shop-components 0.4.23 → 0.4.25

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
- "use strict";var Jr=Object.create;var vi=Object.defineProperty;var $r=Object.getOwnPropertyDescriptor;var en=Object.getOwnPropertyNames;var tn=Object.getPrototypeOf,sn=Object.prototype.hasOwnProperty;var rn=(o,e,t)=>e in o?vi(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var nn=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of en(e))!sn.call(o,s)&&s!==t&&vi(o,s,{get:()=>e[s],enumerable:!(i=$r(e,s))||i.enumerable});return o};var on=(o,e,t)=>(t=o!=null?Jr(tn(o)):{},nn(e||!o||!o.__esModule?vi(t,"default",{value:o,enumerable:!0}):t,o));var F=(o,e,t)=>(rn(o,typeof e!="symbol"?e+"":e,t),t),xs=(o,e,t)=>{if(!e.has(o))throw TypeError("Cannot "+t)};var W=(o,e,t)=>(xs(o,e,"read from private field"),t?t.call(o):e.get(o)),Se=(o,e,t)=>{if(e.has(o))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(o):e.set(o,t)},de=(o,e,t,i)=>(xs(o,e,"write to private field"),i?i.call(o,t):e.set(o,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("three"),ws=require("three/examples/jsm/loaders/HDRLoader.js"),an=require("three/examples/jsm/controls/OrbitControls"),ge=require("three/examples/jsm/renderers/CSS2DRenderer"),ln=require("three/examples/jsm/loaders/FontLoader"),os=require("three/examples/jsm/loaders/GLTFLoader.js");require("three/examples/jsm/libs/meshopt_decoder.module.js");require("three/examples/jsm/loaders/DRACOLoader.js");const cn=require("three/examples/jsm/loaders/GLTFLoader"),hn=require("three/examples/jsm/loaders/DRACOLoader"),un=require("three/examples/jsm/exporters/DRACOExporter"),fn=require("three/examples/jsm/exporters/GLTFExporter"),dn=require("three/examples/jsm/utils/SkeletonUtils.js"),pn=require("three/examples/jsm/lines/Line2.js"),mn=require("three/examples/jsm/lines/LineMaterial.js"),bs=require("three/examples/jsm/lines/LineGeometry.js"),gn=require("three/examples/jsm/renderers/CSS3DRenderer");require("three/examples/jsm/utils/BufferGeometryUtils");const Ot=require("three/examples/jsm/postprocessing/Pass"),Ie=require("three-mesh-bvh"),ut=require("three/examples/jsm/postprocessing/Pass.js");var ft=typeof document<"u"?document.currentScript:null;function mr(o){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>o[t]})}}return e.default=o,Object.freeze(e)}const k=mr(d),_i=mr(dn);function gr(o,e,t=0){if(o.isInterleavedBufferAttribute){const i=o.itemSize;for(let s=0,a=o.count;s<a;s++){const n=s+t;e.setX(n,o.getX(s)),i>=2&&e.setY(n,o.getY(s)),i>=3&&e.setZ(n,o.getZ(s)),i>=4&&e.setW(n,o.getW(s))}}else{const i=e.array,s=i.constructor,a=i.BYTES_PER_ELEMENT*o.itemSize*t;new s(i.buffer,a,o.array.length).set(o.array)}}function Rt(o,e=null){const t=o.array.constructor,i=o.normalized,s=o.itemSize,a=e===null?o.count:e;return new d.BufferAttribute(new t(s*a),s,i)}function rt(o,e){if(!o&&!e)return!0;if(!!o!=!!e)return!1;const t=o.count===e.count,i=o.normalized===e.normalized,s=o.array.constructor===e.array.constructor,a=o.itemSize===e.itemSize;return!(!t||!i||!s||!a)}function vn(o){const e=o[0].index!==null,t=new Set(Object.keys(o[0].attributes));if(!o[0].getAttribute("position"))throw new Error("StaticGeometryGenerator: position attribute is required.");for(let i=0;i<o.length;++i){const s=o[i];let a=0;if(e!==(s.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const n in s.attributes){if(!t.has(n))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+n+'" attribute exists among all geometries, or in none of them.');a++}if(a!==t.size)throw new Error("StaticGeometryGenerator: All geometries must have the same number of attributes.")}}function _n(o){let e=0;for(let t=0,i=o.length;t<i;t++)e+=o[t].getIndex().count;return e}function yn(o){let e=0;for(let t=0,i=o.length;t<i;t++)e+=o[t].getAttribute("position").count;return e}function xn(o,e,t){o.index&&o.index.count!==e&&o.setIndex(null);const i=o.attributes;for(const s in i)i[s].count!==t&&o.deleteAttribute(s)}function wn(o,e={},t=new d.BufferGeometry){const{useGroups:i=!1,forceUpdate:s=!1,skipAssigningAttributes:a=[],overwriteIndex:n=!0}=e;vn(o);const c=o[0].index!==null,h=c?_n(o):-1,f=yn(o);if(xn(t,h,f),i){let r=0;for(let l=0,u=o.length;l<u;l++){const g=o[l];let y;c?y=g.getIndex().count:y=g.getAttribute("position").count,t.addGroup(r,y,l),r+=y}}if(c){let r=!1;if(t.index||(t.setIndex(new d.BufferAttribute(new Uint32Array(h),1,!1)),r=!0),r||n){let l=0,u=0;const g=t.getIndex();for(let y=0,m=o.length;y<m;y++){const v=o[y],_=v.getIndex();if(!(!s&&!r&&a[y]))for(let w=0;w<_.count;++w)g.setX(l+w,_.getX(w)+u);l+=_.count,u+=v.getAttribute("position").count}}}const p=Object.keys(o[0].attributes);for(let r=0,l=p.length;r<l;r++){let u=!1;const g=p[r];if(!t.getAttribute(g)){const v=o[0].getAttribute(g);t.setAttribute(g,Rt(v,f)),u=!0}let y=0;const m=t.getAttribute(g);for(let v=0,_=o.length;v<_;v++){const x=o[v],w=!s&&!u&&a[v],b=x.getAttribute(g);w||gr(b,m,y),y+=b.count}}}function bn(o,e,t){const i=o.index,a=o.attributes.position.count,n=i?i.count:a;let c=o.groups;c.length===0&&(c=[{count:n,start:0,materialIndex:0}]);let h=o.getAttribute("materialIndex");if(!h||h.count!==a){let p;t.length<=255?p=new Uint8Array(a):p=new Uint16Array(a),h=new d.BufferAttribute(p,1,!1),o.deleteAttribute("materialIndex"),o.setAttribute("materialIndex",h)}const f=h.array;for(let p=0;p<c.length;p++){const r=c[p],l=r.start,u=r.count,g=Math.min(u,n-l),y=Array.isArray(e)?e[r.materialIndex]:e,m=t.indexOf(y);for(let v=0;v<g;v++){let _=l+v;i&&(_=i.getX(_)),f[_]=m}}}function An(o,e){if(!o.index){const t=o.attributes.position.count,i=new Array(t);for(let s=0;s<t;s++)i[s]=s;o.setIndex(i)}if(!o.attributes.normal&&e&&e.includes("normal")&&o.computeVertexNormals(),!o.attributes.uv&&e&&e.includes("uv")){const t=o.attributes.position.count;o.setAttribute("uv",new d.BufferAttribute(new Float32Array(t*2),2,!1))}if(!o.attributes.uv2&&e&&e.includes("uv2")){const t=o.attributes.position.count;o.setAttribute("uv2",new d.BufferAttribute(new Float32Array(t*2),2,!1))}if(!o.attributes.tangent&&e&&e.includes("tangent"))if(o.attributes.uv&&o.attributes.normal)o.computeTangents();else{const t=o.attributes.position.count;o.setAttribute("tangent",new d.BufferAttribute(new Float32Array(t*4),4,!1))}if(!o.attributes.color&&e&&e.includes("color")){const t=o.attributes.position.count,i=new Float32Array(t*4);i.fill(1),o.setAttribute("color",new d.BufferAttribute(i,4))}}function as(o){let e=0;if(o.byteLength!==0){const t=new Uint8Array(o);for(let i=0;i<o.byteLength;i++){const s=t[i];e=(e<<5)-e+s,e|=0}}return e}function As(o){let e=o.uuid;const t=Object.values(o.attributes);o.index&&(t.push(o.index),e+=`index|${o.index.version}`);const i=Object.keys(t).sort();for(const s of i){const a=t[s];e+=`${s}_${a.version}|`}return e}function Ts(o){const e=o.skeleton;return e?(e.boneTexture||e.computeBoneTexture(),`${as(e.boneTexture.image.data.buffer)}_${e.boneTexture.uuid}`):null}class Tn{constructor(e=null){this.matrixWorld=new d.Matrix4,this.geometryHash=null,this.skeletonHash=null,this.primitiveCount=-1,e!==null&&this.updateFrom(e)}updateFrom(e){const t=e.geometry,i=(t.index?t.index.count:t.attributes.position.count)/3;this.matrixWorld.copy(e.matrixWorld),this.geometryHash=As(t),this.primitiveCount=i,this.skeletonHash=Ts(e)}didChange(e){const t=e.geometry,i=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===As(t)&&this.skeletonHash===Ts(e)&&this.primitiveCount===i)}}const Be=new d.Vector3,ke=new d.Vector3,Oe=new d.Vector3,Ss=new d.Vector4,zt=new d.Vector3,yi=new d.Vector3,Ms=new d.Vector4,Cs=new d.Vector4,Vt=new d.Matrix4,Rs=new d.Matrix4;function Ls(o,e,t){const i=o.skeleton,s=o.geometry,a=i.bones,n=i.boneInverses;Ms.fromBufferAttribute(s.attributes.skinIndex,e),Cs.fromBufferAttribute(s.attributes.skinWeight,e),Vt.elements.fill(0);for(let c=0;c<4;c++){const h=Cs.getComponent(c);if(h!==0){const f=Ms.getComponent(c);Rs.multiplyMatrices(a[f].matrixWorld,n[f]),Sn(Vt,Rs,h)}}return Vt.multiply(o.bindMatrix).premultiply(o.bindMatrixInverse),t.transformDirection(Vt),t}function xi(o,e,t,i,s){zt.set(0,0,0);for(let a=0,n=o.length;a<n;a++){const c=e[a],h=o[a];c!==0&&(yi.fromBufferAttribute(h,i),t?zt.addScaledVector(yi,c):zt.addScaledVector(yi.sub(s),c))}s.add(zt)}function Sn(o,e,t){const i=o.elements,s=e.elements;for(let a=0,n=s.length;a<n;a++)i[a]+=s[a]*t}function Mn(o){const{index:e,attributes:t}=o;if(e)for(let i=0,s=e.count;i<s;i+=3){const a=e.getX(i),n=e.getX(i+2);e.setX(i,n),e.setX(i+2,a)}else for(const i in t){const s=t[i],a=s.itemSize;for(let n=0,c=s.count;n<c;n+=3)for(let h=0;h<a;h++){const f=s.getComponent(n,h),p=s.getComponent(n+2,h);s.setComponent(n,h,p),s.setComponent(n+2,h,f)}}return o}function Cn(o,e={},t=new d.BufferGeometry){e={applyWorldTransforms:!0,attributes:[],...e};const i=o.geometry,s=e.applyWorldTransforms,a=e.attributes.includes("normal"),n=e.attributes.includes("tangent"),c=i.attributes,h=t.attributes;for(const _ in t.attributes)(!e.attributes.includes(_)||!(_ in i.attributes))&&t.deleteAttribute(_);!t.index&&i.index&&(t.index=i.index.clone()),h.position||t.setAttribute("position",Rt(c.position)),a&&!h.normal&&c.normal&&t.setAttribute("normal",Rt(c.normal)),n&&!h.tangent&&c.tangent&&t.setAttribute("tangent",Rt(c.tangent)),rt(i.index,t.index),rt(c.position,h.position),a&&rt(c.normal,h.normal),n&&rt(c.tangent,h.tangent);const f=c.position,p=a?c.normal:null,r=n?c.tangent:null,l=i.morphAttributes.position,u=i.morphAttributes.normal,g=i.morphAttributes.tangent,y=i.morphTargetsRelative,m=o.morphTargetInfluences,v=new d.Matrix3;v.getNormalMatrix(o.matrixWorld),i.index&&t.index.array.set(i.index.array);for(let _=0,x=c.position.count;_<x;_++)Be.fromBufferAttribute(f,_),p&&ke.fromBufferAttribute(p,_),r&&(Ss.fromBufferAttribute(r,_),Oe.fromBufferAttribute(r,_)),m&&(l&&xi(l,m,y,_,Be),u&&xi(u,m,y,_,ke),g&&xi(g,m,y,_,Oe)),o.isSkinnedMesh&&(o.applyBoneTransform(_,Be),p&&Ls(o,_,ke),r&&Ls(o,_,Oe)),s&&Be.applyMatrix4(o.matrixWorld),h.position.setXYZ(_,Be.x,Be.y,Be.z),p&&(s&&ke.applyNormalMatrix(v),h.normal.setXYZ(_,ke.x,ke.y,ke.z)),r&&(s&&Oe.transformDirection(o.matrixWorld),h.tangent.setXYZW(_,Oe.x,Oe.y,Oe.z,Ss.w));for(const _ in e.attributes){const x=e.attributes[_];x==="position"||x==="tangent"||x==="normal"||!(x in c)||(h[x]||t.setAttribute(x,Rt(c[x])),rt(c[x],h[x]),gr(c[x],h[x]))}return o.matrixWorld.determinant()<0&&Mn(t),t}class Rn extends d.BufferGeometry{constructor(){super(),this.version=0,this.hash=null,this._diff=new Tn}isCompatible(e,t){const i=e.geometry;for(let s=0;s<t.length;s++){const a=t[s],n=i.attributes[a],c=this.attributes[a];if(n&&!rt(n,c))return!1}return!0}updateFrom(e,t){const i=this._diff;return i.didChange(e)?(Cn(e,t,this),i.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}}const Ui=0,vr=1,_r=2;function Ln(o,e){for(let t=0,i=o.length;t<i;t++)o[t].traverseVisible(a=>{a.isMesh&&e(a)})}function In(o){const e=[];for(let t=0,i=o.length;t<i;t++){const s=o[t];Array.isArray(s.material)?e.push(...s.material):e.push(s.material)}return e}function Dn(o,e,t){if(o.length===0){e.setIndex(null);const i=e.attributes;for(const s in i)e.deleteAttribute(s);for(const s in t.attributes)e.setAttribute(t.attributes[s],new d.BufferAttribute(new Float32Array(0),4,!1))}else wn(o,t,e);for(const i in e.attributes)e.attributes[i].needsUpdate=!0}class Pn{constructor(e){this.objects=null,this.useGroups=!0,this.applyWorldTransforms=!0,this.generateMissingAttributes=!0,this.overwriteIndex=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Map,this._geometryMergeSets=new WeakMap,this._mergeOrder=[],this._dummyMesh=null,this.setObjects(e||[])}_getDummyMesh(){if(!this._dummyMesh){const e=new d.MeshBasicMaterial,t=new d.BufferGeometry;t.setAttribute("position",new d.BufferAttribute(new Float32Array(9),3)),this._dummyMesh=new d.Mesh(t,e)}return this._dummyMesh}_getMeshes(){const e=[];return Ln(this.objects,t=>{e.push(t)}),e.sort((t,i)=>t.uuid>i.uuid?1:t.uuid<i.uuid?-1:0),e.length===0&&e.push(this._getDummyMesh()),e}_updateIntermediateGeometries(){const{_intermediateGeometry:e}=this,t=this._getMeshes(),i=new Set(e.keys()),s={attributes:this.attributes,applyWorldTransforms:this.applyWorldTransforms};for(let a=0,n=t.length;a<n;a++){const c=t[a],h=c.uuid;i.delete(h);let f=e.get(h);(!f||!f.isCompatible(c,this.attributes))&&(f&&f.dispose(),f=new Rn,e.set(h,f)),f.updateFrom(c,s)&&this.generateMissingAttributes&&An(f,this.attributes)}i.forEach(a=>{e.delete(a)})}setObjects(e){Array.isArray(e)?this.objects=[...e]:this.objects=[e]}generate(e=new d.BufferGeometry){const{useGroups:t,overwriteIndex:i,_intermediateGeometry:s,_geometryMergeSets:a}=this,n=this._getMeshes(),c=[],h=[],f=a.get(e)||[];this._updateIntermediateGeometries();let p=!1;n.length!==f.length&&(p=!0);for(let l=0,u=n.length;l<u;l++){const g=n[l],y=s.get(g.uuid);h.push(y);const m=f[l];!m||m.uuid!==y.uuid?(c.push(!1),p=!0):m.version!==y.version?c.push(!1):c.push(!0)}Dn(h,e,{useGroups:t,forceUpdate:p,skipAssigningAttributes:c,overwriteIndex:i}),p&&e.dispose(),a.set(e,h.map(l=>({version:l.version,uuid:l.uuid})));let r=Ui;return p?r=_r:c.includes(!1)&&(r=vr),{changeType:r,materials:In(n),geometry:e}}}function Fn(o){const e=new Set;for(let t=0,i=o.length;t<i;t++){const s=o[t];for(const a in s){const n=s[a];n&&n.isTexture&&e.add(n)}}return Array.from(e)}function En(o){const e=[],t=new Set;for(let s=0,a=o.length;s<a;s++)o[s].traverse(n=>{n.visible&&(n.isRectAreaLight||n.isSpotLight||n.isPointLight||n.isDirectionalLight)&&(e.push(n),n.iesMap&&t.add(n.iesMap))});const i=Array.from(t).sort((s,a)=>s.uuid<a.uuid?1:s.uuid>a.uuid?-1:0);return{lights:e,iesTextures:i}}class Bn{get initialized(){return!!this.bvh}constructor(e){this.bvhOptions={},this.attributes=["position","normal","tangent","color","uv","uv2"],this.generateBVH=!0,this.bvh=null,this.geometry=new d.BufferGeometry,this.staticGeometryGenerator=new Pn(e),this._bvhWorker=null,this._pendingGenerate=null,this._buildAsync=!1}setObjects(e){this.staticGeometryGenerator.setObjects(e)}setBVHWorker(e){this._bvhWorker=e}async generateAsync(e=null){if(!this._bvhWorker)throw new Error('PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.');if(this.bvh instanceof Promise)return this._pendingGenerate||(this._pendingGenerate=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(e)))),this._pendingGenerate;{this._buildAsync=!0;const t=this.generate(e);return this._buildAsync=!1,t.bvh=this.bvh=await t.bvh,t}}generate(e=null){const{staticGeometryGenerator:t,geometry:i,attributes:s}=this,a=t.objects;t.attributes=s,a.forEach(r=>{r.traverse(l=>{l.isSkinnedMesh&&l.skeleton&&l.skeleton.update()})});const n=t.generate(i),c=n.materials,h=Fn(c),{lights:f,iesTextures:p}=En(a);if(n.changeType!==Ui&&bn(i,c,c),this.generateBVH){if(this.bvh instanceof Promise)throw new Error("PathTracingSceneGenerator: BVH is already building asynchronously.");if(n.changeType===_r){const r={strategy:Ie.SAH,maxLeafTris:1,indirect:!0,onProgress:e,...this.bvhOptions};this._buildAsync?this.bvh=this._bvhWorker.generate(i,r):this.bvh=new Ie.MeshBVH(i,r)}else n.changeType===vr&&this.bvh.refit()}return{bvhChanged:n.changeType!==Ui,bvh:this.bvh,lights:f,iesTextures:p,geometry:i,materials:c,textures:h,objects:a}}}class ls extends d.ShaderMaterial{set needsUpdate(e){super.needsUpdate=!0,this.dispatchEvent({type:"recompilation"})}constructor(e){super(e);for(const t in this.uniforms)Object.defineProperty(this,t,{get(){return this.uniforms[t].value},set(i){this.uniforms[t].value=i}})}setDefine(e,t=void 0){if(t==null){if(e in this.defines)return delete this.defines[e],this.needsUpdate=!0,!0}else if(this.defines[e]!==t)return this.defines[e]=t,this.needsUpdate=!0,!0;return!1}}class kn extends ls{constructor(e){super({blending:d.NoBlending,uniforms:{target1:{value:null},target2:{value:null},opacity:{value:1}},vertexShader:`
1
+ "use strict";var _n=Object.create;var Di=Object.defineProperty;var vn=Object.getOwnPropertyDescriptor;var yn=Object.getOwnPropertyNames;var xn=Object.getPrototypeOf,wn=Object.prototype.hasOwnProperty;var bn=(a,e,t)=>e in a?Di(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var An=(a,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of yn(e))!wn.call(a,s)&&s!==t&&Di(a,s,{get:()=>e[s],enumerable:!(i=vn(e,s))||i.enumerable});return a};var Tn=(a,e,t)=>(t=a!=null?_n(xn(a)):{},An(e||!a||!a.__esModule?Di(t,"default",{value:a,enumerable:!0}):t,a));var E=(a,e,t)=>(bn(a,typeof e!="symbol"?e+"":e,t),t),Es=(a,e,t)=>{if(!e.has(a))throw TypeError("Cannot "+t)};var Q=(a,e,t)=>(Es(a,e,"read from private field"),t?t.call(a):e.get(a)),Pe=(a,e,t)=>{if(e.has(a))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(a):e.set(a,t)},ye=(a,e,t,i)=>(Es(a,e,"write to private field"),i?i.call(a,t):e.set(a,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("three"),ks=require("three/examples/jsm/loaders/HDRLoader.js"),Sn=require("three/examples/jsm/controls/OrbitControls"),be=require("three/examples/jsm/renderers/CSS2DRenderer"),Mn=require("three/examples/jsm/loaders/FontLoader"),ws=require("three/examples/jsm/loaders/GLTFLoader.js");require("three/examples/jsm/libs/meshopt_decoder.module.js");require("three/examples/jsm/loaders/DRACOLoader.js");const Cn=require("three/examples/jsm/loaders/GLTFLoader"),Dn=require("three/examples/jsm/loaders/DRACOLoader"),Ln=require("three/examples/jsm/exporters/DRACOExporter"),Pn=require("three/examples/jsm/exporters/GLTFExporter"),In=require("three/examples/jsm/utils/SkeletonUtils.js"),Rr=require("three/examples/jsm/lines/Line2.js"),Er=require("three/examples/jsm/lines/LineMaterial.js"),$i=require("three/examples/jsm/lines/LineGeometry.js"),Rn=require("three/examples/jsm/renderers/CSS3DRenderer");require("three/examples/jsm/utils/BufferGeometryUtils");const jt=require("three/examples/jsm/postprocessing/Pass"),Be=require("three-mesh-bvh"),_t=require("three/examples/jsm/postprocessing/Pass.js");var vt=typeof document<"u"?document.currentScript:null;function kr(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const V=kr(f),Li=kr(In);function Fr(a,e,t=0){if(a.isInterleavedBufferAttribute){const i=a.itemSize;for(let s=0,r=a.count;s<r;s++){const o=s+t;e.setX(o,a.getX(s)),i>=2&&e.setY(o,a.getY(s)),i>=3&&e.setZ(o,a.getZ(s)),i>=4&&e.setW(o,a.getW(s))}}else{const i=e.array,s=i.constructor,r=i.BYTES_PER_ELEMENT*a.itemSize*t;new s(i.buffer,r,a.array.length).set(a.array)}}function Ft(a,e=null){const t=a.array.constructor,i=a.normalized,s=a.itemSize,r=e===null?a.count:e;return new f.BufferAttribute(new t(s*r),s,i)}function ht(a,e){if(!a&&!e)return!0;if(!!a!=!!e)return!1;const t=a.count===e.count,i=a.normalized===e.normalized,s=a.array.constructor===e.array.constructor,r=a.itemSize===e.itemSize;return!(!t||!i||!s||!r)}function En(a){const e=a[0].index!==null,t=new Set(Object.keys(a[0].attributes));if(!a[0].getAttribute("position"))throw new Error("StaticGeometryGenerator: position attribute is required.");for(let i=0;i<a.length;++i){const s=a[i];let r=0;if(e!==(s.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const o in s.attributes){if(!t.has(o))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+o+'" attribute exists among all geometries, or in none of them.');r++}if(r!==t.size)throw new Error("StaticGeometryGenerator: All geometries must have the same number of attributes.")}}function kn(a){let e=0;for(let t=0,i=a.length;t<i;t++)e+=a[t].getIndex().count;return e}function Fn(a){let e=0;for(let t=0,i=a.length;t<i;t++)e+=a[t].getAttribute("position").count;return e}function Bn(a,e,t){a.index&&a.index.count!==e&&a.setIndex(null);const i=a.attributes;for(const s in i)i[s].count!==t&&a.deleteAttribute(s)}function On(a,e={},t=new f.BufferGeometry){const{useGroups:i=!1,forceUpdate:s=!1,skipAssigningAttributes:r=[],overwriteIndex:o=!0}=e;En(a);const c=a[0].index!==null,h=c?kn(a):-1,u=Fn(a);if(Bn(t,h,u),i){let n=0;for(let l=0,d=a.length;l<d;l++){const g=a[l];let v;c?v=g.getIndex().count:v=g.getAttribute("position").count,t.addGroup(n,v,l),n+=v}}if(c){let n=!1;if(t.index||(t.setIndex(new f.BufferAttribute(new Uint32Array(h),1,!1)),n=!0),n||o){let l=0,d=0;const g=t.getIndex();for(let v=0,m=a.length;v<m;v++){const _=a[v],y=_.getIndex();if(!(!s&&!n&&r[v]))for(let x=0;x<y.count;++x)g.setX(l+x,y.getX(x)+d);l+=y.count,d+=_.getAttribute("position").count}}}const p=Object.keys(a[0].attributes);for(let n=0,l=p.length;n<l;n++){let d=!1;const g=p[n];if(!t.getAttribute(g)){const _=a[0].getAttribute(g);t.setAttribute(g,Ft(_,u)),d=!0}let v=0;const m=t.getAttribute(g);for(let _=0,y=a.length;_<y;_++){const w=a[_],x=!s&&!d&&r[_],b=w.getAttribute(g);x||Fr(b,m,v),v+=b.count}}}function zn(a,e,t){const i=a.index,r=a.attributes.position.count,o=i?i.count:r;let c=a.groups;c.length===0&&(c=[{count:o,start:0,materialIndex:0}]);let h=a.getAttribute("materialIndex");if(!h||h.count!==r){let p;t.length<=255?p=new Uint8Array(r):p=new Uint16Array(r),h=new f.BufferAttribute(p,1,!1),a.deleteAttribute("materialIndex"),a.setAttribute("materialIndex",h)}const u=h.array;for(let p=0;p<c.length;p++){const n=c[p],l=n.start,d=n.count,g=Math.min(d,o-l),v=Array.isArray(e)?e[n.materialIndex]:e,m=t.indexOf(v);for(let _=0;_<g;_++){let y=l+_;i&&(y=i.getX(y)),u[y]=m}}}function Vn(a,e){if(!a.index){const t=a.attributes.position.count,i=new Array(t);for(let s=0;s<t;s++)i[s]=s;a.setIndex(i)}if(!a.attributes.normal&&e&&e.includes("normal")&&a.computeVertexNormals(),!a.attributes.uv&&e&&e.includes("uv")){const t=a.attributes.position.count;a.setAttribute("uv",new f.BufferAttribute(new Float32Array(t*2),2,!1))}if(!a.attributes.uv2&&e&&e.includes("uv2")){const t=a.attributes.position.count;a.setAttribute("uv2",new f.BufferAttribute(new Float32Array(t*2),2,!1))}if(!a.attributes.tangent&&e&&e.includes("tangent"))if(a.attributes.uv&&a.attributes.normal)a.computeTangents();else{const t=a.attributes.position.count;a.setAttribute("tangent",new f.BufferAttribute(new Float32Array(t*4),4,!1))}if(!a.attributes.color&&e&&e.includes("color")){const t=a.attributes.position.count,i=new Float32Array(t*4);i.fill(1),a.setAttribute("color",new f.BufferAttribute(i,4))}}function bs(a){let e=0;if(a.byteLength!==0){const t=new Uint8Array(a);for(let i=0;i<a.byteLength;i++){const s=t[i];e=(e<<5)-e+s,e|=0}}return e}function Fs(a){let e=a.uuid;const t=Object.values(a.attributes);a.index&&(t.push(a.index),e+=`index|${a.index.version}`);const i=Object.keys(t).sort();for(const s of i){const r=t[s];e+=`${s}_${r.version}|`}return e}function Bs(a){const e=a.skeleton;return e?(e.boneTexture||e.computeBoneTexture(),`${bs(e.boneTexture.image.data.buffer)}_${e.boneTexture.uuid}`):null}class Wn{constructor(e=null){this.matrixWorld=new f.Matrix4,this.geometryHash=null,this.skeletonHash=null,this.primitiveCount=-1,e!==null&&this.updateFrom(e)}updateFrom(e){const t=e.geometry,i=(t.index?t.index.count:t.attributes.position.count)/3;this.matrixWorld.copy(e.matrixWorld),this.geometryHash=Fs(t),this.primitiveCount=i,this.skeletonHash=Bs(e)}didChange(e){const t=e.geometry,i=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===Fs(t)&&this.skeletonHash===Bs(e)&&this.primitiveCount===i)}}const We=new f.Vector3,Ue=new f.Vector3,He=new f.Vector3,Os=new f.Vector4,qt=new f.Vector3,Pi=new f.Vector3,zs=new f.Vector4,Vs=new f.Vector4,Yt=new f.Matrix4,Ws=new f.Matrix4;function Us(a,e,t){const i=a.skeleton,s=a.geometry,r=i.bones,o=i.boneInverses;zs.fromBufferAttribute(s.attributes.skinIndex,e),Vs.fromBufferAttribute(s.attributes.skinWeight,e),Yt.elements.fill(0);for(let c=0;c<4;c++){const h=Vs.getComponent(c);if(h!==0){const u=zs.getComponent(c);Ws.multiplyMatrices(r[u].matrixWorld,o[u]),Un(Yt,Ws,h)}}return Yt.multiply(a.bindMatrix).premultiply(a.bindMatrixInverse),t.transformDirection(Yt),t}function Ii(a,e,t,i,s){qt.set(0,0,0);for(let r=0,o=a.length;r<o;r++){const c=e[r],h=a[r];c!==0&&(Pi.fromBufferAttribute(h,i),t?qt.addScaledVector(Pi,c):qt.addScaledVector(Pi.sub(s),c))}s.add(qt)}function Un(a,e,t){const i=a.elements,s=e.elements;for(let r=0,o=s.length;r<o;r++)i[r]+=s[r]*t}function Hn(a){const{index:e,attributes:t}=a;if(e)for(let i=0,s=e.count;i<s;i+=3){const r=e.getX(i),o=e.getX(i+2);e.setX(i,o),e.setX(i+2,r)}else for(const i in t){const s=t[i],r=s.itemSize;for(let o=0,c=s.count;o<c;o+=3)for(let h=0;h<r;h++){const u=s.getComponent(o,h),p=s.getComponent(o+2,h);s.setComponent(o,h,p),s.setComponent(o+2,h,u)}}return a}function Gn(a,e={},t=new f.BufferGeometry){e={applyWorldTransforms:!0,attributes:[],...e};const i=a.geometry,s=e.applyWorldTransforms,r=e.attributes.includes("normal"),o=e.attributes.includes("tangent"),c=i.attributes,h=t.attributes;for(const y in t.attributes)(!e.attributes.includes(y)||!(y in i.attributes))&&t.deleteAttribute(y);!t.index&&i.index&&(t.index=i.index.clone()),h.position||t.setAttribute("position",Ft(c.position)),r&&!h.normal&&c.normal&&t.setAttribute("normal",Ft(c.normal)),o&&!h.tangent&&c.tangent&&t.setAttribute("tangent",Ft(c.tangent)),ht(i.index,t.index),ht(c.position,h.position),r&&ht(c.normal,h.normal),o&&ht(c.tangent,h.tangent);const u=c.position,p=r?c.normal:null,n=o?c.tangent:null,l=i.morphAttributes.position,d=i.morphAttributes.normal,g=i.morphAttributes.tangent,v=i.morphTargetsRelative,m=a.morphTargetInfluences,_=new f.Matrix3;_.getNormalMatrix(a.matrixWorld),i.index&&t.index.array.set(i.index.array);for(let y=0,w=c.position.count;y<w;y++)We.fromBufferAttribute(u,y),p&&Ue.fromBufferAttribute(p,y),n&&(Os.fromBufferAttribute(n,y),He.fromBufferAttribute(n,y)),m&&(l&&Ii(l,m,v,y,We),d&&Ii(d,m,v,y,Ue),g&&Ii(g,m,v,y,He)),a.isSkinnedMesh&&(a.applyBoneTransform(y,We),p&&Us(a,y,Ue),n&&Us(a,y,He)),s&&We.applyMatrix4(a.matrixWorld),h.position.setXYZ(y,We.x,We.y,We.z),p&&(s&&Ue.applyNormalMatrix(_),h.normal.setXYZ(y,Ue.x,Ue.y,Ue.z)),n&&(s&&He.transformDirection(a.matrixWorld),h.tangent.setXYZW(y,He.x,He.y,He.z,Os.w));for(const y in e.attributes){const w=e.attributes[y];w==="position"||w==="tangent"||w==="normal"||!(w in c)||(h[w]||t.setAttribute(w,Ft(c[w])),ht(c[w],h[w]),Fr(c[w],h[w]))}return a.matrixWorld.determinant()<0&&Hn(t),t}class Nn extends f.BufferGeometry{constructor(){super(),this.version=0,this.hash=null,this._diff=new Wn}isCompatible(e,t){const i=e.geometry;for(let s=0;s<t.length;s++){const r=t[s],o=i.attributes[r],c=this.attributes[r];if(o&&!ht(o,c))return!1}return!0}updateFrom(e,t){const i=this._diff;return i.didChange(e)?(Gn(e,t,this),i.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}}const es=0,Br=1,Or=2;function Qn(a,e){for(let t=0,i=a.length;t<i;t++)a[t].traverseVisible(r=>{r.isMesh&&e(r)})}function jn(a){const e=[];for(let t=0,i=a.length;t<i;t++){const s=a[t];Array.isArray(s.material)?e.push(...s.material):e.push(s.material)}return e}function qn(a,e,t){if(a.length===0){e.setIndex(null);const i=e.attributes;for(const s in i)e.deleteAttribute(s);for(const s in t.attributes)e.setAttribute(t.attributes[s],new f.BufferAttribute(new Float32Array(0),4,!1))}else On(a,t,e);for(const i in e.attributes)e.attributes[i].needsUpdate=!0}class Yn{constructor(e){this.objects=null,this.useGroups=!0,this.applyWorldTransforms=!0,this.generateMissingAttributes=!0,this.overwriteIndex=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Map,this._geometryMergeSets=new WeakMap,this._mergeOrder=[],this._dummyMesh=null,this.setObjects(e||[])}_getDummyMesh(){if(!this._dummyMesh){const e=new f.MeshBasicMaterial,t=new f.BufferGeometry;t.setAttribute("position",new f.BufferAttribute(new Float32Array(9),3)),this._dummyMesh=new f.Mesh(t,e)}return this._dummyMesh}_getMeshes(){const e=[];return Qn(this.objects,t=>{e.push(t)}),e.sort((t,i)=>t.uuid>i.uuid?1:t.uuid<i.uuid?-1:0),e.length===0&&e.push(this._getDummyMesh()),e}_updateIntermediateGeometries(){const{_intermediateGeometry:e}=this,t=this._getMeshes(),i=new Set(e.keys()),s={attributes:this.attributes,applyWorldTransforms:this.applyWorldTransforms};for(let r=0,o=t.length;r<o;r++){const c=t[r],h=c.uuid;i.delete(h);let u=e.get(h);(!u||!u.isCompatible(c,this.attributes))&&(u&&u.dispose(),u=new Nn,e.set(h,u)),u.updateFrom(c,s)&&this.generateMissingAttributes&&Vn(u,this.attributes)}i.forEach(r=>{e.delete(r)})}setObjects(e){Array.isArray(e)?this.objects=[...e]:this.objects=[e]}generate(e=new f.BufferGeometry){const{useGroups:t,overwriteIndex:i,_intermediateGeometry:s,_geometryMergeSets:r}=this,o=this._getMeshes(),c=[],h=[],u=r.get(e)||[];this._updateIntermediateGeometries();let p=!1;o.length!==u.length&&(p=!0);for(let l=0,d=o.length;l<d;l++){const g=o[l],v=s.get(g.uuid);h.push(v);const m=u[l];!m||m.uuid!==v.uuid?(c.push(!1),p=!0):m.version!==v.version?c.push(!1):c.push(!0)}qn(h,e,{useGroups:t,forceUpdate:p,skipAssigningAttributes:c,overwriteIndex:i}),p&&e.dispose(),r.set(e,h.map(l=>({version:l.version,uuid:l.uuid})));let n=es;return p?n=Or:c.includes(!1)&&(n=Br),{changeType:n,materials:jn(o),geometry:e}}}function Zn(a){const e=new Set;for(let t=0,i=a.length;t<i;t++){const s=a[t];for(const r in s){const o=s[r];o&&o.isTexture&&e.add(o)}}return Array.from(e)}function Kn(a){const e=[],t=new Set;for(let s=0,r=a.length;s<r;s++)a[s].traverse(o=>{o.visible&&(o.isRectAreaLight||o.isSpotLight||o.isPointLight||o.isDirectionalLight)&&(e.push(o),o.iesMap&&t.add(o.iesMap))});const i=Array.from(t).sort((s,r)=>s.uuid<r.uuid?1:s.uuid>r.uuid?-1:0);return{lights:e,iesTextures:i}}class Xn{get initialized(){return!!this.bvh}constructor(e){this.bvhOptions={},this.attributes=["position","normal","tangent","color","uv","uv2"],this.generateBVH=!0,this.bvh=null,this.geometry=new f.BufferGeometry,this.staticGeometryGenerator=new Yn(e),this._bvhWorker=null,this._pendingGenerate=null,this._buildAsync=!1}setObjects(e){this.staticGeometryGenerator.setObjects(e)}setBVHWorker(e){this._bvhWorker=e}async generateAsync(e=null){if(!this._bvhWorker)throw new Error('PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.');if(this.bvh instanceof Promise)return this._pendingGenerate||(this._pendingGenerate=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(e)))),this._pendingGenerate;{this._buildAsync=!0;const t=this.generate(e);return this._buildAsync=!1,t.bvh=this.bvh=await t.bvh,t}}generate(e=null){const{staticGeometryGenerator:t,geometry:i,attributes:s}=this,r=t.objects;t.attributes=s,r.forEach(n=>{n.traverse(l=>{l.isSkinnedMesh&&l.skeleton&&l.skeleton.update()})});const o=t.generate(i),c=o.materials,h=Zn(c),{lights:u,iesTextures:p}=Kn(r);if(o.changeType!==es&&zn(i,c,c),this.generateBVH){if(this.bvh instanceof Promise)throw new Error("PathTracingSceneGenerator: BVH is already building asynchronously.");if(o.changeType===Or){const n={strategy:Be.SAH,maxLeafTris:1,indirect:!0,onProgress:e,...this.bvhOptions};this._buildAsync?this.bvh=this._bvhWorker.generate(i,n):this.bvh=new Be.MeshBVH(i,n)}else o.changeType===Br&&this.bvh.refit()}return{bvhChanged:o.changeType!==es,bvh:this.bvh,lights:u,iesTextures:p,geometry:i,materials:c,textures:h,objects:r}}}class As extends f.ShaderMaterial{set needsUpdate(e){super.needsUpdate=!0,this.dispatchEvent({type:"recompilation"})}constructor(e){super(e);for(const t in this.uniforms)Object.defineProperty(this,t,{get(){return this.uniforms[t].value},set(i){this.uniforms[t].value=i}})}setDefine(e,t=void 0){if(t==null){if(e in this.defines)return delete this.defines[e],this.needsUpdate=!0,!0}else if(this.defines[e]!==t)return this.defines[e]=t,this.needsUpdate=!0,!0;return!1}}class Jn extends As{constructor(e){super({blending:f.NoBlending,uniforms:{target1:{value:null},target2:{value:null},opacity:{value:1}},vertexShader:`
2
2
 
3
3
  varying vec2 vUv;
4
4
 
@@ -35,7 +35,7 @@
35
35
 
36
36
  }
37
37
 
38
- }`}),this.setValues(e)}}function Ut(o=1){let e="uint";return o>1&&(e="uvec"+o),`
38
+ }`}),this.setValues(e)}}function Zt(a=1){let e="uint";return a>1&&(e="uvec"+a),`
39
39
  ${e} sobolReverseBits( ${e} x ) {
40
40
 
41
41
  x = ( ( ( x & 0xaaaaaaaau ) >> 1 ) | ( ( x & 0x55555555u ) << 1 ) );
@@ -70,7 +70,7 @@
70
70
  return x;
71
71
 
72
72
  }
73
- `}function Wt(o=1){let e="uint",t="float",i="",s=".r",a="1u";return o>1&&(e="uvec"+o,t="vec"+o,i=o+"",o===2?(s=".rg",a="uvec2( 1u, 2u )"):o===3?(s=".rgb",a="uvec3( 1u, 2u, 3u )"):(s="",a="uvec4( 1u, 2u, 3u, 4u )")),`
73
+ `}function Kt(a=1){let e="uint",t="float",i="",s=".r",r="1u";return a>1&&(e="uvec"+a,t="vec"+a,i=a+"",a===2?(s=".rg",r="uvec2( 1u, 2u )"):a===3?(s=".rgb",r="uvec3( 1u, 2u, 3u )"):(s="",r="uvec4( 1u, 2u, 3u, 4u )")),`
74
74
 
75
75
  ${t} sobol${i}( int effect ) {
76
76
 
@@ -82,22 +82,22 @@
82
82
  ${t} sobol_pt = sobolGetTexturePoint( shuffled_index )${s};
83
83
  ${e} result = ${e}( sobol_pt * 16777216.0 );
84
84
 
85
- ${e} seed2 = sobolHashCombine( seed, ${a} );
85
+ ${e} seed2 = sobolHashCombine( seed, ${r} );
86
86
  result = nestedUniformScrambleBase2( result, seed2 );
87
87
 
88
88
  return SOBOL_FACTOR * ${t}( result >> 8 );
89
89
 
90
90
  }
91
- `}const yr=`
91
+ `}const zr=`
92
92
 
93
93
  // Utils
94
94
  const float SOBOL_FACTOR = 1.0 / 16777216.0;
95
95
  const uint SOBOL_MAX_POINTS = 256u * 256u;
96
96
 
97
- ${Ut(1)}
98
- ${Ut(2)}
99
- ${Ut(3)}
100
- ${Ut(4)}
97
+ ${Zt(1)}
98
+ ${Zt(2)}
99
+ ${Zt(3)}
100
+ ${Zt(4)}
101
101
 
102
102
  uint sobolHash( uint x ) {
103
103
 
@@ -111,7 +111,7 @@
111
111
 
112
112
  }
113
113
 
114
- `,On=`
114
+ `,$n=`
115
115
 
116
116
  const uint SOBOL_DIRECTIONS_1[ 32 ] = uint[ 32 ](
117
117
  0x80000000u, 0xc0000000u, 0xa0000000u, 0xf0000000u,
@@ -189,7 +189,7 @@
189
189
 
190
190
  }
191
191
 
192
- `,zn=`
192
+ `,eo=`
193
193
 
194
194
  // Seeds
195
195
  uniform sampler2D sobolTexture;
@@ -227,12 +227,12 @@
227
227
 
228
228
  }
229
229
 
230
- ${Wt(1)}
231
- ${Wt(2)}
232
- ${Wt(3)}
233
- ${Wt(4)}
230
+ ${Kt(1)}
231
+ ${Kt(2)}
232
+ ${Kt(3)}
233
+ ${Kt(4)}
234
234
 
235
- `;class Vn extends ls{constructor(){super({blending:d.NoBlending,uniforms:{resolution:{value:new d.Vector2}},vertexShader:`
235
+ `;class to extends As{constructor(){super({blending:f.NoBlending,uniforms:{resolution:{value:new f.Vector2}},vertexShader:`
236
236
 
237
237
  varying vec2 vUv;
238
238
  void main() {
@@ -243,8 +243,8 @@
243
243
  }
244
244
  `,fragmentShader:`
245
245
 
246
- ${yr}
247
- ${On}
246
+ ${zr}
247
+ ${$n}
248
248
 
249
249
  varying vec2 vUv;
250
250
  uniform vec2 resolution;
@@ -254,7 +254,7 @@
254
254
  gl_FragColor = generateSobolPoint( index );
255
255
 
256
256
  }
257
- `})}}class Un{generate(e,t=256){const i=new d.WebGLRenderTarget(t,t,{type:d.FloatType,format:d.RGBAFormat,minFilter:d.NearestFilter,magFilter:d.NearestFilter,generateMipmaps:!1}),s=e.getRenderTarget();e.setRenderTarget(i);const a=new ut.FullScreenQuad(new Vn);return a.material.resolution.set(t,t),a.render(e),e.setRenderTarget(s),a.dispose(),i}}class Wn extends d.PerspectiveCamera{set bokehSize(e){this.fStop=this.getFocalLength()/e}get bokehSize(){return this.getFocalLength()/this.fStop}constructor(...e){super(...e),this.fStop=1.4,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=25,this.anamorphicRatio=1}copy(e,t){return super.copy(e,t),this.fStop=e.fStop,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio,this}}class Hn{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof Wn?(this.bokehSize=e.bokehSize,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio):(this.bokehSize=0,this.apertureRotation=0,this.apertureBlades=0,this.focusDistance=10,this.anamorphicRatio=1)}}function wi(o){const e=new Uint16Array(o.length);for(let t=0,i=o.length;t<i;++t)e[t]=d.DataUtils.toHalfFloat(o[t]);return e}function Is(o,e,t=0,i=o.length){let s=t,a=t+i-1;for(;s<a;){const n=s+a>>1;o[n]<e?s=n+1:a=n}return s-t}function Gn(o,e,t){return .2126*o+.7152*e+.0722*t}function Nn(o,e=d.HalfFloatType){const t=o.clone();t.source=new d.Source({...t.image});const{width:i,height:s,data:a}=t.image;let n=a;if(t.type!==e){e===d.HalfFloatType?n=new Uint16Array(a.length):n=new Float32Array(a.length);let c;a instanceof Int8Array||a instanceof Int16Array||a instanceof Int32Array?c=2**(8*a.BYTES_PER_ELEMENT-1)-1:c=2**(8*a.BYTES_PER_ELEMENT)-1;for(let h=0,f=a.length;h<f;h++){let p=a[h];t.type===d.HalfFloatType&&(p=d.DataUtils.fromHalfFloat(a[h])),t.type!==d.FloatType&&t.type!==d.HalfFloatType&&(p/=c),e===d.HalfFloatType&&(n[h]=d.DataUtils.toHalfFloat(p))}t.image.data=n,t.type=e}if(t.flipY){const c=n;n=n.slice();for(let h=0;h<s;h++)for(let f=0;f<i;f++){const p=s-h-1,r=4*(h*i+f),l=4*(p*i+f);n[l+0]=c[r+0],n[l+1]=c[r+1],n[l+2]=c[r+2],n[l+3]=c[r+3]}t.flipY=!1,t.image.data=n}return t}class qn{constructor(){const e=new d.DataTexture(wi(new Float32Array([0,0,0,0])),1,1);e.type=d.HalfFloatType,e.format=d.RGBAFormat,e.minFilter=d.LinearFilter,e.magFilter=d.LinearFilter,e.wrapS=d.RepeatWrapping,e.wrapT=d.RepeatWrapping,e.generateMipmaps=!1,e.needsUpdate=!0;const t=new d.DataTexture(wi(new Float32Array([0,1])),1,2);t.type=d.HalfFloatType,t.format=d.RedFormat,t.minFilter=d.LinearFilter,t.magFilter=d.LinearFilter,t.generateMipmaps=!1,t.needsUpdate=!0;const i=new d.DataTexture(wi(new Float32Array([0,0,1,1])),2,2);i.type=d.HalfFloatType,i.format=d.RedFormat,i.minFilter=d.LinearFilter,i.magFilter=d.LinearFilter,i.generateMipmaps=!1,i.needsUpdate=!0,this.map=e,this.marginalWeights=t,this.conditionalWeights=i,this.totalSum=0}dispose(){this.marginalWeights.dispose(),this.conditionalWeights.dispose(),this.map.dispose()}updateFrom(e){const t=Nn(e);t.wrapS=d.RepeatWrapping,t.wrapT=d.ClampToEdgeWrapping;const{width:i,height:s,data:a}=t.image,n=new Float32Array(i*s),c=new Float32Array(i*s),h=new Float32Array(s),f=new Float32Array(s);let p=0,r=0;for(let m=0;m<s;m++){let v=0;for(let _=0;_<i;_++){const x=m*i+_,w=d.DataUtils.fromHalfFloat(a[4*x+0]),b=d.DataUtils.fromHalfFloat(a[4*x+1]),T=d.DataUtils.fromHalfFloat(a[4*x+2]),S=Gn(w,b,T);v+=S,p+=S,n[x]=S,c[x]=v}if(v!==0)for(let _=m*i,x=m*i+i;_<x;_++)n[_]/=v,c[_]/=v;r+=v,h[m]=v,f[m]=r}if(r!==0)for(let m=0,v=h.length;m<v;m++)h[m]/=r,f[m]/=r;const l=new Uint16Array(s),u=new Uint16Array(i*s);for(let m=0;m<s;m++){const v=(m+1)/s,_=Is(f,v);l[m]=d.DataUtils.toHalfFloat((_+.5)/s)}for(let m=0;m<s;m++)for(let v=0;v<i;v++){const _=m*i+v,x=(v+1)/i,w=Is(c,x,m*i,i);u[_]=d.DataUtils.toHalfFloat((w+.5)/i)}this.dispose();const{marginalWeights:g,conditionalWeights:y}=this;g.image={width:s,height:1,data:l},g.needsUpdate=!0,y.image={width:i,height:s,data:u},y.needsUpdate=!0,this.totalSum=p,this.map=t}}const bi=6,jn=0,Qn=1,Yn=2,Kn=3,Xn=4,ce=new d.Vector3,J=new d.Vector3,Ds=new d.Matrix4,Ne=new d.Quaternion,Ps=new d.Vector3,qe=new d.Vector3,Zn=new d.Vector3(0,1,0);class Jn{constructor(){const e=new d.DataTexture(new Float32Array(4),1,1);e.format=d.RGBAFormat,e.type=d.FloatType,e.wrapS=d.ClampToEdgeWrapping,e.wrapT=d.ClampToEdgeWrapping,e.generateMipmaps=!1,e.minFilter=d.NearestFilter,e.magFilter=d.NearestFilter,this.tex=e,this.count=0}updateFrom(e,t=[]){const i=this.tex,s=Math.max(e.length*bi,1),a=Math.ceil(Math.sqrt(s));i.image.width!==a&&(i.dispose(),i.image.data=new Float32Array(a*a*4),i.image.width=a,i.image.height=a);const n=i.image.data;for(let h=0,f=e.length;h<f;h++){const p=e[h],r=h*bi*4;let l=0;for(let g=0;g<bi*4;g++)n[r+g]=0;p.getWorldPosition(J),n[r+l++]=J.x,n[r+l++]=J.y,n[r+l++]=J.z;let u=jn;if(p.isRectAreaLight&&p.isCircular?u=Qn:p.isSpotLight?u=Yn:p.isDirectionalLight?u=Kn:p.isPointLight&&(u=Xn),n[r+l++]=u,n[r+l++]=p.color.r,n[r+l++]=p.color.g,n[r+l++]=p.color.b,n[r+l++]=p.intensity,p.getWorldQuaternion(Ne),p.isRectAreaLight)ce.set(p.width,0,0).applyQuaternion(Ne),n[r+l++]=ce.x,n[r+l++]=ce.y,n[r+l++]=ce.z,l++,J.set(0,p.height,0).applyQuaternion(Ne),n[r+l++]=J.x,n[r+l++]=J.y,n[r+l++]=J.z,n[r+l++]=ce.cross(J).length()*(p.isCircular?Math.PI/4:1);else if(p.isSpotLight){const g=p.radius||0;Ps.setFromMatrixPosition(p.matrixWorld),qe.setFromMatrixPosition(p.target.matrixWorld),Ds.lookAt(Ps,qe,Zn),Ne.setFromRotationMatrix(Ds),ce.set(1,0,0).applyQuaternion(Ne),n[r+l++]=ce.x,n[r+l++]=ce.y,n[r+l++]=ce.z,l++,J.set(0,1,0).applyQuaternion(Ne),n[r+l++]=J.x,n[r+l++]=J.y,n[r+l++]=J.z,n[r+l++]=Math.PI*g*g,n[r+l++]=g,n[r+l++]=p.decay,n[r+l++]=p.distance,n[r+l++]=Math.cos(p.angle),n[r+l++]=Math.cos(p.angle*(1-p.penumbra)),n[r+l++]=p.iesMap?t.indexOf(p.iesMap):-1}else if(p.isPointLight){const g=ce.setFromMatrixPosition(p.matrixWorld);n[r+l++]=g.x,n[r+l++]=g.y,n[r+l++]=g.z,l++,l+=4,l+=1,n[r+l++]=p.decay,n[r+l++]=p.distance}else if(p.isDirectionalLight){const g=ce.setFromMatrixPosition(p.matrixWorld),y=J.setFromMatrixPosition(p.target.matrixWorld);qe.subVectors(g,y).normalize(),n[r+l++]=qe.x,n[r+l++]=qe.y,n[r+l++]=qe.z}}this.count=e.length;const c=as(n.buffer);return this.hash!==c?(this.hash=c,i.needsUpdate=!0,!0):!1}}function Fs(o,e,t,i,s){if(e>i)throw new Error;const a=o.length/e,n=o.constructor.BYTES_PER_ELEMENT*8;let c=1;switch(o.constructor){case Uint8Array:case Uint16Array:case Uint32Array:c=2**n-1;break;case Int8Array:case Int16Array:case Int32Array:c=2**(n-1)-1;break}for(let h=0;h<a;h++){const f=4*h,p=e*h;for(let r=0;r<i;r++)t[s+f+r]=e>=r+1?o[p+r]/c:0}}class $n extends d.DataArrayTexture{constructor(){super(),this._textures=[],this.type=d.FloatType,this.format=d.RGBAFormat,this.internalFormat="RGBA32F"}updateAttribute(e,t){const i=this._textures[e];i.updateFrom(t);const s=i.image,a=this.image;if(s.width!==a.width||s.height!==a.height)throw new Error("FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.");const{width:n,height:c,data:h}=a,p=n*c*4*e;let r=t.itemSize;r===3&&(r=4),Fs(i.image.data,r,h,4,p),this.dispose(),this.needsUpdate=!0}setAttributes(e){const t=e[0].count,i=e.length;for(let r=0,l=i;r<l;r++)if(e[r].count!==t)throw new Error("FloatAttributeTextureArray: All attributes must have the same item count.");const s=this._textures;for(;s.length<i;){const r=new Ie.FloatVertexAttributeTexture;s.push(r)}for(;s.length>i;)s.pop();for(let r=0,l=i;r<l;r++)s[r].updateFrom(e[r]);const n=s[0].image,c=this.image;(n.width!==c.width||n.height!==c.height||n.depth!==i)&&(c.width=n.width,c.height=n.height,c.depth=i,c.data=new Float32Array(c.width*c.height*c.depth*4));const{data:h,width:f,height:p}=c;for(let r=0,l=i;r<l;r++){const u=s[r],y=f*p*4*r;let m=e[r].itemSize;m===3&&(m=4),Fs(u.image.data,m,h,4,y)}this.dispose(),this.needsUpdate=!0}}class eo extends $n{updateNormalAttribute(e){this.updateAttribute(0,e)}updateTangentAttribute(e){this.updateAttribute(1,e)}updateUvAttribute(e){this.updateAttribute(2,e)}updateColorAttribute(e){this.updateAttribute(3,e)}updateFrom(e,t,i,s){this.setAttributes([e,t,i,s])}}function cs(o,e){return o.uuid<e.uuid?1:o.uuid>e.uuid?-1:0}function Wi(o){return`${o.source.uuid}:${o.colorSpace}`}function to(o){const e=new Set,t=[];for(let i=0,s=o.length;i<s;i++){const a=o[i],n=Wi(a);e.has(n)||(e.add(n),t.push(a))}return t}function io(o){const e=o.map(i=>i.iesMap||null).filter(i=>i),t=new Set(e);return Array.from(t).sort(cs)}function so(o){const e=new Set;for(let i=0,s=o.length;i<s;i++){const a=o[i];for(const n in a){const c=a[n];c&&c.isTexture&&e.add(c)}}const t=Array.from(e);return to(t).sort(cs)}function ro(o){const e=[];return o.traverse(t=>{t.visible&&(t.isRectAreaLight||t.isSpotLight||t.isPointLight||t.isDirectionalLight)&&e.push(t)}),e.sort(cs)}const xr=45,Es=xr*4;class no{constructor(){this._features={}}isUsed(e){return e in this._features}setUsed(e,t=!0){t===!1?delete this._features[e]:this._features[e]=!0}reset(){this._features={}}}class oo extends d.DataTexture{constructor(){super(new Float32Array(4),1,1),this.format=d.RGBAFormat,this.type=d.FloatType,this.wrapS=d.ClampToEdgeWrapping,this.wrapT=d.ClampToEdgeWrapping,this.minFilter=d.NearestFilter,this.magFilter=d.NearestFilter,this.generateMipmaps=!1,this.features=new no}updateFrom(e,t){function i(g,y,m=-1){if(y in g&&g[y]){const v=Wi(g[y]);return r[v]}else return m}function s(g,y,m){return y in g?g[y]:m}function a(g,y,m,v){const _=g[y]&&g[y].isTexture?g[y]:null;if(_){_.matrixAutoUpdate&&_.updateMatrix();const x=_.matrix.elements;let w=0;m[v+w++]=x[0],m[v+w++]=x[3],m[v+w++]=x[6],w++,m[v+w++]=x[1],m[v+w++]=x[4],m[v+w++]=x[7],w++}return 8}let n=0;const c=e.length*xr,h=Math.ceil(Math.sqrt(c))||1,{image:f,features:p}=this,r={};for(let g=0,y=t.length;g<y;g++)r[Wi(t[g])]=g;f.width!==h&&(this.dispose(),f.data=new Float32Array(h*h*4),f.width=h,f.height=h);const l=f.data;p.reset();for(let g=0,y=e.length;g<y;g++){const m=e[g];if(m.isFogVolumeMaterial){p.setUsed("FOG");for(let x=0;x<Es;x++)l[n+x]=0;l[n+0*4+0]=m.color.r,l[n+0*4+1]=m.color.g,l[n+0*4+2]=m.color.b,l[n+2*4+3]=s(m,"emissiveIntensity",0),l[n+3*4+0]=m.emissive.r,l[n+3*4+1]=m.emissive.g,l[n+3*4+2]=m.emissive.b,l[n+13*4+1]=m.density,l[n+13*4+3]=0,l[n+14*4+2]=4,n+=Es;continue}l[n++]=m.color.r,l[n++]=m.color.g,l[n++]=m.color.b,l[n++]=i(m,"map"),l[n++]=s(m,"metalness",0),l[n++]=i(m,"metalnessMap"),l[n++]=s(m,"roughness",0),l[n++]=i(m,"roughnessMap"),l[n++]=s(m,"ior",1.5),l[n++]=s(m,"transmission",0),l[n++]=i(m,"transmissionMap"),l[n++]=s(m,"emissiveIntensity",0),"emissive"in m?(l[n++]=m.emissive.r,l[n++]=m.emissive.g,l[n++]=m.emissive.b):(l[n++]=0,l[n++]=0,l[n++]=0),l[n++]=i(m,"emissiveMap"),l[n++]=i(m,"normalMap"),"normalScale"in m?(l[n++]=m.normalScale.x,l[n++]=m.normalScale.y):(l[n++]=1,l[n++]=1),l[n++]=s(m,"clearcoat",0),l[n++]=i(m,"clearcoatMap"),l[n++]=s(m,"clearcoatRoughness",0),l[n++]=i(m,"clearcoatRoughnessMap"),l[n++]=i(m,"clearcoatNormalMap"),"clearcoatNormalScale"in m?(l[n++]=m.clearcoatNormalScale.x,l[n++]=m.clearcoatNormalScale.y):(l[n++]=1,l[n++]=1),n++,l[n++]=s(m,"sheen",0),"sheenColor"in m?(l[n++]=m.sheenColor.r,l[n++]=m.sheenColor.g,l[n++]=m.sheenColor.b):(l[n++]=0,l[n++]=0,l[n++]=0),l[n++]=i(m,"sheenColorMap"),l[n++]=s(m,"sheenRoughness",0),l[n++]=i(m,"sheenRoughnessMap"),l[n++]=i(m,"iridescenceMap"),l[n++]=i(m,"iridescenceThicknessMap"),l[n++]=s(m,"iridescence",0),l[n++]=s(m,"iridescenceIOR",1.3);const v=s(m,"iridescenceThicknessRange",[100,400]);l[n++]=v[0],l[n++]=v[1],"specularColor"in m?(l[n++]=m.specularColor.r,l[n++]=m.specularColor.g,l[n++]=m.specularColor.b):(l[n++]=1,l[n++]=1,l[n++]=1),l[n++]=i(m,"specularColorMap"),l[n++]=s(m,"specularIntensity",1),l[n++]=i(m,"specularIntensityMap");const _=s(m,"thickness",0)===0&&s(m,"attenuationDistance",1/0)===1/0;if(l[n++]=Number(_),n++,"attenuationColor"in m?(l[n++]=m.attenuationColor.r,l[n++]=m.attenuationColor.g,l[n++]=m.attenuationColor.b):(l[n++]=1,l[n++]=1,l[n++]=1),l[n++]=s(m,"attenuationDistance",1/0),l[n++]=i(m,"alphaMap"),l[n++]=m.opacity,l[n++]=m.alphaTest,!_&&m.transmission>0)l[n++]=0;else switch(m.side){case d.FrontSide:l[n++]=1;break;case d.BackSide:l[n++]=-1;break;case d.DoubleSide:l[n++]=0;break}l[n++]=Number(s(m,"matte",!1)),l[n++]=Number(s(m,"castShadow",!0)),l[n++]=Number(m.vertexColors)|Number(m.flatShading)<<1,l[n++]=Number(m.transparent),n+=a(m,"map",l,n),n+=a(m,"metalnessMap",l,n),n+=a(m,"roughnessMap",l,n),n+=a(m,"transmissionMap",l,n),n+=a(m,"emissiveMap",l,n),n+=a(m,"normalMap",l,n),n+=a(m,"clearcoatMap",l,n),n+=a(m,"clearcoatNormalMap",l,n),n+=a(m,"clearcoatRoughnessMap",l,n),n+=a(m,"sheenColorMap",l,n),n+=a(m,"sheenRoughnessMap",l,n),n+=a(m,"iridescenceMap",l,n),n+=a(m,"iridescenceThicknessMap",l,n),n+=a(m,"specularColorMap",l,n),n+=a(m,"specularIntensityMap",l,n)}const u=as(l.buffer);return this.hash!==u?(this.hash=u,this.needsUpdate=!0,!0):!1}}const Bs=new d.Color;function ao(o){return o?`${o.uuid}:${o.version}`:null}function lo(o,e){for(const t in e)t in o&&(o[t]=e[t])}class ks extends d.WebGLArrayRenderTarget{constructor(e,t,i){const s={format:d.RGBAFormat,type:d.UnsignedByteType,minFilter:d.LinearFilter,magFilter:d.LinearFilter,wrapS:d.RepeatWrapping,wrapT:d.RepeatWrapping,generateMipmaps:!1,...i};super(e,t,1,s),lo(this.texture,s),this.texture.setTextures=(...n)=>{this.setTextures(...n)},this.hashes=[null];const a=new ut.FullScreenQuad(new co);this.fsQuad=a}setTextures(e,t,i=this.width,s=this.height){const a=e.getRenderTarget(),n=e.toneMapping,c=e.getClearAlpha();e.getClearColor(Bs);const h=t.length||1;(i!==this.width||s!==this.height||this.depth!==h)&&(this.setSize(i,s,h),this.hashes=new Array(h).fill(null)),e.setClearColor(0,0),e.toneMapping=d.NoToneMapping;const f=this.fsQuad,p=this.hashes;let r=!1;for(let l=0,u=h;l<u;l++){const g=t[l],y=ao(g);g&&(p[l]!==y||g.isWebGLRenderTarget)&&(g.matrixAutoUpdate=!1,g.matrix.identity(),f.material.map=g,e.setRenderTarget(this,l),f.render(e),g.updateMatrix(),g.matrixAutoUpdate=!0,p[l]=y,r=!0)}return f.material.map=null,e.setClearColor(Bs,c),e.setRenderTarget(a),e.toneMapping=n,r}dispose(){super.dispose(),this.fsQuad.dispose()}}class co extends d.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}constructor(){super({uniforms:{map:{value:null}},vertexShader:`
257
+ `})}}class io{generate(e,t=256){const i=new f.WebGLRenderTarget(t,t,{type:f.FloatType,format:f.RGBAFormat,minFilter:f.NearestFilter,magFilter:f.NearestFilter,generateMipmaps:!1}),s=e.getRenderTarget();e.setRenderTarget(i);const r=new _t.FullScreenQuad(new to);return r.material.resolution.set(t,t),r.render(e),e.setRenderTarget(s),r.dispose(),i}}class so extends f.PerspectiveCamera{set bokehSize(e){this.fStop=this.getFocalLength()/e}get bokehSize(){return this.getFocalLength()/this.fStop}constructor(...e){super(...e),this.fStop=1.4,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=25,this.anamorphicRatio=1}copy(e,t){return super.copy(e,t),this.fStop=e.fStop,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio,this}}class ro{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof so?(this.bokehSize=e.bokehSize,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio):(this.bokehSize=0,this.apertureRotation=0,this.apertureBlades=0,this.focusDistance=10,this.anamorphicRatio=1)}}function Ri(a){const e=new Uint16Array(a.length);for(let t=0,i=a.length;t<i;++t)e[t]=f.DataUtils.toHalfFloat(a[t]);return e}function Hs(a,e,t=0,i=a.length){let s=t,r=t+i-1;for(;s<r;){const o=s+r>>1;a[o]<e?s=o+1:r=o}return s-t}function no(a,e,t){return .2126*a+.7152*e+.0722*t}function oo(a,e=f.HalfFloatType){const t=a.clone();t.source=new f.Source({...t.image});const{width:i,height:s,data:r}=t.image;let o=r;if(t.type!==e){e===f.HalfFloatType?o=new Uint16Array(r.length):o=new Float32Array(r.length);let c;r instanceof Int8Array||r instanceof Int16Array||r instanceof Int32Array?c=2**(8*r.BYTES_PER_ELEMENT-1)-1:c=2**(8*r.BYTES_PER_ELEMENT)-1;for(let h=0,u=r.length;h<u;h++){let p=r[h];t.type===f.HalfFloatType&&(p=f.DataUtils.fromHalfFloat(r[h])),t.type!==f.FloatType&&t.type!==f.HalfFloatType&&(p/=c),e===f.HalfFloatType&&(o[h]=f.DataUtils.toHalfFloat(p))}t.image.data=o,t.type=e}if(t.flipY){const c=o;o=o.slice();for(let h=0;h<s;h++)for(let u=0;u<i;u++){const p=s-h-1,n=4*(h*i+u),l=4*(p*i+u);o[l+0]=c[n+0],o[l+1]=c[n+1],o[l+2]=c[n+2],o[l+3]=c[n+3]}t.flipY=!1,t.image.data=o}return t}class ao{constructor(){const e=new f.DataTexture(Ri(new Float32Array([0,0,0,0])),1,1);e.type=f.HalfFloatType,e.format=f.RGBAFormat,e.minFilter=f.LinearFilter,e.magFilter=f.LinearFilter,e.wrapS=f.RepeatWrapping,e.wrapT=f.RepeatWrapping,e.generateMipmaps=!1,e.needsUpdate=!0;const t=new f.DataTexture(Ri(new Float32Array([0,1])),1,2);t.type=f.HalfFloatType,t.format=f.RedFormat,t.minFilter=f.LinearFilter,t.magFilter=f.LinearFilter,t.generateMipmaps=!1,t.needsUpdate=!0;const i=new f.DataTexture(Ri(new Float32Array([0,0,1,1])),2,2);i.type=f.HalfFloatType,i.format=f.RedFormat,i.minFilter=f.LinearFilter,i.magFilter=f.LinearFilter,i.generateMipmaps=!1,i.needsUpdate=!0,this.map=e,this.marginalWeights=t,this.conditionalWeights=i,this.totalSum=0}dispose(){this.marginalWeights.dispose(),this.conditionalWeights.dispose(),this.map.dispose()}updateFrom(e){const t=oo(e);t.wrapS=f.RepeatWrapping,t.wrapT=f.ClampToEdgeWrapping;const{width:i,height:s,data:r}=t.image,o=new Float32Array(i*s),c=new Float32Array(i*s),h=new Float32Array(s),u=new Float32Array(s);let p=0,n=0;for(let m=0;m<s;m++){let _=0;for(let y=0;y<i;y++){const w=m*i+y,x=f.DataUtils.fromHalfFloat(r[4*w+0]),b=f.DataUtils.fromHalfFloat(r[4*w+1]),T=f.DataUtils.fromHalfFloat(r[4*w+2]),M=no(x,b,T);_+=M,p+=M,o[w]=M,c[w]=_}if(_!==0)for(let y=m*i,w=m*i+i;y<w;y++)o[y]/=_,c[y]/=_;n+=_,h[m]=_,u[m]=n}if(n!==0)for(let m=0,_=h.length;m<_;m++)h[m]/=n,u[m]/=n;const l=new Uint16Array(s),d=new Uint16Array(i*s);for(let m=0;m<s;m++){const _=(m+1)/s,y=Hs(u,_);l[m]=f.DataUtils.toHalfFloat((y+.5)/s)}for(let m=0;m<s;m++)for(let _=0;_<i;_++){const y=m*i+_,w=(_+1)/i,x=Hs(c,w,m*i,i);d[y]=f.DataUtils.toHalfFloat((x+.5)/i)}this.dispose();const{marginalWeights:g,conditionalWeights:v}=this;g.image={width:s,height:1,data:l},g.needsUpdate=!0,v.image={width:i,height:s,data:d},v.needsUpdate=!0,this.totalSum=p,this.map=t}}const Ei=6,lo=0,co=1,ho=2,uo=3,fo=4,de=new f.Vector3,se=new f.Vector3,Gs=new f.Matrix4,Ke=new f.Quaternion,Ns=new f.Vector3,Xe=new f.Vector3,po=new f.Vector3(0,1,0);class mo{constructor(){const e=new f.DataTexture(new Float32Array(4),1,1);e.format=f.RGBAFormat,e.type=f.FloatType,e.wrapS=f.ClampToEdgeWrapping,e.wrapT=f.ClampToEdgeWrapping,e.generateMipmaps=!1,e.minFilter=f.NearestFilter,e.magFilter=f.NearestFilter,this.tex=e,this.count=0}updateFrom(e,t=[]){const i=this.tex,s=Math.max(e.length*Ei,1),r=Math.ceil(Math.sqrt(s));i.image.width!==r&&(i.dispose(),i.image.data=new Float32Array(r*r*4),i.image.width=r,i.image.height=r);const o=i.image.data;for(let h=0,u=e.length;h<u;h++){const p=e[h],n=h*Ei*4;let l=0;for(let g=0;g<Ei*4;g++)o[n+g]=0;p.getWorldPosition(se),o[n+l++]=se.x,o[n+l++]=se.y,o[n+l++]=se.z;let d=lo;if(p.isRectAreaLight&&p.isCircular?d=co:p.isSpotLight?d=ho:p.isDirectionalLight?d=uo:p.isPointLight&&(d=fo),o[n+l++]=d,o[n+l++]=p.color.r,o[n+l++]=p.color.g,o[n+l++]=p.color.b,o[n+l++]=p.intensity,p.getWorldQuaternion(Ke),p.isRectAreaLight)de.set(p.width,0,0).applyQuaternion(Ke),o[n+l++]=de.x,o[n+l++]=de.y,o[n+l++]=de.z,l++,se.set(0,p.height,0).applyQuaternion(Ke),o[n+l++]=se.x,o[n+l++]=se.y,o[n+l++]=se.z,o[n+l++]=de.cross(se).length()*(p.isCircular?Math.PI/4:1);else if(p.isSpotLight){const g=p.radius||0;Ns.setFromMatrixPosition(p.matrixWorld),Xe.setFromMatrixPosition(p.target.matrixWorld),Gs.lookAt(Ns,Xe,po),Ke.setFromRotationMatrix(Gs),de.set(1,0,0).applyQuaternion(Ke),o[n+l++]=de.x,o[n+l++]=de.y,o[n+l++]=de.z,l++,se.set(0,1,0).applyQuaternion(Ke),o[n+l++]=se.x,o[n+l++]=se.y,o[n+l++]=se.z,o[n+l++]=Math.PI*g*g,o[n+l++]=g,o[n+l++]=p.decay,o[n+l++]=p.distance,o[n+l++]=Math.cos(p.angle),o[n+l++]=Math.cos(p.angle*(1-p.penumbra)),o[n+l++]=p.iesMap?t.indexOf(p.iesMap):-1}else if(p.isPointLight){const g=de.setFromMatrixPosition(p.matrixWorld);o[n+l++]=g.x,o[n+l++]=g.y,o[n+l++]=g.z,l++,l+=4,l+=1,o[n+l++]=p.decay,o[n+l++]=p.distance}else if(p.isDirectionalLight){const g=de.setFromMatrixPosition(p.matrixWorld),v=se.setFromMatrixPosition(p.target.matrixWorld);Xe.subVectors(g,v).normalize(),o[n+l++]=Xe.x,o[n+l++]=Xe.y,o[n+l++]=Xe.z}}this.count=e.length;const c=bs(o.buffer);return this.hash!==c?(this.hash=c,i.needsUpdate=!0,!0):!1}}function Qs(a,e,t,i,s){if(e>i)throw new Error;const r=a.length/e,o=a.constructor.BYTES_PER_ELEMENT*8;let c=1;switch(a.constructor){case Uint8Array:case Uint16Array:case Uint32Array:c=2**o-1;break;case Int8Array:case Int16Array:case Int32Array:c=2**(o-1)-1;break}for(let h=0;h<r;h++){const u=4*h,p=e*h;for(let n=0;n<i;n++)t[s+u+n]=e>=n+1?a[p+n]/c:0}}class go extends f.DataArrayTexture{constructor(){super(),this._textures=[],this.type=f.FloatType,this.format=f.RGBAFormat,this.internalFormat="RGBA32F"}updateAttribute(e,t){const i=this._textures[e];i.updateFrom(t);const s=i.image,r=this.image;if(s.width!==r.width||s.height!==r.height)throw new Error("FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.");const{width:o,height:c,data:h}=r,p=o*c*4*e;let n=t.itemSize;n===3&&(n=4),Qs(i.image.data,n,h,4,p),this.dispose(),this.needsUpdate=!0}setAttributes(e){const t=e[0].count,i=e.length;for(let n=0,l=i;n<l;n++)if(e[n].count!==t)throw new Error("FloatAttributeTextureArray: All attributes must have the same item count.");const s=this._textures;for(;s.length<i;){const n=new Be.FloatVertexAttributeTexture;s.push(n)}for(;s.length>i;)s.pop();for(let n=0,l=i;n<l;n++)s[n].updateFrom(e[n]);const o=s[0].image,c=this.image;(o.width!==c.width||o.height!==c.height||o.depth!==i)&&(c.width=o.width,c.height=o.height,c.depth=i,c.data=new Float32Array(c.width*c.height*c.depth*4));const{data:h,width:u,height:p}=c;for(let n=0,l=i;n<l;n++){const d=s[n],v=u*p*4*n;let m=e[n].itemSize;m===3&&(m=4),Qs(d.image.data,m,h,4,v)}this.dispose(),this.needsUpdate=!0}}class _o extends go{updateNormalAttribute(e){this.updateAttribute(0,e)}updateTangentAttribute(e){this.updateAttribute(1,e)}updateUvAttribute(e){this.updateAttribute(2,e)}updateColorAttribute(e){this.updateAttribute(3,e)}updateFrom(e,t,i,s){this.setAttributes([e,t,i,s])}}function Ts(a,e){return a.uuid<e.uuid?1:a.uuid>e.uuid?-1:0}function ts(a){return`${a.source.uuid}:${a.colorSpace}`}function vo(a){const e=new Set,t=[];for(let i=0,s=a.length;i<s;i++){const r=a[i],o=ts(r);e.has(o)||(e.add(o),t.push(r))}return t}function yo(a){const e=a.map(i=>i.iesMap||null).filter(i=>i),t=new Set(e);return Array.from(t).sort(Ts)}function xo(a){const e=new Set;for(let i=0,s=a.length;i<s;i++){const r=a[i];for(const o in r){const c=r[o];c&&c.isTexture&&e.add(c)}}const t=Array.from(e);return vo(t).sort(Ts)}function wo(a){const e=[];return a.traverse(t=>{t.visible&&(t.isRectAreaLight||t.isSpotLight||t.isPointLight||t.isDirectionalLight)&&e.push(t)}),e.sort(Ts)}const Vr=45,js=Vr*4;class bo{constructor(){this._features={}}isUsed(e){return e in this._features}setUsed(e,t=!0){t===!1?delete this._features[e]:this._features[e]=!0}reset(){this._features={}}}class Ao extends f.DataTexture{constructor(){super(new Float32Array(4),1,1),this.format=f.RGBAFormat,this.type=f.FloatType,this.wrapS=f.ClampToEdgeWrapping,this.wrapT=f.ClampToEdgeWrapping,this.minFilter=f.NearestFilter,this.magFilter=f.NearestFilter,this.generateMipmaps=!1,this.features=new bo}updateFrom(e,t){function i(g,v,m=-1){if(v in g&&g[v]){const _=ts(g[v]);return n[_]}else return m}function s(g,v,m){return v in g?g[v]:m}function r(g,v,m,_){const y=g[v]&&g[v].isTexture?g[v]:null;if(y){y.matrixAutoUpdate&&y.updateMatrix();const w=y.matrix.elements;let x=0;m[_+x++]=w[0],m[_+x++]=w[3],m[_+x++]=w[6],x++,m[_+x++]=w[1],m[_+x++]=w[4],m[_+x++]=w[7],x++}return 8}let o=0;const c=e.length*Vr,h=Math.ceil(Math.sqrt(c))||1,{image:u,features:p}=this,n={};for(let g=0,v=t.length;g<v;g++)n[ts(t[g])]=g;u.width!==h&&(this.dispose(),u.data=new Float32Array(h*h*4),u.width=h,u.height=h);const l=u.data;p.reset();for(let g=0,v=e.length;g<v;g++){const m=e[g];if(m.isFogVolumeMaterial){p.setUsed("FOG");for(let w=0;w<js;w++)l[o+w]=0;l[o+0*4+0]=m.color.r,l[o+0*4+1]=m.color.g,l[o+0*4+2]=m.color.b,l[o+2*4+3]=s(m,"emissiveIntensity",0),l[o+3*4+0]=m.emissive.r,l[o+3*4+1]=m.emissive.g,l[o+3*4+2]=m.emissive.b,l[o+13*4+1]=m.density,l[o+13*4+3]=0,l[o+14*4+2]=4,o+=js;continue}l[o++]=m.color.r,l[o++]=m.color.g,l[o++]=m.color.b,l[o++]=i(m,"map"),l[o++]=s(m,"metalness",0),l[o++]=i(m,"metalnessMap"),l[o++]=s(m,"roughness",0),l[o++]=i(m,"roughnessMap"),l[o++]=s(m,"ior",1.5),l[o++]=s(m,"transmission",0),l[o++]=i(m,"transmissionMap"),l[o++]=s(m,"emissiveIntensity",0),"emissive"in m?(l[o++]=m.emissive.r,l[o++]=m.emissive.g,l[o++]=m.emissive.b):(l[o++]=0,l[o++]=0,l[o++]=0),l[o++]=i(m,"emissiveMap"),l[o++]=i(m,"normalMap"),"normalScale"in m?(l[o++]=m.normalScale.x,l[o++]=m.normalScale.y):(l[o++]=1,l[o++]=1),l[o++]=s(m,"clearcoat",0),l[o++]=i(m,"clearcoatMap"),l[o++]=s(m,"clearcoatRoughness",0),l[o++]=i(m,"clearcoatRoughnessMap"),l[o++]=i(m,"clearcoatNormalMap"),"clearcoatNormalScale"in m?(l[o++]=m.clearcoatNormalScale.x,l[o++]=m.clearcoatNormalScale.y):(l[o++]=1,l[o++]=1),o++,l[o++]=s(m,"sheen",0),"sheenColor"in m?(l[o++]=m.sheenColor.r,l[o++]=m.sheenColor.g,l[o++]=m.sheenColor.b):(l[o++]=0,l[o++]=0,l[o++]=0),l[o++]=i(m,"sheenColorMap"),l[o++]=s(m,"sheenRoughness",0),l[o++]=i(m,"sheenRoughnessMap"),l[o++]=i(m,"iridescenceMap"),l[o++]=i(m,"iridescenceThicknessMap"),l[o++]=s(m,"iridescence",0),l[o++]=s(m,"iridescenceIOR",1.3);const _=s(m,"iridescenceThicknessRange",[100,400]);l[o++]=_[0],l[o++]=_[1],"specularColor"in m?(l[o++]=m.specularColor.r,l[o++]=m.specularColor.g,l[o++]=m.specularColor.b):(l[o++]=1,l[o++]=1,l[o++]=1),l[o++]=i(m,"specularColorMap"),l[o++]=s(m,"specularIntensity",1),l[o++]=i(m,"specularIntensityMap");const y=s(m,"thickness",0)===0&&s(m,"attenuationDistance",1/0)===1/0;if(l[o++]=Number(y),o++,"attenuationColor"in m?(l[o++]=m.attenuationColor.r,l[o++]=m.attenuationColor.g,l[o++]=m.attenuationColor.b):(l[o++]=1,l[o++]=1,l[o++]=1),l[o++]=s(m,"attenuationDistance",1/0),l[o++]=i(m,"alphaMap"),l[o++]=m.opacity,l[o++]=m.alphaTest,!y&&m.transmission>0)l[o++]=0;else switch(m.side){case f.FrontSide:l[o++]=1;break;case f.BackSide:l[o++]=-1;break;case f.DoubleSide:l[o++]=0;break}l[o++]=Number(s(m,"matte",!1)),l[o++]=Number(s(m,"castShadow",!0)),l[o++]=Number(m.vertexColors)|Number(m.flatShading)<<1,l[o++]=Number(m.transparent),o+=r(m,"map",l,o),o+=r(m,"metalnessMap",l,o),o+=r(m,"roughnessMap",l,o),o+=r(m,"transmissionMap",l,o),o+=r(m,"emissiveMap",l,o),o+=r(m,"normalMap",l,o),o+=r(m,"clearcoatMap",l,o),o+=r(m,"clearcoatNormalMap",l,o),o+=r(m,"clearcoatRoughnessMap",l,o),o+=r(m,"sheenColorMap",l,o),o+=r(m,"sheenRoughnessMap",l,o),o+=r(m,"iridescenceMap",l,o),o+=r(m,"iridescenceThicknessMap",l,o),o+=r(m,"specularColorMap",l,o),o+=r(m,"specularIntensityMap",l,o)}const d=bs(l.buffer);return this.hash!==d?(this.hash=d,this.needsUpdate=!0,!0):!1}}const qs=new f.Color;function To(a){return a?`${a.uuid}:${a.version}`:null}function So(a,e){for(const t in e)t in a&&(a[t]=e[t])}class Ys extends f.WebGLArrayRenderTarget{constructor(e,t,i){const s={format:f.RGBAFormat,type:f.UnsignedByteType,minFilter:f.LinearFilter,magFilter:f.LinearFilter,wrapS:f.RepeatWrapping,wrapT:f.RepeatWrapping,generateMipmaps:!1,...i};super(e,t,1,s),So(this.texture,s),this.texture.setTextures=(...o)=>{this.setTextures(...o)},this.hashes=[null];const r=new _t.FullScreenQuad(new Mo);this.fsQuad=r}setTextures(e,t,i=this.width,s=this.height){const r=e.getRenderTarget(),o=e.toneMapping,c=e.getClearAlpha();e.getClearColor(qs);const h=t.length||1;(i!==this.width||s!==this.height||this.depth!==h)&&(this.setSize(i,s,h),this.hashes=new Array(h).fill(null)),e.setClearColor(0,0),e.toneMapping=f.NoToneMapping;const u=this.fsQuad,p=this.hashes;let n=!1;for(let l=0,d=h;l<d;l++){const g=t[l],v=To(g);g&&(p[l]!==v||g.isWebGLRenderTarget)&&(g.matrixAutoUpdate=!1,g.matrix.identity(),u.material.map=g,e.setRenderTarget(this,l),u.render(e),g.updateMatrix(),g.matrixAutoUpdate=!0,p[l]=v,n=!0)}return u.material.map=null,e.setClearColor(qs,c),e.setRenderTarget(r),e.toneMapping=o,n}dispose(){super.dispose(),this.fsQuad.dispose()}}class Mo extends f.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}constructor(){super({uniforms:{map:{value:null}},vertexShader:`
258
258
  varying vec2 vUv;
259
259
  void main() {
260
260
 
@@ -270,7 +270,7 @@
270
270
  gl_FragColor = texture2D( map, vUv );
271
271
 
272
272
  }
273
- `})}}function ho(o,e=Math.random()){for(let t=o.length-1;t>0;t--){const i=Math.floor(e()*(t+1)),s=o[t];o[t]=o[i],o[i]=s}return o}class uo{constructor(e,t,i=Math.random){const s=e**t,a=new Uint16Array(s);let n=s;for(let c=0;c<s;c++)a[c]=c;this.samples=new Float32Array(t),this.strataCount=e,this.reset=function(){for(let c=0;c<s;c++)a[c]=c;n=0},this.reshuffle=function(){n=0},this.next=function(){const{samples:c}=this;n>=a.length&&(ho(a,i),this.reshuffle());let h=a[n++];for(let f=0;f<t;f++)c[f]=(h%e+i())/e,h=Math.floor(h/e);return c}}}class fo{constructor(e,t,i=Math.random){let s=0;for(const h of t)s+=h;const a=new Float32Array(s),n=[];let c=0;for(const h of t){const f=new uo(e,h,i);f.samples=new Float32Array(a.buffer,c,f.samples.length),c+=f.samples.length*4,n.push(f)}this.samples=a,this.strataCount=e,this.next=function(){for(const h of n)h.next();return a},this.reshuffle=function(){for(const h of n)h.reshuffle()},this.reset=function(){for(const h of n)h.reset()}}}class po{constructor(e=0){this.m=2147483648,this.a=1103515245,this.c=12345,this.seed=e}nextInt(){return this.seed=(this.a*this.seed+this.c)%this.m,this.seed}nextFloat(){return this.nextInt()/(this.m-1)}}class mo extends d.DataTexture{constructor(e=1,t=1,i=8){super(new Float32Array(1),1,1,d.RGBAFormat,d.FloatType),this.minFilter=d.NearestFilter,this.magFilter=d.NearestFilter,this.strata=i,this.sampler=null,this.generator=new po,this.stableNoise=!1,this.random=()=>this.stableNoise?this.generator.nextFloat():Math.random(),this.init(e,t,i)}init(e=this.image.height,t=this.image.width,i=this.strata){const{image:s}=this;if(s.width===t&&s.height===e&&this.sampler!==null)return;const a=new Array(e*t).fill(4),n=new fo(i,a,this.random);s.width=t,s.height=e,s.data=n.samples,this.sampler=n,this.dispose(),this.next()}next(){this.sampler.next(),this.needsUpdate=!0}reset(){this.sampler.reset(),this.generator.seed=0}}function go(o,e=Math.random){for(let t=o.length-1;t>0;t--){const i=~~((e()-1e-6)*t),s=o[t];o[t]=o[i],o[i]=s}}function vo(o,e){o.fill(0);for(let t=0;t<e;t++)o[t]=1}class Os{constructor(e){this.count=0,this.size=-1,this.sigma=-1,this.radius=-1,this.lookupTable=null,this.score=null,this.binaryPattern=null,this.resize(e),this.setSigma(1.5)}findVoid(){const{score:e,binaryPattern:t}=this;let i=1/0,s=-1;for(let a=0,n=t.length;a<n;a++){if(t[a]!==0)continue;const c=e[a];c<i&&(i=c,s=a)}return s}findCluster(){const{score:e,binaryPattern:t}=this;let i=-1/0,s=-1;for(let a=0,n=t.length;a<n;a++){if(t[a]!==1)continue;const c=e[a];c>i&&(i=c,s=a)}return s}setSigma(e){if(e===this.sigma)return;const t=~~(Math.sqrt(10*2*e**2)+1),i=2*t+1,s=new Float32Array(i*i),a=e*e;for(let n=-t;n<=t;n++)for(let c=-t;c<=t;c++){const h=(t+c)*i+n+t,f=n*n+c*c;s[h]=Math.E**(-f/(2*a))}this.lookupTable=s,this.sigma=e,this.radius=t}resize(e){this.size!==e&&(this.size=e,this.score=new Float32Array(e*e),this.binaryPattern=new Uint8Array(e*e))}invert(){const{binaryPattern:e,score:t,size:i}=this;t.fill(0);for(let s=0,a=e.length;s<a;s++)if(e[s]===0){const n=~~(s/i),c=s-n*i;this.updateScore(c,n,1),e[s]=1}else e[s]=0}updateScore(e,t,i){const{size:s,score:a,lookupTable:n}=this,c=this.radius,h=2*c+1;for(let f=-c;f<=c;f++)for(let p=-c;p<=c;p++){const r=(c+p)*h+f+c,l=n[r];let u=e+f;u=u<0?s+u:u%s;let g=t+p;g=g<0?s+g:g%s;const y=g*s+u;a[y]+=i*l}}addPointIndex(e){this.binaryPattern[e]=1;const t=this.size,i=~~(e/t),s=e-i*t;this.updateScore(s,i,1),this.count++}removePointIndex(e){this.binaryPattern[e]=0;const t=this.size,i=~~(e/t),s=e-i*t;this.updateScore(s,i,-1),this.count--}copy(e){this.resize(e.size),this.score.set(e.score),this.binaryPattern.set(e.binaryPattern),this.setSigma(e.sigma),this.count=e.count}}class _o{constructor(){this.random=Math.random,this.sigma=1.5,this.size=64,this.majorityPointsRatio=.1,this.samples=new Os(1),this.savedSamples=new Os(1)}generate(){const{samples:e,savedSamples:t,sigma:i,majorityPointsRatio:s,size:a}=this;e.resize(a),e.setSigma(i);const n=Math.floor(a*a*s),c=e.binaryPattern;vo(c,n),go(c,this.random);for(let r=0,l=c.length;r<l;r++)c[r]===1&&e.addPointIndex(r);for(;;){const r=e.findCluster();e.removePointIndex(r);const l=e.findVoid();if(r===l){e.addPointIndex(r);break}e.addPointIndex(l)}const h=new Uint32Array(a*a);t.copy(e);let f;for(f=e.count-1;f>=0;){const r=e.findCluster();e.removePointIndex(r),h[r]=f,f--}const p=a*a;for(f=t.count;f<p/2;){const r=t.findVoid();t.addPointIndex(r),h[r]=f,f++}for(t.invert();f<p;){const r=t.findCluster();t.removePointIndex(r),h[r]=f,f++}return{data:h,maxValue:p}}}function yo(o){return o>=3?4:o}function xo(o){switch(o){case 1:return d.RedFormat;case 2:return d.RGFormat;default:return d.RGBAFormat}}class wo extends d.DataTexture{constructor(e=64,t=1){super(new Float32Array(4),1,1,d.RGBAFormat,d.FloatType),this.minFilter=d.NearestFilter,this.magFilter=d.NearestFilter,this.size=e,this.channels=t,this.update()}update(){const e=this.channels,t=this.size,i=new _o;i.channels=e,i.size=t;const s=yo(e),a=xo(s);(this.image.width!==t||a!==this.format)&&(this.image.width=t,this.image.height=t,this.image.data=new Float32Array(t**2*s),this.format=a,this.dispose());const n=this.image.data;for(let c=0,h=e;c<h;c++){const f=i.generate(),p=f.data,r=f.maxValue;for(let l=0,u=p.length;l<u;l++){const g=p[l]/r;n[l*s+c]=g}}this.needsUpdate=!0}}const bo=`
273
+ `})}}function Co(a,e=Math.random()){for(let t=a.length-1;t>0;t--){const i=Math.floor(e()*(t+1)),s=a[t];a[t]=a[i],a[i]=s}return a}class Do{constructor(e,t,i=Math.random){const s=e**t,r=new Uint16Array(s);let o=s;for(let c=0;c<s;c++)r[c]=c;this.samples=new Float32Array(t),this.strataCount=e,this.reset=function(){for(let c=0;c<s;c++)r[c]=c;o=0},this.reshuffle=function(){o=0},this.next=function(){const{samples:c}=this;o>=r.length&&(Co(r,i),this.reshuffle());let h=r[o++];for(let u=0;u<t;u++)c[u]=(h%e+i())/e,h=Math.floor(h/e);return c}}}class Lo{constructor(e,t,i=Math.random){let s=0;for(const h of t)s+=h;const r=new Float32Array(s),o=[];let c=0;for(const h of t){const u=new Do(e,h,i);u.samples=new Float32Array(r.buffer,c,u.samples.length),c+=u.samples.length*4,o.push(u)}this.samples=r,this.strataCount=e,this.next=function(){for(const h of o)h.next();return r},this.reshuffle=function(){for(const h of o)h.reshuffle()},this.reset=function(){for(const h of o)h.reset()}}}class Po{constructor(e=0){this.m=2147483648,this.a=1103515245,this.c=12345,this.seed=e}nextInt(){return this.seed=(this.a*this.seed+this.c)%this.m,this.seed}nextFloat(){return this.nextInt()/(this.m-1)}}class Io extends f.DataTexture{constructor(e=1,t=1,i=8){super(new Float32Array(1),1,1,f.RGBAFormat,f.FloatType),this.minFilter=f.NearestFilter,this.magFilter=f.NearestFilter,this.strata=i,this.sampler=null,this.generator=new Po,this.stableNoise=!1,this.random=()=>this.stableNoise?this.generator.nextFloat():Math.random(),this.init(e,t,i)}init(e=this.image.height,t=this.image.width,i=this.strata){const{image:s}=this;if(s.width===t&&s.height===e&&this.sampler!==null)return;const r=new Array(e*t).fill(4),o=new Lo(i,r,this.random);s.width=t,s.height=e,s.data=o.samples,this.sampler=o,this.dispose(),this.next()}next(){this.sampler.next(),this.needsUpdate=!0}reset(){this.sampler.reset(),this.generator.seed=0}}function Ro(a,e=Math.random){for(let t=a.length-1;t>0;t--){const i=~~((e()-1e-6)*t),s=a[t];a[t]=a[i],a[i]=s}}function Eo(a,e){a.fill(0);for(let t=0;t<e;t++)a[t]=1}class Zs{constructor(e){this.count=0,this.size=-1,this.sigma=-1,this.radius=-1,this.lookupTable=null,this.score=null,this.binaryPattern=null,this.resize(e),this.setSigma(1.5)}findVoid(){const{score:e,binaryPattern:t}=this;let i=1/0,s=-1;for(let r=0,o=t.length;r<o;r++){if(t[r]!==0)continue;const c=e[r];c<i&&(i=c,s=r)}return s}findCluster(){const{score:e,binaryPattern:t}=this;let i=-1/0,s=-1;for(let r=0,o=t.length;r<o;r++){if(t[r]!==1)continue;const c=e[r];c>i&&(i=c,s=r)}return s}setSigma(e){if(e===this.sigma)return;const t=~~(Math.sqrt(10*2*e**2)+1),i=2*t+1,s=new Float32Array(i*i),r=e*e;for(let o=-t;o<=t;o++)for(let c=-t;c<=t;c++){const h=(t+c)*i+o+t,u=o*o+c*c;s[h]=Math.E**(-u/(2*r))}this.lookupTable=s,this.sigma=e,this.radius=t}resize(e){this.size!==e&&(this.size=e,this.score=new Float32Array(e*e),this.binaryPattern=new Uint8Array(e*e))}invert(){const{binaryPattern:e,score:t,size:i}=this;t.fill(0);for(let s=0,r=e.length;s<r;s++)if(e[s]===0){const o=~~(s/i),c=s-o*i;this.updateScore(c,o,1),e[s]=1}else e[s]=0}updateScore(e,t,i){const{size:s,score:r,lookupTable:o}=this,c=this.radius,h=2*c+1;for(let u=-c;u<=c;u++)for(let p=-c;p<=c;p++){const n=(c+p)*h+u+c,l=o[n];let d=e+u;d=d<0?s+d:d%s;let g=t+p;g=g<0?s+g:g%s;const v=g*s+d;r[v]+=i*l}}addPointIndex(e){this.binaryPattern[e]=1;const t=this.size,i=~~(e/t),s=e-i*t;this.updateScore(s,i,1),this.count++}removePointIndex(e){this.binaryPattern[e]=0;const t=this.size,i=~~(e/t),s=e-i*t;this.updateScore(s,i,-1),this.count--}copy(e){this.resize(e.size),this.score.set(e.score),this.binaryPattern.set(e.binaryPattern),this.setSigma(e.sigma),this.count=e.count}}class ko{constructor(){this.random=Math.random,this.sigma=1.5,this.size=64,this.majorityPointsRatio=.1,this.samples=new Zs(1),this.savedSamples=new Zs(1)}generate(){const{samples:e,savedSamples:t,sigma:i,majorityPointsRatio:s,size:r}=this;e.resize(r),e.setSigma(i);const o=Math.floor(r*r*s),c=e.binaryPattern;Eo(c,o),Ro(c,this.random);for(let n=0,l=c.length;n<l;n++)c[n]===1&&e.addPointIndex(n);for(;;){const n=e.findCluster();e.removePointIndex(n);const l=e.findVoid();if(n===l){e.addPointIndex(n);break}e.addPointIndex(l)}const h=new Uint32Array(r*r);t.copy(e);let u;for(u=e.count-1;u>=0;){const n=e.findCluster();e.removePointIndex(n),h[n]=u,u--}const p=r*r;for(u=t.count;u<p/2;){const n=t.findVoid();t.addPointIndex(n),h[n]=u,u++}for(t.invert();u<p;){const n=t.findCluster();t.removePointIndex(n),h[n]=u,u++}return{data:h,maxValue:p}}}function Fo(a){return a>=3?4:a}function Bo(a){switch(a){case 1:return f.RedFormat;case 2:return f.RGFormat;default:return f.RGBAFormat}}class Oo extends f.DataTexture{constructor(e=64,t=1){super(new Float32Array(4),1,1,f.RGBAFormat,f.FloatType),this.minFilter=f.NearestFilter,this.magFilter=f.NearestFilter,this.size=e,this.channels=t,this.update()}update(){const e=this.channels,t=this.size,i=new ko;i.channels=e,i.size=t;const s=Fo(e),r=Bo(s);(this.image.width!==t||r!==this.format)&&(this.image.width=t,this.image.height=t,this.image.data=new Float32Array(t**2*s),this.format=r,this.dispose());const o=this.image.data;for(let c=0,h=e;c<h;c++){const u=i.generate(),p=u.data,n=u.maxValue;for(let l=0,d=p.length;l<d;l++){const g=p[l]/n;o[l*s+c]=g}}this.needsUpdate=!0}}const zo=`
274
274
 
275
275
  struct PhysicalCamera {
276
276
 
@@ -282,7 +282,7 @@
282
282
 
283
283
  };
284
284
 
285
- `,Ao=`
285
+ `,Vo=`
286
286
 
287
287
  struct EquirectHdrInfo {
288
288
 
@@ -294,7 +294,7 @@
294
294
 
295
295
  };
296
296
 
297
- `,To=`
297
+ `,Wo=`
298
298
 
299
299
  #define RECT_AREA_LIGHT_TYPE 0
300
300
  #define CIRC_AREA_LIGHT_TYPE 1
@@ -380,7 +380,7 @@
380
380
 
381
381
  }
382
382
 
383
- `,So=`
383
+ `,Uo=`
384
384
 
385
385
  struct Material {
386
386
 
@@ -587,7 +587,7 @@
587
587
 
588
588
  }
589
589
 
590
- `,Mo=`
590
+ `,Ho=`
591
591
 
592
592
  struct SurfaceRecord {
593
593
 
@@ -649,7 +649,7 @@
649
649
  vec3 color;
650
650
  };
651
651
 
652
- `,Co=`
652
+ `,Go=`
653
653
 
654
654
  // samples the the given environment map in the given direction
655
655
  vec3 sampleEquirectColor( sampler2D envMap, vec3 direction ) {
@@ -716,7 +716,7 @@
716
716
  return float( resolution.x * resolution.y ) * pdf * equirectDirectionPdf( direction );
717
717
 
718
718
  }
719
- `,Ro=`
719
+ `,No=`
720
720
 
721
721
  float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {
722
722
 
@@ -931,7 +931,7 @@
931
931
 
932
932
  }
933
933
 
934
- `,Lo=`
934
+ `,Qo=`
935
935
 
936
936
  vec3 sampleHemisphere( vec3 n, vec2 uv ) {
937
937
 
@@ -1016,7 +1016,7 @@
1016
1016
  }
1017
1017
 
1018
1018
 
1019
- `,Io=`
1019
+ `,jo=`
1020
1020
 
1021
1021
  bool totalInternalReflection( float cosTheta, float eta ) {
1022
1022
 
@@ -1119,7 +1119,7 @@
1119
1119
 
1120
1120
  }
1121
1121
 
1122
- `,Do=`
1122
+ `,qo=`
1123
1123
 
1124
1124
  // Fast arccos approximation used to remove banding artifacts caused by numerical errors in acos.
1125
1125
  // This is a cubic Lagrange interpolating polynomial for x = [-1, -1/2, 0, 1/2, 1].
@@ -1199,7 +1199,7 @@
1199
1199
 
1200
1200
  }
1201
1201
 
1202
- `,Po=`
1202
+ `,Yo=`
1203
1203
 
1204
1204
  // Finds the point where the ray intersects the plane defined by u and v and checks if this point
1205
1205
  // falls in the bounds of the rectangle on that same plane.
@@ -1260,7 +1260,7 @@
1260
1260
 
1261
1261
  }
1262
1262
 
1263
- `,Fo=`
1263
+ `,Zo=`
1264
1264
 
1265
1265
  // add texel fetch functions for texture arrays
1266
1266
  vec4 texelFetch1D( sampler2DArray tex, int layer, uint index ) {
@@ -1283,7 +1283,7 @@
1283
1283
 
1284
1284
  }
1285
1285
 
1286
- `,wr=`
1286
+ `,Wr=`
1287
1287
 
1288
1288
  // TODO: possibly this should be renamed something related to material or path tracing logic
1289
1289
 
@@ -1398,7 +1398,7 @@
1398
1398
  return x < 0.5 ? sqrt( 2.0 * x ) - 1.0 : 1.0 - sqrt( 2.0 - ( 2.0 * x ) );
1399
1399
 
1400
1400
  }
1401
- `,zs=`
1401
+ `,Ks=`
1402
1402
 
1403
1403
  // https://www.shadertoy.com/view/wltcRS
1404
1404
  uvec4 WHITE_NOISE_SEED;
@@ -1454,7 +1454,7 @@
1454
1454
  return vec4( WHITE_NOISE_SEED ) / float( 0xffffffffu );
1455
1455
 
1456
1456
  }
1457
- `,Eo=`
1457
+ `,Ko=`
1458
1458
 
1459
1459
  uniform sampler2D stratifiedTexture;
1460
1460
  uniform sampler2D stratifiedOffsetTexture;
@@ -1503,7 +1503,7 @@
1503
1503
 
1504
1504
  }
1505
1505
 
1506
- `,Bo=`
1506
+ `,Xo=`
1507
1507
 
1508
1508
  // diffuse
1509
1509
  float diffuseEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRecord surf, inout vec3 color ) {
@@ -1941,7 +1941,7 @@
1941
1941
 
1942
1942
  }
1943
1943
 
1944
- `,ko=`
1944
+ `,Jo=`
1945
1945
 
1946
1946
  // returns the hit distance given the material density
1947
1947
  float intersectFogVolume( Material material, float u ) {
@@ -1962,7 +1962,7 @@
1962
1962
 
1963
1963
  }
1964
1964
 
1965
- `,Oo=`
1965
+ `,$o=`
1966
1966
 
1967
1967
  // The GGX functions provide sampling and distribution information for normals as output so
1968
1968
  // in order to get probability of scatter direction the half vector must be computed and provided.
@@ -2063,7 +2063,7 @@
2063
2063
 
2064
2064
  }
2065
2065
 
2066
- `,zo=`
2066
+ `,ea=`
2067
2067
 
2068
2068
  // XYZ to sRGB color space
2069
2069
  const mat3 XYZ_TO_REC709 = mat3(
@@ -2197,7 +2197,7 @@
2197
2197
 
2198
2198
  }
2199
2199
 
2200
- `,Vo=`
2200
+ `,ta=`
2201
2201
 
2202
2202
  // See equation (2) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
2203
2203
  float velvetD( float cosThetaH, float roughness ) {
@@ -2294,7 +2294,7 @@
2294
2294
 
2295
2295
  }
2296
2296
 
2297
- `,Uo=`
2297
+ `,ia=`
2298
2298
 
2299
2299
  #ifndef FOG_CHECK_ITERATIONS
2300
2300
  #define FOG_CHECK_ITERATIONS 30
@@ -2355,7 +2355,7 @@ bool bvhIntersectFogVolumeHit(
2355
2355
 
2356
2356
  }
2357
2357
 
2358
- `,Wo=`
2358
+ `,sa=`
2359
2359
 
2360
2360
  // step through multiple surface hits and accumulate color attenuation based on transmissive surfaces
2361
2361
  // returns true if a solid surface was hit
@@ -2532,7 +2532,7 @@ bool bvhIntersectFogVolumeHit(
2532
2532
 
2533
2533
  }
2534
2534
 
2535
- `,Ho=`
2535
+ `,ra=`
2536
2536
 
2537
2537
  vec3 ndcToRayOrigin( vec2 coord ) {
2538
2538
 
@@ -2615,7 +2615,7 @@ bool bvhIntersectFogVolumeHit(
2615
2615
 
2616
2616
  }
2617
2617
 
2618
- `,Go=`
2618
+ `,na=`
2619
2619
 
2620
2620
  vec3 directLightContribution( vec3 worldWo, SurfaceRecord surf, RenderState state, vec3 rayOrigin ) {
2621
2621
 
@@ -2711,7 +2711,7 @@ bool bvhIntersectFogVolumeHit(
2711
2711
 
2712
2712
  }
2713
2713
 
2714
- `,No=`
2714
+ `,oa=`
2715
2715
 
2716
2716
  #define SKIP_SURFACE 0
2717
2717
  #define HIT_SURFACE 1
@@ -3033,7 +3033,7 @@ bool bvhIntersectFogVolumeHit(
3033
3033
  return HIT_SURFACE;
3034
3034
 
3035
3035
  }
3036
- `,qo=`
3036
+ `,aa=`
3037
3037
 
3038
3038
  struct Ray {
3039
3039
 
@@ -3082,7 +3082,7 @@ bool bvhIntersectFogVolumeHit(
3082
3082
 
3083
3083
  }
3084
3084
 
3085
- `,jo=`
3085
+ `,la=`
3086
3086
 
3087
3087
  #define NO_HIT 0
3088
3088
  #define SURFACE_HIT 1
@@ -3129,7 +3129,7 @@ bool bvhIntersectFogVolumeHit(
3129
3129
 
3130
3130
  }
3131
3131
 
3132
- `;class Qo extends ls{onBeforeRender(){this.setDefine("FEATURE_DOF",this.physicalCamera.bokehSize===0?0:1),this.setDefine("FEATURE_BACKGROUND_MAP",this.backgroundMap?1:0),this.setDefine("FEATURE_FOG",this.materials.features.isUsed("FOG")?1:0)}constructor(e){super({transparent:!0,depthWrite:!1,defines:{FEATURE_MIS:1,FEATURE_RUSSIAN_ROULETTE:1,FEATURE_DOF:1,FEATURE_BACKGROUND_MAP:0,FEATURE_FOG:1,RANDOM_TYPE:2,CAMERA_TYPE:0,DEBUG_MODE:0,ATTR_NORMAL:0,ATTR_TANGENT:1,ATTR_UV:2,ATTR_COLOR:3},uniforms:{resolution:{value:new d.Vector2},opacity:{value:1},bounces:{value:10},transmissiveBounces:{value:10},filterGlossyFactor:{value:0},physicalCamera:{value:new Hn},cameraWorldMatrix:{value:new d.Matrix4},invProjectionMatrix:{value:new d.Matrix4},bvh:{value:new Ie.MeshBVHUniformStruct},attributesArray:{value:new eo},materialIndexAttribute:{value:new Ie.UIntVertexAttributeTexture},materials:{value:new oo},textures:{value:new ks().texture},lights:{value:new Jn},iesProfiles:{value:new ks(360,180,{type:d.HalfFloatType,wrapS:d.ClampToEdgeWrapping,wrapT:d.ClampToEdgeWrapping}).texture},environmentIntensity:{value:1},environmentRotation:{value:new d.Matrix4},envMapInfo:{value:new qn},backgroundBlur:{value:0},backgroundMap:{value:null},backgroundAlpha:{value:1},backgroundIntensity:{value:1},backgroundRotation:{value:new d.Matrix4},seed:{value:0},sobolTexture:{value:null},stratifiedTexture:{value:new mo},stratifiedOffsetTexture:{value:new wo(64,1)}},vertexShader:`
3132
+ `;class ca extends As{onBeforeRender(){this.setDefine("FEATURE_DOF",this.physicalCamera.bokehSize===0?0:1),this.setDefine("FEATURE_BACKGROUND_MAP",this.backgroundMap?1:0),this.setDefine("FEATURE_FOG",this.materials.features.isUsed("FOG")?1:0)}constructor(e){super({transparent:!0,depthWrite:!1,defines:{FEATURE_MIS:1,FEATURE_RUSSIAN_ROULETTE:1,FEATURE_DOF:1,FEATURE_BACKGROUND_MAP:0,FEATURE_FOG:1,RANDOM_TYPE:2,CAMERA_TYPE:0,DEBUG_MODE:0,ATTR_NORMAL:0,ATTR_TANGENT:1,ATTR_UV:2,ATTR_COLOR:3},uniforms:{resolution:{value:new f.Vector2},opacity:{value:1},bounces:{value:10},transmissiveBounces:{value:10},filterGlossyFactor:{value:0},physicalCamera:{value:new ro},cameraWorldMatrix:{value:new f.Matrix4},invProjectionMatrix:{value:new f.Matrix4},bvh:{value:new Be.MeshBVHUniformStruct},attributesArray:{value:new _o},materialIndexAttribute:{value:new Be.UIntVertexAttributeTexture},materials:{value:new Ao},textures:{value:new Ys().texture},lights:{value:new mo},iesProfiles:{value:new Ys(360,180,{type:f.HalfFloatType,wrapS:f.ClampToEdgeWrapping,wrapT:f.ClampToEdgeWrapping}).texture},environmentIntensity:{value:1},environmentRotation:{value:new f.Matrix4},envMapInfo:{value:new ao},backgroundBlur:{value:0},backgroundMap:{value:null},backgroundAlpha:{value:1},backgroundIntensity:{value:1},backgroundRotation:{value:new f.Matrix4},seed:{value:0},sobolTexture:{value:null},stratifiedTexture:{value:new Io},stratifiedOffsetTexture:{value:new Oo(64,1)}},vertexShader:`
3133
3133
 
3134
3134
  varying vec2 vUv;
3135
3135
  void main() {
@@ -3153,27 +3153,27 @@ bool bvhIntersectFogVolumeHit(
3153
3153
  #include <common>
3154
3154
 
3155
3155
  // bvh intersection
3156
- ${Ie.BVHShaderGLSL.common_functions}
3157
- ${Ie.BVHShaderGLSL.bvh_struct_definitions}
3158
- ${Ie.BVHShaderGLSL.bvh_ray_functions}
3156
+ ${Be.BVHShaderGLSL.common_functions}
3157
+ ${Be.BVHShaderGLSL.bvh_struct_definitions}
3158
+ ${Be.BVHShaderGLSL.bvh_ray_functions}
3159
3159
 
3160
3160
  // uniform structs
3161
- ${bo}
3162
- ${To}
3163
- ${Ao}
3164
- ${So}
3165
- ${Mo}
3161
+ ${zo}
3162
+ ${Wo}
3163
+ ${Vo}
3164
+ ${Uo}
3165
+ ${Ho}
3166
3166
 
3167
3167
  // random
3168
3168
  #if RANDOM_TYPE == 2 // Stratified List
3169
3169
 
3170
- ${Eo}
3170
+ ${Ko}
3171
3171
 
3172
3172
  #elif RANDOM_TYPE == 1 // Sobol
3173
3173
 
3174
- ${zs}
3175
- ${yr}
3176
- ${zn}
3174
+ ${Ks}
3175
+ ${zr}
3176
+ ${eo}
3177
3177
 
3178
3178
  #define rand(v) sobol(v)
3179
3179
  #define rand2(v) sobol2(v)
@@ -3182,7 +3182,7 @@ bool bvhIntersectFogVolumeHit(
3182
3182
 
3183
3183
  #else // PCG
3184
3184
 
3185
- ${zs}
3185
+ ${Ks}
3186
3186
 
3187
3187
  // Using the sobol functions seems to break the the compiler on MacOS
3188
3188
  // - specifically the "sobolReverseBits" function.
@@ -3198,11 +3198,11 @@ bool bvhIntersectFogVolumeHit(
3198
3198
  #endif
3199
3199
 
3200
3200
  // common
3201
- ${Fo}
3202
- ${Io}
3203
- ${wr}
3204
- ${Do}
3205
- ${Po}
3201
+ ${Zo}
3202
+ ${jo}
3203
+ ${Wr}
3204
+ ${qo}
3205
+ ${Yo}
3206
3206
 
3207
3207
  // environment
3208
3208
  uniform EquirectHdrInfo envMapInfo;
@@ -3258,16 +3258,16 @@ bool bvhIntersectFogVolumeHit(
3258
3258
  float lightsDenom;
3259
3259
 
3260
3260
  // sampling
3261
- ${Lo}
3262
- ${Co}
3263
- ${Ro}
3261
+ ${Qo}
3262
+ ${Go}
3263
+ ${No}
3264
3264
 
3265
- ${Uo}
3266
- ${Oo}
3267
- ${Vo}
3268
- ${zo}
3269
- ${ko}
3270
- ${Bo}
3265
+ ${ia}
3266
+ ${$o}
3267
+ ${ta}
3268
+ ${ea}
3269
+ ${Jo}
3270
+ ${Xo}
3271
3271
 
3272
3272
  float applyFilteredGlossy( float roughness, float accumulatedRoughness ) {
3273
3273
 
@@ -3299,12 +3299,12 @@ bool bvhIntersectFogVolumeHit(
3299
3299
 
3300
3300
  }
3301
3301
 
3302
- ${qo}
3303
- ${Ho}
3304
- ${jo}
3305
- ${Wo}
3306
- ${Go}
3307
- ${No}
3302
+ ${aa}
3303
+ ${ra}
3304
+ ${la}
3305
+ ${sa}
3306
+ ${na}
3307
+ ${oa}
3308
3308
 
3309
3309
  void main() {
3310
3310
 
@@ -3596,7 +3596,7 @@ bool bvhIntersectFogVolumeHit(
3596
3596
 
3597
3597
  }
3598
3598
 
3599
- `}),this.setValues(e)}}function*Yo(){const{_renderer:o,_fsQuad:e,_blendQuad:t,_primaryTarget:i,_blendTargets:s,_sobolTarget:a,_subframe:n,alpha:c,material:h}=this,f=new d.Vector4,p=new d.Vector4,r=t.material;let[l,u]=s;for(;;){c?(r.opacity=this._opacityFactor/(this.samples+1),h.blending=d.NoBlending,h.opacity=1):(h.opacity=this._opacityFactor/(this.samples+1),h.blending=d.NormalBlending);const[g,y,m,v]=n,_=i.width,x=i.height;h.resolution.set(_*m,x*v),h.sobolTexture=a.texture,h.stratifiedTexture.init(20,h.bounces+h.transmissiveBounces+5),h.stratifiedTexture.next(),h.seed++;const w=this.tiles.x||1,b=this.tiles.y||1,T=w*b,S=Math.ceil(_*m),L=Math.ceil(x*v),C=Math.floor(g*_),D=Math.floor(y*x),R=Math.ceil(S/w),A=Math.ceil(L/b);for(let M=0;M<b;M++)for(let I=0;I<w;I++){const P=o.getRenderTarget(),E=o.autoClear,B=o.getScissorTest();o.getScissor(f),o.getViewport(p);let V=I,G=M;if(!this.stableTiles){const j=this._currentTile%(w*b);V=j%w,G=~~(j/w),this._currentTile=j+1}const H=b-G-1;i.scissor.set(C+V*R,D+H*A,Math.min(R,S-V*R),Math.min(A,L-H*A)),i.viewport.set(C,D,S,L),o.setRenderTarget(i),o.setScissorTest(!0),o.autoClear=!1,e.render(o),o.setViewport(p),o.setScissor(f),o.setScissorTest(B),o.setRenderTarget(P),o.autoClear=E,c&&(r.target1=l.texture,r.target2=i.texture,o.setRenderTarget(u),t.render(o),o.setRenderTarget(P)),this.samples+=1/T,I===w-1&&M===b-1&&(this.samples=Math.round(this.samples)),yield}[l,u]=[u,l]}}const Vs=new d.Color;class Us{get material(){return this._fsQuad.material}set material(e){this._fsQuad.material.removeEventListener("recompilation",this._compileFunction),e.addEventListener("recompilation",this._compileFunction),this._fsQuad.material=e}get target(){return this._alpha?this._blendTargets[1]:this._primaryTarget}set alpha(e){this._alpha!==e&&(e||(this._blendTargets[0].dispose(),this._blendTargets[1].dispose()),this._alpha=e,this.reset())}get alpha(){return this._alpha}get isCompiling(){return!!this._compilePromise}constructor(e){this.camera=null,this.tiles=new d.Vector2(3,3),this.stableNoise=!1,this.stableTiles=!0,this.samples=0,this._subframe=new d.Vector4(0,0,1,1),this._opacityFactor=1,this._renderer=e,this._alpha=!1,this._fsQuad=new ut.FullScreenQuad(new Qo),this._blendQuad=new ut.FullScreenQuad(new kn),this._task=null,this._currentTile=0,this._compilePromise=null,this._sobolTarget=new Un().generate(e),this._primaryTarget=new d.WebGLRenderTarget(1,1,{format:d.RGBAFormat,type:d.FloatType,magFilter:d.NearestFilter,minFilter:d.NearestFilter}),this._blendTargets=[new d.WebGLRenderTarget(1,1,{format:d.RGBAFormat,type:d.FloatType,magFilter:d.NearestFilter,minFilter:d.NearestFilter}),new d.WebGLRenderTarget(1,1,{format:d.RGBAFormat,type:d.FloatType,magFilter:d.NearestFilter,minFilter:d.NearestFilter})],this._compileFunction=()=>{const t=this.compileMaterial(this._fsQuad._mesh);t.then(()=>{this._compilePromise===t&&(this._compilePromise=null)}),this._compilePromise=t},this.material.addEventListener("recompilation",this._compileFunction)}compileMaterial(){return this._renderer.compileAsync(this._fsQuad._mesh)}setCamera(e){const{material:t}=this;t.cameraWorldMatrix.copy(e.matrixWorld),t.invProjectionMatrix.copy(e.projectionMatrixInverse),t.physicalCamera.updateFrom(e);let i=0;e.projectionMatrix.elements[15]>0&&(i=1),e.isEquirectCamera&&(i=2),t.setDefine("CAMERA_TYPE",i),this.camera=e}setSize(e,t){e=Math.ceil(e),t=Math.ceil(t),!(this._primaryTarget.width===e&&this._primaryTarget.height===t)&&(this._primaryTarget.setSize(e,t),this._blendTargets[0].setSize(e,t),this._blendTargets[1].setSize(e,t),this.reset())}getSize(e){e.x=this._primaryTarget.width,e.y=this._primaryTarget.height}dispose(){this._primaryTarget.dispose(),this._blendTargets[0].dispose(),this._blendTargets[1].dispose(),this._sobolTarget.dispose(),this._fsQuad.dispose(),this._blendQuad.dispose(),this._task=null}reset(){const{_renderer:e,_primaryTarget:t,_blendTargets:i}=this,s=e.getRenderTarget(),a=e.getClearAlpha();e.getClearColor(Vs),e.setRenderTarget(t),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(i[0]),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(i[1]),e.setClearColor(0,0),e.clearColor(),e.setClearColor(Vs,a),e.setRenderTarget(s),this.samples=0,this._task=null,this.material.stratifiedTexture.stableNoise=this.stableNoise,this.stableNoise&&(this.material.seed=0,this.material.stratifiedTexture.reset())}update(){this.material.onBeforeRender(),!this.isCompiling&&(this._task||(this._task=Yo.call(this)),this._task.next())}}const ze=new d.Vector2,Ws=new d.Vector2,Ht=new d.Spherical,Gt=new d.Color;class Ko extends d.DataTexture{constructor(e=512,t=512){super(new Float32Array(e*t*4),e,t,d.RGBAFormat,d.FloatType,d.EquirectangularReflectionMapping,d.RepeatWrapping,d.ClampToEdgeWrapping,d.LinearFilter,d.LinearFilter),this.generationCallback=null}update(){this.dispose(),this.needsUpdate=!0;const{data:e,width:t,height:i}=this.image;for(let s=0;s<t;s++)for(let a=0;a<i;a++){Ws.set(t,i),ze.set(s/t,a/i),ze.x-=.5,ze.y=1-ze.y,Ht.theta=ze.x*2*Math.PI,Ht.phi=ze.y*Math.PI,Ht.radius=1,this.generationCallback(Ht,ze,Ws,Gt);const c=4*(a*t+s);e[c+0]=Gt.r,e[c+1]=Gt.g,e[c+2]=Gt.b,e[c+3]=1}}copy(e){return super.copy(e),this.generationCallback=e.generationCallback,this}}const Hs=new d.Vector3;class Xo extends Ko{constructor(e=512){super(e,e),this.topColor=new d.Color().set(16777215),this.bottomColor=new d.Color().set(0),this.exponent=2,this.generationCallback=(t,i,s,a)=>{Hs.setFromSpherical(t);const n=Hs.y*.5+.5;a.lerpColors(this.bottomColor,this.topColor,n**this.exponent)}}copy(e){return super.copy(e),this.topColor.copy(e.topColor),this.bottomColor.copy(e.bottomColor),this}}class Zo extends d.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}get opacity(){return this.uniforms.opacity.value}set opacity(e){this.uniforms&&(this.uniforms.opacity.value=e)}constructor(e){super({uniforms:{map:{value:null},opacity:{value:1}},vertexShader:`
3599
+ `}),this.setValues(e)}}function*ha(){const{_renderer:a,_fsQuad:e,_blendQuad:t,_primaryTarget:i,_blendTargets:s,_sobolTarget:r,_subframe:o,alpha:c,material:h}=this,u=new f.Vector4,p=new f.Vector4,n=t.material;let[l,d]=s;for(;;){c?(n.opacity=this._opacityFactor/(this.samples+1),h.blending=f.NoBlending,h.opacity=1):(h.opacity=this._opacityFactor/(this.samples+1),h.blending=f.NormalBlending);const[g,v,m,_]=o,y=i.width,w=i.height;h.resolution.set(y*m,w*_),h.sobolTexture=r.texture,h.stratifiedTexture.init(20,h.bounces+h.transmissiveBounces+5),h.stratifiedTexture.next(),h.seed++;const x=this.tiles.x||1,b=this.tiles.y||1,T=x*b,M=Math.ceil(y*m),L=Math.ceil(w*_),C=Math.floor(g*y),I=Math.floor(v*w),D=Math.ceil(M/x),A=Math.ceil(L/b);for(let S=0;S<b;S++)for(let P=0;P<x;P++){const R=a.getRenderTarget(),k=a.autoClear,F=a.getScissorTest();a.getScissor(u),a.getViewport(p);let z=P,B=S;if(!this.stableTiles){const W=this._currentTile%(x*b);z=W%x,B=~~(W/x),this._currentTile=W+1}const N=b-B-1;i.scissor.set(C+z*D,I+N*A,Math.min(D,M-z*D),Math.min(A,L-N*A)),i.viewport.set(C,I,M,L),a.setRenderTarget(i),a.setScissorTest(!0),a.autoClear=!1,e.render(a),a.setViewport(p),a.setScissor(u),a.setScissorTest(F),a.setRenderTarget(R),a.autoClear=k,c&&(n.target1=l.texture,n.target2=i.texture,a.setRenderTarget(d),t.render(a),a.setRenderTarget(R)),this.samples+=1/T,P===x-1&&S===b-1&&(this.samples=Math.round(this.samples)),yield}[l,d]=[d,l]}}const Xs=new f.Color;class Js{get material(){return this._fsQuad.material}set material(e){this._fsQuad.material.removeEventListener("recompilation",this._compileFunction),e.addEventListener("recompilation",this._compileFunction),this._fsQuad.material=e}get target(){return this._alpha?this._blendTargets[1]:this._primaryTarget}set alpha(e){this._alpha!==e&&(e||(this._blendTargets[0].dispose(),this._blendTargets[1].dispose()),this._alpha=e,this.reset())}get alpha(){return this._alpha}get isCompiling(){return!!this._compilePromise}constructor(e){this.camera=null,this.tiles=new f.Vector2(3,3),this.stableNoise=!1,this.stableTiles=!0,this.samples=0,this._subframe=new f.Vector4(0,0,1,1),this._opacityFactor=1,this._renderer=e,this._alpha=!1,this._fsQuad=new _t.FullScreenQuad(new ca),this._blendQuad=new _t.FullScreenQuad(new Jn),this._task=null,this._currentTile=0,this._compilePromise=null,this._sobolTarget=new io().generate(e),this._primaryTarget=new f.WebGLRenderTarget(1,1,{format:f.RGBAFormat,type:f.FloatType,magFilter:f.NearestFilter,minFilter:f.NearestFilter}),this._blendTargets=[new f.WebGLRenderTarget(1,1,{format:f.RGBAFormat,type:f.FloatType,magFilter:f.NearestFilter,minFilter:f.NearestFilter}),new f.WebGLRenderTarget(1,1,{format:f.RGBAFormat,type:f.FloatType,magFilter:f.NearestFilter,minFilter:f.NearestFilter})],this._compileFunction=()=>{const t=this.compileMaterial(this._fsQuad._mesh);t.then(()=>{this._compilePromise===t&&(this._compilePromise=null)}),this._compilePromise=t},this.material.addEventListener("recompilation",this._compileFunction)}compileMaterial(){return this._renderer.compileAsync(this._fsQuad._mesh)}setCamera(e){const{material:t}=this;t.cameraWorldMatrix.copy(e.matrixWorld),t.invProjectionMatrix.copy(e.projectionMatrixInverse),t.physicalCamera.updateFrom(e);let i=0;e.projectionMatrix.elements[15]>0&&(i=1),e.isEquirectCamera&&(i=2),t.setDefine("CAMERA_TYPE",i),this.camera=e}setSize(e,t){e=Math.ceil(e),t=Math.ceil(t),!(this._primaryTarget.width===e&&this._primaryTarget.height===t)&&(this._primaryTarget.setSize(e,t),this._blendTargets[0].setSize(e,t),this._blendTargets[1].setSize(e,t),this.reset())}getSize(e){e.x=this._primaryTarget.width,e.y=this._primaryTarget.height}dispose(){this._primaryTarget.dispose(),this._blendTargets[0].dispose(),this._blendTargets[1].dispose(),this._sobolTarget.dispose(),this._fsQuad.dispose(),this._blendQuad.dispose(),this._task=null}reset(){const{_renderer:e,_primaryTarget:t,_blendTargets:i}=this,s=e.getRenderTarget(),r=e.getClearAlpha();e.getClearColor(Xs),e.setRenderTarget(t),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(i[0]),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(i[1]),e.setClearColor(0,0),e.clearColor(),e.setClearColor(Xs,r),e.setRenderTarget(s),this.samples=0,this._task=null,this.material.stratifiedTexture.stableNoise=this.stableNoise,this.stableNoise&&(this.material.seed=0,this.material.stratifiedTexture.reset())}update(){this.material.onBeforeRender(),!this.isCompiling&&(this._task||(this._task=ha.call(this)),this._task.next())}}const Ge=new f.Vector2,$s=new f.Vector2,Xt=new f.Spherical,Jt=new f.Color;class ua extends f.DataTexture{constructor(e=512,t=512){super(new Float32Array(e*t*4),e,t,f.RGBAFormat,f.FloatType,f.EquirectangularReflectionMapping,f.RepeatWrapping,f.ClampToEdgeWrapping,f.LinearFilter,f.LinearFilter),this.generationCallback=null}update(){this.dispose(),this.needsUpdate=!0;const{data:e,width:t,height:i}=this.image;for(let s=0;s<t;s++)for(let r=0;r<i;r++){$s.set(t,i),Ge.set(s/t,r/i),Ge.x-=.5,Ge.y=1-Ge.y,Xt.theta=Ge.x*2*Math.PI,Xt.phi=Ge.y*Math.PI,Xt.radius=1,this.generationCallback(Xt,Ge,$s,Jt);const c=4*(r*t+s);e[c+0]=Jt.r,e[c+1]=Jt.g,e[c+2]=Jt.b,e[c+3]=1}}copy(e){return super.copy(e),this.generationCallback=e.generationCallback,this}}const er=new f.Vector3;class fa extends ua{constructor(e=512){super(e,e),this.topColor=new f.Color().set(16777215),this.bottomColor=new f.Color().set(0),this.exponent=2,this.generationCallback=(t,i,s,r)=>{er.setFromSpherical(t);const o=er.y*.5+.5;r.lerpColors(this.bottomColor,this.topColor,o**this.exponent)}}copy(e){return super.copy(e),this.topColor.copy(e.topColor),this.bottomColor.copy(e.bottomColor),this}}class da extends f.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}get opacity(){return this.uniforms.opacity.value}set opacity(e){this.uniforms&&(this.uniforms.opacity.value=e)}constructor(e){super({uniforms:{map:{value:null},opacity:{value:1}},vertexShader:`
3600
3600
  varying vec2 vUv;
3601
3601
  void main() {
3602
3602
 
@@ -3653,7 +3653,7 @@ bool bvhIntersectFogVolumeHit(
3653
3653
  #include <premultiplied_alpha_fragment>
3654
3654
 
3655
3655
  }
3656
- `}),this.setValues(e)}}class Jo extends d.ShaderMaterial{constructor(){super({uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:`
3656
+ `}),this.setValues(e)}}class pa extends f.ShaderMaterial{constructor(){super({uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:`
3657
3657
  varying vec2 vUv;
3658
3658
  void main() {
3659
3659
 
@@ -3670,7 +3670,7 @@ bool bvhIntersectFogVolumeHit(
3670
3670
  #include <common>
3671
3671
  #include <cube_uv_reflection_fragment>
3672
3672
 
3673
- ${wr}
3673
+ ${Wr}
3674
3674
 
3675
3675
  void main() {
3676
3676
 
@@ -3678,14 +3678,14 @@ bool bvhIntersectFogVolumeHit(
3678
3678
  rayDirection.x *= flipEnvMap;
3679
3679
  gl_FragColor = textureCube( envMap, rayDirection );
3680
3680
 
3681
- }`}),this.depthWrite=!1,this.depthTest=!1}}class Gs{constructor(e){this._renderer=e,this._quad=new ut.FullScreenQuad(new Jo)}generate(e,t=null,i=null){if(!e.isCubeTexture)throw new Error("CubeToEquirectMaterial: Source can only be cube textures.");const s=e.images[0],a=this._renderer,n=this._quad;t===null&&(t=4*s.height),i===null&&(i=2*s.height);const c=new d.WebGLRenderTarget(t,i,{type:d.FloatType,colorSpace:s.colorSpace}),h=s.height,f=Math.log2(h)-2,p=1/h,r=1/(3*Math.max(Math.pow(2,f),7*16));n.material.defines.CUBEUV_MAX_MIP=`${f}.0`,n.material.defines.CUBEUV_TEXEL_WIDTH=r,n.material.defines.CUBEUV_TEXEL_HEIGHT=p,n.material.uniforms.envMap.value=e,n.material.uniforms.flipEnvMap.value=e.isRenderTargetTexture?1:-1,n.material.needsUpdate=!0;const l=a.getRenderTarget(),u=a.autoClear;a.autoClear=!0,a.setRenderTarget(c),n.render(a),a.setRenderTarget(l),a.autoClear=u;const g=new Uint16Array(t*i*4),y=new Float32Array(t*i*4);a.readRenderTargetPixels(c,0,0,t,i,y),c.dispose();for(let v=0,_=y.length;v<_;v++)g[v]=d.DataUtils.toHalfFloat(y[v]);const m=new d.DataTexture(g,t,i,d.RGBAFormat,d.HalfFloatType);return m.minFilter=d.LinearMipMapLinearFilter,m.magFilter=d.LinearFilter,m.wrapS=d.RepeatWrapping,m.wrapT=d.RepeatWrapping,m.mapping=d.EquirectangularReflectionMapping,m.needsUpdate=!0,m}dispose(){this._quad.dispose()}}function $o(o){return o.extensions.get("EXT_float_blend")}const je=new d.Vector2;class ea{get multipleImportanceSampling(){return!!this._pathTracer.material.defines.FEATURE_MIS}set multipleImportanceSampling(e){this._pathTracer.material.setDefine("FEATURE_MIS",e?1:0)}get transmissiveBounces(){return this._pathTracer.material.transmissiveBounces}set transmissiveBounces(e){this._pathTracer.material.transmissiveBounces=e}get bounces(){return this._pathTracer.material.bounces}set bounces(e){this._pathTracer.material.bounces=e}get filterGlossyFactor(){return this._pathTracer.material.filterGlossyFactor}set filterGlossyFactor(e){this._pathTracer.material.filterGlossyFactor=e}get samples(){return this._pathTracer.samples}get target(){return this._pathTracer.target}get tiles(){return this._pathTracer.tiles}get stableNoise(){return this._pathTracer.stableNoise}set stableNoise(e){this._pathTracer.stableNoise=e}get isCompiling(){return!!this._pathTracer.isCompiling}constructor(e){this._renderer=e,this._generator=new Bn,this._pathTracer=new Us(e),this._queueReset=!1,this._clock=new d.Clock,this._compilePromise=null,this._lowResPathTracer=new Us(e),this._lowResPathTracer.tiles.set(1,1),this._quad=new ut.FullScreenQuad(new Zo({map:null,transparent:!0,blending:d.NoBlending,premultipliedAlpha:e.getContextAttributes().premultipliedAlpha})),this._materials=null,this._previousEnvironment=null,this._previousBackground=null,this._internalBackground=null,this.renderDelay=100,this.minSamples=5,this.fadeDuration=500,this.enablePathTracing=!0,this.pausePathTracing=!1,this.dynamicLowRes=!1,this.lowResScale=.25,this.renderScale=1,this.synchronizeRenderSize=!0,this.rasterizeScene=!0,this.renderToCanvas=!0,this.textureSize=new d.Vector2(1024,1024),this.rasterizeSceneCallback=(t,i)=>{this._renderer.render(t,i)},this.renderToCanvasCallback=(t,i,s)=>{const a=i.autoClear;i.autoClear=!1,s.render(i),i.autoClear=a},this.setScene(new d.Scene,new d.PerspectiveCamera)}setBVHWorker(e){this._generator.setBVHWorker(e)}setScene(e,t,i={}){e.updateMatrixWorld(!0),t.updateMatrixWorld();const s=this._generator;if(s.setObjects(e),this._buildAsync)return s.generateAsync(i.onProgress).then(a=>this._updateFromResults(e,t,a));{const a=s.generate();return this._updateFromResults(e,t,a)}}setSceneAsync(...e){this._buildAsync=!0;const t=this.setScene(...e);return this._buildAsync=!1,t}setCamera(e){this.camera=e,this.updateCamera()}updateCamera(){const e=this.camera;e.updateMatrixWorld(),this._pathTracer.setCamera(e),this._lowResPathTracer.setCamera(e),this.reset()}updateMaterials(){const e=this._pathTracer.material,t=this._renderer,i=this._materials,s=this.textureSize,a=so(i);e.textures.setTextures(t,a,s.x,s.y),e.materials.updateFrom(i,a),this.reset()}updateLights(){const e=this.scene,t=this._renderer,i=this._pathTracer.material,s=ro(e),a=io(s);i.lights.updateFrom(s,a),i.iesProfiles.setTextures(t,a),this.reset()}updateEnvironment(){const e=this.scene,t=this._pathTracer.material;if(this._internalBackground&&(this._internalBackground.dispose(),this._internalBackground=null),t.backgroundBlur=e.backgroundBlurriness,t.backgroundIntensity=e.backgroundIntensity??1,t.backgroundRotation.makeRotationFromEuler(e.backgroundRotation).invert(),e.background===null)t.backgroundMap=null,t.backgroundAlpha=0;else if(e.background.isColor){this._colorBackground=this._colorBackground||new Xo(16);const i=this._colorBackground;i.topColor.equals(e.background)||(i.topColor.set(e.background),i.bottomColor.set(e.background),i.update()),t.backgroundMap=i,t.backgroundAlpha=1}else if(e.background.isCubeTexture){if(e.background!==this._previousBackground){const i=new Gs(this._renderer).generate(e.background);this._internalBackground=i,t.backgroundMap=i,t.backgroundAlpha=1}}else t.backgroundMap=e.background,t.backgroundAlpha=1;if(t.environmentIntensity=e.environmentIntensity??1,t.environmentRotation.makeRotationFromEuler(e.environmentRotation).invert(),this._previousEnvironment!==e.environment)if(e.environment!==null)if(e.environment.isCubeTexture){const i=new Gs(this._renderer).generate(e.environment);t.envMapInfo.updateFrom(i)}else t.envMapInfo.updateFrom(e.environment);else t.environmentIntensity=0;this._previousEnvironment=e.environment,this._previousBackground=e.background,this.reset()}_updateFromResults(e,t,i){const{materials:s,geometry:a,bvh:n,bvhChanged:c}=i;this._materials=s;const f=this._pathTracer.material;return c&&(f.bvh.updateFrom(n),f.attributesArray.updateFrom(a.attributes.normal,a.attributes.tangent,a.attributes.uv,a.attributes.color),f.materialIndexAttribute.updateFrom(a.attributes.materialIndex)),this._previousScene=e,this.scene=e,this.camera=t,this.updateCamera(),this.updateMaterials(),this.updateEnvironment(),this.updateLights(),i}renderSample(){const e=this._lowResPathTracer,t=this._pathTracer,i=this._renderer,s=this._clock,a=this._quad;this._updateScale(),this._queueReset&&(t.reset(),e.reset(),this._queueReset=!1,a.material.opacity=0,s.start());const n=s.getDelta()*1e3,c=s.getElapsedTime()*1e3;if(!this.pausePathTracing&&this.enablePathTracing&&this.renderDelay<=c&&!this.isCompiling&&t.update(),t.alpha=t.material.backgroundAlpha!==1||!$o(i),e.alpha=t.alpha,this.renderToCanvas){const h=this._renderer,f=this.minSamples;if(c>=this.renderDelay&&this.samples>=this.minSamples&&(this.fadeDuration!==0?a.material.opacity=Math.min(a.material.opacity+n/this.fadeDuration,1):a.material.opacity=1),!this.enablePathTracing||this.samples<f||a.material.opacity<1){if(this.dynamicLowRes&&!this.isCompiling){e.samples<1&&(e.material=t.material,e.update());const p=a.material.opacity;a.material.opacity=1-a.material.opacity,a.material.map=e.target.texture,a.render(h),a.material.opacity=p}(!this.dynamicLowRes&&this.rasterizeScene||this.dynamicLowRes&&this.isCompiling)&&this.rasterizeSceneCallback(this.scene,this.camera)}this.enablePathTracing&&a.material.opacity>0&&(a.material.opacity<1&&(a.material.blending=this.dynamicLowRes?d.AdditiveBlending:d.NormalBlending),a.material.map=t.target.texture,this.renderToCanvasCallback(t.target,h,a),a.material.blending=d.NoBlending)}}reset(){this._queueReset=!0,this._pathTracer.samples=0}dispose(){this._renderQuad.dispose(),this._renderQuad.material.dispose(),this._pathTracer.dispose()}_updateScale(){if(this.synchronizeRenderSize){this._renderer.getDrawingBufferSize(je);const e=Math.floor(this.renderScale*je.x),t=Math.floor(this.renderScale*je.y);if(this._pathTracer.getSize(je),je.x!==e||je.y!==t){const i=this.lowResScale;this._pathTracer.setSize(e,t),this._lowResPathTracer.setSize(Math.floor(e*i),Math.floor(t*i))}}}}const ta="";globalThis.GLTF_PROGRESSIVE_VERSION=ta;console.debug("[gltf-progressive] version -");let br="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",ia="https://cdn.needle.tools/static/three/0.179.1/basis2/";const sa=new URL(br+"draco_decoder.js");sa.searchParams.append("range","true");const ra=()=>({dracoDecoderPath:br,ktx2TranscoderPath:ia});function Ar(o){return{dracoLoader:Sr,meshoptDecoder:Mr}}function Tr(o){o.dracoLoader||o.setDRACOLoader(Sr),o.meshoptDecoder||o.setMeshoptDecoder(Mr)}let Sr,Mr;const Hi=new WeakMap;function Cr(o,e){let t=Hi.get(o);t?t=Object.assign(t,e):t=e,Hi.set(o,t)}const Ai=os.GLTFLoader.prototype.load;function na(...o){const e=Hi.get(this);let t=o[0];const i=new URL(t,window.location.href);if(i.hostname.endsWith("needle.tools")){const a=(e==null?void 0:e.progressive)!==void 0?e.progressive:!0,n=e!=null&&e.usecase?e.usecase:"default";a?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${n}`:this.requestHeader.Accept=`*/*;usecase=${n}`,t=i.toString()}return o[0]=t,Ai==null?void 0:Ai.call(this,...o)}os.GLTFLoader.prototype.load=na;He("debugprogressive");function He(o){if(typeof window>"u")return!1;const t=new URL(window.location.href).searchParams.get(o);return t==null||t==="0"||t==="false"?!1:t===""?!0:t}function oa(o,e){if(e===void 0||o===void 0||e.startsWith("./")||e.startsWith("http")||e.startsWith("data:")||e.startsWith("blob:"))return e;const t=o.lastIndexOf("/");if(t>=0){const i=o.substring(0,t+1);for(;i.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return i+e}return e}function Rr(){return gt!==void 0||(gt=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),He("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",gt)),gt}let gt;function Ns(){if(typeof window>"u")return!1;const o=new URL(window.location.href),e=o.hostname==="localhost"||/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(o.hostname);return o.hostname==="127.0.0.1"||e}class aa{constructor(e=100,t={}){F(this,"_running",new Map);F(this,"_queue",[]);F(this,"debug",!1);F(this,"tick",()=>{this.internalUpdate(),setTimeout(this.tick,10)});this.maxConcurrent=e,this.debug=t.debug??!1,window.requestAnimationFrame(this.tick)}slot(e){return this.debug&&console.debug(`[PromiseQueue]: Requesting slot for key ${e}, running: ${this._running.size}, waiting: ${this._queue.length}`),new Promise(t=>{this._queue.push({key:e,resolve:t})})}add(e,t){this._running.has(e)||(this._running.set(e,t),t.finally(()=>{this._running.delete(e),this.debug&&console.debug(`[PromiseQueue]: Promise finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${e})`)}),this.debug&&console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${e})`))}internalUpdate(){const e=this.maxConcurrent-this._running.size;for(let t=0;t<e&&this._queue.length>0;t++){this.debug&&console.debug(`[PromiseQueue]: Running ${this._running.size} promises, waiting for ${this._queue.length} more.`);const{key:i,resolve:s}=this._queue.shift();s({use:a=>this.add(i,a)})}}}const la=typeof window>"u"&&typeof document>"u",Gi=Symbol("needle:raycast-mesh");function Bt(o){return(o==null?void 0:o[Gi])instanceof d.BufferGeometry?o[Gi]:null}function ca(o,e){if((o.type==="Mesh"||o.type==="SkinnedMesh")&&!Bt(o)){const i=ua(e);i.userData={isRaycastMesh:!0},o[Gi]=i}}function ha(o=!0){if(o){if(vt)return;const e=vt=d.Mesh.prototype.raycast;d.Mesh.prototype.raycast=function(t,i){const s=this,a=Bt(s);let n;a&&s.isMesh&&(n=s.geometry,s.geometry=a),e.call(this,t,i),n&&(s.geometry=n)}}else{if(!vt)return;d.Mesh.prototype.raycast=vt,vt=null}}let vt=null;function ua(o){const e=new d.BufferGeometry;for(const t in o.attributes)e.setAttribute(t,o.getAttribute(t));return e.setIndex(o.getIndex()),e}const Re=new Array,z=He("debugprogressive");let It,Ve=-1;if(z){let o=function(){Ve+=1,Ve>=e&&(Ve=-1),console.log(`Toggle LOD level [${Ve}]`)},e=6;window.addEventListener("keyup",t=>{t.key==="p"&&o(),t.key==="w"&&(It=!It,console.log(`Toggle wireframe [${It}]`));const i=parseInt(t.key);!isNaN(i)&&i>=0&&(Ve=i,console.log(`Set LOD level to [${Ve}]`))})}function Lr(o){if(z&&It!==void 0)if(Array.isArray(o))for(const e of o)Lr(e);else o&&"wireframe"in o&&(o.wireframe=It===!0)}const _t=new Array;let fa=0;const da=Rr()?2:10;function pa(o){if(_t.length<da){const i=_t.length;z&&console.warn(`[Worker] Creating new worker #${i}`);const s=hs.createWorker(o||{});return _t.push(s),s}const e=fa++%_t.length;return _t[e]}class hs{constructor(e,t){F(this,"_running",[]);F(this,"_webglRenderer",null);F(this,"_debug",!1);this.worker=e,this._debug=t.debug??!1,e.onmessage=i=>{const s=i.data;switch(this._debug&&console.log("[Worker] EVENT",s),s.type){case"loaded-gltf":for(const a of this._running)if(a.url===s.result.url){ma(s.result),a.resolve(s.result);const n=a.url;n.startsWith("blob:")&&URL.revokeObjectURL(n)}}},e.onerror=i=>{console.error("[Worker] Error in gltf-progressive worker:",i)},e.postMessage({type:"init"})}static async createWorker(e){const t=new Worker(new URL(""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/assets/loader.worker-46d0lFWx.js").href:new URL("assets/loader.worker-46d0lFWx.js",document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"?require("url").pathToFileURL(__filename).href:ft&&ft.src||new URL("shop-components.cjs",document.baseURI).href),{type:"module"});return new hs(t,e)}async load(e,t){const i=ra();let s=t==null?void 0:t.renderer;s||(this._webglRenderer??(this._webglRenderer=(async()=>{const{WebGLRenderer:f}=await import("three");return new f})()),s=await this._webglRenderer);const c=Ar().ktx2Loader.workerConfig;e instanceof URL?e=e.toString():e.startsWith("file:")?e=URL.createObjectURL(new Blob([e])):!e.startsWith("blob:")&&!e.startsWith("http:")&&!e.startsWith("https:")&&(e=new URL(e,window.location.href).toString());const h={type:"load",url:e,dracoDecoderPath:i.dracoDecoderPath,ktx2TranscoderPath:i.ktx2TranscoderPath,ktx2LoaderConfig:c};return this._debug&&console.debug("[Worker] Sending load request",h),this.worker.postMessage(h),new Promise(f=>{this._running.push({url:e.toString(),resolve:f})})}}function ma(o){var e,t,i,s,a,n,c,h,f,p,r,l,u,g,y,m;for(const v of o.geometries){const _=v.geometry,x=new d.BufferGeometry;if(x.name=_.name||"",_.index){const w=_.index;x.setIndex(Ti(w))}for(const w in _.attributes){const b=_.attributes[w],T=Ti(b);x.setAttribute(w,T)}if(_.morphAttributes)for(const w in _.morphAttributes){const T=_.morphAttributes[w].map(S=>Ti(S));x.morphAttributes[w]=T}if(x.morphTargetsRelative=_.morphTargetsRelative??!1,x.boundingBox=new d.Box3,x.boundingBox.min=new d.Vector3((e=_.boundingBox)==null?void 0:e.min.x,(t=_.boundingBox)==null?void 0:t.min.y,(i=_.boundingBox)==null?void 0:i.min.z),x.boundingBox.max=new d.Vector3((s=_.boundingBox)==null?void 0:s.max.x,(a=_.boundingBox)==null?void 0:a.max.y,(n=_.boundingBox)==null?void 0:n.max.z),x.boundingSphere=new d.Sphere(new d.Vector3((c=_.boundingSphere)==null?void 0:c.center.x,(h=_.boundingSphere)==null?void 0:h.center.y,(f=_.boundingSphere)==null?void 0:f.center.z),(p=_.boundingSphere)==null?void 0:p.radius),_.groups)for(const w of _.groups)x.addGroup(w.start,w.count,w.materialIndex);_.userData&&(x.userData=_.userData),v.geometry=x}for(const v of o.textures){const _=v.texture;let x=null;if(_.isCompressedTexture){const w=_.mipmaps,b=((r=_.image)==null?void 0:r.width)||((u=(l=_.source)==null?void 0:l.data)==null?void 0:u.width)||-1,T=((g=_.image)==null?void 0:g.height)||((m=(y=_.source)==null?void 0:y.data)==null?void 0:m.height)||-1;x=new d.CompressedTexture(w,b,T,_.format,_.type,_.mapping,_.wrapS,_.wrapT,_.magFilter,_.minFilter,_.anisotropy,_.colorSpace)}else x=new d.Texture(_.image,_.mapping,_.wrapS,_.wrapT,_.magFilter,_.minFilter,_.format,_.type,_.anisotropy,_.colorSpace),x.mipmaps=_.mipmaps,x.channel=_.channel,x.source.data=_.source.data,x.flipY=_.flipY,x.premultiplyAlpha=_.premultiplyAlpha,x.unpackAlignment=_.unpackAlignment,x.matrix=new d.Matrix3(..._.matrix.elements);if(!x){console.error("[Worker] Failed to create new texture from received data. Texture is not a CompressedTexture or Texture.");continue}v.texture=x}return o}function Ti(o){let e=o;if("isInterleavedBufferAttribute"in o&&o.isInterleavedBufferAttribute){const t=o.data,i=t.array,s=new d.InterleavedBuffer(i,t.stride);e=new d.InterleavedBufferAttribute(s,o.itemSize,i.byteOffset,o.normalized),e.offset=o.offset}else"isBufferAttribute"in o&&o.isBufferAttribute&&(e=new d.BufferAttribute(o.array,o.itemSize,o.normalized),e.usage=o.usage,e.gpuType=o.gpuType,e.updateRanges=o.updateRanges);return e}const ga=He("gltf-progressive-worker"),va=He("gltf-progressive-reduce-mipmaps"),Si=Symbol("needle-progressive-texture"),ye="NEEDLE_progressive",O=class O{constructor(e){F(this,"parser");F(this,"url");F(this,"_isLoadingMesh");F(this,"loadMesh",e=>{var i,s;if(this._isLoadingMesh)return null;const t=(s=(i=this.parser.json.meshes[e])==null?void 0:i.extensions)==null?void 0:s[ye];return t?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",e).then(a=>{var n;return this._isLoadingMesh=!1,a&&O.registerMesh(this.url,t.guid,a,(n=t.lods)==null?void 0:n.length,0,t),a})):null});const t=e.options.path;z&&console.log("Progressive extension registered for",t),this.parser=e,this.url=t}get name(){return ye}static getMeshLODExtension(e){const t=this.getAssignedLODInformation(e);return t!=null&&t.key?this.lodInfos.get(t.key):null}static getPrimitiveIndex(e){var i;const t=(i=this.getAssignedLODInformation(e))==null?void 0:i.index;return t??-1}static getMaterialMinMaxLODsCount(e,t){const i=this,s="LODS:minmax",a=e[s];if(a!=null)return a;if(t||(t={min_count:1/0,max_count:0,lods:[]}),Array.isArray(e)){for(const c of e)this.getMaterialMinMaxLODsCount(c,t);return e[s]=t,t}if(z==="verbose"&&console.log("getMaterialMinMaxLODsCount",e),e.type==="ShaderMaterial"||e.type==="RawShaderMaterial"){const c=e;for(const h of Object.keys(c.uniforms)){const f=c.uniforms[h].value;(f==null?void 0:f.isTexture)===!0&&n(f,t)}}else if(e.isMaterial)for(const c of Object.keys(e)){const h=e[c];(h==null?void 0:h.isTexture)===!0&&n(h,t)}else z&&console.warn(`[getMaterialMinMaxLODsCount] Unsupported material type: ${e.type}`);return e[s]=t,t;function n(c,h){const f=i.getAssignedLODInformation(c);if(f){const p=i.lodInfos.get(f.key);if(p&&p.lods){h.min_count=Math.min(h.min_count,p.lods.length),h.max_count=Math.max(h.max_count,p.lods.length);for(let r=0;r<p.lods.length;r++){const l=p.lods[r];l.width&&(h.lods[r]=h.lods[r]||{min_height:1/0,max_height:0},h.lods[r].min_height=Math.min(h.lods[r].min_height,l.height),h.lods[r].max_height=Math.max(h.lods[r].max_height,l.height))}}}}}static hasLODLevelAvailable(e,t){var a;if(Array.isArray(e)){for(const n of e)if(this.hasLODLevelAvailable(n,t))return!0;return!1}if(e.isMaterial===!0){for(const n of Object.keys(e)){const c=e[n];if(c&&c.isTexture&&this.hasLODLevelAvailable(c,t))return!0}return!1}else if(e.isGroup===!0){for(const n of e.children)if(n.isMesh===!0&&this.hasLODLevelAvailable(n,t))return!0}let i,s;if(e.isMesh?i=e.geometry:(e.isBufferGeometry||e.isTexture)&&(i=e),i&&(a=i==null?void 0:i.userData)!=null&&a.LODS){const n=i.userData.LODS;if(s=this.lodInfos.get(n.key),t===void 0)return s!=null;if(s)return Array.isArray(s.lods)?t<s.lods.length:t===0}return!1}static assignMeshLOD(e,t){var i;if(!e)return Promise.resolve(null);if(e instanceof d.Mesh||e.isMesh===!0){const s=e.geometry,a=this.getAssignedLODInformation(s);if(!a)return Promise.resolve(null);for(const n of Re)(i=n.onBeforeGetLODMesh)==null||i.call(n,e,t);return e["LOD:requested level"]=t,O.getOrLoadLOD(s,t).then(n=>{if(Array.isArray(n)){const c=a.index||0;n=n[c]}return e["LOD:requested level"]===t&&(delete e["LOD:requested level"],n&&s!=n&&((n==null?void 0:n.isBufferGeometry)?e.geometry=n:z&&console.error("Invalid LOD geometry",n))),n}).catch(n=>(console.error("Error loading mesh LOD",e,n),null))}else z&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",e);return Promise.resolve(null)}static assignTextureLOD(e,t=0){if(!e)return Promise.resolve(null);if(e.isMesh===!0){const i=e;if(Array.isArray(i.material)){const s=new Array;for(const a of i.material){const n=this.assignTextureLOD(a,t);s.push(n)}return Promise.all(s).then(a=>{const n=new Array;for(const c of a)Array.isArray(c)&&n.push(...c);return n})}else return this.assignTextureLOD(i.material,t)}if(e.isMaterial===!0){const i=e,s=[],a=new Array;if(i.uniforms&&(i.isRawShaderMaterial||i.isShaderMaterial===!0)){const n=i;for(const c of Object.keys(n.uniforms)){const h=n.uniforms[c].value;if((h==null?void 0:h.isTexture)===!0){const f=this.assignTextureLODForSlot(h,t,i,c).then(p=>(p&&n.uniforms[c].value!=p&&(n.uniforms[c].value=p,n.uniformsNeedUpdate=!0),p));s.push(f),a.push(c)}}}else for(const n of Object.keys(i)){const c=i[n];if((c==null?void 0:c.isTexture)===!0){const h=this.assignTextureLODForSlot(c,t,i,n);s.push(h),a.push(n)}}return Promise.all(s).then(n=>{const c=new Array;for(let h=0;h<n.length;h++){const f=n[h],p=a[h];f&&f.isTexture===!0?c.push({material:i,slot:p,texture:f,level:t}):c.push({material:i,slot:p,texture:null,level:t})}return c})}if(e instanceof d.Texture||e.isTexture===!0){const i=e;return this.assignTextureLODForSlot(i,t,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(e,t,i,s){return(e==null?void 0:e.isTexture)!==!0?Promise.resolve(null):s==="glyphMap"?Promise.resolve(e):O.getOrLoadLOD(e,t).then(a=>{var n,c;if(Array.isArray(a))return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."),null;if((a==null?void 0:a.isTexture)===!0){if(a!=e&&i&&s){const h=i[s];if(h&&!z){const f=this.getAssignedLODInformation(h);if(f&&(f==null?void 0:f.level)<t)return z==="verbose"&&console.warn("Assigned texture level is already higher: ",f.level,t,i,h,a),null}if(va&&a.mipmaps){const f=a.mipmaps.length;a.mipmaps.length=Math.min(a.mipmaps.length,3),f!==a.mipmaps.length&&z&&console.debug(`Reduced mipmap count from ${f} to ${a.mipmaps.length} for ${a.uuid}: ${(n=a.image)==null?void 0:n.width}x${(c=a.image)==null?void 0:c.height}.`)}i[s]=a}return a}else z=="verbose"&&console.warn("No LOD found for",e,t);return null}).catch(a=>(console.error("Error loading LOD",e,a),null))}afterRoot(e){var t,i;return z&&console.log("AFTER",this.url,e),(t=this.parser.json.textures)==null||t.forEach((s,a)=>{var n;if(s!=null&&s.extensions){const c=s==null?void 0:s.extensions[ye];if(c){if(!c.lods){z&&console.warn("Texture has no LODs",c);return}let h=!1;for(const f of this.parser.associations.keys())if(f.isTexture===!0){const p=this.parser.associations.get(f);(p==null?void 0:p.textures)===a&&(h=!0,O.registerTexture(this.url,f,(n=c.lods)==null?void 0:n.length,a,c))}h||this.parser.getDependency("texture",a).then(f=>{var p;f&&O.registerTexture(this.url,f,(p=c.lods)==null?void 0:p.length,a,c)})}}}),(i=this.parser.json.meshes)==null||i.forEach((s,a)=>{if(s!=null&&s.extensions){const n=s==null?void 0:s.extensions[ye];if(n&&n.lods){for(const c of this.parser.associations.keys())if(c.isMesh){const h=this.parser.associations.get(c);(h==null?void 0:h.meshes)===a&&O.registerMesh(this.url,n.guid,c,n.lods.length,h.primitives,n)}}}}),null}static async getOrLoadLOD(e,t){var h,f,p,r;const i=z=="verbose",s=this.getAssignedLODInformation(e);if(!s)return z&&console.warn(`[gltf-progressive] No LOD information found: ${e.name}, uuid: ${e.uuid}, type: ${e.type}`,e),null;const a=s==null?void 0:s.key;let n;if(e.isTexture===!0){const l=e;l.source&&l.source[Si]&&(n=l.source[Si])}if(n||(n=O.lodInfos.get(a)),!n)z&&console.warn(`Can not load LOD ${t}: no LOD info found for "${a}" ${e.name}`,e.type,O.lodInfos);else{if(t>0){let g=!1;const y=Array.isArray(n.lods);if(y&&t>=n.lods.length?g=!0:y||(g=!0),g)return this.lowresCache.get(a)}const l=Array.isArray(n.lods)?(h=n.lods[t])==null?void 0:h.path:n.lods;if(!l)return z&&!n["missing:uri"]&&(n["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+t,n)),null;const u=oa(s.url,l);if(u.endsWith(".glb")||u.endsWith(".gltf")){if(!n.guid)return console.warn("missing pointer for glb/gltf texture",n),null;const g=u+"_"+n.guid,y=await this.queue.slot(u),m=this.previouslyLoaded.get(g);if(m!==void 0){i&&console.log(`LOD ${t} was already loading/loaded: ${g}`);let w=await m.catch(T=>(console.error(`Error loading LOD ${t} from ${u}
3682
- `,T),null)),b=!1;if(w==null||(w instanceof d.Texture&&e instanceof d.Texture?(f=w.image)!=null&&f.data||(p=w.source)!=null&&p.data?w=this.copySettings(e,w):(b=!0,this.previouslyLoaded.delete(g)):w instanceof d.BufferGeometry&&e instanceof d.BufferGeometry&&((r=w.attributes.position)!=null&&r.array||(b=!0,this.previouslyLoaded.delete(g)))),!b)return w}if(!y.use)return z&&console.log(`LOD ${t} was aborted: ${u}`),null;const v=n,_=new Promise(async(w,b)=>{if(ga){const A=await(await pa({})).load(u);if(A.textures.length>0)for(const M of A.textures){let I=M.texture;return O.assignLODInformation(s.url,I,a,t,void 0),e instanceof d.Texture&&(I=this.copySettings(e,I)),I&&(I.guid=v.guid),w(I)}if(A.geometries.length>0){const M=new Array;for(const I of A.geometries){const P=I.geometry;O.assignLODInformation(s.url,P,a,t,I.primitiveIndex),M.push(P)}return w(M)}return w(null)}const T=new os.GLTFLoader;Tr(T),z&&(await new Promise(R=>setTimeout(R,1e3)),i&&console.warn("Start loading (delayed) "+u,v.guid));let S=u;if(v&&Array.isArray(v.lods)){const R=v.lods[t];R.hash&&(S+="?v="+R.hash)}const L=await T.loadAsync(S).catch(R=>(console.error(`Error loading LOD ${t} from ${u}
3683
- `,R),w(null)));if(!L)return w(null);const C=L.parser;i&&console.log("Loading finished "+u,v.guid);let D=0;if(L.parser.json.textures){let R=!1;for(const A of L.parser.json.textures){if(A!=null&&A.extensions){const M=A==null?void 0:A.extensions[ye];if(M!=null&&M.guid&&M.guid===v.guid){R=!0;break}}D++}if(R){let A=await C.getDependency("texture",D);return A&&O.assignLODInformation(s.url,A,a,t,void 0),i&&console.log('change "'+e.name+'" → "'+A.name+'"',u,D,A,g),e instanceof d.Texture&&(A=this.copySettings(e,A)),A&&(A.guid=v.guid),w(A)}else z&&console.warn("Could not find texture with guid",v.guid,L.parser.json)}if(D=0,L.parser.json.meshes){let R=!1;for(const A of L.parser.json.meshes){if(A!=null&&A.extensions){const M=A==null?void 0:A.extensions[ye];if(M!=null&&M.guid&&M.guid===v.guid){R=!0;break}}D++}if(R){const A=await C.getDependency("mesh",D);if(i&&console.log(`Loaded Mesh "${A.name}"`,u,D,A,g),A.isMesh===!0){const M=A.geometry;return O.assignLODInformation(s.url,M,a,t,0),w(M)}else{const M=new Array;for(let I=0;I<A.children.length;I++){const P=A.children[I];if(P.isMesh===!0){const E=P.geometry;O.assignLODInformation(s.url,E,a,t,I),M.push(E)}}return w(M)}}else z&&console.warn("Could not find mesh with guid",v.guid,L.parser.json)}return w(null)});return this.previouslyLoaded.set(g,_),y.use(_),await _}else if(e instanceof d.Texture){i&&console.log("Load texture from uri: "+u);const y=await new d.TextureLoader().loadAsync(u);return y?(y.guid=n.guid,y.flipY=!1,y.needsUpdate=!0,y.colorSpace=e.colorSpace,i&&console.log(n,y)):z&&console.warn("failed loading",u),y}}return null}static assignLODInformation(e,t,i,s,a){if(!t)return;t.userData||(t.userData={});const n=new _a(e,i,s,a);t.userData.LODS=n,"source"in t&&typeof t.source=="object"&&(t.source.LODS=n)}static getAssignedLODInformation(e){var t,i;return e?(t=e.userData)!=null&&t.LODS?e.userData.LODS:"source"in e&&((i=e.source)!=null&&i.LODS)?e.source.LODS:null:null}static copySettings(e,t){return t?(z==="verbose"&&console.debug(`Copy texture settings
3681
+ }`}),this.depthWrite=!1,this.depthTest=!1}}class tr{constructor(e){this._renderer=e,this._quad=new _t.FullScreenQuad(new pa)}generate(e,t=null,i=null){if(!e.isCubeTexture)throw new Error("CubeToEquirectMaterial: Source can only be cube textures.");const s=e.images[0],r=this._renderer,o=this._quad;t===null&&(t=4*s.height),i===null&&(i=2*s.height);const c=new f.WebGLRenderTarget(t,i,{type:f.FloatType,colorSpace:s.colorSpace}),h=s.height,u=Math.log2(h)-2,p=1/h,n=1/(3*Math.max(Math.pow(2,u),7*16));o.material.defines.CUBEUV_MAX_MIP=`${u}.0`,o.material.defines.CUBEUV_TEXEL_WIDTH=n,o.material.defines.CUBEUV_TEXEL_HEIGHT=p,o.material.uniforms.envMap.value=e,o.material.uniforms.flipEnvMap.value=e.isRenderTargetTexture?1:-1,o.material.needsUpdate=!0;const l=r.getRenderTarget(),d=r.autoClear;r.autoClear=!0,r.setRenderTarget(c),o.render(r),r.setRenderTarget(l),r.autoClear=d;const g=new Uint16Array(t*i*4),v=new Float32Array(t*i*4);r.readRenderTargetPixels(c,0,0,t,i,v),c.dispose();for(let _=0,y=v.length;_<y;_++)g[_]=f.DataUtils.toHalfFloat(v[_]);const m=new f.DataTexture(g,t,i,f.RGBAFormat,f.HalfFloatType);return m.minFilter=f.LinearMipMapLinearFilter,m.magFilter=f.LinearFilter,m.wrapS=f.RepeatWrapping,m.wrapT=f.RepeatWrapping,m.mapping=f.EquirectangularReflectionMapping,m.needsUpdate=!0,m}dispose(){this._quad.dispose()}}function ma(a){return a.extensions.get("EXT_float_blend")}const Je=new f.Vector2;class ga{get multipleImportanceSampling(){return!!this._pathTracer.material.defines.FEATURE_MIS}set multipleImportanceSampling(e){this._pathTracer.material.setDefine("FEATURE_MIS",e?1:0)}get transmissiveBounces(){return this._pathTracer.material.transmissiveBounces}set transmissiveBounces(e){this._pathTracer.material.transmissiveBounces=e}get bounces(){return this._pathTracer.material.bounces}set bounces(e){this._pathTracer.material.bounces=e}get filterGlossyFactor(){return this._pathTracer.material.filterGlossyFactor}set filterGlossyFactor(e){this._pathTracer.material.filterGlossyFactor=e}get samples(){return this._pathTracer.samples}get target(){return this._pathTracer.target}get tiles(){return this._pathTracer.tiles}get stableNoise(){return this._pathTracer.stableNoise}set stableNoise(e){this._pathTracer.stableNoise=e}get isCompiling(){return!!this._pathTracer.isCompiling}constructor(e){this._renderer=e,this._generator=new Xn,this._pathTracer=new Js(e),this._queueReset=!1,this._clock=new f.Clock,this._compilePromise=null,this._lowResPathTracer=new Js(e),this._lowResPathTracer.tiles.set(1,1),this._quad=new _t.FullScreenQuad(new da({map:null,transparent:!0,blending:f.NoBlending,premultipliedAlpha:e.getContextAttributes().premultipliedAlpha})),this._materials=null,this._previousEnvironment=null,this._previousBackground=null,this._internalBackground=null,this.renderDelay=100,this.minSamples=5,this.fadeDuration=500,this.enablePathTracing=!0,this.pausePathTracing=!1,this.dynamicLowRes=!1,this.lowResScale=.25,this.renderScale=1,this.synchronizeRenderSize=!0,this.rasterizeScene=!0,this.renderToCanvas=!0,this.textureSize=new f.Vector2(1024,1024),this.rasterizeSceneCallback=(t,i)=>{this._renderer.render(t,i)},this.renderToCanvasCallback=(t,i,s)=>{const r=i.autoClear;i.autoClear=!1,s.render(i),i.autoClear=r},this.setScene(new f.Scene,new f.PerspectiveCamera)}setBVHWorker(e){this._generator.setBVHWorker(e)}setScene(e,t,i={}){e.updateMatrixWorld(!0),t.updateMatrixWorld();const s=this._generator;if(s.setObjects(e),this._buildAsync)return s.generateAsync(i.onProgress).then(r=>this._updateFromResults(e,t,r));{const r=s.generate();return this._updateFromResults(e,t,r)}}setSceneAsync(...e){this._buildAsync=!0;const t=this.setScene(...e);return this._buildAsync=!1,t}setCamera(e){this.camera=e,this.updateCamera()}updateCamera(){const e=this.camera;e.updateMatrixWorld(),this._pathTracer.setCamera(e),this._lowResPathTracer.setCamera(e),this.reset()}updateMaterials(){const e=this._pathTracer.material,t=this._renderer,i=this._materials,s=this.textureSize,r=xo(i);e.textures.setTextures(t,r,s.x,s.y),e.materials.updateFrom(i,r),this.reset()}updateLights(){const e=this.scene,t=this._renderer,i=this._pathTracer.material,s=wo(e),r=yo(s);i.lights.updateFrom(s,r),i.iesProfiles.setTextures(t,r),this.reset()}updateEnvironment(){const e=this.scene,t=this._pathTracer.material;if(this._internalBackground&&(this._internalBackground.dispose(),this._internalBackground=null),t.backgroundBlur=e.backgroundBlurriness,t.backgroundIntensity=e.backgroundIntensity??1,t.backgroundRotation.makeRotationFromEuler(e.backgroundRotation).invert(),e.background===null)t.backgroundMap=null,t.backgroundAlpha=0;else if(e.background.isColor){this._colorBackground=this._colorBackground||new fa(16);const i=this._colorBackground;i.topColor.equals(e.background)||(i.topColor.set(e.background),i.bottomColor.set(e.background),i.update()),t.backgroundMap=i,t.backgroundAlpha=1}else if(e.background.isCubeTexture){if(e.background!==this._previousBackground){const i=new tr(this._renderer).generate(e.background);this._internalBackground=i,t.backgroundMap=i,t.backgroundAlpha=1}}else t.backgroundMap=e.background,t.backgroundAlpha=1;if(t.environmentIntensity=e.environmentIntensity??1,t.environmentRotation.makeRotationFromEuler(e.environmentRotation).invert(),this._previousEnvironment!==e.environment)if(e.environment!==null)if(e.environment.isCubeTexture){const i=new tr(this._renderer).generate(e.environment);t.envMapInfo.updateFrom(i)}else t.envMapInfo.updateFrom(e.environment);else t.environmentIntensity=0;this._previousEnvironment=e.environment,this._previousBackground=e.background,this.reset()}_updateFromResults(e,t,i){const{materials:s,geometry:r,bvh:o,bvhChanged:c}=i;this._materials=s;const u=this._pathTracer.material;return c&&(u.bvh.updateFrom(o),u.attributesArray.updateFrom(r.attributes.normal,r.attributes.tangent,r.attributes.uv,r.attributes.color),u.materialIndexAttribute.updateFrom(r.attributes.materialIndex)),this._previousScene=e,this.scene=e,this.camera=t,this.updateCamera(),this.updateMaterials(),this.updateEnvironment(),this.updateLights(),i}renderSample(){const e=this._lowResPathTracer,t=this._pathTracer,i=this._renderer,s=this._clock,r=this._quad;this._updateScale(),this._queueReset&&(t.reset(),e.reset(),this._queueReset=!1,r.material.opacity=0,s.start());const o=s.getDelta()*1e3,c=s.getElapsedTime()*1e3;if(!this.pausePathTracing&&this.enablePathTracing&&this.renderDelay<=c&&!this.isCompiling&&t.update(),t.alpha=t.material.backgroundAlpha!==1||!ma(i),e.alpha=t.alpha,this.renderToCanvas){const h=this._renderer,u=this.minSamples;if(c>=this.renderDelay&&this.samples>=this.minSamples&&(this.fadeDuration!==0?r.material.opacity=Math.min(r.material.opacity+o/this.fadeDuration,1):r.material.opacity=1),!this.enablePathTracing||this.samples<u||r.material.opacity<1){if(this.dynamicLowRes&&!this.isCompiling){e.samples<1&&(e.material=t.material,e.update());const p=r.material.opacity;r.material.opacity=1-r.material.opacity,r.material.map=e.target.texture,r.render(h),r.material.opacity=p}(!this.dynamicLowRes&&this.rasterizeScene||this.dynamicLowRes&&this.isCompiling)&&this.rasterizeSceneCallback(this.scene,this.camera)}this.enablePathTracing&&r.material.opacity>0&&(r.material.opacity<1&&(r.material.blending=this.dynamicLowRes?f.AdditiveBlending:f.NormalBlending),r.material.map=t.target.texture,this.renderToCanvasCallback(t.target,h,r),r.material.blending=f.NoBlending)}}reset(){this._queueReset=!0,this._pathTracer.samples=0}dispose(){this._renderQuad.dispose(),this._renderQuad.material.dispose(),this._pathTracer.dispose()}_updateScale(){if(this.synchronizeRenderSize){this._renderer.getDrawingBufferSize(Je);const e=Math.floor(this.renderScale*Je.x),t=Math.floor(this.renderScale*Je.y);if(this._pathTracer.getSize(Je),Je.x!==e||Je.y!==t){const i=this.lowResScale;this._pathTracer.setSize(e,t),this._lowResPathTracer.setSize(Math.floor(e*i),Math.floor(t*i))}}}}const _a="";globalThis.GLTF_PROGRESSIVE_VERSION=_a;console.debug("[gltf-progressive] version -");let Ur="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",va="https://cdn.needle.tools/static/three/0.179.1/basis2/";const ya=new URL(Ur+"draco_decoder.js");ya.searchParams.append("range","true");const xa=()=>({dracoDecoderPath:Ur,ktx2TranscoderPath:va});function Hr(a){return{dracoLoader:Nr,meshoptDecoder:Qr}}function Gr(a){a.dracoLoader||a.setDRACOLoader(Nr),a.meshoptDecoder||a.setMeshoptDecoder(Qr)}let Nr,Qr;const is=new WeakMap;function jr(a,e){let t=is.get(a);t?t=Object.assign(t,e):t=e,is.set(a,t)}const ki=ws.GLTFLoader.prototype.load;function wa(...a){const e=is.get(this);let t=a[0];const i=new URL(t,window.location.href);if(i.hostname.endsWith("needle.tools")){const r=(e==null?void 0:e.progressive)!==void 0?e.progressive:!0,o=e!=null&&e.usecase?e.usecase:"default";r?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${o}`:this.requestHeader.Accept=`*/*;usecase=${o}`,t=i.toString()}return a[0]=t,ki==null?void 0:ki.call(this,...a)}ws.GLTFLoader.prototype.load=wa;qe("debugprogressive");function qe(a){if(typeof window>"u")return!1;const t=new URL(window.location.href).searchParams.get(a);return t==null||t==="0"||t==="false"?!1:t===""?!0:t}function ba(a,e){if(e===void 0||a===void 0||e.startsWith("./")||e.startsWith("http")||e.startsWith("data:")||e.startsWith("blob:"))return e;const t=a.lastIndexOf("/");if(t>=0){const i=a.substring(0,t+1);for(;i.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return i+e}return e}function qr(){return wt!==void 0||(wt=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),qe("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",wt)),wt}let wt;function ir(){if(typeof window>"u")return!1;const a=new URL(window.location.href),e=a.hostname==="localhost"||/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(a.hostname);return a.hostname==="127.0.0.1"||e}class Aa{constructor(e=100,t={}){E(this,"_running",new Map);E(this,"_queue",[]);E(this,"debug",!1);E(this,"tick",()=>{this.internalUpdate(),setTimeout(this.tick,10)});this.maxConcurrent=e,this.debug=t.debug??!1,window.requestAnimationFrame(this.tick)}slot(e){return this.debug&&console.debug(`[PromiseQueue]: Requesting slot for key ${e}, running: ${this._running.size}, waiting: ${this._queue.length}`),new Promise(t=>{this._queue.push({key:e,resolve:t})})}add(e,t){this._running.has(e)||(this._running.set(e,t),t.finally(()=>{this._running.delete(e),this.debug&&console.debug(`[PromiseQueue]: Promise finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${e})`)}),this.debug&&console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${e})`))}internalUpdate(){const e=this.maxConcurrent-this._running.size;for(let t=0;t<e&&this._queue.length>0;t++){this.debug&&console.debug(`[PromiseQueue]: Running ${this._running.size} promises, waiting for ${this._queue.length} more.`);const{key:i,resolve:s}=this._queue.shift();s({use:r=>this.add(i,r)})}}}const Ta=typeof window>"u"&&typeof document>"u",ss=Symbol("needle:raycast-mesh");function Ht(a){return(a==null?void 0:a[ss])instanceof f.BufferGeometry?a[ss]:null}function Sa(a,e){if((a.type==="Mesh"||a.type==="SkinnedMesh")&&!Ht(a)){const i=Ca(e);i.userData={isRaycastMesh:!0},a[ss]=i}}function Ma(a=!0){if(a){if(bt)return;const e=bt=f.Mesh.prototype.raycast;f.Mesh.prototype.raycast=function(t,i){const s=this,r=Ht(s);let o;r&&s.isMesh&&(o=s.geometry,s.geometry=r),e.call(this,t,i),o&&(s.geometry=o)}}else{if(!bt)return;f.Mesh.prototype.raycast=bt,bt=null}}let bt=null;function Ca(a){const e=new f.BufferGeometry;for(const t in a.attributes)e.setAttribute(t,a.getAttribute(t));return e.setIndex(a.getIndex()),e}const ke=new Array,G=qe("debugprogressive");let Ot,Ne=-1;if(G){let a=function(){Ne+=1,Ne>=e&&(Ne=-1),console.log(`Toggle LOD level [${Ne}]`)},e=6;window.addEventListener("keyup",t=>{t.key==="p"&&a(),t.key==="w"&&(Ot=!Ot,console.log(`Toggle wireframe [${Ot}]`));const i=parseInt(t.key);!isNaN(i)&&i>=0&&(Ne=i,console.log(`Set LOD level to [${Ne}]`))})}function Yr(a){if(G&&Ot!==void 0)if(Array.isArray(a))for(const e of a)Yr(e);else a&&"wireframe"in a&&(a.wireframe=Ot===!0)}const At=new Array;let Da=0;const La=qr()?2:10;function Pa(a){if(At.length<La){const i=At.length;G&&console.warn(`[Worker] Creating new worker #${i}`);const s=Ss.createWorker(a||{});return At.push(s),s}const e=Da++%At.length;return At[e]}class Ss{constructor(e,t){E(this,"_running",[]);E(this,"_webglRenderer",null);E(this,"_debug",!1);this.worker=e,this._debug=t.debug??!1,e.onmessage=i=>{const s=i.data;switch(this._debug&&console.log("[Worker] EVENT",s),s.type){case"loaded-gltf":for(const r of this._running)if(r.url===s.result.url){Ia(s.result),r.resolve(s.result);const o=r.url;o.startsWith("blob:")&&URL.revokeObjectURL(o)}}},e.onerror=i=>{console.error("[Worker] Error in gltf-progressive worker:",i)},e.postMessage({type:"init"})}static async createWorker(e){const t=new Worker(new URL(""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/assets/loader.worker-46d0lFWx.js").href:new URL("assets/loader.worker-46d0lFWx.js",document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"?require("url").pathToFileURL(__filename).href:vt&&vt.src||new URL("shop-components.cjs",document.baseURI).href),{type:"module"});return new Ss(t,e)}async load(e,t){const i=xa();let s=t==null?void 0:t.renderer;s||(this._webglRenderer??(this._webglRenderer=(async()=>{const{WebGLRenderer:u}=await import("three");return new u})()),s=await this._webglRenderer);const c=Hr().ktx2Loader.workerConfig;e instanceof URL?e=e.toString():e.startsWith("file:")?e=URL.createObjectURL(new Blob([e])):!e.startsWith("blob:")&&!e.startsWith("http:")&&!e.startsWith("https:")&&(e=new URL(e,window.location.href).toString());const h={type:"load",url:e,dracoDecoderPath:i.dracoDecoderPath,ktx2TranscoderPath:i.ktx2TranscoderPath,ktx2LoaderConfig:c};return this._debug&&console.debug("[Worker] Sending load request",h),this.worker.postMessage(h),new Promise(u=>{this._running.push({url:e.toString(),resolve:u})})}}function Ia(a){var e,t,i,s,r,o,c,h,u,p,n,l,d,g,v,m;for(const _ of a.geometries){const y=_.geometry,w=new f.BufferGeometry;if(w.name=y.name||"",y.index){const x=y.index;w.setIndex(Fi(x))}for(const x in y.attributes){const b=y.attributes[x],T=Fi(b);w.setAttribute(x,T)}if(y.morphAttributes)for(const x in y.morphAttributes){const T=y.morphAttributes[x].map(M=>Fi(M));w.morphAttributes[x]=T}if(w.morphTargetsRelative=y.morphTargetsRelative??!1,w.boundingBox=new f.Box3,w.boundingBox.min=new f.Vector3((e=y.boundingBox)==null?void 0:e.min.x,(t=y.boundingBox)==null?void 0:t.min.y,(i=y.boundingBox)==null?void 0:i.min.z),w.boundingBox.max=new f.Vector3((s=y.boundingBox)==null?void 0:s.max.x,(r=y.boundingBox)==null?void 0:r.max.y,(o=y.boundingBox)==null?void 0:o.max.z),w.boundingSphere=new f.Sphere(new f.Vector3((c=y.boundingSphere)==null?void 0:c.center.x,(h=y.boundingSphere)==null?void 0:h.center.y,(u=y.boundingSphere)==null?void 0:u.center.z),(p=y.boundingSphere)==null?void 0:p.radius),y.groups)for(const x of y.groups)w.addGroup(x.start,x.count,x.materialIndex);y.userData&&(w.userData=y.userData),_.geometry=w}for(const _ of a.textures){const y=_.texture;let w=null;if(y.isCompressedTexture){const x=y.mipmaps,b=((n=y.image)==null?void 0:n.width)||((d=(l=y.source)==null?void 0:l.data)==null?void 0:d.width)||-1,T=((g=y.image)==null?void 0:g.height)||((m=(v=y.source)==null?void 0:v.data)==null?void 0:m.height)||-1;w=new f.CompressedTexture(x,b,T,y.format,y.type,y.mapping,y.wrapS,y.wrapT,y.magFilter,y.minFilter,y.anisotropy,y.colorSpace)}else w=new f.Texture(y.image,y.mapping,y.wrapS,y.wrapT,y.magFilter,y.minFilter,y.format,y.type,y.anisotropy,y.colorSpace),w.mipmaps=y.mipmaps,w.channel=y.channel,w.source.data=y.source.data,w.flipY=y.flipY,w.premultiplyAlpha=y.premultiplyAlpha,w.unpackAlignment=y.unpackAlignment,w.matrix=new f.Matrix3(...y.matrix.elements);if(!w){console.error("[Worker] Failed to create new texture from received data. Texture is not a CompressedTexture or Texture.");continue}_.texture=w}return a}function Fi(a){let e=a;if("isInterleavedBufferAttribute"in a&&a.isInterleavedBufferAttribute){const t=a.data,i=t.array,s=new f.InterleavedBuffer(i,t.stride);e=new f.InterleavedBufferAttribute(s,a.itemSize,i.byteOffset,a.normalized),e.offset=a.offset}else"isBufferAttribute"in a&&a.isBufferAttribute&&(e=new f.BufferAttribute(a.array,a.itemSize,a.normalized),e.usage=a.usage,e.gpuType=a.gpuType,e.updateRanges=a.updateRanges);return e}const Ra=qe("gltf-progressive-worker"),Ea=qe("gltf-progressive-reduce-mipmaps"),Bi=Symbol("needle-progressive-texture"),Se="NEEDLE_progressive",H=class H{constructor(e){E(this,"parser");E(this,"url");E(this,"_isLoadingMesh");E(this,"loadMesh",e=>{var i,s;if(this._isLoadingMesh)return null;const t=(s=(i=this.parser.json.meshes[e])==null?void 0:i.extensions)==null?void 0:s[Se];return t?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",e).then(r=>{var o;return this._isLoadingMesh=!1,r&&H.registerMesh(this.url,t.guid,r,(o=t.lods)==null?void 0:o.length,0,t),r})):null});const t=e.options.path;G&&console.log("Progressive extension registered for",t),this.parser=e,this.url=t}get name(){return Se}static getMeshLODExtension(e){const t=this.getAssignedLODInformation(e);return t!=null&&t.key?this.lodInfos.get(t.key):null}static getPrimitiveIndex(e){var i;const t=(i=this.getAssignedLODInformation(e))==null?void 0:i.index;return t??-1}static getMaterialMinMaxLODsCount(e,t){const i=this,s="LODS:minmax",r=e[s];if(r!=null)return r;if(t||(t={min_count:1/0,max_count:0,lods:[]}),Array.isArray(e)){for(const c of e)this.getMaterialMinMaxLODsCount(c,t);return e[s]=t,t}if(G==="verbose"&&console.log("getMaterialMinMaxLODsCount",e),e.type==="ShaderMaterial"||e.type==="RawShaderMaterial"){const c=e;for(const h of Object.keys(c.uniforms)){const u=c.uniforms[h].value;(u==null?void 0:u.isTexture)===!0&&o(u,t)}}else if(e.isMaterial)for(const c of Object.keys(e)){const h=e[c];(h==null?void 0:h.isTexture)===!0&&o(h,t)}else G&&console.warn(`[getMaterialMinMaxLODsCount] Unsupported material type: ${e.type}`);return e[s]=t,t;function o(c,h){const u=i.getAssignedLODInformation(c);if(u){const p=i.lodInfos.get(u.key);if(p&&p.lods){h.min_count=Math.min(h.min_count,p.lods.length),h.max_count=Math.max(h.max_count,p.lods.length);for(let n=0;n<p.lods.length;n++){const l=p.lods[n];l.width&&(h.lods[n]=h.lods[n]||{min_height:1/0,max_height:0},h.lods[n].min_height=Math.min(h.lods[n].min_height,l.height),h.lods[n].max_height=Math.max(h.lods[n].max_height,l.height))}}}}}static hasLODLevelAvailable(e,t){var r;if(Array.isArray(e)){for(const o of e)if(this.hasLODLevelAvailable(o,t))return!0;return!1}if(e.isMaterial===!0){for(const o of Object.keys(e)){const c=e[o];if(c&&c.isTexture&&this.hasLODLevelAvailable(c,t))return!0}return!1}else if(e.isGroup===!0){for(const o of e.children)if(o.isMesh===!0&&this.hasLODLevelAvailable(o,t))return!0}let i,s;if(e.isMesh?i=e.geometry:(e.isBufferGeometry||e.isTexture)&&(i=e),i&&(r=i==null?void 0:i.userData)!=null&&r.LODS){const o=i.userData.LODS;if(s=this.lodInfos.get(o.key),t===void 0)return s!=null;if(s)return Array.isArray(s.lods)?t<s.lods.length:t===0}return!1}static assignMeshLOD(e,t){var i;if(!e)return Promise.resolve(null);if(e instanceof f.Mesh||e.isMesh===!0){const s=e.geometry,r=this.getAssignedLODInformation(s);if(!r)return Promise.resolve(null);for(const o of ke)(i=o.onBeforeGetLODMesh)==null||i.call(o,e,t);return e["LOD:requested level"]=t,H.getOrLoadLOD(s,t).then(o=>{if(Array.isArray(o)){const c=r.index||0;o=o[c]}return e["LOD:requested level"]===t&&(delete e["LOD:requested level"],o&&s!=o&&((o==null?void 0:o.isBufferGeometry)?e.geometry=o:G&&console.error("Invalid LOD geometry",o))),o}).catch(o=>(console.error("Error loading mesh LOD",e,o),null))}else G&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",e);return Promise.resolve(null)}static assignTextureLOD(e,t=0){if(!e)return Promise.resolve(null);if(e.isMesh===!0){const i=e;if(Array.isArray(i.material)){const s=new Array;for(const r of i.material){const o=this.assignTextureLOD(r,t);s.push(o)}return Promise.all(s).then(r=>{const o=new Array;for(const c of r)Array.isArray(c)&&o.push(...c);return o})}else return this.assignTextureLOD(i.material,t)}if(e.isMaterial===!0){const i=e,s=[],r=new Array;if(i.uniforms&&(i.isRawShaderMaterial||i.isShaderMaterial===!0)){const o=i;for(const c of Object.keys(o.uniforms)){const h=o.uniforms[c].value;if((h==null?void 0:h.isTexture)===!0){const u=this.assignTextureLODForSlot(h,t,i,c).then(p=>(p&&o.uniforms[c].value!=p&&(o.uniforms[c].value=p,o.uniformsNeedUpdate=!0),p));s.push(u),r.push(c)}}}else for(const o of Object.keys(i)){const c=i[o];if((c==null?void 0:c.isTexture)===!0){const h=this.assignTextureLODForSlot(c,t,i,o);s.push(h),r.push(o)}}return Promise.all(s).then(o=>{const c=new Array;for(let h=0;h<o.length;h++){const u=o[h],p=r[h];u&&u.isTexture===!0?c.push({material:i,slot:p,texture:u,level:t}):c.push({material:i,slot:p,texture:null,level:t})}return c})}if(e instanceof f.Texture||e.isTexture===!0){const i=e;return this.assignTextureLODForSlot(i,t,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(e,t,i,s){return(e==null?void 0:e.isTexture)!==!0?Promise.resolve(null):s==="glyphMap"?Promise.resolve(e):H.getOrLoadLOD(e,t).then(r=>{var o,c;if(Array.isArray(r))return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."),null;if((r==null?void 0:r.isTexture)===!0){if(r!=e&&i&&s){const h=i[s];if(h&&!G){const u=this.getAssignedLODInformation(h);if(u&&(u==null?void 0:u.level)<t)return G==="verbose"&&console.warn("Assigned texture level is already higher: ",u.level,t,i,h,r),null}if(Ea&&r.mipmaps){const u=r.mipmaps.length;r.mipmaps.length=Math.min(r.mipmaps.length,3),u!==r.mipmaps.length&&G&&console.debug(`Reduced mipmap count from ${u} to ${r.mipmaps.length} for ${r.uuid}: ${(o=r.image)==null?void 0:o.width}x${(c=r.image)==null?void 0:c.height}.`)}i[s]=r}return r}else G=="verbose"&&console.warn("No LOD found for",e,t);return null}).catch(r=>(console.error("Error loading LOD",e,r),null))}afterRoot(e){var t,i;return G&&console.log("AFTER",this.url,e),(t=this.parser.json.textures)==null||t.forEach((s,r)=>{var o;if(s!=null&&s.extensions){const c=s==null?void 0:s.extensions[Se];if(c){if(!c.lods){G&&console.warn("Texture has no LODs",c);return}let h=!1;for(const u of this.parser.associations.keys())if(u.isTexture===!0){const p=this.parser.associations.get(u);(p==null?void 0:p.textures)===r&&(h=!0,H.registerTexture(this.url,u,(o=c.lods)==null?void 0:o.length,r,c))}h||this.parser.getDependency("texture",r).then(u=>{var p;u&&H.registerTexture(this.url,u,(p=c.lods)==null?void 0:p.length,r,c)})}}}),(i=this.parser.json.meshes)==null||i.forEach((s,r)=>{if(s!=null&&s.extensions){const o=s==null?void 0:s.extensions[Se];if(o&&o.lods){for(const c of this.parser.associations.keys())if(c.isMesh){const h=this.parser.associations.get(c);(h==null?void 0:h.meshes)===r&&H.registerMesh(this.url,o.guid,c,o.lods.length,h.primitives,o)}}}}),null}static async getOrLoadLOD(e,t){var h,u,p,n;const i=G=="verbose",s=this.getAssignedLODInformation(e);if(!s)return G&&console.warn(`[gltf-progressive] No LOD information found: ${e.name}, uuid: ${e.uuid}, type: ${e.type}`,e),null;const r=s==null?void 0:s.key;let o;if(e.isTexture===!0){const l=e;l.source&&l.source[Bi]&&(o=l.source[Bi])}if(o||(o=H.lodInfos.get(r)),!o)G&&console.warn(`Can not load LOD ${t}: no LOD info found for "${r}" ${e.name}`,e.type,H.lodInfos);else{if(t>0){let g=!1;const v=Array.isArray(o.lods);if(v&&t>=o.lods.length?g=!0:v||(g=!0),g)return this.lowresCache.get(r)}const l=Array.isArray(o.lods)?(h=o.lods[t])==null?void 0:h.path:o.lods;if(!l)return G&&!o["missing:uri"]&&(o["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+t,o)),null;const d=ba(s.url,l);if(d.endsWith(".glb")||d.endsWith(".gltf")){if(!o.guid)return console.warn("missing pointer for glb/gltf texture",o),null;const g=d+"_"+o.guid,v=await this.queue.slot(d),m=this.previouslyLoaded.get(g);if(m!==void 0){i&&console.log(`LOD ${t} was already loading/loaded: ${g}`);let x=await m.catch(T=>(console.error(`Error loading LOD ${t} from ${d}
3682
+ `,T),null)),b=!1;if(x==null||(x instanceof f.Texture&&e instanceof f.Texture?(u=x.image)!=null&&u.data||(p=x.source)!=null&&p.data?x=this.copySettings(e,x):(b=!0,this.previouslyLoaded.delete(g)):x instanceof f.BufferGeometry&&e instanceof f.BufferGeometry&&((n=x.attributes.position)!=null&&n.array||(b=!0,this.previouslyLoaded.delete(g)))),!b)return x}if(!v.use)return G&&console.log(`LOD ${t} was aborted: ${d}`),null;const _=o,y=new Promise(async(x,b)=>{if(Ra){const A=await(await Pa({})).load(d);if(A.textures.length>0)for(const S of A.textures){let P=S.texture;return H.assignLODInformation(s.url,P,r,t,void 0),e instanceof f.Texture&&(P=this.copySettings(e,P)),P&&(P.guid=_.guid),x(P)}if(A.geometries.length>0){const S=new Array;for(const P of A.geometries){const R=P.geometry;H.assignLODInformation(s.url,R,r,t,P.primitiveIndex),S.push(R)}return x(S)}return x(null)}const T=new ws.GLTFLoader;Gr(T),G&&(await new Promise(D=>setTimeout(D,1e3)),i&&console.warn("Start loading (delayed) "+d,_.guid));let M=d;if(_&&Array.isArray(_.lods)){const D=_.lods[t];D.hash&&(M+="?v="+D.hash)}const L=await T.loadAsync(M).catch(D=>(console.error(`Error loading LOD ${t} from ${d}
3683
+ `,D),x(null)));if(!L)return x(null);const C=L.parser;i&&console.log("Loading finished "+d,_.guid);let I=0;if(L.parser.json.textures){let D=!1;for(const A of L.parser.json.textures){if(A!=null&&A.extensions){const S=A==null?void 0:A.extensions[Se];if(S!=null&&S.guid&&S.guid===_.guid){D=!0;break}}I++}if(D){let A=await C.getDependency("texture",I);return A&&H.assignLODInformation(s.url,A,r,t,void 0),i&&console.log('change "'+e.name+'" → "'+A.name+'"',d,I,A,g),e instanceof f.Texture&&(A=this.copySettings(e,A)),A&&(A.guid=_.guid),x(A)}else G&&console.warn("Could not find texture with guid",_.guid,L.parser.json)}if(I=0,L.parser.json.meshes){let D=!1;for(const A of L.parser.json.meshes){if(A!=null&&A.extensions){const S=A==null?void 0:A.extensions[Se];if(S!=null&&S.guid&&S.guid===_.guid){D=!0;break}}I++}if(D){const A=await C.getDependency("mesh",I);if(i&&console.log(`Loaded Mesh "${A.name}"`,d,I,A,g),A.isMesh===!0){const S=A.geometry;return H.assignLODInformation(s.url,S,r,t,0),x(S)}else{const S=new Array;for(let P=0;P<A.children.length;P++){const R=A.children[P];if(R.isMesh===!0){const k=R.geometry;H.assignLODInformation(s.url,k,r,t,P),S.push(k)}}return x(S)}}else G&&console.warn("Could not find mesh with guid",_.guid,L.parser.json)}return x(null)});return this.previouslyLoaded.set(g,y),v.use(y),await y}else if(e instanceof f.Texture){i&&console.log("Load texture from uri: "+d);const v=await new f.TextureLoader().loadAsync(d);return v?(v.guid=o.guid,v.flipY=!1,v.needsUpdate=!0,v.colorSpace=e.colorSpace,i&&console.log(o,v)):G&&console.warn("failed loading",d),v}}return null}static assignLODInformation(e,t,i,s,r){if(!t)return;t.userData||(t.userData={});const o=new ka(e,i,s,r);t.userData.LODS=o,"source"in t&&typeof t.source=="object"&&(t.source.LODS=o)}static getAssignedLODInformation(e){var t,i;return e?(t=e.userData)!=null&&t.LODS?e.userData.LODS:"source"in e&&((i=e.source)!=null&&i.LODS)?e.source.LODS:null:null}static copySettings(e,t){return t?(G==="verbose"&&console.debug(`Copy texture settings
3684
3684
  `,e.uuid,`
3685
- `,t.uuid),t=t.clone(),t.offset=e.offset,t.repeat=e.repeat,t.colorSpace=e.colorSpace,t.magFilter=e.magFilter,t.minFilter=e.minFilter,t.wrapS=e.wrapS,t.wrapT=e.wrapT,t.flipY=e.flipY,t.anisotropy=e.anisotropy,t.mipmaps||(t.generateMipmaps=e.generateMipmaps),t):e}};F(O,"registerTexture",(e,t,i,s,a)=>{var c,h,f,p,r,l,u,g;if(!t){z&&console.error("!! gltf-progressive: Called register texture without texture");return}if(z){const y=((c=t.image)==null?void 0:c.width)||((f=(h=t.source)==null?void 0:h.data)==null?void 0:f.width)||0,m=((p=t.image)==null?void 0:p.height)||((l=(r=t.source)==null?void 0:r.data)==null?void 0:l.height)||0;console.log(`> gltf-progressive: register texture[${s}] "${t.name||t.uuid}", Current: ${y}x${m}, Max: ${(u=a.lods[0])==null?void 0:u.width}x${(g=a.lods[0])==null?void 0:g.height}, uuid: ${t.uuid}`,a,t)}t.source&&(t.source[Si]=a);const n=a.guid;O.assignLODInformation(e,t,n,i,s),O.lodInfos.set(n,a),O.lowresCache.set(n,t)}),F(O,"registerMesh",(e,t,i,s,a,n)=>{var f;const c=i.geometry;if(!c){z&&console.warn("gltf-progressive: Register mesh without geometry");return}c.userData||(c.userData={}),z&&console.log("> Progressive: register mesh "+i.name,{index:a,uuid:i.uuid},n,i),O.assignLODInformation(e,c,t,s,a),O.lodInfos.set(t,n);let h=O.lowresCache.get(t);h?h.push(i.geometry):h=[i.geometry],O.lowresCache.set(t,h),s>0&&!Bt(i)&&ca(i,c);for(const p of Re)(f=p.onRegisteredNewMesh)==null||f.call(p,i,n)}),F(O,"lodInfos",new Map),F(O,"previouslyLoaded",new Map),F(O,"lowresCache",new Map),F(O,"workers",[]),F(O,"_workersIndex",0),F(O,"maxConcurrent",50),F(O,"queue",new aa(O.maxConcurrent,{debug:z!=!1}));let me=O;class _a{constructor(e,t,i,s){F(this,"url");F(this,"key");F(this,"level");F(this,"index");this.url=e,this.key=t,this.level=i,s!=null&&(this.index=s)}}class ni{constructor(e,t){F(this,"ready");F(this,"_resolve");F(this,"_signal");F(this,"_frame_start");F(this,"_frames_to_capture");F(this,"_resolved",!1);F(this,"_addedCount",0);F(this,"_resolvedCount",0);F(this,"_awaiting",[]);F(this,"_maxPromisesPerObject",1);F(this,"_currentFrame",0);F(this,"_seen",new WeakMap);var a;const s=Math.max(t.frames??2,2);this._frame_start=t.waitForFirstCapture?void 0:e,this._frames_to_capture=s,this.ready=new Promise(n=>{this._resolve=n}),this.ready.finally(()=>{this._resolved=!0,this._awaiting.length=0}),this._signal=t.signal,(a=this._signal)==null||a.addEventListener("abort",()=>{this.resolveNow()}),this._maxPromisesPerObject=Math.max(1,t.maxPromisesPerObject??1)}get awaitedCount(){return this._addedCount}get resolvedCount(){return this._resolvedCount}get currentlyAwaiting(){return this._awaiting.length}update(e){var t;this._currentFrame=e,this._frame_start===void 0&&this._addedCount>0&&(this._frame_start=e),((t=this._signal)!=null&&t.aborted||this._awaiting.length===0&&this._frame_start!==void 0&&e>this._frame_start+this._frames_to_capture)&&this.resolveNow()}add(e,t,i){if(this._resolved){z&&console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");return}if(!(this._frame_start!==void 0&&this._currentFrame>this._frame_start+this._frames_to_capture)){if(this._maxPromisesPerObject>=1)if(this._seen.has(t)){let s=this._seen.get(t);if(s>=this._maxPromisesPerObject){z&&console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");return}this._seen.set(t,s+1)}else this._seen.set(t,1);this._awaiting.push(i),this._addedCount++,i.finally(()=>{this._resolvedCount++,this._awaiting.splice(this._awaiting.indexOf(i),1)})}}resolveNow(){var e,t;this._resolved||(t=this._resolve)==null||t.call(this,{awaited_count:this._addedCount,resolved_count:this._resolvedCount,cancelled:((e=this._signal)==null?void 0:e.aborted)??!1})}}F(ni,"addPromise",(e,t,i,s)=>{s.forEach(a=>{a.add(e,t,i)})});const he=He("debugprogressive"),ya=He("noprogressive"),Mi=Symbol("Needle:LODSManager"),Ci=Symbol("Needle:LODState"),Me=Symbol("Needle:CurrentLOD"),$={mesh_lod:-1,texture_lod:-1};var ie,xe,ui,De,ht,fi,we;const N=class N{constructor(e,t){F(this,"renderer");F(this,"context");F(this,"projectionScreenMatrix",new d.Matrix4);F(this,"overrideLodLevel");F(this,"targetTriangleDensity",2e5);F(this,"skinnedMeshAutoUpdateBoundsInterval",30);F(this,"updateInterval","auto");Se(this,ie,1);F(this,"pause",!1);F(this,"manual",!1);F(this,"_newPromiseGroups",[]);F(this,"_promiseGroupIds",0);F(this,"_lodchangedlisteners",[]);Se(this,xe,void 0);Se(this,ui,new d.Clock);Se(this,De,0);Se(this,ht,0);Se(this,fi,0);Se(this,we,0);F(this,"_fpsBuffer",[60,60,60,60,60]);F(this,"_sphere",new d.Sphere);F(this,"_tempBox",new d.Box3);F(this,"_tempBox2",new d.Box3);F(this,"tempMatrix",new d.Matrix4);F(this,"_tempWorldPosition",new d.Vector3);F(this,"_tempBoxSize",new d.Vector3);F(this,"_tempBox2Size",new d.Vector3);this.renderer=e,this.context={...t}}static getObjectLODState(e){return e[Ci]}static addPlugin(e){Re.push(e)}static removePlugin(e){const t=Re.indexOf(e);t>=0&&Re.splice(t,1)}static get(e,t){if(e[Mi])return console.debug("[gltf-progressive] LODsManager already exists for this renderer"),e[Mi];const i=new N(e,{engine:"unknown",...t});return e[Mi]=i,i}get plugins(){return Re}awaitLoading(e){const t=this._promiseGroupIds++,i=new ni(W(this,De),{...e});this._newPromiseGroups.push(i);const s=performance.now();return i.ready.finally(()=>{const a=this._newPromiseGroups.indexOf(i);a>=0&&(this._newPromiseGroups.splice(a,1),Ns()&&performance.measure("LODsManager:awaitLoading",{start:s,detail:{id:t,name:e==null?void 0:e.name,awaited:i.awaitedCount,resolved:i.resolvedCount}}))}),i.ready}_postprocessPromiseGroups(){if(this._newPromiseGroups.length!==0)for(let e=this._newPromiseGroups.length-1;e>=0;e--)this._newPromiseGroups[e].update(W(this,De))}addEventListener(e,t){e==="changed"&&this._lodchangedlisteners.push(t)}removeEventListener(e,t){if(e==="changed"){const i=this._lodchangedlisteners.indexOf(t);i>=0&&this._lodchangedlisteners.splice(i,1)}}enable(){if(W(this,xe))return;console.debug("[gltf-progressive] Enabling LODsManager for renderer");let e=0;de(this,xe,this.renderer.render);const t=this;Ar(this.renderer),this.renderer.render=function(i,s){const a=t.renderer.getRenderTarget();(a==null||"isXRRenderTarget"in a&&a.isXRRenderTarget)&&(e=0,de(t,De,W(t,De)+1),de(t,ht,W(t,ui).getDelta()),de(t,fi,W(t,fi)+W(t,ht)),t._fpsBuffer.shift(),t._fpsBuffer.push(1/W(t,ht)),de(t,we,t._fpsBuffer.reduce((c,h)=>c+h)/t._fpsBuffer.length),he&&W(t,De)%200===0&&console.log("FPS",Math.round(W(t,we)),"Interval:",W(t,ie)));const n=e++;W(t,xe).call(this,i,s),t.onAfterRender(i,s,n)}}disable(){W(this,xe)&&(console.debug("[gltf-progressive] Disabling LODsManager for renderer"),this.renderer.render=W(this,xe),de(this,xe,void 0))}update(e,t){this.internalUpdate(e,t)}onAfterRender(e,t,i){if(this.pause)return;const a=this.renderer.renderLists.get(e,0).opaque;let n=!0;if(a.length===1){const c=a[0].material;(c.name==="EffectMaterial"||c.name==="CopyShader")&&(n=!1)}if((t.parent&&t.parent.type==="CubeCamera"||i>=1&&t.type==="OrthographicCamera")&&(n=!1),n){if(ya||(this.updateInterval==="auto"?W(this,we)<40&&W(this,ie)<10?(de(this,ie,W(this,ie)+1),he&&console.warn("↓ Reducing LOD updates",W(this,ie),W(this,we).toFixed(0))):W(this,we)>=60&&W(this,ie)>1&&(de(this,ie,W(this,ie)-1),he&&console.warn("↑ Increasing LOD updates",W(this,ie),W(this,we).toFixed(0))):de(this,ie,this.updateInterval),W(this,ie)>0&&W(this,De)%W(this,ie)!=0))return;this.internalUpdate(e,t),this._postprocessPromiseGroups()}}internalUpdate(e,t){var h,f;const i=this.renderer.renderLists.get(e,0),s=i.opaque;this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse);const a=this.targetTriangleDensity;for(const p of s){if(p.material&&(((h=p.geometry)==null?void 0:h.type)==="BoxGeometry"||((f=p.geometry)==null?void 0:f.type)==="BufferGeometry")&&(p.material.name==="SphericalGaussianBlur"||p.material.name=="BackgroundCubeMaterial"||p.material.name==="CubemapFromEquirect"||p.material.name==="EquirectangularToCubeUV")){he&&(p.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]||(p.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]=!0,console.warn("Ignoring skybox or BLIT object",p,p.material.name,p.material.type)));continue}switch(p.material.type){case"LineBasicMaterial":case"LineDashedMaterial":case"PointsMaterial":case"ShadowMaterial":case"MeshDistanceMaterial":case"MeshDepthMaterial":continue}if(he==="color"&&p.material&&!p.object.progressive_debug_color){p.object.progressive_debug_color=!0;const l=Math.random()*16777215,u=new d.MeshStandardMaterial({color:l});p.object.material=u}const r=p.object;(r instanceof d.Mesh||r.isMesh)&&this.updateLODs(e,t,r,a)}const n=i.transparent;for(const p of n){const r=p.object;(r instanceof d.Mesh||r.isMesh)&&this.updateLODs(e,t,r,a)}const c=i.transmissive;for(const p of c){const r=p.object;(r instanceof d.Mesh||r.isMesh)&&this.updateLODs(e,t,r,a)}}updateLODs(e,t,i,s){var c,h;i.userData||(i.userData={});let a=i[Ci];if(a||(a=new xa,i[Ci]=a),a.frames++<2)return;for(const f of Re)(c=f.onBeforeUpdateLOD)==null||c.call(f,this.renderer,e,t,i);const n=this.overrideLodLevel!==void 0?this.overrideLodLevel:Ve;n>=0?($.mesh_lod=n,$.texture_lod=n):(this.calculateLodLevel(t,i,a,s,$),$.mesh_lod=Math.round($.mesh_lod),$.texture_lod=Math.round($.texture_lod)),$.mesh_lod>=0&&this.loadProgressiveMeshes(i,$.mesh_lod),i.material&&$.texture_lod>=0&&this.loadProgressiveTextures(i.material,$.texture_lod,n),z&&i.material&&!i.isGizmo&&Lr(i.material);for(const f of Re)(h=f.onAfterUpdatedLOD)==null||h.call(f,this.renderer,e,t,i,$);a.lastLodLevel_Mesh=$.mesh_lod,a.lastLodLevel_Texture=$.texture_lod}loadProgressiveTextures(e,t,i){if(!e)return;if(Array.isArray(e)){for(const a of e)this.loadProgressiveTextures(a,t);return}let s=!1;if((e[Me]===void 0||t<e[Me])&&(s=!0),i!==void 0&&i>=0&&(s=e[Me]!=i,t=i),s){e[Me]=t;const a=me.assignTextureLOD(e,t).then(n=>{this._lodchangedlisteners.forEach(c=>c({type:"texture",level:t,object:e}))});ni.addPromise("texture",e,a,this._newPromiseGroups)}}loadProgressiveMeshes(e,t){if(!e)return Promise.resolve(null);let i=e[Me]!==t;const s=e["DEBUG:LOD"];if(s!=null&&(i=e[Me]!=s,t=s),i){e[Me]=t;const a=e.geometry,n=me.assignMeshLOD(e,t).then(c=>(c&&e[Me]==t&&a!=e.geometry&&this._lodchangedlisteners.forEach(h=>h({type:"mesh",level:t,object:e})),c));return ni.addPromise("mesh",e,n,this._newPromiseGroups),n}return Promise.resolve(null)}static isInside(e,t){const i=e.min,s=e.max,a=(i.x+s.x)*.5,n=(i.y+s.y)*.5;return this._tempPtInside.set(a,n,i.z).applyMatrix4(t).z<0}calculateLodLevel(e,t,i,s,a){var m,v,_,x;if(!t){a.mesh_lod=-1,a.texture_lod=-1;return}if(!e){a.mesh_lod=-1,a.texture_lod=-1;return}let c=10+1,h=!1;if(he&&t["DEBUG:LOD"]!=null)return t["DEBUG:LOD"];const f=(m=me.getMeshLODExtension(t.geometry))==null?void 0:m.lods,p=me.getPrimitiveIndex(t.geometry),r=f&&f.length>0,l=me.getMaterialMinMaxLODsCount(t.material),u=l.min_count!==1/0&&l.min_count>=0&&l.max_count>=0;if(!r&&!u){a.mesh_lod=0,a.texture_lod=0;return}r||(h=!0,c=0);const g=this.renderer.domElement.clientHeight||this.renderer.domElement.height;let y=t.geometry.boundingBox;if(t.type==="SkinnedMesh"){const w=t;if(!w.boundingBox)w.computeBoundingBox();else if(this.skinnedMeshAutoUpdateBoundsInterval>0){if(!w[N.$skinnedMeshBoundsOffset]){const T=N.skinnedMeshBoundsFrameOffsetCounter++;w[N.$skinnedMeshBoundsOffset]=T}const b=w[N.$skinnedMeshBoundsOffset];if((i.frames+b)%this.skinnedMeshAutoUpdateBoundsInterval===0){const T=Bt(w),S=w.geometry;T&&(w.geometry=T),w.computeBoundingBox(),w.geometry=S}}y=w.boundingBox}if(y){const w=e;if(t.geometry.attributes.color&&t.geometry.attributes.color.count<100&&t.geometry.boundingSphere){this._sphere.copy(t.geometry.boundingSphere),this._sphere.applyMatrix4(t.matrixWorld);const M=e.getWorldPosition(this._tempWorldPosition);if(this._sphere.containsPoint(M)){a.mesh_lod=0,a.texture_lod=0;return}}if(this._tempBox.copy(y),this._tempBox.applyMatrix4(t.matrixWorld),w.isPerspectiveCamera&&N.isInside(this._tempBox,this.projectionScreenMatrix)){a.mesh_lod=0,a.texture_lod=0;return}if(this._tempBox.applyMatrix4(this.projectionScreenMatrix),this.renderer.xr.enabled&&w.isPerspectiveCamera&&w.fov>70){const M=this._tempBox.min,I=this._tempBox.max;let P=M.x,E=M.y,B=I.x,V=I.y;const G=2,H=1.5,j=(M.x+I.x)*.5,U=(M.y+I.y)*.5;P=(P-j)*G+j,E=(E-U)*G+U,B=(B-j)*G+j,V=(V-U)*G+U;const Q=P<0&&B>0?0:Math.min(Math.abs(M.x),Math.abs(I.x)),re=E<0&&V>0?0:Math.min(Math.abs(M.y),Math.abs(I.y)),te=Math.max(Q,re);i.lastCentrality=(H-te)*(H-te)*(H-te)}else i.lastCentrality=1;const b=this._tempBox.getSize(this._tempBoxSize);b.multiplyScalar(.5),screen.availHeight>0&&g>0&&b.multiplyScalar(g/screen.availHeight),e.isPerspectiveCamera?b.x*=e.aspect:e.isOrthographicCamera;const T=e.matrixWorldInverse,S=this._tempBox2;S.copy(y),S.applyMatrix4(t.matrixWorld),S.applyMatrix4(T);const L=S.getSize(this._tempBox2Size),C=Math.max(L.x,L.y);if(Math.max(b.x,b.y)!=0&&C!=0&&(b.z=L.z/Math.max(L.x,L.y)*Math.max(b.x,b.y)),i.lastScreenCoverage=Math.max(b.x,b.y,b.z),i.lastScreenspaceVolume.copy(b),i.lastScreenCoverage*=i.lastCentrality,he&&N.debugDrawLine){const M=this.tempMatrix.copy(this.projectionScreenMatrix);M.invert();const I=N.corner0,P=N.corner1,E=N.corner2,B=N.corner3;I.copy(this._tempBox.min),P.copy(this._tempBox.max),P.x=I.x,E.copy(this._tempBox.max),E.y=I.y,B.copy(this._tempBox.max);const V=(I.z+B.z)*.5;I.z=P.z=E.z=B.z=V,I.applyMatrix4(M),P.applyMatrix4(M),E.applyMatrix4(M),B.applyMatrix4(M),N.debugDrawLine(I,P,255),N.debugDrawLine(I,E,255),N.debugDrawLine(P,B,255),N.debugDrawLine(E,B,255)}let R=999;if(f&&i.lastScreenCoverage>0)for(let M=0;M<f.length;M++){const I=f[M],E=(((v=I.densities)==null?void 0:v[p])||I.density||1e-5)/i.lastScreenCoverage;if(p>0&&Ns()&&!I.densities&&!globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]&&(window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]=!0,console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")),E<s){R=M;break}}R<c&&(c=R,h=!0)}if(h?a.mesh_lod=c:a.mesh_lod=i.lastLodLevel_Mesh,he&&a.mesh_lod!=i.lastLodLevel_Mesh){const b=f==null?void 0:f[a.mesh_lod];b&&console.log(`Mesh LOD changed: ${i.lastLodLevel_Mesh} → ${a.mesh_lod} (density: ${(_=b.densities)==null?void 0:_[p].toFixed(0)}) | ${t.name}`)}if(u){const w="saveData"in globalThis.navigator&&globalThis.navigator.saveData===!0;if(i.lastLodLevel_Texture<0){if(a.texture_lod=l.max_count-1,he){const b=l.lods[l.max_count-1];he&&console.log(`First Texture LOD ${a.texture_lod} (${b.max_height}px) - ${t.name}`)}}else{const b=i.lastScreenspaceVolume.x+i.lastScreenspaceVolume.y+i.lastScreenspaceVolume.z;let T=i.lastScreenCoverage*4;((x=this.context)==null?void 0:x.engine)==="model-viewer"&&(T*=1.5);const L=g/window.devicePixelRatio*T;let C=!1;for(let D=l.lods.length-1;D>=0;D--){const R=l.lods[D];if(!(w&&R.max_height>=2048)&&!(Rr()&&R.max_height>4096)&&(R.max_height>L||!C&&D===0)){if(C=!0,a.texture_lod=D,he&&a.texture_lod<i.lastLodLevel_Texture){const A=R.max_height;console.log(`Texture LOD changed: ${i.lastLodLevel_Texture} → ${a.texture_lod} = ${A}px
3685
+ `,t.uuid),t=t.clone(),t.offset=e.offset,t.repeat=e.repeat,t.colorSpace=e.colorSpace,t.magFilter=e.magFilter,t.minFilter=e.minFilter,t.wrapS=e.wrapS,t.wrapT=e.wrapT,t.flipY=e.flipY,t.anisotropy=e.anisotropy,t.mipmaps||(t.generateMipmaps=e.generateMipmaps),t):e}};E(H,"registerTexture",(e,t,i,s,r)=>{var c,h,u,p,n,l,d,g;if(!t){G&&console.error("!! gltf-progressive: Called register texture without texture");return}if(G){const v=((c=t.image)==null?void 0:c.width)||((u=(h=t.source)==null?void 0:h.data)==null?void 0:u.width)||0,m=((p=t.image)==null?void 0:p.height)||((l=(n=t.source)==null?void 0:n.data)==null?void 0:l.height)||0;console.log(`> gltf-progressive: register texture[${s}] "${t.name||t.uuid}", Current: ${v}x${m}, Max: ${(d=r.lods[0])==null?void 0:d.width}x${(g=r.lods[0])==null?void 0:g.height}, uuid: ${t.uuid}`,r,t)}t.source&&(t.source[Bi]=r);const o=r.guid;H.assignLODInformation(e,t,o,i,s),H.lodInfos.set(o,r),H.lowresCache.set(o,t)}),E(H,"registerMesh",(e,t,i,s,r,o)=>{var u;const c=i.geometry;if(!c){G&&console.warn("gltf-progressive: Register mesh without geometry");return}c.userData||(c.userData={}),G&&console.log("> Progressive: register mesh "+i.name,{index:r,uuid:i.uuid},o,i),H.assignLODInformation(e,c,t,s,r),H.lodInfos.set(t,o);let h=H.lowresCache.get(t);h?h.push(i.geometry):h=[i.geometry],H.lowresCache.set(t,h),s>0&&!Ht(i)&&Sa(i,c);for(const p of ke)(u=p.onRegisteredNewMesh)==null||u.call(p,i,o)}),E(H,"lodInfos",new Map),E(H,"previouslyLoaded",new Map),E(H,"lowresCache",new Map),E(H,"workers",[]),E(H,"_workersIndex",0),E(H,"maxConcurrent",50),E(H,"queue",new Aa(H.maxConcurrent,{debug:G!=!1}));let we=H;class ka{constructor(e,t,i,s){E(this,"url");E(this,"key");E(this,"level");E(this,"index");this.url=e,this.key=t,this.level=i,s!=null&&(this.index=s)}}class _i{constructor(e,t){E(this,"ready");E(this,"_resolve");E(this,"_signal");E(this,"_frame_start");E(this,"_frames_to_capture");E(this,"_resolved",!1);E(this,"_addedCount",0);E(this,"_resolvedCount",0);E(this,"_awaiting",[]);E(this,"_maxPromisesPerObject",1);E(this,"_currentFrame",0);E(this,"_seen",new WeakMap);var r;const s=Math.max(t.frames??2,2);this._frame_start=t.waitForFirstCapture?void 0:e,this._frames_to_capture=s,this.ready=new Promise(o=>{this._resolve=o}),this.ready.finally(()=>{this._resolved=!0,this._awaiting.length=0}),this._signal=t.signal,(r=this._signal)==null||r.addEventListener("abort",()=>{this.resolveNow()}),this._maxPromisesPerObject=Math.max(1,t.maxPromisesPerObject??1)}get awaitedCount(){return this._addedCount}get resolvedCount(){return this._resolvedCount}get currentlyAwaiting(){return this._awaiting.length}update(e){var t;this._currentFrame=e,this._frame_start===void 0&&this._addedCount>0&&(this._frame_start=e),((t=this._signal)!=null&&t.aborted||this._awaiting.length===0&&this._frame_start!==void 0&&e>this._frame_start+this._frames_to_capture)&&this.resolveNow()}add(e,t,i){if(this._resolved){G&&console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");return}if(!(this._frame_start!==void 0&&this._currentFrame>this._frame_start+this._frames_to_capture)){if(this._maxPromisesPerObject>=1)if(this._seen.has(t)){let s=this._seen.get(t);if(s>=this._maxPromisesPerObject){G&&console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");return}this._seen.set(t,s+1)}else this._seen.set(t,1);this._awaiting.push(i),this._addedCount++,i.finally(()=>{this._resolvedCount++,this._awaiting.splice(this._awaiting.indexOf(i),1)})}}resolveNow(){var e,t;this._resolved||(t=this._resolve)==null||t.call(this,{awaited_count:this._addedCount,resolved_count:this._resolvedCount,cancelled:((e=this._signal)==null?void 0:e.aborted)??!1})}}E(_i,"addPromise",(e,t,i,s)=>{s.forEach(r=>{r.add(e,t,i)})});const pe=qe("debugprogressive"),Fa=qe("noprogressive"),Oi=Symbol("Needle:LODSManager"),zi=Symbol("Needle:LODState"),Ie=Symbol("Needle:CurrentLOD"),re={mesh_lod:-1,texture_lod:-1};var ae,Me,Ai,Oe,gt,Ti,Ce;const q=class q{constructor(e,t){E(this,"renderer");E(this,"context");E(this,"projectionScreenMatrix",new f.Matrix4);E(this,"overrideLodLevel");E(this,"targetTriangleDensity",2e5);E(this,"skinnedMeshAutoUpdateBoundsInterval",30);E(this,"updateInterval","auto");Pe(this,ae,1);E(this,"pause",!1);E(this,"manual",!1);E(this,"_newPromiseGroups",[]);E(this,"_promiseGroupIds",0);E(this,"_lodchangedlisteners",[]);Pe(this,Me,void 0);Pe(this,Ai,new f.Clock);Pe(this,Oe,0);Pe(this,gt,0);Pe(this,Ti,0);Pe(this,Ce,0);E(this,"_fpsBuffer",[60,60,60,60,60]);E(this,"_sphere",new f.Sphere);E(this,"_tempBox",new f.Box3);E(this,"_tempBox2",new f.Box3);E(this,"tempMatrix",new f.Matrix4);E(this,"_tempWorldPosition",new f.Vector3);E(this,"_tempBoxSize",new f.Vector3);E(this,"_tempBox2Size",new f.Vector3);this.renderer=e,this.context={...t}}static getObjectLODState(e){return e[zi]}static addPlugin(e){ke.push(e)}static removePlugin(e){const t=ke.indexOf(e);t>=0&&ke.splice(t,1)}static get(e,t){if(e[Oi])return console.debug("[gltf-progressive] LODsManager already exists for this renderer"),e[Oi];const i=new q(e,{engine:"unknown",...t});return e[Oi]=i,i}get plugins(){return ke}awaitLoading(e){const t=this._promiseGroupIds++,i=new _i(Q(this,Oe),{...e});this._newPromiseGroups.push(i);const s=performance.now();return i.ready.finally(()=>{const r=this._newPromiseGroups.indexOf(i);r>=0&&(this._newPromiseGroups.splice(r,1),ir()&&performance.measure("LODsManager:awaitLoading",{start:s,detail:{id:t,name:e==null?void 0:e.name,awaited:i.awaitedCount,resolved:i.resolvedCount}}))}),i.ready}_postprocessPromiseGroups(){if(this._newPromiseGroups.length!==0)for(let e=this._newPromiseGroups.length-1;e>=0;e--)this._newPromiseGroups[e].update(Q(this,Oe))}addEventListener(e,t){e==="changed"&&this._lodchangedlisteners.push(t)}removeEventListener(e,t){if(e==="changed"){const i=this._lodchangedlisteners.indexOf(t);i>=0&&this._lodchangedlisteners.splice(i,1)}}enable(){if(Q(this,Me))return;console.debug("[gltf-progressive] Enabling LODsManager for renderer");let e=0;ye(this,Me,this.renderer.render);const t=this;Hr(this.renderer),this.renderer.render=function(i,s){const r=t.renderer.getRenderTarget();(r==null||"isXRRenderTarget"in r&&r.isXRRenderTarget)&&(e=0,ye(t,Oe,Q(t,Oe)+1),ye(t,gt,Q(t,Ai).getDelta()),ye(t,Ti,Q(t,Ti)+Q(t,gt)),t._fpsBuffer.shift(),t._fpsBuffer.push(1/Q(t,gt)),ye(t,Ce,t._fpsBuffer.reduce((c,h)=>c+h)/t._fpsBuffer.length),pe&&Q(t,Oe)%200===0&&console.log("FPS",Math.round(Q(t,Ce)),"Interval:",Q(t,ae)));const o=e++;Q(t,Me).call(this,i,s),t.onAfterRender(i,s,o)}}disable(){Q(this,Me)&&(console.debug("[gltf-progressive] Disabling LODsManager for renderer"),this.renderer.render=Q(this,Me),ye(this,Me,void 0))}update(e,t){this.internalUpdate(e,t)}onAfterRender(e,t,i){if(this.pause)return;const r=this.renderer.renderLists.get(e,0).opaque;let o=!0;if(r.length===1){const c=r[0].material;(c.name==="EffectMaterial"||c.name==="CopyShader")&&(o=!1)}if((t.parent&&t.parent.type==="CubeCamera"||i>=1&&t.type==="OrthographicCamera")&&(o=!1),o){if(Fa||(this.updateInterval==="auto"?Q(this,Ce)<40&&Q(this,ae)<10?(ye(this,ae,Q(this,ae)+1),pe&&console.warn("↓ Reducing LOD updates",Q(this,ae),Q(this,Ce).toFixed(0))):Q(this,Ce)>=60&&Q(this,ae)>1&&(ye(this,ae,Q(this,ae)-1),pe&&console.warn("↑ Increasing LOD updates",Q(this,ae),Q(this,Ce).toFixed(0))):ye(this,ae,this.updateInterval),Q(this,ae)>0&&Q(this,Oe)%Q(this,ae)!=0))return;this.internalUpdate(e,t),this._postprocessPromiseGroups()}}internalUpdate(e,t){var h,u;const i=this.renderer.renderLists.get(e,0),s=i.opaque;this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse);const r=this.targetTriangleDensity;for(const p of s){if(p.material&&(((h=p.geometry)==null?void 0:h.type)==="BoxGeometry"||((u=p.geometry)==null?void 0:u.type)==="BufferGeometry")&&(p.material.name==="SphericalGaussianBlur"||p.material.name=="BackgroundCubeMaterial"||p.material.name==="CubemapFromEquirect"||p.material.name==="EquirectangularToCubeUV")){pe&&(p.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]||(p.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]=!0,console.warn("Ignoring skybox or BLIT object",p,p.material.name,p.material.type)));continue}switch(p.material.type){case"LineBasicMaterial":case"LineDashedMaterial":case"PointsMaterial":case"ShadowMaterial":case"MeshDistanceMaterial":case"MeshDepthMaterial":continue}if(pe==="color"&&p.material&&!p.object.progressive_debug_color){p.object.progressive_debug_color=!0;const l=Math.random()*16777215,d=new f.MeshStandardMaterial({color:l});p.object.material=d}const n=p.object;(n instanceof f.Mesh||n.isMesh)&&this.updateLODs(e,t,n,r)}const o=i.transparent;for(const p of o){const n=p.object;(n instanceof f.Mesh||n.isMesh)&&this.updateLODs(e,t,n,r)}const c=i.transmissive;for(const p of c){const n=p.object;(n instanceof f.Mesh||n.isMesh)&&this.updateLODs(e,t,n,r)}}updateLODs(e,t,i,s){var c,h;i.userData||(i.userData={});let r=i[zi];if(r||(r=new Ba,i[zi]=r),r.frames++<2)return;for(const u of ke)(c=u.onBeforeUpdateLOD)==null||c.call(u,this.renderer,e,t,i);const o=this.overrideLodLevel!==void 0?this.overrideLodLevel:Ne;o>=0?(re.mesh_lod=o,re.texture_lod=o):(this.calculateLodLevel(t,i,r,s,re),re.mesh_lod=Math.round(re.mesh_lod),re.texture_lod=Math.round(re.texture_lod)),re.mesh_lod>=0&&this.loadProgressiveMeshes(i,re.mesh_lod),i.material&&re.texture_lod>=0&&this.loadProgressiveTextures(i.material,re.texture_lod,o),G&&i.material&&!i.isGizmo&&Yr(i.material);for(const u of ke)(h=u.onAfterUpdatedLOD)==null||h.call(u,this.renderer,e,t,i,re);r.lastLodLevel_Mesh=re.mesh_lod,r.lastLodLevel_Texture=re.texture_lod}loadProgressiveTextures(e,t,i){if(!e)return;if(Array.isArray(e)){for(const r of e)this.loadProgressiveTextures(r,t);return}let s=!1;if((e[Ie]===void 0||t<e[Ie])&&(s=!0),i!==void 0&&i>=0&&(s=e[Ie]!=i,t=i),s){e[Ie]=t;const r=we.assignTextureLOD(e,t).then(o=>{this._lodchangedlisteners.forEach(c=>c({type:"texture",level:t,object:e}))});_i.addPromise("texture",e,r,this._newPromiseGroups)}}loadProgressiveMeshes(e,t){if(!e)return Promise.resolve(null);let i=e[Ie]!==t;const s=e["DEBUG:LOD"];if(s!=null&&(i=e[Ie]!=s,t=s),i){e[Ie]=t;const r=e.geometry,o=we.assignMeshLOD(e,t).then(c=>(c&&e[Ie]==t&&r!=e.geometry&&this._lodchangedlisteners.forEach(h=>h({type:"mesh",level:t,object:e})),c));return _i.addPromise("mesh",e,o,this._newPromiseGroups),o}return Promise.resolve(null)}static isInside(e,t){const i=e.min,s=e.max,r=(i.x+s.x)*.5,o=(i.y+s.y)*.5;return this._tempPtInside.set(r,o,i.z).applyMatrix4(t).z<0}calculateLodLevel(e,t,i,s,r){var m,_,y,w;if(!t){r.mesh_lod=-1,r.texture_lod=-1;return}if(!e){r.mesh_lod=-1,r.texture_lod=-1;return}let c=10+1,h=!1;if(pe&&t["DEBUG:LOD"]!=null)return t["DEBUG:LOD"];const u=(m=we.getMeshLODExtension(t.geometry))==null?void 0:m.lods,p=we.getPrimitiveIndex(t.geometry),n=u&&u.length>0,l=we.getMaterialMinMaxLODsCount(t.material),d=l.min_count!==1/0&&l.min_count>=0&&l.max_count>=0;if(!n&&!d){r.mesh_lod=0,r.texture_lod=0;return}n||(h=!0,c=0);const g=this.renderer.domElement.clientHeight||this.renderer.domElement.height;let v=t.geometry.boundingBox;if(t.type==="SkinnedMesh"){const x=t;if(!x.boundingBox)x.computeBoundingBox();else if(this.skinnedMeshAutoUpdateBoundsInterval>0){if(!x[q.$skinnedMeshBoundsOffset]){const T=q.skinnedMeshBoundsFrameOffsetCounter++;x[q.$skinnedMeshBoundsOffset]=T}const b=x[q.$skinnedMeshBoundsOffset];if((i.frames+b)%this.skinnedMeshAutoUpdateBoundsInterval===0){const T=Ht(x),M=x.geometry;T&&(x.geometry=T),x.computeBoundingBox(),x.geometry=M}}v=x.boundingBox}if(v){const x=e;if(t.geometry.attributes.color&&t.geometry.attributes.color.count<100&&t.geometry.boundingSphere){this._sphere.copy(t.geometry.boundingSphere),this._sphere.applyMatrix4(t.matrixWorld);const S=e.getWorldPosition(this._tempWorldPosition);if(this._sphere.containsPoint(S)){r.mesh_lod=0,r.texture_lod=0;return}}if(this._tempBox.copy(v),this._tempBox.applyMatrix4(t.matrixWorld),x.isPerspectiveCamera&&q.isInside(this._tempBox,this.projectionScreenMatrix)){r.mesh_lod=0,r.texture_lod=0;return}if(this._tempBox.applyMatrix4(this.projectionScreenMatrix),this.renderer.xr.enabled&&x.isPerspectiveCamera&&x.fov>70){const S=this._tempBox.min,P=this._tempBox.max;let R=S.x,k=S.y,F=P.x,z=P.y;const B=2,N=1.5,W=(S.x+P.x)*.5,O=(S.y+P.y)*.5;R=(R-W)*B+W,k=(k-O)*B+O,F=(F-W)*B+W,z=(z-O)*B+O;const j=R<0&&F>0?0:Math.min(Math.abs(S.x),Math.abs(P.x)),U=k<0&&z>0?0:Math.min(Math.abs(S.y),Math.abs(P.y)),ie=Math.max(j,U);i.lastCentrality=(N-ie)*(N-ie)*(N-ie)}else i.lastCentrality=1;const b=this._tempBox.getSize(this._tempBoxSize);b.multiplyScalar(.5),screen.availHeight>0&&g>0&&b.multiplyScalar(g/screen.availHeight),e.isPerspectiveCamera?b.x*=e.aspect:e.isOrthographicCamera;const T=e.matrixWorldInverse,M=this._tempBox2;M.copy(v),M.applyMatrix4(t.matrixWorld),M.applyMatrix4(T);const L=M.getSize(this._tempBox2Size),C=Math.max(L.x,L.y);if(Math.max(b.x,b.y)!=0&&C!=0&&(b.z=L.z/Math.max(L.x,L.y)*Math.max(b.x,b.y)),i.lastScreenCoverage=Math.max(b.x,b.y,b.z),i.lastScreenspaceVolume.copy(b),i.lastScreenCoverage*=i.lastCentrality,pe&&q.debugDrawLine){const S=this.tempMatrix.copy(this.projectionScreenMatrix);S.invert();const P=q.corner0,R=q.corner1,k=q.corner2,F=q.corner3;P.copy(this._tempBox.min),R.copy(this._tempBox.max),R.x=P.x,k.copy(this._tempBox.max),k.y=P.y,F.copy(this._tempBox.max);const z=(P.z+F.z)*.5;P.z=R.z=k.z=F.z=z,P.applyMatrix4(S),R.applyMatrix4(S),k.applyMatrix4(S),F.applyMatrix4(S),q.debugDrawLine(P,R,255),q.debugDrawLine(P,k,255),q.debugDrawLine(R,F,255),q.debugDrawLine(k,F,255)}let D=999;if(u&&i.lastScreenCoverage>0)for(let S=0;S<u.length;S++){const P=u[S],k=(((_=P.densities)==null?void 0:_[p])||P.density||1e-5)/i.lastScreenCoverage;if(p>0&&ir()&&!P.densities&&!globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]&&(window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]=!0,console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")),k<s){D=S;break}}D<c&&(c=D,h=!0)}if(h?r.mesh_lod=c:r.mesh_lod=i.lastLodLevel_Mesh,pe&&r.mesh_lod!=i.lastLodLevel_Mesh){const b=u==null?void 0:u[r.mesh_lod];b&&console.log(`Mesh LOD changed: ${i.lastLodLevel_Mesh} → ${r.mesh_lod} (density: ${(y=b.densities)==null?void 0:y[p].toFixed(0)}) | ${t.name}`)}if(d){const x="saveData"in globalThis.navigator&&globalThis.navigator.saveData===!0;if(i.lastLodLevel_Texture<0){if(r.texture_lod=l.max_count-1,pe){const b=l.lods[l.max_count-1];pe&&console.log(`First Texture LOD ${r.texture_lod} (${b.max_height}px) - ${t.name}`)}}else{const b=i.lastScreenspaceVolume.x+i.lastScreenspaceVolume.y+i.lastScreenspaceVolume.z;let T=i.lastScreenCoverage*4;((w=this.context)==null?void 0:w.engine)==="model-viewer"&&(T*=1.5);const L=g/window.devicePixelRatio*T;let C=!1;for(let I=l.lods.length-1;I>=0;I--){const D=l.lods[I];if(!(x&&D.max_height>=2048)&&!(qr()&&D.max_height>4096)&&(D.max_height>L||!C&&I===0)){if(C=!0,r.texture_lod=I,pe&&r.texture_lod<i.lastLodLevel_Texture){const A=D.max_height;console.log(`Texture LOD changed: ${i.lastLodLevel_Texture} → ${r.texture_lod} = ${A}px
3686
3686
  Screensize: ${L.toFixed(0)}px, Coverage: ${(100*i.lastScreenCoverage).toFixed(2)}%, Volume ${b.toFixed(1)}
3687
- ${t.name}`)}break}}}}else a.texture_lod=0}};ie=new WeakMap,xe=new WeakMap,ui=new WeakMap,De=new WeakMap,ht=new WeakMap,fi=new WeakMap,we=new WeakMap,F(N,"debugDrawLine"),F(N,"corner0",new d.Vector3),F(N,"corner1",new d.Vector3),F(N,"corner2",new d.Vector3),F(N,"corner3",new d.Vector3),F(N,"_tempPtInside",new d.Vector3),F(N,"skinnedMeshBoundsFrameOffsetCounter",0),F(N,"$skinnedMeshBoundsOffset",Symbol("gltf-progressive-skinnedMeshBoundsOffset"));let dt=N;class xa{constructor(){F(this,"frames",0);F(this,"lastLodLevel_Mesh",-1);F(this,"lastLodLevel_Texture",-1);F(this,"lastScreenCoverage",0);F(this,"lastScreenspaceVolume",new d.Vector3);F(this,"lastCentrality",0)}}const qs=Symbol("NEEDLE_mesh_lod"),Nt=Symbol("NEEDLE_texture_lod");let yt=null;function Ir(){const o=wa();o&&(o.mapURLs(function(e){return js(),e}),js(),yt==null||yt.disconnect(),yt=new MutationObserver(e=>{e.forEach(t=>{t.addedNodes.forEach(i=>{i instanceof HTMLElement&&i.tagName.toLowerCase()==="model-viewer"&&Dr(i)})})}),yt.observe(document,{childList:!0,subtree:!0}))}function wa(){if(typeof customElements>"u")return null;const o=customElements.get("model-viewer");return o||(customElements.whenDefined("model-viewer").then(()=>{console.debug("[gltf-progressive] model-viewer defined"),Ir()}),null)}function js(){if(typeof document>"u")return;document.querySelectorAll("model-viewer").forEach(e=>{Dr(e)})}const Qs=new WeakSet;let ba=0;function Dr(o){if(!o||Qs.has(o))return null;Qs.add(o),console.debug("[gltf-progressive] found new model-viewer..."+ ++ba+`
3688
- `,o.getAttribute("src"));let e=null,t=null,i=null;for(let s=o;s!=null;s=Object.getPrototypeOf(s)){const a=Object.getOwnPropertySymbols(s),n=a.find(f=>f.toString()=="Symbol(renderer)"),c=a.find(f=>f.toString()=="Symbol(scene)"),h=a.find(f=>f.toString()=="Symbol(needsRender)");!e&&n!=null&&(e=o[n].threeRenderer),!t&&c!=null&&(t=o[c]),!i&&h!=null&&(i=o[h])}if(e&&t){let s=function(){if(i){let n=0,c=setInterval(()=>{if(n++>5){clearInterval(c);return}i==null||i.call(o)},300)}};console.debug("[gltf-progressive] setup model-viewer");const a=dt.get(e,{engine:"model-viewer"});return dt.addPlugin(new Aa),a.enable(),a.addEventListener("changed",()=>{i==null||i.call(o)}),o.addEventListener("model-visibility",n=>{n.detail.visible&&(i==null||i.call(o))}),o.addEventListener("load",()=>{s()}),()=>{a.disable()}}return null}class Aa{constructor(){F(this,"_didWarnAboutMissingUrl",!1)}onBeforeUpdateLOD(e,t,i,s){this.tryParseMeshLOD(t,s),this.tryParseTextureLOD(t,s)}getUrl(e){if(!e)return null;let t=e.getAttribute("src");return t||(t=e.src),t||(this._didWarnAboutMissingUrl||console.warn("No url found in modelviewer",e),this._didWarnAboutMissingUrl=!0),t}tryGetCurrentGLTF(e){return e._currentGLTF}tryGetCurrentModelViewer(e){return e.element}tryParseTextureLOD(e,t){if(t[Nt]==!0)return;t[Nt]=!0;const i=this.tryGetCurrentGLTF(e),s=this.tryGetCurrentModelViewer(e),a=this.getUrl(s);if(a&&i&&t.material){let n=function(h){var p,r,l;if(h[Nt]==!0)return;h[Nt]=!0,h.userData&&(h.userData.LOD=-1);const f=Object.keys(h);for(let u=0;u<f.length;u++){const g=f[u],y=h[g];if((y==null?void 0:y.isTexture)===!0){const m=(r=(p=y.userData)==null?void 0:p.associations)==null?void 0:r.textures;if(m==null)continue;const v=i.parser.json.textures[m];if(!v){console.warn("Texture data not found for texture index "+m);continue}if((l=v==null?void 0:v.extensions)!=null&&l[ye]){const _=v.extensions[ye];_&&a&&me.registerTexture(a,y,_.lods.length,m,_)}}}};const c=t.material;if(Array.isArray(c))for(const h of c)n(h);else n(c)}}tryParseMeshLOD(e,t){var n,c;if(t[qs]==!0)return;t[qs]=!0;const i=this.tryGetCurrentModelViewer(e),s=this.getUrl(i);if(!s)return;const a=(c=(n=t.userData)==null?void 0:n.gltfExtensions)==null?void 0:c[ye];if(a&&s){const h=t.uuid;me.registerMesh(s,h,t,0,a.lods.length,a)}}}function Pr(...o){let e,t,i,s;switch(o.length){case 2:[i,t]=o,s={};break;case 3:[i,t,s]=o;break;case 4:[e,t,i,s]=o;break;default:throw new Error("Invalid arguments")}Tr(i),Cr(i,{progressive:!0,...s==null?void 0:s.hints}),i.register(n=>new me(n));const a=dt.get(t);return(s==null?void 0:s.enableLODsManager)!==!1&&a.enable(),a}Ir();if(!la){const o={gltfProgressive:{useNeedleProgressive:Pr,LODsManager:dt,configureLoader:Cr,getRaycastMesh:Bt,useRaycastMeshes:ha}};if(!globalThis.Needle)globalThis.Needle=o;else for(const e in o)globalThis.Needle[e]=o[e]}var lt=Object.freeze({Linear:Object.freeze({None:function(o){return o},In:function(o){return o},Out:function(o){return o},InOut:function(o){return o}}),Quadratic:Object.freeze({In:function(o){return o*o},Out:function(o){return o*(2-o)},InOut:function(o){return(o*=2)<1?.5*o*o:-.5*(--o*(o-2)-1)}}),Cubic:Object.freeze({In:function(o){return o*o*o},Out:function(o){return--o*o*o+1},InOut:function(o){return(o*=2)<1?.5*o*o*o:.5*((o-=2)*o*o+2)}}),Quartic:Object.freeze({In:function(o){return o*o*o*o},Out:function(o){return 1- --o*o*o*o},InOut:function(o){return(o*=2)<1?.5*o*o*o*o:-.5*((o-=2)*o*o*o-2)}}),Quintic:Object.freeze({In:function(o){return o*o*o*o*o},Out:function(o){return--o*o*o*o*o+1},InOut:function(o){return(o*=2)<1?.5*o*o*o*o*o:.5*((o-=2)*o*o*o*o+2)}}),Sinusoidal:Object.freeze({In:function(o){return 1-Math.sin((1-o)*Math.PI/2)},Out:function(o){return Math.sin(o*Math.PI/2)},InOut:function(o){return .5*(1-Math.sin(Math.PI*(.5-o)))}}),Exponential:Object.freeze({In:function(o){return o===0?0:Math.pow(1024,o-1)},Out:function(o){return o===1?1:1-Math.pow(2,-10*o)},InOut:function(o){return o===0?0:o===1?1:(o*=2)<1?.5*Math.pow(1024,o-1):.5*(-Math.pow(2,-10*(o-1))+2)}}),Circular:Object.freeze({In:function(o){return 1-Math.sqrt(1-o*o)},Out:function(o){return Math.sqrt(1- --o*o)},InOut:function(o){return(o*=2)<1?-.5*(Math.sqrt(1-o*o)-1):.5*(Math.sqrt(1-(o-=2)*o)+1)}}),Elastic:Object.freeze({In:function(o){return o===0?0:o===1?1:-Math.pow(2,10*(o-1))*Math.sin((o-1.1)*5*Math.PI)},Out:function(o){return o===0?0:o===1?1:Math.pow(2,-10*o)*Math.sin((o-.1)*5*Math.PI)+1},InOut:function(o){return o===0?0:o===1?1:(o*=2,o<1?-.5*Math.pow(2,10*(o-1))*Math.sin((o-1.1)*5*Math.PI):.5*Math.pow(2,-10*(o-1))*Math.sin((o-1.1)*5*Math.PI)+1)}}),Back:Object.freeze({In:function(o){var e=1.70158;return o===1?1:o*o*((e+1)*o-e)},Out:function(o){var e=1.70158;return o===0?0:--o*o*((e+1)*o+e)+1},InOut:function(o){var e=2.5949095;return(o*=2)<1?.5*(o*o*((e+1)*o-e)):.5*((o-=2)*o*((e+1)*o+e)+2)}}),Bounce:Object.freeze({In:function(o){return 1-lt.Bounce.Out(1-o)},Out:function(o){return o<1/2.75?7.5625*o*o:o<2/2.75?7.5625*(o-=1.5/2.75)*o+.75:o<2.5/2.75?7.5625*(o-=2.25/2.75)*o+.9375:7.5625*(o-=2.625/2.75)*o+.984375},InOut:function(o){return o<.5?lt.Bounce.In(o*2)*.5:lt.Bounce.Out(o*2-1)*.5+.5}}),generatePow:function(o){return o===void 0&&(o=4),o=o<Number.EPSILON?Number.EPSILON:o,o=o>1e4?1e4:o,{In:function(e){return Math.pow(e,o)},Out:function(e){return 1-Math.pow(1-e,o)},InOut:function(e){return e<.5?Math.pow(e*2,o)/2:(1-Math.pow(2-e*2,o))/2+.5}}}}),ot=function(){return performance.now()},Fr=function(){function o(){this._tweens={},this._tweensAddedDuringUpdate={}}return o.prototype.getAll=function(){var e=this;return Object.keys(this._tweens).map(function(t){return e._tweens[t]})},o.prototype.removeAll=function(){this._tweens={}},o.prototype.add=function(e){this._tweens[e.getId()]=e,this._tweensAddedDuringUpdate[e.getId()]=e},o.prototype.remove=function(e){delete this._tweens[e.getId()],delete this._tweensAddedDuringUpdate[e.getId()]},o.prototype.update=function(e,t){e===void 0&&(e=ot()),t===void 0&&(t=!1);var i=Object.keys(this._tweens);if(i.length===0)return!1;for(;i.length>0;){this._tweensAddedDuringUpdate={};for(var s=0;s<i.length;s++){var a=this._tweens[i[s]],n=!t;a&&a.update(e,n)===!1&&!t&&delete this._tweens[i[s]]}i=Object.keys(this._tweensAddedDuringUpdate)}return!0},o}(),Ue={Linear:function(o,e){var t=o.length-1,i=t*e,s=Math.floor(i),a=Ue.Utils.Linear;return e<0?a(o[0],o[1],i):e>1?a(o[t],o[t-1],t-i):a(o[s],o[s+1>t?t:s+1],i-s)},Bezier:function(o,e){for(var t=0,i=o.length-1,s=Math.pow,a=Ue.Utils.Bernstein,n=0;n<=i;n++)t+=s(1-e,i-n)*s(e,n)*o[n]*a(i,n);return t},CatmullRom:function(o,e){var t=o.length-1,i=t*e,s=Math.floor(i),a=Ue.Utils.CatmullRom;return o[0]===o[t]?(e<0&&(s=Math.floor(i=t*(1+e))),a(o[(s-1+t)%t],o[s],o[(s+1)%t],o[(s+2)%t],i-s)):e<0?o[0]-(a(o[0],o[0],o[1],o[1],-i)-o[0]):e>1?o[t]-(a(o[t],o[t],o[t-1],o[t-1],i-t)-o[t]):a(o[s?s-1:0],o[s],o[t<s+1?t:s+1],o[t<s+2?t:s+2],i-s)},Utils:{Linear:function(o,e,t){return(e-o)*t+o},Bernstein:function(o,e){var t=Ue.Utils.Factorial;return t(o)/t(e)/t(o-e)},Factorial:function(){var o=[1];return function(e){var t=1;if(o[e])return o[e];for(var i=e;i>1;i--)t*=i;return o[e]=t,t}}(),CatmullRom:function(o,e,t,i,s){var a=(t-o)*.5,n=(i-e)*.5,c=s*s,h=s*c;return(2*e-2*t+a+n)*h+(-3*e+3*t-2*a-n)*c+a*s+e}}},us=function(){function o(){}return o.nextId=function(){return o._nextId++},o._nextId=0,o}(),Ni=new Fr,ci=function(){function o(e,t){t===void 0&&(t=Ni),this._object=e,this._group=t,this._isPaused=!1,this._pauseStart=0,this._valuesStart={},this._valuesEnd={},this._valuesStartRepeat={},this._duration=1e3,this._isDynamic=!1,this._initialRepeat=0,this._repeat=0,this._yoyo=!1,this._isPlaying=!1,this._reversed=!1,this._delayTime=0,this._startTime=0,this._easingFunction=lt.Linear.None,this._interpolationFunction=Ue.Linear,this._chainedTweens=[],this._onStartCallbackFired=!1,this._onEveryStartCallbackFired=!1,this._id=us.nextId(),this._isChainStopped=!1,this._propertiesAreSetUp=!1,this._goToEnd=!1}return o.prototype.getId=function(){return this._id},o.prototype.isPlaying=function(){return this._isPlaying},o.prototype.isPaused=function(){return this._isPaused},o.prototype.getDuration=function(){return this._duration},o.prototype.to=function(e,t){if(t===void 0&&(t=1e3),this._isPlaying)throw new Error("Can not call Tween.to() while Tween is already started or paused. Stop the Tween first.");return this._valuesEnd=e,this._propertiesAreSetUp=!1,this._duration=t<0?0:t,this},o.prototype.duration=function(e){return e===void 0&&(e=1e3),this._duration=e<0?0:e,this},o.prototype.dynamic=function(e){return e===void 0&&(e=!1),this._isDynamic=e,this},o.prototype.start=function(e,t){if(e===void 0&&(e=ot()),t===void 0&&(t=!1),this._isPlaying)return this;if(this._group&&this._group.add(this),this._repeat=this._initialRepeat,this._reversed){this._reversed=!1;for(var i in this._valuesStartRepeat)this._swapEndStartRepeatValues(i),this._valuesStart[i]=this._valuesStartRepeat[i]}if(this._isPlaying=!0,this._isPaused=!1,this._onStartCallbackFired=!1,this._onEveryStartCallbackFired=!1,this._isChainStopped=!1,this._startTime=e,this._startTime+=this._delayTime,!this._propertiesAreSetUp||t){if(this._propertiesAreSetUp=!0,!this._isDynamic){var s={};for(var a in this._valuesEnd)s[a]=this._valuesEnd[a];this._valuesEnd=s}this._setupProperties(this._object,this._valuesStart,this._valuesEnd,this._valuesStartRepeat,t)}return this},o.prototype.startFromCurrentValues=function(e){return this.start(e,!0)},o.prototype._setupProperties=function(e,t,i,s,a){for(var n in i){var c=e[n],h=Array.isArray(c),f=h?"array":typeof c,p=!h&&Array.isArray(i[n]);if(!(f==="undefined"||f==="function")){if(p){var r=i[n];if(r.length===0)continue;for(var l=[c],u=0,g=r.length;u<g;u+=1){var y=this._handleRelativeValue(c,r[u]);if(isNaN(y)){p=!1,console.warn("Found invalid interpolation list. Skipping.");break}l.push(y)}p&&(i[n]=l)}if((f==="object"||h)&&c&&!p){t[n]=h?[]:{};var m=c;for(var v in m)t[n][v]=m[v];s[n]=h?[]:{};var r=i[n];if(!this._isDynamic){var _={};for(var v in r)_[v]=r[v];i[n]=r=_}this._setupProperties(m,t[n],r,s[n],a)}else(typeof t[n]>"u"||a)&&(t[n]=c),h||(t[n]*=1),p?s[n]=i[n].slice().reverse():s[n]=t[n]||0}}},o.prototype.stop=function(){return this._isChainStopped||(this._isChainStopped=!0,this.stopChainedTweens()),this._isPlaying?(this._group&&this._group.remove(this),this._isPlaying=!1,this._isPaused=!1,this._onStopCallback&&this._onStopCallback(this._object),this):this},o.prototype.end=function(){return this._goToEnd=!0,this.update(1/0),this},o.prototype.pause=function(e){return e===void 0&&(e=ot()),this._isPaused||!this._isPlaying?this:(this._isPaused=!0,this._pauseStart=e,this._group&&this._group.remove(this),this)},o.prototype.resume=function(e){return e===void 0&&(e=ot()),!this._isPaused||!this._isPlaying?this:(this._isPaused=!1,this._startTime+=e-this._pauseStart,this._pauseStart=0,this._group&&this._group.add(this),this)},o.prototype.stopChainedTweens=function(){for(var e=0,t=this._chainedTweens.length;e<t;e++)this._chainedTweens[e].stop();return this},o.prototype.group=function(e){return e===void 0&&(e=Ni),this._group=e,this},o.prototype.delay=function(e){return e===void 0&&(e=0),this._delayTime=e,this},o.prototype.repeat=function(e){return e===void 0&&(e=0),this._initialRepeat=e,this._repeat=e,this},o.prototype.repeatDelay=function(e){return this._repeatDelayTime=e,this},o.prototype.yoyo=function(e){return e===void 0&&(e=!1),this._yoyo=e,this},o.prototype.easing=function(e){return e===void 0&&(e=lt.Linear.None),this._easingFunction=e,this},o.prototype.interpolation=function(e){return e===void 0&&(e=Ue.Linear),this._interpolationFunction=e,this},o.prototype.chain=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this._chainedTweens=e,this},o.prototype.onStart=function(e){return this._onStartCallback=e,this},o.prototype.onEveryStart=function(e){return this._onEveryStartCallback=e,this},o.prototype.onUpdate=function(e){return this._onUpdateCallback=e,this},o.prototype.onRepeat=function(e){return this._onRepeatCallback=e,this},o.prototype.onComplete=function(e){return this._onCompleteCallback=e,this},o.prototype.onStop=function(e){return this._onStopCallback=e,this},o.prototype.update=function(e,t){var i=this,s;if(e===void 0&&(e=ot()),t===void 0&&(t=!0),this._isPaused)return!0;var a,n=this._startTime+this._duration;if(!this._goToEnd&&!this._isPlaying){if(e>n)return!1;t&&this.start(e,!0)}if(this._goToEnd=!1,e<this._startTime)return!0;this._onStartCallbackFired===!1&&(this._onStartCallback&&this._onStartCallback(this._object),this._onStartCallbackFired=!0),this._onEveryStartCallbackFired===!1&&(this._onEveryStartCallback&&this._onEveryStartCallback(this._object),this._onEveryStartCallbackFired=!0);var c=e-this._startTime,h=this._duration+((s=this._repeatDelayTime)!==null&&s!==void 0?s:this._delayTime),f=this._duration+this._repeat*h,p=function(){if(i._duration===0||c>f)return 1;var m=Math.trunc(c/h),v=c-m*h,_=Math.min(v/i._duration,1);return _===0&&c===i._duration?1:_},r=p(),l=this._easingFunction(r);if(this._updateProperties(this._object,this._valuesStart,this._valuesEnd,l),this._onUpdateCallback&&this._onUpdateCallback(this._object,r),this._duration===0||c>=this._duration)if(this._repeat>0){var u=Math.min(Math.trunc((c-this._duration)/h)+1,this._repeat);isFinite(this._repeat)&&(this._repeat-=u);for(a in this._valuesStartRepeat)!this._yoyo&&typeof this._valuesEnd[a]=="string"&&(this._valuesStartRepeat[a]=this._valuesStartRepeat[a]+parseFloat(this._valuesEnd[a])),this._yoyo&&this._swapEndStartRepeatValues(a),this._valuesStart[a]=this._valuesStartRepeat[a];return this._yoyo&&(this._reversed=!this._reversed),this._startTime+=h*u,this._onRepeatCallback&&this._onRepeatCallback(this._object),this._onEveryStartCallbackFired=!1,!0}else{this._onCompleteCallback&&this._onCompleteCallback(this._object);for(var g=0,y=this._chainedTweens.length;g<y;g++)this._chainedTweens[g].start(this._startTime+this._duration,!1);return this._isPlaying=!1,!1}return!0},o.prototype._updateProperties=function(e,t,i,s){for(var a in i)if(t[a]!==void 0){var n=t[a]||0,c=i[a],h=Array.isArray(e[a]),f=Array.isArray(c),p=!h&&f;p?e[a]=this._interpolationFunction(c,s):typeof c=="object"&&c?this._updateProperties(e[a],n,c,s):(c=this._handleRelativeValue(n,c),typeof c=="number"&&(e[a]=n+(c-n)*s))}},o.prototype._handleRelativeValue=function(e,t){return typeof t!="string"?t:t.charAt(0)==="+"||t.charAt(0)==="-"?e+parseFloat(t):parseFloat(t)},o.prototype._swapEndStartRepeatValues=function(e){var t=this._valuesStartRepeat[e],i=this._valuesEnd[e];typeof i=="string"?this._valuesStartRepeat[e]=this._valuesStartRepeat[e]+parseFloat(i):this._valuesStartRepeat[e]=this._valuesEnd[e],this._valuesEnd[e]=t},o}(),Ta="23.1.3",Sa=us.nextId,ve=Ni,Ma=ve.getAll.bind(ve),Ca=ve.removeAll.bind(ve),Ra=ve.add.bind(ve),La=ve.remove.bind(ve),Ia=ve.update.bind(ve),Pe={Easing:lt,Group:Fr,Interpolation:Ue,now:ot,Sequence:us,nextId:Sa,Tween:ci,VERSION:Ta,getAll:Ma,removeAll:Ca,add:Ra,remove:La,update:Ia},xt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Da(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var Er={exports:{}};(function(o){var e=Object.prototype.hasOwnProperty,t="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(t=!1));function s(h,f,p){this.fn=h,this.context=f,this.once=p||!1}function a(h,f,p,r,l){if(typeof p!="function")throw new TypeError("The listener must be a function");var u=new s(p,r||h,l),g=t?t+f:f;return h._events[g]?h._events[g].fn?h._events[g]=[h._events[g],u]:h._events[g].push(u):(h._events[g]=u,h._eventsCount++),h}function n(h,f){--h._eventsCount===0?h._events=new i:delete h._events[f]}function c(){this._events=new i,this._eventsCount=0}c.prototype.eventNames=function(){var f=[],p,r;if(this._eventsCount===0)return f;for(r in p=this._events)e.call(p,r)&&f.push(t?r.slice(1):r);return Object.getOwnPropertySymbols?f.concat(Object.getOwnPropertySymbols(p)):f},c.prototype.listeners=function(f){var p=t?t+f:f,r=this._events[p];if(!r)return[];if(r.fn)return[r.fn];for(var l=0,u=r.length,g=new Array(u);l<u;l++)g[l]=r[l].fn;return g},c.prototype.listenerCount=function(f){var p=t?t+f:f,r=this._events[p];return r?r.fn?1:r.length:0},c.prototype.emit=function(f,p,r,l,u,g){var y=t?t+f:f;if(!this._events[y])return!1;var m=this._events[y],v=arguments.length,_,x;if(m.fn){switch(m.once&&this.removeListener(f,m.fn,void 0,!0),v){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,p),!0;case 3:return m.fn.call(m.context,p,r),!0;case 4:return m.fn.call(m.context,p,r,l),!0;case 5:return m.fn.call(m.context,p,r,l,u),!0;case 6:return m.fn.call(m.context,p,r,l,u,g),!0}for(x=1,_=new Array(v-1);x<v;x++)_[x-1]=arguments[x];m.fn.apply(m.context,_)}else{var w=m.length,b;for(x=0;x<w;x++)switch(m[x].once&&this.removeListener(f,m[x].fn,void 0,!0),v){case 1:m[x].fn.call(m[x].context);break;case 2:m[x].fn.call(m[x].context,p);break;case 3:m[x].fn.call(m[x].context,p,r);break;case 4:m[x].fn.call(m[x].context,p,r,l);break;default:if(!_)for(b=1,_=new Array(v-1);b<v;b++)_[b-1]=arguments[b];m[x].fn.apply(m[x].context,_)}}return!0},c.prototype.on=function(f,p,r){return a(this,f,p,r,!1)},c.prototype.once=function(f,p,r){return a(this,f,p,r,!0)},c.prototype.removeListener=function(f,p,r,l){var u=t?t+f:f;if(!this._events[u])return this;if(!p)return n(this,u),this;var g=this._events[u];if(g.fn)g.fn===p&&(!l||g.once)&&(!r||g.context===r)&&n(this,u);else{for(var y=0,m=[],v=g.length;y<v;y++)(g[y].fn!==p||l&&!g[y].once||r&&g[y].context!==r)&&m.push(g[y]);m.length?this._events[u]=m.length===1?m[0]:m:n(this,u)}return this},c.prototype.removeAllListeners=function(f){var p;return f?(p=t?t+f:f,this._events[p]&&n(this,p)):(this._events=new i,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=t,c.EventEmitter=c,o.exports=c})(Er);var Pa=Er.exports;const pt=Da(Pa);var Dt=function(){var o=0,e=document.createElement("div");e.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000",e.addEventListener("click",function(r){r.preventDefault(),i(++o%e.children.length)},!1);function t(r){return e.appendChild(r.dom),r}function i(r){for(var l=0;l<e.children.length;l++)e.children[l].style.display=l===r?"block":"none";o=r}var s=(performance||Date).now(),a=s,n=0,c=t(new Dt.Panel("FPS","#0ff","#002")),h=t(new Dt.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var f=t(new Dt.Panel("MB","#f08","#201"));i(0);var p=0;return{REVISION:16,dom:e,fps:function(){return p&&parseInt(p.toFixed(0))},addPanel:t,showPanel:i,begin:function(){s=(performance||Date).now()},end:function(){n++;var r=(performance||Date).now();if(h.update(r-s,200),r>=a+1e3&&(p=n*1e3/(r-a),c.update(p,100),a=r,n=0,f)){var l=performance.memory;f.update(l.usedJSHeapSize/1048576,l.jsHeapSizeLimit/1048576)}return r},update:function(){s=this.end()},domElement:e,setMode:i}};Dt.Panel=function(o,e,t){var i=1/0,s=0,a=Math.round,n=a(window.devicePixelRatio||1),c=80*n,h=48*n,f=3*n,p=2*n,r=3*n,l=15*n,u=74*n,g=30*n,y=document.createElement("canvas");y.width=c,y.height=h,y.style.cssText="width:80px;height:48px";var m=y.getContext("2d");return m.font="bold "+9*n+"px Helvetica,Arial,sans-serif",m.textBaseline="top",m.fillStyle=t,m.fillRect(0,0,c,h),m.fillStyle=e,m.fillText(o,f,p),m.fillRect(r,l,u,g),m.fillStyle=t,m.globalAlpha=.9,m.fillRect(r,l,u,g),{dom:y,update:function(v,_){i=Math.min(i,v),s=Math.max(s,v),m.fillStyle=t,m.globalAlpha=1,m.fillRect(0,0,c,l),m.fillStyle=e,m.fillText(a(v)+" "+o+" ("+a(i)+"-"+a(s)+")",f,p),m.drawImage(y,r+n,l,u-n,g,r,l,u-n,g),m.fillRect(r+u-n,l,n,g),m.fillStyle=t,m.globalAlpha=.9,m.fillRect(r+u-n,l,n,a((1-v/_)*g))}}};function Fa(o,e){const t=URL.createObjectURL(o),i=document.createElement("a");i.href=t,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(t)}function Br(o){return o.length===0?0:o.reduce((t,i)=>t+i,0)/o.length}function qi(o,e){const t=new Blob([o],{type:e});return URL.createObjectURL(t)}function kr(){return/Mac|iPod|iPhone|iPad/.test(navigator==null?void 0:navigator.platform)||/Mac OS|iOS/.test(navigator==null?void 0:navigator.userAgent)}function ji(o){let e=document.createElement("canvas");const t=e.getContext("2d");return e.width=o.width,e.height=o.height,t?(t.drawImage(o,0,0),e.toDataURL("image/png",.75)):void 0}function Ea(o,e=43){const t=o*Math.PI/180;return e/(2*Math.tan(t/2))}var Or={};/*!
3687
+ ${t.name}`)}break}}}}else r.texture_lod=0}};ae=new WeakMap,Me=new WeakMap,Ai=new WeakMap,Oe=new WeakMap,gt=new WeakMap,Ti=new WeakMap,Ce=new WeakMap,E(q,"debugDrawLine"),E(q,"corner0",new f.Vector3),E(q,"corner1",new f.Vector3),E(q,"corner2",new f.Vector3),E(q,"corner3",new f.Vector3),E(q,"_tempPtInside",new f.Vector3),E(q,"skinnedMeshBoundsFrameOffsetCounter",0),E(q,"$skinnedMeshBoundsOffset",Symbol("gltf-progressive-skinnedMeshBoundsOffset"));let yt=q;class Ba{constructor(){E(this,"frames",0);E(this,"lastLodLevel_Mesh",-1);E(this,"lastLodLevel_Texture",-1);E(this,"lastScreenCoverage",0);E(this,"lastScreenspaceVolume",new f.Vector3);E(this,"lastCentrality",0)}}const sr=Symbol("NEEDLE_mesh_lod"),$t=Symbol("NEEDLE_texture_lod");let Tt=null;function Zr(){const a=Oa();a&&(a.mapURLs(function(e){return rr(),e}),rr(),Tt==null||Tt.disconnect(),Tt=new MutationObserver(e=>{e.forEach(t=>{t.addedNodes.forEach(i=>{i instanceof HTMLElement&&i.tagName.toLowerCase()==="model-viewer"&&Kr(i)})})}),Tt.observe(document,{childList:!0,subtree:!0}))}function Oa(){if(typeof customElements>"u")return null;const a=customElements.get("model-viewer");return a||(customElements.whenDefined("model-viewer").then(()=>{console.debug("[gltf-progressive] model-viewer defined"),Zr()}),null)}function rr(){if(typeof document>"u")return;document.querySelectorAll("model-viewer").forEach(e=>{Kr(e)})}const nr=new WeakSet;let za=0;function Kr(a){if(!a||nr.has(a))return null;nr.add(a),console.debug("[gltf-progressive] found new model-viewer..."+ ++za+`
3688
+ `,a.getAttribute("src"));let e=null,t=null,i=null;for(let s=a;s!=null;s=Object.getPrototypeOf(s)){const r=Object.getOwnPropertySymbols(s),o=r.find(u=>u.toString()=="Symbol(renderer)"),c=r.find(u=>u.toString()=="Symbol(scene)"),h=r.find(u=>u.toString()=="Symbol(needsRender)");!e&&o!=null&&(e=a[o].threeRenderer),!t&&c!=null&&(t=a[c]),!i&&h!=null&&(i=a[h])}if(e&&t){let s=function(){if(i){let o=0,c=setInterval(()=>{if(o++>5){clearInterval(c);return}i==null||i.call(a)},300)}};console.debug("[gltf-progressive] setup model-viewer");const r=yt.get(e,{engine:"model-viewer"});return yt.addPlugin(new Va),r.enable(),r.addEventListener("changed",()=>{i==null||i.call(a)}),a.addEventListener("model-visibility",o=>{o.detail.visible&&(i==null||i.call(a))}),a.addEventListener("load",()=>{s()}),()=>{r.disable()}}return null}class Va{constructor(){E(this,"_didWarnAboutMissingUrl",!1)}onBeforeUpdateLOD(e,t,i,s){this.tryParseMeshLOD(t,s),this.tryParseTextureLOD(t,s)}getUrl(e){if(!e)return null;let t=e.getAttribute("src");return t||(t=e.src),t||(this._didWarnAboutMissingUrl||console.warn("No url found in modelviewer",e),this._didWarnAboutMissingUrl=!0),t}tryGetCurrentGLTF(e){return e._currentGLTF}tryGetCurrentModelViewer(e){return e.element}tryParseTextureLOD(e,t){if(t[$t]==!0)return;t[$t]=!0;const i=this.tryGetCurrentGLTF(e),s=this.tryGetCurrentModelViewer(e),r=this.getUrl(s);if(r&&i&&t.material){let o=function(h){var p,n,l;if(h[$t]==!0)return;h[$t]=!0,h.userData&&(h.userData.LOD=-1);const u=Object.keys(h);for(let d=0;d<u.length;d++){const g=u[d],v=h[g];if((v==null?void 0:v.isTexture)===!0){const m=(n=(p=v.userData)==null?void 0:p.associations)==null?void 0:n.textures;if(m==null)continue;const _=i.parser.json.textures[m];if(!_){console.warn("Texture data not found for texture index "+m);continue}if((l=_==null?void 0:_.extensions)!=null&&l[Se]){const y=_.extensions[Se];y&&r&&we.registerTexture(r,v,y.lods.length,m,y)}}}};const c=t.material;if(Array.isArray(c))for(const h of c)o(h);else o(c)}}tryParseMeshLOD(e,t){var o,c;if(t[sr]==!0)return;t[sr]=!0;const i=this.tryGetCurrentModelViewer(e),s=this.getUrl(i);if(!s)return;const r=(c=(o=t.userData)==null?void 0:o.gltfExtensions)==null?void 0:c[Se];if(r&&s){const h=t.uuid;we.registerMesh(s,h,t,0,r.lods.length,r)}}}function Xr(...a){let e,t,i,s;switch(a.length){case 2:[i,t]=a,s={};break;case 3:[i,t,s]=a;break;case 4:[e,t,i,s]=a;break;default:throw new Error("Invalid arguments")}Gr(i),jr(i,{progressive:!0,...s==null?void 0:s.hints}),i.register(o=>new we(o));const r=yt.get(t);return(s==null?void 0:s.enableLODsManager)!==!1&&r.enable(),r}Zr();if(!Ta){const a={gltfProgressive:{useNeedleProgressive:Xr,LODsManager:yt,configureLoader:jr,getRaycastMesh:Ht,useRaycastMeshes:Ma}};if(!globalThis.Needle)globalThis.Needle=a;else for(const e in a)globalThis.Needle[e]=a[e]}var pt=Object.freeze({Linear:Object.freeze({None:function(a){return a},In:function(a){return a},Out:function(a){return a},InOut:function(a){return a}}),Quadratic:Object.freeze({In:function(a){return a*a},Out:function(a){return a*(2-a)},InOut:function(a){return(a*=2)<1?.5*a*a:-.5*(--a*(a-2)-1)}}),Cubic:Object.freeze({In:function(a){return a*a*a},Out:function(a){return--a*a*a+1},InOut:function(a){return(a*=2)<1?.5*a*a*a:.5*((a-=2)*a*a+2)}}),Quartic:Object.freeze({In:function(a){return a*a*a*a},Out:function(a){return 1- --a*a*a*a},InOut:function(a){return(a*=2)<1?.5*a*a*a*a:-.5*((a-=2)*a*a*a-2)}}),Quintic:Object.freeze({In:function(a){return a*a*a*a*a},Out:function(a){return--a*a*a*a*a+1},InOut:function(a){return(a*=2)<1?.5*a*a*a*a*a:.5*((a-=2)*a*a*a*a+2)}}),Sinusoidal:Object.freeze({In:function(a){return 1-Math.sin((1-a)*Math.PI/2)},Out:function(a){return Math.sin(a*Math.PI/2)},InOut:function(a){return .5*(1-Math.sin(Math.PI*(.5-a)))}}),Exponential:Object.freeze({In:function(a){return a===0?0:Math.pow(1024,a-1)},Out:function(a){return a===1?1:1-Math.pow(2,-10*a)},InOut:function(a){return a===0?0:a===1?1:(a*=2)<1?.5*Math.pow(1024,a-1):.5*(-Math.pow(2,-10*(a-1))+2)}}),Circular:Object.freeze({In:function(a){return 1-Math.sqrt(1-a*a)},Out:function(a){return Math.sqrt(1- --a*a)},InOut:function(a){return(a*=2)<1?-.5*(Math.sqrt(1-a*a)-1):.5*(Math.sqrt(1-(a-=2)*a)+1)}}),Elastic:Object.freeze({In:function(a){return a===0?0:a===1?1:-Math.pow(2,10*(a-1))*Math.sin((a-1.1)*5*Math.PI)},Out:function(a){return a===0?0:a===1?1:Math.pow(2,-10*a)*Math.sin((a-.1)*5*Math.PI)+1},InOut:function(a){return a===0?0:a===1?1:(a*=2,a<1?-.5*Math.pow(2,10*(a-1))*Math.sin((a-1.1)*5*Math.PI):.5*Math.pow(2,-10*(a-1))*Math.sin((a-1.1)*5*Math.PI)+1)}}),Back:Object.freeze({In:function(a){var e=1.70158;return a===1?1:a*a*((e+1)*a-e)},Out:function(a){var e=1.70158;return a===0?0:--a*a*((e+1)*a+e)+1},InOut:function(a){var e=2.5949095;return(a*=2)<1?.5*(a*a*((e+1)*a-e)):.5*((a-=2)*a*((e+1)*a+e)+2)}}),Bounce:Object.freeze({In:function(a){return 1-pt.Bounce.Out(1-a)},Out:function(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+.9375:7.5625*(a-=2.625/2.75)*a+.984375},InOut:function(a){return a<.5?pt.Bounce.In(a*2)*.5:pt.Bounce.Out(a*2-1)*.5+.5}}),generatePow:function(a){return a===void 0&&(a=4),a=a<Number.EPSILON?Number.EPSILON:a,a=a>1e4?1e4:a,{In:function(e){return Math.pow(e,a)},Out:function(e){return 1-Math.pow(1-e,a)},InOut:function(e){return e<.5?Math.pow(e*2,a)/2:(1-Math.pow(2-e*2,a))/2+.5}}}}),ft=function(){return performance.now()},Jr=function(){function a(){this._tweens={},this._tweensAddedDuringUpdate={}}return a.prototype.getAll=function(){var e=this;return Object.keys(this._tweens).map(function(t){return e._tweens[t]})},a.prototype.removeAll=function(){this._tweens={}},a.prototype.add=function(e){this._tweens[e.getId()]=e,this._tweensAddedDuringUpdate[e.getId()]=e},a.prototype.remove=function(e){delete this._tweens[e.getId()],delete this._tweensAddedDuringUpdate[e.getId()]},a.prototype.update=function(e,t){e===void 0&&(e=ft()),t===void 0&&(t=!1);var i=Object.keys(this._tweens);if(i.length===0)return!1;for(;i.length>0;){this._tweensAddedDuringUpdate={};for(var s=0;s<i.length;s++){var r=this._tweens[i[s]],o=!t;r&&r.update(e,o)===!1&&!t&&delete this._tweens[i[s]]}i=Object.keys(this._tweensAddedDuringUpdate)}return!0},a}(),Qe={Linear:function(a,e){var t=a.length-1,i=t*e,s=Math.floor(i),r=Qe.Utils.Linear;return e<0?r(a[0],a[1],i):e>1?r(a[t],a[t-1],t-i):r(a[s],a[s+1>t?t:s+1],i-s)},Bezier:function(a,e){for(var t=0,i=a.length-1,s=Math.pow,r=Qe.Utils.Bernstein,o=0;o<=i;o++)t+=s(1-e,i-o)*s(e,o)*a[o]*r(i,o);return t},CatmullRom:function(a,e){var t=a.length-1,i=t*e,s=Math.floor(i),r=Qe.Utils.CatmullRom;return a[0]===a[t]?(e<0&&(s=Math.floor(i=t*(1+e))),r(a[(s-1+t)%t],a[s],a[(s+1)%t],a[(s+2)%t],i-s)):e<0?a[0]-(r(a[0],a[0],a[1],a[1],-i)-a[0]):e>1?a[t]-(r(a[t],a[t],a[t-1],a[t-1],i-t)-a[t]):r(a[s?s-1:0],a[s],a[t<s+1?t:s+1],a[t<s+2?t:s+2],i-s)},Utils:{Linear:function(a,e,t){return(e-a)*t+a},Bernstein:function(a,e){var t=Qe.Utils.Factorial;return t(a)/t(e)/t(a-e)},Factorial:function(){var a=[1];return function(e){var t=1;if(a[e])return a[e];for(var i=e;i>1;i--)t*=i;return a[e]=t,t}}(),CatmullRom:function(a,e,t,i,s){var r=(t-a)*.5,o=(i-e)*.5,c=s*s,h=s*c;return(2*e-2*t+r+o)*h+(-3*e+3*t-2*r-o)*c+r*s+e}}},Ms=function(){function a(){}return a.nextId=function(){return a._nextId++},a._nextId=0,a}(),rs=new Jr,wi=function(){function a(e,t){t===void 0&&(t=rs),this._object=e,this._group=t,this._isPaused=!1,this._pauseStart=0,this._valuesStart={},this._valuesEnd={},this._valuesStartRepeat={},this._duration=1e3,this._isDynamic=!1,this._initialRepeat=0,this._repeat=0,this._yoyo=!1,this._isPlaying=!1,this._reversed=!1,this._delayTime=0,this._startTime=0,this._easingFunction=pt.Linear.None,this._interpolationFunction=Qe.Linear,this._chainedTweens=[],this._onStartCallbackFired=!1,this._onEveryStartCallbackFired=!1,this._id=Ms.nextId(),this._isChainStopped=!1,this._propertiesAreSetUp=!1,this._goToEnd=!1}return a.prototype.getId=function(){return this._id},a.prototype.isPlaying=function(){return this._isPlaying},a.prototype.isPaused=function(){return this._isPaused},a.prototype.getDuration=function(){return this._duration},a.prototype.to=function(e,t){if(t===void 0&&(t=1e3),this._isPlaying)throw new Error("Can not call Tween.to() while Tween is already started or paused. Stop the Tween first.");return this._valuesEnd=e,this._propertiesAreSetUp=!1,this._duration=t<0?0:t,this},a.prototype.duration=function(e){return e===void 0&&(e=1e3),this._duration=e<0?0:e,this},a.prototype.dynamic=function(e){return e===void 0&&(e=!1),this._isDynamic=e,this},a.prototype.start=function(e,t){if(e===void 0&&(e=ft()),t===void 0&&(t=!1),this._isPlaying)return this;if(this._group&&this._group.add(this),this._repeat=this._initialRepeat,this._reversed){this._reversed=!1;for(var i in this._valuesStartRepeat)this._swapEndStartRepeatValues(i),this._valuesStart[i]=this._valuesStartRepeat[i]}if(this._isPlaying=!0,this._isPaused=!1,this._onStartCallbackFired=!1,this._onEveryStartCallbackFired=!1,this._isChainStopped=!1,this._startTime=e,this._startTime+=this._delayTime,!this._propertiesAreSetUp||t){if(this._propertiesAreSetUp=!0,!this._isDynamic){var s={};for(var r in this._valuesEnd)s[r]=this._valuesEnd[r];this._valuesEnd=s}this._setupProperties(this._object,this._valuesStart,this._valuesEnd,this._valuesStartRepeat,t)}return this},a.prototype.startFromCurrentValues=function(e){return this.start(e,!0)},a.prototype._setupProperties=function(e,t,i,s,r){for(var o in i){var c=e[o],h=Array.isArray(c),u=h?"array":typeof c,p=!h&&Array.isArray(i[o]);if(!(u==="undefined"||u==="function")){if(p){var n=i[o];if(n.length===0)continue;for(var l=[c],d=0,g=n.length;d<g;d+=1){var v=this._handleRelativeValue(c,n[d]);if(isNaN(v)){p=!1,console.warn("Found invalid interpolation list. Skipping.");break}l.push(v)}p&&(i[o]=l)}if((u==="object"||h)&&c&&!p){t[o]=h?[]:{};var m=c;for(var _ in m)t[o][_]=m[_];s[o]=h?[]:{};var n=i[o];if(!this._isDynamic){var y={};for(var _ in n)y[_]=n[_];i[o]=n=y}this._setupProperties(m,t[o],n,s[o],r)}else(typeof t[o]>"u"||r)&&(t[o]=c),h||(t[o]*=1),p?s[o]=i[o].slice().reverse():s[o]=t[o]||0}}},a.prototype.stop=function(){return this._isChainStopped||(this._isChainStopped=!0,this.stopChainedTweens()),this._isPlaying?(this._group&&this._group.remove(this),this._isPlaying=!1,this._isPaused=!1,this._onStopCallback&&this._onStopCallback(this._object),this):this},a.prototype.end=function(){return this._goToEnd=!0,this.update(1/0),this},a.prototype.pause=function(e){return e===void 0&&(e=ft()),this._isPaused||!this._isPlaying?this:(this._isPaused=!0,this._pauseStart=e,this._group&&this._group.remove(this),this)},a.prototype.resume=function(e){return e===void 0&&(e=ft()),!this._isPaused||!this._isPlaying?this:(this._isPaused=!1,this._startTime+=e-this._pauseStart,this._pauseStart=0,this._group&&this._group.add(this),this)},a.prototype.stopChainedTweens=function(){for(var e=0,t=this._chainedTweens.length;e<t;e++)this._chainedTweens[e].stop();return this},a.prototype.group=function(e){return e===void 0&&(e=rs),this._group=e,this},a.prototype.delay=function(e){return e===void 0&&(e=0),this._delayTime=e,this},a.prototype.repeat=function(e){return e===void 0&&(e=0),this._initialRepeat=e,this._repeat=e,this},a.prototype.repeatDelay=function(e){return this._repeatDelayTime=e,this},a.prototype.yoyo=function(e){return e===void 0&&(e=!1),this._yoyo=e,this},a.prototype.easing=function(e){return e===void 0&&(e=pt.Linear.None),this._easingFunction=e,this},a.prototype.interpolation=function(e){return e===void 0&&(e=Qe.Linear),this._interpolationFunction=e,this},a.prototype.chain=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this._chainedTweens=e,this},a.prototype.onStart=function(e){return this._onStartCallback=e,this},a.prototype.onEveryStart=function(e){return this._onEveryStartCallback=e,this},a.prototype.onUpdate=function(e){return this._onUpdateCallback=e,this},a.prototype.onRepeat=function(e){return this._onRepeatCallback=e,this},a.prototype.onComplete=function(e){return this._onCompleteCallback=e,this},a.prototype.onStop=function(e){return this._onStopCallback=e,this},a.prototype.update=function(e,t){var i=this,s;if(e===void 0&&(e=ft()),t===void 0&&(t=!0),this._isPaused)return!0;var r,o=this._startTime+this._duration;if(!this._goToEnd&&!this._isPlaying){if(e>o)return!1;t&&this.start(e,!0)}if(this._goToEnd=!1,e<this._startTime)return!0;this._onStartCallbackFired===!1&&(this._onStartCallback&&this._onStartCallback(this._object),this._onStartCallbackFired=!0),this._onEveryStartCallbackFired===!1&&(this._onEveryStartCallback&&this._onEveryStartCallback(this._object),this._onEveryStartCallbackFired=!0);var c=e-this._startTime,h=this._duration+((s=this._repeatDelayTime)!==null&&s!==void 0?s:this._delayTime),u=this._duration+this._repeat*h,p=function(){if(i._duration===0||c>u)return 1;var m=Math.trunc(c/h),_=c-m*h,y=Math.min(_/i._duration,1);return y===0&&c===i._duration?1:y},n=p(),l=this._easingFunction(n);if(this._updateProperties(this._object,this._valuesStart,this._valuesEnd,l),this._onUpdateCallback&&this._onUpdateCallback(this._object,n),this._duration===0||c>=this._duration)if(this._repeat>0){var d=Math.min(Math.trunc((c-this._duration)/h)+1,this._repeat);isFinite(this._repeat)&&(this._repeat-=d);for(r in this._valuesStartRepeat)!this._yoyo&&typeof this._valuesEnd[r]=="string"&&(this._valuesStartRepeat[r]=this._valuesStartRepeat[r]+parseFloat(this._valuesEnd[r])),this._yoyo&&this._swapEndStartRepeatValues(r),this._valuesStart[r]=this._valuesStartRepeat[r];return this._yoyo&&(this._reversed=!this._reversed),this._startTime+=h*d,this._onRepeatCallback&&this._onRepeatCallback(this._object),this._onEveryStartCallbackFired=!1,!0}else{this._onCompleteCallback&&this._onCompleteCallback(this._object);for(var g=0,v=this._chainedTweens.length;g<v;g++)this._chainedTweens[g].start(this._startTime+this._duration,!1);return this._isPlaying=!1,!1}return!0},a.prototype._updateProperties=function(e,t,i,s){for(var r in i)if(t[r]!==void 0){var o=t[r]||0,c=i[r],h=Array.isArray(e[r]),u=Array.isArray(c),p=!h&&u;p?e[r]=this._interpolationFunction(c,s):typeof c=="object"&&c?this._updateProperties(e[r],o,c,s):(c=this._handleRelativeValue(o,c),typeof c=="number"&&(e[r]=o+(c-o)*s))}},a.prototype._handleRelativeValue=function(e,t){return typeof t!="string"?t:t.charAt(0)==="+"||t.charAt(0)==="-"?e+parseFloat(t):parseFloat(t)},a.prototype._swapEndStartRepeatValues=function(e){var t=this._valuesStartRepeat[e],i=this._valuesEnd[e];typeof i=="string"?this._valuesStartRepeat[e]=this._valuesStartRepeat[e]+parseFloat(i):this._valuesStartRepeat[e]=this._valuesEnd[e],this._valuesEnd[e]=t},a}(),Wa="23.1.3",Ua=Ms.nextId,Ae=rs,Ha=Ae.getAll.bind(Ae),Ga=Ae.removeAll.bind(Ae),Na=Ae.add.bind(Ae),Qa=Ae.remove.bind(Ae),ja=Ae.update.bind(Ae),ne={Easing:pt,Group:Jr,Interpolation:Qe,now:ft,Sequence:Ms,nextId:Ua,Tween:wi,VERSION:Wa,getAll:Ha,removeAll:Ga,add:Na,remove:Qa,update:ja},St=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function qa(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}var $r={exports:{}};(function(a){var e=Object.prototype.hasOwnProperty,t="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(t=!1));function s(h,u,p){this.fn=h,this.context=u,this.once=p||!1}function r(h,u,p,n,l){if(typeof p!="function")throw new TypeError("The listener must be a function");var d=new s(p,n||h,l),g=t?t+u:u;return h._events[g]?h._events[g].fn?h._events[g]=[h._events[g],d]:h._events[g].push(d):(h._events[g]=d,h._eventsCount++),h}function o(h,u){--h._eventsCount===0?h._events=new i:delete h._events[u]}function c(){this._events=new i,this._eventsCount=0}c.prototype.eventNames=function(){var u=[],p,n;if(this._eventsCount===0)return u;for(n in p=this._events)e.call(p,n)&&u.push(t?n.slice(1):n);return Object.getOwnPropertySymbols?u.concat(Object.getOwnPropertySymbols(p)):u},c.prototype.listeners=function(u){var p=t?t+u:u,n=this._events[p];if(!n)return[];if(n.fn)return[n.fn];for(var l=0,d=n.length,g=new Array(d);l<d;l++)g[l]=n[l].fn;return g},c.prototype.listenerCount=function(u){var p=t?t+u:u,n=this._events[p];return n?n.fn?1:n.length:0},c.prototype.emit=function(u,p,n,l,d,g){var v=t?t+u:u;if(!this._events[v])return!1;var m=this._events[v],_=arguments.length,y,w;if(m.fn){switch(m.once&&this.removeListener(u,m.fn,void 0,!0),_){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,p),!0;case 3:return m.fn.call(m.context,p,n),!0;case 4:return m.fn.call(m.context,p,n,l),!0;case 5:return m.fn.call(m.context,p,n,l,d),!0;case 6:return m.fn.call(m.context,p,n,l,d,g),!0}for(w=1,y=new Array(_-1);w<_;w++)y[w-1]=arguments[w];m.fn.apply(m.context,y)}else{var x=m.length,b;for(w=0;w<x;w++)switch(m[w].once&&this.removeListener(u,m[w].fn,void 0,!0),_){case 1:m[w].fn.call(m[w].context);break;case 2:m[w].fn.call(m[w].context,p);break;case 3:m[w].fn.call(m[w].context,p,n);break;case 4:m[w].fn.call(m[w].context,p,n,l);break;default:if(!y)for(b=1,y=new Array(_-1);b<_;b++)y[b-1]=arguments[b];m[w].fn.apply(m[w].context,y)}}return!0},c.prototype.on=function(u,p,n){return r(this,u,p,n,!1)},c.prototype.once=function(u,p,n){return r(this,u,p,n,!0)},c.prototype.removeListener=function(u,p,n,l){var d=t?t+u:u;if(!this._events[d])return this;if(!p)return o(this,d),this;var g=this._events[d];if(g.fn)g.fn===p&&(!l||g.once)&&(!n||g.context===n)&&o(this,d);else{for(var v=0,m=[],_=g.length;v<_;v++)(g[v].fn!==p||l&&!g[v].once||n&&g[v].context!==n)&&m.push(g[v]);m.length?this._events[d]=m.length===1?m[0]:m:o(this,d)}return this},c.prototype.removeAllListeners=function(u){var p;return u?(p=t?t+u:u,this._events[p]&&o(this,p)):(this._events=new i,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=t,c.EventEmitter=c,a.exports=c})($r);var Ya=$r.exports;const Ye=qa(Ya);var zt=function(){var a=0,e=document.createElement("div");e.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000",e.addEventListener("click",function(n){n.preventDefault(),i(++a%e.children.length)},!1);function t(n){return e.appendChild(n.dom),n}function i(n){for(var l=0;l<e.children.length;l++)e.children[l].style.display=l===n?"block":"none";a=n}var s=(performance||Date).now(),r=s,o=0,c=t(new zt.Panel("FPS","#0ff","#002")),h=t(new zt.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var u=t(new zt.Panel("MB","#f08","#201"));i(0);var p=0;return{REVISION:16,dom:e,fps:function(){return p&&parseInt(p.toFixed(0))},addPanel:t,showPanel:i,begin:function(){s=(performance||Date).now()},end:function(){o++;var n=(performance||Date).now();if(h.update(n-s,200),n>=r+1e3&&(p=o*1e3/(n-r),c.update(p,100),r=n,o=0,u)){var l=performance.memory;u.update(l.usedJSHeapSize/1048576,l.jsHeapSizeLimit/1048576)}return n},update:function(){s=this.end()},domElement:e,setMode:i}};zt.Panel=function(a,e,t){var i=1/0,s=0,r=Math.round,o=r(window.devicePixelRatio||1),c=80*o,h=48*o,u=3*o,p=2*o,n=3*o,l=15*o,d=74*o,g=30*o,v=document.createElement("canvas");v.width=c,v.height=h,v.style.cssText="width:80px;height:48px";var m=v.getContext("2d");return m.font="bold "+9*o+"px Helvetica,Arial,sans-serif",m.textBaseline="top",m.fillStyle=t,m.fillRect(0,0,c,h),m.fillStyle=e,m.fillText(a,u,p),m.fillRect(n,l,d,g),m.fillStyle=t,m.globalAlpha=.9,m.fillRect(n,l,d,g),{dom:v,update:function(_,y){i=Math.min(i,_),s=Math.max(s,_),m.fillStyle=t,m.globalAlpha=1,m.fillRect(0,0,c,l),m.fillStyle=e,m.fillText(r(_)+" "+a+" ("+r(i)+"-"+r(s)+")",u,p),m.drawImage(v,n+o,l,d-o,g,n,l,d-o,g),m.fillRect(n+d-o,l,o,g),m.fillStyle=t,m.globalAlpha=.9,m.fillRect(n+d-o,l,o,r((1-_/y)*g))}}};function Za(a,e){const t=URL.createObjectURL(a),i=document.createElement("a");i.href=t,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(t)}function en(a){return a.length===0?0:a.reduce((t,i)=>t+i,0)/a.length}function ns(a,e){const t=new Blob([a],{type:e});return URL.createObjectURL(t)}function tn(){return/Mac|iPod|iPhone|iPad/.test(navigator==null?void 0:navigator.platform)||/Mac OS|iOS/.test(navigator==null?void 0:navigator.userAgent)}function os(a){let e=document.createElement("canvas");const t=e.getContext("2d");return e.width=a.width,e.height=a.height,t?(t.drawImage(a,0,0),e.toDataURL("image/png",.75)):void 0}function Ka(a,e=43){const t=a*Math.PI/180;return e/(2*Math.tan(t/2))}var sn={};/*!
3689
3689
  * howler.js v2.2.4
3690
3690
  * howlerjs.com
3691
3691
  *
@@ -3693,7 +3693,7 @@ ${t.name}`)}break}}}}else a.texture_lod=0}};ie=new WeakMap,xe=new WeakMap,ui=new
3693
3693
  * goldfirestudios.com
3694
3694
  *
3695
3695
  * MIT License
3696
- */(function(o){(function(){var e=function(){this.init()};e.prototype={init:function(){var r=this||t;return r._counter=1e3,r._html5AudioPool=[],r.html5PoolSize=10,r._codecs={},r._howls=[],r._muted=!1,r._volume=1,r._canPlayEvent="canplaythrough",r._navigator=typeof window<"u"&&window.navigator?window.navigator:null,r.masterGain=null,r.noAudio=!1,r.usingWebAudio=!0,r.autoSuspend=!0,r.ctx=null,r.autoUnlock=!0,r._setup(),r},volume:function(r){var l=this||t;if(r=parseFloat(r),l.ctx||p(),typeof r<"u"&&r>=0&&r<=1){if(l._volume=r,l._muted)return l;l.usingWebAudio&&l.masterGain.gain.setValueAtTime(r,t.ctx.currentTime);for(var u=0;u<l._howls.length;u++)if(!l._howls[u]._webAudio)for(var g=l._howls[u]._getSoundIds(),y=0;y<g.length;y++){var m=l._howls[u]._soundById(g[y]);m&&m._node&&(m._node.volume=m._volume*r)}return l}return l._volume},mute:function(r){var l=this||t;l.ctx||p(),l._muted=r,l.usingWebAudio&&l.masterGain.gain.setValueAtTime(r?0:l._volume,t.ctx.currentTime);for(var u=0;u<l._howls.length;u++)if(!l._howls[u]._webAudio)for(var g=l._howls[u]._getSoundIds(),y=0;y<g.length;y++){var m=l._howls[u]._soundById(g[y]);m&&m._node&&(m._node.muted=r?!0:m._muted)}return l},stop:function(){for(var r=this||t,l=0;l<r._howls.length;l++)r._howls[l].stop();return r},unload:function(){for(var r=this||t,l=r._howls.length-1;l>=0;l--)r._howls[l].unload();return r.usingWebAudio&&r.ctx&&typeof r.ctx.close<"u"&&(r.ctx.close(),r.ctx=null,p()),r},codecs:function(r){return(this||t)._codecs[r.replace(/^x-/,"")]},_setup:function(){var r=this||t;if(r.state=r.ctx&&r.ctx.state||"suspended",r._autoSuspend(),!r.usingWebAudio)if(typeof Audio<"u")try{var l=new Audio;typeof l.oncanplaythrough>"u"&&(r._canPlayEvent="canplay")}catch{r.noAudio=!0}else r.noAudio=!0;try{var l=new Audio;l.muted&&(r.noAudio=!0)}catch{}return r.noAudio||r._setupCodecs(),r},_setupCodecs:function(){var r=this||t,l=null;try{l=typeof Audio<"u"?new Audio:null}catch{return r}if(!l||typeof l.canPlayType!="function")return r;var u=l.canPlayType("audio/mpeg;").replace(/^no$/,""),g=r._navigator?r._navigator.userAgent:"",y=g.match(/OPR\/(\d+)/g),m=y&&parseInt(y[0].split("/")[1],10)<33,v=g.indexOf("Safari")!==-1&&g.indexOf("Chrome")===-1,_=g.match(/Version\/(.*?) /),x=v&&_&&parseInt(_[1],10)<15;return r._codecs={mp3:!!(!m&&(u||l.canPlayType("audio/mp3;").replace(/^no$/,""))),mpeg:!!u,opus:!!l.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/,""),ogg:!!l.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),oga:!!l.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),wav:!!(l.canPlayType('audio/wav; codecs="1"')||l.canPlayType("audio/wav")).replace(/^no$/,""),aac:!!l.canPlayType("audio/aac;").replace(/^no$/,""),caf:!!l.canPlayType("audio/x-caf;").replace(/^no$/,""),m4a:!!(l.canPlayType("audio/x-m4a;")||l.canPlayType("audio/m4a;")||l.canPlayType("audio/aac;")).replace(/^no$/,""),m4b:!!(l.canPlayType("audio/x-m4b;")||l.canPlayType("audio/m4b;")||l.canPlayType("audio/aac;")).replace(/^no$/,""),mp4:!!(l.canPlayType("audio/x-mp4;")||l.canPlayType("audio/mp4;")||l.canPlayType("audio/aac;")).replace(/^no$/,""),weba:!!(!x&&l.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,"")),webm:!!(!x&&l.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,"")),dolby:!!l.canPlayType('audio/mp4; codecs="ec-3"').replace(/^no$/,""),flac:!!(l.canPlayType("audio/x-flac;")||l.canPlayType("audio/flac;")).replace(/^no$/,"")},r},_unlockAudio:function(){var r=this||t;if(!(r._audioUnlocked||!r.ctx)){r._audioUnlocked=!1,r.autoUnlock=!1,!r._mobileUnloaded&&r.ctx.sampleRate!==44100&&(r._mobileUnloaded=!0,r.unload()),r._scratchBuffer=r.ctx.createBuffer(1,1,22050);var l=function(u){for(;r._html5AudioPool.length<r.html5PoolSize;)try{var g=new Audio;g._unlocked=!0,r._releaseHtml5Audio(g)}catch{r.noAudio=!0;break}for(var y=0;y<r._howls.length;y++)if(!r._howls[y]._webAudio)for(var m=r._howls[y]._getSoundIds(),v=0;v<m.length;v++){var _=r._howls[y]._soundById(m[v]);_&&_._node&&!_._node._unlocked&&(_._node._unlocked=!0,_._node.load())}r._autoResume();var x=r.ctx.createBufferSource();x.buffer=r._scratchBuffer,x.connect(r.ctx.destination),typeof x.start>"u"?x.noteOn(0):x.start(0),typeof r.ctx.resume=="function"&&r.ctx.resume(),x.onended=function(){x.disconnect(0),r._audioUnlocked=!0,document.removeEventListener("touchstart",l,!0),document.removeEventListener("touchend",l,!0),document.removeEventListener("click",l,!0),document.removeEventListener("keydown",l,!0);for(var w=0;w<r._howls.length;w++)r._howls[w]._emit("unlock")}};return document.addEventListener("touchstart",l,!0),document.addEventListener("touchend",l,!0),document.addEventListener("click",l,!0),document.addEventListener("keydown",l,!0),r}},_obtainHtml5Audio:function(){var r=this||t;if(r._html5AudioPool.length)return r._html5AudioPool.pop();var l=new Audio().play();return l&&typeof Promise<"u"&&(l instanceof Promise||typeof l.then=="function")&&l.catch(function(){console.warn("HTML5 Audio pool exhausted, returning potentially locked audio object.")}),new Audio},_releaseHtml5Audio:function(r){var l=this||t;return r._unlocked&&l._html5AudioPool.push(r),l},_autoSuspend:function(){var r=this;if(!(!r.autoSuspend||!r.ctx||typeof r.ctx.suspend>"u"||!t.usingWebAudio)){for(var l=0;l<r._howls.length;l++)if(r._howls[l]._webAudio){for(var u=0;u<r._howls[l]._sounds.length;u++)if(!r._howls[l]._sounds[u]._paused)return r}return r._suspendTimer&&clearTimeout(r._suspendTimer),r._suspendTimer=setTimeout(function(){if(r.autoSuspend){r._suspendTimer=null,r.state="suspending";var g=function(){r.state="suspended",r._resumeAfterSuspend&&(delete r._resumeAfterSuspend,r._autoResume())};r.ctx.suspend().then(g,g)}},3e4),r}},_autoResume:function(){var r=this;if(!(!r.ctx||typeof r.ctx.resume>"u"||!t.usingWebAudio))return r.state==="running"&&r.ctx.state!=="interrupted"&&r._suspendTimer?(clearTimeout(r._suspendTimer),r._suspendTimer=null):r.state==="suspended"||r.state==="running"&&r.ctx.state==="interrupted"?(r.ctx.resume().then(function(){r.state="running";for(var l=0;l<r._howls.length;l++)r._howls[l]._emit("resume")}),r._suspendTimer&&(clearTimeout(r._suspendTimer),r._suspendTimer=null)):r.state==="suspending"&&(r._resumeAfterSuspend=!0),r}};var t=new e,i=function(r){var l=this;if(!r.src||r.src.length===0){console.error("An array of source files must be passed with any new Howl.");return}l.init(r)};i.prototype={init:function(r){var l=this;return t.ctx||p(),l._autoplay=r.autoplay||!1,l._format=typeof r.format!="string"?r.format:[r.format],l._html5=r.html5||!1,l._muted=r.mute||!1,l._loop=r.loop||!1,l._pool=r.pool||5,l._preload=typeof r.preload=="boolean"||r.preload==="metadata"?r.preload:!0,l._rate=r.rate||1,l._sprite=r.sprite||{},l._src=typeof r.src!="string"?r.src:[r.src],l._volume=r.volume!==void 0?r.volume:1,l._xhr={method:r.xhr&&r.xhr.method?r.xhr.method:"GET",headers:r.xhr&&r.xhr.headers?r.xhr.headers:null,withCredentials:r.xhr&&r.xhr.withCredentials?r.xhr.withCredentials:!1},l._duration=0,l._state="unloaded",l._sounds=[],l._endTimers={},l._queue=[],l._playLock=!1,l._onend=r.onend?[{fn:r.onend}]:[],l._onfade=r.onfade?[{fn:r.onfade}]:[],l._onload=r.onload?[{fn:r.onload}]:[],l._onloaderror=r.onloaderror?[{fn:r.onloaderror}]:[],l._onplayerror=r.onplayerror?[{fn:r.onplayerror}]:[],l._onpause=r.onpause?[{fn:r.onpause}]:[],l._onplay=r.onplay?[{fn:r.onplay}]:[],l._onstop=r.onstop?[{fn:r.onstop}]:[],l._onmute=r.onmute?[{fn:r.onmute}]:[],l._onvolume=r.onvolume?[{fn:r.onvolume}]:[],l._onrate=r.onrate?[{fn:r.onrate}]:[],l._onseek=r.onseek?[{fn:r.onseek}]:[],l._onunlock=r.onunlock?[{fn:r.onunlock}]:[],l._onresume=[],l._webAudio=t.usingWebAudio&&!l._html5,typeof t.ctx<"u"&&t.ctx&&t.autoUnlock&&t._unlockAudio(),t._howls.push(l),l._autoplay&&l._queue.push({event:"play",action:function(){l.play()}}),l._preload&&l._preload!=="none"&&l.load(),l},load:function(){var r=this,l=null;if(t.noAudio){r._emit("loaderror",null,"No audio support.");return}typeof r._src=="string"&&(r._src=[r._src]);for(var u=0;u<r._src.length;u++){var g,y;if(r._format&&r._format[u])g=r._format[u];else{if(y=r._src[u],typeof y!="string"){r._emit("loaderror",null,"Non-string found in selected audio sources - ignoring.");continue}g=/^data:audio\/([^;,]+);/i.exec(y),g||(g=/\.([^.]+)$/.exec(y.split("?",1)[0])),g&&(g=g[1].toLowerCase())}if(g||console.warn('No file extension was found. Consider using the "format" property or specify an extension.'),g&&t.codecs(g)){l=r._src[u];break}}if(!l){r._emit("loaderror",null,"No codec support for selected audio sources.");return}return r._src=l,r._state="loading",window.location.protocol==="https:"&&l.slice(0,5)==="http:"&&(r._html5=!0,r._webAudio=!1),new s(r),r._webAudio&&n(r),r},play:function(r,l){var u=this,g=null;if(typeof r=="number")g=r,r=null;else{if(typeof r=="string"&&u._state==="loaded"&&!u._sprite[r])return null;if(typeof r>"u"&&(r="__default",!u._playLock)){for(var y=0,m=0;m<u._sounds.length;m++)u._sounds[m]._paused&&!u._sounds[m]._ended&&(y++,g=u._sounds[m]._id);y===1?r=null:g=null}}var v=g?u._soundById(g):u._inactiveSound();if(!v)return null;if(g&&!r&&(r=v._sprite||"__default"),u._state!=="loaded"){v._sprite=r,v._ended=!1;var _=v._id;return u._queue.push({event:"play",action:function(){u.play(_)}}),_}if(g&&!v._paused)return l||u._loadQueue("play"),v._id;u._webAudio&&t._autoResume();var x=Math.max(0,v._seek>0?v._seek:u._sprite[r][0]/1e3),w=Math.max(0,(u._sprite[r][0]+u._sprite[r][1])/1e3-x),b=w*1e3/Math.abs(v._rate),T=u._sprite[r][0]/1e3,S=(u._sprite[r][0]+u._sprite[r][1])/1e3;v._sprite=r,v._ended=!1;var L=function(){v._paused=!1,v._seek=x,v._start=T,v._stop=S,v._loop=!!(v._loop||u._sprite[r][2])};if(x>=S){u._ended(v);return}var C=v._node;if(u._webAudio){var D=function(){u._playLock=!1,L(),u._refreshBuffer(v);var I=v._muted||u._muted?0:v._volume;C.gain.setValueAtTime(I,t.ctx.currentTime),v._playStart=t.ctx.currentTime,typeof C.bufferSource.start>"u"?v._loop?C.bufferSource.noteGrainOn(0,x,86400):C.bufferSource.noteGrainOn(0,x,w):v._loop?C.bufferSource.start(0,x,86400):C.bufferSource.start(0,x,w),b!==1/0&&(u._endTimers[v._id]=setTimeout(u._ended.bind(u,v),b)),l||setTimeout(function(){u._emit("play",v._id),u._loadQueue()},0)};t.state==="running"&&t.ctx.state!=="interrupted"?D():(u._playLock=!0,u.once("resume",D),u._clearTimer(v._id))}else{var R=function(){C.currentTime=x,C.muted=v._muted||u._muted||t._muted||C.muted,C.volume=v._volume*t.volume(),C.playbackRate=v._rate;try{var I=C.play();if(I&&typeof Promise<"u"&&(I instanceof Promise||typeof I.then=="function")?(u._playLock=!0,L(),I.then(function(){u._playLock=!1,C._unlocked=!0,l?u._loadQueue():u._emit("play",v._id)}).catch(function(){u._playLock=!1,u._emit("playerror",v._id,"Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction."),v._ended=!0,v._paused=!0})):l||(u._playLock=!1,L(),u._emit("play",v._id)),C.playbackRate=v._rate,C.paused){u._emit("playerror",v._id,"Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction.");return}r!=="__default"||v._loop?u._endTimers[v._id]=setTimeout(u._ended.bind(u,v),b):(u._endTimers[v._id]=function(){u._ended(v),C.removeEventListener("ended",u._endTimers[v._id],!1)},C.addEventListener("ended",u._endTimers[v._id],!1))}catch(P){u._emit("playerror",v._id,P)}};C.src==="data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA"&&(C.src=u._src,C.load());var A=window&&window.ejecta||!C.readyState&&t._navigator.isCocoonJS;if(C.readyState>=3||A)R();else{u._playLock=!0,u._state="loading";var M=function(){u._state="loaded",R(),C.removeEventListener(t._canPlayEvent,M,!1)};C.addEventListener(t._canPlayEvent,M,!1),u._clearTimer(v._id)}}return v._id},pause:function(r){var l=this;if(l._state!=="loaded"||l._playLock)return l._queue.push({event:"pause",action:function(){l.pause(r)}}),l;for(var u=l._getSoundIds(r),g=0;g<u.length;g++){l._clearTimer(u[g]);var y=l._soundById(u[g]);if(y&&!y._paused&&(y._seek=l.seek(u[g]),y._rateSeek=0,y._paused=!0,l._stopFade(u[g]),y._node))if(l._webAudio){if(!y._node.bufferSource)continue;typeof y._node.bufferSource.stop>"u"?y._node.bufferSource.noteOff(0):y._node.bufferSource.stop(0),l._cleanBuffer(y._node)}else(!isNaN(y._node.duration)||y._node.duration===1/0)&&y._node.pause();arguments[1]||l._emit("pause",y?y._id:null)}return l},stop:function(r,l){var u=this;if(u._state!=="loaded"||u._playLock)return u._queue.push({event:"stop",action:function(){u.stop(r)}}),u;for(var g=u._getSoundIds(r),y=0;y<g.length;y++){u._clearTimer(g[y]);var m=u._soundById(g[y]);m&&(m._seek=m._start||0,m._rateSeek=0,m._paused=!0,m._ended=!0,u._stopFade(g[y]),m._node&&(u._webAudio?m._node.bufferSource&&(typeof m._node.bufferSource.stop>"u"?m._node.bufferSource.noteOff(0):m._node.bufferSource.stop(0),u._cleanBuffer(m._node)):(!isNaN(m._node.duration)||m._node.duration===1/0)&&(m._node.currentTime=m._start||0,m._node.pause(),m._node.duration===1/0&&u._clearSound(m._node))),l||u._emit("stop",m._id))}return u},mute:function(r,l){var u=this;if(u._state!=="loaded"||u._playLock)return u._queue.push({event:"mute",action:function(){u.mute(r,l)}}),u;if(typeof l>"u")if(typeof r=="boolean")u._muted=r;else return u._muted;for(var g=u._getSoundIds(l),y=0;y<g.length;y++){var m=u._soundById(g[y]);m&&(m._muted=r,m._interval&&u._stopFade(m._id),u._webAudio&&m._node?m._node.gain.setValueAtTime(r?0:m._volume,t.ctx.currentTime):m._node&&(m._node.muted=t._muted?!0:r),u._emit("mute",m._id))}return u},volume:function(){var r=this,l=arguments,u,g;if(l.length===0)return r._volume;if(l.length===1||l.length===2&&typeof l[1]>"u"){var y=r._getSoundIds(),m=y.indexOf(l[0]);m>=0?g=parseInt(l[0],10):u=parseFloat(l[0])}else l.length>=2&&(u=parseFloat(l[0]),g=parseInt(l[1],10));var v;if(typeof u<"u"&&u>=0&&u<=1){if(r._state!=="loaded"||r._playLock)return r._queue.push({event:"volume",action:function(){r.volume.apply(r,l)}}),r;typeof g>"u"&&(r._volume=u),g=r._getSoundIds(g);for(var _=0;_<g.length;_++)v=r._soundById(g[_]),v&&(v._volume=u,l[2]||r._stopFade(g[_]),r._webAudio&&v._node&&!v._muted?v._node.gain.setValueAtTime(u,t.ctx.currentTime):v._node&&!v._muted&&(v._node.volume=u*t.volume()),r._emit("volume",v._id))}else return v=g?r._soundById(g):r._sounds[0],v?v._volume:0;return r},fade:function(r,l,u,g){var y=this;if(y._state!=="loaded"||y._playLock)return y._queue.push({event:"fade",action:function(){y.fade(r,l,u,g)}}),y;r=Math.min(Math.max(0,parseFloat(r)),1),l=Math.min(Math.max(0,parseFloat(l)),1),u=parseFloat(u),y.volume(r,g);for(var m=y._getSoundIds(g),v=0;v<m.length;v++){var _=y._soundById(m[v]);if(_){if(g||y._stopFade(m[v]),y._webAudio&&!_._muted){var x=t.ctx.currentTime,w=x+u/1e3;_._volume=r,_._node.gain.setValueAtTime(r,x),_._node.gain.linearRampToValueAtTime(l,w)}y._startFadeInterval(_,r,l,u,m[v],typeof g>"u")}}return y},_startFadeInterval:function(r,l,u,g,y,m){var v=this,_=l,x=u-l,w=Math.abs(x/.01),b=Math.max(4,w>0?g/w:g),T=Date.now();r._fadeTo=u,r._interval=setInterval(function(){var S=(Date.now()-T)/g;T=Date.now(),_+=x*S,_=Math.round(_*100)/100,x<0?_=Math.max(u,_):_=Math.min(u,_),v._webAudio?r._volume=_:v.volume(_,r._id,!0),m&&(v._volume=_),(u<l&&_<=u||u>l&&_>=u)&&(clearInterval(r._interval),r._interval=null,r._fadeTo=null,v.volume(u,r._id),v._emit("fade",r._id))},b)},_stopFade:function(r){var l=this,u=l._soundById(r);return u&&u._interval&&(l._webAudio&&u._node.gain.cancelScheduledValues(t.ctx.currentTime),clearInterval(u._interval),u._interval=null,l.volume(u._fadeTo,r),u._fadeTo=null,l._emit("fade",r)),l},loop:function(){var r=this,l=arguments,u,g,y;if(l.length===0)return r._loop;if(l.length===1)if(typeof l[0]=="boolean")u=l[0],r._loop=u;else return y=r._soundById(parseInt(l[0],10)),y?y._loop:!1;else l.length===2&&(u=l[0],g=parseInt(l[1],10));for(var m=r._getSoundIds(g),v=0;v<m.length;v++)y=r._soundById(m[v]),y&&(y._loop=u,r._webAudio&&y._node&&y._node.bufferSource&&(y._node.bufferSource.loop=u,u&&(y._node.bufferSource.loopStart=y._start||0,y._node.bufferSource.loopEnd=y._stop,r.playing(m[v])&&(r.pause(m[v],!0),r.play(m[v],!0)))));return r},rate:function(){var r=this,l=arguments,u,g;if(l.length===0)g=r._sounds[0]._id;else if(l.length===1){var y=r._getSoundIds(),m=y.indexOf(l[0]);m>=0?g=parseInt(l[0],10):u=parseFloat(l[0])}else l.length===2&&(u=parseFloat(l[0]),g=parseInt(l[1],10));var v;if(typeof u=="number"){if(r._state!=="loaded"||r._playLock)return r._queue.push({event:"rate",action:function(){r.rate.apply(r,l)}}),r;typeof g>"u"&&(r._rate=u),g=r._getSoundIds(g);for(var _=0;_<g.length;_++)if(v=r._soundById(g[_]),v){r.playing(g[_])&&(v._rateSeek=r.seek(g[_]),v._playStart=r._webAudio?t.ctx.currentTime:v._playStart),v._rate=u,r._webAudio&&v._node&&v._node.bufferSource?v._node.bufferSource.playbackRate.setValueAtTime(u,t.ctx.currentTime):v._node&&(v._node.playbackRate=u);var x=r.seek(g[_]),w=(r._sprite[v._sprite][0]+r._sprite[v._sprite][1])/1e3-x,b=w*1e3/Math.abs(v._rate);(r._endTimers[g[_]]||!v._paused)&&(r._clearTimer(g[_]),r._endTimers[g[_]]=setTimeout(r._ended.bind(r,v),b)),r._emit("rate",v._id)}}else return v=r._soundById(g),v?v._rate:r._rate;return r},seek:function(){var r=this,l=arguments,u,g;if(l.length===0)r._sounds.length&&(g=r._sounds[0]._id);else if(l.length===1){var y=r._getSoundIds(),m=y.indexOf(l[0]);m>=0?g=parseInt(l[0],10):r._sounds.length&&(g=r._sounds[0]._id,u=parseFloat(l[0]))}else l.length===2&&(u=parseFloat(l[0]),g=parseInt(l[1],10));if(typeof g>"u")return 0;if(typeof u=="number"&&(r._state!=="loaded"||r._playLock))return r._queue.push({event:"seek",action:function(){r.seek.apply(r,l)}}),r;var v=r._soundById(g);if(v)if(typeof u=="number"&&u>=0){var _=r.playing(g);_&&r.pause(g,!0),v._seek=u,v._ended=!1,r._clearTimer(g),!r._webAudio&&v._node&&!isNaN(v._node.duration)&&(v._node.currentTime=u);var x=function(){_&&r.play(g,!0),r._emit("seek",g)};if(_&&!r._webAudio){var w=function(){r._playLock?setTimeout(w,0):x()};setTimeout(w,0)}else x()}else if(r._webAudio){var b=r.playing(g)?t.ctx.currentTime-v._playStart:0,T=v._rateSeek?v._rateSeek-v._seek:0;return v._seek+(T+b*Math.abs(v._rate))}else return v._node.currentTime;return r},playing:function(r){var l=this;if(typeof r=="number"){var u=l._soundById(r);return u?!u._paused:!1}for(var g=0;g<l._sounds.length;g++)if(!l._sounds[g]._paused)return!0;return!1},duration:function(r){var l=this,u=l._duration,g=l._soundById(r);return g&&(u=l._sprite[g._sprite][1]/1e3),u},state:function(){return this._state},unload:function(){for(var r=this,l=r._sounds,u=0;u<l.length;u++)l[u]._paused||r.stop(l[u]._id),r._webAudio||(r._clearSound(l[u]._node),l[u]._node.removeEventListener("error",l[u]._errorFn,!1),l[u]._node.removeEventListener(t._canPlayEvent,l[u]._loadFn,!1),l[u]._node.removeEventListener("ended",l[u]._endFn,!1),t._releaseHtml5Audio(l[u]._node)),delete l[u]._node,r._clearTimer(l[u]._id);var g=t._howls.indexOf(r);g>=0&&t._howls.splice(g,1);var y=!0;for(u=0;u<t._howls.length;u++)if(t._howls[u]._src===r._src||r._src.indexOf(t._howls[u]._src)>=0){y=!1;break}return a&&y&&delete a[r._src],t.noAudio=!1,r._state="unloaded",r._sounds=[],r=null,null},on:function(r,l,u,g){var y=this,m=y["_on"+r];return typeof l=="function"&&m.push(g?{id:u,fn:l,once:g}:{id:u,fn:l}),y},off:function(r,l,u){var g=this,y=g["_on"+r],m=0;if(typeof l=="number"&&(u=l,l=null),l||u)for(m=0;m<y.length;m++){var v=u===y[m].id;if(l===y[m].fn&&v||!l&&v){y.splice(m,1);break}}else if(r)g["_on"+r]=[];else{var _=Object.keys(g);for(m=0;m<_.length;m++)_[m].indexOf("_on")===0&&Array.isArray(g[_[m]])&&(g[_[m]]=[])}return g},once:function(r,l,u){var g=this;return g.on(r,l,u,1),g},_emit:function(r,l,u){for(var g=this,y=g["_on"+r],m=y.length-1;m>=0;m--)(!y[m].id||y[m].id===l||r==="load")&&(setTimeout((function(v){v.call(this,l,u)}).bind(g,y[m].fn),0),y[m].once&&g.off(r,y[m].fn,y[m].id));return g._loadQueue(r),g},_loadQueue:function(r){var l=this;if(l._queue.length>0){var u=l._queue[0];u.event===r&&(l._queue.shift(),l._loadQueue()),r||u.action()}return l},_ended:function(r){var l=this,u=r._sprite;if(!l._webAudio&&r._node&&!r._node.paused&&!r._node.ended&&r._node.currentTime<r._stop)return setTimeout(l._ended.bind(l,r),100),l;var g=!!(r._loop||l._sprite[u][2]);if(l._emit("end",r._id),!l._webAudio&&g&&l.stop(r._id,!0).play(r._id),l._webAudio&&g){l._emit("play",r._id),r._seek=r._start||0,r._rateSeek=0,r._playStart=t.ctx.currentTime;var y=(r._stop-r._start)*1e3/Math.abs(r._rate);l._endTimers[r._id]=setTimeout(l._ended.bind(l,r),y)}return l._webAudio&&!g&&(r._paused=!0,r._ended=!0,r._seek=r._start||0,r._rateSeek=0,l._clearTimer(r._id),l._cleanBuffer(r._node),t._autoSuspend()),!l._webAudio&&!g&&l.stop(r._id,!0),l},_clearTimer:function(r){var l=this;if(l._endTimers[r]){if(typeof l._endTimers[r]!="function")clearTimeout(l._endTimers[r]);else{var u=l._soundById(r);u&&u._node&&u._node.removeEventListener("ended",l._endTimers[r],!1)}delete l._endTimers[r]}return l},_soundById:function(r){for(var l=this,u=0;u<l._sounds.length;u++)if(r===l._sounds[u]._id)return l._sounds[u];return null},_inactiveSound:function(){var r=this;r._drain();for(var l=0;l<r._sounds.length;l++)if(r._sounds[l]._ended)return r._sounds[l].reset();return new s(r)},_drain:function(){var r=this,l=r._pool,u=0,g=0;if(!(r._sounds.length<l)){for(g=0;g<r._sounds.length;g++)r._sounds[g]._ended&&u++;for(g=r._sounds.length-1;g>=0;g--){if(u<=l)return;r._sounds[g]._ended&&(r._webAudio&&r._sounds[g]._node&&r._sounds[g]._node.disconnect(0),r._sounds.splice(g,1),u--)}}},_getSoundIds:function(r){var l=this;if(typeof r>"u"){for(var u=[],g=0;g<l._sounds.length;g++)u.push(l._sounds[g]._id);return u}else return[r]},_refreshBuffer:function(r){var l=this;return r._node.bufferSource=t.ctx.createBufferSource(),r._node.bufferSource.buffer=a[l._src],r._panner?r._node.bufferSource.connect(r._panner):r._node.bufferSource.connect(r._node),r._node.bufferSource.loop=r._loop,r._loop&&(r._node.bufferSource.loopStart=r._start||0,r._node.bufferSource.loopEnd=r._stop||0),r._node.bufferSource.playbackRate.setValueAtTime(r._rate,t.ctx.currentTime),l},_cleanBuffer:function(r){var l=this,u=t._navigator&&t._navigator.vendor.indexOf("Apple")>=0;if(!r.bufferSource)return l;if(t._scratchBuffer&&r.bufferSource&&(r.bufferSource.onended=null,r.bufferSource.disconnect(0),u))try{r.bufferSource.buffer=t._scratchBuffer}catch{}return r.bufferSource=null,l},_clearSound:function(r){var l=/MSIE |Trident\//.test(t._navigator&&t._navigator.userAgent);l||(r.src="data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA")}};var s=function(r){this._parent=r,this.init()};s.prototype={init:function(){var r=this,l=r._parent;return r._muted=l._muted,r._loop=l._loop,r._volume=l._volume,r._rate=l._rate,r._seek=0,r._paused=!0,r._ended=!0,r._sprite="__default",r._id=++t._counter,l._sounds.push(r),r.create(),r},create:function(){var r=this,l=r._parent,u=t._muted||r._muted||r._parent._muted?0:r._volume;return l._webAudio?(r._node=typeof t.ctx.createGain>"u"?t.ctx.createGainNode():t.ctx.createGain(),r._node.gain.setValueAtTime(u,t.ctx.currentTime),r._node.paused=!0,r._node.connect(t.masterGain)):t.noAudio||(r._node=t._obtainHtml5Audio(),r._errorFn=r._errorListener.bind(r),r._node.addEventListener("error",r._errorFn,!1),r._loadFn=r._loadListener.bind(r),r._node.addEventListener(t._canPlayEvent,r._loadFn,!1),r._endFn=r._endListener.bind(r),r._node.addEventListener("ended",r._endFn,!1),r._node.src=l._src,r._node.preload=l._preload===!0?"auto":l._preload,r._node.volume=u*t.volume(),r._node.load()),r},reset:function(){var r=this,l=r._parent;return r._muted=l._muted,r._loop=l._loop,r._volume=l._volume,r._rate=l._rate,r._seek=0,r._rateSeek=0,r._paused=!0,r._ended=!0,r._sprite="__default",r._id=++t._counter,r},_errorListener:function(){var r=this;r._parent._emit("loaderror",r._id,r._node.error?r._node.error.code:0),r._node.removeEventListener("error",r._errorFn,!1)},_loadListener:function(){var r=this,l=r._parent;l._duration=Math.ceil(r._node.duration*10)/10,Object.keys(l._sprite).length===0&&(l._sprite={__default:[0,l._duration*1e3]}),l._state!=="loaded"&&(l._state="loaded",l._emit("load"),l._loadQueue()),r._node.removeEventListener(t._canPlayEvent,r._loadFn,!1)},_endListener:function(){var r=this,l=r._parent;l._duration===1/0&&(l._duration=Math.ceil(r._node.duration*10)/10,l._sprite.__default[1]===1/0&&(l._sprite.__default[1]=l._duration*1e3),l._ended(r)),r._node.removeEventListener("ended",r._endFn,!1)}};var a={},n=function(r){var l=r._src;if(a[l]){r._duration=a[l].duration,f(r);return}if(/^data:[^;]+;base64,/.test(l)){for(var u=atob(l.split(",")[1]),g=new Uint8Array(u.length),y=0;y<u.length;++y)g[y]=u.charCodeAt(y);h(g.buffer,r)}else{var m=new XMLHttpRequest;m.open(r._xhr.method,l,!0),m.withCredentials=r._xhr.withCredentials,m.responseType="arraybuffer",r._xhr.headers&&Object.keys(r._xhr.headers).forEach(function(v){m.setRequestHeader(v,r._xhr.headers[v])}),m.onload=function(){var v=(m.status+"")[0];if(v!=="0"&&v!=="2"&&v!=="3"){r._emit("loaderror",null,"Failed loading audio file with status: "+m.status+".");return}h(m.response,r)},m.onerror=function(){r._webAudio&&(r._html5=!0,r._webAudio=!1,r._sounds=[],delete a[l],r.load())},c(m)}},c=function(r){try{r.send()}catch{r.onerror()}},h=function(r,l){var u=function(){l._emit("loaderror",null,"Decoding audio data failed.")},g=function(y){y&&l._sounds.length>0?(a[l._src]=y,f(l,y)):u()};typeof Promise<"u"&&t.ctx.decodeAudioData.length===1?t.ctx.decodeAudioData(r).then(g).catch(u):t.ctx.decodeAudioData(r,g,u)},f=function(r,l){l&&!r._duration&&(r._duration=l.duration),Object.keys(r._sprite).length===0&&(r._sprite={__default:[0,r._duration*1e3]}),r._state!=="loaded"&&(r._state="loaded",r._emit("load"),r._loadQueue())},p=function(){if(t.usingWebAudio){try{typeof AudioContext<"u"?t.ctx=new AudioContext:typeof webkitAudioContext<"u"?t.ctx=new webkitAudioContext:t.usingWebAudio=!1}catch{t.usingWebAudio=!1}t.ctx||(t.usingWebAudio=!1);var r=/iP(hone|od|ad)/.test(t._navigator&&t._navigator.platform),l=t._navigator&&t._navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/),u=l?parseInt(l[1],10):null;if(r&&u&&u<9){var g=/safari/.test(t._navigator&&t._navigator.userAgent.toLowerCase());t._navigator&&!g&&(t.usingWebAudio=!1)}t.usingWebAudio&&(t.masterGain=typeof t.ctx.createGain>"u"?t.ctx.createGainNode():t.ctx.createGain(),t.masterGain.gain.setValueAtTime(t._muted?0:t._volume,t.ctx.currentTime),t.masterGain.connect(t.ctx.destination)),t._setup()}};o.Howler=t,o.Howl=i,typeof xt<"u"?(xt.HowlerGlobal=e,xt.Howler=t,xt.Howl=i,xt.Sound=s):typeof window<"u"&&(window.HowlerGlobal=e,window.Howler=t,window.Howl=i,window.Sound=s)})();/*!
3696
+ */(function(a){(function(){var e=function(){this.init()};e.prototype={init:function(){var n=this||t;return n._counter=1e3,n._html5AudioPool=[],n.html5PoolSize=10,n._codecs={},n._howls=[],n._muted=!1,n._volume=1,n._canPlayEvent="canplaythrough",n._navigator=typeof window<"u"&&window.navigator?window.navigator:null,n.masterGain=null,n.noAudio=!1,n.usingWebAudio=!0,n.autoSuspend=!0,n.ctx=null,n.autoUnlock=!0,n._setup(),n},volume:function(n){var l=this||t;if(n=parseFloat(n),l.ctx||p(),typeof n<"u"&&n>=0&&n<=1){if(l._volume=n,l._muted)return l;l.usingWebAudio&&l.masterGain.gain.setValueAtTime(n,t.ctx.currentTime);for(var d=0;d<l._howls.length;d++)if(!l._howls[d]._webAudio)for(var g=l._howls[d]._getSoundIds(),v=0;v<g.length;v++){var m=l._howls[d]._soundById(g[v]);m&&m._node&&(m._node.volume=m._volume*n)}return l}return l._volume},mute:function(n){var l=this||t;l.ctx||p(),l._muted=n,l.usingWebAudio&&l.masterGain.gain.setValueAtTime(n?0:l._volume,t.ctx.currentTime);for(var d=0;d<l._howls.length;d++)if(!l._howls[d]._webAudio)for(var g=l._howls[d]._getSoundIds(),v=0;v<g.length;v++){var m=l._howls[d]._soundById(g[v]);m&&m._node&&(m._node.muted=n?!0:m._muted)}return l},stop:function(){for(var n=this||t,l=0;l<n._howls.length;l++)n._howls[l].stop();return n},unload:function(){for(var n=this||t,l=n._howls.length-1;l>=0;l--)n._howls[l].unload();return n.usingWebAudio&&n.ctx&&typeof n.ctx.close<"u"&&(n.ctx.close(),n.ctx=null,p()),n},codecs:function(n){return(this||t)._codecs[n.replace(/^x-/,"")]},_setup:function(){var n=this||t;if(n.state=n.ctx&&n.ctx.state||"suspended",n._autoSuspend(),!n.usingWebAudio)if(typeof Audio<"u")try{var l=new Audio;typeof l.oncanplaythrough>"u"&&(n._canPlayEvent="canplay")}catch{n.noAudio=!0}else n.noAudio=!0;try{var l=new Audio;l.muted&&(n.noAudio=!0)}catch{}return n.noAudio||n._setupCodecs(),n},_setupCodecs:function(){var n=this||t,l=null;try{l=typeof Audio<"u"?new Audio:null}catch{return n}if(!l||typeof l.canPlayType!="function")return n;var d=l.canPlayType("audio/mpeg;").replace(/^no$/,""),g=n._navigator?n._navigator.userAgent:"",v=g.match(/OPR\/(\d+)/g),m=v&&parseInt(v[0].split("/")[1],10)<33,_=g.indexOf("Safari")!==-1&&g.indexOf("Chrome")===-1,y=g.match(/Version\/(.*?) /),w=_&&y&&parseInt(y[1],10)<15;return n._codecs={mp3:!!(!m&&(d||l.canPlayType("audio/mp3;").replace(/^no$/,""))),mpeg:!!d,opus:!!l.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/,""),ogg:!!l.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),oga:!!l.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),wav:!!(l.canPlayType('audio/wav; codecs="1"')||l.canPlayType("audio/wav")).replace(/^no$/,""),aac:!!l.canPlayType("audio/aac;").replace(/^no$/,""),caf:!!l.canPlayType("audio/x-caf;").replace(/^no$/,""),m4a:!!(l.canPlayType("audio/x-m4a;")||l.canPlayType("audio/m4a;")||l.canPlayType("audio/aac;")).replace(/^no$/,""),m4b:!!(l.canPlayType("audio/x-m4b;")||l.canPlayType("audio/m4b;")||l.canPlayType("audio/aac;")).replace(/^no$/,""),mp4:!!(l.canPlayType("audio/x-mp4;")||l.canPlayType("audio/mp4;")||l.canPlayType("audio/aac;")).replace(/^no$/,""),weba:!!(!w&&l.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,"")),webm:!!(!w&&l.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,"")),dolby:!!l.canPlayType('audio/mp4; codecs="ec-3"').replace(/^no$/,""),flac:!!(l.canPlayType("audio/x-flac;")||l.canPlayType("audio/flac;")).replace(/^no$/,"")},n},_unlockAudio:function(){var n=this||t;if(!(n._audioUnlocked||!n.ctx)){n._audioUnlocked=!1,n.autoUnlock=!1,!n._mobileUnloaded&&n.ctx.sampleRate!==44100&&(n._mobileUnloaded=!0,n.unload()),n._scratchBuffer=n.ctx.createBuffer(1,1,22050);var l=function(d){for(;n._html5AudioPool.length<n.html5PoolSize;)try{var g=new Audio;g._unlocked=!0,n._releaseHtml5Audio(g)}catch{n.noAudio=!0;break}for(var v=0;v<n._howls.length;v++)if(!n._howls[v]._webAudio)for(var m=n._howls[v]._getSoundIds(),_=0;_<m.length;_++){var y=n._howls[v]._soundById(m[_]);y&&y._node&&!y._node._unlocked&&(y._node._unlocked=!0,y._node.load())}n._autoResume();var w=n.ctx.createBufferSource();w.buffer=n._scratchBuffer,w.connect(n.ctx.destination),typeof w.start>"u"?w.noteOn(0):w.start(0),typeof n.ctx.resume=="function"&&n.ctx.resume(),w.onended=function(){w.disconnect(0),n._audioUnlocked=!0,document.removeEventListener("touchstart",l,!0),document.removeEventListener("touchend",l,!0),document.removeEventListener("click",l,!0),document.removeEventListener("keydown",l,!0);for(var x=0;x<n._howls.length;x++)n._howls[x]._emit("unlock")}};return document.addEventListener("touchstart",l,!0),document.addEventListener("touchend",l,!0),document.addEventListener("click",l,!0),document.addEventListener("keydown",l,!0),n}},_obtainHtml5Audio:function(){var n=this||t;if(n._html5AudioPool.length)return n._html5AudioPool.pop();var l=new Audio().play();return l&&typeof Promise<"u"&&(l instanceof Promise||typeof l.then=="function")&&l.catch(function(){console.warn("HTML5 Audio pool exhausted, returning potentially locked audio object.")}),new Audio},_releaseHtml5Audio:function(n){var l=this||t;return n._unlocked&&l._html5AudioPool.push(n),l},_autoSuspend:function(){var n=this;if(!(!n.autoSuspend||!n.ctx||typeof n.ctx.suspend>"u"||!t.usingWebAudio)){for(var l=0;l<n._howls.length;l++)if(n._howls[l]._webAudio){for(var d=0;d<n._howls[l]._sounds.length;d++)if(!n._howls[l]._sounds[d]._paused)return n}return n._suspendTimer&&clearTimeout(n._suspendTimer),n._suspendTimer=setTimeout(function(){if(n.autoSuspend){n._suspendTimer=null,n.state="suspending";var g=function(){n.state="suspended",n._resumeAfterSuspend&&(delete n._resumeAfterSuspend,n._autoResume())};n.ctx.suspend().then(g,g)}},3e4),n}},_autoResume:function(){var n=this;if(!(!n.ctx||typeof n.ctx.resume>"u"||!t.usingWebAudio))return n.state==="running"&&n.ctx.state!=="interrupted"&&n._suspendTimer?(clearTimeout(n._suspendTimer),n._suspendTimer=null):n.state==="suspended"||n.state==="running"&&n.ctx.state==="interrupted"?(n.ctx.resume().then(function(){n.state="running";for(var l=0;l<n._howls.length;l++)n._howls[l]._emit("resume")}),n._suspendTimer&&(clearTimeout(n._suspendTimer),n._suspendTimer=null)):n.state==="suspending"&&(n._resumeAfterSuspend=!0),n}};var t=new e,i=function(n){var l=this;if(!n.src||n.src.length===0){console.error("An array of source files must be passed with any new Howl.");return}l.init(n)};i.prototype={init:function(n){var l=this;return t.ctx||p(),l._autoplay=n.autoplay||!1,l._format=typeof n.format!="string"?n.format:[n.format],l._html5=n.html5||!1,l._muted=n.mute||!1,l._loop=n.loop||!1,l._pool=n.pool||5,l._preload=typeof n.preload=="boolean"||n.preload==="metadata"?n.preload:!0,l._rate=n.rate||1,l._sprite=n.sprite||{},l._src=typeof n.src!="string"?n.src:[n.src],l._volume=n.volume!==void 0?n.volume:1,l._xhr={method:n.xhr&&n.xhr.method?n.xhr.method:"GET",headers:n.xhr&&n.xhr.headers?n.xhr.headers:null,withCredentials:n.xhr&&n.xhr.withCredentials?n.xhr.withCredentials:!1},l._duration=0,l._state="unloaded",l._sounds=[],l._endTimers={},l._queue=[],l._playLock=!1,l._onend=n.onend?[{fn:n.onend}]:[],l._onfade=n.onfade?[{fn:n.onfade}]:[],l._onload=n.onload?[{fn:n.onload}]:[],l._onloaderror=n.onloaderror?[{fn:n.onloaderror}]:[],l._onplayerror=n.onplayerror?[{fn:n.onplayerror}]:[],l._onpause=n.onpause?[{fn:n.onpause}]:[],l._onplay=n.onplay?[{fn:n.onplay}]:[],l._onstop=n.onstop?[{fn:n.onstop}]:[],l._onmute=n.onmute?[{fn:n.onmute}]:[],l._onvolume=n.onvolume?[{fn:n.onvolume}]:[],l._onrate=n.onrate?[{fn:n.onrate}]:[],l._onseek=n.onseek?[{fn:n.onseek}]:[],l._onunlock=n.onunlock?[{fn:n.onunlock}]:[],l._onresume=[],l._webAudio=t.usingWebAudio&&!l._html5,typeof t.ctx<"u"&&t.ctx&&t.autoUnlock&&t._unlockAudio(),t._howls.push(l),l._autoplay&&l._queue.push({event:"play",action:function(){l.play()}}),l._preload&&l._preload!=="none"&&l.load(),l},load:function(){var n=this,l=null;if(t.noAudio){n._emit("loaderror",null,"No audio support.");return}typeof n._src=="string"&&(n._src=[n._src]);for(var d=0;d<n._src.length;d++){var g,v;if(n._format&&n._format[d])g=n._format[d];else{if(v=n._src[d],typeof v!="string"){n._emit("loaderror",null,"Non-string found in selected audio sources - ignoring.");continue}g=/^data:audio\/([^;,]+);/i.exec(v),g||(g=/\.([^.]+)$/.exec(v.split("?",1)[0])),g&&(g=g[1].toLowerCase())}if(g||console.warn('No file extension was found. Consider using the "format" property or specify an extension.'),g&&t.codecs(g)){l=n._src[d];break}}if(!l){n._emit("loaderror",null,"No codec support for selected audio sources.");return}return n._src=l,n._state="loading",window.location.protocol==="https:"&&l.slice(0,5)==="http:"&&(n._html5=!0,n._webAudio=!1),new s(n),n._webAudio&&o(n),n},play:function(n,l){var d=this,g=null;if(typeof n=="number")g=n,n=null;else{if(typeof n=="string"&&d._state==="loaded"&&!d._sprite[n])return null;if(typeof n>"u"&&(n="__default",!d._playLock)){for(var v=0,m=0;m<d._sounds.length;m++)d._sounds[m]._paused&&!d._sounds[m]._ended&&(v++,g=d._sounds[m]._id);v===1?n=null:g=null}}var _=g?d._soundById(g):d._inactiveSound();if(!_)return null;if(g&&!n&&(n=_._sprite||"__default"),d._state!=="loaded"){_._sprite=n,_._ended=!1;var y=_._id;return d._queue.push({event:"play",action:function(){d.play(y)}}),y}if(g&&!_._paused)return l||d._loadQueue("play"),_._id;d._webAudio&&t._autoResume();var w=Math.max(0,_._seek>0?_._seek:d._sprite[n][0]/1e3),x=Math.max(0,(d._sprite[n][0]+d._sprite[n][1])/1e3-w),b=x*1e3/Math.abs(_._rate),T=d._sprite[n][0]/1e3,M=(d._sprite[n][0]+d._sprite[n][1])/1e3;_._sprite=n,_._ended=!1;var L=function(){_._paused=!1,_._seek=w,_._start=T,_._stop=M,_._loop=!!(_._loop||d._sprite[n][2])};if(w>=M){d._ended(_);return}var C=_._node;if(d._webAudio){var I=function(){d._playLock=!1,L(),d._refreshBuffer(_);var P=_._muted||d._muted?0:_._volume;C.gain.setValueAtTime(P,t.ctx.currentTime),_._playStart=t.ctx.currentTime,typeof C.bufferSource.start>"u"?_._loop?C.bufferSource.noteGrainOn(0,w,86400):C.bufferSource.noteGrainOn(0,w,x):_._loop?C.bufferSource.start(0,w,86400):C.bufferSource.start(0,w,x),b!==1/0&&(d._endTimers[_._id]=setTimeout(d._ended.bind(d,_),b)),l||setTimeout(function(){d._emit("play",_._id),d._loadQueue()},0)};t.state==="running"&&t.ctx.state!=="interrupted"?I():(d._playLock=!0,d.once("resume",I),d._clearTimer(_._id))}else{var D=function(){C.currentTime=w,C.muted=_._muted||d._muted||t._muted||C.muted,C.volume=_._volume*t.volume(),C.playbackRate=_._rate;try{var P=C.play();if(P&&typeof Promise<"u"&&(P instanceof Promise||typeof P.then=="function")?(d._playLock=!0,L(),P.then(function(){d._playLock=!1,C._unlocked=!0,l?d._loadQueue():d._emit("play",_._id)}).catch(function(){d._playLock=!1,d._emit("playerror",_._id,"Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction."),_._ended=!0,_._paused=!0})):l||(d._playLock=!1,L(),d._emit("play",_._id)),C.playbackRate=_._rate,C.paused){d._emit("playerror",_._id,"Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction.");return}n!=="__default"||_._loop?d._endTimers[_._id]=setTimeout(d._ended.bind(d,_),b):(d._endTimers[_._id]=function(){d._ended(_),C.removeEventListener("ended",d._endTimers[_._id],!1)},C.addEventListener("ended",d._endTimers[_._id],!1))}catch(R){d._emit("playerror",_._id,R)}};C.src==="data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA"&&(C.src=d._src,C.load());var A=window&&window.ejecta||!C.readyState&&t._navigator.isCocoonJS;if(C.readyState>=3||A)D();else{d._playLock=!0,d._state="loading";var S=function(){d._state="loaded",D(),C.removeEventListener(t._canPlayEvent,S,!1)};C.addEventListener(t._canPlayEvent,S,!1),d._clearTimer(_._id)}}return _._id},pause:function(n){var l=this;if(l._state!=="loaded"||l._playLock)return l._queue.push({event:"pause",action:function(){l.pause(n)}}),l;for(var d=l._getSoundIds(n),g=0;g<d.length;g++){l._clearTimer(d[g]);var v=l._soundById(d[g]);if(v&&!v._paused&&(v._seek=l.seek(d[g]),v._rateSeek=0,v._paused=!0,l._stopFade(d[g]),v._node))if(l._webAudio){if(!v._node.bufferSource)continue;typeof v._node.bufferSource.stop>"u"?v._node.bufferSource.noteOff(0):v._node.bufferSource.stop(0),l._cleanBuffer(v._node)}else(!isNaN(v._node.duration)||v._node.duration===1/0)&&v._node.pause();arguments[1]||l._emit("pause",v?v._id:null)}return l},stop:function(n,l){var d=this;if(d._state!=="loaded"||d._playLock)return d._queue.push({event:"stop",action:function(){d.stop(n)}}),d;for(var g=d._getSoundIds(n),v=0;v<g.length;v++){d._clearTimer(g[v]);var m=d._soundById(g[v]);m&&(m._seek=m._start||0,m._rateSeek=0,m._paused=!0,m._ended=!0,d._stopFade(g[v]),m._node&&(d._webAudio?m._node.bufferSource&&(typeof m._node.bufferSource.stop>"u"?m._node.bufferSource.noteOff(0):m._node.bufferSource.stop(0),d._cleanBuffer(m._node)):(!isNaN(m._node.duration)||m._node.duration===1/0)&&(m._node.currentTime=m._start||0,m._node.pause(),m._node.duration===1/0&&d._clearSound(m._node))),l||d._emit("stop",m._id))}return d},mute:function(n,l){var d=this;if(d._state!=="loaded"||d._playLock)return d._queue.push({event:"mute",action:function(){d.mute(n,l)}}),d;if(typeof l>"u")if(typeof n=="boolean")d._muted=n;else return d._muted;for(var g=d._getSoundIds(l),v=0;v<g.length;v++){var m=d._soundById(g[v]);m&&(m._muted=n,m._interval&&d._stopFade(m._id),d._webAudio&&m._node?m._node.gain.setValueAtTime(n?0:m._volume,t.ctx.currentTime):m._node&&(m._node.muted=t._muted?!0:n),d._emit("mute",m._id))}return d},volume:function(){var n=this,l=arguments,d,g;if(l.length===0)return n._volume;if(l.length===1||l.length===2&&typeof l[1]>"u"){var v=n._getSoundIds(),m=v.indexOf(l[0]);m>=0?g=parseInt(l[0],10):d=parseFloat(l[0])}else l.length>=2&&(d=parseFloat(l[0]),g=parseInt(l[1],10));var _;if(typeof d<"u"&&d>=0&&d<=1){if(n._state!=="loaded"||n._playLock)return n._queue.push({event:"volume",action:function(){n.volume.apply(n,l)}}),n;typeof g>"u"&&(n._volume=d),g=n._getSoundIds(g);for(var y=0;y<g.length;y++)_=n._soundById(g[y]),_&&(_._volume=d,l[2]||n._stopFade(g[y]),n._webAudio&&_._node&&!_._muted?_._node.gain.setValueAtTime(d,t.ctx.currentTime):_._node&&!_._muted&&(_._node.volume=d*t.volume()),n._emit("volume",_._id))}else return _=g?n._soundById(g):n._sounds[0],_?_._volume:0;return n},fade:function(n,l,d,g){var v=this;if(v._state!=="loaded"||v._playLock)return v._queue.push({event:"fade",action:function(){v.fade(n,l,d,g)}}),v;n=Math.min(Math.max(0,parseFloat(n)),1),l=Math.min(Math.max(0,parseFloat(l)),1),d=parseFloat(d),v.volume(n,g);for(var m=v._getSoundIds(g),_=0;_<m.length;_++){var y=v._soundById(m[_]);if(y){if(g||v._stopFade(m[_]),v._webAudio&&!y._muted){var w=t.ctx.currentTime,x=w+d/1e3;y._volume=n,y._node.gain.setValueAtTime(n,w),y._node.gain.linearRampToValueAtTime(l,x)}v._startFadeInterval(y,n,l,d,m[_],typeof g>"u")}}return v},_startFadeInterval:function(n,l,d,g,v,m){var _=this,y=l,w=d-l,x=Math.abs(w/.01),b=Math.max(4,x>0?g/x:g),T=Date.now();n._fadeTo=d,n._interval=setInterval(function(){var M=(Date.now()-T)/g;T=Date.now(),y+=w*M,y=Math.round(y*100)/100,w<0?y=Math.max(d,y):y=Math.min(d,y),_._webAudio?n._volume=y:_.volume(y,n._id,!0),m&&(_._volume=y),(d<l&&y<=d||d>l&&y>=d)&&(clearInterval(n._interval),n._interval=null,n._fadeTo=null,_.volume(d,n._id),_._emit("fade",n._id))},b)},_stopFade:function(n){var l=this,d=l._soundById(n);return d&&d._interval&&(l._webAudio&&d._node.gain.cancelScheduledValues(t.ctx.currentTime),clearInterval(d._interval),d._interval=null,l.volume(d._fadeTo,n),d._fadeTo=null,l._emit("fade",n)),l},loop:function(){var n=this,l=arguments,d,g,v;if(l.length===0)return n._loop;if(l.length===1)if(typeof l[0]=="boolean")d=l[0],n._loop=d;else return v=n._soundById(parseInt(l[0],10)),v?v._loop:!1;else l.length===2&&(d=l[0],g=parseInt(l[1],10));for(var m=n._getSoundIds(g),_=0;_<m.length;_++)v=n._soundById(m[_]),v&&(v._loop=d,n._webAudio&&v._node&&v._node.bufferSource&&(v._node.bufferSource.loop=d,d&&(v._node.bufferSource.loopStart=v._start||0,v._node.bufferSource.loopEnd=v._stop,n.playing(m[_])&&(n.pause(m[_],!0),n.play(m[_],!0)))));return n},rate:function(){var n=this,l=arguments,d,g;if(l.length===0)g=n._sounds[0]._id;else if(l.length===1){var v=n._getSoundIds(),m=v.indexOf(l[0]);m>=0?g=parseInt(l[0],10):d=parseFloat(l[0])}else l.length===2&&(d=parseFloat(l[0]),g=parseInt(l[1],10));var _;if(typeof d=="number"){if(n._state!=="loaded"||n._playLock)return n._queue.push({event:"rate",action:function(){n.rate.apply(n,l)}}),n;typeof g>"u"&&(n._rate=d),g=n._getSoundIds(g);for(var y=0;y<g.length;y++)if(_=n._soundById(g[y]),_){n.playing(g[y])&&(_._rateSeek=n.seek(g[y]),_._playStart=n._webAudio?t.ctx.currentTime:_._playStart),_._rate=d,n._webAudio&&_._node&&_._node.bufferSource?_._node.bufferSource.playbackRate.setValueAtTime(d,t.ctx.currentTime):_._node&&(_._node.playbackRate=d);var w=n.seek(g[y]),x=(n._sprite[_._sprite][0]+n._sprite[_._sprite][1])/1e3-w,b=x*1e3/Math.abs(_._rate);(n._endTimers[g[y]]||!_._paused)&&(n._clearTimer(g[y]),n._endTimers[g[y]]=setTimeout(n._ended.bind(n,_),b)),n._emit("rate",_._id)}}else return _=n._soundById(g),_?_._rate:n._rate;return n},seek:function(){var n=this,l=arguments,d,g;if(l.length===0)n._sounds.length&&(g=n._sounds[0]._id);else if(l.length===1){var v=n._getSoundIds(),m=v.indexOf(l[0]);m>=0?g=parseInt(l[0],10):n._sounds.length&&(g=n._sounds[0]._id,d=parseFloat(l[0]))}else l.length===2&&(d=parseFloat(l[0]),g=parseInt(l[1],10));if(typeof g>"u")return 0;if(typeof d=="number"&&(n._state!=="loaded"||n._playLock))return n._queue.push({event:"seek",action:function(){n.seek.apply(n,l)}}),n;var _=n._soundById(g);if(_)if(typeof d=="number"&&d>=0){var y=n.playing(g);y&&n.pause(g,!0),_._seek=d,_._ended=!1,n._clearTimer(g),!n._webAudio&&_._node&&!isNaN(_._node.duration)&&(_._node.currentTime=d);var w=function(){y&&n.play(g,!0),n._emit("seek",g)};if(y&&!n._webAudio){var x=function(){n._playLock?setTimeout(x,0):w()};setTimeout(x,0)}else w()}else if(n._webAudio){var b=n.playing(g)?t.ctx.currentTime-_._playStart:0,T=_._rateSeek?_._rateSeek-_._seek:0;return _._seek+(T+b*Math.abs(_._rate))}else return _._node.currentTime;return n},playing:function(n){var l=this;if(typeof n=="number"){var d=l._soundById(n);return d?!d._paused:!1}for(var g=0;g<l._sounds.length;g++)if(!l._sounds[g]._paused)return!0;return!1},duration:function(n){var l=this,d=l._duration,g=l._soundById(n);return g&&(d=l._sprite[g._sprite][1]/1e3),d},state:function(){return this._state},unload:function(){for(var n=this,l=n._sounds,d=0;d<l.length;d++)l[d]._paused||n.stop(l[d]._id),n._webAudio||(n._clearSound(l[d]._node),l[d]._node.removeEventListener("error",l[d]._errorFn,!1),l[d]._node.removeEventListener(t._canPlayEvent,l[d]._loadFn,!1),l[d]._node.removeEventListener("ended",l[d]._endFn,!1),t._releaseHtml5Audio(l[d]._node)),delete l[d]._node,n._clearTimer(l[d]._id);var g=t._howls.indexOf(n);g>=0&&t._howls.splice(g,1);var v=!0;for(d=0;d<t._howls.length;d++)if(t._howls[d]._src===n._src||n._src.indexOf(t._howls[d]._src)>=0){v=!1;break}return r&&v&&delete r[n._src],t.noAudio=!1,n._state="unloaded",n._sounds=[],n=null,null},on:function(n,l,d,g){var v=this,m=v["_on"+n];return typeof l=="function"&&m.push(g?{id:d,fn:l,once:g}:{id:d,fn:l}),v},off:function(n,l,d){var g=this,v=g["_on"+n],m=0;if(typeof l=="number"&&(d=l,l=null),l||d)for(m=0;m<v.length;m++){var _=d===v[m].id;if(l===v[m].fn&&_||!l&&_){v.splice(m,1);break}}else if(n)g["_on"+n]=[];else{var y=Object.keys(g);for(m=0;m<y.length;m++)y[m].indexOf("_on")===0&&Array.isArray(g[y[m]])&&(g[y[m]]=[])}return g},once:function(n,l,d){var g=this;return g.on(n,l,d,1),g},_emit:function(n,l,d){for(var g=this,v=g["_on"+n],m=v.length-1;m>=0;m--)(!v[m].id||v[m].id===l||n==="load")&&(setTimeout((function(_){_.call(this,l,d)}).bind(g,v[m].fn),0),v[m].once&&g.off(n,v[m].fn,v[m].id));return g._loadQueue(n),g},_loadQueue:function(n){var l=this;if(l._queue.length>0){var d=l._queue[0];d.event===n&&(l._queue.shift(),l._loadQueue()),n||d.action()}return l},_ended:function(n){var l=this,d=n._sprite;if(!l._webAudio&&n._node&&!n._node.paused&&!n._node.ended&&n._node.currentTime<n._stop)return setTimeout(l._ended.bind(l,n),100),l;var g=!!(n._loop||l._sprite[d][2]);if(l._emit("end",n._id),!l._webAudio&&g&&l.stop(n._id,!0).play(n._id),l._webAudio&&g){l._emit("play",n._id),n._seek=n._start||0,n._rateSeek=0,n._playStart=t.ctx.currentTime;var v=(n._stop-n._start)*1e3/Math.abs(n._rate);l._endTimers[n._id]=setTimeout(l._ended.bind(l,n),v)}return l._webAudio&&!g&&(n._paused=!0,n._ended=!0,n._seek=n._start||0,n._rateSeek=0,l._clearTimer(n._id),l._cleanBuffer(n._node),t._autoSuspend()),!l._webAudio&&!g&&l.stop(n._id,!0),l},_clearTimer:function(n){var l=this;if(l._endTimers[n]){if(typeof l._endTimers[n]!="function")clearTimeout(l._endTimers[n]);else{var d=l._soundById(n);d&&d._node&&d._node.removeEventListener("ended",l._endTimers[n],!1)}delete l._endTimers[n]}return l},_soundById:function(n){for(var l=this,d=0;d<l._sounds.length;d++)if(n===l._sounds[d]._id)return l._sounds[d];return null},_inactiveSound:function(){var n=this;n._drain();for(var l=0;l<n._sounds.length;l++)if(n._sounds[l]._ended)return n._sounds[l].reset();return new s(n)},_drain:function(){var n=this,l=n._pool,d=0,g=0;if(!(n._sounds.length<l)){for(g=0;g<n._sounds.length;g++)n._sounds[g]._ended&&d++;for(g=n._sounds.length-1;g>=0;g--){if(d<=l)return;n._sounds[g]._ended&&(n._webAudio&&n._sounds[g]._node&&n._sounds[g]._node.disconnect(0),n._sounds.splice(g,1),d--)}}},_getSoundIds:function(n){var l=this;if(typeof n>"u"){for(var d=[],g=0;g<l._sounds.length;g++)d.push(l._sounds[g]._id);return d}else return[n]},_refreshBuffer:function(n){var l=this;return n._node.bufferSource=t.ctx.createBufferSource(),n._node.bufferSource.buffer=r[l._src],n._panner?n._node.bufferSource.connect(n._panner):n._node.bufferSource.connect(n._node),n._node.bufferSource.loop=n._loop,n._loop&&(n._node.bufferSource.loopStart=n._start||0,n._node.bufferSource.loopEnd=n._stop||0),n._node.bufferSource.playbackRate.setValueAtTime(n._rate,t.ctx.currentTime),l},_cleanBuffer:function(n){var l=this,d=t._navigator&&t._navigator.vendor.indexOf("Apple")>=0;if(!n.bufferSource)return l;if(t._scratchBuffer&&n.bufferSource&&(n.bufferSource.onended=null,n.bufferSource.disconnect(0),d))try{n.bufferSource.buffer=t._scratchBuffer}catch{}return n.bufferSource=null,l},_clearSound:function(n){var l=/MSIE |Trident\//.test(t._navigator&&t._navigator.userAgent);l||(n.src="data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA")}};var s=function(n){this._parent=n,this.init()};s.prototype={init:function(){var n=this,l=n._parent;return n._muted=l._muted,n._loop=l._loop,n._volume=l._volume,n._rate=l._rate,n._seek=0,n._paused=!0,n._ended=!0,n._sprite="__default",n._id=++t._counter,l._sounds.push(n),n.create(),n},create:function(){var n=this,l=n._parent,d=t._muted||n._muted||n._parent._muted?0:n._volume;return l._webAudio?(n._node=typeof t.ctx.createGain>"u"?t.ctx.createGainNode():t.ctx.createGain(),n._node.gain.setValueAtTime(d,t.ctx.currentTime),n._node.paused=!0,n._node.connect(t.masterGain)):t.noAudio||(n._node=t._obtainHtml5Audio(),n._errorFn=n._errorListener.bind(n),n._node.addEventListener("error",n._errorFn,!1),n._loadFn=n._loadListener.bind(n),n._node.addEventListener(t._canPlayEvent,n._loadFn,!1),n._endFn=n._endListener.bind(n),n._node.addEventListener("ended",n._endFn,!1),n._node.src=l._src,n._node.preload=l._preload===!0?"auto":l._preload,n._node.volume=d*t.volume(),n._node.load()),n},reset:function(){var n=this,l=n._parent;return n._muted=l._muted,n._loop=l._loop,n._volume=l._volume,n._rate=l._rate,n._seek=0,n._rateSeek=0,n._paused=!0,n._ended=!0,n._sprite="__default",n._id=++t._counter,n},_errorListener:function(){var n=this;n._parent._emit("loaderror",n._id,n._node.error?n._node.error.code:0),n._node.removeEventListener("error",n._errorFn,!1)},_loadListener:function(){var n=this,l=n._parent;l._duration=Math.ceil(n._node.duration*10)/10,Object.keys(l._sprite).length===0&&(l._sprite={__default:[0,l._duration*1e3]}),l._state!=="loaded"&&(l._state="loaded",l._emit("load"),l._loadQueue()),n._node.removeEventListener(t._canPlayEvent,n._loadFn,!1)},_endListener:function(){var n=this,l=n._parent;l._duration===1/0&&(l._duration=Math.ceil(n._node.duration*10)/10,l._sprite.__default[1]===1/0&&(l._sprite.__default[1]=l._duration*1e3),l._ended(n)),n._node.removeEventListener("ended",n._endFn,!1)}};var r={},o=function(n){var l=n._src;if(r[l]){n._duration=r[l].duration,u(n);return}if(/^data:[^;]+;base64,/.test(l)){for(var d=atob(l.split(",")[1]),g=new Uint8Array(d.length),v=0;v<d.length;++v)g[v]=d.charCodeAt(v);h(g.buffer,n)}else{var m=new XMLHttpRequest;m.open(n._xhr.method,l,!0),m.withCredentials=n._xhr.withCredentials,m.responseType="arraybuffer",n._xhr.headers&&Object.keys(n._xhr.headers).forEach(function(_){m.setRequestHeader(_,n._xhr.headers[_])}),m.onload=function(){var _=(m.status+"")[0];if(_!=="0"&&_!=="2"&&_!=="3"){n._emit("loaderror",null,"Failed loading audio file with status: "+m.status+".");return}h(m.response,n)},m.onerror=function(){n._webAudio&&(n._html5=!0,n._webAudio=!1,n._sounds=[],delete r[l],n.load())},c(m)}},c=function(n){try{n.send()}catch{n.onerror()}},h=function(n,l){var d=function(){l._emit("loaderror",null,"Decoding audio data failed.")},g=function(v){v&&l._sounds.length>0?(r[l._src]=v,u(l,v)):d()};typeof Promise<"u"&&t.ctx.decodeAudioData.length===1?t.ctx.decodeAudioData(n).then(g).catch(d):t.ctx.decodeAudioData(n,g,d)},u=function(n,l){l&&!n._duration&&(n._duration=l.duration),Object.keys(n._sprite).length===0&&(n._sprite={__default:[0,n._duration*1e3]}),n._state!=="loaded"&&(n._state="loaded",n._emit("load"),n._loadQueue())},p=function(){if(t.usingWebAudio){try{typeof AudioContext<"u"?t.ctx=new AudioContext:typeof webkitAudioContext<"u"?t.ctx=new webkitAudioContext:t.usingWebAudio=!1}catch{t.usingWebAudio=!1}t.ctx||(t.usingWebAudio=!1);var n=/iP(hone|od|ad)/.test(t._navigator&&t._navigator.platform),l=t._navigator&&t._navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/),d=l?parseInt(l[1],10):null;if(n&&d&&d<9){var g=/safari/.test(t._navigator&&t._navigator.userAgent.toLowerCase());t._navigator&&!g&&(t.usingWebAudio=!1)}t.usingWebAudio&&(t.masterGain=typeof t.ctx.createGain>"u"?t.ctx.createGainNode():t.ctx.createGain(),t.masterGain.gain.setValueAtTime(t._muted?0:t._volume,t.ctx.currentTime),t.masterGain.connect(t.ctx.destination)),t._setup()}};a.Howler=t,a.Howl=i,typeof St<"u"?(St.HowlerGlobal=e,St.Howler=t,St.Howl=i,St.Sound=s):typeof window<"u"&&(window.HowlerGlobal=e,window.Howler=t,window.Howl=i,window.Sound=s)})();/*!
3697
3697
  * Spatial Plugin - Adds support for stereo and 3D audio where Web Audio is supported.
3698
3698
  *
3699
3699
  * howler.js v2.2.4
@@ -3703,32 +3703,32 @@ ${t.name}`)}break}}}}else a.texture_lod=0}};ie=new WeakMap,xe=new WeakMap,ui=new
3703
3703
  * goldfirestudios.com
3704
3704
  *
3705
3705
  * MIT License
3706
- */(function(){HowlerGlobal.prototype._pos=[0,0,0],HowlerGlobal.prototype._orientation=[0,0,-1,0,1,0],HowlerGlobal.prototype.stereo=function(t){var i=this;if(!i.ctx||!i.ctx.listener)return i;for(var s=i._howls.length-1;s>=0;s--)i._howls[s].stereo(t);return i},HowlerGlobal.prototype.pos=function(t,i,s){var a=this;if(!a.ctx||!a.ctx.listener)return a;if(i=typeof i!="number"?a._pos[1]:i,s=typeof s!="number"?a._pos[2]:s,typeof t=="number")a._pos=[t,i,s],typeof a.ctx.listener.positionX<"u"?(a.ctx.listener.positionX.setTargetAtTime(a._pos[0],Howler.ctx.currentTime,.1),a.ctx.listener.positionY.setTargetAtTime(a._pos[1],Howler.ctx.currentTime,.1),a.ctx.listener.positionZ.setTargetAtTime(a._pos[2],Howler.ctx.currentTime,.1)):a.ctx.listener.setPosition(a._pos[0],a._pos[1],a._pos[2]);else return a._pos;return a},HowlerGlobal.prototype.orientation=function(t,i,s,a,n,c){var h=this;if(!h.ctx||!h.ctx.listener)return h;var f=h._orientation;if(i=typeof i!="number"?f[1]:i,s=typeof s!="number"?f[2]:s,a=typeof a!="number"?f[3]:a,n=typeof n!="number"?f[4]:n,c=typeof c!="number"?f[5]:c,typeof t=="number")h._orientation=[t,i,s,a,n,c],typeof h.ctx.listener.forwardX<"u"?(h.ctx.listener.forwardX.setTargetAtTime(t,Howler.ctx.currentTime,.1),h.ctx.listener.forwardY.setTargetAtTime(i,Howler.ctx.currentTime,.1),h.ctx.listener.forwardZ.setTargetAtTime(s,Howler.ctx.currentTime,.1),h.ctx.listener.upX.setTargetAtTime(a,Howler.ctx.currentTime,.1),h.ctx.listener.upY.setTargetAtTime(n,Howler.ctx.currentTime,.1),h.ctx.listener.upZ.setTargetAtTime(c,Howler.ctx.currentTime,.1)):h.ctx.listener.setOrientation(t,i,s,a,n,c);else return f;return h},Howl.prototype.init=function(t){return function(i){var s=this;return s._orientation=i.orientation||[1,0,0],s._stereo=i.stereo||null,s._pos=i.pos||null,s._pannerAttr={coneInnerAngle:typeof i.coneInnerAngle<"u"?i.coneInnerAngle:360,coneOuterAngle:typeof i.coneOuterAngle<"u"?i.coneOuterAngle:360,coneOuterGain:typeof i.coneOuterGain<"u"?i.coneOuterGain:0,distanceModel:typeof i.distanceModel<"u"?i.distanceModel:"inverse",maxDistance:typeof i.maxDistance<"u"?i.maxDistance:1e4,panningModel:typeof i.panningModel<"u"?i.panningModel:"HRTF",refDistance:typeof i.refDistance<"u"?i.refDistance:1,rolloffFactor:typeof i.rolloffFactor<"u"?i.rolloffFactor:1},s._onstereo=i.onstereo?[{fn:i.onstereo}]:[],s._onpos=i.onpos?[{fn:i.onpos}]:[],s._onorientation=i.onorientation?[{fn:i.onorientation}]:[],t.call(this,i)}}(Howl.prototype.init),Howl.prototype.stereo=function(t,i){var s=this;if(!s._webAudio)return s;if(s._state!=="loaded")return s._queue.push({event:"stereo",action:function(){s.stereo(t,i)}}),s;var a=typeof Howler.ctx.createStereoPanner>"u"?"spatial":"stereo";if(typeof i>"u")if(typeof t=="number")s._stereo=t,s._pos=[t,0,0];else return s._stereo;for(var n=s._getSoundIds(i),c=0;c<n.length;c++){var h=s._soundById(n[c]);if(h)if(typeof t=="number")h._stereo=t,h._pos=[t,0,0],h._node&&(h._pannerAttr.panningModel="equalpower",(!h._panner||!h._panner.pan)&&e(h,a),a==="spatial"?typeof h._panner.positionX<"u"?(h._panner.positionX.setValueAtTime(t,Howler.ctx.currentTime),h._panner.positionY.setValueAtTime(0,Howler.ctx.currentTime),h._panner.positionZ.setValueAtTime(0,Howler.ctx.currentTime)):h._panner.setPosition(t,0,0):h._panner.pan.setValueAtTime(t,Howler.ctx.currentTime)),s._emit("stereo",h._id);else return h._stereo}return s},Howl.prototype.pos=function(t,i,s,a){var n=this;if(!n._webAudio)return n;if(n._state!=="loaded")return n._queue.push({event:"pos",action:function(){n.pos(t,i,s,a)}}),n;if(i=typeof i!="number"?0:i,s=typeof s!="number"?-.5:s,typeof a>"u")if(typeof t=="number")n._pos=[t,i,s];else return n._pos;for(var c=n._getSoundIds(a),h=0;h<c.length;h++){var f=n._soundById(c[h]);if(f)if(typeof t=="number")f._pos=[t,i,s],f._node&&((!f._panner||f._panner.pan)&&e(f,"spatial"),typeof f._panner.positionX<"u"?(f._panner.positionX.setValueAtTime(t,Howler.ctx.currentTime),f._panner.positionY.setValueAtTime(i,Howler.ctx.currentTime),f._panner.positionZ.setValueAtTime(s,Howler.ctx.currentTime)):f._panner.setPosition(t,i,s)),n._emit("pos",f._id);else return f._pos}return n},Howl.prototype.orientation=function(t,i,s,a){var n=this;if(!n._webAudio)return n;if(n._state!=="loaded")return n._queue.push({event:"orientation",action:function(){n.orientation(t,i,s,a)}}),n;if(i=typeof i!="number"?n._orientation[1]:i,s=typeof s!="number"?n._orientation[2]:s,typeof a>"u")if(typeof t=="number")n._orientation=[t,i,s];else return n._orientation;for(var c=n._getSoundIds(a),h=0;h<c.length;h++){var f=n._soundById(c[h]);if(f)if(typeof t=="number")f._orientation=[t,i,s],f._node&&(f._panner||(f._pos||(f._pos=n._pos||[0,0,-.5]),e(f,"spatial")),typeof f._panner.orientationX<"u"?(f._panner.orientationX.setValueAtTime(t,Howler.ctx.currentTime),f._panner.orientationY.setValueAtTime(i,Howler.ctx.currentTime),f._panner.orientationZ.setValueAtTime(s,Howler.ctx.currentTime)):f._panner.setOrientation(t,i,s)),n._emit("orientation",f._id);else return f._orientation}return n},Howl.prototype.pannerAttr=function(){var t=this,i=arguments,s,a,n;if(!t._webAudio)return t;if(i.length===0)return t._pannerAttr;if(i.length===1)if(typeof i[0]=="object")s=i[0],typeof a>"u"&&(s.pannerAttr||(s.pannerAttr={coneInnerAngle:s.coneInnerAngle,coneOuterAngle:s.coneOuterAngle,coneOuterGain:s.coneOuterGain,distanceModel:s.distanceModel,maxDistance:s.maxDistance,refDistance:s.refDistance,rolloffFactor:s.rolloffFactor,panningModel:s.panningModel}),t._pannerAttr={coneInnerAngle:typeof s.pannerAttr.coneInnerAngle<"u"?s.pannerAttr.coneInnerAngle:t._coneInnerAngle,coneOuterAngle:typeof s.pannerAttr.coneOuterAngle<"u"?s.pannerAttr.coneOuterAngle:t._coneOuterAngle,coneOuterGain:typeof s.pannerAttr.coneOuterGain<"u"?s.pannerAttr.coneOuterGain:t._coneOuterGain,distanceModel:typeof s.pannerAttr.distanceModel<"u"?s.pannerAttr.distanceModel:t._distanceModel,maxDistance:typeof s.pannerAttr.maxDistance<"u"?s.pannerAttr.maxDistance:t._maxDistance,refDistance:typeof s.pannerAttr.refDistance<"u"?s.pannerAttr.refDistance:t._refDistance,rolloffFactor:typeof s.pannerAttr.rolloffFactor<"u"?s.pannerAttr.rolloffFactor:t._rolloffFactor,panningModel:typeof s.pannerAttr.panningModel<"u"?s.pannerAttr.panningModel:t._panningModel});else return n=t._soundById(parseInt(i[0],10)),n?n._pannerAttr:t._pannerAttr;else i.length===2&&(s=i[0],a=parseInt(i[1],10));for(var c=t._getSoundIds(a),h=0;h<c.length;h++)if(n=t._soundById(c[h]),n){var f=n._pannerAttr;f={coneInnerAngle:typeof s.coneInnerAngle<"u"?s.coneInnerAngle:f.coneInnerAngle,coneOuterAngle:typeof s.coneOuterAngle<"u"?s.coneOuterAngle:f.coneOuterAngle,coneOuterGain:typeof s.coneOuterGain<"u"?s.coneOuterGain:f.coneOuterGain,distanceModel:typeof s.distanceModel<"u"?s.distanceModel:f.distanceModel,maxDistance:typeof s.maxDistance<"u"?s.maxDistance:f.maxDistance,refDistance:typeof s.refDistance<"u"?s.refDistance:f.refDistance,rolloffFactor:typeof s.rolloffFactor<"u"?s.rolloffFactor:f.rolloffFactor,panningModel:typeof s.panningModel<"u"?s.panningModel:f.panningModel};var p=n._panner;p||(n._pos||(n._pos=t._pos||[0,0,-.5]),e(n,"spatial"),p=n._panner),p.coneInnerAngle=f.coneInnerAngle,p.coneOuterAngle=f.coneOuterAngle,p.coneOuterGain=f.coneOuterGain,p.distanceModel=f.distanceModel,p.maxDistance=f.maxDistance,p.refDistance=f.refDistance,p.rolloffFactor=f.rolloffFactor,p.panningModel=f.panningModel}return t},Sound.prototype.init=function(t){return function(){var i=this,s=i._parent;i._orientation=s._orientation,i._stereo=s._stereo,i._pos=s._pos,i._pannerAttr=s._pannerAttr,t.call(this),i._stereo?s.stereo(i._stereo):i._pos&&s.pos(i._pos[0],i._pos[1],i._pos[2],i._id)}}(Sound.prototype.init),Sound.prototype.reset=function(t){return function(){var i=this,s=i._parent;return i._orientation=s._orientation,i._stereo=s._stereo,i._pos=s._pos,i._pannerAttr=s._pannerAttr,i._stereo?s.stereo(i._stereo):i._pos?s.pos(i._pos[0],i._pos[1],i._pos[2],i._id):i._panner&&(i._panner.disconnect(0),i._panner=void 0,s._refreshBuffer(i)),t.call(this)}}(Sound.prototype.reset);var e=function(t,i){i=i||"spatial",i==="spatial"?(t._panner=Howler.ctx.createPanner(),t._panner.coneInnerAngle=t._pannerAttr.coneInnerAngle,t._panner.coneOuterAngle=t._pannerAttr.coneOuterAngle,t._panner.coneOuterGain=t._pannerAttr.coneOuterGain,t._panner.distanceModel=t._pannerAttr.distanceModel,t._panner.maxDistance=t._pannerAttr.maxDistance,t._panner.refDistance=t._pannerAttr.refDistance,t._panner.rolloffFactor=t._pannerAttr.rolloffFactor,t._panner.panningModel=t._pannerAttr.panningModel,typeof t._panner.positionX<"u"?(t._panner.positionX.setValueAtTime(t._pos[0],Howler.ctx.currentTime),t._panner.positionY.setValueAtTime(t._pos[1],Howler.ctx.currentTime),t._panner.positionZ.setValueAtTime(t._pos[2],Howler.ctx.currentTime)):t._panner.setPosition(t._pos[0],t._pos[1],t._pos[2]),typeof t._panner.orientationX<"u"?(t._panner.orientationX.setValueAtTime(t._orientation[0],Howler.ctx.currentTime),t._panner.orientationY.setValueAtTime(t._orientation[1],Howler.ctx.currentTime),t._panner.orientationZ.setValueAtTime(t._orientation[2],Howler.ctx.currentTime)):t._panner.setOrientation(t._orientation[0],t._orientation[1],t._orientation[2])):(t._panner=Howler.ctx.createStereoPanner(),t._panner.pan.setValueAtTime(t._stereo,Howler.ctx.currentTime)),t._panner.connect(t._node),t._paused||t._parent.pause(t._id,!0).play(t._id,!0)}})()})(Or);const Ba="data:audio/mpeg;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjQxLjEwMAAAAAAAAAAAAAAA//NwwAAAAAAAAAAAAEluZm8AAAAPAAAAFAAACOAAICAgICwsLCwsNzc3NzdDQ0NDQ09PT09PW1tbW1tmZmZmZnJycnJyfn5+fn6KioqKipWVlZWVoaGhoaGtra2trbm5ubm5xcXFxcXQ0NDQ0Nzc3Nzc6Ojo6Oj09PT09P//////AAAAAExhdmM1OC43NQAAAAAAAAAAAAAAACQCwAAAAAAAAAjgTZykiAAAAAAAAAAAAAAAAAD/80DEABJhFmQCwwYUIDsKrsHAWBMRyeJYliQJBg5RYsWU/W3z/8OLc/3AAAQiIAIjv+7vUCJXd4jucQABAE3lwffiDBD+JC58oCH8H/1h/WH//1HPwTUMFrULH9ELKxULyTodFKYbO//zQsQRFFkScKDSRhyGWpIFpG91I7Fi/F6D2RWwN6TN/t9CiVSG5wMw74ogYcHoEwTFyMmTf4KkxEwmRfjXIYv1tpIOZRv/3O9ibtjR6gYmbGCgQ+Fk0mfSmybOX1cf78g7D6nP6qxCgf/zQMQbF+EacktaSABfy+3JKszHdMgcwwcl/kNFIuAo0I0DD1fWVs/crTSTTRInof3cmIwyLBwGQqCSLq7hyvtRPBB4aFyyXHov9X///7UXKqoIIcgcHict89/0y+n+nf/C0DIjB/+P//NCxBYZU9q0AYpoAHNyXSLn/+EjEbJclC4eJT//8e5aMAWeE4////wvAyAvYjZLjAD0Lg9D0kCU/////zwwBdJcYAehKBIwtYyx6FyXC4XP//////x7l83NDpfqd6gAcA/+wu9A2FGg//NAxAwXCnsq/5M4AhQKAOwmRvQRhjhOe5S8UkAmVHpU8IVU3lwejjIcayXOOceGwjf+D05I8oAu2x382o1ZHHV//31NU4441lmqcv///+RNGrUJKImnTf//iVYK1UZquoZESSy3egH/80LEChchBtMfyzAAk191v20qimbuNqavb211BthJKSJAG2aucbdLeVFVmRjZEVvzOggIwuUFDgvEZA7UeuUqNMLOraDQ5CVCk5m9BsmT3kbNrBdolcFSsqXGwQTWyYUX2wEDEgKkvZb/80DECRYRUpWsikYY1HXLbDZksYxtCHBShdHt/DgYCOM6r8AmUSpfGZYzH7ARMBCj1JtmY/hmwoGio0XBUShoklC5GsNeDR38RQ6d01DyrENtqp6mCJ5GJUckmpUBaIgYK6C0fPjmUf/zQsQLFil+cajTBhydxPRO4mLMWWSGQF2qa1f3PPlHQDJdzCxnwgkzB1SQohrpNRYRgtobv07tBLUFc27jQdWoQY0JNpiMJy654enBVoqnQR571uq/i9rpL1oAqAupJATLLk5L+QT3Kf/zQMQOE9D2bWFaGACZyWQZdt1rd3OVY8s/y2dBlg0m12PFzdFSlYrboY6gMOE1hJp7iFqmDcopF8F2OKEPnktdThRLoy9iuyj//0vD4+qf///++38OsIIFFhpEFZMC4s+gZmilJz1X//NCxBkaW8allZI4AWPWKBoLFWrwfuYvukbk4Rt9tBuJYOBoWpfzfjQaNMp//+OGEzzzDIif3+n/4PBIEt5hjDc9zxv/////nseeNDHGg0MQwxBEFn//////4TpB9d/s9thcHddpssFg//NAxAsVCT8GX5BAAigUAPBBdOBaKEIpaajR1VyCNH/gAwAfjRX8G7B4zfx0HANA8BpjQ6FhfqKxRBQURleGbrufzJywVGVfRdOzp5///ERCxhb//8wqijBAwUYMBCjVWZsv26uwYU3/80LEERRTIuTLwxABmdQgEBGKFNo9amfRWcpnayOUsKJ/UpWo/qyL////sj1b+pc3oarStSWpf/VP+hlotDN/0MVjKMKDAZGL/Ar8QWpCR0msAoVgrMoeT3xHIZd3qARkQge7hzlejQD/80DEGxPQ5sryeYYUBCI58AEvohe5nAMDcPxAbUxN6VCB4xCid97iaTyonF0l4upInmIpD//V0f/OllFls0vEBipVlYYRWhuzlHgpEiJSRmYJQaiptezfqvKm1PBRJKiq7M3s1yoqKv/zQsQmFBEGuojBkAQdCzTSpHY0FSwdboEQKi7pZN986g7UVOkf5ZR6VdbbQwZ+79PW6VoWdwZqA4VT2QGoxuuO0VZgbATjSNkSqqresUZ4lDGM5tfbuZzGHYfri5YKg0eDjgQjhm0Wpf/zQMQxE1jyoqhoxFD16D4jzQUUULEB1QXZhRIdIbHFtSlSvX5anFh11QTHaABkiBXOXoXxGW9galRr4fRiew3yOag/4HjxOydOM9ZyyokPlRKdFBa0CjY1luBiKXXwLw6oeMWEhjoS//NCxD4TUNKKIJpMJNTRh7nf/3kekmjdSWypy9UZXQgZMDh3pnAWB4O2M6nAaelR4r1OmVPFSwoksiWRUE1zc+f1lPc0ZudtdFDr4LLpoSwwGkpVO+oD6Tlb3HsYL7d+R1//td2LQMNF//NAxEwTaP5xYqJMCFlqIwAbEoCJNDEp9/3itYVbV6Yx/v0nuLdzyy50qHQw3cafmKlb6zBo0yXeRMnQG5J4jE7j4PFAkTSpQ9pexojMMsL0PIqP/Z1Xp/TpnVZZ27eWtNWRSSSyWyz/80LEWRSo1nDhWhgAlsstlkskgADyNOHqG5rlhLnSyI0a5oClU7uw0JnJQq2kTMBUYADEskGQ9wdHohh2xMKnCubKTIdyRgT83NEIrcfJpJOL3fV7l9cyXXJwJRDGpJLTZJF1+3OPUX3/80DEYiVyorJfmlgDRVRdYm21rHJXTVH0+ajd35ouiSF1tVcmLGnFummxbrhsXfHNzcf/2qgd/7XhppiSaYkmmQGRpnCsAMAEB4tQrXVA0VOiINSMWfljtMTHsRdZ3iL/V1neW6zvLf/zQsQnDSAiMFXMGADWd4i6zvEX+W/yzud5ZUxBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVQ==";let ka=class{constructor(){this.sound=new Or.Howl({src:[Ba]})}play(){this.sound.play()}};function Oa(o,e,t=new d.Box3){if(t.makeEmpty(),!o||!e)return t;o.updateWorldMatrix(!0,!0),e.updateWorldMatrix(!0,!0);const i=new d.Matrix4().copy(e.matrixWorld).invert(),s=new d.Matrix4,a=new d.Vector3;let n=!1;return o.traverseVisible(c=>{var l,u,g;if(!(c!=null&&c.geometry)||!(c!=null&&c.isMesh)||(l=c==null?void 0:c.userData)!=null&&l.ignoreSize)return;const h=c.material;if((u=h==null?void 0:h.userData)!=null&&u.isLOGO)return;const f=c.geometry,p=(g=f==null?void 0:f.getAttribute)==null?void 0:g.call(f,"position");if(!p||p.count<=0)return;s.multiplyMatrices(i,c.matrixWorld);const r=typeof c.getVertexPosition=="function"?c.getVertexPosition.bind(c):void 0;for(let y=0,m=p.count;y<m;y++)r?r(y,a):a.fromBufferAttribute(p,y),a.applyMatrix4(s),t.expandByPoint(a),n=!0}),(!n||t.isEmpty())&&(t.min.set(0,0,0),t.max.set(0,0,0)),t}function za(o,e,t=new d.Vector3){return Oa(o,e).getSize(t)}const be=o=>{var e,t;if(typeof o.destroy=="function"){o.destroy();return}for(;o.children.length>0;)be(o.children[0]),(e=o.children[0])==null||e.removeFromParent();if(o instanceof d.Mesh)try{(t=o.geometry)==null||t.dispose()}catch{}};function Va(o){return new d.Vector3(o[0],o[1],o[2])}function Ua(){let o=3,e=Math.max(1/window.devicePixelRatio,.5);return window.innerWidth/window.innerHeight<.65&&(o=4,e=1/window.devicePixelRatio),{tiles:o,renderScale:e}}function Wa(o){let e=!1,t=!1,i=!1,s=1/0,a=1/0,n=1/0,c=-1/0,h=-1/0,f=-1/0,p=0,r=0;return o.traverse(u=>{var L,C,D;const g=u;if(!(g!=null&&g.isMesh)||!g.geometry||g.userData.ignoreSize)return;const y=g.material;if((L=y==null?void 0:y.userData)!=null&&L.isLOGO)return;const m=g.geometry,v=(C=m==null?void 0:m.attributes)==null?void 0:C.position;if(!v||v.count<=0)return;const _=g.morphTargetDictionary;_&&(_.width!==void 0&&(t=!0),_.length!==void 0&&(e=!0),_.height!==void 0&&(i=!0));const x=(D=m==null?void 0:m.morphAttributes)==null?void 0:D.position,w=g.morphTargetInfluences,b=[];if(x&&w&&x.length>0){const R=Math.min(x.length,w.length);for(let A=0;A<R;A++){const M=w[A]||0;if(M===0)continue;const I=x[A];b.push({attr:I,weight:M,array:I.array,itemSize:I.itemSize??3})}}const T=v.array,S=v.itemSize??3;if(T&&S>=3){const R=v.count,A=b.length>0;for(let M=0;M<R;M++){const I=M*S;let P=T[I],E=T[I+1],B=T[I+2];if(A)for(let G=0;G<b.length;G++){const H=b[G],j=H.weight;if(H.array&&H.itemSize>=3){const U=M*H.itemSize;P+=H.array[U]*j,E+=H.array[U+1]*j,B+=H.array[U+2]*j}else P+=H.attr.getX(M)*j,E+=H.attr.getY(M)*j,B+=H.attr.getZ(M)*j}P<s&&(s=P),E<a&&(a=E),B<n&&(n=B),P>c&&(c=P),E>h&&(h=E),B>f&&(f=B),E>r&&(r=E);const V=P*P+E*E;V>p&&(p=V)}return}for(let R=0;R<v.count;R++){let A=v.getX(R),M=v.getY(R),I=v.getZ(R);if(b.length>0)for(let E=0;E<b.length;E++){const B=b[E],V=B.weight;A+=B.attr.getX(R)*V,M+=B.attr.getY(R)*V,I+=B.attr.getZ(R)*V}A<s&&(s=A),M<a&&(a=M),I<n&&(n=I),A>c&&(c=A),M>h&&(h=M),I>f&&(f=I),M>r&&(r=M);const P=A*A+M*M;P>p&&(p=P)}}),s===1/0?{box:new d.Box3(new d.Vector3(0,0,0),new d.Vector3(0,0,0)),maxRadius:0,height:0,hasWidth:t,hasLength:e,hasHeight:i}:{box:new d.Box3(new d.Vector3(s,a,n),new d.Vector3(c,h,f)),maxRadius:Math.sqrt(p),height:r,hasWidth:t,hasLength:e,hasHeight:i}}function Ha(o,e,t=null){let i=0;return function(){let s=t||this,a=arguments;clearTimeout(i),i=window.setTimeout(function(){o.apply(s,a)},e)}}class Ga{constructor(e,t,i){this.length=e,this.width=t,this.height=i}}const Ys=o=>{var i;let e=0,t=0;if(o.geometry){o.geometry.computeBoundingBox();const s=new d.Vector3;(i=o.geometry.boundingBox)==null||i.getSize(s),s.y?(t=s.y,!s.x&&s.z?e=s.z:s.x&&!s.z?e=s.x:s.x&&s.z&&(e=s.z)):(e=s.z,t=s.x)}return{width:e,height:t}};function fs(){var e;if(typeof navigator>"u")return!1;if(Na())return!0;const o=(e=navigator.userAgent)==null?void 0:e.toLowerCase();return/iphone|ipad|ipod|android|mobile|blackberry|iemobile|opera mini/.test(o)}function Na(){try{if(typeof wx<"u"&&wx.getSystemInfo||typeof my<"u"&&my.alert||typeof tt<"u"&&tt.getSystemInfo||typeof swan<"u"&&swan.getSystemInfo)return!0}catch{}return!1}const zr=new fn.GLTFExporter,We=new cn.GLTFLoader,di=new hn.DRACOLoader;let ct="./draco/";try{ct=new URL("./draco/",typeof document>"u"?require("url").pathToFileURL(__filename).href:ft&&ft.src||new URL("shop-components.cjs",document.baseURI).href).href}catch{ct="./draco/"}typeof window<"u"&&window.dracoPath&&(ct=window.dracoPath);di.setDecoderConfig({type:"wasm"});di.setDecoderPath(ct.endsWith("/")?ct:`${ct}/`);di.preload();We.setDRACOLoader(di);const qa=new un.DRACOExporter,Ks=[115,103,108,98];function ja(o,e,t){const i=JSON.stringify(e),s=new TextEncoder().encode(i),a=new Uint8Array([115,103,108,98]),n=new Uint8Array(2);n[0]=t>>8,n[1]=t&255;const c=new Uint8Array(4);c[0]=s.length>>24,c[1]=s.length>>16&255,c[2]=s.length>>8&255,c[3]=s.length&255;const h=new Uint8Array(o),f=a.length+n.length+c.length+s.length+h.length,p=new Uint8Array(f);let r=0;return p.set(a,r),r+=a.length,p.set(n,r),r+=n.length,p.set(c,r),r+=c.length,p.set(s,r),r+=s.length,p.set(h,r),p.buffer}function Qa(o){const e=new Uint8Array(o.slice(0,4));let t=!0;for(let r=0;r<Ks.length;r++)if(e[r]!==Ks[r]){t=!1;break}if(!t)throw new Error("Invalid file format");const s=new DataView(o,4,2).getUint16(0,!1),n=new DataView(o,6,4).getUint32(0,!1),c=new Uint8Array(o.slice(10,10+n)),h=new TextDecoder().decode(c),f=JSON.parse(h),p=o.slice(10+n);return{version:s,jsonDescription:f,glbContent:p}}class Et{constructor(e){this.props=e,this.cache=new Map}load(e,t,i,s){if(this.props.useCache&&this.cache.has(e)){t(this.cache.get(e));return}const a=this;fetch(e).then(n=>{if(!n.ok){s==null||s(new ErrorEvent("NetworkError",{message:"NetworkError for "+e+": "+n.statusText}));return}return n.arrayBuffer()}).then(async n=>{n||s==null||s(new ErrorEvent("Error",{message:"Not a valid sglb file."}));try{const c=a.parse(n);if(!c.glbContent){s==null||s(new ErrorEvent("Error",{message:"No glb content."}));return}const h=qi(c.glbContent,"model/gltf-binary"),f=await We.loadAsync(h);URL.revokeObjectURL(h),c.glbContent=void 0,c.glb=f.scene,c.scene=f.scene,c.animations=f.animations,n=void 0,this.cache.set(e,c),t(c)}catch(c){s==null||s(new ErrorEvent("Error",{message:c==null?void 0:c.message}))}}).catch(n=>{s==null||s(new ErrorEvent("Error",{message:n.message}))})}async loadAsync(e){if(this.props.useCache&&this.cache.has(e))return this.cache.get(e);try{const t=await fetch(e);if(!t.ok)throw new Error(`NetworkError for ${e}: ${t.statusText}`);const i=await t.arrayBuffer();if(!i)throw new Error("Not a valid sglb file.");const s=this.parse(i);if(!s.glbContent)throw new Error("No GLB content.");const a=qi(s.glbContent,"model/gltf-binary");console.log(a);const n=await We.loadAsync(a);return URL.revokeObjectURL(a),s.glbContent=void 0,s.glb=n.scene,s.scene=n.scene,s.animations=n.animations,this.cache.set(e,s),s}catch(t){throw t}}parse(e){return Qa(e)}clear(){[...this.cache.values()]}}const Ya=`*{box-sizing:border-box}.slot-item-container.is-mobile .main{pointer-events:none;border-width:1px;opacity:.8}.slot-item-container.is-mobile .main.focus{width:18px!important;height:18px!important;border-width:2px;opacity:1}.slot-item-container.is-mobile .main.filled{opacity:1;border-width:1px;width:14px!important;height:14px!important;background-image:none;border-radius:50%}.slot-item-container.is-mobile .main.to-be-installed{opacity:1;pointer-events:auto;width:38px!important;height:38px!important;border-color:#000;border-width:1px;background-image:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20fill='none'%20version='1.1'%20width='20'%20height='20'%20viewBox='0%200%2020%2020'%3e%3cg%3e%3cg%3e%3cpath%20d='M20,10.75L0,10.75L0,9.25L20,9.25L20,10.75Z'%20fill-rule='evenodd'%20fill='%23000000'%20fill-opacity='1'/%3e%3c/g%3e%3cg%20transform='matrix(0,1,1,0,10,-10)'%3e%3cpath%20d='M30,0.75L10,0.75L10,-0.75L30,-0.75L30,0.75Z'%20fill-rule='evenodd'%20fill='%23000000'%20fill-opacity='1'/%3e%3c/g%3e%3c/g%3e%3c/svg%3e");background-size:20px auto;background-repeat:no-repeat;background-position:center;background-color:#fff9}.slot-item-container.is-mobile .main.to-be-installed+.info{pointer-events:auto;overflow:visible;width:auto}.slot-item-container.is-mobile .main.to-be-installed.filled{opacity:1;border-width:2px;width:18px!important;height:18px!important;background-image:none;border-radius:50%;border-color:#00ff95}.slot-item-container.is-mobile .main.to-be-installed.to-be-replaced{opacity:1;border-width:1px;pointer-events:auto;width:38px!important;height:38px!important;border-radius:50%;background-image:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20fill='none'%20version='1.1'%20width='40'%20height='40'%20viewBox='0%200%2040%2040'%3e%3cdefs%3e%3cclipPath%20id='master_svg0_504_014299'%3e%3crect%20x='0'%20y='0'%20width='40'%20height='40'%20rx='20'/%3e%3c/clipPath%3e%3c/defs%3e%3cg%20clip-path='url(%23master_svg0_504_014299)'%3e%3cg%3e%3cg%3e%3cpath%20d='M31.695414,17L26.009501,10.74549544L24.899591,11.75450456L28.304586,15.5L8.75,15.5L8.75,17L31.695414,17Z'%20fill-rule='evenodd'%20fill='%23000000'%20fill-opacity='1'/%3e%3c/g%3e%3cg%3e%3cpath%20d='M8.3045862,23L13.9904997,29.2545042L15.10041,28.2454953L11.6954139,24.5L31.25,24.5L31.25,23L8.3045862,23Z'%20fill-rule='evenodd'%20fill='%23000000'%20fill-opacity='1'/%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/svg%3e");background-size:38px auto;border-color:#000}.slot-item-container.is-mobile .info{left:100%;margin-top:0;margin-left:4px}.slot-item-container.is-mobile .info .name-wrapper{margin-top:0;border-radius:0;background:#000;color:#fff}.slot-item-container.is-mobile .info>img{display:none}.slot-item-container .main{pointer-events:auto;cursor:pointer;font-size:12px;color:#fff;width:22px;height:22px;background:#fff0;border:1.5px solid #fff;border-radius:0;transition:background .2s,width .14s,height .14s,border .14s}.slot-item-container .main.disable{cursor:not-allowed}.slot-item-container .main.drag-over{border-color:red}.slot-item-container .main.can-install{position:relative;width:44px;height:44px;background:#0066ff1a;border-color:#06f}.slot-item-container .main.filled{border-color:#00ff95;border-radius:50%}.slot-item-container .main.selected{border-width:4px}.slot-item-container .main.selected+.info{pointer-events:auto;overflow:visible;width:auto}.slot-item-container .main.focus{border-color:#000}.slot-item-container .main.focus+.info{pointer-events:auto;overflow:visible;width:auto}.slot-item-container .main.has-error{border-color:red}.slot-item-container .main.hidden{display:none}.slot-item-container .main.hidden+.info{display:none}.slot-item-container .main:after{pointer-events:none;content:attr(data-name);transition:all .2s .3s;opacity:0;position:absolute;left:50%;bottom:100%;transform:translate3d(-50%,5px,0);white-space:nowrap;font-size:12px;color:#000;padding:2px 8px;border-radius:2px;background:#fff}.slot-item-container .main:hover{background:#ffffff80}.slot-item-container .main:hover+.info{pointer-events:auto;overflow:visible;width:auto}.slot-item-container .name{position:relative}.slot-item-container .name-wrapper{margin-top:-10px;white-space:nowrap;font-size:12px;color:#fff;padding:2px 8px;background:#000}.slot-item-container .functions-wrapper{z-index:20000;position:absolute;left:0;top:100%}.slot-item-container .functions-wrapper>.functions{display:inline-block;min-width:100px;padding:6px 0;border-left:1px solid #00ff95;border-radius:0 2px 2px 0;background:#0003;-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px)}.slot-item-container .functions-wrapper>.functions .btn-add{cursor:pointer;padding:2px 0;margin:0 8px;display:flex;justify-content:center;align-content:center;align-items:center;border:1px dashed #eee;font-size:12px;color:#eee;border-radius:2px;-webkit-backdrop-filter:none;backdrop-filter:none;background:#00050a80}.slot-item-container .functions-wrapper>.functions .btn-add.btn-not-allowed{cursor:not-allowed}.slot-item-container .functions-wrapper>.functions .function{display:flex;justify-content:space-between;white-space:nowrap;margin-bottom:6px;padding:0 8px;font-size:12px;color:#fff}.slot-item-container .functions-wrapper>.functions .function span{margin-right:4px}.slot-item-container .functions-wrapper>.functions .function .btn-remove{pointer-events:none;opacity:0;cursor:pointer;align-self:center;margin-right:0;height:14px;width:14px;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAACnSURBVEiJxZaxFcMgDETPTuUtWCWTM4pZAq5RojRpnOfEyEKxSnh3HySeBEhNjZJJTRgUG89GyZWilbKOgJCaKmWtFG2UvFnwQr56jYAcengg3dozELPGIjh96x6hu26/DIa9vD0jq/nUA3nikQEkAOW9nACUGbf7skxlX2mIj1Ob0jK76QdxbYpGFNlk3rPnNndDQltFaLMLbdehAyd8ZP5l6Ed+W17xG7oN9QkytAAAAABJRU5ErkJggg==) center no-repeat;background-size:10px 10px}.slot-item-container .functions-wrapper>.functions .function:hover .btn-remove{pointer-events:auto;opacity:1;transform:scale(1.2)}.slot-item-container .device-name{position:relative;margin:2px 0;display:flex;min-width:120px;align-items:center;align-content:center;justify-content:space-between;white-space:nowrap;height:30px;padding:0 8px;font-size:14px;font-weight:700;color:#000;background:#fff}.slot-item-container .device-name .device-logo{margin-left:-8px;margin-right:4px;width:30px;height:30px;object-fit:contain}.slot-item-container .device-name span{display:block;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;max-width:250px}.slot-item-container .device-name .btn-close{margin-left:8px;cursor:pointer;height:20px;width:20px;background:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20fill='none'%20version='1.1'%20width='20'%20height='20'%20viewBox='0%200%2020%2020'%3e%3cdefs%3e%3cclipPath%20id='master_svg0_504_017509'%3e%3crect%20x='0'%20y='0'%20width='20'%20height='20'%20rx='0'/%3e%3c/clipPath%3e%3c/defs%3e%3cg%20clip-path='url(%23master_svg0_504_017509)'%3e%3cg%3e%3cpath%20d='M4.375,16.875L4.375,4.375L15.625,4.375L15.625,16.875L4.375,16.875ZM14.375,5.625L5.625,5.625L5.625,15.625L14.375,15.625L14.375,5.625Z'%20fill-rule='evenodd'%20fill='%23999999'%20fill-opacity='1'/%3e%3c/g%3e%3cg%3e%3cpath%20d='M8.125,12.1875L8.125,8.125L9.375,8.125L9.375,12.1875L8.125,12.1875Z'%20fill-rule='evenodd'%20fill='%23999999'%20fill-opacity='1'/%3e%3c/g%3e%3cg%3e%3cpath%20d='M10.625,12.1875L10.625,8.125L11.875,8.125L11.875,12.1875L10.625,12.1875Z'%20fill-rule='evenodd'%20fill='%23999999'%20fill-opacity='1'/%3e%3c/g%3e%3cg%3e%3cpath%20d='M16.875,5.625L3.125,5.625L3.125,4.375L16.875,4.375L16.875,5.625Z'%20fill-rule='evenodd'%20fill='%23999999'%20fill-opacity='1'/%3e%3c/g%3e%3cg%3e%3cpath%20d='M6.4446528999999995,5.625L13.545177899999999,5.625L11.8665838,2.5L8.15767372,2.5L6.4446528999999995,5.625ZM11.4548223,4.3749999L8.5553472,4.3749999L8.8979512,3.75L11.1191032,3.75L11.4548223,4.3749999Z'%20fill-rule='evenodd'%20fill='%23999999'%20fill-opacity='1'/%3e%3c/g%3e%3c/g%3e%3c/svg%3e") center no-repeat;background-size:100% auto}.slot-item-container .device-name.empty{color:#000c;font-weight:400}.slot-item-container .device-name.empty .btn-close{display:none}.slot-item-container .device-name.empty:before{height:0}.slot-item-container .all-functions{opacity:0;pointer-events:none;min-width:80px;position:absolute;left:-10px;margin-left:100%;bottom:0;padding:6px 0;background:#fff;transition:all .3s}.slot-item-container .all-functions.show{opacity:1;pointer-events:auto;left:16px}.slot-item-container .all-functions label{margin-left:8px;margin-bottom:20px;color:#444e69;font-size:14px}.slot-item-container .all-functions .btn-close{cursor:pointer;position:absolute;right:7px;top:7px;height:16px;width:16px;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAB4SURBVDiNpZPLEYAgDAUXe6MuoK4UpwdBwQkQJDcyb9+QnxORCOC9jyxE4Y78DiWxAIcmISKnxaSrtZhMNSOB+ZeacAS7ngl3k1JOBSBpk1INPib0YHjH+Du2S1DhlSZOYbPJ1iLtrLKrG2a9yJopYzTD8Jx+ArgAylOzjm1WpDwAAAAASUVORK5CYII=) center no-repeat;background-size:10px 10px}.slot-item-container .all-functions .functions{display:inline-block;max-height:200px;overflow-x:hidden;overflow-y:auto}.slot-item-container .all-functions .functions::-webkit-scrollbar{width:4px}.slot-item-container .all-functions .functions::-webkit-scrollbar-track{background-color:#fff}.slot-item-container .all-functions .functions::-webkit-scrollbar-thumb{background:#787878;border-radius:25px}.slot-item-container .all-functions .function{display:flex;justify-content:space-between;white-space:nowrap;padding:5px 10px;font-size:12px;color:#787878}.slot-item-container .all-functions .function span{display:flex;align-content:center;align-items:center;margin-right:4px}.slot-item-container .all-functions .function:hover{background:#444e6933}.slot-item-container .all-functions .btn-add{cursor:pointer;width:16px;font-size:16px;text-align:center;font-style:normal}.slot-item-container .info{overflow:hidden;margin-left:-2px;margin-top:-19px;position:absolute;left:100%;top:50%;transform:translateY(-50%);width:0;display:flex;align-items:flex-start;transition:all .3s}.slot-item-container .info>img{flex:0 0 auto;width:53px;height:29px}`,Ka="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGsAAAA7CAYAAAB8MXT7AAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAGTSURBVHic7dxLbQNBEIThnigADGEhxAwcBoZgCIZgBoZgCIZgCIaQMIgZVC4daw/xXPLoqdX/3fbW0milUtfutMCdpCkiLhEx1U6CLkkvkt4k7atnQYekfR7US/Us6JB0yIOaqmfBA5JWks6SrhzUwCRN+TYdq2dBx+ygDtWzoEPSNg9qVz0LOmZBgsQ3sqUkvufqAf6SpFVEnCPiFhHr1tqteCR8hyBhYrY6OlTPgo5cHX1I2lbPgo6lBInFk3Rc+uroqXqAn8ogcc3H19bae+U8eIDEZ0LSJoMEZeHIWB2ZIPEZoCw0QVlogsRnYlYWsjoaGUHCRK6OOKiRfa2OMvWtqufBAwQJE5SFJmZl4aZ6FnSQ+Azk6mjxZeFv+/fycfbDWrTW1pSFgyLxmcjVEWXh6CgLTZD4DMzKwguro4ERJEywOjIhaUdZaIAgYYKy0ABloQkSnwlxKZUHcSmVBxKfgVwdnSgLB8d35iZIfCYoC01QFpog8Y3rftFWrotO+cilVKMiSJigLDSS30hQFhr4BEcKZN0LNhDxAAAAAElFTkSuQmCC",Xs={name:"",isMobile:!1},Xa={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function wt(o){return o==null?"":String(o).replace(/[&<>"']/g,e=>Xa[e])}function Zs(...o){return o.filter(Boolean).join(" ")}class Vr extends HTMLElement{constructor(e){super(),this._size=12,this._showDialog=!1,this._selected=!1,this._focused=!1,this._toBeInstalled=!1,this._toBeReplaced=!1,this._hasError=!1,this._canInstall=!1,this._hide=!1,this._disable=!1,this._filled=!1,this._allFunctions=[],this._functions=[],this._deviceName="",this._deviceLogo="",this._renderQueued=!1,this._needsRender=!0,this.attachShadow({mode:"open"}),this._props={...Xs,...e??{}},this.handleShadowClick=this.handleShadowClick.bind(this),this.shadowRoot.addEventListener("click",this.handleShadowClick),this.render()}connectedCallback(){this._needsRender&&(this._needsRender=!1,this.render())}get props(){return this._props}set props(e){this._props={...Xs,...e},this.scheduleRender()}get slot(){return this._slot}set slot(e){this._slot=e,this.scheduleRender()}get selected(){return this._selected}set selected(e){const t=!!e;this._selected!==t&&(this._selected=t,this.scheduleRender())}get focused(){return this._focused}set focused(e){const t=!!e;this._focused!==t&&(this._focused=t,this.scheduleRender())}get toBeInstalled(){return this._toBeInstalled}set toBeInstalled(e){const t=!!e;this._toBeInstalled!==t&&(this._toBeInstalled=t,this.scheduleRender())}get toBeReplaced(){return this._toBeReplaced}set toBeReplaced(e){const t=!!e;this._toBeReplaced!==t&&(this._toBeReplaced=t,this.scheduleRender())}get hasError(){return this._hasError}set hasError(e){const t=!!e;this._hasError!==t&&(this._hasError=t,this.scheduleRender())}get canInstall(){return this._canInstall}set canInstall(e){var s;const t=!!e,i=(s=this.shadowRoot)==null?void 0:s.querySelector(".main");if(i){e?i.classList.add("can-install"):i.classList.remove("can-install");return}this._canInstall!==t&&(this._canInstall=t,this.scheduleRender())}get hide(){return this._hide}set hide(e){const t=!!e;this._hide!==t&&(this._hide=t,this.scheduleRender())}get disable(){return this._disable}set disable(e){const t=!!e;this._disable!==t&&(this._disable=t,this.scheduleRender())}get filled(){return this._filled}set filled(e){var s;const t=!!e,i=(s=this.shadowRoot)==null?void 0:s.querySelector(".main");if(i){e?i.classList.add("filled"):i.classList.remove("filled");return}this._filled!==t&&(this._filled=t,this.scheduleRender())}get allFunctions(){return[...this._allFunctions]}set allFunctions(e){this._allFunctions=Array.isArray(e)?[...e]:[],this.hasMoreFunctions||(this._showDialog=!1),this.scheduleRender()}get functions(){return[...this._functions]}set functions(e){this._functions=Array.isArray(e)?[...e]:[],this.hasMoreFunctions||(this._showDialog=!1),this.scheduleRender()}get deviceName(){return this._deviceName}set deviceName(e){this._deviceName=e??"",this.scheduleRender()}get deviceLogo(){return this._deviceLogo}set deviceLogo(e){this._deviceLogo=e??"",this.scheduleRender()}get hasMoreFunctions(){return this._allFunctions.some(e=>!this._functions.includes(e))}setSize(e=12){var s;const t=Number.isFinite(e)?Number(e):12,i=(s=this.shadowRoot)==null?void 0:s.querySelector(".main");if(i){i.style.width=i.style.height=`${e}px`;return}this._size!==t&&(this._size=t,this.scheduleRender())}removeDevice(){var e,t;this._showDialog=!1,this.scheduleRender(),(t=(e=this._props).onRemove)==null||t.call(e)}addFunction(e){this.dispatchEvent(new CustomEvent("function-added",{detail:e}))}scheduleRender(){if(!this.isConnected){this._needsRender=!0;return}this._renderQueued||(this._renderQueued=!0,queueMicrotask(()=>{this._renderQueued=!1,this.render()}))}render(){var p;if(!this.shadowRoot)return;const e=Zs("slot-item-container",this._props.isMobile&&"is-mobile"),t=Zs("main",this._selected&&"selected",this._focused&&"focus",this._toBeInstalled&&"to-be-installed",this._toBeReplaced&&"to-be-replaced",this._hasError&&"has-error",this._canInstall&&"can-install",this._hide&&"hidden",this._disable&&"disable",this._filled&&"filled"),i=this._functions.map(r=>{const l=wt(r);return`<div class="function" data-function="${l}"><span>${l}</span><i class="btn btn-remove" data-action="remove-function" data-function="${l}"></i></div>`}).join(""),s=this._allFunctions.filter(r=>!this._functions.includes(r)),a=this._allFunctions.length?`<div class="functions">${i}${`<div class="btn btn-add ${this.hasMoreFunctions?"":"btn-not-allowed"}" data-action="toggle-dialog">+添加</div>`}</div>`:"",n=s.length?`<div class="all-functions ${this._showDialog?"show":""}">
3706
+ */(function(){HowlerGlobal.prototype._pos=[0,0,0],HowlerGlobal.prototype._orientation=[0,0,-1,0,1,0],HowlerGlobal.prototype.stereo=function(t){var i=this;if(!i.ctx||!i.ctx.listener)return i;for(var s=i._howls.length-1;s>=0;s--)i._howls[s].stereo(t);return i},HowlerGlobal.prototype.pos=function(t,i,s){var r=this;if(!r.ctx||!r.ctx.listener)return r;if(i=typeof i!="number"?r._pos[1]:i,s=typeof s!="number"?r._pos[2]:s,typeof t=="number")r._pos=[t,i,s],typeof r.ctx.listener.positionX<"u"?(r.ctx.listener.positionX.setTargetAtTime(r._pos[0],Howler.ctx.currentTime,.1),r.ctx.listener.positionY.setTargetAtTime(r._pos[1],Howler.ctx.currentTime,.1),r.ctx.listener.positionZ.setTargetAtTime(r._pos[2],Howler.ctx.currentTime,.1)):r.ctx.listener.setPosition(r._pos[0],r._pos[1],r._pos[2]);else return r._pos;return r},HowlerGlobal.prototype.orientation=function(t,i,s,r,o,c){var h=this;if(!h.ctx||!h.ctx.listener)return h;var u=h._orientation;if(i=typeof i!="number"?u[1]:i,s=typeof s!="number"?u[2]:s,r=typeof r!="number"?u[3]:r,o=typeof o!="number"?u[4]:o,c=typeof c!="number"?u[5]:c,typeof t=="number")h._orientation=[t,i,s,r,o,c],typeof h.ctx.listener.forwardX<"u"?(h.ctx.listener.forwardX.setTargetAtTime(t,Howler.ctx.currentTime,.1),h.ctx.listener.forwardY.setTargetAtTime(i,Howler.ctx.currentTime,.1),h.ctx.listener.forwardZ.setTargetAtTime(s,Howler.ctx.currentTime,.1),h.ctx.listener.upX.setTargetAtTime(r,Howler.ctx.currentTime,.1),h.ctx.listener.upY.setTargetAtTime(o,Howler.ctx.currentTime,.1),h.ctx.listener.upZ.setTargetAtTime(c,Howler.ctx.currentTime,.1)):h.ctx.listener.setOrientation(t,i,s,r,o,c);else return u;return h},Howl.prototype.init=function(t){return function(i){var s=this;return s._orientation=i.orientation||[1,0,0],s._stereo=i.stereo||null,s._pos=i.pos||null,s._pannerAttr={coneInnerAngle:typeof i.coneInnerAngle<"u"?i.coneInnerAngle:360,coneOuterAngle:typeof i.coneOuterAngle<"u"?i.coneOuterAngle:360,coneOuterGain:typeof i.coneOuterGain<"u"?i.coneOuterGain:0,distanceModel:typeof i.distanceModel<"u"?i.distanceModel:"inverse",maxDistance:typeof i.maxDistance<"u"?i.maxDistance:1e4,panningModel:typeof i.panningModel<"u"?i.panningModel:"HRTF",refDistance:typeof i.refDistance<"u"?i.refDistance:1,rolloffFactor:typeof i.rolloffFactor<"u"?i.rolloffFactor:1},s._onstereo=i.onstereo?[{fn:i.onstereo}]:[],s._onpos=i.onpos?[{fn:i.onpos}]:[],s._onorientation=i.onorientation?[{fn:i.onorientation}]:[],t.call(this,i)}}(Howl.prototype.init),Howl.prototype.stereo=function(t,i){var s=this;if(!s._webAudio)return s;if(s._state!=="loaded")return s._queue.push({event:"stereo",action:function(){s.stereo(t,i)}}),s;var r=typeof Howler.ctx.createStereoPanner>"u"?"spatial":"stereo";if(typeof i>"u")if(typeof t=="number")s._stereo=t,s._pos=[t,0,0];else return s._stereo;for(var o=s._getSoundIds(i),c=0;c<o.length;c++){var h=s._soundById(o[c]);if(h)if(typeof t=="number")h._stereo=t,h._pos=[t,0,0],h._node&&(h._pannerAttr.panningModel="equalpower",(!h._panner||!h._panner.pan)&&e(h,r),r==="spatial"?typeof h._panner.positionX<"u"?(h._panner.positionX.setValueAtTime(t,Howler.ctx.currentTime),h._panner.positionY.setValueAtTime(0,Howler.ctx.currentTime),h._panner.positionZ.setValueAtTime(0,Howler.ctx.currentTime)):h._panner.setPosition(t,0,0):h._panner.pan.setValueAtTime(t,Howler.ctx.currentTime)),s._emit("stereo",h._id);else return h._stereo}return s},Howl.prototype.pos=function(t,i,s,r){var o=this;if(!o._webAudio)return o;if(o._state!=="loaded")return o._queue.push({event:"pos",action:function(){o.pos(t,i,s,r)}}),o;if(i=typeof i!="number"?0:i,s=typeof s!="number"?-.5:s,typeof r>"u")if(typeof t=="number")o._pos=[t,i,s];else return o._pos;for(var c=o._getSoundIds(r),h=0;h<c.length;h++){var u=o._soundById(c[h]);if(u)if(typeof t=="number")u._pos=[t,i,s],u._node&&((!u._panner||u._panner.pan)&&e(u,"spatial"),typeof u._panner.positionX<"u"?(u._panner.positionX.setValueAtTime(t,Howler.ctx.currentTime),u._panner.positionY.setValueAtTime(i,Howler.ctx.currentTime),u._panner.positionZ.setValueAtTime(s,Howler.ctx.currentTime)):u._panner.setPosition(t,i,s)),o._emit("pos",u._id);else return u._pos}return o},Howl.prototype.orientation=function(t,i,s,r){var o=this;if(!o._webAudio)return o;if(o._state!=="loaded")return o._queue.push({event:"orientation",action:function(){o.orientation(t,i,s,r)}}),o;if(i=typeof i!="number"?o._orientation[1]:i,s=typeof s!="number"?o._orientation[2]:s,typeof r>"u")if(typeof t=="number")o._orientation=[t,i,s];else return o._orientation;for(var c=o._getSoundIds(r),h=0;h<c.length;h++){var u=o._soundById(c[h]);if(u)if(typeof t=="number")u._orientation=[t,i,s],u._node&&(u._panner||(u._pos||(u._pos=o._pos||[0,0,-.5]),e(u,"spatial")),typeof u._panner.orientationX<"u"?(u._panner.orientationX.setValueAtTime(t,Howler.ctx.currentTime),u._panner.orientationY.setValueAtTime(i,Howler.ctx.currentTime),u._panner.orientationZ.setValueAtTime(s,Howler.ctx.currentTime)):u._panner.setOrientation(t,i,s)),o._emit("orientation",u._id);else return u._orientation}return o},Howl.prototype.pannerAttr=function(){var t=this,i=arguments,s,r,o;if(!t._webAudio)return t;if(i.length===0)return t._pannerAttr;if(i.length===1)if(typeof i[0]=="object")s=i[0],typeof r>"u"&&(s.pannerAttr||(s.pannerAttr={coneInnerAngle:s.coneInnerAngle,coneOuterAngle:s.coneOuterAngle,coneOuterGain:s.coneOuterGain,distanceModel:s.distanceModel,maxDistance:s.maxDistance,refDistance:s.refDistance,rolloffFactor:s.rolloffFactor,panningModel:s.panningModel}),t._pannerAttr={coneInnerAngle:typeof s.pannerAttr.coneInnerAngle<"u"?s.pannerAttr.coneInnerAngle:t._coneInnerAngle,coneOuterAngle:typeof s.pannerAttr.coneOuterAngle<"u"?s.pannerAttr.coneOuterAngle:t._coneOuterAngle,coneOuterGain:typeof s.pannerAttr.coneOuterGain<"u"?s.pannerAttr.coneOuterGain:t._coneOuterGain,distanceModel:typeof s.pannerAttr.distanceModel<"u"?s.pannerAttr.distanceModel:t._distanceModel,maxDistance:typeof s.pannerAttr.maxDistance<"u"?s.pannerAttr.maxDistance:t._maxDistance,refDistance:typeof s.pannerAttr.refDistance<"u"?s.pannerAttr.refDistance:t._refDistance,rolloffFactor:typeof s.pannerAttr.rolloffFactor<"u"?s.pannerAttr.rolloffFactor:t._rolloffFactor,panningModel:typeof s.pannerAttr.panningModel<"u"?s.pannerAttr.panningModel:t._panningModel});else return o=t._soundById(parseInt(i[0],10)),o?o._pannerAttr:t._pannerAttr;else i.length===2&&(s=i[0],r=parseInt(i[1],10));for(var c=t._getSoundIds(r),h=0;h<c.length;h++)if(o=t._soundById(c[h]),o){var u=o._pannerAttr;u={coneInnerAngle:typeof s.coneInnerAngle<"u"?s.coneInnerAngle:u.coneInnerAngle,coneOuterAngle:typeof s.coneOuterAngle<"u"?s.coneOuterAngle:u.coneOuterAngle,coneOuterGain:typeof s.coneOuterGain<"u"?s.coneOuterGain:u.coneOuterGain,distanceModel:typeof s.distanceModel<"u"?s.distanceModel:u.distanceModel,maxDistance:typeof s.maxDistance<"u"?s.maxDistance:u.maxDistance,refDistance:typeof s.refDistance<"u"?s.refDistance:u.refDistance,rolloffFactor:typeof s.rolloffFactor<"u"?s.rolloffFactor:u.rolloffFactor,panningModel:typeof s.panningModel<"u"?s.panningModel:u.panningModel};var p=o._panner;p||(o._pos||(o._pos=t._pos||[0,0,-.5]),e(o,"spatial"),p=o._panner),p.coneInnerAngle=u.coneInnerAngle,p.coneOuterAngle=u.coneOuterAngle,p.coneOuterGain=u.coneOuterGain,p.distanceModel=u.distanceModel,p.maxDistance=u.maxDistance,p.refDistance=u.refDistance,p.rolloffFactor=u.rolloffFactor,p.panningModel=u.panningModel}return t},Sound.prototype.init=function(t){return function(){var i=this,s=i._parent;i._orientation=s._orientation,i._stereo=s._stereo,i._pos=s._pos,i._pannerAttr=s._pannerAttr,t.call(this),i._stereo?s.stereo(i._stereo):i._pos&&s.pos(i._pos[0],i._pos[1],i._pos[2],i._id)}}(Sound.prototype.init),Sound.prototype.reset=function(t){return function(){var i=this,s=i._parent;return i._orientation=s._orientation,i._stereo=s._stereo,i._pos=s._pos,i._pannerAttr=s._pannerAttr,i._stereo?s.stereo(i._stereo):i._pos?s.pos(i._pos[0],i._pos[1],i._pos[2],i._id):i._panner&&(i._panner.disconnect(0),i._panner=void 0,s._refreshBuffer(i)),t.call(this)}}(Sound.prototype.reset);var e=function(t,i){i=i||"spatial",i==="spatial"?(t._panner=Howler.ctx.createPanner(),t._panner.coneInnerAngle=t._pannerAttr.coneInnerAngle,t._panner.coneOuterAngle=t._pannerAttr.coneOuterAngle,t._panner.coneOuterGain=t._pannerAttr.coneOuterGain,t._panner.distanceModel=t._pannerAttr.distanceModel,t._panner.maxDistance=t._pannerAttr.maxDistance,t._panner.refDistance=t._pannerAttr.refDistance,t._panner.rolloffFactor=t._pannerAttr.rolloffFactor,t._panner.panningModel=t._pannerAttr.panningModel,typeof t._panner.positionX<"u"?(t._panner.positionX.setValueAtTime(t._pos[0],Howler.ctx.currentTime),t._panner.positionY.setValueAtTime(t._pos[1],Howler.ctx.currentTime),t._panner.positionZ.setValueAtTime(t._pos[2],Howler.ctx.currentTime)):t._panner.setPosition(t._pos[0],t._pos[1],t._pos[2]),typeof t._panner.orientationX<"u"?(t._panner.orientationX.setValueAtTime(t._orientation[0],Howler.ctx.currentTime),t._panner.orientationY.setValueAtTime(t._orientation[1],Howler.ctx.currentTime),t._panner.orientationZ.setValueAtTime(t._orientation[2],Howler.ctx.currentTime)):t._panner.setOrientation(t._orientation[0],t._orientation[1],t._orientation[2])):(t._panner=Howler.ctx.createStereoPanner(),t._panner.pan.setValueAtTime(t._stereo,Howler.ctx.currentTime)),t._panner.connect(t._node),t._paused||t._parent.pause(t._id,!0).play(t._id,!0)}})()})(sn);const Xa="data:audio/mpeg;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjQxLjEwMAAAAAAAAAAAAAAA//NwwAAAAAAAAAAAAEluZm8AAAAPAAAAFAAACOAAICAgICwsLCwsNzc3NzdDQ0NDQ09PT09PW1tbW1tmZmZmZnJycnJyfn5+fn6KioqKipWVlZWVoaGhoaGtra2trbm5ubm5xcXFxcXQ0NDQ0Nzc3Nzc6Ojo6Oj09PT09P//////AAAAAExhdmM1OC43NQAAAAAAAAAAAAAAACQCwAAAAAAAAAjgTZykiAAAAAAAAAAAAAAAAAD/80DEABJhFmQCwwYUIDsKrsHAWBMRyeJYliQJBg5RYsWU/W3z/8OLc/3AAAQiIAIjv+7vUCJXd4jucQABAE3lwffiDBD+JC58oCH8H/1h/WH//1HPwTUMFrULH9ELKxULyTodFKYbO//zQsQRFFkScKDSRhyGWpIFpG91I7Fi/F6D2RWwN6TN/t9CiVSG5wMw74ogYcHoEwTFyMmTf4KkxEwmRfjXIYv1tpIOZRv/3O9ibtjR6gYmbGCgQ+Fk0mfSmybOX1cf78g7D6nP6qxCgf/zQMQbF+EacktaSABfy+3JKszHdMgcwwcl/kNFIuAo0I0DD1fWVs/crTSTTRInof3cmIwyLBwGQqCSLq7hyvtRPBB4aFyyXHov9X///7UXKqoIIcgcHict89/0y+n+nf/C0DIjB/+P//NCxBYZU9q0AYpoAHNyXSLn/+EjEbJclC4eJT//8e5aMAWeE4////wvAyAvYjZLjAD0Lg9D0kCU/////zwwBdJcYAehKBIwtYyx6FyXC4XP//////x7l83NDpfqd6gAcA/+wu9A2FGg//NAxAwXCnsq/5M4AhQKAOwmRvQRhjhOe5S8UkAmVHpU8IVU3lwejjIcayXOOceGwjf+D05I8oAu2x382o1ZHHV//31NU4441lmqcv///+RNGrUJKImnTf//iVYK1UZquoZESSy3egH/80LEChchBtMfyzAAk191v20qimbuNqavb211BthJKSJAG2aucbdLeVFVmRjZEVvzOggIwuUFDgvEZA7UeuUqNMLOraDQ5CVCk5m9BsmT3kbNrBdolcFSsqXGwQTWyYUX2wEDEgKkvZb/80DECRYRUpWsikYY1HXLbDZksYxtCHBShdHt/DgYCOM6r8AmUSpfGZYzH7ARMBCj1JtmY/hmwoGio0XBUShoklC5GsNeDR38RQ6d01DyrENtqp6mCJ5GJUckmpUBaIgYK6C0fPjmUf/zQsQLFil+cajTBhydxPRO4mLMWWSGQF2qa1f3PPlHQDJdzCxnwgkzB1SQohrpNRYRgtobv07tBLUFc27jQdWoQY0JNpiMJy654enBVoqnQR571uq/i9rpL1oAqAupJATLLk5L+QT3Kf/zQMQOE9D2bWFaGACZyWQZdt1rd3OVY8s/y2dBlg0m12PFzdFSlYrboY6gMOE1hJp7iFqmDcopF8F2OKEPnktdThRLoy9iuyj//0vD4+qf///++38OsIIFFhpEFZMC4s+gZmilJz1X//NCxBkaW8allZI4AWPWKBoLFWrwfuYvukbk4Rt9tBuJYOBoWpfzfjQaNMp//+OGEzzzDIif3+n/4PBIEt5hjDc9zxv/////nseeNDHGg0MQwxBEFn//////4TpB9d/s9thcHddpssFg//NAxAsVCT8GX5BAAigUAPBBdOBaKEIpaajR1VyCNH/gAwAfjRX8G7B4zfx0HANA8BpjQ6FhfqKxRBQURleGbrufzJywVGVfRdOzp5///ERCxhb//8wqijBAwUYMBCjVWZsv26uwYU3/80LEERRTIuTLwxABmdQgEBGKFNo9amfRWcpnayOUsKJ/UpWo/qyL////sj1b+pc3oarStSWpf/VP+hlotDN/0MVjKMKDAZGL/Ar8QWpCR0msAoVgrMoeT3xHIZd3qARkQge7hzlejQD/80DEGxPQ5sryeYYUBCI58AEvohe5nAMDcPxAbUxN6VCB4xCid97iaTyonF0l4upInmIpD//V0f/OllFls0vEBipVlYYRWhuzlHgpEiJSRmYJQaiptezfqvKm1PBRJKiq7M3s1yoqKv/zQsQmFBEGuojBkAQdCzTSpHY0FSwdboEQKi7pZN986g7UVOkf5ZR6VdbbQwZ+79PW6VoWdwZqA4VT2QGoxuuO0VZgbATjSNkSqqresUZ4lDGM5tfbuZzGHYfri5YKg0eDjgQjhm0Wpf/zQMQxE1jyoqhoxFD16D4jzQUUULEB1QXZhRIdIbHFtSlSvX5anFh11QTHaABkiBXOXoXxGW9galRr4fRiew3yOag/4HjxOydOM9ZyyokPlRKdFBa0CjY1luBiKXXwLw6oeMWEhjoS//NCxD4TUNKKIJpMJNTRh7nf/3kekmjdSWypy9UZXQgZMDh3pnAWB4O2M6nAaelR4r1OmVPFSwoksiWRUE1zc+f1lPc0ZudtdFDr4LLpoSwwGkpVO+oD6Tlb3HsYL7d+R1//td2LQMNF//NAxEwTaP5xYqJMCFlqIwAbEoCJNDEp9/3itYVbV6Yx/v0nuLdzyy50qHQw3cafmKlb6zBo0yXeRMnQG5J4jE7j4PFAkTSpQ9pexojMMsL0PIqP/Z1Xp/TpnVZZ27eWtNWRSSSyWyz/80LEWRSo1nDhWhgAlsstlkskgADyNOHqG5rlhLnSyI0a5oClU7uw0JnJQq2kTMBUYADEskGQ9wdHohh2xMKnCubKTIdyRgT83NEIrcfJpJOL3fV7l9cyXXJwJRDGpJLTZJF1+3OPUX3/80DEYiVyorJfmlgDRVRdYm21rHJXTVH0+ajd35ouiSF1tVcmLGnFummxbrhsXfHNzcf/2qgd/7XhppiSaYkmmQGRpnCsAMAEB4tQrXVA0VOiINSMWfljtMTHsRdZ3iL/V1neW6zvLf/zQsQnDSAiMFXMGADWd4i6zvEX+W/yzud5ZUxBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVQ==";let Ja=class{constructor(){this.sound=new sn.Howl({src:[Xa]})}play(){this.sound.play()}};function $a(a,e,t=new f.Box3){if(t.makeEmpty(),!a||!e)return t;a.updateWorldMatrix(!0,!0),e.updateWorldMatrix(!0,!0);const i=new f.Matrix4().copy(e.matrixWorld).invert(),s=new f.Matrix4,r=new f.Vector3;let o=!1;return a.traverseVisible(c=>{var l,d,g;if(!(c!=null&&c.geometry)||!(c!=null&&c.isMesh)||(l=c==null?void 0:c.userData)!=null&&l.ignoreSize)return;const h=c.material;if((d=h==null?void 0:h.userData)!=null&&d.isLOGO)return;const u=c.geometry,p=(g=u==null?void 0:u.getAttribute)==null?void 0:g.call(u,"position");if(!p||p.count<=0)return;s.multiplyMatrices(i,c.matrixWorld);const n=typeof c.getVertexPosition=="function"?c.getVertexPosition.bind(c):void 0;for(let v=0,m=p.count;v<m;v++)n?n(v,r):r.fromBufferAttribute(p,v),r.applyMatrix4(s),t.expandByPoint(r),o=!0}),(!o||t.isEmpty())&&(t.min.set(0,0,0),t.max.set(0,0,0)),t}function el(a,e,t=new f.Vector3){return $a(a,e).getSize(t)}const De=a=>{var e,t;if(typeof a.destroy=="function"){a.destroy();return}for(;a.children.length>0;)De(a.children[0]),(e=a.children[0])==null||e.removeFromParent();if(a instanceof f.Mesh)try{(t=a.geometry)==null||t.dispose()}catch{}};function tl(a){return new f.Vector3(a[0],a[1],a[2])}function il(){let a=3,e=Math.max(1/window.devicePixelRatio,.5);return window.innerWidth/window.innerHeight<.65&&(a=4,e=1/window.devicePixelRatio),{tiles:a,renderScale:e}}function sl(a){let e=!1,t=!1,i=!1,s=1/0,r=1/0,o=1/0,c=-1/0,h=-1/0,u=-1/0,p=0,n=0;return a.traverse(d=>{var L,C,I;const g=d;if(!(g!=null&&g.isMesh)||!g.geometry||g.userData.ignoreSize)return;const v=g.material;if((L=v==null?void 0:v.userData)!=null&&L.isLOGO)return;const m=g.geometry,_=(C=m==null?void 0:m.attributes)==null?void 0:C.position;if(!_||_.count<=0)return;const y=g.morphTargetDictionary;y&&(y.width!==void 0&&(t=!0),y.length!==void 0&&(e=!0),y.height!==void 0&&(i=!0));const w=(I=m==null?void 0:m.morphAttributes)==null?void 0:I.position,x=g.morphTargetInfluences,b=[];if(w&&x&&w.length>0){const D=Math.min(w.length,x.length);for(let A=0;A<D;A++){const S=x[A]||0;if(S===0)continue;const P=w[A];b.push({attr:P,weight:S,array:P.array,itemSize:P.itemSize??3})}}const T=_.array,M=_.itemSize??3;if(T&&M>=3){const D=_.count,A=b.length>0;for(let S=0;S<D;S++){const P=S*M;let R=T[P],k=T[P+1],F=T[P+2];if(A)for(let B=0;B<b.length;B++){const N=b[B],W=N.weight;if(N.array&&N.itemSize>=3){const O=S*N.itemSize;R+=N.array[O]*W,k+=N.array[O+1]*W,F+=N.array[O+2]*W}else R+=N.attr.getX(S)*W,k+=N.attr.getY(S)*W,F+=N.attr.getZ(S)*W}R<s&&(s=R),k<r&&(r=k),F<o&&(o=F),R>c&&(c=R),k>h&&(h=k),F>u&&(u=F),k>n&&(n=k);const z=R*R+k*k;z>p&&(p=z)}return}for(let D=0;D<_.count;D++){let A=_.getX(D),S=_.getY(D),P=_.getZ(D);if(b.length>0)for(let k=0;k<b.length;k++){const F=b[k],z=F.weight;A+=F.attr.getX(D)*z,S+=F.attr.getY(D)*z,P+=F.attr.getZ(D)*z}A<s&&(s=A),S<r&&(r=S),P<o&&(o=P),A>c&&(c=A),S>h&&(h=S),P>u&&(u=P),S>n&&(n=S);const R=A*A+S*S;R>p&&(p=R)}}),s===1/0?{box:new f.Box3(new f.Vector3(0,0,0),new f.Vector3(0,0,0)),maxRadius:0,height:0,hasWidth:t,hasLength:e,hasHeight:i}:{box:new f.Box3(new f.Vector3(s,r,o),new f.Vector3(c,h,u)),maxRadius:Math.sqrt(p),height:n,hasWidth:t,hasLength:e,hasHeight:i}}function rl(a,e,t=null){let i=0;return function(){let s=t||this,r=arguments;clearTimeout(i),i=window.setTimeout(function(){a.apply(s,r)},e)}}class nl{constructor(e,t,i){this.length=e,this.width=t,this.height=i}}const or=a=>{var i;let e=0,t=0;if(a.geometry){a.geometry.computeBoundingBox();const s=new f.Vector3;(i=a.geometry.boundingBox)==null||i.getSize(s),s.y?(t=s.y,!s.x&&s.z?e=s.z:s.x&&!s.z?e=s.x:s.x&&s.z&&(e=s.z)):(e=s.z,t=s.x)}return{width:e,height:t}};function Cs(){var e;if(typeof navigator>"u")return!1;if(ol())return!0;const a=(e=navigator.userAgent)==null?void 0:e.toLowerCase();return/iphone|ipad|ipod|android|mobile|blackberry|iemobile|opera mini/.test(a)}function ol(){try{if(typeof wx<"u"&&wx.getSystemInfo||typeof my<"u"&&my.alert||typeof tt<"u"&&tt.getSystemInfo||typeof swan<"u"&&swan.getSystemInfo)return!0}catch{}return!1}const rn=new Pn.GLTFExporter,je=new Cn.GLTFLoader,Si=new Dn.DRACOLoader;let mt="./draco/";try{mt=new URL("./draco/",typeof document>"u"?require("url").pathToFileURL(__filename).href:vt&&vt.src||new URL("shop-components.cjs",document.baseURI).href).href}catch{mt="./draco/"}typeof window<"u"&&window.dracoPath&&(mt=window.dracoPath);Si.setDecoderConfig({type:"wasm"});Si.setDecoderPath(mt.endsWith("/")?mt:`${mt}/`);Si.preload();je.setDRACOLoader(Si);const al=new Ln.DRACOExporter,ar=[115,103,108,98];function ll(a,e,t){const i=JSON.stringify(e),s=new TextEncoder().encode(i),r=new Uint8Array([115,103,108,98]),o=new Uint8Array(2);o[0]=t>>8,o[1]=t&255;const c=new Uint8Array(4);c[0]=s.length>>24,c[1]=s.length>>16&255,c[2]=s.length>>8&255,c[3]=s.length&255;const h=new Uint8Array(a),u=r.length+o.length+c.length+s.length+h.length,p=new Uint8Array(u);let n=0;return p.set(r,n),n+=r.length,p.set(o,n),n+=o.length,p.set(c,n),n+=c.length,p.set(s,n),n+=s.length,p.set(h,n),p.buffer}function cl(a){const e=new Uint8Array(a.slice(0,4));let t=!0;for(let n=0;n<ar.length;n++)if(e[n]!==ar[n]){t=!1;break}if(!t)throw new Error("Invalid file format");const s=new DataView(a,4,2).getUint16(0,!1),o=new DataView(a,6,4).getUint32(0,!1),c=new Uint8Array(a.slice(10,10+o)),h=new TextDecoder().decode(c),u=JSON.parse(h),p=a.slice(10+o);return{version:s,jsonDescription:u,glbContent:p}}class Ut{constructor(e){this.props=e,this.cache=new Map}load(e,t,i,s){if(this.props.useCache&&this.cache.has(e)){t(this.cache.get(e));return}const r=this;fetch(e).then(o=>{if(!o.ok){s==null||s(new ErrorEvent("NetworkError",{message:"NetworkError for "+e+": "+o.statusText}));return}return o.arrayBuffer()}).then(async o=>{o||s==null||s(new ErrorEvent("Error",{message:"Not a valid sglb file."}));try{const c=r.parse(o);if(!c.glbContent){s==null||s(new ErrorEvent("Error",{message:"No glb content."}));return}const h=ns(c.glbContent,"model/gltf-binary"),u=await je.loadAsync(h);URL.revokeObjectURL(h),c.glbContent=void 0,c.glb=u.scene,c.scene=u.scene,c.animations=u.animations,o=void 0,this.cache.set(e,c),t(c)}catch(c){s==null||s(new ErrorEvent("Error",{message:c==null?void 0:c.message}))}}).catch(o=>{s==null||s(new ErrorEvent("Error",{message:o.message}))})}async loadAsync(e){if(this.props.useCache&&this.cache.has(e))return this.cache.get(e);try{const t=await fetch(e);if(!t.ok)throw new Error(`NetworkError for ${e}: ${t.statusText}`);const i=await t.arrayBuffer();if(!i)throw new Error("Not a valid sglb file.");const s=this.parse(i);if(!s.glbContent)throw new Error("No GLB content.");const r=ns(s.glbContent,"model/gltf-binary");console.log(r);const o=await je.loadAsync(r);return URL.revokeObjectURL(r),s.glbContent=void 0,s.glb=o.scene,s.scene=o.scene,s.animations=o.animations,this.cache.set(e,s),s}catch(t){throw t}}parse(e){return cl(e)}clear(){[...this.cache.values()]}}const hl=`*{box-sizing:border-box}.slot-item-container.is-mobile .main{pointer-events:none;border-width:1px;opacity:.8}.slot-item-container.is-mobile .main.focus{width:18px!important;height:18px!important;border-width:2px;opacity:1}.slot-item-container.is-mobile .main.filled{opacity:1;border-width:1px;width:14px!important;height:14px!important;background-image:none;border-radius:50%}.slot-item-container.is-mobile .main.to-be-installed{opacity:1;pointer-events:auto;width:38px!important;height:38px!important;border-color:#000;border-width:1px;background-image:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20fill='none'%20version='1.1'%20width='20'%20height='20'%20viewBox='0%200%2020%2020'%3e%3cg%3e%3cg%3e%3cpath%20d='M20,10.75L0,10.75L0,9.25L20,9.25L20,10.75Z'%20fill-rule='evenodd'%20fill='%23000000'%20fill-opacity='1'/%3e%3c/g%3e%3cg%20transform='matrix(0,1,1,0,10,-10)'%3e%3cpath%20d='M30,0.75L10,0.75L10,-0.75L30,-0.75L30,0.75Z'%20fill-rule='evenodd'%20fill='%23000000'%20fill-opacity='1'/%3e%3c/g%3e%3c/g%3e%3c/svg%3e");background-size:20px auto;background-repeat:no-repeat;background-position:center;background-color:#fff9}.slot-item-container.is-mobile .main.to-be-installed+.info{pointer-events:auto;overflow:visible;width:auto}.slot-item-container.is-mobile .main.to-be-installed.filled{opacity:1;border-width:2px;width:18px!important;height:18px!important;background-image:none;border-radius:50%;border-color:#00ff95}.slot-item-container.is-mobile .main.to-be-installed.to-be-replaced{opacity:1;border-width:1px;pointer-events:auto;width:38px!important;height:38px!important;border-radius:50%;background-image:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20fill='none'%20version='1.1'%20width='40'%20height='40'%20viewBox='0%200%2040%2040'%3e%3cdefs%3e%3cclipPath%20id='master_svg0_504_014299'%3e%3crect%20x='0'%20y='0'%20width='40'%20height='40'%20rx='20'/%3e%3c/clipPath%3e%3c/defs%3e%3cg%20clip-path='url(%23master_svg0_504_014299)'%3e%3cg%3e%3cg%3e%3cpath%20d='M31.695414,17L26.009501,10.74549544L24.899591,11.75450456L28.304586,15.5L8.75,15.5L8.75,17L31.695414,17Z'%20fill-rule='evenodd'%20fill='%23000000'%20fill-opacity='1'/%3e%3c/g%3e%3cg%3e%3cpath%20d='M8.3045862,23L13.9904997,29.2545042L15.10041,28.2454953L11.6954139,24.5L31.25,24.5L31.25,23L8.3045862,23Z'%20fill-rule='evenodd'%20fill='%23000000'%20fill-opacity='1'/%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/svg%3e");background-size:38px auto;border-color:#000}.slot-item-container.is-mobile .info{left:100%;margin-top:0;margin-left:4px}.slot-item-container.is-mobile .info .name-wrapper{margin-top:0;border-radius:0;background:#000;color:#fff}.slot-item-container.is-mobile .info>img{display:none}.slot-item-container .main{pointer-events:auto;cursor:pointer;font-size:12px;color:#fff;width:22px;height:22px;background:#fff0;border:1.5px solid #fff;border-radius:0;transition:background .2s,width .14s,height .14s,border .14s}.slot-item-container .main.disable{cursor:not-allowed}.slot-item-container .main.drag-over{border-color:red}.slot-item-container .main.can-install{position:relative;width:44px;height:44px;background:#0066ff1a;border-color:#06f}.slot-item-container .main.filled{border-color:#00ff95;border-radius:50%}.slot-item-container .main.selected{border-width:4px}.slot-item-container .main.selected+.info{pointer-events:auto;overflow:visible;width:auto}.slot-item-container .main.focus{border-color:#000}.slot-item-container .main.focus+.info{pointer-events:auto;overflow:visible;width:auto}.slot-item-container .main.has-error{border-color:red}.slot-item-container .main.hidden{display:none}.slot-item-container .main.hidden+.info{display:none}.slot-item-container .main:after{pointer-events:none;content:attr(data-name);transition:all .2s .3s;opacity:0;position:absolute;left:50%;bottom:100%;transform:translate3d(-50%,5px,0);white-space:nowrap;font-size:12px;color:#000;padding:2px 8px;border-radius:2px;background:#fff}.slot-item-container .main:hover{background:#ffffff80}.slot-item-container .main:hover+.info{pointer-events:auto;overflow:visible;width:auto}.slot-item-container .name{position:relative}.slot-item-container .name-wrapper{margin-top:-10px;white-space:nowrap;font-size:12px;color:#fff;padding:2px 8px;background:#000}.slot-item-container .functions-wrapper{z-index:20000;position:absolute;left:0;top:100%}.slot-item-container .functions-wrapper>.functions{display:inline-block;min-width:100px;padding:6px 0;border-left:1px solid #00ff95;border-radius:0 2px 2px 0;background:#0003;-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px)}.slot-item-container .functions-wrapper>.functions .btn-add{cursor:pointer;padding:2px 0;margin:0 8px;display:flex;justify-content:center;align-content:center;align-items:center;border:1px dashed #eee;font-size:12px;color:#eee;border-radius:2px;-webkit-backdrop-filter:none;backdrop-filter:none;background:#00050a80}.slot-item-container .functions-wrapper>.functions .btn-add.btn-not-allowed{cursor:not-allowed}.slot-item-container .functions-wrapper>.functions .function{display:flex;justify-content:space-between;white-space:nowrap;margin-bottom:6px;padding:0 8px;font-size:12px;color:#fff}.slot-item-container .functions-wrapper>.functions .function span{margin-right:4px}.slot-item-container .functions-wrapper>.functions .function .btn-remove{pointer-events:none;opacity:0;cursor:pointer;align-self:center;margin-right:0;height:14px;width:14px;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAACnSURBVEiJxZaxFcMgDETPTuUtWCWTM4pZAq5RojRpnOfEyEKxSnh3HySeBEhNjZJJTRgUG89GyZWilbKOgJCaKmWtFG2UvFnwQr56jYAcengg3dozELPGIjh96x6hu26/DIa9vD0jq/nUA3nikQEkAOW9nACUGbf7skxlX2mIj1Ob0jK76QdxbYpGFNlk3rPnNndDQltFaLMLbdehAyd8ZP5l6Ed+W17xG7oN9QkytAAAAABJRU5ErkJggg==) center no-repeat;background-size:10px 10px}.slot-item-container .functions-wrapper>.functions .function:hover .btn-remove{pointer-events:auto;opacity:1;transform:scale(1.2)}.slot-item-container .device-name{position:relative;margin:2px 0;display:flex;min-width:120px;align-items:center;align-content:center;justify-content:space-between;white-space:nowrap;height:30px;padding:0 8px;font-size:14px;font-weight:700;color:#000;background:#fff}.slot-item-container .device-name .device-logo{margin-left:-8px;margin-right:4px;width:30px;height:30px;object-fit:contain}.slot-item-container .device-name span{display:block;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;max-width:250px}.slot-item-container .device-name .btn-close{margin-left:8px;cursor:pointer;height:20px;width:20px;background:url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20fill='none'%20version='1.1'%20width='20'%20height='20'%20viewBox='0%200%2020%2020'%3e%3cdefs%3e%3cclipPath%20id='master_svg0_504_017509'%3e%3crect%20x='0'%20y='0'%20width='20'%20height='20'%20rx='0'/%3e%3c/clipPath%3e%3c/defs%3e%3cg%20clip-path='url(%23master_svg0_504_017509)'%3e%3cg%3e%3cpath%20d='M4.375,16.875L4.375,4.375L15.625,4.375L15.625,16.875L4.375,16.875ZM14.375,5.625L5.625,5.625L5.625,15.625L14.375,15.625L14.375,5.625Z'%20fill-rule='evenodd'%20fill='%23999999'%20fill-opacity='1'/%3e%3c/g%3e%3cg%3e%3cpath%20d='M8.125,12.1875L8.125,8.125L9.375,8.125L9.375,12.1875L8.125,12.1875Z'%20fill-rule='evenodd'%20fill='%23999999'%20fill-opacity='1'/%3e%3c/g%3e%3cg%3e%3cpath%20d='M10.625,12.1875L10.625,8.125L11.875,8.125L11.875,12.1875L10.625,12.1875Z'%20fill-rule='evenodd'%20fill='%23999999'%20fill-opacity='1'/%3e%3c/g%3e%3cg%3e%3cpath%20d='M16.875,5.625L3.125,5.625L3.125,4.375L16.875,4.375L16.875,5.625Z'%20fill-rule='evenodd'%20fill='%23999999'%20fill-opacity='1'/%3e%3c/g%3e%3cg%3e%3cpath%20d='M6.4446528999999995,5.625L13.545177899999999,5.625L11.8665838,2.5L8.15767372,2.5L6.4446528999999995,5.625ZM11.4548223,4.3749999L8.5553472,4.3749999L8.8979512,3.75L11.1191032,3.75L11.4548223,4.3749999Z'%20fill-rule='evenodd'%20fill='%23999999'%20fill-opacity='1'/%3e%3c/g%3e%3c/g%3e%3c/svg%3e") center no-repeat;background-size:100% auto}.slot-item-container .device-name.empty{color:#000c;font-weight:400}.slot-item-container .device-name.empty .btn-close{display:none}.slot-item-container .device-name.empty:before{height:0}.slot-item-container .all-functions{opacity:0;pointer-events:none;min-width:80px;position:absolute;left:-10px;margin-left:100%;bottom:0;padding:6px 0;background:#fff;transition:all .3s}.slot-item-container .all-functions.show{opacity:1;pointer-events:auto;left:16px}.slot-item-container .all-functions label{margin-left:8px;margin-bottom:20px;color:#444e69;font-size:14px}.slot-item-container .all-functions .btn-close{cursor:pointer;position:absolute;right:7px;top:7px;height:16px;width:16px;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAB4SURBVDiNpZPLEYAgDAUXe6MuoK4UpwdBwQkQJDcyb9+QnxORCOC9jyxE4Y78DiWxAIcmISKnxaSrtZhMNSOB+ZeacAS7ngl3k1JOBSBpk1INPib0YHjH+Du2S1DhlSZOYbPJ1iLtrLKrG2a9yJopYzTD8Jx+ArgAylOzjm1WpDwAAAAASUVORK5CYII=) center no-repeat;background-size:10px 10px}.slot-item-container .all-functions .functions{display:inline-block;max-height:200px;overflow-x:hidden;overflow-y:auto}.slot-item-container .all-functions .functions::-webkit-scrollbar{width:4px}.slot-item-container .all-functions .functions::-webkit-scrollbar-track{background-color:#fff}.slot-item-container .all-functions .functions::-webkit-scrollbar-thumb{background:#787878;border-radius:25px}.slot-item-container .all-functions .function{display:flex;justify-content:space-between;white-space:nowrap;padding:5px 10px;font-size:12px;color:#787878}.slot-item-container .all-functions .function span{display:flex;align-content:center;align-items:center;margin-right:4px}.slot-item-container .all-functions .function:hover{background:#444e6933}.slot-item-container .all-functions .btn-add{cursor:pointer;width:16px;font-size:16px;text-align:center;font-style:normal}.slot-item-container .info{overflow:hidden;margin-left:-2px;margin-top:-19px;position:absolute;left:100%;top:50%;transform:translateY(-50%);width:0;display:flex;align-items:flex-start;transition:all .3s}.slot-item-container .info>img{flex:0 0 auto;width:53px;height:29px}`,ul="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGsAAAA7CAYAAAB8MXT7AAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAGTSURBVHic7dxLbQNBEIThnigADGEhxAwcBoZgCIZgBoZgCIZgCIaQMIgZVC4daw/xXPLoqdX/3fbW0milUtfutMCdpCkiLhEx1U6CLkkvkt4k7atnQYekfR7US/Us6JB0yIOaqmfBA5JWks6SrhzUwCRN+TYdq2dBx+ygDtWzoEPSNg9qVz0LOmZBgsQ3sqUkvufqAf6SpFVEnCPiFhHr1tqteCR8hyBhYrY6OlTPgo5cHX1I2lbPgo6lBInFk3Rc+uroqXqAn8ogcc3H19bae+U8eIDEZ0LSJoMEZeHIWB2ZIPEZoCw0QVlogsRnYlYWsjoaGUHCRK6OOKiRfa2OMvWtqufBAwQJE5SFJmZl4aZ6FnSQ+Azk6mjxZeFv+/fycfbDWrTW1pSFgyLxmcjVEWXh6CgLTZD4DMzKwguro4ERJEywOjIhaUdZaIAgYYKy0ABloQkSnwlxKZUHcSmVBxKfgVwdnSgLB8d35iZIfCYoC01QFpog8Y3rftFWrotO+cilVKMiSJigLDSS30hQFhr4BEcKZN0LNhDxAAAAAElFTkSuQmCC",lr={name:"",isMobile:!1},fl={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function Mt(a){return a==null?"":String(a).replace(/[&<>"']/g,e=>fl[e])}function cr(...a){return a.filter(Boolean).join(" ")}class nn extends HTMLElement{constructor(e){super(),this._size=12,this._showDialog=!1,this._selected=!1,this._focused=!1,this._toBeInstalled=!1,this._toBeReplaced=!1,this._hasError=!1,this._canInstall=!1,this._hide=!1,this._disable=!1,this._filled=!1,this._allFunctions=[],this._functions=[],this._deviceName="",this._deviceLogo="",this._renderQueued=!1,this._needsRender=!0,this.attachShadow({mode:"open"}),this._props={...lr,...e??{}},this.handleShadowClick=this.handleShadowClick.bind(this),this.shadowRoot.addEventListener("click",this.handleShadowClick),this.render()}connectedCallback(){this._needsRender&&(this._needsRender=!1,this.render())}get props(){return this._props}set props(e){this._props={...lr,...e},this.scheduleRender()}get slot(){return this._slot}set slot(e){this._slot=e,this.scheduleRender()}get selected(){return this._selected}set selected(e){const t=!!e;this._selected!==t&&(this._selected=t,this.scheduleRender())}get focused(){return this._focused}set focused(e){const t=!!e;this._focused!==t&&(this._focused=t,this.scheduleRender())}get toBeInstalled(){return this._toBeInstalled}set toBeInstalled(e){const t=!!e;this._toBeInstalled!==t&&(this._toBeInstalled=t,this.scheduleRender())}get toBeReplaced(){return this._toBeReplaced}set toBeReplaced(e){const t=!!e;this._toBeReplaced!==t&&(this._toBeReplaced=t,this.scheduleRender())}get hasError(){return this._hasError}set hasError(e){const t=!!e;this._hasError!==t&&(this._hasError=t,this.scheduleRender())}get canInstall(){return this._canInstall}set canInstall(e){var s;const t=!!e,i=(s=this.shadowRoot)==null?void 0:s.querySelector(".main");if(i){e?i.classList.add("can-install"):i.classList.remove("can-install");return}this._canInstall!==t&&(this._canInstall=t,this.scheduleRender())}get hide(){return this._hide}set hide(e){const t=!!e;this._hide!==t&&(this._hide=t,this.scheduleRender())}get disable(){return this._disable}set disable(e){const t=!!e;this._disable!==t&&(this._disable=t,this.scheduleRender())}get filled(){return this._filled}set filled(e){var s;const t=!!e,i=(s=this.shadowRoot)==null?void 0:s.querySelector(".main");if(i){e?i.classList.add("filled"):i.classList.remove("filled");return}this._filled!==t&&(this._filled=t,this.scheduleRender())}get allFunctions(){return[...this._allFunctions]}set allFunctions(e){this._allFunctions=Array.isArray(e)?[...e]:[],this.hasMoreFunctions||(this._showDialog=!1),this.scheduleRender()}get functions(){return[...this._functions]}set functions(e){this._functions=Array.isArray(e)?[...e]:[],this.hasMoreFunctions||(this._showDialog=!1),this.scheduleRender()}get deviceName(){return this._deviceName}set deviceName(e){this._deviceName=e??"",this.scheduleRender()}get deviceLogo(){return this._deviceLogo}set deviceLogo(e){this._deviceLogo=e??"",this.scheduleRender()}get hasMoreFunctions(){return this._allFunctions.some(e=>!this._functions.includes(e))}setSize(e=12){var s;const t=Number.isFinite(e)?Number(e):12,i=(s=this.shadowRoot)==null?void 0:s.querySelector(".main");if(i){i.style.width=i.style.height=`${e}px`;return}this._size!==t&&(this._size=t,this.scheduleRender())}removeDevice(){var e,t;this._showDialog=!1,this.scheduleRender(),(t=(e=this._props).onRemove)==null||t.call(e)}addFunction(e){this.dispatchEvent(new CustomEvent("function-added",{detail:e}))}scheduleRender(){if(!this.isConnected){this._needsRender=!0;return}this._renderQueued||(this._renderQueued=!0,queueMicrotask(()=>{this._renderQueued=!1,this.render()}))}render(){var p;if(!this.shadowRoot)return;const e=cr("slot-item-container",this._props.isMobile&&"is-mobile"),t=cr("main",this._selected&&"selected",this._focused&&"focus",this._toBeInstalled&&"to-be-installed",this._toBeReplaced&&"to-be-replaced",this._hasError&&"has-error",this._canInstall&&"can-install",this._hide&&"hidden",this._disable&&"disable",this._filled&&"filled"),i=this._functions.map(n=>{const l=Mt(n);return`<div class="function" data-function="${l}"><span>${l}</span><i class="btn btn-remove" data-action="remove-function" data-function="${l}"></i></div>`}).join(""),s=this._allFunctions.filter(n=>!this._functions.includes(n)),r=this._allFunctions.length?`<div class="functions">${i}${`<div class="btn btn-add ${this.hasMoreFunctions?"":"btn-not-allowed"}" data-action="toggle-dialog">+添加</div>`}</div>`:"",o=s.length?`<div class="all-functions ${this._showDialog?"show":""}">
3707
3707
  <label>添加功能<i class="btn btn-close" data-action="toggle-dialog"></i></label>
3708
3708
  <div class="functions">
3709
- ${s.map(r=>{const l=wt(r);return`<div class="function"><span>${l}</span><i class="btn btn-add" data-action="add-function" data-function="${l}">+</i></div>`}).join("")}
3709
+ ${s.map(n=>{const l=Mt(n);return`<div class="function"><span>${l}</span><i class="btn btn-add" data-action="add-function" data-function="${l}">+</i></div>`}).join("")}
3710
3710
  </div>
3711
- </div>`:"",c=this._deviceLogo?`<img class="device-logo" src="${wt(this._deviceLogo)}" alt="device logo">`:"",h=wt(((p=this._slot)==null?void 0:p.name)??this._props.name??""),f=wt(this._deviceName||"待安装");this.shadowRoot.innerHTML=`
3712
- <style>${Ya}</style>
3711
+ </div>`:"",c=this._deviceLogo?`<img class="device-logo" src="${Mt(this._deviceLogo)}" alt="device logo">`:"",h=Mt(((p=this._slot)==null?void 0:p.name)??this._props.name??""),u=Mt(this._deviceName||"待安装");this.shadowRoot.innerHTML=`
3712
+ <style>${hl}</style>
3713
3713
  <div class="${e}">
3714
3714
  <div class="${t}" style="width:${this._size}px;height:${this._size}px"></div>
3715
3715
  <div class="info">
3716
- <img alt="" src="${Ka}">
3716
+ <img alt="" src="${ul}">
3717
3717
  <div class="name">
3718
3718
  <div class="name-wrapper">${h}</div>
3719
3719
  <div class="functions-wrapper">
3720
3720
  <div class="device-name ${this._deviceName?"":"empty"}">
3721
3721
  ${c}
3722
- <span>${f}</span>
3722
+ <span>${u}</span>
3723
3723
  <i class="btn btn-close" data-action="remove-device"></i>
3724
3724
  </div>
3725
- ${a}
3726
- ${n}
3725
+ ${r}
3726
+ ${o}
3727
3727
  </div>
3728
3728
  </div>
3729
3729
  </div>
3730
3730
  </div>
3731
- `,this._needsRender=!1}handleShadowClick(e){const t=e.target;if(!t)return;t.closest(".info")&&(e.preventDefault(),e.stopPropagation());const i=t.closest("[data-action]");if(!i)return;const s=i.getAttribute("data-action");if(s)switch(e.preventDefault(),e.stopPropagation(),s){case"remove-device":this.removeDevice();break;case"remove-function":{const a=i.getAttribute("data-function");a&&this.dispatchEvent(new CustomEvent("function-removed",{detail:a}));break}case"toggle-dialog":if(!this.hasMoreFunctions)return;this._showDialog=!this._showDialog,this.scheduleRender();break;case"add-function":{const a=i.getAttribute("data-function");a&&(this.dispatchEvent(new CustomEvent("function-added",{detail:a})),this._showDialog=!1,this.scheduleRender());break}}}}customElements.get("slot-item")||customElements.define("slot-item",Vr);const X={ON_DROP:"slot-on-drop",ON_DEVICE_DELETED:"slot-on-device-deleted",ON_DEVICE_REPLACED:"slot-on-device-replaced",ON_BEFORE_SELECTED:"slot-on-before-selected",ON_SELECTED:"slot-on-selected",ON_ADD_BUTTON_CLICKED:"slot-add-button-clicked",ON_DEVICE_SELECTED:"slot-on-device-selected",ON_DROP_ERROR:"slot-on-drop-error",ON_ERROR_STATE_CHANGE:"slot-on-error-state-change",ON_FUNCTION_REMOVED:"slot-on-function-removed",ON_FUNCTION_ADDED:"slot-on-function-added"};class Qi extends ge.CSS2DObject{constructor(e){const t=document.createElement("div");super(t),this.props=e,this._emitter=new pt,this._slotContainer=new d.Group,this._bracketSlots=[],this._hasError=!1,this.useBracket=!1,this.addEventListener=this._emitter.addListener.bind(this._emitter),this.removeEventListener=this._emitter.removeListener.bind(this._emitter),this._canInstall=!1,this._loading=!1,this._selected=!1,this._deviceSelected=!1,this._focused=!1,this._toBeInstalled=!1,this._toBeReplaced=!1,this._allFunctions=new Set,this._functions=new Set,this._timer=0,this._parentPos=new d.Vector3,this._wrapper=new d.Group,this._showSlot=!0,this._isMirror=!1,this.beforeInstall=void 0,this._preventDefaults=i=>{i.preventDefault(),i.stopPropagation()},this.getWP=this._slotContainer.getWorldPosition.bind(this._slotContainer),t.setAttribute("data-ui-type","slot"),this._showSlot=typeof e.show=="boolean"?e.show:!0,this.name=e.name,this._isMirror=e.isMirror,this._slotUI=new Vr({name:e.name,isMobile:e.isMobile,onRemove:()=>{this.clearSlot(),this._emitter.emit(X.ON_DEVICE_DELETED)}}),this._slotUI.slot=this,this._slotUI.hide=!this._showSlot||this.isMirror,t.append(this._slotUI),this._parentPos.copy(this.props.slot.position),this._slotUI.addEventListener("function-removed",({detail:i})=>{this.removeFunction(i)}),this._slotUI.addEventListener("function-added",({detail:i})=>{this.addFunction(i)}),this.add(this._slotContainer),this.props.slot.add(this),setTimeout(()=>{var i;(i=this.props.slot.parent)==null||i.add(this._wrapper),this._wrapper.add(this.props.slot)},10),["dragenter","dragover","dragleave","drop"].forEach(i=>{t.addEventListener(i,this._preventDefaults,!1)}),t.addEventListener("click",i=>{i.preventDefault(),i.stopPropagation(),this.toBeInstalled?this._emitter.emit(X.ON_ADD_BUTTON_CLICKED):this.selected=!this.selected}),t.addEventListener("dragover",i=>{if(i.preventDefault(),i.dataTransfer.dropEffect="copy",!this._canInstall){i.dataTransfer&&(i.dataTransfer.dropEffect="none");return}}),t.addEventListener("drop",async i=>{var a;if(i.preventDefault(),i.stopPropagation(),!this._canInstall)return;const s=(a=i.dataTransfer)==null?void 0:a.getData("application/json");if(s){const n=JSON.parse(s);try{await this.install(n),this._emitter.emit(X.ON_DROP,this)}catch(c){this._emitter.emit(X.ON_DROP_ERROR,c)}}else this._emitter.emit(X.ON_DROP_ERROR,new Error("No device info"))})}get hasDevice(){return this._slotContainer.children.length>0}get isMirror(){return this._isMirror}shapeKeyChanged(e,t){if(this.props.follows.has(e)){const i=this.props.follows.get(e);if(i){let s="x";["height","mast"].includes(e)?s="z":["width","liftOuterWidth"].includes(e)&&(s="y");const a=i.initPos[s]>0?1:-1;this._wrapper.position[s]=(t-i.origin)*i.scale*a}}}async loadGlb(e){const i=await new Et({useCache:!0}).loadAsync(e);if(i.glb)return i.glb.clone(!0)}async installBracket(e){const i=await new Et({useCache:!0}).loadAsync(e);if(!i.glb)return;const s=i.glb.clone(!0);s.traverse(a=>{a.userData.isBracket=!0}),this.useBracket=!0,this._slotContainer.add(s)}async install(e){var t;if(!this._loading){this._loading=!0,this.beforeInstall&&typeof this.beforeInstall=="function"&&await((t=this.beforeInstall)==null?void 0:t.call(this,e));try{const i=await this.loadGlb(e.url);if(!i)throw new Error(`Fail to load device from: ${e.url}`);if(i.traverse(s=>{s.userData.isDevice=!0}),this.isMirror&&i.scale.set(1,1,-1),e.bracketUrl){const s=await this.loadGlb(e.bracketUrl);if(s)this.clearSlot(),this._emitter.emit(X.ON_DEVICE_REPLACED),s.traverse(a=>{a.name.startsWith("Slot")&&this._bracketSlots.push(a),a.userData.isBracket=!0}),this._slotContainer.add(s);else throw new Error(`Fail to load bracket from: ${e.bracketUrl}`);this._bracketSlots.forEach(a=>{a.add(i)})}else this.clearSlot(),this._emitter.emit(X.ON_DEVICE_REPLACED),this._slotContainer.add(i);this.mirrorTarget&&this.mirrorTarget.install(e),this.deviceInfo=e,this._slotUI.deviceLogo=e.logo||"",this._slotUI.deviceName=e.name,this._slotUI.filled=!0,this.holeTarget&&(this.holeTarget.visible=!1)}catch(i){throw i}finally{this._loading=!1}}}get device(){return this._slotContainer.children.length?this._slotContainer.children[0]:null}get allFunctions(){return[...this._allFunctions]}set allFunctions(e){this._functions.forEach(t=>{e.includes(t)||this._functions.delete(t)}),this._allFunctions=new Set(e),this._slotUI.allFunctions=e}get functions(){return[...this._functions]}addFunction(e){this._allFunctions.has(e)&&(this._functions.add(e),this._slotUI.functions=[...this.functions],this._emitter.emit(X.ON_FUNCTION_ADDED,e))}removeFunction(e){this._functions.has(e)&&(this._functions.delete(e),this._slotUI.functions=[...this.functions],this._emitter.emit(X.ON_FUNCTION_REMOVED,e))}clearFunctions(){this._functions.forEach(e=>this.removeFunction(e))}addFunctions(e){e.forEach(t=>this.addFunction(t)),this._slotUI.functions=this.functions}changeName(e){var t;this.name=e,this.props.slot.userData.name=e,this.props.name=e,(t=this.element)==null||t.setAttribute("data-name",this.props.name)}clearSlot(){this._bracketSlots=[],this._slotContainer.children.forEach(e=>{e.removeFromParent(),be(e)}),this._slotUI.filled=!1,this.deviceInfo=void 0,this._slotUI.deviceName="",this._slotUI.deviceLogo="",this.holeTarget&&(this.holeTarget.visible=!0),this.mirrorTarget&&this.mirrorTarget.clearSlot()}get disabled(){return this._slotUI.disable}enable(){this.show(),this._slotUI.disable=!1}disable(){this._slotUI.disable=!0,this.hide()}hide(){this._slotUI.hide=!0}show(){this.isMirror||this.disabled||(this._slotUI.hide=!1)}get selected(){return this._selected}get focused(){return this._focused}set focused(e){this._focused=e,this._slotUI.focused=e}get toBeInstalled(){return this._toBeInstalled}set toBeInstalled(e){this._toBeInstalled=e,this._slotUI.toBeInstalled=e}get toBeReplaced(){return this._toBeReplaced}set toBeReplaced(e){this._toBeReplaced=e,this._slotUI.toBeReplaced=e}set selected(e){this.disabled||(e&&this._emitter.emit(X.ON_BEFORE_SELECTED,e),this._selected=e,this._slotUI.selected=e,this._emitter.emit(X.ON_SELECTED,e),this.element.style.zIndex="100",this.selected?this.renderOrder=1/0:this.renderOrder=1)}get deviceSelected(){return this._deviceSelected}set deviceSelected(e){this._deviceSelected=e,this._emitter.emit(X.ON_DEVICE_SELECTED,e)}get error(){return this._hasError}set error(e){this._loading&&setTimeout(()=>{this.error=e},100),this._hasError=e,this._slotUI.hasError=e,this._emitter.emit(X.ON_ERROR_STATE_CHANGE,e)}getCanInstall(){return this._canInstall}canInstall(e){this._canInstall=e,this._slotUI.canInstall=e}dispose(){cancelAnimationFrame(this._timer),["dragenter","dragover","dragleave","drop"].forEach(e=>{this.element.addEventListener(e,this._preventDefaults,!1)}),this.props.follows.clear(),this.clearSlot(),this._emitter.removeAllListeners(),be(this._slotContainer),this.element.remove()}render(e){const t=this.element.style.transform,i=/translate\(-?\d*\.?\d*%?,?\s-?\d*\.?\d*%?\)\s*translate\((-?\d*\.?\d*)px,\s*(-?\d*\.?\d*)px\)/.exec(t);if(!i)return;const s=new d.Vector2(parseFloat(i[1]),parseFloat(i[2])),a=e.mousePos.distanceTo(s);let n=this.props.isMobile?12:18,c=38,h=30;if(this._canInstall&&(n=34,c=60,h=60),a<h){let f=(h-a)*1+n;a<20&&(f=c),f>c&&(f=c),this._slotUI.setSize(f)}else this._slotUI.setSize(n)}clone(e){return new d.Group}}class Za extends ge.CSS2DObject{constructor(e){const t=document.createElement("div");super(t),this._text=document.createElement("div");const i=fs(),s=i?"#ddd":"#eee";this.element.style.pointerEvents="auto",this.element.style.padding=i?"2px 6px":"3px 12px",this.element.style.borderTop=`1px solid ${s}`,this.element.style.borderBottom=this.element.style.borderTop;const a="6px",n=document.createElement("div");n.style.pointerEvents="none",Object.assign(n.style,{pointerEvents:"none",borderLeft:`1px solid ${s}`,borderRight:`1px solid ${s}`,position:"absolute",left:"0",top:"0",boxSizing:"border-box",height:a,width:"100%"}),this.element.append(n);const c=document.createElement("div");c.style.pointerEvents="none",Object.assign(c.style,{pointerEvents:"none",borderLeft:`1px solid ${s}`,borderRight:`1px solid ${s}`,position:"absolute",left:"0",bottom:"0",boxSizing:"border-box",height:a,width:"100%"}),this.element.append(c),this._text.style.fontSize=i?"10px":"14px",this._text.style.font="SF Pro SC,SF Pro Text,SF Pro Icons,PingFang SC,Helvetica Neue,Helvetica,Arial,sans-serif",this._text.style.color="#fff",this._text.style.fontWeight="500",this._text.style.transition="all .16s",this._text.innerText=e,this.element.append(this._text),this._text.addEventListener("pointermove",()=>{var h;n.style.borderColor=c.style.borderColor=this.element.style.borderColor="#666",this._text.style.color="#000",(h=this.onPointMove)==null||h.call(this)}),this._text.addEventListener("pointerleave",()=>{var h;n.style.borderColor=c.style.borderColor=this.element.style.borderColor=s,this._text.style.transform="scale(1)",this._text.style.color="#fff",(h=this.onPointLeave)==null||h.call(this)})}set text(e){this._text.innerText=e}dispose(){this.element&&this.element.parentNode&&this.element.parentNode.removeChild(this.element)}}class oi extends d.Group{constructor(e,t=!0,i=!0){super(),this._startWith=e,this._showText=t,this.useStartEnd=i,this._line2Length=.01,this._line=new d.LineSegments(new d.BufferGeometry,new d.LineBasicMaterial({color:"#666",linewidth:2})),this._line2=new d.LineSegments(new d.BufferGeometry,new d.LineBasicMaterial({color:"#666",linewidth:2})),this._text=new Za(""),this._line.frustumCulled=!1,this.add(this._line,this._line2),this._showText&&(this.add(this._text),this._text.onPointMove=()=>{this._line.material.color.set("#000"),this._line2.material.color.set("#000")},this._text.onPointLeave=()=>{this._line.material.color.set("#666"),this._line2.material.color.set("#666")})}updateMaterial(e){this._line.material=e}reset(){var e,t;(e=this._line.geometry)==null||e.dispose(),this._line.geometry=new d.BufferGeometry().setFromPoints([new d.Vector3,new d.Vector3]),this._line.computeLineDistances(),(t=this._line2.geometry)==null||t.dispose(),this._line2.geometry=new d.BufferGeometry().setFromPoints([new d.Vector3,new d.Vector3]),this._line2.computeLineDistances()}update(e,t,i=0){var u,g;(u=this._line.geometry)==null||u.dispose(),this._line.geometry=new d.BufferGeometry().setFromPoints([e,t]),this._line.computeLineDistances();const s=this._line2Length+i*.02,a=new d.Vector3().subVectors(t,e).normalize();let n;Math.abs(a.z)>Math.abs(a.x)&&Math.abs(a.z)>Math.abs(a.y)?n=new d.Vector3(-a.y,a.x,0):Math.abs(a.y)>Math.abs(a.x)?n=new d.Vector3(1,0,0):n=new d.Vector3(0,1,0),n.length()<.001&&(Math.abs(a.x)<.9?n=new d.Vector3(1,0,0):n=new d.Vector3(0,1,0)),n.normalize();const c=new d.Vector3().addVectors(e,n.clone().multiplyScalar(s)),h=new d.Vector3().addVectors(e,n.clone().multiplyScalar(-s)),f=new d.Vector3().addVectors(t,n.clone().multiplyScalar(s)),p=new d.Vector3().addVectors(t,n.clone().multiplyScalar(-s));(g=this._line2.geometry)==null||g.dispose(),this._line2.geometry=new d.BufferGeometry,this._line2.geometry.setFromPoints([c,h,f,p]),this._line2.computeLineDistances();const r=e.distanceTo(t);this._startWith?this._text.text=`${this._startWith}${(r*1e3).toFixed(0)} mm`:this._text.text=`${(r*1e3).toFixed(0)} mm`;const l=new d.Vector3;l.addVectors(e,t).multiplyScalar(.5),this._text.position.copy(l),this.useStartEnd||(this._line2.visible=!1)}destroy(){this._text.dispose(),this.children.forEach(e=>be(e)),this.removeFromParent()}}class Ur extends d.Object3D{constructor(e,t){super(),this.radius=e,this._text=new Ja(""),this._line=new oi(void 0,!1,!1),this._box=new d.Mesh,this._arc=new pn.Line2,this._previousPosition=null,this._updateTimer=null,this._updateDelay=300,this._accumulatedAngle=0,this._lastAngle=null,this._line.updateMaterial(new d.LineDashedMaterial({color:"#555",dashSize:.06,gapSize:.06})),this._line.renderOrder=0,this._box.geometry=new d.RingGeometry(e,e+.003,128),this._box.material=new d.MeshBasicMaterial({color:"#666",side:d.DoubleSide}),this._arc.geometry=new bs.LineGeometry,this._arc.geometry.setPositions([0,0,0,0,0,0]),this._arc.geometry.instanceCount=0,this._arc.material=new mn.LineMaterial({color:"#eee",linewidth:2,resolution:new d.Vector2(window.innerWidth,window.innerHeight)}),this._arc.visible=!1,this._arc.rotateX(-Math.PI/2),this.position.y=t,this._arc.position.y=.001,this.add(this._box),this.add(this._arc),this.add(this._line),this.add(this._text)}hide(){this._text.hide(),this._line.visible=!1,this._arc.visible=!1}show(){this._text.show(),this._line.visible=!0}dispose(){this._updateTimer&&(clearTimeout(this._updateTimer),this._updateTimer=null),this._box.geometry&&this._box.geometry.dispose(),this._arc.geometry&&this._arc.geometry.dispose(),this._arc.visible=!1,this._previousPosition=null}update(e){var t;this.radius=e,(t=this._box.geometry)==null||t.dispose(),this._box.geometry=new d.RingGeometry(e,e+.003,128),this._line.updateMaterial(new d.LineDashedMaterial({color:"#555",dashSize:.06*e,gapSize:.06*e})),this._text.update((e*1e3).toFixed(0))}change(e){const t=e.clone();t.setZ(0),t.normalize().multiplyScalar(this.radius),this._text.position.set(t.x,t.y,t.z),this._text.updateColor("#eee"),this._line.update(t,new d.Vector3),this._previousPosition&&this._updateArc(this._previousPosition,t),this._updateTimer&&clearTimeout(this._updateTimer),this._updateTimer=setTimeout(()=>{this._previousPosition=null,this._accumulatedAngle=0,this._lastAngle=null,this._clearArc(),this._updateTimer=null},this._updateDelay),this._previousPosition||(this._previousPosition=t.clone(),this._lastAngle=Math.atan2(t.y,t.x),this._accumulatedAngle=0)}_updateArc(e,t){const i=Math.atan2(t.y,t.x);if(this._lastAngle!==null){let h=i-this._lastAngle;h>Math.PI?h-=2*Math.PI:h<-Math.PI&&(h+=2*Math.PI),this._accumulatedAngle+=h}if(this._lastAngle=i,Math.abs(this._accumulatedAngle)<.01){this._arc.visible=!1;return}const s=Math.atan2(e.y,e.x),a=s+this._accumulatedAngle;let n=.006*this.radius;n<.003&&(n=.003),n>.006&&(n=.006);const c=this._createArcGeometry(s,a,this.radius+n);this._arc.geometry&&this._arc.geometry.dispose(),this._arc.geometry=c,this._arc.visible=!0}_clearArc(){this._text.updateColor(),this._arc.geometry&&(this._arc.geometry.setPositions([0,0,0,0,0,0]),this._arc.geometry.instanceCount=0,this._arc.computeLineDistances()),this._arc.visible=!1}_createArcGeometry(e,t,i){const s=[],a=t-e,n=Math.max(128,Math.floor(Math.abs(a)/(Math.PI/128))),c=a/n;for(let f=0;f<=n;f++){const p=e+f*c,r=Math.cos(p),l=Math.sin(p);s.push(i*r,0,i*l)}const h=new bs.LineGeometry;return h.setPositions(s),h.instanceCount=Math.max(0,s.length/3-1),h}}class Ja extends ge.CSS2DObject{constructor(e){const t=document.createElement("div");super(t),this._wrapper=document.createElement("div"),this._circle=document.createElement("div");const i=fs();this._wrapper.style.fontSize=i?"10px":"11px",this._wrapper.style.color="#fff",this._wrapper.style.whiteSpace="nowrap",this._wrapper.style.position="absolute",this._wrapper.style.transform="translateX(-50%)",this._wrapper.style.top="6px",this._wrapper.style.font="SF Pro SC,SF Pro Text,SF Pro Icons,PingFang SC,Helvetica Neue,Helvetica,Arial,sans-serif";const s=this._circle;s.style.position="relative",s.style.zIndex="10",s.style.width=s.style.height="5px",s.style.borderRadius="50%",s.style.background="#666",t.append(this._wrapper,s),this.update(e)}show(){this.element.style.display="block"}hide(){this.element.style.display="none"}update(e){this._wrapper.innerText="旋转半径:"+e+" mm",this.updateColor("#eee")}updateColor(e="#666"){this._circle.style.background=e}}const $a="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADgAAAAUCAYAAADY6P5TAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAEvSURBVFiFzZdbFYMwEEQroRKQgAQkVEIlICEOkFAJlRAJSIgEJNx+sPS0nGxIaOhyv3nM7mTmwOViDHAFesADD+BqrakKQAcMwMQ3AWis9e1C3HLASJoAdNZ6sxG3/MZQMZy1dhWgFbfWRzDGlFjAwFlyyXdh5OD5OIqykBgBy1yiF0aMUQaJugLclOcEoP3nULmFgQgeyCwOoJGBYrijByspDM98ZIszJAt8Ks8dag/VUFYYLtetjHdruRz5JZf8WBg1Ae7KcgOluaSsMAKJwqgJ6Vz2WzcvhZHjVlFh1ESG1DQ67SYtyGs8OwujNpTkUtw4nVtbyLK1XDafF3aKW90Z3EpBbi5lE0u9n3qoNTKk9rHh3heZqqwA8Vw6a11VkVwuPK31HALzb5pfovYC2xSs5LCDIUcAAAAASUVORK5CYII=",el="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAKCAYAAACngj4SAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAChSURBVDiNrdJbFYMwEIRhJFQCEpCAhEqIhDhBAlKQgAQkIOHrSziHpmkbLvua7P4zO9s0FYUeM0b0NT2nC9FnLQho7wQ9MOwgQ3K4ZPDrrtGmFcKKkL0HTAXXw2HX6HYuFnR/hMWC6ykX+W1AzJqq1abDGguux6LoPK9aUGFOm1Y+F+Bh+7DlsSKehRXgnfdDm5od7GdeN8ADnpuKQ3ldqReHZFd3742nZgAAAABJRU5ErkJggg==",Js="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGwAAABsCAYAAACPZlfNAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAdzSURBVHic7Z3hlZs6EIUvW4E7CB3EHcQdxB08OngugVTg8yrwSQVOKnBSwW4qsFOB3cF9PxhZQsYYjEAS1neOD7ssCwPXMxoNIGWIDJJLAAsASwCfAOTyey6bLOQDABf5qJ9P8vkry48sy05j2+ySzLcBjyC5QiXOV1kuWv+hPxcAvwD8BvCBSsRL6394JDjBSC4ArFEJtG7Y5ILqwp4A/JHlxfyoC04yN/4vh/bEz9Dim9uY+/8O4EfI4nmFZEFyz1veSe5Iri0BXB13Icfekjxaxz6TPMixXXt2fJDM5WLZF+og63MPNi1IbsQGW7zyJYUToXZyEUxP8iLSPUS80hLvdYQTobbWN3fHKvMLGpKrBq/bzla4htC3C8mbutIg3JnkxrddzhCvil4omwbhDqy6IPEisV5xJFn4tsk1rDJI8wtZ+rapN+JV73PzqnuwSk7MtvkQzflabdUxGsMdIGFSnfuZZFPHPxysELjnXDOoFsTbzAJA6dumRiyxSt/2+Ma6Hlvf9lyRb9QumjAwIZKQqOLAznvEEbFUcvFS7VVXWO/WvHsTLYnVnSBEM8JgEqsDlmi7qQ++TWL1xxKtnOqgKvs5J7H6I6KdJxFNsh5FygafxLqOxVgHme6b8QIYkWqcZoW6Mr13vvMXhboi8u56x+a34eXKTWMhXSO3SQirgqZi5WSniSvS1ChyFztUoTCcetjMoNGnHbqjTQqF42P1z4pnd7IwssKUwo8Mq/uIz2eN1NWMg3vzxoUWvu3pihEa+zU/4l3RJhoRC/ZcAkKdxkfnXUC8ggE1L+tWILbartW45o1D5IIpL+tWq43du4C4BQNqXlY82jB67wJmIdhSTG/vl1FXkaP1LiB+wQCA+m5+Ya5/s7b7V5a/J7Eq0cZ/svza+FcrHEZd1ZiJh5kp/q0e1D3tqMMhMA/BgFodt1DrzJD4jyx/TmpVoo3vsqyHxTmFQ2BWHpY3ngP1Pa9h5f1AmItgQC1bXAE6JKpXVn94sSrRxocsl4AW7Iss/0xuTuIRKqfQ7dic2i9gdiHxWlu0V8yi/QLmJRhQc6jlG3T7lYboCRfVji3eoMda+mjeNhEAJ1ku31ANYQekhCNklDafTA87eTEl0YWTLHNTsNSGhYvSZvEGPWDkyY8t1xt2ua/jd0Uyah/jYinBcvt+2OTIBTgAOHi6GJ3wbKeOfkaOn09sRNM4VGcXF8N1P0wiwNmyMx+63x7HV48dnuHqpJ40ZMNbBovmUrAGsRSTjuB2PRefgokhZcPFGCSaK8FaxCqf3ecAW66Cea8juhbNhWCBiaXridRtSD61IZZRzkQbKlhIYok9ut5rCOY9Q3Ml2hDBQhNLbKoJdpBfVr4MMnEh2rOChSiW2KWeCHg3X4wO5h2woaI9I1ioYolt6gHf/RuMOpU/k+pkWVYC+GatXmCkTit1p9hOvL6JLb7JZXky+0LTjn/UgWc9rY+HhexZCuqXIzZmfAzyAdJnROsqWAxiAbUnp9bmmxJn34bdo69oXQSLRSwAt10veqwndqVFtKJh21bBWD2WHotYuo5orDzIymAyxSbuiEZbtDbBqN8hCF4soGbv3lwZbOJh00W0e4LFJhZQG81hY67UHbMIeCRak2AxigXU2q+V/QdF7sWynrSJ1nFdDGJd2y/axXnqikfhx7z+tIjWhdK3/Y+gbqpuu1yM9IU+Nt8EfUQU00ex4YU+84/m6Df55NYNgPdDXhOFb3u7wLZwaGwUXVhUdBSt8G1nV9hlvBTjpKPIFm0eiFb4tq8P7No3ZkA3NJ/hjmiFb7v6QN3Nuh8OjY3VCQffib6HJVrh256+GN5Vdtk4ZwS1xUeIaIVvO/rSy7uMf9rF7mWx0su7jH9SD31E7WWxwfoI5v0eO6QuOiYvmwgOGcGcLkZ6TnSG+kGb7m1Xw05UtnVMoXE8WJ8hYljZjL4mKXsh6HIE85SAjAvHmCqFabKcUeAYk+UYO1ePWqXpqBxBXWx3f0vLyhpL5wd4MYyoNd7bnKzX6IJ+wipkOOXUlJN8M2YMfUxNaSUh+SQHnQFWszLtfGxME2/3whJr+j4t09T2nbHE8jO1vRiSRHtAMGIZBi2M8HhO2aNGskGVYOy8i2VCXQ+bLvsJGNYfci1929OIZeQ+qG/UREjE2QcvlsIKA0cGMjrBFFjt1ZGx3EcUww/Gt2w7Z2+T890Z5/seZQJmhcjjHBMSVuW6o3GepW+bBsHqfo/pbYc5hMkGrzpG6VX3YPWWyTl24e4IVfi2axRYZVBm+h+NcKxGHdhZtm9n5VX3EOHKBo8rGVByIt5UUFdzKDbvXkIomzvCKfE2PsQzRDpYNh1lfT61TcEhwq3lItniHSX0FGMIKAKtxWveecueAbVRmW8DbESUNaopHpe4HbDrhGqU6Q9UMyao309qgyzLTsa+7E8O4LMsm/YPVPOo/QTwI8uyoMbzD04wE7ngS/l8AbBC8wUeghL/J4CPLMt+Od6/U4IWrAlpQ5aoPOSTLHNoIRfGzxfoMd9P0J74F5VIlyzLopok6H/tVqA8kSYfTwAAAABJRU5ErkJggg==",tl="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYwAAACsCAYAAABo4pvIAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAzYSURBVHic7d3hcdtIEobhD05gmYGRgbkRLDKwMjiGoBCUgeoi0F0Evo1AdASiIxAcgbkR9P1Aj9mESIm2QMwAeJ8qlihKomeXwHzsHgCsBBTOzGpJK7+pd7/2r3+ceCw69Vh8nkvt/fbW4/H7vaR//H4bfqeNX6uqij8DilPlHgCWxcxW6ibvNFmn+x/DY/Fn0mHyPXVLE7F0ejKOf3/SpRO1B9c55wJNOg6rfrD1/5v7/31pbN97j7WS9lVVnf3vAoZGYGAwPqHW6ia+tbrJce0/Tj+Lk176+k/4/ui2tAnRA/VUaNbqQjXdr8PvtDoOku/xeyoXDIXAwMXMbK1DGHzUcTikiatVN1l9Uy8YmLiG1wuY2r9+0vHrUuvwOux0/PrseF1wKQIDR06EQvw+TTatunexrXgXOwmh+ku31AJc6xAoMUxaESboITAWyoOhVjdhfAr307vQnbpQ2KlrDe2yDBSj8EBJ20S/Qml12B7S/XZp7UIQGLMX3lk2Og6Gnbqd/1u4zySAI+EghRQmH9VtS7W6bWYrKpLFIDBmJFQNf6nbwdOCc6oYvqqrFrY5xof56AXJJ53e3r5J2hIi80FgTFRoIcRwaP32Vb7TUjFgTCdaW426thYhMgMExgT4u7m1Dm2lxn+UqoatCAcUyrffRodqpPEfbcWbm0khMAoUdrBUPTTyUFC3g7UsQmPKvBJpdNzOiq3TLQFSHgKjAKGM/6xDOb+T9Le6d17bXGMDxmJmjY73g1aHRfX/ESD5ERgZhBbTZx2OOCEggOCVAEn7CQEyMgJjJL2Nv9Hxhr/NNS5gKnr7UK0uQNiHMH1mtjKzGzN7MLNnvz34Rg/gHXz/aszs3vetH75/bbyCB8pmZrVvsI/WeTSzWz8/AsCV+L536/vcj7Dv1bnHBvxkZmt/l/MUqogb3uUAefSqjx++X95R3SOLEBK0moDCER4Y3YmQuKfVBEyLh8dd2I8JDwzD+6J3hAQwP2fCo849LkyI9z/TwnVqNxESwIyF8IgL5qxD4jTfYB786KYvZnaTe0wAxudzQTraivVJdE60nDaUpACkn92GuxAed1QdCxSqCY5wAvCm3pFWj8wZM2eHk+p+VhO5xwRgWrzqSCcIPrHWMTMeFGltgmoCwCB6ax33tLMnzM+biG2nOveYAMxPWAulXTU1vUNiuRAZgFGERfJngqNwrE8AKEVoVz0xHxWEoABQqhAczE85ERQApiIEB62qMREUAKaK4BiJH4nwRFAAmDqC40rCeRQEBYBZ8Y5JumZVnXs8k9U7RO0u93gA4Br6cx2nAvyisE5B6gJYBA+OB684uFr2W3rtpzr3eABgbL31jTr3eIoUTq2/yz0WAMjNugsbPpvZbe6xFMOrimfSFACO+fyYzhhvco8nq1BVkKAAcIZXGz/M7D73WEYXqgoWtQHgAr1qo849nlGEvtwm91gAYGoWsbbBEVAAMIxw5YvH2Z23EVpQy+u/AcAV+Hkb9z63rnOPZxBhsWa+5RMAZDKbFlVIvzr3WABgrsbq4ny4xpOm/pqklaQ/q6pqr/HvAAAkn2P/lLSa1FFUIenuco8FAJYmXMiwzj2WVxEWAJBfCI0yF8PN7MYXtze5xwIASxeu+t3kHsuRMLAy0wwAFsjM1kW9kQ9hUeceCwDgWFgq2OQeSPp4wTrrQAAAZ3lo5Ks0QljQhgKAwmVrT1n3iVCEBQBMSAiNcebuUNrwmbMAMDF+ROv11539Ylf5F08AAL8tXH+qvuY/8sgVZwFg+vzkvqdrPfm9mT1e5ckBAKPz604NWwSM1vMCAIxm8HM0wiI3R0QBwMz4kVPDFAS+bjHtD+YAAJzli+DvW3IY5EkAAMV715XGaUUBwHKEOb/+nT/+wudaAMBy+KG2D7/6R42XJ6srjQsAUCCf+y+/kocvdDfXGxIAoETpIysu/eWGhW4AWK6Lz83w6oILCwLAQl1UZaS1i5HGBAAo1JtrGV5dbMYbEgCgRF5lnF6e8EuX/xh5TACAQvUvGfIh/OxW0n/GHhAAoFhbSS/bUp4kzdijAQCU6eS6dvqM7kxjAgAUKhYTqSW1Fu0oAMBLW3UZ0eHMbgDAKUcnc6ejo7huFACgzzPCpK4lVUvaV1W1zzoqAEBxPBt2ZtZ8UNeb2uYdEgCgYK2k9QdJnyR9yzsWAEDBvkr6mFpSbdahAABKtpNXGGtJrF8AAF6zSudhtDlHAQAo2l4hMAAAOGcvaaV0fC0AAOeYmVFhAAAu8kHSPl7vHACAyDOi/aDUmwIA4BUEBgDgLbV0CAwAAM5ZSdp9kJ/Bl3kwAIBy1fI1jO+S/so7FgBAwT5J+pYqjDrvWAAABWvUZUV3QgYfoAQA6IsfspdO3NuKdQwAwEtrSbuqqvYpMP6W9K+MAwIAlOmzuozo+Id8P+cbDwCgRN6OavoPPr94EACwWP1iIl588N+iLQUAOPgs6b8vHjWzmrYUACBJR0el739WGFVVtZJaM9tkGBcAoCCeBbuqqk5fPsrMbqgyAAAXrWv7L21GGREAoDhePDxe8osbqgwAWC4ze7z4qFmqDABYJj+U9u3qIvwBaxkAsDB+3ahfPyfPzB7M7O4qowIAFMfM7szsy+/8Ye3H4NbDDwsAUBIzW79rzve0oTUFADPnC923+Z8EAFAsM7v9pYXuV56o9kUQPi8DAGbm3a2oE0+48dAY5gkBANmFguBm6Ce+N7OnQZ8UAJCNLzncX+vJnzjUFgCmz4uA969bvPIPpPKFRXAAmKiwzLB6+7ff9w9dp+cFALg6v5LHeOfYhVV1jpwCgIkIc3cz9j+8ITQAYBpCWGxyDWAzamkDAPhl4VJPm9wD4RwNAChUWHfe5B6LJNpTAFAib0OVExaJf+hGeQMDgAUKb+TLPKI1pNld7rEAwFKlK40Xv1QQ+mV3uccCAEszmbBIPDSe/FP7rnsmIQAgfbzqg8+9de7x/DK/Vsl0kg4AJih0dq5zIcGx+AdzcP0pALgCn2N/zGaODYvh97SoAGAYs+3ieH/tcbL9NQAoRGhBPcx6PqVFBQC/L1xdYxlzaDiK6nHW6QgAA/F582GWLahLeP9tPos1AHAFYWH7LvdYsvJLilBtAECPVxWPi60qzmFtAwAO/IxtqopzQpo+2tifCAUABVjMEVBDscNnznJpEQCL0FvU3uQez6T4eRvpIlp3BAeAuWKuG0hI3fwfLwgAAwrnVNB+GpIfTcX6BoDJC0HBlS+uieAAMFUhKFinGBPBAWAqCIpChBeC4ABQFIKiUP7CPBEcAHIjKCYitKo4RA3AaPxUgNjx2OQeEy4UguOHB0ede0wA5qd3wt2Dma1zjwm/yV/MdFVc2lUABuFvSh+sw3kUc+Ll4m1Y57ilXQXgV/XXJwiKmeu1q+6pOgC8JlQTqe3U5B4TRmaH61WldhWL5AAk/Wxnx2qCtVB0wjsI1jqABbPuatlfwtpEk3tMKFRY64hHWDW5xwXgesxsHVpOj15Z0G3A5bwkTZcdfiY8gPnwkLin5YTBecuK8AAm7ERI3HPeBK6qFx4caQUUrHeEEyGBfM6FB/1PIA9fh7wJIfFESKA4vuYRF8wf/fs699iAOfNWU9r3LCxc17nHBrzJDhciS4fqplKY6gMYwIlW04NXFuxfV1LlHsBS+BrHWtJnSbWkVtLfknZVVW1zjQuYit4+1Ejain1oVARGBv4OKG74taSd2PiBn3oBsVb3Jmurw36yzzW2pSIwCuABciPpkwgQLNSZgIj7QZtrbOgQGAXyAGkk/aVux1mr23F2kr5J2rLzYMr8iKVah228UVc97CR9VbeNU0EUhsCYgNDCWqvbwRr/0VZdgOzEDoZChe230SEgpMP2uxUtpkkgMCbKDxds1LWxUpjsddgJW1HGY2Qn3tzUOrRYU/XAdjlRBMaMnAkR6bidtZPU8m4O7+VrDisdt06l43Boq6raZRkgBkdgzJyHSOoXx0X1Vl018l2HxUWCBEe8Yqj9tla3DaX7O3XbTmortVQO80ZgLFCYBFKQfAz39+omgr1obS2GL0KndlLaHtJjMRjSGwuqhgUiMHDkREWyCt+3OoRJqkxa8c6yeP66xttH/5pe3/S67tS9tjtJe4IBEYGBi4UwWek4TFLF0uplhbIPj+9peQ0vhMEqfP0Uvq91/Lq0IhTwGwgMDKb3Lnalw7vY9H0tDw4dqhPpUK1IIVy0wIDxduGpWy3pD70MhpWO/1/uJP2jEA5UfxgKgYFRhQmx1vGk99F/JT6WbvverfXf3aubHJM23E+/27//wqUT6htXPk1jTeoz9//Q6UCIf9/q5X/zd/WqNXGQAkZGYKB4YaLuf43300QsvZy8+9+/9fhrzoVP+8pjMdjiY0eBRiWA0v0fPGR4m68wwtkAAAAASUVORK5CYII=";class $s extends ge.CSS2DObject{constructor(e,t){const i=document.createElement("div");super(i),this.props=e,this.amr=t,this._direction=1,this._controllingRotate=!1,this._controlling=!1,this._startAt=0,this._looper=0,this._initial=0,this._canRotate=!1,this._emitter=new pt,this.addListener=this._emitter.addListener.bind(this._emitter),this.removeListener=this._emitter.removeListener.bind(this._emitter),this._update=()=>{if(this._looper=requestAnimationFrame(this._update),this._controlling){let r=(Date.now()-this._startAt)/200;r>4&&(r=4);let l=this._initial+.005*r*this._direction;if(l>this.props.max||l<this.props.min){this.mechanism&&(l<this.props.min?(this.mechanism.position.setZ(this.props.min),this._emitter.emit("change",this.props.min)):l>this.props.max&&(this.mechanism.position.setZ(this.props.max),this._emitter.emit("change",this.props.max)));return}if(this._initial=l,!this.mechanism)return;this.mechanism.position.setZ(l),this._emitter.emit("change",l)}},i.setAttribute("data-ui-type","mechanism");const s=fs();e.userData&&e.userData.target&&(this.name=e.userData.target.name,t.traverse(r=>{r.name===e.userData.target.name&&(this.mechanism=r)})),i.style.fontSize="30px",i.style.color="#0066FF",i.style.cursor="pointer",i.style.pointerEvents="auto";const a=r=>{r.stopPropagation()},n=r=>{r.preventDefault(),r.stopPropagation()},c={capture:!1,passive:!0},h={capture:!1,passive:!1};["pointerdown","pointerup","pointermove","pointercancel","click","dblclick","contextmenu","mousemove"].forEach(r=>{i.addEventListener(r,a,c)}),["wheel","dragenter","dragover","dragleave","drop"].forEach(r=>{i.addEventListener(r,n,h)});const f=document.createElement("div");f.style.position="absolute",f.style.left="0",f.style.transform="translateX(-50%) rotate(-180deg)",f.style.marginBottom="5px",f.style.width=f.style.height=s?"34px":"44px",f.style.background=`url(${Js}) center no-repeat`,f.style.backgroundSize="100% auto",f.setAttribute("data-direction","up"),f.style.transition="all .2s";const p=document.createElement("div");if(p.style.position="absolute",p.style.left="0",p.style.transform="translateX(-50%)",f.style.bottom=p.style.top="8px",p.style.width=p.style.height=f.style.width,p.style.background=`url(${Js}) center no-repeat`,p.style.backgroundSize="100% auto",p.style.transition="all .2s",p.setAttribute("data-direction","down"),Array.from([f,p]).forEach(r=>{s||r.addEventListener("mousemove",()=>{r.style.filter="invert(100%)"}),r.addEventListener("mouseleave",()=>{r.style.filter=""}),r.addEventListener("pointerdown",()=>{this.mechanism&&(r.style.filter="invert(100%)",this._controlling=!0,this._startAt=Date.now(),this._initial=this.mechanism.position.z,this._direction=r.getAttribute("data-direction")==="up"?1:-1,this._update())}),r.addEventListener("pointerup",()=>{this._controlling=!1,cancelAnimationFrame(this._looper),r.style.filter=""}),r.addEventListener("pointerleave",()=>{this._controlling=!1,cancelAnimationFrame(this._looper),r.style.filter=""})}),e.userData&&(this._canRotate=e.userData.canRotate,this._canRotate)){const{rotateTarget:r,rotateDuration:l,rotateStep:u,rotateMax:g,rotateMin:y}=e.userData;let m;if(r&&(t.traverse(v=>{v.name===r.name&&(m=v)}),m)){const v=document.createElement("div");v.style.background=`url(${tl}) center no-repeat`,v.style.backgroundSize="100% auto",v.style.position="absolute",v.style.top="-50%",v.style.left="-50%",v.style.width=s?"140px":"160px",v.style.height=s?"70px":"80px",v.style.transform="translateX(-50%) translateY(-50%)",i.append(v);const _=document.createElement("div");_.style.background=`url(${el}) center no-repeat`,_.style.backgroundSize="100% auto",_.style.width=_.style.height=s?"20px":"26px",_.style.position="absolute",_.style.top="0",_.style.transform="translateY(-50%)",_.style.marginBottom="5px",_.setAttribute("data-direction","left"),i.append(_);const x=document.createElement("div");x.style.background=`url(${$a}) center no-repeat`,x.style.backgroundSize="100% auto",x.style.width=x.style.height=s?"20px":"26px",x.style.position="absolute",_.style.left=x.style.right=s?"62px":"69px",x.style.top="0",x.style.transform="translateY(-50%)",x.style.marginBottom="5px",x.setAttribute("data-direction","right"),i.append(x),Array.from([_,x]).forEach(w=>{s||w.addEventListener("mousemove",()=>{w.style.filter="invert(100%)"}),w.addEventListener("mouseleave",()=>{w.style.filter=""}),w.addEventListener("pointerdown",()=>{if(this._timer&&this._timer.isPlaying())return;w.style.filter="invert(100%)",this._controllingRotate=!0,this._startAt=Date.now(),this._direction=w.getAttribute("data-direction")==="left"?1:-1;let b=u/180*Math.PI*this._direction+m.rotation.z;b>g/180*Math.PI?b=g/180*Math.PI:b<y/180*Math.PI&&(b=y/180*Math.PI),this._timer=new ci(m.rotation).to({z:b}).duration(l).start(),this._update()}),w.addEventListener("pointerup",()=>{this._controllingRotate=!1,cancelAnimationFrame(this._looper),w.style.filter=""}),w.addEventListener("pointerleave",()=>{this._controllingRotate=!1,cancelAnimationFrame(this._looper),w.style.filter=""})})}}i.append(f,p),this.scale.set(.01,.01,.01),this.matrixAutoUpdate=!1,this.updateMatrix()}hide(){this.element.style.display="none",this.traverse(e=>{e.visible=!1,e instanceof ge.CSS2DObject&&(e.element.style.visibility="hidden")}),this.visible=!1}show(){this.element.style.display="auto",this.traverse(e=>{e.visible=!0,e instanceof ge.CSS2DObject&&(e.element.style.visibility="visible")}),this.visible=!0}dispose(){this._emitter.removeAllListeners(),cancelAnimationFrame(this._looper),this.element.remove()}}class il extends gn.CSS3DObject{constructor(e){const t=document.createElement("div");super(t),this.props=e,this._scale=.01,this._emitter=new pt,this.addEventListener=this._emitter.on.bind(this._emitter),this.removeEventListener=this._emitter.on.bind(this._emitter),this._mouseStart=new d.Vector2,this._targetSize=new d.Vector2,this._caches=[],this._sizeFlag="width",this._direction=1,this._lines=[],this._pointerdown=h=>{const{pageX:f,pageY:p}=h;this.endNode.setPointerCapture(h.pointerId),this._mouseStart.set(f,p),this._targetSize.setX(parseFloat(this.endNode.parentElement.style.width)),this._targetSize.setY(parseFloat(this.endNode.parentElement.style.height))},this._pointermove=h=>{if(!this._mouseStart.x)return;const{pageX:f,pageY:p}=h;let r=f-this._mouseStart.x,l=r+this._targetSize.x;this._sizeFlag==="height"&&(r=p-this._mouseStart.y,l=r*this._direction+this._targetSize.y);const u=l%10;l=l-u,r=(l-this._targetSize.x)*this._direction,this._sizeFlag==="height"&&(r=(l-this._targetSize.y)*this._direction),this._textNode.innerText=(l/100).toFixed(2)+" m",this.endNode.parentElement.style[this._sizeFlag]=`${l}px`},this._pointercancel=h=>{this.endNode.releasePointerCapture(h.pointerId),this._mouseStart.set(0,0)};const{start:i,end:s}=e,a=s.distanceTo(i);this.props.axios==="z"?this.props.axios="y":this.props.axios==="y"&&(this.props.axios="z"),this.props.axios==="y"&&(this._sizeFlag="height");const n=document.createElement("div");n.style.position="absolute",n.style.left="0",n.style.bottom="0",t.append(n),this._textNode=document.createElement("div"),this._textNode.innerText=a.toFixed(2)+" m",n.append(this._textNode);const c=document.createElement("div");this.endNode=c,c.style.position="absolute",c.style.left="auto",c.style.right="0",c.style.width="4px",c.style.height="4px",c.style.background="#0066FF",c.style.borderRadius="50%",c.style.margin="-2px -2px 0 0",c.style.cursor="pointer",n.append(c),this.scale.set(this._scale,this._scale,this._scale),t.style.fontSize="6px",t.style.color="#fff",n.style[this._sizeFlag]=a*100+"px",n.style.textAlign="center",this._sizeFlag==="height"?(n.style.borderLeft="0.1px dashed #fff",n.style.display="flex",n.style.alignItems="center",n.style.justifyContent="center",n.style.whiteSpace="nowrap",c.style.top="0",c.style.left="0",c.style.right="auto",c.style.margin="-2px 0 0 -2px"):n.style.borderBottom="0.1px dashed #fff",c.addEventListener("pointerdown",this._pointerdown),c.addEventListener("pointermove",this._pointermove),c.addEventListener("pointerup",this._pointercancel),s[this.props.axios]<i[this.props.axios]?this.rotateY(Math.PI):this._direction=-1}_getIndexByAxios(){return this.props.axios==="y"?1:this.props.axios==="z"?2:0}dispose(){this._lines.forEach(e=>e.dispose()),this._emitter.removeAllListeners(),this.endNode.removeEventListener("pointerdown",this._pointerdown),this.endNode.removeEventListener("pointermove",this._pointermove),this.endNode.removeEventListener("pointerup",this._pointercancel),this.element.remove(),this._caches.forEach(e=>e.clear()),this._caches=[]}}class sl extends d.Object3D{constructor(){super(),this._box3=new d.Box3,this._line11=new oi("长:"),this._line12=new oi("宽:"),this._line13=new oi("高:"),this._outline=new Ur(0,0),this._radius=0,this._hasWidthConfig=!1,this._hasLengthConfig=!1,this._hasHeightConfig=!1,this.follow="",this.followOrigin=0,this.followScale=1,this.originOffset=0,this.translateCache=0,this.head=0,this.tail=0,this._change=()=>{if(!this._app)return;const e=this._app.camera;e&&this._outline.change(e.position)},this.add(this._outline,this._line11,this._line12,this._line13)}get hasSizeConfig(){return{length:this._hasLengthConfig,width:this._hasWidthConfig,height:this._hasHeightConfig}}get size(){return this._box3.clone()}get radius(){return this._radius}init(e){this._app=e,this._app.controls.addEventListener("change",this._change)}reset(){this.hide(),this._line11.reset()}generate(e,t=0){e&&(this._object=e),this.update(t)}show(e=!0){const t=[this._line11,this._line12,this._line13];e&&(this.visible=!0,this._outline.visible=!0,this._outline.show(),t.push(this._outline)),t.forEach(i=>{i.traverse(s=>{s.visible=!0,s instanceof ge.CSS2DObject&&(s.element.style.visibility="visible")})})}hide(e=!0){const t=[this._line11,this._line12,this._line13];e&&(this.visible=!1,this._outline.visible=!1,this._outline.hide(),t.push(this._outline)),t.forEach(i=>{i.traverse(s=>{s.visible=!1,s instanceof ge.CSS2DObject&&(s.element.style.visibility="hidden")})})}destroy(){var e;(e=this._app)==null||e.controls.removeEventListener("change",this._change),this._line11.destroy(),this._line12.destroy(),this._line13.destroy()}update(e=0){if(!this._object)return;const t=this._object,{box:i,maxRadius:s,hasLength:a,hasHeight:n,hasWidth:c}=Wa(t);this.tail=Math.abs(i.min.x),this.head=Math.abs(i.max.x),this._hasWidthConfig=c,this._hasLengthConfig=a,this._hasHeightConfig=n,this._box3.copy(i),this._radius=s,this.follow&&e&&(this.originOffset=(this.followOrigin-e)*this.followScale),this._outline.update(this._radius),this._change();const h=this._box3.min.x,f=this._box3.max.x,p=this._box3.min.z,r=this._box3.max.z,l=this._box3.min.y,u=this._box3.max.y;let g=.2;const y=new d.Vector3(h,u,0),m=new d.Vector3(f,u,0);this._line11.update(y.clone().sub(new d.Vector3(0,-g/1.8,0)),m.clone().sub(new d.Vector3(0,-g/1.8,0)),this._radius);const v=new d.Vector3(f,l,0);this._line12.update(m.clone().add(new d.Vector3(g,0,0)),v.clone().add(new d.Vector3(g,0,0)),this._radius);const _=new d.Vector3(h,u,p),x=new d.Vector3(h,u,r),w=_.clone();w.y-=g/6;const b=x.clone();b.y-=g/6,this._line13.update(w,b,this._radius)}}class pe extends d.Mesh{constructor(e=.6,t=.4,i=.2){super(),this.isGoods=!0,this._lineMaterial=new d.LineDashedMaterial({color:new d.Color("#000"),dashSize:.015,gapSize:.015}),this._currentLength=.6,this._currentWidth=.4,this._currentHeight=.2,this.material=new d.MeshBasicMaterial({color:new d.Color("#0f5fd5"),transparent:!0,opacity:.4}),this._currentLength=e,this._currentWidth=t,this._currentHeight=i,this._generate(e,t,i)}updateSize(e=.1,t=.1,i=.1){this._currentLength=e,this._currentWidth=t,this._currentHeight=i,this._generate(e,t,i)}hide(){this.traverse(e=>e.visible=!1)}show(){this.traverse(e=>e.visible=!0)}dispose(){var t,i,s,a,n;(t=this.lineSegments)==null||t.removeFromParent(),(s=(i=this.lineSegments)==null?void 0:i.geometry)==null||s.dispose(),this.lineSegments=void 0,(a=this.geometry)==null||a.dispose();const e=this.material;Array.isArray(e)?e.forEach(c=>{var h;return(h=c==null?void 0:c.dispose)==null?void 0:h.call(c)}):(n=e==null?void 0:e.dispose)==null||n.call(e),this._lineMaterial.dispose(),this.clear()}clearAll(){this.dispose()}clone(e){return new pe(this._currentLength,this._currentWidth,this._currentHeight)}_generate(e,t,i){be(this),this.clear(),this.geometry.dispose(),this.geometry=new d.BoxGeometry(e,t,i),this.geometry.translate(0,0,i/2);const s=new d.EdgesGeometry(this.geometry);this.lineSegments=new d.LineSegments(s,this._lineMaterial),this.add(this.lineSegments),this.lineSegments.geometry.dispose(),this.lineSegments.geometry=s,this.lineSegments.computeLineDistances()}}const rl="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAALSURBVAiZY2AAAgAABQABYlUyiAAAAABJRU5ErkJggg==";class Yi{constructor(e){this._props=e,this.name="",this.transparentTexture=ds.load(rl),this._offscreen=new OffscreenCanvas(0,0),this._defaults={...e},this.target=e.target,this.parent=this.target.parent,this.reset()}get imageSize(){return this._props.imageSize}get size(){return this._props.size}get defaultConfigs(){return{canvasWidth:200,canvasHeight:200,scaleX:1,scaleY:1,x:0,y:0,ox:0,oy:0,url:this._defaults.imageUrl}}clear(){this.change()}change(e,t=new d.Vector2(1,1),i=new d.Vector2){this.imageUrl=e;let s;if(e){const a=new Image;a.crossOrigin="anonymous",a.src=e,a.onload=async()=>{var f;let n=window.devicePixelRatio*2;this._offscreen.width=a.width+n,this._offscreen.height=a.height+n;const c=this._offscreen.getContext("2d");c==null||c.clearRect(0,0,this._offscreen.width,this._offscreen.height),c==null||c.drawImage(a,n/2,n/2,a.width,a.height),s=new d.Texture(this._offscreen),s.minFilter=1003,s.colorSpace=d.SRGBColorSpace,s.wrapS=s.wrapT=d.ClampToEdgeWrapping,s.repeat.set(1/t.x,1/t.y),s.offset.set(i.x,i.y),s.flipY=!1,s.needsUpdate=!0;const h=this._props.target;h.material&&((f=h.material.map)==null||f.dispose(),s?(h.material.map=s,h.material.opacity=1):(h.material.map=this.transparentTexture,h.material.opacity=0))}}else{const a=this._props.target;a.material&&(a.material.map=this.transparentTexture)}}reset(){this._props=this._defaults,this.name=this._props.name,this.imageUrl=this._props.imageUrl,this.target=this._props.target,this.change(this.imageUrl||"")}dispose(){this._offscreen=null}}function Ri(o){return o.type?o.type==="Mesh":o.isMesh}const ds=new d.TextureLoader;ds.crossOrigin="anonymous";class Wr extends d.Object3D{constructor(e){super(),this._props=e,this._emitter=new pt,this.addEventListener=this._emitter.addListener.bind(this._emitter),this._container=new d.Group,this.lines=new d.Group,this._clips=[],this._actionsMap=new Map,this._animationClock=new d.Clock,this.sizeBox=new sl,this._goodsSize=new Ga(0,0,0),this._slots=[],this._logos=[],this._skins=[],this._levels=new Map,this._rollerLevel=new Map,this._liftBrackets=[],this._shelfSyncCache=new WeakMap,this._rollerPools=new WeakMap,this._videoCache=new Map,this._rollerColumns=1,this._bodyOpacity=1,this._masts=new Map,this._liftMaxHeight=0,this._jackMaxHeight=0,this._forkMaxHeight=0,this.controllers=[],this.goods=[],this._breathLights=[],this._shelves=new Map,this._shelfMaxLevel=1,this._url="",this._showController=!0,this._showSlots=!0,this._shapeKeys=new Map,this._shapeKeyTargets=new Map,this._shapeKeyTimer=0,this._shapeKeyCache="",this._materialsCache=new Map,this.opacityCache=void 0,this.actions=[],this._useCenterModel=!1,this._useLift=!1,this._columnCount=1,this._columnGap=.03,this._rowCount=1,this._rowGap=.01,this._levelCount=1,this._currentAction=null,this._pendingFinishedCallback=null,this._url=e.url||"",this._url&&this.load(this._url).then(),this.add(this._container,this.lines),this._props.showSizeBox&&this.add(this.sizeBox),this.showController=typeof e.showController=="boolean"?e.showController:!0,this._showSlots=typeof e.showSlots=="boolean"?e.showSlots:!0}get shapeKeys(){return this._shapeKeys}get size(){const e=this.sizeBox.size.getSize(new d.Vector3);return{width:e.z,length:e.x,height:e.y}}get goodsSize(){return this._goodsSize}get showController(){return this._showController}set showController(e){this._showController=e,this.controllers.forEach(t=>e?t.show():t.hide())}get slots(){return this._slots}get logos(){return this._logos}get skins(){return this._skins}get bodyOpacity(){return this._bodyOpacity}get fork(){return this._fork}get forkHeight(){var e;return((e=this._fork)==null?void 0:e.position.z)||0}get liftHeight(){var e;return this._lift?this._lift instanceof Map?((e=this._lift.get(0))==null?void 0:e.position.z)||0:this._lift.position.z||0:0}get jack(){return this._jack}get jackHeight(){var e;return((e=this._jack)==null?void 0:e.position.z)||0}get lift(){return this._lift}get useCenterModel(){return this._useCenterModel}set useCenterModel(e){this._useCenterModel=e,this._rollerLevel.forEach(t=>{t.traverse(i=>{i.userData.isCenterModel&&(i.visible=e)})})}set bodyOpacity(e){this._bodyOpacity=e,e<1?this._materialsCache.forEach(t=>{t.mat.transparent=!0,t.mat.opacity=e,t.mat.metalness=0,t.mat.roughness=1,t.mat.color=new d.Color("#3859be"),t.mat.needsUpdate=!0}):this._materialsCache.forEach(t=>{t.mat.transparent=t.transparent,t.mat.opacity=t.opacity,t.mat.metalness=t.metalness,t.mat.roughness=t.roughness,t.mat.color=t.color,t.mat.needsUpdate=!0})}init(e){this._app=e,this.sizeBox.init(e),this._onTicker&&this._app.renderer.domElement.removeEventListener("ticker",this._onTicker),this._onTicker=()=>{if(this._mixer){const t=this._animationClock.getDelta();this._mixer.update(t)}else this._animationClock.getDelta()},this._app.renderer.domElement.addEventListener("ticker",this._onTicker),this.addEventListener("shape-key-changed",(t,i)=>{if(this._slots.forEach(s=>s.shapeKeyChanged(t,i)),this.sizeBox.follow===t?(this.sizeBox.generate(this._container,i),this.sizeBox.originOffset&&(this._container.traverse(s=>{s instanceof d.Mesh&&!s.userData.isDevice&&!s.userData.isBracket&&s.geometry.translate(this.sizeBox.originOffset-this.sizeBox.translateCache,0,0),s instanceof Qi&&!s.props.slot.userData.ignoreOriginChanged&&s.parent&&s.parent.position.add(new d.Vector3(this.sizeBox.originOffset-this.sizeBox.translateCache,0,0))}),this.sizeBox.translateCache=this.sizeBox.originOffset,this.sizeBox.generate(this._container))):this.sizeBox.generate(this._container),["width","length","height"].includes(t)&&this._emitter.emit("size-changed",t,i),t==="goodsLength"){const s=this._goodsSize.length,a=this._getLayoutGoodsLength(s),n=i;this._goodsSize.length=this._layoutLengthToItemLength(n),this._applyDerivedSizesFromLayoutGoodsLength(n),this._generateRollers(),this._syncRollerGoodsBoxesFromGoodsSize(),this._syncShelvesFromGoodsSize({prevLayoutLengthForBaseX:a})}t==="goodsWidth"&&(this._goodsSize.width=i,this._applyDerivedSizesFromGoodsWidth(i),this._columnCount>1&&this.setColumns(this._columnCount,!1),this._syncRollerGoodsBoxesFromGoodsSize(),this._syncShelvesFromGoodsSize())})}_syncRollerGoodsBoxesFromGoodsSize(){const e=h=>{var r;const f=[],p=[...h.children];for(;p.length;){const l=p.pop();if((r=l.userData)!=null&&r.isRollerLevelBox){f.push(l);continue}l.children&&l.children.length&&p.push(...l.children)}return f},t=Math.max(1,this._rowCount||1),i=t>1?this._rowGap:0,s=this._goodsSize.length||0,a=this._getLayoutGoodsLength(s),n=s+i,c=t>0?-a/2+s/2:0;this._rollerLevel.forEach(h=>{e(h).forEach(p=>{const r=p.children.filter(l=>l instanceof pe);for(r.forEach(l=>{l.userData.__amrRollerGoodsBox=!0,this.goods.includes(l)||this.goods.push(l)});r.length<t;){const l=new pe(this._goodsSize.width,this._goodsSize.length,this._goodsSize.height);l.userData.__amrRollerGoodsBox=!0,p.add(l),this.goods.push(l),r.push(l)}for(let l=t;l<r.length;l++){const u=r[l];this.goods=this.goods.filter(g=>g!==u),u.dispose(),u.removeFromParent()}for(let l=0;l<t;l++){const u=r[l];u.updateSize(this._goodsSize.width,this._goodsSize.length,this._goodsSize.height),u.position.y=c+n*l}})})}_syncShelvesFromGoodsSize(e){const t=this.shapeKeys.has("goodsLength")||this.shapeKeys.has("goodsWidth"),i=this._getLayoutGoodsLength(this._goodsSize.length);this._shelves.forEach(s=>{let a=this._shelfSyncCache.get(s);a||(a={container:void 0,morphMeshes:[],goodsBoxes:[]},s.traverse(h=>{var f;if((f=h.userData)!=null&&f.isShelfContainer&&(a.container=h),h instanceof pe&&a.goodsBoxes.push(h),Ri(h)){const p=h,r=p.morphTargetDictionary||{};(Object.prototype.hasOwnProperty.call(r,"goodsWidth")||Object.prototype.hasOwnProperty.call(r,"goodsLength"))&&a.morphMeshes.push(p)}}),this._shelfSyncCache.set(s,a)),a.goodsBoxes.forEach(h=>{h.updateSize(this._goodsSize.length,this._goodsSize.width,this._goodsSize.height)}),a.morphMeshes.forEach(h=>{this.setShapeKeyToMesh(h,"goodsWidth",this._goodsSize.width),this.setShapeKeyToMesh(h,"goodsLength",i)});const n=a.container;if(!n)return;if(typeof n.userData.__goodsBaseX!="number")if(t){const h=typeof(e==null?void 0:e.prevLayoutLengthForBaseX)=="number"?e.prevLayoutLengthForBaseX:i;n.userData.__goodsBaseX=n.position.x-(h||0)/2}else n.userData.__goodsBaseX=n.position.x;const c=n.userData.__goodsBaseX;n.position.x=t?c+i/2:c})}_findFirstSkinnedMesh(e){if(!e)return;let t;return e.traverse(i=>{!t&&i.isSkinnedMesh&&(t=i)}),t}async loadAnimation(e,t="sglb"){let i,s;if(t==="glb"||e.endsWith(".glb")){const h=await We.loadAsync(e);i=h.animations||[],s=h.scene}else if(t==="sglb"||e.endsWith(".sglb")){const f=await new Et({useCache:!0}).loadAsync(e);i=f.animations||[],s=f.scene}else{console.warn("[Amr.loadAnimation] 目前仅支持 glb/sglb 动画文件",{url:e,type:t});return}if(!i||i.length===0){console.warn("[Amr.loadAnimation] 文件中未找到动画",e);return}if(!this._modelRoot){console.warn("[Amr.loadAnimation] 模型尚未加载,无法绑定动画",e);return}if(!s){console.warn("[Amr.loadAnimation] 动画文件中缺少 scene,无法执行重定向",e);return}const a=this._findFirstSkinnedMesh(s),n=this._findFirstSkinnedMesh(this._modelRoot);(!a||!n)&&console.warn("[Amr.loadAnimation] 在动画或目标模型中未找到 SkinnedMesh,使用原始动画 clip",e),this._mixer||(this._mixer=new d.AnimationMixer(this._modelRoot));const c=typeof _i.retargetClip=="function";i.forEach(h=>{let f=h;if(c&&a&&n)try{f=_i.retargetClip(n,a,h)}catch(r){console.warn("[Amr.loadAnimation] 重定向动画失败,回退到原始 clip",h.name,r)}this._clips=this._clips.filter(r=>r.name!==f.name),this._clips.push(f);const p=this._mixer.clipAction(f);this._actionsMap.set(f.name,p)}),this.actions=Array.from(this._actionsMap.keys())}async load(e,t=""){this._url=e,this.name||(this.name=e.substring(e.lastIndexOf("/")+1,e.lastIndexOf("."))),!e.startsWith("blob")&&e.endsWith(".sglb");let i,s;if(t==="glb"||e.endsWith(".glb")){let n=await We.loadAsync(e);i=n.scene,s=n.animations||[]}else{const c=await new Et({useCache:!0}).loadAsync(e);if(!c.glb)return;i=c.glb}const a=_i.clone(i);this._generateAmr(a,s),i=null,this._emitter.emit("amr-loaded")}changeSkin(e,t){e&&(e.change(t),this._app&&this._app.usePathTracing&&(this._app.sampleCount=0,this._app.usePathTracing&&(this._app.pathTracer.pausePathTracing=!1,this._app.pathTracer.updateMaterials())))}changeLogo(e,t){e.change(t.url,new d.Vector2(t.scaleX,t.scaleY),new d.Vector2(t.ox,t.oy))}getShapeKeyTargets(e){return this._shapeKeyTargets.get(e)||[]}setShapeKey(e,t,i=!0){i&&this._shapeKeyTimer&&e===this._shapeKeyCache&&clearTimeout(this._shapeKeyTimer),this._shapeKeyCache=e,this._shapeKeyTimer=window.setTimeout(()=>{this.getShapeKeyTargets(e).forEach(a=>{var h;performance.now();let n=t;a.userData[`origin_${e}`]&&(n-=a.userData[`origin_${e}`]);const c=(h=a.morphTargetDictionary)==null?void 0:h[e];c!==void 0&&a.morphTargetInfluences&&(a.morphTargetInfluences[c]=n),a instanceof d.Mesh&&a.geometry.translate(0,0,1e-9)}),i&&this._emitter.emit("shape-key-changed",e,t)},0)}_generateAmr(e,t){this._modelRoot=e,this._actionsMap.clear(),this.actions=[],this._clips=[],t&&t.length&&(this._mixer=new d.AnimationMixer(e),this._clips=t,t.forEach(i=>{const s=this._mixer.clipAction(i);this._actionsMap.set(i.name,s)}),this.actions=t.map(i=>i.name)),this._shapeKeyTargets.clear(),this._shapeKeys.clear(),e.traverse(i=>{if(i.userData.isShelf&&(this._shelf=i),i.userData.isFork&&(this._fork=i),i.userData.isMast&&i.userData.mastLevel&&this._masts.set(i.userData.mastLevel,i),i.userData.isJack&&(this._jack=i),i.userData.isLift&&(this._lift=i),i.userData.isRollerLevel&&this._rollerLevel.set(i.userData.level||0,i),i.userData.isCenterModel&&(i.visible=this.useCenterModel),i.userData.isSwitch&&i.userData.switchName==="top"&&(this._rollerTop=i),i.userData.isLiftBracket&&(this._liftBrackets.push(i),i.visible=this._useLift),i.userData.isBaffle&&(this._rollerBaffle=i,i.visible=!this._useLift),i.userData.isRoller&&(this._roller=i,this._roller.visible=!1,this._generateRollers()),i.userData.isRollerLevelBox){this._rollerGoodsBox=i;const s=new pe(this._goodsSize.width,this._goodsSize.length,this._goodsSize.height);i.add(s),this.goods.push(s)}Object.keys(i.morphTargetDictionary||{}).forEach(s=>{let a=i.morphTargetInfluences[i.morphTargetDictionary[s]];i.userData[`origin_${s}`]&&(a+=i.userData[`origin_${s}`]),this._shapeKeys.has(s)||this._shapeKeys.set(s,a);const n=this._shapeKeyTargets.get(s);n?n.push(i):this._shapeKeyTargets.set(s,[i])})}),e.traverse(i=>{if(i instanceof d.Mesh){if(i.castShadow=!0,i.receiveShadow=!0,i.material)if(Array.isArray(i.material))i.material.forEach(a=>{a.userData.changeColor&&(this.skins.find(n=>n.name===a.userData.name)||this.skins.push(new rs({name:a.userData.name,target:a})))});else{if(i.material.userData.isVideo&&i.material.userData.video){const a=i.material.userData.video;let n=this._videoCache.get(a);n||(n=document.createElement("video"),n.src=a,n.crossOrigin="anonymous",n.loop=!0,n.muted=!0,n.playsInline=!0,n.autoplay=!0,n.preload="auto",this._videoCache.set(a,n)),n.play().catch(()=>{}),i.material.map&&i.material.map.dispose(),i.material.emissiveMap&&i.material.emissiveMap.dispose();const c=new d.VideoTexture(n);c.colorSpace=d.SRGBColorSpace,i.material.map=c,i.material.emissiveMap=c,i.material.emissive||(i.material.emissive=new d.Color(16777215)),i.material.emissiveIntensity=1,i.material.needsUpdate=!0}if(i.material.userData.isBreathLight&&i.material.emissiveIntensity){i.material.emissive||(i.material.emissive=new d.Color(16777215)),i.material.emissiveIntensity=2,i.material.toneMapped=!1;const a=1e3,n=new Pe.Tween(i.material).to({emissiveIntensity:.2}).easing(Pe.Easing.Quintic.InOut).duration(a),c=new Pe.Tween(i.material).to({emissiveIntensity:2}).easing(Pe.Easing.Quintic.InOut).duration(a);n.onComplete(()=>c.start()),c.onComplete(()=>n.start()),n.start(),this._breathLights.push(n,c)}i.material.userData.changeColor&&(this.skins.find(a=>a.name===i.material.userData.name)||this.skins.push(new rs({name:i.material.userData.name,target:i.material})))}if(i.material)if(Array.isArray(i.material))i.material.forEach(n=>{if(n.userData.isLOGO){i.material.transparent=!0;let c;const h={width:0,height:0};i.material.map&&i.material.map.image&&(h.width=i.material.map.image.width,h.height=i.material.map.image.height,c=ji(i.material.map.image)),i.material.needsUpdate=!0;const f=new Yi({name:n.userData.name,target:i,size:Ys(i),imageSize:h,imageUrl:c});this._logos.push(f)}n.userData.isTransparent&&(n.transparent=!0),this._materialsCache.set(n.uuid,{opacity:n.opacity,transparent:n.transparent,roughness:n.roughness,metalness:n.metalness,color:n.color,mat:n})});else{const a=i.material;if(a.userData.isLOGO){i.material.transparent=!0;let n;const c={width:0,height:0};i.material.map&&i.material.map.image&&(c.width=i.material.map.image.width,c.height=i.material.map.image.height,n=ji(i.material.map.image));const h=new Yi({name:a.userData.name,target:i,size:Ys(i),imageSize:c,imageUrl:n});this._logos.push(h)}a.userData.isTransparent&&(a.transparent=!0),this._materialsCache.set(a.uuid,{opacity:a.opacity,transparent:a.transparent,roughness:a.roughness,metalness:a.metalness,color:a.color,mat:a})}}this.generateController(i,e),this.generateDimension(i,e);const s=this.generateSlot(i,e);s&&this._slots.push(s),i.userData.isOrigin&&Object.keys(i.userData).forEach(n=>{if(n.startsWith("follow_")){const c=n.replace("follow_","");this.shapeKeys.has(c)&&(this.sizeBox.follow=c,this.sizeBox.followOrigin=this._shapeKeys.get(c)||0,this.sizeBox.followScale=i.userData[n])}})}),this.slots.forEach(i=>{i.props.mirrorTarget&&(i.mirrorTarget=this.slots.find(s=>s.props.slot.name===i.props.mirrorTarget))}),e.updateMatrixWorld(!0),this._container.add(e),this.sizeBox.generate(e),this.sizeBox.show()}setHeight(e){this.setShapeKey("height",e)}setWeight(e){this.setShapeKey("width",e)}setLength(e){this.setShapeKey("length",e)}limitValue(e){this.name==="SFL-CDD14"&&(e>1.6?this.setShapeKey("mast",1):this.setShapeKey("mast",0)),["SFL-CDD20","SFL-CDD20-Y"].includes(this.name)&&(e>1.6?this.setShapeKey("mast",1):this.setShapeKey("mast",0)),this.name==="SFL-CDD15"&&(e>2.43?this.setShapeKey("mast",1):this.setShapeKey("mast",0)),["SFL-CPD20-Y","SFL-CPD30-Y"].includes(this.name)&&(e>3.5?this.setShapeKey("mast",2):e>3?this.setShapeKey("mast",1):this.setShapeKey("mast",0))}setForkHeight(e){if(this._fork){if(e>this._forkMaxHeight&&(e=this._forkMaxHeight),this._fork.position.z=e,this._masts.size===1){const t=this._masts.get(2),i=(t==null?void 0:t.userData.startHeight)||.1;t&&(t.position.z=(e-i)*.5)}this._emitter.emit("fork-height-change",e)}}setForkMaxHeight(e){this._fork&&(this._forkMaxHeight=e,this.limitValue(e),this.controllers.forEach(t=>{t.name.toLowerCase().includes("fork")&&(t.props.max=e)}),this._fork&&this.forkHeight>this._forkMaxHeight&&this.setForkHeight(e))}setLiftHeight(e){if(this._lift)if(e>this._liftMaxHeight&&(e=this._liftMaxHeight),this._lift instanceof Map){const t=this._lift.get(0);t&&(t.position.z=e)}else this._lift&&(this._lift.position.z=e)}getLiftMaxHeight(){return this._liftMaxHeight}setLiftMaxHeight(e){if(!this._lift)return;this._liftMaxHeight=e,this.limitValue(e),this.controllers.forEach(a=>{a.name.toLowerCase().includes("lift")&&(a.props.max=e)}),this.liftHeight>this._liftMaxHeight&&this.setLiftHeight(e);let t=.46;this.levelOffset&&(t=this.levelOffset+.1);let i=e+t;const s=this.getShelfMinHeight()+t||0;i<s&&(i=s),this.setHeight(i)}setJackMaxHeight(e){this._jack&&(this._jackMaxHeight=e,this.limitValue(e),this.controllers.forEach(t=>{t.name.toLowerCase().includes("jack")&&(t.props.max=e)}),this.jackHeight>this._jackMaxHeight&&this.setJackHeight(e))}setJackHeight(e){this._jack&&(e>this._jackMaxHeight&&(e=this._jackMaxHeight),requestAnimationFrame(()=>{this.setShapeKey("jackHeight",e,!1)}),this._jack.position.z=e)}setLevel(e){}setGoodsSize(e){this._goodsSize.length=e.length,this._goodsSize.width=e.width,this._goodsSize.height=e.height,this.setShelfLevel(this._shelfMaxLevel),this.setRoller(),this._rollerLevel.forEach(t=>{t.traverse(i=>{i instanceof pe&&i.updateSize(e.width,e.length,e.height)})})}setRoller(){}get isTopInvert(){if(this._rollerTop)return Math.abs(this._rollerTop.rotation.z)===Math.PI/2}setTopInvert(e=!0){this._rollerTop&&(this._rollerTop.rotation.z=e?Math.PI/2:0,this.setShapeKey("switch",e?1:0),this.setShapeKey("goodsWidth",this.goodsSize.width),this.setShapeKey("goodsLength",this._getLayoutGoodsLength(this.goodsSize.length)))}get useLift(){return this._useLift}set useLift(e){var t;this._lift&&(this._useLift=e,(t=this._rollerTop)==null||t.traverse(i=>{i.userData.isBaffle&&(i.visible=!e),i.userData.isLiftBracket&&(i.visible=e)}))}get columns(){return this._columnCount}get rows(){return this._rowCount}setRows(e){const t=Math.max(1,Math.floor(e||1));if(t===this._rowCount)return;const i=this._getLayoutGoodsLength(this._goodsSize.length);this._rowCount=t;const s=this._getLayoutGoodsLength(this._goodsSize.length);this.setShapeKey("goodsLength",s,!1),this._applyDerivedSizesFromLayoutGoodsLength(s),this._generateRollers(),this._syncRollerGoodsBoxesFromGoodsSize(),this._syncShelvesFromGoodsSize({prevLayoutLengthForBaseX:i})}_getLayoutGoodsLength(e=this._goodsSize.length){const t=Math.max(1,this._rowCount||1),i=e||0;return t<=1?i:i*t+this._rowGap*(t-1)}_layoutLengthToItemLength(e){const t=Math.max(1,this._rowCount||1);if(t<=1)return Math.max(0,e||0);const i=this._rowGap*(t-1);return Math.max(0,((e||0)-i)/t)}setGoodsItemLength(e){this._goodsSize.length=e;const t=this._getLayoutGoodsLength(e);this.setShapeKey("goodsLength",t)}_applyDerivedSizesFromLayoutGoodsLength(e){const t=e+.14-.54;this.setShapeKey("boxLength",t);const i=e+.14;if(this.setShapeKey("topWidth",i),this.isTopInvert){const s=e-.259;this.setShapeKey("length",s)}else this.setShapeKey("width",i)}_applyDerivedSizesFromGoodsLength(e){const t=this._getLayoutGoodsLength(e);this._applyDerivedSizesFromLayoutGoodsLength(t)}_applyDerivedSizesFromGoodsWidth(e){const t=Math.max(1,this._columnCount||1),i=.125,s=t===1?e+i:(e+i)*t+this._columnGap*(t-1),a=s+.06;this.setShapeKey("boxWidth",a);const n=s+.085;if(this.setShapeKey("topLength",n),this.isTopInvert){const c=s+.485;this.setShapeKey("width",c)}else this.setShapeKey("length",n)}setColumns(e,t=!0){const i=Math.max(1,Math.floor(e||1));this._columnCount=i,this._rollerLevel.forEach(s=>{const a=s.children.filter(u=>{var g;return(g=u.userData)==null?void 0:g.isRollerLevelBox}),n=a.length>0?(Math.min(...a.map(u=>u.position.x))+Math.max(...a.map(u=>u.position.x)))/2:0;s.children.filter(u=>{var g,y;return((g=u.userData)==null?void 0:g.isRollerLevelBox)&&((y=u.userData)==null?void 0:y.cloned)}).forEach(u=>s.remove(u));const c=s.children.find(u=>u.userData.isRollerLevelBox&&!u.userData.cloned)||s.children.find(u=>u.userData.isRollerLevelBox);if(!c)return;const h=za(c,s,new d.Vector3),f=this._columnGap,r=h.x+f,l=(i-1)*r/2;c.position.x=n-l;for(let u=1;u<i;u++){const g=c.clone(!0);g.userData.cloned=!0,this._stripRollerInstances(g),this.regenerateShapeKeyNode(g),g.position.x=n-l+u*r,s.add(g)}}),t&&this._applyDerivedSizesFromGoodsWidth(this.goodsSize.width),this._pruneShapeKeyTargets(),this.setShapeKey("goodsWidth",this._goodsSize.width,!1),this.setShapeKey("goodsLength",this._getLayoutGoodsLength(this._goodsSize.length),!1),this._generateRollers(),this._syncRollerGoodsBoxesFromGoodsSize()}get levels(){return this._levelCount}setLevels(e){var n;const t=Math.max(1,Math.floor(e||1));this._levelCount=t;const i=this._rollerLevel.size,s=t-i,a=this._rollerLevel.get(0);if(s>0&&a){for(let h=i;h<t;h++){const f=a.clone(!0);f.visible=!0,this._stripRollerInstances(f),f.position.z=a.position.z+.2*h,f.userData.level=h,this._rollerLevel.set(h,f),(n=a.parent)==null||n.add(f),this.regenerateShapeKeyNode(f),f.traverse(p=>{p instanceof pe&&(p.updateSize(this.goodsSize.width,this.goodsSize.length,this.goodsSize.height),this.goods.push(p))})}this._columnCount>1&&this.setColumns(this._columnCount,!1),this._generateRollers()}else for(let c=0;c<i;c++){const h=this._rollerLevel.get(c);h&&(h.visible=c<t)}}regenerateShapeKeyNode(e){e&&e.traverse(t=>{Ri(t)&&Object.keys(t.morphTargetDictionary||{}).forEach(i=>{const s=this._shapeKeyTargets.get(i);s&&s.push(t)})})}_stripRollerInstances(e){const t=[];e.traverse(i=>{var s,a;((s=i==null?void 0:i.userData)!=null&&s.__amrRollerInstance||(a=i==null?void 0:i.userData)!=null&&a.isCloned)&&t.push(i)}),t.forEach(i=>{i.parent&&i.removeFromParent()})}_isInAmrContainer(e){let t=e;for(;t;){if(t===this._container||t===this)return!0;t=t.parent}return!1}_pruneShapeKeyTargets(){this._shapeKeyTargets.forEach((e,t)=>{const i=new Set,s=[];for(const a of e)a&&this._isInAmrContainer(a)&&(i.has(a.uuid)||(i.add(a.uuid),s.push(a)));this._shapeKeyTargets.set(t,s)})}setRollerHeight(e,t){const i=this._rollerLevel.get(e);i&&(i.position.z=t)}_generateRollers(){if(!this._roller)return;let e=this._getLayoutGoodsLength(this._goodsSize.length);e=e||.5;const t=.05;let i=.02;const a=e-i,n=t+i;let c=Math.floor(a/n);const h=a%n,f=l=>{var y;const u=[],g=[...l.children];for(;g.length;){const m=g.pop();if((y=m.userData)!=null&&y.isRollerLevelBox){u.push(m);continue}m.children&&m.children.length&&g.push(...m.children)}return u},p=[];this._rollerLevel.forEach(l=>{p.push(...f(l))});let r=!1;if(p.forEach(l=>{const u=[];l.traverse(g=>{var y,m;g!==l&&((y=g==null?void 0:g.userData)!=null&&y.isCloned)&&!((m=g==null?void 0:g.userData)!=null&&m.__amrRollerInstance)&&u.push(g)}),u.forEach(g=>g.removeFromParent()),u.length&&(r=!0)}),r&&this._pruneShapeKeyTargets(),c>0){c>1&&(i+=h/(c+2));const l=t+i,u=-e/2+i+t/2;p.forEach(g=>{let y=this._rollerPools.get(g);for(y||(y=[],this._rollerPools.set(g,y));y.length<c;){const m=this._roller.clone(!0);m.visible=!1,m.userData.__amrRollerInstance=!0,m.userData.isCloned=!0,g.add(m),this.regenerateShapeKeyNode(m),y.push(m)}for(let m=0;m<c;m++){const v=y[m];v.parent!==g&&g.add(v),v.visible=!0,v.position.y=u+l*m}for(let m=c;m<y.length;m++)y[m].visible=!1})}else p.forEach(l=>{const u=this._rollerPools.get(l);u&&u.forEach(g=>g.visible=!1)})}getShelfMinHeight(){const e=this.levelOffset,t=this._shelfMaxLevel,i=this._shelves.get(0);return i?i.position.z+e*t+.1:0}getShelfMaxShelfHeight(){const e=this.levelOffset,t=this._shelfMaxLevel,i=this._shelves.get(0);if(i)return i.position.z+e*(t-1)}get levelOffset(){return this._goodsSize.height+.2}setShapeKeyToMesh(e,t,i){if(!Object.keys(e.morphTargetDictionary||{}).includes(t))return;const s=e.morphTargetDictionary[t];e.morphTargetInfluences&&(e.morphTargetInfluences[s]=i),e.geometry.translate(0,0,1e-9)}setShelfLevel(e=3){var a;if(!this._shelf)return;this._shelfMaxLevel=e;const t=this.levelOffset,i=this._getLayoutGoodsLength(this._goodsSize.length);this._shelves.delete(0),this._shelves.forEach(n=>{be(n),n.parent&&n.removeFromParent()}),this.goods=this.goods.filter(n=>{var c;return(c=n==null?void 0:n.userData)==null?void 0:c.__amrRollerGoodsBox}),this._shelves.clear(),this._shelves.set(0,this._shelf);for(let n=1;n<e;n++){if(!this._shelf)return;this._shelf.traverse(f=>{Ri(f)&&(this.setShapeKeyToMesh(f,"goodsWidth",this._goodsSize.width),this.setShapeKeyToMesh(f,"goodsLength",i))});const c=this._shelf.clone(!0);c.position.z+=t*n,this._shelves.set(n,c),(a=this._shelf.parent)==null||a.add(c);let h;if(c.traverse(f=>{f.userData.isShelfContainer&&(h=f)}),(this.shapeKeys.has("goodsLength")||this.shapeKeys.has("goodsWidth"))&&h&&(typeof h.userData.__goodsBaseX!="number"&&(h.userData.__goodsBaseX=h.position.x),h.position.x=h.userData.__goodsBaseX+i/2),h){const f=new pe(this._goodsSize.length,this._goodsSize.width,this._goodsSize.height);if(f.userData.__amrShelfGoodsBox=!0,h.add(f),this.goods.push(f),n===1){const p=new pe(this._goodsSize.length,this._goodsSize.width,this._goodsSize.height);p.userData.__amrShelfGoodsBox=!0,p.position.z-=t,h.add(p),this.goods.push(p)}}}const s=this.getShelfMinHeight()||0;this._liftMaxHeight<s&&this.setLiftMaxHeight(s)}generateOuterLine(){this.traverse(e=>{if(e.userData.isOuterObject){const t=this.sizeBox.radius;this._outline?this._outline.update(t):(this._outline=new Ur(t,0),this.add(this._outline))}})}generateController(e,t){if(this.showController){if(e.userData.isForkController&&e.userData.target){const i=e.userData.target.name,{min:s,max:a}=e.userData;let n;if(t.traverse(h=>{h.name===i&&(n=h)}),!n)return;const c=new $s({name:"",target:i,default:0,min:s,max:a},n);e.add(c)}else if(e.userData.isController&&e.userData.target){const i=e.userData.target.name,{min:s,max:a}=e.userData;let n;if(t.traverse(h=>{h.name===i&&(n=h)}),!n)return;const c=new $s({name:"",userData:e.userData,target:e.userData.key,default:0,min:s||0,max:a||1},n);e.add(c),this.controllers.push(c),(n.userData.isFork||n.userData.isLift||n.userData.isJack)&&(this._forkMaxHeight=a||1,this._liftMaxHeight=a||1,this._jackMaxHeight=a||1,c.addListener("change",h=>{this.setForkHeight(h),this.setLiftHeight(h),this.setJackHeight(h)}))}}}generateDimension(e,t){if(e.userData.isDimension){const i=e.userData.divider,s=Va(e.userData.startOrigin),a=e.userData.axios;let n,c;if(a==="x"?(n=new d.Vector3(e.userData.start-e.position.x,0,0),c=n.clone().setX(e.userData.end-e.position.x)):a==="z"?(n=new d.Vector3(0,e.userData.start-e.position.y,0),c=n.clone().setY(e.userData.end-e.position.y)):(n=new d.Vector3(0,0,e.userData.start-e.position.z),c=n.clone().setZ(e.userData.end-e.position.z)),!Object.keys(e.userData).flatMap(r=>r.startsWith("target")?e.userData[r].name:[]).length)return;const p=new il({start:n,end:c,startOrigin:s,axios:a,divider:i});e.add(p)}}generateSlot(e,t){var i,s;if(e.userData.isSlot){const a=e.userData.name,n=e.userData.isMirror,c=(i=e.userData.mirrorSlot)==null?void 0:i.name;if(a){const h=e.userData.holeTarget&&e.userData.holeTarget.name;let f;h&&t.traverse(u=>{u.name===h&&(f=u)});const p=new Map;Object.keys(e.userData).forEach(u=>{if(u.startsWith("follow_")){const g=u.split("_")[1];if(g){let y=e.userData[u];p.set(g,{scale:y,initPos:e.position.clone(),origin:this.shapeKeys.get(g)||0})}}});const r=(s=this._app)==null?void 0:s.props.isMobile,l=new Qi({name:a,follows:p,slot:e,show:this._showSlots,isMirror:n,mirrorTarget:c,isMobile:r});return l.holeTarget=f,l.addEventListener(X.ON_DROP,u=>{this._app&&this._app.props.useSound&&this._app.sound.play()}),l.addEventListener(X.ON_BEFORE_SELECTED,u=>{this._slots.forEach(g=>{g.selected&&(g.selected=!1)})}),l.addEventListener(X.ON_ERROR_STATE_CHANGE,u=>{var y;if(!this._app)return;const g=(y=this._app)==null?void 0:y._outlinePassError;if(g)if(g.selectedObjects=g.selectedObjects.filter(m=>!!m.parent),u){if(l.device){if(g.selectedObjects.find(v=>{var _;return v.parent===((_=l.device)==null?void 0:_.parent)}))return;g.selectedObjects=[l.device,...g.selectedObjects]}}else l.device&&(g.selectedObjects=g.selectedObjects.filter(m=>{var v;return m.parent!==((v=l.device)==null?void 0:v.parent)}))}),l}}}clean(){this._emitter.removeAllListeners(),this.controllers.forEach(e=>e.dispose()),this.controllers=[],this._levels.forEach(e=>e.destroy()),this._levels.clear(),this._rollerLevel.clear(),be(this._container),this._slots=[],this._logos=[],this._skins=[],this._materialsCache.clear(),this.opacityCache=void 0,this._breathLights.forEach(e=>e.stop()),this._breathLights=[],this.sizeBox.reset(),this._shapeKeyTargets.clear(),this._shapeKeys.clear(),this._shelfSyncCache=new WeakMap,this._rollerPools=new WeakMap,this._shapeKeyTimer&&(clearTimeout(this._shapeKeyTimer),this._shapeKeyTimer=0),this._currentAction=null,this._pendingFinishedCallback&&this._mixer&&(this._mixer.removeEventListener("finished",this._pendingFinishedCallback),this._pendingFinishedCallback=null),this._mixer&&(this._mixer.stopAllAction(),this._modelRoot&&this._mixer.uncacheRoot(this._modelRoot)),this._mixer=void 0,this._clips=[],this._actionsMap.clear(),this.actions=[],this._lift=void 0,this._fork=void 0,this._jack=void 0,this._roller=void 0,this._rollerBaffle=void 0,this._rollerTop=void 0,this._shelf=void 0,this._rollerGoodsBox=void 0,this._modelRoot=void 0,this.goods.forEach(e=>{e.dispose(),e.parent&&e.removeFromParent()}),this.goods=[],this._liftBrackets=[],this._videoCache.forEach(e=>{e.pause(),e.removeAttribute("src"),e.load(),e.remove()}),this._videoCache.clear(),this._masts.clear(),this._shelves.clear(),this._outline&&(this._outline.removeFromParent(),this._outline=void 0),this._app&&this._onTicker&&this._app.renderer.domElement.removeEventListener("ticker",this._onTicker),this._onTicker=void 0}destroy(){this.clean(),this.sizeBox.destroy()}playAction(e,t){const i=Object.keys(t||{}).includes("reset")?t==null?void 0:t.reset:!0,s=this._actionsMap.get(e);if(!s||!this._mixer)return Promise.reject(new Error(`Action "${e}" not found or mixer not initialized.`));if(s.isRunning()&&s===this._currentAction)return Promise.resolve();const a=this._currentAction,n=a===s,c=n?0:t!=null&&t.fadeIn?t==null?void 0:t.fadeIn:.5,h=a&&!n&&a.isRunning();this._actionsMap.forEach(r=>{r!==s&&r!==a&&(r.stopFading(),r.setEffectiveWeight(0),r.stop())});const f=(t==null?void 0:t.loop)??!1;(i||!s.isRunning())&&s.reset(),s.enabled=!0,s.setEffectiveTimeScale((t==null?void 0:t.timeScale)??1),s.setEffectiveWeight(1),s.paused=!1,s.setLoop(f?d.LoopRepeat:d.LoopOnce,f?1/0:1),s.clampWhenFinished=(t==null?void 0:t.clampWhenFinished)??!f,s.play();const p=(t==null?void 0:t.timeScale)??1;return h?(a.stopFading(),a.enabled=!0,a.setEffectiveWeight(1),a.crossFadeTo(s,c,!1)):c>0&&s.fadeIn(c),s.setEffectiveTimeScale(p),this._currentAction=s,new Promise(r=>{this._pendingFinishedCallback&&this._mixer&&this._mixer.removeEventListener("finished",this._pendingFinishedCallback);const l=u=>{var g;u.action===s&&((g=this._mixer)==null||g.removeEventListener("finished",l),this._pendingFinishedCallback=null,r())};this._pendingFinishedCallback=l,this._mixer.addEventListener("finished",l)})}pauseAction(e){const t=this._actionsMap.get(e);t&&(t.paused=!0)}stopAction(e,t=.3){const i=this._actionsMap.get(e);return!i||!i.isRunning()?Promise.resolve():(this._currentAction===i&&(this._currentAction=null),t>0?(i.fadeOut(t),new Promise(s=>{setTimeout(()=>{i.stop(),s()},t*1e3)})):(i.stop(),Promise.resolve()))}stopAllActions(e=.3){return this._mixer?(this._currentAction=null,e>0?(this._actionsMap.forEach(t=>{t.isRunning()&&t.fadeOut(e)}),new Promise(t=>{setTimeout(()=>{var i;(i=this._mixer)==null||i.stopAllAction(),t()},e*1e3)})):(this._mixer.stopAllAction(),Promise.resolve())):Promise.resolve()}}const Hr=0,nl=1,ol=2,er=2,Li=1.25,tr=1,Pt=6*4+4+4,pi=65535,al=Math.pow(2,-24),Ii=Symbol("SKIP_GENERATION");function ll(o){return o.index?o.index.count:o.attributes.position.count}function mt(o){return ll(o)/3}function cl(o,e=ArrayBuffer){return o>65535?new Uint32Array(new e(4*o)):new Uint16Array(new e(2*o))}function hl(o,e){if(!o.index){const t=o.attributes.position.count,i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=cl(t,i);o.setIndex(new d.BufferAttribute(s,1));for(let a=0;a<t;a++)s[a]=a}}function Gr(o){const e=mt(o),t=o.drawRange,i=t.start/3,s=(t.start+t.count)/3,a=Math.max(0,i),n=Math.min(e,s)-a;return[{offset:Math.floor(a),count:Math.floor(n)}]}function Nr(o){if(!o.groups||!o.groups.length)return Gr(o);const e=[],t=new Set,i=o.drawRange,s=i.start/3,a=(i.start+i.count)/3;for(const c of o.groups){const h=c.start/3,f=(c.start+c.count)/3;t.add(Math.max(s,h)),t.add(Math.min(a,f))}const n=Array.from(t.values()).sort((c,h)=>c-h);for(let c=0;c<n.length-1;c++){const h=n[c],f=n[c+1];e.push({offset:Math.floor(h),count:Math.floor(f-h)})}return e}function ul(o){if(o.groups.length===0)return!1;const e=mt(o),t=Nr(o).sort((a,n)=>a.offset-n.offset),i=t[t.length-1];i.count=Math.min(e-i.offset,i.count);let s=0;return t.forEach(({count:a})=>s+=a),e!==s}function Di(o,e,t,i,s){let a=1/0,n=1/0,c=1/0,h=-1/0,f=-1/0,p=-1/0,r=1/0,l=1/0,u=1/0,g=-1/0,y=-1/0,m=-1/0;for(let v=e*6,_=(e+t)*6;v<_;v+=6){const x=o[v+0],w=o[v+1],b=x-w,T=x+w;b<a&&(a=b),T>h&&(h=T),x<r&&(r=x),x>g&&(g=x);const S=o[v+2],L=o[v+3],C=S-L,D=S+L;C<n&&(n=C),D>f&&(f=D),S<l&&(l=S),S>y&&(y=S);const R=o[v+4],A=o[v+5],M=R-A,I=R+A;M<c&&(c=M),I>p&&(p=I),R<u&&(u=R),R>m&&(m=R)}i[0]=a,i[1]=n,i[2]=c,i[3]=h,i[4]=f,i[5]=p,s[0]=r,s[1]=l,s[2]=u,s[3]=g,s[4]=y,s[5]=m}function fl(o,e=null,t=null,i=null){const s=o.attributes.position,a=o.index?o.index.array:null,n=mt(o),c=s.normalized;let h;e===null?(h=new Float32Array(n*6*4),t=0,i=n):(h=e,t=t||0,i=i||n);const f=s.array,p=s.offset||0;let r=3;s.isInterleavedBufferAttribute&&(r=s.data.stride);const l=["getX","getY","getZ"];for(let u=t;u<t+i;u++){const g=u*3,y=u*6;let m=g+0,v=g+1,_=g+2;a&&(m=a[m],v=a[v],_=a[_]),c||(m=m*r+p,v=v*r+p,_=_*r+p);for(let x=0;x<3;x++){let w,b,T;c?(w=s[l[x]](m),b=s[l[x]](v),T=s[l[x]](_)):(w=f[m+x],b=f[v+x],T=f[_+x]);let S=w;b<S&&(S=b),T<S&&(S=T);let L=w;b>L&&(L=b),T>L&&(L=T);const C=(L-S)/2,D=x*2;h[y+D+0]=S+C,h[y+D+1]=C+(Math.abs(S)+C)*al}}return h}function Y(o,e,t){return t.min.x=e[o],t.min.y=e[o+1],t.min.z=e[o+2],t.max.x=e[o+3],t.max.y=e[o+4],t.max.z=e[o+5],t}function ir(o){let e=-1,t=-1/0;for(let i=0;i<3;i++){const s=o[i+3]-o[i];s>t&&(t=s,e=i)}return e}function sr(o,e){e.set(o)}function rr(o,e,t){let i,s;for(let a=0;a<3;a++){const n=a+3;i=o[a],s=e[a],t[a]=i<s?i:s,i=o[n],s=e[n],t[n]=i>s?i:s}}function qt(o,e,t){for(let i=0;i<3;i++){const s=e[o+2*i],a=e[o+2*i+1],n=s-a,c=s+a;n<t[i]&&(t[i]=n),c>t[i+3]&&(t[i+3]=c)}}function bt(o){const e=o[3]-o[0],t=o[4]-o[1],i=o[5]-o[2];return 2*(e*t+t*i+i*e)}const _e=32,dl=(o,e)=>o.candidate-e.candidate,Ce=new Array(_e).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),jt=new Float32Array(6);function pl(o,e,t,i,s,a){let n=-1,c=0;if(a===Hr)n=ir(e),n!==-1&&(c=(e[n]+e[n+3])/2);else if(a===nl)n=ir(o),n!==-1&&(c=ml(t,i,s,n));else if(a===ol){const h=bt(o);let f=Li*s;const p=i*6,r=(i+s)*6;for(let l=0;l<3;l++){const u=e[l],m=(e[l+3]-u)/_e;if(s<_e/4){const v=[...Ce];v.length=s;let _=0;for(let w=p;w<r;w+=6,_++){const b=v[_];b.candidate=t[w+2*l],b.count=0;const{bounds:T,leftCacheBounds:S,rightCacheBounds:L}=b;for(let C=0;C<3;C++)L[C]=1/0,L[C+3]=-1/0,S[C]=1/0,S[C+3]=-1/0,T[C]=1/0,T[C+3]=-1/0;qt(w,t,T)}v.sort(dl);let x=s;for(let w=0;w<x;w++){const b=v[w];for(;w+1<x&&v[w+1].candidate===b.candidate;)v.splice(w+1,1),x--}for(let w=p;w<r;w+=6){const b=t[w+2*l];for(let T=0;T<x;T++){const S=v[T];b>=S.candidate?qt(w,t,S.rightCacheBounds):(qt(w,t,S.leftCacheBounds),S.count++)}}for(let w=0;w<x;w++){const b=v[w],T=b.count,S=s-b.count,L=b.leftCacheBounds,C=b.rightCacheBounds;let D=0;T!==0&&(D=bt(L)/h);let R=0;S!==0&&(R=bt(C)/h);const A=tr+Li*(D*T+R*S);A<f&&(n=l,f=A,c=b.candidate)}}else{for(let x=0;x<_e;x++){const w=Ce[x];w.count=0,w.candidate=u+m+x*m;const b=w.bounds;for(let T=0;T<3;T++)b[T]=1/0,b[T+3]=-1/0}for(let x=p;x<r;x+=6){let T=~~((t[x+2*l]-u)/m);T>=_e&&(T=_e-1);const S=Ce[T];S.count++,qt(x,t,S.bounds)}const v=Ce[_e-1];sr(v.bounds,v.rightCacheBounds);for(let x=_e-2;x>=0;x--){const w=Ce[x],b=Ce[x+1];rr(w.bounds,b.rightCacheBounds,w.rightCacheBounds)}let _=0;for(let x=0;x<_e-1;x++){const w=Ce[x],b=w.count,T=w.bounds,L=Ce[x+1].rightCacheBounds;b!==0&&(_===0?sr(T,jt):rr(T,jt,jt)),_+=b;let C=0,D=0;_!==0&&(C=bt(jt)/h);const R=s-_;R!==0&&(D=bt(L)/h);const A=tr+Li*(C*_+D*R);A<f&&(n=l,f=A,c=w.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${a} used.`);return{axis:n,pos:c}}function ml(o,e,t,i){let s=0;for(let a=e,n=e+t;a<n;a++)s+=o[a*6+i*2];return s/t}class Pi{constructor(){this.boundingData=new Float32Array(6)}}function gl(o,e,t,i,s,a){let n=i,c=i+s-1;const h=a.pos,f=a.axis*2;for(;;){for(;n<=c&&t[n*6+f]<h;)n++;for(;n<=c&&t[c*6+f]>=h;)c--;if(n<c){for(let p=0;p<3;p++){let r=e[n*3+p];e[n*3+p]=e[c*3+p],e[c*3+p]=r}for(let p=0;p<6;p++){let r=t[n*6+p];t[n*6+p]=t[c*6+p],t[c*6+p]=r}n++,c--}else return n}}function vl(o,e,t,i,s,a){let n=i,c=i+s-1;const h=a.pos,f=a.axis*2;for(;;){for(;n<=c&&t[n*6+f]<h;)n++;for(;n<=c&&t[c*6+f]>=h;)c--;if(n<c){let p=o[n];o[n]=o[c],o[c]=p;for(let r=0;r<6;r++){let l=t[n*6+r];t[n*6+r]=t[c*6+r],t[c*6+r]=l}n++,c--}else return n}}function ee(o,e){return e[o+15]===65535}function se(o,e){return e[o+6]}function ne(o,e){return e[o+14]}function oe(o){return o+8}function ae(o,e){return e[o+6]}function qr(o,e){return e[o+7]}let jr,Lt,ai,Qr;const _l=Math.pow(2,32);function Ki(o){return"count"in o?1:1+Ki(o.left)+Ki(o.right)}function yl(o,e,t){return jr=new Float32Array(t),Lt=new Uint32Array(t),ai=new Uint16Array(t),Qr=new Uint8Array(t),Xi(o,e)}function Xi(o,e){const t=o/4,i=o/2,s="count"in e,a=e.boundingData;for(let n=0;n<6;n++)jr[t+n]=a[n];if(s)if(e.buffer){const n=e.buffer;Qr.set(new Uint8Array(n),o);for(let c=o,h=o+n.byteLength;c<h;c+=Pt){const f=c/2;ee(f,ai)||(Lt[c/4+6]+=t)}return o+n.byteLength}else{const n=e.offset,c=e.count;return Lt[t+6]=n,ai[i+14]=c,ai[i+15]=pi,o+Pt}else{const n=e.left,c=e.right,h=e.splitAxis;let f;if(f=Xi(o+Pt,n),f/4>_l)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return Lt[t+6]=f/4,f=Xi(f,c),Lt[t+7]=h,f}}function xl(o,e){const t=(o.index?o.index.count:o.attributes.position.count)/3,i=t>2**16,s=i?4:2,a=e?new SharedArrayBuffer(t*s):new ArrayBuffer(t*s),n=i?new Uint32Array(a):new Uint16Array(a);for(let c=0,h=n.length;c<h;c++)n[c]=c;return n}function wl(o,e,t,i,s){const{maxDepth:a,verbose:n,maxLeafTris:c,strategy:h,onProgress:f,indirect:p}=s,r=o._indirectBuffer,l=o.geometry,u=l.index?l.index.array:null,g=p?vl:gl,y=mt(l),m=new Float32Array(6);let v=!1;const _=new Pi;return Di(e,t,i,_.boundingData,m),w(_,t,i,m),_;function x(b){f&&f(b/y)}function w(b,T,S,L=null,C=0){if(!v&&C>=a&&(v=!0,n&&(console.warn(`MeshBVH: Max depth of ${a} reached when generating BVH. Consider increasing maxDepth.`),console.warn(l))),S<=c||C>=a)return x(T+S),b.offset=T,b.count=S,b;const D=pl(b.boundingData,L,e,T,S,h);if(D.axis===-1)return x(T+S),b.offset=T,b.count=S,b;const R=g(r,u,e,T,S,D);if(R===T||R===T+S)x(T+S),b.offset=T,b.count=S;else{b.splitAxis=D.axis;const A=new Pi,M=T,I=R-T;b.left=A,Di(e,M,I,A.boundingData,m),w(A,M,I,m,C+1);const P=new Pi,E=R,B=S-I;b.right=P,Di(e,E,B,P.boundingData,m),w(P,E,B,m,C+1)}return b}}function bl(o,e){const t=o.geometry;e.indirect&&(o._indirectBuffer=xl(t,e.useSharedArrayBuffer),ul(t)&&!e.verbose&&console.warn('MeshBVH: Provided geometry contains groups that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),o._indirectBuffer||hl(t,e);const i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=fl(t),a=e.indirect?Gr(t):Nr(t);o._roots=a.map(n=>{const c=wl(o,s,n.offset,n.count,e),h=Ki(c),f=new i(Pt*h);return yl(0,c,f),f})}class Ae{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let i=1/0,s=-1/0;for(let a=0,n=e.length;a<n;a++){const h=e[a][t];i=h<i?h:i,s=h>s?h:s}this.min=i,this.max=s}setFromPoints(e,t){let i=1/0,s=-1/0;for(let a=0,n=t.length;a<n;a++){const c=t[a],h=e.dot(c);i=h<i?h:i,s=h>s?h:s}this.min=i,this.max=s}isSeparated(e){return this.min>e.max||e.min>this.max}}Ae.prototype.setFromBox=function(){const o=new d.Vector3;return function(t,i){const s=i.min,a=i.max;let n=1/0,c=-1/0;for(let h=0;h<=1;h++)for(let f=0;f<=1;f++)for(let p=0;p<=1;p++){o.x=s.x*h+a.x*(1-h),o.y=s.y*f+a.y*(1-f),o.z=s.z*p+a.z*(1-p);const r=t.dot(o);n=Math.min(r,n),c=Math.max(r,c)}this.min=n,this.max=c}}();const Al=function(){const o=new d.Vector3,e=new d.Vector3,t=new d.Vector3;return function(s,a,n){const c=s.start,h=o,f=a.start,p=e;t.subVectors(c,f),o.subVectors(s.end,s.start),e.subVectors(a.end,a.start);const r=t.dot(p),l=p.dot(h),u=p.dot(p),g=t.dot(h),m=h.dot(h)*u-l*l;let v,_;m!==0?v=(r*l-g*u)/m:v=0,_=(r+v*l)/u,n.x=v,n.y=_}}(),ps=function(){const o=new d.Vector2,e=new d.Vector3,t=new d.Vector3;return function(s,a,n,c){Al(s,a,o);let h=o.x,f=o.y;if(h>=0&&h<=1&&f>=0&&f<=1){s.at(h,n),a.at(f,c);return}else if(h>=0&&h<=1){f<0?a.at(0,c):a.at(1,c),s.closestPointToPoint(c,!0,n);return}else if(f>=0&&f<=1){h<0?s.at(0,n):s.at(1,n),a.closestPointToPoint(n,!0,c);return}else{let p;h<0?p=s.start:p=s.end;let r;f<0?r=a.start:r=a.end;const l=e,u=t;if(s.closestPointToPoint(r,!0,e),a.closestPointToPoint(p,!0,t),l.distanceToSquared(r)<=u.distanceToSquared(p)){n.copy(l),c.copy(r);return}else{n.copy(p),c.copy(u);return}}}}(),Tl=function(){const o=new d.Vector3,e=new d.Vector3,t=new d.Plane,i=new d.Line3;return function(a,n){const{radius:c,center:h}=a,{a:f,b:p,c:r}=n;if(i.start=f,i.end=p,i.closestPointToPoint(h,!0,o).distanceTo(h)<=c||(i.start=f,i.end=r,i.closestPointToPoint(h,!0,o).distanceTo(h)<=c)||(i.start=p,i.end=r,i.closestPointToPoint(h,!0,o).distanceTo(h)<=c))return!0;const y=n.getPlane(t);if(Math.abs(y.distanceToPoint(h))<=c){const v=y.projectPoint(h,e);if(n.containsPoint(v))return!0}return!1}}(),Sl=1e-15;function Fi(o){return Math.abs(o)<Sl}class fe extends d.Triangle{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new d.Vector3),this.satBounds=new Array(4).fill().map(()=>new Ae),this.points=[this.a,this.b,this.c],this.sphere=new d.Sphere,this.plane=new d.Plane,this.needsUpdate=!0}intersectsSphere(e){return Tl(e,this)}update(){const e=this.a,t=this.b,i=this.c,s=this.points,a=this.satAxes,n=this.satBounds,c=a[0],h=n[0];this.getNormal(c),h.setFromPoints(c,s);const f=a[1],p=n[1];f.subVectors(e,t),p.setFromPoints(f,s);const r=a[2],l=n[2];r.subVectors(t,i),l.setFromPoints(r,s);const u=a[3],g=n[3];u.subVectors(i,e),g.setFromPoints(u,s),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(c,e),this.needsUpdate=!1}}fe.prototype.closestPointToSegment=function(){const o=new d.Vector3,e=new d.Vector3,t=new d.Line3;return function(s,a=null,n=null){const{start:c,end:h}=s,f=this.points;let p,r=1/0;for(let l=0;l<3;l++){const u=(l+1)%3;t.start.copy(f[l]),t.end.copy(f[u]),ps(t,s,o,e),p=o.distanceToSquared(e),p<r&&(r=p,a&&a.copy(o),n&&n.copy(e))}return this.closestPointToPoint(c,o),p=c.distanceToSquared(o),p<r&&(r=p,a&&a.copy(o),n&&n.copy(c)),this.closestPointToPoint(h,o),p=h.distanceToSquared(o),p<r&&(r=p,a&&a.copy(o),n&&n.copy(h)),Math.sqrt(r)}}();fe.prototype.intersectsTriangle=function(){const o=new fe,e=new Array(3),t=new Array(3),i=new Ae,s=new Ae,a=new d.Vector3,n=new d.Vector3,c=new d.Vector3,h=new d.Vector3,f=new d.Vector3,p=new d.Line3,r=new d.Line3,l=new d.Line3,u=new d.Vector3;function g(y,m,v){const _=y.points;let x=0,w=-1;for(let b=0;b<3;b++){const{start:T,end:S}=p;T.copy(_[b]),S.copy(_[(b+1)%3]),p.delta(n);const L=Fi(m.distanceToPoint(T));if(Fi(m.normal.dot(n))&&L){v.copy(p),x=2;break}const C=m.intersectLine(p,u);if(!C&&L&&u.copy(T),(C||L)&&!Fi(u.distanceTo(S))){if(x<=1)(x===1?v.start:v.end).copy(u),L&&(w=x);else if(x>=2){(w===1?v.start:v.end).copy(u),x=2;break}if(x++,x===2&&w===-1)break}}return x}return function(m,v=null,_=!1){this.needsUpdate&&this.update(),m.isExtendedTriangle?m.needsUpdate&&m.update():(o.copy(m),o.update(),m=o);const x=this.plane,w=m.plane;if(Math.abs(x.normal.dot(w.normal))>1-1e-10){const b=this.satBounds,T=this.satAxes;t[0]=m.a,t[1]=m.b,t[2]=m.c;for(let C=0;C<4;C++){const D=b[C],R=T[C];if(i.setFromPoints(R,t),D.isSeparated(i))return!1}const S=m.satBounds,L=m.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let C=0;C<4;C++){const D=S[C],R=L[C];if(i.setFromPoints(R,e),D.isSeparated(i))return!1}for(let C=0;C<4;C++){const D=T[C];for(let R=0;R<4;R++){const A=L[R];if(a.crossVectors(D,A),i.setFromPoints(a,e),s.setFromPoints(a,t),i.isSeparated(s))return!1}}return v&&(_||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),v.start.set(0,0,0),v.end.set(0,0,0)),!0}else{const b=g(this,w,r);if(b===1&&m.containsPoint(r.end))return v&&(v.start.copy(r.end),v.end.copy(r.end)),!0;if(b!==2)return!1;const T=g(m,x,l);if(T===1&&this.containsPoint(l.end))return v&&(v.start.copy(l.end),v.end.copy(l.end)),!0;if(T!==2)return!1;if(r.delta(c),l.delta(h),c.dot(h)<0){let M=l.start;l.start=l.end,l.end=M}const S=r.start.dot(c),L=r.end.dot(c),C=l.start.dot(c),D=l.end.dot(c),R=L<C,A=S<D;return S!==D&&C!==L&&R===A?!1:(v&&(f.subVectors(r.start,l.start),f.dot(c)>0?v.start.copy(r.start):v.start.copy(l.start),f.subVectors(r.end,l.end),f.dot(c)<0?v.end.copy(r.end):v.end.copy(l.end)),!0)}}}();fe.prototype.distanceToPoint=function(){const o=new d.Vector3;return function(t){return this.closestPointToPoint(t,o),t.distanceTo(o)}}();fe.prototype.distanceToTriangle=function(){const o=new d.Vector3,e=new d.Vector3,t=["a","b","c"],i=new d.Line3,s=new d.Line3;return function(n,c=null,h=null){const f=c||h?i:null;if(this.intersectsTriangle(n,f))return(c||h)&&(c&&f.getCenter(c),h&&f.getCenter(h)),0;let p=1/0;for(let r=0;r<3;r++){let l;const u=t[r],g=n[u];this.closestPointToPoint(g,o),l=g.distanceToSquared(o),l<p&&(p=l,c&&c.copy(o),h&&h.copy(g));const y=this[u];n.closestPointToPoint(y,o),l=y.distanceToSquared(o),l<p&&(p=l,c&&c.copy(y),h&&h.copy(o))}for(let r=0;r<3;r++){const l=t[r],u=t[(r+1)%3];i.set(this[l],this[u]);for(let g=0;g<3;g++){const y=t[g],m=t[(g+1)%3];s.set(n[y],n[m]),ps(i,s,o,e);const v=o.distanceToSquared(e);v<p&&(p=v,c&&c.copy(o),h&&h.copy(e))}}return Math.sqrt(p)}}();class Z{constructor(e,t,i){this.isOrientedBox=!0,this.min=new d.Vector3,this.max=new d.Vector3,this.matrix=new d.Matrix4,this.invMatrix=new d.Matrix4,this.points=new Array(8).fill().map(()=>new d.Vector3),this.satAxes=new Array(3).fill().map(()=>new d.Vector3),this.satBounds=new Array(3).fill().map(()=>new Ae),this.alignedSatBounds=new Array(3).fill().map(()=>new Ae),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),i&&this.matrix.copy(i)}set(e,t,i){this.min.copy(e),this.max.copy(t),this.matrix.copy(i),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}Z.prototype.update=function(){return function(){const e=this.matrix,t=this.min,i=this.max,s=this.points;for(let f=0;f<=1;f++)for(let p=0;p<=1;p++)for(let r=0;r<=1;r++){const l=1*f|2*p|4*r,u=s[l];u.x=f?i.x:t.x,u.y=p?i.y:t.y,u.z=r?i.z:t.z,u.applyMatrix4(e)}const a=this.satBounds,n=this.satAxes,c=s[0];for(let f=0;f<3;f++){const p=n[f],r=a[f],l=1<<f,u=s[l];p.subVectors(c,u),r.setFromPoints(p,s)}const h=this.alignedSatBounds;h[0].setFromPointsField(s,"x"),h[1].setFromPointsField(s,"y"),h[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}();Z.prototype.intersectsBox=function(){const o=new Ae;return function(t){this.needsUpdate&&this.update();const i=t.min,s=t.max,a=this.satBounds,n=this.satAxes,c=this.alignedSatBounds;if(o.min=i.x,o.max=s.x,c[0].isSeparated(o)||(o.min=i.y,o.max=s.y,c[1].isSeparated(o))||(o.min=i.z,o.max=s.z,c[2].isSeparated(o)))return!1;for(let h=0;h<3;h++){const f=n[h],p=a[h];if(o.setFromBox(f,t),p.isSeparated(o))return!1}return!0}}();Z.prototype.intersectsTriangle=function(){const o=new fe,e=new Array(3),t=new Ae,i=new Ae,s=new d.Vector3;return function(n){this.needsUpdate&&this.update(),n.isExtendedTriangle?n.needsUpdate&&n.update():(o.copy(n),o.update(),n=o);const c=this.satBounds,h=this.satAxes;e[0]=n.a,e[1]=n.b,e[2]=n.c;for(let l=0;l<3;l++){const u=c[l],g=h[l];if(t.setFromPoints(g,e),u.isSeparated(t))return!1}const f=n.satBounds,p=n.satAxes,r=this.points;for(let l=0;l<3;l++){const u=f[l],g=p[l];if(t.setFromPoints(g,r),u.isSeparated(t))return!1}for(let l=0;l<3;l++){const u=h[l];for(let g=0;g<4;g++){const y=p[g];if(s.crossVectors(u,y),t.setFromPoints(s,e),i.setFromPoints(s,r),t.isSeparated(i))return!1}}return!0}}();Z.prototype.closestPointToPoint=function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}}();Z.prototype.distanceToPoint=function(){const o=new d.Vector3;return function(t){return this.closestPointToPoint(t,o),t.distanceTo(o)}}();Z.prototype.distanceToBox=function(){const o=["x","y","z"],e=new Array(12).fill().map(()=>new d.Line3),t=new Array(12).fill().map(()=>new d.Line3),i=new d.Vector3,s=new d.Vector3;return function(n,c=0,h=null,f=null){if(this.needsUpdate&&this.update(),this.intersectsBox(n))return(h||f)&&(n.getCenter(s),this.closestPointToPoint(s,i),n.closestPointToPoint(i,s),h&&h.copy(i),f&&f.copy(s)),0;const p=c*c,r=n.min,l=n.max,u=this.points;let g=1/0;for(let m=0;m<8;m++){const v=u[m];s.copy(v).clamp(r,l);const _=v.distanceToSquared(s);if(_<g&&(g=_,h&&h.copy(v),f&&f.copy(s),_<p))return Math.sqrt(_)}let y=0;for(let m=0;m<3;m++)for(let v=0;v<=1;v++)for(let _=0;_<=1;_++){const x=(m+1)%3,w=(m+2)%3,b=v<<x|_<<w,T=1<<m|v<<x|_<<w,S=u[b],L=u[T];e[y].set(S,L);const D=o[m],R=o[x],A=o[w],M=t[y],I=M.start,P=M.end;I[D]=r[D],I[R]=v?r[R]:l[R],I[A]=_?r[A]:l[R],P[D]=l[D],P[R]=v?r[R]:l[R],P[A]=_?r[A]:l[R],y++}for(let m=0;m<=1;m++)for(let v=0;v<=1;v++)for(let _=0;_<=1;_++){s.x=m?l.x:r.x,s.y=v?l.y:r.y,s.z=_?l.z:r.z,this.closestPointToPoint(s,i);const x=s.distanceToSquared(i);if(x<g&&(g=x,h&&h.copy(i),f&&f.copy(s),x<p))return Math.sqrt(x)}for(let m=0;m<12;m++){const v=e[m];for(let _=0;_<12;_++){const x=t[_];ps(v,x,i,s);const w=i.distanceToSquared(s);if(w<g&&(g=w,h&&h.copy(i),f&&f.copy(s),w<p))return Math.sqrt(w)}}return Math.sqrt(g)}}();class ms{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class Ml extends ms{constructor(){super(()=>new fe)}}const le=new Ml;class Cl{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=i=>{t&&e.push(t),t=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const q=new Cl;let Fe,at;const Qe=[],Qt=new ms(()=>new d.Box3);function Rl(o,e,t,i,s,a){Fe=Qt.getPrimitive(),at=Qt.getPrimitive(),Qe.push(Fe,at),q.setBuffer(o._roots[e]);const n=Zi(0,o.geometry,t,i,s,a);q.clearBuffer(),Qt.releasePrimitive(Fe),Qt.releasePrimitive(at),Qe.pop(),Qe.pop();const c=Qe.length;return c>0&&(at=Qe[c-1],Fe=Qe[c-2]),n}function Zi(o,e,t,i,s=null,a=0,n=0){const{float32Array:c,uint16Array:h,uint32Array:f}=q;let p=o*2;if(ee(p,h)){const l=se(o,f),u=ne(p,h);return Y(o,c,Fe),i(l,u,!1,n,a+o,Fe)}else{let D=function(A){const{uint16Array:M,uint32Array:I}=q;let P=A*2;for(;!ee(P,M);)A=oe(A),P=A*2;return se(A,I)},R=function(A){const{uint16Array:M,uint32Array:I}=q;let P=A*2;for(;!ee(P,M);)A=ae(A,I),P=A*2;return se(A,I)+ne(P,M)};const l=oe(o),u=ae(o,f);let g=l,y=u,m,v,_,x;if(s&&(_=Fe,x=at,Y(g,c,_),Y(y,c,x),m=s(_),v=s(x),v<m)){g=u,y=l;const A=m;m=v,v=A,_=x}_||(_=Fe,Y(g,c,_));const w=ee(g*2,h),b=t(_,w,m,n+1,a+g);let T;if(b===er){const A=D(g),I=R(g)-A;T=i(A,I,!0,n+1,a+g,_)}else T=b&&Zi(g,e,t,i,s,a,n+1);if(T)return!0;x=at,Y(y,c,x);const S=ee(y*2,h),L=t(x,S,v,n+1,a+y);let C;if(L===er){const A=D(y),I=R(y)-A;C=i(A,I,!0,n+1,a+y,x)}else C=L&&Zi(y,e,t,i,s,a,n+1);return!!C}}const At=new d.Vector3,Ei=new d.Vector3;function Ll(o,e,t={},i=0,s=1/0){const a=i*i,n=s*s;let c=1/0,h=null;if(o.shapecast({boundsTraverseOrder:p=>(At.copy(e).clamp(p.min,p.max),At.distanceToSquared(e)),intersectsBounds:(p,r,l)=>l<c&&l<n,intersectsTriangle:(p,r)=>{p.closestPointToPoint(e,At);const l=e.distanceToSquared(At);return l<c&&(Ei.copy(At),c=l,h=r),l<a}}),c===1/0)return null;const f=Math.sqrt(c);return t.point?t.point.copy(Ei):t.point=Ei.clone(),t.distance=f,t.faceIndex=h,t}const Ye=new d.Vector3,Ke=new d.Vector3,Xe=new d.Vector3,Yt=new d.Vector2,Kt=new d.Vector2,Xt=new d.Vector2,nr=new d.Vector3,or=new d.Vector3,ar=new d.Vector3,Zt=new d.Vector3;function Il(o,e,t,i,s,a,n,c){let h;if(a===d.BackSide?h=o.intersectTriangle(i,t,e,!0,s):h=o.intersectTriangle(e,t,i,a!==d.DoubleSide,s),h===null)return null;const f=o.origin.distanceTo(s);return f<n||f>c?null:{distance:f,point:s.clone()}}function Dl(o,e,t,i,s,a,n,c,h,f,p){Ye.fromBufferAttribute(e,a),Ke.fromBufferAttribute(e,n),Xe.fromBufferAttribute(e,c);const r=Il(o,Ye,Ke,Xe,Zt,h,f,p);if(r){i&&(Yt.fromBufferAttribute(i,a),Kt.fromBufferAttribute(i,n),Xt.fromBufferAttribute(i,c),r.uv=d.Triangle.getInterpolation(Zt,Ye,Ke,Xe,Yt,Kt,Xt,new d.Vector2)),s&&(Yt.fromBufferAttribute(s,a),Kt.fromBufferAttribute(s,n),Xt.fromBufferAttribute(s,c),r.uv1=d.Triangle.getInterpolation(Zt,Ye,Ke,Xe,Yt,Kt,Xt,new d.Vector2)),t&&(nr.fromBufferAttribute(t,a),or.fromBufferAttribute(t,n),ar.fromBufferAttribute(t,c),r.normal=d.Triangle.getInterpolation(Zt,Ye,Ke,Xe,nr,or,ar,new d.Vector3),r.normal.dot(o.direction)>0&&r.normal.multiplyScalar(-1));const l={a,b:n,c,normal:new d.Vector3,materialIndex:0};d.Triangle.getNormal(Ye,Ke,Xe,l.normal),r.face=l,r.faceIndex=a}return r}function mi(o,e,t,i,s,a,n){const c=i*3;let h=c+0,f=c+1,p=c+2;const r=o.index;o.index&&(h=r.getX(h),f=r.getX(f),p=r.getX(p));const{position:l,normal:u,uv:g,uv1:y}=o.attributes,m=Dl(t,l,u,g,y,h,f,p,e,a,n);return m?(m.faceIndex=i,s&&s.push(m),m):null}function K(o,e,t,i){const s=o.a,a=o.b,n=o.c;let c=e,h=e+1,f=e+2;t&&(c=t.getX(c),h=t.getX(h),f=t.getX(f)),s.x=i.getX(c),s.y=i.getY(c),s.z=i.getZ(c),a.x=i.getX(h),a.y=i.getY(h),a.z=i.getZ(h),n.x=i.getX(f),n.y=i.getY(f),n.z=i.getZ(f)}function Pl(o,e,t,i,s,a,n,c){const{geometry:h,_indirectBuffer:f}=o;for(let p=i,r=i+s;p<r;p++)mi(h,e,t,p,a,n,c)}function Fl(o,e,t,i,s,a,n){const{geometry:c,_indirectBuffer:h}=o;let f=1/0,p=null;for(let r=i,l=i+s;r<l;r++){let u;u=mi(c,e,t,r,null,a,n),u&&u.distance<f&&(p=u,f=u.distance)}return p}function El(o,e,t,i,s,a,n){const{geometry:c}=t,{index:h}=c,f=c.attributes.position;for(let p=o,r=e+o;p<r;p++){let l;if(l=p,K(n,l*3,h,f),n.needsUpdate=!0,i(n,l,s,a))return!0}return!1}function Bl(o,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=o.geometry,i=t.index?t.index.array:null,s=t.attributes.position;let a,n,c,h,f=0;const p=o._roots;for(let l=0,u=p.length;l<u;l++)a=p[l],n=new Uint32Array(a),c=new Uint16Array(a),h=new Float32Array(a),r(0,f),f+=a.byteLength;function r(l,u,g=!1){const y=l*2;if(c[y+15]===pi){const v=n[l+6],_=c[y+14];let x=1/0,w=1/0,b=1/0,T=-1/0,S=-1/0,L=-1/0;for(let C=3*v,D=3*(v+_);C<D;C++){let R=i[C];const A=s.getX(R),M=s.getY(R),I=s.getZ(R);A<x&&(x=A),A>T&&(T=A),M<w&&(w=M),M>S&&(S=M),I<b&&(b=I),I>L&&(L=I)}return h[l+0]!==x||h[l+1]!==w||h[l+2]!==b||h[l+3]!==T||h[l+4]!==S||h[l+5]!==L?(h[l+0]=x,h[l+1]=w,h[l+2]=b,h[l+3]=T,h[l+4]=S,h[l+5]=L,!0):!1}else{const v=l+8,_=n[l+6],x=v+u,w=_+u;let b=g,T=!1,S=!1;e?b||(T=e.has(x),S=e.has(w),b=!T&&!S):(T=!0,S=!0);const L=b||T,C=b||S;let D=!1;L&&(D=r(v,u,b));let R=!1;C&&(R=r(_,u,b));const A=D||R;if(A)for(let M=0;M<3;M++){const I=v+M,P=_+M,E=h[I],B=h[I+3],V=h[P],G=h[P+3];h[l+M]=E<V?E:V,h[l+M+3]=B>G?B:G}return A}}}function Ee(o,e,t,i,s){let a,n,c,h,f,p;const r=1/t.direction.x,l=1/t.direction.y,u=1/t.direction.z,g=t.origin.x,y=t.origin.y,m=t.origin.z;let v=e[o],_=e[o+3],x=e[o+1],w=e[o+3+1],b=e[o+2],T=e[o+3+2];return r>=0?(a=(v-g)*r,n=(_-g)*r):(a=(_-g)*r,n=(v-g)*r),l>=0?(c=(x-y)*l,h=(w-y)*l):(c=(w-y)*l,h=(x-y)*l),a>h||c>n||((c>a||isNaN(a))&&(a=c),(h<n||isNaN(n))&&(n=h),u>=0?(f=(b-m)*u,p=(T-m)*u):(f=(T-m)*u,p=(b-m)*u),a>p||f>n)?!1:((f>a||a!==a)&&(a=f),(p<n||n!==n)&&(n=p),a<=s&&n>=i)}function kl(o,e,t,i,s,a,n,c){const{geometry:h,_indirectBuffer:f}=o;for(let p=i,r=i+s;p<r;p++){let l=f?f[p]:p;mi(h,e,t,l,a,n,c)}}function Ol(o,e,t,i,s,a,n){const{geometry:c,_indirectBuffer:h}=o;let f=1/0,p=null;for(let r=i,l=i+s;r<l;r++){let u;u=mi(c,e,t,h?h[r]:r,null,a,n),u&&u.distance<f&&(p=u,f=u.distance)}return p}function zl(o,e,t,i,s,a,n){const{geometry:c}=t,{index:h}=c,f=c.attributes.position;for(let p=o,r=e+o;p<r;p++){let l;if(l=t.resolveTriangleIndex(p),K(n,l*3,h,f),n.needsUpdate=!0,i(n,l,s,a))return!0}return!1}function Vl(o,e,t,i,s,a,n){q.setBuffer(o._roots[e]),Ji(0,o,t,i,s,a,n),q.clearBuffer()}function Ji(o,e,t,i,s,a,n){const{float32Array:c,uint16Array:h,uint32Array:f}=q,p=o*2;if(ee(p,h)){const l=se(o,f),u=ne(p,h);Pl(e,t,i,l,u,s,a,n)}else{const l=oe(o);Ee(l,c,i,a,n)&&Ji(l,e,t,i,s,a,n);const u=ae(o,f);Ee(u,c,i,a,n)&&Ji(u,e,t,i,s,a,n)}}const Ul=["x","y","z"];function Wl(o,e,t,i,s,a){q.setBuffer(o._roots[e]);const n=$i(0,o,t,i,s,a);return q.clearBuffer(),n}function $i(o,e,t,i,s,a){const{float32Array:n,uint16Array:c,uint32Array:h}=q;let f=o*2;if(ee(f,c)){const r=se(o,h),l=ne(f,c);return Fl(e,t,i,r,l,s,a)}else{const r=qr(o,h),l=Ul[r],g=i.direction[l]>=0;let y,m;g?(y=oe(o),m=ae(o,h)):(y=ae(o,h),m=oe(o));const _=Ee(y,n,i,s,a)?$i(y,e,t,i,s,a):null;if(_){const b=_.point[l];if(g?b<=n[m+r]:b>=n[m+r+3])return _}const w=Ee(m,n,i,s,a)?$i(m,e,t,i,s,a):null;return _&&w?_.distance<=w.distance?_:w:_||w||null}}const Jt=new d.Box3,Ze=new fe,Je=new fe,Tt=new d.Matrix4,lr=new Z,$t=new Z;function Hl(o,e,t,i){q.setBuffer(o._roots[e]);const s=es(0,o,t,i);return q.clearBuffer(),s}function es(o,e,t,i,s=null){const{float32Array:a,uint16Array:n,uint32Array:c}=q;let h=o*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),lr.set(t.boundingBox.min,t.boundingBox.max,i),s=lr),ee(h,n)){const p=e.geometry,r=p.index,l=p.attributes.position,u=t.index,g=t.attributes.position,y=se(o,c),m=ne(h,n);if(Tt.copy(i).invert(),t.boundsTree)return Y(o,a,$t),$t.matrix.copy(Tt),$t.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:_=>$t.intersectsBox(_),intersectsTriangle:_=>{_.a.applyMatrix4(i),_.b.applyMatrix4(i),_.c.applyMatrix4(i),_.needsUpdate=!0;for(let x=y*3,w=(m+y)*3;x<w;x+=3)if(K(Je,x,r,l),Je.needsUpdate=!0,_.intersectsTriangle(Je))return!0;return!1}});for(let v=y*3,_=(m+y)*3;v<_;v+=3){K(Ze,v,r,l),Ze.a.applyMatrix4(Tt),Ze.b.applyMatrix4(Tt),Ze.c.applyMatrix4(Tt),Ze.needsUpdate=!0;for(let x=0,w=u.count;x<w;x+=3)if(K(Je,x,u,g),Je.needsUpdate=!0,Ze.intersectsTriangle(Je))return!0}}else{const p=o+8,r=c[o+6];return Y(p,a,Jt),!!(s.intersectsBox(Jt)&&es(p,e,t,i,s)||(Y(r,a,Jt),s.intersectsBox(Jt)&&es(r,e,t,i,s)))}}const ei=new d.Matrix4,Bi=new Z,St=new Z,Gl=new d.Vector3,Nl=new d.Vector3,ql=new d.Vector3,jl=new d.Vector3;function Ql(o,e,t,i={},s={},a=0,n=1/0){e.boundingBox||e.computeBoundingBox(),Bi.set(e.boundingBox.min,e.boundingBox.max,t),Bi.needsUpdate=!0;const c=o.geometry,h=c.attributes.position,f=c.index,p=e.attributes.position,r=e.index,l=le.getPrimitive(),u=le.getPrimitive();let g=Gl,y=Nl,m=null,v=null;s&&(m=ql,v=jl);let _=1/0,x=null,w=null;return ei.copy(t).invert(),St.matrix.copy(ei),o.shapecast({boundsTraverseOrder:b=>Bi.distanceToBox(b),intersectsBounds:(b,T,S)=>S<_&&S<n?(T&&(St.min.copy(b.min),St.max.copy(b.max),St.needsUpdate=!0),!0):!1,intersectsRange:(b,T)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:L=>St.distanceToBox(L),intersectsBounds:(L,C,D)=>D<_&&D<n,intersectsRange:(L,C)=>{for(let D=L,R=L+C;D<R;D++){K(u,3*D,r,p),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let A=b,M=b+T;A<M;A++){K(l,3*A,f,h),l.needsUpdate=!0;const I=l.distanceToTriangle(u,g,m);if(I<_&&(y.copy(g),v&&v.copy(m),_=I,x=A,w=D),I<a)return!0}}}});{const S=mt(e);for(let L=0,C=S;L<C;L++){K(u,3*L,r,p),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let D=b,R=b+T;D<R;D++){K(l,3*D,f,h),l.needsUpdate=!0;const A=l.distanceToTriangle(u,g,m);if(A<_&&(y.copy(g),v&&v.copy(m),_=A,x=D,w=L),A<a)return!0}}}}}),le.releasePrimitive(l),le.releasePrimitive(u),_===1/0?null:(i.point?i.point.copy(y):i.point=y.clone(),i.distance=_,i.faceIndex=x,s&&(s.point?s.point.copy(v):s.point=v.clone(),s.point.applyMatrix4(ei),y.applyMatrix4(ei),s.distance=y.sub(s.point).length(),s.faceIndex=w),i)}function Yl(o,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=o.geometry,i=t.index?t.index.array:null,s=t.attributes.position;let a,n,c,h,f=0;const p=o._roots;for(let l=0,u=p.length;l<u;l++)a=p[l],n=new Uint32Array(a),c=new Uint16Array(a),h=new Float32Array(a),r(0,f),f+=a.byteLength;function r(l,u,g=!1){const y=l*2;if(c[y+15]===pi){const v=n[l+6],_=c[y+14];let x=1/0,w=1/0,b=1/0,T=-1/0,S=-1/0,L=-1/0;for(let C=v,D=v+_;C<D;C++){const R=3*o.resolveTriangleIndex(C);for(let A=0;A<3;A++){let M=R+A;M=i?i[M]:M;const I=s.getX(M),P=s.getY(M),E=s.getZ(M);I<x&&(x=I),I>T&&(T=I),P<w&&(w=P),P>S&&(S=P),E<b&&(b=E),E>L&&(L=E)}}return h[l+0]!==x||h[l+1]!==w||h[l+2]!==b||h[l+3]!==T||h[l+4]!==S||h[l+5]!==L?(h[l+0]=x,h[l+1]=w,h[l+2]=b,h[l+3]=T,h[l+4]=S,h[l+5]=L,!0):!1}else{const v=l+8,_=n[l+6],x=v+u,w=_+u;let b=g,T=!1,S=!1;e?b||(T=e.has(x),S=e.has(w),b=!T&&!S):(T=!0,S=!0);const L=b||T,C=b||S;let D=!1;L&&(D=r(v,u,b));let R=!1;C&&(R=r(_,u,b));const A=D||R;if(A)for(let M=0;M<3;M++){const I=v+M,P=_+M,E=h[I],B=h[I+3],V=h[P],G=h[P+3];h[l+M]=E<V?E:V,h[l+M+3]=B>G?B:G}return A}}}function Kl(o,e,t,i,s,a,n){q.setBuffer(o._roots[e]),ts(0,o,t,i,s,a,n),q.clearBuffer()}function ts(o,e,t,i,s,a,n){const{float32Array:c,uint16Array:h,uint32Array:f}=q,p=o*2;if(ee(p,h)){const l=se(o,f),u=ne(p,h);kl(e,t,i,l,u,s,a,n)}else{const l=oe(o);Ee(l,c,i,a,n)&&ts(l,e,t,i,s,a,n);const u=ae(o,f);Ee(u,c,i,a,n)&&ts(u,e,t,i,s,a,n)}}const Xl=["x","y","z"];function Zl(o,e,t,i,s,a){q.setBuffer(o._roots[e]);const n=is(0,o,t,i,s,a);return q.clearBuffer(),n}function is(o,e,t,i,s,a){const{float32Array:n,uint16Array:c,uint32Array:h}=q;let f=o*2;if(ee(f,c)){const r=se(o,h),l=ne(f,c);return Ol(e,t,i,r,l,s,a)}else{const r=qr(o,h),l=Xl[r],g=i.direction[l]>=0;let y,m;g?(y=oe(o),m=ae(o,h)):(y=ae(o,h),m=oe(o));const _=Ee(y,n,i,s,a)?is(y,e,t,i,s,a):null;if(_){const b=_.point[l];if(g?b<=n[m+r]:b>=n[m+r+3])return _}const w=Ee(m,n,i,s,a)?is(m,e,t,i,s,a):null;return _&&w?_.distance<=w.distance?_:w:_||w||null}}const ti=new d.Box3,$e=new fe,et=new fe,Mt=new d.Matrix4,cr=new Z,ii=new Z;function Jl(o,e,t,i){q.setBuffer(o._roots[e]);const s=ss(0,o,t,i);return q.clearBuffer(),s}function ss(o,e,t,i,s=null){const{float32Array:a,uint16Array:n,uint32Array:c}=q;let h=o*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),cr.set(t.boundingBox.min,t.boundingBox.max,i),s=cr),ee(h,n)){const p=e.geometry,r=p.index,l=p.attributes.position,u=t.index,g=t.attributes.position,y=se(o,c),m=ne(h,n);if(Mt.copy(i).invert(),t.boundsTree)return Y(o,a,ii),ii.matrix.copy(Mt),ii.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:_=>ii.intersectsBox(_),intersectsTriangle:_=>{_.a.applyMatrix4(i),_.b.applyMatrix4(i),_.c.applyMatrix4(i),_.needsUpdate=!0;for(let x=y,w=m+y;x<w;x++)if(K(et,3*e.resolveTriangleIndex(x),r,l),et.needsUpdate=!0,_.intersectsTriangle(et))return!0;return!1}});for(let v=y,_=m+y;v<_;v++){const x=e.resolveTriangleIndex(v);K($e,3*x,r,l),$e.a.applyMatrix4(Mt),$e.b.applyMatrix4(Mt),$e.c.applyMatrix4(Mt),$e.needsUpdate=!0;for(let w=0,b=u.count;w<b;w+=3)if(K(et,w,u,g),et.needsUpdate=!0,$e.intersectsTriangle(et))return!0}}else{const p=o+8,r=c[o+6];return Y(p,a,ti),!!(s.intersectsBox(ti)&&ss(p,e,t,i,s)||(Y(r,a,ti),s.intersectsBox(ti)&&ss(r,e,t,i,s)))}}const si=new d.Matrix4,ki=new Z,Ct=new Z,$l=new d.Vector3,ec=new d.Vector3,tc=new d.Vector3,ic=new d.Vector3;function sc(o,e,t,i={},s={},a=0,n=1/0){e.boundingBox||e.computeBoundingBox(),ki.set(e.boundingBox.min,e.boundingBox.max,t),ki.needsUpdate=!0;const c=o.geometry,h=c.attributes.position,f=c.index,p=e.attributes.position,r=e.index,l=le.getPrimitive(),u=le.getPrimitive();let g=$l,y=ec,m=null,v=null;s&&(m=tc,v=ic);let _=1/0,x=null,w=null;return si.copy(t).invert(),Ct.matrix.copy(si),o.shapecast({boundsTraverseOrder:b=>ki.distanceToBox(b),intersectsBounds:(b,T,S)=>S<_&&S<n?(T&&(Ct.min.copy(b.min),Ct.max.copy(b.max),Ct.needsUpdate=!0),!0):!1,intersectsRange:(b,T)=>{if(e.boundsTree){const S=e.boundsTree;return S.shapecast({boundsTraverseOrder:L=>Ct.distanceToBox(L),intersectsBounds:(L,C,D)=>D<_&&D<n,intersectsRange:(L,C)=>{for(let D=L,R=L+C;D<R;D++){const A=S.resolveTriangleIndex(D);K(u,3*A,r,p),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let M=b,I=b+T;M<I;M++){const P=o.resolveTriangleIndex(M);K(l,3*P,f,h),l.needsUpdate=!0;const E=l.distanceToTriangle(u,g,m);if(E<_&&(y.copy(g),v&&v.copy(m),_=E,x=M,w=D),E<a)return!0}}}})}else{const S=mt(e);for(let L=0,C=S;L<C;L++){K(u,3*L,r,p),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let D=b,R=b+T;D<R;D++){const A=o.resolveTriangleIndex(D);K(l,3*A,f,h),l.needsUpdate=!0;const M=l.distanceToTriangle(u,g,m);if(M<_&&(y.copy(g),v&&v.copy(m),_=M,x=D,w=L),M<a)return!0}}}}}),le.releasePrimitive(l),le.releasePrimitive(u),_===1/0?null:(i.point?i.point.copy(y):i.point=y.clone(),i.distance=_,i.faceIndex=x,s&&(s.point?s.point.copy(v):s.point=v.clone(),s.point.applyMatrix4(si),y.applyMatrix4(si),s.distance=y.sub(s.point).length(),s.faceIndex=w),i)}function rc(){return typeof SharedArrayBuffer<"u"}const Ft=new q.constructor,hi=new q.constructor,Le=new ms(()=>new d.Box3),it=new d.Box3,st=new d.Box3,Oi=new d.Box3,zi=new d.Box3;let Vi=!1;function nc(o,e,t,i){if(Vi)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Vi=!0;const s=o._roots,a=e._roots;let n,c=0,h=0;const f=new d.Matrix4().copy(t).invert();for(let p=0,r=s.length;p<r;p++){Ft.setBuffer(s[p]),h=0;const l=Le.getPrimitive();Y(0,Ft.float32Array,l),l.applyMatrix4(f);for(let u=0,g=a.length;u<g&&(hi.setBuffer(a[p]),n=ue(0,0,t,f,i,c,h,0,0,l),hi.clearBuffer(),h+=a[u].length,!n);u++);if(Le.releasePrimitive(l),Ft.clearBuffer(),c+=s[p].length,n)break}return Vi=!1,n}function ue(o,e,t,i,s,a=0,n=0,c=0,h=0,f=null,p=!1){let r,l;p?(r=hi,l=Ft):(r=Ft,l=hi);const u=r.float32Array,g=r.uint32Array,y=r.uint16Array,m=l.float32Array,v=l.uint32Array,_=l.uint16Array,x=o*2,w=e*2,b=ee(x,y),T=ee(w,_);let S=!1;if(T&&b)p?S=s(se(e,v),ne(e*2,_),se(o,g),ne(o*2,y),h,n+e,c,a+o):S=s(se(o,g),ne(o*2,y),se(e,v),ne(e*2,_),c,a+o,h,n+e);else if(T){const L=Le.getPrimitive();Y(e,m,L),L.applyMatrix4(t);const C=oe(o),D=ae(o,g);Y(C,u,it),Y(D,u,st);const R=L.intersectsBox(it),A=L.intersectsBox(st);S=R&&ue(e,C,i,t,s,n,a,h,c+1,L,!p)||A&&ue(e,D,i,t,s,n,a,h,c+1,L,!p),Le.releasePrimitive(L)}else{const L=oe(e),C=ae(e,v);Y(L,m,Oi),Y(C,m,zi);const D=f.intersectsBox(Oi),R=f.intersectsBox(zi);if(D&&R)S=ue(o,L,t,i,s,a,n,c,h+1,f,p)||ue(o,C,t,i,s,a,n,c,h+1,f,p);else if(D)if(b)S=ue(o,L,t,i,s,a,n,c,h+1,f,p);else{const A=Le.getPrimitive();A.copy(Oi).applyMatrix4(t);const M=oe(o),I=ae(o,g);Y(M,u,it),Y(I,u,st);const P=A.intersectsBox(it),E=A.intersectsBox(st);S=P&&ue(L,M,i,t,s,n,a,h,c+1,A,!p)||E&&ue(L,I,i,t,s,n,a,h,c+1,A,!p),Le.releasePrimitive(A)}else if(R)if(b)S=ue(o,C,t,i,s,a,n,c,h+1,f,p);else{const A=Le.getPrimitive();A.copy(zi).applyMatrix4(t);const M=oe(o),I=ae(o,g);Y(M,u,it),Y(I,u,st);const P=A.intersectsBox(it),E=A.intersectsBox(st);S=P&&ue(C,M,i,t,s,n,a,h,c+1,A,!p)||E&&ue(C,I,i,t,s,n,a,h,c+1,A,!p),Le.releasePrimitive(A)}}return S}const ri=new Z,hr=new d.Box3,oc={strategy:Hr,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0};class gs{static serialize(e,t={}){t={cloneBuffers:!0,...t};const i=e.geometry,s=e._roots,a=e._indirectBuffer,n=i.getIndex();let c;return t.cloneBuffers?c={roots:s.map(h=>h.slice()),index:n?n.array.slice():null,indirectBuffer:a?a.slice():null}:c={roots:s,index:n?n.array:null,indirectBuffer:a},c}static deserialize(e,t,i={}){i={setIndex:!0,indirect:!!e.indirectBuffer,...i};const{index:s,roots:a,indirectBuffer:n}=e,c=new gs(t,{...i,[Ii]:!0});if(c._roots=a,c._indirectBuffer=n||null,i.setIndex){const h=t.getIndex();if(h===null){const f=new d.BufferAttribute(e.index,1,!1);t.setIndex(f)}else h.array!==s&&(h.array.set(s),h.needsUpdate=!0)}return c}get indirect(){return!!this._indirectBuffer}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t=Object.assign({...oc,[Ii]:!1},t),t.useSharedArrayBuffer&&!rc())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[Ii]||(bl(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new d.Box3))),this.resolveTriangleIndex=t.indirect?i=>this._indirectBuffer[i]:i=>i}refit(e=null){return(this.indirect?Yl:Bl)(this,e)}traverse(e,t=0){const i=this._roots[t],s=new Uint32Array(i),a=new Uint16Array(i);n(0);function n(c,h=0){const f=c*2,p=a[f+15]===pi;if(p){const r=s[c+6],l=a[f+14];e(h,p,new Float32Array(i,c*4,6),r,l)}else{const r=c+Pt/4,l=s[c+6],u=s[c+7];e(h,p,new Float32Array(i,c*4,6),u)||(n(r,h+1),n(l,h+1))}}}raycast(e,t=d.FrontSide,i=0,s=1/0){const a=this._roots,n=this.geometry,c=[],h=t.isMaterial,f=Array.isArray(t),p=n.groups,r=h?t.side:t,l=this.indirect?Kl:Vl;for(let u=0,g=a.length;u<g;u++){const y=f?t[p[u].materialIndex].side:r,m=c.length;if(l(this,u,y,e,c,i,s),f){const v=p[u].materialIndex;for(let _=m,x=c.length;_<x;_++)c[_].face.materialIndex=v}}return c}raycastFirst(e,t=d.FrontSide,i=0,s=1/0){const a=this._roots,n=this.geometry,c=t.isMaterial,h=Array.isArray(t);let f=null;const p=n.groups,r=c?t.side:t,l=this.indirect?Zl:Wl;for(let u=0,g=a.length;u<g;u++){const y=h?t[p[u].materialIndex].side:r,m=l(this,u,y,e,i,s);m!=null&&(f==null||m.distance<f.distance)&&(f=m,h&&(m.face.materialIndex=p[u].materialIndex))}return f}intersectsGeometry(e,t){let i=!1;const s=this._roots,a=this.indirect?Jl:Hl;for(let n=0,c=s.length;n<c&&(i=a(this,n,e,t),!i);n++);return i}shapecast(e){const t=le.getPrimitive(),i=this.indirect?zl:El;let{boundsTraverseOrder:s,intersectsBounds:a,intersectsRange:n,intersectsTriangle:c}=e;if(n&&c){const r=n;n=(l,u,g,y,m)=>r(l,u,g,y,m)?!0:i(l,u,this,c,g,y,t)}else n||(c?n=(r,l,u,g)=>i(r,l,this,c,u,g,t):n=(r,l,u)=>u);let h=!1,f=0;const p=this._roots;for(let r=0,l=p.length;r<l;r++){const u=p[r];if(h=Rl(this,r,a,n,s,f),h)break;f+=u.byteLength}return le.releasePrimitive(t),h}bvhcast(e,t,i){let{intersectsRanges:s,intersectsTriangles:a}=i;const n=le.getPrimitive(),c=this.geometry.index,h=this.geometry.attributes.position,f=this.indirect?g=>{const y=this.resolveTriangleIndex(g);K(n,y*3,c,h)}:g=>{K(n,g*3,c,h)},p=le.getPrimitive(),r=e.geometry.index,l=e.geometry.attributes.position,u=e.indirect?g=>{const y=e.resolveTriangleIndex(g);K(p,y*3,r,l)}:g=>{K(p,g*3,r,l)};if(a){const g=(y,m,v,_,x,w,b,T)=>{for(let S=v,L=v+_;S<L;S++){u(S),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let C=y,D=y+m;C<D;C++)if(f(C),n.needsUpdate=!0,a(n,p,C,S,x,w,b,T))return!0}return!1};if(s){const y=s;s=function(m,v,_,x,w,b,T,S){return y(m,v,_,x,w,b,T,S)?!0:g(m,v,_,x,w,b,T,S)}}else s=g}return nc(this,e,t,s)}intersectsBox(e,t){return ri.set(e.min,e.max,t),ri.needsUpdate=!0,this.shapecast({intersectsBounds:i=>ri.intersectsBox(i),intersectsTriangle:i=>ri.intersectsTriangle(i)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,i={},s={},a=0,n=1/0){return(this.indirect?sc:Ql)(this,e,t,i,s,a,n)}closestPointToPoint(e,t={},i=0,s=1/0){return Ll(this,e,t,i,s)}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(i=>{Y(0,new Float32Array(i),hr),e.union(hr)}),e}}class ac{constructor(e){this.name="WorkerBase",this.running=!1,this.worker=e,this.worker.onerror=t=>{throw t.message?new Error(`${this.name}: Could not create Web Worker with error "${t.message}"`):new Error(`${this.name}: Could not create Web Worker.`)}}runTask(){}generate(...e){if(this.running)throw new Error("GenerateMeshBVHWorker: Already running job.");if(this.worker===null)throw new Error("GenerateMeshBVHWorker: Worker has been disposed.");this.running=!0;const t=this.runTask(this.worker,...e);return t.finally(()=>{this.running=!1}),t}dispose(){this.worker.terminate(),this.worker=null}}class lc extends ac{constructor(e){const t=new Worker(e||new URL("data:text/javascript;base64,aW1wb3J0IHsKCUJ1ZmZlckdlb21ldHJ5LAoJQnVmZmVyQXR0cmlidXRlLAp9IGZyb20gJ3RocmVlJzsKaW1wb3J0IHsgTWVzaEJWSCB9IGZyb20gJy4uL2NvcmUvTWVzaEJWSC5qcyc7Cgpvbm1lc3NhZ2UgPSAoIHsgZGF0YSB9ICkgPT4gewoKCWxldCBwcmV2VGltZSA9IHBlcmZvcm1hbmNlLm5vdygpOwoJZnVuY3Rpb24gb25Qcm9ncmVzc0NhbGxiYWNrKCBwcm9ncmVzcyApIHsKCgkJLy8gYWNjb3VudCBmb3IgZXJyb3IKCQlwcm9ncmVzcyA9IE1hdGgubWluKCBwcm9ncmVzcywgMSApOwoKCQljb25zdCBjdXJyVGltZSA9IHBlcmZvcm1hbmNlLm5vdygpOwoJCWlmICggY3VyclRpbWUgLSBwcmV2VGltZSA+PSAxMCAmJiBwcm9ncmVzcyAhPT0gMS4wICkgewoKCQkJcG9zdE1lc3NhZ2UoIHsKCgkJCQllcnJvcjogbnVsbCwKCQkJCXNlcmlhbGl6ZWQ6IG51bGwsCgkJCQlwb3NpdGlvbjogbnVsbCwKCQkJCXByb2dyZXNzLAoKCQkJfSApOwoJCQlwcmV2VGltZSA9IGN1cnJUaW1lOwoKCQl9CgoJfQoKCWNvbnN0IHsgaW5kZXgsIHBvc2l0aW9uLCBvcHRpb25zIH0gPSBkYXRhOwoJdHJ5IHsKCgkJY29uc3QgZ2VvbWV0cnkgPSBuZXcgQnVmZmVyR2VvbWV0cnkoKTsKCQlnZW9tZXRyeS5zZXRBdHRyaWJ1dGUoICdwb3NpdGlvbicsIG5ldyBCdWZmZXJBdHRyaWJ1dGUoIHBvc2l0aW9uLCAzLCBmYWxzZSApICk7CgkJaWYgKCBpbmRleCApIHsKCgkJCWdlb21ldHJ5LnNldEluZGV4KCBuZXcgQnVmZmVyQXR0cmlidXRlKCBpbmRleCwgMSwgZmFsc2UgKSApOwoKCQl9CgoJCWlmICggb3B0aW9ucy5pbmNsdWRlZFByb2dyZXNzQ2FsbGJhY2sgKSB7CgoJCQlvcHRpb25zLm9uUHJvZ3Jlc3MgPSBvblByb2dyZXNzQ2FsbGJhY2s7CgoJCX0KCgkJaWYgKCBvcHRpb25zLmdyb3VwcyApIHsKCgkJCWNvbnN0IGdyb3VwcyA9IG9wdGlvbnMuZ3JvdXBzOwoJCQlmb3IgKCBjb25zdCBpIGluIGdyb3VwcyApIHsKCgkJCQljb25zdCBncm91cCA9IGdyb3Vwc1sgaSBdOwoJCQkJZ2VvbWV0cnkuYWRkR3JvdXAoIGdyb3VwLnN0YXJ0LCBncm91cC5jb3VudCwgZ3JvdXAubWF0ZXJpYWxJbmRleCApOwoKCQkJfQoKCQl9CgoJCWNvbnN0IGJ2aCA9IG5ldyBNZXNoQlZIKCBnZW9tZXRyeSwgb3B0aW9ucyApOwoJCWNvbnN0IHNlcmlhbGl6ZWQgPSBNZXNoQlZILnNlcmlhbGl6ZSggYnZoLCB7IGNvcHlJbmRleEJ1ZmZlcjogZmFsc2UgfSApOwoJCWxldCB0b1RyYW5zZmVyID0gWyBwb3NpdGlvbi5idWZmZXIsIC4uLnNlcmlhbGl6ZWQucm9vdHMgXTsKCQlpZiAoIHNlcmlhbGl6ZWQuaW5kZXggKSB7CgoJCQl0b1RyYW5zZmVyLnB1c2goIHNlcmlhbGl6ZWQuaW5kZXguYnVmZmVyICk7CgoJCX0KCgkJdG9UcmFuc2ZlciA9IHRvVHJhbnNmZXIuZmlsdGVyKCB2ID0+ICggdHlwZW9mIFNoYXJlZEFycmF5QnVmZmVyID09PSAndW5kZWZpbmVkJyApIHx8ICEgKCB2IGluc3RhbmNlb2YgU2hhcmVkQXJyYXlCdWZmZXIgKSApOwoKCQlpZiAoIGJ2aC5faW5kaXJlY3RCdWZmZXIgKSB7CgoJCQl0b1RyYW5zZmVyLnB1c2goIHNlcmlhbGl6ZWQuaW5kaXJlY3RCdWZmZXIuYnVmZmVyICk7CgoJCX0KCgkJcG9zdE1lc3NhZ2UoIHsKCgkJCWVycm9yOiBudWxsLAoJCQlzZXJpYWxpemVkLAoJCQlwb3NpdGlvbiwKCQkJcHJvZ3Jlc3M6IDEsCgoJCX0sIHRvVHJhbnNmZXIgKTsKCgl9IGNhdGNoICggZXJyb3IgKSB7CgoJCXBvc3RNZXNzYWdlKCB7CgoJCQllcnJvciwKCQkJc2VyaWFsaXplZDogbnVsbCwKCQkJcG9zaXRpb246IG51bGwsCgkJCXByb2dyZXNzOiAxLAoKCQl9ICk7CgoJfQoKfTsK",typeof document>"u"?require("url").pathToFileURL(__filename).href:ft&&ft.src||new URL("shop-components.cjs",document.baseURI).href),{type:"module"});super(t),this.name="GenerateMeshBVHWorker"}runTask(e,t,i={}){return new Promise((s,a)=>{if(t.getAttribute("position").isInterleavedBufferAttribute||t.index&&t.index.isInterleavedBufferAttribute)throw new Error("GenerateMeshBVHWorker: InterleavedBufferAttribute are not supported for the geometry attributes.");e.onerror=f=>{a(new Error(`GenerateMeshBVHWorker: ${f.message}`))},e.onmessage=f=>{const{data:p}=f;if(p.error)a(new Error(p.error)),e.onmessage=null;else if(p.serialized){const{serialized:r,position:l}=p,u=gs.deserialize(r,t,{setIndex:!1}),g=Object.assign({setBoundingBox:!0},i);if(t.attributes.position.array=l,r.index)if(t.index)t.index.array=r.index;else{const y=new d.BufferAttribute(r.index,1,!1);t.setIndex(y)}g.setBoundingBox&&(t.boundingBox=u.getBoundingBox(new d.Box3)),i.onProgress&&i.onProgress(p.progress),s(u),e.onmessage=null}else i.onProgress&&i.onProgress(p.progress)};const n=t.index?t.index.array:null,c=t.attributes.position.array,h=[c];n&&h.push(n),e.postMessage({index:n,position:c,options:{...i,onProgress:null,includedProgressCallback:!!i.onProgress,groups:[...t.groups]}},h.map(f=>f.buffer).filter(f=>typeof SharedArrayBuffer>"u"||!(f instanceof SharedArrayBuffer)))})}}class cc{constructor(e,t){this.lock=!1,this.lockX=!1,this.lockY=!1,this.invRotMat=new d.Matrix4,this.mouse=new d.Vector3,this.rotateStart=new d.Vector2,this.rotateEnd=new d.Vector2,this.rotateDelta=new d.Vector2,this.selectedAxis=null,this.isDragging=!1,this.context=null,this.orbitState=!0,this._animator=0,this._emitter=new pt,this.addListener=this._emitter.addListener.bind(this._emitter),this.removeAllListeners=this._emitter.removeAllListeners.bind(this._emitter),this._text=document.createElement("div"),this._textTimer=0,this._update=()=>{this.lock||(this._textTimer&&(window.clearTimeout(this._textTimer),this._textTimer=0),this._textTimer=window.setTimeout(()=>{this._text.style.opacity="0"},800),this.camera.updateMatrix(),this.invRotMat.extractRotation(this.camera.matrix).invert(),this.axes.forEach(s=>{this.setAxisPosition(s)}),this.axes.sort((s,a)=>s.position.z>a.position.z?1:-1),this.drawLayers(!0),this._text.style.opacity="1",this._text.innerText=this.camera.position.distanceTo(this.orbit.target).toFixed(2)+" m")},this.updateMouseFromEvent=s=>{this.rect=this.domElement.getBoundingClientRect();const a=this.domElement.width/this.domElement.clientWidth,n=this.domElement.height/this.domElement.clientHeight,{left:c,top:h}=this.rect;this.mouse.set((s.clientX-c)*a,(s.clientY-h)*n,0)},this.updateSelectedAxisUnderMouse=()=>{this.selectedAxis=null,this.axes.forEach(s=>{this.mouse.distanceTo(s.position)<s.size&&(this.selectedAxis=s)})},this.onPointerDown=s=>{this.rotateStart.set(s.clientX,s.clientY),this.updateMouseFromEvent(s),this.updateSelectedAxisUnderMouse(),this.orbitState=this.orbit.enabled,this.orbit.enabled=!1,window.addEventListener("pointermove",this.onDrag,!1),window.addEventListener("pointerup",this.onPointerUp,!1)},this.onPointerUp=()=>{this.domElement.style.backgroundColor="#FFF0",setTimeout(()=>this.isDragging=!1,0),this.domElement.classList.remove("dragging"),this.orbit.enabled=this.orbitState,window.removeEventListener("pointermove",this.onDrag,!1),window.removeEventListener("pointerup",this.onPointerUp,!1)},this.onPointerEnter=()=>{this.domElement.style.backgroundColor="#FFF3",this.rect=this.domElement.getBoundingClientRect()},this.onPointerMove=s=>{if(this.lock||this.isDragging)return;const a=this.selectedAxis;s&&(this.updateMouseFromEvent(s),this.updateSelectedAxisUnderMouse()),a!==this.selectedAxis&&this.drawLayers()},this.onDrag=s=>{this.lock||(this.isDragging||this.domElement.classList.add("dragging"),this.isDragging=!0,this.selectedAxis=null,this.rotateEnd.set(s.clientX,s.clientY),this.rotateDelta.subVectors(this.rotateEnd,this.rotateStart).multiplyScalar(.5),this.rotateStart.copy(this.rotateEnd),this.orbit.update())},this.onMouseClick=s=>{if(this.lock||(this.updateMouseFromEvent(s),this.updateSelectedAxisUnderMouse(),this.isDragging||!this.selectedAxis))return;this._animator&&cancelAnimationFrame(this._animator);const a=this.selectedAxis.direction.clone();this.camera.lookAt(0,0,0);const n=this.camera.position.distanceTo(this.orbit.target);a.multiplyScalar(n),this.selectedAxis.axis==="z"?a.setZ(this.orbit.target.z+n):this.selectedAxis.axis==="-z"?a.setZ(this.orbit.target.z-n):a.setZ(this.orbit.target.z);const c=500,h=performance.now(),f=1,p=this.selectedAxis.axis,r=()=>{const u=performance.now()-h,g=Math.min(u/c,f);if(this.camera.position.lerp(a,g),this.orbit.update(),g!==f){this._animator=window.requestAnimationFrame(r);return}else this._animator=0,this.onPointerMove(void 0),this._emitter.emit("axis-select-end",p);this.onPointerMove(void 0)};this._emitter.emit("axis-select-start",p),r()},this.drawCircle=(s,a=10,n="#FF0000")=>{this.context&&(this.context.beginPath(),this.context.rect(s.x-a,s.y-a,a*2,a*2),this.context.fillStyle=n,this.context.fill(),this.context.closePath())},this.drawLine=(s,a,n=1,c="#FF0000")=>{this.context&&(this.context.beginPath(),this.context.moveTo(s.x,s.y),this.context.lineTo(a.x,a.y),this.context.lineWidth=n,this.context.strokeStyle=c,this.context.stroke(),this.context.closePath())},this.drawLayers=(s=!1)=>{this.context&&(s&&this.context.clearRect(0,0,this.domElement.width,this.domElement.height),this.axes.forEach(a=>{const n=this.selectedAxis===a,c=a.position.z>=-.01?a.color[0]:a.color[1];if(a.line&&this.drawLine(this.center,a.position,a.line,c),this.drawCircle(a.position,a.size,n?"#0066ff":c),a.label){const h=a.axis==="-x"?this.options.fontSize-3:this.options.fontSize;this.context.font=[this.options.fontWeight,h+"px",this.options.fontFamily].join(" "),this.context.fillStyle=this.options.fontColor,this.context.textBaseline="middle",this.context.textAlign="center",this.context.fillText(a.label,a.position.x,a.position.y)}}))},this.setAxisPosition=s=>{const a=s.direction.clone().applyMatrix4(this.invRotMat),n=s.size;s.position.set(a.x*(this.center.x-n/2-this.options.padding)+this.center.x,this.center.y-a.y*(this.center.y-n/2-this.options.padding),a.z)};const i={offset:new d.Vector2,size:90,padding:8,bubbleSizePrimary:8,bubbleSizeSecondary:6,lineWidth:2,fontSize:11,fontFamily:"arial",fontWeight:"normal",fontColor:"#fff",className:"orbit-controls-gizmo",colors:{x:["#f35f5f","#902525"],y:["#78da2f","#71ae45"],z:["#1d92fa","#d0d1d1"]}};this.options={...i,...t},this.orbit=e,this.camera=e.object,this.center=new d.Vector3(this.options.size/2,this.options.size/2,0),this.axes=this.createAxes(),this.domElement=this.createCanvas(this.options),this.orbit.addEventListener("change",this._update),this._text.style.cssText=`
3731
+ `,this._needsRender=!1}handleShadowClick(e){const t=e.target;if(!t)return;t.closest(".info")&&(e.preventDefault(),e.stopPropagation());const i=t.closest("[data-action]");if(!i)return;const s=i.getAttribute("data-action");if(s)switch(e.preventDefault(),e.stopPropagation(),s){case"remove-device":this.removeDevice();break;case"remove-function":{const r=i.getAttribute("data-function");r&&this.dispatchEvent(new CustomEvent("function-removed",{detail:r}));break}case"toggle-dialog":if(!this.hasMoreFunctions)return;this._showDialog=!this._showDialog,this.scheduleRender();break;case"add-function":{const r=i.getAttribute("data-function");r&&(this.dispatchEvent(new CustomEvent("function-added",{detail:r})),this._showDialog=!1,this.scheduleRender());break}}}}customElements.get("slot-item")||customElements.define("slot-item",nn);const J={ON_DROP:"slot-on-drop",ON_DEVICE_DELETED:"slot-on-device-deleted",ON_DEVICE_REPLACED:"slot-on-device-replaced",ON_BEFORE_SELECTED:"slot-on-before-selected",ON_SELECTED:"slot-on-selected",ON_ADD_BUTTON_CLICKED:"slot-add-button-clicked",ON_DEVICE_SELECTED:"slot-on-device-selected",ON_DROP_ERROR:"slot-on-drop-error",ON_ERROR_STATE_CHANGE:"slot-on-error-state-change",ON_FUNCTION_REMOVED:"slot-on-function-removed",ON_FUNCTION_ADDED:"slot-on-function-added"};class as extends be.CSS2DObject{constructor(e){const t=document.createElement("div");super(t),this.props=e,this._emitter=new Ye,this._slotContainer=new f.Group,this._bracketSlots=[],this._hasError=!1,this.useBracket=!1,this.addEventListener=this._emitter.addListener.bind(this._emitter),this.removeEventListener=this._emitter.removeListener.bind(this._emitter),this._canInstall=!1,this._loading=!1,this._selected=!1,this._deviceSelected=!1,this._focused=!1,this._toBeInstalled=!1,this._toBeReplaced=!1,this._allFunctions=new Set,this._functions=new Set,this._timer=0,this._parentPos=new f.Vector3,this._wrapper=new f.Group,this._showSlot=!0,this._isMirror=!1,this.beforeInstall=void 0,this._preventDefaults=i=>{i.preventDefault(),i.stopPropagation()},this.getWP=this._slotContainer.getWorldPosition.bind(this._slotContainer),t.setAttribute("data-ui-type","slot"),this._showSlot=typeof e.show=="boolean"?e.show:!0,this.name=e.name,this._isMirror=e.isMirror,this._slotUI=new nn({name:e.name,isMobile:e.isMobile,onRemove:()=>{this.clearSlot()}}),this._slotUI.slot=this,this._slotUI.hide=!this._showSlot||this.isMirror,t.append(this._slotUI),this._parentPos.copy(this.props.slot.position),this._slotUI.addEventListener("function-removed",({detail:i})=>{this.removeFunction(i)}),this._slotUI.addEventListener("function-added",({detail:i})=>{this.addFunction(i)}),this.add(this._slotContainer),this.props.slot.add(this),setTimeout(()=>{var i;(i=this.props.slot.parent)==null||i.add(this._wrapper),this._wrapper.add(this.props.slot)},10),["dragenter","dragover","dragleave","drop"].forEach(i=>{t.addEventListener(i,this._preventDefaults,!1)}),t.addEventListener("click",i=>{i.preventDefault(),i.stopPropagation(),this.toBeInstalled?this._emitter.emit(J.ON_ADD_BUTTON_CLICKED):this.selected=!this.selected}),t.addEventListener("dragover",i=>{if(i.preventDefault(),i.dataTransfer.dropEffect="copy",!this._canInstall){i.dataTransfer&&(i.dataTransfer.dropEffect="none");return}}),t.addEventListener("drop",async i=>{var r;if(i.preventDefault(),i.stopPropagation(),!this._canInstall)return;const s=(r=i.dataTransfer)==null?void 0:r.getData("application/json");if(s){const o=JSON.parse(s);try{await this.install(o),this._emitter.emit(J.ON_DROP,this)}catch(c){this._emitter.emit(J.ON_DROP_ERROR,c)}}else this._emitter.emit(J.ON_DROP_ERROR,new Error("No device info"))})}get hasDevice(){return this._slotContainer.children.length>0}get isMirror(){return this._isMirror}shapeKeyChanged(e,t){if(this.props.follows.has(e)){const i=this.props.follows.get(e);if(i){let s="x";["height","mast"].includes(e)?s="z":["width","liftOuterWidth"].includes(e)&&(s="y");const r=i.initPos[s]>0?1:-1;this._wrapper.position[s]=(t-i.origin)*i.scale*r}}}async loadGlb(e){const i=await new Ut({useCache:!0}).loadAsync(e);if(i.glb)return i.glb.clone(!0)}async installBracket(e){const i=await new Ut({useCache:!0}).loadAsync(e);if(!i.glb)return;const s=i.glb.clone(!0);s.traverse(r=>{r.userData.isBracket=!0}),this.useBracket=!0,this._slotContainer.add(s)}async install(e){var t;if(!this._loading){this._loading=!0,this.beforeInstall&&typeof this.beforeInstall=="function"&&await((t=this.beforeInstall)==null?void 0:t.call(this,e));try{const i=await this.loadGlb(e.url);if(!i)throw new Error(`Fail to load device from: ${e.url}`);if(i.traverse(s=>{s.userData.isDevice=!0}),this.isMirror&&i.scale.set(1,1,-1),e.bracketUrl){const s=await this.loadGlb(e.bracketUrl);if(s)this.clearSlot(),s.traverse(r=>{r.name.startsWith("Slot")&&this._bracketSlots.push(r),r.userData.isBracket=!0}),this._slotContainer.add(s);else throw new Error(`Fail to load bracket from: ${e.bracketUrl}`);this._bracketSlots.forEach(r=>{r.add(i)})}else this.clearSlot(),this._slotContainer.add(i);this.mirrorTarget&&this.mirrorTarget.install(e),this.deviceInfo=e,this._currentDeivceLoaded=i,this._slotUI.deviceLogo=e.logo||"",this._slotUI.deviceName=e.name,this._slotUI.filled=!0,this.holeTarget&&(this.holeTarget.visible=!1),this._emitter.emit(J.ON_DEVICE_REPLACED,i)}catch(i){throw i}finally{this._loading=!1}}}get device(){return this._slotContainer.children.length?this._slotContainer.children[0]:null}get allFunctions(){return[...this._allFunctions]}set allFunctions(e){this._functions.forEach(t=>{e.includes(t)||this._functions.delete(t)}),this._allFunctions=new Set(e),this._slotUI.allFunctions=e}get functions(){return[...this._functions]}addFunction(e){this._allFunctions.has(e)&&(this._functions.add(e),this._slotUI.functions=[...this.functions],this._emitter.emit(J.ON_FUNCTION_ADDED,e))}removeFunction(e){this._functions.has(e)&&(this._functions.delete(e),this._slotUI.functions=[...this.functions],this._emitter.emit(J.ON_FUNCTION_REMOVED,e))}clearFunctions(){this._functions.forEach(e=>this.removeFunction(e))}addFunctions(e){e.forEach(t=>this.addFunction(t)),this._slotUI.functions=this.functions}changeName(e){var t;this.name=e,this.props.slot.userData.name=e,this.props.name=e,(t=this.element)==null||t.setAttribute("data-name",this.props.name)}clearSlot(){this._emitter.emit(J.ON_DEVICE_DELETED,this._currentDeivceLoaded),this._bracketSlots=[],this._slotContainer.children.forEach(e=>{e.removeFromParent(),De(e)}),this._slotUI.filled=!1,this.deviceInfo=void 0,this._currentDeivceLoaded=void 0,this._slotUI.deviceName="",this._slotUI.deviceLogo="",this.holeTarget&&(this.holeTarget.visible=!0),this.mirrorTarget&&this.mirrorTarget.clearSlot()}get disabled(){return this._slotUI.disable}enable(){this.show(),this._slotUI.disable=!1}disable(){this._slotUI.disable=!0,this.hide()}hide(){this._slotUI.hide=!0}show(){this.isMirror||this.disabled||(this._slotUI.hide=!1)}get selected(){return this._selected}get focused(){return this._focused}set focused(e){this._focused=e,this._slotUI.focused=e}get toBeInstalled(){return this._toBeInstalled}set toBeInstalled(e){this._toBeInstalled=e,this._slotUI.toBeInstalled=e}get toBeReplaced(){return this._toBeReplaced}set toBeReplaced(e){this._toBeReplaced=e,this._slotUI.toBeReplaced=e}set selected(e){this.disabled||(e&&this._emitter.emit(J.ON_BEFORE_SELECTED,e),this._selected=e,this._slotUI.selected=e,this._emitter.emit(J.ON_SELECTED,e),this.element.style.zIndex="100",this.selected?this.renderOrder=1/0:this.renderOrder=1)}get deviceSelected(){return this._deviceSelected}set deviceSelected(e){this._deviceSelected=e,this._emitter.emit(J.ON_DEVICE_SELECTED,e)}get error(){return this._hasError}set error(e){this._loading&&setTimeout(()=>{this.error=e},100),this._hasError=e,this._slotUI.hasError=e,this._emitter.emit(J.ON_ERROR_STATE_CHANGE,e)}getCanInstall(){return this._canInstall}canInstall(e){this._canInstall=e,this._slotUI.canInstall=e}dispose(){cancelAnimationFrame(this._timer),["dragenter","dragover","dragleave","drop"].forEach(e=>{this.element.addEventListener(e,this._preventDefaults,!1)}),this.props.follows.clear(),this.clearSlot(),this._emitter.removeAllListeners(),De(this._slotContainer),this.element.remove()}render(e){const t=this.element.style.transform,i=/translate\(-?\d*\.?\d*%?,?\s-?\d*\.?\d*%?\)\s*translate\((-?\d*\.?\d*)px,\s*(-?\d*\.?\d*)px\)/.exec(t);if(!i)return;const s=new f.Vector2(parseFloat(i[1]),parseFloat(i[2])),r=e.mousePos.distanceTo(s);let o=this.props.isMobile?12:18,c=38,h=30;if(this._canInstall&&(o=34,c=60,h=60),r<h){let u=(h-r)*1+o;r<20&&(u=c),u>c&&(u=c),this._slotUI.setSize(u)}else this._slotUI.setSize(o)}clone(e){return new f.Group}}class dl extends be.CSS2DObject{constructor(e){const t=document.createElement("div");super(t),this._text=document.createElement("div");const i=Cs(),s=i?"#ddd":"#eee";this.element.style.pointerEvents="auto",this.element.style.padding=i?"2px 6px":"3px 12px",this.element.style.borderTop=`1px solid ${s}`,this.element.style.borderBottom=this.element.style.borderTop;const r="6px",o=document.createElement("div");o.style.pointerEvents="none",Object.assign(o.style,{pointerEvents:"none",borderLeft:`1px solid ${s}`,borderRight:`1px solid ${s}`,position:"absolute",left:"0",top:"0",boxSizing:"border-box",height:r,width:"100%"}),this.element.append(o);const c=document.createElement("div");c.style.pointerEvents="none",Object.assign(c.style,{pointerEvents:"none",borderLeft:`1px solid ${s}`,borderRight:`1px solid ${s}`,position:"absolute",left:"0",bottom:"0",boxSizing:"border-box",height:r,width:"100%"}),this.element.append(c),this._text.style.fontSize=i?"10px":"14px",this._text.style.font="SF Pro SC,SF Pro Text,SF Pro Icons,PingFang SC,Helvetica Neue,Helvetica,Arial,sans-serif",this._text.style.color="#fff",this._text.style.fontWeight="500",this._text.style.transition="all .16s",this._text.innerText=e,this.element.append(this._text),this._text.addEventListener("pointermove",()=>{var h;o.style.borderColor=c.style.borderColor=this.element.style.borderColor="#666",this._text.style.color="#000",(h=this.onPointMove)==null||h.call(this)}),this._text.addEventListener("pointerleave",()=>{var h;o.style.borderColor=c.style.borderColor=this.element.style.borderColor=s,this._text.style.transform="scale(1)",this._text.style.color="#fff",(h=this.onPointLeave)==null||h.call(this)})}set text(e){this._text.innerText=e}dispose(){this.element&&this.element.parentNode&&this.element.parentNode.removeChild(this.element)}}class vi extends f.Group{constructor(e,t=!0,i=!0){super(),this._startWith=e,this._showText=t,this.useStartEnd=i,this._line2Length=.01,this._line=new f.LineSegments(new f.BufferGeometry,new f.LineBasicMaterial({color:"#666",linewidth:2})),this._line2=new f.LineSegments(new f.BufferGeometry,new f.LineBasicMaterial({color:"#666",linewidth:2})),this._text=new dl(""),this._line.frustumCulled=!1,this.add(this._line,this._line2),this._showText&&(this.add(this._text),this._text.onPointMove=()=>{this._line.material.color.set("#000"),this._line2.material.color.set("#000")},this._text.onPointLeave=()=>{this._line.material.color.set("#666"),this._line2.material.color.set("#666")})}updateMaterial(e){this._line.material=e}reset(){var e,t;(e=this._line.geometry)==null||e.dispose(),this._line.geometry=new f.BufferGeometry().setFromPoints([new f.Vector3,new f.Vector3]),this._line.computeLineDistances(),(t=this._line2.geometry)==null||t.dispose(),this._line2.geometry=new f.BufferGeometry().setFromPoints([new f.Vector3,new f.Vector3]),this._line2.computeLineDistances()}update(e,t,i=0){var d,g;(d=this._line.geometry)==null||d.dispose(),this._line.geometry=new f.BufferGeometry().setFromPoints([e,t]),this._line.computeLineDistances();const s=this._line2Length+i*.02,r=new f.Vector3().subVectors(t,e).normalize();let o;Math.abs(r.z)>Math.abs(r.x)&&Math.abs(r.z)>Math.abs(r.y)?o=new f.Vector3(-r.y,r.x,0):Math.abs(r.y)>Math.abs(r.x)?o=new f.Vector3(1,0,0):o=new f.Vector3(0,1,0),o.length()<.001&&(Math.abs(r.x)<.9?o=new f.Vector3(1,0,0):o=new f.Vector3(0,1,0)),o.normalize();const c=new f.Vector3().addVectors(e,o.clone().multiplyScalar(s)),h=new f.Vector3().addVectors(e,o.clone().multiplyScalar(-s)),u=new f.Vector3().addVectors(t,o.clone().multiplyScalar(s)),p=new f.Vector3().addVectors(t,o.clone().multiplyScalar(-s));(g=this._line2.geometry)==null||g.dispose(),this._line2.geometry=new f.BufferGeometry,this._line2.geometry.setFromPoints([c,h,u,p]),this._line2.computeLineDistances();const n=e.distanceTo(t);this._startWith?this._text.text=`${this._startWith}${(n*1e3).toFixed(0)} mm`:this._text.text=`${(n*1e3).toFixed(0)} mm`;const l=new f.Vector3;l.addVectors(e,t).multiplyScalar(.5),this._text.position.copy(l),this.useStartEnd||(this._line2.visible=!1)}destroy(){this._text.dispose(),this.children.forEach(e=>De(e)),this.removeFromParent()}}class on extends f.Object3D{constructor(e,t){super(),this.radius=e,this._text=new pl(""),this._line=new vi(void 0,!1,!1),this._box=new f.Mesh,this._arc=new Rr.Line2,this._previousPosition=null,this._updateTimer=null,this._updateDelay=300,this._accumulatedAngle=0,this._lastAngle=null,this._line.updateMaterial(new f.LineDashedMaterial({color:"#555",dashSize:.06,gapSize:.06})),this._line.renderOrder=0,this._box.geometry=new f.RingGeometry(e,e+.003,128),this._box.material=new f.MeshBasicMaterial({color:"#666",side:f.DoubleSide}),this._arc.geometry=new $i.LineGeometry,this._arc.geometry.setPositions([0,0,0,0,0,0]),this._arc.geometry.instanceCount=0,this._arc.material=new Er.LineMaterial({color:"#eee",linewidth:2,resolution:new f.Vector2(window.innerWidth,window.innerHeight)}),this._arc.visible=!1,this._arc.rotateX(-Math.PI/2),this.position.y=t,this._arc.position.y=.001,this.add(this._box),this.add(this._arc),this.add(this._line),this.add(this._text)}hide(){this._text.hide(),this._line.visible=!1,this._arc.visible=!1}show(){this._text.show(),this._line.visible=!0}dispose(){this._updateTimer&&(clearTimeout(this._updateTimer),this._updateTimer=null),this._box.geometry&&this._box.geometry.dispose(),this._arc.geometry&&this._arc.geometry.dispose(),this._arc.visible=!1,this._previousPosition=null}update(e){var t;this.radius=e,(t=this._box.geometry)==null||t.dispose(),this._box.geometry=new f.RingGeometry(e,e+.003,128),this._line.updateMaterial(new f.LineDashedMaterial({color:"#555",dashSize:.06*e,gapSize:.06*e})),this._text.update((e*1e3).toFixed(0))}change(e){const t=e.clone();t.setZ(0),t.normalize().multiplyScalar(this.radius),this._text.position.set(t.x,t.y,t.z),this._text.updateColor("#eee"),this._line.update(t,new f.Vector3),this._previousPosition&&this._updateArc(this._previousPosition,t),this._updateTimer&&clearTimeout(this._updateTimer),this._updateTimer=setTimeout(()=>{this._previousPosition=null,this._accumulatedAngle=0,this._lastAngle=null,this._clearArc(),this._updateTimer=null},this._updateDelay),this._previousPosition||(this._previousPosition=t.clone(),this._lastAngle=Math.atan2(t.y,t.x),this._accumulatedAngle=0)}_updateArc(e,t){const i=Math.atan2(t.y,t.x);if(this._lastAngle!==null){let h=i-this._lastAngle;h>Math.PI?h-=2*Math.PI:h<-Math.PI&&(h+=2*Math.PI),this._accumulatedAngle+=h}if(this._lastAngle=i,Math.abs(this._accumulatedAngle)<.01){this._arc.visible=!1;return}const s=Math.atan2(e.y,e.x),r=s+this._accumulatedAngle;let o=.006*this.radius;o<.003&&(o=.003),o>.006&&(o=.006);const c=this._createArcGeometry(s,r,this.radius+o);this._arc.geometry&&this._arc.geometry.dispose(),this._arc.geometry=c,this._arc.visible=!0}_clearArc(){this._text.updateColor(),this._arc.geometry&&(this._arc.geometry.setPositions([0,0,0,0,0,0]),this._arc.geometry.instanceCount=0,this._arc.computeLineDistances()),this._arc.visible=!1}_createArcGeometry(e,t,i){const s=[],r=t-e,o=Math.max(128,Math.floor(Math.abs(r)/(Math.PI/128))),c=r/o;for(let u=0;u<=o;u++){const p=e+u*c,n=Math.cos(p),l=Math.sin(p);s.push(i*n,0,i*l)}const h=new $i.LineGeometry;return h.setPositions(s),h.instanceCount=Math.max(0,s.length/3-1),h}}class pl extends be.CSS2DObject{constructor(e){const t=document.createElement("div");super(t),this._wrapper=document.createElement("div"),this._circle=document.createElement("div");const i=Cs();this._wrapper.style.fontSize=i?"10px":"11px",this._wrapper.style.color="#fff",this._wrapper.style.whiteSpace="nowrap",this._wrapper.style.position="absolute",this._wrapper.style.transform="translateX(-50%)",this._wrapper.style.top="6px",this._wrapper.style.font="SF Pro SC,SF Pro Text,SF Pro Icons,PingFang SC,Helvetica Neue,Helvetica,Arial,sans-serif";const s=this._circle;s.style.position="relative",s.style.zIndex="10",s.style.width=s.style.height="5px",s.style.borderRadius="50%",s.style.background="#666",t.append(this._wrapper,s),this.update(e)}show(){this.element.style.display="block"}hide(){this.element.style.display="none"}update(e){this._wrapper.innerText="旋转半径:"+e+" mm",this.updateColor("#eee")}updateColor(e="#666"){this._circle.style.background=e}}const ml="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADgAAAAUCAYAAADY6P5TAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAEvSURBVFiFzZdbFYMwEEQroRKQgAQkVEIlICEOkFAJlRAJSIgEJNx+sPS0nGxIaOhyv3nM7mTmwOViDHAFesADD+BqrakKQAcMwMQ3AWis9e1C3HLASJoAdNZ6sxG3/MZQMZy1dhWgFbfWRzDGlFjAwFlyyXdh5OD5OIqykBgBy1yiF0aMUQaJugLclOcEoP3nULmFgQgeyCwOoJGBYrijByspDM98ZIszJAt8Ks8dag/VUFYYLtetjHdruRz5JZf8WBg1Ae7KcgOluaSsMAKJwqgJ6Vz2WzcvhZHjVlFh1ESG1DQ67SYtyGs8OwujNpTkUtw4nVtbyLK1XDafF3aKW90Z3EpBbi5lE0u9n3qoNTKk9rHh3heZqqwA8Vw6a11VkVwuPK31HALzb5pfovYC2xSs5LCDIUcAAAAASUVORK5CYII=",gl="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAKCAYAAACngj4SAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAChSURBVDiNrdJbFYMwEIRhJFQCEpCAhEqIhDhBAlKQgAQkIOHrSziHpmkbLvua7P4zO9s0FYUeM0b0NT2nC9FnLQho7wQ9MOwgQ3K4ZPDrrtGmFcKKkL0HTAXXw2HX6HYuFnR/hMWC6ykX+W1AzJqq1abDGguux6LoPK9aUGFOm1Y+F+Bh+7DlsSKehRXgnfdDm5od7GdeN8ADnpuKQ3ldqReHZFd3742nZgAAAABJRU5ErkJggg==",hr="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGwAAABsCAYAAACPZlfNAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAdzSURBVHic7Z3hlZs6EIUvW4E7CB3EHcQdxB08OngugVTg8yrwSQVOKnBSwW4qsFOB3cF9PxhZQsYYjEAS1neOD7ssCwPXMxoNIGWIDJJLAAsASwCfAOTyey6bLOQDABf5qJ9P8vkry48sy05j2+ySzLcBjyC5QiXOV1kuWv+hPxcAvwD8BvCBSsRL6394JDjBSC4ArFEJtG7Y5ILqwp4A/JHlxfyoC04yN/4vh/bEz9Dim9uY+/8O4EfI4nmFZEFyz1veSe5Iri0BXB13Icfekjxaxz6TPMixXXt2fJDM5WLZF+og63MPNi1IbsQGW7zyJYUToXZyEUxP8iLSPUS80hLvdYQTobbWN3fHKvMLGpKrBq/bzla4htC3C8mbutIg3JnkxrddzhCvil4omwbhDqy6IPEisV5xJFn4tsk1rDJI8wtZ+rapN+JV73PzqnuwSk7MtvkQzflabdUxGsMdIGFSnfuZZFPHPxysELjnXDOoFsTbzAJA6dumRiyxSt/2+Ma6Hlvf9lyRb9QumjAwIZKQqOLAznvEEbFUcvFS7VVXWO/WvHsTLYnVnSBEM8JgEqsDlmi7qQ++TWL1xxKtnOqgKvs5J7H6I6KdJxFNsh5FygafxLqOxVgHme6b8QIYkWqcZoW6Mr13vvMXhboi8u56x+a34eXKTWMhXSO3SQirgqZi5WSniSvS1ChyFztUoTCcetjMoNGnHbqjTQqF42P1z4pnd7IwssKUwo8Mq/uIz2eN1NWMg3vzxoUWvu3pihEa+zU/4l3RJhoRC/ZcAkKdxkfnXUC8ggE1L+tWILbartW45o1D5IIpL+tWq43du4C4BQNqXlY82jB67wJmIdhSTG/vl1FXkaP1LiB+wQCA+m5+Ya5/s7b7V5a/J7Eq0cZ/svza+FcrHEZd1ZiJh5kp/q0e1D3tqMMhMA/BgFodt1DrzJD4jyx/TmpVoo3vsqyHxTmFQ2BWHpY3ngP1Pa9h5f1AmItgQC1bXAE6JKpXVn94sSrRxocsl4AW7Iss/0xuTuIRKqfQ7dic2i9gdiHxWlu0V8yi/QLmJRhQc6jlG3T7lYboCRfVji3eoMda+mjeNhEAJ1ku31ANYQekhCNklDafTA87eTEl0YWTLHNTsNSGhYvSZvEGPWDkyY8t1xt2ua/jd0Uyah/jYinBcvt+2OTIBTgAOHi6GJ3wbKeOfkaOn09sRNM4VGcXF8N1P0wiwNmyMx+63x7HV48dnuHqpJ40ZMNbBovmUrAGsRSTjuB2PRefgokhZcPFGCSaK8FaxCqf3ecAW66Cea8juhbNhWCBiaXridRtSD61IZZRzkQbKlhIYok9ut5rCOY9Q3Ml2hDBQhNLbKoJdpBfVr4MMnEh2rOChSiW2KWeCHg3X4wO5h2woaI9I1ioYolt6gHf/RuMOpU/k+pkWVYC+GatXmCkTit1p9hOvL6JLb7JZXky+0LTjn/UgWc9rY+HhexZCuqXIzZmfAzyAdJnROsqWAxiAbUnp9bmmxJn34bdo69oXQSLRSwAt10veqwndqVFtKJh21bBWD2WHotYuo5orDzIymAyxSbuiEZbtDbBqN8hCF4soGbv3lwZbOJh00W0e4LFJhZQG81hY67UHbMIeCRak2AxigXU2q+V/QdF7sWynrSJ1nFdDGJd2y/axXnqikfhx7z+tIjWhdK3/Y+gbqpuu1yM9IU+Nt8EfUQU00ex4YU+84/m6Df55NYNgPdDXhOFb3u7wLZwaGwUXVhUdBSt8G1nV9hlvBTjpKPIFm0eiFb4tq8P7No3ZkA3NJ/hjmiFb7v6QN3Nuh8OjY3VCQffib6HJVrh256+GN5Vdtk4ZwS1xUeIaIVvO/rSy7uMf9rF7mWx0su7jH9SD31E7WWxwfoI5v0eO6QuOiYvmwgOGcGcLkZ6TnSG+kGb7m1Xw05UtnVMoXE8WJ8hYljZjL4mKXsh6HIE85SAjAvHmCqFabKcUeAYk+UYO1ePWqXpqBxBXWx3f0vLyhpL5wd4MYyoNd7bnKzX6IJ+wipkOOXUlJN8M2YMfUxNaSUh+SQHnQFWszLtfGxME2/3whJr+j4t09T2nbHE8jO1vRiSRHtAMGIZBi2M8HhO2aNGskGVYOy8i2VCXQ+bLvsJGNYfci1929OIZeQ+qG/UREjE2QcvlsIKA0cGMjrBFFjt1ZGx3EcUww/Gt2w7Z2+T890Z5/seZQJmhcjjHBMSVuW6o3GepW+bBsHqfo/pbYc5hMkGrzpG6VX3YPWWyTl24e4IVfi2axRYZVBm+h+NcKxGHdhZtm9n5VX3EOHKBo8rGVByIt5UUFdzKDbvXkIomzvCKfE2PsQzRDpYNh1lfT61TcEhwq3lItniHSX0FGMIKAKtxWveecueAbVRmW8DbESUNaopHpe4HbDrhGqU6Q9UMyao309qgyzLTsa+7E8O4LMsm/YPVPOo/QTwI8uyoMbzD04wE7ngS/l8AbBC8wUeghL/J4CPLMt+Od6/U4IWrAlpQ5aoPOSTLHNoIRfGzxfoMd9P0J74F5VIlyzLopok6H/tVqA8kSYfTwAAAABJRU5ErkJggg==",_l="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYwAAACsCAYAAABo4pvIAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAzYSURBVHic7d3hcdtIEobhD05gmYGRgbkRLDKwMjiGoBCUgeoi0F0Evo1AdASiIxAcgbkR9P1Aj9mESIm2QMwAeJ8qlihKomeXwHzsHgCsBBTOzGpJK7+pd7/2r3+ceCw69Vh8nkvt/fbW4/H7vaR//H4bfqeNX6uqij8DilPlHgCWxcxW6ibvNFmn+x/DY/Fn0mHyPXVLE7F0ejKOf3/SpRO1B9c55wJNOg6rfrD1/5v7/31pbN97j7WS9lVVnf3vAoZGYGAwPqHW6ia+tbrJce0/Tj+Lk176+k/4/ui2tAnRA/VUaNbqQjXdr8PvtDoOku/xeyoXDIXAwMXMbK1DGHzUcTikiatVN1l9Uy8YmLiG1wuY2r9+0vHrUuvwOux0/PrseF1wKQIDR06EQvw+TTatunexrXgXOwmh+ku31AJc6xAoMUxaESboITAWyoOhVjdhfAr307vQnbpQ2KlrDe2yDBSj8EBJ20S/Qml12B7S/XZp7UIQGLMX3lk2Og6Gnbqd/1u4zySAI+EghRQmH9VtS7W6bWYrKpLFIDBmJFQNf6nbwdOCc6oYvqqrFrY5xof56AXJJ53e3r5J2hIi80FgTFRoIcRwaP32Vb7TUjFgTCdaW426thYhMgMExgT4u7m1Dm2lxn+UqoatCAcUyrffRodqpPEfbcWbm0khMAoUdrBUPTTyUFC3g7UsQmPKvBJpdNzOiq3TLQFSHgKjAKGM/6xDOb+T9Le6d17bXGMDxmJmjY73g1aHRfX/ESD5ERgZhBbTZx2OOCEggOCVAEn7CQEyMgJjJL2Nv9Hxhr/NNS5gKnr7UK0uQNiHMH1mtjKzGzN7MLNnvz34Rg/gHXz/aszs3vetH75/bbyCB8pmZrVvsI/WeTSzWz8/AsCV+L536/vcj7Dv1bnHBvxkZmt/l/MUqogb3uUAefSqjx++X95R3SOLEBK0moDCER4Y3YmQuKfVBEyLh8dd2I8JDwzD+6J3hAQwP2fCo849LkyI9z/TwnVqNxESwIyF8IgL5qxD4jTfYB786KYvZnaTe0wAxudzQTraivVJdE60nDaUpACkn92GuxAed1QdCxSqCY5wAvCm3pFWj8wZM2eHk+p+VhO5xwRgWrzqSCcIPrHWMTMeFGltgmoCwCB6ax33tLMnzM+biG2nOveYAMxPWAulXTU1vUNiuRAZgFGERfJngqNwrE8AKEVoVz0xHxWEoABQqhAczE85ERQApiIEB62qMREUAKaK4BiJH4nwRFAAmDqC40rCeRQEBYBZ8Y5JumZVnXs8k9U7RO0u93gA4Br6cx2nAvyisE5B6gJYBA+OB684uFr2W3rtpzr3eABgbL31jTr3eIoUTq2/yz0WAMjNugsbPpvZbe6xFMOrimfSFACO+fyYzhhvco8nq1BVkKAAcIZXGz/M7D73WEYXqgoWtQHgAr1qo849nlGEvtwm91gAYGoWsbbBEVAAMIxw5YvH2Z23EVpQy+u/AcAV+Hkb9z63rnOPZxBhsWa+5RMAZDKbFlVIvzr3WABgrsbq4ny4xpOm/pqklaQ/q6pqr/HvAAAkn2P/lLSa1FFUIenuco8FAJYmXMiwzj2WVxEWAJBfCI0yF8PN7MYXtze5xwIASxeu+t3kHsuRMLAy0wwAFsjM1kW9kQ9hUeceCwDgWFgq2OQeSPp4wTrrQAAAZ3lo5Ks0QljQhgKAwmVrT1n3iVCEBQBMSAiNcebuUNrwmbMAMDF+ROv11539Ylf5F08AAL8tXH+qvuY/8sgVZwFg+vzkvqdrPfm9mT1e5ckBAKPz604NWwSM1vMCAIxm8HM0wiI3R0QBwMz4kVPDFAS+bjHtD+YAAJzli+DvW3IY5EkAAMV715XGaUUBwHKEOb/+nT/+wudaAMBy+KG2D7/6R42XJ6srjQsAUCCf+y+/kocvdDfXGxIAoETpIysu/eWGhW4AWK6Lz83w6oILCwLAQl1UZaS1i5HGBAAo1JtrGV5dbMYbEgCgRF5lnF6e8EuX/xh5TACAQvUvGfIh/OxW0n/GHhAAoFhbSS/bUp4kzdijAQCU6eS6dvqM7kxjAgAUKhYTqSW1Fu0oAMBLW3UZ0eHMbgDAKUcnc6ejo7huFACgzzPCpK4lVUvaV1W1zzoqAEBxPBt2ZtZ8UNeb2uYdEgCgYK2k9QdJnyR9yzsWAEDBvkr6mFpSbdahAABKtpNXGGtJrF8AAF6zSudhtDlHAQAo2l4hMAAAOGcvaaV0fC0AAOeYmVFhAAAu8kHSPl7vHACAyDOi/aDUmwIA4BUEBgDgLbV0CAwAAM5ZSdp9kJ/Bl3kwAIBy1fI1jO+S/so7FgBAwT5J+pYqjDrvWAAABWvUZUV3QgYfoAQA6IsfspdO3NuKdQwAwEtrSbuqqvYpMP6W9K+MAwIAlOmzuozo+Id8P+cbDwCgRN6OavoPPr94EACwWP1iIl588N+iLQUAOPgs6b8vHjWzmrYUACBJR0el739WGFVVtZJaM9tkGBcAoCCeBbuqqk5fPsrMbqgyAAAXrWv7L21GGREAoDhePDxe8osbqgwAWC4ze7z4qFmqDABYJj+U9u3qIvwBaxkAsDB+3ahfPyfPzB7M7O4qowIAFMfM7szsy+/8Ye3H4NbDDwsAUBIzW79rzve0oTUFADPnC923+Z8EAFAsM7v9pYXuV56o9kUQPi8DAGbm3a2oE0+48dAY5gkBANmFguBm6Ce+N7OnQZ8UAJCNLzncX+vJnzjUFgCmz4uA969bvPIPpPKFRXAAmKiwzLB6+7ff9w9dp+cFALg6v5LHeOfYhVV1jpwCgIkIc3cz9j+8ITQAYBpCWGxyDWAzamkDAPhl4VJPm9wD4RwNAChUWHfe5B6LJNpTAFAib0OVExaJf+hGeQMDgAUKb+TLPKI1pNld7rEAwFKlK40Xv1QQ+mV3uccCAEszmbBIPDSe/FP7rnsmIQAgfbzqg8+9de7x/DK/Vsl0kg4AJih0dq5zIcGx+AdzcP0pALgCn2N/zGaODYvh97SoAGAYs+3ieH/tcbL9NQAoRGhBPcx6PqVFBQC/L1xdYxlzaDiK6nHW6QgAA/F582GWLahLeP9tPos1AHAFYWH7LvdYsvJLilBtAECPVxWPi60qzmFtAwAO/IxtqopzQpo+2tifCAUABVjMEVBDscNnznJpEQCL0FvU3uQez6T4eRvpIlp3BAeAuWKuG0hI3fwfLwgAAwrnVNB+GpIfTcX6BoDJC0HBlS+uieAAMFUhKFinGBPBAWAqCIpChBeC4ABQFIKiUP7CPBEcAHIjKCYitKo4RA3AaPxUgNjx2OQeEy4UguOHB0ede0wA5qd3wt2Dma1zjwm/yV/MdFVc2lUABuFvSh+sw3kUc+Ll4m1Y57ilXQXgV/XXJwiKmeu1q+6pOgC8JlQTqe3U5B4TRmaH61WldhWL5AAk/Wxnx2qCtVB0wjsI1jqABbPuatlfwtpEk3tMKFRY64hHWDW5xwXgesxsHVpOj15Z0G3A5bwkTZcdfiY8gPnwkLin5YTBecuK8AAm7ERI3HPeBK6qFx4caQUUrHeEEyGBfM6FB/1PIA9fh7wJIfFESKA4vuYRF8wf/fs699iAOfNWU9r3LCxc17nHBrzJDhciS4fqplKY6gMYwIlW04NXFuxfV1LlHsBS+BrHWtJnSbWkVtLfknZVVW1zjQuYit4+1Ejain1oVARGBv4OKG74taSd2PiBn3oBsVb3Jmurw36yzzW2pSIwCuABciPpkwgQLNSZgIj7QZtrbOgQGAXyAGkk/aVux1mr23F2kr5J2rLzYMr8iKVah228UVc97CR9VbeNU0EUhsCYgNDCWqvbwRr/0VZdgOzEDoZChe230SEgpMP2uxUtpkkgMCbKDxds1LWxUpjsddgJW1HGY2Qn3tzUOrRYU/XAdjlRBMaMnAkR6bidtZPU8m4O7+VrDisdt06l43Boq6raZRkgBkdgzJyHSOoXx0X1Vl018l2HxUWCBEe8Yqj9tla3DaX7O3XbTmortVQO80ZgLFCYBFKQfAz39+omgr1obS2GL0KndlLaHtJjMRjSGwuqhgUiMHDkREWyCt+3OoRJqkxa8c6yeP66xttH/5pe3/S67tS9tjtJe4IBEYGBi4UwWek4TFLF0uplhbIPj+9peQ0vhMEqfP0Uvq91/Lq0IhTwGwgMDKb3Lnalw7vY9H0tDw4dqhPpUK1IIVy0wIDxduGpWy3pD70MhpWO/1/uJP2jEA5UfxgKgYFRhQmx1vGk99F/JT6WbvverfXf3aubHJM23E+/27//wqUT6htXPk1jTeoz9//Q6UCIf9/q5X/zd/WqNXGQAkZGYKB4YaLuf43300QsvZy8+9+/9fhrzoVP+8pjMdjiY0eBRiWA0v0fPGR4m68wwtkAAAAASUVORK5CYII=";class ur extends be.CSS2DObject{constructor(e,t){const i=document.createElement("div");super(i),this.props=e,this.amr=t,this.isController=!0,this._direction=1,this._controllingRotate=!1,this._controlling=!1,this._startAt=0,this._looper=0,this._initial=0,this._canRotate=!1,this._emitter=new Ye,this.addListener=this._emitter.addListener.bind(this._emitter),this.removeListener=this._emitter.removeListener.bind(this._emitter),this._update=()=>{if(this._looper=requestAnimationFrame(this._update),this._controlling){let n=(Date.now()-this._startAt)/200;n>4&&(n=4);let l=this._initial+.005*n*this._direction;if(l>this.props.max||l<this.props.min){this.mechanism&&(l<this.props.min?(this.mechanism.position.setZ(this.props.min),this._emitter.emit("change",this.props.min)):l>this.props.max&&(this.mechanism.position.setZ(this.props.max),this._emitter.emit("change",this.props.max)));return}if(this._initial=l,!this.mechanism)return;this.mechanism.position.setZ(l),this._emitter.emit("change",l)}},i.setAttribute("data-ui-type","mechanism");const s=Cs();e.userData&&e.userData.target&&(this.name=e.userData.target.name,t.traverse(n=>{n.name===e.userData.target.name&&(this.mechanism=n)})),i.style.fontSize="30px",i.style.color="#0066FF",i.style.cursor="pointer",i.style.pointerEvents="auto";const r=n=>{n.stopPropagation()},o=n=>{n.preventDefault(),n.stopPropagation()},c={capture:!1,passive:!0},h={capture:!1,passive:!1};["pointerdown","pointerup","pointermove","pointercancel","click","dblclick","contextmenu","mousemove"].forEach(n=>{i.addEventListener(n,r,c)}),["wheel","dragenter","dragover","dragleave","drop"].forEach(n=>{i.addEventListener(n,o,h)});const u=document.createElement("div");u.style.position="absolute",u.style.left="0",u.style.transform="translateX(-50%) rotate(-180deg)",u.style.marginBottom="5px",u.style.width=u.style.height=s?"34px":"44px",u.style.background=`url(${hr}) center no-repeat`,u.style.backgroundSize="100% auto",u.setAttribute("data-direction","up"),u.style.transition="all .2s";const p=document.createElement("div");if(p.style.position="absolute",p.style.left="0",p.style.transform="translateX(-50%)",u.style.bottom=p.style.top="8px",p.style.width=p.style.height=u.style.width,p.style.background=`url(${hr}) center no-repeat`,p.style.backgroundSize="100% auto",p.style.transition="all .2s",p.setAttribute("data-direction","down"),Array.from([u,p]).forEach(n=>{s||n.addEventListener("mousemove",()=>{n.style.filter="invert(100%)"}),n.addEventListener("mouseleave",()=>{n.style.filter=""}),n.addEventListener("pointerdown",()=>{this.mechanism&&(n.style.filter="invert(100%)",this._controlling=!0,this._startAt=Date.now(),this._initial=this.mechanism.position.z,this._direction=n.getAttribute("data-direction")==="up"?1:-1,this._update())}),n.addEventListener("pointerup",()=>{this._controlling=!1,cancelAnimationFrame(this._looper),n.style.filter=""}),n.addEventListener("pointerleave",()=>{this._controlling=!1,cancelAnimationFrame(this._looper),n.style.filter=""})}),e.userData&&(this._canRotate=e.userData.canRotate,this._canRotate)){const{rotateTarget:n,rotateDuration:l,rotateStep:d,rotateMax:g,rotateMin:v}=e.userData;let m;if(n&&(t.traverse(_=>{_.name===n.name&&(m=_)}),m)){const _=document.createElement("div");_.style.background=`url(${_l}) center no-repeat`,_.style.backgroundSize="100% auto",_.style.position="absolute",_.style.top="-50%",_.style.left="-50%",_.style.width=s?"140px":"160px",_.style.height=s?"70px":"80px",_.style.transform="translateX(-50%) translateY(-50%)",i.append(_);const y=document.createElement("div");y.style.background=`url(${gl}) center no-repeat`,y.style.backgroundSize="100% auto",y.style.width=y.style.height=s?"20px":"26px",y.style.position="absolute",y.style.top="0",y.style.transform="translateY(-50%)",y.style.marginBottom="5px",y.setAttribute("data-direction","left"),i.append(y);const w=document.createElement("div");w.style.background=`url(${ml}) center no-repeat`,w.style.backgroundSize="100% auto",w.style.width=w.style.height=s?"20px":"26px",w.style.position="absolute",y.style.left=w.style.right=s?"62px":"69px",w.style.top="0",w.style.transform="translateY(-50%)",w.style.marginBottom="5px",w.setAttribute("data-direction","right"),i.append(w),Array.from([y,w]).forEach(x=>{s||x.addEventListener("mousemove",()=>{x.style.filter="invert(100%)"}),x.addEventListener("mouseleave",()=>{x.style.filter=""}),x.addEventListener("pointerdown",()=>{if(this._timer&&this._timer.isPlaying())return;x.style.filter="invert(100%)",this._controllingRotate=!0,this._startAt=Date.now(),this._direction=x.getAttribute("data-direction")==="left"?1:-1;let b=d/180*Math.PI*this._direction+m.rotation.z;b>g/180*Math.PI?b=g/180*Math.PI:b<v/180*Math.PI&&(b=v/180*Math.PI),this._timer=new wi(m.rotation).to({z:b}).duration(l).start(),this._update()}),x.addEventListener("pointerup",()=>{this._controllingRotate=!1,cancelAnimationFrame(this._looper),x.style.filter=""}),x.addEventListener("pointerleave",()=>{this._controllingRotate=!1,cancelAnimationFrame(this._looper),x.style.filter=""})})}}i.append(u,p),this.scale.set(.01,.01,.01),this.matrixAutoUpdate=!1,this.updateMatrix()}hide(){this.element.style.display="none",this.traverse(e=>{e.visible=!1,e instanceof be.CSS2DObject&&(e.element.style.visibility="hidden")}),this.visible=!1}show(){this.element.style.display="auto",this.traverse(e=>{e.visible=!0,e instanceof be.CSS2DObject&&(e.element.style.visibility="visible")}),this.visible=!0}dispose(){this._emitter.removeAllListeners(),cancelAnimationFrame(this._looper),this.element.remove()}}class vl extends Rn.CSS3DObject{constructor(e){const t=document.createElement("div");super(t),this.props=e,this._scale=.01,this._emitter=new Ye,this.addEventListener=this._emitter.on.bind(this._emitter),this.removeEventListener=this._emitter.on.bind(this._emitter),this._mouseStart=new f.Vector2,this._targetSize=new f.Vector2,this._caches=[],this._sizeFlag="width",this._direction=1,this._lines=[],this._pointerdown=h=>{const{pageX:u,pageY:p}=h;this.endNode.setPointerCapture(h.pointerId),this._mouseStart.set(u,p),this._targetSize.setX(parseFloat(this.endNode.parentElement.style.width)),this._targetSize.setY(parseFloat(this.endNode.parentElement.style.height))},this._pointermove=h=>{if(!this._mouseStart.x)return;const{pageX:u,pageY:p}=h;let n=u-this._mouseStart.x,l=n+this._targetSize.x;this._sizeFlag==="height"&&(n=p-this._mouseStart.y,l=n*this._direction+this._targetSize.y);const d=l%10;l=l-d,n=(l-this._targetSize.x)*this._direction,this._sizeFlag==="height"&&(n=(l-this._targetSize.y)*this._direction),this._textNode.innerText=(l/100).toFixed(2)+" m",this.endNode.parentElement.style[this._sizeFlag]=`${l}px`},this._pointercancel=h=>{this.endNode.releasePointerCapture(h.pointerId),this._mouseStart.set(0,0)};const{start:i,end:s}=e,r=s.distanceTo(i);this.props.axios==="z"?this.props.axios="y":this.props.axios==="y"&&(this.props.axios="z"),this.props.axios==="y"&&(this._sizeFlag="height");const o=document.createElement("div");o.style.position="absolute",o.style.left="0",o.style.bottom="0",t.append(o),this._textNode=document.createElement("div"),this._textNode.innerText=r.toFixed(2)+" m",o.append(this._textNode);const c=document.createElement("div");this.endNode=c,c.style.position="absolute",c.style.left="auto",c.style.right="0",c.style.width="4px",c.style.height="4px",c.style.background="#0066FF",c.style.borderRadius="50%",c.style.margin="-2px -2px 0 0",c.style.cursor="pointer",o.append(c),this.scale.set(this._scale,this._scale,this._scale),t.style.fontSize="6px",t.style.color="#fff",o.style[this._sizeFlag]=r*100+"px",o.style.textAlign="center",this._sizeFlag==="height"?(o.style.borderLeft="0.1px dashed #fff",o.style.display="flex",o.style.alignItems="center",o.style.justifyContent="center",o.style.whiteSpace="nowrap",c.style.top="0",c.style.left="0",c.style.right="auto",c.style.margin="-2px 0 0 -2px"):o.style.borderBottom="0.1px dashed #fff",c.addEventListener("pointerdown",this._pointerdown),c.addEventListener("pointermove",this._pointermove),c.addEventListener("pointerup",this._pointercancel),s[this.props.axios]<i[this.props.axios]?this.rotateY(Math.PI):this._direction=-1}_getIndexByAxios(){return this.props.axios==="y"?1:this.props.axios==="z"?2:0}dispose(){this._lines.forEach(e=>e.dispose()),this._emitter.removeAllListeners(),this.endNode.removeEventListener("pointerdown",this._pointerdown),this.endNode.removeEventListener("pointermove",this._pointermove),this.endNode.removeEventListener("pointerup",this._pointercancel),this.element.remove(),this._caches.forEach(e=>e.clear()),this._caches=[]}}class yl extends f.Object3D{constructor(){super(),this._box3=new f.Box3,this._line11=new vi("长:"),this._line12=new vi("宽:"),this._line13=new vi("高:"),this._outline=new on(0,0),this._radius=0,this._hasWidthConfig=!1,this._hasLengthConfig=!1,this._hasHeightConfig=!1,this.follow="",this.followOrigin=0,this.followScale=1,this.originOffset=0,this.translateCache=0,this.head=0,this.tail=0,this._change=()=>{if(!this._app)return;const e=this._app.camera;e&&this._outline.change(e.position)},this.add(this._outline,this._line11,this._line12,this._line13)}get hasSizeConfig(){return{length:this._hasLengthConfig,width:this._hasWidthConfig,height:this._hasHeightConfig}}get size(){return this._box3.clone()}get radius(){return this._radius}init(e){this._app=e,this._app.controls.addEventListener("change",this._change)}reset(){this.hide(),this._line11.reset()}generate(e,t=0){e&&(this._object=e),this.update(t)}show(e=!0){const t=[this._line11,this._line12,this._line13];e&&(this.visible=!0,this._outline.visible=!0,this._outline.show(),t.push(this._outline)),t.forEach(i=>{i.traverse(s=>{s.visible=!0,s instanceof be.CSS2DObject&&(s.element.style.visibility="visible")})})}hide(e=!0){const t=[this._line11,this._line12,this._line13];e&&(this.visible=!1,this._outline.visible=!1,this._outline.hide(),t.push(this._outline)),t.forEach(i=>{i.traverse(s=>{s.visible=!1,s instanceof be.CSS2DObject&&(s.element.style.visibility="hidden")})})}destroy(){var e;(e=this._app)==null||e.controls.removeEventListener("change",this._change),this._line11.destroy(),this._line12.destroy(),this._line13.destroy()}update(e=0){if(!this._object)return;const t=this._object,{box:i,maxRadius:s,hasLength:r,hasHeight:o,hasWidth:c}=sl(t);this.tail=Math.abs(i.min.x),this.head=Math.abs(i.max.x),this._hasWidthConfig=c,this._hasLengthConfig=r,this._hasHeightConfig=o,this._box3.copy(i),this._radius=s,this.follow&&e&&(this.originOffset=(this.followOrigin-e)*this.followScale),this._outline.update(this._radius),this._change();const h=this._box3.min.x,u=this._box3.max.x,p=this._box3.min.z,n=this._box3.max.z,l=this._box3.min.y,d=this._box3.max.y;let g=.2;const v=new f.Vector3(h,d,0),m=new f.Vector3(u,d,0);this._line11.update(v.clone().sub(new f.Vector3(0,-g/1.8,0)),m.clone().sub(new f.Vector3(0,-g/1.8,0)),this._radius);const _=new f.Vector3(u,l,0);this._line12.update(m.clone().add(new f.Vector3(g,0,0)),_.clone().add(new f.Vector3(g,0,0)),this._radius);const y=new f.Vector3(h,d,p),w=new f.Vector3(h,d,n),x=y.clone();x.y-=g/6;const b=w.clone();b.y-=g/6,this._line13.update(x,b,this._radius)}}class xe extends f.Mesh{constructor(e=.6,t=.4,i=.2){super(),this.isGoods=!0,this._lineMaterial=new f.LineDashedMaterial({color:new f.Color("#000"),dashSize:.015,gapSize:.015}),this._currentLength=.6,this._currentWidth=.4,this._currentHeight=.2,this.material=new f.MeshBasicMaterial({color:new f.Color("#0f5fd5"),transparent:!0,opacity:.4}),this._currentLength=e,this._currentWidth=t,this._currentHeight=i,this._generate(e,t,i)}updateSize(e=.1,t=.1,i=.1){this._currentLength=e,this._currentWidth=t,this._currentHeight=i,this._generate(e,t,i)}hide(){this.traverse(e=>e.visible=!1)}show(){this.traverse(e=>e.visible=!0)}dispose(){var t,i,s,r,o;(t=this.lineSegments)==null||t.removeFromParent(),(s=(i=this.lineSegments)==null?void 0:i.geometry)==null||s.dispose(),this.lineSegments=void 0,(r=this.geometry)==null||r.dispose();const e=this.material;Array.isArray(e)?e.forEach(c=>{var h;return(h=c==null?void 0:c.dispose)==null?void 0:h.call(c)}):(o=e==null?void 0:e.dispose)==null||o.call(e),this._lineMaterial.dispose(),this.clear()}clearAll(){this.dispose()}clone(e){return new xe(this._currentLength,this._currentWidth,this._currentHeight)}_generate(e,t,i){De(this),this.clear(),this.geometry.dispose(),this.geometry=new f.BoxGeometry(e,t,i),this.geometry.translate(0,0,i/2);const s=new f.EdgesGeometry(this.geometry);this.lineSegments=new f.LineSegments(s,this._lineMaterial),this.add(this.lineSegments),this.lineSegments.geometry.dispose(),this.lineSegments.geometry=s,this.lineSegments.computeLineDistances()}}const xl="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAALSURBVAiZY2AAAgAABQABYlUyiAAAAABJRU5ErkJggg==";class ls{constructor(e){this._props=e,this.name="",this.transparentTexture=Ds.load(xl),this._offscreen=new OffscreenCanvas(0,0),this._defaults={...e},this.target=e.target,this.parent=this.target.parent,this.reset()}get imageSize(){return this._props.imageSize}get size(){return this._props.size}get defaultConfigs(){return{canvasWidth:200,canvasHeight:200,scaleX:1,scaleY:1,x:0,y:0,ox:0,oy:0,url:this._defaults.imageUrl}}clear(){this.change()}change(e,t=new f.Vector2(1,1),i=new f.Vector2){this.imageUrl=e;let s;if(e){const r=new Image;r.crossOrigin="anonymous",r.src=e,r.onload=async()=>{var u;let o=window.devicePixelRatio*2;this._offscreen.width=r.width+o,this._offscreen.height=r.height+o;const c=this._offscreen.getContext("2d");c==null||c.clearRect(0,0,this._offscreen.width,this._offscreen.height),c==null||c.drawImage(r,o/2,o/2,r.width,r.height),s=new f.Texture(this._offscreen),s.minFilter=1003,s.colorSpace=f.SRGBColorSpace,s.wrapS=s.wrapT=f.ClampToEdgeWrapping,s.repeat.set(1/t.x,1/t.y),s.offset.set(i.x,i.y),s.flipY=!1,s.needsUpdate=!0;const h=this._props.target;h.material&&((u=h.material.map)==null||u.dispose(),s?(h.material.map=s,h.material.opacity=1):(h.material.map=this.transparentTexture,h.material.opacity=0))}}else{const r=this._props.target;r.material&&(r.material.map=this.transparentTexture)}}reset(){this._props=this._defaults,this.name=this._props.name,this.imageUrl=this._props.imageUrl,this.target=this._props.target,this.change(this.imageUrl||"")}dispose(){this._offscreen=null}}function Vi(a){return a.type?a.type==="Mesh":a.isMesh}class fr{constructor(e,t){this.links=[],this.target=new f.Vector3,this.targetQuaternion=new f.Quaternion,this.iterations=15,this.minDistance=.001,this.maxStep=.35,this.damping=.35,this.maxAngleDelta=.8,this._restQuaternions=[],this._initialRestQuaternions=[],this._axesLocal=[],this._axisMins=[],this._axisMaxs=[],this._jointStates=[],this._frameAppliedAbsDelta=[],this._jointWeights=[],this._stableFrameCount=0,this._lastFramePosErrSq=1/0,this._lastFrameOriErr=1/0,this._tmpEffectorPos=new f.Vector3,this._tmpTargetPos=new f.Vector3,this._tmpLinkPos=new f.Vector3,this._tmpAxisWorld=new f.Vector3,this._tmpVToEff=new f.Vector3,this._tmpVToTar=new f.Vector3,this._tmpProjE=new f.Vector3,this._tmpProjT=new f.Vector3,this._tmpCross=new f.Vector3,this._tmpEffWorldQ=new f.Quaternion,this._tmpTarWorldQ=new f.Quaternion,this._tmpDirCurP=new f.Vector3,this._tmpDirTarP=new f.Vector3,this._tmpDirCurS=new f.Vector3,this._tmpDirTarS=new f.Vector3,this._tmpAxisQ=new f.Quaternion,this._tmpParentWorldQ=new f.Quaternion,this._tmpLocalBeforeQ=new f.Quaternion,this._tmpWorldBeforeQ=new f.Quaternion,t&&(typeof t.iterations=="number"&&(this.iterations=t.iterations),typeof t.minDistance=="number"&&(this.minDistance=t.minDistance),typeof t.maxStep=="number"&&(this.maxStep=t.maxStep),typeof t.damping=="number"&&(this.damping=t.damping),typeof t.maxAngleDelta=="number"&&(this.maxAngleDelta=t.maxAngleDelta),t.orientation&&(this.orientation=Object.assign({enabled:!1},t.orientation))),this.links=(Array.isArray(e)?e:[]).map(s=>{const r=Array.isArray(s.axes)&&s.axes.length>0?s.axes.map(o=>({axis:o.axis.clone(),min:o.min,max:o.max,value:o.value})):void 0;return{object:s.object,ikTcp:!!s.ikTcp,weight:typeof s.weight=="number"?s.weight:void 0,axes:r}});const i=this.links.map(s=>s.object);this._axesLocal=i.map((s,r)=>this._normalizeAxesForLink(r)),this._axisMins=i.map((s,r)=>this._getAxisMinsForLink(r)),this._axisMaxs=i.map((s,r)=>this._getAxisMaxsForLink(r)),this._restQuaternions=i.map((s,r)=>{var u;const o=s.quaternion.clone(),c=this._axesLocal[r],h=this.links[r];if(c&&c.length>0&&h.axes)for(let p=c.length-1;p>=0;p--){const n=c[p],l=((u=h.axes[p])==null?void 0:u.value)??0;Math.abs(l)>1e-6&&(this._tmpAxisQ.setFromAxisAngle(n,l).invert(),o.multiply(this._tmpAxisQ))}return o}),this._initialRestQuaternions=this._restQuaternions.map(s=>s.clone()),this._jointStates=i.map((s,r)=>{var u;const o=((u=this._axesLocal[r])==null?void 0:u.length)??0,c=this.links[r],h=new Array(o).fill(0);if(c.axes&&c.axes.length>0)for(let p=0;p<o;p++)h[p]=c.axes[p].value??0;return{currentAngle:h[0]??0,prevAngle:h[0]??0,currentAngles:h,prevAngles:[...h]}}),this._frameAppliedAbsDelta=i.map((s,r)=>{var o;return new Array(((o=this._axesLocal[r])==null?void 0:o.length)??0).fill(0)}),this._jointWeights=this._buildJointWeights(t==null?void 0:t.weightProfile)}_buildJointWeights(e){var u;const t=(e==null?void 0:e.root)??.3,i=(e==null?void 0:e.middle)??.68,s=(e==null?void 0:e.end)??1,r=Math.max(1,(e==null?void 0:e.curve)??1),o=this.links.length,c=this.links.some(p=>typeof p.weight=="number"),h=[];for(let p=0;p<o;p++){const n=(u=this.links[p])==null?void 0:u.weight;if(c&&typeof n=="number"&&Number.isFinite(n)){h[p]=Math.max(0,n);continue}if(o<=1){h[p]=Math.max(0,s);continue}const l=p/(o-1),d=l<=.5?Math.pow(l/.5,r):Math.pow((l-.5)/.5,r),g=l<=.5?t+(i-t)*d:i+(s-i)*d;h[p]=Math.max(0,g)}return h}_normalizeAxesForLink(e){const t=this.links[e];return t?Array.isArray(t.axes)&&t.axes.length>0?t.axes.map(i=>{const s=i.axis.clone();return s.lengthSq()>0&&s.normalize(),s}):[]:[]}_getAxisMinsForLink(e){const t=this.links[e];return t?Array.isArray(t.axes)&&t.axes.length>0?t.axes.map(i=>i.min):[]:[]}_getAxisMaxsForLink(e){const t=this.links[e];return t?Array.isArray(t.axes)&&t.axes.length>0?t.axes.map(i=>i.max):[]:[]}_applyLinkAngles(e){var o;const t=(o=this.links[e])==null?void 0:o.object;if(!t)return;const i=this._axesLocal[e],r=this._jointStates[e].currentAngles??[];t.quaternion.copy(this._restQuaternions[e]);for(let c=0;c<i.length;c++){const h=i[c],u=r[c]??0;!h||h.lengthSq()<1e-12||Math.abs(u)<1e-12||(this._tmpAxisQ.setFromAxisAngle(h,u),t.quaternion.multiply(this._tmpAxisQ))}}_getAxisWorld(e,t,i){var u;const s=(u=this.links[e])==null?void 0:u.object;if(!s)return i.set(0,0,0);const r=this._axesLocal[e],o=r==null?void 0:r[t];if(!o||o.lengthSq()<1e-12)return i.set(0,0,0);s.parent?s.parent.getWorldQuaternion(this._tmpParentWorldQ):this._tmpParentWorldQ.identity(),this._tmpLocalBeforeQ.copy(this._restQuaternions[e]);const h=this._jointStates[e].currentAngles??[];for(let p=0;p<t;p++){const n=r[p],l=h[p]??0;!n||n.lengthSq()<1e-12||Math.abs(l)<1e-12||(this._tmpAxisQ.setFromAxisAngle(n,l),this._tmpLocalBeforeQ.multiply(this._tmpAxisQ))}return this._tmpWorldBeforeQ.copy(this._tmpParentWorldQ).multiply(this._tmpLocalBeforeQ),i.copy(o).applyQuaternion(this._tmpWorldBeforeQ).normalize()}resetToInitialPose(){for(let e=0;e<this.links.length;e++){const t=this._initialRestQuaternions[e];t&&(this._restQuaternions[e].copy(t),this.links[e].object.quaternion.copy(t));const i=this._jointStates[e];i.currentAngles&&i.currentAngles.fill(0),i.prevAngles&&i.prevAngles.fill(0),this._frameAppliedAbsDelta[e]&&this._frameAppliedAbsDelta[e].fill(0)}this.links.length>0&&this.links[0].object.updateMatrixWorld(!0)}get restQuaternions(){return this._restQuaternions}_isOrientationEnabled(){var e;return!!((e=this.orientation)!=null&&e.enabled)}_getEndIndices(){var o,c;let e=-1;for(let h=0;h<this.links.length;h++)(o=this.links[h])!=null&&o.ikTcp&&(e=h);e<0&&(e=this.links.length-1);const t=!!((c=this.links[e])!=null&&c.ikTcp),i=t?e:this.links.length-1;let s=-1;for(let h=i;h>=0;h--){const u=this._axesLocal[h];if(u&&u.length>0){s=h;break}}return s<0&&(s=Math.max(0,Math.min(this.links.length-1,i))),{ikTcpIndex:e,effectorJointIndex:s,orientationEvalIndex:t?e:s}}_getOrientationDefaults(){var l,d,g,v,m,_,y;const{effectorJointIndex:e,orientationEvalIndex:t}=this._getEndIndices(),i=e,s=this._getOrientationChainStartIndex(i),r=(((l=this.orientation)==null?void 0:l.forwardAxis)??new f.Vector3(1,0,0)).clone().normalize(),o=(((d=this.orientation)==null?void 0:d.upAxis)??new f.Vector3(0,0,1)).clone().normalize(),c=(((g=this.orientation)==null?void 0:g.targetForwardAxis)??new f.Vector3(1,0,0)).clone().normalize(),h=(((v=this.orientation)==null?void 0:v.targetUpAxis)??new f.Vector3(0,0,1)).clone().normalize(),u=((m=this.orientation)==null?void 0:m.forwardWeight)??1,p=((_=this.orientation)==null?void 0:_.upWeight)??.15,n=((y=this.orientation)==null?void 0:y.minAngle)??Math.PI/180;return{effectorIndex:i,orientationEvalIndex:t,orientationStartIndex:s,effectorForwardAxis:r,effectorUpAxis:o,targetForwardAxis:c,targetUpAxis:h,forwardWeight:u,upWeight:p,minAngle:n}}_orientationErrorAngle(){if(!this._isOrientationEnabled()||this.links.length<1)return 0;const{orientationEvalIndex:e,effectorForwardAxis:t,effectorUpAxis:i,targetForwardAxis:s,targetUpAxis:r,forwardWeight:o,upWeight:c}=this._getOrientationDefaults();this.links[Math.max(0,Math.min(this.links.length-1,e))].object.getWorldQuaternion(this._tmpEffWorldQ),this._tmpTarWorldQ.copy(this.targetQuaternion),this._tmpDirCurP.copy(t).applyQuaternion(this._tmpEffWorldQ).normalize(),this._tmpDirTarP.copy(s).applyQuaternion(this._tmpTarWorldQ).normalize();let u=o*this._angleBetweenNormalized(this._tmpDirCurP,this._tmpDirTarP);return c>0&&(this._tmpDirCurS.copy(i).applyQuaternion(this._tmpEffWorldQ).normalize(),this._tmpDirTarS.copy(r).applyQuaternion(this._tmpTarWorldQ).normalize(),u+=c*this._angleBetweenNormalized(this._tmpDirCurS,this._tmpDirTarS)),u}_angleBetweenNormalized(e,t){const i=Math.max(-1,Math.min(1,e.dot(t)));this._tmpCross.crossVectors(e,t);const s=this._tmpCross.length();return Math.atan2(s,i)}_getOrientationChainStartIndex(e){let t=0;for(let i=e;i>=0;i--){const s=this._axesLocal[i];if(s&&s.length>0&&(t+=s.length),t>=3)return i}return 0}bindRestPose(){for(let e=0;e<this.links.length;e++){this._restQuaternions[e].copy(this.links[e].object.quaternion);const t=this._jointStates[e];t.currentAngle=0,t.prevAngle=0,t.currentAngles&&t.currentAngles.fill(0),t.prevAngles&&t.prevAngles.fill(0)}}updateJointStateFromCurrentPose(){var e;for(let t=0;t<this.links.length;t++){const i=(e=this.links[t])==null?void 0:e.object;if(!i)continue;const s=this._restQuaternions[t],r=i.quaternion;this._updateLinkAnglesFromQuaternion(t,r,s),this._frameAppliedAbsDelta[t]&&this._frameAppliedAbsDelta[t].fill(0)}}rebindRestPoseWithBase(e){var t;for(let i=0;i<this.links.length;i++){const s=(t=this.links[i])==null?void 0:t.object;if(!s)continue;const r=e[i]??s.quaternion,o=s.quaternion;this._restQuaternions[i].copy(r),this._initialRestQuaternions[i]&&this._initialRestQuaternions[i].copy(r),this._updateLinkAnglesFromQuaternion(i,o,r),this._frameAppliedAbsDelta[i]&&this._frameAppliedAbsDelta[i].fill(0)}}_updateLinkAnglesFromQuaternion(e,t,i){const s=this._axesLocal[e]??[],r=this._jointStates[e];r.currentAngles||(r.currentAngles=new Array(s.length).fill(0)),r.prevAngles||(r.prevAngles=new Array(s.length).fill(0));const o=this._tmpLocalBeforeQ.copy(i).invert().multiply(t),c=this._tmpWorldBeforeQ.copy(o);for(let h=0;h<s.length;h++){const u=s[h];if(!u||u.lengthSq()<1e-12){r.currentAngles[h]=0,r.prevAngles[h]=0;continue}const p=this._tmpVToEff.set(c.x,c.y,c.z).dot(u);this._tmpAxisQ.set(u.x*p,u.y*p,u.z*p,c.w).normalize();const n=2*Math.atan2(p,this._tmpAxisQ.w);r.currentAngles[h]=n,r.prevAngles[h]=n,this._tmpParentWorldQ.copy(this._tmpAxisQ).invert(),c.premultiply(this._tmpParentWorldQ)}r.currentAngle=r.currentAngles[0]??0,r.prevAngle=r.currentAngle}get jointStates(){return this._jointStates}_clamp(e,t,i){return t!==void 0&&e<t&&(e=t),i!==void 0&&e>i&&(e=i),e}_signedAngleAroundAxis(e,t,i){const s=e.dot(i),r=t.dot(i);this._tmpProjE.copy(e).addScaledVector(i,-s),this._tmpProjT.copy(t).addScaledVector(i,-r);const o=this._tmpProjE.lengthSq(),c=this._tmpProjT.lengthSq(),h=1e-10;if(o<h||c<h)return 0;const u=Math.sqrt(o),p=Math.sqrt(c);this._tmpProjE.multiplyScalar(1/u),this._tmpProjT.multiplyScalar(1/p);const n=this._tmpProjE.dot(this._tmpProjT);this._tmpCross.crossVectors(this._tmpProjE,this._tmpProjT);const l=i.dot(this._tmpCross),d=Math.max(-1,Math.min(1,n));let g=Math.atan2(l,d);const v=Math.min(u,p),m=Math.sin(Math.PI/180*4.6),_=Math.sin(Math.PI/180*30);if(v<=m)return 0;if(v<_){const y=(v-m)/(_-m);g*=Math.max(0,Math.min(1,y))}return g}update(){var C,I,D;if(this.links.length<2)return;const{ikTcpIndex:e,effectorJointIndex:t}=this._getEndIndices(),i=this.links[Math.max(0,Math.min(this.links.length-1,e))].object,s=this._tmpEffectorPos,r=this._tmpTargetPos.copy(this.target),o=this._tmpLinkPos,c=this._tmpAxisWorld,h=this._tmpVToEff,u=this._tmpVToTar;let p=this._isOrientationEnabled();const n=p?this._getOrientationDefaults():void 0;i.getWorldPosition(s);const l=this.minDistance*this.minDistance,d=(n==null?void 0:n.minAngle)??Math.PI/180,g=s.distanceToSquared(r),v=p?this._orientationErrorAngle():0,m=g<=l,_=!p||v<=d,y=this.minDistance*2,w=y*y,x=d*2,b=g<=this._lastFramePosErrSq*1.5&&(!p||v<=this._lastFrameOriErr*1.5);if(m&&_||g<=w&&(!p||v<=x))if(b){if(this._stableFrameCount++,this._stableFrameCount>=2){this._lastFramePosErrSq=g,this._lastFrameOriErr=v;return}}else this._stableFrameCount=0;else this._stableFrameCount=0;this._lastFramePosErrSq=g,this._lastFrameOriErr=v;for(let A=0;A<this._frameAppliedAbsDelta.length;A++)this._frameAppliedAbsDelta[A]&&this._frameAppliedAbsDelta[A].fill(0);for(let A=0;A<this._jointStates.length;A++){const S=this._jointStates[A];if(S.prevAngle=S.currentAngle,S.prevAngles&&S.currentAngles)for(let P=0;P<S.currentAngles.length;P++)S.prevAngles[P]=S.currentAngles[P]}let T=g,M=v,L=0;for(let A=0;A<this.iterations;A++){i.getWorldPosition(s);const S=s.distanceToSquared(r),P=S<l,R=p?this._orientationErrorAngle():0,k=!p||R<=d;if(P&&k)break;if(S>=T*.9&&(!p||R>=M*.5)){if(L++,L>=2)break}else L=0;T=S,M=R;let F=0,z=p?t:e===t?t-1:t;z=Math.max(0,Math.min(this.links.length-1,z));for(let B=z;B>=0;B--){const N=this.links[B].object,W=this._axesLocal[B];if(!(!W||W.length===0))for(let O=0;O<W.length;O++){const j=W[O];if(!j||j.lengthSq()<1e-12||(i.getWorldPosition(s),N.getWorldPosition(o),this._getAxisWorld(B,O,c),c.lengthSq()<1e-12))continue;let U=0;if(!(B===t&&e===t)){h.subVectors(s,o),u.subVectors(r,o);const X=h.lengthSq(),ee=u.lengthSq();X>=1e-12&&ee>=1e-12&&(h.multiplyScalar(1/Math.sqrt(X)),u.multiplyScalar(1/Math.sqrt(ee)),U+=this._signedAngleAroundAxis(h,u,c))}if(p&&B>=n.orientationStartIndex&&B<=n.effectorIndex){this.links[Math.max(0,Math.min(this.links.length-1,n.orientationEvalIndex))].object.getWorldQuaternion(this._tmpEffWorldQ),this._tmpTarWorldQ.copy(this.targetQuaternion),this._tmpDirCurP.copy(n.effectorForwardAxis).applyQuaternion(this._tmpEffWorldQ).normalize(),this._tmpDirTarP.copy(n.targetForwardAxis).applyQuaternion(this._tmpTarWorldQ).normalize();const ee=this._signedAngleAroundAxis(this._tmpDirCurP,this._tmpDirTarP,c);let Rs=0;n.upWeight>0&&(this._tmpDirCurS.copy(n.effectorUpAxis).applyQuaternion(this._tmpEffWorldQ).normalize(),this._tmpDirTarS.copy(n.targetUpAxis).applyQuaternion(this._tmpTarWorldQ).normalize(),Rs=this._signedAngleAroundAxis(this._tmpDirCurS,this._tmpDirTarS,c)),U+=n.forwardWeight*ee+n.upWeight*Rs}if(Math.abs(U)<1e-6)continue;const Ze=Math.max(0,this._jointWeights[B]??1);if(Ze<=0)continue;if(U*=Math.max(0,Math.min(1,this.damping))*Ze,this.maxStep>0){const X=this.maxStep*Ze;if(X<=0)continue;U>X?U=X:U<-X&&(U=-X)}if(this.maxAngleDelta>0){const X=((C=this._frameAppliedAbsDelta[B])==null?void 0:C[O])??0,ee=Math.max(0,this.maxAngleDelta-X);if(ee<=0)continue;U>ee?U=ee:U<-ee&&(U=-ee)}const _e=this._jointStates[B];_e.currentAngles||(_e.currentAngles=new Array(W.length).fill(0));const Gt=(_e.currentAngles[O]??0)+U,Nt=(I=this._axisMins[B])==null?void 0:I[O],ve=(D=this._axisMaxs[B])==null?void 0:D[O];U=this._clamp(Gt,Nt,ve)-(_e.currentAngles[O]??0),!(Math.abs(U)<1e-9)&&(_e.currentAngles[O]=(_e.currentAngles[O]??0)+U,_e.currentAngle=_e.currentAngles[0]??0,Math.abs(U)>F&&(F=Math.abs(U)),this._frameAppliedAbsDelta[B]&&(this._frameAppliedAbsDelta[B][O]=(this._frameAppliedAbsDelta[B][O]??0)+Math.abs(U)),this._applyLinkAngles(B),N.updateMatrixWorld(!0))}}if(F<1e-5&&S<=l*4&&(!p||R<=d*2))break}}}const Re=new f.Raycaster,Ct=new f.Vector3,wl=new f.Quaternion,dr=new f.Vector3,pr=new f.Vector3,Wi={type:"change"},mr={type:"mouseDown",mode:null},gr={type:"mouseUp",mode:null},bl={type:"objectChange"},ei=new WeakMap,ti=new WeakMap,Dt=new WeakMap;function Al(a){if(!this.domElement)return{x:0,y:0,button:a.button};if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:a.button};const e=this.domElement.getBoundingClientRect();return{x:(a.clientX-e.left)/e.width*2-1,y:-((a.clientY-e.top)/e.height)*2+1,button:a.button}}function ii(a,e,t){const i=e.intersectObject(a,!0);for(let s=0;s<i.length;s++)if(i[s].object.visible||t)return i[s];return!1}function Ui(a){return a==="E"?"rotate":a==="XYZ"?"translate":null}class Tl extends f.Object3D{constructor(e){super(),this.isTransformControlsRoot=!0,this.controls=e,this.visible=!1}updateMatrixWorld(e){const t=this.controls;t.object!==void 0&&(t.object.updateMatrixWorld(),t.object.parent===null?console.error("FreeTransformControls: The attached 3D object must be a part of the scene graph."):t.object.parent.matrixWorld.decompose(t._parentPosition,t._parentQuaternion,t._parentScale),t.object.matrixWorld.decompose(t.worldPosition,t.worldQuaternion,t._worldScale),t._parentQuaternionInv.copy(t._parentQuaternion).invert(),t._worldQuaternionInv.copy(t.worldQuaternion).invert()),t.camera.updateMatrixWorld(),t.camera.matrixWorld.decompose(t.cameraPosition,t.cameraQuaternion,t._cameraScale),t.camera.isOrthographicCamera?t.camera.getWorldDirection(t.eye).negate():t.eye.copy(t.cameraPosition).sub(t.worldPosition).normalize(),super.updateMatrixWorld(e)}dispose(){this.traverse(e=>{const t=e;t.geometry&&t.geometry.dispose(),t.material&&t.material.dispose()})}}const $=class $ extends f.Object3D{constructor(e){super(),this.picker=new f.Object3D,this.gizmo=new f.Object3D,this.helper=new f.Object3D,this._matMove=new f.MeshBasicMaterial({color:16777215,depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0,opacity:1}),this._matRing=new f.MeshBasicMaterial({color:16777215,depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0,opacity:1}),this._matInvisible=new f.MeshBasicMaterial({color:16777215,depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0,opacity:0}),this._matHelper=new f.LineBasicMaterial({color:16777215,depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0,opacity:.6}),this._arcSegments=96,this._arcStartAngleOffset=.05,this._moveColorDefault=new f.Color(16777215),this._moveColorActive=new f.Color(0),this._moveOpacityDefault=1,this._moveOpacityRingActive=.5,this._ringColorDefault=new f.Color(16777215),this._ringColorActive=new f.Color(0),this._ringOpacityDefault=1,this._ringOpacityActive=.6,this._ringScale=1,this._ringTargetScale=1.5,this._ringScaleTweening=!1,this._isMoveActive=!1,this._isRingActive=!1,this._isMoveHover=!1,this._isDragging=!1,this._isExpanded=!1,this.controls=e,this._moveMesh=new f.Mesh(new f.CircleGeometry($.MOVE_RADIUS,96),this._matMove),this._moveMesh.rotateX(-Math.PI/2),this._moveMesh.name="XYZ",this._moveMesh.renderOrder=1/0,this._ringMesh=new f.Mesh(new f.TorusGeometry($.RING_RADIUS,$.RING_TUBE,48,96),this._matRing),this._ringMesh.name="E",this._ringMesh.renderOrder=1e3,this._arcGeom=new $i.LineGeometry,this._arcPositions=new Float32Array((this._arcSegments+1)*3),this._arcGeom.setPositions(this._arcPositions),this._arcGeom.instanceCount=0;const t=new Er.LineMaterial({color:16777215,linewidth:2,depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0,opacity:1});t.resolution.set(window.innerWidth,window.innerHeight),this._arcLine=new Rr.Line2(this._arcGeom,t),this._arcLine.renderOrder=1001,this._arcLine.visible=!1,this.gizmo.add(this._ringMesh),this.gizmo.add(this._moveMesh),this.gizmo.add(this._arcLine);const i=new f.Mesh(new f.CircleGeometry($.PICKER_MOVE_RADIUS,32),this._matInvisible);i.name="XYZ",i.renderOrder=1/0;const s=new f.Mesh(new f.TorusGeometry($.RING_RADIUS+.005,$.PICKER_RING_TUBE,8,48),this._matInvisible);s.name="E",s.renderOrder=1/0,this.picker.add(s),this.picker.add(i),this.picker.visible=!1;const r=new f.OctahedronGeometry(.01,2),o=new f.MeshBasicMaterial({color:16777215,depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0,opacity:.7});this._startMarker=new f.Mesh(r,o),this._startMarker.renderOrder=1/0,this._startMarker.visible=!1,this._endMarker=new f.Mesh(r,o),this._endMarker.renderOrder=1/0,this._endMarker.visible=!1,this._deltaGeom=new f.BufferGeometry,this._deltaGeom.setAttribute("position",new f.Float32BufferAttribute(new Float32Array(2*3),3)),this._deltaLine=new f.Line(this._deltaGeom,this._matHelper),this._deltaLine.renderOrder=1/0,this._deltaLine.visible=!1,this.helper.add(this._startMarker),this.helper.add(this._endMarker),this.helper.add(this._deltaLine),this.add(this.gizmo),this.add(this.picker),this.add(this.helper)}get isExpanded(){return this._isExpanded}set isExpanded(e){var s;if(this._isExpanded===e)return;this._isExpanded=e;const t=e?this._ringTargetScale:1;this._ringScaleTweening=!0,(s=this._ringScaleTween)==null||s.stop();const i={scale:this._ringScale};this._ringScaleTween=new ne.Tween(i).to({scale:t},200).easing(ne.Easing.Quadratic.Out).onUpdate(()=>{this._ringScale=i.scale}).onStop(()=>{this._ringScaleTweening=!1}).onComplete(()=>{this._ringScaleTweening=!1}).start()}get isRingScaleTweening(){return this._ringScaleTweening}updateMatrixWorld(e){var y,w;const t=this.controls,i=t.axis,s=t.mode,r=t.worldPosition,o=t.size;this._arcLine.material.resolution.set(window.innerWidth,window.innerHeight);const h=(x,b=1)=>{x.position.copy(r),x.scale.set(1,1,1).multiplyScalar(o*b),x.visible=!0};h(this._moveMesh),h(this._ringMesh,this._ringScale),h(this._arcLine,this._ringScale),this.picker.position.copy(r),this.picker.scale.set(1,1,1).multiplyScalar(o);for(const x of this.picker.children)x.quaternion.copy(t.cameraQuaternion),x.scale.set(1,1,1).multiplyScalar(this._ringScale);this._ringMesh.quaternion.copy(t.cameraQuaternion),this._arcLine.quaternion.copy(t.cameraQuaternion),this._moveMesh.lookAt(t.cameraPosition);const u=s==="default"||s==="translate",p=s==="default"||s==="rotate";this._moveMesh.visible=u,this._ringMesh.visible=p;for(const x of this.picker.children)x.name==="XYZ"&&(x.visible=u),x.name==="E"&&(x.visible=p);const n=t.dragging,l=!n&&i==="XYZ",d=!n&&i==="E",g=l||n&&i==="XYZ",v=d||n&&i==="E";if(g!==this._isMoveActive){this._isMoveActive=g;const x=g?this._moveColorActive:this._moveColorDefault;(y=this._moveColorTween)==null||y.stop();const b={r:this._matMove.color.r,g:this._matMove.color.g,b:this._matMove.color.b};this._moveColorTween=new ne.Tween(b).to({r:x.r,g:x.g,b:x.b},200).easing(ne.Easing.Quadratic.Out).onUpdate(()=>{this._matMove.color.setRGB(b.r,b.g,b.b)}).start()}if(v!==this._isRingActive){this._isRingActive=v;const x=v?this._ringColorActive:this._ringColorDefault,b=v?this._ringOpacityActive:this._ringOpacityDefault,T=v?this._moveOpacityRingActive:this._moveOpacityDefault;this._matMove.opacity=T,(w=this._ringColorTween)==null||w.stop();const M={r:this._matRing.color.r,g:this._matRing.color.g,b:this._matRing.color.b,opacity:this._matRing.opacity};this._ringColorTween=new ne.Tween(M).to({r:x.r,g:x.g,b:x.b,opacity:b},200).easing(ne.Easing.Quadratic.Out).onUpdate(()=>{this._matRing.color.setRGB(M.r,M.g,M.b),this._matRing.opacity=M.opacity}).start()}const m=n;if(this._startMarker.visible=m,this._endMarker.visible=m,this._deltaLine.visible=m,m){this._startMarker.position.copy(t.worldPositionStart),this._endMarker.position.copy(t.worldPosition),this._startMarker.scale.set(1,1,1).multiplyScalar(o),this._endMarker.scale.set(1,1,1).multiplyScalar(o);const x=this._deltaGeom.getAttribute("position");x.setXYZ(0,t.worldPositionStart.x,t.worldPositionStart.y,t.worldPositionStart.z),x.setXYZ(1,t.worldPosition.x,t.worldPosition.y,t.worldPosition.z),x.needsUpdate=!0,this._deltaGeom.computeBoundingSphere()}const _=m&&p&&i==="E";if(this._arcLine.visible=_,_){const x=t.pointStart,b=t.pointEnd;if(x.lengthSq()>1e-12&&b.lengthSq()>1e-12){dr.set(1,0,0).applyQuaternion(t.cameraQuaternion),pr.set(0,1,0).applyQuaternion(t.cameraQuaternion);const T=x.dot(dr),M=x.dot(pr),L=Math.atan2(M,T),C=t.rotationAngle;if(Math.abs(C)<1e-4)this._arcLine.visible=!1,this._arcGeom.instanceCount=0;else{const I=this._arcSegments,D=Math.max(2,Math.min(I,Math.ceil(Math.abs(C)/(Math.PI*2)*I))),A=C/D,S=$.RING_RADIUS,P=Math.sign(C)*this._arcStartAngleOffset;for(let F=0;F<=D;F++){const z=L+P+A*F,B=Math.cos(z)*S,N=Math.sin(z)*S,W=F*3;this._arcPositions[W]=B,this._arcPositions[W+1]=N,this._arcPositions[W+2]=0}for(let F=D+1;F<=I;F++){const z=F*3;this._arcPositions[z]=0,this._arcPositions[z+1]=0,this._arcPositions[z+2]=0}this._arcGeom.setPositions(this._arcPositions),this._arcGeom.instanceCount=D,this._arcLine.computeLineDistances(),this._arcGeom.computeBoundingSphere();const R=Math.cos(L)*$.RING_RADIUS*this._ringScale,k=Math.sin(L)*$.RING_RADIUS*this._ringScale;Ct.set(R,k,0),Ct.applyQuaternion(t.cameraQuaternion),Ct.multiplyScalar(o),Ct.add(r),this._startMarker.position.copy(Ct)}}else this._arcLine.visible=!1,this._arcGeom.instanceCount=0}else this._arcGeom.instanceCount=0;super.updateMatrixWorld(e)}};$.RING_RADIUS=.18,$.RING_TUBE=.003,$.PICKER_RING_TUBE=.025,$.MOVE_RADIUS=.04,$.PICKER_MOVE_RADIUS=.2;let cs=$;class Sl extends f.Mesh{constructor(){super(new f.PlaneGeometry(1e5,1e5,2,2),new f.MeshBasicMaterial({visible:!1,wireframe:!0,transparent:!0,opacity:.1,depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1})),this.isTransformControlsPlane=!0}updateMatrixWorld(e){const t=this,i=t.dragging?t.worldPositionStart:t.worldPosition;this.position.copy(i),this.quaternion.copy(t.cameraQuaternion),super.updateMatrixWorld(e)}}class Ml extends f.EventDispatcher{constructor(e,t=null){super(),this.domElement=null,this._offset=new f.Vector3,this._startNorm=new f.Vector3,this._endNorm=new f.Vector3,this._cameraScale=new f.Vector3,this._parentPosition=new f.Vector3,this._parentQuaternion=new f.Quaternion,this._parentQuaternionInv=new f.Quaternion,this._parentScale=new f.Vector3,this._worldScaleStart=new f.Vector3,this._worldQuaternionInv=new f.Quaternion,this._worldScale=new f.Vector3,this._positionStart=new f.Vector3,this._quaternionStart=new f.Quaternion,this._scaleStart=new f.Vector3,this._capturePointerId=null,this._captureDocument=null,this._hoverShieldActive=!1;const i=new Tl(this);this._root=i;const s=new cs(this);this._gizmo=s,i.add(s);const r=new Sl;this._plane=r,i.add(r);const o=this;function c(h,u){let p=u;Object.defineProperty(o,h,{get(){return p!==void 0?p:u},set(n){p!==n&&(p=n,r[h]=n,s[h]=n,o.dispatchEvent({type:h+"-changed",value:n}),o.dispatchEvent(Wi))}}),o[h]=u,r[h]=u,s[h]=u}c("camera",e),c("object",void 0),c("enabled",!0),c("depthTest",!0),c("axis",null),c("mode","default"),c("space","world"),c("size",.25),c("dragging",!1),c("gizmoPriority",!0),c("worldPosition",new f.Vector3),c("worldPositionStart",new f.Vector3),c("worldQuaternion",new f.Quaternion),c("worldQuaternionStart",new f.Quaternion),c("cameraPosition",new f.Vector3),c("cameraQuaternion",new f.Quaternion),c("pointStart",new f.Vector3),c("pointEnd",new f.Vector3),c("rotationAxis",new f.Vector3),c("rotationAngle",0),c("eye",new f.Vector3),this._getPointer=Al.bind(this),this._onPointerDown=this._handlePointerDown.bind(this),this._onPointerHover=this._handlePointerHover.bind(this),this._onPointerMove=this._handlePointerMove.bind(this),this._onPointerUp=this._handlePointerUp.bind(this),this._onPointerDownCapture=this._handlePointerDownCapture.bind(this),this._onPointerMoveCapture=this._handlePointerMoveCapture.bind(this),this._onPointerUpCapture=this._handlePointerUpCapture.bind(this),this._onMouseMoveCapture=this._handleMouseMoveCapture.bind(this),t!==null&&this.connect(t)}connect(e){this.domElement=e,this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="none";const t=this.domElement.ownerDocument;this._captureDocument=t,t.addEventListener("pointerdown",this._onPointerDownCapture,!0),t.addEventListener("pointermove",this._onPointerMoveCapture,!0),t.addEventListener("pointerup",this._onPointerUpCapture,!0),t.addEventListener("mousemove",this._onMouseMoveCapture,!0)}disconnect(){this.domElement&&(this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="auto",this._captureDocument&&(this._captureDocument.removeEventListener("pointerdown",this._onPointerDownCapture,!0),this._captureDocument.removeEventListener("pointermove",this._onPointerMoveCapture,!0),this._captureDocument.removeEventListener("pointerup",this._onPointerUpCapture,!0),this._captureDocument.removeEventListener("mousemove",this._onMouseMoveCapture,!0),this._captureDocument=null))}getHelper(){return this._root}dispose(){this.disconnect(),this._root.dispose()}attach(e){return this.object=e,this._root.visible=!0,this}detach(){return this.object=void 0,this.axis=null,this.dragging=!1,this._setHoverShieldActive(!1),this._root.visible=!1,this}getMode(){return this.mode}setMode(e){this.mode=e,this.axis=null,this.dispatchEvent(Wi)}setSize(e){this.size=e}getRaycaster(){return Re}_handlePointerHover(e){if(this.enabled)switch(e.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(e));break}}_handlePointerDown(e){if(!this.enabled||!this.domElement)return;document.pointerLockElement||this.domElement.setPointerCapture(e.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove);const t=this._getPointer(e);this.pointerHover(t),this.pointerDown(t)}_handlePointerMove(e){this.enabled&&this.pointerMove(this._getPointer(e))}_handlePointerUp(e){this.enabled&&this.domElement&&(this.domElement.releasePointerCapture(e.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(e)))}_setHoverShieldActive(e){if(!this.domElement)return;const t=this.domElement.ownerDocument;if(e){if(this._hoverShieldActive)return;this._hoverShieldActive=!0;const r=Dt.get(t)??0;Dt.set(t,r+1);let o=ti.get(t);o||(o=t.createElement("div"),o.style.position="fixed",o.style.left="0",o.style.top="0",o.style.right="0",o.style.bottom="0",o.style.cursor="grab",o.style.pointerEvents="auto",o.style.background="transparent",o.style.zIndex="2147483647",ti.set(t,o)),o.parentElement||t.body.appendChild(o);return}if(!this._hoverShieldActive)return;this._hoverShieldActive=!1;const i=Dt.get(t)??0,s=Math.max(0,i-1);if(s===0){Dt.delete(t);const r=ti.get(t);r!=null&&r.parentElement&&r.parentElement.removeChild(r),ti.delete(t)}else Dt.set(t,s)}_handlePointerDownCapture(e){if(!this.enabled||!this.domElement||!this.gizmoPriority)return;const t=e.target;if(t&&(t===this.domElement||this.domElement.contains(t)))return;const i=this._getPointer(e);this.pointerHover(i),!(!this.axis||!this._isAxisAllowed(this.axis))&&i.button===0&&(this._capturePointerId=e.pointerId,document.pointerLockElement||this.domElement.setPointerCapture(e.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),this.pointerDown(i))}_handlePointerMoveCapture(e){if(!this.enabled||!this.domElement||!this.gizmoPriority)return;const t=this._getPointer(e);if(this._capturePointerId===e.pointerId&&this.dragging){e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),this.pointerMove(t);return}this.dragging||(this.pointerHover(t),this.axis&&this._isAxisAllowed(this.axis)&&(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation()))}_handleMouseMoveCapture(e){if(!this.enabled||!this.domElement||!this.gizmoPriority)return;const t=this._getPointer(e);if(this.dragging){e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();return}this.pointerHover(t),this.axis&&this._isAxisAllowed(this.axis)&&(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation())}_handlePointerUpCapture(e){!this.enabled||!this.domElement||!this.gizmoPriority||this._capturePointerId===e.pointerId&&(this._capturePointerId=null,this.domElement.releasePointerCapture(e.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),this.pointerUp(this._getPointer(e)))}pointerHover(e){if(this.object===void 0||this.dragging===!0)return;e!==null&&Re.setFromCamera(e,this.camera);const t=this._gizmo.picker.children.find(h=>h.name==="XYZ"),i=this._gizmo.picker.children.find(h=>h.name==="E"),s=t?ii(t,Re):!1,r=i?ii(i,Re):!1;let o=this._gizmo.isExpanded,c=null;o?r&&!this._gizmo.isRingScaleTweening?c="E":s?c="XYZ":(o=!1,c=null):s&&(o=!0,c="XYZ"),this._gizmo.isExpanded!==o&&(this._gizmo.isExpanded=o),c&&this._isAxisAllowed(c)?this.axis=c:this.axis=null,this._setHoverShieldActive(!!this.axis||this.dragging),this._updateCursor()}pointerDown(e){if(!(this.object===void 0||this.dragging===!0||e!=null&&e.button!==0)&&this.axis!==null&&this._isAxisAllowed(this.axis)){e!==null&&Re.setFromCamera(e,this.camera);const t=ii(this._plane,Re,!0);t&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(t.point).sub(this.worldPositionStart)),this.dragging=!0,this._setHoverShieldActive(!0);const i=Ui(this.axis);mr.mode=i,this.dispatchEvent(mr),this._updateCursor()}}pointerMove(e){const t=this.axis,i=this.object;if(i===void 0||t===null||this.dragging===!1||e!==null&&e.button!==-1||!this._isAxisAllowed(t))return;const s=Ui(t);if(!s)return;e!==null&&Re.setFromCamera(e,this.camera);const r=ii(this._plane,Re,!0);r&&(this.pointEnd.copy(r.point).sub(this.worldPositionStart),s==="translate"?(this._offset.copy(this.pointEnd).sub(this.pointStart),this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),i.position.copy(this._offset).add(this._positionStart)):s==="rotate"&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1,this.rotationAxis.applyQuaternion(this._parentQuaternionInv),i.quaternion.copy(wl.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),i.quaternion.multiply(this._quaternionStart).normalize()),this.dispatchEvent(Wi),this.dispatchEvent(bl))}pointerUp(e){if(!(e!==null&&e.button!==0)){if(this.dragging&&this.axis!==null){const t=Ui(this.axis);gr.mode=t,this.dispatchEvent(gr)}this.dragging=!1,this.axis=null,this._setHoverShieldActive(!1),this._updateCursor()}}_updateCursor(){if(!this.domElement)return;const e=ei.get(this.domElement);if(this.dragging){this.domElement.style.cursor="grabbing",ei.set(this.domElement,this);return}if(this.axis){this.domElement.style.cursor="grab",ei.set(this.domElement,this);return}e===this&&(this.domElement.style.cursor="",ei.delete(this.domElement))}_isAxisAllowed(e){return this.mode==="default"?e==="XYZ"||e==="E":this.mode==="translate"?e==="XYZ":this.mode==="rotate"?e==="E":!1}}class Cl{constructor(e,t){var n;this.isController=!0,this._enabled=!0,this._tmpQ=new f.Quaternion,this._tmpContainerQ=new f.Quaternion,this._tmpV=new f.Vector3,this._resetHierarchy=!1,this._defaultPoseQuats=new Map,this._zeroPoseQuats=new Map,this._emitter=new Ye,this.addListener=this._emitter.addListener.bind(this._emitter),this.removeAllListeners=this._emitter.removeAllListeners.bind(this._emitter),this._initialTargetPos=new f.Vector3,this._initialTargetQuat=new f.Quaternion,this._axesHelpers=[],this._showAxes=!1;const{joints:i,container:s,context:r,resetHierarchy:o}=e,c=(Array.isArray(i)?i:[]).map(l=>l.object);this._container=s,this._context=r,this._resetHierarchy=!!o;let h;if(Array.isArray(i))for(let l=0;l<i.length;l++)(n=i[l])!=null&&n.ikTcp&&(h=i[l].object);this._effector=h??c[c.length-1],this._resetHierarchy&&this.setupHierarchy(c),c.forEach(l=>{l&&(this._defaultPoseQuats.has(l.uuid)||this._defaultPoseQuats.set(l.uuid,l.quaternion.clone()))}),this.transformControls=new Ml(t.camera,t.domElement),this.transformControls.addEventListener("dragging-changed",({value:l})=>{this._emitter.emit("dragging-changed",l),l||this.syncTargetToEffector()}),this.transformControls.addEventListener("axis-changed",({value:l})=>{this.transformControls.dragging||(this.targetObject.visible=l==="E")}),this.targetObject=new f.Object3D,this.targetObject.name="ikTarget",this.targetObject.visible=!1,this.targetObject.userData.isIKTarget=!0,this.transformControls.attach(this.targetObject);const u=new f.AxesHelper(.0675);u.material.depthTest=!1,u.material.depthWrite=!1,u.renderOrder=1e3,this.targetObject.add(u),this.syncTargetToEffector(),this._initialTargetPos.copy(this.targetObject.position),this._initialTargetQuat.copy(this.targetObject.quaternion);const p=this.transformControls.getHelper();this._container.add(this.targetObject),this._container.add(p),this.solver=new fr(i,r),this.solver.links.forEach((l,d)=>{const g=l.object;if(g){const v=this.solver.restQuaternions[d];v&&this._zeroPoseQuats.set(g.uuid,v.clone())}}),c.forEach(l=>{const d=new f.AxesHelper(.2);d.visible=!1,l.add(d),this._axesHelpers.push(d)})}get enabled(){return this._enabled}set enabled(e){this._enabled=e,this.transformControls.enabled=e,this.transformControls.getHelper().visible=e}get showAxes(){return this._showAxes}set showAxes(e){this._showAxes=e,this._axesHelpers.forEach(t=>t.visible=e)}getEffectorLocalPos(){var t;const e=new f.Vector3;return this._effector&&(this._effector.getWorldPosition(e),(t=this._container)==null||t.worldToLocal(e)),e}getEffectorLocalQuat(){const e=new f.Quaternion;return this._effector&&(this._effector.getWorldQuaternion(e),this._container&&(this._container.getWorldQuaternion(this._tmpContainerQ),this._tmpContainerQ.invert(),e.premultiply(this._tmpContainerQ))),e}setupHierarchy(e){for(let t=0;t<e.length-1;t++){const i=e[t],s=e[t+1];s.parent!==i&&i.attach(s)}}syncTargetToEffector(){this.targetObject.position.copy(this.getEffectorLocalPos()),this.targetObject.quaternion.copy(this.getEffectorLocalQuat()),this.targetObject.updateMatrixWorld(!0)}syncTargetToSolver(){this.solver&&(this.targetObject.getWorldPosition(this._tmpV),this.solver.target.copy(this._tmpV),this.targetObject.getWorldQuaternion(this._tmpQ),this.solver.targetQuaternion.copy(this._tmpQ))}setControlMode(e){this.transformControls.setMode(e)}setOrientation(e){this.solver&&(this.solver.orientation.forwardAxis=e.forwardAxis,this.solver.orientation.upAxis=e.upAxis)}updateJointChain(e){var h;const t=(Array.isArray(e)?e:[]).filter(u=>!!(u!=null&&u.object));if(t.length<2||!this._container)return;const i=t.map(u=>u.object);i.forEach(u=>{u&&(this._defaultPoseQuats.has(u.uuid)||this._defaultPoseQuats.set(u.uuid,u.quaternion.clone()),this._zeroPoseQuats.has(u.uuid)||this._zeroPoseQuats.set(u.uuid,u.quaternion.clone()))});let s;for(let u=0;u<t.length;u++)(h=t[u])!=null&&h.ikTcp&&(s=t[u].object);this._effector=s??i[i.length-1],this._resetHierarchy&&this.setupHierarchy(i);const r=this.solver,o=new fr(t,this._context);r&&(o.iterations=r.iterations,o.minDistance=r.minDistance,o.maxStep=r.maxStep,o.damping=r.damping,o.maxAngleDelta=r.maxAngleDelta,r.orientation&&o.orientation&&Object.assign(o.orientation,r.orientation));const c=o.links.map(u=>this._zeroPoseQuats.get(u.object.uuid));o.rebindRestPoseWithBase(c),this.solver=o,this._axesHelpers.forEach(u=>u.removeFromParent()),this._axesHelpers=[],i.forEach(u=>{const p=new f.AxesHelper(.2);p.visible=this._showAxes,u.add(p),this._axesHelpers.push(p)}),this.syncTargetToEffector(),this.syncTargetToSolver()}update(){!this._enabled||!this.solver||(this.syncTargetToSolver(),this.solver.update())}toggleOrientation(e){this.solver&&(this.solver.orientation.enabled=e)}setSolverContext(e){this.solver&&(typeof e.iterations=="number"&&(this.solver.iterations=e.iterations),typeof e.damping=="number"&&(this.solver.damping=e.damping))}reset(){if(!(!this.solver||!this._container)){for(const e of this.solver.links){const t=e==null?void 0:e.object;if(!t)continue;const i=this._defaultPoseQuats.get(t.uuid);i&&t.quaternion.copy(i)}this._container.updateMatrixWorld(!0),this.solver.updateJointStateFromCurrentPose(),this.syncTargetToEffector(),this.syncTargetToSolver()}}dispose(){this.transformControls.detach(),this.transformControls.dispose(),this.targetObject.removeFromParent(),this._axesHelpers.forEach(e=>e.removeFromParent()),this._axesHelpers=[]}}const Dl=(a,e,t,i={})=>{const s=[],{resetHierarchy:r,onDraggingChanged:o}=i;return a.forEach(c=>{if(!(c!=null&&c.joints)||c.joints.length<2)return;const h=new Cl({joints:c.joints,container:e,context:{orientation:c.orientation},resetHierarchy:r},t);o&&h.addListener("dragging-changed",u=>{o(h,u)}),s.push(h)}),s},Ds=new f.TextureLoader;Ds.crossOrigin="anonymous";class an extends f.Object3D{constructor(e){super(),this._props=e,this._emitter=new Ye,this.addEventListener=this._emitter.addListener.bind(this._emitter),this._container=new f.Group,this.lines=new f.Group,this._clips=[],this._actionsMap=new Map,this._animationClock=new f.Clock,this.sizeBox=new yl,this._goodsSize=new nl(0,0,0),this._slots=[],this._logos=[],this._skins=[],this._levels=new Map,this._rollerLevel=new Map,this._liftBrackets=[],this._ikChains=[],this.ikControllers=[],this._ikDraggingControllers=new Set,this._shelfSyncCache=new WeakMap,this._rollerPools=new WeakMap,this._videoCache=new Map,this._rollerColumns=1,this._bodyOpacity=1,this._masts=new Map,this._liftMaxHeight=0,this._jackMaxHeight=0,this._forkMaxHeight=0,this.controllers=[],this.goods=[],this._breathLights=[],this._shelves=new Map,this._shelfMaxLevel=1,this._url="",this._showController=!0,this._showSlots=!0,this._shapeKeys=new Map,this._shapeKeyTargets=new Map,this._shapeKeyTimer=0,this._shapeKeyCache="",this._materialsCache=new Map,this.opacityCache=void 0,this.actions=[],this._useCenterModel=!1,this._useLift=!1,this._columnCount=1,this._columnGap=.03,this._rowCount=1,this._rowGap=.01,this._levelCount=1,this._currentAction=null,this._pendingFinishedCallback=null,this._url=e.url||"",this._url&&this.load(this._url).then(),this.add(this._container,this.lines),this._props.showSizeBox&&this.add(this.sizeBox),this.showController=typeof e.showController=="boolean"?e.showController:!0,this._showSlots=typeof e.showSlots=="boolean"?e.showSlots:!0}get shapeKeys(){return this._shapeKeys}get size(){const e=this.sizeBox.size.getSize(new f.Vector3);return{width:e.z,length:e.x,height:e.y}}get goodsSize(){return this._goodsSize}get showController(){return this._showController}set showController(e){this._showController=e,this.controllers.forEach(t=>e?t.show():t.hide())}get slots(){return this._slots}get logos(){return this._logos}get skins(){return this._skins}get bodyOpacity(){return this._bodyOpacity}get fork(){return this._fork}get forkHeight(){var e;return((e=this._fork)==null?void 0:e.position.z)||0}get liftHeight(){var e;return this._lift?this._lift instanceof Map?((e=this._lift.get(0))==null?void 0:e.position.z)||0:this._lift.position.z||0:0}get jack(){return this._jack}get jackHeight(){var e;return((e=this._jack)==null?void 0:e.position.z)||0}get lift(){return this._lift}get useCenterModel(){return this._useCenterModel}set useCenterModel(e){this._useCenterModel=e,this._rollerLevel.forEach(t=>{t.traverse(i=>{i.userData.isCenterModel&&(i.visible=e)})})}set bodyOpacity(e){this._bodyOpacity=e,e<1?this._materialsCache.forEach(t=>{t.mat.transparent=!0,t.mat.opacity=e,t.mat.metalness=0,t.mat.roughness=1,t.mat.color=new f.Color("#3859be"),t.mat.needsUpdate=!0}):this._materialsCache.forEach(t=>{t.mat.transparent=t.transparent,t.mat.opacity=t.opacity,t.mat.metalness=t.metalness,t.mat.roughness=t.roughness,t.mat.color=t.color,t.mat.needsUpdate=!0})}init(e){this._app=e,this.sizeBox.init(e),this._onTicker&&this._app.renderer.domElement.removeEventListener("ticker",this._onTicker),this._onTicker=()=>{if(this._mixer){const t=this._animationClock.getDelta();this._mixer.update(t)}else this._animationClock.getDelta();this.ikControllers.forEach(t=>t.update())},this._app.renderer.domElement.addEventListener("ticker",this._onTicker),this.addEventListener("shape-key-changed",(t,i)=>{if(this._slots.forEach(s=>s.shapeKeyChanged(t,i)),this.sizeBox.follow===t?(this.sizeBox.generate(this._container,i),this.sizeBox.originOffset&&(this._container.traverse(s=>{s instanceof f.Mesh&&!s.userData.isDevice&&!s.userData.isBracket&&s.geometry.translate(this.sizeBox.originOffset-this.sizeBox.translateCache,0,0),s instanceof as&&!s.props.slot.userData.ignoreOriginChanged&&s.parent&&s.parent.position.add(new f.Vector3(this.sizeBox.originOffset-this.sizeBox.translateCache,0,0))}),this.sizeBox.translateCache=this.sizeBox.originOffset,this.sizeBox.generate(this._container))):this.sizeBox.generate(this._container),["width","length","height"].includes(t)&&this._emitter.emit("size-changed",t,i),t==="goodsLength"){const s=i;this._goodsSize.length=this._layoutLengthToItemLength(s),this._applyDerivedSizesFromLayoutGoodsLength(s),this._generateRollers(),this._syncRollerGoodsBoxesFromGoodsSize(),this._syncShelvesFromGoodsSize()}t==="goodsWidth"&&(this._goodsSize.width=i,this._applyDerivedSizesFromGoodsWidth(i),this._columnCount>1&&this.setColumns(this._columnCount,!1),this._syncRollerGoodsBoxesFromGoodsSize(),this._syncShelvesFromGoodsSize())})}_syncRollerGoodsBoxesFromGoodsSize(){const e=h=>{var n;const u=[],p=[...h.children];for(;p.length;){const l=p.pop();if((n=l.userData)!=null&&n.isRollerLevelBox){u.push(l);continue}l.children&&l.children.length&&p.push(...l.children)}return u},t=Math.max(1,this._rowCount||1),i=t>1?this._rowGap:0,s=this._goodsSize.length||0,r=this._getLayoutGoodsLength(s),o=s+i,c=t>0?-r/2+s/2:0;this._rollerLevel.forEach(h=>{e(h).forEach(p=>{const n=p.children.filter(l=>l instanceof xe);for(n.forEach(l=>{l.userData.__amrRollerGoodsBox=!0,this.goods.includes(l)||this.goods.push(l)});n.length<t;){const l=new xe(this._goodsSize.width,this._goodsSize.length,this._goodsSize.height);l.userData.__amrRollerGoodsBox=!0,p.add(l),this.goods.push(l),n.push(l)}for(let l=t;l<n.length;l++){const d=n[l];this.goods=this.goods.filter(g=>g!==d),d.dispose(),d.removeFromParent()}for(let l=0;l<t;l++){const d=n[l];d.updateSize(this._goodsSize.width,this._goodsSize.length,this._goodsSize.height),d.position.y=c+o*l}})})}_syncShelvesFromGoodsSize(){const e=this.shapeKeys.has("goodsLength")||this.shapeKeys.has("goodsWidth"),t=this._getLayoutGoodsLength(this._goodsSize.length);this._shelves.forEach(i=>{let s=this._shelfSyncCache.get(i);s||(s={container:void 0,morphMeshes:[],goodsBoxes:[]},i.traverse(c=>{var h;if((h=c.userData)!=null&&h.isShelfContainer&&(s.container=c),c instanceof xe&&s.goodsBoxes.push(c),Vi(c)){const u=c,p=u.morphTargetDictionary||{};(Object.prototype.hasOwnProperty.call(p,"goodsWidth")||Object.prototype.hasOwnProperty.call(p,"goodsLength"))&&s.morphMeshes.push(u)}}),this._shelfSyncCache.set(i,s)),s.goodsBoxes.forEach(c=>{c.updateSize(this._goodsSize.length,this._goodsSize.width,this._goodsSize.height)}),s.morphMeshes.forEach(c=>{this.setShapeKeyToMesh(c,"goodsWidth",this._goodsSize.width),this.setShapeKeyToMesh(c,"goodsLength",t)});const r=s.container;if(!r)return;typeof r.userData.__goodsBaseX!="number"&&(r.userData.__goodsBaseX=r.position.x);const o=r.userData.__goodsBaseX;r.position.x=e?o+t/2:o})}_findFirstSkinnedMesh(e){if(!e)return;let t;return e.traverse(i=>{!t&&i.isSkinnedMesh&&(t=i)}),t}async loadAnimation(e,t="sglb"){let i,s;if(t==="glb"||e.endsWith(".glb")){const h=await je.loadAsync(e);i=h.animations||[],s=h.scene}else if(t==="sglb"||e.endsWith(".sglb")){const u=await new Ut({useCache:!0}).loadAsync(e);i=u.animations||[],s=u.scene}else{console.warn("[Amr.loadAnimation] 目前仅支持 glb/sglb 动画文件",{url:e,type:t});return}if(!i||i.length===0){console.warn("[Amr.loadAnimation] 文件中未找到动画",e);return}if(!this._modelRoot){console.warn("[Amr.loadAnimation] 模型尚未加载,无法绑定动画",e);return}if(!s){console.warn("[Amr.loadAnimation] 动画文件中缺少 scene,无法执行重定向",e);return}const r=this._findFirstSkinnedMesh(s),o=this._findFirstSkinnedMesh(this._modelRoot);(!r||!o)&&console.warn("[Amr.loadAnimation] 在动画或目标模型中未找到 SkinnedMesh,使用原始动画 clip",e),this._mixer||(this._mixer=new f.AnimationMixer(this._modelRoot));const c=typeof Li.retargetClip=="function";i.forEach(h=>{let u=h;if(c&&r&&o)try{u=Li.retargetClip(o,r,h)}catch(n){console.warn("[Amr.loadAnimation] 重定向动画失败,回退到原始 clip",h.name,n)}this._clips=this._clips.filter(n=>n.name!==u.name),this._clips.push(u);const p=this._mixer.clipAction(u);this._actionsMap.set(u.name,p)}),this.actions=Array.from(this._actionsMap.keys())}async load(e,t=""){this._url=e,this.name||(this.name=e.substring(e.lastIndexOf("/")+1,e.lastIndexOf("."))),!e.startsWith("blob")&&e.endsWith(".sglb");let i,s;if(t==="glb"||e.endsWith(".glb")){let o=await je.loadAsync(e);i=o.scene,s=o.animations||[]}else{const c=await new Ut({useCache:!0}).loadAsync(e);if(!c.glb)return;i=c.glb}const r=Li.clone(i);this._generateAmr(r,s),i=null,this._emitter.emit("amr-loaded")}changeSkin(e,t){e&&(e.change(t),this._app&&this._app.usePathTracing&&(this._app.sampleCount=0,this._app.usePathTracing&&(this._app.pathTracer.pausePathTracing=!1,this._app.pathTracer.updateMaterials())))}changeLogo(e,t){e.change(t.url,new f.Vector2(t.scaleX,t.scaleY),new f.Vector2(t.ox,t.oy))}getShapeKeyTargets(e){return this._shapeKeyTargets.get(e)||[]}setShapeKey(e,t,i=!0){i&&this._shapeKeyTimer&&e===this._shapeKeyCache&&clearTimeout(this._shapeKeyTimer),this._shapeKeyCache=e,this._shapeKeyTimer=window.setTimeout(()=>{this.getShapeKeyTargets(e).forEach(r=>{var h;performance.now();let o=t;r.userData[`origin_${e}`]&&(o-=r.userData[`origin_${e}`]);const c=(h=r.morphTargetDictionary)==null?void 0:h[e];c!==void 0&&r.morphTargetInfluences&&(r.morphTargetInfluences[c]=o),r instanceof f.Mesh&&r.geometry.translate(0,0,1e-9)}),i&&this._emitter.emit("shape-key-changed",e,t)},0)}_generateAmr(e,t){var i,s;this._modelRoot=e,this._actionsMap.clear(),this.actions=[],this._clips=[],t&&t.length&&(this._mixer=new f.AnimationMixer(e),this._clips=t,t.forEach(r=>{const o=this._mixer.clipAction(r);this._actionsMap.set(r.name,o)}),this.actions=t.map(r=>r.name)),this._shapeKeyTargets.clear(),this._shapeKeys.clear(),e.traverse(r=>{if(r.userData.isShelf&&(this._shelf=r),r.userData.isFork&&(this._fork=r),r.userData.isMast&&r.userData.mastLevel&&this._masts.set(r.userData.mastLevel,r),r.userData.isJack&&(this._jack=r),r.userData.isLift&&(this._lift=r),r.userData.isRollerLevel&&this._rollerLevel.set(r.userData.level||0,r),r.userData.isCenterModel&&(r.visible=this.useCenterModel),r.userData.isSwitch&&r.userData.switchName==="top"&&(this._rollerTop=r),r.userData.isLiftBracket&&(this._liftBrackets.push(r),r.visible=this._useLift),r.userData.isBaffle&&(this._rollerBaffle=r,r.visible=!this._useLift),r.userData.isRoller&&(this._roller=r,this._roller.visible=!1,this._generateRollers()),r.userData.isRollerLevelBox){this._rollerGoodsBox=r;const o=new xe(this._goodsSize.width,this._goodsSize.length,this._goodsSize.height);r.add(o),this.goods.push(o)}Object.keys(r.morphTargetDictionary||{}).forEach(o=>{let c=r.morphTargetInfluences[r.morphTargetDictionary[o]];r.userData[`origin_${o}`]&&(c+=r.userData[`origin_${o}`]),this._shapeKeys.has(o)||this._shapeKeys.set(o,c);const h=this._shapeKeyTargets.get(o);h?h.push(r):this._shapeKeyTargets.set(o,[r])})}),e.traverse(r=>{if(r instanceof f.Mesh){if(r.castShadow=!0,r.receiveShadow=!0,r.material)if(Array.isArray(r.material))r.material.forEach(c=>{c.userData.changeColor&&(this.skins.find(h=>h.name===c.userData.name)||this.skins.push(new ys({name:c.userData.name,target:c})))});else{if(r.material.userData.isVideo&&r.material.userData.video){const c=r.material.userData.video;let h=this._videoCache.get(c);h||(h=document.createElement("video"),h.src=c,h.crossOrigin="anonymous",h.loop=!0,h.muted=!0,h.playsInline=!0,h.autoplay=!0,h.preload="auto",this._videoCache.set(c,h)),h.play().catch(()=>{}),r.material.map&&r.material.map.dispose(),r.material.emissiveMap&&r.material.emissiveMap.dispose();const u=new f.VideoTexture(h);u.colorSpace=f.SRGBColorSpace,r.material.map=u,r.material.emissiveMap=u,r.material.emissive||(r.material.emissive=new f.Color(16777215)),r.material.emissiveIntensity=1,r.material.needsUpdate=!0}if(r.material.userData.isBreathLight&&r.material.emissiveIntensity){r.material.emissive||(r.material.emissive=new f.Color(16777215)),r.material.emissiveIntensity=2,r.material.toneMapped=!1;const c=1e3,h=new ne.Tween(r.material).to({emissiveIntensity:.2}).easing(ne.Easing.Quintic.InOut).duration(c),u=new ne.Tween(r.material).to({emissiveIntensity:2}).easing(ne.Easing.Quintic.InOut).duration(c);h.onComplete(()=>u.start()),u.onComplete(()=>h.start()),h.start(),this._breathLights.push(h,u)}r.material.userData.changeColor&&(this.skins.find(c=>c.name===r.material.userData.name)||this.skins.push(new ys({name:r.material.userData.name,target:r.material})))}if(r.material)if(Array.isArray(r.material))r.material.forEach(h=>{if(h.userData.isLOGO){r.material.transparent=!0;let u;const p={width:0,height:0};r.material.map&&r.material.map.image&&(p.width=r.material.map.image.width,p.height=r.material.map.image.height,u=os(r.material.map.image)),r.material.needsUpdate=!0;const n=new ls({name:h.userData.name,target:r,size:or(r),imageSize:p,imageUrl:u});this._logos.push(n)}h.userData.isTransparent&&(h.transparent=!0),this._materialsCache.set(h.uuid,{opacity:h.opacity,transparent:h.transparent,roughness:h.roughness,metalness:h.metalness,color:h.color,mat:h})});else{const c=r.material;if(c.userData.isLOGO){r.material.transparent=!0;let h;const u={width:0,height:0};r.material.map&&r.material.map.image&&(u.width=r.material.map.image.width,u.height=r.material.map.image.height,h=os(r.material.map.image));const p=new ls({name:c.userData.name,target:r,size:or(r),imageSize:u,imageUrl:h});this._logos.push(p)}c.userData.isTransparent&&(c.transparent=!0),this._materialsCache.set(c.uuid,{opacity:c.opacity,transparent:c.transparent,roughness:c.roughness,metalness:c.metalness,color:c.color,mat:c})}}this.generateController(r,e),this.generateDimension(r,e);const o=this.generateSlot(r,e);o&&this._slots.push(o),r.userData.isOrigin&&Object.keys(r.userData).forEach(h=>{if(h.startsWith("follow_")){const u=h.replace("follow_","");this.shapeKeys.has(u)&&(this.sizeBox.follow=u,this.sizeBox.followOrigin=this._shapeKeys.get(u)||0,this.sizeBox.followScale=r.userData[h])}})}),this.slots.forEach(r=>{r.props.mirrorTarget&&(r.mirrorTarget=this.slots.find(o=>o.props.slot.name===r.props.mirrorTarget))}),e.updateMatrixWorld(!0),this._container.add(e),this._buildJointChain(e),this._disposeIkControllers(),this._ikChains.length&&(this.ikControllers=Dl(this._ikChains,this,{camera:(i=this._app)==null?void 0:i.camera,domElement:(s=this._app)==null?void 0:s.renderer.domElement},{onDraggingChanged:(r,o)=>{this._onIkDraggingChanged(r,o)}}),this._ikChains.forEach((r,o)=>{r.controller=this.ikControllers[o]})),this.sizeBox.generate(e),this.sizeBox.show()}_syncIkDraggingState(){this._app&&(this._app.controls.enabled=this._ikDraggingControllers.size===0)}_onIkDraggingChanged(e,t){t?this._ikDraggingControllers.add(e):this._ikDraggingControllers.delete(e),this._syncIkDraggingState()}_disposeIkControllers(){this.ikControllers.forEach(e=>e.dispose()),this.ikControllers=[],this._ikChains.forEach(e=>{e.controller=void 0}),this._ikDraggingControllers.clear(),this._syncIkDraggingState()}_buildJointChain(e){if(this._ikChains=[],!this._ikChains.length){const t=[];e.traverse(i=>{i!=null&&i.name&&i.name.startsWith("ArmatureRoot")&&t.push(i)}),t.sort((i,s)=>i.name.localeCompare(s.name)),t.forEach(i=>{const{joints:s,orientation:r}=this._buildIKChainParams(i);if(s.length<2)return;const o={enabled:!0,...r};this._ikChains.push({name:i.name,joints:s,baseLinks:s.slice(),toolLinks:[],orientation:o})})}}_findIkChainByNode(e){var t;for(const i of this._ikChains){if(!((t=i.baseLinks)!=null&&t.length))continue;const s=new Set(i.baseLinks.map(o=>o.object.uuid));let r=e;for(;r;){if(s.has(r.uuid))return i;r=r.parent}}}updateIkJointChainByTool(e,t){if(!e)return;const i=this._findIkChainByNode(e);if(console.log("chain",i),!i||!i.controller||!i.baseLinks||i.baseLinks.length<2)return;const s=(u,p)=>{if(!p.length)return!1;const n=new Set;return u.traverse(l=>n.add(l.uuid)),p.some(l=>n.has(l.uuid))};if(t==="uninstall"){if(!(!!i.toolRootUuid&&e.uuid===i.toolRootUuid||i.toolLinks.length>0&&s(e,i.toolLinks.map(p=>p.object))))return;i.toolLinks=[],i.toolRootUuid=void 0,i.joints=i.baseLinks.slice(),i.controller.updateJointChain(i.joints);return}const{joints:r,orientation:o}=this._buildIKChainParams(e);if(!r.length)return;o&&i.controller.setOrientation(o);const c=!!i.toolRootUuid&&e.uuid===i.toolRootUuid,h=i.toolLinks.length>0;if(c&&h){i.joints=[...i.baseLinks,...i.toolLinks],i.controller.updateJointChain(i.joints);return}i.toolRootUuid=e.uuid,i.toolLinks=r,i.joints=[...i.baseLinks,...i.toolLinks],i.controller.updateJointChain(i.joints)}_buildIKChainParams(e){var o,c,h,u;if(!e)return{joints:[],orientation:void 0};const t=[];let i;const s=p=>{const n=p.children.find(l=>{var d,g;return((d=l.userData)==null?void 0:d.isJoint)||((g=l.userData)==null?void 0:g.isTcp)});if(n)return n;for(const l of p.children){const d=s(l);if(d)return d}};let r=(o=e.userData)!=null&&o.isJoint||(c=e.userData)!=null&&c.isTcp?e:s(e);for(;r;){if(console.log("cur",r),(h=r.userData)!=null&&h.isJoint){const p=this._parseIkAxes(r.userData.ikAxes);this._fillInitialRotationValues(r,p),t.push({object:r,axes:p})}else if((u=r.userData)!=null&&u.isTcp){const p=this._parseIkAxes(r.userData.ikAxes);this._fillInitialRotationValues(r,p),t.push({object:r,ikTcp:!0,axes:p}),i=this._parseIkOrientation(r.userData.ikOrientation)??i;break}r=s(r)}return{joints:t,orientation:i}}_fillInitialRotationValues(e,t){if(!t||!e)return;const i=e.rotation;t.forEach(s=>{const{axis:r}=s;Math.abs(r.x)>.9?s.value=i.x*Math.sign(r.x):Math.abs(r.y)>.9?s.value=i.y*Math.sign(r.y):Math.abs(r.z)>.9&&(s.value=i.z*Math.sign(r.z))})}_axisFromLetter(e){const t=String(e).trim().toUpperCase();if(t==="X")return new f.Vector3(1,0,0);if(t==="Y")return new f.Vector3(0,1,0);if(t==="Z")return new f.Vector3(0,0,1)}_parseIkAxes(e){if(!e||typeof e!="string")return;const t=JSON.parse(e);if(!(!Array.isArray(t)||t.length===0))return t.map(i=>{const s=this._axisFromLetter(i.axis)??new f.Vector3(0,0,0),r=typeof i.min=="number"?f.MathUtils.degToRad(i.min):void 0,o=typeof i.max=="number"?f.MathUtils.degToRad(i.max):void 0;return{axis:s,min:r,max:o}})}_parseIkOrientation(e){if(!e)return;const t=typeof e=="string"?JSON.parse(e):e,i=this._axisFromLetter(t.forwardAxis),s=this._axisFromLetter(t.upAxis);if(!(!i||!s))return{forwardAxis:i,upAxis:s}}setHeight(e){this.setShapeKey("height",e)}setWeight(e){this.setShapeKey("width",e)}setLength(e){this.setShapeKey("length",e)}limitValue(e){this.name==="SFL-CDD14"&&(e>1.6?this.setShapeKey("mast",1):this.setShapeKey("mast",0)),["SFL-CDD20","SFL-CDD20-Y"].includes(this.name)&&(e>1.6?this.setShapeKey("mast",1):this.setShapeKey("mast",0)),this.name==="SFL-CDD15"&&(e>2.43?this.setShapeKey("mast",1):this.setShapeKey("mast",0)),["SFL-CPD20-Y","SFL-CPD30-Y"].includes(this.name)&&(e>3.5?this.setShapeKey("mast",2):e>3?this.setShapeKey("mast",1):this.setShapeKey("mast",0))}setForkHeight(e){if(this._fork){if(e>this._forkMaxHeight&&(e=this._forkMaxHeight),this._fork.position.z=e,this._masts.size===1){const t=this._masts.get(2),i=(t==null?void 0:t.userData.startHeight)||.1;t&&(t.position.z=(e-i)*.5)}this._emitter.emit("fork-height-change",e)}}setForkMaxHeight(e){this._fork&&(this._forkMaxHeight=e,this.limitValue(e),this.controllers.forEach(t=>{t.name.toLowerCase().includes("fork")&&(t.props.max=e)}),this._fork&&this.forkHeight>this._forkMaxHeight&&this.setForkHeight(e))}setLiftHeight(e){if(this._lift)if(e>this._liftMaxHeight&&(e=this._liftMaxHeight),this._lift instanceof Map){const t=this._lift.get(0);t&&(t.position.z=e)}else this._lift&&(this._lift.position.z=e)}getLiftMaxHeight(){return this._liftMaxHeight}setLiftMaxHeight(e){if(!this._lift)return;this._liftMaxHeight=e,this.limitValue(e),this.controllers.forEach(r=>{r.name.toLowerCase().includes("lift")&&(r.props.max=e)}),this.liftHeight>this._liftMaxHeight&&this.setLiftHeight(e);let t=.46;this.levelOffset&&(t=this.levelOffset+.1);let i=e+t;const s=this.getShelfMinHeight()+t||0;i<s&&(i=s),this.setHeight(i)}setJackMaxHeight(e){this._jack&&(this._jackMaxHeight=e,this.limitValue(e),this.controllers.forEach(t=>{t.name.toLowerCase().includes("jack")&&(t.props.max=e)}),this.jackHeight>this._jackMaxHeight&&this.setJackHeight(e))}setJackHeight(e){this._jack&&(e>this._jackMaxHeight&&(e=this._jackMaxHeight),requestAnimationFrame(()=>{this.setShapeKey("jackHeight",e,!1)}),this._jack.position.z=e)}setLevel(e){}setGoodsSize(e){this._goodsSize.length=e.length,this._goodsSize.width=e.width,this._goodsSize.height=e.height,this.setShelfLevel(this._shelfMaxLevel),this.setRoller(),this._rollerLevel.forEach(t=>{t.traverse(i=>{i instanceof xe&&i.updateSize(e.width,e.length,e.height)})})}setRoller(){}get isTopInvert(){if(this._rollerTop)return Math.abs(this._rollerTop.rotation.z)===Math.PI/2}setTopInvert(e=!0){this._rollerTop&&(this._rollerTop.rotation.z=e?Math.PI/2:0,this.setShapeKey("switch",e?1:0),this.setShapeKey("goodsWidth",this.goodsSize.width),this.setShapeKey("goodsLength",this._getLayoutGoodsLength(this.goodsSize.length)))}get useLift(){return this._useLift}set useLift(e){var t;this._lift&&(this._useLift=e,(t=this._rollerTop)==null||t.traverse(i=>{i.userData.isBaffle&&(i.visible=!e),i.userData.isLiftBracket&&(i.visible=e)}))}get columns(){return this._columnCount}get rows(){return this._rowCount}setRows(e){const t=Math.max(1,Math.floor(e||1));if(t===this._rowCount)return;this._rowCount=t;const i=this._getLayoutGoodsLength(this._goodsSize.length);this.setShapeKey("goodsLength",i,!1),this._applyDerivedSizesFromLayoutGoodsLength(i),this._generateRollers(),this._syncRollerGoodsBoxesFromGoodsSize(),this._syncShelvesFromGoodsSize()}_getLayoutGoodsLength(e=this._goodsSize.length){const t=Math.max(1,this._rowCount||1),i=e||0;return t<=1?i:i*t+this._rowGap*(t-1)}_layoutLengthToItemLength(e){const t=Math.max(1,this._rowCount||1);if(t<=1)return Math.max(0,e||0);const i=this._rowGap*(t-1);return Math.max(0,((e||0)-i)/t)}setGoodsItemLength(e){this._goodsSize.length=e;const t=this._getLayoutGoodsLength(e);this.setShapeKey("goodsLength",t)}_applyDerivedSizesFromLayoutGoodsLength(e){const t=e+.14-.54;this.setShapeKey("boxLength",t);const i=e+.14;if(this.setShapeKey("topWidth",i),this.isTopInvert){const s=e-.259;this.setShapeKey("length",s)}else this.setShapeKey("width",i)}_applyDerivedSizesFromGoodsLength(e){const t=this._getLayoutGoodsLength(e);this._applyDerivedSizesFromLayoutGoodsLength(t)}_applyDerivedSizesFromGoodsWidth(e){const t=Math.max(1,this._columnCount||1),i=.125,s=t===1?e+i:(e+i)*t+this._columnGap*(t-1),r=s+.06;this.setShapeKey("boxWidth",r);const o=s+.085;if(this.setShapeKey("topLength",o),this.isTopInvert){const c=s+.485;this.setShapeKey("width",c)}else this.setShapeKey("length",o)}setColumns(e,t=!0){const i=Math.max(1,Math.floor(e||1));this._columnCount=i,this._rollerLevel.forEach(s=>{const r=s.children.filter(d=>{var g;return(g=d.userData)==null?void 0:g.isRollerLevelBox}),o=r.length>0?(Math.min(...r.map(d=>d.position.x))+Math.max(...r.map(d=>d.position.x)))/2:0;s.children.filter(d=>{var g,v;return((g=d.userData)==null?void 0:g.isRollerLevelBox)&&((v=d.userData)==null?void 0:v.cloned)}).forEach(d=>s.remove(d));const c=s.children.find(d=>d.userData.isRollerLevelBox&&!d.userData.cloned)||s.children.find(d=>d.userData.isRollerLevelBox);if(!c)return;const h=el(c,s,new f.Vector3),u=this._columnGap,n=h.x+u,l=(i-1)*n/2;c.position.x=o-l;for(let d=1;d<i;d++){const g=c.clone(!0);g.userData.cloned=!0,this._stripRollerInstances(g),this.regenerateShapeKeyNode(g),g.position.x=o-l+d*n,s.add(g)}}),t&&this._applyDerivedSizesFromGoodsWidth(this.goodsSize.width),this._pruneShapeKeyTargets(),this.setShapeKey("goodsWidth",this._goodsSize.width,!1),this.setShapeKey("goodsLength",this._getLayoutGoodsLength(this._goodsSize.length),!1),this._generateRollers(),this._syncRollerGoodsBoxesFromGoodsSize()}get levels(){return this._levelCount}setLevels(e){var o;const t=Math.max(1,Math.floor(e||1));this._levelCount=t;const i=this._rollerLevel.size,s=t-i,r=this._rollerLevel.get(0);if(s>0&&r){for(let h=i;h<t;h++){const u=r.clone(!0);u.visible=!0,this._stripRollerInstances(u),u.position.z=r.position.z+.2*h,u.userData.level=h,this._rollerLevel.set(h,u),(o=r.parent)==null||o.add(u),this.regenerateShapeKeyNode(u),u.traverse(p=>{p instanceof xe&&(p.updateSize(this.goodsSize.width,this.goodsSize.length,this.goodsSize.height),this.goods.push(p))})}this._columnCount>1&&this.setColumns(this._columnCount,!1),this._generateRollers(),this._syncRollerGoodsBoxesFromGoodsSize()}else for(let c=0;c<i;c++){const h=this._rollerLevel.get(c);h&&(h.visible=c<t)}}regenerateShapeKeyNode(e){e&&e.traverse(t=>{Vi(t)&&Object.keys(t.morphTargetDictionary||{}).forEach(i=>{const s=this._shapeKeyTargets.get(i);s&&s.push(t)})})}_stripRollerInstances(e){const t=[];e.traverse(i=>{var s,r;((s=i==null?void 0:i.userData)!=null&&s.__amrRollerInstance||(r=i==null?void 0:i.userData)!=null&&r.isCloned)&&t.push(i)}),t.forEach(i=>{i.parent&&i.removeFromParent()})}_isInAmrContainer(e){let t=e;for(;t;){if(t===this._container||t===this)return!0;t=t.parent}return!1}_pruneShapeKeyTargets(){this._shapeKeyTargets.forEach((e,t)=>{const i=new Set,s=[];for(const r of e)r&&this._isInAmrContainer(r)&&(i.has(r.uuid)||(i.add(r.uuid),s.push(r)));this._shapeKeyTargets.set(t,s)})}setRollerHeight(e,t){const i=this._rollerLevel.get(e);i&&(i.position.z=t)}_generateRollers(){if(!this._roller)return;let e=this._getLayoutGoodsLength(this._goodsSize.length);e=e||.5;const t=.05;let i=.02;const r=e-i,o=t+i;let c=Math.floor(r/o);const h=r%o,u=l=>{var v;const d=[],g=[...l.children];for(;g.length;){const m=g.pop();if((v=m.userData)!=null&&v.isRollerLevelBox){d.push(m);continue}m.children&&m.children.length&&g.push(...m.children)}return d},p=[];this._rollerLevel.forEach(l=>{p.push(...u(l))});let n=!1;if(p.forEach(l=>{const d=[];l.traverse(g=>{var v,m;g!==l&&((v=g==null?void 0:g.userData)!=null&&v.isCloned)&&!((m=g==null?void 0:g.userData)!=null&&m.__amrRollerInstance)&&d.push(g)}),d.forEach(g=>g.removeFromParent()),d.length&&(n=!0)}),n&&this._pruneShapeKeyTargets(),c>0){c>1&&(i+=h/(c+2));const l=t+i,d=-e/2+i+t/2;p.forEach(g=>{let v=this._rollerPools.get(g);for(v||(v=[],this._rollerPools.set(g,v));v.length<c;){const m=this._roller.clone(!0);m.visible=!1,m.userData.__amrRollerInstance=!0,m.userData.isCloned=!0,g.add(m),this.regenerateShapeKeyNode(m),v.push(m)}for(let m=0;m<c;m++){const _=v[m];_.parent!==g&&g.add(_),_.visible=!0,_.position.y=d+l*m}for(let m=c;m<v.length;m++)v[m].visible=!1})}else p.forEach(l=>{const d=this._rollerPools.get(l);d&&d.forEach(g=>g.visible=!1)})}getShelfMinHeight(){const e=this.levelOffset,t=this._shelfMaxLevel,i=this._shelves.get(0);return i?i.position.z+e*t+.1:0}getShelfMaxShelfHeight(){const e=this.levelOffset,t=this._shelfMaxLevel,i=this._shelves.get(0);if(i)return i.position.z+e*(t-1)}get levelOffset(){return this._goodsSize.height+.2}setShapeKeyToMesh(e,t,i){if(!Object.keys(e.morphTargetDictionary||{}).includes(t))return;const s=e.morphTargetDictionary[t];e.morphTargetInfluences&&(e.morphTargetInfluences[s]=i),e.geometry.translate(0,0,1e-9)}setShelfLevel(e=3){var r;if(!this._shelf)return;this._shelfMaxLevel=e;const t=this.levelOffset,i=this._getLayoutGoodsLength(this._goodsSize.length);this._shelves.delete(0),this._shelves.forEach(o=>{De(o),o.parent&&o.removeFromParent()}),this.goods=this.goods.filter(o=>{var c;return(c=o==null?void 0:o.userData)==null?void 0:c.__amrRollerGoodsBox}),this._shelves.clear(),this._shelves.set(0,this._shelf);for(let o=1;o<e;o++){if(!this._shelf)return;this._shelf.traverse(u=>{Vi(u)&&(this.setShapeKeyToMesh(u,"goodsWidth",this._goodsSize.width),this.setShapeKeyToMesh(u,"goodsLength",i))});const c=this._shelf.clone(!0);c.position.z+=t*o,this._shelves.set(o,c),(r=this._shelf.parent)==null||r.add(c);let h;if(c.traverse(u=>{u.userData.isShelfContainer&&(h=u)}),(this.shapeKeys.has("goodsLength")||this.shapeKeys.has("goodsWidth"))&&h&&(typeof h.userData.__goodsBaseX!="number"&&(h.userData.__goodsBaseX=h.position.x),h.position.x=h.userData.__goodsBaseX+i/2),h){const u=new xe(this._goodsSize.length,this._goodsSize.width,this._goodsSize.height);if(u.userData.__amrShelfGoodsBox=!0,h.add(u),this.goods.push(u),o===1){const p=new xe(this._goodsSize.length,this._goodsSize.width,this._goodsSize.height);p.userData.__amrShelfGoodsBox=!0,p.position.z-=t,h.add(p),this.goods.push(p)}}}const s=this.getShelfMinHeight()||0;this._liftMaxHeight<s&&this.setLiftMaxHeight(s)}generateOuterLine(){this.traverse(e=>{if(e.userData.isOuterObject){const t=this.sizeBox.radius;this._outline?this._outline.update(t):(this._outline=new on(t,0),this.add(this._outline))}})}generateController(e,t){if(this.showController){if(e.userData.isForkController&&e.userData.target){const i=e.userData.target.name,{min:s,max:r}=e.userData;let o;if(t.traverse(h=>{h.name===i&&(o=h)}),!o)return;const c=new ur({name:"",target:i,default:0,min:s,max:r},o);e.add(c)}else if(e.userData.isController&&e.userData.target){const i=e.userData.target.name,{min:s,max:r}=e.userData;let o;if(t.traverse(h=>{h.name===i&&(o=h)}),!o)return;const c=new ur({name:"",userData:e.userData,target:e.userData.key,default:0,min:s||0,max:r||1},o);e.add(c),this.controllers.push(c),c.addListener("change",()=>{this.ikControllers.forEach(h=>{h.enabled=!1}),clearTimeout(this._ikControllersTimer),this._ikControllersTimer=setTimeout(()=>{this.ikControllers.forEach(h=>{h.enabled=!0,h.syncTargetToEffector()})},100)}),(o.userData.isFork||o.userData.isLift||o.userData.isJack)&&(this._forkMaxHeight=r||1,this._liftMaxHeight=r||1,this._jackMaxHeight=r||1,c.addListener("change",h=>{this.setForkHeight(h),this.setLiftHeight(h),this.setJackHeight(h)}))}}}generateDimension(e,t){if(e.userData.isDimension){const i=e.userData.divider,s=tl(e.userData.startOrigin),r=e.userData.axios;let o,c;if(r==="x"?(o=new f.Vector3(e.userData.start-e.position.x,0,0),c=o.clone().setX(e.userData.end-e.position.x)):r==="z"?(o=new f.Vector3(0,e.userData.start-e.position.y,0),c=o.clone().setY(e.userData.end-e.position.y)):(o=new f.Vector3(0,0,e.userData.start-e.position.z),c=o.clone().setZ(e.userData.end-e.position.z)),!Object.keys(e.userData).flatMap(n=>n.startsWith("target")?e.userData[n].name:[]).length)return;const p=new vl({start:o,end:c,startOrigin:s,axios:r,divider:i});e.add(p)}}generateSlot(e,t){var i,s;if(e.userData.isSlot){const r=e.userData.name,o=e.userData.isMirror,c=(i=e.userData.mirrorSlot)==null?void 0:i.name;if(r){const h=e.userData.holeTarget&&e.userData.holeTarget.name;let u;h&&t.traverse(d=>{d.name===h&&(u=d)});const p=new Map;Object.keys(e.userData).forEach(d=>{if(d.startsWith("follow_")){const g=d.split("_")[1];if(g){let v=e.userData[d];p.set(g,{scale:v,initPos:e.position.clone(),origin:this.shapeKeys.get(g)||0})}}});const n=(s=this._app)==null?void 0:s.props.isMobile,l=new as({name:r,follows:p,slot:e,show:this._showSlots,isMirror:o,mirrorTarget:c,isMobile:n});return l.holeTarget=u,l.addEventListener(J.ON_DROP,d=>{this._app&&this._app.props.useSound&&this._app.sound.play()}),l.addEventListener(J.ON_DEVICE_REPLACED,d=>{d&&this.updateIkJointChainByTool(d,"install")}),l.addEventListener(J.ON_DEVICE_DELETED,d=>{d&&this.updateIkJointChainByTool(d,"uninstall")}),l.addEventListener(J.ON_BEFORE_SELECTED,d=>{this._slots.forEach(g=>{g.selected&&(g.selected=!1)})}),l.addEventListener(J.ON_ERROR_STATE_CHANGE,d=>{var v;if(!this._app)return;const g=(v=this._app)==null?void 0:v._outlinePassError;if(g)if(g.selectedObjects=g.selectedObjects.filter(m=>!!m.parent),d){if(l.device){if(g.selectedObjects.find(_=>{var y;return _.parent===((y=l.device)==null?void 0:y.parent)}))return;g.selectedObjects=[l.device,...g.selectedObjects]}}else l.device&&(g.selectedObjects=g.selectedObjects.filter(m=>{var _;return m.parent!==((_=l.device)==null?void 0:_.parent)}))}),l}}}clean(){this._emitter.removeAllListeners(),this.controllers.forEach(e=>e.dispose()),this.controllers=[],this._levels.forEach(e=>e.destroy()),this._levels.clear(),this._rollerLevel.clear(),De(this._container),this._slots=[],this._logos=[],this._skins=[],this._materialsCache.clear(),this.opacityCache=void 0,this._breathLights.forEach(e=>e.stop()),this._breathLights=[],this.sizeBox.reset(),this._shapeKeyTargets.clear(),this._shapeKeys.clear(),this._shelfSyncCache=new WeakMap,this._rollerPools=new WeakMap,this._shapeKeyTimer&&(clearTimeout(this._shapeKeyTimer),this._shapeKeyTimer=0),this._currentAction=null,this._pendingFinishedCallback&&this._mixer&&(this._mixer.removeEventListener("finished",this._pendingFinishedCallback),this._pendingFinishedCallback=null),this._mixer&&(this._mixer.stopAllAction(),this._modelRoot&&this._mixer.uncacheRoot(this._modelRoot)),this._mixer=void 0,this._clips=[],this._actionsMap.clear(),this.actions=[],this._disposeIkControllers(),this._lift=void 0,this._fork=void 0,this._jack=void 0,this._roller=void 0,this._rollerBaffle=void 0,this._rollerTop=void 0,this._shelf=void 0,this._rollerGoodsBox=void 0,this._modelRoot=void 0,this.goods.forEach(e=>{e.dispose(),e.parent&&e.removeFromParent()}),this.goods=[],this._liftBrackets=[],this._videoCache.forEach(e=>{e.pause(),e.removeAttribute("src"),e.load(),e.remove()}),this._videoCache.clear(),this._masts.clear(),this._shelves.clear(),this._outline&&(this._outline.removeFromParent(),this._outline=void 0),this._app&&this._onTicker&&this._app.renderer.domElement.removeEventListener("ticker",this._onTicker),this._onTicker=void 0}destroy(){this.clean(),this.sizeBox.destroy()}playAction(e,t){const i=Object.keys(t||{}).includes("reset")?t==null?void 0:t.reset:!0,s=this._actionsMap.get(e);if(!s||!this._mixer)return Promise.reject(new Error(`Action "${e}" not found or mixer not initialized.`));if(s.isRunning()&&s===this._currentAction)return Promise.resolve();const r=this._currentAction,o=r===s,c=o?0:t!=null&&t.fadeIn?t==null?void 0:t.fadeIn:.5,h=r&&!o&&r.isRunning();this._actionsMap.forEach(n=>{n!==s&&n!==r&&(n.stopFading(),n.setEffectiveWeight(0),n.stop())});const u=(t==null?void 0:t.loop)??!1;(i||!s.isRunning())&&s.reset(),s.enabled=!0,s.setEffectiveTimeScale((t==null?void 0:t.timeScale)??1),s.setEffectiveWeight(1),s.paused=!1,s.setLoop(u?f.LoopRepeat:f.LoopOnce,u?1/0:1),s.clampWhenFinished=(t==null?void 0:t.clampWhenFinished)??!u,s.play();const p=(t==null?void 0:t.timeScale)??1;return h?(r.stopFading(),r.enabled=!0,r.setEffectiveWeight(1),r.crossFadeTo(s,c,!1)):c>0&&s.fadeIn(c),s.setEffectiveTimeScale(p),this._currentAction=s,new Promise(n=>{this._pendingFinishedCallback&&this._mixer&&this._mixer.removeEventListener("finished",this._pendingFinishedCallback);const l=d=>{var g;d.action===s&&((g=this._mixer)==null||g.removeEventListener("finished",l),this._pendingFinishedCallback=null,n())};this._pendingFinishedCallback=l,this._mixer.addEventListener("finished",l)})}pauseAction(e){const t=this._actionsMap.get(e);t&&(t.paused=!0)}stopAction(e,t=.3){const i=this._actionsMap.get(e);return!i||!i.isRunning()?Promise.resolve():(this._currentAction===i&&(this._currentAction=null),t>0?(i.fadeOut(t),new Promise(s=>{setTimeout(()=>{i.stop(),s()},t*1e3)})):(i.stop(),Promise.resolve()))}stopAllActions(e=.3){return this._mixer?(this._currentAction=null,e>0?(this._actionsMap.forEach(t=>{t.isRunning()&&t.fadeOut(e)}),new Promise(t=>{setTimeout(()=>{var i;(i=this._mixer)==null||i.stopAllAction(),t()},e*1e3)})):(this._mixer.stopAllAction(),Promise.resolve())):Promise.resolve()}}const ln=0,Ll=1,Pl=2,_r=2,Hi=1.25,vr=1,Vt=6*4+4+4,Mi=65535,Il=Math.pow(2,-24),Gi=Symbol("SKIP_GENERATION");function Rl(a){return a.index?a.index.count:a.attributes.position.count}function xt(a){return Rl(a)/3}function El(a,e=ArrayBuffer){return a>65535?new Uint32Array(new e(4*a)):new Uint16Array(new e(2*a))}function kl(a,e){if(!a.index){const t=a.attributes.position.count,i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=El(t,i);a.setIndex(new f.BufferAttribute(s,1));for(let r=0;r<t;r++)s[r]=r}}function cn(a){const e=xt(a),t=a.drawRange,i=t.start/3,s=(t.start+t.count)/3,r=Math.max(0,i),o=Math.min(e,s)-r;return[{offset:Math.floor(r),count:Math.floor(o)}]}function hn(a){if(!a.groups||!a.groups.length)return cn(a);const e=[],t=new Set,i=a.drawRange,s=i.start/3,r=(i.start+i.count)/3;for(const c of a.groups){const h=c.start/3,u=(c.start+c.count)/3;t.add(Math.max(s,h)),t.add(Math.min(r,u))}const o=Array.from(t.values()).sort((c,h)=>c-h);for(let c=0;c<o.length-1;c++){const h=o[c],u=o[c+1];e.push({offset:Math.floor(h),count:Math.floor(u-h)})}return e}function Fl(a){if(a.groups.length===0)return!1;const e=xt(a),t=hn(a).sort((r,o)=>r.offset-o.offset),i=t[t.length-1];i.count=Math.min(e-i.offset,i.count);let s=0;return t.forEach(({count:r})=>s+=r),e!==s}function Ni(a,e,t,i,s){let r=1/0,o=1/0,c=1/0,h=-1/0,u=-1/0,p=-1/0,n=1/0,l=1/0,d=1/0,g=-1/0,v=-1/0,m=-1/0;for(let _=e*6,y=(e+t)*6;_<y;_+=6){const w=a[_+0],x=a[_+1],b=w-x,T=w+x;b<r&&(r=b),T>h&&(h=T),w<n&&(n=w),w>g&&(g=w);const M=a[_+2],L=a[_+3],C=M-L,I=M+L;C<o&&(o=C),I>u&&(u=I),M<l&&(l=M),M>v&&(v=M);const D=a[_+4],A=a[_+5],S=D-A,P=D+A;S<c&&(c=S),P>p&&(p=P),D<d&&(d=D),D>m&&(m=D)}i[0]=r,i[1]=o,i[2]=c,i[3]=h,i[4]=u,i[5]=p,s[0]=n,s[1]=l,s[2]=d,s[3]=g,s[4]=v,s[5]=m}function Bl(a,e=null,t=null,i=null){const s=a.attributes.position,r=a.index?a.index.array:null,o=xt(a),c=s.normalized;let h;e===null?(h=new Float32Array(o*6*4),t=0,i=o):(h=e,t=t||0,i=i||o);const u=s.array,p=s.offset||0;let n=3;s.isInterleavedBufferAttribute&&(n=s.data.stride);const l=["getX","getY","getZ"];for(let d=t;d<t+i;d++){const g=d*3,v=d*6;let m=g+0,_=g+1,y=g+2;r&&(m=r[m],_=r[_],y=r[y]),c||(m=m*n+p,_=_*n+p,y=y*n+p);for(let w=0;w<3;w++){let x,b,T;c?(x=s[l[w]](m),b=s[l[w]](_),T=s[l[w]](y)):(x=u[m+w],b=u[_+w],T=u[y+w]);let M=x;b<M&&(M=b),T<M&&(M=T);let L=x;b>L&&(L=b),T>L&&(L=T);const C=(L-M)/2,I=w*2;h[v+I+0]=M+C,h[v+I+1]=C+(Math.abs(M)+C)*Il}}return h}function Z(a,e,t){return t.min.x=e[a],t.min.y=e[a+1],t.min.z=e[a+2],t.max.x=e[a+3],t.max.y=e[a+4],t.max.z=e[a+5],t}function yr(a){let e=-1,t=-1/0;for(let i=0;i<3;i++){const s=a[i+3]-a[i];s>t&&(t=s,e=i)}return e}function xr(a,e){e.set(a)}function wr(a,e,t){let i,s;for(let r=0;r<3;r++){const o=r+3;i=a[r],s=e[r],t[r]=i<s?i:s,i=a[o],s=e[o],t[o]=i>s?i:s}}function si(a,e,t){for(let i=0;i<3;i++){const s=e[a+2*i],r=e[a+2*i+1],o=s-r,c=s+r;o<t[i]&&(t[i]=o),c>t[i+3]&&(t[i+3]=c)}}function Lt(a){const e=a[3]-a[0],t=a[4]-a[1],i=a[5]-a[2];return 2*(e*t+t*i+i*e)}const Te=32,Ol=(a,e)=>a.candidate-e.candidate,Ee=new Array(Te).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),ri=new Float32Array(6);function zl(a,e,t,i,s,r){let o=-1,c=0;if(r===ln)o=yr(e),o!==-1&&(c=(e[o]+e[o+3])/2);else if(r===Ll)o=yr(a),o!==-1&&(c=Vl(t,i,s,o));else if(r===Pl){const h=Lt(a);let u=Hi*s;const p=i*6,n=(i+s)*6;for(let l=0;l<3;l++){const d=e[l],m=(e[l+3]-d)/Te;if(s<Te/4){const _=[...Ee];_.length=s;let y=0;for(let x=p;x<n;x+=6,y++){const b=_[y];b.candidate=t[x+2*l],b.count=0;const{bounds:T,leftCacheBounds:M,rightCacheBounds:L}=b;for(let C=0;C<3;C++)L[C]=1/0,L[C+3]=-1/0,M[C]=1/0,M[C+3]=-1/0,T[C]=1/0,T[C+3]=-1/0;si(x,t,T)}_.sort(Ol);let w=s;for(let x=0;x<w;x++){const b=_[x];for(;x+1<w&&_[x+1].candidate===b.candidate;)_.splice(x+1,1),w--}for(let x=p;x<n;x+=6){const b=t[x+2*l];for(let T=0;T<w;T++){const M=_[T];b>=M.candidate?si(x,t,M.rightCacheBounds):(si(x,t,M.leftCacheBounds),M.count++)}}for(let x=0;x<w;x++){const b=_[x],T=b.count,M=s-b.count,L=b.leftCacheBounds,C=b.rightCacheBounds;let I=0;T!==0&&(I=Lt(L)/h);let D=0;M!==0&&(D=Lt(C)/h);const A=vr+Hi*(I*T+D*M);A<u&&(o=l,u=A,c=b.candidate)}}else{for(let w=0;w<Te;w++){const x=Ee[w];x.count=0,x.candidate=d+m+w*m;const b=x.bounds;for(let T=0;T<3;T++)b[T]=1/0,b[T+3]=-1/0}for(let w=p;w<n;w+=6){let T=~~((t[w+2*l]-d)/m);T>=Te&&(T=Te-1);const M=Ee[T];M.count++,si(w,t,M.bounds)}const _=Ee[Te-1];xr(_.bounds,_.rightCacheBounds);for(let w=Te-2;w>=0;w--){const x=Ee[w],b=Ee[w+1];wr(x.bounds,b.rightCacheBounds,x.rightCacheBounds)}let y=0;for(let w=0;w<Te-1;w++){const x=Ee[w],b=x.count,T=x.bounds,L=Ee[w+1].rightCacheBounds;b!==0&&(y===0?xr(T,ri):wr(T,ri,ri)),y+=b;let C=0,I=0;y!==0&&(C=Lt(ri)/h);const D=s-y;D!==0&&(I=Lt(L)/h);const A=vr+Hi*(C*y+I*D);A<u&&(o=l,u=A,c=x.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${r} used.`);return{axis:o,pos:c}}function Vl(a,e,t,i){let s=0;for(let r=e,o=e+t;r<o;r++)s+=a[r*6+i*2];return s/t}class Qi{constructor(){this.boundingData=new Float32Array(6)}}function Wl(a,e,t,i,s,r){let o=i,c=i+s-1;const h=r.pos,u=r.axis*2;for(;;){for(;o<=c&&t[o*6+u]<h;)o++;for(;o<=c&&t[c*6+u]>=h;)c--;if(o<c){for(let p=0;p<3;p++){let n=e[o*3+p];e[o*3+p]=e[c*3+p],e[c*3+p]=n}for(let p=0;p<6;p++){let n=t[o*6+p];t[o*6+p]=t[c*6+p],t[c*6+p]=n}o++,c--}else return o}}function Ul(a,e,t,i,s,r){let o=i,c=i+s-1;const h=r.pos,u=r.axis*2;for(;;){for(;o<=c&&t[o*6+u]<h;)o++;for(;o<=c&&t[c*6+u]>=h;)c--;if(o<c){let p=a[o];a[o]=a[c],a[c]=p;for(let n=0;n<6;n++){let l=t[o*6+n];t[o*6+n]=t[c*6+n],t[c*6+n]=l}o++,c--}else return o}}function oe(a,e){return e[a+15]===65535}function le(a,e){return e[a+6]}function ce(a,e){return e[a+14]}function he(a){return a+8}function ue(a,e){return e[a+6]}function un(a,e){return e[a+7]}let fn,Bt,yi,dn;const Hl=Math.pow(2,32);function hs(a){return"count"in a?1:1+hs(a.left)+hs(a.right)}function Gl(a,e,t){return fn=new Float32Array(t),Bt=new Uint32Array(t),yi=new Uint16Array(t),dn=new Uint8Array(t),us(a,e)}function us(a,e){const t=a/4,i=a/2,s="count"in e,r=e.boundingData;for(let o=0;o<6;o++)fn[t+o]=r[o];if(s)if(e.buffer){const o=e.buffer;dn.set(new Uint8Array(o),a);for(let c=a,h=a+o.byteLength;c<h;c+=Vt){const u=c/2;oe(u,yi)||(Bt[c/4+6]+=t)}return a+o.byteLength}else{const o=e.offset,c=e.count;return Bt[t+6]=o,yi[i+14]=c,yi[i+15]=Mi,a+Vt}else{const o=e.left,c=e.right,h=e.splitAxis;let u;if(u=us(a+Vt,o),u/4>Hl)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return Bt[t+6]=u/4,u=us(u,c),Bt[t+7]=h,u}}function Nl(a,e){const t=(a.index?a.index.count:a.attributes.position.count)/3,i=t>2**16,s=i?4:2,r=e?new SharedArrayBuffer(t*s):new ArrayBuffer(t*s),o=i?new Uint32Array(r):new Uint16Array(r);for(let c=0,h=o.length;c<h;c++)o[c]=c;return o}function Ql(a,e,t,i,s){const{maxDepth:r,verbose:o,maxLeafTris:c,strategy:h,onProgress:u,indirect:p}=s,n=a._indirectBuffer,l=a.geometry,d=l.index?l.index.array:null,g=p?Ul:Wl,v=xt(l),m=new Float32Array(6);let _=!1;const y=new Qi;return Ni(e,t,i,y.boundingData,m),x(y,t,i,m),y;function w(b){u&&u(b/v)}function x(b,T,M,L=null,C=0){if(!_&&C>=r&&(_=!0,o&&(console.warn(`MeshBVH: Max depth of ${r} reached when generating BVH. Consider increasing maxDepth.`),console.warn(l))),M<=c||C>=r)return w(T+M),b.offset=T,b.count=M,b;const I=zl(b.boundingData,L,e,T,M,h);if(I.axis===-1)return w(T+M),b.offset=T,b.count=M,b;const D=g(n,d,e,T,M,I);if(D===T||D===T+M)w(T+M),b.offset=T,b.count=M;else{b.splitAxis=I.axis;const A=new Qi,S=T,P=D-T;b.left=A,Ni(e,S,P,A.boundingData,m),x(A,S,P,m,C+1);const R=new Qi,k=D,F=M-P;b.right=R,Ni(e,k,F,R.boundingData,m),x(R,k,F,m,C+1)}return b}}function jl(a,e){const t=a.geometry;e.indirect&&(a._indirectBuffer=Nl(t,e.useSharedArrayBuffer),Fl(t)&&!e.verbose&&console.warn('MeshBVH: Provided geometry contains groups that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),a._indirectBuffer||kl(t,e);const i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=Bl(t),r=e.indirect?cn(t):hn(t);a._roots=r.map(o=>{const c=Ql(a,s,o.offset,o.count,e),h=hs(c),u=new i(Vt*h);return Gl(0,c,u),u})}class Le{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let i=1/0,s=-1/0;for(let r=0,o=e.length;r<o;r++){const h=e[r][t];i=h<i?h:i,s=h>s?h:s}this.min=i,this.max=s}setFromPoints(e,t){let i=1/0,s=-1/0;for(let r=0,o=t.length;r<o;r++){const c=t[r],h=e.dot(c);i=h<i?h:i,s=h>s?h:s}this.min=i,this.max=s}isSeparated(e){return this.min>e.max||e.min>this.max}}Le.prototype.setFromBox=function(){const a=new f.Vector3;return function(t,i){const s=i.min,r=i.max;let o=1/0,c=-1/0;for(let h=0;h<=1;h++)for(let u=0;u<=1;u++)for(let p=0;p<=1;p++){a.x=s.x*h+r.x*(1-h),a.y=s.y*u+r.y*(1-u),a.z=s.z*p+r.z*(1-p);const n=t.dot(a);o=Math.min(n,o),c=Math.max(n,c)}this.min=o,this.max=c}}();const ql=function(){const a=new f.Vector3,e=new f.Vector3,t=new f.Vector3;return function(s,r,o){const c=s.start,h=a,u=r.start,p=e;t.subVectors(c,u),a.subVectors(s.end,s.start),e.subVectors(r.end,r.start);const n=t.dot(p),l=p.dot(h),d=p.dot(p),g=t.dot(h),m=h.dot(h)*d-l*l;let _,y;m!==0?_=(n*l-g*d)/m:_=0,y=(n+_*l)/d,o.x=_,o.y=y}}(),Ls=function(){const a=new f.Vector2,e=new f.Vector3,t=new f.Vector3;return function(s,r,o,c){ql(s,r,a);let h=a.x,u=a.y;if(h>=0&&h<=1&&u>=0&&u<=1){s.at(h,o),r.at(u,c);return}else if(h>=0&&h<=1){u<0?r.at(0,c):r.at(1,c),s.closestPointToPoint(c,!0,o);return}else if(u>=0&&u<=1){h<0?s.at(0,o):s.at(1,o),r.closestPointToPoint(o,!0,c);return}else{let p;h<0?p=s.start:p=s.end;let n;u<0?n=r.start:n=r.end;const l=e,d=t;if(s.closestPointToPoint(n,!0,e),r.closestPointToPoint(p,!0,t),l.distanceToSquared(n)<=d.distanceToSquared(p)){o.copy(l),c.copy(n);return}else{o.copy(p),c.copy(d);return}}}}(),Yl=function(){const a=new f.Vector3,e=new f.Vector3,t=new f.Plane,i=new f.Line3;return function(r,o){const{radius:c,center:h}=r,{a:u,b:p,c:n}=o;if(i.start=u,i.end=p,i.closestPointToPoint(h,!0,a).distanceTo(h)<=c||(i.start=u,i.end=n,i.closestPointToPoint(h,!0,a).distanceTo(h)<=c)||(i.start=p,i.end=n,i.closestPointToPoint(h,!0,a).distanceTo(h)<=c))return!0;const v=o.getPlane(t);if(Math.abs(v.distanceToPoint(h))<=c){const _=v.projectPoint(h,e);if(o.containsPoint(_))return!0}return!1}}(),Zl=1e-15;function ji(a){return Math.abs(a)<Zl}class ge extends f.Triangle{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new f.Vector3),this.satBounds=new Array(4).fill().map(()=>new Le),this.points=[this.a,this.b,this.c],this.sphere=new f.Sphere,this.plane=new f.Plane,this.needsUpdate=!0}intersectsSphere(e){return Yl(e,this)}update(){const e=this.a,t=this.b,i=this.c,s=this.points,r=this.satAxes,o=this.satBounds,c=r[0],h=o[0];this.getNormal(c),h.setFromPoints(c,s);const u=r[1],p=o[1];u.subVectors(e,t),p.setFromPoints(u,s);const n=r[2],l=o[2];n.subVectors(t,i),l.setFromPoints(n,s);const d=r[3],g=o[3];d.subVectors(i,e),g.setFromPoints(d,s),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(c,e),this.needsUpdate=!1}}ge.prototype.closestPointToSegment=function(){const a=new f.Vector3,e=new f.Vector3,t=new f.Line3;return function(s,r=null,o=null){const{start:c,end:h}=s,u=this.points;let p,n=1/0;for(let l=0;l<3;l++){const d=(l+1)%3;t.start.copy(u[l]),t.end.copy(u[d]),Ls(t,s,a,e),p=a.distanceToSquared(e),p<n&&(n=p,r&&r.copy(a),o&&o.copy(e))}return this.closestPointToPoint(c,a),p=c.distanceToSquared(a),p<n&&(n=p,r&&r.copy(a),o&&o.copy(c)),this.closestPointToPoint(h,a),p=h.distanceToSquared(a),p<n&&(n=p,r&&r.copy(a),o&&o.copy(h)),Math.sqrt(n)}}();ge.prototype.intersectsTriangle=function(){const a=new ge,e=new Array(3),t=new Array(3),i=new Le,s=new Le,r=new f.Vector3,o=new f.Vector3,c=new f.Vector3,h=new f.Vector3,u=new f.Vector3,p=new f.Line3,n=new f.Line3,l=new f.Line3,d=new f.Vector3;function g(v,m,_){const y=v.points;let w=0,x=-1;for(let b=0;b<3;b++){const{start:T,end:M}=p;T.copy(y[b]),M.copy(y[(b+1)%3]),p.delta(o);const L=ji(m.distanceToPoint(T));if(ji(m.normal.dot(o))&&L){_.copy(p),w=2;break}const C=m.intersectLine(p,d);if(!C&&L&&d.copy(T),(C||L)&&!ji(d.distanceTo(M))){if(w<=1)(w===1?_.start:_.end).copy(d),L&&(x=w);else if(w>=2){(x===1?_.start:_.end).copy(d),w=2;break}if(w++,w===2&&x===-1)break}}return w}return function(m,_=null,y=!1){this.needsUpdate&&this.update(),m.isExtendedTriangle?m.needsUpdate&&m.update():(a.copy(m),a.update(),m=a);const w=this.plane,x=m.plane;if(Math.abs(w.normal.dot(x.normal))>1-1e-10){const b=this.satBounds,T=this.satAxes;t[0]=m.a,t[1]=m.b,t[2]=m.c;for(let C=0;C<4;C++){const I=b[C],D=T[C];if(i.setFromPoints(D,t),I.isSeparated(i))return!1}const M=m.satBounds,L=m.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let C=0;C<4;C++){const I=M[C],D=L[C];if(i.setFromPoints(D,e),I.isSeparated(i))return!1}for(let C=0;C<4;C++){const I=T[C];for(let D=0;D<4;D++){const A=L[D];if(r.crossVectors(I,A),i.setFromPoints(r,e),s.setFromPoints(r,t),i.isSeparated(s))return!1}}return _&&(y||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),_.start.set(0,0,0),_.end.set(0,0,0)),!0}else{const b=g(this,x,n);if(b===1&&m.containsPoint(n.end))return _&&(_.start.copy(n.end),_.end.copy(n.end)),!0;if(b!==2)return!1;const T=g(m,w,l);if(T===1&&this.containsPoint(l.end))return _&&(_.start.copy(l.end),_.end.copy(l.end)),!0;if(T!==2)return!1;if(n.delta(c),l.delta(h),c.dot(h)<0){let S=l.start;l.start=l.end,l.end=S}const M=n.start.dot(c),L=n.end.dot(c),C=l.start.dot(c),I=l.end.dot(c),D=L<C,A=M<I;return M!==I&&C!==L&&D===A?!1:(_&&(u.subVectors(n.start,l.start),u.dot(c)>0?_.start.copy(n.start):_.start.copy(l.start),u.subVectors(n.end,l.end),u.dot(c)<0?_.end.copy(n.end):_.end.copy(l.end)),!0)}}}();ge.prototype.distanceToPoint=function(){const a=new f.Vector3;return function(t){return this.closestPointToPoint(t,a),t.distanceTo(a)}}();ge.prototype.distanceToTriangle=function(){const a=new f.Vector3,e=new f.Vector3,t=["a","b","c"],i=new f.Line3,s=new f.Line3;return function(o,c=null,h=null){const u=c||h?i:null;if(this.intersectsTriangle(o,u))return(c||h)&&(c&&u.getCenter(c),h&&u.getCenter(h)),0;let p=1/0;for(let n=0;n<3;n++){let l;const d=t[n],g=o[d];this.closestPointToPoint(g,a),l=g.distanceToSquared(a),l<p&&(p=l,c&&c.copy(a),h&&h.copy(g));const v=this[d];o.closestPointToPoint(v,a),l=v.distanceToSquared(a),l<p&&(p=l,c&&c.copy(v),h&&h.copy(a))}for(let n=0;n<3;n++){const l=t[n],d=t[(n+1)%3];i.set(this[l],this[d]);for(let g=0;g<3;g++){const v=t[g],m=t[(g+1)%3];s.set(o[v],o[m]),Ls(i,s,a,e);const _=a.distanceToSquared(e);_<p&&(p=_,c&&c.copy(a),h&&h.copy(e))}}return Math.sqrt(p)}}();class te{constructor(e,t,i){this.isOrientedBox=!0,this.min=new f.Vector3,this.max=new f.Vector3,this.matrix=new f.Matrix4,this.invMatrix=new f.Matrix4,this.points=new Array(8).fill().map(()=>new f.Vector3),this.satAxes=new Array(3).fill().map(()=>new f.Vector3),this.satBounds=new Array(3).fill().map(()=>new Le),this.alignedSatBounds=new Array(3).fill().map(()=>new Le),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),i&&this.matrix.copy(i)}set(e,t,i){this.min.copy(e),this.max.copy(t),this.matrix.copy(i),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}te.prototype.update=function(){return function(){const e=this.matrix,t=this.min,i=this.max,s=this.points;for(let u=0;u<=1;u++)for(let p=0;p<=1;p++)for(let n=0;n<=1;n++){const l=1*u|2*p|4*n,d=s[l];d.x=u?i.x:t.x,d.y=p?i.y:t.y,d.z=n?i.z:t.z,d.applyMatrix4(e)}const r=this.satBounds,o=this.satAxes,c=s[0];for(let u=0;u<3;u++){const p=o[u],n=r[u],l=1<<u,d=s[l];p.subVectors(c,d),n.setFromPoints(p,s)}const h=this.alignedSatBounds;h[0].setFromPointsField(s,"x"),h[1].setFromPointsField(s,"y"),h[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}();te.prototype.intersectsBox=function(){const a=new Le;return function(t){this.needsUpdate&&this.update();const i=t.min,s=t.max,r=this.satBounds,o=this.satAxes,c=this.alignedSatBounds;if(a.min=i.x,a.max=s.x,c[0].isSeparated(a)||(a.min=i.y,a.max=s.y,c[1].isSeparated(a))||(a.min=i.z,a.max=s.z,c[2].isSeparated(a)))return!1;for(let h=0;h<3;h++){const u=o[h],p=r[h];if(a.setFromBox(u,t),p.isSeparated(a))return!1}return!0}}();te.prototype.intersectsTriangle=function(){const a=new ge,e=new Array(3),t=new Le,i=new Le,s=new f.Vector3;return function(o){this.needsUpdate&&this.update(),o.isExtendedTriangle?o.needsUpdate&&o.update():(a.copy(o),a.update(),o=a);const c=this.satBounds,h=this.satAxes;e[0]=o.a,e[1]=o.b,e[2]=o.c;for(let l=0;l<3;l++){const d=c[l],g=h[l];if(t.setFromPoints(g,e),d.isSeparated(t))return!1}const u=o.satBounds,p=o.satAxes,n=this.points;for(let l=0;l<3;l++){const d=u[l],g=p[l];if(t.setFromPoints(g,n),d.isSeparated(t))return!1}for(let l=0;l<3;l++){const d=h[l];for(let g=0;g<4;g++){const v=p[g];if(s.crossVectors(d,v),t.setFromPoints(s,e),i.setFromPoints(s,n),t.isSeparated(i))return!1}}return!0}}();te.prototype.closestPointToPoint=function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}}();te.prototype.distanceToPoint=function(){const a=new f.Vector3;return function(t){return this.closestPointToPoint(t,a),t.distanceTo(a)}}();te.prototype.distanceToBox=function(){const a=["x","y","z"],e=new Array(12).fill().map(()=>new f.Line3),t=new Array(12).fill().map(()=>new f.Line3),i=new f.Vector3,s=new f.Vector3;return function(o,c=0,h=null,u=null){if(this.needsUpdate&&this.update(),this.intersectsBox(o))return(h||u)&&(o.getCenter(s),this.closestPointToPoint(s,i),o.closestPointToPoint(i,s),h&&h.copy(i),u&&u.copy(s)),0;const p=c*c,n=o.min,l=o.max,d=this.points;let g=1/0;for(let m=0;m<8;m++){const _=d[m];s.copy(_).clamp(n,l);const y=_.distanceToSquared(s);if(y<g&&(g=y,h&&h.copy(_),u&&u.copy(s),y<p))return Math.sqrt(y)}let v=0;for(let m=0;m<3;m++)for(let _=0;_<=1;_++)for(let y=0;y<=1;y++){const w=(m+1)%3,x=(m+2)%3,b=_<<w|y<<x,T=1<<m|_<<w|y<<x,M=d[b],L=d[T];e[v].set(M,L);const I=a[m],D=a[w],A=a[x],S=t[v],P=S.start,R=S.end;P[I]=n[I],P[D]=_?n[D]:l[D],P[A]=y?n[A]:l[D],R[I]=l[I],R[D]=_?n[D]:l[D],R[A]=y?n[A]:l[D],v++}for(let m=0;m<=1;m++)for(let _=0;_<=1;_++)for(let y=0;y<=1;y++){s.x=m?l.x:n.x,s.y=_?l.y:n.y,s.z=y?l.z:n.z,this.closestPointToPoint(s,i);const w=s.distanceToSquared(i);if(w<g&&(g=w,h&&h.copy(i),u&&u.copy(s),w<p))return Math.sqrt(w)}for(let m=0;m<12;m++){const _=e[m];for(let y=0;y<12;y++){const w=t[y];Ls(_,w,i,s);const x=i.distanceToSquared(s);if(x<g&&(g=x,h&&h.copy(i),u&&u.copy(s),x<p))return Math.sqrt(x)}}return Math.sqrt(g)}}();class Ps{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class Kl extends Ps{constructor(){super(()=>new ge)}}const fe=new Kl;class Xl{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=i=>{t&&e.push(t),t=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const Y=new Xl;let ze,dt;const $e=[],ni=new Ps(()=>new f.Box3);function Jl(a,e,t,i,s,r){ze=ni.getPrimitive(),dt=ni.getPrimitive(),$e.push(ze,dt),Y.setBuffer(a._roots[e]);const o=fs(0,a.geometry,t,i,s,r);Y.clearBuffer(),ni.releasePrimitive(ze),ni.releasePrimitive(dt),$e.pop(),$e.pop();const c=$e.length;return c>0&&(dt=$e[c-1],ze=$e[c-2]),o}function fs(a,e,t,i,s=null,r=0,o=0){const{float32Array:c,uint16Array:h,uint32Array:u}=Y;let p=a*2;if(oe(p,h)){const l=le(a,u),d=ce(p,h);return Z(a,c,ze),i(l,d,!1,o,r+a,ze)}else{let I=function(A){const{uint16Array:S,uint32Array:P}=Y;let R=A*2;for(;!oe(R,S);)A=he(A),R=A*2;return le(A,P)},D=function(A){const{uint16Array:S,uint32Array:P}=Y;let R=A*2;for(;!oe(R,S);)A=ue(A,P),R=A*2;return le(A,P)+ce(R,S)};const l=he(a),d=ue(a,u);let g=l,v=d,m,_,y,w;if(s&&(y=ze,w=dt,Z(g,c,y),Z(v,c,w),m=s(y),_=s(w),_<m)){g=d,v=l;const A=m;m=_,_=A,y=w}y||(y=ze,Z(g,c,y));const x=oe(g*2,h),b=t(y,x,m,o+1,r+g);let T;if(b===_r){const A=I(g),P=D(g)-A;T=i(A,P,!0,o+1,r+g,y)}else T=b&&fs(g,e,t,i,s,r,o+1);if(T)return!0;w=dt,Z(v,c,w);const M=oe(v*2,h),L=t(w,M,_,o+1,r+v);let C;if(L===_r){const A=I(v),P=D(v)-A;C=i(A,P,!0,o+1,r+v,w)}else C=L&&fs(v,e,t,i,s,r,o+1);return!!C}}const Pt=new f.Vector3,qi=new f.Vector3;function $l(a,e,t={},i=0,s=1/0){const r=i*i,o=s*s;let c=1/0,h=null;if(a.shapecast({boundsTraverseOrder:p=>(Pt.copy(e).clamp(p.min,p.max),Pt.distanceToSquared(e)),intersectsBounds:(p,n,l)=>l<c&&l<o,intersectsTriangle:(p,n)=>{p.closestPointToPoint(e,Pt);const l=e.distanceToSquared(Pt);return l<c&&(qi.copy(Pt),c=l,h=n),l<r}}),c===1/0)return null;const u=Math.sqrt(c);return t.point?t.point.copy(qi):t.point=qi.clone(),t.distance=u,t.faceIndex=h,t}const et=new f.Vector3,it=new f.Vector3,st=new f.Vector3,oi=new f.Vector2,ai=new f.Vector2,li=new f.Vector2,br=new f.Vector3,Ar=new f.Vector3,Tr=new f.Vector3,ci=new f.Vector3;function ec(a,e,t,i,s,r,o,c){let h;if(r===f.BackSide?h=a.intersectTriangle(i,t,e,!0,s):h=a.intersectTriangle(e,t,i,r!==f.DoubleSide,s),h===null)return null;const u=a.origin.distanceTo(s);return u<o||u>c?null:{distance:u,point:s.clone()}}function tc(a,e,t,i,s,r,o,c,h,u,p){et.fromBufferAttribute(e,r),it.fromBufferAttribute(e,o),st.fromBufferAttribute(e,c);const n=ec(a,et,it,st,ci,h,u,p);if(n){i&&(oi.fromBufferAttribute(i,r),ai.fromBufferAttribute(i,o),li.fromBufferAttribute(i,c),n.uv=f.Triangle.getInterpolation(ci,et,it,st,oi,ai,li,new f.Vector2)),s&&(oi.fromBufferAttribute(s,r),ai.fromBufferAttribute(s,o),li.fromBufferAttribute(s,c),n.uv1=f.Triangle.getInterpolation(ci,et,it,st,oi,ai,li,new f.Vector2)),t&&(br.fromBufferAttribute(t,r),Ar.fromBufferAttribute(t,o),Tr.fromBufferAttribute(t,c),n.normal=f.Triangle.getInterpolation(ci,et,it,st,br,Ar,Tr,new f.Vector3),n.normal.dot(a.direction)>0&&n.normal.multiplyScalar(-1));const l={a:r,b:o,c,normal:new f.Vector3,materialIndex:0};f.Triangle.getNormal(et,it,st,l.normal),n.face=l,n.faceIndex=r}return n}function Ci(a,e,t,i,s,r,o){const c=i*3;let h=c+0,u=c+1,p=c+2;const n=a.index;a.index&&(h=n.getX(h),u=n.getX(u),p=n.getX(p));const{position:l,normal:d,uv:g,uv1:v}=a.attributes,m=tc(t,l,d,g,v,h,u,p,e,r,o);return m?(m.faceIndex=i,s&&s.push(m),m):null}function K(a,e,t,i){const s=a.a,r=a.b,o=a.c;let c=e,h=e+1,u=e+2;t&&(c=t.getX(c),h=t.getX(h),u=t.getX(u)),s.x=i.getX(c),s.y=i.getY(c),s.z=i.getZ(c),r.x=i.getX(h),r.y=i.getY(h),r.z=i.getZ(h),o.x=i.getX(u),o.y=i.getY(u),o.z=i.getZ(u)}function ic(a,e,t,i,s,r,o,c){const{geometry:h,_indirectBuffer:u}=a;for(let p=i,n=i+s;p<n;p++)Ci(h,e,t,p,r,o,c)}function sc(a,e,t,i,s,r,o){const{geometry:c,_indirectBuffer:h}=a;let u=1/0,p=null;for(let n=i,l=i+s;n<l;n++){let d;d=Ci(c,e,t,n,null,r,o),d&&d.distance<u&&(p=d,u=d.distance)}return p}function rc(a,e,t,i,s,r,o){const{geometry:c}=t,{index:h}=c,u=c.attributes.position;for(let p=a,n=e+a;p<n;p++){let l;if(l=p,K(o,l*3,h,u),o.needsUpdate=!0,i(o,l,s,r))return!0}return!1}function nc(a,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=a.geometry,i=t.index?t.index.array:null,s=t.attributes.position;let r,o,c,h,u=0;const p=a._roots;for(let l=0,d=p.length;l<d;l++)r=p[l],o=new Uint32Array(r),c=new Uint16Array(r),h=new Float32Array(r),n(0,u),u+=r.byteLength;function n(l,d,g=!1){const v=l*2;if(c[v+15]===Mi){const _=o[l+6],y=c[v+14];let w=1/0,x=1/0,b=1/0,T=-1/0,M=-1/0,L=-1/0;for(let C=3*_,I=3*(_+y);C<I;C++){let D=i[C];const A=s.getX(D),S=s.getY(D),P=s.getZ(D);A<w&&(w=A),A>T&&(T=A),S<x&&(x=S),S>M&&(M=S),P<b&&(b=P),P>L&&(L=P)}return h[l+0]!==w||h[l+1]!==x||h[l+2]!==b||h[l+3]!==T||h[l+4]!==M||h[l+5]!==L?(h[l+0]=w,h[l+1]=x,h[l+2]=b,h[l+3]=T,h[l+4]=M,h[l+5]=L,!0):!1}else{const _=l+8,y=o[l+6],w=_+d,x=y+d;let b=g,T=!1,M=!1;e?b||(T=e.has(w),M=e.has(x),b=!T&&!M):(T=!0,M=!0);const L=b||T,C=b||M;let I=!1;L&&(I=n(_,d,b));let D=!1;C&&(D=n(y,d,b));const A=I||D;if(A)for(let S=0;S<3;S++){const P=_+S,R=y+S,k=h[P],F=h[P+3],z=h[R],B=h[R+3];h[l+S]=k<z?k:z,h[l+S+3]=F>B?F:B}return A}}}function Ve(a,e,t,i,s){let r,o,c,h,u,p;const n=1/t.direction.x,l=1/t.direction.y,d=1/t.direction.z,g=t.origin.x,v=t.origin.y,m=t.origin.z;let _=e[a],y=e[a+3],w=e[a+1],x=e[a+3+1],b=e[a+2],T=e[a+3+2];return n>=0?(r=(_-g)*n,o=(y-g)*n):(r=(y-g)*n,o=(_-g)*n),l>=0?(c=(w-v)*l,h=(x-v)*l):(c=(x-v)*l,h=(w-v)*l),r>h||c>o||((c>r||isNaN(r))&&(r=c),(h<o||isNaN(o))&&(o=h),d>=0?(u=(b-m)*d,p=(T-m)*d):(u=(T-m)*d,p=(b-m)*d),r>p||u>o)?!1:((u>r||r!==r)&&(r=u),(p<o||o!==o)&&(o=p),r<=s&&o>=i)}function oc(a,e,t,i,s,r,o,c){const{geometry:h,_indirectBuffer:u}=a;for(let p=i,n=i+s;p<n;p++){let l=u?u[p]:p;Ci(h,e,t,l,r,o,c)}}function ac(a,e,t,i,s,r,o){const{geometry:c,_indirectBuffer:h}=a;let u=1/0,p=null;for(let n=i,l=i+s;n<l;n++){let d;d=Ci(c,e,t,h?h[n]:n,null,r,o),d&&d.distance<u&&(p=d,u=d.distance)}return p}function lc(a,e,t,i,s,r,o){const{geometry:c}=t,{index:h}=c,u=c.attributes.position;for(let p=a,n=e+a;p<n;p++){let l;if(l=t.resolveTriangleIndex(p),K(o,l*3,h,u),o.needsUpdate=!0,i(o,l,s,r))return!0}return!1}function cc(a,e,t,i,s,r,o){Y.setBuffer(a._roots[e]),ds(0,a,t,i,s,r,o),Y.clearBuffer()}function ds(a,e,t,i,s,r,o){const{float32Array:c,uint16Array:h,uint32Array:u}=Y,p=a*2;if(oe(p,h)){const l=le(a,u),d=ce(p,h);ic(e,t,i,l,d,s,r,o)}else{const l=he(a);Ve(l,c,i,r,o)&&ds(l,e,t,i,s,r,o);const d=ue(a,u);Ve(d,c,i,r,o)&&ds(d,e,t,i,s,r,o)}}const hc=["x","y","z"];function uc(a,e,t,i,s,r){Y.setBuffer(a._roots[e]);const o=ps(0,a,t,i,s,r);return Y.clearBuffer(),o}function ps(a,e,t,i,s,r){const{float32Array:o,uint16Array:c,uint32Array:h}=Y;let u=a*2;if(oe(u,c)){const n=le(a,h),l=ce(u,c);return sc(e,t,i,n,l,s,r)}else{const n=un(a,h),l=hc[n],g=i.direction[l]>=0;let v,m;g?(v=he(a),m=ue(a,h)):(v=ue(a,h),m=he(a));const y=Ve(v,o,i,s,r)?ps(v,e,t,i,s,r):null;if(y){const b=y.point[l];if(g?b<=o[m+n]:b>=o[m+n+3])return y}const x=Ve(m,o,i,s,r)?ps(m,e,t,i,s,r):null;return y&&x?y.distance<=x.distance?y:x:y||x||null}}const hi=new f.Box3,rt=new ge,nt=new ge,It=new f.Matrix4,Sr=new te,ui=new te;function fc(a,e,t,i){Y.setBuffer(a._roots[e]);const s=ms(0,a,t,i);return Y.clearBuffer(),s}function ms(a,e,t,i,s=null){const{float32Array:r,uint16Array:o,uint32Array:c}=Y;let h=a*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),Sr.set(t.boundingBox.min,t.boundingBox.max,i),s=Sr),oe(h,o)){const p=e.geometry,n=p.index,l=p.attributes.position,d=t.index,g=t.attributes.position,v=le(a,c),m=ce(h,o);if(It.copy(i).invert(),t.boundsTree)return Z(a,r,ui),ui.matrix.copy(It),ui.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:y=>ui.intersectsBox(y),intersectsTriangle:y=>{y.a.applyMatrix4(i),y.b.applyMatrix4(i),y.c.applyMatrix4(i),y.needsUpdate=!0;for(let w=v*3,x=(m+v)*3;w<x;w+=3)if(K(nt,w,n,l),nt.needsUpdate=!0,y.intersectsTriangle(nt))return!0;return!1}});for(let _=v*3,y=(m+v)*3;_<y;_+=3){K(rt,_,n,l),rt.a.applyMatrix4(It),rt.b.applyMatrix4(It),rt.c.applyMatrix4(It),rt.needsUpdate=!0;for(let w=0,x=d.count;w<x;w+=3)if(K(nt,w,d,g),nt.needsUpdate=!0,rt.intersectsTriangle(nt))return!0}}else{const p=a+8,n=c[a+6];return Z(p,r,hi),!!(s.intersectsBox(hi)&&ms(p,e,t,i,s)||(Z(n,r,hi),s.intersectsBox(hi)&&ms(n,e,t,i,s)))}}const fi=new f.Matrix4,Yi=new te,Rt=new te,dc=new f.Vector3,pc=new f.Vector3,mc=new f.Vector3,gc=new f.Vector3;function _c(a,e,t,i={},s={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),Yi.set(e.boundingBox.min,e.boundingBox.max,t),Yi.needsUpdate=!0;const c=a.geometry,h=c.attributes.position,u=c.index,p=e.attributes.position,n=e.index,l=fe.getPrimitive(),d=fe.getPrimitive();let g=dc,v=pc,m=null,_=null;s&&(m=mc,_=gc);let y=1/0,w=null,x=null;return fi.copy(t).invert(),Rt.matrix.copy(fi),a.shapecast({boundsTraverseOrder:b=>Yi.distanceToBox(b),intersectsBounds:(b,T,M)=>M<y&&M<o?(T&&(Rt.min.copy(b.min),Rt.max.copy(b.max),Rt.needsUpdate=!0),!0):!1,intersectsRange:(b,T)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:L=>Rt.distanceToBox(L),intersectsBounds:(L,C,I)=>I<y&&I<o,intersectsRange:(L,C)=>{for(let I=L,D=L+C;I<D;I++){K(d,3*I,n,p),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let A=b,S=b+T;A<S;A++){K(l,3*A,u,h),l.needsUpdate=!0;const P=l.distanceToTriangle(d,g,m);if(P<y&&(v.copy(g),_&&_.copy(m),y=P,w=A,x=I),P<r)return!0}}}});{const M=xt(e);for(let L=0,C=M;L<C;L++){K(d,3*L,n,p),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let I=b,D=b+T;I<D;I++){K(l,3*I,u,h),l.needsUpdate=!0;const A=l.distanceToTriangle(d,g,m);if(A<y&&(v.copy(g),_&&_.copy(m),y=A,w=I,x=L),A<r)return!0}}}}}),fe.releasePrimitive(l),fe.releasePrimitive(d),y===1/0?null:(i.point?i.point.copy(v):i.point=v.clone(),i.distance=y,i.faceIndex=w,s&&(s.point?s.point.copy(_):s.point=_.clone(),s.point.applyMatrix4(fi),v.applyMatrix4(fi),s.distance=v.sub(s.point).length(),s.faceIndex=x),i)}function vc(a,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=a.geometry,i=t.index?t.index.array:null,s=t.attributes.position;let r,o,c,h,u=0;const p=a._roots;for(let l=0,d=p.length;l<d;l++)r=p[l],o=new Uint32Array(r),c=new Uint16Array(r),h=new Float32Array(r),n(0,u),u+=r.byteLength;function n(l,d,g=!1){const v=l*2;if(c[v+15]===Mi){const _=o[l+6],y=c[v+14];let w=1/0,x=1/0,b=1/0,T=-1/0,M=-1/0,L=-1/0;for(let C=_,I=_+y;C<I;C++){const D=3*a.resolveTriangleIndex(C);for(let A=0;A<3;A++){let S=D+A;S=i?i[S]:S;const P=s.getX(S),R=s.getY(S),k=s.getZ(S);P<w&&(w=P),P>T&&(T=P),R<x&&(x=R),R>M&&(M=R),k<b&&(b=k),k>L&&(L=k)}}return h[l+0]!==w||h[l+1]!==x||h[l+2]!==b||h[l+3]!==T||h[l+4]!==M||h[l+5]!==L?(h[l+0]=w,h[l+1]=x,h[l+2]=b,h[l+3]=T,h[l+4]=M,h[l+5]=L,!0):!1}else{const _=l+8,y=o[l+6],w=_+d,x=y+d;let b=g,T=!1,M=!1;e?b||(T=e.has(w),M=e.has(x),b=!T&&!M):(T=!0,M=!0);const L=b||T,C=b||M;let I=!1;L&&(I=n(_,d,b));let D=!1;C&&(D=n(y,d,b));const A=I||D;if(A)for(let S=0;S<3;S++){const P=_+S,R=y+S,k=h[P],F=h[P+3],z=h[R],B=h[R+3];h[l+S]=k<z?k:z,h[l+S+3]=F>B?F:B}return A}}}function yc(a,e,t,i,s,r,o){Y.setBuffer(a._roots[e]),gs(0,a,t,i,s,r,o),Y.clearBuffer()}function gs(a,e,t,i,s,r,o){const{float32Array:c,uint16Array:h,uint32Array:u}=Y,p=a*2;if(oe(p,h)){const l=le(a,u),d=ce(p,h);oc(e,t,i,l,d,s,r,o)}else{const l=he(a);Ve(l,c,i,r,o)&&gs(l,e,t,i,s,r,o);const d=ue(a,u);Ve(d,c,i,r,o)&&gs(d,e,t,i,s,r,o)}}const xc=["x","y","z"];function wc(a,e,t,i,s,r){Y.setBuffer(a._roots[e]);const o=_s(0,a,t,i,s,r);return Y.clearBuffer(),o}function _s(a,e,t,i,s,r){const{float32Array:o,uint16Array:c,uint32Array:h}=Y;let u=a*2;if(oe(u,c)){const n=le(a,h),l=ce(u,c);return ac(e,t,i,n,l,s,r)}else{const n=un(a,h),l=xc[n],g=i.direction[l]>=0;let v,m;g?(v=he(a),m=ue(a,h)):(v=ue(a,h),m=he(a));const y=Ve(v,o,i,s,r)?_s(v,e,t,i,s,r):null;if(y){const b=y.point[l];if(g?b<=o[m+n]:b>=o[m+n+3])return y}const x=Ve(m,o,i,s,r)?_s(m,e,t,i,s,r):null;return y&&x?y.distance<=x.distance?y:x:y||x||null}}const di=new f.Box3,ot=new ge,at=new ge,Et=new f.Matrix4,Mr=new te,pi=new te;function bc(a,e,t,i){Y.setBuffer(a._roots[e]);const s=vs(0,a,t,i);return Y.clearBuffer(),s}function vs(a,e,t,i,s=null){const{float32Array:r,uint16Array:o,uint32Array:c}=Y;let h=a*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),Mr.set(t.boundingBox.min,t.boundingBox.max,i),s=Mr),oe(h,o)){const p=e.geometry,n=p.index,l=p.attributes.position,d=t.index,g=t.attributes.position,v=le(a,c),m=ce(h,o);if(Et.copy(i).invert(),t.boundsTree)return Z(a,r,pi),pi.matrix.copy(Et),pi.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:y=>pi.intersectsBox(y),intersectsTriangle:y=>{y.a.applyMatrix4(i),y.b.applyMatrix4(i),y.c.applyMatrix4(i),y.needsUpdate=!0;for(let w=v,x=m+v;w<x;w++)if(K(at,3*e.resolveTriangleIndex(w),n,l),at.needsUpdate=!0,y.intersectsTriangle(at))return!0;return!1}});for(let _=v,y=m+v;_<y;_++){const w=e.resolveTriangleIndex(_);K(ot,3*w,n,l),ot.a.applyMatrix4(Et),ot.b.applyMatrix4(Et),ot.c.applyMatrix4(Et),ot.needsUpdate=!0;for(let x=0,b=d.count;x<b;x+=3)if(K(at,x,d,g),at.needsUpdate=!0,ot.intersectsTriangle(at))return!0}}else{const p=a+8,n=c[a+6];return Z(p,r,di),!!(s.intersectsBox(di)&&vs(p,e,t,i,s)||(Z(n,r,di),s.intersectsBox(di)&&vs(n,e,t,i,s)))}}const mi=new f.Matrix4,Zi=new te,kt=new te,Ac=new f.Vector3,Tc=new f.Vector3,Sc=new f.Vector3,Mc=new f.Vector3;function Cc(a,e,t,i={},s={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),Zi.set(e.boundingBox.min,e.boundingBox.max,t),Zi.needsUpdate=!0;const c=a.geometry,h=c.attributes.position,u=c.index,p=e.attributes.position,n=e.index,l=fe.getPrimitive(),d=fe.getPrimitive();let g=Ac,v=Tc,m=null,_=null;s&&(m=Sc,_=Mc);let y=1/0,w=null,x=null;return mi.copy(t).invert(),kt.matrix.copy(mi),a.shapecast({boundsTraverseOrder:b=>Zi.distanceToBox(b),intersectsBounds:(b,T,M)=>M<y&&M<o?(T&&(kt.min.copy(b.min),kt.max.copy(b.max),kt.needsUpdate=!0),!0):!1,intersectsRange:(b,T)=>{if(e.boundsTree){const M=e.boundsTree;return M.shapecast({boundsTraverseOrder:L=>kt.distanceToBox(L),intersectsBounds:(L,C,I)=>I<y&&I<o,intersectsRange:(L,C)=>{for(let I=L,D=L+C;I<D;I++){const A=M.resolveTriangleIndex(I);K(d,3*A,n,p),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let S=b,P=b+T;S<P;S++){const R=a.resolveTriangleIndex(S);K(l,3*R,u,h),l.needsUpdate=!0;const k=l.distanceToTriangle(d,g,m);if(k<y&&(v.copy(g),_&&_.copy(m),y=k,w=S,x=I),k<r)return!0}}}})}else{const M=xt(e);for(let L=0,C=M;L<C;L++){K(d,3*L,n,p),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let I=b,D=b+T;I<D;I++){const A=a.resolveTriangleIndex(I);K(l,3*A,u,h),l.needsUpdate=!0;const S=l.distanceToTriangle(d,g,m);if(S<y&&(v.copy(g),_&&_.copy(m),y=S,w=I,x=L),S<r)return!0}}}}}),fe.releasePrimitive(l),fe.releasePrimitive(d),y===1/0?null:(i.point?i.point.copy(v):i.point=v.clone(),i.distance=y,i.faceIndex=w,s&&(s.point?s.point.copy(_):s.point=_.clone(),s.point.applyMatrix4(mi),v.applyMatrix4(mi),s.distance=v.sub(s.point).length(),s.faceIndex=x),i)}function Dc(){return typeof SharedArrayBuffer<"u"}const Wt=new Y.constructor,bi=new Y.constructor,Fe=new Ps(()=>new f.Box3),lt=new f.Box3,ct=new f.Box3,Ki=new f.Box3,Xi=new f.Box3;let Ji=!1;function Lc(a,e,t,i){if(Ji)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Ji=!0;const s=a._roots,r=e._roots;let o,c=0,h=0;const u=new f.Matrix4().copy(t).invert();for(let p=0,n=s.length;p<n;p++){Wt.setBuffer(s[p]),h=0;const l=Fe.getPrimitive();Z(0,Wt.float32Array,l),l.applyMatrix4(u);for(let d=0,g=r.length;d<g&&(bi.setBuffer(r[p]),o=me(0,0,t,u,i,c,h,0,0,l),bi.clearBuffer(),h+=r[d].length,!o);d++);if(Fe.releasePrimitive(l),Wt.clearBuffer(),c+=s[p].length,o)break}return Ji=!1,o}function me(a,e,t,i,s,r=0,o=0,c=0,h=0,u=null,p=!1){let n,l;p?(n=bi,l=Wt):(n=Wt,l=bi);const d=n.float32Array,g=n.uint32Array,v=n.uint16Array,m=l.float32Array,_=l.uint32Array,y=l.uint16Array,w=a*2,x=e*2,b=oe(w,v),T=oe(x,y);let M=!1;if(T&&b)p?M=s(le(e,_),ce(e*2,y),le(a,g),ce(a*2,v),h,o+e,c,r+a):M=s(le(a,g),ce(a*2,v),le(e,_),ce(e*2,y),c,r+a,h,o+e);else if(T){const L=Fe.getPrimitive();Z(e,m,L),L.applyMatrix4(t);const C=he(a),I=ue(a,g);Z(C,d,lt),Z(I,d,ct);const D=L.intersectsBox(lt),A=L.intersectsBox(ct);M=D&&me(e,C,i,t,s,o,r,h,c+1,L,!p)||A&&me(e,I,i,t,s,o,r,h,c+1,L,!p),Fe.releasePrimitive(L)}else{const L=he(e),C=ue(e,_);Z(L,m,Ki),Z(C,m,Xi);const I=u.intersectsBox(Ki),D=u.intersectsBox(Xi);if(I&&D)M=me(a,L,t,i,s,r,o,c,h+1,u,p)||me(a,C,t,i,s,r,o,c,h+1,u,p);else if(I)if(b)M=me(a,L,t,i,s,r,o,c,h+1,u,p);else{const A=Fe.getPrimitive();A.copy(Ki).applyMatrix4(t);const S=he(a),P=ue(a,g);Z(S,d,lt),Z(P,d,ct);const R=A.intersectsBox(lt),k=A.intersectsBox(ct);M=R&&me(L,S,i,t,s,o,r,h,c+1,A,!p)||k&&me(L,P,i,t,s,o,r,h,c+1,A,!p),Fe.releasePrimitive(A)}else if(D)if(b)M=me(a,C,t,i,s,r,o,c,h+1,u,p);else{const A=Fe.getPrimitive();A.copy(Xi).applyMatrix4(t);const S=he(a),P=ue(a,g);Z(S,d,lt),Z(P,d,ct);const R=A.intersectsBox(lt),k=A.intersectsBox(ct);M=R&&me(C,S,i,t,s,o,r,h,c+1,A,!p)||k&&me(C,P,i,t,s,o,r,h,c+1,A,!p),Fe.releasePrimitive(A)}}return M}const gi=new te,Cr=new f.Box3,Pc={strategy:ln,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0};class Is{static serialize(e,t={}){t={cloneBuffers:!0,...t};const i=e.geometry,s=e._roots,r=e._indirectBuffer,o=i.getIndex();let c;return t.cloneBuffers?c={roots:s.map(h=>h.slice()),index:o?o.array.slice():null,indirectBuffer:r?r.slice():null}:c={roots:s,index:o?o.array:null,indirectBuffer:r},c}static deserialize(e,t,i={}){i={setIndex:!0,indirect:!!e.indirectBuffer,...i};const{index:s,roots:r,indirectBuffer:o}=e,c=new Is(t,{...i,[Gi]:!0});if(c._roots=r,c._indirectBuffer=o||null,i.setIndex){const h=t.getIndex();if(h===null){const u=new f.BufferAttribute(e.index,1,!1);t.setIndex(u)}else h.array!==s&&(h.array.set(s),h.needsUpdate=!0)}return c}get indirect(){return!!this._indirectBuffer}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t=Object.assign({...Pc,[Gi]:!1},t),t.useSharedArrayBuffer&&!Dc())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[Gi]||(jl(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new f.Box3))),this.resolveTriangleIndex=t.indirect?i=>this._indirectBuffer[i]:i=>i}refit(e=null){return(this.indirect?vc:nc)(this,e)}traverse(e,t=0){const i=this._roots[t],s=new Uint32Array(i),r=new Uint16Array(i);o(0);function o(c,h=0){const u=c*2,p=r[u+15]===Mi;if(p){const n=s[c+6],l=r[u+14];e(h,p,new Float32Array(i,c*4,6),n,l)}else{const n=c+Vt/4,l=s[c+6],d=s[c+7];e(h,p,new Float32Array(i,c*4,6),d)||(o(n,h+1),o(l,h+1))}}}raycast(e,t=f.FrontSide,i=0,s=1/0){const r=this._roots,o=this.geometry,c=[],h=t.isMaterial,u=Array.isArray(t),p=o.groups,n=h?t.side:t,l=this.indirect?yc:cc;for(let d=0,g=r.length;d<g;d++){const v=u?t[p[d].materialIndex].side:n,m=c.length;if(l(this,d,v,e,c,i,s),u){const _=p[d].materialIndex;for(let y=m,w=c.length;y<w;y++)c[y].face.materialIndex=_}}return c}raycastFirst(e,t=f.FrontSide,i=0,s=1/0){const r=this._roots,o=this.geometry,c=t.isMaterial,h=Array.isArray(t);let u=null;const p=o.groups,n=c?t.side:t,l=this.indirect?wc:uc;for(let d=0,g=r.length;d<g;d++){const v=h?t[p[d].materialIndex].side:n,m=l(this,d,v,e,i,s);m!=null&&(u==null||m.distance<u.distance)&&(u=m,h&&(m.face.materialIndex=p[d].materialIndex))}return u}intersectsGeometry(e,t){let i=!1;const s=this._roots,r=this.indirect?bc:fc;for(let o=0,c=s.length;o<c&&(i=r(this,o,e,t),!i);o++);return i}shapecast(e){const t=fe.getPrimitive(),i=this.indirect?lc:rc;let{boundsTraverseOrder:s,intersectsBounds:r,intersectsRange:o,intersectsTriangle:c}=e;if(o&&c){const n=o;o=(l,d,g,v,m)=>n(l,d,g,v,m)?!0:i(l,d,this,c,g,v,t)}else o||(c?o=(n,l,d,g)=>i(n,l,this,c,d,g,t):o=(n,l,d)=>d);let h=!1,u=0;const p=this._roots;for(let n=0,l=p.length;n<l;n++){const d=p[n];if(h=Jl(this,n,r,o,s,u),h)break;u+=d.byteLength}return fe.releasePrimitive(t),h}bvhcast(e,t,i){let{intersectsRanges:s,intersectsTriangles:r}=i;const o=fe.getPrimitive(),c=this.geometry.index,h=this.geometry.attributes.position,u=this.indirect?g=>{const v=this.resolveTriangleIndex(g);K(o,v*3,c,h)}:g=>{K(o,g*3,c,h)},p=fe.getPrimitive(),n=e.geometry.index,l=e.geometry.attributes.position,d=e.indirect?g=>{const v=e.resolveTriangleIndex(g);K(p,v*3,n,l)}:g=>{K(p,g*3,n,l)};if(r){const g=(v,m,_,y,w,x,b,T)=>{for(let M=_,L=_+y;M<L;M++){d(M),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let C=v,I=v+m;C<I;C++)if(u(C),o.needsUpdate=!0,r(o,p,C,M,w,x,b,T))return!0}return!1};if(s){const v=s;s=function(m,_,y,w,x,b,T,M){return v(m,_,y,w,x,b,T,M)?!0:g(m,_,y,w,x,b,T,M)}}else s=g}return Lc(this,e,t,s)}intersectsBox(e,t){return gi.set(e.min,e.max,t),gi.needsUpdate=!0,this.shapecast({intersectsBounds:i=>gi.intersectsBox(i),intersectsTriangle:i=>gi.intersectsTriangle(i)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,i={},s={},r=0,o=1/0){return(this.indirect?Cc:_c)(this,e,t,i,s,r,o)}closestPointToPoint(e,t={},i=0,s=1/0){return $l(this,e,t,i,s)}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(i=>{Z(0,new Float32Array(i),Cr),e.union(Cr)}),e}}class Ic{constructor(e){this.name="WorkerBase",this.running=!1,this.worker=e,this.worker.onerror=t=>{throw t.message?new Error(`${this.name}: Could not create Web Worker with error "${t.message}"`):new Error(`${this.name}: Could not create Web Worker.`)}}runTask(){}generate(...e){if(this.running)throw new Error("GenerateMeshBVHWorker: Already running job.");if(this.worker===null)throw new Error("GenerateMeshBVHWorker: Worker has been disposed.");this.running=!0;const t=this.runTask(this.worker,...e);return t.finally(()=>{this.running=!1}),t}dispose(){this.worker.terminate(),this.worker=null}}class Rc extends Ic{constructor(e){const t=new Worker(e||new URL("data:text/javascript;base64,aW1wb3J0IHsKCUJ1ZmZlckdlb21ldHJ5LAoJQnVmZmVyQXR0cmlidXRlLAp9IGZyb20gJ3RocmVlJzsKaW1wb3J0IHsgTWVzaEJWSCB9IGZyb20gJy4uL2NvcmUvTWVzaEJWSC5qcyc7Cgpvbm1lc3NhZ2UgPSAoIHsgZGF0YSB9ICkgPT4gewoKCWxldCBwcmV2VGltZSA9IHBlcmZvcm1hbmNlLm5vdygpOwoJZnVuY3Rpb24gb25Qcm9ncmVzc0NhbGxiYWNrKCBwcm9ncmVzcyApIHsKCgkJLy8gYWNjb3VudCBmb3IgZXJyb3IKCQlwcm9ncmVzcyA9IE1hdGgubWluKCBwcm9ncmVzcywgMSApOwoKCQljb25zdCBjdXJyVGltZSA9IHBlcmZvcm1hbmNlLm5vdygpOwoJCWlmICggY3VyclRpbWUgLSBwcmV2VGltZSA+PSAxMCAmJiBwcm9ncmVzcyAhPT0gMS4wICkgewoKCQkJcG9zdE1lc3NhZ2UoIHsKCgkJCQllcnJvcjogbnVsbCwKCQkJCXNlcmlhbGl6ZWQ6IG51bGwsCgkJCQlwb3NpdGlvbjogbnVsbCwKCQkJCXByb2dyZXNzLAoKCQkJfSApOwoJCQlwcmV2VGltZSA9IGN1cnJUaW1lOwoKCQl9CgoJfQoKCWNvbnN0IHsgaW5kZXgsIHBvc2l0aW9uLCBvcHRpb25zIH0gPSBkYXRhOwoJdHJ5IHsKCgkJY29uc3QgZ2VvbWV0cnkgPSBuZXcgQnVmZmVyR2VvbWV0cnkoKTsKCQlnZW9tZXRyeS5zZXRBdHRyaWJ1dGUoICdwb3NpdGlvbicsIG5ldyBCdWZmZXJBdHRyaWJ1dGUoIHBvc2l0aW9uLCAzLCBmYWxzZSApICk7CgkJaWYgKCBpbmRleCApIHsKCgkJCWdlb21ldHJ5LnNldEluZGV4KCBuZXcgQnVmZmVyQXR0cmlidXRlKCBpbmRleCwgMSwgZmFsc2UgKSApOwoKCQl9CgoJCWlmICggb3B0aW9ucy5pbmNsdWRlZFByb2dyZXNzQ2FsbGJhY2sgKSB7CgoJCQlvcHRpb25zLm9uUHJvZ3Jlc3MgPSBvblByb2dyZXNzQ2FsbGJhY2s7CgoJCX0KCgkJaWYgKCBvcHRpb25zLmdyb3VwcyApIHsKCgkJCWNvbnN0IGdyb3VwcyA9IG9wdGlvbnMuZ3JvdXBzOwoJCQlmb3IgKCBjb25zdCBpIGluIGdyb3VwcyApIHsKCgkJCQljb25zdCBncm91cCA9IGdyb3Vwc1sgaSBdOwoJCQkJZ2VvbWV0cnkuYWRkR3JvdXAoIGdyb3VwLnN0YXJ0LCBncm91cC5jb3VudCwgZ3JvdXAubWF0ZXJpYWxJbmRleCApOwoKCQkJfQoKCQl9CgoJCWNvbnN0IGJ2aCA9IG5ldyBNZXNoQlZIKCBnZW9tZXRyeSwgb3B0aW9ucyApOwoJCWNvbnN0IHNlcmlhbGl6ZWQgPSBNZXNoQlZILnNlcmlhbGl6ZSggYnZoLCB7IGNvcHlJbmRleEJ1ZmZlcjogZmFsc2UgfSApOwoJCWxldCB0b1RyYW5zZmVyID0gWyBwb3NpdGlvbi5idWZmZXIsIC4uLnNlcmlhbGl6ZWQucm9vdHMgXTsKCQlpZiAoIHNlcmlhbGl6ZWQuaW5kZXggKSB7CgoJCQl0b1RyYW5zZmVyLnB1c2goIHNlcmlhbGl6ZWQuaW5kZXguYnVmZmVyICk7CgoJCX0KCgkJdG9UcmFuc2ZlciA9IHRvVHJhbnNmZXIuZmlsdGVyKCB2ID0+ICggdHlwZW9mIFNoYXJlZEFycmF5QnVmZmVyID09PSAndW5kZWZpbmVkJyApIHx8ICEgKCB2IGluc3RhbmNlb2YgU2hhcmVkQXJyYXlCdWZmZXIgKSApOwoKCQlpZiAoIGJ2aC5faW5kaXJlY3RCdWZmZXIgKSB7CgoJCQl0b1RyYW5zZmVyLnB1c2goIHNlcmlhbGl6ZWQuaW5kaXJlY3RCdWZmZXIuYnVmZmVyICk7CgoJCX0KCgkJcG9zdE1lc3NhZ2UoIHsKCgkJCWVycm9yOiBudWxsLAoJCQlzZXJpYWxpemVkLAoJCQlwb3NpdGlvbiwKCQkJcHJvZ3Jlc3M6IDEsCgoJCX0sIHRvVHJhbnNmZXIgKTsKCgl9IGNhdGNoICggZXJyb3IgKSB7CgoJCXBvc3RNZXNzYWdlKCB7CgoJCQllcnJvciwKCQkJc2VyaWFsaXplZDogbnVsbCwKCQkJcG9zaXRpb246IG51bGwsCgkJCXByb2dyZXNzOiAxLAoKCQl9ICk7CgoJfQoKfTsK",typeof document>"u"?require("url").pathToFileURL(__filename).href:vt&&vt.src||new URL("shop-components.cjs",document.baseURI).href),{type:"module"});super(t),this.name="GenerateMeshBVHWorker"}runTask(e,t,i={}){return new Promise((s,r)=>{if(t.getAttribute("position").isInterleavedBufferAttribute||t.index&&t.index.isInterleavedBufferAttribute)throw new Error("GenerateMeshBVHWorker: InterleavedBufferAttribute are not supported for the geometry attributes.");e.onerror=u=>{r(new Error(`GenerateMeshBVHWorker: ${u.message}`))},e.onmessage=u=>{const{data:p}=u;if(p.error)r(new Error(p.error)),e.onmessage=null;else if(p.serialized){const{serialized:n,position:l}=p,d=Is.deserialize(n,t,{setIndex:!1}),g=Object.assign({setBoundingBox:!0},i);if(t.attributes.position.array=l,n.index)if(t.index)t.index.array=n.index;else{const v=new f.BufferAttribute(n.index,1,!1);t.setIndex(v)}g.setBoundingBox&&(t.boundingBox=d.getBoundingBox(new f.Box3)),i.onProgress&&i.onProgress(p.progress),s(d),e.onmessage=null}else i.onProgress&&i.onProgress(p.progress)};const o=t.index?t.index.array:null,c=t.attributes.position.array,h=[c];o&&h.push(o),e.postMessage({index:o,position:c,options:{...i,onProgress:null,includedProgressCallback:!!i.onProgress,groups:[...t.groups]}},h.map(u=>u.buffer).filter(u=>typeof SharedArrayBuffer>"u"||!(u instanceof SharedArrayBuffer)))})}}class Ec{constructor(e,t){this.lock=!1,this.lockX=!1,this.lockY=!1,this.invRotMat=new f.Matrix4,this.mouse=new f.Vector3,this.rotateStart=new f.Vector2,this.rotateEnd=new f.Vector2,this.rotateDelta=new f.Vector2,this.selectedAxis=null,this.isDragging=!1,this.context=null,this.orbitState=!0,this._animator=0,this._emitter=new Ye,this.addListener=this._emitter.addListener.bind(this._emitter),this.removeAllListeners=this._emitter.removeAllListeners.bind(this._emitter),this._text=document.createElement("div"),this._textTimer=0,this._update=()=>{this.lock||(this._textTimer&&(window.clearTimeout(this._textTimer),this._textTimer=0),this._textTimer=window.setTimeout(()=>{this._text.style.opacity="0"},800),this.camera.updateMatrix(),this.invRotMat.extractRotation(this.camera.matrix).invert(),this.axes.forEach(s=>{this.setAxisPosition(s)}),this.axes.sort((s,r)=>s.position.z>r.position.z?1:-1),this.drawLayers(!0),this._text.style.opacity="1",this._text.innerText=this.camera.position.distanceTo(this.orbit.target).toFixed(2)+" m")},this.updateMouseFromEvent=s=>{this.rect=this.domElement.getBoundingClientRect();const r=this.domElement.width/this.domElement.clientWidth,o=this.domElement.height/this.domElement.clientHeight,{left:c,top:h}=this.rect;this.mouse.set((s.clientX-c)*r,(s.clientY-h)*o,0)},this.updateSelectedAxisUnderMouse=()=>{this.selectedAxis=null,this.axes.forEach(s=>{this.mouse.distanceTo(s.position)<s.size&&(this.selectedAxis=s)})},this.onPointerDown=s=>{this.rotateStart.set(s.clientX,s.clientY),this.updateMouseFromEvent(s),this.updateSelectedAxisUnderMouse(),this.orbitState=this.orbit.enabled,this.orbit.enabled=!1,window.addEventListener("pointermove",this.onDrag,!1),window.addEventListener("pointerup",this.onPointerUp,!1)},this.onPointerUp=()=>{this.domElement.style.backgroundColor="#FFF0",setTimeout(()=>this.isDragging=!1,0),this.domElement.classList.remove("dragging"),this.orbit.enabled=this.orbitState,window.removeEventListener("pointermove",this.onDrag,!1),window.removeEventListener("pointerup",this.onPointerUp,!1)},this.onPointerEnter=()=>{this.domElement.style.backgroundColor="#FFF3",this.rect=this.domElement.getBoundingClientRect()},this.onPointerMove=s=>{if(this.lock||this.isDragging)return;const r=this.selectedAxis;s&&(this.updateMouseFromEvent(s),this.updateSelectedAxisUnderMouse()),r!==this.selectedAxis&&this.drawLayers()},this.onDrag=s=>{this.lock||(this.isDragging||this.domElement.classList.add("dragging"),this.isDragging=!0,this.selectedAxis=null,this.rotateEnd.set(s.clientX,s.clientY),this.rotateDelta.subVectors(this.rotateEnd,this.rotateStart).multiplyScalar(.5),this.rotateStart.copy(this.rotateEnd),this.orbit.update())},this.onMouseClick=s=>{if(this.lock||(this.updateMouseFromEvent(s),this.updateSelectedAxisUnderMouse(),this.isDragging||!this.selectedAxis))return;this._animator&&cancelAnimationFrame(this._animator);const r=this.selectedAxis.direction.clone();this.camera.lookAt(0,0,0);const o=this.camera.position.distanceTo(this.orbit.target);r.multiplyScalar(o),this.selectedAxis.axis==="z"?r.setZ(this.orbit.target.z+o):this.selectedAxis.axis==="-z"?r.setZ(this.orbit.target.z-o):r.setZ(this.orbit.target.z);const c=500,h=performance.now(),u=1,p=this.selectedAxis.axis,n=()=>{const d=performance.now()-h,g=Math.min(d/c,u);if(this.camera.position.lerp(r,g),this.orbit.update(),g!==u){this._animator=window.requestAnimationFrame(n);return}else this._animator=0,this.onPointerMove(void 0),this._emitter.emit("axis-select-end",p);this.onPointerMove(void 0)};this._emitter.emit("axis-select-start",p),n()},this.drawCircle=(s,r=10,o="#FF0000")=>{this.context&&(this.context.beginPath(),this.context.rect(s.x-r,s.y-r,r*2,r*2),this.context.fillStyle=o,this.context.fill(),this.context.closePath())},this.drawLine=(s,r,o=1,c="#FF0000")=>{this.context&&(this.context.beginPath(),this.context.moveTo(s.x,s.y),this.context.lineTo(r.x,r.y),this.context.lineWidth=o,this.context.strokeStyle=c,this.context.stroke(),this.context.closePath())},this.drawLayers=(s=!1)=>{this.context&&(s&&this.context.clearRect(0,0,this.domElement.width,this.domElement.height),this.axes.forEach(r=>{const o=this.selectedAxis===r,c=r.position.z>=-.01?r.color[0]:r.color[1];if(r.line&&this.drawLine(this.center,r.position,r.line,c),this.drawCircle(r.position,r.size,o?"#0066ff":c),r.label){const h=r.axis==="-x"?this.options.fontSize-3:this.options.fontSize;this.context.font=[this.options.fontWeight,h+"px",this.options.fontFamily].join(" "),this.context.fillStyle=this.options.fontColor,this.context.textBaseline="middle",this.context.textAlign="center",this.context.fillText(r.label,r.position.x,r.position.y)}}))},this.setAxisPosition=s=>{const r=s.direction.clone().applyMatrix4(this.invRotMat),o=s.size;s.position.set(r.x*(this.center.x-o/2-this.options.padding)+this.center.x,this.center.y-r.y*(this.center.y-o/2-this.options.padding),r.z)};const i={offset:new f.Vector2,size:90,padding:8,bubbleSizePrimary:8,bubbleSizeSecondary:6,lineWidth:2,fontSize:11,fontFamily:"arial",fontWeight:"normal",fontColor:"#fff",className:"orbit-controls-gizmo",colors:{x:["#f35f5f","#902525"],y:["#78da2f","#71ae45"],z:["#1d92fa","#d0d1d1"]}};this.options={...i,...t},this.orbit=e,this.camera=e.object,this.center=new f.Vector3(this.options.size/2,this.options.size/2,0),this.axes=this.createAxes(),this.domElement=this.createCanvas(this.options),this.orbit.addEventListener("change",this._update),this._text.style.cssText=`
3732
3732
  transition: all 0.8s ease-in-out;
3733
3733
  color: rgb(68, 78, 105);
3734
3734
  position: absolute;
@@ -3739,7 +3739,7 @@ ${t.name}`)}break}}}}else a.texture_lod=0}};ie=new WeakMap,xe=new WeakMap,ui=new
3739
3739
  margin-right: ${-this.options.size/4}px;
3740
3740
  font-size: 12px;
3741
3741
  text-align:center;
3742
- `}appendTo(e){e.append(this.domElement),e.append(this._text)}createAxes(){const{colors:e,lineWidth:t,bubbleSizePrimary:i,bubbleSizeSecondary:s}=this.options;return[{axis:"x",direction:new d.Vector3(1,0,0),size:i,color:e.x,line:t,label:"前",position:new d.Vector3},{axis:"y",direction:new d.Vector3(0,1,0),size:i,color:e.y,line:t,label:"左",position:new d.Vector3},{axis:"z",direction:new d.Vector3(0,0,1),size:i,color:e.z,line:t,label:"上",position:new d.Vector3},{axis:"-x",direction:new d.Vector3(-1,0,0),size:s,color:e.x,label:"后",position:new d.Vector3},{axis:"-y",direction:new d.Vector3(0,-1,0),size:s,color:e.y,position:new d.Vector3,label:"右"},{axis:"-z",direction:new d.Vector3(0,0,-1),size:i,color:e.z,label:"下",position:new d.Vector3}]}createCanvas(e){const t=document.createElement("canvas");return t.width=e.size,t.height=e.size,t.classList.add(e.className),t.style.cssText=`
3742
+ `}appendTo(e){e.append(this.domElement),e.append(this._text)}createAxes(){const{colors:e,lineWidth:t,bubbleSizePrimary:i,bubbleSizeSecondary:s}=this.options;return[{axis:"x",direction:new f.Vector3(1,0,0),size:i,color:e.x,line:t,label:"前",position:new f.Vector3},{axis:"y",direction:new f.Vector3(0,1,0),size:i,color:e.y,line:t,label:"左",position:new f.Vector3},{axis:"z",direction:new f.Vector3(0,0,1),size:i,color:e.z,line:t,label:"上",position:new f.Vector3},{axis:"-x",direction:new f.Vector3(-1,0,0),size:s,color:e.x,label:"后",position:new f.Vector3},{axis:"-y",direction:new f.Vector3(0,-1,0),size:s,color:e.y,position:new f.Vector3,label:"右"},{axis:"-z",direction:new f.Vector3(0,0,-1),size:i,color:e.z,label:"下",position:new f.Vector3}]}createCanvas(e){const t=document.createElement("canvas");return t.width=e.size,t.height=e.size,t.classList.add(e.className),t.style.cssText=`
3743
3743
  position: absolute;
3744
3744
  left: auto;
3745
3745
  top: ${this.options.offset.y}px;
@@ -3751,14 +3751,14 @@ ${t.name}`)}break}}}}else a.texture_lod=0}};ie=new WeakMap,xe=new WeakMap,ui=new
3751
3751
  border-radius: 100%;
3752
3752
  transition: background-color .15s linear;
3753
3753
  cursor: pointer;
3754
- `,t.addEventListener("pointerdown",this.onPointerDown,!1),t.addEventListener("pointerenter",this.onPointerEnter,!1),t.addEventListener("pointermove",this.onPointerMove,!1),t.addEventListener("click",this.onMouseClick,!1),this.context=t.getContext("2d"),t}destroy(){cancelAnimationFrame(this._animator),this.orbit.removeEventListener("change",this._update),this.orbit.enabled=this.orbitState,window.removeEventListener("pointermove",this.onDrag,!1),window.removeEventListener("pointerup",this.onPointerUp,!1),this._emitter.removeAllListeners(),this.domElement.removeEventListener("pointerdown",this.onPointerDown,!1),this.domElement.removeEventListener("pointerenter",this.onPointerEnter,!1),this.domElement.removeEventListener("pointermove",this.onPointerMove,!1),this.domElement.removeEventListener("click",this.onMouseClick,!1),this.domElement.remove(),window.clearTimeout(this._textTimer),this._text.remove()}}class hc{get isFinished(){return this.params?this.framesDone>=this.params.frames:!0}set visible(e){this.shadowCatcherMesh.visible=e,this.progShadowGrp.visible=e,e||(this.isRendering=!1)}get paused(){return this.params?this.params.paused:!0}set paused(e){this.params&&(this.params.paused=e,e&&(this.isRendering=!1))}constructor(e,t,{resolution:i=1024,shadowMapRes:s=1024,shadowBias:a=5e-4,lightCount:n=8,size:c=4,frames:h=40,lightRadius:f=1,ambientWeight:p=.8,alphaTest:r=.98,displayDelayFrames:l=1,paused:u=!1}={}){this.params={enabled:!0,frames:h,lightRadius:f,ambientWeight:p,alphaTest:r,debugHelpers:!1,size:c,displayDelayFrames:Math.max(0,Math.floor(l)),paused:u},this.scene=t,this.renderer=e,this.buffer1Active=!1,this.dirLights=[],this.dirLightsHelpers=[],this.clearColor=new d.Color,this.clearAlpha=0,this.progress=0,this.discardMaterial=new fc,this.lights=[],this.meshes=[],this.objectsToShow=[],this.autoHiddenObjects=[],this.objectsToShowSet=new Set,this.objectsToShowAncestors=new Set,this.framesDone=0,this.fixedCamera=null,this.isRendering=!1,this._displaySuppressed=!1,this._displayDelayRemaining=0,this._displayRestoreOpacity=1,this.shadowMapHistory=[],this.isZUp=d.Object3D.DEFAULT_UP.z===1,this.progShadowGrp=new d.Group,this.progShadowGrp.name="progressive_shadow_assets",this.scene.add(this.progShadowGrp),this.lightOrigin=new d.Group,this.lightOrigin.name="light_origin",this.isZUp?this.lightOrigin.position.set(c,c,c*1.5):this.lightOrigin.position.set(c,c,c),this.progShadowGrp.add(this.lightOrigin),this.lightGroup=new d.Group,this.lightGroup.name="all_dir_lights",this.progShadowGrp.add(this.lightGroup);const g=Math.PI;for(let v=0;v<n;v++){const _=new d.DirectionalLight(16777215,g/n);_.name="dir_light_"+v,_.castShadow=!0,_.shadow.bias=a,_.shadow.camera.near=.1,_.shadow.camera.far=50,_.shadow.camera.right=c/2,_.shadow.camera.left=-c/2,_.shadow.camera.top=c/2,_.shadow.camera.bottom=-c/2,_.shadow.mapSize.width=s,_.shadow.mapSize.height=s,this.dirLights.push(_),this.lightGroup.add(_)}const y=/(Android|iPad|iPhone|iPod)/g.test(navigator==null?void 0:navigator.userAgent)?d.HalfFloatType:d.FloatType;this.progressiveLightMap1=new d.WebGLRenderTarget(i,i,{type:y}),this.progressiveLightMap2=new d.WebGLRenderTarget(i,i,{type:y}),this.progressiveLightMap1.texture.colorSpace=d.NoColorSpace,this.progressiveLightMap2.texture.colorSpace=d.NoColorSpace,this.shadowCatcherMaterial=new uc({map:this.progressiveLightMap2.texture,transparent:!0,opacity:1});const m=new d.PlaneGeometry(c,c);this.isZUp||m.rotateX(-Math.PI/2),this.shadowCatcherMesh=new d.Mesh(m,this.shadowCatcherMaterial),this.isZUp?this.shadowCatcherMesh.position.z=.001:this.shadowCatcherMesh.position.y=.001,this.shadowCatcherMesh.name="shadowCatcherMesh",this.shadowCatcherMesh.receiveShadow=!0,this.progShadowGrp.add(this.shadowCatcherMesh),this.addObjectToShow(this.progShadowGrp),this.addObjectToShow(this.lightGroup),this.addObjectToShow(this.lightOrigin),this.addObjectToShow(this.shadowCatcherMesh),this.rebuildObjectsToShowAncestors(),this.debugHelpersGroup=new d.Group,this.targetMat=new d.MeshLambertMaterial({fog:!1}),this.previousShadowMap={value:this.progressiveLightMap1.texture},this.averagingWindow={value:h},this.targetMat.onBeforeCompile=v=>{v.vertexShader=`varying vec2 vUv;
3755
- `+v.vertexShader.slice(0,-1)+"vUv = uv; gl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0); }";const _=v.fragmentShader.indexOf("void main() {");v.fragmentShader=`varying vec2 vUv;
3756
- `+v.fragmentShader.slice(0,_)+`uniform sampler2D previousShadowMap;
3754
+ `,t.addEventListener("pointerdown",this.onPointerDown,!1),t.addEventListener("pointerenter",this.onPointerEnter,!1),t.addEventListener("pointermove",this.onPointerMove,!1),t.addEventListener("click",this.onMouseClick,!1),this.context=t.getContext("2d"),t}destroy(){cancelAnimationFrame(this._animator),this.orbit.removeEventListener("change",this._update),this.orbit.enabled=this.orbitState,window.removeEventListener("pointermove",this.onDrag,!1),window.removeEventListener("pointerup",this.onPointerUp,!1),this._emitter.removeAllListeners(),this.domElement.removeEventListener("pointerdown",this.onPointerDown,!1),this.domElement.removeEventListener("pointerenter",this.onPointerEnter,!1),this.domElement.removeEventListener("pointermove",this.onPointerMove,!1),this.domElement.removeEventListener("click",this.onMouseClick,!1),this.domElement.remove(),window.clearTimeout(this._textTimer),this._text.remove()}}class kc{get isFinished(){return this.params?this.framesDone>=this.params.frames:!0}set visible(e){this.shadowCatcherMesh.visible=e,this.progShadowGrp.visible=e,e||(this.isRendering=!1)}get paused(){return this.params?this.params.paused:!0}set paused(e){this.params&&(this.params.paused=e,e&&(this.isRendering=!1))}constructor(e,t,{resolution:i=1024,shadowMapRes:s=1024,shadowBias:r=5e-4,lightCount:o=8,size:c=4,frames:h=40,lightRadius:u=1,ambientWeight:p=.8,alphaTest:n=.98,displayDelayFrames:l=1,paused:d=!1}={}){this.params={enabled:!0,frames:h,lightRadius:u,ambientWeight:p,alphaTest:n,debugHelpers:!1,size:c,displayDelayFrames:Math.max(0,Math.floor(l)),paused:d},this.scene=t,this.renderer=e,this.buffer1Active=!1,this.dirLights=[],this.dirLightsHelpers=[],this.clearColor=new f.Color,this.clearAlpha=0,this.progress=0,this.discardMaterial=new Bc,this.lights=[],this.meshes=[],this.objectsToShow=[],this.autoHiddenObjects=[],this.objectsToShowSet=new Set,this.objectsToShowAncestors=new Set,this.framesDone=0,this.fixedCamera=null,this.isRendering=!1,this._displaySuppressed=!1,this._displayDelayRemaining=0,this._displayRestoreOpacity=1,this.shadowMapHistory=[],this.isZUp=f.Object3D.DEFAULT_UP.z===1,this.progShadowGrp=new f.Group,this.progShadowGrp.name="progressive_shadow_assets",this.scene.add(this.progShadowGrp),this.lightOrigin=new f.Group,this.lightOrigin.name="light_origin",this.isZUp?this.lightOrigin.position.set(c,c,c*1.5):this.lightOrigin.position.set(c,c,c),this.progShadowGrp.add(this.lightOrigin),this.lightGroup=new f.Group,this.lightGroup.name="all_dir_lights",this.progShadowGrp.add(this.lightGroup);const g=Math.PI;for(let _=0;_<o;_++){const y=new f.DirectionalLight(16777215,g/o);y.name="dir_light_"+_,y.castShadow=!0,y.shadow.bias=r,y.shadow.camera.near=.1,y.shadow.camera.far=50,y.shadow.camera.right=c/2,y.shadow.camera.left=-c/2,y.shadow.camera.top=c/2,y.shadow.camera.bottom=-c/2,y.shadow.mapSize.width=s,y.shadow.mapSize.height=s,this.dirLights.push(y),this.lightGroup.add(y)}const v=/(Android|iPad|iPhone|iPod)/g.test(navigator==null?void 0:navigator.userAgent)?f.HalfFloatType:f.FloatType;this.progressiveLightMap1=new f.WebGLRenderTarget(i,i,{type:v}),this.progressiveLightMap2=new f.WebGLRenderTarget(i,i,{type:v}),this.progressiveLightMap1.texture.colorSpace=f.NoColorSpace,this.progressiveLightMap2.texture.colorSpace=f.NoColorSpace,this.shadowCatcherMaterial=new Fc({map:this.progressiveLightMap2.texture,transparent:!0,opacity:1});const m=new f.PlaneGeometry(c,c);this.isZUp||m.rotateX(-Math.PI/2),this.shadowCatcherMesh=new f.Mesh(m,this.shadowCatcherMaterial),this.isZUp?this.shadowCatcherMesh.position.z=.001:this.shadowCatcherMesh.position.y=.001,this.shadowCatcherMesh.name="shadowCatcherMesh",this.shadowCatcherMesh.receiveShadow=!0,this.progShadowGrp.add(this.shadowCatcherMesh),this.addObjectToShow(this.progShadowGrp),this.addObjectToShow(this.lightGroup),this.addObjectToShow(this.lightOrigin),this.addObjectToShow(this.shadowCatcherMesh),this.rebuildObjectsToShowAncestors(),this.debugHelpersGroup=new f.Group,this.targetMat=new f.MeshLambertMaterial({fog:!1}),this.previousShadowMap={value:this.progressiveLightMap1.texture},this.averagingWindow={value:h},this.targetMat.onBeforeCompile=_=>{_.vertexShader=`varying vec2 vUv;
3755
+ `+_.vertexShader.slice(0,-1)+"vUv = uv; gl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0); }";const y=_.fragmentShader.indexOf("void main() {");_.fragmentShader=`varying vec2 vUv;
3756
+ `+_.fragmentShader.slice(0,y)+`uniform sampler2D previousShadowMap;
3757
3757
  uniform float averagingWindow;
3758
- `+v.fragmentShader.slice(_-1,-1)+`
3758
+ `+_.fragmentShader.slice(y-1,-1)+`
3759
3759
  vec3 texelOld = texture2D(previousShadowMap, vUv).rgb;
3760
3760
  gl_FragColor.rgb = mix(texelOld, gl_FragColor.rgb, 1.0/ averagingWindow);
3761
- }`,v.uniforms.previousShadowMap=this.previousShadowMap,v.uniforms.averagingWindow=this.averagingWindow},this._pushShadowHistory("init")}_now(){try{if(typeof performance<"u"&&typeof performance.now=="function")return performance.now()}catch{}return Date.now()}_getMeshMaterialLabel(){var t;const e=(t=this.shadowCatcherMesh)==null?void 0:t.material;return e?e===this.shadowCatcherMaterial?"shadowCatcherMaterial":e===this.targetMat?"targetMat":e.type||"unknown":"none"}_getTextureLabel(e){var t,i;return e?(t=this.progressiveLightMap1)!=null&&t.texture&&e===this.progressiveLightMap1.texture?"progressiveLightMap1":(i=this.progressiveLightMap2)!=null&&i.texture&&e===this.progressiveLightMap2.texture?"progressiveLightMap2":e.uuid?`external:${e.uuid}`:"external":"none"}_pushShadowHistory(e,t={}){const i=this.shadowCatcherMaterial,s={time:this._now(),reason:e,framesDone:this.framesDone,buffer1Active:this.buffer1Active,isRendering:this.isRendering,displaySuppressed:this._displaySuppressed,displayDelayRemaining:this._displayDelayRemaining,displayMap:this._getTextureLabel(i==null?void 0:i.map),alphaTest:typeof(i==null?void 0:i.alphaTest)=="number"?i.alphaTest:0,opacity:typeof(i==null?void 0:i.opacity)=="number"?i.opacity:0,meshMaterial:this._getMeshMaterialLabel(),...t};this.shadowMapHistory.push(s);const a=180;this.shadowMapHistory.length>a&&this.shadowMapHistory.splice(0,this.shadowMapHistory.length-a)}_suppressDisplay(e,t){const i=this.shadowCatcherMaterial;if(!i)return;this._displaySuppressed||(this._displayRestoreOpacity=typeof i.opacity=="number"?i.opacity:1),this._displaySuppressed=!0;const s=t===void 0?this.params.displayDelayFrames:Math.max(0,Math.floor(t));this._displayDelayRemaining=Math.max(this._displayDelayRemaining,s),typeof i.opacity=="number"&&(i.opacity=0),this._pushShadowHistory(`display_suppress:${e}`)}_tickDisplaySuppression(){if(!this._displaySuppressed||(this._displayDelayRemaining>0&&(this._displayDelayRemaining-=1),this._displayDelayRemaining>0))return;const e=this.shadowCatcherMaterial;e&&typeof e.opacity=="number"&&(e.opacity=this._displayRestoreOpacity),this._displaySuppressed=!1,this._pushShadowHistory("display_restore")}renderOnRenderTargets(e){this.prepare(),this.averagingWindow.value=Math.max(this.framesDone+1,1);const t=this.buffer1Active?this.progressiveLightMap1:this.progressiveLightMap2,i=this.buffer1Active?this.progressiveLightMap2:this.progressiveLightMap1;this.renderer.setRenderTarget(t),this.previousShadowMap.value=i.texture,this.buffer1Active=!this.buffer1Active,this.renderer.render(this.scene,e),this.finish(),this.shadowCatcherMaterial.map=t.texture,this._pushShadowHistory("renderOnRenderTargets",{writeMap:this._getTextureLabel(t.texture),readMap:this._getTextureLabel(i.texture)}),this.renderer.setRenderTarget(null)}showDebugHelpers(e){if(!this.debugHelpersGroup.children.length){const t=new d.Mesh(new d.PlaneGeometry(2,2),new d.MeshBasicMaterial({map:this.progressiveLightMap1.texture,side:d.DoubleSide}));this.isZUp?t.position.z=this.params.size/2:t.position.y=this.params.size/2;for(const a of this.dirLights){const n=new d.DirectionalLightHelper(a);this.dirLightsHelpers.push(n)}const i=this.isZUp?new d.Vector3(0,0,1):new d.Vector3(0,1,0),s=new d.PlaneHelper(new d.Plane(i,.001),this.params.size,16776960);this.debugHelpersGroup.add(t,s,...this.dirLightsHelpers)}e?(this.progShadowGrp.add(this.debugHelpersGroup),this.dirLightsHelpers.forEach(t=>{t.update()})):this.progShadowGrp.remove(this.debugHelpersGroup)}randomiseLights(){const e=this.lightOrigin.position.length();for(let t=0;t<this.dirLights.length;t++){if(Math.random()>this.params.ambientWeight)this.dirLights[t].position.set(this.lightOrigin.position.x,this.lightOrigin.position.y+d.MathUtils.randFloatSpread(this.params.lightRadius),this.lightOrigin.position.z+d.MathUtils.randFloatSpread(this.params.lightRadius));else{const i=Math.acos(2*Math.random()-1)-1.570795,s=2*3.14159*Math.random();this.isZUp?this.dirLights[t].position.set(Math.cos(i)*Math.cos(s)*e,Math.cos(i)*Math.sin(s)*e,Math.abs(Math.sin(i)*e)):this.dirLights[t].position.set(Math.cos(i)*Math.cos(s)*e,Math.abs(Math.cos(i)*Math.sin(s)*e),Math.sin(i)*e)}this.params.debugHelpers&&this.dirLightsHelpers[t].update()}}async recalculate(){this.params.enabled&&(this._suppressDisplay("recalculate"),this._pushShadowHistory("recalculate"),this.clear())}prepare(){this.lights.forEach(t=>{t.object.intensity=0}),this.meshes.forEach(t=>{t.object.material=this.discardMaterial}),this.autoHiddenObjects.length=0;const e=t=>this.objectsToShowAncestors.has(t);this.scene.traverse(t=>{t!==this.scene&&(this.isExcludedObject(t)||e(t)||t.isLight||t.isCamera||t.visible&&(this.autoHiddenObjects.push({object:t,visible:t.visible}),t.visible=!1))}),this.lightGroup.visible=!0,this.shadowCatcherMesh.material=this.targetMat,this.params.debugHelpers&&this.showDebugHelpers(!1)}finish(){this.lights.forEach(e=>{e.object.intensity=e.intensity}),this.meshes.forEach(e=>{e.object.material=e.material}),this.autoHiddenObjects.forEach(e=>{e.object.visible=e.visible}),this.autoHiddenObjects.length=0,this.lightGroup.visible=!1,this.shadowCatcherMesh.material=this.shadowCatcherMaterial,this.params.debugHelpers&&this.showDebugHelpers(!0)}clear(){this._suppressDisplay("clear"),this._pushShadowHistory("clear_begin"),this.renderer.getClearColor(this.clearColor),this.clearAlpha=this.renderer.getClearAlpha(),this.renderer.setClearColor("black",1),this.renderer.setRenderTarget(this.progressiveLightMap1),this.renderer.clear(),this.renderer.setRenderTarget(this.progressiveLightMap2),this.renderer.clear(),this.renderer.setRenderTarget(null),this.renderer.setClearColor(this.clearColor,this.clearAlpha),this.buffer1Active=!1,this.shadowCatcherMaterial.alphaTest=0;try{this.shadowCatcherMesh.material.alphaTest=0}catch{}this.framesDone=0,this.fixedCamera=null,this.isRendering=!1,this.updateShadowObjectsList(),this._pushShadowHistory("clear_end")}updateShadowObjectsList(){this.lights.length=0,this.meshes.length=0,this.objectsToShow.length=0,this.objectsToShowSet.clear(),this.addObjectToShow(this.progShadowGrp),this.addObjectToShow(this.lightGroup),this.addObjectToShow(this.lightOrigin),this.addObjectToShow(this.shadowCatcherMesh),this.scene.traverse(e=>{if(e!==this.scene){if(this.isExcludedObject(e)){this.addObjectToShow(e);return}if(e===this.progShadowGrp||e===this.lightGroup||e===this.lightOrigin){this.addObjectToShow(e);return}if(e===this.shadowCatcherMesh){this.addObjectToShow(e);return}if(e.isLight&&e.parent!==this.lightGroup){this.lights.push({object:e,intensity:e.intensity});return}e.isGoods||e.isTransformControls||e.geometry&&e!==this.shadowCatcherMesh&&e.castShadow&&(this.meshes.push({object:e,material:e.material}),this.addObjectToShow(e))}}),this.rebuildObjectsToShowAncestors()}addObjectToShow(e){e&&(this.objectsToShowSet.has(e)||(this.objectsToShow.push({object:e,visible:e.visible}),this.objectsToShowSet.add(e)))}rebuildObjectsToShowAncestors(){this.objectsToShowAncestors.clear();const e=t=>{let i=t;for(;i&&!this.objectsToShowAncestors.has(i);)this.objectsToShowAncestors.add(i),i=i.parent};this.objectsToShow.forEach(({object:t})=>{e(t)})}isExcludedObject(e){const t=e;return!!(t.isCSS2DObject||t.isCSS3DObject||t.isHelper||typeof e.type=="string"&&e.type.endsWith("Helper")||typeof e.name=="string"&&e.name.toLowerCase().includes("helper"))}update(e){!this.params||!this.shadowCatcherMesh||!this.progressiveLightMap1||!this.progressiveLightMap2||!this.params.enabled||this.framesDone>=this.params.frames||this.params.paused||!this.shadowCatcherMesh.visible||!this.progShadowGrp.visible||(this.framesDone===0&&(this.fixedCamera=e.clone(),this.isRendering=!0),this.shadowCatcherMaterial.alphaTest=d.MathUtils.clamp(d.MathUtils.mapLinear(this.framesDone,2,this.params.frames-1,0,this.params.alphaTest),0,1),this.renderOnRenderTargets(this.fixedCamera||e),this.randomiseLights(),this.progress=d.MathUtils.mapLinear(this.framesDone,0,this.params.frames-1,0,100),this.framesDone++,this._tickDisplaySuppression(),this.framesDone>=this.params.frames&&(this._displaySuppressed&&(this._displayDelayRemaining=0,this._tickDisplaySuppression()),this.fixedCamera=null,this.isRendering=!1))}destroy(){this.scene&&this.progShadowGrp&&this.scene.remove(this.progShadowGrp),this.progressiveLightMap1&&(this.progressiveLightMap1.dispose(),this.progressiveLightMap1=null),this.progressiveLightMap2&&(this.progressiveLightMap2.dispose(),this.progressiveLightMap2=null),this.shadowCatcherMaterial&&(this.shadowCatcherMaterial.dispose(),this.shadowCatcherMaterial=null),this.targetMat&&(this.targetMat.dispose(),this.targetMat=null),this.discardMaterial&&(this.discardMaterial.dispose(),this.discardMaterial=null),this.shadowCatcherMesh&&(this.shadowCatcherMesh.geometry&&this.shadowCatcherMesh.geometry.dispose(),this.shadowCatcherMesh=null),this.dirLights.forEach(e=>{e.parent&&e.parent.remove(e);const t=e;t.dispose&&typeof t.dispose=="function"&&t.dispose()}),this.dirLights=[],this.dirLightsHelpers.forEach(e=>{e.parent&&e.parent.remove(e);const t=e;t.dispose&&typeof t.dispose=="function"&&t.dispose()}),this.dirLightsHelpers=[],this.debugHelpersGroup&&(this.debugHelpersGroup.children.forEach(e=>{e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose()}),this.debugHelpersGroup.clear(),this.debugHelpersGroup=null),this.progShadowGrp&&(this.progShadowGrp.clear(),this.progShadowGrp=null),this.lightGroup&&(this.lightGroup.clear(),this.lightGroup=null),this.lightOrigin&&(this.lightOrigin.clear(),this.lightOrigin=null),this.lights=[],this.meshes=[],this.objectsToShow=[],this.autoHiddenObjects=[],this.objectsToShowSet=new Set,this.objectsToShowAncestors=new Set,this.shadowMapHistory.length=0,this._displaySuppressed=!1,this._displayDelayRemaining=0,this._displayRestoreOpacity=1,this.scene=null,this.renderer=null,this.fixedCamera=null,this.clearColor=null,this.previousShadowMap=null,this.averagingWindow=null,this.params=null}}function Yr(o={},e,t,i=s=>{}){const s=class extends d.ShaderMaterial{constructor(a={}){const n=Object.entries(o);super({uniforms:n.reduce((c,[h,f])=>{const p=d.UniformsUtils.clone({[h]:{value:f}});return{...c,...p}},{}),vertexShader:e,fragmentShader:t}),n.forEach(([c])=>Object.defineProperty(this,c,{get:()=>this.uniforms[c].value,set:h=>this.uniforms[c].value=h})),Object.assign(this,a),i&&i(this)}};return s.key=d.MathUtils.generateUUID(),s}const uc=Yr({transparent:!0,color:new d.Color(0,0,0),alphaTest:0,opacity:1,map:null,depthWrite:!1,toneMapped:!1,blend:2},`varying vec2 vUv;
3761
+ }`,_.uniforms.previousShadowMap=this.previousShadowMap,_.uniforms.averagingWindow=this.averagingWindow},this._pushShadowHistory("init")}_now(){try{if(typeof performance<"u"&&typeof performance.now=="function")return performance.now()}catch{}return Date.now()}_getMeshMaterialLabel(){var t;const e=(t=this.shadowCatcherMesh)==null?void 0:t.material;return e?e===this.shadowCatcherMaterial?"shadowCatcherMaterial":e===this.targetMat?"targetMat":e.type||"unknown":"none"}_getTextureLabel(e){var t,i;return e?(t=this.progressiveLightMap1)!=null&&t.texture&&e===this.progressiveLightMap1.texture?"progressiveLightMap1":(i=this.progressiveLightMap2)!=null&&i.texture&&e===this.progressiveLightMap2.texture?"progressiveLightMap2":e.uuid?`external:${e.uuid}`:"external":"none"}_pushShadowHistory(e,t={}){const i=this.shadowCatcherMaterial,s={time:this._now(),reason:e,framesDone:this.framesDone,buffer1Active:this.buffer1Active,isRendering:this.isRendering,displaySuppressed:this._displaySuppressed,displayDelayRemaining:this._displayDelayRemaining,displayMap:this._getTextureLabel(i==null?void 0:i.map),alphaTest:typeof(i==null?void 0:i.alphaTest)=="number"?i.alphaTest:0,opacity:typeof(i==null?void 0:i.opacity)=="number"?i.opacity:0,meshMaterial:this._getMeshMaterialLabel(),...t};this.shadowMapHistory.push(s);const r=180;this.shadowMapHistory.length>r&&this.shadowMapHistory.splice(0,this.shadowMapHistory.length-r)}_suppressDisplay(e,t){const i=this.shadowCatcherMaterial;if(!i)return;this._displaySuppressed||(this._displayRestoreOpacity=typeof i.opacity=="number"?i.opacity:1),this._displaySuppressed=!0;const s=t===void 0?this.params.displayDelayFrames:Math.max(0,Math.floor(t));this._displayDelayRemaining=Math.max(this._displayDelayRemaining,s),typeof i.opacity=="number"&&(i.opacity=0),this._pushShadowHistory(`display_suppress:${e}`)}_tickDisplaySuppression(){if(!this._displaySuppressed||(this._displayDelayRemaining>0&&(this._displayDelayRemaining-=1),this._displayDelayRemaining>0))return;const e=this.shadowCatcherMaterial;e&&typeof e.opacity=="number"&&(e.opacity=this._displayRestoreOpacity),this._displaySuppressed=!1,this._pushShadowHistory("display_restore")}renderOnRenderTargets(e){this.prepare(),this.averagingWindow.value=Math.max(this.framesDone+1,1);const t=this.buffer1Active?this.progressiveLightMap1:this.progressiveLightMap2,i=this.buffer1Active?this.progressiveLightMap2:this.progressiveLightMap1;this.renderer.setRenderTarget(t),this.previousShadowMap.value=i.texture,this.buffer1Active=!this.buffer1Active,this.renderer.render(this.scene,e),this.finish(),this.shadowCatcherMaterial.map=t.texture,this._pushShadowHistory("renderOnRenderTargets",{writeMap:this._getTextureLabel(t.texture),readMap:this._getTextureLabel(i.texture)}),this.renderer.setRenderTarget(null)}showDebugHelpers(e){if(!this.debugHelpersGroup.children.length){const t=new f.Mesh(new f.PlaneGeometry(2,2),new f.MeshBasicMaterial({map:this.progressiveLightMap1.texture,side:f.DoubleSide}));this.isZUp?t.position.z=this.params.size/2:t.position.y=this.params.size/2;for(const r of this.dirLights){const o=new f.DirectionalLightHelper(r);this.dirLightsHelpers.push(o)}const i=this.isZUp?new f.Vector3(0,0,1):new f.Vector3(0,1,0),s=new f.PlaneHelper(new f.Plane(i,.001),this.params.size,16776960);this.debugHelpersGroup.add(t,s,...this.dirLightsHelpers)}e?(this.progShadowGrp.add(this.debugHelpersGroup),this.dirLightsHelpers.forEach(t=>{t.update()})):this.progShadowGrp.remove(this.debugHelpersGroup)}randomiseLights(){const e=this.lightOrigin.position.length();for(let t=0;t<this.dirLights.length;t++){if(Math.random()>this.params.ambientWeight)this.dirLights[t].position.set(this.lightOrigin.position.x,this.lightOrigin.position.y+f.MathUtils.randFloatSpread(this.params.lightRadius),this.lightOrigin.position.z+f.MathUtils.randFloatSpread(this.params.lightRadius));else{const i=Math.acos(2*Math.random()-1)-1.570795,s=2*3.14159*Math.random();this.isZUp?this.dirLights[t].position.set(Math.cos(i)*Math.cos(s)*e,Math.cos(i)*Math.sin(s)*e,Math.abs(Math.sin(i)*e)):this.dirLights[t].position.set(Math.cos(i)*Math.cos(s)*e,Math.abs(Math.cos(i)*Math.sin(s)*e),Math.sin(i)*e)}this.params.debugHelpers&&this.dirLightsHelpers[t].update()}}async recalculate(){this.params.enabled&&(this._suppressDisplay("recalculate"),this._pushShadowHistory("recalculate"),this.clear())}prepare(){this.lights.forEach(t=>{t.object.intensity=0}),this.meshes.forEach(t=>{t.object.material=this.discardMaterial}),this.autoHiddenObjects.length=0;const e=t=>this.objectsToShowAncestors.has(t);this.scene.traverse(t=>{t!==this.scene&&(this.isExcludedObject(t)||e(t)||t.isLight||t.isCamera||t.visible&&(this.autoHiddenObjects.push({object:t,visible:t.visible}),t.visible=!1))}),this.lightGroup.visible=!0,this.shadowCatcherMesh.material=this.targetMat,this.params.debugHelpers&&this.showDebugHelpers(!1)}finish(){this.lights.forEach(e=>{e.object.intensity=e.intensity}),this.meshes.forEach(e=>{e.object.material=e.material}),this.autoHiddenObjects.forEach(e=>{e.object.visible=e.visible}),this.autoHiddenObjects.length=0,this.lightGroup.visible=!1,this.shadowCatcherMesh.material=this.shadowCatcherMaterial,this.params.debugHelpers&&this.showDebugHelpers(!0)}clear(){this._suppressDisplay("clear"),this._pushShadowHistory("clear_begin"),this.renderer.getClearColor(this.clearColor),this.clearAlpha=this.renderer.getClearAlpha(),this.renderer.setClearColor("black",1),this.renderer.setRenderTarget(this.progressiveLightMap1),this.renderer.clear(),this.renderer.setRenderTarget(this.progressiveLightMap2),this.renderer.clear(),this.renderer.setRenderTarget(null),this.renderer.setClearColor(this.clearColor,this.clearAlpha),this.buffer1Active=!1,this.shadowCatcherMaterial.alphaTest=0;try{this.shadowCatcherMesh.material.alphaTest=0}catch{}this.framesDone=0,this.fixedCamera=null,this.isRendering=!1,this.updateShadowObjectsList(),this._pushShadowHistory("clear_end")}updateShadowObjectsList(){this.lights.length=0,this.meshes.length=0,this.objectsToShow.length=0,this.objectsToShowSet.clear(),this.addObjectToShow(this.progShadowGrp),this.addObjectToShow(this.lightGroup),this.addObjectToShow(this.lightOrigin),this.addObjectToShow(this.shadowCatcherMesh),this.scene.traverse(e=>{if(e!==this.scene){if(this.isExcludedObject(e)){this.addObjectToShow(e);return}if(e===this.progShadowGrp||e===this.lightGroup||e===this.lightOrigin){this.addObjectToShow(e);return}if(e===this.shadowCatcherMesh){this.addObjectToShow(e);return}if(e.isLight&&e.parent!==this.lightGroup){this.lights.push({object:e,intensity:e.intensity});return}e.isGoods||e.isTransformControls||e.geometry&&e!==this.shadowCatcherMesh&&e.castShadow&&(this.meshes.push({object:e,material:e.material}),this.addObjectToShow(e))}}),this.rebuildObjectsToShowAncestors()}addObjectToShow(e){e&&(this.objectsToShowSet.has(e)||(this.objectsToShow.push({object:e,visible:e.visible}),this.objectsToShowSet.add(e)))}rebuildObjectsToShowAncestors(){this.objectsToShowAncestors.clear();const e=t=>{let i=t;for(;i&&!this.objectsToShowAncestors.has(i);)this.objectsToShowAncestors.add(i),i=i.parent};this.objectsToShow.forEach(({object:t})=>{e(t)})}isExcludedObject(e){const t=e;return!!(t.isCSS2DObject||t.isCSS3DObject||t.isHelper||typeof e.type=="string"&&e.type.endsWith("Helper")||typeof e.name=="string"&&e.name.toLowerCase().includes("helper"))}update(e){!this.params||!this.shadowCatcherMesh||!this.progressiveLightMap1||!this.progressiveLightMap2||!this.params.enabled||this.framesDone>=this.params.frames||this.params.paused||!this.shadowCatcherMesh.visible||!this.progShadowGrp.visible||(this.framesDone===0&&(this.fixedCamera=e.clone(),this.isRendering=!0),this.shadowCatcherMaterial.alphaTest=f.MathUtils.clamp(f.MathUtils.mapLinear(this.framesDone,2,this.params.frames-1,0,this.params.alphaTest),0,1),this.renderOnRenderTargets(this.fixedCamera||e),this.randomiseLights(),this.progress=f.MathUtils.mapLinear(this.framesDone,0,this.params.frames-1,0,100),this.framesDone++,this._tickDisplaySuppression(),this.framesDone>=this.params.frames&&(this._displaySuppressed&&(this._displayDelayRemaining=0,this._tickDisplaySuppression()),this.fixedCamera=null,this.isRendering=!1))}destroy(){this.scene&&this.progShadowGrp&&this.scene.remove(this.progShadowGrp),this.progressiveLightMap1&&(this.progressiveLightMap1.dispose(),this.progressiveLightMap1=null),this.progressiveLightMap2&&(this.progressiveLightMap2.dispose(),this.progressiveLightMap2=null),this.shadowCatcherMaterial&&(this.shadowCatcherMaterial.dispose(),this.shadowCatcherMaterial=null),this.targetMat&&(this.targetMat.dispose(),this.targetMat=null),this.discardMaterial&&(this.discardMaterial.dispose(),this.discardMaterial=null),this.shadowCatcherMesh&&(this.shadowCatcherMesh.geometry&&this.shadowCatcherMesh.geometry.dispose(),this.shadowCatcherMesh=null),this.dirLights.forEach(e=>{e.parent&&e.parent.remove(e);const t=e;t.dispose&&typeof t.dispose=="function"&&t.dispose()}),this.dirLights=[],this.dirLightsHelpers.forEach(e=>{e.parent&&e.parent.remove(e);const t=e;t.dispose&&typeof t.dispose=="function"&&t.dispose()}),this.dirLightsHelpers=[],this.debugHelpersGroup&&(this.debugHelpersGroup.children.forEach(e=>{e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose()}),this.debugHelpersGroup.clear(),this.debugHelpersGroup=null),this.progShadowGrp&&(this.progShadowGrp.clear(),this.progShadowGrp=null),this.lightGroup&&(this.lightGroup.clear(),this.lightGroup=null),this.lightOrigin&&(this.lightOrigin.clear(),this.lightOrigin=null),this.lights=[],this.meshes=[],this.objectsToShow=[],this.autoHiddenObjects=[],this.objectsToShowSet=new Set,this.objectsToShowAncestors=new Set,this.shadowMapHistory.length=0,this._displaySuppressed=!1,this._displayDelayRemaining=0,this._displayRestoreOpacity=1,this.scene=null,this.renderer=null,this.fixedCamera=null,this.clearColor=null,this.previousShadowMap=null,this.averagingWindow=null,this.params=null}}function pn(a={},e,t,i=s=>{}){const s=class extends f.ShaderMaterial{constructor(r={}){const o=Object.entries(a);super({uniforms:o.reduce((c,[h,u])=>{const p=f.UniformsUtils.clone({[h]:{value:u}});return{...c,...p}},{}),vertexShader:e,fragmentShader:t}),o.forEach(([c])=>Object.defineProperty(this,c,{get:()=>this.uniforms[c].value,set:h=>this.uniforms[c].value=h})),Object.assign(this,r),i&&i(this)}};return s.key=f.MathUtils.generateUUID(),s}const Fc=pn({transparent:!0,color:new f.Color(0,0,0),alphaTest:0,opacity:1,map:null,depthWrite:!1,toneMapped:!1,blend:2},`varying vec2 vUv;
3762
3762
  void main() {
3763
3763
  gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.);
3764
3764
  vUv = uv;
@@ -3784,7 +3784,7 @@ vec3 texelOld = texture2D(previousShadowMap, vUv).rgb;
3784
3784
 
3785
3785
  #include <tonemapping_fragment>
3786
3786
  #include <colorspace_fragment>
3787
- }`),fc=Yr({},"void main() { }","void main() { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); discard; }");class dc extends ge.CSS2DObject{constructor(e){const t=document.createElement("div");super(t),this._controls=e}}class pc extends k.ShaderMaterial{get source(){return this.uniforms.source.value}set source(e){this.uniforms.source.value=e}constructor(){super({uniforms:{source:{value:null}},vertexShader:`
3787
+ }`),Bc=pn({},"void main() { }","void main() { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); discard; }");class Oc extends be.CSS2DObject{constructor(e){const t=document.createElement("div");super(t),this._controls=e}}class zc extends V.ShaderMaterial{get source(){return this.uniforms.source.value}set source(e){this.uniforms.source.value=e}constructor(){super({uniforms:{source:{value:null}},vertexShader:`
3788
3788
  void main() {
3789
3789
  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
3790
3790
  }
@@ -3806,7 +3806,7 @@ vec3 texelOld = texture2D(previousShadowMap, vUv).rgb;
3806
3806
  }
3807
3807
  gl_FragColor = vec4( 0.0 );
3808
3808
  }
3809
- `})}}class ur extends k.ShaderMaterial{get negative(){return this.uniforms.negative.value===-1}set negative(e){this.uniforms.negative.value=e?-1:1}constructor(){super({uniforms:{negative:{value:1}},vertexShader:`
3809
+ `})}}class Dr extends V.ShaderMaterial{get negative(){return this.uniforms.negative.value===-1}set negative(e){this.uniforms.negative.value=e?-1:1}constructor(){super({uniforms:{negative:{value:1}},vertexShader:`
3810
3810
  #include <morphtarget_pars_vertex>
3811
3811
  void main() {
3812
3812
  vec3 transformed = position;
@@ -3818,7 +3818,7 @@ vec3 texelOld = texture2D(previousShadowMap, vUv).rgb;
3818
3818
  void main() {
3819
3819
  gl_FragColor = vec4( gl_FragCoord.xy, 1e4 * float( negative ), 1 );
3820
3820
  }
3821
- `}),this.morphTargets=!0}}class mc extends k.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}get mask(){return this.uniforms.mask.value}set mask(e){this.uniforms.mask.value=e}get thickness(){return this.uniforms.thickness.value}set thickness(e){this.uniforms.thickness.value=e}get inside(){return this.uniforms.inside.value===-1}set inside(e){this.uniforms.inside.value=e?-1:1}get color(){return this.uniforms.color.value}constructor(){super({transparent:!0,uniforms:{map:{value:null},mask:{value:null},color:{value:new k.Color},thickness:{value:5},inside:{value:1}},vertexShader:`
3821
+ `}),this.morphTargets=!0}}class Vc extends V.ShaderMaterial{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}get mask(){return this.uniforms.mask.value}set mask(e){this.uniforms.mask.value=e}get thickness(){return this.uniforms.thickness.value}set thickness(e){this.uniforms.thickness.value=e}get inside(){return this.uniforms.inside.value===-1}set inside(e){this.uniforms.inside.value=e?-1:1}get color(){return this.uniforms.color.value}constructor(){super({transparent:!0,uniforms:{map:{value:null},mask:{value:null},color:{value:new V.Color},thickness:{value:5},inside:{value:1}},vertexShader:`
3822
3822
  varying vec2 vUv;
3823
3823
  void main() {
3824
3824
  vUv = uv;
@@ -3852,7 +3852,7 @@ vec3 texelOld = texture2D(previousShadowMap, vUv).rgb;
3852
3852
  }
3853
3853
  #include <colorspace_fragment>
3854
3854
  }
3855
- `})}}class gc extends k.ShaderMaterial{get source(){return this.uniforms.source.value}set source(e){this.uniforms.source.value=e}get mask(){return this.uniforms.mask.value}set mask(e){this.uniforms.mask.value=e}get step(){return this.uniforms.step.value}set step(e){this.uniforms.step.value=e}constructor(){super({uniforms:{source:{value:null},mask:{value:null},step:{value:0}},vertexShader:`
3855
+ `})}}class Wc extends V.ShaderMaterial{get source(){return this.uniforms.source.value}set source(e){this.uniforms.source.value=e}get mask(){return this.uniforms.mask.value}set mask(e){this.uniforms.mask.value=e}get step(){return this.uniforms.step.value}set step(e){this.uniforms.step.value=e}constructor(){super({uniforms:{source:{value:null},mask:{value:null},step:{value:0}},vertexShader:`
3856
3856
  varying vec2 vUv;
3857
3857
  void main() {
3858
3858
  vUv = uv;
@@ -3901,7 +3901,7 @@ vec3 texelOld = texture2D(previousShadowMap, vUv).rgb;
3901
3901
  `}).join("")}
3902
3902
  gl_FragColor = vec4( result, 1.0 );
3903
3903
  }
3904
- `})}}class vc{constructor(e,t,i,s){this.params={inside:!1,thickness:30,color:new k.Color("#e91e63")},this._selectionLayer=31,this._box=new k.Box3,this._sphere=new k.Sphere,this.renderer=e,this.scene=t,this.camera=i,(s==null?void 0:s.inside)!==void 0&&(this.params.inside=s.inside),(s==null?void 0:s.thickness)!==void 0&&(this.params.thickness=s.thickness),(s==null?void 0:s.color)!==void 0&&(this.params.color=new k.Color(s.color)),this.seedMaterial=new ur,this.seedMaterial.side=k.DoubleSide,this.seedModelMaterial=new ur,this.seedModelMaterial.side=k.DoubleSide,this.maskMaterial=new k.MeshBasicMaterial({color:16777215,side:k.DoubleSide}),this.maskMaterial.morphTargets=!0,this.targets=[new k.WebGLRenderTarget(1,1,{format:k.RGBAFormat,type:k.FloatType,minFilter:k.NearestFilter,magFilter:k.NearestFilter}),new k.WebGLRenderTarget(1,1,{format:k.RGBAFormat,type:k.FloatType,minFilter:k.NearestFilter,magFilter:k.NearestFilter})],this.masks=[new k.WebGLRenderTarget(1,1,{format:k.RedFormat,type:k.UnsignedByteType,minFilter:k.LinearFilter,magFilter:k.LinearFilter,wrapS:k.ClampToEdgeWrapping,wrapT:k.ClampToEdgeWrapping}),new k.WebGLRenderTarget(1,1,{format:k.RedFormat,type:k.UnsignedByteType,minFilter:k.LinearFilter,magFilter:k.LinearFilter,wrapS:k.ClampToEdgeWrapping,wrapT:k.ClampToEdgeWrapping})],this.effectQuad=new Ot.FullScreenQuad(new mc),this.jfaQuad=new Ot.FullScreenQuad(new gc),this.seedQuad=new Ot.FullScreenQuad(this.seedMaterial),this.expandQuad=new Ot.FullScreenQuad(new pc),this.setSize(window.innerWidth,window.innerHeight)}setSize(e,t){const i=this.renderer.getPixelRatio(),s=Math.floor(e*i),a=Math.floor(t*i);this.targets[0].setSize(s,a),this.targets[1].setSize(s,a)}render(e){const t=this.renderer,i=this.scene,s=this.camera,a=this.params;let n=!1;const c=s.layers.mask;if(e){const L=Array.isArray(e)?e:[e];L.length>0&&(n=!0,this._box.makeEmpty(),L.forEach(C=>{if(C)try{this._box.expandByObject(C),C.traverse(D=>{D.layers.enable(this._selectionLayer)})}catch(D){console.log("eee",D)}}),this._box.getBoundingSphere(this._sphere),s.layers.set(this._selectionLayer))}else this._box.setFromObject(i).getBoundingSphere(this._sphere);this.masks[0].setSize(this.targets[0].width,this.targets[0].height),this.masks[1].setSize(this.masks[0].width,this.masks[0].height),i.overrideMaterial=this.maskMaterial,t.setClearColor(0,0),t.setRenderTarget(this.masks[0]),t.clear(),t.render(i,s),i.overrideMaterial=null,t.setRenderTarget(null);for(let L=0;L<4;L++)this.expandQuad.material.source=this.masks[0].texture,t.setRenderTarget(this.masks[1]),this.expandQuad.render(t),t.setRenderTarget(null),this.masks.reverse();this.masks.reverse(),s.updateMatrixWorld();const h=this._sphere.center.clone();h.applyMatrix4(s.matrixWorldInverse);const f=h.z>-this._sphere.radius-s.near;h.x+=this._sphere.radius,h.y+=this._sphere.radius,h.applyMatrix4(s.projectionMatrix);const p=this._sphere.center.clone();p.project(s).multiplyScalar(.5),p.x+=.5,p.y+=.5,p.z=0,h.multiplyScalar(.5),h.x+=.5,h.y+=.5,h.z=0;let{width:r,height:l}=this.targets[0];r/=t.getPixelRatio(),l/=t.getPixelRatio();const u=a.thickness+20,g=Math.max(Math.abs(p.x-h.x)*r,Math.abs(p.y-h.y)*l)*1.5+u;p.x*=r,p.y*=l;const y=p.x-g,m=p.y-g,v=g*2,_=g*2;f||v>=r||_>=l?t.setScissorTest(!1):(t.setScissorTest(!0),t.setScissor(y,m,v,_)),t.setRenderTarget(this.targets[0]),this.seedQuad.material.depthWrite=!1,this.seedQuad.render(t),i.overrideMaterial=this.seedModelMaterial,this.seedModelMaterial.negative=!0,t.autoClear=!1,t.render(i,s),t.autoClear=!0,i.overrideMaterial=null,t.setRenderTarget(null);let x=Math.min(Math.max(this.targets[0].width,this.targets[0].height),a.thickness);for(;this.jfaQuad.material.step=x,this.jfaQuad.material.source=this.targets[0].texture,this.jfaQuad.material.mask=this.masks[1].texture,t.setRenderTarget(this.targets[1]),this.jfaQuad.render(t),t.setRenderTarget(null),this.targets.reverse(),!(x<=1);)x=Math.ceil(x*.5);const w=t.autoClear;t.autoClear=!1;const b=this.effectQuad.material;b.map=this.targets[0].texture;const T=this.targets[0].texture.minFilter,S=this.targets[0].texture.magFilter;this.targets[0].texture.minFilter=k.LinearFilter,this.targets[0].texture.magFilter=k.LinearFilter,this.targets[0].texture.needsUpdate=!0,b.mask=this.masks[1].texture,b.thickness=a.thickness,b.inside=a.inside,b.color.set(a.color),b.transparent=!0,b.blending=k.NormalBlending,b.depthTest=!1,b.depthWrite=!1,this.effectQuad.render(t),this.targets[0].texture.minFilter=T,this.targets[0].texture.magFilter=S,this.targets[0].texture.needsUpdate=!0,t.autoClear=w,t.setScissorTest(!1),n&&e&&((Array.isArray(e)?e:[e]).forEach(C=>{C&&C.traverse(D=>{D.layers.disable(this._selectionLayer)})}),s.layers.mask=c)}}class _c extends d.Mesh{constructor(e=200,t=20,i=.8){const s=new d.PlaneGeometry(e,e),a=new d.ShaderMaterial({side:d.DoubleSide,transparent:!0,depthWrite:!1,uniforms:{uColor:{value:new d.Color(13619165)},uSize:{value:1},uDistance:{value:e/2},uOpacity:{value:i}},vertexShader:`
3904
+ `})}}class Uc{constructor(e,t,i,s){this.params={inside:!1,thickness:30,color:new V.Color("#e91e63")},this._selectionLayer=31,this._box=new V.Box3,this._sphere=new V.Sphere,this.renderer=e,this.scene=t,this.camera=i,(s==null?void 0:s.inside)!==void 0&&(this.params.inside=s.inside),(s==null?void 0:s.thickness)!==void 0&&(this.params.thickness=s.thickness),(s==null?void 0:s.color)!==void 0&&(this.params.color=new V.Color(s.color)),this.seedMaterial=new Dr,this.seedMaterial.side=V.DoubleSide,this.seedModelMaterial=new Dr,this.seedModelMaterial.side=V.DoubleSide,this.maskMaterial=new V.MeshBasicMaterial({color:16777215,side:V.DoubleSide}),this.maskMaterial.morphTargets=!0,this.targets=[new V.WebGLRenderTarget(1,1,{format:V.RGBAFormat,type:V.FloatType,minFilter:V.NearestFilter,magFilter:V.NearestFilter}),new V.WebGLRenderTarget(1,1,{format:V.RGBAFormat,type:V.FloatType,minFilter:V.NearestFilter,magFilter:V.NearestFilter})],this.masks=[new V.WebGLRenderTarget(1,1,{format:V.RedFormat,type:V.UnsignedByteType,minFilter:V.LinearFilter,magFilter:V.LinearFilter,wrapS:V.ClampToEdgeWrapping,wrapT:V.ClampToEdgeWrapping}),new V.WebGLRenderTarget(1,1,{format:V.RedFormat,type:V.UnsignedByteType,minFilter:V.LinearFilter,magFilter:V.LinearFilter,wrapS:V.ClampToEdgeWrapping,wrapT:V.ClampToEdgeWrapping})],this.effectQuad=new jt.FullScreenQuad(new Vc),this.jfaQuad=new jt.FullScreenQuad(new Wc),this.seedQuad=new jt.FullScreenQuad(this.seedMaterial),this.expandQuad=new jt.FullScreenQuad(new zc),this.setSize(window.innerWidth,window.innerHeight)}setSize(e,t){const i=this.renderer.getPixelRatio(),s=Math.floor(e*i),r=Math.floor(t*i);this.targets[0].setSize(s,r),this.targets[1].setSize(s,r)}render(e){const t=this.renderer,i=this.scene,s=this.camera,r=this.params;let o=!1;const c=s.layers.mask;if(e){const L=Array.isArray(e)?e:[e];L.length>0&&(o=!0,this._box.makeEmpty(),L.forEach(C=>{if(C)try{this._box.expandByObject(C),C.traverse(I=>{I.layers.enable(this._selectionLayer)})}catch(I){console.log("eee",I)}}),this._box.getBoundingSphere(this._sphere),s.layers.set(this._selectionLayer))}else this._box.setFromObject(i).getBoundingSphere(this._sphere);this.masks[0].setSize(this.targets[0].width,this.targets[0].height),this.masks[1].setSize(this.masks[0].width,this.masks[0].height),i.overrideMaterial=this.maskMaterial,t.setClearColor(0,0),t.setRenderTarget(this.masks[0]),t.clear(),t.render(i,s),i.overrideMaterial=null,t.setRenderTarget(null);for(let L=0;L<4;L++)this.expandQuad.material.source=this.masks[0].texture,t.setRenderTarget(this.masks[1]),this.expandQuad.render(t),t.setRenderTarget(null),this.masks.reverse();this.masks.reverse(),s.updateMatrixWorld();const h=this._sphere.center.clone();h.applyMatrix4(s.matrixWorldInverse);const u=h.z>-this._sphere.radius-s.near;h.x+=this._sphere.radius,h.y+=this._sphere.radius,h.applyMatrix4(s.projectionMatrix);const p=this._sphere.center.clone();p.project(s).multiplyScalar(.5),p.x+=.5,p.y+=.5,p.z=0,h.multiplyScalar(.5),h.x+=.5,h.y+=.5,h.z=0;let{width:n,height:l}=this.targets[0];n/=t.getPixelRatio(),l/=t.getPixelRatio();const d=r.thickness+20,g=Math.max(Math.abs(p.x-h.x)*n,Math.abs(p.y-h.y)*l)*1.5+d;p.x*=n,p.y*=l;const v=p.x-g,m=p.y-g,_=g*2,y=g*2;u||_>=n||y>=l?t.setScissorTest(!1):(t.setScissorTest(!0),t.setScissor(v,m,_,y)),t.setRenderTarget(this.targets[0]),this.seedQuad.material.depthWrite=!1,this.seedQuad.render(t),i.overrideMaterial=this.seedModelMaterial,this.seedModelMaterial.negative=!0,t.autoClear=!1,t.render(i,s),t.autoClear=!0,i.overrideMaterial=null,t.setRenderTarget(null);let w=Math.min(Math.max(this.targets[0].width,this.targets[0].height),r.thickness);for(;this.jfaQuad.material.step=w,this.jfaQuad.material.source=this.targets[0].texture,this.jfaQuad.material.mask=this.masks[1].texture,t.setRenderTarget(this.targets[1]),this.jfaQuad.render(t),t.setRenderTarget(null),this.targets.reverse(),!(w<=1);)w=Math.ceil(w*.5);const x=t.autoClear;t.autoClear=!1;const b=this.effectQuad.material;b.map=this.targets[0].texture;const T=this.targets[0].texture.minFilter,M=this.targets[0].texture.magFilter;this.targets[0].texture.minFilter=V.LinearFilter,this.targets[0].texture.magFilter=V.LinearFilter,this.targets[0].texture.needsUpdate=!0,b.mask=this.masks[1].texture,b.thickness=r.thickness,b.inside=r.inside,b.color.set(r.color),b.transparent=!0,b.blending=V.NormalBlending,b.depthTest=!1,b.depthWrite=!1,this.effectQuad.render(t),this.targets[0].texture.minFilter=T,this.targets[0].texture.magFilter=M,this.targets[0].texture.needsUpdate=!0,t.autoClear=x,t.setScissorTest(!1),o&&e&&((Array.isArray(e)?e:[e]).forEach(C=>{C&&C.traverse(I=>{I.layers.disable(this._selectionLayer)})}),s.layers.mask=c)}}class Hc extends f.Mesh{constructor(e=200,t=20,i=.8){const s=new f.PlaneGeometry(e,e),r=new f.ShaderMaterial({side:f.DoubleSide,transparent:!0,depthWrite:!1,uniforms:{uColor:{value:new f.Color(13619165)},uSize:{value:1},uDistance:{value:e/2},uOpacity:{value:i}},vertexShader:`
3905
3905
  varying vec3 vPos;
3906
3906
  void main() {
3907
3907
  vPos = position;
@@ -3935,7 +3935,7 @@ vec3 texelOld = texture2D(previousShadowMap, vUv).rgb;
3935
3935
  // Combine
3936
3936
  gl_FragColor = vec4(uColor, alpha * fade * uOpacity);
3937
3937
  }
3938
- `});super(s,a),this.position.z=-.02}}const yc="https://cdn2.seer-group.com/libs/hdr/aristea_wreck_512.hdr",xc="https://cdn2.seer-group.com/libs/hdr/lightroom_14b_512.hdr",wc="https://cdn2.seer-group.com/libs/fonts.type.json",bc=new ln.Font(wc);class rs{constructor(e){var i;this._props=e,this.name="",this._defaults={color:"",metalness:0,roughness:0,envMapIntensity:1},this.color="",this.metalness=0,this.roughness=0,this.envMapIntensity=1,this.name=this._props.name;const t=this.material;t&&(this.color=this._defaults.color="#"+((i=t.color)==null?void 0:i.getHexString()),this.metalness=this._defaults.metalness=t.metalness??0,this.roughness=this._defaults.roughness=t.roughness??1,this.envMapIntensity=this._defaults.envMapIntensity=t.envMapIntensity??1)}get material(){if(this._props.target instanceof d.MeshStandardMaterial)return this._props.target;if(this._props.target instanceof d.Mesh){if(Array.isArray(this._props.target.material))return this._props.target.material.find(e=>e instanceof d.MeshStandardMaterial);if(this._props.target.material instanceof d.MeshStandardMaterial)return this._props.target.material}}change(e){var i;this.color=e;const t=this.material;(i=t==null?void 0:t.color)==null||i.set(e)}reset(){this.change(this._defaults.color);const e=this.material;e&&(e.metalness=this._defaults.metalness,e.roughness=this._defaults.roughness,e.envMapIntensity=this._defaults.envMapIntensity,e.needsUpdate=!0)}}var Kr=(o=>(o[o.DEFAULT=0]="DEFAULT",o[o.CAN_INSTALL=1]="CAN_INSTALL",o))(Kr||{});const fr=.15;d.Object3D.DEFAULT_UP.set(0,0,1);let nt,li=0,ns=0;const Ac=()=>{nt=void 0,li=0,ns=0},Tc=new d.MeshBasicMaterial({colorWrite:!1});class Sc{constructor(e){this.props=e,this.stats=new Dt,this.scene=new d.Scene,this.overlayScene=new d.Scene,this.renderer=new d.WebGLRenderer({antialias:!0,alpha:!0,logarithmicDepthBuffer:!0,powerPreference:"high-performance",preserveDrawingBuffer:!0}),this.css2dRenderer=new ge.CSS2DRenderer,this.mousePos=new d.Vector2,this.mouseCoord=new d.Vector2,this.offset=new d.Vector2,this.size=new d.Vector2,this.amr=new Wr({showSizeBox:!0,showController:!0}),this._selectedForOutline=[],this._clock=new d.Clock(!0),this._uiHiddenTime=this._clock.getElapsedTime(),this.camera=new d.PerspectiveCamera(39.6,window.innerWidth/window.innerHeight,.1,1e4),this.d=2,this.orthographicCamera=new d.OrthographicCamera(-this.d*(window.innerWidth/window.innerHeight),this.d*(window.innerWidth/window.innerHeight),this.d,-this.d,.1,1e3),this._axisMoving=!1,this._container=new d.Group,this._raycaster=new d.Raycaster,this._selected=[],this._pointerDownTimeout=0,this._dragging=!1,this.maxSample=1024*2,this.sampleCount=0,this._usePathTracing=!1,this._fpsCache=[],this._fpsCacheMax=20,this._emitter=new pt,this.sound=new ka,this._rafId=null,this._destroyed=!1,this._css2dUiStyleInjected=!1,this._ground=new d.Mesh(new d.PlaneGeometry(100,100),new d.MeshPhysicalMaterial({color:new d.Color("#eee"),metalness:.4,roughness:.1,clearcoat:1,clearcoatRoughness:.1})),this._sciFiGrid=new _c(18,40),this._amrRender=new d.WebGLRenderTarget(1024,1024,{format:d.RGBAFormat,type:d.UnsignedByteType,colorSpace:d.SRGBColorSpace,samples:8}),this._lastTarget=new d.Vector3,this._shadowMode=!1,this.addEventListener=this._emitter.on.bind(this._emitter),this.removeEventListener=this._emitter.on.bind(this._emitter),this._showSlots=!0,this._showSize=!0,this._showControls=!0,this._drag=c=>{this._dragging=!0,this._pointermove(c)},this._dragend=c=>{this._dragging=!1},this._pointermove=c=>{if(this._pointerDownTimeout)return clearTimeout(this._pointerDownTimeout),this._pointerDownTimeout=0;let{top:h,left:f}=this.renderer.domElement.getBoundingClientRect();this.offset.set(f,h),this.mousePos.set(c.clientX-f,c.clientY-h),this.mouseCoord.set((c.clientX-f)/this.size.x*2-1,-((c.clientY-h)/this.size.y)*2+1),this._raycaster.setFromCamera(this.mouseCoord,this.camera)},this._pointerdown=c=>{const h=()=>{this.amr.slots.forEach(r=>r.selected=!1);const p=this._raycaster.intersectObjects(this.amr.slots,!1)[0];p&&this.amr.slots.forEach(r=>{r.traverse(l=>{l==p.object||(r.deviceSelected=!1)})}),this._pointerDownTimeout=0};this._pointerDownTimeout=window.setTimeout(h,200)},this._detectTrackpad=()=>{nt||typeof nt<"u"||(li===0&&(ns=performance.now()),li++,performance.now()-ns>66&&(li>5?nt=!0:nt=!1,nt?this.controls.zoomSpeed=.2:this.controls.zoomSpeed=1,setTimeout(Ac,2e3)))},this.debounceForkHeightChange=Ha(()=>{var c;this._progressShadow.clear(),(c=this._progressShadow)==null||c.recalculate()},300),this.focusObjects=(c,h)=>{var j;if(!c.length){this.fit();return}this.scene.updateMatrixWorld(!0),this._focusRestoreView=void 0,(j=this._fitAnimation)==null||j.stop();const f=new d.Box3,p=new d.Box3,r=new d.Vector3,l=new d.Vector3,u=new d.Vector3,g=new d.Vector3,y=U=>{U.geometry&&(U.geometry.boundingBox||U.geometry.computeBoundingBox(),p.copy(U.geometry.boundingBox).applyMatrix4(U.matrixWorld),p.isEmpty()||f.union(p))},m=U=>{var _s,ys;const Q=U.geometry,re=(_s=Q==null?void 0:Q.attributes)==null?void 0:_s.position;if(!re){y(U);return}const te=((ys=Q.morphAttributes)==null?void 0:ys.position)||[],vs=U.morphTargetInfluences||[],Zr=te.length>0&&vs.length>0;for(let Te=0;Te<re.count;Te++){if(r.set(re.getX(Te),re.getY(Te),re.getZ(Te)),Zr){l.set(0,0,0);let gi=0;for(let Ge=0;Ge<te.length;Ge++){const kt=vs[Ge]||0;kt&&(gi+=kt,u.set(te[Ge].getX(Te),te[Ge].getY(Te),te[Ge].getZ(Te)),Q.morphTargetsRelative,l.addScaledVector(u,kt))}Q.morphTargetsRelative?r.add(l):gi>0&&(r.multiplyScalar(1-gi),r.add(l))}g.copy(r).applyMatrix4(U.matrixWorld),f.expandByPoint(g)}};if(c.forEach(U=>{U.traverse(Q=>{if(Q.visible){if(Q instanceof d.Mesh){m(Q);return}(Q.isPoint||Q.isLine)&&y(Q)}})}),f.isEmpty())return;const v=new d.Vector3;f.getCenter(v);const _=new d.Vector3;f.getSize(_);const x=v.clone();this._lastTarget.copy(x);let w;h?w=h.clone().normalize().negate():w=this.camera.position.clone().sub(this.controls.target).normalize();const b=_.clone().multiplyScalar(.5),T=[new d.Vector3(b.x,b.y,b.z),new d.Vector3(b.x,b.y,-b.z),new d.Vector3(b.x,-b.y,b.z),new d.Vector3(b.x,-b.y,-b.z),new d.Vector3(-b.x,b.y,b.z),new d.Vector3(-b.x,b.y,-b.z),new d.Vector3(-b.x,-b.y,b.z),new d.Vector3(-b.x,-b.y,-b.z)],S=new d.Vector3(0,1,0);Math.abs(w.dot(S))>.99&&S.set(0,0,1);const L=new d.Vector3().crossVectors(w,S).normalize(),C=new d.Vector3().crossVectors(L,w).normalize();let D=0;T.forEach(U=>{const Q=U.dot(L),re=U.dot(C),te=Math.sqrt(Q*Q+re*re);D=Math.max(D,te)}),D=D/2+.4;const R=this.camera.fov*Math.PI/180,A=2*Math.atan(Math.tan(R/2)*this.camera.aspect),M=D/Math.tan(A/2),I=D/Math.tan(R/2),P=Math.max(M,I),E=v.clone().add(w.multiplyScalar(P)),B=this.camera.position.clone(),V=this.controls.target.clone();let G=500;const H=B.distanceTo(E)+V.distanceTo(x);H>.001&&(G=Math.min(1e3,Math.max(450,H*45))),this._animateCamera(B,E,V,x,G)},this.focusSlots=c=>{var C,D;if(this.amr.slots.forEach(R=>{R.focused=!1,R.hide()}),!c.length)if(this._lastTarget.set(0,0,this._lastTarget.z),this.amr.slots.forEach(R=>{R.show()}),this.shadowMode=!1,this._focusRestoreView){const R=this._focusRestoreView;this._focusRestoreView=void 0;const A=this.camera.position.clone(),M=this.controls.target.clone(),I=R.position.clone(),P=R.target.clone();let E=500;const B=A.distanceTo(I)+M.distanceTo(P);B>.001&&(E=Math.min(1e3,Math.max(450,B*45))),this._animateCamera(A,I,M,P,E,()=>{this.camera.up.copy(R.up)});return}else{this.fit();return}(C=this._fitAnimation)!=null&&C.isPlaying()||this.shadowMode||(this._focusRestoreView={position:this.camera.position.clone(),target:new d.Vector3(0,0,this.controls.target.z),up:this.camera.up.clone()}),(D=this._fitAnimation)==null||D.stop(),this.shadowMode=!0;const h=c.flatMap(R=>{if(R.show(),R.focused=!0,!R.parent)return[];const A=new d.Vector3;return R.parent.getWorldPosition(A),[A]});if(!h.length)return;const f=h.reduce((R,A)=>R.add(A),new d.Vector3).multiplyScalar(1/h.length),p=this.controls.target.clone(),r=this.camera.position.clone().sub(p).normalize();let l=0;for(const R of h){const A=R.clone().sub(f),M=A.dot(r),I=Math.sqrt(Math.max(0,A.lengthSq()-M*M));I>l&&(l=I)}l=l+.4;const u=this.camera.fov*Math.PI/180,g=2*Math.atan(Math.tan(u/2)*this.camera.aspect),y=l/Math.tan(g/2),m=l/Math.tan(u/2),v=Math.max(y,m),_=f.clone(),x=f.clone().add(r.clone().multiplyScalar(v<1?1:v)),w=this.camera.position.clone(),b=p.clone(),T={t:0};let S=500;const L=w.distanceTo(x)+b.distanceTo(_);L>.001&&(S=Math.min(1e3,Math.max(450,L*45))),this._lastTarget=_.clone(),this._fitAnimation=new ci(T).to({t:1},S).easing(Pe.Easing.Quadratic.InOut).onStart(()=>{this.controls.enabled=!1}).onUpdate(()=>{const R=T.t;this.camera.position.lerpVectors(w,x,R),this.controls.target.lerpVectors(b,_,R)}).onComplete(()=>{this.controls.enabled=!0}).start()},this.fit=()=>{this._focusRestoreView=void 0,new d.Box3().setFromObject(this._container);const h=this.amr.sizeBox.size.getSize(new d.Vector3),f=h.clone().multiplyScalar(.5),p=new d.Vector3(0,0,f.z);this._lastTarget.copy(p);let r=f.clone().sub(p);r.lengthSq()<1e-6&&(r=new d.Vector3(1,0,0));const l=r.clone().normalize(),u=h.clone().multiplyScalar(.5),g=[new d.Vector3(u.x,u.y,u.z),new d.Vector3(u.x,u.y,-u.z),new d.Vector3(u.x,-u.y,u.z),new d.Vector3(u.x,-u.y,-u.z),new d.Vector3(-u.x,u.y,u.z),new d.Vector3(-u.x,u.y,-u.z),new d.Vector3(-u.x,-u.y,u.z),new d.Vector3(-u.x,-u.y,-u.z)];let y=0;for(const A of g){const M=A.dot(l),I=Math.sqrt(Math.max(0,A.lengthSq()-M*M));I>y&&(y=I)}y=y*1.05;const m=this.camera.fov*Math.PI/180,v=2*Math.atan(Math.tan(m/2)*this.camera.aspect),_=y/Math.tan(v/2),x=y/Math.tan(m/2),w=Math.max(_,x),b=f.clone();let T=h.z/3;h.z<h.x&&h.z<h.y&&(T=h.x*.8),h.z>h.x&&h.z>h.y&&(T=0),b.z+=T;const S=r.clone().normalize().multiplyScalar(w<1?1:w).add(b);Math.max(h.x*2,5);const L=this.camera.position.clone(),C=this.controls.target.clone();let D=600;const R=L.distanceTo(S)+C.distanceTo(p);R>.001&&(D=Math.min(800,Math.max(650,R*45))),this._animateCamera(L,S,C,p,D,()=>{this.shadowMode||(this._progressShadow.visible=!0,this._progressShadow.isFinished||this._progressShadow.recalculate())}),this.controls.minDistance=Math.max(.2,Math.min(w*.25,w-.1)),this.controls.maxDistance=w*4},this.resize=()=>{var p,r;const c=this.renderer.domElement.parentElement;if(!c)return;c.style.display="flex",this.renderer.domElement.style.width="100%",this.renderer.domElement.style.height="100%",this.renderer.domElement.style.flexGrow="1";const h=c.clientWidth,f=c.clientHeight;this.size.set(h,f),this.camera.aspect=h/f,this.camera.updateProjectionMatrix(),this._amrRender.setSize(h,f),this._updateCamera(),this.css2dRenderer.setSize(h,f),this.renderer.getPixelRatio(),(p=this.pathTracer)==null||p.updateCamera(),this.sampleCount=0,this.renderer.setSize(h,f),(r=this._jumpFlood)==null||r.setSize(h,f)},this.ticker=c=>{if(!this._destroyed){if(this.stats.begin(),this.renderer.domElement.dispatchEvent(new CustomEvent("ticker",{detail:c})),this._rafId=requestAnimationFrame(this.ticker),this.renderer.clear(),this.usePathTracing){this.hideAmrUI(),this.sampleCount<this.maxSample?this.sampleCount++:this.pathTracer.pausePathTracing=!0,this.pathTracer.renderSample();const h=this.renderer.autoClear;this.renderer.autoClear=!1,this.scene.overrideMaterial=Tc,this.renderer.clearDepth(),this.renderer.render(this.scene,this.mainCamera),this.scene.overrideMaterial=null,this.renderer.render(this.overlayScene,this.mainCamera),this.renderer.autoClear=h}else{this._clock.getElapsedTime()-this._uiHiddenTime>.15?this.showControls&&this.amr.controllers.forEach(p=>p.show()):this.amr.controllers.forEach(p=>p.hide());const f=this.stats.fps();if(this.usePathTracing||(this._fpsCache.length>this._fpsCacheMax&&this._fpsCache.shift(),this._fpsCache.push(f)),this.amr.slots.forEach(p=>{this._dragging?p.getCanInstall()&&p.render(this):p.render(this)}),Pe.update(),this.controls.update(),this._progressShadow.update(this.mainCamera),this.css2dRenderer.render(this.scene,this.mainCamera),this.updatePosition(),this.scene.overrideMaterial=null,this.renderer.render(this.scene,this.mainCamera),this._jumpFlood&&this._selectedForOutline.length>0){const p=this.scene.background;this.scene.background=null,this._jumpFlood.render(this._selectedForOutline),this.scene.background=p}}this.stats.end()}},this.stats.showPanel(0),this.hideState(),e.fov&&(this.camera.fov=e.fov,this.camera.updateProjectionMatrix()),Pr(We,this.renderer),this._ground.visible=!1,this.controls=new an.OrbitControls(this.camera,this.renderer.domElement),this.controls.enablePan=!0,this.controls.rotateSpeed=this.props.isMobile?.6:.5,this.controls.dampingFactor=fr,this.controls.enableDamping=!0,this.controls.maxDistance=10,this.controls.minDistance=1,this.controls.zoomSpeed=this.props.isMobile?.3:kr()?.2:1,this._cameraPositionUI=new dc(this.controls),this.renderer.setPixelRatio(window.devicePixelRatio||1),this.renderer.autoClear=!0,this.renderer.toneMapping=d.ACESFilmicToneMapping,this.renderer.toneMappingExposure=1.4,this.renderer.outputColorSpace=d.SRGBColorSpace,this.renderer.localClippingEnabled=!0,this.renderer.shadowMap.enabled=!0,this.css2dRenderer.domElement.style.pointerEvents="none",this.css2dRenderer.domElement.style.position="absolute",this.css2dRenderer.domElement.style.top="0px",this.css2dRenderer.domElement.setAttribute("data-css2d-root","1"),this._ensureCss2dUiStyle(),this.camera.position.set(10,-10,5),this.camera.lookAt(new d.Vector3);const{tiles:t}=Ua();this.pathTracer=new ea(this.renderer),this.pathTracer.multipleImportanceSampling=!0,this.pathTracer.filterGlossyFactor=.6;let i=window.devicePixelRatio;i<2&&(i=2),this.pathTracer.renderScale=this.props.isMobile?1:i,this.pathTracer.bounces=this.props.isMobile?8:10,this.pathTracer.transmissiveBounces=this.props.isMobile?1:3,this.pathTracer.tiles.set(t,t),this.pathTracer.minSamples=10,this.pathTracer.dynamicLowRes=!0,this.pathTracer.lowResScale=.5,this.pathTracer.fadeDuration=0;const s=new lc(e.workerUrl),a=typeof navigator<"u"?navigator.hardwareConcurrency:4;s.maxWorkerCount=a,this.pathTracer.setBVHWorker(s),this.orthographicCamera.left=-20,this.orthographicCamera.right=20,this.orthographicCamera.top=-20,this.orthographicCamera.bottom=20,this._lastTarget=this.controls.target.clone();const n=()=>{let c=this._lastTarget.x,h=this._lastTarget.y;this.controls.target.x=c,this.controls.target.y=h};this.controls.addEventListener("change",()=>{var c;this.sampleCount=0,n(),this._uiHiddenTime=this._clock.getElapsedTime(),this.orthographicCamera.position.copy(this.camera.position),this.orthographicCamera.lookAt(this.controls.target),this.usePathTracing&&(this.pathTracer.pausePathTracing=!1,(c=this.pathTracer)==null||c.updateCamera()),this._updateCamera(),!(Math.abs(this.camera.position.x)<.001||Math.abs(this.camera.position.y)<.001)&&(this._axisMoving||(this.mainCamera=this.camera,this.usePathTracing&&this.generateBVH().then()))}),this._mainCamera=this.camera,this._progressShadow=new hc(this.renderer,this.scene,{size:8,lightCount:6,frames:e.isMobile?20:60,lightRadius:2,ambientWeight:.75}),this._progressShadow.lightOrigin.position.set(3,2.5,.6),this._progressShadow.visible=!1,this._container.add(this.amr),this.scene.add(this._container),this.ticker(0),this._loadEnv(),this._initEvents(),this.scene.add(this._cameraPositionUI),this._ground.rotateX(-Math.PI/2),this.scene.add(this._ground),this._jumpFlood=new vc(this.renderer,this.scene,this.camera,{thickness:4,color:"#fff"}),(typeof e.useAxisBall!="boolean"||e.useAxisBall)&&(this._controlsGizmo=new cc(this.controls,{size:160,padding:12,offset:e.axisBallOffset||new d.Vector2(10,10),fontSize:17,bubbleSizePrimary:18,bubbleSizeSecondary:14}),this._controlsGizmo.addListener("axis-select-start",()=>{this._axisMoving=!0,this.mainCamera=this.orthographicCamera,this.usePathTracing&&this.generateBVH().then()}),this._controlsGizmo.addListener("axis-select-end",()=>{this._axisMoving=!1}))}get usePathTracing(){return this._usePathTracing}_clearAmrContent(){const e=this.renderer.getRenderTarget();this.renderer.setRenderTarget(this._amrRender),this.renderer.setClearColor(0,0),this.renderer.clear(!0,!0,!0),this.renderer.setRenderTarget(e)}get shadowMode(){return this._shadowMode}set shadowMode(e){e?(this._progressShadow.visible=!1,this.amr.bodyOpacity=.2):(this._progressShadow.visible=!0,this.amr.bodyOpacity=1,this._progressShadow.isFinished||this._progressShadow.recalculate().then()),this._shadowMode=e}set usePathTracing(e){this._clearAmrContent(),e?(this.scene.background=new d.Color("transparent"),this.renderer.toneMappingExposure=1.8,this.overlayScene.add(this._progressShadow.shadowCatcherMesh),this.amr&&(this.amr.bodyOpacity=1),this.hideAmrUI(),this.pathTracer.renderToCanvas=!0,this.scene.background=null,this._ptEnvMap?(this.scene.environment=this._ptEnvMap,this.pathTracer.updateEnvironment()):new ws.HDRLoader().load(xc,t=>{t.mapping=d.EquirectangularReflectionMapping,this._ptEnvMap=t,this.usePathTracing&&(this.scene.environment=t,this.pathTracer.updateEnvironment())})):(this.renderer.toneMappingExposure=1.4,this.scene.add(this._progressShadow.shadowCatcherMesh),this.pathTracer.renderToCanvas=!1,this.amr.logos.forEach(t=>{var i;(i=t.parent)==null||i.add(t.target)}),this.showAmrUI(),this.amr&&this.amr.opacityCache!==void 0?(this.amr.bodyOpacity=this.amr.opacityCache,this.amr.opacityCache=void 0):this.amr&&(this.amr.bodyOpacity=1),this.pathTracer.reset(),this._ground.visible=!1,this._envMap&&(this.scene.background=this._envMap,this.scene.environment=this._envMap)),this._usePathTracing=e,this.controls.dampingFactor=e?1:fr,this.sampleCount=0}get fpsAverage(){return Br(this._fpsCache)}get mainCamera(){return this._mainCamera}set mainCamera(e){this._mainCamera=e,e instanceof d.OrthographicCamera?this.scene.background=null:this.scene.background=this.scene.environment}showState(){this.stats.dom.style.display="block"}hideState(){this.stats.dom.style.display="none"}hideAmrUI(e=!0,t=!0){this.shadowMode||this.amr.slots.forEach(i=>i.hide()),this.amr.sizeBox.hide(e),this.amr.controllers.forEach(i=>i.hide()),t&&this.amr.goods.forEach(i=>i.hide())}showAmrUI(e=!0){this.showSlots&&this.amr.slots.forEach(t=>t.show()),this.showSize&&this.amr.sizeBox.show(e),this.showControls&&this.amr.controllers.forEach(t=>t.show()),this.amr.goods.forEach(t=>t.show())}get showSlots(){return this._showSlots}set showSlots(e){this._showSlots=e,this.amr.slots.forEach(t=>e?t.show():t.hide())}get showSize(){return this._showSize}set showSize(e){this._showSize=e,e?this.amr.sizeBox.show(!0):this.amr.sizeBox.hide(!0)}get showControls(){return this._showControls}set showControls(e){this._showControls=e,this.amr.controllers.forEach(t=>e?t.show():t.hide())}_updateCamera(){const e=this.mainCamera.position.distanceTo(this.controls.target),t=2*Math.tan(this.camera.fov*.5*Math.PI/180)*e,i=this.size.x/this.size.y;this.orthographicCamera.left=-t*i/2,this.orthographicCamera.right=t*i/2,this.orthographicCamera.top=t/2,this.orthographicCamera.bottom=-t/2,this.orthographicCamera.updateProjectionMatrix()}_loadEnv(){new ws.HDRLoader().load(yc,t=>{t.mapping=d.EquirectangularReflectionMapping,this._envMap=t,this._usePathTracing||(this.scene.background=t,this.scene.backgroundBlurriness=1,this.scene.backgroundIntensity=1,this.scene.backgroundRotation=new d.Euler(Math.PI/2,0,Math.PI*.98*.8),this.scene.environment=t,this.overlayScene.environment=t,this.scene.environmentRotation=this.scene.backgroundRotation,this.overlayScene.environmentRotation=this.scene.environmentRotation,this.scene.environmentIntensity=1.4,this.overlayScene.environmentIntensity=this.scene.environmentIntensity),this.pathTracer.updateEnvironment()},()=>{},()=>{})}_initEvents(){window.addEventListener("drag",this._drag),window.addEventListener("dragend",this._dragend),document.addEventListener("wheel",this._detectTrackpad),window.addEventListener("pointermove",this._pointermove),this.renderer.domElement.addEventListener("pointerdown",this._pointerdown);const e=this.scene.children.find(t=>t.type==="Mesh");e&&this.select(e)}switchCamera(){this.mainCamera=this.mainCamera===this.camera?this.orthographicCamera:this.camera}toCameraTop(){const e=this.camera.position.distanceTo(this.controls.target);this.camera.position.copy(new d.Vector3(0,e+this.controls.target.y,0))}toCameraRight(){const e=this.camera.position.distanceTo(this.controls.target);this.camera.position.copy(new d.Vector3(0,this.controls.target.y,e))}toCameraFace(){const e=this.camera.position.distanceTo(this.controls.target);this.camera.position.copy(new d.Vector3(e,this.controls.target.y,0))}async generateBVH(){this.pathTracer.pausePathTracing=!1,this.amr.slots.forEach(e=>e.hide()),this.amr&&(this.amr.opacityCache=this.amr.bodyOpacity,this.amr.bodyOpacity=1,this.overlayScene.clear(),this.amr.logos.forEach(e=>{const t=new d.Group;e.target.updateMatrixWorld(!0),t.applyMatrix4(e.target.matrixWorld),t.add(e.target),this.overlayScene.add(t)})),this.usePathTracing=!0,this.pathTracer.setScene(this.scene,this.mainCamera)}async download(e=!1){if(e&&!this.usePathTracing){const t=this._amrRender.width,i=this._amrRender.height,s=new Uint8Array(t*i*4);this.renderer.setRenderTarget(this._amrRender),this.renderer.readRenderTargetPixels(this._amrRender,0,0,t,i,s),this.renderer.setRenderTarget(null);const a=document.createElement("canvas");a.width=t,a.height=i;const n=a.getContext("2d"),c=new ImageData(t,i);for(let h=0;h<i;h++)for(let f=0;f<t;f++){const p=((i-h-1)*t+f)*4,r=(h*t+f)*4;c.data[r]=s[p],c.data[r+1]=s[p+1],c.data[r+2]=s[p+2],c.data[r+3]=s[p+3]}return n.putImageData(c,0,0),a.toDataURL("image/png")}else return new Promise((t,i)=>{this._uiHiddenTime=this._clock.getElapsedTime(),this.hideAmrUI();const s=this.scene.background;this.scene.background=null,setTimeout(()=>{const a=this.renderer.domElement.toDataURL("image/png");return this.scene.background=s,t(a)},this.fpsAverage)})}async captureTriViews(e){var n;const t=(e==null?void 0:e.subject)??this._container;(n=this._progressShadow)==null||n.visible;const i=this.scene.background,s=this.showSize;return new Xr({renderer:this.renderer,scene:this.scene,overlayScene:this.overlayScene,subject:t,onBeforeCapture:()=>{this.scene.background=null,this.hideAmrUI(),this.showSize=!1,this.usePathTracing&&(this.usePathTracing=!1),this._progressShadow.visible=!1},onAfterCapture:()=>{this.scene.background=i,this.showAmrUI(),this.showSize=s,this._progressShadow.visible=!0}}).capture(e)}clearAMR(){be(this.overlayScene),this.amr.clean(),this.usePathTracing=!1}async exportAMR(){const e=this._container.clone(!0);return e.traverse(t=>{t.dispose&&(t.dispose(),t.removeFromParent())}),await zr.parseAsync(e,{onlyVisible:!0,binary:!0})}async addAMR(e,t=""){this.amr.init(this),await this.amr.load(e,t),this.amr.addEventListener("fork-height-change",this.debounceForkHeightChange),this.amr.addEventListener("shape-key-changed",(i,s)=>{this.pathTracer.reset(),this.sampleCount=0,this.pathTracer.setScene(this.scene,this.camera),this.overlayScene.traverse(a=>{if(!Object.keys(a.morphTargetDictionary||{}).includes(i))return;let n=s;a.userData[`origin_${i}`]&&(n-=a.userData[`origin_${i}`]);const c=a.morphTargetDictionary[i];a.morphTargetInfluences&&(a.morphTargetInfluences[c]=n),a instanceof d.Mesh&&a.geometry.translate(0,0,1e-5)}),["width","length","liftLength","liftWidth","liftOuterWidth"].includes(i)&&(this._progressShadow.clear(),this.debounceForkHeightChange())})}_animateCamera(e,t,i,s,a,n){var h;const c={t:0};(h=this._fitAnimation)==null||h.stop(),this._fitAnimation=new ci(c).to({t:1},a).easing(Pe.Easing.Quadratic.InOut).onStart(()=>{this.controls.enabled=!1}).onUpdate(()=>{const f=c.t;this.controls.target.lerpVectors(i,s,f);const p=s.clone(),r=e.clone().sub(p),l=t.clone().sub(p),u=r.length(),g=l.length(),y=u+(g-u)*f;let m;if(u>.001&&g>.001){const v=r.clone().normalize(),_=l.clone().normalize(),x=v.angleTo(_);if(x>.001){const w=new d.Vector3().crossVectors(v,_);if(w.lengthSq()>.001){w.normalize();const b=new d.Quaternion().setFromAxisAngle(w,x*f),T=v.clone().applyQuaternion(b);m=p.clone().add(T.multiplyScalar(y))}else m=p.clone().add(v.multiplyScalar(y))}else m=p.clone().add(v.multiplyScalar(y))}else m=e.clone().lerp(t,f);this.camera.position.copy(m),this.camera.lookAt(this.controls.target)}).onComplete(()=>{this.controls.enabled=!0,n==null||n()}).start()}select(e,t=4){if(this._jumpFlood&&(this._jumpFlood.params.thickness=t),!e){this._selectedForOutline=[];return}typeof e=="string"||(Array.isArray(e)?this._selectedForOutline=[...e]:this._selectedForOutline=[e])}appendTo(e){e.append(this.renderer.domElement),e.append(this.stats.dom),e.append(this.css2dRenderer.domElement),this.props.isMobile?(e.classList.add("is-mobile"),e.style.cssText=`
3938
+ `});super(s,r),this.position.z=-.02}}const Gc="https://cdn2.seer-group.com/libs/hdr/aristea_wreck_512.hdr",Nc="https://cdn2.seer-group.com/libs/hdr/lightroom_14b_512.hdr",Qc="https://cdn2.seer-group.com/libs/fonts.type.json",jc=new Mn.Font(Qc);class ys{constructor(e){var i;this._props=e,this.name="",this._defaults={color:"",metalness:0,roughness:0,envMapIntensity:1},this.color="",this.metalness=0,this.roughness=0,this.envMapIntensity=1,this.name=this._props.name;const t=this.material;t&&(this.color=this._defaults.color="#"+((i=t.color)==null?void 0:i.getHexString()),this.metalness=this._defaults.metalness=t.metalness??0,this.roughness=this._defaults.roughness=t.roughness??1,this.envMapIntensity=this._defaults.envMapIntensity=t.envMapIntensity??1)}get material(){if(this._props.target instanceof f.MeshStandardMaterial)return this._props.target;if(this._props.target instanceof f.Mesh){if(Array.isArray(this._props.target.material))return this._props.target.material.find(e=>e instanceof f.MeshStandardMaterial);if(this._props.target.material instanceof f.MeshStandardMaterial)return this._props.target.material}}change(e){var i;this.color=e;const t=this.material;(i=t==null?void 0:t.color)==null||i.set(e)}reset(){this.change(this._defaults.color);const e=this.material;e&&(e.metalness=this._defaults.metalness,e.roughness=this._defaults.roughness,e.envMapIntensity=this._defaults.envMapIntensity,e.needsUpdate=!0)}}var mn=(a=>(a[a.DEFAULT=0]="DEFAULT",a[a.CAN_INSTALL=1]="CAN_INSTALL",a))(mn||{});const Lr=.15;f.Object3D.DEFAULT_UP.set(0,0,1);let ut,xi=0,xs=0;const qc=()=>{ut=void 0,xi=0,xs=0},Yc=new f.MeshBasicMaterial({colorWrite:!1});class Zc{constructor(e){this.props=e,this.stats=new zt,this.scene=new f.Scene,this.overlayScene=new f.Scene,this.renderer=new f.WebGLRenderer({antialias:!0,alpha:!0,logarithmicDepthBuffer:!0,powerPreference:"high-performance",preserveDrawingBuffer:!0}),this.css2dRenderer=new be.CSS2DRenderer,this.mousePos=new f.Vector2,this.mouseCoord=new f.Vector2,this.offset=new f.Vector2,this.size=new f.Vector2,this.amr=new an({showSizeBox:!0,showController:!0}),this._selectedForOutline=[],this._clock=new f.Clock(!0),this._uiHiddenTime=this._clock.getElapsedTime(),this.camera=new f.PerspectiveCamera(39.6,window.innerWidth/window.innerHeight,.1,1e4),this.d=2,this.orthographicCamera=new f.OrthographicCamera(-this.d*(window.innerWidth/window.innerHeight),this.d*(window.innerWidth/window.innerHeight),this.d,-this.d,.1,1e3),this._axisMoving=!1,this._container=new f.Group,this._raycaster=new f.Raycaster,this._selected=[],this._pointerDownTimeout=0,this._dragging=!1,this.maxSample=1024*2,this.sampleCount=0,this._usePathTracing=!1,this._fpsCache=[],this._fpsCacheMax=20,this._emitter=new Ye,this.sound=new Ja,this._rafId=null,this._destroyed=!1,this._css2dUiStyleInjected=!1,this._ground=new f.Mesh(new f.PlaneGeometry(100,100),new f.MeshPhysicalMaterial({color:new f.Color("#eee"),metalness:.4,roughness:.1,clearcoat:1,clearcoatRoughness:.1})),this._sciFiGrid=new Hc(18,40),this._amrRender=new f.WebGLRenderTarget(1024,1024,{format:f.RGBAFormat,type:f.UnsignedByteType,colorSpace:f.SRGBColorSpace,samples:8}),this._lastTarget=new f.Vector3,this._shadowMode=!1,this.addEventListener=this._emitter.on.bind(this._emitter),this.removeEventListener=this._emitter.on.bind(this._emitter),this._showSlots=!0,this._showSize=!0,this._showControls=!0,this._drag=c=>{this._dragging=!0,this._pointermove(c)},this._dragend=c=>{this._dragging=!1},this._pointermove=c=>{if(this._pointerDownTimeout)return clearTimeout(this._pointerDownTimeout),this._pointerDownTimeout=0;let{top:h,left:u}=this.renderer.domElement.getBoundingClientRect();this.offset.set(u,h),this.mousePos.set(c.clientX-u,c.clientY-h),this.mouseCoord.set((c.clientX-u)/this.size.x*2-1,-((c.clientY-h)/this.size.y)*2+1),this._raycaster.setFromCamera(this.mouseCoord,this.camera)},this._pointerdown=c=>{const h=()=>{this.amr.slots.forEach(n=>n.selected=!1);const p=this._raycaster.intersectObjects(this.amr.slots,!1)[0];p&&this.amr.slots.forEach(n=>{n.traverse(l=>{l==p.object||(n.deviceSelected=!1)})}),this._pointerDownTimeout=0};this._pointerDownTimeout=window.setTimeout(h,200)},this._detectTrackpad=()=>{ut||typeof ut<"u"||(xi===0&&(xs=performance.now()),xi++,performance.now()-xs>66&&(xi>5?ut=!0:ut=!1,ut?this.controls.zoomSpeed=.2:this.controls.zoomSpeed=1,setTimeout(qc,2e3)))},this.debounceForkHeightChange=rl(()=>{var c;this._progressShadow.clear(),(c=this._progressShadow)==null||c.recalculate()},300),this.focusObjects=(c,h)=>{var W;if(!c.length){this.fit();return}this.scene.updateMatrixWorld(!0),this._focusRestoreView=void 0,(W=this._fitAnimation)==null||W.stop();const u=new f.Box3,p=new f.Box3,n=new f.Vector3,l=new f.Vector3,d=new f.Vector3,g=new f.Vector3,v=O=>{O.geometry&&(O.geometry.boundingBox||O.geometry.computeBoundingBox(),p.copy(O.geometry.boundingBox).applyMatrix4(O.matrixWorld),p.isEmpty()||u.union(p))},m=O=>{var Gt,Nt;const j=O.geometry,U=(Gt=j==null?void 0:j.attributes)==null?void 0:Gt.position;if(!U){v(O);return}const ie=((Nt=j.morphAttributes)==null?void 0:Nt.position)||[],Ze=O.morphTargetInfluences||[],_e=ie.length>0&&Ze.length>0;for(let ve=0;ve<U.count;ve++){if(n.set(U.getX(ve),U.getY(ve),U.getZ(ve)),_e){l.set(0,0,0);let Qt=0;for(let X=0;X<ie.length;X++){const ee=Ze[X]||0;ee&&(Qt+=ee,d.set(ie[X].getX(ve),ie[X].getY(ve),ie[X].getZ(ve)),j.morphTargetsRelative,l.addScaledVector(d,ee))}j.morphTargetsRelative?n.add(l):Qt>0&&(n.multiplyScalar(1-Qt),n.add(l))}g.copy(n).applyMatrix4(O.matrixWorld),u.expandByPoint(g)}};if(c.forEach(O=>{O.traverse(j=>{if(j.visible){if(j instanceof f.Mesh){m(j);return}(j.isPoint||j.isLine)&&v(j)}})}),u.isEmpty())return;const _=new f.Vector3;u.getCenter(_);const y=new f.Vector3;u.getSize(y);const w=_.clone();this._lastTarget.copy(w);let x;h?x=h.clone().normalize().negate():x=this.camera.position.clone().sub(this.controls.target).normalize();const b=y.clone().multiplyScalar(.5),T=[new f.Vector3(b.x,b.y,b.z),new f.Vector3(b.x,b.y,-b.z),new f.Vector3(b.x,-b.y,b.z),new f.Vector3(b.x,-b.y,-b.z),new f.Vector3(-b.x,b.y,b.z),new f.Vector3(-b.x,b.y,-b.z),new f.Vector3(-b.x,-b.y,b.z),new f.Vector3(-b.x,-b.y,-b.z)],M=new f.Vector3(0,1,0);Math.abs(x.dot(M))>.99&&M.set(0,0,1);const L=new f.Vector3().crossVectors(x,M).normalize(),C=new f.Vector3().crossVectors(L,x).normalize();let I=0;T.forEach(O=>{const j=O.dot(L),U=O.dot(C),ie=Math.sqrt(j*j+U*U);I=Math.max(I,ie)}),I=I/2+.4;const D=this.camera.fov*Math.PI/180,A=2*Math.atan(Math.tan(D/2)*this.camera.aspect),S=I/Math.tan(A/2),P=I/Math.tan(D/2),R=Math.max(S,P),k=_.clone().add(x.multiplyScalar(R)),F=this.camera.position.clone(),z=this.controls.target.clone();let B=500;const N=F.distanceTo(k)+z.distanceTo(w);N>.001&&(B=Math.min(1e3,Math.max(450,N*45))),this._animateCamera(F,k,z,w,B)},this.focusSlots=c=>{var C,I;if(this.amr.slots.forEach(D=>{D.focused=!1,D.hide()}),!c.length)if(this._lastTarget.set(0,0,this._lastTarget.z),this.amr.slots.forEach(D=>{D.show()}),this.shadowMode=!1,this._focusRestoreView){const D=this._focusRestoreView;this._focusRestoreView=void 0;const A=this.camera.position.clone(),S=this.controls.target.clone(),P=D.position.clone(),R=D.target.clone();let k=500;const F=A.distanceTo(P)+S.distanceTo(R);F>.001&&(k=Math.min(1e3,Math.max(450,F*45))),this._animateCamera(A,P,S,R,k,()=>{this.camera.up.copy(D.up)});return}else{this.fit();return}(C=this._fitAnimation)!=null&&C.isPlaying()||this.shadowMode||(this._focusRestoreView={position:this.camera.position.clone(),target:new f.Vector3(0,0,this.controls.target.z),up:this.camera.up.clone()}),(I=this._fitAnimation)==null||I.stop(),this.shadowMode=!0;const h=c.flatMap(D=>{if(D.show(),D.focused=!0,!D.parent)return[];const A=new f.Vector3;return D.parent.getWorldPosition(A),[A]});if(!h.length)return;const u=h.reduce((D,A)=>D.add(A),new f.Vector3).multiplyScalar(1/h.length),p=this.controls.target.clone(),n=this.camera.position.clone().sub(p).normalize();let l=0;for(const D of h){const A=D.clone().sub(u),S=A.dot(n),P=Math.sqrt(Math.max(0,A.lengthSq()-S*S));P>l&&(l=P)}l=l+.4;const d=this.camera.fov*Math.PI/180,g=2*Math.atan(Math.tan(d/2)*this.camera.aspect),v=l/Math.tan(g/2),m=l/Math.tan(d/2),_=Math.max(v,m),y=u.clone(),w=u.clone().add(n.clone().multiplyScalar(_<1?1:_)),x=this.camera.position.clone(),b=p.clone(),T={t:0};let M=500;const L=x.distanceTo(w)+b.distanceTo(y);L>.001&&(M=Math.min(1e3,Math.max(450,L*45))),this._lastTarget=y.clone(),this._fitAnimation=new wi(T).to({t:1},M).easing(ne.Easing.Quadratic.InOut).onStart(()=>{this.controls.enabled=!1}).onUpdate(()=>{const D=T.t;this.camera.position.lerpVectors(x,w,D),this.controls.target.lerpVectors(b,y,D)}).onComplete(()=>{this.controls.enabled=!0}).start()},this.fit=()=>{this._focusRestoreView=void 0,new f.Box3().setFromObject(this._container);const h=this.amr.sizeBox.size.getSize(new f.Vector3),u=h.clone().multiplyScalar(.5),p=new f.Vector3(0,0,u.z);this._lastTarget.copy(p);let n=u.clone().sub(p);n.lengthSq()<1e-6&&(n=new f.Vector3(1,0,0));const l=n.clone().normalize(),d=h.clone().multiplyScalar(.5),g=[new f.Vector3(d.x,d.y,d.z),new f.Vector3(d.x,d.y,-d.z),new f.Vector3(d.x,-d.y,d.z),new f.Vector3(d.x,-d.y,-d.z),new f.Vector3(-d.x,d.y,d.z),new f.Vector3(-d.x,d.y,-d.z),new f.Vector3(-d.x,-d.y,d.z),new f.Vector3(-d.x,-d.y,-d.z)];let v=0;for(const A of g){const S=A.dot(l),P=Math.sqrt(Math.max(0,A.lengthSq()-S*S));P>v&&(v=P)}v=v*1.05;const m=this.camera.fov*Math.PI/180,_=2*Math.atan(Math.tan(m/2)*this.camera.aspect),y=v/Math.tan(_/2),w=v/Math.tan(m/2),x=Math.max(y,w),b=u.clone();let T=h.z/3;h.z<h.x&&h.z<h.y&&(T=h.x*.8),h.z>h.x&&h.z>h.y&&(T=0),b.z+=T;const M=n.clone().normalize().multiplyScalar(x<1?1:x).add(b);Math.max(h.x*2,5);const L=this.camera.position.clone(),C=this.controls.target.clone();let I=600;const D=L.distanceTo(M)+C.distanceTo(p);D>.001&&(I=Math.min(800,Math.max(650,D*45))),this._animateCamera(L,M,C,p,I,()=>{this.shadowMode||(this._progressShadow.visible=!0,this._progressShadow.isFinished||this._progressShadow.recalculate())}),this.controls.minDistance=Math.max(.2,Math.min(x*.25,x-.1)),this.controls.maxDistance=x*4},this.resize=()=>{var p,n;const c=this.renderer.domElement.parentElement;if(!c)return;c.style.display="flex",this.renderer.domElement.style.width="100%",this.renderer.domElement.style.height="100%",this.renderer.domElement.style.flexGrow="1";const h=c.clientWidth,u=c.clientHeight;this.size.set(h,u),this.camera.aspect=h/u,this.camera.updateProjectionMatrix(),this._amrRender.setSize(h,u),this._updateCamera(),this.css2dRenderer.setSize(h,u),this.renderer.getPixelRatio(),(p=this.pathTracer)==null||p.updateCamera(),this.sampleCount=0,this.renderer.setSize(h,u),(n=this._jumpFlood)==null||n.setSize(h,u)},this.ticker=c=>{if(!this._destroyed){if(this.stats.begin(),this.renderer.domElement.dispatchEvent(new CustomEvent("ticker",{detail:c})),this._rafId=requestAnimationFrame(this.ticker),this.renderer.clear(),this.usePathTracing){this.hideAmrUI(),this.sampleCount<this.maxSample?this.sampleCount++:this.pathTracer.pausePathTracing=!0,this.pathTracer.renderSample();const h=this.renderer.autoClear;this.renderer.autoClear=!1,this.scene.overrideMaterial=Yc,this.renderer.clearDepth(),this.renderer.render(this.scene,this.mainCamera),this.scene.overrideMaterial=null,this.renderer.render(this.overlayScene,this.mainCamera),this.renderer.autoClear=h}else{this._clock.getElapsedTime()-this._uiHiddenTime>.15?this.showControls&&this.amr.controllers.forEach(p=>p.show()):this.amr.controllers.forEach(p=>p.hide());const u=this.stats.fps();if(this.usePathTracing||(this._fpsCache.length>this._fpsCacheMax&&this._fpsCache.shift(),this._fpsCache.push(u)),this.amr.slots.forEach(p=>{this._dragging?p.getCanInstall()&&p.render(this):p.render(this)}),ne.update(),this.controls.update(),this._progressShadow.update(this.mainCamera),this.css2dRenderer.render(this.scene,this.mainCamera),this.updatePosition(),this.scene.overrideMaterial=null,this.renderer.render(this.scene,this.mainCamera),this._jumpFlood&&this._selectedForOutline.length>0){const p=this.scene.background;this.scene.background=null,this._jumpFlood.render(this._selectedForOutline),this.scene.background=p}}this.stats.end()}},this.stats.showPanel(0),this.hideState(),e.fov&&(this.camera.fov=e.fov,this.camera.updateProjectionMatrix()),Xr(je,this.renderer),this._ground.visible=!1,this.controls=new Sn.OrbitControls(this.camera,this.renderer.domElement),this.controls.enablePan=!0,this.controls.rotateSpeed=this.props.isMobile?.6:.5,this.controls.dampingFactor=Lr,this.controls.enableDamping=!0,this.controls.maxDistance=10,this.controls.minDistance=1,this.controls.zoomSpeed=this.props.isMobile?.3:tn()?.2:1,this._cameraPositionUI=new Oc(this.controls),this.renderer.setPixelRatio(window.devicePixelRatio||1),this.renderer.autoClear=!0,this.renderer.toneMapping=f.ACESFilmicToneMapping,this.renderer.toneMappingExposure=1.4,this.renderer.outputColorSpace=f.SRGBColorSpace,this.renderer.localClippingEnabled=!0,this.renderer.shadowMap.enabled=!0,this.css2dRenderer.domElement.style.pointerEvents="none",this.css2dRenderer.domElement.style.position="absolute",this.css2dRenderer.domElement.style.top="0px",this.css2dRenderer.domElement.setAttribute("data-css2d-root","1"),this._ensureCss2dUiStyle(),this.camera.position.set(10,-10,5),this.camera.lookAt(new f.Vector3);const{tiles:t}=il();this.pathTracer=new ga(this.renderer),this.pathTracer.multipleImportanceSampling=!0,this.pathTracer.filterGlossyFactor=.6;let i=window.devicePixelRatio;i<2&&(i=2),this.pathTracer.renderScale=this.props.isMobile?1:i,this.pathTracer.bounces=this.props.isMobile?8:10,this.pathTracer.transmissiveBounces=this.props.isMobile?1:3,this.pathTracer.tiles.set(t,t),this.pathTracer.minSamples=10,this.pathTracer.dynamicLowRes=!0,this.pathTracer.lowResScale=.5,this.pathTracer.fadeDuration=0;const s=new Rc(e.workerUrl),r=typeof navigator<"u"?navigator.hardwareConcurrency:4;s.maxWorkerCount=r,this.pathTracer.setBVHWorker(s),this.orthographicCamera.left=-20,this.orthographicCamera.right=20,this.orthographicCamera.top=-20,this.orthographicCamera.bottom=20,this._lastTarget=this.controls.target.clone();const o=()=>{let c=this._lastTarget.x,h=this._lastTarget.y;this.controls.target.x=c,this.controls.target.y=h};this.controls.addEventListener("change",()=>{var c;this.sampleCount=0,o(),this._uiHiddenTime=this._clock.getElapsedTime(),this.orthographicCamera.position.copy(this.camera.position),this.orthographicCamera.lookAt(this.controls.target),this.usePathTracing&&(this.pathTracer.pausePathTracing=!1,(c=this.pathTracer)==null||c.updateCamera()),this._updateCamera(),!(Math.abs(this.camera.position.x)<.001||Math.abs(this.camera.position.y)<.001)&&(this._axisMoving||(this.mainCamera=this.camera,this.usePathTracing&&this.generateBVH().then()))}),this._mainCamera=this.camera,this._progressShadow=new kc(this.renderer,this.scene,{size:8,lightCount:6,frames:e.isMobile?20:60,lightRadius:2,ambientWeight:.75}),this._progressShadow.lightOrigin.position.set(3,2.5,.6),this._progressShadow.visible=!1,this._container.add(this.amr),this.scene.add(this._container),this.ticker(0),this._loadEnv(),this._initEvents(),this.scene.add(this._cameraPositionUI),this._ground.rotateX(-Math.PI/2),this.scene.add(this._ground),this._jumpFlood=new Uc(this.renderer,this.scene,this.camera,{thickness:4,color:"#fff"}),(typeof e.useAxisBall!="boolean"||e.useAxisBall)&&(this._controlsGizmo=new Ec(this.controls,{size:160,padding:12,offset:e.axisBallOffset||new f.Vector2(10,10),fontSize:17,bubbleSizePrimary:18,bubbleSizeSecondary:14}),this._controlsGizmo.addListener("axis-select-start",()=>{this._axisMoving=!0,this.mainCamera=this.orthographicCamera,this.usePathTracing&&this.generateBVH().then()}),this._controlsGizmo.addListener("axis-select-end",()=>{this._axisMoving=!1}))}get usePathTracing(){return this._usePathTracing}_clearAmrContent(){const e=this.renderer.getRenderTarget();this.renderer.setRenderTarget(this._amrRender),this.renderer.setClearColor(0,0),this.renderer.clear(!0,!0,!0),this.renderer.setRenderTarget(e)}get shadowMode(){return this._shadowMode}set shadowMode(e){e?(this._progressShadow.visible=!1,this.amr.bodyOpacity=.2):(this._progressShadow.visible=!0,this.amr.bodyOpacity=1,this._progressShadow.isFinished||this._progressShadow.recalculate().then()),this._shadowMode=e}set usePathTracing(e){this._clearAmrContent(),e?(this.scene.background=new f.Color("transparent"),this.renderer.toneMappingExposure=1.8,this.overlayScene.add(this._progressShadow.shadowCatcherMesh),this.amr&&(this.amr.bodyOpacity=1),this.hideAmrUI(),this.pathTracer.renderToCanvas=!0,this.scene.background=null,this._ptEnvMap?(this.scene.environment=this._ptEnvMap,this.pathTracer.updateEnvironment()):new ks.HDRLoader().load(Nc,t=>{t.mapping=f.EquirectangularReflectionMapping,this._ptEnvMap=t,this.usePathTracing&&(this.scene.environment=t,this.pathTracer.updateEnvironment())})):(this.renderer.toneMappingExposure=1.4,this.scene.add(this._progressShadow.shadowCatcherMesh),this.pathTracer.renderToCanvas=!1,this.amr.logos.forEach(t=>{var i;(i=t.parent)==null||i.add(t.target)}),this.showAmrUI(),this.amr&&this.amr.opacityCache!==void 0?(this.amr.bodyOpacity=this.amr.opacityCache,this.amr.opacityCache=void 0):this.amr&&(this.amr.bodyOpacity=1),this.pathTracer.reset(),this._ground.visible=!1,this._envMap&&(this.scene.background=this._envMap,this.scene.environment=this._envMap)),this._usePathTracing=e,this.controls.dampingFactor=e?1:Lr,this.sampleCount=0}get fpsAverage(){return en(this._fpsCache)}get mainCamera(){return this._mainCamera}set mainCamera(e){this._mainCamera=e,e instanceof f.OrthographicCamera?this.scene.background=null:this.scene.background=this.scene.environment}showState(){this.stats.dom.style.display="block"}hideState(){this.stats.dom.style.display="none"}hideAmrUI(e=!0,t=!0){this.shadowMode||this.amr.slots.forEach(i=>i.hide()),this.amr.sizeBox.hide(e),this.amr.controllers.forEach(i=>i.hide()),this.amr.ikControllers.forEach(i=>i.enabled=!1),t&&this.amr.goods.forEach(i=>i.hide())}showAmrUI(e=!0){this.showSlots&&this.amr.slots.forEach(t=>t.show()),this.showSize&&this.amr.sizeBox.show(e),this.showControls&&(this.amr.controllers.forEach(t=>t.show()),this.amr.ikControllers.forEach(t=>t.enabled=!0)),this.amr.goods.forEach(t=>t.show())}get showSlots(){return this._showSlots}set showSlots(e){this._showSlots=e,this.amr.slots.forEach(t=>e?t.show():t.hide())}get showSize(){return this._showSize}set showSize(e){this._showSize=e,e?this.amr.sizeBox.show(!0):this.amr.sizeBox.hide(!0)}get showControls(){return this._showControls}set showControls(e){this._showControls=e,this.amr.controllers.forEach(t=>e?t.show():t.hide()),this.amr.ikControllers.forEach(t=>e?t.enabled=!0:t.enabled=!1)}_updateCamera(){const e=this.mainCamera.position.distanceTo(this.controls.target),t=2*Math.tan(this.camera.fov*.5*Math.PI/180)*e,i=this.size.x/this.size.y;this.orthographicCamera.left=-t*i/2,this.orthographicCamera.right=t*i/2,this.orthographicCamera.top=t/2,this.orthographicCamera.bottom=-t/2,this.orthographicCamera.updateProjectionMatrix()}_loadEnv(){new ks.HDRLoader().load(Gc,t=>{t.mapping=f.EquirectangularReflectionMapping,this._envMap=t,this._usePathTracing||(this.scene.background=t,this.scene.backgroundBlurriness=1,this.scene.backgroundIntensity=1,this.scene.backgroundRotation=new f.Euler(Math.PI/2,0,Math.PI*.98*.8),this.scene.environment=t,this.overlayScene.environment=t,this.scene.environmentRotation=this.scene.backgroundRotation,this.overlayScene.environmentRotation=this.scene.environmentRotation,this.scene.environmentIntensity=1.4,this.overlayScene.environmentIntensity=this.scene.environmentIntensity),this.pathTracer.updateEnvironment()},()=>{},()=>{})}_initEvents(){window.addEventListener("drag",this._drag),window.addEventListener("dragend",this._dragend),document.addEventListener("wheel",this._detectTrackpad),window.addEventListener("pointermove",this._pointermove),this.renderer.domElement.addEventListener("pointerdown",this._pointerdown);const e=this.scene.children.find(t=>t.type==="Mesh");e&&this.select(e)}switchCamera(){this.mainCamera=this.mainCamera===this.camera?this.orthographicCamera:this.camera}toCameraTop(){const e=this.camera.position.distanceTo(this.controls.target);this.camera.position.copy(new f.Vector3(0,e+this.controls.target.y,0))}toCameraRight(){const e=this.camera.position.distanceTo(this.controls.target);this.camera.position.copy(new f.Vector3(0,this.controls.target.y,e))}toCameraFace(){const e=this.camera.position.distanceTo(this.controls.target);this.camera.position.copy(new f.Vector3(e,this.controls.target.y,0))}async generateBVH(){this.pathTracer.pausePathTracing=!1,this.amr.slots.forEach(e=>e.hide()),this.amr&&(this.amr.opacityCache=this.amr.bodyOpacity,this.amr.bodyOpacity=1,this.overlayScene.clear(),this.amr.logos.forEach(e=>{const t=new f.Group;e.target.updateMatrixWorld(!0),t.applyMatrix4(e.target.matrixWorld),t.add(e.target),this.overlayScene.add(t)})),this.usePathTracing=!0,this.pathTracer.setScene(this.scene,this.mainCamera)}async download(e=!1){if(e&&!this.usePathTracing){const t=this._amrRender.width,i=this._amrRender.height,s=new Uint8Array(t*i*4);this.renderer.setRenderTarget(this._amrRender),this.renderer.readRenderTargetPixels(this._amrRender,0,0,t,i,s),this.renderer.setRenderTarget(null);const r=document.createElement("canvas");r.width=t,r.height=i;const o=r.getContext("2d"),c=new ImageData(t,i);for(let h=0;h<i;h++)for(let u=0;u<t;u++){const p=((i-h-1)*t+u)*4,n=(h*t+u)*4;c.data[n]=s[p],c.data[n+1]=s[p+1],c.data[n+2]=s[p+2],c.data[n+3]=s[p+3]}return o.putImageData(c,0,0),r.toDataURL("image/png")}else return new Promise((t,i)=>{this._uiHiddenTime=this._clock.getElapsedTime(),this.hideAmrUI();const s=this.scene.background;this.scene.background=null,setTimeout(()=>{const r=this.renderer.domElement.toDataURL("image/png");return this.scene.background=s,t(r)},this.fpsAverage)})}async captureTriViews(e){var o;const t=(e==null?void 0:e.subject)??this._container;(o=this._progressShadow)==null||o.visible;const i=this.scene.background,s=this.showSize;return new gn({renderer:this.renderer,scene:this.scene,overlayScene:this.overlayScene,subject:t,onBeforeCapture:()=>{this.scene.background=null,this.hideAmrUI(),this.showSize=!1,this.usePathTracing&&(this.usePathTracing=!1),this._progressShadow.visible=!1},onAfterCapture:()=>{this.scene.background=i,this.showAmrUI(),this.showSize=s,this._progressShadow.visible=!0}}).capture(e)}clearAMR(){De(this.overlayScene),this.amr.clean(),this.usePathTracing=!1}async exportAMR(){const e=this._container.clone(!0);return e.traverse(t=>{t.dispose&&(t.dispose(),t.removeFromParent())}),await rn.parseAsync(e,{onlyVisible:!0,binary:!0})}async addAMR(e,t=""){this.amr.init(this),await this.amr.load(e,t),this.amr.addEventListener("fork-height-change",this.debounceForkHeightChange),this.amr.addEventListener("shape-key-changed",(i,s)=>{this.pathTracer.reset(),this.sampleCount=0,this.pathTracer.setScene(this.scene,this.camera),this.overlayScene.traverse(r=>{if(!Object.keys(r.morphTargetDictionary||{}).includes(i))return;let o=s;r.userData[`origin_${i}`]&&(o-=r.userData[`origin_${i}`]);const c=r.morphTargetDictionary[i];r.morphTargetInfluences&&(r.morphTargetInfluences[c]=o),r instanceof f.Mesh&&r.geometry.translate(0,0,1e-5)}),["width","length","liftLength","liftWidth","liftOuterWidth"].includes(i)&&(this._progressShadow.clear(),this.debounceForkHeightChange())})}_animateCamera(e,t,i,s,r,o){var h;const c={t:0};(h=this._fitAnimation)==null||h.stop(),this._fitAnimation=new wi(c).to({t:1},r).easing(ne.Easing.Quadratic.InOut).onStart(()=>{this.controls.enabled=!1}).onUpdate(()=>{const u=c.t;this.controls.target.lerpVectors(i,s,u);const p=s.clone(),n=e.clone().sub(p),l=t.clone().sub(p),d=n.length(),g=l.length(),v=d+(g-d)*u;let m;if(d>.001&&g>.001){const _=n.clone().normalize(),y=l.clone().normalize(),w=_.angleTo(y);if(w>.001){const x=new f.Vector3().crossVectors(_,y);if(x.lengthSq()>.001){x.normalize();const b=new f.Quaternion().setFromAxisAngle(x,w*u),T=_.clone().applyQuaternion(b);m=p.clone().add(T.multiplyScalar(v))}else m=p.clone().add(_.multiplyScalar(v))}else m=p.clone().add(_.multiplyScalar(v))}else m=e.clone().lerp(t,u);this.camera.position.copy(m),this.camera.lookAt(this.controls.target)}).onComplete(()=>{this.controls.enabled=!0,o==null||o()}).start()}select(e,t=4){if(this._jumpFlood&&(this._jumpFlood.params.thickness=t),!e){this._selectedForOutline=[];return}typeof e=="string"||(Array.isArray(e)?this._selectedForOutline=[...e]:this._selectedForOutline=[e])}appendTo(e){e.append(this.renderer.domElement),e.append(this.stats.dom),e.append(this.css2dRenderer.domElement),this.props.isMobile?(e.classList.add("is-mobile"),e.style.cssText=`
3939
3939
  -webkit-user-select: none;
3940
3940
  user-select: none;
3941
3941
  touch-action: none;
@@ -3944,4 +3944,4 @@ vec3 texelOld = texture2D(previousShadowMap, vUv).rgb;
3944
3944
  [data-css2d-root="1"] [data-ui-type="mechanism"] {
3945
3945
  z-index: 2147483647 !important;
3946
3946
  }
3947
- `,document.head.append(t),this._css2dUiStyleInjected=!0}updatePosition(){}removeFromParent(){var t;const e=this.renderer.domElement.parentElement;e&&((t=this._resizeObserver)==null||t.unobserve(e),e.removeChild(this.renderer.domElement))}clean(){this.amr.clean(),this._progressShadow.clear()}destroy(){var t,i,s,a,n,c;this._destroyed=!0,this._rafId!==null&&(cancelAnimationFrame(this._rafId),this._rafId=null),this._clock.stop(),(t=this._controlsGizmo)==null||t.destroy(),this.amr.destroy(),this.amr.removeFromParent(),this._progressShadow.destroy(),(i=this._sciFiGrid)==null||i.removeFromParent(),(s=this._sciFiGrid)==null||s.geometry.dispose(),(a=this._sciFiGrid.material)==null||a.dispose(),Pe.removeAll(),this.stats.dom.remove(),this._emitter.removeAllListeners(),(n=this._fitAnimation)==null||n.stop(),window.removeEventListener("drag",this._drag),document.removeEventListener("wheel",this._detectTrackpad),window.removeEventListener("pointermove",this._pointermove),this.renderer.domElement.removeEventListener("pointerdown",this._pointerdown);const e=this.renderer.domElement.parentElement;e&&((c=this._resizeObserver)==null||c.unobserve(e)),this.controls.dispose(),this.renderer.domElement.remove(),this.renderer.dispose(),be(this.scene),this.scene.clear()}}class Xr{constructor(e){this.deps=e,this.canvas=null,this.pixelBuffer=null,this.orthoCamera=new d.OrthographicCamera(-1,1,1,-1,.1,1e3),this.orthoCamera.position.set(0,0,5),this.perspectiveCamera=new d.PerspectiveCamera(45,1,.1,2e3)}async capture(e){var g,y,m,v,_,x;const t=this.deps.renderer,i=(e==null?void 0:e.subject)??this.deps.subject;if(!i)throw new Error("TriViewCapture: subject is required.");const s=new d.Vector2;t.getSize(s);const a=((g=e==null?void 0:e.size)==null?void 0:g.width)??Math.round(s.x),n=((y=e==null?void 0:e.size)==null?void 0:y.height)??Math.round(s.y),c=(e==null?void 0:e.margin)??.15,h=(e==null?void 0:e.includeOverlay)??!1,f=a/n||1,p=this.resolveViews(e==null?void 0:e.views),r=new d.WebGLRenderTarget(a,n,{format:d.RGBAFormat,type:d.UnsignedByteType});r.texture.colorSpace=d.SRGBColorSpace,r.texture.generateMipmaps=!1,r.depthBuffer=!0;const l=this.storeRendererState(t),u={};try{(v=(m=this.deps).onBeforeCapture)==null||v.call(m);const w=this.computeBounds(i);this.applyRendererState(t,a,n,e==null?void 0:e.backgroundColor);for(const b of p){const T=this.configureCamera(w,b,f,c,a,n);t.setRenderTarget(r),t.clear(!0,!0,!0),t.render(this.deps.scene,T),h&&this.deps.overlayScene&&(t.clearDepth(),t.render(this.deps.overlayScene,T));const S=this.readPixels(t,r,a,n);u[b.key]=S}}finally{r.dispose(),this.restoreRendererState(t,l),(x=(_=this.deps).onAfterCapture)==null||x.call(_)}return u}resolveViews(e){return e&&e.length?e.map(t=>({key:t.key,direction:t.direction.clone(),up:t.up.clone(),plane:t.plane})):[{key:"top",direction:new d.Vector3(0,0,1),up:new d.Vector3(0,1,0),plane:{width:"x",height:"y",depth:"z"}},{key:"front",direction:new d.Vector3(0,-1,0),up:new d.Vector3(0,0,1),plane:{width:"x",height:"z",depth:"y"}},{key:"side",direction:new d.Vector3(1,0,0),up:new d.Vector3(0,0,1),plane:{width:"y",height:"z",depth:"x"}},{key:"perspective",direction:new d.Vector3(1,1,1),up:new d.Vector3(0,0,1),plane:{width:"x",height:"z",depth:"y"},mode:"perspective",fov:39.6}]}computeBounds(e){const t=new d.Box3,i=new d.Box3,s=new d.Vector3,a=new d.Vector3,n=new d.Sphere;return e.updateMatrixWorld(!0),e.traverse(c=>{if(!c.visible)return;const f=c.geometry;if(!f)return;f.boundingBox||f.computeBoundingBox();const p=f.boundingBox;p&&(i.copy(p).applyMatrix4(c.matrixWorld),t.union(i))}),t.isEmpty()?(t.setFromCenterAndSize(s,new d.Vector3(.001,.001,.001)),a.set(.001,.001,.001),n.center.copy(s),n.radius=.001):(t.getCenter(s),t.getSize(a),t.getBoundingSphere(n)),(!Number.isFinite(n.radius)||n.radius<=0)&&(n.radius=Math.max(a.length()*.5,.001)),{box:t,center:s,size:a,sphere:n}}configureCamera(e,t,i,s,a,n){const c=t.direction.clone().normalize();c.lengthSq()===0&&c.set(0,0,1);const h=t.up.clone().normalize();if(Math.abs(h.dot(c))>.999&&(h.set(0,0,1),Math.abs(h.dot(c))>.999&&h.set(0,1,0)),(t.mode??"orthographic")==="perspective"){const w=this.perspectiveCamera,b=t.fov??45,T=d.MathUtils.degToRad(b),S=Math.max(Math.tan(T/2),1e-4),L=Math.max(S*(i||1),1e-4),C=this.getPerspectiveDirection(t,e.size).normalize(),D=new d.Vector3().crossVectors(C,h).normalize();D.lengthSq()<1e-6&&D.set(1,0,0);const R=new d.Vector3().crossVectors(D,C).normalize(),A=Math.max(e.size.x*.5,1e-4),M=Math.max(e.size.y*.5,1e-4),I=Math.max(e.size.z*.5,1e-4),P=[new d.Vector3(-A,-M,-I),new d.Vector3(-A,-M,I),new d.Vector3(-A,M,-I),new d.Vector3(-A,M,I),new d.Vector3(A,-M,-I),new d.Vector3(A,-M,I),new d.Vector3(A,M,-I),new d.Vector3(A,M,I)];let E=0,B=-1/0;for(const H of P){const j=D.dot(H),U=R.dot(H),Q=C.dot(H);B=Math.max(B,Q);const re=Q+Math.abs(j)/L,te=Q+Math.abs(U)/S;E=Math.max(E,re,te)}E=Math.max(E,B+.1);const V=E*(1+s);let G=1/0;for(const H of P){const j=C.dot(H),U=V-j;U>.001&&(G=Math.min(G,U))}return w.fov=b,w.aspect=i||a/Math.max(n,1),w.near=Math.max(.1,Number.isFinite(G)?G*.5:V*.1),w.far=Math.max(w.near+1,V+e.sphere.radius*3),w.position.copy(e.center).add(C.clone().multiplyScalar(V)),w.up.copy(R),w.lookAt(e.center),w.updateProjectionMatrix(),w.updateMatrixWorld(!0),w}const p=this.orthoCamera,r=e.size,l=e.center,u=Math.max(r[t.plane.width]*.5,.01),g=Math.max(r[t.plane.height]*.5,.01),y=Math.max(r[t.plane.depth]*.5,.01);let m=u*(1+s),v=g*(1+s);m/i>v?v=m/i:m=v*i;const _=y*(1+s)+Math.max(m,v),x=l.clone().add(c.multiplyScalar(_));return p.left=-m,p.right=m,p.top=v,p.bottom=-v,p.near=.1,p.far=_*4,p.zoom=1,p.position.copy(x),p.up.copy(h),p.lookAt(l),p.updateProjectionMatrix(),p.updateMatrixWorld(!0),p}getPerspectiveDirection(e,t){const i=e.direction.clone();i.lengthSq()===0&&i.set(1,1,1);const s=new d.Vector3(Math.abs(i.x)||1,Math.abs(i.y)||1,Math.abs(i.z)||1),a=new d.Vector3(Math.sign(i.x||1),Math.sign(i.y||1),Math.sign(i.z||1)),n=.25,c=new d.Vector3(Math.max(n,s.x)*Math.max(t.x,.001),Math.max(n,s.y)*Math.max(t.y,.001),0),h=Math.max((t.x+t.y)*.5,.001),f=Math.max(t.z,.001),p=Math.max(n,s.z),r=f*.5+h*.5;return c.z=p*r,c.multiply(a),c}storeRendererState(e){const t=new d.Vector2;e.getSize(t);const i=new d.Vector4;e.getViewport(i);const s=new d.Vector4;e.getScissor(s);const a=e.getClearColor(new d.Color),n=e.getClearAlpha();return{size:t,pixelRatio:e.getPixelRatio(),viewport:i,scissor:s,scissorTest:e.getScissorTest(),autoClear:e.autoClear,target:e.getRenderTarget(),clearColor:a,clearAlpha:n}}applyRendererState(e,t,i,s){if(e.setPixelRatio(1),e.setSize(t,i,!1),e.setViewport(0,0,t,i),e.setScissor(0,0,t,i),e.setScissorTest(!1),e.autoClear=!0,s!==void 0)if(s===null){const a=e.getClearColor(new d.Color);e.setClearColor(a,0)}else s instanceof d.Color?e.setClearColor(s,1):e.setClearColor(new d.Color(s),1);else{const a=e.getClearColor(new d.Color);e.setClearColor(a,0)}}restoreRendererState(e,t){e.setPixelRatio(t.pixelRatio),e.setSize(t.size.x,t.size.y,!1),e.setViewport(t.viewport.x,t.viewport.y,t.viewport.z,t.viewport.w),e.setScissor(t.scissor.x,t.scissor.y,t.scissor.z,t.scissor.w),e.setScissorTest(t.scissorTest),e.autoClear=t.autoClear,e.setRenderTarget(t.target),e.setClearColor(t.clearColor,t.clearAlpha)}readPixels(e,t,i,s){const a=i*s*4;(!this.pixelBuffer||this.pixelBuffer.length!==a)&&(this.pixelBuffer=new Uint8Array(a)),e.readRenderTargetPixels(t,0,0,i,s,this.pixelBuffer);const n=this.ensureCanvas(i,s),c=n.getContext("2d");if(!c)throw new Error("TriViewCapture: failed to get 2D context.");const h=c.createImageData(i,s),f=h.data,p=this.pixelBuffer;for(let r=0;r<s;r+=1){const u=(s-r-1)*i*4,g=r*i*4;f.set(p.subarray(u,u+i*4),g)}return c.putImageData(h,0,0),n.toDataURL("image/png")}ensureCanvas(e,t){if(typeof document>"u")throw new Error("TriViewCapture: document is not available in this environment.");return this.canvas||(this.canvas=document.createElement("canvas")),(this.canvas.width!==e||this.canvas.height!==t)&&(this.canvas.width=e,this.canvas.height=t),this.canvas}}const Mc="shop-components",Cc="0.4.23",Rc="Shop components",Lc="dist/shop-components.umd.js",Ic="dist/shop-components.mjs",Dc="dist/main.d.ts",Pc={dts:"tsc --emitDeclarationOnly & tsc & storybook build -o dist",dev:"vite dev",build:"vite build","build:web":"BUILD_WEB=1 vite build --outDir dist/web --emptyOutDir",v:"auto-changelog -p && git add CHANGELOG.md"},Fc=["dist","package.json"],Ec=[],Bc="machengda<machengda@seer-group.com>",kc="ISC",Oc={"@needle-tools/gltf-progressive":"^3.3.5","auto-changelog":"^2.4.0",vite:"5.1.6","vite-plugin-dts":"^3.7.3",tweakpane:"^4.0.3","@tweakpane/core":"^2.0.3",stylus:"^0.63.0"},zc={"string-width":"4.2.3"},Vc={three:"0.182.0"},Uc={"@tweenjs/tween.js":"^23.1.2","@types/howler":"^2.2.11","@types/three":"0.182.0",eventemitter3:"^5.0.1",howler:"^2.2.4","stats-fps.js":"0.0.6","three-gpu-pathtracer":"^0.0.23","three-mesh-bvh":"^0.7.5","troika-three-text":"^0.49.1"},Wc={name:Mc,version:Cc,description:Rc,main:Lc,module:Ic,types:Dc,scripts:Pc,files:Fc,keywords:Ec,author:Bc,license:kc,devDependencies:Oc,resolutions:zc,peerDependencies:Vc,dependencies:Uc};function dr(){const o="Nebula Engin",e=Wc.version,t=`%c ${o} %c v${e} `;console.log(t,"background:#111827;color:#ffffff;padding:4px 10px;border-radius:4px 0 0 4px;font-weight:700;","background:#10B981;color:#ffffff;padding:4px 10px;border-radius:0 4px 4px 0;font-weight:700;")}const pr="__SHOP_COMPONENTS_BANNER_PRINTED__";try{const o=globalThis;o[pr]||(o[pr]=!0,dr())}catch{dr()}exports.Amr=Wr;exports.Logo=Yi;exports.SGLBLoader=Et;exports.SLOT_EVENTS=X;exports.Scene3D=Sc;exports.Skin=rs;exports.Slot=Qi;exports.SlotState=Kr;exports.TriViewCapture=Xr;exports.arrayBufferToUrl=qi;exports.calculateArrayAverage=Br;exports.calculateFocalLength=Ea;exports.createSGLBFile=ja;exports.downloadBlob=Fa;exports.dracoExporter=qa;exports.font=bc;exports.gltfExporter=zr;exports.gltfLoader=We;exports.imageBitmapToUrl=ji;exports.isAppleDevice=kr;exports.textureLoader=ds;
3947
+ `,document.head.append(t),this._css2dUiStyleInjected=!0}updatePosition(){}removeFromParent(){var t;const e=this.renderer.domElement.parentElement;e&&((t=this._resizeObserver)==null||t.unobserve(e),e.removeChild(this.renderer.domElement))}clean(){this.amr.clean(),this._progressShadow.clear()}destroy(){var t,i,s,r,o,c;this._destroyed=!0,this._rafId!==null&&(cancelAnimationFrame(this._rafId),this._rafId=null),this._clock.stop(),(t=this._controlsGizmo)==null||t.destroy(),this.amr.destroy(),this.amr.removeFromParent(),this._progressShadow.destroy(),(i=this._sciFiGrid)==null||i.removeFromParent(),(s=this._sciFiGrid)==null||s.geometry.dispose(),(r=this._sciFiGrid.material)==null||r.dispose(),ne.removeAll(),this.stats.dom.remove(),this._emitter.removeAllListeners(),(o=this._fitAnimation)==null||o.stop(),window.removeEventListener("drag",this._drag),document.removeEventListener("wheel",this._detectTrackpad),window.removeEventListener("pointermove",this._pointermove),this.renderer.domElement.removeEventListener("pointerdown",this._pointerdown);const e=this.renderer.domElement.parentElement;e&&((c=this._resizeObserver)==null||c.unobserve(e)),this.controls.dispose(),this.renderer.domElement.remove(),this.renderer.dispose(),De(this.scene),this.scene.clear()}}class gn{constructor(e){this.deps=e,this.canvas=null,this.pixelBuffer=null,this.orthoCamera=new f.OrthographicCamera(-1,1,1,-1,.1,1e3),this.orthoCamera.position.set(0,0,5),this.perspectiveCamera=new f.PerspectiveCamera(45,1,.1,2e3)}async capture(e){var g,v,m,_,y,w;const t=this.deps.renderer,i=(e==null?void 0:e.subject)??this.deps.subject;if(!i)throw new Error("TriViewCapture: subject is required.");const s=new f.Vector2;t.getSize(s);const r=((g=e==null?void 0:e.size)==null?void 0:g.width)??Math.round(s.x),o=((v=e==null?void 0:e.size)==null?void 0:v.height)??Math.round(s.y),c=(e==null?void 0:e.margin)??.15,h=(e==null?void 0:e.includeOverlay)??!1,u=r/o||1,p=this.resolveViews(e==null?void 0:e.views),n=new f.WebGLRenderTarget(r,o,{format:f.RGBAFormat,type:f.UnsignedByteType});n.texture.colorSpace=f.SRGBColorSpace,n.texture.generateMipmaps=!1,n.depthBuffer=!0;const l=this.storeRendererState(t),d={};try{(_=(m=this.deps).onBeforeCapture)==null||_.call(m);const x=this.computeBounds(i);this.applyRendererState(t,r,o,e==null?void 0:e.backgroundColor);for(const b of p){const T=this.configureCamera(x,b,u,c,r,o);t.setRenderTarget(n),t.clear(!0,!0,!0),t.render(this.deps.scene,T),h&&this.deps.overlayScene&&(t.clearDepth(),t.render(this.deps.overlayScene,T));const M=this.readPixels(t,n,r,o);d[b.key]=M}}finally{n.dispose(),this.restoreRendererState(t,l),(w=(y=this.deps).onAfterCapture)==null||w.call(y)}return d}resolveViews(e){return e&&e.length?e.map(t=>({key:t.key,direction:t.direction.clone(),up:t.up.clone(),plane:t.plane})):[{key:"top",direction:new f.Vector3(0,0,1),up:new f.Vector3(0,1,0),plane:{width:"x",height:"y",depth:"z"}},{key:"front",direction:new f.Vector3(0,-1,0),up:new f.Vector3(0,0,1),plane:{width:"x",height:"z",depth:"y"}},{key:"side",direction:new f.Vector3(1,0,0),up:new f.Vector3(0,0,1),plane:{width:"y",height:"z",depth:"x"}},{key:"perspective",direction:new f.Vector3(1,1,1),up:new f.Vector3(0,0,1),plane:{width:"x",height:"z",depth:"y"},mode:"perspective",fov:39.6}]}computeBounds(e){const t=new f.Box3,i=new f.Box3,s=new f.Vector3,r=new f.Vector3,o=new f.Sphere;return e.updateMatrixWorld(!0),e.traverse(c=>{if(!c.visible)return;const u=c.geometry;if(!u)return;u.boundingBox||u.computeBoundingBox();const p=u.boundingBox;p&&(i.copy(p).applyMatrix4(c.matrixWorld),t.union(i))}),t.isEmpty()?(t.setFromCenterAndSize(s,new f.Vector3(.001,.001,.001)),r.set(.001,.001,.001),o.center.copy(s),o.radius=.001):(t.getCenter(s),t.getSize(r),t.getBoundingSphere(o)),(!Number.isFinite(o.radius)||o.radius<=0)&&(o.radius=Math.max(r.length()*.5,.001)),{box:t,center:s,size:r,sphere:o}}configureCamera(e,t,i,s,r,o){const c=t.direction.clone().normalize();c.lengthSq()===0&&c.set(0,0,1);const h=t.up.clone().normalize();if(Math.abs(h.dot(c))>.999&&(h.set(0,0,1),Math.abs(h.dot(c))>.999&&h.set(0,1,0)),(t.mode??"orthographic")==="perspective"){const x=this.perspectiveCamera,b=t.fov??45,T=f.MathUtils.degToRad(b),M=Math.max(Math.tan(T/2),1e-4),L=Math.max(M*(i||1),1e-4),C=this.getPerspectiveDirection(t,e.size).normalize(),I=new f.Vector3().crossVectors(C,h).normalize();I.lengthSq()<1e-6&&I.set(1,0,0);const D=new f.Vector3().crossVectors(I,C).normalize(),A=Math.max(e.size.x*.5,1e-4),S=Math.max(e.size.y*.5,1e-4),P=Math.max(e.size.z*.5,1e-4),R=[new f.Vector3(-A,-S,-P),new f.Vector3(-A,-S,P),new f.Vector3(-A,S,-P),new f.Vector3(-A,S,P),new f.Vector3(A,-S,-P),new f.Vector3(A,-S,P),new f.Vector3(A,S,-P),new f.Vector3(A,S,P)];let k=0,F=-1/0;for(const N of R){const W=I.dot(N),O=D.dot(N),j=C.dot(N);F=Math.max(F,j);const U=j+Math.abs(W)/L,ie=j+Math.abs(O)/M;k=Math.max(k,U,ie)}k=Math.max(k,F+.1);const z=k*(1+s);let B=1/0;for(const N of R){const W=C.dot(N),O=z-W;O>.001&&(B=Math.min(B,O))}return x.fov=b,x.aspect=i||r/Math.max(o,1),x.near=Math.max(.1,Number.isFinite(B)?B*.5:z*.1),x.far=Math.max(x.near+1,z+e.sphere.radius*3),x.position.copy(e.center).add(C.clone().multiplyScalar(z)),x.up.copy(D),x.lookAt(e.center),x.updateProjectionMatrix(),x.updateMatrixWorld(!0),x}const p=this.orthoCamera,n=e.size,l=e.center,d=Math.max(n[t.plane.width]*.5,.01),g=Math.max(n[t.plane.height]*.5,.01),v=Math.max(n[t.plane.depth]*.5,.01);let m=d*(1+s),_=g*(1+s);m/i>_?_=m/i:m=_*i;const y=v*(1+s)+Math.max(m,_),w=l.clone().add(c.multiplyScalar(y));return p.left=-m,p.right=m,p.top=_,p.bottom=-_,p.near=.1,p.far=y*4,p.zoom=1,p.position.copy(w),p.up.copy(h),p.lookAt(l),p.updateProjectionMatrix(),p.updateMatrixWorld(!0),p}getPerspectiveDirection(e,t){const i=e.direction.clone();i.lengthSq()===0&&i.set(1,1,1);const s=new f.Vector3(Math.abs(i.x)||1,Math.abs(i.y)||1,Math.abs(i.z)||1),r=new f.Vector3(Math.sign(i.x||1),Math.sign(i.y||1),Math.sign(i.z||1)),o=.25,c=new f.Vector3(Math.max(o,s.x)*Math.max(t.x,.001),Math.max(o,s.y)*Math.max(t.y,.001),0),h=Math.max((t.x+t.y)*.5,.001),u=Math.max(t.z,.001),p=Math.max(o,s.z),n=u*.5+h*.5;return c.z=p*n,c.multiply(r),c}storeRendererState(e){const t=new f.Vector2;e.getSize(t);const i=new f.Vector4;e.getViewport(i);const s=new f.Vector4;e.getScissor(s);const r=e.getClearColor(new f.Color),o=e.getClearAlpha();return{size:t,pixelRatio:e.getPixelRatio(),viewport:i,scissor:s,scissorTest:e.getScissorTest(),autoClear:e.autoClear,target:e.getRenderTarget(),clearColor:r,clearAlpha:o}}applyRendererState(e,t,i,s){if(e.setPixelRatio(1),e.setSize(t,i,!1),e.setViewport(0,0,t,i),e.setScissor(0,0,t,i),e.setScissorTest(!1),e.autoClear=!0,s!==void 0)if(s===null){const r=e.getClearColor(new f.Color);e.setClearColor(r,0)}else s instanceof f.Color?e.setClearColor(s,1):e.setClearColor(new f.Color(s),1);else{const r=e.getClearColor(new f.Color);e.setClearColor(r,0)}}restoreRendererState(e,t){e.setPixelRatio(t.pixelRatio),e.setSize(t.size.x,t.size.y,!1),e.setViewport(t.viewport.x,t.viewport.y,t.viewport.z,t.viewport.w),e.setScissor(t.scissor.x,t.scissor.y,t.scissor.z,t.scissor.w),e.setScissorTest(t.scissorTest),e.autoClear=t.autoClear,e.setRenderTarget(t.target),e.setClearColor(t.clearColor,t.clearAlpha)}readPixels(e,t,i,s){const r=i*s*4;(!this.pixelBuffer||this.pixelBuffer.length!==r)&&(this.pixelBuffer=new Uint8Array(r)),e.readRenderTargetPixels(t,0,0,i,s,this.pixelBuffer);const o=this.ensureCanvas(i,s),c=o.getContext("2d");if(!c)throw new Error("TriViewCapture: failed to get 2D context.");const h=c.createImageData(i,s),u=h.data,p=this.pixelBuffer;for(let n=0;n<s;n+=1){const d=(s-n-1)*i*4,g=n*i*4;u.set(p.subarray(d,d+i*4),g)}return c.putImageData(h,0,0),o.toDataURL("image/png")}ensureCanvas(e,t){if(typeof document>"u")throw new Error("TriViewCapture: document is not available in this environment.");return this.canvas||(this.canvas=document.createElement("canvas")),(this.canvas.width!==e||this.canvas.height!==t)&&(this.canvas.width=e,this.canvas.height=t),this.canvas}}const Kc="shop-components",Xc="0.4.24",Jc="Shop components",$c="dist/shop-components.umd.js",eh="dist/shop-components.mjs",th="dist/main.d.ts",ih={dts:"tsc --emitDeclarationOnly & tsc & storybook build -o dist",dev:"vite dev",build:"vite build","build:web":"BUILD_WEB=1 vite build --outDir dist/web --emptyOutDir",v:"auto-changelog -p && git add CHANGELOG.md"},sh=["dist","package.json"],rh=[],nh="machengda<machengda@seer-group.com>",oh="ISC",ah={"@needle-tools/gltf-progressive":"^3.3.5","auto-changelog":"^2.4.0",vite:"5.1.6","vite-plugin-dts":"^3.7.3",tweakpane:"^4.0.3","@tweakpane/core":"^2.0.3",stylus:"^0.63.0"},lh={"string-width":"4.2.3"},ch={three:"0.182.0"},hh={"@tweenjs/tween.js":"^23.1.2","@types/howler":"^2.2.11","@types/three":"0.182.0",eventemitter3:"^5.0.1",howler:"^2.2.4","stats-fps.js":"0.0.6","three-gpu-pathtracer":"^0.0.23","three-mesh-bvh":"^0.7.5","troika-three-text":"^0.49.1"},uh={name:Kc,version:Xc,description:Jc,main:$c,module:eh,types:th,scripts:ih,files:sh,keywords:rh,author:nh,license:oh,devDependencies:ah,resolutions:lh,peerDependencies:ch,dependencies:hh};function Pr(){const a="Nebula Engin",e=uh.version,t=`%c ${a} %c v${e} `;console.log(t,"background:#111827;color:#ffffff;padding:4px 10px;border-radius:4px 0 0 4px;font-weight:700;","background:#10B981;color:#ffffff;padding:4px 10px;border-radius:0 4px 4px 0;font-weight:700;")}const Ir="__SHOP_COMPONENTS_BANNER_PRINTED__";try{const a=globalThis;a[Ir]||(a[Ir]=!0,Pr())}catch{Pr()}exports.Amr=an;exports.Logo=ls;exports.SGLBLoader=Ut;exports.SLOT_EVENTS=J;exports.Scene3D=Zc;exports.Skin=ys;exports.Slot=as;exports.SlotState=mn;exports.TriViewCapture=gn;exports.arrayBufferToUrl=ns;exports.calculateArrayAverage=en;exports.calculateFocalLength=Ka;exports.createSGLBFile=ll;exports.downloadBlob=Za;exports.dracoExporter=al;exports.font=jc;exports.gltfExporter=rn;exports.gltfLoader=je;exports.imageBitmapToUrl=os;exports.isAppleDevice=tn;exports.textureLoader=Ds;