@ridp/threejs 1.4.1 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/{readme.md → README.md} +228 -26
  2. package/dist/hooks.cjs +1 -1
  3. package/dist/hooks.js +12 -9
  4. package/dist/packages/threejs/package.json.cjs +1 -0
  5. package/dist/packages/threejs/package.json.js +4 -0
  6. package/dist/packages/threejs/src/hooks/useBatchGLTFLoader.cjs +1 -0
  7. package/dist/packages/threejs/src/hooks/useBatchGLTFLoader.js +83 -0
  8. package/dist/packages/threejs/src/hooks/useGLTFLoader.cjs +1 -0
  9. package/dist/packages/threejs/src/hooks/useGLTFLoader.js +292 -0
  10. package/dist/packages/threejs/src/hooks/useObb.cjs +1 -0
  11. package/dist/packages/threejs/src/hooks/useObb.js +41 -0
  12. package/dist/packages/threejs/src/hooks/useRaycaster.cjs +1 -0
  13. package/dist/packages/threejs/src/hooks/useRaycaster.js +35 -0
  14. package/dist/packages/threejs/src/hooks/useThreeJs.cjs +5 -0
  15. package/dist/packages/threejs/src/hooks/useThreeJs.js +153 -0
  16. package/dist/packages/threejs/src/instance/IDBCache.cjs +1 -0
  17. package/dist/packages/threejs/src/instance/IDBCache.js +142 -0
  18. package/dist/packages/threejs/src/instance/threeIns.cjs +3 -0
  19. package/dist/packages/threejs/src/instance/threeIns.js +393 -0
  20. package/dist/packages/threejs/src/utils/CacheMonitor.cjs +1 -0
  21. package/dist/packages/threejs/src/utils/CacheMonitor.js +125 -0
  22. package/dist/packages/threejs/src/utils/ImageLoader.cjs +1 -0
  23. package/dist/packages/threejs/src/utils/ImageLoader.js +33 -0
  24. package/dist/packages/threejs/src/utils/PredictiveLoader.cjs +1 -0
  25. package/dist/packages/threejs/src/utils/PredictiveLoader.js +155 -0
  26. package/dist/packages/threejs/src/utils/RetryHelper.cjs +1 -0
  27. package/dist/packages/threejs/src/utils/RetryHelper.js +108 -0
  28. package/dist/packages/threejs/src/utils/common.cjs +1 -0
  29. package/dist/packages/threejs/src/utils/common.js +15 -0
  30. package/dist/packages/threejs/src/utils/css3dHelper.cjs +15 -0
  31. package/dist/packages/threejs/src/utils/css3dHelper.js +42 -0
  32. package/dist/packages/threejs/src/utils/disposeObject.cjs +1 -0
  33. package/dist/packages/threejs/src/utils/disposeObject.js +13 -0
  34. package/dist/packages/threejs/src/utils/helper.cjs +1 -0
  35. package/dist/packages/threejs/src/utils/helper.js +47 -0
  36. package/dist/packages/threejs/src/utils/modelSerialize.cjs +1 -0
  37. package/dist/packages/threejs/src/utils/modelSerialize.js +225 -0
  38. package/dist/packages/threejs/src/utils/sceneRebuilder.cjs +1 -0
  39. package/dist/packages/threejs/src/utils/sceneRebuilder.js +138 -0
  40. package/dist/packages/threejs/src/workers/gltfParser.worker.cjs +1 -0
  41. package/dist/packages/threejs/src/workers/gltfParser.worker.js +11 -0
  42. package/dist/packages/threejs/src/workers/gltfParserOptimized.worker.cjs +1 -0
  43. package/dist/packages/threejs/src/workers/gltfParserOptimized.worker.js +11 -0
  44. package/dist/threejs.cjs +1 -3
  45. package/dist/threejs.js +58 -404
  46. package/dist/utils.cjs +1 -1
  47. package/dist/utils.js +40 -32
  48. package/package.json +1 -1
  49. package/dist/ImageLoader-Br_nvMOg.js +0 -1444
  50. package/dist/ImageLoader-DL32KyTh.cjs +0 -24
  51. package/dist/PredictiveLoader-CZfMSjv-.js +0 -3731
  52. package/dist/PredictiveLoader-DDxh7dDg.cjs +0 -2
  53. package/dist/useBatchGLTFLoader-B5EUagWI.js +0 -493
  54. package/dist/useBatchGLTFLoader-BjAvIpyB.cjs +0 -5
  55. /package/dist/{modelOptimizer-A0Cs6f9e.cjs → packages/threejs/src/utils/modelOptimizer.cjs} +0 -0
  56. /package/dist/{modelOptimizer-BRPnM2RH.js → packages/threejs/src/utils/modelOptimizer.js} +0 -0
@@ -1,2 +0,0 @@
1
- "use strict";const u=require("three"),ve=require("dexie");function He(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const S=He(u);var V=function(){var r=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(d){d.preventDefault(),s(++r%e.children.length)},!1);function t(d){return e.appendChild(d.dom),d}function s(d){for(var h=0;h<e.children.length;h++)e.children[h].style.display=h===d?"block":"none";r=d}var n=(performance||Date).now(),i=n,o=0,c=t(new V.Panel("FPS","#0ff","#002")),a=t(new V.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var l=t(new V.Panel("MB","#f08","#201"));return s(0),{REVISION:16,dom:e,addPanel:t,showPanel:s,begin:function(){n=(performance||Date).now()},end:function(){o++;var d=(performance||Date).now();if(a.update(d-n,200),d>=i+1e3&&(c.update(o*1e3/(d-i),100),i=d,o=0,l)){var h=performance.memory;l.update(h.usedJSHeapSize/1048576,h.jsHeapSizeLimit/1048576)}return d},update:function(){n=this.end()},domElement:e,setMode:s}};V.Panel=function(r,e,t){var s=1/0,n=0,i=Math.round,o=i(window.devicePixelRatio||1),c=80*o,a=48*o,l=3*o,d=2*o,h=3*o,g=15*o,p=74*o,y=30*o,_=document.createElement("canvas");_.width=c,_.height=a,_.style.cssText="width:80px;height:48px";var m=_.getContext("2d");return m.font="bold "+9*o+"px Helvetica,Arial,sans-serif",m.textBaseline="top",m.fillStyle=t,m.fillRect(0,0,c,a),m.fillStyle=e,m.fillText(r,l,d),m.fillRect(h,g,p,y),m.fillStyle=t,m.globalAlpha=.9,m.fillRect(h,g,p,y),{dom:_,update:function(f,T){s=Math.min(s,f),n=Math.max(n,f),m.fillStyle=t,m.globalAlpha=1,m.fillRect(0,0,c,g),m.fillStyle=e,m.fillText(i(f)+" "+r+" ("+i(s)+"-"+i(n)+")",l,d),m.drawImage(_,h+o,g,p-o,y,h,g,p-o,y),m.fillRect(h+p-o,g,o,y),m.fillStyle=t,m.globalAlpha=.9,m.fillRect(h+p-o,g,o,i((1-f/T)*y))}}};const me=new u.Vector3,Fe=new u.Quaternion,ge=new u.Vector3;class Ue extends u.Object3D{constructor(e=document.createElement("div")){super(),this.isCSS3DObject=!0,this.element=e,this.element.style.position="absolute",this.element.style.pointerEvents="auto",this.element.style.userSelect="none",this.element.setAttribute("draggable",!1),this.addEventListener("removed",function(){this.traverse(function(t){t.element instanceof t.element.ownerDocument.defaultView.Element&&t.element.parentNode!==null&&t.element.remove()})})}copy(e,t){return super.copy(e,t),this.element=e.element.cloneNode(!0),this}}class je extends Ue{constructor(e){super(e),this.isCSS3DSprite=!0,this.rotation2D=0}copy(e,t){return super.copy(e,t),this.rotation2D=e.rotation2D,this}}const I=new u.Matrix4,Ge=new u.Matrix4;class Be{constructor(e={}){const t=this;let s,n,i,o;const c={camera:{style:""},objects:new WeakMap},a=e.element!==void 0?e.element:document.createElement("div");a.style.overflow="hidden",this.domElement=a;const l=document.createElement("div");l.style.transformOrigin="0 0",l.style.pointerEvents="none",a.appendChild(l);const d=document.createElement("div");d.style.transformStyle="preserve-3d",l.appendChild(d),this.getSize=function(){return{width:s,height:n}},this.render=function(m,f){const T=f.projectionMatrix.elements[5]*o;f.view&&f.view.enabled?(l.style.transform=`translate( ${-f.view.offsetX*(s/f.view.width)}px, ${-f.view.offsetY*(n/f.view.height)}px )`,l.style.transform+=`scale( ${f.view.fullWidth/f.view.width}, ${f.view.fullHeight/f.view.height} )`):l.style.transform="",m.matrixWorldAutoUpdate===!0&&m.updateMatrixWorld(),f.parent===null&&f.matrixWorldAutoUpdate===!0&&f.updateMatrixWorld();let w,b;f.isOrthographicCamera&&(w=-(f.right+f.left)/2,b=(f.top+f.bottom)/2);const M=f.view&&f.view.enabled?f.view.height/f.view.fullHeight:1,A=f.isOrthographicCamera?`scale( ${M} )scale(`+T+")translate("+h(w)+"px,"+h(b)+"px)"+g(f.matrixWorldInverse):`scale( ${M} )translateZ(`+T+"px)"+g(f.matrixWorldInverse),R=(f.isPerspectiveCamera?"perspective("+T+"px) ":"")+A+"translate("+i+"px,"+o+"px)";c.camera.style!==R&&(d.style.transform=R,c.camera.style=R),_(m,m,f)},this.setSize=function(m,f){s=m,n=f,i=s/2,o=n/2,a.style.width=m+"px",a.style.height=f+"px",l.style.width=m+"px",l.style.height=f+"px",d.style.width=m+"px",d.style.height=f+"px"};function h(m){return Math.abs(m)<1e-10?0:m}function g(m){const f=m.elements;return"matrix3d("+h(f[0])+","+h(-f[1])+","+h(f[2])+","+h(f[3])+","+h(f[4])+","+h(-f[5])+","+h(f[6])+","+h(f[7])+","+h(f[8])+","+h(-f[9])+","+h(f[10])+","+h(f[11])+","+h(f[12])+","+h(-f[13])+","+h(f[14])+","+h(f[15])+")"}function p(m){const f=m.elements;return"translate(-50%,-50%)"+("matrix3d("+h(f[0])+","+h(f[1])+","+h(f[2])+","+h(f[3])+","+h(-f[4])+","+h(-f[5])+","+h(-f[6])+","+h(-f[7])+","+h(f[8])+","+h(f[9])+","+h(f[10])+","+h(f[11])+","+h(f[12])+","+h(f[13])+","+h(f[14])+","+h(f[15])+")")}function y(m){m.isCSS3DObject&&(m.element.style.display="none");for(let f=0,T=m.children.length;f<T;f++)y(m.children[f])}function _(m,f,T,w){if(m.visible===!1){y(m);return}if(m.isCSS3DObject){const b=m.layers.test(T.layers)===!0,M=m.element;if(M.style.display=b===!0?"":"none",b===!0){m.onBeforeRender(t,f,T);let A;m.isCSS3DSprite?(I.copy(T.matrixWorldInverse),I.transpose(),m.rotation2D!==0&&I.multiply(Ge.makeRotationZ(m.rotation2D)),m.matrixWorld.decompose(me,Fe,ge),I.setPosition(me),I.scale(ge),I.elements[3]=0,I.elements[7]=0,I.elements[11]=0,I.elements[15]=1,A=p(I)):A=p(m.matrixWorld);const L=c.objects.get(m);if(L===void 0||L.style!==A){M.style.transform=A;const R={style:A};c.objects.set(m,R)}M.parentNode!==d&&d.appendChild(M),m.onAfterRender(t,f,T)}}for(let b=0,M=m.children.length;b<M;b++)_(m.children[b],f,T)}}}const ye={type:"change"},de={type:"start"},Ae={type:"end"},Z=new u.Ray,_e=new u.Plane,ze=Math.cos(70*u.MathUtils.DEG2RAD),P=new u.Vector3,D=2*Math.PI,x={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},se=1e-6;class Le extends u.Controls{constructor(e,t=null){super(e,t),this.state=x.NONE,this.target=new u.Vector3,this.cursor=new u.Vector3,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:u.MOUSE.ROTATE,MIDDLE:u.MOUSE.DOLLY,RIGHT:u.MOUSE.PAN},this.touches={ONE:u.TOUCH.ROTATE,TWO:u.TOUCH.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this._lastPosition=new u.Vector3,this._lastQuaternion=new u.Quaternion,this._lastTargetPosition=new u.Vector3,this._quat=new u.Quaternion().setFromUnitVectors(e.up,new u.Vector3(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new u.Spherical,this._sphericalDelta=new u.Spherical,this._scale=1,this._panOffset=new u.Vector3,this._rotateStart=new u.Vector2,this._rotateEnd=new u.Vector2,this._rotateDelta=new u.Vector2,this._panStart=new u.Vector2,this._panEnd=new u.Vector2,this._panDelta=new u.Vector2,this._dollyStart=new u.Vector2,this._dollyEnd=new u.Vector2,this._dollyDelta=new u.Vector2,this._dollyDirection=new u.Vector3,this._mouse=new u.Vector2,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=Ve.bind(this),this._onPointerDown=Ke.bind(this),this._onPointerUp=We.bind(this),this._onContextMenu=Je.bind(this),this._onMouseWheel=qe.bind(this),this._onKeyDown=Ze.bind(this),this._onTouchStart=$e.bind(this),this._onTouchMove=Qe.bind(this),this._onMouseDown=Xe.bind(this),this._onMouseMove=Ye.bind(this),this._interceptControlDown=et.bind(this),this._interceptControlUp=tt.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}connect(e){super.connect(e),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(ye),this.update(),this.state=x.NONE}update(e=null){const t=this.object.position;P.copy(t).sub(this.target),P.applyQuaternion(this._quat),this._spherical.setFromVector3(P),this.autoRotate&&this.state===x.NONE&&this._rotateLeft(this._getAutoRotationAngle(e)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let s=this.minAzimuthAngle,n=this.maxAzimuthAngle;isFinite(s)&&isFinite(n)&&(s<-Math.PI?s+=D:s>Math.PI&&(s-=D),n<-Math.PI?n+=D:n>Math.PI&&(n-=D),s<=n?this._spherical.theta=Math.max(s,Math.min(n,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(s+n)/2?Math.max(s,this._spherical.theta):Math.min(n,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let i=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const o=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),i=o!=this._spherical.radius}if(P.setFromSpherical(this._spherical),P.applyQuaternion(this._quatInverse),t.copy(this.target).add(P),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let o=null;if(this.object.isPerspectiveCamera){const c=P.length();o=this._clampDistance(c*this._scale);const a=c-o;this.object.position.addScaledVector(this._dollyDirection,a),this.object.updateMatrixWorld(),i=!!a}else if(this.object.isOrthographicCamera){const c=new u.Vector3(this._mouse.x,this._mouse.y,0);c.unproject(this.object);const a=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),i=a!==this.object.zoom;const l=new u.Vector3(this._mouse.x,this._mouse.y,0);l.unproject(this.object),this.object.position.sub(l).add(c),this.object.updateMatrixWorld(),o=P.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;o!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(o).add(this.object.position):(Z.origin.copy(this.object.position),Z.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(Z.direction))<ze?this.object.lookAt(this.target):(_e.setFromNormalAndCoplanarPoint(this.object.up,this.target),Z.intersectPlane(_e,this.target))))}else if(this.object.isOrthographicCamera){const o=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),o!==this.object.zoom&&(this.object.updateProjectionMatrix(),i=!0)}return this._scale=1,this._performCursorZoom=!1,i||this._lastPosition.distanceToSquared(this.object.position)>se||8*(1-this._lastQuaternion.dot(this.object.quaternion))>se||this._lastTargetPosition.distanceToSquared(this.target)>se?(this.dispatchEvent(ye),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e!==null?D/60*this.autoRotateSpeed*e:D/60/60*this.autoRotateSpeed}_getZoomScale(e){const t=Math.abs(e*.01);return Math.pow(.95,this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){P.setFromMatrixColumn(t,0),P.multiplyScalar(-e),this._panOffset.add(P)}_panUp(e,t){this.screenSpacePanning===!0?P.setFromMatrixColumn(t,1):(P.setFromMatrixColumn(t,0),P.crossVectors(this.object.up,P)),P.multiplyScalar(e),this._panOffset.add(P)}_pan(e,t){const s=this.domElement;if(this.object.isPerspectiveCamera){const n=this.object.position;P.copy(n).sub(this.target);let i=P.length();i*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*i/s.clientHeight,this.object.matrix),this._panUp(2*t*i/s.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/s.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/s.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const s=this.domElement.getBoundingClientRect(),n=e-s.left,i=t-s.top,o=s.width,c=s.height;this._mouse.x=n/o*2-1,this._mouse.y=-(i/c)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(D*this._rotateDelta.x/t.clientHeight),this._rotateUp(D*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(D*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-D*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(D*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-D*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),s=.5*(e.pageX+t.x),n=.5*(e.pageY+t.y);this._rotateStart.set(s,n)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),s=.5*(e.pageX+t.x),n=.5*(e.pageY+t.y);this._panStart.set(s,n)}}_handleTouchStartDolly(e){const t=this._getSecondPointerPosition(e),s=e.pageX-t.x,n=e.pageY-t.y,i=Math.sqrt(s*s+n*n);this._dollyStart.set(0,i)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{const s=this._getSecondPointerPosition(e),n=.5*(e.pageX+s.x),i=.5*(e.pageY+s.y);this._rotateEnd.set(n,i)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(D*this._rotateDelta.x/t.clientHeight),this._rotateUp(D*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),s=.5*(e.pageX+t.x),n=.5*(e.pageY+t.y);this._panEnd.set(s,n)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){const t=this._getSecondPointerPosition(e),s=e.pageX-t.x,n=e.pageY-t.y,i=Math.sqrt(s*s+n*n);this._dollyEnd.set(0,i),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const o=(e.pageX+t.x)*.5,c=(e.pageY+t.y)*.5;this._updateZoomParameters(o,c)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new u.Vector2,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){const t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){const t=e.deltaMode,s={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:s.deltaY*=16;break;case 2:s.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(s.deltaY*=10),s}}function Ke(r){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(r.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(r)&&(this._addPointer(r),r.pointerType==="touch"?this._onTouchStart(r):this._onMouseDown(r)))}function Ve(r){this.enabled!==!1&&(r.pointerType==="touch"?this._onTouchMove(r):this._onMouseMove(r))}function We(r){switch(this._removePointer(r),this._pointers.length){case 0:this.domElement.releasePointerCapture(r.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(Ae),this.state=x.NONE;break;case 1:const e=this._pointers[0],t=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:t.x,pageY:t.y});break}}function Xe(r){let e;switch(r.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case u.MOUSE.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(r),this.state=x.DOLLY;break;case u.MOUSE.ROTATE:if(r.ctrlKey||r.metaKey||r.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(r),this.state=x.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(r),this.state=x.ROTATE}break;case u.MOUSE.PAN:if(r.ctrlKey||r.metaKey||r.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(r),this.state=x.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(r),this.state=x.PAN}break;default:this.state=x.NONE}this.state!==x.NONE&&this.dispatchEvent(de)}function Ye(r){switch(this.state){case x.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(r);break;case x.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(r);break;case x.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(r);break}}function qe(r){this.enabled===!1||this.enableZoom===!1||this.state!==x.NONE||(r.preventDefault(),this.dispatchEvent(de),this._handleMouseWheel(this._customWheelEvent(r)),this.dispatchEvent(Ae))}function Ze(r){this.enabled!==!1&&this._handleKeyDown(r)}function $e(r){switch(this._trackPointer(r),this._pointers.length){case 1:switch(this.touches.ONE){case u.TOUCH.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(r),this.state=x.TOUCH_ROTATE;break;case u.TOUCH.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(r),this.state=x.TOUCH_PAN;break;default:this.state=x.NONE}break;case 2:switch(this.touches.TWO){case u.TOUCH.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(r),this.state=x.TOUCH_DOLLY_PAN;break;case u.TOUCH.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(r),this.state=x.TOUCH_DOLLY_ROTATE;break;default:this.state=x.NONE}break;default:this.state=x.NONE}this.state!==x.NONE&&this.dispatchEvent(de)}function Qe(r){switch(this._trackPointer(r),this.state){case x.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(r),this.update();break;case x.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(r),this.update();break;case x.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(r),this.update();break;case x.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(r),this.update();break;default:this.state=x.NONE}}function Je(r){this.enabled!==!1&&r.preventDefault()}function et(r){r.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function tt(r){r.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}class st extends Le{constructor(e,t){super(e,t),this.screenSpacePanning=!1,this.mouseButtons={LEFT:u.MOUSE.PAN,MIDDLE:u.MOUSE.DOLLY,RIGHT:u.MOUSE.ROTATE},this.touches={ONE:u.TOUCH.PAN,TWO:u.TOUCH.DOLLY_ROTATE}}}function nt(r){return new u.CameraHelper(r)}function it(r=150,...e){return new u.GridHelper(r,r/10,...e)}function ot(r){return new u.BoxHelper(r,16776960)}function rt(r,e){return new Le(r,e)}function at(r,e){return new st(r,e)}function ct(){const r=new u.Raycaster,e=new u.Vector2(0,0);return{raycaster:r,pointer:e}}function lt(r=10){return new u.AxesHelper(r)}function ht(r=new u.Vector3(1,1,1),e=new u.Vector3(10,10,10),t=5,s=16776960){return r.normalize(),new u.ArrowHelper(r,e,t,s)}function ut(){const r=new V;return r.dom.style.cssText="position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000",r}function Te(r,e){if(e===u.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),r;if(e===u.TriangleFanDrawMode||e===u.TriangleStripDrawMode){let t=r.getIndex();if(t===null){const o=[],c=r.getAttribute("position");if(c!==void 0){for(let a=0;a<c.count;a++)o.push(a);r.setIndex(o),t=r.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),r}const s=t.count-2,n=[];if(e===u.TriangleFanDrawMode)for(let o=1;o<=s;o++)n.push(t.getX(0)),n.push(t.getX(o)),n.push(t.getX(o+1));else for(let o=0;o<s;o++)o%2===0?(n.push(t.getX(o)),n.push(t.getX(o+1)),n.push(t.getX(o+2))):(n.push(t.getX(o+2)),n.push(t.getX(o+1)),n.push(t.getX(o)));n.length/3!==s&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=r.clone();return i.setIndex(n),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),r}const ne=new WeakMap;class dt extends u.Loader{constructor(e){super(e),this.decoderPath="",this.decoderConfig={},this.decoderBinary=null,this.decoderPending=null,this.workerLimit=4,this.workerPool=[],this.workerNextTaskID=1,this.workerSourceURL="",this.defaultAttributeIDs={position:"POSITION",normal:"NORMAL",color:"COLOR",uv:"TEX_COORD"},this.defaultAttributeTypes={position:"Float32Array",normal:"Float32Array",color:"Float32Array",uv:"Float32Array"}}setDecoderPath(e){return this.decoderPath=e,this}setDecoderConfig(e){return this.decoderConfig=e,this}setWorkerLimit(e){return this.workerLimit=e,this}load(e,t,s,n){const i=new u.FileLoader(this.manager);i.setPath(this.path),i.setResponseType("arraybuffer"),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,o=>{this.parse(o,t,n)},s,n)}parse(e,t,s=()=>{}){this.decodeDracoFile(e,t,null,null,u.SRGBColorSpace,s).catch(s)}decodeDracoFile(e,t,s,n,i=u.LinearSRGBColorSpace,o=()=>{}){const c={attributeIDs:s||this.defaultAttributeIDs,attributeTypes:n||this.defaultAttributeTypes,useUniqueIDs:!!s,vertexColorSpace:i};return this.decodeGeometry(e,c).then(t).catch(o)}decodeGeometry(e,t){const s=JSON.stringify(t);if(ne.has(e)){const a=ne.get(e);if(a.key===s)return a.promise;if(e.byteLength===0)throw new Error("THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred.")}let n;const i=this.workerNextTaskID++,o=e.byteLength,c=this._getWorker(i,o).then(a=>(n=a,new Promise((l,d)=>{n._callbacks[i]={resolve:l,reject:d},n.postMessage({type:"decode",id:i,taskConfig:t,buffer:e},[e])}))).then(a=>this._createGeometry(a.geometry));return c.catch(()=>!0).then(()=>{n&&i&&this._releaseTask(n,i)}),ne.set(e,{key:s,promise:c}),c}_createGeometry(e){const t=new u.BufferGeometry;e.index&&t.setIndex(new u.BufferAttribute(e.index.array,1));for(let s=0;s<e.attributes.length;s++){const n=e.attributes[s],i=n.name,o=n.array,c=n.itemSize,a=new u.BufferAttribute(o,c);i==="color"&&(this._assignVertexColorSpace(a,n.vertexColorSpace),a.normalized=!(o instanceof Float32Array)),t.setAttribute(i,a)}return t}_assignVertexColorSpace(e,t){if(t!==u.SRGBColorSpace)return;const s=new u.Color;for(let n=0,i=e.count;n<i;n++)s.fromBufferAttribute(e,n),u.ColorManagement.colorSpaceToWorking(s,u.SRGBColorSpace),e.setXYZ(n,s.r,s.g,s.b)}_loadLibrary(e,t){const s=new u.FileLoader(this.manager);return s.setPath(this.decoderPath),s.setResponseType(t),s.setWithCredentials(this.withCredentials),new Promise((n,i)=>{s.load(e,n,void 0,i)})}preload(){return this._initDecoder(),this}_initDecoder(){if(this.decoderPending)return this.decoderPending;const e=typeof WebAssembly!="object"||this.decoderConfig.type==="js",t=[];return e?t.push(this._loadLibrary("draco_decoder.js","text")):(t.push(this._loadLibrary("draco_wasm_wrapper.js","text")),t.push(this._loadLibrary("draco_decoder.wasm","arraybuffer"))),this.decoderPending=Promise.all(t).then(s=>{const n=s[0];e||(this.decoderConfig.wasmBinary=s[1]);const i=ft.toString(),o=["/* draco decoder */",n,"","/* worker */",i.substring(i.indexOf("{")+1,i.lastIndexOf("}"))].join(`
2
- `);this.workerSourceURL=URL.createObjectURL(new Blob([o]))}),this.decoderPending}_getWorker(e,t){return this._initDecoder().then(()=>{if(this.workerPool.length<this.workerLimit){const n=new Worker(this.workerSourceURL);n._callbacks={},n._taskCosts={},n._taskLoad=0,n.postMessage({type:"init",decoderConfig:this.decoderConfig}),n.onmessage=function(i){const o=i.data;switch(o.type){case"decode":n._callbacks[o.id].resolve(o);break;case"error":n._callbacks[o.id].reject(o);break;default:console.error('THREE.DRACOLoader: Unexpected message, "'+o.type+'"')}},this.workerPool.push(n)}else this.workerPool.sort(function(n,i){return n._taskLoad>i._taskLoad?-1:1});const s=this.workerPool[this.workerPool.length-1];return s._taskCosts[e]=t,s._taskLoad+=t,s})}_releaseTask(e,t){e._taskLoad-=e._taskCosts[t],delete e._callbacks[t],delete e._taskCosts[t]}debug(){console.log("Task load: ",this.workerPool.map(e=>e._taskLoad))}dispose(){for(let e=0;e<this.workerPool.length;++e)this.workerPool[e].terminate();return this.workerPool.length=0,this.workerSourceURL!==""&&URL.revokeObjectURL(this.workerSourceURL),this}}function ft(){let r,e;onmessage=function(o){const c=o.data;switch(c.type){case"init":r=c.decoderConfig,e=new Promise(function(d){r.onModuleLoaded=function(h){d({draco:h})},DracoDecoderModule(r)});break;case"decode":const a=c.buffer,l=c.taskConfig;e.then(d=>{const h=d.draco,g=new h.Decoder;try{const p=t(h,g,new Int8Array(a),l),y=p.attributes.map(_=>_.array.buffer);p.index&&y.push(p.index.array.buffer),self.postMessage({type:"decode",id:c.id,geometry:p},y)}catch(p){console.error(p),self.postMessage({type:"error",id:c.id,error:p.message})}finally{h.destroy(g)}});break}};function t(o,c,a,l){const d=l.attributeIDs,h=l.attributeTypes;let g,p;const y=c.GetEncodedGeometryType(a);if(y===o.TRIANGULAR_MESH)g=new o.Mesh,p=c.DecodeArrayToMesh(a,a.byteLength,g);else if(y===o.POINT_CLOUD)g=new o.PointCloud,p=c.DecodeArrayToPointCloud(a,a.byteLength,g);else throw new Error("THREE.DRACOLoader: Unexpected geometry type.");if(!p.ok()||g.ptr===0)throw new Error("THREE.DRACOLoader: Decoding failed: "+p.error_msg());const _={index:null,attributes:[]};for(const m in d){const f=self[h[m]];let T,w;if(l.useUniqueIDs)w=d[m],T=c.GetAttributeByUniqueId(g,w);else{if(w=c.GetAttributeId(g,o[d[m]]),w===-1)continue;T=c.GetAttribute(g,w)}const b=n(o,c,g,m,f,T);m==="color"&&(b.vertexColorSpace=l.vertexColorSpace),_.attributes.push(b)}return y===o.TRIANGULAR_MESH&&(_.index=s(o,c,g)),o.destroy(g),_}function s(o,c,a){const d=a.num_faces()*3,h=d*4,g=o._malloc(h);c.GetTrianglesUInt32Array(a,h,g);const p=new Uint32Array(o.HEAPF32.buffer,g,d).slice();return o._free(g),{array:p,itemSize:1}}function n(o,c,a,l,d,h){const g=h.num_components(),y=a.num_points()*g,_=y*d.BYTES_PER_ELEMENT,m=i(o,d),f=o._malloc(_);c.GetAttributeDataArrayForAllPoints(a,h,m,_,f);const T=new d(o.HEAPF32.buffer,f,y).slice();return o._free(f),{name:l,array:T,itemSize:g}}function i(o,c){switch(c){case Float32Array:return o.DT_FLOAT32;case Int8Array:return o.DT_INT8;case Int16Array:return o.DT_INT16;case Int32Array:return o.DT_INT32;case Uint8Array:return o.DT_UINT8;case Uint16Array:return o.DT_UINT16;case Uint32Array:return o.DT_UINT32}}}class pt extends u.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new Tt(t)}),this.register(function(t){return new bt(t)}),this.register(function(t){return new Pt(t)}),this.register(function(t){return new Ct(t)}),this.register(function(t){return new Dt(t)}),this.register(function(t){return new Et(t)}),this.register(function(t){return new St(t)}),this.register(function(t){return new xt(t)}),this.register(function(t){return new Mt(t)}),this.register(function(t){return new _t(t)}),this.register(function(t){return new Rt(t)}),this.register(function(t){return new wt(t)}),this.register(function(t){return new Lt(t)}),this.register(function(t){return new At(t)}),this.register(function(t){return new gt(t)}),this.register(function(t){return new Ot(t)}),this.register(function(t){return new It(t)})}load(e,t,s,n){const i=this;let o;if(this.resourcePath!=="")o=this.resourcePath;else if(this.path!==""){const l=u.LoaderUtils.extractUrlBase(e);o=u.LoaderUtils.resolveURL(l,this.path)}else o=u.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const c=function(l){n?n(l):console.error(l),i.manager.itemError(e),i.manager.itemEnd(e)},a=new u.FileLoader(this.manager);a.setPath(this.path),a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(e,function(l){try{i.parse(l,o,function(d){t(d),i.manager.itemEnd(e)},c)}catch(d){c(d)}},s,c)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,s,n){let i;const o={},c={},a=new TextDecoder;if(typeof e=="string")i=JSON.parse(e);else if(e instanceof ArrayBuffer)if(a.decode(new Uint8Array(e,0,4))===Pe){try{o[E.KHR_BINARY_GLTF]=new kt(e)}catch(h){n&&n(h);return}i=JSON.parse(o[E.KHR_BINARY_GLTF].content)}else i=JSON.parse(a.decode(e));else i=e;if(i.asset===void 0||i.asset.version[0]<2){n&&n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const l=new Xt(i,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});l.fileLoader.setRequestHeader(this.requestHeader);for(let d=0;d<this.pluginCallbacks.length;d++){const h=this.pluginCallbacks[d](l);h.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),c[h.name]=h,o[h.name]=!0}if(i.extensionsUsed)for(let d=0;d<i.extensionsUsed.length;++d){const h=i.extensionsUsed[d],g=i.extensionsRequired||[];switch(h){case E.KHR_MATERIALS_UNLIT:o[h]=new yt;break;case E.KHR_DRACO_MESH_COMPRESSION:o[h]=new Nt(i,this.dracoLoader);break;case E.KHR_TEXTURE_TRANSFORM:o[h]=new vt;break;case E.KHR_MESH_QUANTIZATION:o[h]=new Ht;break;default:g.indexOf(h)>=0&&c[h]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+h+'".')}}l.setExtensions(o),l.setPlugins(c),l.parse(s,n)}parseAsync(e,t){const s=this;return new Promise(function(n,i){s.parse(e,t,n,i)})}}function mt(){let r={};return{get:function(e){return r[e]},add:function(e,t){r[e]=t},remove:function(e){delete r[e]},removeAll:function(){r={}}}}const E={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class gt{constructor(e){this.parser=e,this.name=E.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,n=t.length;s<n;s++){const i=t[s];i.extensions&&i.extensions[this.name]&&i.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,i.extensions[this.name].light)}}_loadLight(e){const t=this.parser,s="light:"+e;let n=t.cache.get(s);if(n)return n;const i=t.json,a=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e];let l;const d=new u.Color(16777215);a.color!==void 0&&d.setRGB(a.color[0],a.color[1],a.color[2],u.LinearSRGBColorSpace);const h=a.range!==void 0?a.range:0;switch(a.type){case"directional":l=new u.DirectionalLight(d),l.target.position.set(0,0,-1),l.add(l.target);break;case"point":l=new u.PointLight(d),l.distance=h;break;case"spot":l=new u.SpotLight(d),l.distance=h,a.spot=a.spot||{},a.spot.innerConeAngle=a.spot.innerConeAngle!==void 0?a.spot.innerConeAngle:0,a.spot.outerConeAngle=a.spot.outerConeAngle!==void 0?a.spot.outerConeAngle:Math.PI/4,l.angle=a.spot.outerConeAngle,l.penumbra=1-a.spot.innerConeAngle/a.spot.outerConeAngle,l.target.position.set(0,0,-1),l.add(l.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+a.type)}return l.position.set(0,0,0),N(l,a),a.intensity!==void 0&&(l.intensity=a.intensity),l.name=t.createUniqueName(a.name||"light_"+e),n=Promise.resolve(l),t.cache.add(s,n),n}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,s=this.parser,i=s.json.nodes[e],c=(i.extensions&&i.extensions[this.name]||{}).light;return c===void 0?null:this._loadLight(c).then(function(a){return s._getNodeRef(t.cache,c,a)})}}class yt{constructor(){this.name=E.KHR_MATERIALS_UNLIT}getMaterialType(){return u.MeshBasicMaterial}extendParams(e,t,s){const n=[];e.color=new u.Color(1,1,1),e.opacity=1;const i=t.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const o=i.baseColorFactor;e.color.setRGB(o[0],o[1],o[2],u.LinearSRGBColorSpace),e.opacity=o[3]}i.baseColorTexture!==void 0&&n.push(s.assignTexture(e,"map",i.baseColorTexture,u.SRGBColorSpace))}return Promise.all(n)}}class _t{constructor(e){this.parser=e,this.name=E.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=n.extensions[this.name].emissiveStrength;return i!==void 0&&(t.emissiveIntensity=i),Promise.resolve()}}class Tt{constructor(e){this.parser=e,this.name=E.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:u.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];if(o.clearcoatFactor!==void 0&&(t.clearcoat=o.clearcoatFactor),o.clearcoatTexture!==void 0&&i.push(s.assignTexture(t,"clearcoatMap",o.clearcoatTexture)),o.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=o.clearcoatRoughnessFactor),o.clearcoatRoughnessTexture!==void 0&&i.push(s.assignTexture(t,"clearcoatRoughnessMap",o.clearcoatRoughnessTexture)),o.clearcoatNormalTexture!==void 0&&(i.push(s.assignTexture(t,"clearcoatNormalMap",o.clearcoatNormalTexture)),o.clearcoatNormalTexture.scale!==void 0)){const c=o.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new u.Vector2(c,c)}return Promise.all(i)}}class bt{constructor(e){this.parser=e,this.name=E.KHR_MATERIALS_DISPERSION}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:u.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=n.extensions[this.name];return t.dispersion=i.dispersion!==void 0?i.dispersion:0,Promise.resolve()}}class wt{constructor(e){this.parser=e,this.name=E.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:u.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];return o.iridescenceFactor!==void 0&&(t.iridescence=o.iridescenceFactor),o.iridescenceTexture!==void 0&&i.push(s.assignTexture(t,"iridescenceMap",o.iridescenceTexture)),o.iridescenceIor!==void 0&&(t.iridescenceIOR=o.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),o.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=o.iridescenceThicknessMinimum),o.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=o.iridescenceThicknessMaximum),o.iridescenceThicknessTexture!==void 0&&i.push(s.assignTexture(t,"iridescenceThicknessMap",o.iridescenceThicknessTexture)),Promise.all(i)}}class Et{constructor(e){this.parser=e,this.name=E.KHR_MATERIALS_SHEEN}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:u.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[];t.sheenColor=new u.Color(0,0,0),t.sheenRoughness=0,t.sheen=1;const o=n.extensions[this.name];if(o.sheenColorFactor!==void 0){const c=o.sheenColorFactor;t.sheenColor.setRGB(c[0],c[1],c[2],u.LinearSRGBColorSpace)}return o.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=o.sheenRoughnessFactor),o.sheenColorTexture!==void 0&&i.push(s.assignTexture(t,"sheenColorMap",o.sheenColorTexture,u.SRGBColorSpace)),o.sheenRoughnessTexture!==void 0&&i.push(s.assignTexture(t,"sheenRoughnessMap",o.sheenRoughnessTexture)),Promise.all(i)}}class St{constructor(e){this.parser=e,this.name=E.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:u.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];return o.transmissionFactor!==void 0&&(t.transmission=o.transmissionFactor),o.transmissionTexture!==void 0&&i.push(s.assignTexture(t,"transmissionMap",o.transmissionTexture)),Promise.all(i)}}class xt{constructor(e){this.parser=e,this.name=E.KHR_MATERIALS_VOLUME}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:u.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];t.thickness=o.thicknessFactor!==void 0?o.thicknessFactor:0,o.thicknessTexture!==void 0&&i.push(s.assignTexture(t,"thicknessMap",o.thicknessTexture)),t.attenuationDistance=o.attenuationDistance||1/0;const c=o.attenuationColor||[1,1,1];return t.attenuationColor=new u.Color().setRGB(c[0],c[1],c[2],u.LinearSRGBColorSpace),Promise.all(i)}}class Mt{constructor(e){this.parser=e,this.name=E.KHR_MATERIALS_IOR}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:u.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=n.extensions[this.name];return t.ior=i.ior!==void 0?i.ior:1.5,Promise.resolve()}}class Rt{constructor(e){this.parser=e,this.name=E.KHR_MATERIALS_SPECULAR}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:u.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];t.specularIntensity=o.specularFactor!==void 0?o.specularFactor:1,o.specularTexture!==void 0&&i.push(s.assignTexture(t,"specularIntensityMap",o.specularTexture));const c=o.specularColorFactor||[1,1,1];return t.specularColor=new u.Color().setRGB(c[0],c[1],c[2],u.LinearSRGBColorSpace),o.specularColorTexture!==void 0&&i.push(s.assignTexture(t,"specularColorMap",o.specularColorTexture,u.SRGBColorSpace)),Promise.all(i)}}class At{constructor(e){this.parser=e,this.name=E.EXT_MATERIALS_BUMP}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:u.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];return t.bumpScale=o.bumpFactor!==void 0?o.bumpFactor:1,o.bumpTexture!==void 0&&i.push(s.assignTexture(t,"bumpMap",o.bumpTexture)),Promise.all(i)}}class Lt{constructor(e){this.parser=e,this.name=E.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:u.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];return o.anisotropyStrength!==void 0&&(t.anisotropy=o.anisotropyStrength),o.anisotropyRotation!==void 0&&(t.anisotropyRotation=o.anisotropyRotation),o.anisotropyTexture!==void 0&&i.push(s.assignTexture(t,"anisotropyMap",o.anisotropyTexture)),Promise.all(i)}}class Pt{constructor(e){this.parser=e,this.name=E.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,n=s.textures[e];if(!n.extensions||!n.extensions[this.name])return null;const i=n.extensions[this.name],o=t.options.ktx2Loader;if(!o){if(s.extensionsRequired&&s.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,i.source,o)}}class Ct{constructor(e){this.parser=e,this.name=E.EXT_TEXTURE_WEBP}loadTexture(e){const t=this.name,s=this.parser,n=s.json,i=n.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],c=n.images[o.source];let a=s.textureLoader;if(c.uri){const l=s.options.manager.getHandler(c.uri);l!==null&&(a=l)}return s.loadTextureImage(e,o.source,a)}}class Dt{constructor(e){this.parser=e,this.name=E.EXT_TEXTURE_AVIF}loadTexture(e){const t=this.name,s=this.parser,n=s.json,i=n.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],c=n.images[o.source];let a=s.textureLoader;if(c.uri){const l=s.options.manager.getHandler(c.uri);l!==null&&(a=l)}return s.loadTextureImage(e,o.source,a)}}class Ot{constructor(e){this.name=E.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,s=t.bufferViews[e];if(s.extensions&&s.extensions[this.name]){const n=s.extensions[this.name],i=this.parser.getDependency("buffer",n.buffer),o=this.parser.options.meshoptDecoder;if(!o||!o.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return i.then(function(c){const a=n.byteOffset||0,l=n.byteLength||0,d=n.count,h=n.byteStride,g=new Uint8Array(c,a,l);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(d,h,g,n.mode,n.filter).then(function(p){return p.buffer}):o.ready.then(function(){const p=new ArrayBuffer(d*h);return o.decodeGltfBuffer(new Uint8Array(p),d,h,g,n.mode,n.filter),p})})}else return null}}class It{constructor(e){this.name=E.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,s=t.nodes[e];if(!s.extensions||!s.extensions[this.name]||s.mesh===void 0)return null;const n=t.meshes[s.mesh];for(const l of n.primitives)if(l.mode!==O.TRIANGLES&&l.mode!==O.TRIANGLE_STRIP&&l.mode!==O.TRIANGLE_FAN&&l.mode!==void 0)return null;const o=s.extensions[this.name].attributes,c=[],a={};for(const l in o)c.push(this.parser.getDependency("accessor",o[l]).then(d=>(a[l]=d,a[l])));return c.length<1?null:(c.push(this.parser.createNodeMesh(e)),Promise.all(c).then(l=>{const d=l.pop(),h=d.isGroup?d.children:[d],g=l[0].count,p=[];for(const y of h){const _=new u.Matrix4,m=new u.Vector3,f=new u.Quaternion,T=new u.Vector3(1,1,1),w=new u.InstancedMesh(y.geometry,y.material,g);for(let b=0;b<g;b++)a.TRANSLATION&&m.fromBufferAttribute(a.TRANSLATION,b),a.ROTATION&&f.fromBufferAttribute(a.ROTATION,b),a.SCALE&&T.fromBufferAttribute(a.SCALE,b),w.setMatrixAt(b,_.compose(m,f,T));for(const b in a)if(b==="_COLOR_0"){const M=a[b];w.instanceColor=new u.InstancedBufferAttribute(M.array,M.itemSize,M.normalized)}else b!=="TRANSLATION"&&b!=="ROTATION"&&b!=="SCALE"&&y.geometry.setAttribute(b,a[b]);u.Object3D.prototype.copy.call(w,y),this.parser.assignFinalMaterial(w),p.push(w)}return d.isGroup?(d.clear(),d.add(...p),d):p[0]}))}}const Pe="glTF",Y=12,be={JSON:1313821514,BIN:5130562};class kt{constructor(e){this.name=E.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,Y),s=new TextDecoder;if(this.header={magic:s.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==Pe)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const n=this.header.length-Y,i=new DataView(e,Y);let o=0;for(;o<n;){const c=i.getUint32(o,!0);o+=4;const a=i.getUint32(o,!0);if(o+=4,a===be.JSON){const l=new Uint8Array(e,Y+o,c);this.content=s.decode(l)}else if(a===be.BIN){const l=Y+o;this.body=e.slice(l,l+c)}o+=c}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class Nt{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=E.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,n=this.dracoLoader,i=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,c={},a={},l={};for(const d in o){const h=le[d]||d.toLowerCase();c[h]=o[d]}for(const d in e.attributes){const h=le[d]||d.toLowerCase();if(o[d]!==void 0){const g=s.accessors[e.attributes[d]],p=W[g.componentType];l[h]=p.name,a[h]=g.normalized===!0}}return t.getDependency("bufferView",i).then(function(d){return new Promise(function(h,g){n.decodeDracoFile(d,function(p){for(const y in p.attributes){const _=p.attributes[y],m=a[y];m!==void 0&&(_.normalized=m)}h(p)},c,l,u.LinearSRGBColorSpace,g)})})}}class vt{constructor(){this.name=E.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return(t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0||(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),e.needsUpdate=!0),e}}class Ht{constructor(){this.name=E.KHR_MESH_QUANTIZATION}}class Ce extends u.Interpolant{constructor(e,t,s,n){super(e,t,s,n)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,n=this.valueSize,i=e*n*3+n;for(let o=0;o!==n;o++)t[o]=s[i+o];return t}interpolate_(e,t,s,n){const i=this.resultBuffer,o=this.sampleValues,c=this.valueSize,a=c*2,l=c*3,d=n-t,h=(s-t)/d,g=h*h,p=g*h,y=e*l,_=y-l,m=-2*p+3*g,f=p-g,T=1-m,w=f-g+h;for(let b=0;b!==c;b++){const M=o[_+b+c],A=o[_+b+a]*d,L=o[y+b+c],R=o[y+b]*d;i[b]=T*M+w*A+m*L+f*R}return i}}const Ft=new u.Quaternion;class Ut extends Ce{interpolate_(e,t,s,n){const i=super.interpolate_(e,t,s,n);return Ft.fromArray(i).normalize().toArray(i),i}}const O={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},W={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},we={9728:u.NearestFilter,9729:u.LinearFilter,9984:u.NearestMipmapNearestFilter,9985:u.LinearMipmapNearestFilter,9986:u.NearestMipmapLinearFilter,9987:u.LinearMipmapLinearFilter},Ee={33071:u.ClampToEdgeWrapping,33648:u.MirroredRepeatWrapping,10497:u.RepeatWrapping},ie={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},le={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},H={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},jt={CUBICSPLINE:void 0,LINEAR:u.InterpolateLinear,STEP:u.InterpolateDiscrete},oe={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function Gt(r){return r.DefaultMaterial===void 0&&(r.DefaultMaterial=new u.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:u.FrontSide})),r.DefaultMaterial}function j(r,e,t){for(const s in t.extensions)r[s]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[s]=t.extensions[s])}function N(r,e){e.extras!==void 0&&(typeof e.extras=="object"?Object.assign(r.userData,e.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+e.extras))}function Bt(r,e,t){let s=!1,n=!1,i=!1;for(let l=0,d=e.length;l<d;l++){const h=e[l];if(h.POSITION!==void 0&&(s=!0),h.NORMAL!==void 0&&(n=!0),h.COLOR_0!==void 0&&(i=!0),s&&n&&i)break}if(!s&&!n&&!i)return Promise.resolve(r);const o=[],c=[],a=[];for(let l=0,d=e.length;l<d;l++){const h=e[l];if(s){const g=h.POSITION!==void 0?t.getDependency("accessor",h.POSITION):r.attributes.position;o.push(g)}if(n){const g=h.NORMAL!==void 0?t.getDependency("accessor",h.NORMAL):r.attributes.normal;c.push(g)}if(i){const g=h.COLOR_0!==void 0?t.getDependency("accessor",h.COLOR_0):r.attributes.color;a.push(g)}}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(a)]).then(function(l){const d=l[0],h=l[1],g=l[2];return s&&(r.morphAttributes.position=d),n&&(r.morphAttributes.normal=h),i&&(r.morphAttributes.color=g),r.morphTargetsRelative=!0,r})}function zt(r,e){if(r.updateMorphTargets(),e.weights!==void 0)for(let t=0,s=e.weights.length;t<s;t++)r.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){const t=e.extras.targetNames;if(r.morphTargetInfluences.length===t.length){r.morphTargetDictionary={};for(let s=0,n=t.length;s<n;s++)r.morphTargetDictionary[t[s]]=s}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function Kt(r){let e;const t=r.extensions&&r.extensions[E.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+re(t.attributes):e=r.indices+":"+re(r.attributes)+":"+r.mode,r.targets!==void 0)for(let s=0,n=r.targets.length;s<n;s++)e+=":"+re(r.targets[s]);return e}function re(r){let e="";const t=Object.keys(r).sort();for(let s=0,n=t.length;s<n;s++)e+=t[s]+":"+r[t[s]]+";";return e}function he(r){switch(r){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}function Vt(r){return r.search(/\.jpe?g($|\?)/i)>0||r.search(/^data\:image\/jpeg/)===0?"image/jpeg":r.search(/\.webp($|\?)/i)>0||r.search(/^data\:image\/webp/)===0?"image/webp":r.search(/\.ktx2($|\?)/i)>0||r.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}const Wt=new u.Matrix4;class Xt{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new mt,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let s=!1,n=-1,i=!1,o=-1;if(typeof navigator<"u"){const c=navigator.userAgent;s=/^((?!chrome|android).)*safari/i.test(c)===!0;const a=c.match(/Version\/(\d+)/);n=s&&a?parseInt(a[1],10):-1,i=c.indexOf("Firefox")>-1,o=i?c.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||s&&n<17||i&&o<98?this.textureLoader=new u.TextureLoader(this.options.manager):this.textureLoader=new u.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new u.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const s=this,n=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(o){return o._markDefs&&o._markDefs()}),Promise.all(this._invokeAll(function(o){return o.beforeRoot&&o.beforeRoot()})).then(function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])}).then(function(o){const c={scene:o[0][n.scene||0],scenes:o[0],animations:o[1],cameras:o[2],asset:n.asset,parser:s,userData:{}};return j(i,c,n),N(c,n),Promise.all(s._invokeAll(function(a){return a.afterRoot&&a.afterRoot(c)})).then(function(){for(const a of c.scenes)a.updateMatrixWorld();e(c)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],s=this.json.meshes||[];for(let n=0,i=t.length;n<i;n++){const o=t[n].joints;for(let c=0,a=o.length;c<a;c++)e[o[c]].isBone=!0}for(let n=0,i=e.length;n<i;n++){const o=e[n];o.mesh!==void 0&&(this._addNodeRef(this.meshCache,o.mesh),o.skin!==void 0&&(s[o.mesh].isSkinnedMesh=!0)),o.camera!==void 0&&this._addNodeRef(this.cameraCache,o.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,s){if(e.refs[t]<=1)return s;const n=s.clone(),i=(o,c)=>{const a=this.associations.get(o);a!=null&&this.associations.set(c,a);for(const[l,d]of o.children.entries())i(d,c.children[l])};return i(s,n),n.name+="_instance_"+e.uses[t]++,n}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const n=e(t[s]);if(n)return n}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let n=0;n<t.length;n++){const i=e(t[n]);i&&s.push(i)}return s}getDependency(e,t){const s=e+":"+t;let n=this.cache.get(s);if(!n){switch(e){case"scene":n=this.loadScene(t);break;case"node":n=this._invokeOne(function(i){return i.loadNode&&i.loadNode(t)});break;case"mesh":n=this._invokeOne(function(i){return i.loadMesh&&i.loadMesh(t)});break;case"accessor":n=this.loadAccessor(t);break;case"bufferView":n=this._invokeOne(function(i){return i.loadBufferView&&i.loadBufferView(t)});break;case"buffer":n=this.loadBuffer(t);break;case"material":n=this._invokeOne(function(i){return i.loadMaterial&&i.loadMaterial(t)});break;case"texture":n=this._invokeOne(function(i){return i.loadTexture&&i.loadTexture(t)});break;case"skin":n=this.loadSkin(t);break;case"animation":n=this._invokeOne(function(i){return i.loadAnimation&&i.loadAnimation(t)});break;case"camera":n=this.loadCamera(t);break;default:if(n=this._invokeOne(function(i){return i!=this&&i.getDependency&&i.getDependency(e,t)}),!n)throw new Error("Unknown type: "+e);break}this.cache.add(s,n)}return n}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,n=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(n.map(function(i,o){return s.getDependency(e,o)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],s=this.fileLoader;if(t.type&&t.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[E.KHR_BINARY_GLTF].body);const n=this.options;return new Promise(function(i,o){s.load(u.LoaderUtils.resolveURL(t.uri,n.path),i,void 0,function(){o(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))})})}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(s){const n=t.byteLength||0,i=t.byteOffset||0;return s.slice(i,i+n)})}loadAccessor(e){const t=this,s=this.json,n=this.json.accessors[e];if(n.bufferView===void 0&&n.sparse===void 0){const o=ie[n.type],c=W[n.componentType],a=n.normalized===!0,l=new c(n.count*o);return Promise.resolve(new u.BufferAttribute(l,o,a))}const i=[];return n.bufferView!==void 0?i.push(this.getDependency("bufferView",n.bufferView)):i.push(null),n.sparse!==void 0&&(i.push(this.getDependency("bufferView",n.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",n.sparse.values.bufferView))),Promise.all(i).then(function(o){const c=o[0],a=ie[n.type],l=W[n.componentType],d=l.BYTES_PER_ELEMENT,h=d*a,g=n.byteOffset||0,p=n.bufferView!==void 0?s.bufferViews[n.bufferView].byteStride:void 0,y=n.normalized===!0;let _,m;if(p&&p!==h){const f=Math.floor(g/p),T="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+f+":"+n.count;let w=t.cache.get(T);w||(_=new l(c,f*p,n.count*p/d),w=new u.InterleavedBuffer(_,p/d),t.cache.add(T,w)),m=new u.InterleavedBufferAttribute(w,a,g%p/d,y)}else c===null?_=new l(n.count*a):_=new l(c,g,n.count*a),m=new u.BufferAttribute(_,a,y);if(n.sparse!==void 0){const f=ie.SCALAR,T=W[n.sparse.indices.componentType],w=n.sparse.indices.byteOffset||0,b=n.sparse.values.byteOffset||0,M=new T(o[1],w,n.sparse.count*f),A=new l(o[2],b,n.sparse.count*a);c!==null&&(m=new u.BufferAttribute(m.array.slice(),m.itemSize,m.normalized)),m.normalized=!1;for(let L=0,R=M.length;L<R;L++){const C=M[L];if(m.setX(C,A[L*a]),a>=2&&m.setY(C,A[L*a+1]),a>=3&&m.setZ(C,A[L*a+2]),a>=4&&m.setW(C,A[L*a+3]),a>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}m.normalized=y}return m})}loadTexture(e){const t=this.json,s=this.options,i=t.textures[e].source,o=t.images[i];let c=this.textureLoader;if(o.uri){const a=s.manager.getHandler(o.uri);a!==null&&(c=a)}return this.loadTextureImage(e,i,c)}loadTextureImage(e,t,s){const n=this,i=this.json,o=i.textures[e],c=i.images[t],a=(c.uri||c.bufferView)+":"+o.sampler;if(this.textureCache[a])return this.textureCache[a];const l=this.loadImageSource(t,s).then(function(d){d.flipY=!1,d.name=o.name||c.name||"",d.name===""&&typeof c.uri=="string"&&c.uri.startsWith("data:image/")===!1&&(d.name=c.uri);const g=(i.samplers||{})[o.sampler]||{};return d.magFilter=we[g.magFilter]||u.LinearFilter,d.minFilter=we[g.minFilter]||u.LinearMipmapLinearFilter,d.wrapS=Ee[g.wrapS]||u.RepeatWrapping,d.wrapT=Ee[g.wrapT]||u.RepeatWrapping,d.generateMipmaps=!d.isCompressedTexture&&d.minFilter!==u.NearestFilter&&d.minFilter!==u.LinearFilter,n.associations.set(d,{textures:e}),d}).catch(function(){return null});return this.textureCache[a]=l,l}loadImageSource(e,t){const s=this,n=this.json,i=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(h=>h.clone());const o=n.images[e],c=self.URL||self.webkitURL;let a=o.uri||"",l=!1;if(o.bufferView!==void 0)a=s.getDependency("bufferView",o.bufferView).then(function(h){l=!0;const g=new Blob([h],{type:o.mimeType});return a=c.createObjectURL(g),a});else if(o.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const d=Promise.resolve(a).then(function(h){return new Promise(function(g,p){let y=g;t.isImageBitmapLoader===!0&&(y=function(_){const m=new u.Texture(_);m.needsUpdate=!0,g(m)}),t.load(u.LoaderUtils.resolveURL(h,i.path),y,void 0,p)})}).then(function(h){return l===!0&&c.revokeObjectURL(a),N(h,o),h.userData.mimeType=o.mimeType||Vt(o.uri),h}).catch(function(h){throw console.error("THREE.GLTFLoader: Couldn't load texture",a),h});return this.sourceCache[e]=d,d}assignTexture(e,t,s,n){const i=this;return this.getDependency("texture",s.index).then(function(o){if(!o)return null;if(s.texCoord!==void 0&&s.texCoord>0&&(o=o.clone(),o.channel=s.texCoord),i.extensions[E.KHR_TEXTURE_TRANSFORM]){const c=s.extensions!==void 0?s.extensions[E.KHR_TEXTURE_TRANSFORM]:void 0;if(c){const a=i.associations.get(o);o=i.extensions[E.KHR_TEXTURE_TRANSFORM].extendTexture(o,c),i.associations.set(o,a)}}return n!==void 0&&(o.colorSpace=n),e[t]=o,o})}assignFinalMaterial(e){const t=e.geometry;let s=e.material;const n=t.attributes.tangent===void 0,i=t.attributes.color!==void 0,o=t.attributes.normal===void 0;if(e.isPoints){const c="PointsMaterial:"+s.uuid;let a=this.cache.get(c);a||(a=new u.PointsMaterial,u.Material.prototype.copy.call(a,s),a.color.copy(s.color),a.map=s.map,a.sizeAttenuation=!1,this.cache.add(c,a)),s=a}else if(e.isLine){const c="LineBasicMaterial:"+s.uuid;let a=this.cache.get(c);a||(a=new u.LineBasicMaterial,u.Material.prototype.copy.call(a,s),a.color.copy(s.color),a.map=s.map,this.cache.add(c,a)),s=a}if(n||i||o){let c="ClonedMaterial:"+s.uuid+":";n&&(c+="derivative-tangents:"),i&&(c+="vertex-colors:"),o&&(c+="flat-shading:");let a=this.cache.get(c);a||(a=s.clone(),i&&(a.vertexColors=!0),o&&(a.flatShading=!0),n&&(a.normalScale&&(a.normalScale.y*=-1),a.clearcoatNormalScale&&(a.clearcoatNormalScale.y*=-1)),this.cache.add(c,a),this.associations.set(a,this.associations.get(s))),s=a}e.material=s}getMaterialType(){return u.MeshStandardMaterial}loadMaterial(e){const t=this,s=this.json,n=this.extensions,i=s.materials[e];let o;const c={},a=i.extensions||{},l=[];if(a[E.KHR_MATERIALS_UNLIT]){const h=n[E.KHR_MATERIALS_UNLIT];o=h.getMaterialType(),l.push(h.extendParams(c,i,t))}else{const h=i.pbrMetallicRoughness||{};if(c.color=new u.Color(1,1,1),c.opacity=1,Array.isArray(h.baseColorFactor)){const g=h.baseColorFactor;c.color.setRGB(g[0],g[1],g[2],u.LinearSRGBColorSpace),c.opacity=g[3]}h.baseColorTexture!==void 0&&l.push(t.assignTexture(c,"map",h.baseColorTexture,u.SRGBColorSpace)),c.metalness=h.metallicFactor!==void 0?h.metallicFactor:1,c.roughness=h.roughnessFactor!==void 0?h.roughnessFactor:1,h.metallicRoughnessTexture!==void 0&&(l.push(t.assignTexture(c,"metalnessMap",h.metallicRoughnessTexture)),l.push(t.assignTexture(c,"roughnessMap",h.metallicRoughnessTexture))),o=this._invokeOne(function(g){return g.getMaterialType&&g.getMaterialType(e)}),l.push(Promise.all(this._invokeAll(function(g){return g.extendMaterialParams&&g.extendMaterialParams(e,c)})))}i.doubleSided===!0&&(c.side=u.DoubleSide);const d=i.alphaMode||oe.OPAQUE;if(d===oe.BLEND?(c.transparent=!0,c.depthWrite=!1):(c.transparent=!1,d===oe.MASK&&(c.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture!==void 0&&o!==u.MeshBasicMaterial&&(l.push(t.assignTexture(c,"normalMap",i.normalTexture)),c.normalScale=new u.Vector2(1,1),i.normalTexture.scale!==void 0)){const h=i.normalTexture.scale;c.normalScale.set(h,h)}if(i.occlusionTexture!==void 0&&o!==u.MeshBasicMaterial&&(l.push(t.assignTexture(c,"aoMap",i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(c.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&o!==u.MeshBasicMaterial){const h=i.emissiveFactor;c.emissive=new u.Color().setRGB(h[0],h[1],h[2],u.LinearSRGBColorSpace)}return i.emissiveTexture!==void 0&&o!==u.MeshBasicMaterial&&l.push(t.assignTexture(c,"emissiveMap",i.emissiveTexture,u.SRGBColorSpace)),Promise.all(l).then(function(){const h=new o(c);return i.name&&(h.name=i.name),N(h,i),t.associations.set(h,{materials:e}),i.extensions&&j(n,h,i),h})}createUniqueName(e){const t=u.PropertyBinding.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,s=this.extensions,n=this.primitiveCache;function i(c){return s[E.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(c,t).then(function(a){return Se(a,c,t)})}const o=[];for(let c=0,a=e.length;c<a;c++){const l=e[c],d=Kt(l),h=n[d];if(h)o.push(h.promise);else{let g;l.extensions&&l.extensions[E.KHR_DRACO_MESH_COMPRESSION]?g=i(l):g=Se(new u.BufferGeometry,l,t),n[d]={primitive:l,promise:g},o.push(g)}}return Promise.all(o)}loadMesh(e){const t=this,s=this.json,n=this.extensions,i=s.meshes[e],o=i.primitives,c=[];for(let a=0,l=o.length;a<l;a++){const d=o[a].material===void 0?Gt(this.cache):this.getDependency("material",o[a].material);c.push(d)}return c.push(t.loadGeometries(o)),Promise.all(c).then(function(a){const l=a.slice(0,a.length-1),d=a[a.length-1],h=[];for(let p=0,y=d.length;p<y;p++){const _=d[p],m=o[p];let f;const T=l[p];if(m.mode===O.TRIANGLES||m.mode===O.TRIANGLE_STRIP||m.mode===O.TRIANGLE_FAN||m.mode===void 0)f=i.isSkinnedMesh===!0?new u.SkinnedMesh(_,T):new u.Mesh(_,T),f.isSkinnedMesh===!0&&f.normalizeSkinWeights(),m.mode===O.TRIANGLE_STRIP?f.geometry=Te(f.geometry,u.TriangleStripDrawMode):m.mode===O.TRIANGLE_FAN&&(f.geometry=Te(f.geometry,u.TriangleFanDrawMode));else if(m.mode===O.LINES)f=new u.LineSegments(_,T);else if(m.mode===O.LINE_STRIP)f=new u.Line(_,T);else if(m.mode===O.LINE_LOOP)f=new u.LineLoop(_,T);else if(m.mode===O.POINTS)f=new u.Points(_,T);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+m.mode);Object.keys(f.geometry.morphAttributes).length>0&&zt(f,i),f.name=t.createUniqueName(i.name||"mesh_"+e),N(f,i),m.extensions&&j(n,f,m),t.assignFinalMaterial(f),h.push(f)}for(let p=0,y=h.length;p<y;p++)t.associations.set(h[p],{meshes:e,primitives:p});if(h.length===1)return i.extensions&&j(n,h[0],i),h[0];const g=new u.Group;i.extensions&&j(n,g,i),t.associations.set(g,{meshes:e});for(let p=0,y=h.length;p<y;p++)g.add(h[p]);return g})}loadCamera(e){let t;const s=this.json.cameras[e],n=s[s.type];if(!n){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return s.type==="perspective"?t=new u.PerspectiveCamera(u.MathUtils.radToDeg(n.yfov),n.aspectRatio||1,n.znear||1,n.zfar||2e6):s.type==="orthographic"&&(t=new u.OrthographicCamera(-n.xmag,n.xmag,n.ymag,-n.ymag,n.znear,n.zfar)),s.name&&(t.name=this.createUniqueName(s.name)),N(t,s),Promise.resolve(t)}loadSkin(e){const t=this.json.skins[e],s=[];for(let n=0,i=t.joints.length;n<i;n++)s.push(this._loadNodeShallow(t.joints[n]));return t.inverseBindMatrices!==void 0?s.push(this.getDependency("accessor",t.inverseBindMatrices)):s.push(null),Promise.all(s).then(function(n){const i=n.pop(),o=n,c=[],a=[];for(let l=0,d=o.length;l<d;l++){const h=o[l];if(h){c.push(h);const g=new u.Matrix4;i!==null&&g.fromArray(i.array,l*16),a.push(g)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[l])}return new u.Skeleton(c,a)})}loadAnimation(e){const t=this.json,s=this,n=t.animations[e],i=n.name?n.name:"animation_"+e,o=[],c=[],a=[],l=[],d=[];for(let h=0,g=n.channels.length;h<g;h++){const p=n.channels[h],y=n.samplers[p.sampler],_=p.target,m=_.node,f=n.parameters!==void 0?n.parameters[y.input]:y.input,T=n.parameters!==void 0?n.parameters[y.output]:y.output;_.node!==void 0&&(o.push(this.getDependency("node",m)),c.push(this.getDependency("accessor",f)),a.push(this.getDependency("accessor",T)),l.push(y),d.push(_))}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(a),Promise.all(l),Promise.all(d)]).then(function(h){const g=h[0],p=h[1],y=h[2],_=h[3],m=h[4],f=[];for(let T=0,w=g.length;T<w;T++){const b=g[T],M=p[T],A=y[T],L=_[T],R=m[T];if(b===void 0)continue;b.updateMatrix&&b.updateMatrix();const C=s._createAnimationTracks(b,M,A,L,R);if(C)for(let k=0;k<C.length;k++)f.push(C[k])}return new u.AnimationClip(i,void 0,f)})}createNodeMesh(e){const t=this.json,s=this,n=t.nodes[e];return n.mesh===void 0?null:s.getDependency("mesh",n.mesh).then(function(i){const o=s._getNodeRef(s.meshCache,n.mesh,i);return n.weights!==void 0&&o.traverse(function(c){if(c.isMesh)for(let a=0,l=n.weights.length;a<l;a++)c.morphTargetInfluences[a]=n.weights[a]}),o})}loadNode(e){const t=this.json,s=this,n=t.nodes[e],i=s._loadNodeShallow(e),o=[],c=n.children||[];for(let l=0,d=c.length;l<d;l++)o.push(s.getDependency("node",c[l]));const a=n.skin===void 0?Promise.resolve(null):s.getDependency("skin",n.skin);return Promise.all([i,Promise.all(o),a]).then(function(l){const d=l[0],h=l[1],g=l[2];g!==null&&d.traverse(function(p){p.isSkinnedMesh&&p.bind(g,Wt)});for(let p=0,y=h.length;p<y;p++)d.add(h[p]);return d})}_loadNodeShallow(e){const t=this.json,s=this.extensions,n=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];const i=t.nodes[e],o=i.name?n.createUniqueName(i.name):"",c=[],a=n._invokeOne(function(l){return l.createNodeMesh&&l.createNodeMesh(e)});return a&&c.push(a),i.camera!==void 0&&c.push(n.getDependency("camera",i.camera).then(function(l){return n._getNodeRef(n.cameraCache,i.camera,l)})),n._invokeAll(function(l){return l.createNodeAttachment&&l.createNodeAttachment(e)}).forEach(function(l){c.push(l)}),this.nodeCache[e]=Promise.all(c).then(function(l){let d;if(i.isBone===!0?d=new u.Bone:l.length>1?d=new u.Group:l.length===1?d=l[0]:d=new u.Object3D,d!==l[0])for(let h=0,g=l.length;h<g;h++)d.add(l[h]);if(i.name&&(d.userData.name=i.name,d.name=o),N(d,i),i.extensions&&j(s,d,i),i.matrix!==void 0){const h=new u.Matrix4;h.fromArray(i.matrix),d.applyMatrix4(h)}else i.translation!==void 0&&d.position.fromArray(i.translation),i.rotation!==void 0&&d.quaternion.fromArray(i.rotation),i.scale!==void 0&&d.scale.fromArray(i.scale);if(!n.associations.has(d))n.associations.set(d,{});else if(i.mesh!==void 0&&n.meshCache.refs[i.mesh]>1){const h=n.associations.get(d);n.associations.set(d,{...h})}return n.associations.get(d).nodes=e,d}),this.nodeCache[e]}loadScene(e){const t=this.extensions,s=this.json.scenes[e],n=this,i=new u.Group;s.name&&(i.name=n.createUniqueName(s.name)),N(i,s),s.extensions&&j(t,i,s);const o=s.nodes||[],c=[];for(let a=0,l=o.length;a<l;a++)c.push(n.getDependency("node",o[a]));return Promise.all(c).then(function(a){for(let d=0,h=a.length;d<h;d++)i.add(a[d]);const l=d=>{const h=new Map;for(const[g,p]of n.associations)(g instanceof u.Material||g instanceof u.Texture)&&h.set(g,p);return d.traverse(g=>{const p=n.associations.get(g);p!=null&&h.set(g,p)}),h};return n.associations=l(i),i})}_createAnimationTracks(e,t,s,n,i){const o=[],c=e.name?e.name:e.uuid,a=[];H[i.path]===H.weights?e.traverse(function(g){g.morphTargetInfluences&&a.push(g.name?g.name:g.uuid)}):a.push(c);let l;switch(H[i.path]){case H.weights:l=u.NumberKeyframeTrack;break;case H.rotation:l=u.QuaternionKeyframeTrack;break;case H.translation:case H.scale:l=u.VectorKeyframeTrack;break;default:switch(s.itemSize){case 1:l=u.NumberKeyframeTrack;break;case 2:case 3:default:l=u.VectorKeyframeTrack;break}break}const d=n.interpolation!==void 0?jt[n.interpolation]:u.InterpolateLinear,h=this._getArrayFromAccessor(s);for(let g=0,p=a.length;g<p;g++){const y=new l(a[g]+"."+H[i.path],t.array,h,d);n.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(y),o.push(y)}return o}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const s=he(t.constructor),n=new Float32Array(t.length);for(let i=0,o=t.length;i<o;i++)n[i]=t[i]*s;t=n}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(s){const n=this instanceof u.QuaternionKeyframeTrack?Ut:Ce;return new n(this.times,this.values,this.getValueSize()/3,s)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function Yt(r,e,t){const s=e.attributes,n=new u.Box3;if(s.POSITION!==void 0){const c=t.json.accessors[s.POSITION],a=c.min,l=c.max;if(a!==void 0&&l!==void 0){if(n.set(new u.Vector3(a[0],a[1],a[2]),new u.Vector3(l[0],l[1],l[2])),c.normalized){const d=he(W[c.componentType]);n.min.multiplyScalar(d),n.max.multiplyScalar(d)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const i=e.targets;if(i!==void 0){const c=new u.Vector3,a=new u.Vector3;for(let l=0,d=i.length;l<d;l++){const h=i[l];if(h.POSITION!==void 0){const g=t.json.accessors[h.POSITION],p=g.min,y=g.max;if(p!==void 0&&y!==void 0){if(a.setX(Math.max(Math.abs(p[0]),Math.abs(y[0]))),a.setY(Math.max(Math.abs(p[1]),Math.abs(y[1]))),a.setZ(Math.max(Math.abs(p[2]),Math.abs(y[2]))),g.normalized){const _=he(W[g.componentType]);a.multiplyScalar(_)}c.max(a)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}n.expandByVector(c)}r.boundingBox=n;const o=new u.Sphere;n.getCenter(o.center),o.radius=n.min.distanceTo(n.max)/2,r.boundingSphere=o}function Se(r,e,t){const s=e.attributes,n=[];function i(o,c){return t.getDependency("accessor",o).then(function(a){r.setAttribute(c,a)})}for(const o in s){const c=le[o]||o.toLowerCase();c in r.attributes||n.push(i(s[o],c))}if(e.indices!==void 0&&!r.index){const o=t.getDependency("accessor",e.indices).then(function(c){r.setIndex(c)});n.push(o)}return u.ColorManagement.workingColorSpace!==u.LinearSRGBColorSpace&&"COLOR_0"in s&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${u.ColorManagement.workingColorSpace}" not supported.`),N(r,e),Yt(r,e,t),Promise.all(n).then(function(){return e.targets!==void 0?Bt(r,e.targets,t):r})}const De=r=>{r.geometry&&r.geometry.dispose(),r.material&&(Array.isArray(r.material)?r.material.forEach(e=>{xe(e)}):xe(r.material)),r.children&&r.children.forEach(e=>De(e))};function xe(r){for(const e in r)r[e]&&r[e].isTexture&&r[e].dispose();r.dispose()}const ae={};async function qt(r,e=50){const t={type:r.type,name:r.name,position:r.position.toArray(),rotation:r.rotation.toArray(),scale:r.scale.toArray(),visible:r.visible,children:[],geometry:null,material:null,userData:r.userData};r.isMesh&&(t.geometry=Q(r.geometry),t.material=ee(r.material));const s=[{object:r,parentData:t}];let n=0;for(;s.length>0;){const{object:i,parentData:o}=s.pop();for(const c of i.children){const a={type:c.type,name:c.name,position:c.position.toArray(),rotation:c.rotation.toArray(),scale:c.scale.toArray(),visible:c.visible,children:[],geometry:null,material:null,userData:c.userData};c.isMesh&&(a.geometry=Q(c.geometry),a.material=ee(c.material)),o.children.push(a),s.push({object:c,parentData:a}),n++,n%e===0&&await new Promise(l=>requestAnimationFrame(l))}}return t}function Zt(r){const e={type:r.type,name:r.name,position:r.position.toArray(),rotation:r.rotation.toArray(),scale:r.scale.toArray(),visible:r.visible,children:[],geometry:null,material:null,userData:r.userData};r.isMesh&&(e.geometry=Q(r.geometry),e.material=ee(r.material));const t=[{object:r,parentData:e}];for(;t.length>0;){const{object:s,parentData:n}=t.pop();for(const i of s.children){const o={type:i.type,name:i.name,position:i.position.toArray(),rotation:i.rotation.toArray(),scale:i.scale.toArray(),visible:i.visible,children:[],geometry:null,material:null,userData:i.userData};i.isMesh&&(o.geometry=Q(i.geometry),o.material=ee(i.material)),n.children.push(o),t.push({object:i,parentData:o})}}return e}async function Oe(r,e=50){const t=[];let s;switch(r.type){case"Mesh":const i=J(r.geometry),o=te(r.material);s=new S.Mesh(i,o);break;case"Group":s=new S.Group;break;case"Object3D":s=new S.Object3D;break;default:return console.warn(`Unsupported object type: ${r.type}`),null}s.name=r.name,s.position.fromArray(r.position),s.rotation.fromArray(r.rotation),s.scale.fromArray(r.scale),s.visible=r.visible,s.userData=r.userData,t.push({data:r,object:s});let n=0;for(;t.length>0;){const{data:i,object:o}=t.pop();for(const c of[...i.children].reverse()){let a;switch(c.type){case"Mesh":const l=J(c.geometry),d=te(c.material);a=new S.Mesh(l,d);break;case"Group":a=new S.Group;break;case"Object3D":a=new S.Object3D;break;default:console.warn(`Unsupported object type: ${c.type}`);continue}a&&(a.name=c.name,a.position.fromArray(c.position),a.rotation.fromArray(c.rotation),a.scale.fromArray(c.scale),a.visible=c.visible,a.userData=c.userData,o.add(a),t.push({data:c,object:a}),n++,n%e===0&&await new Promise(l=>requestAnimationFrame(l)))}}return s}function $t(r){const e=[];let t;switch(r.type){case"Mesh":const s=J(r.geometry),n=te(r.material);t=new S.Mesh(s,n);break;case"Group":t=new S.Group;break;case"Object3D":t=new S.Object3D;break;default:return console.warn(`Unsupported object type: ${r.type}`),null}for(t.name=r.name,t.position.fromArray(r.position),t.rotation.fromArray(r.rotation),t.scale.fromArray(r.scale),t.visible=r.visible,t.userData=r.userData,e.push({data:r,object:t});e.length>0;){const{data:s,object:n}=e.pop();for(const i of[...s.children].reverse()){let o;switch(i.type){case"Mesh":const c=J(i.geometry),a=te(i.material);o=new S.Mesh(c,a);break;case"Group":o=new S.Group;break;case"Object3D":o=new S.Object3D;break;default:console.warn(`Unsupported object type: ${i.type}`);continue}o&&(o.name=i.name,o.position.fromArray(i.position),o.rotation.fromArray(i.rotation),o.scale.fromArray(i.scale),o.visible=i.visible,o.userData=i.userData,n.add(o),e.push({data:i,object:o}))}}return t}function Q(r){const e={},{attributes:t,index:s,type:n}=r;t.position&&(e.position={type:"Float32Array",array:Array.from(t.position.array),itemSize:3}),t.normal&&(e.normal={type:"Float32Array",array:Array.from(t.normal.array),itemSize:3}),t.uv&&(e.uv={type:"Float32Array",array:Array.from(t.uv.array),itemSize:2});const i={type:n,attributes:e};return s&&s.array&&(i.index={type:"Uint32Array",array:Array.from(s.array),itemSize:1}),i}function J(r){const{type:e,attributes:t,index:s}=r,n=new S.BufferGeometry;for(const i in t)if(t.hasOwnProperty(i)){const{type:o,array:c,itemSize:a}=t[i];n.setAttribute(i,new S.BufferAttribute(new Float32Array(c),a))}return s&&n.setIndex(s.array),n}function ee(r){return{type:r.type,color:r.color.getHex(),map:r.map?r.map.image.src:null,opacity:r.opacity,name:r.name,depthTest:r.depthTest,depthWrite:r.depthWrite,transparent:r.transparent,side:r.side,roughness:r.roughness,metalness:r.metalness,emissive:r.emissive.getHex()}}function te(r){if(ae[r.name])return ae[r.name];const{type:e,...t}=r,s=e||"MeshStandardMaterial",n=new S[s]({...t});if(r.map){const i=new S.TextureLoader().load(r.map);n.map=i}return n.needsUpdate=!0,ae[r.name]=n,n}class Ie{constructor(){this.stats={hits:0,misses:0,totalLoadTime:0,cacheSaveTime:0,errors:0},this.loadHistory=[]}recordHit(e){this.stats.hits++,this.stats.totalLoadTime+=e,this._recordHistory("hit",e)}recordMiss(e){this.stats.misses++,this.stats.totalLoadTime+=e,this._recordHistory("miss",e)}recordCacheSave(e){this.stats.cacheSaveTime+=e}recordError(e,t){this.stats.errors++,this._recordHistory("error",0,{path:e,error:t.message})}getHitRate(){const e=this.stats.hits+this.stats.misses;return e>0?(this.stats.hits/e*100).toFixed(2)+"%":"0%"}getAvgLoadTime(){const e=this.stats.hits+this.stats.misses;return e>0?(this.stats.totalLoadTime/e).toFixed(2)+"ms":"0ms"}getStats(){const e=this.stats.hits+this.stats.misses;return{命中率:this.getHitRate(),平均加载时间:this.getAvgLoadTime(),缓存命中数:this.stats.hits,缓存未命中数:this.stats.misses,总加载次数:e,总加载时间:this.stats.totalLoadTime.toFixed(2)+"ms",缓存保存时间:this.stats.cacheSaveTime.toFixed(2)+"ms",错误次数:this.stats.errors}}getHistory(e=10){return this.loadHistory.slice(-e)}reset(){this.stats={hits:0,misses:0,totalLoadTime:0,cacheSaveTime:0,errors:0},this.loadHistory=[]}_recordHistory(e,t,s={}){this.loadHistory.push({type:e,duration:t,timestamp:Date.now(),...s}),this.loadHistory.length>100&&this.loadHistory.shift()}logReport(){console.group("📊 缓存性能报告");const e=this.getStats();Object.entries(e).forEach(([t,s])=>{console.log(`${t}: ${s}`)}),console.groupEnd()}}const U=new Ie;class q{static async retry(e,t={}){const{maxRetries:s=3,initialDelay:n=1e3,maxDelay:i=1e4,backoffFactor:o=2,shouldRetry:c=q.defaultShouldRetry}=t;let a,l=n;for(let d=0;d<=s;d++)try{return await e()}catch(h){if(a=h,d===s||!c(h,d))throw h;console.warn(`[ RetryHelper ] 操作失败,第 ${d+1} 次尝试失败,${l}ms 后进行第 ${d+2} 次尝试...`,h),await q.delay(l),l=Math.min(l*o,i)}throw a}static defaultShouldRetry(e,t){if(e.name==="TypeError"&&e.message.includes("fetch"))return!0;if(e.message.includes("HTTP error")){const s=e.message.match(/status:\s*(\d+)/);if(s){const n=parseInt(s[1],10);return n>=500||n===429||n===408}}return!1}static delay(e){return new Promise(t=>setTimeout(t,e))}}const $={NETWORK:"NETWORK",PARSE:"PARSE",VERSION_MISMATCH:"VERSION",UNKNOWN:"UNKNOWN"};class X extends Error{constructor(e,t,s,n){super(e),this.name="ModelLoadError",this.type=t,this.path=s,this.originalError=n,this.timestamp=Date.now()}static networkError(e,t){return new X(`网络加载失败: ${e}`,$.NETWORK,e,t)}static parseError(e,t){return new X(`模型解析失败: ${e}`,$.PARSE,e,t)}static versionMismatchError(e,t,s){return new X(`版本不匹配: ${e} (期望: ${t}, 实际: ${s})`,$.VERSION_MISMATCH,e)}}const Me=4;class ue{constructor(e="threeJsIDBCache",t={}){this.version=Me,this.dbName=e,this.options={maxSize:t.maxSize||500*1024*1024,maxEntries:t.maxEntries||50,evictRatio:t.evictRatio||.2},this.dbInit()}dbInit(){this.db=new ve(this.dbName),this.db.version(this.version).stores({models:"&path, version, timestamp, accessCount, size"}).upgrade(async e=>{console.log("[ IDBCache 版本更新 ] ====> version",Me);const t=e.table("models"),s=await t.toArray();for(const n of s)n.data instanceof ArrayBuffer||await t.delete(n.path)})}getDatabase(){return this.db}async saveModel(e,t,s){await this.ensureCapacity(s.byteLength),await this.db.table("models").put({path:e,version:t,data:s,size:s.byteLength,timestamp:Date.now(),accessCount:0})}async ensureCapacity(e){const t=await this.db.table("models").toArray(),s=t.reduce((c,a)=>c+(a.size||0),0),n=t.length,i=s+e>this.options.maxSize,o=n>=this.options.maxEntries;(i||o)&&(console.log(`[ IDBCache ] ====> 容量不足,开始 LRU 淘汰. 总大小: ${(s/1024/1024).toFixed(2)}MB, 条目数: ${n}`),await this.evictLRU(t))}async evictLRU(e){const t=e.sort((c,a)=>(c.accessCount||0)!==(a.accessCount||0)?(c.accessCount||0)-(a.accessCount||0):(c.timestamp||0)-(a.timestamp||0)),s=Math.max(1,Math.floor(t.length*this.options.evictRatio)),n=t.slice(0,s),i=n.map(c=>c.path);await this.db.table("models").bulkDelete(i);const o=n.reduce((c,a)=>c+(a.size||0),0);console.log(`[ IDBCache ] ====> LRU 淘汰完成. 删除 ${s} 个条目,释放 ${(o/1024/1024).toFixed(2)}MB`)}async getModel(e,t){const s=await this.db.table("models").get(e);return s?s.version!==t?(console.log("模型版本不一致, 清除当前记录"),await this.db.table("models").delete(e),null):(await this.db.table("models").update(e,{accessCount:(s.accessCount||0)+1,timestamp:Date.now()}),s.data):(console.warn(`Model "${e}" not found in table models`),null)}async cacheModel(e,t,s){console.log("[ ] ====> path, modelData, version",e,t,s);try{this.db.table("models").put({version:s,path:e,data:t}).then(()=>{console.log(`Model "${e}" cached successfully in table models`)})}catch{console.log(" 缓存模型失败 =====> ")}return t}async loadCachedModel(e,t){let s=null;try{if(s=await this.db.table("models").get(e),!s)return console.warn(`Model "${t}" not found in table models`),null;if(s.version!==t)return console.log(" =====> 模型版本不一致, 清除当前记录"),await this.db.table("models").delete(e),null}catch{return console.log(" =====> 查询表中模型失败"),this.db.delete().then(()=>{this.init()}),null}return s.data}async getStats(){const e=await this.db.table("models").toArray(),t=e.reduce((n,i)=>n+(i.size||0),0),s=e.reduce((n,i)=>n+(i.accessCount||0),0);return{count:e.length,totalSize:t,totalSizeMB:(t/1024/1024).toFixed(2),maxEntries:this.options.maxEntries,maxSizeMB:(this.options.maxSize/1024/1024).toFixed(2),usagePercentage:(t/this.options.maxSize*100).toFixed(2),totalAccessCount:s,avgAccessCount:e.length>0?(s/e.length).toFixed(2):0}}async clear(){await this.db.table("models").clear(),console.log("[ IDBCache ] ====> 缓存已清空")}async deleteModel(e){await this.db.table("models").delete(e)}}function fe(r){const{geometries:e,materials:t,hierarchy:s}=r,n=new Map;e.forEach((a,l)=>{const d=Qt(a);n.set(l,d)});const i=new Map;t.forEach((a,l)=>{const d=Jt(a);i.set(l,d)});const o=new S.Group;o.name="Scene";const c=new Map;return s.forEach(a=>{let l;if(a.type==="Mesh"){const d=a.geometryIndex>=0?n.get(a.geometryIndex):null,h=a.materialIndex>=0?i.get(a.materialIndex):null;l=new S.Mesh(d,h)}else a.type==="Group"?l=new S.Group:a.type==="Object3D"?l=new S.Object3D:l=new S.Object3D;l.name=a.name,l.position.fromArray(a.position),l.rotation.fromArray(a.rotation),l.scale.fromArray(a.scale),l.visible=a.visible,c.set(a.id,l)}),s.forEach(a=>{const l=c.get(a.id);if(a.parentId!==null){const d=c.get(a.parentId);d&&d.add(l)}else o.add(l)}),o}function Qt(r){const e=new S.BufferGeometry;for(const t in r.attributes){const s=r.attributes[t],n=s.array;let i;if(n.byteLength===0){console.warn(`[ sceneRebuilder ] 属性 ${t} 的数组为空`);continue}if(n.buffer&&n.buffer.byteLength===0){console.warn(`[ sceneRebuilder ] 属性 ${t} 的 buffer 已被转移,尝试重建`);continue}i=n;const o=new S.BufferAttribute(i,s.itemSize);o.normalized=s.normalized,e.setAttribute(t,o)}if(r.index){const t=r.index,s=t.array;if(s&&s.byteLength>0){const n=new S.BufferAttribute(s,t.itemSize);e.setIndex(n)}}return e}function Jt(r){let e;const t={color:r.color!==void 0?r.color:16777215,opacity:r.opacity!==void 0?r.opacity:1,transparent:r.transparent!==void 0?r.transparent:!1,alphaTest:r.alphaTest!==void 0?r.alphaTest:0,side:r.side!==void 0?r.side:S.FrontSide,depthTest:r.depthTest!==void 0?r.depthTest:!0,depthWrite:r.depthWrite!==void 0?r.depthWrite:!0,wireframe:r.wireframe!==void 0?r.wireframe:!1,vertexColors:r.vertexColors!==void 0?r.vertexColors:!1};switch(r.type){case"MeshStandardMaterial":e=new S.MeshStandardMaterial({...t,roughness:r.roughness!==void 0?r.roughness:.5,metalness:r.metalness!==void 0?r.metalness:.5,emissive:r.emissive!==void 0?r.emissive:0,emissiveIntensity:r.emissiveIntensity!==void 0?r.emissiveIntensity:1});break;case"MeshBasicMaterial":e=new S.MeshBasicMaterial({...t});break;case"MeshPhongMaterial":e=new S.MeshPhongMaterial({...t,shininess:r.shininess!==void 0?r.shininess:30,specular:r.specular!==void 0?r.specular:1118481,emissive:r.emissive!==void 0?r.emissive:0,emissiveIntensity:r.emissiveIntensity!==void 0?r.emissiveIntensity:1});break;default:e=new S.MeshStandardMaterial(t)}return e.uuid=r.uuid,e}class es{constructor(){this.geometries=[],this.materials=[],this.hierarchy=[],this.geometryMap=new Map,this.materialMap=new Map}addChunk(e){e.geometries&&e.geometries.forEach(t=>{const s=this.geometries.length;this.geometries.push(t),this.geometryMap.set(t.uuid,s)}),e.materials&&e.materials.forEach(t=>{const s=this.materials.length;this.materials.push(t),this.materialMap.set(t.uuid,s)}),e.hierarchy&&this.hierarchy.push(...e.hierarchy)}buildCurrent(){const e={geometries:this.geometries,materials:this.materials,hierarchy:this.hierarchy};return fe(e)}finalize(){return this.buildCurrent()}}const ts="/assets/gltfParser.worker-Bqz8BBJx.js",ss="/assets/gltfParserOptimized.worker-DfipxPjm.js";let B;const ce="/draco/";let z,K,Re=0;const F=new Map,ke=()=>{const r=new pt,e=new dt;e.setDecoderPath(ce),r.setDRACOLoader(e);function t(p,y,_,m){return r.load(p,y,_,m)}function s(p,y){return new Promise((_,m)=>{r.load(p,_,y,m)})}async function n(p,y,_,m={}){const f=performance.now();let T=!1;const{maxRetries:w=3,optimizeMaterials:b=!1,simplifyGeometry:M=!1,simplifyRatio:A=.5,simplifyOptions:L={}}=m;try{let R=await o(p,y);if(R)console.log(`[ asyncFetch ] ====> 缓存命中: ${p}`),T=!0;else{console.log(`[ asyncFetch ] ====> 缓存未命中: ${p}`),console.time("[ fetchArrayBuffer ] 加载模型耗时"),R=await q.retry(()=>i(p,_),{maxRetries:w,shouldRetry:pe=>!!(pe.name==="TypeError"||pe.message.includes("HTTP error! status: 5"))}),console.timeEnd("[ fetchArrayBuffer ] 加载模型耗时");const v=performance.now();await B.saveModel(p,y,R);const G=performance.now()-v;U.recordCacheSave(G),T=!1}console.time("[ 解析模型耗时 ]");let C=await c(R);if(console.timeEnd("[ 解析模型耗时 ]"),console.time("[ 模型优化耗时 ]"),b){console.log("🔧 [ 材质优化 ] 开始合并相同材质...");const{modelOptimizer:v}=await Promise.resolve().then(()=>require("./modelOptimizer-A0Cs6f9e.cjs"));C=v.optimizeMaterials(C)}if(M){console.log(`🔧 [ 几何体简化 ] 开始简化模型 (比例: ${A})...`);const{modelOptimizer:v}=await Promise.resolve().then(()=>require("./modelOptimizer-A0Cs6f9e.cjs")),G={minFaceCount:100,preserveUVs:!0,...L};C=v.simplifyModel(C,A,G)}console.timeEnd("[ 模型优化耗时 ]");const k=performance.now()-f;return T?U.recordHit(k):U.recordMiss(k),C}catch(R){throw console.error(`加载模型 ${p} 失败:`,R),U.recordError(p,R),R.name==="TypeError"&&R.message.includes("fetch")?X.networkError(p,R):R}}async function i(p,y){return new Promise((_,m)=>{fetch(p).then(f=>{if(!f.ok)throw new Error(`HTTP error! status: ${f.status}`);return f}).then(f=>{const T=f.headers.get("content-length"),w=T?parseInt(T,10):0;if(y&&w>0){const b=f.body.getReader();let M=0;const A=[],L=()=>{b.read().then(({done:R,value:C})=>{if(R){const k=new Uint8Array(M);let v=0;for(const G of A)k.set(G,v),v+=G.length;_(k.buffer);return}A.push(C),M+=C.length,y(Math.round(M/w*100)),L()}).catch(m)};L()}else return f.arrayBuffer()}).then(f=>_(f)).catch(f=>{m(f)})})}async function o(p,y){return B||(B=new ue),B.getModel(p,y)}async function c(p,y={}){if(!p)return null;const{useOptimizedParser:_=!0,useProgressive:m=!1}=y;if(_){const w=l();if(w)try{console.time("[ 优化解析 ] 使用 Transferable Objects 解析");const b=await d(w,p,m);return console.timeEnd("[ 优化解析 ] 使用 Transferable Objects 解析"),fe(b)}catch(b){console.warn("[ 优化解析 ] 失败,回退到标准解析",b)}}const f=a();if(f)try{const w=await h(f,p);return Oe(w)}catch(w){console.warn("[ GLTF Worker ] ====> 解析失败,回退到主线程解析",w)}return(await g(p)).scene}const a=()=>typeof window>"u"||typeof Worker>"u"?null:(z||(z=new Worker(ts,{type:"module"}),z.onmessage=p=>{const{id:y,data:_,error:m}=p.data||{};if(!y||!F.has(y))return;const{resolve:f,reject:T}=F.get(y);F.delete(y),m?T(new Error(m)):f(_)},z.onmessageerror=p=>{console.error("[ GLTF Worker ] ====> 消息解析失败",p)},z.onerror=p=>{console.error("[ GLTF Worker ] ====> 运行错误",p)}),z),l=()=>{if(typeof window>"u"||typeof Worker>"u")return null;if(!K)try{K=new Worker(ss,{type:"module"}),K.onmessage=p=>{const{id:y,data:_,error:m,type:f}=p.data||{};if(!y||!F.has(y)||f==="progress")return;const{resolve:T,reject:w}=F.get(y);F.delete(y),m?w(new Error(m)):T(_)},K.onmessageerror=p=>{console.error("[ 优化 Worker ] ====> 消息解析失败",p)},K.onerror=p=>{console.error("[ 优化 Worker ] ====> 运行错误",p)}}catch(p){return console.warn("[ 优化 Worker ] ====> 创建失败,可能不支持模块化 Worker",p),null}return K},d=(p,y,_=!1)=>new Promise((m,f)=>{const T=++Re;F.set(T,{resolve:m,reject:f});const w={id:T,arrayBuffer:y,dracoPath:ce,mode:_?"progressive":"standard"};p.postMessage(w,[y])}),h=(p,y)=>new Promise((_,m)=>{const f=++Re;F.set(f,{resolve:_,reject:m}),p.postMessage({id:f,arrayBuffer:y,dracoPath:ce})}),g=p=>new Promise((y,_)=>{r.parse(p,"",y,_)});return{load:t,asyncLoad:s,asyncCacheLoad:n,asyncFetch:n,getCacheStats:()=>U.getStats(),getCache:()=>B||(B=new ue),logCacheReport:()=>U.logReport(),resetCacheStats:()=>U.reset()}};class Ne{constructor(e={}){this.options={maxPreloadCount:e.maxPreloadCount||5,preloadDelay:e.preloadDelay||1e3,enableLearning:e.enableLearning!==!1},this.loadHistory=new Map,this.loadSequence=[],this.associations=new Map,this.preloadQueue=new Set,this.isPreloading=!1,this.loader=null,this.getLoader=()=>(this.loader||(this.loader=ke()),this.loader)}recordLoad(e,t){const s=Date.now(),n=this.loadHistory.get(e)||{count:0,lastLoadTime:0,versions:new Set};n.count++,n.lastLoadTime=s,n.versions.add(t),this.loadHistory.set(e,n),this.loadSequence.push({path:e,timestamp:s}),this.loadSequence.length>100&&this.loadSequence.shift(),this.options.enableLearning&&this.loadSequence.length>=2&&this._learnAssociations(e),this._triggerPredictivePreload(e,t)}_learnAssociations(e){const s=this.loadSequence.length-1;for(let n=Math.max(0,s-10);n<s;n++){const{path:i}=this.loadSequence[n];if(this.loadSequence[s].timestamp-this.loadSequence[n].timestamp<5*60*1e3&&i!==e){this.associations.has(i)||this.associations.set(i,new Map);const c=this.associations.get(i),a=c.get(e)||0;c.set(e,a+1)}}}_triggerPredictivePreload(e,t){setTimeout(()=>{const s=this.predictNext(e);this.preload(s,t)},this.options.preloadDelay)}predictNext(e){const t=new Map,s=this.associations.get(e);s&&s.forEach((c,a)=>{t.set(a,(t.get(a)||0)+c*2)});const n=Array.from(this.loadHistory.values()).reduce((c,a)=>c+a.count,0)/(this.loadHistory.size||1);this.loadHistory.forEach((c,a)=>{if(a!==e){const l=c.count/n;t.set(a,(t.get(a)||0)+l)}});const i=this.loadSequence.slice(-10);return new Set(i.map(c=>c.path)).forEach(c=>{c!==e&&t.set(c,(t.get(c)||0)+.5)}),Array.from(t.entries()).sort((c,a)=>a[1]-c[1]).slice(0,this.options.maxPreloadCount).map(([c])=>c)}async preload(e,t="latest"){if(this.isPreloading)return;this.isPreloading=!0;const{asyncFetch:s}=this.getLoader(),n=e.filter(i=>!this.preloadQueue.has(i)).slice(0,this.options.maxPreloadCount).map(async i=>{this.preloadQueue.add(i);try{console.log(`[ 智能预加载 ] 开始预加载: ${i}`),await s(i,t),console.log(`[ 智能预加载 ] 完成: ${i}`)}catch(o){console.warn(`[ 智能预加载 ] 失败: ${i}`,o)}finally{this.preloadQueue.delete(i)}});await Promise.all(n),this.isPreloading=!1}addAssociation(e,t){this.associations.has(e)||this.associations.set(e,new Map);const s=this.associations.get(e);t.forEach(n=>{const i=s.get(n)||0;s.set(n,i+10)})}getStats(){const e=Array.from(this.loadHistory.entries()).sort((t,s)=>s[1].count-t[1].count).slice(0,10).map(([t,s])=>({path:t,loadCount:s.count,lastLoadTime:new Date(s.lastLoadTime).toLocaleString()}));return{totalModelsLoaded:this.loadHistory.size,totalAssociations:this.associations.size,topModels:e,preloadQueueSize:this.preloadQueue.size}}clearHistory(){this.loadHistory.clear(),this.loadSequence=[],this.associations.clear()}exportAssociations(){const e={};return this.associations.forEach((t,s)=>{e[s]=Array.from(t.entries())}),e}importAssociations(e){Object.entries(e).forEach(([t,s])=>{const n=new Map(s);this.associations.set(t,n)})}}const ns=new Ne;exports.CSS3DRenderer=Be;exports.CSS3DSprite=je;exports.CacheMonitor=Ie;exports.ErrorType=$;exports.IDBCache=ue;exports.ModelLoadError=X;exports.PredictiveLoader=Ne;exports.ProgressiveSceneBuilder=es;exports.RetryHelper=q;exports.Stats=V;exports.cacheMonitor=U;exports.createArrowHelper=ht;exports.createAxesHelper=lt;exports.createBox3Helper=ot;exports.createCameraHelper=nt;exports.createGridHelper=it;exports.createMapControls=at;exports.createOrbitControl=rt;exports.createRaycaster=ct;exports.createStats=ut;exports.dataToObject3D=Oe;exports.dataToObject3DSync=$t;exports.disposeThreeObject=De;exports.object3DToData=qt;exports.object3DToDataSync=Zt;exports.predictiveLoader=ns;exports.rebuildScene=fe;exports.useGLTFLoader=ke;