diff --git a/examples/Clipper/index.html b/examples/Clipper/index.html new file mode 100644 index 000000000..d55b212da --- /dev/null +++ b/examples/Clipper/index.html @@ -0,0 +1,38 @@ + + + + + + + + + + + Simple Clipper + + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/examples/Cullers/index.html b/examples/Cullers/index.html new file mode 100644 index 000000000..67dd738ef --- /dev/null +++ b/examples/Cullers/index.html @@ -0,0 +1,37 @@ + + + + + + + + + + + Screen Culler + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/examples/Grids/index.html b/examples/Grids/index.html new file mode 100644 index 000000000..96994a66f --- /dev/null +++ b/examples/Grids/index.html @@ -0,0 +1,36 @@ + + + + + + + + + + + Simple 2D Scene + + + + + + + + +
+ + + \ No newline at end of file diff --git a/examples/Marker/index.html b/examples/Marker/index.html new file mode 100644 index 000000000..75111ad89 --- /dev/null +++ b/examples/Marker/index.html @@ -0,0 +1,34 @@ + + + + + + + + + + + Simple 2D Scene + + + + + + +
+ + + \ No newline at end of file diff --git a/examples/Materials/index.html b/examples/Materials/index.html new file mode 100644 index 000000000..8ea056819 --- /dev/null +++ b/examples/Materials/index.html @@ -0,0 +1,36 @@ + + + + + + + + + + Material Manager + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/examples/Raycasters/index.html b/examples/Raycasters/index.html new file mode 100644 index 000000000..d70d96a38 --- /dev/null +++ b/examples/Raycasters/index.html @@ -0,0 +1,35 @@ + + + + + + + + + + Simple Raycaster + + + + + + + + +
+ + + \ No newline at end of file diff --git a/examples/Worlds/index.html b/examples/Worlds/index.html index 328bccc46..d1c6e8c73 100644 --- a/examples/Worlds/index.html +++ b/examples/Worlds/index.html @@ -24,6 +24,8 @@ } + + diff --git a/examples/assets/clipper.js b/examples/assets/clipper.js new file mode 100644 index 000000000..dd94173a7 --- /dev/null +++ b/examples/assets/clipper.js @@ -0,0 +1 @@ +var Oe=Object.defineProperty;var We=(h,n,t)=>n in h?Oe(h,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[n]=t;var r=(h,n,t)=>(We(h,typeof n!="symbol"?n+"":n,t),t);import{R as Ge,V as l,O as le,Q as I,E as Ne,M as me,n as he,t as Ue,p as g,u,j as ge,v as ye,b as o,w as ie,x as X,y as Ve,z as O,k as Ae,m as De,P as Je,o as Ke,I as $e,J as et,C as tt}from"./three.module-CYx2Afzj.js";import{g as nt}from"./lil-gui.module.min-Bc0DeA9g.js";import{S as it}from"./stats.min-BpIepu9J.js";import{E as b,c as st,W as Ye,C as ot,S as at,a as rt,b as lt}from"./index-DCLJCpH4.js";import{R as _e}from"./index-BXUCpuVG.js";const z=new Ge,f=new l,C=new l,d=new I,be={X:new l(1,0,0),Y:new l(0,1,0),Z:new l(0,0,1)},ce={type:"change"},Pe={type:"mouseDown"},Me={type:"mouseUp",mode:null},xe={type:"objectChange"};class ht extends le{constructor(n,t){super(),t===void 0&&(console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.'),t=document),this.isTransformControls=!0,this.visible=!1,this.domElement=t,this.domElement.style.touchAction="none";const i=new ft;this._gizmo=i,this.add(i);const s=new wt;this._plane=s,this.add(s);const a=this;function e(w,P){let k=P;Object.defineProperty(a,w,{get:function(){return k!==void 0?k:P},set:function(T){k!==T&&(k=T,s[w]=T,i[w]=T,a.dispatchEvent({type:w+"-changed",value:T}),a.dispatchEvent(ce))}}),a[w]=P,s[w]=P,i[w]=P}e("camera",n),e("object",void 0),e("enabled",!0),e("axis",null),e("mode","translate"),e("translationSnap",null),e("rotationSnap",null),e("scaleSnap",null),e("space","world"),e("size",1),e("dragging",!1),e("showX",!0),e("showY",!0),e("showZ",!0);const c=new l,m=new l,v=new I,B=new I,F=new l,q=new I,fe=new l,K=new l,D=new l,Y=0,S=new l;e("worldPosition",c),e("worldPositionStart",m),e("worldQuaternion",v),e("worldQuaternionStart",B),e("cameraPosition",F),e("cameraQuaternion",q),e("pointStart",fe),e("pointEnd",K),e("rotationAxis",D),e("rotationAngle",Y),e("eye",S),this._offset=new l,this._startNorm=new l,this._endNorm=new l,this._cameraScale=new l,this._parentPosition=new l,this._parentQuaternion=new I,this._parentQuaternionInv=new I,this._parentScale=new l,this._worldScaleStart=new l,this._worldQuaternionInv=new I,this._worldScale=new l,this._positionStart=new l,this._quaternionStart=new I,this._scaleStart=new l,this._getPointer=ct.bind(this),this._onPointerDown=dt.bind(this),this._onPointerHover=pt.bind(this),this._onPointerMove=mt.bind(this),this._onPointerUp=ut.bind(this),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp)}updateMatrixWorld(){this.object!==void 0&&(this.object.updateMatrixWorld(),this.object.parent===null?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):this.object.parent.matrixWorld.decompose(this._parentPosition,this._parentQuaternion,this._parentScale),this.object.matrixWorld.decompose(this.worldPosition,this.worldQuaternion,this._worldScale),this._parentQuaternionInv.copy(this._parentQuaternion).invert(),this._worldQuaternionInv.copy(this.worldQuaternion).invert()),this.camera.updateMatrixWorld(),this.camera.matrixWorld.decompose(this.cameraPosition,this.cameraQuaternion,this._cameraScale),this.camera.isOrthographicCamera?this.camera.getWorldDirection(this.eye).negate():this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize(),super.updateMatrixWorld(this)}pointerHover(n){if(this.object===void 0||this.dragging===!0)return;z.setFromCamera(n,this.camera);const t=pe(this._gizmo.picker[this.mode],z);t?this.axis=t.object.name:this.axis=null}pointerDown(n){if(!(this.object===void 0||this.dragging===!0||n.button!==0)&&this.axis!==null){z.setFromCamera(n,this.camera);const t=pe(this._plane,z,!0);t&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(t.point).sub(this.worldPositionStart)),this.dragging=!0,Pe.mode=this.mode,this.dispatchEvent(Pe)}}pointerMove(n){const t=this.axis,i=this.mode,s=this.object;let a=this.space;if(i==="scale"?a="local":(t==="E"||t==="XYZE"||t==="XYZ")&&(a="world"),s===void 0||t===null||this.dragging===!1||n.button!==-1)return;z.setFromCamera(n,this.camera);const e=pe(this._plane,z,!0);if(e){if(this.pointEnd.copy(e.point).sub(this.worldPositionStart),i==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),a==="local"&&t!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),t.indexOf("X")===-1&&(this._offset.x=0),t.indexOf("Y")===-1&&(this._offset.y=0),t.indexOf("Z")===-1&&(this._offset.z=0),a==="local"&&t!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),s.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(a==="local"&&(s.position.applyQuaternion(d.copy(this._quaternionStart).invert()),t.search("X")!==-1&&(s.position.x=Math.round(s.position.x/this.translationSnap)*this.translationSnap),t.search("Y")!==-1&&(s.position.y=Math.round(s.position.y/this.translationSnap)*this.translationSnap),t.search("Z")!==-1&&(s.position.z=Math.round(s.position.z/this.translationSnap)*this.translationSnap),s.position.applyQuaternion(this._quaternionStart)),a==="world"&&(s.parent&&s.position.add(f.setFromMatrixPosition(s.parent.matrixWorld)),t.search("X")!==-1&&(s.position.x=Math.round(s.position.x/this.translationSnap)*this.translationSnap),t.search("Y")!==-1&&(s.position.y=Math.round(s.position.y/this.translationSnap)*this.translationSnap),t.search("Z")!==-1&&(s.position.z=Math.round(s.position.z/this.translationSnap)*this.translationSnap),s.parent&&s.position.sub(f.setFromMatrixPosition(s.parent.matrixWorld))));else if(i==="scale"){if(t.search("XYZ")!==-1){let c=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(c*=-1),C.set(c,c,c)}else f.copy(this.pointStart),C.copy(this.pointEnd),f.applyQuaternion(this._worldQuaternionInv),C.applyQuaternion(this._worldQuaternionInv),C.divide(f),t.search("X")===-1&&(C.x=1),t.search("Y")===-1&&(C.y=1),t.search("Z")===-1&&(C.z=1);s.scale.copy(this._scaleStart).multiply(C),this.scaleSnap&&(t.search("X")!==-1&&(s.scale.x=Math.round(s.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search("Y")!==-1&&(s.scale.y=Math.round(s.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search("Z")!==-1&&(s.scale.z=Math.round(s.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(i==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const c=20/this.worldPosition.distanceTo(f.setFromMatrixPosition(this.camera.matrixWorld));let m=!1;t==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(f.copy(this.rotationAxis).cross(this.eye))*c):(t==="X"||t==="Y"||t==="Z")&&(this.rotationAxis.copy(be[t]),f.copy(be[t]),a==="local"&&f.applyQuaternion(this.worldQuaternion),f.cross(this.eye),f.length()===0?m=!0:this.rotationAngle=this._offset.dot(f.normalize())*c),(t==="E"||m)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),a==="local"&&t!=="E"&&t!=="XYZE"?(s.quaternion.copy(this._quaternionStart),s.quaternion.multiply(d.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),s.quaternion.copy(d.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),s.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(ce),this.dispatchEvent(xe)}}pointerUp(n){n.button===0&&(this.dragging&&this.axis!==null&&(Me.mode=this.mode,this.dispatchEvent(Me)),this.dragging=!1,this.axis=null)}dispose(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.traverse(function(n){n.geometry&&n.geometry.dispose(),n.material&&n.material.dispose()})}attach(n){return this.object=n,this.visible=!0,this}detach(){return this.object=void 0,this.visible=!1,this.axis=null,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(ce),this.dispatchEvent(xe),this.pointStart.copy(this.pointEnd))}getRaycaster(){return z}getMode(){return this.mode}setMode(n){this.mode=n}setTranslationSnap(n){this.translationSnap=n}setRotationSnap(n){this.rotationSnap=n}setScaleSnap(n){this.scaleSnap=n}setSize(n){this.size=n}setSpace(n){this.space=n}}function ct(h){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:h.button};{const n=this.domElement.getBoundingClientRect();return{x:(h.clientX-n.left)/n.width*2-1,y:-(h.clientY-n.top)/n.height*2+1,button:h.button}}}function pt(h){if(this.enabled)switch(h.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(h));break}}function dt(h){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(h.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(h)),this.pointerDown(this._getPointer(h)))}function mt(h){this.enabled&&this.pointerMove(this._getPointer(h))}function ut(h){this.enabled&&(this.domElement.releasePointerCapture(h.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(h)))}function pe(h,n,t){const i=n.intersectObject(h,!0);for(let s=0;s.9&&(e.visible=!1)),this.axis==="Y"&&(d.setFromEuler(se.set(0,0,Math.PI/2)),e.quaternion.copy(i).multiply(d),Math.abs(p.copy(Z).applyQuaternion(i).dot(this.eye))>.9&&(e.visible=!1)),this.axis==="Z"&&(d.setFromEuler(se.set(0,Math.PI/2,0)),e.quaternion.copy(i).multiply(d),Math.abs(p.copy(U).applyQuaternion(i).dot(this.eye))>.9&&(e.visible=!1)),this.axis==="XYZE"&&(d.setFromEuler(se.set(0,Math.PI/2,0)),p.copy(this.rotationAxis),e.quaternion.setFromRotationMatrix(Se.lookAt(ve,p,Z)),e.quaternion.multiply(d),e.visible=this.dragging),this.axis==="E"&&(e.visible=!1)):e.name==="START"?(e.position.copy(this.worldPositionStart),e.visible=this.dragging):e.name==="END"?(e.position.copy(this.worldPosition),e.visible=this.dragging):e.name==="DELTA"?(e.position.copy(this.worldPositionStart),e.quaternion.copy(this.worldQuaternionStart),f.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),f.applyQuaternion(this.worldQuaternionStart.clone().invert()),e.scale.copy(f),e.visible=this.dragging):(e.quaternion.copy(i),this.dragging?e.position.copy(this.worldPositionStart):e.position.copy(this.worldPosition),this.axis&&(e.visible=this.axis.search(e.name)!==-1));continue}e.quaternion.copy(i),this.mode==="translate"||this.mode==="scale"?(e.name==="X"&&Math.abs(p.copy(N).applyQuaternion(i).dot(this.eye))>.99&&(e.scale.set(1e-10,1e-10,1e-10),e.visible=!1),e.name==="Y"&&Math.abs(p.copy(Z).applyQuaternion(i).dot(this.eye))>.99&&(e.scale.set(1e-10,1e-10,1e-10),e.visible=!1),e.name==="Z"&&Math.abs(p.copy(U).applyQuaternion(i).dot(this.eye))>.99&&(e.scale.set(1e-10,1e-10,1e-10),e.visible=!1),e.name==="XY"&&Math.abs(p.copy(U).applyQuaternion(i).dot(this.eye))<.2&&(e.scale.set(1e-10,1e-10,1e-10),e.visible=!1),e.name==="YZ"&&Math.abs(p.copy(N).applyQuaternion(i).dot(this.eye))<.2&&(e.scale.set(1e-10,1e-10,1e-10),e.visible=!1),e.name==="XZ"&&Math.abs(p.copy(Z).applyQuaternion(i).dot(this.eye))<.2&&(e.scale.set(1e-10,1e-10,1e-10),e.visible=!1)):this.mode==="rotate"&&(oe.copy(i),p.copy(this.eye).applyQuaternion(d.copy(i).invert()),e.name.search("E")!==-1&&e.quaternion.setFromRotationMatrix(Se.lookAt(this.eye,ve,Z)),e.name==="X"&&(d.setFromAxisAngle(N,Math.atan2(-p.y,p.z)),d.multiplyQuaternions(oe,d),e.quaternion.copy(d)),e.name==="Y"&&(d.setFromAxisAngle(Z,Math.atan2(p.x,p.z)),d.multiplyQuaternions(oe,d),e.quaternion.copy(d)),e.name==="Z"&&(d.setFromAxisAngle(U,Math.atan2(p.y,p.x)),d.multiplyQuaternions(oe,d),e.quaternion.copy(d))),e.visible=e.visible&&(e.name.indexOf("X")===-1||this.showX),e.visible=e.visible&&(e.name.indexOf("Y")===-1||this.showY),e.visible=e.visible&&(e.name.indexOf("Z")===-1||this.showZ),e.visible=e.visible&&(e.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),e.material._color=e.material._color||e.material.color.clone(),e.material._opacity=e.material._opacity||e.material.opacity,e.material.color.copy(e.material._color),e.material.opacity=e.material._opacity,this.enabled&&this.axis&&(e.name===this.axis||this.axis.split("").some(function(m){return e.name===m}))&&(e.material.color.setHex(16776960),e.material.opacity=1)}super.updateMatrixWorld(n)}}class wt extends o{constructor(){super(new Ae(1e5,1e5,2,2),new he({visible:!1,wireframe:!0,side:De,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(n){let t=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(t="local"),ae.copy(N).applyQuaternion(t==="local"?this.worldQuaternion:re),W.copy(Z).applyQuaternion(t==="local"?this.worldQuaternion:re),G.copy(U).applyQuaternion(t==="local"?this.worldQuaternion:re),p.copy(W),this.mode){case"translate":case"scale":switch(this.axis){case"X":p.copy(this.eye).cross(ae),E.copy(ae).cross(p);break;case"Y":p.copy(this.eye).cross(W),E.copy(W).cross(p);break;case"Z":p.copy(this.eye).cross(G),E.copy(G).cross(p);break;case"XY":E.copy(G);break;case"YZ":E.copy(ae);break;case"XZ":p.copy(G),E.copy(W);break;case"XYZ":case"E":E.set(0,0,0);break}break;case"rotate":default:E.set(0,0,0)}E.length()===0?this.quaternion.copy(this.cameraQuaternion):(Ee.lookAt(f.set(0,0,0),E,p),this.quaternion.setFromRotationMatrix(Ee)),super.updateMatrixWorld(n)}}class ue{constructor(n,t,i,s,a,e=5,c=!0){r(this,"onDraggingStarted",new b);r(this,"onDraggingEnded",new b);r(this,"onDisposed",new b);r(this,"normal");r(this,"origin");r(this,"three",new Je);r(this,"_helper");r(this,"_visible",!0);r(this,"_enabled",!0);r(this,"components");r(this,"world");r(this,"_controlsActive",!1);r(this,"_arrowBoundBox",new o);r(this,"_planeMesh");r(this,"_controls");r(this,"_hiddenMaterial",new he({visible:!1}));r(this,"update",async()=>{this._enabled&&this.three.setFromNormalAndCoplanarPoint(this.normal,this._helper.position)});r(this,"changeDrag",n=>{this._visible=!n.value,this.preventCameraMovement(),this.notifyDraggingChanged(n)});if(this.components=n,this.world=t,!t.renderer)throw new Error("The given world must have a renderer!");this.normal=s,this.origin=i,t.renderer.setPlane(!0,this.three),this._planeMesh=ue.newPlaneMesh(e,a),this._helper=this.newHelper(),this._controls=this.newTransformControls(),this.three.setFromNormalAndCoplanarPoint(s,i),c&&this.toggleControls(!0)}get enabled(){return this._enabled}set enabled(n){if(!this.world.renderer)throw new Error("No renderer found for clipping plane!");this._enabled=n,this.world.renderer.setPlane(n,this.three)}get visible(){return this._visible}set visible(n){this._visible=n,this._controls.visible=n,this._helper.visible=n,this.toggleControls(n)}get meshes(){return[this._planeMesh,this._arrowBoundBox]}get planeMaterial(){return this._planeMesh.material}set planeMaterial(n){this._planeMesh.material=n}get size(){return this._planeMesh.scale.x}set size(n){this._planeMesh.scale.set(n,n,n)}get helper(){return this._helper}async setFromNormalAndCoplanarPoint(n,t){this.reset(),this.normal.equals(n)||(this.normal.copy(n),this._helper.lookAt(n)),this.origin.copy(t),this._helper.position.copy(t),this._helper.updateMatrix(),await this.update()}dispose(){this._enabled=!1,this.onDraggingStarted.reset(),this.onDraggingEnded.reset(),this._helper.removeFromParent(),this.world.renderer&&this.world.renderer.setPlane(!1,this.three),this._arrowBoundBox.removeFromParent(),this._arrowBoundBox.geometry.dispose(),this._planeMesh.geometry.dispose(),this._controls.removeFromParent(),this._controls.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}reset(){const n=new l(1,0,0),t=new l;this.normal.equals(n)||(this.normal.copy(n),this._helper.lookAt(n)),this.origin.copy(t),this._helper.position.copy(t),this._helper.updateMatrix()}toggleControls(n){if(n){if(this._controlsActive)return;this._controls.addEventListener("change",this.update),this._controls.addEventListener("dragging-changed",this.changeDrag)}else this._controls.removeEventListener("change",this.update),this._controls.removeEventListener("dragging-changed",this.changeDrag);this._controlsActive=n}newTransformControls(){if(!this.world.renderer)throw new Error("No renderer found for clipping plane!");const n=this.world.camera.three,t=this.world.renderer.three.domElement,i=new ht(n,t);return this.initializeControls(i),this.world.scene.three.add(i),i}initializeControls(n){n.attach(this._helper),n.showX=!1,n.showY=!1,n.setSpace("local"),this.createArrowBoundingBox(),n.children[0].children[0].add(this._arrowBoundBox)}createArrowBoundingBox(){this._arrowBoundBox.geometry=new g(.18,.18,1.2),this._arrowBoundBox.material=this._hiddenMaterial,this._arrowBoundBox.rotateX(Math.PI/2),this._arrowBoundBox.updateMatrix(),this._arrowBoundBox.geometry.applyMatrix4(this._arrowBoundBox.matrix)}notifyDraggingChanged(n){n.value?this.onDraggingStarted.trigger():this.onDraggingEnded.trigger()}preventCameraMovement(){this.world.camera.enabled=this._visible}newHelper(){const n=new le;return n.lookAt(this.normal),n.position.copy(this.origin),this._planeMesh.position.z+=.01,n.add(this._planeMesh),this.world.scene.three.add(n),n}static newPlaneMesh(n,t){const i=new Ae(1),s=new o(i,t);return s.scale.set(n,n,n),s}}const V=class V extends st{constructor(t){super(t);r(this,"onAfterCreate",new b);r(this,"onAfterDelete",new b);r(this,"onBeforeDrag",new b);r(this,"onAfterDrag",new b);r(this,"onBeforeCreate",new b);r(this,"onBeforeCancel",new b);r(this,"onAfterCancel",new b);r(this,"onBeforeDelete",new b);r(this,"onDisposed",new b);r(this,"orthogonalY",!1);r(this,"toleranceOrthogonalY",.7);r(this,"planes",[]);r(this,"PlaneType");r(this,"_material",new he({color:16776960,side:De,transparent:!0,opacity:.2}));r(this,"_size",5);r(this,"_enabled",!1);r(this,"_visible",!1);r(this,"_onStartDragging",()=>{this.onBeforeDrag.trigger()});r(this,"_onEndDragging",()=>{this.onAfterDrag.trigger()});this.components.add(V.uuid,this),this.PlaneType=ue}get enabled(){return this._enabled}set enabled(t){this._enabled=t;for(const i of this.planes)i.enabled=t;this.updateMaterialsAndPlanes()}get visible(){return this._visible}set visible(t){this._visible=t;for(const i of this.planes)i.visible=t}get material(){return this._material}set material(t){this._material=t;for(const i of this.planes)i.planeMaterial=t}get size(){return this._size}set size(t){this._size=t;for(const i of this.planes)i.size=t}endCreation(){}cancelCreation(){}dispose(){this._enabled=!1;for(const t of this.planes)t.dispose();this.planes.length=0,this._material.dispose(),this.onBeforeCreate.reset(),this.onBeforeCancel.reset(),this.onBeforeDelete.reset(),this.onBeforeDrag.reset(),this.onAfterCreate.reset(),this.onAfterCancel.reset(),this.onAfterDelete.reset(),this.onAfterDrag.reset(),this.onDisposed.trigger(V.uuid),this.onDisposed.reset()}create(t){if(!this.enabled)return;const a=this.components.get(_e).get(t).castRay();a&&this.createPlaneFromIntersection(t,a)}createFromNormalAndCoplanarPoint(t,i,s){const a=this.newPlane(t,s,i);return this.updateMaterialsAndPlanes(),a}delete(t,i){this.enabled&&(i||(i=this.pickPlane(t)),i&&this.deletePlane(i))}deleteAll(){for(;this.planes.length>0;){const t=this.planes[0];this.delete(t.world,t)}}deletePlane(t){const i=this.planes.indexOf(t);if(i!==-1){if(this.planes.splice(i,1),!t.world.renderer)throw new Error("Renderer not found for this plane's world!");t.world.renderer.setPlane(!1,t.three),t.dispose(),this.updateMaterialsAndPlanes(),this.onAfterDelete.trigger(t)}}pickPlane(t){const s=this.components.get(_e).get(t),a=this.getAllPlaneMeshes(),e=s.castRay(a);if(e){const c=e.object;return this.planes.find(m=>m.meshes.includes(c))}}getAllPlaneMeshes(){const t=[];for(const i of this.planes)t.push(...i.meshes);return t}createPlaneFromIntersection(t,i){var m;if(!t.renderer)throw new Error("The given world must have a renderer!");const s=i.point.distanceTo(new l(0,0,0)),a=(m=i.face)==null?void 0:m.normal;if(!s||!a)return;const e=this.getWorldNormal(i,a),c=this.newPlane(t,i.point,e.negate());t.renderer.setPlane(!0,c.three),this.updateMaterialsAndPlanes()}getWorldNormal(t,i){const s=t.object;let a=t.object.matrixWorld.clone();if(s instanceof $e&&t.instanceId!==void 0){const v=new me;s.getMatrixAt(t.instanceId,v),a=v.multiply(a)}const c=new Ke().getNormalMatrix(a),m=i.clone().applyMatrix3(c).normalize();return this.normalizePlaneDirectionY(m),m}normalizePlaneDirectionY(t){this.orthogonalY&&(t.y>this.toleranceOrthogonalY&&(t.x=0,t.y=1,t.z=0),t.y<-this.toleranceOrthogonalY&&(t.x=0,t.y=-1,t.z=0))}newPlane(t,i,s){const a=this.newPlaneInstance(t,i,s);return a.onDraggingStarted.add(this._onStartDragging),a.onDraggingEnded.add(this._onEndDragging),this.planes.push(a),this.onAfterCreate.trigger(a),a}newPlaneInstance(t,i,s){return new this.PlaneType(this.components,t,i,s,this._material)}updateMaterialsAndPlanes(){const t=this.components.get(Ye);for(const[i,s]of t.list){if(!s.renderer)continue;s.renderer.updateClippingPlanes();const{clippingPlanes:a}=s.renderer;for(const e of s.meshes)if(Array.isArray(e.material))for(const c of e.material)c.clippingPlanes=a;else e.material.clippingPlanes=a}}};r(V,"uuid","66290bc5-18c4-4cd1-9379-2e17a0617611");let de=V;const Qe=document.getElementById("container"),L=new ot,gt=L.get(Ye),x=gt.create();x.scene=new at(L);x.renderer=new rt(L,Qe);x.camera=new lt(L);L.init();x.camera.controls.setLookAt(10,10,10,0,0,0);x.scene.setup();const yt=new u(3,3,3),_t=new et({color:"#6528D7"}),R=new o(yt,_t);R.position.set(0,1.5,0);x.scene.three.add(R);x.meshes.add(R);const A=new de(L);A.enabled=!0;Qe.ondblclick=()=>A.create(x);window.onkeydown=h=>{(h.code==="Delete"||h.code==="Backspace")&&A.delete(x)};const J=new it;J.showPanel(2);document.body.append(J.dom);J.dom.style.left="0px";x.renderer.onBeforeUpdate.add(()=>J.begin());x.renderer.onAfterUpdate.add(()=>J.end());const Xe=new nt,Ce=Xe.addFolder("Shortcuts"),Te={"Create clipping plane":"Double click","Delete clipping plane":"Delete"};Ce.add(Te,"Create clipping plane");Ce.add(Te,"Delete clipping plane");const H=Xe.addFolder("Actions");H.add(A,"enabled").name("Toggle clipping planes enabled");H.add(A,"visible").name("Toggle clipping planes visible");const bt={value:0},Ie=new tt;H.addColor(bt,"value").name("Plane color").onChange(h=>{Ie.setHex(h),"color"in A.material&&(A.material.color=Ie)});H.add(A,"size").name("Plane Size").min(0).max(15);H.add(A.material,"opacity").name("Plane Opacity").min(0).max(1);const ze={"Delete all planes":()=>{A.deleteAll()},"Rotate cube":()=>{R.rotation.x=2*Math.PI*Math.random(),R.rotation.y=2*Math.PI*Math.random(),R.rotation.z=2*Math.PI*Math.random()}};H.add(ze,"Rotate cube");H.add(ze,"Delete all planes"); diff --git a/examples/assets/cullers.js b/examples/assets/cullers.js new file mode 100644 index 000000000..118bd9de7 --- /dev/null +++ b/examples/assets/cullers.js @@ -0,0 +1,18 @@ +var I=Object.defineProperty;var x=(s,t,e)=>t in s?I(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var i=(s,t,e)=>(x(s,typeof t!="symbol"?t+"":t,e),e);import{c as B,W as R,G as T,n as E,I as S,M as L,q as m,C as F,m as V,u as W,K as k,b as G}from"./three.module-CYx2Afzj.js";import{S as H}from"./stats.min-BpIepu9J.js";import{E as w,D as U,c as N,C as O,W as $,S as z,a as K,b as X}from"./index-DCLJCpH4.js";import{G as j}from"./index-C2l-cS9k.js";class A{static isTransparent(t){return t.transparent&&t.opacity<1}}function Y(s,t,e,r){return new Promise((n,o)=>{function a(){const d=s.clientWaitSync(t,e,0);if(d===s.WAIT_FAILED){o();return}if(d===s.TIMEOUT_EXPIRED){setTimeout(a,r);return}n()}a()})}async function q(s,t,e,r,n,o,a){const d=s.fenceSync(s.SYNC_GPU_COMMANDS_COMPLETE,0);s.flush(),await Y(s,d,0,10),s.deleteSync(d),s.bindBuffer(t,e),s.getBufferSubData(t,r,n,o,a),s.bindBuffer(t,null)}async function J(s,t,e,r,n,o,a,d){const l=s.createBuffer();return s.bindBuffer(s.PIXEL_PACK_BUFFER,l),s.bufferData(s.PIXEL_PACK_BUFFER,d.byteLength,s.STREAM_READ),s.readPixels(t,e,r,n,o,a,0),s.bindBuffer(s.PIXEL_PACK_BUFFER,null),await q(s,s.PIXEL_PACK_BUFFER,l,0,d),s.deleteBuffer(l),d}class Q{constructor(t,e,r){i(this,"onDisposed",new w);i(this,"onViewUpdated",new w);i(this,"enabled",!0);i(this,"needsUpdate",!1);i(this,"renderDebugFrame",!1);i(this,"components");i(this,"world");i(this,"renderer");i(this,"autoUpdate",!0);i(this,"updateInterval",1e3);i(this,"worker");i(this,"scene",new B);i(this,"_width",512);i(this,"_height",512);i(this,"_availableColor",1);i(this,"renderTarget");i(this,"bufferSize");i(this,"_buffer");i(this,"updateVisibility",async t=>{if(!this.enabled||!this.needsUpdate&&!t)return;const e=this.world.camera.three;e.updateMatrix(),this.renderer.setSize(this._width,this._height),this.renderer.setRenderTarget(this.renderTarget),this.renderer.render(this.scene,e);const r=this.renderer.getContext();await J(r,0,0,this._width,this._height,r.RGBA,r.UNSIGNED_BYTE,this._buffer),this.renderer.setRenderTarget(null),this.renderDebugFrame&&this.renderer.render(this.scene,e),this.worker.postMessage({buffer:this._buffer}),this.needsUpdate=!1});if(!e.renderer)throw new Error("The given world must have a renderer!");this.components=t,this.applySettings(r),this.world=e,this.renderer=new R,this.renderTarget=new T(this._width,this._height),this.bufferSize=this._width*this._height*4,this._buffer=new Uint8Array(this.bufferSize),this.renderer.clippingPlanes=e.renderer.clippingPlanes;const n=` + addEventListener("message", (event) => { + const { buffer } = event.data; + const colors = new Map(); + for (let i = 0; i < buffer.length; i += 4) { + const r = buffer[i]; + const g = buffer[i + 1]; + const b = buffer[i + 2]; + const code = "" + r + "-" + g + "-" + b; + if(colors.has(code)) { + colors.set(code, colors.get(code) + 1); + } else { + colors.set(code, 1); + } + } + postMessage({ colors }); + }); + `,o=new Blob([n],{type:"application/javascript"});this.worker=new Worker(URL.createObjectURL(o))}dispose(){this.enabled=!1;for(const t of this.scene.children)t.removeFromParent();this.onViewUpdated.reset(),this.worker.terminate(),this.renderer.dispose(),this.renderTarget.dispose(),this._buffer=null,this.onDisposed.reset()}getAvailableColor(){let t=BigInt(this._availableColor.toString());const e=[];do e.unshift(Number(t%256n)),t/=256n;while(t);for(;e.length!==3;)e.unshift(0);const[r,n,o]=e,a=`${r}-${n}-${o}`;return{r,g:n,b:o,code:a}}increaseColor(){if(this._availableColor===256*256*256){console.warn("Color can't be increased over 256 x 256 x 256!");return}this._availableColor++}decreaseColor(){if(this._availableColor===1){console.warn("Color can't be decreased under 0!");return}this._availableColor--}applySettings(t){t&&(t.updateInterval!==void 0&&(this.updateInterval=t.updateInterval),t.height!==void 0&&(this._height=t.height),t.width!==void 0&&(this._width=t.width),t.autoUpdate!==void 0&&(this.autoUpdate=t.autoUpdate))}}class Z extends Q{constructor(e,r,n){super(e,r,n);i(this,"threshold",100);i(this,"onViewUpdated",new w);i(this,"colorMeshes",new Map);i(this,"isProcessing",!1);i(this,"_colorCodeMeshMap",new Map);i(this,"_meshIDColorCodeMap",new Map);i(this,"_currentVisibleMeshes",new Set);i(this,"_recentlyHiddenMeshes",new Set);i(this,"_transparentMat",new E({transparent:!0,opacity:0}));i(this,"handleWorkerMessage",async e=>{if(this.isProcessing)return;const r=e.data.colors;this._recentlyHiddenMeshes=new Set(this._currentVisibleMeshes),this._currentVisibleMeshes.clear();for(const[n,o]of r){if(o{this.isProcessing||await this.updateVisibility()},this.updateInterval),this.onViewUpdated.add(({seen:o,unseen:a})=>{for(const d of o)d.visible=!0;for(const d of a)d.visible=!1})}dispose(){super.dispose(),this._currentVisibleMeshes.clear(),this._recentlyHiddenMeshes.clear(),this._meshIDColorCodeMap.clear(),this._transparentMat.dispose(),this._colorCodeMeshMap.clear();const e=this.components.get(U);for(const r in this.colorMeshes){const n=this.colorMeshes.get(r);n&&e.destroy(n,!0)}this.colorMeshes.clear()}add(e){if(!this.enabled)return;if(this.isProcessing){console.log("Culler processing not finished yet.");return}this.isProcessing=!0;const r=e instanceof S,{geometry:n,material:o}=e,{colorMaterial:a,code:d}=this.getAvailableMaterial();let l;if(Array.isArray(o)){let P=!0;const g=[];for(const D of o)A.isTransparent(D)?g.push(this._transparentMat):(P=!1,g.push(a));if(P){a.dispose(),this.isProcessing=!1;return}l=g}else if(A.isTransparent(o)){a.dispose(),this.isProcessing=!1;return}else l=a;this._colorCodeMeshMap.set(d,e),this._meshIDColorCodeMap.set(e.uuid,d);const _=r?e.count:1,u=new S(n,l,_);r?u.instanceMatrix=e.instanceMatrix:u.setMatrixAt(0,new L),e.visible=!1,u.applyMatrix4(e.matrix),u.updateMatrix(),this.scene.add(u),this.colorMeshes.set(e.uuid,u),this.increaseColor(),this.isProcessing=!1}remove(e){if(this.isProcessing){console.log("Culler processing not finished yet.");return}this.isProcessing=!0;const r=this.components.get(U);this._currentVisibleMeshes.delete(e),this._recentlyHiddenMeshes.delete(e);const n=this.colorMeshes.get(e.uuid),o=this._meshIDColorCodeMap.get(e.uuid);if(!n||!o){this.isProcessing=!1,console.log(e.visible);return}this._colorCodeMeshMap.delete(o),this._meshIDColorCodeMap.delete(e.uuid),this.colorMeshes.delete(e.uuid),n.geometry=void 0,n.material=[],r.destroy(n,!0),this._recentlyHiddenMeshes.delete(e),this._currentVisibleMeshes.delete(e),this.isProcessing=!1}getAvailableMaterial(){const{r:e,g:r,b:n,code:o}=this.getAvailableColor(),a=m.enabled;m.enabled=!1;const d=new F(`rgb(${e}, ${r}, ${n})`);if(!this.world.renderer)throw new Error("Renderer not found in the world!");const l=this.world.renderer.clippingPlanes,_=new E({color:d,clippingPlanes:l,side:V});return m.enabled=a,{colorMaterial:_,code:o}}}const p=class p extends N{constructor(e){super(e);i(this,"_enabled",!0);i(this,"list",new Map);i(this,"onDisposed",new w);e.add(p.uuid,this)}get enabled(){return this._enabled}set enabled(e){this._enabled=e;for(const[r,n]of this.list)n.enabled=e}create(e,r){if(this.list.has(e.uuid))return this.list.get(e.uuid);const n=new Z(this.components,e,r);return this.list.set(e.uuid,n),n}remove(e){const r=this.list.get(e.uuid);r&&r.dispose(),this.list.delete(e.uuid)}dispose(){this.enabled=!1,this.onDisposed.trigger(p.uuid),this.onDisposed.reset();for(const[e,r]of this.list)r.dispose();this.list.clear()}};i(p,"uuid","69f2a50d-c266-44fc-b1bd-fa4d34be89e6");let C=p;const ee=document.getElementById("container"),h=new O,te=h.get($),c=te.create();c.scene=new z(h);c.renderer=new K(h,ee);c.camera=new X(h);h.init();c.camera.controls.setLookAt(13,13,13,0,0,0);c.scene.setup();const se=h.get(j);se.create(c);const re=new C(h),f=re.create(c);f.threshold=200;f.renderDebugFrame=!0;const b=f.renderer.domElement;document.body.appendChild(b);b.style.position="fixed";b.style.left="0";b.style.bottom="0";b.style.visibility="collapse";function y(s){return Math.random()*s}const v=[],ie=new W(2,2,2),ne=new k({color:"#6528D7"});function oe(){for(const s of v)s.removeFromParent();v.length=0}function ae(){oe();for(let s=0;s<300;s++){const t=new G(ie,ne);t.position.x=y(10),t.position.y=y(10),t.position.z=y(10),t.updateMatrix(),c.scene.three.add(t),f.add(t),v.push(t)}}ae();f.needsUpdate=!0;c.camera.controls.addEventListener("controlend",()=>{f.needsUpdate=!0});const M=new H;M.showPanel(2);document.body.append(M.dom);M.dom.style.left="0px";c.renderer.onBeforeUpdate.add(()=>M.begin());c.renderer.onAfterUpdate.add(()=>M.end()); diff --git a/examples/assets/grids.js b/examples/assets/grids.js new file mode 100644 index 000000000..964a65600 --- /dev/null +++ b/examples/assets/grids.js @@ -0,0 +1 @@ +import{b as o,u as r}from"./three.module-CYx2Afzj.js";import{C as s,W as t,S as a,a as c,b as m}from"./index-DCLJCpH4.js";import{G as i}from"./index-C2l-cS9k.js";const d=document.getElementById("container"),e=new s,p=e.get(t),n=p.create();n.scene=new a(e);n.renderer=new c(e,d);n.camera=new m(e);e.init();const w=new o(new r);n.scene.three.add(w);const l=e.get(i);l.create(n); diff --git a/examples/assets/index-BXUCpuVG.js b/examples/assets/index-BXUCpuVG.js new file mode 100644 index 000000000..b1c3d71b9 --- /dev/null +++ b/examples/assets/index-BXUCpuVG.js @@ -0,0 +1 @@ +var u=Object.defineProperty;var c=(r,e,t)=>e in r?u(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var i=(r,e,t)=>(c(r,typeof e!="symbol"?e+"":e,t),t);import{E as n,c as l}from"./index-DCLJCpH4.js";import{a as p,R as m}from"./three.module-CYx2Afzj.js";class f{constructor(e){i(this,"_event");i(this,"_position",new p);i(this,"onDisposed",new n);i(this,"updateMouseInfo",e=>{this._event=e});this.dom=e,this.setupEvents(!0)}get position(){if(this._event){const e=this.dom.getBoundingClientRect();this._position.x=this.getPositionX(e,this._event),this._position.y=this.getPositionY(e,this._event)}return this._position}dispose(){this.setupEvents(!1),this.onDisposed.trigger(),this.onDisposed.reset()}getPositionY(e,t){return-((t.clientY-e.top)/(e.bottom-e.top))*2+1}getPositionX(e,t){return(t.clientX-e.left)/(e.right-e.left)*2-1}setupEvents(e){e?this.dom.addEventListener("mousemove",this.updateMouseInfo):this.dom.removeEventListener("mousemove",this.updateMouseInfo)}}class g{constructor(e,t){i(this,"enabled",!0);i(this,"components");i(this,"onDisposed",new n);i(this,"mouse");i(this,"three",new m);i(this,"world");const s=t.renderer;if(!s)throw new Error("A renderer is needed for the raycaster to work!");this.world=t,this.mouse=new f(s.three.domElement),this.components=e}dispose(){this.mouse.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}castRay(e=Array.from(this.world.meshes)){if(!this.world)throw new Error("A world is needed to cast rays!");const t=this.world.camera.three;return this.three.setFromCamera(this.mouse.position,t),this.intersect(e)}castRayFromVector(e,t,s=Array.from(this.world.meshes)){return this.three.set(e,t),this.intersect(s)}intersect(e=Array.from(this.world.meshes)){const t=this.three.intersectObjects(e),s=this.filterClippingPlanes(t);return s.length>0?s[0]:null}filterClippingPlanes(e){if(!this.world.renderer)throw new Error("Renderer not found!");const t=this.world.renderer.three;if(!t.clippingPlanes)return e;const s=t.clippingPlanes;return e.length<=0||!s||(s==null?void 0:s.length)<=0?e:e.filter(d=>s.every(a=>a.distanceToPoint(d.point)>0))}}const o=class o extends l{constructor(t){super(t);i(this,"enabled",!0);i(this,"list",new Map);i(this,"onDisposed",new n);t.add(o.uuid,this)}get(t){if(this.list.has(t.uuid))return this.list.get(t.uuid);const s=new g(this.components,t);return this.list.set(t.uuid,s),t.onDisposed.add(()=>{this.delete(t)}),s}delete(t){const s=this.list.get(t.uuid);s&&s.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,s]of this.list)s.dispose();this.list.clear(),this.onDisposed.trigger()}};i(o,"uuid","d5d8bdf0-db25-4952-b951-b643af207ace");let h=o;export{h as R}; diff --git a/examples/assets/index-C2l-cS9k.js b/examples/assets/index-C2l-cS9k.js new file mode 100644 index 000000000..a52bda774 --- /dev/null +++ b/examples/assets/index-C2l-cS9k.js @@ -0,0 +1,62 @@ +var h=Object.defineProperty;var g=(s,i,e)=>i in s?h(s,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[i]=e;var o=(s,i,e)=>(g(s,typeof i!="symbol"?i+"":i,e),e);import{k as f,l as p,m as v,b as w,C as z}from"./three.module-CYx2Afzj.js";import{E as a,D as _,b as r,c as x}from"./index-DCLJCpH4.js";class D{constructor(i,e,t){o(this,"onDisposed",new a);o(this,"world");o(this,"components");o(this,"_grid");o(this,"_fade",3);o(this,"updateZoom",()=>{this.world.camera instanceof r&&(this.material.uniforms.uZoom.value=this.world.camera.three.zoom)});this.world=e;const{color:n,size1:d,size2:l,distance:u}=t;this.components=i;const m=new f(2,2,1,1),c=new p({side:v,uniforms:{uSize1:{value:d},uSize2:{value:l},uColor:{value:n},uDistance:{value:u},uFade:{value:this._fade},uZoom:{value:1}},transparent:!0,vertexShader:` + + varying vec3 worldPosition; + + uniform float uDistance; + + void main() { + + vec3 pos = position.xzy * uDistance; + pos.xz += cameraPosition.xz; + + worldPosition = pos; + + gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0); + + } + `,fragmentShader:` + + varying vec3 worldPosition; + + uniform float uZoom; + uniform float uFade; + uniform float uSize1; + uniform float uSize2; + uniform vec3 uColor; + uniform float uDistance; + + + + float getGrid(float size) { + + vec2 r = worldPosition.xz / size; + + + vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r); + float line = min(grid.x, grid.y); + + + return 1.0 - min(line, 1.0); + } + + void main() { + + + float d = 1.0 - min(distance(cameraPosition.xz, worldPosition.xz) / uDistance, 1.0); + + float g1 = getGrid(uSize1); + float g2 = getGrid(uSize2); + + // Ortho camera fades the grid away when zooming out + float minZoom = step(0.2, uZoom); + float zoomFactor = pow(min(uZoom, 1.), 2.) * minZoom; + + gl_FragColor = vec4(uColor.rgb, mix(g2, g1, g1) * pow(d, uFade)); + gl_FragColor.a = mix(0.5 * gl_FragColor.a, gl_FragColor.a, g2) * zoomFactor; + + if ( gl_FragColor.a <= 0.0 ) discard; + + + } + + `,extensions:{derivatives:!0}});this._grid=new w(m,c),this._grid.frustumCulled=!1,e.scene.three.add(this._grid),this.setupEvents(!0)}get visible(){return this._grid.visible}set visible(i){i?this.world.scene.three.add(this._grid):this._grid.removeFromParent()}get material(){return this._grid.material}get fade(){return this._fade===3}set fade(i){this._fade=i?3:0,this.material.uniforms.uFade.value=this._fade}[Symbol.dispose](){throw new Error("Method not implemented.")}get(){return this._grid}dispose(){this.setupEvents(!1),this.components.get(_).destroy(this._grid),this.onDisposed.trigger(),this.onDisposed.reset(),this.world=null,this.components=null}setupEvents(i){if(!(this.world.camera instanceof r))return;const e=this.world.camera.controls;i?e.addEventListener("update",this.updateZoom):e.removeEventListener("update",this.updateZoom)}}class C extends x{constructor(){super(...arguments);o(this,"list",new Map);o(this,"onDisposed",new a);o(this,"config",{color:new z(12303291),size1:1,size2:10,distance:500});o(this,"enabled",!0)}create(e){if(this.list.has(e.uuid))throw new Error("This world already has a grid!");const t=new D(this.components,e,this.config);this.list.set(e.uuid,t),e.onDisposed.add(()=>{this.delete(e)})}delete(e){const t=this.list.get(e.uuid);t&&t.dispose(),this.list.delete(e.uuid)}dispose(){for(const[e,t]of this.list)t.dispose();this.list.clear(),this.onDisposed.trigger()}}o(C,"uuid","d1e814d5-b81c-4452-87a2-f039375e0489");export{C as G}; diff --git a/examples/assets/index-DCLJCpH4.js b/examples/assets/index-DCLJCpH4.js new file mode 100644 index 000000000..42117132d --- /dev/null +++ b/examples/assets/index-DCLJCpH4.js @@ -0,0 +1,10 @@ +var qs=Object.defineProperty;var Ws=(n,e,t)=>e in n?qs(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var D=(n,e,t)=>(Ws(n,typeof e!="symbol"?e+"":e,t),t);import{r as Bs,V as S,a as ht,P as Fs,L as lt,T as Qt,S as zs,M as ut,B as st,H as $s,m as Ks,F as is,b as Rs,s as Qs,i as Gs,j as ns,C as Pe,c as js,D as Js,A as ti,W as os,d as ei,e as si,f as ii,Q as ni,g as oi,R as ri,h as ai}from"./three.module-CYx2Afzj.js";const Is=0,ci=1,li=2,rs=2,Ue=1.25,as=1,Te=6*4+4+4,Ce=65535,hi=Math.pow(2,-24),ve=Symbol("SKIP_GENERATION");function ui(n){return n.index?n.index.count:n.attributes.position.count}function Ft(n){return ui(n)/3}function fi(n,e=ArrayBuffer){return n>65535?new Uint32Array(new e(4*n)):new Uint16Array(new e(2*n))}function di(n,e){if(!n.index){const t=n.attributes.position.count,s=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=fi(t,s);n.setIndex(new Bs(i,1));for(let r=0;ra-c);for(let a=0;ar.offset-o.offset),s=t[t.length-1];s.count=Math.min(e-s.offset,s.count);let i=0;return t.forEach(({count:r})=>i+=r),e!==i}function Y(n,e,t){return t.min.x=e[n],t.min.y=e[n+1],t.min.z=e[n+2],t.max.x=e[n+3],t.max.y=e[n+4],t.max.z=e[n+5],t}function _i(n){n[0]=n[1]=n[2]=1/0,n[3]=n[4]=n[5]=-1/0}function cs(n){let e=-1,t=-1/0;for(let s=0;s<3;s++){const i=n[s+3]-n[s];i>t&&(t=i,e=s)}return e}function ls(n,e){e.set(n)}function hs(n,e,t){let s,i;for(let r=0;r<3;r++){const o=r+3;s=n[r],i=e[r],t[r]=si?s:i}}function te(n,e,t){for(let s=0;s<3;s++){const i=e[n+2*s],r=e[n+2*s+1],o=i-r,a=i+r;ot[s+3]&&(t[s+3]=a)}}function Ht(n){const e=n[3]-n[0],t=n[4]-n[1],s=n[5]-n[2];return 2*(e*t+t*s+s*e)}function Le(n,e,t,s,i=null){let r=1/0,o=1/0,a=1/0,c=-1/0,d=-1/0,f=-1/0,u=1/0,l=1/0,p=1/0,y=-1/0,O=-1/0,T=-1/0;const m=i!==null;for(let g=e*6,E=(e+t)*6;gc&&(c=w),m&&hy&&(y=h);const C=n[g+2],b=n[g+3],P=C-b,v=C+b;Pd&&(d=v),m&&CO&&(O=C);const U=n[g+4],L=n[g+5],M=U-L,R=U+L;Mf&&(f=R),m&&UT&&(T=U)}s[0]=r,s[1]=o,s[2]=a,s[3]=c,s[4]=d,s[5]=f,m&&(i[0]=u,i[1]=l,i[2]=p,i[3]=y,i[4]=O,i[5]=T)}function mi(n,e,t,s){let i=1/0,r=1/0,o=1/0,a=-1/0,c=-1/0,d=-1/0;for(let f=e*6,u=(e+t)*6;fa&&(a=l);const p=n[f+2];pc&&(c=p);const y=n[f+4];yd&&(d=y)}s[0]=i,s[1]=r,s[2]=o,s[3]=a,s[4]=c,s[5]=d}function yi(n,e){_i(e);const t=n.attributes.position,s=n.index?n.index.array:null,i=Ft(n),r=new Float32Array(i*6),o=t.normalized,a=t.array,c=t.offset||0;let d=3;t.isInterleavedBufferAttribute&&(d=t.data.stride);const f=["getX","getY","getZ"];for(let u=0;ux&&(x=E),h>x&&(x=h);const w=(x-_)/2,C=m*2;r[p+C+0]=_+w,r[p+C+1]=w+(Math.abs(_)+w)*hi,_e[m+3]&&(e[m+3]=x)}}return r}const ct=32,gi=(n,e)=>n.candidate-e.candidate,dt=new Array(ct).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),ee=new Float32Array(6);function Ti(n,e,t,s,i,r){let o=-1,a=0;if(r===Is)o=cs(e),o!==-1&&(a=(e[o]+e[o+3])/2);else if(r===ci)o=cs(n),o!==-1&&(a=Ei(t,s,i,o));else if(r===li){const c=Ht(n);let d=Ue*i;const f=s*6,u=(s+i)*6;for(let l=0;l<3;l++){const p=e[l],T=(e[l+3]-p)/ct;if(i=w.candidate?te(h,t,w.rightCacheBounds):(te(h,t,w.leftCacheBounds),w.count++)}}for(let h=0;h=ct&&(x=ct-1);const w=dt[x];w.count++,te(E,t,w.bounds)}const m=dt[ct-1];ls(m.bounds,m.rightCacheBounds);for(let E=ct-2;E>=0;E--){const h=dt[E],_=dt[E+1];hs(h.bounds,_.rightCacheBounds,h.rightCacheBounds)}let g=0;for(let E=0;E=c;)a--;if(o=c;)a--;if(o2**16,i=s?4:2,r=e?new SharedArrayBuffer(t*i):new ArrayBuffer(t*i),o=s?new Uint32Array(r):new Uint16Array(r);for(let a=0,c=o.length;a=i&&(u=!0,r&&(console.warn(`MeshBVH: Max depth of ${i} reached when generating BVH. Consider increasing maxDepth.`),console.warn(t))),x<=o||C>=i)return g(_+x),h.offset=_,h.count=x,h;const b=Ti(h.boundingData,w,y,_,x,a);if(b.axis===-1)return g(_+x),h.offset=_,h.count=x,h;const P=O(f,s,y,_,x,b);if(P===_||P===_+x)g(_+x),h.offset=_,h.count=x;else{h.splitAxis=b.axis;const v=new se,U=_,L=P-_;h.left=v,v.boundingData=new Float32Array(6),Le(y,U,L,v.boundingData,p),E(v,U,L,p,C+1);const M=new se,R=P,N=x-L;h.right=M,M.boundingData=new Float32Array(6),Le(y,R,N,M.boundingData,p),E(M,R,N,p,C+1)}return h}}function Ci(n,e){const t=n.geometry;e.indirect&&(n._indirectBuffer=Oi(t,e.useSharedArrayBuffer),pi(t)&&!e.verbose&&console.warn('MeshBVH: Provided geometry contains groups that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),n._indirectBuffer||di(t,e);const s=Ai(n,e);let i,r,o;const a=[],c=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer;for(let u=0;uMath.pow(2,32))throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return r[p+6]=h/4,h=f(h,g),r[p+7]=E,h}}}class ft{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let s=1/0,i=-1/0;for(let r=0,o=e.length;ri?c:i}this.min=s,this.max=i}setFromPoints(e,t){let s=1/0,i=-1/0;for(let r=0,o=t.length;ri?c:i}this.min=s,this.max=i}isSeparated(e){return this.min>e.max||e.min>this.max}}ft.prototype.setFromBox=function(){const n=new S;return function(t,s){const i=s.min,r=s.max;let o=1/0,a=-1/0;for(let c=0;c<=1;c++)for(let d=0;d<=1;d++)for(let f=0;f<=1;f++){n.x=i.x*c+r.x*(1-c),n.y=i.y*d+r.y*(1-d),n.z=i.z*f+r.z*(1-f);const u=t.dot(n);o=Math.min(u,o),a=Math.max(u,a)}this.min=o,this.max=a}}();const bi=function(){const n=new S,e=new S,t=new S;return function(i,r,o){const a=i.start,c=n,d=r.start,f=e;t.subVectors(a,d),n.subVectors(i.end,i.start),e.subVectors(r.end,r.start);const u=t.dot(f),l=f.dot(c),p=f.dot(f),y=t.dot(c),T=c.dot(c)*p-l*l;let m,g;T!==0?m=(u*l-y*p)/T:m=0,g=(u+m*l)/p,o.x=m,o.y=g}}(),je=function(){const n=new ht,e=new S,t=new S;return function(i,r,o,a){bi(i,r,n);let c=n.x,d=n.y;if(c>=0&&c<=1&&d>=0&&d<=1){i.at(c,o),r.at(d,a);return}else if(c>=0&&c<=1){d<0?r.at(0,a):r.at(1,a),i.closestPointToPoint(a,!0,o);return}else if(d>=0&&d<=1){c<0?i.at(0,o):i.at(1,o),r.closestPointToPoint(o,!0,a);return}else{let f;c<0?f=i.start:f=i.end;let u;d<0?u=r.start:u=r.end;const l=e,p=t;if(i.closestPointToPoint(u,!0,e),r.closestPointToPoint(f,!0,t),l.distanceToSquared(u)<=p.distanceToSquared(f)){o.copy(l),a.copy(u);return}else{o.copy(f),a.copy(p);return}}}}(),Pi=function(){const n=new S,e=new S,t=new Fs,s=new lt;return function(r,o){const{radius:a,center:c}=r,{a:d,b:f,c:u}=o;if(s.start=d,s.end=f,s.closestPointToPoint(c,!0,n).distanceTo(c)<=a||(s.start=d,s.end=u,s.closestPointToPoint(c,!0,n).distanceTo(c)<=a)||(s.start=f,s.end=u,s.closestPointToPoint(c,!0,n).distanceTo(c)<=a))return!0;const O=o.getPlane(t);if(Math.abs(O.distanceToPoint(c))<=a){const m=O.projectPoint(c,e);if(o.containsPoint(m))return!0}return!1}}(),Ui=1e-15;function De(n){return Math.abs(n)new S),this.satBounds=new Array(4).fill().map(()=>new ft),this.points=[this.a,this.b,this.c],this.sphere=new zs,this.plane=new Fs,this.needsUpdate=!0}intersectsSphere(e){return Pi(e,this)}update(){const e=this.a,t=this.b,s=this.c,i=this.points,r=this.satAxes,o=this.satBounds,a=r[0],c=o[0];this.getNormal(a),c.setFromPoints(a,i);const d=r[1],f=o[1];d.subVectors(e,t),f.setFromPoints(d,i);const u=r[2],l=o[2];u.subVectors(t,s),l.setFromPoints(u,i);const p=r[3],y=o[3];p.subVectors(s,e),y.setFromPoints(p,i),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(a,e),this.needsUpdate=!1}}ot.prototype.closestPointToSegment=function(){const n=new S,e=new S,t=new lt;return function(i,r=null,o=null){const{start:a,end:c}=i,d=this.points;let f,u=1/0;for(let l=0;l<3;l++){const p=(l+1)%3;t.start.copy(d[l]),t.end.copy(d[p]),je(t,i,n,e),f=n.distanceToSquared(e),f=2){(h===1?m.start:m.end).copy(p),E=2;break}if(E++,E===2&&h===-1)break}}return E}return function(T,m=null,g=!1){this.needsUpdate&&this.update(),T.isExtendedTriangle?T.needsUpdate&&T.update():(n.copy(T),n.update(),T=n);const E=this.plane,h=T.plane;if(Math.abs(E.normal.dot(h.normal))>1-1e-10){const _=this.satBounds,x=this.satAxes;t[0]=T.a,t[1]=T.b,t[2]=T.c;for(let b=0;b<4;b++){const P=_[b],v=x[b];if(s.setFromPoints(v,t),P.isSeparated(s))return!1}const w=T.satBounds,C=T.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let b=0;b<4;b++){const P=w[b],v=C[b];if(s.setFromPoints(v,e),P.isSeparated(s))return!1}for(let b=0;b<4;b++){const P=x[b];for(let v=0;v<4;v++){const U=C[v];if(r.crossVectors(P,U),s.setFromPoints(r,e),i.setFromPoints(r,t),s.isSeparated(i))return!1}}return m&&(g||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),m.start.set(0,0,0),m.end.set(0,0,0)),!0}else{const _=y(this,h,u);if(_===1&&T.containsPoint(u.end))return m&&(m.start.copy(u.end),m.end.copy(u.end)),!0;if(_!==2)return!1;const x=y(T,E,l);if(x===1&&this.containsPoint(l.end))return m&&(m.start.copy(l.end),m.end.copy(l.end)),!0;if(x!==2)return!1;if(u.delta(a),l.delta(c),a.dot(c)<0){let L=l.start;l.start=l.end,l.end=L}const w=u.start.dot(a),C=u.end.dot(a),b=l.start.dot(a),P=l.end.dot(a),v=C0?m.start.copy(u.start):m.start.copy(l.start),d.subVectors(u.end,l.end),d.dot(a)<0?m.end.copy(u.end):m.end.copy(l.end)),!0)}}}();ot.prototype.distanceToPoint=function(){const n=new S;return function(t){return this.closestPointToPoint(t,n),t.distanceTo(n)}}();ot.prototype.distanceToTriangle=function(){const n=new S,e=new S,t=["a","b","c"],s=new lt,i=new lt;return function(o,a=null,c=null){const d=a||c?s:null;if(this.intersectsTriangle(o,d))return(a||c)&&(a&&d.getCenter(a),c&&d.getCenter(c)),0;let f=1/0;for(let u=0;u<3;u++){let l;const p=t[u],y=o[p];this.closestPointToPoint(y,n),l=y.distanceToSquared(n),lnew S),this.satAxes=new Array(3).fill().map(()=>new S),this.satBounds=new Array(3).fill().map(()=>new ft),this.alignedSatBounds=new Array(3).fill().map(()=>new ft),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),s&&this.matrix.copy(s)}set(e,t,s){this.min.copy(e),this.max.copy(t),this.matrix.copy(s),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}W.prototype.update=function(){return function(){const e=this.matrix,t=this.min,s=this.max,i=this.points;for(let d=0;d<=1;d++)for(let f=0;f<=1;f++)for(let u=0;u<=1;u++){const l=1*d|2*f|4*u,p=i[l];p.x=d?s.x:t.x,p.y=f?s.y:t.y,p.z=u?s.z:t.z,p.applyMatrix4(e)}const r=this.satBounds,o=this.satAxes,a=i[0];for(let d=0;d<3;d++){const f=o[d],u=r[d],l=1<new lt),t=new Array(12).fill().map(()=>new lt),s=new S,i=new S;return function(o,a=0,c=null,d=null){if(this.needsUpdate&&this.update(),this.intersectsBox(o))return(c||d)&&(o.getCenter(i),this.closestPointToPoint(i,s),o.closestPointToPoint(s,i),c&&c.copy(s),d&&d.copy(i)),0;const f=a*a,u=o.min,l=o.max,p=this.points;let y=1/0;for(let T=0;T<8;T++){const m=p[T];i.copy(m).clamp(u,l);const g=m.distanceToSquared(i);if(gnew ot)}}const j=new vi;function K(n,e){return e[n+15]===65535}function Q(n,e){return e[n+6]}function J(n,e){return e[n+14]}function tt(n){return n+8}function et(n,e){return e[n+6]}function Vs(n,e){return e[n+7]}class Li{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=s=>{t&&e.push(t),t=s,this.float32Array=new Float32Array(s),this.uint16Array=new Uint16Array(s),this.uint32Array=new Uint32Array(s)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const V=new Li;let mt,Bt;const Et=[],ie=new Je(()=>new st);function Di(n,e,t,s,i,r){mt=ie.getPrimitive(),Bt=ie.getPrimitive(),Et.push(mt,Bt),V.setBuffer(n._roots[e]);const o=Xe(0,n.geometry,t,s,i,r);V.clearBuffer(),ie.releasePrimitive(mt),ie.releasePrimitive(Bt),Et.pop(),Et.pop();const a=Et.length;return a>0&&(Bt=Et[a-1],mt=Et[a-2]),o}function Xe(n,e,t,s,i=null,r=0,o=0){const{float32Array:a,uint16Array:c,uint32Array:d}=V;let f=n*2;if(K(f,c)){const l=Q(n,d),p=J(f,c);return Y(n,a,mt),s(l,p,!1,o,r+n,mt)}else{let P=function(U){const{uint16Array:L,uint32Array:M}=V;let R=U*2;for(;!K(R,L);)U=tt(U),R=U*2;return Q(U,M)},v=function(U){const{uint16Array:L,uint32Array:M}=V;let R=U*2;for(;!K(R,L);)U=et(U,M),R=U*2;return Q(U,M)+J(R,L)};const l=tt(n),p=et(n,d);let y=l,O=p,T,m,g,E;if(i&&(g=mt,E=Bt,Y(y,a,g),Y(O,a,E),T=i(g),m=i(E),m(kt.copy(e).clamp(f.min,f.max),kt.distanceToSquared(e)),intersectsBounds:(f,u,l)=>l{f.closestPointToPoint(e,kt);const l=e.distanceToSquared(kt);return l0&&d.normal.multiplyScalar(-1));const f={a:r,b:o,c:a,normal:new S,materialIndex:0};Qt.getNormal(xt,wt,Ot,f.normal),d.face=f,d.faceIndex=r}return d}function be(n,e,t,s,i){const r=s*3;let o=r+0,a=r+1,c=r+2;const d=n.index;n.index&&(o=d.getX(o),a=d.getX(a),c=d.getX(c));const{position:f,normal:u,uv:l,uv1:p}=n.attributes,y=Bi(t,f,u,l,p,o,a,c,e);return y?(y.faceIndex=s,i&&i.push(y),y):null}function q(n,e,t,s){const i=n.a,r=n.b,o=n.c;let a=e,c=e+1,d=e+2;t&&(a=t.getX(a),c=t.getX(c),d=t.getX(d)),i.x=s.getX(a),i.y=s.getY(a),i.z=s.getZ(a),r.x=s.getX(c),r.y=s.getY(c),r.z=s.getZ(c),o.x=s.getX(d),o.y=s.getY(d),o.z=s.getZ(d)}function Fi(n,e,t,s,i,r){const{geometry:o,_indirectBuffer:a}=n;for(let c=s,d=s+i;cx&&(x=U),Lw&&(w=L),M<_&&(_=M),M>C&&(C=M)}return c[l+0]!==E||c[l+1]!==h||c[l+2]!==_||c[l+3]!==x||c[l+4]!==w||c[l+5]!==C?(c[l+0]=E,c[l+1]=h,c[l+2]=_,c[l+3]=x,c[l+4]=w,c[l+5]=C,!0):!1}else{const m=l+8,g=o[l+6],E=m+p,h=g+p;let _=y,x=!1,w=!1;e?_||(x=e.has(E),w=e.has(h),_=!x&&!w):(x=!0,w=!0);const C=_||x,b=_||w;let P=!1;C&&(P=u(m,p,_));let v=!1;b&&(v=u(g,p,_));const U=P||v;if(U)for(let L=0;L<3;L++){const M=m+L,R=g+L,N=c[M],zt=c[M+3],Rt=c[R],It=c[R+3];c[l+L]=NIt?zt:It}return U}}}const ps=new st;function yt(n,e,t,s){return Y(n,e,ps),t.intersectBox(ps,s)}function Hi(n,e,t,s,i,r){const{geometry:o,_indirectBuffer:a}=n;for(let c=s,d=s+i;c=0;let p,y;l?(p=tt(n),y=et(n,o)):(p=et(n,o),y=tt(n));const T=yt(p,i,s,ms)?We(p,e,t,s):null;if(T){const E=T.point[f];if(l?E<=i[y+d]:E>=i[y+d+3])return T}const g=yt(y,i,s,ms)?We(y,e,t,s):null;return T&&g?T.distance<=g.distance?T:g:T||g||null}}const ce=new st,At=new ot,Ct=new ot,Vt=new ut,ys=new W,le=new W;function Xi(n,e,t,s){V.setBuffer(n._roots[e]);const i=$e(0,n,t,s);return V.clearBuffer(),i}function $e(n,e,t,s,i=null){const{float32Array:r,uint16Array:o,uint32Array:a}=V;let c=n*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),ys.set(t.boundingBox.min,t.boundingBox.max,s),i=ys),K(c,o)){const f=e.geometry,u=f.index,l=f.attributes.position,p=t.index,y=t.attributes.position,O=Q(n,a),T=J(c,o);if(Vt.copy(s).invert(),t.boundsTree)return Y(n,r,le),le.matrix.copy(Vt),le.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:g=>le.intersectsBox(g),intersectsTriangle:g=>{g.a.applyMatrix4(s),g.b.applyMatrix4(s),g.c.applyMatrix4(s),g.needsUpdate=!0;for(let E=O*3,h=(T+O)*3;EMe.distanceToBox(_),intersectsBounds:(_,x,w)=>w{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:C=>Yt.distanceToBox(C),intersectsBounds:(C,b,P)=>P{for(let P=C,v=C+b;Px&&(x=M),Rw&&(w=R),N<_&&(_=N),N>C&&(C=N)}}return c[l+0]!==E||c[l+1]!==h||c[l+2]!==_||c[l+3]!==x||c[l+4]!==w||c[l+5]!==C?(c[l+0]=E,c[l+1]=h,c[l+2]=_,c[l+3]=x,c[l+4]=w,c[l+5]=C,!0):!1}else{const m=l+8,g=o[l+6],E=m+p,h=g+p;let _=y,x=!1,w=!1;e?_||(x=e.has(E),w=e.has(h),_=!x&&!w):(x=!0,w=!0);const C=_||x,b=_||w;let P=!1;C&&(P=u(m,p,_));let v=!1;b&&(v=u(g,p,_));const U=P||v;if(U)for(let L=0;L<3;L++){const M=m+L,R=g+L,N=c[M],zt=c[M+3],Rt=c[R],It=c[R+3];c[l+L]=NIt?zt:It}return U}}}const gs=new S;function ji(n,e,t,s,i){V.setBuffer(n._roots[e]),Ke(0,n,t,s,i),V.clearBuffer()}function Ke(n,e,t,s,i){const{float32Array:r,uint16Array:o,uint32Array:a}=V,c=n*2;if(K(c,o)){const f=Q(n,a),u=J(c,o);Hi(e,t,s,f,u,i)}else{const f=tt(n);yt(f,r,s,gs)&&Ke(f,e,t,s,i);const u=et(n,a);yt(u,r,s,gs)&&Ke(u,e,t,s,i)}}const Ts=new S,Ji=["x","y","z"];function tn(n,e,t,s){V.setBuffer(n._roots[e]);const i=Qe(0,n,t,s);return V.clearBuffer(),i}function Qe(n,e,t,s){const{float32Array:i,uint16Array:r,uint32Array:o}=V;let a=n*2;if(K(a,r)){const d=Q(n,o),f=J(a,r);return ki(e,t,s,d,f)}else{const d=Vs(n,o),f=Ji[d],l=s.direction[f]>=0;let p,y;l?(p=tt(n),y=et(n,o)):(p=et(n,o),y=tt(n));const T=yt(p,i,s,Ts)?Qe(p,e,t,s):null;if(T){const E=T.point[f];if(l?E<=i[y+d]:E>=i[y+d+3])return T}const g=yt(y,i,s,Ts)?Qe(y,e,t,s):null;return T&&g?T.distance<=g.distance?T:g:T||g||null}}const ue=new st,bt=new ot,Pt=new ot,Nt=new ut,Es=new W,fe=new W;function en(n,e,t,s){V.setBuffer(n._roots[e]);const i=Ge(0,n,t,s);return V.clearBuffer(),i}function Ge(n,e,t,s,i=null){const{float32Array:r,uint16Array:o,uint32Array:a}=V;let c=n*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Es.set(t.boundingBox.min,t.boundingBox.max,s),i=Es),K(c,o)){const f=e.geometry,u=f.index,l=f.attributes.position,p=t.index,y=t.attributes.position,O=Q(n,a),T=J(c,o);if(Nt.copy(s).invert(),t.boundsTree)return Y(n,r,fe),fe.matrix.copy(Nt),fe.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:g=>fe.intersectsBox(g),intersectsTriangle:g=>{g.a.applyMatrix4(s),g.b.applyMatrix4(s),g.c.applyMatrix4(s),g.needsUpdate=!0;for(let E=O,h=T+O;EBe.distanceToBox(_),intersectsBounds:(_,x,w)=>w{if(e.boundsTree){const w=e.boundsTree;return w.shapecast({boundsTraverseOrder:C=>Zt.distanceToBox(C),intersectsBounds:(C,b,P)=>P{for(let P=C,v=C+b;Pnew st),Ut=new st,vt=new st,Fe=new st,ze=new st;let Re=!1;function ln(n,e,t,s){if(Re)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Re=!0;const i=n._roots,r=e._roots;let o,a=0,c=0;const d=new ut().copy(t).invert();for(let f=0,u=i.length;fc.slice()),index:o.array.slice(),indirectBuffer:r?r.slice():null}:a={roots:i,index:o.array,indirectBuffer:r},a}static deserialize(e,t,s={}){s={setIndex:!0,indirect:!!e.indirectBuffer,...s};const{index:i,roots:r,indirectBuffer:o}=e,a=new ts(t,{...s,[ve]:!0});if(a._roots=r,a._indirectBuffer=o||null,s.setIndex){const c=t.getIndex();if(c===null){const d=new Bs(e.index,1,!1);t.setIndex(d)}else c.array!==i&&(c.array.set(i),c.needsUpdate=!0)}return a}get indirect(){return!!this._indirectBuffer}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t=Object.assign({strategy:Is,maxDepth:40,maxLeafTris:10,verbose:!0,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,[ve]:!1},t),t.useSharedArrayBuffer&&!cn())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[ve]||(Ci(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new st)));const{_indirectBuffer:s}=this;this.resolveTriangleIndex=t.indirect?i=>s[i]:i=>i}refit(e=null){return(this.indirect?Gi:Ii)(this,e)}traverse(e,t=0){const s=this._roots[t],i=new Uint32Array(s),r=new Uint16Array(s);o(0);function o(a,c=0){const d=a*2,f=r[d+15]===Ce;if(f){const u=i[a+6],l=r[d+14];e(c,f,new Float32Array(s,a*4,6),u,l)}else{const u=a+Te/4,l=i[a+6],p=i[a+7];e(c,f,new Float32Array(s,a*4,6),p)||(o(u,c+1),o(l,c+1))}}}raycast(e,t=is){const s=this._roots,i=this.geometry,r=[],o=t.isMaterial,a=Array.isArray(t),c=i.groups,d=o?t.side:t,f=this.indirect?ji:Yi;for(let u=0,l=s.length;uu(l,p,y,O,T)?!0:s(l,p,this,a,y,O,t)}else o||(a?o=(u,l,p,y)=>s(u,l,this,a,p,y,t):o=(u,l,p)=>p);let c=!1,d=0;const f=this._roots;for(let u=0,l=f.length;u{const O=this.resolveTriangleIndex(y);q(o,O*3,a,c)}:y=>{q(o,y*3,a,c)},f=j.getPrimitive(),u=e.geometry.index,l=e.geometry.attributes.position,p=e.indirect?y=>{const O=e.resolveTriangleIndex(y);q(f,O*3,u,l)}:y=>{q(f,y*3,u,l)};if(r){const y=(O,T,m,g,E,h,_,x)=>{for(let w=m,C=m+g;wpe.intersectsBox(s),intersectsTriangle:s=>pe.intersectsTriangle(s)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,s={},i={},r=0,o=1/0){return(this.indirect?an:Qi)(this,e,t,s,i,r,o)}closestPointToPoint(e,t={},s=0,i=1/0){return Si(this,e,t,s,i)}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(s=>{Y(0,new Float32Array(s),xs),e.union(xs)}),e}}function ws(n,e,t){return n===null||(n.point.applyMatrix4(e.matrixWorld),n.distance=n.point.distanceTo(t.ray.origin),n.object=e,n.distancet.far)?null:n}const Ie=new Qs,Os=new ut,hn=Rs.prototype.raycast;function un(n,e){if(this.geometry.boundsTree){if(this.material===void 0)return;Os.copy(this.matrixWorld).invert(),Ie.copy(n.ray).applyMatrix4(Os);const t=this.geometry.boundsTree;if(n.firstHitOnly===!0){const s=ws(t.raycastFirst(Ie,this.material),this,n);s&&e.push(s)}else{const s=t.raycast(Ie,this.material);for(let i=0,r=s.length;i{const t=this.handlers.slice(0);for(const s of t)s(e)});D(this,"handlers",[])}add(e){this.handlers.push(e)}remove(e){this.handlers=this.handlers.filter(t=>t!==e)}reset(){this.handlers.length=0}}class es{constructor(e){D(this,"isDisposeable",()=>"dispose"in this&&"onDisposed"in this);D(this,"isResizeable",()=>"resize"in this&&"getSize"in this);D(this,"isUpdateable",()=>"onAfterUpdate"in this&&"onBeforeUpdate"in this&&"update"in this);D(this,"isHideable",()=>"visible"in this);D(this,"isConfigurable",()=>"setup"in this&&"config"in this&&"onSetup"in this);this.components=e}}class Ys extends es{}class ss extends es{constructor(t){super(t);D(this,"worlds",new Map);D(this,"onWorldChanged",new X);D(this,"currentWorld",null);this.onWorldChanged.add(({world:s,action:i})=>{i==="removed"&&this.worlds.delete(s.uuid)})}}class pn extends ss{constructor(){super(...arguments);D(this,"hasCameraControls",()=>"controls"in this)}}class _n extends ss{constructor(){super(...arguments);D(this,"onAfterUpdate",new X);D(this,"onBeforeUpdate",new X);D(this,"onDisposed",new X);D(this,"onResize",new X);D(this,"onClippingPlanesUpdated",new X);D(this,"clippingPlanes",[])}updateClippingPlanes(){this.onClippingPlanesUpdated.trigger()}setPlane(t,s,i){s.isLocal=i;const r=this.clippingPlanes.indexOf(s);t&&r===-1?this.clippingPlanes.push(s):!t&&r>-1&&this.clippingPlanes.splice(r,1),this.three.clippingPlanes=this.clippingPlanes.filter(o=>!o.isLocal)}}const jt=class jt extends Ys{constructor(t){super(t);D(this,"_disposedComponents",new Set);D(this,"enabled",!0);t.add(jt.uuid,this)}get(){return this._disposedComponents}destroy(t,s=!0,i=!0){t.removeFromParent();const r=t;r.dispose&&r.dispose(),this.disposeGeometryAndMaterials(t,s),i&&r.children&&r.children.length&&this.disposeChildren(r),t.children.length=0}disposeGeometry(t){const s=t;s.boundsTree&&s.disposeBoundsTree(),t.dispose()}disposeGeometryAndMaterials(t,s){const i=t;i.geometry&&this.disposeGeometry(i.geometry),s&&i.material&&jt.disposeMaterial(i),i.material=[],i.geometry=null}disposeChildren(t){for(const s of t.children)this.destroy(s)}static disposeMaterial(t){if(t.material)if(Array.isArray(t.material))for(const s of t.material)s.dispose();else t.material.dispose()}};D(jt,"uuid","76e9cd8e-ad8f-4753-9ef6-cbc60f7247fe");let xe=jt;class mn extends ss{constructor(t){super(t);D(this,"onDisposed",new X)}dispose(){const t=this.components.get(xe);for(const s of this.three.children){const i=s;i.geometry&&t.destroy(i)}this.three.children=[],this.onDisposed.trigger(),this.onDisposed.reset()}}const Z=class Z{static create(){const e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,s=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return`${Z._lut[e&255]+Z._lut[e>>8&255]+Z._lut[e>>16&255]+Z._lut[e>>24&255]}-${Z._lut[t&255]}${Z._lut[t>>8&255]}-${Z._lut[t>>16&15|64]}${Z._lut[t>>24&255]}-${Z._lut[s&63|128]}${Z._lut[s>>8&255]}-${Z._lut[s>>16&255]}${Z._lut[s>>24&255]}${Z._lut[i&255]}${Z._lut[i>>8&255]}${Z._lut[i>>16&255]}${Z._lut[i>>24&255]}`.toLowerCase()}static validate(e){if(!Z._pattern.test(e))throw new Error(`${e} is not a valid UUID v4. + +- If you're the tool creator, you can take one from https://www.uuidgenerator.net/. + +- If you're using a platform tool, verify the uuid isn't misspelled or contact the tool creator.`)}};D(Z,"_pattern",/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/),D(Z,"_lut",["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"]);let we=Z;const Oe=class Oe{constructor(){D(this,"onDisposed",new X);D(this,"list",new Map);D(this,"enabled",!1);D(this,"_clock");D(this,"update",()=>{if(!this.enabled)return;const e=this._clock.getDelta();for(const[t,s]of this.list)s.enabled&&s.isUpdateable()&&s.update(e);requestAnimationFrame(this.update)});this._clock=new Gs,Oe.setupBVH()}add(e,t){if(this.list.has(e))throw new Error("You're trying to add a component that already exists in the components intance. Use Components.get() instead.");we.validate(e),this.list.set(e,t)}get(e){const t=e.uuid;if(!this.list.has(t)){const s=new e(this);return this.list.has(t)||this.add(t,s),s}return this.list.get(t)}init(){this.enabled=!0,this._clock.start(),this.update()}dispose(){this.enabled=!1;for(const[e,t]of this.list)t.enabled=!1,t.isDisposeable()&&t.dispose();this._clock.stop(),this.onDisposed.trigger(),this.onDisposed.reset()}static setupBVH(){ns.prototype.computeBoundsTree=fn,ns.prototype.disposeBoundsTree=dn,Rs.prototype.raycast=un}};D(Oe,"release","1.4.21");let As=Oe;class yn extends es{constructor(t){super(t);D(this,"meshes",new Set);D(this,"onAfterUpdate",new X);D(this,"onBeforeUpdate",new X);D(this,"enabled",!0);D(this,"uuid",we.create());D(this,"onDisposed",new X);D(this,"_scene");D(this,"_camera");D(this,"_renderer",null)}get scene(){if(!this._scene)throw new Error("No scene initialized!");return this._scene}set scene(t){this._scene=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get camera(){if(!this._camera)throw new Error("No camera initialized!");return this._camera}set camera(t){this._camera=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get renderer(){return this._renderer}set renderer(t){this._renderer=t,t&&(t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"}))}update(t){this.enabled&&(!this._scene||!this._camera||(this.scene.currentWorld=this,this.camera.currentWorld=this,this.renderer&&(this.renderer.currentWorld=this),this.onBeforeUpdate.trigger(),this.scene.isUpdateable()&&this.scene.update(t),this.camera.isUpdateable()&&this.camera.update(t),this.renderer&&this.renderer.update(t),this.onAfterUpdate.trigger()))}dispose(t=!0){if(this.enabled=!1,this.scene.onWorldChanged.trigger({world:this,action:"removed"}),this.camera.onWorldChanged.trigger({world:this,action:"removed"}),this.renderer&&this.renderer.onWorldChanged.trigger({world:this,action:"removed"}),t){const s=this.components.get(xe);this.scene.dispose(),this.camera.isDisposeable()&&this.camera.dispose(),this.renderer&&this.renderer.dispose();for(const i of this.meshes)s.destroy(i);this.meshes.clear()}this._scene=null,this._camera=null,this._renderer=null,this.onDisposed.trigger()}}class An extends mn{constructor(t){super(t);D(this,"isSetup",!1);D(this,"three");D(this,"onSetup",new X);D(this,"config",{directionalLight:{color:new Pe("white"),intensity:1.5,position:new S(5,10,3)},ambientLight:{color:new Pe("white"),intensity:1}});this.three=new js,this.three.background=new Pe(2107698)}setup(t){this.config={...this.config,...t};const s=new Js(this.config.directionalLight.color,this.config.directionalLight.intensity);s.position.copy(this.config.directionalLight.position);const i=new ti(this.config.ambientLight.color,this.config.ambientLight.intensity);this.three.add(s,i),this.isSetup=!0,this.onSetup.trigger(this)}}class Cn extends _n{constructor(t,s,i){super(t);D(this,"enabled",!0);D(this,"container");D(this,"three");D(this,"_canvas");D(this,"_parameters");D(this,"onContainerUpdated",new X);D(this,"resize",t=>{if(this.updateContainer(),!this.container)return;const s=t?t.x:this.container.clientWidth,i=t?t.y:this.container.clientHeight;this.three.setSize(s,i),this.onResize.trigger(new ht(s,i))});D(this,"resizeEvent",()=>{this.resize()});D(this,"onContextLost",t=>{t.preventDefault(),this.components.enabled=!1});D(this,"onContextBack",()=>{this.three.setRenderTarget(null),this.three.dispose(),this.three=new os({canvas:this._canvas,antialias:!0,alpha:!0,...this._parameters}),this.components.enabled=!0});this.container=s||null,this._parameters=i,this.three=new os({antialias:!0,alpha:!0,...i}),this.three.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.setupRenderer(),this.setupEvents(!0),this.resize(),this._canvas=this.three.domElement;const r=this.three.getContext(),{canvas:o}=r;o.addEventListener("webglcontextlost",this.onContextLost,!1),o.addEventListener("webglcontextrestored",this.onContextBack,!1)}update(){if(!this.enabled||!this.currentWorld)return;this.onBeforeUpdate.trigger(this);const t=this.currentWorld.scene.three,s=this.currentWorld.camera.three;this.three.render(t,s),this.onAfterUpdate.trigger(this)}dispose(){this.enabled=!1,this.setupEvents(!1),this.three.domElement.remove(),this.three.dispose(),this.onResize.reset(),this.onAfterUpdate.reset(),this.onBeforeUpdate.reset(),this.onDisposed.trigger(),this.onDisposed.reset()}getSize(){return new ht(this.three.domElement.clientWidth,this.three.domElement.clientHeight)}setupEvents(t){const s=this.three.domElement;t?s.addEventListener("resize",this.resizeEvent):s.removeEventListener("resize",this.resizeEvent)}setupRenderer(){this.three.localClippingEnabled=!0,this.container&&this.container.appendChild(this.three.domElement),this.updateContainer()}updateContainer(){if(!this.container){const t=this.three.domElement.parentElement;t&&(this.container=t,this.onContainerUpdated.trigger(t))}}}/*! + * camera-controls + * https://github.com/yomotsu/camera-controls + * (c) 2017 @yomotsu + * Released under the MIT License. + */const F={LEFT:1,RIGHT:2,MIDDLE:4},A=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,OFFSET:4,DOLLY:8,ZOOM:16,TOUCH_ROTATE:32,TOUCH_TRUCK:64,TOUCH_OFFSET:128,TOUCH_DOLLY:256,TOUCH_ZOOM:512,TOUCH_DOLLY_TRUCK:1024,TOUCH_DOLLY_OFFSET:2048,TOUCH_DOLLY_ROTATE:4096,TOUCH_ZOOM_TRUCK:8192,TOUCH_ZOOM_OFFSET:16384,TOUCH_ZOOM_ROTATE:32768}),Lt={NONE:0,IN:1,OUT:-1};function gt(n){return n.isPerspectiveCamera}function pt(n){return n.isOrthographicCamera}const Dt=Math.PI*2,Cs=Math.PI/2,Ns=1e-5,Xt=Math.PI/180;function nt(n,e,t){return Math.max(e,Math.min(t,n))}function k(n,e=Ns){return Math.abs(n)0==p>f&&(p=f,t.value=(p-f)/r),p}function Ps(n,e,t,s,i=1/0,r,o){s=Math.max(1e-4,s);const a=2/s,c=a*r,d=1/(1+c+.48*c*c+.235*c*c*c);let f=e.x,u=e.y,l=e.z,p=n.x-f,y=n.y-u,O=n.z-l;const T=f,m=u,g=l,E=i*s,h=E*E,_=p*p+y*y+O*O;if(_>h){const R=Math.sqrt(_);p=p/R*E,y=y/R*E,O=O/R*E}f=n.x-p,u=n.y-y,l=n.z-O;const x=(t.x+a*p)*r,w=(t.y+a*y)*r,C=(t.z+a*O)*r;t.x=(t.x-a*x)*d,t.y=(t.y-a*w)*d,t.z=(t.z-a*C)*d,o.x=f+(p+x)*d,o.y=u+(y+w)*d,o.z=l+(O+C)*d;const b=T-n.x,P=m-n.y,v=g-n.z,U=o.x-T,L=o.y-m,M=o.z-g;return b*U+P*L+v*M>0&&(o.x=T,o.y=m,o.z=g,t.x=(o.x-T)/r,t.y=(o.y-m)/r,t.z=(o.z-g)/r),o}function He(n,e){e.set(0,0),n.forEach(t=>{e.x+=t.clientX,e.y+=t.clientY}),e.x/=n.length,e.y/=n.length}function ke(n,e){return pt(n)?(console.warn(`${e} is not supported in OrthographicCamera`),!0):!1}class gn{constructor(){this._listeners={}}addEventListener(e,t){const s=this._listeners;s[e]===void 0&&(s[e]=[]),s[e].indexOf(t)===-1&&s[e].push(t)}hasEventListener(e,t){const s=this._listeners;return s[e]!==void 0&&s[e].indexOf(t)!==-1}removeEventListener(e,t){const i=this._listeners[e];if(i!==void 0){const r=i.indexOf(t);r!==-1&&i.splice(r,1)}}removeAllEventListeners(e){if(!e){this._listeners={};return}Array.isArray(this._listeners[e])&&(this._listeners[e].length=0)}dispatchEvent(e){const s=this._listeners[e.type];if(s!==void 0){e.target=this;const i=s.slice(0);for(let r=0,o=i.length;r{},this._enabled=!0,this._state=A.NONE,this._viewport=null,this._changedDolly=0,this._changedZoom=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=new DOMRect,this._isDragging=!1,this._dragNeedsUpdate=!0,this._activePointers=[],this._lockedPointer=null,this._interactiveArea=new DOMRect(0,0,1,1),this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._lastDollyDirection=Lt.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new B.Vector3,this._focalOffsetVelocity=new B.Vector3,this._zoomVelocity={value:0},this._truckInternal=(h,_,x)=>{let w,C;if(gt(this._camera)){const b=z.copy(this._camera.position).sub(this._target),P=this._camera.getEffectiveFOV()*Xt,v=b.length()*Math.tan(P*.5);w=this.truckSpeed*h*v/this._elementRect.height,C=this.truckSpeed*_*v/this._elementRect.height}else if(pt(this._camera)){const b=this._camera;w=h*(b.right-b.left)/b.zoom/this._elementRect.width,C=_*(b.top-b.bottom)/b.zoom/this._elementRect.height}else return;this.verticalDragToForward?(x?this.setFocalOffset(this._focalOffsetEnd.x+w,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(w,0,!0),this.forward(-C,!0)):x?this.setFocalOffset(this._focalOffsetEnd.x+w,this._focalOffsetEnd.y+C,this._focalOffsetEnd.z,!0):this.truck(w,C,!0)},this._rotateInternal=(h,_)=>{const x=Dt*this.azimuthRotateSpeed*h/this._elementRect.height,w=Dt*this.polarRotateSpeed*_/this._elementRect.height;this.rotate(x,w,!0)},this._dollyInternal=(h,_,x)=>{const w=Math.pow(.95,-h*this.dollySpeed),C=this._sphericalEnd.radius,b=this._sphericalEnd.radius*w,P=nt(b,this.minDistance,this.maxDistance),v=P-b;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(b,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(v,!0),this._dollyToNoClamp(P,!0)):this._dollyToNoClamp(P,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?b:P)-C,this._dollyControlCoord.set(_,x)),this._lastDollyDirection=Math.sign(-h)},this._zoomInternal=(h,_,x)=>{const w=Math.pow(.95,h*this.dollySpeed),C=this._zoom,b=this._zoom*w;this.zoomTo(b,!0),this.dollyToCursor&&(this._changedZoom+=b-C,this._dollyControlCoord.set(_,x))},typeof B>"u"&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=e,this._yAxisUpSpace=new B.Quaternion().setFromUnitVectors(this._camera.up,ye),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=A.NONE,this._target=new B.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new B.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new B.Spherical().setFromVector3(z.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._lastDistance=this._spherical.radius,this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._lastZoom=this._zoom,this._nearPlaneCorners=[new B.Vector3,new B.Vector3,new B.Vector3,new B.Vector3],this._updateNearPlaneCorners(),this._boundary=new B.Box3(new B.Vector3(-1/0,-1/0,-1/0),new B.Vector3(1/0,1/0,1/0)),this._cameraUp0=this._camera.up.clone(),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlCoord=new B.Vector2,this.mouseButtons={left:A.ROTATE,middle:A.DOLLY,right:A.TRUCK,wheel:gt(this._camera)?A.DOLLY:pt(this._camera)?A.ZOOM:A.NONE},this.touches={one:A.TOUCH_ROTATE,two:gt(this._camera)?A.TOUCH_DOLLY_TRUCK:pt(this._camera)?A.TOUCH_ZOOM_TRUCK:A.NONE,three:A.TOUCH_TRUCK};const s=new B.Vector2,i=new B.Vector2,r=new B.Vector2,o=h=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const w=this._domElement.getBoundingClientRect(),C=h.clientX/w.width,b=h.clientY/w.height;if(Cthis._interactiveArea.right||bthis._interactiveArea.bottom)return}const _=h.pointerType!=="mouse"?null:(h.buttons&F.LEFT)===F.LEFT?F.LEFT:(h.buttons&F.MIDDLE)===F.MIDDLE?F.MIDDLE:(h.buttons&F.RIGHT)===F.RIGHT?F.RIGHT:null;if(_!==null){const w=this._findPointerByMouseButton(_);w&&this._disposePointer(w)}if((h.buttons&F.LEFT)===F.LEFT&&this._lockedPointer)return;const x={pointerId:h.pointerId,clientX:h.clientX,clientY:h.clientY,deltaX:0,deltaY:0,mouseButton:_};this._activePointers.push(x),this._domElement.ownerDocument.removeEventListener("pointermove",c,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",f),this._domElement.ownerDocument.addEventListener("pointermove",c,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",f),this._isDragging=!0,O(h)},a=h=>{if(!this._enabled||!this._domElement||this._lockedPointer)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const w=this._domElement.getBoundingClientRect(),C=h.clientX/w.width,b=h.clientY/w.height;if(Cthis._interactiveArea.right||bthis._interactiveArea.bottom)return}const _=(h.buttons&F.LEFT)===F.LEFT?F.LEFT:(h.buttons&F.MIDDLE)===F.MIDDLE?F.MIDDLE:(h.buttons&F.RIGHT)===F.RIGHT?F.RIGHT:null;if(_!==null){const w=this._findPointerByMouseButton(_);w&&this._disposePointer(w)}const x={pointerId:1,clientX:h.clientX,clientY:h.clientY,deltaX:0,deltaY:0,mouseButton:(h.buttons&F.LEFT)===F.LEFT?F.LEFT:(h.buttons&F.MIDDLE)===F.LEFT?F.MIDDLE:(h.buttons&F.RIGHT)===F.LEFT?F.RIGHT:null};this._activePointers.push(x),this._domElement.ownerDocument.removeEventListener("mousemove",d),this._domElement.ownerDocument.removeEventListener("mouseup",u),this._domElement.ownerDocument.addEventListener("mousemove",d),this._domElement.ownerDocument.addEventListener("mouseup",u),this._isDragging=!0,O(h)},c=h=>{h.cancelable&&h.preventDefault();const _=h.pointerId,x=this._lockedPointer||this._findPointerById(_);if(x){if(x.clientX=h.clientX,x.clientY=h.clientY,x.deltaX=h.movementX,x.deltaY=h.movementY,this._state=0,h.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(h.buttons&F.LEFT)===F.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(h.buttons&F.MIDDLE)===F.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(h.buttons&F.RIGHT)===F.RIGHT&&(this._state=this._state|this.mouseButtons.right);T()}},d=h=>{const _=this._lockedPointer||this._findPointerById(1);_&&(_.clientX=h.clientX,_.clientY=h.clientY,_.deltaX=h.movementX,_.deltaY=h.movementY,this._state=0,(this._lockedPointer||(h.buttons&F.LEFT)===F.LEFT)&&(this._state=this._state|this.mouseButtons.left),(h.buttons&F.MIDDLE)===F.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(h.buttons&F.RIGHT)===F.RIGHT&&(this._state=this._state|this.mouseButtons.right),T())},f=h=>{const _=this._findPointerById(h.pointerId);if(!(_&&_===this._lockedPointer)){if(_&&this._disposePointer(_),h.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=A.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=A.NONE;m()}},u=()=>{const h=this._findPointerById(1);h&&h===this._lockedPointer||(h&&this._disposePointer(h),this._state=A.NONE,m())};let l=-1;const p=h=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===A.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const b=this._domElement.getBoundingClientRect(),P=h.clientX/b.width,v=h.clientY/b.height;if(Pthis._interactiveArea.right||vthis._interactiveArea.bottom)return}if(h.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===A.ROTATE||this.mouseButtons.wheel===A.TRUCK){const b=performance.now();l-b<1e3&&this._getClientRect(this._elementRect),l=b}const _=En?-1:-3,x=h.deltaMode===1?h.deltaY/_:h.deltaY/(_*10),w=this.dollyToCursor?(h.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,C=this.dollyToCursor?(h.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case A.ROTATE:{this._rotateInternal(h.deltaX,h.deltaY),this._isUserControllingRotate=!0;break}case A.TRUCK:{this._truckInternal(h.deltaX,h.deltaY,!1),this._isUserControllingTruck=!0;break}case A.OFFSET:{this._truckInternal(h.deltaX,h.deltaY,!0),this._isUserControllingOffset=!0;break}case A.DOLLY:{this._dollyInternal(-x,w,C),this._isUserControllingDolly=!0;break}case A.ZOOM:{this._zoomInternal(-x,w,C),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},y=h=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===Jt.ACTION.NONE){const _=h instanceof PointerEvent?h.pointerId:(h instanceof MouseEvent,0),x=this._findPointerById(_);x&&this._disposePointer(x),this._domElement.ownerDocument.removeEventListener("pointermove",c,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",f),this._domElement.ownerDocument.removeEventListener("mousemove",d),this._domElement.ownerDocument.removeEventListener("mouseup",u);return}h.preventDefault()}},O=h=>{if(!this._enabled)return;if(He(this._activePointers,$),this._getClientRect(this._elementRect),s.copy($),i.copy($),this._activePointers.length>=2){const x=$.x-this._activePointers[1].clientX,w=$.y-this._activePointers[1].clientY,C=Math.sqrt(x*x+w*w);r.set(0,C);const b=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,P=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;i.set(b,P)}if(this._state=0,!h)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in h&&h.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else!this._lockedPointer&&(h.buttons&F.LEFT)===F.LEFT&&(this._state=this._state|this.mouseButtons.left),(h.buttons&F.MIDDLE)===F.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(h.buttons&F.RIGHT)===F.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&A.ROTATE)===A.ROTATE||(this._state&A.TOUCH_ROTATE)===A.TOUCH_ROTATE||(this._state&A.TOUCH_DOLLY_ROTATE)===A.TOUCH_DOLLY_ROTATE||(this._state&A.TOUCH_ZOOM_ROTATE)===A.TOUCH_ZOOM_ROTATE)&&(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),((this._state&A.TRUCK)===A.TRUCK||(this._state&A.TOUCH_TRUCK)===A.TOUCH_TRUCK||(this._state&A.TOUCH_DOLLY_TRUCK)===A.TOUCH_DOLLY_TRUCK||(this._state&A.TOUCH_ZOOM_TRUCK)===A.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&A.DOLLY)===A.DOLLY||(this._state&A.TOUCH_DOLLY)===A.TOUCH_DOLLY||(this._state&A.TOUCH_DOLLY_TRUCK)===A.TOUCH_DOLLY_TRUCK||(this._state&A.TOUCH_DOLLY_OFFSET)===A.TOUCH_DOLLY_OFFSET||(this._state&A.TOUCH_DOLLY_ROTATE)===A.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&A.ZOOM)===A.ZOOM||(this._state&A.TOUCH_ZOOM)===A.TOUCH_ZOOM||(this._state&A.TOUCH_ZOOM_TRUCK)===A.TOUCH_ZOOM_TRUCK||(this._state&A.TOUCH_ZOOM_OFFSET)===A.TOUCH_ZOOM_OFFSET||(this._state&A.TOUCH_ZOOM_ROTATE)===A.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&A.OFFSET)===A.OFFSET||(this._state&A.TOUCH_OFFSET)===A.TOUCH_OFFSET||(this._state&A.TOUCH_DOLLY_OFFSET)===A.TOUCH_DOLLY_OFFSET||(this._state&A.TOUCH_ZOOM_OFFSET)===A.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},T=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,He(this._activePointers,$);const _=this._domElement&&document.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,x=_?-_.deltaX:i.x-$.x,w=_?-_.deltaY:i.y-$.y;if(i.copy($),((this._state&A.ROTATE)===A.ROTATE||(this._state&A.TOUCH_ROTATE)===A.TOUCH_ROTATE||(this._state&A.TOUCH_DOLLY_ROTATE)===A.TOUCH_DOLLY_ROTATE||(this._state&A.TOUCH_ZOOM_ROTATE)===A.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(x,w),this._isUserControllingRotate=!0),(this._state&A.DOLLY)===A.DOLLY||(this._state&A.ZOOM)===A.ZOOM){const C=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,b=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0,P=this.dollyDragInverted?-1:1;(this._state&A.DOLLY)===A.DOLLY?(this._dollyInternal(P*w*me,C,b),this._isUserControllingDolly=!0):(this._zoomInternal(P*w*me,C,b),this._isUserControllingZoom=!0)}if((this._state&A.TOUCH_DOLLY)===A.TOUCH_DOLLY||(this._state&A.TOUCH_ZOOM)===A.TOUCH_ZOOM||(this._state&A.TOUCH_DOLLY_TRUCK)===A.TOUCH_DOLLY_TRUCK||(this._state&A.TOUCH_ZOOM_TRUCK)===A.TOUCH_ZOOM_TRUCK||(this._state&A.TOUCH_DOLLY_OFFSET)===A.TOUCH_DOLLY_OFFSET||(this._state&A.TOUCH_ZOOM_OFFSET)===A.TOUCH_ZOOM_OFFSET||(this._state&A.TOUCH_DOLLY_ROTATE)===A.TOUCH_DOLLY_ROTATE||(this._state&A.TOUCH_ZOOM_ROTATE)===A.TOUCH_ZOOM_ROTATE){const C=$.x-this._activePointers[1].clientX,b=$.y-this._activePointers[1].clientY,P=Math.sqrt(C*C+b*b),v=r.y-P;r.set(0,P);const U=this.dollyToCursor?(i.x-this._elementRect.x)/this._elementRect.width*2-1:0,L=this.dollyToCursor?(i.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&A.TOUCH_DOLLY)===A.TOUCH_DOLLY||(this._state&A.TOUCH_DOLLY_ROTATE)===A.TOUCH_DOLLY_ROTATE||(this._state&A.TOUCH_DOLLY_TRUCK)===A.TOUCH_DOLLY_TRUCK||(this._state&A.TOUCH_DOLLY_OFFSET)===A.TOUCH_DOLLY_OFFSET?(this._dollyInternal(v*me,U,L),this._isUserControllingDolly=!0):(this._zoomInternal(v*me,U,L),this._isUserControllingZoom=!0)}((this._state&A.TRUCK)===A.TRUCK||(this._state&A.TOUCH_TRUCK)===A.TOUCH_TRUCK||(this._state&A.TOUCH_DOLLY_TRUCK)===A.TOUCH_DOLLY_TRUCK||(this._state&A.TOUCH_ZOOM_TRUCK)===A.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(x,w,!1),this._isUserControllingTruck=!0),((this._state&A.OFFSET)===A.OFFSET||(this._state&A.TOUCH_OFFSET)===A.TOUCH_OFFSET||(this._state&A.TOUCH_DOLLY_OFFSET)===A.TOUCH_DOLLY_OFFSET||(this._state&A.TOUCH_ZOOM_OFFSET)===A.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(x,w,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},m=()=>{He(this._activePointers,$),i.copy($),this._dragNeedsUpdate=!1,(this._activePointers.length===0||this._activePointers.length===1&&this._activePointers[0]===this._lockedPointer)&&(this._isDragging=!1),this._activePointers.length===0&&this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointermove",c,{passive:!1}),this._domElement.ownerDocument.removeEventListener("mousemove",d),this._domElement.ownerDocument.removeEventListener("pointerup",f),this._domElement.ownerDocument.removeEventListener("mouseup",u),this.dispatchEvent({type:"controlend"}))};this.lockPointer=()=>{!this._enabled||!this._domElement||(this.cancel(),this._lockedPointer={pointerId:-1,clientX:0,clientY:0,deltaX:0,deltaY:0,mouseButton:null},this._activePointers.push(this._lockedPointer),this._domElement.ownerDocument.removeEventListener("pointermove",c,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",f),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",g),this._domElement.ownerDocument.addEventListener("pointerlockerror",E),this._domElement.ownerDocument.addEventListener("pointermove",c,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",f),O())},this.unlockPointer=()=>{this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),document.exitPointerLock(),this.cancel(),this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointerlockchange",g),this._domElement.ownerDocument.removeEventListener("pointerlockerror",E))};const g=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},E=()=>{this.unlockPointer()};this._addAllEventListeners=h=>{this._domElement=h,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",o),xn&&this._domElement.addEventListener("mousedown",a),this._domElement.addEventListener("pointercancel",f),this._domElement.addEventListener("wheel",p,{passive:!1}),this._domElement.addEventListener("contextmenu",y)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",o),this._domElement.removeEventListener("mousedown",a),this._domElement.removeEventListener("pointercancel",f),this._domElement.removeEventListener("wheel",p,{passive:!1}),this._domElement.removeEventListener("contextmenu",y),this._domElement.ownerDocument.removeEventListener("pointermove",c,{passive:!1}),this._domElement.ownerDocument.removeEventListener("mousemove",d),this._domElement.ownerDocument.removeEventListener("pointerup",f),this._domElement.ownerDocument.removeEventListener("mouseup",u),this._domElement.ownerDocument.removeEventListener("pointerlockchange",g),this._domElement.ownerDocument.removeEventListener("pointerlockerror",E))},this.cancel=()=>{this._state!==A.NONE&&(this._state=A.NONE,this._activePointers.length=0,m())},t&&this.connect(t),this.update(0)}get camera(){return this._camera}set camera(e){this._camera=e,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(e){this._enabled=e,this._domElement&&(e?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(e){this._spherical.radius===e&&this._sphericalEnd.radius===e||(this._spherical.radius=e,this._sphericalEnd.radius=e,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(e){this._spherical.theta===e&&this._sphericalEnd.theta===e||(this._spherical.theta=e,this._sphericalEnd.theta=e,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(e){this._spherical.phi===e&&this._sphericalEnd.phi===e||(this._spherical.phi=e,this._sphericalEnd.phi=e,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(e){this._boundaryEnclosesCamera=e,this._needsUpdate=!0}set interactiveArea(e){this._interactiveArea.width=nt(e.width,0,1),this._interactiveArea.height=nt(e.height,0,1),this._interactiveArea.x=nt(e.x,0,1-this._interactiveArea.width),this._interactiveArea.y=nt(e.y,0,1-this._interactiveArea.height)}addEventListener(e,t){super.addEventListener(e,t)}removeEventListener(e,t){super.removeEventListener(e,t)}rotate(e,t,s=!1){return this.rotateTo(this._sphericalEnd.theta+e,this._sphericalEnd.phi+t,s)}rotateAzimuthTo(e,t=!1){return this.rotateTo(e,this._sphericalEnd.phi,t)}rotatePolarTo(e,t=!1){return this.rotateTo(this._sphericalEnd.theta,e,t)}rotateTo(e,t,s=!1){this._isUserControllingRotate=!1;const i=nt(e,this.minAzimuthAngle,this.maxAzimuthAngle),r=nt(t,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=i,this._sphericalEnd.phi=r,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const o=!s||H(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&H(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(o)}dolly(e,t=!1){return this.dollyTo(this._sphericalEnd.radius-e,t)}dollyTo(e,t=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Lt.NONE,this._changedDolly=0,this._dollyToNoClamp(nt(e,this.minDistance,this.maxDistance),t)}_dollyToNoClamp(e,t=!1){const s=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const o=this._collisionTest(),a=H(o,this._spherical.radius);if(!(s>e)&&a)return Promise.resolve();this._sphericalEnd.radius=Math.min(e,o)}else this._sphericalEnd.radius=e;this._needsUpdate=!0,t||(this._spherical.radius=this._sphericalEnd.radius);const r=!t||H(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(r)}dollyInFixed(e,t=!1){this._targetEnd.add(this._getCameraDirection($t).multiplyScalar(e)),t||this._target.copy(this._targetEnd);const s=!t||H(this._target.x,this._targetEnd.x,this.restThreshold)&&H(this._target.y,this._targetEnd.y,this.restThreshold)&&H(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(s)}zoom(e,t=!1){return this.zoomTo(this._zoomEnd+e,t)}zoomTo(e,t=!1){this._isUserControllingZoom=!1,this._zoomEnd=nt(e,this.minZoom,this.maxZoom),this._needsUpdate=!0,t||(this._zoom=this._zoomEnd);const s=!t||H(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(s)}pan(e,t,s=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(e,t,s)}truck(e,t,s=!1){this._camera.updateMatrix(),rt.setFromMatrixColumn(this._camera.matrix,0),at.setFromMatrixColumn(this._camera.matrix,1),rt.multiplyScalar(e),at.multiplyScalar(-t);const i=z.copy(rt).add(at),r=I.copy(this._targetEnd).add(i);return this.moveTo(r.x,r.y,r.z,s)}forward(e,t=!1){z.setFromMatrixColumn(this._camera.matrix,0),z.crossVectors(this._camera.up,z),z.multiplyScalar(e);const s=I.copy(this._targetEnd).add(z);return this.moveTo(s.x,s.y,s.z,t)}elevate(e,t=!1){return z.copy(this._camera.up).multiplyScalar(e),this.moveTo(this._targetEnd.x+z.x,this._targetEnd.y+z.y,this._targetEnd.z+z.z,t)}moveTo(e,t,s,i=!1){this._isUserControllingTruck=!1;const r=z.set(e,t,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,r,this.boundaryFriction),this._needsUpdate=!0,i||this._target.copy(this._targetEnd);const o=!i||H(this._target.x,this._targetEnd.x,this.restThreshold)&&H(this._target.y,this._targetEnd.y,this.restThreshold)&&H(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(o)}lookInDirectionOf(e,t,s,i=!1){const a=z.set(e,t,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius);return this.setPosition(a.x,a.y,a.z,i)}fitToBox(e,t,{cover:s=!1,paddingLeft:i=0,paddingRight:r=0,paddingBottom:o=0,paddingTop:a=0}={}){const c=[],d=e.isBox3?Mt.copy(e):Mt.setFromObject(e);d.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const f=bs(this._sphericalEnd.theta,Cs),u=bs(this._sphericalEnd.phi,Cs);c.push(this.rotateTo(f,u,t));const l=z.setFromSpherical(this._sphericalEnd).normalize(),p=Ss.setFromUnitVectors(l,Ve),y=H(Math.abs(l.y),1);y&&p.multiply(Ne.setFromAxisAngle(ye,f)),p.multiply(this._yAxisUpSpaceInverse);const O=Ds.makeEmpty();I.copy(d.min).applyQuaternion(p),O.expandByPoint(I),I.copy(d.min).setX(d.max.x).applyQuaternion(p),O.expandByPoint(I),I.copy(d.min).setY(d.max.y).applyQuaternion(p),O.expandByPoint(I),I.copy(d.max).setZ(d.min.z).applyQuaternion(p),O.expandByPoint(I),I.copy(d.min).setZ(d.max.z).applyQuaternion(p),O.expandByPoint(I),I.copy(d.max).setY(d.min.y).applyQuaternion(p),O.expandByPoint(I),I.copy(d.max).setX(d.min.x).applyQuaternion(p),O.expandByPoint(I),I.copy(d.max).applyQuaternion(p),O.expandByPoint(I),O.min.x-=i,O.min.y-=o,O.max.x+=r,O.max.y+=a,p.setFromUnitVectors(Ve,l),y&&p.premultiply(Ne.invert()),p.premultiply(this._yAxisUpSpace);const T=O.getSize(z),m=O.getCenter(I).applyQuaternion(p);if(gt(this._camera)){const g=this.getDistanceToFitBox(T.x,T.y,T.z,s);c.push(this.moveTo(m.x,m.y,m.z,t)),c.push(this.dollyTo(g,t)),c.push(this.setFocalOffset(0,0,0,t))}else if(pt(this._camera)){const g=this._camera,E=g.right-g.left,h=g.top-g.bottom,_=s?Math.max(E/T.x,h/T.y):Math.min(E/T.x,h/T.y);c.push(this.moveTo(m.x,m.y,m.z,t)),c.push(this.zoomTo(_,t)),c.push(this.setFocalOffset(0,0,0,t))}return Promise.all(c)}fitToSphere(e,t){const s=[],r=e instanceof B.Sphere?Ye.copy(e):Jt.createBoundingSphere(e,Ye);if(s.push(this.moveTo(r.center.x,r.center.y,r.center.z,t)),gt(this._camera)){const o=this.getDistanceToFitSphere(r.radius);s.push(this.dollyTo(o,t))}else if(pt(this._camera)){const o=this._camera.right-this._camera.left,a=this._camera.top-this._camera.bottom,c=2*r.radius,d=Math.min(o/c,a/c);s.push(this.zoomTo(d,t))}return s.push(this.setFocalOffset(0,0,0,t)),Promise.all(s)}setLookAt(e,t,s,i,r,o,a=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Lt.NONE,this._changedDolly=0;const c=I.set(i,r,o),d=z.set(e,t,s);this._targetEnd.copy(c),this._sphericalEnd.setFromVector3(d.sub(c).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,a||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const f=!a||H(this._target.x,this._targetEnd.x,this.restThreshold)&&H(this._target.y,this._targetEnd.y,this.restThreshold)&&H(this._target.z,this._targetEnd.z,this.restThreshold)&&H(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&H(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&H(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(f)}lerpLookAt(e,t,s,i,r,o,a,c,d,f,u,l,p,y=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Lt.NONE,this._changedDolly=0;const O=z.set(i,r,o),T=I.set(e,t,s);G.setFromVector3(T.sub(O).applyQuaternion(this._yAxisUpSpace));const m=St.set(f,u,l),g=I.set(a,c,d);Kt.setFromVector3(g.sub(m).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(O.lerp(m,p));const E=Kt.theta-G.theta,h=Kt.phi-G.phi,_=Kt.radius-G.radius;this._sphericalEnd.set(G.radius+_*p,G.phi+h*p,G.theta+E*p),this.normalizeRotations(),this._needsUpdate=!0,y||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const x=!y||H(this._target.x,this._targetEnd.x,this.restThreshold)&&H(this._target.y,this._targetEnd.y,this.restThreshold)&&H(this._target.z,this._targetEnd.z,this.restThreshold)&&H(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&H(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&H(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(x)}setPosition(e,t,s,i=!1){return this.setLookAt(e,t,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,i)}setTarget(e,t,s,i=!1){const r=this.getPosition(z),o=this.setLookAt(r.x,r.y,r.z,e,t,s,i);return this._sphericalEnd.phi=nt(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),o}setFocalOffset(e,t,s,i=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(e,t,s),this._needsUpdate=!0,i||this._focalOffset.copy(this._focalOffsetEnd);const r=!i||H(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&H(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&H(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}setOrbitPoint(e,t,s){this._camera.updateMatrixWorld(),rt.setFromMatrixColumn(this._camera.matrixWorldInverse,0),at.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Tt.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const i=z.set(e,t,s),r=i.distanceTo(this._camera.position),o=i.sub(this._camera.position);rt.multiplyScalar(o.x),at.multiplyScalar(o.y),Tt.multiplyScalar(o.z),z.copy(rt).add(at).add(Tt),z.z=z.z+r,this.dollyTo(r,!1),this.setFocalOffset(-z.x,z.y,-z.z,!1),this.moveTo(e,t,s,!1)}setBoundary(e){if(!e){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(e),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(e,t,s,i){if(e===null){this._viewport=null;return}this._viewport=this._viewport||new B.Vector4,typeof e=="number"?this._viewport.set(e,t,s,i):this._viewport.copy(e)}getDistanceToFitBox(e,t,s,i=!1){if(ke(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const r=e/t,o=this._camera.getEffectiveFOV()*Xt,a=this._camera.aspect;return((i?r>a:rt.pointerId===e)}_findPointerByMouseButton(e){return this._activePointers.find(t=>t.mouseButton===e)}_disposePointer(e){this._activePointers.splice(this._activePointers.indexOf(e),1)}_encloseToBoundary(e,t,s){const i=t.lengthSq();if(i===0)return e;const r=I.copy(t).add(e),a=this._boundary.clampPoint(r,St).sub(r),c=a.lengthSq();if(c===0)return e.add(t);if(c===i)return e;if(s===0)return e.add(t).add(a);{const d=1+s*c/t.dot(a);return e.add(I.copy(t).multiplyScalar(d)).add(a.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(gt(this._camera)){const e=this._camera,t=e.near,s=e.getEffectiveFOV()*Xt,i=Math.tan(s*.5)*t,r=i*e.aspect;this._nearPlaneCorners[0].set(-r,-i,0),this._nearPlaneCorners[1].set(r,-i,0),this._nearPlaneCorners[2].set(r,i,0),this._nearPlaneCorners[3].set(-r,i,0)}else if(pt(this._camera)){const e=this._camera,t=1/e.zoom,s=e.left*t,i=e.right*t,r=e.top*t,o=e.bottom*t;this._nearPlaneCorners[0].set(s,r,0),this._nearPlaneCorners[1].set(i,r,0),this._nearPlaneCorners[2].set(i,o,0),this._nearPlaneCorners[3].set(s,o,0)}}_collisionTest(){let e=1/0;if(!(this.colliderMeshes.length>=1)||ke(this._camera,"_collisionTest"))return e;const s=this._getTargetDirection($t);Ze.lookAt(Us,s,this._camera.up);for(let i=0;i<4;i++){const r=I.copy(this._nearPlaneCorners[i]);r.applyMatrix4(Ze);const o=St.addVectors(this._target,r);ge.set(o,s),ge.far=this._spherical.radius+1;const a=ge.intersectObjects(this.colliderMeshes);a.length!==0&&a[0].distance{const s=()=>{this.removeEventListener("rest",s),t()};this.addEventListener("rest",s)}))}_addAllEventListeners(e){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(e){console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead.")}get draggingDampingFactor(){return console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead."),0}set draggingDampingFactor(e){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(e,t=new B.Sphere){const s=t,i=s.center;Mt.makeEmpty(),e.traverseVisible(o=>{o.isMesh&&Mt.expandByObject(o)}),Mt.getCenter(i);let r=0;return e.traverseVisible(o=>{if(!o.isMesh)return;const a=o,c=a.geometry.clone();c.applyMatrix4(a.matrixWorld);const f=c.attributes.position;for(let u=0,l=f.count;u{var t;if(!(!this.currentWorld||!this.currentWorld.renderer)&&(t=this.currentWorld.renderer)!=null&&t.isResizeable()){const s=this.currentWorld.renderer.getSize();this.three.aspect=s.width/s.height,this.three.updateProjectionMatrix(),this.onAspectUpdated.trigger()}});this.three=this.setupCamera(),this.setupEvents(!0),this.onWorldChanged.add(({action:s,world:i})=>{if(s==="added"){const r=this.newCameraControls();this._allControls.set(i.uuid,r)}if(s==="removed"){const r=this._allControls.get(i.uuid);r&&(r.dispose(),this._allControls.delete(i.uuid))}})}get controls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");const t=this._allControls.get(this.currentWorld.uuid);if(!t)throw new Error("Controls not found!");return t}get enabled(){return this.currentWorld===null?!1:this.controls.enabled}set enabled(t){this.controls.enabled=t}dispose(){this.setupEvents(!1),this.enabled=!1,this.onAspectUpdated.reset(),this.onBeforeUpdate.reset(),this.onAfterUpdate.reset(),this.three.removeFromParent(),this.onDisposed.trigger(),this.onDisposed.reset();for(const[t,s]of this._allControls)s.dispose()}update(t){this.enabled&&(this.onBeforeUpdate.trigger(this),this.controls.update(t),this.onAfterUpdate.trigger(this))}setupCamera(){const t=window.innerWidth/window.innerHeight,s=new ei(60,t,1,1e3);return s.position.set(50,50,50),s.lookAt(new S(0,0,0)),s}newCameraControls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");if(!this.currentWorld.renderer)throw new Error("This camera needs a renderer to work!");Jt.install({THREE:Xs.getSubsetOfThree()});const{domElement:t}=this.currentWorld.renderer.three,s=new Jt(this.three,t);return s.smoothTime=.2,s.dollyToCursor=!0,s.infinityDolly=!0,s}setupEvents(t){t?window.addEventListener("resize",this.updateAspect):window.removeEventListener("resize",this.updateAspect)}static getSubsetOfThree(){return{MOUSE:si,Vector2:ht,Vector3:S,Vector4:ii,Quaternion:ni,Matrix4:ut,Spherical:oi,Box3:st,Sphere:zs,Raycaster:ri,MathUtils:ai}}}const Ae=class Ae extends Ys{constructor(t){super(t);D(this,"onAfterUpdate",new X);D(this,"onBeforeUpdate",new X);D(this,"onDisposed",new X);D(this,"list",new Map);D(this,"enabled",!0);t.add(Ae.uuid,this)}create(){const t=new yn(this.components),s=t.uuid;if(this.list.has(s))throw new Error("There is already a world with this name!");return this.list.set(s,t),t}delete(t){this.list.delete(t.uuid),t.dispose()}dispose(){this.enabled=!1;for(const[t,s]of this.list)s.dispose();this.list.clear(),this.onDisposed.trigger()}update(t){if(this.enabled)for(const[s,i]of this.list)i.update(t)}};D(Ae,"uuid","fdb61dc4-2ec1-4966-b83d-54ea795fad4a");let Ms=Ae;export{As as C,xe as D,X as E,An as S,Ms as W,Cn as a,Xs as b,Ys as c}; diff --git a/examples/assets/lil-gui.module.min-Bc0DeA9g.js b/examples/assets/lil-gui.module.min-Bc0DeA9g.js new file mode 100644 index 000000000..428c5fdf0 --- /dev/null +++ b/examples/assets/lil-gui.module.min-Bc0DeA9g.js @@ -0,0 +1,10 @@ +/** + * lil-gui + * https://lil-gui.georgealways.com + * @version 0.17.0 + * @author George Michael Brower + * @license MIT + */class u{constructor(t,i,e,n,a="div"){this.parent=t,this.object=i,this.property=e,this._disabled=!1,this._hidden=!1,this.initialValue=this.getValue(),this.domElement=document.createElement("div"),this.domElement.classList.add("controller"),this.domElement.classList.add(n),this.$name=document.createElement("div"),this.$name.classList.add("name"),u.nextNameID=u.nextNameID||0,this.$name.id="lil-gui-name-"+ ++u.nextNameID,this.$widget=document.createElement(a),this.$widget.classList.add("widget"),this.$disable=this.$widget,this.domElement.appendChild(this.$name),this.domElement.appendChild(this.$widget),this.parent.children.push(this),this.parent.controllers.push(this),this.parent.$children.appendChild(this.domElement),this._listenCallback=this._listenCallback.bind(this),this.name(e)}name(t){return this._name=t,this.$name.innerHTML=t,this}onChange(t){return this._onChange=t,this}_callOnChange(){this.parent._callOnChange(this),this._onChange!==void 0&&this._onChange.call(this,this.getValue()),this._changed=!0}onFinishChange(t){return this._onFinishChange=t,this}_callOnFinishChange(){this._changed&&(this.parent._callOnFinishChange(this),this._onFinishChange!==void 0&&this._onFinishChange.call(this,this.getValue())),this._changed=!1}reset(){return this.setValue(this.initialValue),this._callOnFinishChange(),this}enable(t=!0){return this.disable(!t)}disable(t=!0){return t===this._disabled||(this._disabled=t,this.domElement.classList.toggle("disabled",t),this.$disable.toggleAttribute("disabled",t)),this}show(t=!0){return this._hidden=!t,this.domElement.style.display=this._hidden?"none":"",this}hide(){return this.show(!1)}options(t){const i=this.parent.add(this.object,this.property,t);return i.name(this._name),this.destroy(),i}min(t){return this}max(t){return this}step(t){return this}decimals(t){return this}listen(t=!0){return this._listening=t,this._listenCallbackID!==void 0&&(cancelAnimationFrame(this._listenCallbackID),this._listenCallbackID=void 0),this._listening&&this._listenCallback(),this}_listenCallback(){this._listenCallbackID=requestAnimationFrame(this._listenCallback);const t=this.save();t!==this._listenPrevValue&&this.updateDisplay(),this._listenPrevValue=t}getValue(){return this.object[this.property]}setValue(t){return this.object[this.property]=t,this._callOnChange(),this.updateDisplay(),this}updateDisplay(){return this}load(t){return this.setValue(t),this._callOnFinishChange(),this}save(){return this.getValue()}destroy(){this.listen(!1),this.parent.children.splice(this.parent.children.indexOf(this),1),this.parent.controllers.splice(this.parent.controllers.indexOf(this),1),this.parent.$children.removeChild(this.domElement)}}class C extends u{constructor(t,i,e){super(t,i,e,"boolean","label"),this.$input=document.createElement("input"),this.$input.setAttribute("type","checkbox"),this.$input.setAttribute("aria-labelledby",this.$name.id),this.$widget.appendChild(this.$input),this.$input.addEventListener("change",()=>{this.setValue(this.$input.checked),this._callOnFinishChange()}),this.$disable=this.$input,this.updateDisplay()}updateDisplay(){return this.$input.checked=this.getValue(),this}}function w(l){let t,i;return(t=l.match(/(#|0x)?([a-f0-9]{6})/i))?i=t[2]:(t=l.match(/rgb\(\s*(\d*)\s*,\s*(\d*)\s*,\s*(\d*)\s*\)/))?i=parseInt(t[1]).toString(16).padStart(2,0)+parseInt(t[2]).toString(16).padStart(2,0)+parseInt(t[3]).toString(16).padStart(2,0):(t=l.match(/^#?([a-f0-9])([a-f0-9])([a-f0-9])$/i))&&(i=t[1]+t[1]+t[2]+t[2]+t[3]+t[3]),!!i&&"#"+i}const k={isPrimitive:!0,match:l=>typeof l=="string",fromHexString:w,toHexString:w},m={isPrimitive:!0,match:l=>typeof l=="number",fromHexString:l=>parseInt(l.substring(1),16),toHexString:l=>"#"+l.toString(16).padStart(6,0)},L={isPrimitive:!1,match:Array.isArray,fromHexString(l,t,i=1){const e=m.fromHexString(l);t[0]=(e>>16&255)/255*i,t[1]=(e>>8&255)/255*i,t[2]=(255&e)/255*i},toHexString:([l,t,i],e=1)=>m.toHexString(l*(e=255/e)<<16^t*e<<8^i*e<<0)},S={isPrimitive:!1,match:l=>Object(l)===l,fromHexString(l,t,i=1){const e=m.fromHexString(l);t.r=(e>>16&255)/255*i,t.g=(e>>8&255)/255*i,t.b=(255&e)/255*i},toHexString:({r:l,g:t,b:i},e=1)=>m.toHexString(l*(e=255/e)<<16^t*e<<8^i*e<<0)},D=[k,m,L,S];class F extends u{constructor(t,i,e,n){var a;super(t,i,e,"color"),this.$input=document.createElement("input"),this.$input.setAttribute("type","color"),this.$input.setAttribute("tabindex",-1),this.$input.setAttribute("aria-labelledby",this.$name.id),this.$text=document.createElement("input"),this.$text.setAttribute("type","text"),this.$text.setAttribute("spellcheck","false"),this.$text.setAttribute("aria-labelledby",this.$name.id),this.$display=document.createElement("div"),this.$display.classList.add("display"),this.$display.appendChild(this.$input),this.$widget.appendChild(this.$display),this.$widget.appendChild(this.$text),this._format=(a=this.initialValue,D.find(r=>r.match(a))),this._rgbScale=n,this._initialValueHexString=this.save(),this._textFocused=!1,this.$input.addEventListener("input",()=>{this._setValueFromHexString(this.$input.value)}),this.$input.addEventListener("blur",()=>{this._callOnFinishChange()}),this.$text.addEventListener("input",()=>{const r=w(this.$text.value);r&&this._setValueFromHexString(r)}),this.$text.addEventListener("focus",()=>{this._textFocused=!0,this.$text.select()}),this.$text.addEventListener("blur",()=>{this._textFocused=!1,this.updateDisplay(),this._callOnFinishChange()}),this.$disable=this.$text,this.updateDisplay()}reset(){return this._setValueFromHexString(this._initialValueHexString),this}_setValueFromHexString(t){if(this._format.isPrimitive){const i=this._format.fromHexString(t);this.setValue(i)}else this._format.fromHexString(t,this.getValue(),this._rgbScale),this._callOnChange(),this.updateDisplay()}save(){return this._format.toHexString(this.getValue(),this._rgbScale)}load(t){return this._setValueFromHexString(t),this._callOnFinishChange(),this}updateDisplay(){return this.$input.value=this._format.toHexString(this.getValue(),this._rgbScale),this._textFocused||(this.$text.value=this.$input.value.substring(1)),this.$display.style.backgroundColor=this.$input.value,this}}class f extends u{constructor(t,i,e){super(t,i,e,"function"),this.$button=document.createElement("button"),this.$button.appendChild(this.$name),this.$widget.appendChild(this.$button),this.$button.addEventListener("click",n=>{n.preventDefault(),this.getValue().call(this.object)}),this.$button.addEventListener("touchstart",()=>{},{passive:!0}),this.$disable=this.$button}}class V extends u{constructor(t,i,e,n,a,r){super(t,i,e,"number"),this._initInput(),this.min(n),this.max(a);const d=r!==void 0;this.step(d?r:this._getImplicitStep(),d),this.updateDisplay()}decimals(t){return this._decimals=t,this.updateDisplay(),this}min(t){return this._min=t,this._onUpdateMinMax(),this}max(t){return this._max=t,this._onUpdateMinMax(),this}step(t,i=!0){return this._step=t,this._stepExplicit=i,this}updateDisplay(){const t=this.getValue();if(this._hasSlider){let i=(t-this._min)/(this._max-this._min);i=Math.max(0,Math.min(i,1)),this.$fill.style.width=100*i+"%"}return this._inputFocused||(this.$input.value=this._decimals===void 0?t:t.toFixed(this._decimals)),this}_initInput(){this.$input=document.createElement("input"),this.$input.setAttribute("type","number"),this.$input.setAttribute("step","any"),this.$input.setAttribute("aria-labelledby",this.$name.id),this.$widget.appendChild(this.$input),this.$disable=this.$input;const t=s=>{const p=parseFloat(this.$input.value);isNaN(p)||(this._snapClampSetValue(p+s),this.$input.value=this.getValue())};let i,e,n,a,r,d=!1;const h=s=>{if(d){const p=s.clientX-i,o=s.clientY-e;Math.abs(o)>5?(s.preventDefault(),this.$input.blur(),d=!1,this._setDraggingStyle(!0,"vertical")):Math.abs(p)>5&&c()}if(!d){const p=s.clientY-n;r-=p*this._step*this._arrowKeyMultiplier(s),a+r>this._max?r=this._max-a:a+r{this._setDraggingStyle(!1,"vertical"),this._callOnFinishChange(),window.removeEventListener("mousemove",h),window.removeEventListener("mouseup",c)};this.$input.addEventListener("input",()=>{let s=parseFloat(this.$input.value);isNaN(s)||(this._stepExplicit&&(s=this._snap(s)),this.setValue(this._clamp(s)))}),this.$input.addEventListener("keydown",s=>{s.code==="Enter"&&this.$input.blur(),s.code==="ArrowUp"&&(s.preventDefault(),t(this._step*this._arrowKeyMultiplier(s))),s.code==="ArrowDown"&&(s.preventDefault(),t(this._step*this._arrowKeyMultiplier(s)*-1))}),this.$input.addEventListener("wheel",s=>{this._inputFocused&&(s.preventDefault(),t(this._step*this._normalizeMouseWheel(s)))},{passive:!1}),this.$input.addEventListener("mousedown",s=>{i=s.clientX,e=n=s.clientY,d=!0,a=this.getValue(),r=0,window.addEventListener("mousemove",h),window.addEventListener("mouseup",c)}),this.$input.addEventListener("focus",()=>{this._inputFocused=!0}),this.$input.addEventListener("blur",()=>{this._inputFocused=!1,this.updateDisplay(),this._callOnFinishChange()})}_initSlider(){this._hasSlider=!0,this.$slider=document.createElement("div"),this.$slider.classList.add("slider"),this.$fill=document.createElement("div"),this.$fill.classList.add("fill"),this.$slider.appendChild(this.$fill),this.$widget.insertBefore(this.$slider,this.$input),this.domElement.classList.add("hasSlider");const t=o=>{const g=this.$slider.getBoundingClientRect();let b=(x=o,v=g.left,y=g.right,A=this._min,_=this._max,(x-v)/(y-v)*(_-A)+A);var x,v,y,A,_;this._snapClampSetValue(b)},i=o=>{t(o.clientX)},e=()=>{this._callOnFinishChange(),this._setDraggingStyle(!1),window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",e)};let n,a,r=!1;const d=o=>{o.preventDefault(),this._setDraggingStyle(!0),t(o.touches[0].clientX),r=!1},h=o=>{if(r){const g=o.touches[0].clientX-n,b=o.touches[0].clientY-a;Math.abs(g)>Math.abs(b)?d(o):(window.removeEventListener("touchmove",h),window.removeEventListener("touchend",c))}else o.preventDefault(),t(o.touches[0].clientX)},c=()=>{this._callOnFinishChange(),this._setDraggingStyle(!1),window.removeEventListener("touchmove",h),window.removeEventListener("touchend",c)},s=this._callOnFinishChange.bind(this);let p;this.$slider.addEventListener("mousedown",o=>{this._setDraggingStyle(!0),t(o.clientX),window.addEventListener("mousemove",i),window.addEventListener("mouseup",e)}),this.$slider.addEventListener("touchstart",o=>{o.touches.length>1||(this._hasScrollBar?(n=o.touches[0].clientX,a=o.touches[0].clientY,r=!0):d(o),window.addEventListener("touchmove",h,{passive:!1}),window.addEventListener("touchend",c))},{passive:!1}),this.$slider.addEventListener("wheel",o=>{if(Math.abs(o.deltaX)this._max&&(t=this._max),t}_snapClampSetValue(t){this.setValue(this._clamp(this._snap(t)))}get _hasScrollBar(){const t=this.parent.root.$children;return t.scrollHeight>t.clientHeight}get _hasMin(){return this._min!==void 0}get _hasMax(){return this._max!==void 0}}class M extends u{constructor(t,i,e,n){super(t,i,e,"option"),this.$select=document.createElement("select"),this.$select.setAttribute("aria-labelledby",this.$name.id),this.$display=document.createElement("div"),this.$display.classList.add("display"),this._values=Array.isArray(n)?n:Object.values(n),this._names=Array.isArray(n)?n:Object.keys(n),this._names.forEach(a=>{const r=document.createElement("option");r.innerHTML=a,this.$select.appendChild(r)}),this.$select.addEventListener("change",()=>{this.setValue(this._values[this.$select.selectedIndex]),this._callOnFinishChange()}),this.$select.addEventListener("focus",()=>{this.$display.classList.add("focus")}),this.$select.addEventListener("blur",()=>{this.$display.classList.remove("focus")}),this.$widget.appendChild(this.$select),this.$widget.appendChild(this.$display),this.$disable=this.$select,this.updateDisplay()}updateDisplay(){const t=this.getValue(),i=this._values.indexOf(t);return this.$select.selectedIndex=i,this.$display.innerHTML=i===-1?t:this._names[i],this}}class H extends u{constructor(t,i,e){super(t,i,e,"string"),this.$input=document.createElement("input"),this.$input.setAttribute("type","text"),this.$input.setAttribute("aria-labelledby",this.$name.id),this.$input.addEventListener("input",()=>{this.setValue(this.$input.value)}),this.$input.addEventListener("keydown",n=>{n.code==="Enter"&&this.$input.blur()}),this.$input.addEventListener("blur",()=>{this._callOnFinishChange()}),this.$widget.appendChild(this.$input),this.$disable=this.$input,this.updateDisplay()}updateDisplay(){return this.$input.value=this.getValue(),this}}let $=!1;class E{constructor({parent:t,autoPlace:i=t===void 0,container:e,width:n,title:a="Controls",injectStyles:r=!0,touchStyles:d=!0}={}){if(this.parent=t,this.root=t?t.root:this,this.children=[],this.controllers=[],this.folders=[],this._closed=!1,this._hidden=!1,this.domElement=document.createElement("div"),this.domElement.classList.add("lil-gui"),this.$title=document.createElement("div"),this.$title.classList.add("title"),this.$title.setAttribute("role","button"),this.$title.setAttribute("aria-expanded",!0),this.$title.setAttribute("tabindex",0),this.$title.addEventListener("click",()=>this.openAnimated(this._closed)),this.$title.addEventListener("keydown",h=>{h.code!=="Enter"&&h.code!=="Space"||(h.preventDefault(),this.$title.click())}),this.$title.addEventListener("touchstart",()=>{},{passive:!0}),this.$children=document.createElement("div"),this.$children.classList.add("children"),this.domElement.appendChild(this.$title),this.domElement.appendChild(this.$children),this.title(a),d&&this.domElement.classList.add("allow-touch-styles"),this.parent)return this.parent.children.push(this),this.parent.folders.push(this),void this.parent.$children.appendChild(this.domElement);this.domElement.classList.add("root"),!$&&r&&(function(h){const c=document.createElement("style");c.innerHTML=h;const s=document.querySelector("head link[rel=stylesheet], head style");s?document.head.insertBefore(c,s):document.head.appendChild(c)}('.lil-gui{--background-color:#1f1f1f;--text-color:#ebebeb;--title-background-color:#111;--title-text-color:#ebebeb;--widget-color:#424242;--hover-color:#4f4f4f;--focus-color:#595959;--number-color:#2cc9ff;--string-color:#a2db3c;--font-size:11px;--input-font-size:11px;--font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif;--font-family-mono:Menlo,Monaco,Consolas,"Droid Sans Mono",monospace;--padding:4px;--spacing:4px;--widget-height:20px;--name-width:45%;--slider-knob-width:2px;--slider-input-width:27%;--color-input-width:27%;--slider-input-min-width:45px;--color-input-min-width:45px;--folder-indent:7px;--widget-padding:0 0 0 3px;--widget-border-radius:2px;--checkbox-size:calc(var(--widget-height)*0.75);--scrollbar-width:5px;background-color:var(--background-color);color:var(--text-color);font-family:var(--font-family);font-size:var(--font-size);font-style:normal;font-weight:400;line-height:1;text-align:left;touch-action:manipulation;user-select:none;-webkit-user-select:none}.lil-gui,.lil-gui *{box-sizing:border-box;margin:0;padding:0}.lil-gui.root{display:flex;flex-direction:column;width:var(--width,245px)}.lil-gui.root>.title{background:var(--title-background-color);color:var(--title-text-color)}.lil-gui.root>.children{overflow-x:hidden;overflow-y:auto}.lil-gui.root>.children::-webkit-scrollbar{background:var(--background-color);height:var(--scrollbar-width);width:var(--scrollbar-width)}.lil-gui.root>.children::-webkit-scrollbar-thumb{background:var(--focus-color);border-radius:var(--scrollbar-width)}.lil-gui.force-touch-styles{--widget-height:28px;--padding:6px;--spacing:6px;--font-size:13px;--input-font-size:16px;--folder-indent:10px;--scrollbar-width:7px;--slider-input-min-width:50px;--color-input-min-width:65px}.lil-gui.autoPlace{max-height:100%;position:fixed;right:15px;top:0;z-index:1001}.lil-gui .controller{align-items:center;display:flex;margin:var(--spacing) 0;padding:0 var(--padding)}.lil-gui .controller.disabled{opacity:.5}.lil-gui .controller.disabled,.lil-gui .controller.disabled *{pointer-events:none!important}.lil-gui .controller>.name{flex-shrink:0;line-height:var(--widget-height);min-width:var(--name-width);padding-right:var(--spacing);white-space:pre}.lil-gui .controller .widget{align-items:center;display:flex;min-height:var(--widget-height);position:relative;width:100%}.lil-gui .controller.string input{color:var(--string-color)}.lil-gui .controller.boolean .widget{cursor:pointer}.lil-gui .controller.color .display{border-radius:var(--widget-border-radius);height:var(--widget-height);position:relative;width:100%}.lil-gui .controller.color input[type=color]{cursor:pointer;height:100%;opacity:0;width:100%}.lil-gui .controller.color input[type=text]{flex-shrink:0;font-family:var(--font-family-mono);margin-left:var(--spacing);min-width:var(--color-input-min-width);width:var(--color-input-width)}.lil-gui .controller.option select{max-width:100%;opacity:0;position:absolute;width:100%}.lil-gui .controller.option .display{background:var(--widget-color);border-radius:var(--widget-border-radius);height:var(--widget-height);line-height:var(--widget-height);max-width:100%;overflow:hidden;padding-left:.55em;padding-right:1.75em;pointer-events:none;position:relative;word-break:break-all}.lil-gui .controller.option .display.active{background:var(--focus-color)}.lil-gui .controller.option .display:after{bottom:0;content:"↕";font-family:lil-gui;padding-right:.375em;position:absolute;right:0;top:0}.lil-gui .controller.option .widget,.lil-gui .controller.option select{cursor:pointer}.lil-gui .controller.number input{color:var(--number-color)}.lil-gui .controller.number.hasSlider input{flex-shrink:0;margin-left:var(--spacing);min-width:var(--slider-input-min-width);width:var(--slider-input-width)}.lil-gui .controller.number .slider{background-color:var(--widget-color);border-radius:var(--widget-border-radius);cursor:ew-resize;height:var(--widget-height);overflow:hidden;padding-right:var(--slider-knob-width);touch-action:pan-y;width:100%}.lil-gui .controller.number .slider.active{background-color:var(--focus-color)}.lil-gui .controller.number .slider.active .fill{opacity:.95}.lil-gui .controller.number .fill{border-right:var(--slider-knob-width) solid var(--number-color);box-sizing:content-box;height:100%}.lil-gui-dragging .lil-gui{--hover-color:var(--widget-color)}.lil-gui-dragging *{cursor:ew-resize!important}.lil-gui-dragging.lil-gui-vertical *{cursor:ns-resize!important}.lil-gui .title{--title-height:calc(var(--widget-height) + var(--spacing)*1.25);-webkit-tap-highlight-color:transparent;text-decoration-skip:objects;cursor:pointer;font-weight:600;height:var(--title-height);line-height:calc(var(--title-height) - 4px);outline:none;padding:0 var(--padding)}.lil-gui .title:before{content:"▾";display:inline-block;font-family:lil-gui;padding-right:2px}.lil-gui .title:active{background:var(--title-background-color);opacity:.75}.lil-gui.root>.title:focus{text-decoration:none!important}.lil-gui.closed>.title:before{content:"▸"}.lil-gui.closed>.children{opacity:0;transform:translateY(-7px)}.lil-gui.closed:not(.transition)>.children{display:none}.lil-gui.transition>.children{overflow:hidden;pointer-events:none;transition-duration:.3s;transition-property:height,opacity,transform;transition-timing-function:cubic-bezier(.2,.6,.35,1)}.lil-gui .children:empty:before{content:"Empty";display:block;font-style:italic;height:var(--widget-height);line-height:var(--widget-height);margin:var(--spacing) 0;opacity:.5;padding:0 var(--padding)}.lil-gui.root>.children>.lil-gui>.title{border-width:0;border-bottom:1px solid var(--widget-color);border-left:0 solid var(--widget-color);border-right:0 solid var(--widget-color);border-top:1px solid var(--widget-color);transition:border-color .3s}.lil-gui.root>.children>.lil-gui.closed>.title{border-bottom-color:transparent}.lil-gui+.controller{border-top:1px solid var(--widget-color);margin-top:0;padding-top:var(--spacing)}.lil-gui .lil-gui .lil-gui>.title{border:none}.lil-gui .lil-gui .lil-gui>.children{border:none;border-left:2px solid var(--widget-color);margin-left:var(--folder-indent)}.lil-gui .lil-gui .controller{border:none}.lil-gui input{-webkit-tap-highlight-color:transparent;background:var(--widget-color);border:0;border-radius:var(--widget-border-radius);color:var(--text-color);font-family:var(--font-family);font-size:var(--input-font-size);height:var(--widget-height);outline:none;width:100%}.lil-gui input:disabled{opacity:1}.lil-gui input[type=number],.lil-gui input[type=text]{padding:var(--widget-padding)}.lil-gui input[type=number]:focus,.lil-gui input[type=text]:focus{background:var(--focus-color)}.lil-gui input::-webkit-inner-spin-button,.lil-gui input::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.lil-gui input[type=number]{-moz-appearance:textfield}.lil-gui input[type=checkbox]{appearance:none;-webkit-appearance:none;border-radius:var(--widget-border-radius);cursor:pointer;height:var(--checkbox-size);text-align:center;width:var(--checkbox-size)}.lil-gui input[type=checkbox]:checked:before{content:"✓";font-family:lil-gui;font-size:var(--checkbox-size);line-height:var(--checkbox-size)}.lil-gui button{-webkit-tap-highlight-color:transparent;background:var(--widget-color);border:1px solid var(--widget-color);border-radius:var(--widget-border-radius);color:var(--text-color);cursor:pointer;font-family:var(--font-family);font-size:var(--font-size);height:var(--widget-height);line-height:calc(var(--widget-height) - 4px);outline:none;text-align:center;text-transform:none;width:100%}.lil-gui button:active{background:var(--focus-color)}@font-face{font-family:lil-gui;src:url("data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAAUsAAsAAAAACJwAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAAH4AAADAImwmYE9TLzIAAAGIAAAAPwAAAGBKqH5SY21hcAAAAcgAAAD0AAACrukyyJBnbHlmAAACvAAAAF8AAACEIZpWH2hlYWQAAAMcAAAAJwAAADZfcj2zaGhlYQAAA0QAAAAYAAAAJAC5AHhobXR4AAADXAAAABAAAABMAZAAAGxvY2EAAANsAAAAFAAAACgCEgIybWF4cAAAA4AAAAAeAAAAIAEfABJuYW1lAAADoAAAASIAAAIK9SUU/XBvc3QAAATEAAAAZgAAAJCTcMc2eJxVjbEOgjAURU+hFRBK1dGRL+ALnAiToyMLEzFpnPz/eAshwSa97517c/MwwJmeB9kwPl+0cf5+uGPZXsqPu4nvZabcSZldZ6kfyWnomFY/eScKqZNWupKJO6kXN3K9uCVoL7iInPr1X5baXs3tjuMqCtzEuagm/AAlzQgPAAB4nGNgYRBlnMDAysDAYM/gBiT5oLQBAwuDJAMDEwMrMwNWEJDmmsJwgCFeXZghBcjlZMgFCzOiKOIFAB71Bb8AeJy1kjFuwkAQRZ+DwRAwBtNQRUGKQ8OdKCAWUhAgKLhIuAsVSpWz5Bbkj3dEgYiUIszqWdpZe+Z7/wB1oCYmIoboiwiLT2WjKl/jscrHfGg/pKdMkyklC5Zs2LEfHYpjcRoPzme9MWWmk3dWbK9ObkWkikOetJ554fWyoEsmdSlt+uR0pCJR34b6t/TVg1SY3sYvdf8vuiKrpyaDXDISiegp17p7579Gp3p++y7HPAiY9pmTibljrr85qSidtlg4+l25GLCaS8e6rRxNBmsnERunKbaOObRz7N72ju5vdAjYpBXHgJylOAVsMseDAPEP8LYoUHicY2BiAAEfhiAGJgZWBgZ7RnFRdnVJELCQlBSRlATJMoLV2DK4glSYs6ubq5vbKrJLSbGrgEmovDuDJVhe3VzcXFwNLCOILB/C4IuQ1xTn5FPilBTj5FPmBAB4WwoqAHicY2BkYGAA4sk1sR/j+W2+MnAzpDBgAyEMQUCSg4EJxAEAwUgFHgB4nGNgZGBgSGFggJMhDIwMqEAYAByHATJ4nGNgAIIUNEwmAABl3AGReJxjYAACIQYlBiMGJ3wQAEcQBEV4nGNgZGBgEGZgY2BiAAEQyQWEDAz/wXwGAAsPATIAAHicXdBNSsNAHAXwl35iA0UQXYnMShfS9GPZA7T7LgIu03SSpkwzYTIt1BN4Ak/gKTyAeCxfw39jZkjymzcvAwmAW/wgwHUEGDb36+jQQ3GXGot79L24jxCP4gHzF/EIr4jEIe7wxhOC3g2TMYy4Q7+Lu/SHuEd/ivt4wJd4wPxbPEKMX3GI5+DJFGaSn4qNzk8mcbKSR6xdXdhSzaOZJGtdapd4vVPbi6rP+cL7TGXOHtXKll4bY1Xl7EGnPtp7Xy2n00zyKLVHfkHBa4IcJ2oD3cgggWvt/V/FbDrUlEUJhTn/0azVWbNTNr0Ens8de1tceK9xZmfB1CPjOmPH4kitmvOubcNpmVTN3oFJyjzCvnmrwhJTzqzVj9jiSX911FjeAAB4nG3HMRKCMBBA0f0giiKi4DU8k0V2GWbIZDOh4PoWWvq6J5V8If9NVNQcaDhyouXMhY4rPTcG7jwYmXhKq8Wz+p762aNaeYXom2n3m2dLTVgsrCgFJ7OTmIkYbwIbC6vIB7WmFfAAAA==") format("woff")}@media (pointer:coarse){.lil-gui.allow-touch-styles{--widget-height:28px;--padding:6px;--spacing:6px;--font-size:13px;--input-font-size:16px;--folder-indent:10px;--scrollbar-width:7px;--slider-input-min-width:50px;--color-input-min-width:65px}}@media (hover:hover){.lil-gui .controller.color .display:hover:before{border:1px solid #fff9;border-radius:var(--widget-border-radius);bottom:0;content:" ";display:block;left:0;position:absolute;right:0;top:0}.lil-gui .controller.option .display.focus{background:var(--focus-color)}.lil-gui .controller.option .widget:hover .display{background:var(--hover-color)}.lil-gui .controller.number .slider:hover{background-color:var(--hover-color)}body:not(.lil-gui-dragging) .lil-gui .title:hover{background:var(--title-background-color);opacity:.85}.lil-gui .title:focus{text-decoration:underline var(--focus-color)}.lil-gui input:hover{background:var(--hover-color)}.lil-gui input:active{background:var(--focus-color)}.lil-gui input[type=checkbox]:focus{box-shadow:inset 0 0 0 1px var(--focus-color)}.lil-gui button:hover{background:var(--hover-color);border-color:var(--hover-color)}.lil-gui button:focus{border-color:var(--focus-color)}}'),$=!0),e?e.appendChild(this.domElement):i&&(this.domElement.classList.add("autoPlace"),document.body.appendChild(this.domElement)),n&&this.domElement.style.setProperty("--width",n+"px"),this.domElement.addEventListener("keydown",h=>h.stopPropagation()),this.domElement.addEventListener("keyup",h=>h.stopPropagation())}add(t,i,e,n,a){if(Object(e)===e)return new M(this,t,i,e);const r=t[i];switch(typeof r){case"number":return new V(this,t,i,e,n,a);case"boolean":return new C(this,t,i);case"string":return new H(this,t,i);case"function":return new f(this,t,i)}console.error(`gui.add failed + property:`,i,` + object:`,t,` + value:`,r)}addColor(t,i,e=1){return new F(this,t,i,e)}addFolder(t){return new E({parent:this,title:t})}load(t,i=!0){return t.controllers&&this.controllers.forEach(e=>{e instanceof f||e._name in t.controllers&&e.load(t.controllers[e._name])}),i&&t.folders&&this.folders.forEach(e=>{e._title in t.folders&&e.load(t.folders[e._title])}),this}save(t=!0){const i={controllers:{},folders:{}};return this.controllers.forEach(e=>{if(!(e instanceof f)){if(e._name in i.controllers)throw new Error(`Cannot save GUI with duplicate property "${e._name}"`);i.controllers[e._name]=e.save()}}),t&&this.folders.forEach(e=>{if(e._title in i.folders)throw new Error(`Cannot save GUI with duplicate folder "${e._title}"`);i.folders[e._title]=e.save()}),i}open(t=!0){return this._closed=!t,this.$title.setAttribute("aria-expanded",!this._closed),this.domElement.classList.toggle("closed",this._closed),this}close(){return this.open(!1)}show(t=!0){return this._hidden=!t,this.domElement.style.display=this._hidden?"none":"",this}hide(){return this.show(!1)}openAnimated(t=!0){return this._closed=!t,this.$title.setAttribute("aria-expanded",!this._closed),requestAnimationFrame(()=>{const i=this.$children.clientHeight;this.$children.style.height=i+"px",this.domElement.classList.add("transition");const e=a=>{a.target===this.$children&&(this.$children.style.height="",this.domElement.classList.remove("transition"),this.$children.removeEventListener("transitionend",e))};this.$children.addEventListener("transitionend",e);const n=t?this.$children.scrollHeight:0;this.domElement.classList.toggle("closed",!t),requestAnimationFrame(()=>{this.$children.style.height=n+"px"})}),this}title(t){return this._title=t,this.$title.innerHTML=t,this}reset(t=!0){return(t?this.controllersRecursive():this.controllers).forEach(i=>i.reset()),this}onChange(t){return this._onChange=t,this}_callOnChange(t){this.parent&&this.parent._callOnChange(t),this._onChange!==void 0&&this._onChange.call(this,{object:t.object,property:t.property,value:t.getValue(),controller:t})}onFinishChange(t){return this._onFinishChange=t,this}_callOnFinishChange(t){this.parent&&this.parent._callOnFinishChange(t),this._onFinishChange!==void 0&&this._onFinishChange.call(this,{object:t.object,property:t.property,value:t.getValue(),controller:t})}destroy(){this.parent&&(this.parent.children.splice(this.parent.children.indexOf(this),1),this.parent.folders.splice(this.parent.folders.indexOf(this),1)),this.domElement.parentElement&&this.domElement.parentElement.removeChild(this.domElement),Array.from(this.children).forEach(t=>t.destroy())}controllersRecursive(){let t=Array.from(this.controllers);return this.folders.forEach(i=>{t=t.concat(i.controllersRecursive())}),t}foldersRecursive(){let t=Array.from(this.folders);return this.folders.forEach(i=>{t=t.concat(i.foldersRecursive())}),t}}export{E as g}; diff --git a/examples/assets/marker.js b/examples/assets/marker.js new file mode 100644 index 000000000..2d1fbfdeb --- /dev/null +++ b/examples/assets/marker.js @@ -0,0 +1,88 @@ +var rn=Object.defineProperty;var on=(r,t,e)=>t in r?rn(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var G=(r,t,e)=>(on(r,typeof t!="symbol"?t+"":t,e),e);import{L as bt,B as ot,R as Ys,E as an,M as et,V as O,a as _t,P as Zs,T as _e,S as ki,b as U,C as we,c as ve,D as hn,A as ln,d as cn,e as dn,f as un,Q as ft,g as pn,h as mn,i as fn,j as ss,W as Ms,k as Vs,l as _n,m as Me,n as Jt,I as be,o as gn,p as tt,O as Ee,q as as,r as Hi,F as Gs,s as yn,t as wn,u as $,v as $s,w as Se,x as Tt,y as xn,z as se,G as vn,H as bn}from"./three.module-CYx2Afzj.js";var En=Object.defineProperty,Tn=(r,t,e)=>t in r?En(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,v=(r,t,e)=>(Tn(r,typeof t!="symbol"?t+"":t,e),e);const Yi=0,Pn=1,Cn=2,Js=2,hs=1.25,ti=1,ts=6*4+4+4,rs=65535,Mn=Math.pow(2,-24),ls=Symbol("SKIP_GENERATION");function On(r){return r.index?r.index.count:r.attributes.position.count}function te(r){return On(r)/3}function An(r,t=ArrayBuffer){return r>65535?new Uint32Array(new t(4*r)):new Uint16Array(new t(2*r))}function Dn(r,t){if(!r.index){const e=r.attributes.position.count,s=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=An(e,s);r.setIndex(new Hi(i,1));for(let n=0;na-h);for(let a=0;an.offset-o.offset),s=e[e.length-1];s.count=Math.min(t-s.offset,s.count);let i=0;return e.forEach(({count:n})=>i+=n),t!==i}function Q(r,t,e){return e.min.x=t[r],e.min.y=t[r+1],e.min.z=t[r+2],e.max.x=t[r+3],e.max.y=t[r+4],e.max.z=t[r+5],e}function Un(r){r[0]=r[1]=r[2]=1/0,r[3]=r[4]=r[5]=-1/0}function ei(r){let t=-1,e=-1/0;for(let s=0;s<3;s++){const i=r[s+3]-r[s];i>e&&(e=i,t=s)}return t}function si(r,t){t.set(r)}function ii(r,t,e){let s,i;for(let n=0;n<3;n++){const o=n+3;s=r[n],i=t[n],e[n]=si?s:i}}function Ue(r,t,e){for(let s=0;s<3;s++){const i=t[r+2*s],n=t[r+2*s+1],o=i-n,a=i+n;oe[s+3]&&(e[s+3]=a)}}function ie(r){const t=r[3]-r[0],e=r[4]-r[1],s=r[5]-r[2];return 2*(t*e+e*s+s*t)}function cs(r,t,e,s,i=null){let n=1/0,o=1/0,a=1/0,h=-1/0,l=-1/0,c=-1/0,u=1/0,d=1/0,p=1/0,y=-1/0,g=-1/0,f=-1/0;const _=i!==null;for(let w=t*6,b=(t+e)*6;wh&&(h=E),_&&my&&(y=m);const T=r[w+2],M=r[w+3],A=T-M,S=T+M;Al&&(l=S),_&&Tg&&(g=T);const D=r[w+4],B=r[w+5],z=D-B,H=D+B;zc&&(c=H),_&&Df&&(f=D)}s[0]=n,s[1]=o,s[2]=a,s[3]=h,s[4]=l,s[5]=c,_&&(i[0]=u,i[1]=d,i[2]=p,i[3]=y,i[4]=g,i[5]=f)}function Bn(r,t,e,s){let i=1/0,n=1/0,o=1/0,a=-1/0,h=-1/0,l=-1/0;for(let c=t*6,u=(t+e)*6;ca&&(a=d);const p=r[c+2];ph&&(h=p);const y=r[c+4];yl&&(l=y)}s[0]=i,s[1]=n,s[2]=o,s[3]=a,s[4]=h,s[5]=l}function Ln(r,t){Un(t);const e=r.attributes.position,s=r.index?r.index.array:null,i=te(r),n=new Float32Array(i*6),o=e.normalized,a=e.array,h=e.offset||0;let l=3;e.isInterleavedBufferAttribute&&(l=e.data.stride);const c=["getX","getY","getZ"];for(let u=0;uP&&(P=b),m>P&&(P=m);const E=(P-x)/2,T=_*2;n[p+T+0]=x+E,n[p+T+1]=E+(Math.abs(x)+E)*Mn,xt[_+3]&&(t[_+3]=P)}}return n}const vt=32,zn=(r,t)=>r.candidate-t.candidate,Pt=new Array(vt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Be=new Float32Array(6);function Fn(r,t,e,s,i,n){let o=-1,a=0;if(n===Yi)o=ei(t),o!==-1&&(a=(t[o]+t[o+3])/2);else if(n===Pn)o=ei(r),o!==-1&&(a=In(e,s,i,o));else if(n===Cn){const h=ie(r);let l=hs*i;const c=s*6,u=(s+i)*6;for(let d=0;d<3;d++){const p=t[d],y=(t[d+3]-p)/vt;if(i=x.candidate?Ue(w,e,x.rightCacheBounds):(Ue(w,e,x.leftCacheBounds),x.count++)}}for(let w=0;w<_;w++){const b=g[w],m=b.count,x=i-b.count,P=b.leftCacheBounds,E=b.rightCacheBounds;let T=0;m!==0&&(T=ie(P)/h);let M=0;x!==0&&(M=ie(E)/h);const A=ti+hs*(T*m+M*x);A=vt&&(w=vt-1);const b=Pt[w];b.count++,Ue(_,e,b.bounds)}const g=Pt[vt-1];si(g.bounds,g.rightCacheBounds);for(let _=vt-2;_>=0;_--){const w=Pt[_],b=Pt[_+1];ii(w.bounds,b.rightCacheBounds,w.rightCacheBounds)}let f=0;for(let _=0;_=h;)a--;if(o=h;)a--;if(o2**16,i=s?4:2,n=t?new SharedArrayBuffer(e*i):new ArrayBuffer(e*i),o=s?new Uint32Array(n):new Uint16Array(n);for(let a=0,h=o.length;a=i&&(u=!0,n&&(console.warn(`MeshBVH: Max depth of ${i} reached when generating BVH. Consider increasing maxDepth.`),console.warn(e))),P<=o||T>=i)return w(x+P),m.offset=x,m.count=P,m;const M=Fn(m.boundingData,E,y,x,P,a);if(M.axis===-1)return w(x+P),m.offset=x,m.count=P,m;const A=g(c,s,y,x,P,M);if(A===x||A===x+P)w(x+P),m.offset=x,m.count=P;else{m.splitAxis=M.axis;const S=new Le,D=x,B=A-x;m.left=S,S.boundingData=new Float32Array(6),cs(y,D,B,S.boundingData,p),b(S,D,B,p,T+1);const z=new Le,H=A,Z=P-B;m.right=z,z.boundingData=new Float32Array(6),cs(y,H,Z,z.boundingData,p),b(z,H,Z,p,T+1)}return m}}function Zn(r,t){const e=r.geometry;t.indirect&&(r._indirectBuffer=Hn(e,t.useSharedArrayBuffer),Sn(e)&&!t.verbose&&console.warn('MeshBVH: Provided geometry contains groups that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),r._indirectBuffer||Dn(e,t);const s=Yn(r,t);let i,n,o;const a=[],h=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer;for(let u=0;uMath.pow(2,32))throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return n[p+6]=m/4,m=c(m,w),n[p+7]=b,m}}}class Et{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let s=1/0,i=-1/0;for(let n=0,o=t.length;ni?a:i}this.min=s,this.max=i}setFromPoints(t,e){let s=1/0,i=-1/0;for(let n=0,o=e.length;ni?h:i}this.min=s,this.max=i}isSeparated(t){return this.min>t.max||t.min>this.max}}Et.prototype.setFromBox=function(){const r=new O;return function(t,e){const s=e.min,i=e.max;let n=1/0,o=-1/0;for(let a=0;a<=1;a++)for(let h=0;h<=1;h++)for(let l=0;l<=1;l++){r.x=s.x*a+i.x*(1-a),r.y=s.y*h+i.y*(1-h),r.z=s.z*l+i.z*(1-l);const c=t.dot(r);n=Math.min(c,n),o=Math.max(c,o)}this.min=n,this.max=o}}();const Vn=function(){const r=new O,t=new O,e=new O;return function(s,i,n){const o=s.start,a=r,h=i.start,l=t;e.subVectors(o,h),r.subVectors(s.end,s.start),t.subVectors(i.end,i.start);const c=e.dot(l),u=l.dot(a),d=l.dot(l),p=e.dot(a),y=a.dot(a)*d-u*u;let g,f;y!==0?g=(c*u-p*d)/y:g=0,f=(c+g*u)/d,n.x=g,n.y=f}}(),Ns=function(){const r=new _t,t=new O,e=new O;return function(s,i,n,o){Vn(s,i,r);let a=r.x,h=r.y;if(a>=0&&a<=1&&h>=0&&h<=1){s.at(a,n),i.at(h,o);return}else if(a>=0&&a<=1){h<0?i.at(0,o):i.at(1,o),s.closestPointToPoint(o,!0,n);return}else if(h>=0&&h<=1){a<0?s.at(0,n):s.at(1,n),i.closestPointToPoint(n,!0,o);return}else{let l;a<0?l=s.start:l=s.end;let c;h<0?c=i.start:c=i.end;const u=t,d=e;if(s.closestPointToPoint(c,!0,t),i.closestPointToPoint(l,!0,e),u.distanceToSquared(c)<=d.distanceToSquared(l)){n.copy(u),o.copy(c);return}else{n.copy(l),o.copy(d);return}}}}(),Nn=function(){const r=new O,t=new O,e=new Zs,s=new bt;return function(i,n){const{radius:o,center:a}=i,{a:h,b:l,c}=n;if(s.start=h,s.end=l,s.closestPointToPoint(a,!0,r).distanceTo(a)<=o||(s.start=h,s.end=c,s.closestPointToPoint(a,!0,r).distanceTo(a)<=o)||(s.start=l,s.end=c,s.closestPointToPoint(a,!0,r).distanceTo(a)<=o))return!0;const u=n.getPlane(e);if(Math.abs(u.distanceToPoint(a))<=o){const d=u.projectPoint(a,t);if(n.containsPoint(d))return!0}return!1}}(),Xn=1e-15;function ds(r){return Math.abs(r)new O),this.satBounds=new Array(4).fill().map(()=>new Et),this.points=[this.a,this.b,this.c],this.sphere=new ki,this.plane=new Zs,this.needsUpdate=!0}intersectsSphere(t){return Nn(t,this)}update(){const t=this.a,e=this.b,s=this.c,i=this.points,n=this.satAxes,o=this.satBounds,a=n[0],h=o[0];this.getNormal(a),h.setFromPoints(a,i);const l=n[1],c=o[1];l.subVectors(t,e),c.setFromPoints(l,i);const u=n[2],d=o[2];u.subVectors(e,s),d.setFromPoints(u,i);const p=n[3],y=o[3];p.subVectors(s,t),y.setFromPoints(p,i),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}gt.prototype.closestPointToSegment=function(){const r=new O,t=new O,e=new bt;return function(s,i=null,n=null){const{start:o,end:a}=s,h=this.points;let l,c=1/0;for(let u=0;u<3;u++){const d=(u+1)%3;e.start.copy(h[u]),e.end.copy(h[d]),Ns(e,s,r,t),l=r.distanceToSquared(t),l=2){(m===1?_.start:_.end).copy(p),b=2;break}if(b++,b===2&&m===-1)break}}return b}return function(g,f=null,_=!1){this.needsUpdate&&this.update(),g.isExtendedTriangle?g.needsUpdate&&g.update():(r.copy(g),r.update(),g=r);const w=this.plane,b=g.plane;if(Math.abs(w.normal.dot(b.normal))>1-1e-10){const m=this.satBounds,x=this.satAxes;e[0]=g.a,e[1]=g.b,e[2]=g.c;for(let T=0;T<4;T++){const M=m[T],A=x[T];if(s.setFromPoints(A,e),M.isSeparated(s))return!1}const P=g.satBounds,E=g.satAxes;t[0]=this.a,t[1]=this.b,t[2]=this.c;for(let T=0;T<4;T++){const M=P[T],A=E[T];if(s.setFromPoints(A,t),M.isSeparated(s))return!1}for(let T=0;T<4;T++){const M=x[T];for(let A=0;A<4;A++){const S=E[A];if(n.crossVectors(M,S),s.setFromPoints(n,t),i.setFromPoints(n,e),s.isSeparated(i))return!1}}return f&&(_||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),f.start.set(0,0,0),f.end.set(0,0,0)),!0}else{const m=y(this,b,u);if(m===1&&g.containsPoint(u.end))return f&&(f.start.copy(u.end),f.end.copy(u.end)),!0;if(m!==2)return!1;const x=y(g,w,d);if(x===1&&this.containsPoint(d.end))return f&&(f.start.copy(d.end),f.end.copy(d.end)),!0;if(x!==2)return!1;if(u.delta(a),d.delta(h),a.dot(h)<0){let D=d.start;d.start=d.end,d.end=D}const P=u.start.dot(a),E=u.end.dot(a),T=d.start.dot(a),M=d.end.dot(a),A=E0?f.start.copy(u.start):f.start.copy(d.start),l.subVectors(u.end,d.end),l.dot(a)<0?f.end.copy(u.end):f.end.copy(d.end)),!0)}}}();gt.prototype.distanceToPoint=function(){const r=new O;return function(t){return this.closestPointToPoint(t,r),t.distanceTo(r)}}();gt.prototype.distanceToTriangle=function(){const r=new O,t=new O,e=["a","b","c"],s=new bt,i=new bt;return function(n,o=null,a=null){const h=o||a?s:null;if(this.intersectsTriangle(n,h))return(o||a)&&(o&&h.getCenter(o),a&&h.getCenter(a)),0;let l=1/0;for(let c=0;c<3;c++){let u;const d=e[c],p=n[d];this.closestPointToPoint(p,r),u=p.distanceToSquared(r),unew O),this.satAxes=new Array(3).fill().map(()=>new O),this.satBounds=new Array(3).fill().map(()=>new Et),this.alignedSatBounds=new Array(3).fill().map(()=>new Et),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),s&&this.matrix.copy(s)}set(t,e,s){this.min.copy(t),this.max.copy(e),this.matrix.copy(s),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}st.prototype.update=function(){return function(){const r=this.matrix,t=this.min,e=this.max,s=this.points;for(let h=0;h<=1;h++)for(let l=0;l<=1;l++)for(let c=0;c<=1;c++){const u=1*h|2*l|4*c,d=s[u];d.x=h?e.x:t.x,d.y=l?e.y:t.y,d.z=c?e.z:t.z,d.applyMatrix4(r)}const i=this.satBounds,n=this.satAxes,o=s[0];for(let h=0;h<3;h++){const l=n[h],c=i[h],u=1<new bt),e=new Array(12).fill().map(()=>new bt),s=new O,i=new O;return function(n,o=0,a=null,h=null){if(this.needsUpdate&&this.update(),this.intersectsBox(n))return(a||h)&&(n.getCenter(i),this.closestPointToPoint(i,s),n.closestPointToPoint(s,i),a&&a.copy(s),h&&h.copy(i)),0;const l=o*o,c=n.min,u=n.max,d=this.points;let p=1/0;for(let g=0;g<8;g++){const f=d[g];i.copy(f).clamp(c,u);const _=f.distanceToSquared(i);if(_new gt)}}const lt=new Wn;function nt(r,t){return t[r+15]===65535}function rt(r,t){return t[r+6]}function ct(r,t){return t[r+14]}function dt(r){return r+8}function ut(r,t){return t[r+6]}function Ni(r,t){return t[r+7]}class Qn{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=s=>{e&&t.push(e),e=s,this.float32Array=new Float32Array(s),this.uint16Array=new Uint16Array(s),this.uint32Array=new Uint32Array(s)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const X=new Qn;let At,$t;const It=[],ze=new Xs(()=>new ot);function qn(r,t,e,s,i,n){At=ze.getPrimitive(),$t=ze.getPrimitive(),It.push(At,$t),X.setBuffer(r._roots[t]);const o=Os(0,r.geometry,e,s,i,n);X.clearBuffer(),ze.releasePrimitive(At),ze.releasePrimitive($t),It.pop(),It.pop();const a=It.length;return a>0&&($t=It[a-1],At=It[a-2]),o}function Os(r,t,e,s,i=null,n=0,o=0){const{float32Array:a,uint16Array:h,uint32Array:l}=X;let c=r*2;if(nt(c,h)){const u=rt(r,l),d=ct(c,h);return Q(r,a,At),s(u,d,!1,o,n+r,At)}else{let u=function(S){const{uint16Array:D,uint32Array:B}=X;let z=S*2;for(;!nt(z,D);)S=dt(S),z=S*2;return rt(S,B)},d=function(S){const{uint16Array:D,uint32Array:B}=X;let z=S*2;for(;!nt(z,D);)S=ut(S,B),z=S*2;return rt(S,B)+ct(z,D)};const p=dt(r),y=ut(r,l);let g=p,f=y,_,w,b,m;if(i&&(b=At,m=$t,Q(g,a,b),Q(f,a,m),_=i(b),w=i(m),w<_)){g=y,f=p;const S=_;_=w,w=S,b=m}b||(b=At,Q(g,a,b));const x=nt(g*2,h),P=e(b,x,_,o+1,n+g);let E;if(P===Js){const S=u(g),D=d(g)-S;E=s(S,D,!0,o+1,n+g,b)}else E=P&&Os(g,t,e,s,i,n,o+1);if(E)return!0;m=$t,Q(f,a,m);const T=nt(f*2,h),M=e(m,T,w,o+1,n+f);let A;if(M===Js){const S=u(f),D=d(f)-S;A=s(S,D,!0,o+1,n+f,m)}else A=M&&Os(f,t,e,s,i,n,o+1);return!!A}}const ne=new O,us=new O;function Kn(r,t,e={},s=0,i=1/0){const n=s*s,o=i*i;let a=1/0,h=null;if(r.shapecast({boundsTraverseOrder:c=>(ne.copy(t).clamp(c.min,c.max),ne.distanceToSquared(t)),intersectsBounds:(c,u,d)=>d{c.closestPointToPoint(t,ne);const d=t.distanceToSquared(ne);return d0&&l.normal.multiplyScalar(-1));const c={a:n,b:o,c:a,normal:new O,materialIndex:0};_e.getNormal(Rt,kt,Ht,c.normal),l.face=c,l.faceIndex=n}return l}function os(r,t,e,s,i){const n=s*3;let o=n+0,a=n+1,h=n+2;const l=r.index;r.index&&(o=l.getX(o),a=l.getX(a),h=l.getX(h));const{position:c,normal:u,uv:d,uv1:p}=r.attributes,y=Gn(e,c,u,d,p,o,a,h,t);return y?(y.faceIndex=s,i&&i.push(y),y):null}function K(r,t,e,s){const i=r.a,n=r.b,o=r.c;let a=t,h=t+1,l=t+2;e&&(a=e.getX(a),h=e.getX(h),l=e.getX(l)),i.x=s.getX(a),i.y=s.getY(a),i.z=s.getZ(a),n.x=s.getX(h),n.y=s.getY(h),n.z=s.getZ(h),o.x=s.getX(l),o.y=s.getY(l),o.z=s.getZ(l)}function $n(r,t,e,s,i,n){const{geometry:o,_indirectBuffer:a}=r;for(let h=s,l=s+i;hx&&(x=S),DP&&(P=D),BE&&(E=B)}return h[d+0]!==w||h[d+1]!==b||h[d+2]!==m||h[d+3]!==x||h[d+4]!==P||h[d+5]!==E?(h[d+0]=w,h[d+1]=b,h[d+2]=m,h[d+3]=x,h[d+4]=P,h[d+5]=E,!0):!1}else{const f=d+8,_=o[d+6],w=f+p,b=_+p;let m=y,x=!1,P=!1;t?m||(x=t.has(w),P=t.has(b),m=!x&&!P):(x=!0,P=!0);const E=m||x,T=m||P;let M=!1;E&&(M=u(f,p,m));let A=!1;T&&(A=u(_,p,m));const S=M||A;if(S)for(let D=0;D<3;D++){const B=f+D,z=_+D,H=h[B],Z=h[B+3],at=h[z],q=h[z+3];h[d+D]=Hq?Z:q}return S}}}const ai=new ot;function Dt(r,t,e,s){return Q(r,t,ai),e.intersectBox(ai,s)}function sr(r,t,e,s,i,n){const{geometry:o,_indirectBuffer:a}=r;for(let h=s,l=s+i;h=0;let u,d;c?(u=dt(r),d=ut(r,o)):(u=ut(r,o),d=dt(r));const p=Dt(u,i,s,li)?Ds(u,t,e,s):null;if(p){const g=p.point[l];if(c?g<=i[d+h]:g>=i[d+h+3])return p}const y=Dt(d,i,s,li)?Ds(d,t,e,s):null;return p&&y?p.distance<=y.distance?p:y:p||y||null}}const He=new ot,Yt=new gt,Zt=new gt,re=new et,ci=new st,Ye=new st;function hr(r,t,e,s){X.setBuffer(r._roots[t]);const i=Ss(0,r,e,s);return X.clearBuffer(),i}function Ss(r,t,e,s,i=null){const{float32Array:n,uint16Array:o,uint32Array:a}=X;let h=r*2;if(i===null&&(e.boundingBox||e.computeBoundingBox(),ci.set(e.boundingBox.min,e.boundingBox.max,s),i=ci),nt(h,o)){const l=t.geometry,c=l.index,u=l.attributes.position,d=e.index,p=e.attributes.position,y=rt(r,a),g=ct(h,o);if(re.copy(s).invert(),e.boundsTree)return Q(r,n,Ye),Ye.matrix.copy(re),Ye.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:f=>Ye.intersectsBox(f),intersectsTriangle:f=>{f.a.applyMatrix4(s),f.b.applyMatrix4(s),f.c.applyMatrix4(s),f.needsUpdate=!0;for(let _=y*3,w=(g+y)*3;_ps.distanceToBox(x),intersectsBounds:(x,P,E)=>E{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:E=>oe.distanceToBox(E),intersectsBounds:(E,T,M)=>M{for(let M=E,A=E+T;Mx&&(x=B),zP&&(P=z),HE&&(E=H)}}return h[d+0]!==w||h[d+1]!==b||h[d+2]!==m||h[d+3]!==x||h[d+4]!==P||h[d+5]!==E?(h[d+0]=w,h[d+1]=b,h[d+2]=m,h[d+3]=x,h[d+4]=P,h[d+5]=E,!0):!1}else{const f=d+8,_=o[d+6],w=f+p,b=_+p;let m=y,x=!1,P=!1;t?m||(x=t.has(w),P=t.has(b),m=!x&&!P):(x=!0,P=!0);const E=m||x,T=m||P;let M=!1;E&&(M=u(f,p,m));let A=!1;T&&(A=u(_,p,m));const S=M||A;if(S)for(let D=0;D<3;D++){const B=f+D,z=_+D,H=h[B],Z=h[B+3],at=h[z],q=h[z+3];h[d+D]=Hq?Z:q}return S}}}const di=new O;function fr(r,t,e,s,i){X.setBuffer(r._roots[t]),Us(0,r,e,s,i),X.clearBuffer()}function Us(r,t,e,s,i){const{float32Array:n,uint16Array:o,uint32Array:a}=X,h=r*2;if(nt(h,o)){const l=rt(r,a),c=ct(h,o);sr(t,e,s,l,c,i)}else{const l=dt(r);Dt(l,n,s,di)&&Us(l,t,e,s,i);const c=ut(r,a);Dt(c,n,s,di)&&Us(c,t,e,s,i)}}const ui=new O,_r=["x","y","z"];function gr(r,t,e,s){X.setBuffer(r._roots[t]);const i=Bs(0,r,e,s);return X.clearBuffer(),i}function Bs(r,t,e,s){const{float32Array:i,uint16Array:n,uint32Array:o}=X;let a=r*2;if(nt(a,n)){const h=rt(r,o),l=ct(a,n);return ir(t,e,s,h,l)}else{const h=Ni(r,o),l=_r[h],c=s.direction[l]>=0;let u,d;c?(u=dt(r),d=ut(r,o)):(u=ut(r,o),d=dt(r));const p=Dt(u,i,s,ui)?Bs(u,t,e,s):null;if(p){const g=p.point[l];if(c?g<=i[d+h]:g>=i[d+h+3])return p}const y=Dt(d,i,s,ui)?Bs(d,t,e,s):null;return p&&y?p.distance<=y.distance?p:y:p||y||null}}const Ve=new ot,Vt=new gt,Nt=new gt,ae=new et,pi=new st,Ne=new st;function yr(r,t,e,s){X.setBuffer(r._roots[t]);const i=Ls(0,r,e,s);return X.clearBuffer(),i}function Ls(r,t,e,s,i=null){const{float32Array:n,uint16Array:o,uint32Array:a}=X;let h=r*2;if(i===null&&(e.boundingBox||e.computeBoundingBox(),pi.set(e.boundingBox.min,e.boundingBox.max,s),i=pi),nt(h,o)){const l=t.geometry,c=l.index,u=l.attributes.position,d=e.index,p=e.attributes.position,y=rt(r,a),g=ct(h,o);if(ae.copy(s).invert(),e.boundsTree)return Q(r,n,Ne),Ne.matrix.copy(ae),Ne.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:f=>Ne.intersectsBox(f),intersectsTriangle:f=>{f.a.applyMatrix4(s),f.b.applyMatrix4(s),f.c.applyMatrix4(s),f.needsUpdate=!0;for(let _=y,w=g+y;_ms.distanceToBox(x),intersectsBounds:(x,P,E)=>E{if(t.boundsTree){const E=t.boundsTree;return E.shapecast({boundsTraverseOrder:T=>he.distanceToBox(T),intersectsBounds:(T,M,A)=>A{for(let A=T,S=T+M;Anew ot),Xt=new ot,Wt=new ot,fs=new ot,_s=new ot;let gs=!1;function Pr(r,t,e,s){if(gs)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");gs=!0;const i=r._roots,n=t._roots;let o,a=0,h=0;const l=new et().copy(e).invert();for(let c=0,u=i.length;ch.slice()),index:o.array.slice(),indirectBuffer:n?n.slice():null}:a={roots:i,index:o.array,indirectBuffer:n},a}static deserialize(t,e,s={}){s={setIndex:!0,indirect:!!t.indirectBuffer,...s};const{index:i,roots:n,indirectBuffer:o}=t,a=new Ws(e,{...s,[ls]:!0});if(a._roots=n,a._indirectBuffer=o||null,s.setIndex){const h=e.getIndex();if(h===null){const l=new Hi(t.index,1,!1);e.setIndex(l)}else h.array!==i&&(h.array.set(i),h.needsUpdate=!0)}return a}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(e=Object.assign({strategy:Yi,maxDepth:40,maxLeafTris:10,verbose:!0,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,[ls]:!1},e),e.useSharedArrayBuffer&&!Tr())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[ls]||(Zn(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new ot)));const{_indirectBuffer:s}=this;this.resolveTriangleIndex=e.indirect?i=>s[i]:i=>i}refit(t=null){return(this.indirect?mr:er)(this,t)}traverse(t,e=0){const s=this._roots[e],i=new Uint32Array(s),n=new Uint16Array(s);o(0);function o(a,h=0){const l=a*2,c=n[l+15]===rs;if(c){const u=i[a+6],d=n[l+14];t(h,c,new Float32Array(s,a*4,6),u,d)}else{const u=a+ts/4,d=i[a+6],p=i[a+7];t(h,c,new Float32Array(s,a*4,6),p)||(o(u,h+1),o(d,h+1))}}}raycast(t,e=Gs){const s=this._roots,i=this.geometry,n=[],o=e.isMaterial,a=Array.isArray(e),h=i.groups,l=o?e.side:e,c=this.indirect?fr:rr;for(let u=0,d=s.length;uu(d,p,y,g,f)?!0:s(d,p,this,a,y,g,e)}else o||(a?o=(u,d,p,y)=>s(u,d,this,a,p,y,e):o=(u,d,p)=>p);let h=!1,l=0;const c=this._roots;for(let u=0,d=c.length;u{const g=this.resolveTriangleIndex(y);K(o,g*3,a,h)}:y=>{K(o,y*3,a,h)},c=lt.getPrimitive(),u=t.geometry.index,d=t.geometry.attributes.position,p=t.indirect?y=>{const g=t.resolveTriangleIndex(y);K(c,g*3,u,d)}:y=>{K(c,y*3,u,d)};if(n){const y=(g,f,_,w,b,m,x,P)=>{for(let E=_,T=_+w;EWe.intersectsBox(s),intersectsTriangle:s=>We.intersectsTriangle(s)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,s={},i={},n=0,o=1/0){return(this.indirect?Er:pr)(this,t,e,s,i,n,o)}closestPointToPoint(t,e={},s=0,i=1/0){return Kn(this,t,e,s,i)}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(e=>{Q(0,new Float32Array(e),mi),t.union(mi)}),t}}function fi(r,t,e){return r===null||(r.point.applyMatrix4(t.matrixWorld),r.distance=r.point.distanceTo(e.ray.origin),r.object=t,r.distancee.far)?null:r}const ys=new yn,_i=new et,Cr=U.prototype.raycast;function Mr(r,t){if(this.geometry.boundsTree){if(this.material===void 0)return;_i.copy(this.matrixWorld).invert(),ys.copy(r.ray).applyMatrix4(_i);const e=this.geometry.boundsTree;if(r.firstHitOnly===!0){const s=fi(e.raycastFirst(ys,this.material),this,r);s&&t.push(s)}else{const s=e.raycast(ys,this.material);for(let i=0,n=s.length;i{const e=this.handlers.slice(0);for(const s of e)s(t)}),v(this,"handlers",[])}add(t){this.handlers.push(t)}remove(t){this.handlers=this.handlers.filter(e=>e!==t)}reset(){this.handlers.length=0}}class Qs{constructor(t){v(this,"isDisposeable",()=>"dispose"in this&&"onDisposed"in this),v(this,"isResizeable",()=>"resize"in this&&"getSize"in this),v(this,"isUpdateable",()=>"onAfterUpdate"in this&&"onBeforeUpdate"in this&&"update"in this),v(this,"isHideable",()=>"visible"in this),v(this,"isConfigurable",()=>"setup"in this&&"config"in this&&"onSetup"in this),this.components=t}}class St extends Qs{}class qs extends Qs{constructor(t){super(t),v(this,"worlds",new Map),v(this,"onWorldChanged",new I),v(this,"currentWorld",null),this.onWorldChanged.add(({world:e,action:s})=>{s==="removed"&&this.worlds.delete(e.uuid)})}}class Dr extends qs{constructor(){super(...arguments),v(this,"hasCameraControls",()=>"controls"in this)}}class Sr extends qs{constructor(){super(...arguments),v(this,"onAfterUpdate",new I),v(this,"onBeforeUpdate",new I),v(this,"onDisposed",new I),v(this,"onResize",new I),v(this,"onClippingPlanesUpdated",new I),v(this,"clippingPlanes",[])}updateClippingPlanes(){this.onClippingPlanesUpdated.trigger()}setPlane(t,e,s){e.isLocal=s;const i=this.clippingPlanes.indexOf(e);t&&i===-1?this.clippingPlanes.push(e):!t&&i>-1&&this.clippingPlanes.splice(i,1),this.three.clippingPlanes=this.clippingPlanes.filter(n=>!n.isLocal)}}const Xi=class zs extends St{constructor(t){super(t),v(this,"_disposedComponents",new Set),v(this,"enabled",!0),t.add(zs.uuid,this)}get(){return this._disposedComponents}destroy(t,e=!0,s=!0){t.removeFromParent();const i=t;i.dispose&&i.dispose(),this.disposeGeometryAndMaterials(t,e),s&&i.children&&i.children.length&&this.disposeChildren(i),t.children.length=0}disposeGeometry(t){const e=t;e.boundsTree&&e.disposeBoundsTree(),t.dispose()}disposeGeometryAndMaterials(t,e){const s=t;s.geometry&&this.disposeGeometry(s.geometry),e&&s.material&&zs.disposeMaterial(s),s.material=[],s.geometry=null}disposeChildren(t){for(const e of t.children)this.destroy(e)}static disposeMaterial(t){if(t.material)if(Array.isArray(t.material))for(const e of t.material)e.dispose();else t.material.dispose()}};v(Xi,"uuid","76e9cd8e-ad8f-4753-9ef6-cbc60f7247fe");let Te=Xi;class Ur extends qs{constructor(t){super(t),v(this,"onDisposed",new I)}dispose(){const t=this.components.get(Te);for(const e of this.three.children){const s=e;s.geometry&&t.destroy(s)}this.three.children=[],this.onDisposed.trigger(),this.onDisposed.reset()}}const Fs=class j{static create(){const t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,s=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return`${j._lut[t&255]+j._lut[t>>8&255]+j._lut[t>>16&255]+j._lut[t>>24&255]}-${j._lut[e&255]}${j._lut[e>>8&255]}-${j._lut[e>>16&15|64]}${j._lut[e>>24&255]}-${j._lut[s&63|128]}${j._lut[s>>8&255]}-${j._lut[s>>16&255]}${j._lut[s>>24&255]}${j._lut[i&255]}${j._lut[i>>8&255]}${j._lut[i>>16&255]}${j._lut[i>>24&255]}`.toLowerCase()}static validate(t){if(!j._pattern.test(t))throw new Error(`${t} is not a valid UUID v4. + +- If you're the tool creator, you can take one from https://www.uuidgenerator.net/. + +- If you're using a platform tool, verify the uuid isn't misspelled or contact the tool creator.`)}};v(Fs,"_pattern",/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/),v(Fs,"_lut",["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"]);let Wi=Fs;class gi{static isTransparent(t){return t.transparent&&t.opacity<1}}const Qi=class qi{constructor(){v(this,"onDisposed",new I),v(this,"list",new Map),v(this,"enabled",!1),v(this,"_clock"),v(this,"update",()=>{if(!this.enabled)return;const t=this._clock.getDelta();for(const[e,s]of this.list)s.enabled&&s.isUpdateable()&&s.update(t);requestAnimationFrame(this.update)}),this._clock=new fn,qi.setupBVH()}add(t,e){if(this.list.has(t))throw new Error("You're trying to add a component that already exists in the components intance. Use Components.get() instead.");Wi.validate(t),this.list.set(t,e)}get(t){const e=t.uuid;if(!this.list.has(e)){const s=new t(this);return this.list.has(e)||this.add(e,s),s}return this.list.get(e)}init(){this.enabled=!0,this._clock.start(),this.update()}dispose(){this.enabled=!1;for(const[t,e]of this.list)e.enabled=!1,e.isDisposeable()&&e.dispose();this._clock.stop(),this.onDisposed.trigger(),this.onDisposed.reset()}static setupBVH(){ss.prototype.computeBoundsTree=Or,ss.prototype.disposeBoundsTree=Ar,U.prototype.raycast=Mr}};v(Qi,"release","1.4.21");let Br=Qi;class Lr{constructor(t){v(this,"_event"),v(this,"_position",new _t),v(this,"onDisposed",new I),v(this,"updateMouseInfo",e=>{this._event=e}),this.dom=t,this.setupEvents(!0)}get position(){if(this._event){const t=this.dom.getBoundingClientRect();this._position.x=this.getPositionX(t,this._event),this._position.y=this.getPositionY(t,this._event)}return this._position}dispose(){this.setupEvents(!1),this.onDisposed.trigger(),this.onDisposed.reset()}getPositionY(t,e){return-((e.clientY-t.top)/(t.bottom-t.top))*2+1}getPositionX(t,e){return(e.clientX-t.left)/(t.right-t.left)*2-1}setupEvents(t){t?this.dom.addEventListener("mousemove",this.updateMouseInfo):this.dom.removeEventListener("mousemove",this.updateMouseInfo)}}class zr{constructor(t,e){v(this,"enabled",!0),v(this,"components"),v(this,"onDisposed",new I),v(this,"mouse"),v(this,"three",new Ys),v(this,"world");const s=e.renderer;if(!s)throw new Error("A renderer is needed for the raycaster to work!");this.world=e,this.mouse=new Lr(s.three.domElement),this.components=t}dispose(){this.mouse.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}castRay(t=Array.from(this.world.meshes)){if(!this.world)throw new Error("A world is needed to cast rays!");const e=this.world.camera.three;return this.three.setFromCamera(this.mouse.position,e),this.intersect(t)}castRayFromVector(t,e,s=Array.from(this.world.meshes)){return this.three.set(t,e),this.intersect(s)}intersect(t=Array.from(this.world.meshes)){const e=this.three.intersectObjects(t),s=this.filterClippingPlanes(e);return s.length>0?s[0]:null}filterClippingPlanes(t){if(!this.world.renderer)throw new Error("Renderer not found!");const e=this.world.renderer.three;if(!e.clippingPlanes)return t;const s=e.clippingPlanes;return t.length<=0||!s||(s==null?void 0:s.length)<=0?t:t.filter(i=>s.every(n=>n.distanceToPoint(i.point)>0))}}const Ki=class ji extends St{constructor(t){super(t),v(this,"enabled",!0),v(this,"list",new Map),v(this,"onDisposed",new I),t.add(ji.uuid,this)}get(t){if(this.list.has(t.uuid))return this.list.get(t.uuid);const e=new zr(this.components,t);return this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)}),e}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}};v(Ki,"uuid","d5d8bdf0-db25-4952-b951-b643af207ace");let yi=Ki;class Fr extends Qs{constructor(t){super(t),v(this,"meshes",new Set),v(this,"onAfterUpdate",new I),v(this,"onBeforeUpdate",new I),v(this,"enabled",!0),v(this,"uuid",Wi.create()),v(this,"onDisposed",new I),v(this,"_scene"),v(this,"_camera"),v(this,"_renderer",null)}get scene(){if(!this._scene)throw new Error("No scene initialized!");return this._scene}set scene(t){this._scene=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get camera(){if(!this._camera)throw new Error("No camera initialized!");return this._camera}set camera(t){this._camera=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get renderer(){return this._renderer}set renderer(t){this._renderer=t,t&&(t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"}))}update(t){this.enabled&&(!this._scene||!this._camera||(this.scene.currentWorld=this,this.camera.currentWorld=this,this.renderer&&(this.renderer.currentWorld=this),this.onBeforeUpdate.trigger(),this.scene.isUpdateable()&&this.scene.update(t),this.camera.isUpdateable()&&this.camera.update(t),this.renderer&&this.renderer.update(t),this.onAfterUpdate.trigger()))}dispose(t=!0){if(this.enabled=!1,this.scene.onWorldChanged.trigger({world:this,action:"removed"}),this.camera.onWorldChanged.trigger({world:this,action:"removed"}),this.renderer&&this.renderer.onWorldChanged.trigger({world:this,action:"removed"}),t){const e=this.components.get(Te);this.scene.dispose(),this.camera.isDisposeable()&&this.camera.dispose(),this.renderer&&this.renderer.dispose();for(const s of this.meshes)e.destroy(s);this.meshes.clear()}this._scene=null,this._camera=null,this._renderer=null,this.onDisposed.trigger()}}class Ir extends Ur{constructor(t){super(t),v(this,"isSetup",!1),v(this,"three"),v(this,"onSetup",new I),v(this,"config",{directionalLight:{color:new we("white"),intensity:1.5,position:new O(5,10,3)},ambientLight:{color:new we("white"),intensity:1}}),this.three=new ve,this.three.background=new we(2107698)}setup(t){this.config={...this.config,...t};const e=new hn(this.config.directionalLight.color,this.config.directionalLight.intensity);e.position.copy(this.config.directionalLight.position);const s=new ln(this.config.ambientLight.color,this.config.ambientLight.intensity);this.three.add(e,s),this.isSetup=!0,this.onSetup.trigger(this)}}class Rr extends Sr{constructor(t,e,s){super(t),v(this,"enabled",!0),v(this,"container"),v(this,"three"),v(this,"_canvas"),v(this,"_parameters"),v(this,"onContainerUpdated",new I),v(this,"resize",o=>{if(this.updateContainer(),!this.container)return;const a=o?o.x:this.container.clientWidth,h=o?o.y:this.container.clientHeight;this.three.setSize(a,h),this.onResize.trigger(new _t(a,h))}),v(this,"resizeEvent",()=>{this.resize()}),v(this,"onContextLost",o=>{o.preventDefault(),this.components.enabled=!1}),v(this,"onContextBack",()=>{this.three.setRenderTarget(null),this.three.dispose(),this.three=new Ms({canvas:this._canvas,antialias:!0,alpha:!0,...this._parameters}),this.components.enabled=!0}),this.container=e||null,this._parameters=s,this.three=new Ms({antialias:!0,alpha:!0,...s}),this.three.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.setupRenderer(),this.setupEvents(!0),this.resize(),this._canvas=this.three.domElement;const i=this.three.getContext(),{canvas:n}=i;n.addEventListener("webglcontextlost",this.onContextLost,!1),n.addEventListener("webglcontextrestored",this.onContextBack,!1)}update(){if(!this.enabled||!this.currentWorld)return;this.onBeforeUpdate.trigger(this);const t=this.currentWorld.scene.three,e=this.currentWorld.camera.three;this.three.render(t,e),this.onAfterUpdate.trigger(this)}dispose(){this.enabled=!1,this.setupEvents(!1),this.three.domElement.remove(),this.three.dispose(),this.onResize.reset(),this.onAfterUpdate.reset(),this.onBeforeUpdate.reset(),this.onDisposed.trigger(),this.onDisposed.reset()}getSize(){return new _t(this.three.domElement.clientWidth,this.three.domElement.clientHeight)}setupEvents(t){const e=this.three.domElement;t?e.addEventListener("resize",this.resizeEvent):e.removeEventListener("resize",this.resizeEvent)}setupRenderer(){this.three.localClippingEnabled=!0,this.container&&this.container.appendChild(this.three.domElement),this.updateContainer()}updateContainer(){if(!this.container){const t=this.three.domElement.parentElement;t&&(this.container=t,this.onContainerUpdated.trigger(t))}}}/*! + * camera-controls + * https://github.com/yomotsu/camera-controls + * (c) 2017 @yomotsu + * Released under the MIT License. + */const F={LEFT:1,RIGHT:2,MIDDLE:4},C=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,OFFSET:4,DOLLY:8,ZOOM:16,TOUCH_ROTATE:32,TOUCH_TRUCK:64,TOUCH_OFFSET:128,TOUCH_DOLLY:256,TOUCH_ZOOM:512,TOUCH_DOLLY_TRUCK:1024,TOUCH_DOLLY_OFFSET:2048,TOUCH_DOLLY_ROTATE:4096,TOUCH_ZOOM_TRUCK:8192,TOUCH_ZOOM_OFFSET:16384,TOUCH_ZOOM_ROTATE:32768}),Qt={NONE:0,IN:1,OUT:-1};function Ut(r){return r.isPerspectiveCamera}function Mt(r){return r.isOrthographicCamera}const qt=Math.PI*2,wi=Math.PI/2,Gi=1e-5,le=Math.PI/180;function mt(r,t,e){return Math.max(t,Math.min(e,r))}function N(r,t=Gi){return Math.abs(r)0==p>c&&(p=c,e.value=(p-c)/n),p}function vi(r,t,e,s,i=1/0,n,o){s=Math.max(1e-4,s);const a=2/s,h=a*n,l=1/(1+h+.48*h*h+.235*h*h*h);let c=t.x,u=t.y,d=t.z,p=r.x-c,y=r.y-u,g=r.z-d;const f=c,_=u,w=d,b=i*s,m=b*b,x=p*p+y*y+g*g;if(x>m){const H=Math.sqrt(x);p=p/H*b,y=y/H*b,g=g/H*b}c=r.x-p,u=r.y-y,d=r.z-g;const P=(e.x+a*p)*n,E=(e.y+a*y)*n,T=(e.z+a*g)*n;e.x=(e.x-a*P)*l,e.y=(e.y-a*E)*l,e.z=(e.z-a*T)*l,o.x=c+(p+P)*l,o.y=u+(y+E)*l,o.z=d+(g+T)*l;const M=f-r.x,A=_-r.y,S=w-r.z,D=o.x-f,B=o.y-_,z=o.z-w;return M*D+A*B+S*z>0&&(o.x=f,o.y=_,o.z=w,e.x=(o.x-f)/n,e.y=(o.y-_)/n,e.z=(o.z-w)/n),o}function ws(r,t){t.set(0,0),r.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=r.length,t.y/=r.length}function xs(r,t){return Mt(r)?(console.warn(`${t} is not supported in OrthographicCamera`),!0):!1}class kr{constructor(){this._listeners={}}addEventListener(t,e){const s=this._listeners;s[t]===void 0&&(s[t]=[]),s[t].indexOf(e)===-1&&s[t].push(e)}hasEventListener(t,e){const s=this._listeners;return s[t]!==void 0&&s[t].indexOf(e)!==-1}removeEventListener(t,e){const s=this._listeners[t];if(s!==void 0){const i=s.indexOf(e);i!==-1&&s.splice(i,1)}}removeAllEventListeners(t){if(!t){this._listeners={};return}Array.isArray(this._listeners[t])&&(this._listeners[t].length=0)}dispatchEvent(t){const e=this._listeners[t.type];if(e!==void 0){t.target=this;const s=e.slice(0);for(let i=0,n=s.length;i{},this._enabled=!0,this._state=C.NONE,this._viewport=null,this._changedDolly=0,this._changedZoom=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=new DOMRect,this._isDragging=!1,this._dragNeedsUpdate=!0,this._activePointers=[],this._lockedPointer=null,this._interactiveArea=new DOMRect(0,0,1,1),this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._lastDollyDirection=Qt.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new L.Vector3,this._focalOffsetVelocity=new L.Vector3,this._zoomVelocity={value:0},this._truckInternal=(m,x,P)=>{let E,T;if(Ut(this._camera)){const M=R.copy(this._camera.position).sub(this._target),A=this._camera.getEffectiveFOV()*le,S=M.length()*Math.tan(A*.5);E=this.truckSpeed*m*S/this._elementRect.height,T=this.truckSpeed*x*S/this._elementRect.height}else if(Mt(this._camera)){const M=this._camera;E=m*(M.right-M.left)/M.zoom/this._elementRect.width,T=x*(M.top-M.bottom)/M.zoom/this._elementRect.height}else return;this.verticalDragToForward?(P?this.setFocalOffset(this._focalOffsetEnd.x+E,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(E,0,!0),this.forward(-T,!0)):P?this.setFocalOffset(this._focalOffsetEnd.x+E,this._focalOffsetEnd.y+T,this._focalOffsetEnd.z,!0):this.truck(E,T,!0)},this._rotateInternal=(m,x)=>{const P=qt*this.azimuthRotateSpeed*m/this._elementRect.height,E=qt*this.polarRotateSpeed*x/this._elementRect.height;this.rotate(P,E,!0)},this._dollyInternal=(m,x,P)=>{const E=Math.pow(.95,-m*this.dollySpeed),T=this._sphericalEnd.radius,M=this._sphericalEnd.radius*E,A=mt(M,this.minDistance,this.maxDistance),S=A-M;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(M,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(S,!0),this._dollyToNoClamp(A,!0)):this._dollyToNoClamp(A,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?M:A)-T,this._dollyControlCoord.set(x,P)),this._lastDollyDirection=Math.sign(-m)},this._zoomInternal=(m,x,P)=>{const E=Math.pow(.95,m*this.dollySpeed),T=this._zoom,M=this._zoom*E;this.zoomTo(M,!0),this.dollyToCursor&&(this._changedZoom+=M-T,this._dollyControlCoord.set(x,P))},typeof L>"u"&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=t,this._yAxisUpSpace=new L.Quaternion().setFromUnitVectors(this._camera.up,Ke),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=C.NONE,this._target=new L.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new L.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new L.Spherical().setFromVector3(R.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._lastDistance=this._spherical.radius,this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._lastZoom=this._zoom,this._nearPlaneCorners=[new L.Vector3,new L.Vector3,new L.Vector3,new L.Vector3],this._updateNearPlaneCorners(),this._boundary=new L.Box3(new L.Vector3(-1/0,-1/0,-1/0),new L.Vector3(1/0,1/0,1/0)),this._cameraUp0=this._camera.up.clone(),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlCoord=new L.Vector2,this.mouseButtons={left:C.ROTATE,middle:C.DOLLY,right:C.TRUCK,wheel:Ut(this._camera)?C.DOLLY:Mt(this._camera)?C.ZOOM:C.NONE},this.touches={one:C.TOUCH_ROTATE,two:Ut(this._camera)?C.TOUCH_DOLLY_TRUCK:Mt(this._camera)?C.TOUCH_ZOOM_TRUCK:C.NONE,three:C.TOUCH_TRUCK};const s=new L.Vector2,i=new L.Vector2,n=new L.Vector2,o=m=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const E=this._domElement.getBoundingClientRect(),T=m.clientX/E.width,M=m.clientY/E.height;if(Tthis._interactiveArea.right||Mthis._interactiveArea.bottom)return}const x=m.pointerType!=="mouse"?null:(m.buttons&F.LEFT)===F.LEFT?F.LEFT:(m.buttons&F.MIDDLE)===F.MIDDLE?F.MIDDLE:(m.buttons&F.RIGHT)===F.RIGHT?F.RIGHT:null;if(x!==null){const E=this._findPointerByMouseButton(x);E&&this._disposePointer(E)}if((m.buttons&F.LEFT)===F.LEFT&&this._lockedPointer)return;const P={pointerId:m.pointerId,clientX:m.clientX,clientY:m.clientY,deltaX:0,deltaY:0,mouseButton:x};this._activePointers.push(P),this._domElement.ownerDocument.removeEventListener("pointermove",h,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",c),this._domElement.ownerDocument.addEventListener("pointermove",h,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",c),this._isDragging=!0,g(m)},a=m=>{if(!this._enabled||!this._domElement||this._lockedPointer)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const E=this._domElement.getBoundingClientRect(),T=m.clientX/E.width,M=m.clientY/E.height;if(Tthis._interactiveArea.right||Mthis._interactiveArea.bottom)return}const x=(m.buttons&F.LEFT)===F.LEFT?F.LEFT:(m.buttons&F.MIDDLE)===F.MIDDLE?F.MIDDLE:(m.buttons&F.RIGHT)===F.RIGHT?F.RIGHT:null;if(x!==null){const E=this._findPointerByMouseButton(x);E&&this._disposePointer(E)}const P={pointerId:1,clientX:m.clientX,clientY:m.clientY,deltaX:0,deltaY:0,mouseButton:(m.buttons&F.LEFT)===F.LEFT?F.LEFT:(m.buttons&F.MIDDLE)===F.LEFT?F.MIDDLE:(m.buttons&F.RIGHT)===F.LEFT?F.RIGHT:null};this._activePointers.push(P),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("mouseup",u),this._domElement.ownerDocument.addEventListener("mousemove",l),this._domElement.ownerDocument.addEventListener("mouseup",u),this._isDragging=!0,g(m)},h=m=>{m.cancelable&&m.preventDefault();const x=m.pointerId,P=this._lockedPointer||this._findPointerById(x);if(P){if(P.clientX=m.clientX,P.clientY=m.clientY,P.deltaX=m.movementX,P.deltaY=m.movementY,this._state=0,m.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(m.buttons&F.LEFT)===F.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(m.buttons&F.MIDDLE)===F.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(m.buttons&F.RIGHT)===F.RIGHT&&(this._state=this._state|this.mouseButtons.right);f()}},l=m=>{const x=this._lockedPointer||this._findPointerById(1);x&&(x.clientX=m.clientX,x.clientY=m.clientY,x.deltaX=m.movementX,x.deltaY=m.movementY,this._state=0,(this._lockedPointer||(m.buttons&F.LEFT)===F.LEFT)&&(this._state=this._state|this.mouseButtons.left),(m.buttons&F.MIDDLE)===F.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(m.buttons&F.RIGHT)===F.RIGHT&&(this._state=this._state|this.mouseButtons.right),f())},c=m=>{const x=this._findPointerById(m.pointerId);if(!(x&&x===this._lockedPointer)){if(x&&this._disposePointer(x),m.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=C.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=C.NONE;_()}},u=()=>{const m=this._findPointerById(1);m&&m===this._lockedPointer||(m&&this._disposePointer(m),this._state=C.NONE,_())};let d=-1;const p=m=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===C.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const M=this._domElement.getBoundingClientRect(),A=m.clientX/M.width,S=m.clientY/M.height;if(Athis._interactiveArea.right||Sthis._interactiveArea.bottom)return}if(m.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===C.ROTATE||this.mouseButtons.wheel===C.TRUCK){const M=performance.now();d-M<1e3&&this._getClientRect(this._elementRect),d=M}const x=Yr?-1:-3,P=m.deltaMode===1?m.deltaY/x:m.deltaY/(x*10),E=this.dollyToCursor?(m.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,T=this.dollyToCursor?(m.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case C.ROTATE:{this._rotateInternal(m.deltaX,m.deltaY),this._isUserControllingRotate=!0;break}case C.TRUCK:{this._truckInternal(m.deltaX,m.deltaY,!1),this._isUserControllingTruck=!0;break}case C.OFFSET:{this._truckInternal(m.deltaX,m.deltaY,!0),this._isUserControllingOffset=!0;break}case C.DOLLY:{this._dollyInternal(-P,E,T),this._isUserControllingDolly=!0;break}case C.ZOOM:{this._zoomInternal(-P,E,T),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},y=m=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===Pe.ACTION.NONE){const x=m instanceof PointerEvent?m.pointerId:0,P=this._findPointerById(x);P&&this._disposePointer(P),this._domElement.ownerDocument.removeEventListener("pointermove",h,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",c),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("mouseup",u);return}m.preventDefault()}},g=m=>{if(this._enabled){if(ws(this._activePointers,it),this._getClientRect(this._elementRect),s.copy(it),i.copy(it),this._activePointers.length>=2){const x=it.x-this._activePointers[1].clientX,P=it.y-this._activePointers[1].clientY,E=Math.sqrt(x*x+P*P);n.set(0,E);const T=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,M=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;i.set(T,M)}if(this._state=0,!m)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in m&&m.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else!this._lockedPointer&&(m.buttons&F.LEFT)===F.LEFT&&(this._state=this._state|this.mouseButtons.left),(m.buttons&F.MIDDLE)===F.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(m.buttons&F.RIGHT)===F.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&C.ROTATE)===C.ROTATE||(this._state&C.TOUCH_ROTATE)===C.TOUCH_ROTATE||(this._state&C.TOUCH_DOLLY_ROTATE)===C.TOUCH_DOLLY_ROTATE||(this._state&C.TOUCH_ZOOM_ROTATE)===C.TOUCH_ZOOM_ROTATE)&&(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),((this._state&C.TRUCK)===C.TRUCK||(this._state&C.TOUCH_TRUCK)===C.TOUCH_TRUCK||(this._state&C.TOUCH_DOLLY_TRUCK)===C.TOUCH_DOLLY_TRUCK||(this._state&C.TOUCH_ZOOM_TRUCK)===C.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&C.DOLLY)===C.DOLLY||(this._state&C.TOUCH_DOLLY)===C.TOUCH_DOLLY||(this._state&C.TOUCH_DOLLY_TRUCK)===C.TOUCH_DOLLY_TRUCK||(this._state&C.TOUCH_DOLLY_OFFSET)===C.TOUCH_DOLLY_OFFSET||(this._state&C.TOUCH_DOLLY_ROTATE)===C.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&C.ZOOM)===C.ZOOM||(this._state&C.TOUCH_ZOOM)===C.TOUCH_ZOOM||(this._state&C.TOUCH_ZOOM_TRUCK)===C.TOUCH_ZOOM_TRUCK||(this._state&C.TOUCH_ZOOM_OFFSET)===C.TOUCH_ZOOM_OFFSET||(this._state&C.TOUCH_ZOOM_ROTATE)===C.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&C.OFFSET)===C.OFFSET||(this._state&C.TOUCH_OFFSET)===C.TOUCH_OFFSET||(this._state&C.TOUCH_DOLLY_OFFSET)===C.TOUCH_DOLLY_OFFSET||(this._state&C.TOUCH_ZOOM_OFFSET)===C.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})}},f=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,ws(this._activePointers,it);const m=this._domElement&&document.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,x=m?-m.deltaX:i.x-it.x,P=m?-m.deltaY:i.y-it.y;if(i.copy(it),((this._state&C.ROTATE)===C.ROTATE||(this._state&C.TOUCH_ROTATE)===C.TOUCH_ROTATE||(this._state&C.TOUCH_DOLLY_ROTATE)===C.TOUCH_DOLLY_ROTATE||(this._state&C.TOUCH_ZOOM_ROTATE)===C.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(x,P),this._isUserControllingRotate=!0),(this._state&C.DOLLY)===C.DOLLY||(this._state&C.ZOOM)===C.ZOOM){const E=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,T=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0,M=this.dollyDragInverted?-1:1;(this._state&C.DOLLY)===C.DOLLY?(this._dollyInternal(M*P*qe,E,T),this._isUserControllingDolly=!0):(this._zoomInternal(M*P*qe,E,T),this._isUserControllingZoom=!0)}if((this._state&C.TOUCH_DOLLY)===C.TOUCH_DOLLY||(this._state&C.TOUCH_ZOOM)===C.TOUCH_ZOOM||(this._state&C.TOUCH_DOLLY_TRUCK)===C.TOUCH_DOLLY_TRUCK||(this._state&C.TOUCH_ZOOM_TRUCK)===C.TOUCH_ZOOM_TRUCK||(this._state&C.TOUCH_DOLLY_OFFSET)===C.TOUCH_DOLLY_OFFSET||(this._state&C.TOUCH_ZOOM_OFFSET)===C.TOUCH_ZOOM_OFFSET||(this._state&C.TOUCH_DOLLY_ROTATE)===C.TOUCH_DOLLY_ROTATE||(this._state&C.TOUCH_ZOOM_ROTATE)===C.TOUCH_ZOOM_ROTATE){const E=it.x-this._activePointers[1].clientX,T=it.y-this._activePointers[1].clientY,M=Math.sqrt(E*E+T*T),A=n.y-M;n.set(0,M);const S=this.dollyToCursor?(i.x-this._elementRect.x)/this._elementRect.width*2-1:0,D=this.dollyToCursor?(i.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&C.TOUCH_DOLLY)===C.TOUCH_DOLLY||(this._state&C.TOUCH_DOLLY_ROTATE)===C.TOUCH_DOLLY_ROTATE||(this._state&C.TOUCH_DOLLY_TRUCK)===C.TOUCH_DOLLY_TRUCK||(this._state&C.TOUCH_DOLLY_OFFSET)===C.TOUCH_DOLLY_OFFSET?(this._dollyInternal(A*qe,S,D),this._isUserControllingDolly=!0):(this._zoomInternal(A*qe,S,D),this._isUserControllingZoom=!0)}((this._state&C.TRUCK)===C.TRUCK||(this._state&C.TOUCH_TRUCK)===C.TOUCH_TRUCK||(this._state&C.TOUCH_DOLLY_TRUCK)===C.TOUCH_DOLLY_TRUCK||(this._state&C.TOUCH_ZOOM_TRUCK)===C.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(x,P,!1),this._isUserControllingTruck=!0),((this._state&C.OFFSET)===C.OFFSET||(this._state&C.TOUCH_OFFSET)===C.TOUCH_OFFSET||(this._state&C.TOUCH_DOLLY_OFFSET)===C.TOUCH_DOLLY_OFFSET||(this._state&C.TOUCH_ZOOM_OFFSET)===C.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(x,P,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},_=()=>{ws(this._activePointers,it),i.copy(it),this._dragNeedsUpdate=!1,(this._activePointers.length===0||this._activePointers.length===1&&this._activePointers[0]===this._lockedPointer)&&(this._isDragging=!1),this._activePointers.length===0&&this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointermove",h,{passive:!1}),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("pointerup",c),this._domElement.ownerDocument.removeEventListener("mouseup",u),this.dispatchEvent({type:"controlend"}))};this.lockPointer=()=>{!this._enabled||!this._domElement||(this.cancel(),this._lockedPointer={pointerId:-1,clientX:0,clientY:0,deltaX:0,deltaY:0,mouseButton:null},this._activePointers.push(this._lockedPointer),this._domElement.ownerDocument.removeEventListener("pointermove",h,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",c),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",w),this._domElement.ownerDocument.addEventListener("pointerlockerror",b),this._domElement.ownerDocument.addEventListener("pointermove",h,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",c),g())},this.unlockPointer=()=>{this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),document.exitPointerLock(),this.cancel(),this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointerlockchange",w),this._domElement.ownerDocument.removeEventListener("pointerlockerror",b))};const w=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},b=()=>{this.unlockPointer()};this._addAllEventListeners=m=>{this._domElement=m,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",o),Zr&&this._domElement.addEventListener("mousedown",a),this._domElement.addEventListener("pointercancel",c),this._domElement.addEventListener("wheel",p,{passive:!1}),this._domElement.addEventListener("contextmenu",y)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",o),this._domElement.removeEventListener("mousedown",a),this._domElement.removeEventListener("pointercancel",c),this._domElement.removeEventListener("wheel",p,{passive:!1}),this._domElement.removeEventListener("contextmenu",y),this._domElement.ownerDocument.removeEventListener("pointermove",h,{passive:!1}),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("pointerup",c),this._domElement.ownerDocument.removeEventListener("mouseup",u),this._domElement.ownerDocument.removeEventListener("pointerlockchange",w),this._domElement.ownerDocument.removeEventListener("pointerlockerror",b))},this.cancel=()=>{this._state!==C.NONE&&(this._state=C.NONE,this._activePointers.length=0,_())},e&&this.connect(e),this.update(0)}get camera(){return this._camera}set camera(t){this._camera=t,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(t){this._enabled=t,this._domElement&&(t?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(t){this._spherical.radius===t&&this._sphericalEnd.radius===t||(this._spherical.radius=t,this._sphericalEnd.radius=t,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(t){this._spherical.theta===t&&this._sphericalEnd.theta===t||(this._spherical.theta=t,this._sphericalEnd.theta=t,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(t){this._spherical.phi===t&&this._sphericalEnd.phi===t||(this._spherical.phi=t,this._sphericalEnd.phi=t,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(t){this._boundaryEnclosesCamera=t,this._needsUpdate=!0}set interactiveArea(t){this._interactiveArea.width=mt(t.width,0,1),this._interactiveArea.height=mt(t.height,0,1),this._interactiveArea.x=mt(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=mt(t.y,0,1-this._interactiveArea.height)}addEventListener(t,e){super.addEventListener(t,e)}removeEventListener(t,e){super.removeEventListener(t,e)}rotate(t,e,s=!1){return this.rotateTo(this._sphericalEnd.theta+t,this._sphericalEnd.phi+e,s)}rotateAzimuthTo(t,e=!1){return this.rotateTo(t,this._sphericalEnd.phi,e)}rotatePolarTo(t,e=!1){return this.rotateTo(this._sphericalEnd.theta,t,e)}rotateTo(t,e,s=!1){this._isUserControllingRotate=!1;const i=mt(t,this.minAzimuthAngle,this.maxAzimuthAngle),n=mt(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=i,this._sphericalEnd.phi=n,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const o=!s||Y(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Y(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(o)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Qt.NONE,this._changedDolly=0,this._dollyToNoClamp(mt(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const s=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const n=this._collisionTest(),o=Y(n,this._spherical.radius);if(!(s>t)&&o)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,n)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const i=!e||Y(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(i)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(ue).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const s=!e||Y(this._target.x,this._targetEnd.x,this.restThreshold)&&Y(this._target.y,this._targetEnd.y,this.restThreshold)&&Y(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(s)}zoom(t,e=!1){return this.zoomTo(this._zoomEnd+t,e)}zoomTo(t,e=!1){this._isUserControllingZoom=!1,this._zoomEnd=mt(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const s=!e||Y(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(s)}pan(t,e,s=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(t,e,s)}truck(t,e,s=!1){this._camera.updateMatrix(),yt.setFromMatrixColumn(this._camera.matrix,0),wt.setFromMatrixColumn(this._camera.matrix,1),yt.multiplyScalar(t),wt.multiplyScalar(-e);const i=R.copy(yt).add(wt),n=k.copy(this._targetEnd).add(i);return this.moveTo(n.x,n.y,n.z,s)}forward(t,e=!1){R.setFromMatrixColumn(this._camera.matrix,0),R.crossVectors(this._camera.up,R),R.multiplyScalar(t);const s=k.copy(this._targetEnd).add(R);return this.moveTo(s.x,s.y,s.z,e)}elevate(t,e=!1){return R.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+R.x,this._targetEnd.y+R.y,this._targetEnd.z+R.z,e)}moveTo(t,e,s,i=!1){this._isUserControllingTruck=!1;const n=R.set(t,e,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,n,this.boundaryFriction),this._needsUpdate=!0,i||this._target.copy(this._targetEnd);const o=!i||Y(this._target.x,this._targetEnd.x,this.restThreshold)&&Y(this._target.y,this._targetEnd.y,this.restThreshold)&&Y(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(o)}lookInDirectionOf(t,e,s,i=!1){const n=R.set(t,e,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius);return this.setPosition(n.x,n.y,n.z,i)}fitToBox(t,e,{cover:s=!1,paddingLeft:i=0,paddingRight:n=0,paddingBottom:o=0,paddingTop:a=0}={}){const h=[],l=t.isBox3?jt.copy(t):jt.setFromObject(t);l.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const c=xi(this._sphericalEnd.theta,wi),u=xi(this._sphericalEnd.phi,wi);h.push(this.rotateTo(c,u,e));const d=R.setFromSpherical(this._sphericalEnd).normalize(),p=Ci.setFromUnitVectors(d,vs),y=Y(Math.abs(d.y),1);y&&p.multiply(Es.setFromAxisAngle(Ke,c)),p.multiply(this._yAxisUpSpaceInverse);const g=Pi.makeEmpty();k.copy(l.min).applyQuaternion(p),g.expandByPoint(k),k.copy(l.min).setX(l.max.x).applyQuaternion(p),g.expandByPoint(k),k.copy(l.min).setY(l.max.y).applyQuaternion(p),g.expandByPoint(k),k.copy(l.max).setZ(l.min.z).applyQuaternion(p),g.expandByPoint(k),k.copy(l.min).setZ(l.max.z).applyQuaternion(p),g.expandByPoint(k),k.copy(l.max).setY(l.min.y).applyQuaternion(p),g.expandByPoint(k),k.copy(l.max).setX(l.min.x).applyQuaternion(p),g.expandByPoint(k),k.copy(l.max).applyQuaternion(p),g.expandByPoint(k),g.min.x-=i,g.min.y-=o,g.max.x+=n,g.max.y+=a,p.setFromUnitVectors(vs,d),y&&p.premultiply(Es.invert()),p.premultiply(this._yAxisUpSpace);const f=g.getSize(R),_=g.getCenter(k).applyQuaternion(p);if(Ut(this._camera)){const w=this.getDistanceToFitBox(f.x,f.y,f.z,s);h.push(this.moveTo(_.x,_.y,_.z,e)),h.push(this.dollyTo(w,e)),h.push(this.setFocalOffset(0,0,0,e))}else if(Mt(this._camera)){const w=this._camera,b=w.right-w.left,m=w.top-w.bottom,x=s?Math.max(b/f.x,m/f.y):Math.min(b/f.x,m/f.y);h.push(this.moveTo(_.x,_.y,_.z,e)),h.push(this.zoomTo(x,e)),h.push(this.setFocalOffset(0,0,0,e))}return Promise.all(h)}fitToSphere(t,e){const s=[],i=t instanceof L.Sphere?bs.copy(t):Pe.createBoundingSphere(t,bs);if(s.push(this.moveTo(i.center.x,i.center.y,i.center.z,e)),Ut(this._camera)){const n=this.getDistanceToFitSphere(i.radius);s.push(this.dollyTo(n,e))}else if(Mt(this._camera)){const n=this._camera.right-this._camera.left,o=this._camera.top-this._camera.bottom,a=2*i.radius,h=Math.min(n/a,o/a);s.push(this.zoomTo(h,e))}return s.push(this.setFocalOffset(0,0,0,e)),Promise.all(s)}setLookAt(t,e,s,i,n,o,a=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Qt.NONE,this._changedDolly=0;const h=k.set(i,n,o),l=R.set(t,e,s);this._targetEnd.copy(h),this._sphericalEnd.setFromVector3(l.sub(h).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,a||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const c=!a||Y(this._target.x,this._targetEnd.x,this.restThreshold)&&Y(this._target.y,this._targetEnd.y,this.restThreshold)&&Y(this._target.z,this._targetEnd.z,this.restThreshold)&&Y(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Y(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&Y(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(c)}lerpLookAt(t,e,s,i,n,o,a,h,l,c,u,d,p,y=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Qt.NONE,this._changedDolly=0;const g=R.set(i,n,o),f=k.set(t,e,s);ht.setFromVector3(f.sub(g).applyQuaternion(this._yAxisUpSpace));const _=Kt.set(c,u,d),w=k.set(a,h,l);pe.setFromVector3(w.sub(_).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(g.lerp(_,p));const b=pe.theta-ht.theta,m=pe.phi-ht.phi,x=pe.radius-ht.radius;this._sphericalEnd.set(ht.radius+x*p,ht.phi+m*p,ht.theta+b*p),this.normalizeRotations(),this._needsUpdate=!0,y||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const P=!y||Y(this._target.x,this._targetEnd.x,this.restThreshold)&&Y(this._target.y,this._targetEnd.y,this.restThreshold)&&Y(this._target.z,this._targetEnd.z,this.restThreshold)&&Y(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Y(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&Y(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(P)}setPosition(t,e,s,i=!1){return this.setLookAt(t,e,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,i)}setTarget(t,e,s,i=!1){const n=this.getPosition(R),o=this.setLookAt(n.x,n.y,n.z,t,e,s,i);return this._sphericalEnd.phi=mt(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),o}setFocalOffset(t,e,s,i=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,s),this._needsUpdate=!0,i||this._focalOffset.copy(this._focalOffsetEnd);const n=!i||Y(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&Y(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&Y(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}setOrbitPoint(t,e,s){this._camera.updateMatrixWorld(),yt.setFromMatrixColumn(this._camera.matrixWorldInverse,0),wt.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Bt.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const i=R.set(t,e,s),n=i.distanceTo(this._camera.position),o=i.sub(this._camera.position);yt.multiplyScalar(o.x),wt.multiplyScalar(o.y),Bt.multiplyScalar(o.z),R.copy(yt).add(wt).add(Bt),R.z=R.z+n,this.dollyTo(n,!1),this.setFocalOffset(-R.x,R.y,-R.z,!1),this.moveTo(t,e,s,!1)}setBoundary(t){if(!t){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(t),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(t,e,s,i){if(t===null){this._viewport=null;return}this._viewport=this._viewport||new L.Vector4,typeof t=="number"?this._viewport.set(t,e,s,i):this._viewport.copy(t)}getDistanceToFitBox(t,e,s,i=!1){if(xs(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const n=t/e,o=this._camera.getEffectiveFOV()*le,a=this._camera.aspect;return((i?n>a:ne.pointerId===t)}_findPointerByMouseButton(t){return this._activePointers.find(e=>e.mouseButton===t)}_disposePointer(t){this._activePointers.splice(this._activePointers.indexOf(t),1)}_encloseToBoundary(t,e,s){const i=e.lengthSq();if(i===0)return t;const n=k.copy(e).add(t),o=this._boundary.clampPoint(n,Kt).sub(n),a=o.lengthSq();if(a===0)return t.add(e);if(a===i)return t;if(s===0)return t.add(e).add(o);{const h=1+s*a/e.dot(o);return t.add(k.copy(e).multiplyScalar(h)).add(o.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(Ut(this._camera)){const t=this._camera,e=t.near,s=t.getEffectiveFOV()*le,i=Math.tan(s*.5)*e,n=i*t.aspect;this._nearPlaneCorners[0].set(-n,-i,0),this._nearPlaneCorners[1].set(n,-i,0),this._nearPlaneCorners[2].set(n,i,0),this._nearPlaneCorners[3].set(-n,i,0)}else if(Mt(this._camera)){const t=this._camera,e=1/t.zoom,s=t.left*e,i=t.right*e,n=t.top*e,o=t.bottom*e;this._nearPlaneCorners[0].set(s,n,0),this._nearPlaneCorners[1].set(i,n,0),this._nearPlaneCorners[2].set(i,o,0),this._nearPlaneCorners[3].set(s,o,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1)||xs(this._camera,"_collisionTest"))return t;const e=this._getTargetDirection(ue);Ts.lookAt(bi,e,this._camera.up);for(let s=0;s<4;s++){const i=k.copy(this._nearPlaneCorners[s]);i.applyMatrix4(Ts);const n=Kt.addVectors(this._target,i);je.set(n,e),je.far=this._spherical.radius+1;const o=je.intersectObjects(this.colliderMeshes);o.length!==0&&o[0].distance{const s=()=>{this.removeEventListener("rest",s),e()};this.addEventListener("rest",s)}))}_addAllEventListeners(t){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(t){console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead.")}get draggingDampingFactor(){return console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead."),0}set draggingDampingFactor(t){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(t,e=new L.Sphere){const s=e,i=s.center;jt.makeEmpty(),t.traverseVisible(o=>{o.isMesh&&jt.expandByObject(o)}),jt.getCenter(i);let n=0;return t.traverseVisible(o=>{if(!o.isMesh)return;const a=o,h=a.geometry.clone();h.applyMatrix4(a.matrixWorld);const l=h.attributes.position;for(let c=0,u=l.count;c{var e;if(!(!this.currentWorld||!this.currentWorld.renderer)&&(e=this.currentWorld.renderer)!=null&&e.isResizeable()){const s=this.currentWorld.renderer.getSize();this.three.aspect=s.width/s.height,this.three.updateProjectionMatrix(),this.onAspectUpdated.trigger()}}),this.three=this.setupCamera(),this.setupEvents(!0),this.onWorldChanged.add(({action:e,world:s})=>{if(e==="added"){const i=this.newCameraControls();this._allControls.set(s.uuid,i)}if(e==="removed"){const i=this._allControls.get(s.uuid);i&&(i.dispose(),this._allControls.delete(s.uuid))}})}get controls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");const t=this._allControls.get(this.currentWorld.uuid);if(!t)throw new Error("Controls not found!");return t}get enabled(){return this.currentWorld===null?!1:this.controls.enabled}set enabled(t){this.controls.enabled=t}dispose(){this.setupEvents(!1),this.enabled=!1,this.onAspectUpdated.reset(),this.onBeforeUpdate.reset(),this.onAfterUpdate.reset(),this.three.removeFromParent(),this.onDisposed.trigger(),this.onDisposed.reset();for(const[t,e]of this._allControls)e.dispose()}update(t){this.enabled&&(this.onBeforeUpdate.trigger(this),this.controls.update(t),this.onAfterUpdate.trigger(this))}setupCamera(){const t=window.innerWidth/window.innerHeight,e=new cn(60,t,1,1e3);return e.position.set(50,50,50),e.lookAt(new O(0,0,0)),e}newCameraControls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");if(!this.currentWorld.renderer)throw new Error("This camera needs a renderer to work!");Pe.install({THREE:Ce.getSubsetOfThree()});const{domElement:t}=this.currentWorld.renderer.three,e=new Pe(this.three,t);return e.smoothTime=.2,e.dollyToCursor=!0,e.infinityDolly=!0,e}setupEvents(t){t?window.addEventListener("resize",this.updateAspect):window.removeEventListener("resize",this.updateAspect)}static getSubsetOfThree(){return{MOUSE:dn,Vector2:_t,Vector3:O,Vector4:un,Quaternion:ft,Matrix4:et,Spherical:pn,Box3:ot,Sphere:ki,Raycaster:Ys,MathUtils:mn}}}const Ji=class tn extends St{constructor(t){super(t),v(this,"onAfterUpdate",new I),v(this,"onBeforeUpdate",new I),v(this,"onDisposed",new I),v(this,"list",new Map),v(this,"enabled",!0),t.add(tn.uuid,this)}create(){const t=new Fr(this.components),e=t.uuid;if(this.list.has(e))throw new Error("There is already a world with this name!");return this.list.set(e,t),t}delete(t){this.list.delete(t.uuid),t.dispose()}dispose(){this.enabled=!1;for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}update(t){if(this.enabled)for(const[e,s]of this.list)s.update(t)}};v(Ji,"uuid","fdb61dc4-2ec1-4966-b83d-54ea795fad4a");let en=Ji;class Vr{constructor(t,e,s){v(this,"onDisposed",new I),v(this,"world"),v(this,"components"),v(this,"_grid"),v(this,"_fade",3),v(this,"updateZoom",()=>{this.world.camera instanceof Ce&&(this.material.uniforms.uZoom.value=this.world.camera.three.zoom)}),this.world=e;const{color:i,size1:n,size2:o,distance:a}=s;this.components=t;const h=new Vs(2,2,1,1),l=new _n({side:Me,uniforms:{uSize1:{value:n},uSize2:{value:o},uColor:{value:i},uDistance:{value:a},uFade:{value:this._fade},uZoom:{value:1}},transparent:!0,vertexShader:` + + varying vec3 worldPosition; + + uniform float uDistance; + + void main() { + + vec3 pos = position.xzy * uDistance; + pos.xz += cameraPosition.xz; + + worldPosition = pos; + + gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0); + + } + `,fragmentShader:` + + varying vec3 worldPosition; + + uniform float uZoom; + uniform float uFade; + uniform float uSize1; + uniform float uSize2; + uniform vec3 uColor; + uniform float uDistance; + + + + float getGrid(float size) { + + vec2 r = worldPosition.xz / size; + + + vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r); + float line = min(grid.x, grid.y); + + + return 1.0 - min(line, 1.0); + } + + void main() { + + + float d = 1.0 - min(distance(cameraPosition.xz, worldPosition.xz) / uDistance, 1.0); + + float g1 = getGrid(uSize1); + float g2 = getGrid(uSize2); + + // Ortho camera fades the grid away when zooming out + float minZoom = step(0.2, uZoom); + float zoomFactor = pow(min(uZoom, 1.), 2.) * minZoom; + + gl_FragColor = vec4(uColor.rgb, mix(g2, g1, g1) * pow(d, uFade)); + gl_FragColor.a = mix(0.5 * gl_FragColor.a, gl_FragColor.a, g2) * zoomFactor; + + if ( gl_FragColor.a <= 0.0 ) discard; + + + } + + `,extensions:{derivatives:!0}});this._grid=new U(h,l),this._grid.frustumCulled=!1,e.scene.three.add(this._grid),this.setupEvents(!0)}get visible(){return this._grid.visible}set visible(t){t?this.world.scene.three.add(this._grid):this._grid.removeFromParent()}get material(){return this._grid.material}get fade(){return this._fade===3}set fade(t){this._fade=t?3:0,this.material.uniforms.uFade.value=this._fade}[Symbol.dispose](){throw new Error("Method not implemented.")}get(){return this._grid}dispose(){this.setupEvents(!1),this.components.get(Te).destroy(this._grid),this.onDisposed.trigger(),this.onDisposed.reset(),this.world=null,this.components=null}setupEvents(t){if(!(this.world.camera instanceof Ce))return;const e=this.world.camera.controls;t?e.addEventListener("update",this.updateZoom):e.removeEventListener("update",this.updateZoom)}}class sn extends St{constructor(){super(...arguments),v(this,"list",new Map),v(this,"onDisposed",new I),v(this,"config",{color:new we(12303291),size1:1,size2:10,distance:500}),v(this,"enabled",!0)}create(t){if(this.list.has(t.uuid))throw new Error("This world already has a grid!");const e=new Vr(this.components,t,this.config);this.list.set(t.uuid,e),t.onDisposed.add(()=>{this.delete(t)})}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,e]of this.list)e.dispose();this.list.clear(),this.onDisposed.trigger()}}v(sn,"uuid","d1e814d5-b81c-4452-87a2-f039375e0489");const Lt=new Ys,J=new O,Ct=new O,W=new ft,Mi={X:new O(1,0,0),Y:new O(0,1,0),Z:new O(0,0,1)},Ps={type:"change"},Oi={type:"mouseDown"},Ai={type:"mouseUp",mode:null},Di={type:"objectChange"};class Nr extends Ee{constructor(t,e){super(),e===void 0&&(console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.'),e=document),this.isTransformControls=!0,this.visible=!1,this.domElement=e,this.domElement.style.touchAction="none";const s=new jr;this._gizmo=s,this.add(s);const i=new Gr;this._plane=i,this.add(i);const n=this;function o(w,b){let m=b;Object.defineProperty(n,w,{get:function(){return m!==void 0?m:b},set:function(x){m!==x&&(m=x,i[w]=x,s[w]=x,n.dispatchEvent({type:w+"-changed",value:x}),n.dispatchEvent(Ps))}}),n[w]=b,i[w]=b,s[w]=b}o("camera",t),o("object",void 0),o("enabled",!0),o("axis",null),o("mode","translate"),o("translationSnap",null),o("rotationSnap",null),o("scaleSnap",null),o("space","world"),o("size",1),o("dragging",!1),o("showX",!0),o("showY",!0),o("showZ",!0);const a=new O,h=new O,l=new ft,c=new ft,u=new O,d=new ft,p=new O,y=new O,g=new O,f=0,_=new O;o("worldPosition",a),o("worldPositionStart",h),o("worldQuaternion",l),o("worldQuaternionStart",c),o("cameraPosition",u),o("cameraQuaternion",d),o("pointStart",p),o("pointEnd",y),o("rotationAxis",g),o("rotationAngle",f),o("eye",_),this._offset=new O,this._startNorm=new O,this._endNorm=new O,this._cameraScale=new O,this._parentPosition=new O,this._parentQuaternion=new ft,this._parentQuaternionInv=new ft,this._parentScale=new O,this._worldScaleStart=new O,this._worldQuaternionInv=new ft,this._worldScale=new O,this._positionStart=new O,this._quaternionStart=new ft,this._scaleStart=new O,this._getPointer=Xr.bind(this),this._onPointerDown=Qr.bind(this),this._onPointerHover=Wr.bind(this),this._onPointerMove=qr.bind(this),this._onPointerUp=Kr.bind(this),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp)}updateMatrixWorld(){this.object!==void 0&&(this.object.updateMatrixWorld(),this.object.parent===null?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):this.object.parent.matrixWorld.decompose(this._parentPosition,this._parentQuaternion,this._parentScale),this.object.matrixWorld.decompose(this.worldPosition,this.worldQuaternion,this._worldScale),this._parentQuaternionInv.copy(this._parentQuaternion).invert(),this._worldQuaternionInv.copy(this.worldQuaternion).invert()),this.camera.updateMatrixWorld(),this.camera.matrixWorld.decompose(this.cameraPosition,this.cameraQuaternion,this._cameraScale),this.camera.isOrthographicCamera?this.camera.getWorldDirection(this.eye).negate():this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize(),super.updateMatrixWorld(this)}pointerHover(t){if(this.object===void 0||this.dragging===!0)return;Lt.setFromCamera(t,this.camera);const e=Cs(this._gizmo.picker[this.mode],Lt);e?this.axis=e.object.name:this.axis=null}pointerDown(t){if(!(this.object===void 0||this.dragging===!0||t.button!==0)&&this.axis!==null){Lt.setFromCamera(t,this.camera);const e=Cs(this._plane,Lt,!0);e&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(e.point).sub(this.worldPositionStart)),this.dragging=!0,Oi.mode=this.mode,this.dispatchEvent(Oi)}}pointerMove(t){const e=this.axis,s=this.mode,i=this.object;let n=this.space;if(s==="scale"?n="local":(e==="E"||e==="XYZE"||e==="XYZ")&&(n="world"),i===void 0||e===null||this.dragging===!1||t.button!==-1)return;Lt.setFromCamera(t,this.camera);const o=Cs(this._plane,Lt,!0);if(o){if(this.pointEnd.copy(o.point).sub(this.worldPositionStart),s==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),n==="local"&&e!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),e.indexOf("X")===-1&&(this._offset.x=0),e.indexOf("Y")===-1&&(this._offset.y=0),e.indexOf("Z")===-1&&(this._offset.z=0),n==="local"&&e!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),i.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(n==="local"&&(i.position.applyQuaternion(W.copy(this._quaternionStart).invert()),e.search("X")!==-1&&(i.position.x=Math.round(i.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(i.position.y=Math.round(i.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(i.position.z=Math.round(i.position.z/this.translationSnap)*this.translationSnap),i.position.applyQuaternion(this._quaternionStart)),n==="world"&&(i.parent&&i.position.add(J.setFromMatrixPosition(i.parent.matrixWorld)),e.search("X")!==-1&&(i.position.x=Math.round(i.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(i.position.y=Math.round(i.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(i.position.z=Math.round(i.position.z/this.translationSnap)*this.translationSnap),i.parent&&i.position.sub(J.setFromMatrixPosition(i.parent.matrixWorld))));else if(s==="scale"){if(e.search("XYZ")!==-1){let a=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(a*=-1),Ct.set(a,a,a)}else J.copy(this.pointStart),Ct.copy(this.pointEnd),J.applyQuaternion(this._worldQuaternionInv),Ct.applyQuaternion(this._worldQuaternionInv),Ct.divide(J),e.search("X")===-1&&(Ct.x=1),e.search("Y")===-1&&(Ct.y=1),e.search("Z")===-1&&(Ct.z=1);i.scale.copy(this._scaleStart).multiply(Ct),this.scaleSnap&&(e.search("X")!==-1&&(i.scale.x=Math.round(i.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Y")!==-1&&(i.scale.y=Math.round(i.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Z")!==-1&&(i.scale.z=Math.round(i.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(s==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const a=20/this.worldPosition.distanceTo(J.setFromMatrixPosition(this.camera.matrixWorld));let h=!1;e==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(J.copy(this.rotationAxis).cross(this.eye))*a):(e==="X"||e==="Y"||e==="Z")&&(this.rotationAxis.copy(Mi[e]),J.copy(Mi[e]),n==="local"&&J.applyQuaternion(this.worldQuaternion),J.cross(this.eye),J.length()===0?h=!0:this.rotationAngle=this._offset.dot(J.normalize())*a),(e==="E"||h)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),n==="local"&&e!=="E"&&e!=="XYZE"?(i.quaternion.copy(this._quaternionStart),i.quaternion.multiply(W.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),i.quaternion.copy(W.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),i.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(Ps),this.dispatchEvent(Di)}}pointerUp(t){t.button===0&&(this.dragging&&this.axis!==null&&(Ai.mode=this.mode,this.dispatchEvent(Ai)),this.dragging=!1,this.axis=null)}dispose(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.traverse(function(t){t.geometry&&t.geometry.dispose(),t.material&&t.material.dispose()})}attach(t){return this.object=t,this.visible=!0,this}detach(){return this.object=void 0,this.visible=!1,this.axis=null,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(Ps),this.dispatchEvent(Di),this.pointStart.copy(this.pointEnd))}getRaycaster(){return Lt}getMode(){return this.mode}setMode(t){this.mode=t}setTranslationSnap(t){this.translationSnap=t}setRotationSnap(t){this.rotationSnap=t}setScaleSnap(t){this.scaleSnap=t}setSize(t){this.size=t}setSpace(t){this.space=t}}function Xr(r){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:r.button};{const t=this.domElement.getBoundingClientRect();return{x:(r.clientX-t.left)/t.width*2-1,y:-(r.clientY-t.top)/t.height*2+1,button:r.button}}}function Wr(r){if(this.enabled)switch(r.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(r));break}}function Qr(r){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(r.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(r)),this.pointerDown(this._getPointer(r)))}function qr(r){this.enabled&&this.pointerMove(this._getPointer(r))}function Kr(r){this.enabled&&(this.domElement.releasePointerCapture(r.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(r)))}function Cs(r,t,e){const s=t.intersectObject(r,!0);for(let i=0;i.9&&(n.visible=!1)),this.axis==="Y"&&(W.setFromEuler(Ge.set(0,0,Math.PI/2)),n.quaternion.copy(e).multiply(W),Math.abs(V.copy(zt).applyQuaternion(e).dot(this.eye))>.9&&(n.visible=!1)),this.axis==="Z"&&(W.setFromEuler(Ge.set(0,Math.PI/2,0)),n.quaternion.copy(e).multiply(W),Math.abs(V.copy(ye).applyQuaternion(e).dot(this.eye))>.9&&(n.visible=!1)),this.axis==="XYZE"&&(W.setFromEuler(Ge.set(0,Math.PI/2,0)),V.copy(this.rotationAxis),n.quaternion.setFromRotationMatrix(Ui.lookAt(Si,V,zt)),n.quaternion.multiply(W),n.visible=this.dragging),this.axis==="E"&&(n.visible=!1)):n.name==="START"?(n.position.copy(this.worldPositionStart),n.visible=this.dragging):n.name==="END"?(n.position.copy(this.worldPosition),n.visible=this.dragging):n.name==="DELTA"?(n.position.copy(this.worldPositionStart),n.quaternion.copy(this.worldQuaternionStart),J.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),J.applyQuaternion(this.worldQuaternionStart.clone().invert()),n.scale.copy(J),n.visible=this.dragging):(n.quaternion.copy(e),this.dragging?n.position.copy(this.worldPositionStart):n.position.copy(this.worldPosition),this.axis&&(n.visible=this.axis.search(n.name)!==-1));continue}n.quaternion.copy(e),this.mode==="translate"||this.mode==="scale"?(n.name==="X"&&Math.abs(V.copy(ge).applyQuaternion(e).dot(this.eye))>.99&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="Y"&&Math.abs(V.copy(zt).applyQuaternion(e).dot(this.eye))>.99&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="Z"&&Math.abs(V.copy(ye).applyQuaternion(e).dot(this.eye))>.99&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="XY"&&Math.abs(V.copy(ye).applyQuaternion(e).dot(this.eye))<.2&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="YZ"&&Math.abs(V.copy(ge).applyQuaternion(e).dot(this.eye))<.2&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="XZ"&&Math.abs(V.copy(zt).applyQuaternion(e).dot(this.eye))<.2&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1)):this.mode==="rotate"&&($e.copy(e),V.copy(this.eye).applyQuaternion(W.copy(e).invert()),n.name.search("E")!==-1&&n.quaternion.setFromRotationMatrix(Ui.lookAt(this.eye,Si,zt)),n.name==="X"&&(W.setFromAxisAngle(ge,Math.atan2(-V.y,V.z)),W.multiplyQuaternions($e,W),n.quaternion.copy(W)),n.name==="Y"&&(W.setFromAxisAngle(zt,Math.atan2(V.x,V.z)),W.multiplyQuaternions($e,W),n.quaternion.copy(W)),n.name==="Z"&&(W.setFromAxisAngle(ye,Math.atan2(V.y,V.x)),W.multiplyQuaternions($e,W),n.quaternion.copy(W))),n.visible=n.visible&&(n.name.indexOf("X")===-1||this.showX),n.visible=n.visible&&(n.name.indexOf("Y")===-1||this.showY),n.visible=n.visible&&(n.name.indexOf("Z")===-1||this.showZ),n.visible=n.visible&&(n.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),n.material._color=n.material._color||n.material.color.clone(),n.material._opacity=n.material._opacity||n.material.opacity,n.material.color.copy(n.material._color),n.material.opacity=n.material._opacity,this.enabled&&this.axis&&(n.name===this.axis||this.axis.split("").some(function(a){return n.name===a}))&&(n.material.color.setHex(16776960),n.material.opacity=1)}super.updateMatrixWorld(t)}}class Gr extends U{constructor(){super(new Vs(1e5,1e5,2,2),new Jt({visible:!1,wireframe:!0,side:Me,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(t){let e=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(e="local"),Je.copy(ge).applyQuaternion(e==="local"?this.worldQuaternion:es),me.copy(zt).applyQuaternion(e==="local"?this.worldQuaternion:es),fe.copy(ye).applyQuaternion(e==="local"?this.worldQuaternion:es),V.copy(me),this.mode){case"translate":case"scale":switch(this.axis){case"X":V.copy(this.eye).cross(Je),xt.copy(Je).cross(V);break;case"Y":V.copy(this.eye).cross(me),xt.copy(me).cross(V);break;case"Z":V.copy(this.eye).cross(fe),xt.copy(fe).cross(V);break;case"XY":xt.copy(fe);break;case"YZ":xt.copy(Je);break;case"XZ":V.copy(fe),xt.copy(me);break;case"XYZ":case"E":xt.set(0,0,0);break}break;case"rotate":default:xt.set(0,0,0)}xt.length()===0?this.quaternion.copy(this.cameraQuaternion):(Bi.lookAt(J.set(0,0,0),xt,V),this.quaternion.setFromRotationMatrix(Bi)),super.updateMatrixWorld(t)}}class Ks{constructor(t,e,s,i,n,o=5,a=!0){if(v(this,"onDraggingStarted",new I),v(this,"onDraggingEnded",new I),v(this,"onDisposed",new I),v(this,"normal"),v(this,"origin"),v(this,"three",new Zs),v(this,"_helper"),v(this,"_visible",!0),v(this,"_enabled",!0),v(this,"components"),v(this,"world"),v(this,"_controlsActive",!1),v(this,"_arrowBoundBox",new U),v(this,"_planeMesh"),v(this,"_controls"),v(this,"_hiddenMaterial",new Jt({visible:!1})),v(this,"update",async()=>{this._enabled&&this.three.setFromNormalAndCoplanarPoint(this.normal,this._helper.position)}),v(this,"changeDrag",h=>{this._visible=!h.value,this.preventCameraMovement(),this.notifyDraggingChanged(h)}),this.components=t,this.world=e,!e.renderer)throw new Error("The given world must have a renderer!");this.normal=i,this.origin=s,e.renderer.setPlane(!0,this.three),this._planeMesh=Ks.newPlaneMesh(o,n),this._helper=this.newHelper(),this._controls=this.newTransformControls(),this.three.setFromNormalAndCoplanarPoint(i,s),a&&this.toggleControls(!0)}get enabled(){return this._enabled}set enabled(t){if(!this.world.renderer)throw new Error("No renderer found for clipping plane!");this._enabled=t,this.world.renderer.setPlane(t,this.three)}get visible(){return this._visible}set visible(t){this._visible=t,this._controls.visible=t,this._helper.visible=t,this.toggleControls(t)}get meshes(){return[this._planeMesh,this._arrowBoundBox]}get planeMaterial(){return this._planeMesh.material}set planeMaterial(t){this._planeMesh.material=t}get size(){return this._planeMesh.scale.x}set size(t){this._planeMesh.scale.set(t,t,t)}get helper(){return this._helper}async setFromNormalAndCoplanarPoint(t,e){this.reset(),this.normal.equals(t)||(this.normal.copy(t),this._helper.lookAt(t)),this.origin.copy(e),this._helper.position.copy(e),this._helper.updateMatrix(),await this.update()}dispose(){this._enabled=!1,this.onDraggingStarted.reset(),this.onDraggingEnded.reset(),this._helper.removeFromParent(),this.world.renderer&&this.world.renderer.setPlane(!1,this.three),this._arrowBoundBox.removeFromParent(),this._arrowBoundBox.geometry.dispose(),this._planeMesh.geometry.dispose(),this._controls.removeFromParent(),this._controls.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}reset(){const t=new O(1,0,0),e=new O;this.normal.equals(t)||(this.normal.copy(t),this._helper.lookAt(t)),this.origin.copy(e),this._helper.position.copy(e),this._helper.updateMatrix()}toggleControls(t){if(t){if(this._controlsActive)return;this._controls.addEventListener("change",this.update),this._controls.addEventListener("dragging-changed",this.changeDrag)}else this._controls.removeEventListener("change",this.update),this._controls.removeEventListener("dragging-changed",this.changeDrag);this._controlsActive=t}newTransformControls(){if(!this.world.renderer)throw new Error("No renderer found for clipping plane!");const t=this.world.camera.three,e=this.world.renderer.three.domElement,s=new Nr(t,e);return this.initializeControls(s),this.world.scene.three.add(s),s}initializeControls(t){t.attach(this._helper),t.showX=!1,t.showY=!1,t.setSpace("local"),this.createArrowBoundingBox(),t.children[0].children[0].add(this._arrowBoundBox)}createArrowBoundingBox(){this._arrowBoundBox.geometry=new tt(.18,.18,1.2),this._arrowBoundBox.material=this._hiddenMaterial,this._arrowBoundBox.rotateX(Math.PI/2),this._arrowBoundBox.updateMatrix(),this._arrowBoundBox.geometry.applyMatrix4(this._arrowBoundBox.matrix)}notifyDraggingChanged(t){t.value?this.onDraggingStarted.trigger():this.onDraggingEnded.trigger()}preventCameraMovement(){this.world.camera.enabled=this._visible}newHelper(){const t=new Ee;return t.lookAt(this.normal),t.position.copy(this.origin),this._planeMesh.position.z+=.01,t.add(this._planeMesh),this.world.scene.three.add(t),t}static newPlaneMesh(t,e){const s=new Vs(1),i=new U(s,e);return i.scale.set(t,t,t),i}}const $r=class Is extends St{constructor(t){super(t),v(this,"onAfterCreate",new I),v(this,"onAfterDelete",new I),v(this,"onBeforeDrag",new I),v(this,"onAfterDrag",new I),v(this,"onBeforeCreate",new I),v(this,"onBeforeCancel",new I),v(this,"onAfterCancel",new I),v(this,"onBeforeDelete",new I),v(this,"onDisposed",new I),v(this,"orthogonalY",!1),v(this,"toleranceOrthogonalY",.7),v(this,"planes",[]),v(this,"PlaneType"),v(this,"_material",new Jt({color:16776960,side:Me,transparent:!0,opacity:.2})),v(this,"_size",5),v(this,"_enabled",!1),v(this,"_visible",!1),v(this,"_onStartDragging",()=>{this.onBeforeDrag.trigger()}),v(this,"_onEndDragging",()=>{this.onAfterDrag.trigger()}),this.components.add(Is.uuid,this),this.PlaneType=Ks}get enabled(){return this._enabled}set enabled(t){this._enabled=t;for(const e of this.planes)e.enabled=t;this.updateMaterialsAndPlanes()}get visible(){return this._visible}set visible(t){this._visible=t;for(const e of this.planes)e.visible=t}get material(){return this._material}set material(t){this._material=t;for(const e of this.planes)e.planeMaterial=t}get size(){return this._size}set size(t){this._size=t;for(const e of this.planes)e.size=t}endCreation(){}cancelCreation(){}dispose(){this._enabled=!1;for(const t of this.planes)t.dispose();this.planes.length=0,this._material.dispose(),this.onBeforeCreate.reset(),this.onBeforeCancel.reset(),this.onBeforeDelete.reset(),this.onBeforeDrag.reset(),this.onAfterCreate.reset(),this.onAfterCancel.reset(),this.onAfterDelete.reset(),this.onAfterDrag.reset(),this.onDisposed.trigger(Is.uuid),this.onDisposed.reset()}create(t){if(!this.enabled)return;const e=this.components.get(yi).get(t).castRay();e&&this.createPlaneFromIntersection(t,e)}createFromNormalAndCoplanarPoint(t,e,s){const i=this.newPlane(t,s,e);return this.updateMaterialsAndPlanes(),i}delete(t,e){this.enabled&&(e||(e=this.pickPlane(t)),e&&this.deletePlane(e))}deleteAll(){for(;this.planes.length>0;){const t=this.planes[0];this.delete(t.world,t)}}deletePlane(t){const e=this.planes.indexOf(t);if(e!==-1){if(this.planes.splice(e,1),!t.world.renderer)throw new Error("Renderer not found for this plane's world!");t.world.renderer.setPlane(!1,t.three),t.dispose(),this.updateMaterialsAndPlanes(),this.onAfterDelete.trigger(t)}}pickPlane(t){const e=this.components.get(yi).get(t),s=this.getAllPlaneMeshes(),i=e.castRay(s);if(i){const n=i.object;return this.planes.find(o=>o.meshes.includes(n))}}getAllPlaneMeshes(){const t=[];for(const e of this.planes)t.push(...e.meshes);return t}createPlaneFromIntersection(t,e){var s;if(!t.renderer)throw new Error("The given world must have a renderer!");const i=e.point.distanceTo(new O(0,0,0)),n=(s=e.face)==null?void 0:s.normal;if(!i||!n)return;const o=this.getWorldNormal(e,n),a=this.newPlane(t,e.point,o.negate());t.renderer.setPlane(!0,a.three),this.updateMaterialsAndPlanes()}getWorldNormal(t,e){const s=t.object;let i=t.object.matrixWorld.clone();if(s instanceof be&&t.instanceId!==void 0){const a=new et;s.getMatrixAt(t.instanceId,a),i=a.multiply(i)}const n=new gn().getNormalMatrix(i),o=e.clone().applyMatrix3(n).normalize();return this.normalizePlaneDirectionY(o),o}normalizePlaneDirectionY(t){this.orthogonalY&&(t.y>this.toleranceOrthogonalY&&(t.x=0,t.y=1,t.z=0),t.y<-this.toleranceOrthogonalY&&(t.x=0,t.y=-1,t.z=0))}newPlane(t,e,s){const i=this.newPlaneInstance(t,e,s);return i.onDraggingStarted.add(this._onStartDragging),i.onDraggingEnded.add(this._onEndDragging),this.planes.push(i),this.onAfterCreate.trigger(i),i}newPlaneInstance(t,e,s){return new this.PlaneType(this.components,t,e,s,this._material)}updateMaterialsAndPlanes(){const t=this.components.get(en);for(const[e,s]of t.list){if(!s.renderer)continue;s.renderer.updateClippingPlanes();const{clippingPlanes:i}=s.renderer;for(const n of s.meshes)if(Array.isArray(n.material))for(const o of n.material)o.clippingPlanes=i;else n.material.clippingPlanes=i}}};v($r,"uuid","66290bc5-18c4-4cd1-9379-2e17a0617611");const Jr=class Rs extends St{constructor(t){super(t),v(this,"enabled",!0),v(this,"_originalBackground",new Map),v(this,"onDisposed",new I),v(this,"list",{}),v(this,"_originals",{}),this.components.add(Rs.uuid,this)}set(t,e=Object.keys(this.list)){for(const s of e){const{material:i,meshes:n}=this.list[s];for(const o of n)if(t)this._originals[o.uuid]||(this._originals[o.uuid]={material:o.material}),o instanceof be&&o.instanceColor&&(this._originals[o.uuid].instances=o.instanceColor,o.instanceColor=null),o.material=i;else{if(!this._originals[o.uuid])continue;o.material=this._originals[o.uuid].material;const a=this._originals[o.uuid].instances;o instanceof be&&a&&(o.instanceColor=a)}}}dispose(){for(const t in this.list){const{material:e}=this.list[t];e.dispose()}this.list={},this._originals={},this.onDisposed.trigger(Rs.uuid),this.onDisposed.reset(),this._originalBackground.clear()}setBackgroundColor(t,e){const s=e.scene.three;s instanceof ve&&(this._originalBackground.has(e.uuid)||this._originalBackground.set(e.uuid,s.background),this._originalBackground&&(s.background=t))}resetBackgroundColor(t){const e=t.scene.three;if(!(e instanceof ve))return;const s=this._originalBackground.get(t.uuid);s&&(e.background=s)}addMaterial(t,e){if(this.list[t])throw new Error("This ID already exists!");this.list[t]={material:e,meshes:new Set}}addMeshes(t,e){if(!this.list[t])throw new Error("This ID doesn't exists!");for(const s of e)this.list[t].meshes.add(s)}removeMeshes(t,e){if(!this.list[t])throw new Error("This ID doesn't exists!");for(const s of e)this.list[t].meshes.delete(s)}};v(Jr,"uuid","24989d27-fa2f-4797-8b08-35918f74e502");function to(r,t,e,s){return new Promise((i,n)=>{function o(){const a=r.clientWaitSync(t,e,0);if(a===r.WAIT_FAILED){n();return}if(a===r.TIMEOUT_EXPIRED){setTimeout(o,s);return}i()}o()})}async function eo(r,t,e,s,i,n,o){const a=r.fenceSync(r.SYNC_GPU_COMMANDS_COMPLETE,0);r.flush(),await to(r,a,0,10),r.deleteSync(a),r.bindBuffer(t,e),r.getBufferSubData(t,s,i,n,o),r.bindBuffer(t,null)}async function so(r,t,e,s,i,n,o,a){const h=r.createBuffer();return r.bindBuffer(r.PIXEL_PACK_BUFFER,h),r.bufferData(r.PIXEL_PACK_BUFFER,a.byteLength,r.STREAM_READ),r.readPixels(t,e,s,i,n,o,0),r.bindBuffer(r.PIXEL_PACK_BUFFER,null),await eo(r,r.PIXEL_PACK_BUFFER,h,0,a),r.deleteBuffer(h),a}class io{constructor(t,e,s){if(v(this,"onDisposed",new I),v(this,"onViewUpdated",new I),v(this,"enabled",!0),v(this,"needsUpdate",!1),v(this,"renderDebugFrame",!1),v(this,"components"),v(this,"world"),v(this,"renderer"),v(this,"autoUpdate",!0),v(this,"updateInterval",1e3),v(this,"worker"),v(this,"scene",new ve),v(this,"_width",512),v(this,"_height",512),v(this,"_availableColor",1),v(this,"renderTarget"),v(this,"bufferSize"),v(this,"_buffer"),v(this,"updateVisibility",async o=>{if(!this.enabled||!this.needsUpdate&&!o)return;const a=this.world.camera.three;a.updateMatrix(),this.renderer.setSize(this._width,this._height),this.renderer.setRenderTarget(this.renderTarget),this.renderer.render(this.scene,a);const h=this.renderer.getContext();await so(h,0,0,this._width,this._height,h.RGBA,h.UNSIGNED_BYTE,this._buffer),this.renderer.setRenderTarget(null),this.renderDebugFrame&&this.renderer.render(this.scene,a),this.worker.postMessage({buffer:this._buffer}),this.needsUpdate=!1}),!e.renderer)throw new Error("The given world must have a renderer!");this.components=t,this.applySettings(s),this.world=e,this.renderer=new Ms,this.renderTarget=new vn(this._width,this._height),this.bufferSize=this._width*this._height*4,this._buffer=new Uint8Array(this.bufferSize),this.renderer.clippingPlanes=e.renderer.clippingPlanes;const i=` + addEventListener("message", (event) => { + const { buffer } = event.data; + const colors = new Map(); + for (let i = 0; i < buffer.length; i += 4) { + const r = buffer[i]; + const g = buffer[i + 1]; + const b = buffer[i + 2]; + const code = "" + r + "-" + g + "-" + b; + if(colors.has(code)) { + colors.set(code, colors.get(code) + 1); + } else { + colors.set(code, 1); + } + } + postMessage({ colors }); + }); + `,n=new Blob([i],{type:"application/javascript"});this.worker=new Worker(URL.createObjectURL(n))}dispose(){this.enabled=!1;for(const t of this.scene.children)t.removeFromParent();this.onViewUpdated.reset(),this.worker.terminate(),this.renderer.dispose(),this.renderTarget.dispose(),this._buffer=null,this.onDisposed.reset()}getAvailableColor(){let t=BigInt(this._availableColor.toString());const e=[];do e.unshift(Number(t%256n)),t/=256n;while(t);for(;e.length!==3;)e.unshift(0);const[s,i,n]=e,o=`${s}-${i}-${n}`;return{r:s,g:i,b:n,code:o}}increaseColor(){if(this._availableColor===256*256*256){console.warn("Color can't be increased over 256 x 256 x 256!");return}this._availableColor++}decreaseColor(){if(this._availableColor===1){console.warn("Color can't be decreased under 0!");return}this._availableColor--}applySettings(t){t&&(t.updateInterval!==void 0&&(this.updateInterval=t.updateInterval),t.height!==void 0&&(this._height=t.height),t.width!==void 0&&(this._width=t.width),t.autoUpdate!==void 0&&(this.autoUpdate=t.autoUpdate))}}class no extends io{constructor(t,e,s){super(t,e,s),v(this,"threshold",100),v(this,"onViewUpdated",new I),v(this,"colorMeshes",new Map),v(this,"isProcessing",!1),v(this,"_colorCodeMeshMap",new Map),v(this,"_meshIDColorCodeMap",new Map),v(this,"_currentVisibleMeshes",new Set),v(this,"_recentlyHiddenMeshes",new Set),v(this,"_transparentMat",new Jt({transparent:!0,opacity:0})),v(this,"handleWorkerMessage",async i=>{if(this.isProcessing)return;const n=i.data.colors;this._recentlyHiddenMeshes=new Set(this._currentVisibleMeshes),this._currentVisibleMeshes.clear();for(const[o,a]of n){if(a{this.isProcessing||await this.updateVisibility()},this.updateInterval),this.onViewUpdated.add(({seen:i,unseen:n})=>{for(const o of i)o.visible=!0;for(const o of n)o.visible=!1})}dispose(){super.dispose(),this._currentVisibleMeshes.clear(),this._recentlyHiddenMeshes.clear(),this._meshIDColorCodeMap.clear(),this._transparentMat.dispose(),this._colorCodeMeshMap.clear();const t=this.components.get(Te);for(const e in this.colorMeshes){const s=this.colorMeshes.get(e);s&&t.destroy(s,!0)}this.colorMeshes.clear()}add(t){if(!this.enabled)return;if(this.isProcessing){console.log("Culler processing not finished yet.");return}this.isProcessing=!0;const e=t instanceof be,{geometry:s,material:i}=t,{colorMaterial:n,code:o}=this.getAvailableMaterial();let a;if(Array.isArray(i)){let c=!0;const u=[];for(const d of i)gi.isTransparent(d)?u.push(this._transparentMat):(c=!1,u.push(n));if(c){n.dispose(),this.isProcessing=!1;return}a=u}else if(gi.isTransparent(i)){n.dispose(),this.isProcessing=!1;return}else a=n;this._colorCodeMeshMap.set(o,t),this._meshIDColorCodeMap.set(t.uuid,o);const h=e?t.count:1,l=new be(s,a,h);e?l.instanceMatrix=t.instanceMatrix:l.setMatrixAt(0,new et),t.visible=!1,l.applyMatrix4(t.matrix),l.updateMatrix(),this.scene.add(l),this.colorMeshes.set(t.uuid,l),this.increaseColor(),this.isProcessing=!1}remove(t){if(this.isProcessing){console.log("Culler processing not finished yet.");return}this.isProcessing=!0;const e=this.components.get(Te);this._currentVisibleMeshes.delete(t),this._recentlyHiddenMeshes.delete(t);const s=this.colorMeshes.get(t.uuid),i=this._meshIDColorCodeMap.get(t.uuid);if(!s||!i){this.isProcessing=!1,console.log(t.visible);return}this._colorCodeMeshMap.delete(i),this._meshIDColorCodeMap.delete(t.uuid),this.colorMeshes.delete(t.uuid),s.geometry=void 0,s.material=[],e.destroy(s,!0),this._recentlyHiddenMeshes.delete(t),this._currentVisibleMeshes.delete(t),this.isProcessing=!1}getAvailableMaterial(){const{r:t,g:e,b:s,code:i}=this.getAvailableColor(),n=as.enabled;as.enabled=!1;const o=new we(`rgb(${t}, ${e}, ${s})`);if(!this.world.renderer)throw new Error("Renderer not found in the world!");const a=this.world.renderer.clippingPlanes,h=new Jt({color:o,clippingPlanes:a,side:Me});return as.enabled=n,{colorMaterial:h,code:i}}}const ro=class ks extends St{constructor(t){super(t),v(this,"_enabled",!0),v(this,"list",new Map),v(this,"onDisposed",new I),t.add(ks.uuid,this)}get enabled(){return this._enabled}set enabled(t){this._enabled=t;for(const[e,s]of this.list)s.enabled=t}create(t,e){if(this.list.has(t.uuid))return this.list.get(t.uuid);const s=new no(this.components,t,e);return this.list.set(t.uuid,s),s}remove(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){this.enabled=!1,this.onDisposed.trigger(ks.uuid),this.onDisposed.reset();for(const[t,e]of this.list)e.dispose();this.list.clear()}};v(ro,"uuid","69f2a50d-c266-44fc-b1bd-fa4d34be89e6");class oo extends Ee{constructor(t=document.createElement("div")){super(),this.isCSS2DObject=!0,this.element=t,this.element.style.position="absolute",this.element.style.userSelect="none",this.element.setAttribute("draggable",!1),this.center=new _t(.5,.5),this.addEventListener("removed",function(){this.traverse(function(e){e.element instanceof Element&&e.element.parentNode!==null&&e.element.parentNode.removeChild(e.element)})})}copy(t,e){return super.copy(t,e),this.element=t.element.cloneNode(!0),this.center=t.center,this}}const Gt=new O,Li=new et,zi=new et,Fi=new O,Ii=new O;class ao{constructor(t={}){const e=this;let s,i,n,o;const a={objects:new WeakMap},h=t.element!==void 0?t.element:document.createElement("div");h.style.overflow="hidden",this.domElement=h,this.getSize=function(){return{width:s,height:i}},this.render=function(p,y){p.matrixWorldAutoUpdate===!0&&p.updateMatrixWorld(),y.parent===null&&y.matrixWorldAutoUpdate===!0&&y.updateMatrixWorld(),Li.copy(y.matrixWorldInverse),zi.multiplyMatrices(y.projectionMatrix,Li),l(p,p,y),d(p)},this.setSize=function(p,y){s=p,i=y,n=s/2,o=i/2,h.style.width=p+"px",h.style.height=y+"px"};function l(p,y,g){if(p.isCSS2DObject){Gt.setFromMatrixPosition(p.matrixWorld),Gt.applyMatrix4(zi);const f=p.visible===!0&&Gt.z>=-1&&Gt.z<=1&&p.layers.test(g.layers)===!0;if(p.element.style.display=f===!0?"":"none",f===!0){p.onBeforeRender(e,y,g);const w=p.element;w.style.transform="translate("+-100*p.center.x+"%,"+-100*p.center.y+"%)translate("+(Gt.x*n+n)+"px,"+(-Gt.y*o+o)+"px)",w.parentNode!==h&&h.appendChild(w),p.onAfterRender(e,y,g)}const _={distanceToCameraSquared:c(g,p)};a.objects.set(p,_)}for(let f=0,_=p.children.length;f<_;f++)l(p.children[f],y,g)}function c(p,y){return Fi.setFromMatrixPosition(p.matrixWorld),Ii.setFromMatrixPosition(y.matrixWorld),Fi.distanceToSquared(Ii)}function u(p){const y=[];return p.traverse(function(g){g.isCSS2DObject&&y.push(g)}),y}function d(p){const y=u(p).sort(function(f,_){if(f.renderOrder!==_.renderOrder)return _.renderOrder-f.renderOrder;const w=a.objects.get(f).distanceToCameraSquared,b=a.objects.get(_).distanceToCameraSquared;return w-b}),g=y.length;for(let f=0,_=y.length;f<_;f++)y[f].element.style.zIndex=g-f}}}class ho extends Rr{constructor(e,s,i){super(e,s,i);G(this,"three2D",new ao);this.onAfterUpdate.add(()=>{if(this.onBeforeUpdate.trigger(this),!this.enabled||!this.currentWorld)return;const n=this.currentWorld.scene.three,o=this.currentWorld.camera.three;n instanceof ve&&this.three2D.render(n,o)}),this.onDisposed.add(()=>{this.three2D.domElement.remove()}),this.onResize.add(({x:n,y:o})=>{this.three2D.setSize(n,o)}),this.onContainerUpdated.add(n=>{n.appendChild(this.three2D.domElement)}),this.setupHtmlRenderer(),this.resize()}setupHtmlRenderer(){this.three2D.domElement.style.position="absolute",this.three2D.domElement.style.top="0px",this.three2D.domElement.style.pointerEvents="none",this.container&&this.container.appendChild(this.three2D.domElement)}}class Ri{constructor(t,e,s){G(this,"three");G(this,"world");G(this,"onDisposed",new I);this.world=t;let i;e?i=e:(i=document.createElement("div"),i.className="w-[15px] h-[15px] border-3 border-solid border-red-600"),this.three=new oo(i);const n=s||t.scene.three;n.add(this.three),console.log(n),this.visible=!0}set visible(t){this.three.visible=t}get visible(){return this.three.visible}toggleVisibility(){this.visible=!this.visible}dispose(){this.three.removeFromParent(),this.three.element.remove(),this.onDisposed.trigger(),this.onDisposed.reset()}}const ns=class ns extends St{constructor(e){super(e);G(this,"enabled",!0);G(this,"clusterOnZoom",!0);G(this,"clusterThreshold",50);G(this,"list",new Set);G(this,"clusterLabels",new Set);G(this,"currentKeys",new Set);G(this,"_color","white");G(this,"_markerKey",0);G(this,"_clusterKey",0);G(this,"isNavigating",!1);G(this,"_setupWorlds",new Set);e.add(ns.uuid,this)}get color(){return this._color}set color(e){this._color=e;for(const s of this.list)s.label.three.element.style.color=e}create(e,s,i){this.setupEvents(e,!0);const n=document.createElement("span");n.innerHTML=s,n.style.color=this._color;const o=new Ri(e,n);o.three.position.copy(i),this.list.add({label:o,key:this._markerKey.toString(),merged:!1,static:!1}),this._markerKey++}clear(e){const s=[...this.list];for(const i of s)e&&i.type!==e||(i.label.dispose(),this.list.delete(i));this.list.clear(),this._markerKey=0}dispose(){for(const e of this.list)e.label.dispose();this.list.clear(),this._markerKey=0;for(const e of this.clusterLabels)e.label.dispose();this.clusterLabels.clear(),this._clusterKey=0,this.currentKeys.clear()}setupEvents(e,s){s&&this._setupWorlds.has(e.uuid)||e.camera.hasCameraControls()&&(s?(e.camera.controls.addEventListener("sleep",()=>{this.manageCluster()}),e.camera.controls.addEventListener("rest",()=>{this.isNavigating&&(this.manageCluster(),this.isNavigating=!1)})):(e.camera.controls.removeEventListener("sleep",()=>{this.manageCluster()}),e.camera.controls.removeEventListener("rest",()=>{this.isNavigating&&(this.manageCluster(),this.isNavigating=!1)})))}resetMarkers(){for(const e of this.list)e.merged=!1;for(const e of this.clusterLabels)e.label.dispose();this.clusterLabels.clear(),this._clusterKey=0}removeMergeMarkers(){for(const e of this.list)e.merged?e.label.dispose():e.label.world.scene.three.add(e.label.three);for(const e of this.clusterLabels)if(e.markerKeys.length===1){const s=Array.from(this.list).find(i=>i.key===e.markerKeys[0]);s&&(s.label.world.scene.three.add(s.label.three),s.merged=!1),e.label.dispose(),this.clusterLabels.delete(e)}}manageCluster(){this.resetMarkers();for(const e of this.list)if(!e.merged&&!e.static){this.currentKeys.clear();for(const s of this.list)s.static||e.key!==s.key&&!s.merged&&this.distance(e.label,s.label)0){this.currentKeys.add(e.key),e.merged=!0;const s=Array.from(this.currentKeys),i=this.getAveragePositionFromLabels(s),n=new Ri(e.label.world,this.createClusterElement(this._clusterKey.toString())),{element:o}=n.three;o.textContent=s.length.toString(),n.three.position.copy(i),this.clusterLabels.add({key:this._clusterKey.toString(),markerKeys:s,label:n}),this._clusterKey++}}this.removeMergeMarkers()}getAveragePositionFromLabels(e){const s=e.map(i=>{const n=Array.from(this.list).find(o=>o.key===i);return n?n.label.three.position:new O});return s.reduce((i,n)=>i.add(n),new O).divideScalar(s.length)}createClusterElement(e){const s=document.createElement("div");return s.textContent=e,s.style.color="#000000",s.style.background="#FFFFFF",s.style.fontSize="1.2rem",s.style.fontWeight="500",s.style.pointerEvents="auto",s.style.borderRadius="50%",s.style.padding="5px 11px",s.style.textAlign="center",s.style.cursor="pointer",s.addEventListener("pointerdown",()=>{this.navigateToCluster(e)}),s.addEventListener("pointerover",()=>{s.style.background="#BCF124"}),s.addEventListener("pointerout",()=>{s.style.background="#FFFFFF"}),s}getScreenPosition(e){const s=new O;if(!e.world.renderer)throw new Error("Renderer not found!");const i=e.three.position.clone();i.project(e.world.camera.three);const n=e.world.renderer.getSize();return s.x=i.x*n.x/2+n.x/2,s.y=-(i.y*n.y/2)+n.y/2,s}distance(e,s){const i=this.getScreenPosition(e),n=this.getScreenPosition(s),o=i.x-n.x,a=i.y-n.y,h=Math.sqrt(o*o+a*a)*.5;return h===0?this.clusterThreshold+1:h}navigateToCluster(e){const s=[],i=Array.from(this.clusterLabels).find(d=>d.key===e);if(!i)return;const n=i.label.world.camera;if(!n.hasCameraControls()){console.warn("Zoom to clusters only supported with Camera Controls!");return}for(const d of i.markerKeys){const p=Array.from(this.list).find(y=>y.key===d);p&&s.push(p.label.three.position)}i.label.dispose(),this.clusterLabels.delete(i);const o=this.createBox3FromPoints(s),a=new O;o.getSize(a);const h=new O;o.getCenter(h);const l=new $(a.x,a.y,a.z);l.translate(h.x,h.y,h.z);const c=new U(l);c.geometry.computeBoundingSphere(),c.geometry.boundingSphere&&n.controls.fitToSphere(c,!0),this.isNavigating=!0,l.dispose(),c.clear(),s.length=0}createBox3FromPoints(e){const s=new ot;for(const i of e)s.expandByPoint(i);return s}};G(ns,"uuid","fdb61dc4-2ec1-4966-b83d-54ea795fad4a");let Hs=ns;const lo=document.getElementById("container"),Ft=new Br,co=Ft.get(en),ee=co.create();ee.scene=new Ir(Ft);ee.renderer=new ho(Ft,lo);ee.camera=new Ce(Ft);Ft.init();ee.camera.controls.setLookAt(5,5,5,0,0,0);const uo=Ft.get(sn);uo.create(ee);const po=Ft.get(Hs);po.create(ee,"Helloooo!",new O); diff --git a/examples/assets/materials.js b/examples/assets/materials.js new file mode 100644 index 000000000..805161e58 --- /dev/null +++ b/examples/assets/materials.js @@ -0,0 +1 @@ +var D=Object.defineProperty;var E=(a,s,e)=>s in a?D(a,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[s]=e;var c=(a,s,e)=>(E(a,typeof s!="symbol"?s+"":s,e),e);import{I as b,c as w,u as I,y as G,K as R,C as f,n as C,b as k}from"./three.module-CYx2Afzj.js";import{g as T}from"./lil-gui.module.min-Bc0DeA9g.js";import{S as v}from"./stats.min-BpIepu9J.js";import{c as z,E as A,C as L,W as U,S as W,a as j,b as K}from"./index-DCLJCpH4.js";const h=class h extends z{constructor(e){super(e);c(this,"enabled",!0);c(this,"_originalBackground",new Map);c(this,"onDisposed",new A);c(this,"list",{});c(this,"_originals",{});this.components.add(h.uuid,this)}set(e,t=Object.keys(this.list)){for(const o of t){const{material:x,meshes:_}=this.list[o];for(const n of _)if(e)this._originals[n.uuid]||(this._originals[n.uuid]={material:n.material}),n instanceof b&&n.instanceColor&&(this._originals[n.uuid].instances=n.instanceColor,n.instanceColor=null),n.material=x;else{if(!this._originals[n.uuid])continue;n.material=this._originals[n.uuid].material;const M=this._originals[n.uuid].instances;n instanceof b&&M&&(n.instanceColor=M)}}}dispose(){for(const e in this.list){const{material:t}=this.list[e];t.dispose()}this.list={},this._originals={},this.onDisposed.trigger(h.uuid),this.onDisposed.reset(),this._originalBackground.clear()}setBackgroundColor(e,t){const o=t.scene.three;o instanceof w&&(this._originalBackground.has(t.uuid)||this._originalBackground.set(t.uuid,o.background),this._originalBackground&&(o.background=e))}resetBackgroundColor(e){const t=e.scene.three;if(!(t instanceof w))return;const o=this._originalBackground.get(e.uuid);o&&(t.background=o)}addMaterial(e,t){if(this.list[e])throw new Error("This ID already exists!");this.list[e]={material:t,meshes:new Set}}addMeshes(e,t){if(!this.list[e])throw new Error("This ID doesn't exists!");for(const o of t)this.list[e].meshes.add(o)}removeMeshes(e,t){if(!this.list[e])throw new Error("This ID doesn't exists!");for(const o of t)this.list[e].meshes.delete(o)}};c(h,"uuid","24989d27-fa2f-4797-8b08-35918f74e502");let p=h;const N=document.getElementById("container"),l=new L,O=l.get(U),i=O.create();i.scene=new W(l);i.renderer=new j(l,N);i.camera=new K(l);l.init();i.camera.controls.setLookAt(13,13,13,0,0,0);i.scene.setup();const B=[],S=[],P=new I(2,2,2),q=new G(2,8,8),y=new R({color:"#6528D7"});function d(a){return Math.random()*a}function F(){for(let a=0;a<3;a++){const s=new k(P,y);s.position.x=d(10),s.position.y=d(10),s.position.z=d(10),s.updateMatrix(),i.scene.three.add(s),B.push(s)}}function H(){for(let a=0;a<3;a++){const s=new k(q,y);s.position.x=d(10),s.position.y=d(10),s.position.z=d(10),s.updateMatrix(),i.scene.three.add(s),S.push(s)}}F();H();const r=l.get(p),J=new f("white"),Q=new f(7460648),V=new C({color:Q}),X=new f(14100587),Y=new C({color:X});r.addMaterial("cubeMaterial",V);r.addMeshes("cubeMaterial",B);r.addMaterial("sphereMaterial",Y);r.addMeshes("sphereMaterial",S);const g=new T,m={changeSphereMaterial:()=>{r.set(!0,["sphereMaterial"])},changeCubeMaterial:()=>{r.set(!0,["cubeMaterial"])},changeBackground:()=>{r.setBackgroundColor(J,i)},reset:()=>{r.set(!1,["cubeMaterial","sphereMaterial"]),r.resetBackgroundColor(i)}};g.add(m,"changeSphereMaterial").name("Change Sphere Material");g.add(m,"changeCubeMaterial").name("Change Cube Material");g.add(m,"changeBackground").name("Change Background");g.add(m,"reset").name("Reset Material");const u=new v;u.showPanel(2);document.body.append(u.dom);u.dom.style.left="0px";i.renderer.onBeforeUpdate.add(()=>u.begin());i.renderer.onAfterUpdate.add(()=>u.end()); diff --git a/examples/assets/raycasters.js b/examples/assets/raycasters.js new file mode 100644 index 000000000..99163d646 --- /dev/null +++ b/examples/assets/raycasters.js @@ -0,0 +1 @@ +import{J as d,u,b as c}from"./three.module-CYx2Afzj.js";import{C as w,W as p,S as b,a as f,b as y}from"./index-DCLJCpH4.js";import{R as S}from"./index-BXUCpuVG.js";const g=document.getElementById("container"),t=new w,x=t.get(p),e=x.create();e.scene=new b(t);e.renderer=new f(t,g);e.camera=new y(t);t.init();e.camera.controls.setLookAt(10,10,10,0,0,0);e.scene.setup();const i=new d({color:"#6528D7"}),M=new d({color:"#BCF124"}),l=new u(3,3,3),a=new c(l,i),n=new c(l,i),r=new c(l,i);e.scene.three.add(a,n,r);const C=[a,n,r];n.position.x=5;r.position.x=-5;const o=Math.PI/180;function h(){a.rotation.x+=o,a.rotation.y+=o,n.rotation.x+=o,n.rotation.z+=o,r.rotation.y+=o,r.rotation.z+=o}e.renderer.onBeforeUpdate.add(h);const B=t.get(S),R=B.get(e);let m=null;window.onmousemove=()=>{const s=R.castRay(C);m&&(m.material=i),!(!s||!(s.object instanceof c))&&(s.object.material=M,m=s.object)}; diff --git a/examples/assets/stats.min-BpIepu9J.js b/examples/assets/stats.min-BpIepu9J.js new file mode 100644 index 000000000..d27722ece --- /dev/null +++ b/examples/assets/stats.min-BpIepu9J.js @@ -0,0 +1 @@ +var b=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function E(f){return f&&f.__esModule&&Object.prototype.hasOwnProperty.call(f,"default")?f.default:f}var x={exports:{}};(function(f,R){(function(s,a){f.exports=a()})(b,function(){var s=function(){function a(n){return o.appendChild(n.dom),n}function c(n){for(var l=0;li+1e3&&(y.update(1e3*e/(n-i),100),i=n,e=0,v)){var l=performance.memory;v.update(l.usedJSHeapSize/1048576,l.jsHeapSizeLimit/1048576)}return n},update:function(){r=this.end()},domElement:o,setMode:c}};return s.Panel=function(a,c,d){var o=1/0,r=0,i=Math.round,e=i(window.devicePixelRatio||1),y=80*e,g=48*e,v=3*e,n=2*e,l=3*e,p=15*e,u=74*e,m=30*e,h=document.createElement("canvas");h.width=y,h.height=g,h.style.cssText="width:80px;height:48px";var t=h.getContext("2d");return t.font="bold "+9*e+"px Helvetica,Arial,sans-serif",t.textBaseline="top",t.fillStyle=d,t.fillRect(0,0,y,g),t.fillStyle=c,t.fillText(a,v,n),t.fillRect(l,p,u,m),t.fillStyle=d,t.globalAlpha=.9,t.fillRect(l,p,u,m),{dom:h,update:function(w,S){o=Math.min(o,w),r=Math.max(r,w),t.fillStyle=d,t.globalAlpha=1,t.fillRect(0,0,y,p),t.fillStyle=c,t.fillText(i(w)+" "+a+" ("+i(o)+"-"+i(r)+")",v,n),t.drawImage(h,l+e,p,u-e,m,l,p,u-e,m),t.fillRect(l+u-e,p,e,m),t.fillStyle=d,t.globalAlpha=.9,t.fillRect(l+u-e,p,e,i((1-w/S)*m))}}},s})})(x);var P=x.exports;const M=E(P);export{M as S}; diff --git a/examples/assets/three.module-CYx2Afzj.js b/examples/assets/three.module-CYx2Afzj.js new file mode 100644 index 000000000..7216ec914 --- /dev/null +++ b/examples/assets/three.module-CYx2Afzj.js @@ -0,0 +1,3686 @@ +(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))n(r);new MutationObserver(r=>{for(const s of r)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&n(o)}).observe(document,{childList:!0,subtree:!0});function t(r){const s={};return r.integrity&&(s.integrity=r.integrity),r.referrerPolicy&&(s.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?s.credentials="include":r.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function n(r){if(r.ep)return;r.ep=!0;const s=t(r);fetch(r.href,s)}})();/** + * @license + * Copyright 2010-2023 Three.js Authors + * SPDX-License-Identifier: MIT + */const Kr="160",np={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},Po=0,ds=1,Do=2,Wa=1,Uo=2,jt=3,cn=0,St=1,Kt=2,an=0,Yn=1,ps=2,ms=3,_s=4,Io=5,vn=100,No=101,Fo=102,gs=103,vs=104,Oo=200,Bo=201,zo=202,Go=203,zr=204,Gr=205,Ho=206,Vo=207,ko=208,Wo=209,Xo=210,qo=211,Yo=212,jo=213,Ko=214,Zo=0,$o=1,Jo=2,Yi=3,Qo=4,el=5,tl=6,nl=7,Zr=0,il=1,rl=2,on=0,sl=1,al=2,ol=3,ll=4,cl=5,hl=6,Xa=300,Kn=301,Zn=302,Hr=303,Vr=304,er=306,kr=1e3,Ft=1001,Wr=1002,Mt=1003,xs=1004,lr=1005,Rt=1006,ul=1007,di=1008,ln=1009,fl=1010,dl=1011,$r=1012,qa=1013,rn=1014,sn=1015,pi=1016,Ya=1017,ja=1018,Mn=1020,pl=1021,Ot=1023,ml=1024,_l=1025,Sn=1026,$n=1027,gl=1028,Ka=1029,vl=1030,Za=1031,$a=1033,cr=33776,hr=33777,ur=33778,fr=33779,Ms=35840,Ss=35841,Es=35842,ys=35843,Ja=36196,Ts=37492,As=37496,bs=37808,ws=37809,Rs=37810,Cs=37811,Ls=37812,Ps=37813,Ds=37814,Us=37815,Is=37816,Ns=37817,Fs=37818,Os=37819,Bs=37820,zs=37821,dr=36492,Gs=36494,Hs=36495,xl=36283,Vs=36284,ks=36285,Ws=36286,Qa=3e3,En=3001,Ml=3200,Sl=3201,Jr=0,El=1,Ct="",ct="srgb",$t="srgb-linear",Qr="display-p3",tr="display-p3-linear",ji="linear",je="srgb",Ki="rec709",Zi="p3",wn=7680,Xs=519,yl=512,Tl=513,Al=514,eo=515,bl=516,wl=517,Rl=518,Cl=519,qs=35044,Ys="300 es",Xr=1035,Zt=2e3,$i=2001;class Qn{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});const n=this._listeners;n[e]===void 0&&(n[e]=[]),n[e].indexOf(t)===-1&&n[e].push(t)}hasEventListener(e,t){if(this._listeners===void 0)return!1;const n=this._listeners;return n[e]!==void 0&&n[e].indexOf(t)!==-1}removeEventListener(e,t){if(this._listeners===void 0)return;const r=this._listeners[e];if(r!==void 0){const s=r.indexOf(t);s!==-1&&r.splice(s,1)}}dispatchEvent(e){if(this._listeners===void 0)return;const n=this._listeners[e.type];if(n!==void 0){e.target=this;const r=n.slice(0);for(let s=0,o=r.length;s>8&255]+dt[i>>16&255]+dt[i>>24&255]+"-"+dt[e&255]+dt[e>>8&255]+"-"+dt[e>>16&15|64]+dt[e>>24&255]+"-"+dt[t&63|128]+dt[t>>8&255]+"-"+dt[t>>16&255]+dt[t>>24&255]+dt[n&255]+dt[n>>8&255]+dt[n>>16&255]+dt[n>>24&255]).toLowerCase()}function ht(i,e,t){return Math.max(e,Math.min(t,i))}function es(i,e){return(i%e+e)%e}function Ll(i,e,t,n,r){return n+(i-e)*(r-n)/(t-e)}function Pl(i,e,t){return i!==e?(t-i)/(e-i):0}function ui(i,e,t){return(1-t)*i+t*e}function Dl(i,e,t,n){return ui(i,e,1-Math.exp(-t*n))}function Ul(i,e=1){return e-Math.abs(es(i,e*2)-e)}function Il(i,e,t){return i<=e?0:i>=t?1:(i=(i-e)/(t-e),i*i*(3-2*i))}function Nl(i,e,t){return i<=e?0:i>=t?1:(i=(i-e)/(t-e),i*i*i*(i*(i*6-15)+10))}function Fl(i,e){return i+Math.floor(Math.random()*(e-i+1))}function Ol(i,e){return i+Math.random()*(e-i)}function Bl(i){return i*(.5-Math.random())}function zl(i){i!==void 0&&(js=i);let e=js+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function Gl(i){return i*hi}function Hl(i){return i*mi}function qr(i){return(i&i-1)===0&&i!==0}function Vl(i){return Math.pow(2,Math.ceil(Math.log(i)/Math.LN2))}function Ji(i){return Math.pow(2,Math.floor(Math.log(i)/Math.LN2))}function kl(i,e,t,n,r){const s=Math.cos,o=Math.sin,a=s(t/2),l=o(t/2),c=s((e+n)/2),u=o((e+n)/2),f=s((e-n)/2),d=o((e-n)/2),m=s((n-e)/2),g=o((n-e)/2);switch(r){case"XYX":i.set(a*u,l*f,l*d,a*c);break;case"YZY":i.set(l*d,a*u,l*f,a*c);break;case"ZXZ":i.set(l*f,l*d,a*u,a*c);break;case"XZX":i.set(a*u,l*g,l*m,a*c);break;case"YXY":i.set(l*m,a*u,l*g,a*c);break;case"ZYZ":i.set(l*g,l*m,a*u,a*c);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}}function Wn(i,e){switch(e.constructor){case Float32Array:return i;case Uint32Array:return i/4294967295;case Uint16Array:return i/65535;case Uint8Array:return i/255;case Int32Array:return Math.max(i/2147483647,-1);case Int16Array:return Math.max(i/32767,-1);case Int8Array:return Math.max(i/127,-1);default:throw new Error("Invalid component type.")}}function vt(i,e){switch(e.constructor){case Float32Array:return i;case Uint32Array:return Math.round(i*4294967295);case Uint16Array:return Math.round(i*65535);case Uint8Array:return Math.round(i*255);case Int32Array:return Math.round(i*2147483647);case Int16Array:return Math.round(i*32767);case Int8Array:return Math.round(i*127);default:throw new Error("Invalid component type.")}}const ip={DEG2RAD:hi,RAD2DEG:mi,generateUUID:ei,clamp:ht,euclideanModulo:es,mapLinear:Ll,inverseLerp:Pl,lerp:ui,damp:Dl,pingpong:Ul,smoothstep:Il,smootherstep:Nl,randInt:Fl,randFloat:Ol,randFloatSpread:Bl,seededRandom:zl,degToRad:Gl,radToDeg:Hl,isPowerOfTwo:qr,ceilPowerOfTwo:Vl,floorPowerOfTwo:Ji,setQuaternionFromProperEuler:kl,normalize:vt,denormalize:Wn};class ze{constructor(e=0,t=0){ze.prototype.isVector2=!0,this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,n=this.y,r=e.elements;return this.x=r[0]*t+r[3]*n+r[6],this.y=r[1]*t+r[4]*n+r[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const n=this.dot(e)/t;return Math.acos(ht(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y;return t*t+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){const n=Math.cos(t),r=Math.sin(t),s=this.x-e.x,o=this.y-e.y;return this.x=s*n-o*r+e.x,this.y=s*r+o*n+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Oe{constructor(e,t,n,r,s,o,a,l,c){Oe.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,n,r,s,o,a,l,c)}set(e,t,n,r,s,o,a,l,c){const u=this.elements;return u[0]=e,u[1]=r,u[2]=a,u[3]=t,u[4]=s,u[5]=l,u[6]=n,u[7]=o,u[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],this}extractBasis(e,t,n){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const n=e.elements,r=t.elements,s=this.elements,o=n[0],a=n[3],l=n[6],c=n[1],u=n[4],f=n[7],d=n[2],m=n[5],g=n[8],x=r[0],p=r[3],h=r[6],E=r[1],_=r[4],A=r[7],C=r[2],b=r[5],w=r[8];return s[0]=o*x+a*E+l*C,s[3]=o*p+a*_+l*b,s[6]=o*h+a*A+l*w,s[1]=c*x+u*E+f*C,s[4]=c*p+u*_+f*b,s[7]=c*h+u*A+f*w,s[2]=d*x+m*E+g*C,s[5]=d*p+m*_+g*b,s[8]=d*h+m*A+g*w,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],n=e[1],r=e[2],s=e[3],o=e[4],a=e[5],l=e[6],c=e[7],u=e[8];return t*o*u-t*a*c-n*s*u+n*a*l+r*s*c-r*o*l}invert(){const e=this.elements,t=e[0],n=e[1],r=e[2],s=e[3],o=e[4],a=e[5],l=e[6],c=e[7],u=e[8],f=u*o-a*c,d=a*l-u*s,m=c*s-o*l,g=t*f+n*d+r*m;if(g===0)return this.set(0,0,0,0,0,0,0,0,0);const x=1/g;return e[0]=f*x,e[1]=(r*c-u*n)*x,e[2]=(a*n-r*o)*x,e[3]=d*x,e[4]=(u*t-r*l)*x,e[5]=(r*s-a*t)*x,e[6]=m*x,e[7]=(n*l-c*t)*x,e[8]=(o*t-n*s)*x,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,n,r,s,o,a){const l=Math.cos(s),c=Math.sin(s);return this.set(n*l,n*c,-n*(l*o+c*a)+o+e,-r*c,r*l,-r*(-c*o+l*a)+a+t,0,0,1),this}scale(e,t){return this.premultiply(pr.makeScale(e,t)),this}rotate(e){return this.premultiply(pr.makeRotation(-e)),this}translate(e,t){return this.premultiply(pr.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,n,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,n=e.elements;for(let r=0;r<9;r++)if(t[r]!==n[r])return!1;return!0}fromArray(e,t=0){for(let n=0;n<9;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){const n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e}clone(){return new this.constructor().fromArray(this.elements)}}const pr=new Oe;function to(i){for(let e=i.length-1;e>=0;--e)if(i[e]>=65535)return!0;return!1}function Qi(i){return document.createElementNS("http://www.w3.org/1999/xhtml",i)}function Wl(){const i=Qi("canvas");return i.style.display="block",i}const Ks={};function fi(i){i in Ks||(Ks[i]=!0,console.warn(i))}const Zs=new Oe().set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),$s=new Oe().set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),Mi={[$t]:{transfer:ji,primaries:Ki,toReference:i=>i,fromReference:i=>i},[ct]:{transfer:je,primaries:Ki,toReference:i=>i.convertSRGBToLinear(),fromReference:i=>i.convertLinearToSRGB()},[tr]:{transfer:ji,primaries:Zi,toReference:i=>i.applyMatrix3($s),fromReference:i=>i.applyMatrix3(Zs)},[Qr]:{transfer:je,primaries:Zi,toReference:i=>i.convertSRGBToLinear().applyMatrix3($s),fromReference:i=>i.applyMatrix3(Zs).convertLinearToSRGB()}},Xl=new Set([$t,tr]),We={enabled:!0,_workingColorSpace:$t,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(i){if(!Xl.has(i))throw new Error(`Unsupported working color space, "${i}".`);this._workingColorSpace=i},convert:function(i,e,t){if(this.enabled===!1||e===t||!e||!t)return i;const n=Mi[e].toReference,r=Mi[t].fromReference;return r(n(i))},fromWorkingColorSpace:function(i,e){return this.convert(i,this._workingColorSpace,e)},toWorkingColorSpace:function(i,e){return this.convert(i,e,this._workingColorSpace)},getPrimaries:function(i){return Mi[i].primaries},getTransfer:function(i){return i===Ct?ji:Mi[i].transfer}};function jn(i){return i<.04045?i*.0773993808:Math.pow(i*.9478672986+.0521327014,2.4)}function mr(i){return i<.0031308?i*12.92:1.055*Math.pow(i,.41666)-.055}let Rn;class no{static getDataURL(e){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let t;if(e instanceof HTMLCanvasElement)t=e;else{Rn===void 0&&(Rn=Qi("canvas")),Rn.width=e.width,Rn.height=e.height;const n=Rn.getContext("2d");e instanceof ImageData?n.putImageData(e,0,0):n.drawImage(e,0,0,e.width,e.height),t=Rn}return t.width>2048||t.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",e),t.toDataURL("image/jpeg",.6)):t.toDataURL("image/png")}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){const t=Qi("canvas");t.width=e.width,t.height=e.height;const n=t.getContext("2d");n.drawImage(e,0,0,e.width,e.height);const r=n.getImageData(0,0,e.width,e.height),s=r.data;for(let o=0;o0&&(n.userData=this.userData),t||(e.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==Xa)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case kr:e.x=e.x-Math.floor(e.x);break;case Ft:e.x=e.x<0?0:1;break;case Wr:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case kr:e.y=e.y-Math.floor(e.y);break;case Ft:e.y=e.y<0?0:1;break;case Wr:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}get encoding(){return fi("THREE.Texture: Property .encoding has been replaced by .colorSpace."),this.colorSpace===ct?En:Qa}set encoding(e){fi("THREE.Texture: Property .encoding has been replaced by .colorSpace."),this.colorSpace=e===En?ct:Ct}}At.DEFAULT_IMAGE=null;At.DEFAULT_MAPPING=Xa;At.DEFAULT_ANISOTROPY=1;class lt{constructor(e=0,t=0,n=0,r=1){lt.prototype.isVector4=!0,this.x=e,this.y=t,this.z=n,this.w=r}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,n,r){return this.x=e,this.y=t,this.z=n,this.w=r,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,n=this.y,r=this.z,s=this.w,o=e.elements;return this.x=o[0]*t+o[4]*n+o[8]*r+o[12]*s,this.y=o[1]*t+o[5]*n+o[9]*r+o[13]*s,this.z=o[2]*t+o[6]*n+o[10]*r+o[14]*s,this.w=o[3]*t+o[7]*n+o[11]*r+o[15]*s,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,n,r,s;const l=e.elements,c=l[0],u=l[4],f=l[8],d=l[1],m=l[5],g=l[9],x=l[2],p=l[6],h=l[10];if(Math.abs(u-d)<.01&&Math.abs(f-x)<.01&&Math.abs(g-p)<.01){if(Math.abs(u+d)<.1&&Math.abs(f+x)<.1&&Math.abs(g+p)<.1&&Math.abs(c+m+h-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const _=(c+1)/2,A=(m+1)/2,C=(h+1)/2,b=(u+d)/4,w=(f+x)/4,z=(g+p)/4;return _>A&&_>C?_<.01?(n=0,r=.707106781,s=.707106781):(n=Math.sqrt(_),r=b/n,s=w/n):A>C?A<.01?(n=.707106781,r=0,s=.707106781):(r=Math.sqrt(A),n=b/r,s=z/r):C<.01?(n=.707106781,r=.707106781,s=0):(s=Math.sqrt(C),n=w/s,r=z/s),this.set(n,r,s,t),this}let E=Math.sqrt((p-g)*(p-g)+(f-x)*(f-x)+(d-u)*(d-u));return Math.abs(E)<.001&&(E=1),this.x=(p-g)/E,this.y=(f-x)/E,this.z=(d-u)/E,this.w=Math.acos((c+m+h-1)/2),this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this.w=Math.max(e.w,Math.min(t.w,this.w)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this.w=Math.max(e,Math.min(t,this.w)),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this.w=e.w+(t.w-e.w)*n,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class jl extends Qn{constructor(e=1,t=1,n={}){super(),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=1,this.scissor=new lt(0,0,e,t),this.scissorTest=!1,this.viewport=new lt(0,0,e,t);const r={width:e,height:t,depth:1};n.encoding!==void 0&&(fi("THREE.WebGLRenderTarget: option.encoding has been replaced by option.colorSpace."),n.colorSpace=n.encoding===En?ct:Ct),n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:Rt,depthBuffer:!0,stencilBuffer:!1,depthTexture:null,samples:0},n),this.texture=new At(r,n.mapping,n.wrapS,n.wrapT,n.magFilter,n.minFilter,n.format,n.type,n.anisotropy,n.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.flipY=!1,this.texture.generateMipmaps=n.generateMipmaps,this.texture.internalFormat=n.internalFormat,this.depthBuffer=n.depthBuffer,this.stencilBuffer=n.stencilBuffer,this.depthTexture=n.depthTexture,this.samples=n.samples}setSize(e,t,n=1){(this.width!==e||this.height!==t||this.depth!==n)&&(this.width=e,this.height=t,this.depth=n,this.texture.image.width=e,this.texture.image.height=t,this.texture.image.depth=n,this.dispose()),this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.texture=e.texture.clone(),this.texture.isRenderTargetTexture=!0;const t=Object.assign({},e.texture.image);return this.texture.source=new io(t),this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,e.depthTexture!==null&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class yn extends jl{constructor(e=1,t=1,n={}){super(e,t,n),this.isWebGLRenderTarget=!0}}class ro extends At{constructor(e=null,t=1,n=1,r=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:n,depth:r},this.magFilter=Mt,this.minFilter=Mt,this.wrapR=Ft,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class Kl extends At{constructor(e=null,t=1,n=1,r=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:n,depth:r},this.magFilter=Mt,this.minFilter=Mt,this.wrapR=Ft,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class _i{constructor(e=0,t=0,n=0,r=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=n,this._w=r}static slerpFlat(e,t,n,r,s,o,a){let l=n[r+0],c=n[r+1],u=n[r+2],f=n[r+3];const d=s[o+0],m=s[o+1],g=s[o+2],x=s[o+3];if(a===0){e[t+0]=l,e[t+1]=c,e[t+2]=u,e[t+3]=f;return}if(a===1){e[t+0]=d,e[t+1]=m,e[t+2]=g,e[t+3]=x;return}if(f!==x||l!==d||c!==m||u!==g){let p=1-a;const h=l*d+c*m+u*g+f*x,E=h>=0?1:-1,_=1-h*h;if(_>Number.EPSILON){const C=Math.sqrt(_),b=Math.atan2(C,h*E);p=Math.sin(p*b)/C,a=Math.sin(a*b)/C}const A=a*E;if(l=l*p+d*A,c=c*p+m*A,u=u*p+g*A,f=f*p+x*A,p===1-a){const C=1/Math.sqrt(l*l+c*c+u*u+f*f);l*=C,c*=C,u*=C,f*=C}}e[t]=l,e[t+1]=c,e[t+2]=u,e[t+3]=f}static multiplyQuaternionsFlat(e,t,n,r,s,o){const a=n[r],l=n[r+1],c=n[r+2],u=n[r+3],f=s[o],d=s[o+1],m=s[o+2],g=s[o+3];return e[t]=a*g+u*f+l*m-c*d,e[t+1]=l*g+u*d+c*f-a*m,e[t+2]=c*g+u*m+a*d-l*f,e[t+3]=u*g-a*f-l*d-c*m,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,n,r){return this._x=e,this._y=t,this._z=n,this._w=r,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const n=e._x,r=e._y,s=e._z,o=e._order,a=Math.cos,l=Math.sin,c=a(n/2),u=a(r/2),f=a(s/2),d=l(n/2),m=l(r/2),g=l(s/2);switch(o){case"XYZ":this._x=d*u*f+c*m*g,this._y=c*m*f-d*u*g,this._z=c*u*g+d*m*f,this._w=c*u*f-d*m*g;break;case"YXZ":this._x=d*u*f+c*m*g,this._y=c*m*f-d*u*g,this._z=c*u*g-d*m*f,this._w=c*u*f+d*m*g;break;case"ZXY":this._x=d*u*f-c*m*g,this._y=c*m*f+d*u*g,this._z=c*u*g+d*m*f,this._w=c*u*f-d*m*g;break;case"ZYX":this._x=d*u*f-c*m*g,this._y=c*m*f+d*u*g,this._z=c*u*g-d*m*f,this._w=c*u*f+d*m*g;break;case"YZX":this._x=d*u*f+c*m*g,this._y=c*m*f+d*u*g,this._z=c*u*g-d*m*f,this._w=c*u*f-d*m*g;break;case"XZY":this._x=d*u*f-c*m*g,this._y=c*m*f-d*u*g,this._z=c*u*g+d*m*f,this._w=c*u*f+d*m*g;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+o)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const n=t/2,r=Math.sin(n);return this._x=e.x*r,this._y=e.y*r,this._z=e.z*r,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,n=t[0],r=t[4],s=t[8],o=t[1],a=t[5],l=t[9],c=t[2],u=t[6],f=t[10],d=n+a+f;if(d>0){const m=.5/Math.sqrt(d+1);this._w=.25/m,this._x=(u-l)*m,this._y=(s-c)*m,this._z=(o-r)*m}else if(n>a&&n>f){const m=2*Math.sqrt(1+n-a-f);this._w=(u-l)/m,this._x=.25*m,this._y=(r+o)/m,this._z=(s+c)/m}else if(a>f){const m=2*Math.sqrt(1+a-n-f);this._w=(s-c)/m,this._x=(r+o)/m,this._y=.25*m,this._z=(l+u)/m}else{const m=2*Math.sqrt(1+f-n-a);this._w=(o-r)/m,this._x=(s+c)/m,this._y=(l+u)/m,this._z=.25*m}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let n=e.dot(t)+1;return nMath.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=n):(this._x=0,this._y=-e.z,this._z=e.y,this._w=n)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=n),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(ht(this.dot(e),-1,1)))}rotateTowards(e,t){const n=this.angleTo(e);if(n===0)return this;const r=Math.min(1,t/n);return this.slerp(e,r),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const n=e._x,r=e._y,s=e._z,o=e._w,a=t._x,l=t._y,c=t._z,u=t._w;return this._x=n*u+o*a+r*c-s*l,this._y=r*u+o*l+s*a-n*c,this._z=s*u+o*c+n*l-r*a,this._w=o*u-n*a-r*l-s*c,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);const n=this._x,r=this._y,s=this._z,o=this._w;let a=o*e._w+n*e._x+r*e._y+s*e._z;if(a<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,a=-a):this.copy(e),a>=1)return this._w=o,this._x=n,this._y=r,this._z=s,this;const l=1-a*a;if(l<=Number.EPSILON){const m=1-t;return this._w=m*o+t*this._w,this._x=m*n+t*this._x,this._y=m*r+t*this._y,this._z=m*s+t*this._z,this.normalize(),this}const c=Math.sqrt(l),u=Math.atan2(c,a),f=Math.sin((1-t)*u)/c,d=Math.sin(t*u)/c;return this._w=o*f+this._w*d,this._x=n*f+this._x*d,this._y=r*f+this._y*d,this._z=s*f+this._z*d,this._onChangeCallback(),this}slerpQuaternions(e,t,n){return this.copy(e).slerp(t,n)}random(){const e=Math.random(),t=Math.sqrt(1-e),n=Math.sqrt(e),r=2*Math.PI*Math.random(),s=2*Math.PI*Math.random();return this.set(t*Math.cos(r),n*Math.sin(s),n*Math.cos(s),t*Math.sin(r))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class P{constructor(e=0,t=0,n=0){P.prototype.isVector3=!0,this.x=e,this.y=t,this.z=n}set(e,t,n){return n===void 0&&(n=this.z),this.x=e,this.y=t,this.z=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(Js.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Js.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,n=this.y,r=this.z,s=e.elements;return this.x=s[0]*t+s[3]*n+s[6]*r,this.y=s[1]*t+s[4]*n+s[7]*r,this.z=s[2]*t+s[5]*n+s[8]*r,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,n=this.y,r=this.z,s=e.elements,o=1/(s[3]*t+s[7]*n+s[11]*r+s[15]);return this.x=(s[0]*t+s[4]*n+s[8]*r+s[12])*o,this.y=(s[1]*t+s[5]*n+s[9]*r+s[13])*o,this.z=(s[2]*t+s[6]*n+s[10]*r+s[14])*o,this}applyQuaternion(e){const t=this.x,n=this.y,r=this.z,s=e.x,o=e.y,a=e.z,l=e.w,c=2*(o*r-a*n),u=2*(a*t-s*r),f=2*(s*n-o*t);return this.x=t+l*c+o*f-a*u,this.y=n+l*u+a*c-s*f,this.z=r+l*f+s*u-o*c,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const t=this.x,n=this.y,r=this.z,s=e.elements;return this.x=s[0]*t+s[4]*n+s[8]*r,this.y=s[1]*t+s[5]*n+s[9]*r,this.z=s[2]*t+s[6]*n+s[10]*r,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const n=e.x,r=e.y,s=e.z,o=t.x,a=t.y,l=t.z;return this.x=r*l-s*a,this.y=s*o-n*l,this.z=n*a-r*o,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const n=e.dot(this)/t;return this.copy(e).multiplyScalar(n)}projectOnPlane(e){return gr.copy(this).projectOnVector(e),this.sub(gr)}reflect(e){return this.sub(gr.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const n=this.dot(e)/t;return Math.acos(ht(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y,r=this.z-e.z;return t*t+n*n+r*r}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,n){const r=Math.sin(t)*e;return this.x=r*Math.sin(n),this.y=Math.cos(t)*e,this.z=r*Math.cos(n),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,n){return this.x=e*Math.sin(t),this.y=n,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),n=this.setFromMatrixColumn(e,1).length(),r=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=n,this.z=r,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=(Math.random()-.5)*2,t=Math.random()*Math.PI*2,n=Math.sqrt(1-e**2);return this.x=n*Math.cos(t),this.y=n*Math.sin(t),this.z=e,this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const gr=new P,Js=new _i;class An{constructor(e=new P(1/0,1/0,1/0),t=new P(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,n=e.length;tthis.max.x||e.ythis.max.y||e.zthis.max.z)}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return!(e.max.xthis.max.x||e.max.ythis.max.y||e.max.zthis.max.z)}intersectsSphere(e){return this.clampPoint(e.center,Pt),Pt.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,n;return e.normal.x>0?(t=e.normal.x*this.min.x,n=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,n=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,n+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,n+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,n+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,n+=e.normal.z*this.min.z),t<=-e.constant&&n>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(ri),Ei.subVectors(this.max,ri),Cn.subVectors(e.a,ri),Ln.subVectors(e.b,ri),Pn.subVectors(e.c,ri),Jt.subVectors(Ln,Cn),Qt.subVectors(Pn,Ln),fn.subVectors(Cn,Pn);let t=[0,-Jt.z,Jt.y,0,-Qt.z,Qt.y,0,-fn.z,fn.y,Jt.z,0,-Jt.x,Qt.z,0,-Qt.x,fn.z,0,-fn.x,-Jt.y,Jt.x,0,-Qt.y,Qt.x,0,-fn.y,fn.x,0];return!vr(t,Cn,Ln,Pn,Ei)||(t=[1,0,0,0,1,0,0,0,1],!vr(t,Cn,Ln,Pn,Ei))?!1:(yi.crossVectors(Jt,Qt),t=[yi.x,yi.y,yi.z],vr(t,Cn,Ln,Pn,Ei))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Pt).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(Pt).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(kt[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),kt[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),kt[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),kt[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),kt[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),kt[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),kt[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),kt[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(kt),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}}const kt=[new P,new P,new P,new P,new P,new P,new P,new P],Pt=new P,Si=new An,Cn=new P,Ln=new P,Pn=new P,Jt=new P,Qt=new P,fn=new P,ri=new P,Ei=new P,yi=new P,dn=new P;function vr(i,e,t,n,r){for(let s=0,o=i.length-3;s<=o;s+=3){dn.fromArray(i,s);const a=r.x*Math.abs(dn.x)+r.y*Math.abs(dn.y)+r.z*Math.abs(dn.z),l=e.dot(dn),c=t.dot(dn),u=n.dot(dn);if(Math.max(-Math.max(l,c,u),Math.min(l,c,u))>a)return!1}return!0}const Zl=new An,si=new P,xr=new P;class ti{constructor(e=new P,t=-1){this.isSphere=!0,this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){const n=this.center;t!==void 0?n.copy(t):Zl.setFromPoints(e).getCenter(n);let r=0;for(let s=0,o=e.length;sthis.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;si.subVectors(e,this.center);const t=si.lengthSq();if(t>this.radius*this.radius){const n=Math.sqrt(t),r=(n-this.radius)*.5;this.center.addScaledVector(si,r/n),this.radius+=r}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(xr.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(si.copy(e.center).add(xr)),this.expandByPoint(si.copy(e.center).sub(xr))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}}const Wt=new P,Mr=new P,Ti=new P,en=new P,Sr=new P,Ai=new P,Er=new P;class ts{constructor(e=new P,t=new P(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,Wt)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);const n=t.dot(this.direction);return n<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){const t=Wt.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(Wt.copy(this.origin).addScaledVector(this.direction,t),Wt.distanceToSquared(e))}distanceSqToSegment(e,t,n,r){Mr.copy(e).add(t).multiplyScalar(.5),Ti.copy(t).sub(e).normalize(),en.copy(this.origin).sub(Mr);const s=e.distanceTo(t)*.5,o=-this.direction.dot(Ti),a=en.dot(this.direction),l=-en.dot(Ti),c=en.lengthSq(),u=Math.abs(1-o*o);let f,d,m,g;if(u>0)if(f=o*l-a,d=o*a-l,g=s*u,f>=0)if(d>=-g)if(d<=g){const x=1/u;f*=x,d*=x,m=f*(f+o*d+2*a)+d*(o*f+d+2*l)+c}else d=s,f=Math.max(0,-(o*d+a)),m=-f*f+d*(d+2*l)+c;else d=-s,f=Math.max(0,-(o*d+a)),m=-f*f+d*(d+2*l)+c;else d<=-g?(f=Math.max(0,-(-o*s+a)),d=f>0?-s:Math.min(Math.max(-s,-l),s),m=-f*f+d*(d+2*l)+c):d<=g?(f=0,d=Math.min(Math.max(-s,-l),s),m=d*(d+2*l)+c):(f=Math.max(0,-(o*s+a)),d=f>0?s:Math.min(Math.max(-s,-l),s),m=-f*f+d*(d+2*l)+c);else d=o>0?-s:s,f=Math.max(0,-(o*d+a)),m=-f*f+d*(d+2*l)+c;return n&&n.copy(this.origin).addScaledVector(this.direction,f),r&&r.copy(Mr).addScaledVector(Ti,d),m}intersectSphere(e,t){Wt.subVectors(e.center,this.origin);const n=Wt.dot(this.direction),r=Wt.dot(Wt)-n*n,s=e.radius*e.radius;if(r>s)return null;const o=Math.sqrt(s-r),a=n-o,l=n+o;return l<0?null:a<0?this.at(l,t):this.at(a,t)}intersectsSphere(e){return this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){const t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;const n=-(this.origin.dot(e.normal)+e.constant)/t;return n>=0?n:null}intersectPlane(e,t){const n=this.distanceToPlane(e);return n===null?null:this.at(n,t)}intersectsPlane(e){const t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let n,r,s,o,a,l;const c=1/this.direction.x,u=1/this.direction.y,f=1/this.direction.z,d=this.origin;return c>=0?(n=(e.min.x-d.x)*c,r=(e.max.x-d.x)*c):(n=(e.max.x-d.x)*c,r=(e.min.x-d.x)*c),u>=0?(s=(e.min.y-d.y)*u,o=(e.max.y-d.y)*u):(s=(e.max.y-d.y)*u,o=(e.min.y-d.y)*u),n>o||s>r||((s>n||isNaN(n))&&(n=s),(o=0?(a=(e.min.z-d.z)*f,l=(e.max.z-d.z)*f):(a=(e.max.z-d.z)*f,l=(e.min.z-d.z)*f),n>l||a>r)||((a>n||n!==n)&&(n=a),(l=0?n:r,t)}intersectsBox(e){return this.intersectBox(e,Wt)!==null}intersectTriangle(e,t,n,r,s){Sr.subVectors(t,e),Ai.subVectors(n,e),Er.crossVectors(Sr,Ai);let o=this.direction.dot(Er),a;if(o>0){if(r)return null;a=1}else if(o<0)a=-1,o=-o;else return null;en.subVectors(this.origin,e);const l=a*this.direction.dot(Ai.crossVectors(en,Ai));if(l<0)return null;const c=a*this.direction.dot(Sr.cross(en));if(c<0||l+c>o)return null;const u=-a*en.dot(Er);return u<0?null:this.at(u/o,s)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class $e{constructor(e,t,n,r,s,o,a,l,c,u,f,d,m,g,x,p){$e.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,n,r,s,o,a,l,c,u,f,d,m,g,x,p)}set(e,t,n,r,s,o,a,l,c,u,f,d,m,g,x,p){const h=this.elements;return h[0]=e,h[4]=t,h[8]=n,h[12]=r,h[1]=s,h[5]=o,h[9]=a,h[13]=l,h[2]=c,h[6]=u,h[10]=f,h[14]=d,h[3]=m,h[7]=g,h[11]=x,h[15]=p,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new $e().fromArray(this.elements)}copy(e){const t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],this}copyPosition(e){const t=this.elements,n=e.elements;return t[12]=n[12],t[13]=n[13],t[14]=n[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,n){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(e,t,n){return this.set(e.x,t.x,n.x,0,e.y,t.y,n.y,0,e.z,t.z,n.z,0,0,0,0,1),this}extractRotation(e){const t=this.elements,n=e.elements,r=1/Dn.setFromMatrixColumn(e,0).length(),s=1/Dn.setFromMatrixColumn(e,1).length(),o=1/Dn.setFromMatrixColumn(e,2).length();return t[0]=n[0]*r,t[1]=n[1]*r,t[2]=n[2]*r,t[3]=0,t[4]=n[4]*s,t[5]=n[5]*s,t[6]=n[6]*s,t[7]=0,t[8]=n[8]*o,t[9]=n[9]*o,t[10]=n[10]*o,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,n=e.x,r=e.y,s=e.z,o=Math.cos(n),a=Math.sin(n),l=Math.cos(r),c=Math.sin(r),u=Math.cos(s),f=Math.sin(s);if(e.order==="XYZ"){const d=o*u,m=o*f,g=a*u,x=a*f;t[0]=l*u,t[4]=-l*f,t[8]=c,t[1]=m+g*c,t[5]=d-x*c,t[9]=-a*l,t[2]=x-d*c,t[6]=g+m*c,t[10]=o*l}else if(e.order==="YXZ"){const d=l*u,m=l*f,g=c*u,x=c*f;t[0]=d+x*a,t[4]=g*a-m,t[8]=o*c,t[1]=o*f,t[5]=o*u,t[9]=-a,t[2]=m*a-g,t[6]=x+d*a,t[10]=o*l}else if(e.order==="ZXY"){const d=l*u,m=l*f,g=c*u,x=c*f;t[0]=d-x*a,t[4]=-o*f,t[8]=g+m*a,t[1]=m+g*a,t[5]=o*u,t[9]=x-d*a,t[2]=-o*c,t[6]=a,t[10]=o*l}else if(e.order==="ZYX"){const d=o*u,m=o*f,g=a*u,x=a*f;t[0]=l*u,t[4]=g*c-m,t[8]=d*c+x,t[1]=l*f,t[5]=x*c+d,t[9]=m*c-g,t[2]=-c,t[6]=a*l,t[10]=o*l}else if(e.order==="YZX"){const d=o*l,m=o*c,g=a*l,x=a*c;t[0]=l*u,t[4]=x-d*f,t[8]=g*f+m,t[1]=f,t[5]=o*u,t[9]=-a*u,t[2]=-c*u,t[6]=m*f+g,t[10]=d-x*f}else if(e.order==="XZY"){const d=o*l,m=o*c,g=a*l,x=a*c;t[0]=l*u,t[4]=-f,t[8]=c*u,t[1]=d*f+x,t[5]=o*u,t[9]=m*f-g,t[2]=g*f-m,t[6]=a*u,t[10]=x*f+d}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose($l,e,Jl)}lookAt(e,t,n){const r=this.elements;return yt.subVectors(e,t),yt.lengthSq()===0&&(yt.z=1),yt.normalize(),tn.crossVectors(n,yt),tn.lengthSq()===0&&(Math.abs(n.z)===1?yt.x+=1e-4:yt.z+=1e-4,yt.normalize(),tn.crossVectors(n,yt)),tn.normalize(),bi.crossVectors(yt,tn),r[0]=tn.x,r[4]=bi.x,r[8]=yt.x,r[1]=tn.y,r[5]=bi.y,r[9]=yt.y,r[2]=tn.z,r[6]=bi.z,r[10]=yt.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const n=e.elements,r=t.elements,s=this.elements,o=n[0],a=n[4],l=n[8],c=n[12],u=n[1],f=n[5],d=n[9],m=n[13],g=n[2],x=n[6],p=n[10],h=n[14],E=n[3],_=n[7],A=n[11],C=n[15],b=r[0],w=r[4],z=r[8],M=r[12],T=r[1],B=r[5],V=r[9],ee=r[13],L=r[2],U=r[6],k=r[10],q=r[14],X=r[3],W=r[7],Z=r[11],Q=r[15];return s[0]=o*b+a*T+l*L+c*X,s[4]=o*w+a*B+l*U+c*W,s[8]=o*z+a*V+l*k+c*Z,s[12]=o*M+a*ee+l*q+c*Q,s[1]=u*b+f*T+d*L+m*X,s[5]=u*w+f*B+d*U+m*W,s[9]=u*z+f*V+d*k+m*Z,s[13]=u*M+f*ee+d*q+m*Q,s[2]=g*b+x*T+p*L+h*X,s[6]=g*w+x*B+p*U+h*W,s[10]=g*z+x*V+p*k+h*Z,s[14]=g*M+x*ee+p*q+h*Q,s[3]=E*b+_*T+A*L+C*X,s[7]=E*w+_*B+A*U+C*W,s[11]=E*z+_*V+A*k+C*Z,s[15]=E*M+_*ee+A*q+C*Q,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],n=e[4],r=e[8],s=e[12],o=e[1],a=e[5],l=e[9],c=e[13],u=e[2],f=e[6],d=e[10],m=e[14],g=e[3],x=e[7],p=e[11],h=e[15];return g*(+s*l*f-r*c*f-s*a*d+n*c*d+r*a*m-n*l*m)+x*(+t*l*m-t*c*d+s*o*d-r*o*m+r*c*u-s*l*u)+p*(+t*c*f-t*a*m-s*o*f+n*o*m+s*a*u-n*c*u)+h*(-r*a*u-t*l*f+t*a*d+r*o*f-n*o*d+n*l*u)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,n){const r=this.elements;return e.isVector3?(r[12]=e.x,r[13]=e.y,r[14]=e.z):(r[12]=e,r[13]=t,r[14]=n),this}invert(){const e=this.elements,t=e[0],n=e[1],r=e[2],s=e[3],o=e[4],a=e[5],l=e[6],c=e[7],u=e[8],f=e[9],d=e[10],m=e[11],g=e[12],x=e[13],p=e[14],h=e[15],E=f*p*c-x*d*c+x*l*m-a*p*m-f*l*h+a*d*h,_=g*d*c-u*p*c-g*l*m+o*p*m+u*l*h-o*d*h,A=u*x*c-g*f*c+g*a*m-o*x*m-u*a*h+o*f*h,C=g*f*l-u*x*l-g*a*d+o*x*d+u*a*p-o*f*p,b=t*E+n*_+r*A+s*C;if(b===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const w=1/b;return e[0]=E*w,e[1]=(x*d*s-f*p*s-x*r*m+n*p*m+f*r*h-n*d*h)*w,e[2]=(a*p*s-x*l*s+x*r*c-n*p*c-a*r*h+n*l*h)*w,e[3]=(f*l*s-a*d*s-f*r*c+n*d*c+a*r*m-n*l*m)*w,e[4]=_*w,e[5]=(u*p*s-g*d*s+g*r*m-t*p*m-u*r*h+t*d*h)*w,e[6]=(g*l*s-o*p*s-g*r*c+t*p*c+o*r*h-t*l*h)*w,e[7]=(o*d*s-u*l*s+u*r*c-t*d*c-o*r*m+t*l*m)*w,e[8]=A*w,e[9]=(g*f*s-u*x*s-g*n*m+t*x*m+u*n*h-t*f*h)*w,e[10]=(o*x*s-g*a*s+g*n*c-t*x*c-o*n*h+t*a*h)*w,e[11]=(u*a*s-o*f*s-u*n*c+t*f*c+o*n*m-t*a*m)*w,e[12]=C*w,e[13]=(u*x*r-g*f*r+g*n*d-t*x*d-u*n*p+t*f*p)*w,e[14]=(g*a*r-o*x*r-g*n*l+t*x*l+o*n*p-t*a*p)*w,e[15]=(o*f*r-u*a*r+u*n*l-t*f*l-o*n*d+t*a*d)*w,this}scale(e){const t=this.elements,n=e.x,r=e.y,s=e.z;return t[0]*=n,t[4]*=r,t[8]*=s,t[1]*=n,t[5]*=r,t[9]*=s,t[2]*=n,t[6]*=r,t[10]*=s,t[3]*=n,t[7]*=r,t[11]*=s,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],r=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,n,r))}makeTranslation(e,t,n){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,n,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),n=Math.sin(e);return this.set(1,0,0,0,0,t,-n,0,0,n,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,0,n,0,0,1,0,0,-n,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,0,n,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const n=Math.cos(t),r=Math.sin(t),s=1-n,o=e.x,a=e.y,l=e.z,c=s*o,u=s*a;return this.set(c*o+n,c*a-r*l,c*l+r*a,0,c*a+r*l,u*a+n,u*l-r*o,0,c*l-r*a,u*l+r*o,s*l*l+n,0,0,0,0,1),this}makeScale(e,t,n){return this.set(e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1),this}makeShear(e,t,n,r,s,o){return this.set(1,n,s,0,e,1,o,0,t,r,1,0,0,0,0,1),this}compose(e,t,n){const r=this.elements,s=t._x,o=t._y,a=t._z,l=t._w,c=s+s,u=o+o,f=a+a,d=s*c,m=s*u,g=s*f,x=o*u,p=o*f,h=a*f,E=l*c,_=l*u,A=l*f,C=n.x,b=n.y,w=n.z;return r[0]=(1-(x+h))*C,r[1]=(m+A)*C,r[2]=(g-_)*C,r[3]=0,r[4]=(m-A)*b,r[5]=(1-(d+h))*b,r[6]=(p+E)*b,r[7]=0,r[8]=(g+_)*w,r[9]=(p-E)*w,r[10]=(1-(d+x))*w,r[11]=0,r[12]=e.x,r[13]=e.y,r[14]=e.z,r[15]=1,this}decompose(e,t,n){const r=this.elements;let s=Dn.set(r[0],r[1],r[2]).length();const o=Dn.set(r[4],r[5],r[6]).length(),a=Dn.set(r[8],r[9],r[10]).length();this.determinant()<0&&(s=-s),e.x=r[12],e.y=r[13],e.z=r[14],Dt.copy(this);const c=1/s,u=1/o,f=1/a;return Dt.elements[0]*=c,Dt.elements[1]*=c,Dt.elements[2]*=c,Dt.elements[4]*=u,Dt.elements[5]*=u,Dt.elements[6]*=u,Dt.elements[8]*=f,Dt.elements[9]*=f,Dt.elements[10]*=f,t.setFromRotationMatrix(Dt),n.x=s,n.y=o,n.z=a,this}makePerspective(e,t,n,r,s,o,a=Zt){const l=this.elements,c=2*s/(t-e),u=2*s/(n-r),f=(t+e)/(t-e),d=(n+r)/(n-r);let m,g;if(a===Zt)m=-(o+s)/(o-s),g=-2*o*s/(o-s);else if(a===$i)m=-o/(o-s),g=-o*s/(o-s);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return l[0]=c,l[4]=0,l[8]=f,l[12]=0,l[1]=0,l[5]=u,l[9]=d,l[13]=0,l[2]=0,l[6]=0,l[10]=m,l[14]=g,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(e,t,n,r,s,o,a=Zt){const l=this.elements,c=1/(t-e),u=1/(n-r),f=1/(o-s),d=(t+e)*c,m=(n+r)*u;let g,x;if(a===Zt)g=(o+s)*f,x=-2*f;else if(a===$i)g=s*f,x=-1*f;else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return l[0]=2*c,l[4]=0,l[8]=0,l[12]=-d,l[1]=0,l[5]=2*u,l[9]=0,l[13]=-m,l[2]=0,l[6]=0,l[10]=x,l[14]=-g,l[3]=0,l[7]=0,l[11]=0,l[15]=1,this}equals(e){const t=this.elements,n=e.elements;for(let r=0;r<16;r++)if(t[r]!==n[r])return!1;return!0}fromArray(e,t=0){for(let n=0;n<16;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){const n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e[t+9]=n[9],e[t+10]=n[10],e[t+11]=n[11],e[t+12]=n[12],e[t+13]=n[13],e[t+14]=n[14],e[t+15]=n[15],e}}const Dn=new P,Dt=new $e,$l=new P(0,0,0),Jl=new P(1,1,1),tn=new P,bi=new P,yt=new P,Qs=new $e,ea=new _i;class nr{constructor(e=0,t=0,n=0,r=nr.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=n,this._order=r}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,n,r=this._order){return this._x=e,this._y=t,this._z=n,this._order=r,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,n=!0){const r=e.elements,s=r[0],o=r[4],a=r[8],l=r[1],c=r[5],u=r[9],f=r[2],d=r[6],m=r[10];switch(t){case"XYZ":this._y=Math.asin(ht(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-u,m),this._z=Math.atan2(-o,s)):(this._x=Math.atan2(d,c),this._z=0);break;case"YXZ":this._x=Math.asin(-ht(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(a,m),this._z=Math.atan2(l,c)):(this._y=Math.atan2(-f,s),this._z=0);break;case"ZXY":this._x=Math.asin(ht(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-f,m),this._z=Math.atan2(-o,c)):(this._y=0,this._z=Math.atan2(l,s));break;case"ZYX":this._y=Math.asin(-ht(f,-1,1)),Math.abs(f)<.9999999?(this._x=Math.atan2(d,m),this._z=Math.atan2(l,s)):(this._x=0,this._z=Math.atan2(-o,c));break;case"YZX":this._z=Math.asin(ht(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-u,c),this._y=Math.atan2(-f,s)):(this._x=0,this._y=Math.atan2(a,m));break;case"XZY":this._z=Math.asin(-ht(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(d,c),this._y=Math.atan2(a,s)):(this._x=Math.atan2(-u,m),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,n===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,n){return Qs.makeRotationFromQuaternion(e),this.setFromRotationMatrix(Qs,t,n)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return ea.setFromEuler(this),this.setFromQuaternion(ea,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}nr.DEFAULT_ORDER="XYZ";class ns{constructor(){this.mask=1}set(e){this.mask=(1<>>0}enable(e){this.mask|=1<1){for(let t=0;t1){for(let n=0;n0&&(r.userData=this.userData),r.layers=this.layers.mask,r.matrix=this.matrix.toArray(),r.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(r.matrixAutoUpdate=!1),this.isInstancedMesh&&(r.type="InstancedMesh",r.count=this.count,r.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(r.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(r.type="BatchedMesh",r.perObjectFrustumCulled=this.perObjectFrustumCulled,r.sortObjects=this.sortObjects,r.drawRanges=this._drawRanges,r.reservedRanges=this._reservedRanges,r.visibility=this._visibility,r.active=this._active,r.bounds=this._bounds.map(a=>({boxInitialized:a.boxInitialized,boxMin:a.box.min.toArray(),boxMax:a.box.max.toArray(),sphereInitialized:a.sphereInitialized,sphereRadius:a.sphere.radius,sphereCenter:a.sphere.center.toArray()})),r.maxGeometryCount=this._maxGeometryCount,r.maxVertexCount=this._maxVertexCount,r.maxIndexCount=this._maxIndexCount,r.geometryInitialized=this._geometryInitialized,r.geometryCount=this._geometryCount,r.matricesTexture=this._matricesTexture.toJSON(e),this.boundingSphere!==null&&(r.boundingSphere={center:r.boundingSphere.center.toArray(),radius:r.boundingSphere.radius}),this.boundingBox!==null&&(r.boundingBox={min:r.boundingBox.min.toArray(),max:r.boundingBox.max.toArray()}));function s(a,l){return a[l.uuid]===void 0&&(a[l.uuid]=l.toJSON(e)),l.uuid}if(this.isScene)this.background&&(this.background.isColor?r.background=this.background.toJSON():this.background.isTexture&&(r.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(r.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){r.geometry=s(e.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const l=a.shapes;if(Array.isArray(l))for(let c=0,u=l.length;c0){r.children=[];for(let a=0;a0){r.animations=[];for(let a=0;a0&&(n.geometries=a),l.length>0&&(n.materials=l),c.length>0&&(n.textures=c),u.length>0&&(n.images=u),f.length>0&&(n.shapes=f),d.length>0&&(n.skeletons=d),m.length>0&&(n.animations=m),g.length>0&&(n.nodes=g)}return n.object=r,n;function o(a){const l=[];for(const c in a){const u=a[c];delete u.metadata,l.push(u)}return l}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let n=0;n0?r.multiplyScalar(1/Math.sqrt(s)):r.set(0,0,0)}static getBarycoord(e,t,n,r,s){Ut.subVectors(r,t),qt.subVectors(n,t),yr.subVectors(e,t);const o=Ut.dot(Ut),a=Ut.dot(qt),l=Ut.dot(yr),c=qt.dot(qt),u=qt.dot(yr),f=o*c-a*a;if(f===0)return s.set(0,0,0),null;const d=1/f,m=(c*l-a*u)*d,g=(o*u-a*l)*d;return s.set(1-m-g,g,m)}static containsPoint(e,t,n,r){return this.getBarycoord(e,t,n,r,Yt)===null?!1:Yt.x>=0&&Yt.y>=0&&Yt.x+Yt.y<=1}static getUV(e,t,n,r,s,o,a,l){return Ri===!1&&(console.warn("THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation()."),Ri=!0),this.getInterpolation(e,t,n,r,s,o,a,l)}static getInterpolation(e,t,n,r,s,o,a,l){return this.getBarycoord(e,t,n,r,Yt)===null?(l.x=0,l.y=0,"z"in l&&(l.z=0),"w"in l&&(l.w=0),null):(l.setScalar(0),l.addScaledVector(s,Yt.x),l.addScaledVector(o,Yt.y),l.addScaledVector(a,Yt.z),l)}static isFrontFacing(e,t,n,r){return Ut.subVectors(n,t),qt.subVectors(e,t),Ut.cross(qt).dot(r)<0}set(e,t,n){return this.a.copy(e),this.b.copy(t),this.c.copy(n),this}setFromPointsAndIndices(e,t,n,r){return this.a.copy(e[t]),this.b.copy(e[n]),this.c.copy(e[r]),this}setFromAttributeAndIndices(e,t,n,r){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,n),this.c.fromBufferAttribute(e,r),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return Ut.subVectors(this.c,this.b),qt.subVectors(this.a,this.b),Ut.cross(qt).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return It.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,t){return It.getBarycoord(e,this.a,this.b,this.c,t)}getUV(e,t,n,r,s){return Ri===!1&&(console.warn("THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation()."),Ri=!0),It.getInterpolation(e,this.a,this.b,this.c,t,n,r,s)}getInterpolation(e,t,n,r,s){return It.getInterpolation(e,this.a,this.b,this.c,t,n,r,s)}containsPoint(e){return It.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return It.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){const n=this.a,r=this.b,s=this.c;let o,a;In.subVectors(r,n),Nn.subVectors(s,n),Tr.subVectors(e,n);const l=In.dot(Tr),c=Nn.dot(Tr);if(l<=0&&c<=0)return t.copy(n);Ar.subVectors(e,r);const u=In.dot(Ar),f=Nn.dot(Ar);if(u>=0&&f<=u)return t.copy(r);const d=l*f-u*c;if(d<=0&&l>=0&&u<=0)return o=l/(l-u),t.copy(n).addScaledVector(In,o);br.subVectors(e,s);const m=In.dot(br),g=Nn.dot(br);if(g>=0&&m<=g)return t.copy(s);const x=m*c-l*g;if(x<=0&&c>=0&&g<=0)return a=c/(c-g),t.copy(n).addScaledVector(Nn,a);const p=u*g-m*f;if(p<=0&&f-u>=0&&m-g>=0)return sa.subVectors(s,r),a=(f-u)/(f-u+(m-g)),t.copy(r).addScaledVector(sa,a);const h=1/(p+x+d);return o=x*h,a=d*h,t.copy(n).addScaledVector(In,o).addScaledVector(Nn,a)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}}const so={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},nn={h:0,s:0,l:0},Ci={h:0,s:0,l:0};function wr(i,e,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?i+(e-i)*6*t:t<1/2?e:t<2/3?i+(e-i)*6*(2/3-t):i}class Ge{constructor(e,t,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,n)}set(e,t,n){if(t===void 0&&n===void 0){const r=e;r&&r.isColor?this.copy(r):typeof r=="number"?this.setHex(r):typeof r=="string"&&this.setStyle(r)}else this.setRGB(e,t,n);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=ct){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,We.toWorkingColorSpace(this,t),this}setRGB(e,t,n,r=We.workingColorSpace){return this.r=e,this.g=t,this.b=n,We.toWorkingColorSpace(this,r),this}setHSL(e,t,n,r=We.workingColorSpace){if(e=es(e,1),t=ht(t,0,1),n=ht(n,0,1),t===0)this.r=this.g=this.b=n;else{const s=n<=.5?n*(1+t):n+t-n*t,o=2*n-s;this.r=wr(o,s,e+1/3),this.g=wr(o,s,e),this.b=wr(o,s,e-1/3)}return We.toWorkingColorSpace(this,r),this}setStyle(e,t=ct){function n(s){s!==void 0&&parseFloat(s)<1&&console.warn("THREE.Color: Alpha component of "+e+" will be ignored.")}let r;if(r=/^(\w+)\(([^\)]*)\)/.exec(e)){let s;const o=r[1],a=r[2];switch(o){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setRGB(Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,t);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setRGB(Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,t);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,t);break;default:console.warn("THREE.Color: Unknown color model "+e)}}else if(r=/^\#([A-Fa-f\d]+)$/.exec(e)){const s=r[1],o=s.length;if(o===3)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,t);if(o===6)return this.setHex(parseInt(s,16),t);console.warn("THREE.Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=ct){const n=so[e.toLowerCase()];return n!==void 0?this.setHex(n,t):console.warn("THREE.Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=jn(e.r),this.g=jn(e.g),this.b=jn(e.b),this}copyLinearToSRGB(e){return this.r=mr(e.r),this.g=mr(e.g),this.b=mr(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=ct){return We.fromWorkingColorSpace(pt.copy(this),e),Math.round(ht(pt.r*255,0,255))*65536+Math.round(ht(pt.g*255,0,255))*256+Math.round(ht(pt.b*255,0,255))}getHexString(e=ct){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=We.workingColorSpace){We.fromWorkingColorSpace(pt.copy(this),t);const n=pt.r,r=pt.g,s=pt.b,o=Math.max(n,r,s),a=Math.min(n,r,s);let l,c;const u=(a+o)/2;if(a===o)l=0,c=0;else{const f=o-a;switch(c=u<=.5?f/(o+a):f/(2-o-a),o){case n:l=(r-s)/f+(r0!=e>0&&this.version++,this._alphaTest=e}onBuild(){}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(const t in e){const n=e[t];if(n===void 0){console.warn(`THREE.Material: parameter '${t}' has value of undefined.`);continue}const r=this[t];if(r===void 0){console.warn(`THREE.Material: '${t}' is not a property of THREE.${this.type}.`);continue}r&&r.isColor?r.set(n):r&&r.isVector3&&n&&n.isVector3?r.copy(n):this[t]=n}}toJSON(e){const t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{}});const n={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),this.roughness!==void 0&&(n.roughness=this.roughness),this.metalness!==void 0&&(n.metalness=this.metalness),this.sheen!==void 0&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),this.emissiveIntensity&&this.emissiveIntensity!==1&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(n.shininess=this.shininess),this.clearcoat!==void 0&&(n.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.iridescence!==void 0&&(n.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(n.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(n.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(e).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(e).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(e).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(e).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(e).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(n.combine=this.combine)),this.envMapIntensity!==void 0&&(n.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(n.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(n.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(n.size=this.size),this.shadowSide!==null&&(n.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(n.sizeAttenuation=this.sizeAttenuation),this.blending!==Yn&&(n.blending=this.blending),this.side!==cn&&(n.side=this.side),this.vertexColors===!0&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),this.transparent===!0&&(n.transparent=!0),this.blendSrc!==zr&&(n.blendSrc=this.blendSrc),this.blendDst!==Gr&&(n.blendDst=this.blendDst),this.blendEquation!==vn&&(n.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(n.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(n.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(n.blendAlpha=this.blendAlpha),this.depthFunc!==Yi&&(n.depthFunc=this.depthFunc),this.depthTest===!1&&(n.depthTest=this.depthTest),this.depthWrite===!1&&(n.depthWrite=this.depthWrite),this.colorWrite===!1&&(n.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(n.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==Xs&&(n.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(n.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==wn&&(n.stencilFail=this.stencilFail),this.stencilZFail!==wn&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==wn&&(n.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(n.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(n.rotation=this.rotation),this.polygonOffset===!0&&(n.polygonOffset=!0),this.polygonOffsetFactor!==0&&(n.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(n.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(n.linewidth=this.linewidth),this.dashSize!==void 0&&(n.dashSize=this.dashSize),this.gapSize!==void 0&&(n.gapSize=this.gapSize),this.scale!==void 0&&(n.scale=this.scale),this.dithering===!0&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),this.alphaHash===!0&&(n.alphaHash=!0),this.alphaToCoverage===!0&&(n.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(n.premultipliedAlpha=!0),this.forceSinglePass===!0&&(n.forceSinglePass=!0),this.wireframe===!0&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(n.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(n.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(n.flatShading=!0),this.visible===!1&&(n.visible=!1),this.toneMapped===!1&&(n.toneMapped=!1),this.fog===!1&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData);function r(s){const o=[];for(const a in s){const l=s[a];delete l.metadata,o.push(l)}return o}if(t){const s=r(e.textures),o=r(e.images);s.length>0&&(n.textures=s),o.length>0&&(n.images=o)}return n}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;const t=e.clippingPlanes;let n=null;if(t!==null){const r=t.length;n=new Array(r);for(let s=0;s!==r;++s)n[s]=t[s].clone()}return this.clippingPlanes=n,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){e===!0&&this.version++}}class ao extends bn{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new Ge(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=Zr,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}}const tt=new P,Li=new ze;class Bt{constructor(e,t,n=!1){if(Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=n,this.usage=qs,this._updateRange={offset:0,count:-1},this.updateRanges=[],this.gpuType=sn,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}get updateRange(){return console.warn("THREE.BufferAttribute: updateRange() is deprecated and will be removed in r169. Use addUpdateRange() instead."),this._updateRange}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,n){e*=this.itemSize,n*=t.itemSize;for(let r=0,s=this.itemSize;r0&&(e.userData=this.userData),this.parameters!==void 0){const l=this.parameters;for(const c in l)l[c]!==void 0&&(e[c]=l[c]);return e}e.data={attributes:{}};const t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});const n=this.attributes;for(const l in n){const c=n[l];e.data.attributes[l]=c.toJSON(e.data)}const r={};let s=!1;for(const l in this.morphAttributes){const c=this.morphAttributes[l],u=[];for(let f=0,d=c.length;f0&&(r[l]=u,s=!0)}s&&(e.data.morphAttributes=r,e.data.morphTargetsRelative=this.morphTargetsRelative);const o=this.groups;o.length>0&&(e.data.groups=JSON.parse(JSON.stringify(o)));const a=this.boundingSphere;return a!==null&&(e.data.boundingSphere={center:a.center.toArray(),radius:a.radius}),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const t={};this.name=e.name;const n=e.index;n!==null&&this.setIndex(n.clone(t));const r=e.attributes;for(const c in r){const u=r[c];this.setAttribute(c,u.clone(t))}const s=e.morphAttributes;for(const c in s){const u=[],f=s[c];for(let d=0,m=f.length;d0){const r=t[n[0]];if(r!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=r.length;s(e.far-e.near)**2))&&(aa.copy(s).invert(),pn.copy(e.ray).applyMatrix4(aa),!(n.boundingBox!==null&&pn.intersectsBox(n.boundingBox)===!1)&&this._computeIntersections(e,t,pn)))}_computeIntersections(e,t,n){let r;const s=this.geometry,o=this.material,a=s.index,l=s.attributes.position,c=s.attributes.uv,u=s.attributes.uv1,f=s.attributes.normal,d=s.groups,m=s.drawRange;if(a!==null)if(Array.isArray(o))for(let g=0,x=d.length;gt.far?null:{distance:c,point:Oi.clone(),object:i}}function Bi(i,e,t,n,r,s,o,a,l,c){i.getVertexPosition(a,On),i.getVertexPosition(l,Bn),i.getVertexPosition(c,zn);const u=ac(i,e,t,n,On,Bn,zn,Fi);if(u){r&&(Ui.fromBufferAttribute(r,a),Ii.fromBufferAttribute(r,l),Ni.fromBufferAttribute(r,c),u.uv=It.getInterpolation(Fi,On,Bn,zn,Ui,Ii,Ni,new ze)),s&&(Ui.fromBufferAttribute(s,a),Ii.fromBufferAttribute(s,l),Ni.fromBufferAttribute(s,c),u.uv1=It.getInterpolation(Fi,On,Bn,zn,Ui,Ii,Ni,new ze),u.uv2=u.uv1),o&&(la.fromBufferAttribute(o,a),ca.fromBufferAttribute(o,l),ha.fromBufferAttribute(o,c),u.normal=It.getInterpolation(Fi,On,Bn,zn,la,ca,ha,new P),u.normal.dot(n.direction)>0&&u.normal.multiplyScalar(-1));const f={a,b:l,c,normal:new P,materialIndex:0};It.getNormal(On,Bn,zn,f.normal),u.face=f}return u}class gi extends Lt{constructor(e=1,t=1,n=1,r=1,s=1,o=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:t,depth:n,widthSegments:r,heightSegments:s,depthSegments:o};const a=this;r=Math.floor(r),s=Math.floor(s),o=Math.floor(o);const l=[],c=[],u=[],f=[];let d=0,m=0;g("z","y","x",-1,-1,n,t,e,o,s,0),g("z","y","x",1,-1,n,t,-e,o,s,1),g("x","z","y",1,1,e,n,t,r,o,2),g("x","z","y",1,-1,e,n,-t,r,o,3),g("x","y","z",1,-1,e,t,n,r,s,4),g("x","y","z",-1,-1,e,t,-n,r,s,5),this.setIndex(l),this.setAttribute("position",new nt(c,3)),this.setAttribute("normal",new nt(u,3)),this.setAttribute("uv",new nt(f,2));function g(x,p,h,E,_,A,C,b,w,z,M){const T=A/w,B=C/z,V=A/2,ee=C/2,L=b/2,U=w+1,k=z+1;let q=0,X=0;const W=new P;for(let Z=0;Z0?1:-1,u.push(W.x,W.y,W.z),f.push(le/w),f.push(1-Z/z),q+=1}}for(let Z=0;Z0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;const n={};for(const r in this.extensions)this.extensions[r]===!0&&(n[r]=!0);return Object.keys(n).length>0&&(t.extensions=n),t}}class ho extends ut{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new $e,this.projectionMatrix=new $e,this.projectionMatrixInverse=new $e,this.coordinateSystem=Zt}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return new this.constructor().copy(this)}}class Nt extends ho{constructor(e=50,t=1,n=.1,r=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=e,this.zoom=1,this.near=n,this.far=r,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=e.view===null?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){const t=.5*this.getFilmHeight()/e;this.fov=mi*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){const e=Math.tan(hi*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return mi*2*Math.atan(Math.tan(hi*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}setViewOffset(e,t,n,r,s,o){this.aspect=e/t,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=n,this.view.offsetY=r,this.view.width=s,this.view.height=o,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=this.near;let t=e*Math.tan(hi*.5*this.fov)/this.zoom,n=2*t,r=this.aspect*n,s=-.5*r;const o=this.view;if(this.view!==null&&this.view.enabled){const l=o.fullWidth,c=o.fullHeight;s+=o.offsetX*r/l,t-=o.offsetY*n/c,r*=o.width/l,n*=o.height/c}const a=this.filmOffset;a!==0&&(s+=e*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(s,s+r,t,t-n,e,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.fov=this.fov,t.object.zoom=this.zoom,t.object.near=this.near,t.object.far=this.far,t.object.focus=this.focus,t.object.aspect=this.aspect,this.view!==null&&(t.object.view=Object.assign({},this.view)),t.object.filmGauge=this.filmGauge,t.object.filmOffset=this.filmOffset,t}}const Gn=-90,Hn=1;class uc extends ut{constructor(e,t,n){super(),this.type="CubeCamera",this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;const r=new Nt(Gn,Hn,e,t);r.layers=this.layers,this.add(r);const s=new Nt(Gn,Hn,e,t);s.layers=this.layers,this.add(s);const o=new Nt(Gn,Hn,e,t);o.layers=this.layers,this.add(o);const a=new Nt(Gn,Hn,e,t);a.layers=this.layers,this.add(a);const l=new Nt(Gn,Hn,e,t);l.layers=this.layers,this.add(l);const c=new Nt(Gn,Hn,e,t);c.layers=this.layers,this.add(c)}updateCoordinateSystem(){const e=this.coordinateSystem,t=this.children.concat(),[n,r,s,o,a,l]=t;for(const c of t)this.remove(c);if(e===Zt)n.up.set(0,1,0),n.lookAt(1,0,0),r.up.set(0,1,0),r.lookAt(-1,0,0),s.up.set(0,0,-1),s.lookAt(0,1,0),o.up.set(0,0,1),o.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),l.up.set(0,1,0),l.lookAt(0,0,-1);else if(e===$i)n.up.set(0,-1,0),n.lookAt(-1,0,0),r.up.set(0,-1,0),r.lookAt(1,0,0),s.up.set(0,0,1),s.lookAt(0,1,0),o.up.set(0,0,-1),o.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),l.up.set(0,-1,0),l.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+e);for(const c of t)this.add(c),c.updateMatrixWorld()}update(e,t){this.parent===null&&this.updateMatrixWorld();const{renderTarget:n,activeMipmapLevel:r}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());const[s,o,a,l,c,u]=this.children,f=e.getRenderTarget(),d=e.getActiveCubeFace(),m=e.getActiveMipmapLevel(),g=e.xr.enabled;e.xr.enabled=!1;const x=n.texture.generateMipmaps;n.texture.generateMipmaps=!1,e.setRenderTarget(n,0,r),e.render(t,s),e.setRenderTarget(n,1,r),e.render(t,o),e.setRenderTarget(n,2,r),e.render(t,a),e.setRenderTarget(n,3,r),e.render(t,l),e.setRenderTarget(n,4,r),e.render(t,c),n.texture.generateMipmaps=x,e.setRenderTarget(n,5,r),e.render(t,u),e.setRenderTarget(f,d,m),e.xr.enabled=g,n.texture.needsPMREMUpdate=!0}}class uo extends At{constructor(e,t,n,r,s,o,a,l,c,u){e=e!==void 0?e:[],t=t!==void 0?t:Kn,super(e,t,n,r,s,o,a,l,c,u),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}}class fc extends yn{constructor(e=1,t={}){super(e,e,t),this.isWebGLCubeRenderTarget=!0;const n={width:e,height:e,depth:1},r=[n,n,n,n,n,n];t.encoding!==void 0&&(fi("THREE.WebGLCubeRenderTarget: option.encoding has been replaced by option.colorSpace."),t.colorSpace=t.encoding===En?ct:Ct),this.texture=new uo(r,t.mapping,t.wrapS,t.wrapT,t.magFilter,t.minFilter,t.format,t.type,t.anisotropy,t.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=t.generateMipmaps!==void 0?t.generateMipmaps:!1,this.texture.minFilter=t.minFilter!==void 0?t.minFilter:Rt}fromEquirectangularTexture(e,t){this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const n={uniforms:{tEquirect:{value:null}},vertexShader:` + + varying vec3 vWorldDirection; + + vec3 transformDirection( in vec3 dir, in mat4 matrix ) { + + return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz ); + + } + + void main() { + + vWorldDirection = transformDirection( position, modelMatrix ); + + #include + #include + + } + `,fragmentShader:` + + uniform sampler2D tEquirect; + + varying vec3 vWorldDirection; + + #include + + void main() { + + vec3 direction = normalize( vWorldDirection ); + + vec2 sampleUV = equirectUv( direction ); + + gl_FragColor = texture2D( tEquirect, sampleUV ); + + } + `},r=new gi(5,5,5),s=new Tn({name:"CubemapFromEquirect",uniforms:Jn(n.uniforms),vertexShader:n.vertexShader,fragmentShader:n.fragmentShader,side:St,blending:an});s.uniforms.tEquirect.value=t;const o=new Ht(r,s),a=t.minFilter;return t.minFilter===di&&(t.minFilter=Rt),new uc(1,10,this).update(e,o),t.minFilter=a,o.geometry.dispose(),o.material.dispose(),this}clear(e,t,n,r){const s=e.getRenderTarget();for(let o=0;o<6;o++)e.setRenderTarget(this,o),e.clear(t,n,r);e.setRenderTarget(s)}}const Lr=new P,dc=new P,pc=new Oe;class _n{constructor(e=new P(1,0,0),t=0){this.isPlane=!0,this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,n,r){return this.normal.set(e,t,n),this.constant=r,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,n){const r=Lr.subVectors(n,t).cross(dc.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(r,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){const e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t){const n=e.delta(Lr),r=this.normal.dot(n);if(r===0)return this.distanceToPoint(e.start)===0?t.copy(e.start):null;const s=-(e.start.dot(this.normal)+this.constant)/r;return s<0||s>1?null:t.copy(e.start).addScaledVector(n,s)}intersectsLine(e){const t=this.distanceToPoint(e.start),n=this.distanceToPoint(e.end);return t<0&&n>0||n<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){const n=t||pc.getNormalMatrix(e),r=this.coplanarPoint(Lr).applyMatrix4(e),s=this.normal.applyMatrix3(n).normalize();return this.constant=-r.dot(s),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return new this.constructor().copy(this)}}const mn=new ti,zi=new P;class is{constructor(e=new _n,t=new _n,n=new _n,r=new _n,s=new _n,o=new _n){this.planes=[e,t,n,r,s,o]}set(e,t,n,r,s,o){const a=this.planes;return a[0].copy(e),a[1].copy(t),a[2].copy(n),a[3].copy(r),a[4].copy(s),a[5].copy(o),this}copy(e){const t=this.planes;for(let n=0;n<6;n++)t[n].copy(e.planes[n]);return this}setFromProjectionMatrix(e,t=Zt){const n=this.planes,r=e.elements,s=r[0],o=r[1],a=r[2],l=r[3],c=r[4],u=r[5],f=r[6],d=r[7],m=r[8],g=r[9],x=r[10],p=r[11],h=r[12],E=r[13],_=r[14],A=r[15];if(n[0].setComponents(l-s,d-c,p-m,A-h).normalize(),n[1].setComponents(l+s,d+c,p+m,A+h).normalize(),n[2].setComponents(l+o,d+u,p+g,A+E).normalize(),n[3].setComponents(l-o,d-u,p-g,A-E).normalize(),n[4].setComponents(l-a,d-f,p-x,A-_).normalize(),t===Zt)n[5].setComponents(l+a,d+f,p+x,A+_).normalize();else if(t===$i)n[5].setComponents(a,f,x,_).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+t);return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),mn.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{const t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),mn.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(mn)}intersectsSprite(e){return mn.center.set(0,0,0),mn.radius=.7071067811865476,mn.applyMatrix4(e.matrixWorld),this.intersectsSphere(mn)}intersectsSphere(e){const t=this.planes,n=e.center,r=-e.radius;for(let s=0;s<6;s++)if(t[s].distanceToPoint(n)0?e.max.x:e.min.x,zi.y=r.normal.y>0?e.max.y:e.min.y,zi.z=r.normal.z>0?e.max.z:e.min.z,r.distanceToPoint(zi)<0)return!1}return!0}containsPoint(e){const t=this.planes;for(let n=0;n<6;n++)if(t[n].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}function fo(){let i=null,e=!1,t=null,n=null;function r(s,o){t(s,o),n=i.requestAnimationFrame(r)}return{start:function(){e!==!0&&t!==null&&(n=i.requestAnimationFrame(r),e=!0)},stop:function(){i.cancelAnimationFrame(n),e=!1},setAnimationLoop:function(s){t=s},setContext:function(s){i=s}}}function mc(i,e){const t=e.isWebGL2,n=new WeakMap;function r(c,u){const f=c.array,d=c.usage,m=f.byteLength,g=i.createBuffer();i.bindBuffer(u,g),i.bufferData(u,f,d),c.onUploadCallback();let x;if(f instanceof Float32Array)x=i.FLOAT;else if(f instanceof Uint16Array)if(c.isFloat16BufferAttribute)if(t)x=i.HALF_FLOAT;else throw new Error("THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.");else x=i.UNSIGNED_SHORT;else if(f instanceof Int16Array)x=i.SHORT;else if(f instanceof Uint32Array)x=i.UNSIGNED_INT;else if(f instanceof Int32Array)x=i.INT;else if(f instanceof Int8Array)x=i.BYTE;else if(f instanceof Uint8Array)x=i.UNSIGNED_BYTE;else if(f instanceof Uint8ClampedArray)x=i.UNSIGNED_BYTE;else throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: "+f);return{buffer:g,type:x,bytesPerElement:f.BYTES_PER_ELEMENT,version:c.version,size:m}}function s(c,u,f){const d=u.array,m=u._updateRange,g=u.updateRanges;if(i.bindBuffer(f,c),m.count===-1&&g.length===0&&i.bufferSubData(f,0,d),g.length!==0){for(let x=0,p=g.length;x 0 + vec4 plane; + #pragma unroll_loop_start + for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) { + plane = clippingPlanes[ i ]; + if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard; + } + #pragma unroll_loop_end + #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES + bool clipped = true; + #pragma unroll_loop_start + for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) { + plane = clippingPlanes[ i ]; + clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped; + } + #pragma unroll_loop_end + if ( clipped ) discard; + #endif +#endif`,Dc=`#if NUM_CLIPPING_PLANES > 0 + varying vec3 vClipPosition; + uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ]; +#endif`,Uc=`#if NUM_CLIPPING_PLANES > 0 + varying vec3 vClipPosition; +#endif`,Ic=`#if NUM_CLIPPING_PLANES > 0 + vClipPosition = - mvPosition.xyz; +#endif`,Nc=`#if defined( USE_COLOR_ALPHA ) + diffuseColor *= vColor; +#elif defined( USE_COLOR ) + diffuseColor.rgb *= vColor; +#endif`,Fc=`#if defined( USE_COLOR_ALPHA ) + varying vec4 vColor; +#elif defined( USE_COLOR ) + varying vec3 vColor; +#endif`,Oc=`#if defined( USE_COLOR_ALPHA ) + varying vec4 vColor; +#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) + varying vec3 vColor; +#endif`,Bc=`#if defined( USE_COLOR_ALPHA ) + vColor = vec4( 1.0 ); +#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) + vColor = vec3( 1.0 ); +#endif +#ifdef USE_COLOR + vColor *= color; +#endif +#ifdef USE_INSTANCING_COLOR + vColor.xyz *= instanceColor.xyz; +#endif`,zc=`#define PI 3.141592653589793 +#define PI2 6.283185307179586 +#define PI_HALF 1.5707963267948966 +#define RECIPROCAL_PI 0.3183098861837907 +#define RECIPROCAL_PI2 0.15915494309189535 +#define EPSILON 1e-6 +#ifndef saturate +#define saturate( a ) clamp( a, 0.0, 1.0 ) +#endif +#define whiteComplement( a ) ( 1.0 - saturate( a ) ) +float pow2( const in float x ) { return x*x; } +vec3 pow2( const in vec3 x ) { return x*x; } +float pow3( const in float x ) { return x*x*x; } +float pow4( const in float x ) { float x2 = x*x; return x2*x2; } +float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); } +float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); } +highp float rand( const in vec2 uv ) { + const highp float a = 12.9898, b = 78.233, c = 43758.5453; + highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI ); + return fract( sin( sn ) * c ); +} +#ifdef HIGH_PRECISION + float precisionSafeLength( vec3 v ) { return length( v ); } +#else + float precisionSafeLength( vec3 v ) { + float maxComponent = max3( abs( v ) ); + return length( v / maxComponent ) * maxComponent; + } +#endif +struct IncidentLight { + vec3 color; + vec3 direction; + bool visible; +}; +struct ReflectedLight { + vec3 directDiffuse; + vec3 directSpecular; + vec3 indirectDiffuse; + vec3 indirectSpecular; +}; +#ifdef USE_ALPHAHASH + varying vec3 vPosition; +#endif +vec3 transformDirection( in vec3 dir, in mat4 matrix ) { + return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz ); +} +vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) { + return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz ); +} +mat3 transposeMat3( const in mat3 m ) { + mat3 tmp; + tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x ); + tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y ); + tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z ); + return tmp; +} +float luminance( const in vec3 rgb ) { + const vec3 weights = vec3( 0.2126729, 0.7151522, 0.0721750 ); + return dot( weights, rgb ); +} +bool isPerspectiveMatrix( mat4 m ) { + return m[ 2 ][ 3 ] == - 1.0; +} +vec2 equirectUv( in vec3 dir ) { + float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5; + float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5; + return vec2( u, v ); +} +vec3 BRDF_Lambert( const in vec3 diffuseColor ) { + return RECIPROCAL_PI * diffuseColor; +} +vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) { + float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH ); + return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel ); +} +float F_Schlick( const in float f0, const in float f90, const in float dotVH ) { + float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH ); + return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel ); +} // validated`,Gc=`#ifdef ENVMAP_TYPE_CUBE_UV + #define cubeUV_minMipLevel 4.0 + #define cubeUV_minTileSize 16.0 + float getFace( vec3 direction ) { + vec3 absDirection = abs( direction ); + float face = - 1.0; + if ( absDirection.x > absDirection.z ) { + if ( absDirection.x > absDirection.y ) + face = direction.x > 0.0 ? 0.0 : 3.0; + else + face = direction.y > 0.0 ? 1.0 : 4.0; + } else { + if ( absDirection.z > absDirection.y ) + face = direction.z > 0.0 ? 2.0 : 5.0; + else + face = direction.y > 0.0 ? 1.0 : 4.0; + } + return face; + } + vec2 getUV( vec3 direction, float face ) { + vec2 uv; + if ( face == 0.0 ) { + uv = vec2( direction.z, direction.y ) / abs( direction.x ); + } else if ( face == 1.0 ) { + uv = vec2( - direction.x, - direction.z ) / abs( direction.y ); + } else if ( face == 2.0 ) { + uv = vec2( - direction.x, direction.y ) / abs( direction.z ); + } else if ( face == 3.0 ) { + uv = vec2( - direction.z, direction.y ) / abs( direction.x ); + } else if ( face == 4.0 ) { + uv = vec2( - direction.x, direction.z ) / abs( direction.y ); + } else { + uv = vec2( direction.x, direction.y ) / abs( direction.z ); + } + return 0.5 * ( uv + 1.0 ); + } + vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) { + float face = getFace( direction ); + float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 ); + mipInt = max( mipInt, cubeUV_minMipLevel ); + float faceSize = exp2( mipInt ); + highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0; + if ( face > 2.0 ) { + uv.y += faceSize; + face -= 3.0; + } + uv.x += face * faceSize; + uv.x += filterInt * 3.0 * cubeUV_minTileSize; + uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize ); + uv.x *= CUBEUV_TEXEL_WIDTH; + uv.y *= CUBEUV_TEXEL_HEIGHT; + #ifdef texture2DGradEXT + return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb; + #else + return texture2D( envMap, uv ).rgb; + #endif + } + #define cubeUV_r0 1.0 + #define cubeUV_m0 - 2.0 + #define cubeUV_r1 0.8 + #define cubeUV_m1 - 1.0 + #define cubeUV_r4 0.4 + #define cubeUV_m4 2.0 + #define cubeUV_r5 0.305 + #define cubeUV_m5 3.0 + #define cubeUV_r6 0.21 + #define cubeUV_m6 4.0 + float roughnessToMip( float roughness ) { + float mip = 0.0; + if ( roughness >= cubeUV_r1 ) { + mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0; + } else if ( roughness >= cubeUV_r4 ) { + mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1; + } else if ( roughness >= cubeUV_r5 ) { + mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4; + } else if ( roughness >= cubeUV_r6 ) { + mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5; + } else { + mip = - 2.0 * log2( 1.16 * roughness ); } + return mip; + } + vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) { + float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP ); + float mipF = fract( mip ); + float mipInt = floor( mip ); + vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt ); + if ( mipF == 0.0 ) { + return vec4( color0, 1.0 ); + } else { + vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 ); + return vec4( mix( color0, color1, mipF ), 1.0 ); + } + } +#endif`,Hc=`vec3 transformedNormal = objectNormal; +#ifdef USE_TANGENT + vec3 transformedTangent = objectTangent; +#endif +#ifdef USE_BATCHING + mat3 bm = mat3( batchingMatrix ); + transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) ); + transformedNormal = bm * transformedNormal; + #ifdef USE_TANGENT + transformedTangent = bm * transformedTangent; + #endif +#endif +#ifdef USE_INSTANCING + mat3 im = mat3( instanceMatrix ); + transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) ); + transformedNormal = im * transformedNormal; + #ifdef USE_TANGENT + transformedTangent = im * transformedTangent; + #endif +#endif +transformedNormal = normalMatrix * transformedNormal; +#ifdef FLIP_SIDED + transformedNormal = - transformedNormal; +#endif +#ifdef USE_TANGENT + transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz; + #ifdef FLIP_SIDED + transformedTangent = - transformedTangent; + #endif +#endif`,Vc=`#ifdef USE_DISPLACEMENTMAP + uniform sampler2D displacementMap; + uniform float displacementScale; + uniform float displacementBias; +#endif`,kc=`#ifdef USE_DISPLACEMENTMAP + transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias ); +#endif`,Wc=`#ifdef USE_EMISSIVEMAP + vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv ); + totalEmissiveRadiance *= emissiveColor.rgb; +#endif`,Xc=`#ifdef USE_EMISSIVEMAP + uniform sampler2D emissiveMap; +#endif`,qc="gl_FragColor = linearToOutputTexel( gl_FragColor );",Yc=` +const mat3 LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = mat3( + vec3( 0.8224621, 0.177538, 0.0 ), + vec3( 0.0331941, 0.9668058, 0.0 ), + vec3( 0.0170827, 0.0723974, 0.9105199 ) +); +const mat3 LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = mat3( + vec3( 1.2249401, - 0.2249404, 0.0 ), + vec3( - 0.0420569, 1.0420571, 0.0 ), + vec3( - 0.0196376, - 0.0786361, 1.0982735 ) +); +vec4 LinearSRGBToLinearDisplayP3( in vec4 value ) { + return vec4( value.rgb * LINEAR_SRGB_TO_LINEAR_DISPLAY_P3, value.a ); +} +vec4 LinearDisplayP3ToLinearSRGB( in vec4 value ) { + return vec4( value.rgb * LINEAR_DISPLAY_P3_TO_LINEAR_SRGB, value.a ); +} +vec4 LinearTransferOETF( in vec4 value ) { + return value; +} +vec4 sRGBTransferOETF( in vec4 value ) { + return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a ); +} +vec4 LinearToLinear( in vec4 value ) { + return value; +} +vec4 LinearTosRGB( in vec4 value ) { + return sRGBTransferOETF( value ); +}`,jc=`#ifdef USE_ENVMAP + #ifdef ENV_WORLDPOS + vec3 cameraToFrag; + if ( isOrthographic ) { + cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) ); + } else { + cameraToFrag = normalize( vWorldPosition - cameraPosition ); + } + vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); + #ifdef ENVMAP_MODE_REFLECTION + vec3 reflectVec = reflect( cameraToFrag, worldNormal ); + #else + vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio ); + #endif + #else + vec3 reflectVec = vReflect; + #endif + #ifdef ENVMAP_TYPE_CUBE + vec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) ); + #else + vec4 envColor = vec4( 0.0 ); + #endif + #ifdef ENVMAP_BLENDING_MULTIPLY + outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity ); + #elif defined( ENVMAP_BLENDING_MIX ) + outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity ); + #elif defined( ENVMAP_BLENDING_ADD ) + outgoingLight += envColor.xyz * specularStrength * reflectivity; + #endif +#endif`,Kc=`#ifdef USE_ENVMAP + uniform float envMapIntensity; + uniform float flipEnvMap; + #ifdef ENVMAP_TYPE_CUBE + uniform samplerCube envMap; + #else + uniform sampler2D envMap; + #endif + +#endif`,Zc=`#ifdef USE_ENVMAP + uniform float reflectivity; + #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT ) + #define ENV_WORLDPOS + #endif + #ifdef ENV_WORLDPOS + varying vec3 vWorldPosition; + uniform float refractionRatio; + #else + varying vec3 vReflect; + #endif +#endif`,$c=`#ifdef USE_ENVMAP + #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT ) + #define ENV_WORLDPOS + #endif + #ifdef ENV_WORLDPOS + + varying vec3 vWorldPosition; + #else + varying vec3 vReflect; + uniform float refractionRatio; + #endif +#endif`,Jc=`#ifdef USE_ENVMAP + #ifdef ENV_WORLDPOS + vWorldPosition = worldPosition.xyz; + #else + vec3 cameraToVertex; + if ( isOrthographic ) { + cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) ); + } else { + cameraToVertex = normalize( worldPosition.xyz - cameraPosition ); + } + vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix ); + #ifdef ENVMAP_MODE_REFLECTION + vReflect = reflect( cameraToVertex, worldNormal ); + #else + vReflect = refract( cameraToVertex, worldNormal, refractionRatio ); + #endif + #endif +#endif`,Qc=`#ifdef USE_FOG + vFogDepth = - mvPosition.z; +#endif`,eh=`#ifdef USE_FOG + varying float vFogDepth; +#endif`,th=`#ifdef USE_FOG + #ifdef FOG_EXP2 + float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth ); + #else + float fogFactor = smoothstep( fogNear, fogFar, vFogDepth ); + #endif + gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor ); +#endif`,nh=`#ifdef USE_FOG + uniform vec3 fogColor; + varying float vFogDepth; + #ifdef FOG_EXP2 + uniform float fogDensity; + #else + uniform float fogNear; + uniform float fogFar; + #endif +#endif`,ih=`#ifdef USE_GRADIENTMAP + uniform sampler2D gradientMap; +#endif +vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) { + float dotNL = dot( normal, lightDirection ); + vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 ); + #ifdef USE_GRADIENTMAP + return vec3( texture2D( gradientMap, coord ).r ); + #else + vec2 fw = fwidth( coord ) * 0.5; + return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) ); + #endif +}`,rh=`#ifdef USE_LIGHTMAP + vec4 lightMapTexel = texture2D( lightMap, vLightMapUv ); + vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity; + reflectedLight.indirectDiffuse += lightMapIrradiance; +#endif`,sh=`#ifdef USE_LIGHTMAP + uniform sampler2D lightMap; + uniform float lightMapIntensity; +#endif`,ah=`LambertMaterial material; +material.diffuseColor = diffuseColor.rgb; +material.specularStrength = specularStrength;`,oh=`varying vec3 vViewPosition; +struct LambertMaterial { + vec3 diffuseColor; + float specularStrength; +}; +void RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) { + float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); + vec3 irradiance = dotNL * directLight.color; + reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) { + reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +#define RE_Direct RE_Direct_Lambert +#define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert`,lh=`uniform bool receiveShadow; +uniform vec3 ambientLightColor; +#if defined( USE_LIGHT_PROBES ) + uniform vec3 lightProbe[ 9 ]; +#endif +vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) { + float x = normal.x, y = normal.y, z = normal.z; + vec3 result = shCoefficients[ 0 ] * 0.886227; + result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y; + result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z; + result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x; + result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y; + result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z; + result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 ); + result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z; + result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y ); + return result; +} +vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) { + vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); + vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe ); + return irradiance; +} +vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) { + vec3 irradiance = ambientLightColor; + return irradiance; +} +float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) { + #if defined ( LEGACY_LIGHTS ) + if ( cutoffDistance > 0.0 && decayExponent > 0.0 ) { + return pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent ); + } + return 1.0; + #else + float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 ); + if ( cutoffDistance > 0.0 ) { + distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) ); + } + return distanceFalloff; + #endif +} +float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) { + return smoothstep( coneCosine, penumbraCosine, angleCosine ); +} +#if NUM_DIR_LIGHTS > 0 + struct DirectionalLight { + vec3 direction; + vec3 color; + }; + uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ]; + void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) { + light.color = directionalLight.color; + light.direction = directionalLight.direction; + light.visible = true; + } +#endif +#if NUM_POINT_LIGHTS > 0 + struct PointLight { + vec3 position; + vec3 color; + float distance; + float decay; + }; + uniform PointLight pointLights[ NUM_POINT_LIGHTS ]; + void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) { + vec3 lVector = pointLight.position - geometryPosition; + light.direction = normalize( lVector ); + float lightDistance = length( lVector ); + light.color = pointLight.color; + light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay ); + light.visible = ( light.color != vec3( 0.0 ) ); + } +#endif +#if NUM_SPOT_LIGHTS > 0 + struct SpotLight { + vec3 position; + vec3 direction; + vec3 color; + float distance; + float decay; + float coneCos; + float penumbraCos; + }; + uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ]; + void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) { + vec3 lVector = spotLight.position - geometryPosition; + light.direction = normalize( lVector ); + float angleCos = dot( light.direction, spotLight.direction ); + float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos ); + if ( spotAttenuation > 0.0 ) { + float lightDistance = length( lVector ); + light.color = spotLight.color * spotAttenuation; + light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay ); + light.visible = ( light.color != vec3( 0.0 ) ); + } else { + light.color = vec3( 0.0 ); + light.visible = false; + } + } +#endif +#if NUM_RECT_AREA_LIGHTS > 0 + struct RectAreaLight { + vec3 color; + vec3 position; + vec3 halfWidth; + vec3 halfHeight; + }; + uniform sampler2D ltc_1; uniform sampler2D ltc_2; + uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ]; +#endif +#if NUM_HEMI_LIGHTS > 0 + struct HemisphereLight { + vec3 direction; + vec3 skyColor; + vec3 groundColor; + }; + uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ]; + vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) { + float dotNL = dot( normal, hemiLight.direction ); + float hemiDiffuseWeight = 0.5 * dotNL + 0.5; + vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight ); + return irradiance; + } +#endif`,ch=`#ifdef USE_ENVMAP + vec3 getIBLIrradiance( const in vec3 normal ) { + #ifdef ENVMAP_TYPE_CUBE_UV + vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); + vec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 ); + return PI * envMapColor.rgb * envMapIntensity; + #else + return vec3( 0.0 ); + #endif + } + vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) { + #ifdef ENVMAP_TYPE_CUBE_UV + vec3 reflectVec = reflect( - viewDir, normal ); + reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) ); + reflectVec = inverseTransformDirection( reflectVec, viewMatrix ); + vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness ); + return envMapColor.rgb * envMapIntensity; + #else + return vec3( 0.0 ); + #endif + } + #ifdef USE_ANISOTROPY + vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) { + #ifdef ENVMAP_TYPE_CUBE_UV + vec3 bentNormal = cross( bitangent, viewDir ); + bentNormal = normalize( cross( bentNormal, bitangent ) ); + bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) ); + return getIBLRadiance( viewDir, bentNormal, roughness ); + #else + return vec3( 0.0 ); + #endif + } + #endif +#endif`,hh=`ToonMaterial material; +material.diffuseColor = diffuseColor.rgb;`,uh=`varying vec3 vViewPosition; +struct ToonMaterial { + vec3 diffuseColor; +}; +void RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) { + vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color; + reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) { + reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +#define RE_Direct RE_Direct_Toon +#define RE_IndirectDiffuse RE_IndirectDiffuse_Toon`,fh=`BlinnPhongMaterial material; +material.diffuseColor = diffuseColor.rgb; +material.specularColor = specular; +material.specularShininess = shininess; +material.specularStrength = specularStrength;`,dh=`varying vec3 vViewPosition; +struct BlinnPhongMaterial { + vec3 diffuseColor; + vec3 specularColor; + float specularShininess; + float specularStrength; +}; +void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) { + float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); + vec3 irradiance = dotNL * directLight.color; + reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); + reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength; +} +void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) { + reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +#define RE_Direct RE_Direct_BlinnPhong +#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong`,ph=`PhysicalMaterial material; +material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor ); +vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) ); +float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z ); +material.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness; +material.roughness = min( material.roughness, 1.0 ); +#ifdef IOR + material.ior = ior; + #ifdef USE_SPECULAR + float specularIntensityFactor = specularIntensity; + vec3 specularColorFactor = specularColor; + #ifdef USE_SPECULAR_COLORMAP + specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb; + #endif + #ifdef USE_SPECULAR_INTENSITYMAP + specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a; + #endif + material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor ); + #else + float specularIntensityFactor = 1.0; + vec3 specularColorFactor = vec3( 1.0 ); + material.specularF90 = 1.0; + #endif + material.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor ); +#else + material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor ); + material.specularF90 = 1.0; +#endif +#ifdef USE_CLEARCOAT + material.clearcoat = clearcoat; + material.clearcoatRoughness = clearcoatRoughness; + material.clearcoatF0 = vec3( 0.04 ); + material.clearcoatF90 = 1.0; + #ifdef USE_CLEARCOATMAP + material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x; + #endif + #ifdef USE_CLEARCOAT_ROUGHNESSMAP + material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y; + #endif + material.clearcoat = saturate( material.clearcoat ); material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 ); + material.clearcoatRoughness += geometryRoughness; + material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 ); +#endif +#ifdef USE_IRIDESCENCE + material.iridescence = iridescence; + material.iridescenceIOR = iridescenceIOR; + #ifdef USE_IRIDESCENCEMAP + material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r; + #endif + #ifdef USE_IRIDESCENCE_THICKNESSMAP + material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum; + #else + material.iridescenceThickness = iridescenceThicknessMaximum; + #endif +#endif +#ifdef USE_SHEEN + material.sheenColor = sheenColor; + #ifdef USE_SHEEN_COLORMAP + material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb; + #endif + material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 ); + #ifdef USE_SHEEN_ROUGHNESSMAP + material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a; + #endif +#endif +#ifdef USE_ANISOTROPY + #ifdef USE_ANISOTROPYMAP + mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x ); + vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb; + vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b; + #else + vec2 anisotropyV = anisotropyVector; + #endif + material.anisotropy = length( anisotropyV ); + if( material.anisotropy == 0.0 ) { + anisotropyV = vec2( 1.0, 0.0 ); + } else { + anisotropyV /= material.anisotropy; + material.anisotropy = saturate( material.anisotropy ); + } + material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) ); + material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y; + material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y; +#endif`,mh=`struct PhysicalMaterial { + vec3 diffuseColor; + float roughness; + vec3 specularColor; + float specularF90; + #ifdef USE_CLEARCOAT + float clearcoat; + float clearcoatRoughness; + vec3 clearcoatF0; + float clearcoatF90; + #endif + #ifdef USE_IRIDESCENCE + float iridescence; + float iridescenceIOR; + float iridescenceThickness; + vec3 iridescenceFresnel; + vec3 iridescenceF0; + #endif + #ifdef USE_SHEEN + vec3 sheenColor; + float sheenRoughness; + #endif + #ifdef IOR + float ior; + #endif + #ifdef USE_TRANSMISSION + float transmission; + float transmissionAlpha; + float thickness; + float attenuationDistance; + vec3 attenuationColor; + #endif + #ifdef USE_ANISOTROPY + float anisotropy; + float alphaT; + vec3 anisotropyT; + vec3 anisotropyB; + #endif +}; +vec3 clearcoatSpecularDirect = vec3( 0.0 ); +vec3 clearcoatSpecularIndirect = vec3( 0.0 ); +vec3 sheenSpecularDirect = vec3( 0.0 ); +vec3 sheenSpecularIndirect = vec3(0.0 ); +vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) { + float x = clamp( 1.0 - dotVH, 0.0, 1.0 ); + float x2 = x * x; + float x5 = clamp( x * x2 * x2, 0.0, 0.9999 ); + return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 ); +} +float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) { + float a2 = pow2( alpha ); + float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) ); + float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) ); + return 0.5 / max( gv + gl, EPSILON ); +} +float D_GGX( const in float alpha, const in float dotNH ) { + float a2 = pow2( alpha ); + float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; + return RECIPROCAL_PI * a2 / pow2( denom ); +} +#ifdef USE_ANISOTROPY + float V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) { + float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) ); + float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) ); + float v = 0.5 / ( gv + gl ); + return saturate(v); + } + float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) { + float a2 = alphaT * alphaB; + highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH ); + highp float v2 = dot( v, v ); + float w2 = a2 / v2; + return RECIPROCAL_PI * a2 * pow2 ( w2 ); + } +#endif +#ifdef USE_CLEARCOAT + vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) { + vec3 f0 = material.clearcoatF0; + float f90 = material.clearcoatF90; + float roughness = material.clearcoatRoughness; + float alpha = pow2( roughness ); + vec3 halfDir = normalize( lightDir + viewDir ); + float dotNL = saturate( dot( normal, lightDir ) ); + float dotNV = saturate( dot( normal, viewDir ) ); + float dotNH = saturate( dot( normal, halfDir ) ); + float dotVH = saturate( dot( viewDir, halfDir ) ); + vec3 F = F_Schlick( f0, f90, dotVH ); + float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV ); + float D = D_GGX( alpha, dotNH ); + return F * ( V * D ); + } +#endif +vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) { + vec3 f0 = material.specularColor; + float f90 = material.specularF90; + float roughness = material.roughness; + float alpha = pow2( roughness ); + vec3 halfDir = normalize( lightDir + viewDir ); + float dotNL = saturate( dot( normal, lightDir ) ); + float dotNV = saturate( dot( normal, viewDir ) ); + float dotNH = saturate( dot( normal, halfDir ) ); + float dotVH = saturate( dot( viewDir, halfDir ) ); + vec3 F = F_Schlick( f0, f90, dotVH ); + #ifdef USE_IRIDESCENCE + F = mix( F, material.iridescenceFresnel, material.iridescence ); + #endif + #ifdef USE_ANISOTROPY + float dotTL = dot( material.anisotropyT, lightDir ); + float dotTV = dot( material.anisotropyT, viewDir ); + float dotTH = dot( material.anisotropyT, halfDir ); + float dotBL = dot( material.anisotropyB, lightDir ); + float dotBV = dot( material.anisotropyB, viewDir ); + float dotBH = dot( material.anisotropyB, halfDir ); + float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL ); + float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH ); + #else + float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV ); + float D = D_GGX( alpha, dotNH ); + #endif + return F * ( V * D ); +} +vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) { + const float LUT_SIZE = 64.0; + const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE; + const float LUT_BIAS = 0.5 / LUT_SIZE; + float dotNV = saturate( dot( N, V ) ); + vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) ); + uv = uv * LUT_SCALE + LUT_BIAS; + return uv; +} +float LTC_ClippedSphereFormFactor( const in vec3 f ) { + float l = length( f ); + return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 ); +} +vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) { + float x = dot( v1, v2 ); + float y = abs( x ); + float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y; + float b = 3.4175940 + ( 4.1616724 + y ) * y; + float v = a / b; + float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v; + return cross( v1, v2 ) * theta_sintheta; +} +vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) { + vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ]; + vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ]; + vec3 lightNormal = cross( v1, v2 ); + if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 ); + vec3 T1, T2; + T1 = normalize( V - N * dot( V, N ) ); + T2 = - cross( N, T1 ); + mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) ); + vec3 coords[ 4 ]; + coords[ 0 ] = mat * ( rectCoords[ 0 ] - P ); + coords[ 1 ] = mat * ( rectCoords[ 1 ] - P ); + coords[ 2 ] = mat * ( rectCoords[ 2 ] - P ); + coords[ 3 ] = mat * ( rectCoords[ 3 ] - P ); + coords[ 0 ] = normalize( coords[ 0 ] ); + coords[ 1 ] = normalize( coords[ 1 ] ); + coords[ 2 ] = normalize( coords[ 2 ] ); + coords[ 3 ] = normalize( coords[ 3 ] ); + vec3 vectorFormFactor = vec3( 0.0 ); + vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] ); + vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] ); + vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] ); + vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] ); + float result = LTC_ClippedSphereFormFactor( vectorFormFactor ); + return vec3( result ); +} +#if defined( USE_SHEEN ) +float D_Charlie( float roughness, float dotNH ) { + float alpha = pow2( roughness ); + float invAlpha = 1.0 / alpha; + float cos2h = dotNH * dotNH; + float sin2h = max( 1.0 - cos2h, 0.0078125 ); + return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI ); +} +float V_Neubelt( float dotNV, float dotNL ) { + return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) ); +} +vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) { + vec3 halfDir = normalize( lightDir + viewDir ); + float dotNL = saturate( dot( normal, lightDir ) ); + float dotNV = saturate( dot( normal, viewDir ) ); + float dotNH = saturate( dot( normal, halfDir ) ); + float D = D_Charlie( sheenRoughness, dotNH ); + float V = V_Neubelt( dotNV, dotNL ); + return sheenColor * ( D * V ); +} +#endif +float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) { + float dotNV = saturate( dot( normal, viewDir ) ); + float r2 = roughness * roughness; + float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95; + float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72; + float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) ); + return saturate( DG * RECIPROCAL_PI ); +} +vec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) { + float dotNV = saturate( dot( normal, viewDir ) ); + const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 ); + const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 ); + vec4 r = roughness * c0 + c1; + float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y; + vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw; + return fab; +} +vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) { + vec2 fab = DFGApprox( normal, viewDir, roughness ); + return specularColor * fab.x + specularF90 * fab.y; +} +#ifdef USE_IRIDESCENCE +void computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) { +#else +void computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) { +#endif + vec2 fab = DFGApprox( normal, viewDir, roughness ); + #ifdef USE_IRIDESCENCE + vec3 Fr = mix( specularColor, iridescenceF0, iridescence ); + #else + vec3 Fr = specularColor; + #endif + vec3 FssEss = Fr * fab.x + specularF90 * fab.y; + float Ess = fab.x + fab.y; + float Ems = 1.0 - Ess; + vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg ); + singleScatter += FssEss; + multiScatter += Fms * Ems; +} +#if NUM_RECT_AREA_LIGHTS > 0 + void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { + vec3 normal = geometryNormal; + vec3 viewDir = geometryViewDir; + vec3 position = geometryPosition; + vec3 lightPos = rectAreaLight.position; + vec3 halfWidth = rectAreaLight.halfWidth; + vec3 halfHeight = rectAreaLight.halfHeight; + vec3 lightColor = rectAreaLight.color; + float roughness = material.roughness; + vec3 rectCoords[ 4 ]; + rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; rectCoords[ 1 ] = lightPos - halfWidth - halfHeight; + rectCoords[ 2 ] = lightPos - halfWidth + halfHeight; + rectCoords[ 3 ] = lightPos + halfWidth + halfHeight; + vec2 uv = LTC_Uv( normal, viewDir, roughness ); + vec4 t1 = texture2D( ltc_1, uv ); + vec4 t2 = texture2D( ltc_2, uv ); + mat3 mInv = mat3( + vec3( t1.x, 0, t1.y ), + vec3( 0, 1, 0 ), + vec3( t1.z, 0, t1.w ) + ); + vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y ); + reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords ); + reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords ); + } +#endif +void RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { + float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); + vec3 irradiance = dotNL * directLight.color; + #ifdef USE_CLEARCOAT + float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) ); + vec3 ccIrradiance = dotNLcc * directLight.color; + clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material ); + #endif + #ifdef USE_SHEEN + sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness ); + #endif + reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material ); + reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { + reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) { + #ifdef USE_CLEARCOAT + clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness ); + #endif + #ifdef USE_SHEEN + sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ); + #endif + vec3 singleScattering = vec3( 0.0 ); + vec3 multiScattering = vec3( 0.0 ); + vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI; + #ifdef USE_IRIDESCENCE + computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering ); + #else + computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering ); + #endif + vec3 totalScattering = singleScattering + multiScattering; + vec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) ); + reflectedLight.indirectSpecular += radiance * singleScattering; + reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance; + reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance; +} +#define RE_Direct RE_Direct_Physical +#define RE_Direct_RectArea RE_Direct_RectArea_Physical +#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical +#define RE_IndirectSpecular RE_IndirectSpecular_Physical +float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) { + return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion ); +}`,_h=` +vec3 geometryPosition = - vViewPosition; +vec3 geometryNormal = normal; +vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition ); +vec3 geometryClearcoatNormal = vec3( 0.0 ); +#ifdef USE_CLEARCOAT + geometryClearcoatNormal = clearcoatNormal; +#endif +#ifdef USE_IRIDESCENCE + float dotNVi = saturate( dot( normal, geometryViewDir ) ); + if ( material.iridescenceThickness == 0.0 ) { + material.iridescence = 0.0; + } else { + material.iridescence = saturate( material.iridescence ); + } + if ( material.iridescence > 0.0 ) { + material.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor ); + material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi ); + } +#endif +IncidentLight directLight; +#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct ) + PointLight pointLight; + #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0 + PointLightShadow pointLightShadow; + #endif + #pragma unroll_loop_start + for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) { + pointLight = pointLights[ i ]; + getPointLightInfo( pointLight, geometryPosition, directLight ); + #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS ) + pointLightShadow = pointLightShadows[ i ]; + directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0; + #endif + RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); + } + #pragma unroll_loop_end +#endif +#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct ) + SpotLight spotLight; + vec4 spotColor; + vec3 spotLightCoord; + bool inSpotLightMap; + #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0 + SpotLightShadow spotLightShadow; + #endif + #pragma unroll_loop_start + for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) { + spotLight = spotLights[ i ]; + getSpotLightInfo( spotLight, geometryPosition, directLight ); + #if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS ) + #define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX + #elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) + #define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS + #else + #define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS ) + #endif + #if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS ) + spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w; + inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) ); + spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy ); + directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color; + #endif + #undef SPOT_LIGHT_MAP_INDEX + #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) + spotLightShadow = spotLightShadows[ i ]; + directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0; + #endif + RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); + } + #pragma unroll_loop_end +#endif +#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct ) + DirectionalLight directionalLight; + #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0 + DirectionalLightShadow directionalLightShadow; + #endif + #pragma unroll_loop_start + for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) { + directionalLight = directionalLights[ i ]; + getDirectionalLightInfo( directionalLight, directLight ); + #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS ) + directionalLightShadow = directionalLightShadows[ i ]; + directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0; + #endif + RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); + } + #pragma unroll_loop_end +#endif +#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea ) + RectAreaLight rectAreaLight; + #pragma unroll_loop_start + for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) { + rectAreaLight = rectAreaLights[ i ]; + RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); + } + #pragma unroll_loop_end +#endif +#if defined( RE_IndirectDiffuse ) + vec3 iblIrradiance = vec3( 0.0 ); + vec3 irradiance = getAmbientLightIrradiance( ambientLightColor ); + #if defined( USE_LIGHT_PROBES ) + irradiance += getLightProbeIrradiance( lightProbe, geometryNormal ); + #endif + #if ( NUM_HEMI_LIGHTS > 0 ) + #pragma unroll_loop_start + for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) { + irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal ); + } + #pragma unroll_loop_end + #endif +#endif +#if defined( RE_IndirectSpecular ) + vec3 radiance = vec3( 0.0 ); + vec3 clearcoatRadiance = vec3( 0.0 ); +#endif`,gh=`#if defined( RE_IndirectDiffuse ) + #ifdef USE_LIGHTMAP + vec4 lightMapTexel = texture2D( lightMap, vLightMapUv ); + vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity; + irradiance += lightMapIrradiance; + #endif + #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV ) + iblIrradiance += getIBLIrradiance( geometryNormal ); + #endif +#endif +#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular ) + #ifdef USE_ANISOTROPY + radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy ); + #else + radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness ); + #endif + #ifdef USE_CLEARCOAT + clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness ); + #endif +#endif`,vh=`#if defined( RE_IndirectDiffuse ) + RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); +#endif +#if defined( RE_IndirectSpecular ) + RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); +#endif`,xh=`#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT ) + gl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5; +#endif`,Mh=`#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT ) + uniform float logDepthBufFC; + varying float vFragDepth; + varying float vIsPerspective; +#endif`,Sh=`#ifdef USE_LOGDEPTHBUF + #ifdef USE_LOGDEPTHBUF_EXT + varying float vFragDepth; + varying float vIsPerspective; + #else + uniform float logDepthBufFC; + #endif +#endif`,Eh=`#ifdef USE_LOGDEPTHBUF + #ifdef USE_LOGDEPTHBUF_EXT + vFragDepth = 1.0 + gl_Position.w; + vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) ); + #else + if ( isPerspectiveMatrix( projectionMatrix ) ) { + gl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0; + gl_Position.z *= gl_Position.w; + } + #endif +#endif`,yh=`#ifdef USE_MAP + vec4 sampledDiffuseColor = texture2D( map, vMapUv ); + #ifdef DECODE_VIDEO_TEXTURE + sampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w ); + + #endif + diffuseColor *= sampledDiffuseColor; +#endif`,Th=`#ifdef USE_MAP + uniform sampler2D map; +#endif`,Ah=`#if defined( USE_MAP ) || defined( USE_ALPHAMAP ) + #if defined( USE_POINTS_UV ) + vec2 uv = vUv; + #else + vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy; + #endif +#endif +#ifdef USE_MAP + diffuseColor *= texture2D( map, uv ); +#endif +#ifdef USE_ALPHAMAP + diffuseColor.a *= texture2D( alphaMap, uv ).g; +#endif`,bh=`#if defined( USE_POINTS_UV ) + varying vec2 vUv; +#else + #if defined( USE_MAP ) || defined( USE_ALPHAMAP ) + uniform mat3 uvTransform; + #endif +#endif +#ifdef USE_MAP + uniform sampler2D map; +#endif +#ifdef USE_ALPHAMAP + uniform sampler2D alphaMap; +#endif`,wh=`float metalnessFactor = metalness; +#ifdef USE_METALNESSMAP + vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv ); + metalnessFactor *= texelMetalness.b; +#endif`,Rh=`#ifdef USE_METALNESSMAP + uniform sampler2D metalnessMap; +#endif`,Ch=`#if defined( USE_MORPHCOLORS ) && defined( MORPHTARGETS_TEXTURE ) + vColor *= morphTargetBaseInfluence; + for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { + #if defined( USE_COLOR_ALPHA ) + if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ]; + #elif defined( USE_COLOR ) + if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ]; + #endif + } +#endif`,Lh=`#ifdef USE_MORPHNORMALS + objectNormal *= morphTargetBaseInfluence; + #ifdef MORPHTARGETS_TEXTURE + for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { + if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ]; + } + #else + objectNormal += morphNormal0 * morphTargetInfluences[ 0 ]; + objectNormal += morphNormal1 * morphTargetInfluences[ 1 ]; + objectNormal += morphNormal2 * morphTargetInfluences[ 2 ]; + objectNormal += morphNormal3 * morphTargetInfluences[ 3 ]; + #endif +#endif`,Ph=`#ifdef USE_MORPHTARGETS + uniform float morphTargetBaseInfluence; + #ifdef MORPHTARGETS_TEXTURE + uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ]; + uniform sampler2DArray morphTargetsTexture; + uniform ivec2 morphTargetsTextureSize; + vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) { + int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset; + int y = texelIndex / morphTargetsTextureSize.x; + int x = texelIndex - y * morphTargetsTextureSize.x; + ivec3 morphUV = ivec3( x, y, morphTargetIndex ); + return texelFetch( morphTargetsTexture, morphUV, 0 ); + } + #else + #ifndef USE_MORPHNORMALS + uniform float morphTargetInfluences[ 8 ]; + #else + uniform float morphTargetInfluences[ 4 ]; + #endif + #endif +#endif`,Dh=`#ifdef USE_MORPHTARGETS + transformed *= morphTargetBaseInfluence; + #ifdef MORPHTARGETS_TEXTURE + for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { + if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ]; + } + #else + transformed += morphTarget0 * morphTargetInfluences[ 0 ]; + transformed += morphTarget1 * morphTargetInfluences[ 1 ]; + transformed += morphTarget2 * morphTargetInfluences[ 2 ]; + transformed += morphTarget3 * morphTargetInfluences[ 3 ]; + #ifndef USE_MORPHNORMALS + transformed += morphTarget4 * morphTargetInfluences[ 4 ]; + transformed += morphTarget5 * morphTargetInfluences[ 5 ]; + transformed += morphTarget6 * morphTargetInfluences[ 6 ]; + transformed += morphTarget7 * morphTargetInfluences[ 7 ]; + #endif + #endif +#endif`,Uh=`float faceDirection = gl_FrontFacing ? 1.0 : - 1.0; +#ifdef FLAT_SHADED + vec3 fdx = dFdx( vViewPosition ); + vec3 fdy = dFdy( vViewPosition ); + vec3 normal = normalize( cross( fdx, fdy ) ); +#else + vec3 normal = normalize( vNormal ); + #ifdef DOUBLE_SIDED + normal *= faceDirection; + #endif +#endif +#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) + #ifdef USE_TANGENT + mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal ); + #else + mat3 tbn = getTangentFrame( - vViewPosition, normal, + #if defined( USE_NORMALMAP ) + vNormalMapUv + #elif defined( USE_CLEARCOAT_NORMALMAP ) + vClearcoatNormalMapUv + #else + vUv + #endif + ); + #endif + #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED ) + tbn[0] *= faceDirection; + tbn[1] *= faceDirection; + #endif +#endif +#ifdef USE_CLEARCOAT_NORMALMAP + #ifdef USE_TANGENT + mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal ); + #else + mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv ); + #endif + #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED ) + tbn2[0] *= faceDirection; + tbn2[1] *= faceDirection; + #endif +#endif +vec3 nonPerturbedNormal = normal;`,Ih=`#ifdef USE_NORMALMAP_OBJECTSPACE + normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0; + #ifdef FLIP_SIDED + normal = - normal; + #endif + #ifdef DOUBLE_SIDED + normal = normal * faceDirection; + #endif + normal = normalize( normalMatrix * normal ); +#elif defined( USE_NORMALMAP_TANGENTSPACE ) + vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0; + mapN.xy *= normalScale; + normal = normalize( tbn * mapN ); +#elif defined( USE_BUMPMAP ) + normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection ); +#endif`,Nh=`#ifndef FLAT_SHADED + varying vec3 vNormal; + #ifdef USE_TANGENT + varying vec3 vTangent; + varying vec3 vBitangent; + #endif +#endif`,Fh=`#ifndef FLAT_SHADED + varying vec3 vNormal; + #ifdef USE_TANGENT + varying vec3 vTangent; + varying vec3 vBitangent; + #endif +#endif`,Oh=`#ifndef FLAT_SHADED + vNormal = normalize( transformedNormal ); + #ifdef USE_TANGENT + vTangent = normalize( transformedTangent ); + vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w ); + #endif +#endif`,Bh=`#ifdef USE_NORMALMAP + uniform sampler2D normalMap; + uniform vec2 normalScale; +#endif +#ifdef USE_NORMALMAP_OBJECTSPACE + uniform mat3 normalMatrix; +#endif +#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) ) + mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) { + vec3 q0 = dFdx( eye_pos.xyz ); + vec3 q1 = dFdy( eye_pos.xyz ); + vec2 st0 = dFdx( uv.st ); + vec2 st1 = dFdy( uv.st ); + vec3 N = surf_norm; + vec3 q1perp = cross( q1, N ); + vec3 q0perp = cross( N, q0 ); + vec3 T = q1perp * st0.x + q0perp * st1.x; + vec3 B = q1perp * st0.y + q0perp * st1.y; + float det = max( dot( T, T ), dot( B, B ) ); + float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det ); + return mat3( T * scale, B * scale, N ); + } +#endif`,zh=`#ifdef USE_CLEARCOAT + vec3 clearcoatNormal = nonPerturbedNormal; +#endif`,Gh=`#ifdef USE_CLEARCOAT_NORMALMAP + vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0; + clearcoatMapN.xy *= clearcoatNormalScale; + clearcoatNormal = normalize( tbn2 * clearcoatMapN ); +#endif`,Hh=`#ifdef USE_CLEARCOATMAP + uniform sampler2D clearcoatMap; +#endif +#ifdef USE_CLEARCOAT_NORMALMAP + uniform sampler2D clearcoatNormalMap; + uniform vec2 clearcoatNormalScale; +#endif +#ifdef USE_CLEARCOAT_ROUGHNESSMAP + uniform sampler2D clearcoatRoughnessMap; +#endif`,Vh=`#ifdef USE_IRIDESCENCEMAP + uniform sampler2D iridescenceMap; +#endif +#ifdef USE_IRIDESCENCE_THICKNESSMAP + uniform sampler2D iridescenceThicknessMap; +#endif`,kh=`#ifdef OPAQUE +diffuseColor.a = 1.0; +#endif +#ifdef USE_TRANSMISSION +diffuseColor.a *= material.transmissionAlpha; +#endif +gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,Wh=`vec3 packNormalToRGB( const in vec3 normal ) { + return normalize( normal ) * 0.5 + 0.5; +} +vec3 unpackRGBToNormal( const in vec3 rgb ) { + return 2.0 * rgb.xyz - 1.0; +} +const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.; +const vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. ); +const vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. ); +const float ShiftRight8 = 1. / 256.; +vec4 packDepthToRGBA( const in float v ) { + vec4 r = vec4( fract( v * PackFactors ), v ); + r.yzw -= r.xyz * ShiftRight8; return r * PackUpscale; +} +float unpackRGBAToDepth( const in vec4 v ) { + return dot( v, UnpackFactors ); +} +vec2 packDepthToRG( in highp float v ) { + return packDepthToRGBA( v ).yx; +} +float unpackRGToDepth( const in highp vec2 v ) { + return unpackRGBAToDepth( vec4( v.xy, 0.0, 0.0 ) ); +} +vec4 pack2HalfToRGBA( vec2 v ) { + vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) ); + return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w ); +} +vec2 unpackRGBATo2Half( vec4 v ) { + return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) ); +} +float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) { + return ( viewZ + near ) / ( near - far ); +} +float orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) { + return depth * ( near - far ) - near; +} +float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) { + return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ ); +} +float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) { + return ( near * far ) / ( ( far - near ) * depth - far ); +}`,Xh=`#ifdef PREMULTIPLIED_ALPHA + gl_FragColor.rgb *= gl_FragColor.a; +#endif`,qh=`vec4 mvPosition = vec4( transformed, 1.0 ); +#ifdef USE_BATCHING + mvPosition = batchingMatrix * mvPosition; +#endif +#ifdef USE_INSTANCING + mvPosition = instanceMatrix * mvPosition; +#endif +mvPosition = modelViewMatrix * mvPosition; +gl_Position = projectionMatrix * mvPosition;`,Yh=`#ifdef DITHERING + gl_FragColor.rgb = dithering( gl_FragColor.rgb ); +#endif`,jh=`#ifdef DITHERING + vec3 dithering( vec3 color ) { + float grid_position = rand( gl_FragCoord.xy ); + vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 ); + dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position ); + return color + dither_shift_RGB; + } +#endif`,Kh=`float roughnessFactor = roughness; +#ifdef USE_ROUGHNESSMAP + vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv ); + roughnessFactor *= texelRoughness.g; +#endif`,Zh=`#ifdef USE_ROUGHNESSMAP + uniform sampler2D roughnessMap; +#endif`,$h=`#if NUM_SPOT_LIGHT_COORDS > 0 + varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ]; +#endif +#if NUM_SPOT_LIGHT_MAPS > 0 + uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ]; +#endif +#ifdef USE_SHADOWMAP + #if NUM_DIR_LIGHT_SHADOWS > 0 + uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ]; + varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ]; + struct DirectionalLightShadow { + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + }; + uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ]; + #endif + #if NUM_SPOT_LIGHT_SHADOWS > 0 + uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ]; + struct SpotLightShadow { + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + }; + uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ]; + #endif + #if NUM_POINT_LIGHT_SHADOWS > 0 + uniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ]; + varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ]; + struct PointLightShadow { + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + float shadowCameraNear; + float shadowCameraFar; + }; + uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ]; + #endif + float texture2DCompare( sampler2D depths, vec2 uv, float compare ) { + return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) ); + } + vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) { + return unpackRGBATo2Half( texture2D( shadow, uv ) ); + } + float VSMShadow (sampler2D shadow, vec2 uv, float compare ){ + float occlusion = 1.0; + vec2 distribution = texture2DDistribution( shadow, uv ); + float hard_shadow = step( compare , distribution.x ); + if (hard_shadow != 1.0 ) { + float distance = compare - distribution.x ; + float variance = max( 0.00000, distribution.y * distribution.y ); + float softness_probability = variance / (variance + distance * distance ); softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 ); occlusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 ); + } + return occlusion; + } + float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) { + float shadow = 1.0; + shadowCoord.xyz /= shadowCoord.w; + shadowCoord.z += shadowBias; + bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0; + bool frustumTest = inFrustum && shadowCoord.z <= 1.0; + if ( frustumTest ) { + #if defined( SHADOWMAP_TYPE_PCF ) + vec2 texelSize = vec2( 1.0 ) / shadowMapSize; + float dx0 = - texelSize.x * shadowRadius; + float dy0 = - texelSize.y * shadowRadius; + float dx1 = + texelSize.x * shadowRadius; + float dy1 = + texelSize.y * shadowRadius; + float dx2 = dx0 / 2.0; + float dy2 = dy0 / 2.0; + float dx3 = dx1 / 2.0; + float dy3 = dy1 / 2.0; + shadow = ( + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z ) + ) * ( 1.0 / 17.0 ); + #elif defined( SHADOWMAP_TYPE_PCF_SOFT ) + vec2 texelSize = vec2( 1.0 ) / shadowMapSize; + float dx = texelSize.x; + float dy = texelSize.y; + vec2 uv = shadowCoord.xy; + vec2 f = fract( uv * shadowMapSize + 0.5 ); + uv -= f * texelSize; + shadow = ( + texture2DCompare( shadowMap, uv, shadowCoord.z ) + + texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) + + texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) + + mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ), + f.x ) + + mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ), + f.x ) + + mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ), + f.y ) + + mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ), + f.y ) + + mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ), + f.x ), + mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ), + f.x ), + f.y ) + ) * ( 1.0 / 9.0 ); + #elif defined( SHADOWMAP_TYPE_VSM ) + shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z ); + #else + shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ); + #endif + } + return shadow; + } + vec2 cubeToUV( vec3 v, float texelSizeY ) { + vec3 absV = abs( v ); + float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) ); + absV *= scaleToCube; + v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY ); + vec2 planar = v.xy; + float almostATexel = 1.5 * texelSizeY; + float almostOne = 1.0 - almostATexel; + if ( absV.z >= almostOne ) { + if ( v.z > 0.0 ) + planar.x = 4.0 - v.x; + } else if ( absV.x >= almostOne ) { + float signX = sign( v.x ); + planar.x = v.z * signX + 2.0 * signX; + } else if ( absV.y >= almostOne ) { + float signY = sign( v.y ); + planar.x = v.x + 2.0 * signY + 2.0; + planar.y = v.z * signY - 2.0; + } + return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 ); + } + float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) { + vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) ); + vec3 lightToPosition = shadowCoord.xyz; + float dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); dp += shadowBias; + vec3 bd3D = normalize( lightToPosition ); + #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM ) + vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y; + return ( + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp ) + ) * ( 1.0 / 9.0 ); + #else + return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ); + #endif + } +#endif`,Jh=`#if NUM_SPOT_LIGHT_COORDS > 0 + uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ]; + varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ]; +#endif +#ifdef USE_SHADOWMAP + #if NUM_DIR_LIGHT_SHADOWS > 0 + uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ]; + varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ]; + struct DirectionalLightShadow { + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + }; + uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ]; + #endif + #if NUM_SPOT_LIGHT_SHADOWS > 0 + struct SpotLightShadow { + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + }; + uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ]; + #endif + #if NUM_POINT_LIGHT_SHADOWS > 0 + uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ]; + varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ]; + struct PointLightShadow { + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + float shadowCameraNear; + float shadowCameraFar; + }; + uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ]; + #endif +#endif`,Qh=`#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 ) + vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix ); + vec4 shadowWorldPosition; +#endif +#if defined( USE_SHADOWMAP ) + #if NUM_DIR_LIGHT_SHADOWS > 0 + #pragma unroll_loop_start + for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) { + shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 ); + vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition; + } + #pragma unroll_loop_end + #endif + #if NUM_POINT_LIGHT_SHADOWS > 0 + #pragma unroll_loop_start + for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) { + shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 ); + vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition; + } + #pragma unroll_loop_end + #endif +#endif +#if NUM_SPOT_LIGHT_COORDS > 0 + #pragma unroll_loop_start + for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) { + shadowWorldPosition = worldPosition; + #if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) + shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias; + #endif + vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition; + } + #pragma unroll_loop_end +#endif`,eu=`float getShadowMask() { + float shadow = 1.0; + #ifdef USE_SHADOWMAP + #if NUM_DIR_LIGHT_SHADOWS > 0 + DirectionalLightShadow directionalLight; + #pragma unroll_loop_start + for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) { + directionalLight = directionalLightShadows[ i ]; + shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0; + } + #pragma unroll_loop_end + #endif + #if NUM_SPOT_LIGHT_SHADOWS > 0 + SpotLightShadow spotLight; + #pragma unroll_loop_start + for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) { + spotLight = spotLightShadows[ i ]; + shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0; + } + #pragma unroll_loop_end + #endif + #if NUM_POINT_LIGHT_SHADOWS > 0 + PointLightShadow pointLight; + #pragma unroll_loop_start + for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) { + pointLight = pointLightShadows[ i ]; + shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0; + } + #pragma unroll_loop_end + #endif + #endif + return shadow; +}`,tu=`#ifdef USE_SKINNING + mat4 boneMatX = getBoneMatrix( skinIndex.x ); + mat4 boneMatY = getBoneMatrix( skinIndex.y ); + mat4 boneMatZ = getBoneMatrix( skinIndex.z ); + mat4 boneMatW = getBoneMatrix( skinIndex.w ); +#endif`,nu=`#ifdef USE_SKINNING + uniform mat4 bindMatrix; + uniform mat4 bindMatrixInverse; + uniform highp sampler2D boneTexture; + mat4 getBoneMatrix( const in float i ) { + int size = textureSize( boneTexture, 0 ).x; + int j = int( i ) * 4; + int x = j % size; + int y = j / size; + vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 ); + vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 ); + vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 ); + vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 ); + return mat4( v1, v2, v3, v4 ); + } +#endif`,iu=`#ifdef USE_SKINNING + vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 ); + vec4 skinned = vec4( 0.0 ); + skinned += boneMatX * skinVertex * skinWeight.x; + skinned += boneMatY * skinVertex * skinWeight.y; + skinned += boneMatZ * skinVertex * skinWeight.z; + skinned += boneMatW * skinVertex * skinWeight.w; + transformed = ( bindMatrixInverse * skinned ).xyz; +#endif`,ru=`#ifdef USE_SKINNING + mat4 skinMatrix = mat4( 0.0 ); + skinMatrix += skinWeight.x * boneMatX; + skinMatrix += skinWeight.y * boneMatY; + skinMatrix += skinWeight.z * boneMatZ; + skinMatrix += skinWeight.w * boneMatW; + skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix; + objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz; + #ifdef USE_TANGENT + objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz; + #endif +#endif`,su=`float specularStrength; +#ifdef USE_SPECULARMAP + vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv ); + specularStrength = texelSpecular.r; +#else + specularStrength = 1.0; +#endif`,au=`#ifdef USE_SPECULARMAP + uniform sampler2D specularMap; +#endif`,ou=`#if defined( TONE_MAPPING ) + gl_FragColor.rgb = toneMapping( gl_FragColor.rgb ); +#endif`,lu=`#ifndef saturate +#define saturate( a ) clamp( a, 0.0, 1.0 ) +#endif +uniform float toneMappingExposure; +vec3 LinearToneMapping( vec3 color ) { + return saturate( toneMappingExposure * color ); +} +vec3 ReinhardToneMapping( vec3 color ) { + color *= toneMappingExposure; + return saturate( color / ( vec3( 1.0 ) + color ) ); +} +vec3 OptimizedCineonToneMapping( vec3 color ) { + color *= toneMappingExposure; + color = max( vec3( 0.0 ), color - 0.004 ); + return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) ); +} +vec3 RRTAndODTFit( vec3 v ) { + vec3 a = v * ( v + 0.0245786 ) - 0.000090537; + vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081; + return a / b; +} +vec3 ACESFilmicToneMapping( vec3 color ) { + const mat3 ACESInputMat = mat3( + vec3( 0.59719, 0.07600, 0.02840 ), vec3( 0.35458, 0.90834, 0.13383 ), + vec3( 0.04823, 0.01566, 0.83777 ) + ); + const mat3 ACESOutputMat = mat3( + vec3( 1.60475, -0.10208, -0.00327 ), vec3( -0.53108, 1.10813, -0.07276 ), + vec3( -0.07367, -0.00605, 1.07602 ) + ); + color *= toneMappingExposure / 0.6; + color = ACESInputMat * color; + color = RRTAndODTFit( color ); + color = ACESOutputMat * color; + return saturate( color ); +} +const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3( + vec3( 1.6605, - 0.1246, - 0.0182 ), + vec3( - 0.5876, 1.1329, - 0.1006 ), + vec3( - 0.0728, - 0.0083, 1.1187 ) +); +const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3( + vec3( 0.6274, 0.0691, 0.0164 ), + vec3( 0.3293, 0.9195, 0.0880 ), + vec3( 0.0433, 0.0113, 0.8956 ) +); +vec3 agxDefaultContrastApprox( vec3 x ) { + vec3 x2 = x * x; + vec3 x4 = x2 * x2; + return + 15.5 * x4 * x2 + - 40.14 * x4 * x + + 31.96 * x4 + - 6.868 * x2 * x + + 0.4298 * x2 + + 0.1191 * x + - 0.00232; +} +vec3 AgXToneMapping( vec3 color ) { + const mat3 AgXInsetMatrix = mat3( + vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ), + vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ), + vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 ) + ); + const mat3 AgXOutsetMatrix = mat3( + vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ), + vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ), + vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 ) + ); + const float AgxMinEv = - 12.47393; const float AgxMaxEv = 4.026069; + color = LINEAR_SRGB_TO_LINEAR_REC2020 * color; + color *= toneMappingExposure; + color = AgXInsetMatrix * color; + color = max( color, 1e-10 ); color = log2( color ); + color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv ); + color = clamp( color, 0.0, 1.0 ); + color = agxDefaultContrastApprox( color ); + color = AgXOutsetMatrix * color; + color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) ); + color = LINEAR_REC2020_TO_LINEAR_SRGB * color; + return color; +} +vec3 CustomToneMapping( vec3 color ) { return color; }`,cu=`#ifdef USE_TRANSMISSION + material.transmission = transmission; + material.transmissionAlpha = 1.0; + material.thickness = thickness; + material.attenuationDistance = attenuationDistance; + material.attenuationColor = attenuationColor; + #ifdef USE_TRANSMISSIONMAP + material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r; + #endif + #ifdef USE_THICKNESSMAP + material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g; + #endif + vec3 pos = vWorldPosition; + vec3 v = normalize( cameraPosition - pos ); + vec3 n = inverseTransformDirection( normal, viewMatrix ); + vec4 transmitted = getIBLVolumeRefraction( + n, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90, + pos, modelMatrix, viewMatrix, projectionMatrix, material.ior, material.thickness, + material.attenuationColor, material.attenuationDistance ); + material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission ); + totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission ); +#endif`,hu=`#ifdef USE_TRANSMISSION + uniform float transmission; + uniform float thickness; + uniform float attenuationDistance; + uniform vec3 attenuationColor; + #ifdef USE_TRANSMISSIONMAP + uniform sampler2D transmissionMap; + #endif + #ifdef USE_THICKNESSMAP + uniform sampler2D thicknessMap; + #endif + uniform vec2 transmissionSamplerSize; + uniform sampler2D transmissionSamplerMap; + uniform mat4 modelMatrix; + uniform mat4 projectionMatrix; + varying vec3 vWorldPosition; + float w0( float a ) { + return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 ); + } + float w1( float a ) { + return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 ); + } + float w2( float a ){ + return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 ); + } + float w3( float a ) { + return ( 1.0 / 6.0 ) * ( a * a * a ); + } + float g0( float a ) { + return w0( a ) + w1( a ); + } + float g1( float a ) { + return w2( a ) + w3( a ); + } + float h0( float a ) { + return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) ); + } + float h1( float a ) { + return 1.0 + w3( a ) / ( w2( a ) + w3( a ) ); + } + vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) { + uv = uv * texelSize.zw + 0.5; + vec2 iuv = floor( uv ); + vec2 fuv = fract( uv ); + float g0x = g0( fuv.x ); + float g1x = g1( fuv.x ); + float h0x = h0( fuv.x ); + float h1x = h1( fuv.x ); + float h0y = h0( fuv.y ); + float h1y = h1( fuv.y ); + vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy; + vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy; + vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy; + vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy; + return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) + + g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) ); + } + vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) { + vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) ); + vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) ); + vec2 fLodSizeInv = 1.0 / fLodSize; + vec2 cLodSizeInv = 1.0 / cLodSize; + vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) ); + vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) ); + return mix( fSample, cSample, fract( lod ) ); + } + vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) { + vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior ); + vec3 modelScale; + modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) ); + modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) ); + modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) ); + return normalize( refractionVector ) * thickness * modelScale; + } + float applyIorToRoughness( const in float roughness, const in float ior ) { + return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 ); + } + vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) { + float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior ); + return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod ); + } + vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) { + if ( isinf( attenuationDistance ) ) { + return vec3( 1.0 ); + } else { + vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance; + vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance; + } + } + vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor, + const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix, + const in mat4 viewMatrix, const in mat4 projMatrix, const in float ior, const in float thickness, + const in vec3 attenuationColor, const in float attenuationDistance ) { + vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix ); + vec3 refractedRayExit = position + transmissionRay; + vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 ); + vec2 refractionCoords = ndcPos.xy / ndcPos.w; + refractionCoords += 1.0; + refractionCoords /= 2.0; + vec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior ); + vec3 transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance ); + vec3 attenuatedColor = transmittance * transmittedLight.rgb; + vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness ); + float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0; + return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor ); + } +#endif`,uu=`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) + varying vec2 vUv; +#endif +#ifdef USE_MAP + varying vec2 vMapUv; +#endif +#ifdef USE_ALPHAMAP + varying vec2 vAlphaMapUv; +#endif +#ifdef USE_LIGHTMAP + varying vec2 vLightMapUv; +#endif +#ifdef USE_AOMAP + varying vec2 vAoMapUv; +#endif +#ifdef USE_BUMPMAP + varying vec2 vBumpMapUv; +#endif +#ifdef USE_NORMALMAP + varying vec2 vNormalMapUv; +#endif +#ifdef USE_EMISSIVEMAP + varying vec2 vEmissiveMapUv; +#endif +#ifdef USE_METALNESSMAP + varying vec2 vMetalnessMapUv; +#endif +#ifdef USE_ROUGHNESSMAP + varying vec2 vRoughnessMapUv; +#endif +#ifdef USE_ANISOTROPYMAP + varying vec2 vAnisotropyMapUv; +#endif +#ifdef USE_CLEARCOATMAP + varying vec2 vClearcoatMapUv; +#endif +#ifdef USE_CLEARCOAT_NORMALMAP + varying vec2 vClearcoatNormalMapUv; +#endif +#ifdef USE_CLEARCOAT_ROUGHNESSMAP + varying vec2 vClearcoatRoughnessMapUv; +#endif +#ifdef USE_IRIDESCENCEMAP + varying vec2 vIridescenceMapUv; +#endif +#ifdef USE_IRIDESCENCE_THICKNESSMAP + varying vec2 vIridescenceThicknessMapUv; +#endif +#ifdef USE_SHEEN_COLORMAP + varying vec2 vSheenColorMapUv; +#endif +#ifdef USE_SHEEN_ROUGHNESSMAP + varying vec2 vSheenRoughnessMapUv; +#endif +#ifdef USE_SPECULARMAP + varying vec2 vSpecularMapUv; +#endif +#ifdef USE_SPECULAR_COLORMAP + varying vec2 vSpecularColorMapUv; +#endif +#ifdef USE_SPECULAR_INTENSITYMAP + varying vec2 vSpecularIntensityMapUv; +#endif +#ifdef USE_TRANSMISSIONMAP + uniform mat3 transmissionMapTransform; + varying vec2 vTransmissionMapUv; +#endif +#ifdef USE_THICKNESSMAP + uniform mat3 thicknessMapTransform; + varying vec2 vThicknessMapUv; +#endif`,fu=`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) + varying vec2 vUv; +#endif +#ifdef USE_MAP + uniform mat3 mapTransform; + varying vec2 vMapUv; +#endif +#ifdef USE_ALPHAMAP + uniform mat3 alphaMapTransform; + varying vec2 vAlphaMapUv; +#endif +#ifdef USE_LIGHTMAP + uniform mat3 lightMapTransform; + varying vec2 vLightMapUv; +#endif +#ifdef USE_AOMAP + uniform mat3 aoMapTransform; + varying vec2 vAoMapUv; +#endif +#ifdef USE_BUMPMAP + uniform mat3 bumpMapTransform; + varying vec2 vBumpMapUv; +#endif +#ifdef USE_NORMALMAP + uniform mat3 normalMapTransform; + varying vec2 vNormalMapUv; +#endif +#ifdef USE_DISPLACEMENTMAP + uniform mat3 displacementMapTransform; + varying vec2 vDisplacementMapUv; +#endif +#ifdef USE_EMISSIVEMAP + uniform mat3 emissiveMapTransform; + varying vec2 vEmissiveMapUv; +#endif +#ifdef USE_METALNESSMAP + uniform mat3 metalnessMapTransform; + varying vec2 vMetalnessMapUv; +#endif +#ifdef USE_ROUGHNESSMAP + uniform mat3 roughnessMapTransform; + varying vec2 vRoughnessMapUv; +#endif +#ifdef USE_ANISOTROPYMAP + uniform mat3 anisotropyMapTransform; + varying vec2 vAnisotropyMapUv; +#endif +#ifdef USE_CLEARCOATMAP + uniform mat3 clearcoatMapTransform; + varying vec2 vClearcoatMapUv; +#endif +#ifdef USE_CLEARCOAT_NORMALMAP + uniform mat3 clearcoatNormalMapTransform; + varying vec2 vClearcoatNormalMapUv; +#endif +#ifdef USE_CLEARCOAT_ROUGHNESSMAP + uniform mat3 clearcoatRoughnessMapTransform; + varying vec2 vClearcoatRoughnessMapUv; +#endif +#ifdef USE_SHEEN_COLORMAP + uniform mat3 sheenColorMapTransform; + varying vec2 vSheenColorMapUv; +#endif +#ifdef USE_SHEEN_ROUGHNESSMAP + uniform mat3 sheenRoughnessMapTransform; + varying vec2 vSheenRoughnessMapUv; +#endif +#ifdef USE_IRIDESCENCEMAP + uniform mat3 iridescenceMapTransform; + varying vec2 vIridescenceMapUv; +#endif +#ifdef USE_IRIDESCENCE_THICKNESSMAP + uniform mat3 iridescenceThicknessMapTransform; + varying vec2 vIridescenceThicknessMapUv; +#endif +#ifdef USE_SPECULARMAP + uniform mat3 specularMapTransform; + varying vec2 vSpecularMapUv; +#endif +#ifdef USE_SPECULAR_COLORMAP + uniform mat3 specularColorMapTransform; + varying vec2 vSpecularColorMapUv; +#endif +#ifdef USE_SPECULAR_INTENSITYMAP + uniform mat3 specularIntensityMapTransform; + varying vec2 vSpecularIntensityMapUv; +#endif +#ifdef USE_TRANSMISSIONMAP + uniform mat3 transmissionMapTransform; + varying vec2 vTransmissionMapUv; +#endif +#ifdef USE_THICKNESSMAP + uniform mat3 thicknessMapTransform; + varying vec2 vThicknessMapUv; +#endif`,du=`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) + vUv = vec3( uv, 1 ).xy; +#endif +#ifdef USE_MAP + vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy; +#endif +#ifdef USE_ALPHAMAP + vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_LIGHTMAP + vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_AOMAP + vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_BUMPMAP + vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_NORMALMAP + vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_DISPLACEMENTMAP + vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_EMISSIVEMAP + vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_METALNESSMAP + vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_ROUGHNESSMAP + vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_ANISOTROPYMAP + vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_CLEARCOATMAP + vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_CLEARCOAT_NORMALMAP + vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_CLEARCOAT_ROUGHNESSMAP + vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_IRIDESCENCEMAP + vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_IRIDESCENCE_THICKNESSMAP + vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_SHEEN_COLORMAP + vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_SHEEN_ROUGHNESSMAP + vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_SPECULARMAP + vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_SPECULAR_COLORMAP + vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_SPECULAR_INTENSITYMAP + vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_TRANSMISSIONMAP + vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_THICKNESSMAP + vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy; +#endif`,pu=`#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0 + vec4 worldPosition = vec4( transformed, 1.0 ); + #ifdef USE_BATCHING + worldPosition = batchingMatrix * worldPosition; + #endif + #ifdef USE_INSTANCING + worldPosition = instanceMatrix * worldPosition; + #endif + worldPosition = modelMatrix * worldPosition; +#endif`;const mu=`varying vec2 vUv; +uniform mat3 uvTransform; +void main() { + vUv = ( uvTransform * vec3( uv, 1 ) ).xy; + gl_Position = vec4( position.xy, 1.0, 1.0 ); +}`,_u=`uniform sampler2D t2D; +uniform float backgroundIntensity; +varying vec2 vUv; +void main() { + vec4 texColor = texture2D( t2D, vUv ); + #ifdef DECODE_VIDEO_TEXTURE + texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w ); + #endif + texColor.rgb *= backgroundIntensity; + gl_FragColor = texColor; + #include + #include +}`,gu=`varying vec3 vWorldDirection; +#include +void main() { + vWorldDirection = transformDirection( position, modelMatrix ); + #include + #include + gl_Position.z = gl_Position.w; +}`,vu=`#ifdef ENVMAP_TYPE_CUBE + uniform samplerCube envMap; +#elif defined( ENVMAP_TYPE_CUBE_UV ) + uniform sampler2D envMap; +#endif +uniform float flipEnvMap; +uniform float backgroundBlurriness; +uniform float backgroundIntensity; +varying vec3 vWorldDirection; +#include +void main() { + #ifdef ENVMAP_TYPE_CUBE + vec4 texColor = textureCube( envMap, vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) ); + #elif defined( ENVMAP_TYPE_CUBE_UV ) + vec4 texColor = textureCubeUV( envMap, vWorldDirection, backgroundBlurriness ); + #else + vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 ); + #endif + texColor.rgb *= backgroundIntensity; + gl_FragColor = texColor; + #include + #include +}`,xu=`varying vec3 vWorldDirection; +#include +void main() { + vWorldDirection = transformDirection( position, modelMatrix ); + #include + #include + gl_Position.z = gl_Position.w; +}`,Mu=`uniform samplerCube tCube; +uniform float tFlip; +uniform float opacity; +varying vec3 vWorldDirection; +void main() { + vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) ); + gl_FragColor = texColor; + gl_FragColor.a *= opacity; + #include + #include +}`,Su=`#include +#include +#include +#include +#include +#include +#include +#include +varying vec2 vHighPrecisionZW; +void main() { + #include + #include + #include + #ifdef USE_DISPLACEMENTMAP + #include + #include + #include + #endif + #include + #include + #include + #include + #include + #include + #include + vHighPrecisionZW = gl_Position.zw; +}`,Eu=`#if DEPTH_PACKING == 3200 + uniform float opacity; +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +varying vec2 vHighPrecisionZW; +void main() { + #include + vec4 diffuseColor = vec4( 1.0 ); + #if DEPTH_PACKING == 3200 + diffuseColor.a = opacity; + #endif + #include + #include + #include + #include + #include + float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5; + #if DEPTH_PACKING == 3200 + gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity ); + #elif DEPTH_PACKING == 3201 + gl_FragColor = packDepthToRGBA( fragCoordZ ); + #endif +}`,yu=`#define DISTANCE +varying vec3 vWorldPosition; +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #ifdef USE_DISPLACEMENTMAP + #include + #include + #include + #endif + #include + #include + #include + #include + #include + #include + #include + vWorldPosition = worldPosition.xyz; +}`,Tu=`#define DISTANCE +uniform vec3 referencePosition; +uniform float nearDistance; +uniform float farDistance; +varying vec3 vWorldPosition; +#include +#include +#include +#include +#include +#include +#include +#include +void main () { + #include + vec4 diffuseColor = vec4( 1.0 ); + #include + #include + #include + #include + float dist = length( vWorldPosition - referencePosition ); + dist = ( dist - nearDistance ) / ( farDistance - nearDistance ); + dist = saturate( dist ); + gl_FragColor = packDepthToRGBA( dist ); +}`,Au=`varying vec3 vWorldDirection; +#include +void main() { + vWorldDirection = transformDirection( position, modelMatrix ); + #include + #include +}`,bu=`uniform sampler2D tEquirect; +varying vec3 vWorldDirection; +#include +void main() { + vec3 direction = normalize( vWorldDirection ); + vec2 sampleUV = equirectUv( direction ); + gl_FragColor = texture2D( tEquirect, sampleUV ); + #include + #include +}`,wu=`uniform float scale; +attribute float lineDistance; +varying float vLineDistance; +#include +#include +#include +#include +#include +#include +#include +void main() { + vLineDistance = scale * lineDistance; + #include + #include + #include + #include + #include + #include + #include + #include + #include +}`,Ru=`uniform vec3 diffuse; +uniform float opacity; +uniform float dashSize; +uniform float totalSize; +varying float vLineDistance; +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + if ( mod( vLineDistance, totalSize ) > dashSize ) { + discard; + } + vec3 outgoingLight = vec3( 0.0 ); + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + #include + #include + outgoingLight = diffuseColor.rgb; + #include + #include + #include + #include + #include +}`,Cu=`#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #if defined ( USE_ENVMAP ) || defined ( USE_SKINNING ) + #include + #include + #include + #include + #include + #endif + #include + #include + #include + #include + #include + #include + #include + #include + #include +}`,Lu=`uniform vec3 diffuse; +uniform float opacity; +#ifndef FLAT_SHADED + varying vec3 vNormal; +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + #include + #include + #include + #include + #include + #include + ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); + #ifdef USE_LIGHTMAP + vec4 lightMapTexel = texture2D( lightMap, vLightMapUv ); + reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI; + #else + reflectedLight.indirectDiffuse += vec3( 1.0 ); + #endif + #include + reflectedLight.indirectDiffuse *= diffuseColor.rgb; + vec3 outgoingLight = reflectedLight.indirectDiffuse; + #include + #include + #include + #include + #include + #include + #include +}`,Pu=`#define LAMBERT +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vViewPosition = - mvPosition.xyz; + #include + #include + #include + #include +}`,Du=`#define LAMBERT +uniform vec3 diffuse; +uniform vec3 emissive; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + vec4 diffuseColor = vec4( diffuse, opacity ); + ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); + vec3 totalEmissiveRadiance = emissive; + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance; + #include + #include + #include + #include + #include + #include + #include +}`,Uu=`#define MATCAP +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vViewPosition = - mvPosition.xyz; +}`,Iu=`#define MATCAP +uniform vec3 diffuse; +uniform float opacity; +uniform sampler2D matcap; +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + #include + #include + #include + #include + #include + #include + #include + vec3 viewDir = normalize( vViewPosition ); + vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) ); + vec3 y = cross( viewDir, x ); + vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5; + #ifdef USE_MATCAP + vec4 matcapColor = texture2D( matcap, uv ); + #else + vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 ); + #endif + vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb; + #include + #include + #include + #include + #include + #include +}`,Nu=`#define NORMAL +#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) + varying vec3 vViewPosition; +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include +#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) + vViewPosition = - mvPosition.xyz; +#endif +}`,Fu=`#define NORMAL +uniform float opacity; +#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) + varying vec3 vViewPosition; +#endif +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + gl_FragColor = vec4( packNormalToRGB( normal ), opacity ); + #ifdef OPAQUE + gl_FragColor.a = 1.0; + #endif +}`,Ou=`#define PHONG +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vViewPosition = - mvPosition.xyz; + #include + #include + #include + #include +}`,Bu=`#define PHONG +uniform vec3 diffuse; +uniform vec3 emissive; +uniform vec3 specular; +uniform float shininess; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + vec4 diffuseColor = vec4( diffuse, opacity ); + ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); + vec3 totalEmissiveRadiance = emissive; + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance; + #include + #include + #include + #include + #include + #include + #include +}`,zu=`#define STANDARD +varying vec3 vViewPosition; +#ifdef USE_TRANSMISSION + varying vec3 vWorldPosition; +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vViewPosition = - mvPosition.xyz; + #include + #include + #include +#ifdef USE_TRANSMISSION + vWorldPosition = worldPosition.xyz; +#endif +}`,Gu=`#define STANDARD +#ifdef PHYSICAL + #define IOR + #define USE_SPECULAR +#endif +uniform vec3 diffuse; +uniform vec3 emissive; +uniform float roughness; +uniform float metalness; +uniform float opacity; +#ifdef IOR + uniform float ior; +#endif +#ifdef USE_SPECULAR + uniform float specularIntensity; + uniform vec3 specularColor; + #ifdef USE_SPECULAR_COLORMAP + uniform sampler2D specularColorMap; + #endif + #ifdef USE_SPECULAR_INTENSITYMAP + uniform sampler2D specularIntensityMap; + #endif +#endif +#ifdef USE_CLEARCOAT + uniform float clearcoat; + uniform float clearcoatRoughness; +#endif +#ifdef USE_IRIDESCENCE + uniform float iridescence; + uniform float iridescenceIOR; + uniform float iridescenceThicknessMinimum; + uniform float iridescenceThicknessMaximum; +#endif +#ifdef USE_SHEEN + uniform vec3 sheenColor; + uniform float sheenRoughness; + #ifdef USE_SHEEN_COLORMAP + uniform sampler2D sheenColorMap; + #endif + #ifdef USE_SHEEN_ROUGHNESSMAP + uniform sampler2D sheenRoughnessMap; + #endif +#endif +#ifdef USE_ANISOTROPY + uniform vec2 anisotropyVector; + #ifdef USE_ANISOTROPYMAP + uniform sampler2D anisotropyMap; + #endif +#endif +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + vec4 diffuseColor = vec4( diffuse, opacity ); + ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); + vec3 totalEmissiveRadiance = emissive; + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse; + vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular; + #include + vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance; + #ifdef USE_SHEEN + float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor ); + outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect; + #endif + #ifdef USE_CLEARCOAT + float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) ); + vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc ); + outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat; + #endif + #include + #include + #include + #include + #include + #include +}`,Hu=`#define TOON +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vViewPosition = - mvPosition.xyz; + #include + #include + #include +}`,Vu=`#define TOON +uniform vec3 diffuse; +uniform vec3 emissive; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + vec4 diffuseColor = vec4( diffuse, opacity ); + ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); + vec3 totalEmissiveRadiance = emissive; + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance; + #include + #include + #include + #include + #include + #include +}`,ku=`uniform float size; +uniform float scale; +#include +#include +#include +#include +#include +#include +#ifdef USE_POINTS_UV + varying vec2 vUv; + uniform mat3 uvTransform; +#endif +void main() { + #ifdef USE_POINTS_UV + vUv = ( uvTransform * vec3( uv, 1 ) ).xy; + #endif + #include + #include + #include + #include + #include + gl_PointSize = size; + #ifdef USE_SIZEATTENUATION + bool isPerspective = isPerspectiveMatrix( projectionMatrix ); + if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z ); + #endif + #include + #include + #include + #include +}`,Wu=`uniform vec3 diffuse; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + vec3 outgoingLight = vec3( 0.0 ); + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + #include + #include + #include + #include + outgoingLight = diffuseColor.rgb; + #include + #include + #include + #include + #include +}`,Xu=`#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include +}`,qu=`uniform vec3 color; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) ); + #include + #include + #include +}`,Yu=`uniform float rotation; +uniform vec2 center; +#include +#include +#include +#include +#include +void main() { + #include + vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 ); + vec2 scale; + scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) ); + scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) ); + #ifndef USE_SIZEATTENUATION + bool isPerspective = isPerspectiveMatrix( projectionMatrix ); + if ( isPerspective ) scale *= - mvPosition.z; + #endif + vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale; + vec2 rotatedPosition; + rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y; + rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y; + mvPosition.xy += rotatedPosition; + gl_Position = projectionMatrix * mvPosition; + #include + #include + #include +}`,ju=`uniform vec3 diffuse; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + vec3 outgoingLight = vec3( 0.0 ); + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + #include + #include + #include + #include + outgoingLight = diffuseColor.rgb; + #include + #include + #include + #include +}`,Pe={alphahash_fragment:_c,alphahash_pars_fragment:gc,alphamap_fragment:vc,alphamap_pars_fragment:xc,alphatest_fragment:Mc,alphatest_pars_fragment:Sc,aomap_fragment:Ec,aomap_pars_fragment:yc,batching_pars_vertex:Tc,batching_vertex:Ac,begin_vertex:bc,beginnormal_vertex:wc,bsdfs:Rc,iridescence_fragment:Cc,bumpmap_pars_fragment:Lc,clipping_planes_fragment:Pc,clipping_planes_pars_fragment:Dc,clipping_planes_pars_vertex:Uc,clipping_planes_vertex:Ic,color_fragment:Nc,color_pars_fragment:Fc,color_pars_vertex:Oc,color_vertex:Bc,common:zc,cube_uv_reflection_fragment:Gc,defaultnormal_vertex:Hc,displacementmap_pars_vertex:Vc,displacementmap_vertex:kc,emissivemap_fragment:Wc,emissivemap_pars_fragment:Xc,colorspace_fragment:qc,colorspace_pars_fragment:Yc,envmap_fragment:jc,envmap_common_pars_fragment:Kc,envmap_pars_fragment:Zc,envmap_pars_vertex:$c,envmap_physical_pars_fragment:ch,envmap_vertex:Jc,fog_vertex:Qc,fog_pars_vertex:eh,fog_fragment:th,fog_pars_fragment:nh,gradientmap_pars_fragment:ih,lightmap_fragment:rh,lightmap_pars_fragment:sh,lights_lambert_fragment:ah,lights_lambert_pars_fragment:oh,lights_pars_begin:lh,lights_toon_fragment:hh,lights_toon_pars_fragment:uh,lights_phong_fragment:fh,lights_phong_pars_fragment:dh,lights_physical_fragment:ph,lights_physical_pars_fragment:mh,lights_fragment_begin:_h,lights_fragment_maps:gh,lights_fragment_end:vh,logdepthbuf_fragment:xh,logdepthbuf_pars_fragment:Mh,logdepthbuf_pars_vertex:Sh,logdepthbuf_vertex:Eh,map_fragment:yh,map_pars_fragment:Th,map_particle_fragment:Ah,map_particle_pars_fragment:bh,metalnessmap_fragment:wh,metalnessmap_pars_fragment:Rh,morphcolor_vertex:Ch,morphnormal_vertex:Lh,morphtarget_pars_vertex:Ph,morphtarget_vertex:Dh,normal_fragment_begin:Uh,normal_fragment_maps:Ih,normal_pars_fragment:Nh,normal_pars_vertex:Fh,normal_vertex:Oh,normalmap_pars_fragment:Bh,clearcoat_normal_fragment_begin:zh,clearcoat_normal_fragment_maps:Gh,clearcoat_pars_fragment:Hh,iridescence_pars_fragment:Vh,opaque_fragment:kh,packing:Wh,premultiplied_alpha_fragment:Xh,project_vertex:qh,dithering_fragment:Yh,dithering_pars_fragment:jh,roughnessmap_fragment:Kh,roughnessmap_pars_fragment:Zh,shadowmap_pars_fragment:$h,shadowmap_pars_vertex:Jh,shadowmap_vertex:Qh,shadowmask_pars_fragment:eu,skinbase_vertex:tu,skinning_pars_vertex:nu,skinning_vertex:iu,skinnormal_vertex:ru,specularmap_fragment:su,specularmap_pars_fragment:au,tonemapping_fragment:ou,tonemapping_pars_fragment:lu,transmission_fragment:cu,transmission_pars_fragment:hu,uv_pars_fragment:uu,uv_pars_vertex:fu,uv_vertex:du,worldpos_vertex:pu,background_vert:mu,background_frag:_u,backgroundCube_vert:gu,backgroundCube_frag:vu,cube_vert:xu,cube_frag:Mu,depth_vert:Su,depth_frag:Eu,distanceRGBA_vert:yu,distanceRGBA_frag:Tu,equirect_vert:Au,equirect_frag:bu,linedashed_vert:wu,linedashed_frag:Ru,meshbasic_vert:Cu,meshbasic_frag:Lu,meshlambert_vert:Pu,meshlambert_frag:Du,meshmatcap_vert:Uu,meshmatcap_frag:Iu,meshnormal_vert:Nu,meshnormal_frag:Fu,meshphong_vert:Ou,meshphong_frag:Bu,meshphysical_vert:zu,meshphysical_frag:Gu,meshtoon_vert:Hu,meshtoon_frag:Vu,points_vert:ku,points_frag:Wu,shadow_vert:Xu,shadow_frag:qu,sprite_vert:Yu,sprite_frag:ju},ne={common:{diffuse:{value:new Ge(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new Oe},alphaMap:{value:null},alphaMapTransform:{value:new Oe},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new Oe}},envmap:{envMap:{value:null},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new Oe}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new Oe}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new Oe},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new Oe},normalScale:{value:new ze(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new Oe},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new Oe}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new Oe}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new Oe}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new Ge(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new Ge(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new Oe},alphaTest:{value:0},uvTransform:{value:new Oe}},sprite:{diffuse:{value:new Ge(16777215)},opacity:{value:1},center:{value:new ze(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new Oe},alphaMap:{value:null},alphaMapTransform:{value:new Oe},alphaTest:{value:0}}},Gt={basic:{uniforms:xt([ne.common,ne.specularmap,ne.envmap,ne.aomap,ne.lightmap,ne.fog]),vertexShader:Pe.meshbasic_vert,fragmentShader:Pe.meshbasic_frag},lambert:{uniforms:xt([ne.common,ne.specularmap,ne.envmap,ne.aomap,ne.lightmap,ne.emissivemap,ne.bumpmap,ne.normalmap,ne.displacementmap,ne.fog,ne.lights,{emissive:{value:new Ge(0)}}]),vertexShader:Pe.meshlambert_vert,fragmentShader:Pe.meshlambert_frag},phong:{uniforms:xt([ne.common,ne.specularmap,ne.envmap,ne.aomap,ne.lightmap,ne.emissivemap,ne.bumpmap,ne.normalmap,ne.displacementmap,ne.fog,ne.lights,{emissive:{value:new Ge(0)},specular:{value:new Ge(1118481)},shininess:{value:30}}]),vertexShader:Pe.meshphong_vert,fragmentShader:Pe.meshphong_frag},standard:{uniforms:xt([ne.common,ne.envmap,ne.aomap,ne.lightmap,ne.emissivemap,ne.bumpmap,ne.normalmap,ne.displacementmap,ne.roughnessmap,ne.metalnessmap,ne.fog,ne.lights,{emissive:{value:new Ge(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Pe.meshphysical_vert,fragmentShader:Pe.meshphysical_frag},toon:{uniforms:xt([ne.common,ne.aomap,ne.lightmap,ne.emissivemap,ne.bumpmap,ne.normalmap,ne.displacementmap,ne.gradientmap,ne.fog,ne.lights,{emissive:{value:new Ge(0)}}]),vertexShader:Pe.meshtoon_vert,fragmentShader:Pe.meshtoon_frag},matcap:{uniforms:xt([ne.common,ne.bumpmap,ne.normalmap,ne.displacementmap,ne.fog,{matcap:{value:null}}]),vertexShader:Pe.meshmatcap_vert,fragmentShader:Pe.meshmatcap_frag},points:{uniforms:xt([ne.points,ne.fog]),vertexShader:Pe.points_vert,fragmentShader:Pe.points_frag},dashed:{uniforms:xt([ne.common,ne.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Pe.linedashed_vert,fragmentShader:Pe.linedashed_frag},depth:{uniforms:xt([ne.common,ne.displacementmap]),vertexShader:Pe.depth_vert,fragmentShader:Pe.depth_frag},normal:{uniforms:xt([ne.common,ne.bumpmap,ne.normalmap,ne.displacementmap,{opacity:{value:1}}]),vertexShader:Pe.meshnormal_vert,fragmentShader:Pe.meshnormal_frag},sprite:{uniforms:xt([ne.sprite,ne.fog]),vertexShader:Pe.sprite_vert,fragmentShader:Pe.sprite_frag},background:{uniforms:{uvTransform:{value:new Oe},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:Pe.background_vert,fragmentShader:Pe.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1}},vertexShader:Pe.backgroundCube_vert,fragmentShader:Pe.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:Pe.cube_vert,fragmentShader:Pe.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Pe.equirect_vert,fragmentShader:Pe.equirect_frag},distanceRGBA:{uniforms:xt([ne.common,ne.displacementmap,{referencePosition:{value:new P},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Pe.distanceRGBA_vert,fragmentShader:Pe.distanceRGBA_frag},shadow:{uniforms:xt([ne.lights,ne.fog,{color:{value:new Ge(0)},opacity:{value:1}}]),vertexShader:Pe.shadow_vert,fragmentShader:Pe.shadow_frag}};Gt.physical={uniforms:xt([Gt.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new Oe},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new Oe},clearcoatNormalScale:{value:new ze(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new Oe},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new Oe},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new Oe},sheen:{value:0},sheenColor:{value:new Ge(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new Oe},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new Oe},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new Oe},transmissionSamplerSize:{value:new ze},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new Oe},attenuationDistance:{value:0},attenuationColor:{value:new Ge(0)},specularColor:{value:new Ge(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new Oe},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new Oe},anisotropyVector:{value:new ze},anisotropyMap:{value:null},anisotropyMapTransform:{value:new Oe}}]),vertexShader:Pe.meshphysical_vert,fragmentShader:Pe.meshphysical_frag};const Gi={r:0,b:0,g:0};function Ku(i,e,t,n,r,s,o){const a=new Ge(0);let l=s===!0?0:1,c,u,f=null,d=0,m=null;function g(p,h){let E=!1,_=h.isScene===!0?h.background:null;_&&_.isTexture&&(_=(h.backgroundBlurriness>0?t:e).get(_)),_===null?x(a,l):_&&_.isColor&&(x(_,1),E=!0);const A=i.xr.getEnvironmentBlendMode();A==="additive"?n.buffers.color.setClear(0,0,0,1,o):A==="alpha-blend"&&n.buffers.color.setClear(0,0,0,0,o),(i.autoClear||E)&&i.clear(i.autoClearColor,i.autoClearDepth,i.autoClearStencil),_&&(_.isCubeTexture||_.mapping===er)?(u===void 0&&(u=new Ht(new gi(1,1,1),new Tn({name:"BackgroundCubeMaterial",uniforms:Jn(Gt.backgroundCube.uniforms),vertexShader:Gt.backgroundCube.vertexShader,fragmentShader:Gt.backgroundCube.fragmentShader,side:St,depthTest:!1,depthWrite:!1,fog:!1})),u.geometry.deleteAttribute("normal"),u.geometry.deleteAttribute("uv"),u.onBeforeRender=function(C,b,w){this.matrixWorld.copyPosition(w.matrixWorld)},Object.defineProperty(u.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),r.update(u)),u.material.uniforms.envMap.value=_,u.material.uniforms.flipEnvMap.value=_.isCubeTexture&&_.isRenderTargetTexture===!1?-1:1,u.material.uniforms.backgroundBlurriness.value=h.backgroundBlurriness,u.material.uniforms.backgroundIntensity.value=h.backgroundIntensity,u.material.toneMapped=We.getTransfer(_.colorSpace)!==je,(f!==_||d!==_.version||m!==i.toneMapping)&&(u.material.needsUpdate=!0,f=_,d=_.version,m=i.toneMapping),u.layers.enableAll(),p.unshift(u,u.geometry,u.material,0,0,null)):_&&_.isTexture&&(c===void 0&&(c=new Ht(new rs(2,2),new Tn({name:"BackgroundMaterial",uniforms:Jn(Gt.background.uniforms),vertexShader:Gt.background.vertexShader,fragmentShader:Gt.background.fragmentShader,side:cn,depthTest:!1,depthWrite:!1,fog:!1})),c.geometry.deleteAttribute("normal"),Object.defineProperty(c.material,"map",{get:function(){return this.uniforms.t2D.value}}),r.update(c)),c.material.uniforms.t2D.value=_,c.material.uniforms.backgroundIntensity.value=h.backgroundIntensity,c.material.toneMapped=We.getTransfer(_.colorSpace)!==je,_.matrixAutoUpdate===!0&&_.updateMatrix(),c.material.uniforms.uvTransform.value.copy(_.matrix),(f!==_||d!==_.version||m!==i.toneMapping)&&(c.material.needsUpdate=!0,f=_,d=_.version,m=i.toneMapping),c.layers.enableAll(),p.unshift(c,c.geometry,c.material,0,0,null))}function x(p,h){p.getRGB(Gi,co(i)),n.buffers.color.setClear(Gi.r,Gi.g,Gi.b,h,o)}return{getClearColor:function(){return a},setClearColor:function(p,h=1){a.set(p),l=h,x(a,l)},getClearAlpha:function(){return l},setClearAlpha:function(p){l=p,x(a,l)},render:g}}function Zu(i,e,t,n){const r=i.getParameter(i.MAX_VERTEX_ATTRIBS),s=n.isWebGL2?null:e.get("OES_vertex_array_object"),o=n.isWebGL2||s!==null,a={},l=p(null);let c=l,u=!1;function f(L,U,k,q,X){let W=!1;if(o){const Z=x(q,k,U);c!==Z&&(c=Z,m(c.object)),W=h(L,q,k,X),W&&E(L,q,k,X)}else{const Z=U.wireframe===!0;(c.geometry!==q.id||c.program!==k.id||c.wireframe!==Z)&&(c.geometry=q.id,c.program=k.id,c.wireframe=Z,W=!0)}X!==null&&t.update(X,i.ELEMENT_ARRAY_BUFFER),(W||u)&&(u=!1,z(L,U,k,q),X!==null&&i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,t.get(X).buffer))}function d(){return n.isWebGL2?i.createVertexArray():s.createVertexArrayOES()}function m(L){return n.isWebGL2?i.bindVertexArray(L):s.bindVertexArrayOES(L)}function g(L){return n.isWebGL2?i.deleteVertexArray(L):s.deleteVertexArrayOES(L)}function x(L,U,k){const q=k.wireframe===!0;let X=a[L.id];X===void 0&&(X={},a[L.id]=X);let W=X[U.id];W===void 0&&(W={},X[U.id]=W);let Z=W[q];return Z===void 0&&(Z=p(d()),W[q]=Z),Z}function p(L){const U=[],k=[],q=[];for(let X=0;X=0){const Y=X[le];let ae=W[le];if(ae===void 0&&(le==="instanceMatrix"&&L.instanceMatrix&&(ae=L.instanceMatrix),le==="instanceColor"&&L.instanceColor&&(ae=L.instanceColor)),Y===void 0||Y.attribute!==ae||ae&&Y.data!==ae.data)return!0;Z++}return c.attributesNum!==Z||c.index!==q}function E(L,U,k,q){const X={},W=U.attributes;let Z=0;const Q=k.getAttributes();for(const le in Q)if(Q[le].location>=0){let Y=W[le];Y===void 0&&(le==="instanceMatrix"&&L.instanceMatrix&&(Y=L.instanceMatrix),le==="instanceColor"&&L.instanceColor&&(Y=L.instanceColor));const ae={};ae.attribute=Y,Y&&Y.data&&(ae.data=Y.data),X[le]=ae,Z++}c.attributes=X,c.attributesNum=Z,c.index=q}function _(){const L=c.newAttributes;for(let U=0,k=L.length;U=0){let H=X[Q];if(H===void 0&&(Q==="instanceMatrix"&&L.instanceMatrix&&(H=L.instanceMatrix),Q==="instanceColor"&&L.instanceColor&&(H=L.instanceColor)),H!==void 0){const Y=H.normalized,ae=H.itemSize,me=t.get(H);if(me===void 0)continue;const pe=me.buffer,we=me.type,Ce=me.bytesPerElement,Se=n.isWebGL2===!0&&(we===i.INT||we===i.UNSIGNED_INT||H.gpuType===qa);if(H.isInterleavedBufferAttribute){const He=H.data,I=He.stride,mt=H.offset;if(He.isInstancedInterleavedBuffer){for(let ge=0;ge0&&i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.HIGH_FLOAT).precision>0)return"highp";w="mediump"}return w==="mediump"&&i.getShaderPrecisionFormat(i.VERTEX_SHADER,i.MEDIUM_FLOAT).precision>0&&i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}const o=typeof WebGL2RenderingContext<"u"&&i.constructor.name==="WebGL2RenderingContext";let a=t.precision!==void 0?t.precision:"highp";const l=s(a);l!==a&&(console.warn("THREE.WebGLRenderer:",a,"not supported, using",l,"instead."),a=l);const c=o||e.has("WEBGL_draw_buffers"),u=t.logarithmicDepthBuffer===!0,f=i.getParameter(i.MAX_TEXTURE_IMAGE_UNITS),d=i.getParameter(i.MAX_VERTEX_TEXTURE_IMAGE_UNITS),m=i.getParameter(i.MAX_TEXTURE_SIZE),g=i.getParameter(i.MAX_CUBE_MAP_TEXTURE_SIZE),x=i.getParameter(i.MAX_VERTEX_ATTRIBS),p=i.getParameter(i.MAX_VERTEX_UNIFORM_VECTORS),h=i.getParameter(i.MAX_VARYING_VECTORS),E=i.getParameter(i.MAX_FRAGMENT_UNIFORM_VECTORS),_=d>0,A=o||e.has("OES_texture_float"),C=_&&A,b=o?i.getParameter(i.MAX_SAMPLES):0;return{isWebGL2:o,drawBuffers:c,getMaxAnisotropy:r,getMaxPrecision:s,precision:a,logarithmicDepthBuffer:u,maxTextures:f,maxVertexTextures:d,maxTextureSize:m,maxCubemapSize:g,maxAttributes:x,maxVertexUniforms:p,maxVaryings:h,maxFragmentUniforms:E,vertexTextures:_,floatFragmentTextures:A,floatVertexTextures:C,maxSamples:b}}function Qu(i){const e=this;let t=null,n=0,r=!1,s=!1;const o=new _n,a=new Oe,l={value:null,needsUpdate:!1};this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(f,d){const m=f.length!==0||d||n!==0||r;return r=d,n=f.length,m},this.beginShadows=function(){s=!0,u(null)},this.endShadows=function(){s=!1},this.setGlobalState=function(f,d){t=u(f,d,0)},this.setState=function(f,d,m){const g=f.clippingPlanes,x=f.clipIntersection,p=f.clipShadows,h=i.get(f);if(!r||g===null||g.length===0||s&&!p)s?u(null):c();else{const E=s?0:n,_=E*4;let A=h.clippingState||null;l.value=A,A=u(g,d,_,m);for(let C=0;C!==_;++C)A[C]=t[C];h.clippingState=A,this.numIntersection=x?this.numPlanes:0,this.numPlanes+=E}};function c(){l.value!==t&&(l.value=t,l.needsUpdate=n>0),e.numPlanes=n,e.numIntersection=0}function u(f,d,m,g){const x=f!==null?f.length:0;let p=null;if(x!==0){if(p=l.value,g!==!0||p===null){const h=m+x*4,E=d.matrixWorldInverse;a.getNormalMatrix(E),(p===null||p.length0){const c=new fc(l.height/2);return c.fromEquirectangularTexture(i,o),e.set(o,c),o.addEventListener("dispose",r),t(c.texture,o.mapping)}else return null}}return o}function r(o){const a=o.target;a.removeEventListener("dispose",r);const l=e.get(a);l!==void 0&&(e.delete(a),l.dispose())}function s(){e=new WeakMap}return{get:n,dispose:s}}class po extends ho{constructor(e=-1,t=1,n=1,r=-1,s=.1,o=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=n,this.bottom=r,this.near=s,this.far=o,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=e.view===null?null:Object.assign({},e.view),this}setViewOffset(e,t,n,r,s,o){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=n,this.view.offsetY=r,this.view.width=s,this.view.height=o,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),n=(this.right+this.left)/2,r=(this.top+this.bottom)/2;let s=n-e,o=n+e,a=r+t,l=r-t;if(this.view!==null&&this.view.enabled){const c=(this.right-this.left)/this.view.fullWidth/this.zoom,u=(this.top-this.bottom)/this.view.fullHeight/this.zoom;s+=c*this.view.offsetX,o=s+c*this.view.width,a-=u*this.view.offsetY,l=a-u*this.view.height}this.projectionMatrix.makeOrthographic(s,o,a,l,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.zoom=this.zoom,t.object.left=this.left,t.object.right=this.right,t.object.top=this.top,t.object.bottom=this.bottom,t.object.near=this.near,t.object.far=this.far,this.view!==null&&(t.object.view=Object.assign({},this.view)),t}}const Xn=4,ua=[.125,.215,.35,.446,.526,.582],xn=20,Pr=new po,fa=new Ge;let Dr=null,Ur=0,Ir=0;const gn=(1+Math.sqrt(5))/2,Vn=1/gn,da=[new P(1,1,1),new P(-1,1,1),new P(1,1,-1),new P(-1,1,-1),new P(0,gn,Vn),new P(0,gn,-Vn),new P(Vn,0,gn),new P(-Vn,0,gn),new P(gn,Vn,0),new P(-gn,Vn,0)];class pa{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._compileMaterial(this._blurMaterial)}fromScene(e,t=0,n=.1,r=100){Dr=this._renderer.getRenderTarget(),Ur=this._renderer.getActiveCubeFace(),Ir=this._renderer.getActiveMipmapLevel(),this._setSize(256);const s=this._allocateTargets();return s.depthBuffer=!0,this._sceneToCubeUV(e,n,r,s),t>0&&this._blur(s,0,0,t),this._applyPMREM(s),this._cleanup(s),s}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=ga(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=_a(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose()}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e2?_:0,_,_),u.setRenderTarget(r),x&&u.render(g,a),u.render(e,a)}g.geometry.dispose(),g.material.dispose(),u.toneMapping=d,u.autoClear=f,e.background=p}_textureToCubeUV(e,t){const n=this._renderer,r=e.mapping===Kn||e.mapping===Zn;r?(this._cubemapMaterial===null&&(this._cubemapMaterial=ga()),this._cubemapMaterial.uniforms.flipEnvMap.value=e.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=_a());const s=r?this._cubemapMaterial:this._equirectMaterial,o=new Ht(this._lodPlanes[0],s),a=s.uniforms;a.envMap.value=e;const l=this._cubeSize;Hi(t,0,0,3*l,2*l),n.setRenderTarget(t),n.render(o,Pr)}_applyPMREM(e){const t=this._renderer,n=t.autoClear;t.autoClear=!1;for(let r=1;rxn&&console.warn(`sigmaRadians, ${s}, is too large and will clip, as it requested ${p} samples when the maximum is set to ${xn}`);const h=[];let E=0;for(let w=0;w_-Xn?r-_+Xn:0),b=4*(this._cubeSize-A);Hi(t,C,b,3*A,2*A),l.setRenderTarget(t),l.render(f,Pr)}}function tf(i){const e=[],t=[],n=[];let r=i;const s=i-Xn+1+ua.length;for(let o=0;oi-Xn?l=ua[o-i+Xn-1]:o===0&&(l=0),n.push(l);const c=1/(a-2),u=-c,f=1+c,d=[u,u,f,u,f,f,u,u,f,f,u,f],m=6,g=6,x=3,p=2,h=1,E=new Float32Array(x*g*m),_=new Float32Array(p*g*m),A=new Float32Array(h*g*m);for(let b=0;b2?0:-1,M=[w,z,0,w+2/3,z,0,w+2/3,z+1,0,w,z,0,w+2/3,z+1,0,w,z+1,0];E.set(M,x*g*b),_.set(d,p*g*b);const T=[b,b,b,b,b,b];A.set(T,h*g*b)}const C=new Lt;C.setAttribute("position",new Bt(E,x)),C.setAttribute("uv",new Bt(_,p)),C.setAttribute("faceIndex",new Bt(A,h)),e.push(C),r>Xn&&r--}return{lodPlanes:e,sizeLods:t,sigmas:n}}function ma(i,e,t){const n=new yn(i,e,t);return n.texture.mapping=er,n.texture.name="PMREM.cubeUv",n.scissorTest=!0,n}function Hi(i,e,t,n,r){i.viewport.set(e,t,n,r),i.scissor.set(e,t,n,r)}function nf(i,e,t){const n=new Float32Array(xn),r=new P(0,1,0);return new Tn({name:"SphericalGaussianBlur",defines:{n:xn,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/t,CUBEUV_MAX_MIP:`${i}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:n},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:r}},vertexShader:ss(),fragmentShader:` + + precision mediump float; + precision mediump int; + + varying vec3 vOutputDirection; + + uniform sampler2D envMap; + uniform int samples; + uniform float weights[ n ]; + uniform bool latitudinal; + uniform float dTheta; + uniform float mipInt; + uniform vec3 poleAxis; + + #define ENVMAP_TYPE_CUBE_UV + #include + + vec3 getSample( float theta, vec3 axis ) { + + float cosTheta = cos( theta ); + // Rodrigues' axis-angle rotation + vec3 sampleDirection = vOutputDirection * cosTheta + + cross( axis, vOutputDirection ) * sin( theta ) + + axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta ); + + return bilinearCubeUV( envMap, sampleDirection, mipInt ); + + } + + void main() { + + vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection ); + + if ( all( equal( axis, vec3( 0.0 ) ) ) ) { + + axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x ); + + } + + axis = normalize( axis ); + + gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 ); + gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis ); + + for ( int i = 1; i < n; i++ ) { + + if ( i >= samples ) { + + break; + + } + + float theta = dTheta * float( i ); + gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis ); + gl_FragColor.rgb += weights[ i ] * getSample( theta, axis ); + + } + + } + `,blending:an,depthTest:!1,depthWrite:!1})}function _a(){return new Tn({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:ss(),fragmentShader:` + + precision mediump float; + precision mediump int; + + varying vec3 vOutputDirection; + + uniform sampler2D envMap; + + #include + + void main() { + + vec3 outputDirection = normalize( vOutputDirection ); + vec2 uv = equirectUv( outputDirection ); + + gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 ); + + } + `,blending:an,depthTest:!1,depthWrite:!1})}function ga(){return new Tn({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:ss(),fragmentShader:` + + precision mediump float; + precision mediump int; + + uniform float flipEnvMap; + + varying vec3 vOutputDirection; + + uniform samplerCube envMap; + + void main() { + + gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) ); + + } + `,blending:an,depthTest:!1,depthWrite:!1})}function ss(){return` + + precision mediump float; + precision mediump int; + + attribute float faceIndex; + + varying vec3 vOutputDirection; + + // RH coordinate system; PMREM face-indexing convention + vec3 getDirection( vec2 uv, float face ) { + + uv = 2.0 * uv - 1.0; + + vec3 direction = vec3( uv, 1.0 ); + + if ( face == 0.0 ) { + + direction = direction.zyx; // ( 1, v, u ) pos x + + } else if ( face == 1.0 ) { + + direction = direction.xzy; + direction.xz *= -1.0; // ( -u, 1, -v ) pos y + + } else if ( face == 2.0 ) { + + direction.x *= -1.0; // ( -u, v, 1 ) pos z + + } else if ( face == 3.0 ) { + + direction = direction.zyx; + direction.xz *= -1.0; // ( -1, v, -u ) neg x + + } else if ( face == 4.0 ) { + + direction = direction.xzy; + direction.xy *= -1.0; // ( -u, -1, v ) neg y + + } else if ( face == 5.0 ) { + + direction.z *= -1.0; // ( u, v, -1 ) neg z + + } + + return direction; + + } + + void main() { + + vOutputDirection = getDirection( uv, faceIndex ); + gl_Position = vec4( position, 1.0 ); + + } + `}function rf(i){let e=new WeakMap,t=null;function n(a){if(a&&a.isTexture){const l=a.mapping,c=l===Hr||l===Vr,u=l===Kn||l===Zn;if(c||u)if(a.isRenderTargetTexture&&a.needsPMREMUpdate===!0){a.needsPMREMUpdate=!1;let f=e.get(a);return t===null&&(t=new pa(i)),f=c?t.fromEquirectangular(a,f):t.fromCubemap(a,f),e.set(a,f),f.texture}else{if(e.has(a))return e.get(a).texture;{const f=a.image;if(c&&f&&f.height>0||u&&f&&r(f)){t===null&&(t=new pa(i));const d=c?t.fromEquirectangular(a):t.fromCubemap(a);return e.set(a,d),a.addEventListener("dispose",s),d.texture}else return null}}}return a}function r(a){let l=0;const c=6;for(let u=0;ue.maxTextureSize&&(T=Math.ceil(M/e.maxTextureSize),M=e.maxTextureSize);const B=new Float32Array(M*T*4*g),V=new ro(B,M,T,g);V.type=sn,V.needsUpdate=!0;const ee=z*4;for(let U=0;U0)return i;const r=e*t;let s=va[r];if(s===void 0&&(s=new Float32Array(r),va[r]=s),e!==0){n.toArray(s,0);for(let o=1,a=0;o!==e;++o)a+=t,i[o].toArray(s,a)}return s}function it(i,e){if(i.length!==e.length)return!1;for(let t=0,n=i.length;t":" "} ${a}: ${t[o]}`)}return n.join(` +`)}function ad(i){const e=We.getPrimaries(We.workingColorSpace),t=We.getPrimaries(i);let n;switch(e===t?n="":e===Zi&&t===Ki?n="LinearDisplayP3ToLinearSRGB":e===Ki&&t===Zi&&(n="LinearSRGBToLinearDisplayP3"),i){case $t:case tr:return[n,"LinearTransferOETF"];case ct:case Qr:return[n,"sRGBTransferOETF"];default:return console.warn("THREE.WebGLProgram: Unsupported color space:",i),[n,"LinearTransferOETF"]}}function Aa(i,e,t){const n=i.getShaderParameter(e,i.COMPILE_STATUS),r=i.getShaderInfoLog(e).trim();if(n&&r==="")return"";const s=/ERROR: 0:(\d+)/.exec(r);if(s){const o=parseInt(s[1]);return t.toUpperCase()+` + +`+r+` + +`+sd(i.getShaderSource(e),o)}else return r}function od(i,e){const t=ad(e);return`vec4 ${i}( vec4 value ) { return ${t[0]}( ${t[1]}( value ) ); }`}function ld(i,e){let t;switch(e){case sl:t="Linear";break;case al:t="Reinhard";break;case ol:t="OptimizedCineon";break;case ll:t="ACESFilmic";break;case hl:t="AgX";break;case cl:t="Custom";break;default:console.warn("THREE.WebGLProgram: Unsupported toneMapping:",e),t="Linear"}return"vec3 "+i+"( vec3 color ) { return "+t+"ToneMapping( color ); }"}function cd(i){return[i.extensionDerivatives||i.envMapCubeUVHeight||i.bumpMap||i.normalMapTangentSpace||i.clearcoatNormalMap||i.flatShading||i.shaderID==="physical"?"#extension GL_OES_standard_derivatives : enable":"",(i.extensionFragDepth||i.logarithmicDepthBuffer)&&i.rendererExtensionFragDepth?"#extension GL_EXT_frag_depth : enable":"",i.extensionDrawBuffers&&i.rendererExtensionDrawBuffers?"#extension GL_EXT_draw_buffers : require":"",(i.extensionShaderTextureLOD||i.envMap||i.transmission)&&i.rendererExtensionShaderTextureLod?"#extension GL_EXT_shader_texture_lod : enable":""].filter(qn).join(` +`)}function hd(i){return[i.extensionClipCullDistance?"#extension GL_ANGLE_clip_cull_distance : require":""].filter(qn).join(` +`)}function ud(i){const e=[];for(const t in i){const n=i[t];n!==!1&&e.push("#define "+t+" "+n)}return e.join(` +`)}function fd(i,e){const t={},n=i.getProgramParameter(e,i.ACTIVE_ATTRIBUTES);for(let r=0;r/gm;function Yr(i){return i.replace(dd,md)}const pd=new Map([["encodings_fragment","colorspace_fragment"],["encodings_pars_fragment","colorspace_pars_fragment"],["output_fragment","opaque_fragment"]]);function md(i,e){let t=Pe[e];if(t===void 0){const n=pd.get(e);if(n!==void 0)t=Pe[n],console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',e,n);else throw new Error("Can not resolve #include <"+e+">")}return Yr(t)}const _d=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function Ra(i){return i.replace(_d,gd)}function gd(i,e,t,n){let r="";for(let s=parseInt(e);s0&&(h+=` +`),E=[m,"#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,x].filter(qn).join(` +`),E.length>0&&(E+=` +`)):(h=[Ca(t),"#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,x,t.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",t.batching?"#define USE_BATCHING":"",t.instancing?"#define USE_INSTANCING":"",t.instancingColor?"#define USE_INSTANCING_COLOR":"",t.useFog&&t.fog?"#define USE_FOG":"",t.useFog&&t.fogExp2?"#define FOG_EXP2":"",t.map?"#define USE_MAP":"",t.envMap?"#define USE_ENVMAP":"",t.envMap?"#define "+u:"",t.lightMap?"#define USE_LIGHTMAP":"",t.aoMap?"#define USE_AOMAP":"",t.bumpMap?"#define USE_BUMPMAP":"",t.normalMap?"#define USE_NORMALMAP":"",t.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",t.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",t.displacementMap?"#define USE_DISPLACEMENTMAP":"",t.emissiveMap?"#define USE_EMISSIVEMAP":"",t.anisotropy?"#define USE_ANISOTROPY":"",t.anisotropyMap?"#define USE_ANISOTROPYMAP":"",t.clearcoatMap?"#define USE_CLEARCOATMAP":"",t.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",t.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",t.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",t.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",t.specularMap?"#define USE_SPECULARMAP":"",t.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",t.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",t.roughnessMap?"#define USE_ROUGHNESSMAP":"",t.metalnessMap?"#define USE_METALNESSMAP":"",t.alphaMap?"#define USE_ALPHAMAP":"",t.alphaHash?"#define USE_ALPHAHASH":"",t.transmission?"#define USE_TRANSMISSION":"",t.transmissionMap?"#define USE_TRANSMISSIONMAP":"",t.thicknessMap?"#define USE_THICKNESSMAP":"",t.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",t.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",t.mapUv?"#define MAP_UV "+t.mapUv:"",t.alphaMapUv?"#define ALPHAMAP_UV "+t.alphaMapUv:"",t.lightMapUv?"#define LIGHTMAP_UV "+t.lightMapUv:"",t.aoMapUv?"#define AOMAP_UV "+t.aoMapUv:"",t.emissiveMapUv?"#define EMISSIVEMAP_UV "+t.emissiveMapUv:"",t.bumpMapUv?"#define BUMPMAP_UV "+t.bumpMapUv:"",t.normalMapUv?"#define NORMALMAP_UV "+t.normalMapUv:"",t.displacementMapUv?"#define DISPLACEMENTMAP_UV "+t.displacementMapUv:"",t.metalnessMapUv?"#define METALNESSMAP_UV "+t.metalnessMapUv:"",t.roughnessMapUv?"#define ROUGHNESSMAP_UV "+t.roughnessMapUv:"",t.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+t.anisotropyMapUv:"",t.clearcoatMapUv?"#define CLEARCOATMAP_UV "+t.clearcoatMapUv:"",t.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+t.clearcoatNormalMapUv:"",t.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+t.clearcoatRoughnessMapUv:"",t.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+t.iridescenceMapUv:"",t.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+t.iridescenceThicknessMapUv:"",t.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+t.sheenColorMapUv:"",t.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+t.sheenRoughnessMapUv:"",t.specularMapUv?"#define SPECULARMAP_UV "+t.specularMapUv:"",t.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+t.specularColorMapUv:"",t.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+t.specularIntensityMapUv:"",t.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+t.transmissionMapUv:"",t.thicknessMapUv?"#define THICKNESSMAP_UV "+t.thicknessMapUv:"",t.vertexTangents&&t.flatShading===!1?"#define USE_TANGENT":"",t.vertexColors?"#define USE_COLOR":"",t.vertexAlphas?"#define USE_COLOR_ALPHA":"",t.vertexUv1s?"#define USE_UV1":"",t.vertexUv2s?"#define USE_UV2":"",t.vertexUv3s?"#define USE_UV3":"",t.pointsUvs?"#define USE_POINTS_UV":"",t.flatShading?"#define FLAT_SHADED":"",t.skinning?"#define USE_SKINNING":"",t.morphTargets?"#define USE_MORPHTARGETS":"",t.morphNormals&&t.flatShading===!1?"#define USE_MORPHNORMALS":"",t.morphColors&&t.isWebGL2?"#define USE_MORPHCOLORS":"",t.morphTargetsCount>0&&t.isWebGL2?"#define MORPHTARGETS_TEXTURE":"",t.morphTargetsCount>0&&t.isWebGL2?"#define MORPHTARGETS_TEXTURE_STRIDE "+t.morphTextureStride:"",t.morphTargetsCount>0&&t.isWebGL2?"#define MORPHTARGETS_COUNT "+t.morphTargetsCount:"",t.doubleSided?"#define DOUBLE_SIDED":"",t.flipSided?"#define FLIP_SIDED":"",t.shadowMapEnabled?"#define USE_SHADOWMAP":"",t.shadowMapEnabled?"#define "+l:"",t.sizeAttenuation?"#define USE_SIZEATTENUATION":"",t.numLightProbes>0?"#define USE_LIGHT_PROBES":"",t.useLegacyLights?"#define LEGACY_LIGHTS":"",t.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",t.logarithmicDepthBuffer&&t.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING"," attribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR"," attribute vec3 instanceColor;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1"," attribute vec2 uv1;","#endif","#ifdef USE_UV2"," attribute vec2 uv2;","#endif","#ifdef USE_UV3"," attribute vec2 uv3;","#endif","#ifdef USE_TANGENT"," attribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )"," attribute vec4 color;","#elif defined( USE_COLOR )"," attribute vec3 color;","#endif","#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )"," attribute vec3 morphTarget0;"," attribute vec3 morphTarget1;"," attribute vec3 morphTarget2;"," attribute vec3 morphTarget3;"," #ifdef USE_MORPHNORMALS"," attribute vec3 morphNormal0;"," attribute vec3 morphNormal1;"," attribute vec3 morphNormal2;"," attribute vec3 morphNormal3;"," #else"," attribute vec3 morphTarget4;"," attribute vec3 morphTarget5;"," attribute vec3 morphTarget6;"," attribute vec3 morphTarget7;"," #endif","#endif","#ifdef USE_SKINNING"," attribute vec4 skinIndex;"," attribute vec4 skinWeight;","#endif",` +`].filter(qn).join(` +`),E=[m,Ca(t),"#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,x,t.useFog&&t.fog?"#define USE_FOG":"",t.useFog&&t.fogExp2?"#define FOG_EXP2":"",t.map?"#define USE_MAP":"",t.matcap?"#define USE_MATCAP":"",t.envMap?"#define USE_ENVMAP":"",t.envMap?"#define "+c:"",t.envMap?"#define "+u:"",t.envMap?"#define "+f:"",d?"#define CUBEUV_TEXEL_WIDTH "+d.texelWidth:"",d?"#define CUBEUV_TEXEL_HEIGHT "+d.texelHeight:"",d?"#define CUBEUV_MAX_MIP "+d.maxMip+".0":"",t.lightMap?"#define USE_LIGHTMAP":"",t.aoMap?"#define USE_AOMAP":"",t.bumpMap?"#define USE_BUMPMAP":"",t.normalMap?"#define USE_NORMALMAP":"",t.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",t.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",t.emissiveMap?"#define USE_EMISSIVEMAP":"",t.anisotropy?"#define USE_ANISOTROPY":"",t.anisotropyMap?"#define USE_ANISOTROPYMAP":"",t.clearcoat?"#define USE_CLEARCOAT":"",t.clearcoatMap?"#define USE_CLEARCOATMAP":"",t.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",t.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",t.iridescence?"#define USE_IRIDESCENCE":"",t.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",t.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",t.specularMap?"#define USE_SPECULARMAP":"",t.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",t.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",t.roughnessMap?"#define USE_ROUGHNESSMAP":"",t.metalnessMap?"#define USE_METALNESSMAP":"",t.alphaMap?"#define USE_ALPHAMAP":"",t.alphaTest?"#define USE_ALPHATEST":"",t.alphaHash?"#define USE_ALPHAHASH":"",t.sheen?"#define USE_SHEEN":"",t.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",t.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",t.transmission?"#define USE_TRANSMISSION":"",t.transmissionMap?"#define USE_TRANSMISSIONMAP":"",t.thicknessMap?"#define USE_THICKNESSMAP":"",t.vertexTangents&&t.flatShading===!1?"#define USE_TANGENT":"",t.vertexColors||t.instancingColor?"#define USE_COLOR":"",t.vertexAlphas?"#define USE_COLOR_ALPHA":"",t.vertexUv1s?"#define USE_UV1":"",t.vertexUv2s?"#define USE_UV2":"",t.vertexUv3s?"#define USE_UV3":"",t.pointsUvs?"#define USE_POINTS_UV":"",t.gradientMap?"#define USE_GRADIENTMAP":"",t.flatShading?"#define FLAT_SHADED":"",t.doubleSided?"#define DOUBLE_SIDED":"",t.flipSided?"#define FLIP_SIDED":"",t.shadowMapEnabled?"#define USE_SHADOWMAP":"",t.shadowMapEnabled?"#define "+l:"",t.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",t.numLightProbes>0?"#define USE_LIGHT_PROBES":"",t.useLegacyLights?"#define LEGACY_LIGHTS":"",t.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",t.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",t.logarithmicDepthBuffer&&t.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",t.toneMapping!==on?"#define TONE_MAPPING":"",t.toneMapping!==on?Pe.tonemapping_pars_fragment:"",t.toneMapping!==on?ld("toneMapping",t.toneMapping):"",t.dithering?"#define DITHERING":"",t.opaque?"#define OPAQUE":"",Pe.colorspace_pars_fragment,od("linearToOutputTexel",t.outputColorSpace),t.useDepthPacking?"#define DEPTH_PACKING "+t.depthPacking:"",` +`].filter(qn).join(` +`)),o=Yr(o),o=ba(o,t),o=wa(o,t),a=Yr(a),a=ba(a,t),a=wa(a,t),o=Ra(o),a=Ra(a),t.isWebGL2&&t.isRawShaderMaterial!==!0&&(_=`#version 300 es +`,h=[g,"precision mediump sampler2DArray;","#define attribute in","#define varying out","#define texture2D texture"].join(` +`)+` +`+h,E=["precision mediump sampler2DArray;","#define varying in",t.glslVersion===Ys?"":"layout(location = 0) out highp vec4 pc_fragColor;",t.glslVersion===Ys?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join(` +`)+` +`+E);const A=_+h+o,C=_+E+a,b=Ta(r,r.VERTEX_SHADER,A),w=Ta(r,r.FRAGMENT_SHADER,C);r.attachShader(p,b),r.attachShader(p,w),t.index0AttributeName!==void 0?r.bindAttribLocation(p,0,t.index0AttributeName):t.morphTargets===!0&&r.bindAttribLocation(p,0,"position"),r.linkProgram(p);function z(V){if(i.debug.checkShaderErrors){const ee=r.getProgramInfoLog(p).trim(),L=r.getShaderInfoLog(b).trim(),U=r.getShaderInfoLog(w).trim();let k=!0,q=!0;if(r.getProgramParameter(p,r.LINK_STATUS)===!1)if(k=!1,typeof i.debug.onShaderError=="function")i.debug.onShaderError(r,p,b,w);else{const X=Aa(r,b,"vertex"),W=Aa(r,w,"fragment");console.error("THREE.WebGLProgram: Shader Error "+r.getError()+" - VALIDATE_STATUS "+r.getProgramParameter(p,r.VALIDATE_STATUS)+` + +Program Info Log: `+ee+` +`+X+` +`+W)}else ee!==""?console.warn("THREE.WebGLProgram: Program Info Log:",ee):(L===""||U==="")&&(q=!1);q&&(V.diagnostics={runnable:k,programLog:ee,vertexShader:{log:L,prefix:h},fragmentShader:{log:U,prefix:E}})}r.deleteShader(b),r.deleteShader(w),M=new qi(r,p),T=fd(r,p)}let M;this.getUniforms=function(){return M===void 0&&z(this),M};let T;this.getAttributes=function(){return T===void 0&&z(this),T};let B=t.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return B===!1&&(B=r.getProgramParameter(p,id)),B},this.destroy=function(){n.releaseStatesOfProgram(this),r.deleteProgram(p),this.program=void 0},this.type=t.shaderType,this.name=t.shaderName,this.id=rd++,this.cacheKey=e,this.usedTimes=1,this.program=p,this.vertexShader=b,this.fragmentShader=w,this}let Td=0;class Ad{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(e){const t=e.vertexShader,n=e.fragmentShader,r=this._getShaderStage(t),s=this._getShaderStage(n),o=this._getShaderCacheForMaterial(e);return o.has(r)===!1&&(o.add(r),r.usedTimes++),o.has(s)===!1&&(o.add(s),s.usedTimes++),this}remove(e){const t=this.materialCache.get(e);for(const n of t)n.usedTimes--,n.usedTimes===0&&this.shaderCache.delete(n.code);return this.materialCache.delete(e),this}getVertexShaderID(e){return this._getShaderStage(e.vertexShader).id}getFragmentShaderID(e){return this._getShaderStage(e.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(e){const t=this.materialCache;let n=t.get(e);return n===void 0&&(n=new Set,t.set(e,n)),n}_getShaderStage(e){const t=this.shaderCache;let n=t.get(e);return n===void 0&&(n=new bd(e),t.set(e,n)),n}}class bd{constructor(e){this.id=Td++,this.code=e,this.usedTimes=0}}function wd(i,e,t,n,r,s,o){const a=new ns,l=new Ad,c=[],u=r.isWebGL2,f=r.logarithmicDepthBuffer,d=r.vertexTextures;let m=r.precision;const g={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distanceRGBA",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function x(M){return M===0?"uv":`uv${M}`}function p(M,T,B,V,ee){const L=V.fog,U=ee.geometry,k=M.isMeshStandardMaterial?V.environment:null,q=(M.isMeshStandardMaterial?t:e).get(M.envMap||k),X=q&&q.mapping===er?q.image.height:null,W=g[M.type];M.precision!==null&&(m=r.getMaxPrecision(M.precision),m!==M.precision&&console.warn("THREE.WebGLProgram.getParameters:",M.precision,"not supported, using",m,"instead."));const Z=U.morphAttributes.position||U.morphAttributes.normal||U.morphAttributes.color,Q=Z!==void 0?Z.length:0;let le=0;U.morphAttributes.position!==void 0&&(le=1),U.morphAttributes.normal!==void 0&&(le=2),U.morphAttributes.color!==void 0&&(le=3);let H,Y,ae,me;if(W){const _t=Gt[W];H=_t.vertexShader,Y=_t.fragmentShader}else H=M.vertexShader,Y=M.fragmentShader,l.update(M),ae=l.getVertexShaderID(M),me=l.getFragmentShaderID(M);const pe=i.getRenderTarget(),we=ee.isInstancedMesh===!0,Ce=ee.isBatchedMesh===!0,Se=!!M.map,He=!!M.matcap,I=!!q,mt=!!M.aoMap,ge=!!M.lightMap,Ae=!!M.bumpMap,ue=!!M.normalMap,Ke=!!M.displacementMap,De=!!M.emissiveMap,y=!!M.metalnessMap,v=!!M.roughnessMap,F=M.anisotropy>0,$=M.clearcoat>0,K=M.iridescence>0,J=M.sheen>0,fe=M.transmission>0,se=F&&!!M.anisotropyMap,ce=$&&!!M.clearcoatMap,Me=$&&!!M.clearcoatNormalMap,Ue=$&&!!M.clearcoatRoughnessMap,j=K&&!!M.iridescenceMap,ke=K&&!!M.iridescenceThicknessMap,Be=J&&!!M.sheenColorMap,Te=J&&!!M.sheenRoughnessMap,_e=!!M.specularMap,he=!!M.specularColorMap,Le=!!M.specularIntensityMap,Ve=fe&&!!M.transmissionMap,Je=fe&&!!M.thicknessMap,Ne=!!M.gradientMap,te=!!M.alphaMap,R=M.alphaTest>0,ie=!!M.alphaHash,re=!!M.extensions,Ee=!!U.attributes.uv1,ve=!!U.attributes.uv2,Xe=!!U.attributes.uv3;let qe=on;return M.toneMapped&&(pe===null||pe.isXRRenderTarget===!0)&&(qe=i.toneMapping),{isWebGL2:u,shaderID:W,shaderType:M.type,shaderName:M.name,vertexShader:H,fragmentShader:Y,defines:M.defines,customVertexShaderID:ae,customFragmentShaderID:me,isRawShaderMaterial:M.isRawShaderMaterial===!0,glslVersion:M.glslVersion,precision:m,batching:Ce,instancing:we,instancingColor:we&&ee.instanceColor!==null,supportsVertexTextures:d,outputColorSpace:pe===null?i.outputColorSpace:pe.isXRRenderTarget===!0?pe.texture.colorSpace:$t,map:Se,matcap:He,envMap:I,envMapMode:I&&q.mapping,envMapCubeUVHeight:X,aoMap:mt,lightMap:ge,bumpMap:Ae,normalMap:ue,displacementMap:d&&Ke,emissiveMap:De,normalMapObjectSpace:ue&&M.normalMapType===El,normalMapTangentSpace:ue&&M.normalMapType===Jr,metalnessMap:y,roughnessMap:v,anisotropy:F,anisotropyMap:se,clearcoat:$,clearcoatMap:ce,clearcoatNormalMap:Me,clearcoatRoughnessMap:Ue,iridescence:K,iridescenceMap:j,iridescenceThicknessMap:ke,sheen:J,sheenColorMap:Be,sheenRoughnessMap:Te,specularMap:_e,specularColorMap:he,specularIntensityMap:Le,transmission:fe,transmissionMap:Ve,thicknessMap:Je,gradientMap:Ne,opaque:M.transparent===!1&&M.blending===Yn,alphaMap:te,alphaTest:R,alphaHash:ie,combine:M.combine,mapUv:Se&&x(M.map.channel),aoMapUv:mt&&x(M.aoMap.channel),lightMapUv:ge&&x(M.lightMap.channel),bumpMapUv:Ae&&x(M.bumpMap.channel),normalMapUv:ue&&x(M.normalMap.channel),displacementMapUv:Ke&&x(M.displacementMap.channel),emissiveMapUv:De&&x(M.emissiveMap.channel),metalnessMapUv:y&&x(M.metalnessMap.channel),roughnessMapUv:v&&x(M.roughnessMap.channel),anisotropyMapUv:se&&x(M.anisotropyMap.channel),clearcoatMapUv:ce&&x(M.clearcoatMap.channel),clearcoatNormalMapUv:Me&&x(M.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:Ue&&x(M.clearcoatRoughnessMap.channel),iridescenceMapUv:j&&x(M.iridescenceMap.channel),iridescenceThicknessMapUv:ke&&x(M.iridescenceThicknessMap.channel),sheenColorMapUv:Be&&x(M.sheenColorMap.channel),sheenRoughnessMapUv:Te&&x(M.sheenRoughnessMap.channel),specularMapUv:_e&&x(M.specularMap.channel),specularColorMapUv:he&&x(M.specularColorMap.channel),specularIntensityMapUv:Le&&x(M.specularIntensityMap.channel),transmissionMapUv:Ve&&x(M.transmissionMap.channel),thicknessMapUv:Je&&x(M.thicknessMap.channel),alphaMapUv:te&&x(M.alphaMap.channel),vertexTangents:!!U.attributes.tangent&&(ue||F),vertexColors:M.vertexColors,vertexAlphas:M.vertexColors===!0&&!!U.attributes.color&&U.attributes.color.itemSize===4,vertexUv1s:Ee,vertexUv2s:ve,vertexUv3s:Xe,pointsUvs:ee.isPoints===!0&&!!U.attributes.uv&&(Se||te),fog:!!L,useFog:M.fog===!0,fogExp2:L&&L.isFogExp2,flatShading:M.flatShading===!0,sizeAttenuation:M.sizeAttenuation===!0,logarithmicDepthBuffer:f,skinning:ee.isSkinnedMesh===!0,morphTargets:U.morphAttributes.position!==void 0,morphNormals:U.morphAttributes.normal!==void 0,morphColors:U.morphAttributes.color!==void 0,morphTargetsCount:Q,morphTextureStride:le,numDirLights:T.directional.length,numPointLights:T.point.length,numSpotLights:T.spot.length,numSpotLightMaps:T.spotLightMap.length,numRectAreaLights:T.rectArea.length,numHemiLights:T.hemi.length,numDirLightShadows:T.directionalShadowMap.length,numPointLightShadows:T.pointShadowMap.length,numSpotLightShadows:T.spotShadowMap.length,numSpotLightShadowsWithMaps:T.numSpotLightShadowsWithMaps,numLightProbes:T.numLightProbes,numClippingPlanes:o.numPlanes,numClipIntersection:o.numIntersection,dithering:M.dithering,shadowMapEnabled:i.shadowMap.enabled&&B.length>0,shadowMapType:i.shadowMap.type,toneMapping:qe,useLegacyLights:i._useLegacyLights,decodeVideoTexture:Se&&M.map.isVideoTexture===!0&&We.getTransfer(M.map.colorSpace)===je,premultipliedAlpha:M.premultipliedAlpha,doubleSided:M.side===Kt,flipSided:M.side===St,useDepthPacking:M.depthPacking>=0,depthPacking:M.depthPacking||0,index0AttributeName:M.index0AttributeName,extensionDerivatives:re&&M.extensions.derivatives===!0,extensionFragDepth:re&&M.extensions.fragDepth===!0,extensionDrawBuffers:re&&M.extensions.drawBuffers===!0,extensionShaderTextureLOD:re&&M.extensions.shaderTextureLOD===!0,extensionClipCullDistance:re&&M.extensions.clipCullDistance&&n.has("WEBGL_clip_cull_distance"),rendererExtensionFragDepth:u||n.has("EXT_frag_depth"),rendererExtensionDrawBuffers:u||n.has("WEBGL_draw_buffers"),rendererExtensionShaderTextureLod:u||n.has("EXT_shader_texture_lod"),rendererExtensionParallelShaderCompile:n.has("KHR_parallel_shader_compile"),customProgramCacheKey:M.customProgramCacheKey()}}function h(M){const T=[];if(M.shaderID?T.push(M.shaderID):(T.push(M.customVertexShaderID),T.push(M.customFragmentShaderID)),M.defines!==void 0)for(const B in M.defines)T.push(B),T.push(M.defines[B]);return M.isRawShaderMaterial===!1&&(E(T,M),_(T,M),T.push(i.outputColorSpace)),T.push(M.customProgramCacheKey),T.join()}function E(M,T){M.push(T.precision),M.push(T.outputColorSpace),M.push(T.envMapMode),M.push(T.envMapCubeUVHeight),M.push(T.mapUv),M.push(T.alphaMapUv),M.push(T.lightMapUv),M.push(T.aoMapUv),M.push(T.bumpMapUv),M.push(T.normalMapUv),M.push(T.displacementMapUv),M.push(T.emissiveMapUv),M.push(T.metalnessMapUv),M.push(T.roughnessMapUv),M.push(T.anisotropyMapUv),M.push(T.clearcoatMapUv),M.push(T.clearcoatNormalMapUv),M.push(T.clearcoatRoughnessMapUv),M.push(T.iridescenceMapUv),M.push(T.iridescenceThicknessMapUv),M.push(T.sheenColorMapUv),M.push(T.sheenRoughnessMapUv),M.push(T.specularMapUv),M.push(T.specularColorMapUv),M.push(T.specularIntensityMapUv),M.push(T.transmissionMapUv),M.push(T.thicknessMapUv),M.push(T.combine),M.push(T.fogExp2),M.push(T.sizeAttenuation),M.push(T.morphTargetsCount),M.push(T.morphAttributeCount),M.push(T.numDirLights),M.push(T.numPointLights),M.push(T.numSpotLights),M.push(T.numSpotLightMaps),M.push(T.numHemiLights),M.push(T.numRectAreaLights),M.push(T.numDirLightShadows),M.push(T.numPointLightShadows),M.push(T.numSpotLightShadows),M.push(T.numSpotLightShadowsWithMaps),M.push(T.numLightProbes),M.push(T.shadowMapType),M.push(T.toneMapping),M.push(T.numClippingPlanes),M.push(T.numClipIntersection),M.push(T.depthPacking)}function _(M,T){a.disableAll(),T.isWebGL2&&a.enable(0),T.supportsVertexTextures&&a.enable(1),T.instancing&&a.enable(2),T.instancingColor&&a.enable(3),T.matcap&&a.enable(4),T.envMap&&a.enable(5),T.normalMapObjectSpace&&a.enable(6),T.normalMapTangentSpace&&a.enable(7),T.clearcoat&&a.enable(8),T.iridescence&&a.enable(9),T.alphaTest&&a.enable(10),T.vertexColors&&a.enable(11),T.vertexAlphas&&a.enable(12),T.vertexUv1s&&a.enable(13),T.vertexUv2s&&a.enable(14),T.vertexUv3s&&a.enable(15),T.vertexTangents&&a.enable(16),T.anisotropy&&a.enable(17),T.alphaHash&&a.enable(18),T.batching&&a.enable(19),M.push(a.mask),a.disableAll(),T.fog&&a.enable(0),T.useFog&&a.enable(1),T.flatShading&&a.enable(2),T.logarithmicDepthBuffer&&a.enable(3),T.skinning&&a.enable(4),T.morphTargets&&a.enable(5),T.morphNormals&&a.enable(6),T.morphColors&&a.enable(7),T.premultipliedAlpha&&a.enable(8),T.shadowMapEnabled&&a.enable(9),T.useLegacyLights&&a.enable(10),T.doubleSided&&a.enable(11),T.flipSided&&a.enable(12),T.useDepthPacking&&a.enable(13),T.dithering&&a.enable(14),T.transmission&&a.enable(15),T.sheen&&a.enable(16),T.opaque&&a.enable(17),T.pointsUvs&&a.enable(18),T.decodeVideoTexture&&a.enable(19),M.push(a.mask)}function A(M){const T=g[M.type];let B;if(T){const V=Gt[T];B=lc.clone(V.uniforms)}else B=M.uniforms;return B}function C(M,T){let B;for(let V=0,ee=c.length;V0?n.push(h):m.transparent===!0?r.push(h):t.push(h)}function l(f,d,m,g,x,p){const h=o(f,d,m,g,x,p);m.transmission>0?n.unshift(h):m.transparent===!0?r.unshift(h):t.unshift(h)}function c(f,d){t.length>1&&t.sort(f||Cd),n.length>1&&n.sort(d||La),r.length>1&&r.sort(d||La)}function u(){for(let f=e,d=i.length;f=s.length?(o=new Pa,s.push(o)):o=s[r],o}function t(){i=new WeakMap}return{get:e,dispose:t}}function Pd(){const i={};return{get:function(e){if(i[e.id]!==void 0)return i[e.id];let t;switch(e.type){case"DirectionalLight":t={direction:new P,color:new Ge};break;case"SpotLight":t={position:new P,direction:new P,color:new Ge,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":t={position:new P,color:new Ge,distance:0,decay:0};break;case"HemisphereLight":t={direction:new P,skyColor:new Ge,groundColor:new Ge};break;case"RectAreaLight":t={color:new Ge,position:new P,halfWidth:new P,halfHeight:new P};break}return i[e.id]=t,t}}}function Dd(){const i={};return{get:function(e){if(i[e.id]!==void 0)return i[e.id];let t;switch(e.type){case"DirectionalLight":t={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new ze};break;case"SpotLight":t={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new ze};break;case"PointLight":t={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new ze,shadowCameraNear:1,shadowCameraFar:1e3};break}return i[e.id]=t,t}}}let Ud=0;function Id(i,e){return(e.castShadow?2:0)-(i.castShadow?2:0)+(e.map?1:0)-(i.map?1:0)}function Nd(i,e){const t=new Pd,n=Dd(),r={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let u=0;u<9;u++)r.probe.push(new P);const s=new P,o=new $e,a=new $e;function l(u,f){let d=0,m=0,g=0;for(let V=0;V<9;V++)r.probe[V].set(0,0,0);let x=0,p=0,h=0,E=0,_=0,A=0,C=0,b=0,w=0,z=0,M=0;u.sort(Id);const T=f===!0?Math.PI:1;for(let V=0,ee=u.length;V0&&(e.isWebGL2?i.has("OES_texture_float_linear")===!0?(r.rectAreaLTC1=ne.LTC_FLOAT_1,r.rectAreaLTC2=ne.LTC_FLOAT_2):(r.rectAreaLTC1=ne.LTC_HALF_1,r.rectAreaLTC2=ne.LTC_HALF_2):i.has("OES_texture_float_linear")===!0?(r.rectAreaLTC1=ne.LTC_FLOAT_1,r.rectAreaLTC2=ne.LTC_FLOAT_2):i.has("OES_texture_half_float_linear")===!0?(r.rectAreaLTC1=ne.LTC_HALF_1,r.rectAreaLTC2=ne.LTC_HALF_2):console.error("THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.")),r.ambient[0]=d,r.ambient[1]=m,r.ambient[2]=g;const B=r.hash;(B.directionalLength!==x||B.pointLength!==p||B.spotLength!==h||B.rectAreaLength!==E||B.hemiLength!==_||B.numDirectionalShadows!==A||B.numPointShadows!==C||B.numSpotShadows!==b||B.numSpotMaps!==w||B.numLightProbes!==M)&&(r.directional.length=x,r.spot.length=h,r.rectArea.length=E,r.point.length=p,r.hemi.length=_,r.directionalShadow.length=A,r.directionalShadowMap.length=A,r.pointShadow.length=C,r.pointShadowMap.length=C,r.spotShadow.length=b,r.spotShadowMap.length=b,r.directionalShadowMatrix.length=A,r.pointShadowMatrix.length=C,r.spotLightMatrix.length=b+w-z,r.spotLightMap.length=w,r.numSpotLightShadowsWithMaps=z,r.numLightProbes=M,B.directionalLength=x,B.pointLength=p,B.spotLength=h,B.rectAreaLength=E,B.hemiLength=_,B.numDirectionalShadows=A,B.numPointShadows=C,B.numSpotShadows=b,B.numSpotMaps=w,B.numLightProbes=M,r.version=Ud++)}function c(u,f){let d=0,m=0,g=0,x=0,p=0;const h=f.matrixWorldInverse;for(let E=0,_=u.length;E<_;E++){const A=u[E];if(A.isDirectionalLight){const C=r.directional[d];C.direction.setFromMatrixPosition(A.matrixWorld),s.setFromMatrixPosition(A.target.matrixWorld),C.direction.sub(s),C.direction.transformDirection(h),d++}else if(A.isSpotLight){const C=r.spot[g];C.position.setFromMatrixPosition(A.matrixWorld),C.position.applyMatrix4(h),C.direction.setFromMatrixPosition(A.matrixWorld),s.setFromMatrixPosition(A.target.matrixWorld),C.direction.sub(s),C.direction.transformDirection(h),g++}else if(A.isRectAreaLight){const C=r.rectArea[x];C.position.setFromMatrixPosition(A.matrixWorld),C.position.applyMatrix4(h),a.identity(),o.copy(A.matrixWorld),o.premultiply(h),a.extractRotation(o),C.halfWidth.set(A.width*.5,0,0),C.halfHeight.set(0,A.height*.5,0),C.halfWidth.applyMatrix4(a),C.halfHeight.applyMatrix4(a),x++}else if(A.isPointLight){const C=r.point[m];C.position.setFromMatrixPosition(A.matrixWorld),C.position.applyMatrix4(h),m++}else if(A.isHemisphereLight){const C=r.hemi[p];C.direction.setFromMatrixPosition(A.matrixWorld),C.direction.transformDirection(h),p++}}}return{setup:l,setupView:c,state:r}}function Da(i,e){const t=new Nd(i,e),n=[],r=[];function s(){n.length=0,r.length=0}function o(f){n.push(f)}function a(f){r.push(f)}function l(f){t.setup(n,f)}function c(f){t.setupView(n,f)}return{init:s,state:{lightsArray:n,shadowsArray:r,lights:t},setupLights:l,setupLightsView:c,pushLight:o,pushShadow:a}}function Fd(i,e){let t=new WeakMap;function n(s,o=0){const a=t.get(s);let l;return a===void 0?(l=new Da(i,e),t.set(s,[l])):o>=a.length?(l=new Da(i,e),a.push(l)):l=a[o],l}function r(){t=new WeakMap}return{get:n,dispose:r}}class Od extends bn{constructor(e){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=Ml,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(e)}copy(e){return super.copy(e),this.depthPacking=e.depthPacking,this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this}}class Bd extends bn{constructor(e){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(e)}copy(e){return super.copy(e),this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this}}const zd=`void main() { + gl_Position = vec4( position, 1.0 ); +}`,Gd=`uniform sampler2D shadow_pass; +uniform vec2 resolution; +uniform float radius; +#include +void main() { + const float samples = float( VSM_SAMPLES ); + float mean = 0.0; + float squared_mean = 0.0; + float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 ); + float uvStart = samples <= 1.0 ? 0.0 : - 1.0; + for ( float i = 0.0; i < samples; i ++ ) { + float uvOffset = uvStart + i * uvStride; + #ifdef HORIZONTAL_PASS + vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) ); + mean += distribution.x; + squared_mean += distribution.y * distribution.y + distribution.x * distribution.x; + #else + float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) ); + mean += depth; + squared_mean += depth * depth; + #endif + } + mean = mean / samples; + squared_mean = squared_mean / samples; + float std_dev = sqrt( squared_mean - mean * mean ); + gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) ); +}`;function Hd(i,e,t){let n=new is;const r=new ze,s=new ze,o=new lt,a=new Od({depthPacking:Sl}),l=new Bd,c={},u=t.maxTextureSize,f={[cn]:St,[St]:cn,[Kt]:Kt},d=new Tn({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new ze},radius:{value:4}},vertexShader:zd,fragmentShader:Gd}),m=d.clone();m.defines.HORIZONTAL_PASS=1;const g=new Lt;g.setAttribute("position",new Bt(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const x=new Ht(g,d),p=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=Wa;let h=this.type;this.render=function(b,w,z){if(p.enabled===!1||p.autoUpdate===!1&&p.needsUpdate===!1||b.length===0)return;const M=i.getRenderTarget(),T=i.getActiveCubeFace(),B=i.getActiveMipmapLevel(),V=i.state;V.setBlending(an),V.buffers.color.setClear(1,1,1,1),V.buffers.depth.setTest(!0),V.setScissorTest(!1);const ee=h!==jt&&this.type===jt,L=h===jt&&this.type!==jt;for(let U=0,k=b.length;Uu||r.y>u)&&(r.x>u&&(s.x=Math.floor(u/W.x),r.x=s.x*W.x,X.mapSize.x=s.x),r.y>u&&(s.y=Math.floor(u/W.y),r.y=s.y*W.y,X.mapSize.y=s.y)),X.map===null||ee===!0||L===!0){const Q=this.type!==jt?{minFilter:Mt,magFilter:Mt}:{};X.map!==null&&X.map.dispose(),X.map=new yn(r.x,r.y,Q),X.map.texture.name=q.name+".shadowMap",X.camera.updateProjectionMatrix()}i.setRenderTarget(X.map),i.clear();const Z=X.getViewportCount();for(let Q=0;Q0||w.map&&w.alphaTest>0){const V=T.uuid,ee=w.uuid;let L=c[V];L===void 0&&(L={},c[V]=L);let U=L[ee];U===void 0&&(U=T.clone(),L[ee]=U,w.addEventListener("dispose",C)),T=U}if(T.visible=w.visible,T.wireframe=w.wireframe,M===jt?T.side=w.shadowSide!==null?w.shadowSide:w.side:T.side=w.shadowSide!==null?w.shadowSide:f[w.side],T.alphaMap=w.alphaMap,T.alphaTest=w.alphaTest,T.map=w.map,T.clipShadows=w.clipShadows,T.clippingPlanes=w.clippingPlanes,T.clipIntersection=w.clipIntersection,T.displacementMap=w.displacementMap,T.displacementScale=w.displacementScale,T.displacementBias=w.displacementBias,T.wireframeLinewidth=w.wireframeLinewidth,T.linewidth=w.linewidth,z.isPointLight===!0&&T.isMeshDistanceMaterial===!0){const V=i.properties.get(T);V.light=z}return T}function A(b,w,z,M,T){if(b.visible===!1)return;if(b.layers.test(w.layers)&&(b.isMesh||b.isLine||b.isPoints)&&(b.castShadow||b.receiveShadow&&T===jt)&&(!b.frustumCulled||n.intersectsObject(b))){b.modelViewMatrix.multiplyMatrices(z.matrixWorldInverse,b.matrixWorld);const ee=e.update(b),L=b.material;if(Array.isArray(L)){const U=ee.groups;for(let k=0,q=U.length;k=1):Z.indexOf("OpenGL ES")!==-1&&(W=parseFloat(/^OpenGL ES (\d)/.exec(Z)[1]),X=W>=2);let Q=null,le={};const H=i.getParameter(i.SCISSOR_BOX),Y=i.getParameter(i.VIEWPORT),ae=new lt().fromArray(H),me=new lt().fromArray(Y);function pe(R,ie,re,Ee){const ve=new Uint8Array(4),Xe=i.createTexture();i.bindTexture(R,Xe),i.texParameteri(R,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(R,i.TEXTURE_MAG_FILTER,i.NEAREST);for(let qe=0;qe"u"?!1:/OculusBrowser/g.test(navigator.userAgent),u=new WeakMap;let f;const d=new WeakMap;let m=!1;try{m=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function g(y,v){return m?new OffscreenCanvas(y,v):Qi("canvas")}function x(y,v,F,$){let K=1;if((y.width>$||y.height>$)&&(K=$/Math.max(y.width,y.height)),K<1||v===!0)if(typeof HTMLImageElement<"u"&&y instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&y instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&y instanceof ImageBitmap){const J=v?Ji:Math.floor,fe=J(K*y.width),se=J(K*y.height);f===void 0&&(f=g(fe,se));const ce=F?g(fe,se):f;return ce.width=fe,ce.height=se,ce.getContext("2d").drawImage(y,0,0,fe,se),console.warn("THREE.WebGLRenderer: Texture has been resized from ("+y.width+"x"+y.height+") to ("+fe+"x"+se+")."),ce}else return"data"in y&&console.warn("THREE.WebGLRenderer: Image in DataTexture is too big ("+y.width+"x"+y.height+")."),y;return y}function p(y){return qr(y.width)&&qr(y.height)}function h(y){return a?!1:y.wrapS!==Ft||y.wrapT!==Ft||y.minFilter!==Mt&&y.minFilter!==Rt}function E(y,v){return y.generateMipmaps&&v&&y.minFilter!==Mt&&y.minFilter!==Rt}function _(y){i.generateMipmap(y)}function A(y,v,F,$,K=!1){if(a===!1)return v;if(y!==null){if(i[y]!==void 0)return i[y];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+y+"'")}let J=v;if(v===i.RED&&(F===i.FLOAT&&(J=i.R32F),F===i.HALF_FLOAT&&(J=i.R16F),F===i.UNSIGNED_BYTE&&(J=i.R8)),v===i.RED_INTEGER&&(F===i.UNSIGNED_BYTE&&(J=i.R8UI),F===i.UNSIGNED_SHORT&&(J=i.R16UI),F===i.UNSIGNED_INT&&(J=i.R32UI),F===i.BYTE&&(J=i.R8I),F===i.SHORT&&(J=i.R16I),F===i.INT&&(J=i.R32I)),v===i.RG&&(F===i.FLOAT&&(J=i.RG32F),F===i.HALF_FLOAT&&(J=i.RG16F),F===i.UNSIGNED_BYTE&&(J=i.RG8)),v===i.RGBA){const fe=K?ji:We.getTransfer($);F===i.FLOAT&&(J=i.RGBA32F),F===i.HALF_FLOAT&&(J=i.RGBA16F),F===i.UNSIGNED_BYTE&&(J=fe===je?i.SRGB8_ALPHA8:i.RGBA8),F===i.UNSIGNED_SHORT_4_4_4_4&&(J=i.RGBA4),F===i.UNSIGNED_SHORT_5_5_5_1&&(J=i.RGB5_A1)}return(J===i.R16F||J===i.R32F||J===i.RG16F||J===i.RG32F||J===i.RGBA16F||J===i.RGBA32F)&&e.get("EXT_color_buffer_float"),J}function C(y,v,F){return E(y,F)===!0||y.isFramebufferTexture&&y.minFilter!==Mt&&y.minFilter!==Rt?Math.log2(Math.max(v.width,v.height))+1:y.mipmaps!==void 0&&y.mipmaps.length>0?y.mipmaps.length:y.isCompressedTexture&&Array.isArray(y.image)?v.mipmaps.length:1}function b(y){return y===Mt||y===xs||y===lr?i.NEAREST:i.LINEAR}function w(y){const v=y.target;v.removeEventListener("dispose",w),M(v),v.isVideoTexture&&u.delete(v)}function z(y){const v=y.target;v.removeEventListener("dispose",z),B(v)}function M(y){const v=n.get(y);if(v.__webglInit===void 0)return;const F=y.source,$=d.get(F);if($){const K=$[v.__cacheKey];K.usedTimes--,K.usedTimes===0&&T(y),Object.keys($).length===0&&d.delete(F)}n.remove(y)}function T(y){const v=n.get(y);i.deleteTexture(v.__webglTexture);const F=y.source,$=d.get(F);delete $[v.__cacheKey],o.memory.textures--}function B(y){const v=y.texture,F=n.get(y),$=n.get(v);if($.__webglTexture!==void 0&&(i.deleteTexture($.__webglTexture),o.memory.textures--),y.depthTexture&&y.depthTexture.dispose(),y.isWebGLCubeRenderTarget)for(let K=0;K<6;K++){if(Array.isArray(F.__webglFramebuffer[K]))for(let J=0;J=r.maxTextures&&console.warn("THREE.WebGLTextures: Trying to use "+y+" texture units while this GPU supports only "+r.maxTextures),V+=1,y}function U(y){const v=[];return v.push(y.wrapS),v.push(y.wrapT),v.push(y.wrapR||0),v.push(y.magFilter),v.push(y.minFilter),v.push(y.anisotropy),v.push(y.internalFormat),v.push(y.format),v.push(y.type),v.push(y.generateMipmaps),v.push(y.premultiplyAlpha),v.push(y.flipY),v.push(y.unpackAlignment),v.push(y.colorSpace),v.join()}function k(y,v){const F=n.get(y);if(y.isVideoTexture&&Ke(y),y.isRenderTargetTexture===!1&&y.version>0&&F.__version!==y.version){const $=y.image;if($===null)console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found.");else if($.complete===!1)console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete");else{ae(F,y,v);return}}t.bindTexture(i.TEXTURE_2D,F.__webglTexture,i.TEXTURE0+v)}function q(y,v){const F=n.get(y);if(y.version>0&&F.__version!==y.version){ae(F,y,v);return}t.bindTexture(i.TEXTURE_2D_ARRAY,F.__webglTexture,i.TEXTURE0+v)}function X(y,v){const F=n.get(y);if(y.version>0&&F.__version!==y.version){ae(F,y,v);return}t.bindTexture(i.TEXTURE_3D,F.__webglTexture,i.TEXTURE0+v)}function W(y,v){const F=n.get(y);if(y.version>0&&F.__version!==y.version){me(F,y,v);return}t.bindTexture(i.TEXTURE_CUBE_MAP,F.__webglTexture,i.TEXTURE0+v)}const Z={[kr]:i.REPEAT,[Ft]:i.CLAMP_TO_EDGE,[Wr]:i.MIRRORED_REPEAT},Q={[Mt]:i.NEAREST,[xs]:i.NEAREST_MIPMAP_NEAREST,[lr]:i.NEAREST_MIPMAP_LINEAR,[Rt]:i.LINEAR,[ul]:i.LINEAR_MIPMAP_NEAREST,[di]:i.LINEAR_MIPMAP_LINEAR},le={[yl]:i.NEVER,[Cl]:i.ALWAYS,[Tl]:i.LESS,[eo]:i.LEQUAL,[Al]:i.EQUAL,[Rl]:i.GEQUAL,[bl]:i.GREATER,[wl]:i.NOTEQUAL};function H(y,v,F){if(F?(i.texParameteri(y,i.TEXTURE_WRAP_S,Z[v.wrapS]),i.texParameteri(y,i.TEXTURE_WRAP_T,Z[v.wrapT]),(y===i.TEXTURE_3D||y===i.TEXTURE_2D_ARRAY)&&i.texParameteri(y,i.TEXTURE_WRAP_R,Z[v.wrapR]),i.texParameteri(y,i.TEXTURE_MAG_FILTER,Q[v.magFilter]),i.texParameteri(y,i.TEXTURE_MIN_FILTER,Q[v.minFilter])):(i.texParameteri(y,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(y,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),(y===i.TEXTURE_3D||y===i.TEXTURE_2D_ARRAY)&&i.texParameteri(y,i.TEXTURE_WRAP_R,i.CLAMP_TO_EDGE),(v.wrapS!==Ft||v.wrapT!==Ft)&&console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping."),i.texParameteri(y,i.TEXTURE_MAG_FILTER,b(v.magFilter)),i.texParameteri(y,i.TEXTURE_MIN_FILTER,b(v.minFilter)),v.minFilter!==Mt&&v.minFilter!==Rt&&console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.")),v.compareFunction&&(i.texParameteri(y,i.TEXTURE_COMPARE_MODE,i.COMPARE_REF_TO_TEXTURE),i.texParameteri(y,i.TEXTURE_COMPARE_FUNC,le[v.compareFunction])),e.has("EXT_texture_filter_anisotropic")===!0){const $=e.get("EXT_texture_filter_anisotropic");if(v.magFilter===Mt||v.minFilter!==lr&&v.minFilter!==di||v.type===sn&&e.has("OES_texture_float_linear")===!1||a===!1&&v.type===pi&&e.has("OES_texture_half_float_linear")===!1)return;(v.anisotropy>1||n.get(v).__currentAnisotropy)&&(i.texParameterf(y,$.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(v.anisotropy,r.getMaxAnisotropy())),n.get(v).__currentAnisotropy=v.anisotropy)}}function Y(y,v){let F=!1;y.__webglInit===void 0&&(y.__webglInit=!0,v.addEventListener("dispose",w));const $=v.source;let K=d.get($);K===void 0&&(K={},d.set($,K));const J=U(v);if(J!==y.__cacheKey){K[J]===void 0&&(K[J]={texture:i.createTexture(),usedTimes:0},o.memory.textures++,F=!0),K[J].usedTimes++;const fe=K[y.__cacheKey];fe!==void 0&&(K[y.__cacheKey].usedTimes--,fe.usedTimes===0&&T(v)),y.__cacheKey=J,y.__webglTexture=K[J].texture}return F}function ae(y,v,F){let $=i.TEXTURE_2D;(v.isDataArrayTexture||v.isCompressedArrayTexture)&&($=i.TEXTURE_2D_ARRAY),v.isData3DTexture&&($=i.TEXTURE_3D);const K=Y(y,v),J=v.source;t.bindTexture($,y.__webglTexture,i.TEXTURE0+F);const fe=n.get(J);if(J.version!==fe.__version||K===!0){t.activeTexture(i.TEXTURE0+F);const se=We.getPrimaries(We.workingColorSpace),ce=v.colorSpace===Ct?null:We.getPrimaries(v.colorSpace),Me=v.colorSpace===Ct||se===ce?i.NONE:i.BROWSER_DEFAULT_WEBGL;i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,v.flipY),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,v.premultiplyAlpha),i.pixelStorei(i.UNPACK_ALIGNMENT,v.unpackAlignment),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,Me);const Ue=h(v)&&p(v.image)===!1;let j=x(v.image,Ue,!1,r.maxTextureSize);j=De(v,j);const ke=p(j)||a,Be=s.convert(v.format,v.colorSpace);let Te=s.convert(v.type),_e=A(v.internalFormat,Be,Te,v.colorSpace,v.isVideoTexture);H($,v,ke);let he;const Le=v.mipmaps,Ve=a&&v.isVideoTexture!==!0&&_e!==Ja,Je=fe.__version===void 0||K===!0,Ne=C(v,j,ke);if(v.isDepthTexture)_e=i.DEPTH_COMPONENT,a?v.type===sn?_e=i.DEPTH_COMPONENT32F:v.type===rn?_e=i.DEPTH_COMPONENT24:v.type===Mn?_e=i.DEPTH24_STENCIL8:_e=i.DEPTH_COMPONENT16:v.type===sn&&console.error("WebGLRenderer: Floating point depth texture requires WebGL2."),v.format===Sn&&_e===i.DEPTH_COMPONENT&&v.type!==$r&&v.type!==rn&&(console.warn("THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture."),v.type=rn,Te=s.convert(v.type)),v.format===$n&&_e===i.DEPTH_COMPONENT&&(_e=i.DEPTH_STENCIL,v.type!==Mn&&(console.warn("THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture."),v.type=Mn,Te=s.convert(v.type))),Je&&(Ve?t.texStorage2D(i.TEXTURE_2D,1,_e,j.width,j.height):t.texImage2D(i.TEXTURE_2D,0,_e,j.width,j.height,0,Be,Te,null));else if(v.isDataTexture)if(Le.length>0&&ke){Ve&&Je&&t.texStorage2D(i.TEXTURE_2D,Ne,_e,Le[0].width,Le[0].height);for(let te=0,R=Le.length;te>=1,R>>=1}}else if(Le.length>0&&ke){Ve&&Je&&t.texStorage2D(i.TEXTURE_2D,Ne,_e,Le[0].width,Le[0].height);for(let te=0,R=Le.length;te0&&Je++,t.texStorage2D(i.TEXTURE_CUBE_MAP,Je,he,j[0].width,j[0].height));for(let te=0;te<6;te++)if(Ue){Le?t.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+te,0,0,0,j[te].width,j[te].height,Te,_e,j[te].data):t.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+te,0,he,j[te].width,j[te].height,0,Te,_e,j[te].data);for(let R=0;R>J),j=Math.max(1,v.height>>J);K===i.TEXTURE_3D||K===i.TEXTURE_2D_ARRAY?t.texImage3D(K,J,ce,Ue,j,v.depth,0,fe,se,null):t.texImage2D(K,J,ce,Ue,j,0,fe,se,null)}t.bindFramebuffer(i.FRAMEBUFFER,y),ue(v)?l.framebufferTexture2DMultisampleEXT(i.FRAMEBUFFER,$,K,n.get(F).__webglTexture,0,Ae(v)):(K===i.TEXTURE_2D||K>=i.TEXTURE_CUBE_MAP_POSITIVE_X&&K<=i.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&i.framebufferTexture2D(i.FRAMEBUFFER,$,K,n.get(F).__webglTexture,J),t.bindFramebuffer(i.FRAMEBUFFER,null)}function we(y,v,F){if(i.bindRenderbuffer(i.RENDERBUFFER,y),v.depthBuffer&&!v.stencilBuffer){let $=a===!0?i.DEPTH_COMPONENT24:i.DEPTH_COMPONENT16;if(F||ue(v)){const K=v.depthTexture;K&&K.isDepthTexture&&(K.type===sn?$=i.DEPTH_COMPONENT32F:K.type===rn&&($=i.DEPTH_COMPONENT24));const J=Ae(v);ue(v)?l.renderbufferStorageMultisampleEXT(i.RENDERBUFFER,J,$,v.width,v.height):i.renderbufferStorageMultisample(i.RENDERBUFFER,J,$,v.width,v.height)}else i.renderbufferStorage(i.RENDERBUFFER,$,v.width,v.height);i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.RENDERBUFFER,y)}else if(v.depthBuffer&&v.stencilBuffer){const $=Ae(v);F&&ue(v)===!1?i.renderbufferStorageMultisample(i.RENDERBUFFER,$,i.DEPTH24_STENCIL8,v.width,v.height):ue(v)?l.renderbufferStorageMultisampleEXT(i.RENDERBUFFER,$,i.DEPTH24_STENCIL8,v.width,v.height):i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_STENCIL,v.width,v.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.RENDERBUFFER,y)}else{const $=v.isWebGLMultipleRenderTargets===!0?v.texture:[v.texture];for(let K=0;K<$.length;K++){const J=$[K],fe=s.convert(J.format,J.colorSpace),se=s.convert(J.type),ce=A(J.internalFormat,fe,se,J.colorSpace),Me=Ae(v);F&&ue(v)===!1?i.renderbufferStorageMultisample(i.RENDERBUFFER,Me,ce,v.width,v.height):ue(v)?l.renderbufferStorageMultisampleEXT(i.RENDERBUFFER,Me,ce,v.width,v.height):i.renderbufferStorage(i.RENDERBUFFER,ce,v.width,v.height)}}i.bindRenderbuffer(i.RENDERBUFFER,null)}function Ce(y,v){if(v&&v.isWebGLCubeRenderTarget)throw new Error("Depth Texture with cube render targets is not supported");if(t.bindFramebuffer(i.FRAMEBUFFER,y),!(v.depthTexture&&v.depthTexture.isDepthTexture))throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");(!n.get(v.depthTexture).__webglTexture||v.depthTexture.image.width!==v.width||v.depthTexture.image.height!==v.height)&&(v.depthTexture.image.width=v.width,v.depthTexture.image.height=v.height,v.depthTexture.needsUpdate=!0),k(v.depthTexture,0);const $=n.get(v.depthTexture).__webglTexture,K=Ae(v);if(v.depthTexture.format===Sn)ue(v)?l.framebufferTexture2DMultisampleEXT(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,$,0,K):i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,$,0);else if(v.depthTexture.format===$n)ue(v)?l.framebufferTexture2DMultisampleEXT(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.TEXTURE_2D,$,0,K):i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.TEXTURE_2D,$,0);else throw new Error("Unknown depthTexture format")}function Se(y){const v=n.get(y),F=y.isWebGLCubeRenderTarget===!0;if(y.depthTexture&&!v.__autoAllocateDepthBuffer){if(F)throw new Error("target.depthTexture not supported in Cube render targets");Ce(v.__webglFramebuffer,y)}else if(F){v.__webglDepthbuffer=[];for(let $=0;$<6;$++)t.bindFramebuffer(i.FRAMEBUFFER,v.__webglFramebuffer[$]),v.__webglDepthbuffer[$]=i.createRenderbuffer(),we(v.__webglDepthbuffer[$],y,!1)}else t.bindFramebuffer(i.FRAMEBUFFER,v.__webglFramebuffer),v.__webglDepthbuffer=i.createRenderbuffer(),we(v.__webglDepthbuffer,y,!1);t.bindFramebuffer(i.FRAMEBUFFER,null)}function He(y,v,F){const $=n.get(y);v!==void 0&&pe($.__webglFramebuffer,y,y.texture,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,0),F!==void 0&&Se(y)}function I(y){const v=y.texture,F=n.get(y),$=n.get(v);y.addEventListener("dispose",z),y.isWebGLMultipleRenderTargets!==!0&&($.__webglTexture===void 0&&($.__webglTexture=i.createTexture()),$.__version=v.version,o.memory.textures++);const K=y.isWebGLCubeRenderTarget===!0,J=y.isWebGLMultipleRenderTargets===!0,fe=p(y)||a;if(K){F.__webglFramebuffer=[];for(let se=0;se<6;se++)if(a&&v.mipmaps&&v.mipmaps.length>0){F.__webglFramebuffer[se]=[];for(let ce=0;ce0){F.__webglFramebuffer=[];for(let se=0;se0&&ue(y)===!1){const se=J?v:[v];F.__webglMultisampledFramebuffer=i.createFramebuffer(),F.__webglColorRenderbuffer=[],t.bindFramebuffer(i.FRAMEBUFFER,F.__webglMultisampledFramebuffer);for(let ce=0;ce0)for(let ce=0;ce0)for(let ce=0;ce0&&ue(y)===!1){const v=y.isWebGLMultipleRenderTargets?y.texture:[y.texture],F=y.width,$=y.height;let K=i.COLOR_BUFFER_BIT;const J=[],fe=y.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT,se=n.get(y),ce=y.isWebGLMultipleRenderTargets===!0;if(ce)for(let Me=0;Me0&&e.has("WEBGL_multisampled_render_to_texture")===!0&&v.__useRenderToTexture!==!1}function Ke(y){const v=o.render.frame;u.get(y)!==v&&(u.set(y,v),y.update())}function De(y,v){const F=y.colorSpace,$=y.format,K=y.type;return y.isCompressedTexture===!0||y.isVideoTexture===!0||y.format===Xr||F!==$t&&F!==Ct&&(We.getTransfer(F)===je?a===!1?e.has("EXT_sRGB")===!0&&$===Ot?(y.format=Xr,y.minFilter=Rt,y.generateMipmaps=!1):v=no.sRGBToLinear(v):($!==Ot||K!==ln)&&console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):console.error("THREE.WebGLTextures: Unsupported texture color space:",F)),v}this.allocateTextureUnit=L,this.resetTextureUnits=ee,this.setTexture2D=k,this.setTexture2DArray=q,this.setTexture3D=X,this.setTextureCube=W,this.rebindTextures=He,this.setupRenderTarget=I,this.updateRenderTargetMipmap=mt,this.updateMultisampleRenderTarget=ge,this.setupDepthRenderbuffer=Se,this.setupFrameBufferTexture=pe,this.useMultisampledRTT=ue}function Wd(i,e,t){const n=t.isWebGL2;function r(s,o=Ct){let a;const l=We.getTransfer(o);if(s===ln)return i.UNSIGNED_BYTE;if(s===Ya)return i.UNSIGNED_SHORT_4_4_4_4;if(s===ja)return i.UNSIGNED_SHORT_5_5_5_1;if(s===fl)return i.BYTE;if(s===dl)return i.SHORT;if(s===$r)return i.UNSIGNED_SHORT;if(s===qa)return i.INT;if(s===rn)return i.UNSIGNED_INT;if(s===sn)return i.FLOAT;if(s===pi)return n?i.HALF_FLOAT:(a=e.get("OES_texture_half_float"),a!==null?a.HALF_FLOAT_OES:null);if(s===pl)return i.ALPHA;if(s===Ot)return i.RGBA;if(s===ml)return i.LUMINANCE;if(s===_l)return i.LUMINANCE_ALPHA;if(s===Sn)return i.DEPTH_COMPONENT;if(s===$n)return i.DEPTH_STENCIL;if(s===Xr)return a=e.get("EXT_sRGB"),a!==null?a.SRGB_ALPHA_EXT:null;if(s===gl)return i.RED;if(s===Ka)return i.RED_INTEGER;if(s===vl)return i.RG;if(s===Za)return i.RG_INTEGER;if(s===$a)return i.RGBA_INTEGER;if(s===cr||s===hr||s===ur||s===fr)if(l===je)if(a=e.get("WEBGL_compressed_texture_s3tc_srgb"),a!==null){if(s===cr)return a.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(s===hr)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(s===ur)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(s===fr)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(a=e.get("WEBGL_compressed_texture_s3tc"),a!==null){if(s===cr)return a.COMPRESSED_RGB_S3TC_DXT1_EXT;if(s===hr)return a.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(s===ur)return a.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(s===fr)return a.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(s===Ms||s===Ss||s===Es||s===ys)if(a=e.get("WEBGL_compressed_texture_pvrtc"),a!==null){if(s===Ms)return a.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(s===Ss)return a.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(s===Es)return a.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(s===ys)return a.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(s===Ja)return a=e.get("WEBGL_compressed_texture_etc1"),a!==null?a.COMPRESSED_RGB_ETC1_WEBGL:null;if(s===Ts||s===As)if(a=e.get("WEBGL_compressed_texture_etc"),a!==null){if(s===Ts)return l===je?a.COMPRESSED_SRGB8_ETC2:a.COMPRESSED_RGB8_ETC2;if(s===As)return l===je?a.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:a.COMPRESSED_RGBA8_ETC2_EAC}else return null;if(s===bs||s===ws||s===Rs||s===Cs||s===Ls||s===Ps||s===Ds||s===Us||s===Is||s===Ns||s===Fs||s===Os||s===Bs||s===zs)if(a=e.get("WEBGL_compressed_texture_astc"),a!==null){if(s===bs)return l===je?a.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:a.COMPRESSED_RGBA_ASTC_4x4_KHR;if(s===ws)return l===je?a.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:a.COMPRESSED_RGBA_ASTC_5x4_KHR;if(s===Rs)return l===je?a.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:a.COMPRESSED_RGBA_ASTC_5x5_KHR;if(s===Cs)return l===je?a.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:a.COMPRESSED_RGBA_ASTC_6x5_KHR;if(s===Ls)return l===je?a.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:a.COMPRESSED_RGBA_ASTC_6x6_KHR;if(s===Ps)return l===je?a.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:a.COMPRESSED_RGBA_ASTC_8x5_KHR;if(s===Ds)return l===je?a.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:a.COMPRESSED_RGBA_ASTC_8x6_KHR;if(s===Us)return l===je?a.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:a.COMPRESSED_RGBA_ASTC_8x8_KHR;if(s===Is)return l===je?a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:a.COMPRESSED_RGBA_ASTC_10x5_KHR;if(s===Ns)return l===je?a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:a.COMPRESSED_RGBA_ASTC_10x6_KHR;if(s===Fs)return l===je?a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:a.COMPRESSED_RGBA_ASTC_10x8_KHR;if(s===Os)return l===je?a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:a.COMPRESSED_RGBA_ASTC_10x10_KHR;if(s===Bs)return l===je?a.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:a.COMPRESSED_RGBA_ASTC_12x10_KHR;if(s===zs)return l===je?a.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:a.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(s===dr||s===Gs||s===Hs)if(a=e.get("EXT_texture_compression_bptc"),a!==null){if(s===dr)return l===je?a.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:a.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(s===Gs)return a.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(s===Hs)return a.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(s===xl||s===Vs||s===ks||s===Ws)if(a=e.get("EXT_texture_compression_rgtc"),a!==null){if(s===dr)return a.COMPRESSED_RED_RGTC1_EXT;if(s===Vs)return a.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(s===ks)return a.COMPRESSED_RED_GREEN_RGTC2_EXT;if(s===Ws)return a.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return s===Mn?n?i.UNSIGNED_INT_24_8:(a=e.get("WEBGL_depth_texture"),a!==null?a.UNSIGNED_INT_24_8_WEBGL:null):i[s]!==void 0?i[s]:null}return{convert:r}}class Xd extends Nt{constructor(e=[]){super(),this.isArrayCamera=!0,this.cameras=e}}class Vi extends ut{constructor(){super(),this.isGroup=!0,this.type="Group"}}const qd={type:"move"};class Fr{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Vi,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new Vi,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new P,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new P),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new Vi,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new P,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new P),this._grip}dispatchEvent(e){return this._targetRay!==null&&this._targetRay.dispatchEvent(e),this._grip!==null&&this._grip.dispatchEvent(e),this._hand!==null&&this._hand.dispatchEvent(e),this}connect(e){if(e&&e.hand){const t=this._hand;if(t)for(const n of e.hand.values())this._getHandJoint(t,n)}return this.dispatchEvent({type:"connected",data:e}),this}disconnect(e){return this.dispatchEvent({type:"disconnected",data:e}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(e,t,n){let r=null,s=null,o=null;const a=this._targetRay,l=this._grip,c=this._hand;if(e&&t.session.visibilityState!=="visible-blurred"){if(c&&e.hand){o=!0;for(const x of e.hand.values()){const p=t.getJointPose(x,n),h=this._getHandJoint(c,x);p!==null&&(h.matrix.fromArray(p.transform.matrix),h.matrix.decompose(h.position,h.rotation,h.scale),h.matrixWorldNeedsUpdate=!0,h.jointRadius=p.radius),h.visible=p!==null}const u=c.joints["index-finger-tip"],f=c.joints["thumb-tip"],d=u.position.distanceTo(f.position),m=.02,g=.005;c.inputState.pinching&&d>m+g?(c.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:e.handedness,target:this})):!c.inputState.pinching&&d<=m-g&&(c.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:e.handedness,target:this}))}else l!==null&&e.gripSpace&&(s=t.getPose(e.gripSpace,n),s!==null&&(l.matrix.fromArray(s.transform.matrix),l.matrix.decompose(l.position,l.rotation,l.scale),l.matrixWorldNeedsUpdate=!0,s.linearVelocity?(l.hasLinearVelocity=!0,l.linearVelocity.copy(s.linearVelocity)):l.hasLinearVelocity=!1,s.angularVelocity?(l.hasAngularVelocity=!0,l.angularVelocity.copy(s.angularVelocity)):l.hasAngularVelocity=!1));a!==null&&(r=t.getPose(e.targetRaySpace,n),r===null&&s!==null&&(r=s),r!==null&&(a.matrix.fromArray(r.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),a.matrixWorldNeedsUpdate=!0,r.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(r.linearVelocity)):a.hasLinearVelocity=!1,r.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(r.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(qd)))}return a!==null&&(a.visible=r!==null),l!==null&&(l.visible=s!==null),c!==null&&(c.visible=o!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){const n=new Vi;n.matrixAutoUpdate=!1,n.visible=!1,e.joints[t.jointName]=n,e.add(n)}return e.joints[t.jointName]}}class Yd extends Qn{constructor(e,t){super();const n=this;let r=null,s=1,o=null,a="local-floor",l=1,c=null,u=null,f=null,d=null,m=null,g=null;const x=t.getContextAttributes();let p=null,h=null;const E=[],_=[],A=new ze;let C=null;const b=new Nt;b.layers.enable(1),b.viewport=new lt;const w=new Nt;w.layers.enable(2),w.viewport=new lt;const z=[b,w],M=new Xd;M.layers.enable(1),M.layers.enable(2);let T=null,B=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(H){let Y=E[H];return Y===void 0&&(Y=new Fr,E[H]=Y),Y.getTargetRaySpace()},this.getControllerGrip=function(H){let Y=E[H];return Y===void 0&&(Y=new Fr,E[H]=Y),Y.getGripSpace()},this.getHand=function(H){let Y=E[H];return Y===void 0&&(Y=new Fr,E[H]=Y),Y.getHandSpace()};function V(H){const Y=_.indexOf(H.inputSource);if(Y===-1)return;const ae=E[Y];ae!==void 0&&(ae.update(H.inputSource,H.frame,c||o),ae.dispatchEvent({type:H.type,data:H.inputSource}))}function ee(){r.removeEventListener("select",V),r.removeEventListener("selectstart",V),r.removeEventListener("selectend",V),r.removeEventListener("squeeze",V),r.removeEventListener("squeezestart",V),r.removeEventListener("squeezeend",V),r.removeEventListener("end",ee),r.removeEventListener("inputsourceschange",L);for(let H=0;H=0&&(_[me]=null,E[me].disconnect(ae))}for(let Y=0;Y=_.length){_.push(ae),me=we;break}else if(_[we]===null){_[we]=ae,me=we;break}if(me===-1)break}const pe=E[me];pe&&pe.connect(ae)}}const U=new P,k=new P;function q(H,Y,ae){U.setFromMatrixPosition(Y.matrixWorld),k.setFromMatrixPosition(ae.matrixWorld);const me=U.distanceTo(k),pe=Y.projectionMatrix.elements,we=ae.projectionMatrix.elements,Ce=pe[14]/(pe[10]-1),Se=pe[14]/(pe[10]+1),He=(pe[9]+1)/pe[5],I=(pe[9]-1)/pe[5],mt=(pe[8]-1)/pe[0],ge=(we[8]+1)/we[0],Ae=Ce*mt,ue=Ce*ge,Ke=me/(-mt+ge),De=Ke*-mt;Y.matrixWorld.decompose(H.position,H.quaternion,H.scale),H.translateX(De),H.translateZ(Ke),H.matrixWorld.compose(H.position,H.quaternion,H.scale),H.matrixWorldInverse.copy(H.matrixWorld).invert();const y=Ce+Ke,v=Se+Ke,F=Ae-De,$=ue+(me-De),K=He*Se/v*y,J=I*Se/v*y;H.projectionMatrix.makePerspective(F,$,K,J,y,v),H.projectionMatrixInverse.copy(H.projectionMatrix).invert()}function X(H,Y){Y===null?H.matrixWorld.copy(H.matrix):H.matrixWorld.multiplyMatrices(Y.matrixWorld,H.matrix),H.matrixWorldInverse.copy(H.matrixWorld).invert()}this.updateCamera=function(H){if(r===null)return;M.near=w.near=b.near=H.near,M.far=w.far=b.far=H.far,(T!==M.near||B!==M.far)&&(r.updateRenderState({depthNear:M.near,depthFar:M.far}),T=M.near,B=M.far);const Y=H.parent,ae=M.cameras;X(M,Y);for(let me=0;me0&&(p.alphaTest.value=h.alphaTest);const E=e.get(h).envMap;if(E&&(p.envMap.value=E,p.flipEnvMap.value=E.isCubeTexture&&E.isRenderTargetTexture===!1?-1:1,p.reflectivity.value=h.reflectivity,p.ior.value=h.ior,p.refractionRatio.value=h.refractionRatio),h.lightMap){p.lightMap.value=h.lightMap;const _=i._useLegacyLights===!0?Math.PI:1;p.lightMapIntensity.value=h.lightMapIntensity*_,t(h.lightMap,p.lightMapTransform)}h.aoMap&&(p.aoMap.value=h.aoMap,p.aoMapIntensity.value=h.aoMapIntensity,t(h.aoMap,p.aoMapTransform))}function o(p,h){p.diffuse.value.copy(h.color),p.opacity.value=h.opacity,h.map&&(p.map.value=h.map,t(h.map,p.mapTransform))}function a(p,h){p.dashSize.value=h.dashSize,p.totalSize.value=h.dashSize+h.gapSize,p.scale.value=h.scale}function l(p,h,E,_){p.diffuse.value.copy(h.color),p.opacity.value=h.opacity,p.size.value=h.size*E,p.scale.value=_*.5,h.map&&(p.map.value=h.map,t(h.map,p.uvTransform)),h.alphaMap&&(p.alphaMap.value=h.alphaMap,t(h.alphaMap,p.alphaMapTransform)),h.alphaTest>0&&(p.alphaTest.value=h.alphaTest)}function c(p,h){p.diffuse.value.copy(h.color),p.opacity.value=h.opacity,p.rotation.value=h.rotation,h.map&&(p.map.value=h.map,t(h.map,p.mapTransform)),h.alphaMap&&(p.alphaMap.value=h.alphaMap,t(h.alphaMap,p.alphaMapTransform)),h.alphaTest>0&&(p.alphaTest.value=h.alphaTest)}function u(p,h){p.specular.value.copy(h.specular),p.shininess.value=Math.max(h.shininess,1e-4)}function f(p,h){h.gradientMap&&(p.gradientMap.value=h.gradientMap)}function d(p,h){p.metalness.value=h.metalness,h.metalnessMap&&(p.metalnessMap.value=h.metalnessMap,t(h.metalnessMap,p.metalnessMapTransform)),p.roughness.value=h.roughness,h.roughnessMap&&(p.roughnessMap.value=h.roughnessMap,t(h.roughnessMap,p.roughnessMapTransform)),e.get(h).envMap&&(p.envMapIntensity.value=h.envMapIntensity)}function m(p,h,E){p.ior.value=h.ior,h.sheen>0&&(p.sheenColor.value.copy(h.sheenColor).multiplyScalar(h.sheen),p.sheenRoughness.value=h.sheenRoughness,h.sheenColorMap&&(p.sheenColorMap.value=h.sheenColorMap,t(h.sheenColorMap,p.sheenColorMapTransform)),h.sheenRoughnessMap&&(p.sheenRoughnessMap.value=h.sheenRoughnessMap,t(h.sheenRoughnessMap,p.sheenRoughnessMapTransform))),h.clearcoat>0&&(p.clearcoat.value=h.clearcoat,p.clearcoatRoughness.value=h.clearcoatRoughness,h.clearcoatMap&&(p.clearcoatMap.value=h.clearcoatMap,t(h.clearcoatMap,p.clearcoatMapTransform)),h.clearcoatRoughnessMap&&(p.clearcoatRoughnessMap.value=h.clearcoatRoughnessMap,t(h.clearcoatRoughnessMap,p.clearcoatRoughnessMapTransform)),h.clearcoatNormalMap&&(p.clearcoatNormalMap.value=h.clearcoatNormalMap,t(h.clearcoatNormalMap,p.clearcoatNormalMapTransform),p.clearcoatNormalScale.value.copy(h.clearcoatNormalScale),h.side===St&&p.clearcoatNormalScale.value.negate())),h.iridescence>0&&(p.iridescence.value=h.iridescence,p.iridescenceIOR.value=h.iridescenceIOR,p.iridescenceThicknessMinimum.value=h.iridescenceThicknessRange[0],p.iridescenceThicknessMaximum.value=h.iridescenceThicknessRange[1],h.iridescenceMap&&(p.iridescenceMap.value=h.iridescenceMap,t(h.iridescenceMap,p.iridescenceMapTransform)),h.iridescenceThicknessMap&&(p.iridescenceThicknessMap.value=h.iridescenceThicknessMap,t(h.iridescenceThicknessMap,p.iridescenceThicknessMapTransform))),h.transmission>0&&(p.transmission.value=h.transmission,p.transmissionSamplerMap.value=E.texture,p.transmissionSamplerSize.value.set(E.width,E.height),h.transmissionMap&&(p.transmissionMap.value=h.transmissionMap,t(h.transmissionMap,p.transmissionMapTransform)),p.thickness.value=h.thickness,h.thicknessMap&&(p.thicknessMap.value=h.thicknessMap,t(h.thicknessMap,p.thicknessMapTransform)),p.attenuationDistance.value=h.attenuationDistance,p.attenuationColor.value.copy(h.attenuationColor)),h.anisotropy>0&&(p.anisotropyVector.value.set(h.anisotropy*Math.cos(h.anisotropyRotation),h.anisotropy*Math.sin(h.anisotropyRotation)),h.anisotropyMap&&(p.anisotropyMap.value=h.anisotropyMap,t(h.anisotropyMap,p.anisotropyMapTransform))),p.specularIntensity.value=h.specularIntensity,p.specularColor.value.copy(h.specularColor),h.specularColorMap&&(p.specularColorMap.value=h.specularColorMap,t(h.specularColorMap,p.specularColorMapTransform)),h.specularIntensityMap&&(p.specularIntensityMap.value=h.specularIntensityMap,t(h.specularIntensityMap,p.specularIntensityMapTransform))}function g(p,h){h.matcap&&(p.matcap.value=h.matcap)}function x(p,h){const E=e.get(h).light;p.referencePosition.value.setFromMatrixPosition(E.matrixWorld),p.nearDistance.value=E.shadow.camera.near,p.farDistance.value=E.shadow.camera.far}return{refreshFogUniforms:n,refreshMaterialUniforms:r}}function Kd(i,e,t,n){let r={},s={},o=[];const a=t.isWebGL2?i.getParameter(i.MAX_UNIFORM_BUFFER_BINDINGS):0;function l(E,_){const A=_.program;n.uniformBlockBinding(E,A)}function c(E,_){let A=r[E.id];A===void 0&&(g(E),A=u(E),r[E.id]=A,E.addEventListener("dispose",p));const C=_.program;n.updateUBOMapping(E,C);const b=e.render.frame;s[E.id]!==b&&(d(E),s[E.id]=b)}function u(E){const _=f();E.__bindingPointIndex=_;const A=i.createBuffer(),C=E.__size,b=E.usage;return i.bindBuffer(i.UNIFORM_BUFFER,A),i.bufferData(i.UNIFORM_BUFFER,C,b),i.bindBuffer(i.UNIFORM_BUFFER,null),i.bindBufferBase(i.UNIFORM_BUFFER,_,A),A}function f(){for(let E=0;E0&&(A+=C-b),E.__size=A,E.__cache={},this}function x(E){const _={boundary:0,storage:0};return typeof E=="number"||typeof E=="boolean"?(_.boundary=4,_.storage=4):E.isVector2?(_.boundary=8,_.storage=8):E.isVector3||E.isColor?(_.boundary=16,_.storage=12):E.isVector4?(_.boundary=16,_.storage=16):E.isMatrix3?(_.boundary=48,_.storage=48):E.isMatrix4?(_.boundary=64,_.storage=64):E.isTexture?console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group."):console.warn("THREE.WebGLRenderer: Unsupported uniform value type.",E),_}function p(E){const _=E.target;_.removeEventListener("dispose",p);const A=o.indexOf(_.__bindingPointIndex);o.splice(A,1),i.deleteBuffer(r[_.id]),delete r[_.id],delete s[_.id]}function h(){for(const E in r)i.deleteBuffer(r[E]);o=[],r={},s={}}return{bind:l,update:c,dispose:h}}class Zd{constructor(e={}){const{canvas:t=Wl(),context:n=null,depth:r=!0,stencil:s=!0,alpha:o=!1,antialias:a=!1,premultipliedAlpha:l=!0,preserveDrawingBuffer:c=!1,powerPreference:u="default",failIfMajorPerformanceCaveat:f=!1}=e;this.isWebGLRenderer=!0;let d;n!==null?d=n.getContextAttributes().alpha:d=o;const m=new Uint32Array(4),g=new Int32Array(4);let x=null,p=null;const h=[],E=[];this.domElement=t,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this._outputColorSpace=ct,this._useLegacyLights=!1,this.toneMapping=on,this.toneMappingExposure=1;const _=this;let A=!1,C=0,b=0,w=null,z=-1,M=null;const T=new lt,B=new lt;let V=null;const ee=new Ge(0);let L=0,U=t.width,k=t.height,q=1,X=null,W=null;const Z=new lt(0,0,U,k),Q=new lt(0,0,U,k);let le=!1;const H=new is;let Y=!1,ae=!1,me=null;const pe=new $e,we=new ze,Ce=new P,Se={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};function He(){return w===null?q:1}let I=n;function mt(S,D){for(let O=0;O{function oe(){if(G.forEach(function(de){De.get(de).currentProgram.isReady()&&G.delete(de)}),G.size===0){N(S);return}setTimeout(oe,10)}ge.get("KHR_parallel_shader_compile")!==null?oe():setTimeout(oe,10)})};let qe=null;function st(S){qe&&qe(S)}function _t(){gt.stop()}function Ye(){gt.start()}const gt=new fo;gt.setAnimationLoop(st),typeof self<"u"&>.setContext(self),this.setAnimationLoop=function(S){qe=S,Ne.setAnimationLoop(S),S===null?gt.stop():gt.start()},Ne.addEventListener("sessionstart",_t),Ne.addEventListener("sessionend",Ye),this.render=function(S,D){if(D!==void 0&&D.isCamera!==!0){console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(A===!0)return;S.matrixWorldAutoUpdate===!0&&S.updateMatrixWorld(),D.parent===null&&D.matrixWorldAutoUpdate===!0&&D.updateMatrixWorld(),Ne.enabled===!0&&Ne.isPresenting===!0&&(Ne.cameraAutoUpdate===!0&&Ne.updateCamera(D),D=Ne.getCamera()),S.isScene===!0&&S.onBeforeRender(_,S,D,w),p=Me.get(S,E.length),p.init(),E.push(p),pe.multiplyMatrices(D.projectionMatrix,D.matrixWorldInverse),H.setFromProjectionMatrix(pe),ae=this.localClippingEnabled,Y=Ue.init(this.clippingPlanes,ae),x=ce.get(S,h.length),x.init(),h.push(x),zt(S,D,0,_.sortObjects),x.finish(),_.sortObjects===!0&&x.sort(X,W),this.info.render.frame++,Y===!0&&Ue.beginShadows();const O=p.state.shadowsArray;if(j.render(O,S,D),Y===!0&&Ue.endShadows(),this.info.autoReset===!0&&this.info.reset(),ke.render(x,S),p.setupLights(_._useLegacyLights),D.isArrayCamera){const G=D.cameras;for(let N=0,oe=G.length;N0?p=E[E.length-1]:p=null,h.pop(),h.length>0?x=h[h.length-1]:x=null};function zt(S,D,O,G){if(S.visible===!1)return;if(S.layers.test(D.layers)){if(S.isGroup)O=S.renderOrder;else if(S.isLOD)S.autoUpdate===!0&&S.update(D);else if(S.isLight)p.pushLight(S),S.castShadow&&p.pushShadow(S);else if(S.isSprite){if(!S.frustumCulled||H.intersectsSprite(S)){G&&Ce.setFromMatrixPosition(S.matrixWorld).applyMatrix4(pe);const de=J.update(S),xe=S.material;xe.visible&&x.push(S,de,xe,O,Ce.z,null)}}else if((S.isMesh||S.isLine||S.isPoints)&&(!S.frustumCulled||H.intersectsObject(S))){const de=J.update(S),xe=S.material;if(G&&(S.boundingSphere!==void 0?(S.boundingSphere===null&&S.computeBoundingSphere(),Ce.copy(S.boundingSphere.center)):(de.boundingSphere===null&&de.computeBoundingSphere(),Ce.copy(de.boundingSphere.center)),Ce.applyMatrix4(S.matrixWorld).applyMatrix4(pe)),Array.isArray(xe)){const ye=de.groups;for(let Ie=0,be=ye.length;Ie0&&bo(N,oe,D,O),G&&ue.viewport(T.copy(G)),N.length>0&&vi(N,D,O),oe.length>0&&vi(oe,D,O),de.length>0&&vi(de,D,O),ue.buffers.depth.setTest(!0),ue.buffers.depth.setMask(!0),ue.buffers.color.setMask(!0),ue.setPolygonOffset(!1)}function bo(S,D,O,G){if((O.isScene===!0?O.overrideMaterial:null)!==null)return;const oe=Ae.isWebGL2;me===null&&(me=new yn(1,1,{generateMipmaps:!0,type:ge.has("EXT_color_buffer_half_float")?pi:ln,minFilter:di,samples:oe?4:0})),_.getDrawingBufferSize(we),oe?me.setSize(we.x,we.y):me.setSize(Ji(we.x),Ji(we.y));const de=_.getRenderTarget();_.setRenderTarget(me),_.getClearColor(ee),L=_.getClearAlpha(),L<1&&_.setClearColor(16777215,.5),_.clear();const xe=_.toneMapping;_.toneMapping=on,vi(S,O,G),y.updateMultisampleRenderTarget(me),y.updateRenderTargetMipmap(me);let ye=!1;for(let Ie=0,be=D.length;Ie0),Re=!!O.morphAttributes.position,et=!!O.morphAttributes.normal,Et=!!O.morphAttributes.color;let at=on;G.toneMapped&&(w===null||w.isXRRenderTarget===!0)&&(at=_.toneMapping);const Vt=O.morphAttributes.position||O.morphAttributes.normal||O.morphAttributes.color,Ze=Vt!==void 0?Vt.length:0,Fe=De.get(G),rr=p.state.lights;if(Y===!0&&(ae===!0||S!==M)){const bt=S===M&&G.id===z;Ue.setState(G,S,bt)}let Qe=!1;G.version===Fe.__version?(Fe.needsLights&&Fe.lightsStateVersion!==rr.state.version||Fe.outputColorSpace!==xe||N.isBatchedMesh&&Fe.batching===!1||!N.isBatchedMesh&&Fe.batching===!0||N.isInstancedMesh&&Fe.instancing===!1||!N.isInstancedMesh&&Fe.instancing===!0||N.isSkinnedMesh&&Fe.skinning===!1||!N.isSkinnedMesh&&Fe.skinning===!0||N.isInstancedMesh&&Fe.instancingColor===!0&&N.instanceColor===null||N.isInstancedMesh&&Fe.instancingColor===!1&&N.instanceColor!==null||Fe.envMap!==ye||G.fog===!0&&Fe.fog!==oe||Fe.numClippingPlanes!==void 0&&(Fe.numClippingPlanes!==Ue.numPlanes||Fe.numIntersection!==Ue.numIntersection)||Fe.vertexAlphas!==Ie||Fe.vertexTangents!==be||Fe.morphTargets!==Re||Fe.morphNormals!==et||Fe.morphColors!==Et||Fe.toneMapping!==at||Ae.isWebGL2===!0&&Fe.morphTargetsCount!==Ze)&&(Qe=!0):(Qe=!0,Fe.__version=G.version);let hn=Fe.currentProgram;Qe===!0&&(hn=xi(G,D,N));let us=!1,ii=!1,sr=!1;const ft=hn.getUniforms(),un=Fe.uniforms;if(ue.useProgram(hn.program)&&(us=!0,ii=!0,sr=!0),G.id!==z&&(z=G.id,ii=!0),us||M!==S){ft.setValue(I,"projectionMatrix",S.projectionMatrix),ft.setValue(I,"viewMatrix",S.matrixWorldInverse);const bt=ft.map.cameraPosition;bt!==void 0&&bt.setValue(I,Ce.setFromMatrixPosition(S.matrixWorld)),Ae.logarithmicDepthBuffer&&ft.setValue(I,"logDepthBufFC",2/(Math.log(S.far+1)/Math.LN2)),(G.isMeshPhongMaterial||G.isMeshToonMaterial||G.isMeshLambertMaterial||G.isMeshBasicMaterial||G.isMeshStandardMaterial||G.isShaderMaterial)&&ft.setValue(I,"isOrthographic",S.isOrthographicCamera===!0),M!==S&&(M=S,ii=!0,sr=!0)}if(N.isSkinnedMesh){ft.setOptional(I,N,"bindMatrix"),ft.setOptional(I,N,"bindMatrixInverse");const bt=N.skeleton;bt&&(Ae.floatVertexTextures?(bt.boneTexture===null&&bt.computeBoneTexture(),ft.setValue(I,"boneTexture",bt.boneTexture,y)):console.warn("THREE.WebGLRenderer: SkinnedMesh can only be used with WebGL 2. With WebGL 1 OES_texture_float and vertex textures support is required."))}N.isBatchedMesh&&(ft.setOptional(I,N,"batchingTexture"),ft.setValue(I,"batchingTexture",N._matricesTexture,y));const ar=O.morphAttributes;if((ar.position!==void 0||ar.normal!==void 0||ar.color!==void 0&&Ae.isWebGL2===!0)&&Be.update(N,O,hn),(ii||Fe.receiveShadow!==N.receiveShadow)&&(Fe.receiveShadow=N.receiveShadow,ft.setValue(I,"receiveShadow",N.receiveShadow)),G.isMeshGouraudMaterial&&G.envMap!==null&&(un.envMap.value=ye,un.flipEnvMap.value=ye.isCubeTexture&&ye.isRenderTargetTexture===!1?-1:1),ii&&(ft.setValue(I,"toneMappingExposure",_.toneMappingExposure),Fe.needsLights&&Ro(un,sr),oe&&G.fog===!0&&se.refreshFogUniforms(un,oe),se.refreshMaterialUniforms(un,G,q,k,me),qi.upload(I,cs(Fe),un,y)),G.isShaderMaterial&&G.uniformsNeedUpdate===!0&&(qi.upload(I,cs(Fe),un,y),G.uniformsNeedUpdate=!1),G.isSpriteMaterial&&ft.setValue(I,"center",N.center),ft.setValue(I,"modelViewMatrix",N.modelViewMatrix),ft.setValue(I,"normalMatrix",N.normalMatrix),ft.setValue(I,"modelMatrix",N.matrixWorld),G.isShaderMaterial||G.isRawShaderMaterial){const bt=G.uniformsGroups;for(let or=0,Lo=bt.length;or0&&y.useMultisampledRTT(S)===!1?N=De.get(S).__webglMultisampledFramebuffer:Array.isArray(be)?N=be[O]:N=be,T.copy(S.viewport),B.copy(S.scissor),V=S.scissorTest}else T.copy(Z).multiplyScalar(q).floor(),B.copy(Q).multiplyScalar(q).floor(),V=le;if(ue.bindFramebuffer(I.FRAMEBUFFER,N)&&Ae.drawBuffers&&G&&ue.drawBuffers(S,N),ue.viewport(T),ue.scissor(B),ue.setScissorTest(V),oe){const ye=De.get(S.texture);I.framebufferTexture2D(I.FRAMEBUFFER,I.COLOR_ATTACHMENT0,I.TEXTURE_CUBE_MAP_POSITIVE_X+D,ye.__webglTexture,O)}else if(de){const ye=De.get(S.texture),Ie=D||0;I.framebufferTextureLayer(I.FRAMEBUFFER,I.COLOR_ATTACHMENT0,ye.__webglTexture,O||0,Ie)}z=-1},this.readRenderTargetPixels=function(S,D,O,G,N,oe,de){if(!(S&&S.isWebGLRenderTarget)){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let xe=De.get(S).__webglFramebuffer;if(S.isWebGLCubeRenderTarget&&de!==void 0&&(xe=xe[de]),xe){ue.bindFramebuffer(I.FRAMEBUFFER,xe);try{const ye=S.texture,Ie=ye.format,be=ye.type;if(Ie!==Ot&&he.convert(Ie)!==I.getParameter(I.IMPLEMENTATION_COLOR_READ_FORMAT)){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}const Re=be===pi&&(ge.has("EXT_color_buffer_half_float")||Ae.isWebGL2&&ge.has("EXT_color_buffer_float"));if(be!==ln&&he.convert(be)!==I.getParameter(I.IMPLEMENTATION_COLOR_READ_TYPE)&&!(be===sn&&(Ae.isWebGL2||ge.has("OES_texture_float")||ge.has("WEBGL_color_buffer_float")))&&!Re){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");return}D>=0&&D<=S.width-G&&O>=0&&O<=S.height-N&&I.readPixels(D,O,G,N,he.convert(Ie),he.convert(be),oe)}finally{const ye=w!==null?De.get(w).__webglFramebuffer:null;ue.bindFramebuffer(I.FRAMEBUFFER,ye)}}},this.copyFramebufferToTexture=function(S,D,O=0){const G=Math.pow(2,-O),N=Math.floor(D.image.width*G),oe=Math.floor(D.image.height*G);y.setTexture2D(D,0),I.copyTexSubImage2D(I.TEXTURE_2D,O,0,0,S.x,S.y,N,oe),ue.unbindTexture()},this.copyTextureToTexture=function(S,D,O,G=0){const N=D.image.width,oe=D.image.height,de=he.convert(O.format),xe=he.convert(O.type);y.setTexture2D(O,0),I.pixelStorei(I.UNPACK_FLIP_Y_WEBGL,O.flipY),I.pixelStorei(I.UNPACK_PREMULTIPLY_ALPHA_WEBGL,O.premultiplyAlpha),I.pixelStorei(I.UNPACK_ALIGNMENT,O.unpackAlignment),D.isDataTexture?I.texSubImage2D(I.TEXTURE_2D,G,S.x,S.y,N,oe,de,xe,D.image.data):D.isCompressedTexture?I.compressedTexSubImage2D(I.TEXTURE_2D,G,S.x,S.y,D.mipmaps[0].width,D.mipmaps[0].height,de,D.mipmaps[0].data):I.texSubImage2D(I.TEXTURE_2D,G,S.x,S.y,de,xe,D.image),G===0&&O.generateMipmaps&&I.generateMipmap(I.TEXTURE_2D),ue.unbindTexture()},this.copyTextureToTexture3D=function(S,D,O,G,N=0){if(_.isWebGL1Renderer){console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: can only be used with WebGL2.");return}const oe=S.max.x-S.min.x+1,de=S.max.y-S.min.y+1,xe=S.max.z-S.min.z+1,ye=he.convert(G.format),Ie=he.convert(G.type);let be;if(G.isData3DTexture)y.setTexture3D(G,0),be=I.TEXTURE_3D;else if(G.isDataArrayTexture||G.isCompressedArrayTexture)y.setTexture2DArray(G,0),be=I.TEXTURE_2D_ARRAY;else{console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.");return}I.pixelStorei(I.UNPACK_FLIP_Y_WEBGL,G.flipY),I.pixelStorei(I.UNPACK_PREMULTIPLY_ALPHA_WEBGL,G.premultiplyAlpha),I.pixelStorei(I.UNPACK_ALIGNMENT,G.unpackAlignment);const Re=I.getParameter(I.UNPACK_ROW_LENGTH),et=I.getParameter(I.UNPACK_IMAGE_HEIGHT),Et=I.getParameter(I.UNPACK_SKIP_PIXELS),at=I.getParameter(I.UNPACK_SKIP_ROWS),Vt=I.getParameter(I.UNPACK_SKIP_IMAGES),Ze=O.isCompressedTexture?O.mipmaps[N]:O.image;I.pixelStorei(I.UNPACK_ROW_LENGTH,Ze.width),I.pixelStorei(I.UNPACK_IMAGE_HEIGHT,Ze.height),I.pixelStorei(I.UNPACK_SKIP_PIXELS,S.min.x),I.pixelStorei(I.UNPACK_SKIP_ROWS,S.min.y),I.pixelStorei(I.UNPACK_SKIP_IMAGES,S.min.z),O.isDataTexture||O.isData3DTexture?I.texSubImage3D(be,N,D.x,D.y,D.z,oe,de,xe,ye,Ie,Ze.data):O.isCompressedArrayTexture?(console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: untested support for compressed srcTexture."),I.compressedTexSubImage3D(be,N,D.x,D.y,D.z,oe,de,xe,ye,Ze.data)):I.texSubImage3D(be,N,D.x,D.y,D.z,oe,de,xe,ye,Ie,Ze),I.pixelStorei(I.UNPACK_ROW_LENGTH,Re),I.pixelStorei(I.UNPACK_IMAGE_HEIGHT,et),I.pixelStorei(I.UNPACK_SKIP_PIXELS,Et),I.pixelStorei(I.UNPACK_SKIP_ROWS,at),I.pixelStorei(I.UNPACK_SKIP_IMAGES,Vt),N===0&&G.generateMipmaps&&I.generateMipmap(be),ue.unbindTexture()},this.initTexture=function(S){S.isCubeTexture?y.setTextureCube(S,0):S.isData3DTexture?y.setTexture3D(S,0):S.isDataArrayTexture||S.isCompressedArrayTexture?y.setTexture2DArray(S,0):y.setTexture2D(S,0),ue.unbindTexture()},this.resetState=function(){C=0,b=0,w=null,ue.reset(),Le.reset()},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return Zt}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(e){this._outputColorSpace=e;const t=this.getContext();t.drawingBufferColorSpace=e===Qr?"display-p3":"srgb",t.unpackColorSpace=We.workingColorSpace===tr?"display-p3":"srgb"}get outputEncoding(){return console.warn("THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead."),this.outputColorSpace===ct?En:Qa}set outputEncoding(e){console.warn("THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead."),this.outputColorSpace=e===En?ct:$t}get useLegacyLights(){return console.warn("THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733."),this._useLegacyLights}set useLegacyLights(e){console.warn("THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733."),this._useLegacyLights=e}}class $d extends Zd{}$d.prototype.isWebGL1Renderer=!0;class rp extends ut{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(e,t){return super.copy(e,t),e.background!==null&&(this.background=e.background.clone()),e.environment!==null&&(this.environment=e.environment.clone()),e.fog!==null&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,e.overrideMaterial!==null&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){const t=super.toJSON(e);return this.fog!==null&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t}}class Ua extends Bt{constructor(e,t,n,r=1){super(e,t,n),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=r}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}toJSON(){const e=super.toJSON();return e.meshPerAttribute=this.meshPerAttribute,e.isInstancedBufferAttribute=!0,e}}const kn=new $e,Ia=new $e,ki=[],Na=new An,Jd=new $e,li=new Ht,ci=new ti;class sp extends Ht{constructor(e,t,n){super(e,t),this.isInstancedMesh=!0,this.instanceMatrix=new Ua(new Float32Array(n*16),16),this.instanceColor=null,this.count=n,this.boundingBox=null,this.boundingSphere=null;for(let r=0;rl)continue;d.applyMatrix4(this.matrixWorld);const z=e.ray.origin.distanceTo(d);ze.far||t.push({distance:z,point:f.clone().applyMatrix4(this.matrixWorld),index:_,face:null,faceIndex:null,object:this})}}else{const h=Math.max(0,o.start),E=Math.min(p.count,o.start+o.count);for(let _=h,A=E-1;_l)continue;d.applyMatrix4(this.matrixWorld);const b=e.ray.origin.distanceTo(d);be.far||t.push({distance:b,point:f.clone().applyMatrix4(this.matrixWorld),index:_,face:null,faceIndex:null,object:this})}}}updateMorphTargets(){const t=this.geometry.morphAttributes,n=Object.keys(t);if(n.length>0){const r=t[n[0]];if(r!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=r.length;s0&&_(!0),t>0&&_(!1)),this.setIndex(u),this.setAttribute("position",new nt(f,3)),this.setAttribute("normal",new nt(d,3)),this.setAttribute("uv",new nt(m,2));function E(){const A=new P,C=new P;let b=0;const w=(t-e)/n;for(let z=0;z<=s;z++){const M=[],T=z/s,B=T*(t-e)+e;for(let V=0;V<=r;V++){const ee=V/r,L=ee*l+a,U=Math.sin(L),k=Math.cos(L);C.x=B*U,C.y=-T*n+p,C.z=B*k,f.push(C.x,C.y,C.z),A.set(U,w,k).normalize(),d.push(A.x,A.y,A.z),m.push(ee,1-T),M.push(g++)}x.push(M)}for(let z=0;z.9&&w<.1&&(_<.2&&(o[E+0]+=1),A<.2&&(o[E+2]+=1),C<.2&&(o[E+4]+=1))}}function d(E){s.push(E.x,E.y,E.z)}function m(E,_){const A=E*3;_.x=e[A+0],_.y=e[A+1],_.z=e[A+2]}function g(){const E=new P,_=new P,A=new P,C=new P,b=new ze,w=new ze,z=new ze;for(let M=0,T=0;M0)&&m.push(_,A,b),(h!==n-1||l"u"?Date:performance).now()}class fp{constructor(e,t,n=0,r=1/0){this.ray=new ts(e,t),this.near=n,this.far=r,this.camera=null,this.layers=new ns,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(e,t){this.ray.set(e,t)}setFromCamera(e,t){t.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(e.x,e.y,.5).unproject(t).sub(this.ray.origin).normalize(),this.camera=t):t.isOrthographicCamera?(this.ray.origin.set(e.x,e.y,(t.near+t.far)/(t.near-t.far)).unproject(t),this.ray.direction.set(0,0,-1).transformDirection(t.matrixWorld),this.camera=t):console.error("THREE.Raycaster: Unsupported camera type: "+t.type)}intersectObject(e,t=!0,n=[]){return jr(e,this,n,t),n.sort(Va),n}intersectObjects(e,t=!0,n=[]){for(let r=0,s=e.length;rt in i?dh(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var ht=(i,t,e)=>(ph(i,typeof t!="symbol"?t+"":t,e),e);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))n(s);new MutationObserver(s=>{for(const r of s)if(r.type==="childList")for(const a of r.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&n(a)}).observe(document,{childList:!0,subtree:!0});function e(s){const r={};return s.integrity&&(r.integrity=s.integrity),s.referrerPolicy&&(r.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?r.credentials="include":s.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function n(s){if(s.ep)return;s.ep=!0;const r=e(s);fetch(s.href,r)}})();/** - * @license - * Copyright 2010-2023 Three.js Authors - * SPDX-License-Identifier: MIT - */const ra="160",mh={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},_h=0,ba=1,gh=2,yl=1,xh=2,yn=3,_n=0,Oe=1,mn=2,Gn=0,ki=1,wa=2,Ca=3,Ra=4,vh=5,ei=100,Eh=101,Mh=102,Pa=103,La=104,Sh=200,yh=201,Th=202,Ah=203,zo=204,Ho=205,bh=206,wh=207,Ch=208,Rh=209,Ph=210,Lh=211,Uh=212,Dh=213,Ih=214,Oh=0,Nh=1,Fh=2,Sr=3,Bh=4,zh=5,Hh=6,Vh=7,Tl=0,Gh=1,kh=2,kn=0,Wh=1,Xh=2,Yh=3,qh=4,Zh=5,Kh=6,Al=300,Xi=301,Yi=302,Vo=303,Go=304,Ir=306,ko=1e3,an=1001,Wo=1002,Ie=1003,Ua=1004,Xr=1005,qe=1006,$h=1007,ys=1008,Wn=1009,jh=1010,Jh=1011,oa=1012,bl=1013,zn=1014,Hn=1015,Ts=1016,wl=1017,Cl=1018,ii=1020,Qh=1021,cn=1023,tu=1024,eu=1025,si=1026,qi=1027,nu=1028,Rl=1029,iu=1030,Pl=1031,Ll=1033,Yr=33776,qr=33777,Zr=33778,Kr=33779,Da=35840,Ia=35841,Oa=35842,Na=35843,Ul=36196,Fa=37492,Ba=37496,za=37808,Ha=37809,Va=37810,Ga=37811,ka=37812,Wa=37813,Xa=37814,Ya=37815,qa=37816,Za=37817,Ka=37818,$a=37819,ja=37820,Ja=37821,$r=36492,Qa=36494,tc=36495,su=36283,ec=36284,nc=36285,ic=36286,Dl=3e3,ri=3001,ru=3200,ou=3201,au=0,cu=1,Ke="",Me="srgb",Cn="srgb-linear",aa="display-p3",Or="display-p3-linear",yr="linear",ie="srgb",Tr="rec709",Ar="p3",li=7680,sc=519,lu=512,hu=513,uu=514,Il=515,fu=516,du=517,pu=518,mu=519,rc=35044,oc="300 es",Xo=1035,bn=2e3,br=2001;let Ki=class{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const n=this._listeners;n[t]===void 0&&(n[t]=[]),n[t].indexOf(e)===-1&&n[t].push(e)}hasEventListener(t,e){if(this._listeners===void 0)return!1;const n=this._listeners;return n[t]!==void 0&&n[t].indexOf(e)!==-1}removeEventListener(t,e){if(this._listeners===void 0)return;const s=this._listeners[t];if(s!==void 0){const r=s.indexOf(e);r!==-1&&s.splice(r,1)}}dispatchEvent(t){if(this._listeners===void 0)return;const n=this._listeners[t.type];if(n!==void 0){t.target=this;const s=n.slice(0);for(let r=0,a=s.length;r>8&255]+Ae[i>>16&255]+Ae[i>>24&255]+"-"+Ae[t&255]+Ae[t>>8&255]+"-"+Ae[t>>16&15|64]+Ae[t>>24&255]+"-"+Ae[e&63|128]+Ae[e>>8&255]+"-"+Ae[e>>16&255]+Ae[e>>24&255]+Ae[n&255]+Ae[n>>8&255]+Ae[n>>16&255]+Ae[n>>24&255]).toLowerCase()}function Se(i,t,e){return Math.max(t,Math.min(e,i))}function ca(i,t){return(i%t+t)%t}function _u(i,t,e,n,s){return n+(i-t)*(s-n)/(e-t)}function gu(i,t,e){return i!==t?(e-i)/(t-i):0}function vs(i,t,e){return(1-e)*i+e*t}function xu(i,t,e,n){return vs(i,t,1-Math.exp(-e*n))}function vu(i,t=1){return t-Math.abs(ca(i,t*2)-t)}function Eu(i,t,e){return i<=t?0:i>=e?1:(i=(i-t)/(e-t),i*i*(3-2*i))}function Mu(i,t,e){return i<=t?0:i>=e?1:(i=(i-t)/(e-t),i*i*i*(i*(i*6-15)+10))}function Su(i,t){return i+Math.floor(Math.random()*(t-i+1))}function yu(i,t){return i+Math.random()*(t-i)}function Tu(i){return i*(.5-Math.random())}function Au(i){i!==void 0&&(ac=i);let t=ac+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function bu(i){return i*xs}function wu(i){return i*As}function Yo(i){return(i&i-1)===0&&i!==0}function Cu(i){return Math.pow(2,Math.ceil(Math.log(i)/Math.LN2))}function wr(i){return Math.pow(2,Math.floor(Math.log(i)/Math.LN2))}function Ru(i,t,e,n,s){const r=Math.cos,a=Math.sin,o=r(e/2),c=a(e/2),l=r((t+n)/2),h=a((t+n)/2),f=r((t-n)/2),u=a((t-n)/2),m=r((n-t)/2),g=a((n-t)/2);switch(s){case"XYX":i.set(o*h,c*f,c*u,o*l);break;case"YZY":i.set(c*u,o*h,c*f,o*l);break;case"ZXZ":i.set(c*f,c*u,o*h,o*l);break;case"XZX":i.set(o*h,c*g,c*m,o*l);break;case"YXY":i.set(c*m,o*h,c*g,o*l);break;case"ZYZ":i.set(c*g,c*m,o*h,o*l);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+s)}}function zi(i,t){switch(t.constructor){case Float32Array:return i;case Uint32Array:return i/4294967295;case Uint16Array:return i/65535;case Uint8Array:return i/255;case Int32Array:return Math.max(i/2147483647,-1);case Int16Array:return Math.max(i/32767,-1);case Int8Array:return Math.max(i/127,-1);default:throw new Error("Invalid component type.")}}function Ue(i,t){switch(t.constructor){case Float32Array:return i;case Uint32Array:return Math.round(i*4294967295);case Uint16Array:return Math.round(i*65535);case Uint8Array:return Math.round(i*255);case Int32Array:return Math.round(i*2147483647);case Int16Array:return Math.round(i*32767);case Int8Array:return Math.round(i*127);default:throw new Error("Invalid component type.")}}const Pu={DEG2RAD:xs,RAD2DEG:As,generateUUID:$i,clamp:Se,euclideanModulo:ca,mapLinear:_u,inverseLerp:gu,lerp:vs,damp:xu,pingpong:vu,smoothstep:Eu,smootherstep:Mu,randInt:Su,randFloat:yu,randFloatSpread:Tu,seededRandom:Au,degToRad:bu,radToDeg:wu,isPowerOfTwo:Yo,ceilPowerOfTwo:Cu,floorPowerOfTwo:wr,setQuaternionFromProperEuler:Ru,normalize:Ue,denormalize:zi};class kt{constructor(t=0,e=0){kt.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,n=this.y,s=t.elements;return this.x=s[0]*e+s[3]*n+s[6],this.y=s[1]*e+s[4]*n+s[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(Se(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y;return e*e+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const n=Math.cos(e),s=Math.sin(e),r=this.x-t.x,a=this.y-t.y;return this.x=r*n-a*s+t.x,this.y=r*s+a*n+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Gt{constructor(t,e,n,s,r,a,o,c,l){Gt.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,n,s,r,a,o,c,l)}set(t,e,n,s,r,a,o,c,l){const h=this.elements;return h[0]=t,h[1]=s,h[2]=o,h[3]=e,h[4]=r,h[5]=c,h[6]=n,h[7]=a,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],this}extractBasis(t,e,n){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,s=e.elements,r=this.elements,a=n[0],o=n[3],c=n[6],l=n[1],h=n[4],f=n[7],u=n[2],m=n[5],g=n[8],x=s[0],p=s[3],d=s[6],M=s[1],v=s[4],_=s[7],y=s[2],A=s[5],T=s[8];return r[0]=a*x+o*M+c*y,r[3]=a*p+o*v+c*A,r[6]=a*d+o*_+c*T,r[1]=l*x+h*M+f*y,r[4]=l*p+h*v+f*A,r[7]=l*d+h*_+f*T,r[2]=u*x+m*M+g*y,r[5]=u*p+m*v+g*A,r[8]=u*d+m*_+g*T,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[1],s=t[2],r=t[3],a=t[4],o=t[5],c=t[6],l=t[7],h=t[8];return e*a*h-e*o*l-n*r*h+n*o*c+s*r*l-s*a*c}invert(){const t=this.elements,e=t[0],n=t[1],s=t[2],r=t[3],a=t[4],o=t[5],c=t[6],l=t[7],h=t[8],f=h*a-o*l,u=o*c-h*r,m=l*r-a*c,g=e*f+n*u+s*m;if(g===0)return this.set(0,0,0,0,0,0,0,0,0);const x=1/g;return t[0]=f*x,t[1]=(s*l-h*n)*x,t[2]=(o*n-s*a)*x,t[3]=u*x,t[4]=(h*e-s*c)*x,t[5]=(s*r-o*e)*x,t[6]=m*x,t[7]=(n*c-l*e)*x,t[8]=(a*e-n*r)*x,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,n,s,r,a,o){const c=Math.cos(r),l=Math.sin(r);return this.set(n*c,n*l,-n*(c*a+l*o)+a+t,-s*l,s*c,-s*(-l*a+c*o)+o+e,0,0,1),this}scale(t,e){return this.premultiply(jr.makeScale(t,e)),this}rotate(t){return this.premultiply(jr.makeRotation(-t)),this}translate(t,e){return this.premultiply(jr.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,n,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,n=t.elements;for(let s=0;s<9;s++)if(e[s]!==n[s])return!1;return!0}fromArray(t,e=0){for(let n=0;n<9;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t}clone(){return new this.constructor().fromArray(this.elements)}}const jr=new Gt;function Ol(i){for(let t=i.length-1;t>=0;--t)if(i[t]>=65535)return!0;return!1}function Cr(i){return document.createElementNS("http://www.w3.org/1999/xhtml",i)}function Lu(){const i=Cr("canvas");return i.style.display="block",i}const cc={};function Es(i){i in cc||(cc[i]=!0,console.warn(i))}const lc=new Gt().set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),hc=new Gt().set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),Ls={[Cn]:{transfer:yr,primaries:Tr,toReference:i=>i,fromReference:i=>i},[Me]:{transfer:ie,primaries:Tr,toReference:i=>i.convertSRGBToLinear(),fromReference:i=>i.convertLinearToSRGB()},[Or]:{transfer:yr,primaries:Ar,toReference:i=>i.applyMatrix3(hc),fromReference:i=>i.applyMatrix3(lc)},[aa]:{transfer:ie,primaries:Ar,toReference:i=>i.convertSRGBToLinear().applyMatrix3(hc),fromReference:i=>i.applyMatrix3(lc).convertLinearToSRGB()}},Uu=new Set([Cn,Or]),jt={enabled:!0,_workingColorSpace:Cn,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(i){if(!Uu.has(i))throw new Error(`Unsupported working color space, "${i}".`);this._workingColorSpace=i},convert:function(i,t,e){if(this.enabled===!1||t===e||!t||!e)return i;const n=Ls[t].toReference,s=Ls[e].fromReference;return s(n(i))},fromWorkingColorSpace:function(i,t){return this.convert(i,this._workingColorSpace,t)},toWorkingColorSpace:function(i,t){return this.convert(i,t,this._workingColorSpace)},getPrimaries:function(i){return Ls[i].primaries},getTransfer:function(i){return i===Ke?yr:Ls[i].transfer}};function Wi(i){return i<.04045?i*.0773993808:Math.pow(i*.9478672986+.0521327014,2.4)}function Jr(i){return i<.0031308?i*12.92:1.055*Math.pow(i,.41666)-.055}let hi;class Nl{static getDataURL(t){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{hi===void 0&&(hi=Cr("canvas")),hi.width=t.width,hi.height=t.height;const n=hi.getContext("2d");t instanceof ImageData?n.putImageData(t,0,0):n.drawImage(t,0,0,t.width,t.height),e=hi}return e.width>2048||e.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",t),e.toDataURL("image/jpeg",.6)):e.toDataURL("image/png")}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=Cr("canvas");e.width=t.width,e.height=t.height;const n=e.getContext("2d");n.drawImage(t,0,0,t.width,t.height);const s=n.getImageData(0,0,t.width,t.height),r=s.data;for(let a=0;a0&&(n.userData=this.userData),e||(t.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==Al)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case ko:t.x=t.x-Math.floor(t.x);break;case an:t.x=t.x<0?0:1;break;case Wo:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case ko:t.y=t.y-Math.floor(t.y);break;case an:t.y=t.y<0?0:1;break;case Wo:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}get encoding(){return Es("THREE.Texture: Property .encoding has been replaced by .colorSpace."),this.colorSpace===Me?ri:Dl}set encoding(t){Es("THREE.Texture: Property .encoding has been replaced by .colorSpace."),this.colorSpace=t===ri?Me:Ke}}ke.DEFAULT_IMAGE=null;ke.DEFAULT_MAPPING=Al;ke.DEFAULT_ANISOTROPY=1;class pe{constructor(t=0,e=0,n=0,s=1){pe.prototype.isVector4=!0,this.x=t,this.y=e,this.z=n,this.w=s}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,n,s){return this.x=t,this.y=e,this.z=n,this.w=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,n=this.y,s=this.z,r=this.w,a=t.elements;return this.x=a[0]*e+a[4]*n+a[8]*s+a[12]*r,this.y=a[1]*e+a[5]*n+a[9]*s+a[13]*r,this.z=a[2]*e+a[6]*n+a[10]*s+a[14]*r,this.w=a[3]*e+a[7]*n+a[11]*s+a[15]*r,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,n,s,r;const c=t.elements,l=c[0],h=c[4],f=c[8],u=c[1],m=c[5],g=c[9],x=c[2],p=c[6],d=c[10];if(Math.abs(h-u)<.01&&Math.abs(f-x)<.01&&Math.abs(g-p)<.01){if(Math.abs(h+u)<.1&&Math.abs(f+x)<.1&&Math.abs(g+p)<.1&&Math.abs(l+m+d-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const v=(l+1)/2,_=(m+1)/2,y=(d+1)/2,A=(h+u)/4,T=(f+x)/4,P=(g+p)/4;return v>_&&v>y?v<.01?(n=0,s=.707106781,r=.707106781):(n=Math.sqrt(v),s=A/n,r=T/n):_>y?_<.01?(n=.707106781,s=0,r=.707106781):(s=Math.sqrt(_),n=A/s,r=P/s):y<.01?(n=.707106781,s=.707106781,r=0):(r=Math.sqrt(y),n=T/r,s=P/r),this.set(n,s,r,e),this}let M=Math.sqrt((p-g)*(p-g)+(f-x)*(f-x)+(u-h)*(u-h));return Math.abs(M)<.001&&(M=1),this.x=(p-g)/M,this.y=(f-x)/M,this.z=(u-h)/M,this.w=Math.acos((l+m+d-1)/2),this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this.w=Math.max(t.w,Math.min(e.w,this.w)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this.w=Math.max(t,Math.min(e,this.w)),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this.w=t.w+(e.w-t.w)*n,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class Ou extends Ki{constructor(t=1,e=1,n={}){super(),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=1,this.scissor=new pe(0,0,t,e),this.scissorTest=!1,this.viewport=new pe(0,0,t,e);const s={width:t,height:e,depth:1};n.encoding!==void 0&&(Es("THREE.WebGLRenderTarget: option.encoding has been replaced by option.colorSpace."),n.colorSpace=n.encoding===ri?Me:Ke),n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:qe,depthBuffer:!0,stencilBuffer:!1,depthTexture:null,samples:0},n),this.texture=new ke(s,n.mapping,n.wrapS,n.wrapT,n.magFilter,n.minFilter,n.format,n.type,n.anisotropy,n.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.flipY=!1,this.texture.generateMipmaps=n.generateMipmaps,this.texture.internalFormat=n.internalFormat,this.depthBuffer=n.depthBuffer,this.stencilBuffer=n.stencilBuffer,this.depthTexture=n.depthTexture,this.samples=n.samples}setSize(t,e,n=1){(this.width!==t||this.height!==e||this.depth!==n)&&(this.width=t,this.height=e,this.depth=n,this.texture.image.width=t,this.texture.image.height=e,this.texture.image.depth=n,this.dispose()),this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e)}clone(){return new this.constructor().copy(this)}copy(t){this.width=t.width,this.height=t.height,this.depth=t.depth,this.scissor.copy(t.scissor),this.scissorTest=t.scissorTest,this.viewport.copy(t.viewport),this.texture=t.texture.clone(),this.texture.isRenderTargetTexture=!0;const e=Object.assign({},t.texture.image);return this.texture.source=new Fl(e),this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,t.depthTexture!==null&&(this.depthTexture=t.depthTexture.clone()),this.samples=t.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class ai extends Ou{constructor(t=1,e=1,n={}){super(t,e,n),this.isWebGLRenderTarget=!0}}class Bl extends ke{constructor(t=null,e=1,n=1,s=1){super(null),this.isDataArrayTexture=!0,this.image={data:t,width:e,height:n,depth:s},this.magFilter=Ie,this.minFilter=Ie,this.wrapR=an,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class Nu extends ke{constructor(t=null,e=1,n=1,s=1){super(null),this.isData3DTexture=!0,this.image={data:t,width:e,height:n,depth:s},this.magFilter=Ie,this.minFilter=Ie,this.wrapR=an,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class ji{constructor(t=0,e=0,n=0,s=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=n,this._w=s}static slerpFlat(t,e,n,s,r,a,o){let c=n[s+0],l=n[s+1],h=n[s+2],f=n[s+3];const u=r[a+0],m=r[a+1],g=r[a+2],x=r[a+3];if(o===0){t[e+0]=c,t[e+1]=l,t[e+2]=h,t[e+3]=f;return}if(o===1){t[e+0]=u,t[e+1]=m,t[e+2]=g,t[e+3]=x;return}if(f!==x||c!==u||l!==m||h!==g){let p=1-o;const d=c*u+l*m+h*g+f*x,M=d>=0?1:-1,v=1-d*d;if(v>Number.EPSILON){const y=Math.sqrt(v),A=Math.atan2(y,d*M);p=Math.sin(p*A)/y,o=Math.sin(o*A)/y}const _=o*M;if(c=c*p+u*_,l=l*p+m*_,h=h*p+g*_,f=f*p+x*_,p===1-o){const y=1/Math.sqrt(c*c+l*l+h*h+f*f);c*=y,l*=y,h*=y,f*=y}}t[e]=c,t[e+1]=l,t[e+2]=h,t[e+3]=f}static multiplyQuaternionsFlat(t,e,n,s,r,a){const o=n[s],c=n[s+1],l=n[s+2],h=n[s+3],f=r[a],u=r[a+1],m=r[a+2],g=r[a+3];return t[e]=o*g+h*f+c*m-l*u,t[e+1]=c*g+h*u+l*f-o*m,t[e+2]=l*g+h*m+o*u-c*f,t[e+3]=h*g-o*f-c*u-l*m,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,n,s){return this._x=t,this._y=e,this._z=n,this._w=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const n=t._x,s=t._y,r=t._z,a=t._order,o=Math.cos,c=Math.sin,l=o(n/2),h=o(s/2),f=o(r/2),u=c(n/2),m=c(s/2),g=c(r/2);switch(a){case"XYZ":this._x=u*h*f+l*m*g,this._y=l*m*f-u*h*g,this._z=l*h*g+u*m*f,this._w=l*h*f-u*m*g;break;case"YXZ":this._x=u*h*f+l*m*g,this._y=l*m*f-u*h*g,this._z=l*h*g-u*m*f,this._w=l*h*f+u*m*g;break;case"ZXY":this._x=u*h*f-l*m*g,this._y=l*m*f+u*h*g,this._z=l*h*g+u*m*f,this._w=l*h*f-u*m*g;break;case"ZYX":this._x=u*h*f-l*m*g,this._y=l*m*f+u*h*g,this._z=l*h*g-u*m*f,this._w=l*h*f+u*m*g;break;case"YZX":this._x=u*h*f+l*m*g,this._y=l*m*f+u*h*g,this._z=l*h*g-u*m*f,this._w=l*h*f-u*m*g;break;case"XZY":this._x=u*h*f-l*m*g,this._y=l*m*f-u*h*g,this._z=l*h*g+u*m*f,this._w=l*h*f+u*m*g;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+a)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const n=e/2,s=Math.sin(n);return this._x=t.x*s,this._y=t.y*s,this._z=t.z*s,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,n=e[0],s=e[4],r=e[8],a=e[1],o=e[5],c=e[9],l=e[2],h=e[6],f=e[10],u=n+o+f;if(u>0){const m=.5/Math.sqrt(u+1);this._w=.25/m,this._x=(h-c)*m,this._y=(r-l)*m,this._z=(a-s)*m}else if(n>o&&n>f){const m=2*Math.sqrt(1+n-o-f);this._w=(h-c)/m,this._x=.25*m,this._y=(s+a)/m,this._z=(r+l)/m}else if(o>f){const m=2*Math.sqrt(1+o-n-f);this._w=(r-l)/m,this._x=(s+a)/m,this._y=.25*m,this._z=(c+h)/m}else{const m=2*Math.sqrt(1+f-n-o);this._w=(a-s)/m,this._x=(r+l)/m,this._y=(c+h)/m,this._z=.25*m}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let n=t.dot(e)+1;return nMath.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=n):(this._x=0,this._y=-t.z,this._z=t.y,this._w=n)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=n),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(Se(this.dot(t),-1,1)))}rotateTowards(t,e){const n=this.angleTo(t);if(n===0)return this;const s=Math.min(1,e/n);return this.slerp(t,s),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const n=t._x,s=t._y,r=t._z,a=t._w,o=e._x,c=e._y,l=e._z,h=e._w;return this._x=n*h+a*o+s*l-r*c,this._y=s*h+a*c+r*o-n*l,this._z=r*h+a*l+n*c-s*o,this._w=a*h-n*o-s*c-r*l,this._onChangeCallback(),this}slerp(t,e){if(e===0)return this;if(e===1)return this.copy(t);const n=this._x,s=this._y,r=this._z,a=this._w;let o=a*t._w+n*t._x+s*t._y+r*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),o>=1)return this._w=a,this._x=n,this._y=s,this._z=r,this;const c=1-o*o;if(c<=Number.EPSILON){const m=1-e;return this._w=m*a+e*this._w,this._x=m*n+e*this._x,this._y=m*s+e*this._y,this._z=m*r+e*this._z,this.normalize(),this}const l=Math.sqrt(c),h=Math.atan2(l,o),f=Math.sin((1-e)*h)/l,u=Math.sin(e*h)/l;return this._w=a*f+this._w*u,this._x=n*f+this._x*u,this._y=s*f+this._y*u,this._z=r*f+this._z*u,this._onChangeCallback(),this}slerpQuaternions(t,e,n){return this.copy(t).slerp(e,n)}random(){const t=Math.random(),e=Math.sqrt(1-t),n=Math.sqrt(t),s=2*Math.PI*Math.random(),r=2*Math.PI*Math.random();return this.set(e*Math.cos(s),n*Math.sin(r),n*Math.cos(r),e*Math.sin(s))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class U{constructor(t=0,e=0,n=0){U.prototype.isVector3=!0,this.x=t,this.y=e,this.z=n}set(t,e,n){return n===void 0&&(n=this.z),this.x=t,this.y=e,this.z=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(uc.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(uc.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,n=this.y,s=this.z,r=t.elements;return this.x=r[0]*e+r[3]*n+r[6]*s,this.y=r[1]*e+r[4]*n+r[7]*s,this.z=r[2]*e+r[5]*n+r[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,n=this.y,s=this.z,r=t.elements,a=1/(r[3]*e+r[7]*n+r[11]*s+r[15]);return this.x=(r[0]*e+r[4]*n+r[8]*s+r[12])*a,this.y=(r[1]*e+r[5]*n+r[9]*s+r[13])*a,this.z=(r[2]*e+r[6]*n+r[10]*s+r[14])*a,this}applyQuaternion(t){const e=this.x,n=this.y,s=this.z,r=t.x,a=t.y,o=t.z,c=t.w,l=2*(a*s-o*n),h=2*(o*e-r*s),f=2*(r*n-a*e);return this.x=e+c*l+a*f-o*h,this.y=n+c*h+o*l-r*f,this.z=s+c*f+r*h-a*l,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,n=this.y,s=this.z,r=t.elements;return this.x=r[0]*e+r[4]*n+r[8]*s,this.y=r[1]*e+r[5]*n+r[9]*s,this.z=r[2]*e+r[6]*n+r[10]*s,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const n=t.x,s=t.y,r=t.z,a=e.x,o=e.y,c=e.z;return this.x=s*c-r*o,this.y=r*a-n*c,this.z=n*o-s*a,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const n=t.dot(this)/e;return this.copy(t).multiplyScalar(n)}projectOnPlane(t){return to.copy(this).projectOnVector(t),this.sub(to)}reflect(t){return this.sub(to.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(Se(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y,s=this.z-t.z;return e*e+n*n+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,n){const s=Math.sin(e)*t;return this.x=s*Math.sin(n),this.y=Math.cos(e)*t,this.z=s*Math.cos(n),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,n){return this.x=t*Math.sin(e),this.y=n,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),n=this.setFromMatrixColumn(t,1).length(),s=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=n,this.z=s,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=(Math.random()-.5)*2,e=Math.random()*Math.PI*2,n=Math.sqrt(1-t**2);return this.x=n*Math.cos(e),this.y=n*Math.sin(e),this.z=t,this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const to=new U,uc=new ji;class ye{constructor(t=new U(1/0,1/0,1/0),e=new U(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,n=t.length;ethis.max.x||t.ythis.max.y||t.zthis.max.z)}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return!(t.max.xthis.max.x||t.max.ythis.max.y||t.max.zthis.max.z)}intersectsSphere(t){return this.clampPoint(t.center,en),en.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,n;return t.normal.x>0?(e=t.normal.x*this.min.x,n=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,n=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,n+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,n+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,n+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,n+=t.normal.z*this.min.z),e<=-t.constant&&n>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(is),Ds.subVectors(this.max,is),ui.subVectors(t.a,is),fi.subVectors(t.b,is),di.subVectors(t.c,is),Ln.subVectors(fi,ui),Un.subVectors(di,fi),Zn.subVectors(ui,di);let e=[0,-Ln.z,Ln.y,0,-Un.z,Un.y,0,-Zn.z,Zn.y,Ln.z,0,-Ln.x,Un.z,0,-Un.x,Zn.z,0,-Zn.x,-Ln.y,Ln.x,0,-Un.y,Un.x,0,-Zn.y,Zn.x,0];return!eo(e,ui,fi,di,Ds)||(e=[1,0,0,0,1,0,0,0,1],!eo(e,ui,fi,di,Ds))?!1:(Is.crossVectors(Ln,Un),e=[Is.x,Is.y,Is.z],eo(e,ui,fi,di,Ds))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,en).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(en).length()*.5),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()?this:(xn[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),xn[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),xn[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),xn[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),xn[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),xn[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),xn[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),xn[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(xn),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const xn=[new U,new U,new U,new U,new U,new U,new U,new U],en=new U,Us=new ye,ui=new U,fi=new U,di=new U,Ln=new U,Un=new U,Zn=new U,is=new U,Ds=new U,Is=new U,Kn=new U;function eo(i,t,e,n,s){for(let r=0,a=i.length-3;r<=a;r+=3){Kn.fromArray(i,r);const o=s.x*Math.abs(Kn.x)+s.y*Math.abs(Kn.y)+s.z*Math.abs(Kn.z),c=t.dot(Kn),l=e.dot(Kn),h=n.dot(Kn);if(Math.max(-Math.max(c,l,h),Math.min(c,l,h))>o)return!1}return!0}const Fu=new ye,ss=new U,no=new U;class ws{constructor(t=new U,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const n=this.center;e!==void 0?n.copy(e):Fu.setFromPoints(t).getCenter(n);let s=0;for(let r=0,a=t.length;rthis.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;ss.subVectors(t,this.center);const e=ss.lengthSq();if(e>this.radius*this.radius){const n=Math.sqrt(e),s=(n-this.radius)*.5;this.center.addScaledVector(ss,s/n),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(no.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(ss.copy(t.center).add(no)),this.expandByPoint(ss.copy(t.center).sub(no))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}}const vn=new U,io=new U,Os=new U,Dn=new U,so=new U,Ns=new U,ro=new U;class la{constructor(t=new U,e=new U(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,vn)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const n=e.dot(this.direction);return n<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=vn.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(vn.copy(this.origin).addScaledVector(this.direction,e),vn.distanceToSquared(t))}distanceSqToSegment(t,e,n,s){io.copy(t).add(e).multiplyScalar(.5),Os.copy(e).sub(t).normalize(),Dn.copy(this.origin).sub(io);const r=t.distanceTo(e)*.5,a=-this.direction.dot(Os),o=Dn.dot(this.direction),c=-Dn.dot(Os),l=Dn.lengthSq(),h=Math.abs(1-a*a);let f,u,m,g;if(h>0)if(f=a*c-o,u=a*o-c,g=r*h,f>=0)if(u>=-g)if(u<=g){const x=1/h;f*=x,u*=x,m=f*(f+a*u+2*o)+u*(a*f+u+2*c)+l}else u=r,f=Math.max(0,-(a*u+o)),m=-f*f+u*(u+2*c)+l;else u=-r,f=Math.max(0,-(a*u+o)),m=-f*f+u*(u+2*c)+l;else u<=-g?(f=Math.max(0,-(-a*r+o)),u=f>0?-r:Math.min(Math.max(-r,-c),r),m=-f*f+u*(u+2*c)+l):u<=g?(f=0,u=Math.min(Math.max(-r,-c),r),m=u*(u+2*c)+l):(f=Math.max(0,-(a*r+o)),u=f>0?r:Math.min(Math.max(-r,-c),r),m=-f*f+u*(u+2*c)+l);else u=a>0?-r:r,f=Math.max(0,-(a*u+o)),m=-f*f+u*(u+2*c)+l;return n&&n.copy(this.origin).addScaledVector(this.direction,f),s&&s.copy(io).addScaledVector(Os,u),m}intersectSphere(t,e){vn.subVectors(t.center,this.origin);const n=vn.dot(this.direction),s=vn.dot(vn)-n*n,r=t.radius*t.radius;if(s>r)return null;const a=Math.sqrt(r-s),o=n-a,c=n+a;return c<0?null:o<0?this.at(c,e):this.at(o,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?0:null;const n=-(this.origin.dot(t.normal)+t.constant)/e;return n>=0?n:null}intersectPlane(t,e){const n=this.distanceToPlane(t);return n===null?null:this.at(n,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let n,s,r,a,o,c;const l=1/this.direction.x,h=1/this.direction.y,f=1/this.direction.z,u=this.origin;return l>=0?(n=(t.min.x-u.x)*l,s=(t.max.x-u.x)*l):(n=(t.max.x-u.x)*l,s=(t.min.x-u.x)*l),h>=0?(r=(t.min.y-u.y)*h,a=(t.max.y-u.y)*h):(r=(t.max.y-u.y)*h,a=(t.min.y-u.y)*h),n>a||r>s||((r>n||isNaN(n))&&(n=r),(a=0?(o=(t.min.z-u.z)*f,c=(t.max.z-u.z)*f):(o=(t.max.z-u.z)*f,c=(t.min.z-u.z)*f),n>c||o>s)||((o>n||n!==n)&&(n=o),(c=0?n:s,e)}intersectsBox(t){return this.intersectBox(t,vn)!==null}intersectTriangle(t,e,n,s,r){so.subVectors(e,t),Ns.subVectors(n,t),ro.crossVectors(so,Ns);let a=this.direction.dot(ro),o;if(a>0){if(s)return null;o=1}else if(a<0)o=-1,a=-a;else return null;Dn.subVectors(this.origin,t);const c=o*this.direction.dot(Ns.crossVectors(Dn,Ns));if(c<0)return null;const l=o*this.direction.dot(so.cross(Dn));if(l<0||c+l>a)return null;const h=-o*Dn.dot(ro);return h<0?null:this.at(h/a,r)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class Jt{constructor(t,e,n,s,r,a,o,c,l,h,f,u,m,g,x,p){Jt.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,n,s,r,a,o,c,l,h,f,u,m,g,x,p)}set(t,e,n,s,r,a,o,c,l,h,f,u,m,g,x,p){const d=this.elements;return d[0]=t,d[4]=e,d[8]=n,d[12]=s,d[1]=r,d[5]=a,d[9]=o,d[13]=c,d[2]=l,d[6]=h,d[10]=f,d[14]=u,d[3]=m,d[7]=g,d[11]=x,d[15]=p,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new Jt().fromArray(this.elements)}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15],this}copyPosition(t){const e=this.elements,n=t.elements;return e[12]=n[12],e[13]=n[13],e[14]=n[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,n){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(t,e,n){return this.set(t.x,e.x,n.x,0,t.y,e.y,n.y,0,t.z,e.z,n.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,n=t.elements,s=1/pi.setFromMatrixColumn(t,0).length(),r=1/pi.setFromMatrixColumn(t,1).length(),a=1/pi.setFromMatrixColumn(t,2).length();return e[0]=n[0]*s,e[1]=n[1]*s,e[2]=n[2]*s,e[3]=0,e[4]=n[4]*r,e[5]=n[5]*r,e[6]=n[6]*r,e[7]=0,e[8]=n[8]*a,e[9]=n[9]*a,e[10]=n[10]*a,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,n=t.x,s=t.y,r=t.z,a=Math.cos(n),o=Math.sin(n),c=Math.cos(s),l=Math.sin(s),h=Math.cos(r),f=Math.sin(r);if(t.order==="XYZ"){const u=a*h,m=a*f,g=o*h,x=o*f;e[0]=c*h,e[4]=-c*f,e[8]=l,e[1]=m+g*l,e[5]=u-x*l,e[9]=-o*c,e[2]=x-u*l,e[6]=g+m*l,e[10]=a*c}else if(t.order==="YXZ"){const u=c*h,m=c*f,g=l*h,x=l*f;e[0]=u+x*o,e[4]=g*o-m,e[8]=a*l,e[1]=a*f,e[5]=a*h,e[9]=-o,e[2]=m*o-g,e[6]=x+u*o,e[10]=a*c}else if(t.order==="ZXY"){const u=c*h,m=c*f,g=l*h,x=l*f;e[0]=u-x*o,e[4]=-a*f,e[8]=g+m*o,e[1]=m+g*o,e[5]=a*h,e[9]=x-u*o,e[2]=-a*l,e[6]=o,e[10]=a*c}else if(t.order==="ZYX"){const u=a*h,m=a*f,g=o*h,x=o*f;e[0]=c*h,e[4]=g*l-m,e[8]=u*l+x,e[1]=c*f,e[5]=x*l+u,e[9]=m*l-g,e[2]=-l,e[6]=o*c,e[10]=a*c}else if(t.order==="YZX"){const u=a*c,m=a*l,g=o*c,x=o*l;e[0]=c*h,e[4]=x-u*f,e[8]=g*f+m,e[1]=f,e[5]=a*h,e[9]=-o*h,e[2]=-l*h,e[6]=m*f+g,e[10]=u-x*f}else if(t.order==="XZY"){const u=a*c,m=a*l,g=o*c,x=o*l;e[0]=c*h,e[4]=-f,e[8]=l*h,e[1]=u*f+x,e[5]=a*h,e[9]=m*f-g,e[2]=g*f-m,e[6]=o*h,e[10]=x*f+u}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(Bu,t,zu)}lookAt(t,e,n){const s=this.elements;return ze.subVectors(t,e),ze.lengthSq()===0&&(ze.z=1),ze.normalize(),In.crossVectors(n,ze),In.lengthSq()===0&&(Math.abs(n.z)===1?ze.x+=1e-4:ze.z+=1e-4,ze.normalize(),In.crossVectors(n,ze)),In.normalize(),Fs.crossVectors(ze,In),s[0]=In.x,s[4]=Fs.x,s[8]=ze.x,s[1]=In.y,s[5]=Fs.y,s[9]=ze.y,s[2]=In.z,s[6]=Fs.z,s[10]=ze.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,s=e.elements,r=this.elements,a=n[0],o=n[4],c=n[8],l=n[12],h=n[1],f=n[5],u=n[9],m=n[13],g=n[2],x=n[6],p=n[10],d=n[14],M=n[3],v=n[7],_=n[11],y=n[15],A=s[0],T=s[4],P=s[8],E=s[12],S=s[1],D=s[5],I=s[9],B=s[13],R=s[2],O=s[6],F=s[10],Y=s[14],q=s[3],Z=s[7],K=s[11],et=s[15];return r[0]=a*A+o*S+c*R+l*q,r[4]=a*T+o*D+c*O+l*Z,r[8]=a*P+o*I+c*F+l*K,r[12]=a*E+o*B+c*Y+l*et,r[1]=h*A+f*S+u*R+m*q,r[5]=h*T+f*D+u*O+m*Z,r[9]=h*P+f*I+u*F+m*K,r[13]=h*E+f*B+u*Y+m*et,r[2]=g*A+x*S+p*R+d*q,r[6]=g*T+x*D+p*O+d*Z,r[10]=g*P+x*I+p*F+d*K,r[14]=g*E+x*B+p*Y+d*et,r[3]=M*A+v*S+_*R+y*q,r[7]=M*T+v*D+_*O+y*Z,r[11]=M*P+v*I+_*F+y*K,r[15]=M*E+v*B+_*Y+y*et,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[4],s=t[8],r=t[12],a=t[1],o=t[5],c=t[9],l=t[13],h=t[2],f=t[6],u=t[10],m=t[14],g=t[3],x=t[7],p=t[11],d=t[15];return g*(+r*c*f-s*l*f-r*o*u+n*l*u+s*o*m-n*c*m)+x*(+e*c*m-e*l*u+r*a*u-s*a*m+s*l*h-r*c*h)+p*(+e*l*f-e*o*m-r*a*f+n*a*m+r*o*h-n*l*h)+d*(-s*o*h-e*c*f+e*o*u+s*a*f-n*a*u+n*c*h)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,n){const s=this.elements;return t.isVector3?(s[12]=t.x,s[13]=t.y,s[14]=t.z):(s[12]=t,s[13]=e,s[14]=n),this}invert(){const t=this.elements,e=t[0],n=t[1],s=t[2],r=t[3],a=t[4],o=t[5],c=t[6],l=t[7],h=t[8],f=t[9],u=t[10],m=t[11],g=t[12],x=t[13],p=t[14],d=t[15],M=f*p*l-x*u*l+x*c*m-o*p*m-f*c*d+o*u*d,v=g*u*l-h*p*l-g*c*m+a*p*m+h*c*d-a*u*d,_=h*x*l-g*f*l+g*o*m-a*x*m-h*o*d+a*f*d,y=g*f*c-h*x*c-g*o*u+a*x*u+h*o*p-a*f*p,A=e*M+n*v+s*_+r*y;if(A===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const T=1/A;return t[0]=M*T,t[1]=(x*u*r-f*p*r-x*s*m+n*p*m+f*s*d-n*u*d)*T,t[2]=(o*p*r-x*c*r+x*s*l-n*p*l-o*s*d+n*c*d)*T,t[3]=(f*c*r-o*u*r-f*s*l+n*u*l+o*s*m-n*c*m)*T,t[4]=v*T,t[5]=(h*p*r-g*u*r+g*s*m-e*p*m-h*s*d+e*u*d)*T,t[6]=(g*c*r-a*p*r-g*s*l+e*p*l+a*s*d-e*c*d)*T,t[7]=(a*u*r-h*c*r+h*s*l-e*u*l-a*s*m+e*c*m)*T,t[8]=_*T,t[9]=(g*f*r-h*x*r-g*n*m+e*x*m+h*n*d-e*f*d)*T,t[10]=(a*x*r-g*o*r+g*n*l-e*x*l-a*n*d+e*o*d)*T,t[11]=(h*o*r-a*f*r-h*n*l+e*f*l+a*n*m-e*o*m)*T,t[12]=y*T,t[13]=(h*x*s-g*f*s+g*n*u-e*x*u-h*n*p+e*f*p)*T,t[14]=(g*o*s-a*x*s-g*n*c+e*x*c+a*n*p-e*o*p)*T,t[15]=(a*f*s-h*o*s+h*n*c-e*f*c-a*n*u+e*o*u)*T,this}scale(t){const e=this.elements,n=t.x,s=t.y,r=t.z;return e[0]*=n,e[4]*=s,e[8]*=r,e[1]*=n,e[5]*=s,e[9]*=r,e[2]*=n,e[6]*=s,e[10]*=r,e[3]*=n,e[7]*=s,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],n=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],s=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,n,s))}makeTranslation(t,e,n){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),n=Math.sin(t);return this.set(1,0,0,0,0,e,-n,0,0,n,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,0,n,0,0,1,0,0,-n,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,0,n,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const n=Math.cos(e),s=Math.sin(e),r=1-n,a=t.x,o=t.y,c=t.z,l=r*a,h=r*o;return this.set(l*a+n,l*o-s*c,l*c+s*o,0,l*o+s*c,h*o+n,h*c-s*a,0,l*c-s*o,h*c+s*a,r*c*c+n,0,0,0,0,1),this}makeScale(t,e,n){return this.set(t,0,0,0,0,e,0,0,0,0,n,0,0,0,0,1),this}makeShear(t,e,n,s,r,a){return this.set(1,n,r,0,t,1,a,0,e,s,1,0,0,0,0,1),this}compose(t,e,n){const s=this.elements,r=e._x,a=e._y,o=e._z,c=e._w,l=r+r,h=a+a,f=o+o,u=r*l,m=r*h,g=r*f,x=a*h,p=a*f,d=o*f,M=c*l,v=c*h,_=c*f,y=n.x,A=n.y,T=n.z;return s[0]=(1-(x+d))*y,s[1]=(m+_)*y,s[2]=(g-v)*y,s[3]=0,s[4]=(m-_)*A,s[5]=(1-(u+d))*A,s[6]=(p+M)*A,s[7]=0,s[8]=(g+v)*T,s[9]=(p-M)*T,s[10]=(1-(u+x))*T,s[11]=0,s[12]=t.x,s[13]=t.y,s[14]=t.z,s[15]=1,this}decompose(t,e,n){const s=this.elements;let r=pi.set(s[0],s[1],s[2]).length();const a=pi.set(s[4],s[5],s[6]).length(),o=pi.set(s[8],s[9],s[10]).length();this.determinant()<0&&(r=-r),t.x=s[12],t.y=s[13],t.z=s[14],nn.copy(this);const l=1/r,h=1/a,f=1/o;return nn.elements[0]*=l,nn.elements[1]*=l,nn.elements[2]*=l,nn.elements[4]*=h,nn.elements[5]*=h,nn.elements[6]*=h,nn.elements[8]*=f,nn.elements[9]*=f,nn.elements[10]*=f,e.setFromRotationMatrix(nn),n.x=r,n.y=a,n.z=o,this}makePerspective(t,e,n,s,r,a,o=bn){const c=this.elements,l=2*r/(e-t),h=2*r/(n-s),f=(e+t)/(e-t),u=(n+s)/(n-s);let m,g;if(o===bn)m=-(a+r)/(a-r),g=-2*a*r/(a-r);else if(o===br)m=-a/(a-r),g=-a*r/(a-r);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);return c[0]=l,c[4]=0,c[8]=f,c[12]=0,c[1]=0,c[5]=h,c[9]=u,c[13]=0,c[2]=0,c[6]=0,c[10]=m,c[14]=g,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(t,e,n,s,r,a,o=bn){const c=this.elements,l=1/(e-t),h=1/(n-s),f=1/(a-r),u=(e+t)*l,m=(n+s)*h;let g,x;if(o===bn)g=(a+r)*f,x=-2*f;else if(o===br)g=r*f,x=-1*f;else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return c[0]=2*l,c[4]=0,c[8]=0,c[12]=-u,c[1]=0,c[5]=2*h,c[9]=0,c[13]=-m,c[2]=0,c[6]=0,c[10]=x,c[14]=-g,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(t){const e=this.elements,n=t.elements;for(let s=0;s<16;s++)if(e[s]!==n[s])return!1;return!0}fromArray(t,e=0){for(let n=0;n<16;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t[e+9]=n[9],t[e+10]=n[10],t[e+11]=n[11],t[e+12]=n[12],t[e+13]=n[13],t[e+14]=n[14],t[e+15]=n[15],t}}const pi=new U,nn=new Jt,Bu=new U(0,0,0),zu=new U(1,1,1),In=new U,Fs=new U,ze=new U,fc=new Jt,dc=new ji;class Nr{constructor(t=0,e=0,n=0,s=Nr.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=n,this._order=s}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,n,s=this._order){return this._x=t,this._y=e,this._z=n,this._order=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,n=!0){const s=t.elements,r=s[0],a=s[4],o=s[8],c=s[1],l=s[5],h=s[9],f=s[2],u=s[6],m=s[10];switch(e){case"XYZ":this._y=Math.asin(Se(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,m),this._z=Math.atan2(-a,r)):(this._x=Math.atan2(u,l),this._z=0);break;case"YXZ":this._x=Math.asin(-Se(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(o,m),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-f,r),this._z=0);break;case"ZXY":this._x=Math.asin(Se(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-f,m),this._z=Math.atan2(-a,l)):(this._y=0,this._z=Math.atan2(c,r));break;case"ZYX":this._y=Math.asin(-Se(f,-1,1)),Math.abs(f)<.9999999?(this._x=Math.atan2(u,m),this._z=Math.atan2(c,r)):(this._x=0,this._z=Math.atan2(-a,l));break;case"YZX":this._z=Math.asin(Se(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-f,r)):(this._x=0,this._y=Math.atan2(o,m));break;case"XZY":this._z=Math.asin(-Se(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(u,l),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-h,m),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,n===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,n){return fc.makeRotationFromQuaternion(t),this.setFromRotationMatrix(fc,e,n)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return dc.setFromEuler(this),this.setFromQuaternion(dc,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Nr.DEFAULT_ORDER="XYZ";class ha{constructor(){this.mask=1}set(t){this.mask=(1<>>0}enable(t){this.mask|=1<1){for(let e=0;e1){for(let n=0;n0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(s.matrixAutoUpdate=!1),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(s.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(s.type="BatchedMesh",s.perObjectFrustumCulled=this.perObjectFrustumCulled,s.sortObjects=this.sortObjects,s.drawRanges=this._drawRanges,s.reservedRanges=this._reservedRanges,s.visibility=this._visibility,s.active=this._active,s.bounds=this._bounds.map(o=>({boxInitialized:o.boxInitialized,boxMin:o.box.min.toArray(),boxMax:o.box.max.toArray(),sphereInitialized:o.sphereInitialized,sphereRadius:o.sphere.radius,sphereCenter:o.sphere.center.toArray()})),s.maxGeometryCount=this._maxGeometryCount,s.maxVertexCount=this._maxVertexCount,s.maxIndexCount=this._maxIndexCount,s.geometryInitialized=this._geometryInitialized,s.geometryCount=this._geometryCount,s.matricesTexture=this._matricesTexture.toJSON(t),this.boundingSphere!==null&&(s.boundingSphere={center:s.boundingSphere.center.toArray(),radius:s.boundingSphere.radius}),this.boundingBox!==null&&(s.boundingBox={min:s.boundingBox.min.toArray(),max:s.boundingBox.max.toArray()}));function r(o,c){return o[c.uuid]===void 0&&(o[c.uuid]=c.toJSON(t)),c.uuid}if(this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(s.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=r(t.geometries,this.geometry);const o=this.geometry.parameters;if(o!==void 0&&o.shapes!==void 0){const c=o.shapes;if(Array.isArray(c))for(let l=0,h=c.length;l0){s.children=[];for(let o=0;o0){s.animations=[];for(let o=0;o0&&(n.geometries=o),c.length>0&&(n.materials=c),l.length>0&&(n.textures=l),h.length>0&&(n.images=h),f.length>0&&(n.shapes=f),u.length>0&&(n.skeletons=u),m.length>0&&(n.animations=m),g.length>0&&(n.nodes=g)}return n.object=s,n;function a(o){const c=[];for(const l in o){const h=o[l];delete h.metadata,c.push(h)}return c}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let n=0;n0?s.multiplyScalar(1/Math.sqrt(r)):s.set(0,0,0)}static getBarycoord(t,e,n,s,r){sn.subVectors(s,e),Mn.subVectors(n,e),oo.subVectors(t,e);const a=sn.dot(sn),o=sn.dot(Mn),c=sn.dot(oo),l=Mn.dot(Mn),h=Mn.dot(oo),f=a*l-o*o;if(f===0)return r.set(0,0,0),null;const u=1/f,m=(l*c-o*h)*u,g=(a*h-o*c)*u;return r.set(1-m-g,g,m)}static containsPoint(t,e,n,s){return this.getBarycoord(t,e,n,s,Sn)===null?!1:Sn.x>=0&&Sn.y>=0&&Sn.x+Sn.y<=1}static getUV(t,e,n,s,r,a,o,c){return zs===!1&&(console.warn("THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation()."),zs=!0),this.getInterpolation(t,e,n,s,r,a,o,c)}static getInterpolation(t,e,n,s,r,a,o,c){return this.getBarycoord(t,e,n,s,Sn)===null?(c.x=0,c.y=0,"z"in c&&(c.z=0),"w"in c&&(c.w=0),null):(c.setScalar(0),c.addScaledVector(r,Sn.x),c.addScaledVector(a,Sn.y),c.addScaledVector(o,Sn.z),c)}static isFrontFacing(t,e,n,s){return sn.subVectors(n,e),Mn.subVectors(t,e),sn.cross(Mn).dot(s)<0}set(t,e,n){return this.a.copy(t),this.b.copy(e),this.c.copy(n),this}setFromPointsAndIndices(t,e,n,s){return this.a.copy(t[e]),this.b.copy(t[n]),this.c.copy(t[s]),this}setFromAttributeAndIndices(t,e,n,s){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,n),this.c.fromBufferAttribute(t,s),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return sn.subVectors(this.c,this.b),Mn.subVectors(this.a,this.b),sn.cross(Mn).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return we.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return we.getBarycoord(t,this.a,this.b,this.c,e)}getUV(t,e,n,s,r){return zs===!1&&(console.warn("THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation()."),zs=!0),we.getInterpolation(t,this.a,this.b,this.c,e,n,s,r)}getInterpolation(t,e,n,s,r){return we.getInterpolation(t,this.a,this.b,this.c,e,n,s,r)}containsPoint(t){return we.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return we.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const n=this.a,s=this.b,r=this.c;let a,o;_i.subVectors(s,n),gi.subVectors(r,n),ao.subVectors(t,n);const c=_i.dot(ao),l=gi.dot(ao);if(c<=0&&l<=0)return e.copy(n);co.subVectors(t,s);const h=_i.dot(co),f=gi.dot(co);if(h>=0&&f<=h)return e.copy(s);const u=c*f-h*l;if(u<=0&&c>=0&&h<=0)return a=c/(c-h),e.copy(n).addScaledVector(_i,a);lo.subVectors(t,r);const m=_i.dot(lo),g=gi.dot(lo);if(g>=0&&m<=g)return e.copy(r);const x=m*l-c*g;if(x<=0&&l>=0&&g<=0)return o=l/(l-g),e.copy(n).addScaledVector(gi,o);const p=h*g-m*f;if(p<=0&&f-h>=0&&m-g>=0)return xc.subVectors(r,s),o=(f-h)/(f-h+(m-g)),e.copy(s).addScaledVector(xc,o);const d=1/(p+x+u);return a=x*d,o=u*d,e.copy(n).addScaledVector(_i,a).addScaledVector(gi,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const zl={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},On={h:0,s:0,l:0},Hs={h:0,s:0,l:0};function ho(i,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?i+(t-i)*6*e:e<1/2?t:e<2/3?i+(t-i)*6*(2/3-e):i}class qt{constructor(t,e,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,n)}set(t,e,n){if(e===void 0&&n===void 0){const s=t;s&&s.isColor?this.copy(s):typeof s=="number"?this.setHex(s):typeof s=="string"&&this.setStyle(s)}else this.setRGB(t,e,n);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=Me){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,jt.toWorkingColorSpace(this,e),this}setRGB(t,e,n,s=jt.workingColorSpace){return this.r=t,this.g=e,this.b=n,jt.toWorkingColorSpace(this,s),this}setHSL(t,e,n,s=jt.workingColorSpace){if(t=ca(t,1),e=Se(e,0,1),n=Se(n,0,1),e===0)this.r=this.g=this.b=n;else{const r=n<=.5?n*(1+e):n+e-n*e,a=2*n-r;this.r=ho(a,r,t+1/3),this.g=ho(a,r,t),this.b=ho(a,r,t-1/3)}return jt.toWorkingColorSpace(this,s),this}setStyle(t,e=Me){function n(r){r!==void 0&&parseFloat(r)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let s;if(s=/^(\w+)\(([^\)]*)\)/.exec(t)){let r;const a=s[1],o=s[2];switch(a){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,e);if(r=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,e);break;case"hsl":case"hsla":if(r=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(s=/^\#([A-Fa-f\d]+)$/.exec(t)){const r=s[1],a=r.length;if(a===3)return this.setRGB(parseInt(r.charAt(0),16)/15,parseInt(r.charAt(1),16)/15,parseInt(r.charAt(2),16)/15,e);if(a===6)return this.setHex(parseInt(r,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=Me){const n=zl[t.toLowerCase()];return n!==void 0?this.setHex(n,e):console.warn("THREE.Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=Wi(t.r),this.g=Wi(t.g),this.b=Wi(t.b),this}copyLinearToSRGB(t){return this.r=Jr(t.r),this.g=Jr(t.g),this.b=Jr(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=Me){return jt.fromWorkingColorSpace(be.copy(this),t),Math.round(Se(be.r*255,0,255))*65536+Math.round(Se(be.g*255,0,255))*256+Math.round(Se(be.b*255,0,255))}getHexString(t=Me){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=jt.workingColorSpace){jt.fromWorkingColorSpace(be.copy(this),e);const n=be.r,s=be.g,r=be.b,a=Math.max(n,s,r),o=Math.min(n,s,r);let c,l;const h=(o+a)/2;if(o===a)c=0,l=0;else{const f=a-o;switch(l=h<=.5?f/(a+o):f/(2-a-o),a){case n:c=(s-r)/f+(s0!=t>0&&this.version++,this._alphaTest=t}onBuild(){}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(t!==void 0)for(const e in t){const n=t[e];if(n===void 0){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}const s=this[e];if(s===void 0){console.warn(`THREE.Material: '${e}' is not a property of THREE.${this.type}.`);continue}s&&s.isColor?s.set(n):s&&s.isVector3&&n&&n.isVector3?s.copy(n):this[e]=n}}toJSON(t){const e=t===void 0||typeof t=="string";e&&(t={textures:{},images:{}});const n={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),this.roughness!==void 0&&(n.roughness=this.roughness),this.metalness!==void 0&&(n.metalness=this.metalness),this.sheen!==void 0&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),this.emissiveIntensity&&this.emissiveIntensity!==1&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(n.shininess=this.shininess),this.clearcoat!==void 0&&(n.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.iridescence!==void 0&&(n.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(n.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),this.anisotropy!==void 0&&(n.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(t).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(t).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(t).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(t).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(t).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(t).uuid,this.combine!==void 0&&(n.combine=this.combine)),this.envMapIntensity!==void 0&&(n.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(n.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(t).uuid),this.transmission!==void 0&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(t).uuid),this.thickness!==void 0&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(t).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(n.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(n.size=this.size),this.shadowSide!==null&&(n.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(n.sizeAttenuation=this.sizeAttenuation),this.blending!==ki&&(n.blending=this.blending),this.side!==_n&&(n.side=this.side),this.vertexColors===!0&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),this.transparent===!0&&(n.transparent=!0),this.blendSrc!==zo&&(n.blendSrc=this.blendSrc),this.blendDst!==Ho&&(n.blendDst=this.blendDst),this.blendEquation!==ei&&(n.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(n.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(n.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(n.blendAlpha=this.blendAlpha),this.depthFunc!==Sr&&(n.depthFunc=this.depthFunc),this.depthTest===!1&&(n.depthTest=this.depthTest),this.depthWrite===!1&&(n.depthWrite=this.depthWrite),this.colorWrite===!1&&(n.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(n.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==sc&&(n.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(n.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==li&&(n.stencilFail=this.stencilFail),this.stencilZFail!==li&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==li&&(n.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(n.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(n.rotation=this.rotation),this.polygonOffset===!0&&(n.polygonOffset=!0),this.polygonOffsetFactor!==0&&(n.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(n.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(n.linewidth=this.linewidth),this.dashSize!==void 0&&(n.dashSize=this.dashSize),this.gapSize!==void 0&&(n.gapSize=this.gapSize),this.scale!==void 0&&(n.scale=this.scale),this.dithering===!0&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),this.alphaHash===!0&&(n.alphaHash=!0),this.alphaToCoverage===!0&&(n.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(n.premultipliedAlpha=!0),this.forceSinglePass===!0&&(n.forceSinglePass=!0),this.wireframe===!0&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(n.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(n.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(n.flatShading=!0),this.visible===!1&&(n.visible=!1),this.toneMapped===!1&&(n.toneMapped=!1),this.fog===!1&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData);function s(r){const a=[];for(const o in r){const c=r[o];delete c.metadata,a.push(c)}return a}if(e){const r=s(t.textures),a=s(t.images);r.length>0&&(n.textures=r),a.length>0&&(n.images=a)}return n}clone(){return new this.constructor().copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let n=null;if(e!==null){const s=e.length;n=new Array(s);for(let r=0;r!==s;++r)n[r]=e[r].clone()}return this.clippingPlanes=n,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){t===!0&&this.version++}}class Hl extends Fr{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new qt(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=Tl,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const fe=new U,Vs=new kt;class tn{constructor(t,e,n=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=n,this.usage=rc,this._updateRange={offset:0,count:-1},this.updateRanges=[],this.gpuType=Hn,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}get updateRange(){return console.warn("THREE.BufferAttribute: updateRange() is deprecated and will be removed in r169. Use addUpdateRange() instead."),this._updateRange}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,n){t*=this.itemSize,n*=e.itemSize;for(let s=0,r=this.itemSize;s0&&(t.userData=this.userData),this.parameters!==void 0){const c=this.parameters;for(const l in c)c[l]!==void 0&&(t[l]=c[l]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const n=this.attributes;for(const c in n){const l=n[c];t.data.attributes[c]=l.toJSON(t.data)}const s={};let r=!1;for(const c in this.morphAttributes){const l=this.morphAttributes[c],h=[];for(let f=0,u=l.length;f0&&(s[c]=h,r=!0)}r&&(t.data.morphAttributes=s,t.data.morphTargetsRelative=this.morphTargetsRelative);const a=this.groups;a.length>0&&(t.data.groups=JSON.parse(JSON.stringify(a)));const o=this.boundingSphere;return o!==null&&(t.data.boundingSphere={center:o.center.toArray(),radius:o.radius}),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const n=t.index;n!==null&&this.setIndex(n.clone(e));const s=t.attributes;for(const l in s){const h=s[l];this.setAttribute(l,h.clone(e))}const r=t.morphAttributes;for(const l in r){const h=[],f=r[l];for(let u=0,m=f.length;u0){const s=e[n[0]];if(s!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let r=0,a=s.length;r(t.far-t.near)**2))&&(vc.copy(r).invert(),$n.copy(t.ray).applyMatrix4(vc),!(n.boundingBox!==null&&$n.intersectsBox(n.boundingBox)===!1)&&this._computeIntersections(t,e,$n)))}_computeIntersections(t,e,n){let s;const r=this.geometry,a=this.material,o=r.index,c=r.attributes.position,l=r.attributes.uv,h=r.attributes.uv1,f=r.attributes.normal,u=r.groups,m=r.drawRange;if(o!==null)if(Array.isArray(a))for(let g=0,x=u.length;ge.far?null:{distance:l,point:Zs.clone(),object:i}}function Ks(i,t,e,n,s,r,a,o,c,l){i.getVertexPosition(o,vi),i.getVertexPosition(c,Ei),i.getVertexPosition(l,Mi);const h=qu(i,t,e,n,vi,Ei,Mi,qs);if(h){s&&(Ws.fromBufferAttribute(s,o),Xs.fromBufferAttribute(s,c),Ys.fromBufferAttribute(s,l),h.uv=we.getInterpolation(qs,vi,Ei,Mi,Ws,Xs,Ys,new kt)),r&&(Ws.fromBufferAttribute(r,o),Xs.fromBufferAttribute(r,c),Ys.fromBufferAttribute(r,l),h.uv1=we.getInterpolation(qs,vi,Ei,Mi,Ws,Xs,Ys,new kt),h.uv2=h.uv1),a&&(Mc.fromBufferAttribute(a,o),Sc.fromBufferAttribute(a,c),yc.fromBufferAttribute(a,l),h.normal=we.getInterpolation(qs,vi,Ei,Mi,Mc,Sc,yc,new U),h.normal.dot(n.direction)>0&&h.normal.multiplyScalar(-1));const f={a:o,b:c,c:l,normal:new U,materialIndex:0};we.getNormal(vi,Ei,Mi,f.normal),h.face=f}return h}class Ji extends Rn{constructor(t=1,e=1,n=1,s=1,r=1,a=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:n,widthSegments:s,heightSegments:r,depthSegments:a};const o=this;s=Math.floor(s),r=Math.floor(r),a=Math.floor(a);const c=[],l=[],h=[],f=[];let u=0,m=0;g("z","y","x",-1,-1,n,e,t,a,r,0),g("z","y","x",1,-1,n,e,-t,a,r,1),g("x","z","y",1,1,t,n,e,s,a,2),g("x","z","y",1,-1,t,n,-e,s,a,3),g("x","y","z",1,-1,t,e,n,s,r,4),g("x","y","z",-1,-1,t,e,-n,s,r,5),this.setIndex(c),this.setAttribute("position",new oi(l,3)),this.setAttribute("normal",new oi(h,3)),this.setAttribute("uv",new oi(f,2));function g(x,p,d,M,v,_,y,A,T,P,E){const S=_/T,D=y/P,I=_/2,B=y/2,R=A/2,O=T+1,F=P+1;let Y=0,q=0;const Z=new U;for(let K=0;K0?1:-1,h.push(Z.x,Z.y,Z.z),f.push(nt/T),f.push(1-K/P),Y+=1}}for(let K=0;K0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;const n={};for(const s in this.extensions)this.extensions[s]===!0&&(n[s]=!0);return Object.keys(n).length>0&&(e.extensions=n),e}}class Wl extends Ce{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new Jt,this.projectionMatrix=new Jt,this.projectionMatrixInverse=new Jt,this.coordinateSystem=bn}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this.coordinateSystem=t.coordinateSystem,this}getWorldDirection(t){return super.getWorldDirection(t).negate()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return new this.constructor().copy(this)}}class Ze extends Wl{constructor(t=50,e=1,n=.1,s=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=n,this.far=s,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=t.view===null?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=As*2*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(xs*.5*this.fov);return .5*this.getFilmHeight()/t}getEffectiveFOV(){return As*2*Math.atan(Math.tan(xs*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}setViewOffset(t,e,n,s,r,a){this.aspect=t/e,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=n,this.view.offsetY=s,this.view.width=r,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(xs*.5*this.fov)/this.zoom,n=2*e,s=this.aspect*n,r=-.5*s;const a=this.view;if(this.view!==null&&this.view.enabled){const c=a.fullWidth,l=a.fullHeight;r+=a.offsetX*s/c,e-=a.offsetY*n/l,s*=a.width/c,n*=a.height/l}const o=this.filmOffset;o!==0&&(r+=t*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+s,e,e-n,t,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,this.view!==null&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}const Si=-90,yi=1;class Ju extends Ce{constructor(t,e,n){super(),this.type="CubeCamera",this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;const s=new Ze(Si,yi,t,e);s.layers=this.layers,this.add(s);const r=new Ze(Si,yi,t,e);r.layers=this.layers,this.add(r);const a=new Ze(Si,yi,t,e);a.layers=this.layers,this.add(a);const o=new Ze(Si,yi,t,e);o.layers=this.layers,this.add(o);const c=new Ze(Si,yi,t,e);c.layers=this.layers,this.add(c);const l=new Ze(Si,yi,t,e);l.layers=this.layers,this.add(l)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[n,s,r,a,o,c]=e;for(const l of e)this.remove(l);if(t===bn)n.up.set(0,1,0),n.lookAt(1,0,0),s.up.set(0,1,0),s.lookAt(-1,0,0),r.up.set(0,0,-1),r.lookAt(0,1,0),a.up.set(0,0,1),a.lookAt(0,-1,0),o.up.set(0,1,0),o.lookAt(0,0,1),c.up.set(0,1,0),c.lookAt(0,0,-1);else if(t===br)n.up.set(0,-1,0),n.lookAt(-1,0,0),s.up.set(0,-1,0),s.lookAt(1,0,0),r.up.set(0,0,1),r.lookAt(0,1,0),a.up.set(0,0,-1),a.lookAt(0,-1,0),o.up.set(0,-1,0),o.lookAt(0,0,1),c.up.set(0,-1,0),c.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);for(const l of e)this.add(l),l.updateMatrixWorld()}update(t,e){this.parent===null&&this.updateMatrixWorld();const{renderTarget:n,activeMipmapLevel:s}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[r,a,o,c,l,h]=this.children,f=t.getRenderTarget(),u=t.getActiveCubeFace(),m=t.getActiveMipmapLevel(),g=t.xr.enabled;t.xr.enabled=!1;const x=n.texture.generateMipmaps;n.texture.generateMipmaps=!1,t.setRenderTarget(n,0,s),t.render(e,r),t.setRenderTarget(n,1,s),t.render(e,a),t.setRenderTarget(n,2,s),t.render(e,o),t.setRenderTarget(n,3,s),t.render(e,c),t.setRenderTarget(n,4,s),t.render(e,l),n.texture.generateMipmaps=x,t.setRenderTarget(n,5,s),t.render(e,h),t.setRenderTarget(f,u,m),t.xr.enabled=g,n.texture.needsPMREMUpdate=!0}}class Xl extends ke{constructor(t,e,n,s,r,a,o,c,l,h){t=t!==void 0?t:[],e=e!==void 0?e:Xi,super(t,e,n,s,r,a,o,c,l,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class Qu extends ai{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const n={width:t,height:t,depth:1},s=[n,n,n,n,n,n];e.encoding!==void 0&&(Es("THREE.WebGLCubeRenderTarget: option.encoding has been replaced by option.colorSpace."),e.colorSpace=e.encoding===ri?Me:Ke),this.texture=new Xl(s,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=e.generateMipmaps!==void 0?e.generateMipmaps:!1,this.texture.minFilter=e.minFilter!==void 0?e.minFilter:qe}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const n={uniforms:{tEquirect:{value:null}},vertexShader:` - - varying vec3 vWorldDirection; - - vec3 transformDirection( in vec3 dir, in mat4 matrix ) { - - return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz ); - - } - - void main() { - - vWorldDirection = transformDirection( position, modelMatrix ); - - #include - #include - - } - `,fragmentShader:` - - uniform sampler2D tEquirect; - - varying vec3 vWorldDirection; - - #include - - void main() { - - vec3 direction = normalize( vWorldDirection ); - - vec2 sampleUV = equirectUv( direction ); - - gl_FragColor = texture2D( tEquirect, sampleUV ); - - } - `},s=new Ji(5,5,5),r=new ci({name:"CubemapFromEquirect",uniforms:Zi(n.uniforms),vertexShader:n.vertexShader,fragmentShader:n.fragmentShader,side:Oe,blending:Gn});r.uniforms.tEquirect.value=e;const a=new ln(s,r),o=e.minFilter;return e.minFilter===ys&&(e.minFilter=qe),new Ju(1,10,this).update(t,a),e.minFilter=o,a.geometry.dispose(),a.material.dispose(),this}clear(t,e,n,s){const r=t.getRenderTarget();for(let a=0;a<6;a++)t.setRenderTarget(this,a),t.clear(e,n,s);t.setRenderTarget(r)}}const po=new U,tf=new U,ef=new Gt;class An{constructor(t=new U(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,n,s){return this.normal.set(t,e,n),this.constant=s,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,n){const s=po.subVectors(n,e).cross(tf.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(s,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const n=t.delta(po),s=this.normal.dot(n);if(s===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const r=-(t.start.dot(this.normal)+this.constant)/s;return r<0||r>1?null:e.copy(t.start).addScaledVector(n,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),n=this.distanceToPoint(t.end);return e<0&&n>0||n<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const n=e||ef.getNormalMatrix(t),s=this.coplanarPoint(po).applyMatrix4(t),r=this.normal.applyMatrix3(n).normalize();return this.constant=-s.dot(r),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return new this.constructor().copy(this)}}const jn=new ws,$s=new U;class ua{constructor(t=new An,e=new An,n=new An,s=new An,r=new An,a=new An){this.planes=[t,e,n,s,r,a]}set(t,e,n,s,r,a){const o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(n),o[3].copy(s),o[4].copy(r),o[5].copy(a),this}copy(t){const e=this.planes;for(let n=0;n<6;n++)e[n].copy(t.planes[n]);return this}setFromProjectionMatrix(t,e=bn){const n=this.planes,s=t.elements,r=s[0],a=s[1],o=s[2],c=s[3],l=s[4],h=s[5],f=s[6],u=s[7],m=s[8],g=s[9],x=s[10],p=s[11],d=s[12],M=s[13],v=s[14],_=s[15];if(n[0].setComponents(c-r,u-l,p-m,_-d).normalize(),n[1].setComponents(c+r,u+l,p+m,_+d).normalize(),n[2].setComponents(c+a,u+h,p+g,_+M).normalize(),n[3].setComponents(c-a,u-h,p-g,_-M).normalize(),n[4].setComponents(c-o,u-f,p-x,_-v).normalize(),e===bn)n[5].setComponents(c+o,u+f,p+x,_+v).normalize();else if(e===br)n[5].setComponents(o,f,x,v).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);return this}intersectsObject(t){if(t.boundingSphere!==void 0)t.boundingSphere===null&&t.computeBoundingSphere(),jn.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;e.boundingSphere===null&&e.computeBoundingSphere(),jn.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(jn)}intersectsSprite(t){return jn.center.set(0,0,0),jn.radius=.7071067811865476,jn.applyMatrix4(t.matrixWorld),this.intersectsSphere(jn)}intersectsSphere(t){const e=this.planes,n=t.center,s=-t.radius;for(let r=0;r<6;r++)if(e[r].distanceToPoint(n)0?t.max.x:t.min.x,$s.y=s.normal.y>0?t.max.y:t.min.y,$s.z=s.normal.z>0?t.max.z:t.min.z,s.distanceToPoint($s)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let n=0;n<6;n++)if(e[n].distanceToPoint(t)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}function Yl(){let i=null,t=!1,e=null,n=null;function s(r,a){e(r,a),n=i.requestAnimationFrame(s)}return{start:function(){t!==!0&&e!==null&&(n=i.requestAnimationFrame(s),t=!0)},stop:function(){i.cancelAnimationFrame(n),t=!1},setAnimationLoop:function(r){e=r},setContext:function(r){i=r}}}function nf(i,t){const e=t.isWebGL2,n=new WeakMap;function s(l,h){const f=l.array,u=l.usage,m=f.byteLength,g=i.createBuffer();i.bindBuffer(h,g),i.bufferData(h,f,u),l.onUploadCallback();let x;if(f instanceof Float32Array)x=i.FLOAT;else if(f instanceof Uint16Array)if(l.isFloat16BufferAttribute)if(e)x=i.HALF_FLOAT;else throw new Error("THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.");else x=i.UNSIGNED_SHORT;else if(f instanceof Int16Array)x=i.SHORT;else if(f instanceof Uint32Array)x=i.UNSIGNED_INT;else if(f instanceof Int32Array)x=i.INT;else if(f instanceof Int8Array)x=i.BYTE;else if(f instanceof Uint8Array)x=i.UNSIGNED_BYTE;else if(f instanceof Uint8ClampedArray)x=i.UNSIGNED_BYTE;else throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: "+f);return{buffer:g,type:x,bytesPerElement:f.BYTES_PER_ELEMENT,version:l.version,size:m}}function r(l,h,f){const u=h.array,m=h._updateRange,g=h.updateRanges;if(i.bindBuffer(f,l),m.count===-1&&g.length===0&&i.bufferSubData(f,0,u),g.length!==0){for(let x=0,p=g.length;x 0 - vec4 plane; - #pragma unroll_loop_start - for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) { - plane = clippingPlanes[ i ]; - if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard; - } - #pragma unroll_loop_end - #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES - bool clipped = true; - #pragma unroll_loop_start - for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) { - plane = clippingPlanes[ i ]; - clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped; - } - #pragma unroll_loop_end - if ( clipped ) discard; - #endif -#endif`,Ef=`#if NUM_CLIPPING_PLANES > 0 - varying vec3 vClipPosition; - uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ]; -#endif`,Mf=`#if NUM_CLIPPING_PLANES > 0 - varying vec3 vClipPosition; -#endif`,Sf=`#if NUM_CLIPPING_PLANES > 0 - vClipPosition = - mvPosition.xyz; -#endif`,yf=`#if defined( USE_COLOR_ALPHA ) - diffuseColor *= vColor; -#elif defined( USE_COLOR ) - diffuseColor.rgb *= vColor; -#endif`,Tf=`#if defined( USE_COLOR_ALPHA ) - varying vec4 vColor; -#elif defined( USE_COLOR ) - varying vec3 vColor; -#endif`,Af=`#if defined( USE_COLOR_ALPHA ) - varying vec4 vColor; -#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) - varying vec3 vColor; -#endif`,bf=`#if defined( USE_COLOR_ALPHA ) - vColor = vec4( 1.0 ); -#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) - vColor = vec3( 1.0 ); -#endif -#ifdef USE_COLOR - vColor *= color; -#endif -#ifdef USE_INSTANCING_COLOR - vColor.xyz *= instanceColor.xyz; -#endif`,wf=`#define PI 3.141592653589793 -#define PI2 6.283185307179586 -#define PI_HALF 1.5707963267948966 -#define RECIPROCAL_PI 0.3183098861837907 -#define RECIPROCAL_PI2 0.15915494309189535 -#define EPSILON 1e-6 -#ifndef saturate -#define saturate( a ) clamp( a, 0.0, 1.0 ) -#endif -#define whiteComplement( a ) ( 1.0 - saturate( a ) ) -float pow2( const in float x ) { return x*x; } -vec3 pow2( const in vec3 x ) { return x*x; } -float pow3( const in float x ) { return x*x*x; } -float pow4( const in float x ) { float x2 = x*x; return x2*x2; } -float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); } -float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); } -highp float rand( const in vec2 uv ) { - const highp float a = 12.9898, b = 78.233, c = 43758.5453; - highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI ); - return fract( sin( sn ) * c ); -} -#ifdef HIGH_PRECISION - float precisionSafeLength( vec3 v ) { return length( v ); } -#else - float precisionSafeLength( vec3 v ) { - float maxComponent = max3( abs( v ) ); - return length( v / maxComponent ) * maxComponent; - } -#endif -struct IncidentLight { - vec3 color; - vec3 direction; - bool visible; -}; -struct ReflectedLight { - vec3 directDiffuse; - vec3 directSpecular; - vec3 indirectDiffuse; - vec3 indirectSpecular; -}; -#ifdef USE_ALPHAHASH - varying vec3 vPosition; -#endif -vec3 transformDirection( in vec3 dir, in mat4 matrix ) { - return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz ); -} -vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) { - return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz ); -} -mat3 transposeMat3( const in mat3 m ) { - mat3 tmp; - tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x ); - tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y ); - tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z ); - return tmp; -} -float luminance( const in vec3 rgb ) { - const vec3 weights = vec3( 0.2126729, 0.7151522, 0.0721750 ); - return dot( weights, rgb ); -} -bool isPerspectiveMatrix( mat4 m ) { - return m[ 2 ][ 3 ] == - 1.0; -} -vec2 equirectUv( in vec3 dir ) { - float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5; - float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5; - return vec2( u, v ); -} -vec3 BRDF_Lambert( const in vec3 diffuseColor ) { - return RECIPROCAL_PI * diffuseColor; -} -vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) { - float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH ); - return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel ); -} -float F_Schlick( const in float f0, const in float f90, const in float dotVH ) { - float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH ); - return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel ); -} // validated`,Cf=`#ifdef ENVMAP_TYPE_CUBE_UV - #define cubeUV_minMipLevel 4.0 - #define cubeUV_minTileSize 16.0 - float getFace( vec3 direction ) { - vec3 absDirection = abs( direction ); - float face = - 1.0; - if ( absDirection.x > absDirection.z ) { - if ( absDirection.x > absDirection.y ) - face = direction.x > 0.0 ? 0.0 : 3.0; - else - face = direction.y > 0.0 ? 1.0 : 4.0; - } else { - if ( absDirection.z > absDirection.y ) - face = direction.z > 0.0 ? 2.0 : 5.0; - else - face = direction.y > 0.0 ? 1.0 : 4.0; - } - return face; - } - vec2 getUV( vec3 direction, float face ) { - vec2 uv; - if ( face == 0.0 ) { - uv = vec2( direction.z, direction.y ) / abs( direction.x ); - } else if ( face == 1.0 ) { - uv = vec2( - direction.x, - direction.z ) / abs( direction.y ); - } else if ( face == 2.0 ) { - uv = vec2( - direction.x, direction.y ) / abs( direction.z ); - } else if ( face == 3.0 ) { - uv = vec2( - direction.z, direction.y ) / abs( direction.x ); - } else if ( face == 4.0 ) { - uv = vec2( - direction.x, direction.z ) / abs( direction.y ); - } else { - uv = vec2( direction.x, direction.y ) / abs( direction.z ); - } - return 0.5 * ( uv + 1.0 ); - } - vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) { - float face = getFace( direction ); - float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 ); - mipInt = max( mipInt, cubeUV_minMipLevel ); - float faceSize = exp2( mipInt ); - highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0; - if ( face > 2.0 ) { - uv.y += faceSize; - face -= 3.0; - } - uv.x += face * faceSize; - uv.x += filterInt * 3.0 * cubeUV_minTileSize; - uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize ); - uv.x *= CUBEUV_TEXEL_WIDTH; - uv.y *= CUBEUV_TEXEL_HEIGHT; - #ifdef texture2DGradEXT - return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb; - #else - return texture2D( envMap, uv ).rgb; - #endif - } - #define cubeUV_r0 1.0 - #define cubeUV_m0 - 2.0 - #define cubeUV_r1 0.8 - #define cubeUV_m1 - 1.0 - #define cubeUV_r4 0.4 - #define cubeUV_m4 2.0 - #define cubeUV_r5 0.305 - #define cubeUV_m5 3.0 - #define cubeUV_r6 0.21 - #define cubeUV_m6 4.0 - float roughnessToMip( float roughness ) { - float mip = 0.0; - if ( roughness >= cubeUV_r1 ) { - mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0; - } else if ( roughness >= cubeUV_r4 ) { - mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1; - } else if ( roughness >= cubeUV_r5 ) { - mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4; - } else if ( roughness >= cubeUV_r6 ) { - mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5; - } else { - mip = - 2.0 * log2( 1.16 * roughness ); } - return mip; - } - vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) { - float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP ); - float mipF = fract( mip ); - float mipInt = floor( mip ); - vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt ); - if ( mipF == 0.0 ) { - return vec4( color0, 1.0 ); - } else { - vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 ); - return vec4( mix( color0, color1, mipF ), 1.0 ); - } - } -#endif`,Rf=`vec3 transformedNormal = objectNormal; -#ifdef USE_TANGENT - vec3 transformedTangent = objectTangent; -#endif -#ifdef USE_BATCHING - mat3 bm = mat3( batchingMatrix ); - transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) ); - transformedNormal = bm * transformedNormal; - #ifdef USE_TANGENT - transformedTangent = bm * transformedTangent; - #endif -#endif -#ifdef USE_INSTANCING - mat3 im = mat3( instanceMatrix ); - transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) ); - transformedNormal = im * transformedNormal; - #ifdef USE_TANGENT - transformedTangent = im * transformedTangent; - #endif -#endif -transformedNormal = normalMatrix * transformedNormal; -#ifdef FLIP_SIDED - transformedNormal = - transformedNormal; -#endif -#ifdef USE_TANGENT - transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz; - #ifdef FLIP_SIDED - transformedTangent = - transformedTangent; - #endif -#endif`,Pf=`#ifdef USE_DISPLACEMENTMAP - uniform sampler2D displacementMap; - uniform float displacementScale; - uniform float displacementBias; -#endif`,Lf=`#ifdef USE_DISPLACEMENTMAP - transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias ); -#endif`,Uf=`#ifdef USE_EMISSIVEMAP - vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv ); - totalEmissiveRadiance *= emissiveColor.rgb; -#endif`,Df=`#ifdef USE_EMISSIVEMAP - uniform sampler2D emissiveMap; -#endif`,If="gl_FragColor = linearToOutputTexel( gl_FragColor );",Of=` -const mat3 LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = mat3( - vec3( 0.8224621, 0.177538, 0.0 ), - vec3( 0.0331941, 0.9668058, 0.0 ), - vec3( 0.0170827, 0.0723974, 0.9105199 ) -); -const mat3 LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = mat3( - vec3( 1.2249401, - 0.2249404, 0.0 ), - vec3( - 0.0420569, 1.0420571, 0.0 ), - vec3( - 0.0196376, - 0.0786361, 1.0982735 ) -); -vec4 LinearSRGBToLinearDisplayP3( in vec4 value ) { - return vec4( value.rgb * LINEAR_SRGB_TO_LINEAR_DISPLAY_P3, value.a ); -} -vec4 LinearDisplayP3ToLinearSRGB( in vec4 value ) { - return vec4( value.rgb * LINEAR_DISPLAY_P3_TO_LINEAR_SRGB, value.a ); -} -vec4 LinearTransferOETF( in vec4 value ) { - return value; -} -vec4 sRGBTransferOETF( in vec4 value ) { - return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a ); -} -vec4 LinearToLinear( in vec4 value ) { - return value; -} -vec4 LinearTosRGB( in vec4 value ) { - return sRGBTransferOETF( value ); -}`,Nf=`#ifdef USE_ENVMAP - #ifdef ENV_WORLDPOS - vec3 cameraToFrag; - if ( isOrthographic ) { - cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) ); - } else { - cameraToFrag = normalize( vWorldPosition - cameraPosition ); - } - vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); - #ifdef ENVMAP_MODE_REFLECTION - vec3 reflectVec = reflect( cameraToFrag, worldNormal ); - #else - vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio ); - #endif - #else - vec3 reflectVec = vReflect; - #endif - #ifdef ENVMAP_TYPE_CUBE - vec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) ); - #else - vec4 envColor = vec4( 0.0 ); - #endif - #ifdef ENVMAP_BLENDING_MULTIPLY - outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity ); - #elif defined( ENVMAP_BLENDING_MIX ) - outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity ); - #elif defined( ENVMAP_BLENDING_ADD ) - outgoingLight += envColor.xyz * specularStrength * reflectivity; - #endif -#endif`,Ff=`#ifdef USE_ENVMAP - uniform float envMapIntensity; - uniform float flipEnvMap; - #ifdef ENVMAP_TYPE_CUBE - uniform samplerCube envMap; - #else - uniform sampler2D envMap; - #endif - -#endif`,Bf=`#ifdef USE_ENVMAP - uniform float reflectivity; - #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT ) - #define ENV_WORLDPOS - #endif - #ifdef ENV_WORLDPOS - varying vec3 vWorldPosition; - uniform float refractionRatio; - #else - varying vec3 vReflect; - #endif -#endif`,zf=`#ifdef USE_ENVMAP - #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT ) - #define ENV_WORLDPOS - #endif - #ifdef ENV_WORLDPOS - - varying vec3 vWorldPosition; - #else - varying vec3 vReflect; - uniform float refractionRatio; - #endif -#endif`,Hf=`#ifdef USE_ENVMAP - #ifdef ENV_WORLDPOS - vWorldPosition = worldPosition.xyz; - #else - vec3 cameraToVertex; - if ( isOrthographic ) { - cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) ); - } else { - cameraToVertex = normalize( worldPosition.xyz - cameraPosition ); - } - vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix ); - #ifdef ENVMAP_MODE_REFLECTION - vReflect = reflect( cameraToVertex, worldNormal ); - #else - vReflect = refract( cameraToVertex, worldNormal, refractionRatio ); - #endif - #endif -#endif`,Vf=`#ifdef USE_FOG - vFogDepth = - mvPosition.z; -#endif`,Gf=`#ifdef USE_FOG - varying float vFogDepth; -#endif`,kf=`#ifdef USE_FOG - #ifdef FOG_EXP2 - float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth ); - #else - float fogFactor = smoothstep( fogNear, fogFar, vFogDepth ); - #endif - gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor ); -#endif`,Wf=`#ifdef USE_FOG - uniform vec3 fogColor; - varying float vFogDepth; - #ifdef FOG_EXP2 - uniform float fogDensity; - #else - uniform float fogNear; - uniform float fogFar; - #endif -#endif`,Xf=`#ifdef USE_GRADIENTMAP - uniform sampler2D gradientMap; -#endif -vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) { - float dotNL = dot( normal, lightDirection ); - vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 ); - #ifdef USE_GRADIENTMAP - return vec3( texture2D( gradientMap, coord ).r ); - #else - vec2 fw = fwidth( coord ) * 0.5; - return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) ); - #endif -}`,Yf=`#ifdef USE_LIGHTMAP - vec4 lightMapTexel = texture2D( lightMap, vLightMapUv ); - vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity; - reflectedLight.indirectDiffuse += lightMapIrradiance; -#endif`,qf=`#ifdef USE_LIGHTMAP - uniform sampler2D lightMap; - uniform float lightMapIntensity; -#endif`,Zf=`LambertMaterial material; -material.diffuseColor = diffuseColor.rgb; -material.specularStrength = specularStrength;`,Kf=`varying vec3 vViewPosition; -struct LambertMaterial { - vec3 diffuseColor; - float specularStrength; -}; -void RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) { - float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); - vec3 irradiance = dotNL * directLight.color; - reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); -} -void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) { - reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); -} -#define RE_Direct RE_Direct_Lambert -#define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert`,$f=`uniform bool receiveShadow; -uniform vec3 ambientLightColor; -#if defined( USE_LIGHT_PROBES ) - uniform vec3 lightProbe[ 9 ]; -#endif -vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) { - float x = normal.x, y = normal.y, z = normal.z; - vec3 result = shCoefficients[ 0 ] * 0.886227; - result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y; - result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z; - result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x; - result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y; - result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z; - result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 ); - result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z; - result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y ); - return result; -} -vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) { - vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); - vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe ); - return irradiance; -} -vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) { - vec3 irradiance = ambientLightColor; - return irradiance; -} -float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) { - #if defined ( LEGACY_LIGHTS ) - if ( cutoffDistance > 0.0 && decayExponent > 0.0 ) { - return pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent ); - } - return 1.0; - #else - float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 ); - if ( cutoffDistance > 0.0 ) { - distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) ); - } - return distanceFalloff; - #endif -} -float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) { - return smoothstep( coneCosine, penumbraCosine, angleCosine ); -} -#if NUM_DIR_LIGHTS > 0 - struct DirectionalLight { - vec3 direction; - vec3 color; - }; - uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ]; - void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) { - light.color = directionalLight.color; - light.direction = directionalLight.direction; - light.visible = true; - } -#endif -#if NUM_POINT_LIGHTS > 0 - struct PointLight { - vec3 position; - vec3 color; - float distance; - float decay; - }; - uniform PointLight pointLights[ NUM_POINT_LIGHTS ]; - void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) { - vec3 lVector = pointLight.position - geometryPosition; - light.direction = normalize( lVector ); - float lightDistance = length( lVector ); - light.color = pointLight.color; - light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay ); - light.visible = ( light.color != vec3( 0.0 ) ); - } -#endif -#if NUM_SPOT_LIGHTS > 0 - struct SpotLight { - vec3 position; - vec3 direction; - vec3 color; - float distance; - float decay; - float coneCos; - float penumbraCos; - }; - uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ]; - void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) { - vec3 lVector = spotLight.position - geometryPosition; - light.direction = normalize( lVector ); - float angleCos = dot( light.direction, spotLight.direction ); - float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos ); - if ( spotAttenuation > 0.0 ) { - float lightDistance = length( lVector ); - light.color = spotLight.color * spotAttenuation; - light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay ); - light.visible = ( light.color != vec3( 0.0 ) ); - } else { - light.color = vec3( 0.0 ); - light.visible = false; - } - } -#endif -#if NUM_RECT_AREA_LIGHTS > 0 - struct RectAreaLight { - vec3 color; - vec3 position; - vec3 halfWidth; - vec3 halfHeight; - }; - uniform sampler2D ltc_1; uniform sampler2D ltc_2; - uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ]; -#endif -#if NUM_HEMI_LIGHTS > 0 - struct HemisphereLight { - vec3 direction; - vec3 skyColor; - vec3 groundColor; - }; - uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ]; - vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) { - float dotNL = dot( normal, hemiLight.direction ); - float hemiDiffuseWeight = 0.5 * dotNL + 0.5; - vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight ); - return irradiance; - } -#endif`,jf=`#ifdef USE_ENVMAP - vec3 getIBLIrradiance( const in vec3 normal ) { - #ifdef ENVMAP_TYPE_CUBE_UV - vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); - vec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 ); - return PI * envMapColor.rgb * envMapIntensity; - #else - return vec3( 0.0 ); - #endif - } - vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) { - #ifdef ENVMAP_TYPE_CUBE_UV - vec3 reflectVec = reflect( - viewDir, normal ); - reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) ); - reflectVec = inverseTransformDirection( reflectVec, viewMatrix ); - vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness ); - return envMapColor.rgb * envMapIntensity; - #else - return vec3( 0.0 ); - #endif - } - #ifdef USE_ANISOTROPY - vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) { - #ifdef ENVMAP_TYPE_CUBE_UV - vec3 bentNormal = cross( bitangent, viewDir ); - bentNormal = normalize( cross( bentNormal, bitangent ) ); - bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) ); - return getIBLRadiance( viewDir, bentNormal, roughness ); - #else - return vec3( 0.0 ); - #endif - } - #endif -#endif`,Jf=`ToonMaterial material; -material.diffuseColor = diffuseColor.rgb;`,Qf=`varying vec3 vViewPosition; -struct ToonMaterial { - vec3 diffuseColor; -}; -void RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) { - vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color; - reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); -} -void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) { - reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); -} -#define RE_Direct RE_Direct_Toon -#define RE_IndirectDiffuse RE_IndirectDiffuse_Toon`,td=`BlinnPhongMaterial material; -material.diffuseColor = diffuseColor.rgb; -material.specularColor = specular; -material.specularShininess = shininess; -material.specularStrength = specularStrength;`,ed=`varying vec3 vViewPosition; -struct BlinnPhongMaterial { - vec3 diffuseColor; - vec3 specularColor; - float specularShininess; - float specularStrength; -}; -void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) { - float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); - vec3 irradiance = dotNL * directLight.color; - reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); - reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength; -} -void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) { - reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); -} -#define RE_Direct RE_Direct_BlinnPhong -#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong`,nd=`PhysicalMaterial material; -material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor ); -vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) ); -float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z ); -material.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness; -material.roughness = min( material.roughness, 1.0 ); -#ifdef IOR - material.ior = ior; - #ifdef USE_SPECULAR - float specularIntensityFactor = specularIntensity; - vec3 specularColorFactor = specularColor; - #ifdef USE_SPECULAR_COLORMAP - specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb; - #endif - #ifdef USE_SPECULAR_INTENSITYMAP - specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a; - #endif - material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor ); - #else - float specularIntensityFactor = 1.0; - vec3 specularColorFactor = vec3( 1.0 ); - material.specularF90 = 1.0; - #endif - material.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor ); -#else - material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor ); - material.specularF90 = 1.0; -#endif -#ifdef USE_CLEARCOAT - material.clearcoat = clearcoat; - material.clearcoatRoughness = clearcoatRoughness; - material.clearcoatF0 = vec3( 0.04 ); - material.clearcoatF90 = 1.0; - #ifdef USE_CLEARCOATMAP - material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x; - #endif - #ifdef USE_CLEARCOAT_ROUGHNESSMAP - material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y; - #endif - material.clearcoat = saturate( material.clearcoat ); material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 ); - material.clearcoatRoughness += geometryRoughness; - material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 ); -#endif -#ifdef USE_IRIDESCENCE - material.iridescence = iridescence; - material.iridescenceIOR = iridescenceIOR; - #ifdef USE_IRIDESCENCEMAP - material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r; - #endif - #ifdef USE_IRIDESCENCE_THICKNESSMAP - material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum; - #else - material.iridescenceThickness = iridescenceThicknessMaximum; - #endif -#endif -#ifdef USE_SHEEN - material.sheenColor = sheenColor; - #ifdef USE_SHEEN_COLORMAP - material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb; - #endif - material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 ); - #ifdef USE_SHEEN_ROUGHNESSMAP - material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a; - #endif -#endif -#ifdef USE_ANISOTROPY - #ifdef USE_ANISOTROPYMAP - mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x ); - vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb; - vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b; - #else - vec2 anisotropyV = anisotropyVector; - #endif - material.anisotropy = length( anisotropyV ); - if( material.anisotropy == 0.0 ) { - anisotropyV = vec2( 1.0, 0.0 ); - } else { - anisotropyV /= material.anisotropy; - material.anisotropy = saturate( material.anisotropy ); - } - material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) ); - material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y; - material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y; -#endif`,id=`struct PhysicalMaterial { - vec3 diffuseColor; - float roughness; - vec3 specularColor; - float specularF90; - #ifdef USE_CLEARCOAT - float clearcoat; - float clearcoatRoughness; - vec3 clearcoatF0; - float clearcoatF90; - #endif - #ifdef USE_IRIDESCENCE - float iridescence; - float iridescenceIOR; - float iridescenceThickness; - vec3 iridescenceFresnel; - vec3 iridescenceF0; - #endif - #ifdef USE_SHEEN - vec3 sheenColor; - float sheenRoughness; - #endif - #ifdef IOR - float ior; - #endif - #ifdef USE_TRANSMISSION - float transmission; - float transmissionAlpha; - float thickness; - float attenuationDistance; - vec3 attenuationColor; - #endif - #ifdef USE_ANISOTROPY - float anisotropy; - float alphaT; - vec3 anisotropyT; - vec3 anisotropyB; - #endif -}; -vec3 clearcoatSpecularDirect = vec3( 0.0 ); -vec3 clearcoatSpecularIndirect = vec3( 0.0 ); -vec3 sheenSpecularDirect = vec3( 0.0 ); -vec3 sheenSpecularIndirect = vec3(0.0 ); -vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) { - float x = clamp( 1.0 - dotVH, 0.0, 1.0 ); - float x2 = x * x; - float x5 = clamp( x * x2 * x2, 0.0, 0.9999 ); - return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 ); -} -float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) { - float a2 = pow2( alpha ); - float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) ); - float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) ); - return 0.5 / max( gv + gl, EPSILON ); -} -float D_GGX( const in float alpha, const in float dotNH ) { - float a2 = pow2( alpha ); - float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; - return RECIPROCAL_PI * a2 / pow2( denom ); -} -#ifdef USE_ANISOTROPY - float V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) { - float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) ); - float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) ); - float v = 0.5 / ( gv + gl ); - return saturate(v); - } - float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) { - float a2 = alphaT * alphaB; - highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH ); - highp float v2 = dot( v, v ); - float w2 = a2 / v2; - return RECIPROCAL_PI * a2 * pow2 ( w2 ); - } -#endif -#ifdef USE_CLEARCOAT - vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) { - vec3 f0 = material.clearcoatF0; - float f90 = material.clearcoatF90; - float roughness = material.clearcoatRoughness; - float alpha = pow2( roughness ); - vec3 halfDir = normalize( lightDir + viewDir ); - float dotNL = saturate( dot( normal, lightDir ) ); - float dotNV = saturate( dot( normal, viewDir ) ); - float dotNH = saturate( dot( normal, halfDir ) ); - float dotVH = saturate( dot( viewDir, halfDir ) ); - vec3 F = F_Schlick( f0, f90, dotVH ); - float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV ); - float D = D_GGX( alpha, dotNH ); - return F * ( V * D ); - } -#endif -vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) { - vec3 f0 = material.specularColor; - float f90 = material.specularF90; - float roughness = material.roughness; - float alpha = pow2( roughness ); - vec3 halfDir = normalize( lightDir + viewDir ); - float dotNL = saturate( dot( normal, lightDir ) ); - float dotNV = saturate( dot( normal, viewDir ) ); - float dotNH = saturate( dot( normal, halfDir ) ); - float dotVH = saturate( dot( viewDir, halfDir ) ); - vec3 F = F_Schlick( f0, f90, dotVH ); - #ifdef USE_IRIDESCENCE - F = mix( F, material.iridescenceFresnel, material.iridescence ); - #endif - #ifdef USE_ANISOTROPY - float dotTL = dot( material.anisotropyT, lightDir ); - float dotTV = dot( material.anisotropyT, viewDir ); - float dotTH = dot( material.anisotropyT, halfDir ); - float dotBL = dot( material.anisotropyB, lightDir ); - float dotBV = dot( material.anisotropyB, viewDir ); - float dotBH = dot( material.anisotropyB, halfDir ); - float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL ); - float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH ); - #else - float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV ); - float D = D_GGX( alpha, dotNH ); - #endif - return F * ( V * D ); -} -vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) { - const float LUT_SIZE = 64.0; - const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE; - const float LUT_BIAS = 0.5 / LUT_SIZE; - float dotNV = saturate( dot( N, V ) ); - vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) ); - uv = uv * LUT_SCALE + LUT_BIAS; - return uv; -} -float LTC_ClippedSphereFormFactor( const in vec3 f ) { - float l = length( f ); - return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 ); -} -vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) { - float x = dot( v1, v2 ); - float y = abs( x ); - float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y; - float b = 3.4175940 + ( 4.1616724 + y ) * y; - float v = a / b; - float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v; - return cross( v1, v2 ) * theta_sintheta; -} -vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) { - vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ]; - vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ]; - vec3 lightNormal = cross( v1, v2 ); - if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 ); - vec3 T1, T2; - T1 = normalize( V - N * dot( V, N ) ); - T2 = - cross( N, T1 ); - mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) ); - vec3 coords[ 4 ]; - coords[ 0 ] = mat * ( rectCoords[ 0 ] - P ); - coords[ 1 ] = mat * ( rectCoords[ 1 ] - P ); - coords[ 2 ] = mat * ( rectCoords[ 2 ] - P ); - coords[ 3 ] = mat * ( rectCoords[ 3 ] - P ); - coords[ 0 ] = normalize( coords[ 0 ] ); - coords[ 1 ] = normalize( coords[ 1 ] ); - coords[ 2 ] = normalize( coords[ 2 ] ); - coords[ 3 ] = normalize( coords[ 3 ] ); - vec3 vectorFormFactor = vec3( 0.0 ); - vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] ); - vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] ); - vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] ); - vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] ); - float result = LTC_ClippedSphereFormFactor( vectorFormFactor ); - return vec3( result ); -} -#if defined( USE_SHEEN ) -float D_Charlie( float roughness, float dotNH ) { - float alpha = pow2( roughness ); - float invAlpha = 1.0 / alpha; - float cos2h = dotNH * dotNH; - float sin2h = max( 1.0 - cos2h, 0.0078125 ); - return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI ); -} -float V_Neubelt( float dotNV, float dotNL ) { - return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) ); -} -vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) { - vec3 halfDir = normalize( lightDir + viewDir ); - float dotNL = saturate( dot( normal, lightDir ) ); - float dotNV = saturate( dot( normal, viewDir ) ); - float dotNH = saturate( dot( normal, halfDir ) ); - float D = D_Charlie( sheenRoughness, dotNH ); - float V = V_Neubelt( dotNV, dotNL ); - return sheenColor * ( D * V ); -} -#endif -float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) { - float dotNV = saturate( dot( normal, viewDir ) ); - float r2 = roughness * roughness; - float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95; - float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72; - float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) ); - return saturate( DG * RECIPROCAL_PI ); -} -vec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) { - float dotNV = saturate( dot( normal, viewDir ) ); - const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 ); - const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 ); - vec4 r = roughness * c0 + c1; - float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y; - vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw; - return fab; -} -vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) { - vec2 fab = DFGApprox( normal, viewDir, roughness ); - return specularColor * fab.x + specularF90 * fab.y; -} -#ifdef USE_IRIDESCENCE -void computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) { -#else -void computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) { -#endif - vec2 fab = DFGApprox( normal, viewDir, roughness ); - #ifdef USE_IRIDESCENCE - vec3 Fr = mix( specularColor, iridescenceF0, iridescence ); - #else - vec3 Fr = specularColor; - #endif - vec3 FssEss = Fr * fab.x + specularF90 * fab.y; - float Ess = fab.x + fab.y; - float Ems = 1.0 - Ess; - vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg ); - singleScatter += FssEss; - multiScatter += Fms * Ems; -} -#if NUM_RECT_AREA_LIGHTS > 0 - void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { - vec3 normal = geometryNormal; - vec3 viewDir = geometryViewDir; - vec3 position = geometryPosition; - vec3 lightPos = rectAreaLight.position; - vec3 halfWidth = rectAreaLight.halfWidth; - vec3 halfHeight = rectAreaLight.halfHeight; - vec3 lightColor = rectAreaLight.color; - float roughness = material.roughness; - vec3 rectCoords[ 4 ]; - rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; rectCoords[ 1 ] = lightPos - halfWidth - halfHeight; - rectCoords[ 2 ] = lightPos - halfWidth + halfHeight; - rectCoords[ 3 ] = lightPos + halfWidth + halfHeight; - vec2 uv = LTC_Uv( normal, viewDir, roughness ); - vec4 t1 = texture2D( ltc_1, uv ); - vec4 t2 = texture2D( ltc_2, uv ); - mat3 mInv = mat3( - vec3( t1.x, 0, t1.y ), - vec3( 0, 1, 0 ), - vec3( t1.z, 0, t1.w ) - ); - vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y ); - reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords ); - reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords ); - } -#endif -void RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { - float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); - vec3 irradiance = dotNL * directLight.color; - #ifdef USE_CLEARCOAT - float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) ); - vec3 ccIrradiance = dotNLcc * directLight.color; - clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material ); - #endif - #ifdef USE_SHEEN - sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness ); - #endif - reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material ); - reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); -} -void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { - reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); -} -void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) { - #ifdef USE_CLEARCOAT - clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness ); - #endif - #ifdef USE_SHEEN - sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ); - #endif - vec3 singleScattering = vec3( 0.0 ); - vec3 multiScattering = vec3( 0.0 ); - vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI; - #ifdef USE_IRIDESCENCE - computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering ); - #else - computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering ); - #endif - vec3 totalScattering = singleScattering + multiScattering; - vec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) ); - reflectedLight.indirectSpecular += radiance * singleScattering; - reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance; - reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance; -} -#define RE_Direct RE_Direct_Physical -#define RE_Direct_RectArea RE_Direct_RectArea_Physical -#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical -#define RE_IndirectSpecular RE_IndirectSpecular_Physical -float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) { - return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion ); -}`,sd=` -vec3 geometryPosition = - vViewPosition; -vec3 geometryNormal = normal; -vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition ); -vec3 geometryClearcoatNormal = vec3( 0.0 ); -#ifdef USE_CLEARCOAT - geometryClearcoatNormal = clearcoatNormal; -#endif -#ifdef USE_IRIDESCENCE - float dotNVi = saturate( dot( normal, geometryViewDir ) ); - if ( material.iridescenceThickness == 0.0 ) { - material.iridescence = 0.0; - } else { - material.iridescence = saturate( material.iridescence ); - } - if ( material.iridescence > 0.0 ) { - material.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor ); - material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi ); - } -#endif -IncidentLight directLight; -#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct ) - PointLight pointLight; - #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0 - PointLightShadow pointLightShadow; - #endif - #pragma unroll_loop_start - for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) { - pointLight = pointLights[ i ]; - getPointLightInfo( pointLight, geometryPosition, directLight ); - #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS ) - pointLightShadow = pointLightShadows[ i ]; - directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0; - #endif - RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); - } - #pragma unroll_loop_end -#endif -#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct ) - SpotLight spotLight; - vec4 spotColor; - vec3 spotLightCoord; - bool inSpotLightMap; - #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0 - SpotLightShadow spotLightShadow; - #endif - #pragma unroll_loop_start - for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) { - spotLight = spotLights[ i ]; - getSpotLightInfo( spotLight, geometryPosition, directLight ); - #if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS ) - #define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX - #elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) - #define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS - #else - #define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS ) - #endif - #if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS ) - spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w; - inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) ); - spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy ); - directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color; - #endif - #undef SPOT_LIGHT_MAP_INDEX - #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) - spotLightShadow = spotLightShadows[ i ]; - directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0; - #endif - RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); - } - #pragma unroll_loop_end -#endif -#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct ) - DirectionalLight directionalLight; - #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0 - DirectionalLightShadow directionalLightShadow; - #endif - #pragma unroll_loop_start - for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) { - directionalLight = directionalLights[ i ]; - getDirectionalLightInfo( directionalLight, directLight ); - #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS ) - directionalLightShadow = directionalLightShadows[ i ]; - directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0; - #endif - RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); - } - #pragma unroll_loop_end -#endif -#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea ) - RectAreaLight rectAreaLight; - #pragma unroll_loop_start - for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) { - rectAreaLight = rectAreaLights[ i ]; - RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); - } - #pragma unroll_loop_end -#endif -#if defined( RE_IndirectDiffuse ) - vec3 iblIrradiance = vec3( 0.0 ); - vec3 irradiance = getAmbientLightIrradiance( ambientLightColor ); - #if defined( USE_LIGHT_PROBES ) - irradiance += getLightProbeIrradiance( lightProbe, geometryNormal ); - #endif - #if ( NUM_HEMI_LIGHTS > 0 ) - #pragma unroll_loop_start - for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) { - irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal ); - } - #pragma unroll_loop_end - #endif -#endif -#if defined( RE_IndirectSpecular ) - vec3 radiance = vec3( 0.0 ); - vec3 clearcoatRadiance = vec3( 0.0 ); -#endif`,rd=`#if defined( RE_IndirectDiffuse ) - #ifdef USE_LIGHTMAP - vec4 lightMapTexel = texture2D( lightMap, vLightMapUv ); - vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity; - irradiance += lightMapIrradiance; - #endif - #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV ) - iblIrradiance += getIBLIrradiance( geometryNormal ); - #endif -#endif -#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular ) - #ifdef USE_ANISOTROPY - radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy ); - #else - radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness ); - #endif - #ifdef USE_CLEARCOAT - clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness ); - #endif -#endif`,od=`#if defined( RE_IndirectDiffuse ) - RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); -#endif -#if defined( RE_IndirectSpecular ) - RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); -#endif`,ad=`#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT ) - gl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5; -#endif`,cd=`#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT ) - uniform float logDepthBufFC; - varying float vFragDepth; - varying float vIsPerspective; -#endif`,ld=`#ifdef USE_LOGDEPTHBUF - #ifdef USE_LOGDEPTHBUF_EXT - varying float vFragDepth; - varying float vIsPerspective; - #else - uniform float logDepthBufFC; - #endif -#endif`,hd=`#ifdef USE_LOGDEPTHBUF - #ifdef USE_LOGDEPTHBUF_EXT - vFragDepth = 1.0 + gl_Position.w; - vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) ); - #else - if ( isPerspectiveMatrix( projectionMatrix ) ) { - gl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0; - gl_Position.z *= gl_Position.w; - } - #endif -#endif`,ud=`#ifdef USE_MAP - vec4 sampledDiffuseColor = texture2D( map, vMapUv ); - #ifdef DECODE_VIDEO_TEXTURE - sampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w ); - - #endif - diffuseColor *= sampledDiffuseColor; -#endif`,fd=`#ifdef USE_MAP - uniform sampler2D map; -#endif`,dd=`#if defined( USE_MAP ) || defined( USE_ALPHAMAP ) - #if defined( USE_POINTS_UV ) - vec2 uv = vUv; - #else - vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy; - #endif -#endif -#ifdef USE_MAP - diffuseColor *= texture2D( map, uv ); -#endif -#ifdef USE_ALPHAMAP - diffuseColor.a *= texture2D( alphaMap, uv ).g; -#endif`,pd=`#if defined( USE_POINTS_UV ) - varying vec2 vUv; -#else - #if defined( USE_MAP ) || defined( USE_ALPHAMAP ) - uniform mat3 uvTransform; - #endif -#endif -#ifdef USE_MAP - uniform sampler2D map; -#endif -#ifdef USE_ALPHAMAP - uniform sampler2D alphaMap; -#endif`,md=`float metalnessFactor = metalness; -#ifdef USE_METALNESSMAP - vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv ); - metalnessFactor *= texelMetalness.b; -#endif`,_d=`#ifdef USE_METALNESSMAP - uniform sampler2D metalnessMap; -#endif`,gd=`#if defined( USE_MORPHCOLORS ) && defined( MORPHTARGETS_TEXTURE ) - vColor *= morphTargetBaseInfluence; - for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { - #if defined( USE_COLOR_ALPHA ) - if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ]; - #elif defined( USE_COLOR ) - if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ]; - #endif - } -#endif`,xd=`#ifdef USE_MORPHNORMALS - objectNormal *= morphTargetBaseInfluence; - #ifdef MORPHTARGETS_TEXTURE - for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { - if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ]; - } - #else - objectNormal += morphNormal0 * morphTargetInfluences[ 0 ]; - objectNormal += morphNormal1 * morphTargetInfluences[ 1 ]; - objectNormal += morphNormal2 * morphTargetInfluences[ 2 ]; - objectNormal += morphNormal3 * morphTargetInfluences[ 3 ]; - #endif -#endif`,vd=`#ifdef USE_MORPHTARGETS - uniform float morphTargetBaseInfluence; - #ifdef MORPHTARGETS_TEXTURE - uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ]; - uniform sampler2DArray morphTargetsTexture; - uniform ivec2 morphTargetsTextureSize; - vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) { - int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset; - int y = texelIndex / morphTargetsTextureSize.x; - int x = texelIndex - y * morphTargetsTextureSize.x; - ivec3 morphUV = ivec3( x, y, morphTargetIndex ); - return texelFetch( morphTargetsTexture, morphUV, 0 ); - } - #else - #ifndef USE_MORPHNORMALS - uniform float morphTargetInfluences[ 8 ]; - #else - uniform float morphTargetInfluences[ 4 ]; - #endif - #endif -#endif`,Ed=`#ifdef USE_MORPHTARGETS - transformed *= morphTargetBaseInfluence; - #ifdef MORPHTARGETS_TEXTURE - for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { - if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ]; - } - #else - transformed += morphTarget0 * morphTargetInfluences[ 0 ]; - transformed += morphTarget1 * morphTargetInfluences[ 1 ]; - transformed += morphTarget2 * morphTargetInfluences[ 2 ]; - transformed += morphTarget3 * morphTargetInfluences[ 3 ]; - #ifndef USE_MORPHNORMALS - transformed += morphTarget4 * morphTargetInfluences[ 4 ]; - transformed += morphTarget5 * morphTargetInfluences[ 5 ]; - transformed += morphTarget6 * morphTargetInfluences[ 6 ]; - transformed += morphTarget7 * morphTargetInfluences[ 7 ]; - #endif - #endif -#endif`,Md=`float faceDirection = gl_FrontFacing ? 1.0 : - 1.0; -#ifdef FLAT_SHADED - vec3 fdx = dFdx( vViewPosition ); - vec3 fdy = dFdy( vViewPosition ); - vec3 normal = normalize( cross( fdx, fdy ) ); -#else - vec3 normal = normalize( vNormal ); - #ifdef DOUBLE_SIDED - normal *= faceDirection; - #endif -#endif -#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) - #ifdef USE_TANGENT - mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal ); - #else - mat3 tbn = getTangentFrame( - vViewPosition, normal, - #if defined( USE_NORMALMAP ) - vNormalMapUv - #elif defined( USE_CLEARCOAT_NORMALMAP ) - vClearcoatNormalMapUv - #else - vUv - #endif - ); - #endif - #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED ) - tbn[0] *= faceDirection; - tbn[1] *= faceDirection; - #endif -#endif -#ifdef USE_CLEARCOAT_NORMALMAP - #ifdef USE_TANGENT - mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal ); - #else - mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv ); - #endif - #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED ) - tbn2[0] *= faceDirection; - tbn2[1] *= faceDirection; - #endif -#endif -vec3 nonPerturbedNormal = normal;`,Sd=`#ifdef USE_NORMALMAP_OBJECTSPACE - normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0; - #ifdef FLIP_SIDED - normal = - normal; - #endif - #ifdef DOUBLE_SIDED - normal = normal * faceDirection; - #endif - normal = normalize( normalMatrix * normal ); -#elif defined( USE_NORMALMAP_TANGENTSPACE ) - vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0; - mapN.xy *= normalScale; - normal = normalize( tbn * mapN ); -#elif defined( USE_BUMPMAP ) - normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection ); -#endif`,yd=`#ifndef FLAT_SHADED - varying vec3 vNormal; - #ifdef USE_TANGENT - varying vec3 vTangent; - varying vec3 vBitangent; - #endif -#endif`,Td=`#ifndef FLAT_SHADED - varying vec3 vNormal; - #ifdef USE_TANGENT - varying vec3 vTangent; - varying vec3 vBitangent; - #endif -#endif`,Ad=`#ifndef FLAT_SHADED - vNormal = normalize( transformedNormal ); - #ifdef USE_TANGENT - vTangent = normalize( transformedTangent ); - vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w ); - #endif -#endif`,bd=`#ifdef USE_NORMALMAP - uniform sampler2D normalMap; - uniform vec2 normalScale; -#endif -#ifdef USE_NORMALMAP_OBJECTSPACE - uniform mat3 normalMatrix; -#endif -#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) ) - mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) { - vec3 q0 = dFdx( eye_pos.xyz ); - vec3 q1 = dFdy( eye_pos.xyz ); - vec2 st0 = dFdx( uv.st ); - vec2 st1 = dFdy( uv.st ); - vec3 N = surf_norm; - vec3 q1perp = cross( q1, N ); - vec3 q0perp = cross( N, q0 ); - vec3 T = q1perp * st0.x + q0perp * st1.x; - vec3 B = q1perp * st0.y + q0perp * st1.y; - float det = max( dot( T, T ), dot( B, B ) ); - float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det ); - return mat3( T * scale, B * scale, N ); - } -#endif`,wd=`#ifdef USE_CLEARCOAT - vec3 clearcoatNormal = nonPerturbedNormal; -#endif`,Cd=`#ifdef USE_CLEARCOAT_NORMALMAP - vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0; - clearcoatMapN.xy *= clearcoatNormalScale; - clearcoatNormal = normalize( tbn2 * clearcoatMapN ); -#endif`,Rd=`#ifdef USE_CLEARCOATMAP - uniform sampler2D clearcoatMap; -#endif -#ifdef USE_CLEARCOAT_NORMALMAP - uniform sampler2D clearcoatNormalMap; - uniform vec2 clearcoatNormalScale; -#endif -#ifdef USE_CLEARCOAT_ROUGHNESSMAP - uniform sampler2D clearcoatRoughnessMap; -#endif`,Pd=`#ifdef USE_IRIDESCENCEMAP - uniform sampler2D iridescenceMap; -#endif -#ifdef USE_IRIDESCENCE_THICKNESSMAP - uniform sampler2D iridescenceThicknessMap; -#endif`,Ld=`#ifdef OPAQUE -diffuseColor.a = 1.0; -#endif -#ifdef USE_TRANSMISSION -diffuseColor.a *= material.transmissionAlpha; -#endif -gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,Ud=`vec3 packNormalToRGB( const in vec3 normal ) { - return normalize( normal ) * 0.5 + 0.5; -} -vec3 unpackRGBToNormal( const in vec3 rgb ) { - return 2.0 * rgb.xyz - 1.0; -} -const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.; -const vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. ); -const vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. ); -const float ShiftRight8 = 1. / 256.; -vec4 packDepthToRGBA( const in float v ) { - vec4 r = vec4( fract( v * PackFactors ), v ); - r.yzw -= r.xyz * ShiftRight8; return r * PackUpscale; -} -float unpackRGBAToDepth( const in vec4 v ) { - return dot( v, UnpackFactors ); -} -vec2 packDepthToRG( in highp float v ) { - return packDepthToRGBA( v ).yx; -} -float unpackRGToDepth( const in highp vec2 v ) { - return unpackRGBAToDepth( vec4( v.xy, 0.0, 0.0 ) ); -} -vec4 pack2HalfToRGBA( vec2 v ) { - vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) ); - return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w ); -} -vec2 unpackRGBATo2Half( vec4 v ) { - return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) ); -} -float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) { - return ( viewZ + near ) / ( near - far ); -} -float orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) { - return depth * ( near - far ) - near; -} -float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) { - return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ ); -} -float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) { - return ( near * far ) / ( ( far - near ) * depth - far ); -}`,Dd=`#ifdef PREMULTIPLIED_ALPHA - gl_FragColor.rgb *= gl_FragColor.a; -#endif`,Id=`vec4 mvPosition = vec4( transformed, 1.0 ); -#ifdef USE_BATCHING - mvPosition = batchingMatrix * mvPosition; -#endif -#ifdef USE_INSTANCING - mvPosition = instanceMatrix * mvPosition; -#endif -mvPosition = modelViewMatrix * mvPosition; -gl_Position = projectionMatrix * mvPosition;`,Od=`#ifdef DITHERING - gl_FragColor.rgb = dithering( gl_FragColor.rgb ); -#endif`,Nd=`#ifdef DITHERING - vec3 dithering( vec3 color ) { - float grid_position = rand( gl_FragCoord.xy ); - vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 ); - dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position ); - return color + dither_shift_RGB; - } -#endif`,Fd=`float roughnessFactor = roughness; -#ifdef USE_ROUGHNESSMAP - vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv ); - roughnessFactor *= texelRoughness.g; -#endif`,Bd=`#ifdef USE_ROUGHNESSMAP - uniform sampler2D roughnessMap; -#endif`,zd=`#if NUM_SPOT_LIGHT_COORDS > 0 - varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ]; -#endif -#if NUM_SPOT_LIGHT_MAPS > 0 - uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ]; -#endif -#ifdef USE_SHADOWMAP - #if NUM_DIR_LIGHT_SHADOWS > 0 - uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ]; - varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ]; - struct DirectionalLightShadow { - float shadowBias; - float shadowNormalBias; - float shadowRadius; - vec2 shadowMapSize; - }; - uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ]; - #endif - #if NUM_SPOT_LIGHT_SHADOWS > 0 - uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ]; - struct SpotLightShadow { - float shadowBias; - float shadowNormalBias; - float shadowRadius; - vec2 shadowMapSize; - }; - uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ]; - #endif - #if NUM_POINT_LIGHT_SHADOWS > 0 - uniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ]; - varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ]; - struct PointLightShadow { - float shadowBias; - float shadowNormalBias; - float shadowRadius; - vec2 shadowMapSize; - float shadowCameraNear; - float shadowCameraFar; - }; - uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ]; - #endif - float texture2DCompare( sampler2D depths, vec2 uv, float compare ) { - return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) ); - } - vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) { - return unpackRGBATo2Half( texture2D( shadow, uv ) ); - } - float VSMShadow (sampler2D shadow, vec2 uv, float compare ){ - float occlusion = 1.0; - vec2 distribution = texture2DDistribution( shadow, uv ); - float hard_shadow = step( compare , distribution.x ); - if (hard_shadow != 1.0 ) { - float distance = compare - distribution.x ; - float variance = max( 0.00000, distribution.y * distribution.y ); - float softness_probability = variance / (variance + distance * distance ); softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 ); occlusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 ); - } - return occlusion; - } - float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) { - float shadow = 1.0; - shadowCoord.xyz /= shadowCoord.w; - shadowCoord.z += shadowBias; - bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0; - bool frustumTest = inFrustum && shadowCoord.z <= 1.0; - if ( frustumTest ) { - #if defined( SHADOWMAP_TYPE_PCF ) - vec2 texelSize = vec2( 1.0 ) / shadowMapSize; - float dx0 = - texelSize.x * shadowRadius; - float dy0 = - texelSize.y * shadowRadius; - float dx1 = + texelSize.x * shadowRadius; - float dy1 = + texelSize.y * shadowRadius; - float dx2 = dx0 / 2.0; - float dy2 = dy0 / 2.0; - float dx3 = dx1 / 2.0; - float dy3 = dy1 / 2.0; - shadow = ( - texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) + - texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z ) - ) * ( 1.0 / 17.0 ); - #elif defined( SHADOWMAP_TYPE_PCF_SOFT ) - vec2 texelSize = vec2( 1.0 ) / shadowMapSize; - float dx = texelSize.x; - float dy = texelSize.y; - vec2 uv = shadowCoord.xy; - vec2 f = fract( uv * shadowMapSize + 0.5 ); - uv -= f * texelSize; - shadow = ( - texture2DCompare( shadowMap, uv, shadowCoord.z ) + - texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) + - texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) + - texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) + - mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), - texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ), - f.x ) + - mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), - texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ), - f.x ) + - mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), - texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ), - f.y ) + - mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), - texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ), - f.y ) + - mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), - texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ), - f.x ), - mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), - texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ), - f.x ), - f.y ) - ) * ( 1.0 / 9.0 ); - #elif defined( SHADOWMAP_TYPE_VSM ) - shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z ); - #else - shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ); - #endif - } - return shadow; - } - vec2 cubeToUV( vec3 v, float texelSizeY ) { - vec3 absV = abs( v ); - float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) ); - absV *= scaleToCube; - v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY ); - vec2 planar = v.xy; - float almostATexel = 1.5 * texelSizeY; - float almostOne = 1.0 - almostATexel; - if ( absV.z >= almostOne ) { - if ( v.z > 0.0 ) - planar.x = 4.0 - v.x; - } else if ( absV.x >= almostOne ) { - float signX = sign( v.x ); - planar.x = v.z * signX + 2.0 * signX; - } else if ( absV.y >= almostOne ) { - float signY = sign( v.y ); - planar.x = v.x + 2.0 * signY + 2.0; - planar.y = v.z * signY - 2.0; - } - return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 ); - } - float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) { - vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) ); - vec3 lightToPosition = shadowCoord.xyz; - float dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); dp += shadowBias; - vec3 bd3D = normalize( lightToPosition ); - #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM ) - vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y; - return ( - texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) + - texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) + - texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) + - texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) + - texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) + - texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) + - texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) + - texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) + - texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp ) - ) * ( 1.0 / 9.0 ); - #else - return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ); - #endif - } -#endif`,Hd=`#if NUM_SPOT_LIGHT_COORDS > 0 - uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ]; - varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ]; -#endif -#ifdef USE_SHADOWMAP - #if NUM_DIR_LIGHT_SHADOWS > 0 - uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ]; - varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ]; - struct DirectionalLightShadow { - float shadowBias; - float shadowNormalBias; - float shadowRadius; - vec2 shadowMapSize; - }; - uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ]; - #endif - #if NUM_SPOT_LIGHT_SHADOWS > 0 - struct SpotLightShadow { - float shadowBias; - float shadowNormalBias; - float shadowRadius; - vec2 shadowMapSize; - }; - uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ]; - #endif - #if NUM_POINT_LIGHT_SHADOWS > 0 - uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ]; - varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ]; - struct PointLightShadow { - float shadowBias; - float shadowNormalBias; - float shadowRadius; - vec2 shadowMapSize; - float shadowCameraNear; - float shadowCameraFar; - }; - uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ]; - #endif -#endif`,Vd=`#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 ) - vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix ); - vec4 shadowWorldPosition; -#endif -#if defined( USE_SHADOWMAP ) - #if NUM_DIR_LIGHT_SHADOWS > 0 - #pragma unroll_loop_start - for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) { - shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 ); - vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition; - } - #pragma unroll_loop_end - #endif - #if NUM_POINT_LIGHT_SHADOWS > 0 - #pragma unroll_loop_start - for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) { - shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 ); - vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition; - } - #pragma unroll_loop_end - #endif -#endif -#if NUM_SPOT_LIGHT_COORDS > 0 - #pragma unroll_loop_start - for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) { - shadowWorldPosition = worldPosition; - #if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) - shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias; - #endif - vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition; - } - #pragma unroll_loop_end -#endif`,Gd=`float getShadowMask() { - float shadow = 1.0; - #ifdef USE_SHADOWMAP - #if NUM_DIR_LIGHT_SHADOWS > 0 - DirectionalLightShadow directionalLight; - #pragma unroll_loop_start - for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) { - directionalLight = directionalLightShadows[ i ]; - shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0; - } - #pragma unroll_loop_end - #endif - #if NUM_SPOT_LIGHT_SHADOWS > 0 - SpotLightShadow spotLight; - #pragma unroll_loop_start - for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) { - spotLight = spotLightShadows[ i ]; - shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0; - } - #pragma unroll_loop_end - #endif - #if NUM_POINT_LIGHT_SHADOWS > 0 - PointLightShadow pointLight; - #pragma unroll_loop_start - for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) { - pointLight = pointLightShadows[ i ]; - shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0; - } - #pragma unroll_loop_end - #endif - #endif - return shadow; -}`,kd=`#ifdef USE_SKINNING - mat4 boneMatX = getBoneMatrix( skinIndex.x ); - mat4 boneMatY = getBoneMatrix( skinIndex.y ); - mat4 boneMatZ = getBoneMatrix( skinIndex.z ); - mat4 boneMatW = getBoneMatrix( skinIndex.w ); -#endif`,Wd=`#ifdef USE_SKINNING - uniform mat4 bindMatrix; - uniform mat4 bindMatrixInverse; - uniform highp sampler2D boneTexture; - mat4 getBoneMatrix( const in float i ) { - int size = textureSize( boneTexture, 0 ).x; - int j = int( i ) * 4; - int x = j % size; - int y = j / size; - vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 ); - vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 ); - vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 ); - vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 ); - return mat4( v1, v2, v3, v4 ); - } -#endif`,Xd=`#ifdef USE_SKINNING - vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 ); - vec4 skinned = vec4( 0.0 ); - skinned += boneMatX * skinVertex * skinWeight.x; - skinned += boneMatY * skinVertex * skinWeight.y; - skinned += boneMatZ * skinVertex * skinWeight.z; - skinned += boneMatW * skinVertex * skinWeight.w; - transformed = ( bindMatrixInverse * skinned ).xyz; -#endif`,Yd=`#ifdef USE_SKINNING - mat4 skinMatrix = mat4( 0.0 ); - skinMatrix += skinWeight.x * boneMatX; - skinMatrix += skinWeight.y * boneMatY; - skinMatrix += skinWeight.z * boneMatZ; - skinMatrix += skinWeight.w * boneMatW; - skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix; - objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz; - #ifdef USE_TANGENT - objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz; - #endif -#endif`,qd=`float specularStrength; -#ifdef USE_SPECULARMAP - vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv ); - specularStrength = texelSpecular.r; -#else - specularStrength = 1.0; -#endif`,Zd=`#ifdef USE_SPECULARMAP - uniform sampler2D specularMap; -#endif`,Kd=`#if defined( TONE_MAPPING ) - gl_FragColor.rgb = toneMapping( gl_FragColor.rgb ); -#endif`,$d=`#ifndef saturate -#define saturate( a ) clamp( a, 0.0, 1.0 ) -#endif -uniform float toneMappingExposure; -vec3 LinearToneMapping( vec3 color ) { - return saturate( toneMappingExposure * color ); -} -vec3 ReinhardToneMapping( vec3 color ) { - color *= toneMappingExposure; - return saturate( color / ( vec3( 1.0 ) + color ) ); -} -vec3 OptimizedCineonToneMapping( vec3 color ) { - color *= toneMappingExposure; - color = max( vec3( 0.0 ), color - 0.004 ); - return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) ); -} -vec3 RRTAndODTFit( vec3 v ) { - vec3 a = v * ( v + 0.0245786 ) - 0.000090537; - vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081; - return a / b; -} -vec3 ACESFilmicToneMapping( vec3 color ) { - const mat3 ACESInputMat = mat3( - vec3( 0.59719, 0.07600, 0.02840 ), vec3( 0.35458, 0.90834, 0.13383 ), - vec3( 0.04823, 0.01566, 0.83777 ) - ); - const mat3 ACESOutputMat = mat3( - vec3( 1.60475, -0.10208, -0.00327 ), vec3( -0.53108, 1.10813, -0.07276 ), - vec3( -0.07367, -0.00605, 1.07602 ) - ); - color *= toneMappingExposure / 0.6; - color = ACESInputMat * color; - color = RRTAndODTFit( color ); - color = ACESOutputMat * color; - return saturate( color ); -} -const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3( - vec3( 1.6605, - 0.1246, - 0.0182 ), - vec3( - 0.5876, 1.1329, - 0.1006 ), - vec3( - 0.0728, - 0.0083, 1.1187 ) -); -const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3( - vec3( 0.6274, 0.0691, 0.0164 ), - vec3( 0.3293, 0.9195, 0.0880 ), - vec3( 0.0433, 0.0113, 0.8956 ) -); -vec3 agxDefaultContrastApprox( vec3 x ) { - vec3 x2 = x * x; - vec3 x4 = x2 * x2; - return + 15.5 * x4 * x2 - - 40.14 * x4 * x - + 31.96 * x4 - - 6.868 * x2 * x - + 0.4298 * x2 - + 0.1191 * x - - 0.00232; -} -vec3 AgXToneMapping( vec3 color ) { - const mat3 AgXInsetMatrix = mat3( - vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ), - vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ), - vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 ) - ); - const mat3 AgXOutsetMatrix = mat3( - vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ), - vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ), - vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 ) - ); - const float AgxMinEv = - 12.47393; const float AgxMaxEv = 4.026069; - color = LINEAR_SRGB_TO_LINEAR_REC2020 * color; - color *= toneMappingExposure; - color = AgXInsetMatrix * color; - color = max( color, 1e-10 ); color = log2( color ); - color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv ); - color = clamp( color, 0.0, 1.0 ); - color = agxDefaultContrastApprox( color ); - color = AgXOutsetMatrix * color; - color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) ); - color = LINEAR_REC2020_TO_LINEAR_SRGB * color; - return color; -} -vec3 CustomToneMapping( vec3 color ) { return color; }`,jd=`#ifdef USE_TRANSMISSION - material.transmission = transmission; - material.transmissionAlpha = 1.0; - material.thickness = thickness; - material.attenuationDistance = attenuationDistance; - material.attenuationColor = attenuationColor; - #ifdef USE_TRANSMISSIONMAP - material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r; - #endif - #ifdef USE_THICKNESSMAP - material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g; - #endif - vec3 pos = vWorldPosition; - vec3 v = normalize( cameraPosition - pos ); - vec3 n = inverseTransformDirection( normal, viewMatrix ); - vec4 transmitted = getIBLVolumeRefraction( - n, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90, - pos, modelMatrix, viewMatrix, projectionMatrix, material.ior, material.thickness, - material.attenuationColor, material.attenuationDistance ); - material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission ); - totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission ); -#endif`,Jd=`#ifdef USE_TRANSMISSION - uniform float transmission; - uniform float thickness; - uniform float attenuationDistance; - uniform vec3 attenuationColor; - #ifdef USE_TRANSMISSIONMAP - uniform sampler2D transmissionMap; - #endif - #ifdef USE_THICKNESSMAP - uniform sampler2D thicknessMap; - #endif - uniform vec2 transmissionSamplerSize; - uniform sampler2D transmissionSamplerMap; - uniform mat4 modelMatrix; - uniform mat4 projectionMatrix; - varying vec3 vWorldPosition; - float w0( float a ) { - return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 ); - } - float w1( float a ) { - return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 ); - } - float w2( float a ){ - return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 ); - } - float w3( float a ) { - return ( 1.0 / 6.0 ) * ( a * a * a ); - } - float g0( float a ) { - return w0( a ) + w1( a ); - } - float g1( float a ) { - return w2( a ) + w3( a ); - } - float h0( float a ) { - return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) ); - } - float h1( float a ) { - return 1.0 + w3( a ) / ( w2( a ) + w3( a ) ); - } - vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) { - uv = uv * texelSize.zw + 0.5; - vec2 iuv = floor( uv ); - vec2 fuv = fract( uv ); - float g0x = g0( fuv.x ); - float g1x = g1( fuv.x ); - float h0x = h0( fuv.x ); - float h1x = h1( fuv.x ); - float h0y = h0( fuv.y ); - float h1y = h1( fuv.y ); - vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy; - vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy; - vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy; - vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy; - return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) + - g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) ); - } - vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) { - vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) ); - vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) ); - vec2 fLodSizeInv = 1.0 / fLodSize; - vec2 cLodSizeInv = 1.0 / cLodSize; - vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) ); - vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) ); - return mix( fSample, cSample, fract( lod ) ); - } - vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) { - vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior ); - vec3 modelScale; - modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) ); - modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) ); - modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) ); - return normalize( refractionVector ) * thickness * modelScale; - } - float applyIorToRoughness( const in float roughness, const in float ior ) { - return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 ); - } - vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) { - float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior ); - return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod ); - } - vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) { - if ( isinf( attenuationDistance ) ) { - return vec3( 1.0 ); - } else { - vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance; - vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance; - } - } - vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor, - const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix, - const in mat4 viewMatrix, const in mat4 projMatrix, const in float ior, const in float thickness, - const in vec3 attenuationColor, const in float attenuationDistance ) { - vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix ); - vec3 refractedRayExit = position + transmissionRay; - vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 ); - vec2 refractionCoords = ndcPos.xy / ndcPos.w; - refractionCoords += 1.0; - refractionCoords /= 2.0; - vec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior ); - vec3 transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance ); - vec3 attenuatedColor = transmittance * transmittedLight.rgb; - vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness ); - float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0; - return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor ); - } -#endif`,Qd=`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) - varying vec2 vUv; -#endif -#ifdef USE_MAP - varying vec2 vMapUv; -#endif -#ifdef USE_ALPHAMAP - varying vec2 vAlphaMapUv; -#endif -#ifdef USE_LIGHTMAP - varying vec2 vLightMapUv; -#endif -#ifdef USE_AOMAP - varying vec2 vAoMapUv; -#endif -#ifdef USE_BUMPMAP - varying vec2 vBumpMapUv; -#endif -#ifdef USE_NORMALMAP - varying vec2 vNormalMapUv; -#endif -#ifdef USE_EMISSIVEMAP - varying vec2 vEmissiveMapUv; -#endif -#ifdef USE_METALNESSMAP - varying vec2 vMetalnessMapUv; -#endif -#ifdef USE_ROUGHNESSMAP - varying vec2 vRoughnessMapUv; -#endif -#ifdef USE_ANISOTROPYMAP - varying vec2 vAnisotropyMapUv; -#endif -#ifdef USE_CLEARCOATMAP - varying vec2 vClearcoatMapUv; -#endif -#ifdef USE_CLEARCOAT_NORMALMAP - varying vec2 vClearcoatNormalMapUv; -#endif -#ifdef USE_CLEARCOAT_ROUGHNESSMAP - varying vec2 vClearcoatRoughnessMapUv; -#endif -#ifdef USE_IRIDESCENCEMAP - varying vec2 vIridescenceMapUv; -#endif -#ifdef USE_IRIDESCENCE_THICKNESSMAP - varying vec2 vIridescenceThicknessMapUv; -#endif -#ifdef USE_SHEEN_COLORMAP - varying vec2 vSheenColorMapUv; -#endif -#ifdef USE_SHEEN_ROUGHNESSMAP - varying vec2 vSheenRoughnessMapUv; -#endif -#ifdef USE_SPECULARMAP - varying vec2 vSpecularMapUv; -#endif -#ifdef USE_SPECULAR_COLORMAP - varying vec2 vSpecularColorMapUv; -#endif -#ifdef USE_SPECULAR_INTENSITYMAP - varying vec2 vSpecularIntensityMapUv; -#endif -#ifdef USE_TRANSMISSIONMAP - uniform mat3 transmissionMapTransform; - varying vec2 vTransmissionMapUv; -#endif -#ifdef USE_THICKNESSMAP - uniform mat3 thicknessMapTransform; - varying vec2 vThicknessMapUv; -#endif`,tp=`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) - varying vec2 vUv; -#endif -#ifdef USE_MAP - uniform mat3 mapTransform; - varying vec2 vMapUv; -#endif -#ifdef USE_ALPHAMAP - uniform mat3 alphaMapTransform; - varying vec2 vAlphaMapUv; -#endif -#ifdef USE_LIGHTMAP - uniform mat3 lightMapTransform; - varying vec2 vLightMapUv; -#endif -#ifdef USE_AOMAP - uniform mat3 aoMapTransform; - varying vec2 vAoMapUv; -#endif -#ifdef USE_BUMPMAP - uniform mat3 bumpMapTransform; - varying vec2 vBumpMapUv; -#endif -#ifdef USE_NORMALMAP - uniform mat3 normalMapTransform; - varying vec2 vNormalMapUv; -#endif -#ifdef USE_DISPLACEMENTMAP - uniform mat3 displacementMapTransform; - varying vec2 vDisplacementMapUv; -#endif -#ifdef USE_EMISSIVEMAP - uniform mat3 emissiveMapTransform; - varying vec2 vEmissiveMapUv; -#endif -#ifdef USE_METALNESSMAP - uniform mat3 metalnessMapTransform; - varying vec2 vMetalnessMapUv; -#endif -#ifdef USE_ROUGHNESSMAP - uniform mat3 roughnessMapTransform; - varying vec2 vRoughnessMapUv; -#endif -#ifdef USE_ANISOTROPYMAP - uniform mat3 anisotropyMapTransform; - varying vec2 vAnisotropyMapUv; -#endif -#ifdef USE_CLEARCOATMAP - uniform mat3 clearcoatMapTransform; - varying vec2 vClearcoatMapUv; -#endif -#ifdef USE_CLEARCOAT_NORMALMAP - uniform mat3 clearcoatNormalMapTransform; - varying vec2 vClearcoatNormalMapUv; -#endif -#ifdef USE_CLEARCOAT_ROUGHNESSMAP - uniform mat3 clearcoatRoughnessMapTransform; - varying vec2 vClearcoatRoughnessMapUv; -#endif -#ifdef USE_SHEEN_COLORMAP - uniform mat3 sheenColorMapTransform; - varying vec2 vSheenColorMapUv; -#endif -#ifdef USE_SHEEN_ROUGHNESSMAP - uniform mat3 sheenRoughnessMapTransform; - varying vec2 vSheenRoughnessMapUv; -#endif -#ifdef USE_IRIDESCENCEMAP - uniform mat3 iridescenceMapTransform; - varying vec2 vIridescenceMapUv; -#endif -#ifdef USE_IRIDESCENCE_THICKNESSMAP - uniform mat3 iridescenceThicknessMapTransform; - varying vec2 vIridescenceThicknessMapUv; -#endif -#ifdef USE_SPECULARMAP - uniform mat3 specularMapTransform; - varying vec2 vSpecularMapUv; -#endif -#ifdef USE_SPECULAR_COLORMAP - uniform mat3 specularColorMapTransform; - varying vec2 vSpecularColorMapUv; -#endif -#ifdef USE_SPECULAR_INTENSITYMAP - uniform mat3 specularIntensityMapTransform; - varying vec2 vSpecularIntensityMapUv; -#endif -#ifdef USE_TRANSMISSIONMAP - uniform mat3 transmissionMapTransform; - varying vec2 vTransmissionMapUv; -#endif -#ifdef USE_THICKNESSMAP - uniform mat3 thicknessMapTransform; - varying vec2 vThicknessMapUv; -#endif`,ep=`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) - vUv = vec3( uv, 1 ).xy; -#endif -#ifdef USE_MAP - vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy; -#endif -#ifdef USE_ALPHAMAP - vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_LIGHTMAP - vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_AOMAP - vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_BUMPMAP - vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_NORMALMAP - vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_DISPLACEMENTMAP - vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_EMISSIVEMAP - vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_METALNESSMAP - vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_ROUGHNESSMAP - vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_ANISOTROPYMAP - vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_CLEARCOATMAP - vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_CLEARCOAT_NORMALMAP - vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_CLEARCOAT_ROUGHNESSMAP - vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_IRIDESCENCEMAP - vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_IRIDESCENCE_THICKNESSMAP - vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_SHEEN_COLORMAP - vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_SHEEN_ROUGHNESSMAP - vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_SPECULARMAP - vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_SPECULAR_COLORMAP - vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_SPECULAR_INTENSITYMAP - vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_TRANSMISSIONMAP - vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy; -#endif -#ifdef USE_THICKNESSMAP - vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy; -#endif`,np=`#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0 - vec4 worldPosition = vec4( transformed, 1.0 ); - #ifdef USE_BATCHING - worldPosition = batchingMatrix * worldPosition; - #endif - #ifdef USE_INSTANCING - worldPosition = instanceMatrix * worldPosition; - #endif - worldPosition = modelMatrix * worldPosition; -#endif`;const ip=`varying vec2 vUv; -uniform mat3 uvTransform; -void main() { - vUv = ( uvTransform * vec3( uv, 1 ) ).xy; - gl_Position = vec4( position.xy, 1.0, 1.0 ); -}`,sp=`uniform sampler2D t2D; -uniform float backgroundIntensity; -varying vec2 vUv; -void main() { - vec4 texColor = texture2D( t2D, vUv ); - #ifdef DECODE_VIDEO_TEXTURE - texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w ); - #endif - texColor.rgb *= backgroundIntensity; - gl_FragColor = texColor; - #include - #include -}`,rp=`varying vec3 vWorldDirection; -#include -void main() { - vWorldDirection = transformDirection( position, modelMatrix ); - #include - #include - gl_Position.z = gl_Position.w; -}`,op=`#ifdef ENVMAP_TYPE_CUBE - uniform samplerCube envMap; -#elif defined( ENVMAP_TYPE_CUBE_UV ) - uniform sampler2D envMap; -#endif -uniform float flipEnvMap; -uniform float backgroundBlurriness; -uniform float backgroundIntensity; -varying vec3 vWorldDirection; -#include -void main() { - #ifdef ENVMAP_TYPE_CUBE - vec4 texColor = textureCube( envMap, vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) ); - #elif defined( ENVMAP_TYPE_CUBE_UV ) - vec4 texColor = textureCubeUV( envMap, vWorldDirection, backgroundBlurriness ); - #else - vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 ); - #endif - texColor.rgb *= backgroundIntensity; - gl_FragColor = texColor; - #include - #include -}`,ap=`varying vec3 vWorldDirection; -#include -void main() { - vWorldDirection = transformDirection( position, modelMatrix ); - #include - #include - gl_Position.z = gl_Position.w; -}`,cp=`uniform samplerCube tCube; -uniform float tFlip; -uniform float opacity; -varying vec3 vWorldDirection; -void main() { - vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) ); - gl_FragColor = texColor; - gl_FragColor.a *= opacity; - #include - #include -}`,lp=`#include -#include -#include -#include -#include -#include -#include -#include -varying vec2 vHighPrecisionZW; -void main() { - #include - #include - #include - #ifdef USE_DISPLACEMENTMAP - #include - #include - #include - #endif - #include - #include - #include - #include - #include - #include - #include - vHighPrecisionZW = gl_Position.zw; -}`,hp=`#if DEPTH_PACKING == 3200 - uniform float opacity; -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -varying vec2 vHighPrecisionZW; -void main() { - #include - vec4 diffuseColor = vec4( 1.0 ); - #if DEPTH_PACKING == 3200 - diffuseColor.a = opacity; - #endif - #include - #include - #include - #include - #include - float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5; - #if DEPTH_PACKING == 3200 - gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity ); - #elif DEPTH_PACKING == 3201 - gl_FragColor = packDepthToRGBA( fragCoordZ ); - #endif -}`,up=`#define DISTANCE -varying vec3 vWorldPosition; -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - #include - #include - #ifdef USE_DISPLACEMENTMAP - #include - #include - #include - #endif - #include - #include - #include - #include - #include - #include - #include - vWorldPosition = worldPosition.xyz; -}`,fp=`#define DISTANCE -uniform vec3 referencePosition; -uniform float nearDistance; -uniform float farDistance; -varying vec3 vWorldPosition; -#include -#include -#include -#include -#include -#include -#include -#include -void main () { - #include - vec4 diffuseColor = vec4( 1.0 ); - #include - #include - #include - #include - float dist = length( vWorldPosition - referencePosition ); - dist = ( dist - nearDistance ) / ( farDistance - nearDistance ); - dist = saturate( dist ); - gl_FragColor = packDepthToRGBA( dist ); -}`,dp=`varying vec3 vWorldDirection; -#include -void main() { - vWorldDirection = transformDirection( position, modelMatrix ); - #include - #include -}`,pp=`uniform sampler2D tEquirect; -varying vec3 vWorldDirection; -#include -void main() { - vec3 direction = normalize( vWorldDirection ); - vec2 sampleUV = equirectUv( direction ); - gl_FragColor = texture2D( tEquirect, sampleUV ); - #include - #include -}`,mp=`uniform float scale; -attribute float lineDistance; -varying float vLineDistance; -#include -#include -#include -#include -#include -#include -#include -void main() { - vLineDistance = scale * lineDistance; - #include - #include - #include - #include - #include - #include - #include - #include - #include -}`,_p=`uniform vec3 diffuse; -uniform float opacity; -uniform float dashSize; -uniform float totalSize; -varying float vLineDistance; -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - if ( mod( vLineDistance, totalSize ) > dashSize ) { - discard; - } - vec3 outgoingLight = vec3( 0.0 ); - vec4 diffuseColor = vec4( diffuse, opacity ); - #include - #include - #include - outgoingLight = diffuseColor.rgb; - #include - #include - #include - #include - #include -}`,gp=`#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - #include - #include - #include - #if defined ( USE_ENVMAP ) || defined ( USE_SKINNING ) - #include - #include - #include - #include - #include - #endif - #include - #include - #include - #include - #include - #include - #include - #include - #include -}`,xp=`uniform vec3 diffuse; -uniform float opacity; -#ifndef FLAT_SHADED - varying vec3 vNormal; -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - vec4 diffuseColor = vec4( diffuse, opacity ); - #include - #include - #include - #include - #include - #include - #include - ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); - #ifdef USE_LIGHTMAP - vec4 lightMapTexel = texture2D( lightMap, vLightMapUv ); - reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI; - #else - reflectedLight.indirectDiffuse += vec3( 1.0 ); - #endif - #include - reflectedLight.indirectDiffuse *= diffuseColor.rgb; - vec3 outgoingLight = reflectedLight.indirectDiffuse; - #include - #include - #include - #include - #include - #include - #include -}`,vp=`#define LAMBERT -varying vec3 vViewPosition; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - vViewPosition = - mvPosition.xyz; - #include - #include - #include - #include -}`,Ep=`#define LAMBERT -uniform vec3 diffuse; -uniform vec3 emissive; -uniform float opacity; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - vec4 diffuseColor = vec4( diffuse, opacity ); - ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); - vec3 totalEmissiveRadiance = emissive; - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance; - #include - #include - #include - #include - #include - #include - #include -}`,Mp=`#define MATCAP -varying vec3 vViewPosition; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - vViewPosition = - mvPosition.xyz; -}`,Sp=`#define MATCAP -uniform vec3 diffuse; -uniform float opacity; -uniform sampler2D matcap; -varying vec3 vViewPosition; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - vec4 diffuseColor = vec4( diffuse, opacity ); - #include - #include - #include - #include - #include - #include - #include - #include - vec3 viewDir = normalize( vViewPosition ); - vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) ); - vec3 y = cross( viewDir, x ); - vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5; - #ifdef USE_MATCAP - vec4 matcapColor = texture2D( matcap, uv ); - #else - vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 ); - #endif - vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb; - #include - #include - #include - #include - #include - #include -}`,yp=`#define NORMAL -#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) - varying vec3 vViewPosition; -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include -#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) - vViewPosition = - mvPosition.xyz; -#endif -}`,Tp=`#define NORMAL -uniform float opacity; -#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) - varying vec3 vViewPosition; -#endif -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - #include - #include - #include - gl_FragColor = vec4( packNormalToRGB( normal ), opacity ); - #ifdef OPAQUE - gl_FragColor.a = 1.0; - #endif -}`,Ap=`#define PHONG -varying vec3 vViewPosition; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - vViewPosition = - mvPosition.xyz; - #include - #include - #include - #include -}`,bp=`#define PHONG -uniform vec3 diffuse; -uniform vec3 emissive; -uniform vec3 specular; -uniform float shininess; -uniform float opacity; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - vec4 diffuseColor = vec4( diffuse, opacity ); - ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); - vec3 totalEmissiveRadiance = emissive; - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance; - #include - #include - #include - #include - #include - #include - #include -}`,wp=`#define STANDARD -varying vec3 vViewPosition; -#ifdef USE_TRANSMISSION - varying vec3 vWorldPosition; -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - vViewPosition = - mvPosition.xyz; - #include - #include - #include -#ifdef USE_TRANSMISSION - vWorldPosition = worldPosition.xyz; -#endif -}`,Cp=`#define STANDARD -#ifdef PHYSICAL - #define IOR - #define USE_SPECULAR -#endif -uniform vec3 diffuse; -uniform vec3 emissive; -uniform float roughness; -uniform float metalness; -uniform float opacity; -#ifdef IOR - uniform float ior; -#endif -#ifdef USE_SPECULAR - uniform float specularIntensity; - uniform vec3 specularColor; - #ifdef USE_SPECULAR_COLORMAP - uniform sampler2D specularColorMap; - #endif - #ifdef USE_SPECULAR_INTENSITYMAP - uniform sampler2D specularIntensityMap; - #endif -#endif -#ifdef USE_CLEARCOAT - uniform float clearcoat; - uniform float clearcoatRoughness; -#endif -#ifdef USE_IRIDESCENCE - uniform float iridescence; - uniform float iridescenceIOR; - uniform float iridescenceThicknessMinimum; - uniform float iridescenceThicknessMaximum; -#endif -#ifdef USE_SHEEN - uniform vec3 sheenColor; - uniform float sheenRoughness; - #ifdef USE_SHEEN_COLORMAP - uniform sampler2D sheenColorMap; - #endif - #ifdef USE_SHEEN_ROUGHNESSMAP - uniform sampler2D sheenRoughnessMap; - #endif -#endif -#ifdef USE_ANISOTROPY - uniform vec2 anisotropyVector; - #ifdef USE_ANISOTROPYMAP - uniform sampler2D anisotropyMap; - #endif -#endif -varying vec3 vViewPosition; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - vec4 diffuseColor = vec4( diffuse, opacity ); - ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); - vec3 totalEmissiveRadiance = emissive; - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse; - vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular; - #include - vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance; - #ifdef USE_SHEEN - float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor ); - outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect; - #endif - #ifdef USE_CLEARCOAT - float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) ); - vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc ); - outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat; - #endif - #include - #include - #include - #include - #include - #include -}`,Rp=`#define TOON -varying vec3 vViewPosition; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - vViewPosition = - mvPosition.xyz; - #include - #include - #include -}`,Pp=`#define TOON -uniform vec3 diffuse; -uniform vec3 emissive; -uniform float opacity; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - vec4 diffuseColor = vec4( diffuse, opacity ); - ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); - vec3 totalEmissiveRadiance = emissive; - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance; - #include - #include - #include - #include - #include - #include -}`,Lp=`uniform float size; -uniform float scale; -#include -#include -#include -#include -#include -#include -#ifdef USE_POINTS_UV - varying vec2 vUv; - uniform mat3 uvTransform; -#endif -void main() { - #ifdef USE_POINTS_UV - vUv = ( uvTransform * vec3( uv, 1 ) ).xy; - #endif - #include - #include - #include - #include - #include - gl_PointSize = size; - #ifdef USE_SIZEATTENUATION - bool isPerspective = isPerspectiveMatrix( projectionMatrix ); - if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z ); - #endif - #include - #include - #include - #include -}`,Up=`uniform vec3 diffuse; -uniform float opacity; -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - vec3 outgoingLight = vec3( 0.0 ); - vec4 diffuseColor = vec4( diffuse, opacity ); - #include - #include - #include - #include - #include - outgoingLight = diffuseColor.rgb; - #include - #include - #include - #include - #include -}`,Dp=`#include -#include -#include -#include -#include -#include -#include -void main() { - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include -}`,Ip=`uniform vec3 color; -uniform float opacity; -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) ); - #include - #include - #include -}`,Op=`uniform float rotation; -uniform vec2 center; -#include -#include -#include -#include -#include -void main() { - #include - vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 ); - vec2 scale; - scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) ); - scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) ); - #ifndef USE_SIZEATTENUATION - bool isPerspective = isPerspectiveMatrix( projectionMatrix ); - if ( isPerspective ) scale *= - mvPosition.z; - #endif - vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale; - vec2 rotatedPosition; - rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y; - rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y; - mvPosition.xy += rotatedPosition; - gl_Position = projectionMatrix * mvPosition; - #include - #include - #include -}`,Np=`uniform vec3 diffuse; -uniform float opacity; -#include -#include -#include -#include -#include -#include -#include -#include -#include -void main() { - #include - vec3 outgoingLight = vec3( 0.0 ); - vec4 diffuseColor = vec4( diffuse, opacity ); - #include - #include - #include - #include - #include - outgoingLight = diffuseColor.rgb; - #include - #include - #include - #include -}`,Nt={alphahash_fragment:sf,alphahash_pars_fragment:rf,alphamap_fragment:of,alphamap_pars_fragment:af,alphatest_fragment:cf,alphatest_pars_fragment:lf,aomap_fragment:hf,aomap_pars_fragment:uf,batching_pars_vertex:ff,batching_vertex:df,begin_vertex:pf,beginnormal_vertex:mf,bsdfs:_f,iridescence_fragment:gf,bumpmap_pars_fragment:xf,clipping_planes_fragment:vf,clipping_planes_pars_fragment:Ef,clipping_planes_pars_vertex:Mf,clipping_planes_vertex:Sf,color_fragment:yf,color_pars_fragment:Tf,color_pars_vertex:Af,color_vertex:bf,common:wf,cube_uv_reflection_fragment:Cf,defaultnormal_vertex:Rf,displacementmap_pars_vertex:Pf,displacementmap_vertex:Lf,emissivemap_fragment:Uf,emissivemap_pars_fragment:Df,colorspace_fragment:If,colorspace_pars_fragment:Of,envmap_fragment:Nf,envmap_common_pars_fragment:Ff,envmap_pars_fragment:Bf,envmap_pars_vertex:zf,envmap_physical_pars_fragment:jf,envmap_vertex:Hf,fog_vertex:Vf,fog_pars_vertex:Gf,fog_fragment:kf,fog_pars_fragment:Wf,gradientmap_pars_fragment:Xf,lightmap_fragment:Yf,lightmap_pars_fragment:qf,lights_lambert_fragment:Zf,lights_lambert_pars_fragment:Kf,lights_pars_begin:$f,lights_toon_fragment:Jf,lights_toon_pars_fragment:Qf,lights_phong_fragment:td,lights_phong_pars_fragment:ed,lights_physical_fragment:nd,lights_physical_pars_fragment:id,lights_fragment_begin:sd,lights_fragment_maps:rd,lights_fragment_end:od,logdepthbuf_fragment:ad,logdepthbuf_pars_fragment:cd,logdepthbuf_pars_vertex:ld,logdepthbuf_vertex:hd,map_fragment:ud,map_pars_fragment:fd,map_particle_fragment:dd,map_particle_pars_fragment:pd,metalnessmap_fragment:md,metalnessmap_pars_fragment:_d,morphcolor_vertex:gd,morphnormal_vertex:xd,morphtarget_pars_vertex:vd,morphtarget_vertex:Ed,normal_fragment_begin:Md,normal_fragment_maps:Sd,normal_pars_fragment:yd,normal_pars_vertex:Td,normal_vertex:Ad,normalmap_pars_fragment:bd,clearcoat_normal_fragment_begin:wd,clearcoat_normal_fragment_maps:Cd,clearcoat_pars_fragment:Rd,iridescence_pars_fragment:Pd,opaque_fragment:Ld,packing:Ud,premultiplied_alpha_fragment:Dd,project_vertex:Id,dithering_fragment:Od,dithering_pars_fragment:Nd,roughnessmap_fragment:Fd,roughnessmap_pars_fragment:Bd,shadowmap_pars_fragment:zd,shadowmap_pars_vertex:Hd,shadowmap_vertex:Vd,shadowmask_pars_fragment:Gd,skinbase_vertex:kd,skinning_pars_vertex:Wd,skinning_vertex:Xd,skinnormal_vertex:Yd,specularmap_fragment:qd,specularmap_pars_fragment:Zd,tonemapping_fragment:Kd,tonemapping_pars_fragment:$d,transmission_fragment:jd,transmission_pars_fragment:Jd,uv_pars_fragment:Qd,uv_pars_vertex:tp,uv_vertex:ep,worldpos_vertex:np,background_vert:ip,background_frag:sp,backgroundCube_vert:rp,backgroundCube_frag:op,cube_vert:ap,cube_frag:cp,depth_vert:lp,depth_frag:hp,distanceRGBA_vert:up,distanceRGBA_frag:fp,equirect_vert:dp,equirect_frag:pp,linedashed_vert:mp,linedashed_frag:_p,meshbasic_vert:gp,meshbasic_frag:xp,meshlambert_vert:vp,meshlambert_frag:Ep,meshmatcap_vert:Mp,meshmatcap_frag:Sp,meshnormal_vert:yp,meshnormal_frag:Tp,meshphong_vert:Ap,meshphong_frag:bp,meshphysical_vert:wp,meshphysical_frag:Cp,meshtoon_vert:Rp,meshtoon_frag:Pp,points_vert:Lp,points_frag:Up,shadow_vert:Dp,shadow_frag:Ip,sprite_vert:Op,sprite_frag:Np},st={common:{diffuse:{value:new qt(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new Gt},alphaMap:{value:null},alphaMapTransform:{value:new Gt},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new Gt}},envmap:{envMap:{value:null},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new Gt}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new Gt}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new Gt},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new Gt},normalScale:{value:new kt(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new Gt},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new Gt}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new Gt}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new Gt}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new qt(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new qt(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new Gt},alphaTest:{value:0},uvTransform:{value:new Gt}},sprite:{diffuse:{value:new qt(16777215)},opacity:{value:1},center:{value:new kt(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new Gt},alphaMap:{value:null},alphaMapTransform:{value:new Gt},alphaTest:{value:0}}},pn={basic:{uniforms:De([st.common,st.specularmap,st.envmap,st.aomap,st.lightmap,st.fog]),vertexShader:Nt.meshbasic_vert,fragmentShader:Nt.meshbasic_frag},lambert:{uniforms:De([st.common,st.specularmap,st.envmap,st.aomap,st.lightmap,st.emissivemap,st.bumpmap,st.normalmap,st.displacementmap,st.fog,st.lights,{emissive:{value:new qt(0)}}]),vertexShader:Nt.meshlambert_vert,fragmentShader:Nt.meshlambert_frag},phong:{uniforms:De([st.common,st.specularmap,st.envmap,st.aomap,st.lightmap,st.emissivemap,st.bumpmap,st.normalmap,st.displacementmap,st.fog,st.lights,{emissive:{value:new qt(0)},specular:{value:new qt(1118481)},shininess:{value:30}}]),vertexShader:Nt.meshphong_vert,fragmentShader:Nt.meshphong_frag},standard:{uniforms:De([st.common,st.envmap,st.aomap,st.lightmap,st.emissivemap,st.bumpmap,st.normalmap,st.displacementmap,st.roughnessmap,st.metalnessmap,st.fog,st.lights,{emissive:{value:new qt(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Nt.meshphysical_vert,fragmentShader:Nt.meshphysical_frag},toon:{uniforms:De([st.common,st.aomap,st.lightmap,st.emissivemap,st.bumpmap,st.normalmap,st.displacementmap,st.gradientmap,st.fog,st.lights,{emissive:{value:new qt(0)}}]),vertexShader:Nt.meshtoon_vert,fragmentShader:Nt.meshtoon_frag},matcap:{uniforms:De([st.common,st.bumpmap,st.normalmap,st.displacementmap,st.fog,{matcap:{value:null}}]),vertexShader:Nt.meshmatcap_vert,fragmentShader:Nt.meshmatcap_frag},points:{uniforms:De([st.points,st.fog]),vertexShader:Nt.points_vert,fragmentShader:Nt.points_frag},dashed:{uniforms:De([st.common,st.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Nt.linedashed_vert,fragmentShader:Nt.linedashed_frag},depth:{uniforms:De([st.common,st.displacementmap]),vertexShader:Nt.depth_vert,fragmentShader:Nt.depth_frag},normal:{uniforms:De([st.common,st.bumpmap,st.normalmap,st.displacementmap,{opacity:{value:1}}]),vertexShader:Nt.meshnormal_vert,fragmentShader:Nt.meshnormal_frag},sprite:{uniforms:De([st.sprite,st.fog]),vertexShader:Nt.sprite_vert,fragmentShader:Nt.sprite_frag},background:{uniforms:{uvTransform:{value:new Gt},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:Nt.background_vert,fragmentShader:Nt.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1}},vertexShader:Nt.backgroundCube_vert,fragmentShader:Nt.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:Nt.cube_vert,fragmentShader:Nt.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Nt.equirect_vert,fragmentShader:Nt.equirect_frag},distanceRGBA:{uniforms:De([st.common,st.displacementmap,{referencePosition:{value:new U},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Nt.distanceRGBA_vert,fragmentShader:Nt.distanceRGBA_frag},shadow:{uniforms:De([st.lights,st.fog,{color:{value:new qt(0)},opacity:{value:1}}]),vertexShader:Nt.shadow_vert,fragmentShader:Nt.shadow_frag}};pn.physical={uniforms:De([pn.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new Gt},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new Gt},clearcoatNormalScale:{value:new kt(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new Gt},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new Gt},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new Gt},sheen:{value:0},sheenColor:{value:new qt(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new Gt},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new Gt},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new Gt},transmissionSamplerSize:{value:new kt},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new Gt},attenuationDistance:{value:0},attenuationColor:{value:new qt(0)},specularColor:{value:new qt(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new Gt},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new Gt},anisotropyVector:{value:new kt},anisotropyMap:{value:null},anisotropyMapTransform:{value:new Gt}}]),vertexShader:Nt.meshphysical_vert,fragmentShader:Nt.meshphysical_frag};const js={r:0,b:0,g:0};function Fp(i,t,e,n,s,r,a){const o=new qt(0);let c=r===!0?0:1,l,h,f=null,u=0,m=null;function g(p,d){let M=!1,v=d.isScene===!0?d.background:null;v&&v.isTexture&&(v=(d.backgroundBlurriness>0?e:t).get(v)),v===null?x(o,c):v&&v.isColor&&(x(v,1),M=!0);const _=i.xr.getEnvironmentBlendMode();_==="additive"?n.buffers.color.setClear(0,0,0,1,a):_==="alpha-blend"&&n.buffers.color.setClear(0,0,0,0,a),(i.autoClear||M)&&i.clear(i.autoClearColor,i.autoClearDepth,i.autoClearStencil),v&&(v.isCubeTexture||v.mapping===Ir)?(h===void 0&&(h=new ln(new Ji(1,1,1),new ci({name:"BackgroundCubeMaterial",uniforms:Zi(pn.backgroundCube.uniforms),vertexShader:pn.backgroundCube.vertexShader,fragmentShader:pn.backgroundCube.fragmentShader,side:Oe,depthTest:!1,depthWrite:!1,fog:!1})),h.geometry.deleteAttribute("normal"),h.geometry.deleteAttribute("uv"),h.onBeforeRender=function(y,A,T){this.matrixWorld.copyPosition(T.matrixWorld)},Object.defineProperty(h.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),s.update(h)),h.material.uniforms.envMap.value=v,h.material.uniforms.flipEnvMap.value=v.isCubeTexture&&v.isRenderTargetTexture===!1?-1:1,h.material.uniforms.backgroundBlurriness.value=d.backgroundBlurriness,h.material.uniforms.backgroundIntensity.value=d.backgroundIntensity,h.material.toneMapped=jt.getTransfer(v.colorSpace)!==ie,(f!==v||u!==v.version||m!==i.toneMapping)&&(h.material.needsUpdate=!0,f=v,u=v.version,m=i.toneMapping),h.layers.enableAll(),p.unshift(h,h.geometry,h.material,0,0,null)):v&&v.isTexture&&(l===void 0&&(l=new ln(new fa(2,2),new ci({name:"BackgroundMaterial",uniforms:Zi(pn.background.uniforms),vertexShader:pn.background.vertexShader,fragmentShader:pn.background.fragmentShader,side:_n,depthTest:!1,depthWrite:!1,fog:!1})),l.geometry.deleteAttribute("normal"),Object.defineProperty(l.material,"map",{get:function(){return this.uniforms.t2D.value}}),s.update(l)),l.material.uniforms.t2D.value=v,l.material.uniforms.backgroundIntensity.value=d.backgroundIntensity,l.material.toneMapped=jt.getTransfer(v.colorSpace)!==ie,v.matrixAutoUpdate===!0&&v.updateMatrix(),l.material.uniforms.uvTransform.value.copy(v.matrix),(f!==v||u!==v.version||m!==i.toneMapping)&&(l.material.needsUpdate=!0,f=v,u=v.version,m=i.toneMapping),l.layers.enableAll(),p.unshift(l,l.geometry,l.material,0,0,null))}function x(p,d){p.getRGB(js,kl(i)),n.buffers.color.setClear(js.r,js.g,js.b,d,a)}return{getClearColor:function(){return o},setClearColor:function(p,d=1){o.set(p),c=d,x(o,c)},getClearAlpha:function(){return c},setClearAlpha:function(p){c=p,x(o,c)},render:g}}function Bp(i,t,e,n){const s=i.getParameter(i.MAX_VERTEX_ATTRIBS),r=n.isWebGL2?null:t.get("OES_vertex_array_object"),a=n.isWebGL2||r!==null,o={},c=p(null);let l=c,h=!1;function f(R,O,F,Y,q){let Z=!1;if(a){const K=x(Y,F,O);l!==K&&(l=K,m(l.object)),Z=d(R,Y,F,q),Z&&M(R,Y,F,q)}else{const K=O.wireframe===!0;(l.geometry!==Y.id||l.program!==F.id||l.wireframe!==K)&&(l.geometry=Y.id,l.program=F.id,l.wireframe=K,Z=!0)}q!==null&&e.update(q,i.ELEMENT_ARRAY_BUFFER),(Z||h)&&(h=!1,P(R,O,F,Y),q!==null&&i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,e.get(q).buffer))}function u(){return n.isWebGL2?i.createVertexArray():r.createVertexArrayOES()}function m(R){return n.isWebGL2?i.bindVertexArray(R):r.bindVertexArrayOES(R)}function g(R){return n.isWebGL2?i.deleteVertexArray(R):r.deleteVertexArrayOES(R)}function x(R,O,F){const Y=F.wireframe===!0;let q=o[R.id];q===void 0&&(q={},o[R.id]=q);let Z=q[O.id];Z===void 0&&(Z={},q[O.id]=Z);let K=Z[Y];return K===void 0&&(K=p(u()),Z[Y]=K),K}function p(R){const O=[],F=[],Y=[];for(let q=0;q=0){const $=q[nt];let ct=Z[nt];if(ct===void 0&&(nt==="instanceMatrix"&&R.instanceMatrix&&(ct=R.instanceMatrix),nt==="instanceColor"&&R.instanceColor&&(ct=R.instanceColor)),$===void 0||$.attribute!==ct||ct&&$.data!==ct.data)return!0;K++}return l.attributesNum!==K||l.index!==Y}function M(R,O,F,Y){const q={},Z=O.attributes;let K=0;const et=F.getAttributes();for(const nt in et)if(et[nt].location>=0){let $=Z[nt];$===void 0&&(nt==="instanceMatrix"&&R.instanceMatrix&&($=R.instanceMatrix),nt==="instanceColor"&&R.instanceColor&&($=R.instanceColor));const ct={};ct.attribute=$,$&&$.data&&(ct.data=$.data),q[nt]=ct,K++}l.attributes=q,l.attributesNum=K,l.index=Y}function v(){const R=l.newAttributes;for(let O=0,F=R.length;O=0){let X=q[et];if(X===void 0&&(et==="instanceMatrix"&&R.instanceMatrix&&(X=R.instanceMatrix),et==="instanceColor"&&R.instanceColor&&(X=R.instanceColor)),X!==void 0){const $=X.normalized,ct=X.itemSize,gt=e.get(X);if(gt===void 0)continue;const _t=gt.buffer,Lt=gt.type,It=gt.bytesPerElement,At=n.isWebGL2===!0&&(Lt===i.INT||Lt===i.UNSIGNED_INT||X.gpuType===bl);if(X.isInterleavedBufferAttribute){const Xt=X.data,z=Xt.stride,Re=X.offset;if(Xt.isInstancedInterleavedBuffer){for(let vt=0;vt0&&i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.HIGH_FLOAT).precision>0)return"highp";T="mediump"}return T==="mediump"&&i.getShaderPrecisionFormat(i.VERTEX_SHADER,i.MEDIUM_FLOAT).precision>0&&i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}const a=typeof WebGL2RenderingContext<"u"&&i.constructor.name==="WebGL2RenderingContext";let o=e.precision!==void 0?e.precision:"highp";const c=r(o);c!==o&&(console.warn("THREE.WebGLRenderer:",o,"not supported, using",c,"instead."),o=c);const l=a||t.has("WEBGL_draw_buffers"),h=e.logarithmicDepthBuffer===!0,f=i.getParameter(i.MAX_TEXTURE_IMAGE_UNITS),u=i.getParameter(i.MAX_VERTEX_TEXTURE_IMAGE_UNITS),m=i.getParameter(i.MAX_TEXTURE_SIZE),g=i.getParameter(i.MAX_CUBE_MAP_TEXTURE_SIZE),x=i.getParameter(i.MAX_VERTEX_ATTRIBS),p=i.getParameter(i.MAX_VERTEX_UNIFORM_VECTORS),d=i.getParameter(i.MAX_VARYING_VECTORS),M=i.getParameter(i.MAX_FRAGMENT_UNIFORM_VECTORS),v=u>0,_=a||t.has("OES_texture_float"),y=v&&_,A=a?i.getParameter(i.MAX_SAMPLES):0;return{isWebGL2:a,drawBuffers:l,getMaxAnisotropy:s,getMaxPrecision:r,precision:o,logarithmicDepthBuffer:h,maxTextures:f,maxVertexTextures:u,maxTextureSize:m,maxCubemapSize:g,maxAttributes:x,maxVertexUniforms:p,maxVaryings:d,maxFragmentUniforms:M,vertexTextures:v,floatFragmentTextures:_,floatVertexTextures:y,maxSamples:A}}function Vp(i){const t=this;let e=null,n=0,s=!1,r=!1;const a=new An,o=new Gt,c={value:null,needsUpdate:!1};this.uniform=c,this.numPlanes=0,this.numIntersection=0,this.init=function(f,u){const m=f.length!==0||u||n!==0||s;return s=u,n=f.length,m},this.beginShadows=function(){r=!0,h(null)},this.endShadows=function(){r=!1},this.setGlobalState=function(f,u){e=h(f,u,0)},this.setState=function(f,u,m){const g=f.clippingPlanes,x=f.clipIntersection,p=f.clipShadows,d=i.get(f);if(!s||g===null||g.length===0||r&&!p)r?h(null):l();else{const M=r?0:n,v=M*4;let _=d.clippingState||null;c.value=_,_=h(g,u,v,m);for(let y=0;y!==v;++y)_[y]=e[y];d.clippingState=_,this.numIntersection=x?this.numPlanes:0,this.numPlanes+=M}};function l(){c.value!==e&&(c.value=e,c.needsUpdate=n>0),t.numPlanes=n,t.numIntersection=0}function h(f,u,m,g){const x=f!==null?f.length:0;let p=null;if(x!==0){if(p=c.value,g!==!0||p===null){const d=m+x*4,M=u.matrixWorldInverse;o.getNormalMatrix(M),(p===null||p.length0){const l=new Qu(c.height/2);return l.fromEquirectangularTexture(i,a),t.set(a,l),a.addEventListener("dispose",s),e(l.texture,a.mapping)}else return null}}return a}function s(a){const o=a.target;o.removeEventListener("dispose",s);const c=t.get(o);c!==void 0&&(t.delete(o),c.dispose())}function r(){t=new WeakMap}return{get:n,dispose:r}}class ql extends Wl{constructor(t=-1,e=1,n=1,s=-1,r=.1,a=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=n,this.bottom=s,this.near=r,this.far=a,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom,this.near=t.near,this.far=t.far,this.zoom=t.zoom,this.view=t.view===null?null:Object.assign({},t.view),this}setViewOffset(t,e,n,s,r,a){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=n,this.view.offsetY=s,this.view.width=r,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=(this.right-this.left)/(2*this.zoom),e=(this.top-this.bottom)/(2*this.zoom),n=(this.right+this.left)/2,s=(this.top+this.bottom)/2;let r=n-t,a=n+t,o=s+e,c=s-e;if(this.view!==null&&this.view.enabled){const l=(this.right-this.left)/this.view.fullWidth/this.zoom,h=(this.top-this.bottom)/this.view.fullHeight/this.zoom;r+=l*this.view.offsetX,a=r+l*this.view.width,o-=h*this.view.offsetY,c=o-h*this.view.height}this.projectionMatrix.makeOrthographic(r,a,o,c,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,this.view!==null&&(e.object.view=Object.assign({},this.view)),e}}const Hi=4,Tc=[.125,.215,.35,.446,.526,.582],ni=20,mo=new ql,Ac=new qt;let _o=null,go=0,xo=0;const ti=(1+Math.sqrt(5))/2,Ti=1/ti,bc=[new U(1,1,1),new U(-1,1,1),new U(1,1,-1),new U(-1,1,-1),new U(0,ti,Ti),new U(0,ti,-Ti),new U(Ti,0,ti),new U(-Ti,0,ti),new U(ti,Ti,0),new U(-ti,Ti,0)];class wc{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._compileMaterial(this._blurMaterial)}fromScene(t,e=0,n=.1,s=100){_o=this._renderer.getRenderTarget(),go=this._renderer.getActiveCubeFace(),xo=this._renderer.getActiveMipmapLevel(),this._setSize(256);const r=this._allocateTargets();return r.depthBuffer=!0,this._sceneToCubeUV(t,n,s,r),e>0&&this._blur(r,0,0,e),this._applyPMREM(r),this._cleanup(r),r}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=Pc(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=Rc(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose()}_setSize(t){this._lodMax=Math.floor(Math.log2(t)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let t=0;t2?v:0,v,v),h.setRenderTarget(s),x&&h.render(g,o),h.render(t,o)}g.geometry.dispose(),g.material.dispose(),h.toneMapping=u,h.autoClear=f,t.background=p}_textureToCubeUV(t,e){const n=this._renderer,s=t.mapping===Xi||t.mapping===Yi;s?(this._cubemapMaterial===null&&(this._cubemapMaterial=Pc()),this._cubemapMaterial.uniforms.flipEnvMap.value=t.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=Rc());const r=s?this._cubemapMaterial:this._equirectMaterial,a=new ln(this._lodPlanes[0],r),o=r.uniforms;o.envMap.value=t;const c=this._cubeSize;Js(e,0,0,3*c,2*c),n.setRenderTarget(e),n.render(a,mo)}_applyPMREM(t){const e=this._renderer,n=e.autoClear;e.autoClear=!1;for(let s=1;sni&&console.warn(`sigmaRadians, ${r}, is too large and will clip, as it requested ${p} samples when the maximum is set to ${ni}`);const d=[];let M=0;for(let T=0;Tv-Hi?s-v+Hi:0),A=4*(this._cubeSize-_);Js(e,y,A,3*_,2*_),c.setRenderTarget(e),c.render(f,mo)}}function kp(i){const t=[],e=[],n=[];let s=i;const r=i-Hi+1+Tc.length;for(let a=0;ai-Hi?c=Tc[a-i+Hi-1]:a===0&&(c=0),n.push(c);const l=1/(o-2),h=-l,f=1+l,u=[h,h,f,h,f,f,h,h,f,f,h,f],m=6,g=6,x=3,p=2,d=1,M=new Float32Array(x*g*m),v=new Float32Array(p*g*m),_=new Float32Array(d*g*m);for(let A=0;A2?0:-1,E=[T,P,0,T+2/3,P,0,T+2/3,P+1,0,T,P,0,T+2/3,P+1,0,T,P+1,0];M.set(E,x*g*A),v.set(u,p*g*A);const S=[A,A,A,A,A,A];_.set(S,d*g*A)}const y=new Rn;y.setAttribute("position",new tn(M,x)),y.setAttribute("uv",new tn(v,p)),y.setAttribute("faceIndex",new tn(_,d)),t.push(y),s>Hi&&s--}return{lodPlanes:t,sizeLods:e,sigmas:n}}function Cc(i,t,e){const n=new ai(i,t,e);return n.texture.mapping=Ir,n.texture.name="PMREM.cubeUv",n.scissorTest=!0,n}function Js(i,t,e,n,s){i.viewport.set(t,e,n,s),i.scissor.set(t,e,n,s)}function Wp(i,t,e){const n=new Float32Array(ni),s=new U(0,1,0);return new ci({name:"SphericalGaussianBlur",defines:{n:ni,CUBEUV_TEXEL_WIDTH:1/t,CUBEUV_TEXEL_HEIGHT:1/e,CUBEUV_MAX_MIP:`${i}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:n},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:s}},vertexShader:da(),fragmentShader:` - - precision mediump float; - precision mediump int; - - varying vec3 vOutputDirection; - - uniform sampler2D envMap; - uniform int samples; - uniform float weights[ n ]; - uniform bool latitudinal; - uniform float dTheta; - uniform float mipInt; - uniform vec3 poleAxis; - - #define ENVMAP_TYPE_CUBE_UV - #include - - vec3 getSample( float theta, vec3 axis ) { - - float cosTheta = cos( theta ); - // Rodrigues' axis-angle rotation - vec3 sampleDirection = vOutputDirection * cosTheta - + cross( axis, vOutputDirection ) * sin( theta ) - + axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta ); - - return bilinearCubeUV( envMap, sampleDirection, mipInt ); - - } - - void main() { - - vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection ); - - if ( all( equal( axis, vec3( 0.0 ) ) ) ) { - - axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x ); - - } - - axis = normalize( axis ); - - gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 ); - gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis ); - - for ( int i = 1; i < n; i++ ) { - - if ( i >= samples ) { - - break; - - } - - float theta = dTheta * float( i ); - gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis ); - gl_FragColor.rgb += weights[ i ] * getSample( theta, axis ); - - } - - } - `,blending:Gn,depthTest:!1,depthWrite:!1})}function Rc(){return new ci({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:da(),fragmentShader:` - - precision mediump float; - precision mediump int; - - varying vec3 vOutputDirection; - - uniform sampler2D envMap; - - #include - - void main() { - - vec3 outputDirection = normalize( vOutputDirection ); - vec2 uv = equirectUv( outputDirection ); - - gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 ); - - } - `,blending:Gn,depthTest:!1,depthWrite:!1})}function Pc(){return new ci({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:da(),fragmentShader:` - - precision mediump float; - precision mediump int; - - uniform float flipEnvMap; - - varying vec3 vOutputDirection; - - uniform samplerCube envMap; - - void main() { - - gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) ); - - } - `,blending:Gn,depthTest:!1,depthWrite:!1})}function da(){return` - - precision mediump float; - precision mediump int; - - attribute float faceIndex; - - varying vec3 vOutputDirection; - - // RH coordinate system; PMREM face-indexing convention - vec3 getDirection( vec2 uv, float face ) { - - uv = 2.0 * uv - 1.0; - - vec3 direction = vec3( uv, 1.0 ); - - if ( face == 0.0 ) { - - direction = direction.zyx; // ( 1, v, u ) pos x - - } else if ( face == 1.0 ) { - - direction = direction.xzy; - direction.xz *= -1.0; // ( -u, 1, -v ) pos y - - } else if ( face == 2.0 ) { - - direction.x *= -1.0; // ( -u, v, 1 ) pos z - - } else if ( face == 3.0 ) { - - direction = direction.zyx; - direction.xz *= -1.0; // ( -1, v, -u ) neg x - - } else if ( face == 4.0 ) { - - direction = direction.xzy; - direction.xy *= -1.0; // ( -u, -1, v ) neg y - - } else if ( face == 5.0 ) { - - direction.z *= -1.0; // ( u, v, -1 ) neg z - - } - - return direction; - - } - - void main() { - - vOutputDirection = getDirection( uv, faceIndex ); - gl_Position = vec4( position, 1.0 ); - - } - `}function Xp(i){let t=new WeakMap,e=null;function n(o){if(o&&o.isTexture){const c=o.mapping,l=c===Vo||c===Go,h=c===Xi||c===Yi;if(l||h)if(o.isRenderTargetTexture&&o.needsPMREMUpdate===!0){o.needsPMREMUpdate=!1;let f=t.get(o);return e===null&&(e=new wc(i)),f=l?e.fromEquirectangular(o,f):e.fromCubemap(o,f),t.set(o,f),f.texture}else{if(t.has(o))return t.get(o).texture;{const f=o.image;if(l&&f&&f.height>0||h&&f&&s(f)){e===null&&(e=new wc(i));const u=l?e.fromEquirectangular(o):e.fromCubemap(o);return t.set(o,u),o.addEventListener("dispose",r),u.texture}else return null}}}return o}function s(o){let c=0;const l=6;for(let h=0;ht.maxTextureSize&&(D=Math.ceil(S/t.maxTextureSize),S=t.maxTextureSize);const I=new Float32Array(S*D*4*x),B=new Bl(I,S,D,x);B.type=Hn,B.needsUpdate=!0;const R=E*4;for(let F=0;F0)return i;const s=t*e;let r=Lc[s];if(r===void 0&&(r=new Float32Array(s),Lc[s]=r),t!==0){n.toArray(r,0);for(let a=1,o=0;a!==t;++a)o+=e,i[a].toArray(r,o)}return r}function _e(i,t){if(i.length!==t.length)return!1;for(let e=0,n=i.length;e":" "} ${o}: ${e[a]}`)}return n.join(` -`)}function qm(i){const t=jt.getPrimaries(jt.workingColorSpace),e=jt.getPrimaries(i);let n;switch(t===e?n="":t===Ar&&e===Tr?n="LinearDisplayP3ToLinearSRGB":t===Tr&&e===Ar&&(n="LinearSRGBToLinearDisplayP3"),i){case Cn:case Or:return[n,"LinearTransferOETF"];case Me:case aa:return[n,"sRGBTransferOETF"];default:return console.warn("THREE.WebGLProgram: Unsupported color space:",i),[n,"LinearTransferOETF"]}}function Bc(i,t,e){const n=i.getShaderParameter(t,i.COMPILE_STATUS),s=i.getShaderInfoLog(t).trim();if(n&&s==="")return"";const r=/ERROR: 0:(\d+)/.exec(s);if(r){const a=parseInt(r[1]);return e.toUpperCase()+` - -`+s+` - -`+Ym(i.getShaderSource(t),a)}else return s}function Zm(i,t){const e=qm(t);return`vec4 ${i}( vec4 value ) { return ${e[0]}( ${e[1]}( value ) ); }`}function Km(i,t){let e;switch(t){case Wh:e="Linear";break;case Xh:e="Reinhard";break;case Yh:e="OptimizedCineon";break;case qh:e="ACESFilmic";break;case Kh:e="AgX";break;case Zh:e="Custom";break;default:console.warn("THREE.WebGLProgram: Unsupported toneMapping:",t),e="Linear"}return"vec3 "+i+"( vec3 color ) { return "+e+"ToneMapping( color ); }"}function $m(i){return[i.extensionDerivatives||i.envMapCubeUVHeight||i.bumpMap||i.normalMapTangentSpace||i.clearcoatNormalMap||i.flatShading||i.shaderID==="physical"?"#extension GL_OES_standard_derivatives : enable":"",(i.extensionFragDepth||i.logarithmicDepthBuffer)&&i.rendererExtensionFragDepth?"#extension GL_EXT_frag_depth : enable":"",i.extensionDrawBuffers&&i.rendererExtensionDrawBuffers?"#extension GL_EXT_draw_buffers : require":"",(i.extensionShaderTextureLOD||i.envMap||i.transmission)&&i.rendererExtensionShaderTextureLod?"#extension GL_EXT_shader_texture_lod : enable":""].filter(Vi).join(` -`)}function jm(i){return[i.extensionClipCullDistance?"#extension GL_ANGLE_clip_cull_distance : require":""].filter(Vi).join(` -`)}function Jm(i){const t=[];for(const e in i){const n=i[e];n!==!1&&t.push("#define "+e+" "+n)}return t.join(` -`)}function Qm(i,t){const e={},n=i.getProgramParameter(t,i.ACTIVE_ATTRIBUTES);for(let s=0;s/gm;function qo(i){return i.replace(t_,n_)}const e_=new Map([["encodings_fragment","colorspace_fragment"],["encodings_pars_fragment","colorspace_pars_fragment"],["output_fragment","opaque_fragment"]]);function n_(i,t){let e=Nt[t];if(e===void 0){const n=e_.get(t);if(n!==void 0)e=Nt[n],console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',t,n);else throw new Error("Can not resolve #include <"+t+">")}return qo(e)}const i_=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function Vc(i){return i.replace(i_,s_)}function s_(i,t,e,n){let s="";for(let r=parseInt(t);r0&&(d+=` -`),M=[m,"#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,x].filter(Vi).join(` -`),M.length>0&&(M+=` -`)):(d=[Gc(e),"#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,x,e.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",e.batching?"#define USE_BATCHING":"",e.instancing?"#define USE_INSTANCING":"",e.instancingColor?"#define USE_INSTANCING_COLOR":"",e.useFog&&e.fog?"#define USE_FOG":"",e.useFog&&e.fogExp2?"#define FOG_EXP2":"",e.map?"#define USE_MAP":"",e.envMap?"#define USE_ENVMAP":"",e.envMap?"#define "+h:"",e.lightMap?"#define USE_LIGHTMAP":"",e.aoMap?"#define USE_AOMAP":"",e.bumpMap?"#define USE_BUMPMAP":"",e.normalMap?"#define USE_NORMALMAP":"",e.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",e.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",e.displacementMap?"#define USE_DISPLACEMENTMAP":"",e.emissiveMap?"#define USE_EMISSIVEMAP":"",e.anisotropy?"#define USE_ANISOTROPY":"",e.anisotropyMap?"#define USE_ANISOTROPYMAP":"",e.clearcoatMap?"#define USE_CLEARCOATMAP":"",e.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",e.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",e.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",e.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",e.specularMap?"#define USE_SPECULARMAP":"",e.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",e.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",e.roughnessMap?"#define USE_ROUGHNESSMAP":"",e.metalnessMap?"#define USE_METALNESSMAP":"",e.alphaMap?"#define USE_ALPHAMAP":"",e.alphaHash?"#define USE_ALPHAHASH":"",e.transmission?"#define USE_TRANSMISSION":"",e.transmissionMap?"#define USE_TRANSMISSIONMAP":"",e.thicknessMap?"#define USE_THICKNESSMAP":"",e.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",e.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",e.mapUv?"#define MAP_UV "+e.mapUv:"",e.alphaMapUv?"#define ALPHAMAP_UV "+e.alphaMapUv:"",e.lightMapUv?"#define LIGHTMAP_UV "+e.lightMapUv:"",e.aoMapUv?"#define AOMAP_UV "+e.aoMapUv:"",e.emissiveMapUv?"#define EMISSIVEMAP_UV "+e.emissiveMapUv:"",e.bumpMapUv?"#define BUMPMAP_UV "+e.bumpMapUv:"",e.normalMapUv?"#define NORMALMAP_UV "+e.normalMapUv:"",e.displacementMapUv?"#define DISPLACEMENTMAP_UV "+e.displacementMapUv:"",e.metalnessMapUv?"#define METALNESSMAP_UV "+e.metalnessMapUv:"",e.roughnessMapUv?"#define ROUGHNESSMAP_UV "+e.roughnessMapUv:"",e.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+e.anisotropyMapUv:"",e.clearcoatMapUv?"#define CLEARCOATMAP_UV "+e.clearcoatMapUv:"",e.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+e.clearcoatNormalMapUv:"",e.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+e.clearcoatRoughnessMapUv:"",e.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+e.iridescenceMapUv:"",e.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+e.iridescenceThicknessMapUv:"",e.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+e.sheenColorMapUv:"",e.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+e.sheenRoughnessMapUv:"",e.specularMapUv?"#define SPECULARMAP_UV "+e.specularMapUv:"",e.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+e.specularColorMapUv:"",e.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+e.specularIntensityMapUv:"",e.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+e.transmissionMapUv:"",e.thicknessMapUv?"#define THICKNESSMAP_UV "+e.thicknessMapUv:"",e.vertexTangents&&e.flatShading===!1?"#define USE_TANGENT":"",e.vertexColors?"#define USE_COLOR":"",e.vertexAlphas?"#define USE_COLOR_ALPHA":"",e.vertexUv1s?"#define USE_UV1":"",e.vertexUv2s?"#define USE_UV2":"",e.vertexUv3s?"#define USE_UV3":"",e.pointsUvs?"#define USE_POINTS_UV":"",e.flatShading?"#define FLAT_SHADED":"",e.skinning?"#define USE_SKINNING":"",e.morphTargets?"#define USE_MORPHTARGETS":"",e.morphNormals&&e.flatShading===!1?"#define USE_MORPHNORMALS":"",e.morphColors&&e.isWebGL2?"#define USE_MORPHCOLORS":"",e.morphTargetsCount>0&&e.isWebGL2?"#define MORPHTARGETS_TEXTURE":"",e.morphTargetsCount>0&&e.isWebGL2?"#define MORPHTARGETS_TEXTURE_STRIDE "+e.morphTextureStride:"",e.morphTargetsCount>0&&e.isWebGL2?"#define MORPHTARGETS_COUNT "+e.morphTargetsCount:"",e.doubleSided?"#define DOUBLE_SIDED":"",e.flipSided?"#define FLIP_SIDED":"",e.shadowMapEnabled?"#define USE_SHADOWMAP":"",e.shadowMapEnabled?"#define "+c:"",e.sizeAttenuation?"#define USE_SIZEATTENUATION":"",e.numLightProbes>0?"#define USE_LIGHT_PROBES":"",e.useLegacyLights?"#define LEGACY_LIGHTS":"",e.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",e.logarithmicDepthBuffer&&e.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING"," attribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR"," attribute vec3 instanceColor;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1"," attribute vec2 uv1;","#endif","#ifdef USE_UV2"," attribute vec2 uv2;","#endif","#ifdef USE_UV3"," attribute vec2 uv3;","#endif","#ifdef USE_TANGENT"," attribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )"," attribute vec4 color;","#elif defined( USE_COLOR )"," attribute vec3 color;","#endif","#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )"," attribute vec3 morphTarget0;"," attribute vec3 morphTarget1;"," attribute vec3 morphTarget2;"," attribute vec3 morphTarget3;"," #ifdef USE_MORPHNORMALS"," attribute vec3 morphNormal0;"," attribute vec3 morphNormal1;"," attribute vec3 morphNormal2;"," attribute vec3 morphNormal3;"," #else"," attribute vec3 morphTarget4;"," attribute vec3 morphTarget5;"," attribute vec3 morphTarget6;"," attribute vec3 morphTarget7;"," #endif","#endif","#ifdef USE_SKINNING"," attribute vec4 skinIndex;"," attribute vec4 skinWeight;","#endif",` -`].filter(Vi).join(` -`),M=[m,Gc(e),"#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,x,e.useFog&&e.fog?"#define USE_FOG":"",e.useFog&&e.fogExp2?"#define FOG_EXP2":"",e.map?"#define USE_MAP":"",e.matcap?"#define USE_MATCAP":"",e.envMap?"#define USE_ENVMAP":"",e.envMap?"#define "+l:"",e.envMap?"#define "+h:"",e.envMap?"#define "+f:"",u?"#define CUBEUV_TEXEL_WIDTH "+u.texelWidth:"",u?"#define CUBEUV_TEXEL_HEIGHT "+u.texelHeight:"",u?"#define CUBEUV_MAX_MIP "+u.maxMip+".0":"",e.lightMap?"#define USE_LIGHTMAP":"",e.aoMap?"#define USE_AOMAP":"",e.bumpMap?"#define USE_BUMPMAP":"",e.normalMap?"#define USE_NORMALMAP":"",e.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",e.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",e.emissiveMap?"#define USE_EMISSIVEMAP":"",e.anisotropy?"#define USE_ANISOTROPY":"",e.anisotropyMap?"#define USE_ANISOTROPYMAP":"",e.clearcoat?"#define USE_CLEARCOAT":"",e.clearcoatMap?"#define USE_CLEARCOATMAP":"",e.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",e.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",e.iridescence?"#define USE_IRIDESCENCE":"",e.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",e.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",e.specularMap?"#define USE_SPECULARMAP":"",e.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",e.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",e.roughnessMap?"#define USE_ROUGHNESSMAP":"",e.metalnessMap?"#define USE_METALNESSMAP":"",e.alphaMap?"#define USE_ALPHAMAP":"",e.alphaTest?"#define USE_ALPHATEST":"",e.alphaHash?"#define USE_ALPHAHASH":"",e.sheen?"#define USE_SHEEN":"",e.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",e.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",e.transmission?"#define USE_TRANSMISSION":"",e.transmissionMap?"#define USE_TRANSMISSIONMAP":"",e.thicknessMap?"#define USE_THICKNESSMAP":"",e.vertexTangents&&e.flatShading===!1?"#define USE_TANGENT":"",e.vertexColors||e.instancingColor?"#define USE_COLOR":"",e.vertexAlphas?"#define USE_COLOR_ALPHA":"",e.vertexUv1s?"#define USE_UV1":"",e.vertexUv2s?"#define USE_UV2":"",e.vertexUv3s?"#define USE_UV3":"",e.pointsUvs?"#define USE_POINTS_UV":"",e.gradientMap?"#define USE_GRADIENTMAP":"",e.flatShading?"#define FLAT_SHADED":"",e.doubleSided?"#define DOUBLE_SIDED":"",e.flipSided?"#define FLIP_SIDED":"",e.shadowMapEnabled?"#define USE_SHADOWMAP":"",e.shadowMapEnabled?"#define "+c:"",e.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",e.numLightProbes>0?"#define USE_LIGHT_PROBES":"",e.useLegacyLights?"#define LEGACY_LIGHTS":"",e.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",e.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",e.logarithmicDepthBuffer&&e.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",e.toneMapping!==kn?"#define TONE_MAPPING":"",e.toneMapping!==kn?Nt.tonemapping_pars_fragment:"",e.toneMapping!==kn?Km("toneMapping",e.toneMapping):"",e.dithering?"#define DITHERING":"",e.opaque?"#define OPAQUE":"",Nt.colorspace_pars_fragment,Zm("linearToOutputTexel",e.outputColorSpace),e.useDepthPacking?"#define DEPTH_PACKING "+e.depthPacking:"",` -`].filter(Vi).join(` -`)),a=qo(a),a=zc(a,e),a=Hc(a,e),o=qo(o),o=zc(o,e),o=Hc(o,e),a=Vc(a),o=Vc(o),e.isWebGL2&&e.isRawShaderMaterial!==!0&&(v=`#version 300 es -`,d=[g,"precision mediump sampler2DArray;","#define attribute in","#define varying out","#define texture2D texture"].join(` -`)+` -`+d,M=["precision mediump sampler2DArray;","#define varying in",e.glslVersion===oc?"":"layout(location = 0) out highp vec4 pc_fragColor;",e.glslVersion===oc?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join(` -`)+` -`+M);const _=v+d+a,y=v+M+o,A=Fc(s,s.VERTEX_SHADER,_),T=Fc(s,s.FRAGMENT_SHADER,y);s.attachShader(p,A),s.attachShader(p,T),e.index0AttributeName!==void 0?s.bindAttribLocation(p,0,e.index0AttributeName):e.morphTargets===!0&&s.bindAttribLocation(p,0,"position"),s.linkProgram(p);function P(I){if(i.debug.checkShaderErrors){const B=s.getProgramInfoLog(p).trim(),R=s.getShaderInfoLog(A).trim(),O=s.getShaderInfoLog(T).trim();let F=!0,Y=!0;if(s.getProgramParameter(p,s.LINK_STATUS)===!1)if(F=!1,typeof i.debug.onShaderError=="function")i.debug.onShaderError(s,p,A,T);else{const q=Bc(s,A,"vertex"),Z=Bc(s,T,"fragment");console.error("THREE.WebGLProgram: Shader Error "+s.getError()+" - VALIDATE_STATUS "+s.getProgramParameter(p,s.VALIDATE_STATUS)+` - -Program Info Log: `+B+` -`+q+` -`+Z)}else B!==""?console.warn("THREE.WebGLProgram: Program Info Log:",B):(R===""||O==="")&&(Y=!1);Y&&(I.diagnostics={runnable:F,programLog:B,vertexShader:{log:R,prefix:d},fragmentShader:{log:O,prefix:M}})}s.deleteShader(A),s.deleteShader(T),E=new Er(s,p),S=Qm(s,p)}let E;this.getUniforms=function(){return E===void 0&&P(this),E};let S;this.getAttributes=function(){return S===void 0&&P(this),S};let D=e.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return D===!1&&(D=s.getProgramParameter(p,Wm)),D},this.destroy=function(){n.releaseStatesOfProgram(this),s.deleteProgram(p),this.program=void 0},this.type=e.shaderType,this.name=e.shaderName,this.id=Xm++,this.cacheKey=t,this.usedTimes=1,this.program=p,this.vertexShader=A,this.fragmentShader=T,this}let u_=0;class f_{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(t){const e=t.vertexShader,n=t.fragmentShader,s=this._getShaderStage(e),r=this._getShaderStage(n),a=this._getShaderCacheForMaterial(t);return a.has(s)===!1&&(a.add(s),s.usedTimes++),a.has(r)===!1&&(a.add(r),r.usedTimes++),this}remove(t){const e=this.materialCache.get(t);for(const n of e)n.usedTimes--,n.usedTimes===0&&this.shaderCache.delete(n.code);return this.materialCache.delete(t),this}getVertexShaderID(t){return this._getShaderStage(t.vertexShader).id}getFragmentShaderID(t){return this._getShaderStage(t.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(t){const e=this.materialCache;let n=e.get(t);return n===void 0&&(n=new Set,e.set(t,n)),n}_getShaderStage(t){const e=this.shaderCache;let n=e.get(t);return n===void 0&&(n=new d_(t),e.set(t,n)),n}}class d_{constructor(t){this.id=u_++,this.code=t,this.usedTimes=0}}function p_(i,t,e,n,s,r,a){const o=new ha,c=new f_,l=[],h=s.isWebGL2,f=s.logarithmicDepthBuffer,u=s.vertexTextures;let m=s.precision;const g={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distanceRGBA",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function x(E){return E===0?"uv":`uv${E}`}function p(E,S,D,I,B){const R=I.fog,O=B.geometry,F=E.isMeshStandardMaterial?I.environment:null,Y=(E.isMeshStandardMaterial?e:t).get(E.envMap||F),q=Y&&Y.mapping===Ir?Y.image.height:null,Z=g[E.type];E.precision!==null&&(m=s.getMaxPrecision(E.precision),m!==E.precision&&console.warn("THREE.WebGLProgram.getParameters:",E.precision,"not supported, using",m,"instead."));const K=O.morphAttributes.position||O.morphAttributes.normal||O.morphAttributes.color,et=K!==void 0?K.length:0;let nt=0;O.morphAttributes.position!==void 0&&(nt=1),O.morphAttributes.normal!==void 0&&(nt=2),O.morphAttributes.color!==void 0&&(nt=3);let X,$,ct,gt;if(Z){const Pe=pn[Z];X=Pe.vertexShader,$=Pe.fragmentShader}else X=E.vertexShader,$=E.fragmentShader,c.update(E),ct=c.getVertexShaderID(E),gt=c.getFragmentShaderID(E);const _t=i.getRenderTarget(),Lt=B.isInstancedMesh===!0,It=B.isBatchedMesh===!0,At=!!E.map,Xt=!!E.matcap,z=!!Y,Re=!!E.aoMap,vt=!!E.lightMap,Rt=!!E.bumpMap,dt=!!E.normalMap,re=!!E.displacementMap,Ft=!!E.emissiveMap,C=!!E.metalnessMap,b=!!E.roughnessMap,V=E.anisotropy>0,Q=E.clearcoat>0,J=E.iridescence>0,tt=E.sheen>0,pt=E.transmission>0,at=V&&!!E.anisotropyMap,ut=Q&&!!E.clearcoatMap,yt=Q&&!!E.clearcoatNormalMap,Bt=Q&&!!E.clearcoatRoughnessMap,j=J&&!!E.iridescenceMap,$t=J&&!!E.iridescenceThicknessMap,Wt=tt&&!!E.sheenColorMap,Ct=tt&&!!E.sheenRoughnessMap,xt=!!E.specularMap,ft=!!E.specularColorMap,Ot=!!E.specularIntensityMap,Kt=pt&&!!E.transmissionMap,ce=pt&&!!E.thicknessMap,Ht=!!E.gradientMap,it=!!E.alphaMap,L=E.alphaTest>0,rt=!!E.alphaHash,ot=!!E.extensions,bt=!!O.attributes.uv1,Et=!!O.attributes.uv2,Qt=!!O.attributes.uv3;let te=kn;return E.toneMapped&&(_t===null||_t.isXRRenderTarget===!0)&&(te=i.toneMapping),{isWebGL2:h,shaderID:Z,shaderType:E.type,shaderName:E.name,vertexShader:X,fragmentShader:$,defines:E.defines,customVertexShaderID:ct,customFragmentShaderID:gt,isRawShaderMaterial:E.isRawShaderMaterial===!0,glslVersion:E.glslVersion,precision:m,batching:It,instancing:Lt,instancingColor:Lt&&B.instanceColor!==null,supportsVertexTextures:u,outputColorSpace:_t===null?i.outputColorSpace:_t.isXRRenderTarget===!0?_t.texture.colorSpace:Cn,map:At,matcap:Xt,envMap:z,envMapMode:z&&Y.mapping,envMapCubeUVHeight:q,aoMap:Re,lightMap:vt,bumpMap:Rt,normalMap:dt,displacementMap:u&&re,emissiveMap:Ft,normalMapObjectSpace:dt&&E.normalMapType===cu,normalMapTangentSpace:dt&&E.normalMapType===au,metalnessMap:C,roughnessMap:b,anisotropy:V,anisotropyMap:at,clearcoat:Q,clearcoatMap:ut,clearcoatNormalMap:yt,clearcoatRoughnessMap:Bt,iridescence:J,iridescenceMap:j,iridescenceThicknessMap:$t,sheen:tt,sheenColorMap:Wt,sheenRoughnessMap:Ct,specularMap:xt,specularColorMap:ft,specularIntensityMap:Ot,transmission:pt,transmissionMap:Kt,thicknessMap:ce,gradientMap:Ht,opaque:E.transparent===!1&&E.blending===ki,alphaMap:it,alphaTest:L,alphaHash:rt,combine:E.combine,mapUv:At&&x(E.map.channel),aoMapUv:Re&&x(E.aoMap.channel),lightMapUv:vt&&x(E.lightMap.channel),bumpMapUv:Rt&&x(E.bumpMap.channel),normalMapUv:dt&&x(E.normalMap.channel),displacementMapUv:re&&x(E.displacementMap.channel),emissiveMapUv:Ft&&x(E.emissiveMap.channel),metalnessMapUv:C&&x(E.metalnessMap.channel),roughnessMapUv:b&&x(E.roughnessMap.channel),anisotropyMapUv:at&&x(E.anisotropyMap.channel),clearcoatMapUv:ut&&x(E.clearcoatMap.channel),clearcoatNormalMapUv:yt&&x(E.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:Bt&&x(E.clearcoatRoughnessMap.channel),iridescenceMapUv:j&&x(E.iridescenceMap.channel),iridescenceThicknessMapUv:$t&&x(E.iridescenceThicknessMap.channel),sheenColorMapUv:Wt&&x(E.sheenColorMap.channel),sheenRoughnessMapUv:Ct&&x(E.sheenRoughnessMap.channel),specularMapUv:xt&&x(E.specularMap.channel),specularColorMapUv:ft&&x(E.specularColorMap.channel),specularIntensityMapUv:Ot&&x(E.specularIntensityMap.channel),transmissionMapUv:Kt&&x(E.transmissionMap.channel),thicknessMapUv:ce&&x(E.thicknessMap.channel),alphaMapUv:it&&x(E.alphaMap.channel),vertexTangents:!!O.attributes.tangent&&(dt||V),vertexColors:E.vertexColors,vertexAlphas:E.vertexColors===!0&&!!O.attributes.color&&O.attributes.color.itemSize===4,vertexUv1s:bt,vertexUv2s:Et,vertexUv3s:Qt,pointsUvs:B.isPoints===!0&&!!O.attributes.uv&&(At||it),fog:!!R,useFog:E.fog===!0,fogExp2:R&&R.isFogExp2,flatShading:E.flatShading===!0,sizeAttenuation:E.sizeAttenuation===!0,logarithmicDepthBuffer:f,skinning:B.isSkinnedMesh===!0,morphTargets:O.morphAttributes.position!==void 0,morphNormals:O.morphAttributes.normal!==void 0,morphColors:O.morphAttributes.color!==void 0,morphTargetsCount:et,morphTextureStride:nt,numDirLights:S.directional.length,numPointLights:S.point.length,numSpotLights:S.spot.length,numSpotLightMaps:S.spotLightMap.length,numRectAreaLights:S.rectArea.length,numHemiLights:S.hemi.length,numDirLightShadows:S.directionalShadowMap.length,numPointLightShadows:S.pointShadowMap.length,numSpotLightShadows:S.spotShadowMap.length,numSpotLightShadowsWithMaps:S.numSpotLightShadowsWithMaps,numLightProbes:S.numLightProbes,numClippingPlanes:a.numPlanes,numClipIntersection:a.numIntersection,dithering:E.dithering,shadowMapEnabled:i.shadowMap.enabled&&D.length>0,shadowMapType:i.shadowMap.type,toneMapping:te,useLegacyLights:i._useLegacyLights,decodeVideoTexture:At&&E.map.isVideoTexture===!0&&jt.getTransfer(E.map.colorSpace)===ie,premultipliedAlpha:E.premultipliedAlpha,doubleSided:E.side===mn,flipSided:E.side===Oe,useDepthPacking:E.depthPacking>=0,depthPacking:E.depthPacking||0,index0AttributeName:E.index0AttributeName,extensionDerivatives:ot&&E.extensions.derivatives===!0,extensionFragDepth:ot&&E.extensions.fragDepth===!0,extensionDrawBuffers:ot&&E.extensions.drawBuffers===!0,extensionShaderTextureLOD:ot&&E.extensions.shaderTextureLOD===!0,extensionClipCullDistance:ot&&E.extensions.clipCullDistance&&n.has("WEBGL_clip_cull_distance"),rendererExtensionFragDepth:h||n.has("EXT_frag_depth"),rendererExtensionDrawBuffers:h||n.has("WEBGL_draw_buffers"),rendererExtensionShaderTextureLod:h||n.has("EXT_shader_texture_lod"),rendererExtensionParallelShaderCompile:n.has("KHR_parallel_shader_compile"),customProgramCacheKey:E.customProgramCacheKey()}}function d(E){const S=[];if(E.shaderID?S.push(E.shaderID):(S.push(E.customVertexShaderID),S.push(E.customFragmentShaderID)),E.defines!==void 0)for(const D in E.defines)S.push(D),S.push(E.defines[D]);return E.isRawShaderMaterial===!1&&(M(S,E),v(S,E),S.push(i.outputColorSpace)),S.push(E.customProgramCacheKey),S.join()}function M(E,S){E.push(S.precision),E.push(S.outputColorSpace),E.push(S.envMapMode),E.push(S.envMapCubeUVHeight),E.push(S.mapUv),E.push(S.alphaMapUv),E.push(S.lightMapUv),E.push(S.aoMapUv),E.push(S.bumpMapUv),E.push(S.normalMapUv),E.push(S.displacementMapUv),E.push(S.emissiveMapUv),E.push(S.metalnessMapUv),E.push(S.roughnessMapUv),E.push(S.anisotropyMapUv),E.push(S.clearcoatMapUv),E.push(S.clearcoatNormalMapUv),E.push(S.clearcoatRoughnessMapUv),E.push(S.iridescenceMapUv),E.push(S.iridescenceThicknessMapUv),E.push(S.sheenColorMapUv),E.push(S.sheenRoughnessMapUv),E.push(S.specularMapUv),E.push(S.specularColorMapUv),E.push(S.specularIntensityMapUv),E.push(S.transmissionMapUv),E.push(S.thicknessMapUv),E.push(S.combine),E.push(S.fogExp2),E.push(S.sizeAttenuation),E.push(S.morphTargetsCount),E.push(S.morphAttributeCount),E.push(S.numDirLights),E.push(S.numPointLights),E.push(S.numSpotLights),E.push(S.numSpotLightMaps),E.push(S.numHemiLights),E.push(S.numRectAreaLights),E.push(S.numDirLightShadows),E.push(S.numPointLightShadows),E.push(S.numSpotLightShadows),E.push(S.numSpotLightShadowsWithMaps),E.push(S.numLightProbes),E.push(S.shadowMapType),E.push(S.toneMapping),E.push(S.numClippingPlanes),E.push(S.numClipIntersection),E.push(S.depthPacking)}function v(E,S){o.disableAll(),S.isWebGL2&&o.enable(0),S.supportsVertexTextures&&o.enable(1),S.instancing&&o.enable(2),S.instancingColor&&o.enable(3),S.matcap&&o.enable(4),S.envMap&&o.enable(5),S.normalMapObjectSpace&&o.enable(6),S.normalMapTangentSpace&&o.enable(7),S.clearcoat&&o.enable(8),S.iridescence&&o.enable(9),S.alphaTest&&o.enable(10),S.vertexColors&&o.enable(11),S.vertexAlphas&&o.enable(12),S.vertexUv1s&&o.enable(13),S.vertexUv2s&&o.enable(14),S.vertexUv3s&&o.enable(15),S.vertexTangents&&o.enable(16),S.anisotropy&&o.enable(17),S.alphaHash&&o.enable(18),S.batching&&o.enable(19),E.push(o.mask),o.disableAll(),S.fog&&o.enable(0),S.useFog&&o.enable(1),S.flatShading&&o.enable(2),S.logarithmicDepthBuffer&&o.enable(3),S.skinning&&o.enable(4),S.morphTargets&&o.enable(5),S.morphNormals&&o.enable(6),S.morphColors&&o.enable(7),S.premultipliedAlpha&&o.enable(8),S.shadowMapEnabled&&o.enable(9),S.useLegacyLights&&o.enable(10),S.doubleSided&&o.enable(11),S.flipSided&&o.enable(12),S.useDepthPacking&&o.enable(13),S.dithering&&o.enable(14),S.transmission&&o.enable(15),S.sheen&&o.enable(16),S.opaque&&o.enable(17),S.pointsUvs&&o.enable(18),S.decodeVideoTexture&&o.enable(19),E.push(o.mask)}function _(E){const S=g[E.type];let D;if(S){const I=pn[S];D=Ku.clone(I.uniforms)}else D=E.uniforms;return D}function y(E,S){let D;for(let I=0,B=l.length;I0?n.push(d):m.transparent===!0?s.push(d):e.push(d)}function c(f,u,m,g,x,p){const d=a(f,u,m,g,x,p);m.transmission>0?n.unshift(d):m.transparent===!0?s.unshift(d):e.unshift(d)}function l(f,u){e.length>1&&e.sort(f||__),n.length>1&&n.sort(u||kc),s.length>1&&s.sort(u||kc)}function h(){for(let f=t,u=i.length;f=r.length?(a=new Wc,r.push(a)):a=r[s],a}function e(){i=new WeakMap}return{get:t,dispose:e}}function x_(){const i={};return{get:function(t){if(i[t.id]!==void 0)return i[t.id];let e;switch(t.type){case"DirectionalLight":e={direction:new U,color:new qt};break;case"SpotLight":e={position:new U,direction:new U,color:new qt,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":e={position:new U,color:new qt,distance:0,decay:0};break;case"HemisphereLight":e={direction:new U,skyColor:new qt,groundColor:new qt};break;case"RectAreaLight":e={color:new qt,position:new U,halfWidth:new U,halfHeight:new U};break}return i[t.id]=e,e}}}function v_(){const i={};return{get:function(t){if(i[t.id]!==void 0)return i[t.id];let e;switch(t.type){case"DirectionalLight":e={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new kt};break;case"SpotLight":e={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new kt};break;case"PointLight":e={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new kt,shadowCameraNear:1,shadowCameraFar:1e3};break}return i[t.id]=e,e}}}let E_=0;function M_(i,t){return(t.castShadow?2:0)-(i.castShadow?2:0)+(t.map?1:0)-(i.map?1:0)}function S_(i,t){const e=new x_,n=v_(),s={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let h=0;h<9;h++)s.probe.push(new U);const r=new U,a=new Jt,o=new Jt;function c(h,f){let u=0,m=0,g=0;for(let I=0;I<9;I++)s.probe[I].set(0,0,0);let x=0,p=0,d=0,M=0,v=0,_=0,y=0,A=0,T=0,P=0,E=0;h.sort(M_);const S=f===!0?Math.PI:1;for(let I=0,B=h.length;I0&&(t.isWebGL2?i.has("OES_texture_float_linear")===!0?(s.rectAreaLTC1=st.LTC_FLOAT_1,s.rectAreaLTC2=st.LTC_FLOAT_2):(s.rectAreaLTC1=st.LTC_HALF_1,s.rectAreaLTC2=st.LTC_HALF_2):i.has("OES_texture_float_linear")===!0?(s.rectAreaLTC1=st.LTC_FLOAT_1,s.rectAreaLTC2=st.LTC_FLOAT_2):i.has("OES_texture_half_float_linear")===!0?(s.rectAreaLTC1=st.LTC_HALF_1,s.rectAreaLTC2=st.LTC_HALF_2):console.error("THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.")),s.ambient[0]=u,s.ambient[1]=m,s.ambient[2]=g;const D=s.hash;(D.directionalLength!==x||D.pointLength!==p||D.spotLength!==d||D.rectAreaLength!==M||D.hemiLength!==v||D.numDirectionalShadows!==_||D.numPointShadows!==y||D.numSpotShadows!==A||D.numSpotMaps!==T||D.numLightProbes!==E)&&(s.directional.length=x,s.spot.length=d,s.rectArea.length=M,s.point.length=p,s.hemi.length=v,s.directionalShadow.length=_,s.directionalShadowMap.length=_,s.pointShadow.length=y,s.pointShadowMap.length=y,s.spotShadow.length=A,s.spotShadowMap.length=A,s.directionalShadowMatrix.length=_,s.pointShadowMatrix.length=y,s.spotLightMatrix.length=A+T-P,s.spotLightMap.length=T,s.numSpotLightShadowsWithMaps=P,s.numLightProbes=E,D.directionalLength=x,D.pointLength=p,D.spotLength=d,D.rectAreaLength=M,D.hemiLength=v,D.numDirectionalShadows=_,D.numPointShadows=y,D.numSpotShadows=A,D.numSpotMaps=T,D.numLightProbes=E,s.version=E_++)}function l(h,f){let u=0,m=0,g=0,x=0,p=0;const d=f.matrixWorldInverse;for(let M=0,v=h.length;M=o.length?(c=new Xc(i,t),o.push(c)):c=o[a],c}function s(){e=new WeakMap}return{get:n,dispose:s}}class T_ extends Fr{constructor(t){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=ru,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}class A_ extends Fr{constructor(t){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}const b_=`void main() { - gl_Position = vec4( position, 1.0 ); -}`,w_=`uniform sampler2D shadow_pass; -uniform vec2 resolution; -uniform float radius; -#include -void main() { - const float samples = float( VSM_SAMPLES ); - float mean = 0.0; - float squared_mean = 0.0; - float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 ); - float uvStart = samples <= 1.0 ? 0.0 : - 1.0; - for ( float i = 0.0; i < samples; i ++ ) { - float uvOffset = uvStart + i * uvStride; - #ifdef HORIZONTAL_PASS - vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) ); - mean += distribution.x; - squared_mean += distribution.y * distribution.y + distribution.x * distribution.x; - #else - float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) ); - mean += depth; - squared_mean += depth * depth; - #endif - } - mean = mean / samples; - squared_mean = squared_mean / samples; - float std_dev = sqrt( squared_mean - mean * mean ); - gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) ); -}`;function C_(i,t,e){let n=new ua;const s=new kt,r=new kt,a=new pe,o=new T_({depthPacking:ou}),c=new A_,l={},h=e.maxTextureSize,f={[_n]:Oe,[Oe]:_n,[mn]:mn},u=new ci({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new kt},radius:{value:4}},vertexShader:b_,fragmentShader:w_}),m=u.clone();m.defines.HORIZONTAL_PASS=1;const g=new Rn;g.setAttribute("position",new tn(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const x=new ln(g,u),p=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=yl;let d=this.type;this.render=function(A,T,P){if(p.enabled===!1||p.autoUpdate===!1&&p.needsUpdate===!1||A.length===0)return;const E=i.getRenderTarget(),S=i.getActiveCubeFace(),D=i.getActiveMipmapLevel(),I=i.state;I.setBlending(Gn),I.buffers.color.setClear(1,1,1,1),I.buffers.depth.setTest(!0),I.setScissorTest(!1);const B=d!==yn&&this.type===yn,R=d===yn&&this.type!==yn;for(let O=0,F=A.length;Oh||s.y>h)&&(s.x>h&&(r.x=Math.floor(h/Z.x),s.x=r.x*Z.x,q.mapSize.x=r.x),s.y>h&&(r.y=Math.floor(h/Z.y),s.y=r.y*Z.y,q.mapSize.y=r.y)),q.map===null||B===!0||R===!0){const et=this.type!==yn?{minFilter:Ie,magFilter:Ie}:{};q.map!==null&&q.map.dispose(),q.map=new ai(s.x,s.y,et),q.map.texture.name=Y.name+".shadowMap",q.camera.updateProjectionMatrix()}i.setRenderTarget(q.map),i.clear();const K=q.getViewportCount();for(let et=0;et0||T.map&&T.alphaTest>0){const I=S.uuid,B=T.uuid;let R=l[I];R===void 0&&(R={},l[I]=R);let O=R[B];O===void 0&&(O=S.clone(),R[B]=O,T.addEventListener("dispose",y)),S=O}if(S.visible=T.visible,S.wireframe=T.wireframe,E===yn?S.side=T.shadowSide!==null?T.shadowSide:T.side:S.side=T.shadowSide!==null?T.shadowSide:f[T.side],S.alphaMap=T.alphaMap,S.alphaTest=T.alphaTest,S.map=T.map,S.clipShadows=T.clipShadows,S.clippingPlanes=T.clippingPlanes,S.clipIntersection=T.clipIntersection,S.displacementMap=T.displacementMap,S.displacementScale=T.displacementScale,S.displacementBias=T.displacementBias,S.wireframeLinewidth=T.wireframeLinewidth,S.linewidth=T.linewidth,P.isPointLight===!0&&S.isMeshDistanceMaterial===!0){const I=i.properties.get(S);I.light=P}return S}function _(A,T,P,E,S){if(A.visible===!1)return;if(A.layers.test(T.layers)&&(A.isMesh||A.isLine||A.isPoints)&&(A.castShadow||A.receiveShadow&&S===yn)&&(!A.frustumCulled||n.intersectsObject(A))){A.modelViewMatrix.multiplyMatrices(P.matrixWorldInverse,A.matrixWorld);const B=t.update(A),R=A.material;if(Array.isArray(R)){const O=B.groups;for(let F=0,Y=O.length;F=1):K.indexOf("OpenGL ES")!==-1&&(Z=parseFloat(/^OpenGL ES (\d)/.exec(K)[1]),q=Z>=2);let et=null,nt={};const X=i.getParameter(i.SCISSOR_BOX),$=i.getParameter(i.VIEWPORT),ct=new pe().fromArray(X),gt=new pe().fromArray($);function _t(L,rt,ot,bt){const Et=new Uint8Array(4),Qt=i.createTexture();i.bindTexture(L,Qt),i.texParameteri(L,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(L,i.TEXTURE_MAG_FILTER,i.NEAREST);for(let te=0;te"u"?!1:/OculusBrowser/g.test(navigator.userAgent),h=new WeakMap;let f;const u=new WeakMap;let m=!1;try{m=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function g(C,b){return m?new OffscreenCanvas(C,b):Cr("canvas")}function x(C,b,V,Q){let J=1;if((C.width>Q||C.height>Q)&&(J=Q/Math.max(C.width,C.height)),J<1||b===!0)if(typeof HTMLImageElement<"u"&&C instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&C instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&C instanceof ImageBitmap){const tt=b?wr:Math.floor,pt=tt(J*C.width),at=tt(J*C.height);f===void 0&&(f=g(pt,at));const ut=V?g(pt,at):f;return ut.width=pt,ut.height=at,ut.getContext("2d").drawImage(C,0,0,pt,at),console.warn("THREE.WebGLRenderer: Texture has been resized from ("+C.width+"x"+C.height+") to ("+pt+"x"+at+")."),ut}else return"data"in C&&console.warn("THREE.WebGLRenderer: Image in DataTexture is too big ("+C.width+"x"+C.height+")."),C;return C}function p(C){return Yo(C.width)&&Yo(C.height)}function d(C){return o?!1:C.wrapS!==an||C.wrapT!==an||C.minFilter!==Ie&&C.minFilter!==qe}function M(C,b){return C.generateMipmaps&&b&&C.minFilter!==Ie&&C.minFilter!==qe}function v(C){i.generateMipmap(C)}function _(C,b,V,Q,J=!1){if(o===!1)return b;if(C!==null){if(i[C]!==void 0)return i[C];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+C+"'")}let tt=b;if(b===i.RED&&(V===i.FLOAT&&(tt=i.R32F),V===i.HALF_FLOAT&&(tt=i.R16F),V===i.UNSIGNED_BYTE&&(tt=i.R8)),b===i.RED_INTEGER&&(V===i.UNSIGNED_BYTE&&(tt=i.R8UI),V===i.UNSIGNED_SHORT&&(tt=i.R16UI),V===i.UNSIGNED_INT&&(tt=i.R32UI),V===i.BYTE&&(tt=i.R8I),V===i.SHORT&&(tt=i.R16I),V===i.INT&&(tt=i.R32I)),b===i.RG&&(V===i.FLOAT&&(tt=i.RG32F),V===i.HALF_FLOAT&&(tt=i.RG16F),V===i.UNSIGNED_BYTE&&(tt=i.RG8)),b===i.RGBA){const pt=J?yr:jt.getTransfer(Q);V===i.FLOAT&&(tt=i.RGBA32F),V===i.HALF_FLOAT&&(tt=i.RGBA16F),V===i.UNSIGNED_BYTE&&(tt=pt===ie?i.SRGB8_ALPHA8:i.RGBA8),V===i.UNSIGNED_SHORT_4_4_4_4&&(tt=i.RGBA4),V===i.UNSIGNED_SHORT_5_5_5_1&&(tt=i.RGB5_A1)}return(tt===i.R16F||tt===i.R32F||tt===i.RG16F||tt===i.RG32F||tt===i.RGBA16F||tt===i.RGBA32F)&&t.get("EXT_color_buffer_float"),tt}function y(C,b,V){return M(C,V)===!0||C.isFramebufferTexture&&C.minFilter!==Ie&&C.minFilter!==qe?Math.log2(Math.max(b.width,b.height))+1:C.mipmaps!==void 0&&C.mipmaps.length>0?C.mipmaps.length:C.isCompressedTexture&&Array.isArray(C.image)?b.mipmaps.length:1}function A(C){return C===Ie||C===Ua||C===Xr?i.NEAREST:i.LINEAR}function T(C){const b=C.target;b.removeEventListener("dispose",T),E(b),b.isVideoTexture&&h.delete(b)}function P(C){const b=C.target;b.removeEventListener("dispose",P),D(b)}function E(C){const b=n.get(C);if(b.__webglInit===void 0)return;const V=C.source,Q=u.get(V);if(Q){const J=Q[b.__cacheKey];J.usedTimes--,J.usedTimes===0&&S(C),Object.keys(Q).length===0&&u.delete(V)}n.remove(C)}function S(C){const b=n.get(C);i.deleteTexture(b.__webglTexture);const V=C.source,Q=u.get(V);delete Q[b.__cacheKey],a.memory.textures--}function D(C){const b=C.texture,V=n.get(C),Q=n.get(b);if(Q.__webglTexture!==void 0&&(i.deleteTexture(Q.__webglTexture),a.memory.textures--),C.depthTexture&&C.depthTexture.dispose(),C.isWebGLCubeRenderTarget)for(let J=0;J<6;J++){if(Array.isArray(V.__webglFramebuffer[J]))for(let tt=0;tt=s.maxTextures&&console.warn("THREE.WebGLTextures: Trying to use "+C+" texture units while this GPU supports only "+s.maxTextures),I+=1,C}function O(C){const b=[];return b.push(C.wrapS),b.push(C.wrapT),b.push(C.wrapR||0),b.push(C.magFilter),b.push(C.minFilter),b.push(C.anisotropy),b.push(C.internalFormat),b.push(C.format),b.push(C.type),b.push(C.generateMipmaps),b.push(C.premultiplyAlpha),b.push(C.flipY),b.push(C.unpackAlignment),b.push(C.colorSpace),b.join()}function F(C,b){const V=n.get(C);if(C.isVideoTexture&&re(C),C.isRenderTargetTexture===!1&&C.version>0&&V.__version!==C.version){const Q=C.image;if(Q===null)console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found.");else if(Q.complete===!1)console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete");else{ct(V,C,b);return}}e.bindTexture(i.TEXTURE_2D,V.__webglTexture,i.TEXTURE0+b)}function Y(C,b){const V=n.get(C);if(C.version>0&&V.__version!==C.version){ct(V,C,b);return}e.bindTexture(i.TEXTURE_2D_ARRAY,V.__webglTexture,i.TEXTURE0+b)}function q(C,b){const V=n.get(C);if(C.version>0&&V.__version!==C.version){ct(V,C,b);return}e.bindTexture(i.TEXTURE_3D,V.__webglTexture,i.TEXTURE0+b)}function Z(C,b){const V=n.get(C);if(C.version>0&&V.__version!==C.version){gt(V,C,b);return}e.bindTexture(i.TEXTURE_CUBE_MAP,V.__webglTexture,i.TEXTURE0+b)}const K={[ko]:i.REPEAT,[an]:i.CLAMP_TO_EDGE,[Wo]:i.MIRRORED_REPEAT},et={[Ie]:i.NEAREST,[Ua]:i.NEAREST_MIPMAP_NEAREST,[Xr]:i.NEAREST_MIPMAP_LINEAR,[qe]:i.LINEAR,[$h]:i.LINEAR_MIPMAP_NEAREST,[ys]:i.LINEAR_MIPMAP_LINEAR},nt={[lu]:i.NEVER,[mu]:i.ALWAYS,[hu]:i.LESS,[Il]:i.LEQUAL,[uu]:i.EQUAL,[pu]:i.GEQUAL,[fu]:i.GREATER,[du]:i.NOTEQUAL};function X(C,b,V){if(V?(i.texParameteri(C,i.TEXTURE_WRAP_S,K[b.wrapS]),i.texParameteri(C,i.TEXTURE_WRAP_T,K[b.wrapT]),(C===i.TEXTURE_3D||C===i.TEXTURE_2D_ARRAY)&&i.texParameteri(C,i.TEXTURE_WRAP_R,K[b.wrapR]),i.texParameteri(C,i.TEXTURE_MAG_FILTER,et[b.magFilter]),i.texParameteri(C,i.TEXTURE_MIN_FILTER,et[b.minFilter])):(i.texParameteri(C,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(C,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),(C===i.TEXTURE_3D||C===i.TEXTURE_2D_ARRAY)&&i.texParameteri(C,i.TEXTURE_WRAP_R,i.CLAMP_TO_EDGE),(b.wrapS!==an||b.wrapT!==an)&&console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping."),i.texParameteri(C,i.TEXTURE_MAG_FILTER,A(b.magFilter)),i.texParameteri(C,i.TEXTURE_MIN_FILTER,A(b.minFilter)),b.minFilter!==Ie&&b.minFilter!==qe&&console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.")),b.compareFunction&&(i.texParameteri(C,i.TEXTURE_COMPARE_MODE,i.COMPARE_REF_TO_TEXTURE),i.texParameteri(C,i.TEXTURE_COMPARE_FUNC,nt[b.compareFunction])),t.has("EXT_texture_filter_anisotropic")===!0){const Q=t.get("EXT_texture_filter_anisotropic");if(b.magFilter===Ie||b.minFilter!==Xr&&b.minFilter!==ys||b.type===Hn&&t.has("OES_texture_float_linear")===!1||o===!1&&b.type===Ts&&t.has("OES_texture_half_float_linear")===!1)return;(b.anisotropy>1||n.get(b).__currentAnisotropy)&&(i.texParameterf(C,Q.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(b.anisotropy,s.getMaxAnisotropy())),n.get(b).__currentAnisotropy=b.anisotropy)}}function $(C,b){let V=!1;C.__webglInit===void 0&&(C.__webglInit=!0,b.addEventListener("dispose",T));const Q=b.source;let J=u.get(Q);J===void 0&&(J={},u.set(Q,J));const tt=O(b);if(tt!==C.__cacheKey){J[tt]===void 0&&(J[tt]={texture:i.createTexture(),usedTimes:0},a.memory.textures++,V=!0),J[tt].usedTimes++;const pt=J[C.__cacheKey];pt!==void 0&&(J[C.__cacheKey].usedTimes--,pt.usedTimes===0&&S(b)),C.__cacheKey=tt,C.__webglTexture=J[tt].texture}return V}function ct(C,b,V){let Q=i.TEXTURE_2D;(b.isDataArrayTexture||b.isCompressedArrayTexture)&&(Q=i.TEXTURE_2D_ARRAY),b.isData3DTexture&&(Q=i.TEXTURE_3D);const J=$(C,b),tt=b.source;e.bindTexture(Q,C.__webglTexture,i.TEXTURE0+V);const pt=n.get(tt);if(tt.version!==pt.__version||J===!0){e.activeTexture(i.TEXTURE0+V);const at=jt.getPrimaries(jt.workingColorSpace),ut=b.colorSpace===Ke?null:jt.getPrimaries(b.colorSpace),yt=b.colorSpace===Ke||at===ut?i.NONE:i.BROWSER_DEFAULT_WEBGL;i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,b.flipY),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,b.premultiplyAlpha),i.pixelStorei(i.UNPACK_ALIGNMENT,b.unpackAlignment),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,yt);const Bt=d(b)&&p(b.image)===!1;let j=x(b.image,Bt,!1,s.maxTextureSize);j=Ft(b,j);const $t=p(j)||o,Wt=r.convert(b.format,b.colorSpace);let Ct=r.convert(b.type),xt=_(b.internalFormat,Wt,Ct,b.colorSpace,b.isVideoTexture);X(Q,b,$t);let ft;const Ot=b.mipmaps,Kt=o&&b.isVideoTexture!==!0&&xt!==Ul,ce=pt.__version===void 0||J===!0,Ht=y(b,j,$t);if(b.isDepthTexture)xt=i.DEPTH_COMPONENT,o?b.type===Hn?xt=i.DEPTH_COMPONENT32F:b.type===zn?xt=i.DEPTH_COMPONENT24:b.type===ii?xt=i.DEPTH24_STENCIL8:xt=i.DEPTH_COMPONENT16:b.type===Hn&&console.error("WebGLRenderer: Floating point depth texture requires WebGL2."),b.format===si&&xt===i.DEPTH_COMPONENT&&b.type!==oa&&b.type!==zn&&(console.warn("THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture."),b.type=zn,Ct=r.convert(b.type)),b.format===qi&&xt===i.DEPTH_COMPONENT&&(xt=i.DEPTH_STENCIL,b.type!==ii&&(console.warn("THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture."),b.type=ii,Ct=r.convert(b.type))),ce&&(Kt?e.texStorage2D(i.TEXTURE_2D,1,xt,j.width,j.height):e.texImage2D(i.TEXTURE_2D,0,xt,j.width,j.height,0,Wt,Ct,null));else if(b.isDataTexture)if(Ot.length>0&&$t){Kt&&ce&&e.texStorage2D(i.TEXTURE_2D,Ht,xt,Ot[0].width,Ot[0].height);for(let it=0,L=Ot.length;it>=1,L>>=1}}else if(Ot.length>0&&$t){Kt&&ce&&e.texStorage2D(i.TEXTURE_2D,Ht,xt,Ot[0].width,Ot[0].height);for(let it=0,L=Ot.length;it0&&ce++,e.texStorage2D(i.TEXTURE_CUBE_MAP,ce,ft,j[0].width,j[0].height));for(let it=0;it<6;it++)if(Bt){Ot?e.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+it,0,0,0,j[it].width,j[it].height,Ct,xt,j[it].data):e.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+it,0,ft,j[it].width,j[it].height,0,Ct,xt,j[it].data);for(let L=0;L>tt),j=Math.max(1,b.height>>tt);J===i.TEXTURE_3D||J===i.TEXTURE_2D_ARRAY?e.texImage3D(J,tt,ut,Bt,j,b.depth,0,pt,at,null):e.texImage2D(J,tt,ut,Bt,j,0,pt,at,null)}e.bindFramebuffer(i.FRAMEBUFFER,C),dt(b)?c.framebufferTexture2DMultisampleEXT(i.FRAMEBUFFER,Q,J,n.get(V).__webglTexture,0,Rt(b)):(J===i.TEXTURE_2D||J>=i.TEXTURE_CUBE_MAP_POSITIVE_X&&J<=i.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&i.framebufferTexture2D(i.FRAMEBUFFER,Q,J,n.get(V).__webglTexture,tt),e.bindFramebuffer(i.FRAMEBUFFER,null)}function Lt(C,b,V){if(i.bindRenderbuffer(i.RENDERBUFFER,C),b.depthBuffer&&!b.stencilBuffer){let Q=o===!0?i.DEPTH_COMPONENT24:i.DEPTH_COMPONENT16;if(V||dt(b)){const J=b.depthTexture;J&&J.isDepthTexture&&(J.type===Hn?Q=i.DEPTH_COMPONENT32F:J.type===zn&&(Q=i.DEPTH_COMPONENT24));const tt=Rt(b);dt(b)?c.renderbufferStorageMultisampleEXT(i.RENDERBUFFER,tt,Q,b.width,b.height):i.renderbufferStorageMultisample(i.RENDERBUFFER,tt,Q,b.width,b.height)}else i.renderbufferStorage(i.RENDERBUFFER,Q,b.width,b.height);i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.RENDERBUFFER,C)}else if(b.depthBuffer&&b.stencilBuffer){const Q=Rt(b);V&&dt(b)===!1?i.renderbufferStorageMultisample(i.RENDERBUFFER,Q,i.DEPTH24_STENCIL8,b.width,b.height):dt(b)?c.renderbufferStorageMultisampleEXT(i.RENDERBUFFER,Q,i.DEPTH24_STENCIL8,b.width,b.height):i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_STENCIL,b.width,b.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.RENDERBUFFER,C)}else{const Q=b.isWebGLMultipleRenderTargets===!0?b.texture:[b.texture];for(let J=0;J0){V.__webglFramebuffer[at]=[];for(let ut=0;ut0){V.__webglFramebuffer=[];for(let at=0;at0&&dt(C)===!1){const at=tt?b:[b];V.__webglMultisampledFramebuffer=i.createFramebuffer(),V.__webglColorRenderbuffer=[],e.bindFramebuffer(i.FRAMEBUFFER,V.__webglMultisampledFramebuffer);for(let ut=0;ut0)for(let ut=0;ut0)for(let ut=0;ut0&&dt(C)===!1){const b=C.isWebGLMultipleRenderTargets?C.texture:[C.texture],V=C.width,Q=C.height;let J=i.COLOR_BUFFER_BIT;const tt=[],pt=C.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT,at=n.get(C),ut=C.isWebGLMultipleRenderTargets===!0;if(ut)for(let yt=0;yt0&&t.has("WEBGL_multisampled_render_to_texture")===!0&&b.__useRenderToTexture!==!1}function re(C){const b=a.render.frame;h.get(C)!==b&&(h.set(C,b),C.update())}function Ft(C,b){const V=C.colorSpace,Q=C.format,J=C.type;return C.isCompressedTexture===!0||C.isVideoTexture===!0||C.format===Xo||V!==Cn&&V!==Ke&&(jt.getTransfer(V)===ie?o===!1?t.has("EXT_sRGB")===!0&&Q===cn?(C.format=Xo,C.minFilter=qe,C.generateMipmaps=!1):b=Nl.sRGBToLinear(b):(Q!==cn||J!==Wn)&&console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):console.error("THREE.WebGLTextures: Unsupported texture color space:",V)),b}this.allocateTextureUnit=R,this.resetTextureUnits=B,this.setTexture2D=F,this.setTexture2DArray=Y,this.setTexture3D=q,this.setTextureCube=Z,this.rebindTextures=Xt,this.setupRenderTarget=z,this.updateRenderTargetMipmap=Re,this.updateMultisampleRenderTarget=vt,this.setupDepthRenderbuffer=At,this.setupFrameBufferTexture=_t,this.useMultisampledRTT=dt}function L_(i,t,e){const n=e.isWebGL2;function s(r,a=Ke){let o;const c=jt.getTransfer(a);if(r===Wn)return i.UNSIGNED_BYTE;if(r===wl)return i.UNSIGNED_SHORT_4_4_4_4;if(r===Cl)return i.UNSIGNED_SHORT_5_5_5_1;if(r===jh)return i.BYTE;if(r===Jh)return i.SHORT;if(r===oa)return i.UNSIGNED_SHORT;if(r===bl)return i.INT;if(r===zn)return i.UNSIGNED_INT;if(r===Hn)return i.FLOAT;if(r===Ts)return n?i.HALF_FLOAT:(o=t.get("OES_texture_half_float"),o!==null?o.HALF_FLOAT_OES:null);if(r===Qh)return i.ALPHA;if(r===cn)return i.RGBA;if(r===tu)return i.LUMINANCE;if(r===eu)return i.LUMINANCE_ALPHA;if(r===si)return i.DEPTH_COMPONENT;if(r===qi)return i.DEPTH_STENCIL;if(r===Xo)return o=t.get("EXT_sRGB"),o!==null?o.SRGB_ALPHA_EXT:null;if(r===nu)return i.RED;if(r===Rl)return i.RED_INTEGER;if(r===iu)return i.RG;if(r===Pl)return i.RG_INTEGER;if(r===Ll)return i.RGBA_INTEGER;if(r===Yr||r===qr||r===Zr||r===Kr)if(c===ie)if(o=t.get("WEBGL_compressed_texture_s3tc_srgb"),o!==null){if(r===Yr)return o.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(r===qr)return o.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(r===Zr)return o.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(r===Kr)return o.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(o=t.get("WEBGL_compressed_texture_s3tc"),o!==null){if(r===Yr)return o.COMPRESSED_RGB_S3TC_DXT1_EXT;if(r===qr)return o.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(r===Zr)return o.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(r===Kr)return o.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(r===Da||r===Ia||r===Oa||r===Na)if(o=t.get("WEBGL_compressed_texture_pvrtc"),o!==null){if(r===Da)return o.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(r===Ia)return o.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(r===Oa)return o.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(r===Na)return o.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(r===Ul)return o=t.get("WEBGL_compressed_texture_etc1"),o!==null?o.COMPRESSED_RGB_ETC1_WEBGL:null;if(r===Fa||r===Ba)if(o=t.get("WEBGL_compressed_texture_etc"),o!==null){if(r===Fa)return c===ie?o.COMPRESSED_SRGB8_ETC2:o.COMPRESSED_RGB8_ETC2;if(r===Ba)return c===ie?o.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:o.COMPRESSED_RGBA8_ETC2_EAC}else return null;if(r===za||r===Ha||r===Va||r===Ga||r===ka||r===Wa||r===Xa||r===Ya||r===qa||r===Za||r===Ka||r===$a||r===ja||r===Ja)if(o=t.get("WEBGL_compressed_texture_astc"),o!==null){if(r===za)return c===ie?o.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:o.COMPRESSED_RGBA_ASTC_4x4_KHR;if(r===Ha)return c===ie?o.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:o.COMPRESSED_RGBA_ASTC_5x4_KHR;if(r===Va)return c===ie?o.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:o.COMPRESSED_RGBA_ASTC_5x5_KHR;if(r===Ga)return c===ie?o.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:o.COMPRESSED_RGBA_ASTC_6x5_KHR;if(r===ka)return c===ie?o.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:o.COMPRESSED_RGBA_ASTC_6x6_KHR;if(r===Wa)return c===ie?o.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:o.COMPRESSED_RGBA_ASTC_8x5_KHR;if(r===Xa)return c===ie?o.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:o.COMPRESSED_RGBA_ASTC_8x6_KHR;if(r===Ya)return c===ie?o.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:o.COMPRESSED_RGBA_ASTC_8x8_KHR;if(r===qa)return c===ie?o.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:o.COMPRESSED_RGBA_ASTC_10x5_KHR;if(r===Za)return c===ie?o.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:o.COMPRESSED_RGBA_ASTC_10x6_KHR;if(r===Ka)return c===ie?o.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:o.COMPRESSED_RGBA_ASTC_10x8_KHR;if(r===$a)return c===ie?o.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:o.COMPRESSED_RGBA_ASTC_10x10_KHR;if(r===ja)return c===ie?o.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:o.COMPRESSED_RGBA_ASTC_12x10_KHR;if(r===Ja)return c===ie?o.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:o.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(r===$r||r===Qa||r===tc)if(o=t.get("EXT_texture_compression_bptc"),o!==null){if(r===$r)return c===ie?o.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:o.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(r===Qa)return o.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(r===tc)return o.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(r===su||r===ec||r===nc||r===ic)if(o=t.get("EXT_texture_compression_rgtc"),o!==null){if(r===$r)return o.COMPRESSED_RED_RGTC1_EXT;if(r===ec)return o.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(r===nc)return o.COMPRESSED_RED_GREEN_RGTC2_EXT;if(r===ic)return o.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return r===ii?n?i.UNSIGNED_INT_24_8:(o=t.get("WEBGL_depth_texture"),o!==null?o.UNSIGNED_INT_24_8_WEBGL:null):i[r]!==void 0?i[r]:null}return{convert:s}}class U_ extends Ze{constructor(t=[]){super(),this.isArrayCamera=!0,this.cameras=t}}class Qs extends Ce{constructor(){super(),this.isGroup=!0,this.type="Group"}}const D_={type:"move"};class Eo{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Qs,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new Qs,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new U,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new U),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new Qs,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new U,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new U),this._grip}dispatchEvent(t){return this._targetRay!==null&&this._targetRay.dispatchEvent(t),this._grip!==null&&this._grip.dispatchEvent(t),this._hand!==null&&this._hand.dispatchEvent(t),this}connect(t){if(t&&t.hand){const e=this._hand;if(e)for(const n of t.hand.values())this._getHandJoint(e,n)}return this.dispatchEvent({type:"connected",data:t}),this}disconnect(t){return this.dispatchEvent({type:"disconnected",data:t}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(t,e,n){let s=null,r=null,a=null;const o=this._targetRay,c=this._grip,l=this._hand;if(t&&e.session.visibilityState!=="visible-blurred"){if(l&&t.hand){a=!0;for(const x of t.hand.values()){const p=e.getJointPose(x,n),d=this._getHandJoint(l,x);p!==null&&(d.matrix.fromArray(p.transform.matrix),d.matrix.decompose(d.position,d.rotation,d.scale),d.matrixWorldNeedsUpdate=!0,d.jointRadius=p.radius),d.visible=p!==null}const h=l.joints["index-finger-tip"],f=l.joints["thumb-tip"],u=h.position.distanceTo(f.position),m=.02,g=.005;l.inputState.pinching&&u>m+g?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:t.handedness,target:this})):!l.inputState.pinching&&u<=m-g&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:t.handedness,target:this}))}else c!==null&&t.gripSpace&&(r=e.getPose(t.gripSpace,n),r!==null&&(c.matrix.fromArray(r.transform.matrix),c.matrix.decompose(c.position,c.rotation,c.scale),c.matrixWorldNeedsUpdate=!0,r.linearVelocity?(c.hasLinearVelocity=!0,c.linearVelocity.copy(r.linearVelocity)):c.hasLinearVelocity=!1,r.angularVelocity?(c.hasAngularVelocity=!0,c.angularVelocity.copy(r.angularVelocity)):c.hasAngularVelocity=!1));o!==null&&(s=e.getPose(t.targetRaySpace,n),s===null&&r!==null&&(s=r),s!==null&&(o.matrix.fromArray(s.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,s.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(s.linearVelocity)):o.hasLinearVelocity=!1,s.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(s.angularVelocity)):o.hasAngularVelocity=!1,this.dispatchEvent(D_)))}return o!==null&&(o.visible=s!==null),c!==null&&(c.visible=r!==null),l!==null&&(l.visible=a!==null),this}_getHandJoint(t,e){if(t.joints[e.jointName]===void 0){const n=new Qs;n.matrixAutoUpdate=!1,n.visible=!1,t.joints[e.jointName]=n,t.add(n)}return t.joints[e.jointName]}}class I_ extends Ki{constructor(t,e){super();const n=this;let s=null,r=1,a=null,o="local-floor",c=1,l=null,h=null,f=null,u=null,m=null,g=null;const x=e.getContextAttributes();let p=null,d=null;const M=[],v=[],_=new kt;let y=null;const A=new Ze;A.layers.enable(1),A.viewport=new pe;const T=new Ze;T.layers.enable(2),T.viewport=new pe;const P=[A,T],E=new U_;E.layers.enable(1),E.layers.enable(2);let S=null,D=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(X){let $=M[X];return $===void 0&&($=new Eo,M[X]=$),$.getTargetRaySpace()},this.getControllerGrip=function(X){let $=M[X];return $===void 0&&($=new Eo,M[X]=$),$.getGripSpace()},this.getHand=function(X){let $=M[X];return $===void 0&&($=new Eo,M[X]=$),$.getHandSpace()};function I(X){const $=v.indexOf(X.inputSource);if($===-1)return;const ct=M[$];ct!==void 0&&(ct.update(X.inputSource,X.frame,l||a),ct.dispatchEvent({type:X.type,data:X.inputSource}))}function B(){s.removeEventListener("select",I),s.removeEventListener("selectstart",I),s.removeEventListener("selectend",I),s.removeEventListener("squeeze",I),s.removeEventListener("squeezestart",I),s.removeEventListener("squeezeend",I),s.removeEventListener("end",B),s.removeEventListener("inputsourceschange",R);for(let X=0;X=0&&(v[gt]=null,M[gt].disconnect(ct))}for(let $=0;$=v.length){v.push(ct),gt=Lt;break}else if(v[Lt]===null){v[Lt]=ct,gt=Lt;break}if(gt===-1)break}const _t=M[gt];_t&&_t.connect(ct)}}const O=new U,F=new U;function Y(X,$,ct){O.setFromMatrixPosition($.matrixWorld),F.setFromMatrixPosition(ct.matrixWorld);const gt=O.distanceTo(F),_t=$.projectionMatrix.elements,Lt=ct.projectionMatrix.elements,It=_t[14]/(_t[10]-1),At=_t[14]/(_t[10]+1),Xt=(_t[9]+1)/_t[5],z=(_t[9]-1)/_t[5],Re=(_t[8]-1)/_t[0],vt=(Lt[8]+1)/Lt[0],Rt=It*Re,dt=It*vt,re=gt/(-Re+vt),Ft=re*-Re;$.matrixWorld.decompose(X.position,X.quaternion,X.scale),X.translateX(Ft),X.translateZ(re),X.matrixWorld.compose(X.position,X.quaternion,X.scale),X.matrixWorldInverse.copy(X.matrixWorld).invert();const C=It+re,b=At+re,V=Rt-Ft,Q=dt+(gt-Ft),J=Xt*At/b*C,tt=z*At/b*C;X.projectionMatrix.makePerspective(V,Q,J,tt,C,b),X.projectionMatrixInverse.copy(X.projectionMatrix).invert()}function q(X,$){$===null?X.matrixWorld.copy(X.matrix):X.matrixWorld.multiplyMatrices($.matrixWorld,X.matrix),X.matrixWorldInverse.copy(X.matrixWorld).invert()}this.updateCamera=function(X){if(s===null)return;E.near=T.near=A.near=X.near,E.far=T.far=A.far=X.far,(S!==E.near||D!==E.far)&&(s.updateRenderState({depthNear:E.near,depthFar:E.far}),S=E.near,D=E.far);const $=X.parent,ct=E.cameras;q(E,$);for(let gt=0;gt0&&(p.alphaTest.value=d.alphaTest);const M=t.get(d).envMap;if(M&&(p.envMap.value=M,p.flipEnvMap.value=M.isCubeTexture&&M.isRenderTargetTexture===!1?-1:1,p.reflectivity.value=d.reflectivity,p.ior.value=d.ior,p.refractionRatio.value=d.refractionRatio),d.lightMap){p.lightMap.value=d.lightMap;const v=i._useLegacyLights===!0?Math.PI:1;p.lightMapIntensity.value=d.lightMapIntensity*v,e(d.lightMap,p.lightMapTransform)}d.aoMap&&(p.aoMap.value=d.aoMap,p.aoMapIntensity.value=d.aoMapIntensity,e(d.aoMap,p.aoMapTransform))}function a(p,d){p.diffuse.value.copy(d.color),p.opacity.value=d.opacity,d.map&&(p.map.value=d.map,e(d.map,p.mapTransform))}function o(p,d){p.dashSize.value=d.dashSize,p.totalSize.value=d.dashSize+d.gapSize,p.scale.value=d.scale}function c(p,d,M,v){p.diffuse.value.copy(d.color),p.opacity.value=d.opacity,p.size.value=d.size*M,p.scale.value=v*.5,d.map&&(p.map.value=d.map,e(d.map,p.uvTransform)),d.alphaMap&&(p.alphaMap.value=d.alphaMap,e(d.alphaMap,p.alphaMapTransform)),d.alphaTest>0&&(p.alphaTest.value=d.alphaTest)}function l(p,d){p.diffuse.value.copy(d.color),p.opacity.value=d.opacity,p.rotation.value=d.rotation,d.map&&(p.map.value=d.map,e(d.map,p.mapTransform)),d.alphaMap&&(p.alphaMap.value=d.alphaMap,e(d.alphaMap,p.alphaMapTransform)),d.alphaTest>0&&(p.alphaTest.value=d.alphaTest)}function h(p,d){p.specular.value.copy(d.specular),p.shininess.value=Math.max(d.shininess,1e-4)}function f(p,d){d.gradientMap&&(p.gradientMap.value=d.gradientMap)}function u(p,d){p.metalness.value=d.metalness,d.metalnessMap&&(p.metalnessMap.value=d.metalnessMap,e(d.metalnessMap,p.metalnessMapTransform)),p.roughness.value=d.roughness,d.roughnessMap&&(p.roughnessMap.value=d.roughnessMap,e(d.roughnessMap,p.roughnessMapTransform)),t.get(d).envMap&&(p.envMapIntensity.value=d.envMapIntensity)}function m(p,d,M){p.ior.value=d.ior,d.sheen>0&&(p.sheenColor.value.copy(d.sheenColor).multiplyScalar(d.sheen),p.sheenRoughness.value=d.sheenRoughness,d.sheenColorMap&&(p.sheenColorMap.value=d.sheenColorMap,e(d.sheenColorMap,p.sheenColorMapTransform)),d.sheenRoughnessMap&&(p.sheenRoughnessMap.value=d.sheenRoughnessMap,e(d.sheenRoughnessMap,p.sheenRoughnessMapTransform))),d.clearcoat>0&&(p.clearcoat.value=d.clearcoat,p.clearcoatRoughness.value=d.clearcoatRoughness,d.clearcoatMap&&(p.clearcoatMap.value=d.clearcoatMap,e(d.clearcoatMap,p.clearcoatMapTransform)),d.clearcoatRoughnessMap&&(p.clearcoatRoughnessMap.value=d.clearcoatRoughnessMap,e(d.clearcoatRoughnessMap,p.clearcoatRoughnessMapTransform)),d.clearcoatNormalMap&&(p.clearcoatNormalMap.value=d.clearcoatNormalMap,e(d.clearcoatNormalMap,p.clearcoatNormalMapTransform),p.clearcoatNormalScale.value.copy(d.clearcoatNormalScale),d.side===Oe&&p.clearcoatNormalScale.value.negate())),d.iridescence>0&&(p.iridescence.value=d.iridescence,p.iridescenceIOR.value=d.iridescenceIOR,p.iridescenceThicknessMinimum.value=d.iridescenceThicknessRange[0],p.iridescenceThicknessMaximum.value=d.iridescenceThicknessRange[1],d.iridescenceMap&&(p.iridescenceMap.value=d.iridescenceMap,e(d.iridescenceMap,p.iridescenceMapTransform)),d.iridescenceThicknessMap&&(p.iridescenceThicknessMap.value=d.iridescenceThicknessMap,e(d.iridescenceThicknessMap,p.iridescenceThicknessMapTransform))),d.transmission>0&&(p.transmission.value=d.transmission,p.transmissionSamplerMap.value=M.texture,p.transmissionSamplerSize.value.set(M.width,M.height),d.transmissionMap&&(p.transmissionMap.value=d.transmissionMap,e(d.transmissionMap,p.transmissionMapTransform)),p.thickness.value=d.thickness,d.thicknessMap&&(p.thicknessMap.value=d.thicknessMap,e(d.thicknessMap,p.thicknessMapTransform)),p.attenuationDistance.value=d.attenuationDistance,p.attenuationColor.value.copy(d.attenuationColor)),d.anisotropy>0&&(p.anisotropyVector.value.set(d.anisotropy*Math.cos(d.anisotropyRotation),d.anisotropy*Math.sin(d.anisotropyRotation)),d.anisotropyMap&&(p.anisotropyMap.value=d.anisotropyMap,e(d.anisotropyMap,p.anisotropyMapTransform))),p.specularIntensity.value=d.specularIntensity,p.specularColor.value.copy(d.specularColor),d.specularColorMap&&(p.specularColorMap.value=d.specularColorMap,e(d.specularColorMap,p.specularColorMapTransform)),d.specularIntensityMap&&(p.specularIntensityMap.value=d.specularIntensityMap,e(d.specularIntensityMap,p.specularIntensityMapTransform))}function g(p,d){d.matcap&&(p.matcap.value=d.matcap)}function x(p,d){const M=t.get(d).light;p.referencePosition.value.setFromMatrixPosition(M.matrixWorld),p.nearDistance.value=M.shadow.camera.near,p.farDistance.value=M.shadow.camera.far}return{refreshFogUniforms:n,refreshMaterialUniforms:s}}function N_(i,t,e,n){let s={},r={},a=[];const o=e.isWebGL2?i.getParameter(i.MAX_UNIFORM_BUFFER_BINDINGS):0;function c(M,v){const _=v.program;n.uniformBlockBinding(M,_)}function l(M,v){let _=s[M.id];_===void 0&&(g(M),_=h(M),s[M.id]=_,M.addEventListener("dispose",p));const y=v.program;n.updateUBOMapping(M,y);const A=t.render.frame;r[M.id]!==A&&(u(M),r[M.id]=A)}function h(M){const v=f();M.__bindingPointIndex=v;const _=i.createBuffer(),y=M.__size,A=M.usage;return i.bindBuffer(i.UNIFORM_BUFFER,_),i.bufferData(i.UNIFORM_BUFFER,y,A),i.bindBuffer(i.UNIFORM_BUFFER,null),i.bindBufferBase(i.UNIFORM_BUFFER,v,_),_}function f(){for(let M=0;M0&&(_+=y-A),M.__size=_,M.__cache={},this}function x(M){const v={boundary:0,storage:0};return typeof M=="number"||typeof M=="boolean"?(v.boundary=4,v.storage=4):M.isVector2?(v.boundary=8,v.storage=8):M.isVector3||M.isColor?(v.boundary=16,v.storage=12):M.isVector4?(v.boundary=16,v.storage=16):M.isMatrix3?(v.boundary=48,v.storage=48):M.isMatrix4?(v.boundary=64,v.storage=64):M.isTexture?console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group."):console.warn("THREE.WebGLRenderer: Unsupported uniform value type.",M),v}function p(M){const v=M.target;v.removeEventListener("dispose",p);const _=a.indexOf(v.__bindingPointIndex);a.splice(_,1),i.deleteBuffer(s[v.id]),delete s[v.id],delete r[v.id]}function d(){for(const M in s)i.deleteBuffer(s[M]);a=[],s={},r={}}return{bind:c,update:l,dispose:d}}class Zo{constructor(t={}){const{canvas:e=Lu(),context:n=null,depth:s=!0,stencil:r=!0,alpha:a=!1,antialias:o=!1,premultipliedAlpha:c=!0,preserveDrawingBuffer:l=!1,powerPreference:h="default",failIfMajorPerformanceCaveat:f=!1}=t;this.isWebGLRenderer=!0;let u;n!==null?u=n.getContextAttributes().alpha:u=a;const m=new Uint32Array(4),g=new Int32Array(4);let x=null,p=null;const d=[],M=[];this.domElement=e,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this._outputColorSpace=Me,this._useLegacyLights=!1,this.toneMapping=kn,this.toneMappingExposure=1;const v=this;let _=!1,y=0,A=0,T=null,P=-1,E=null;const S=new pe,D=new pe;let I=null;const B=new qt(0);let R=0,O=e.width,F=e.height,Y=1,q=null,Z=null;const K=new pe(0,0,O,F),et=new pe(0,0,O,F);let nt=!1;const X=new ua;let $=!1,ct=!1,gt=null;const _t=new Jt,Lt=new kt,It=new U,At={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};function Xt(){return T===null?Y:1}let z=n;function Re(w,N){for(let G=0;G{function lt(){if(k.forEach(function(mt){Ft.get(mt).currentProgram.isReady()&&k.delete(mt)}),k.size===0){H(w);return}setTimeout(lt,10)}vt.get("KHR_parallel_shader_compile")!==null?lt():setTimeout(lt,10)})};let te=null;function xe(w){te&&te(w)}function Pe(){Le.stop()}function ee(){Le.start()}const Le=new Yl;Le.setAnimationLoop(xe),typeof self<"u"&&Le.setContext(self),this.setAnimationLoop=function(w){te=w,Ht.setAnimationLoop(w),w===null?Le.stop():Le.start()},Ht.addEventListener("sessionstart",Pe),Ht.addEventListener("sessionend",ee),this.render=function(w,N){if(N!==void 0&&N.isCamera!==!0){console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(_===!0)return;w.matrixWorldAutoUpdate===!0&&w.updateMatrixWorld(),N.parent===null&&N.matrixWorldAutoUpdate===!0&&N.updateMatrixWorld(),Ht.enabled===!0&&Ht.isPresenting===!0&&(Ht.cameraAutoUpdate===!0&&Ht.updateCamera(N),N=Ht.getCamera()),w.isScene===!0&&w.onBeforeRender(v,w,N,T),p=yt.get(w,M.length),p.init(),M.push(p),_t.multiplyMatrices(N.projectionMatrix,N.matrixWorldInverse),X.setFromProjectionMatrix(_t),ct=this.localClippingEnabled,$=Bt.init(this.clippingPlanes,ct),x=ut.get(w,d.length),x.init(),d.push(x),un(w,N,0,v.sortObjects),x.finish(),v.sortObjects===!0&&x.sort(q,Z),this.info.render.frame++,$===!0&&Bt.beginShadows();const G=p.state.shadowsArray;if(j.render(G,w,N),$===!0&&Bt.endShadows(),this.info.autoReset===!0&&this.info.reset(),$t.render(x,w),p.setupLights(v._useLegacyLights),N.isArrayCamera){const k=N.cameras;for(let H=0,lt=k.length;H0?p=M[M.length-1]:p=null,d.pop(),d.length>0?x=d[d.length-1]:x=null};function un(w,N,G,k){if(w.visible===!1)return;if(w.layers.test(N.layers)){if(w.isGroup)G=w.renderOrder;else if(w.isLOD)w.autoUpdate===!0&&w.update(N);else if(w.isLight)p.pushLight(w),w.castShadow&&p.pushShadow(w);else if(w.isSprite){if(!w.frustumCulled||X.intersectsSprite(w)){k&&It.setFromMatrixPosition(w.matrixWorld).applyMatrix4(_t);const mt=tt.update(w),St=w.material;St.visible&&x.push(w,mt,St,G,It.z,null)}}else if((w.isMesh||w.isLine||w.isPoints)&&(!w.frustumCulled||X.intersectsObject(w))){const mt=tt.update(w),St=w.material;if(k&&(w.boundingSphere!==void 0?(w.boundingSphere===null&&w.computeBoundingSphere(),It.copy(w.boundingSphere.center)):(mt.boundingSphere===null&&mt.computeBoundingSphere(),It.copy(mt.boundingSphere.center)),It.applyMatrix4(w.matrixWorld).applyMatrix4(_t)),Array.isArray(St)){const wt=mt.groups;for(let zt=0,Pt=wt.length;zt0&&ch(H,lt,N,G),k&&dt.viewport(S.copy(k)),H.length>0&&Rs(H,N,G),lt.length>0&&Rs(lt,N,G),mt.length>0&&Rs(mt,N,G),dt.buffers.depth.setTest(!0),dt.buffers.depth.setMask(!0),dt.buffers.color.setMask(!0),dt.setPolygonOffset(!1)}function ch(w,N,G,k){if((G.isScene===!0?G.overrideMaterial:null)!==null)return;const lt=Rt.isWebGL2;gt===null&&(gt=new ai(1,1,{generateMipmaps:!0,type:vt.has("EXT_color_buffer_half_float")?Ts:Wn,minFilter:ys,samples:lt?4:0})),v.getDrawingBufferSize(Lt),lt?gt.setSize(Lt.x,Lt.y):gt.setSize(wr(Lt.x),wr(Lt.y));const mt=v.getRenderTarget();v.setRenderTarget(gt),v.getClearColor(B),R=v.getClearAlpha(),R<1&&v.setClearColor(16777215,.5),v.clear();const St=v.toneMapping;v.toneMapping=kn,Rs(w,G,k),C.updateMultisampleRenderTarget(gt),C.updateRenderTargetMipmap(gt);let wt=!1;for(let zt=0,Pt=N.length;zt0),Ut=!!G.morphAttributes.position,he=!!G.morphAttributes.normal,Be=!!G.morphAttributes.color;let ve=kn;k.toneMapped&&(T===null||T.isXRRenderTarget===!0)&&(ve=v.toneMapping);const gn=G.morphAttributes.position||G.morphAttributes.normal||G.morphAttributes.color,oe=gn!==void 0?gn.length:0,Vt=Ft.get(k),Vr=p.state.lights;if($===!0&&(ct===!0||w!==E)){const We=w===E&&k.id===P;Bt.setState(k,w,We)}let le=!1;k.version===Vt.__version?(Vt.needsLights&&Vt.lightsStateVersion!==Vr.state.version||Vt.outputColorSpace!==St||H.isBatchedMesh&&Vt.batching===!1||!H.isBatchedMesh&&Vt.batching===!0||H.isInstancedMesh&&Vt.instancing===!1||!H.isInstancedMesh&&Vt.instancing===!0||H.isSkinnedMesh&&Vt.skinning===!1||!H.isSkinnedMesh&&Vt.skinning===!0||H.isInstancedMesh&&Vt.instancingColor===!0&&H.instanceColor===null||H.isInstancedMesh&&Vt.instancingColor===!1&&H.instanceColor!==null||Vt.envMap!==wt||k.fog===!0&&Vt.fog!==lt||Vt.numClippingPlanes!==void 0&&(Vt.numClippingPlanes!==Bt.numPlanes||Vt.numIntersection!==Bt.numIntersection)||Vt.vertexAlphas!==zt||Vt.vertexTangents!==Pt||Vt.morphTargets!==Ut||Vt.morphNormals!==he||Vt.morphColors!==Be||Vt.toneMapping!==ve||Rt.isWebGL2===!0&&Vt.morphTargetsCount!==oe)&&(le=!0):(le=!0,Vt.__version=k.version);let Yn=Vt.currentProgram;le===!0&&(Yn=Ps(k,N,H));let Ta=!1,ns=!1,Gr=!1;const Te=Yn.getUniforms(),qn=Vt.uniforms;if(dt.useProgram(Yn.program)&&(Ta=!0,ns=!0,Gr=!0),k.id!==P&&(P=k.id,ns=!0),Ta||E!==w){Te.setValue(z,"projectionMatrix",w.projectionMatrix),Te.setValue(z,"viewMatrix",w.matrixWorldInverse);const We=Te.map.cameraPosition;We!==void 0&&We.setValue(z,It.setFromMatrixPosition(w.matrixWorld)),Rt.logarithmicDepthBuffer&&Te.setValue(z,"logDepthBufFC",2/(Math.log(w.far+1)/Math.LN2)),(k.isMeshPhongMaterial||k.isMeshToonMaterial||k.isMeshLambertMaterial||k.isMeshBasicMaterial||k.isMeshStandardMaterial||k.isShaderMaterial)&&Te.setValue(z,"isOrthographic",w.isOrthographicCamera===!0),E!==w&&(E=w,ns=!0,Gr=!0)}if(H.isSkinnedMesh){Te.setOptional(z,H,"bindMatrix"),Te.setOptional(z,H,"bindMatrixInverse");const We=H.skeleton;We&&(Rt.floatVertexTextures?(We.boneTexture===null&&We.computeBoneTexture(),Te.setValue(z,"boneTexture",We.boneTexture,C)):console.warn("THREE.WebGLRenderer: SkinnedMesh can only be used with WebGL 2. With WebGL 1 OES_texture_float and vertex textures support is required."))}H.isBatchedMesh&&(Te.setOptional(z,H,"batchingTexture"),Te.setValue(z,"batchingTexture",H._matricesTexture,C));const kr=G.morphAttributes;if((kr.position!==void 0||kr.normal!==void 0||kr.color!==void 0&&Rt.isWebGL2===!0)&&Wt.update(H,G,Yn),(ns||Vt.receiveShadow!==H.receiveShadow)&&(Vt.receiveShadow=H.receiveShadow,Te.setValue(z,"receiveShadow",H.receiveShadow)),k.isMeshGouraudMaterial&&k.envMap!==null&&(qn.envMap.value=wt,qn.flipEnvMap.value=wt.isCubeTexture&&wt.isRenderTargetTexture===!1?-1:1),ns&&(Te.setValue(z,"toneMappingExposure",v.toneMappingExposure),Vt.needsLights&&hh(qn,Gr),lt&&k.fog===!0&&at.refreshFogUniforms(qn,lt),at.refreshMaterialUniforms(qn,k,Y,F,gt),Er.upload(z,Sa(Vt),qn,C)),k.isShaderMaterial&&k.uniformsNeedUpdate===!0&&(Er.upload(z,Sa(Vt),qn,C),k.uniformsNeedUpdate=!1),k.isSpriteMaterial&&Te.setValue(z,"center",H.center),Te.setValue(z,"modelViewMatrix",H.modelViewMatrix),Te.setValue(z,"normalMatrix",H.normalMatrix),Te.setValue(z,"modelMatrix",H.matrixWorld),k.isShaderMaterial||k.isRawShaderMaterial){const We=k.uniformsGroups;for(let Wr=0,fh=We.length;Wr0&&C.useMultisampledRTT(w)===!1?H=Ft.get(w).__webglMultisampledFramebuffer:Array.isArray(Pt)?H=Pt[G]:H=Pt,S.copy(w.viewport),D.copy(w.scissor),I=w.scissorTest}else S.copy(K).multiplyScalar(Y).floor(),D.copy(et).multiplyScalar(Y).floor(),I=nt;if(dt.bindFramebuffer(z.FRAMEBUFFER,H)&&Rt.drawBuffers&&k&&dt.drawBuffers(w,H),dt.viewport(S),dt.scissor(D),dt.setScissorTest(I),lt){const wt=Ft.get(w.texture);z.framebufferTexture2D(z.FRAMEBUFFER,z.COLOR_ATTACHMENT0,z.TEXTURE_CUBE_MAP_POSITIVE_X+N,wt.__webglTexture,G)}else if(mt){const wt=Ft.get(w.texture),zt=N||0;z.framebufferTextureLayer(z.FRAMEBUFFER,z.COLOR_ATTACHMENT0,wt.__webglTexture,G||0,zt)}P=-1},this.readRenderTargetPixels=function(w,N,G,k,H,lt,mt){if(!(w&&w.isWebGLRenderTarget)){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let St=Ft.get(w).__webglFramebuffer;if(w.isWebGLCubeRenderTarget&&mt!==void 0&&(St=St[mt]),St){dt.bindFramebuffer(z.FRAMEBUFFER,St);try{const wt=w.texture,zt=wt.format,Pt=wt.type;if(zt!==cn&&ft.convert(zt)!==z.getParameter(z.IMPLEMENTATION_COLOR_READ_FORMAT)){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}const Ut=Pt===Ts&&(vt.has("EXT_color_buffer_half_float")||Rt.isWebGL2&&vt.has("EXT_color_buffer_float"));if(Pt!==Wn&&ft.convert(Pt)!==z.getParameter(z.IMPLEMENTATION_COLOR_READ_TYPE)&&!(Pt===Hn&&(Rt.isWebGL2||vt.has("OES_texture_float")||vt.has("WEBGL_color_buffer_float")))&&!Ut){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");return}N>=0&&N<=w.width-k&&G>=0&&G<=w.height-H&&z.readPixels(N,G,k,H,ft.convert(zt),ft.convert(Pt),lt)}finally{const wt=T!==null?Ft.get(T).__webglFramebuffer:null;dt.bindFramebuffer(z.FRAMEBUFFER,wt)}}},this.copyFramebufferToTexture=function(w,N,G=0){const k=Math.pow(2,-G),H=Math.floor(N.image.width*k),lt=Math.floor(N.image.height*k);C.setTexture2D(N,0),z.copyTexSubImage2D(z.TEXTURE_2D,G,0,0,w.x,w.y,H,lt),dt.unbindTexture()},this.copyTextureToTexture=function(w,N,G,k=0){const H=N.image.width,lt=N.image.height,mt=ft.convert(G.format),St=ft.convert(G.type);C.setTexture2D(G,0),z.pixelStorei(z.UNPACK_FLIP_Y_WEBGL,G.flipY),z.pixelStorei(z.UNPACK_PREMULTIPLY_ALPHA_WEBGL,G.premultiplyAlpha),z.pixelStorei(z.UNPACK_ALIGNMENT,G.unpackAlignment),N.isDataTexture?z.texSubImage2D(z.TEXTURE_2D,k,w.x,w.y,H,lt,mt,St,N.image.data):N.isCompressedTexture?z.compressedTexSubImage2D(z.TEXTURE_2D,k,w.x,w.y,N.mipmaps[0].width,N.mipmaps[0].height,mt,N.mipmaps[0].data):z.texSubImage2D(z.TEXTURE_2D,k,w.x,w.y,mt,St,N.image),k===0&&G.generateMipmaps&&z.generateMipmap(z.TEXTURE_2D),dt.unbindTexture()},this.copyTextureToTexture3D=function(w,N,G,k,H=0){if(v.isWebGL1Renderer){console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: can only be used with WebGL2.");return}const lt=w.max.x-w.min.x+1,mt=w.max.y-w.min.y+1,St=w.max.z-w.min.z+1,wt=ft.convert(k.format),zt=ft.convert(k.type);let Pt;if(k.isData3DTexture)C.setTexture3D(k,0),Pt=z.TEXTURE_3D;else if(k.isDataArrayTexture||k.isCompressedArrayTexture)C.setTexture2DArray(k,0),Pt=z.TEXTURE_2D_ARRAY;else{console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.");return}z.pixelStorei(z.UNPACK_FLIP_Y_WEBGL,k.flipY),z.pixelStorei(z.UNPACK_PREMULTIPLY_ALPHA_WEBGL,k.premultiplyAlpha),z.pixelStorei(z.UNPACK_ALIGNMENT,k.unpackAlignment);const Ut=z.getParameter(z.UNPACK_ROW_LENGTH),he=z.getParameter(z.UNPACK_IMAGE_HEIGHT),Be=z.getParameter(z.UNPACK_SKIP_PIXELS),ve=z.getParameter(z.UNPACK_SKIP_ROWS),gn=z.getParameter(z.UNPACK_SKIP_IMAGES),oe=G.isCompressedTexture?G.mipmaps[H]:G.image;z.pixelStorei(z.UNPACK_ROW_LENGTH,oe.width),z.pixelStorei(z.UNPACK_IMAGE_HEIGHT,oe.height),z.pixelStorei(z.UNPACK_SKIP_PIXELS,w.min.x),z.pixelStorei(z.UNPACK_SKIP_ROWS,w.min.y),z.pixelStorei(z.UNPACK_SKIP_IMAGES,w.min.z),G.isDataTexture||G.isData3DTexture?z.texSubImage3D(Pt,H,N.x,N.y,N.z,lt,mt,St,wt,zt,oe.data):G.isCompressedArrayTexture?(console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: untested support for compressed srcTexture."),z.compressedTexSubImage3D(Pt,H,N.x,N.y,N.z,lt,mt,St,wt,oe.data)):z.texSubImage3D(Pt,H,N.x,N.y,N.z,lt,mt,St,wt,zt,oe),z.pixelStorei(z.UNPACK_ROW_LENGTH,Ut),z.pixelStorei(z.UNPACK_IMAGE_HEIGHT,he),z.pixelStorei(z.UNPACK_SKIP_PIXELS,Be),z.pixelStorei(z.UNPACK_SKIP_ROWS,ve),z.pixelStorei(z.UNPACK_SKIP_IMAGES,gn),H===0&&k.generateMipmaps&&z.generateMipmap(Pt),dt.unbindTexture()},this.initTexture=function(w){w.isCubeTexture?C.setTextureCube(w,0):w.isData3DTexture?C.setTexture3D(w,0):w.isDataArrayTexture||w.isCompressedArrayTexture?C.setTexture2DArray(w,0):C.setTexture2D(w,0),dt.unbindTexture()},this.resetState=function(){y=0,A=0,T=null,dt.reset(),Ot.reset()},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return bn}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(t){this._outputColorSpace=t;const e=this.getContext();e.drawingBufferColorSpace=t===aa?"display-p3":"srgb",e.unpackColorSpace=jt.workingColorSpace===Or?"display-p3":"srgb"}get outputEncoding(){return console.warn("THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead."),this.outputColorSpace===Me?ri:Dl}set outputEncoding(t){console.warn("THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead."),this.outputColorSpace=t===ri?Me:Cn}get useLegacyLights(){return console.warn("THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733."),this._useLegacyLights}set useLegacyLights(t){console.warn("THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733."),this._useLegacyLights=t}}class F_ extends Zo{}F_.prototype.isWebGL1Renderer=!0;class B_ extends Ce{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),t.background!==null&&(this.background=t.background.clone()),t.environment!==null&&(this.environment=t.environment.clone()),t.fog!==null&&(this.fog=t.fog.clone()),this.backgroundBlurriness=t.backgroundBlurriness,this.backgroundIntensity=t.backgroundIntensity,t.overrideMaterial!==null&&(this.overrideMaterial=t.overrideMaterial.clone()),this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return this.fog!==null&&(e.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(e.object.backgroundIntensity=this.backgroundIntensity),e}}class th extends Ce{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new qt(t),this.intensity=e}dispose(){}copy(t,e){return super.copy(t,e),this.color.copy(t.color),this.intensity=t.intensity,this}toJSON(t){const e=super.toJSON(t);return e.object.color=this.color.getHex(),e.object.intensity=this.intensity,this.groundColor!==void 0&&(e.object.groundColor=this.groundColor.getHex()),this.distance!==void 0&&(e.object.distance=this.distance),this.angle!==void 0&&(e.object.angle=this.angle),this.decay!==void 0&&(e.object.decay=this.decay),this.penumbra!==void 0&&(e.object.penumbra=this.penumbra),this.shadow!==void 0&&(e.object.shadow=this.shadow.toJSON()),e}}const Mo=new Jt,Yc=new U,qc=new U;class z_{constructor(t){this.camera=t,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new kt(512,512),this.map=null,this.mapPass=null,this.matrix=new Jt,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new ua,this._frameExtents=new kt(1,1),this._viewportCount=1,this._viewports=[new pe(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,n=this.matrix;Yc.setFromMatrixPosition(t.matrixWorld),e.position.copy(Yc),qc.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(qc),e.updateMatrixWorld(),Mo.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Mo),n.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),n.multiply(Mo)}getViewport(t){return this._viewports[t]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(t){return this.camera=t.camera.clone(),this.bias=t.bias,this.radius=t.radius,this.mapSize.copy(t.mapSize),this}clone(){return new this.constructor().copy(this)}toJSON(){const t={};return this.bias!==0&&(t.bias=this.bias),this.normalBias!==0&&(t.normalBias=this.normalBias),this.radius!==1&&(t.radius=this.radius),(this.mapSize.x!==512||this.mapSize.y!==512)&&(t.mapSize=this.mapSize.toArray()),t.camera=this.camera.toJSON(!1).object,delete t.camera.matrix,t}}class H_ extends z_{constructor(){super(new ql(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class V_ extends th{constructor(t,e){super(t,e),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(Ce.DEFAULT_UP),this.updateMatrix(),this.target=new Ce,this.shadow=new H_}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}class G_ extends th{constructor(t,e){super(t,e),this.isAmbientLight=!0,this.type="AmbientLight"}}class k_{constructor(t=!0){this.autoStart=t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=Zc(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running)return this.start(),0;if(this.running){const e=Zc();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}}function Zc(){return(typeof performance>"u"?Date:performance).now()}class W_{constructor(t,e,n=0,s=1/0){this.ray=new la(t,e),this.near=n,this.far=s,this.camera=null,this.layers=new ha,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(t,e){this.ray.set(t,e)}setFromCamera(t,e){e.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(e.matrixWorld),this.ray.direction.set(t.x,t.y,.5).unproject(e).sub(this.ray.origin).normalize(),this.camera=e):e.isOrthographicCamera?(this.ray.origin.set(t.x,t.y,(e.near+e.far)/(e.near-e.far)).unproject(e),this.ray.direction.set(0,0,-1).transformDirection(e.matrixWorld),this.camera=e):console.error("THREE.Raycaster: Unsupported camera type: "+e.type)}intersectObject(t,e=!0,n=[]){return Ko(t,this,n,e),n.sort(Kc),n}intersectObjects(t,e=!0,n=[]){for(let s=0,r=t.length;s0==m>h&&(m=h,e.value=(m-h)/r),m}function Qc(i,t,e,n,s=1/0,r,a){n=Math.max(1e-4,n);const o=2/n,c=o*r,l=1/(1+c+.48*c*c+.235*c*c*c);let h=t.x,f=t.y,u=t.z,m=i.x-h,g=i.y-f,x=i.z-u;const p=h,d=f,M=u,v=s*n,_=v*v,y=m*m+g*g+x*x;if(y>_){const O=Math.sqrt(y);m=m/O*v,g=g/O*v,x=x/O*v}h=i.x-m,f=i.y-g,u=i.z-x;const A=(e.x+o*m)*r,T=(e.y+o*g)*r,P=(e.z+o*x)*r;e.x=(e.x-o*A)*l,e.y=(e.y-o*T)*l,e.z=(e.z-o*P)*l,a.x=h+(m+A)*l,a.y=f+(g+T)*l,a.z=u+(x+P)*l;const E=p-i.x,S=d-i.y,D=M-i.z,I=a.x-p,B=a.y-d,R=a.z-M;return E*I+S*B+D*R>0&&(a.x=p,a.y=d,a.z=M,e.x=(a.x-p)/r,e.y=(a.y-d)/r,e.z=(a.z-M)/r),a}function So(i,t){t.set(0,0),i.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=i.length,t.y/=i.length}function yo(i,t){return Fn(i)?(console.warn(`${t} is not supported in OrthographicCamera`),!0):!1}class Y_{constructor(){this._listeners={}}addEventListener(t,e){const n=this._listeners;n[t]===void 0&&(n[t]=[]),n[t].indexOf(e)===-1&&n[t].push(e)}hasEventListener(t,e){const n=this._listeners;return n[t]!==void 0&&n[t].indexOf(e)!==-1}removeEventListener(t,e){const s=this._listeners[t];if(s!==void 0){const r=s.indexOf(e);r!==-1&&s.splice(r,1)}}removeAllEventListeners(t){if(!t){this._listeners={};return}Array.isArray(this._listeners[t])&&(this._listeners[t].length=0)}dispatchEvent(t){const n=this._listeners[t.type];if(n!==void 0){t.target=this;const s=n.slice(0);for(let r=0,a=s.length;r{},this._enabled=!0,this._state=W.NONE,this._viewport=null,this._changedDolly=0,this._changedZoom=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=new DOMRect,this._isDragging=!1,this._dragNeedsUpdate=!0,this._activePointers=[],this._lockedPointer=null,this._interactiveArea=new DOMRect(0,0,1,1),this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._lastDollyDirection=Ai.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new Mt.Vector3,this._focalOffsetVelocity=new Mt.Vector3,this._zoomVelocity={value:0},this._truckInternal=(_,y,A)=>{let T,P;if(Jn(this._camera)){const E=Dt.copy(this._camera.position).sub(this._target),S=this._camera.getEffectiveFOV()*as,D=E.length()*Math.tan(S*.5);T=this.truckSpeed*_*D/this._elementRect.height,P=this.truckSpeed*y*D/this._elementRect.height}else if(Fn(this._camera)){const E=this._camera;T=_*(E.right-E.left)/E.zoom/this._elementRect.width,P=y*(E.top-E.bottom)/E.zoom/this._elementRect.height}else return;this.verticalDragToForward?(A?this.setFocalOffset(this._focalOffsetEnd.x+T,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(T,0,!0),this.forward(-P,!0)):A?this.setFocalOffset(this._focalOffsetEnd.x+T,this._focalOffsetEnd.y+P,this._focalOffsetEnd.z,!0):this.truck(T,P,!0)},this._rotateInternal=(_,y)=>{const A=bi*this.azimuthRotateSpeed*_/this._elementRect.height,T=bi*this.polarRotateSpeed*y/this._elementRect.height;this.rotate(A,T,!0)},this._dollyInternal=(_,y,A)=>{const T=Math.pow(.95,-_*this.dollySpeed),P=this._sphericalEnd.radius,E=this._sphericalEnd.radius*T,S=rn(E,this.minDistance,this.maxDistance),D=S-E;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(E,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(D,!0),this._dollyToNoClamp(S,!0)):this._dollyToNoClamp(S,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?E:S)-P,this._dollyControlCoord.set(y,A)),this._lastDollyDirection=Math.sign(-_)},this._zoomInternal=(_,y,A)=>{const T=Math.pow(.95,_*this.dollySpeed),P=this._zoom,E=this._zoom*T;this.zoomTo(E,!0),this.dollyToCursor&&(this._changedZoom+=E-P,this._dollyControlCoord.set(y,A))},typeof Mt>"u"&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=t,this._yAxisUpSpace=new Mt.Quaternion().setFromUnitVectors(this._camera.up,ir),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=W.NONE,this._target=new Mt.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new Mt.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new Mt.Spherical().setFromVector3(Dt.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._lastDistance=this._spherical.radius,this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._lastZoom=this._zoom,this._nearPlaneCorners=[new Mt.Vector3,new Mt.Vector3,new Mt.Vector3,new Mt.Vector3],this._updateNearPlaneCorners(),this._boundary=new Mt.Box3(new Mt.Vector3(-1/0,-1/0,-1/0),new Mt.Vector3(1/0,1/0,1/0)),this._cameraUp0=this._camera.up.clone(),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlCoord=new Mt.Vector2,this.mouseButtons={left:W.ROTATE,middle:W.DOLLY,right:W.TRUCK,wheel:Jn(this._camera)?W.DOLLY:Fn(this._camera)?W.ZOOM:W.NONE},this.touches={one:W.TOUCH_ROTATE,two:Jn(this._camera)?W.TOUCH_DOLLY_TRUCK:Fn(this._camera)?W.TOUCH_ZOOM_TRUCK:W.NONE,three:W.TOUCH_TRUCK};const n=new Mt.Vector2,s=new Mt.Vector2,r=new Mt.Vector2,a=_=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const T=this._domElement.getBoundingClientRect(),P=_.clientX/T.width,E=_.clientY/T.height;if(Pthis._interactiveArea.right||Ethis._interactiveArea.bottom)return}const y=_.pointerType!=="mouse"?null:(_.buttons&Tt.LEFT)===Tt.LEFT?Tt.LEFT:(_.buttons&Tt.MIDDLE)===Tt.MIDDLE?Tt.MIDDLE:(_.buttons&Tt.RIGHT)===Tt.RIGHT?Tt.RIGHT:null;if(y!==null){const T=this._findPointerByMouseButton(y);T&&this._disposePointer(T)}if((_.buttons&Tt.LEFT)===Tt.LEFT&&this._lockedPointer)return;const A={pointerId:_.pointerId,clientX:_.clientX,clientY:_.clientY,deltaX:0,deltaY:0,mouseButton:y};this._activePointers.push(A),this._domElement.ownerDocument.removeEventListener("pointermove",c,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.addEventListener("pointermove",c,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",h),this._isDragging=!0,x(_)},o=_=>{if(!this._enabled||!this._domElement||this._lockedPointer)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const T=this._domElement.getBoundingClientRect(),P=_.clientX/T.width,E=_.clientY/T.height;if(Pthis._interactiveArea.right||Ethis._interactiveArea.bottom)return}const y=(_.buttons&Tt.LEFT)===Tt.LEFT?Tt.LEFT:(_.buttons&Tt.MIDDLE)===Tt.MIDDLE?Tt.MIDDLE:(_.buttons&Tt.RIGHT)===Tt.RIGHT?Tt.RIGHT:null;if(y!==null){const T=this._findPointerByMouseButton(y);T&&this._disposePointer(T)}const A={pointerId:1,clientX:_.clientX,clientY:_.clientY,deltaX:0,deltaY:0,mouseButton:(_.buttons&Tt.LEFT)===Tt.LEFT?Tt.LEFT:(_.buttons&Tt.MIDDLE)===Tt.LEFT?Tt.MIDDLE:(_.buttons&Tt.RIGHT)===Tt.LEFT?Tt.RIGHT:null};this._activePointers.push(A),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("mouseup",f),this._domElement.ownerDocument.addEventListener("mousemove",l),this._domElement.ownerDocument.addEventListener("mouseup",f),this._isDragging=!0,x(_)},c=_=>{_.cancelable&&_.preventDefault();const y=_.pointerId,A=this._lockedPointer||this._findPointerById(y);if(A){if(A.clientX=_.clientX,A.clientY=_.clientY,A.deltaX=_.movementX,A.deltaY=_.movementY,this._state=0,_.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(_.buttons&Tt.LEFT)===Tt.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(_.buttons&Tt.MIDDLE)===Tt.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(_.buttons&Tt.RIGHT)===Tt.RIGHT&&(this._state=this._state|this.mouseButtons.right);p()}},l=_=>{const y=this._lockedPointer||this._findPointerById(1);y&&(y.clientX=_.clientX,y.clientY=_.clientY,y.deltaX=_.movementX,y.deltaY=_.movementY,this._state=0,(this._lockedPointer||(_.buttons&Tt.LEFT)===Tt.LEFT)&&(this._state=this._state|this.mouseButtons.left),(_.buttons&Tt.MIDDLE)===Tt.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(_.buttons&Tt.RIGHT)===Tt.RIGHT&&(this._state=this._state|this.mouseButtons.right),p())},h=_=>{const y=this._findPointerById(_.pointerId);if(!(y&&y===this._lockedPointer)){if(y&&this._disposePointer(y),_.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=W.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=W.NONE;d()}},f=()=>{const _=this._findPointerById(1);_&&_===this._lockedPointer||(_&&this._disposePointer(_),this._state=W.NONE,d())};let u=-1;const m=_=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===W.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const E=this._domElement.getBoundingClientRect(),S=_.clientX/E.width,D=_.clientY/E.height;if(Sthis._interactiveArea.right||Dthis._interactiveArea.bottom)return}if(_.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===W.ROTATE||this.mouseButtons.wheel===W.TRUCK){const E=performance.now();u-E<1e3&&this._getClientRect(this._elementRect),u=E}const y=Z_?-1:-3,A=_.deltaMode===1?_.deltaY/y:_.deltaY/(y*10),T=this.dollyToCursor?(_.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,P=this.dollyToCursor?(_.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case W.ROTATE:{this._rotateInternal(_.deltaX,_.deltaY),this._isUserControllingRotate=!0;break}case W.TRUCK:{this._truckInternal(_.deltaX,_.deltaY,!1),this._isUserControllingTruck=!0;break}case W.OFFSET:{this._truckInternal(_.deltaX,_.deltaY,!0),this._isUserControllingOffset=!0;break}case W.DOLLY:{this._dollyInternal(-A,T,P),this._isUserControllingDolly=!0;break}case W.ZOOM:{this._zoomInternal(-A,T,P),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},g=_=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===bs.ACTION.NONE){const y=_ instanceof PointerEvent?_.pointerId:(_ instanceof MouseEvent,0),A=this._findPointerById(y);A&&this._disposePointer(A),this._domElement.ownerDocument.removeEventListener("pointermove",c,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("mouseup",f);return}_.preventDefault()}},x=_=>{if(!this._enabled)return;if(So(this._activePointers,Fe),this._getClientRect(this._elementRect),n.copy(Fe),s.copy(Fe),this._activePointers.length>=2){const A=Fe.x-this._activePointers[1].clientX,T=Fe.y-this._activePointers[1].clientY,P=Math.sqrt(A*A+T*T);r.set(0,P);const E=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,S=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;s.set(E,S)}if(this._state=0,!_)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in _&&_.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else!this._lockedPointer&&(_.buttons&Tt.LEFT)===Tt.LEFT&&(this._state=this._state|this.mouseButtons.left),(_.buttons&Tt.MIDDLE)===Tt.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(_.buttons&Tt.RIGHT)===Tt.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&W.ROTATE)===W.ROTATE||(this._state&W.TOUCH_ROTATE)===W.TOUCH_ROTATE||(this._state&W.TOUCH_DOLLY_ROTATE)===W.TOUCH_DOLLY_ROTATE||(this._state&W.TOUCH_ZOOM_ROTATE)===W.TOUCH_ZOOM_ROTATE)&&(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),((this._state&W.TRUCK)===W.TRUCK||(this._state&W.TOUCH_TRUCK)===W.TOUCH_TRUCK||(this._state&W.TOUCH_DOLLY_TRUCK)===W.TOUCH_DOLLY_TRUCK||(this._state&W.TOUCH_ZOOM_TRUCK)===W.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&W.DOLLY)===W.DOLLY||(this._state&W.TOUCH_DOLLY)===W.TOUCH_DOLLY||(this._state&W.TOUCH_DOLLY_TRUCK)===W.TOUCH_DOLLY_TRUCK||(this._state&W.TOUCH_DOLLY_OFFSET)===W.TOUCH_DOLLY_OFFSET||(this._state&W.TOUCH_DOLLY_ROTATE)===W.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&W.ZOOM)===W.ZOOM||(this._state&W.TOUCH_ZOOM)===W.TOUCH_ZOOM||(this._state&W.TOUCH_ZOOM_TRUCK)===W.TOUCH_ZOOM_TRUCK||(this._state&W.TOUCH_ZOOM_OFFSET)===W.TOUCH_ZOOM_OFFSET||(this._state&W.TOUCH_ZOOM_ROTATE)===W.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&W.OFFSET)===W.OFFSET||(this._state&W.TOUCH_OFFSET)===W.TOUCH_OFFSET||(this._state&W.TOUCH_DOLLY_OFFSET)===W.TOUCH_DOLLY_OFFSET||(this._state&W.TOUCH_ZOOM_OFFSET)===W.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},p=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,So(this._activePointers,Fe);const y=this._domElement&&document.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,A=y?-y.deltaX:s.x-Fe.x,T=y?-y.deltaY:s.y-Fe.y;if(s.copy(Fe),((this._state&W.ROTATE)===W.ROTATE||(this._state&W.TOUCH_ROTATE)===W.TOUCH_ROTATE||(this._state&W.TOUCH_DOLLY_ROTATE)===W.TOUCH_DOLLY_ROTATE||(this._state&W.TOUCH_ZOOM_ROTATE)===W.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(A,T),this._isUserControllingRotate=!0),(this._state&W.DOLLY)===W.DOLLY||(this._state&W.ZOOM)===W.ZOOM){const P=this.dollyToCursor?(n.x-this._elementRect.x)/this._elementRect.width*2-1:0,E=this.dollyToCursor?(n.y-this._elementRect.y)/this._elementRect.height*-2+1:0,S=this.dollyDragInverted?-1:1;(this._state&W.DOLLY)===W.DOLLY?(this._dollyInternal(S*T*nr,P,E),this._isUserControllingDolly=!0):(this._zoomInternal(S*T*nr,P,E),this._isUserControllingZoom=!0)}if((this._state&W.TOUCH_DOLLY)===W.TOUCH_DOLLY||(this._state&W.TOUCH_ZOOM)===W.TOUCH_ZOOM||(this._state&W.TOUCH_DOLLY_TRUCK)===W.TOUCH_DOLLY_TRUCK||(this._state&W.TOUCH_ZOOM_TRUCK)===W.TOUCH_ZOOM_TRUCK||(this._state&W.TOUCH_DOLLY_OFFSET)===W.TOUCH_DOLLY_OFFSET||(this._state&W.TOUCH_ZOOM_OFFSET)===W.TOUCH_ZOOM_OFFSET||(this._state&W.TOUCH_DOLLY_ROTATE)===W.TOUCH_DOLLY_ROTATE||(this._state&W.TOUCH_ZOOM_ROTATE)===W.TOUCH_ZOOM_ROTATE){const P=Fe.x-this._activePointers[1].clientX,E=Fe.y-this._activePointers[1].clientY,S=Math.sqrt(P*P+E*E),D=r.y-S;r.set(0,S);const I=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,B=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&W.TOUCH_DOLLY)===W.TOUCH_DOLLY||(this._state&W.TOUCH_DOLLY_ROTATE)===W.TOUCH_DOLLY_ROTATE||(this._state&W.TOUCH_DOLLY_TRUCK)===W.TOUCH_DOLLY_TRUCK||(this._state&W.TOUCH_DOLLY_OFFSET)===W.TOUCH_DOLLY_OFFSET?(this._dollyInternal(D*nr,I,B),this._isUserControllingDolly=!0):(this._zoomInternal(D*nr,I,B),this._isUserControllingZoom=!0)}((this._state&W.TRUCK)===W.TRUCK||(this._state&W.TOUCH_TRUCK)===W.TOUCH_TRUCK||(this._state&W.TOUCH_DOLLY_TRUCK)===W.TOUCH_DOLLY_TRUCK||(this._state&W.TOUCH_ZOOM_TRUCK)===W.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(A,T,!1),this._isUserControllingTruck=!0),((this._state&W.OFFSET)===W.OFFSET||(this._state&W.TOUCH_OFFSET)===W.TOUCH_OFFSET||(this._state&W.TOUCH_DOLLY_OFFSET)===W.TOUCH_DOLLY_OFFSET||(this._state&W.TOUCH_ZOOM_OFFSET)===W.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(A,T,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},d=()=>{So(this._activePointers,Fe),s.copy(Fe),this._dragNeedsUpdate=!1,(this._activePointers.length===0||this._activePointers.length===1&&this._activePointers[0]===this._lockedPointer)&&(this._isDragging=!1),this._activePointers.length===0&&this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointermove",c,{passive:!1}),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.removeEventListener("mouseup",f),this.dispatchEvent({type:"controlend"}))};this.lockPointer=()=>{!this._enabled||!this._domElement||(this.cancel(),this._lockedPointer={pointerId:-1,clientX:0,clientY:0,deltaX:0,deltaY:0,mouseButton:null},this._activePointers.push(this._lockedPointer),this._domElement.ownerDocument.removeEventListener("pointermove",c,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",M),this._domElement.ownerDocument.addEventListener("pointerlockerror",v),this._domElement.ownerDocument.addEventListener("pointermove",c,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",h),x())},this.unlockPointer=()=>{this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),document.exitPointerLock(),this.cancel(),this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointerlockchange",M),this._domElement.ownerDocument.removeEventListener("pointerlockerror",v))};const M=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},v=()=>{this.unlockPointer()};this._addAllEventListeners=_=>{this._domElement=_,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",a),K_&&this._domElement.addEventListener("mousedown",o),this._domElement.addEventListener("pointercancel",h),this._domElement.addEventListener("wheel",m,{passive:!1}),this._domElement.addEventListener("contextmenu",g)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",a),this._domElement.removeEventListener("mousedown",o),this._domElement.removeEventListener("pointercancel",h),this._domElement.removeEventListener("wheel",m,{passive:!1}),this._domElement.removeEventListener("contextmenu",g),this._domElement.ownerDocument.removeEventListener("pointermove",c,{passive:!1}),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.removeEventListener("mouseup",f),this._domElement.ownerDocument.removeEventListener("pointerlockchange",M),this._domElement.ownerDocument.removeEventListener("pointerlockerror",v))},this.cancel=()=>{this._state!==W.NONE&&(this._state=W.NONE,this._activePointers.length=0,d())},e&&this.connect(e),this.update(0)}get camera(){return this._camera}set camera(t){this._camera=t,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(t){this._enabled=t,this._domElement&&(t?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(t){this._spherical.radius===t&&this._sphericalEnd.radius===t||(this._spherical.radius=t,this._sphericalEnd.radius=t,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(t){this._spherical.theta===t&&this._sphericalEnd.theta===t||(this._spherical.theta=t,this._sphericalEnd.theta=t,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(t){this._spherical.phi===t&&this._sphericalEnd.phi===t||(this._spherical.phi=t,this._sphericalEnd.phi=t,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(t){this._boundaryEnclosesCamera=t,this._needsUpdate=!0}set interactiveArea(t){this._interactiveArea.width=rn(t.width,0,1),this._interactiveArea.height=rn(t.height,0,1),this._interactiveArea.x=rn(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=rn(t.y,0,1-this._interactiveArea.height)}addEventListener(t,e){super.addEventListener(t,e)}removeEventListener(t,e){super.removeEventListener(t,e)}rotate(t,e,n=!1){return this.rotateTo(this._sphericalEnd.theta+t,this._sphericalEnd.phi+e,n)}rotateAzimuthTo(t,e=!1){return this.rotateTo(t,this._sphericalEnd.phi,e)}rotatePolarTo(t,e=!1){return this.rotateTo(this._sphericalEnd.theta,t,e)}rotateTo(t,e,n=!1){this._isUserControllingRotate=!1;const s=rn(t,this.minAzimuthAngle,this.maxAzimuthAngle),r=rn(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=s,this._sphericalEnd.phi=r,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,n||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const a=!n||Zt(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Zt(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(a)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Ai.NONE,this._changedDolly=0,this._dollyToNoClamp(rn(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const n=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const a=this._collisionTest(),o=Zt(a,this._spherical.radius);if(!(n>t)&&o)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,a)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const r=!e||Zt(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(r)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(hs).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const n=!e||Zt(this._target.x,this._targetEnd.x,this.restThreshold)&&Zt(this._target.y,this._targetEnd.y,this.restThreshold)&&Zt(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}zoom(t,e=!1){return this.zoomTo(this._zoomEnd+t,e)}zoomTo(t,e=!1){this._isUserControllingZoom=!1,this._zoomEnd=rn(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const n=!e||Zt(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(n)}pan(t,e,n=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(t,e,n)}truck(t,e,n=!1){this._camera.updateMatrix(),fn.setFromMatrixColumn(this._camera.matrix,0),dn.setFromMatrixColumn(this._camera.matrix,1),fn.multiplyScalar(t),dn.multiplyScalar(-e);const s=Dt.copy(fn).add(dn),r=Yt.copy(this._targetEnd).add(s);return this.moveTo(r.x,r.y,r.z,n)}forward(t,e=!1){Dt.setFromMatrixColumn(this._camera.matrix,0),Dt.crossVectors(this._camera.up,Dt),Dt.multiplyScalar(t);const n=Yt.copy(this._targetEnd).add(Dt);return this.moveTo(n.x,n.y,n.z,e)}elevate(t,e=!1){return Dt.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+Dt.x,this._targetEnd.y+Dt.y,this._targetEnd.z+Dt.z,e)}moveTo(t,e,n,s=!1){this._isUserControllingTruck=!1;const r=Dt.set(t,e,n).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,r,this.boundaryFriction),this._needsUpdate=!0,s||this._target.copy(this._targetEnd);const a=!s||Zt(this._target.x,this._targetEnd.x,this.restThreshold)&&Zt(this._target.y,this._targetEnd.y,this.restThreshold)&&Zt(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(a)}lookInDirectionOf(t,e,n,s=!1){const o=Dt.set(t,e,n).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius);return this.setPosition(o.x,o.y,o.z,s)}fitToBox(t,e,{cover:n=!1,paddingLeft:s=0,paddingRight:r=0,paddingBottom:a=0,paddingTop:o=0}={}){const c=[],l=t.isBox3?Ci.copy(t):Ci.setFromObject(t);l.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const h=Jc(this._sphericalEnd.theta,jc),f=Jc(this._sphericalEnd.phi,jc);c.push(this.rotateTo(h,f,e));const u=Dt.setFromSpherical(this._sphericalEnd).normalize(),m=sl.setFromUnitVectors(u,To),g=Zt(Math.abs(u.y),1);g&&m.multiply(bo.setFromAxisAngle(ir,h)),m.multiply(this._yAxisUpSpaceInverse);const x=il.makeEmpty();Yt.copy(l.min).applyQuaternion(m),x.expandByPoint(Yt),Yt.copy(l.min).setX(l.max.x).applyQuaternion(m),x.expandByPoint(Yt),Yt.copy(l.min).setY(l.max.y).applyQuaternion(m),x.expandByPoint(Yt),Yt.copy(l.max).setZ(l.min.z).applyQuaternion(m),x.expandByPoint(Yt),Yt.copy(l.min).setZ(l.max.z).applyQuaternion(m),x.expandByPoint(Yt),Yt.copy(l.max).setY(l.min.y).applyQuaternion(m),x.expandByPoint(Yt),Yt.copy(l.max).setX(l.min.x).applyQuaternion(m),x.expandByPoint(Yt),Yt.copy(l.max).applyQuaternion(m),x.expandByPoint(Yt),x.min.x-=s,x.min.y-=a,x.max.x+=r,x.max.y+=o,m.setFromUnitVectors(To,u),g&&m.premultiply(bo.invert()),m.premultiply(this._yAxisUpSpace);const p=x.getSize(Dt),d=x.getCenter(Yt).applyQuaternion(m);if(Jn(this._camera)){const M=this.getDistanceToFitBox(p.x,p.y,p.z,n);c.push(this.moveTo(d.x,d.y,d.z,e)),c.push(this.dollyTo(M,e)),c.push(this.setFocalOffset(0,0,0,e))}else if(Fn(this._camera)){const M=this._camera,v=M.right-M.left,_=M.top-M.bottom,y=n?Math.max(v/p.x,_/p.y):Math.min(v/p.x,_/p.y);c.push(this.moveTo(d.x,d.y,d.z,e)),c.push(this.zoomTo(y,e)),c.push(this.setFocalOffset(0,0,0,e))}return Promise.all(c)}fitToSphere(t,e){const n=[],r=t instanceof Mt.Sphere?Ao.copy(t):bs.createBoundingSphere(t,Ao);if(n.push(this.moveTo(r.center.x,r.center.y,r.center.z,e)),Jn(this._camera)){const a=this.getDistanceToFitSphere(r.radius);n.push(this.dollyTo(a,e))}else if(Fn(this._camera)){const a=this._camera.right-this._camera.left,o=this._camera.top-this._camera.bottom,c=2*r.radius,l=Math.min(a/c,o/c);n.push(this.zoomTo(l,e))}return n.push(this.setFocalOffset(0,0,0,e)),Promise.all(n)}setLookAt(t,e,n,s,r,a,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Ai.NONE,this._changedDolly=0;const c=Yt.set(s,r,a),l=Dt.set(t,e,n);this._targetEnd.copy(c),this._sphericalEnd.setFromVector3(l.sub(c).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,o||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const h=!o||Zt(this._target.x,this._targetEnd.x,this.restThreshold)&&Zt(this._target.y,this._targetEnd.y,this.restThreshold)&&Zt(this._target.z,this._targetEnd.z,this.restThreshold)&&Zt(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Zt(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&Zt(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(h)}lerpLookAt(t,e,n,s,r,a,o,c,l,h,f,u,m,g=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Ai.NONE,this._changedDolly=0;const x=Dt.set(s,r,a),p=Yt.set(t,e,n);Ye.setFromVector3(p.sub(x).applyQuaternion(this._yAxisUpSpace));const d=wi.set(h,f,u),M=Yt.set(o,c,l);us.setFromVector3(M.sub(d).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(x.lerp(d,m));const v=us.theta-Ye.theta,_=us.phi-Ye.phi,y=us.radius-Ye.radius;this._sphericalEnd.set(Ye.radius+y*m,Ye.phi+_*m,Ye.theta+v*m),this.normalizeRotations(),this._needsUpdate=!0,g||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const A=!g||Zt(this._target.x,this._targetEnd.x,this.restThreshold)&&Zt(this._target.y,this._targetEnd.y,this.restThreshold)&&Zt(this._target.z,this._targetEnd.z,this.restThreshold)&&Zt(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Zt(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&Zt(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(A)}setPosition(t,e,n,s=!1){return this.setLookAt(t,e,n,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,s)}setTarget(t,e,n,s=!1){const r=this.getPosition(Dt),a=this.setLookAt(r.x,r.y,r.z,t,e,n,s);return this._sphericalEnd.phi=rn(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),a}setFocalOffset(t,e,n,s=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,n),this._needsUpdate=!0,s||this._focalOffset.copy(this._focalOffsetEnd);const r=!s||Zt(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&Zt(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&Zt(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}setOrbitPoint(t,e,n){this._camera.updateMatrixWorld(),fn.setFromMatrixColumn(this._camera.matrixWorldInverse,0),dn.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Qn.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const s=Dt.set(t,e,n),r=s.distanceTo(this._camera.position),a=s.sub(this._camera.position);fn.multiplyScalar(a.x),dn.multiplyScalar(a.y),Qn.multiplyScalar(a.z),Dt.copy(fn).add(dn).add(Qn),Dt.z=Dt.z+r,this.dollyTo(r,!1),this.setFocalOffset(-Dt.x,Dt.y,-Dt.z,!1),this.moveTo(t,e,n,!1)}setBoundary(t){if(!t){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(t),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(t,e,n,s){if(t===null){this._viewport=null;return}this._viewport=this._viewport||new Mt.Vector4,typeof t=="number"?this._viewport.set(t,e,n,s):this._viewport.copy(t)}getDistanceToFitBox(t,e,n,s=!1){if(yo(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const r=t/e,a=this._camera.getEffectiveFOV()*as,o=this._camera.aspect;return((s?r>o:re.pointerId===t)}_findPointerByMouseButton(t){return this._activePointers.find(e=>e.mouseButton===t)}_disposePointer(t){this._activePointers.splice(this._activePointers.indexOf(t),1)}_encloseToBoundary(t,e,n){const s=e.lengthSq();if(s===0)return t;const r=Yt.copy(e).add(t),o=this._boundary.clampPoint(r,wi).sub(r),c=o.lengthSq();if(c===0)return t.add(e);if(c===s)return t;if(n===0)return t.add(e).add(o);{const l=1+n*c/e.dot(o);return t.add(Yt.copy(e).multiplyScalar(l)).add(o.multiplyScalar(1-n))}}_updateNearPlaneCorners(){if(Jn(this._camera)){const t=this._camera,e=t.near,n=t.getEffectiveFOV()*as,s=Math.tan(n*.5)*e,r=s*t.aspect;this._nearPlaneCorners[0].set(-r,-s,0),this._nearPlaneCorners[1].set(r,-s,0),this._nearPlaneCorners[2].set(r,s,0),this._nearPlaneCorners[3].set(-r,s,0)}else if(Fn(this._camera)){const t=this._camera,e=1/t.zoom,n=t.left*e,s=t.right*e,r=t.top*e,a=t.bottom*e;this._nearPlaneCorners[0].set(n,r,0),this._nearPlaneCorners[1].set(s,r,0),this._nearPlaneCorners[2].set(s,a,0),this._nearPlaneCorners[3].set(n,a,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1)||yo(this._camera,"_collisionTest"))return t;const n=this._getTargetDirection(hs);wo.lookAt(tl,n,this._camera.up);for(let s=0;s<4;s++){const r=Yt.copy(this._nearPlaneCorners[s]);r.applyMatrix4(wo);const a=wi.addVectors(this._target,r);sr.set(a,n),sr.far=this._spherical.radius+1;const o=sr.intersectObjects(this.colliderMeshes);o.length!==0&&o[0].distance{const n=()=>{this.removeEventListener("rest",n),e()};this.addEventListener("rest",n)}))}_addAllEventListeners(t){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(t){console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead.")}get draggingDampingFactor(){return console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead."),0}set draggingDampingFactor(t){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(t,e=new Mt.Sphere){const n=e,s=n.center;Ci.makeEmpty(),t.traverseVisible(a=>{a.isMesh&&Ci.expandByObject(a)}),Ci.getCenter(s);let r=0;return t.traverseVisible(a=>{if(!a.isMesh)return;const o=a,c=o.geometry.clone();c.applyMatrix4(o.matrixWorld);const h=c.attributes.position;for(let f=0,u=h.count;f{const e=this.handlers.slice(0);for(const n of e)n(t)});ht(this,"handlers",[])}add(t){this.handlers.push(t)}remove(t){this.handlers=this.handlers.filter(e=>e!==t)}reset(){this.handlers.length=0}}class pa{constructor(t){ht(this,"isDisposeable",()=>"dispose"in this&&"onDisposed"in this);ht(this,"isResizeable",()=>"resize"in this&&"getSize"in this);ht(this,"isUpdateable",()=>"onAfterUpdate"in this&&"onBeforeUpdate"in this&&"update"in this);ht(this,"isHideable",()=>"visible"in this);ht(this,"isConfigurable",()=>"setup"in this&&"config"in this&&"onSetup"in this);this.components=t}}class ih extends pa{}class ma extends pa{constructor(e){super(e);ht(this,"worlds",new Map);ht(this,"onWorldChanged",new me);ht(this,"currentWorld",null);this.onWorldChanged.add(({world:n,action:s})=>{s==="removed"&&this.worlds.delete(n.uuid)})}}class $_ extends ma{}class j_ extends ma{constructor(){super(...arguments);ht(this,"onAfterUpdate",new me);ht(this,"onBeforeUpdate",new me);ht(this,"onDisposed",new me);ht(this,"onResize",new me)}}const Ss=class Ss extends ih{constructor(e){super(e);ht(this,"_disposedComponents",new Set);ht(this,"enabled",!0);e.add(Ss.uuid,this)}get(){return this._disposedComponents}destroy(e,n=!0,s=!0){e.removeFromParent();const r=e;r.dispose&&r.dispose(),this.disposeGeometryAndMaterials(e,n),s&&r.children&&r.children.length&&this.disposeChildren(r),e.children.length=0}disposeGeometry(e){const n=e;n.boundsTree&&n.disposeBoundsTree(),e.dispose()}disposeGeometryAndMaterials(e,n){const s=e;s.geometry&&this.disposeGeometry(s.geometry),n&&s.material&&Ss.disposeMaterial(s),s.material=[],s.geometry=null}disposeChildren(e){for(const n of e.children)this.destroy(n)}static disposeMaterial(e){if(e.material)if(Array.isArray(e.material))for(const n of e.material)n.dispose();else e.material.dispose()}};ht(Ss,"uuid","76e9cd8e-ad8f-4753-9ef6-cbc60f7247fe");let Rr=Ss;class J_ extends ma{constructor(e){super(e);ht(this,"onDisposed",new me)}dispose(){const e=this.components.get(Rr);for(const n of this.three.children){const s=n;s.geometry&&e.destroy(s)}this.three.children=[],this.onDisposed.trigger(),this.onDisposed.reset()}}class _a extends $_{constructor(e){super(e);ht(this,"onBeforeUpdate",new me);ht(this,"onAfterUpdate",new me);ht(this,"onAspectUpdated",new me);ht(this,"onDisposed",new me);ht(this,"three");ht(this,"_allControls",new Map);ht(this,"updateAspect",()=>{var e;if(!(!this.currentWorld||!this.currentWorld.renderer)&&(e=this.currentWorld.renderer)!=null&&e.isResizeable()){const n=this.currentWorld.renderer.getSize();this.three.aspect=n.width/n.height,this.three.updateProjectionMatrix(),this.onAspectUpdated.trigger()}});this.three=this.setupCamera(),this.setupEvents(!0),this.onWorldChanged.add(({action:n,world:s})=>{if(n==="added"){const r=this.newCameraControls();this._allControls.set(s.uuid,r)}if(n==="removed"){const r=this._allControls.get(s.uuid);r&&(r.dispose(),this._allControls.delete(s.uuid))}})}get controls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");const e=this._allControls.get(this.currentWorld.uuid);if(!e)throw new Error("Controls not found!");return e}get enabled(){return this.currentWorld===null?!1:this.controls.enabled}set enabled(e){this.controls.enabled=e}dispose(){this.setupEvents(!1),this.enabled=!1,this.onAspectUpdated.reset(),this.onBeforeUpdate.reset(),this.onAfterUpdate.reset(),this.three.removeFromParent(),this.onDisposed.trigger(),this.onDisposed.reset();for(const[e,n]of this._allControls)n.dispose()}update(e){this.enabled&&(this.onBeforeUpdate.trigger(this),this.controls.update(e),this.onAfterUpdate.trigger(this))}setupCamera(){const e=window.innerWidth/window.innerHeight,n=new Ze(60,e,1,1e3);return n.position.set(50,50,50),n.lookAt(new U(0,0,0)),n}newCameraControls(){if(!this.currentWorld)throw new Error("This camera needs a world to work!");if(!this.currentWorld.renderer)throw new Error("This camera needs a renderer to work!");bs.install({THREE:_a.getSubsetOfThree()});const{domElement:e}=this.currentWorld.renderer.three,n=new bs(this.three,e);return n.smoothTime=.2,n.dollyToCursor=!0,n.infinityDolly=!0,n}setupEvents(e){e?window.addEventListener("resize",this.updateAspect):window.removeEventListener("resize",this.updateAspect)}static getSubsetOfThree(){return{MOUSE:mh,Vector2:kt,Vector3:U,Vector4:pe,Quaternion:ji,Matrix4:Jt,Spherical:X_,Box3:ye,Sphere:ws,Raycaster:W_,MathUtils:Pu}}}const sh=0,Q_=1,tg=2,rl=2,Co=1.25,ol=1,Mr=6*4+4+4,zr=65535,eg=Math.pow(2,-24),Ro=Symbol("SKIP_GENERATION");function ng(i){return i.index?i.index.count:i.attributes.position.count}function ts(i){return ng(i)/3}function ig(i,t=ArrayBuffer){return i>65535?new Uint32Array(new t(4*i)):new Uint16Array(new t(2*i))}function sg(i,t){if(!i.index){const e=i.attributes.position.count,n=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=ig(e,n);i.setIndex(new tn(s,1));for(let r=0;ro-c);for(let o=0;or.offset-a.offset),n=e[e.length-1];n.count=Math.min(t-n.offset,n.count);let s=0;return e.forEach(({count:r})=>s+=r),t!==s}function ae(i,t,e){return e.min.x=t[i],e.min.y=t[i+1],e.min.z=t[i+2],e.max.x=t[i+3],e.max.y=t[i+4],e.max.z=t[i+5],e}function og(i){i[0]=i[1]=i[2]=1/0,i[3]=i[4]=i[5]=-1/0}function al(i){let t=-1,e=-1/0;for(let n=0;n<3;n++){const s=i[n+3]-i[n];s>e&&(e=s,t=n)}return t}function cl(i,t){t.set(i)}function ll(i,t,e){let n,s;for(let r=0;r<3;r++){const a=r+3;n=i[r],s=t[r],e[r]=ns?n:s}}function rr(i,t,e){for(let n=0;n<3;n++){const s=t[i+2*n],r=t[i+2*n+1],a=s-r,o=s+r;ae[n+3]&&(e[n+3]=o)}}function fs(i){const t=i[3]-i[0],e=i[4]-i[1],n=i[5]-i[2];return 2*(t*e+e*n+n*t)}function Po(i,t,e,n,s=null){let r=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,h=-1/0,f=1/0,u=1/0,m=1/0,g=-1/0,x=-1/0,p=-1/0;const d=s!==null;for(let M=t*6,v=(t+e)*6;Mc&&(c=T),d&&_g&&(g=_);const P=i[M+2],E=i[M+3],S=P-E,D=P+E;Sl&&(l=D),d&&Px&&(x=P);const I=i[M+4],B=i[M+5],R=I-B,O=I+B;Rh&&(h=O),d&&Ip&&(p=I)}n[0]=r,n[1]=a,n[2]=o,n[3]=c,n[4]=l,n[5]=h,d&&(s[0]=f,s[1]=u,s[2]=m,s[3]=g,s[4]=x,s[5]=p)}function ag(i,t,e,n){let s=1/0,r=1/0,a=1/0,o=-1/0,c=-1/0,l=-1/0;for(let h=t*6,f=(t+e)*6;ho&&(o=u);const m=i[h+2];mc&&(c=m);const g=i[h+4];gl&&(l=g)}n[0]=s,n[1]=r,n[2]=a,n[3]=o,n[4]=c,n[5]=l}function cg(i,t){og(t);const e=i.attributes.position,n=i.index?i.index.array:null,s=ts(i),r=new Float32Array(s*6),a=e.normalized,o=e.array,c=e.offset||0;let l=3;e.isInterleavedBufferAttribute&&(l=e.data.stride);const h=["getX","getY","getZ"];for(let f=0;fA&&(A=v),_>A&&(A=_);const T=(A-y)/2,P=d*2;r[m+P+0]=y+T,r[m+P+1]=T+(Math.abs(y)+T)*eg,yt[d+3]&&(t[d+3]=A)}}return r}const Tn=32,lg=(i,t)=>i.candidate-t.candidate,Nn=new Array(Tn).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),or=new Float32Array(6);function hg(i,t,e,n,s,r){let a=-1,o=0;if(r===sh)a=al(t),a!==-1&&(o=(t[a]+t[a+3])/2);else if(r===Q_)a=al(i),a!==-1&&(o=ug(e,n,s,a));else if(r===tg){const c=fs(i);let l=Co*s;const h=n*6,f=(n+s)*6;for(let u=0;u<3;u++){const m=t[u],p=(t[u+3]-m)/Tn;if(s=T.candidate?rr(_,e,T.rightCacheBounds):(rr(_,e,T.leftCacheBounds),T.count++)}}for(let _=0;_=Tn&&(A=Tn-1);const T=Nn[A];T.count++,rr(v,e,T.bounds)}const d=Nn[Tn-1];cl(d.bounds,d.rightCacheBounds);for(let v=Tn-2;v>=0;v--){const _=Nn[v],y=Nn[v+1];ll(_.bounds,y.rightCacheBounds,_.rightCacheBounds)}let M=0;for(let v=0;v=c;)o--;if(a=c;)o--;if(a2**16,s=n?4:2,r=t?new SharedArrayBuffer(e*s):new ArrayBuffer(e*s),a=n?new Uint32Array(r):new Uint16Array(r);for(let o=0,c=a.length;o=s&&(f=!0,r&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(e))),A<=a||P>=s)return M(y+A),_.offset=y,_.count=A,_;const E=hg(_.boundingData,T,g,y,A,o);if(E.axis===-1)return M(y+A),_.offset=y,_.count=A,_;const S=x(h,n,g,y,A,E);if(S===y||S===y+A)M(y+A),_.offset=y,_.count=A;else{_.splitAxis=E.axis;const D=new ar,I=y,B=S-y;_.left=D,D.boundingData=new Float32Array(6),Po(g,I,B,D.boundingData,m),v(D,I,B,m,P+1);const R=new ar,O=S,F=A-B;_.right=R,R.boundingData=new Float32Array(6),Po(g,O,F,R.boundingData,m),v(R,O,F,m,P+1)}return _}}function _g(i,t){const e=i.geometry;t.indirect&&(i._indirectBuffer=pg(e,t.useSharedArrayBuffer),rg(e)&&!t.verbose&&console.warn('MeshBVH: Provided geometry contains groups that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),i._indirectBuffer||sg(e,t);const n=mg(i,t);let s,r,a;const o=[],c=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer;for(let f=0;fMath.pow(2,32))throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return r[m+6]=_/4,_=h(_,M),r[m+7]=v,_}}}class Pn{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let n=1/0,s=-1/0;for(let r=0,a=t.length;rs?c:s}this.min=n,this.max=s}setFromPoints(t,e){let n=1/0,s=-1/0;for(let r=0,a=e.length;rs?c:s}this.min=n,this.max=s}isSeparated(t){return this.min>t.max||t.min>this.max}}Pn.prototype.setFromBox=function(){const i=new U;return function(e,n){const s=n.min,r=n.max;let a=1/0,o=-1/0;for(let c=0;c<=1;c++)for(let l=0;l<=1;l++)for(let h=0;h<=1;h++){i.x=s.x*c+r.x*(1-c),i.y=s.y*l+r.y*(1-l),i.z=s.z*h+r.z*(1-h);const f=e.dot(i);a=Math.min(f,a),o=Math.max(f,o)}this.min=a,this.max=o}}();const gg=function(){const i=new U,t=new U,e=new U;return function(s,r,a){const o=s.start,c=i,l=r.start,h=t;e.subVectors(o,l),i.subVectors(s.end,s.start),t.subVectors(r.end,r.start);const f=e.dot(h),u=h.dot(c),m=h.dot(h),g=e.dot(c),p=c.dot(c)*m-u*u;let d,M;p!==0?d=(f*u-g*m)/p:d=0,M=(f+d*u)/m,a.x=d,a.y=M}}(),ga=function(){const i=new kt,t=new U,e=new U;return function(s,r,a,o){gg(s,r,i);let c=i.x,l=i.y;if(c>=0&&c<=1&&l>=0&&l<=1){s.at(c,a),r.at(l,o);return}else if(c>=0&&c<=1){l<0?r.at(0,o):r.at(1,o),s.closestPointToPoint(o,!0,a);return}else if(l>=0&&l<=1){c<0?s.at(0,a):s.at(1,a),r.closestPointToPoint(a,!0,o);return}else{let h;c<0?h=s.start:h=s.end;let f;l<0?f=r.start:f=r.end;const u=t,m=e;if(s.closestPointToPoint(f,!0,t),r.closestPointToPoint(h,!0,e),u.distanceToSquared(f)<=m.distanceToSquared(h)){a.copy(u),o.copy(f);return}else{a.copy(h),o.copy(m);return}}}}(),xg=function(){const i=new U,t=new U,e=new An,n=new wn;return function(r,a){const{radius:o,center:c}=r,{a:l,b:h,c:f}=a;if(n.start=l,n.end=h,n.closestPointToPoint(c,!0,i).distanceTo(c)<=o||(n.start=l,n.end=f,n.closestPointToPoint(c,!0,i).distanceTo(c)<=o)||(n.start=h,n.end=f,n.closestPointToPoint(c,!0,i).distanceTo(c)<=o))return!0;const x=a.getPlane(e);if(Math.abs(x.distanceToPoint(c))<=o){const d=x.projectPoint(c,t);if(a.containsPoint(d))return!0}return!1}}(),vg=1e-15;function Lo(i){return Math.abs(i)new U),this.satBounds=new Array(4).fill().map(()=>new Pn),this.points=[this.a,this.b,this.c],this.sphere=new ws,this.plane=new An,this.needsUpdate=!0}intersectsSphere(t){return xg(t,this)}update(){const t=this.a,e=this.b,n=this.c,s=this.points,r=this.satAxes,a=this.satBounds,o=r[0],c=a[0];this.getNormal(o),c.setFromPoints(o,s);const l=r[1],h=a[1];l.subVectors(t,e),h.setFromPoints(l,s);const f=r[2],u=a[2];f.subVectors(e,n),u.setFromPoints(f,s);const m=r[3],g=a[3];m.subVectors(n,t),g.setFromPoints(m,s),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,t),this.needsUpdate=!1}}hn.prototype.closestPointToSegment=function(){const i=new U,t=new U,e=new wn;return function(s,r=null,a=null){const{start:o,end:c}=s,l=this.points;let h,f=1/0;for(let u=0;u<3;u++){const m=(u+1)%3;e.start.copy(l[u]),e.end.copy(l[m]),ga(e,s,i,t),h=i.distanceToSquared(t),h=2){(_===1?d.start:d.end).copy(m),v=2;break}if(v++,v===2&&_===-1)break}}return v}return function(p,d=null,M=!1){this.needsUpdate&&this.update(),p.isExtendedTriangle?p.needsUpdate&&p.update():(i.copy(p),i.update(),p=i);const v=this.plane,_=p.plane;if(Math.abs(v.normal.dot(_.normal))>1-1e-10){const y=this.satBounds,A=this.satAxes;e[0]=p.a,e[1]=p.b,e[2]=p.c;for(let E=0;E<4;E++){const S=y[E],D=A[E];if(n.setFromPoints(D,e),S.isSeparated(n))return!1}const T=p.satBounds,P=p.satAxes;t[0]=this.a,t[1]=this.b,t[2]=this.c;for(let E=0;E<4;E++){const S=T[E],D=P[E];if(n.setFromPoints(D,t),S.isSeparated(n))return!1}for(let E=0;E<4;E++){const S=A[E];for(let D=0;D<4;D++){const I=P[D];if(r.crossVectors(S,I),n.setFromPoints(r,t),s.setFromPoints(r,e),n.isSeparated(s))return!1}}return d&&(M||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),d.start.set(0,0,0),d.end.set(0,0,0)),!0}else{const y=g(this,_,f);if(y===1&&p.containsPoint(f.end))return d&&(d.start.copy(f.end),d.end.copy(f.end)),!0;if(y!==2)return!1;const A=g(p,v,u);if(A===1&&this.containsPoint(u.end))return d&&(d.start.copy(u.end),d.end.copy(u.end)),!0;if(A!==2)return!1;if(f.delta(o),u.delta(c),o.dot(c)<0){let B=u.start;u.start=u.end,u.end=B}const T=f.start.dot(o),P=f.end.dot(o),E=u.start.dot(o),S=u.end.dot(o),D=P0?d.start.copy(f.start):d.start.copy(u.start),l.subVectors(f.end,u.end),l.dot(o)<0?d.end.copy(f.end):d.end.copy(u.end)),!0)}}}();hn.prototype.distanceToPoint=function(){const i=new U;return function(e){return this.closestPointToPoint(e,i),e.distanceTo(i)}}();hn.prototype.distanceToTriangle=function(){const i=new U,t=new U,e=["a","b","c"],n=new wn,s=new wn;return function(a,o=null,c=null){const l=o||c?n:null;if(this.intersectsTriangle(a,l))return(o||c)&&(o&&l.getCenter(o),c&&l.getCenter(c)),0;let h=1/0;for(let f=0;f<3;f++){let u;const m=e[f],g=a[m];this.closestPointToPoint(g,i),u=g.distanceToSquared(i),unew U),this.satAxes=new Array(3).fill().map(()=>new U),this.satBounds=new Array(3).fill().map(()=>new Pn),this.alignedSatBounds=new Array(3).fill().map(()=>new Pn),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),n&&this.matrix.copy(n)}set(t,e,n){this.min.copy(t),this.max.copy(e),this.matrix.copy(n),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}Ne.prototype.update=function(){return function(){const t=this.matrix,e=this.min,n=this.max,s=this.points;for(let l=0;l<=1;l++)for(let h=0;h<=1;h++)for(let f=0;f<=1;f++){const u=1*l|2*h|4*f,m=s[u];m.x=l?n.x:e.x,m.y=h?n.y:e.y,m.z=f?n.z:e.z,m.applyMatrix4(t)}const r=this.satBounds,a=this.satAxes,o=s[0];for(let l=0;l<3;l++){const h=a[l],f=r[l],u=1<new wn),e=new Array(12).fill().map(()=>new wn),n=new U,s=new U;return function(a,o=0,c=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(a))return(c||l)&&(a.getCenter(s),this.closestPointToPoint(s,n),a.closestPointToPoint(n,s),c&&c.copy(n),l&&l.copy(s)),0;const h=o*o,f=a.min,u=a.max,m=this.points;let g=1/0;for(let p=0;p<8;p++){const d=m[p];s.copy(d).clamp(f,u);const M=d.distanceToSquared(s);if(Mnew hn)}}const $e=new Eg;function Ve(i,t){return t[i+15]===65535}function Ge(i,t){return t[i+6]}function je(i,t){return t[i+14]}function Je(i){return i+8}function Qe(i,t){return t[i+6]}function ah(i,t){return t[i+7]}class Mg{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=n=>{e&&t.push(e),e=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const se=new Mg;let Vn,Gi;const Ri=[],cr=new xa(()=>new ye);function Sg(i,t,e,n,s,r){Vn=cr.getPrimitive(),Gi=cr.getPrimitive(),Ri.push(Vn,Gi),se.setBuffer(i._roots[t]);const a=$o(0,i.geometry,e,n,s,r);se.clearBuffer(),cr.releasePrimitive(Vn),cr.releasePrimitive(Gi),Ri.pop(),Ri.pop();const o=Ri.length;return o>0&&(Gi=Ri[o-1],Vn=Ri[o-2]),a}function $o(i,t,e,n,s=null,r=0,a=0){const{float32Array:o,uint16Array:c,uint32Array:l}=se;let h=i*2;if(Ve(h,c)){const g=Ge(i,l),x=je(h,c);return ae(i,o,Vn),n(g,x,!1,a,r+i,Vn)}else{let I=function(R){const{uint16Array:O,uint32Array:F}=se;let Y=R*2;for(;!Ve(Y,O);)R=Je(R),Y=R*2;return Ge(R,F)},B=function(R){const{uint16Array:O,uint32Array:F}=se;let Y=R*2;for(;!Ve(Y,O);)R=Qe(R,F),Y=R*2;return Ge(R,F)+je(Y,O)};var u=I,m=B;const g=Je(i),x=Qe(i,l);let p=g,d=x,M,v,_,y;if(s&&(_=Vn,y=Gi,ae(p,o,_),ae(d,o,y),M=s(_),v=s(y),v(ds.copy(t).clamp(h.min,h.max),ds.distanceToSquared(t)),intersectsBounds:(h,f,u)=>u{h.closestPointToPoint(t,ds);const u=t.distanceToSquared(ds);return u0&&l.normal.multiplyScalar(-1));const h={a:r,b:a,c:o,normal:new U,materialIndex:0};we.getNormal(Pi,Li,Ui,h.normal),l.face=h,l.faceIndex=r}return l}function Hr(i,t,e,n,s){const r=n*3;let a=r+0,o=r+1,c=r+2;const l=i.index;i.index&&(a=l.getX(a),o=l.getX(o),c=l.getX(c));const{position:h,normal:f,uv:u,uv1:m}=i.attributes,g=Ag(e,h,f,u,m,a,o,c,t);return g?(g.faceIndex=n,s&&s.push(g),g):null}function de(i,t,e,n){const s=i.a,r=i.b,a=i.c;let o=t,c=t+1,l=t+2;e&&(o=e.getX(o),c=e.getX(c),l=e.getX(l)),s.x=n.getX(o),s.y=n.getY(o),s.z=n.getZ(o),r.x=n.getX(c),r.y=n.getY(c),r.z=n.getZ(c),a.x=n.getX(l),a.y=n.getY(l),a.z=n.getZ(l)}function bg(i,t,e,n,s,r){const{geometry:a,_indirectBuffer:o}=i;for(let c=n,l=n+s;cA&&(A=I),B<_&&(_=B),B>T&&(T=B),RP&&(P=R)}return c[u+0]!==v||c[u+1]!==_||c[u+2]!==y||c[u+3]!==A||c[u+4]!==T||c[u+5]!==P?(c[u+0]=v,c[u+1]=_,c[u+2]=y,c[u+3]=A,c[u+4]=T,c[u+5]=P,!0):!1}else{const d=u+8,M=a[u+6],v=d+m,_=M+m;let y=g,A=!1,T=!1;t?y||(A=t.has(v),T=t.has(_),y=!A&&!T):(A=!0,T=!0);const P=y||A,E=y||T;let S=!1;P&&(S=f(d,m,y));let D=!1;E&&(D=f(M,m,y));const I=S||D;if(I)for(let B=0;B<3;B++){const R=d+B,O=M+B,F=c[R],Y=c[R+3],q=c[O],Z=c[O+3];c[u+B]=FZ?Y:Z}return I}}}const dl=new ye;function Xn(i,t,e,n){return ae(i,t,dl),e.intersectBox(dl,n)}function Pg(i,t,e,n,s,r){const{geometry:a,_indirectBuffer:o}=i;for(let c=n,l=n+s;c=0;let m,g;u?(m=Je(i),g=Qe(i,a)):(m=Qe(i,a),g=Je(i));const p=Xn(m,s,n,ml)?Jo(m,t,e,n):null;if(p){const v=p.point[h];if(u?v<=s[g+l]:v>=s[g+l+3])return p}const M=Xn(g,s,n,ml)?Jo(g,t,e,n):null;return p&&M?p.distance<=M.distance?p:M:p||M||null}}const dr=new ye,Di=new hn,Ii=new hn,ps=new Jt,_l=new Ne,pr=new Ne;function Ng(i,t,e,n){se.setBuffer(i._roots[t]);const s=Qo(0,i,e,n);return se.clearBuffer(),s}function Qo(i,t,e,n,s=null){const{float32Array:r,uint16Array:a,uint32Array:o}=se;let c=i*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),_l.set(e.boundingBox.min,e.boundingBox.max,n),s=_l),Ve(c,a)){const h=t.geometry,f=h.index,u=h.attributes.position,m=e.index,g=e.attributes.position,x=Ge(i,o),p=je(c,a);if(ps.copy(n).invert(),e.boundsTree)return ae(i,r,pr),pr.matrix.copy(ps),pr.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:M=>pr.intersectsBox(M),intersectsTriangle:M=>{M.a.applyMatrix4(n),M.b.applyMatrix4(n),M.c.applyMatrix4(n),M.needsUpdate=!0;for(let v=x*3,_=(p+x)*3;v<_;v+=3)if(de(Ii,v,f,u),Ii.needsUpdate=!0,M.intersectsTriangle(Ii))return!0;return!1}});for(let d=x*3,M=(p+x)*3;dDo.distanceToBox(y),intersectsBounds:(y,A,T)=>T{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:P=>ms.distanceToBox(P),intersectsBounds:(P,E,S)=>S{for(let S=P,D=P+E;SA&&(A=R),O<_&&(_=O),O>T&&(T=O),FP&&(P=F)}}return c[u+0]!==v||c[u+1]!==_||c[u+2]!==y||c[u+3]!==A||c[u+4]!==T||c[u+5]!==P?(c[u+0]=v,c[u+1]=_,c[u+2]=y,c[u+3]=A,c[u+4]=T,c[u+5]=P,!0):!1}else{const d=u+8,M=a[u+6],v=d+m,_=M+m;let y=g,A=!1,T=!1;t?y||(A=t.has(v),T=t.has(_),y=!A&&!T):(A=!0,T=!0);const P=y||A,E=y||T;let S=!1;P&&(S=f(d,m,y));let D=!1;E&&(D=f(M,m,y));const I=S||D;if(I)for(let B=0;B<3;B++){const R=d+B,O=M+B,F=c[R],Y=c[R+3],q=c[O],Z=c[O+3];c[u+B]=FZ?Y:Z}return I}}}const gl=new U;function kg(i,t,e,n,s){se.setBuffer(i._roots[t]),ta(0,i,e,n,s),se.clearBuffer()}function ta(i,t,e,n,s){const{float32Array:r,uint16Array:a,uint32Array:o}=se,c=i*2;if(Ve(c,a)){const h=Ge(i,o),f=je(c,a);Pg(t,e,n,h,f,s)}else{const h=Je(i);Xn(h,r,n,gl)&&ta(h,t,e,n,s);const f=Qe(i,o);Xn(f,r,n,gl)&&ta(f,t,e,n,s)}}const xl=new U,Wg=["x","y","z"];function Xg(i,t,e,n){se.setBuffer(i._roots[t]);const s=ea(0,i,e,n);return se.clearBuffer(),s}function ea(i,t,e,n){const{float32Array:s,uint16Array:r,uint32Array:a}=se;let o=i*2;if(Ve(o,r)){const l=Ge(i,a),h=je(o,r);return Lg(t,e,n,l,h)}else{const l=ah(i,a),h=Wg[l],u=n.direction[h]>=0;let m,g;u?(m=Je(i),g=Qe(i,a)):(m=Qe(i,a),g=Je(i));const p=Xn(m,s,n,xl)?ea(m,t,e,n):null;if(p){const v=p.point[h];if(u?v<=s[g+l]:v>=s[g+l+3])return p}const M=Xn(g,s,n,xl)?ea(g,t,e,n):null;return p&&M?p.distance<=M.distance?p:M:p||M||null}}const _r=new ye,Oi=new hn,Ni=new hn,_s=new Jt,vl=new Ne,gr=new Ne;function Yg(i,t,e,n){se.setBuffer(i._roots[t]);const s=na(0,i,e,n);return se.clearBuffer(),s}function na(i,t,e,n,s=null){const{float32Array:r,uint16Array:a,uint32Array:o}=se;let c=i*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),vl.set(e.boundingBox.min,e.boundingBox.max,n),s=vl),Ve(c,a)){const h=t.geometry,f=h.index,u=h.attributes.position,m=e.index,g=e.attributes.position,x=Ge(i,o),p=je(c,a);if(_s.copy(n).invert(),e.boundsTree)return ae(i,r,gr),gr.matrix.copy(_s),gr.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:M=>gr.intersectsBox(M),intersectsTriangle:M=>{M.a.applyMatrix4(n),M.b.applyMatrix4(n),M.c.applyMatrix4(n),M.needsUpdate=!0;for(let v=x,_=p+x;v<_;v++)if(de(Ni,3*t.resolveTriangleIndex(v),f,u),Ni.needsUpdate=!0,M.intersectsTriangle(Ni))return!0;return!1}});for(let d=x,M=p+x;dIo.distanceToBox(y),intersectsBounds:(y,A,T)=>T{if(t.boundsTree){const T=t.boundsTree;return T.shapecast({boundsTraverseOrder:P=>gs.distanceToBox(P),intersectsBounds:(P,E,S)=>S{for(let S=P,D=P+E;Snew ye),Fi=new ye,Bi=new ye,Oo=new ye,No=new ye;let Fo=!1;function Qg(i,t,e,n){if(Fo)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Fo=!0;const s=i._roots,r=t._roots;let a,o=0,c=0;const l=new Jt().copy(e).invert();for(let h=0,f=s.length;hc.slice()),index:a.array.slice(),indirectBuffer:r?r.slice():null}:o={roots:s,index:a.array,indirectBuffer:r},o}static deserialize(t,e,n={}){n={setIndex:!0,indirect:!!t.indirectBuffer,...n};const{index:s,roots:r,indirectBuffer:a}=t,o=new va(e,{...n,[Ro]:!0});if(o._roots=r,o._indirectBuffer=a||null,n.setIndex){const c=e.getIndex();if(c===null){const l=new tn(t.index,1,!1);e.setIndex(l)}else c.array!==s&&(c.array.set(s),c.needsUpdate=!0)}return o}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(e=Object.assign({strategy:sh,maxDepth:40,maxLeafTris:10,verbose:!0,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,[Ro]:!1},e),e.useSharedArrayBuffer&&!Jg())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[Ro]||(_g(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new ye)));const{_indirectBuffer:n}=this;this.resolveTriangleIndex=e.indirect?s=>n[s]:s=>s}refit(t=null){return(this.indirect?Gg:Rg)(this,t)}traverse(t,e=0){const n=this._roots[e],s=new Uint32Array(n),r=new Uint16Array(n);a(0);function a(o,c=0){const l=o*2,h=r[l+15]===zr;if(h){const f=s[o+6],u=r[l+14];t(c,h,new Float32Array(n,o*4,6),f,u)}else{const f=o+Mr/4,u=s[o+6],m=s[o+7];t(c,h,new Float32Array(n,o*4,6),m)||(a(f,c+1),a(u,c+1))}}}raycast(t,e=_n){const n=this._roots,s=this.geometry,r=[],a=e.isMaterial,o=Array.isArray(e),c=s.groups,l=a?e.side:e,h=this.indirect?kg:Dg;for(let f=0,u=n.length;ff(u,m,g,x,p)?!0:n(u,m,this,o,g,x,e)}else a||(o?a=(f,u,m,g)=>n(f,u,this,o,m,g,e):a=(f,u,m)=>m);let c=!1,l=0;const h=this._roots;for(let f=0,u=h.length;f{const x=this.resolveTriangleIndex(g);de(a,x*3,o,c)}:g=>{de(a,g*3,o,c)},h=$e.getPrimitive(),f=t.geometry.index,u=t.geometry.attributes.position,m=t.indirect?g=>{const x=t.resolveTriangleIndex(g);de(h,x*3,f,u)}:g=>{de(h,g*3,f,u)};if(r){const g=(x,p,d,M,v,_,y,A)=>{for(let T=d,P=d+M;Tvr.intersectsBox(n),intersectsTriangle:n=>vr.intersectsTriangle(n)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,n={},s={},r=0,a=1/0){return(this.indirect?jg:Vg)(this,t,e,n,s,r,a)}closestPointToPoint(t,e={},n=0,s=1/0){return yg(this,t,e,n,s)}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(n=>{ae(0,new Float32Array(n),El),t.union(El)}),t}}function Ml(i,t,e){return i===null||(i.point.applyMatrix4(t.matrixWorld),i.distance=i.point.distanceTo(e.ray.origin),i.object=t,i.distancee.far)?null:i}const Bo=new la,Sl=new Jt,tx=ln.prototype.raycast;function ex(i,t){if(this.geometry.boundsTree){if(this.material===void 0)return;Sl.copy(this.matrixWorld).invert(),Bo.copy(i.ray).applyMatrix4(Sl);const e=this.geometry.boundsTree;if(i.firstHitOnly===!0){const n=Ml(e.raycastFirst(Bo,this.material),this,i);n&&t.push(n)}else{const n=e.raycast(Bo,this.material);for(let s=0,r=n.length;s>8&255]+ue._lut[t>>16&255]+ue._lut[t>>24&255]}-${ue._lut[e&255]}${ue._lut[e>>8&255]}-${ue._lut[e>>16&15|64]}${ue._lut[e>>24&255]}-${ue._lut[n&63|128]}${ue._lut[n>>8&255]}-${ue._lut[n>>16&255]}${ue._lut[n>>24&255]}${ue._lut[s&255]}${ue._lut[s>>8&255]}${ue._lut[s>>16&255]}${ue._lut[s>>24&255]}`.toLowerCase()}static validate(t){if(!ue._pattern.test(t))throw new Error(`${t} is not a valid UUID v4. - -- If you're the tool creator, you can take one from https://www.uuidgenerator.net/. - -- If you're using a platform tool, verify the uuid isn't misspelled or contact the tool creator.`)}};ht(ue,"_pattern",/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/),ht(ue,"_lut",["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"]);let Lr=ue;const Ur=class Ur{constructor(){ht(this,"meshes",new Set);ht(this,"onDisposed",new me);ht(this,"list",new Map);ht(this,"enabled",!1);ht(this,"_clock");ht(this,"update",()=>{if(!this.enabled)return;const t=this._clock.getDelta();for(const[e,n]of this.list)n.enabled&&n.isUpdateable()&&n.update(t);requestAnimationFrame(this.update)});this._clock=new k_,Ur.setupBVH()}add(t,e){if(this.list.has(t))throw new Error("You're trying to add a component that already exists in the components intance. Use Components.get() instead.");Lr.validate(t),this.list.set(t,e)}get(t){const e=t.uuid;if(!this.list.has(e)){const n=new t(this);return this.list.has(e)||this.add(e,n),n}return this.list.get(e)}init(){this.enabled=!0,this._clock.start(),this.update()}dispose(){const t=this.get(Rr);this.enabled=!1;for(const[e,n]of this.list)n.enabled=!1,n.isDisposeable()&&n.dispose();this._clock.stop();for(const e of this.meshes)t.destroy(e);this.meshes.clear(),this.onDisposed.trigger(),this.onDisposed.reset()}static setupBVH(){Rn.prototype.computeBoundsTree=nx,Rn.prototype.disposeBoundsTree=ix,ln.prototype.raycast=ex}};ht(Ur,"release","1.4.21");let ia=Ur;class sx extends j_{constructor(e,n,s){super(e);ht(this,"enabled",!0);ht(this,"container");ht(this,"three");ht(this,"_canvas");ht(this,"_parameters");ht(this,"onContainerUpdated",new me);ht(this,"resize",e=>{if(this.updateContainer(),!this.container)return;const n=e?e.x:this.container.clientWidth,s=e?e.y:this.container.clientHeight;this.three.setSize(n,s),this.onResize.trigger(e)});ht(this,"resizeEvent",()=>{this.resize()});ht(this,"onContextLost",e=>{e.preventDefault(),this.components.enabled=!1});ht(this,"onContextBack",()=>{this.three.setRenderTarget(null),this.three.dispose(),this.three=new Zo({canvas:this._canvas,antialias:!0,alpha:!0,...this._parameters}),this.components.enabled=!0});this.container=n||null,this._parameters=s,this.three=new Zo({antialias:!0,alpha:!0,...s}),this.three.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.setupRenderer(),this.setupEvents(!0),this.resize(),this._canvas=this.three.domElement;const r=this.three.getContext(),{canvas:a}=r;a.addEventListener("webglcontextlost",this.onContextLost,!1),a.addEventListener("webglcontextrestored",this.onContextBack,!1)}update(){if(!this.enabled||!this.currentWorld)return;this.onBeforeUpdate.trigger(this);const e=this.currentWorld.scene.three,n=this.currentWorld.camera.three;this.three.render(e,n),this.onAfterUpdate.trigger(this)}dispose(){this.enabled=!1,this.setupEvents(!1),this.three.domElement.remove(),this.three.dispose(),this.onResize.reset(),this.onAfterUpdate.reset(),this.onBeforeUpdate.reset(),this.onDisposed.trigger(),this.onDisposed.reset()}getSize(){return new kt(this.three.domElement.clientWidth,this.three.domElement.clientHeight)}setupEvents(e){const n=this.three.domElement;e?n.addEventListener("resize",this.resizeEvent):n.removeEventListener("resize",this.resizeEvent)}setupRenderer(){this.three.localClippingEnabled=!0,this.container&&this.container.appendChild(this.three.domElement),this.updateContainer()}updateContainer(){if(!this.container){const e=this.three.domElement.parentElement;e&&(this.container=e,this.onContainerUpdated.trigger(e))}}}class rx extends J_{constructor(e){super(e);ht(this,"isSetup",!1);ht(this,"three");ht(this,"onSetup",new me);ht(this,"config",{directionalLight:{color:new qt("white"),intensity:1.5,position:new U(5,10,3)},ambientLight:{color:new qt("white"),intensity:1}});this.three=new B_,this.three.background=new qt(2107698)}setup(e){this.config={...this.config,...e};const n=new V_(this.config.directionalLight.color,this.config.directionalLight.intensity);n.position.copy(this.config.directionalLight.position);const s=new G_(this.config.ambientLight.color,this.config.ambientLight.intensity);this.three.add(n,s),this.isSetup=!0,this.onSetup.trigger(this)}}class ox extends pa{constructor(e){super(e);ht(this,"onAfterUpdate",new me);ht(this,"onBeforeUpdate",new me);ht(this,"enabled",!0);ht(this,"uuid",Lr.create());ht(this,"onDisposed",new me);ht(this,"_scene");ht(this,"_camera");ht(this,"_renderer",null)}get scene(){if(!this._scene)throw new Error("No scene initialized!");return this._scene}set scene(e){this._scene=e,e.worlds.set(this.uuid,this),e.currentWorld=this,e.onWorldChanged.trigger({world:this,action:"added"})}get camera(){if(!this._camera)throw new Error("No camera initialized!");return this._camera}set camera(e){this._camera=e,e.worlds.set(this.uuid,this),e.currentWorld=this,e.onWorldChanged.trigger({world:this,action:"added"})}get renderer(){return this._renderer}set renderer(e){this._renderer=e,e&&(e.worlds.set(this.uuid,this),e.currentWorld=this,e.onWorldChanged.trigger({world:this,action:"added"}))}update(e){this.enabled&&(this.scene.currentWorld=this,this.camera.currentWorld=this,this.renderer&&(this.renderer.currentWorld=this),this.onBeforeUpdate.trigger(),this.scene.isUpdateable()&&this.scene.update(e),this.camera.isUpdateable()&&this.camera.update(e),this.renderer&&this.renderer.update(e),this.onAfterUpdate.trigger())}dispose(e=!0){this.enabled=!1,this.scene.onWorldChanged.trigger({world:this,action:"removed"}),this.camera.onWorldChanged.trigger({world:this,action:"removed"}),this.renderer&&this.renderer.onWorldChanged.trigger({world:this,action:"removed"}),e&&(this.scene.dispose(),this.camera.isDisposeable()&&this.camera.dispose(),this.renderer&&this.renderer.dispose()),this._scene=null,this._camera=null,this._renderer=null,this.onDisposed.trigger()}}const Dr=class Dr extends ih{constructor(e){super(e);ht(this,"onAfterUpdate",new me);ht(this,"onBeforeUpdate",new me);ht(this,"onDisposed",new me);ht(this,"list",new Map);ht(this,"enabled",!0);e.add(Dr.uuid,this)}add(e){const n=e.uuid;if(this.list.has(n))throw new Error("There is already a world with this name!");this.list.set(n,e)}dispose(){this.enabled=!1;for(const[e,n]of this.list)n.dispose();this.onDisposed.trigger()}update(e){if(this.enabled)for(const[n,s]of this.list)s.update(e)}};ht(Dr,"uuid","fdb61dc4-2ec1-4966-b83d-54ea795fad4a");let sa=Dr;const ax=document.getElementById("container"),es=new ia,cx=es.get(sa),Cs=new ox(es);Cs.scene=new rx(es);Cs.renderer=new sx(es,ax);Cs.camera=new _a(es);cx.add(Cs);es.init();const lx=new ln(new Ji);Cs.scene.three.add(lx); +import{b as o,u as t}from"./three.module-CYx2Afzj.js";import{C as r,W as s,S as a,a as c,b as m}from"./index-DCLJCpH4.js";const d=document.getElementById("container"),e=new r,i=e.get(s),n=i.create();n.scene=new a(e);n.renderer=new c(e,d);n.camera=new m(e);e.init();const l=new o(new t);n.scene.three.add(l);n.camera.controls.setLookAt(13,13,13,0,0,0); diff --git a/index.html b/index.html index 14dece434..f15d5dd3d 100644 --- a/index.html +++ b/index.html @@ -17,11 +17,11 @@

diff --git a/packages/components-front/package.json b/packages/components-front/package.json index dc7e3d490..392b2104e 100644 --- a/packages/components-front/package.json +++ b/packages/components-front/package.json @@ -33,6 +33,7 @@ "prepublishOnly": "yarn build" }, "peerDependencies": { + "bim-fragment": "1.5.0", "three": "^0.160.1" }, "devDependencies": { @@ -40,6 +41,7 @@ "three": "^0.160.1" }, "dependencies": { - "@thatopen/components": "1.5.0" + "@thatopen/components": "1.5.0", + "camera-controls": "2.7.3" } } diff --git a/packages/components-front/src/civil/CivilMarker/index.ts b/packages/components-front/src/civil/CivilMarker/index.ts new file mode 100644 index 000000000..a48880fc8 --- /dev/null +++ b/packages/components-front/src/civil/CivilMarker/index.ts @@ -0,0 +1,224 @@ +// import * as FRAGS from "bim-fragment"; +// import * as THREE from "three"; +// import { World } from "@thatopen/components/src"; +// import { Marker } from "../../core"; +// import { Mark } from "../../core/Marker/src"; +// +// type CivilLabels = +// | "Station" +// | "Radius" +// | "Length" +// | "InitialKP" +// | "FinalKP" +// | "KP" +// | "Slope" +// | "Height" +// | "InitialKPV" +// | "FinalKPV"; +// +// /** +// * Class for Managing Markers along with creating different types of markers +// * Every marker is a Simple2DMarker +// * For every marker that needs to be added, you can use the Manager to add the marker and change its look and feel +// */ +// export class CivilMarker extends Marker { +// addKPStation(world: World, text: string, mesh: THREE.Line) { +// const container = document.createElement("div"); +// const span = document.createElement("div"); +// container.appendChild(span); +// +// span.innerHTML = text; +// +// span.style.color = this._color; +// span.style.borderBottom = "1px dotted white"; +// span.style.width = "160px"; +// span.style.textAlign = "left"; +// +// const marker = new Mark(world, container); +// +// const point = new THREE.Vector3(); +// point.x = mesh.geometry.attributes.position.getX( +// mesh.geometry.attributes.position.count - 1, +// ); +// point.y = mesh.geometry.attributes.position.getY( +// mesh.geometry.attributes.position.count - 1, +// ); +// point.z = mesh.geometry.attributes.position.getZ( +// mesh.geometry.attributes.position.count - 1, +// ); +// +// const secondLastPoint = new THREE.Vector3(); +// secondLastPoint.x = mesh.geometry.attributes.position.getX( +// mesh.geometry.attributes.position.count - 2, +// ); +// secondLastPoint.y = mesh.geometry.attributes.position.getY( +// mesh.geometry.attributes.position.count - 2, +// ); +// secondLastPoint.z = mesh.geometry.attributes.position.getZ( +// mesh.geometry.attributes.position.count - 2, +// ); +// +// const midPoint = new THREE.Vector3(); +// midPoint.x = (point.x + secondLastPoint.x) / 2; +// midPoint.y = (point.y + secondLastPoint.y) / 2; +// midPoint.z = (point.z + secondLastPoint.z) / 2; +// +// marker.three.position.copy(midPoint); +// +// const direction = new THREE.Vector3(); +// direction.subVectors(point, secondLastPoint).normalize(); +// const quaternion = new THREE.Quaternion(); +// quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), direction); +// +// const eulerZ = new THREE.Euler().setFromQuaternion(quaternion).z; +// const rotationZ = THREE.MathUtils.radToDeg(eulerZ); +// +// span.style.transform = `rotate(${ +// -rotationZ - 90 +// }deg) translate(-35%, -50%)`; +// +// this.list.add({ +// label: marker, +// key: this._markerKey.toString(), +// merged: false, +// static: false, +// }); +// this._markerKey++; +// } +// +// addCivilVerticalMarker( +// world: World, +// text: string, +// mesh: FRAGS.CurveMesh, +// type: CivilLabels, +// root: THREE.Object3D, +// ) { +// const span = document.createElement("span"); +// span.innerHTML = text; +// span.style.color = this._color; +// +// const marker = new Mark(world, span, root); +// +// if (type === "Height") { +// const span = document.createElement("span"); +// span.innerHTML = text; +// span.style.color = this._color; +// +// const { position } = mesh.geometry.attributes; +// const setArray = position.array.length / 3; +// +// const firstIndex = (setArray - 1) * 3; +// const lastIndex = position.array.slice(firstIndex, firstIndex + 3); +// +// marker.three.position.set(lastIndex[0], lastIndex[1] + 10, lastIndex[2]); +// } else if (type === "InitialKPV") { +// const { position } = mesh.geometry.attributes; +// +// const pX = position.getX(0); +// const pY = position.getY(0); +// const pZ = position.getZ(0); +// +// marker.three.position.set(pX - 20, pY, pZ); +// } else if (type === "FinalKPV") { +// const { position } = mesh.geometry.attributes; +// +// const pX = position.getX(mesh.geometry.attributes.position.count - 1); +// const pY = position.getY(mesh.geometry.attributes.position.count - 1); +// const pZ = position.getZ(mesh.geometry.attributes.position.count - 1); +// +// marker.three.position.set(pX + 20, pY, pZ); +// } else if (type === "Slope") { +// span.style.color = "grey"; +// const { position } = mesh.geometry.attributes; +// +// const pointStart = new THREE.Vector3(); +// pointStart.x = position.getX(0); +// pointStart.y = position.getY(0); +// pointStart.z = position.getZ(0); +// +// const pointEnd = new THREE.Vector3(); +// pointEnd.x = position.getX(position.count - 1); +// pointEnd.y = position.getY(position.count - 1); +// pointEnd.z = position.getZ(position.count - 1); +// +// const midPoint = new THREE.Vector3(); +// midPoint.addVectors(pointStart, pointEnd).multiplyScalar(0.5); +// +// marker.three.position.set(midPoint.x, midPoint.y - 10, midPoint.z); +// } +// +// this.list.add({ +// label: marker, +// key: this._markerKey.toString(), +// type, +// merged: false, +// static: false, +// }); +// this._markerKey++; +// +// return marker; +// } +// +// addCivilMarker( +// world: World, +// text: string, +// mesh: FRAGS.CurveMesh, +// type: CivilLabels, +// ) { +// const span = document.createElement("span"); +// span.innerHTML = text; +// span.style.color = this._color; +// +// const marker = new Mark(world, span); +// +// if (type === "InitialKP") { +// const pX = mesh.geometry.attributes.position.getX(0); +// const pY = mesh.geometry.attributes.position.getY(0); +// const pZ = mesh.geometry.attributes.position.getZ(0); +// marker.three.position.set(pX + 2, pY + 2, pZ); +// } else if (type === "FinalKP") { +// const pX = mesh.geometry.attributes.position.getX( +// mesh.geometry.attributes.position.count - 1, +// ); +// const pY = mesh.geometry.attributes.position.getY( +// mesh.geometry.attributes.position.count - 1, +// ); +// const pZ = mesh.geometry.attributes.position.getZ( +// mesh.geometry.attributes.position.count - 1, +// ); +// marker.three.position.set(pX + 2, pY - 2, pZ); +// } else if (type === "Length") { +// const pointStart = new THREE.Vector3(); +// pointStart.x = mesh.geometry.attributes.position.getX(0); +// pointStart.y = mesh.geometry.attributes.position.getY(0); +// pointStart.z = mesh.geometry.attributes.position.getZ(0); +// +// const pointEnd = new THREE.Vector3(); +// pointEnd.x = mesh.geometry.attributes.position.getX( +// mesh.geometry.attributes.position.count - 1, +// ); +// pointEnd.y = mesh.geometry.attributes.position.getY( +// mesh.geometry.attributes.position.count - 1, +// ); +// pointEnd.z = mesh.geometry.attributes.position.getZ( +// mesh.geometry.attributes.position.count - 1, +// ); +// +// const length = pointStart.distanceTo(pointEnd); +// marker.three.element.innerText = length.toFixed(2); +// const target = pointEnd.clone().add(pointStart).divideScalar(2); +// marker.three.position.copy(target); +// } +// +// this.list.add({ +// label: marker, +// key: this._markerKey.toString(), +// type, +// merged: false, +// static: false, +// }); +// this._markerKey++; +// +// return marker; +// } +// } diff --git a/packages/components-front/src/civil/index.ts b/packages/components-front/src/civil/index.ts new file mode 100644 index 000000000..39b02152d --- /dev/null +++ b/packages/components-front/src/civil/index.ts @@ -0,0 +1 @@ +// export * from "./CivilMarker"; diff --git a/temp/core/Simple2DScene/example.html b/packages/components-front/src/core/Marker/example.html similarity index 100% rename from temp/core/Simple2DScene/example.html rename to packages/components-front/src/core/Marker/example.html diff --git a/packages/components-front/src/core/Marker/example.ts b/packages/components-front/src/core/Marker/example.ts new file mode 100644 index 000000000..c4713ebc6 --- /dev/null +++ b/packages/components-front/src/core/Marker/example.ts @@ -0,0 +1,42 @@ +import * as THREE from "three"; +import * as OBC from "@thatopen/components"; +import * as OBCF from "../.."; + +const container = document.getElementById("container")!; + +const components = new OBC.Components(); + +const worlds = components.get(OBC.Worlds); + +const world = worlds.create< + OBC.SimpleScene, + OBC.SimpleCamera, + OBCF.RendererWith2D +>(); + +world.scene = new OBC.SimpleScene(components); +world.renderer = new OBCF.RendererWith2D(components, container); +world.camera = new OBC.SimpleCamera(components); + +components.init(); + +// const cube = new THREE.Mesh(new THREE.BoxGeometry()); +// world.scene.three.add(cube); + +world.camera.controls.setLookAt(5, 5, 5, 0, 0, 0); + +const grids = components.get(OBC.Grids); +grids.create(world); + +const marker = components.get(OBCF.Marker); + +marker.threshold = 10; + +// marker.autoCluster = false; + +for (let i = 0; i < 20; i++) { + const x = Math.random() * 5; + const y = Math.random() * 5; + const z = Math.random() * 5; + marker.create(world, "🚀", new THREE.Vector3(x, y, z)); +} diff --git a/packages/components-front/src/core/Marker/index.ts b/packages/components-front/src/core/Marker/index.ts new file mode 100644 index 000000000..4a7191428 --- /dev/null +++ b/packages/components-front/src/core/Marker/index.ts @@ -0,0 +1,370 @@ +import * as THREE from "three"; +import * as OBC from "@thatopen/components"; +import { Mark } from "./src"; + +// TODO: Right now the clustering algorithm is probably n^2 +// (compares all clusters with all clusters). Can we use a faster algo?) +// TODO: Optimize by computing clusters in worker +// TODO: Optimize by only computing visible marks + + +export interface IMarker { + key: string; + label: Mark; + type?: string; + merged: boolean; + static: boolean; +} + +export interface IGroupedMarkers { + key: string; + markerKeys: string[]; + label: Mark; +} + +/** + * Class for Managing Markers along with creating different types of markers + * Every marker is a Simple2DMarker + * For every marker that needs to be added, you can use the Manager to add the marker and change its look and feel + */ +export class Marker extends OBC.Component { + static readonly uuid = "4079eb91-79b0-4ede-bcf2-15b837129236" as const; + + enabled = true; + + threshold = 50; + + autoCluster = true; + + protected list = new Map(); + + protected clusterLabels: Set = new Set(); + + protected currentKeys: Set = new Set(); + + protected _color = "white"; + + // TODO: Replace with UUID for the marker key + protected _markerKey = 0; + + protected _clusterKey = 0; + + protected isNavigating = false; + + private _setupWorlds = new Set(); + + constructor(components: OBC.Components) { + super(components); + components.add(Marker.uuid, this); + } + + get color() { + return this._color; + } + + set color(value: string) { + this._color = value; + for (const [_id, marker] of this.list) { + marker.label.three.element.style.color = value; + } + } + + create(world: OBC.World, text: string, point: THREE.Vector3) { + this.setupEvents(world, true); + + const span = document.createElement("span"); + span.innerHTML = text; + span.style.color = this._color; + const marker = new Mark(world, span); + + marker.three.position.copy(point); + + const key = this._markerKey.toString(); + + this.list.set(key, { + key, + label: marker, + merged: false, + static: false, + }); + + this._markerKey++; + + return key; + } + + delete(id: string) { + const marker = this.list.get(id); + if (marker) { + marker.label.dispose(); + } + this.list.delete(id); + } + + clear(type?: string) { + const ids = [...this.list.keys()]; + for (const id of ids) { + const marker = this.list.get(id) as IMarker; + if (type && marker.type !== type) { + continue; + } + marker.label.dispose(); + this.list.delete(id); + } + this.list.clear(); + this._markerKey = 0; + } + + dispose() { + for (const [_id, marker] of this.list) { + marker.label.dispose(); + } + + this.list.clear(); + this._markerKey = 0; + + for (const cluster of this.clusterLabels) { + cluster.label.dispose(); + } + + this.clusterLabels.clear(); + this._clusterKey = 0; + + this.currentKeys.clear(); + } + + private setupEvents(world: OBC.World, enabled: boolean) { + if (enabled && this._setupWorlds.has(world.uuid)) { + return; + } + if (!world.camera.hasCameraControls()) { + return; + } + if (enabled) { + world.camera.controls.addEventListener("sleep", () => { + this.manageCluster(); + }); + + world.camera.controls.addEventListener("rest", () => { + if (this.isNavigating) { + this.manageCluster(); + this.isNavigating = false; + } + }); + } else { + world.camera.controls.removeEventListener("sleep", () => { + this.manageCluster(); + }); + + world.camera.controls.removeEventListener("rest", () => { + if (this.isNavigating) { + this.manageCluster(); + this.isNavigating = false; + } + }); + } + } + + private resetMarkers() { + for (const [_id, marker] of this.list) { + marker.merged = false; + } + for (const cluster of this.clusterLabels) { + cluster.label.dispose(); + } + this.clusterLabels.clear(); + this._clusterKey = 0; + } + + private removeMergeMarkers() { + for (const [_id, marker] of this.list) { + if (marker.merged) { + marker.label.dispose(); + } else { + const scene = marker.label.world.scene.three; + scene.add(marker.label.three); + } + } + + for (const cluster of this.clusterLabels) { + if (cluster.markerKeys.length === 1) { + const marker = this.list.get(cluster.markerKeys[0]); + + if (marker) { + const scene = marker.label.world.scene.three; + scene.add(marker.label.three); + marker.merged = false; + } + + cluster.label.dispose(); + this.clusterLabels.delete(cluster); + } + } + } + + private manageCluster() { + if (!this.autoCluster) return; + this.resetMarkers(); + + for (const [_id, marker] of this.list) { + if (!marker.merged && !marker.static) { + this.currentKeys.clear(); + for (const [_id, marker2] of this.list) { + if (marker2.static) { + continue; + } + if (marker.key !== marker2.key && !marker2.merged) { + const distance = this.distance(marker.label, marker2.label); + if (distance < this.threshold) { + this.currentKeys.add(marker2.key); + marker2.merged = true; + } + } + } + + if (this.currentKeys.size > 0) { + this.currentKeys.add(marker.key); + marker.merged = true; + const clusterGroup = Array.from(this.currentKeys); + const averagePosition = + this.getAveragePositionFromLabels(clusterGroup); + + const clusterLabel = new Mark( + marker.label.world, + this.createClusterElement(this._clusterKey.toString()), + ); + + const { element } = clusterLabel.three; + element.textContent = clusterGroup.length.toString(); + + clusterLabel.three.position.copy(averagePosition); + + this.clusterLabels.add({ + key: this._clusterKey.toString(), + markerKeys: clusterGroup, + label: clusterLabel, + }); + + this._clusterKey++; + } + } + } + + this.removeMergeMarkers(); + } + + private getAveragePositionFromLabels(clusterGroup: string[]) { + const positions = clusterGroup.map((key) => { + const marker = this.list.get(key); + if (marker) { + return marker.label.three.position; + } + return new THREE.Vector3(); + }); + + return positions + .reduce((acc, curr) => acc.add(curr), new THREE.Vector3()) + .divideScalar(positions.length); + } + + private createClusterElement(key: string) { + const div = document.createElement("div"); + div.textContent = key; + div.style.color = "#000000"; + div.style.background = "#FFFFFF"; + div.style.fontSize = "1.2rem"; + div.style.fontWeight = "500"; + div.style.pointerEvents = "auto"; + div.style.borderRadius = "50%"; + div.style.padding = "5px 11px"; + div.style.textAlign = "center"; + div.style.cursor = "pointer"; + // div.style.transition = "all 0.05s"; + div.addEventListener("pointerdown", () => { + this.navigateToCluster(key); + }); + div.addEventListener("pointerover", () => { + div.style.background = "#BCF124"; + }); + div.addEventListener("pointerout", () => { + div.style.background = "#FFFFFF"; + }); + return div; + } + + private getScreenPosition(label: Mark) { + const screenPosition = new THREE.Vector3(); + + if (!label.world.renderer) { + throw new Error("Renderer not found!"); + } + + const position = label.three.position.clone(); + position.project(label.world.camera.three); + const dimensions = label.world.renderer.getSize(); + screenPosition.x = (position.x * dimensions.x) / 2 + dimensions.x / 2; + screenPosition.y = -((position.y * dimensions.y) / 2) + dimensions.y / 2; + + return screenPosition; + } + + private distance(label1: Mark, label2: Mark) { + const screenPosition1 = this.getScreenPosition(label1); + const screenPosition2 = this.getScreenPosition(label2); + const dx = screenPosition1.x - screenPosition2.x; + const dy = screenPosition1.y - screenPosition2.y; + const distance = Math.sqrt(dx * dx + dy * dy) * 0.5; + // Managing Overlapping Labels + if (distance === 0) { + return this.threshold + 1; + } + return distance; + } + + private navigateToCluster(key: string) { + const boundingRegion: number[] = []; + + const cluster = Array.from(this.clusterLabels).find( + (cluster) => cluster.key === key, + ); + + if (!cluster) { + return; + } + + const camera = cluster.label.world.camera; + if (!camera.hasCameraControls()) { + console.warn("Zoom to clusters only supported with Camera Controls!"); + return; + } + + for (const markerKey of cluster.markerKeys) { + const marker = this.list.get(markerKey); + if (marker) { + const { x, y, z } = marker.label.three.position; + boundingRegion.push(x, y, z); + } + } + cluster.label.dispose(); + this.clusterLabels.delete(cluster); + + const geometry = new THREE.BufferGeometry(); + const buffer = new Float32Array(boundingRegion); + const attr = new THREE.BufferAttribute(buffer, 3); + geometry.setAttribute("position", attr); + + const mesh = new THREE.Mesh(geometry); + mesh.geometry.computeBoundingSphere(); + const boundingSphere = mesh.geometry.boundingSphere; + + if (boundingSphere) { + camera.controls.fitToSphere(mesh, true); + } + + this.isNavigating = true; + geometry.dispose(); + mesh.clear(); + + boundingRegion.length = 0; + } +} diff --git a/packages/components-front/src/core/Marker/src/index.ts b/packages/components-front/src/core/Marker/src/index.ts new file mode 100644 index 000000000..2f89b4d92 --- /dev/null +++ b/packages/components-front/src/core/Marker/src/index.ts @@ -0,0 +1 @@ +export * from "./mark"; diff --git a/packages/components-front/src/core/Marker/src/mark.ts b/packages/components-front/src/core/Marker/src/mark.ts new file mode 100644 index 000000000..9ff5e04a8 --- /dev/null +++ b/packages/components-front/src/core/Marker/src/mark.ts @@ -0,0 +1,56 @@ +import * as THREE from "three"; +import { CSS2DObject } from "three/examples/jsm/renderers/CSS2DRenderer.js"; +import * as OBC from "@thatopen/components"; + +export class Mark implements OBC.Hideable, OBC.Disposable { + three: CSS2DObject; + + world: OBC.World; + + /** {@link Disposable.onDisposed} */ + readonly onDisposed = new OBC.Event(); + + set visible(value: boolean) { + this.three.visible = value; + } + + get visible() { + return this.three.visible; + } + + // Define marker as setup configuration? + constructor( + world: OBC.World, + element?: HTMLElement, + parent?: THREE.Object3D, + ) { + this.world = world; + + let marker: HTMLElement; + if (element) { + marker = element; + } else { + marker = document.createElement("div"); + marker.className = + "w-[15px] h-[15px] border-3 border-solid border-red-600"; + } + + this.three = new CSS2DObject(marker); + + const container = parent || world.scene.three; + container.add(this.three); + + this.visible = true; + } + + toggleVisibility() { + this.visible = !this.visible; + } + + dispose() { + this.three.removeFromParent(); + this.three.element.remove(); + this.onDisposed.trigger(); + this.onDisposed.reset(); + } +} diff --git a/packages/components-front/src/core/Renderers/SimplerendererWithHTML/index.ts b/packages/components-front/src/core/RendererWith2D/index.ts similarity index 91% rename from packages/components-front/src/core/Renderers/SimplerendererWithHTML/index.ts rename to packages/components-front/src/core/RendererWith2D/index.ts index beb1977a2..007563e9c 100644 --- a/packages/components-front/src/core/Renderers/SimplerendererWithHTML/index.ts +++ b/packages/components-front/src/core/RendererWith2D/index.ts @@ -8,7 +8,7 @@ import { Components, SimpleRenderer } from "@thatopen/components"; * [CSS2DObjects](https://threejs.org/docs/#examples/en/renderers/CSS2DRenderer) * respectively). */ -export class SimpleRendererWithHTML extends SimpleRenderer { +export class RendererWith2D extends SimpleRenderer { three2D = new CSS2DRenderer(); constructor( @@ -41,6 +41,7 @@ export class SimpleRendererWithHTML extends SimpleRenderer { }); this.setupHtmlRenderer(); + this.resize(); } private setupHtmlRenderer() { @@ -48,7 +49,7 @@ export class SimpleRendererWithHTML extends SimpleRenderer { this.three2D.domElement.style.top = "0px"; this.three2D.domElement.style.pointerEvents = "none"; if (this.container) { - this.container.appendChild(this.three.domElement); + this.container.appendChild(this.three2D.domElement); } } } diff --git a/packages/components-front/src/core/Renderers/index.ts b/packages/components-front/src/core/Renderers/index.ts deleted file mode 100644 index 6e3b58a09..000000000 --- a/packages/components-front/src/core/Renderers/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./SimplerendererWithHTML"; diff --git a/packages/components-front/src/core/index.ts b/packages/components-front/src/core/index.ts index 8d0c99ef1..019396254 100644 --- a/packages/components-front/src/core/index.ts +++ b/packages/components-front/src/core/index.ts @@ -1 +1,2 @@ -export * from "./Renderers"; +export * from "./RendererWith2D"; +export * from "./Marker"; diff --git a/packages/components-front/src/index.js b/packages/components-front/src/index.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/components-front/src/index.ts b/packages/components-front/src/index.ts index 8d119dee8..c93ceba97 100644 --- a/packages/components-front/src/index.ts +++ b/packages/components-front/src/index.ts @@ -1 +1,2 @@ export * from "./core"; +// export * from "./civil"; diff --git a/packages/components/src/core/Clipper/example.ts b/packages/components/src/core/Clipper/example.ts index 145ae87e5..615e352db 100644 --- a/packages/components/src/core/Clipper/example.ts +++ b/packages/components/src/core/Clipper/example.ts @@ -9,18 +9,16 @@ const container = document.getElementById("container")!; const components = new OBC.Components(); const worlds = components.get(OBC.Worlds); -const world = new OBC.SimpleWorld< +const world = worlds.create< OBC.SimpleScene, OBC.SimpleCamera, OBC.SimpleRenderer ->(components); +>(); world.scene = new OBC.SimpleScene(components); world.renderer = new OBC.SimpleRenderer(components, container); world.camera = new OBC.SimpleCamera(components); -worlds.add(world); - components.init(); world.camera.controls.setLookAt(10, 10, 10, 0, 0, 0); @@ -63,7 +61,7 @@ cube.position.set(0, 1.5, 0); */ world.scene.three.add(cube); -components.meshes.add(cube); +world.meshes.add(cube); /* MD ### ⚙️ Adding Simple Clipper @@ -73,7 +71,6 @@ components.meshes.add(cube); */ const clipper = new OBC.Clipper(components); -clipper.world = world; /* MD @@ -106,7 +103,7 @@ clipper.enabled = true; */ -container.ondblclick = () => clipper.create(); +container.ondblclick = () => clipper.create(world); /* MD @@ -129,7 +126,7 @@ container.ondblclick = () => clipper.create(); window.onkeydown = (event) => { if (event.code === "Delete" || event.code === "Backspace") { - clipper.delete(); + clipper.delete(world); } }; diff --git a/packages/components/src/core/Clipper/index.ts b/packages/components/src/core/Clipper/index.ts index ad7e5f0b0..162ed4cd1 100644 --- a/packages/components/src/core/Clipper/index.ts +++ b/packages/components/src/core/Clipper/index.ts @@ -10,6 +10,7 @@ import { import { SimplePlane } from "./src"; import { Components } from "../Components"; import { Raycasters } from "../Raycasters"; +import { Worlds } from "../Worlds"; export * from "./src"; @@ -50,23 +51,6 @@ export class Clipper /** {@link Disposable.onDisposed} */ readonly onDisposed = new Event(); - protected _world: World | null = null; - - get world() { - return this._world; - } - - set world(world: World | null) { - this._world = world; - const casters = this.components.get(Raycasters); - if (world === null) return; - // Create raycaster if it doesn't exist, so that when the user - // creates the first plane, the mouse position is tracked - if (!casters.list.has(world.uuid)) { - casters.get(world); - } - } - /** * Whether to force the clipping plane to be orthogonal in the Y direction * (up). This is desirable when clipping a building horizontally and a @@ -181,18 +165,15 @@ export class Clipper } /** {@link Createable.create} */ - create() { + create(world: World) { if (!this.enabled) return; - if (!this._world) { - throw new Error("You must set a world before creating a plane!"); - } const casters = this.components.get(Raycasters); - const caster = casters.get(this._world); + const caster = casters.get(world); const intersects = caster.castRay(); if (intersects) { - this.createPlaneFromIntersection(intersects); + this.createPlaneFromIntersection(world, intersects); } } @@ -200,15 +181,17 @@ export class Clipper * Creates a plane in a certain place and with a certain orientation, * without the need of the mouse. * + * @param world - the world where this plane should be created. * @param normal - the orientation of the clipping plane. * @param point - the position of the clipping plane. * navigation. */ createFromNormalAndCoplanarPoint( + world: World, normal: THREE.Vector3, point: THREE.Vector3, ) { - const plane = this.newPlane(point, normal); + const plane = this.newPlane(world, point, normal); this.updateMaterialsAndPlanes(); return plane; } @@ -216,13 +199,14 @@ export class Clipper /** * {@link Createable.delete} * + * @param world - the world where the plane to delete is. * @param plane - the plane to delete. If undefined, the first plane * found under the cursor will be deleted. */ - delete(plane?: T) { + delete(world: World, plane?: T) { if (!this.enabled) return; if (!plane) { - plane = this.pickPlane(); + plane = this.pickPlane(world); } if (!plane) { return; @@ -233,34 +217,28 @@ export class Clipper /** Deletes all the existing clipping planes. */ deleteAll() { while (this.planes.length > 0) { - this.delete(this.planes[0]); + const plane = this.planes[0]; + this.delete(plane.world, plane); } } private deletePlane(plane: T) { - if (!this._world) { - throw new Error("You must select a world to delete a plane!"); - } - if (!this._world.renderer) { - console.warn("The selected world doesn't have a renderer."); - return; - } const index = this.planes.indexOf(plane); if (index !== -1) { this.planes.splice(index, 1); - this._world.renderer.setPlane(false, plane.three); + if (!plane.world.renderer) { + throw new Error("Renderer not found for this plane's world!"); + } + plane.world.renderer.setPlane(false, plane.three); plane.dispose(); this.updateMaterialsAndPlanes(); this.onAfterDelete.trigger(plane); } } - private pickPlane(): T | undefined { - if (!this._world) { - throw new Error("World not found!"); - } + private pickPlane(world: World): T | undefined { const casters = this.components.get(Raycasters); - const caster = casters.get(this._world); + const caster = casters.get(world); const meshes = this.getAllPlaneMeshes(); const intersects = caster.castRay(meshes); if (intersects) { @@ -278,21 +256,20 @@ export class Clipper return meshes; } - private createPlaneFromIntersection(intersect: THREE.Intersection) { - if (!this._world) { - throw new Error("World not found!"); - } - if (!this._world.renderer) { - console.warn("The selected world doesn't have a renderer."); - return; + private createPlaneFromIntersection( + world: World, + intersect: THREE.Intersection, + ) { + if (!world.renderer) { + throw new Error("The given world must have a renderer!"); } const constant = intersect.point.distanceTo(new THREE.Vector3(0, 0, 0)); const normal = intersect.face?.normal; if (!constant || !normal) return; const worldNormal = this.getWorldNormal(intersect, normal); - const plane = this.newPlane(intersect.point, worldNormal.negate()); - this._world.renderer.setPlane(true, plane.three); + const plane = this.newPlane(world, intersect.point, worldNormal.negate()); + world.renderer.setPlane(true, plane.three); this.updateMaterialsAndPlanes(); } @@ -326,8 +303,8 @@ export class Clipper } } - private newPlane(point: THREE.Vector3, normal: THREE.Vector3) { - const plane = this.newPlaneInstance(point, normal); + private newPlane(world: World, point: THREE.Vector3, normal: THREE.Vector3) { + const plane = this.newPlaneInstance(world, point, normal); plane.onDraggingStarted.add(this._onStartDragging); plane.onDraggingEnded.add(this._onEndDragging); this.planes.push(plane); @@ -335,10 +312,14 @@ export class Clipper return plane; } - protected newPlaneInstance(point: THREE.Vector3, normal: THREE.Vector3) { + protected newPlaneInstance( + world: World, + point: THREE.Vector3, + normal: THREE.Vector3, + ) { return new this.PlaneType( this.components, - this._world, + world, point, normal, this._material, @@ -346,22 +327,21 @@ export class Clipper } private updateMaterialsAndPlanes() { - if (!this._world) { - throw new Error("World not found!"); - } - if (!this._world.renderer) { - console.warn("The selected world doesn't have a renderer."); - return; - } - this._world.renderer.updateClippingPlanes(); - const { clippingPlanes } = this._world.renderer; - for (const model of this.components.meshes) { - if (Array.isArray(model.material)) { - for (const mat of model.material) { - mat.clippingPlanes = clippingPlanes; + const worlds = this.components.get(Worlds); + for (const [_id, world] of worlds.list) { + if (!world.renderer) { + continue; + } + world.renderer.updateClippingPlanes(); + const { clippingPlanes } = world.renderer; + for (const model of world.meshes) { + if (Array.isArray(model.material)) { + for (const mat of model.material) { + mat.clippingPlanes = clippingPlanes; + } + } else { + model.material.clippingPlanes = clippingPlanes; } - } else { - model.material.clippingPlanes = clippingPlanes; } } } diff --git a/packages/components/src/core/Components/index.ts b/packages/components/src/core/Components/index.ts index 39faddb92..dd8ebead6 100644 --- a/packages/components/src/core/Components/index.ts +++ b/packages/components/src/core/Components/index.ts @@ -5,7 +5,6 @@ import { disposeBoundsTree, } from "three-mesh-bvh"; import { Component, Disposable, Event } from "../Types"; -import { Disposer } from "../Disposer"; import { UUID } from "../../utils"; /** @@ -18,11 +17,6 @@ import { UUID } from "../../utils"; export class Components implements Disposable { static readonly release = "1.4.21"; - /** - * All the loaded [meshes](https://threejs.org/docs/#api/en/objects/Mesh). - */ - readonly meshes = new Set(); - /** {@link Disposable.onDisposed} */ readonly onDisposed = new Event(); @@ -95,7 +89,6 @@ export class Components implements Disposable { * */ dispose() { - const disposer = this.get(Disposer); this.enabled = false; for (const [_id, component] of this.list) { @@ -106,11 +99,7 @@ export class Components implements Disposable { } this._clock.stop(); - for (const mesh of this.meshes) { - disposer.destroy(mesh); - } - this.meshes.clear(); this.onDisposed.trigger(); this.onDisposed.reset(); } diff --git a/packages/components/src/core/Cullers/example.ts b/packages/components/src/core/Cullers/example.ts index 4c30aedc5..630e8e311 100644 --- a/packages/components/src/core/Cullers/example.ts +++ b/packages/components/src/core/Cullers/example.ts @@ -8,18 +8,16 @@ const container = document.getElementById("container")!; const components = new OBC.Components(); const worlds = components.get(OBC.Worlds); -const world = new OBC.SimpleWorld< +const world = worlds.create< OBC.SimpleScene, OBC.SimpleCamera, OBC.SimpleRenderer ->(components); +>(); world.scene = new OBC.SimpleScene(components); world.renderer = new OBC.SimpleRenderer(components, container); world.camera = new OBC.SimpleCamera(components); -worlds.add(world); - components.init(); world.camera.controls.setLookAt(13, 13, 13, 0, 0, 0); diff --git a/packages/components/src/core/Grids/example.ts b/packages/components/src/core/Grids/example.ts index f4bb16cde..5be35c054 100644 --- a/packages/components/src/core/Grids/example.ts +++ b/packages/components/src/core/Grids/example.ts @@ -6,18 +6,16 @@ const container = document.getElementById("container")!; const components = new OBC.Components(); const worlds = components.get(OBC.Worlds); -const world = new OBC.SimpleWorld< +const world = worlds.create< OBC.SimpleScene, OBC.SimpleCamera, OBC.SimpleRenderer ->(components); +>(); world.scene = new OBC.SimpleScene(components); world.renderer = new OBC.SimpleRenderer(components, container); world.camera = new OBC.SimpleCamera(components); -worlds.add(world); - components.init(); const cube = new THREE.Mesh(new THREE.BoxGeometry()); diff --git a/packages/components/src/core/Materials/example.ts b/packages/components/src/core/Materials/example.ts index fa5a972cf..c3521a026 100644 --- a/packages/components/src/core/Materials/example.ts +++ b/packages/components/src/core/Materials/example.ts @@ -9,18 +9,16 @@ const container = document.getElementById("container")!; const components = new OBC.Components(); const worlds = components.get(OBC.Worlds); -const world = new OBC.SimpleWorld< +const world = worlds.create< OBC.SimpleScene, OBC.SimpleCamera, OBC.SimpleRenderer ->(components); +>(); world.scene = new OBC.SimpleScene(components); world.renderer = new OBC.SimpleRenderer(components, container); world.camera = new OBC.SimpleCamera(components); -worlds.add(world); - components.init(); world.camera.controls.setLookAt(13, 13, 13, 0, 0, 0); diff --git a/packages/components/src/core/Raycasters/example.ts b/packages/components/src/core/Raycasters/example.ts index 89d892b17..cb830270a 100644 --- a/packages/components/src/core/Raycasters/example.ts +++ b/packages/components/src/core/Raycasters/example.ts @@ -6,18 +6,16 @@ const container = document.getElementById("container")!; const components = new OBC.Components(); const worlds = components.get(OBC.Worlds); -const world = new OBC.SimpleWorld< +const world = worlds.create< OBC.SimpleScene, OBC.SimpleCamera, OBC.SimpleRenderer ->(components); +>(); world.scene = new OBC.SimpleScene(components); world.renderer = new OBC.SimpleRenderer(components, container); world.camera = new OBC.SimpleCamera(components); -worlds.add(world); - components.init(); world.camera.controls.setLookAt(10, 10, 10, 0, 0, 0); diff --git a/packages/components/src/core/Raycasters/src/simple-raycaster.ts b/packages/components/src/core/Raycasters/src/simple-raycaster.ts index abfea8e2a..58f6251a2 100644 --- a/packages/components/src/core/Raycasters/src/simple-raycaster.ts +++ b/packages/components/src/core/Raycasters/src/simple-raycaster.ts @@ -51,7 +51,7 @@ export class SimpleRaycaster implements Disposable { * {@link Components.meshes}. */ castRay( - items: THREE.Mesh[] = Array.from(this.components.meshes), + items: THREE.Mesh[] = Array.from(this.world.meshes), ): THREE.Intersection | null { if (!this.world) { throw new Error("A world is needed to cast rays!"); @@ -64,13 +64,13 @@ export class SimpleRaycaster implements Disposable { castRayFromVector( origin: THREE.Vector3, direction: THREE.Vector3, - items = Array.from(this.components.meshes), + items = Array.from(this.world.meshes), ) { this.three.set(origin, direction); return this.intersect(items); } - private intersect(items: THREE.Mesh[] = Array.from(this.components.meshes)) { + private intersect(items: THREE.Mesh[] = Array.from(this.world.meshes)) { const result = this.three.intersectObjects(items); const filtered = this.filterClippingPlanes(result); return filtered.length > 0 ? filtered[0] : null; diff --git a/packages/components/src/core/Types/src/base-camera.ts b/packages/components/src/core/Types/src/base-camera.ts index 81da3ba8b..43c147d7e 100644 --- a/packages/components/src/core/Types/src/base-camera.ts +++ b/packages/components/src/core/Types/src/base-camera.ts @@ -1,7 +1,16 @@ import * as THREE from "three"; +import CameraControls from "camera-controls"; import { BaseWorldItem } from "./base-world-item"; +import { CameraControllable } from "./interfaces"; export abstract class BaseCamera extends BaseWorldItem { abstract enabled: boolean; abstract three: THREE.Camera; + + abstract controls?: CameraControls; + + /** Whether is instance is {@link CameraControllable}. */ + hasCameraControls = (): this is CameraControllable => { + return "controls" in this; + }; } diff --git a/packages/components/src/core/Types/src/interfaces.ts b/packages/components/src/core/Types/src/interfaces.ts index 1908920a2..5c58e5815 100644 --- a/packages/components/src/core/Types/src/interfaces.ts +++ b/packages/components/src/core/Types/src/interfaces.ts @@ -1,4 +1,5 @@ import * as THREE from "three"; +import CameraControls from "camera-controls"; import { Event } from "./event"; /** @@ -151,3 +152,10 @@ export interface BVHGeometry extends THREE.BufferGeometry { boundsTree: Object | undefined; disposeBoundsTree: () => void; } + +/** + * Whether a camera uses the Camera Controls library. + */ +export interface CameraControllable { + controls: CameraControls; +} diff --git a/packages/components/src/core/Types/src/world.ts b/packages/components/src/core/Types/src/world.ts index 53f6087fe..f9bcabc5b 100644 --- a/packages/components/src/core/Types/src/world.ts +++ b/packages/components/src/core/Types/src/world.ts @@ -1,9 +1,11 @@ +import * as THREE from "three"; import { BaseScene } from "./base-scene"; import { BaseCamera } from "./base-camera"; import { BaseRenderer } from "./base-renderer"; import { Updateable, Disposable } from "./interfaces"; export interface World extends Disposable, Updateable { + meshes: Set; scene: BaseScene; camera: BaseCamera; renderer: BaseRenderer | null; diff --git a/packages/components/src/core/Worlds/example.ts b/packages/components/src/core/Worlds/example.ts index 402db9048..a285f1702 100644 --- a/packages/components/src/core/Worlds/example.ts +++ b/packages/components/src/core/Worlds/example.ts @@ -6,18 +6,17 @@ const container = document.getElementById("container")!; const components = new OBC.Components(); const worlds = components.get(OBC.Worlds); -const world = new OBC.SimpleWorld< + +const world = worlds.create< OBC.SimpleScene, OBC.SimpleCamera, OBC.SimpleRenderer ->(components); +>(); world.scene = new OBC.SimpleScene(components); world.renderer = new OBC.SimpleRenderer(components, container); world.camera = new OBC.SimpleCamera(components); -worlds.add(world); - components.init(); const cube = new THREE.Mesh(new THREE.BoxGeometry()); diff --git a/packages/components/src/core/Worlds/index.ts b/packages/components/src/core/Worlds/index.ts index b871e4055..86aac8d98 100644 --- a/packages/components/src/core/Worlds/index.ts +++ b/packages/components/src/core/Worlds/index.ts @@ -1,5 +1,15 @@ -import { Component, Disposable, Updateable, World, Event } from "../Types"; +import { + Component, + Disposable, + Updateable, + World, + Event, + BaseScene, + BaseCamera, + BaseRenderer, +} from "../Types"; import { Components } from "../Components"; +import { SimpleWorld } from "./src"; export * from "./src"; @@ -21,12 +31,23 @@ export class Worlds extends Component implements Updateable, Disposable { components.add(Worlds.uuid, this); } - add(world: World) { + create< + T extends BaseScene = BaseScene, + U extends BaseCamera = BaseCamera, + S extends BaseRenderer = BaseRenderer, + >() { + const world = new SimpleWorld(this.components); const id = world.uuid; if (this.list.has(id)) { throw new Error("There is already a world with this name!"); } this.list.set(id, world); + return world; + } + + delete(world: World) { + this.list.delete(world.uuid); + world.dispose(); } dispose() { @@ -34,6 +55,7 @@ export class Worlds extends Component implements Updateable, Disposable { for (const [_id, world] of this.list) { world.dispose(); } + this.list.clear(); this.onDisposed.trigger(); } diff --git a/packages/components/src/core/Worlds/src/simple-renderer.ts b/packages/components/src/core/Worlds/src/simple-renderer.ts index d61054972..23c4dc838 100644 --- a/packages/components/src/core/Worlds/src/simple-renderer.ts +++ b/packages/components/src/core/Worlds/src/simple-renderer.ts @@ -100,7 +100,7 @@ export class SimpleRenderer extends BaseRenderer { const height = size ? size.y : this.container.clientHeight; this.three.setSize(width, height); // this._renderer2D.setSize(width, height); - this.onResize.trigger(size); + this.onResize.trigger(new THREE.Vector2(width, height)); }; setupEvents(active: boolean) { diff --git a/packages/components/src/core/Worlds/src/simple-world.ts b/packages/components/src/core/Worlds/src/simple-world.ts index a70cc5e24..62875fbff 100644 --- a/packages/components/src/core/Worlds/src/simple-world.ts +++ b/packages/components/src/core/Worlds/src/simple-world.ts @@ -1,3 +1,4 @@ +import * as THREE from "three"; import { UUID } from "../../../utils"; import { Event, @@ -8,6 +9,7 @@ import { BaseRenderer, } from "../../Types"; import { Components } from "../../Components"; +import { Disposer } from "../../Disposer"; export class SimpleWorld< T extends BaseScene = BaseScene, @@ -17,6 +19,11 @@ export class SimpleWorld< extends Base implements World { + /** + * All the loaded [meshes](https://threejs.org/docs/#api/en/objects/Mesh). + */ + readonly meshes = new Set(); + readonly onAfterUpdate = new Event(); readonly onBeforeUpdate = new Event(); @@ -81,6 +88,10 @@ export class SimpleWorld< update(delta?: number) { if (!this.enabled) return; + if (!this._scene || !this._camera) { + return; + } + this.scene.currentWorld = this; this.camera.currentWorld = this; if (this.renderer) { @@ -114,6 +125,8 @@ export class SimpleWorld< } if (disposeResources) { + const disposer = this.components.get(Disposer); + this.scene.dispose(); if (this.camera.isDisposeable()) { this.camera.dispose(); @@ -121,6 +134,11 @@ export class SimpleWorld< if (this.renderer) { this.renderer.dispose(); } + for (const mesh of this.meshes) { + disposer.destroy(mesh); + } + + this.meshes.clear(); } this._scene = null as any; diff --git a/temp/core/Simple2DMarker/index.ts b/temp/core/Simple2DMarker/index.ts deleted file mode 100644 index a54dd3efa..000000000 --- a/temp/core/Simple2DMarker/index.ts +++ /dev/null @@ -1,68 +0,0 @@ -import * as THREE from "three"; -import { CSS2DObject } from "three/examples/jsm/renderers/CSS2DRenderer.js"; -import { Hideable, Disposable, Event } from "../../base-types"; -import { Component } from "../../base-types/component"; -import { Components } from "../Components"; - -export class Simple2DMarker - extends Component - implements Hideable, Disposable -{ - /** {@link Component.enabled} */ - enabled: boolean = true; - - private _visible: boolean = true; - private _marker: CSS2DObject; - - set visible(value: boolean) { - this._visible = value; - this._marker.visible = value; - } - - get visible() { - return this._visible; - } - - // Define marker as setup configuration? - constructor( - components: Components, - marker?: HTMLElement, - parent?: THREE.Object3D, - ) { - super(components); - let _marker: HTMLElement; - if (marker) { - _marker = marker; - } else { - _marker = document.createElement("div"); - _marker.className = - "w-[15px] h-[15px] border-3 border-solid border-red-600"; - } - this._marker = new CSS2DObject(_marker); - if (parent) { - parent.add(this._marker); - } else { - this.components.scene.get().add(this._marker); - } - this.visible = true; - } - - /** {@link Component.get} */ - get(): CSS2DObject { - return this._marker; - } - - toggleVisibility() { - this.visible = !this.visible; - } - - /** {@link Disposable.onDisposed} */ - readonly onDisposed = new Event(); - - async dispose() { - this._marker.removeFromParent(); - this._marker.element.remove(); - await this.onDisposed.trigger(); - this.onDisposed.reset(); - } -} diff --git a/temp/core/Simple2DMarker/src/marker-manager.ts b/temp/core/Simple2DMarker/src/marker-manager.ts deleted file mode 100644 index 148cabdc0..000000000 --- a/temp/core/Simple2DMarker/src/marker-manager.ts +++ /dev/null @@ -1,606 +0,0 @@ -import * as FRAGS from "bim-fragment"; -import * as THREE from "three"; -import CameraControls from "camera-controls"; -import { Components, Simple2DMarker, SimpleRenderer } from "../.."; -import { PostproductionRenderer } from "../../../navigation"; - -type CivilLabels = - | "Station" - | "Radius" - | "Length" - | "InitialKP" - | "FinalKP" - | "KP" - | "Slope" - | "Height" - | "InitialKPV" - | "FinalKPV"; - -interface IMarker { - key: string; - label: Simple2DMarker; - mesh: FRAGS.CurveMesh | THREE.Mesh | THREE.Line; - type?: CivilLabels; - merged: boolean; - static: boolean; -} - -interface IGroupedLabels { - key: string; - markerKeys: string[]; - label: Simple2DMarker; -} - -/** - * Class for Managing Markers along with creating different types of markers - * Every marker is a Simple2DMarker - * For every marker that needs to be added, you can use the Manager to add the marker and change its look and feel - */ -export class MarkerManager { - private markers: Set = new Set(); - private clusterLabels: Set = new Set(); - - private currentKeys: Set = new Set(); - - private scene: THREE.Group | THREE.Scene; - private _clusterOnZoom = true; - private _color = "white"; - - // TODO: Replace with UUID for the marker key - private _markerKey = 0; - private _clusterKey = 0; - - private _clusterThreeshold = 50; - private isNavigating = false; - - constructor( - private components: Components, - private renderer: SimpleRenderer | PostproductionRenderer, - scene: THREE.Group | THREE.Scene, - private controls: CameraControls - ) { - this.scene = scene; - this.setupEvents(); - } - - set clusterOnZoom(value: boolean) { - this._clusterOnZoom = value; - } - - get clusterOnZoom() { - return this._clusterOnZoom; - } - - set color(value: string) { - this._color = value; - for (const marker of this.markers) { - marker.label.get().element.style.color = value; - } - } - - set clusterThreeshold(value: number) { - this._clusterThreeshold = value; - } - - get clusterThreeshold() { - return this._clusterThreeshold; - } - - private setupEvents() { - if (this.scene) { - this.controls.addEventListener("sleep", () => { - this.manageCluster(); - }); - - this.controls.addEventListener("rest", () => { - if (this.isNavigating) { - this.manageCluster(); - this.isNavigating = false; - } - }); - } - } - - private resetMarkers() { - for (const marker of this.markers) { - marker.merged = false; - } - for (const cluster of this.clusterLabels) { - this.scene.remove(cluster.label.get()); - } - this.clusterLabels.clear(); - this._clusterKey = 0; - } - - private removeMergeMarkers() { - for (const marker of this.markers) { - if (marker.merged) { - this.scene.remove(marker.label.get()); - } else { - this.scene.add(marker.label.get()); - } - } - - for (const cluster of this.clusterLabels) { - if (cluster.markerKeys.length === 1) { - const marker = Array.from(this.markers).find( - (marker) => marker.key === cluster.markerKeys[0] - ); - - if (marker) { - this.scene.add(marker.label.get()); - marker.merged = false; - } - - this.scene.remove(cluster.label.get()); - this.clusterLabels.delete(cluster); - } - } - } - - private manageCluster() { - this.resetMarkers(); - - for (const marker of this.markers) { - if (!marker.merged && !marker.static) { - this.currentKeys.clear(); - for (const marker2 of this.markers) { - if (marker2.static) { - continue; - } - if (marker.key !== marker2.key && !marker2.merged) { - const distance = this.distance(marker.label, marker2.label); - if (distance < this._clusterThreeshold) { - this.currentKeys.add(marker2.key); - marker2.merged = true; - } - } - } - if (this.currentKeys.size > 0) { - if (!this.scene) { - return; - } - this.currentKeys.add(marker.key); - marker.merged = true; - const clusterGroup = Array.from(this.currentKeys); - const averagePosition = - this.getAveragePositionFromLabels(clusterGroup); - const clusterLabel = new Simple2DMarker( - this.components, - this.createClusterElement(this._clusterKey.toString()), - this.scene - ); - clusterLabel.get().element.textContent = - clusterGroup.length.toString(); - clusterLabel.get().position.copy(averagePosition); - this.clusterLabels.add({ - key: this._clusterKey.toString(), - markerKeys: clusterGroup, - label: clusterLabel, - }); - this._clusterKey++; - } - } - } - - this.removeMergeMarkers(); - } - - getAveragePositionFromLabels(clusterGroup: string[]) { - const positions = clusterGroup.map((key) => { - const marker = Array.from(this.markers).find( - (marker: IMarker) => marker.key === key - ); - if (marker) { - return marker.label.get().position; - } - return new THREE.Vector3(); - }); - const averagePosition = positions - .reduce((acc, curr) => acc.add(curr), new THREE.Vector3()) - .divideScalar(positions.length); - return averagePosition; - } - - private createClusterElement(key: string) { - const div = document.createElement("div"); - div.textContent = key; - div.style.color = "#000000"; - div.style.background = "#FFFFFF"; - div.style.fontSize = "1.2rem"; - div.style.fontWeight = "500"; - div.style.pointerEvents = "auto"; - div.style.borderRadius = "50%"; - div.style.padding = "5px 11px"; - div.style.textAlign = "center"; - div.style.cursor = "pointer"; - // div.style.transition = "all 0.05s"; - div.addEventListener("pointerdown", () => { - this.navigateToCluster(key); - }); - div.addEventListener("pointerover", () => { - div.style.background = "#BCF124"; - }); - div.addEventListener("pointerout", () => { - div.style.background = "#FFFFFF"; - }); - return div; - } - - addMarker(text: string, mesh: THREE.Mesh) { - const span = document.createElement("span"); - span.innerHTML = text; - span.style.color = this._color; - - const marker = this.addMarkerToScene(span); - - marker.get().position.copy(mesh.position); - this.markers.add({ - label: marker, - mesh, - key: this._markerKey.toString(), - merged: false, - static: false, - }); - this._markerKey++; - } - - addMarkerAtPoint( - text: string, - point: THREE.Vector3, - type?: CivilLabels | undefined, - isStatic = false - ) { - if (type !== undefined) { - const span = document.createElement("span"); - span.innerHTML = text; - span.style.color = this._color; - - const marker = new Simple2DMarker(this.components, span, this.scene); - - marker.get().position.copy(point); - this.markers.add({ - label: marker, - mesh: new THREE.Mesh(), - key: this._markerKey.toString(), - merged: false, - type, - static: isStatic, - }); - this._markerKey++; - } else { - // Generating Labels that are perpendicular to the point and has dotted line beneath it - } - } - - // TODO: Move this to switch statement inside addCivilMarker - addKPStation(text: string, mesh: THREE.Line) { - const container = document.createElement("div"); - const span = document.createElement("div"); - container.appendChild(span); - - span.innerHTML = text; - - span.style.color = this._color; - span.style.borderBottom = "1px dotted white"; - span.style.width = "160px"; - span.style.textAlign = "left"; - - const marker = new Simple2DMarker(this.components, container, this.scene); - - const point = new THREE.Vector3(); - point.x = mesh.geometry.attributes.position.getX( - mesh.geometry.attributes.position.count - 1 - ); - point.y = mesh.geometry.attributes.position.getY( - mesh.geometry.attributes.position.count - 1 - ); - point.z = mesh.geometry.attributes.position.getZ( - mesh.geometry.attributes.position.count - 1 - ); - - const secondLastPoint = new THREE.Vector3(); - secondLastPoint.x = mesh.geometry.attributes.position.getX( - mesh.geometry.attributes.position.count - 2 - ); - secondLastPoint.y = mesh.geometry.attributes.position.getY( - mesh.geometry.attributes.position.count - 2 - ); - secondLastPoint.z = mesh.geometry.attributes.position.getZ( - mesh.geometry.attributes.position.count - 2 - ); - - const midPoint = new THREE.Vector3(); - midPoint.x = (point.x + secondLastPoint.x) / 2; - midPoint.y = (point.y + secondLastPoint.y) / 2; - midPoint.z = (point.z + secondLastPoint.z) / 2; - - marker.get().position.copy(midPoint); - - const direction = new THREE.Vector3(); - direction.subVectors(point, secondLastPoint).normalize(); - const quaternion = new THREE.Quaternion(); - quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), direction); - - const eulerZ = new THREE.Euler().setFromQuaternion(quaternion).z; - const rotationZ = THREE.MathUtils.radToDeg(eulerZ); - - span.style.transform = `rotate(${ - -rotationZ - 90 - }deg) translate(-35%, -50%)`; - - this.markers.add({ - label: marker, - mesh, - key: this._markerKey.toString(), - merged: false, - static: false, - }); - this._markerKey++; - } - - addCivilVerticalMarker( - text: string, - mesh: FRAGS.CurveMesh, - type: CivilLabels, - root: THREE.Object3D - ) { - const span = document.createElement("span"); - span.innerHTML = text; - span.style.color = this._color; - - const marker = new Simple2DMarker(this.components, span, root); - - if (type === "Height") { - const span = document.createElement("span"); - span.innerHTML = text; - span.style.color = this._color; - - const { position } = mesh.geometry.attributes; - const setArray = position.array.length / 3; - - const firstIndex = (setArray - 1) * 3; - const lastIndex = position.array.slice(firstIndex, firstIndex + 3); - - marker.get().position.set(lastIndex[0], lastIndex[1] + 10, lastIndex[2]); - } else if (type === "InitialKPV") { - const { position } = mesh.geometry.attributes; - - const pX = position.getX(0); - const pY = position.getY(0); - const pZ = position.getZ(0); - - marker.get().position.set(pX - 20, pY, pZ); - } else if (type === "FinalKPV") { - const { position } = mesh.geometry.attributes; - - const pX = position.getX(mesh.geometry.attributes.position.count - 1); - const pY = position.getY(mesh.geometry.attributes.position.count - 1); - const pZ = position.getZ(mesh.geometry.attributes.position.count - 1); - - marker.get().position.set(pX + 20, pY, pZ); - } else if (type === "Slope") { - span.style.color = "grey"; - const { position } = mesh.geometry.attributes; - - const pointStart = new THREE.Vector3(); - pointStart.x = position.getX(0); - pointStart.y = position.getY(0); - pointStart.z = position.getZ(0); - - const pointEnd = new THREE.Vector3(); - pointEnd.x = position.getX(position.count - 1); - pointEnd.y = position.getY(position.count - 1); - pointEnd.z = position.getZ(position.count - 1); - - const midPoint = new THREE.Vector3(); - midPoint.addVectors(pointStart, pointEnd).multiplyScalar(0.5); - - marker.get().position.set(midPoint.x, midPoint.y - 10, midPoint.z); - } - - this.markers.add({ - label: marker, - mesh, - key: this._markerKey.toString(), - type, - merged: false, - static: false, - }); - this._markerKey++; - - return marker; - } - - addCivilMarker(text: string, mesh: FRAGS.CurveMesh, type: CivilLabels) { - const span = document.createElement("span"); - span.innerHTML = text; - span.style.color = this._color; - - const marker = this.addMarkerToScene(span); - - if (type === "InitialKP") { - const pX = mesh.geometry.attributes.position.getX(0); - const pY = mesh.geometry.attributes.position.getY(0); - const pZ = mesh.geometry.attributes.position.getZ(0); - marker.get().position.set(pX + 2, pY + 2, pZ); - } else if (type === "FinalKP") { - const pX = mesh.geometry.attributes.position.getX( - mesh.geometry.attributes.position.count - 1 - ); - const pY = mesh.geometry.attributes.position.getY( - mesh.geometry.attributes.position.count - 1 - ); - const pZ = mesh.geometry.attributes.position.getZ( - mesh.geometry.attributes.position.count - 1 - ); - marker.get().position.set(pX + 2, pY - 2, pZ); - } else if (type === "Length") { - const pointStart = new THREE.Vector3(); - pointStart.x = mesh.geometry.attributes.position.getX(0); - pointStart.y = mesh.geometry.attributes.position.getY(0); - pointStart.z = mesh.geometry.attributes.position.getZ(0); - - const pointEnd = new THREE.Vector3(); - pointEnd.x = mesh.geometry.attributes.position.getX( - mesh.geometry.attributes.position.count - 1 - ); - pointEnd.y = mesh.geometry.attributes.position.getY( - mesh.geometry.attributes.position.count - 1 - ); - pointEnd.z = mesh.geometry.attributes.position.getZ( - mesh.geometry.attributes.position.count - 1 - ); - - const length = pointStart.distanceTo(pointEnd); - marker.get().element.innerText = length.toFixed(2); - marker - .get() - .position.copy(pointEnd.clone().add(pointStart).divideScalar(2)); - } - - this.markers.add({ - label: marker, - mesh, - key: this._markerKey.toString(), - type, - merged: false, - static: false, - }); - this._markerKey++; - - return marker; - } - - private addMarkerToScene(span: HTMLSpanElement) { - if (!this.scene) { - throw new Error("Scene is needed to add markers!"); - } - const scene = this.scene; - const marker = new Simple2DMarker(this.components, span, scene); - return marker; - } - - private getScreenPosition(label: Simple2DMarker) { - const screenPosition = new THREE.Vector3(); - if (!this.scene) { - const labelPosition = label - .get() - .position.clone() - .project(this.components.camera.get()); - const dimensions = this.components.renderer.getSize(); - screenPosition.x = - (labelPosition.x * dimensions.x) / 2 + dimensions.x / 2; - screenPosition.y = - -((labelPosition.y * dimensions.y) / 2) + dimensions.y / 2; - } else { - const labelPosition = label - .get() - .position.clone() - .project(this.controls.camera); - const dimensions = this.renderer.getSize(); - screenPosition.x = - (labelPosition.x * dimensions.x) / 2 + dimensions.x / 2; - screenPosition.y = - -((labelPosition.y * dimensions.y) / 2) + dimensions.y / 2; - } - return screenPosition; - } - - private distance(label1: Simple2DMarker, label2: Simple2DMarker) { - const screenPosition1 = this.getScreenPosition(label1); - const screenPosition2 = this.getScreenPosition(label2); - const dx = screenPosition1.x - screenPosition2.x; - const dy = screenPosition1.y - screenPosition2.y; - const distance = Math.sqrt(dx * dx + dy * dy) * 0.5; - // Managing Overlapping Labels - if (distance === 0) { - const updateDistance = this._clusterThreeshold + 1; - return updateDistance; - } - return distance; - } - - private navigateToCluster(key: string) { - const boundingRegion: THREE.Vector3[] = []; - - const cluster = Array.from(this.clusterLabels).find( - (cluster) => cluster.key === key - ); - if (cluster) { - for (const markerKey of cluster.markerKeys) { - const marker = Array.from(this.markers).find( - (marker) => marker.key === markerKey - ); - if (marker) { - boundingRegion.push(marker.label.get().position); - } - } - this.scene.remove(cluster?.label.get()); - this.clusterLabels.delete(cluster); - } - if (this.scene) { - const box3 = this.createBox3FromPoints(boundingRegion); - const size = new THREE.Vector3(); - box3.getSize(size); - const center = new THREE.Vector3(); - box3.getCenter(center); - const geometry = new THREE.BoxGeometry(size.x, size.y, size.z); - geometry.translate(center.x, center.y, center.z); - const mesh = new THREE.Mesh(geometry); - mesh.geometry.computeBoundingSphere(); - const boundingSphere = mesh.geometry?.boundingSphere; - if (this.controls && boundingSphere) { - this.controls.fitToSphere(mesh, true); - } - this.isNavigating = true; - geometry.dispose(); - mesh.clear(); - } - - boundingRegion.length = 0; - } - - private createBox3FromPoints(points: THREE.Vector3[]) { - const bbox = new THREE.Box3(); - for (const point of points) { - bbox.expandByPoint(point); - } - return bbox; - } - - clearMarkers() { - for (const marker of this.markers) { - this.scene.remove(marker.label.get()); - } - this.markers.clear(); - this._markerKey = 0; - } - - clearMarkersByType(type: CivilLabels) { - for (const marker of this.markers) { - if (marker.type === type) { - this.scene.remove(marker.label.get()); - this.markers.delete(marker); - } - } - } - - dispose() { - for (const marker of this.markers) { - marker.label.dispose(); - } - - this.markers.clear(); - this._markerKey = 0; - - for (const cluster of this.clusterLabels) { - cluster.label.dispose(); - } - - this.clusterLabels.clear(); - this._clusterKey = 0; - - this.currentKeys.clear(); - } -} diff --git a/temp/core/Simple2DScene/example.ts b/temp/core/Simple2DScene/example.ts deleted file mode 100644 index ff8f35d42..000000000 --- a/temp/core/Simple2DScene/example.ts +++ /dev/null @@ -1,132 +0,0 @@ -import * as THREE from "three"; -import * as OBC from "../.."; - -const container = document.getElementById("container")!; - -const components = new OBC.Components(); - -const sceneComponent = new OBC.SimpleScene(components); -sceneComponent.setup(); -components.scene = sceneComponent; - -const rendererComponent = new OBC.PostproductionRenderer(components, container); -components.renderer = rendererComponent; - -const cameraComponent = new OBC.SimpleCamera(components); -components.camera = cameraComponent; - -components.raycaster = new OBC.SimpleRaycaster(components); - -components.init(); - -const scene = components.scene.get(); - -cameraComponent.controls.setLookAt(10, 10, 10, 0, 0, 0); - -// @ts-ignore -const grid = new OBC.SimpleGrid(components); - -const boxMaterial = new THREE.MeshStandardMaterial({ color: "#6528D7" }); -const boxGeometry = new THREE.BoxGeometry(3, 3, 3); -const cube = new THREE.Mesh(boxGeometry, boxMaterial); -cube.position.set(0, 1.5, 0); -scene.add(cube); - -/* MD - ### 🎨 Draw in 2D on top of 3D! - ___ - The `Simple2DScene` component is an easy way to represent 2D data - using the same tools and API that you use for 3D. Using it is - super simple: just create a new instance and you can start - adding things to it! - - :::tip Drawing 2D with THREE.js? - - Yes! 2D is just a specific case of 3D. So we can use exactly the same - libraries and tools to display 2D data easily. - - ::: - - The first step is to create a instance of the `Simple2DScene` component: - - */ - -const simple2dScene = new OBC.Simple2DScene(components); - -/* MD - Great! Now we can start adding things to it, just like we would with the - 3D scene. We will create a cube some lights and a grid: 💡🧊 - */ - -const cube2 = new THREE.Mesh(boxGeometry, boxMaterial); -const scene2d = simple2dScene.get(); -scene2d.add(cube2); - -const directionalLight2 = new THREE.DirectionalLight(); -directionalLight2.position.set(5, 10, 3); -directionalLight2.intensity = 0.5; -scene2d.add(directionalLight2); - -const ambientLight2 = new THREE.AmbientLight(); -ambientLight2.intensity = 0.5; -scene2d.add(ambientLight2); - -// window.ondblclick = () => { -// simple2dScene.scaleY += 0.1; -// } - -/* MD - ### 💅 Creating the UI - ___ - The `Simple2DScene` comes with a button to easily turn it on and off. - Let's create a simple toolbar and add it to the scene: - */ - -const mainWindow = new OBC.FloatingWindow(components); -components.ui.add(mainWindow); -mainWindow.visible = false; -mainWindow.domElement.style.height = "20rem"; -mainWindow.addChild(simple2dScene.uiElement.get("container")); - -mainWindow.onResized.add(() => simple2dScene.grid.regenerate()); - -rendererComponent.onAfterUpdate.add(() => { - if (mainWindow.visible) { - simple2dScene.update(); - } -}); - -mainWindow.slots.content.domElement.style.padding = "0"; -mainWindow.slots.content.domElement.style.overflow = "hidden"; - -mainWindow.onResized.add(() => { - const { width, height } = mainWindow.containerSize; - simple2dScene.setSize(height, width); -}); - -mainWindow.domElement.style.width = "20rem"; -mainWindow.domElement.style.height = "20rem"; - -mainWindow.onVisible.add(() => { - if (mainWindow.visible) { - const { width, height } = mainWindow.containerSize; - simple2dScene.setSize(height, width); - simple2dScene.grid.regenerate(); - } -}); - -const mainButton = new OBC.Button(components); -mainButton.materialIcon = "fact_check"; -mainButton.tooltip = "2D scene"; -mainButton.onClick.add(() => { - mainWindow.visible = !mainWindow.visible; -}); - -const mainToolbar = new OBC.Toolbar(components); -components.ui.addToolbar(mainToolbar); -mainToolbar.addChild(mainButton); - -/* MD - That's it! Great work. Now you can easily draw 2D graphics with the same - API and expose them to your end users. 🥳 - */ diff --git a/temp/core/Simple2DScene/index.ts b/temp/core/Simple2DScene/index.ts deleted file mode 100644 index 69d2054a2..000000000 --- a/temp/core/Simple2DScene/index.ts +++ /dev/null @@ -1,213 +0,0 @@ -import * as THREE from "three"; -import CameraControls from "camera-controls"; -import { - Component, - Updateable, - UI, - Disposable, - Event, - UIElement, - Resizeable, -} from "../../base-types"; -import { SimpleUIComponent } from "../../ui"; -import { Components } from "../Components"; -import { Disposer } from "../Disposer"; -import { SimpleRenderer } from "../SimpleRenderer"; -import { PostproductionRenderer } from "../../navigation/PostproductionRenderer"; -import { Infinite2dGrid } from "./src"; - -// TODO: Make a scene manager as a Tool (so that it as an UUID) - -/** - * A simple floating 2D scene that you can use to easily draw 2D graphics - * with all the power of Three.js. - */ -export class Simple2DScene - extends Component - implements UI, Updateable, Disposable, Resizeable -{ - static readonly uuid = "b48b7194-0f9a-43a4-a718-270b1522595f" as const; - - /** {@link Updateable.onAfterUpdate} */ - readonly onAfterUpdate = new Event(); - - /** {@link Updateable.onBeforeUpdate} */ - readonly onBeforeUpdate = new Event(); - - /** {@link Resizeable.onResize} */ - onResize = new Event(); - - /** {@link Component.enabled} */ - enabled = true; - - /** {@link Disposable.onDisposed} */ - readonly onDisposed = new Event(); - - /** {@link UI.uiElement} */ - uiElement = new UIElement<{ - container: SimpleUIComponent; - }>(); - - /** The camera controls that move around in the scene. */ - readonly controls: CameraControls; - - /** The camera that renders the scene. */ - readonly camera: THREE.OrthographicCamera; - - readonly scene: THREE.Scene; - - renderer: SimpleRenderer | PostproductionRenderer; - - grid: Infinite2dGrid; - - private _scaleX = 1; - private _scaleY = 1; - private readonly _root = new THREE.Group(); - private readonly _size = new THREE.Vector2(); - private readonly _frustumSize = 50; - - get size() { - return this._size.clone(); - } - - get scaleX() { - return this._scaleX; - } - - set scaleX(value: number) { - this._scaleX = value; - this._root.scale.x = value; - this.grid.scaleX = value; - this.grid.regenerate(); - } - - get scaleY() { - return this._scaleY; - } - - set scaleY(value: number) { - this._scaleY = value; - this._root.scale.y = value; - this.grid.scaleY = value; - this.grid.regenerate(); - } - - constructor(components: Components, postproduction = false) { - super(components); - - if (!components.uiEnabled) { - throw new Error( - "The Simple2DScene component needs to use UI elements (TODO: Decouple from them)." - ); - } - - const container = new SimpleUIComponent(components); - container.domElement.classList.add("relative"); - this.uiElement.set({ container }); - - this.scene = new THREE.Scene(); - - this._size.set(window.innerWidth, window.innerHeight); - const { width, height } = this._size; - - // Creates the camera (point of view of the user) - const aspect = width / height; - const halfSize = this._frustumSize * 0.5; - - this.camera = new THREE.OrthographicCamera( - -halfSize * aspect, - halfSize * aspect, - halfSize, - -halfSize, - -1000, - 1000 - ); - - this.scene.add(this.camera); - this.camera.position.z = 10; - - const domContainer = container.domElement; - - this.scene.add(this._root); - - this.grid = new Infinite2dGrid(this.camera, domContainer); - const gridObject = this.grid.get(); - this.scene.add(gridObject); - - if (postproduction) { - this.renderer = new PostproductionRenderer(this.components, domContainer); - } else { - this.renderer = new SimpleRenderer(this.components, domContainer); - } - - const renderer = this.renderer.get(); - renderer.localClippingEnabled = false; - this.renderer.setupEvents(false); - this.renderer.overrideScene = this.scene; - this.renderer.overrideCamera = this.camera; - - this.controls = new CameraControls(this.camera, renderer.domElement); - // this.controls.smoothTime = 0.6; - this.controls.setTarget(0, 0, 0); - this.controls.addEventListener("update", () => this.grid.regenerate()); - this.controls.mouseButtons.left = CameraControls.ACTION.TRUCK; - this.controls.dollyToCursor = true; - this.controls.restThreshold = 2; - this.controls.smoothTime = 0.2; - } - - /** - * {@link Component.get} - * @returns the 2D scene. - */ - get() { - return this._root; - } - - /** {@link Disposable.dispose} */ - async dispose() { - const disposer = this.components.tools.get(Disposer); - for (const child of this.scene.children) { - const item = child as any; - if (item instanceof THREE.Object3D) { - disposer.destroy(item); - } - } - await this.renderer.dispose(); - await this.uiElement.dispose(); - await this.onDisposed.trigger(Simple2DScene.uuid); - this.onDisposed.reset(); - } - - /** {@link Updateable.update} */ - async update() { - await this.onBeforeUpdate.trigger(); - this.controls.update(1 / 60); - await this.renderer.update(); - await this.onAfterUpdate.trigger(); - } - - /** {@link Resizeable.getSize} */ - getSize() { - return new THREE.Vector2(this._size.width, this._size.height); - } - - setSize(height: number, width: number) { - this._size.width = width; - this._size.height = height; - this.resize(); - } - - /** {@link Resizeable.resize} */ - resize = () => { - const { height, width } = this._size; - const aspect = width / height; - this.camera.left = (-this._frustumSize * aspect) / 2; - this.camera.right = (this._frustumSize * aspect) / 2; - this.camera.top = this._frustumSize / 2; - this.camera.bottom = -this._frustumSize / 2; - this.camera.updateProjectionMatrix(); - this.camera.updateProjectionMatrix(); - this.renderer.resize(this._size); - }; -} diff --git a/temp/core/Simple2DScene/src/index.ts b/temp/core/Simple2DScene/src/index.ts deleted file mode 100644 index abd579b08..000000000 --- a/temp/core/Simple2DScene/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./infinite-2d-grid"; diff --git a/temp/core/Simple2DScene/src/infinite-2d-grid.ts b/temp/core/Simple2DScene/src/infinite-2d-grid.ts deleted file mode 100644 index 7a7c02e67..000000000 --- a/temp/core/Simple2DScene/src/infinite-2d-grid.ts +++ /dev/null @@ -1,220 +0,0 @@ -import * as THREE from "three"; -import { CSS2DObject } from "three/examples/jsm/renderers/CSS2DRenderer.js"; - -/** - * An infinite lightweight 2D grid that can be used for any - * kind of 2d viewports. - */ -export class Infinite2dGrid { - grids: { - main: THREE.LineSegments; - secondary: THREE.LineSegments; - }; - - numbers = new THREE.Group(); - - maxRegenerateRetrys = 4; - - gridsFactor = 5; - - scaleX = 1; - scaleY = 1; - - private _group = new THREE.Group(); - private _frustum = new THREE.Frustum(); - private _frustumMat = new THREE.Matrix4(); - private _camera: THREE.Camera; - private _container: HTMLElement; - - private _regenerateDelay = 200; - private _regenerateCounter = 0; - - constructor(camera: THREE.Camera, container: HTMLElement) { - this._camera = camera; - this._container = container; - - const main = this.newGrid(0x222222, -1); - const secondary = this.newGrid(0x111111, -2); - this.grids = { main, secondary }; - - this._group.add(secondary, main, this.numbers); - } - - get() { - return this._group; - } - - dispose() { - const { main, secondary } = this.grids; - main.removeFromParent(); - secondary.removeFromParent(); - main.geometry.dispose(); - const mMat = main.material as THREE.LineBasicMaterial; - mMat.dispose(); - secondary.geometry.dispose(); - const sMat = secondary.material as THREE.LineBasicMaterial; - sMat.dispose(); - } - - regenerate() { - const isReady = this.isGridReady(); - if (!isReady) { - this._regenerateCounter++; - if (this._regenerateCounter > this.maxRegenerateRetrys) { - throw new Error("Grid could not be regenerated"); - } - setTimeout(() => this.regenerate, this._regenerateDelay); - return; - } - this._regenerateCounter = 0; - - const matrix = this._frustumMat.multiplyMatrices( - this._camera.projectionMatrix, - this._camera.matrixWorldInverse, - ); - this._frustum.setFromProjectionMatrix(matrix); - - // Step 1: find out the distance of the visible area of the 2D scene - // and the translation pixel / 3d unit - - const { planes } = this._frustum; - const right = planes[0].constant * -planes[0].normal.x; - const left = planes[1].constant * -planes[1].normal.x; - const bottom = planes[2].constant * -planes[2].normal.y; - const top = planes[3].constant * -planes[3].normal.y; - const horizontalDistance = Math.abs(right - left); - const verticalDistance = Math.abs(top - bottom); - - const { clientWidth, clientHeight } = this._container; - const maxPixelDist = Math.max(clientWidth, clientHeight); - const maxUnit3dDist = Math.max(horizontalDistance, verticalDistance); - const unit3dPixelRel = maxUnit3dDist / maxPixelDist; - - // Step 2: find out its order of magnitude - - const magnitudeX = Math.ceil(Math.log10(horizontalDistance / this.scaleX)); - const magnitudeY = Math.ceil(Math.log10(verticalDistance / this.scaleY)); - - // Step 3: represent main grid - const sDistanceHor = 10 ** (magnitudeX - 2) * this.scaleX; - const sDistanceVert = 10 ** (magnitudeY - 2) * this.scaleY; - const mDistanceHor = sDistanceHor * this.gridsFactor; - const mDistanceVert = sDistanceVert * this.gridsFactor; - - const mainGridCountVert = Math.ceil(verticalDistance / mDistanceVert); - const mainGridCountHor = Math.ceil(horizontalDistance / mDistanceHor); - const secondaryGridCountVert = Math.ceil(verticalDistance / sDistanceVert); - const secondaryGridCountHor = Math.ceil(horizontalDistance / sDistanceHor); - - // Step 4: find out position of first lines - const sTrueLeft = sDistanceHor * Math.ceil(left / sDistanceHor); - const sTrueBottom = sDistanceVert * Math.ceil(bottom / sDistanceVert); - const mTrueLeft = mDistanceHor * Math.ceil(left / mDistanceHor); - const mTrueBottom = mDistanceVert * Math.ceil(bottom / mDistanceVert); - - // Step 5: draw lines and texts - const numbers = [...this.numbers.children]; - for (const number of numbers) { - number.removeFromParent(); - } - this.numbers.children = []; - - const mPoints = []; - - const realWidthPerCharacter = 9 * unit3dPixelRel; // 9 pixels per char - - const p = 10000; - - // Avoid horizontal text overlap by computing the real width of a text - // and computing which lines should have a label starting from zero - const minLabel = Math.round(Math.abs(mTrueLeft / this.scaleX) * p) / p; - const maxDist = (mainGridCountHor - 1) * mDistanceHor; - const maxLabel = - Math.round(Math.abs((mTrueLeft + maxDist) / this.scaleX) * p) / p; - const biggestLabelLength = Math.max(minLabel, maxLabel).toString().length; - const biggestLabelSize = biggestLabelLength * realWidthPerCharacter; - const cellsOccupiedByALabel = Math.ceil(biggestLabelSize / mDistanceHor); - let offsetToZero = cellsOccupiedByALabel * mDistanceHor; - - for (let i = 0; i < mainGridCountHor; i++) { - let offset = mTrueLeft + i * mDistanceHor; - mPoints.push(offset, top, 0, offset, bottom, 0); - - const value = offset / this.scaleX; - - offset = Math.round(offset * p) / p; - offsetToZero = Math.round(offsetToZero * p) / p; - const result = offset % offsetToZero; - - // TODO: Removing horizontal labels for clarity doesn't work for small distances - const isSmall = mDistanceHor < 1 || mDistanceVert < 1; - - if (!isSmall && Math.abs(result) > 0.01) { - continue; - } - - const sign = this.newNumber(value); - const textOffsetPixels = 12; - const textOffset = textOffsetPixels * unit3dPixelRel; - sign.position.set(offset, bottom + textOffset, 0); - } - for (let i = 0; i < mainGridCountVert; i++) { - const offset = mTrueBottom + i * mDistanceVert; - mPoints.push(left, offset, 0, right, offset, 0); - const sign = this.newNumber(offset / this.scaleY); - let textOffsetPixels = 12; - if (sign.element.textContent) { - textOffsetPixels += 4 * sign.element.textContent.length; - } - const textOffset = textOffsetPixels * unit3dPixelRel; - sign.position.set(left + textOffset, offset, 0); - } - - const sPoints = []; - for (let i = 0; i < secondaryGridCountHor; i++) { - const offset = sTrueLeft + i * sDistanceHor; - sPoints.push(offset, top, 0, offset, bottom, 0); - } - for (let i = 0; i < secondaryGridCountVert; i++) { - const offset = sTrueBottom + i * sDistanceVert; - sPoints.push(left, offset, 0, right, offset, 0); - } - - const mBuffer = new THREE.BufferAttribute(new Float32Array(mPoints), 3); - const sBuffer = new THREE.BufferAttribute(new Float32Array(sPoints), 3); - const { main, secondary } = this.grids; - main.geometry.setAttribute("position", mBuffer); - secondary.geometry.setAttribute("position", sBuffer); - } - - private newNumber(offset: number) { - const text = document.createElement("div"); - const formattedNumber = Math.round(offset * 100) / 100; - text.textContent = `${formattedNumber}`; - text.style.height = "24px"; - text.style.fontSize = "12px"; - const sign = new CSS2DObject(text); - this.numbers.add(sign); - return sign; - } - - private newGrid(color: number, renderOrder: number) { - const geometry = new THREE.BufferGeometry(); - const material = new THREE.LineBasicMaterial({ color }); - const grid = new THREE.LineSegments(geometry, material); - grid.frustumCulled = false; - grid.renderOrder = renderOrder; - return grid; - } - - private isGridReady() { - const nums = this._camera.projectionMatrix.elements; - for (let i = 0; i < nums.length; i++) { - const num = nums[i]; - if (Number.isNaN(num)) { - return false; - } - } - return true; - } -} diff --git a/temp/core/index.ts b/temp/core/index.ts deleted file mode 100644 index 98ed0cf18..000000000 --- a/temp/core/index.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { MeshBVH, acceleratedRaycast, computeBoundsTree, disposeBoundsTree } from "three-mesh-bvh"; - -// TODO: Find a better place to put this. -declare module 'three' { - export interface BufferGeometry { - boundsTree?: MeshBVH; - computeBoundsTree: typeof computeBoundsTree; - disposeBoundsTree: typeof disposeBoundsTree; - } - - export interface Mesh { - raycast: typeof acceleratedRaycast; - } -} - -export * from "./Disposer"; -export * from "./SimpleScene"; -export * from "./ToolsComponent"; -export * from "./SimpleRenderer"; -export * from "./SimpleCamera"; -export * from "./SimpleRaycaster"; -export * from "./SimpleGrid"; -export * from "./Components"; -export * from "./SimpleClipper"; -export * from "./ScreenCuller"; -export * from "./SimpleSVGViewport"; -export * from "./Simple2DMarker"; -export * from "./MaterialManager"; -export * from "./Simple2DScene"; diff --git a/temp/navigation/ViewpointsManager/index.ts b/temp/navigation/ViewpointsManager/index.ts deleted file mode 100644 index 2f805b7a0..000000000 --- a/temp/navigation/ViewpointsManager/index.ts +++ /dev/null @@ -1,241 +0,0 @@ -import { Vector3 } from "three"; -import { generateUUID } from "three/src/math/MathUtils.js"; -import { LengthMeasurement, SimpleDimensionLine } from "../../measurement"; -import { Components } from "../../core/Components"; -import { - UI, - Component, - Event, - FragmentIdMap, - UIElement, -} from "../../base-types"; -import { Button, SimpleUICard, FloatingWindow } from "../../ui"; - -import { DrawManager } from "../../annotation"; -import { OrthoPerspectiveCamera } from "../OrthoPerspectiveCamera"; -import { CameraProjection } from "../OrthoPerspectiveCamera/src/types"; -import { FragmentHighlighter } from "../../fragments"; - -// TODO: Update and implement memory disposal - -export interface IViewpointsManagerConfig { - selectionHighlighter: string; - drawManager?: DrawManager; -} - -export interface IViewpoint { - guid: string; - title: string; - description: string | null; - position: Vector3; - target: Vector3; - selection: FragmentIdMap; - projection: CameraProjection; - dimensions: { start: Vector3; end: Vector3 }[]; - filter?: { [groupSystem: string]: string }; - annotations?: SVGGElement; -} - -export class ViewpointsManager extends Component implements UI { - // private _fragmentManager: FragmentManager; - // private _fragmentGrouper: FragmentGrouper; - private _drawManager?: DrawManager; - name: string = "ViewpointsManager"; - - uiElement = new UIElement<{ - main: Button; - newButton: Button; - window: FloatingWindow; - }>(); - - enabled: boolean = true; - list: IViewpoint[] = []; - selectionHighlighter = ""; - readonly onViewpointViewed = new Event(); - readonly onViewpointAdded = new Event(); - - constructor(components: Components) { - super(components); - this.components = components; - } - - initialize(config: IViewpointsManagerConfig) { - this.selectionHighlighter = config.selectionHighlighter; - // this._fragmentGrouper = config.fragmentGrouper; - // this._fragmentManager = config.fragmentManager; - this._drawManager = config.drawManager; - if (this.components.uiEnabled) { - this.setUI(); - } - } - - private setUI() { - const viewerContainer = this.components.renderer.get().domElement - .parentElement as HTMLElement; - const window = new FloatingWindow(this.components); - window.title = "Viewpoints"; - viewerContainer.append(window.get()); - window.visible = false; - const main = new Button(this.components, { - materialIconName: "photo_camera", - }); - const newButton = new Button(this.components, { - materialIconName: "add", - name: "New viewpoint", - }); - const listButton = new Button(this.components, { - materialIconName: "format_list_bulleted", - name: "Viewpoints list", - }); - listButton.onClick.add(() => { - window.visible = !window.visible; - }); - main.addChild(listButton, newButton); - this.uiElement.set({ main, newButton, window }); - } - - get(): string { - throw new Error("Method not implemented."); - } - - add(data: { title: string; description: string | null }) { - const { title, description } = data; - if (!title) { - return undefined; - } - - const guid = generateUUID().toLowerCase(); - - // #region Store dimensions - const dimensions: { start: Vector3; end: Vector3 }[] = []; - const dimensionsComp = this.components.tools.get(LengthMeasurement); - const allDimensions = dimensionsComp.get(); - for (const dimension of allDimensions) { - dimensions.push({ start: dimension.startPoint, end: dimension.endPoint }); - } - // #endregion - - // #redgion Store selection - const highlighter = this.components.tools.get(FragmentHighlighter); - const selection = highlighter.selection[this.selectionHighlighter]; - // #endregion - - // #region Store filter (WIP) - // const filter = {entities: "IFCBEAM", storeys: "N07"} - // #endregion - - // #region Store camera position and target - const camera = this.components.camera as OrthoPerspectiveCamera; - const controls = camera.controls; - const target = new Vector3(); - const position = new Vector3(); - controls.getTarget(target); - controls.getPosition(position); - const projection = camera.getProjection(); - // #endregion - - // #region Store annotations - const annotations = this._drawManager?.saveDrawing(guid); - // #endregion - - const viewpoint: IViewpoint = { - guid, - title, - target, - position, - selection, - // filter, - description, - dimensions, - annotations, - projection, - }; - - // #region UI representation - const card = new SimpleUICard(this.components, viewpoint.guid); - card.title = title; - card.description = description; - card.domElement.onclick = () => this.view(viewpoint.guid); - this.uiElement.get("window").addChild(card); - // #endregion - - this.list.push(viewpoint); - this.onViewpointAdded.trigger(guid); - return viewpoint; - } - - retrieve(guid: string) { - return this.list.find((v) => v.guid === guid); - } - - async view(guid: string) { - const viewpoint = this.retrieve(guid); - if (!viewpoint) { - return; - } - - // #region Recover annotations - if (this._drawManager && viewpoint.annotations) { - this._drawManager.viewport.clear(); - this._drawManager.enabled = true; - this._drawManager.viewport.get().append(viewpoint.annotations); - } - // #endregion - - // #region Recover dimensions - const dimensionsComponent = this.components.tools.get(LengthMeasurement); - - viewpoint.dimensions.forEach((data) => { - const dimension = new SimpleDimensionLine(this.components, { - start: data.start, - end: data.end, - // @ts-ignore - lineMaterial: dimensionsComponent._lineMaterial, - // @ts-ignore - endpoint: dimensionsComponent._endpointMesh, - }); - dimension.createBoundingBox(); - // @ts-ignore - dimensionsComponent._dimensions.push(dimension); - }); - // #endregion - - // #region Recover filtered elements - // if (viewpoint.filter) { - // const filterData = fragments.groups.get(viewpoint.filter) - // for (const fragmentID in fragments.list) { - // const fragment = fragments.list[fragmentID] - // fragment.setVisibility(fragment.items, false) - // } - // for (const fragmentID in filterData) { - // const ids = filterData[fragmentID] - // fragments.list[fragmentID]?.setVisibility(ids, true) - // } - // } - // #endregion - - // Select elements in the viewpoint - const selection: FragmentIdMap = {}; - for (const fragmentID in viewpoint.selection) { - selection[fragmentID] = viewpoint.selection[fragmentID]; - } - - const highlighter = this.components.tools.get(FragmentHighlighter); - await highlighter.highlightByID(this.selectionHighlighter, selection, true); - - // #region Recover camera position & target - const camera = this.components.camera as OrthoPerspectiveCamera; - const controls = camera.controls; - controls.setLookAt( - viewpoint.position.x, - viewpoint.position.y, - viewpoint.position.z, - viewpoint.target.x, - viewpoint.target.y, - viewpoint.target.z, - true - ); - await this.onViewpointViewed.trigger(guid); - // #endregion - } -} diff --git a/yarn.lock b/yarn.lock index 567bc8a38..7dae91a7c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1251,8 +1251,10 @@ __metadata: dependencies: "@thatopen/components": 1.5.0 "@types/three": ^0.160.0 + camera-controls: 2.7.3 three: ^0.160.1 peerDependencies: + bim-fragment: 1.5.0 three: ^0.160.1 languageName: unknown linkType: soft