ohzi-core 14.0.0 → 15.0.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 (214) hide show
  1. package/README.md +2 -1
  2. package/build/index.mjs +1 -1
  3. package/build/index.mjs.map +1 -1
  4. package/package.json +8 -5
  5. package/src/Capabilities.ts +0 -2
  6. package/src/Debug.ts +38 -33
  7. package/src/Graphics.ts +2 -2
  8. package/src/Initializer.ts +2 -1
  9. package/src/SceneManager.ts +4 -5
  10. package/src/action_sequencer/NumberInterpolator.ts +2 -0
  11. package/src/blitter_index.ts +1 -2
  12. package/src/camera_controller/CameraController.ts +100 -59
  13. package/src/camera_controller/states/common/CommonCameraState.ts +2 -1
  14. package/src/components/AxisHelper.ts +1 -0
  15. package/src/components/Line.ts +35 -27
  16. package/src/components/PlaneHelper.ts +1 -1
  17. package/src/components/Text2D.ts +3 -1
  18. package/src/components/WorldImage.ts +27 -20
  19. package/src/components/sdf_text/SDFTextBatch.ts +16 -26
  20. package/src/dev_bridge/DebugDrawer.ts +399 -0
  21. package/src/index.ts +9 -12
  22. package/src/materials/AddMaterial.ts +14 -7
  23. package/src/materials/BlitNodeMaterial.ts +85 -0
  24. package/src/materials/BloomComposeMaterial.ts +21 -9
  25. package/src/materials/BoxBlurMaterial.ts +26 -6
  26. package/src/materials/ClearDepthNormalMaterial.ts +12 -6
  27. package/src/materials/DepthNormalMaterial.ts +25 -14
  28. package/src/materials/DualFilteringBlurMaterial.ts +32 -5
  29. package/src/materials/GaussianBlurMaterial.ts +36 -14
  30. package/src/materials/LineMaterial.ts +52 -0
  31. package/src/materials/LuminosityHighPassMaterial.ts +23 -10
  32. package/src/materials/NormalMaterial.ts +10 -11
  33. package/src/materials/SDFTextMaterial.ts +63 -16
  34. package/src/materials/SSAOComposeMaterial.ts +14 -5
  35. package/src/materials/SSAOMaterial.ts +123 -24
  36. package/src/materials/ScreenSpaceTextureMaterial.ts +19 -31
  37. package/src/materials/UnrealBloomComposeMaterial.ts +41 -32
  38. package/src/materials/WorldImageMaterial.ts +51 -0
  39. package/src/materials/deferred/DeferredPointLightMaterial.ts +45 -14
  40. package/src/materials/deferred/depth_normal_encoding.ts +36 -0
  41. package/src/primitives/Cube.ts +1 -1
  42. package/src/primitives/Sphere.ts +1 -1
  43. package/src/raycast/GroupRaycaster.ts +2 -2
  44. package/src/render_mode/BloomRender.ts +18 -4
  45. package/src/render_mode/DebugNormalsRender.ts +6 -1
  46. package/src/render_mode/DeferredRender.ts +5 -34
  47. package/src/render_mode/NormalAORender.ts +9 -19
  48. package/src/render_mode/UnrealBloomRender.ts +2 -1
  49. package/src/render_mode/VRRender.ts +6 -3
  50. package/src/render_utilities/Blitter.ts +4 -4
  51. package/src/render_utilities/Blurrer.ts +7 -0
  52. package/src/render_utilities/DualFilteringBlurrer.ts +26 -10
  53. package/src/resource_loader/AudioLoader.ts +5 -3
  54. package/src/resource_loader/HDRTextureLoader.ts +1 -1
  55. package/src/scenes/AbstractScene.ts +7 -3
  56. package/src/scenes/Compilator.ts +5 -1
  57. package/src/scenes/loading_states/LoadingState.ts +15 -7
  58. package/src/scenes/loading_states/RegularLoadingState.ts +2 -1
  59. package/src/utilities/CameraUtilities.ts +57 -79
  60. package/src/utilities/HTMLUtilities.ts +2 -1
  61. package/src/utilities/MeshSampler.ts +8 -1
  62. package/src/utilities/OrthographicFrustumPointFitter.ts +53 -4
  63. package/src/view_components/ApplicationView.ts +1 -1
  64. package/src/view_components/ViewComponent.ts +1 -1
  65. package/src/view_components/ViewManager.ts +7 -1
  66. package/src/view_components/transition/DrawIOAnimationSheet.ts +1 -1
  67. package/types/Capabilities.d.ts +0 -1
  68. package/types/SceneManager.d.ts +1 -1
  69. package/types/blitter_index.d.ts +1 -2
  70. package/types/camera_controller/CameraController.d.ts +9 -0
  71. package/types/components/Line.d.ts +3 -2
  72. package/types/components/WorldImage.d.ts +3 -2
  73. package/types/index.d.ts +2 -7
  74. package/types/materials/AddMaterial.d.ts +2 -2
  75. package/types/materials/BlitNodeMaterial.d.ts +18 -0
  76. package/types/materials/BloomComposeMaterial.d.ts +2 -2
  77. package/types/materials/BoxBlurMaterial.d.ts +2 -2
  78. package/types/materials/ClearDepthNormalMaterial.d.ts +2 -2
  79. package/types/materials/DepthNormalMaterial.d.ts +2 -2
  80. package/types/materials/DualFilteringBlurMaterial.d.ts +2 -2
  81. package/types/materials/GaussianBlurMaterial.d.ts +2 -2
  82. package/types/materials/LuminosityHighPassMaterial.d.ts +2 -2
  83. package/types/materials/NormalMaterial.d.ts +2 -2
  84. package/types/materials/SDFTextMaterial.d.ts +2 -2
  85. package/types/materials/SSAOComposeMaterial.d.ts +2 -2
  86. package/types/materials/SSAOMaterial.d.ts +2 -2
  87. package/types/materials/ScreenSpaceTextureMaterial.d.ts +2 -2
  88. package/types/materials/UnrealBloomComposeMaterial.d.ts +2 -2
  89. package/types/materials/deferred/DeferredPointLightMaterial.d.ts +2 -2
  90. package/types/render_mode/DeferredRender.d.ts +0 -2
  91. package/types/render_mode/NormalAORender.d.ts +0 -2
  92. package/types/render_utilities/Blitter.d.ts +2 -2
  93. package/types/render_utilities/DualFilteringBlurrer.d.ts +0 -2
  94. package/types/utilities/CameraUtilities.d.ts +0 -1
  95. package/types/utilities/OrthographicFrustumPointFitter.d.ts +14 -8
  96. package/build/index.module.js +0 -2
  97. package/build/index.module.js.map +0 -1
  98. package/src/components/EdgeMesh.ts +0 -150
  99. package/src/components/GeometryEdgeVisualizer.ts +0 -49
  100. package/src/components/MultiLinePath.ts +0 -25
  101. package/src/components/MultiLineText2D.ts +0 -65
  102. package/src/components/Shape2D.ts +0 -42
  103. package/src/components/Shape3D.ts +0 -38
  104. package/src/gpu_particles/GPUParticleSystem.ts +0 -122
  105. package/src/gpu_particles/ParticleAttribute.ts +0 -110
  106. package/src/gpu_particles/ParticlePositionAttribute.ts +0 -46
  107. package/src/materials/AlphaFilterMaterial.ts +0 -21
  108. package/src/materials/BaseShaderMaterial.ts +0 -20
  109. package/src/materials/BlitMaterial.ts +0 -27
  110. package/src/materials/DeferredRendererComposeMaterial.ts +0 -36
  111. package/src/materials/DisplayNormalTextureMaterial.ts +0 -18
  112. package/src/materials/FXAAMaterial.ts +0 -12
  113. package/src/materials/MedianFilterMaterial.ts +0 -46
  114. package/src/materials/SDFScreenTextMaterial.ts +0 -32
  115. package/src/materials/UnrealBlurMaterial.ts +0 -20
  116. package/src/materials/UnrealComposeMaterial.ts +0 -27
  117. package/src/materials/ViewPositionMaterial.ts +0 -19
  118. package/src/materials/gpu_particles/AttributeUpdateMaterial.ts +0 -35
  119. package/src/materials/gpu_particles/BasicParticleMaterial.ts +0 -25
  120. package/src/materials/gpu_particles/ParticleStorageMaterial.ts +0 -36
  121. package/src/materials/gpu_particles/PositionStorageMaterial.ts +0 -27
  122. package/src/render_utilities/MedianFilter.ts +0 -72
  123. package/src/render_utilities/ViewPositionRenderer.ts +0 -53
  124. package/src/shaders/add/add.frag +0 -28
  125. package/src/shaders/anti_aliasing/fxaa.frag +0 -72
  126. package/src/shaders/basic_color/basic_color.frag +0 -6
  127. package/src/shaders/basic_color/basic_color.vert +0 -10
  128. package/src/shaders/basic_line/basic_line.frag +0 -37
  129. package/src/shaders/basic_line/basic_line.vert +0 -37
  130. package/src/shaders/basic_texture/basic_texture.frag +0 -10
  131. package/src/shaders/basic_texture/basic_texture.vert +0 -17
  132. package/src/shaders/bloom/bloom_compose.frag +0 -22
  133. package/src/shaders/bloom/cheap_bloom_compose.frag +0 -13
  134. package/src/shaders/box_blur/box_blur.frag +0 -24
  135. package/src/shaders/box_blur/compose.frag +0 -31
  136. package/src/shaders/clear/clear_depth_normal.frag +0 -25
  137. package/src/shaders/copy/copy.frag +0 -7
  138. package/src/shaders/copy/copy.vert +0 -6
  139. package/src/shaders/deferred/blit_copy.vert +0 -11
  140. package/src/shaders/deferred/deferred_compose.frag +0 -59
  141. package/src/shaders/deferred/point_light.frag +0 -66
  142. package/src/shaders/deferred/point_light.vert +0 -13
  143. package/src/shaders/depth_normals/debug_normals.frag +0 -48
  144. package/src/shaders/depth_normals/depth_normals.frag +0 -30
  145. package/src/shaders/depth_normals/depth_normals.vert +0 -13
  146. package/src/shaders/dual_filter_blur/alpha_filter.frag +0 -14
  147. package/src/shaders/dual_filter_blur/downsample.frag +0 -21
  148. package/src/shaders/dual_filter_blur/upsample.frag +0 -24
  149. package/src/shaders/edge_visualizer/edge_visualizer.frag +0 -18
  150. package/src/shaders/edge_visualizer/edge_visualizer.vert +0 -16
  151. package/src/shaders/edges/corners.frag +0 -11
  152. package/src/shaders/edges/corners.vert +0 -31
  153. package/src/shaders/edges/edges.frag +0 -7
  154. package/src/shaders/edges/edges.vert +0 -27
  155. package/src/shaders/gaussian_blur/gaussian_blur.frag +0 -44
  156. package/src/shaders/gaussian_blur/unreal_bloom_compose.frag +0 -36
  157. package/src/shaders/gpu_particles/common_utils.glsl +0 -13
  158. package/src/shaders/gpu_particles/generic_storage.frag +0 -6
  159. package/src/shaders/gpu_particles/store/store_position.vert +0 -14
  160. package/src/shaders/gpu_particles/update/basic_update.frag +0 -21
  161. package/src/shaders/gpu_particles/visualize/visualize.frag +0 -11
  162. package/src/shaders/gpu_particles/visualize/visualize.vert +0 -12
  163. package/src/shaders/grid/grid.frag +0 -17
  164. package/src/shaders/grid/grid.vert +0 -10
  165. package/src/shaders/luminosity_high_pass/luminosity_high_pass.frag +0 -38
  166. package/src/shaders/median_filter/median_filter.frag +0 -134
  167. package/src/shaders/normal/normal.frag +0 -6
  168. package/src/shaders/normal/normal.vert +0 -6
  169. package/src/shaders/sdf_text/sdf_screen_text.frag +0 -51
  170. package/src/shaders/sdf_text/sdf_screen_text.vert +0 -42
  171. package/src/shaders/sdf_text/sdf_text.frag +0 -53
  172. package/src/shaders/sdf_text/sdf_text.vert +0 -42
  173. package/src/shaders/ssao/hbao.frag +0 -264
  174. package/src/shaders/ssao/ssao.frag +0 -95
  175. package/src/shaders/ssao/ssao.vert +0 -11
  176. package/src/shaders/ssao/ssao_compose.frag +0 -14
  177. package/src/shaders/transparent_mix/copy.frag +0 -7
  178. package/src/shaders/transparent_mix/transparent_mix.frag +0 -19
  179. package/src/shaders/transparent_mix/transparent_mix.vert +0 -8
  180. package/src/shaders/ui/ss_texture.frag +0 -11
  181. package/src/shaders/ui/ss_texture.vert +0 -32
  182. package/src/shaders/ui/ws_texture.vert +0 -39
  183. package/src/shaders/unreal_blur/unreal_blur.frag +0 -25
  184. package/src/shaders/unreal_blur/unreal_compose.frag +0 -24
  185. package/src/shaders/write_view_position/write_view_position.frag +0 -7
  186. package/src/shaders/write_view_position/write_view_position.vert +0 -9
  187. package/src/types.d.ts +0 -14
  188. package/types/components/EdgeMesh.d.ts +0 -16
  189. package/types/components/GeometryEdgeVisualizer.d.ts +0 -8
  190. package/types/components/MultiLinePath.d.ts +0 -8
  191. package/types/components/MultiLineText2D.d.ts +0 -12
  192. package/types/components/Shape2D.d.ts +0 -7
  193. package/types/components/Shape3D.d.ts +0 -6
  194. package/types/gpu_particles/GPUParticleSystem.d.ts +0 -19
  195. package/types/gpu_particles/ParticleAttribute.d.ts +0 -20
  196. package/types/gpu_particles/ParticlePositionAttribute.d.ts +0 -6
  197. package/types/materials/AlphaFilterMaterial.d.ts +0 -7
  198. package/types/materials/BaseShaderMaterial.d.ts +0 -4
  199. package/types/materials/BlitMaterial.d.ts +0 -4
  200. package/types/materials/DeferredRendererComposeMaterial.d.ts +0 -10
  201. package/types/materials/DisplayNormalTextureMaterial.d.ts +0 -4
  202. package/types/materials/FXAAMaterial.d.ts +0 -5
  203. package/types/materials/MedianFilterMaterial.d.ts +0 -8
  204. package/types/materials/SDFScreenTextMaterial.d.ts +0 -8
  205. package/types/materials/UIElementMaterial.d.ts +0 -4
  206. package/types/materials/UnrealBlurMaterial.d.ts +0 -5
  207. package/types/materials/UnrealComposeMaterial.d.ts +0 -5
  208. package/types/materials/ViewPositionMaterial.d.ts +0 -5
  209. package/types/materials/gpu_particles/AttributeUpdateMaterial.d.ts +0 -8
  210. package/types/materials/gpu_particles/BasicParticleMaterial.d.ts +0 -5
  211. package/types/materials/gpu_particles/ParticleStorageMaterial.d.ts +0 -5
  212. package/types/materials/gpu_particles/PositionStorageMaterial.d.ts +0 -5
  213. package/types/render_utilities/MedianFilter.d.ts +0 -12
  214. package/types/render_utilities/ViewPositionRenderer.d.ts +0 -12
package/build/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{ShaderMaterial as e,Vector2 as t,NoBlending as s,AlwaysDepth as r,Color as i,Scene as n,Mesh as o,PlaneGeometry as a,OrthographicCamera as l,Vector4 as _,RenderTarget as h,Vector3 as c,PositionalAudio as u,Audio as d,AudioContext as p,Texture as m,SRGBColorSpace as g,NoColorSpace as f,CubeTextureLoader as v,CanvasTexture as y,UVMapping as b,ClampToEdgeWrapping as w,NearestFilter as x,Object3D as M,LineBasicMaterial as S,BufferGeometry as z,Line as T,PerspectiveCamera as k,CylinderGeometry as A,ConeGeometry as F,MeshBasicMaterial as C,BoxGeometry as R,SphereGeometry as P,Box3 as L,Box3Helper as D,CatmullRomCurve3 as j,Sphere as U,Plane as O,Line3 as N,Quaternion as q,Matrix4 as I,Ray as E,DataTexture as Y,RGBAFormat as B,RepeatWrapping as V,LinearFilter as $,HalfFloatType as G,UnsignedByteType as X,LinearSRGBColorSpace as W,BufferAttribute as Q,Skeleton as H,DoubleSide as K,LinearMipMapLinearFilter as Z,Box2 as J,InstancedBufferGeometry as ee,Float32BufferAttribute as te,InstancedBufferAttribute as se,DynamicDrawUsage as re,FloatType as ie,Points as ne,FileLoader as oe,PlaneHelper as ae}from"three";import{GLTFLoader as le}from"three/examples/jsm/loaders/GLTFLoader.js";import{HDRCubeTextureLoader as _e}from"three/examples/jsm/loaders/HDRCubeTextureLoader.js";import{HDRLoader as he}from"three/examples/jsm/loaders/HDRLoader";import*as ce from"three/examples/jsm/utils/BufferGeometryUtils.js";export{ce as BufferGeometryUtils};import{MeshBasicNodeMaterial as ue}from"three/webgpu";import{uniform as de,attribute as pe,vec3 as me,mix as ge,fwidth as fe,smoothstep as ve,min as ye}from"three/tsl";import{ColladaLoader as be}from"three/examples/jsm/loaders/ColladaLoader.js";import{FontLoader as we}from"three/examples/jsm/loaders/FontLoader.js";import{OBJLoader as xe}from"three/examples/jsm/loaders/OBJLoader.js";class Me{on_post_start(){}on_enter(e){}on_exit(e){}before_update(){}update(){}fixed_update(){}on_post_render(){}on_pre_render(){}on_frame_end(){}dispose(){}}class Se extends e{constructor(e,i,n){super({uniforms:{_MainTex:{value:null},_Resolution:{value:new t(0,0)},_TargetResolution:{value:new t(0,0)}},defines:n||{},vertexShader:i||"#define GLSLIFY 1\nvarying vec2 vUv;void main(){gl_Position=vec4(uv*2.0-1.0,1.0,1.0);vUv=uv;}",fragmentShader:e||"#define GLSLIFY 1\nuniform sampler2D _MainTex;varying vec2 vUv;void main(){gl_FragColor=texture2D(_MainTex,vUv);}",depthWrite:!1,blending:s,depthTest:!1,depthFunc:r})}}class ze extends Se{constructor(e=!1){super("#define GLSLIFY 1\nuniform sampler2D _MainTex;uniform sampler2D _SecondTex;varying vec2 vUv;vec4 sampleTex(sampler2D tex,vec2 uv){vec4 col=texture2D(tex,uv);\n#ifndef USE_LINEAR_COLOR_SPACE\ncol.rgb=pow(col.rgb,vec3(2.2));\n#endif\nreturn col;}void main(){vec4 col0=sampleTex(_MainTex,vUv);vec4 col1=sampleTex(_SecondTex,vUv);gl_FragColor=col0+col1;gl_FragColor.rgb=pow(gl_FragColor.rgb,vec3(0.4545));}"),this.defines.USE_LINEAR_COLOR_SPACE=e,this.uniforms._SecondTex={value:void 0}}set_add_texture(e){this.uniforms._SecondTex.value=e}}var Te="#define GLSLIFY 1\nuniform vec3 _Color;void main(){gl_FragColor=vec4(_Color,1.0);}",ke="#define GLSLIFY 1\nvarying vec2 vUv;void main(){vec3 pos=position;mat4 MVP=projectionMatrix*modelViewMatrix;gl_Position=MVP*vec4(pos,1.0);vUv=uv;}";class Ae extends e{constructor(e,t,s){super({vertexShader:e||ke,fragmentShader:t||Te,uniforms:s??{_Color:{value:new i("#FF0000")}}})}}class Fe extends Se{constructor(e,t=!1){super("#define GLSLIFY 1\nvarying vec2 vUv;uniform sampler2D blurTexture1;uniform sampler2D blurTexture2;uniform sampler2D blurTexture3;uniform sampler2D blurTexture4;uniform sampler2D blurTexture5;uniform float bloomStrength;uniform float bloomRadius;uniform float bloomFactors[NUM_MIPS];uniform vec3 bloomTintColors[NUM_MIPS];float lerpBloomFactor(const in float factor){float mirrorFactor=1.2-factor;return mix(factor,mirrorFactor,bloomRadius);}vec4 sampleTex(sampler2D tex,vec2 uv){vec4 col=texture2D(tex,uv);\n#ifndef USE_LINEAR_COLOR_SPACE\ncol.rgb=pow(col.rgb,vec3(2.2));\n#endif\nreturn col;}void main(){gl_FragColor=bloomStrength*(lerpBloomFactor(bloomFactors[0])*vec4(bloomTintColors[0],1.0)*sampleTex(blurTexture1,vUv)+lerpBloomFactor(bloomFactors[1])*vec4(bloomTintColors[1],1.0)*sampleTex(blurTexture2,vUv)+lerpBloomFactor(bloomFactors[2])*vec4(bloomTintColors[2],1.0)*sampleTex(blurTexture3,vUv)+lerpBloomFactor(bloomFactors[3])*vec4(bloomTintColors[3],1.0)*sampleTex(blurTexture4,vUv)+lerpBloomFactor(bloomFactors[4])*vec4(bloomTintColors[4],1.0)*sampleTex(blurTexture5,vUv));\n#ifndef USE_LINEAR_COLOR_SPACE\ngl_FragColor.rgb=pow(gl_FragColor.rgb,vec3(0.4545));\n#endif\n}",void 0,{NUM_MIPS:e}),this.uniforms._MainTex={value:void 0},this.uniforms._BlurredTex={value:void 0},this.uniforms._BloomStrength={value:1},this.uniforms.blurTexture1={value:null},this.uniforms.blurTexture2={value:null},this.uniforms.blurTexture3={value:null},this.uniforms.blurTexture4={value:null},this.uniforms.blurTexture5={value:null},this.uniforms.bloomStrength={value:1},this.uniforms.bloomFactors={value:[1,.8,.6,.4,.2]},this.uniforms.bloomRadius={value:1},this.defines.USE_LINEAR_COLOR_SPACE=t;const s=[new i("#FFFFFF"),new i("#FFFFFF"),new i("#FFFFFF"),new i("#FFFFFF"),new i("#FFFFFF")];this.uniforms.bloomTintColors={value:s}}set_blur_texture_0(e){this.uniforms.blurTexture1.value=e}set_blur_texture_1(e){this.uniforms.blurTexture2.value=e}set_blur_texture_2(e){this.uniforms.blurTexture3.value=e}set_blur_texture_3(e){this.uniforms.blurTexture4.value=e}set_blur_texture_4(e){this.uniforms.blurTexture5.value=e}set_bloom_strength(e){this.uniforms.bloomStrength.value=e}set_bloom_radius(e){this.uniforms.bloomRadius.value=e}set_tint_color_0(e){this.uniforms.bloomTintColors.value[0].set(e)}set_tint_color_1(e){this.uniforms.bloomTintColors.value[1].set(e)}set_tint_color_2(e){this.uniforms.bloomTintColors.value[2].set(e)}set_tint_color_3(e){this.uniforms.bloomTintColors.value[3].set(e)}set_tint_color_4(e){this.uniforms.bloomTintColors.value[4].set(e)}}class Ce{constructor(){}render(e){}on_enter(e,t){}on_exit(e,t){}resize(){}dispose(){}}class Re{constructor(e,t,s=1){this.resource_id=e,this.url=t,this.loaded_bytes=0,this.total_bytes=s,this.has_finished=!1,this.has_error=!1,this.error_message="none"}__update_downloaded_bytes(e,t){e=this.is_number(e)?e:1,t=this.is_number(t)?t:1,this.loaded_bytes=e,t>0&&(this.total_bytes=t),this.loaded_bytes>this.total_bytes&&console.warn("Total bytes is smaller than loaded ones. Please set total bytes by hand to:",this.url)}__loading_ended(){this.has_finished=!0}__set_error(e){this.has_error=!0,this.error_message=e}print_error(){console.error("Error while loading "+this.resource_id+"\n\t path: "+this.url+"\n\t\t"+this.error_message)}load(e){if(void 0===e.resources_by_url[this.url]){const t="default";fetch(this.url,{method:"GET",mode:"cors",cache:t,credentials:"same-origin",redirect:"follow"}).then(this.on_progress.bind(this,e)).catch(this.__on_error.bind(this))}else e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended()}async on_progress(e,t){const s=t.clone(),r=t.body.getReader(),i=+t.headers.get("Content-Length");let n=0;for(;;){const{done:e,value:t}=await r.read();if(e)break;n+=t.length,this.__update_downloaded_bytes(n,i)}t.ok?this.on_preloaded_finished(e,s):(this.__set_error(`${t.status}: ${t.statusText}`),this.__loading_ended())}on_preloaded_finished(e,t){}__on_error(e){console.error(e)}is_int(e){return Number(e)===e&&e%1==0}is_float(e){return Number(e)===e&&e%1!=0}is_number(e){return this.is_int(e)||this.is_float(e)}}const Pe=new class{init(){this._current=void 0,this._spectator=void 0}set current(e){this._current=e}get current(){return this._current}set spectator(e){this._spectator=e}get spectator(){return this._spectator}};const Le=new class{init(){this.width=1,this.height=1,this.position=new t,this.render_width=1,this.render_height=1,this.width_height=new t(this.width,this.height),this.dpr=1,this.pixel_size=new t(1/this.width,1/this.height)}update_position(e,t){this.position.set(e,t)}update(){this.size_changed=!1}update_size(e,s){this.width=e,this.height=s,this.pixel_size=new t(1/this.width,1/this.height),this.width_height.x=e,this.width_height.y=s,this.render_width=e*this.dpr,this.render_height=s*this.dpr,this.size_changed=!0}apply_pixel_density_v2(e){return e.multiplyScalar(1/this.dpr),e}apply_pixel_density(e){return e*(1/this.dpr)}get_pixel_size(){return this.pixel_size}get aspect_ratio(){return this.width/this.height}get portrait(){return this.width<this.height}};const De=new class{init(){this._current=new nt({name:"default_scene",compilators:{}}),this._current.name="default_scene"}add_scene(e){}get current(){return this._current}set current(e){this._current=e}dispose(){for(this.current.traverse((e=>{if(e.geometry){e.geometry.dispose();const t=e.material;Array.isArray(t)?t.forEach((e=>e.dispose())):t.dispose()}}));this.current.children.length>0;)this.current.remove(this.current.children[0])}};class je{constructor(e){this.renderer=e,this._blit_scene=new n,this._blit_material=new Se,this._blit_quad=new o(new a(1,1),this._blit_material),this._blit_scene.add(this._blit_quad),this._blit_camera=new l(-1,1,1,-1,-1e4,1e4)}blit(e,t){this._blit_quad.material=this._blit_material;const s=!0===e.isRenderTarget?e.texture:e,r=!0===e.isRenderTarget?e.width:e.image.width,i=!0===e.isRenderTarget?e.height:e.image.height;this._blit_quad.material.uniforms._MainTex.value=s,this._blit_quad.material.uniforms._Resolution.value.set(r,i),t?this._blit_quad.material.uniforms._TargetResolution.value.set(t.width,t.height):this.renderer.getSize(this._blit_quad.material.uniforms._TargetResolution.value),this.__render(t)}material_pass(e,t){this._blit_quad.material=e,this.__render(t)}blit_with_material(e,t,s){const r=!0===e.isRenderTarget?e.texture:e,i=!0===e.isRenderTarget?e.width:e.image.width,n=!0===e.isRenderTarget?e.height:e.image.height;this._blit_quad.material=s,this._blit_quad.material.uniforms._MainTex.value=r,this._blit_quad.material.uniforms._Resolution.value.set(i,n),t?this._blit_quad.material.uniforms._TargetResolution.value.set(t.width,t.height):this.renderer.getSize(this._blit_quad.material.uniforms._TargetResolution.value),this.__render(t)}blit_clear_with_material(e,t){this._blit_quad.material=t,this.__render(e)}dispose(){this._blit_quad.geometry.dispose(),this._blit_quad.material.dispose()}__render(e){const t=void 0===e?null:e,s=this.renderer.getRenderTarget();this.renderer.setRenderTarget(t),this.renderer.render(this._blit_scene,this._blit_camera),this.renderer.setRenderTarget(s)}}class Ue extends Se{constructor(e,t){super("#define GLSLIFY 1\nuniform vec4 _DepthNormal;vec2 EncodeFloatRG(float v){vec2 kEncodeMul=vec2(1.0,255.0);float kEncodeBit=1.0/255.0;vec2 enc=kEncodeMul*v;enc=fract(enc);enc.x-=enc.y*kEncodeBit;return enc;}vec2 EncodeNormal(vec3 n){float scale=1.7777;vec2 enc=n.xy/(n.z+1.0);enc/=scale;enc=enc*0.5+0.5;return enc;}void main(){gl_FragColor=vec4(EncodeFloatRG(_DepthNormal.x),EncodeNormal(normalize(_DepthNormal.yzw)));}"),this.uniforms._DepthNormal={value:new _(e,t.x,t.y,t.z)}}}class Oe extends e{constructor(){super({uniforms:{_FarPlane:{value:1}},vertexShader:"#define GLSLIFY 1\nvarying vec3 v_normal;varying vec3 v_pos;void main(){vec3 pos=position;mat4 MVP=projectionMatrix*modelViewMatrix;v_normal=(modelViewMatrix*vec4(normal,0.0)).xyz;v_pos=(modelViewMatrix*vec4(pos,1.0)).xyz;gl_Position=MVP*vec4(pos,1.0);}",fragmentShader:"#define GLSLIFY 1\nvarying vec3 v_normal;varying vec3 v_pos;uniform float _FarPlane;vec2 EncodeFloatRG(float v){vec2 kEncodeMul=vec2(1.0,255.0);float kEncodeBit=1.0/255.0;vec2 enc=kEncodeMul*v;enc=fract(enc);enc.x-=enc.y*kEncodeBit;return enc;}vec2 EncodeNormal(vec3 n){float scale=1.7777;vec2 enc=n.xy/(n.z+1.0);enc/=scale;enc=enc*0.5+0.5;return enc;}void main(){gl_FragColor=vec4(EncodeFloatRG(length(v_pos.z)/_FarPlane),EncodeNormal(normalize(v_normal)));}"})}set far_plane(e){this.uniforms._FarPlane.value=e}get far_plane(){return this.uniforms._FarPlane.value}}class Ne{constructor(){this.RT=new h(Le.width,Le.height),this.clear_depth_normal_mat=new Ue(1,new c(0,0,1)),this.depth_normal_material=new Oe}render(e){this.__resize_RT_if_necessary(),e.clear(this.RT,void 0,!0,!0),e.blit_clear_with_material(this.RT,this.clear_depth_normal_mat),this.depth_normal_material.far_plane=Pe.current.far,e.render(void 0,void 0,this.RT,this.depth_normal_material)}__resize_RT_if_necessary(){this.RT.width===Le.width&&this.RT.height===Le.height||this.RT.setSize(Le.width,Le.height)}get render_target(){return this.RT}}const qe=new class{init({renderer:e,core_attributes:t,dpr:s}){this._renderer=e,this.blitter=void 0,this.canvas=void 0,this.no_render=void 0,this.current_render_mode=void 0,this.generate_depth_normal_texture=!1,this.depth_and_normals_renderer=void 0,this.core_attributes={xr_enabled:!1},Object.assign(this.core_attributes,t),this.core_attributes.xr_enabled?this._renderer.xr.enabled=!0:this._renderer.autoClear=!1,Le.dpr=s,this._renderer.setPixelRatio(s),this.blitter=new je(this._renderer),this.canvas=this._renderer.domElement,this.no_render=new Ce,this.current_render_mode=this.no_render,this.generate_depth_normal_texture=!1,this.depth_and_normals_renderer=new Ne}get dom_element(){return this._renderer.domElement}get depth_normals_RT(){return this.depth_and_normals_renderer.render_target}set_state(e){this.current_render_mode.on_exit(this,this._renderer),this.current_render_mode=e,this.current_render_mode.on_enter(this,this._renderer)}update(){this.generate_depth_normal_texture&&this.depth_and_normals_renderer.render(this),this.__update_current_camera(),Pe.current&&this.current_render_mode.render(),Le.update()}__update_current_camera(){Pe.current&&(Pe.current.aspect=Le.aspect_ratio,Pe.current.updateProjectionMatrix(),Pe.current.updateMatrix(),Pe.current.updateMatrixWorld(!0))}render(e,t,s,r){this.__apply_override_material(e,r),this._renderer.setRenderTarget(void 0===s?null:s),this._renderer.render(e||De.current,t||Pe.current),this.__apply_override_material(e,void 0)}async compile(e,t,s,r){this.__apply_override_material(e,r),this._renderer.setRenderTarget(void 0===s?null:s),await this._renderer.compile(e||De.current,t||Pe.current),this.__apply_override_material(e,void 0)}async compile_async(e,t,s,r,i){this.__apply_override_material(e,r),this._renderer.setRenderTarget(void 0===s?null:s);const n=this._renderer.compileAsync(e||De.current,t||Pe.current,i);return this.__apply_override_material(e,void 0),n}render_scene(e){"on_pre_render"in e&&e.on_pre_render(),"render"in e?e.render():this.render(e,void 0),"on_post_render"in e&&e.on_post_render()}__apply_override_material(e,t){t=void 0===t?null:t,e?e.overrideMaterial=t:De.current.overrideMaterial=t}async readback_RT(e){return this._renderer.readRenderTargetPixelsAsync(e,0,0,e.width,e.height)}clear(e,t,s,r){this._renderer.setRenderTarget(void 0===e?null:e),t&&this._renderer.setClearColor(t.clear_color,t.clear_alpha),this._renderer.clear(!!t,!!s,!!r)}on_resize(e,t){for(const s of e)Le.dpr=t,Le.update_position(s.contentRect.x,s.contentRect.y),Le.update_size(s.contentRect.width,s.contentRect.height),this.canvas.width=Le.render_width,this.canvas.height=Le.render_height,this._renderer.setViewport(0,0,Le.render_width,Le.render_height),this._renderer.setSize(Le.width,Le.height),this.__update_current_camera()}material_pass(e,t){this.blitter.material_pass(e,t)}blit(e,t,s){s?this.blitter.blit_with_material(e,t,s):this.blitter.blit(e,t)}blit_clear_with_material(e,t){this.blitter.blit_clear_with_material(e,t)}take_screenshot(e,t=Le.width,s=Le.height){const r=Le.width,i=Le.height,n=t,o=s,a=1024,l=1024,_=Math.ceil(n/a),h=Math.ceil(o/l);Le.update_size(a,l);const c=this._renderer.getPixelRatio();this._renderer.setPixelRatio(1),this._renderer.setSize(a,l,!1);const u=document.createElement("canvas").getContext("2d");u.canvas.width=n,u.canvas.height=o,Pe.current.aspect=Le.aspect_ratio,Pe.current.updateMatrix(),Pe.current.updateMatrixWorld(!0);for(let e=0;e<_;e++)for(let t=0;t<h;t++)Pe.current.setViewOffset(n,o,Le.width*e,Le.height*t,Le.width,Le.height),this.current_render_mode.render(),u.drawImage(this._renderer.domElement,Le.width*e,Le.height*t);u.canvas.toBlob(e,"image/png;base64;"),Pe.current.clearViewOffset(),Le.update_size(r,i),this._renderer.setPixelRatio(c),this._renderer.setSize(r,i,!1),Pe.current.aspect=Le.aspect_ratio,Pe.current.updateMatrix(),Pe.current.updateMatrixWorld(!0)}download_screenshot(e){const t=document.createElement("a");t.download="Snapshot.png",t.href=URL.createObjectURL(e),t.click(),t.onclick=function(){requestAnimationFrame((function(){URL.revokeObjectURL(t.href)})),t.removeAttribute("href")}}dispose(){this._renderer.dispose(),this.current_render_mode.dispose(),this.blitter.dispose()}};class Ie{constructor(e,t=!0,s=1,r=!1){this.buffer=e,this.loop=t,this.volume=s,this.positional=r,this.audio=void 0}init(e){this.positional?this.audio=new u(e):this.audio=new d(e),this.audio.setBuffer(this.buffer),this.audio.setLoop(this.loop),this.audio.gain.gain.value=0,this.audio.setVolume(this.loop?0:this.volume)}play(){this.audio.play()}pause(){this.audio.pause()}stop(){this.audio.stop()}get is_playing(){return this.audio.isPlaying}}class Ee extends Re{constructor(e,t,s=!0,r=0,i,n=!1){super(e,t,i),this.loop=s,this.volume=r,this.positional=n}on_preloaded_finished(e){void 0===e.resources_by_url[this.url]?this.instantiate_audio(e):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}instantiate_audio(e){const t=p.getContext(),s=t.createBuffer(2,22050,44100);fetch(this.url).then((e=>e.blob())).then((r=>{r.arrayBuffer?r.arrayBuffer().then((s=>{t.decodeAudioData(s,(t=>{e.set_resource(this.resource_id,this.url,new Ie(t,this.loop,this.volume,this.positional)),this.__update_downloaded_bytes(1,1),this.__loading_ended()}))})):(e.set_resource(this.resource_id,this.url,new Ie(s,this.loop,this.volume,this.positional)),this.__update_downloaded_bytes(1,1),this.__loading_ended())}))}}const Ye=new class{init(){this.resources={},this.resources_by_url={}}set_resource(e,t,s){Object.keys(this.resources_by_url).includes(t)?this.resources[e]=this.resources_by_url[t]:(this.resources[e]=s,this.resources_by_url[t]=s)}get_resource(e){return this.resources[e]}get(e){return this.resources[e]}};class Be{constructor(e,t,s){this.resource_container=Ye,this.assets=t,this.name=e,this.worker=s,this.bound_on_message=this.on_message.bind(this),this.__setup_worker(),this.assets_loaders=this.__setup_loaders()}load(){this.worker.postMessage({type:"load",loader_name:this.name})}is_loaded(){for(let e=0;e<this.assets_loaders.length;e++){const t=this.assets_loaders[e];if(!t.has_finished)return!1;t.has_error&&(t.url=t.original_url,t.print_error())}return!0}get_progress(){return this.__get_loaded_bytes()/this.__get_total_bytes()}__get_loaded_bytes(){let e=1;for(let t=0;t<this.assets_loaders.length;t++)e+=this.assets_loaders[t].loaded_bytes;return e}__get_total_bytes(){let e=1;for(let t=0;t<this.assets_loaders.length;t++)e+=this.assets_loaders[t].total_bytes;return e}get_assets_names(){const e=[];for(let t=0;t<this.assets.length;t++){const s=this.assets[t];e.push(s.name)}return e}static create_worker(){return new Worker(new URL("./assets_loader/AsyncAssetsLoaderWorker.ts",import.meta.url),{name:"OHZI - AssetLoader",type:"module"})}__setup_worker(){this.worker.addEventListener("message",this.bound_on_message),this.worker.postMessage({type:"assets",loader_name:this.name,data:this.assets})}on_message(e){const t=e.data;if(t.type===`asset_loaded_${this.name}`)this.__on_assets_loaded(t.data)}__on_assets_loaded(e){this.worker.removeEventListener("message",this.bound_on_message);for(let t=0;t<this.assets_loaders.length;t++){const s=this.assets_loaders[t];s.original_url=s.url,s.url=e[s.resource_id],s.on_preloaded_finished(this.resource_container)}}__setup_loaders(){return console.warn("Not implemented"),[]}}class Ve extends Be{constructor(e,t,s){super(e,t,s)}__setup_loaders(){const e=[];for(let t=0;t<this.assets.length;t++){const s=this.assets[t];e.push(new Ee(s.name,s.url,s.loop,s.volume,s.size,s.positional))}return e}}class $e extends Re{constructor(e,t,s,r){super(e,t,r),this.loader=new le,this.loader.setDRACOLoader(s)}on_preloaded_finished(e){void 0===e.resources_by_url[this.url]?this.loader.load(this.url,(t=>{e.set_resource(this.resource_id,this.url,t),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(e=>{this.__set_error(e+"\n\n\t If the error says something about unexpected token < in JSON then the probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class Ge extends Re{constructor(e,t,s){super(e,t,s),this.loader=new le}on_preloaded_finished(e){void 0===e.resources_by_url[this.url]?this.loader.load(this.url,(t=>{e.set_resource(this.resource_id,this.url,t),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(e=>{this.__set_error(e+"\n\n\t If the error says something about unexpected token < in JSON then the probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class Xe extends Be{constructor(e,t,s){super(e,t,s)}__setup_loaders(){const e=[];for(let t=0;t<this.assets.length;t++){const s=this.assets[t];if(s.draco){const t=Ye.get("draco_loader");e.push(new $e(s.name,s.url,t,s.size))}else e.push(new Ge(s.name,s.url,s.size))}return e}}const We=new class{async init(){switch(this.browser_name="",this.agent=window.navigator.userAgent.toLowerCase(),this.has_web_xr_support="xr"in navigator,this.is_vr=this.has_web_xr_support&&await navigator.xr.isSessionSupported("immersive-vr"),!0){case this.agent.indexOf("edge")>-1:this.browser_name="edge_ie";break;case this.agent.indexOf("edg")>-1:this.browser_name="edge_chromium";break;case this.agent.indexOf("opr")>-1&&!!window.opr:this.browser_name="opera";break;case this.agent.indexOf("chrome")>-1&&!!window.chrome:this.browser_name="chrome";break;case this.agent.indexOf("trident")>-1:this.browser_name="iexplorer";break;case this.agent.indexOf("firefox")>-1:this.browser_name="firefox";break;case this.agent.indexOf("safari")>-1:this.browser_name="safari";break;default:this.browser_name="other"}this.version=this.get_version()}get name(){return this.browser_name}get is_safari(){return"safari"===this.browser_name}get is_chrome(){return"chrome"===this.browser_name}get is_firefox(){return"firefox"===this.browser_name}get is_edge(){return"edge_ie"===this.browser_name}get is_edge_chromium(){return"edge_chromium"===this.browser_name}get has_webm(){return!!(this.is_chrome||this.is_firefox||this.is_edge_chromium)}get has_hvec(){return this.is_safari}get preferred_video_extension(){return this.has_webm?"webm":this.has_hvec?"hvec.mp4":"mp4"}get_version(){const e=navigator.userAgent;let t=[],s="0",r=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];return/trident/i.test(r[1])&&(t=/\brv[ :]+(\d+)/g.exec(e)||[],s="IE "+(t[1]||"")),"Chrome"===r[1]&&(t=e.match(/\b(OPR|Edge)\/(\d+)/),null!=t&&(s=t.slice(1).join(" ").replace("OPR","Opera"))),r=r[2]?[r[1],r[2]]:[navigator.appName,navigator.appVersion,"-?"],null!=(t=e.match(/version\/(\d+(\.\d+)?)/i))&&r.splice(1,1,t[1]),s=r.join(" "),Number(s.split(" ")[1])}};class Qe extends Re{constructor(e,t,s,r=!0,i=!1,n=!0){super(e,t,s),this.original_url="",this.colorSpaceConversion=n,this.premultiplyAlpha=i,this.flipY=r}on_preloaded_finished(e){We.is_safari?this.load_with_old_method(e):this.load_with_new_method(e)}load_with_old_method(e){if(void 0===e.resources_by_url[this.url]){const t=new m,s=new Image;s.src=this.url,s.onload=()=>{t.image=s,t.flipY=this.flipY,t.premultiplyAlpha=this.premultiplyAlpha,t.colorSpace=this.colorSpaceConversion?g:f,t.needsUpdate=!0,e.set_resource(this.resource_id,this.url,t),this.__update_downloaded_bytes(1,1),this.__loading_ended()},s.onerror=()=>{console.error("The source image could not be decoded.",this.original_url)}}else e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended()}load_with_new_method(e){if(void 0===e.resources_by_url[this.url]){const t={credentials:"same-origin"};fetch(this.url,t).then((e=>e.blob())).then((e=>createImageBitmap(e,{colorSpaceConversion:this.colorSpaceConversion?"default":"none",imageOrientation:this.flipY?"flipY":"from-image",premultiplyAlpha:this.premultiplyAlpha?"premultiply":"none"}))).then((t=>{const s=new m(t);s.flipY=this.flipY,s.premultiplyAlpha=this.premultiplyAlpha,s.colorSpace=this.colorSpaceConversion?g:f,s.needsUpdate=!0,e.set_resource(this.resource_id,this.url,s),this.__update_downloaded_bytes(1,1),this.__loading_ended()})).catch((e=>{console.error(e,this.original_url)}))}else e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended()}}class He extends Re{constructor(e,t,s,r){super(e,t,r),this.loader=s}on_preloaded_finished(e){void 0===e.resources_by_url[this.url]?this.loader.load(this.url,(t=>{e.set_resource(this.resource_id,this.url,t),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(e=>{}),(e=>{this.__set_error(e+"\n\n\t If the error says something about unexpected token < in JSON then the probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class Ke extends Re{constructor(e,t,s,r){super(e,t,r),this.loader=new v,this.loader.setPath(t+"/"),this.urls=[`px.${s}`,`nx.${s}`,`py.${s}`,`ny.${s}`,`pz.${s}`,`nz.${s}`]}on_preloaded_finished(e){void 0===e.resources_by_url[this.url]?this.loader.load(this.urls,(t=>{e.set_resource(this.resource_id,this.url,t),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(e=>{this.__set_error("Image could not be loaded. Maybe wrong name or path, I don't know¯\\_(ツ)_/¯"+e),this.__loading_ended()})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class Ze extends Re{constructor(e,t,s,r){super(e,t,r),this.loader=new _e,this.loader.setPath(t+"/"),this.urls=[`px.${s}`,`nx.${s}`,`py.${s}`,`ny.${s}`,`pz.${s}`,`nz.${s}`]}on_preloaded_finished(e){void 0===e.resources_by_url[this.url]?this.loader.load(this.urls,(t=>{e.set_resource(this.resource_id,this.url,t),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(e=>{this.__set_error(e+"\n\n\t If the error says something about unexpected token < in JSON then the probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class Je extends Re{constructor(e,t,s){super(e,t,s),this.loader=new he}on_preloaded_finished(e){void 0===e.resources_by_url[this.url]?this.loader.load(this.url,(t=>{e.set_resource(this.resource_id,this.url,t),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(e=>{this.__set_error(e+"\n\n\t If the error says something about unexpected token < in JSON then the probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class et extends Be{constructor(e,t,s){super(e,t,s)}__setup_loaders(){const e=[];for(let t=0;t<this.assets.length;t++){const s=this.assets[t];switch(s.kind){case"regular":e.push(new Qe(s.name,s.url,s.size,s.flipY,s.premultiplyAlpha,s.colorSpaceConversion));break;case"basis":e.push(new He(s.name,s.url,Ye.get("basis_loader"),s.size));break;case"hdr":e.push(new Je(s.name,s.url,s.size));break;case"cubemap":e.push(new Ke(s.name,s.url,s.extension,s.size));break;case"cubemap_hdr":e.push(new Ze(s.name,s.url,s.extension,s.size))}}return e}}class tt{constructor(e){this.compilators=e,this.first_update=!0,this.index=0}update(){this.is_finished()||(this.compilators[this.index].finished?(this.index++,this.first_update=!0):this.first_update?(this.compilators[this.index].start(),this.first_update=!1):this.compilators[this.index].update())}is_finished(){return this.index===this.compilators.length}}class st{constructor(e,{SceneCompilator:t,TexturesCompilator:s,AudiosCompilator:r}){this.scene=e,this.SceneCompilator=t,this.TexturesCompilator=s,this.AudiosCompilator=r,this.loaders=[],this.compilators=[],this.callback_called=!1}set_assets(e,t,s,r=[],i=[],n=[]){this.scene_objects=e,this.scene_textures=t,this.scene_sounds=s,this.custom_loaders=r,this.custom_compilators=i,this.custom_data=n}get loading_progress(){let e=0;for(let t=0;t<this.loaders.length;t++){e+=this.loaders[t].get_progress()}return e/this.loaders.length}load(){this.setup_loader(),this.loaders[0].load()}on_enter(){}on_exit(){}update(){}setup_loader(){const e=[],t=Ye.get("assets_worker");t.postMessage({type:"reset",loader_name:this.scene.name});const s=new Xe(this.scene.name,this.scene_objects,t);this.loaders.push(s),e.push(new this.SceneCompilator(this.scene));const r=new et(this.scene.name,this.scene_textures,t);this.loaders.push(r),e.push(new this.TexturesCompilator(r.get_assets_names()));const i=new Ve(this.scene.name,this.scene_sounds,t);this.loaders.push(i),e.push(new this.AudiosCompilator(i.get_assets_names()));for(let s=0;s<this.custom_loaders.length;s++){const r=new this.custom_loaders[s](this.scene.name,this.custom_data[s],t);this.loaders.push(r),e.push(new this.custom_compilators[s](r.get_assets_names()))}this.compilator_manager=new tt(e)}is_loaded(){let e=!0;for(let t=0;t<this.loaders.length;t++){const s=this.loaders[t];e=e&&s.is_loaded()}return e}is_compiled(){return this.compilator_manager.update(),this.compilator_manager.is_finished()}}class rt extends st{on_enter(){super.on_enter()}on_exit(){super.on_exit()}update(){super.update(),this.is_loaded()&&this.scene.on_high_quality_assets_ready()}}class it extends st{constructor(e,t){super(e,t),this.on_assets_ready_called=!1}on_enter(){super.on_enter()}on_exit(){super.on_exit()}update(){super.update(),this.is_loaded()&&(this.on_assets_ready_called||(this.scene.on_assets_ready(),this.on_assets_ready_called=!0),this.is_compiled()&&this.scene.on_assets_compiled())}}class nt extends n{constructor({name:e,compilators:t}){super(),this.name=e,this.initialized=!1,this.is_loaded=!1,this.is_high_loaded=!1,this.loading_states={regular:new it(this,t),high:new rt(this,t)},this.current_loading_state=new st(this,t)}get loading_progress(){return this.current_loading_state.loading_progress}init(){this.initialized=!0}load(){this.initialized||this.init(),this.set_loading_state(this.loading_states.regular),this.current_loading_state.load()}get_objects(){const e=[];return this.traverse((t=>{t instanceof o&&t.geometry&&e.push(t)})),e}dispose_cpu(){this.traverse((e=>{if(e instanceof o&&e.geometry&&(e.geometry.attributes.position.array=new Float32Array(3),e.geometry.attributes.normal&&(e.geometry.attributes.normal.array=new Float32Array(3)),e.geometry.attributes.uv&&(e.geometry.attributes.uv.array=new Float32Array(2)),e.material.map))for(let t=0;t<e.material.map.mipmaps.length;t++)e.material.map.mipmaps[t]=new Uint8Array(4)})),this.initialized=!1}dispose(){this.traverse((e=>{e instanceof o&&e.material&&(e.material.map&&e.material.map.dispose(),e.material.dispose(),e.geometry.dispose())})),this.initialized=!1}set_assets(e,t,s,r,i,n){this.loading_states.regular.set_assets(e,t,s,r,i,n)}set_high_assets(e,t,s,r,i,n){this.loading_states.high.set_assets(e,t,s,r,i,n)}set_loading_state(e){this.current_loading_state.on_exit(),this.current_loading_state=e,this.current_loading_state.on_enter()}update_loading_state(){this.is_high_loaded||this.current_loading_state.update()}update(){this.update_loading_state()}on_assets_ready(){}on_assets_compiled(){this.is_loaded=!0,this.set_loading_state(this.loading_states.high),this.current_loading_state.load()}on_high_quality_assets_ready(){this.is_high_loaded=!0}on_pre_render(){}render(){qe.render(this,Pe.current)}on_post_render(){}}class ot{constructor(e,t,s){this.name=e,this.method=t,this.args=s}trigger(){ViewApi.application[this.name][this.method](...this.args.split(","))}}class at{constructor(){}static linear_map(e,t,s,r,i){return(e-t)/(s-t)*(i-r)+r}static between(e,t,s){return e>=t&&e<=s}static mod(e,t){return(e%t+t)%t}static rgb_to_hex(e){return e.r=Math.round(255*parseFloat(e.r)).toString(16),e.g=Math.round(255*parseFloat(e.g)).toString(16),e.b=Math.round(255*parseFloat(e.b)).toString(16),1===e.r.length&&(e.r="0"+e.r),1===e.g.length&&(e.g="0"+e.g),1===e.b.length&&(e.b="0"+e.b),"#"+e.r+e.g+e.b}static project_points_on_plane(e,t){const s=e[0].clone();s.set(0,0,0);const r=[];for(let i=0;i<e.length;i++)t.projectPoint(e[i],s),r.push(s.clone());return r}static matrix4_lerp(e,t,s,r){for(let i=0;i<16;i++)s.elements[i]=this.lerp(e.elements[i],t.elements[i],r)}static equals(e,t){return Math.abs(e-t)<1e-6}static lerp(e,t,s){return(1-s)*e+s*t}static clamp(e,t,s){return Math.max(t,Math.min(s,e))}static euclideanModulo(e,t){return(e%t+t)%t}static pingpong(e,t=1){return t-Math.abs(at.euclideanModulo(e,2*t)-t)}static degToRad(e){return e*(Math.PI/180)}static radToDeg(e){return e*(180/Math.PI)}static deg_to_rad(e){return e*(Math.PI/180)}static rad_to_deg(e){return e*(180/Math.PI)}static perspective_divide(e){return e.x/=e.w,e.y/=e.w,e.z/=e.w,e}static points_average(e){const t=e[0].clone();for(let s=1;s<e.length;s++)t.add(e[s]);return t.multiplyScalar(1/e.length),t}static get_random_color(){const e=[0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f"];let t="#";return t+=e[Math.floor(16*Math.random())],t+=e[Math.floor(16*Math.random())],t+=e[Math.floor(16*Math.random())],t+=e[Math.floor(16*Math.random())],t+=e[Math.floor(16*Math.random())],t+=e[Math.floor(16*Math.random())],t}static saturate(e){return at.clamp(e,0,1)}static generate_uuid(){const e=["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"],t=4294967295*Math.random()|0,s=4294967295*Math.random()|0,r=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return(e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]+"-"+e[255&s]+e[s>>8&255]+"-"+e[s>>16&15|64]+e[s>>24&255]+"-"+e[63&r|128]+e[r>>8&255]+"-"+e[r>>16&255]+e[r>>24&255]+e[255&i]+e[i>>8&255]+e[i>>16&255]+e[i>>24&255]).toLowerCase()}}class lt{constructor(e={}){this.previous_elapsed_time=-1e-5,this.elapsed_time=-1e-5,this.playback_speed=this.__get_playback_speed(),this.playing=!0,this.action_events=[],this.context=e,this.initial_context=JSON.parse(JSON.stringify(e)),this.tmp_t=0,this.channels={};const t=Object.keys(e);for(let e=0;e<t.length;e++)this.channels[t[e]]=[];this.duration=0}play(){this.playing=!0}stop(){this.playing=!1}reset(){this.elapsed_time=-1e-5}skip(){const e=this.get_duration();this.__play_clips(this.elapsed_time,e+1e-4),this.elapsed_time=e}update(e){this.playing&&(this.previous_elapsed_time=this.elapsed_time,this.elapsed_time+=e*this.playback_speed,this.__play_clips(this.previous_elapsed_time,this.elapsed_time))}set_progress(e){this.previous_elapsed_time=this.elapsed_time,this.elapsed_time=at.clamp(e,0,this.duration),this.__play_clips(this.elapsed_time,this.elapsed_time)}set_normalized_progress(e){this.previous_elapsed_time=this.elapsed_time,this.elapsed_time=at.clamp(e,0,1)*this.duration,this.__play_clips(this.elapsed_time,this.elapsed_time)}get_progress(){return at.clamp(this.elapsed_time/this.get_duration(),0,1)}is_finished(){return this.elapsed_time>this.get_duration()}add_action_event(e,t){this.action_events.push({trigger_time:e,action:t}),this.duration=Math.max(this.duration,e)}add_action_interpolator(e,t,s,r=!1){if(r){const e=this.channels[s.attribute_name];void 0===e&&console.error(`${s.attribute_name} missing in initial state data.`),0===e.length?s.from=this.initial_context[s.attribute_name]:s.from=e[e.length-1].interpolator.to}const i={from:e,to:t,interpolator:s};this.duration=Math.max(this.duration,t),this.channels[s.attribute_name].push(i)}get_current_target_value(e){const t=this.__get_current_keyframe(e,this.elapsed_time);return this.elapsed_time<t.from?t.interpolator.evaluate(0):t.interpolator.evaluate(1)}get_current_starting_value(e){return this.__get_current_keyframe(e,this.elapsed_time).interpolator.evaluate(0)}get_current_progress(e){const t=this.__get_current_keyframe(e,this.elapsed_time),s=this.__linear_map_01(this.elapsed_time,t.from,t.to);return t.interpolator.easing_function(s)}get_duration(){return this.duration}__play_clips(e,t){this.elapsed_time>this.previous_elapsed_time&&this.__play_events(this.previous_elapsed_time,this.elapsed_time);const s=Object.keys(this.initial_context);for(let t=0;t<s.length;t++){const r=s[t],i=this.__get_current_keyframe(r,e);this.context[r]=this.evaluate_keyframe(i,e)}}__play_events(e,t){for(let s=0;s<this.action_events.length;s++){const r=this.action_events[s].trigger_time;at.between(r,e,t)&&this.action_events[s].action.trigger()}}evaluate_keyframe(e,t){return this.tmp_t=this.__linear_map_01(t,e.from,e.to),e.interpolator.evaluate(at.clamp(this.tmp_t,0,1))}get_keyframes(e){return this.channels[e]}is_channel_redefined(e){for(let t=0;t<this.channels[e].length;t++){if(this.channels[e][t].interpolator.initial)return!1}return!0}__linear_map_01(e,t,s){return at.saturate((e-t)/(s-t)*1+0)}__get_current_keyframe(e,t){let s;const r=this.channels[e];for(let e=0;e<r.length;e++){const i=r[e];if(t>=i.from&&t<=i.to)return s=i,s}let i=1/0;for(let e=0;e<r.length;e++){const n=r[e],o=Math.abs(n.to-t);o<i&&(s=n,i=o)}return s}__get_playback_speed(){const e=new URLSearchParams(window.location.search).get("transitions_velocity");return e?Number(e):1}set_initial_value_on_channel(e,t){this.get_keyframes(e)[0].interpolator.from=t}set_final_value_on_channel(e,t){const s=this.get_keyframes(e);s[s.length-1].interpolator.to=t}}class _t{constructor(){}static linear(e){return e}static triangular(e){return 1-Math.abs(2*e%2-1)}static ease_in_sine(e){return 1-Math.cos(3.1415926*e/2)}static ease_out_sine(e){return Math.sin(3.1415926*e/2)}static ease_in_out_sine(e){return-(Math.cos(3.1415926*e)-1)/2}static ease_in_cubic(e){return e*e*e}static ease_out_cubic(e){return 1-Math.pow(1-e,3)}static ease_in_out_cubic(e){return e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2}static ease_in_quad(e){return e*e}static ease_out_quad(e){return 1-(1-e)*(1-e)}static ease_in_out_quad(e){return e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2}static ease_in_quart(e){return e*e*e*e}static ease_out_quart(e){return 1-Math.pow(1-e,4)}static ease_in_out_quart(e){return e<.5?8*e*e*e*e:1-Math.pow(-2*e+2,4)/2}static ease_in_quint(e){return e*e*e*e*e}static ease_out_quint(e){return 1-Math.pow(1-e,5)}static ease_in_out_quint(e){return e<.5?16*e*e*e*e*e:1-Math.pow(-2*e+2,5)/2}static ease_in_expo(e){return 0===e?0:Math.pow(2,10*e-10)}static ease_out_expo(e){return 1===e?1:1-Math.pow(2,-10*e)}static ease_in_out_expo(e){return 0===e?0:1===e?1:e<.5?Math.pow(2,20*e-10)/2:(2-Math.pow(2,-20*e+10))/2}static ease_in_circ(e){return 1-Math.sqrt(1-Math.pow(e,2))}static ease_out_circ(e){return Math.sqrt(1-Math.pow(e-1,2))}static ease_in_out_circ(e){return e<.5?(1-Math.sqrt(1-Math.pow(2*e,2)))/2:(Math.sqrt(1-Math.pow(-2*e+2,2))+1)/2}static ease_in_back(e){return 2.7015*e*e*e-1.7015*e*e}static ease_out_back(e){return 1+2.7015*Math.pow(e-1,3)+1.7015*Math.pow(e-1,2)}static ease_in_out_back(e){return e<.5?Math.pow(2*e,2)*(7.189819*e-2.5949095)/2:(Math.pow(2*e-2,2)*(3.5949095*(2*e-2)+2.5949095)+2)/2}static ease_in_elastic(e){const t=2*Math.PI/3;return 0===e?0:1===e?1:-Math.pow(2,10*e-10)*Math.sin((10*e-10.75)*t)}static ease_out_elastic(e){return 0===e?0:1===e?1:Math.pow(2,-10*e)*Math.sin(2.094395*(10*e-.75))+1}static ease_in_out_elastic(e){return 0===e?0:1===e?1:e<.5?-Math.pow(2,20*e-10)*Math.sin(1.3962633*(20*e-11.125))/2:Math.pow(2,-20*e+10)*Math.sin(1.3962633*(20*e-11.125))/2+1}static ease_in_bounce(e){return 1-this.ease_out_bounce(1-e)}static ease_out_bounce(e){const t=7.5625,s=2.75;return e<1/s?t*e*e:e<2/s?t*(e-=1.5/s)*e+.75:e<2.5/s?t*(e-=2.25/s)*e+.9375:t*(e-=2.625/s)*e+.984375}static ease_in_out_bounce(e){return e<.5?(1-this.ease_out_bounce(1-2*e))/2:(1+this.ease_out_bounce(2*e-1))/2}static heartbeat(e){return 1-Math.pow(Math.abs(Math.sin(e+1)),63)*Math.sign(Math.sin(e))*Math.sin(e+1.5+1)*.8}}class ht{constructor(e="linear"){this.easing_function=void 0,this.easing_function="string"==typeof e?_t[e]:e,this.attribute_name="",this.from=0,this.to=1}update(e,t){}}class ct extends ht{constructor(e,t=0,s=1,r=!1,i="linear"){super(i),this.attribute_name=e,this.from=t,this.to=s,this.initial=r}update(e,t){e[this.attribute_name]=at.lerp(this.from,this.to,this.easing_function(t))}evaluate(e){return at.lerp(this.from,this.to,this.easing_function(e))}}class ut{constructor(){}parse(e){const t=(new DOMParser).parseFromString(e,"text/xml").querySelectorAll("mxGeometry"),s=[],r=[];for(let e=0;e<t.length;e++){const i=t[e],n=i.parentElement,o=n.getAttribute("value"),a=this.get_node_x_position(i)/100,l=parseFloat(i.getAttribute("width"))/100;if(n.getAttribute("style").includes("rhombus;")){const e=o.split("."),t=e[0],s=e[1];r.push({name:t,method:s,at_time:a+.5*l})}if(n.getAttribute("style").includes("rounded=0;")&&!n.getAttribute("style").includes("text;")&&""!==o&&!o.includes(" ")){const e=o.split("="),t=e[0],r=e[1].split("--"),i=parseFloat(r[0]),n=r[1];2!==e.length&&console.error("DrawIO data is malformed:",o),2!==r.length&&console.error("DrawIO data is malformed:",o),s.push({attribute_name:t,from_time:a,to_time:a+l,to_value:i,easing_function:n})}}return s.sort(((e,t)=>e.from_time-t.from_time)),{animation_tracks:s,triggers:r}}get_node_x_position(e){const t=e.getAttribute("x");return null===t?0:parseFloat(t)}}class dt{constructor(e){this.default_state_data=e}from_animation_sheet(e,t,s){s=s||this.default_state_data;const r=e.animation_tracks,i=e.triggers,n=this.state_to_tracks(this.default_state_data,this.get_longest_time(e.animation_tracks));for(let e=0;e<n.length;e++)void 0===r.find((t=>t.attribute_name===n[e].attribute_name))&&r.push(n[e]);const o=new lt(t);for(let e=0;e<r.length;e++){const s=r[e],i=new ct(s.attribute_name,t[s.attribute_name],s.to_value,s.initial,s.easing_function);o.add_action_interpolator(s.from_time,s.to_time,i,!0)}for(let e=0;e<i.length;e++){const t=i[e],s=new ot(t.name,t.method,t.args);o.add_action_event(t.at_time,s)}return o}state_to_tracks(e,t){const s=[],r=Object.keys(e);for(let i=0;i<r.length;i++)s.push({attribute_name:r[i],from_time:0,to_time:t<1?t:1,to_value:e[r[i]],initial:!0,easing_function:"ease_in_out_cubic"});return s}from_draw_io(e,t){const s=(new ut).parse(e),r=s.animation_tracks,i=s.triggers,n=new lt(t);for(let e=0;e<r.length;e++){const s=r[e],i=new ct(s.attribute_name,t[s.attribute_name],s.to_value,!1,s.easing_function);n.add_action_interpolator(s.from_time,s.to_time,i,!0)}for(let e=0;e<i.length;e++){const t=i[e],s=new ot(t.name,t.method);n.add_action_event(t.at_time,s)}return n}get_longest_time(e){let t=-1;for(let s=0;s<e.length;s++){const r=e[s].to_time;t=r>t?r:t}return t}}class pt{constructor(){this.transitions=[],this.default_state_data={}}get(e,t,s){for(let r=0;r<this.transitions.length;r++)if(this.transitions[r].from===e&&this.transitions[r].to===t){return new dt(this.default_state_data).from_animation_sheet(this.transitions[r].data,s)}for(let e=0;e<this.transitions.length;e++)if(this.transitions[e].to===t&&void 0===this.transitions[e].from){return new dt(this.default_state_data).from_animation_sheet(this.transitions[e].data,s)}console.error("TransitionTable.get no data found for: ",e,t)}add_transitions(e){for(let t=0;t<e.length;t++)this.transitions.push(e[t])}set_transitions(e){this.transitions=e}set_default_state_data(e){this.default_state_data=e}}const mt=new class{constructor(){this.__delta_buffer=[.016,.016,.016,.016,.016,.016,.016,.016,.016,.016]}init(){this.__previous_elapsed_time=-1,this.__delta_time=0,this.__smooth_delta_time=0,this.__elapsed_time=0,this.__frame_interpolation_t=0,this.fixed_delta_time=1/30}get elapsed_time(){return this.__elapsed_time}get delta_time(){return this.__delta_time}get smooth_delta_time(){return this.__smooth_delta_time}get frame_interpolation(){return this.__frame_interpolation_t}get fdt(){return this.fixed_delta_time}get dt(){return this.delta_time}get sdt(){return this.smooth_delta_time}__set_frame_interpolation(e){this.__frame_interpolation_t=e}__update(e){this.__previous_elapsed_time<0&&(this.__previous_elapsed_time=e),this.__delta_time=(e-this.__previous_elapsed_time)/1e3,this.__elapsed_time=e/1e3,this.__delta_buffer.shift(),this.__delta_buffer.push(this.delta_time<.32?this.delta_time:.032),this.__calculate_smooth_delta_time(),this.__previous_elapsed_time=e}__calculate_smooth_delta_time(){this.__smooth_delta_time=0;for(let e=0;e<this.__delta_buffer.length;e++)this.__smooth_delta_time+=this.__delta_buffer[e];this.__smooth_delta_time=this.__smooth_delta_time/this.__delta_buffer.length}};class gt{constructor(e){this.name=e}start(){}before_enter(){}on_enter(){}before_exit(){}on_exit(){}before_update(){}update(){}fixed_update(){}update_enter_transition(e,t,s){}update_exit_transition(e,t,s){}}class ft{constructor(e){this.last_state=new gt("last_initial"),this.current_state=new gt("current_initial"),this.default_state_data={},this.current_state_data={},this.transition_table=e,this.transitioning=!1}go_to_state(e,t=!1){this.transitioning&&this.__exit_last_state(),this.last_state=this.current_state,this.current_state=e,this.last_state.before_exit(),this.current_state.before_enter(),this.action_sequencer=this.transition_table.get(this.last_state.name,this.current_state.name,this.current_state_data),this.action_sequencer.play(),this.transitioning=!0,t&&(this.action_sequencer.skip(),this.update())}update(){this.transitioning?(this.__update_transitions(),this.action_sequencer.is_finished()&&(this.transitioning=!1,this.__update_transitions(),this.__exit_last_state(),this.current_state.on_enter())):this.current_state.update()}before_update(){this.current_state.before_update()}fixed_update(){this.current_state.fixed_update()}set_state(e){this.current_state=e}set_default_state_data(e){Object.assign(this.default_state_data,e),Object.assign(this.current_state_data,e)}__update_transitions(){this.action_sequencer.update(mt.delta_time),this.last_state.update_exit_transition(this.current_state_data,this.action_sequencer.get_progress(),this.action_sequencer),this.current_state.update_enter_transition(this.current_state_data,this.action_sequencer.get_progress(),this.action_sequencer)}__exit_last_state(){this.last_state.on_exit()}}const vt=new class{constructor(){this.transition_table=new pt,this.transition_handler=new ft(this.transition_table)}get action_sequencer(){return this.transition_handler.action_sequencer}get current_state_data(){return this.transition_handler.current_state_data}get_current_state(){return this.transition_handler.current_state}go_to_state(e,t=!1){this.transition_handler.go_to_state(e,t)}before_update(){this.transition_handler.before_update()}update(){this.transition_handler.update()}fixed_update(){this.transition_handler.fixed_update()}add_transitions(e){this.transition_table.add_transitions(e)}set_transitions(e){this.transition_table.set_transitions(e)}set_state(e){this.transition_handler.set_state(e)}set_default_state_data(e){this.transition_table.set_default_state_data(e),this.transition_handler.set_default_state_data(e)}};const yt=new class{constructor(){this.views=[],this.browser_title_suffix=""}update(){this.__set_views_opacities()}go_to_view(e,t=!0,s=!1){const r=this.get(e);t&&(this.__change_browser_url(r.url),this.__change_browser_title(r.url)),vt.go_to_state(r,s)}go_to_scene(e,t=!1,s=!1){const r=this.get(e),i=this.get("transition");i.set_next_view(r),this.go_to_view(i.name,t,s)}register_view(e){this.views.push(e)}has_view(e){for(let t=0;t<this.views.length;t++)if(this.views[t].name===e)return!0;return!1}set_view(e){const t=this.get(e);vt.set_state(t)}set_browser_title_suffix(e){this.browser_title_suffix=e}get_current_view(){return vt.get_current_state()}get_view_by_name(e){console.warn("DEPRECATED. Use ViewManager.get instead"),this.get(e)}get(e){for(let t=0;t<this.views.length;t++)if(this.views[t].name===e)return this.views[t];console.error("[ViewManager.get] no view found for: ",e)}get_by_url(e){for(let t=0;t<this.views.length;t++)if(this.views[t].url===e)return this.views[t];console.error("[ViewManager.get_by_url] no view found for: ",e)}__change_browser_url(e){window.history.pushState("","",e)}__change_browser_title(e){const t=this.__capitalize(e);document.title=t?`${t} | ${this.browser_title_suffix}`:this.browser_title_suffix}__set_views_opacities(){for(let e=0;e<this.views.length;e++)this.views[e].set_opacity(vt.current_state_data)}__capitalize(e){let t=e.toUpperCase().replace("/","");return t=this.__snake_to_whitespace(t),t}__snake_to_whitespace(e){return e.replace(/([-_][A-Z])/g,(e=>e.replace("-"," ").replace("_"," ")))}};class bt extends gt{constructor({name:e,url:t,container:s,transition_data:r}){super(e),this.container=s,this.url=t,this.current_opacity=0;const i=[{to:e,data:r=r||{animation_tracks:[],triggers:[]}}];yt.register_view(this),vt.add_transitions(i)}before_enter(){this.container.classList.add("before_enter"),this.container.classList.remove("before_exit"),this.container.classList.remove("hidden")}on_enter(){this.container.classList.remove("before_enter"),this.container.classList.remove("before_exit"),this.container.classList.remove("hidden")}before_exit(){this.container.classList.add("before_exit"),this.container.classList.remove("before_enter"),this.container.classList.remove("hidden")}on_exit(){this.container.classList.add("hidden"),this.container.classList.remove("before_enter"),this.container.classList.remove("before_exit")}set_opacity(e){const t=e[`${this.name}_opacity`];(this.current_opacity>t||this.current_opacity<t)&&(this.current_opacity=t,this.container.style.opacity=this.current_opacity)}}class wt{constructor(e){this.uses_dynamic_font=!!e,this.__textHeight=null,this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d")}getFontHeight(e="Arial"){if(null==this.__textHeight||this.uses_dynamic_font){const t=document.getElementsByTagName("body")[0],s=document.createElement("div"),r=document.createTextNode("MÉqgOLAKTAL");s.appendChild(r),s.setAttribute("style",`font:${e};position:absolute;top:0;left:0`),t.appendChild(s),this.__textHeight=s.offsetHeight,t.removeChild(s)}return this.__textHeight}get_text_size(e,s="24px Arial"){const r=new t;return this.ctx.font=s,r.x=Math.ceil(this.ctx.measureText(e).width),r.y=Math.ceil(this.getFontHeight(s)),r}draw_canvas(e,t={}){return t.font=t.font||"24px Arial",t.font_color=t.font_color||"#000000",this.__draw(e,t,this.canvas,this.ctx),this.canvas}draw_on_texture(e,t){const s=this.draw_canvas(e,t),r=new y(s,b,w,w,x,x);return r.generateMipmaps=!1,r.needsUpdate=!0,r}__draw(e,t,s,r){}roundRect(e,t,s,r,i,n,o,a){if(void 0===a&&(a=!0),void 0===n&&(n=5),"number"==typeof n)n={tl:n,tr:n,br:n,bl:n};else{const e={tl:0,tr:0,br:0,bl:0};for(const t in e){const s=t;n[s]=n[s]||e[s]}}e.beginPath(),e.moveTo(t+n.tl,s),e.lineTo(t+r-n.tr,s),e.quadraticCurveTo(t+r,s,t+r,s+n.tr),e.lineTo(t+r,s+i-n.br),e.quadraticCurveTo(t+r,s+i,t+r-n.br,s+i),e.lineTo(t+n.bl,s+i),e.quadraticCurveTo(t,s+i,t,s+i-n.bl),e.lineTo(t,s+n.tl),e.quadraticCurveTo(t,s,t+n.tl,s),e.closePath(),o&&e.fill(),a&&e.stroke()}}class xt extends wt{constructor(){super(),this.text_margin=new t(2,0)}__draw(e,t,s,r){r.font=t.font;const i=this.get_text_size(e,t.font);s.width=Math.ceil(i.x+2*this.text_margin.x),s.height=Math.ceil(i.y+2*this.text_margin.y),r.clearRect(0,0,s.width,s.height),r.globalAlpha=0,r.fillStyle=t.font_color||"#000000",r.fillRect(0,0,s.width,s.height),r.globalAlpha=1,r.globalAlpha=1,r.font=t.font,r.fillStyle=t.font_color||"#000000",r.textBaseline="middle",r.textAlign=t.textAlign||"center","center"===r.textAlign?r.fillText(e,s.width/2,s.height/2):r.fillText(e,0,s.height/2)}}const Mt=new class{init(){this.max_anisotropy=0,this.vertex_texture_sampler_available=!1,this.fp_textures_available=!1}};class St{get(e,t){return this.describe(this.require_camera(e),t)}set(e,t,s){const r=this.require_camera(e),i=[];null!==t&&this.apply_orbit(t,s,i),this.apply_position(r,t,s,i),this.apply_fov(r,s,i);const n=this.describe(r,t);return n.changed=i,n}frame(e,t,s,r,i){const n=this.require_camera(e);if(null===t)throw this.error("no_controller","The active scene has no camera_controller, so framing is unavailable.");const o="string"==typeof r.uuid?r.uuid:null,a="string"==typeof r.name?r.name:null;if(null===o&&null===a)throw this.error("not_found","Pass a uuid or a name to identify the object to frame.");const l=this.find(s,o,a);if(null===l){const e=null===o?`name '${null===a?"":a}'`:`uuid '${o}'`;throw this.error("not_found",`No object matching ${e} in the current scene.`)}const _="number"==typeof r.scale&&Number.isFinite(r.scale)?r.scale:1;t.focus_on_bounding_box(i(l),_);const h=this.describe(n,t);return h.changed=["framed"],h}apply_orbit(e,t,s){const r=this.number(t.tilt),i=this.number(t.orientation),n=this.number(t.azimuth);null===r&&null===i&&null===n||(null!==r&&s.push("tilt"),null!==i&&s.push("orientation"),null!==n&&s.push("azimuth"),e.set_rotation(null===r?void 0:r,null===i?void 0:i,null===n?void 0:n));const o=this.number(t.zoom);null!==o&&(e.set_normalized_zoom(o),s.push("zoom"));const a=this.triple(t.target);null!==a&&(e.reference_position.x=a[0],e.reference_position.y=a[1],e.reference_position.z=a[2],s.push("target"))}apply_position(e,t,s,r){const i=this.triple(s.position);if(null!==i){if(null!==t)throw this.error("controller_owns_camera","A CameraController is driving this camera and would overwrite a raw position on the next frame. Use tilt, orientation, azimuth, zoom and target instead.");e.position.x=i[0],e.position.y=i[1],e.position.z=i[2],r.push("position")}}apply_fov(e,t,s){const r=this.number(t.fov);null!==r&&(e.fov=r,s.push("fov"),"function"==typeof e.updateProjectionMatrix&&e.updateProjectionMatrix())}describe(e,t){return{position:[this.round(e.position.x),this.round(e.position.y),this.round(e.position.z)],fov:"number"==typeof e.fov?e.fov:null,near:"number"==typeof e.near?e.near:null,far:"number"==typeof e.far?e.far:null,clear_color:this.hex(e.clear_color),clear_alpha:"number"==typeof e.clear_alpha?e.clear_alpha:null,controller:null===t?null:{tilt:t.get_current_tilt(),orientation:t.get_current_orientation(),azimuth:t.get_current_azimuth(),zoom:t.normalized_zoom,min_zoom:t.min_zoom,max_zoom:t.max_zoom,target:[this.round(t.reference_position.x),this.round(t.reference_position.y),this.round(t.reference_position.z)]}}}find(e,t,s){if(null!==t?e.uuid===t:e.name===s)return e;const r=Array.isArray(e.children)?e.children:[];for(const e of r){const r=this.find(e,t,s);if(null!==r)return r}return null}require_camera(e){if("object"!=typeof e||null===e||"object"!=typeof e.position)throw this.error("no_camera","No camera is active. CameraManager.current is not set yet.");return e}hex(e){return"object"!=typeof e||null===e||"function"!=typeof e.getHexString?null:`#${e.getHexString()}`}number(e){return"number"==typeof e&&Number.isFinite(e)?e:null}triple(e){if(!Array.isArray(e))return null;const t=e,s=[];for(let e=0;e<3;e++){const r=this.number(t[e]);if(null===r)return null;s.push(r)}return s}round(e){return"number"==typeof e&&Number.isFinite(e)?Math.round(1e4*e)/1e4:0}error(e,t){const s=new Error(t);return s.code=e,s}}class zt{constructor(e,t,s=(()=>document.createElement("canvas"))){this.graphics=e,this.has_camera=t,this.create_canvas=s}async capture(e){return"hires"===e.mode?this.capture_hires(e):this.capture_fast(e)}async capture_fast(e){const t=this.graphics.canvas,s=this.scaled_size(t.width,t.height,e.max_size);if(null!==s){const e=this.draw_scaled(t,s.width,s.height);if(null!==e){const r=await this.request_blob((t=>e.toBlob(t,"image/png"))),i=await this.build_result("fast",s.width,s.height,r);return i.scaled_from={width:t.width,height:t.height},i}}const r=await this.request_blob((e=>t.toBlob(e,"image/png")));return this.build_result("fast",t.width,t.height,r)}scaled_size(e,t,s){const r="number"==typeof s?s:1280;if(!Number.isFinite(r)||r<=0)return null;const i=Math.max(e,t);if(i<=r)return null;const n=r/i;return{width:Math.max(1,Math.round(e*n)),height:Math.max(1,Math.round(t*n))}}draw_scaled(e,t,s){const r=this.create_canvas();r.width=t,r.height=s;const i=r.getContext("2d");return null===i?null:(i.drawImage(e,0,0,t,s),r)}async capture_hires(e){if(!this.has_camera())throw this.error("no_camera","A hires capture needs an active camera; CameraManager.current is not set yet.");const t=this.graphics.canvas,s=this.dimension(e.width,t.width),r=this.dimension(e.height,t.height),i=await this.request_blob((e=>this.graphics.take_screenshot(e,s,r)));return this.build_result("hires",s,r,i)}dimension(e,t){return"number"==typeof e?this.clamp(e):this.clamp(t)}clamp(e){return!Number.isFinite(e)||e<1?1:Math.min(Math.floor(e),8192)}request_blob(e){return new Promise(((t,s)=>{e((e=>{null!==e?t(e):s(this.error("capture_failed","The canvas produced no image data."))}))}))}async build_result(e,t,s,r){const i=await r.arrayBuffer(),n=new Uint8Array(i);return{mode:e,mime_type:"image/png",width:t,height:s,bytes:n.length,data:this.to_base64(n)}}to_base64(e){let t="";for(let s=0;s<e.length;s+=8192)t+=String.fromCharCode(...e.subarray(s,s+8192));return btoa(t)}error(e,t){const s=new Error(t);return s.code=e,s}}const Tt=2e3,kt=["log","info","warn","error"];class At{constructor(e=200,t=(()=>Date.now())){this.capacity=e>0?Math.floor(e):200,this.entries=[],this.seq=0,this.dropped=0,this.clock=t,this.target=null,this.source=null,this.originals={},this.on_error=null,this.on_rejection=null}install(e,t){this.dispose(),this.target=e;for(const t of kt){const s=e[t];this.originals[t]=s,e[t]=(...r)=>{this.push(t,this.format(r)),s.apply(e,r)}}void 0!==t&&(this.source=t,this.on_error=e=>this.push("error",this.event_message(e)),this.on_rejection=e=>this.push("error",`Unhandled rejection: ${this.event_reason(e)}`),t.addEventListener("error",this.on_error),t.addEventListener("unhandledrejection",this.on_rejection))}dispose(){const e=this.target;if(null!==e)for(const t of kt){const s=this.originals[t];void 0!==s&&(e[t]=s)}const t=this.source;null!==t&&(null!==this.on_error&&t.removeEventListener("error",this.on_error),null!==this.on_rejection&&t.removeEventListener("unhandledrejection",this.on_rejection)),this.originals={},this.target=null,this.source=null,this.on_error=null,this.on_rejection=null}read(e){const t="string"==typeof e.level?e.level:null,s="number"==typeof e.since?e.since:0,r="number"==typeof e.limit&&e.limit>0?Math.floor(e.limit):0;let i=this.entries.filter((e=>e.seq>s));return null!==t&&(i=i.filter((e=>e.level===t))),r>0&&i.length>r&&(i=i.slice(i.length-r)),{entries:i,dropped:this.dropped,total:this.seq,capacity:this.capacity}}push(e,t){for(this.seq++,this.entries.push({seq:this.seq,level:e,message:t,at:this.clock()});this.entries.length>this.capacity;)this.entries.shift(),this.dropped++}format(e){const t=e.map((e=>this.describe(e))).join(" ");if(t.length<=Tt)return t;const s=t.length-Tt;return`${t.slice(0,Tt)} ... [truncated ${s} chars]`}describe(e){if("string"==typeof e)return e;if(null===e)return"null";if(void 0===e)return"undefined";if("number"==typeof e||"boolean"==typeof e)return String(e);if("function"==typeof e)return"[function]";if("symbol"==typeof e)return"[symbol]";if("bigint"==typeof e)return`${e.toString()}n`;if(e instanceof Error)return`${e.name}: ${e.message}`;try{const t=JSON.stringify(e);return void 0===t?"[unserialisable]":t}catch{return"[unserialisable]"}}event_message(e){if("object"==typeof e&&null!==e){const t=e;if("string"==typeof t.message)return t.message;if(void 0!==t.error)return this.describe(t.error)}return this.describe(e)}event_reason(e){if("object"==typeof e&&null!==e){const t=e;if(void 0!==t.reason)return this.describe(t.reason)}return this.describe(e)}}const Ft={left:0,middle:1,right:2};class Ct{constructor(e,t,s){this.dispatch=e,this.sleep=t,this.to_client=s}async pointer(e){const t=this.text(e.action,"click"),s=this.space(e.space),r=this.point(e.x,e.y,s),i=this.button(e.button),n=Math.min(1e4,this.positive(e.hold_ms,60)),o=[];if("move"!==t&&"down"!==t&&"click"!==t||(this.send("mousemove",{clientX:r.x,clientY:r.y}),o.push("mousemove")),"down"!==t&&"click"!==t||(this.send("mousedown",{clientX:r.x,clientY:r.y,button:i}),o.push("mousedown")),"click"===t&&await this.sleep(n),"up"!==t&&"click"!==t||(this.send("mouseup",{clientX:r.x,clientY:r.y,button:i}),o.push("mouseup")),0===o.length)throw this.error("bad_request",`Unknown pointer action '${t}'. Use click, down, up or move.`);return{dispatched:o,at:[r.x,r.y]}}async drag(e){const t=this.space(e.space),s=this.pair(e.from,t,"from"),r=this.pair(e.to,t,"to"),i=Math.min(120,Math.max(1,Math.floor(this.positive(e.steps,8)))),n=Math.min(1e4,this.positive(e.duration_ms,240)),o=this.button(e.button),a=[];this.send("mousemove",{clientX:s.x,clientY:s.y}),a.push("mousemove"),this.send("mousedown",{clientX:s.x,clientY:s.y,button:o}),a.push("mousedown");for(let e=1;e<=i;e++){const t=e/i;await this.sleep(n/i),this.send("mousemove",{clientX:s.x+(r.x-s.x)*t,clientY:s.y+(r.y-s.y)*t}),a.push("mousemove")}return this.send("mouseup",{clientX:r.x,clientY:r.y,button:o}),a.push("mouseup"),{dispatched:a,from:[s.x,s.y],to:[r.x,r.y]}}scroll(e){const t=this.number(e.delta);if(null===t)throw this.error("bad_request","scroll requires a numeric delta.");const s=this.space(e.space),r=this.point(void 0===e.x?0:e.x,void 0===e.y?0:e.y,s);return this.send("wheel",{clientX:r.x,clientY:r.y,deltaY:t}),Promise.resolve({dispatched:["wheel"],at:[r.x,r.y],delta:t})}async key(e){const t="string"==typeof e.code&&e.code.length>0?e.code:null;if(null===t)throw this.error("bad_request","key requires a code, for example 'Space' or 'KeyW'.");const s=this.text(e.action,"press"),r=Math.min(1e4,this.positive(e.hold_ms,60)),i=[];if("down"!==s&&"press"!==s||(this.send("keydown",{code:t,key:t}),i.push("keydown")),"press"===s&&await this.sleep(r),"up"!==s&&"press"!==s||(this.send("keyup",{code:t,key:t}),i.push("keyup")),0===i.length)throw this.error("bad_request",`Unknown key action '${s}'. Use press, down or up.`);return{dispatched:i,code:t}}send(e,t){this.dispatch(e,{...t,bubbles:!0,cancelable:!0})}point(e,t,s){const r=this.number(e),i=this.number(t);if(null===r||null===i)throw this.error("bad_request","x and y must be numbers.");return this.to_client(r,i,s)}pair(e,t,s){if(!Array.isArray(e)||e.length<2)throw this.error("bad_request",`${s} must be [x, y].`);const r=e;return this.point(r[0],r[1],t)}space(e){return"ndc"===e?"ndc":"pixels"}button(e){if("string"!=typeof e)return 0;const t=Ft[e.toLowerCase()];return void 0===t?0:t}text(e,t){return"string"==typeof e&&e.length>0?e.toLowerCase():t}number(e){return"number"==typeof e&&Number.isFinite(e)?e:null}positive(e,t){const s=this.number(e);return null===s||s<=0?t:s}error(e,t){const s=new Error(t);return s.code=e,s}}class Rt{read(e,t,s){const r={fps:this.rate(e.delta_time),smooth_fps:this.rate(e.smooth_delta_time),frame_ms:this.round(1e3*this.seconds(e.delta_time),100),elapsed_s:this.round(this.seconds(e.elapsed_time),10),canvas:{width:t.width,height:t.height,render_width:t.render_width,render_height:t.render_height,dpr:t.dpr}},i=this.section(s,"render"),n=this.section(s,"memory");return this.assign(r,"draw_calls",i,"drawCalls"),this.assign(r,"triangles",i,"triangles"),this.assign(r,"geometries",n,"geometries"),this.assign(r,"textures",n,"textures"),r}section(e,t){if("object"!=typeof e||null===e)return null;const s=e[t];return"object"!=typeof s||null===s?null:s}assign(e,t,s,r){if(null===s)return;const i=s[r];"number"==typeof i&&Number.isFinite(i)&&(e[t]=i)}rate(e){const t=this.seconds(e);return t<=0?0:this.round(1/t,10)}seconds(e){return"number"==typeof e&&Number.isFinite(e)&&e>0?e:0}round(e,t){return Math.round(e*t)/t}}class Pt{constructor(e){this.descriptors=e}list(){return this.descriptors.map((e=>({name:e.name,description:void 0===e.description?"":e.description,options:void 0===e.options?[]:e.options})))}create(e,t){const s="string"==typeof e?e.toLowerCase():null,r=null===s?void 0:this.descriptors.find((e=>e.name.toLowerCase()===s));if(void 0===r){const e=this.descriptors.map((e=>e.name)).join(", ");throw this.error("unknown_render_mode",`Unknown render mode. Available modes: ${e}.`)}return r.factory(t)}error(e,t){const s=new Error(t);return s.code=e,s}}class Lt{get(e,t){const s=this.require(e,t);return this.describe(s.node,s.parent)}set(e,t,s){const r=this.require(e,t),i=[];this.apply_vector(r.node.position,s.position)&&i.push("position"),this.apply_vector(r.node.rotation,s.rotation)&&i.push("rotation"),this.apply_vector(r.node.scale,s.scale)&&i.push("scale"),"boolean"==typeof s.visible&&(r.node.visible=s.visible,i.push("visible"));const n=this.describe(r.node,r.parent);return n.changed=i,n}require(e,t){if("object"!=typeof e||null===e)throw this.error("not_found","No scene is set. SceneManager.current is empty.");const s="string"==typeof t.uuid?t.uuid:null,r="string"==typeof t.name?t.name:null;if(null===s&&null===r)throw this.error("not_found","Pass a uuid or a name to identify the object.");const i=this.find(e,null,s,r);if(null===i){const e=null===s?`name '${null===r?"":r}'`:`uuid '${s}'`;throw this.error("not_found",`No object matching ${e} in the current scene.`)}return i}find(e,t,s,r){if(null!==s?e.uuid===s:e.name===r)return{node:e,parent:t};const i=Array.isArray(e.children)?e.children:[];for(const t of i){const i=this.find(t,e,s,r);if(null!==i)return i}return null}apply_vector(e,t){if("object"!=typeof e||null===e||!Array.isArray(t))return!1;const s=["x","y","z"],r=t;let i=!1;for(let t=0;t<s.length;t++){const n=r[t];"number"==typeof n&&Number.isFinite(n)&&(e[s[t]]=n,i=!0)}return i}describe(e,t){const s={uuid:"string"==typeof e.uuid?e.uuid:"(no uuid)",name:"string"==typeof e.name?e.name:"",type:"string"==typeof e.type?e.type:"Object3D",parent:this.parent_label(t),children:Array.isArray(e.children)?e.children.length:0,visible:!1!==e.visible,position:this.vector(e.position,0),rotation:this.vector(e.rotation,0),scale:this.vector(e.scale,1)},r=this.material_type(e.material);null!==r&&(s.material=r);const i=this.vertices(e.geometry);return null!==i&&(s.vertices=i),s}parent_label(e){return null===e?null:"string"==typeof e.name&&e.name.length>0?e.name:"string"==typeof e.uuid?e.uuid:null}material_type(e){if(Array.isArray(e))return`${e.length} materials`;if("object"==typeof e&&null!==e){const t=e.type;return"string"==typeof t?t:"Material"}return null}vertices(e){if("object"!=typeof e||null===e)return null;const t=e.attributes;if("object"!=typeof t||null===t)return null;const s=t.position;if("object"!=typeof s||null===s)return null;const r=s.count;return"number"==typeof r?r:null}vector(e,t){return"object"!=typeof e||null===e?[t,t,t]:[this.round(e.x,t),this.round(e.y,t),this.round(e.z,t)]}round(e,t){return"number"==typeof e&&Number.isFinite(e)?Math.round(1e4*e)/1e4:t}error(e,t){const s=new Error(t);return s.code=e,s}}class Dt{inspect(e,t){if("object"!=typeof e||null===e)return{root:null,counts:{total:0,meshes:0,returned:0},truncated:!1,notes:["No scene is set. SceneManager.current is empty."]};const s=this.positive(t.depth,4),r=this.positive(t.max_nodes,200),i="string"==typeof t.filter&&t.filter.length>0?t.filter.toLowerCase():null,n=[],o=this.count(e);let a=null;null!==i&&(a=new Set,this.mark(e,i,a),0===a.size&&(n.push(`no nodes matched the filter '${i}'`),a=new Set([e])));const l={used:0,depth_cut:!1,node_cut:!1},_=this.serialise(e,0,s,r,a,l);return l.node_cut&&n.push(`stopped at max_nodes=${r}; ${o.total-l.used} of ${o.total} nodes not returned`),l.depth_cut&&n.push(`stopped at depth=${s}; deeper nodes not returned`),{root:_,counts:{total:o.total,meshes:o.meshes,returned:l.used},truncated:l.node_cut||l.depth_cut,notes:n}}serialise(e,t,s,r,i,n){if(null!==i&&!i.has(e))return null;if(n.used>=r)return n.node_cut=!0,null;n.used++;const o={uuid:"string"==typeof e.uuid?e.uuid:"(no uuid)",name:"string"==typeof e.name?e.name:"",type:"string"==typeof e.type?e.type:"Object3D",position:this.vector(e.position,0)},a=this.vector(e.rotation,0),l=this.vector(e.scale,1);this.is_uniform(a,0)||(o.rotation=a),this.is_uniform(l,1)||(o.scale=l),!1===e.visible&&(o.visible=!1);const _=this.describe_material(e.material);null!==_&&(o.material=_);const h=this.count_vertices(e.geometry);null!==h&&(o.vertices=h);const c=Array.isArray(e.children)?e.children:[];if(0===c.length)return o;if(t+1>s)return n.depth_cut=!0,o.truncated=`${c.length} children hidden (depth limit ${s})`,o;const u=[];let d=0;for(const e of c){const o=this.serialise(e,t+1,s,r,i,n);null!==o?u.push(o):d++}return u.length>0&&(o.children=u),d>0&&null===i&&(o.truncated=`${d} children hidden (max_nodes ${r})`),o}count(e){let t=0,s=0;const r=[e];for(;r.length>0;){const e=r.pop();if("object"!=typeof e||null===e)continue;t++,"Mesh"===e.type&&s++;const i=Array.isArray(e.children)?e.children:[];for(const e of i)r.push(e)}return{total:t,meshes:s}}mark(e,t,s){const r="string"==typeof e.name?e.name.toLowerCase():"",i="string"==typeof e.type?e.type.toLowerCase():"";let n=r.includes(t)||i.includes(t);const o=Array.isArray(e.children)?e.children:[];for(const e of o)this.mark(e,t,s)&&(n=!0);return n&&s.add(e),n}describe_material(e){if(Array.isArray(e)){const t=e.map((e=>this.material_type(e)));return`${e.length} materials: ${t.join(", ")}`}return"object"==typeof e&&null!==e?this.material_type(e):null}material_type(e){if("object"==typeof e&&null!==e){const t=e.type;if("string"==typeof t)return t}return"Material"}count_vertices(e){if("object"!=typeof e||null===e)return null;const t=e.attributes;if("object"!=typeof t||null===t)return null;const s=t.position;if("object"!=typeof s||null===s)return null;const r=s.count;return"number"==typeof r?r:null}vector(e,t){return"object"!=typeof e||null===e?[t,t,t]:[this.round(e.x,t),this.round(e.y,t),this.round(e.z,t)]}round(e,t){return"number"==typeof e&&Number.isFinite(e)?Math.round(1e4*e)/1e4:t}is_uniform(e,t){return e.every((e=>e===t))}positive(e,t){return"number"!=typeof e||!Number.isFinite(e)||e<1?t:Math.floor(e)}}class jt{list(e){const t=this.current(e);return{current:t,views:this.names(e).map((e=>({name:e.name,url:e.url,current:e.name===t})))}}go(e,t){const s="string"==typeof t.name?t.name:null,r=this.names(e);if(null===s||!r.some((e=>e.name===s))){const e=r.map((e=>e.name)).join(", ");throw this.error("not_found",`Unknown view. Available views: ${e}.`)}const i=void 0===t.change_url||!0===t.change_url,n=!0===t.skip;return e.go_to_view(s,i,n),{requested:s,current:this.current(e),change_url:i,skip:n}}names(e){return(Array.isArray(e.views)?e.views:[]).filter((e=>"string"==typeof e.name)).map((e=>({name:e.name,url:"string"==typeof e.url?e.url:""})))}current(e){const t=e.get_current_view();return"object"!=typeof t||null===t||"string"!=typeof t.name?null:t.name}error(e,t){const s=new Error(t);return s.code=e,s}}class Ut extends M{constructor(e=1){super();const t=[];t.push(new c(0,0,0)),t.push(new c(0,0,1e3));const s=new S({color:4474111,depthFunc:r}),i=(new z).setFromPoints(t),n=new T(i,s);n.renderOrder=5e4;const o=[];o.push(new c(0,0,0)),o.push(new c(0,1e3,0));const a=new S({color:4521796,depthFunc:r}),l=(new z).setFromPoints(o),_=new T(l,a);_.renderOrder=5e4;const h=[];h.push(new c(0,0,0)),h.push(new c(1e3,0,0));const u=new S({color:16729156,depthFunc:r}),d=(new z).setFromPoints(h),p=new T(d,u);p.renderOrder=5e4,this.renderOrder=1e5,this.add(n),this.add(_),this.add(p),this.scale.set(e,e,e)}update(){}dispose(){}}class Ot extends Ae{constructor(){super("\n uniform vec2 _ScreenSpacePosition;\n uniform vec2 _ScreenSize;\n uniform vec2 _TextureSize;\n varying vec2 vUv;\n void main()\n {\n vec2 pos = uv * vec2(_TextureSize.x / _ScreenSize.x, _TextureSize.y / _ScreenSize.y);\n pos += vec2(_ScreenSpacePosition.x / _ScreenSize.x, _ScreenSpacePosition.y / _ScreenSize.y);\n\n pos.x = pos.x * 2.0 - 1.0;\n pos.y = pos.y * 2.0 - 1.0;\n\n gl_Position = vec4(pos, 0.0, 1.0);\n vUv = uv;\n }\n ","\n uniform sampler2D _MainTex;\n varying vec2 vUv;\n\n void main()\n {\n gl_FragColor = texture2D(_MainTex, vUv);\n }\n ",{_MainTex:{value:void 0},_ScreenSpacePosition:{value:new t},_ScreenSize:{value:new t},_TextureSize:{value:new t}})}set_position(e,t){this.uniforms._ScreenSpacePosition.value.set(e,t)}set_texture(e,t,s){this.uniforms._MainTex.value=e,this.uniforms._TextureSize.value.set(e.image.width,e.image.height),void 0!==t&&(this.uniforms._TextureSize.value.x=t),void 0!==s&&(this.uniforms._TextureSize.value.y=s)}set_screen_size(e,t){this.uniforms._ScreenSize.value.set(e,t)}}class Nt extends k{constructor(e,t,s,r){super(e,t,s,r),this.clear_color=new i("#000000"),this.clear_alpha=1}copy(e){return super.copy(e),this.clear_color.copy(e.clear_color),this.clear_alpha=e.clear_alpha,this}}class qt extends o{constructor(e,t,s){e=e||"#FF0000";const r=(t=t||1)-.4,i=new A(.01,.01,r,32);i.translate(0,r/2,0);const n=new F(.1,.4,32);n.translate(0,r+.2,0);const o=ce.mergeGeometries([i,n]);o.rotateX(1.57);super(o,new C({color:e})),s&&this.quaternion.setFromUnitVectors(new c(0,0,1),s),this._dir=s}set dir(e){this.quaternion.setFromUnitVectors(new c(0,0,1),e),this._dir=e}get dir(){return this._dir}set length(e){this.scale.z=e}get length(){return this.scale.z}}class It extends o{constructor(e,t,s){e=e||new c(1,1,1),t=t||new c(1,1,1),s=s||16711680;super(new R(e.x,e.y,e.z,t.x,t.y,t.z),new C({color:s}))}}class Et extends o{constructor(e,t){t=t||"#FF0000";super(new P(e=e||1,64,64),new C({color:t})),this.radius=e,this.color=t,this.center=this.position}}const Yt=new class{init(){this.Vector3_one=new c(1,1,1),this.Vector3_zero=new c(0,0,0),this.canvas_renderer=void 0,this.display_texture_meshes=[],this.ctx=void 0,this.scene=new n,this.camera=new Nt(60,Le.aspect_ratio,.1,1e3),this.camera.clear_alpha=0}draw_arrow(e,t,s=16711680){const r=new qt(s,t.length(),t.clone().normalize());return r.position.copy(e),this.scene.add(r),r}draw_axis(){const e=new Ut;return this.scene.add(e),e}set_debug_RT(e){this.rt_debug=e}draw_rectangle(e,t,s,r){t=t||100,s=s||100,this.ctx.fillStyle=r||"rgba(255, 0, 0, 1)",this.ctx.fillRect(e.x-t/2,this.ctx.canvas.height-e.y-s/2,t,s)}clear(){this.ctx&&this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}draw_line_2D(e,t,s){this.ctx.strokeStyle=s||"rgba(255, 0, 0, 1)",this.ctx.beginPath(),this.ctx.moveTo(e.x,e.y),this.ctx.lineTo(t.x,t.y),this.ctx.closePath(),this.ctx.stroke()}draw_line(e,t=16711680){const s=new S({color:t}),r=(new z).setFromPoints(e),i=new T(r,s);return i.frustumCulled=!1,this.scene.add(i),i}draw_cube(e,t,s){t=t||1,s=s||16711680,e=e||new c;const r=new It(new c(t,t,t),void 0,s);return r.position.copy(e),this.scene.add(r),r}draw_oriented_cube(e,t,s=1,r="#FF0000",i=.1){const n=e.distanceTo(t),o=new It(new c(i,s,n),void 0,r),a=t.clone().sub(e).multiplyScalar(.5),l=a.clone().normalize();return a.add(e),o.position.copy(a),o.quaternion.setFromUnitVectors(new c(0,0,-1),l),this.scene.add(o),o}draw_plane(t,s,r){const i=new a(t,s),n=new e({uniforms:{_Color:{value:new _(0,1,0,.2)}},vertexShader:ke,fragmentShader:Te,transparent:!0,depthWrite:!1}),l=new o(i,n);return l.renderOrder=-1e4,this.scene.add(l),l}draw_empty_cube(e,t,s){t=t||1,s=s||16711680;const r=(new L).setFromCenterAndSize(new c,new c(t,t,t)),i=new D(r,s);return i.position.copy(e||new c),i}draw_sphere(e,t,s){t=t||1,s=s||16711680,e=e||new c;const r=new Et(t,s);return r.position.copy(e),this.scene.add(r),r}draw_point_array(e,t=!1,s=16711680){const r=new j(e,t);r.updateArcLengths();const i=r.getSpacedPoints(200);return this.draw_line(i,65280)}draw_sphere_helper(e,t){t=t||16711680;const s=new P(e.radius,32,32),r=new C({color:t}),i=new o(s,r);return i.position.copy(e.center),De.current.add(i),i}draw_math_sphere(t){const s=new P(t.radius,32,32),r=new e({uniforms:{_Color:{value:new _(1,0,0,.2)}},vertexShader:ke,fragmentShader:Te,transparent:!0}),i=new o(s,r);i.position.copy(t.center),De.current.add(i)}draw_bounding_box(e){const t=new D(e,16776960);De.current.add(t)}draw_curve(e,t){const s=new c(0,0,0);t&&(s.y=t.offset||0);for(let t=0;t<e.length-1;t++)this.draw_line([e[t].clone().add(s),e[t+1].clone().add(s)])}draw_texture(e,t,s){const r=new o(new a(1,1),new Ot);return this.display_texture_meshes.push(r),this.scene.add(r),r.material.set_texture(e,t,s),r}render(e){for(let e=0;e<this.display_texture_meshes.length;e++)this.display_texture_meshes[e].material.set_screen_size(Le.width,Le.height);this.scene.children.length>0&&e.render(this.scene,Pe.current)}};class Bt{constructor(e){this.reply=e,this.handlers={},this.queue=[]}register(e,t,s){this.handlers[e]={timing:t,handler:s}}handle(e){const t=this.handlers[e.cmd],s=void 0===e.args?{}:e.args;void 0!==t?"frame_end"!==t.timing?this.run(e.id,s,t.handler):this.queue.push({id:e.id,args:s,handler:t.handler}):this.reply({id:e.id,ok:!1,error:{code:"unknown_command",message:`Unknown command '${e.cmd}'`}})}drain(){const e=this.queue;this.queue=[];for(const t of e)this.run(t.id,t.args,t.handler)}run(e,t,s){try{Promise.resolve(s(t)).then((t=>this.reply({id:e,ok:!0,result:t}))).catch((t=>this.reply({id:e,ok:!1,error:this.to_error(t)})))}catch(t){this.reply({id:e,ok:!1,error:this.to_error(t)})}}to_error(e){const t=e?.code,s=e?.message;return{code:void 0===t?"handler_failed":t,message:"string"==typeof s?s:this.describe(e)}}describe(e){return"string"==typeof e?e:"Handler failed with a non-Error value of type "+typeof e}}class Vt{constructor(){this.socket=null,this.options=null,this.retry_timer=0,this.disposed=!1,this.dispatcher=new Bt((e=>this.send_reply(e)))}init(e){this.options=e,this.disposed=!1,this.connect()}register(e,t,s){this.dispatcher.register(e,t,s)}on_frame_end(){this.dispatcher.drain()}dispose(){this.disposed=!0,window.clearTimeout(this.retry_timer),null!==this.socket&&(this.socket.onclose=null,this.socket.close(),this.socket=null)}connect(){const e=this.options;if(this.disposed||null===e)return;const t=new WebSocket(`ws://127.0.0.1:${e.port}`);this.socket=t,t.onopen=()=>{t.send(JSON.stringify({event:"hello",protocol:1,app:e.app_info()}))},t.onmessage=e=>this.on_message(e),t.onclose=()=>{this.socket===t&&(this.socket=null),this.schedule_retry()},t.onerror=()=>{}}on_message(e){const t=e.data;if("string"!=typeof t)return;const s=this.parse_frame(t);if(null!==s)if("welcome"!==s.event)if("refused"!==s.event)"string"==typeof s.id&&"string"==typeof s.cmd&&this.dispatcher.handle(s);else{const e=this.as_text(s.reason),t=this.as_text(s.server_protocol);console.warn(`[ohzi-mcp] bridge refused: ${e} (server protocol ${t}, this app speaks 1)`)}else console.info("[ohzi-mcp] bridge connected")}parse_frame(e){try{const t=JSON.parse(e);return"object"!=typeof t||null===t?null:t}catch{return null}}as_text(e){return"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e?String(e):"(unknown)"}send_reply(e){null!==this.socket&&this.socket.readyState===WebSocket.OPEN&&this.socket.send(JSON.stringify(e))}schedule_retry(){this.disposed||(window.clearTimeout(this.retry_timer),this.retry_timer=window.setTimeout((()=>this.connect()),2e3))}}class $t{constructor(){}get is_animating(){return!1}on_enter(e){}update(e){}on_exit(e){}}class Gt{constructor(){this.t=0,this.easing_function_t=0}get is_animating(){return!0}on_enter(e){}update(e){this.t+=mt.delta_time/e.duration,this.easing_function_t=e.easing_function(this.t),this.easing_function_t=at.clamp(this.easing_function_t,0,1),e.set_property_value(at.lerp(e.from,e.to,this.easing_function_t)),this.easing_function_t>=.9999&&(e.set_property_value(e.to),e.set_current_state(new $t),e.finished_callback(e))}on_exit(e){}}class Xt{constructor({element:e,css_property:t,from:s=0,to:r=1,duration:i=1,value_prefix:n="",value_suffix:o="",easing_function:a=_t.ease_in_out_cubic,finished_callback:l=(()=>{})}){this.element=e,this.css_property=t,this.from=s,this.to=r,this.value_prefix=n,this.value_suffix=o,this.duration=i,this.easing_function=a,this.finished_callback=l,this.current_state=new $t}animate(){this.set_current_state(new Gt)}stop(){this.set_current_state(new $t)}set_property_value(e){this.element.style[this.css_property]=`${this.value_prefix}${e}${this.value_suffix}`}update(){this.current_state.update(this)}get is_animating(){return this.current_state.is_animating}set_current_state(e){this.current_state.on_exit(this),this.current_state=e,this.current_state.on_enter(this)}}const Wt=new class{init(){this.operating_systems={ANDROID:"android",IOS:"ios",LINUX:"linux",MAC:"mac",WINDOWS:"windows"},this.is_mobile=!!navigator.userAgent.match(/(iPhone|iPod|iPad|Android|playbook|silk|BlackBerry|BB10|Windows Phone|Tizen|Bada|webOS|IEMobile|Opera Mini)/),this.is_ipad=!!(navigator.userAgent.match(/Mac/)&&navigator.maxTouchPoints&&navigator.maxTouchPoints>2),this.is_ios=!!navigator.userAgent.match(/(iPhone|iPod|iPad)/)||this.is_ipad,this.is_android=this.get_os()===this.operating_systems.ANDROID,this.is_linux=this.get_os()===this.operating_systems.LINUX,this.is_mac=this.get_os()===this.operating_systems.MAC,this.is_windows=this.get_os()===this.operating_systems.WINDOWS}get_os(){const e=window.navigator.userAgent,t=window.navigator.platform;let s=null;return-1!==["Macintosh","MacIntel","MacPPC","Mac68K"].indexOf(t)?s=this.operating_systems.MAC:-1!==["iPhone","iPad","iPod"].indexOf(t)?s=this.operating_systems.IOS:-1!==["Win32","Win64","Windows","WinCE"].indexOf(t)?s=this.operating_systems.WINDOWS:/Android/.test(e)?s=this.operating_systems.ANDROID:!s&&/Linux/.test(t)&&(s=this.operating_systems.LINUX),s}};const Qt=new class{init(){this.target_geometry=void 0,this.target_position=new c}set_target_geometry(e){this.target_geometry=e}};class Ht{constructor(){}fit_points(e,t,s,r){const i=t.clone().inverse(),n=[];for(let t=0;t<e.length;t++)n.push(e[t].clone().applyQuaternion(i));const o=(new L).setFromPoints(n),a=new c;o.getSize(a);const l=this.get_distance_to_fit_rect(a.x/2,a.y/2,s,r),_=new c;return o.getCenter(_),_.applyQuaternion(t),{center:_,distance_to_center:l}}get_distance_to_fit_rect(e,t,s,r){const i=s/2*Math.PI/180,n=2*Math.atan(Math.tan(i)*r)/2,o=t/Math.tan(i),a=e/Math.tan(n);return Math.max(Math.abs(a),Math.abs(o))}}class Kt{constructor(){this.sphere=new U}fit_points(e,t,s,r){this.sphere.setFromPoints(e);const i=at.degToRad(s/2),n=2*Math.atan(Math.tan(i)*r)/2,o=this.get_up_plane_normal(t,i),a=this.get_down_plane_normal(t,i),l=this.get_left_plane_normal(t,n),_=this.get_right_plane_normal(t,n),h=new c(0,0,-1).applyQuaternion(t),u=this.sphere.center.clone(),d=this.get_distance_to_fit_rect(2*this.sphere.radius,2*this.sphere.radius,s,r),p=u.clone().add(h.clone().multiplyScalar(-1*d)),m=(new O).setFromNormalAndCoplanarPoint(o,p),g=(new O).setFromNormalAndCoplanarPoint(a,p),f=(new O).setFromNormalAndCoplanarPoint(l,p),v=(new O).setFromNormalAndCoplanarPoint(_,p);this.apply_center_correction_to_pos(p,e,t,m,g,f,v),m.setFromNormalAndCoplanarPoint(o,p),g.setFromNormalAndCoplanarPoint(a,p),f.setFromNormalAndCoplanarPoint(l,p),v.setFromNormalAndCoplanarPoint(_,p);let y=1/0;const b=h.clone().multiplyScalar(-2*d);for(let t=0;t<e.length;t++){const s=new N(e[t].clone(),e[t].clone().add(b)),r=new c,i=new c,n=new c,o=new c;m.intersectLine(s,r),g.intersectLine(s,i),f.intersectLine(s,n),v.intersectLine(s,o),r.length()<1e-4&&console.log("up intersection not found",t),i.length()<1e-4&&console.log("down intersection not found",t),n.length()<1e-4&&console.log("left intersection not found",t),o.length()<1e-4&&console.log("right intersection not found",t);const a=e[t].clone().sub(r).length(),l=e[t].clone().sub(i).length(),_=e[t].clone().sub(n).length(),h=e[t].clone().sub(o).length(),u=Math.min(a,l),d=Math.min(_,h),p=Math.min(u,d);p<y&&(y=p)}const w=h.clone().multiplyScalar(y);return p.clone().add(w)}apply_center_correction_to_pos(e,t,s,r,i,n,o){const a=this.get_vertical_correction(t,i,r,s),l=this.get_horizontal_correction(t,n,o,s);e.add(a),e.add(l)}get_vertical_correction(e,t,s,r){let i=1/0,n=1/0;const o=new c(0,1,0).applyQuaternion(r);for(let r=0;r<e.length;r++){const a=new N(e[r].clone(),e[r].clone().add(o.clone().multiplyScalar(-5e6))),l=new N(e[r].clone(),e[r].clone().add(o.clone().multiplyScalar(5e6))),_=new c,h=new c;t.intersectLine(a,_),s.intersectLine(l,h);const u=_.distanceTo(e[r]),d=h.distanceTo(e[r]);h.length()<1e-4&&console.log("vertical up intersection not found",r),_.length()<1e-4&&console.log("vertical down intersection not found",r),u<n&&(n=u),d<i&&(i=d)}const a=(i-n)/2;return o.clone().multiplyScalar(-a)}get_horizontal_correction(e,t,s,r){let i=1/0,n=1/0;const o=new c(1,0,0).applyQuaternion(r);for(let r=0;r<e.length;r++){const a=new N(e[r].clone(),e[r].clone().add(o.clone().multiplyScalar(-5e6))),l=new N(e[r].clone(),e[r].clone().add(o.clone().multiplyScalar(5e6))),_=new c,h=new c;t.intersectLine(a,_),s.intersectLine(l,h);const u=_.distanceTo(e[r]),d=h.distanceTo(e[r]);_.length()<1e-4&&console.log("left intersection not found",r),h.length()<1e-4&&console.log("right intersection not found",r),u<n&&(n=u),d<i&&(i=d)}const a=(i-n)/2;return o.clone().multiplyScalar(-a)}get_up_plane_normal(e,t){const s=new c(0,-1,0);return s.applyQuaternion((new q).setFromAxisAngle(new c(1,0,0),t)),s.applyQuaternion(e),s}get_down_plane_normal(e,t){const s=new c(0,1,0);return s.applyQuaternion((new q).setFromAxisAngle(new c(1,0,0),-t)),s.applyQuaternion(e),s}get_left_plane_normal(e,t){const s=new c(1,0,0);return s.applyQuaternion((new q).setFromAxisAngle(new c(0,1,0),t)),s.applyQuaternion(e),s}get_right_plane_normal(e,t){const s=new c(-1,0,0);return s.applyQuaternion((new q).setFromAxisAngle(new c(0,1,0),-t)),s.applyQuaternion(e),s}get_distance_to_fit_rect(e,t,s,r){const i=s/2*Math.PI/180,n=2*Math.atan(Math.tan(i)*r)/2,o=t/Math.tan(i),a=e/Math.tan(n);return Math.max(Math.abs(a),Math.abs(o))}}const Zt=new class{init(e){this.tmp_mat=new I,this.plane=new O,this.ray=new E,this.tmp_size=new c,this.tmp_unproj=new c,this.input=e}get_up_dir(e){e=e||Pe.current;const t=new c;return t.set(0,1,0),t.applyQuaternion(e.quaternion),t}get_forward_dir(e){e=e||Pe.current;const t=new c;return t.set(0,0,-1),t.applyQuaternion(e.quaternion),t}get_right_dir(e){e=e||Pe.current;const t=new c;return t.set(1,0,0),t.applyQuaternion(e.quaternion),t}unproject_mouse_position(e,t){t=t||Pe.current;const s=new c,r=t.fov/2*Math.PI/180,i=2*Math.atan(Math.tan(r)*t.aspect)/2,n=Math.tan(r)*t.far,o=Math.tan(i)*t.far;return s.set(o*e.x,n*e.y,-t.far).normalize(),s.applyQuaternion(t.quaternion)}get_plane_intersection(e,t,s,r){r=r||Pe.current,s=s||this.input.NDC;const i=new c;if(this.plane.setFromNormalAndCoplanarPoint(t||this.get_forward_dir(r),e),r.isPerspectiveCamera)this.ray.set(r.position,this.unproject_mouse_position(s,r));else{const e=new c(s.x*r.right,s.y*r.top,0);e.applyQuaternion(r.quaternion),e.add(r.position);const t=new c(0,0,-1).applyQuaternion(r.quaternion);this.ray.set(e,t)}return this.ray.intersectPlane(this.plane,i),i}fit_points_on_camera(e,t=1){const s=(new U).setFromPoints(e).center,r=this.get_forward_dir(Pe.current).clone(),i=(new O).setFromNormalAndCoplanarPoint(r,s),n=at.project_points_on_plane(e,i),o=new c;let a=(new L).setFromPoints(n);a.getCenter(o);const l=new c(0,1,0).applyQuaternion(Pe.current.quaternion),_=l.clone().cross(r).normalize(),h=(new I).set(_.x,l.x,r.x,s.x,_.y,l.y,r.y,s.y,_.z,l.z,r.z,s.z,0,0,0,1).invert();for(let e=0;e<n.length;e++)n[e].applyMatrix4(h);const u=new c;a=(new L).setFromPoints(n),a.getSize(u),u.multiplyScalar(t);const d=new c;return a.getCenter(d),{position:o,zoom:this.get_zoom_to_fit_rect(u.x/2,u.y/2)}}get_zoom_to_fit_rect(e,t){const s=Pe.current.fov/2*Math.PI/180,r=2*Math.atan(Math.tan(s)*Pe.current.aspect)/2,i=t/Math.tan(s),n=e/Math.tan(r);return Math.max(Math.abs(n),Math.abs(i))}get_zoom_to_fit_box(e,t){if(t.isOrthographicCamera){e.getSize(this.tmp_size);const t=this.tmp_size.x,s=this.tmp_size.y,r=t/s;return Le.aspect_ratio/r>1?Le.height/s:Le.width/t}{const t=new c;return e.getSize(t),this.get_zoom_to_fit_rect(t.x,t.y)}}get_html_screen_pos(e,t){t=t||Pe.current;const s=new c;return e.getWorldPosition(s),s.project(t),s.x=(.5*s.x+.5)*Le.width,s.y=(1-(.5*s.y+.5))*Le.height,s}world_pos_to_screen(e,t){t=t||Pe.current;const s=new c;return s.copy(e),s.project(t),s.x=(.5*s.x+.5)*Le.width,s.y=(1-(.5*s.y+.5))*Le.height,s}update_projection(e){e.left=-Le.width/2,e.right=Le.width/2,e.top=Le.height/2,e.bottom=-Le.height/2,e.aspect=Le.aspect_ratio,e.updateProjectionMatrix(!0)}fit_bounding_box_points(e,t,s=1){const r=new c;r.copy(t.max).sub(t.min);const i=t.min.clone(),n=i.clone().add(new c(r.x,0,0)),o=i.clone().add(new c(0,r.y,0)),a=i.clone().add(new c(0,0,r.z)),l=i.clone().add(new c(r.x,0,r.z)),_=i.clone().add(new c(0,r.y,r.z)),h=t.max.clone(),u=i.clone().add(new c(r.x,r.y,0));return this.fit_points(e,[i,n,o,a,l,_,h,u],s)}fit_points(e,t,s=1){if(e.isPerspectiveCamera){const r=new c(0,0,-1).applyQuaternion(e.quaternion),i=r.clone().multiplyScalar(-1),n=new Kt,o=Le.aspect_ratio,a=n.fit_points(t,e.quaternion,e.fov*s,o),l=(new L).setFromPoints(t),_=new c;l.getCenter(_);const h=(new O).setFromNormalAndCoplanarPoint(i,_),u=new E(a,r),d=new c;u.intersectPlane(h,d);return{zoom:a.distanceTo(d),reference_position:d,camera_position:a}}{const r=(new Ht).fit_points(t,this.reference_rotation,e.fov*s,Le.aspect_ratio);this.reference_position.copy(r.center),this.reference_zoom=r.distance_to_center;const i=new c(0,0,1).applyQuaternion(e.quaternion);return{zoom:r.distance_to_center,reference_position:r.center,camera_position:i.multiplyScalar(r.distance_to_center)}}}};const Jt=new class{constructor(){}init(e){Pe.init(),Zt.init(e),Mt.init(),Wt.init(),We.init(),Qt.init(),Ye.init(),De.init(),Le.init(),mt.init(),Yt.init()}dispose(e){qe.dispose(),De.dispose(),e.dispose()}};class es{constructor(){this.on_key_down=e=>{90===e.keyCode&&e.ctrlKey&&!this.ctrlz_fired&&(this.ctrlz_pressed=!0,this.ctrlz_fired=!0),e.code&&this.press_key(e.code)},this.on_key_up=e=>{this.release_key(e.code)}}init(e){this.ctrlz_pressed=!1,this.ctrlz_fired=!1,this.keys={},this.keys_keys=[],this.container=e,this.container.addEventListener("keydown",this.on_key_down,!1),this.container.addEventListener("keyup",this.on_key_up,!1)}clear(){this.ctrlz_pressed=!1;for(let e=0;e<this.keys_keys.length;e++)this.keys[this.keys_keys[e]].pressed=!1,this.keys[this.keys_keys[e]].released=!1}release_key(e){const t=this.keys[e];t&&(t.fired=!1,t.down=!1,t.released=!0)}release_keys(){this.ctrlz_fired=!1;for(let e=0;e<this.keys_keys.length;e++)this.keys[this.keys_keys[e]].fired=!1,this.keys[this.keys_keys[e]].down=!1}press_key(e){const t=this.keys[e];t&&(!1===t.down&&(t.pressed=!0),t.down=!0,t.fired=!0)}is_key_pressed(e){const t=this.keys[e];return!!t&&t.pressed}is_key_down(e){const t=this.keys[e];return!!t&&t.down}is_key_released(e){const t=this.keys[e];return!!t&&t.released}register_key(e){this.keys[e]={key_name:e,pressed:!1,down:!1,fired:!1,released:!1},this.keys_keys=Object.keys(this.keys)}unregister_key(e){delete this.keys[e]}dispose(){this.container.removeEventListener("keydown",this.on_key_down,!1),this.container.removeEventListener("keyup",this.on_key_up,!1)}}class ts extends l{constructor(e,t,s,r,n,o){super(e,t,s,r,n,o),this.clear_color=new i("#000000"),this.clear_alpha=1}copy(e){return super.copy(e),this.clear_color.copy(e.clear_color),this.clear_alpha=e.clear_alpha,this}}class ss extends e{constructor(){super({uniforms:{},vertexShader:"#define GLSLIFY 1\nvarying vec3 v_normal;void main(){gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0);v_normal=(modelMatrix*vec4(normal,0.0)).xyz;}",fragmentShader:"#define GLSLIFY 1\nvarying vec3 v_normal;void main(){gl_FragColor=vec4(v_normal*0.5+vec3(0.5),1.0);}"})}}class rs extends Ce{constructor(){super()}render(){qe.clear(void 0,Pe.current,!0,!0),qe.render(De.current,Pe.current,void 0,new ss)}}var is="#define GLSLIFY 1\nvarying vec2 vUv;varying vec4 vRay;uniform mat4 _InverseProjMatrix;void main(){gl_Position=vec4(uv*2.0-1.0,1.0,1.0);vRay=_InverseProjMatrix*vec4(uv*2.0-1.0,1.0,1.0);vUv=uv;}";class ns extends Se{constructor(){super("#define GLSLIFY 1\nuniform sampler2D _MainTex;uniform vec2 _Resolution;uniform float _FarPlane;varying vec2 vUv;varying vec4 vRay;vec3 decode_normal(vec4 enc){float scale=1.7777;vec3 nn=enc.xyz*vec3(2.0*scale,2.0*scale,0.0)+vec3(-scale,-scale,1.0);float g=2.0/dot(nn.xyz,nn.xyz);vec3 n;n.xy=g*nn.xy;n.z=g-1.0;return n;}float DecodeFloatRG(vec2 enc){vec2 kDecodeDot=vec2(1.0,1.0/255.0);return dot(enc,kDecodeDot);}vec3 DecodeNormal(vec2 uv){vec4 depthNormal=texture2D(_MainTex,uv);vec3 normalValue=normalize(decode_normal(vec4(depthNormal.zw,0.,0.)));return normalize(normalValue);}vec3 DecodeViewPos(vec2 uv){vec2 depth=texture2D(_MainTex,uv).xy;return DecodeFloatRG(depth)*(vRay.xyz/vRay.w);}void main(){vec3 viewPos=DecodeViewPos(vUv);vec3 normalValue=DecodeNormal(vUv);float vDepth=clamp(0.0,1.0,length(viewPos)/_FarPlane);vDepth=length(viewPos)/_FarPlane;gl_FragColor=vec4(vDepth,vDepth,vDepth,1.0);}",is),this.uniforms._FarPlane={value:1},this.uniforms._InverseProjMatrix={value:new I}}}class os extends Se{constructor(){super("#define GLSLIFY 1\nuniform sampler2D _MainTex;uniform sampler2D _AO;uniform vec2 _Resolution;uniform vec2 _SampleDir;varying vec2 vUv;void main(){gl_FragColor.rgb=texture2D(_MainTex,vUv).rgb*(1.0-texture2D(_AO,vUv).r);gl_FragColor.a=1.0;}"),this.uniforms._AO={value:void 0}}}class as extends Se{constructor(){super("#define GLSLIFY 1\nuniform sampler2D _MainTex;uniform mat4 _InverseProjMatrix;uniform float _Bias;uniform float _Radius;uniform vec2 _Resolution;uniform float _FarPlane;varying vec2 vUv;varying vec4 vRay;uniform vec3 _SampleKernel[64];uniform sampler2D _RandomRotation;uniform mat4 _ProjectionMatrix;vec3 decode_normal(vec4 enc){float scale=1.7777;vec3 nn=enc.xyz*vec3(2.0*scale,2.0*scale,0.0)+vec3(-scale,-scale,1.0);float g=2.0/dot(nn.xyz,nn.xyz);vec3 n;n.xy=g*nn.xy;n.z=g-1.0;return n;}float DecodeFloatRG(vec2 enc){vec2 kDecodeDot=vec2(1.0,1.0/255.0);return dot(enc,kDecodeDot);}vec3 DecodeNormal(vec2 uv){vec2 encoded_normal=texture2D(_MainTex,uv).zw;vec3 normalValue=normalize(decode_normal(vec4(encoded_normal,0.,0.)));return normalize(normalValue);}vec3 DecodeViewPos(vec2 uv){vec2 depth=texture2D(_MainTex,uv).xy;vec4 inv_proj=_InverseProjMatrix*vec4(vUv*2.0-1.0,1.0,1.0);return DecodeFloatRG(depth)*(vRay.xyz/vRay.w);}void main(){vec2 noiseScale=vec2(_Resolution.x/4.0,_Resolution.y/4.0);vec3 fragPos=DecodeViewPos(vUv);vec3 normal=DecodeNormal(vUv);vec3 randomVec=texture2D(_RandomRotation,vUv*noiseScale).xyz;randomVec=vec3(randomVec.xy*2.0-1.0,0);randomVec=normalize(randomVec);vec3 tangent=normalize(randomVec-normal*dot(randomVec,normal));vec3 bitangent=normalize(cross(normal,tangent));mat3 TBN=mat3(tangent,bitangent,normal);float occlusion=0.0;const int kernelSize=64;for(int i=0;i<kernelSize;++i){vec3 sample=TBN*_SampleKernel[i];sample=fragPos+sample*_Radius;vec4 projPos=_ProjectionMatrix*vec4(sample,1.0);vec2 screenPos=projPos.xy/projPos.w;screenPos=screenPos*0.5+0.5;float sampled_depth=DecodeViewPos(screenPos).z;float rangeCheck=smoothstep(0.0,1.0,_Radius/abs(fragPos.z-sampled_depth));occlusion+=step(sample.z+_Bias,sampled_depth)*rangeCheck;}occlusion=(occlusion/float(kernelSize));gl_FragColor.rgb=vec3(occlusion,occlusion,occlusion);gl_FragColor.a=1.0;}",is),this.uniforms._InverseProjMatrix={value:new I},this.uniforms._ProjectionMatrix={value:new I},this.uniforms._Bias={value:.0125},this.uniforms._Radius={value:.3},this.uniforms._FarPlane={value:100},this.uniforms._SampleKernel={value:this.__get_sample_kernel()},this.uniforms._RandomRotation={value:this.__get_rotation_kernel()}}__get_sample_kernel(){const e=[];for(let t=0;t<64;t++){const s=new c(2*Math.random()-1,2*Math.random()-1,Math.random());s.normalize();let r=t/64;r=at.lerp(.1,1,r*r),s.multiplyScalar(r),e.push(s)}return e}__get_rotation_kernel(){const e=new Uint8Array(48);for(let t=0;t<16;t++)e[3*t+1]=Math.floor(255*Math.random()),e[3*t+2]=Math.floor(255*Math.random()),e[3*t+3]=0;const t=new Y(e,4,4,B);return t.wrapS=V,t.wrapT=V,t.needsUpdate=!0,t}}class ls extends Se{constructor(){super("#define GLSLIFY 1\nuniform sampler2D _MainTex;uniform vec2 _Resolution;uniform vec2 _SampleDir;varying vec2 vUv;void main(){vec4 sum=vec4(0.,0.,0.,0.);vec2 dir=(0.5/_Resolution)*_SampleDir;float _Distance=2.0;sum+=texture2D(_MainTex,vUv+dir*-4.*_Distance)*0.0525;sum+=texture2D(_MainTex,vUv+dir*-3.*_Distance)*0.075;sum+=texture2D(_MainTex,vUv+dir*-2.*_Distance)*0.110;sum+=texture2D(_MainTex,vUv+dir*-1.*_Distance)*0.150;sum+=texture2D(_MainTex,vUv+dir*0.*_Distance)*0.225;sum+=texture2D(_MainTex,vUv+dir*1.*_Distance)*0.150;sum+=texture2D(_MainTex,vUv+dir*2.*_Distance)*0.110;sum+=texture2D(_MainTex,vUv+dir*3.*_Distance)*0.075;sum+=texture2D(_MainTex,vUv+dir*4.*_Distance)*0.0525;gl_FragColor=vec4(sum);}"),this.uniforms._SampleDir={value:new t}}}class _s{constructor(){this.RT1=new h(1,1),this.RT2=new h(1,1),this.box_blur_mat=new ls}blur(e){e.width===this.RT1.width&&e.height===this.RT1.height||(this.RT1.setSize(e.width,e.height),this.RT2.setSize(e.width,e.height)),this.box_blur_mat.uniforms._SampleDir.value.set(1,0),qe.blit(e,this.RT1,this.box_blur_mat),this.box_blur_mat.uniforms._SampleDir.value.set(0,1),qe.blit(this.RT1,e,this.box_blur_mat)}}class hs extends Ce{constructor(e=!1){super(),this.ssao_mat=new as,this.ssao_compose_mat=new os,this.debug_normals=new ns,this.ssaa=e?2:1,this.main_RT=new h(Le.width*this.ssaa,Le.height*this.ssaa),this.SSAO_RT=new h(Le.width,Le.height),this.blurrer=new _s,qe.generate_depth_normal_texture=!0}render(){this.__check_RT_size(),qe.clear(this.main_RT,Pe.current,!0,!1),qe.render(De.current,Pe.current,this.main_RT),this.__update_uniforms(),qe.blit(qe.depth_normals_RT,this.SSAO_RT,this.ssao_mat),this.blurrer.blur(this.SSAO_RT),qe.blit(this.SSAO_RT,void 0),this.ssao_compose_mat.uniforms._AO.value=this.SSAO_RT.texture,qe.blit(this.main_RT,void 0,this.ssao_compose_mat)}__update_uniforms(){this.ssao_mat.uniforms._InverseProjMatrix.value=Pe.current.projectionMatrix.clone().invert(),this.ssao_mat.uniforms._ProjectionMatrix.value=Pe.current.projectionMatrix.clone(),this.ssao_mat.uniforms._FarPlane.value=Pe.current.far}__check_RT_size(){this.main_RT.width===Le.width*this.ssaa&&this.main_RT.height===Le.height*this.ssaa||(this.main_RT.setSize(Le.width*this.ssaa,Le.height*this.ssaa),this.SSAO_RT.setSize(Le.width,Le.height))}}class cs extends Ce{constructor(){super()}render(){qe.clear(void 0,Pe.current,!0,!0),De.current.on_pre_render(),De.current.render(),De.current.on_post_render()}}class us extends Se{constructor(e){super("#define GLSLIFY 1\n#include <common>\nvarying vec2 vUv;uniform sampler2D _MainTex;uniform vec2 texSize;uniform vec2 direction;uniform float radius;float gaussianPdf(in float x,in float sigma){return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;}vec4 sampleTex(sampler2D tex,vec2 uv){vec4 col=texture2D(tex,uv);\n#ifndef USE_LINEAR_COLOR_SPACE\ncol.rgb=pow(col.rgb,vec3(2.2));\n#endif\nreturn col;}void main(){vec2 invSize=1.0/texSize;float fSigma=float(SIGMA);float weightSum=gaussianPdf(0.0,fSigma);vec4 diffuseSum=sampleTex(_MainTex,vUv)*weightSum;for(int i=1;i<KERNEL_RADIUS;i++){float x=float(i);float w=gaussianPdf(x,fSigma);vec2 uvOffset=direction*invSize*x*radius;vec4 sample1=sampleTex(_MainTex,vUv+uvOffset);vec4 sample2=sampleTex(_MainTex,vUv-uvOffset);diffuseSum+=(sample1+sample2)*w;weightSum+=2.0*w;}gl_FragColor=vec4(diffuseSum/weightSum);\n#ifndef USE_LINEAR_COLOR_SPACE\ngl_FragColor.rgb=pow(gl_FragColor.rgb,vec3(0.4545));\n#endif\n}",void 0,{KERNEL_RADIUS:e,SIGMA:e}),this.uniforms.texSize={value:new t(.5,.5)},this.uniforms.direction={value:new t(.5,.5)},this.uniforms.radius={value:1},this.defines.USE_LINEAR_COLOR_SPACE=!0}set_size(e,t){this.uniforms.texSize.value.x=e,this.uniforms.texSize.value.y=t}set_direction(e,t){this.uniforms.direction.value.set(e,t)}set_radius(e=1){this.uniforms.radius.value=e}}class ds extends Se{constructor(){super("#define GLSLIFY 1\nuniform sampler2D _MainTex;uniform vec3 defaultColor;uniform float defaultOpacity;uniform float luminosityThreshold;uniform float smoothWidth;varying vec2 vUv;vec4 sampleTex(sampler2D tex,vec2 uv){vec4 col=texture2D(tex,uv);\n#ifndef USE_LINEAR_COLOR_SPACE\ncol.rgb=pow(col.rgb,vec3(2.2));\n#endif\nreturn col;}void main(){vec4 texel=sampleTex(_MainTex,vUv);vec3 luma=vec3(0.299,0.587,0.114);float v=dot(texel.xyz,luma);vec4 outputColor=vec4(defaultColor.rgb,defaultOpacity);float alpha=smoothstep(luminosityThreshold,luminosityThreshold+smoothWidth,v);gl_FragColor=mix(outputColor,texel,alpha);\n#ifndef USE_LINEAR_COLOR_SPACE\ngl_FragColor.rgb=pow(gl_FragColor.rgb,vec3(0.4545));\n#endif\n}"),this.uniforms.luminosityThreshold={value:.23},this.uniforms.smoothWidth={value:.01},this.uniforms.defaultColor={value:new i("#000000")},this.uniforms.defaultOpacity={value:0},this.defines.USE_LINEAR_COLOR_SPACE=!0}set_threshold(e){this.uniforms.luminosityThreshold.value=e}}class ps{constructor(e=!1){this.current_width=1,this.current_height=1,this.separableBlurMaterials=[],this.renderTargetsHorizontal=[],this.renderTargetsVertical=[],this.use_half_float=e,this.nMips=5,this.kernelSizeArray=[3,5,7,9,11],this.rt_pars={minFilter:$,magFilter:$,format:B,type:e?G:X,colorSpace:e?W:g},this.renderTargetBright=new h(1,1,this.rt_pars),this.renderTargetBright.texture.generateMipmaps=!1,this.init_materials(),this.init_RT(),this.luminosity_high_pass_mat=new ds}blur(e,t){this.resize_RT(e.width,e.height);let s=e;t&&(qe.blit(e,this.renderTargetBright,this.luminosity_high_pass_mat),s=this.renderTargetBright);for(let e=0;e<this.nMips;e++){const t=this.separableBlurMaterials[e];t.set_direction(1,0),qe.blit(s,this.renderTargetsHorizontal[e],t),t.set_direction(0,1),qe.blit(this.renderTargetsHorizontal[e],this.renderTargetsVertical[e],t),s=this.renderTargetsVertical[e]}}get_blurred_texture(){return this.renderTargetsHorizontal[0].texture}get_blurred_RT(){return this.renderTargetsHorizontal[0]}init_RT(){this.dispose_RT(),this.renderTargetBright.setSize(1,1);for(let e=0;e<this.nMips;e++){const e=new h(1,1,this.rt_pars),t=new h(1,1,this.rt_pars);e.texture.generateMipmaps=!1,t.texture.generateMipmaps=!1,e.texture.colorSpace=this.rt_pars.colorSpace,t.texture.colorSpace=this.rt_pars.colorSpace,this.renderTargetsHorizontal.push(e),this.renderTargetsVertical.push(t)}}resize_RT(e,t){if(this.current_width===e&&this.current_height===t)return;this.current_width=e,this.current_height=t;let s=Math.round(e/2),r=Math.round(t/2);this.renderTargetBright.setSize(s,r);for(let e=0;e<this.nMips;e++)this.renderTargetsVertical[e].setSize(s,r),this.renderTargetsHorizontal[e].setSize(s,r),this.separableBlurMaterials[e].set_size(s,r),s=Math.round(s/2),r=Math.round(r/2)}init_materials(){this.dispose_materials();for(let e=0;e<this.nMips;e++)this.separableBlurMaterials.push(new us(this.kernelSizeArray[e]))}set_radius(e){for(let t=0;t<this.separableBlurMaterials.length;t++)this.separableBlurMaterials[t].set_radius(e)}set_luminosity_threshold(e){this.luminosity_high_pass_mat.set_threshold(e)}dispose_materials(){for(let e=0;e<this.separableBlurMaterials.length;e++)this.separableBlurMaterials[e].dispose();this.separableBlurMaterials.length=0}dispose_RT(){for(let e=0;e<this.renderTargetsVertical.length;e++)this.renderTargetsHorizontal[e].dispose(),this.renderTargetsVertical[e].dispose();this.renderTargetBright.dispose(),this.renderTargetsHorizontal.length=0,this.renderTargetsVertical.length=0}}class ms extends Ce{constructor(e,t,s,r=!1){super(),this.add_mat=new ze(t);const i={samples:e?8:1,type:t?G:X,format:B,colorSpace:W,minFilter:x,magFilter:x};this.use_rendering_size=r,this.main_RT=new h(1,1,i),this.main_RT.texture.colorSpace=W,this.main_RT.texture.minFilter=x,this.main_RT.texture.magFilter=x,this.bloom_compose_mat=new Fe(5,t),this.blurrer=new ps(t),this.use_hight_luminosity_pass=s,this.luminosity_threshold=.5}on_enter(){this.bloom_compose_mat.set_blur_texture_0(this.blurrer.renderTargetsVertical[0].texture),this.bloom_compose_mat.set_blur_texture_1(this.blurrer.renderTargetsVertical[1].texture),this.bloom_compose_mat.set_blur_texture_2(this.blurrer.renderTargetsVertical[2].texture),this.bloom_compose_mat.set_blur_texture_3(this.blurrer.renderTargetsVertical[3].texture),this.bloom_compose_mat.set_blur_texture_4(this.blurrer.renderTargetsVertical[4].texture),this.add_mat.set_add_texture(this.blurrer.renderTargetsHorizontal[0].texture)}render(){this.__check_RT_size(),qe.clear(this.main_RT,Pe.current,!0,!1),qe.render(De.current,Pe.current,this.main_RT),this.blurrer.blur(this.main_RT,this.use_hight_luminosity_pass),qe.material_pass(this.bloom_compose_mat,this.blurrer.renderTargetsHorizontal[0]),qe.blit(this.main_RT,void 0,this.add_mat)}set_bloom_strength(e){this.bloom_compose_mat.set_bloom_strength(e)}set_bloom_radius(e){this.blurrer.set_radius(e)}set_luminosity_threshold(e){this.blurrer.set_luminosity_threshold(e)}set_tint_color_0(e){this.bloom_compose_mat.set_tint_color_0(e)}set_tint_color_1(e){this.bloom_compose_mat.set_tint_color_1(e)}set_tint_color_2(e){this.bloom_compose_mat.set_tint_color_2(e)}set_tint_color_3(e){this.bloom_compose_mat.set_tint_color_3(e)}set_tint_color_4(e){this.bloom_compose_mat.set_tint_color_4(e)}__check_RT_size(){const e=this.use_rendering_size?Le.render_width:Le.width,t=this.use_rendering_size?Le.render_height:Le.height;this.main_RT.width===e&&this.main_RT.height===t||this.main_RT.setSize(e,t)}}class gs extends Ce{constructor(){super()}render(){De.current.on_pre_render&&De.current.on_pre_render(),De.current.render?De.current.render():qe.render(De.current,Pe.current,qe._renderer.getRenderTarget()),this.render_spectator_camera(),De.current.on_post_render&&De.current.on_post_render()}render_spectator_camera(){const e=Pe.spectator;if(e&&qe._renderer.xr.isPresenting){const t=qe._renderer.xr.getCamera();e.projectionMatrix.copy(Pe.current.projectionMatrix),e.position.copy(t.position),e.quaternion.copy(t.quaternion);const s=qe._renderer.getRenderTarget();qe._renderer.xr.isPresenting=!1,qe._renderer.setRenderTarget(null),qe._renderer.render(De.current,e),qe._renderer.setRenderTarget(s),qe._renderer.xr.isPresenting=!0}}}const fs=new class{constructor(){this.components=[],this.enabled_components=new Set}update(){this.__set_components_opacities();for(const e of this.enabled_components)e.update(vt.current_state_data)}register_component(e){this.components.push(e)}enable_component(e){this.enabled_components.add(e)}disable_component(e){this.enabled_components.delete(e)}get_component_by_name(e){console.warn("DEPRECATED. Use ViewComponentManager.get instead"),this.get(e)}get(e){for(let t=0;t<this.components.length;t++)if(this.components[t].name===e)return this.components[t];console.error("[ViewComponentManager.get] no component found for: ",e)}__set_components_opacities(){for(let e=0;e<this.components.length;e++)this.components[e].set_opacity(vt.current_state_data)}};class vs{constructor(e,t,s){e=e||new Me,this.target_application=e,this.graphics=t,this.input=s,this.is_running=!1,this.frames_passed=0,this.time_accumulator=0}update(e){if(this.is_running){for(mt.__update(e),1===this.frames_passed&&this.target_application.on_post_start(),this.input.update(),this.time_accumulator+=mt.delta_time,this.target_application.before_update(),vt.before_update();this.time_accumulator>mt.fixed_delta_time;)this.target_application.fixed_update(),vt.fixed_update(),this.time_accumulator-=mt.fixed_delta_time;mt.__set_frame_interpolation(this.time_accumulator/mt.fixed_delta_time),this.target_application.update(),vt.update(),yt.update(),fs.update(),this.target_application.on_pre_render(),this.graphics.update(),this.target_application.on_post_render(),Yt.render(this.graphics),this.target_application.on_frame_end(),this.frames_passed++,this.input.clear(),Yt.clear()}}start(){this.is_running||(0===this.frames_passed&&this.target_application.on_enter(this),this.is_running=!0,this.graphics._renderer.setAnimationLoop(this.update.bind(this)))}stop(){!1!==this.is_running&&(this.is_running=!1,this.target_application.on_exit(this),this.graphics._renderer.setAnimationLoop(null))}set_state(e){this.target_application.on_exit(this),this.target_application=e,this.target_application.on_enter(this)}dispose(){this.stop(),this.frames_passed=0}}const ys=new class{init(){console.warn("Screen Singleton is deprecated. Please use OScreen."),Le.init()}update_position(e,t){console.warn("Screen Singleton is deprecated. Please use OScreen."),Le.update_position(e,t)}update(){console.warn("Screen Singleton is deprecated. Please use OScreen."),Le.update()}update_size(e,t){console.warn("Screen Singleton is deprecated. Please use OScreen."),Le.update_size(e,t)}apply_pixel_density_v2(e){return console.warn("Screen Singleton is deprecated. Please use OScreen."),Le.apply_pixel_density_v2(e)}apply_pixel_density(e){return console.warn("Screen Singleton is deprecated. Please use OScreen."),Le.apply_pixel_density(e)}get_pixel_size(){return console.warn("Screen Singleton is deprecated. Please use OScreen."),Le.get_pixel_size()}get aspect_ratio(){return console.warn("Screen Singleton is deprecated. Please use OScreen."),Le.aspect_ratio}};class bs{constructor({name:e,container:t}){this.name=e,this.container=t,this.hidden=!0,fs.register_component(this)}start(){}on_enter(){this.container.classList.remove("hidden"),fs.enable_component(this),this.hidden=!1}update(e){}on_exit(){this.container.classList.add("hidden"),fs.disable_component(this),this.hidden=!0}set_opacity(e){this.container.style.opacity=e[`${this.name}_opacity`],this.toggle_hidden()}toggle_hidden(){this.container.style.opacity>.001?this.hidden&&this.on_enter():this.hidden||this.on_exit()}}class ws extends o{constructor(e,t,s,r){e=e||1,t=t||1,s=s||"#FF0000",r=r||new C({color:s});const i=new a(e,t);i.rotateX(-1.57),super(i,r)}}class xs extends o{constructor(e,t,s,r){e=e||1,t=t||1,s=s||"#FF0000",r=r||new C({color:s});super(new a(e,t),r)}}class Ms{constructor(){}static merge_from_to(e,t){t.push.apply(t,e)}static expand_vec3_array(e,t){const s=t-e.length;for(let t=0;t<s;t++)e.push(e[t].clone())}static remove_elem(e,t){const s=e.indexOf(t);s>-1&&e.splice(s,1)}static get_closest_point(e,t){let s=e[0],r=s.distanceTo(t);for(let i=1;i<e.length;i++)e[i].distanceTo(t)<r&&(s=e[i],r=e[i].distanceTo(t));return s}static object_values_to_array(e){const t=Object.keys(e),s=[];for(let r=0;r<t.length;r++)s.push(e[t[r]]);return s}}class Ss{constructor(){this.sphere=new U}fit_points(e,t,s,r){this.sphere.setFromPoints(e);const i=at.degToRad(s/2),n=2*Math.atan(Math.tan(i)*r)/2,o=this.get_up_plane_normal(t,i),a=this.get_down_plane_normal(t,i),l=this.get_left_plane_normal(t,n),_=this.get_right_plane_normal(t,n),h=new c(0,0,-1).applyQuaternion(t),u=this.sphere.center.clone(),d=this.get_distance_to_fit_rect(2*this.sphere.radius,2*this.sphere.radius,s,r),p=u.clone().add(h.clone().multiplyScalar(-1*d)),m=(new O).setFromNormalAndCoplanarPoint(o,p),g=(new O).setFromNormalAndCoplanarPoint(a,p),f=(new O).setFromNormalAndCoplanarPoint(l,p),v=(new O).setFromNormalAndCoplanarPoint(_,p);this.apply_center_correction_to_pos(p,e,t,m,g,f,v),m.setFromNormalAndCoplanarPoint(o,p),g.setFromNormalAndCoplanarPoint(a,p),f.setFromNormalAndCoplanarPoint(l,p),v.setFromNormalAndCoplanarPoint(_,p);let y=1/0;const b=h.clone().multiplyScalar(-2*d);for(let t=0;t<e.length;t++){const s=new N(e[t].clone(),e[t].clone().add(b)),r=new c,i=new c,n=new c,o=new c;m.intersectLine(s,r),g.intersectLine(s,i),f.intersectLine(s,n),v.intersectLine(s,o),r.length()<1e-4&&console.log("up intersection not found",t),i.length()<1e-4&&console.log("down intersection not found",t),n.length()<1e-4&&console.log("left intersection not found",t),o.length()<1e-4&&console.log("right intersection not found",t);const a=e[t].clone().sub(r).length(),l=e[t].clone().sub(i).length(),_=e[t].clone().sub(n).length(),h=e[t].clone().sub(o).length(),u=Math.min(a,l),d=Math.min(_,h),p=Math.min(u,d);p<y&&(y=p)}const w=h.clone().multiplyScalar(y);return p.clone().add(w)}apply_center_correction_to_pos(e,t,s,r,i,n,o){const a=this.get_vertical_correction(t,i,r,s),l=this.get_hozirontal_correction(t,n,o,s);e.add(a),e.add(l)}get_vertical_correction(e,t,s,r){let i,n,o=1/0,a=1/0;const l=new c(0,1,0).applyQuaternion(r);for(let r=0;r<e.length;r++){const _=new N(e[r].clone(),e[r].clone().add(l.clone().multiplyScalar(-5e6))),h=new N(e[r].clone(),e[r].clone().add(l.clone().multiplyScalar(5e6))),u=new c,d=new c;t.intersectLine(_,u),s.intersectLine(h,d);const p=u.distanceTo(e[r]),m=d.distanceTo(e[r]);d.length()<1e-4&&console.log("vertical up intersection not found",r),u.length()<1e-4&&console.log("vertical down intersection not found",r),p<a&&(a=p,n=e[r]),m<o&&(o=m,i=e[r])}console.log(i,n);const _=(o-a)/2;return l.clone().multiplyScalar(-_)}get_hozirontal_correction(e,t,s,r){let i,n,o=1/0,a=1/0;const l=new c(1,0,0).applyQuaternion(r);for(let r=0;r<e.length;r++){const _=new N(e[r].clone(),e[r].clone().add(l.clone().multiplyScalar(-5e6))),h=new N(e[r].clone(),e[r].clone().add(l.clone().multiplyScalar(5e6))),u=new c,d=new c;t.intersectLine(_,u),s.intersectLine(h,d);const p=u.distanceTo(e[r]),m=d.distanceTo(e[r]);u.length()<1e-4&&console.log("left intersection not found",r),d.length()<1e-4&&console.log("right intersection not found",r),p<a&&(a=p,n=e[r]),m<o&&(o=m,i=e[r])}const _=(o-a)/2;return console.log(i,n),l.clone().multiplyScalar(-_)}get_up_plane_normal(e,t){const s=new c(0,-1,0);return s.applyQuaternion((new q).setFromAxisAngle(new c(1,0,0),t)),s.applyQuaternion(e),s}get_down_plane_normal(e,t){const s=new c(0,1,0);return s.applyQuaternion((new q).setFromAxisAngle(new c(1,0,0),-t)),s.applyQuaternion(e),s}get_left_plane_normal(e,t){const s=new c(1,0,0);return s.applyQuaternion((new q).setFromAxisAngle(new c(0,1,0),t)),s.applyQuaternion(e),s}get_right_plane_normal(e,t){const s=new c(-1,0,0);return s.applyQuaternion((new q).setFromAxisAngle(new c(0,1,0),-t)),s.applyQuaternion(e),s}get_distance_to_fit_rect(e,t,s,r){const i=s/2*Math.PI/180,n=2*Math.atan(Math.tan(i)*r)/2,o=t/Math.tan(i),a=e/Math.tan(n);return Math.max(Math.abs(a),Math.abs(o))}}class zs{static convert_to_non_indexed_geometry(e){const t=e.index,s=e.getAttribute("position"),r=[];for(let e=0;e<t.count;e+=3)r.push(s.getX(t.array[e+0])),r.push(s.getY(t.array[e+0])),r.push(s.getZ(t.array[e+0])),r.push(s.getX(t.array[e+1])),r.push(s.getY(t.array[e+1])),r.push(s.getZ(t.array[e+1])),r.push(s.getX(t.array[e+2])),r.push(s.getY(t.array[e+2])),r.push(s.getZ(t.array[e+2]));const i=new z;return i.setAttribute("position",new Q(new Float32Array(r),3)),zs.add_barycentric_attribute(i),i}static add_barycentric_attribute(e){const t=[],s=e.getAttribute("position");for(let e=0;e<s.count;e+=3)t.push(1),t.push(0),t.push(0),t.push(0),t.push(1),t.push(0),t.push(0),t.push(0),t.push(1);e.setAttribute("barycentric",new Q(new Float32Array(t),3))}}class Ts{static load_images(e){const t=e.querySelectorAll("img");for(let e=0;e<t.length;e++){const s=t[e];s.dataset.src&&(s.src=s.dataset.src)}const s=e.querySelectorAll("object");for(let e=0;e<s.length;e++){const t=s[e];t.dataset.src&&(t.data=t.dataset.src)}}static load_videos(e){const t=e.querySelectorAll("video");for(let e=0;e<t.length;e++){const s=t[e];s.dataset.src&&(s.src=s.dataset.src)}}static load_iframes(e){const t=e.querySelectorAll("iframe");for(let e=0;e<t.length;e++){const s=t[e];s.dataset.src&&(s.src=s.dataset.src)}}static load_elements(e,t){const s=e.querySelectorAll(t);for(let e=0;e<s.length;e++){const t=s[e];t.dataset.src&&(t.src=t.dataset.src)}}}class ks{constructor(){}static get_image_data(e){const t=document.createElement("canvas");t.width=e.width,t.height=e.height;const s=t.getContext("2d");return s.drawImage(e,0,0),s.getImageData(0,0,e.width,e.height)}static get_pixel(e,t,s){const r=4*(t+e.width*s),i=e.data;return new _(i[r+0],i[r+1],i[r+2],i[r+3])}}const As=new class{constructor(){}sample(e,s){const r=[];let i=99999999;const n=e.getAttribute("position"),o=e.getAttribute("normal"),a=e.getAttribute("tangent"),l=e.getAttribute("uv"),_=e.index,h=[];for(let e=0;e<_.count;e+=3){const s=_.array[e+0],u=_.array[e+1],d=_.array[e+2],p=new c;p.x=n.getX(s),p.y=n.getY(s),p.z=n.getZ(s);const m=new c;m.x=n.getX(u),m.y=n.getY(u),m.z=n.getZ(u);const g=new c;g.x=n.getX(d),g.y=n.getY(d),g.z=n.getZ(d);const f={a:p,b:m,c:g,normal:void 0,tangent:void 0,uv_a:void 0,uv_b:void 0,uv_c:void 0};if(o){const e=new c;e.x=o.getX(s),e.y=o.getY(s),e.z=o.getZ(s);const t=new c;t.x=o.getX(u),t.y=o.getY(u),t.z=o.getZ(u);const r=new c;r.x=o.getX(d),r.y=o.getY(d),r.z=o.getZ(d);const i=e.clone().add(t).add(r).normalize();f.normal=i}if(a){const e=new c;e.x=a.getX(s),e.y=a.getY(s),e.z=a.getZ(s);const t=new c;t.x=a.getX(u),t.y=a.getY(u),t.z=a.getZ(u);const r=new c;r.x=a.getX(d),r.y=a.getY(d),r.z=a.getZ(d);const i=e.clone().add(t).add(r).normalize();f.tangent=i}if(l){const e=new t;e.x=l.getX(s),e.y=l.getY(s);const r=new t;r.x=l.getX(u),r.y=l.getY(u);const i=new t;i.x=l.getX(d),i.y=l.getY(d),f.uv_a=e,f.uv_b=r,f.uv_c=i}h.push(f);const v=this.get_face_area(f);i=Math.min(v,i),r.push(v)}const u=this.get_uniform_face_distribution(r,i,h),d=this.select_random_faces(u,s);return this.sample_data_from_faces(d)}sample_data_from_faces(e){const t=[],s=[],r=[],i=[];for(let n=0;n<e.length;n++){const o=e[n],a=Math.random(),l=Math.random();t.push(this.sample_point_in_face(a,l,o.a,o.b,o.c).clone()),o.normal&&s.push(o.normal.clone()),o.tangent&&r.push(o.tangent.clone()),o.uv_a&&i.push(this.sample_point_in_face(a,l,o.uv_a,o.uv_b,o.uv_c).clone())}return{points:t,normals:s,tangents:r,uvs:i}}select_random_faces(e,t){const s=[];for(let r=0;r<t;r++){const t=e[Math.floor(Math.random()*e.length)];s.push(t)}return s}get_uniform_face_distribution(e,t,s){const r=[];for(let i=0;i<e.length;i++){e[i]/=t;const n=Math.floor(Math.round(e[i]));for(let e=0;e<n;e++)r.push(s[i])}return r}get_face_area(e){const t=e.b.clone().sub(e.a),s=e.c.clone().sub(e.a);return t.cross(s).length()/2}sample_point_in_face(e,t,s,r,i){e+t>1&&(e=1-e,t=1-t);const n=1-(e+t);return s.clone().multiplyScalar(e).add(r.clone().multiplyScalar(t)).add(i.clone().multiplyScalar(n))}};const Fs=new class{get_mesh(e,t){e.traverse((e=>{e instanceof o&&(e.geometry&&(e.geometry=e.geometry.clone()),t(e))}))}get_geometries(e){const t=[];return this.get_mesh(e,(e=>{t.push(e.geometry)})),t}assign_material(e,t,s){e.traverse((e=>{e instanceof o&&(void 0===s||e.name===s)&&(e.material=t)}))}clone_animated_gltf(e){const t={animations:e.animations,scene:e.scene.clone(!0)},s={};e.scene.traverse((e=>{e.isSkinnedMesh&&(s[e.name]=e)}));const r={},i={};t.scene.traverse((e=>{e.isBone&&(r[e.name]=e),e.isSkinnedMesh&&(i[e.name]=e)}));for(const e in s){const t=s[e].skeleton,n=i[e],o=[];for(let e=0;e<t.bones.length;++e){const s=r[t.bones[e].name];o.push(s)}n.bind(new H(o,t.boneInverses),n.matrixWorld)}return t}set_shadow_config(e,t,s){e.traverse((e=>{e instanceof o&&(e.castShadow=t,e.receiveShadow=s)}))}__find_object(e,t,s){e.traverse((e=>{e.name===t&&s(e)}))}get_object(e,t){let s;return e.traverse((e=>{e.name===t&&(s=e)})),s}get_object_by_type(e,t){let s;return e.traverse((e=>{e.constructor.name===t&&(s=e)})),s}};class Cs{static is_object(e){return e&&"object"==typeof e&&!Array.isArray(e)}static merge_deep(e,...t){if(!t.length)return e;const s=t.shift();if(Cs.is_object(e)&&Cs.is_object(s))for(const t in s)Cs.is_object(s[t])?(e[t]||Object.assign(e,{[t]:{}}),Cs.merge_deep(e[t],s[t])):Object.assign(e,{[t]:s[t]});return Cs.merge_deep(e,...t)}static xml_to_json(e){let t={};if(1===e.nodeType){if(e.attributes.length>0){t["@attributes"]={};for(let s=0;s<e.attributes.length;s++){const r=e.attributes.item(s);t["@attributes"][r.nodeName]=r.nodeValue}}}else 3===e.nodeType&&(t=e.nodeValue);if(e.hasChildNodes())for(let s=0;s<e.childNodes.length;s++){const r=e.childNodes.item(s),i=r.nodeName;if(void 0===t[i])t[i]=this.xml_to_json(r);else{if(void 0===t[i].push){const e=t[i];t[i]=[],t[i].push(e)}t[i].push(this.xml_to_json(r))}}return t}}class Rs{constructor(){}static get_random_color(){const e=[0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F"];let t="#";for(let s=0;s<6;s++){t+=e[Math.floor(Math.random()*e.length)]}return t}static capitalize(e){const t=e.split(" ");for(let e=0;e<t.length;e++)t[e]=t[e][0].toUpperCase()+t[e].substr(1);return t.join(" ")}static capitalize_first_letter(e){return e.charAt(0).toUpperCase()+e.slice(1)}static snake_to_camelcase(e){return e.toLowerCase().replace(/[-_][a-z0-9]/g,(e=>e.slice(-1).toUpperCase()))}}class Ps{constructor(){}time_str_to_ms(e){const t=e.split(":");let s=Number(t[0]);s=60*s*60*1e3;let r=Number(t[1]);r=60*r*1e3;let i=Number(t[2]);return i*=1e3,s+r+i}}class Ls{constructor(){}static is_int(e){return Number(e)===e&&e%1==0}static is_float(e){return Number(e)===e&&e%1!=0}static is_number(e){return this.is_int(e)||this.is_float(e)}static is_json(e){try{JSON.parse(e)}catch(e){return!1}return!0}}class Ds extends o{constructor(){const{colorNode:e,opacityNode:t}=function(e="#4a4a4a"){const t=de(new i(e)),s=(e=>{const t=fe(e),s=ve(me(0),t.mul(1.5),e);return ye(ye(s.x,s.y),s.z)})(pe("barycentric","vec3").add(me(1,1,0)));return{colorNode:ge(t,me(0),s),opacityNode:s.oneMinus().mul(.2)}}("#4a4a4a"),s=new ue({transparent:!0,depthWrite:!1});s.colorNode=e,s.opacityNode=t;const r=new a(100,100,100,100);super(zs.convert_to_non_indexed_geometry(r),s),this.rotation.x=-1.57}}class js extends o{constructor(t){const s=new z;s.setAttribute("position",new Q(new Float32Array([]),3)),s.setAttribute("next_position",new Q(new Float32Array([]),3)),s.setAttribute("previous_position",new Q(new Float32Array([]),3)),s.setAttribute("orientation",new Q(new Float32Array([]),1)),s.setAttribute("coverage",new Q(new Float32Array([]),1));const r=new e({uniforms:{_Thickness:{value:.2},_Length:{value:0},_ElapsedTime:{value:0},_Color:{value:new i("#FF0000")}},vertexShader:"#define GLSLIFY 1\nuniform float _Thickness;attribute vec3 next_position;attribute vec3 previous_position;attribute float orientation;attribute float coverage;varying float line_coverage;varying float uv_u;vec3 w_space_normal(vec3 from,vec3 to){vec3 w_from=(modelMatrix*vec4(from,1.0)).xyz;vec3 w_to=(modelMatrix*vec4(to,1.0)).xyz;vec3 z=normalize(w_to-w_from);return normalize(cross(z,normalize(cameraPosition-w_from)));}void main(){mat4 VP=projectionMatrix*viewMatrix;vec3 pos=position;vec3 normal=w_space_normal(next_position,previous_position);pos=(modelMatrix*vec4(pos,1.0)).xyz;pos+=normal*(_Thickness*0.5)*orientation;gl_Position=VP*vec4(pos,1.0);line_coverage=coverage;uv_u=orientation*0.5+0.5;}",fragmentShader:"#define GLSLIFY 1\nuniform float _Length;uniform float _ElapsedTime;uniform float _Thickness;uniform vec3 _Color;varying float line_coverage;varying float uv_u;float aastep(float threshold,float value){\n#ifdef GL_OES_standard_derivatives\nfloat afwidth=length(vec2(dFdx(value),dFdy(value)))*0.70710678118654757;return smoothstep(threshold-afwidth,threshold+afwidth,value);\n#else\nreturn step(threshold,value);\n#endif\n}void main(){float u=(1.0-abs(uv_u*2.0-1.0));float diffuse=dot(vec2(u,u),vec2(0.0,1.0))*0.5+0.5;gl_FragColor=vec4(_Color*diffuse,1.0);}",transparent:!0,depthWrite:!1});super(s,r),this.material=r,t&&this.setup(t)}setup(e){const t=[],s=[],r=[],i=[],n=[];let o=0;for(let a=0;a<e.length;a++){t.push(e[a].x),t.push(e[a].y),t.push(e[a].z),i.push(1),t.push(e[a].x),t.push(e[a].y),t.push(e[a].z),i.push(-1);const l=this.__get_next_position(e,a);s.push(l.x),s.push(l.y),s.push(l.z),s.push(l.x),s.push(l.y),s.push(l.z);const _=this.__get_previous_position(e,a);r.push(_.x),r.push(_.y),r.push(_.z),r.push(_.x),r.push(_.y),r.push(_.z),n.push(o),n.push(o),a<e.length-1&&(o+=e[a].distanceTo(l))}const a=new Float32Array(t),l=new Float32Array(s),_=new Float32Array(r),h=new Float32Array(i),c=new Float32Array(n),u=[];for(let e=0;e<(a.length/3-2)/2;e++){const t=2*e+1;u.push(t),u.push(t+1),u.push(t-1),u.push(t),u.push(t+2),u.push(t+1)}this.geometry.setIndex(u),this.geometry.getAttribute("position").copy(new Q(a,3)),this.geometry.getAttribute("next_position").copy(new Q(l,3)),this.geometry.getAttribute("previous_position").copy(new Q(_,3)),this.geometry.getAttribute("orientation").copy(new Q(h,1)),this.geometry.getAttribute("coverage").copy(new Q(c,1)),this.geometry.getAttribute("position").needsUpdate=!0,this.geometry.getAttribute("next_position").needsUpdate=!0,this.geometry.getAttribute("previous_position").needsUpdate=!0,this.geometry.getAttribute("orientation").needsUpdate=!0,this.geometry.getAttribute("coverage").needsUpdate=!0,this.material.uniforms._Length.value=o,this._length=o,this.accumulated_length=o}set thickness(e){this.material.uniforms._Thickness.value=e}get thickness(){return this.material.uniforms._Thickness.value}__get_previous_position(e,t){return 0===t?e[1].clone().sub(e[0]).multiplyScalar(-1).add(e[0]):e[t-1]}__get_next_position(e,t){return t===e.length-1?e[e.length-2].clone().sub(e[e.length-1]).multiplyScalar(-1).add(e[e.length-1]):e[t+1]}update(){}distance(){return this.accumulated_length}total_length(){return this.accumulated_length}dispose(){this.geometry.dispose(),this.material.dispose(),this.parent&&this.parent.remove(this)}set color(e){this.material.uniforms._Color.value.set(e)}get color(){return this.material.uniforms._Color.value}copy_color(e){this.material.uniforms._Color.value.copy(e)}}class Us extends o{constructor(s,r){r=r||new t(0,0);const i=new e({uniforms:{_MainTex:{value:s},_ScreenAligned:{value:0},_Scale:{value:1},_Opacity:{value:1}},vertexShader:"#define GLSLIFY 1\nvarying vec2 vUv;uniform float _ScreenAligned;uniform float _Scale;void main(){vec3 pos=position;mat4 local_to_camera=modelViewMatrix;float scale=_Scale;local_to_camera[0]=mix(modelViewMatrix[0],vec4(1.0*scale,0.0,0.0,0.0),_ScreenAligned);local_to_camera[1]=mix(modelViewMatrix[1],vec4(0.0,1.0*scale,0.0,0.0),_ScreenAligned);local_to_camera[2]=mix(modelViewMatrix[2],vec4(0.0,0.0,1.0*scale,0.0),_ScreenAligned);gl_Position=projectionMatrix*local_to_camera*vec4(pos,1.0);vUv=uv;}",fragmentShader:"#define GLSLIFY 1\nuniform sampler2D _MainTex;varying vec2 vUv;uniform float _Opacity;void main(){gl_FragColor=texture2D(_MainTex,vUv);gl_FragColor.a*=_Opacity;}",transparent:!0,depthWrite:!1,side:K}),n=new a(1,1,1);n.translate(-r.x/2,-r.y/2,0);const o=s.image.width/s.image.height;n.scale(o,1,1),super(n,i),this.current_scale=o,this.geometry.computeBoundingBox(),this.tmp_bb_size=new c,this.geometry.boundingBox.getSize(this.tmp_bb_size),this.material=i}update_texture(){this.material.uniforms._MainTex.value.needsUpdate=!0;const e=this.material.uniforms._MainTex.value.image;this.geometry.scale(1/this.current_scale,1,1),this.current_scale=e.width/e.height,this.geometry.scale(this.current_scale,1,1),this.geometry.computeBoundingBox(),this.geometry.boundingBox.getSize(this.tmp_bb_size)}get size(){return this.tmp_bb_size.clone().multiplyScalar(this.scale.x)}set size(e){this.scale.copy(e),this.material.uniforms._Scale.value=e}set screen_aligned(e){this.material.uniforms._ScreenAligned.value=!0===e?1:0}get screen_aligned(){return 1===this.material.uniforms._ScreenAligned.value}set opacity(e){this.material.uniforms._Opacity.value=e}get opacity(){return this.material.uniforms._Opacity.value}dispose(){this.geometry.dispose(),this.parent.remove(this),this.material.uniforms._MainTex.value.dispose(),this.material.dispose()}}class Os extends Us{constructor(e,t,s,r){const i=new xt,n={font:t,font_color:s||"#000000"},o=i.draw_on_texture(e,n);o.minFilter=Z,o.minFilter=$,o.needsUpdate=!0,super(o,r),this.simple_text_drawer=i,this.canvas_texture=o,this.draw_settings=n}set text(e){this.simple_text_drawer.draw_canvas(e,this.draw_settings),this.update_texture()}get text(){return"not implemented"}}class Ns extends o{constructor(e,t){super(e,t),this.material=t;const s=this;this.onBeforeRender=()=>{"update"in s.material&&"function"==typeof s.material.update&&s.material.update()}}}class qs extends Ae{constructor(e){super("#define GLSLIFY 1\nattribute vec4 transformsCol0;attribute vec4 transformsCol1;attribute vec4 transformsCol2;attribute vec4 transformsCol3;attribute vec4 glyph_bounds;attribute vec4 plane_bounds;attribute vec4 color;varying vec2 vUv;varying vec4 v_glyph_bounds;varying vec4 v_color;void main(){vec4 pos=vec4(position,1.0);pos.x*=plane_bounds.z;pos.y*=plane_bounds.w;pos.x+=plane_bounds.x;pos.y+=plane_bounds.y;mat4 offset_matrix=mat4(transformsCol0,transformsCol1,transformsCol2,transformsCol3);gl_Position=projectionMatrix*viewMatrix*offset_matrix*pos;vUv=uv;v_glyph_bounds=glyph_bounds;v_color=color;}","#define GLSLIFY 1\nuniform sampler2D _Texture;uniform float _Boldness;varying vec2 vUv;uniform vec2 _AtlasSize;varying vec4 v_glyph_bounds;varying vec4 v_color;float median(float r,float g,float b){return max(min(r,g),min(max(r,g),b));}void main(){float left=v_glyph_bounds.x/_AtlasSize.x;float right=v_glyph_bounds.y/_AtlasSize.x;float top=v_glyph_bounds.z/_AtlasSize.y;float bottom=v_glyph_bounds.w/_AtlasSize.y;float width=abs(right-left);float height=abs(top-bottom);vec2 coord=vec2(vUv.x*width+left,vUv.y*height+top-height);vec4 col=texture2D(_Texture,coord);float sig_dist=median(col.r,col.g,col.b);float _Cutoff=_Boldness;float dist=(_Cutoff-sig_dist);vec2 ddist=vec2(dFdx(dist),dFdy(dist));float pixelDist=dist/length(ddist);float opacity=clamp(0.5-pixelDist,0.0,1.0);gl_FragColor=vec4(v_color.rgb,opacity*v_color.a);}",{_Texture:{value:e},_Boldness:{value:.5},_AtlasSize:{value:new t(1,1)}}),this.transparent=!0,this.depthWrite=!1,this.side=K,e.minFilter=$,e.magFilter=$,e.generateMipmaps=!1}set_atlas_size(e){this.uniforms._AtlasSize.value.copy(e)}set_boldness(e){this.uniforms._Boldness.value=at.lerp(.5,.2,e)}}class Is{constructor(e,s,r){const i=s.right-s.left,n=s.top-s.bottom;this.scale=new t(i,n),this.position=new t(e+s.left,s.bottom),this.atlas_bounds=new _(r.left,r.right,r.top,r.bottom)}}class Es{constructor(e,s=""){this.glyph_layout=e,this.glyphs=[],this.glyph_is_dirty=!0,this.matrix_is_dirty=!0,this.color_is_dirty=!0,this.position=new c,this.quaternion=new q,this.scale=new c(1,1,1),this.matrix=new I,this.color=new i("#FFFFFF"),this.pivot_point=new t,this.__opacity=1,this.__text=s,this.__generate_glyphs(s)}set text(e){this.__text=e,this.__generate_glyphs(e),this.matrix_is_dirty=!0}get text(){return this.__text}update_matrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrix_is_dirty=!1,this.glyph_is_dirty=!0}clear_glyph_dirty(){this.glyph_is_dirty=!1}clear_color_dirty(){this.color_is_dirty=!1}set_rotation(e=0,t=0){const s=(new q).setFromAxisAngle(new c(0,1,0),e/360*Math.PI*2),r=(new q).setFromAxisAngle(new c(1,0,0),-t/360*Math.PI*2);this.quaternion.copy(s.multiply(r)),this.matrix_is_dirty=!0}set_position(e){this.position.copy(e),this.matrix_is_dirty=!0}set_size(e){this.scale.set(e,e,e),this.matrix_is_dirty=!0}set_color(e){this.color.set(e),this.color_is_dirty=!0}set_pivot(e){this.pivot_point.copy(e),this.update_glyphs()}set opacity(e){this.__opacity=e,this.color_is_dirty=!0}get opacity(){return this.__opacity}update_glyphs(){this.__generate_glyphs(this.text)}__generate_glyphs(e){let s=0;this.glyphs.length=0;for(let t=0;t<e.length;t++){const r=e.charCodeAt(t),i=this.glyph_layout.find((e=>e.unicode===r));if(i){if(i.planeBounds){const e=new Is(s,i.planeBounds,i.atlasBounds);this.glyphs.push(e)}s+=i.advance}}const r=new J,i=this.glyphs[0];r.setFromCenterAndSize(i.position.clone().add(new t(i.scale.x/2,i.scale.y/2)),i.scale);for(let e=1;e<this.glyphs.length;e++){const s=this.glyphs[e],i=(new J).setFromCenterAndSize(s.position.clone().add(new t(s.scale.x/2,s.scale.y/2)),s.scale);r.union(i)}const n=new t;r.getSize(n);for(let e=0;e<this.glyphs.length;e++)this.glyphs[e].position.x-=n.x/2,this.glyphs[e].position.y-=n.y/2,this.glyphs[e].position.x+=n.x/2*this.pivot_point.x,this.glyphs[e].position.y+=n.y/2*this.pivot_point.y;this.glyph_is_dirty=!0}}class Ys extends o{constructor(e,s){const r=new ee;r.instanceCount=0;const i=new a(1,1);i.translate(.5,.5,0),r.setAttribute("position",new te(i.getAttribute("position").array,3)),r.setAttribute("uv",new te(i.getAttribute("uv").array,2)),r.index=i.index;const n=new se(new Float32Array(8e3),4,!1),o=new se(new Float32Array(8e3),4,!1),l=new se(new Float32Array(8e3),4,!1),_=new se(new Float32Array(8e3),4,!1),h=new se(new Float32Array(8e3),4,!1),c=new se(new Float32Array(8e3),4,!1),u=new se(new Float32Array(8e3),4,!1);n.usage=re,o.usage=re,l.usage=re,_.usage=re,h.usage=re,c.usage=re,u.usage=re,r.setAttribute("transformsCol0",n),r.setAttribute("transformsCol1",o),r.setAttribute("transformsCol2",l),r.setAttribute("transformsCol3",_),r.setAttribute("glyph_bounds",h),r.setAttribute("plane_bounds",c),r.setAttribute("color",u),super(r,new qs(s)),this.text_elements=[],this.font_layout=e,this.material.set_atlas_size(new t(e.atlas.width,e.atlas.height)),this.frustumCulled=!1}set_boldness(e){this.material.set_boldness(e)}add_text(e){const t=new Es(this.font_layout.glyphs,e);return this.text_elements.push(t),t}remove_text(e){Ms.remove_elem(this.text_elements,e),this.update(!0)}update(e){const t=this.geometry.getAttribute("glyph_bounds"),s=this.geometry.getAttribute("plane_bounds"),r=this.geometry.getAttribute("transformsCol0"),i=this.geometry.getAttribute("transformsCol1"),n=this.geometry.getAttribute("transformsCol2"),o=this.geometry.getAttribute("transformsCol3"),a=this.geometry.getAttribute("color");let l=!0===e,_=!0===e,h=!0===e,c=0;for(let e=0;e<this.text_elements.length;e++){const u=this.text_elements[e];u.matrix_is_dirty&&(l=!0,u.update_matrix()),u.glyph_is_dirty&&(_=!0,u.clear_glyph_dirty()),u.color_is_dirty&&(h=!0,u.clear_color_dirty());const d=u.matrix,p=u.color,m=u.opacity;for(let e=0;e<u.glyphs.length;e++){const l=u.glyphs[e],_=c;t.setXYZW(_,l.atlas_bounds.x,l.atlas_bounds.y,l.atlas_bounds.z,l.atlas_bounds.w),s.setXYZW(_,l.position.x,l.position.y,l.scale.x,l.scale.y),r.setXYZW(_,d.elements[0],d.elements[1],d.elements[2],d.elements[3]),i.setXYZW(_,d.elements[4],d.elements[5],d.elements[6],d.elements[7]),n.setXYZW(_,d.elements[8],d.elements[9],d.elements[10],d.elements[11]),o.setXYZW(_,d.elements[12],d.elements[13],d.elements[14],d.elements[15]),a.setXYZW(_,p.r,p.g,p.b,m),c++}}this.geometry.instanceCount=c,c>this.max_allocations&&console.error("SDFTextBatch exceeded maximum glyph allocations(max/current): ",this.max_allocations,c,this),l&&(r.needsUpdate=!0,i.needsUpdate=!0,n.needsUpdate=!0,o.needsUpdate=!0),_&&(t.needsUpdate=!0,s.needsUpdate=!0),h&&(a.needsUpdate=!0)}dispose(){this.geometry.dispose(),this.material.dispose()}}class Bs extends ht{constructor(e,t=new c,s=new c(1,1,1),r="linear"){super(r),this.attribute_name=e,this.from=t,this.to=s}update(e,t){const s=this.from.clone();s.lerp(this.to,this.easing_function(t)),e[this.attribute_name].copy(s)}}class Vs extends Se{constructor(){super("#define GLSLIFY 1\nuniform sampler2D _MainTex;uniform vec2 _Resolution;varying vec2 vUv;void main(){vec4 col=texture2D(_MainTex,vUv);gl_FragColor=col;gl_FragColor.a=col.a;}")}set offset(e){this.uniforms._Offset.value=e}get offset(){return this.uniforms._Offset.value}}class $s extends Se{constructor(e){super(e?"#define GLSLIFY 1\nuniform sampler2D _MainTex;uniform vec2 _Resolution;varying vec2 vUv;vec4 upsample(vec2 uv,vec2 halfpixel){vec4 sum=texture2D(_MainTex,uv+vec2(-halfpixel.x*2.0,0.0));sum+=texture2D(_MainTex,uv+vec2(-halfpixel.x,halfpixel.y))*2.0;sum+=texture2D(_MainTex,uv+vec2(0.0,halfpixel.y*2.0));sum+=texture2D(_MainTex,uv+vec2(halfpixel.x,halfpixel.y))*2.0;sum+=texture2D(_MainTex,uv+vec2(halfpixel.x*2.0,0.0));sum+=texture2D(_MainTex,uv+vec2(halfpixel.x,-halfpixel.y))*2.0;sum+=texture2D(_MainTex,uv+vec2(0.0,-halfpixel.y*2.0));sum+=texture2D(_MainTex,uv+vec2(-halfpixel.x,-halfpixel.y))*2.0;return sum/12.0;}void main(){vec2 half_pixel;half_pixel.x=0.5/_Resolution.x;half_pixel.y=0.5/_Resolution.y;gl_FragColor=upsample(vUv,half_pixel);}":"#define GLSLIFY 1\nuniform sampler2D _MainTex;uniform vec2 _Resolution;varying vec2 vUv;vec4 downsample(vec2 uv,vec2 halfpixel){vec4 sum=texture2D(_MainTex,uv)*4.0;sum+=texture2D(_MainTex,uv-halfpixel);sum+=texture2D(_MainTex,uv+halfpixel);sum+=texture2D(_MainTex,uv+vec2(halfpixel.x,-halfpixel.y));sum+=texture2D(_MainTex,uv-vec2(halfpixel.x,-halfpixel.y));return sum/8.0;}void main(){vec2 half_pixel=vec2(0.5/_Resolution.x,0.5/_Resolution.y);gl_FragColor=downsample(vUv,half_pixel);}")}}class Gs{constructor(){this.current_width=1,this.current_height=1,this.RT0=new h(1,1),this.RT1=new h(1,1),this.RT2=new h(1,1),this.RT3=new h(1,1),this.RT4=new h(1,1),this.upscale_blur_mat=new $s(!0),this.downscale_blur_mat=new $s(!1),this.alpha_filter_mat=new Vs}blur(e){this.check_RT_resize(e.width,e.height),qe.blit(e,this.RT1,this.alpha_filter_mat),qe.blit(this.RT1,this.RT2,this.downscale_blur_mat),qe.blit(this.RT2,this.RT3,this.downscale_blur_mat),qe.blit(this.RT3,this.RT4,this.downscale_blur_mat),qe.blit(this.RT4,this.RT3,this.upscale_blur_mat),qe.blit(this.RT3,this.RT2,this.upscale_blur_mat),qe.blit(this.RT2,e,this.upscale_blur_mat)}check_RT_resize(e,t){this.current_width===e&&this.current_height===t||(this.current_width=e,this.current_height=t,this.RT0.setSize(this.current_width/2,this.current_height/2),this.RT1.setSize(this.current_width/2,this.current_height/2),this.RT2.setSize(this.current_width/4,this.current_height/4),this.RT3.setSize(this.current_width/8,this.current_height/8),this.RT4.setSize(this.current_width/16,this.current_height/16))}}class Xs extends Se{constructor(){super("#define GLSLIFY 1\nuniform sampler2D _SourceTex;uniform vec2 _SourceTexSize;varying vec2 vUv;\n#define vec vec4\n#define toVec(x) x.rgba\n#define s2(a, b) temp = a; a = min(a, b); b = max(temp, b);\n#define t2(a, b) s2(v[a], v[b]);\n#define t24(a, b, c, d, e, f, g, h) t2(a, b); t2(c, d); t2(e, f); t2(g, h);\n#define t25(a, b, c, d, e, f, g, h, i, j) t24(a, b, c, d, e, f, g, h); t2(i, j);\n#define s2(a, b) temp = a; a = min(a, b); b = max(temp, b);\n#define mn3(a, b, c) s2(a, b); s2(a, c);\n#define mx3(a, b, c) s2(b, c); s2(a, c);\n#define mnmx3(a, b, c) mx3(a, b, c); s2(a, b);\n#define mnmx4(a, b, c, d) s2(a, b); s2(c, d); s2(a, c); s2(b, d);\n#define mnmx5(a, b, c, d, e) s2(a, b); s2(c, d); mn3(a, c, e); mx3(b, d, e);\n#define mnmx6(a, b, c, d, e, f) s2(a, d); s2(b, e); s2(c, f); mn3(a, b, c); mx3(d, e, f);\nvoid main(){vec2 inv_size=vec2(1.0/_SourceTexSize.x,1.0/_SourceTexSize.y);\n#ifdef kernel5x5\nvec v[25];for(int dX=-2;dX<=2;++dX){for(int dY=-2;dY<=2;++dY){vec2 offset=vec2(float(dX),float(dY));v[(dX+2)*5+(dY+2)]=toVec(texture2D(_SourceTex,vUv+offset*inv_size));}}vec temp;t25(0,1,3,4,2,4,2,3,6,7);t25(5,7,5,6,9,7,1,7,1,4);t25(12,13,11,13,11,12,15,16,14,16);t25(14,15,18,19,17,19,17,18,21,22);t25(20,22,20,21,23,24,2,5,3,6);t25(0,6,0,3,4,7,1,7,1,4);t25(11,14,8,14,8,11,12,15,9,15);t25(9,12,13,16,10,16,10,13,20,23);t25(17,23,17,20,21,24,18,24,18,21);t25(19,22,8,17,9,18,0,18,0,9);t25(10,19,1,19,1,10,11,20,2,20);t25(2,11,12,21,3,21,3,12,13,22);t25(4,22,4,13,14,23,5,23,5,14);t25(15,24,6,24,6,15,7,16,7,19);t25(3,11,5,17,11,17,9,17,4,10);t25(6,12,7,14,4,6,4,7,12,14);t25(10,14,6,7,10,12,6,10,6,17);t25(12,17,7,17,7,10,12,18,7,12);t24(10,18,12,20,10,20,10,12);gl_FragColor=v[12];\n#endif\n#ifdef kernel3x3\nvec v[9];for(int dX=-1;dX<=1;++dX){for(int dY=-1;dY<=1;++dY){vec2 offset=vec2(float(dX),float(dY));v[(dX+1)*3+(dY+1)]=toVec(texture2D(_SourceTex,vUv+offset*inv_size));}}vec temp;mnmx6(v[0],v[1],v[2],v[3],v[4],v[5]);mnmx5(v[1],v[2],v[3],v[4],v[6]);mnmx4(v[2],v[3],v[4],v[7]);mnmx3(v[3],v[4],v[8]);toVec(gl_FragColor)=v[4];\n#endif\n}",void 0,{kernel3x3:!0}),this.uniforms._SourceTex={value:void 0},this.uniforms._SourceTexSize={value:new t(1,1)}}set_texture(e){this.uniforms._SourceTex.value=e;const t=this.get_size(e);this.uniforms._SourceTexSize.value.copy(t)}get_size(e){return e.isVideoTexture?new t(Math.max(1,e.image.videoWidth),Math.max(1,e.image.videoHeight)):e.isWebGLRenderTarget?new t(e.width,e.height):e.isTexture?new t(e.image.width,e.image.height):new t(1,1)}}class Ws{constructor(){this.RT=new h(1,1,{type:ie,format:B,minFilter:x,magFilter:x}),this.RT1=new h(1,1,{type:ie,format:B,minFilter:x,magFilter:x}),this.median_filter_mat=new Xs}filter(e){const t=this.get_size(e);t.x===this.RT.width&&t.y===this.RT.height||(this.RT.setSize(t.x,t.y),this.RT1.setSize(t.x,t.y)),this.median_filter_mat.set_texture(e),qe.material_pass(this.median_filter_mat,this.RT);for(let e=0;e<0;e++)this.median_filter_mat.set_texture(this.RT.texture),qe.material_pass(this.median_filter_mat,this.RT1),this.median_filter_mat.set_texture(this.RT1.texture),qe.material_pass(this.median_filter_mat,this.RT);return this.RT}get_size(e){return e.isVideoTexture?new t(Math.max(1,e.image.videoWidth),Math.max(1,e.image.videoHeight)):e.isRenderTarget?new t(e.width,e.height):e.isTexture?new t(e.image.width,e.image.height):new t(1,1)}}class Qs{constructor(e,t){this.read=void 0,this.write=void 0,this.name=e,this.update_material=t}init_from_geometry(e){}init_from_attribute(e){}build_RT(e){const t=Qs.calculate_resolution(e),s={minFilter:x,magFilter:x,format:B,colorScape:f,type:Mt.fp_textures_available?ie:G,stencilBuffer:!1,depthBuffer:!1};return new h(t.width,t.height,s)}static calculate_resolution(e){const t=Math.min(e,512);return{width:t,height:Math.max(1,Math.ceil(e/t))}}swap_RT(){const e=this.read;this.read=this.write,this.write=e}update(e){this.update_material&&(this.update_material.update(),e.children[0]instanceof o&&(e.children[0].material=this.update_material),this.update_material.uniforms._MainTex.value=this.read.texture,qe.render(e,void 0,this.write),e.children[0]instanceof o&&(e.children[0].material=void 0),this.swap_RT())}store_geometry_attribute_in_RT(e,t,s,r){r.children[0]instanceof o&&(r.children[0].geometry.setAttribute("data",e),r.children[0].material=s),qe.render(r,void 0,t),r.children[0]instanceof o&&(r.children[0].geometry.deleteAttribute("data"),r.children[0].material=void 0)}get_texture(){return this.read.texture}}class Hs extends M{constructor(e,t){super(),this.attributes=[],this.mesh=this.build_point_mesh(e,t),this.add(this.mesh),this.attribute_writter_mesh=this.build_attribute_writter_mesh(e),this.attribute_writter_scene=new n,this.attribute_writter_scene.add(this.attribute_writter_mesh)}add_texture_attribute(e){this.attributes.push(e)}add_update_attribute_array(e,t,s){this.attribute_writter_mesh.geometry.setAttribute(e,new Q(t,s,!1))}add_attribute_array(e,t,s){this.mesh.geometry.setAttribute(e,new se(t,s,!1))}update(){const e=this.mesh.material;Array.isArray(e)?e.forEach((e=>e.dispose())):e.dispose();for(let e=0;e<this.attributes.length;e++)this.attributes[e].update(this.attribute_writter_scene)}dispose(){this.mesh.geometry.dispose();const e=this.mesh.material;Array.isArray(e)?e.forEach((e=>e.dispose())):e.dispose()}build_point_mesh(e=1,t){const s=new a,r=new ee;r.setAttribute("position",s.getAttribute("position")),r.index=s.index,r.setAttribute("storage_uv",this.build_uv_storage_attribute(e)),r.instanceCount=e;const i=new o(r,t);return i.frustumCulled=!1,i}build_attribute_writter_mesh(e){const{width:t,height:s}=Qs.calculate_resolution(e),r=new Float32Array(3*e);for(let i=0;i<e;i++){const e=i%t,n=Math.floor(i/t);r[3*i+0]=(e+.5)/t,r[3*i+1]=(n+.5)/s,r[3*i+2]=i}const i=new z;i.setAttribute("position",new Q(r,3,!1));const n=new ne(i);return n.frustumCulled=!1,n}build_uv_storage_attribute(e){const{width:t,height:s}=Qs.calculate_resolution(e),r=new Float32Array(2*e);for(let i=0;i<e;i++){const e=i%t,n=Math.floor(i/t);r[2*i+0]=(e+.5)/t,r[2*i+1]=(n+.5)/s}return new se(r,2,!1)}}class Ks extends e{constructor(e){super({uniforms:{},vertexShader:e=e||"\n varying vec4 value;\n attribute vec4 data;\n\n void main()\n {\n gl_Position = vec4(position.xy * 2.0 - 1.0, 1.0,1.0);\n gl_PointSize = 1.0;\n\n value = data;\n }\n ",fragmentShader:"#define GLSLIFY 1\nvarying vec4 value;void main(){gl_FragColor=value;}",depthWrite:!1,blending:s,depthTest:!1,depthFunc:r})}}class Zs extends Qs{constructor(e){super("_Position",e)}store_geometry(e,t){const s=e.getAttribute("position");this.read=this.build_RT(s.count),this.write=this.build_RT(s.count);const r=new Ks;this.store_geometry_attribute_in_RT(e.getAttribute("position"),this.read,r,t)}store_positions(e,t){this.read=this.build_RT(e.length),this.write=this.build_RT(e.length);const s=new Float32Array(4*e.length);for(let t=0;t<e.length;t++)s[4*t+0]=e[t].x,s[4*t+1]=e[t].y,s[4*t+2]=e[t].z,s[4*t+3]=10*(2*Math.random()-1);const r=new Ks;this.store_geometry_attribute_in_RT(new Q(s,4),this.read,r,t)}}class Js extends Re{constructor(e,t,s){super(e,t,s),this.loader=new be}on_preloaded_finished(e){void 0===e.resources_by_url[this.url]?this.loader.load(this.url,(t=>{e.set_resource(this.resource_id,this.url,t),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(e=>{this.__set_error(e+"\n\n\t If the error says something about unexpected token < in JSON then the probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class er extends Re{constructor(e,t,s){super(e,t,s),this.loader=new oe}on_preloaded_finished(e){void 0===e.resources_by_url[this.url]?this.loader.load(this.url,(t=>{e.set_resource(this.resource_id,this.url,t),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(e=>{this.__set_error(e),this.__loading_ended()})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class tr extends Re{constructor(e,t,s){super(e,t,s),this.loader=new we}on_preloaded_finished(e){void 0===e.resources_by_url[this.url]?this.loader.load(this.url,(t=>{e.set_resource(this.resource_id,this.url,t),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(e=>{this.__set_error(e+"\n\n\t If the error says something about unexpected token < in JSON then probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class sr extends Re{constructor(e,t,s){super(e,t,s)}on_preloaded_finished(e){void 0===e.resources_by_url[this.url]?fetch(this.url).then((t=>{t.json().then((t=>{e.set_resource(this.resource_id,this.url,t),this.__update_downloaded_bytes(1,1),this.__loading_ended()}))})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class rr extends Re{constructor(e,t,s){super(e,t,s),this.loader=new xe}on_preloaded_finished(e){void 0===e.resources_by_url[this.url]?this.loader.load(this.url,(t=>{e.set_resource(this.resource_id,this.url,t),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(e=>{this.__set_error(e+"\n\n\t If the error says something about unexpected token < in JSON then probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class ir extends Re{constructor(e,t,s){super(e,t,s),this.loader=new oe}on_preloaded_finished(e){void 0===e.resources_by_url[this.url]?this.loader.load(this.url,(t=>{e.set_resource(this.resource_id,this.url,this.parse_path(t)),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(e=>{this.__set_error(e),this.__loading_ended()})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}parse_path(e){const t=e.split("\n");""===t[t.length-1]&&t.pop();const s=[];for(let e=0;e<t.length;e+=3){const r=parseFloat(t[e+0]),i=parseFloat(t[e+1]),n=parseFloat(t[e+2]);s.push(new c(r,i,n))}return s}}class nr extends Re{constructor(e,t,s){super(e,t,s),this.loader=new oe}on_preloaded_finished(e){void 0===e.resources_by_url[this.url]?this.loader.load(this.url,(t=>{e.set_resource(this.resource_id,this.url,t),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(e=>{this.__set_error(e),this.__loading_ended()})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class or extends Re{constructor(e,t,s){super(e,t,s)}on_preloaded_finished(e,t){void 0===e.resources_by_url[this.url]?t.blob().then((t=>{const s=new m,r=URL.createObjectURL(t),i=new Image;i.src=r,i.onload=()=>{s.image=i,s.needsUpdate=!0,e.set_resource(this.resource_id,this.url,s),this.__update_downloaded_bytes(1,1),this.__loading_ended()},i.onerror=()=>{console.error("Error loading texture. Maybe the resource is not an image?",this.url)}})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class ar extends Re{constructor(e,t,s){super(e,t,s)}on_preloaded_finished(e,t){void 0===e.resources_by_url[this.url]?t.blob().then((t=>{e.set_resource(this.resource_id,this.url,URL.createObjectURL(t)),this.__update_downloaded_bytes(1,1),this.__loading_ended()})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class lr{constructor(e){this.name=e,this.resources={},this.resources_by_url={}}set_resource(e,t,s){Object.keys(this.resources_by_url).includes(t)?this.resources[e]=this.resources_by_url[t]:(this.resources[e]=s,this.resources_by_url[t]=s)}get_resource(e){return this.resources[e]}get(e){return this.resources[e]}}class _r{constructor(e){this.resource_loaders=[],this.batch_name=e||"unnamed batch"}add_loader(e){this.resource_loaders.push(e)}load(e){for(let t=0;t<this.resource_loaders.length;t++)this.resource_loaders[t].load(e||lr)}get loading_finished(){let e=!0;for(let t=0;t<this.resource_loaders.length;t++)e=e&&this.resource_loaders[t].has_finished;return e}get has_errors(){let e=!1;for(let t=0;t<this.resource_loaders.length;t++)e=e||this.resource_loaders[t].has_error;return e}print_errors(){console.error("Batch <"+this.batch_name+"> could not load successfully");for(let e=0;e<this.resource_loaders.length;e++)this.resource_loaders[e].has_error&&this.resource_loaders[e].print_error()}get_progress(){return this.get_loaded_bytes()/this.get_total_bytes()}get_loaded_bytes(){let e=1;for(let t=0;t<this.resource_loaders.length;t++)e+=this.resource_loaders[t].loaded_bytes;return e}get_total_bytes(){let e=1;for(let t=0;t<this.resource_loaders.length;t++)e+=this.resource_loaders[t].total_bytes;return e}}class hr{start(){this.finished=!1}update(){this.finished=!0}}class cr{constructor(){}on_enter(e){}on_exit(e){}update(e){}}class ur extends cr{constructor(){super(),this.rotation_speed=new t,this.vector_forward_axis=new c(0,0,-1),this.tmp_forward=new c,this.tmp_quat=new q,this.tmp_camera_target_pos=new c}on_enter(e){e.reference_rotation.copy(e.camera.quaternion)}update(e){e.camera.quaternion.copy(e.reference_rotation),this.tmp_forward.copy(this.vector_forward_axis);const t=this.tmp_forward.applyQuaternion(e.camera.quaternion);e.reference_zoom=at.clamp(e.reference_zoom,e.min_zoom,e.max_zoom),e.camera.position.copy(e.reference_position).sub(t.multiplyScalar(e.reference_zoom)),e.__last_reference_position.copy(e.reference_position)}get_target_camera_pos(e){this.tmp_quat.copy(e.reference_rotation),this.tmp_forward.copy(this.vector_forward_axis);const t=this.tmp_forward.applyQuaternion(this.tmp_quat),s=at.clamp(e.reference_zoom,e.min_zoom,e.max_zoom);return this.tmp_camera_target_pos.copy(e.reference_position).sub(t.multiplyScalar(s)),this.tmp_camera_target_pos}}class dr{constructor(){}on_enter(e){}on_exit(e){}update(e){}lock_zoom(){}unlock_zoom(){}}class pr{constructor(e){this.input=e,this.camera=void 0,this.camera_initial_rot=void 0,this.camera_initial_pos=void 0,this.current_state=new dr,this.current_mode=new ur,this.point_of_interest=new c,this.normalized_zoom=0,this.vector_up_axis=new c(0,1,0),this.vector_right_axis=new c(1,0,0),this.vector_forward_axis=new c(0,0,1),this.tmp_forward=this.vector_forward_axis.clone(),this.tmp_right=this.vector_right_axis.clone(),this.tmp_dir=new c,this.zoom=10,this.reference_zoom=10,this.orientation=27,this.tilt=70,this.reference_rotation=new q,this.reference_position=new c,this.__last_reference_position=new c,this.tmp_size=new c,this.tmp_quat=new q,this.min_zoom=1,this.max_zoom=400,this.current_tilt=0,this.current_orientation=0,this.current_azimuth=0,this.projection_plane_helper=new ae(new O,1,16776960),this.input_enabled=!0,this.raised_look_at_position=new c(-82.2986094900191,0,39.7538467209173),this.use_raised_look_at_direction=0}enable(){this.input_enabled=!0}disable(){this.input_enabled=!1}set_camera(e){this.camera=e,this.camera_initial_rot=e.quaternion.clone(),this.camera_initial_pos=e.position.clone()}set_state(e){this.current_state.on_exit(this),this.current_state=e,this.current_state.on_enter(this)}set_mode(e){this.current_mode.on_exit(this),this.current_mode=e,this.current_mode.on_enter(this)}set_normalized_zoom(e){this.normalized_zoom=at.clamp(e,0,1)}update_normalized_zoom(e,t){const s=this.camera.position.distanceTo(this.reference_position);this.normalized_zoom=at.linear_map(s,e,t,1,0),this.normalized_zoom=at.clamp(this.normalized_zoom,0,1)}update(){this.debug_box&&this.debug_box.position.copy(this.reference_position),this.current_state.update(this),this.current_mode.update(this),this.update_normalized_zoom(this.min_zoom,this.max_zoom)}set_idle(){this.set_state(new dr)}camera_is_zoomed_out(){return this.normalized_zoom<.2}set_rotation(e,t,s){this.old_orientation=this.current_orientation,this.current_tilt=e??this.current_tilt,this.current_orientation=t??this.current_orientation,this.current_azimuth=s??this.current_azimuth,this.set_quaternion(this.build_rotation(this.current_tilt,this.current_orientation))}set_rotation_delta(e,t,s=0){this.lerp_rotation(this.current_tilt,this.current_tilt+e,this.current_orientation,this.current_orientation+t,this.current_azimuth,this.current_azimuth+s,1)}lerp_tilt(e,t,s){this.lerp_rotation(e,t,this.current_orientation,this.current_orientation,this.current_azimuth,this.current_azimuth,s)}set_quaternion(e){const t=2*Math.atan2(e.x,e.w),s=2*Math.atan2(e.y,e.w);this.current_orientation=at.radToDeg(s)%360,this.current_tilt=-1*at.radToDeg(t),this.reference_rotation.copy(e)}lerp_quaternion(e,t){this.set_quaternion(this.reference_rotation.clone().slerp(e,t))}lerp_orientation(e,t,s){this.lerp_rotation(this.current_tilt,this.current_tilt,e,t,this.current_azimuth,this.current_azimuth,s)}lerp_azimuth(e,t,s){}lerp_rotation(e,t,s,r,i,n,o){const a=this.build_rotation(e,s),l=this.build_rotation(t,r);a.slerp(l,o),this.set_quaternion(a)}build_rotation(e,t){t<0&&(t+=360);const s=(new q).setFromAxisAngle(this.vector_up_axis,t%360/360*Math.PI*2),r=(new q).setFromAxisAngle(this.vector_right_axis,-e/360*Math.PI*2);return s.multiply(r)}translate_forward(e){this.tmp_forward.copy(this.vector_forward_axis),this.tmp_forward.applyQuaternion(this.camera.quaternion),this.reference_position.add(this.tmp_forward.multiplyScalar(e))}translate_right(e){this.tmp_right.copy(this.vector_right_axis),this.tmp_right.applyQuaternion(this.camera.quaternion),this.reference_position.add(this.tmp_right.multiplyScalar(e))}focus_on_bounding_box(e,t=1){if(this.camera.isOrthographicCamera){e.getSize(this.tmp_size);const t=this.tmp_size.x,s=this.tmp_size.y,r=t/s;Le.aspect_ratio/r>1?this.camera.zoom=Le.height/s:this.camera.zoom=Le.width/t,e.getCenter(this.reference_position)}else{const s=new c;s.copy(e.max).sub(e.min);const r=e.min.clone(),i=r.clone().add(new c(s.x,0,0)),n=r.clone().add(new c(0,s.y,0)),o=r.clone().add(new c(0,0,s.z)),a=r.clone().add(new c(s.x,0,s.z)),l=r.clone().add(new c(0,s.y,s.z)),_=e.max.clone(),h=r.clone().add(new c(s.x,s.y,0));this.focus_camera_on_points([r,i,n,o,a,l,_,h],t)}}get_zoom_to_focus_on_points(e,t){const s=this.reference_zoom,r=(new c).copy(this.reference_position);this.focus_camera_on_points(e,t);const i=this.reference_zoom;return this.reference_zoom=s,this.reference_position.copy(r),i}get_target_pos_to_focus_on_points(e,t){const s=this.reference_zoom,r=(new c).copy(this.reference_position);this.focus_camera_on_points(e,t);const i=this.reference_position.clone();return this.reference_zoom=s,this.reference_position.copy(r),i}focus_camera_on_sphere(e,t){this.reference_zoom=this.get_zoom_to_sphere(e,t),this.reference_position.copy(e.center)}get_zoom_to_sphere(e,t){const s=this.camera.fov/2*Math.PI/180,r=2*Math.atan(Math.tan(s)*this.camera.aspect)/2,i=e.radius/Math.tan(s),n=e.radius/Math.tan(r);return Math.max(Math.abs(n),Math.abs(i))}hide_projected_points(){for(let e=0;e<this.projected_points.length;e++)this.projected_points[e].visible=!1}show_projected_points(e){this.hide_projected_points();for(let t=0;t<e.length;t++)this.projected_points[t].visible=!0,this.projected_points[t].position.copy(e[t])}show_plane_projection(e,t=1){this.projection_plane_helper.plane=e,this.projection_plane_helper.size=t,this.projection_plane_helper.updateMatrixWorld(),this.projection_plane_helper.visible=!0}show_sphere_projection(e){this.projection_sphere_helper.scale.set(e.radius,e.radius,e.radius),this.projection_sphere_helper.position.copy(e.center),this.projection_sphere_helper.visible=!0}fit_points(e,t,s=1){if(this.camera.isPerspectiveCamera){const r=new c(0,0,-1).applyQuaternion(e),i=r.clone().multiplyScalar(-1),n=new Kt,o=Le.aspect_ratio,a=n.fit_points(t,e,this.camera.fov*s,o),l=(new L).setFromPoints(t),_=new c;l.getCenter(_);const h=(new O).setFromNormalAndCoplanarPoint(i,_),u=new E(a,r),d=new c;u.intersectPlane(h,d);return{zoom:a.distanceTo(d),reference_position:d,camera_position:a}}{const r=(new Ht).fit_points(t,this.reference_rotation,this.camera.fov*s,Le.aspect_ratio);this.reference_position.copy(r.center),this.reference_zoom=r.distance_to_center;const i=new c(0,0,1).applyQuaternion(e);return{zoom:r.distance_to_center,reference_position:r.center,camera_position:i.multiplyScalar(r.distance_to_center)}}}focus_camera_on_points(e,t=1){if(this.camera.isPerspectiveCamera){const s=new c(0,0,-1).applyQuaternion(this.reference_rotation),r=s.clone().multiplyScalar(-1),i=new Kt,n=Le.aspect_ratio,o=i.fit_points(e,this.reference_rotation,this.camera.fov*t,n),a=(new L).setFromPoints(e),l=new c;a.getCenter(l);const _=(new O).setFromNormalAndCoplanarPoint(r,l),h=new E(o,s),u=new c;h.intersectPlane(_,u);const d=o.distanceTo(u);this.reference_zoom=d,this.reference_position.copy(u)}else{const s=(new Ht).fit_points(e,this.reference_rotation,this.camera.fov*t,Le.aspect_ratio);this.reference_position.copy(s.center),this.reference_zoom=s.distance_to_center}}get_current_tilt(){return this.current_tilt}get_current_orientation(){return this.current_orientation}get_current_azimuth(){return this.current_azimuth}__get_zoom_to_show_rect(e,t,s=1){const r=at.degToRad(this.camera.fov/2),i=2*Math.atan(Math.tan(r)*this.camera.aspect)/2,n=t/Math.tan(r*s),o=e/Math.tan(i*s);return Math.max(Math.abs(o),Math.abs(n))}}class mr extends dr{constructor(e){super(),this.input=e,this.last_point=new t,this.rotation_velocity=new t,this.forward_dir=0,this.right_dir=0,this.y_dir=0,this.azimuth_dir=0,this.shift_key=!1}on_enter(e){}on_exit(e){}update(e){this.__check_key_down(),this.__check_key_up()}__show_camera_position(e){this.input.left_mouse_button_released&&console.log({x:e.reference_position.x,y:e.reference_position.y,z:e.reference_position.z,orientation:e.current_orientation,tilt:e.current_tilt,azimuth:e.current_azimuth,zoom:e.reference_zoom,fov:e.camera.fov})}__zoom_camera(e){e.reference_zoom+=.5*this.input.zoom_delta}__rotate_camera(e){if(this.input.left_mouse_button_down&&1===this.input.pointer_count){const e=new t(-24*this.input.NDC_delta.x,-8*this.input.NDC_delta.y);e.multiplyScalar(60*mt.delta_time),this.rotation_velocity.add(e)}e.set_rotation_delta(this.rotation_velocity.y,this.rotation_velocity.x);const s=1-Math.exp(-5*mt.delta_time);this.rotation_velocity.lerp(new t(0,0),s)}__move_camera(e){if(e.translate_forward(this.forward_dir),e.translate_right(this.right_dir),e.reference_position.y-=this.y_dir,this.input.right_mouse_button_pressed&&this.last_point.copy(this.input.NDC),this.input.right_mouse_button_down){const t=Zt.get_plane_intersection(e.reference_position,void 0,this.last_point).clone(),s=Zt.get_plane_intersection(e.reference_position,void 0,this.input.NDC).clone();s.sub(t),e.reference_position.x-=s.x,e.reference_position.y-=s.y,e.reference_position.z-=s.z,this.last_point.copy(this.input.NDC)}}__check_key_down(){const e=.12;this.input.keyboard.is_key_down("KeyW")&&(this.forward_dir=-.12),this.input.keyboard.is_key_down("KeyS")&&(this.forward_dir=e),this.input.keyboard.is_key_down("KeyA")&&(this.right_dir=-.12),this.input.keyboard.is_key_down("KeyD")&&(this.right_dir=e),this.input.keyboard.is_key_down("KeyQ")&&(this.azimuth_dir=.48),this.input.keyboard.is_key_down("KeyE")&&(this.azimuth_dir=-.48),this.input.keyboard.is_key_down("KeyZ")&&(this.y_dir=e),this.input.keyboard.is_key_down("KeyC")&&(this.y_dir=-.12),this.input.keyboard.is_key_down("ShiftLeft")&&(this.shift_key=!0)}__check_key_up(){this.input.keyboard.is_key_released("KeyW")&&(this.forward_dir=0),this.input.keyboard.is_key_released("KeyS")&&(this.forward_dir=0),this.input.keyboard.is_key_released("KeyA")&&(this.right_dir=0),this.input.keyboard.is_key_released("KeyD")&&(this.right_dir=0),this.input.keyboard.is_key_released("KeyQ")&&(this.azimuth_dir=0),this.input.keyboard.is_key_released("KeyE")&&(this.azimuth_dir=0),this.input.keyboard.is_key_released("KeyZ")&&(this.y_dir=0),this.input.keyboard.is_key_released("KeyC")&&(this.y_dir=0),this.input.keyboard.is_key_released("ShiftLeft")&&(this.shift_key=!1)}}export{dr as AbstractCameraState,Re as AbstractLoader,nt as AbstractScene,ot as ActionEvent,ht as ActionInterpolator,lt as ActionSequencer,dt as ActionSequencerBuilder,ze as AddMaterial,bt as ApplicationView,Ms as ArrayUtilities,qt as Arrow,Be as AsyncAbstractLoader,Ve as AsyncAudiosLoader,Xe as AsyncObjectsLoader,Qe as AsyncTextureLoader,et as AsyncTexturesLoader,Ee as AudioLoader,Me as BaseApplication,Ce as BaseRender,Ae as BaseShaderMaterial,He as BasisLoader,Se as BlitMaterial,_s as Blurrer,We as Browser,Xt as CSSAnimator,St as CameraBridge,pr as CameraController,Pe as CameraManager,cr as CameraMovementMode,Zt as CameraUtilities,wt as CanvasDrawer,Mt as Capabilities,zt as CaptureService,mr as CommonCameraState,hr as Compilator,At as ConsoleBuffer,It as Cube,Ke as CubemapLoader,Js as DAELoader,Yt as Debug,rs as DebugNormalsRender,Vt as DevBridge,ut as DrawIOAnimationSheet,$s as DualFilteringBlurMaterial,Gs as DualFilteringBlurrer,_t as EasingFunctions,er as FileLoader,tr as FontLoader,Ss as FrustumPointFitter,$e as GLTFDRACOLoader,Ge as GLTFLoader,Hs as GPUParticleSystem,ps as GaussianBlurrer,zs as GeometryUtilities,qe as Graphics,Ds as Grid,Ze as HDRCubeTextureLoader,Je as HDRTextureLoader,Ts as HTMLUtilities,rt as HighQualityLoadingState,ws as HorizontalPlane,ks as ImageUtilities,ur as ImmediateMode,Jt as Initializer,Ct as InputSynthesizer,sr as JSONLoader,es as KeyboardInput,js as Line,st as LoadingState,Ws as MedianFilter,As as MeshSampler,Fs as ModelUtilities,hs as NormalAORender,cs as NormalRender,ct as NumberInterpolator,rr as OBJLoader,at as OMath,Wt as OS,Le as OScreen,Cs as ObjectUtilities,ts as OrthographicCamera,Ht as OrthographicFrustumPointFitter,Qs as ParticleAttribute,Zs as ParticlePositionAttribute,Rt as PerformanceProbe,Nt as PerspectiveCamera,Kt as PerspectiveFrustumPointFitter,ir as PointArrayLoader,it as RegularLoadingState,vs as RenderLoop,Pt as RenderModeRegistry,_r as ResourceBatch,Ye as ResourceContainer,Ys as SDFTextBatch,Lt as SceneEditor,Dt as SceneInspector,De as SceneManager,ys as Screen,xt as SimpleTextDrawer,Et as Sphere,Rs as StringUtilities,Os as Text2D,nr as TextLoader,or as TextureLoader,mt as Time,Ps as TimeUtilities,vt as TransitionManager,pt as TransitionTable,Fe as UnrealBloomComposeMaterial,ms as UnrealBloomRender,Ns as UpdatableMaterialMesh,gs as VRRender,Ls as Validation,Bs as VectorInterpolator,xs as VerticalPlane,ar as VideoLoader,bs as ViewComponent,fs as ViewComponentManager,yt as ViewManager,jt as ViewNavigator,Us as WorldImage};
1
+ import{Texture as t,Vector2 as e,NoBlending as s,Color as r,Scene as i,Mesh as n,PlaneGeometry as o,OrthographicCamera as a,Vector4 as h,RenderTarget as _,Vector3 as l,PositionalAudio as c,Audio as u,AudioContext as d,SRGBColorSpace as p,NoColorSpace as m,CubeTextureLoader as g,CanvasTexture as f,UVMapping as y,ClampToEdgeWrapping as b,NearestFilter as w,DoubleSide as x,LinearFilter as v,Quaternion as z,Matrix4 as M,Box2 as T,InstancedBufferGeometry as k,Float32BufferAttribute as A,InstancedInterleavedBuffer as S,DynamicDrawUsage as R,InterleavedBufferAttribute as C,Sphere as j,Box3 as F,TextureLoader as q,Object3D as P,LineBasicMaterial as N,AlwaysDepth as O,BufferGeometry as L,Line as $,LinearMipMapLinearFilter as U,PerspectiveCamera as B,CylinderGeometry as E,ConeGeometry as I,MeshBasicMaterial as D,BoxGeometry as Q,SphereGeometry as V,Box3Helper as Y,CatmullRomCurve3 as W,Plane as X,Line3 as H,Ray as Z,CustomBlending as K,OneFactor as J,AdditiveBlending as G,BackSide as tt,DataTexture as et,RGBAFormat as st,RepeatWrapping as rt,HalfFloatType as it,UnsignedByteType as nt,LinearSRGBColorSpace as ot,BufferAttribute as at,Skeleton as ht,FileLoader as _t,PlaneHelper as lt}from"three";import{texture as ct,uniform as ut,vec4 as dt,positionGeometry as pt,uv as mt,mix as gt,Fn as ft,fract as yt,vec2 as bt,dot as wt,vec3 as xt,float as vt,normalize as zt,abs as Mt,positionView as Tt,normalView as kt,attribute as At,mat4 as St,cameraProjectionMatrix as Rt,cameraViewMatrix as Ct,varying as jt,max as Ft,min as qt,length as Pt,dFdx as Nt,dFdy as Ot,clamp as Lt,modelViewMatrix as $t,colorSpaceToWorking as Ut,packNormalToRGB as Bt,normalWorldGeometry as Et,screenUV as It,modelViewPosition as Dt,saturate as Qt,uniformArray as Vt,cross as Yt,Loop as Wt,smoothstep as Xt,step as Ht,floor as Zt,ivec2 as Kt,fwidth as Jt,modelWorldMatrix as Gt,cameraPosition as te}from"three/tsl";import{NodeMaterial as ee,MeshBasicNodeMaterial as se}from"three/webgpu";import{GLTFLoader as re}from"three/examples/jsm/loaders/GLTFLoader.js";import{HDRCubeTextureLoader as ie}from"three/examples/jsm/loaders/HDRCubeTextureLoader.js";import{HDRLoader as ne}from"three/examples/jsm/loaders/HDRLoader.js";import*as oe from"three/examples/jsm/utils/BufferGeometryUtils.js";export{oe as BufferGeometryUtils};import{ColladaLoader as ae}from"three/examples/jsm/loaders/ColladaLoader.js";import{FontLoader as he}from"three/examples/jsm/loaders/FontLoader.js";import{OBJLoader as _e}from"three/examples/jsm/loaders/OBJLoader.js";class le{on_post_start(){}on_enter(t){}on_exit(t){}before_update(){}update(){}fixed_update(){}on_post_render(){}on_pre_render(){}on_frame_end(){}dispose(){}}class ce extends ee{constructor(){super(),this.uv_by_texture=new Map,this.top_left_origin_by_texture=new Map,this.uniforms={_MainTex:ct(new t),_Resolution:ut(new e(0,0)),_TargetResolution:ut(new e(0,0))},this.vertexNode=dt(pt.xy.mul(2),0,1),this.fragmentNode=this.sample_main_tex(),this.depthWrite=!1,this.depthTest=!1,this.blending=s}uv_for(t){let e=this.uv_by_texture.get(t);return void 0===e&&(e=this.texture_uv_at(t,mt()),this.uv_by_texture.set(t,e)),e}texture_uv_at(t,e){let s=this.top_left_origin_by_texture.get(t);return void 0===s&&(s=ut(!1).onObjectUpdate((()=>{return!0===(e=t.value).isRenderTargetTexture||!0===e.isFramebufferTexture||!0===e.isDepthTexture;var e})),this.top_left_origin_by_texture.set(t,s)),s.select(e.flipY(),e)}sample(t,e){const s=this.uv_for(t);return t.sample(e?s.add(e):s)}sample_main_tex(t){return this.sample(this.uniforms._MainTex,t)}}class ue extends ce{constructor(e=!1){super();const s=ct(new t);this.uniforms._SecondTex=s,this.fragmentNode=this.sample_main_tex().add(this.sample(s))}set_add_texture(t){this.uniforms._SecondTex.value=t}}const de=[1,.8,.6,.4,.2];class pe extends ce{constructor(e,s=!1){super();const i=ut(1),n=ut(1),o=[];this.uniforms.bloomStrength=i,this.uniforms.bloomRadius=n;let a=dt(0);for(let s=0;s<e;s++){const e=ct(new t),i=new r("#FFFFFF"),h=de[s]??de[de.length-1],_=gt(h,1.2-h,n);this.uniforms[`blurTexture${s+1}`]=e,o.push(i),a=a.add(this.sample(e).mul(dt(ut(i),1)).mul(_))}this.uniforms.bloomTintColors={value:o},this.fragmentNode=a.mul(i)}set_blur_texture_0(t){this.uniforms.blurTexture1.value=t}set_blur_texture_1(t){this.uniforms.blurTexture2.value=t}set_blur_texture_2(t){this.uniforms.blurTexture3.value=t}set_blur_texture_3(t){this.uniforms.blurTexture4.value=t}set_blur_texture_4(t){this.uniforms.blurTexture5.value=t}set_bloom_strength(t){this.uniforms.bloomStrength.value=t}set_bloom_radius(t){this.uniforms.bloomRadius.value=t}set_tint_color_0(t){this.uniforms.bloomTintColors.value[0].set(t)}set_tint_color_1(t){this.uniforms.bloomTintColors.value[1].set(t)}set_tint_color_2(t){this.uniforms.bloomTintColors.value[2].set(t)}set_tint_color_3(t){this.uniforms.bloomTintColors.value[3].set(t)}set_tint_color_4(t){this.uniforms.bloomTintColors.value[4].set(t)}}class me{constructor(){}render(t){}on_enter(t,e){}on_exit(t,e){}resize(){}dispose(){}}class ge{constructor(t,e,s=1){this.resource_id=t,this.url=e,this.loaded_bytes=0,this.total_bytes=s,this.has_finished=!1,this.has_error=!1,this.error_message="none"}__update_downloaded_bytes(t,e){t=this.is_number(t)?t:1,e=this.is_number(e)?e:1,this.loaded_bytes=t,e>0&&(this.total_bytes=e),this.loaded_bytes>this.total_bytes&&console.warn("Total bytes is smaller than loaded ones. Please set total bytes by hand to:",this.url)}__loading_ended(){this.has_finished=!0}__set_error(t){this.has_error=!0,this.error_message=t}print_error(){console.error("Error while loading "+this.resource_id+"\n\t path: "+this.url+"\n\t\t"+this.error_message)}load(t){if(void 0===t.resources_by_url[this.url]){const e="default";fetch(this.url,{method:"GET",mode:"cors",cache:e,credentials:"same-origin",redirect:"follow"}).then(this.on_progress.bind(this,t)).catch(this.__on_error.bind(this))}else t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended()}async on_progress(t,e){const s=e.clone(),r=e.body.getReader(),i=+e.headers.get("Content-Length");let n=0;for(;;){const{done:t,value:e}=await r.read();if(t)break;n+=e.length,this.__update_downloaded_bytes(n,i)}e.ok?this.on_preloaded_finished(t,s):(this.__set_error(`${e.status}: ${e.statusText}`),this.__loading_ended())}on_preloaded_finished(t,e){}__on_error(t){console.error(t)}is_int(t){return Number(t)===t&&t%1==0}is_float(t){return Number(t)===t&&t%1!=0}is_number(t){return this.is_int(t)||this.is_float(t)}}const fe=new class{init(){this._current=void 0,this._spectator=void 0}set current(t){this._current=t}get current(){return this._current}set spectator(t){this._spectator=t}get spectator(){return this._spectator}};const ye=new class{init(){this.width=1,this.height=1,this.position=new e,this.render_width=1,this.render_height=1,this.width_height=new e(this.width,this.height),this.dpr=1,this.pixel_size=new e(1/this.width,1/this.height)}update_position(t,e){this.position.set(t,e)}update(){this.size_changed=!1}update_size(t,s){this.width=t,this.height=s,this.pixel_size=new e(1/this.width,1/this.height),this.width_height.x=t,this.width_height.y=s,this.render_width=t*this.dpr,this.render_height=s*this.dpr,this.size_changed=!0}apply_pixel_density_v2(t){return t.multiplyScalar(1/this.dpr),t}apply_pixel_density(t){return t*(1/this.dpr)}get_pixel_size(){return this.pixel_size}get aspect_ratio(){return this.width/this.height}get portrait(){return this.width<this.height}};const be=new class{init(t){this._current=t}add_scene(t){}get current(){return this._current}set current(t){this._current=t}dispose(){for(this.current.traverse((t=>{if(t.geometry){t.geometry.dispose();const e=t.material;Array.isArray(e)?e.forEach((t=>t.dispose())):e.dispose()}}));this.current.children.length>0;)this.current.remove(this.current.children[0])}};class we{constructor(t){this.renderer=t,this._blit_scene=new i,this._blit_material=new ce,this._blit_quad=new n(new o(1,1),this._blit_material),this._blit_scene.add(this._blit_quad),this._blit_camera=new a(-1,1,1,-1,-1e4,1e4)}blit(t,e){this._blit_quad.material=this._blit_material;const s=!0===t.isRenderTarget?t.texture:t,r=!0===t.isRenderTarget?t.width:t.image.width,i=!0===t.isRenderTarget?t.height:t.image.height;this._blit_quad.material.uniforms._MainTex.value=s,this._blit_quad.material.uniforms._Resolution.value.set(r,i),e?this._blit_quad.material.uniforms._TargetResolution.value.set(e.width,e.height):this.renderer.getSize(this._blit_quad.material.uniforms._TargetResolution.value),this.__render(e)}material_pass(t,e){this._blit_quad.material=t,this.__render(e)}blit_with_material(t,e,s){const r=!0===t.isRenderTarget?t.texture:t,i=!0===t.isRenderTarget?t.width:t.image.width,n=!0===t.isRenderTarget?t.height:t.image.height;this._blit_quad.material=s,this._blit_quad.material.uniforms._MainTex.value=r,this._blit_quad.material.uniforms._Resolution.value.set(i,n),e?this._blit_quad.material.uniforms._TargetResolution.value.set(e.width,e.height):this.renderer.getSize(this._blit_quad.material.uniforms._TargetResolution.value),this.__render(e)}blit_clear_with_material(t,e){this._blit_quad.material=e,this.__render(t)}dispose(){this._blit_quad.geometry.dispose(),this._blit_quad.material.dispose()}__render(t){const e=void 0===t?null:t,s=this.renderer.getRenderTarget();this.renderer.setRenderTarget(e),this.renderer.render(this._blit_scene,this._blit_camera),this.renderer.setRenderTarget(s)}}const xe=1.7777,ve=ft((([t])=>{const e=yt(bt(1,255).mul(t));return bt(e.x.sub(e.y.div(255)),e.y)})),ze=ft((([t])=>wt(t,bt(1,1/255)))),Me=ft((([t])=>t.xy.div(t.z.add(1)).div(xe).mul(.5).add(.5))),Te=ft((([t])=>{const e=xt(t.mul(3.5554).sub(xe),1),s=vt(2).div(wt(e,e));return xt(e.xy.mul(s),s.sub(1))}));class ke extends ce{constructor(t,e){super();const s=ut(new h(t,e.x,e.y,e.z));this.uniforms._DepthNormal=s,this.fragmentNode=dt(ve(s.x),Me(zt(s.yzw)))}}class Ae extends ee{constructor(){super();const t=ut(1);this.uniforms={_FarPlane:t},this.fragmentNode=dt(ve(Mt(Tt.z).div(t)),Me(zt(kt))),this.blending=s}set far_plane(t){this.uniforms._FarPlane.value=t}get far_plane(){return this.uniforms._FarPlane.value}}class Se{constructor(){this.RT=new _(ye.width,ye.height),this.clear_depth_normal_mat=new ke(1,new l(0,0,1)),this.depth_normal_material=new Ae}render(t){this.__resize_RT_if_necessary(),t.clear(this.RT,void 0,!0,!0),t.blit_clear_with_material(this.RT,this.clear_depth_normal_mat),this.depth_normal_material.far_plane=fe.current.far,t.render(void 0,void 0,this.RT,this.depth_normal_material)}__resize_RT_if_necessary(){this.RT.width===ye.width&&this.RT.height===ye.height||this.RT.setSize(ye.width,ye.height)}get render_target(){return this.RT}}const Re=new class{init({renderer:t,core_attributes:e,dpr:s}){this._renderer=t,this.blitter=void 0,this.canvas=void 0,this.no_render=void 0,this.current_render_mode=void 0,this.generate_depth_normal_texture=!1,this.depth_and_normals_renderer=void 0,this.core_attributes={xr_enabled:!1},Object.assign(this.core_attributes,e),this.core_attributes.xr_enabled?this._renderer.xr.enabled=!0:this._renderer.autoClear=!1,ye.dpr=s,this._renderer.setPixelRatio(s),this.blitter=new we(this._renderer),this.canvas=this._renderer.domElement,this.no_render=new me,this.current_render_mode=this.no_render,this.generate_depth_normal_texture=!1,this.depth_and_normals_renderer=new Se}get dom_element(){return this._renderer.domElement}get depth_normals_RT(){return this.depth_and_normals_renderer.render_target}set_state(t){this.current_render_mode.on_exit(this,this._renderer),this.current_render_mode=t,this.current_render_mode.on_enter(this,this._renderer)}update(){this.generate_depth_normal_texture&&this.depth_and_normals_renderer.render(this),this.__update_current_camera(),fe.current&&this.current_render_mode.render(),ye.update()}__update_current_camera(){fe.current&&(fe.current.aspect=ye.aspect_ratio,fe.current.updateProjectionMatrix(),fe.current.updateMatrix(),fe.current.updateMatrixWorld(!0))}render(t,e,s,r){this.__apply_override_material(t,r),this._renderer.setRenderTarget(void 0===s?null:s),this._renderer.render(t||be.current,e||fe.current),this.__apply_override_material(t,void 0)}async compile(t,e,s,r){this.__apply_override_material(t,r),this._renderer.setRenderTarget(void 0===s?null:s),await this._renderer.compile(t||be.current,e||fe.current),this.__apply_override_material(t,void 0)}async compile_async(t,e,s,r,i){this.__apply_override_material(t,r),this._renderer.setRenderTarget(void 0===s?null:s);const n=this._renderer.compileAsync(t||be.current,e||fe.current,i);return this.__apply_override_material(t,void 0),n}render_scene(t){"on_pre_render"in t&&t.on_pre_render(),"render"in t?t.render():this.render(t,void 0),"on_post_render"in t&&t.on_post_render()}__apply_override_material(t,e){e=void 0===e?null:e,t?t.overrideMaterial=e:be.current.overrideMaterial=e}async readback_RT(t){return this._renderer.readRenderTargetPixelsAsync(t,0,0,t.width,t.height)}clear(t,e,s,r){this._renderer.setRenderTarget(void 0===t?null:t),e&&this._renderer.setClearColor(e.clear_color,e.clear_alpha),this._renderer.clear(!!e,!!s,!!r)}on_resize(t,e){for(const s of t)ye.dpr=e,ye.update_position(s.contentRect.x,s.contentRect.y),ye.update_size(s.contentRect.width,s.contentRect.height),this.canvas.width=ye.render_width,this.canvas.height=ye.render_height,this._renderer.setViewport(0,0,ye.render_width,ye.render_height),this._renderer.setSize(ye.width,ye.height),this.__update_current_camera()}material_pass(t,e){this.blitter.material_pass(t,e)}blit(t,e,s){s?this.blitter.blit_with_material(t,e,s):this.blitter.blit(t,e)}blit_clear_with_material(t,e){this.blitter.blit_clear_with_material(t,e)}take_screenshot(t,e=ye.width,s=ye.height){const r=ye.width,i=ye.height,n=e,o=s,a=1024,h=1024,_=Math.ceil(n/a),l=Math.ceil(o/h);ye.update_size(a,h);const c=this._renderer.getPixelRatio();this._renderer.setPixelRatio(1),this._renderer.setSize(a,h,!1);const u=document.createElement("canvas").getContext("2d");u.canvas.width=n,u.canvas.height=o,fe.current.aspect=ye.aspect_ratio,fe.current.updateMatrix(),fe.current.updateMatrixWorld(!0);for(let t=0;t<_;t++)for(let e=0;e<l;e++)fe.current.setViewOffset(n,o,ye.width*t,ye.height*e,ye.width,ye.height),this.current_render_mode.render(),u.drawImage(this._renderer.domElement,ye.width*t,ye.height*e);u.canvas.toBlob(t,"image/png;base64;"),fe.current.clearViewOffset(),ye.update_size(r,i),this._renderer.setPixelRatio(c),this._renderer.setSize(r,i,!1),fe.current.aspect=ye.aspect_ratio,fe.current.updateMatrix(),fe.current.updateMatrixWorld(!0)}download_screenshot(t){const e=document.createElement("a");e.download="Snapshot.png",e.href=URL.createObjectURL(t),e.click(),e.onclick=function(){requestAnimationFrame((function(){URL.revokeObjectURL(e.href)})),e.removeAttribute("href")}}dispose(){this._renderer.dispose(),this.current_render_mode.dispose(),this.blitter.dispose()}};class Ce{constructor(t,e=!0,s=1,r=!1){this.buffer=t,this.loop=e,this.volume=s,this.positional=r,this.audio=void 0}init(t){this.positional?this.audio=new c(t):this.audio=new u(t),this.audio.setBuffer(this.buffer),this.audio.setLoop(this.loop),this.audio.gain.gain.value=0,this.audio.setVolume(this.loop?0:this.volume)}play(){this.audio.play()}pause(){this.audio.pause()}stop(){this.audio.stop()}get is_playing(){return this.audio.isPlaying}}class je extends ge{constructor(t,e,s=!0,r=0,i,n=!1){super(t,e,i),this.loop=s,this.volume=r,this.positional=n}on_preloaded_finished(t){void 0===t.resources_by_url[this.url]?this.instantiate_audio(t):(t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}instantiate_audio(t){const e=d.getContext(),s=e.createBuffer(2,22050,44100);fetch(this.url).then((t=>t.blob())).then((r=>{r.arrayBuffer?r.arrayBuffer().then((s=>{e.decodeAudioData(s,(e=>{t.set_resource(this.resource_id,this.url,new Ce(e,this.loop,this.volume,this.positional)),this.__update_downloaded_bytes(1,1),this.__loading_ended()}))})):(t.set_resource(this.resource_id,this.url,new Ce(s,this.loop,this.volume,this.positional)),this.__update_downloaded_bytes(1,1),this.__loading_ended())}))}}const Fe=new class{init(){this.resources={},this.resources_by_url={}}set_resource(t,e,s){Object.keys(this.resources_by_url).includes(e)?this.resources[t]=this.resources_by_url[e]:(this.resources[t]=s,this.resources_by_url[e]=s)}get_resource(t){return this.resources[t]}get(t){return this.resources[t]}};class qe{constructor(t,e,s){this.resource_container=Fe,this.assets=e,this.name=t,this.worker=s,this.bound_on_message=this.on_message.bind(this),this.__setup_worker(),this.assets_loaders=this.__setup_loaders()}load(){this.worker.postMessage({type:"load",loader_name:this.name})}is_loaded(){for(let t=0;t<this.assets_loaders.length;t++){const e=this.assets_loaders[t];if(!e.has_finished)return!1;e.has_error&&(e.url=e.original_url,e.print_error())}return!0}get_progress(){return this.__get_loaded_bytes()/this.__get_total_bytes()}__get_loaded_bytes(){let t=1;for(let e=0;e<this.assets_loaders.length;e++)t+=this.assets_loaders[e].loaded_bytes;return t}__get_total_bytes(){let t=1;for(let e=0;e<this.assets_loaders.length;e++)t+=this.assets_loaders[e].total_bytes;return t}get_assets_names(){const t=[];for(let e=0;e<this.assets.length;e++){const s=this.assets[e];t.push(s.name)}return t}static create_worker(){return new Worker(new URL("./assets_loader/AsyncAssetsLoaderWorker.ts",import.meta.url),{name:"OHZI - AssetLoader",type:"module"})}__setup_worker(){this.worker.addEventListener("message",this.bound_on_message),this.worker.postMessage({type:"assets",loader_name:this.name,data:this.assets})}on_message(t){const e=t.data;if(e.type===`asset_loaded_${this.name}`)this.__on_assets_loaded(e.data)}__on_assets_loaded(t){this.worker.removeEventListener("message",this.bound_on_message);for(let e=0;e<this.assets_loaders.length;e++){const s=this.assets_loaders[e];s.original_url=s.url,s.url=t[s.resource_id],s.on_preloaded_finished(this.resource_container)}}__setup_loaders(){return console.warn("Not implemented"),[]}}class Pe extends qe{constructor(t,e,s){super(t,e,s)}__setup_loaders(){const t=[];for(let e=0;e<this.assets.length;e++){const s=this.assets[e];t.push(new je(s.name,s.url,s.loop,s.volume,s.size,s.positional))}return t}}class Ne extends ge{constructor(t,e,s,r){super(t,e,r),this.loader=new re,this.loader.setDRACOLoader(s)}on_preloaded_finished(t){void 0===t.resources_by_url[this.url]?this.loader.load(this.url,(e=>{t.set_resource(this.resource_id,this.url,e),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(t=>{this.__set_error(t+"\n\n\t If the error says something about unexpected token < in JSON then the probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class Oe extends ge{constructor(t,e,s){super(t,e,s),this.loader=new re}on_preloaded_finished(t){void 0===t.resources_by_url[this.url]?this.loader.load(this.url,(e=>{t.set_resource(this.resource_id,this.url,e),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(t=>{this.__set_error(t+"\n\n\t If the error says something about unexpected token < in JSON then the probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class Le extends qe{constructor(t,e,s){super(t,e,s)}__setup_loaders(){const t=[];for(let e=0;e<this.assets.length;e++){const s=this.assets[e];if(s.draco){const e=Fe.get("draco_loader");t.push(new Ne(s.name,s.url,e,s.size))}else t.push(new Oe(s.name,s.url,s.size))}return t}}const $e=new class{async init(){switch(this.browser_name="",this.agent=window.navigator.userAgent.toLowerCase(),this.has_web_xr_support="xr"in navigator,this.is_vr=this.has_web_xr_support&&await navigator.xr.isSessionSupported("immersive-vr"),!0){case this.agent.indexOf("edge")>-1:this.browser_name="edge_ie";break;case this.agent.indexOf("edg")>-1:this.browser_name="edge_chromium";break;case this.agent.indexOf("opr")>-1&&!!window.opr:this.browser_name="opera";break;case this.agent.indexOf("chrome")>-1&&!!window.chrome:this.browser_name="chrome";break;case this.agent.indexOf("trident")>-1:this.browser_name="iexplorer";break;case this.agent.indexOf("firefox")>-1:this.browser_name="firefox";break;case this.agent.indexOf("safari")>-1:this.browser_name="safari";break;default:this.browser_name="other"}this.version=this.get_version()}get name(){return this.browser_name}get is_safari(){return"safari"===this.browser_name}get is_chrome(){return"chrome"===this.browser_name}get is_firefox(){return"firefox"===this.browser_name}get is_edge(){return"edge_ie"===this.browser_name}get is_edge_chromium(){return"edge_chromium"===this.browser_name}get has_webm(){return!!(this.is_chrome||this.is_firefox||this.is_edge_chromium)}get has_hvec(){return this.is_safari}get preferred_video_extension(){return this.has_webm?"webm":this.has_hvec?"hvec.mp4":"mp4"}get_version(){const t=navigator.userAgent;let e=[],s="0",r=t.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];return/trident/i.test(r[1])&&(e=/\brv[ :]+(\d+)/g.exec(t)||[],s="IE "+(e[1]||"")),"Chrome"===r[1]&&(e=t.match(/\b(OPR|Edge)\/(\d+)/),null!=e&&(s=e.slice(1).join(" ").replace("OPR","Opera"))),r=r[2]?[r[1],r[2]]:[navigator.appName,navigator.appVersion,"-?"],null!=(e=t.match(/version\/(\d+(\.\d+)?)/i))&&r.splice(1,1,e[1]),s=r.join(" "),Number(s.split(" ")[1])}};class Ue extends ge{constructor(t,e,s,r=!0,i=!1,n=!0){super(t,e,s),this.original_url="",this.colorSpaceConversion=n,this.premultiplyAlpha=i,this.flipY=r}on_preloaded_finished(t){$e.is_safari?this.load_with_old_method(t):this.load_with_new_method(t)}load_with_old_method(e){if(void 0===e.resources_by_url[this.url]){const s=new t,r=new Image;r.src=this.url,r.onload=()=>{s.image=r,s.flipY=this.flipY,s.premultiplyAlpha=this.premultiplyAlpha,s.colorSpace=this.colorSpaceConversion?p:m,s.needsUpdate=!0,e.set_resource(this.resource_id,this.url,s),this.__update_downloaded_bytes(1,1),this.__loading_ended()},r.onerror=()=>{console.error("The source image could not be decoded.",this.original_url)}}else e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended()}load_with_new_method(e){if(void 0===e.resources_by_url[this.url]){const s={credentials:"same-origin"};fetch(this.url,s).then((t=>t.blob())).then((t=>createImageBitmap(t,{colorSpaceConversion:this.colorSpaceConversion?"default":"none",imageOrientation:this.flipY?"flipY":"from-image",premultiplyAlpha:this.premultiplyAlpha?"premultiply":"none"}))).then((s=>{const r=new t(s);r.flipY=this.flipY,r.premultiplyAlpha=this.premultiplyAlpha,r.colorSpace=this.colorSpaceConversion?p:m,r.needsUpdate=!0,e.set_resource(this.resource_id,this.url,r),this.__update_downloaded_bytes(1,1),this.__loading_ended()})).catch((t=>{console.error(t,this.original_url)}))}else e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended()}}class Be extends ge{constructor(t,e,s,r){super(t,e,r),this.loader=s}on_preloaded_finished(t){void 0===t.resources_by_url[this.url]?this.loader.load(this.url,(e=>{t.set_resource(this.resource_id,this.url,e),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(t=>{}),(t=>{this.__set_error(t+"\n\n\t If the error says something about unexpected token < in JSON then the probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class Ee extends ge{constructor(t,e,s,r){super(t,e,r),this.loader=new g,this.loader.setPath(e+"/"),this.urls=[`px.${s}`,`nx.${s}`,`py.${s}`,`ny.${s}`,`pz.${s}`,`nz.${s}`]}on_preloaded_finished(t){void 0===t.resources_by_url[this.url]?this.loader.load(this.urls,(e=>{t.set_resource(this.resource_id,this.url,e),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(t=>{this.__set_error("Image could not be loaded. Maybe wrong name or path, I don't know¯\\_(ツ)_/¯"+t),this.__loading_ended()})):(t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class Ie extends ge{constructor(t,e,s,r){super(t,e,r),this.loader=new ie,this.loader.setPath(e+"/"),this.urls=[`px.${s}`,`nx.${s}`,`py.${s}`,`ny.${s}`,`pz.${s}`,`nz.${s}`]}on_preloaded_finished(t){void 0===t.resources_by_url[this.url]?this.loader.load(this.urls,(e=>{t.set_resource(this.resource_id,this.url,e),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(t=>{this.__set_error(t+"\n\n\t If the error says something about unexpected token < in JSON then the probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class De extends ge{constructor(t,e,s){super(t,e,s),this.loader=new ne}on_preloaded_finished(t){void 0===t.resources_by_url[this.url]?this.loader.load(this.url,(e=>{t.set_resource(this.resource_id,this.url,e),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(t=>{this.__set_error(t+"\n\n\t If the error says something about unexpected token < in JSON then the probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class Qe extends qe{constructor(t,e,s){super(t,e,s)}__setup_loaders(){const t=[];for(let e=0;e<this.assets.length;e++){const s=this.assets[e];switch(s.kind){case"regular":t.push(new Ue(s.name,s.url,s.size,s.flipY,s.premultiplyAlpha,s.colorSpaceConversion));break;case"basis":t.push(new Be(s.name,s.url,Fe.get("basis_loader"),s.size));break;case"hdr":t.push(new De(s.name,s.url,s.size));break;case"cubemap":t.push(new Ee(s.name,s.url,s.extension,s.size));break;case"cubemap_hdr":t.push(new Ie(s.name,s.url,s.extension,s.size))}}return t}}class Ve{constructor(t){this.compilators=t,this.first_update=!0,this.index=0}update(){this.is_finished()||(this.compilators[this.index].finished?(this.index++,this.first_update=!0):this.first_update?(this.compilators[this.index].start(),this.first_update=!1):this.compilators[this.index].update())}is_finished(){return this.index===this.compilators.length}}class Ye{constructor(t,{SceneCompilator:e,TexturesCompilator:s,AudiosCompilator:r}){this.scene=t,this.SceneCompilator=e,this.TexturesCompilator=s,this.AudiosCompilator=r,this.loaders=[],this.compilators=[],this.callback_called=!1}set_assets(t,e,s,r=[],i=[],n=[]){this.scene_objects=t,this.scene_textures=e,this.scene_sounds=s,this.custom_loaders=r,this.custom_compilators=i,this.custom_data=n}get loading_progress(){let t=0;for(let e=0;e<this.loaders.length;e++){t+=this.loaders[e].get_progress()}return t/this.loaders.length}load(){this.setup_loader(),this.loaders[0].load()}on_enter(){}on_exit(){}update(){}setup_loader(){const t=[],e=Fe.get("assets_worker");e.postMessage({type:"reset",loader_name:this.scene.name});const s=new Le(this.scene.name,this.scene_objects,e);this.loaders.push(s),t.push(new this.SceneCompilator(this.scene));const r=new Qe(this.scene.name,this.scene_textures,e);this.loaders.push(r),t.push(new this.TexturesCompilator(r.get_assets_names()));const i=new Pe(this.scene.name,this.scene_sounds,e);this.loaders.push(i),t.push(new this.AudiosCompilator(i.get_assets_names()));for(let s=0;s<this.custom_loaders.length;s++){const r=new this.custom_loaders[s](this.scene.name,this.custom_data[s],e);this.loaders.push(r),t.push(new this.custom_compilators[s](r.get_assets_names()))}this.compilator_manager=new Ve(t)}is_loaded(){let t=!0;for(let e=0;e<this.loaders.length;e++){const s=this.loaders[e];t=t&&s.is_loaded()}return t}is_compiled(){return this.compilator_manager.update(),this.compilator_manager.is_finished()}}class We extends Ye{on_enter(){super.on_enter()}on_exit(){super.on_exit()}update(){super.update(),this.is_loaded()&&this.scene.on_high_quality_assets_ready()}}class Xe extends Ye{constructor(t,e){super(t,e),this.on_assets_ready_called=!1}on_enter(){super.on_enter()}on_exit(){super.on_exit()}update(){super.update(),this.is_loaded()&&(this.on_assets_ready_called||(this.scene.on_assets_ready(),this.on_assets_ready_called=!0),this.is_compiled()&&this.scene.on_assets_compiled())}}class He extends i{constructor({name:t,compilators:e}){super(),this.name=t,this.initialized=!1,this.is_loaded=!1,this.is_high_loaded=!1,this.loading_states={regular:new Xe(this,e),high:new We(this,e)},this.current_loading_state=new Ye(this,e)}get loading_progress(){return this.current_loading_state.loading_progress}init(){this.initialized=!0}load(){this.initialized||this.init(),this.set_loading_state(this.loading_states.regular),this.current_loading_state.load()}get_objects(){const t=[];return this.traverse((e=>{e instanceof n&&e.geometry&&t.push(e)})),t}dispose_cpu(){this.traverse((t=>{if(t instanceof n&&t.geometry&&(t.geometry.attributes.position.array=new Float32Array(3),t.geometry.attributes.normal&&(t.geometry.attributes.normal.array=new Float32Array(3)),t.geometry.attributes.uv&&(t.geometry.attributes.uv.array=new Float32Array(2)),t.material.map))for(let e=0;e<t.material.map.mipmaps.length;e++)t.material.map.mipmaps[e]=new Uint8Array(4)})),this.initialized=!1}dispose(){this.traverse((t=>{t instanceof n&&t.material&&(t.material.map&&t.material.map.dispose(),t.material.dispose(),t.geometry.dispose())})),this.initialized=!1,super.dispose()}set_assets(t,e,s,r,i,n){this.loading_states.regular.set_assets(t,e,s,r,i,n)}set_high_assets(t,e,s,r,i,n){this.loading_states.high.set_assets(t,e,s,r,i,n)}set_loading_state(t){this.current_loading_state.on_exit(),this.current_loading_state=t,this.current_loading_state.on_enter()}update_loading_state(){this.is_high_loaded||this.current_loading_state.update()}update(){this.update_loading_state()}on_assets_ready(){}on_assets_compiled(){this.is_loaded=!0,this.set_loading_state(this.loading_states.high),this.current_loading_state.load()}on_high_quality_assets_ready(){this.is_high_loaded=!0}on_pre_render(){}render(){Re.render(this,fe.current)}on_post_render(){}}class Ze{constructor(t,e,s){this.name=t,this.method=e,this.args=s}trigger(){ViewApi.application[this.name][this.method](...this.args.split(","))}}class Ke{constructor(){}static linear_map(t,e,s,r,i){return(t-e)/(s-e)*(i-r)+r}static between(t,e,s){return t>=e&&t<=s}static mod(t,e){return(t%e+e)%e}static rgb_to_hex(t){return t.r=Math.round(255*parseFloat(t.r)).toString(16),t.g=Math.round(255*parseFloat(t.g)).toString(16),t.b=Math.round(255*parseFloat(t.b)).toString(16),1===t.r.length&&(t.r="0"+t.r),1===t.g.length&&(t.g="0"+t.g),1===t.b.length&&(t.b="0"+t.b),"#"+t.r+t.g+t.b}static project_points_on_plane(t,e){const s=t[0].clone();s.set(0,0,0);const r=[];for(let i=0;i<t.length;i++)e.projectPoint(t[i],s),r.push(s.clone());return r}static matrix4_lerp(t,e,s,r){for(let i=0;i<16;i++)s.elements[i]=this.lerp(t.elements[i],e.elements[i],r)}static equals(t,e){return Math.abs(t-e)<1e-6}static lerp(t,e,s){return(1-s)*t+s*e}static clamp(t,e,s){return Math.max(e,Math.min(s,t))}static euclideanModulo(t,e){return(t%e+e)%e}static pingpong(t,e=1){return e-Math.abs(Ke.euclideanModulo(t,2*e)-e)}static degToRad(t){return t*(Math.PI/180)}static radToDeg(t){return t*(180/Math.PI)}static deg_to_rad(t){return t*(Math.PI/180)}static rad_to_deg(t){return t*(180/Math.PI)}static perspective_divide(t){return t.x/=t.w,t.y/=t.w,t.z/=t.w,t}static points_average(t){const e=t[0].clone();for(let s=1;s<t.length;s++)e.add(t[s]);return e.multiplyScalar(1/t.length),e}static get_random_color(){const t=[0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f"];let e="#";return e+=t[Math.floor(16*Math.random())],e+=t[Math.floor(16*Math.random())],e+=t[Math.floor(16*Math.random())],e+=t[Math.floor(16*Math.random())],e+=t[Math.floor(16*Math.random())],e+=t[Math.floor(16*Math.random())],e}static saturate(t){return Ke.clamp(t,0,1)}static generate_uuid(){const t=["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"],e=4294967295*Math.random()|0,s=4294967295*Math.random()|0,r=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return(t[255&e]+t[e>>8&255]+t[e>>16&255]+t[e>>24&255]+"-"+t[255&s]+t[s>>8&255]+"-"+t[s>>16&15|64]+t[s>>24&255]+"-"+t[63&r|128]+t[r>>8&255]+"-"+t[r>>16&255]+t[r>>24&255]+t[255&i]+t[i>>8&255]+t[i>>16&255]+t[i>>24&255]).toLowerCase()}}class Je{constructor(t={}){this.previous_elapsed_time=-1e-5,this.elapsed_time=-1e-5,this.playback_speed=this.__get_playback_speed(),this.playing=!0,this.action_events=[],this.context=t,this.initial_context=JSON.parse(JSON.stringify(t)),this.tmp_t=0,this.channels={};const e=Object.keys(t);for(let t=0;t<e.length;t++)this.channels[e[t]]=[];this.duration=0}play(){this.playing=!0}stop(){this.playing=!1}reset(){this.elapsed_time=-1e-5}skip(){const t=this.get_duration();this.__play_clips(this.elapsed_time,t+1e-4),this.elapsed_time=t}update(t){this.playing&&(this.previous_elapsed_time=this.elapsed_time,this.elapsed_time+=t*this.playback_speed,this.__play_clips(this.previous_elapsed_time,this.elapsed_time))}set_progress(t){this.previous_elapsed_time=this.elapsed_time,this.elapsed_time=Ke.clamp(t,0,this.duration),this.__play_clips(this.elapsed_time,this.elapsed_time)}set_normalized_progress(t){this.previous_elapsed_time=this.elapsed_time,this.elapsed_time=Ke.clamp(t,0,1)*this.duration,this.__play_clips(this.elapsed_time,this.elapsed_time)}get_progress(){return Ke.clamp(this.elapsed_time/this.get_duration(),0,1)}is_finished(){return this.elapsed_time>this.get_duration()}add_action_event(t,e){this.action_events.push({trigger_time:t,action:e}),this.duration=Math.max(this.duration,t)}add_action_interpolator(t,e,s,r=!1){if(r){const t=this.channels[s.attribute_name];void 0===t&&console.error(`${s.attribute_name} missing in initial state data.`),0===t.length?s.from=this.initial_context[s.attribute_name]:s.from=t[t.length-1].interpolator.to}const i={from:t,to:e,interpolator:s};this.duration=Math.max(this.duration,e),this.channels[s.attribute_name].push(i)}get_current_target_value(t){const e=this.__get_current_keyframe(t,this.elapsed_time);return this.elapsed_time<e.from?e.interpolator.evaluate(0):e.interpolator.evaluate(1)}get_current_starting_value(t){return this.__get_current_keyframe(t,this.elapsed_time).interpolator.evaluate(0)}get_current_progress(t){const e=this.__get_current_keyframe(t,this.elapsed_time),s=this.__linear_map_01(this.elapsed_time,e.from,e.to);return e.interpolator.easing_function(s)}get_duration(){return this.duration}__play_clips(t,e){this.elapsed_time>this.previous_elapsed_time&&this.__play_events(this.previous_elapsed_time,this.elapsed_time);const s=Object.keys(this.initial_context);for(let e=0;e<s.length;e++){const r=s[e],i=this.__get_current_keyframe(r,t);this.context[r]=this.evaluate_keyframe(i,t)}}__play_events(t,e){for(let s=0;s<this.action_events.length;s++){const r=this.action_events[s].trigger_time;Ke.between(r,t,e)&&this.action_events[s].action.trigger()}}evaluate_keyframe(t,e){return this.tmp_t=this.__linear_map_01(e,t.from,t.to),t.interpolator.evaluate(Ke.clamp(this.tmp_t,0,1))}get_keyframes(t){return this.channels[t]}is_channel_redefined(t){for(let e=0;e<this.channels[t].length;e++){if(this.channels[t][e].interpolator.initial)return!1}return!0}__linear_map_01(t,e,s){return Ke.saturate((t-e)/(s-e)*1+0)}__get_current_keyframe(t,e){let s;const r=this.channels[t];for(let t=0;t<r.length;t++){const i=r[t];if(e>=i.from&&e<=i.to)return s=i,s}let i=1/0;for(let t=0;t<r.length;t++){const n=r[t],o=Math.abs(n.to-e);o<i&&(s=n,i=o)}return s}__get_playback_speed(){const t=new URLSearchParams(window.location.search).get("transitions_velocity");return t?Number(t):1}set_initial_value_on_channel(t,e){this.get_keyframes(t)[0].interpolator.from=e}set_final_value_on_channel(t,e){const s=this.get_keyframes(t);s[s.length-1].interpolator.to=e}}class Ge{constructor(){}static linear(t){return t}static triangular(t){return 1-Math.abs(2*t%2-1)}static ease_in_sine(t){return 1-Math.cos(3.1415926*t/2)}static ease_out_sine(t){return Math.sin(3.1415926*t/2)}static ease_in_out_sine(t){return-(Math.cos(3.1415926*t)-1)/2}static ease_in_cubic(t){return t*t*t}static ease_out_cubic(t){return 1-Math.pow(1-t,3)}static ease_in_out_cubic(t){return t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2}static ease_in_quad(t){return t*t}static ease_out_quad(t){return 1-(1-t)*(1-t)}static ease_in_out_quad(t){return t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2}static ease_in_quart(t){return t*t*t*t}static ease_out_quart(t){return 1-Math.pow(1-t,4)}static ease_in_out_quart(t){return t<.5?8*t*t*t*t:1-Math.pow(-2*t+2,4)/2}static ease_in_quint(t){return t*t*t*t*t}static ease_out_quint(t){return 1-Math.pow(1-t,5)}static ease_in_out_quint(t){return t<.5?16*t*t*t*t*t:1-Math.pow(-2*t+2,5)/2}static ease_in_expo(t){return 0===t?0:Math.pow(2,10*t-10)}static ease_out_expo(t){return 1===t?1:1-Math.pow(2,-10*t)}static ease_in_out_expo(t){return 0===t?0:1===t?1:t<.5?Math.pow(2,20*t-10)/2:(2-Math.pow(2,-20*t+10))/2}static ease_in_circ(t){return 1-Math.sqrt(1-Math.pow(t,2))}static ease_out_circ(t){return Math.sqrt(1-Math.pow(t-1,2))}static ease_in_out_circ(t){return t<.5?(1-Math.sqrt(1-Math.pow(2*t,2)))/2:(Math.sqrt(1-Math.pow(-2*t+2,2))+1)/2}static ease_in_back(t){return 2.7015*t*t*t-1.7015*t*t}static ease_out_back(t){return 1+2.7015*Math.pow(t-1,3)+1.7015*Math.pow(t-1,2)}static ease_in_out_back(t){return t<.5?Math.pow(2*t,2)*(7.189819*t-2.5949095)/2:(Math.pow(2*t-2,2)*(3.5949095*(2*t-2)+2.5949095)+2)/2}static ease_in_elastic(t){const e=2*Math.PI/3;return 0===t?0:1===t?1:-Math.pow(2,10*t-10)*Math.sin((10*t-10.75)*e)}static ease_out_elastic(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(2.094395*(10*t-.75))+1}static ease_in_out_elastic(t){return 0===t?0:1===t?1:t<.5?-Math.pow(2,20*t-10)*Math.sin(1.3962633*(20*t-11.125))/2:Math.pow(2,-20*t+10)*Math.sin(1.3962633*(20*t-11.125))/2+1}static ease_in_bounce(t){return 1-this.ease_out_bounce(1-t)}static ease_out_bounce(t){const e=7.5625,s=2.75;return t<1/s?e*t*t:t<2/s?e*(t-=1.5/s)*t+.75:t<2.5/s?e*(t-=2.25/s)*t+.9375:e*(t-=2.625/s)*t+.984375}static ease_in_out_bounce(t){return t<.5?(1-this.ease_out_bounce(1-2*t))/2:(1+this.ease_out_bounce(2*t-1))/2}static heartbeat(t){return 1-Math.pow(Math.abs(Math.sin(t+1)),63)*Math.sign(Math.sin(t))*Math.sin(t+1.5+1)*.8}}class ts{constructor(t="linear"){this.easing_function=void 0,this.easing_function="string"==typeof t?Ge[t]:t,this.attribute_name="",this.from=0,this.to=1}update(t,e){}}class es extends ts{constructor(t,e=0,s=1,r=!1,i="linear"){super(i),this.attribute_name=t,this.from=e,this.to=s,this.initial=r}update(t,e){t[this.attribute_name]=Ke.lerp(this.from,this.to,this.easing_function(e))}evaluate(t){return Ke.lerp(this.from,this.to,this.easing_function(t))}}class ss{constructor(){}parse(t){const e=(new DOMParser).parseFromString(t,"text/xml").querySelectorAll("mxGeometry"),s=[],r=[];for(let t=0;t<e.length;t++){const i=e[t],n=i.parentElement,o=n.getAttribute("value"),a=this.get_node_x_position(i)/100,h=parseFloat(i.getAttribute("width"))/100;if(n.getAttribute("style").includes("rhombus;")){const t=o.split("."),e=t[0],s=t[1];r.push({name:e,method:s,at_time:a+.5*h})}if(n.getAttribute("style").includes("rounded=0;")&&!n.getAttribute("style").includes("text;")&&""!==o&&!o.includes(" ")){const t=o.split("="),e=t[0],r=t[1].split("--"),i=parseFloat(r[0]),n=r[1];2!==t.length&&console.error("DrawIO data is malformed:",o),2!==r.length&&console.error("DrawIO data is malformed:",o),s.push({attribute_name:e,from_time:a,to_time:a+h,to_value:i,easing_function:n})}}return s.sort(((t,e)=>t.from_time-e.from_time)),{animation_tracks:s,triggers:r}}get_node_x_position(t){const e=t.getAttribute("x");return null===e?0:parseFloat(e)}}class rs{constructor(t){this.default_state_data=t}from_animation_sheet(t,e,s){s=s||this.default_state_data;const r=t.animation_tracks,i=t.triggers,n=this.state_to_tracks(this.default_state_data,this.get_longest_time(t.animation_tracks));for(let t=0;t<n.length;t++)void 0===r.find((e=>e.attribute_name===n[t].attribute_name))&&r.push(n[t]);const o=new Je(e);for(let t=0;t<r.length;t++){const s=r[t],i=new es(s.attribute_name,e[s.attribute_name],s.to_value,s.initial,s.easing_function);o.add_action_interpolator(s.from_time,s.to_time,i,!0)}for(let t=0;t<i.length;t++){const e=i[t],s=new Ze(e.name,e.method,e.args);o.add_action_event(e.at_time,s)}return o}state_to_tracks(t,e){const s=[],r=Object.keys(t);for(let i=0;i<r.length;i++)s.push({attribute_name:r[i],from_time:0,to_time:e<1?e:1,to_value:t[r[i]],initial:!0,easing_function:"ease_in_out_cubic"});return s}from_draw_io(t,e){const s=(new ss).parse(t),r=s.animation_tracks,i=s.triggers,n=new Je(e);for(let t=0;t<r.length;t++){const s=r[t],i=new es(s.attribute_name,e[s.attribute_name],s.to_value,!1,s.easing_function);n.add_action_interpolator(s.from_time,s.to_time,i,!0)}for(let t=0;t<i.length;t++){const e=i[t],s=new Ze(e.name,e.method);n.add_action_event(e.at_time,s)}return n}get_longest_time(t){let e=-1;for(let s=0;s<t.length;s++){const r=t[s].to_time;e=r>e?r:e}return e}}class is{constructor(){this.transitions=[],this.default_state_data={}}get(t,e,s){for(let r=0;r<this.transitions.length;r++)if(this.transitions[r].from===t&&this.transitions[r].to===e){return new rs(this.default_state_data).from_animation_sheet(this.transitions[r].data,s)}for(let t=0;t<this.transitions.length;t++)if(this.transitions[t].to===e&&void 0===this.transitions[t].from){return new rs(this.default_state_data).from_animation_sheet(this.transitions[t].data,s)}console.error("TransitionTable.get no data found for: ",t,e)}add_transitions(t){for(let e=0;e<t.length;e++)this.transitions.push(t[e])}set_transitions(t){this.transitions=t}set_default_state_data(t){this.default_state_data=t}}const ns=new class{constructor(){this.__delta_buffer=[.016,.016,.016,.016,.016,.016,.016,.016,.016,.016]}init(){this.__previous_elapsed_time=-1,this.__delta_time=0,this.__smooth_delta_time=0,this.__elapsed_time=0,this.__frame_interpolation_t=0,this.fixed_delta_time=1/30}get elapsed_time(){return this.__elapsed_time}get delta_time(){return this.__delta_time}get smooth_delta_time(){return this.__smooth_delta_time}get frame_interpolation(){return this.__frame_interpolation_t}get fdt(){return this.fixed_delta_time}get dt(){return this.delta_time}get sdt(){return this.smooth_delta_time}__set_frame_interpolation(t){this.__frame_interpolation_t=t}__update(t){this.__previous_elapsed_time<0&&(this.__previous_elapsed_time=t),this.__delta_time=(t-this.__previous_elapsed_time)/1e3,this.__elapsed_time=t/1e3,this.__delta_buffer.shift(),this.__delta_buffer.push(this.delta_time<.32?this.delta_time:.032),this.__calculate_smooth_delta_time(),this.__previous_elapsed_time=t}__calculate_smooth_delta_time(){this.__smooth_delta_time=0;for(let t=0;t<this.__delta_buffer.length;t++)this.__smooth_delta_time+=this.__delta_buffer[t];this.__smooth_delta_time=this.__smooth_delta_time/this.__delta_buffer.length}};class os{constructor(t){this.name=t}start(){}before_enter(){}on_enter(){}before_exit(){}on_exit(){}before_update(){}update(){}fixed_update(){}update_enter_transition(t,e,s){}update_exit_transition(t,e,s){}}class as{constructor(t){this.last_state=new os("last_initial"),this.current_state=new os("current_initial"),this.default_state_data={},this.current_state_data={},this.transition_table=t,this.transitioning=!1}go_to_state(t,e=!1){this.transitioning&&this.__exit_last_state(),this.last_state=this.current_state,this.current_state=t,this.last_state.before_exit(),this.current_state.before_enter(),this.action_sequencer=this.transition_table.get(this.last_state.name,this.current_state.name,this.current_state_data),this.action_sequencer.play(),this.transitioning=!0,e&&(this.action_sequencer.skip(),this.update())}update(){this.transitioning?(this.__update_transitions(),this.action_sequencer.is_finished()&&(this.transitioning=!1,this.__update_transitions(),this.__exit_last_state(),this.current_state.on_enter())):this.current_state.update()}before_update(){this.current_state.before_update()}fixed_update(){this.current_state.fixed_update()}set_state(t){this.current_state=t}set_default_state_data(t){Object.assign(this.default_state_data,t),Object.assign(this.current_state_data,t)}__update_transitions(){this.action_sequencer.update(ns.delta_time),this.last_state.update_exit_transition(this.current_state_data,this.action_sequencer.get_progress(),this.action_sequencer),this.current_state.update_enter_transition(this.current_state_data,this.action_sequencer.get_progress(),this.action_sequencer)}__exit_last_state(){this.last_state.on_exit()}}const hs=new class{constructor(){this.transition_table=new is,this.transition_handler=new as(this.transition_table)}get action_sequencer(){return this.transition_handler.action_sequencer}get current_state_data(){return this.transition_handler.current_state_data}get_current_state(){return this.transition_handler.current_state}go_to_state(t,e=!1){this.transition_handler.go_to_state(t,e)}before_update(){this.transition_handler.before_update()}update(){this.transition_handler.update()}fixed_update(){this.transition_handler.fixed_update()}add_transitions(t){this.transition_table.add_transitions(t)}set_transitions(t){this.transition_table.set_transitions(t)}set_state(t){this.transition_handler.set_state(t)}set_default_state_data(t){this.transition_table.set_default_state_data(t),this.transition_handler.set_default_state_data(t)}};const _s=new class{constructor(){this.views=[],this.browser_title_suffix=""}update(){this.__set_views_opacities()}go_to_view(t,e=!0,s=!1){const r=this.get(t);e&&(this.__change_browser_url(r.url),this.__change_browser_title(r.url)),hs.go_to_state(r,s)}go_to_scene(t,e=!1,s=!1){const r=this.get(t),i=this.get("transition");i.set_next_view(r),this.go_to_view(i.name,e,s)}register_view(t){this.views.push(t)}has_view(t){for(let e=0;e<this.views.length;e++)if(this.views[e].name===t)return!0;return!1}set_view(t){const e=this.get(t);hs.set_state(e)}set_browser_title_suffix(t){this.browser_title_suffix=t}get_current_view(){return hs.get_current_state()}get_view_by_name(t){console.warn("DEPRECATED. Use ViewManager.get instead"),this.get(t)}get(t){for(let e=0;e<this.views.length;e++)if(this.views[e].name===t)return this.views[e];console.error("[ViewManager.get] no view found for: ",t)}get_by_url(t){for(let e=0;e<this.views.length;e++)if(this.views[e].url===t)return this.views[e];console.error("[ViewManager.get_by_url] no view found for: ",t)}__change_browser_url(t){window.history.pushState("","",t)}__change_browser_title(t){const e=this.__capitalize(t);document.title=e?`${e} | ${this.browser_title_suffix}`:this.browser_title_suffix}__set_views_opacities(){for(let t=0;t<this.views.length;t++)this.views[t].set_opacity(hs.current_state_data)}__capitalize(t){let e=t.toUpperCase().replace("/","");return e=this.__snake_to_whitespace(e),e}__snake_to_whitespace(t){return t.replace(/([-_][A-Z])/g,(t=>t.replace("-"," ").replace("_"," ")))}};class ls extends os{constructor({name:t,url:e,container:s,transition_data:r}){super(t),this.container=s,this.url=e,this.current_opacity=0;const i=[{to:t,data:r=r||{animation_tracks:[],triggers:[]}}];_s.register_view(this),hs.add_transitions(i)}before_enter(){this.container.classList.add("before_enter"),this.container.classList.remove("before_exit"),this.container.classList.remove("hidden")}on_enter(){this.container.classList.remove("before_enter"),this.container.classList.remove("before_exit"),this.container.classList.remove("hidden")}before_exit(){this.container.classList.add("before_exit"),this.container.classList.remove("before_enter"),this.container.classList.remove("hidden")}on_exit(){this.container.classList.add("hidden"),this.container.classList.remove("before_enter"),this.container.classList.remove("before_exit")}set_opacity(t){const e=t[`${this.name}_opacity`];(this.current_opacity>e||this.current_opacity<e)&&(this.current_opacity=e,this.container.style.opacity=String(this.current_opacity))}}class cs{constructor(t){this.uses_dynamic_font=!!t,this.__textHeight=null,this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d")}getFontHeight(t="Arial"){if(null==this.__textHeight||this.uses_dynamic_font){const e=document.getElementsByTagName("body")[0],s=document.createElement("div"),r=document.createTextNode("MÉqgOLAKTAL");s.appendChild(r),s.setAttribute("style",`font:${t};position:absolute;top:0;left:0`),e.appendChild(s),this.__textHeight=s.offsetHeight,e.removeChild(s)}return this.__textHeight}get_text_size(t,s="24px Arial"){const r=new e;return this.ctx.font=s,r.x=Math.ceil(this.ctx.measureText(t).width),r.y=Math.ceil(this.getFontHeight(s)),r}draw_canvas(t,e={}){return e.font=e.font||"24px Arial",e.font_color=e.font_color||"#000000",this.__draw(t,e,this.canvas,this.ctx),this.canvas}draw_on_texture(t,e){const s=this.draw_canvas(t,e),r=new f(s,y,b,b,w,w);return r.generateMipmaps=!1,r.needsUpdate=!0,r}__draw(t,e,s,r){}roundRect(t,e,s,r,i,n,o,a){if(void 0===a&&(a=!0),void 0===n&&(n=5),"number"==typeof n)n={tl:n,tr:n,br:n,bl:n};else{const t={tl:0,tr:0,br:0,bl:0};for(const e in t){const s=e;n[s]=n[s]||t[s]}}t.beginPath(),t.moveTo(e+n.tl,s),t.lineTo(e+r-n.tr,s),t.quadraticCurveTo(e+r,s,e+r,s+n.tr),t.lineTo(e+r,s+i-n.br),t.quadraticCurveTo(e+r,s+i,e+r-n.br,s+i),t.lineTo(e+n.bl,s+i),t.quadraticCurveTo(e,s+i,e,s+i-n.bl),t.lineTo(e,s+n.tl),t.quadraticCurveTo(e,s,e+n.tl,s),t.closePath(),o&&t.fill(),a&&t.stroke()}}class us extends cs{constructor(){super(),this.text_margin=new e(2,0)}__draw(t,e,s,r){r.font=e.font;const i=this.get_text_size(t,e.font);s.width=Math.ceil(i.x+2*this.text_margin.x),s.height=Math.ceil(i.y+2*this.text_margin.y),r.clearRect(0,0,s.width,s.height),r.globalAlpha=0,r.fillStyle=e.font_color||"#000000",r.fillRect(0,0,s.width,s.height),r.globalAlpha=1,r.globalAlpha=1,r.font=e.font,r.fillStyle=e.font_color||"#000000",r.textBaseline="middle",r.textAlign=e.textAlign||"center","center"===r.textAlign?r.fillText(t,s.width/2,s.height/2):r.fillText(t,0,s.height/2)}}const ds=new class{init(){this.max_anisotropy=0,this.vertex_texture_sampler_available=!1}};class ps{get(t,e){return this.describe(this.require_camera(t),e)}set(t,e,s){const r=this.require_camera(t),i=[];null!==e&&this.apply_orbit(e,s,i),this.apply_position(r,e,s,i),this.apply_fov(r,s,i);const n=this.describe(r,e);return n.changed=i,n}frame(t,e,s,r,i){const n=this.require_camera(t);if(null===e)throw this.error("no_controller","The active scene has no camera_controller, so framing is unavailable.");const o="string"==typeof r.uuid?r.uuid:null,a="string"==typeof r.name?r.name:null;if(null===o&&null===a)throw this.error("not_found","Pass a uuid or a name to identify the object to frame.");const h=this.find(s,o,a);if(null===h){const t=null===o?`name '${null===a?"":a}'`:`uuid '${o}'`;throw this.error("not_found",`No object matching ${t} in the current scene.`)}const _="number"==typeof r.scale&&Number.isFinite(r.scale)?r.scale:1;e.focus_on_bounding_box(i(h),_);const l=this.describe(n,e);return l.changed=["framed"],l}apply_orbit(t,e,s){const r=this.number(e.tilt),i=this.number(e.orientation),n=this.number(e.azimuth);null===r&&null===i&&null===n||(null!==r&&s.push("tilt"),null!==i&&s.push("orientation"),null!==n&&s.push("azimuth"),t.set_rotation(null===r?void 0:r,null===i?void 0:i,null===n?void 0:n));const o=this.number(e.zoom);null!==o&&(t.set_normalized_zoom(o),s.push("zoom"));const a=this.triple(e.target);null!==a&&(t.reference_position.x=a[0],t.reference_position.y=a[1],t.reference_position.z=a[2],s.push("target"))}apply_position(t,e,s,r){const i=this.triple(s.position);if(null!==i){if(null!==e)throw this.error("controller_owns_camera","A CameraController is driving this camera and would overwrite a raw position on the next frame. Use tilt, orientation, azimuth, zoom and target instead.");t.position.x=i[0],t.position.y=i[1],t.position.z=i[2],r.push("position")}}apply_fov(t,e,s){const r=this.number(e.fov);null!==r&&(t.fov=r,s.push("fov"),"function"==typeof t.updateProjectionMatrix&&t.updateProjectionMatrix())}describe(t,e){return{position:[this.round(t.position.x),this.round(t.position.y),this.round(t.position.z)],fov:"number"==typeof t.fov?t.fov:null,near:"number"==typeof t.near?t.near:null,far:"number"==typeof t.far?t.far:null,clear_color:this.hex(t.clear_color),clear_alpha:"number"==typeof t.clear_alpha?t.clear_alpha:null,controller:null===e?null:{tilt:e.get_current_tilt(),orientation:e.get_current_orientation(),azimuth:e.get_current_azimuth(),zoom:e.normalized_zoom,min_zoom:e.min_zoom,max_zoom:e.max_zoom,target:[this.round(e.reference_position.x),this.round(e.reference_position.y),this.round(e.reference_position.z)]}}}find(t,e,s){if(null!==e?t.uuid===e:t.name===s)return t;const r=Array.isArray(t.children)?t.children:[];for(const t of r){const r=this.find(t,e,s);if(null!==r)return r}return null}require_camera(t){if("object"!=typeof t||null===t||"object"!=typeof t.position)throw this.error("no_camera","No camera is active. CameraManager.current is not set yet.");return t}hex(t){return"object"!=typeof t||null===t||"function"!=typeof t.getHexString?null:`#${t.getHexString()}`}number(t){return"number"==typeof t&&Number.isFinite(t)?t:null}triple(t){if(!Array.isArray(t))return null;const e=t,s=[];for(let t=0;t<3;t++){const r=this.number(e[t]);if(null===r)return null;s.push(r)}return s}round(t){return"number"==typeof t&&Number.isFinite(t)?Math.round(1e4*t)/1e4:0}error(t,e){const s=new Error(e);return s.code=t,s}}class ms{constructor(t,e,s=()=>document.createElement("canvas")){this.graphics=t,this.has_camera=e,this.create_canvas=s}async capture(t){return"hires"===t.mode?this.capture_hires(t):this.capture_fast(t)}async capture_fast(t){const e=this.graphics.canvas,s=this.scaled_size(e.width,e.height,t.max_size);if(null!==s){const t=this.draw_scaled(e,s.width,s.height);if(null!==t){const r=await this.request_blob((e=>t.toBlob(e,"image/png"))),i=await this.build_result("fast",s.width,s.height,r);return i.scaled_from={width:e.width,height:e.height},i}}const r=await this.request_blob((t=>e.toBlob(t,"image/png")));return this.build_result("fast",e.width,e.height,r)}scaled_size(t,e,s){const r="number"==typeof s?s:1280;if(!Number.isFinite(r)||r<=0)return null;const i=Math.max(t,e);if(i<=r)return null;const n=r/i;return{width:Math.max(1,Math.round(t*n)),height:Math.max(1,Math.round(e*n))}}draw_scaled(t,e,s){const r=this.create_canvas();r.width=e,r.height=s;const i=r.getContext("2d");return null===i?null:(i.drawImage(t,0,0,e,s),r)}async capture_hires(t){if(!this.has_camera())throw this.error("no_camera","A hires capture needs an active camera; CameraManager.current is not set yet.");const e=this.graphics.canvas,s=this.dimension(t.width,e.width),r=this.dimension(t.height,e.height),i=await this.request_blob((t=>this.graphics.take_screenshot(t,s,r)));return this.build_result("hires",s,r,i)}dimension(t,e){return"number"==typeof t?this.clamp(t):this.clamp(e)}clamp(t){return!Number.isFinite(t)||t<1?1:Math.min(Math.floor(t),8192)}request_blob(t){return new Promise(((e,s)=>{t((t=>{null!==t?e(t):s(this.error("capture_failed","The canvas produced no image data."))}))}))}async build_result(t,e,s,r){const i=await r.arrayBuffer(),n=new Uint8Array(i);return{mode:t,mime_type:"image/png",width:e,height:s,bytes:n.length,data:this.to_base64(n)}}to_base64(t){let e="";for(let s=0;s<t.length;s+=8192)e+=String.fromCharCode(...t.subarray(s,s+8192));return btoa(e)}error(t,e){const s=new Error(e);return s.code=t,s}}const gs=2e3,fs=["log","info","warn","error"];class ys{constructor(t=200,e=()=>Date.now()){this.capacity=t>0?Math.floor(t):200,this.entries=[],this.seq=0,this.dropped=0,this.clock=e,this.target=null,this.source=null,this.originals={},this.on_error=null,this.on_rejection=null}install(t,e){this.dispose(),this.target=t;for(const e of fs){const s=t[e];this.originals[e]=s,t[e]=(...r)=>{this.push(e,this.format(r)),s.apply(t,r)}}void 0!==e&&(this.source=e,this.on_error=t=>this.push("error",this.event_message(t)),this.on_rejection=t=>this.push("error",`Unhandled rejection: ${this.event_reason(t)}`),e.addEventListener("error",this.on_error),e.addEventListener("unhandledrejection",this.on_rejection))}dispose(){const t=this.target;if(null!==t)for(const e of fs){const s=this.originals[e];void 0!==s&&(t[e]=s)}const e=this.source;null!==e&&(null!==this.on_error&&e.removeEventListener("error",this.on_error),null!==this.on_rejection&&e.removeEventListener("unhandledrejection",this.on_rejection)),this.originals={},this.target=null,this.source=null,this.on_error=null,this.on_rejection=null}read(t){const e="string"==typeof t.level?t.level:null,s="number"==typeof t.since?t.since:0,r="number"==typeof t.limit&&t.limit>0?Math.floor(t.limit):0;let i=this.entries.filter((t=>t.seq>s));return null!==e&&(i=i.filter((t=>t.level===e))),r>0&&i.length>r&&(i=i.slice(i.length-r)),{entries:i,dropped:this.dropped,total:this.seq,capacity:this.capacity}}push(t,e){for(this.seq++,this.entries.push({seq:this.seq,level:t,message:e,at:this.clock()});this.entries.length>this.capacity;)this.entries.shift(),this.dropped++}format(t){const e=t.map((t=>this.describe(t))).join(" ");if(e.length<=gs)return e;const s=e.length-gs;return`${e.slice(0,gs)} ... [truncated ${s} chars]`}describe(t){if("string"==typeof t)return t;if(null===t)return"null";if(void 0===t)return"undefined";if("number"==typeof t||"boolean"==typeof t)return String(t);if("function"==typeof t)return"[function]";if("symbol"==typeof t)return"[symbol]";if("bigint"==typeof t)return`${t.toString()}n`;if(t instanceof Error)return`${t.name}: ${t.message}`;try{const e=JSON.stringify(t);return void 0===e?"[unserialisable]":e}catch{return"[unserialisable]"}}event_message(t){if("object"==typeof t&&null!==t){const e=t;if("string"==typeof e.message)return e.message;if(void 0!==e.error)return this.describe(e.error)}return this.describe(t)}event_reason(t){if("object"==typeof t&&null!==t){const e=t;if(void 0!==e.reason)return this.describe(e.reason)}return this.describe(t)}}class bs extends ee{constructor(t){super();const s=ut(.5),r=ut(new e(1,1)),i=At("plane_bounds","vec4"),n=St(At("transformsCol0","vec4"),At("transformsCol1","vec4"),At("transformsCol2","vec4"),At("transformsCol3","vec4")),o=dt(pt.xy.mul(i.zw).add(i.xy),pt.z,1);this.vertexNode=Rt.mul(Ct).mul(n).mul(o);const a=jt(At("glyph_bounds","vec4")),h=jt(At("color","vec4")),_=a.x.div(r.x),l=a.y.div(r.x),c=a.z.div(r.y),u=a.w.div(r.y),d=Mt(l.sub(_)),p=Mt(c.sub(u)),m=ct(t,bt(mt().x.mul(d).add(_),mt().y.mul(p).add(c).sub(p)));this.uniforms={_Texture:m,_Boldness:s,_AtlasSize:r};const g=Ft(qt(m.r,m.g),qt(Ft(m.r,m.g),m.b)),f=s.sub(g),y=f.div(Ft(Pt(bt(Nt(f),Ot(f))),1e-6)),b=Lt(vt(.5).sub(y),0,1);this.fragmentNode=dt(h.rgb,b.mul(h.a)),this.transparent=!0,this.depthWrite=!1,this.side=x,this.fog=!1,t.minFilter=v,t.magFilter=v,t.generateMipmaps=!1}set_atlas_size(t){this.uniforms._AtlasSize.value.copy(t)}set_boldness(t){this.uniforms._Boldness.value=Ke.lerp(.5,.2,t)}}class ws{constructor(){}static merge_from_to(t,e){e.push.apply(e,t)}static expand_vec3_array(t,e){const s=e-t.length;for(let e=0;e<s;e++)t.push(t[e].clone())}static remove_elem(t,e){const s=t.indexOf(e);s>-1&&t.splice(s,1)}static get_closest_point(t,e){let s=t[0],r=s.distanceTo(e);for(let i=1;i<t.length;i++)t[i].distanceTo(e)<r&&(s=t[i],r=t[i].distanceTo(e));return s}static object_values_to_array(t){const e=Object.keys(t),s=[];for(let r=0;r<e.length;r++)s.push(t[e[r]]);return s}}class xs{constructor(t,s,r){const i=s.right-s.left,n=s.top-s.bottom;this.scale=new e(i,n),this.position=new e(t+s.left,s.bottom),this.atlas_bounds=new h(r.left,r.right,r.top,r.bottom)}}class vs{constructor(t,s=""){this.glyph_layout=t,this.glyphs=[],this.glyph_is_dirty=!0,this.matrix_is_dirty=!0,this.color_is_dirty=!0,this.position=new l,this.quaternion=new z,this.scale=new l(1,1,1),this.matrix=new M,this.color=new r("#FFFFFF"),this.pivot_point=new e,this.__opacity=1,this.__text=s,this.__generate_glyphs(s)}set text(t){this.__text=t,this.__generate_glyphs(t),this.matrix_is_dirty=!0}get text(){return this.__text}update_matrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrix_is_dirty=!1,this.glyph_is_dirty=!0}clear_glyph_dirty(){this.glyph_is_dirty=!1}clear_color_dirty(){this.color_is_dirty=!1}set_rotation(t=0,e=0){const s=(new z).setFromAxisAngle(new l(0,1,0),t/360*Math.PI*2),r=(new z).setFromAxisAngle(new l(1,0,0),-e/360*Math.PI*2);this.quaternion.copy(s.multiply(r)),this.matrix_is_dirty=!0}set_position(t){this.position.copy(t),this.matrix_is_dirty=!0}set_size(t){this.scale.set(t,t,t),this.matrix_is_dirty=!0}set_color(t){this.color.set(t),this.color_is_dirty=!0}set_pivot(t){this.pivot_point.copy(t),this.update_glyphs()}set opacity(t){this.__opacity=t,this.color_is_dirty=!0}get opacity(){return this.__opacity}update_glyphs(){this.__generate_glyphs(this.text)}__generate_glyphs(t){let s=0;this.glyphs.length=0;for(let e=0;e<t.length;e++){const r=t.charCodeAt(e),i=this.glyph_layout.find((t=>t.unicode===r));if(i){if(i.planeBounds){const t=new xs(s,i.planeBounds,i.atlasBounds);this.glyphs.push(t)}s+=i.advance}}const r=new T,i=this.glyphs[0];r.setFromCenterAndSize(i.position.clone().add(new e(i.scale.x/2,i.scale.y/2)),i.scale);for(let t=1;t<this.glyphs.length;t++){const s=this.glyphs[t],i=(new T).setFromCenterAndSize(s.position.clone().add(new e(s.scale.x/2,s.scale.y/2)),s.scale);r.union(i)}const n=new e;r.getSize(n);for(let t=0;t<this.glyphs.length;t++)this.glyphs[t].position.x-=n.x/2,this.glyphs[t].position.y-=n.y/2,this.glyphs[t].position.x+=n.x/2*this.pivot_point.x,this.glyphs[t].position.y+=n.y/2*this.pivot_point.y;this.glyph_is_dirty=!0}}const zs=["transformsCol0","transformsCol1","transformsCol2","transformsCol3","glyph_bounds","plane_bounds","color"];class Ms extends n{constructor(t,s){const r=new k;r.instanceCount=0;const i=new o(1,1);i.translate(.5,.5,0),r.setAttribute("position",new A(i.getAttribute("position").array,3)),r.setAttribute("uv",new A(i.getAttribute("uv").array,2)),r.index=i.index;const n=new S(new Float32Array(2e3*zs.length*4),4*zs.length);n.setUsage(R),zs.forEach(((t,e)=>{r.setAttribute(t,new C(n,4,4*e))})),super(r,new bs(s)),this.text_elements=[],this.font_layout=t,this.material.set_atlas_size(new e(t.atlas.width,t.atlas.height)),this.frustumCulled=!1}set_boldness(t){this.material.set_boldness(t)}add_text(t){const e=new vs(this.font_layout.glyphs,t);return this.text_elements.push(e),e}remove_text(t){ws.remove_elem(this.text_elements,t),this.update(!0)}update(t){const e=this.geometry.getAttribute("glyph_bounds"),s=this.geometry.getAttribute("plane_bounds"),r=this.geometry.getAttribute("transformsCol0"),i=this.geometry.getAttribute("transformsCol1"),n=this.geometry.getAttribute("transformsCol2"),o=this.geometry.getAttribute("transformsCol3"),a=this.geometry.getAttribute("color");let h=!0===t,_=!0===t,l=!0===t,c=0;for(let t=0;t<this.text_elements.length;t++){const u=this.text_elements[t];u.matrix_is_dirty&&(h=!0,u.update_matrix()),u.glyph_is_dirty&&(_=!0,u.clear_glyph_dirty()),u.color_is_dirty&&(l=!0,u.clear_color_dirty());const d=u.matrix,p=u.color,m=u.opacity;for(let t=0;t<u.glyphs.length;t++){const h=u.glyphs[t],_=c;e.setXYZW(_,h.atlas_bounds.x,h.atlas_bounds.y,h.atlas_bounds.z,h.atlas_bounds.w),s.setXYZW(_,h.position.x,h.position.y,h.scale.x,h.scale.y),r.setXYZW(_,d.elements[0],d.elements[1],d.elements[2],d.elements[3]),i.setXYZW(_,d.elements[4],d.elements[5],d.elements[6],d.elements[7]),n.setXYZW(_,d.elements[8],d.elements[9],d.elements[10],d.elements[11]),o.setXYZW(_,d.elements[12],d.elements[13],d.elements[14],d.elements[15]),a.setXYZW(_,p.r,p.g,p.b,m),c++}}this.geometry.instanceCount=c,c>this.max_allocations&&console.error("SDFTextBatch exceeded maximum glyph allocations(max/current): ",this.max_allocations,c,this),h&&(r.needsUpdate=!0,i.needsUpdate=!0,n.needsUpdate=!0,o.needsUpdate=!0),_&&(e.needsUpdate=!0,s.needsUpdate=!0),l&&(a.needsUpdate=!0)}dispose(){this.geometry.dispose(),this.material.dispose(),super.dispose()}}class Ts extends ee{constructor(t){super();const e=ct(t),s=ut(0),r=ut(new l(1,1,1)),i=ut(1);this.uniforms={_MainTex:e,_ScreenAligned:s,_Scale:r,_Opacity:i};const n=$t.mul(dt(pt,1)).xyz,o=$t.element(3).xyz.add(pt.mul(r));this.vertexNode=Rt.mul(dt(gt(n,o,s),1)),this.fragmentNode=dt(e.rgb,e.a.mul(i)),this.transparent=!0,this.depthWrite=!1,this.side=x,this.fog=!1}}class ks extends n{constructor(t,s){s=s||new e(0,0);const r=new Ts(t),i=new o(1,1,1);i.translate(-s.x/2,-s.y/2,0);const n=t.image.width/t.image.height;i.scale(n,1,1),super(i,r),this.current_scale=n,this.sized_texture=t,this.texture_size=new e(t.image.width,t.image.height),this.geometry.computeBoundingBox(),this.tmp_bb_size=new l,this.geometry.boundingBox.getSize(this.tmp_bb_size),this.material=r}update_texture(){const t=this.material.uniforms._MainTex.value,e=t.image,s=e.width!==this.texture_size.x||e.height!==this.texture_size.y;t===this.sized_texture&&s&&t.dispose(),this.sized_texture=t,this.texture_size.set(e.width,e.height),t.needsUpdate=!0,this.geometry.scale(1/this.current_scale,1,1),this.current_scale=e.width/e.height,this.geometry.scale(this.current_scale,1,1),this.geometry.computeBoundingBox(),this.geometry.boundingBox.getSize(this.tmp_bb_size)}get size(){return this.tmp_bb_size.clone().multiplyScalar(this.scale.x)}set size(t){this.scale.copy(t),this.material.uniforms._Scale.value.copy(t)}set screen_aligned(t){this.material.uniforms._ScreenAligned.value=!0===t?1:0}get screen_aligned(){return 1===this.material.uniforms._ScreenAligned.value}set opacity(t){this.material.uniforms._Opacity.value=t}get opacity(){return this.material.uniforms._Opacity.value}dispose(){this.geometry.dispose(),this.parent.remove(this),this.material.uniforms._MainTex.value.dispose(),this.material.dispose(),super.dispose()}}const As=["cube","sphere","plane","math_sphere","bounding_box","label","sdf_text"];async function Ss(t,e){const s=await fetch(t);if(!s.ok)throw new Error(`HTTP ${s.status}`);const r=(new q).loadAsync(e).catch((()=>{throw new Error(`no atlas image at ${e}`)})),[i,n]=await Promise.all([s.json(),r]);return{layout:i,atlas:n}}class Rs{constructor(t={}){this.helpers=new Map,this.sdf_fonts=new Map,this.sdf_font=t.sdf_font,this.load_sdf_font=t.load_sdf_font??Ss}draw(t,e,s){const r="string"==typeof s.shape&&As.includes(s.shape)?s.shape:null;if(null===r)throw this.error("bad_request",`Unknown shape. Valid shapes: ${As.join(", ")}.`);const i=this.position(s.position),n=this.size(s.size),o=this.color(s.color);return"sdf_text"===r?this.draw_sdf_text(t,this.text(s.text),this.font_url(s.font),i,n,o):this.track(r,this.build(t,e,r,s,i,n,o))}track(t,e){return this.helpers.set(e.uuid,e),{id:e.uuid,shape:t,helpers:this.helpers.size}}async draw_sdf_text(t,e,s,i,n,o){const a=await this.font(s),h=this.sdf_layout(a.layout,s);if(!Array.from({length:e.length},((t,s)=>e.charCodeAt(s))).some((t=>h.glyphs.some((e=>e.unicode===t&&void 0!==e.planeBounds)))))throw this.error("bad_request",`The font at ${s} has none of the characters of the text.`);const _=new Ms(h,a.atlas),l=_.add_text(e);return l.set_position(i),l.set_size(n),l.set_color(new r(o??16777215)),_.update(!0),t.scene.add(_),this.track("sdf_text",_)}font(t){let e=this.sdf_fonts.get(t);return void 0===e&&(e=this.load_sdf_font(t,t.replace(/\.json(?=$|[?#])/,".png")).catch((e=>{this.sdf_fonts.delete(t);const s=e instanceof Error?e.message:"string"==typeof e?e:"unknown error";throw this.error("not_found",`Could not load the SDF font at ${t}: ${s}`)})),this.sdf_fonts.set(t,e)),e}font_url(t){if(void 0===t&&void 0===this.sdf_font)throw this.error("bad_request","sdf_text needs a font: no default SDF font is configured.");const e=t??this.sdf_font;if("string"!=typeof e||!/\.json(?=$|[?#])/.test(e))throw this.error("bad_request","font must be the URL of an msdf-atlas-gen .json layout, with its .png atlas next to it.");return e}sdf_layout(t,e){const s=t;if("number"!=typeof s?.atlas?.width||"number"!=typeof s.atlas.height||!Array.isArray(s.glyphs))throw this.error("bad_request",`The font at ${e} is not an msdf-atlas-gen layout.`);if("top"===s.atlas.yOrigin)throw this.error("bad_request",`The font at ${e} has yOrigin top. Generate it with -yorigin bottom.`);return s}build(t,e,s,r,i,n,o){switch(s){case"cube":return t.draw_cube(i,n,o);case"sphere":return t.draw_sphere(i,n,o);case"plane":{const e=t.draw_plane(n,n,o);return e.position.copy(i),e}case"math_sphere":return t.draw_math_sphere(new j(i,n),o);case"label":return t.draw_label(this.text(r.text),i,n,o);default:return t.draw_bounding_box(this.bounds(e,r.object),o)}}clear(t){if(void 0===t.id){const t=this.helpers.size;return this.helpers.forEach((t=>this.dispose(t))),this.helpers.clear(),{removed:t,helpers:0}}const e="string"==typeof t.id?this.helpers.get(t.id):void 0;if(void 0===e)throw this.error("not_found","No helper with that id was drawn through debug_draw.");return this.dispose(e),this.helpers.delete(e.uuid),{removed:1,helpers:this.helpers.size}}dispose(t){t.removeFromParent(),t.traverse((t=>{const e=t;e.geometry?.dispose();(Array.isArray(e.material)?e.material:e.material?[e.material]:[]).forEach((t=>t.dispose())),t instanceof ks&&t.material.uniforms._MainTex.value.dispose()}))}bounds(t,e){const{name:s,uuid:r}="object"==typeof e&&null!==e?e:{};if("string"!=typeof r&&"string"!=typeof s)throw this.error("bad_request","bounding_box needs an object with a name or a uuid.");const i="string"==typeof r?t.getObjectByProperty("uuid",r):t.getObjectByName(s);if(void 0===i){const t="string"==typeof r?`uuid ${r}`:`name ${s}`;throw this.error("not_found",`No object matching ${t} in the current scene.`)}const n=(new F).setFromObject(i);if(n.isEmpty())throw this.error("bad_request",`Object "${i.name||i.uuid}" has no geometry, so its bounds are empty.`);return n}text(t){if("string"!=typeof t||0===t.length||t.length>200)throw this.error("bad_request","label and sdf_text need a text of 1 to 200 characters.");return t}position(t){if(void 0===t)return new l;if(!Array.isArray(t)||3!==t.length||!t.every((t=>"number"==typeof t&&Number.isFinite(t))))throw this.error("bad_request","position must be [x, y, z] with finite numbers.");return new l(t[0],t[1],t[2])}size(t){if(void 0===t)return 1;if("number"!=typeof t||!Number.isFinite(t)||t<=0)throw this.error("bad_request","size must be a positive finite number.");return t}color(t){if(void 0===t||"number"==typeof t||"string"==typeof t)return t;throw this.error("bad_request","color must be a number or a string.")}error(t,e){const s=new Error(e);return s.code=t,s}}const Cs={left:0,middle:1,right:2};class js{constructor(t,e,s){this.dispatch=t,this.sleep=e,this.to_client=s}async pointer(t){const e=this.text(t.action,"click"),s=this.space(t.space),r=this.point(t.x,t.y,s),i=this.button(t.button),n=Math.min(1e4,this.positive(t.hold_ms,60)),o=[];if("move"!==e&&"down"!==e&&"click"!==e||(this.send("mousemove",{clientX:r.x,clientY:r.y}),o.push("mousemove")),"down"!==e&&"click"!==e||(this.send("mousedown",{clientX:r.x,clientY:r.y,button:i}),o.push("mousedown")),"click"===e&&await this.sleep(n),"up"!==e&&"click"!==e||(this.send("mouseup",{clientX:r.x,clientY:r.y,button:i}),o.push("mouseup")),0===o.length)throw this.error("bad_request",`Unknown pointer action '${e}'. Use click, down, up or move.`);return{dispatched:o,at:[r.x,r.y]}}async drag(t){const e=this.space(t.space),s=this.pair(t.from,e,"from"),r=this.pair(t.to,e,"to"),i=Math.min(120,Math.max(1,Math.floor(this.positive(t.steps,8)))),n=Math.min(1e4,this.positive(t.duration_ms,240)),o=this.button(t.button),a=[];this.send("mousemove",{clientX:s.x,clientY:s.y}),a.push("mousemove"),this.send("mousedown",{clientX:s.x,clientY:s.y,button:o}),a.push("mousedown");for(let t=1;t<=i;t++){const e=t/i;await this.sleep(n/i),this.send("mousemove",{clientX:s.x+(r.x-s.x)*e,clientY:s.y+(r.y-s.y)*e}),a.push("mousemove")}return this.send("mouseup",{clientX:r.x,clientY:r.y,button:o}),a.push("mouseup"),{dispatched:a,from:[s.x,s.y],to:[r.x,r.y]}}scroll(t){const e=this.number(t.delta);if(null===e)throw this.error("bad_request","scroll requires a numeric delta.");const s=this.space(t.space),r=this.point(void 0===t.x?0:t.x,void 0===t.y?0:t.y,s);return this.send("wheel",{clientX:r.x,clientY:r.y,deltaY:e}),Promise.resolve({dispatched:["wheel"],at:[r.x,r.y],delta:e})}async key(t){const e="string"==typeof t.code&&t.code.length>0?t.code:null;if(null===e)throw this.error("bad_request","key requires a code, for example 'Space' or 'KeyW'.");const s=this.text(t.action,"press"),r=Math.min(1e4,this.positive(t.hold_ms,60)),i=[];if("down"!==s&&"press"!==s||(this.send("keydown",{code:e,key:e}),i.push("keydown")),"press"===s&&await this.sleep(r),"up"!==s&&"press"!==s||(this.send("keyup",{code:e,key:e}),i.push("keyup")),0===i.length)throw this.error("bad_request",`Unknown key action '${s}'. Use press, down or up.`);return{dispatched:i,code:e}}send(t,e){this.dispatch(t,{...e,bubbles:!0,cancelable:!0})}point(t,e,s){const r=this.number(t),i=this.number(e);if(null===r||null===i)throw this.error("bad_request","x and y must be numbers.");return this.to_client(r,i,s)}pair(t,e,s){if(!Array.isArray(t)||t.length<2)throw this.error("bad_request",`${s} must be [x, y].`);const r=t;return this.point(r[0],r[1],e)}space(t){return"ndc"===t?"ndc":"pixels"}button(t){if("string"!=typeof t)return 0;const e=Cs[t.toLowerCase()];return void 0===e?0:e}text(t,e){return"string"==typeof t&&t.length>0?t.toLowerCase():e}number(t){return"number"==typeof t&&Number.isFinite(t)?t:null}positive(t,e){const s=this.number(t);return null===s||s<=0?e:s}error(t,e){const s=new Error(e);return s.code=t,s}}class Fs{read(t,e,s){const r={fps:this.rate(t.delta_time),smooth_fps:this.rate(t.smooth_delta_time),frame_ms:this.round(1e3*this.seconds(t.delta_time),100),elapsed_s:this.round(this.seconds(t.elapsed_time),10),canvas:{width:e.width,height:e.height,render_width:e.render_width,render_height:e.render_height,dpr:e.dpr}},i=this.section(s,"render"),n=this.section(s,"memory");return this.assign(r,"draw_calls",i,"drawCalls"),this.assign(r,"triangles",i,"triangles"),this.assign(r,"geometries",n,"geometries"),this.assign(r,"textures",n,"textures"),r}section(t,e){if("object"!=typeof t||null===t)return null;const s=t[e];return"object"!=typeof s||null===s?null:s}assign(t,e,s,r){if(null===s)return;const i=s[r];"number"==typeof i&&Number.isFinite(i)&&(t[e]=i)}rate(t){const e=this.seconds(t);return e<=0?0:this.round(1/e,10)}seconds(t){return"number"==typeof t&&Number.isFinite(t)&&t>0?t:0}round(t,e){return Math.round(t*e)/e}}class qs{constructor(t){this.descriptors=t}list(){return this.descriptors.map((t=>({name:t.name,description:void 0===t.description?"":t.description,options:void 0===t.options?[]:t.options})))}create(t,e){const s="string"==typeof t?t.toLowerCase():null,r=null===s?void 0:this.descriptors.find((t=>t.name.toLowerCase()===s));if(void 0===r){const t=this.descriptors.map((t=>t.name)).join(", ");throw this.error("unknown_render_mode",`Unknown render mode. Available modes: ${t}.`)}return r.factory(e)}error(t,e){const s=new Error(e);return s.code=t,s}}class Ps{get(t,e){const s=this.require(t,e);return this.describe(s.node,s.parent)}set(t,e,s){const r=this.require(t,e),i=[];this.apply_vector(r.node.position,s.position)&&i.push("position"),this.apply_vector(r.node.rotation,s.rotation)&&i.push("rotation"),this.apply_vector(r.node.scale,s.scale)&&i.push("scale"),"boolean"==typeof s.visible&&(r.node.visible=s.visible,i.push("visible"));const n=this.describe(r.node,r.parent);return n.changed=i,n}require(t,e){if("object"!=typeof t||null===t)throw this.error("not_found","No scene is set. SceneManager.current is empty.");const s="string"==typeof e.uuid?e.uuid:null,r="string"==typeof e.name?e.name:null;if(null===s&&null===r)throw this.error("not_found","Pass a uuid or a name to identify the object.");const i=this.find(t,null,s,r);if(null===i){const t=null===s?`name '${null===r?"":r}'`:`uuid '${s}'`;throw this.error("not_found",`No object matching ${t} in the current scene.`)}return i}find(t,e,s,r){if(null!==s?t.uuid===s:t.name===r)return{node:t,parent:e};const i=Array.isArray(t.children)?t.children:[];for(const e of i){const i=this.find(e,t,s,r);if(null!==i)return i}return null}apply_vector(t,e){if("object"!=typeof t||null===t||!Array.isArray(e))return!1;const s=["x","y","z"],r=e;let i=!1;for(let e=0;e<s.length;e++){const n=r[e];"number"==typeof n&&Number.isFinite(n)&&(t[s[e]]=n,i=!0)}return i}describe(t,e){const s={uuid:"string"==typeof t.uuid?t.uuid:"(no uuid)",name:"string"==typeof t.name?t.name:"",type:"string"==typeof t.type?t.type:"Object3D",parent:this.parent_label(e),children:Array.isArray(t.children)?t.children.length:0,visible:!1!==t.visible,position:this.vector(t.position,0),rotation:this.vector(t.rotation,0),scale:this.vector(t.scale,1)},r=this.material_type(t.material);null!==r&&(s.material=r);const i=this.vertices(t.geometry);return null!==i&&(s.vertices=i),s}parent_label(t){return null===t?null:"string"==typeof t.name&&t.name.length>0?t.name:"string"==typeof t.uuid?t.uuid:null}material_type(t){if(Array.isArray(t))return`${t.length} materials`;if("object"==typeof t&&null!==t){const e=t.type;return"string"==typeof e?e:"Material"}return null}vertices(t){if("object"!=typeof t||null===t)return null;const e=t.attributes;if("object"!=typeof e||null===e)return null;const s=e.position;if("object"!=typeof s||null===s)return null;const r=s.count;return"number"==typeof r?r:null}vector(t,e){return"object"!=typeof t||null===t?[e,e,e]:[this.round(t.x,e),this.round(t.y,e),this.round(t.z,e)]}round(t,e){return"number"==typeof t&&Number.isFinite(t)?Math.round(1e4*t)/1e4:e}error(t,e){const s=new Error(e);return s.code=t,s}}class Ns{inspect(t,e){if("object"!=typeof t||null===t)return{root:null,counts:{total:0,meshes:0,returned:0},truncated:!1,notes:["No scene is set. SceneManager.current is empty."]};const s=this.positive(e.depth,4),r=this.positive(e.max_nodes,200),i="string"==typeof e.filter&&e.filter.length>0?e.filter.toLowerCase():null,n=[],o=this.count(t);let a=null;null!==i&&(a=new Set,this.mark(t,i,a),0===a.size&&(n.push(`no nodes matched the filter '${i}'`),a=new Set([t])));const h={used:0,depth_cut:!1,node_cut:!1},_=this.serialise(t,0,s,r,a,h);return h.node_cut&&n.push(`stopped at max_nodes=${r}; ${o.total-h.used} of ${o.total} nodes not returned`),h.depth_cut&&n.push(`stopped at depth=${s}; deeper nodes not returned`),{root:_,counts:{total:o.total,meshes:o.meshes,returned:h.used},truncated:h.node_cut||h.depth_cut,notes:n}}serialise(t,e,s,r,i,n){if(null!==i&&!i.has(t))return null;if(n.used>=r)return n.node_cut=!0,null;n.used++;const o={uuid:"string"==typeof t.uuid?t.uuid:"(no uuid)",name:"string"==typeof t.name?t.name:"",type:"string"==typeof t.type?t.type:"Object3D",position:this.vector(t.position,0)},a=this.vector(t.rotation,0),h=this.vector(t.scale,1);this.is_uniform(a,0)||(o.rotation=a),this.is_uniform(h,1)||(o.scale=h),!1===t.visible&&(o.visible=!1);const _=this.describe_material(t.material);null!==_&&(o.material=_);const l=this.count_vertices(t.geometry);null!==l&&(o.vertices=l);const c=Array.isArray(t.children)?t.children:[];if(0===c.length)return o;if(e+1>s)return n.depth_cut=!0,o.truncated=`${c.length} children hidden (depth limit ${s})`,o;const u=[];let d=0;for(const t of c){const o=this.serialise(t,e+1,s,r,i,n);null!==o?u.push(o):d++}return u.length>0&&(o.children=u),d>0&&null===i&&(o.truncated=`${d} children hidden (max_nodes ${r})`),o}count(t){let e=0,s=0;const r=[t];for(;r.length>0;){const t=r.pop();if("object"!=typeof t||null===t)continue;e++,"Mesh"===t.type&&s++;const i=Array.isArray(t.children)?t.children:[];for(const t of i)r.push(t)}return{total:e,meshes:s}}mark(t,e,s){const r="string"==typeof t.name?t.name.toLowerCase():"",i="string"==typeof t.type?t.type.toLowerCase():"";let n=r.includes(e)||i.includes(e);const o=Array.isArray(t.children)?t.children:[];for(const t of o)this.mark(t,e,s)&&(n=!0);return n&&s.add(t),n}describe_material(t){if(Array.isArray(t)){const e=t.map((t=>this.material_type(t)));return`${t.length} materials: ${e.join(", ")}`}return"object"==typeof t&&null!==t?this.material_type(t):null}material_type(t){if("object"==typeof t&&null!==t){const e=t.type;if("string"==typeof e)return e}return"Material"}count_vertices(t){if("object"!=typeof t||null===t)return null;const e=t.attributes;if("object"!=typeof e||null===e)return null;const s=e.position;if("object"!=typeof s||null===s)return null;const r=s.count;return"number"==typeof r?r:null}vector(t,e){return"object"!=typeof t||null===t?[e,e,e]:[this.round(t.x,e),this.round(t.y,e),this.round(t.z,e)]}round(t,e){return"number"==typeof t&&Number.isFinite(t)?Math.round(1e4*t)/1e4:e}is_uniform(t,e){return t.every((t=>t===e))}positive(t,e){return"number"!=typeof t||!Number.isFinite(t)||t<1?e:Math.floor(t)}}class Os{list(t){const e=this.current(t);return{current:e,views:this.names(t).map((t=>({name:t.name,url:t.url,current:t.name===e})))}}go(t,e){const s="string"==typeof e.name?e.name:null,r=this.names(t);if(null===s||!r.some((t=>t.name===s))){const t=r.map((t=>t.name)).join(", ");throw this.error("not_found",`Unknown view. Available views: ${t}.`)}const i=void 0===e.change_url||!0===e.change_url,n=!0===e.skip;return t.go_to_view(s,i,n),{requested:s,current:this.current(t),change_url:i,skip:n}}names(t){return(Array.isArray(t.views)?t.views:[]).filter((t=>"string"==typeof t.name)).map((t=>({name:t.name,url:"string"==typeof t.url?t.url:""})))}current(t){const e=t.get_current_view();return"object"!=typeof e||null===e||"string"!=typeof e.name?null:e.name}error(t,e){const s=new Error(e);return s.code=t,s}}class Ls extends P{constructor(t=1){super();const e=[];e.push(new l(0,0,0)),e.push(new l(0,0,1e3));const s=new N({color:4474111,depthFunc:O}),r=(new L).setFromPoints(e),i=new $(r,s);i.renderOrder=5e4;const n=[];n.push(new l(0,0,0)),n.push(new l(0,1e3,0));const o=new N({color:4521796,depthFunc:O}),a=(new L).setFromPoints(n),h=new $(a,o);h.renderOrder=5e4;const _=[];_.push(new l(0,0,0)),_.push(new l(1e3,0,0));const c=new N({color:16729156,depthFunc:O}),u=(new L).setFromPoints(_),d=new $(u,c);d.renderOrder=5e4,this.renderOrder=1e5,this.add(i),this.add(h),this.add(d),this.scale.set(t,t,t)}update(){}dispose(){super.dispose()}}class $s extends ks{constructor(t,e,s,r){const i=new us,n={font:e,font_color:s||"#000000"},o=i.draw_on_texture(t,n);o.minFilter=U,o.minFilter=v,o.colorSpace=p,o.needsUpdate=!0,super(o,r),this.simple_text_drawer=i,this.canvas_texture=o,this.draw_settings=n}set text(t){this.simple_text_drawer.draw_canvas(t,this.draw_settings),this.update_texture()}get text(){return"not implemented"}}class Us extends ce{constructor(){super();const t=ut(new e),s=ut(new e),r=ut(new e);this.uniforms._ScreenSpacePosition=t,this.uniforms._ScreenSize=s,this.uniforms._TextureSize=r;const i=mt().mul(r).add(t).div(s);this.vertexNode=dt(i.mul(2).sub(1),0,1)}set_position(t,e){this.uniforms._ScreenSpacePosition.value.set(t,e)}set_texture(t,e,s){this.uniforms._MainTex.value=t,this.uniforms._TextureSize.value.set(t.image.width,t.image.height),void 0!==e&&(this.uniforms._TextureSize.value.x=e),void 0!==s&&(this.uniforms._TextureSize.value.y=s)}set_screen_size(t,e){this.uniforms._ScreenSize.value.set(t,e)}}class Bs extends B{constructor(t,e,s,i){super(t,e,s,i),this.clear_color=new r("#000000"),this.clear_alpha=1}copy(t){return super.copy(t),this.clear_color.copy(t.clear_color),this.clear_alpha=t.clear_alpha,this}}class Es extends n{constructor(t,e,s){t=t||"#FF0000";const r=(e=e||1)-.4,i=new E(.01,.01,r,32);i.translate(0,r/2,0);const n=new I(.1,.4,32);n.translate(0,r+.2,0);const o=oe.mergeGeometries([i,n]);o.rotateX(1.57);super(o,new D({color:t})),s&&this.quaternion.setFromUnitVectors(new l(0,0,1),s),this._dir=s}set dir(t){this.quaternion.setFromUnitVectors(new l(0,0,1),t),this._dir=t}get dir(){return this._dir}set length(t){this.scale.z=t}get length(){return this.scale.z}}class Is extends n{constructor(t,e,s){t=t||new l(1,1,1),e=e||new l(1,1,1),s=s??16711680;super(new Q(t.x,t.y,t.z,e.x,e.y,e.z),new D({color:s}))}}class Ds extends n{constructor(t,e){e=e??"#FF0000";super(new V(t=t||1,64,64),new D({color:e})),this.radius=t,this.color=e,this.center=this.position}}function Qs(t){return new se({color:t,opacity:.2,transparent:!0,depthWrite:!1})}const Vs=new class{init(){this.Vector3_one=new l(1,1,1),this.Vector3_zero=new l(0,0,0),this.canvas_renderer=void 0,this.display_texture_meshes=[],this.ctx=void 0,this.scene=new i,this.camera=new Bs(60,ye.aspect_ratio,.1,1e3),this.camera.clear_alpha=0}draw_arrow(t,e,s=16711680){const r=new Es(s,e.length(),e.clone().normalize());return r.position.copy(t),this.scene.add(r),r}draw_axis(){const t=new Ls;return this.scene.add(t),t}set_debug_RT(t){this.rt_debug=t}draw_rectangle(t,e,s,r){e=e||100,s=s||100,this.ctx.fillStyle=r||"rgba(255, 0, 0, 1)",this.ctx.fillRect(t.x-e/2,this.ctx.canvas.height-t.y-s/2,e,s)}clear(){this.ctx&&this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}draw_line_2D(t,e,s){this.ctx.strokeStyle=s||"rgba(255, 0, 0, 1)",this.ctx.beginPath(),this.ctx.moveTo(t.x,t.y),this.ctx.lineTo(e.x,e.y),this.ctx.closePath(),this.ctx.stroke()}draw_line(t,e=16711680){const s=new N({color:e}),r=(new L).setFromPoints(t),i=new $(r,s);return i.frustumCulled=!1,this.scene.add(i),i}draw_cube(t,e,s){e=e||1,s=s??16711680,t=t||new l;const r=new Is(new l(e,e,e),void 0,s);return r.position.copy(t),this.scene.add(r),r}draw_oriented_cube(t,e,s=1,r="#FF0000",i=.1){const n=t.distanceTo(e),o=new Is(new l(i,s,n),void 0,r),a=e.clone().sub(t).multiplyScalar(.5),h=a.clone().normalize();return a.add(t),o.position.copy(a),o.quaternion.setFromUnitVectors(new l(0,0,-1),h),this.scene.add(o),o}draw_plane(t,e,s=65280){const r=new o(t,e),i=Qs(s),a=new n(r,i);return a.renderOrder=-1e4,this.scene.add(a),a}draw_empty_cube(t,e,s){e=e||1,s=s??16711680;const r=(new F).setFromCenterAndSize(new l,new l(e,e,e)),i=new Y(r,s);return i.position.copy(t||new l),i}draw_sphere(t,e,s){e=e||1,s=s??16711680,t=t||new l;const r=new Ds(e,s);return r.position.copy(t),this.scene.add(r),r}draw_point_array(t,e=!1,s=16711680){const r=new W(t,e);r.updateArcLengths();const i=r.getSpacedPoints(200);return this.draw_line(i,65280)}draw_sphere_helper(t,e){e=e??16711680;const s=new V(t.radius,32,32),r=new D({color:e}),i=new n(s,r);return i.position.copy(t.center),be.current.add(i),i}draw_math_sphere(t,e=16711680){const s=new V(t.radius,32,32),r=Qs(e),i=new n(s,r);return i.position.copy(t.center),be.current.add(i),i}draw_bounding_box(t,e=16776960){const s=new Y(t,e);return be.current.add(s),s}draw_curve(t,e){const s=new l(0,0,0);e&&(s.y=e.offset||0);for(let e=0;e<t.length-1;e++)this.draw_line([t[e].clone().add(s),t[e+1].clone().add(s)])}draw_texture(t,e,s){const r=new n(new o(1,1),new Us);return r.frustumCulled=!1,this.display_texture_meshes.push(r),this.scene.add(r),r.material.set_texture(t,e,s),r}draw_label(t,s,i=1,n=16777215){const o=new $s(t,"bold 48px Arial",new r(n).getStyle(),new e);return o.size=new l(i,i,i),o.screen_aligned=!0,o.position.copy(s||new l),this.scene.add(o),o}render(t){for(let t=0;t<this.display_texture_meshes.length;t++)this.display_texture_meshes[t].material.set_screen_size(ye.width,ye.height);this.scene.children.length>0&&t.render(this.scene,fe.current)}};class Ys{constructor(t){this.reply=t,this.handlers={},this.queue=[]}register(t,e,s){this.handlers[t]={timing:e,handler:s}}handle(t){const e=this.handlers[t.cmd],s=void 0===t.args?{}:t.args;void 0!==e?"frame_end"!==e.timing?this.run(t.id,s,e.handler):this.queue.push({id:t.id,args:s,handler:e.handler}):this.reply({id:t.id,ok:!1,error:{code:"unknown_command",message:`Unknown command '${t.cmd}'`}})}drain(){const t=this.queue;this.queue=[];for(const e of t)this.run(e.id,e.args,e.handler)}run(t,e,s){try{Promise.resolve(s(e)).then((e=>this.reply({id:t,ok:!0,result:e}))).catch((e=>this.reply({id:t,ok:!1,error:this.to_error(e)})))}catch(e){this.reply({id:t,ok:!1,error:this.to_error(e)})}}to_error(t){const e=t?.code,s=t?.message;return{code:void 0===e?"handler_failed":e,message:"string"==typeof s?s:this.describe(t)}}describe(t){return"string"==typeof t?t:"Handler failed with a non-Error value of type "+typeof t}}class Ws{constructor(){this.socket=null,this.options=null,this.retry_timer=0,this.disposed=!1,this.dispatcher=new Ys((t=>this.send_reply(t)))}init(t){this.options=t,this.disposed=!1,this.connect()}register(t,e,s){this.dispatcher.register(t,e,s)}on_frame_end(){this.dispatcher.drain()}dispose(){this.disposed=!0,window.clearTimeout(this.retry_timer),null!==this.socket&&(this.socket.onclose=null,this.socket.close(),this.socket=null)}connect(){const t=this.options;if(this.disposed||null===t)return;const e=new WebSocket(`ws://127.0.0.1:${t.port}`);this.socket=e,e.onopen=()=>{e.send(JSON.stringify({event:"hello",protocol:1,app:t.app_info()}))},e.onmessage=t=>this.on_message(t),e.onclose=()=>{this.socket===e&&(this.socket=null),this.schedule_retry()},e.onerror=()=>{}}on_message(t){const e=t.data;if("string"!=typeof e)return;const s=this.parse_frame(e);if(null!==s)if("welcome"!==s.event)if("refused"!==s.event)"string"==typeof s.id&&"string"==typeof s.cmd&&this.dispatcher.handle(s);else{const t=this.as_text(s.reason),e=this.as_text(s.server_protocol);console.warn(`[ohzi-mcp] bridge refused: ${t} (server protocol ${e}, this app speaks 1)`)}else console.info("[ohzi-mcp] bridge connected")}parse_frame(t){try{const e=JSON.parse(t);return"object"!=typeof e||null===e?null:e}catch{return null}}as_text(t){return"string"==typeof t?t:"number"==typeof t||"boolean"==typeof t?String(t):"(unknown)"}send_reply(t){null!==this.socket&&this.socket.readyState===WebSocket.OPEN&&this.socket.send(JSON.stringify(t))}schedule_retry(){this.disposed||(window.clearTimeout(this.retry_timer),this.retry_timer=window.setTimeout((()=>this.connect()),2e3))}}class Xs{constructor(){}get is_animating(){return!1}on_enter(t){}update(t){}on_exit(t){}}class Hs{constructor(){this.t=0,this.easing_function_t=0}get is_animating(){return!0}on_enter(t){}update(t){this.t+=ns.delta_time/t.duration,this.easing_function_t=t.easing_function(this.t),this.easing_function_t=Ke.clamp(this.easing_function_t,0,1),t.set_property_value(Ke.lerp(t.from,t.to,this.easing_function_t)),this.easing_function_t>=.9999&&(t.set_property_value(t.to),t.set_current_state(new Xs),t.finished_callback(t))}on_exit(t){}}class Zs{constructor({element:t,css_property:e,from:s=0,to:r=1,duration:i=1,value_prefix:n="",value_suffix:o="",easing_function:a=Ge.ease_in_out_cubic,finished_callback:h=()=>{}}){this.element=t,this.css_property=e,this.from=s,this.to=r,this.value_prefix=n,this.value_suffix=o,this.duration=i,this.easing_function=a,this.finished_callback=h,this.current_state=new Xs}animate(){this.set_current_state(new Hs)}stop(){this.set_current_state(new Xs)}set_property_value(t){this.element.style[this.css_property]=`${this.value_prefix}${t}${this.value_suffix}`}update(){this.current_state.update(this)}get is_animating(){return this.current_state.is_animating}set_current_state(t){this.current_state.on_exit(this),this.current_state=t,this.current_state.on_enter(this)}}const Ks=new class{init(){this.operating_systems={ANDROID:"android",IOS:"ios",LINUX:"linux",MAC:"mac",WINDOWS:"windows"},this.is_mobile=!!navigator.userAgent.match(/(iPhone|iPod|iPad|Android|playbook|silk|BlackBerry|BB10|Windows Phone|Tizen|Bada|webOS|IEMobile|Opera Mini)/),this.is_ipad=!!(navigator.userAgent.match(/Mac/)&&navigator.maxTouchPoints&&navigator.maxTouchPoints>2),this.is_ios=!!navigator.userAgent.match(/(iPhone|iPod|iPad)/)||this.is_ipad,this.is_android=this.get_os()===this.operating_systems.ANDROID,this.is_linux=this.get_os()===this.operating_systems.LINUX,this.is_mac=this.get_os()===this.operating_systems.MAC,this.is_windows=this.get_os()===this.operating_systems.WINDOWS}get_os(){const t=window.navigator.userAgent,e=window.navigator.platform;let s=null;return-1!==["Macintosh","MacIntel","MacPPC","Mac68K"].indexOf(e)?s=this.operating_systems.MAC:-1!==["iPhone","iPad","iPod"].indexOf(e)?s=this.operating_systems.IOS:-1!==["Win32","Win64","Windows","WinCE"].indexOf(e)?s=this.operating_systems.WINDOWS:/Android/.test(t)?s=this.operating_systems.ANDROID:!s&&/Linux/.test(e)&&(s=this.operating_systems.LINUX),s}};const Js=new class{init(){this.target_geometry=void 0,this.target_position=new l}set_target_geometry(t){this.target_geometry=t}};class Gs{constructor(){}fit_points(t,e,s,r){const i=this.get_view_bounds(t,e),n=this.get_distance_to_fit_rect(i.size.x/2,i.size.y/2,s,r);return{center:i.center,distance_to_center:n}}get_view_bounds(t,e){const s=e.clone().invert(),r=[];for(let e=0;e<t.length;e++)r.push(t[e].clone().applyQuaternion(s));const i=(new F).setFromPoints(r),n=new l;i.getSize(n);const o=1e-9*Math.max(n.x,n.y,n.z);n.set(n.x>o?n.x:0,n.y>o?n.y:0,n.z>o?n.z:0);const a=new l;return i.getCenter(a),a.applyQuaternion(e),{center:a,size:n}}get_zoom_to_fit_size(t,e,s,r=1){const i=Math.min(Math.abs((t.right-t.left)/e),Math.abs((t.top-t.bottom)/s));return Number.isFinite(i)?i*r:t.zoom}get_distance_to_fit_depth(t,e,s){const r=e+t.near,i=t.far-e;let n=Math.max(s,r);return n>i&&(n=Math.max(r,i)),n}get_distance_to_fit_rect(t,e,s,r){const i=s/2*Math.PI/180,n=2*Math.atan(Math.tan(i)*r)/2,o=e/Math.tan(i),a=t/Math.tan(n);return Math.max(Math.abs(a),Math.abs(o))}}class tr{constructor(){this.sphere=new j}fit_points(t,e,s,r){this.sphere.setFromPoints(t);const i=Ke.degToRad(s/2),n=2*Math.atan(Math.tan(i)*r)/2,o=this.get_up_plane_normal(e,i),a=this.get_down_plane_normal(e,i),h=this.get_left_plane_normal(e,n),_=this.get_right_plane_normal(e,n),c=new l(0,0,-1).applyQuaternion(e),u=this.sphere.center.clone(),d=this.get_distance_to_fit_rect(2*this.sphere.radius,2*this.sphere.radius,s,r),p=u.clone().add(c.clone().multiplyScalar(-1*d)),m=(new X).setFromNormalAndCoplanarPoint(o,p),g=(new X).setFromNormalAndCoplanarPoint(a,p),f=(new X).setFromNormalAndCoplanarPoint(h,p),y=(new X).setFromNormalAndCoplanarPoint(_,p);this.apply_center_correction_to_pos(p,t,e,m,g,f,y),m.setFromNormalAndCoplanarPoint(o,p),g.setFromNormalAndCoplanarPoint(a,p),f.setFromNormalAndCoplanarPoint(h,p),y.setFromNormalAndCoplanarPoint(_,p);let b=1/0;const w=c.clone().multiplyScalar(-2*d);for(let e=0;e<t.length;e++){const s=new H(t[e].clone(),t[e].clone().add(w)),r=new l,i=new l,n=new l,o=new l;m.intersectLine(s,r),g.intersectLine(s,i),f.intersectLine(s,n),y.intersectLine(s,o),r.length()<1e-4&&console.log("up intersection not found",e),i.length()<1e-4&&console.log("down intersection not found",e),n.length()<1e-4&&console.log("left intersection not found",e),o.length()<1e-4&&console.log("right intersection not found",e);const a=t[e].clone().sub(r).length(),h=t[e].clone().sub(i).length(),_=t[e].clone().sub(n).length(),c=t[e].clone().sub(o).length(),u=Math.min(a,h),d=Math.min(_,c),p=Math.min(u,d);p<b&&(b=p)}const x=c.clone().multiplyScalar(b);return p.clone().add(x)}apply_center_correction_to_pos(t,e,s,r,i,n,o){const a=this.get_vertical_correction(e,i,r,s),h=this.get_horizontal_correction(e,n,o,s);t.add(a),t.add(h)}get_vertical_correction(t,e,s,r){let i=1/0,n=1/0;const o=new l(0,1,0).applyQuaternion(r);for(let r=0;r<t.length;r++){const a=new H(t[r].clone(),t[r].clone().add(o.clone().multiplyScalar(-5e6))),h=new H(t[r].clone(),t[r].clone().add(o.clone().multiplyScalar(5e6))),_=new l,c=new l;e.intersectLine(a,_),s.intersectLine(h,c);const u=_.distanceTo(t[r]),d=c.distanceTo(t[r]);c.length()<1e-4&&console.log("vertical up intersection not found",r),_.length()<1e-4&&console.log("vertical down intersection not found",r),u<n&&(n=u),d<i&&(i=d)}const a=(i-n)/2;return o.clone().multiplyScalar(-a)}get_horizontal_correction(t,e,s,r){let i=1/0,n=1/0;const o=new l(1,0,0).applyQuaternion(r);for(let r=0;r<t.length;r++){const a=new H(t[r].clone(),t[r].clone().add(o.clone().multiplyScalar(-5e6))),h=new H(t[r].clone(),t[r].clone().add(o.clone().multiplyScalar(5e6))),_=new l,c=new l;e.intersectLine(a,_),s.intersectLine(h,c);const u=_.distanceTo(t[r]),d=c.distanceTo(t[r]);_.length()<1e-4&&console.log("left intersection not found",r),c.length()<1e-4&&console.log("right intersection not found",r),u<n&&(n=u),d<i&&(i=d)}const a=(i-n)/2;return o.clone().multiplyScalar(-a)}get_up_plane_normal(t,e){const s=new l(0,-1,0);return s.applyQuaternion((new z).setFromAxisAngle(new l(1,0,0),e)),s.applyQuaternion(t),s}get_down_plane_normal(t,e){const s=new l(0,1,0);return s.applyQuaternion((new z).setFromAxisAngle(new l(1,0,0),-e)),s.applyQuaternion(t),s}get_left_plane_normal(t,e){const s=new l(1,0,0);return s.applyQuaternion((new z).setFromAxisAngle(new l(0,1,0),e)),s.applyQuaternion(t),s}get_right_plane_normal(t,e){const s=new l(-1,0,0);return s.applyQuaternion((new z).setFromAxisAngle(new l(0,1,0),-e)),s.applyQuaternion(t),s}get_distance_to_fit_rect(t,e,s,r){const i=s/2*Math.PI/180,n=2*Math.atan(Math.tan(i)*r)/2,o=e/Math.tan(i),a=t/Math.tan(n);return Math.max(Math.abs(a),Math.abs(o))}}const er=new class{init(t){this.tmp_mat=new M,this.plane=new X,this.ray=new Z,this.tmp_size=new l,this.tmp_unproj=new l,this.input=t}get_up_dir(t){t=t||fe.current;const e=new l;return e.set(0,1,0),e.applyQuaternion(t.quaternion),e}get_forward_dir(t){t=t||fe.current;const e=new l;return e.set(0,0,-1),e.applyQuaternion(t.quaternion),e}get_right_dir(t){t=t||fe.current;const e=new l;return e.set(1,0,0),e.applyQuaternion(t.quaternion),e}unproject_mouse_position(t,e){e=e||fe.current;const s=new l,r=e.fov/2*Math.PI/180,i=2*Math.atan(Math.tan(r)*e.aspect)/2,n=Math.tan(r)*e.far,o=Math.tan(i)*e.far;return s.set(o*t.x,n*t.y,-e.far).normalize(),s.applyQuaternion(e.quaternion)}get_plane_intersection(t,e,s,r){r=r||fe.current,s=s||this.input.NDC;const i=new l;if(this.plane.setFromNormalAndCoplanarPoint(e||this.get_forward_dir(r),t),r.isPerspectiveCamera)this.ray.set(r.position,this.unproject_mouse_position(s,r));else{const t=r,e=(t.right+t.left)/2,i=(t.top+t.bottom)/2,n=(t.right-t.left)/(2*t.zoom),o=(t.top-t.bottom)/(2*t.zoom),a=new l(e+s.x*n,i+s.y*o,0);a.applyQuaternion(r.quaternion),a.add(r.position);const h=new l(0,0,-1).applyQuaternion(r.quaternion);this.ray.set(a,h)}return this.ray.intersectPlane(this.plane,i),i}fit_points_on_camera(t,e=1){const s=(new Gs).get_view_bounds(t,fe.current.quaternion),r=s.size.clone().multiplyScalar(e);return{position:s.center,zoom:this.get_zoom_to_fit_rect(r.x/2,r.y/2)}}get_zoom_to_fit_rect(t,e){const s=fe.current;if(s.isOrthographicCamera)return(new Gs).get_zoom_to_fit_size(s,2*t,2*e);const r=s,i=r.fov/2*Math.PI/180,n=2*Math.atan(Math.tan(i)*r.aspect)/2,o=e/Math.tan(i),a=t/Math.tan(n);return Math.max(Math.abs(a),Math.abs(o))}get_zoom_to_fit_box(t,e){return e=e||fe.current,t.isEmpty()?e.isOrthographicCamera?e.zoom:0:this.fit_bounding_box_points(e,t).zoom}get_html_screen_pos(t,e){e=e||fe.current;const s=new l;return t.getWorldPosition(s),s.project(e),s.x=(.5*s.x+.5)*ye.width,s.y=(1-(.5*s.y+.5))*ye.height,s}world_pos_to_screen(t,e){e=e||fe.current;const s=new l;return s.copy(t),s.project(e),s.x=(.5*s.x+.5)*ye.width,s.y=(1-(.5*s.y+.5))*ye.height,s}update_projection(t){const e=t;e.left=-ye.width/2,e.right=ye.width/2,e.top=ye.height/2,e.bottom=-ye.height/2,e.aspect=ye.aspect_ratio,e.updateProjectionMatrix()}fit_bounding_box_points(t,e,s=1){const r=new l;r.copy(e.max).sub(e.min);const i=e.min.clone(),n=i.clone().add(new l(r.x,0,0)),o=i.clone().add(new l(0,r.y,0)),a=i.clone().add(new l(0,0,r.z)),h=i.clone().add(new l(r.x,0,r.z)),_=i.clone().add(new l(0,r.y,r.z)),c=e.max.clone(),u=i.clone().add(new l(r.x,r.y,0));return this.fit_points(t,[i,n,o,a,h,_,c,u],s)}fit_points(t,e,s=1){const r=t;if(r.isPerspectiveCamera){const i=new l(0,0,-1).applyQuaternion(t.quaternion),n=i.clone().multiplyScalar(-1),o=(new tr).fit_points(e,t.quaternion,r.fov*s,r.aspect),a=(new F).setFromPoints(e),h=new l;a.getCenter(h);const _=(new X).setFromNormalAndCoplanarPoint(n,h),c=new Z(o,i),u=new l;c.intersectPlane(_,u);return{zoom:o.distanceTo(u),reference_position:u,camera_position:o}}{const r=t,i=new Gs,n=i.get_view_bounds(e,t.quaternion),o=new l(0,0,1).applyQuaternion(t.quaternion),a=t.position.clone().sub(n.center).dot(o),h=i.get_distance_to_fit_depth(r,n.size.z/2,a);return{zoom:i.get_zoom_to_fit_size(r,n.size.x,n.size.y,s),reference_position:n.center,camera_position:n.center.clone().addScaledVector(o,h)}}}};const sr=new class{constructor(){}init(t){fe.init(),er.init(t),ds.init(),Ks.init(),$e.init(),Js.init(),Fe.init(),be.init(new He({name:"default_scene",compilators:{}})),ye.init(),ns.init(),Vs.init()}dispose(t){Re.dispose(),be.dispose(),t.dispose()}};class rr{constructor(){this.on_key_down=t=>{90===t.keyCode&&t.ctrlKey&&!this.ctrlz_fired&&(this.ctrlz_pressed=!0,this.ctrlz_fired=!0),t.code&&this.press_key(t.code)},this.on_key_up=t=>{this.release_key(t.code)}}init(t){this.ctrlz_pressed=!1,this.ctrlz_fired=!1,this.keys={},this.keys_keys=[],this.container=t,this.container.addEventListener("keydown",this.on_key_down,!1),this.container.addEventListener("keyup",this.on_key_up,!1)}clear(){this.ctrlz_pressed=!1;for(let t=0;t<this.keys_keys.length;t++)this.keys[this.keys_keys[t]].pressed=!1,this.keys[this.keys_keys[t]].released=!1}release_key(t){const e=this.keys[t];e&&(e.fired=!1,e.down=!1,e.released=!0)}release_keys(){this.ctrlz_fired=!1;for(let t=0;t<this.keys_keys.length;t++)this.keys[this.keys_keys[t]].fired=!1,this.keys[this.keys_keys[t]].down=!1}press_key(t){const e=this.keys[t];e&&(!1===e.down&&(e.pressed=!0),e.down=!0,e.fired=!0)}is_key_pressed(t){const e=this.keys[t];return!!e&&e.pressed}is_key_down(t){const e=this.keys[t];return!!e&&e.down}is_key_released(t){const e=this.keys[t];return!!e&&e.released}register_key(t){this.keys[t]={key_name:t,pressed:!1,down:!1,fired:!1,released:!1},this.keys_keys=Object.keys(this.keys)}unregister_key(t){delete this.keys[t]}dispose(){this.container.removeEventListener("keydown",this.on_key_down,!1),this.container.removeEventListener("keyup",this.on_key_up,!1)}}class ir extends a{constructor(t,e,s,i,n,o){super(t,e,s,i,n,o),this.clear_color=new r("#000000"),this.clear_alpha=1}copy(t){return super.copy(t),this.clear_color.copy(t.clear_color),this.clear_alpha=t.clear_alpha,this}}class nr extends ce{constructor(e=!1){super();const s=ct(new t),r=ut(1);this.uniforms._BlurredTex=s,this.uniforms._BloomStrength=r;const i=this.sample(s);e?(this.fragmentNode=i,this.blending=K,this.blendSrc=J,this.blendDst=J):this.fragmentNode=this.sample_main_tex().add(i.mul(r))}}const or=[[-4,.0525],[-3,.075],[-2,.11],[-1,.15],[0,.225],[1,.15],[2,.11],[3,.075],[4,.0525]];class ar extends ce{constructor(){super();const t=ut(new e);this.uniforms._SampleDir=t;const s=this.uniforms._Resolution,r=t.mul(bt(.5).div(s)),i=or.map((([t,e])=>(0===t?this.sample_main_tex():this.sample_main_tex(r.mul(2*t))).mul(e)));this.fragmentNode=i.reduce(((t,e)=>t.add(e)))}}class hr{constructor(){this.RT1=new _(1,1),this.RT2=new _(1,1),this.box_blur_mat=new ar}blur(t){t.width===this.RT1.width&&t.height===this.RT1.height||(this.RT1.setSize(t.width,t.height),this.RT2.setSize(t.width,t.height)),this.box_blur_mat.uniforms._SampleDir.value.set(1,0),Re.blit(t,this.RT1,this.box_blur_mat),this.box_blur_mat.uniforms._SampleDir.value.set(0,1),Re.blit(this.RT1,t,this.box_blur_mat)}dispose(){this.RT1.dispose(),this.RT2.dispose(),this.box_blur_mat.dispose()}}const _r=[[0,0,4],[-1,-1,1],[1,1,1],[1,-1,1],[-1,1,1]],lr=[[-2,0,1],[-1,1,2],[0,2,1],[1,1,2],[2,0,1],[1,-1,2],[0,-2,1],[-1,-1,2]];class cr extends ce{constructor(t){super();const e=bt(.5).div(this.uniforms._Resolution),s=t?lr:_r,r=s.map((([t,s,r])=>this.sample_main_tex(e.mul(bt(t,s))).mul(r))),i=s.reduce(((t,[,,e])=>t+e),0);this.fragmentNode=r.reduce(((t,e)=>t.add(e))).div(i)}}class ur{constructor(){this.current_width=1,this.current_height=1,this.RT0=new _(1,1),this.RT1=new _(1,1),this.RT2=new _(1,1),this.RT3=new _(1,1),this.RT4=new _(1,1),this.upscale_blur_mat=new cr(!0),this.downscale_blur_mat=new cr(!1)}blur(t){this.check_RT_resize(t.width,t.height),Re.blit(t,this.RT1),Re.blit(this.RT1,this.RT2,this.downscale_blur_mat),Re.blit(this.RT2,this.RT3,this.downscale_blur_mat),Re.blit(this.RT3,this.RT4,this.downscale_blur_mat),Re.blit(this.RT4,this.RT3,this.upscale_blur_mat),Re.blit(this.RT3,this.RT2,this.upscale_blur_mat),Re.blit(this.RT2,t,this.upscale_blur_mat)}check_RT_resize(t,e){this.current_width===t&&this.current_height===e||(this.current_width=t,this.current_height=e,this.resize(this.RT1,2),this.resize(this.RT2,4),this.resize(this.RT3,8),this.resize(this.RT4,16))}dispose(){this.RT0.dispose(),this.RT1.dispose(),this.RT2.dispose(),this.RT3.dispose(),this.RT4.dispose(),this.upscale_blur_mat.dispose(),this.downscale_blur_mat.dispose()}resize(t,e){t.setSize(Math.max(1,Math.floor(this.current_width/e)),Math.max(1,Math.floor(this.current_height/e)))}}class dr extends me{constructor(t=!1){super(),this.use_dual_filtering=t,this.bloom_compose_mat=new nr,window.bloom_mat=this.bloom_compose_mat,this.main_RT=void 0,this.blur_RT=void 0,this.blurrer=void 0}on_enter(){this.blurrer=this.use_dual_filtering?new ur:new hr,this.main_RT=new _(ye.width,ye.height),this.blur_RT=new _(ye.width,ye.height)}on_exit(){this.blurrer.dispose(),this.main_RT.dispose(),this.blur_RT.dispose()}render(){this.__check_RT_size(),Re.clear(this.main_RT,fe.current,!0,!1),Re.render(be.current,fe.current,this.main_RT),Re.blit(this.main_RT,this.blur_RT),this.blurrer.blur(this.blur_RT),this.bloom_compose_mat.uniforms._BlurredTex.value=this.blur_RT.texture,Re.blit(this.main_RT,void 0,this.bloom_compose_mat)}__check_RT_size(){this.main_RT.width===ye.width&&this.main_RT.height===ye.height||(this.main_RT.setSize(ye.width,ye.height),this.blur_RT.setSize(ye.width,ye.height))}}class pr extends ee{constructor(){super(),this.colorNode=dt(Ut(dt(Bt(Et),1),p))}}class mr extends me{constructor(){super(),this.normal_material=new pr}render(){Re.clear(void 0,fe.current,!0,!0),Re.render(be.current,fe.current,void 0,this.normal_material)}}class gr extends ee{constructor(e=1){super();const s=ut(e),r=ct(new t),i=ct(new t),n=ut(new M);this.uniforms={_Intensity:s,_AlbedoTex:r,_NormalDepthTex:i,_InverseProjMatrix:n};const o=bt(It.x.mul(2).sub(1),It.y.mul(-2).add(1)),a=n.mul(dt(o,1,1)),h=i.sample(It),_=a.xyz.div(a.w).mul(ze(h.xy)),l=zt(Te(h.zw)),c=r.sample(It).rgb,u=Dt.sub(_),d=Qt(wt(l,zt(u))),p=s.div(wt(u,u));this.colorNode=dt(c.mul(d).mul(p),1),this.blending=G,this.depthWrite=!1,this.side=tt}set_inverse_proj_matrix(t){this.uniforms._InverseProjMatrix.value.copy(t)}set_normal_depth_rt(t){this.uniforms._NormalDepthTex.value=t.texture}set_albedo_rt(t){this.uniforms._AlbedoTex.value=t.texture}}class fr extends me{constructor(){super(),this.main_rt=new _(ye.width,ye.height),this.scene_lights=new He({name:"lights_scene",compilators:{}});const t=Math.sqrt(204.8)/2,e=new n(new V(t),new gr(1));for(let t=0;t<2;t++)for(let s=0;s<2;s++){const r=e.clone();r.position.set(2*t-1,1,2*s-1),this.scene_lights.add(r)}this.camera_inverse_proj_mat=new M}on_enter(){Re.generate_depth_normal_texture=!0}render(){this.__check_RT_size(),Re.clear(this.main_rt,fe.current,!0,!1),Re.render(be.current,fe.current,this.main_rt),this.camera_inverse_proj_mat.copy(fe.current.projectionMatrix).invert();const t=this.camera_inverse_proj_mat,e=this.main_rt,s=Re.depth_normals_RT;this.scene_lights.traverse((r=>{r.material&&(r.material.set_inverse_proj_matrix(t),r.material.set_normal_depth_rt(s),r.material.set_albedo_rt(e))})),Re.clear(void 0,fe.current,!0,!0),Re.render(this.scene_lights,fe.current)}__check_RT_size(){this.main_rt.width===ye.width&&this.main_rt.height===ye.height||this.main_rt.setSize(ye.width,ye.height)}}class yr extends ce{constructor(){super();const e=ct(new t);this.uniforms._AO=e;const s=this.sample(e).r;this.fragmentNode=dt(this.sample_main_tex().rgb.mul(s.oneMinus()),1)}}class br extends ce{constructor(t=!0){super(),this.sample_kernel=this.__get_sample_kernel(),this.use_exact_depth=t;const e=ut(new M),s=ut(new M),r=ut(.0125),i=ut(.3),n=Vt(this.sample_kernel,"vec3"),o=ct(this.__get_rotation_texture());Object.assign(this.uniforms,{_InverseProjMatrix:e,_ProjectionMatrix:s,_Bias:r,_Radius:i,_SampleKernel:n,_RandomRotation:o});const a=this.uniforms._MainTex,h=this.uniforms._Resolution,_=t?t=>{const e=t.mul(h).sub(.5),s=Zt(e),r=e.sub(s),i=h.sub(1),n=(t,e)=>{const r=Lt(s.add(bt(t,e)),bt(0),i);return ze(a.load(Kt(r)).xy)};return gt(gt(n(0,0),n(1,0),r.x),gt(n(0,1),n(1,1),r.x),r.y)}:t=>ze(a.sample(t).xy),l=t=>{const s=e.mul(dt(t.mul(2).sub(1),1,1)),r=_(this.texture_uv_at(a,t));return s.xyz.div(s.w).mul(r)};this.fragmentNode=ft((()=>{const t=l(mt()).toVar(),e=zt(Te(this.sample_main_tex().zw)).toVar(),a=o.sample(mt().mul(h.div(4))).xy.mul(2).sub(1),_=zt(xt(a,0)),c=zt(_.sub(e.mul(wt(_,e)))).toVar(),u=zt(Yt(e,c)).toVar(),d=vt(0).toVar();return Wt(64,(({i:o})=>{const a=xt(n.element(o)),h=t.add(c.mul(a.x).add(u.mul(a.y)).add(e.mul(a.z)).mul(i)),_=s.mul(dt(h,1)),p=_.xy.div(_.w).mul(.5).add(.5),m=l(p).z,g=Xt(0,1,i.div(Mt(t.z.sub(m))));d.addAssign(Ht(h.z.add(r),m).mul(g))})),dt(xt(d.div(64)),1)}))()}set_projection_matrix(t){this.uniforms._ProjectionMatrix.value.copy(t),this.uniforms._InverseProjMatrix.value.copy(t).invert()}__get_sample_kernel(){const t=[];for(let e=0;e<64;e++){const s=new l(2*Math.random()-1,2*Math.random()-1,Math.random());s.normalize();let r=e/64;r=Ke.lerp(.1,1,r*r),s.multiplyScalar(r),t.push(s)}return t}__get_rotation_texture(){const t=new Uint8Array(64);for(let e=0;e<16;e++)t[4*e+0]=Math.floor(255*Math.random()),t[4*e+1]=Math.floor(255*Math.random()),t[4*e+2]=0,t[4*e+3]=255;const e=new et(t,4,4,st);return e.wrapS=rt,e.wrapT=rt,e.needsUpdate=!0,e}}class wr extends me{constructor(t=!1,e=!0){super(),this.ssao_mat=new br(e),this.ssao_compose_mat=new yr,this.ssaa=t?2:1,this.main_RT=new _(ye.width*this.ssaa,ye.height*this.ssaa),this.SSAO_RT=new _(ye.width,ye.height),this.blurrer=new hr}on_enter(){Re.generate_depth_normal_texture=!0}render(){this.__check_RT_size(),Re.clear(this.main_RT,fe.current,!0,!1),Re.render(be.current,fe.current,this.main_RT),this.ssao_mat.set_projection_matrix(fe.current.projectionMatrix),Re.blit(Re.depth_normals_RT,this.SSAO_RT,this.ssao_mat),this.blurrer.blur(this.SSAO_RT),this.ssao_compose_mat.uniforms._AO.value=this.SSAO_RT.texture,Re.blit(this.main_RT,void 0,this.ssao_compose_mat)}__check_RT_size(){this.main_RT.width===ye.width*this.ssaa&&this.main_RT.height===ye.height*this.ssaa||(this.main_RT.setSize(ye.width*this.ssaa,ye.height*this.ssaa),this.SSAO_RT.setSize(ye.width,ye.height))}}class xr extends me{constructor(){super()}render(){Re.clear(void 0,fe.current,!0,!0),be.current.on_pre_render(),be.current.render(),be.current.on_post_render()}}function vr(t,e){return.39894*Math.exp(-.5*t*t/(e*e))/e}class zr extends ce{constructor(t){super();const s=ut(new e(.5,.5)),r=ut(new e(.5,.5)),i=ut(1);this.uniforms.texSize=s,this.uniforms.direction=r,this.uniforms.radius=i;const n=t,o=r.mul(bt(1).div(s)).mul(i);let a=vr(0,n),h=this.sample_main_tex().mul(a);for(let e=1;e<t;e++){const t=vr(e,n),s=o.mul(e),r=this.sample_main_tex(s).add(this.sample_main_tex(s.negate()));h=h.add(r.mul(t)),a+=2*t}this.fragmentNode=h.div(a)}set_size(t,e){this.uniforms.texSize.value.set(t,e)}set_direction(t,e){this.uniforms.direction.value.set(t,e)}set_radius(t=1){this.uniforms.radius.value=t}}const Mr=xt(.299,.587,.114);class Tr extends ce{constructor(){super();const t=ut(.23),e=ut(.01),s=ut(new r("#000000")),i=ut(0);this.uniforms.luminosityThreshold=t,this.uniforms.smoothWidth=e,this.uniforms.defaultColor=s,this.uniforms.defaultOpacity=i;const n=this.sample_main_tex(),o=wt(n.rgb,Mr),a=Xt(t,t.add(e),o);this.fragmentNode=gt(dt(s,i),n,a)}set_threshold(t){this.uniforms.luminosityThreshold.value=t}}class kr{constructor(t=!1){this.current_width=1,this.current_height=1,this.separableBlurMaterials=[],this.renderTargetsHorizontal=[],this.renderTargetsVertical=[],this.use_half_float=t,this.nMips=5,this.kernelSizeArray=[3,5,7,9,11],this.rt_pars={minFilter:v,magFilter:v,format:st,type:t?it:nt,colorSpace:t?ot:p},this.renderTargetBright=new _(1,1,this.rt_pars),this.renderTargetBright.texture.generateMipmaps=!1,this.init_materials(),this.init_RT(),this.luminosity_high_pass_mat=new Tr}blur(t,e){this.resize_RT(t.width,t.height);let s=t;e&&(Re.blit(t,this.renderTargetBright,this.luminosity_high_pass_mat),s=this.renderTargetBright);for(let t=0;t<this.nMips;t++){const e=this.separableBlurMaterials[t];e.set_direction(1,0),Re.blit(s,this.renderTargetsHorizontal[t],e),e.set_direction(0,1),Re.blit(this.renderTargetsHorizontal[t],this.renderTargetsVertical[t],e),s=this.renderTargetsVertical[t]}}get_blurred_texture(){return this.renderTargetsHorizontal[0].texture}get_blurred_RT(){return this.renderTargetsHorizontal[0]}init_RT(){this.dispose_RT(),this.renderTargetBright.setSize(1,1);for(let t=0;t<this.nMips;t++){const t=new _(1,1,this.rt_pars),e=new _(1,1,this.rt_pars);t.texture.generateMipmaps=!1,e.texture.generateMipmaps=!1,t.texture.colorSpace=this.rt_pars.colorSpace,e.texture.colorSpace=this.rt_pars.colorSpace,this.renderTargetsHorizontal.push(t),this.renderTargetsVertical.push(e)}}resize_RT(t,e){if(this.current_width===t&&this.current_height===e)return;this.current_width=t,this.current_height=e;let s=Math.round(t/2),r=Math.round(e/2);this.renderTargetBright.setSize(s,r);for(let t=0;t<this.nMips;t++)this.renderTargetsVertical[t].setSize(s,r),this.renderTargetsHorizontal[t].setSize(s,r),this.separableBlurMaterials[t].set_size(s,r),s=Math.round(s/2),r=Math.round(r/2)}init_materials(){this.dispose_materials();for(let t=0;t<this.nMips;t++)this.separableBlurMaterials.push(new zr(this.kernelSizeArray[t]))}set_radius(t){for(let e=0;e<this.separableBlurMaterials.length;e++)this.separableBlurMaterials[e].set_radius(t)}set_luminosity_threshold(t){this.luminosity_high_pass_mat.set_threshold(t)}dispose_materials(){for(let t=0;t<this.separableBlurMaterials.length;t++)this.separableBlurMaterials[t].dispose();this.separableBlurMaterials.length=0}dispose_RT(){for(let t=0;t<this.renderTargetsVertical.length;t++)this.renderTargetsHorizontal[t].dispose(),this.renderTargetsVertical[t].dispose();this.renderTargetBright.dispose(),this.renderTargetsHorizontal.length=0,this.renderTargetsVertical.length=0}}class Ar extends me{constructor(t,e,s,r=!1){super(),this.add_mat=new ue(e);const i={samples:t?4:1,type:e?it:nt,format:st,colorSpace:ot,minFilter:w,magFilter:w};this.use_rendering_size=r,this.main_RT=new _(1,1,i),this.main_RT.texture.colorSpace=ot,this.main_RT.texture.minFilter=w,this.main_RT.texture.magFilter=w,this.bloom_compose_mat=new pe(5,e),this.blurrer=new kr(e),this.use_hight_luminosity_pass=s,this.luminosity_threshold=.5}on_enter(){this.bloom_compose_mat.set_blur_texture_0(this.blurrer.renderTargetsVertical[0].texture),this.bloom_compose_mat.set_blur_texture_1(this.blurrer.renderTargetsVertical[1].texture),this.bloom_compose_mat.set_blur_texture_2(this.blurrer.renderTargetsVertical[2].texture),this.bloom_compose_mat.set_blur_texture_3(this.blurrer.renderTargetsVertical[3].texture),this.bloom_compose_mat.set_blur_texture_4(this.blurrer.renderTargetsVertical[4].texture),this.add_mat.set_add_texture(this.blurrer.renderTargetsHorizontal[0].texture)}render(){this.__check_RT_size(),Re.clear(this.main_RT,fe.current,!0,!1),Re.render(be.current,fe.current,this.main_RT),this.blurrer.blur(this.main_RT,this.use_hight_luminosity_pass),Re.material_pass(this.bloom_compose_mat,this.blurrer.renderTargetsHorizontal[0]),Re.blit(this.main_RT,void 0,this.add_mat)}set_bloom_strength(t){this.bloom_compose_mat.set_bloom_strength(t)}set_bloom_radius(t){this.blurrer.set_radius(t)}set_luminosity_threshold(t){this.blurrer.set_luminosity_threshold(t)}set_tint_color_0(t){this.bloom_compose_mat.set_tint_color_0(t)}set_tint_color_1(t){this.bloom_compose_mat.set_tint_color_1(t)}set_tint_color_2(t){this.bloom_compose_mat.set_tint_color_2(t)}set_tint_color_3(t){this.bloom_compose_mat.set_tint_color_3(t)}set_tint_color_4(t){this.bloom_compose_mat.set_tint_color_4(t)}__check_RT_size(){const t=this.use_rendering_size?ye.render_width:ye.width,e=this.use_rendering_size?ye.render_height:ye.height;this.main_RT.width===t&&this.main_RT.height===e||this.main_RT.setSize(t,e)}}class Sr extends me{constructor(){super()}render(){be.current.on_pre_render&&be.current.on_pre_render(),be.current.render?be.current.render():Re.render(be.current,fe.current,Re._renderer.getRenderTarget()),this.render_spectator_camera(),be.current.on_post_render&&be.current.on_post_render()}render_spectator_camera(){const t=fe.spectator;if(t&&Re._renderer.xr.isPresenting){const e=Re._renderer.xr,s=e.getCamera();t.projectionMatrix.copy(fe.current.projectionMatrix),t.position.copy(s.position),t.quaternion.copy(s.quaternion);const r=Re._renderer.getRenderTarget();e.isPresenting=!1,Re._renderer.setRenderTarget(null),Re._renderer.render(be.current,t),Re._renderer.setRenderTarget(r),e.isPresenting=!0}}}const Rr=new class{constructor(){this.components=[],this.enabled_components=new Set}update(){this.__set_components_opacities();for(const t of this.enabled_components)t.update(hs.current_state_data)}register_component(t){this.components.push(t)}enable_component(t){this.enabled_components.add(t)}disable_component(t){this.enabled_components.delete(t)}get_component_by_name(t){console.warn("DEPRECATED. Use ViewComponentManager.get instead"),this.get(t)}get(t){for(let e=0;e<this.components.length;e++)if(this.components[e].name===t)return this.components[e];console.error("[ViewComponentManager.get] no component found for: ",t)}__set_components_opacities(){for(let t=0;t<this.components.length;t++)this.components[t].set_opacity(hs.current_state_data)}};class Cr{constructor(t,e,s){t=t||new le,this.target_application=t,this.graphics=e,this.input=s,this.is_running=!1,this.frames_passed=0,this.time_accumulator=0}update(t){if(this.is_running){for(ns.__update(t),1===this.frames_passed&&this.target_application.on_post_start(),this.input.update(),this.time_accumulator+=ns.delta_time,this.target_application.before_update(),hs.before_update();this.time_accumulator>ns.fixed_delta_time;)this.target_application.fixed_update(),hs.fixed_update(),this.time_accumulator-=ns.fixed_delta_time;ns.__set_frame_interpolation(this.time_accumulator/ns.fixed_delta_time),this.target_application.update(),hs.update(),_s.update(),Rr.update(),this.target_application.on_pre_render(),this.graphics.update(),this.target_application.on_post_render(),Vs.render(this.graphics),this.target_application.on_frame_end(),this.frames_passed++,this.input.clear(),Vs.clear()}}start(){this.is_running||(0===this.frames_passed&&this.target_application.on_enter(this),this.is_running=!0,this.graphics._renderer.setAnimationLoop(this.update.bind(this)))}stop(){!1!==this.is_running&&(this.is_running=!1,this.target_application.on_exit(this),this.graphics._renderer.setAnimationLoop(null))}set_state(t){this.target_application.on_exit(this),this.target_application=t,this.target_application.on_enter(this)}dispose(){this.stop(),this.frames_passed=0}}const jr=new class{init(){console.warn("Screen Singleton is deprecated. Please use OScreen."),ye.init()}update_position(t,e){console.warn("Screen Singleton is deprecated. Please use OScreen."),ye.update_position(t,e)}update(){console.warn("Screen Singleton is deprecated. Please use OScreen."),ye.update()}update_size(t,e){console.warn("Screen Singleton is deprecated. Please use OScreen."),ye.update_size(t,e)}apply_pixel_density_v2(t){return console.warn("Screen Singleton is deprecated. Please use OScreen."),ye.apply_pixel_density_v2(t)}apply_pixel_density(t){return console.warn("Screen Singleton is deprecated. Please use OScreen."),ye.apply_pixel_density(t)}get_pixel_size(){return console.warn("Screen Singleton is deprecated. Please use OScreen."),ye.get_pixel_size()}get aspect_ratio(){return console.warn("Screen Singleton is deprecated. Please use OScreen."),ye.aspect_ratio}};class Fr{constructor({name:t,container:e}){this.name=t,this.container=e,this.hidden=!0,Rr.register_component(this)}start(){}on_enter(){this.container.classList.remove("hidden"),Rr.enable_component(this),this.hidden=!1}update(t){}on_exit(){this.container.classList.add("hidden"),Rr.disable_component(this),this.hidden=!0}set_opacity(t){this.container.style.opacity=t[`${this.name}_opacity`],this.toggle_hidden()}toggle_hidden(){Number(this.container.style.opacity)>.001?this.hidden&&this.on_enter():this.hidden||this.on_exit()}}class qr extends n{constructor(t,e,s,r){t=t||1,e=e||1,s=s||"#FF0000",r=r||new D({color:s});const i=new o(t,e);i.rotateX(-1.57),super(i,r)}}class Pr extends n{constructor(t,e,s,r){t=t||1,e=e||1,s=s||"#FF0000",r=r||new D({color:s});super(new o(t,e),r)}}class Nr{constructor(){this.sphere=new j}fit_points(t,e,s,r){this.sphere.setFromPoints(t);const i=Ke.degToRad(s/2),n=2*Math.atan(Math.tan(i)*r)/2,o=this.get_up_plane_normal(e,i),a=this.get_down_plane_normal(e,i),h=this.get_left_plane_normal(e,n),_=this.get_right_plane_normal(e,n),c=new l(0,0,-1).applyQuaternion(e),u=this.sphere.center.clone(),d=this.get_distance_to_fit_rect(2*this.sphere.radius,2*this.sphere.radius,s,r),p=u.clone().add(c.clone().multiplyScalar(-1*d)),m=(new X).setFromNormalAndCoplanarPoint(o,p),g=(new X).setFromNormalAndCoplanarPoint(a,p),f=(new X).setFromNormalAndCoplanarPoint(h,p),y=(new X).setFromNormalAndCoplanarPoint(_,p);this.apply_center_correction_to_pos(p,t,e,m,g,f,y),m.setFromNormalAndCoplanarPoint(o,p),g.setFromNormalAndCoplanarPoint(a,p),f.setFromNormalAndCoplanarPoint(h,p),y.setFromNormalAndCoplanarPoint(_,p);let b=1/0;const w=c.clone().multiplyScalar(-2*d);for(let e=0;e<t.length;e++){const s=new H(t[e].clone(),t[e].clone().add(w)),r=new l,i=new l,n=new l,o=new l;m.intersectLine(s,r),g.intersectLine(s,i),f.intersectLine(s,n),y.intersectLine(s,o),r.length()<1e-4&&console.log("up intersection not found",e),i.length()<1e-4&&console.log("down intersection not found",e),n.length()<1e-4&&console.log("left intersection not found",e),o.length()<1e-4&&console.log("right intersection not found",e);const a=t[e].clone().sub(r).length(),h=t[e].clone().sub(i).length(),_=t[e].clone().sub(n).length(),c=t[e].clone().sub(o).length(),u=Math.min(a,h),d=Math.min(_,c),p=Math.min(u,d);p<b&&(b=p)}const x=c.clone().multiplyScalar(b);return p.clone().add(x)}apply_center_correction_to_pos(t,e,s,r,i,n,o){const a=this.get_vertical_correction(e,i,r,s),h=this.get_hozirontal_correction(e,n,o,s);t.add(a),t.add(h)}get_vertical_correction(t,e,s,r){let i,n,o=1/0,a=1/0;const h=new l(0,1,0).applyQuaternion(r);for(let r=0;r<t.length;r++){const _=new H(t[r].clone(),t[r].clone().add(h.clone().multiplyScalar(-5e6))),c=new H(t[r].clone(),t[r].clone().add(h.clone().multiplyScalar(5e6))),u=new l,d=new l;e.intersectLine(_,u),s.intersectLine(c,d);const p=u.distanceTo(t[r]),m=d.distanceTo(t[r]);d.length()<1e-4&&console.log("vertical up intersection not found",r),u.length()<1e-4&&console.log("vertical down intersection not found",r),p<a&&(a=p,n=t[r]),m<o&&(o=m,i=t[r])}console.log(i,n);const _=(o-a)/2;return h.clone().multiplyScalar(-_)}get_hozirontal_correction(t,e,s,r){let i,n,o=1/0,a=1/0;const h=new l(1,0,0).applyQuaternion(r);for(let r=0;r<t.length;r++){const _=new H(t[r].clone(),t[r].clone().add(h.clone().multiplyScalar(-5e6))),c=new H(t[r].clone(),t[r].clone().add(h.clone().multiplyScalar(5e6))),u=new l,d=new l;e.intersectLine(_,u),s.intersectLine(c,d);const p=u.distanceTo(t[r]),m=d.distanceTo(t[r]);u.length()<1e-4&&console.log("left intersection not found",r),d.length()<1e-4&&console.log("right intersection not found",r),p<a&&(a=p,n=t[r]),m<o&&(o=m,i=t[r])}const _=(o-a)/2;return console.log(i,n),h.clone().multiplyScalar(-_)}get_up_plane_normal(t,e){const s=new l(0,-1,0);return s.applyQuaternion((new z).setFromAxisAngle(new l(1,0,0),e)),s.applyQuaternion(t),s}get_down_plane_normal(t,e){const s=new l(0,1,0);return s.applyQuaternion((new z).setFromAxisAngle(new l(1,0,0),-e)),s.applyQuaternion(t),s}get_left_plane_normal(t,e){const s=new l(1,0,0);return s.applyQuaternion((new z).setFromAxisAngle(new l(0,1,0),e)),s.applyQuaternion(t),s}get_right_plane_normal(t,e){const s=new l(-1,0,0);return s.applyQuaternion((new z).setFromAxisAngle(new l(0,1,0),-e)),s.applyQuaternion(t),s}get_distance_to_fit_rect(t,e,s,r){const i=s/2*Math.PI/180,n=2*Math.atan(Math.tan(i)*r)/2,o=e/Math.tan(i),a=t/Math.tan(n);return Math.max(Math.abs(a),Math.abs(o))}}class Or{static convert_to_non_indexed_geometry(t){const e=t.index,s=t.getAttribute("position"),r=[];for(let t=0;t<e.count;t+=3)r.push(s.getX(e.array[t+0])),r.push(s.getY(e.array[t+0])),r.push(s.getZ(e.array[t+0])),r.push(s.getX(e.array[t+1])),r.push(s.getY(e.array[t+1])),r.push(s.getZ(e.array[t+1])),r.push(s.getX(e.array[t+2])),r.push(s.getY(e.array[t+2])),r.push(s.getZ(e.array[t+2]));const i=new L;return i.setAttribute("position",new at(new Float32Array(r),3)),Or.add_barycentric_attribute(i),i}static add_barycentric_attribute(t){const e=[],s=t.getAttribute("position");for(let t=0;t<s.count;t+=3)e.push(1),e.push(0),e.push(0),e.push(0),e.push(1),e.push(0),e.push(0),e.push(0),e.push(1);t.setAttribute("barycentric",new at(new Float32Array(e),3))}}class Lr{static load_images(t){const e=t.querySelectorAll("img");for(let t=0;t<e.length;t++){const s=e[t];s.dataset.src&&(s.src=s.dataset.src)}const s=t.querySelectorAll("object");for(let t=0;t<s.length;t++){const e=s[t];e.dataset.src&&(e.data=e.dataset.src)}}static load_videos(t){const e=t.querySelectorAll("video");for(let t=0;t<e.length;t++){const s=e[t];s.dataset.src&&(s.src=s.dataset.src)}}static load_iframes(t){const e=t.querySelectorAll("iframe");for(let t=0;t<e.length;t++){const s=e[t];s.dataset.src&&(s.src=s.dataset.src)}}static load_elements(t,e){const s=t.querySelectorAll(e);for(let t=0;t<s.length;t++){const e=s[t];e.dataset.src&&(e.src=e.dataset.src)}}}class $r{constructor(){}static get_image_data(t){const e=document.createElement("canvas");e.width=t.width,e.height=t.height;const s=e.getContext("2d");return s.drawImage(t,0,0),s.getImageData(0,0,t.width,t.height)}static get_pixel(t,e,s){const r=4*(e+t.width*s),i=t.data;return new h(i[r+0],i[r+1],i[r+2],i[r+3])}}const Ur=new class{constructor(){}sample(t,s){const r=[];let i=99999999;const n=t.getAttribute("position"),o=t.getAttribute("normal"),a=t.getAttribute("tangent"),h=t.getAttribute("uv"),_=t.index,c=[];for(let t=0;t<_.count;t+=3){const s=_.array[t+0],u=_.array[t+1],d=_.array[t+2],p=new l;p.x=n.getX(s),p.y=n.getY(s),p.z=n.getZ(s);const m=new l;m.x=n.getX(u),m.y=n.getY(u),m.z=n.getZ(u);const g=new l;g.x=n.getX(d),g.y=n.getY(d),g.z=n.getZ(d);const f={a:p,b:m,c:g,normal:void 0,tangent:void 0,uv_a:void 0,uv_b:void 0,uv_c:void 0};if(o){const t=new l;t.x=o.getX(s),t.y=o.getY(s),t.z=o.getZ(s);const e=new l;e.x=o.getX(u),e.y=o.getY(u),e.z=o.getZ(u);const r=new l;r.x=o.getX(d),r.y=o.getY(d),r.z=o.getZ(d);const i=t.clone().add(e).add(r).normalize();f.normal=i}if(a){const t=new l;t.x=a.getX(s),t.y=a.getY(s),t.z=a.getZ(s);const e=new l;e.x=a.getX(u),e.y=a.getY(u),e.z=a.getZ(u);const r=new l;r.x=a.getX(d),r.y=a.getY(d),r.z=a.getZ(d);const i=t.clone().add(e).add(r).normalize();f.tangent=i}if(h){const t=new e;t.x=h.getX(s),t.y=h.getY(s);const r=new e;r.x=h.getX(u),r.y=h.getY(u);const i=new e;i.x=h.getX(d),i.y=h.getY(d),f.uv_a=t,f.uv_b=r,f.uv_c=i}c.push(f);const y=this.get_face_area(f);i=Math.min(y,i),r.push(y)}const u=this.get_uniform_face_distribution(r,i,c),d=this.select_random_faces(u,s);return this.sample_data_from_faces(d)}sample_data_from_faces(t){const e=[],s=[],r=[],i=[];for(let n=0;n<t.length;n++){const o=t[n],a=Math.random(),h=Math.random();e.push(this.sample_point_in_face(a,h,o.a,o.b,o.c).clone()),o.normal&&s.push(o.normal.clone()),o.tangent&&r.push(o.tangent.clone()),o.uv_a&&i.push(this.sample_point_in_face(a,h,o.uv_a,o.uv_b,o.uv_c).clone())}return{points:e,normals:s,tangents:r,uvs:i}}select_random_faces(t,e){const s=[];for(let r=0;r<e;r++){const e=t[Math.floor(Math.random()*t.length)];s.push(e)}return s}get_uniform_face_distribution(t,e,s){const r=[];for(let i=0;i<t.length;i++){t[i]/=e;const n=Math.floor(Math.round(t[i]));for(let t=0;t<n;t++)r.push(s[i])}return r}get_face_area(t){const e=t.b.clone().sub(t.a),s=t.c.clone().sub(t.a);return e.cross(s).length()/2}sample_point_in_face(t,e,s,r,i){t+e>1&&(t=1-t,e=1-e);const n=1-(t+e);return s.clone().multiplyScalar(t).add(r.clone().multiplyScalar(e)).add(i.clone().multiplyScalar(n))}};const Br=new class{get_mesh(t,e){t.traverse((t=>{t instanceof n&&(t.geometry&&(t.geometry=t.geometry.clone()),e(t))}))}get_geometries(t){const e=[];return this.get_mesh(t,(t=>{e.push(t.geometry)})),e}assign_material(t,e,s){t.traverse((t=>{t instanceof n&&(void 0===s||t.name===s)&&(t.material=e)}))}clone_animated_gltf(t){const e={animations:t.animations,scene:t.scene.clone(!0)},s={};t.scene.traverse((t=>{t.isSkinnedMesh&&(s[t.name]=t)}));const r={},i={};e.scene.traverse((t=>{t.isBone&&(r[t.name]=t),t.isSkinnedMesh&&(i[t.name]=t)}));for(const t in s){const e=s[t].skeleton,n=i[t],o=[];for(let t=0;t<e.bones.length;++t){const s=r[e.bones[t].name];o.push(s)}n.bind(new ht(o,e.boneInverses),n.matrixWorld)}return e}set_shadow_config(t,e,s){t.traverse((t=>{t instanceof n&&(t.castShadow=e,t.receiveShadow=s)}))}__find_object(t,e,s){t.traverse((t=>{t.name===e&&s(t)}))}get_object(t,e){let s;return t.traverse((t=>{t.name===e&&(s=t)})),s}get_object_by_type(t,e){let s;return t.traverse((t=>{t.constructor.name===e&&(s=t)})),s}};class Er{static is_object(t){return t&&"object"==typeof t&&!Array.isArray(t)}static merge_deep(t,...e){if(!e.length)return t;const s=e.shift();if(Er.is_object(t)&&Er.is_object(s))for(const e in s)Er.is_object(s[e])?(t[e]||Object.assign(t,{[e]:{}}),Er.merge_deep(t[e],s[e])):Object.assign(t,{[e]:s[e]});return Er.merge_deep(t,...e)}static xml_to_json(t){let e={};if(1===t.nodeType){if(t.attributes.length>0){e["@attributes"]={};for(let s=0;s<t.attributes.length;s++){const r=t.attributes.item(s);e["@attributes"][r.nodeName]=r.nodeValue}}}else 3===t.nodeType&&(e=t.nodeValue);if(t.hasChildNodes())for(let s=0;s<t.childNodes.length;s++){const r=t.childNodes.item(s),i=r.nodeName;if(void 0===e[i])e[i]=this.xml_to_json(r);else{if(void 0===e[i].push){const t=e[i];e[i]=[],e[i].push(t)}e[i].push(this.xml_to_json(r))}}return e}}class Ir{constructor(){}static get_random_color(){const t=[0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F"];let e="#";for(let s=0;s<6;s++){e+=t[Math.floor(Math.random()*t.length)]}return e}static capitalize(t){const e=t.split(" ");for(let t=0;t<e.length;t++)e[t]=e[t][0].toUpperCase()+e[t].substr(1);return e.join(" ")}static capitalize_first_letter(t){return t.charAt(0).toUpperCase()+t.slice(1)}static snake_to_camelcase(t){return t.toLowerCase().replace(/[-_][a-z0-9]/g,(t=>t.slice(-1).toUpperCase()))}}class Dr{constructor(){}time_str_to_ms(t){const e=t.split(":");let s=Number(e[0]);s=60*s*60*1e3;let r=Number(e[1]);r=60*r*1e3;let i=Number(e[2]);return i*=1e3,s+r+i}}class Qr{constructor(){}static is_int(t){return Number(t)===t&&t%1==0}static is_float(t){return Number(t)===t&&t%1!=0}static is_number(t){return this.is_int(t)||this.is_float(t)}static is_json(t){try{JSON.parse(t)}catch(t){return!1}return!0}}class Vr extends n{constructor(){const{colorNode:t,opacityNode:e}=function(t="#4a4a4a"){const e=ut(new r(t)),s=(t=>{const e=Jt(t),s=Xt(xt(0),e.mul(1.5),t);return qt(qt(s.x,s.y),s.z)})(At("barycentric","vec3").add(xt(1,1,0)));return{colorNode:gt(e,xt(0),s),opacityNode:s.oneMinus().mul(.2)}}("#4a4a4a"),s=new se({transparent:!0,depthWrite:!1});s.colorNode=t,s.opacityNode=e;const i=new o(100,100,100,100);super(Or.convert_to_non_indexed_geometry(i),s),this.rotation.x=-1.57}}class Yr extends ee{constructor(){super();const t=ut(.2),e=ut(new r("#FF0000"));this.uniforms={_Thickness:t,_Length:ut(0),_ElapsedTime:ut(0),_Color:e};const s=At("orientation","float"),i=Gt.mul(dt(At("next_position","vec3"),1)).xyz,n=Gt.mul(dt(At("previous_position","vec3"),1)).xyz,o=zt(n.sub(i)),a=zt(Yt(o,zt(te.sub(i)))),h=Gt.mul(dt(pt,1)).xyz.add(a.mul(t.mul(.5)).mul(s));this.vertexNode=Rt.mul(Ct).mul(dt(h,1));const _=jt(s);this.fragmentNode=dt(e.mul(vt(1).sub(Mt(_)).mul(.5).add(.5)),1),this.transparent=!0,this.depthWrite=!1,this.fog=!1}}function Wr(){const t=new L;return t.setAttribute("position",new at(new Float32Array([]),3)),t.setAttribute("next_position",new at(new Float32Array([]),3)),t.setAttribute("previous_position",new at(new Float32Array([]),3)),t.setAttribute("orientation",new at(new Float32Array([]),1)),t.setAttribute("coverage",new at(new Float32Array([]),1)),t}class Xr extends n{constructor(t){const e=Wr(),s=new Yr;super(e,s),this.material=s,t&&this.setup(t)}setup(t){const e=[],s=[],r=[],i=[],n=[];let o=0;for(let a=0;a<t.length;a++){e.push(t[a].x),e.push(t[a].y),e.push(t[a].z),i.push(1),e.push(t[a].x),e.push(t[a].y),e.push(t[a].z),i.push(-1);const h=this.__get_next_position(t,a);s.push(h.x),s.push(h.y),s.push(h.z),s.push(h.x),s.push(h.y),s.push(h.z);const _=this.__get_previous_position(t,a);r.push(_.x),r.push(_.y),r.push(_.z),r.push(_.x),r.push(_.y),r.push(_.z),n.push(o),n.push(o),a<t.length-1&&(o+=t[a].distanceTo(h))}const a=new Float32Array(e),h=new Float32Array(s),_=new Float32Array(r),l=new Float32Array(i),c=new Float32Array(n),u=[];for(let t=0;t<(a.length/3-2)/2;t++){const e=2*t+1;u.push(e),u.push(e+1),u.push(e-1),u.push(e),u.push(e+2),u.push(e+1)}if(a.length/3!==this.geometry.getAttribute("position").count){const t=this.geometry;this.geometry=Wr(),this.geometry.setIndex(u),t.dispose()}this.geometry.getAttribute("position").copy(new at(a,3)),this.geometry.getAttribute("next_position").copy(new at(h,3)),this.geometry.getAttribute("previous_position").copy(new at(_,3)),this.geometry.getAttribute("orientation").copy(new at(l,1)),this.geometry.getAttribute("coverage").copy(new at(c,1)),this.geometry.getAttribute("position").needsUpdate=!0,this.geometry.getAttribute("next_position").needsUpdate=!0,this.geometry.getAttribute("previous_position").needsUpdate=!0,this.geometry.getAttribute("orientation").needsUpdate=!0,this.geometry.getAttribute("coverage").needsUpdate=!0,this.material.uniforms._Length.value=o,this._length=o,this.accumulated_length=o}set thickness(t){this.material.uniforms._Thickness.value=t}get thickness(){return this.material.uniforms._Thickness.value}__get_previous_position(t,e){return 0===e?t[1].clone().sub(t[0]).multiplyScalar(-1).add(t[0]):t[e-1]}__get_next_position(t,e){return e===t.length-1?t[t.length-2].clone().sub(t[t.length-1]).multiplyScalar(-1).add(t[t.length-1]):t[e+1]}update(){}distance(){return this.accumulated_length}total_length(){return this.accumulated_length}dispose(){this.geometry.dispose(),this.material.dispose(),this.parent&&this.parent.remove(this),super.dispose()}set color(t){this.material.uniforms._Color.value.set(t)}get color(){return this.material.uniforms._Color.value}copy_color(t){this.material.uniforms._Color.value.copy(t)}}class Hr extends n{constructor(t,e){super(t,e),this.material=e;const s=this;this.onBeforeRender=()=>{"update"in s.material&&"function"==typeof s.material.update&&s.material.update()}}}class Zr extends ts{constructor(t,e=new l,s=new l(1,1,1),r="linear"){super(r),this.attribute_name=t,this.from=e,this.to=s}update(t,e){const s=this.from.clone();s.lerp(this.to,this.easing_function(e)),t[this.attribute_name].copy(s)}}class Kr extends ge{constructor(t,e,s){super(t,e,s),this.loader=new ae}on_preloaded_finished(t){void 0===t.resources_by_url[this.url]?this.loader.load(this.url,(e=>{t.set_resource(this.resource_id,this.url,e),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(t=>{this.__set_error(t+"\n\n\t If the error says something about unexpected token < in JSON then the probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class Jr extends ge{constructor(t,e,s){super(t,e,s),this.loader=new _t}on_preloaded_finished(t){void 0===t.resources_by_url[this.url]?this.loader.load(this.url,(e=>{t.set_resource(this.resource_id,this.url,e),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(t=>{this.__set_error(t),this.__loading_ended()})):(t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class Gr extends ge{constructor(t,e,s){super(t,e,s),this.loader=new he}on_preloaded_finished(t){void 0===t.resources_by_url[this.url]?this.loader.load(this.url,(e=>{t.set_resource(this.resource_id,this.url,e),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(t=>{this.__set_error(t+"\n\n\t If the error says something about unexpected token < in JSON then probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class ti extends ge{constructor(t,e,s){super(t,e,s)}on_preloaded_finished(t){void 0===t.resources_by_url[this.url]?fetch(this.url).then((e=>{e.json().then((e=>{t.set_resource(this.resource_id,this.url,e),this.__update_downloaded_bytes(1,1),this.__loading_ended()}))})):(t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class ei extends ge{constructor(t,e,s){super(t,e,s),this.loader=new _e}on_preloaded_finished(t){void 0===t.resources_by_url[this.url]?this.loader.load(this.url,(e=>{t.set_resource(this.resource_id,this.url,e),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(t=>{this.__set_error(t+"\n\n\t If the error says something about unexpected token < in JSON then probably the problem is related to the file not being found. Check the name and path of the resource"),this.__loading_ended()})):(t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class si extends ge{constructor(t,e,s){super(t,e,s),this.loader=new _t}on_preloaded_finished(t){void 0===t.resources_by_url[this.url]?this.loader.load(this.url,(e=>{t.set_resource(this.resource_id,this.url,this.parse_path(e)),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(t=>{this.__set_error(t),this.__loading_ended()})):(t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}parse_path(t){const e=t.split("\n");""===e[e.length-1]&&e.pop();const s=[];for(let t=0;t<e.length;t+=3){const r=parseFloat(e[t+0]),i=parseFloat(e[t+1]),n=parseFloat(e[t+2]);s.push(new l(r,i,n))}return s}}class ri extends ge{constructor(t,e,s){super(t,e,s),this.loader=new _t}on_preloaded_finished(t){void 0===t.resources_by_url[this.url]?this.loader.load(this.url,(e=>{t.set_resource(this.resource_id,this.url,e),this.__update_downloaded_bytes(1,1),this.__loading_ended()}),(()=>{}),(t=>{this.__set_error(t),this.__loading_ended()})):(t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class ii extends ge{constructor(t,e,s){super(t,e,s)}on_preloaded_finished(e,s){void 0===e.resources_by_url[this.url]?s.blob().then((s=>{const r=new t,i=URL.createObjectURL(s),n=new Image;n.src=i,n.onload=()=>{r.image=n,r.needsUpdate=!0,e.set_resource(this.resource_id,this.url,r),this.__update_downloaded_bytes(1,1),this.__loading_ended()},n.onerror=()=>{console.error("Error loading texture. Maybe the resource is not an image?",this.url)}})):(e.set_resource(this.resource_id,this.url,e.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class ni extends ge{constructor(t,e,s){super(t,e,s)}on_preloaded_finished(t,e){void 0===t.resources_by_url[this.url]?e.blob().then((e=>{t.set_resource(this.resource_id,this.url,URL.createObjectURL(e)),this.__update_downloaded_bytes(1,1),this.__loading_ended()})):(t.set_resource(this.resource_id,this.url,t.resources_by_url[this.url]),this.__update_downloaded_bytes(1,1),this.__loading_ended())}}class oi{constructor(t){this.name=t,this.resources={},this.resources_by_url={}}set_resource(t,e,s){Object.keys(this.resources_by_url).includes(e)?this.resources[t]=this.resources_by_url[e]:(this.resources[t]=s,this.resources_by_url[e]=s)}get_resource(t){return this.resources[t]}get(t){return this.resources[t]}}class ai{constructor(t){this.resource_loaders=[],this.batch_name=t||"unnamed batch"}add_loader(t){this.resource_loaders.push(t)}load(t){for(let e=0;e<this.resource_loaders.length;e++)this.resource_loaders[e].load(t||oi)}get loading_finished(){let t=!0;for(let e=0;e<this.resource_loaders.length;e++)t=t&&this.resource_loaders[e].has_finished;return t}get has_errors(){let t=!1;for(let e=0;e<this.resource_loaders.length;e++)t=t||this.resource_loaders[e].has_error;return t}print_errors(){console.error("Batch <"+this.batch_name+"> could not load successfully");for(let t=0;t<this.resource_loaders.length;t++)this.resource_loaders[t].has_error&&this.resource_loaders[t].print_error()}get_progress(){return this.get_loaded_bytes()/this.get_total_bytes()}get_loaded_bytes(){let t=1;for(let e=0;e<this.resource_loaders.length;e++)t+=this.resource_loaders[e].loaded_bytes;return t}get_total_bytes(){let t=1;for(let e=0;e<this.resource_loaders.length;e++)t+=this.resource_loaders[e].total_bytes;return t}}class hi{start(){this.finished=!1}update(){this.finished=!0}}class _i{constructor(){}on_enter(t){}on_exit(t){}update(t){}}class li extends _i{constructor(){super(),this.rotation_speed=new e,this.vector_forward_axis=new l(0,0,-1),this.tmp_forward=new l,this.tmp_quat=new z,this.tmp_camera_target_pos=new l}on_enter(t){t.reference_rotation.copy(t.camera.quaternion)}update(t){t.camera.quaternion.copy(t.reference_rotation),this.tmp_forward.copy(this.vector_forward_axis);const e=this.tmp_forward.applyQuaternion(t.camera.quaternion);t.reference_zoom=Ke.clamp(t.reference_zoom,t.min_zoom,t.max_zoom),t.camera.position.copy(t.reference_position).sub(e.multiplyScalar(t.reference_zoom)),t.__last_reference_position.copy(t.reference_position)}get_target_camera_pos(t){this.tmp_quat.copy(t.reference_rotation),this.tmp_forward.copy(this.vector_forward_axis);const e=this.tmp_forward.applyQuaternion(this.tmp_quat),s=Ke.clamp(t.reference_zoom,t.min_zoom,t.max_zoom);return this.tmp_camera_target_pos.copy(t.reference_position).sub(e.multiplyScalar(s)),this.tmp_camera_target_pos}}class ci{constructor(){}on_enter(t){}on_exit(t){}update(t){}lock_zoom(){}unlock_zoom(){}}class ui{constructor(t){this.input=t,this.camera=void 0,this.camera_initial_rot=void 0,this.camera_initial_pos=void 0,this.current_state=new ci,this.current_mode=new li,this.point_of_interest=new l,this.normalized_zoom=0,this.vector_up_axis=new l(0,1,0),this.vector_right_axis=new l(1,0,0),this.vector_forward_axis=new l(0,0,1),this.tmp_forward=this.vector_forward_axis.clone(),this.tmp_right=this.vector_right_axis.clone(),this.tmp_dir=new l,this.zoom=10,this.reference_zoom=10,this.orientation=27,this.tilt=70,this.reference_rotation=new z,this.reference_position=new l,this.__last_reference_position=new l,this.tmp_size=new l,this.tmp_quat=new z,this.min_zoom=1,this.max_zoom=400,this.current_tilt=0,this.current_orientation=0,this.current_azimuth=0,this.projection_plane_helper=new lt(new X,1,16776960),this.input_enabled=!0,this.raised_look_at_position=new l(-82.2986094900191,0,39.7538467209173),this.use_raised_look_at_direction=0}enable(){this.input_enabled=!0}disable(){this.input_enabled=!1}set_camera(t){this.camera=t,this.camera_initial_rot=t.quaternion.clone(),this.camera_initial_pos=t.position.clone()}set_state(t){this.current_state.on_exit(this),this.current_state=t,this.current_state.on_enter(this)}set_mode(t){this.current_mode.on_exit(this),this.current_mode=t,this.current_mode.on_enter(this)}set_normalized_zoom(t){this.normalized_zoom=Ke.clamp(t,0,1)}update_normalized_zoom(t,e){const s=this.camera.position.distanceTo(this.reference_position);this.normalized_zoom=Ke.linear_map(s,t,e,1,0),this.normalized_zoom=Ke.clamp(this.normalized_zoom,0,1)}update(){this.debug_box&&this.debug_box.position.copy(this.reference_position),this.current_state.update(this),this.current_mode.update(this),this.update_normalized_zoom(this.min_zoom,this.max_zoom)}set_idle(){this.set_state(new ci)}camera_is_zoomed_out(){return this.normalized_zoom<.2}set_rotation(t,e,s){this.old_orientation=this.current_orientation,this.current_tilt=t??this.current_tilt,this.current_orientation=e??this.current_orientation,this.current_azimuth=s??this.current_azimuth,this.set_quaternion(this.build_rotation(this.current_tilt,this.current_orientation))}set_rotation_delta(t,e,s=0){this.lerp_rotation(this.current_tilt,this.current_tilt+t,this.current_orientation,this.current_orientation+e,this.current_azimuth,this.current_azimuth+s,1)}lerp_tilt(t,e,s){this.lerp_rotation(t,e,this.current_orientation,this.current_orientation,this.current_azimuth,this.current_azimuth,s)}set_quaternion(t){const e=2*Math.atan2(t.x,t.w),s=2*Math.atan2(t.y,t.w);this.current_orientation=Ke.euclideanModulo(Ke.radToDeg(s),360),this.current_tilt=180-Ke.euclideanModulo(180+Ke.radToDeg(e),360),this.reference_rotation.copy(t)}lerp_quaternion(t,e){this.set_quaternion(this.reference_rotation.clone().slerp(t,e))}lerp_orientation(t,e,s){this.lerp_rotation(this.current_tilt,this.current_tilt,t,e,this.current_azimuth,this.current_azimuth,s)}lerp_azimuth(t,e,s){}lerp_rotation(t,e,s,r,i,n,o){const a=this.build_rotation(t,s),h=this.build_rotation(e,r);a.slerp(h,o),this.set_quaternion(a)}build_rotation(t,e){e<0&&(e+=360);const s=(new z).setFromAxisAngle(this.vector_up_axis,e%360/360*Math.PI*2),r=(new z).setFromAxisAngle(this.vector_right_axis,-t/360*Math.PI*2);return s.multiply(r)}translate_forward(t){this.tmp_forward.copy(this.vector_forward_axis),this.tmp_forward.applyQuaternion(this.camera.quaternion),this.reference_position.add(this.tmp_forward.multiplyScalar(t))}translate_right(t){this.tmp_right.copy(this.vector_right_axis),this.tmp_right.applyQuaternion(this.camera.quaternion),this.reference_position.add(this.tmp_right.multiplyScalar(t))}focus_on_bounding_box(t,e=1){const s=new l;s.copy(t.max).sub(t.min);const r=t.min.clone(),i=r.clone().add(new l(s.x,0,0)),n=r.clone().add(new l(0,s.y,0)),o=r.clone().add(new l(0,0,s.z)),a=r.clone().add(new l(s.x,0,s.z)),h=r.clone().add(new l(0,s.y,s.z)),_=t.max.clone(),c=r.clone().add(new l(s.x,s.y,0));this.focus_camera_on_points([r,i,n,o,a,h,_,c],e)}get_zoom_to_focus_on_points(t,e){if(this.__is_orthographic())return this.__fit_orthographic(this.reference_rotation,t,e).zoom;const s=this.reference_zoom,r=(new l).copy(this.reference_position);this.focus_camera_on_points(t,e);const i=this.reference_zoom;return this.reference_zoom=s,this.reference_position.copy(r),i}get_target_pos_to_focus_on_points(t,e){if(this.__is_orthographic())return this.__fit_orthographic(this.reference_rotation,t,e).center;const s=this.reference_zoom,r=(new l).copy(this.reference_position);this.focus_camera_on_points(t,e);const i=this.reference_position.clone();return this.reference_zoom=s,this.reference_position.copy(r),i}focus_camera_on_sphere(t,e){this.__is_orthographic()?(this.__set_orthographic_zoom(this.get_zoom_to_sphere(t,e)),this.reference_zoom=this.__get_orthographic_distance(t.radius)):this.reference_zoom=this.get_zoom_to_sphere(t,e),this.reference_position.copy(t.center)}get_zoom_to_sphere(t,e){if(this.__is_orthographic())return this.__get_orthographic_zoom(2*t.radius,2*t.radius);const s=this.camera.fov/2*Math.PI/180,r=2*Math.atan(Math.tan(s)*this.camera.aspect)/2,i=t.radius/Math.tan(s),n=t.radius/Math.tan(r);return Math.max(Math.abs(n),Math.abs(i))}hide_projected_points(){for(let t=0;t<this.projected_points.length;t++)this.projected_points[t].visible=!1}show_projected_points(t){this.hide_projected_points();for(let e=0;e<t.length;e++)this.projected_points[e].visible=!0,this.projected_points[e].position.copy(t[e])}show_plane_projection(t,e=1){this.projection_plane_helper.plane=t,this.projection_plane_helper.size=e,this.projection_plane_helper.updateMatrixWorld(),this.projection_plane_helper.visible=!0}show_sphere_projection(t){this.projection_sphere_helper.scale.set(t.radius,t.radius,t.radius),this.projection_sphere_helper.position.copy(t.center),this.projection_sphere_helper.visible=!0}fit_points(t,e,s=1){if(this.camera.isPerspectiveCamera){const r=new l(0,0,-1).applyQuaternion(t),i=r.clone().multiplyScalar(-1),n=new tr,o=ye.aspect_ratio,a=n.fit_points(e,t,this.camera.fov*s,o),h=(new F).setFromPoints(e),_=new l;h.getCenter(_);const c=(new X).setFromNormalAndCoplanarPoint(i,_),u=new Z(a,r),d=new l;u.intersectPlane(c,d);return{zoom:a.distanceTo(d),reference_position:d,camera_position:a}}{const r=this.__fit_orthographic(t,e,s),i=new l(0,0,1).applyQuaternion(t);return{zoom:r.zoom,reference_position:r.center,camera_position:r.center.clone().add(i.multiplyScalar(r.distance))}}}focus_camera_on_points(t,e=1){if(this.camera.isPerspectiveCamera){const s=new l(0,0,-1).applyQuaternion(this.reference_rotation),r=s.clone().multiplyScalar(-1),i=new tr,n=ye.aspect_ratio,o=i.fit_points(t,this.reference_rotation,this.camera.fov*e,n),a=(new F).setFromPoints(t),h=new l;a.getCenter(h);const _=(new X).setFromNormalAndCoplanarPoint(r,h),c=new Z(o,s),u=new l;c.intersectPlane(_,u);const d=o.distanceTo(u);this.reference_zoom=d,this.reference_position.copy(u)}else{const s=this.__fit_orthographic(this.reference_rotation,t,e);this.__set_orthographic_zoom(s.zoom),this.reference_zoom=s.distance,this.reference_position.copy(s.center)}}get_current_tilt(){return this.current_tilt}get_current_orientation(){return this.current_orientation}get_current_azimuth(){return this.current_azimuth}__get_zoom_to_show_rect(t,e,s=1){if(this.__is_orthographic())return this.__get_orthographic_zoom(2*t,2*e,s);const r=Ke.degToRad(this.camera.fov/2),i=2*Math.atan(Math.tan(r)*this.camera.aspect)/2,n=e/Math.tan(r*s),o=t/Math.tan(i*s);return Math.max(Math.abs(o),Math.abs(n))}__is_orthographic(){return!0===this.camera.isOrthographicCamera}__fit_orthographic(t,e,s){const r=(new Gs).get_view_bounds(e,t);return{zoom:this.__get_orthographic_zoom(r.size.x,r.size.y,s),center:r.center,distance:this.__get_orthographic_distance(r.size.z/2)}}__get_orthographic_distance(t){return(new Gs).get_distance_to_fit_depth(this.camera,t,this.reference_zoom)}__get_orthographic_zoom(t,e,s=1){return(new Gs).get_zoom_to_fit_size(this.camera,t,e,s)}__set_orthographic_zoom(t){const e=this.camera;e.zoom=t,e.updateProjectionMatrix()}}class di extends ci{constructor(t){super(),this.input=t,this.last_point=new e,this.rotation_velocity=new e,this.forward_dir=0,this.right_dir=0,this.y_dir=0,this.azimuth_dir=0,this.shift_key=!1}on_enter(t){}on_exit(t){}update(t){this.__check_key_down(),this.__check_key_up()}__show_camera_position(t){this.input.left_mouse_button_released&&console.log({x:t.reference_position.x,y:t.reference_position.y,z:t.reference_position.z,orientation:t.current_orientation,tilt:t.current_tilt,azimuth:t.current_azimuth,zoom:t.reference_zoom,fov:t.camera.fov})}__zoom_camera(t){t.reference_zoom+=.5*this.input.zoom_delta}__rotate_camera(t){if(this.input.left_mouse_button_down&&1===this.input.pointer_count){const t=new e(-24*this.input.NDC_delta.x,-8*this.input.NDC_delta.y);t.multiplyScalar(60*ns.delta_time),this.rotation_velocity.add(t)}t.set_rotation_delta(this.rotation_velocity.y,this.rotation_velocity.x);const s=1-Math.exp(-5*ns.delta_time);this.rotation_velocity.lerp(new e(0,0),s)}__move_camera(t){if(t.translate_forward(this.forward_dir),t.translate_right(this.right_dir),t.reference_position.y-=this.y_dir,this.input.right_mouse_button_pressed&&this.last_point.copy(this.input.NDC),this.input.right_mouse_button_down){const e=er.get_plane_intersection(t.reference_position,void 0,this.last_point).clone(),s=er.get_plane_intersection(t.reference_position,void 0,this.input.NDC).clone();s.sub(e),t.reference_position.x-=s.x,t.reference_position.y-=s.y,t.reference_position.z-=s.z,this.last_point.copy(this.input.NDC)}}__check_key_down(){const t=.12;this.input.keyboard.is_key_down("KeyW")&&(this.forward_dir=-.12),this.input.keyboard.is_key_down("KeyS")&&(this.forward_dir=t),this.input.keyboard.is_key_down("KeyA")&&(this.right_dir=-.12),this.input.keyboard.is_key_down("KeyD")&&(this.right_dir=t),this.input.keyboard.is_key_down("KeyQ")&&(this.azimuth_dir=.48),this.input.keyboard.is_key_down("KeyE")&&(this.azimuth_dir=-.48),this.input.keyboard.is_key_down("KeyZ")&&(this.y_dir=t),this.input.keyboard.is_key_down("KeyC")&&(this.y_dir=-.12),this.input.keyboard.is_key_down("ShiftLeft")&&(this.shift_key=!0)}__check_key_up(){this.input.keyboard.is_key_released("KeyW")&&(this.forward_dir=0),this.input.keyboard.is_key_released("KeyS")&&(this.forward_dir=0),this.input.keyboard.is_key_released("KeyA")&&(this.right_dir=0),this.input.keyboard.is_key_released("KeyD")&&(this.right_dir=0),this.input.keyboard.is_key_released("KeyQ")&&(this.azimuth_dir=0),this.input.keyboard.is_key_released("KeyE")&&(this.azimuth_dir=0),this.input.keyboard.is_key_released("KeyZ")&&(this.y_dir=0),this.input.keyboard.is_key_released("KeyC")&&(this.y_dir=0),this.input.keyboard.is_key_released("ShiftLeft")&&(this.shift_key=!1)}}export{ci as AbstractCameraState,ge as AbstractLoader,He as AbstractScene,Ze as ActionEvent,ts as ActionInterpolator,Je as ActionSequencer,rs as ActionSequencerBuilder,ue as AddMaterial,ls as ApplicationView,ws as ArrayUtilities,Es as Arrow,qe as AsyncAbstractLoader,Pe as AsyncAudiosLoader,Le as AsyncObjectsLoader,Ue as AsyncTextureLoader,Qe as AsyncTexturesLoader,je as AudioLoader,le as BaseApplication,me as BaseRender,Be as BasisLoader,ce as BlitNodeMaterial,dr as BloomRender,hr as Blurrer,$e as Browser,Zs as CSSAnimator,ps as CameraBridge,ui as CameraController,fe as CameraManager,_i as CameraMovementMode,er as CameraUtilities,cs as CanvasDrawer,ds as Capabilities,ms as CaptureService,di as CommonCameraState,hi as Compilator,ys as ConsoleBuffer,Is as Cube,Ee as CubemapLoader,Kr as DAELoader,Vs as Debug,Rs as DebugDrawer,mr as DebugNormalsRender,fr as DeferredRender,Ws as DevBridge,ss as DrawIOAnimationSheet,cr as DualFilteringBlurMaterial,ur as DualFilteringBlurrer,Ge as EasingFunctions,Jr as FileLoader,Gr as FontLoader,Nr as FrustumPointFitter,Ne as GLTFDRACOLoader,Oe as GLTFLoader,kr as GaussianBlurrer,Or as GeometryUtilities,Re as Graphics,Vr as Grid,Ie as HDRCubeTextureLoader,De as HDRTextureLoader,Lr as HTMLUtilities,We as HighQualityLoadingState,qr as HorizontalPlane,$r as ImageUtilities,li as ImmediateMode,sr as Initializer,js as InputSynthesizer,ti as JSONLoader,rr as KeyboardInput,Xr as Line,Ye as LoadingState,Ur as MeshSampler,Br as ModelUtilities,wr as NormalAORender,xr as NormalRender,es as NumberInterpolator,ei as OBJLoader,Ke as OMath,Ks as OS,ye as OScreen,Er as ObjectUtilities,ir as OrthographicCamera,Gs as OrthographicFrustumPointFitter,Fs as PerformanceProbe,Bs as PerspectiveCamera,tr as PerspectiveFrustumPointFitter,si as PointArrayLoader,Xe as RegularLoadingState,Cr as RenderLoop,qs as RenderModeRegistry,ai as ResourceBatch,Fe as ResourceContainer,Ms as SDFTextBatch,Ps as SceneEditor,Ns as SceneInspector,be as SceneManager,jr as Screen,us as SimpleTextDrawer,Ds as Sphere,Ir as StringUtilities,$s as Text2D,ri as TextLoader,ii as TextureLoader,ns as Time,Dr as TimeUtilities,hs as TransitionManager,is as TransitionTable,pe as UnrealBloomComposeMaterial,Ar as UnrealBloomRender,Hr as UpdatableMaterialMesh,Sr as VRRender,Qr as Validation,Zr as VectorInterpolator,Pr as VerticalPlane,ni as VideoLoader,Fr as ViewComponent,Rr as ViewComponentManager,_s as ViewManager,Os as ViewNavigator,ks as WorldImage};
2
2
  //# sourceMappingURL=index.mjs.map