@ridp/threejs 1.5.1 → 1.5.2

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