@thatopen/components 2.2.7 → 2.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ export declare class Components implements Disposable {
6
6
  /**
7
7
  * The version of the @thatopen/components library.
8
8
  */
9
- static readonly release = "2.2.7";
9
+ static readonly release = "2.2.8";
10
10
  /** {@link Disposable.onDisposed} */
11
11
  readonly onDisposed: Event<void>;
12
12
  /**
package/dist/index.cjs CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  - If you're the tool creator, you can take one from https://www.uuidgenerator.net/.
4
4
 
5
- - If you're using a platform tool, verify the uuid isn't misspelled or contact the tool creator.`)}};T(Ot,"_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}$/),T(Ot,"_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 re=Ot;class wa extends Ft{constructor(t,e){super(t);T(this,"onDisposed",new Q);T(this,"onVertexFound",new Q);T(this,"onVertexLost",new Q);T(this,"onEnabled",new Q);T(this,"components");T(this,"workingPlane",null);T(this,"_pickedPoint",null);T(this,"_config");T(this,"_enabled",!1);this.components=t,this.config={snapDistance:.25,showOnlyVertex:!1,...e},this.enabled=!1}set enabled(t){this._enabled=t,t||(this._pickedPoint=null),this.onEnabled.trigger(t)}get enabled(){return this._enabled}set config(t){this._config={...this._config,...t}}get config(){return this._config}dispose(){this.onVertexFound.reset(),this.onVertexLost.reset(),this.components=null,this.onDisposed.trigger(),this.onDisposed.reset()}get(t){if(!this.enabled)return this._pickedPoint;const n=this.components.get(Ne).get(t).castRay();if(!n)return this._pickedPoint!==null&&(this.onVertexLost.trigger(),this._pickedPoint=null),this._pickedPoint;const r=this.getClosestVertex(n);return r?(this.workingPlane?Math.abs(this.workingPlane.distanceToPoint(r))<.001:!0)?((this._pickedPoint===null||!this._pickedPoint.equals(r))&&(this._pickedPoint=r.clone(),this.onVertexFound.trigger(this._pickedPoint)),this._pickedPoint):(this._pickedPoint=null,this._pickedPoint):(this._pickedPoint!==null&&(this.onVertexLost.trigger(),this._pickedPoint=null),this._pickedPoint)}getClosestVertex(t){let e=new x.Vector3,i=!1,n=Number.MAX_SAFE_INTEGER;const r=this.getVertices(t);if(r===null)return null;for(const o of r){if(!o)continue;const a=t.point.distanceTo(o);a>n||a>this._config.snapDistance||(i=!0,e=o,n=t.point.distanceTo(o))}return i?e:this.config.showOnlyVertex?null:t.point}getVertices(t){const e=t.object;if(!t.face||!e)return null;const i=e.geometry,n=new x.Matrix4,{instanceId:r}=t,o=r!==void 0,a=e instanceof x.InstancedMesh;return a&&o&&e.getMatrixAt(r,n),[this.getVertex(t.face.a,i),this.getVertex(t.face.b,i),this.getVertex(t.face.c,i)].map(l=>(l&&(a&&o&&l.applyMatrix4(n),l.applyMatrix4(e.matrixWorld)),l))}getVertex(t,e){if(t===void 0)return null;const i=e.attributes.position;return new x.Vector3(i.getX(t),i.getY(t),i.getZ(t))}}const li=class li{constructor(){T(this,"onDisposed",new Q);T(this,"list",new Map);T(this,"enabled",!1);T(this,"_clock");T(this,"update",()=>{if(!this.enabled)return;const s=this._clock.getDelta();for(const[t,e]of this.list)e.enabled&&e.isUpdateable()&&e.update(s);requestAnimationFrame(this.update)});this._clock=new x.Clock,li.setupBVH()}add(s,t){if(this.list.has(s))throw new Error("You're trying to add a component that already exists in the components instance. Use Components.get() instead.");re.validate(s),this.list.set(s,t)}get(s){const t=s.uuid;if(!this.list.has(t)){const e=new s(this);return this.list.has(t)||this.add(t,e),e}return this.list.get(t)}init(){this.enabled=!0,this._clock.start(),this.update()}dispose(){this.enabled=!1;for(const[s,t]of this.list)t.enabled=!1,t.isDisposeable()&&t.dispose();this._clock.stop(),this.onDisposed.trigger(),this.onDisposed.reset()}static setupBVH(){x.BufferGeometry.prototype.computeBoundsTree=ma,x.BufferGeometry.prototype.disposeBoundsTree=Ia,x.Mesh.prototype.raycast=Ea}};T(li,"release","2.2.7");let Js=li;class Sr extends yi{constructor(){super(...arguments);T(this,"meshes",new Set);T(this,"onAfterUpdate",new Q);T(this,"onBeforeUpdate",new Q);T(this,"onDisposed",new Q);T(this,"isDisposing",!1);T(this,"enabled",!0);T(this,"uuid",re.create());T(this,"name");T(this,"_scene");T(this,"_camera");T(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.isDisposing=!0,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(le);this.scene.dispose(),this.camera.isDisposeable()&&this.camera.dispose(),this.renderer&&this.renderer.dispose();for(const i of this.meshes)e.destroy(i);this.meshes.clear()}this._scene=null,this._camera=null,this._renderer=null,this.onDisposed.trigger()}}class Or extends yr{constructor(t){super(t);T(this,"isSetup",!1);T(this,"three");T(this,"onSetup",new Q);T(this,"config",{directionalLight:{color:new x.Color("white"),intensity:1.5,position:new x.Vector3(5,10,3)},ambientLight:{color:new x.Color("white"),intensity:1}});this.three=new x.Scene,this.three.background=new x.Color(2107698)}setup(t){this.config={...this.config,...t};const e=new x.DirectionalLight(this.config.directionalLight.color,this.config.directionalLight.intensity);e.position.copy(this.config.directionalLight.position);const i=new x.AmbientLight(this.config.ambientLight.color,this.config.ambientLight.intensity);this.three.add(e,i),this.directionalLights.set(e.uuid,e),this.ambientLights.set(i.uuid,i),this.isSetup=!0,this.onSetup.trigger(this)}}class Sa extends Rr{constructor(t,e,i){super(t);T(this,"enabled",!0);T(this,"container");T(this,"three");T(this,"_canvas");T(this,"_parameters");T(this,"_resizeObserver",null);T(this,"onContainerUpdated",new Q);T(this,"_resizing",!1);T(this,"resize",t=>{if(this._resizing)return;this._resizing=!0,this.onContainerUpdated.trigger();const e=t?t.x:this.container.clientWidth,i=t?t.y:this.container.clientHeight;this.three.setSize(e,i),this.onResize.trigger(new x.Vector2(e,i)),this._resizing=!1});T(this,"resizeEvent",()=>{this.resize()});T(this,"onContextLost",t=>{t.preventDefault(),this.enabled=!1});T(this,"onContextBack",()=>{this.three.setRenderTarget(null),this.three.dispose(),this.three=new x.WebGLRenderer({canvas:this._canvas,antialias:!0,alpha:!0,...this._parameters}),this.enabled=!0});this.container=e,this._parameters=i,this.three=new x.WebGLRenderer({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 n=this.three.getContext(),{canvas:r}=n;r.addEventListener("webglcontextlost",this.onContextLost,!1),r.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.forceContextLoss(),this.three.dispose(),this.onResize.reset(),this.onAfterUpdate.reset(),this.onBeforeUpdate.reset(),this.onDisposed.trigger(),this.onDisposed.reset()}getSize(){return new x.Vector2(this.three.domElement.clientWidth,this.three.domElement.clientHeight)}setupEvents(t){const e=this.three.domElement.parentElement;if(!e)throw new Error("This renderer needs to have an HTML container!");this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),window.removeEventListener("resize",this.resizeEvent),t&&(this._resizeObserver=new ResizeObserver(this.resizeEvent),this._resizeObserver.observe(e),window.addEventListener("resize",this.resizeEvent))}setupRenderer(){this.three.localClippingEnabled=!0,this.container&&this.container.appendChild(this.three.domElement),this.onContainerUpdated.trigger()}}/*!
5
+ - If you're using a platform tool, verify the uuid isn't misspelled or contact the tool creator.`)}};T(Ot,"_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}$/),T(Ot,"_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 re=Ot;class wa extends Ft{constructor(t,e){super(t);T(this,"onDisposed",new Q);T(this,"onVertexFound",new Q);T(this,"onVertexLost",new Q);T(this,"onEnabled",new Q);T(this,"components");T(this,"workingPlane",null);T(this,"_pickedPoint",null);T(this,"_config");T(this,"_enabled",!1);this.components=t,this.config={snapDistance:.25,showOnlyVertex:!1,...e},this.enabled=!1}set enabled(t){this._enabled=t,t||(this._pickedPoint=null),this.onEnabled.trigger(t)}get enabled(){return this._enabled}set config(t){this._config={...this._config,...t}}get config(){return this._config}dispose(){this.onVertexFound.reset(),this.onVertexLost.reset(),this.components=null,this.onDisposed.trigger(),this.onDisposed.reset()}get(t){if(!this.enabled)return this._pickedPoint;const n=this.components.get(Ne).get(t).castRay();if(!n)return this._pickedPoint!==null&&(this.onVertexLost.trigger(),this._pickedPoint=null),this._pickedPoint;const r=this.getClosestVertex(n);return r?(this.workingPlane?Math.abs(this.workingPlane.distanceToPoint(r))<.001:!0)?((this._pickedPoint===null||!this._pickedPoint.equals(r))&&(this._pickedPoint=r.clone(),this.onVertexFound.trigger(this._pickedPoint)),this._pickedPoint):(this._pickedPoint=null,this._pickedPoint):(this._pickedPoint!==null&&(this.onVertexLost.trigger(),this._pickedPoint=null),this._pickedPoint)}getClosestVertex(t){let e=new x.Vector3,i=!1,n=Number.MAX_SAFE_INTEGER;const r=this.getVertices(t);if(r===null)return null;for(const o of r){if(!o)continue;const a=t.point.distanceTo(o);a>n||a>this._config.snapDistance||(i=!0,e=o,n=t.point.distanceTo(o))}return i?e:this.config.showOnlyVertex?null:t.point}getVertices(t){const e=t.object;if(!t.face||!e)return null;const i=e.geometry,n=new x.Matrix4,{instanceId:r}=t,o=r!==void 0,a=e instanceof x.InstancedMesh;return a&&o&&e.getMatrixAt(r,n),[this.getVertex(t.face.a,i),this.getVertex(t.face.b,i),this.getVertex(t.face.c,i)].map(l=>(l&&(a&&o&&l.applyMatrix4(n),l.applyMatrix4(e.matrixWorld)),l))}getVertex(t,e){if(t===void 0)return null;const i=e.attributes.position;return new x.Vector3(i.getX(t),i.getY(t),i.getZ(t))}}const li=class li{constructor(){T(this,"onDisposed",new Q);T(this,"list",new Map);T(this,"enabled",!1);T(this,"_clock");T(this,"update",()=>{if(!this.enabled)return;const s=this._clock.getDelta();for(const[t,e]of this.list)e.enabled&&e.isUpdateable()&&e.update(s);requestAnimationFrame(this.update)});this._clock=new x.Clock,li.setupBVH()}add(s,t){if(this.list.has(s))throw new Error("You're trying to add a component that already exists in the components instance. Use Components.get() instead.");re.validate(s),this.list.set(s,t)}get(s){const t=s.uuid;if(!this.list.has(t)){const e=new s(this);return this.list.has(t)||this.add(t,e),e}return this.list.get(t)}init(){this.enabled=!0,this._clock.start(),this.update()}dispose(){this.enabled=!1;for(const[s,t]of this.list)t.enabled=!1,t.isDisposeable()&&t.dispose();this._clock.stop(),this.onDisposed.trigger(),this.onDisposed.reset()}static setupBVH(){x.BufferGeometry.prototype.computeBoundsTree=ma,x.BufferGeometry.prototype.disposeBoundsTree=Ia,x.Mesh.prototype.raycast=Ea}};T(li,"release","2.2.8");let Js=li;class Sr extends yi{constructor(){super(...arguments);T(this,"meshes",new Set);T(this,"onAfterUpdate",new Q);T(this,"onBeforeUpdate",new Q);T(this,"onDisposed",new Q);T(this,"isDisposing",!1);T(this,"enabled",!0);T(this,"uuid",re.create());T(this,"name");T(this,"_scene");T(this,"_camera");T(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.isDisposing=!0,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(le);this.scene.dispose(),this.camera.isDisposeable()&&this.camera.dispose(),this.renderer&&this.renderer.dispose();for(const i of this.meshes)e.destroy(i);this.meshes.clear()}this._scene=null,this._camera=null,this._renderer=null,this.onDisposed.trigger()}}class Or extends yr{constructor(t){super(t);T(this,"isSetup",!1);T(this,"three");T(this,"onSetup",new Q);T(this,"config",{directionalLight:{color:new x.Color("white"),intensity:1.5,position:new x.Vector3(5,10,3)},ambientLight:{color:new x.Color("white"),intensity:1}});this.three=new x.Scene,this.three.background=new x.Color(2107698)}setup(t){this.config={...this.config,...t};const e=new x.DirectionalLight(this.config.directionalLight.color,this.config.directionalLight.intensity);e.position.copy(this.config.directionalLight.position);const i=new x.AmbientLight(this.config.ambientLight.color,this.config.ambientLight.intensity);this.three.add(e,i),this.directionalLights.set(e.uuid,e),this.ambientLights.set(i.uuid,i),this.isSetup=!0,this.onSetup.trigger(this)}}class Sa extends Rr{constructor(t,e,i){super(t);T(this,"enabled",!0);T(this,"container");T(this,"three");T(this,"_canvas");T(this,"_parameters");T(this,"_resizeObserver",null);T(this,"onContainerUpdated",new Q);T(this,"_resizing",!1);T(this,"resize",t=>{if(this._resizing)return;this._resizing=!0,this.onContainerUpdated.trigger();const e=t?t.x:this.container.clientWidth,i=t?t.y:this.container.clientHeight;this.three.setSize(e,i),this.onResize.trigger(new x.Vector2(e,i)),this._resizing=!1});T(this,"resizeEvent",()=>{this.resize()});T(this,"onContextLost",t=>{t.preventDefault(),this.enabled=!1});T(this,"onContextBack",()=>{this.three.setRenderTarget(null),this.three.dispose(),this.three=new x.WebGLRenderer({canvas:this._canvas,antialias:!0,alpha:!0,...this._parameters}),this.enabled=!0});this.container=e,this._parameters=i,this.three=new x.WebGLRenderer({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 n=this.three.getContext(),{canvas:r}=n;r.addEventListener("webglcontextlost",this.onContextLost,!1),r.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.forceContextLoss(),this.three.dispose(),this.onResize.reset(),this.onAfterUpdate.reset(),this.onBeforeUpdate.reset(),this.onDisposed.trigger(),this.onDisposed.reset()}getSize(){return new x.Vector2(this.three.domElement.clientWidth,this.three.domElement.clientHeight)}setupEvents(t){const e=this.three.domElement.parentElement;if(!e)throw new Error("This renderer needs to have an HTML container!");this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),window.removeEventListener("resize",this.resizeEvent),t&&(this._resizeObserver=new ResizeObserver(this.resizeEvent),this._resizeObserver.observe(e),window.addEventListener("resize",this.resizeEvent))}setupRenderer(){this.three.localClippingEnabled=!0,this.container&&this.container.appendChild(this.three.domElement),this.onContainerUpdated.trigger()}}/*!
6
6
  * camera-controls
7
7
  * https://github.com/yomotsu/camera-controls
8
8
  * (c) 2017 @yomotsu
9
9
  * Released under the MIT License.
10
- */const lt={LEFT:1,RIGHT:2,MIDDLE:4},H=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}),Ve={NONE:0,IN:1,OUT:-1};function _e(c){return c.isPerspectiveCamera}function fe(c){return c.isOrthographicCamera}const ke=Math.PI*2,Qn=Math.PI/2,Nr=1e-5,is=Math.PI/180;function jt(c,s,t){return Math.max(s,Math.min(t,c))}function Tt(c,s=Nr){return Math.abs(c)<s}function Et(c,s,t=Nr){return Tt(c-s,t)}function qn(c,s){return Math.round(c/s)*s}function ns(c){return isFinite(c)?c:c<0?-Number.MAX_VALUE:Number.MAX_VALUE}function rs(c){return Math.abs(c)<Number.MAX_VALUE?c:c*(1/0)}function Vs(c,s,t,e,i=1/0,n){e=Math.max(1e-4,e);const r=2/e,o=r*n,a=1/(1+o+.48*o*o+.235*o*o*o);let l=c-s;const h=s,d=i*e;l=jt(l,-d,d),s=c-l;const u=(t.value+r*l)*n;t.value=(t.value-r*u)*a;let f=s+(l+u)*a;return h-c>0==f>h&&(f=h,t.value=(f-h)/n),f}function Kn(c,s,t,e,i=1/0,n,r){e=Math.max(1e-4,e);const o=2/e,a=o*n,l=1/(1+a+.48*a*a+.235*a*a*a);let h=s.x,d=s.y,u=s.z,f=c.x-h,E=c.y-d,p=c.z-u;const I=h,m=d,C=u,R=i*e,g=R*R,y=f*f+E*E+p*p;if(y>g){const D=Math.sqrt(y);f=f/D*R,E=E/D*R,p=p/D*R}h=c.x-f,d=c.y-E,u=c.z-p;const w=(t.x+o*f)*n,O=(t.y+o*E)*n,M=(t.z+o*p)*n;t.x=(t.x-o*w)*l,t.y=(t.y-o*O)*l,t.z=(t.z-o*M)*l,r.x=h+(f+w)*l,r.y=d+(E+O)*l,r.z=u+(p+M)*l;const b=I-c.x,v=m-c.y,k=C-c.z,F=r.x-I,L=r.y-m,_=r.z-C;return b*F+v*L+k*_>0&&(r.x=I,r.y=m,r.z=C,t.x=(r.x-I)/n,t.y=(r.y-m)/n,t.z=(r.z-C)/n),r}function Yi(c,s){s.set(0,0),c.forEach(t=>{s.x+=t.clientX,s.y+=t.clientY}),s.x/=c.length,s.y/=c.length}function Hi(c,s){return fe(c)?(console.warn(`${s} is not supported in OrthographicCamera`),!0):!1}class Oa{constructor(){this._listeners={}}addEventListener(s,t){const e=this._listeners;e[s]===void 0&&(e[s]=[]),e[s].indexOf(t)===-1&&e[s].push(t)}hasEventListener(s,t){const e=this._listeners;return e[s]!==void 0&&e[s].indexOf(t)!==-1}removeEventListener(s,t){const i=this._listeners[s];if(i!==void 0){const n=i.indexOf(t);n!==-1&&i.splice(n,1)}}removeAllEventListeners(s){if(!s){this._listeners={};return}Array.isArray(this._listeners[s])&&(this._listeners[s].length=0)}dispatchEvent(s){const e=this._listeners[s.type];if(e!==void 0){s.target=this;const i=e.slice(0);for(let n=0,r=i.length;n<r;n++)i[n].call(this,s)}}}const Na="2.7.3",ks=1/8,br=typeof window<"u",ba=br&&/Mac/.test(navigator.platform),Pa=!(br&&"PointerEvent"in window);let ct,Jn,Gs,Wi,Ut,ht,pt,Ge,os,te,ee,Ae,tr,er,Gt,as,Ye,sr,Xi,ir,Zi,$i,Ys;class xt extends Oa{static install(s){ct=s.THREE,Jn=Object.freeze(new ct.Vector3(0,0,0)),Gs=Object.freeze(new ct.Vector3(0,1,0)),Wi=Object.freeze(new ct.Vector3(0,0,1)),Ut=new ct.Vector2,ht=new ct.Vector3,pt=new ct.Vector3,Ge=new ct.Vector3,os=new ct.Vector3,te=new ct.Vector3,ee=new ct.Vector3,Ae=new ct.Vector3,tr=new ct.Vector3,er=new ct.Vector3,Gt=new ct.Spherical,as=new ct.Spherical,Ye=new ct.Box3,sr=new ct.Box3,Xi=new ct.Sphere,ir=new ct.Quaternion,Zi=new ct.Quaternion,$i=new ct.Matrix4,Ys=new ct.Raycaster}static get ACTION(){return H}constructor(s,t){super(),this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=Number.EPSILON,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.dollyDragInverted=!1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.verticalDragToForward=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=H.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=Ve.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new ct.Vector3,this._focalOffsetVelocity=new ct.Vector3,this._zoomVelocity={value:0},this._truckInternal=(g,y,w)=>{let O,M;if(_e(this._camera)){const b=ht.copy(this._camera.position).sub(this._target),v=this._camera.getEffectiveFOV()*is,k=b.length()*Math.tan(v*.5);O=this.truckSpeed*g*k/this._elementRect.height,M=this.truckSpeed*y*k/this._elementRect.height}else if(fe(this._camera)){const b=this._camera;O=g*(b.right-b.left)/b.zoom/this._elementRect.width,M=y*(b.top-b.bottom)/b.zoom/this._elementRect.height}else return;this.verticalDragToForward?(w?this.setFocalOffset(this._focalOffsetEnd.x+O,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(O,0,!0),this.forward(-M,!0)):w?this.setFocalOffset(this._focalOffsetEnd.x+O,this._focalOffsetEnd.y+M,this._focalOffsetEnd.z,!0):this.truck(O,M,!0)},this._rotateInternal=(g,y)=>{const w=ke*this.azimuthRotateSpeed*g/this._elementRect.height,O=ke*this.polarRotateSpeed*y/this._elementRect.height;this.rotate(w,O,!0)},this._dollyInternal=(g,y,w)=>{const O=Math.pow(.95,-g*this.dollySpeed),M=this._sphericalEnd.radius,b=this._sphericalEnd.radius*O,v=jt(b,this.minDistance,this.maxDistance),k=v-b;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(b,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(k,!0),this._dollyToNoClamp(v,!0)):this._dollyToNoClamp(v,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?b:v)-M,this._dollyControlCoord.set(y,w)),this._lastDollyDirection=Math.sign(-g)},this._zoomInternal=(g,y,w)=>{const O=Math.pow(.95,g*this.dollySpeed),M=this._zoom,b=this._zoom*O;this.zoomTo(b,!0),this.dollyToCursor&&(this._changedZoom+=b-M,this._dollyControlCoord.set(y,w))},typeof ct>"u"&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=s,this._yAxisUpSpace=new ct.Quaternion().setFromUnitVectors(this._camera.up,Gs),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=H.NONE,this._target=new ct.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new ct.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new ct.Spherical().setFromVector3(ht.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 ct.Vector3,new ct.Vector3,new ct.Vector3,new ct.Vector3],this._updateNearPlaneCorners(),this._boundary=new ct.Box3(new ct.Vector3(-1/0,-1/0,-1/0),new ct.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 ct.Vector2,this.mouseButtons={left:H.ROTATE,middle:H.DOLLY,right:H.TRUCK,wheel:_e(this._camera)?H.DOLLY:fe(this._camera)?H.ZOOM:H.NONE},this.touches={one:H.TOUCH_ROTATE,two:_e(this._camera)?H.TOUCH_DOLLY_TRUCK:fe(this._camera)?H.TOUCH_ZOOM_TRUCK:H.NONE,three:H.TOUCH_TRUCK};const e=new ct.Vector2,i=new ct.Vector2,n=new ct.Vector2,r=g=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const O=this._domElement.getBoundingClientRect(),M=g.clientX/O.width,b=g.clientY/O.height;if(M<this._interactiveArea.left||M>this._interactiveArea.right||b<this._interactiveArea.top||b>this._interactiveArea.bottom)return}const y=g.pointerType!=="mouse"?null:(g.buttons&lt.LEFT)===lt.LEFT?lt.LEFT:(g.buttons&lt.MIDDLE)===lt.MIDDLE?lt.MIDDLE:(g.buttons&lt.RIGHT)===lt.RIGHT?lt.RIGHT:null;if(y!==null){const O=this._findPointerByMouseButton(y);O&&this._disposePointer(O)}if((g.buttons&lt.LEFT)===lt.LEFT&&this._lockedPointer)return;const w={pointerId:g.pointerId,clientX:g.clientX,clientY:g.clientY,deltaX:0,deltaY:0,mouseButton:y};this._activePointers.push(w),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",h),this._isDragging=!0,p(g)},o=g=>{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 O=this._domElement.getBoundingClientRect(),M=g.clientX/O.width,b=g.clientY/O.height;if(M<this._interactiveArea.left||M>this._interactiveArea.right||b<this._interactiveArea.top||b>this._interactiveArea.bottom)return}const y=(g.buttons&lt.LEFT)===lt.LEFT?lt.LEFT:(g.buttons&lt.MIDDLE)===lt.MIDDLE?lt.MIDDLE:(g.buttons&lt.RIGHT)===lt.RIGHT?lt.RIGHT:null;if(y!==null){const O=this._findPointerByMouseButton(y);O&&this._disposePointer(O)}const w={pointerId:1,clientX:g.clientX,clientY:g.clientY,deltaX:0,deltaY:0,mouseButton:(g.buttons&lt.LEFT)===lt.LEFT?lt.LEFT:(g.buttons&lt.MIDDLE)===lt.LEFT?lt.MIDDLE:(g.buttons&lt.RIGHT)===lt.LEFT?lt.RIGHT:null};this._activePointers.push(w),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("mouseup",d),this._domElement.ownerDocument.addEventListener("mousemove",l),this._domElement.ownerDocument.addEventListener("mouseup",d),this._isDragging=!0,p(g)},a=g=>{g.cancelable&&g.preventDefault();const y=g.pointerId,w=this._lockedPointer||this._findPointerById(y);if(w){if(w.clientX=g.clientX,w.clientY=g.clientY,w.deltaX=g.movementX,w.deltaY=g.movementY,this._state=0,g.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&&(g.buttons&lt.LEFT)===lt.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(g.buttons&lt.MIDDLE)===lt.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(g.buttons&lt.RIGHT)===lt.RIGHT&&(this._state=this._state|this.mouseButtons.right);I()}},l=g=>{const y=this._lockedPointer||this._findPointerById(1);y&&(y.clientX=g.clientX,y.clientY=g.clientY,y.deltaX=g.movementX,y.deltaY=g.movementY,this._state=0,(this._lockedPointer||(g.buttons&lt.LEFT)===lt.LEFT)&&(this._state=this._state|this.mouseButtons.left),(g.buttons&lt.MIDDLE)===lt.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(g.buttons&lt.RIGHT)===lt.RIGHT&&(this._state=this._state|this.mouseButtons.right),I())},h=g=>{const y=this._findPointerById(g.pointerId);if(!(y&&y===this._lockedPointer)){if(y&&this._disposePointer(y),g.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=H.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=H.NONE;m()}},d=()=>{const g=this._findPointerById(1);g&&g===this._lockedPointer||(g&&this._disposePointer(g),this._state=H.NONE,m())};let u=-1;const f=g=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===H.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const b=this._domElement.getBoundingClientRect(),v=g.clientX/b.width,k=g.clientY/b.height;if(v<this._interactiveArea.left||v>this._interactiveArea.right||k<this._interactiveArea.top||k>this._interactiveArea.bottom)return}if(g.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===H.ROTATE||this.mouseButtons.wheel===H.TRUCK){const b=performance.now();u-b<1e3&&this._getClientRect(this._elementRect),u=b}const y=ba?-1:-3,w=g.deltaMode===1?g.deltaY/y:g.deltaY/(y*10),O=this.dollyToCursor?(g.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,M=this.dollyToCursor?(g.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case H.ROTATE:{this._rotateInternal(g.deltaX,g.deltaY),this._isUserControllingRotate=!0;break}case H.TRUCK:{this._truckInternal(g.deltaX,g.deltaY,!1),this._isUserControllingTruck=!0;break}case H.OFFSET:{this._truckInternal(g.deltaX,g.deltaY,!0),this._isUserControllingOffset=!0;break}case H.DOLLY:{this._dollyInternal(-w,O,M),this._isUserControllingDolly=!0;break}case H.ZOOM:{this._zoomInternal(-w,O,M),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},E=g=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===xt.ACTION.NONE){const y=g instanceof PointerEvent?g.pointerId:(g instanceof MouseEvent,0),w=this._findPointerById(y);w&&this._disposePointer(w),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("mouseup",d);return}g.preventDefault()}},p=g=>{if(!this._enabled)return;if(Yi(this._activePointers,Ut),this._getClientRect(this._elementRect),e.copy(Ut),i.copy(Ut),this._activePointers.length>=2){const w=Ut.x-this._activePointers[1].clientX,O=Ut.y-this._activePointers[1].clientY,M=Math.sqrt(w*w+O*O);n.set(0,M);const b=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,v=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;i.set(b,v)}if(this._state=0,!g)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in g&&g.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&&(g.buttons&lt.LEFT)===lt.LEFT&&(this._state=this._state|this.mouseButtons.left),(g.buttons&lt.MIDDLE)===lt.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(g.buttons&lt.RIGHT)===lt.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&H.ROTATE)===H.ROTATE||(this._state&H.TOUCH_ROTATE)===H.TOUCH_ROTATE||(this._state&H.TOUCH_DOLLY_ROTATE)===H.TOUCH_DOLLY_ROTATE||(this._state&H.TOUCH_ZOOM_ROTATE)===H.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&H.TRUCK)===H.TRUCK||(this._state&H.TOUCH_TRUCK)===H.TOUCH_TRUCK||(this._state&H.TOUCH_DOLLY_TRUCK)===H.TOUCH_DOLLY_TRUCK||(this._state&H.TOUCH_ZOOM_TRUCK)===H.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&H.DOLLY)===H.DOLLY||(this._state&H.TOUCH_DOLLY)===H.TOUCH_DOLLY||(this._state&H.TOUCH_DOLLY_TRUCK)===H.TOUCH_DOLLY_TRUCK||(this._state&H.TOUCH_DOLLY_OFFSET)===H.TOUCH_DOLLY_OFFSET||(this._state&H.TOUCH_DOLLY_ROTATE)===H.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&H.ZOOM)===H.ZOOM||(this._state&H.TOUCH_ZOOM)===H.TOUCH_ZOOM||(this._state&H.TOUCH_ZOOM_TRUCK)===H.TOUCH_ZOOM_TRUCK||(this._state&H.TOUCH_ZOOM_OFFSET)===H.TOUCH_ZOOM_OFFSET||(this._state&H.TOUCH_ZOOM_ROTATE)===H.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&H.OFFSET)===H.OFFSET||(this._state&H.TOUCH_OFFSET)===H.TOUCH_OFFSET||(this._state&H.TOUCH_DOLLY_OFFSET)===H.TOUCH_DOLLY_OFFSET||(this._state&H.TOUCH_ZOOM_OFFSET)===H.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},I=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,Yi(this._activePointers,Ut);const y=this._domElement&&document.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,w=y?-y.deltaX:i.x-Ut.x,O=y?-y.deltaY:i.y-Ut.y;if(i.copy(Ut),((this._state&H.ROTATE)===H.ROTATE||(this._state&H.TOUCH_ROTATE)===H.TOUCH_ROTATE||(this._state&H.TOUCH_DOLLY_ROTATE)===H.TOUCH_DOLLY_ROTATE||(this._state&H.TOUCH_ZOOM_ROTATE)===H.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(w,O),this._isUserControllingRotate=!0),(this._state&H.DOLLY)===H.DOLLY||(this._state&H.ZOOM)===H.ZOOM){const M=this.dollyToCursor?(e.x-this._elementRect.x)/this._elementRect.width*2-1:0,b=this.dollyToCursor?(e.y-this._elementRect.y)/this._elementRect.height*-2+1:0,v=this.dollyDragInverted?-1:1;(this._state&H.DOLLY)===H.DOLLY?(this._dollyInternal(v*O*ks,M,b),this._isUserControllingDolly=!0):(this._zoomInternal(v*O*ks,M,b),this._isUserControllingZoom=!0)}if((this._state&H.TOUCH_DOLLY)===H.TOUCH_DOLLY||(this._state&H.TOUCH_ZOOM)===H.TOUCH_ZOOM||(this._state&H.TOUCH_DOLLY_TRUCK)===H.TOUCH_DOLLY_TRUCK||(this._state&H.TOUCH_ZOOM_TRUCK)===H.TOUCH_ZOOM_TRUCK||(this._state&H.TOUCH_DOLLY_OFFSET)===H.TOUCH_DOLLY_OFFSET||(this._state&H.TOUCH_ZOOM_OFFSET)===H.TOUCH_ZOOM_OFFSET||(this._state&H.TOUCH_DOLLY_ROTATE)===H.TOUCH_DOLLY_ROTATE||(this._state&H.TOUCH_ZOOM_ROTATE)===H.TOUCH_ZOOM_ROTATE){const M=Ut.x-this._activePointers[1].clientX,b=Ut.y-this._activePointers[1].clientY,v=Math.sqrt(M*M+b*b),k=n.y-v;n.set(0,v);const F=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&H.TOUCH_DOLLY)===H.TOUCH_DOLLY||(this._state&H.TOUCH_DOLLY_ROTATE)===H.TOUCH_DOLLY_ROTATE||(this._state&H.TOUCH_DOLLY_TRUCK)===H.TOUCH_DOLLY_TRUCK||(this._state&H.TOUCH_DOLLY_OFFSET)===H.TOUCH_DOLLY_OFFSET?(this._dollyInternal(k*ks,F,L),this._isUserControllingDolly=!0):(this._zoomInternal(k*ks,F,L),this._isUserControllingZoom=!0)}((this._state&H.TRUCK)===H.TRUCK||(this._state&H.TOUCH_TRUCK)===H.TOUCH_TRUCK||(this._state&H.TOUCH_DOLLY_TRUCK)===H.TOUCH_DOLLY_TRUCK||(this._state&H.TOUCH_ZOOM_TRUCK)===H.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(w,O,!1),this._isUserControllingTruck=!0),((this._state&H.OFFSET)===H.OFFSET||(this._state&H.TOUCH_OFFSET)===H.TOUCH_OFFSET||(this._state&H.TOUCH_DOLLY_OFFSET)===H.TOUCH_DOLLY_OFFSET||(this._state&H.TOUCH_ZOOM_OFFSET)===H.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(w,O,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},m=()=>{Yi(this._activePointers,Ut),i.copy(Ut),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",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.removeEventListener("mouseup",d),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",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",C),this._domElement.ownerDocument.addEventListener("pointerlockerror",R),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",h),p())},this.unlockPointer=()=>{this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),document.exitPointerLock(),this.cancel(),this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointerlockchange",C),this._domElement.ownerDocument.removeEventListener("pointerlockerror",R))};const C=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},R=()=>{this.unlockPointer()};this._addAllEventListeners=g=>{this._domElement=g,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",r),Pa&&this._domElement.addEventListener("mousedown",o),this._domElement.addEventListener("pointercancel",h),this._domElement.addEventListener("wheel",f,{passive:!1}),this._domElement.addEventListener("contextmenu",E)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",r),this._domElement.removeEventListener("mousedown",o),this._domElement.removeEventListener("pointercancel",h),this._domElement.removeEventListener("wheel",f,{passive:!1}),this._domElement.removeEventListener("contextmenu",E),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.removeEventListener("mouseup",d),this._domElement.ownerDocument.removeEventListener("pointerlockchange",C),this._domElement.ownerDocument.removeEventListener("pointerlockerror",R))},this.cancel=()=>{this._state!==H.NONE&&(this._state=H.NONE,this._activePointers.length=0,m())},t&&this.connect(t),this.update(0)}get camera(){return this._camera}set camera(s){this._camera=s,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(s){this._enabled=s,this._domElement&&(s?(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(s){this._spherical.radius===s&&this._sphericalEnd.radius===s||(this._spherical.radius=s,this._sphericalEnd.radius=s,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(s){this._spherical.theta===s&&this._sphericalEnd.theta===s||(this._spherical.theta=s,this._sphericalEnd.theta=s,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(s){this._spherical.phi===s&&this._sphericalEnd.phi===s||(this._spherical.phi=s,this._sphericalEnd.phi=s,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(s){this._boundaryEnclosesCamera=s,this._needsUpdate=!0}set interactiveArea(s){this._interactiveArea.width=jt(s.width,0,1),this._interactiveArea.height=jt(s.height,0,1),this._interactiveArea.x=jt(s.x,0,1-this._interactiveArea.width),this._interactiveArea.y=jt(s.y,0,1-this._interactiveArea.height)}addEventListener(s,t){super.addEventListener(s,t)}removeEventListener(s,t){super.removeEventListener(s,t)}rotate(s,t,e=!1){return this.rotateTo(this._sphericalEnd.theta+s,this._sphericalEnd.phi+t,e)}rotateAzimuthTo(s,t=!1){return this.rotateTo(s,this._sphericalEnd.phi,t)}rotatePolarTo(s,t=!1){return this.rotateTo(this._sphericalEnd.theta,s,t)}rotateTo(s,t,e=!1){this._isUserControllingRotate=!1;const i=jt(s,this.minAzimuthAngle,this.maxAzimuthAngle),n=jt(t,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=i,this._sphericalEnd.phi=n,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,e||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const r=!e||Et(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Et(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(r)}dolly(s,t=!1){return this.dollyTo(this._sphericalEnd.radius-s,t)}dollyTo(s,t=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Ve.NONE,this._changedDolly=0,this._dollyToNoClamp(jt(s,this.minDistance,this.maxDistance),t)}_dollyToNoClamp(s,t=!1){const e=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const r=this._collisionTest(),o=Et(r,this._spherical.radius);if(!(e>s)&&o)return Promise.resolve();this._sphericalEnd.radius=Math.min(s,r)}else this._sphericalEnd.radius=s;this._needsUpdate=!0,t||(this._spherical.radius=this._sphericalEnd.radius);const n=!t||Et(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(n)}dollyInFixed(s,t=!1){this._targetEnd.add(this._getCameraDirection(os).multiplyScalar(s)),t||this._target.copy(this._targetEnd);const e=!t||Et(this._target.x,this._targetEnd.x,this.restThreshold)&&Et(this._target.y,this._targetEnd.y,this.restThreshold)&&Et(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(e)}zoom(s,t=!1){return this.zoomTo(this._zoomEnd+s,t)}zoomTo(s,t=!1){this._isUserControllingZoom=!1,this._zoomEnd=jt(s,this.minZoom,this.maxZoom),this._needsUpdate=!0,t||(this._zoom=this._zoomEnd);const e=!t||Et(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(e)}pan(s,t,e=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(s,t,e)}truck(s,t,e=!1){this._camera.updateMatrix(),te.setFromMatrixColumn(this._camera.matrix,0),ee.setFromMatrixColumn(this._camera.matrix,1),te.multiplyScalar(s),ee.multiplyScalar(-t);const i=ht.copy(te).add(ee),n=pt.copy(this._targetEnd).add(i);return this.moveTo(n.x,n.y,n.z,e)}forward(s,t=!1){ht.setFromMatrixColumn(this._camera.matrix,0),ht.crossVectors(this._camera.up,ht),ht.multiplyScalar(s);const e=pt.copy(this._targetEnd).add(ht);return this.moveTo(e.x,e.y,e.z,t)}elevate(s,t=!1){return ht.copy(this._camera.up).multiplyScalar(s),this.moveTo(this._targetEnd.x+ht.x,this._targetEnd.y+ht.y,this._targetEnd.z+ht.z,t)}moveTo(s,t,e,i=!1){this._isUserControllingTruck=!1;const n=ht.set(s,t,e).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,n,this.boundaryFriction),this._needsUpdate=!0,i||this._target.copy(this._targetEnd);const r=!i||Et(this._target.x,this._targetEnd.x,this.restThreshold)&&Et(this._target.y,this._targetEnd.y,this.restThreshold)&&Et(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}lookInDirectionOf(s,t,e,i=!1){const o=ht.set(s,t,e).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius);return this.setPosition(o.x,o.y,o.z,i)}fitToBox(s,t,{cover:e=!1,paddingLeft:i=0,paddingRight:n=0,paddingBottom:r=0,paddingTop:o=0}={}){const a=[],l=s.isBox3?Ye.copy(s):Ye.setFromObject(s);l.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const h=qn(this._sphericalEnd.theta,Qn),d=qn(this._sphericalEnd.phi,Qn);a.push(this.rotateTo(h,d,t));const u=ht.setFromSpherical(this._sphericalEnd).normalize(),f=ir.setFromUnitVectors(u,Wi),E=Et(Math.abs(u.y),1);E&&f.multiply(Zi.setFromAxisAngle(Gs,h)),f.multiply(this._yAxisUpSpaceInverse);const p=sr.makeEmpty();pt.copy(l.min).applyQuaternion(f),p.expandByPoint(pt),pt.copy(l.min).setX(l.max.x).applyQuaternion(f),p.expandByPoint(pt),pt.copy(l.min).setY(l.max.y).applyQuaternion(f),p.expandByPoint(pt),pt.copy(l.max).setZ(l.min.z).applyQuaternion(f),p.expandByPoint(pt),pt.copy(l.min).setZ(l.max.z).applyQuaternion(f),p.expandByPoint(pt),pt.copy(l.max).setY(l.min.y).applyQuaternion(f),p.expandByPoint(pt),pt.copy(l.max).setX(l.min.x).applyQuaternion(f),p.expandByPoint(pt),pt.copy(l.max).applyQuaternion(f),p.expandByPoint(pt),p.min.x-=i,p.min.y-=r,p.max.x+=n,p.max.y+=o,f.setFromUnitVectors(Wi,u),E&&f.premultiply(Zi.invert()),f.premultiply(this._yAxisUpSpace);const I=p.getSize(ht),m=p.getCenter(pt).applyQuaternion(f);if(_e(this._camera)){const C=this.getDistanceToFitBox(I.x,I.y,I.z,e);a.push(this.moveTo(m.x,m.y,m.z,t)),a.push(this.dollyTo(C,t)),a.push(this.setFocalOffset(0,0,0,t))}else if(fe(this._camera)){const C=this._camera,R=C.right-C.left,g=C.top-C.bottom,y=e?Math.max(R/I.x,g/I.y):Math.min(R/I.x,g/I.y);a.push(this.moveTo(m.x,m.y,m.z,t)),a.push(this.zoomTo(y,t)),a.push(this.setFocalOffset(0,0,0,t))}return Promise.all(a)}fitToSphere(s,t){const e=[],n=s instanceof ct.Sphere?Xi.copy(s):xt.createBoundingSphere(s,Xi);if(e.push(this.moveTo(n.center.x,n.center.y,n.center.z,t)),_e(this._camera)){const r=this.getDistanceToFitSphere(n.radius);e.push(this.dollyTo(r,t))}else if(fe(this._camera)){const r=this._camera.right-this._camera.left,o=this._camera.top-this._camera.bottom,a=2*n.radius,l=Math.min(r/a,o/a);e.push(this.zoomTo(l,t))}return e.push(this.setFocalOffset(0,0,0,t)),Promise.all(e)}setLookAt(s,t,e,i,n,r,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Ve.NONE,this._changedDolly=0;const a=pt.set(i,n,r),l=ht.set(s,t,e);this._targetEnd.copy(a),this._sphericalEnd.setFromVector3(l.sub(a).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,o||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const h=!o||Et(this._target.x,this._targetEnd.x,this.restThreshold)&&Et(this._target.y,this._targetEnd.y,this.restThreshold)&&Et(this._target.z,this._targetEnd.z,this.restThreshold)&&Et(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Et(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&Et(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(h)}lerpLookAt(s,t,e,i,n,r,o,a,l,h,d,u,f,E=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Ve.NONE,this._changedDolly=0;const p=ht.set(i,n,r),I=pt.set(s,t,e);Gt.setFromVector3(I.sub(p).applyQuaternion(this._yAxisUpSpace));const m=Ge.set(h,d,u),C=pt.set(o,a,l);as.setFromVector3(C.sub(m).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(p.lerp(m,f));const R=as.theta-Gt.theta,g=as.phi-Gt.phi,y=as.radius-Gt.radius;this._sphericalEnd.set(Gt.radius+y*f,Gt.phi+g*f,Gt.theta+R*f),this.normalizeRotations(),this._needsUpdate=!0,E||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const w=!E||Et(this._target.x,this._targetEnd.x,this.restThreshold)&&Et(this._target.y,this._targetEnd.y,this.restThreshold)&&Et(this._target.z,this._targetEnd.z,this.restThreshold)&&Et(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Et(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&Et(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(w)}setPosition(s,t,e,i=!1){return this.setLookAt(s,t,e,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,i)}setTarget(s,t,e,i=!1){const n=this.getPosition(ht),r=this.setLookAt(n.x,n.y,n.z,s,t,e,i);return this._sphericalEnd.phi=jt(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),r}setFocalOffset(s,t,e,i=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(s,t,e),this._needsUpdate=!0,i||this._focalOffset.copy(this._focalOffsetEnd);const n=!i||Et(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&Et(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&Et(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}setOrbitPoint(s,t,e){this._camera.updateMatrixWorld(),te.setFromMatrixColumn(this._camera.matrixWorldInverse,0),ee.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Ae.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const i=ht.set(s,t,e),n=i.distanceTo(this._camera.position),r=i.sub(this._camera.position);te.multiplyScalar(r.x),ee.multiplyScalar(r.y),Ae.multiplyScalar(r.z),ht.copy(te).add(ee).add(Ae),ht.z=ht.z+n,this.dollyTo(n,!1),this.setFocalOffset(-ht.x,ht.y,-ht.z,!1),this.moveTo(s,t,e,!1)}setBoundary(s){if(!s){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(s),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(s,t,e,i){if(s===null){this._viewport=null;return}this._viewport=this._viewport||new ct.Vector4,typeof s=="number"?this._viewport.set(s,t,e,i):this._viewport.copy(s)}getDistanceToFitBox(s,t,e,i=!1){if(Hi(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const n=s/t,r=this._camera.getEffectiveFOV()*is,o=this._camera.aspect;return((i?n>o:n<o)?t:s/o)*.5/Math.tan(r*.5)+e*.5}getDistanceToFitSphere(s){if(Hi(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const t=this._camera.getEffectiveFOV()*is,e=Math.atan(Math.tan(t*.5)*this._camera.aspect)*2,i=1<this._camera.aspect?t:e;return s/Math.sin(i*.5)}getTarget(s,t=!0){return(s&&s.isVector3?s:new ct.Vector3).copy(t?this._targetEnd:this._target)}getPosition(s,t=!0){return(s&&s.isVector3?s:new ct.Vector3).setFromSpherical(t?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(t?this._targetEnd:this._target)}getSpherical(s,t=!0){return(s&&s instanceof ct.Spherical?s:new ct.Spherical).copy(t?this._sphericalEnd:this._spherical)}getFocalOffset(s,t=!0){return(s&&s.isVector3?s:new ct.Vector3).copy(t?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%ke,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=ke),this._spherical.theta+=ke*Math.round((this._sphericalEnd.theta-this._spherical.theta)/ke)}reset(s=!1){if(!Et(this._camera.up.x,this._cameraUp0.x)||!Et(this._camera.up.y,this._cameraUp0.y)||!Et(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const e=this.getPosition(ht);this.updateCameraUp(),this.setPosition(e.x,e.y,e.z)}const t=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,s),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,s),this.zoomTo(this._zoom0,s)];return Promise.all(t)}saveState(){this._cameraUp0.copy(this._camera.up),this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,Gs),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const s=ht.subVectors(this._target,this._camera.position).normalize(),t=pt.crossVectors(s,this._camera.up);this._camera.up.crossVectors(t,s).normalize(),this._camera.updateMatrixWorld();const e=this.getPosition(ht);this.updateCameraUp(),this.setPosition(e.x,e.y,e.z)}update(s){const t=this._sphericalEnd.theta-this._spherical.theta,e=this._sphericalEnd.phi-this._spherical.phi,i=this._sphericalEnd.radius-this._spherical.radius,n=tr.subVectors(this._targetEnd,this._target),r=er.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(Tt(t))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const d=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=Vs(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,d,1/0,s),this._needsUpdate=!0}if(Tt(e))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const d=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=Vs(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,d,1/0,s),this._needsUpdate=!0}if(Tt(i))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const d=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=Vs(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,d,this.maxSpeed,s),this._needsUpdate=!0}if(Tt(n.x)&&Tt(n.y)&&Tt(n.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const d=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Kn(this._target,this._targetEnd,this._targetVelocity,d,this.maxSpeed,s,this._target),this._needsUpdate=!0}if(Tt(r.x)&&Tt(r.y)&&Tt(r.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const d=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Kn(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,d,this.maxSpeed,s,this._focalOffset),this._needsUpdate=!0}if(Tt(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const d=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=Vs(this._zoom,this._zoomEnd,this._zoomVelocity,d,1/0,s)}if(this.dollyToCursor){if(_e(this._camera)&&this._changedDolly!==0){const d=this._spherical.radius-this._lastDistance,u=this._camera,f=this._getCameraDirection(os),E=ht.copy(f).cross(u.up).normalize();E.lengthSq()===0&&(E.x=1);const p=pt.crossVectors(E,f),I=this._sphericalEnd.radius*Math.tan(u.getEffectiveFOV()*is*.5),C=(this._sphericalEnd.radius-d-this._sphericalEnd.radius)/this._sphericalEnd.radius,R=Ge.copy(this._targetEnd).add(E.multiplyScalar(this._dollyControlCoord.x*I*u.aspect)).add(p.multiplyScalar(this._dollyControlCoord.y*I)),g=ht.copy(this._targetEnd).lerp(R,C),y=this._lastDollyDirection===Ve.IN&&this._spherical.radius<=this.minDistance,w=this._lastDollyDirection===Ve.OUT&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(y||w)){this._sphericalEnd.radius-=d,this._spherical.radius-=d;const M=pt.copy(f).multiplyScalar(-d);g.add(M)}this._boundary.clampPoint(g,g);const O=pt.subVectors(g,this._targetEnd);this._targetEnd.copy(g),this._target.add(O),this._changedDolly-=d,Tt(this._changedDolly)&&(this._changedDolly=0)}else if(fe(this._camera)&&this._changedZoom!==0){const d=this._zoom-this._lastZoom,u=this._camera,f=ht.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(u.near+u.far)/(u.near-u.far)).unproject(u),E=pt.set(0,0,-1).applyQuaternion(u.quaternion),p=Ge.copy(f).add(E.multiplyScalar(-f.dot(u.up))),m=-(this._zoom-d-this._zoom)/this._zoom,C=this._getCameraDirection(os),R=this._targetEnd.dot(C),g=ht.copy(this._targetEnd).lerp(p,m),y=g.dot(C),w=C.multiplyScalar(y-R);g.sub(w),this._boundary.clampPoint(g,g);const O=pt.subVectors(g,this._targetEnd);this._targetEnd.copy(g),this._target.add(O),this._changedZoom-=d,Tt(this._changedZoom)&&(this._changedZoom=0)}}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0),this._dragNeedsUpdate=!0;const a=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,a),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!Tt(this._focalOffset.x)||!Tt(this._focalOffset.y)||!Tt(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),te.setFromMatrixColumn(this._camera.matrix,0),ee.setFromMatrixColumn(this._camera.matrix,1),Ae.setFromMatrixColumn(this._camera.matrix,2),te.multiplyScalar(this._focalOffset.x),ee.multiplyScalar(-this._focalOffset.y),Ae.multiplyScalar(this._focalOffset.z),ht.copy(te).add(ee).add(Ae),this._camera.position.add(ht)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),ht.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const h=this._needsUpdate;return h&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):h?(this.dispatchEvent({type:"update"}),Tt(t,this.restThreshold)&&Tt(e,this.restThreshold)&&Tt(i,this.restThreshold)&&Tt(n.x,this.restThreshold)&&Tt(n.y,this.restThreshold)&&Tt(n.z,this.restThreshold)&&Tt(r.x,this.restThreshold)&&Tt(r.y,this.restThreshold)&&Tt(r.z,this.restThreshold)&&Tt(o,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!h&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=h,this._needsUpdate=!1,h}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:ns(this.maxDistance),minZoom:this.minZoom,maxZoom:ns(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:ns(this.maxPolarAngle),minAzimuthAngle:ns(this.minAzimuthAngle),maxAzimuthAngle:ns(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,verticalDragToForward:this.verticalDragToForward,target:this._targetEnd.toArray(),position:ht.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(s,t=!1){const e=JSON.parse(s);this.enabled=e.enabled,this.minDistance=e.minDistance,this.maxDistance=rs(e.maxDistance),this.minZoom=e.minZoom,this.maxZoom=rs(e.maxZoom),this.minPolarAngle=e.minPolarAngle,this.maxPolarAngle=rs(e.maxPolarAngle),this.minAzimuthAngle=rs(e.minAzimuthAngle),this.maxAzimuthAngle=rs(e.maxAzimuthAngle),this.smoothTime=e.smoothTime,this.draggingSmoothTime=e.draggingSmoothTime,this.dollySpeed=e.dollySpeed,this.truckSpeed=e.truckSpeed,this.dollyToCursor=e.dollyToCursor,this.verticalDragToForward=e.verticalDragToForward,this._target0.fromArray(e.target0),this._position0.fromArray(e.position0),this._zoom0=e.zoom0,this._focalOffset0.fromArray(e.focalOffset0),this.moveTo(e.target[0],e.target[1],e.target[2],t),Gt.setFromVector3(ht.fromArray(e.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(Gt.theta,Gt.phi,t),this.dollyTo(Gt.radius,t),this.zoomTo(e.zoom,t),this.setFocalOffset(e.focalOffset[0],e.focalOffset[1],e.focalOffset[2],t),this._needsUpdate=!0}connect(s){if(this._domElement){console.warn("camera-controls is already connected.");return}s.setAttribute("data-camera-controls-version",Na),this._addAllEventListeners(s),this._getClientRect(this._elementRect)}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement.removeAttribute("data-camera-controls-version"),this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_getTargetDirection(s){return s.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse)}_getCameraDirection(s){return this._getTargetDirection(s).negate()}_findPointerById(s){return this._activePointers.find(t=>t.pointerId===s)}_findPointerByMouseButton(s){return this._activePointers.find(t=>t.mouseButton===s)}_disposePointer(s){this._activePointers.splice(this._activePointers.indexOf(s),1)}_encloseToBoundary(s,t,e){const i=t.lengthSq();if(i===0)return s;const n=pt.copy(t).add(s),o=this._boundary.clampPoint(n,Ge).sub(n),a=o.lengthSq();if(a===0)return s.add(t);if(a===i)return s;if(e===0)return s.add(t).add(o);{const l=1+e*a/t.dot(o);return s.add(pt.copy(t).multiplyScalar(l)).add(o.multiplyScalar(1-e))}}_updateNearPlaneCorners(){if(_e(this._camera)){const s=this._camera,t=s.near,e=s.getEffectiveFOV()*is,i=Math.tan(e*.5)*t,n=i*s.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(fe(this._camera)){const s=this._camera,t=1/s.zoom,e=s.left*t,i=s.right*t,n=s.top*t,r=s.bottom*t;this._nearPlaneCorners[0].set(e,n,0),this._nearPlaneCorners[1].set(i,n,0),this._nearPlaneCorners[2].set(i,r,0),this._nearPlaneCorners[3].set(e,r,0)}}_collisionTest(){let s=1/0;if(!(this.colliderMeshes.length>=1)||Hi(this._camera,"_collisionTest"))return s;const e=this._getTargetDirection(os);$i.lookAt(Jn,e,this._camera.up);for(let i=0;i<4;i++){const n=pt.copy(this._nearPlaneCorners[i]);n.applyMatrix4($i);const r=Ge.addVectors(this._target,n);Ys.set(r,e),Ys.far=this._spherical.radius+1;const o=Ys.intersectObjects(this.colliderMeshes);o.length!==0&&o[0].distance<s&&(s=o[0].distance)}return s}_getClientRect(s){if(!this._domElement)return;const t=this._domElement.getBoundingClientRect();return s.x=t.left,s.y=t.top,this._viewport?(s.x+=this._viewport.x,s.y+=t.height-this._viewport.w-this._viewport.y,s.width=this._viewport.z,s.height=this._viewport.w):(s.width=t.width,s.height=t.height),s}_createOnRestPromise(s){return s?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(t=>{const e=()=>{this.removeEventListener("rest",e),t()};this.addEventListener("rest",e)}))}_addAllEventListeners(s){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(s){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(s){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(s,t=new ct.Sphere){const e=t,i=e.center;Ye.makeEmpty(),s.traverseVisible(r=>{r.isMesh&&Ye.expandByObject(r)}),Ye.getCenter(i);let n=0;return s.traverseVisible(r=>{if(!r.isMesh)return;const o=r,a=o.geometry.clone();a.applyMatrix4(o.matrixWorld);const h=a.attributes.position;for(let d=0,u=h.count;d<u;d++)ht.fromBufferAttribute(h,d),n=Math.max(n,i.distanceToSquared(ht))}),e.radius=Math.sqrt(n),e}}class We extends Ar{constructor(t){super(t);T(this,"onBeforeUpdate",new Q);T(this,"onAfterUpdate",new Q);T(this,"onAspectUpdated",new Q);T(this,"onDisposed",new Q);T(this,"three");T(this,"_allControls",new Map);T(this,"updateAspect",()=>{var t;if(!(!this.currentWorld||!this.currentWorld.renderer)){if(this.three instanceof x.OrthographicCamera){this.onAspectUpdated.trigger();return}if((t=this.currentWorld.renderer)!=null&&t.isResizeable()){const e=this.currentWorld.renderer.getSize();this.three.aspect=e.width/e.height,this.three.updateProjectionMatrix(),this.onAspectUpdated.trigger()}}});this.three=this.setupCamera(),this.setupEvents(!0),this.onWorldChanged.add(({action:e,world:i})=>{if(e==="added"){const n=this.newCameraControls();this._allControls.set(i.uuid,n)}if(e==="removed"){const n=this._allControls.get(i.uuid);n&&(n.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.currentWorld!==null&&(this.controls.enabled=t)}dispose(){this.setupEvents(!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 x.PerspectiveCamera(60,t,1,1e3);return e.position.set(50,50,50),e.lookAt(new x.Vector3(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!");xt.install({THREE:We.getSubsetOfThree()});const{domElement:t}=this.currentWorld.renderer.three,e=new xt(this.three,t);return e.smoothTime=.2,e.dollyToCursor=!0,e.infinityDolly=!0,e.minDistance=6,e}setupEvents(t){t?window.addEventListener("resize",this.updateAspect):window.removeEventListener("resize",this.updateAspect)}static getSubsetOfThree(){return{MOUSE:x.MOUSE,Vector2:x.Vector2,Vector3:x.Vector3,Vector4:x.Vector4,Quaternion:x.Quaternion,Matrix4:x.Matrix4,Spherical:x.Spherical,Box3:x.Box3,Sphere:x.Sphere,Raycaster:x.Raycaster,MathUtils:x.MathUtils}}}const hi=class hi extends Ft{constructor(t){super(t);T(this,"onAfterUpdate",new Q);T(this,"onBeforeUpdate",new Q);T(this,"onDisposed",new Q);T(this,"onWorldCreated",new Q);T(this,"onWorldDeleted",new Q);T(this,"list",new Map);T(this,"enabled",!0);t.add(hi.uuid,this)}create(){const t=new Sr(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),this.onWorldCreated.trigger(t),t}delete(t){if(!this.list.has(t.uuid))throw new Error("The provided world is not found in the list!");const e=t.uuid;this.list.delete(t.uuid),t.dispose(),this.onWorldDeleted.trigger(e)}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,i]of this.list)i.update(t)}};T(hi,"uuid","fdb61dc4-2ec1-4966-b83d-54ea795fad4a");let ti=hi;function La(c,s,t,e){return new Promise((i,n)=>{function r(){const o=c.clientWaitSync(s,t,0);if(o===c.WAIT_FAILED){n();return}if(o===c.TIMEOUT_EXPIRED){setTimeout(r,e);return}i()}r()})}async function Ma(c,s,t,e,i,n,r){const o=c.fenceSync(c.SYNC_GPU_COMMANDS_COMPLETE,0);c.flush(),await La(c,o,0,10),c.deleteSync(o),c.bindBuffer(s,t),c.getBufferSubData(s,e,i,n,r),c.bindBuffer(s,null)}async function Tn(c,s,t,e,i,n,r,o){const a=c.createBuffer();return c.bindBuffer(c.PIXEL_PACK_BUFFER,a),c.bufferData(c.PIXEL_PACK_BUFFER,o.byteLength,c.STREAM_READ),c.readPixels(s,t,e,i,n,r,0),c.bindBuffer(c.PIXEL_PACK_BUFFER,null),await Ma(c,c.PIXEL_PACK_BUFFER,a,0,o),c.deleteBuffer(a),o}class Pr{constructor(s,t,e){T(this,"onDisposed",new Q);T(this,"onViewUpdated",new Es);T(this,"enabled",!0);T(this,"needsUpdate",!1);T(this,"renderDebugFrame",!1);T(this,"components");T(this,"world");T(this,"renderer");T(this,"autoUpdate",!0);T(this,"updateInterval",1e3);T(this,"worker");T(this,"scene",new x.Scene);T(this,"_width",512);T(this,"_height",512);T(this,"_availableColor",1);T(this,"renderTarget");T(this,"bufferSize");T(this,"_buffer");T(this,"_isWorkerBusy",!1);T(this,"updateVisibility",async s=>{if(!this.enabled||!this.needsUpdate&&!s||this._isWorkerBusy)return;this._isWorkerBusy=!0;const t=this.world.camera.three;t.updateMatrix(),this.renderer.setSize(this._width,this._height),this.renderer.setRenderTarget(this.renderTarget),this.renderer.render(this.scene,t);const e=this.renderer.getContext();try{await Tn(e,0,0,this._width,this._height,e.RGBA,e.UNSIGNED_BYTE,this._buffer)}catch{this.renderer.setRenderTarget(null);return}this.renderer.setRenderTarget(null),this.renderDebugFrame&&this.renderer.render(this.scene,t),this.worker.postMessage({buffer:this._buffer}),this.needsUpdate=!1});if(!t.renderer)throw new Error("The given world must have a renderer!");this.components=s,this.applySettings(e),this.world=t,this.renderer=new x.WebGLRenderer,this.renderTarget=new x.WebGLRenderTarget(this._width,this._height),this.bufferSize=this._width*this._height*4,this._buffer=new Uint8Array(this.bufferSize),this.renderer.clippingPlanes=t.renderer.clippingPlanes;const i=`
10
+ */const lt={LEFT:1,RIGHT:2,MIDDLE:4},H=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}),Ve={NONE:0,IN:1,OUT:-1};function _e(c){return c.isPerspectiveCamera}function fe(c){return c.isOrthographicCamera}const ke=Math.PI*2,Qn=Math.PI/2,Nr=1e-5,is=Math.PI/180;function jt(c,s,t){return Math.max(s,Math.min(t,c))}function Tt(c,s=Nr){return Math.abs(c)<s}function Et(c,s,t=Nr){return Tt(c-s,t)}function qn(c,s){return Math.round(c/s)*s}function ns(c){return isFinite(c)?c:c<0?-Number.MAX_VALUE:Number.MAX_VALUE}function rs(c){return Math.abs(c)<Number.MAX_VALUE?c:c*(1/0)}function Vs(c,s,t,e,i=1/0,n){e=Math.max(1e-4,e);const r=2/e,o=r*n,a=1/(1+o+.48*o*o+.235*o*o*o);let l=c-s;const h=s,d=i*e;l=jt(l,-d,d),s=c-l;const u=(t.value+r*l)*n;t.value=(t.value-r*u)*a;let f=s+(l+u)*a;return h-c>0==f>h&&(f=h,t.value=(f-h)/n),f}function Kn(c,s,t,e,i=1/0,n,r){e=Math.max(1e-4,e);const o=2/e,a=o*n,l=1/(1+a+.48*a*a+.235*a*a*a);let h=s.x,d=s.y,u=s.z,f=c.x-h,E=c.y-d,p=c.z-u;const I=h,m=d,C=u,R=i*e,g=R*R,y=f*f+E*E+p*p;if(y>g){const D=Math.sqrt(y);f=f/D*R,E=E/D*R,p=p/D*R}h=c.x-f,d=c.y-E,u=c.z-p;const w=(t.x+o*f)*n,O=(t.y+o*E)*n,M=(t.z+o*p)*n;t.x=(t.x-o*w)*l,t.y=(t.y-o*O)*l,t.z=(t.z-o*M)*l,r.x=h+(f+w)*l,r.y=d+(E+O)*l,r.z=u+(p+M)*l;const b=I-c.x,v=m-c.y,k=C-c.z,F=r.x-I,L=r.y-m,_=r.z-C;return b*F+v*L+k*_>0&&(r.x=I,r.y=m,r.z=C,t.x=(r.x-I)/n,t.y=(r.y-m)/n,t.z=(r.z-C)/n),r}function Yi(c,s){s.set(0,0),c.forEach(t=>{s.x+=t.clientX,s.y+=t.clientY}),s.x/=c.length,s.y/=c.length}function Hi(c,s){return fe(c)?(console.warn(`${s} is not supported in OrthographicCamera`),!0):!1}class Oa{constructor(){this._listeners={}}addEventListener(s,t){const e=this._listeners;e[s]===void 0&&(e[s]=[]),e[s].indexOf(t)===-1&&e[s].push(t)}hasEventListener(s,t){const e=this._listeners;return e[s]!==void 0&&e[s].indexOf(t)!==-1}removeEventListener(s,t){const i=this._listeners[s];if(i!==void 0){const n=i.indexOf(t);n!==-1&&i.splice(n,1)}}removeAllEventListeners(s){if(!s){this._listeners={};return}Array.isArray(this._listeners[s])&&(this._listeners[s].length=0)}dispatchEvent(s){const e=this._listeners[s.type];if(e!==void 0){s.target=this;const i=e.slice(0);for(let n=0,r=i.length;n<r;n++)i[n].call(this,s)}}}const Na="2.7.3",ks=1/8,br=typeof window<"u",ba=br&&/Mac/.test(navigator.platform),Pa=!(br&&"PointerEvent"in window);let ct,Jn,Gs,Wi,Ut,ht,pt,Ge,os,te,ee,Ae,tr,er,Gt,as,Ye,sr,Xi,ir,Zi,$i,Ys;class xt extends Oa{static install(s){ct=s.THREE,Jn=Object.freeze(new ct.Vector3(0,0,0)),Gs=Object.freeze(new ct.Vector3(0,1,0)),Wi=Object.freeze(new ct.Vector3(0,0,1)),Ut=new ct.Vector2,ht=new ct.Vector3,pt=new ct.Vector3,Ge=new ct.Vector3,os=new ct.Vector3,te=new ct.Vector3,ee=new ct.Vector3,Ae=new ct.Vector3,tr=new ct.Vector3,er=new ct.Vector3,Gt=new ct.Spherical,as=new ct.Spherical,Ye=new ct.Box3,sr=new ct.Box3,Xi=new ct.Sphere,ir=new ct.Quaternion,Zi=new ct.Quaternion,$i=new ct.Matrix4,Ys=new ct.Raycaster}static get ACTION(){return H}constructor(s,t){super(),this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=Number.EPSILON,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.dollyDragInverted=!1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.verticalDragToForward=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=H.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=Ve.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new ct.Vector3,this._focalOffsetVelocity=new ct.Vector3,this._zoomVelocity={value:0},this._truckInternal=(g,y,w)=>{let O,M;if(_e(this._camera)){const b=ht.copy(this._camera.position).sub(this._target),v=this._camera.getEffectiveFOV()*is,k=b.length()*Math.tan(v*.5);O=this.truckSpeed*g*k/this._elementRect.height,M=this.truckSpeed*y*k/this._elementRect.height}else if(fe(this._camera)){const b=this._camera;O=g*(b.right-b.left)/b.zoom/this._elementRect.width,M=y*(b.top-b.bottom)/b.zoom/this._elementRect.height}else return;this.verticalDragToForward?(w?this.setFocalOffset(this._focalOffsetEnd.x+O,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(O,0,!0),this.forward(-M,!0)):w?this.setFocalOffset(this._focalOffsetEnd.x+O,this._focalOffsetEnd.y+M,this._focalOffsetEnd.z,!0):this.truck(O,M,!0)},this._rotateInternal=(g,y)=>{const w=ke*this.azimuthRotateSpeed*g/this._elementRect.height,O=ke*this.polarRotateSpeed*y/this._elementRect.height;this.rotate(w,O,!0)},this._dollyInternal=(g,y,w)=>{const O=Math.pow(.95,-g*this.dollySpeed),M=this._sphericalEnd.radius,b=this._sphericalEnd.radius*O,v=jt(b,this.minDistance,this.maxDistance),k=v-b;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(b,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(k,!0),this._dollyToNoClamp(v,!0)):this._dollyToNoClamp(v,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?b:v)-M,this._dollyControlCoord.set(y,w)),this._lastDollyDirection=Math.sign(-g)},this._zoomInternal=(g,y,w)=>{const O=Math.pow(.95,g*this.dollySpeed),M=this._zoom,b=this._zoom*O;this.zoomTo(b,!0),this.dollyToCursor&&(this._changedZoom+=b-M,this._dollyControlCoord.set(y,w))},typeof ct>"u"&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=s,this._yAxisUpSpace=new ct.Quaternion().setFromUnitVectors(this._camera.up,Gs),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=H.NONE,this._target=new ct.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new ct.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new ct.Spherical().setFromVector3(ht.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 ct.Vector3,new ct.Vector3,new ct.Vector3,new ct.Vector3],this._updateNearPlaneCorners(),this._boundary=new ct.Box3(new ct.Vector3(-1/0,-1/0,-1/0),new ct.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 ct.Vector2,this.mouseButtons={left:H.ROTATE,middle:H.DOLLY,right:H.TRUCK,wheel:_e(this._camera)?H.DOLLY:fe(this._camera)?H.ZOOM:H.NONE},this.touches={one:H.TOUCH_ROTATE,two:_e(this._camera)?H.TOUCH_DOLLY_TRUCK:fe(this._camera)?H.TOUCH_ZOOM_TRUCK:H.NONE,three:H.TOUCH_TRUCK};const e=new ct.Vector2,i=new ct.Vector2,n=new ct.Vector2,r=g=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const O=this._domElement.getBoundingClientRect(),M=g.clientX/O.width,b=g.clientY/O.height;if(M<this._interactiveArea.left||M>this._interactiveArea.right||b<this._interactiveArea.top||b>this._interactiveArea.bottom)return}const y=g.pointerType!=="mouse"?null:(g.buttons&lt.LEFT)===lt.LEFT?lt.LEFT:(g.buttons&lt.MIDDLE)===lt.MIDDLE?lt.MIDDLE:(g.buttons&lt.RIGHT)===lt.RIGHT?lt.RIGHT:null;if(y!==null){const O=this._findPointerByMouseButton(y);O&&this._disposePointer(O)}if((g.buttons&lt.LEFT)===lt.LEFT&&this._lockedPointer)return;const w={pointerId:g.pointerId,clientX:g.clientX,clientY:g.clientY,deltaX:0,deltaY:0,mouseButton:y};this._activePointers.push(w),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",h),this._isDragging=!0,p(g)},o=g=>{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 O=this._domElement.getBoundingClientRect(),M=g.clientX/O.width,b=g.clientY/O.height;if(M<this._interactiveArea.left||M>this._interactiveArea.right||b<this._interactiveArea.top||b>this._interactiveArea.bottom)return}const y=(g.buttons&lt.LEFT)===lt.LEFT?lt.LEFT:(g.buttons&lt.MIDDLE)===lt.MIDDLE?lt.MIDDLE:(g.buttons&lt.RIGHT)===lt.RIGHT?lt.RIGHT:null;if(y!==null){const O=this._findPointerByMouseButton(y);O&&this._disposePointer(O)}const w={pointerId:1,clientX:g.clientX,clientY:g.clientY,deltaX:0,deltaY:0,mouseButton:(g.buttons&lt.LEFT)===lt.LEFT?lt.LEFT:(g.buttons&lt.MIDDLE)===lt.LEFT?lt.MIDDLE:(g.buttons&lt.RIGHT)===lt.LEFT?lt.RIGHT:null};this._activePointers.push(w),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("mouseup",d),this._domElement.ownerDocument.addEventListener("mousemove",l),this._domElement.ownerDocument.addEventListener("mouseup",d),this._isDragging=!0,p(g)},a=g=>{g.cancelable&&g.preventDefault();const y=g.pointerId,w=this._lockedPointer||this._findPointerById(y);if(w){if(w.clientX=g.clientX,w.clientY=g.clientY,w.deltaX=g.movementX,w.deltaY=g.movementY,this._state=0,g.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&&(g.buttons&lt.LEFT)===lt.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(g.buttons&lt.MIDDLE)===lt.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(g.buttons&lt.RIGHT)===lt.RIGHT&&(this._state=this._state|this.mouseButtons.right);I()}},l=g=>{const y=this._lockedPointer||this._findPointerById(1);y&&(y.clientX=g.clientX,y.clientY=g.clientY,y.deltaX=g.movementX,y.deltaY=g.movementY,this._state=0,(this._lockedPointer||(g.buttons&lt.LEFT)===lt.LEFT)&&(this._state=this._state|this.mouseButtons.left),(g.buttons&lt.MIDDLE)===lt.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(g.buttons&lt.RIGHT)===lt.RIGHT&&(this._state=this._state|this.mouseButtons.right),I())},h=g=>{const y=this._findPointerById(g.pointerId);if(!(y&&y===this._lockedPointer)){if(y&&this._disposePointer(y),g.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=H.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=H.NONE;m()}},d=()=>{const g=this._findPointerById(1);g&&g===this._lockedPointer||(g&&this._disposePointer(g),this._state=H.NONE,m())};let u=-1;const f=g=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===H.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const b=this._domElement.getBoundingClientRect(),v=g.clientX/b.width,k=g.clientY/b.height;if(v<this._interactiveArea.left||v>this._interactiveArea.right||k<this._interactiveArea.top||k>this._interactiveArea.bottom)return}if(g.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===H.ROTATE||this.mouseButtons.wheel===H.TRUCK){const b=performance.now();u-b<1e3&&this._getClientRect(this._elementRect),u=b}const y=ba?-1:-3,w=g.deltaMode===1?g.deltaY/y:g.deltaY/(y*10),O=this.dollyToCursor?(g.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,M=this.dollyToCursor?(g.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case H.ROTATE:{this._rotateInternal(g.deltaX,g.deltaY),this._isUserControllingRotate=!0;break}case H.TRUCK:{this._truckInternal(g.deltaX,g.deltaY,!1),this._isUserControllingTruck=!0;break}case H.OFFSET:{this._truckInternal(g.deltaX,g.deltaY,!0),this._isUserControllingOffset=!0;break}case H.DOLLY:{this._dollyInternal(-w,O,M),this._isUserControllingDolly=!0;break}case H.ZOOM:{this._zoomInternal(-w,O,M),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},E=g=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===xt.ACTION.NONE){const y=g instanceof PointerEvent?g.pointerId:(g instanceof MouseEvent,0),w=this._findPointerById(y);w&&this._disposePointer(w),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("mouseup",d);return}g.preventDefault()}},p=g=>{if(!this._enabled)return;if(Yi(this._activePointers,Ut),this._getClientRect(this._elementRect),e.copy(Ut),i.copy(Ut),this._activePointers.length>=2){const w=Ut.x-this._activePointers[1].clientX,O=Ut.y-this._activePointers[1].clientY,M=Math.sqrt(w*w+O*O);n.set(0,M);const b=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,v=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;i.set(b,v)}if(this._state=0,!g)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in g&&g.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&&(g.buttons&lt.LEFT)===lt.LEFT&&(this._state=this._state|this.mouseButtons.left),(g.buttons&lt.MIDDLE)===lt.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(g.buttons&lt.RIGHT)===lt.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&H.ROTATE)===H.ROTATE||(this._state&H.TOUCH_ROTATE)===H.TOUCH_ROTATE||(this._state&H.TOUCH_DOLLY_ROTATE)===H.TOUCH_DOLLY_ROTATE||(this._state&H.TOUCH_ZOOM_ROTATE)===H.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&H.TRUCK)===H.TRUCK||(this._state&H.TOUCH_TRUCK)===H.TOUCH_TRUCK||(this._state&H.TOUCH_DOLLY_TRUCK)===H.TOUCH_DOLLY_TRUCK||(this._state&H.TOUCH_ZOOM_TRUCK)===H.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&H.DOLLY)===H.DOLLY||(this._state&H.TOUCH_DOLLY)===H.TOUCH_DOLLY||(this._state&H.TOUCH_DOLLY_TRUCK)===H.TOUCH_DOLLY_TRUCK||(this._state&H.TOUCH_DOLLY_OFFSET)===H.TOUCH_DOLLY_OFFSET||(this._state&H.TOUCH_DOLLY_ROTATE)===H.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&H.ZOOM)===H.ZOOM||(this._state&H.TOUCH_ZOOM)===H.TOUCH_ZOOM||(this._state&H.TOUCH_ZOOM_TRUCK)===H.TOUCH_ZOOM_TRUCK||(this._state&H.TOUCH_ZOOM_OFFSET)===H.TOUCH_ZOOM_OFFSET||(this._state&H.TOUCH_ZOOM_ROTATE)===H.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&H.OFFSET)===H.OFFSET||(this._state&H.TOUCH_OFFSET)===H.TOUCH_OFFSET||(this._state&H.TOUCH_DOLLY_OFFSET)===H.TOUCH_DOLLY_OFFSET||(this._state&H.TOUCH_ZOOM_OFFSET)===H.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},I=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,Yi(this._activePointers,Ut);const y=this._domElement&&document.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,w=y?-y.deltaX:i.x-Ut.x,O=y?-y.deltaY:i.y-Ut.y;if(i.copy(Ut),((this._state&H.ROTATE)===H.ROTATE||(this._state&H.TOUCH_ROTATE)===H.TOUCH_ROTATE||(this._state&H.TOUCH_DOLLY_ROTATE)===H.TOUCH_DOLLY_ROTATE||(this._state&H.TOUCH_ZOOM_ROTATE)===H.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(w,O),this._isUserControllingRotate=!0),(this._state&H.DOLLY)===H.DOLLY||(this._state&H.ZOOM)===H.ZOOM){const M=this.dollyToCursor?(e.x-this._elementRect.x)/this._elementRect.width*2-1:0,b=this.dollyToCursor?(e.y-this._elementRect.y)/this._elementRect.height*-2+1:0,v=this.dollyDragInverted?-1:1;(this._state&H.DOLLY)===H.DOLLY?(this._dollyInternal(v*O*ks,M,b),this._isUserControllingDolly=!0):(this._zoomInternal(v*O*ks,M,b),this._isUserControllingZoom=!0)}if((this._state&H.TOUCH_DOLLY)===H.TOUCH_DOLLY||(this._state&H.TOUCH_ZOOM)===H.TOUCH_ZOOM||(this._state&H.TOUCH_DOLLY_TRUCK)===H.TOUCH_DOLLY_TRUCK||(this._state&H.TOUCH_ZOOM_TRUCK)===H.TOUCH_ZOOM_TRUCK||(this._state&H.TOUCH_DOLLY_OFFSET)===H.TOUCH_DOLLY_OFFSET||(this._state&H.TOUCH_ZOOM_OFFSET)===H.TOUCH_ZOOM_OFFSET||(this._state&H.TOUCH_DOLLY_ROTATE)===H.TOUCH_DOLLY_ROTATE||(this._state&H.TOUCH_ZOOM_ROTATE)===H.TOUCH_ZOOM_ROTATE){const M=Ut.x-this._activePointers[1].clientX,b=Ut.y-this._activePointers[1].clientY,v=Math.sqrt(M*M+b*b),k=n.y-v;n.set(0,v);const F=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&H.TOUCH_DOLLY)===H.TOUCH_DOLLY||(this._state&H.TOUCH_DOLLY_ROTATE)===H.TOUCH_DOLLY_ROTATE||(this._state&H.TOUCH_DOLLY_TRUCK)===H.TOUCH_DOLLY_TRUCK||(this._state&H.TOUCH_DOLLY_OFFSET)===H.TOUCH_DOLLY_OFFSET?(this._dollyInternal(k*ks,F,L),this._isUserControllingDolly=!0):(this._zoomInternal(k*ks,F,L),this._isUserControllingZoom=!0)}((this._state&H.TRUCK)===H.TRUCK||(this._state&H.TOUCH_TRUCK)===H.TOUCH_TRUCK||(this._state&H.TOUCH_DOLLY_TRUCK)===H.TOUCH_DOLLY_TRUCK||(this._state&H.TOUCH_ZOOM_TRUCK)===H.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(w,O,!1),this._isUserControllingTruck=!0),((this._state&H.OFFSET)===H.OFFSET||(this._state&H.TOUCH_OFFSET)===H.TOUCH_OFFSET||(this._state&H.TOUCH_DOLLY_OFFSET)===H.TOUCH_DOLLY_OFFSET||(this._state&H.TOUCH_ZOOM_OFFSET)===H.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(w,O,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},m=()=>{Yi(this._activePointers,Ut),i.copy(Ut),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",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.removeEventListener("mouseup",d),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",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",C),this._domElement.ownerDocument.addEventListener("pointerlockerror",R),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",h),p())},this.unlockPointer=()=>{this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),document.exitPointerLock(),this.cancel(),this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointerlockchange",C),this._domElement.ownerDocument.removeEventListener("pointerlockerror",R))};const C=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},R=()=>{this.unlockPointer()};this._addAllEventListeners=g=>{this._domElement=g,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",r),Pa&&this._domElement.addEventListener("mousedown",o),this._domElement.addEventListener("pointercancel",h),this._domElement.addEventListener("wheel",f,{passive:!1}),this._domElement.addEventListener("contextmenu",E)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",r),this._domElement.removeEventListener("mousedown",o),this._domElement.removeEventListener("pointercancel",h),this._domElement.removeEventListener("wheel",f,{passive:!1}),this._domElement.removeEventListener("contextmenu",E),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("mousemove",l),this._domElement.ownerDocument.removeEventListener("pointerup",h),this._domElement.ownerDocument.removeEventListener("mouseup",d),this._domElement.ownerDocument.removeEventListener("pointerlockchange",C),this._domElement.ownerDocument.removeEventListener("pointerlockerror",R))},this.cancel=()=>{this._state!==H.NONE&&(this._state=H.NONE,this._activePointers.length=0,m())},t&&this.connect(t),this.update(0)}get camera(){return this._camera}set camera(s){this._camera=s,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(s){this._enabled=s,this._domElement&&(s?(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(s){this._spherical.radius===s&&this._sphericalEnd.radius===s||(this._spherical.radius=s,this._sphericalEnd.radius=s,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(s){this._spherical.theta===s&&this._sphericalEnd.theta===s||(this._spherical.theta=s,this._sphericalEnd.theta=s,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(s){this._spherical.phi===s&&this._sphericalEnd.phi===s||(this._spherical.phi=s,this._sphericalEnd.phi=s,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(s){this._boundaryEnclosesCamera=s,this._needsUpdate=!0}set interactiveArea(s){this._interactiveArea.width=jt(s.width,0,1),this._interactiveArea.height=jt(s.height,0,1),this._interactiveArea.x=jt(s.x,0,1-this._interactiveArea.width),this._interactiveArea.y=jt(s.y,0,1-this._interactiveArea.height)}addEventListener(s,t){super.addEventListener(s,t)}removeEventListener(s,t){super.removeEventListener(s,t)}rotate(s,t,e=!1){return this.rotateTo(this._sphericalEnd.theta+s,this._sphericalEnd.phi+t,e)}rotateAzimuthTo(s,t=!1){return this.rotateTo(s,this._sphericalEnd.phi,t)}rotatePolarTo(s,t=!1){return this.rotateTo(this._sphericalEnd.theta,s,t)}rotateTo(s,t,e=!1){this._isUserControllingRotate=!1;const i=jt(s,this.minAzimuthAngle,this.maxAzimuthAngle),n=jt(t,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=i,this._sphericalEnd.phi=n,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,e||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const r=!e||Et(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Et(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(r)}dolly(s,t=!1){return this.dollyTo(this._sphericalEnd.radius-s,t)}dollyTo(s,t=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Ve.NONE,this._changedDolly=0,this._dollyToNoClamp(jt(s,this.minDistance,this.maxDistance),t)}_dollyToNoClamp(s,t=!1){const e=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const r=this._collisionTest(),o=Et(r,this._spherical.radius);if(!(e>s)&&o)return Promise.resolve();this._sphericalEnd.radius=Math.min(s,r)}else this._sphericalEnd.radius=s;this._needsUpdate=!0,t||(this._spherical.radius=this._sphericalEnd.radius);const n=!t||Et(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(n)}dollyInFixed(s,t=!1){this._targetEnd.add(this._getCameraDirection(os).multiplyScalar(s)),t||this._target.copy(this._targetEnd);const e=!t||Et(this._target.x,this._targetEnd.x,this.restThreshold)&&Et(this._target.y,this._targetEnd.y,this.restThreshold)&&Et(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(e)}zoom(s,t=!1){return this.zoomTo(this._zoomEnd+s,t)}zoomTo(s,t=!1){this._isUserControllingZoom=!1,this._zoomEnd=jt(s,this.minZoom,this.maxZoom),this._needsUpdate=!0,t||(this._zoom=this._zoomEnd);const e=!t||Et(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(e)}pan(s,t,e=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(s,t,e)}truck(s,t,e=!1){this._camera.updateMatrix(),te.setFromMatrixColumn(this._camera.matrix,0),ee.setFromMatrixColumn(this._camera.matrix,1),te.multiplyScalar(s),ee.multiplyScalar(-t);const i=ht.copy(te).add(ee),n=pt.copy(this._targetEnd).add(i);return this.moveTo(n.x,n.y,n.z,e)}forward(s,t=!1){ht.setFromMatrixColumn(this._camera.matrix,0),ht.crossVectors(this._camera.up,ht),ht.multiplyScalar(s);const e=pt.copy(this._targetEnd).add(ht);return this.moveTo(e.x,e.y,e.z,t)}elevate(s,t=!1){return ht.copy(this._camera.up).multiplyScalar(s),this.moveTo(this._targetEnd.x+ht.x,this._targetEnd.y+ht.y,this._targetEnd.z+ht.z,t)}moveTo(s,t,e,i=!1){this._isUserControllingTruck=!1;const n=ht.set(s,t,e).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,n,this.boundaryFriction),this._needsUpdate=!0,i||this._target.copy(this._targetEnd);const r=!i||Et(this._target.x,this._targetEnd.x,this.restThreshold)&&Et(this._target.y,this._targetEnd.y,this.restThreshold)&&Et(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}lookInDirectionOf(s,t,e,i=!1){const o=ht.set(s,t,e).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius);return this.setPosition(o.x,o.y,o.z,i)}fitToBox(s,t,{cover:e=!1,paddingLeft:i=0,paddingRight:n=0,paddingBottom:r=0,paddingTop:o=0}={}){const a=[],l=s.isBox3?Ye.copy(s):Ye.setFromObject(s);l.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const h=qn(this._sphericalEnd.theta,Qn),d=qn(this._sphericalEnd.phi,Qn);a.push(this.rotateTo(h,d,t));const u=ht.setFromSpherical(this._sphericalEnd).normalize(),f=ir.setFromUnitVectors(u,Wi),E=Et(Math.abs(u.y),1);E&&f.multiply(Zi.setFromAxisAngle(Gs,h)),f.multiply(this._yAxisUpSpaceInverse);const p=sr.makeEmpty();pt.copy(l.min).applyQuaternion(f),p.expandByPoint(pt),pt.copy(l.min).setX(l.max.x).applyQuaternion(f),p.expandByPoint(pt),pt.copy(l.min).setY(l.max.y).applyQuaternion(f),p.expandByPoint(pt),pt.copy(l.max).setZ(l.min.z).applyQuaternion(f),p.expandByPoint(pt),pt.copy(l.min).setZ(l.max.z).applyQuaternion(f),p.expandByPoint(pt),pt.copy(l.max).setY(l.min.y).applyQuaternion(f),p.expandByPoint(pt),pt.copy(l.max).setX(l.min.x).applyQuaternion(f),p.expandByPoint(pt),pt.copy(l.max).applyQuaternion(f),p.expandByPoint(pt),p.min.x-=i,p.min.y-=r,p.max.x+=n,p.max.y+=o,f.setFromUnitVectors(Wi,u),E&&f.premultiply(Zi.invert()),f.premultiply(this._yAxisUpSpace);const I=p.getSize(ht),m=p.getCenter(pt).applyQuaternion(f);if(_e(this._camera)){const C=this.getDistanceToFitBox(I.x,I.y,I.z,e);a.push(this.moveTo(m.x,m.y,m.z,t)),a.push(this.dollyTo(C,t)),a.push(this.setFocalOffset(0,0,0,t))}else if(fe(this._camera)){const C=this._camera,R=C.right-C.left,g=C.top-C.bottom,y=e?Math.max(R/I.x,g/I.y):Math.min(R/I.x,g/I.y);a.push(this.moveTo(m.x,m.y,m.z,t)),a.push(this.zoomTo(y,t)),a.push(this.setFocalOffset(0,0,0,t))}return Promise.all(a)}fitToSphere(s,t){const e=[],n=s instanceof ct.Sphere?Xi.copy(s):xt.createBoundingSphere(s,Xi);if(e.push(this.moveTo(n.center.x,n.center.y,n.center.z,t)),_e(this._camera)){const r=this.getDistanceToFitSphere(n.radius);e.push(this.dollyTo(r,t))}else if(fe(this._camera)){const r=this._camera.right-this._camera.left,o=this._camera.top-this._camera.bottom,a=2*n.radius,l=Math.min(r/a,o/a);e.push(this.zoomTo(l,t))}return e.push(this.setFocalOffset(0,0,0,t)),Promise.all(e)}setLookAt(s,t,e,i,n,r,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Ve.NONE,this._changedDolly=0;const a=pt.set(i,n,r),l=ht.set(s,t,e);this._targetEnd.copy(a),this._sphericalEnd.setFromVector3(l.sub(a).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,o||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const h=!o||Et(this._target.x,this._targetEnd.x,this.restThreshold)&&Et(this._target.y,this._targetEnd.y,this.restThreshold)&&Et(this._target.z,this._targetEnd.z,this.restThreshold)&&Et(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Et(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&Et(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(h)}lerpLookAt(s,t,e,i,n,r,o,a,l,h,d,u,f,E=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Ve.NONE,this._changedDolly=0;const p=ht.set(i,n,r),I=pt.set(s,t,e);Gt.setFromVector3(I.sub(p).applyQuaternion(this._yAxisUpSpace));const m=Ge.set(h,d,u),C=pt.set(o,a,l);as.setFromVector3(C.sub(m).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(p.lerp(m,f));const R=as.theta-Gt.theta,g=as.phi-Gt.phi,y=as.radius-Gt.radius;this._sphericalEnd.set(Gt.radius+y*f,Gt.phi+g*f,Gt.theta+R*f),this.normalizeRotations(),this._needsUpdate=!0,E||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const w=!E||Et(this._target.x,this._targetEnd.x,this.restThreshold)&&Et(this._target.y,this._targetEnd.y,this.restThreshold)&&Et(this._target.z,this._targetEnd.z,this.restThreshold)&&Et(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Et(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&Et(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(w)}setPosition(s,t,e,i=!1){return this.setLookAt(s,t,e,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,i)}setTarget(s,t,e,i=!1){const n=this.getPosition(ht),r=this.setLookAt(n.x,n.y,n.z,s,t,e,i);return this._sphericalEnd.phi=jt(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),r}setFocalOffset(s,t,e,i=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(s,t,e),this._needsUpdate=!0,i||this._focalOffset.copy(this._focalOffsetEnd);const n=!i||Et(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&Et(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&Et(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}setOrbitPoint(s,t,e){this._camera.updateMatrixWorld(),te.setFromMatrixColumn(this._camera.matrixWorldInverse,0),ee.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Ae.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const i=ht.set(s,t,e),n=i.distanceTo(this._camera.position),r=i.sub(this._camera.position);te.multiplyScalar(r.x),ee.multiplyScalar(r.y),Ae.multiplyScalar(r.z),ht.copy(te).add(ee).add(Ae),ht.z=ht.z+n,this.dollyTo(n,!1),this.setFocalOffset(-ht.x,ht.y,-ht.z,!1),this.moveTo(s,t,e,!1)}setBoundary(s){if(!s){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(s),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(s,t,e,i){if(s===null){this._viewport=null;return}this._viewport=this._viewport||new ct.Vector4,typeof s=="number"?this._viewport.set(s,t,e,i):this._viewport.copy(s)}getDistanceToFitBox(s,t,e,i=!1){if(Hi(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const n=s/t,r=this._camera.getEffectiveFOV()*is,o=this._camera.aspect;return((i?n>o:n<o)?t:s/o)*.5/Math.tan(r*.5)+e*.5}getDistanceToFitSphere(s){if(Hi(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const t=this._camera.getEffectiveFOV()*is,e=Math.atan(Math.tan(t*.5)*this._camera.aspect)*2,i=1<this._camera.aspect?t:e;return s/Math.sin(i*.5)}getTarget(s,t=!0){return(s&&s.isVector3?s:new ct.Vector3).copy(t?this._targetEnd:this._target)}getPosition(s,t=!0){return(s&&s.isVector3?s:new ct.Vector3).setFromSpherical(t?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(t?this._targetEnd:this._target)}getSpherical(s,t=!0){return(s&&s instanceof ct.Spherical?s:new ct.Spherical).copy(t?this._sphericalEnd:this._spherical)}getFocalOffset(s,t=!0){return(s&&s.isVector3?s:new ct.Vector3).copy(t?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%ke,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=ke),this._spherical.theta+=ke*Math.round((this._sphericalEnd.theta-this._spherical.theta)/ke)}reset(s=!1){if(!Et(this._camera.up.x,this._cameraUp0.x)||!Et(this._camera.up.y,this._cameraUp0.y)||!Et(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const e=this.getPosition(ht);this.updateCameraUp(),this.setPosition(e.x,e.y,e.z)}const t=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,s),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,s),this.zoomTo(this._zoom0,s)];return Promise.all(t)}saveState(){this._cameraUp0.copy(this._camera.up),this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,Gs),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const s=ht.subVectors(this._target,this._camera.position).normalize(),t=pt.crossVectors(s,this._camera.up);this._camera.up.crossVectors(t,s).normalize(),this._camera.updateMatrixWorld();const e=this.getPosition(ht);this.updateCameraUp(),this.setPosition(e.x,e.y,e.z)}update(s){const t=this._sphericalEnd.theta-this._spherical.theta,e=this._sphericalEnd.phi-this._spherical.phi,i=this._sphericalEnd.radius-this._spherical.radius,n=tr.subVectors(this._targetEnd,this._target),r=er.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(Tt(t))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const d=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=Vs(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,d,1/0,s),this._needsUpdate=!0}if(Tt(e))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const d=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=Vs(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,d,1/0,s),this._needsUpdate=!0}if(Tt(i))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const d=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=Vs(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,d,this.maxSpeed,s),this._needsUpdate=!0}if(Tt(n.x)&&Tt(n.y)&&Tt(n.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const d=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Kn(this._target,this._targetEnd,this._targetVelocity,d,this.maxSpeed,s,this._target),this._needsUpdate=!0}if(Tt(r.x)&&Tt(r.y)&&Tt(r.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const d=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Kn(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,d,this.maxSpeed,s,this._focalOffset),this._needsUpdate=!0}if(Tt(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const d=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=Vs(this._zoom,this._zoomEnd,this._zoomVelocity,d,1/0,s)}if(this.dollyToCursor){if(_e(this._camera)&&this._changedDolly!==0){const d=this._spherical.radius-this._lastDistance,u=this._camera,f=this._getCameraDirection(os),E=ht.copy(f).cross(u.up).normalize();E.lengthSq()===0&&(E.x=1);const p=pt.crossVectors(E,f),I=this._sphericalEnd.radius*Math.tan(u.getEffectiveFOV()*is*.5),C=(this._sphericalEnd.radius-d-this._sphericalEnd.radius)/this._sphericalEnd.radius,R=Ge.copy(this._targetEnd).add(E.multiplyScalar(this._dollyControlCoord.x*I*u.aspect)).add(p.multiplyScalar(this._dollyControlCoord.y*I)),g=ht.copy(this._targetEnd).lerp(R,C),y=this._lastDollyDirection===Ve.IN&&this._spherical.radius<=this.minDistance,w=this._lastDollyDirection===Ve.OUT&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(y||w)){this._sphericalEnd.radius-=d,this._spherical.radius-=d;const M=pt.copy(f).multiplyScalar(-d);g.add(M)}this._boundary.clampPoint(g,g);const O=pt.subVectors(g,this._targetEnd);this._targetEnd.copy(g),this._target.add(O),this._changedDolly-=d,Tt(this._changedDolly)&&(this._changedDolly=0)}else if(fe(this._camera)&&this._changedZoom!==0){const d=this._zoom-this._lastZoom,u=this._camera,f=ht.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(u.near+u.far)/(u.near-u.far)).unproject(u),E=pt.set(0,0,-1).applyQuaternion(u.quaternion),p=Ge.copy(f).add(E.multiplyScalar(-f.dot(u.up))),m=-(this._zoom-d-this._zoom)/this._zoom,C=this._getCameraDirection(os),R=this._targetEnd.dot(C),g=ht.copy(this._targetEnd).lerp(p,m),y=g.dot(C),w=C.multiplyScalar(y-R);g.sub(w),this._boundary.clampPoint(g,g);const O=pt.subVectors(g,this._targetEnd);this._targetEnd.copy(g),this._target.add(O),this._changedZoom-=d,Tt(this._changedZoom)&&(this._changedZoom=0)}}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0),this._dragNeedsUpdate=!0;const a=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,a),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!Tt(this._focalOffset.x)||!Tt(this._focalOffset.y)||!Tt(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),te.setFromMatrixColumn(this._camera.matrix,0),ee.setFromMatrixColumn(this._camera.matrix,1),Ae.setFromMatrixColumn(this._camera.matrix,2),te.multiplyScalar(this._focalOffset.x),ee.multiplyScalar(-this._focalOffset.y),Ae.multiplyScalar(this._focalOffset.z),ht.copy(te).add(ee).add(Ae),this._camera.position.add(ht)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),ht.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const h=this._needsUpdate;return h&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):h?(this.dispatchEvent({type:"update"}),Tt(t,this.restThreshold)&&Tt(e,this.restThreshold)&&Tt(i,this.restThreshold)&&Tt(n.x,this.restThreshold)&&Tt(n.y,this.restThreshold)&&Tt(n.z,this.restThreshold)&&Tt(r.x,this.restThreshold)&&Tt(r.y,this.restThreshold)&&Tt(r.z,this.restThreshold)&&Tt(o,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!h&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=h,this._needsUpdate=!1,h}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:ns(this.maxDistance),minZoom:this.minZoom,maxZoom:ns(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:ns(this.maxPolarAngle),minAzimuthAngle:ns(this.minAzimuthAngle),maxAzimuthAngle:ns(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,verticalDragToForward:this.verticalDragToForward,target:this._targetEnd.toArray(),position:ht.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(s,t=!1){const e=JSON.parse(s);this.enabled=e.enabled,this.minDistance=e.minDistance,this.maxDistance=rs(e.maxDistance),this.minZoom=e.minZoom,this.maxZoom=rs(e.maxZoom),this.minPolarAngle=e.minPolarAngle,this.maxPolarAngle=rs(e.maxPolarAngle),this.minAzimuthAngle=rs(e.minAzimuthAngle),this.maxAzimuthAngle=rs(e.maxAzimuthAngle),this.smoothTime=e.smoothTime,this.draggingSmoothTime=e.draggingSmoothTime,this.dollySpeed=e.dollySpeed,this.truckSpeed=e.truckSpeed,this.dollyToCursor=e.dollyToCursor,this.verticalDragToForward=e.verticalDragToForward,this._target0.fromArray(e.target0),this._position0.fromArray(e.position0),this._zoom0=e.zoom0,this._focalOffset0.fromArray(e.focalOffset0),this.moveTo(e.target[0],e.target[1],e.target[2],t),Gt.setFromVector3(ht.fromArray(e.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(Gt.theta,Gt.phi,t),this.dollyTo(Gt.radius,t),this.zoomTo(e.zoom,t),this.setFocalOffset(e.focalOffset[0],e.focalOffset[1],e.focalOffset[2],t),this._needsUpdate=!0}connect(s){if(this._domElement){console.warn("camera-controls is already connected.");return}s.setAttribute("data-camera-controls-version",Na),this._addAllEventListeners(s),this._getClientRect(this._elementRect)}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement.removeAttribute("data-camera-controls-version"),this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_getTargetDirection(s){return s.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse)}_getCameraDirection(s){return this._getTargetDirection(s).negate()}_findPointerById(s){return this._activePointers.find(t=>t.pointerId===s)}_findPointerByMouseButton(s){return this._activePointers.find(t=>t.mouseButton===s)}_disposePointer(s){this._activePointers.splice(this._activePointers.indexOf(s),1)}_encloseToBoundary(s,t,e){const i=t.lengthSq();if(i===0)return s;const n=pt.copy(t).add(s),o=this._boundary.clampPoint(n,Ge).sub(n),a=o.lengthSq();if(a===0)return s.add(t);if(a===i)return s;if(e===0)return s.add(t).add(o);{const l=1+e*a/t.dot(o);return s.add(pt.copy(t).multiplyScalar(l)).add(o.multiplyScalar(1-e))}}_updateNearPlaneCorners(){if(_e(this._camera)){const s=this._camera,t=s.near,e=s.getEffectiveFOV()*is,i=Math.tan(e*.5)*t,n=i*s.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(fe(this._camera)){const s=this._camera,t=1/s.zoom,e=s.left*t,i=s.right*t,n=s.top*t,r=s.bottom*t;this._nearPlaneCorners[0].set(e,n,0),this._nearPlaneCorners[1].set(i,n,0),this._nearPlaneCorners[2].set(i,r,0),this._nearPlaneCorners[3].set(e,r,0)}}_collisionTest(){let s=1/0;if(!(this.colliderMeshes.length>=1)||Hi(this._camera,"_collisionTest"))return s;const e=this._getTargetDirection(os);$i.lookAt(Jn,e,this._camera.up);for(let i=0;i<4;i++){const n=pt.copy(this._nearPlaneCorners[i]);n.applyMatrix4($i);const r=Ge.addVectors(this._target,n);Ys.set(r,e),Ys.far=this._spherical.radius+1;const o=Ys.intersectObjects(this.colliderMeshes);o.length!==0&&o[0].distance<s&&(s=o[0].distance)}return s}_getClientRect(s){if(!this._domElement)return;const t=this._domElement.getBoundingClientRect();return s.x=t.left,s.y=t.top,this._viewport?(s.x+=this._viewport.x,s.y+=t.height-this._viewport.w-this._viewport.y,s.width=this._viewport.z,s.height=this._viewport.w):(s.width=t.width,s.height=t.height),s}_createOnRestPromise(s){return s?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(t=>{const e=()=>{this.removeEventListener("rest",e),t()};this.addEventListener("rest",e)}))}_addAllEventListeners(s){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(s){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(s){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(s,t=new ct.Sphere){const e=t,i=e.center;Ye.makeEmpty(),s.traverseVisible(r=>{r.isMesh&&Ye.expandByObject(r)}),Ye.getCenter(i);let n=0;return s.traverseVisible(r=>{if(!r.isMesh)return;const o=r,a=o.geometry.clone();a.applyMatrix4(o.matrixWorld);const h=a.attributes.position;for(let d=0,u=h.count;d<u;d++)ht.fromBufferAttribute(h,d),n=Math.max(n,i.distanceToSquared(ht))}),e.radius=Math.sqrt(n),e}}class We extends Ar{constructor(t){super(t);T(this,"onBeforeUpdate",new Q);T(this,"onAfterUpdate",new Q);T(this,"onAspectUpdated",new Q);T(this,"onDisposed",new Q);T(this,"three");T(this,"_allControls",new Map);T(this,"updateAspect",()=>{var t;if(!(!this.currentWorld||!this.currentWorld.renderer)){if(this.three instanceof x.OrthographicCamera){this.onAspectUpdated.trigger();return}if((t=this.currentWorld.renderer)!=null&&t.isResizeable()){const e=this.currentWorld.renderer.getSize();this.three.aspect=e.width/e.height,this.three.updateProjectionMatrix(),this.onAspectUpdated.trigger()}}});this.three=this.setupCamera(),this.setupEvents(!0),this.onWorldChanged.add(({action:e,world:i})=>{if(e==="added"){const n=this.newCameraControls();this._allControls.set(i.uuid,n)}if(e==="removed"){const n=this._allControls.get(i.uuid);n&&(n.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.currentWorld!==null&&(this.controls.enabled=t)}dispose(){this.setupEvents(!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 x.PerspectiveCamera(60,t,1,1e3);return e.position.set(50,50,50),e.lookAt(new x.Vector3(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!");xt.install({THREE:We.getSubsetOfThree()});const{domElement:t}=this.currentWorld.renderer.three,e=new xt(this.three,t);return e.smoothTime=.2,e.dollyToCursor=!0,e.infinityDolly=!0,e.minDistance=6,e}setupEvents(t){t?window.addEventListener("resize",this.updateAspect):window.removeEventListener("resize",this.updateAspect)}static getSubsetOfThree(){return{MOUSE:x.MOUSE,Vector2:x.Vector2,Vector3:x.Vector3,Vector4:x.Vector4,Quaternion:x.Quaternion,Matrix4:x.Matrix4,Spherical:x.Spherical,Box3:x.Box3,Sphere:x.Sphere,Raycaster:x.Raycaster,MathUtils:x.MathUtils}}}const hi=class hi extends Ft{constructor(t){super(t);T(this,"onAfterUpdate",new Q);T(this,"onBeforeUpdate",new Q);T(this,"onDisposed",new Q);T(this,"onWorldCreated",new Q);T(this,"onWorldDeleted",new Q);T(this,"list",new Map);T(this,"enabled",!0);t.add(hi.uuid,this)}create(){const t=new Sr(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),this.onWorldCreated.trigger(t),t}delete(t){if(!this.list.has(t.uuid))throw new Error("The provided world is not found in the list!");const e=t.uuid;this.list.delete(t.uuid),t.dispose(),this.onWorldDeleted.trigger(e)}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,i]of this.list)i.update(t)}};T(hi,"uuid","fdb61dc4-2ec1-4966-b83d-54ea795fad4a");let ti=hi;function La(c,s,t,e){return new Promise((i,n)=>{function r(){const o=c.clientWaitSync(s,t,0);if(o===c.WAIT_FAILED){n();return}if(o===c.TIMEOUT_EXPIRED){setTimeout(r,e);return}i()}r()})}async function Ma(c,s,t,e,i,n,r){const o=c.fenceSync(c.SYNC_GPU_COMMANDS_COMPLETE,0);c.flush(),await La(c,o,0,10),c.deleteSync(o),c.bindBuffer(s,t),c.getBufferSubData(s,e,i,n,r),c.bindBuffer(s,null)}async function Tn(c,s,t,e,i,n,r,o){const a=c.createBuffer();return c.bindBuffer(c.PIXEL_PACK_BUFFER,a),c.bufferData(c.PIXEL_PACK_BUFFER,o.byteLength,c.STREAM_READ),c.readPixels(s,t,e,i,n,r,0),c.bindBuffer(c.PIXEL_PACK_BUFFER,null),await Ma(c,c.PIXEL_PACK_BUFFER,a,0,o),c.deleteBuffer(a),o}class Pr{constructor(s,t,e){T(this,"onDisposed",new Q);T(this,"onViewUpdated",new Es);T(this,"enabled",!0);T(this,"needsUpdate",!1);T(this,"renderDebugFrame",!1);T(this,"components");T(this,"world");T(this,"renderer");T(this,"autoUpdate",!0);T(this,"updateInterval",1e3);T(this,"worker");T(this,"scene",new x.Scene);T(this,"_width",512);T(this,"_height",512);T(this,"_availableColor",1);T(this,"renderTarget");T(this,"bufferSize");T(this,"_buffer");T(this,"_isWorkerBusy",!1);T(this,"updateVisibility",async s=>{if(!this.enabled||!this.needsUpdate&&!s||this._isWorkerBusy)return;this._isWorkerBusy=!0;const t=this.world.camera.three;t.updateMatrix(),this.renderer.setSize(this._width,this._height),this.renderer.setRenderTarget(this.renderTarget),this.renderer.render(this.scene,t);const e=this.renderer.getContext();try{await Tn(e,0,0,this._width,this._height,e.RGBA,e.UNSIGNED_BYTE,this._buffer)}catch{this.needsUpdate=!1,this._isWorkerBusy=!1,this.renderer.setRenderTarget(null);return}this.renderer.setRenderTarget(null),this.renderDebugFrame&&this.renderer.render(this.scene,t),this.worker.postMessage({buffer:this._buffer}),this.needsUpdate=!1});if(!t.renderer)throw new Error("The given world must have a renderer!");this.components=s,this.applySettings(e),this.world=t,this.renderer=new x.WebGLRenderer,this.renderTarget=new x.WebGLRenderTarget(this._width,this._height),this.bufferSize=this._width*this._height*4,this._buffer=new Uint8Array(this.bufferSize),this.renderer.clippingPlanes=t.renderer.clippingPlanes;const i=`
11
11
  addEventListener("message", (event) => {
12
12
  const { buffer } = event.data;
13
13
  const colors = new Map();
@@ -24,7 +24,7 @@
24
24
  }
25
25
  postMessage({ colors });
26
26
  });
27
- `,n=new Blob([i],{type:"application/javascript"});this.worker=new Worker(URL.createObjectURL(n))}dispose(){this.enabled=!1;for(const s of this.scene.children)s.removeFromParent();this.onViewUpdated.reset(),this.worker.terminate(),this.renderer.forceContextLoss(),this.renderer.dispose(),this.renderTarget.dispose(),this._buffer=null,this.onDisposed.reset()}getAvailableColor(){let s=BigInt(this._availableColor.toString());const t=[];do t.unshift(Number(s%256n)),s/=256n;while(s);for(;t.length!==3;)t.unshift(0);const[e,i,n]=t,r=`${e}-${i}-${n}`;return{r:e,g:i,b:n,code:r}}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(s){s&&(s.updateInterval!==void 0&&(this.updateInterval=s.updateInterval),s.height!==void 0&&(this._height=s.height),s.width!==void 0&&(this._width=s.width),s.autoUpdate!==void 0&&(this.autoUpdate=s.autoUpdate))}}class Lr extends Pr{constructor(t,e,i){super(t,e,i);T(this,"onViewUpdated",new Q);T(this,"threshold",100);T(this,"colorMeshes",new Map);T(this,"isProcessing",!1);T(this,"_interval",null);T(this,"_colorCodeMeshMap",new Map);T(this,"_meshIDColorCodeMap",new Map);T(this,"_currentVisibleMeshes",new Set);T(this,"_recentlyHiddenMeshes",new Set);T(this,"_intervalID",null);T(this,"_transparentMat",new x.MeshBasicMaterial({transparent:!0,opacity:0}));T(this,"handleWorkerMessage",async t=>{if(this.isProcessing)return;const e=t.data.colors;this._recentlyHiddenMeshes=new Set(this._currentVisibleMeshes),this._currentVisibleMeshes.clear();for(const[i,n]of e){if(n<this.threshold)continue;const r=this._colorCodeMeshMap.get(i);r&&(this._currentVisibleMeshes.add(r),this._recentlyHiddenMeshes.delete(r))}this.onViewUpdated.trigger({seen:this._currentVisibleMeshes,unseen:this._recentlyHiddenMeshes}),this._isWorkerBusy=!1});this.worker.addEventListener("message",this.handleWorkerMessage),this.autoUpdate&&(this._interval=window.setInterval(async()=>{this.isProcessing||await this.updateVisibility()},this.updateInterval)),this.onViewUpdated.add(({seen:n,unseen:r})=>{for(const o of n)o.visible=!0;for(const o of r)o.visible=!1})}dispose(){super.dispose(),this._intervalID!==null&&(window.clearInterval(this._intervalID),this._intervalID=null),this._interval!==null&&(window.clearInterval(this._interval),this._intervalID=null),this._currentVisibleMeshes.clear(),this._recentlyHiddenMeshes.clear(),this._meshIDColorCodeMap.clear(),this._transparentMat.dispose(),this._colorCodeMeshMap.clear();const t=this.components.get(le);for(const e in this.colorMeshes){const i=this.colorMeshes.get(e);i&&t.destroy(i,!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 x.InstancedMesh,{geometry:i,material:n}=t,{colorMaterial:r,code:o}=this.getAvailableMaterial();let a;if(Array.isArray(n)){let d=!0;const u=[];for(const f of n)an.isTransparent(f)?u.push(this._transparentMat):(d=!1,u.push(r));if(d){r.dispose(),this.isProcessing=!1;return}a=u}else if(an.isTransparent(n)){r.dispose(),this.isProcessing=!1;return}else a=r;this._colorCodeMeshMap.set(o,t),this._meshIDColorCodeMap.set(t.uuid,o);const l=e?t.count:1,h=new x.InstancedMesh(i,a,l);e?h.instanceMatrix=t.instanceMatrix:h.setMatrixAt(0,new x.Matrix4),t.visible=!1,t.updateWorldMatrix(!0,!1),h.applyMatrix4(t.matrixWorld),h.updateMatrix(),this.scene.add(h),this.colorMeshes.set(t.uuid,h),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(le);this._currentVisibleMeshes.delete(t),this._recentlyHiddenMeshes.delete(t);const i=this.colorMeshes.get(t.uuid),n=this._meshIDColorCodeMap.get(t.uuid);if(!i||!n){this.isProcessing=!1;return}this._colorCodeMeshMap.delete(n),this._meshIDColorCodeMap.delete(t.uuid),this.colorMeshes.delete(t.uuid),i.geometry=void 0,i.material=[],e.destroy(i,!0),this._recentlyHiddenMeshes.delete(t),this._currentVisibleMeshes.delete(t),this.isProcessing=!1}updateInstanced(t){for(const e of t){const i=this.colorMeshes.get(e.uuid);i&&(i.count=e.count)}}getAvailableMaterial(){const{r:t,g:e,b:i,code:n}=this.getAvailableColor(),r=x.ColorManagement.enabled;x.ColorManagement.enabled=!1;const o=new x.Color(`rgb(${t}, ${e}, ${i})`);if(!this.world.renderer)throw new Error("Renderer not found in the world!");const a=this.world.renderer.clippingPlanes,l=new x.MeshBasicMaterial({color:o,clippingPlanes:a,side:x.DoubleSide});return x.ColorManagement.enabled=r,{colorMaterial:l,code:n}}}const Is=class Is extends Ft{constructor(t){super(t);T(this,"onDisposed",new Q);T(this,"_enabled",!0);T(this,"list",new Map);t.add(Is.uuid,this)}get enabled(){return this._enabled}set enabled(t){this._enabled=t;for(const[e,i]of this.list)i.enabled=t}create(t,e){if(this.list.has(t.uuid))return this.list.get(t.uuid);const i=new Lr(this.components,t,e);return this.list.set(t.uuid,i),i}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){this.enabled=!1,this.onDisposed.trigger(Is.uuid),this.onDisposed.reset();for(const[t,e]of this.list)e.dispose();this.list.clear()}updateInstanced(t){for(const[,e]of this.list)e.updateInstanced(t)}};T(Is,"uuid","69f2a50d-c266-44fc-b1bd-fa4d34be89e6");let ei=Is;class xa{constructor(s,t){T(this,"onDisposed",new Q);T(this,"onDistanceComputed",new Q);T(this,"excludedObjects",new Set);T(this,"enabled",!0);T(this,"renderDebugFrame",!1);T(this,"components");T(this,"scene",new x.Scene);T(this,"camera",new x.OrthographicCamera(-1,1,1,-1,0,1));T(this,"depthMaterial");T(this,"world");T(this,"renderer");T(this,"worker");T(this,"_width",512);T(this,"_height",512);T(this,"_postQuad");T(this,"tempRT");T(this,"resultRT");T(this,"bufferSize");T(this,"_buffer");T(this,"_isWorkerBusy",!1);T(this,"compute",async()=>{if(!this.enabled||this.world.isDisposing||this._isWorkerBusy)return;this._isWorkerBusy=!0,this.world.camera.three.updateMatrix(),this.renderer.setSize(this._width,this._height),this.renderer.setRenderTarget(this.tempRT);const s="visibilityBeforeDistanceCheck";for(const e of this.excludedObjects)e.userData[s]=e.visible,e.visible=!1;this.renderer.render(this.world.scene.three,this.world.camera.three);for(const e of this.excludedObjects)e.userData[s]!==void 0&&(e.visible=e.userData[s]);this.depthMaterial.uniforms.tDiffuse.value=this.tempRT.texture,this.depthMaterial.uniforms.tDepth.value=this.tempRT.depthTexture,this.renderer.setRenderTarget(this.resultRT),this.renderer.render(this.scene,this.camera);const t=this.renderer.getContext();try{await Tn(t,0,0,this._width,this._height,t.RGBA,t.UNSIGNED_BYTE,this._buffer)}catch{this.renderer.setRenderTarget(null);return}this.renderer.setRenderTarget(null),this.renderDebugFrame&&this.renderer.render(this.scene,this.camera),this.worker.postMessage({buffer:this._buffer})});T(this,"handleWorkerMessage",s=>{if(!this.enabled||this.world.isDisposing)return;const t=s.data.colors;let e=Number.MAX_VALUE;for(const a of t)a!==0&&a<e&&(e=a);const i=this.world.camera.three||x.OrthographicCamera,r=(e/255-1)*-1*(i.far-i.near),o=Math.min(r,i.far);this.onDistanceComputed.trigger(o),this._isWorkerBusy=!1});if(!t.renderer)throw new Error("The given world must have a renderer!");this.components=s,this.world=t;const e=t.camera.three;this.renderer=new x.WebGLRenderer,this.tempRT=new x.WebGLRenderTarget(this._width,this._height),this.bufferSize=this._width*this._height*4,this._buffer=new Uint8Array(this.bufferSize),this.tempRT.texture.minFilter=x.NearestFilter,this.tempRT.texture.magFilter=x.NearestFilter,this.tempRT.stencilBuffer=!1,this.tempRT.samples=0,this.tempRT.depthTexture=new x.DepthTexture(this._width,this._height),this.tempRT.depthTexture.format=x.DepthFormat,this.tempRT.depthTexture.type=x.UnsignedShortType,this.resultRT=new x.WebGLRenderTarget(this._width,this._height),this.depthMaterial=new x.ShaderMaterial({vertexShader:`
27
+ `,n=new Blob([i],{type:"application/javascript"});this.worker=new Worker(URL.createObjectURL(n))}dispose(){this.enabled=!1;for(const s of this.scene.children)s.removeFromParent();this.onViewUpdated.reset(),this.worker.terminate(),this.renderer.forceContextLoss(),this.renderer.dispose(),this.renderTarget.dispose(),this._buffer=null,this.onDisposed.reset()}getAvailableColor(){let s=BigInt(this._availableColor.toString());const t=[];do t.unshift(Number(s%256n)),s/=256n;while(s);for(;t.length!==3;)t.unshift(0);const[e,i,n]=t,r=`${e}-${i}-${n}`;return{r:e,g:i,b:n,code:r}}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(s){s&&(s.updateInterval!==void 0&&(this.updateInterval=s.updateInterval),s.height!==void 0&&(this._height=s.height),s.width!==void 0&&(this._width=s.width),s.autoUpdate!==void 0&&(this.autoUpdate=s.autoUpdate))}}class Lr extends Pr{constructor(t,e,i){super(t,e,i);T(this,"onViewUpdated",new Q);T(this,"threshold",100);T(this,"colorMeshes",new Map);T(this,"isProcessing",!1);T(this,"_interval",null);T(this,"_colorCodeMeshMap",new Map);T(this,"_meshIDColorCodeMap",new Map);T(this,"_currentVisibleMeshes",new Set);T(this,"_recentlyHiddenMeshes",new Set);T(this,"_intervalID",null);T(this,"_transparentMat",new x.MeshBasicMaterial({transparent:!0,opacity:0}));T(this,"handleWorkerMessage",async t=>{if(this.isProcessing)return;const e=t.data.colors;this._recentlyHiddenMeshes=new Set(this._currentVisibleMeshes),this._currentVisibleMeshes.clear();for(const[i,n]of e){if(n<this.threshold)continue;const r=this._colorCodeMeshMap.get(i);r&&(this._currentVisibleMeshes.add(r),this._recentlyHiddenMeshes.delete(r))}this.onViewUpdated.trigger({seen:this._currentVisibleMeshes,unseen:this._recentlyHiddenMeshes}),this._isWorkerBusy=!1});this.worker.addEventListener("message",this.handleWorkerMessage),this.autoUpdate&&(this._interval=window.setInterval(async()=>{this.isProcessing||await this.updateVisibility()},this.updateInterval)),this.onViewUpdated.add(({seen:n,unseen:r})=>{for(const o of n)o.visible=!0;for(const o of r)o.visible=!1})}dispose(){super.dispose(),this._intervalID!==null&&(window.clearInterval(this._intervalID),this._intervalID=null),this._interval!==null&&(window.clearInterval(this._interval),this._intervalID=null),this._currentVisibleMeshes.clear(),this._recentlyHiddenMeshes.clear(),this._meshIDColorCodeMap.clear(),this._transparentMat.dispose(),this._colorCodeMeshMap.clear();const t=this.components.get(le);for(const e in this.colorMeshes){const i=this.colorMeshes.get(e);i&&t.destroy(i,!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 x.InstancedMesh,{geometry:i,material:n}=t,{colorMaterial:r,code:o}=this.getAvailableMaterial();let a;if(Array.isArray(n)){let d=!0;const u=[];for(const f of n)an.isTransparent(f)?u.push(this._transparentMat):(d=!1,u.push(r));if(d){r.dispose(),this.isProcessing=!1;return}a=u}else if(an.isTransparent(n)){r.dispose(),this.isProcessing=!1;return}else a=r;this._colorCodeMeshMap.set(o,t),this._meshIDColorCodeMap.set(t.uuid,o);const l=e?t.count:1,h=new x.InstancedMesh(i,a,l);e?h.instanceMatrix=t.instanceMatrix:h.setMatrixAt(0,new x.Matrix4),t.visible=!1,t.updateWorldMatrix(!0,!1),h.applyMatrix4(t.matrixWorld),h.updateMatrix(),this.scene.add(h),this.colorMeshes.set(t.uuid,h),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(le);this._currentVisibleMeshes.delete(t),this._recentlyHiddenMeshes.delete(t);const i=this.colorMeshes.get(t.uuid),n=this._meshIDColorCodeMap.get(t.uuid);if(!i||!n){this.isProcessing=!1;return}this._colorCodeMeshMap.delete(n),this._meshIDColorCodeMap.delete(t.uuid),this.colorMeshes.delete(t.uuid),i.geometry=void 0,i.material=[],e.destroy(i,!0),this._recentlyHiddenMeshes.delete(t),this._currentVisibleMeshes.delete(t),this.isProcessing=!1}updateInstanced(t){for(const e of t){const i=this.colorMeshes.get(e.uuid);i&&(i.count=e.count)}}getAvailableMaterial(){const{r:t,g:e,b:i,code:n}=this.getAvailableColor(),r=x.ColorManagement.enabled;x.ColorManagement.enabled=!1;const o=new x.Color(`rgb(${t}, ${e}, ${i})`);if(!this.world.renderer)throw new Error("Renderer not found in the world!");const a=this.world.renderer.clippingPlanes,l=new x.MeshBasicMaterial({color:o,clippingPlanes:a,side:x.DoubleSide});return x.ColorManagement.enabled=r,{colorMaterial:l,code:n}}}const Is=class Is extends Ft{constructor(t){super(t);T(this,"onDisposed",new Q);T(this,"_enabled",!0);T(this,"list",new Map);t.add(Is.uuid,this)}get enabled(){return this._enabled}set enabled(t){this._enabled=t;for(const[e,i]of this.list)i.enabled=t}create(t,e){if(this.list.has(t.uuid))return this.list.get(t.uuid);const i=new Lr(this.components,t,e);return this.list.set(t.uuid,i),i}delete(t){const e=this.list.get(t.uuid);e&&e.dispose(),this.list.delete(t.uuid)}dispose(){this.enabled=!1,this.onDisposed.trigger(Is.uuid),this.onDisposed.reset();for(const[t,e]of this.list)e.dispose();this.list.clear()}updateInstanced(t){for(const[,e]of this.list)e.updateInstanced(t)}};T(Is,"uuid","69f2a50d-c266-44fc-b1bd-fa4d34be89e6");let ei=Is;class xa{constructor(s,t){T(this,"onDisposed",new Q);T(this,"onDistanceComputed",new Q);T(this,"excludedObjects",new Set);T(this,"enabled",!0);T(this,"renderDebugFrame",!1);T(this,"components");T(this,"scene",new x.Scene);T(this,"camera",new x.OrthographicCamera(-1,1,1,-1,0,1));T(this,"depthMaterial");T(this,"world");T(this,"renderer");T(this,"worker");T(this,"_width",512);T(this,"_height",512);T(this,"_postQuad");T(this,"tempRT");T(this,"resultRT");T(this,"bufferSize");T(this,"_buffer");T(this,"_isWorkerBusy",!1);T(this,"compute",async()=>{if(!this.enabled||this.world.isDisposing||this._isWorkerBusy)return;this._isWorkerBusy=!0,this.world.camera.three.updateMatrix(),this.renderer.setSize(this._width,this._height),this.renderer.setRenderTarget(this.tempRT);const s="visibilityBeforeDistanceCheck";for(const e of this.excludedObjects)e.userData[s]=e.visible,e.visible=!1;this.renderer.render(this.world.scene.three,this.world.camera.three);for(const e of this.excludedObjects)e.userData[s]!==void 0&&(e.visible=e.userData[s]);this.depthMaterial.uniforms.tDiffuse.value=this.tempRT.texture,this.depthMaterial.uniforms.tDepth.value=this.tempRT.depthTexture,this.renderer.setRenderTarget(this.resultRT),this.renderer.render(this.scene,this.camera);const t=this.renderer.getContext();try{await Tn(t,0,0,this._width,this._height,t.RGBA,t.UNSIGNED_BYTE,this._buffer)}catch{this.renderer.setRenderTarget(null),this._isWorkerBusy=!1;return}this.renderer.setRenderTarget(null),this.renderDebugFrame&&this.renderer.render(this.scene,this.camera),this.worker.postMessage({buffer:this._buffer})});T(this,"handleWorkerMessage",s=>{if(!this.enabled||this.world.isDisposing)return;const t=s.data.colors;let e=Number.MAX_VALUE;for(const a of t)a!==0&&a<e&&(e=a);const i=this.world.camera.three||x.OrthographicCamera,r=(e/255-1)*-1*(i.far-i.near),o=Math.min(r,i.far);this.onDistanceComputed.trigger(o),this._isWorkerBusy=!1});if(!t.renderer)throw new Error("The given world must have a renderer!");this.components=s,this.world=t;const e=t.camera.three;this.renderer=new x.WebGLRenderer,this.tempRT=new x.WebGLRenderTarget(this._width,this._height),this.bufferSize=this._width*this._height*4,this._buffer=new Uint8Array(this.bufferSize),this.tempRT.texture.minFilter=x.NearestFilter,this.tempRT.texture.magFilter=x.NearestFilter,this.tempRT.stencilBuffer=!1,this.tempRT.samples=0,this.tempRT.depthTexture=new x.DepthTexture(this._width,this._height),this.tempRT.depthTexture.format=x.DepthFormat,this.tempRT.depthTexture.type=x.UnsignedShortType,this.resultRT=new x.WebGLRenderTarget(this._width,this._height),this.depthMaterial=new x.ShaderMaterial({vertexShader:`
28
28
  varying vec2 vUv;
29
29
 
30
30
  void main() {
package/dist/index.mjs CHANGED
@@ -3114,7 +3114,7 @@ const di = class di {
3114
3114
  /**
3115
3115
  * The version of the @thatopen/components library.
3116
3116
  */
3117
- T(di, "release", "2.2.7");
3117
+ T(di, "release", "2.2.8");
3118
3118
  let on = di;
3119
3119
  class La extends An {
3120
3120
  constructor() {
@@ -5027,7 +5027,7 @@ class ka {
5027
5027
  this._buffer
5028
5028
  );
5029
5029
  } catch {
5030
- this.renderer.setRenderTarget(null);
5030
+ this.needsUpdate = !1, this._isWorkerBusy = !1, this.renderer.setRenderTarget(null);
5031
5031
  return;
5032
5032
  }
5033
5033
  this.renderer.setRenderTarget(null), this.renderDebugFrame && this.renderer.render(this.scene, t), this.worker.postMessage({
@@ -5400,7 +5400,7 @@ class Ya {
5400
5400
  this._buffer
5401
5401
  );
5402
5402
  } catch {
5403
- this.renderer.setRenderTarget(null);
5403
+ this.renderer.setRenderTarget(null), this._isWorkerBusy = !1;
5404
5404
  return;
5405
5405
  }
5406
5406
  this.renderer.setRenderTarget(null), this.renderDebugFrame && this.renderer.render(this.scene, this.camera), this.worker.postMessage({