@needle-tools/engine 4.7.2-next.37cf642 → 4.7.2-next.d24ebbc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- var RC=Object.defineProperty,Mv=n=>{throw TypeError(n)},TC=(n,e,t)=>e in n?RC(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,a=(n,e,t)=>TC(n,typeof e!="symbol"?e+"":e,t),Mm=(n,e,t)=>e.has(n)||Mv("Cannot "+t),ge=(n,e,t)=>(Mm(n,e,"read from private field"),t?t.call(n):e.get(n)),Fs=(n,e,t)=>e.has(n)?Mv("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),Us=(n,e,t,s)=>(Mm(n,e,"write to private field"),s?s.call(n,t):e.set(n,t),t),ud=(n,e,t)=>(Mm(n,e,"access private method"),t);import{Vector2 as re,Vector3 as S,Vector4 as fe,Quaternion as V,PlaneGeometry as zs,WebGLRenderer as gr,PerspectiveCamera as we,OrthographicCamera as pd,Scene as xi,Mesh as G,Texture as je,Uniform$1 as Qi,Color as oe,ShaderMaterial as Ns,Box3 as Si,ShadowMaterial as Rv,Euler as Bt,MeshStandardMaterial as bt,Box3Helper as EC,GridHelper as Rm,Object3D as E,Material as Pe,Matrix3 as Tv,Matrix4 as se,Layers as po,Ray as mo,MathUtils as Pn,AxesHelper as Ci,MeshBasicMaterial as Me,DoubleSide as Pi,BufferGeometry as Ws,Group as go,CylinderGeometry as Ev,SphereGeometry as md,BoxGeometry as xa,SpriteMaterial as AC,Sprite as IC,Shape as LC,ExtrudeGeometry as jC,Fog as Av,DirectionalLight as Tm,PointLight as Em,EdgesGeometry as DC,LineSegments as Iv,LineBasicMaterial as Lv,Line as Hl,BufferAttribute as _t,Raycaster as gd,Sphere as fd,ArrayCamera as BC,Plane as fr,SkinnedMesh as On,InterleavedBufferAttribute as jv,Skeleton as FC,Bone as UC,Source as zC,WebGLCubeRenderTarget as NC,CubeCamera as WC,AnimationClip as fo,FileLoader as Am,TextureLoader as Sa,PropertyBinding as Ca,LinearSRGBColorSpace as kn,ShaderChunk as qt,UniformsLib as VC,DataTexture as Im,RGBAFormat as yd,EquirectangularReflectionMapping as Mn,SRGBColorSpace as Rn,Clock as $C,NeutralToneMapping as Pa,AgXToneMapping as vd,ACESFilmicToneMapping as bd,NoToneMapping as _d,PCFSoftShadowMap$1 as HC,BasicNodeLibrary as GC,WebGLRenderTarget as Vs,DepthTexture as Dv,NearestFilter as wd,LoopRepeat as qC,LoopOnce as Lm,AnimationMixer as jm,CompressedTexture as XC,FrontSide as yo,Camera as QC,Frustum as Bv,AudioListener as YC,PositionalAudio as KC,AudioLoader as Dm,EventDispatcher as Bm,BackSide as xd,MeshDepthMaterial as ZC,CustomBlending as JC,MaxEquation as eP,AmbientLight as tP,HemisphereLight as iP,AlwaysStencilFunc as sP,GreaterEqualStencilFunc as nP,NotEqualStencilFunc as oP,GreaterStencilFunc as rP,LessEqualStencilFunc as aP,EqualStencilFunc as lP,LessStencilFunc as cP,NeverStencilFunc as Fv,InvertStencilOp as hP,DecrementWrapStencilOp as dP,IncrementWrapStencilOp as uP,DecrementStencilOp as pP,IncrementStencilOp as mP,ReplaceStencilOp as gP,ZeroStencilOp as fP,KeepStencilOp as yP,RawShaderMaterial as Uv,GLSL3 as vP,AlwaysDepth as bP,GreaterEqualDepth as _P,GreaterDepth as wP,LessEqualDepth as xP,LessDepth as SP,NotEqualDepth as CP,EqualDepth as PP,BatchedMesh as zv,MeshPhysicalMaterial as Fm,LinearFilter as Sd,UnsignedByteType as OP,RingGeometry as kP,Line3 as MP,AdditiveBlending as Nv,BoxHelper as RP,SpotLight as TP,DirectionalLightHelper as EP,CameraHelper as AP,LOD as IP,Triangle as LP,NormalBlending as jP,ReinhardToneMapping as Um,LinearToneMapping as zm,HalfFloatType as Nm,VideoTexture as DP,CubeTexture as BP,CompressedCubeTexture as FP,EquirectangularRefractionMapping as UP,VectorKeyframeTrack as zP,QuaternionKeyframeTrack as NP,Audio as WP,ShaderLib as Cd,UniformsUtils as Wv,MirroredRepeatWrapping as Vv,MeshNormalMaterial as VP,AudioContext as $P,PMREMGenerator$1 as HP}from"./three-DuDKwKB8.min.js";import{createLoaders as Wm,getRaycastMesh as $v,LODsManager as Oa,NEEDLE_progressive as Xe,addDracoAndKTX2Loaders as GP,configureLoader as qP,setKTX2TranscoderLocation as XP,setDracoDecoderLocation as QP}from"./gltf-progressive-Q-uNWnqA.min.js";import{GroundedSkybox as ka,Font as YP,TextGeometry as KP,FontLoader as ZP,GLTFLoader as Tn,TransformControlsGizmo as Hv,EXRLoader as Pd,RGBELoader as Vm,Stats as JP,nodeFrame as eO,OrbitControls as Gv,PositionalAudioHelper as tO,HorizontalBlurShader as iO,VerticalBlurShader as sO,GLTFExporter as qv,strToU8 as Xv,zipSync as nO,XRControllerModelFactory as oO,XRHandMeshModel as rO,Line2 as aO,LineGeometry as lO,LineMaterial as cO,KTX2Loader as hO,TransformControls as dO,InteractiveGroup as uO,HTMLMesh as pO,VertexNormalsHelper as mO,OBJLoader as $m,FBXLoader as Qv,mergeVertices as gO}from"./three-examples-DaDLBuy6.min.js";import{fetchProfile as fO,MotionController as yO,$70d766613f57b014$export$2e2bcd8739ae039 as Yv,ByteBuffer as vO,v5 as Kv,md5 as Zv,SIZE_PREFIX_LENGTH as Jv,Builder as Hm,createNoise4D as bO,Matrix4 as Gm,BatchedParticleRenderer as _O,ParticleSystem as wO,RenderMode as En,ConstantColor as xO,Vector4 as SO,ConstantValue as CO,TrailParticle as eb,WorkerBase as PO,MeshBVH as OO}from"./vendor-BlSxe9JJ.min.js";import{__webpack_exports__default as Re,__webpack_exports__Text as tb,__webpack_exports__Block as ib,__webpack_exports__update as kO,SimpleStateBehavior as MO,__webpack_exports__Inline as qm,__webpack_exports__FontLibrary as sb,ThreeMeshUI as nb}from"./three-mesh-ui-B3p3gyUz.min.js";import{EffectAttribute as RO}from"./postprocessing-xYQWCHFu.min.js";const Xm=new Map;function Xt(n=(e=>(e=globalThis.location)==null?void 0:e.hostname)()){if(Xm.has(n))return Xm.get(n);const e=/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|localhost/.test(n);return Xm.set(n,e),e===!0}function ob(){return window.location.hostname.includes("glitch.me")}const TO='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 160 187.74"><defs><linearGradient id="a" x1="89.64" y1="184.81" x2="90.48" y2="21.85" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#62d399"/><stop offset=".51" stop-color="#acd842"/><stop offset=".9" stop-color="#d7db0a"/></linearGradient><linearGradient id="b" x1="69.68" y1="178.9" x2="68.08" y2="16.77" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#0ba398"/><stop offset=".5" stop-color="#4ca352"/><stop offset="1" stop-color="#76a30a"/></linearGradient><linearGradient id="c" x1="36.6" y1="152.17" x2="34.7" y2="84.19" gradientUnits="userSpaceOnUse"><stop offset=".19" stop-color="#36a382"/><stop offset=".54" stop-color="#49a459"/><stop offset="1" stop-color="#76a30b"/></linearGradient><linearGradient id="d" x1="15.82" y1="153.24" x2="18" y2="90.86" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#267880"/><stop offset=".51" stop-color="#457a5c"/><stop offset="1" stop-color="#717516"/></linearGradient><linearGradient id="e" x1="135.08" y1="135.43" x2="148.93" y2="63.47" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#b0d939"/><stop offset="1" stop-color="#eadb04"/></linearGradient><linearGradient id="f" x1="-4163.25" y1="2285.12" x2="-4160.81" y2="2215.34" gradientTransform="rotate(20 4088.49 13316.712)" gradientUnits="userSpaceOnUse"><stop offset=".17" stop-color="#74af52"/><stop offset=".48" stop-color="#99be32"/><stop offset="1" stop-color="#c0c40a"/></linearGradient><symbol id="g" viewBox="0 0 160 187.74"><path style="fill:url(#a)" d="M79.32 36.98v150.76L95 174.54l6.59-156.31-22.27 18.75z"/><path style="fill:url(#b)" d="M79.32 36.98 57.05 18.23l6.59 156.31 15.68 13.2V36.98z"/><path style="fill:url(#c)" d="m25.19 104.83 8.63 49.04 12.5-14.95-2.46-56.42-18.67 22.33z"/><path style="fill:url(#d)" d="M25.19 104.83 0 90.24l16.97 53.86 16.85 9.77-8.63-49.04z"/><path style="fill:#9c3" d="M43.86 82.5 18.69 67.98 0 90.24l25.18 14.59L43.86 82.5z"/><path style="fill:url(#e)" d="m134.82 78.69-9.97 56.5 15.58-9.04L160 64.1l-25.18 14.59z"/><path style="fill:url(#f)" d="m134.82 78.69-18.68-22.33-2.86 65 11.57 13.83 9.97-56.5z"/><path style="fill:#ffe113" d="m160 64.1-18.69-22.26-25.17 14.52 18.67 22.33L160 64.1z"/><path style="fill:#f3e600" d="M101.59 18.23 79.32 0 57.05 18.23l22.27 18.75 22.27-18.75z"/></symbol></defs><use width="160" height="187.74" xlink:href="#g"/></svg>',EO=btoa(TO),AO="data:image/svg+xml;base64,"+EO,rb=AO,IO=`<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'> <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" version="1.1" viewBox="0 0 1014 282" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m665.95 132.73v44.88l-10.56-8.4c-0.8-0.64-1.2-1.44-1.2-2.4v-32.4c0-6.48-4.12-9.72-12.36-9.72-2.16 0-4.18 0.4-6.06 1.2s-3.54 1.8-4.98 3-2.56 2.5-3.36 3.9-1.2 2.7-1.2 3.9v40.92l-10.68-8.4c-0.72-0.64-1.08-1.44-1.08-2.4v-53.76l10.92 8.52c0.32 0.24 0.56 0.44 0.72 0.6s0.36 0.32 0.6 0.48c0.96-1.2 2.14-2.28 3.54-3.24s2.92-1.76 4.56-2.4 3.34-1.14 5.1-1.5 3.44-0.54 5.04-0.54c1.44 0 2.92 0.04 4.44 0.12s2.84 0.28 3.96 0.6c4.56 1.12 7.8 3.12 9.72 6s2.88 6.56 2.88 11.04z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m732.38 146.05c0 0.88 0.02 1.5 0.06 1.86s-0.02 0.98-0.18 1.86h-7.08c-2.08 0-4.44-0.02-7.08-0.06s-5.36-0.06-8.16-0.06h-22.08c0 2.88 0.56 5.36 1.68 7.44s2.6 3.8 4.44 5.16 3.94 2.36 6.3 3 4.74 0.96 7.14 0.96c3.04 0 5.9-0.76 8.58-2.28s4.94-3.52 6.78-6c0.64 0.56 1.54 1.48 2.7 2.76s2.94 3.2 5.34 5.76c-2.8 3.36-6.22 6.02-10.26 7.98s-8.42 2.94-13.14 2.94-8.92-0.64-12.84-1.92-7.32-3.24-10.2-5.88-5.12-5.98-6.72-10.02-2.4-8.82-2.4-14.34c0-4.96 0.66-9.42 1.98-13.38s3.22-7.32 5.7-10.08 5.44-4.9 8.88-6.42 7.32-2.28 11.64-2.28c5.76 0 10.52 0.88 14.28 2.64s6.72 4.16 8.88 7.2 3.66 6.54 4.5 10.5 1.26 8.18 1.26 12.66zm-29.4-22.8c-2.16 0.16-4.16 0.72-6 1.68s-3.42 2.2-4.74 3.72-2.36 3.28-3.12 5.28-1.14 4.12-1.14 6.36h33.12c0-2-0.22-4.06-0.66-6.18s-1.3-4.02-2.58-5.7-3.1-3.02-5.46-4.02-5.5-1.38-9.42-1.14z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m795.93 146.05c0 0.88 0.02 1.5 0.06 1.86s-0.02 0.98-0.18 1.86h-7.08c-2.08 0-4.44-0.02-7.08-0.06s-5.36-0.06-8.16-0.06h-22.08c0 2.88 0.56 5.36 1.68 7.44s2.6 3.8 4.44 5.16 3.94 2.36 6.3 3 4.74 0.96 7.14 0.96c3.04 0 5.9-0.76 8.58-2.28s4.94-3.52 6.78-6c0.64 0.56 1.54 1.48 2.7 2.76s2.94 3.2 5.34 5.76c-2.8 3.36-6.22 6.02-10.26 7.98s-8.42 2.94-13.14 2.94-8.92-0.64-12.84-1.92-7.32-3.24-10.2-5.88-5.12-5.98-6.72-10.02-2.4-8.82-2.4-14.34c0-4.96 0.66-9.42 1.98-13.38s3.22-7.32 5.7-10.08 5.44-4.9 8.88-6.42 7.32-2.28 11.64-2.28c5.76 0 10.52 0.88 14.28 2.64s6.72 4.16 8.88 7.2 3.66 6.54 4.5 10.5 1.26 8.18 1.26 12.66zm-29.4-22.8c-2.16 0.16-4.16 0.72-6 1.68s-3.42 2.2-4.74 3.72-2.36 3.28-3.12 5.28-1.14 4.12-1.14 6.36h33.12c0-2-0.22-4.06-0.66-6.18s-1.3-4.02-2.58-5.7-3.1-3.02-5.46-4.02-5.5-1.38-9.42-1.14z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m858.57 97.21c0.64 0.48 0.96 1.16 0.96 2.04v74.88c-0.08 1.04-0.12 2.12-0.12 3.24-1.84-1.52-3.56-2.92-5.16-4.2-1.36-1.12-2.66-2.18-3.9-3.18s-2.06-1.66-2.46-1.98c-1.76 2.48-4.26 4.44-7.5 5.88s-7.02 2.16-11.34 2.16c-3.84 0-7.4-0.7-10.68-2.1s-6.14-3.44-8.58-6.12-4.34-5.94-5.7-9.78-2.04-8.16-2.04-12.96c0-4.32 0.78-8.34 2.34-12.06s3.6-6.92 6.12-9.6 5.38-4.78 8.58-6.3 6.48-2.28 9.84-2.28c2.56 0 4.82 0.22 6.78 0.66s3.68 1.06 5.16 1.86 2.78 1.74 3.9 2.82 2.16 2.22 3.12 3.42v-35.04l10.68 8.64zm-27.96 67.92c3.6 0 6.52-0.68 8.76-2.04s3.98-3.06 5.22-5.1 2.1-4.22 2.58-6.54 0.72-4.44 0.72-6.36v-1.2c0-1.12-0.22-2.7-0.66-4.74s-1.28-4.06-2.52-6.06-3-3.7-5.28-5.1-5.22-2.02-8.82-1.86c-3.44 0-6.26 0.74-8.46 2.22s-3.96 3.26-5.28 5.34-2.24 4.2-2.76 6.36-0.78 3.92-0.78 5.28c0 1.84 0.24 3.92 0.72 6.24s1.36 4.48 2.64 6.48 3.04 3.68 5.28 5.04 5.12 2.04 8.64 2.04z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m882.81 97.09c0.64 0.48 0.96 1.12 0.96 1.92l-0.12 41.04v37.08l-10.56-8.4c-0.72-0.64-1.08-1.44-1.08-2.4v-77.88l10.8 8.64z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m950.36 146.05c0 0.88 0.02 1.5 0.06 1.86s-0.02 0.98-0.18 1.86h-7.08c-2.08 0-4.44-0.02-7.08-0.06s-5.36-0.06-8.16-0.06h-22.08c0 2.88 0.56 5.36 1.68 7.44s2.6 3.8 4.44 5.16 3.94 2.36 6.3 3 4.74 0.96 7.14 0.96c3.04 0 5.9-0.76 8.58-2.28s4.94-3.52 6.78-6c0.64 0.56 1.54 1.48 2.7 2.76s2.94 3.2 5.34 5.76c-2.8 3.36-6.22 6.02-10.26 7.98s-8.42 2.94-13.14 2.94-8.92-0.64-12.84-1.92-7.32-3.24-10.2-5.88-5.12-5.98-6.72-10.02-2.4-8.82-2.4-14.34c0-4.96 0.66-9.42 1.98-13.38s3.22-7.32 5.7-10.08 5.44-4.9 8.88-6.42 7.32-2.28 11.64-2.28c5.76 0 10.52 0.88 14.28 2.64s6.72 4.16 8.88 7.2 3.66 6.54 4.5 10.5 1.26 8.18 1.26 12.66zm-29.4-22.8c-2.16 0.16-4.16 0.72-6 1.68s-3.42 2.2-4.74 3.72-2.36 3.28-3.12 5.28-1.14 4.12-1.14 6.36h33.12c0-2-0.22-4.06-0.66-6.18s-1.3-4.02-2.58-5.7-3.1-3.02-5.46-4.02-5.5-1.38-9.42-1.14z" fill-rule="nonzero"/> </g> <g transform="matrix(1.8559 0 0 .7642 45.348 36.475)"> <g transform="translate(2.7114)"> <path d="m3.935 173.02c-0.331 0-0.497-0.402-0.497-1.207v-51.002c0-0.738 0.138-1.107 0.414-1.107h1.781c0.277 0 0.415 0.335 0.415 1.006v5.935c0 0.336 0.027 0.553 0.083 0.654 0.055 0.101 0.151-0.017 0.289-0.352 0.912-1.744 1.754-3.236 2.527-4.477 0.773-1.24 1.554-2.179 2.341-2.816s1.65-0.956 2.588-0.956c1.685 0 3.011 0.922 3.977 2.766 0.967 1.845 1.602 3.84 1.905 5.986 0.056 0.268 0.139 0.369 0.249 0.302s0.221-0.235 0.331-0.503c0.939-1.811 1.802-3.353 2.589-4.628 0.787-1.274 1.581-2.246 2.382-2.917s1.671-1.006 2.61-1.006c2.016 0 3.569 1.392 4.66 4.175 1.09 2.783 1.636 6.421 1.636 10.915v37.925c0 0.871-0.18 1.307-0.539 1.307h-1.739c-0.138 0-0.249-0.1-0.332-0.301-0.083-0.202-0.124-0.503-0.124-0.906v-36.315c0-3.555-0.338-6.321-1.015-8.3-0.676-1.978-1.76-2.967-3.251-2.967-0.884 0-1.726 0.386-2.527 1.157s-1.519 1.727-2.154 2.867-1.201 2.213-1.699 3.219c-0.248 0.469-0.421 0.905-0.517 1.308-0.097 0.402-0.145 0.972-0.145 1.71v37.221c0 0.871-0.166 1.307-0.497 1.307h-1.74c-0.166 0-0.29-0.1-0.373-0.301-0.083-0.202-0.124-0.503-0.124-0.906v-36.315c0-3.555-0.332-6.321-0.994-8.3-0.663-1.978-1.754-2.967-3.273-2.967-1.242 0-2.375 0.704-3.396 2.112-1.022 1.409-2.223 3.555-3.604 6.439v39.031c0 0.805-0.18 1.207-0.539 1.207h-1.698z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m53.642 166.28c-1.077 2.549-2.237 4.477-3.479 5.785-1.243 1.307-2.61 1.961-4.101 1.961-2.154 0-3.853-1.324-5.095-3.973-1.243-2.649-1.864-6.187-1.864-10.613 0-3.488 0.4-6.489 1.201-9.004s1.988-4.51 3.562-5.985c1.574-1.476 3.521-2.414 5.841-2.817l3.686-0.704c0.221-0.067 0.394-0.218 0.518-0.453 0.124-0.234 0.187-0.587 0.187-1.056v-2.917c0-3.89-0.504-6.975-1.512-9.255s-2.354-3.42-4.039-3.42c-1.298 0-2.472 0.72-3.521 2.162s-2.002 3.572-2.858 6.388c-0.083 0.268-0.159 0.453-0.228 0.554-0.069 0.1-0.172 0.083-0.311-0.051l-1.698-1.71c-0.083-0.134-0.138-0.285-0.166-0.453-0.027-0.167 0.014-0.452 0.125-0.855 0.856-3.353 2.009-6.052 3.459-8.098 1.449-2.045 3.224-3.068 5.322-3.068 1.74 0 3.211 0.687 4.412 2.062s2.112 3.37 2.734 5.986c0.621 2.615 0.932 5.7 0.932 9.255v35.712c0 0.536-0.035 0.888-0.104 1.056s-0.2 0.251-0.393 0.251h-1.533c-0.166 0-0.29-0.117-0.373-0.352-0.083-0.234-0.124-0.553-0.124-0.955l-0.083-5.231c-0.055-0.939-0.221-1.006-0.497-0.202zm0.456-19.314c0-1.14-0.194-1.643-0.58-1.509l-3.107 0.603c-1.436 0.202-2.686 0.638-3.749 1.308-1.063 0.671-1.953 1.543-2.671 2.616s-1.257 2.33-1.616 3.772-0.538 3.102-0.538 4.98c0 3.152 0.455 5.616 1.367 7.393 0.911 1.778 2.14 2.666 3.686 2.666 0.939 0 1.85-0.419 2.734-1.257s1.671-1.895 2.361-3.169c0.663-1.408 1.181-2.85 1.553-4.326 0.373-1.475 0.56-2.883 0.56-4.225v-8.852z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m79.034 173.02c-0.166 0-0.297-0.117-0.394-0.352-0.096-0.234-0.145-0.553-0.145-0.955v-4.628c0-0.536-0.041-0.838-0.124-0.905s-0.207 0.1-0.373 0.503c-0.276 0.67-0.69 1.593-1.242 2.766-0.553 1.174-1.271 2.23-2.154 3.169-0.884 0.939-1.961 1.408-3.231 1.408-1.74 0-3.314-0.989-4.722-2.967-1.409-1.979-2.534-4.963-3.376-8.953-0.843-3.991-1.264-8.937-1.264-14.838 0-5.701 0.415-10.68 1.243-14.939s1.988-7.595 3.479-10.009c1.492-2.415 3.204-3.622 5.137-3.622 1.436 0 2.616 0.57 3.541 1.71 0.926 1.14 1.719 2.381 2.382 3.722 0.249 0.47 0.414 0.637 0.497 0.503s0.125-0.536 0.125-1.207v-23.841c0-0.805 0.151-1.208 0.455-1.208h1.864c0.276 0 0.414 0.369 0.414 1.107v72.128c0 0.537-0.041 0.905-0.124 1.107-0.083 0.201-0.235 0.301-0.455 0.301h-1.533zm-0.621-42.049c-0.939-2.213-1.885-3.94-2.838-5.181s-2.009-1.861-3.169-1.861c-1.463 0-2.768 0.889-3.914 2.666s-2.044 4.376-2.693 7.796-0.973 7.578-0.973 12.474c0 5.097 0.338 9.272 1.015 12.524 0.676 3.253 1.567 5.651 2.672 7.193 1.104 1.543 2.305 2.314 3.603 2.314 1.188 0 2.258-0.704 3.211-2.113 0.952-1.408 1.705-3.118 2.257-5.13s0.829-3.957 0.829-5.835v-24.847z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m89.514 149.38c0 3.42 0.345 6.606 1.035 9.557 0.691 2.951 1.609 5.315 2.755 7.092s2.437 2.666 3.873 2.666c1.519 0 2.837-0.738 3.956-2.213 1.118-1.476 2.064-3.655 2.837-6.539 0.083-0.336 0.166-0.52 0.249-0.554 0.083-0.033 0.179 0.017 0.29 0.151l1.408 1.912c0.221 0.268 0.235 0.67 0.041 1.207-0.69 2.548-1.47 4.661-2.34 6.337-0.87 1.677-1.857 2.935-2.962 3.773-1.104 0.838-2.319 1.257-3.645 1.257-2.043 0-3.838-1.14-5.385-3.42-1.546-2.28-2.761-5.482-3.645-9.607-0.884-4.124-1.325-8.836-1.325-14.134 0-5.901 0.455-10.931 1.367-15.089 0.911-4.158 2.14-7.377 3.686-9.658 1.547-2.28 3.3-3.42 5.261-3.42 1.988 0 3.714 1.073 5.178 3.219 1.463 2.146 2.595 5.231 3.396 9.255s1.201 8.886 1.201 14.587c0 0.469-0.02 0.939-0.062 1.408-0.041 0.469-0.214 0.704-0.517 0.704h-16.362c-0.083 0-0.152 0.151-0.207 0.453-0.056 0.302-0.083 0.654-0.083 1.056zm13.752-6.237c0.304 0 0.497-0.1 0.58-0.302 0.083-0.201 0.124-0.57 0.124-1.106 0-3.219-0.283-6.187-0.849-8.903s-1.367-4.896-2.402-6.539c-1.036-1.643-2.272-2.464-3.708-2.464-1.629 0-2.996 0.955-4.101 2.867-1.104 1.911-1.94 4.342-2.506 7.293s-0.849 6.002-0.849 9.154h13.711z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m148.54 119.7c0.165 0 0.283 0.117 0.352 0.352s0.076 0.52 0.02 0.855l-6.254 50.902c-0.028 0.47-0.104 0.788-0.228 0.956s-0.297 0.251-0.518 0.251h-1.615c-0.442 0-0.718-0.402-0.829-1.207l-5.26-40.138c-0.111-0.604-0.201-0.905-0.27-0.905s-0.131 0.301-0.186 0.905l-5.012 40.138c-0.028 0.47-0.097 0.788-0.207 0.956-0.111 0.168-0.277 0.251-0.497 0.251h-1.74c-0.442 0-0.718-0.402-0.829-1.207l-6.503-50.801c-0.055-0.403-0.048-0.721 0.021-0.956s0.2-0.352 0.393-0.352h1.823c0.166 0 0.297 0.067 0.393 0.201 0.097 0.134 0.159 0.403 0.187 0.805l5.302 41.848c0.083 0.671 0.179 0.989 0.29 0.956 0.11-0.034 0.207-0.386 0.29-1.056l5.219-41.949c0.055-0.268 0.124-0.47 0.207-0.604s0.193-0.201 0.331-0.201h1.533c0.138 0 0.262 0.067 0.373 0.201 0.11 0.134 0.179 0.403 0.207 0.805l5.468 41.848c0.083 0.671 0.179 0.989 0.29 0.956 0.11-0.034 0.207-0.386 0.29-1.056l5.053-41.849c0.055-0.335 0.138-0.57 0.249-0.704 0.11-0.134 0.234-0.201 0.373-0.201h1.284z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m156.49 171.51c0 0.604-0.042 1.006-0.125 1.208-0.082 0.201-0.262 0.301-0.538 0.301h-1.533c-0.221 0-0.366-0.083-0.435-0.251s-0.103-0.486-0.103-0.956v-50.902c0-0.805 0.152-1.207 0.456-1.207h1.822c0.304 0 0.456 0.402 0.456 1.207v50.6zm0.165-63.979c0 1.207-0.207 1.811-0.621 1.811h-1.905c-0.221 0-0.366-0.135-0.435-0.403s-0.104-0.67-0.104-1.207v-7.847c0-1.006 0.18-1.509 0.539-1.509h1.988c0.359 0 0.538 0.47 0.538 1.409v7.746z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m168.3 124.83c-0.221 0-0.331 0.269-0.331 0.805v33.801c0 3.42 0.221 5.667 0.663 6.74 0.441 1.073 1.09 1.609 1.946 1.609h3.024c0.138 0 0.242 0.084 0.311 0.252 0.069 0.167 0.103 0.419 0.103 0.754v2.716c0 0.537-0.138 0.906-0.414 1.107-0.248 0.067-0.614 0.134-1.098 0.201-0.483 0.067-0.959 0.118-1.429 0.151-0.469 0.034-0.828 0.05-1.077 0.05-1.712 0-2.934-0.955-3.665-2.867-0.732-1.911-1.098-5.013-1.098-9.305v-35.108c0-0.604-0.124-0.906-0.373-0.906h-3.521c-0.248 0-0.373-0.268-0.373-0.804v-3.521c0-0.537 0.111-0.805 0.332-0.805h3.686c0.166 0 0.263-0.268 0.29-0.805l0.415-16.095c0-0.805 0.124-1.207 0.372-1.207h1.492c0.303 0 0.455 0.436 0.455 1.307v15.995c0 0.537 0.097 0.805 0.29 0.805h5.468c0.221 0 0.331 0.268 0.331 0.805v3.521c0 0.536-0.124 0.804-0.373 0.804h-5.426z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m179.4 173.02c-0.331 0-0.497-0.402-0.497-1.207v-72.329c0-0.738 0.138-1.107 0.414-1.107h1.782c0.276 0 0.414 0.336 0.414 1.006v27.162c0 0.335 0.034 0.536 0.103 0.603s0.159-0.033 0.27-0.302c0.994-1.81 1.898-3.319 2.713-4.526 0.814-1.208 1.629-2.113 2.444-2.717 0.814-0.603 1.691-0.905 2.63-0.905 2.182 0 3.839 1.375 4.971 4.125 1.132 2.749 1.698 6.404 1.698 10.965v37.925c0 0.871-0.166 1.307-0.497 1.307h-1.74c-0.165 0-0.29-0.1-0.373-0.301-0.082-0.202-0.124-0.503-0.124-0.906v-36.315c0-3.555-0.366-6.321-1.097-8.3-0.732-1.978-1.899-2.967-3.501-2.967-0.883 0-1.705 0.318-2.464 0.956-0.76 0.637-1.526 1.576-2.299 2.816-0.773 1.241-1.643 2.834-2.61 4.779v39.031c0 0.805-0.179 1.207-0.538 1.207h-1.699z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> </g> <g transform="matrix(.80638 0 0 .80638 452.53 65.421)" fill-rule="nonzero"> <path d="m79.32 36.98v150.76l15.68-13.2 6.59-156.31-22.27 18.75z" fill="url(#f)"/> <path d="m79.32 36.98-22.27-18.75 6.59 156.31 15.68 13.2v-150.76z" fill="url(#e)"/> <path d="m25.19 104.83 8.63 49.04 12.5-14.95-2.46-56.42-18.67 22.33z" fill="url(#d)"/> <path d="m25.19 104.83-25.19-14.59 16.97 53.86 16.85 9.77-8.63-49.04z" fill="url(#c)"/> <path d="M43.86,82.5L18.69,67.98L0,90.24L25.18,104.83L43.86,82.5Z" fill="#9c3"/> <path d="m134.82 78.69-9.97 56.5 15.58-9.04 19.57-62.05-25.18 14.59z" fill="url(#b)"/> <path d="m134.82 78.69-18.68-22.33-2.86 65 11.57 13.83 9.97-56.5z" fill="url(#a)"/> <path d="m160 64.1-18.69-22.26-25.17 14.52 18.67 22.33 25.19-14.59z" fill="#ffe113"/> <path d="M101.59,18.23L79.32,0L57.05,18.23L79.32,36.98L101.59,18.23Z" fill="#f3e600"/> </g> <defs> <linearGradient id="f" x2="1" gradientTransform="matrix(.84 -162.96 162.96 .84 89.64 184.81)" gradientUnits="userSpaceOnUse"><stop stop-color="#62d399" offset="0"/><stop stop-color="#acd842" offset=".51"/><stop stop-color="#d7db0a" offset=".9"/><stop stop-color="#d7db0a" offset="1"/></linearGradient> <linearGradient id="e" x2="1" gradientTransform="matrix(-1.6,-162.13,162.13,-1.6,69.68,178.9)" gradientUnits="userSpaceOnUse"><stop stop-color="#0ba398" offset="0"/><stop stop-color="#4ca352" offset=".5"/><stop stop-color="#76a30a" offset="1"/></linearGradient> <linearGradient id="d" x2="1" gradientTransform="matrix(-1.9,-67.98,67.98,-1.9,36.6,152.17)" gradientUnits="userSpaceOnUse"><stop stop-color="#36a382" offset="0"/><stop stop-color="#36a382" offset=".19"/><stop stop-color="#49a459" offset=".54"/><stop stop-color="#76a30b" offset="1"/></linearGradient> <linearGradient id="c" x2="1" gradientTransform="matrix(2.18,-62.38,62.38,2.18,15.82,153.24)" gradientUnits="userSpaceOnUse"><stop stop-color="#267880" offset="0"/><stop stop-color="#457a5c" offset=".51"/><stop stop-color="#717516" offset="1"/></linearGradient> <linearGradient id="b" x2="1" gradientTransform="matrix(13.85,-71.96,71.96,13.85,135.08,135.43)" gradientUnits="userSpaceOnUse"><stop stop-color="#b0d939" offset="0"/><stop stop-color="#eadb04" offset="1"/></linearGradient> <linearGradient id="a" x2="1" gradientTransform="matrix(26.159 -64.737 64.737 26.159 107.42 128.14)" gradientUnits="userSpaceOnUse"><stop stop-color="#74af52" offset="0"/><stop stop-color="#74af52" offset=".17"/><stop stop-color="#99be32" offset=".48"/><stop stop-color="#c0c40a" offset="1"/></linearGradient> </defs> </svg>`;btoa(IO);const LO='<svg viewBox="0 0 509 154" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2"><path d="M665.95 132.73v44.88l-10.56-8.4c-.8-.64-1.2-1.44-1.2-2.4v-32.4c0-6.48-4.12-9.72-12.36-9.72-2.16 0-4.18.4-6.06 1.2-1.88.8-3.54 1.8-4.98 3-1.44 1.2-2.56 2.5-3.36 3.9-.8 1.4-1.2 2.7-1.2 3.9v40.92l-10.68-8.4c-.72-.64-1.08-1.44-1.08-2.4v-53.76l10.92 8.52c.32.24.56.44.72.6.16.16.36.32.6.48.96-1.2 2.14-2.28 3.54-3.24 1.4-.96 2.92-1.76 4.56-2.4 1.64-.64 3.34-1.14 5.1-1.5 1.76-.36 3.44-.54 5.04-.54 1.44 0 2.92.04 4.44.12 1.52.08 2.84.28 3.96.6 4.56 1.12 7.8 3.12 9.72 6 1.92 2.88 2.88 6.56 2.88 11.04ZM732.38 146.05c0 .88.02 1.5.06 1.86.04.36-.02.98-.18 1.86h-7.08c-2.08 0-4.44-.02-7.08-.06-2.64-.04-5.36-.06-8.16-.06h-22.08c0 2.88.56 5.36 1.68 7.44 1.12 2.08 2.6 3.8 4.44 5.16 1.84 1.36 3.94 2.36 6.3 3 2.36.64 4.74.96 7.14.96 3.04 0 5.9-.76 8.58-2.28 2.68-1.52 4.94-3.52 6.78-6 .64.56 1.54 1.48 2.7 2.76 1.16 1.28 2.94 3.2 5.34 5.76-2.8 3.36-6.22 6.02-10.26 7.98-4.04 1.96-8.42 2.94-13.14 2.94-4.72 0-8.92-.64-12.84-1.92-3.92-1.28-7.32-3.24-10.2-5.88-2.88-2.64-5.12-5.98-6.72-10.02-1.6-4.04-2.4-8.82-2.4-14.34 0-4.96.66-9.42 1.98-13.38 1.32-3.96 3.22-7.32 5.7-10.08s5.44-4.9 8.88-6.42c3.44-1.52 7.32-2.28 11.64-2.28 5.76 0 10.52.88 14.28 2.64 3.76 1.76 6.72 4.16 8.88 7.2 2.16 3.04 3.66 6.54 4.5 10.5.84 3.96 1.26 8.18 1.26 12.66Zm-29.4-22.8c-2.16.16-4.16.72-6 1.68-1.84.96-3.42 2.2-4.74 3.72-1.32 1.52-2.36 3.28-3.12 5.28-.76 2-1.14 4.12-1.14 6.36h33.12c0-2-.22-4.06-.66-6.18-.44-2.12-1.3-4.02-2.58-5.7-1.28-1.68-3.1-3.02-5.46-4.02-2.36-1-5.5-1.38-9.42-1.14ZM795.93 146.05c0 .88.02 1.5.06 1.86.04.36-.02.98-.18 1.86h-7.08c-2.08 0-4.44-.02-7.08-.06-2.64-.04-5.36-.06-8.16-.06h-22.08c0 2.88.56 5.36 1.68 7.44 1.12 2.08 2.6 3.8 4.44 5.16 1.84 1.36 3.94 2.36 6.3 3 2.36.64 4.74.96 7.14.96 3.04 0 5.9-.76 8.58-2.28 2.68-1.52 4.94-3.52 6.78-6 .64.56 1.54 1.48 2.7 2.76 1.16 1.28 2.94 3.2 5.34 5.76-2.8 3.36-6.22 6.02-10.26 7.98-4.04 1.96-8.42 2.94-13.14 2.94-4.72 0-8.92-.64-12.84-1.92-3.92-1.28-7.32-3.24-10.2-5.88-2.88-2.64-5.12-5.98-6.72-10.02-1.6-4.04-2.4-8.82-2.4-14.34 0-4.96.66-9.42 1.98-13.38 1.32-3.96 3.22-7.32 5.7-10.08s5.44-4.9 8.88-6.42c3.44-1.52 7.32-2.28 11.64-2.28 5.76 0 10.52.88 14.28 2.64 3.76 1.76 6.72 4.16 8.88 7.2 2.16 3.04 3.66 6.54 4.5 10.5.84 3.96 1.26 8.18 1.26 12.66Zm-29.4-22.8c-2.16.16-4.16.72-6 1.68-1.84.96-3.42 2.2-4.74 3.72-1.32 1.52-2.36 3.28-3.12 5.28-.76 2-1.14 4.12-1.14 6.36h33.12c0-2-.22-4.06-.66-6.18-.44-2.12-1.3-4.02-2.58-5.7-1.28-1.68-3.1-3.02-5.46-4.02-2.36-1-5.5-1.38-9.42-1.14ZM858.57 97.21c.64.48.96 1.16.96 2.04v74.88c-.08 1.04-.12 2.12-.12 3.24-1.84-1.52-3.56-2.92-5.16-4.2-1.36-1.12-2.66-2.18-3.9-3.18-1.24-1-2.06-1.66-2.46-1.98-1.76 2.48-4.26 4.44-7.5 5.88-3.24 1.44-7.02 2.16-11.34 2.16-3.84 0-7.4-.7-10.68-2.1-3.28-1.4-6.14-3.44-8.58-6.12-2.44-2.68-4.34-5.94-5.7-9.78-1.36-3.84-2.04-8.16-2.04-12.96 0-4.32.78-8.34 2.34-12.06 1.56-3.72 3.6-6.92 6.12-9.6 2.52-2.68 5.38-4.78 8.58-6.3 3.2-1.52 6.48-2.28 9.84-2.28 2.56 0 4.82.22 6.78.66 1.96.44 3.68 1.06 5.16 1.86s2.78 1.74 3.9 2.82a35.92 35.92 0 0 1 3.12 3.42V88.57l10.68 8.64Zm-27.96 67.92c3.6 0 6.52-.68 8.76-2.04 2.24-1.36 3.98-3.06 5.22-5.1a20.5 20.5 0 0 0 2.58-6.54c.48-2.32.72-4.44.72-6.36v-1.2c0-1.12-.22-2.7-.66-4.74-.44-2.04-1.28-4.06-2.52-6.06s-3-3.7-5.28-5.1c-2.28-1.4-5.22-2.02-8.82-1.86-3.44 0-6.26.74-8.46 2.22-2.2 1.48-3.96 3.26-5.28 5.34-1.32 2.08-2.24 4.2-2.76 6.36-.52 2.16-.78 3.92-.78 5.28 0 1.84.24 3.92.72 6.24.48 2.32 1.36 4.48 2.64 6.48s3.04 3.68 5.28 5.04c2.24 1.36 5.12 2.04 8.64 2.04ZM882.81 97.09c.64.48.96 1.12.96 1.92l-.12 41.04v37.08l-10.56-8.4c-.72-.64-1.08-1.44-1.08-2.4V88.45l10.8 8.64ZM950.36 146.05c0 .88.02 1.5.06 1.86.04.36-.02.98-.18 1.86h-7.08c-2.08 0-4.44-.02-7.08-.06-2.64-.04-5.36-.06-8.16-.06h-22.08c0 2.88.56 5.36 1.68 7.44 1.12 2.08 2.6 3.8 4.44 5.16 1.84 1.36 3.94 2.36 6.3 3 2.36.64 4.74.96 7.14.96 3.04 0 5.9-.76 8.58-2.28 2.68-1.52 4.94-3.52 6.78-6 .64.56 1.54 1.48 2.7 2.76 1.16 1.28 2.94 3.2 5.34 5.76-2.8 3.36-6.22 6.02-10.26 7.98-4.04 1.96-8.42 2.94-13.14 2.94-4.72 0-8.92-.64-12.84-1.92-3.92-1.28-7.32-3.24-10.2-5.88-2.88-2.64-5.12-5.98-6.72-10.02-1.6-4.04-2.4-8.82-2.4-14.34 0-4.96.66-9.42 1.98-13.38 1.32-3.96 3.22-7.32 5.7-10.08s5.44-4.9 8.88-6.42c3.44-1.52 7.32-2.28 11.64-2.28 5.76 0 10.52.88 14.28 2.64 3.76 1.76 6.72 4.16 8.88 7.2 2.16 3.04 3.66 6.54 4.5 10.5.84 3.96 1.26 8.18 1.26 12.66Zm-29.4-22.8c-2.16.16-4.16.72-6 1.68-1.84.96-3.42 2.2-4.74 3.72-1.32 1.52-2.36 3.28-3.12 5.28-.76 2-1.14 4.12-1.14 6.36h33.12c0-2-.22-4.06-.66-6.18-.44-2.12-1.3-4.02-2.58-5.7-1.28-1.68-3.1-3.02-5.46-4.02-2.36-1-5.5-1.38-9.42-1.14Z" style="fill-rule:nonzero" transform="translate(-452.406 -63.709) scale(1.00797)"/><path d="M79.32 36.98v150.76L95 174.54l6.59-156.31-22.27 18.75Z" style="fill:url(#a);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M79.32 36.98 57.05 18.23l6.59 156.31 15.68 13.2V36.98Z" style="fill:url(#b);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m25.19 104.83 8.63 49.04 12.5-14.95-2.46-56.42-18.67 22.33Z" style="fill:url(#c);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M25.19 104.83 0 90.24l16.97 53.86 16.85 9.77-8.63-49.04Z" style="fill:url(#d);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M43.86 82.5 18.69 67.98 0 90.24l25.18 14.59L43.86 82.5Z" style="fill:#9c3;fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m134.82 78.69-9.97 56.5 15.58-9.04L160 64.1l-25.18 14.59Z" style="fill:url(#e);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m134.82 78.69-18.68-22.33-2.86 65 11.57 13.83 9.97-56.5Z" style="fill:url(#f);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m160 64.1-18.69-22.26-25.17 14.52 18.67 22.33L160 64.1Z" style="fill:#ffe113;fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M101.59 18.23 79.32 0 57.05 18.23l22.27 18.75 22.27-18.75Z" style="fill:#f3e600;fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><defs><linearGradient id="a" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(.84 -162.96 162.96 .84 89.64 184.81)"><stop offset="0" style="stop-color:#62d399;stop-opacity:1"/><stop offset=".51" style="stop-color:#acd842;stop-opacity:1"/><stop offset=".9" style="stop-color:#d7db0a;stop-opacity:1"/><stop offset="1" style="stop-color:#d7db0a;stop-opacity:1"/></linearGradient><linearGradient id="b" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-90.565 123.412 54.953) scale(162.14)"><stop offset="0" style="stop-color:#0ba398;stop-opacity:1"/><stop offset=".5" style="stop-color:#4ca352;stop-opacity:1"/><stop offset="1" style="stop-color:#76a30a;stop-opacity:1"/></linearGradient><linearGradient id="c" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="scale(-68) rotate(88.4 .881 -1.396)"><stop offset="0" style="stop-color:#36a382;stop-opacity:1"/><stop offset=".19" style="stop-color:#36a382;stop-opacity:1"/><stop offset=".54" style="stop-color:#49a459;stop-opacity:1"/><stop offset="1" style="stop-color:#76a30b;stop-opacity:1"/></linearGradient><linearGradient id="d" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-88 87.255 68.431) scale(62.42)"><stop offset="0" style="stop-color:#267880;stop-opacity:1"/><stop offset=".51" style="stop-color:#457a5c;stop-opacity:1"/><stop offset="1" style="stop-color:#717516;stop-opacity:1"/></linearGradient><linearGradient id="e" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-79.1 149.53 -14.065) scale(73.28)"><stop offset="0" style="stop-color:#b0d939;stop-opacity:1"/><stop offset="1" style="stop-color:#eadb04;stop-opacity:1"/></linearGradient><linearGradient id="f" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-67.997 148.705 -15.558) scale(69.8226)"><stop offset="0" style="stop-color:#74af52;stop-opacity:1"/><stop offset=".17" style="stop-color:#74af52;stop-opacity:1"/><stop offset=".48" style="stop-color:#99be32;stop-opacity:1"/><stop offset="1" style="stop-color:#c0c40a;stop-opacity:1"/></linearGradient></defs></svg>',jO=btoa(LO),DO="data:image/svg+xml;charset=utf-8;base64,"+jO,BO=DO,ab=typeof window!==void 0?window.location.search.includes("debugcontext"):!1;var me=(n=>(n.ContextRegistered="ContextRegistered",n.ContextCreationStart="ContextCreationStart",n.ContextCreated="ContextCreated",n.ContextFirstFrameRendered="ContextFirstFrameRendered",n.ContextDestroying="ContextDestroying",n.ContextDestroyed="ContextDestroyed",n.MissingCamera="MissingCamera",n.ContextClearing="ContextClearing",n.ContextCleared="ContextCleared",n))(me||{});class pe{static get Current(){return globalThis["NeedleEngine.Context.Current"]}static set Current(e){globalThis["NeedleEngine.Context.Current"]=e}static get All(){return this.Registered}static register(e){this.Registered.indexOf(e)===-1&&(ab&&console.warn("Registering context"),this.Registered.push(e),this.dispatchCallback("ContextRegistered",e))}static unregister(e){const t=this.Registered.indexOf(e);t!==-1&&(ab&&console.warn("Unregistering context"),this.Registered.splice(t,1))}static registerCallback(e,t){this._callbacks[e]||(this._callbacks[e]=[]),this._callbacks[e].push(t)}static unregisterCallback(e,t){if(!this._callbacks[e])return;const s=this._callbacks[e].indexOf(t);s!==-1&&this._callbacks[e].splice(s,1)}static dispatchCallback(e,t,s){if(!this._callbacks[e])return!0;const o={event:e,context:t};if(s)for(const l in s)o[l]=s[l];const r=new Array;return this._callbacks[e].forEach(l=>{const c=l(o);c instanceof Promise&&r.push(c)}),Promise.all(r)}static addContextCreatedCallback(e){this.registerCallback("ContextCreated",e)}static addContextDestroyedCallback(e){this.registerCallback("ContextDestroyed",e)}}a(pe,"Registered",[]),a(pe,"_callbacks",{});const lb=()=>n=>n;function FO(n){return lb()(n)}function UO(){return!!C("debug")}class Oi{constructor(e,t){a(this,"_factory"),a(this,"_cache",[]),a(this,"_maxSize"),a(this,"_index",0),this._factory=e,this._maxSize=t}get(){const e=this._index%this._maxSize;return this._index++,this._cache.length<=e&&(this._cache[e]=this._factory()),this._cache[e]}}let yr=!1;const Qm=new Array;typeof window<"u"&&setTimeout(()=>{if(yr){const n={},e=new URL(window.location.href),t=new URL(e);t.searchParams.append("console","");const s=t.toString().replace(/=$|=(?=&)/g,"");for(const r of Qm){const l=new URL(e);l.searchParams.append(r,""),n[r]=l.toString().replace(/=$|=(?=&)/g,"")}console.log(`\u{1F335} ?help: Debug Options for Needle Engine.
1
+ var RC=Object.defineProperty,Mv=n=>{throw TypeError(n)},TC=(n,e,t)=>e in n?RC(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,a=(n,e,t)=>TC(n,typeof e!="symbol"?e+"":e,t),Mm=(n,e,t)=>e.has(n)||Mv("Cannot "+t),ge=(n,e,t)=>(Mm(n,e,"read from private field"),t?t.call(n):e.get(n)),Fs=(n,e,t)=>e.has(n)?Mv("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),Us=(n,e,t,s)=>(Mm(n,e,"write to private field"),s?s.call(n,t):e.set(n,t),t),ud=(n,e,t)=>(Mm(n,e,"access private method"),t);import{Vector2 as re,Vector3 as S,Vector4 as fe,Quaternion as V,PlaneGeometry as zs,WebGLRenderer as gr,PerspectiveCamera as we,OrthographicCamera as pd,Scene as xi,Mesh as G,Texture as je,Uniform$1 as Qi,Color as oe,ShaderMaterial as Ns,Box3 as Si,ShadowMaterial as Rv,Euler as Bt,MeshStandardMaterial as bt,Box3Helper as EC,GridHelper as Rm,Object3D as E,Material as Pe,Matrix3 as Tv,Matrix4 as se,Layers as po,Ray as mo,MathUtils as Pn,AxesHelper as Ci,MeshBasicMaterial as Me,DoubleSide as Pi,BufferGeometry as Ws,Group as go,CylinderGeometry as Ev,SphereGeometry as md,BoxGeometry as xa,SpriteMaterial as AC,Sprite as IC,Shape as LC,ExtrudeGeometry as jC,Fog as Av,DirectionalLight as Tm,PointLight as Em,EdgesGeometry as DC,LineSegments as Iv,LineBasicMaterial as Lv,Line as Hl,BufferAttribute as _t,Raycaster as gd,Sphere as fd,ArrayCamera as BC,Plane as fr,SkinnedMesh as On,InterleavedBufferAttribute as jv,Skeleton as FC,Bone as UC,Source as zC,WebGLCubeRenderTarget as NC,CubeCamera as WC,AnimationClip as fo,FileLoader as Am,TextureLoader as Sa,PropertyBinding as Ca,LinearSRGBColorSpace as kn,ShaderChunk as qt,UniformsLib as VC,DataTexture as Im,RGBAFormat as yd,EquirectangularReflectionMapping as Mn,SRGBColorSpace as Rn,Clock as $C,NeutralToneMapping as Pa,AgXToneMapping as vd,ACESFilmicToneMapping as bd,NoToneMapping as _d,PCFSoftShadowMap$1 as HC,BasicNodeLibrary as GC,WebGLRenderTarget as Vs,DepthTexture as Dv,NearestFilter as wd,LoopRepeat as qC,LoopOnce as Lm,AnimationMixer as jm,CompressedTexture as XC,FrontSide as yo,Camera as QC,Frustum as Bv,AudioListener as YC,PositionalAudio as KC,AudioLoader as Dm,EventDispatcher as Bm,BackSide as xd,MeshDepthMaterial as ZC,CustomBlending as JC,MaxEquation as eP,AmbientLight as tP,HemisphereLight as iP,AlwaysStencilFunc as sP,GreaterEqualStencilFunc as nP,NotEqualStencilFunc as oP,GreaterStencilFunc as rP,LessEqualStencilFunc as aP,EqualStencilFunc as lP,LessStencilFunc as cP,NeverStencilFunc as Fv,InvertStencilOp as hP,DecrementWrapStencilOp as dP,IncrementWrapStencilOp as uP,DecrementStencilOp as pP,IncrementStencilOp as mP,ReplaceStencilOp as gP,ZeroStencilOp as fP,KeepStencilOp as yP,RawShaderMaterial as Uv,GLSL3 as vP,AlwaysDepth as bP,GreaterEqualDepth as _P,GreaterDepth as wP,LessEqualDepth as xP,LessDepth as SP,NotEqualDepth as CP,EqualDepth as PP,BatchedMesh as zv,MeshPhysicalMaterial as Fm,LinearFilter as Sd,UnsignedByteType as OP,RingGeometry as kP,Line3 as MP,AdditiveBlending as Nv,BoxHelper as RP,SpotLight as TP,DirectionalLightHelper as EP,CameraHelper as AP,LOD as IP,Triangle as LP,NormalBlending as jP,ReinhardToneMapping as Um,LinearToneMapping as zm,HalfFloatType as Nm,VideoTexture as DP,CubeTexture as BP,CompressedCubeTexture as FP,EquirectangularRefractionMapping as UP,VectorKeyframeTrack as zP,QuaternionKeyframeTrack as NP,Audio as WP,ShaderLib as Cd,UniformsUtils as Wv,MirroredRepeatWrapping as Vv,MeshNormalMaterial as VP,AudioContext as $P,PMREMGenerator$1 as HP}from"./three-DuDKwKB8.min.js";import{createLoaders as Wm,getRaycastMesh as $v,LODsManager as Oa,NEEDLE_progressive as Xe,addDracoAndKTX2Loaders as GP,configureLoader as qP,setKTX2TranscoderLocation as XP,setDracoDecoderLocation as QP}from"./gltf-progressive-MgWOszRl.min.js";import{GroundedSkybox as ka,Font as YP,TextGeometry as KP,FontLoader as ZP,GLTFLoader as Tn,TransformControlsGizmo as Hv,EXRLoader as Pd,RGBELoader as Vm,Stats as JP,nodeFrame as eO,OrbitControls as Gv,PositionalAudioHelper as tO,HorizontalBlurShader as iO,VerticalBlurShader as sO,GLTFExporter as qv,strToU8 as Xv,zipSync as nO,XRControllerModelFactory as oO,XRHandMeshModel as rO,Line2 as aO,LineGeometry as lO,LineMaterial as cO,KTX2Loader as hO,TransformControls as dO,InteractiveGroup as uO,HTMLMesh as pO,VertexNormalsHelper as mO,OBJLoader as $m,FBXLoader as Qv,mergeVertices as gO}from"./three-examples-DaDLBuy6.min.js";import{fetchProfile as fO,MotionController as yO,$70d766613f57b014$export$2e2bcd8739ae039 as Yv,ByteBuffer as vO,v5 as Kv,md5 as Zv,SIZE_PREFIX_LENGTH as Jv,Builder as Hm,createNoise4D as bO,Matrix4 as Gm,BatchedParticleRenderer as _O,ParticleSystem as wO,RenderMode as En,ConstantColor as xO,Vector4 as SO,ConstantValue as CO,TrailParticle as eb,WorkerBase as PO,MeshBVH as OO}from"./vendor-BlSxe9JJ.min.js";import{__webpack_exports__default as Re,__webpack_exports__Text as tb,__webpack_exports__Block as ib,__webpack_exports__update as kO,SimpleStateBehavior as MO,__webpack_exports__Inline as qm,__webpack_exports__FontLibrary as sb,ThreeMeshUI as nb}from"./three-mesh-ui-B3p3gyUz.min.js";import{EffectAttribute as RO}from"./postprocessing-xYQWCHFu.min.js";const Xm=new Map;function Xt(n=(e=>(e=globalThis.location)==null?void 0:e.hostname)()){if(Xm.has(n))return Xm.get(n);const e=/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|localhost/.test(n);return Xm.set(n,e),e===!0}function ob(){return window.location.hostname.includes("glitch.me")}const TO='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 160 187.74"><defs><linearGradient id="a" x1="89.64" y1="184.81" x2="90.48" y2="21.85" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#62d399"/><stop offset=".51" stop-color="#acd842"/><stop offset=".9" stop-color="#d7db0a"/></linearGradient><linearGradient id="b" x1="69.68" y1="178.9" x2="68.08" y2="16.77" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#0ba398"/><stop offset=".5" stop-color="#4ca352"/><stop offset="1" stop-color="#76a30a"/></linearGradient><linearGradient id="c" x1="36.6" y1="152.17" x2="34.7" y2="84.19" gradientUnits="userSpaceOnUse"><stop offset=".19" stop-color="#36a382"/><stop offset=".54" stop-color="#49a459"/><stop offset="1" stop-color="#76a30b"/></linearGradient><linearGradient id="d" x1="15.82" y1="153.24" x2="18" y2="90.86" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#267880"/><stop offset=".51" stop-color="#457a5c"/><stop offset="1" stop-color="#717516"/></linearGradient><linearGradient id="e" x1="135.08" y1="135.43" x2="148.93" y2="63.47" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#b0d939"/><stop offset="1" stop-color="#eadb04"/></linearGradient><linearGradient id="f" x1="-4163.25" y1="2285.12" x2="-4160.81" y2="2215.34" gradientTransform="rotate(20 4088.49 13316.712)" gradientUnits="userSpaceOnUse"><stop offset=".17" stop-color="#74af52"/><stop offset=".48" stop-color="#99be32"/><stop offset="1" stop-color="#c0c40a"/></linearGradient><symbol id="g" viewBox="0 0 160 187.74"><path style="fill:url(#a)" d="M79.32 36.98v150.76L95 174.54l6.59-156.31-22.27 18.75z"/><path style="fill:url(#b)" d="M79.32 36.98 57.05 18.23l6.59 156.31 15.68 13.2V36.98z"/><path style="fill:url(#c)" d="m25.19 104.83 8.63 49.04 12.5-14.95-2.46-56.42-18.67 22.33z"/><path style="fill:url(#d)" d="M25.19 104.83 0 90.24l16.97 53.86 16.85 9.77-8.63-49.04z"/><path style="fill:#9c3" d="M43.86 82.5 18.69 67.98 0 90.24l25.18 14.59L43.86 82.5z"/><path style="fill:url(#e)" d="m134.82 78.69-9.97 56.5 15.58-9.04L160 64.1l-25.18 14.59z"/><path style="fill:url(#f)" d="m134.82 78.69-18.68-22.33-2.86 65 11.57 13.83 9.97-56.5z"/><path style="fill:#ffe113" d="m160 64.1-18.69-22.26-25.17 14.52 18.67 22.33L160 64.1z"/><path style="fill:#f3e600" d="M101.59 18.23 79.32 0 57.05 18.23l22.27 18.75 22.27-18.75z"/></symbol></defs><use width="160" height="187.74" xlink:href="#g"/></svg>',EO=btoa(TO),AO="data:image/svg+xml;base64,"+EO,rb=AO,IO=`<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'> <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" version="1.1" viewBox="0 0 1014 282" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m665.95 132.73v44.88l-10.56-8.4c-0.8-0.64-1.2-1.44-1.2-2.4v-32.4c0-6.48-4.12-9.72-12.36-9.72-2.16 0-4.18 0.4-6.06 1.2s-3.54 1.8-4.98 3-2.56 2.5-3.36 3.9-1.2 2.7-1.2 3.9v40.92l-10.68-8.4c-0.72-0.64-1.08-1.44-1.08-2.4v-53.76l10.92 8.52c0.32 0.24 0.56 0.44 0.72 0.6s0.36 0.32 0.6 0.48c0.96-1.2 2.14-2.28 3.54-3.24s2.92-1.76 4.56-2.4 3.34-1.14 5.1-1.5 3.44-0.54 5.04-0.54c1.44 0 2.92 0.04 4.44 0.12s2.84 0.28 3.96 0.6c4.56 1.12 7.8 3.12 9.72 6s2.88 6.56 2.88 11.04z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m732.38 146.05c0 0.88 0.02 1.5 0.06 1.86s-0.02 0.98-0.18 1.86h-7.08c-2.08 0-4.44-0.02-7.08-0.06s-5.36-0.06-8.16-0.06h-22.08c0 2.88 0.56 5.36 1.68 7.44s2.6 3.8 4.44 5.16 3.94 2.36 6.3 3 4.74 0.96 7.14 0.96c3.04 0 5.9-0.76 8.58-2.28s4.94-3.52 6.78-6c0.64 0.56 1.54 1.48 2.7 2.76s2.94 3.2 5.34 5.76c-2.8 3.36-6.22 6.02-10.26 7.98s-8.42 2.94-13.14 2.94-8.92-0.64-12.84-1.92-7.32-3.24-10.2-5.88-5.12-5.98-6.72-10.02-2.4-8.82-2.4-14.34c0-4.96 0.66-9.42 1.98-13.38s3.22-7.32 5.7-10.08 5.44-4.9 8.88-6.42 7.32-2.28 11.64-2.28c5.76 0 10.52 0.88 14.28 2.64s6.72 4.16 8.88 7.2 3.66 6.54 4.5 10.5 1.26 8.18 1.26 12.66zm-29.4-22.8c-2.16 0.16-4.16 0.72-6 1.68s-3.42 2.2-4.74 3.72-2.36 3.28-3.12 5.28-1.14 4.12-1.14 6.36h33.12c0-2-0.22-4.06-0.66-6.18s-1.3-4.02-2.58-5.7-3.1-3.02-5.46-4.02-5.5-1.38-9.42-1.14z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m795.93 146.05c0 0.88 0.02 1.5 0.06 1.86s-0.02 0.98-0.18 1.86h-7.08c-2.08 0-4.44-0.02-7.08-0.06s-5.36-0.06-8.16-0.06h-22.08c0 2.88 0.56 5.36 1.68 7.44s2.6 3.8 4.44 5.16 3.94 2.36 6.3 3 4.74 0.96 7.14 0.96c3.04 0 5.9-0.76 8.58-2.28s4.94-3.52 6.78-6c0.64 0.56 1.54 1.48 2.7 2.76s2.94 3.2 5.34 5.76c-2.8 3.36-6.22 6.02-10.26 7.98s-8.42 2.94-13.14 2.94-8.92-0.64-12.84-1.92-7.32-3.24-10.2-5.88-5.12-5.98-6.72-10.02-2.4-8.82-2.4-14.34c0-4.96 0.66-9.42 1.98-13.38s3.22-7.32 5.7-10.08 5.44-4.9 8.88-6.42 7.32-2.28 11.64-2.28c5.76 0 10.52 0.88 14.28 2.64s6.72 4.16 8.88 7.2 3.66 6.54 4.5 10.5 1.26 8.18 1.26 12.66zm-29.4-22.8c-2.16 0.16-4.16 0.72-6 1.68s-3.42 2.2-4.74 3.72-2.36 3.28-3.12 5.28-1.14 4.12-1.14 6.36h33.12c0-2-0.22-4.06-0.66-6.18s-1.3-4.02-2.58-5.7-3.1-3.02-5.46-4.02-5.5-1.38-9.42-1.14z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m858.57 97.21c0.64 0.48 0.96 1.16 0.96 2.04v74.88c-0.08 1.04-0.12 2.12-0.12 3.24-1.84-1.52-3.56-2.92-5.16-4.2-1.36-1.12-2.66-2.18-3.9-3.18s-2.06-1.66-2.46-1.98c-1.76 2.48-4.26 4.44-7.5 5.88s-7.02 2.16-11.34 2.16c-3.84 0-7.4-0.7-10.68-2.1s-6.14-3.44-8.58-6.12-4.34-5.94-5.7-9.78-2.04-8.16-2.04-12.96c0-4.32 0.78-8.34 2.34-12.06s3.6-6.92 6.12-9.6 5.38-4.78 8.58-6.3 6.48-2.28 9.84-2.28c2.56 0 4.82 0.22 6.78 0.66s3.68 1.06 5.16 1.86 2.78 1.74 3.9 2.82 2.16 2.22 3.12 3.42v-35.04l10.68 8.64zm-27.96 67.92c3.6 0 6.52-0.68 8.76-2.04s3.98-3.06 5.22-5.1 2.1-4.22 2.58-6.54 0.72-4.44 0.72-6.36v-1.2c0-1.12-0.22-2.7-0.66-4.74s-1.28-4.06-2.52-6.06-3-3.7-5.28-5.1-5.22-2.02-8.82-1.86c-3.44 0-6.26 0.74-8.46 2.22s-3.96 3.26-5.28 5.34-2.24 4.2-2.76 6.36-0.78 3.92-0.78 5.28c0 1.84 0.24 3.92 0.72 6.24s1.36 4.48 2.64 6.48 3.04 3.68 5.28 5.04 5.12 2.04 8.64 2.04z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m882.81 97.09c0.64 0.48 0.96 1.12 0.96 1.92l-0.12 41.04v37.08l-10.56-8.4c-0.72-0.64-1.08-1.44-1.08-2.4v-77.88l10.8 8.64z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m950.36 146.05c0 0.88 0.02 1.5 0.06 1.86s-0.02 0.98-0.18 1.86h-7.08c-2.08 0-4.44-0.02-7.08-0.06s-5.36-0.06-8.16-0.06h-22.08c0 2.88 0.56 5.36 1.68 7.44s2.6 3.8 4.44 5.16 3.94 2.36 6.3 3 4.74 0.96 7.14 0.96c3.04 0 5.9-0.76 8.58-2.28s4.94-3.52 6.78-6c0.64 0.56 1.54 1.48 2.7 2.76s2.94 3.2 5.34 5.76c-2.8 3.36-6.22 6.02-10.26 7.98s-8.42 2.94-13.14 2.94-8.92-0.64-12.84-1.92-7.32-3.24-10.2-5.88-5.12-5.98-6.72-10.02-2.4-8.82-2.4-14.34c0-4.96 0.66-9.42 1.98-13.38s3.22-7.32 5.7-10.08 5.44-4.9 8.88-6.42 7.32-2.28 11.64-2.28c5.76 0 10.52 0.88 14.28 2.64s6.72 4.16 8.88 7.2 3.66 6.54 4.5 10.5 1.26 8.18 1.26 12.66zm-29.4-22.8c-2.16 0.16-4.16 0.72-6 1.68s-3.42 2.2-4.74 3.72-2.36 3.28-3.12 5.28-1.14 4.12-1.14 6.36h33.12c0-2-0.22-4.06-0.66-6.18s-1.3-4.02-2.58-5.7-3.1-3.02-5.46-4.02-5.5-1.38-9.42-1.14z" fill-rule="nonzero"/> </g> <g transform="matrix(1.8559 0 0 .7642 45.348 36.475)"> <g transform="translate(2.7114)"> <path d="m3.935 173.02c-0.331 0-0.497-0.402-0.497-1.207v-51.002c0-0.738 0.138-1.107 0.414-1.107h1.781c0.277 0 0.415 0.335 0.415 1.006v5.935c0 0.336 0.027 0.553 0.083 0.654 0.055 0.101 0.151-0.017 0.289-0.352 0.912-1.744 1.754-3.236 2.527-4.477 0.773-1.24 1.554-2.179 2.341-2.816s1.65-0.956 2.588-0.956c1.685 0 3.011 0.922 3.977 2.766 0.967 1.845 1.602 3.84 1.905 5.986 0.056 0.268 0.139 0.369 0.249 0.302s0.221-0.235 0.331-0.503c0.939-1.811 1.802-3.353 2.589-4.628 0.787-1.274 1.581-2.246 2.382-2.917s1.671-1.006 2.61-1.006c2.016 0 3.569 1.392 4.66 4.175 1.09 2.783 1.636 6.421 1.636 10.915v37.925c0 0.871-0.18 1.307-0.539 1.307h-1.739c-0.138 0-0.249-0.1-0.332-0.301-0.083-0.202-0.124-0.503-0.124-0.906v-36.315c0-3.555-0.338-6.321-1.015-8.3-0.676-1.978-1.76-2.967-3.251-2.967-0.884 0-1.726 0.386-2.527 1.157s-1.519 1.727-2.154 2.867-1.201 2.213-1.699 3.219c-0.248 0.469-0.421 0.905-0.517 1.308-0.097 0.402-0.145 0.972-0.145 1.71v37.221c0 0.871-0.166 1.307-0.497 1.307h-1.74c-0.166 0-0.29-0.1-0.373-0.301-0.083-0.202-0.124-0.503-0.124-0.906v-36.315c0-3.555-0.332-6.321-0.994-8.3-0.663-1.978-1.754-2.967-3.273-2.967-1.242 0-2.375 0.704-3.396 2.112-1.022 1.409-2.223 3.555-3.604 6.439v39.031c0 0.805-0.18 1.207-0.539 1.207h-1.698z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m53.642 166.28c-1.077 2.549-2.237 4.477-3.479 5.785-1.243 1.307-2.61 1.961-4.101 1.961-2.154 0-3.853-1.324-5.095-3.973-1.243-2.649-1.864-6.187-1.864-10.613 0-3.488 0.4-6.489 1.201-9.004s1.988-4.51 3.562-5.985c1.574-1.476 3.521-2.414 5.841-2.817l3.686-0.704c0.221-0.067 0.394-0.218 0.518-0.453 0.124-0.234 0.187-0.587 0.187-1.056v-2.917c0-3.89-0.504-6.975-1.512-9.255s-2.354-3.42-4.039-3.42c-1.298 0-2.472 0.72-3.521 2.162s-2.002 3.572-2.858 6.388c-0.083 0.268-0.159 0.453-0.228 0.554-0.069 0.1-0.172 0.083-0.311-0.051l-1.698-1.71c-0.083-0.134-0.138-0.285-0.166-0.453-0.027-0.167 0.014-0.452 0.125-0.855 0.856-3.353 2.009-6.052 3.459-8.098 1.449-2.045 3.224-3.068 5.322-3.068 1.74 0 3.211 0.687 4.412 2.062s2.112 3.37 2.734 5.986c0.621 2.615 0.932 5.7 0.932 9.255v35.712c0 0.536-0.035 0.888-0.104 1.056s-0.2 0.251-0.393 0.251h-1.533c-0.166 0-0.29-0.117-0.373-0.352-0.083-0.234-0.124-0.553-0.124-0.955l-0.083-5.231c-0.055-0.939-0.221-1.006-0.497-0.202zm0.456-19.314c0-1.14-0.194-1.643-0.58-1.509l-3.107 0.603c-1.436 0.202-2.686 0.638-3.749 1.308-1.063 0.671-1.953 1.543-2.671 2.616s-1.257 2.33-1.616 3.772-0.538 3.102-0.538 4.98c0 3.152 0.455 5.616 1.367 7.393 0.911 1.778 2.14 2.666 3.686 2.666 0.939 0 1.85-0.419 2.734-1.257s1.671-1.895 2.361-3.169c0.663-1.408 1.181-2.85 1.553-4.326 0.373-1.475 0.56-2.883 0.56-4.225v-8.852z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m79.034 173.02c-0.166 0-0.297-0.117-0.394-0.352-0.096-0.234-0.145-0.553-0.145-0.955v-4.628c0-0.536-0.041-0.838-0.124-0.905s-0.207 0.1-0.373 0.503c-0.276 0.67-0.69 1.593-1.242 2.766-0.553 1.174-1.271 2.23-2.154 3.169-0.884 0.939-1.961 1.408-3.231 1.408-1.74 0-3.314-0.989-4.722-2.967-1.409-1.979-2.534-4.963-3.376-8.953-0.843-3.991-1.264-8.937-1.264-14.838 0-5.701 0.415-10.68 1.243-14.939s1.988-7.595 3.479-10.009c1.492-2.415 3.204-3.622 5.137-3.622 1.436 0 2.616 0.57 3.541 1.71 0.926 1.14 1.719 2.381 2.382 3.722 0.249 0.47 0.414 0.637 0.497 0.503s0.125-0.536 0.125-1.207v-23.841c0-0.805 0.151-1.208 0.455-1.208h1.864c0.276 0 0.414 0.369 0.414 1.107v72.128c0 0.537-0.041 0.905-0.124 1.107-0.083 0.201-0.235 0.301-0.455 0.301h-1.533zm-0.621-42.049c-0.939-2.213-1.885-3.94-2.838-5.181s-2.009-1.861-3.169-1.861c-1.463 0-2.768 0.889-3.914 2.666s-2.044 4.376-2.693 7.796-0.973 7.578-0.973 12.474c0 5.097 0.338 9.272 1.015 12.524 0.676 3.253 1.567 5.651 2.672 7.193 1.104 1.543 2.305 2.314 3.603 2.314 1.188 0 2.258-0.704 3.211-2.113 0.952-1.408 1.705-3.118 2.257-5.13s0.829-3.957 0.829-5.835v-24.847z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m89.514 149.38c0 3.42 0.345 6.606 1.035 9.557 0.691 2.951 1.609 5.315 2.755 7.092s2.437 2.666 3.873 2.666c1.519 0 2.837-0.738 3.956-2.213 1.118-1.476 2.064-3.655 2.837-6.539 0.083-0.336 0.166-0.52 0.249-0.554 0.083-0.033 0.179 0.017 0.29 0.151l1.408 1.912c0.221 0.268 0.235 0.67 0.041 1.207-0.69 2.548-1.47 4.661-2.34 6.337-0.87 1.677-1.857 2.935-2.962 3.773-1.104 0.838-2.319 1.257-3.645 1.257-2.043 0-3.838-1.14-5.385-3.42-1.546-2.28-2.761-5.482-3.645-9.607-0.884-4.124-1.325-8.836-1.325-14.134 0-5.901 0.455-10.931 1.367-15.089 0.911-4.158 2.14-7.377 3.686-9.658 1.547-2.28 3.3-3.42 5.261-3.42 1.988 0 3.714 1.073 5.178 3.219 1.463 2.146 2.595 5.231 3.396 9.255s1.201 8.886 1.201 14.587c0 0.469-0.02 0.939-0.062 1.408-0.041 0.469-0.214 0.704-0.517 0.704h-16.362c-0.083 0-0.152 0.151-0.207 0.453-0.056 0.302-0.083 0.654-0.083 1.056zm13.752-6.237c0.304 0 0.497-0.1 0.58-0.302 0.083-0.201 0.124-0.57 0.124-1.106 0-3.219-0.283-6.187-0.849-8.903s-1.367-4.896-2.402-6.539c-1.036-1.643-2.272-2.464-3.708-2.464-1.629 0-2.996 0.955-4.101 2.867-1.104 1.911-1.94 4.342-2.506 7.293s-0.849 6.002-0.849 9.154h13.711z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m148.54 119.7c0.165 0 0.283 0.117 0.352 0.352s0.076 0.52 0.02 0.855l-6.254 50.902c-0.028 0.47-0.104 0.788-0.228 0.956s-0.297 0.251-0.518 0.251h-1.615c-0.442 0-0.718-0.402-0.829-1.207l-5.26-40.138c-0.111-0.604-0.201-0.905-0.27-0.905s-0.131 0.301-0.186 0.905l-5.012 40.138c-0.028 0.47-0.097 0.788-0.207 0.956-0.111 0.168-0.277 0.251-0.497 0.251h-1.74c-0.442 0-0.718-0.402-0.829-1.207l-6.503-50.801c-0.055-0.403-0.048-0.721 0.021-0.956s0.2-0.352 0.393-0.352h1.823c0.166 0 0.297 0.067 0.393 0.201 0.097 0.134 0.159 0.403 0.187 0.805l5.302 41.848c0.083 0.671 0.179 0.989 0.29 0.956 0.11-0.034 0.207-0.386 0.29-1.056l5.219-41.949c0.055-0.268 0.124-0.47 0.207-0.604s0.193-0.201 0.331-0.201h1.533c0.138 0 0.262 0.067 0.373 0.201 0.11 0.134 0.179 0.403 0.207 0.805l5.468 41.848c0.083 0.671 0.179 0.989 0.29 0.956 0.11-0.034 0.207-0.386 0.29-1.056l5.053-41.849c0.055-0.335 0.138-0.57 0.249-0.704 0.11-0.134 0.234-0.201 0.373-0.201h1.284z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m156.49 171.51c0 0.604-0.042 1.006-0.125 1.208-0.082 0.201-0.262 0.301-0.538 0.301h-1.533c-0.221 0-0.366-0.083-0.435-0.251s-0.103-0.486-0.103-0.956v-50.902c0-0.805 0.152-1.207 0.456-1.207h1.822c0.304 0 0.456 0.402 0.456 1.207v50.6zm0.165-63.979c0 1.207-0.207 1.811-0.621 1.811h-1.905c-0.221 0-0.366-0.135-0.435-0.403s-0.104-0.67-0.104-1.207v-7.847c0-1.006 0.18-1.509 0.539-1.509h1.988c0.359 0 0.538 0.47 0.538 1.409v7.746z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m168.3 124.83c-0.221 0-0.331 0.269-0.331 0.805v33.801c0 3.42 0.221 5.667 0.663 6.74 0.441 1.073 1.09 1.609 1.946 1.609h3.024c0.138 0 0.242 0.084 0.311 0.252 0.069 0.167 0.103 0.419 0.103 0.754v2.716c0 0.537-0.138 0.906-0.414 1.107-0.248 0.067-0.614 0.134-1.098 0.201-0.483 0.067-0.959 0.118-1.429 0.151-0.469 0.034-0.828 0.05-1.077 0.05-1.712 0-2.934-0.955-3.665-2.867-0.732-1.911-1.098-5.013-1.098-9.305v-35.108c0-0.604-0.124-0.906-0.373-0.906h-3.521c-0.248 0-0.373-0.268-0.373-0.804v-3.521c0-0.537 0.111-0.805 0.332-0.805h3.686c0.166 0 0.263-0.268 0.29-0.805l0.415-16.095c0-0.805 0.124-1.207 0.372-1.207h1.492c0.303 0 0.455 0.436 0.455 1.307v15.995c0 0.537 0.097 0.805 0.29 0.805h5.468c0.221 0 0.331 0.268 0.331 0.805v3.521c0 0.536-0.124 0.804-0.373 0.804h-5.426z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m179.4 173.02c-0.331 0-0.497-0.402-0.497-1.207v-72.329c0-0.738 0.138-1.107 0.414-1.107h1.782c0.276 0 0.414 0.336 0.414 1.006v27.162c0 0.335 0.034 0.536 0.103 0.603s0.159-0.033 0.27-0.302c0.994-1.81 1.898-3.319 2.713-4.526 0.814-1.208 1.629-2.113 2.444-2.717 0.814-0.603 1.691-0.905 2.63-0.905 2.182 0 3.839 1.375 4.971 4.125 1.132 2.749 1.698 6.404 1.698 10.965v37.925c0 0.871-0.166 1.307-0.497 1.307h-1.74c-0.165 0-0.29-0.1-0.373-0.301-0.082-0.202-0.124-0.503-0.124-0.906v-36.315c0-3.555-0.366-6.321-1.097-8.3-0.732-1.978-1.899-2.967-3.501-2.967-0.883 0-1.705 0.318-2.464 0.956-0.76 0.637-1.526 1.576-2.299 2.816-0.773 1.241-1.643 2.834-2.61 4.779v39.031c0 0.805-0.179 1.207-0.538 1.207h-1.699z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> </g> <g transform="matrix(.80638 0 0 .80638 452.53 65.421)" fill-rule="nonzero"> <path d="m79.32 36.98v150.76l15.68-13.2 6.59-156.31-22.27 18.75z" fill="url(#f)"/> <path d="m79.32 36.98-22.27-18.75 6.59 156.31 15.68 13.2v-150.76z" fill="url(#e)"/> <path d="m25.19 104.83 8.63 49.04 12.5-14.95-2.46-56.42-18.67 22.33z" fill="url(#d)"/> <path d="m25.19 104.83-25.19-14.59 16.97 53.86 16.85 9.77-8.63-49.04z" fill="url(#c)"/> <path d="M43.86,82.5L18.69,67.98L0,90.24L25.18,104.83L43.86,82.5Z" fill="#9c3"/> <path d="m134.82 78.69-9.97 56.5 15.58-9.04 19.57-62.05-25.18 14.59z" fill="url(#b)"/> <path d="m134.82 78.69-18.68-22.33-2.86 65 11.57 13.83 9.97-56.5z" fill="url(#a)"/> <path d="m160 64.1-18.69-22.26-25.17 14.52 18.67 22.33 25.19-14.59z" fill="#ffe113"/> <path d="M101.59,18.23L79.32,0L57.05,18.23L79.32,36.98L101.59,18.23Z" fill="#f3e600"/> </g> <defs> <linearGradient id="f" x2="1" gradientTransform="matrix(.84 -162.96 162.96 .84 89.64 184.81)" gradientUnits="userSpaceOnUse"><stop stop-color="#62d399" offset="0"/><stop stop-color="#acd842" offset=".51"/><stop stop-color="#d7db0a" offset=".9"/><stop stop-color="#d7db0a" offset="1"/></linearGradient> <linearGradient id="e" x2="1" gradientTransform="matrix(-1.6,-162.13,162.13,-1.6,69.68,178.9)" gradientUnits="userSpaceOnUse"><stop stop-color="#0ba398" offset="0"/><stop stop-color="#4ca352" offset=".5"/><stop stop-color="#76a30a" offset="1"/></linearGradient> <linearGradient id="d" x2="1" gradientTransform="matrix(-1.9,-67.98,67.98,-1.9,36.6,152.17)" gradientUnits="userSpaceOnUse"><stop stop-color="#36a382" offset="0"/><stop stop-color="#36a382" offset=".19"/><stop stop-color="#49a459" offset=".54"/><stop stop-color="#76a30b" offset="1"/></linearGradient> <linearGradient id="c" x2="1" gradientTransform="matrix(2.18,-62.38,62.38,2.18,15.82,153.24)" gradientUnits="userSpaceOnUse"><stop stop-color="#267880" offset="0"/><stop stop-color="#457a5c" offset=".51"/><stop stop-color="#717516" offset="1"/></linearGradient> <linearGradient id="b" x2="1" gradientTransform="matrix(13.85,-71.96,71.96,13.85,135.08,135.43)" gradientUnits="userSpaceOnUse"><stop stop-color="#b0d939" offset="0"/><stop stop-color="#eadb04" offset="1"/></linearGradient> <linearGradient id="a" x2="1" gradientTransform="matrix(26.159 -64.737 64.737 26.159 107.42 128.14)" gradientUnits="userSpaceOnUse"><stop stop-color="#74af52" offset="0"/><stop stop-color="#74af52" offset=".17"/><stop stop-color="#99be32" offset=".48"/><stop stop-color="#c0c40a" offset="1"/></linearGradient> </defs> </svg>`;btoa(IO);const LO='<svg viewBox="0 0 509 154" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2"><path d="M665.95 132.73v44.88l-10.56-8.4c-.8-.64-1.2-1.44-1.2-2.4v-32.4c0-6.48-4.12-9.72-12.36-9.72-2.16 0-4.18.4-6.06 1.2-1.88.8-3.54 1.8-4.98 3-1.44 1.2-2.56 2.5-3.36 3.9-.8 1.4-1.2 2.7-1.2 3.9v40.92l-10.68-8.4c-.72-.64-1.08-1.44-1.08-2.4v-53.76l10.92 8.52c.32.24.56.44.72.6.16.16.36.32.6.48.96-1.2 2.14-2.28 3.54-3.24 1.4-.96 2.92-1.76 4.56-2.4 1.64-.64 3.34-1.14 5.1-1.5 1.76-.36 3.44-.54 5.04-.54 1.44 0 2.92.04 4.44.12 1.52.08 2.84.28 3.96.6 4.56 1.12 7.8 3.12 9.72 6 1.92 2.88 2.88 6.56 2.88 11.04ZM732.38 146.05c0 .88.02 1.5.06 1.86.04.36-.02.98-.18 1.86h-7.08c-2.08 0-4.44-.02-7.08-.06-2.64-.04-5.36-.06-8.16-.06h-22.08c0 2.88.56 5.36 1.68 7.44 1.12 2.08 2.6 3.8 4.44 5.16 1.84 1.36 3.94 2.36 6.3 3 2.36.64 4.74.96 7.14.96 3.04 0 5.9-.76 8.58-2.28 2.68-1.52 4.94-3.52 6.78-6 .64.56 1.54 1.48 2.7 2.76 1.16 1.28 2.94 3.2 5.34 5.76-2.8 3.36-6.22 6.02-10.26 7.98-4.04 1.96-8.42 2.94-13.14 2.94-4.72 0-8.92-.64-12.84-1.92-3.92-1.28-7.32-3.24-10.2-5.88-2.88-2.64-5.12-5.98-6.72-10.02-1.6-4.04-2.4-8.82-2.4-14.34 0-4.96.66-9.42 1.98-13.38 1.32-3.96 3.22-7.32 5.7-10.08s5.44-4.9 8.88-6.42c3.44-1.52 7.32-2.28 11.64-2.28 5.76 0 10.52.88 14.28 2.64 3.76 1.76 6.72 4.16 8.88 7.2 2.16 3.04 3.66 6.54 4.5 10.5.84 3.96 1.26 8.18 1.26 12.66Zm-29.4-22.8c-2.16.16-4.16.72-6 1.68-1.84.96-3.42 2.2-4.74 3.72-1.32 1.52-2.36 3.28-3.12 5.28-.76 2-1.14 4.12-1.14 6.36h33.12c0-2-.22-4.06-.66-6.18-.44-2.12-1.3-4.02-2.58-5.7-1.28-1.68-3.1-3.02-5.46-4.02-2.36-1-5.5-1.38-9.42-1.14ZM795.93 146.05c0 .88.02 1.5.06 1.86.04.36-.02.98-.18 1.86h-7.08c-2.08 0-4.44-.02-7.08-.06-2.64-.04-5.36-.06-8.16-.06h-22.08c0 2.88.56 5.36 1.68 7.44 1.12 2.08 2.6 3.8 4.44 5.16 1.84 1.36 3.94 2.36 6.3 3 2.36.64 4.74.96 7.14.96 3.04 0 5.9-.76 8.58-2.28 2.68-1.52 4.94-3.52 6.78-6 .64.56 1.54 1.48 2.7 2.76 1.16 1.28 2.94 3.2 5.34 5.76-2.8 3.36-6.22 6.02-10.26 7.98-4.04 1.96-8.42 2.94-13.14 2.94-4.72 0-8.92-.64-12.84-1.92-3.92-1.28-7.32-3.24-10.2-5.88-2.88-2.64-5.12-5.98-6.72-10.02-1.6-4.04-2.4-8.82-2.4-14.34 0-4.96.66-9.42 1.98-13.38 1.32-3.96 3.22-7.32 5.7-10.08s5.44-4.9 8.88-6.42c3.44-1.52 7.32-2.28 11.64-2.28 5.76 0 10.52.88 14.28 2.64 3.76 1.76 6.72 4.16 8.88 7.2 2.16 3.04 3.66 6.54 4.5 10.5.84 3.96 1.26 8.18 1.26 12.66Zm-29.4-22.8c-2.16.16-4.16.72-6 1.68-1.84.96-3.42 2.2-4.74 3.72-1.32 1.52-2.36 3.28-3.12 5.28-.76 2-1.14 4.12-1.14 6.36h33.12c0-2-.22-4.06-.66-6.18-.44-2.12-1.3-4.02-2.58-5.7-1.28-1.68-3.1-3.02-5.46-4.02-2.36-1-5.5-1.38-9.42-1.14ZM858.57 97.21c.64.48.96 1.16.96 2.04v74.88c-.08 1.04-.12 2.12-.12 3.24-1.84-1.52-3.56-2.92-5.16-4.2-1.36-1.12-2.66-2.18-3.9-3.18-1.24-1-2.06-1.66-2.46-1.98-1.76 2.48-4.26 4.44-7.5 5.88-3.24 1.44-7.02 2.16-11.34 2.16-3.84 0-7.4-.7-10.68-2.1-3.28-1.4-6.14-3.44-8.58-6.12-2.44-2.68-4.34-5.94-5.7-9.78-1.36-3.84-2.04-8.16-2.04-12.96 0-4.32.78-8.34 2.34-12.06 1.56-3.72 3.6-6.92 6.12-9.6 2.52-2.68 5.38-4.78 8.58-6.3 3.2-1.52 6.48-2.28 9.84-2.28 2.56 0 4.82.22 6.78.66 1.96.44 3.68 1.06 5.16 1.86s2.78 1.74 3.9 2.82a35.92 35.92 0 0 1 3.12 3.42V88.57l10.68 8.64Zm-27.96 67.92c3.6 0 6.52-.68 8.76-2.04 2.24-1.36 3.98-3.06 5.22-5.1a20.5 20.5 0 0 0 2.58-6.54c.48-2.32.72-4.44.72-6.36v-1.2c0-1.12-.22-2.7-.66-4.74-.44-2.04-1.28-4.06-2.52-6.06s-3-3.7-5.28-5.1c-2.28-1.4-5.22-2.02-8.82-1.86-3.44 0-6.26.74-8.46 2.22-2.2 1.48-3.96 3.26-5.28 5.34-1.32 2.08-2.24 4.2-2.76 6.36-.52 2.16-.78 3.92-.78 5.28 0 1.84.24 3.92.72 6.24.48 2.32 1.36 4.48 2.64 6.48s3.04 3.68 5.28 5.04c2.24 1.36 5.12 2.04 8.64 2.04ZM882.81 97.09c.64.48.96 1.12.96 1.92l-.12 41.04v37.08l-10.56-8.4c-.72-.64-1.08-1.44-1.08-2.4V88.45l10.8 8.64ZM950.36 146.05c0 .88.02 1.5.06 1.86.04.36-.02.98-.18 1.86h-7.08c-2.08 0-4.44-.02-7.08-.06-2.64-.04-5.36-.06-8.16-.06h-22.08c0 2.88.56 5.36 1.68 7.44 1.12 2.08 2.6 3.8 4.44 5.16 1.84 1.36 3.94 2.36 6.3 3 2.36.64 4.74.96 7.14.96 3.04 0 5.9-.76 8.58-2.28 2.68-1.52 4.94-3.52 6.78-6 .64.56 1.54 1.48 2.7 2.76 1.16 1.28 2.94 3.2 5.34 5.76-2.8 3.36-6.22 6.02-10.26 7.98-4.04 1.96-8.42 2.94-13.14 2.94-4.72 0-8.92-.64-12.84-1.92-3.92-1.28-7.32-3.24-10.2-5.88-2.88-2.64-5.12-5.98-6.72-10.02-1.6-4.04-2.4-8.82-2.4-14.34 0-4.96.66-9.42 1.98-13.38 1.32-3.96 3.22-7.32 5.7-10.08s5.44-4.9 8.88-6.42c3.44-1.52 7.32-2.28 11.64-2.28 5.76 0 10.52.88 14.28 2.64 3.76 1.76 6.72 4.16 8.88 7.2 2.16 3.04 3.66 6.54 4.5 10.5.84 3.96 1.26 8.18 1.26 12.66Zm-29.4-22.8c-2.16.16-4.16.72-6 1.68-1.84.96-3.42 2.2-4.74 3.72-1.32 1.52-2.36 3.28-3.12 5.28-.76 2-1.14 4.12-1.14 6.36h33.12c0-2-.22-4.06-.66-6.18-.44-2.12-1.3-4.02-2.58-5.7-1.28-1.68-3.1-3.02-5.46-4.02-2.36-1-5.5-1.38-9.42-1.14Z" style="fill-rule:nonzero" transform="translate(-452.406 -63.709) scale(1.00797)"/><path d="M79.32 36.98v150.76L95 174.54l6.59-156.31-22.27 18.75Z" style="fill:url(#a);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M79.32 36.98 57.05 18.23l6.59 156.31 15.68 13.2V36.98Z" style="fill:url(#b);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m25.19 104.83 8.63 49.04 12.5-14.95-2.46-56.42-18.67 22.33Z" style="fill:url(#c);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M25.19 104.83 0 90.24l16.97 53.86 16.85 9.77-8.63-49.04Z" style="fill:url(#d);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M43.86 82.5 18.69 67.98 0 90.24l25.18 14.59L43.86 82.5Z" style="fill:#9c3;fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m134.82 78.69-9.97 56.5 15.58-9.04L160 64.1l-25.18 14.59Z" style="fill:url(#e);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m134.82 78.69-18.68-22.33-2.86 65 11.57 13.83 9.97-56.5Z" style="fill:url(#f);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m160 64.1-18.69-22.26-25.17 14.52 18.67 22.33L160 64.1Z" style="fill:#ffe113;fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M101.59 18.23 79.32 0 57.05 18.23l22.27 18.75 22.27-18.75Z" style="fill:#f3e600;fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><defs><linearGradient id="a" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(.84 -162.96 162.96 .84 89.64 184.81)"><stop offset="0" style="stop-color:#62d399;stop-opacity:1"/><stop offset=".51" style="stop-color:#acd842;stop-opacity:1"/><stop offset=".9" style="stop-color:#d7db0a;stop-opacity:1"/><stop offset="1" style="stop-color:#d7db0a;stop-opacity:1"/></linearGradient><linearGradient id="b" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-90.565 123.412 54.953) scale(162.14)"><stop offset="0" style="stop-color:#0ba398;stop-opacity:1"/><stop offset=".5" style="stop-color:#4ca352;stop-opacity:1"/><stop offset="1" style="stop-color:#76a30a;stop-opacity:1"/></linearGradient><linearGradient id="c" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="scale(-68) rotate(88.4 .881 -1.396)"><stop offset="0" style="stop-color:#36a382;stop-opacity:1"/><stop offset=".19" style="stop-color:#36a382;stop-opacity:1"/><stop offset=".54" style="stop-color:#49a459;stop-opacity:1"/><stop offset="1" style="stop-color:#76a30b;stop-opacity:1"/></linearGradient><linearGradient id="d" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-88 87.255 68.431) scale(62.42)"><stop offset="0" style="stop-color:#267880;stop-opacity:1"/><stop offset=".51" style="stop-color:#457a5c;stop-opacity:1"/><stop offset="1" style="stop-color:#717516;stop-opacity:1"/></linearGradient><linearGradient id="e" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-79.1 149.53 -14.065) scale(73.28)"><stop offset="0" style="stop-color:#b0d939;stop-opacity:1"/><stop offset="1" style="stop-color:#eadb04;stop-opacity:1"/></linearGradient><linearGradient id="f" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-67.997 148.705 -15.558) scale(69.8226)"><stop offset="0" style="stop-color:#74af52;stop-opacity:1"/><stop offset=".17" style="stop-color:#74af52;stop-opacity:1"/><stop offset=".48" style="stop-color:#99be32;stop-opacity:1"/><stop offset="1" style="stop-color:#c0c40a;stop-opacity:1"/></linearGradient></defs></svg>',jO=btoa(LO),DO="data:image/svg+xml;charset=utf-8;base64,"+jO,BO=DO,ab=typeof window!==void 0?window.location.search.includes("debugcontext"):!1;var me=(n=>(n.ContextRegistered="ContextRegistered",n.ContextCreationStart="ContextCreationStart",n.ContextCreated="ContextCreated",n.ContextFirstFrameRendered="ContextFirstFrameRendered",n.ContextDestroying="ContextDestroying",n.ContextDestroyed="ContextDestroyed",n.MissingCamera="MissingCamera",n.ContextClearing="ContextClearing",n.ContextCleared="ContextCleared",n))(me||{});class pe{static get Current(){return globalThis["NeedleEngine.Context.Current"]}static set Current(e){globalThis["NeedleEngine.Context.Current"]=e}static get All(){return this.Registered}static register(e){this.Registered.indexOf(e)===-1&&(ab&&console.warn("Registering context"),this.Registered.push(e),this.dispatchCallback("ContextRegistered",e))}static unregister(e){const t=this.Registered.indexOf(e);t!==-1&&(ab&&console.warn("Unregistering context"),this.Registered.splice(t,1))}static registerCallback(e,t){this._callbacks[e]||(this._callbacks[e]=[]),this._callbacks[e].push(t)}static unregisterCallback(e,t){if(!this._callbacks[e])return;const s=this._callbacks[e].indexOf(t);s!==-1&&this._callbacks[e].splice(s,1)}static dispatchCallback(e,t,s){if(!this._callbacks[e])return!0;const o={event:e,context:t};if(s)for(const l in s)o[l]=s[l];const r=new Array;return this._callbacks[e].forEach(l=>{const c=l(o);c instanceof Promise&&r.push(c)}),Promise.all(r)}static addContextCreatedCallback(e){this.registerCallback("ContextCreated",e)}static addContextDestroyedCallback(e){this.registerCallback("ContextDestroyed",e)}}a(pe,"Registered",[]),a(pe,"_callbacks",{});const lb=()=>n=>n;function FO(n){return lb()(n)}function UO(){return!!C("debug")}class Oi{constructor(e,t){a(this,"_factory"),a(this,"_cache",[]),a(this,"_maxSize"),a(this,"_index",0),this._factory=e,this._maxSize=t}get(){const e=this._index%this._maxSize;return this._index++,this._cache.length<=e&&(this._cache[e]=this._factory()),this._cache[e]}}let yr=!1;const Qm=new Array;typeof window<"u"&&setTimeout(()=>{if(yr){const n={},e=new URL(window.location.href),t=new URL(e);t.searchParams.append("console","");const s=t.toString().replace(/=$|=(?=&)/g,"");for(const r of Qm){const l=new URL(e);l.searchParams.append(r,""),n[r]=l.toString().replace(/=$|=(?=&)/g,"")}console.log(`\u{1F335} ?help: Debug Options for Needle Engine.
2
2
  Append any of these parameters to the URL to enable specific debug options.
3
3
  Example: ${s} will show an onscreen console window.`);const o=yr===!0?"":` (containing "${yr}")`;console.group("Available URL parameters:"+o);for(const r of Object.keys(n).sort())typeof yr=="string"&&!r.toLowerCase().includes(yr.toLowerCase())||(console.groupCollapsed(r),console.log("Reload with this flag enabled:"),console.log(n[r]),console.groupEnd());console.groupEnd()}},100);function Gl(){var n;return new URLSearchParams((n=globalThis.location)==null?void 0:n.search)}function C(n){yr&&!Qm.includes(n)&&Qm.push(n);const e=Gl();if(e.has(n)){const t=e.get(n);if(t){const s=Number(t);return isNaN(s)?t:s}else return!0}return!1}yr=C("help");function zO(n,e){const t=Gl();t.has(n)?t.set(n,e):t.append(n,e),document.location.search=t.toString()}function ql(n,e,t=!0){const s=Gl();s.has(n)?e===null?s.delete(n):s.set(n,e):e!==null&&s.append(n,e),t?cb(n,s):Km(n,s)}function Ym(n,e,t){n.has(e)?n.set(e,t.toString()):n.append(e,t.toString())}function cb(n,e,t){window.history.pushState(t,n,"?"+e.toString())}function Km(n,e,t){window.history.replaceState(t,n,"?"+e.toString())}function NO(n){for(var e="",t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",s=t.length,o=0;o<n;o++)e+=t.charAt(Math.floor(Math.random()*s));return e}function WO(n,e){return Math.floor(Math.random()*(e-n+1))+n}const hb=["smol","tiny","giant","interesting","smart","bright","dull","extreme","beautiful","pretty","dark","epic","salty","silly","funny","lame","lazy","loud","lucky","mad","mean","mighty","mysterious","nasty","odd","old","powerful","quiet","rapid","scary","shiny","shy","silly","smooth","sour","spicy","stupid","sweet","tasty","terrible","ugly","unusual","vast","wet","wild","witty","wrong","zany","zealous","zippy","zombie","zorro"],db=["cat","dog","mouse","pig","cow","horse","sheep","chicken","duck","goat","panda","tiger","lion","elephant","monkey","bird","fish","snake","frog","turtle","hamster","penguin","kangaroo","whale","dolphin","crocodile","snail","ant","bee","beetle","butterfly","dragon","eagle","fish","giraffe","lizard","panda","penguin","rabbit","snake","spider","tiger","zebra"];function ub(){const n=hb[Math.floor(Math.random()*hb.length)],e=db[Math.floor(Math.random()*db.length)];return n+"_"+e}function pb(n){return n=n.replace(/[^a-z0-9áéíóúñü \.,_-]/gim,""),n.trim()}function Ma(n,e,t=!0,s=!1){var o;if(e==null)return null;if(e.userData&&e.userData.guid===n||e.guid==n)return e;if(s&&(o=e.userData)!=null&&o.components){for(const r of e.userData.components)if(r.guid===n)return r}if(t){if(e.scenes)for(const r in e.scenes){const l=e.scenes[r],c=Ma(n,l,t,s);if(c)return c}if(e.children)for(const r in e.children){const l=e.children[r],c=Ma(n,l,t,s);if(c)return c}}}function Xl(n,e){if(n!=null&&typeof n=="object"){let t;Array.isArray(n)?t=[]:(t=Object.create(n),Object.assign(t,n));for(const s of Object.keys(n)){const o=n[s];e&&!e(n,s,o)?t[s]=o:o?.clone!==void 0&&typeof o.clone=="function"?t[s]=o.clone():t[s]=Xl(o,e)}return t}return n}function $s(n){return new Promise((e,t)=>{setTimeout(e,n)})}function Ql(n,e){if(n<=0)return Promise.resolve();if(e||(e=pe.Current),!e)return Promise.reject("No context");const t=e.time.frameCount+n;return new Promise((s,o)=>{if(!e)return o("No context");const r=()=>{e.time.frameCount>=t&&(e.pre_update_callbacks.splice(e.pre_update_callbacks.indexOf(r),1),s())};e.pre_update_callbacks.push(r)})}const Od=C("debugresolveurl"),mb="rel:";function VO(n,e){return vo(n,e)}function vo(n,e){if(e===void 0)return Od&&console.warn("getPath: uri is undefined, returning uri",e),e;if(e.startsWith("./"))return e;if(e.startsWith("http"))return Od&&console.warn("getPath: uri is absolute, returning uri",e),e;if(n===void 0)return Od&&console.warn("getPath: source is undefined, returning uri",e),e;e.startsWith(mb)&&(e=e.substring(4));const t=n.lastIndexOf("/");if(t>=0){const s=n.substring(0,t+1);for(;s.endsWith("/")&&e.startsWith("/");)e=e.substring(1);const o=s+e;return Od&&console.log("source:",n,`changed uri
4
4
  from`,e,`
@@ -142,8 +142,8 @@ Open this page to get the console: `+e.toString())}const n=X.isMobileDevice()||X
142
142
  #__vconsole .vc-mask {
143
143
  overflow: hidden;
144
144
  }
145
- `,Ki?.prepend(s),n===!0&&ig()<=0&&qb(),console.log("\u{1F335} Debug console has loaded")}},e.onerror=()=>{console.warn("\u{1F335} Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),nc=!1,ni=null},e.src="https://cdn.jsdelivr.net/npm/vconsole@3.9.1/dist/vconsole.min.js",document.body.appendChild(e)}function Wk(){if(!globalThis.VConsole)return;const n=new VConsole.VConsolePlugin("needle-console","\u{1F335} Inspect glTF"),e=()=>document.querySelector("#__vc_plug_"+n._id+" iframe");return n.on("renderTab",function(t){const s=globalThis["needle:codegen_files"];if(!s||s.length===0)return;let o=globalThis["needle:codegen_files"][0];const r=o.indexOf("?");r>-1&&(o=o.substring(0,r));const l=location.protocol+"//"+location.host+location.pathname+"/"+o,c=encodeURIComponent(l);n.fullUrl="https://viewer.needle.tools?inspect&file="+c;var h='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';t(h)}),n.on("show",function(){const t=e();t&&t.src!==n.fullUrl&&(t.src=n.fullUrl)}),n.on("hide",function(){const t=e();t&&(t.src="")}),n.on("addTopBar",function(t){var s=new Array;s.push({name:"Open in new window \u2197",onClick:function(o){window.open(n.fullUrl,"_blank"),ni?.hide()}}),s.push({name:"Reload",onClick:function(o){const r=e();r&&(r.src=n.fullUrl)}}),s.push({name:"Fullscreen",onClick:function(o){const r=e();r.requestFullscreen?r.requestFullscreen():r.webkitRequestFullscreen instanceof Function&&r.webkitRequestFullscreen()}}),t(s)}),n}function Vk(){return document.querySelector("#__vconsole .vc-switch")||null}function $k(){return document.querySelector("#__vconsole")||null}const Kb=C("debugdefines");_o('if(!globalThis["NEEDLE_ENGINE_VERSION"]) globalThis["NEEDLE_ENGINE_VERSION"] = "0.0.0";'),_o('if(!globalThis["NEEDLE_ENGINE_GENERATOR"]) globalThis["NEEDLE_ENGINE_GENERATOR"] = "unknown";'),_o('if(!globalThis["NEEDLE_PROJECT_BUILD_TIME"]) globalThis["NEEDLE_PROJECT_BUILD_TIME"] = "unknown";'),_o('if(!globalThis["NEEDLE_PUBLIC_KEY"]) globalThis["NEEDLE_PUBLIC_KEY"] = "unknown";'),_o('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.7.2-alpha";'),_o('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";'),_o('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Fri Aug 01 2025 15:29:25 GMT+0000 (Coordinated Universal Time)";'),_o('globalThis["__NEEDLE_PUBLIC_KEY__"] = "'+NEEDLE_PUBLIC_KEY+'";');const _s="4.7.2-alpha",Dd="undefined",wg="Fri Aug 01 2025 15:29:25 GMT+0000 (Coordinated Universal Time)";Kb&&console.log(`Engine version: ${_s} (generator: ${Dd})
146
- Project built at ${wg}`);const Ea=NEEDLE_PUBLIC_KEY,An="needle_isActiveInHierarchy",wr="builtin_components",rc="needle_editor_guid";function _o(n){try{(0,eval)(n)}catch(e){Kb&&console.error(e)}}let Zb,Jb=null;function ws(){return Zb}function xg(n){if(n==null){console.warn("Oh no: someone tried registering a non-existend gltf-loader. When you see this log it might mean that needle-engine is being imported multiple times. Please check your project setup.");return}Jb!==n&&(Jb=n,Zb=new n)}const Mi=Symbol("shadowDomOwner"),Hk=C("debugpatch");function Bd(n,e,t,s){const o=Hk===e;if(!t&&!s)return;const r=e+"___needle";qk(n,e,t,s);const l=Object.getOwnPropertyDescriptor(n,e),c=n[e];o&&console.log("Patch",n.constructor.name,e,l,c),l?(o&&console.log("Apply patch with existing descriptor",n.constructor.name,e,l),typeof l.value=="function"&&(n[e]=t_(l.value,n,e))):(o&&console.log("Create patch with new property",n.constructor.name,e,l),Object.defineProperty(n,e,{set:function(h){if(typeof h=="function")this[r]=t_(h,n,e);else{const d=this[r];i_(n,e,this,d,h),this[r]=h,s_(n,e,this,d,h)}},get:function(){const h=this[r];return typeof h=="function"&&h[r]?h[r]:h}}))}function Gk(n,e,t){const s=Cg(n,e);if(s)for(let o=s.length-1;o>=0;o--){const r=s[o];r.prefix===t&&(r.prefix=null),r.postfix===t&&(r.postfix=null),!r.prefix&&!r.postfix&&s.splice(o,1)}}const e_=Symbol("Needle:Patches:WrappedFunction");function t_(n,e,t){if(n[e_])return n;const s=function(...o){i_(e,t,this,...o);const r=n.apply(this,o);return s_(e,t,this,r,...o),r};return s[e_]=!0,s}const Fd="Needle:Patches";function Sg(){return globalThis[Fd]||(globalThis[Fd]=new WeakMap),globalThis[Fd]}function Cg(n,e){const t=Sg().get(n);return t?t.get(e):null}function qk(n,e,t,s){let o=Sg().get(n);o||(o=new Map,Sg().set(n,o));let r=o.get(e);r||(r=[],o.set(e,r)),r.push({prefix:t,postfix:s})}function i_(n,e,t,...s){var o;if(!t)return;const r=Cg(n,e);if(r)for(const l of r)(o=l.prefix)==null||o.call(t,...s)}function s_(n,e,t,s,...o){var r;if(!t)return;const l=Cg(n,e);if(l)for(const c of l)(r=c.postfix)==null||r.call(t,s,...o)}const Aa=[];function Ud(n){Aa.indexOf(n)===-1&&Aa.push(n)}function Xk(n){const e=Aa.indexOf(n);e!==-1&&Aa.splice(e,1)}const Ia=[];function Pg(n){Ia.indexOf(n)===-1&&Ia.push(n)}function Qk(n){const e=Ia.indexOf(n);e!==-1&&Ia.splice(e,1)}function n_(n){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-start",{detail:n}));for(let e=0;e<Aa.length;e++)Aa[e](n)}function o_(n){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-end",{detail:n}));for(let e=0;e<Ia.length;e++)Ia[e](n)}const ct=C("debuginput");var zd=(n=>(n.Mouse="mouse",n.Touch="touch",n.Controller="controller",n.Hand="hand",n))(zd||{}),Be=(n=>(n.PointerDown="pointerdown",n.PointerUp="pointerup",n.PointerMove="pointermove",n.KeyDown="keydown",n.KeyUp="keyup",n.KeyPressed="keypress",n))(Be||{});class In extends PointerEvent{constructor(e,t,s){super(e,s),a(this,"clientZ"),a(this,"deviceIndex"),a(this,"origin"),a(this,"source"),a(this,"mode"),a(this,"_ray"),a(this,"space"),a(this,"isClick",!1),a(this,"isDoubleClick",!1),a(this,"_used",!1),a(this,"_pointerid"),a(this,"_pointerType"),a(this,"_type"),a(this,"metadata",{}),a(this,"intersections",new Array),a(this,"_immediatePropagationStopped",!1),a(this,"_propagationStopped",!1),this.clientZ=s.clientZ,this._pointerid=s.pointerId,this._pointerType=s.pointerType,this._type=e,this.deviceIndex=s.deviceIndex,this.origin=s.origin,this.source=t,this.mode=s.mode,this._ray=s.ray,this.space=s.device}get isSpatial(){return this.mode!="screen"}get ray(){return this._ray||(this._ray=new mo(this.space.worldPosition.clone(),this.space.worldForward.clone())),this._ray}set ray(e){this._ray=e}get hasRay(){return this._ray!==void 0}get used(){return this._used}use(){this._used=!0}get pointerId(){return this._pointerid}get pointerType(){return this._pointerType}get type(){return this._type}get immediatePropagationStopped(){return this._immediatePropagationStopped}get propagationStopped(){return this._immediatePropagationStopped||this._propagationStopped}stopImmediatePropagation(){var e;this._immediatePropagationStopped=!0,super.stopImmediatePropagation(),(e=this.source)==null||e.stopImmediatePropagation()}stopPropagation(){var e;this._propagationStopped=!0,super.stopPropagation(),(e=this.source)==null||e.stopPropagation(),ct&&console.warn("Stop propagation...",this.pointerId,this.pointerType)}}class ac extends KeyboardEvent{constructor(e,t,s){super(e,s),a(this,"source"),this.source=t}stopImmediatePropagation(){var e;super.stopImmediatePropagation(),(e=this.source)==null||e.stopImmediatePropagation()}}class Yk{constructor(e){a(this,"key"),a(this,"keyType"),a(this,"source"),this.key=e.key,this.keyType=e.type,this.source=e}}var oi=(n=>(n[n.Early=-100]="Early",n[n.Default=0]="Default",n[n.Late=100]="Late",n))(oi||{});class r_{constructor(e){a(this,"_eventListeners",{}),a(this,"_doubleClickTimeThreshold",.2),a(this,"_longPressTimeThreshold",1),a(this,"_setCursorTypes",[]),a(this,"context"),a(this,"_pointerDown",[!1]),a(this,"_pointerUp",[!1]),a(this,"_pointerClick",[!1]),a(this,"_pointerDoubleClick",[!1]),a(this,"_pointerPressed",[!1]),a(this,"_pointerPositions",[new re]),a(this,"_pointerPositionsLastFrame",[new re]),a(this,"_pointerPositionsDelta",[new re]),a(this,"_pointerPositionsRC",[new re]),a(this,"_pointerPositionDown",[new S]),a(this,"_pointerDownTime",[]),a(this,"_pointerUpTime",[]),a(this,"_pointerUpTimestamp",[]),a(this,"_pointerIds",[]),a(this,"_pointerTypes",[""]),a(this,"_mouseWheelChanged",[!1]),a(this,"_mouseWheelDeltaY",[0]),a(this,"_pointerEvent",[]),a(this,"_pointerEventsPressed",[]),a(this,"_pointerSpace",[]),a(this,"_pressedStack",new Map),a(this,"_htmlEventSource"),a(this,"onLostFocus",()=>{for(const t in this.keysPressed)this.keysPressed[t].pressed=!1}),a(this,"_receivedPointerMoveEventsThisFrame",new Array),a(this,"onEndOfFrame",()=>{this._receivedPointerMoveEventsThisFrame.length=0;for(let t=0;t<this._pointerUp.length;t++)this._pointerUp[t]=!1;for(let t=0;t<this._pointerDown.length;t++)this._pointerDown[t]=!1;for(let t=0;t<this._pointerClick.length;t++)this._pointerClick[t]=!1;for(let t=0;t<this._pointerDoubleClick.length;t++)this._pointerDoubleClick[t]=!1;for(const t of this._pointerPositionsDelta)t.set(0,0);for(let t=0;t<this._mouseWheelChanged.length;t++)this._mouseWheelChanged[t]=!1;for(let t=0;t<this._mouseWheelDeltaY.length;t++)this._mouseWheelDeltaY[t]=0}),a(this,"onContextMenu",t=>{this.canReceiveInput(t)!==!1&&t instanceof PointerEvent&&t.pointerType}),a(this,"keysPressed",{}),a(this,"onKeyDown",t=>{if(ct&&console.log(`key down ${t.code}, ${this.context.application.hasFocus}`,t),!this.context.application.hasFocus)return;const s=this.keysPressed[t.code];if(s&&s.pressed)return;this.keysPressed[t.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:t.key,code:t.code};const o=new ac("keydown",t,t);this.onDispatchEvent(o)}),a(this,"onKeyPressed",t=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[t.code];if(!s)return;s.pressed=!0,s.frame=this.context.time.frameCount+1;const o=new ac("keypress",t,t);this.onDispatchEvent(o)}),a(this,"onKeyUp",t=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[t.code];if(!s)return;s.pressed=!1,s.frame=this.context.time.frameCount+1;const o=new ac("keyup",t,t);this.onDispatchEvent(o)}),a(this,"onWheelWindow",t=>{document.pointerLockElement&&this.onMouseWheel(t)}),a(this,"onMouseWheel",t=>{if(this.canReceiveInput(t)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const s=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=s+t.deltaY}),a(this,"onPointerDown",t=>{if(this.context.isInAR||this.canReceiveInput(t)===!1)return;t.target instanceof HTMLElement&&t.target.setPointerCapture(t.pointerId);const s=this.getPointerId(t);ct&&De(`pointer down #${s}, identifier:${t.pointerId}`);const o=this.getAndUpdateSpatialObjectForScreenPosition(s,t.clientX,t.clientY),r=new In("pointerdown",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:s,button:t.button,clientX:t.clientX,clientY:t.clientY,pointerType:t.pointerType,buttonName:this.getButtonName(t),device:o,pressure:t.pressure});this.onDown(r)}),a(this,"onPointerMove",t=>{if(this.context.isInAR||this._receivedPointerMoveEventsThisFrame.includes(t.pointerId))return;this._receivedPointerMoveEventsThisFrame.push(t.pointerId);let s=t.button;t.pointerType==="mouse"&&(s=this.getFirstPressedButtonForPointer(0)??0);const o=this.getPointerId(t,s);s===-1&&(s=o);const r=this.getAndUpdateSpatialObjectForScreenPosition(o,t.clientX,t.clientY),l=new In("pointermove",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:o,button:s,clientX:t.clientX,clientY:t.clientY,pointerType:t.pointerType,buttonName:this.getButtonName(t),device:r,pressure:t.pressure});this.onMove(l)}),a(this,"onPointerCancel",t=>{this.context.isInAR||(ct&&console.log("Pointer cancel",t),this.onPointerUp(t))}),a(this,"onPointerUp",t=>{if(this.context.isInAR)return;t.target instanceof HTMLElement&&t.target.releasePointerCapture(t.pointerId);const s=this.getPointerId(t),o=new In("pointerup",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:s,button:t.button,clientX:t.clientX,clientY:t.clientY,pointerType:t.pointerType,buttonName:this.getButtonName(t),device:this.getAndUpdateSpatialObjectForScreenPosition(s,t.clientX,t.clientY),pressure:t.pressure});this.onUp(o),this._pointerIds[s]=-1,ct&&console.log("ID="+s,"PointerId="+t.pointerId,"ALL:",[...this._pointerIds])}),a(this,"onTouchStart",t=>{if(this.context.isInAR)for(let s=0;s<t.changedTouches.length;s++){const o=t.changedTouches[s],r=this.getPointerIndex(o.identifier),l=this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),c=new In("pointerdown",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:l,pressure:o.force});this.onDown(c)}}),a(this,"onTouchMove",t=>{if(this.context.isInAR)for(let s=0;s<t.changedTouches.length;s++){const o=t.changedTouches[s],r=this.getPointerIndex(o.identifier),l=this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),c=new In("pointermove",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:l,pressure:o.force});this.onMove(c)}}),a(this,"onTouchEnd",t=>{if(this.context.isInAR)for(let s=0;s<t.changedTouches.length;s++){const o=t.changedTouches[s],r=this.getPointerIndex(o.identifier),l=new In("pointerup",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),pressure:o.force});this.onUp(l),this._pointerIds[r]=-1}}),a(this,"tempNearPlaneVector",new S),a(this,"tempFarPlaneVector",new S),a(this,"tempLookMatrix",new se),this.context=e,this.context.post_render_callbacks.push(this.onEndOfFrame)}addEventListener(e,t,s){if(this._eventListeners[e]||(this._eventListeners[e]=[]),!t||typeof t!="function"){console.error("Invalid call to addEventListener: callback is required and must be a function!");return}s?s={...s}:s={};let o=0;s?.queue!=null&&(o=s.queue);const r=this._eventListeners[e],l=r.find(c=>c.priority===o);l?l.listeners.push({callback:t,options:s}):(r.push({priority:o,listeners:[{callback:t,options:s}]}),r.sort((c,h)=>c.priority-h.priority))}removeEventListener(e,t,s){if(!this._eventListeners[e]||!t)return;const o=this._eventListeners[e];if(s?.queue!=null){const r=o.find(c=>c.priority===s.queue);if(!r)return;const l=r.listeners.findIndex(c=>c.callback===t);l>=0&&r.listeners.splice(l,1)}else for(const r of o){const l=r.listeners.findIndex(c=>c.callback===t);l>=0&&r.listeners.splice(l,1)}}dispatchEvent(e){var t,s,o,r;let l=!1;if(e instanceof ac){const c=this._eventListeners[e.type];if(c)for(const h of c)for(let d=0;d<h.listeners.length;d++){const u=h.listeners[d];if((s=(t=u.options)==null?void 0:t.signal)!=null&&s.aborted){h.listeners.splice(d,1),d--;continue}u.options.once&&(h.listeners.splice(d,1),d--),u.callback(e)}}if(e instanceof In){const c=this._eventListeners[e.type];if(c)for(const h of c){if(l)break;for(let d=0;d<h.listeners.length;d++){const u=h.listeners[d];if((r=(o=u.options)==null?void 0:o.signal)!=null&&r.aborted){h.listeners.splice(d,1),d--;continue}if(e.immediatePropagationStopped){l=!0,ct&&console.log("immediatePropagationStopped",e.type);break}else e.propagationStopped&&(l=!0,ct&&console.log("propagationStopped",e.type));u.options.once&&(h.listeners.splice(d,1),d--),u.callback(e)}}}}get mousePosition(){return this._pointerPositions[0]}get mousePositionRC(){return this._pointerPositionsRC[0]}get mouseDown(){return this._pointerDown[0]}get mouseUp(){return this._pointerUp[0]}get mouseClick(){return this._pointerClick[0]}get mouseDoubleClick(){return this._pointerDoubleClick[0]}get mousePressed(){return this._pointerPressed[0]}get mouseWheelChanged(){return this.getMouseWheelChanged(0)}get click(){return this._pointerClick[0]}get doubleClick(){return this._pointerDoubleClick[0]}getGamepad(e=0){return typeof navigator<"u"&&"getGamepads"in navigator&&navigator.getGamepads()[e]||null}setCursorPointer(){this.setCursor("pointer")}setCursorNormal(){this.unsetCursor("pointer")}setCursor(e){this._setCursorTypes.push(e),this._setCursorTypes.length>10&&this._setCursorTypes.shift(),this.updateCursor()}unsetCursor(e){for(let t=this._setCursorTypes.length-1;t>=0;t--)if(this._setCursorTypes[t]===e){this._setCursorTypes.splice(t,1),this.updateCursor();break}}updateCursor(){var e;((e=this._setCursorTypes)==null?void 0:e.length)==0?this.context.domElement.style.cursor="default":this.context.domElement.style.cursor=this._setCursorTypes[this._setCursorTypes.length-1]}getIsPointerIdInUse(e){for(const t of this._pointerEventsPressed)if(t.pointerId===e&&t.used)return!0;return!1}getPointerPressedCount(){let e=0;for(let t=0;t<this._pointerPressed.length;t++)this._pointerPressed[t]&&e++;return e}getPointerPosition(e){return e>=this._pointerPositions.length?null:this._pointerPositions[e]}getPointerPositionLastFrame(e){return e>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[e]}getPointerPositionDelta(e){return e>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[e]}getPointerPositionRC(e){return e>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[e]}getPointerDown(e){return e>=this._pointerDown.length?!1:this._pointerDown[e]}getPointerUp(e){return e>=this._pointerUp.length?!1:this._pointerUp[e]}getPointerPressed(e){return e>=this._pointerPressed.length?!1:this._pointerPressed[e]}getPointerClicked(e){return e>=this._pointerClick.length?!1:this._pointerClick[e]}getPointerDoubleClicked(e){return e>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[e]}getPointerDownTime(e){return e>=this._pointerDownTime.length?-1:this._pointerDownTime[e]}getPointerUpTime(e){return e>=this._pointerUpTime.length?-1:this._pointerUpTime[e]}getPointerLongPress(e){return e>=this._pointerDownTime.length?!1:this.getPointerPressed(e)&&this.context.time.time-this._pointerDownTime[e]>this._longPressTimeThreshold}getIsMouse(e){return e<0||e>=this._pointerTypes.length?!1:this._pointerTypes[e]==="mouse"}getIsTouch(e){return e<0||e>=this._pointerTypes.length?!1:this._pointerTypes[e]==="touch"}getTouchesPressedCount(){let e=0;for(let t=0;t<this._pointerPressed.length;t++)this._pointerPressed[t]&&this.getIsTouch(t)&&e++;return e}getMouseWheelChanged(e=0){return e>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[e]}getMouseWheelDeltaY(e=0){return e>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[e]}getPointerEvent(e){if(!(e>=this._pointerEvent.length))return this._pointerEvent[e]??void 0}*foreachPointerId(e){for(let t=0;t<this._pointerTypes.length;t++)if(this._pointerIsActive(t)){if(e!==void 0){const s=this._pointerTypes[t];if(Array.isArray(e)){let o=!1;for(const r of e)if(s===r){o=!0;break}if(!o)continue}else if(e!==s)continue}yield t}}*foreachTouchId(){for(let e=0;e<this._pointerTypes.length;e++)this._pointerTypes[e]==="touch"&&this._pointerIsActive[e]&&(yield e)}_pointerIsActive(e){return e<0?!1:this._pointerPressed[e]||this._pointerDown[e]||this._pointerUp[e]}onDownButton(e,t){let s=this._pressedStack.get(e);s||(s=[],this._pressedStack.set(e,s)),s.push(t)}onReleaseButton(e,t){const s=this._pressedStack.get(e);if(!s)return;const o=s.indexOf(t);o>=0&&s.splice(o,1)}getFirstPressedButtonForPointer(e){const t=this._pressedStack.get(e);if(t)return t[0]}getLatestPressedButtonForPointer(e){const t=this._pressedStack.get(e);if(t)return t[t.length-1]}getKeyDown(e){if(e!==void 0)return this.isKeyDown(e);for(const t in this.keysPressed){const s=this.keysPressed[t];if(s.startFrame===this.context.time.frameCount)return s.key}return null}getKeyPressed(e){if(e!==void 0)return this.isKeyPressed(e);for(const t in this.keysPressed){const s=this.keysPressed[t];if(s.pressed)return s.key}return null}getKeyUp(e){if(e!==void 0)return this.isKeyUp(e);for(const t in this.keysPressed){const s=this.keysPressed[t];return s.pressed===!1&&s.frame===this.context.time.frameCount}return null}isKeyDown(e){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const t=this.getCodeForCommonKeyName(e);if(t!==null){for(const o of t)if(this.isKeyDown(o))return!0;return!1}const s=this.keysPressed[e];return s?s.startFrame===this.context.time.frameCount&&s.pressed:!1}isKeyUp(e){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const t=this.getCodeForCommonKeyName(e);if(t!==null){for(const o of t)if(this.isKeyUp(o))return!0;return!1}const s=this.keysPressed[e];return s?s.frame===this.context.time.frameCount&&s.pressed===!1:!1}isKeyPressed(e){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const t=this.getCodeForCommonKeyName(e);if(t!==null){for(const o of t)if(this.isKeyPressed(o))return!0;return!1}const s=this.keysPressed[e];return s&&s.pressed||!1}getCodeForCommonKeyName(e){if(e.length===1){if(e>="0"&&e<="9")return["Digit"+e];if(e>="a"&&e<="z")return["Key"+e.toUpperCase()];if(e==" ")return["Space"]}switch(e){case"shift":case"Shift":return["ShiftLeft","ShiftRight"];case"control":case"Control":return["ControlLeft","ControlRight"];case"alt":case"Alt":return["AltLeft","AltRight"]}return null}createInputEvent(e){switch(e.type){case"pointerdown":ct&&De("Create Pointer down"),this.onDownButton(e.deviceIndex,e.button),this.onDown(e);break;case"pointermove":ct&&De("Create Pointer move"),this.onMove(e);break;case"pointerup":ct&&De("Create Pointer up"),this.onUp(e),this.onReleaseButton(e.deviceIndex,e.button);break}}convertScreenspaceToRaycastSpace(e){return e.x=(e.x-this.context.domX)/this.context.domWidth*2-1,e.y=-((e.y-this.context.domY)/this.context.domHeight)*2+1,e}bindEvents(){this.unbindEvents(),this._htmlEventSource=this.context.renderer.domElement,window.addEventListener("contextmenu",this.onContextMenu),this._htmlEventSource.addEventListener("pointerdown",this.onPointerDown,{passive:!0}),window.addEventListener("pointermove",this.onPointerMove,{passive:!0,capture:!0}),window.addEventListener("pointerup",this.onPointerUp,{passive:!0}),window.addEventListener("pointercancel",this.onPointerCancel,{passive:!0}),window.addEventListener("touchstart",this.onTouchStart,{passive:!0}),window.addEventListener("touchmove",this.onTouchMove,{passive:!0}),window.addEventListener("touchend",this.onTouchEnd,{passive:!0}),this._htmlEventSource.addEventListener("wheel",this.onMouseWheel,{passive:!0}),window.addEventListener("wheel",this.onWheelWindow,{passive:!0}),window.addEventListener("keydown",this.onKeyDown,!1),window.addEventListener("keypress",this.onKeyPressed,!1),window.addEventListener("keyup",this.onKeyUp,!1),window.addEventListener("blur",this.onLostFocus)}unbindEvents(){var e,t;for(const s in this._eventListeners)this._eventListeners[s].length=0;window.removeEventListener("contextmenu",this.onContextMenu),(e=this._htmlEventSource)==null||e.removeEventListener("pointerdown",this.onPointerDown),window.removeEventListener("pointermove",this.onPointerMove),window.removeEventListener("pointerup",this.onPointerUp),window.removeEventListener("pointercancel",this.onPointerCancel),window.removeEventListener("touchstart",this.onTouchStart),window.removeEventListener("touchmove",this.onTouchMove),window.removeEventListener("touchend",this.onTouchEnd),(t=this._htmlEventSource)==null||t.removeEventListener("wheel",this.onMouseWheel,!1),window.removeEventListener("wheel",this.onWheelWindow,!1),window.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("keypress",this.onKeyPressed,!1),window.removeEventListener("keyup",this.onKeyUp,!1),window.removeEventListener("blur",this.onLostFocus)}dispose(){const e=this.context.post_render_callbacks.indexOf(this.onEndOfFrame);e>=0&&this.context.post_render_callbacks.splice(e,1),this.unbindEvents()}canReceiveInput(e){var t;return e.target===((t=this.context.renderer)==null?void 0:t.domElement)||e.target===this.context.domElement||this.context.isInAR||this.context.isInAR&&e.target===document.body&&X.isMozillaXR()?!0:(ct&&console.warn("CanReceiveInput:False for",e.target),!1)}getPointerId(e,t){return e.pointerType==="mouse"?0+(t??e.button):this.getPointerIndex(e.pointerId)}getButtonName(e){const t=e.button;if(e.pointerType==="mouse")switch(t){case 0:return"left";case 1:return"middle";case 2:return"right"}return"unknown"}getAndUpdateSpatialObjectForScreenPosition(e,t,s){let o=this._pointerSpace[e];o||(o=new E,this._pointerSpace[e]=o),this._pointerSpace[e]=o;const r=this.context.mainCamera;if(r){const l=this.tempNearPlaneVector.set(t,s,-1);this.convertScreenspaceToRaycastSpace(l);const c=this.tempFarPlaneVector.set(l.x,l.y,1);l.unproject(r),c.unproject(r);const h=r.worldUp||q(0,1,0).applyQuaternion(Se(r));this.tempLookMatrix.lookAt(c,l,h),o.position.set(l.x,l.y,l.z),o.quaternion.setFromRotationMatrix(this.tempLookMatrix)}return o}isInRect(e){if(this.context.isInXR)return!0;const t=this.context.domElement.getBoundingClientRect(),s=e.clientX,o=e.clientY,r=s>=t.x&&s<=t.right&&o>=t.y&&o<=t.bottom;return ct&&!r&&console.log("Not in rect",t,s,o),r}onDown(e){const t=e.pointerId;if(this.getPointerPressed(t)&&console.warn(`Received pointerDown for pointerId that is already pressed: ${t}`,ct?e:""),ct&&console.log(e.pointerType,"DOWN",t),!!this.isInRect(e)){for(this.setPointerState(t,this._pointerPressed,!0),this.setPointerState(t,this._pointerDown,!0),this.setPointerStateT(t,this._pointerEvent,e.source);t>=this._pointerTypes.length;)this._pointerTypes.push(e.pointerType);for(this._pointerTypes[t]=e.pointerType;t>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new S);for(this._pointerPositionDown[t].set(e.clientX,e.clientY,e.clientZ??0);t>=this._pointerPositions.length;)this._pointerPositions.push(new re);this._pointerPositions[t].set(e.clientX,e.clientY),t>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[t]=this.context.time.realtimeSinceStartup,this.updatePointerPosition(e),this._pointerEventsPressed.push(e),this.onDispatchEvent(e)}}onMove(e){const t=e.pointerId,s=this.getPointerPressed(t);s===!1&&!this.isInRect(e)||e.pointerType==="touch"&&!s||(this.updatePointerPosition(e),this.setPointerStateT(t,this._pointerEvent,e.source),this.onDispatchEvent(e))}onUp(e){const t=e.pointerId;if(!this.getPointerPressed(t)){ct&&console.log(e.pointerType,"UP",t,"was not down");return}ct&&console.log(e.pointerType,"UP",t),this.setPointerState(t,this._pointerPressed,!1),this.setPointerStateT(t,this._pointerEvent,e.source),this.setPointerState(t,this._pointerUp,!0),this.updatePointerPosition(e);for(let c=this._pointerEventsPressed.length-1;c>=0;c--)if(this._pointerEventsPressed[c].pointerId===t){this._pointerEventsPressed.splice(c,1);break}if(!this._pointerPositionDown[t]){ct&&be("Received pointer up event without matching down event for button: "+t),console.warn("Received pointer up event without matching down event for button: "+t);return}const s=this._pointerUpTime[t],o=this._pointerDownTime[t],r=this.context.time.realtimeSinceStartup,l=r-o;if(t>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),this._pointerUpTime[t]=r,l<1){let c=e.clientX-this._pointerPositionDown[t].x,h=e.clientY-this._pointerPositionDown[t].y,d=0;if(e.isSpatial&&e.clientZ!=null&&(d=e.clientZ-this._pointerPositionDown[t].z,c*=200,h*=200,d*=200),Math.abs(c)<5&&Math.abs(h)<5&&Math.abs(d)<5){this.setPointerState(t,this._pointerClick,!0),e.isClick=!0;const u=r-s;ct&&console.log("CLICK",t,c,h,d,u),u<this._doubleClickTimeThreshold&&u>0&&(this.setPointerState(t,this._pointerDoubleClick,!0),e.isDoubleClick=!0)}}this.onDispatchEvent(e)}updatePointerPosition(e){const t=e.pointerId;for(;t>=this._pointerPositions.length;)this._pointerPositions.push(new re);for(;t>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new re);for(;t>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new re);const s=this._pointerPositionsLastFrame[t];s.copy(this._pointerPositions[t]);const o=this._pointerPositionsDelta[t];let r=e.clientX-s.x,l=e.clientY-s.y;if(e.source instanceof MouseEvent||e.source instanceof TouchEvent){const u=e.source;r===0&&u.movementX!==0&&(r=u.movementX||0),l===0&&u.movementY!==0&&(l=u.movementY||0)}o.x+=r,o.y+=l,this._pointerPositions[t].x=e.clientX,this._pointerPositions[t].y=e.clientY;const c=e.clientX,h=e.clientY;for(;t>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new re);const d=this._pointerPositionsRC[t];d.set(c,h),this.convertScreenspaceToRaycastSpace(d)}getPointerIndex(e){let t=-1;for(let s=0;s<this._pointerIds.length;s++){if(this._pointerIds[s]===e)return s;t===-1&&this._pointerIds[s]===-1&&(t=s)}return t!==-1?(this._pointerIds[t]=e,t):(ct&&console.log("PUSH pointerId:",e),this._pointerIds.push(e),this._pointerIds.length-1)}setPointerState(e,t,s){t[e]=s}setPointerStateT(e,t,s){return t[e]=s,s}onDispatchEvent(e){const t=J.Current;try{J.Current=this.context,this.dispatchEvent(e)}finally{J.Current=t}}}const La=new se().makeRotationY(Math.PI),Zi=new V().setFromAxisAngle(new S(0,1,0),Math.PI),Kk=C("debugwebxr");class Zk{constructor(){if(a(this,"priority",-1e5),a(this,"gameObject"),this.gameObject=new E,this.gameObject.name="Implicit XR Rig",Kk){const e=$g(16733661);e.position.y+=.5,this.gameObject.add(e)}}isXRRig(){return!0}get isActive(){return this.gameObject.visible}}const Ln=C("debugwebxr"),Nd=C("debugcustomgesture"),Jk="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",eM="generic-trigger",tM=new V().setFromEuler(new Bt(Pn.degToRad(0),Pn.degToRad(-90),Pn.degToRad(-90))),iM=new S(.04,-.04,0);class Og{constructor(e,t,s){a(this,"xr"),a(this,"inputSource"),a(this,"index",0),a(this,"emitEvents",!0),a(this,"_connected",!0),a(this,"_isTracking",!1),a(this,"__gamepad"),a(this,"__hand"),a(this,"__side"),a(this,"_hitTestSource"),a(this,"_hasSelectEvent",!1),a(this,"_isMxInk",!1),a(this,"_isMetaQuestTouchController",!1),a(this,"_handJointPoses",new Map),a(this,"_gripMatrix",new se),a(this,"_gripPosition",new S),a(this,"_gripQuaternion",new V),a(this,"_linearVelocity",new S),a(this,"_rayPositionRaw",new S),a(this,"_rayRotationRaw",new V),a(this,"_rayMatrix",new se),a(this,"_rayPosition",new S),a(this,"_rayQuaternion",new V),a(this,"_gripWorldPosition",new S),a(this,"_gripWorldQuaternion",new V),a(this,"_rayWorldPosition",new S),a(this,"_rayWorldQuaternion",new V),a(this,"_pinchPosition",new S),a(this,"_ray"),a(this,"_hand_wristDotUp"),a(this,"_object"),a(this,"_gripSpaceObject"),a(this,"_raySpaceObject"),a(this,"model",null),a(this,"_debugAxesHelper",new Ci(.15)),a(this,"_debugGripAxesHelper",new Ci(.07)),a(this,"_debugRayAxesHelper",new Ci(.07)),a(this,"_hitTestSourcePromise",null),a(this,"onPointerHits",o=>{}),a(this,"_needleGamepadButtons",{}),a(this,"_buttonMap",new Map),a(this,"_motioncontroller"),a(this,"_layout"),a(this,"getMotionController"),a(this,"emitPointerDownEvent",!0),a(this,"emitPointerUpEvent",!0),a(this,"emitPointerMoveEvent",!0),a(this,"pointerMoveDistanceThreshold",.03),a(this,"pointerMoveAngleThreshold",.05),a(this,"_selectButtonIndex"),a(this,"_squeezeButtonIndex"),a(this,"onSelectStart",o=>{var r,l,c,h;if(!this.emitPointerDownEvent||this.inputSource!==o.inputSource)return;this.onUpdateFrame(o.frame),this._hasSelectEvent=!0;const d=(r=this._layout)==null?void 0:r.selectComponentId,u=(h=(c=(l=this._layout)==null?void 0:l.components[d])==null?void 0:c.gamepadIndices)==null?void 0:h.button;u!==void 0&&(this._selectButtonIndex=u),!Nd&&(Ln&&$.DrawDirection(this.rayWorldPosition,q(0,.01,1).applyQuaternion(this.rayWorldQuaternion),16711680,10),this.emitPointerEvent(Be.PointerDown,this._selectButtonIndex||0,"xr-standard-trigger",!0,o))}),a(this,"onSelectEnd",o=>{this.emitPointerUpEvent&&(Nd||this.inputSource===o.inputSource&&this.emitPointerEvent(Be.PointerUp,this._selectButtonIndex||0,"xr-standard-trigger",!0,o))}),a(this,"onSequeezeStart",o=>{var r,l,c;this.emitPointerDownEvent&&this.inputSource===o.inputSource&&(this._squeezeButtonIndex=(c=(l=(r=this._layout)==null?void 0:r.components["xr-standard-squeeze"])==null?void 0:l.gamepadIndices)==null?void 0:c.button,this._squeezeButtonIndex!==void 0&&(Ln&&$.DrawDirection(this.rayWorldPosition,q(0,.01,1).applyQuaternion(this.rayWorldQuaternion),255,10),this.emitPointerEvent(Be.PointerDown,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,o)))}),a(this,"onSequeezeEnd",o=>{this.emitPointerUpEvent&&this.inputSource===o.inputSource&&this._squeezeButtonIndex!==void 0&&this.emitPointerEvent(Be.PointerUp,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,o)}),a(this,"states",{}),a(this,"_didMoveLastFrame",!1),a(this,"_lastPointerMovePosition",new S),a(this,"_lastPointerMoveQuaternion",new V),a(this,"pointerInit"),this.xr=e,this.inputSource=t,this.index=s,this._object=new E,this._object.name=`NeedleXRController_${s}`,Ln&&(this._object.add(this._debugAxesHelper),this._gripSpaceObject=new E,this._raySpaceObject=new E,this._gripSpaceObject.name=`NeedleXRController_${s}_gripSpace`,this._raySpaceObject.name=`NeedleXRController_${s}_raySpace`,this._gripSpaceObject.add(this._debugGripAxesHelper),this._raySpaceObject.add(this._debugRayAxesHelper),this.xr.context.scene.add(this._gripSpaceObject),this.xr.context.scene.add(this._raySpaceObject)),this.xr.context.scene.add(this._object),this._ray=new mo,this.pointerInit={origin:this,pointerType:this.hand?"hand":"controller",deviceIndex:this.index,pointerId:-1,mode:this.inputSource.targetRayMode,ray:this._ray,device:this._object,buttonName:"none"},this.initialize(),this.subscribeEvents()}get context(){return this.xr.context}get connected(){return this._connected}get isTracking(){return this._isTracking}get gamepad(){return this.__gamepad??(this.__gamepad=this.inputSource.gamepad)}get isHand(){return this.hand!=null}get hand(){return this.__hand??(this.__hand=this.inputSource.hand)}get handObject(){return this.context.renderer.xr.getHand(this.index)}get profiles(){return this.inputSource.profiles}get layout(){return this._layout}get targetRayMode(){return this.inputSource.targetRayMode}get targetRaySpace(){return this.inputSource.targetRaySpace}get gripSpace(){return this.inputSource.gripSpace}get side(){return this.__side??(this.__side=this.inputSource.handedness)}get isRight(){return this.side==="right"}get isLeft(){return this.side==="left"}get isStylus(){return this._isMxInk}getHitTestSource(){return this._hitTestSource||this._requestHitTestSource(),this._hitTestSource}get hasHitTestSource(){return this._hitTestSource}cancelHitTestSource(){this._hitTestSource&&(this._hitTestSource.cancel(),this._hitTestSource=void 0)}get hasSelectEvent(){return this._hasSelectEvent}getHitTest(){return this.xr.getHitTest(this)}getHandJointPose(e,t){var s;if(t=t||this.xr.frame,!this.hand||!(t!=null&&t.getJointPose)||!this.xr.referenceSpace)return null;let o=(s=this._handJointPoses)==null?void 0:s.get(e);return o||(o=t.getJointPose(e,this.xr.referenceSpace),o&&this._handJointPoses.set(e,o),o)}get gripPosition(){return q(this._gripPosition)}get gripQuaternion(){return vs(this._gripQuaternion)}get gripMatrix(){return this._gripMatrix}get gripLinearVelocity(){return q(this._linearVelocity).applyQuaternion(Zi)}get rayPosition(){return q(this._rayPosition)}get rayQuaternion(){return vs(this._rayQuaternion)}get gripWorldPosition(){return q(this._gripWorldPosition)}get gripWorldQuaternion(){return vs(this._gripWorldQuaternion)}get rayWorldPosition(){return q(this._rayWorldPosition)}updateRayWorldPosition(){var e;const t=(e=this.xr.context.mainCamera)==null?void 0:e.parent;this._rayWorldPosition.copy(this._rayPositionRaw),t&&this._rayWorldPosition.applyMatrix4(t.matrixWorld)}get rayWorldQuaternion(){return vs(this._rayWorldQuaternion)}get pinchPosition(){return q(this._pinchPosition)}updateRayWorldQuaternion(){var e;const t=(e=this.xr.context.mainCamera)==null?void 0:e.parent,s=t?Se(t):void 0;this._rayWorldQuaternion.copy(this._rayRotationRaw).multiply(Zi),s&&this._rayWorldQuaternion.premultiply(s)}get ray(){return this._ray.origin.copy(this.rayWorldPosition),this._ray.direction.copy(q(0,0,1).applyQuaternion(this.rayWorldQuaternion)),this._ray}get handWristDotUp(){var e;if(this._hand_wristDotUp!==void 0)return this._hand_wristDotUp;const t=(e=this.handObject)==null?void 0:e.joints.wrist;if(t){const s=q(0,1,0).applyQuaternion(t.quaternion),o=q(0,1,0).dot(s);return this._hand_wristDotUp=o}}get isHandUpsideDown(){return this.handWristDotUp!==void 0?this.handWristDotUp<-.7:!1}get isTeleportGesture(){var e;return this.isHandUpsideDown&&((e=this.getGesture("pinch"))==null?void 0:e.isDown)}get object(){return this._object}async getModelUrl(){var e;return(e=this.getMotionController)==null?void 0:e.then(t=>t?.assetUrl||null)}_requestHitTestSource(){var e;return this._hitTestSourcePromise?this._hitTestSourcePromise:this.xr.mode==="immersive-ar"&&this.inputSource.targetRayMode==="tracked-pointer"&&this.xr.session.requestHitTestSourceForTransientInput?this._hitTestSourcePromise=((e=this.xr.session.requestHitTestSourceForTransientInput({profile:this.inputSource.profiles[0],offsetRay:new XRRay}))==null?void 0:e.then(t=>(this._hitTestSourcePromise=null,this.connected?this._hitTestSource=t:(t.cancel(),null))))??null:null}onUpdate(e){this.onUpdateFrame(e),this.updateInputEvents(),this.onUpdateMove()}onRenderDebug(){var e;$.DrawSphere(this.rayWorldPosition,.003),$.DrawDirection(this.rayWorldPosition,q(0,0,10).applyQuaternion(this.rayWorldQuaternion));const t=(this.inputSource.gripSpace?this.gripWorldPosition:this.object.worldPosition).sub(this.object.worldForward.multiplyScalar(.1)),s=this.inputSource.profiles.join(`
145
+ `,Ki?.prepend(s),n===!0&&ig()<=0&&qb(),console.log("\u{1F335} Debug console has loaded")}},e.onerror=()=>{console.warn("\u{1F335} Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),nc=!1,ni=null},e.src="https://cdn.jsdelivr.net/npm/vconsole@3.9.1/dist/vconsole.min.js",document.body.appendChild(e)}function Wk(){if(!globalThis.VConsole)return;const n=new VConsole.VConsolePlugin("needle-console","\u{1F335} Inspect glTF"),e=()=>document.querySelector("#__vc_plug_"+n._id+" iframe");return n.on("renderTab",function(t){const s=globalThis["needle:codegen_files"];if(!s||s.length===0)return;let o=globalThis["needle:codegen_files"][0];const r=o.indexOf("?");r>-1&&(o=o.substring(0,r));const l=location.protocol+"//"+location.host+location.pathname+"/"+o,c=encodeURIComponent(l);n.fullUrl="https://viewer.needle.tools?inspect&file="+c;var h='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';t(h)}),n.on("show",function(){const t=e();t&&t.src!==n.fullUrl&&(t.src=n.fullUrl)}),n.on("hide",function(){const t=e();t&&(t.src="")}),n.on("addTopBar",function(t){var s=new Array;s.push({name:"Open in new window \u2197",onClick:function(o){window.open(n.fullUrl,"_blank"),ni?.hide()}}),s.push({name:"Reload",onClick:function(o){const r=e();r&&(r.src=n.fullUrl)}}),s.push({name:"Fullscreen",onClick:function(o){const r=e();r.requestFullscreen?r.requestFullscreen():r.webkitRequestFullscreen instanceof Function&&r.webkitRequestFullscreen()}}),t(s)}),n}function Vk(){return document.querySelector("#__vconsole .vc-switch")||null}function $k(){return document.querySelector("#__vconsole")||null}const Kb=C("debugdefines");_o('if(!globalThis["NEEDLE_ENGINE_VERSION"]) globalThis["NEEDLE_ENGINE_VERSION"] = "0.0.0";'),_o('if(!globalThis["NEEDLE_ENGINE_GENERATOR"]) globalThis["NEEDLE_ENGINE_GENERATOR"] = "unknown";'),_o('if(!globalThis["NEEDLE_PROJECT_BUILD_TIME"]) globalThis["NEEDLE_PROJECT_BUILD_TIME"] = "unknown";'),_o('if(!globalThis["NEEDLE_PUBLIC_KEY"]) globalThis["NEEDLE_PUBLIC_KEY"] = "unknown";'),_o('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.7.2-alpha";'),_o('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";'),_o('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Fri Aug 01 2025 14:15:44 GMT+0000 (Coordinated Universal Time)";'),_o('globalThis["__NEEDLE_PUBLIC_KEY__"] = "'+NEEDLE_PUBLIC_KEY+'";');const _s="4.7.2-alpha",Dd="undefined",wg="Fri Aug 01 2025 14:15:44 GMT+0000 (Coordinated Universal Time)";Kb&&console.log(`Engine version: ${_s} (generator: ${Dd})
146
+ Project built at ${wg}`);const Ea=NEEDLE_PUBLIC_KEY,An="needle_isActiveInHierarchy",wr="builtin_components",rc="needle_editor_guid";function _o(n){try{(0,eval)(n)}catch(e){Kb&&console.error(e)}}let Zb,Jb=null;function ws(){return Zb}function xg(n){if(n==null){console.warn("Oh no: someone tried registering a non-existend gltf-loader. When you see this log it might mean that needle-engine is being imported multiple times. Please check your project setup.");return}Jb!==n&&(Jb=n,Zb=new n)}const Mi=Symbol("shadowDomOwner"),Hk=C("debugpatch");function Bd(n,e,t,s){const o=Hk===e;if(!t&&!s)return;const r=e+"___needle";qk(n,e,t,s);const l=Object.getOwnPropertyDescriptor(n,e),c=n[e];o&&console.log("Patch",n.constructor.name,e,l,c),l?(o&&console.log("Apply patch with existing descriptor",n.constructor.name,e,l),typeof l.value=="function"&&(n[e]=t_(l.value,n,e))):(o&&console.log("Create patch with new property",n.constructor.name,e,l),Object.defineProperty(n,e,{set:function(h){if(typeof h=="function")this[r]=t_(h,n,e);else{const d=this[r];i_(n,e,this,d,h),this[r]=h,s_(n,e,this,d,h)}},get:function(){const h=this[r];return typeof h=="function"&&h[r]?h[r]:h}}))}function Gk(n,e,t){const s=Cg(n,e);if(s)for(let o=s.length-1;o>=0;o--){const r=s[o];r.prefix===t&&(r.prefix=null),r.postfix===t&&(r.postfix=null),!r.prefix&&!r.postfix&&s.splice(o,1)}}const e_=Symbol("Needle:Patches:WrappedFunction");function t_(n,e,t){if(n[e_])return n;const s=function(...o){i_(e,t,this,...o);const r=n.apply(this,o);return s_(e,t,this,r,...o),r};return s[e_]=!0,s}const Fd="Needle:Patches";function Sg(){return globalThis[Fd]||(globalThis[Fd]=new WeakMap),globalThis[Fd]}function Cg(n,e){const t=Sg().get(n);return t?t.get(e):null}function qk(n,e,t,s){let o=Sg().get(n);o||(o=new Map,Sg().set(n,o));let r=o.get(e);r||(r=[],o.set(e,r)),r.push({prefix:t,postfix:s})}function i_(n,e,t,...s){var o;if(!t)return;const r=Cg(n,e);if(r)for(const l of r)(o=l.prefix)==null||o.call(t,...s)}function s_(n,e,t,s,...o){var r;if(!t)return;const l=Cg(n,e);if(l)for(const c of l)(r=c.postfix)==null||r.call(t,s,...o)}const Aa=[];function Ud(n){Aa.indexOf(n)===-1&&Aa.push(n)}function Xk(n){const e=Aa.indexOf(n);e!==-1&&Aa.splice(e,1)}const Ia=[];function Pg(n){Ia.indexOf(n)===-1&&Ia.push(n)}function Qk(n){const e=Ia.indexOf(n);e!==-1&&Ia.splice(e,1)}function n_(n){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-start",{detail:n}));for(let e=0;e<Aa.length;e++)Aa[e](n)}function o_(n){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-end",{detail:n}));for(let e=0;e<Ia.length;e++)Ia[e](n)}const ct=C("debuginput");var zd=(n=>(n.Mouse="mouse",n.Touch="touch",n.Controller="controller",n.Hand="hand",n))(zd||{}),Be=(n=>(n.PointerDown="pointerdown",n.PointerUp="pointerup",n.PointerMove="pointermove",n.KeyDown="keydown",n.KeyUp="keyup",n.KeyPressed="keypress",n))(Be||{});class In extends PointerEvent{constructor(e,t,s){super(e,s),a(this,"clientZ"),a(this,"deviceIndex"),a(this,"origin"),a(this,"source"),a(this,"mode"),a(this,"_ray"),a(this,"space"),a(this,"isClick",!1),a(this,"isDoubleClick",!1),a(this,"_used",!1),a(this,"_pointerid"),a(this,"_pointerType"),a(this,"_type"),a(this,"metadata",{}),a(this,"intersections",new Array),a(this,"_immediatePropagationStopped",!1),a(this,"_propagationStopped",!1),this.clientZ=s.clientZ,this._pointerid=s.pointerId,this._pointerType=s.pointerType,this._type=e,this.deviceIndex=s.deviceIndex,this.origin=s.origin,this.source=t,this.mode=s.mode,this._ray=s.ray,this.space=s.device}get isSpatial(){return this.mode!="screen"}get ray(){return this._ray||(this._ray=new mo(this.space.worldPosition.clone(),this.space.worldForward.clone())),this._ray}set ray(e){this._ray=e}get hasRay(){return this._ray!==void 0}get used(){return this._used}use(){this._used=!0}get pointerId(){return this._pointerid}get pointerType(){return this._pointerType}get type(){return this._type}get immediatePropagationStopped(){return this._immediatePropagationStopped}get propagationStopped(){return this._immediatePropagationStopped||this._propagationStopped}stopImmediatePropagation(){var e;this._immediatePropagationStopped=!0,super.stopImmediatePropagation(),(e=this.source)==null||e.stopImmediatePropagation()}stopPropagation(){var e;this._propagationStopped=!0,super.stopPropagation(),(e=this.source)==null||e.stopPropagation(),ct&&console.warn("Stop propagation...",this.pointerId,this.pointerType)}}class ac extends KeyboardEvent{constructor(e,t,s){super(e,s),a(this,"source"),this.source=t}stopImmediatePropagation(){var e;super.stopImmediatePropagation(),(e=this.source)==null||e.stopImmediatePropagation()}}class Yk{constructor(e){a(this,"key"),a(this,"keyType"),a(this,"source"),this.key=e.key,this.keyType=e.type,this.source=e}}var oi=(n=>(n[n.Early=-100]="Early",n[n.Default=0]="Default",n[n.Late=100]="Late",n))(oi||{});class r_{constructor(e){a(this,"_eventListeners",{}),a(this,"_doubleClickTimeThreshold",.2),a(this,"_longPressTimeThreshold",1),a(this,"_setCursorTypes",[]),a(this,"context"),a(this,"_pointerDown",[!1]),a(this,"_pointerUp",[!1]),a(this,"_pointerClick",[!1]),a(this,"_pointerDoubleClick",[!1]),a(this,"_pointerPressed",[!1]),a(this,"_pointerPositions",[new re]),a(this,"_pointerPositionsLastFrame",[new re]),a(this,"_pointerPositionsDelta",[new re]),a(this,"_pointerPositionsRC",[new re]),a(this,"_pointerPositionDown",[new S]),a(this,"_pointerDownTime",[]),a(this,"_pointerUpTime",[]),a(this,"_pointerUpTimestamp",[]),a(this,"_pointerIds",[]),a(this,"_pointerTypes",[""]),a(this,"_mouseWheelChanged",[!1]),a(this,"_mouseWheelDeltaY",[0]),a(this,"_pointerEvent",[]),a(this,"_pointerEventsPressed",[]),a(this,"_pointerSpace",[]),a(this,"_pressedStack",new Map),a(this,"_htmlEventSource"),a(this,"onLostFocus",()=>{for(const t in this.keysPressed)this.keysPressed[t].pressed=!1}),a(this,"_receivedPointerMoveEventsThisFrame",new Array),a(this,"onEndOfFrame",()=>{this._receivedPointerMoveEventsThisFrame.length=0;for(let t=0;t<this._pointerUp.length;t++)this._pointerUp[t]=!1;for(let t=0;t<this._pointerDown.length;t++)this._pointerDown[t]=!1;for(let t=0;t<this._pointerClick.length;t++)this._pointerClick[t]=!1;for(let t=0;t<this._pointerDoubleClick.length;t++)this._pointerDoubleClick[t]=!1;for(const t of this._pointerPositionsDelta)t.set(0,0);for(let t=0;t<this._mouseWheelChanged.length;t++)this._mouseWheelChanged[t]=!1;for(let t=0;t<this._mouseWheelDeltaY.length;t++)this._mouseWheelDeltaY[t]=0}),a(this,"onContextMenu",t=>{this.canReceiveInput(t)!==!1&&t instanceof PointerEvent&&t.pointerType}),a(this,"keysPressed",{}),a(this,"onKeyDown",t=>{if(ct&&console.log(`key down ${t.code}, ${this.context.application.hasFocus}`,t),!this.context.application.hasFocus)return;const s=this.keysPressed[t.code];if(s&&s.pressed)return;this.keysPressed[t.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:t.key,code:t.code};const o=new ac("keydown",t,t);this.onDispatchEvent(o)}),a(this,"onKeyPressed",t=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[t.code];if(!s)return;s.pressed=!0,s.frame=this.context.time.frameCount+1;const o=new ac("keypress",t,t);this.onDispatchEvent(o)}),a(this,"onKeyUp",t=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[t.code];if(!s)return;s.pressed=!1,s.frame=this.context.time.frameCount+1;const o=new ac("keyup",t,t);this.onDispatchEvent(o)}),a(this,"onWheelWindow",t=>{document.pointerLockElement&&this.onMouseWheel(t)}),a(this,"onMouseWheel",t=>{if(this.canReceiveInput(t)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const s=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=s+t.deltaY}),a(this,"onPointerDown",t=>{if(this.context.isInAR||this.canReceiveInput(t)===!1)return;t.target instanceof HTMLElement&&t.target.setPointerCapture(t.pointerId);const s=this.getPointerId(t);ct&&De(`pointer down #${s}, identifier:${t.pointerId}`);const o=this.getAndUpdateSpatialObjectForScreenPosition(s,t.clientX,t.clientY),r=new In("pointerdown",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:s,button:t.button,clientX:t.clientX,clientY:t.clientY,pointerType:t.pointerType,buttonName:this.getButtonName(t),device:o,pressure:t.pressure});this.onDown(r)}),a(this,"onPointerMove",t=>{if(this.context.isInAR||this._receivedPointerMoveEventsThisFrame.includes(t.pointerId))return;this._receivedPointerMoveEventsThisFrame.push(t.pointerId);let s=t.button;t.pointerType==="mouse"&&(s=this.getFirstPressedButtonForPointer(0)??0);const o=this.getPointerId(t,s);s===-1&&(s=o);const r=this.getAndUpdateSpatialObjectForScreenPosition(o,t.clientX,t.clientY),l=new In("pointermove",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:o,button:s,clientX:t.clientX,clientY:t.clientY,pointerType:t.pointerType,buttonName:this.getButtonName(t),device:r,pressure:t.pressure});this.onMove(l)}),a(this,"onPointerCancel",t=>{this.context.isInAR||(ct&&console.log("Pointer cancel",t),this.onPointerUp(t))}),a(this,"onPointerUp",t=>{if(this.context.isInAR)return;t.target instanceof HTMLElement&&t.target.releasePointerCapture(t.pointerId);const s=this.getPointerId(t),o=new In("pointerup",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:s,button:t.button,clientX:t.clientX,clientY:t.clientY,pointerType:t.pointerType,buttonName:this.getButtonName(t),device:this.getAndUpdateSpatialObjectForScreenPosition(s,t.clientX,t.clientY),pressure:t.pressure});this.onUp(o),this._pointerIds[s]=-1,ct&&console.log("ID="+s,"PointerId="+t.pointerId,"ALL:",[...this._pointerIds])}),a(this,"onTouchStart",t=>{if(this.context.isInAR)for(let s=0;s<t.changedTouches.length;s++){const o=t.changedTouches[s],r=this.getPointerIndex(o.identifier),l=this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),c=new In("pointerdown",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:l,pressure:o.force});this.onDown(c)}}),a(this,"onTouchMove",t=>{if(this.context.isInAR)for(let s=0;s<t.changedTouches.length;s++){const o=t.changedTouches[s],r=this.getPointerIndex(o.identifier),l=this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),c=new In("pointermove",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:l,pressure:o.force});this.onMove(c)}}),a(this,"onTouchEnd",t=>{if(this.context.isInAR)for(let s=0;s<t.changedTouches.length;s++){const o=t.changedTouches[s],r=this.getPointerIndex(o.identifier),l=new In("pointerup",t,{origin:this,mode:"screen",deviceIndex:0,pointerId:r,button:0,clientX:o.clientX,clientY:o.clientY,pointerType:"touch",buttonName:"unknown",device:this.getAndUpdateSpatialObjectForScreenPosition(r,o.clientX,o.clientY),pressure:o.force});this.onUp(l),this._pointerIds[r]=-1}}),a(this,"tempNearPlaneVector",new S),a(this,"tempFarPlaneVector",new S),a(this,"tempLookMatrix",new se),this.context=e,this.context.post_render_callbacks.push(this.onEndOfFrame)}addEventListener(e,t,s){if(this._eventListeners[e]||(this._eventListeners[e]=[]),!t||typeof t!="function"){console.error("Invalid call to addEventListener: callback is required and must be a function!");return}s?s={...s}:s={};let o=0;s?.queue!=null&&(o=s.queue);const r=this._eventListeners[e],l=r.find(c=>c.priority===o);l?l.listeners.push({callback:t,options:s}):(r.push({priority:o,listeners:[{callback:t,options:s}]}),r.sort((c,h)=>c.priority-h.priority))}removeEventListener(e,t,s){if(!this._eventListeners[e]||!t)return;const o=this._eventListeners[e];if(s?.queue!=null){const r=o.find(c=>c.priority===s.queue);if(!r)return;const l=r.listeners.findIndex(c=>c.callback===t);l>=0&&r.listeners.splice(l,1)}else for(const r of o){const l=r.listeners.findIndex(c=>c.callback===t);l>=0&&r.listeners.splice(l,1)}}dispatchEvent(e){var t,s,o,r;let l=!1;if(e instanceof ac){const c=this._eventListeners[e.type];if(c)for(const h of c)for(let d=0;d<h.listeners.length;d++){const u=h.listeners[d];if((s=(t=u.options)==null?void 0:t.signal)!=null&&s.aborted){h.listeners.splice(d,1),d--;continue}u.options.once&&(h.listeners.splice(d,1),d--),u.callback(e)}}if(e instanceof In){const c=this._eventListeners[e.type];if(c)for(const h of c){if(l)break;for(let d=0;d<h.listeners.length;d++){const u=h.listeners[d];if((r=(o=u.options)==null?void 0:o.signal)!=null&&r.aborted){h.listeners.splice(d,1),d--;continue}if(e.immediatePropagationStopped){l=!0,ct&&console.log("immediatePropagationStopped",e.type);break}else e.propagationStopped&&(l=!0,ct&&console.log("propagationStopped",e.type));u.options.once&&(h.listeners.splice(d,1),d--),u.callback(e)}}}}get mousePosition(){return this._pointerPositions[0]}get mousePositionRC(){return this._pointerPositionsRC[0]}get mouseDown(){return this._pointerDown[0]}get mouseUp(){return this._pointerUp[0]}get mouseClick(){return this._pointerClick[0]}get mouseDoubleClick(){return this._pointerDoubleClick[0]}get mousePressed(){return this._pointerPressed[0]}get mouseWheelChanged(){return this.getMouseWheelChanged(0)}get click(){return this._pointerClick[0]}get doubleClick(){return this._pointerDoubleClick[0]}getGamepad(e=0){return typeof navigator<"u"&&"getGamepads"in navigator&&navigator.getGamepads()[e]||null}setCursorPointer(){this.setCursor("pointer")}setCursorNormal(){this.unsetCursor("pointer")}setCursor(e){this._setCursorTypes.push(e),this._setCursorTypes.length>10&&this._setCursorTypes.shift(),this.updateCursor()}unsetCursor(e){for(let t=this._setCursorTypes.length-1;t>=0;t--)if(this._setCursorTypes[t]===e){this._setCursorTypes.splice(t,1),this.updateCursor();break}}updateCursor(){var e;((e=this._setCursorTypes)==null?void 0:e.length)==0?this.context.domElement.style.cursor="default":this.context.domElement.style.cursor=this._setCursorTypes[this._setCursorTypes.length-1]}getIsPointerIdInUse(e){for(const t of this._pointerEventsPressed)if(t.pointerId===e&&t.used)return!0;return!1}getPointerPressedCount(){let e=0;for(let t=0;t<this._pointerPressed.length;t++)this._pointerPressed[t]&&e++;return e}getPointerPosition(e){return e>=this._pointerPositions.length?null:this._pointerPositions[e]}getPointerPositionLastFrame(e){return e>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[e]}getPointerPositionDelta(e){return e>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[e]}getPointerPositionRC(e){return e>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[e]}getPointerDown(e){return e>=this._pointerDown.length?!1:this._pointerDown[e]}getPointerUp(e){return e>=this._pointerUp.length?!1:this._pointerUp[e]}getPointerPressed(e){return e>=this._pointerPressed.length?!1:this._pointerPressed[e]}getPointerClicked(e){return e>=this._pointerClick.length?!1:this._pointerClick[e]}getPointerDoubleClicked(e){return e>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[e]}getPointerDownTime(e){return e>=this._pointerDownTime.length?-1:this._pointerDownTime[e]}getPointerUpTime(e){return e>=this._pointerUpTime.length?-1:this._pointerUpTime[e]}getPointerLongPress(e){return e>=this._pointerDownTime.length?!1:this.getPointerPressed(e)&&this.context.time.time-this._pointerDownTime[e]>this._longPressTimeThreshold}getIsMouse(e){return e<0||e>=this._pointerTypes.length?!1:this._pointerTypes[e]==="mouse"}getIsTouch(e){return e<0||e>=this._pointerTypes.length?!1:this._pointerTypes[e]==="touch"}getTouchesPressedCount(){let e=0;for(let t=0;t<this._pointerPressed.length;t++)this._pointerPressed[t]&&this.getIsTouch(t)&&e++;return e}getMouseWheelChanged(e=0){return e>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[e]}getMouseWheelDeltaY(e=0){return e>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[e]}getPointerEvent(e){if(!(e>=this._pointerEvent.length))return this._pointerEvent[e]??void 0}*foreachPointerId(e){for(let t=0;t<this._pointerTypes.length;t++)if(this._pointerIsActive(t)){if(e!==void 0){const s=this._pointerTypes[t];if(Array.isArray(e)){let o=!1;for(const r of e)if(s===r){o=!0;break}if(!o)continue}else if(e!==s)continue}yield t}}*foreachTouchId(){for(let e=0;e<this._pointerTypes.length;e++)this._pointerTypes[e]==="touch"&&this._pointerIsActive[e]&&(yield e)}_pointerIsActive(e){return e<0?!1:this._pointerPressed[e]||this._pointerDown[e]||this._pointerUp[e]}onDownButton(e,t){let s=this._pressedStack.get(e);s||(s=[],this._pressedStack.set(e,s)),s.push(t)}onReleaseButton(e,t){const s=this._pressedStack.get(e);if(!s)return;const o=s.indexOf(t);o>=0&&s.splice(o,1)}getFirstPressedButtonForPointer(e){const t=this._pressedStack.get(e);if(t)return t[0]}getLatestPressedButtonForPointer(e){const t=this._pressedStack.get(e);if(t)return t[t.length-1]}getKeyDown(e){if(e!==void 0)return this.isKeyDown(e);for(const t in this.keysPressed){const s=this.keysPressed[t];if(s.startFrame===this.context.time.frameCount)return s.key}return null}getKeyPressed(e){if(e!==void 0)return this.isKeyPressed(e);for(const t in this.keysPressed){const s=this.keysPressed[t];if(s.pressed)return s.key}return null}getKeyUp(e){if(e!==void 0)return this.isKeyUp(e);for(const t in this.keysPressed){const s=this.keysPressed[t];return s.pressed===!1&&s.frame===this.context.time.frameCount}return null}isKeyDown(e){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const t=this.getCodeForCommonKeyName(e);if(t!==null){for(const o of t)if(this.isKeyDown(o))return!0;return!1}const s=this.keysPressed[e];return s?s.startFrame===this.context.time.frameCount&&s.pressed:!1}isKeyUp(e){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const t=this.getCodeForCommonKeyName(e);if(t!==null){for(const o of t)if(this.isKeyUp(o))return!0;return!1}const s=this.keysPressed[e];return s?s.frame===this.context.time.frameCount&&s.pressed===!1:!1}isKeyPressed(e){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const t=this.getCodeForCommonKeyName(e);if(t!==null){for(const o of t)if(this.isKeyPressed(o))return!0;return!1}const s=this.keysPressed[e];return s&&s.pressed||!1}getCodeForCommonKeyName(e){if(e.length===1){if(e>="0"&&e<="9")return["Digit"+e];if(e>="a"&&e<="z")return["Key"+e.toUpperCase()];if(e==" ")return["Space"]}switch(e){case"shift":case"Shift":return["ShiftLeft","ShiftRight"];case"control":case"Control":return["ControlLeft","ControlRight"];case"alt":case"Alt":return["AltLeft","AltRight"]}return null}createInputEvent(e){switch(e.type){case"pointerdown":ct&&De("Create Pointer down"),this.onDownButton(e.deviceIndex,e.button),this.onDown(e);break;case"pointermove":ct&&De("Create Pointer move"),this.onMove(e);break;case"pointerup":ct&&De("Create Pointer up"),this.onUp(e),this.onReleaseButton(e.deviceIndex,e.button);break}}convertScreenspaceToRaycastSpace(e){return e.x=(e.x-this.context.domX)/this.context.domWidth*2-1,e.y=-((e.y-this.context.domY)/this.context.domHeight)*2+1,e}bindEvents(){this.unbindEvents(),this._htmlEventSource=this.context.renderer.domElement,window.addEventListener("contextmenu",this.onContextMenu),this._htmlEventSource.addEventListener("pointerdown",this.onPointerDown,{passive:!0}),window.addEventListener("pointermove",this.onPointerMove,{passive:!0,capture:!0}),window.addEventListener("pointerup",this.onPointerUp,{passive:!0}),window.addEventListener("pointercancel",this.onPointerCancel,{passive:!0}),window.addEventListener("touchstart",this.onTouchStart,{passive:!0}),window.addEventListener("touchmove",this.onTouchMove,{passive:!0}),window.addEventListener("touchend",this.onTouchEnd,{passive:!0}),this._htmlEventSource.addEventListener("wheel",this.onMouseWheel,{passive:!0}),window.addEventListener("wheel",this.onWheelWindow,{passive:!0}),window.addEventListener("keydown",this.onKeyDown,!1),window.addEventListener("keypress",this.onKeyPressed,!1),window.addEventListener("keyup",this.onKeyUp,!1),window.addEventListener("blur",this.onLostFocus)}unbindEvents(){var e,t;window.removeEventListener("contextmenu",this.onContextMenu),(e=this._htmlEventSource)==null||e.removeEventListener("pointerdown",this.onPointerDown),window.removeEventListener("pointermove",this.onPointerMove),window.removeEventListener("pointerup",this.onPointerUp),window.removeEventListener("pointercancel",this.onPointerCancel),window.removeEventListener("touchstart",this.onTouchStart),window.removeEventListener("touchmove",this.onTouchMove),window.removeEventListener("touchend",this.onTouchEnd),(t=this._htmlEventSource)==null||t.removeEventListener("wheel",this.onMouseWheel,!1),window.removeEventListener("wheel",this.onWheelWindow,!1),window.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("keypress",this.onKeyPressed,!1),window.removeEventListener("keyup",this.onKeyUp,!1),window.removeEventListener("blur",this.onLostFocus)}dispose(){const e=this.context.post_render_callbacks.indexOf(this.onEndOfFrame);e>=0&&this.context.post_render_callbacks.splice(e,1),this.unbindEvents()}canReceiveInput(e){var t;return e.target===((t=this.context.renderer)==null?void 0:t.domElement)||e.target===this.context.domElement||this.context.isInAR||this.context.isInAR&&e.target===document.body&&X.isMozillaXR()?!0:(ct&&console.warn("CanReceiveInput:False for",e.target),!1)}getPointerId(e,t){return e.pointerType==="mouse"?0+(t??e.button):this.getPointerIndex(e.pointerId)}getButtonName(e){const t=e.button;if(e.pointerType==="mouse")switch(t){case 0:return"left";case 1:return"middle";case 2:return"right"}return"unknown"}getAndUpdateSpatialObjectForScreenPosition(e,t,s){let o=this._pointerSpace[e];o||(o=new E,this._pointerSpace[e]=o),this._pointerSpace[e]=o;const r=this.context.mainCamera;if(r){const l=this.tempNearPlaneVector.set(t,s,-1);this.convertScreenspaceToRaycastSpace(l);const c=this.tempFarPlaneVector.set(l.x,l.y,1);l.unproject(r),c.unproject(r);const h=r.worldUp||q(0,1,0).applyQuaternion(Se(r));this.tempLookMatrix.lookAt(c,l,h),o.position.set(l.x,l.y,l.z),o.quaternion.setFromRotationMatrix(this.tempLookMatrix)}return o}isInRect(e){if(this.context.isInXR)return!0;const t=this.context.domElement.getBoundingClientRect(),s=e.clientX,o=e.clientY,r=s>=t.x&&s<=t.right&&o>=t.y&&o<=t.bottom;return ct&&!r&&console.log("Not in rect",t,s,o),r}onDown(e){const t=e.pointerId;if(this.getPointerPressed(t)&&console.warn(`Received pointerDown for pointerId that is already pressed: ${t}`,ct?e:""),ct&&console.log(e.pointerType,"DOWN",t),!!this.isInRect(e)){for(this.setPointerState(t,this._pointerPressed,!0),this.setPointerState(t,this._pointerDown,!0),this.setPointerStateT(t,this._pointerEvent,e.source);t>=this._pointerTypes.length;)this._pointerTypes.push(e.pointerType);for(this._pointerTypes[t]=e.pointerType;t>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new S);for(this._pointerPositionDown[t].set(e.clientX,e.clientY,e.clientZ??0);t>=this._pointerPositions.length;)this._pointerPositions.push(new re);this._pointerPositions[t].set(e.clientX,e.clientY),t>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[t]=this.context.time.realtimeSinceStartup,this.updatePointerPosition(e),this._pointerEventsPressed.push(e),this.onDispatchEvent(e)}}onMove(e){const t=e.pointerId,s=this.getPointerPressed(t);s===!1&&!this.isInRect(e)||e.pointerType==="touch"&&!s||(this.updatePointerPosition(e),this.setPointerStateT(t,this._pointerEvent,e.source),this.onDispatchEvent(e))}onUp(e){const t=e.pointerId;if(!this.getPointerPressed(t)){ct&&console.log(e.pointerType,"UP",t,"was not down");return}ct&&console.log(e.pointerType,"UP",t),this.setPointerState(t,this._pointerPressed,!1),this.setPointerStateT(t,this._pointerEvent,e.source),this.setPointerState(t,this._pointerUp,!0),this.updatePointerPosition(e);for(let c=this._pointerEventsPressed.length-1;c>=0;c--)if(this._pointerEventsPressed[c].pointerId===t){this._pointerEventsPressed.splice(c,1);break}if(!this._pointerPositionDown[t]){ct&&be("Received pointer up event without matching down event for button: "+t),console.warn("Received pointer up event without matching down event for button: "+t);return}const s=this._pointerUpTime[t],o=this._pointerDownTime[t],r=this.context.time.realtimeSinceStartup,l=r-o;if(t>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),this._pointerUpTime[t]=r,l<1){let c=e.clientX-this._pointerPositionDown[t].x,h=e.clientY-this._pointerPositionDown[t].y,d=0;if(e.isSpatial&&e.clientZ!=null&&(d=e.clientZ-this._pointerPositionDown[t].z,c*=200,h*=200,d*=200),Math.abs(c)<5&&Math.abs(h)<5&&Math.abs(d)<5){this.setPointerState(t,this._pointerClick,!0),e.isClick=!0;const u=r-s;ct&&console.log("CLICK",t,c,h,d,u),u<this._doubleClickTimeThreshold&&u>0&&(this.setPointerState(t,this._pointerDoubleClick,!0),e.isDoubleClick=!0)}}this.onDispatchEvent(e)}updatePointerPosition(e){const t=e.pointerId;for(;t>=this._pointerPositions.length;)this._pointerPositions.push(new re);for(;t>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new re);for(;t>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new re);const s=this._pointerPositionsLastFrame[t];s.copy(this._pointerPositions[t]);const o=this._pointerPositionsDelta[t];let r=e.clientX-s.x,l=e.clientY-s.y;if(e.source instanceof MouseEvent||e.source instanceof TouchEvent){const u=e.source;r===0&&u.movementX!==0&&(r=u.movementX||0),l===0&&u.movementY!==0&&(l=u.movementY||0)}o.x+=r,o.y+=l,this._pointerPositions[t].x=e.clientX,this._pointerPositions[t].y=e.clientY;const c=e.clientX,h=e.clientY;for(;t>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new re);const d=this._pointerPositionsRC[t];d.set(c,h),this.convertScreenspaceToRaycastSpace(d)}getPointerIndex(e){let t=-1;for(let s=0;s<this._pointerIds.length;s++){if(this._pointerIds[s]===e)return s;t===-1&&this._pointerIds[s]===-1&&(t=s)}return t!==-1?(this._pointerIds[t]=e,t):(ct&&console.log("PUSH pointerId:",e),this._pointerIds.push(e),this._pointerIds.length-1)}setPointerState(e,t,s){t[e]=s}setPointerStateT(e,t,s){return t[e]=s,s}onDispatchEvent(e){const t=J.Current;try{J.Current=this.context,this.dispatchEvent(e)}finally{J.Current=t}}}const La=new se().makeRotationY(Math.PI),Zi=new V().setFromAxisAngle(new S(0,1,0),Math.PI),Kk=C("debugwebxr");class Zk{constructor(){if(a(this,"priority",-1e5),a(this,"gameObject"),this.gameObject=new E,this.gameObject.name="Implicit XR Rig",Kk){const e=$g(16733661);e.position.y+=.5,this.gameObject.add(e)}}isXRRig(){return!0}get isActive(){return this.gameObject.visible}}const Ln=C("debugwebxr"),Nd=C("debugcustomgesture"),Jk="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",eM="generic-trigger",tM=new V().setFromEuler(new Bt(Pn.degToRad(0),Pn.degToRad(-90),Pn.degToRad(-90))),iM=new S(.04,-.04,0);class Og{constructor(e,t,s){a(this,"xr"),a(this,"inputSource"),a(this,"index",0),a(this,"emitEvents",!0),a(this,"_connected",!0),a(this,"_isTracking",!1),a(this,"__gamepad"),a(this,"__hand"),a(this,"__side"),a(this,"_hitTestSource"),a(this,"_hasSelectEvent",!1),a(this,"_isMxInk",!1),a(this,"_isMetaQuestTouchController",!1),a(this,"_handJointPoses",new Map),a(this,"_gripMatrix",new se),a(this,"_gripPosition",new S),a(this,"_gripQuaternion",new V),a(this,"_linearVelocity",new S),a(this,"_rayPositionRaw",new S),a(this,"_rayRotationRaw",new V),a(this,"_rayMatrix",new se),a(this,"_rayPosition",new S),a(this,"_rayQuaternion",new V),a(this,"_gripWorldPosition",new S),a(this,"_gripWorldQuaternion",new V),a(this,"_rayWorldPosition",new S),a(this,"_rayWorldQuaternion",new V),a(this,"_pinchPosition",new S),a(this,"_ray"),a(this,"_hand_wristDotUp"),a(this,"_object"),a(this,"_gripSpaceObject"),a(this,"_raySpaceObject"),a(this,"model",null),a(this,"_debugAxesHelper",new Ci(.15)),a(this,"_debugGripAxesHelper",new Ci(.07)),a(this,"_debugRayAxesHelper",new Ci(.07)),a(this,"_hitTestSourcePromise",null),a(this,"onPointerHits",o=>{}),a(this,"_needleGamepadButtons",{}),a(this,"_buttonMap",new Map),a(this,"_motioncontroller"),a(this,"_layout"),a(this,"getMotionController"),a(this,"emitPointerDownEvent",!0),a(this,"emitPointerUpEvent",!0),a(this,"emitPointerMoveEvent",!0),a(this,"pointerMoveDistanceThreshold",.03),a(this,"pointerMoveAngleThreshold",.05),a(this,"_selectButtonIndex"),a(this,"_squeezeButtonIndex"),a(this,"onSelectStart",o=>{var r,l,c,h;if(!this.emitPointerDownEvent||this.inputSource!==o.inputSource)return;this.onUpdateFrame(o.frame),this._hasSelectEvent=!0;const d=(r=this._layout)==null?void 0:r.selectComponentId,u=(h=(c=(l=this._layout)==null?void 0:l.components[d])==null?void 0:c.gamepadIndices)==null?void 0:h.button;u!==void 0&&(this._selectButtonIndex=u),!Nd&&(Ln&&$.DrawDirection(this.rayWorldPosition,q(0,.01,1).applyQuaternion(this.rayWorldQuaternion),16711680,10),this.emitPointerEvent(Be.PointerDown,this._selectButtonIndex||0,"xr-standard-trigger",!0,o))}),a(this,"onSelectEnd",o=>{this.emitPointerUpEvent&&(Nd||this.inputSource===o.inputSource&&this.emitPointerEvent(Be.PointerUp,this._selectButtonIndex||0,"xr-standard-trigger",!0,o))}),a(this,"onSequeezeStart",o=>{var r,l,c;this.emitPointerDownEvent&&this.inputSource===o.inputSource&&(this._squeezeButtonIndex=(c=(l=(r=this._layout)==null?void 0:r.components["xr-standard-squeeze"])==null?void 0:l.gamepadIndices)==null?void 0:c.button,this._squeezeButtonIndex!==void 0&&(Ln&&$.DrawDirection(this.rayWorldPosition,q(0,.01,1).applyQuaternion(this.rayWorldQuaternion),255,10),this.emitPointerEvent(Be.PointerDown,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,o)))}),a(this,"onSequeezeEnd",o=>{this.emitPointerUpEvent&&this.inputSource===o.inputSource&&this._squeezeButtonIndex!==void 0&&this.emitPointerEvent(Be.PointerUp,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,o)}),a(this,"states",{}),a(this,"_didMoveLastFrame",!1),a(this,"_lastPointerMovePosition",new S),a(this,"_lastPointerMoveQuaternion",new V),a(this,"pointerInit"),this.xr=e,this.inputSource=t,this.index=s,this._object=new E,this._object.name=`NeedleXRController_${s}`,Ln&&(this._object.add(this._debugAxesHelper),this._gripSpaceObject=new E,this._raySpaceObject=new E,this._gripSpaceObject.name=`NeedleXRController_${s}_gripSpace`,this._raySpaceObject.name=`NeedleXRController_${s}_raySpace`,this._gripSpaceObject.add(this._debugGripAxesHelper),this._raySpaceObject.add(this._debugRayAxesHelper),this.xr.context.scene.add(this._gripSpaceObject),this.xr.context.scene.add(this._raySpaceObject)),this.xr.context.scene.add(this._object),this._ray=new mo,this.pointerInit={origin:this,pointerType:this.hand?"hand":"controller",deviceIndex:this.index,pointerId:-1,mode:this.inputSource.targetRayMode,ray:this._ray,device:this._object,buttonName:"none"},this.initialize(),this.subscribeEvents()}get context(){return this.xr.context}get connected(){return this._connected}get isTracking(){return this._isTracking}get gamepad(){return this.__gamepad??(this.__gamepad=this.inputSource.gamepad)}get isHand(){return this.hand!=null}get hand(){return this.__hand??(this.__hand=this.inputSource.hand)}get handObject(){return this.context.renderer.xr.getHand(this.index)}get profiles(){return this.inputSource.profiles}get layout(){return this._layout}get targetRayMode(){return this.inputSource.targetRayMode}get targetRaySpace(){return this.inputSource.targetRaySpace}get gripSpace(){return this.inputSource.gripSpace}get side(){return this.__side??(this.__side=this.inputSource.handedness)}get isRight(){return this.side==="right"}get isLeft(){return this.side==="left"}get isStylus(){return this._isMxInk}getHitTestSource(){return this._hitTestSource||this._requestHitTestSource(),this._hitTestSource}get hasHitTestSource(){return this._hitTestSource}cancelHitTestSource(){this._hitTestSource&&(this._hitTestSource.cancel(),this._hitTestSource=void 0)}get hasSelectEvent(){return this._hasSelectEvent}getHitTest(){return this.xr.getHitTest(this)}getHandJointPose(e,t){var s;if(t=t||this.xr.frame,!this.hand||!(t!=null&&t.getJointPose)||!this.xr.referenceSpace)return null;let o=(s=this._handJointPoses)==null?void 0:s.get(e);return o||(o=t.getJointPose(e,this.xr.referenceSpace),o&&this._handJointPoses.set(e,o),o)}get gripPosition(){return q(this._gripPosition)}get gripQuaternion(){return vs(this._gripQuaternion)}get gripMatrix(){return this._gripMatrix}get gripLinearVelocity(){return q(this._linearVelocity).applyQuaternion(Zi)}get rayPosition(){return q(this._rayPosition)}get rayQuaternion(){return vs(this._rayQuaternion)}get gripWorldPosition(){return q(this._gripWorldPosition)}get gripWorldQuaternion(){return vs(this._gripWorldQuaternion)}get rayWorldPosition(){return q(this._rayWorldPosition)}updateRayWorldPosition(){var e;const t=(e=this.xr.context.mainCamera)==null?void 0:e.parent;this._rayWorldPosition.copy(this._rayPositionRaw),t&&this._rayWorldPosition.applyMatrix4(t.matrixWorld)}get rayWorldQuaternion(){return vs(this._rayWorldQuaternion)}get pinchPosition(){return q(this._pinchPosition)}updateRayWorldQuaternion(){var e;const t=(e=this.xr.context.mainCamera)==null?void 0:e.parent,s=t?Se(t):void 0;this._rayWorldQuaternion.copy(this._rayRotationRaw).multiply(Zi),s&&this._rayWorldQuaternion.premultiply(s)}get ray(){return this._ray.origin.copy(this.rayWorldPosition),this._ray.direction.copy(q(0,0,1).applyQuaternion(this.rayWorldQuaternion)),this._ray}get handWristDotUp(){var e;if(this._hand_wristDotUp!==void 0)return this._hand_wristDotUp;const t=(e=this.handObject)==null?void 0:e.joints.wrist;if(t){const s=q(0,1,0).applyQuaternion(t.quaternion),o=q(0,1,0).dot(s);return this._hand_wristDotUp=o}}get isHandUpsideDown(){return this.handWristDotUp!==void 0?this.handWristDotUp<-.7:!1}get isTeleportGesture(){var e;return this.isHandUpsideDown&&((e=this.getGesture("pinch"))==null?void 0:e.isDown)}get object(){return this._object}async getModelUrl(){var e;return(e=this.getMotionController)==null?void 0:e.then(t=>t?.assetUrl||null)}_requestHitTestSource(){var e;return this._hitTestSourcePromise?this._hitTestSourcePromise:this.xr.mode==="immersive-ar"&&this.inputSource.targetRayMode==="tracked-pointer"&&this.xr.session.requestHitTestSourceForTransientInput?this._hitTestSourcePromise=((e=this.xr.session.requestHitTestSourceForTransientInput({profile:this.inputSource.profiles[0],offsetRay:new XRRay}))==null?void 0:e.then(t=>(this._hitTestSourcePromise=null,this.connected?this._hitTestSource=t:(t.cancel(),null))))??null:null}onUpdate(e){this.onUpdateFrame(e),this.updateInputEvents(),this.onUpdateMove()}onRenderDebug(){var e;$.DrawSphere(this.rayWorldPosition,.003),$.DrawDirection(this.rayWorldPosition,q(0,0,10).applyQuaternion(this.rayWorldQuaternion));const t=(this.inputSource.gripSpace?this.gripWorldPosition:this.object.worldPosition).sub(this.object.worldForward.multiplyScalar(.1)),s=this.inputSource.profiles.join(`
147
147
  `);let o=`Controller[${this.index}] (${this.inputSource.targetRayMode}, ${this.side})
148
148
  C:${this.connected?"x":"-"} T:${this.isTracking?"x":"-"} Hand:${this.inputSource.hand?"x":"-"} Pen: ${this._isMxInk?"x":"-"}`;if(this.inputSource.hand&&(o+=`
149
149
  Pinch: ${(e=this.getGesture("pinch"))==null?void 0:e.value.toFixed(3)}`),o+=`
@@ -1386,7 +1386,7 @@ If you need multisampling consider changing 'auto' to a fixed value (e.g. 4).`))
1386
1386
  // be blended onto the scene.
1387
1387
  gl_FragColor = vec4(direct, max);
1388
1388
  return;
1389
- `)},e.userData.isLightBlendMaterial=!0}applyShadowMaterial(){if(this.targetMesh)if(this.targetMesh.material.type!=="ShadowMaterial"){const e=new Rv;e.color=this.shadowColor,e.opacity=this.shadowColor.alpha,this.applyMaterialOptions(e),this.targetMesh.material=e,e.userData.isShadowCatcherMaterial=!0}else{const e=this.targetMesh.material;e.color=this.shadowColor,e.opacity=this.shadowColor.alpha,this.applyMaterialOptions(e),e.userData.isShadowCatcherMaterial=!0}}applyOccluderMaterial(){if(this.targetMesh){let e=this.targetMesh.material;if(!e){const t=new Me;this.targetMesh.material=t,e=t}e.depthWrite=!0,e.stencilWrite=!0,e.colorWrite=!1,this.gameObject.renderOrder=-100}}applyMaterialOptions(e){e&&(e.depthWrite=!1,e.stencilWrite=!1)}}PS([m()],Th.prototype,"mode"),PS([m(he)],Th.prototype,"shadowColor");var SI=Object.defineProperty,Eh=(n,e,t,s)=>{for(var o=void 0,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=l(e,t,o)||o);return o&&SI(e,t,o),o};const jt=C("debugskybox");Vy("background-image"),Vy("environment-image");function OS(n,e,t,s,o){if(e==="transparent"||e!=null&&e.startsWith("rgb")||e!=null&&e.startsWith("#"))return console.warn(`Needle Engine: Invalid ${o} value (${e}). Did you mean to set background-color instead?`),null;const r=new Xp;r.allowDrop=!1,r.allowNetworking=!1,r.background=t,r.environment=s,P.addComponent(n.scene,r);const l=c=>{typeof c=="string"&&(jt&&console.log(o,"CHANGED TO",c),r.setSkybox(c))};return gb(n.domElement,o,l),r.addEventListener("destroy",()=>{jt&&console.log("Destroyed attribute remote skybox",o),fb(n.domElement,o,l)}),r.setSkybox(e)}const qp=new Array;pe.registerCallback(me.ContextCreationStart,n=>{const e=n.context,t=e.domElement.getAttribute("background-image"),s=e.domElement.getAttribute("environment-image");if(t){jt&&console.log("Creating remote skybox to load "+t);const o=OS(e,t,!0,!1,"background-image");o&&qp.push(o)}if(s){jt&&console.log("Creating remote environment to load "+s);const o=OS(e,s,!1,!0,"environment-image");o&&qp.push(o)}}),pe.registerCallback(me.ContextCreationStart,()=>Promise.all(qp).finally(()=>{qp.length=0}));function kS(){return globalThis.NEEDLE_ENGINE_SKYBOX_TEXTURES||(globalThis.NEEDLE_ENGINE_SKYBOX_TEXTURES=new Array),globalThis.NEEDLE_ENGINE_SKYBOX_TEXTURES}function MS(n){const e=kS().find(t=>t.src===n);return e?(jt&&console.log("Skybox: Found previously loaded texture for "+n),e.texture):null}async function CI(n){const e=await n;Xg(e,!0),Te(e)}function PI(n,e){const t=kS();for(;t.length>5;){const s=t.shift();s&&CI(s.texture)}e.then(s=>Xg(s,!1)),t.push({src:n,texture:e})}const ha=class extends I{constructor(){super(...arguments),a(this,"url"),a(this,"allowDrop",!0),a(this,"background",!0),a(this,"environment",!0),a(this,"allowNetworking",!0),a(this,"_loader"),a(this,"_prevUrl"),a(this,"_prevLoadedEnvironment"),a(this,"_prevEnvironment",null),a(this,"_prevBackground",null),a(this,"validTextureTypes",[".ktx2",".hdr",".exr",".jpg",".jpeg",".png"]),a(this,"onDragOverEvent",n=>{if(this.allowDrop&&n.dataTransfer)for(const e of n.dataTransfer.types)(e==="text/uri-list"||e==="Files")&&n.preventDefault()}),a(this,"onDrop",n=>{var e,t,s,o;if(this.allowDrop&&n.dataTransfer){for(const r of n.dataTransfer.types)if(jt&&console.log(r),r==="text/uri-list"){const l=n.dataTransfer.getData(r);jt&&console.log(r,l);let c=(t=(e=new RegExp(/polyhaven.com\/asset_img\/.+?\/(?<name>.+)\.png/).exec(l))==null?void 0:e.groups)==null?void 0:t.name;if(c||(c=(o=(s=new RegExp(/polyhaven\.com\/a\/(?<name>.+)/).exec(l))==null?void 0:s.groups)==null?void 0:o.name),jt&&console.log(c),c){const h="https://dl.polyhaven.org/file/ph-assets/HDRIs/exr/1k/"+c+"_1k.exr";console.log(`[Remote Skybox] Setting skybox from url: ${h}`),n.preventDefault(),this.setSkybox(h);break}else if(this.isValidTextureType(l)){console.log("[Remote Skybox] Setting skybox from url: "+l),n.preventDefault(),this.setSkybox(l);break}else{console.warn(`[RemoteSkybox] Unknown url ${l}. If you want to load a skybox from a url, make sure it is a valid image url. Url must end with${this.validTextureTypes.join(", ")}.`);const h=new CustomEvent("dropped-unknown-url",{detail:{sender:this,event:n,url:l,apply:d=>{n.preventDefault(),this.setSkybox(d)}}});this.dispatchEvent(h)}}else if(r=="Files"){const l=n.dataTransfer.files.item(0);if(jt&&console.log(r,l),!l)continue;if(!this.isValidTextureType(l.name)){console.warn(`[RemoteSkybox]: File "${l.name}" is not supported. Supported files are ${this.validTextureTypes.join(", ")}`);return}if(MS(l.name)===null){const c=new Blob([l]),h=URL.createObjectURL(c);n.preventDefault(),this.setSkybox(h,l.name)}else n.preventDefault(),this.setSkybox(l.name);break}}})}onEnable(){this.setSkybox(this.url),this.registerDropEvents()}onDisable(){var n;this.context.scene.environment===this._prevLoadedEnvironment&&(this.context.scene.environment=this._prevEnvironment,ci.backgroundShouldBeTransparent(this.context)||(this.context.scene.background=this._prevBackground),this._prevLoadedEnvironment=void 0),this.unregisterDropEvents(),(n=this.context.mainCameraComponent)==null||n.applyClearFlags()}urlChangedSyncField(){this.allowNetworking&&this.url&&(this.isRemoteTexture(this.url)?this.setSkybox(this.url):jt&&console.warn(`RemoteSkybox: Not setting skybox: ${this.url} is not a remote texture. If you want to set a local texture, set allowNetworking to false.`))}async setSkybox(n,e){var t;if(!this.activeAndEnabled||(n=OI(n,this.environment,this.background),!n))return!1;try{n.startsWith("/")||n.startsWith(".")?new URL(n,window.location.href):new URL(n)}catch{return jt&&console.warn("RemoteSkybox: Invalid URL",n,this.name),!1}if(e??(e=n),this.isValidTextureType(e)||console.warn("Potentially invalid skybox url",e,"on",this.name),jt&&console.log("Set remote skybox url: "+n),this._prevUrl===n&&this._prevLoadedEnvironment)return this.apply(),!0;(t=this._prevLoadedEnvironment)==null||t.dispose(),this._prevLoadedEnvironment=void 0,this._prevUrl=n;const s=await this.loadTexture(n,e);if(!s)return jt&&console.warn("RemoteSkybox: Failed to load texture from url",n),!1;if(!this.enabled)return jt&&console.warn("RemoteSkybox: Component is not enabled, aborting setSkybox"),!1;if(this._prevUrl!==n)return jt&&console.warn("RemoteSkybox: URL changed while loading texture, aborting setSkybox"),!1;this.url=n;const o=n.lastIndexOf("/");return s.name=n.substring(o>=0?o+1:0),this._loader instanceof Sa&&(s.colorSpace=Rn),this._prevLoadedEnvironment=s,this.apply(),!0}async loadTexture(n,e){var t,s,o,r,l;if(!n)return Promise.resolve(null);e??(e=n);const c=MS(e);if(c){const g=await c;if(((s=(t=g.source)==null?void 0:t.data)==null?void 0:s.length)>0||(l=(r=(o=g.source)==null?void 0:o.data)==null?void 0:r.data)!=null&&l.length)return g}const h=e.endsWith(".exr"),d=e.endsWith(".hdr"),u=e.endsWith(".ktx2");if(h)this._loader instanceof Pd||(this._loader=new Pd);else if(d)this._loader instanceof Vm||(this._loader=new Vm);else if(u){if(!(this._loader instanceof hO)){const{ktx2Loader:g}=Wm(this.context.renderer);this._loader=g}}else this._loader instanceof Sa||(this._loader=new Sa);jt&&console.log("Loading skybox: "+n);const p=this._loader.loadAsync(n);return PI(e,p),await p}apply(){var n;const e=this._prevLoadedEnvironment;e&&(e instanceof BP||e instanceof FP||(e.mapping=UP,e.needsUpdate=!0),this.context.scene.background!==e&&(this._prevBackground=this.context.scene.background),this.context.scene.environment!==e&&(this._prevEnvironment=this.context.scene.environment),jt&&console.log("Set remote skybox",this.url,!ci.backgroundShouldBeTransparent(this.context)),this.environment&&(this.context.scene.environment=e),this.background&&!ci.backgroundShouldBeTransparent(this.context)&&(this.context.scene.background=e),((n=this.context.mainCameraComponent)==null?void 0:n.backgroundBlurriness)!==void 0&&(this.context.scene.backgroundBlurriness=this.context.mainCameraComponent.backgroundBlurriness))}isRemoteTexture(n){return n.startsWith("http://")||n.startsWith("https://")}isValidTextureType(n){for(const e of this.validTextureTypes)if(n.endsWith(e))return!0;return!1}registerDropEvents(){this.unregisterDropEvents(),this.context.domElement.addEventListener("dragover",this.onDragOverEvent),this.context.domElement.addEventListener("drop",this.onDrop)}unregisterDropEvents(){this.context.domElement.removeEventListener("dragover",this.onDragOverEvent),this.context.domElement.removeEventListener("drop",this.onDrop)}};Eh([Q0(ha.prototype.urlChangedSyncField),m(URL)],ha.prototype,"url"),Eh([m()],ha.prototype,"allowDrop"),Eh([m()],ha.prototype,"background"),Eh([m()],ha.prototype,"environment"),Eh([m()],ha.prototype,"allowNetworking");let Xp=ha;function OI(n,e,t){const s=e&&!t;switch(n?.toLowerCase()){case"studio":return s?"https://cdn.needle.tools/static/skybox/modelviewer-Neutral-small.hdr":"https://cdn.needle.tools/static/skybox/modelviewer-Neutral.hdr";case"blurred-skybox":return s?"https://cdn.needle.tools/static/skybox/blurred-skybox-small.exr":"https://cdn.needle.tools/static/skybox/blurred-skybox.exr";case"quicklook-ar":return s?"https://cdn.needle.tools/static/skybox/QuickLook-ARMode-small.exr":"https://cdn.needle.tools/static/skybox/QuickLook-ARMode.exr";case"quicklook":return s?"https://cdn.needle.tools/static/skybox/QuickLook-ObjectMode-small.exr":"https://cdn.needle.tools/static/skybox/QuickLook-ObjectMode.exr"}return n===void 0?null:n}var kI=Object.defineProperty,Qp=(n,e,t,s)=>{for(var o=void 0,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=l(e,t,o)||o);return o&&kI(e,t,o),o},Yp;const Ah=(Yp=class extends I{constructor(){super(...arguments),a(this,"target",null),a(this,"followFactor",.1),a(this,"rotateFactor",.1),a(this,"positionAxes",Qa.All),a(this,"flipForward",!1),a(this,"_firstUpdate",!0)}onBeforeRender(){this.updateNow(!1)}updateNow(n){if(!(!this.target||this.target===this.gameObject)){if(this.followFactor>0){const e=ee(this.target),t=this._firstUpdate||n?1:W.clamp01(this.context.time.deltaTime*this.followFactor),s=this.worldPosition;this.positionAxes&Qa.X&&(s.x=W.lerp(s.x,e.x,t)),this.positionAxes&Qa.Y&&(s.y=W.lerp(s.y,e.y,t)),this.positionAxes&Qa.Z&&(s.z=W.lerp(s.z,e.z,t)),this.worldPosition=s}if(this.rotateFactor>0){const e=Se(this.target);this.flipForward&&e.premultiply(Yp._invertForward);const t=this._firstUpdate||n?1:W.clamp01(this.context.time.deltaTime*this.rotateFactor);this.worldQuaternion=this.worldQuaternion.slerp(e,t)}this._firstUpdate=!1}}},a(Yp,"_invertForward",new V().setFromAxisAngle(new S(0,1,0),Math.PI)),Yp);Qp([m(E)],Ah.prototype,"target"),Qp([m()],Ah.prototype,"followFactor"),Qp([m()],Ah.prototype,"rotateFactor"),Qp([m()],Ah.prototype,"positionAxes");let Kp=Ah;var MI=Object.defineProperty,Ih=(n,e,t,s)=>{for(var o=void 0,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=l(e,t,o)||o);return o&&MI(e,t,o),o};const Lh=C("debugspatialtrigger"),RS=new po,TS=new po;function RI(n,e){return RS.mask=n,TS.mask=e,RS.test(TS)}class bn extends I{constructor(){super(...arguments),a(this,"triggerMask",0),a(this,"onEnter"),a(this,"onStay"),a(this,"onExit"),a(this,"currentIntersected",[]),a(this,"lastIntersected",[])}start(){Lh&&console.log(this.name,this.triggerMask,this)}update(){this.currentIntersected.length=0;for(const e of Zp.triggers)RI(e.triggerMask,this.triggerMask)&&e.test(this.gameObject)&&this.currentIntersected.push(e);for(let e=this.lastIntersected.length-1;e>=0;e--){const t=this.lastIntersected[e];this.currentIntersected.indexOf(t)<0&&(this.onExitTrigger(t),this.lastIntersected.splice(e,1))}for(const e of this.currentIntersected)this.lastIntersected.indexOf(e)<0&&this.onEnterTrigger(e),this.onStayTrigger(e);this.lastIntersected.length=0,this.lastIntersected.push(...this.currentIntersected)}onEnterTrigger(e){var t;Lh&&console.log("ENTER TRIGGER",this.name,e.name,this,e),e.raiseOnEnterEvent(this),(t=this.onEnter)==null||t.invoke()}onExitTrigger(e){var t;Lh&&console.log("EXIT TRIGGER",this.name,e.name),e.raiseOnExitEvent(this),(t=this.onExit)==null||t.invoke()}onStayTrigger(e){var t;e.raiseOnStayEvent(this),(t=this.onStay)==null||t.invoke()}}Ih([m()],bn.prototype,"triggerMask"),Ih([m(xe)],bn.prototype,"onEnter"),Ih([m(xe)],bn.prototype,"onStay"),Ih([m(xe)],bn.prototype,"onExit");var Tl;const ES=(Tl=class extends I{constructor(){super(...arguments),a(this,"triggerMask"),a(this,"boxHelper")}start(){Lh&&console.log(this.name,this.triggerMask,this)}onEnable(){var n;Tl.triggers.push(this),this.boxHelper||(this.boxHelper=P.addComponent(this.gameObject,Do),(n=this.boxHelper)==null||n.showHelper(null,Lh))}onDisable(){Tl.triggers.splice(Tl.triggers.indexOf(this),1)}test(n){return this.boxHelper?this.boxHelper.isInBox(n)??!1:!1}raiseOnEnterEvent(n){P.foreachComponent(this.gameObject,e=>{e!==n&&e instanceof bn&&e.onEnterTrigger(this)},!1)}raiseOnStayEvent(n){P.foreachComponent(this.gameObject,e=>{e!==n&&e instanceof bn&&e.onStayTrigger(this)},!1)}raiseOnExitEvent(n){P.foreachComponent(this.gameObject,e=>{e!==n&&e instanceof bn&&e.onExitTrigger(this)},!1)}},a(Tl,"triggers",[]),Tl);Ih([m()],ES.prototype,"triggerMask");let Zp=ES;var TI=Object.defineProperty,EI=(n,e,t,s)=>{for(var o=void 0,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=l(e,t,o)||o);return o&&TI(e,t,o),o};const Hi=C("debugspectator");class Jp extends I{constructor(){super(...arguments),a(this,"cam",null),a(this,"useKeys",!0),a(this,"_mode",0),a(this,"orbit",null),a(this,"_handler"),a(this,"eventSub_WebXRRequestStartEvent",null),a(this,"eventSub_WebXRStartEvent",null),a(this,"eventSub_WebXREndEvent",null),a(this,"_debug"),a(this,"_networking")}get mode(){return this._mode}set mode(e){this._mode=e}get isSpectating(){var e;return((e=this._handler)==null?void 0:e.currentTarget)!==void 0}isSpectatingUser(e){var t;return((t=this.target)==null?void 0:t.userId)===e}isFollowedBy(e){var t;return(t=this.followers)==null?void 0:t.includes(e)}get followers(){return this._networking.followers}stopSpectating(){if(this.context.isInXR){this.followSelf();return}this.target=void 0}get localId(){return this.context.connection.connectionId??"local"}set target(e){var t;if(this._handler){const s=(t=this._handler.currentTarget)==null?void 0:t.userId,o=this.context.players.getPlayerView(this.localId);e===void 0||this.context.isInXR===!1&&o?.currentObject===e.currentObject?this._handler.currentTarget!==void 0&&(this._handler.disable(),P.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),this._networking.onSpectatedObjectChanged(e,s)):this._handler.currentTarget!==e&&(this._handler.set(e),P.setActive(this.gameObject,!0),this.orbit&&(this.orbit.enabled=!1),this._networking.onSpectatedObjectChanged(e,s))}}get target(){var e;return(e=this._handler)==null?void 0:e.currentTarget}requestAllFollowMe(){this._networking.onRequestFollowMe()}get isSpectatingSelf(){var e,t;return this.isSpectating&&((e=this.target)==null?void 0:e.currentObject)===((t=this.context.players.getPlayerView(this.localId))==null?void 0:t.currentObject)}awake(){if(this._debug=new LI(this.context,this),this._networking=new BI(this.context,this),this._networking.awake(),P.setActive(this.gameObject,!1),this.cam=P.getComponent(this.gameObject,ci),!this.cam){console.warn("SpectatorCamera: Spectator camera needs camera component on the same object.",this);return}!this._handler&&this.cam&&(this._handler=new AI(this.context,this.cam,this)),this.orbit=P.getComponent(this.context.mainCamera,_e)}onDestroy(){var e,t;this.stopSpectating(),(e=this._handler)==null||e.destroy(),(t=this._networking)==null||t.destroy()}isSupportedPlatform(){const e=window.navigator.userAgent,t=/Windows|MacOS/.test(e),s=/Windows NT/.test(e)&&/Edg/.test(e)&&!/Win64/.test(e);return t&&!s}onBeforeXR(e){this.isSupportedPlatform()&&P.setActive(this.gameObject,!0)}onEnterXR(e){this.isSupportedPlatform()&&(Hi&&console.log(this.context.mainCamera),this.context.mainCamera&&this.followSelf())}onLeaveXR(e){var t,s;this.context.removeCamera(this.cam),P.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),(t=this._handler)==null||t.set(void 0),(s=this._handler)==null||s.disable(),this.isSpectatingSelf&&this.stopSpectating()}followSelf(){this.target=this.context.players.getPlayerView(this.context.connection.connectionId),this.target||(this.context.players.setPlayerView(this.localId,this.context.mainCamera,Co.Headset),this.target=this.context.players.getPlayerView(this.localId)),Hi&&console.log("Follow self",this.target)}onAfterRender(){var e,t,s;if(!this.cam)return;const o=this.context.renderer,r=o.xr.enabled;if(!o.xr.isPresenting&&!((e=this._handler)!=null&&e.currentTarget))return;(t=this._handler)==null||t.update(this._mode);const l=o.getRenderTarget();let c=null;const h=o.state;if(!l){if(!o.state.bindFramebuffer||!h.bindXRFramebuffer)return;c=o._framebuffer,h.bindXRFramebuffer(null)}this.setAvatarFlagsBeforeRender();const d=this.context.mainCameraComponent;if(d){const g=d.backgroundColor;g&&o.setClearColor(g,g.alpha),this.cam.backgroundColor=g,this.cam.clearFlags=d.clearFlags,this.cam.nearClipPlane=d.nearClipPlane,this.cam.farClipPlane=d.farClipPlane}else o.setClearColor(new oe(1,1,1));o.setRenderTarget(null),o.xr.enabled=!1;const u=(s=this.cam)==null?void 0:s.threeCamera;this.context.updateAspect(u);const p=o.xr.isPresenting;o.xr.isPresenting=!1,o.setSize(this.context.domWidth,this.context.domHeight),o.render(this.context.scene,u),o.xr.isPresenting=p,o.xr.enabled=r,l?o.setRenderTarget(l):h.bindXRFramebuffer&&h.bindXRFramebuffer(c),this.resetAvatarFlags()}setAvatarFlagsBeforeRender(){const e=this._mode===0;for(const t of hi.instances)if(t.avatar&&"isLocalAvatar"in t.avatar&&"flags"in t.avatar){let s=an.All;this.isSpectatingSelf&&(s=e&&t.avatar.isLocalAvatar?an.FirstPerson:an.ThirdPerson);const o=t.avatar.flags;if(!o)continue;for(const r of o)r.UpdateVisible(s)}}resetAvatarFlags(){var e;for(const t of hi.instances)if(t.avatar&&"flags"in t.avatar){const s=t.avatar.flags;if(!s)continue;for(const o of s)"isLocalAvatar"in t.avatar&&(e=t.avatar)!=null&&e.isLocalAvatar?o.UpdateVisible(an.FirstPerson):o.UpdateVisible(an.ThirdPerson)}}}EI([m()],Jp.prototype,"useKeys");class AI{constructor(e,t,s){a(this,"context"),a(this,"cam"),a(this,"spectator"),a(this,"follow"),a(this,"target"),a(this,"view"),a(this,"currentObject"),this.context=e,this.cam=t,this.spectator=s}get currentTarget(){return this.view}set(e){const t=e?.currentObject;if(!t){this.spectator.stopSpectating();return}t!==this.currentObject&&(this.currentObject=t,this.view=e,this.follow||(this.follow=P.addComponent(this.cam.gameObject,Kp)),this.target||(this.target=new E),t.add(this.target),this.follow.enabled=!0,this.follow.target=this.target,Hi&&console.log("FOLLOW",t),this.context.isInXR?this.context.removeCamera(this.cam):this.context.setCurrentCamera(this.cam))}disable(){Hi&&console.log("STOP FOLLOW",this.currentObject),this.view=void 0,this.currentObject=void 0,this.context.removeCamera(this.cam),this.follow&&(this.follow.enabled=!1)}destroy(){var e;(e=this.target)==null||e.removeFromParent(),this.follow&&P.destroy(this.follow)}update(e){var t,s,o,r,l,c;if(((t=this.currentTarget)==null?void 0:t.isConnected)===!1||((s=this.currentTarget)==null?void 0:s.removed)===!0){Hi&&console.log("Target disconnected or timeout",this.currentTarget),this.spectator.stopSpectating();return}this.currentTarget&&((o=this.currentTarget)==null?void 0:o.currentObject)!==this.currentObject&&(Hi&&console.log("Target changed",this.currentObject,"to",this.currentTarget.currentObject),this.set(this.currentTarget));const h=this.context.mainCamera;if(h){const u=this.cam.threeCamera;(u.near!==h.near||u.far!==h.far)&&(u.near=h.near,u.far=h.far,u.updateProjectionMatrix())}const d=(r=this.follow)==null?void 0:r.target;if(!(!d||!this.follow)){switch(e){case 0:((l=this.view)==null?void 0:l.viewDevice)!==Co.Browser?(this.follow.followFactor=5,this.follow.rotateFactor=5):(this.follow.followFactor=50,this.follow.rotateFactor=50),d.position.set(0,0,0);break;case 1:this.follow.followFactor=3,this.follow.rotateFactor=2,d.position.set(0,.5,1.5);break}this.follow.flipForward=!1,((c=this.view)==null?void 0:c.viewDevice)!==Co.Browser?d.quaternion.copy(II):d.quaternion.identity()}}}const II=new V().setFromAxisAngle(new S(0,1,0),Math.PI);class LI{constructor(e,t){a(this,"context"),a(this,"spectator"),this.context=e,this.spectator=t,console.log("[Spectator Camera] Click other avatars or cameras to follow them. Press ESC to exit spectator mode."),this.context.domElement.addEventListener("keydown",o=>{!this.spectator.useKeys||o.key==="Escape"&&this.spectator.stopSpectating()});let s=0;this.context.input.addEventListener(Be.PointerDown,o=>{s=this.context.time.time}),this.context.input.addEventListener(Be.PointerUp,o=>{const r=this.context.time.time-s;r>1?this.spectator.stopSpectating():this.context.input.getPointerClicked(0)&&r<.3&&this.trySelectObject()})}trySelectObject(){const e=new Qs;e.setMask(16777215);const t=this.context.physics.raycast(e);if(Hi&&console.log(...t),t!=null&&t.length)for(const s of t){if(s.distance<.2)continue;const o=s.object,r=P.getComponentInParent(o,hi),l=r?.connectionId;if(l){const c=this.context.players.getPlayerView(l);this.spectator.target=c,Hi&&console.log("spectate",l,r);break}}}}class jI{constructor(e,t,s){a(this,"guid"),a(this,"dontSave",!0),a(this,"targetUserId"),a(this,"stoppedFollowing"),this.guid=e,this.targetUserId=t,this.stoppedFollowing=s}}class DI{constructor(e,t){a(this,"guid"),a(this,"userId"),this.guid=e.guid,this.userId=t}}class BI{constructor(e,t){a(this,"followers",[]),a(this,"context"),a(this,"spectator"),a(this,"_followerEventMethod"),a(this,"_requestFollowMethod"),a(this,"_joinedRoomMethod"),a(this,"_lastRequestFollowUser"),a(this,"_enforceFollowInterval"),this.context=e,this.spectator=t,this._followerEventMethod=this.onFollowerEvent.bind(this),this._requestFollowMethod=this.onRequestFollowEvent.bind(this),this._joinedRoomMethod=this.onUserJoinedRoom.bind(this)}awake(){this.context.connection.beginListen("spectator-follower-changed",this._followerEventMethod),this.context.connection.beginListen("spectator-request-follow",this._requestFollowMethod),this.context.connection.beginListen(ie.JoinedRoom,this._joinedRoomMethod),this.context.domElement.addEventListener("keydown",e=>{this.spectator.useKeys&&(e.key==="f"?this.onRequestFollowMe():e.key==="Escape"&&this.onRequestFollowMe(!0))})}destroy(){this.context.connection.stopListen("spectator-follower-changed",this._followerEventMethod),this.context.connection.stopListen("spectator-request-follow",this._requestFollowMethod),this.context.connection.stopListen(ie.JoinedRoom,this._joinedRoomMethod)}onSpectatedObjectChanged(e,t){if(Hi&&console.log(this.context.connection.connectionId,"onSpectatedObjectChanged",e,t),this.context.connection.connectionId){const s=e?.userId===void 0,o=s?t:e?.userId,r=new jI(this.context.connection.connectionId,o,s);this.context.connection.send("spectator-follower-changed",r)}}onRequestFollowMe(e=!1){if(Hi&&console.log("Request follow",this.context.connection.connectionId),this.context.connection.connectionId){this.spectator.stopSpectating();const t=e?void 0:this.context.connection.connectionId,s=new DI(this.spectator,t);this.context.connection.send("spectator-request-follow",s)}}onUserJoinedRoom(){C("followme")&&this.onRequestFollowMe()}onFollowerEvent(e){const t=e.targetUserId,s=e.guid;if(Hi&&console.log(e),t===this.context.connection.connectionId)if(e.stoppedFollowing){const o=this.followers.indexOf(s);o!==-1&&(this.followers.splice(o,1),this.removeDisconnectedFollowers(),console.log(s,"unfollows you",this.followers.length))}else this.followers.includes(s)||(this.followers.push(s),this.removeDisconnectedFollowers(),console.log(s,"follows you",this.followers.length))}removeDisconnectedFollowers(){for(let e=this.followers.length-1;e>=0;e--){const t=this.followers[e];this.context.connection.userIsInRoom(t)===!1&&this.followers.splice(e,1)}}onRequestFollowEvent(e){if(this._lastRequestFollowUser=e,e.userId===this.context.connection.connectionId)this.spectator.stopSpectating();else if(e.userId===void 0)this.spectator.stopSpectating();else{const t=this.context.players.getPlayerView(e.userId);if(t)this.spectator.target=t;else return Hi&&console.warn("Could not find view",e.userId),this.enforceFollow(),!1}return!0}enforceFollow(){this._enforceFollowInterval||(this._enforceFollowInterval=setInterval(()=>{this._lastRequestFollowUser===void 0||this._lastRequestFollowUser.userId&&this.spectator.isFollowedBy(this._lastRequestFollowUser.userId)?(clearInterval(this._enforceFollowInterval),this._enforceFollowInterval=void 0):(Hi&&console.log("REQUEST FOLLOW AGAIN",this._lastRequestFollowUser.userId),this.onRequestFollowEvent(this._lastRequestFollowUser))},1e3))}}class Cn{constructor(){a(this,"bb",null),a(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}static getRootAsSyncedCameraModel(e,t){return(t||new Cn).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsSyncedCameraModel(e,t){return e.setPosition(e.position()+Jv),(t||new Cn).__init(e.readInt32(e.position())+e.position(),e)}userId(e){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__string(this.bb_pos+t,e):null}guid(e){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__string(this.bb_pos+t,e):null}dontSave(){const e=this.bb.__offset(this.bb_pos,8);return e?!!this.bb.readInt8(this.bb_pos+e):!1}pos(e){const t=this.bb.__offset(this.bb_pos,10);return t?(e||new Fr).__init(this.bb_pos+t,this.bb):null}rot(e){const t=this.bb.__offset(this.bb_pos,12);return t?(e||new Fr).__init(this.bb_pos+t,this.bb):null}static startSyncedCameraModel(e){e.startObject(5)}static addUserId(e,t){e.addFieldOffset(0,t,0)}static addGuid(e,t){e.addFieldOffset(1,t,0)}static addDontSave(e,t){e.addFieldInt8(2,+t,0)}static addPos(e,t){e.addFieldStruct(3,t,0)}static addRot(e,t){e.addFieldStruct(4,t,0)}static endSyncedCameraModel(e){return e.endObject()}static finishSyncedCameraModelBuffer(e,t){e.finish(t)}static finishSizePrefixedSyncedCameraModelBuffer(e,t){e.finish(t,void 0,!0)}}var FI=Object.defineProperty,UI=(n,e,t,s)=>{for(var o=void 0,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=l(e,t,o)||o);return o&&FI(e,t,o),o};const em="SCAM";Eg(em,Cn.getRootAsSyncedCameraModel);const Gi=new Hm;class zI{constructor(e,t){a(this,"userId"),a(this,"guid"),this.guid=t,this.userId=e}send(e,t){if(e){Gi.clear();const s=Gi.createString(this.guid),o=Gi.createString(this.userId);Cn.startSyncedCameraModel(Gi),Cn.addGuid(Gi,s),Cn.addUserId(Gi,o);const r=ee(e),l=Id(e);Cn.addPos(Gi,Fr.createVec3(Gi,r.x,r.y,r.z)),Cn.addRot(Gi,Fr.createVec3(Gi,l.x,l.y,l.z));const c=Cn.endSyncedCameraModel(Gi);Gi.finish(c,em),t.sendBinary(Gi.asUint8Array())}}}var jh;const AS=(jh=class extends I{constructor(){super(...arguments),a(this,"cameraPrefab",null),a(this,"_lastWorldPosition"),a(this,"_lastWorldQuaternion"),a(this,"_model",null),a(this,"_needsUpdate",!0),a(this,"_lastUpdateTime",0),a(this,"remoteCams",{}),a(this,"userToCamMap",{}),a(this,"_camTimeoutInSeconds",10),a(this,"_receiveCallback",null)}getCameraObject(n){const e=this.userToCamMap[n];return e?this.remoteCams[e].obj:null}async awake(){this._lastWorldPosition=this.worldPosition.clone(),this._lastWorldQuaternion=this.worldQuaternion.clone(),this.cameraPrefab&&("uri"in this.cameraPrefab&&(this.cameraPrefab=await this.cameraPrefab.instantiate(this.gameObject)),this.cameraPrefab&&"isObject3D"in this.cameraPrefab&&(this.cameraPrefab.visible=!1))}onEnable(){this._receiveCallback=this.context.connection.beginListenBinary(em,this.onReceivedRemoteCameraInfoBin.bind(this))}onDisable(){this.context.connection.stopListenBinary(em,this._receiveCallback)}update(){for(const s in this.remoteCams){const o=this.remoteCams[s],r=this.context.time.realtimeSinceStartup-o.lastUpdate;if(!o||r>this._camTimeoutInSeconds){F()&&console.log("Remote cam timeout",s),o!=null&&o.obj&&P.destroy(o.obj),delete this.remoteCams[s],o&&delete this.userToCamMap[o.userId],jh.instances.push(o),this.context.players.removePlayerView(o.userId,Co.Browser);continue}}if(this.context.isInXR)return;const n=this.context.mainCamera;if(n===null){this.enabled=!1;return}if(!this.context.connection.isConnected||this.context.connection.connectionId===null)return;this._model===null&&(this._model=new zI(this.context.connection.connectionId,this.context.connection.connectionId+"_camera"));const e=ee(n),t=Se(n);(e.distanceTo(this._lastWorldPosition)>.001||t.angleTo(this._lastWorldQuaternion)>.01)&&(this._needsUpdate=!0),this._lastWorldPosition.copy(e),this._lastWorldQuaternion.copy(t),!((!this._needsUpdate||this.context.time.frameCount%2!==0)&&!(this.context.time.realtimeSinceStartup-this._lastUpdateTime>this._camTimeoutInSeconds*.5))&&(this._lastUpdateTime=this.context.time.realtimeSinceStartup,this._needsUpdate=!1,this._model.send(n,this.context.connection),this.context.isInXR||this.context.players.setPlayerView(this.context.connection.connectionId,n,Co.Browser))}onReceivedRemoteCameraInfoBin(n){const e=n.guid();if(!e)return;const t=n.userId();if(!t||!this.context.connection.userIsInRoom(t)||!this.cameraPrefab)return;let s=this.remoteCams[e];if(!s)if("isObject3D"in this.cameraPrefab){const c=new Bs;c.context=this.context;const h=P.instantiate(this.cameraPrefab,c);s=this.remoteCams[e]={obj:h,lastUpdate:this.context.time.realtimeSinceStartup,userId:t},s.obj.visible=!0,this.gameObject.add(h),this.userToCamMap[t]=e,jh.instances.push(s);const d=P.getOrAddComponent(h,hi);d.connectionId=t,d.avatar=h}else return;const o=s.obj;this.context.players.setPlayerView(t,o,Co.Browser),s.lastUpdate=this.context.time.realtimeSinceStartup,ms.markDirty(o);const r=n.pos();r&&vr(o,r.x(),r.y(),r.z());const l=n.rot();l&&Jl(o,l.x(),l.y(),l.z())}},a(jh,"instances",[]),jh);UI([m([E,ce])],AS.prototype,"cameraPrefab");let $y=AS;var NI=Object.defineProperty,WI=Object.getOwnPropertyDescriptor,ar=(n,e,t,s)=>{for(var o=s>1?void 0:s?WI(e,t):e,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(e,t,o):l(o))||o);return s&&o&&NI(e,t,o),o};const Hy="view",Gy=C("debugsyncedroom");class Is extends I{constructor(){super(...arguments),a(this,"roomName",""),a(this,"urlParameterName","room"),a(this,"joinRandomRoom"),a(this,"requireRoomParameter",!1),a(this,"autoRejoin",!0),a(this,"createJoinButton",!0),a(this,"createViewOnlyButton",!1),a(this,"_lastJoinedRoom"),a(this,"_roomPrefix",""),a(this,"_lastPingTime",0),a(this,"_lastRoomTime",-1),a(this,"_userWantsToBeInARoom",!1),a(this,"_roomButton"),a(this,"_roomButtonIconJoin"),a(this,"_roomButtonIconLeave"),a(this,"updateRoomButtonState",()=>{var e,t;this._roomButton&&(this.context.connection.isInRoom?(this._roomButton.title="Leave the networked room",this._roomButton.textContent="Leave Room",(e=this._roomButtonIconJoin)==null||e.remove(),this._roomButton.prepend(this._roomButtonIconLeave)):(this._roomButton.title="Create or join a networked room",this._roomButton.textContent="Join Room",(t=this._roomButtonIconLeave)==null||t.remove(),this._roomButton.prepend(this._roomButtonIconJoin)))}),a(this,"_viewOnlyButton"),a(this,"onCreateViewOnlyButton",()=>{if(!this._viewOnlyButton){const e=document.createElement("button");this._viewOnlyButton=e,e.classList.add("view-only-button"),e.setAttribute("priority","90"),e.onclick=()=>{var t;const s=this.getViewOnlyUrl();s!=null&&s.length?navigator.canShare({url:s})?(t=navigator.share({url:s}))==null||t.catch(o=>{console.warn(o)}):(navigator.clipboard.writeText(s),De("View only URL copied to clipboard")):be("Could not create view only URL")},e.title="Copy the view only URL: A page accessed by the view only URL can not be modified by visiting users.",e.textContent="Share View URL",e.prepend(Mt("visibility"))}this.context.menu.appendChild(this._viewOnlyButton)})}get currentRoomName(){return C(Hy)||C(this.urlParameterName)}set roomPrefix(e){this._roomPrefix=e}get roomPrefix(){return this._roomPrefix}awake(){var e;this.joinRandomRoom===void 0&&((e=this.roomName)==null?void 0:e.length)<=0&&(this.joinRandomRoom=!0),Gy&&console.log(`SyncedRoom roomName:${this.roomName}, urlParamName:${this.urlParameterName}, joinRandomRoom:${this.joinRandomRoom}`)}onEnable(){const e=C(Hy);if(e&&typeof e=="string"&&e.length>0){console.log("Join as viewer"),this.context.connection.joinRoom(e,!0);return}if(this.tryJoinRoom(),this.createJoinButton){const t=this.createRoomButton();this.context.menu.appendChild(t)}this.createViewOnlyButton&&this.onEnableViewOnlyButton()}onDisable(){var e;(e=this._roomButton)==null||e.remove(),this.onDisableViewOnlyButton(),this.roomName&&this.roomName.length>0&&this.context.connection.leaveRoom(this.roomName)}onDestroy(){this.destroyRoomButton()}tryJoinRandomRoom(){this.setRandomRoomUrlParameter(),this.tryJoinRoom()}tryJoinRoom(e=0){var t;e===void 0&&(e=0);let s=!1;if(((t=this.urlParameterName)==null?void 0:t.length)>0){const o=C(this.urlParameterName);if(o&&(typeof o=="string"||typeof o=="number")){s=!0;const r=pb(o.toString());this.roomName=r}else if(this.joinRandomRoom&&(console.log("No room name found in url, generating random one"),this.setRandomRoomUrlParameter(),e<1))return this.tryJoinRoom(e+1)}else this.joinRandomRoom&&(this.roomName===null||this.roomName===void 0||this.roomName.length<=0)&&(this.roomName=this.generateRoomName());return this.requireRoomParameter&&!s?((Gy||F())&&console.warn('[SyncedRoom] Missing required room parameter "'+this.urlParameterName+`" in url - will not connect.
1389
+ `)},e.userData.isLightBlendMaterial=!0}applyShadowMaterial(){if(this.targetMesh)if(this.targetMesh.material.type!=="ShadowMaterial"){const e=new Rv;e.color=this.shadowColor,e.opacity=this.shadowColor.alpha,this.applyMaterialOptions(e),this.targetMesh.material=e,e.userData.isShadowCatcherMaterial=!0}else{const e=this.targetMesh.material;e.color=this.shadowColor,e.opacity=this.shadowColor.alpha,this.applyMaterialOptions(e),e.userData.isShadowCatcherMaterial=!0}}applyOccluderMaterial(){if(this.targetMesh){let e=this.targetMesh.material;if(!e){const t=new Me;this.targetMesh.material=t,e=t}e.depthWrite=!0,e.stencilWrite=!0,e.colorWrite=!1,this.gameObject.renderOrder=-100}}applyMaterialOptions(e){e&&(e.depthWrite=!1,e.stencilWrite=!1)}}PS([m()],Th.prototype,"mode"),PS([m(he)],Th.prototype,"shadowColor");var SI=Object.defineProperty,Eh=(n,e,t,s)=>{for(var o=void 0,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=l(e,t,o)||o);return o&&SI(e,t,o),o};const jt=C("debugskybox");Vy("background-image"),Vy("environment-image");function OS(n,e,t,s,o){if(e==="transparent"||e!=null&&e.startsWith("rgb")||e!=null&&e.startsWith("#")){console.warn(`Needle Engine: Invalid ${o} value (${e}). Did you mean to set background-color instead?`);return}const r=new Xp;r.allowDrop=!1,r.allowNetworking=!1,r.background=t,r.environment=s,P.addComponent(n.scene,r);const l=c=>{typeof c=="string"&&(jt&&console.log(o,"CHANGED TO",c),r.setSkybox(c))};return gb(n.domElement,o,l),r.addEventListener("destroy",()=>{jt&&console.log("Destroyed attribute remote skybox",o),fb(n.domElement,o,l)}),r.setSkybox(e)}const qp=new Array;pe.registerCallback(me.ContextCreationStart,n=>{const e=n.context,t=e.domElement.getAttribute("background-image"),s=e.domElement.getAttribute("environment-image");if(t){jt&&console.log("Creating remote skybox to load "+t);const o=OS(e,t,!0,!1,"background-image");o&&qp.push(o)}if(s){jt&&console.log("Creating remote environment to load "+s);const o=OS(e,s,!1,!0,"environment-image");o&&qp.push(o)}}),pe.registerCallback(me.ContextCreationStart,()=>Promise.all(qp).finally(()=>{qp.length=0}));function kS(){return globalThis.NEEDLE_ENGINE_SKYBOX_TEXTURES||(globalThis.NEEDLE_ENGINE_SKYBOX_TEXTURES=new Array),globalThis.NEEDLE_ENGINE_SKYBOX_TEXTURES}function MS(n){const e=kS().find(t=>t.src===n);return e?(jt&&console.log("Skybox: Found previously loaded texture for "+n),e.texture):null}async function CI(n){const e=await n;Xg(e,!0),Te(e)}function PI(n,e){const t=kS();for(;t.length>5;){const s=t.shift();s&&CI(s.texture)}e.then(s=>Xg(s,!1)),t.push({src:n,texture:e})}const ha=class extends I{constructor(){super(...arguments),a(this,"url"),a(this,"allowDrop",!0),a(this,"background",!0),a(this,"environment",!0),a(this,"allowNetworking",!0),a(this,"_loader"),a(this,"_prevUrl"),a(this,"_prevLoadedEnvironment"),a(this,"_prevEnvironment",null),a(this,"_prevBackground",null),a(this,"validTextureTypes",[".ktx2",".hdr",".exr",".jpg",".jpeg",".png"]),a(this,"onDragOverEvent",n=>{if(this.allowDrop&&n.dataTransfer)for(const e of n.dataTransfer.types)(e==="text/uri-list"||e==="Files")&&n.preventDefault()}),a(this,"onDrop",n=>{var e,t,s,o;if(this.allowDrop&&n.dataTransfer){for(const r of n.dataTransfer.types)if(jt&&console.log(r),r==="text/uri-list"){const l=n.dataTransfer.getData(r);jt&&console.log(r,l);let c=(t=(e=new RegExp(/polyhaven.com\/asset_img\/.+?\/(?<name>.+)\.png/).exec(l))==null?void 0:e.groups)==null?void 0:t.name;if(c||(c=(o=(s=new RegExp(/polyhaven\.com\/a\/(?<name>.+)/).exec(l))==null?void 0:s.groups)==null?void 0:o.name),jt&&console.log(c),c){const h="https://dl.polyhaven.org/file/ph-assets/HDRIs/exr/1k/"+c+"_1k.exr";console.log(`[Remote Skybox] Setting skybox from url: ${h}`),n.preventDefault(),this.setSkybox(h);break}else if(this.isValidTextureType(l)){console.log("[Remote Skybox] Setting skybox from url: "+l),n.preventDefault(),this.setSkybox(l);break}else{console.warn(`[RemoteSkybox] Unknown url ${l}. If you want to load a skybox from a url, make sure it is a valid image url. Url must end with${this.validTextureTypes.join(", ")}.`);const h=new CustomEvent("dropped-unknown-url",{detail:{sender:this,event:n,url:l,apply:d=>{n.preventDefault(),this.setSkybox(d)}}});this.dispatchEvent(h)}}else if(r=="Files"){const l=n.dataTransfer.files.item(0);if(jt&&console.log(r,l),!l)continue;if(!this.isValidTextureType(l.name)){console.warn(`[RemoteSkybox]: File "${l.name}" is not supported. Supported files are ${this.validTextureTypes.join(", ")}`);return}if(MS(l.name)===null){const c=new Blob([l]),h=URL.createObjectURL(c);n.preventDefault(),this.setSkybox(h,l.name)}else n.preventDefault(),this.setSkybox(l.name);break}}})}onEnable(){this.setSkybox(this.url),this.registerDropEvents()}onDisable(){var n;this.context.scene.environment===this._prevLoadedEnvironment&&(this.context.scene.environment=this._prevEnvironment,ci.backgroundShouldBeTransparent(this.context)||(this.context.scene.background=this._prevBackground),this._prevLoadedEnvironment=void 0),this.unregisterDropEvents(),(n=this.context.mainCameraComponent)==null||n.applyClearFlags()}urlChangedSyncField(){this.allowNetworking&&this.url&&(this.isRemoteTexture(this.url)?this.setSkybox(this.url):jt&&console.warn(`RemoteSkybox: Not setting skybox: ${this.url} is not a remote texture. If you want to set a local texture, set allowNetworking to false.`))}async setSkybox(n,e){var t;if(!this.activeAndEnabled||(n=OI(n,this.environment,this.background),!n))return!1;try{n.startsWith("/")||n.startsWith(".")?new URL(n,window.location.href):new URL(n)}catch{return jt&&console.warn("RemoteSkybox: Invalid URL",n,this.name),!1}if(e??(e=n),this.isValidTextureType(e)||console.warn("Potentially invalid skybox url",e,"on",this.name),jt&&console.log("Set remote skybox url: "+n),this._prevUrl===n&&this._prevLoadedEnvironment)return this.apply(),!0;(t=this._prevLoadedEnvironment)==null||t.dispose(),this._prevLoadedEnvironment=void 0,this._prevUrl=n;const s=await this.loadTexture(n,e);if(!s)return jt&&console.warn("RemoteSkybox: Failed to load texture from url",n),!1;if(!this.enabled)return jt&&console.warn("RemoteSkybox: Component is not enabled, aborting setSkybox"),!1;if(this._prevUrl!==n)return jt&&console.warn("RemoteSkybox: URL changed while loading texture, aborting setSkybox"),!1;this.url=n;const o=n.lastIndexOf("/");return s.name=n.substring(o>=0?o+1:0),this._loader instanceof Sa&&(s.colorSpace=Rn),this._prevLoadedEnvironment=s,this.apply(),!0}async loadTexture(n,e){var t,s,o,r,l;if(!n)return Promise.resolve(null);e??(e=n);const c=MS(e);if(c){const g=await c;if(((s=(t=g.source)==null?void 0:t.data)==null?void 0:s.length)>0||(l=(r=(o=g.source)==null?void 0:o.data)==null?void 0:r.data)!=null&&l.length)return g}const h=e.endsWith(".exr"),d=e.endsWith(".hdr"),u=e.endsWith(".ktx2");if(h)this._loader instanceof Pd||(this._loader=new Pd);else if(d)this._loader instanceof Vm||(this._loader=new Vm);else if(u){if(!(this._loader instanceof hO)){const{ktx2Loader:g}=Wm(this.context.renderer);this._loader=g}}else this._loader instanceof Sa||(this._loader=new Sa);jt&&console.log("Loading skybox: "+n);const p=this._loader.loadAsync(n);return PI(e,p),await p}apply(){var n;const e=this._prevLoadedEnvironment;e&&(e instanceof BP||e instanceof FP||(e.mapping=UP,e.needsUpdate=!0),this.context.scene.background!==e&&(this._prevBackground=this.context.scene.background),this.context.scene.environment!==e&&(this._prevEnvironment=this.context.scene.environment),jt&&console.log("Set remote skybox",this.url,!ci.backgroundShouldBeTransparent(this.context)),this.environment&&(this.context.scene.environment=e),this.background&&!ci.backgroundShouldBeTransparent(this.context)&&(this.context.scene.background=e),((n=this.context.mainCameraComponent)==null?void 0:n.backgroundBlurriness)!==void 0&&(this.context.scene.backgroundBlurriness=this.context.mainCameraComponent.backgroundBlurriness))}isRemoteTexture(n){return n.startsWith("http://")||n.startsWith("https://")}isValidTextureType(n){for(const e of this.validTextureTypes)if(n.endsWith(e))return!0;return!1}registerDropEvents(){this.unregisterDropEvents(),this.context.domElement.addEventListener("dragover",this.onDragOverEvent),this.context.domElement.addEventListener("drop",this.onDrop)}unregisterDropEvents(){this.context.domElement.removeEventListener("dragover",this.onDragOverEvent),this.context.domElement.removeEventListener("drop",this.onDrop)}};Eh([Q0(ha.prototype.urlChangedSyncField),m(URL)],ha.prototype,"url"),Eh([m()],ha.prototype,"allowDrop"),Eh([m()],ha.prototype,"background"),Eh([m()],ha.prototype,"environment"),Eh([m()],ha.prototype,"allowNetworking");let Xp=ha;function OI(n,e,t){const s=e&&!t;switch(n?.toLowerCase()){case"studio":return s?"https://cdn.needle.tools/static/skybox/modelviewer-Neutral-small.hdr":"https://cdn.needle.tools/static/skybox/modelviewer-Neutral.hdr";case"blurred-skybox":return s?"https://cdn.needle.tools/static/skybox/blurred-skybox-small.exr":"https://cdn.needle.tools/static/skybox/blurred-skybox.exr";case"quicklook-ar":return s?"https://cdn.needle.tools/static/skybox/QuickLook-ARMode-small.exr":"https://cdn.needle.tools/static/skybox/QuickLook-ARMode.exr";case"quicklook":return s?"https://cdn.needle.tools/static/skybox/QuickLook-ObjectMode-small.exr":"https://cdn.needle.tools/static/skybox/QuickLook-ObjectMode.exr"}return n===void 0?null:n}var kI=Object.defineProperty,Qp=(n,e,t,s)=>{for(var o=void 0,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=l(e,t,o)||o);return o&&kI(e,t,o),o},Yp;const Ah=(Yp=class extends I{constructor(){super(...arguments),a(this,"target",null),a(this,"followFactor",.1),a(this,"rotateFactor",.1),a(this,"positionAxes",Qa.All),a(this,"flipForward",!1),a(this,"_firstUpdate",!0)}onBeforeRender(){this.updateNow(!1)}updateNow(n){if(!(!this.target||this.target===this.gameObject)){if(this.followFactor>0){const e=ee(this.target),t=this._firstUpdate||n?1:W.clamp01(this.context.time.deltaTime*this.followFactor),s=this.worldPosition;this.positionAxes&Qa.X&&(s.x=W.lerp(s.x,e.x,t)),this.positionAxes&Qa.Y&&(s.y=W.lerp(s.y,e.y,t)),this.positionAxes&Qa.Z&&(s.z=W.lerp(s.z,e.z,t)),this.worldPosition=s}if(this.rotateFactor>0){const e=Se(this.target);this.flipForward&&e.premultiply(Yp._invertForward);const t=this._firstUpdate||n?1:W.clamp01(this.context.time.deltaTime*this.rotateFactor);this.worldQuaternion=this.worldQuaternion.slerp(e,t)}this._firstUpdate=!1}}},a(Yp,"_invertForward",new V().setFromAxisAngle(new S(0,1,0),Math.PI)),Yp);Qp([m(E)],Ah.prototype,"target"),Qp([m()],Ah.prototype,"followFactor"),Qp([m()],Ah.prototype,"rotateFactor"),Qp([m()],Ah.prototype,"positionAxes");let Kp=Ah;var MI=Object.defineProperty,Ih=(n,e,t,s)=>{for(var o=void 0,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=l(e,t,o)||o);return o&&MI(e,t,o),o};const Lh=C("debugspatialtrigger"),RS=new po,TS=new po;function RI(n,e){return RS.mask=n,TS.mask=e,RS.test(TS)}class bn extends I{constructor(){super(...arguments),a(this,"triggerMask",0),a(this,"onEnter"),a(this,"onStay"),a(this,"onExit"),a(this,"currentIntersected",[]),a(this,"lastIntersected",[])}start(){Lh&&console.log(this.name,this.triggerMask,this)}update(){this.currentIntersected.length=0;for(const e of Zp.triggers)RI(e.triggerMask,this.triggerMask)&&e.test(this.gameObject)&&this.currentIntersected.push(e);for(let e=this.lastIntersected.length-1;e>=0;e--){const t=this.lastIntersected[e];this.currentIntersected.indexOf(t)<0&&(this.onExitTrigger(t),this.lastIntersected.splice(e,1))}for(const e of this.currentIntersected)this.lastIntersected.indexOf(e)<0&&this.onEnterTrigger(e),this.onStayTrigger(e);this.lastIntersected.length=0,this.lastIntersected.push(...this.currentIntersected)}onEnterTrigger(e){var t;Lh&&console.log("ENTER TRIGGER",this.name,e.name,this,e),e.raiseOnEnterEvent(this),(t=this.onEnter)==null||t.invoke()}onExitTrigger(e){var t;Lh&&console.log("EXIT TRIGGER",this.name,e.name),e.raiseOnExitEvent(this),(t=this.onExit)==null||t.invoke()}onStayTrigger(e){var t;e.raiseOnStayEvent(this),(t=this.onStay)==null||t.invoke()}}Ih([m()],bn.prototype,"triggerMask"),Ih([m(xe)],bn.prototype,"onEnter"),Ih([m(xe)],bn.prototype,"onStay"),Ih([m(xe)],bn.prototype,"onExit");var Tl;const ES=(Tl=class extends I{constructor(){super(...arguments),a(this,"triggerMask"),a(this,"boxHelper")}start(){Lh&&console.log(this.name,this.triggerMask,this)}onEnable(){var n;Tl.triggers.push(this),this.boxHelper||(this.boxHelper=P.addComponent(this.gameObject,Do),(n=this.boxHelper)==null||n.showHelper(null,Lh))}onDisable(){Tl.triggers.splice(Tl.triggers.indexOf(this),1)}test(n){return this.boxHelper?this.boxHelper.isInBox(n)??!1:!1}raiseOnEnterEvent(n){P.foreachComponent(this.gameObject,e=>{e!==n&&e instanceof bn&&e.onEnterTrigger(this)},!1)}raiseOnStayEvent(n){P.foreachComponent(this.gameObject,e=>{e!==n&&e instanceof bn&&e.onStayTrigger(this)},!1)}raiseOnExitEvent(n){P.foreachComponent(this.gameObject,e=>{e!==n&&e instanceof bn&&e.onExitTrigger(this)},!1)}},a(Tl,"triggers",[]),Tl);Ih([m()],ES.prototype,"triggerMask");let Zp=ES;var TI=Object.defineProperty,EI=(n,e,t,s)=>{for(var o=void 0,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=l(e,t,o)||o);return o&&TI(e,t,o),o};const Hi=C("debugspectator");class Jp extends I{constructor(){super(...arguments),a(this,"cam",null),a(this,"useKeys",!0),a(this,"_mode",0),a(this,"orbit",null),a(this,"_handler"),a(this,"eventSub_WebXRRequestStartEvent",null),a(this,"eventSub_WebXRStartEvent",null),a(this,"eventSub_WebXREndEvent",null),a(this,"_debug"),a(this,"_networking")}get mode(){return this._mode}set mode(e){this._mode=e}get isSpectating(){var e;return((e=this._handler)==null?void 0:e.currentTarget)!==void 0}isSpectatingUser(e){var t;return((t=this.target)==null?void 0:t.userId)===e}isFollowedBy(e){var t;return(t=this.followers)==null?void 0:t.includes(e)}get followers(){return this._networking.followers}stopSpectating(){if(this.context.isInXR){this.followSelf();return}this.target=void 0}get localId(){return this.context.connection.connectionId??"local"}set target(e){var t;if(this._handler){const s=(t=this._handler.currentTarget)==null?void 0:t.userId,o=this.context.players.getPlayerView(this.localId);e===void 0||this.context.isInXR===!1&&o?.currentObject===e.currentObject?this._handler.currentTarget!==void 0&&(this._handler.disable(),P.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),this._networking.onSpectatedObjectChanged(e,s)):this._handler.currentTarget!==e&&(this._handler.set(e),P.setActive(this.gameObject,!0),this.orbit&&(this.orbit.enabled=!1),this._networking.onSpectatedObjectChanged(e,s))}}get target(){var e;return(e=this._handler)==null?void 0:e.currentTarget}requestAllFollowMe(){this._networking.onRequestFollowMe()}get isSpectatingSelf(){var e,t;return this.isSpectating&&((e=this.target)==null?void 0:e.currentObject)===((t=this.context.players.getPlayerView(this.localId))==null?void 0:t.currentObject)}awake(){if(this._debug=new LI(this.context,this),this._networking=new BI(this.context,this),this._networking.awake(),P.setActive(this.gameObject,!1),this.cam=P.getComponent(this.gameObject,ci),!this.cam){console.warn("SpectatorCamera: Spectator camera needs camera component on the same object.",this);return}!this._handler&&this.cam&&(this._handler=new AI(this.context,this.cam,this)),this.orbit=P.getComponent(this.context.mainCamera,_e)}onDestroy(){var e,t;this.stopSpectating(),(e=this._handler)==null||e.destroy(),(t=this._networking)==null||t.destroy()}isSupportedPlatform(){const e=window.navigator.userAgent,t=/Windows|MacOS/.test(e),s=/Windows NT/.test(e)&&/Edg/.test(e)&&!/Win64/.test(e);return t&&!s}onBeforeXR(e){this.isSupportedPlatform()&&P.setActive(this.gameObject,!0)}onEnterXR(e){this.isSupportedPlatform()&&(Hi&&console.log(this.context.mainCamera),this.context.mainCamera&&this.followSelf())}onLeaveXR(e){var t,s;this.context.removeCamera(this.cam),P.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),(t=this._handler)==null||t.set(void 0),(s=this._handler)==null||s.disable(),this.isSpectatingSelf&&this.stopSpectating()}followSelf(){this.target=this.context.players.getPlayerView(this.context.connection.connectionId),this.target||(this.context.players.setPlayerView(this.localId,this.context.mainCamera,Co.Headset),this.target=this.context.players.getPlayerView(this.localId)),Hi&&console.log("Follow self",this.target)}onAfterRender(){var e,t,s;if(!this.cam)return;const o=this.context.renderer,r=o.xr.enabled;if(!o.xr.isPresenting&&!((e=this._handler)!=null&&e.currentTarget))return;(t=this._handler)==null||t.update(this._mode);const l=o.getRenderTarget();let c=null;const h=o.state;if(!l){if(!o.state.bindFramebuffer||!h.bindXRFramebuffer)return;c=o._framebuffer,h.bindXRFramebuffer(null)}this.setAvatarFlagsBeforeRender();const d=this.context.mainCameraComponent;if(d){const g=d.backgroundColor;g&&o.setClearColor(g,g.alpha),this.cam.backgroundColor=g,this.cam.clearFlags=d.clearFlags,this.cam.nearClipPlane=d.nearClipPlane,this.cam.farClipPlane=d.farClipPlane}else o.setClearColor(new oe(1,1,1));o.setRenderTarget(null),o.xr.enabled=!1;const u=(s=this.cam)==null?void 0:s.threeCamera;this.context.updateAspect(u);const p=o.xr.isPresenting;o.xr.isPresenting=!1,o.setSize(this.context.domWidth,this.context.domHeight),o.render(this.context.scene,u),o.xr.isPresenting=p,o.xr.enabled=r,l?o.setRenderTarget(l):h.bindXRFramebuffer&&h.bindXRFramebuffer(c),this.resetAvatarFlags()}setAvatarFlagsBeforeRender(){const e=this._mode===0;for(const t of hi.instances)if(t.avatar&&"isLocalAvatar"in t.avatar&&"flags"in t.avatar){let s=an.All;this.isSpectatingSelf&&(s=e&&t.avatar.isLocalAvatar?an.FirstPerson:an.ThirdPerson);const o=t.avatar.flags;if(!o)continue;for(const r of o)r.UpdateVisible(s)}}resetAvatarFlags(){var e;for(const t of hi.instances)if(t.avatar&&"flags"in t.avatar){const s=t.avatar.flags;if(!s)continue;for(const o of s)"isLocalAvatar"in t.avatar&&(e=t.avatar)!=null&&e.isLocalAvatar?o.UpdateVisible(an.FirstPerson):o.UpdateVisible(an.ThirdPerson)}}}EI([m()],Jp.prototype,"useKeys");class AI{constructor(e,t,s){a(this,"context"),a(this,"cam"),a(this,"spectator"),a(this,"follow"),a(this,"target"),a(this,"view"),a(this,"currentObject"),this.context=e,this.cam=t,this.spectator=s}get currentTarget(){return this.view}set(e){const t=e?.currentObject;if(!t){this.spectator.stopSpectating();return}t!==this.currentObject&&(this.currentObject=t,this.view=e,this.follow||(this.follow=P.addComponent(this.cam.gameObject,Kp)),this.target||(this.target=new E),t.add(this.target),this.follow.enabled=!0,this.follow.target=this.target,Hi&&console.log("FOLLOW",t),this.context.isInXR?this.context.removeCamera(this.cam):this.context.setCurrentCamera(this.cam))}disable(){Hi&&console.log("STOP FOLLOW",this.currentObject),this.view=void 0,this.currentObject=void 0,this.context.removeCamera(this.cam),this.follow&&(this.follow.enabled=!1)}destroy(){var e;(e=this.target)==null||e.removeFromParent(),this.follow&&P.destroy(this.follow)}update(e){var t,s,o,r,l,c;if(((t=this.currentTarget)==null?void 0:t.isConnected)===!1||((s=this.currentTarget)==null?void 0:s.removed)===!0){Hi&&console.log("Target disconnected or timeout",this.currentTarget),this.spectator.stopSpectating();return}this.currentTarget&&((o=this.currentTarget)==null?void 0:o.currentObject)!==this.currentObject&&(Hi&&console.log("Target changed",this.currentObject,"to",this.currentTarget.currentObject),this.set(this.currentTarget));const h=this.context.mainCamera;if(h){const u=this.cam.threeCamera;(u.near!==h.near||u.far!==h.far)&&(u.near=h.near,u.far=h.far,u.updateProjectionMatrix())}const d=(r=this.follow)==null?void 0:r.target;if(!(!d||!this.follow)){switch(e){case 0:((l=this.view)==null?void 0:l.viewDevice)!==Co.Browser?(this.follow.followFactor=5,this.follow.rotateFactor=5):(this.follow.followFactor=50,this.follow.rotateFactor=50),d.position.set(0,0,0);break;case 1:this.follow.followFactor=3,this.follow.rotateFactor=2,d.position.set(0,.5,1.5);break}this.follow.flipForward=!1,((c=this.view)==null?void 0:c.viewDevice)!==Co.Browser?d.quaternion.copy(II):d.quaternion.identity()}}}const II=new V().setFromAxisAngle(new S(0,1,0),Math.PI);class LI{constructor(e,t){a(this,"context"),a(this,"spectator"),this.context=e,this.spectator=t,console.log("[Spectator Camera] Click other avatars or cameras to follow them. Press ESC to exit spectator mode."),this.context.domElement.addEventListener("keydown",o=>{!this.spectator.useKeys||o.key==="Escape"&&this.spectator.stopSpectating()});let s=0;this.context.input.addEventListener(Be.PointerDown,o=>{s=this.context.time.time}),this.context.input.addEventListener(Be.PointerUp,o=>{const r=this.context.time.time-s;r>1?this.spectator.stopSpectating():this.context.input.getPointerClicked(0)&&r<.3&&this.trySelectObject()})}trySelectObject(){const e=new Qs;e.setMask(16777215);const t=this.context.physics.raycast(e);if(Hi&&console.log(...t),t!=null&&t.length)for(const s of t){if(s.distance<.2)continue;const o=s.object,r=P.getComponentInParent(o,hi),l=r?.connectionId;if(l){const c=this.context.players.getPlayerView(l);this.spectator.target=c,Hi&&console.log("spectate",l,r);break}}}}class jI{constructor(e,t,s){a(this,"guid"),a(this,"dontSave",!0),a(this,"targetUserId"),a(this,"stoppedFollowing"),this.guid=e,this.targetUserId=t,this.stoppedFollowing=s}}class DI{constructor(e,t){a(this,"guid"),a(this,"userId"),this.guid=e.guid,this.userId=t}}class BI{constructor(e,t){a(this,"followers",[]),a(this,"context"),a(this,"spectator"),a(this,"_followerEventMethod"),a(this,"_requestFollowMethod"),a(this,"_joinedRoomMethod"),a(this,"_lastRequestFollowUser"),a(this,"_enforceFollowInterval"),this.context=e,this.spectator=t,this._followerEventMethod=this.onFollowerEvent.bind(this),this._requestFollowMethod=this.onRequestFollowEvent.bind(this),this._joinedRoomMethod=this.onUserJoinedRoom.bind(this)}awake(){this.context.connection.beginListen("spectator-follower-changed",this._followerEventMethod),this.context.connection.beginListen("spectator-request-follow",this._requestFollowMethod),this.context.connection.beginListen(ie.JoinedRoom,this._joinedRoomMethod),this.context.domElement.addEventListener("keydown",e=>{this.spectator.useKeys&&(e.key==="f"?this.onRequestFollowMe():e.key==="Escape"&&this.onRequestFollowMe(!0))})}destroy(){this.context.connection.stopListen("spectator-follower-changed",this._followerEventMethod),this.context.connection.stopListen("spectator-request-follow",this._requestFollowMethod),this.context.connection.stopListen(ie.JoinedRoom,this._joinedRoomMethod)}onSpectatedObjectChanged(e,t){if(Hi&&console.log(this.context.connection.connectionId,"onSpectatedObjectChanged",e,t),this.context.connection.connectionId){const s=e?.userId===void 0,o=s?t:e?.userId,r=new jI(this.context.connection.connectionId,o,s);this.context.connection.send("spectator-follower-changed",r)}}onRequestFollowMe(e=!1){if(Hi&&console.log("Request follow",this.context.connection.connectionId),this.context.connection.connectionId){this.spectator.stopSpectating();const t=e?void 0:this.context.connection.connectionId,s=new DI(this.spectator,t);this.context.connection.send("spectator-request-follow",s)}}onUserJoinedRoom(){C("followme")&&this.onRequestFollowMe()}onFollowerEvent(e){const t=e.targetUserId,s=e.guid;if(Hi&&console.log(e),t===this.context.connection.connectionId)if(e.stoppedFollowing){const o=this.followers.indexOf(s);o!==-1&&(this.followers.splice(o,1),this.removeDisconnectedFollowers(),console.log(s,"unfollows you",this.followers.length))}else this.followers.includes(s)||(this.followers.push(s),this.removeDisconnectedFollowers(),console.log(s,"follows you",this.followers.length))}removeDisconnectedFollowers(){for(let e=this.followers.length-1;e>=0;e--){const t=this.followers[e];this.context.connection.userIsInRoom(t)===!1&&this.followers.splice(e,1)}}onRequestFollowEvent(e){if(this._lastRequestFollowUser=e,e.userId===this.context.connection.connectionId)this.spectator.stopSpectating();else if(e.userId===void 0)this.spectator.stopSpectating();else{const t=this.context.players.getPlayerView(e.userId);if(t)this.spectator.target=t;else return Hi&&console.warn("Could not find view",e.userId),this.enforceFollow(),!1}return!0}enforceFollow(){this._enforceFollowInterval||(this._enforceFollowInterval=setInterval(()=>{this._lastRequestFollowUser===void 0||this._lastRequestFollowUser.userId&&this.spectator.isFollowedBy(this._lastRequestFollowUser.userId)?(clearInterval(this._enforceFollowInterval),this._enforceFollowInterval=void 0):(Hi&&console.log("REQUEST FOLLOW AGAIN",this._lastRequestFollowUser.userId),this.onRequestFollowEvent(this._lastRequestFollowUser))},1e3))}}class Cn{constructor(){a(this,"bb",null),a(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}static getRootAsSyncedCameraModel(e,t){return(t||new Cn).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsSyncedCameraModel(e,t){return e.setPosition(e.position()+Jv),(t||new Cn).__init(e.readInt32(e.position())+e.position(),e)}userId(e){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__string(this.bb_pos+t,e):null}guid(e){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__string(this.bb_pos+t,e):null}dontSave(){const e=this.bb.__offset(this.bb_pos,8);return e?!!this.bb.readInt8(this.bb_pos+e):!1}pos(e){const t=this.bb.__offset(this.bb_pos,10);return t?(e||new Fr).__init(this.bb_pos+t,this.bb):null}rot(e){const t=this.bb.__offset(this.bb_pos,12);return t?(e||new Fr).__init(this.bb_pos+t,this.bb):null}static startSyncedCameraModel(e){e.startObject(5)}static addUserId(e,t){e.addFieldOffset(0,t,0)}static addGuid(e,t){e.addFieldOffset(1,t,0)}static addDontSave(e,t){e.addFieldInt8(2,+t,0)}static addPos(e,t){e.addFieldStruct(3,t,0)}static addRot(e,t){e.addFieldStruct(4,t,0)}static endSyncedCameraModel(e){return e.endObject()}static finishSyncedCameraModelBuffer(e,t){e.finish(t)}static finishSizePrefixedSyncedCameraModelBuffer(e,t){e.finish(t,void 0,!0)}}var FI=Object.defineProperty,UI=(n,e,t,s)=>{for(var o=void 0,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=l(e,t,o)||o);return o&&FI(e,t,o),o};const em="SCAM";Eg(em,Cn.getRootAsSyncedCameraModel);const Gi=new Hm;class zI{constructor(e,t){a(this,"userId"),a(this,"guid"),this.guid=t,this.userId=e}send(e,t){if(e){Gi.clear();const s=Gi.createString(this.guid),o=Gi.createString(this.userId);Cn.startSyncedCameraModel(Gi),Cn.addGuid(Gi,s),Cn.addUserId(Gi,o);const r=ee(e),l=Id(e);Cn.addPos(Gi,Fr.createVec3(Gi,r.x,r.y,r.z)),Cn.addRot(Gi,Fr.createVec3(Gi,l.x,l.y,l.z));const c=Cn.endSyncedCameraModel(Gi);Gi.finish(c,em),t.sendBinary(Gi.asUint8Array())}}}var jh;const AS=(jh=class extends I{constructor(){super(...arguments),a(this,"cameraPrefab",null),a(this,"_lastWorldPosition"),a(this,"_lastWorldQuaternion"),a(this,"_model",null),a(this,"_needsUpdate",!0),a(this,"_lastUpdateTime",0),a(this,"remoteCams",{}),a(this,"userToCamMap",{}),a(this,"_camTimeoutInSeconds",10),a(this,"_receiveCallback",null)}getCameraObject(n){const e=this.userToCamMap[n];return e?this.remoteCams[e].obj:null}async awake(){this._lastWorldPosition=this.worldPosition.clone(),this._lastWorldQuaternion=this.worldQuaternion.clone(),this.cameraPrefab&&("uri"in this.cameraPrefab&&(this.cameraPrefab=await this.cameraPrefab.instantiate(this.gameObject)),this.cameraPrefab&&"isObject3D"in this.cameraPrefab&&(this.cameraPrefab.visible=!1))}onEnable(){this._receiveCallback=this.context.connection.beginListenBinary(em,this.onReceivedRemoteCameraInfoBin.bind(this))}onDisable(){this.context.connection.stopListenBinary(em,this._receiveCallback)}update(){for(const s in this.remoteCams){const o=this.remoteCams[s],r=this.context.time.realtimeSinceStartup-o.lastUpdate;if(!o||r>this._camTimeoutInSeconds){F()&&console.log("Remote cam timeout",s),o!=null&&o.obj&&P.destroy(o.obj),delete this.remoteCams[s],o&&delete this.userToCamMap[o.userId],jh.instances.push(o),this.context.players.removePlayerView(o.userId,Co.Browser);continue}}if(this.context.isInXR)return;const n=this.context.mainCamera;if(n===null){this.enabled=!1;return}if(!this.context.connection.isConnected||this.context.connection.connectionId===null)return;this._model===null&&(this._model=new zI(this.context.connection.connectionId,this.context.connection.connectionId+"_camera"));const e=ee(n),t=Se(n);(e.distanceTo(this._lastWorldPosition)>.001||t.angleTo(this._lastWorldQuaternion)>.01)&&(this._needsUpdate=!0),this._lastWorldPosition.copy(e),this._lastWorldQuaternion.copy(t),!((!this._needsUpdate||this.context.time.frameCount%2!==0)&&!(this.context.time.realtimeSinceStartup-this._lastUpdateTime>this._camTimeoutInSeconds*.5))&&(this._lastUpdateTime=this.context.time.realtimeSinceStartup,this._needsUpdate=!1,this._model.send(n,this.context.connection),this.context.isInXR||this.context.players.setPlayerView(this.context.connection.connectionId,n,Co.Browser))}onReceivedRemoteCameraInfoBin(n){const e=n.guid();if(!e)return;const t=n.userId();if(!t||!this.context.connection.userIsInRoom(t)||!this.cameraPrefab)return;let s=this.remoteCams[e];if(!s)if("isObject3D"in this.cameraPrefab){const c=new Bs;c.context=this.context;const h=P.instantiate(this.cameraPrefab,c);s=this.remoteCams[e]={obj:h,lastUpdate:this.context.time.realtimeSinceStartup,userId:t},s.obj.visible=!0,this.gameObject.add(h),this.userToCamMap[t]=e,jh.instances.push(s);const d=P.getOrAddComponent(h,hi);d.connectionId=t,d.avatar=h}else return;const o=s.obj;this.context.players.setPlayerView(t,o,Co.Browser),s.lastUpdate=this.context.time.realtimeSinceStartup,ms.markDirty(o);const r=n.pos();r&&vr(o,r.x(),r.y(),r.z());const l=n.rot();l&&Jl(o,l.x(),l.y(),l.z())}},a(jh,"instances",[]),jh);UI([m([E,ce])],AS.prototype,"cameraPrefab");let $y=AS;var NI=Object.defineProperty,WI=Object.getOwnPropertyDescriptor,ar=(n,e,t,s)=>{for(var o=s>1?void 0:s?WI(e,t):e,r=n.length-1,l;r>=0;r--)(l=n[r])&&(o=(s?l(e,t,o):l(o))||o);return s&&o&&NI(e,t,o),o};const Hy="view",Gy=C("debugsyncedroom");class Is extends I{constructor(){super(...arguments),a(this,"roomName",""),a(this,"urlParameterName","room"),a(this,"joinRandomRoom"),a(this,"requireRoomParameter",!1),a(this,"autoRejoin",!0),a(this,"createJoinButton",!0),a(this,"createViewOnlyButton",!1),a(this,"_lastJoinedRoom"),a(this,"_roomPrefix",""),a(this,"_lastPingTime",0),a(this,"_lastRoomTime",-1),a(this,"_userWantsToBeInARoom",!1),a(this,"_roomButton"),a(this,"_roomButtonIconJoin"),a(this,"_roomButtonIconLeave"),a(this,"updateRoomButtonState",()=>{var e,t;this._roomButton&&(this.context.connection.isInRoom?(this._roomButton.title="Leave the networked room",this._roomButton.textContent="Leave Room",(e=this._roomButtonIconJoin)==null||e.remove(),this._roomButton.prepend(this._roomButtonIconLeave)):(this._roomButton.title="Create or join a networked room",this._roomButton.textContent="Join Room",(t=this._roomButtonIconLeave)==null||t.remove(),this._roomButton.prepend(this._roomButtonIconJoin)))}),a(this,"_viewOnlyButton"),a(this,"onCreateViewOnlyButton",()=>{if(!this._viewOnlyButton){const e=document.createElement("button");this._viewOnlyButton=e,e.classList.add("view-only-button"),e.setAttribute("priority","90"),e.onclick=()=>{var t;const s=this.getViewOnlyUrl();s!=null&&s.length?navigator.canShare({url:s})?(t=navigator.share({url:s}))==null||t.catch(o=>{console.warn(o)}):(navigator.clipboard.writeText(s),De("View only URL copied to clipboard")):be("Could not create view only URL")},e.title="Copy the view only URL: A page accessed by the view only URL can not be modified by visiting users.",e.textContent="Share View URL",e.prepend(Mt("visibility"))}this.context.menu.appendChild(this._viewOnlyButton)})}get currentRoomName(){return C(Hy)||C(this.urlParameterName)}set roomPrefix(e){this._roomPrefix=e}get roomPrefix(){return this._roomPrefix}awake(){var e;this.joinRandomRoom===void 0&&((e=this.roomName)==null?void 0:e.length)<=0&&(this.joinRandomRoom=!0),Gy&&console.log(`SyncedRoom roomName:${this.roomName}, urlParamName:${this.urlParameterName}, joinRandomRoom:${this.joinRandomRoom}`)}onEnable(){const e=C(Hy);if(e&&typeof e=="string"&&e.length>0){console.log("Join as viewer"),this.context.connection.joinRoom(e,!0);return}if(this.tryJoinRoom(),this.createJoinButton){const t=this.createRoomButton();this.context.menu.appendChild(t)}this.createViewOnlyButton&&this.onEnableViewOnlyButton()}onDisable(){var e;(e=this._roomButton)==null||e.remove(),this.onDisableViewOnlyButton(),this.roomName&&this.roomName.length>0&&this.context.connection.leaveRoom(this.roomName)}onDestroy(){this.destroyRoomButton()}tryJoinRandomRoom(){this.setRandomRoomUrlParameter(),this.tryJoinRoom()}tryJoinRoom(e=0){var t;e===void 0&&(e=0);let s=!1;if(((t=this.urlParameterName)==null?void 0:t.length)>0){const o=C(this.urlParameterName);if(o&&(typeof o=="string"||typeof o=="number")){s=!0;const r=pb(o.toString());this.roomName=r}else if(this.joinRandomRoom&&(console.log("No room name found in url, generating random one"),this.setRandomRoomUrlParameter(),e<1))return this.tryJoinRoom(e+1)}else this.joinRandomRoom&&(this.roomName===null||this.roomName===void 0||this.roomName.length<=0)&&(this.roomName=this.generateRoomName());return this.requireRoomParameter&&!s?((Gy||F())&&console.warn('[SyncedRoom] Missing required room parameter "'+this.urlParameterName+`" in url - will not connect.
1390
1390
  To allow joining a room without a query parameter you can set "requireRoomParameter" to false.`),!1):(this.context.connection.isConnected||this.context.connection.connect(),this._lastJoinedRoom=this.roomName,this._roomPrefix&&(this.roomName=this._roomPrefix+this.roomName),this.roomName.length<=0?(console.warn(`[SyncedRoom] Room name is not set so we can not join a networked room.
1391
1391
  Please choose one of the following options to fix this:
1392
1392
  A) Set a room name in the SyncedRoom component
@@ -1569,7 +1569,7 @@ Needle Engine: Begin loading `+o+`
1569
1569
  `,s),this.onBeforeBeginLoading();const h=[],d={context:this._context,name:"",progress:{},index:0,count:s.length,totalProgress01:this._loadingProgress01},u=new CustomEvent("progress",{detail:d}),p=new Array,g=new AbortController;this._abortController=g;const f={files:s,abortSignal:g.signal,onLoadingProgress:b=>{var _;if(Ie&&console.debug("Loading progress: ",b),g.signal.aborted)return;const w=b.index;!p[w]&&b.name&&(p[w]=DL(b.name)),b.name=p[w],c&&((_=this._loadingView)==null||_.onLoadingUpdate(b)),d.name=b.name,d.progress=b.progress,this._loadingProgress01=hv(b),d.totalProgress01=this._loadingProgress01,this.dispatchEvent(u)},onLoadingFinished:(b,_,w)=>{Ie&&console.debug(`Finished loading "${_}" (aborted? ${g.signal.aborted})`),!g.signal.aborted&&w&&h.push({src:_,file:w})}};BL(this);const y=this.getAttribute("hash");y!=null&&(this._context.hash=y),this._context.alias=r,this._createContextPromise=this._context.create(f);const v=await this._createContextPromise;if(this.applyAttributes(),Ie&&console.warn(`--------------
1570
1570
  Needle Engine: finished loading `+o+`
1571
1571
  `,s,`Aborted? ${g.signal.aborted}`),g.signal.aborted){console.log("Loading finished but aborted...");return}if(this._loadId!==o){console.log("Load id changed during loading process");return}this._loadingProgress01=1,c&&v&&((t=this._loadingView)==null||t.onLoadingUpdate(1,"creating scene")),this._didFullyLoad=!0,this.classList.remove("loading"),this.classList.add("loading-finished"),this.dispatchEvent(new CustomEvent("loadfinished",{detail:{context:this._context,src:r,loadedFiles:h}}))}applyAttributes(){var e,t;if((e=this._context)!=null&&e.renderer){const r=qw(this.toneMapping);r!==void 0&&(this._context.renderer.toneMapping=r);const l=this.getAttribute("tone-mapping-exposure");if(l!=null){const c=parseFloat(l);isNaN(c)||(this._context.renderer.toneMappingExposure=c)}}const s=this.getAttribute("background-blurriness");if(s!=null){const r=parseFloat(s);r!==void 0&&this._context&&(this._context.scene.backgroundBlurriness=r)}const o=this.getAttribute("background-color");if((t=this._context)!=null&&t.renderer&&typeof o=="string"&&o.length>0){const r=he.fromColorRepresentation(o);Ie&&console.debug("<needle-engine> background-color changed, str:",o,"\u2192",r),this._context.renderer.setClearColor(r,r.alpha),this.context.scene.background=null}}getSourceFiles(){const e=this.getAttribute("src");if(!e)return[];let t;Array.isArray(e)?t=e:e.startsWith("[")&&e.endsWith("]")?t=JSON.parse(e):e.includes(",")?t=e.split(","):t=[e];for(let s=t.length-1;s>=0;s--){const o=t[s];(o==="null"||o==="undefined"||o?.length<=0)&&t.splice(s,1)}return t}checkIfSourceHasChanged(e,t){if(e?.length!==t?.length||e==null&&t!==null||e!==null&&t==null)return!0;if(e!==null&&t!==null){for(let s=0;s<e?.length;s++)if(e[s]!==t[s])return!0}return!1}ensureLoadStartIsRegistered(){const e=this.getAttribute("loadstart");e&&this.registerEventFromAttribute("loadstart",e)}registerEventFromAttribute(e,t){const s=this._previouslyRegisteredMap.get(e);if(s&&(this._previouslyRegisteredMap.delete(e),this.removeEventListener(e,s)),typeof t=="string"&&t.length>0)try{const o=(0,eval)(t);typeof o=="function"&&(this._previouslyRegisteredMap.set(e,o),this.addEventListener(e,r=>o?.call(globalThis,this._context,r)))}catch(o){console.error("Error registering event "+e+'="'+t+`" failed with the following error:
1572
- `,o)}}setPublicKey(){Ea&&Ea.length>0&&this.setAttribute("public-key",Ea)}setVersion(){_s.length>0&&this.setAttribute("version",_s)}getAROverlayContainer(){return this._overlay_ar.createOverlayContainer(this)}getVROverlayContainer(){for(let e=0;e<this.children.length;e++){const t=this.children[e];if(t.classList.contains("vr"))return t}return null}onEnterAR(e){var t;this.onSetupAR();const s=this.getAROverlayContainer();this._overlay_ar.onBegin(this._context,s,e),this.dispatchEvent(new CustomEvent("enter-ar",{detail:{session:e,context:this._context,htmlContainer:(t=this._overlay_ar)==null?void 0:t.ARContainer}}))}onExitAR(e){var t;this._overlay_ar.onEnd(this._context),this.onSetupDesktop(),this.dispatchEvent(new CustomEvent("exit-ar",{detail:{session:e,context:this._context,htmlContainer:(t=this._overlay_ar)==null?void 0:t.ARContainer}}))}onEnterVR(e){this.onSetupVR(),this.dispatchEvent(new CustomEvent("enter-vr",{detail:{session:e,context:this._context}}))}onExitVR(e){this.onSetupDesktop(),this.dispatchEvent(new CustomEvent("exit-vr",{detail:{session:e,context:this._context}}))}onSetupAR(){this.classList.add(ed),this.classList.remove(td);const e=this.getAROverlayContainer();Ie&&console.warn("onSetupAR:",e),e&&(e.classList.add(ed),e.classList.remove(td)),this.foreachHtmlElement(t=>this.setupElementsForMode(t,QS))}onSetupVR(){this.classList.remove(ed),this.classList.remove(td),this.foreachHtmlElement(e=>this.setupElementsForMode(e,tC))}onSetupDesktop(){this.classList.remove(ed),this.classList.add(td);const e=this.getAROverlayContainer();e&&(e.classList.remove(ed),e.classList.add(td)),this.foreachHtmlElement(t=>this.setupElementsForMode(t,iC))}setupElementsForMode(e,t,s=null){var o,r;if(!(e===((r=(o=this._context)==null?void 0:o.renderer)==null?void 0:r.domElement)||e.id==="VRButton"||e.id==="ARButton"))if(e.classList.contains(t))e.style.visibility="visible",e.style.display==="none"&&(e.style.display="block");else for(const l of LL)e.classList.contains(l)&&(e.style.visibility="hidden",e.style.display="none")}foreachHtmlElement(e){for(let t=0;t<this.children.length;t++){const s=this.children[t];s.style&&e(s)}}onBeforeBeginLoading(){const e=this.getAttribute("dracoDecoderPath");e&&(Ie&&console.log("using custom draco decoder path",e),ax(e));const t=this.getAttribute("dracoDecoderType");t&&(Ie&&console.log("using custom draco decoder type",t),lx(t));const s=this.getAttribute("ktx2DecoderPath");s&&(Ie&&console.log("using custom ktx2 decoder path",s),cx(s))}}typeof window<"u"&&!window.customElements.get(eC)&&window.customElements.define(eC,dv);function DL(n){if(n.startsWith("blob:"))return"blob";const e=n.split("/");let t=e[e.length-1];const s=t.indexOf("?");s>0&&(t=t.substring(0,s));const o=t.indexOf("=");o>0&&(t=t.substring(o));const r=t.split(".").pop(),l=r?["glb","gltf","usdz","usd","fbx","obj","mtl"].indexOf(r.toLowerCase()):-1;if(r&&l>=0&&(t=t.substring(0,t.length-r.length-1)),t=decodeURIComponent(t),t.length>3){let c="",h=!1;const d=["(",")","[","]","{","}",":",";",",",".","!","?"];for(let u=0;u<t.length;u++){let p=t[u];(p==="_"||p==="-")&&(p=" "),!(p===" "&&c.length<=0||d.includes(p)||(c.length===0&&(p=p.toUpperCase()),h&&p===" "))&&(h&&(p=p.toUpperCase()),h=!1,c+=p,p===" "&&(h=!0))}return F()&&t!==c&&console.debug('Generated display name: "'+t+'" \u2192 "'+c+'"'),c.trim()}return F()&&console.debug("Loading: use default name",t),t}function BL(n){jf(e=>{var t;const s=n.getAttribute("loading-blur");if(s!==null&&s!=="0"&&e.domElement===n){const o=(t=e.lodsManager.manager)==null?void 0:t.awaitLoading({frames:5,signal:AbortSignal.timeout(1e4),maxPromisesPerObject:1}).catch(c=>{});let r="20px";s.endsWith("px")&&(r=s);const l=170;if(e.scene.background===null){const c=n,h=e.renderer.domElement,d=h.style.filter,u=h.style.overflow;h.style.filter+=`blur(${r})`,c.style.overflow="hidden",o?.then(()=>{const p=h.animate([{filter:"blur(0px)"}],{duration:l,easing:"ease-in"});p.onfinish=()=>{h.style.filter=d,c.style.overflow=u}})}else{const c=document.createElement("div");e.domElement.prepend(c),c.style.cssText="position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; pointer-events: none",c.style.backdropFilter=`blur(${r})`,o?.then(()=>{const h=c.animate([{backdropFilter:"blur(0px)",opacity:0}],{duration:l,easing:"ease-in"});h.onfinish=()=>{c.remove()}})}}},{once:!0})}const FL=Object.freeze(Object.defineProperty({__proto__:null,NeedleEngineWebComponent:dv},Symbol.toStringTag,{value:"Module"}));function UL(){jn.registerWaitForInteraction(()=>{const n=$P.getContext();n.addEventListener("statechange",()=>{setTimeout(()=>{const e=n.state;(e==="suspended"||e==="interrupted")&&n.resume().then(()=>{console.log("AudioContext resumed successfully")}).catch(t=>{console.log("Failed to resume AudioContext: "+t)})},500)})})}setTimeout(UL,1e3);const at=C("debugphysics"),uv=C("debugcolliderplacement"),pv=C("debugcollisions"),zL=C("showcolliders"),mv=C("debugraycasts"),_i=Symbol("needle component"),ti=Symbol("physics body"),sC=Symbol("rigidbody");globalThis.NEEDLE_USE_RAPIER=globalThis.NEEDLE_USE_RAPIER!==void 0?globalThis.NEEDLE_USE_RAPIER:!0,at&&console.log("Use Rapier",!0,globalThis.NEEDLE_USE_RAPIER),pe.registerCallback(me.ContextCreationStart,n=>{at&&console.log("Register rapier physics backend"),n.context.physics.engine=new nC(n.context)});const id=class Om{constructor(e){a(this,"debugRenderColliders",!1),a(this,"debugRenderRaycasts",!1),a(this,"context"),a(this,"_initializePromise"),a(this,"_isInitialized",!1),a(this,"rapierRay"),a(this,"raycastVectorsBuffer",new Oi(()=>new S,10)),a(this,"rapierSphere",null),a(this,"rapierColliderArray",[]),a(this,"rapierIdentityRotation",{x:0,y:0,z:0,w:1}),a(this,"rapierForwardVector",{x:0,y:0,z:1}),a(this,"enabled",!1),a(this,"_tempPosition",new S),a(this,"_tempQuaternion",new V),a(this,"_tempScale",new S),a(this,"_tempMatrix",new se),a(this,"_isUpdatingPhysicsWorld",!1),a(this,"_world"),a(this,"_hasCreatedWorld",!1),a(this,"eventQueue"),a(this,"collisionHandler"),a(this,"objects",[]),a(this,"bodies",[]),a(this,"_meshCache",new Map),a(this,"_gravity",{x:0,y:-9.81,z:0}),a(this,"lines"),a(this,"_tempCenterPos",new S),a(this,"_tempCenterVec",new S),a(this,"_tempCenterQuaternion",new V),this.context=e}removeBody(e){var t,s,o;if(!e)return;this.validate();const r=e[ti];if(e[ti]=null,r&&this.world){const l=this.objects.findIndex(c=>c===e);if(l>=0){const c=this.bodies[l];if(this.bodies.splice(l,1),this.objects.splice(l,1),c instanceof A.RAPIER_PHYSICS.MODULE.Collider){const h=c;(t=this.world)==null||t.removeCollider(h,!0);const d=h.parent();d&&d.numColliders()<=0&&(d[_i]||(s=this.world)==null||s.removeRigidBody(d))}else c instanceof A.RAPIER_PHYSICS.MODULE.RigidBody&&(c.numColliders()<=0?(o=this.world)==null||o.removeRigidBody(c):F()&&(c.did_log_removing||setTimeout(()=>{c.numColliders()>0&&(c.did_log_removing=!0,console.warn("RapierPhysics: removing rigidbody with colliders from the physics world is not possible right now, please remove the colliders first"))},1)))}}}updateBody(e,t,s){if(this.validate(),!!this.enabled&&!(e.destroyed||!e.gameObject)&&!(!t&&!s))if(e.isCollider===!0)console.warn("TODO: implement updating collider position");else{const o=e,r=o[ti];r&&this.syncPhysicsBody(o.gameObject,r,t,s)}}updateProperties(e){if(this.validate(),e.isCollider){const t=e,s=t[ti];s&&(this.internalUpdateColliderProperties(t,s),t.sharedMaterial&&this.updatePhysicsMaterial(t))}else{const t=e,s=this.internal_getRigidbody(t);s&&this.internalUpdateRigidbodyProperties(t,s)}}addForce(e,t,s){this.validate();const o=this.internal_getRigidbody(e);o?o.addForce(t,s):console.warn("Rigidbody doesn't exist: can not apply force (does your object with the Rigidbody have a collider?)")}addImpulse(e,t,s){this.validate();const o=this.internal_getRigidbody(e);o?o.applyImpulse(t,s):console.warn("Rigidbody doesn't exist: can not apply impulse (does your object with the Rigidbody have a collider?)")}getLinearVelocity(e){this.validate();const t=this.internal_getRigidbody(e);return t?t.linvel():null}getAngularVelocity(e){this.validate();const t=this.internal_getRigidbody(e);return t?t.angvel():null}resetForces(e,t){this.validate();const s=this.internal_getRigidbody(e);s?.resetForces(t)}resetTorques(e,t){this.validate();const s=this.internal_getRigidbody(e);s?.resetTorques(t)}applyImpulse(e,t,s){this.validate();const o=this.internal_getRigidbody(e);o?o.applyImpulse(t,s):console.warn("Rigidbody doesn't exist: can not apply impulse (does your object with the Rigidbody have a collider?)")}wakeup(e){this.validate();const t=this.internal_getRigidbody(e);t?t.wakeUp():console.warn("Rigidbody doesn't exist: can not wake up (does your object with the Rigidbody have a collider?)")}isSleeping(e){this.validate();const t=this.internal_getRigidbody(e);return t?.isSleeping()}setAngularVelocity(e,t,s){this.validate();const o=this.internal_getRigidbody(e);o?o.setAngvel(t,s):console.warn("Rigidbody doesn't exist: can not set angular velocity (does your object with the Rigidbody have a collider?)")}setLinearVelocity(e,t,s){this.validate();const o=this.internal_getRigidbody(e);o?o.setLinvel(t,s):console.warn("Rigidbody doesn't exist: can not set linear velocity (does your object with the Rigidbody have a collider?)")}get isInitialized(){return this._isInitialized}async initialize(){return this._initializePromise||(this._initializePromise=this.internalInitialization()),this._initializePromise}async internalInitialization(){return C("__nophysics")?(console.warn("Physics are disabled"),!1):(at&&console.log("Initialize rapier physics engine"),this._hasCreatedWorld?(console.error("Invalid call to create physics world: world is already created"),!0):(this._hasCreatedWorld=!0,A.RAPIER_PHYSICS.MAYBEMODULE==null&&(at&&console.trace("Loading rapier physics engine"),await(await A.RAPIER_PHYSICS.load()).init()),at&&console.log("Physics engine initialized, creating world..."),this._world=new A.RAPIER_PHYSICS.MODULE.World(this._gravity),this.rapierRay=new A.RAPIER_PHYSICS.MODULE.Ray({x:0,y:0,z:0},{x:0,y:0,z:1}),this.enabled=!0,this._isInitialized=!0,at&&console.log("Physics world created"),!0))}validate(){this._isInitialized||at&&(this._lastWarnTime=this._lastWarnTime??0,Date.now()-this._lastWarnTime>1e3&&(this._lastWarnTime=Date.now(),console.warn("Physics engine is not initialized")))}raycast(e,t,s){var o;if(!this._isInitialized)return console.log("Physics engine is not initialized"),null;let r=s?.maxDistance,l=s?.solid;r===void 0&&(r=1/0),l===void 0&&(l=!0);const c=this.getPhysicsRay(this.rapierRay,e,t);if(!c)return null;(this.debugRenderRaycasts||mv)&&$.DrawRay(c.origin,c.dir,255,1);const h=(o=this.world)==null?void 0:o.castRay(c,r,l,s?.queryFilterFlags,s?.filterGroups,void 0,void 0,d=>{const u=d[_i];return s!=null&&s.filterPredicate?s.filterPredicate(u):s?.useIgnoreRaycastLayer!==!1?!(u!=null&&u.gameObject.layers.isEnabled(2)):!0});if(h){const d=c.pointAt(h.timeOfImpact),u=this.raycastVectorsBuffer.get();return u.set(d.x,d.y,d.z),{point:u,collider:h.collider[_i]}}return null}raycastAndGetNormal(e,t,s){var o;if(!this._isInitialized)return null;let r=s?.maxDistance,l=s?.solid;r===void 0&&(r=1/0),l===void 0&&(l=!0);const c=this.getPhysicsRay(this.rapierRay,e,t);if(!c)return null;(this.debugRenderRaycasts||mv)&&$.DrawRay(c.origin,c.dir,255,1);const h=(o=this.world)==null?void 0:o.castRayAndGetNormal(c,r,l,s?.queryFilterFlags,s?.filterGroups,void 0,void 0,d=>{const u=d[_i];return s!=null&&s.filterPredicate?s.filterPredicate(u):s?.useIgnoreRaycastLayer!==!1?!(u!=null&&u.gameObject.layers.isEnabled(2)):!0});if(h){const d=c.pointAt(h.timeOfImpact),u=h.normal,p=this.raycastVectorsBuffer.get(),g=this.raycastVectorsBuffer.get();return p.set(d.x,d.y,d.z),g.set(u.x,u.y,u.z),{point:p,normal:g,collider:h.collider[_i]}}return null}getPhysicsRay(e,t,s){var o,r,l;const c=(o=this.context)==null?void 0:o.mainCamera;if(t===void 0){const u=(r=this.context)==null?void 0:r.input.getPointerPosition(0);if(u)t=u;else return null}if(t.z===void 0){if(!c)return console.error("Can not perform raycast from 2d point - no main camera found"),null;const u=this.raycastVectorsBuffer.get();u.x=t.x,u.y=t.y,u.z=0,(u.x>1||u.y>1||u.y<-1||u.x<-1)&&(at&&console.warn("Converting screenspace to raycast space",u),(l=this.context)==null||l.input.convertScreenspaceToRaycastSpace(u)),u.unproject(c),t=u}const h=t;e.origin.x=h.x,e.origin.y=h.y,e.origin.z=h.z;const d=this.raycastVectorsBuffer.get();if(s)d.set(s.x,s.y,s.z);else{if(!c)return console.error("Can not perform raycast - no camera found"),null;d.set(e.origin.x,e.origin.y,e.origin.z);const u=ee(c);d.sub(u)}return d.normalize(),e.dir.x=d.x,e.dir.y=d.y,e.dir.z=d.z,e}sphereOverlap(e,t){return this.rapierColliderArray.length=0,this._isInitialized?this.world?(this.rapierSphere??(this.rapierSphere=new A.RAPIER_PHYSICS.MODULE.Ball(t)),this.rapierSphere.radius=t,(this.debugRenderRaycasts||mv)&&$.DrawWireSphere(e,t,3359999,1),this.world.intersectionsWithShape(e,this.rapierIdentityRotation,this.rapierSphere,s=>{const o=s[_i],r=new Ix(o.gameObject,o);return this.rapierColliderArray.push(r),!0},void 0,void 0,void 0,void 0,s=>s.isSensor()?!1:s[_i].gameObject.layers.isEnabled(2)==!1),this.rapierColliderArray):this.rapierColliderArray:this.rapierColliderArray}get world(){return this._world}get isUpdating(){return this._isUpdatingPhysicsWorld}get gravity(){var e;return((e=this.world)==null?void 0:e.gravity)??this._gravity}set gravity(e){this.world?this.world.gravity=e:this._gravity=e}clearCaches(){var e,t,s,o;this._meshCache.clear(),(e=this.eventQueue)!=null&&e.raw&&((t=this.eventQueue)==null||t.free()),(s=this.world)!=null&&s.bodies&&((o=this.world)==null||o.free())}async addBoxCollider(e,t){if(this._isInitialized||await this.initialize(),!e.activeAndEnabled)return;if(!this.enabled){at&&console.warn("Physics are disabled");return}const s=e.gameObject,o=Ge(s,this._tempPosition).multiply(t);o.multiplyScalar(.5),o.x<0&&(o.x=Math.abs(o.x)),o.y<0&&(o.y=Math.abs(o.y)),o.z<0&&(o.z=Math.abs(o.z));const r=1e-7;o.x<r&&(o.x=r),o.y<r&&(o.y=r),o.z<r&&(o.z=r);const l=A.RAPIER_PHYSICS.MODULE.ColliderDesc.cuboid(o.x,o.y,o.z);this.createCollider(e,l)}async addSphereCollider(e){if(this._isInitialized||await this.initialize(),!e.activeAndEnabled)return;if(!this.enabled){at&&console.warn("Physics are disabled");return}const t=A.RAPIER_PHYSICS.MODULE.ColliderDesc.ball(.5);this.createCollider(e,t),this.updateProperties(e)}async addCapsuleCollider(e,t,s){if(this._isInitialized||await this.initialize(),!e.activeAndEnabled)return;if(!this.enabled){at&&console.warn("Physics are disabled");return}const o=e.gameObject,r=Ge(o,this._tempPosition);r.x=Math.abs(r.x),r.y=Math.abs(r.y);const l=s*r.x;t=Math.max(t,l*2);const c=W.clamp(t*.5*r.y-s*r.x,0,Number.MAX_SAFE_INTEGER),h=A.RAPIER_PHYSICS.MODULE.ColliderDesc.capsule(c,l);this.createCollider(e,h)}async addMeshCollider(e,t,s,o){var r,l,c;let h=t.geometry;if(!h){at&&console.warn("Missing mesh geometry",t.name);return}(l=(r=h.index)==null?void 0:r.array)!=null&&l.length||(console.warn(`Your MeshCollider is missing vertices or indices in the assined mesh "${t.name}". Consider providing an indexed geometry.`),h=gO(h));let d=null;const u=h.getAttribute("position");if(u instanceof jv){const y=u.count;d=new Float32Array(y*3);for(let v=0;v<y;v++){const b=u.getX(v),_=u.getY(v),w=u.getZ(v);d[v*3]=b,d[v*3+1]=_,d[v*3+2]=w}}else d=u.array;if(await this.initialize(),!this.enabled){at&&console.warn("Physics are disabled");return}if(!e.activeAndEnabled)return;const p=(c=h.index)==null?void 0:c.array,g=e.gameObject.worldScale.clone();if(o&&g.multiply(o),Math.abs(g.x-1)>1e-4||Math.abs(g.y-1)>1e-4||Math.abs(g.z-1)>1e-4){const y=`${h.uuid}_${g.x}_${g.y}_${g.z}_${s}`;if(this._meshCache.has(y))at&&console.warn("Use cached mesh collider"),d=this._meshCache.get(y);else{(at||F())&&console.debug(`[Performance] Your MeshCollider "${e.name}" is scaled: consider applying the scale to the collider mesh instead (${g.x}, ${g.y}, ${g.z})`);const v=new Float32Array(d.length);for(let b=0;b<d.length;b+=3)v[b]=d[b]*g.x,v[b+1]=d[b+1]*g.y,v[b+2]=d[b+2]*g.z;d=v,this._meshCache.set(y,v)}}const f=s?A.RAPIER_PHYSICS.MODULE.ColliderDesc.convexHull(d):A.RAPIER_PHYSICS.MODULE.ColliderDesc.trimesh(d,p);f&&this.createCollider(e,f)}updatePhysicsMaterial(e){if(!e)return;const t=e.sharedMaterial,s=e[ti];if(s&&t){if(t.bounciness!==void 0&&s.setRestitution(t.bounciness),t.bounceCombine!==void 0)switch(t.bounceCombine){case xt.Average:s.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case xt.Maximum:s.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case xt.Minimum:s.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case xt.Multiply:s.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}if(t.dynamicFriction!==void 0&&s.setFriction(t.dynamicFriction),t.frictionCombine!==void 0)switch(t.frictionCombine){case xt.Average:s.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case xt.Maximum:s.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case xt.Minimum:s.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case xt.Multiply:s.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}}}getBody(e){return e?e[ti]:null}getComponent(e){return e?e[_i]:null}createCollider(e,t){var s;if(!this.world)throw new Error("Physics world not initialized");const o=this._tempMatrix;let r;e.attachedRigidbody?r=this.getRigidbody(e,this._tempMatrix):(at&&console.log("Create collider without rigidbody",e.name),o.makeRotationFromQuaternion(Se(e.gameObject)),o.setPosition(ee(e.gameObject))),o.decompose(this._tempPosition,this._tempQuaternion,this._tempScale),this.tryApplyCenter(e,this._tempPosition),t.setTranslation(this._tempPosition.x,this._tempPosition.y,this._tempPosition.z),t.setRotation(this._tempQuaternion),t.setSensor(e.isTrigger);const l=e.sharedMaterial;if(l){if(l.bounciness!==void 0&&t.setRestitution(l.bounciness),l.bounceCombine!==void 0)switch(l.bounceCombine){case xt.Average:t.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case xt.Maximum:t.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case xt.Minimum:t.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case xt.Multiply:t.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}if(l.dynamicFriction!==void 0&&t.setFriction(l.dynamicFriction),l.frictionCombine!==void 0)switch(l.frictionCombine){case xt.Average:t.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case xt.Maximum:t.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case xt.Minimum:t.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case xt.Multiply:t.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}}((s=e.attachedRigidbody)==null?void 0:s.autoMass)===!1&&(t.setDensity(1e-6),t.setMass(1e-6));try{const c=this.world.createCollider(t,r);return c[_i]=e,e[ti]=c,c.setActiveEvents(A.RAPIER_PHYSICS.MODULE.ActiveEvents.COLLISION_EVENTS),c.setActiveCollisionTypes(A.RAPIER_PHYSICS.MODULE.ActiveCollisionTypes.ALL),this.objects.push(e),this.bodies.push(c),this.updateColliderCollisionGroups(e),c}catch(c){return console.error('Error creating collider "'+e.name+`"
1572
+ `,o)}}setPublicKey(){Ea&&Ea.length>0&&this.setAttribute("public-key",Ea)}setVersion(){_s.length>0&&this.setAttribute("version",_s)}getAROverlayContainer(){return this._overlay_ar.createOverlayContainer(this)}getVROverlayContainer(){for(let e=0;e<this.children.length;e++){const t=this.children[e];if(t.classList.contains("vr"))return t}return null}onEnterAR(e){var t;this.onSetupAR();const s=this.getAROverlayContainer();this._overlay_ar.onBegin(this._context,s,e),this.dispatchEvent(new CustomEvent("enter-ar",{detail:{session:e,context:this._context,htmlContainer:(t=this._overlay_ar)==null?void 0:t.ARContainer}}))}onExitAR(e){var t;this._overlay_ar.onEnd(this._context),this.onSetupDesktop(),this.dispatchEvent(new CustomEvent("exit-ar",{detail:{session:e,context:this._context,htmlContainer:(t=this._overlay_ar)==null?void 0:t.ARContainer}}))}onEnterVR(e){this.onSetupVR(),this.dispatchEvent(new CustomEvent("enter-vr",{detail:{session:e,context:this._context}}))}onExitVR(e){this.onSetupDesktop(),this.dispatchEvent(new CustomEvent("exit-vr",{detail:{session:e,context:this._context}}))}onSetupAR(){this.classList.add(ed),this.classList.remove(td);const e=this.getAROverlayContainer();Ie&&console.warn("onSetupAR:",e),e&&(e.classList.add(ed),e.classList.remove(td)),this.foreachHtmlElement(t=>this.setupElementsForMode(t,QS))}onSetupVR(){this.classList.remove(ed),this.classList.remove(td),this.foreachHtmlElement(e=>this.setupElementsForMode(e,tC))}onSetupDesktop(){this.classList.remove(ed),this.classList.add(td);const e=this.getAROverlayContainer();e&&(e.classList.remove(ed),e.classList.add(td)),this.foreachHtmlElement(t=>this.setupElementsForMode(t,iC))}setupElementsForMode(e,t,s=null){var o,r;if(!(e===((r=(o=this._context)==null?void 0:o.renderer)==null?void 0:r.domElement)||e.id==="VRButton"||e.id==="ARButton"))if(e.classList.contains(t))e.style.visibility="visible",e.style.display==="none"&&(e.style.display="block");else for(const l of LL)e.classList.contains(l)&&(e.style.visibility="hidden",e.style.display="none")}foreachHtmlElement(e){for(let t=0;t<this.children.length;t++){const s=this.children[t];s.style&&e(s)}}onBeforeBeginLoading(){const e=this.getAttribute("dracoDecoderPath");e&&(Ie&&console.log("using custom draco decoder path",e),ax(e));const t=this.getAttribute("dracoDecoderType");t&&(Ie&&console.log("using custom draco decoder type",t),lx(t));const s=this.getAttribute("ktx2DecoderPath");s&&(Ie&&console.log("using custom ktx2 decoder path",s),cx(s))}}typeof window<"u"&&!window.customElements.get(eC)&&window.customElements.define(eC,dv);function DL(n){if(n.startsWith("blob:"))return"blob";const e=n.split("/");let t=e[e.length-1];const s=t.indexOf("?");s>0&&(t=t.substring(0,s));const o=t.indexOf("=");o>0&&(t=t.substring(o));const r=t.split(".").pop(),l=r?["glb","gltf","usdz","usd","fbx","obj","mtl"].indexOf(r.toLowerCase()):-1;if(r&&l>=0&&(t=t.substring(0,t.length-r.length-1)),t=decodeURIComponent(t),t.length>3){let c="",h=!1;const d=["(",")","[","]","{","}",":",";",",",".","!","?"];for(let u=0;u<t.length;u++){let p=t[u];(p==="_"||p==="-")&&(p=" "),!(p===" "&&c.length<=0||d.includes(p)||(c.length===0&&(p=p.toUpperCase()),h&&p===" "))&&(h&&(p=p.toUpperCase()),h=!1,c+=p,p===" "&&(h=!0))}return F()&&t!==c&&console.debug('Generated display name: "'+t+'" \u2192 "'+c+'"'),c.trim()}return F()&&console.debug("Loading: use default name",t),t}function BL(n){const e=n.getAttribute("loading-blur");e!==null&&e!=="0"&&jf(t=>{var s;if(t.domElement===n){const o=(s=t.lodsManager.manager)==null?void 0:s.awaitLoading({signal:AbortSignal.timeout(1e4)}).catch(c=>{});let r="10px";e.endsWith("px")&&(r=e);const l=500;if(t.scene.background===null){const c=n,h=t.renderer.domElement,d=h.style.filter,u=h.style.overflow;h.style.filter+=`blur(${r})`,c.style.overflow="hidden",o?.then(()=>{const p=h.animate([{filter:"blur(0px)"}],{duration:l,easing:"ease-in"});p.onfinish=()=>{h.style.filter=d,c.style.overflow=u}})}else{const c=document.createElement("div");t.domElement.prepend(c),c.style.cssText="position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10;",c.style.backdropFilter=`blur(${r})`,o?.then(()=>{const h=c.animate([{backdropFilter:"blur(0px)"}],{duration:l,easing:"ease-in"});h.onfinish=()=>{c.remove()}})}}},{once:!0})}const FL=Object.freeze(Object.defineProperty({__proto__:null,NeedleEngineWebComponent:dv},Symbol.toStringTag,{value:"Module"}));function UL(){jn.registerWaitForInteraction(()=>{const n=$P.getContext();n.addEventListener("statechange",()=>{setTimeout(()=>{const e=n.state;(e==="suspended"||e==="interrupted")&&n.resume().then(()=>{console.log("AudioContext resumed successfully")}).catch(t=>{console.log("Failed to resume AudioContext: "+t)})},500)})})}setTimeout(UL,1e3);const at=C("debugphysics"),uv=C("debugcolliderplacement"),pv=C("debugcollisions"),zL=C("showcolliders"),mv=C("debugraycasts"),_i=Symbol("needle component"),ti=Symbol("physics body"),sC=Symbol("rigidbody");globalThis.NEEDLE_USE_RAPIER=globalThis.NEEDLE_USE_RAPIER!==void 0?globalThis.NEEDLE_USE_RAPIER:!0,at&&console.log("Use Rapier",!0,globalThis.NEEDLE_USE_RAPIER),pe.registerCallback(me.ContextCreationStart,n=>{at&&console.log("Register rapier physics backend"),n.context.physics.engine=new nC(n.context)});const id=class Om{constructor(e){a(this,"debugRenderColliders",!1),a(this,"debugRenderRaycasts",!1),a(this,"context"),a(this,"_initializePromise"),a(this,"_isInitialized",!1),a(this,"rapierRay"),a(this,"raycastVectorsBuffer",new Oi(()=>new S,10)),a(this,"rapierSphere",null),a(this,"rapierColliderArray",[]),a(this,"rapierIdentityRotation",{x:0,y:0,z:0,w:1}),a(this,"rapierForwardVector",{x:0,y:0,z:1}),a(this,"enabled",!1),a(this,"_tempPosition",new S),a(this,"_tempQuaternion",new V),a(this,"_tempScale",new S),a(this,"_tempMatrix",new se),a(this,"_isUpdatingPhysicsWorld",!1),a(this,"_world"),a(this,"_hasCreatedWorld",!1),a(this,"eventQueue"),a(this,"collisionHandler"),a(this,"objects",[]),a(this,"bodies",[]),a(this,"_meshCache",new Map),a(this,"_gravity",{x:0,y:-9.81,z:0}),a(this,"lines"),a(this,"_tempCenterPos",new S),a(this,"_tempCenterVec",new S),a(this,"_tempCenterQuaternion",new V),this.context=e}removeBody(e){var t,s,o;if(!e)return;this.validate();const r=e[ti];if(e[ti]=null,r&&this.world){const l=this.objects.findIndex(c=>c===e);if(l>=0){const c=this.bodies[l];if(this.bodies.splice(l,1),this.objects.splice(l,1),c instanceof A.RAPIER_PHYSICS.MODULE.Collider){const h=c;(t=this.world)==null||t.removeCollider(h,!0);const d=h.parent();d&&d.numColliders()<=0&&(d[_i]||(s=this.world)==null||s.removeRigidBody(d))}else c instanceof A.RAPIER_PHYSICS.MODULE.RigidBody&&(c.numColliders()<=0?(o=this.world)==null||o.removeRigidBody(c):F()&&(c.did_log_removing||setTimeout(()=>{c.numColliders()>0&&(c.did_log_removing=!0,console.warn("RapierPhysics: removing rigidbody with colliders from the physics world is not possible right now, please remove the colliders first"))},1)))}}}updateBody(e,t,s){if(this.validate(),!!this.enabled&&!(e.destroyed||!e.gameObject)&&!(!t&&!s))if(e.isCollider===!0)console.warn("TODO: implement updating collider position");else{const o=e,r=o[ti];r&&this.syncPhysicsBody(o.gameObject,r,t,s)}}updateProperties(e){if(this.validate(),e.isCollider){const t=e,s=t[ti];s&&(this.internalUpdateColliderProperties(t,s),t.sharedMaterial&&this.updatePhysicsMaterial(t))}else{const t=e,s=this.internal_getRigidbody(t);s&&this.internalUpdateRigidbodyProperties(t,s)}}addForce(e,t,s){this.validate();const o=this.internal_getRigidbody(e);o?o.addForce(t,s):console.warn("Rigidbody doesn't exist: can not apply force (does your object with the Rigidbody have a collider?)")}addImpulse(e,t,s){this.validate();const o=this.internal_getRigidbody(e);o?o.applyImpulse(t,s):console.warn("Rigidbody doesn't exist: can not apply impulse (does your object with the Rigidbody have a collider?)")}getLinearVelocity(e){this.validate();const t=this.internal_getRigidbody(e);return t?t.linvel():null}getAngularVelocity(e){this.validate();const t=this.internal_getRigidbody(e);return t?t.angvel():null}resetForces(e,t){this.validate();const s=this.internal_getRigidbody(e);s?.resetForces(t)}resetTorques(e,t){this.validate();const s=this.internal_getRigidbody(e);s?.resetTorques(t)}applyImpulse(e,t,s){this.validate();const o=this.internal_getRigidbody(e);o?o.applyImpulse(t,s):console.warn("Rigidbody doesn't exist: can not apply impulse (does your object with the Rigidbody have a collider?)")}wakeup(e){this.validate();const t=this.internal_getRigidbody(e);t?t.wakeUp():console.warn("Rigidbody doesn't exist: can not wake up (does your object with the Rigidbody have a collider?)")}isSleeping(e){this.validate();const t=this.internal_getRigidbody(e);return t?.isSleeping()}setAngularVelocity(e,t,s){this.validate();const o=this.internal_getRigidbody(e);o?o.setAngvel(t,s):console.warn("Rigidbody doesn't exist: can not set angular velocity (does your object with the Rigidbody have a collider?)")}setLinearVelocity(e,t,s){this.validate();const o=this.internal_getRigidbody(e);o?o.setLinvel(t,s):console.warn("Rigidbody doesn't exist: can not set linear velocity (does your object with the Rigidbody have a collider?)")}get isInitialized(){return this._isInitialized}async initialize(){return this._initializePromise||(this._initializePromise=this.internalInitialization()),this._initializePromise}async internalInitialization(){return C("__nophysics")?(console.warn("Physics are disabled"),!1):(at&&console.log("Initialize rapier physics engine"),this._hasCreatedWorld?(console.error("Invalid call to create physics world: world is already created"),!0):(this._hasCreatedWorld=!0,A.RAPIER_PHYSICS.MAYBEMODULE==null&&(at&&console.trace("Loading rapier physics engine"),await(await A.RAPIER_PHYSICS.load()).init()),at&&console.log("Physics engine initialized, creating world..."),this._world=new A.RAPIER_PHYSICS.MODULE.World(this._gravity),this.rapierRay=new A.RAPIER_PHYSICS.MODULE.Ray({x:0,y:0,z:0},{x:0,y:0,z:1}),this.enabled=!0,this._isInitialized=!0,at&&console.log("Physics world created"),!0))}validate(){this._isInitialized||at&&(this._lastWarnTime=this._lastWarnTime??0,Date.now()-this._lastWarnTime>1e3&&(this._lastWarnTime=Date.now(),console.warn("Physics engine is not initialized")))}raycast(e,t,s){var o;if(!this._isInitialized)return console.log("Physics engine is not initialized"),null;let r=s?.maxDistance,l=s?.solid;r===void 0&&(r=1/0),l===void 0&&(l=!0);const c=this.getPhysicsRay(this.rapierRay,e,t);if(!c)return null;(this.debugRenderRaycasts||mv)&&$.DrawRay(c.origin,c.dir,255,1);const h=(o=this.world)==null?void 0:o.castRay(c,r,l,s?.queryFilterFlags,s?.filterGroups,void 0,void 0,d=>{const u=d[_i];return s!=null&&s.filterPredicate?s.filterPredicate(u):s?.useIgnoreRaycastLayer!==!1?!(u!=null&&u.gameObject.layers.isEnabled(2)):!0});if(h){const d=c.pointAt(h.timeOfImpact),u=this.raycastVectorsBuffer.get();return u.set(d.x,d.y,d.z),{point:u,collider:h.collider[_i]}}return null}raycastAndGetNormal(e,t,s){var o;if(!this._isInitialized)return null;let r=s?.maxDistance,l=s?.solid;r===void 0&&(r=1/0),l===void 0&&(l=!0);const c=this.getPhysicsRay(this.rapierRay,e,t);if(!c)return null;(this.debugRenderRaycasts||mv)&&$.DrawRay(c.origin,c.dir,255,1);const h=(o=this.world)==null?void 0:o.castRayAndGetNormal(c,r,l,s?.queryFilterFlags,s?.filterGroups,void 0,void 0,d=>{const u=d[_i];return s!=null&&s.filterPredicate?s.filterPredicate(u):s?.useIgnoreRaycastLayer!==!1?!(u!=null&&u.gameObject.layers.isEnabled(2)):!0});if(h){const d=c.pointAt(h.timeOfImpact),u=h.normal,p=this.raycastVectorsBuffer.get(),g=this.raycastVectorsBuffer.get();return p.set(d.x,d.y,d.z),g.set(u.x,u.y,u.z),{point:p,normal:g,collider:h.collider[_i]}}return null}getPhysicsRay(e,t,s){var o,r,l;const c=(o=this.context)==null?void 0:o.mainCamera;if(t===void 0){const u=(r=this.context)==null?void 0:r.input.getPointerPosition(0);if(u)t=u;else return null}if(t.z===void 0){if(!c)return console.error("Can not perform raycast from 2d point - no main camera found"),null;const u=this.raycastVectorsBuffer.get();u.x=t.x,u.y=t.y,u.z=0,(u.x>1||u.y>1||u.y<-1||u.x<-1)&&(at&&console.warn("Converting screenspace to raycast space",u),(l=this.context)==null||l.input.convertScreenspaceToRaycastSpace(u)),u.unproject(c),t=u}const h=t;e.origin.x=h.x,e.origin.y=h.y,e.origin.z=h.z;const d=this.raycastVectorsBuffer.get();if(s)d.set(s.x,s.y,s.z);else{if(!c)return console.error("Can not perform raycast - no camera found"),null;d.set(e.origin.x,e.origin.y,e.origin.z);const u=ee(c);d.sub(u)}return d.normalize(),e.dir.x=d.x,e.dir.y=d.y,e.dir.z=d.z,e}sphereOverlap(e,t){return this.rapierColliderArray.length=0,this._isInitialized?this.world?(this.rapierSphere??(this.rapierSphere=new A.RAPIER_PHYSICS.MODULE.Ball(t)),this.rapierSphere.radius=t,(this.debugRenderRaycasts||mv)&&$.DrawWireSphere(e,t,3359999,1),this.world.intersectionsWithShape(e,this.rapierIdentityRotation,this.rapierSphere,s=>{const o=s[_i],r=new Ix(o.gameObject,o);return this.rapierColliderArray.push(r),!0},void 0,void 0,void 0,void 0,s=>s.isSensor()?!1:s[_i].gameObject.layers.isEnabled(2)==!1),this.rapierColliderArray):this.rapierColliderArray:this.rapierColliderArray}get world(){return this._world}get isUpdating(){return this._isUpdatingPhysicsWorld}get gravity(){var e;return((e=this.world)==null?void 0:e.gravity)??this._gravity}set gravity(e){this.world?this.world.gravity=e:this._gravity=e}clearCaches(){var e,t,s,o;this._meshCache.clear(),(e=this.eventQueue)!=null&&e.raw&&((t=this.eventQueue)==null||t.free()),(s=this.world)!=null&&s.bodies&&((o=this.world)==null||o.free())}async addBoxCollider(e,t){if(this._isInitialized||await this.initialize(),!e.activeAndEnabled)return;if(!this.enabled){at&&console.warn("Physics are disabled");return}const s=e.gameObject,o=Ge(s,this._tempPosition).multiply(t);o.multiplyScalar(.5),o.x<0&&(o.x=Math.abs(o.x)),o.y<0&&(o.y=Math.abs(o.y)),o.z<0&&(o.z=Math.abs(o.z));const r=1e-7;o.x<r&&(o.x=r),o.y<r&&(o.y=r),o.z<r&&(o.z=r);const l=A.RAPIER_PHYSICS.MODULE.ColliderDesc.cuboid(o.x,o.y,o.z);this.createCollider(e,l)}async addSphereCollider(e){if(this._isInitialized||await this.initialize(),!e.activeAndEnabled)return;if(!this.enabled){at&&console.warn("Physics are disabled");return}const t=A.RAPIER_PHYSICS.MODULE.ColliderDesc.ball(.5);this.createCollider(e,t),this.updateProperties(e)}async addCapsuleCollider(e,t,s){if(this._isInitialized||await this.initialize(),!e.activeAndEnabled)return;if(!this.enabled){at&&console.warn("Physics are disabled");return}const o=e.gameObject,r=Ge(o,this._tempPosition);r.x=Math.abs(r.x),r.y=Math.abs(r.y);const l=s*r.x;t=Math.max(t,l*2);const c=W.clamp(t*.5*r.y-s*r.x,0,Number.MAX_SAFE_INTEGER),h=A.RAPIER_PHYSICS.MODULE.ColliderDesc.capsule(c,l);this.createCollider(e,h)}async addMeshCollider(e,t,s,o){var r,l,c;let h=t.geometry;if(!h){at&&console.warn("Missing mesh geometry",t.name);return}(l=(r=h.index)==null?void 0:r.array)!=null&&l.length||(console.warn(`Your MeshCollider is missing vertices or indices in the assined mesh "${t.name}". Consider providing an indexed geometry.`),h=gO(h));let d=null;const u=h.getAttribute("position");if(u instanceof jv){const y=u.count;d=new Float32Array(y*3);for(let v=0;v<y;v++){const b=u.getX(v),_=u.getY(v),w=u.getZ(v);d[v*3]=b,d[v*3+1]=_,d[v*3+2]=w}}else d=u.array;if(await this.initialize(),!this.enabled){at&&console.warn("Physics are disabled");return}if(!e.activeAndEnabled)return;const p=(c=h.index)==null?void 0:c.array,g=e.gameObject.worldScale.clone();if(o&&g.multiply(o),Math.abs(g.x-1)>1e-4||Math.abs(g.y-1)>1e-4||Math.abs(g.z-1)>1e-4){const y=`${h.uuid}_${g.x}_${g.y}_${g.z}_${s}`;if(this._meshCache.has(y))at&&console.warn("Use cached mesh collider"),d=this._meshCache.get(y);else{(at||F())&&console.debug(`[Performance] Your MeshCollider "${e.name}" is scaled: consider applying the scale to the collider mesh instead (${g.x}, ${g.y}, ${g.z})`);const v=new Float32Array(d.length);for(let b=0;b<d.length;b+=3)v[b]=d[b]*g.x,v[b+1]=d[b+1]*g.y,v[b+2]=d[b+2]*g.z;d=v,this._meshCache.set(y,v)}}const f=s?A.RAPIER_PHYSICS.MODULE.ColliderDesc.convexHull(d):A.RAPIER_PHYSICS.MODULE.ColliderDesc.trimesh(d,p);f&&this.createCollider(e,f)}updatePhysicsMaterial(e){if(!e)return;const t=e.sharedMaterial,s=e[ti];if(s&&t){if(t.bounciness!==void 0&&s.setRestitution(t.bounciness),t.bounceCombine!==void 0)switch(t.bounceCombine){case xt.Average:s.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case xt.Maximum:s.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case xt.Minimum:s.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case xt.Multiply:s.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}if(t.dynamicFriction!==void 0&&s.setFriction(t.dynamicFriction),t.frictionCombine!==void 0)switch(t.frictionCombine){case xt.Average:s.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case xt.Maximum:s.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case xt.Minimum:s.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case xt.Multiply:s.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}}}getBody(e){return e?e[ti]:null}getComponent(e){return e?e[_i]:null}createCollider(e,t){var s;if(!this.world)throw new Error("Physics world not initialized");const o=this._tempMatrix;let r;e.attachedRigidbody?r=this.getRigidbody(e,this._tempMatrix):(at&&console.log("Create collider without rigidbody",e.name),o.makeRotationFromQuaternion(Se(e.gameObject)),o.setPosition(ee(e.gameObject))),o.decompose(this._tempPosition,this._tempQuaternion,this._tempScale),this.tryApplyCenter(e,this._tempPosition),t.setTranslation(this._tempPosition.x,this._tempPosition.y,this._tempPosition.z),t.setRotation(this._tempQuaternion),t.setSensor(e.isTrigger);const l=e.sharedMaterial;if(l){if(l.bounciness!==void 0&&t.setRestitution(l.bounciness),l.bounceCombine!==void 0)switch(l.bounceCombine){case xt.Average:t.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case xt.Maximum:t.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case xt.Minimum:t.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case xt.Multiply:t.setRestitutionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}if(l.dynamicFriction!==void 0&&t.setFriction(l.dynamicFriction),l.frictionCombine!==void 0)switch(l.frictionCombine){case xt.Average:t.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case xt.Maximum:t.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case xt.Minimum:t.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case xt.Multiply:t.setFrictionCombineRule(A.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}}((s=e.attachedRigidbody)==null?void 0:s.autoMass)===!1&&(t.setDensity(1e-6),t.setMass(1e-6));try{const c=this.world.createCollider(t,r);return c[_i]=e,e[ti]=c,c.setActiveEvents(A.RAPIER_PHYSICS.MODULE.ActiveEvents.COLLISION_EVENTS),c.setActiveCollisionTypes(A.RAPIER_PHYSICS.MODULE.ActiveCollisionTypes.ALL),this.objects.push(e),this.bodies.push(c),this.updateColliderCollisionGroups(e),c}catch(c){return console.error('Error creating collider "'+e.name+`"
1573
1573
  Error:`,c),null}}updateColliderCollisionGroups(e){const t=e[ti],s=e.membership;let o=0;if(s==null)o=65535;else for(let c=0;c<s.length;c++){const h=s[c];h>31?console.error(`Rapier only supports 32 layers, layer ${h} is not supported`):o|=1<<Math.floor(h)}const r=e.filter;let l=0;if(r==null)l=65535;else for(let c=0;c<r.length;c++){const h=r[c];h>31?console.error(`Rapier only supports 32 layers, layer ${h} is not supported`):l|=1<<Math.floor(h)}t.setCollisionGroups(o<<16|l)}getRigidbody(e,t){if(!this.world)throw new Error("Physics world not initialized");let s=null;if(e.attachedRigidbody){const o=e.attachedRigidbody;if(s=o[ti],!s){const r=o.isKinematic&&!uv;at&&console.log("Create rigidbody",r);const l=r?A.RAPIER_PHYSICS.MODULE.RigidBodyDesc.kinematicPositionBased():A.RAPIER_PHYSICS.MODULE.RigidBodyDesc.dynamic(),c=ee(e.attachedRigidbody.gameObject);l.setTranslation(c.x,c.y,c.z),l.setRotation(Se(e.attachedRigidbody.gameObject)),l.centerOfMass=new A.RAPIER_PHYSICS.MODULE.Vector3(o.centerOfMass.x,o.centerOfMass.y,o.centerOfMass.z),s=this.world.createRigidBody(l),this.bodies.push(s),this.objects.push(o)}s[_i]=o,o[ti]=s,this.internalUpdateRigidbodyProperties(o,s),this.getRigidbodyRelativeMatrix(e.gameObject,o.gameObject,t),e[sC]=s}else{const o=A.RAPIER_PHYSICS.MODULE.RigidBodyDesc.kinematicPositionBased(),r=ee(e.gameObject);o.setTranslation(r.x,r.y,r.z),o.setRotation(Se(e.gameObject)),s=this.world.createRigidBody(o),t.identity(),s[_i]=null}return s}internal_getRigidbody(e){return e.isCollider===!0?e[sC]:e[ti]}internalUpdateColliderProperties(e,t){const s=t.shape;let o=!1;switch(s.type){case A.RAPIER_PHYSICS.MODULE.ShapeType.Ball:{const g=s,f=e,y=e.gameObject,v=Ge(y,this._tempPosition),b=Math.abs(f.radius*v.x);o=g.radius!==b,g.radius=b,o&&t.setShape(g);break}case A.RAPIER_PHYSICS.MODULE.ShapeType.Cuboid:const r=s,l=e,c=e.gameObject,h=Ge(c,this._tempPosition),d=Math.abs(l.size.x*.5*h.x),u=Math.abs(l.size.y*.5*h.y),p=Math.abs(l.size.z*.5*h.z);o=r.halfExtents.x!==d||r.halfExtents.y!==u||r.halfExtents.z!==p,r.halfExtents.x=d,r.halfExtents.y=u,r.halfExtents.z=p,o&&t.setShape(r);break}if(o){const r=e.attachedRigidbody;if(r!=null&&r.autoMass){const l=this.getBody(r);l?.recomputeMassPropertiesFromColliders()}}this.updateColliderCollisionGroups(e),e.isTrigger!==t.isSensor()&&t.setSensor(e.isTrigger)}internalUpdateRigidbodyProperties(e,t){if(t.enableCcd(e.collisionDetectionMode!==Mu.Discrete),t.setLinearDamping(e.drag),t.setAngularDamping(e.angularDrag),t.setGravityScale(e.useGravity?e.gravityScale:0,!0),e.dominanceGroup<=127&&e.dominanceGroup>=-127?t.setDominanceGroup(Math.floor(e.dominanceGroup)):t.setDominanceGroup(0),e.autoMass){t.setAdditionalMass(0,!1);for(let s=0;s<t.numColliders();s++)t.collider(s).setDensity(1);t.recomputeMassPropertiesFromColliders()}else{t.setAdditionalMass(e.mass,!1);for(let s=0;s<t.numColliders();s++)t.collider(s).setDensity(1e-7);t.recomputeMassPropertiesFromColliders()}t.setEnabledRotations(!e.lockRotationX,!e.lockRotationY,!e.lockRotationZ,!1),t.setEnabledTranslations(!e.lockPositionX,!e.lockPositionY,!e.lockPositionZ,!1),e.isKinematic?t.setBodyType(A.RAPIER_PHYSICS.MODULE.RigidBodyType.KinematicPositionBased,!1):t.setBodyType(A.RAPIER_PHYSICS.MODULE.RigidBodyType.Dynamic,!1)}step(e){if(this.world&&this.enabled){if(this._isUpdatingPhysicsWorld=!0,this.eventQueue||(this.eventQueue=new A.RAPIER_PHYSICS.MODULE.EventQueue(!1)),e===void 0||e<=0){this._isUpdatingPhysicsWorld=!1;return}else e!==void 0&&(this.world.timestep=W.lerp(this.world.timestep,e,.8));try{this.world.step(this.eventQueue)}catch(t){console.warn("Error running physics step",t)}this._isUpdatingPhysicsWorld=!1}}postStep(){this.world&&this.enabled&&(this._isUpdatingPhysicsWorld=!0,this.syncObjects(),this._isUpdatingPhysicsWorld=!1,this.eventQueue&&!this.collisionHandler&&(this.collisionHandler=new NL(this.world,this.eventQueue)),this.collisionHandler&&(this.collisionHandler.handleCollisionEvents(),this.collisionHandler.update()),this.updateDebugRendering(this.world))}updateDebugRendering(e){var t,s,o,r;if(at||uv||zL||this.debugRenderColliders===!0){if(!this.lines){const c=new Lv({color:7855479,fog:!1}),h=new Ws;this.lines=new Iv(h,c),this.lines.layers.disableAll(),this.lines.layers.enable(2)}this.lines.parent!==((t=this.context)==null?void 0:t.scene)&&((s=this.context)==null||s.scene.add(this.lines));const l=e.debugRender();this.lines.geometry.setAttribute("position",new _t(l.vertices,3)),this.lines.geometry.setAttribute("color",new _t(l.colors,4)),(this.context.time.frame%30===0||((o=this.lines.geometry.boundingSphere)==null?void 0:o.radius)===0)&&this.lines.geometry.computeBoundingSphere()}else this.lines&&((r=this.context)==null||r.scene.remove(this.lines))}syncObjects(){if(!uv)for(let e=0;e<this.bodies.length;e++){const t=this.objects[e],s=this.bodies[e],o=t;if(o?.isCollider===!0&&!o.attachedRigidbody){const h=s.parent();h?this.syncPhysicsBody(t.gameObject,h,!0,!0):this.syncPhysicsBody(t.gameObject,s,!0,!0);continue}const r=s.translation(),l=s.rotation();if(Number.isNaN(r.x)||Number.isNaN(l.x)){!o.__COLLIDER_NAN&&F()&&(console.warn("Collider has NaN values",o.name,o.gameObject,s),o.__COLLIDER_NAN=!0);continue}const c=t.center;if(c&&c.isVector3){this._tempQuaternion.set(l.x,l.y,l.z,l.w);const h=this._tempPosition.copy(c).applyQuaternion(this._tempQuaternion),d=Ge(t.gameObject);h.multiply(d),r.x-=h.x,r.y-=h.y,r.z-=h.z}vr(t.gameObject,r.x,r.y,r.z),ug(t.gameObject,l.x,l.y,l.z,l.w)}}syncPhysicsBody(e,t,s,o){if(t instanceof A.RAPIER_PHYSICS.MODULE.RigidBody){const r=ee(e,this._tempPosition),l=Se(e,this._tempQuaternion);switch(t.bodyType()){case A.RAPIER_PHYSICS.MODULE.RigidBodyType.Fixed:case A.RAPIER_PHYSICS.MODULE.RigidBodyType.KinematicPositionBased:case A.RAPIER_PHYSICS.MODULE.RigidBodyType.KinematicVelocityBased:s&&t.setNextKinematicTranslation(r),o&&t.setNextKinematicRotation(l);break;default:s&&t.setTranslation(r,!1),o&&t.setRotation(l,!1);break}}else if(t instanceof A.RAPIER_PHYSICS.MODULE.Collider){e.matrixWorldNeedsUpdate&&e.updateWorldMatrix(!0,!1),e.matrixWorld.decompose(this._tempPosition,this._tempQuaternion,this._tempScale);const r=this._tempPosition,l=this._tempQuaternion,c=t[_i];if(this.tryApplyCenter(c,r),s){const h=t.translation();(h.x!==r.x||h.y!==r.y||h.z!==r.z)&&t.setTranslation(r)}if(o){const h=t.rotation();(h.x!==l.x||h.y!==l.y||h.z!==l.z||h.w!==l.w)&&t.setRotation(l)}}}tryApplyCenter(e,t){const s=e.center;s&&e.gameObject&&(s.x!==0||s.y!==0||s.z!==0)&&(this._tempCenterPos.x=s.x,this._tempCenterPos.y=s.y,this._tempCenterPos.z=s.z,Ge(e.gameObject,this._tempCenterVec),this._tempCenterPos.multiply(this._tempCenterVec),e.attachedRigidbody?this._tempCenterPos.applyQuaternion(e.gameObject.quaternion):(Se(e.gameObject,this._tempCenterQuaternion),this._tempCenterPos.applyQuaternion(this._tempCenterQuaternion)),t.x+=this._tempCenterPos.x,t.y+=this._tempCenterPos.y,t.z+=this._tempCenterPos.z)}getRigidbodyRelativeMatrix(e,t,s,o){if(o===void 0&&(o=Om._matricesBuffer,o.length=0),e===t){const r=Ge(e,this._tempPosition);s.makeScale(r.x,r.y,r.z);for(let l=o.length-1;l>=0;l--)s.multiply(o[l]);return s}return o.push(e.matrix),e.parent&&this.getRigidbodyRelativeMatrix(e.parent,t,s,o),s}addFixedJoint(e,t){if(!this.world){console.error("Physics world not initialized");return}const s=e[ti],o=t[ti];this.calculateJointRelativeMatrices(e.gameObject,t.gameObject,this._tempMatrix),this._tempMatrix.decompose(this._tempPosition,this._tempQuaternion,this._tempScale);const r=A.RAPIER_PHYSICS.MODULE.JointData.fixed(Om.centerConnectionPos,Om.centerConnectionRot,this._tempPosition,this._tempQuaternion),l=this.world.createImpulseJoint(r,s,o,!0);at&&console.log("ADD FIXED JOINT",l)}addHingeJoint(e,t,s,o){if(!this.world){console.error("Physics world not initialized");return}const r=e[ti],l=t[ti];this.calculateJointRelativeMatrices(e.gameObject,t.gameObject,this._tempMatrix),this._tempMatrix.decompose(this._tempPosition,this._tempQuaternion,this._tempScale);const c=A.RAPIER_PHYSICS.MODULE.JointData.revolute(s,this._tempPosition,o),h=this.world.createImpulseJoint(c,r,l,!0);at&&console.log("ADD HINGE JOINT",h)}calculateJointRelativeMatrices(e,t,s){e.updateWorldMatrix(!0,!1),t.updateWorldMatrix(!0,!1);const o=e.matrixWorld,r=t.matrixWorld;o.elements[0]=1,o.elements[5]=1,o.elements[10]=1,r.elements[0]=1,r.elements[5]=1,r.elements[10]=1,s.copy(r).premultiply(o.invert()).invert()}};a(id,"_didLoadPhysicsEngine",!1),a(id,"_matricesBuffer",[]),a(id,"centerConnectionPos",{x:0,y:0,z:0}),a(id,"centerConnectionRot",{x:0,y:0,z:0,w:1});let nC=id;class NL{constructor(e,t){a(this,"world"),a(this,"eventQueue"),a(this,"activeCollisions",[]),a(this,"activeCollisionsStay",[]),a(this,"activeTriggers",[]),this.world=e,this.eventQueue=t}handleCollisionEvents(){this.eventQueue&&this.world&&this.eventQueue.drainCollisionEvents((e,t,s)=>{const o=this.world.getCollider(e),r=this.world.getCollider(t);if(!o||!r)return;const l=o[_i],c=r[_i];pv&&console.log("EVT",l.name,c.name,s,o,r),l&&c&&(s?(this.onCollisionStarted(l,o,c,r),this.onCollisionStarted(c,r,l,o)):(this.onCollisionEnded(l,c),this.onCollisionEnded(c,l)))})}update(){this.onHandleCollisionStay()}onCollisionStarted(e,t,s,o){let r=null;if(e.isTrigger||s.isTrigger)Er(e.gameObject,l=>{l.onTriggerEnter&&!l.destroyed&&l.onTriggerEnter(s),this.activeTriggers.push({collider:e,component:l,otherCollider:s})});else{const l=e.gameObject;this.world.contactPair(t,o,(c,h)=>{Er(l,d=>{var u;if(d.destroyed)return;const p=d.onCollisionEnter||d.onCollisionStay||d.onCollisionExit;if(p||pv){if(!r){const g=[],f=c.normal();s instanceof Bo&&s.convex&&(f.x=-f.x,f.y=-f.y,f.z=-f.z);for(let y=0;y<c.numSolverContacts();y++){const v=c.solverContactPoint(y),b=c.contactImpulse(y);if(v){const _=c.contactDist(y),w=c.solverContactFriction(y),x=c.solverContactTangentVelocity(y),k=new Ex(v,_,f,b,w,x);g.push(k),pv&&$.DrawDirection(v,f,16711680,3,!0)}}r=new Ax(l,s,g)}if(p){const g={collider:e,component:d,collision:r};this.activeCollisions.push(g),d.onCollisionStay&&this.activeCollisionsStay.push(g),(u=d.onCollisionEnter)==null||u.call(d,r)}}})})}}onHandleCollisionStay(){for(const e of this.activeCollisionsStay){const t=e.component;if(!t.destroyed&&t.activeAndEnabled&&t.onCollisionStay){if(e.collision.collider.destroyed)continue;const s=e.collision;t.onCollisionStay(s)}}for(const e of this.activeTriggers){const t=e.component;if(!t.destroyed&&t.activeAndEnabled&&t.onTriggerStay){const s=e.otherCollider;if(s.destroyed)continue;t.onTriggerStay(s)}}}onCollisionEnded(e,t){if(!(e.destroyed||t.destroyed)){for(let s=0;s<this.activeCollisions.length;s++){const o=this.activeCollisions[s],r=o.collider;if(r.destroyed||o.collision.collider.destroyed){this.activeCollisions.splice(s,1),s--;continue}if(r===e&&o.collision.collider===t){const l=o.component;if(this.activeCollisions.splice(s,1),s--,l.activeAndEnabled&&l.onCollisionExit){const c=o.collision;l.onCollisionExit(c)}}}for(let s=0;s<this.activeCollisionsStay.length;s++){const o=this.activeCollisionsStay[s],r=o.collider;if(r.destroyed||o.collision.collider.destroyed){this.activeCollisionsStay.splice(s,1),s--;continue}if(r===e&&o.collision.collider===t){const l=o.component;if(this.activeCollisionsStay.splice(s,1),s--,l.activeAndEnabled&&l.onCollisionExit){const c=o.collision;l.onCollisionExit(c)}}}for(let s=0;s<this.activeTriggers.length;s++){const o=this.activeTriggers[s],r=o.collider;if(r.destroyed||o.otherCollider.destroyed){this.activeTriggers.splice(s,1),s--;continue}if(r===e&&o.otherCollider===t){const l=o.component;if(this.activeTriggers.splice(s,1),s--,l.activeAndEnabled&&l.onTriggerExit){const c=o.otherCollider;l.onTriggerExit(c)}}}}}}class WL{static async createComparisonScene(e){const{files:t}=e,s=await Promise.all(t.map(y=>new ce(y).loadAssetAsync())),o=new xi;let r=0;for(const y of s)if(y instanceof E){y.position.y=r,o.add(y);const v=si([y]);r+=v.getSize(new S).y,r+=.1}const l=new we(20);o.add(l);const c=e.environment||"https://dl.polyhaven.org/file/ph-assets/HDRIs/exr/1k/studio_small_09_1k.exr";{let y=null;if(c.endsWith(".hdr")){const v=(await import("./three-examples-DaDLBuy6.min.js").then(b=>b.RGBELoader$1)).RGBELoader;y=new v}else if(c.endsWith(".exr")){const v=(await import("./three-examples-DaDLBuy6.min.js").then(b=>b.EXRLoader$1)).EXRLoader;y=new v}if(y){const v=await y.loadAsync(c).catch(b=>(console.error(b),null));v&&(v.mapping=Mn,v.needsUpdate=!0,o.background=v,o.environment=v,o.backgroundBlurriness=.75)}else console.warn("Unsupported environment map format",c)}const h=si(o.children),d=h.getCenter(new S),u=h.getSize(new S),p=Math.max(u.x,u.y,u.z)/(2*Math.tan(Math.PI*l.fov/360));l.position.set(d.x,d.y,p),l.lookAt(d);const g=new Gv(l,e.domElement||document.body);g.target=d,g.update();const f=(e.domElement||document.body).getBoundingClientRect();return l.aspect=f.width/f.height,l.updateProjectionMatrix(),{scene:o,camera:l}}}let gv=0;function oC(n){n?gv++:gv--}function VL(){return gv>0}const $L={binary:!0,animations:!0};async function HL(n){if(!n.context)throw new Error("No context provided to exportAsGLTF");n.scene||(n.scene=n.context.scene);const e={...$L,...n},{context:t}=e,s=new qv;s.register(c=>new l1(c)),s.register(c=>new fE(c)),s.register(c=>new Kx(c)),_0(s,e.context);const o={binary:e.binary,animations:qL(t,e.scene,[])},r=new GL;console.debug("Exporting GLTF",o),r.onBeforeExport(e),oC(!0);const l=await s.parseAsync(e.scene,o).catch(c=>(console.error(c),null));if(oC(!1),r.onAfterExport(e),!l)throw new Error("Failed to export GLTF");if(e.downloadAs!=null){let c=null;if(l instanceof ArrayBuffer?c=new Blob([l],{type:"application/octet-stream"}):console.error("Can not download GLTF as a blob",l),c){const h=URL.createObjectURL(c),d=document.createElement("a");d.href=h;let u=e.downloadAs;!u.endsWith(".glb")&&!u.endsWith(".gltf")&&(u+=e.binary?".glb":".gltf"),d.download=u,d.click()}}return l}const rC=Symbol("needle:weight");class GL{constructor(){a(this,"_undo",[])}onBeforeExport(e){e.context.animations.mixers.forEach(t=>{const s=Ga.tryGetActionsFromMixer(t);if(s)for(let o=0;o<s.length;o++){const r=s[o];r[rC]=r.weight,r.weight=0,this._undo.push(()=>{r.weight=r[rC]})}t.update(0)}),e.context.scene.traverse(t=>{if(!g0(t)){const s=t.parent;s&&(t.removeFromParent(),this._undo.push(()=>s.add(t)))}})}onAfterExport(e){this._undo.forEach(t=>t()),this._undo.length=0}}function qL(n,e,t){n.animations.mixers.forEach(o=>{const r=Ga.tryGetActionsFromMixer(o);if(r)for(let l=0;l<r.length;l++){const c=r[l].getClip();t.push(c)}}),Array.isArray(e)||(e=[e]);for(const o of e)Ga.tryGetAnimationClipsFromObjectHierarchy(o,t);const s=new Set(t);return Array.from(s)}const aC="needle-button",fv=F();var fa,ya,va,wi,js,Bl,mm,lC,cC,gm;class yv extends HTMLElement{constructor(){super(),Fs(this,mm),Fs(this,fa),Fs(this,ya),Fs(this,va),Fs(this,wi),Fs(this,js),Fs(this,Bl),Fs(this,gm,e=>{fv&&console.log("Needle Button clicked"),!e.defaultPrevented&&ge(this,wi)&&ge(this,wi).click()}),this.removeEventListener("click",ge(this,gm)),this.addEventListener("click",ge(this,gm))}attributeChangedCallback(e,t,s){ud(this,mm,lC).call(this)}}fa=new WeakMap,ya=new WeakMap,va=new WeakMap,wi=new WeakMap,js=new WeakMap,Bl=new WeakMap,mm=new WeakSet,lC=function(){var n,e;if((n=ge(this,wi))==null||n.remove(),this.getAttribute("ar")!=null)ge(this,js)??Us(this,js,new gl),Us(this,wi,ge(this,js).createARButton());else if(this.getAttribute("vr")!=null)ge(this,js)??Us(this,js,new gl),Us(this,wi,ge(this,js).createVRButton());else if(this.getAttribute("quicklook")!=null)ge(this,js)??Us(this,js,new gl),Us(this,wi,ge(this,js).createQuicklookButton());else{fv?console.warn("No button type specified for <needle-button>. Use either ar, vr or quicklook attribute."):console.debug("No button type specified for <needle-button>. Use either ar, vr or quicklook attribute.");return}ge(this,fa)??Us(this,fa,this.attachShadow({mode:"open"})),ge(this,ya)??Us(this,ya,document.createElement("slot")),ge(this,va)??Us(this,va,document.createElement("style")),ge(this,va).innerHTML=`
1574
1574
  button {
1575
1575
  all: initial;