gl-draw 0.10.28 → 0.10.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";const b=require("three"),p=require("esus-lite"),j=require("three/examples/jsm/renderers/CSS2DRenderer"),d=require("three/examples/jsm/renderers/CSS3DRenderer"),c=require("./disposeMesh.js");require("idb-keyval");require("d3-geo");function f(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const i=f(b),u=(a,e,t)=>{e&&(c.disposeMesh(e,t),e.children.forEach(r=>{a.has(r)||u(a,r,t)}))};class m{constructor(){this.objectType="BaseObject",this.userData={},this.prefab=!1,this.isInstantiate=!1,this.pm=p.makePromiseCreator(),this.materialList={},this.useMaterialType="origin",this.onPointerIndex=[]}get parent(){const e=this.object3d.parent;return e?this.drawController.objMap.get(e)||this.pencil.scene:null}get children(){return this.object3d.children.map(e=>this.drawController.objMap.get(e)).filter(e=>!!e)}get position(){var e;return(e=this.object3d)==null?void 0:e.position}get rotation(){var e;return(e=this.object3d)==null?void 0:e.rotation}get scale(){var e;return(e=this.object3d)==null?void 0:e.scale}get add(){var e;return(e=this.object3d)==null?void 0:e.add.bind(this.object3d)}get remove(){var e;return(e=this.object3d)==null?void 0:e.remove.bind(this.object3d)}get visible(){return this.object3d?this.object3d.visible:!1}create(){}render(){}update(e,t){}resize(e,t){}show(){return this.object3d&&(this.object3d.visible=!0),this}hide(){return this.object3d&&(this.object3d.visible=!1),this}createMesh(...e){return this.object3d=new i.Mesh(...e),this}createGroup(){return this.object3d=new i.Group,this}createPoints(...e){return this.object3d=new i.Points(...e),this}createCSS2DObject(e){return this.object3d=new j.CSS2DObject(e),this}createCSS3DObject(e){return this.object3d=new d.CSS3DObject(e),this}createCSS3DSprite(e){return this.object3d=new d.CSS3DSprite(e),this}createSprite(e){return this.object3d=new i.Sprite(e),this}attach(...e){return[...e].forEach(t=>{this.object3d.attach(t.object3d),this.drawController!==t.drawController&&(t.drawController.objects.delete(t.key),this.drawController.objects.set(t.key,t))}),this}getSize(){const e=new i.Box3().setFromObject(this.object3d);return{min:e.min,max:e.max,size:e.getSize(new i.Vector3)}}traverse(e){e(this),this.children.forEach(t=>{t.traverse(e)})}clone(){return this.instantiate()}instantiate(e){return this.drawController.instantiate(this,{create:t=>{var r;if(this.object3d){if(this.object3d instanceof i.Sprite&&typeof e=="number"){const{size:s}=this.getSize(),n=new i.MeshBasicMaterial,o=["color","map","alphaMap","transparent","opacity","alphaTest","blending","side","depthTest","depthWrite"];for(const h of o){const l=this.object3d.material[h];l!==null&&(n[h]=l)}t.object3d=new i.Mesh(new i.PlaneGeometry(s.x,s.y,2,2),n)}else t.object3d=this.object3d.clone(!0);typeof e=="number"&&(t.object3d=new i.InstancedMesh(t.object3d.geometry,t.object3d.material,e),t.object3d.instanceMatrix.setUsage(i.DynamicDrawUsage)),t.position.set(0,0,0),t.rotation.set(0,0,0),t.setMaterialList("instantiate","clone"),t.useMaterial("instantiate"),t.object3d.userData.bloom&&((r=this.pencil.composerController)==null||r.toggleBloomSelection(t.object3d,!0)),t.object3d.userData.prefab&&(t.object3d.userData.prefab=!1)}}})}setInstancedMatrix(e){this.object3d instanceof i.InstancedMesh&&(Object.keys(e).forEach(t=>{this.object3d.setMatrixAt(Number(t),e[t])}),this.object3d.instanceMatrix.needsUpdate=!0,this.object3d.computeBoundingSphere())}erase(){this.drawController.erase(this)}cloneMaterial(){const e=this.object3d;if(!e||!e.material)return;const t=e.material;if(Array.isArray(t))return t.map(r=>{const s=r.userData;r.userData={};const n=r.clone();return r.userData=s,n});{const r=t.userData;t.userData={};const s=t.clone();return t.userData=r,s}}setMaterialList(e,t,r=!0){const s=this.object3d;if(!s||!s.material)return;if(this.materialList.origin||(this.materialList.origin=s.material),this.materialList[e])if(r){const o=this.materialList[e];c.disposeMesh({material:o})}else return this.materialList[e];const n=t==="clone"?this.cloneMaterial():t;return this.materialList[e]=n,n}useMaterial(e){const t=this.object3d;!t||!t.material||this.useMaterialType===e||!this.materialList[e]||(this.useMaterialType=e,t.material=this.materialList[e])}setTop(e){this.object3d&&(this.object3d.renderOrder=e)}onPointerEvent(e,t){const r=this.drawController.handlePick([this],e,t);this.onPointerIndex.push(r)}dispose(e=!0){this.onPointerIndex.forEach(t=>{this.drawController.removePick(t)}),u(this.drawController.objMap,this.object3d,e),e&&Object.keys(this.materialList).forEach(t=>{if(t!==this.useMaterialType){if(this.isInstantiate&&t==="origin")return;c.disposeMesh({material:this.materialList[t]})}})}}exports.BaseObject=m;
1
+ "use strict";const b=require("three"),p=require("esus-lite"),j=require("three/examples/jsm/renderers/CSS2DRenderer"),d=require("three/examples/jsm/renderers/CSS3DRenderer"),c=require("./disposeMesh.js");require("idb-keyval");require("d3-geo");require("d3-geo-projection");function f(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const i=f(b),u=(a,e,t)=>{e&&(c.disposeMesh(e,t),e.children.forEach(r=>{a.has(r)||u(a,r,t)}))};class m{constructor(){this.objectType="BaseObject",this.userData={},this.prefab=!1,this.isInstantiate=!1,this.pm=p.makePromiseCreator(),this.materialList={},this.useMaterialType="origin",this.onPointerIndex=[]}get parent(){const e=this.object3d.parent;return e?this.drawController.objMap.get(e)||this.pencil.scene:null}get children(){return this.object3d.children.map(e=>this.drawController.objMap.get(e)).filter(e=>!!e)}get position(){var e;return(e=this.object3d)==null?void 0:e.position}get rotation(){var e;return(e=this.object3d)==null?void 0:e.rotation}get scale(){var e;return(e=this.object3d)==null?void 0:e.scale}get add(){var e;return(e=this.object3d)==null?void 0:e.add.bind(this.object3d)}get remove(){var e;return(e=this.object3d)==null?void 0:e.remove.bind(this.object3d)}get visible(){return this.object3d?this.object3d.visible:!1}create(){}render(){}update(e,t){}resize(e,t){}show(){return this.object3d&&(this.object3d.visible=!0),this}hide(){return this.object3d&&(this.object3d.visible=!1),this}createMesh(...e){return this.object3d=new i.Mesh(...e),this}createGroup(){return this.object3d=new i.Group,this}createPoints(...e){return this.object3d=new i.Points(...e),this}createCSS2DObject(e){return this.object3d=new j.CSS2DObject(e),this}createCSS3DObject(e){return this.object3d=new d.CSS3DObject(e),this}createCSS3DSprite(e){return this.object3d=new d.CSS3DSprite(e),this}createSprite(e){return this.object3d=new i.Sprite(e),this}attach(...e){return[...e].forEach(t=>{this.object3d.attach(t.object3d),this.drawController!==t.drawController&&(t.drawController.objects.delete(t.key),this.drawController.objects.set(t.key,t))}),this}getSize(){const e=new i.Box3().setFromObject(this.object3d);return{min:e.min,max:e.max,size:e.getSize(new i.Vector3)}}traverse(e){e(this),this.children.forEach(t=>{t.traverse(e)})}clone(){return this.instantiate()}instantiate(e){return this.drawController.instantiate(this,{create:t=>{var r;if(this.object3d){if(this.object3d instanceof i.Sprite&&typeof e=="number"){const{size:s}=this.getSize(),n=new i.MeshBasicMaterial,o=["color","map","alphaMap","transparent","opacity","alphaTest","blending","side","depthTest","depthWrite"];for(const h of o){const l=this.object3d.material[h];l!==null&&(n[h]=l)}t.object3d=new i.Mesh(new i.PlaneGeometry(s.x,s.y,2,2),n)}else t.object3d=this.object3d.clone(!0);typeof e=="number"&&(t.object3d=new i.InstancedMesh(t.object3d.geometry,t.object3d.material,e),t.object3d.instanceMatrix.setUsage(i.DynamicDrawUsage)),t.position.set(0,0,0),t.rotation.set(0,0,0),t.setMaterialList("instantiate","clone"),t.useMaterial("instantiate"),t.object3d.userData.bloom&&((r=this.pencil.composerController)==null||r.toggleBloomSelection(t.object3d,!0)),t.object3d.userData.prefab&&(t.object3d.userData.prefab=!1)}}})}setInstancedMatrix(e){this.object3d instanceof i.InstancedMesh&&(Object.keys(e).forEach(t=>{this.object3d.setMatrixAt(Number(t),e[t])}),this.object3d.instanceMatrix.needsUpdate=!0,this.object3d.computeBoundingSphere())}erase(){this.drawController.erase(this)}cloneMaterial(){const e=this.object3d;if(!e||!e.material)return;const t=e.material;if(Array.isArray(t))return t.map(r=>{const s=r.userData;r.userData={};const n=r.clone();return r.userData=s,n});{const r=t.userData;t.userData={};const s=t.clone();return t.userData=r,s}}setMaterialList(e,t,r=!0){const s=this.object3d;if(!s||!s.material)return;if(this.materialList.origin||(this.materialList.origin=s.material),this.materialList[e])if(r){const o=this.materialList[e];c.disposeMesh({material:o})}else return this.materialList[e];const n=t==="clone"?this.cloneMaterial():t;return this.materialList[e]=n,n}useMaterial(e){const t=this.object3d;!t||!t.material||this.useMaterialType===e||!this.materialList[e]||(this.useMaterialType=e,t.material=this.materialList[e])}setTop(e){this.object3d&&(this.object3d.renderOrder=e)}onPointerEvent(e,t){const r=this.drawController.handlePick([this],e,t);this.onPointerIndex.push(r)}dispose(e=!0){this.onPointerIndex.forEach(t=>{this.drawController.removePick(t)}),u(this.drawController.objMap,this.object3d,e),e&&Object.keys(this.materialList).forEach(t=>{if(t!==this.useMaterialType){if(this.isInstantiate&&t==="origin")return;c.disposeMesh({material:this.materialList[t]})}})}}exports.BaseObject=m;
@@ -1,16 +1,17 @@
1
1
  import * as r from "three";
2
2
  import { makePromiseCreator as b } from "esus-lite";
3
3
  import { CSS2DObject as u } from "three/examples/jsm/renderers/CSS2DRenderer";
4
- import { CSS3DObject as p, CSS3DSprite as j } from "three/examples/jsm/renderers/CSS3DRenderer";
4
+ import { CSS3DObject as p, CSS3DSprite as m } from "three/examples/jsm/renderers/CSS3DRenderer";
5
5
  import { d as c } from "./disposeMesh.module.js";
6
6
  import "idb-keyval";
7
7
  import "d3-geo";
8
+ import "d3-geo-projection";
8
9
  const d = (o, t, e) => {
9
10
  t && (c(t, e), t.children.forEach((i) => {
10
11
  o.has(i) || d(o, i, e);
11
12
  }));
12
13
  };
13
- class D {
14
+ class C {
14
15
  constructor() {
15
16
  this.objectType = "BaseObject", this.userData = {}, this.prefab = !1, this.isInstantiate = !1, this.pm = b(), this.materialList = {}, this.useMaterialType = "origin", this.onPointerIndex = [];
16
17
  }
@@ -74,7 +75,7 @@ class D {
74
75
  return this.object3d = new p(t), this;
75
76
  }
76
77
  createCSS3DSprite(t) {
77
- return this.object3d = new j(t), this;
78
+ return this.object3d = new m(t), this;
78
79
  }
79
80
  createSprite(t) {
80
81
  return this.object3d = new r.Sprite(t), this;
@@ -215,5 +216,5 @@ class D {
215
216
  }
216
217
  }
217
218
  export {
218
- D as B
219
+ C as B
219
220
  };
@@ -3,7 +3,7 @@ import GUI from 'lil-gui';
3
3
  import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer';
4
4
  import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass';
5
5
  import { OutputPass } from './pass/OutputPass';
6
- import { ShaderPass } from 'three/examples/jsm/postprocessing/ShaderPass';
6
+ import getMixPass from './pass/MixPass';
7
7
  import { UnrealBloomPass } from 'three/examples/jsm/postprocessing/UnrealBloomPass';
8
8
  import type { IBaseObject } from './BaseObject';
9
9
  export interface BloomParams {
@@ -42,7 +42,7 @@ export default class {
42
42
  renderPass: RenderPass;
43
43
  outputPass: OutputPass;
44
44
  bloomPass?: UnrealBloomPass;
45
- mixPass?: ShaderPass;
45
+ mixPass?: ReturnType<typeof getMixPass>;
46
46
  options: Options;
47
47
  active: boolean;
48
48
  constructor(options: Options);
@@ -0,0 +1,4 @@
1
+ import { ShaderPass } from 'three/examples/jsm/postprocessing/ShaderPass';
2
+ import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer';
3
+ declare const _default: (composer: EffectComposer) => ShaderPass;
4
+ export default _default;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Ht=Object.defineProperty,Vt=Object.defineProperties;var kt=Object.getOwnPropertyDescriptors;var Ct=Object.getOwnPropertySymbols;var Nt=Object.prototype.hasOwnProperty,Bt=Object.prototype.propertyIsEnumerable;var yt=(d,t,e)=>t in d?Ht(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,B=(d,t)=>{for(var e in t||(t={}))Nt.call(t,e)&&yt(d,e,t[e]);if(Ct)for(var e of Ct(t))Bt.call(t,e)&&yt(d,e,t[e]);return d},ht=(d,t)=>Vt(d,kt(t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const ft=require("three"),Yt=require("@tweenjs/tween.js"),Rt=require("./events.js"),Zt=require("deepmerge"),jt=require("stats-gl"),qt=require("lil-gui"),Gt=require("./colorCorrection.js"),Xt=require("./disposeMesh.js");require("idb-keyval");require("esus-lite");require("d3-geo");const Kt=require("three/examples/jsm/helpers/RectAreaLightHelper"),Qt=require("three/examples/jsm/controls/TransformControls"),Wt=require("three/examples/jsm/renderers/CSS3DRenderer"),Jt=require("three/examples/jsm/renderers/CSS2DRenderer"),Et=require("three/examples/jsm/postprocessing/EffectComposer"),$t=require("three/examples/jsm/postprocessing/RenderPass"),te=require("three/examples/jsm/postprocessing/Pass"),ee=require("three/examples/jsm/postprocessing/OutputPass"),se=require("three/examples/jsm/postprocessing/ShaderPass"),ie=require("three/examples/jsm/postprocessing/UnrealBloomPass"),oe=require("./isPlainObject.js"),re=require("./BaseObject.js");function At(d){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(d){for(const e in d)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(d,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>d[e]})}}return t.default=d,Object.freeze(t)}const x=At(ft),Ot=At(Yt),R={LEFT:1,RIGHT:2,MIDDLE:4},n=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}),Y={NONE:0,IN:1,OUT:-1};function V(d){return d.isPerspectiveCamera}function H(d){return d.isOrthographicCamera}const Z=Math.PI*2,Tt=Math.PI/2,Lt=1e-5,G=Math.PI/180;function F(d,t,e){return Math.max(t,Math.min(e,d))}function D(d,t=Lt){return Math.abs(d)<t}function w(d,t,e=Lt){return D(d-t,e)}function vt(d,t){return Math.round(d/t)*t}function X(d){return isFinite(d)?d:d<0?-Number.MAX_VALUE:Number.MAX_VALUE}function K(d){return Math.abs(d)<Number.MAX_VALUE?d:d*(1/0)}function et(d,t,e,s,i=1/0,o){s=Math.max(1e-4,s);const r=2/s,a=r*o,l=1/(1+a+.48*a*a+.235*a*a*a);let c=d-t;const g=t,_=i*s;c=F(c,-_,_),t=d-c;const C=(e.value+r*c)*o;e.value=(e.value-r*C)*l;let p=t+(c+C)*l;return g-d>0==p>g&&(p=g,e.value=(p-g)/o),p}function xt(d,t,e,s,i=1/0,o,r){s=Math.max(1e-4,s);const a=2/s,l=a*o,c=1/(1+l+.48*l*l+.235*l*l*l);let g=t.x,_=t.y,C=t.z,p=d.x-g,P=d.y-_,f=d.z-C;const S=g,h=_,m=C,y=i*s,u=y*y,v=p*p+P*P+f*f;if(v>u){const at=Math.sqrt(v);p=p/at*y,P=P/at*y,f=f/at*y}g=d.x-p,_=d.y-P,C=d.z-f;const O=(e.x+a*p)*o,U=(e.y+a*P)*o,A=(e.z+a*f)*o;e.x=(e.x-a*O)*c,e.y=(e.y-a*U)*c,e.z=(e.z-a*A)*c,r.x=g+(p+O)*c,r.y=_+(P+U)*c,r.z=C+(f+A)*c;const $=S-d.x,tt=h-d.y,zt=m-d.z,Ft=r.x-S,Mt=r.y-h,It=r.z-m;return $*Ft+tt*Mt+zt*It>0&&(r.x=S,r.y=h,r.z=m,e.x=(r.x-S)/o,e.y=(r.y-h)/o,e.z=(r.z-m)/o),r}function lt(d,t){t.set(0,0),d.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=d.length,t.y/=d.length}function ct(d,t){return H(d)?(console.warn(`${t} is not supported in OrthographicCamera`),!0):!1}class ne{constructor(){this._listeners={}}addEventListener(t,e){const s=this._listeners;s[t]===void 0&&(s[t]=[]),s[t].indexOf(e)===-1&&s[t].push(e)}hasEventListener(t,e){const s=this._listeners;return s[t]!==void 0&&s[t].indexOf(e)!==-1}removeEventListener(t,e){const i=this._listeners[t];if(i!==void 0){const o=i.indexOf(e);o!==-1&&i.splice(o,1)}}removeAllEventListeners(t){if(!t){this._listeners={};return}Array.isArray(this._listeners[t])&&(this._listeners[t].length=0)}dispatchEvent(t){const s=this._listeners[t.type];if(s!==void 0){t.target=this;const i=s.slice(0);for(let o=0,r=i.length;o<r;o++)i[o].call(this,t)}}}const st=1/8,ae=/Mac/.test(navigator.platform);let E,Pt,it,dt,L,T,b,j,Q,M,I,k,bt,St,z,W,q,wt,mt,Dt,_t,pt,ot;class N extends ne{static install(t){E=t.THREE,Pt=Object.freeze(new E.Vector3(0,0,0)),it=Object.freeze(new E.Vector3(0,1,0)),dt=Object.freeze(new E.Vector3(0,0,1)),L=new E.Vector2,T=new E.Vector3,b=new E.Vector3,j=new E.Vector3,Q=new E.Vector3,M=new E.Vector3,I=new E.Vector3,k=new E.Vector3,bt=new E.Vector3,St=new E.Vector3,z=new E.Spherical,W=new E.Spherical,q=new E.Box3,wt=new E.Box3,mt=new E.Sphere,Dt=new E.Quaternion,_t=new E.Quaternion,pt=new E.Matrix4,ot=new E.Raycaster}static get ACTION(){return n}constructor(t,e){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=n.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=Y.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new E.Vector3,this._focalOffsetVelocity=new E.Vector3,this._zoomVelocity={value:0},this._truckInternal=(h,m,y)=>{let u,v;if(V(this._camera)){const O=T.copy(this._camera.position).sub(this._target),U=this._camera.getEffectiveFOV()*G,A=O.length()*Math.tan(U*.5);u=this.truckSpeed*h*A/this._elementRect.height,v=this.truckSpeed*m*A/this._elementRect.height}else if(H(this._camera)){const O=this._camera;u=h*(O.right-O.left)/O.zoom/this._elementRect.width,v=m*(O.top-O.bottom)/O.zoom/this._elementRect.height}else return;this.verticalDragToForward?(y?this.setFocalOffset(this._focalOffsetEnd.x+u,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(u,0,!0),this.forward(-v,!0)):y?this.setFocalOffset(this._focalOffsetEnd.x+u,this._focalOffsetEnd.y+v,this._focalOffsetEnd.z,!0):this.truck(u,v,!0)},this._rotateInternal=(h,m)=>{const y=Z*this.azimuthRotateSpeed*h/this._elementRect.height,u=Z*this.polarRotateSpeed*m/this._elementRect.height;this.rotate(y,u,!0)},this._dollyInternal=(h,m,y)=>{const u=Math.pow(.95,-h*this.dollySpeed),v=this._sphericalEnd.radius,O=this._sphericalEnd.radius*u,U=F(O,this.minDistance,this.maxDistance),A=U-O;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(O,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(A,!0),this._dollyToNoClamp(U,!0)):this._dollyToNoClamp(U,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?O:U)-v,this._dollyControlCoord.set(m,y)),this._lastDollyDirection=Math.sign(-h)},this._zoomInternal=(h,m,y)=>{const u=Math.pow(.95,h*this.dollySpeed),v=this._zoom,O=this._zoom*u;this.zoomTo(O,!0),this.dollyToCursor&&(this._changedZoom+=O-v,this._dollyControlCoord.set(m,y))},typeof E=="undefined"&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=t,this._yAxisUpSpace=new E.Quaternion().setFromUnitVectors(this._camera.up,it),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=n.NONE,this._target=new E.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new E.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new E.Spherical().setFromVector3(T.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 E.Vector3,new E.Vector3,new E.Vector3,new E.Vector3],this._updateNearPlaneCorners(),this._boundary=new E.Box3(new E.Vector3(-1/0,-1/0,-1/0),new E.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 E.Vector2,this.mouseButtons={left:n.ROTATE,middle:n.DOLLY,right:n.TRUCK,wheel:V(this._camera)?n.DOLLY:H(this._camera)?n.ZOOM:n.NONE},this.touches={one:n.TOUCH_ROTATE,two:V(this._camera)?n.TOUCH_DOLLY_TRUCK:H(this._camera)?n.TOUCH_ZOOM_TRUCK:n.NONE,three:n.TOUCH_TRUCK};const s=new E.Vector2,i=new E.Vector2,o=new E.Vector2,r=h=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const u=this._domElement.getBoundingClientRect(),v=(h.clientX-u.left)/(u.right-u.left),O=(h.clientY-u.top)/(u.bottom-u.top);if(v<this._interactiveArea.left||v>this._interactiveArea.right||O<this._interactiveArea.top||O>this._interactiveArea.bottom)return}const m=h.pointerType!=="mouse"?null:(h.buttons&R.LEFT)===R.LEFT?R.LEFT:(h.buttons&R.MIDDLE)===R.MIDDLE?R.MIDDLE:(h.buttons&R.RIGHT)===R.RIGHT?R.RIGHT:null;if(m!==null){const u=this._findPointerByMouseButton(m);u&&this._disposePointer(u)}if((h.buttons&R.LEFT)===R.LEFT&&this._lockedPointer)return;const y={pointerId:h.pointerId,clientX:h.clientX,clientY:h.clientY,deltaX:0,deltaY:0,mouseButton:m};this._activePointers.push(y),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",l),this._isDragging=!0,C(h)},a=h=>{h.cancelable&&h.preventDefault();const m=h.pointerId,y=this._lockedPointer||this._findPointerById(m);if(y){if(y.clientX=h.clientX,y.clientY=h.clientY,y.deltaX=h.movementX,y.deltaY=h.movementY,this._state=0,h.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(h.buttons&R.LEFT)===R.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(h.buttons&R.MIDDLE)===R.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(h.buttons&R.RIGHT)===R.RIGHT&&(this._state=this._state|this.mouseButtons.right);p()}},l=h=>{const m=this._findPointerById(h.pointerId);if(!(m&&m===this._lockedPointer)){if(m&&this._disposePointer(m),h.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=n.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=n.NONE;P()}};let c=-1;const g=h=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===n.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const O=this._domElement.getBoundingClientRect(),U=(h.clientX-O.left)/(O.right-O.left),A=(h.clientY-O.top)/(O.bottom-O.top);if(U<this._interactiveArea.left||U>this._interactiveArea.right||A<this._interactiveArea.top||A>this._interactiveArea.bottom)return}if(h.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===n.ROTATE||this.mouseButtons.wheel===n.TRUCK){const O=performance.now();c-O<1e3&&this._getClientRect(this._elementRect),c=O}const m=ae?-1:-3,y=h.deltaMode===1?h.deltaY/m:h.deltaY/(m*10),u=this.dollyToCursor?(h.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,v=this.dollyToCursor?(h.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case n.ROTATE:{this._rotateInternal(h.deltaX,h.deltaY),this._isUserControllingRotate=!0;break}case n.TRUCK:{this._truckInternal(h.deltaX,h.deltaY,!1),this._isUserControllingTruck=!0;break}case n.OFFSET:{this._truckInternal(h.deltaX,h.deltaY,!0),this._isUserControllingOffset=!0;break}case n.DOLLY:{this._dollyInternal(-y,u,v),this._isUserControllingDolly=!0;break}case n.ZOOM:{this._zoomInternal(-y,u,v),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},_=h=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===N.ACTION.NONE){const m=h instanceof PointerEvent?h.pointerId:0,y=this._findPointerById(m);y&&this._disposePointer(y),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l);return}h.preventDefault()}},C=h=>{if(!this._enabled)return;if(lt(this._activePointers,L),this._getClientRect(this._elementRect),s.copy(L),i.copy(L),this._activePointers.length>=2){const y=L.x-this._activePointers[1].clientX,u=L.y-this._activePointers[1].clientY,v=Math.sqrt(y*y+u*u);o.set(0,v);const O=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,U=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;i.set(O,U)}if(this._state=0,!h)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in h&&h.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else!this._lockedPointer&&(h.buttons&R.LEFT)===R.LEFT&&(this._state=this._state|this.mouseButtons.left),(h.buttons&R.MIDDLE)===R.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(h.buttons&R.RIGHT)===R.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&n.ROTATE)===n.ROTATE||(this._state&n.TOUCH_ROTATE)===n.TOUCH_ROTATE||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_ZOOM_ROTATE)===n.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&n.TRUCK)===n.TRUCK||(this._state&n.TOUCH_TRUCK)===n.TOUCH_TRUCK||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&n.DOLLY)===n.DOLLY||(this._state&n.TOUCH_DOLLY)===n.TOUCH_DOLLY||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&n.ZOOM)===n.ZOOM||(this._state&n.TOUCH_ZOOM)===n.TOUCH_ZOOM||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET||(this._state&n.TOUCH_ZOOM_ROTATE)===n.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&n.OFFSET)===n.OFFSET||(this._state&n.TOUCH_OFFSET)===n.TOUCH_OFFSET||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},p=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,lt(this._activePointers,L);const m=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,y=m?-m.deltaX:i.x-L.x,u=m?-m.deltaY:i.y-L.y;if(i.copy(L),((this._state&n.ROTATE)===n.ROTATE||(this._state&n.TOUCH_ROTATE)===n.TOUCH_ROTATE||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_ZOOM_ROTATE)===n.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(y,u),this._isUserControllingRotate=!0),(this._state&n.DOLLY)===n.DOLLY||(this._state&n.ZOOM)===n.ZOOM){const v=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,O=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0,U=this.dollyDragInverted?-1:1;(this._state&n.DOLLY)===n.DOLLY?(this._dollyInternal(U*u*st,v,O),this._isUserControllingDolly=!0):(this._zoomInternal(U*u*st,v,O),this._isUserControllingZoom=!0)}if((this._state&n.TOUCH_DOLLY)===n.TOUCH_DOLLY||(this._state&n.TOUCH_ZOOM)===n.TOUCH_ZOOM||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_ZOOM_ROTATE)===n.TOUCH_ZOOM_ROTATE){const v=L.x-this._activePointers[1].clientX,O=L.y-this._activePointers[1].clientY,U=Math.sqrt(v*v+O*O),A=o.y-U;o.set(0,U);const $=this.dollyToCursor?(i.x-this._elementRect.x)/this._elementRect.width*2-1:0,tt=this.dollyToCursor?(i.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&n.TOUCH_DOLLY)===n.TOUCH_DOLLY||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET?(this._dollyInternal(A*st,$,tt),this._isUserControllingDolly=!0):(this._zoomInternal(A*st,$,tt),this._isUserControllingZoom=!0)}((this._state&n.TRUCK)===n.TRUCK||(this._state&n.TOUCH_TRUCK)===n.TOUCH_TRUCK||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(y,u,!1),this._isUserControllingTruck=!0),((this._state&n.OFFSET)===n.OFFSET||(this._state&n.TOUCH_OFFSET)===n.TOUCH_OFFSET||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(y,u,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},P=()=>{lt(this._activePointers,L),i.copy(L),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("pointerup",l),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",l),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",f),this._domElement.ownerDocument.addEventListener("pointerlockerror",S),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",l),C())},this.unlockPointer=()=>{var h,m,y;this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),(h=this._domElement)===null||h===void 0||h.ownerDocument.exitPointerLock(),(m=this._domElement)===null||m===void 0||m.ownerDocument.removeEventListener("pointerlockchange",f),(y=this._domElement)===null||y===void 0||y.ownerDocument.removeEventListener("pointerlockerror",S),this.cancel()};const f=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},S=()=>{this.unlockPointer()};this._addAllEventListeners=h=>{this._domElement=h,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",r),this._domElement.addEventListener("pointercancel",l),this._domElement.addEventListener("wheel",g,{passive:!1}),this._domElement.addEventListener("contextmenu",_)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",r),this._domElement.removeEventListener("pointercancel",l),this._domElement.removeEventListener("wheel",g,{passive:!1}),this._domElement.removeEventListener("contextmenu",_),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.ownerDocument.removeEventListener("pointerlockchange",f),this._domElement.ownerDocument.removeEventListener("pointerlockerror",S))},this.cancel=()=>{this._state!==n.NONE&&(this._state=n.NONE,this._activePointers.length=0,P())},e&&this.connect(e),this.update(0)}get camera(){return this._camera}set camera(t){this._camera=t,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(t){this._enabled=t,this._domElement&&(t?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(t){this._spherical.radius===t&&this._sphericalEnd.radius===t||(this._spherical.radius=t,this._sphericalEnd.radius=t,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(t){this._spherical.theta===t&&this._sphericalEnd.theta===t||(this._spherical.theta=t,this._sphericalEnd.theta=t,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(t){this._spherical.phi===t&&this._sphericalEnd.phi===t||(this._spherical.phi=t,this._sphericalEnd.phi=t,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(t){this._boundaryEnclosesCamera=t,this._needsUpdate=!0}set interactiveArea(t){this._interactiveArea.width=F(t.width,0,1),this._interactiveArea.height=F(t.height,0,1),this._interactiveArea.x=F(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=F(t.y,0,1-this._interactiveArea.height)}addEventListener(t,e){super.addEventListener(t,e)}removeEventListener(t,e){super.removeEventListener(t,e)}rotate(t,e,s=!1){return this.rotateTo(this._sphericalEnd.theta+t,this._sphericalEnd.phi+e,s)}rotateAzimuthTo(t,e=!1){return this.rotateTo(t,this._sphericalEnd.phi,e)}rotatePolarTo(t,e=!1){return this.rotateTo(this._sphericalEnd.theta,t,e)}rotateTo(t,e,s=!1){this._isUserControllingRotate=!1;const i=F(t,this.minAzimuthAngle,this.maxAzimuthAngle),o=F(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=i,this._sphericalEnd.phi=o,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const r=!s||w(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&w(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(r)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Y.NONE,this._changedDolly=0,this._dollyToNoClamp(F(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const s=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const r=this._collisionTest(),a=w(r,this._spherical.radius);if(!(s>t)&&a)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,r)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const o=!e||w(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(o)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(Q).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const s=!e||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(s)}zoom(t,e=!1){return this.zoomTo(this._zoomEnd+t,e)}zoomTo(t,e=!1){this._isUserControllingZoom=!1,this._zoomEnd=F(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const s=!e||w(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(s)}pan(t,e,s=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(t,e,s)}truck(t,e,s=!1){this._camera.updateMatrix(),M.setFromMatrixColumn(this._camera.matrix,0),I.setFromMatrixColumn(this._camera.matrix,1),M.multiplyScalar(t),I.multiplyScalar(-e);const i=T.copy(M).add(I),o=b.copy(this._targetEnd).add(i);return this.moveTo(o.x,o.y,o.z,s)}forward(t,e=!1){T.setFromMatrixColumn(this._camera.matrix,0),T.crossVectors(this._camera.up,T),T.multiplyScalar(t);const s=b.copy(this._targetEnd).add(T);return this.moveTo(s.x,s.y,s.z,e)}elevate(t,e=!1){return T.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+T.x,this._targetEnd.y+T.y,this._targetEnd.z+T.z,e)}moveTo(t,e,s,i=!1){this._isUserControllingTruck=!1;const o=T.set(t,e,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,o,this.boundaryFriction),this._needsUpdate=!0,i||this._target.copy(this._targetEnd);const r=!i||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}lookInDirectionOf(t,e,s,i=!1){const a=T.set(t,e,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(a.x,a.y,a.z,i)}fitToBox(t,e,{cover:s=!1,paddingLeft:i=0,paddingRight:o=0,paddingBottom:r=0,paddingTop:a=0}={}){const l=[],c=t.isBox3?q.copy(t):q.setFromObject(t);c.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const g=vt(this._sphericalEnd.theta,Tt),_=vt(this._sphericalEnd.phi,Tt);l.push(this.rotateTo(g,_,e));const C=T.setFromSpherical(this._sphericalEnd).normalize(),p=Dt.setFromUnitVectors(C,dt),P=w(Math.abs(C.y),1);P&&p.multiply(_t.setFromAxisAngle(it,g)),p.multiply(this._yAxisUpSpaceInverse);const f=wt.makeEmpty();b.copy(c.min).applyQuaternion(p),f.expandByPoint(b),b.copy(c.min).setX(c.max.x).applyQuaternion(p),f.expandByPoint(b),b.copy(c.min).setY(c.max.y).applyQuaternion(p),f.expandByPoint(b),b.copy(c.max).setZ(c.min.z).applyQuaternion(p),f.expandByPoint(b),b.copy(c.min).setZ(c.max.z).applyQuaternion(p),f.expandByPoint(b),b.copy(c.max).setY(c.min.y).applyQuaternion(p),f.expandByPoint(b),b.copy(c.max).setX(c.min.x).applyQuaternion(p),f.expandByPoint(b),b.copy(c.max).applyQuaternion(p),f.expandByPoint(b),f.min.x-=i,f.min.y-=r,f.max.x+=o,f.max.y+=a,p.setFromUnitVectors(dt,C),P&&p.premultiply(_t.invert()),p.premultiply(this._yAxisUpSpace);const S=f.getSize(T),h=f.getCenter(b).applyQuaternion(p);if(V(this._camera)){const m=this.getDistanceToFitBox(S.x,S.y,S.z,s);l.push(this.moveTo(h.x,h.y,h.z,e)),l.push(this.dollyTo(m,e)),l.push(this.setFocalOffset(0,0,0,e))}else if(H(this._camera)){const m=this._camera,y=m.right-m.left,u=m.top-m.bottom,v=s?Math.max(y/S.x,u/S.y):Math.min(y/S.x,u/S.y);l.push(this.moveTo(h.x,h.y,h.z,e)),l.push(this.zoomTo(v,e)),l.push(this.setFocalOffset(0,0,0,e))}return Promise.all(l)}fitToSphere(t,e){const s=[],o="isObject3D"in t?N.createBoundingSphere(t,mt):mt.copy(t);if(s.push(this.moveTo(o.center.x,o.center.y,o.center.z,e)),V(this._camera)){const r=this.getDistanceToFitSphere(o.radius);s.push(this.dollyTo(r,e))}else if(H(this._camera)){const r=this._camera.right-this._camera.left,a=this._camera.top-this._camera.bottom,l=2*o.radius,c=Math.min(r/l,a/l);s.push(this.zoomTo(c,e))}return s.push(this.setFocalOffset(0,0,0,e)),Promise.all(s)}setLookAt(t,e,s,i,o,r,a=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Y.NONE,this._changedDolly=0;const l=b.set(i,o,r),c=T.set(t,e,s);this._targetEnd.copy(l),this._sphericalEnd.setFromVector3(c.sub(l).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,a||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const g=!a||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(this._target.z,this._targetEnd.z,this.restThreshold)&&w(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&w(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&w(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(g)}lerpLookAt(t,e,s,i,o,r,a,l,c,g,_,C,p,P=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Y.NONE,this._changedDolly=0;const f=T.set(i,o,r),S=b.set(t,e,s);z.setFromVector3(S.sub(f).applyQuaternion(this._yAxisUpSpace));const h=j.set(g,_,C),m=b.set(a,l,c);W.setFromVector3(m.sub(h).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(f.lerp(h,p));const y=W.theta-z.theta,u=W.phi-z.phi,v=W.radius-z.radius;this._sphericalEnd.set(z.radius+v*p,z.phi+u*p,z.theta+y*p),this.normalizeRotations(),this._needsUpdate=!0,P||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const O=!P||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(this._target.z,this._targetEnd.z,this.restThreshold)&&w(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&w(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&w(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(O)}setPosition(t,e,s,i=!1){return this.setLookAt(t,e,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,i)}setTarget(t,e,s,i=!1){const o=this.getPosition(T),r=this.setLookAt(o.x,o.y,o.z,t,e,s,i);return this._sphericalEnd.phi=F(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),r}setFocalOffset(t,e,s,i=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,s),this._needsUpdate=!0,i||this._focalOffset.copy(this._focalOffsetEnd);const o=!i||w(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&w(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&w(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(o)}setOrbitPoint(t,e,s){this._camera.updateMatrixWorld(),M.setFromMatrixColumn(this._camera.matrixWorldInverse,0),I.setFromMatrixColumn(this._camera.matrixWorldInverse,1),k.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const i=T.set(t,e,s),o=i.distanceTo(this._camera.position),r=i.sub(this._camera.position);M.multiplyScalar(r.x),I.multiplyScalar(r.y),k.multiplyScalar(r.z),T.copy(M).add(I).add(k),T.z=T.z+o,this.dollyTo(o,!1),this.setFocalOffset(-T.x,T.y,-T.z,!1),this.moveTo(t,e,s,!1)}setBoundary(t){if(!t){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(t),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(t,e,s,i){if(t===null){this._viewport=null;return}this._viewport=this._viewport||new E.Vector4,typeof t=="number"?this._viewport.set(t,e,s,i):this._viewport.copy(t)}getDistanceToFitBox(t,e,s,i=!1){if(ct(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const o=t/e,r=this._camera.getEffectiveFOV()*G,a=this._camera.aspect;return((i?o>a:o<a)?e:t/a)*.5/Math.tan(r*.5)+s*.5}getDistanceToFitSphere(t){if(ct(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*G,s=Math.atan(Math.tan(e*.5)*this._camera.aspect)*2,i=1<this._camera.aspect?e:s;return t/Math.sin(i*.5)}getTarget(t,e=!0){return(t&&t.isVector3?t:new E.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new E.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new E.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new E.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%Z,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=Z),this._spherical.theta+=Z*Math.round((this._sphericalEnd.theta-this._spherical.theta)/Z)}reset(t=!1){if(!w(this._camera.up.x,this._cameraUp0.x)||!w(this._camera.up.y,this._cameraUp0.y)||!w(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const s=this.getPosition(T);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}const e=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,t),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,t),this.zoomTo(this._zoom0,t)];return Promise.all(e)}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,it),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=T.subVectors(this._target,this._camera.position).normalize(),e=b.crossVectors(t,this._camera.up);this._camera.up.crossVectors(e,t).normalize(),this._camera.updateMatrixWorld();const s=this.getPosition(T);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}update(t){const e=this._sphericalEnd.theta-this._spherical.theta,s=this._sphericalEnd.phi-this._spherical.phi,i=this._sphericalEnd.radius-this._spherical.radius,o=bt.subVectors(this._targetEnd,this._target),r=St.subVectors(this._focalOffsetEnd,this._focalOffset),a=this._zoomEnd-this._zoom;if(D(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const _=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=et(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,_,1/0,t),this._needsUpdate=!0}if(D(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const _=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=et(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,_,1/0,t),this._needsUpdate=!0}if(D(i))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const _=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=et(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,_,this.maxSpeed,t),this._needsUpdate=!0}if(D(o.x)&&D(o.y)&&D(o.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const _=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;xt(this._target,this._targetEnd,this._targetVelocity,_,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(D(r.x)&&D(r.y)&&D(r.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const _=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;xt(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,_,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(D(a))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const _=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=et(this._zoom,this._zoomEnd,this._zoomVelocity,_,1/0,t)}if(this.dollyToCursor){if(V(this._camera)&&this._changedDolly!==0){const _=this._spherical.radius-this._lastDistance,C=this._camera,p=this._getCameraDirection(Q),P=T.copy(p).cross(C.up).normalize();P.lengthSq()===0&&(P.x=1);const f=b.crossVectors(P,p),S=this._sphericalEnd.radius*Math.tan(C.getEffectiveFOV()*G*.5),m=(this._sphericalEnd.radius-_-this._sphericalEnd.radius)/this._sphericalEnd.radius,y=j.copy(this._targetEnd).add(P.multiplyScalar(this._dollyControlCoord.x*S*C.aspect)).add(f.multiplyScalar(this._dollyControlCoord.y*S)),u=T.copy(this._targetEnd).lerp(y,m),v=this._lastDollyDirection===Y.IN&&this._spherical.radius<=this.minDistance,O=this._lastDollyDirection===Y.OUT&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(v||O)){this._sphericalEnd.radius-=_,this._spherical.radius-=_;const A=b.copy(p).multiplyScalar(-_);u.add(A)}this._boundary.clampPoint(u,u);const U=b.subVectors(u,this._targetEnd);this._targetEnd.copy(u),this._target.add(U),this._changedDolly-=_,D(this._changedDolly)&&(this._changedDolly=0)}else if(H(this._camera)&&this._changedZoom!==0){const _=this._zoom-this._lastZoom,C=this._camera,p=T.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(C.near+C.far)/(C.near-C.far)).unproject(C),P=b.set(0,0,-1).applyQuaternion(C.quaternion),f=j.copy(p).add(P.multiplyScalar(-p.dot(C.up))),h=-(this._zoom-_-this._zoom)/this._zoom,m=this._getCameraDirection(Q),y=this._targetEnd.dot(m),u=T.copy(this._targetEnd).lerp(f,h),v=u.dot(m),O=m.multiplyScalar(v-y);u.sub(O),this._boundary.clampPoint(u,u);const U=b.subVectors(u,this._targetEnd);this._targetEnd.copy(u),this._target.add(U),this._changedZoom-=_,D(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 l=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,l),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!D(this._focalOffset.x)||!D(this._focalOffset.y)||!D(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),M.setFromMatrixColumn(this._camera.matrix,0),I.setFromMatrixColumn(this._camera.matrix,1),k.setFromMatrixColumn(this._camera.matrix,2),M.multiplyScalar(this._focalOffset.x),I.multiplyScalar(-this._focalOffset.y),k.multiplyScalar(this._focalOffset.z),T.copy(M).add(I).add(k),this._camera.position.add(T)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),T.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const g=this._needsUpdate;return g&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):g?(this.dispatchEvent({type:"update"}),D(e,this.restThreshold)&&D(s,this.restThreshold)&&D(i,this.restThreshold)&&D(o.x,this.restThreshold)&&D(o.y,this.restThreshold)&&D(o.z,this.restThreshold)&&D(r.x,this.restThreshold)&&D(r.y,this.restThreshold)&&D(r.z,this.restThreshold)&&D(a,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!g&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=g,this._needsUpdate=!1,g}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:X(this.maxDistance),minZoom:this.minZoom,maxZoom:X(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:X(this.maxPolarAngle),minAzimuthAngle:X(this.minAzimuthAngle),maxAzimuthAngle:X(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:T.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(t,e=!1){const s=JSON.parse(t);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=K(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=K(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=K(s.maxPolarAngle),this.minAzimuthAngle=K(s.minAzimuthAngle),this.maxAzimuthAngle=K(s.maxAzimuthAngle),this.smoothTime=s.smoothTime,this.draggingSmoothTime=s.draggingSmoothTime,this.dollySpeed=s.dollySpeed,this.truckSpeed=s.truckSpeed,this.dollyToCursor=s.dollyToCursor,this.verticalDragToForward=s.verticalDragToForward,this._target0.fromArray(s.target0),this._position0.fromArray(s.position0),this._zoom0=s.zoom0,this._focalOffset0.fromArray(s.focalOffset0),this.moveTo(s.target[0],s.target[1],s.target[2],e),z.setFromVector3(T.fromArray(s.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(z.theta,z.phi,e),this.dollyTo(z.radius,e),this.zoomTo(s.zoom,e),this.setFocalOffset(s.focalOffset[0],s.focalOffset[1],s.focalOffset[2],e),this._needsUpdate=!0}connect(t){if(this._domElement){console.warn("camera-controls is already connected.");return}this._addAllEventListeners(t),this._getClientRect(this._elementRect)}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_getTargetDirection(t){return t.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse)}_getCameraDirection(t){return this._getTargetDirection(t).negate()}_findPointerById(t){return this._activePointers.find(e=>e.pointerId===t)}_findPointerByMouseButton(t){return this._activePointers.find(e=>e.mouseButton===t)}_disposePointer(t){this._activePointers.splice(this._activePointers.indexOf(t),1)}_encloseToBoundary(t,e,s){const i=e.lengthSq();if(i===0)return t;const o=b.copy(e).add(t),a=this._boundary.clampPoint(o,j).sub(o),l=a.lengthSq();if(l===0)return t.add(e);if(l===i)return t;if(s===0)return t.add(e).add(a);{const c=1+s*l/e.dot(a);return t.add(b.copy(e).multiplyScalar(c)).add(a.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(V(this._camera)){const t=this._camera,e=t.near,s=t.getEffectiveFOV()*G,i=Math.tan(s*.5)*e,o=i*t.aspect;this._nearPlaneCorners[0].set(-o,-i,0),this._nearPlaneCorners[1].set(o,-i,0),this._nearPlaneCorners[2].set(o,i,0),this._nearPlaneCorners[3].set(-o,i,0)}else if(H(this._camera)){const t=this._camera,e=1/t.zoom,s=t.left*e,i=t.right*e,o=t.top*e,r=t.bottom*e;this._nearPlaneCorners[0].set(s,o,0),this._nearPlaneCorners[1].set(i,o,0),this._nearPlaneCorners[2].set(i,r,0),this._nearPlaneCorners[3].set(s,r,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1)||ct(this._camera,"_collisionTest"))return t;const s=this._getTargetDirection(Q);pt.lookAt(Pt,s,this._camera.up);for(let i=0;i<4;i++){const o=b.copy(this._nearPlaneCorners[i]);o.applyMatrix4(pt);const r=j.addVectors(this._target,o);ot.set(r,s),ot.far=this._spherical.radius+1;const a=ot.intersectObjects(this.colliderMeshes);a.length!==0&&a[0].distance<t&&(t=a[0].distance)}return t}_getClientRect(t){if(!this._domElement)return;const e=this._domElement.getBoundingClientRect();return t.x=e.left,t.y=e.top,this._viewport?(t.x+=this._viewport.x,t.y+=e.height-this._viewport.w-this._viewport.y,t.width=this._viewport.z,t.height=this._viewport.w):(t.width=e.width,t.height=e.height),t}_createOnRestPromise(t){return t?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(e=>{const s=()=>{this.removeEventListener("rest",s),e()};this.addEventListener("rest",s)}))}_addAllEventListeners(t){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(t){console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead.")}get draggingDampingFactor(){return console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead."),0}set draggingDampingFactor(t){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(t,e=new E.Sphere){const s=e,i=s.center;q.makeEmpty(),t.traverseVisible(r=>{r.isMesh&&q.expandByObject(r)}),q.getCenter(i);let o=0;return t.traverseVisible(r=>{if(!r.isMesh)return;const a=r,l=a.geometry.clone();l.applyMatrix4(a.matrixWorld);const g=l.attributes.position;for(let _=0,C=g.count;_<C;_++)T.fromBufferAttribute(g,_),o=Math.max(o,i.distanceToSquared(T))}),s.radius=Math.sqrt(o),s}}const he={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMappingExposure:1,alpha:!1,outputColorSpace:Gt.ColorSpace.sRGB,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,stencil:!1,depth:!1,physicallyCorrectLights:!1};class le{constructor(t){this.options=t;const{width:e,height:s,rendererParams:i}=t,{canvas:o,context:r,alpha:a,devicePixelRatio:l,antialias:c,powerPreference:g,toneMappingExposure:_,outputColorSpace:C,logarithmicDepthBuffer:p,preserveDrawingBuffer:P,stencil:f,depth:S,physicallyCorrectLights:h}=i,m=new x.WebGLRenderer({canvas:o,context:r,alpha:a,antialias:c,powerPreference:g,logarithmicDepthBuffer:p,preserveDrawingBuffer:P,stencil:f,depth:S});m.setSize(e,s),m.setPixelRatio(l),m.toneMappingExposure=_,m.outputColorSpace=C,+x.REVISION<155&&(m.useLegacyLights=h),this.renderer=m}setSize(t,e){this.renderer.setSize(t,e)}setPixelRatio(t){this.renderer.setPixelRatio(t)}render(t){const{scene:e,camera:s}=this.options;this.renderer.render(e,t||s)}dispose(){var t,e;this.setSize(1,1),(t=this.renderer)==null||t.clear(),(e=this.renderer)==null||e.dispose()}}const ce={antialias:!0,devicePixelRatio:window.devicePixelRatio};class de{constructor(t){this.options=t;const{width:e,height:s,rendererParams:i,renderer:o}=t,{devicePixelRatio:r,antialias:a}=i,l=new o({antialias:a});l.setSize(e,s),l.setPixelRatio(r),this.renderer=l}setSize(t,e){this.renderer.setSize(t,e)}render(t){const{scene:e,camera:s}=this.options;this.renderer.render(e,t||s)}dispose(){var t,e;this.setSize(1,1),(t=this.renderer)==null||t.clear(),(e=this.renderer)==null||e.dispose()}}class gt{constructor(t){this.guiParams={},t&&(this.guiParams=t)}showGui(t){t&&Object.keys(this.guiParams).forEach(e=>{const s=t.addFolder(e),i=this.guiParams[e];Object.keys(i).forEach(o=>{const{min:r,max:a,step:l,name:c,paramMap:g,items:_,value:C,target:p}=i[o],P=o.toLowerCase().indexOf("color")>-1;let f;const S=typeof C=="undefined"&&p,h=S?p():i[o],m=S?o:"value";_?f=s.add(h,m,_):P?f=s.addColor(h,m):f=s.add(h,m),f=f.name(c||o),typeof r!="undefined"&&(f=f.min(r)),typeof a!="undefined"&&(f=f.max(a)),typeof l!="undefined"&&(f=f.step(l)),f=f.onChange(()=>{this.setTargetValue(e,o,h[m],g)}),S&&f.listen()})})}setTargetValue(t,e,s,i){const{onChange:o,target:r,value:a}=this.guiParams[t][e],l=e.toLowerCase().indexOf("color")>-1;if(r&&!(typeof a=="undefined"&&r)){let g=r();Array.isArray(g)||(g=[g]),g.forEach(_=>{if(_)if(l)try{_[i||e].set(s)}catch(C){e!=="color"&&!i&&console.warn(`${e} is not a color,set paramMap`)}else _[i||e]=s})}o&&o(s)}setTargetValueByParams(){Object.keys(this.guiParams).forEach(t=>{Object.keys(this.guiParams[t]).forEach(e=>{const s=this.guiParams[t][e];typeof s.value!="undefined"&&this.setTargetValue(t,e,s.value,s.paramMap)})})}}const me={fov:45,near:1,far:1e3,up:new x.Vector3(0,1,0)};class _e{constructor(t){this.customCamera=!1,this.syncCamera=null,this.options=t;const{width:e,height:s,cameraParams:i}=t;if(i instanceof x.Camera)this.camera=i,this.customCamera=!0;else{const{fov:o,far:r,near:a,up:l}=i,c=new x.PerspectiveCamera(o,e/s,a,r);c.position.set(0,0,400),c.lookAt(0,0,0),c.up=l,this.camera=c}}setSize(t,e){this.camera instanceof x.PerspectiveCamera&&(this.camera.aspect=t/e),this.camera.updateProjectionMatrix(),this.camera2&&(this.camera2.aspect=t/e,this.camera2.updateProjectionMatrix())}addCamera2(){const t=new x.PerspectiveCamera(this.camera.fov,this.camera.aspect,this.camera.near,this.camera.far);return t.position.copy(this.camera.position),this.camera2=t,t}sync(){this.syncCamera&&!(this.camera.matrixWorld.equals(this.syncCamera.matrixWorld)&&this.camera.far===this.syncCamera.far&&this.camera.near===this.syncCamera.near&&this.camera.fov===this.syncCamera.fov&&this.camera.aspect===this.syncCamera.aspect)&&this.camera.copy(this.syncCamera)}setGui(t){const e=new gt({camera:ht(B({},this.options.cameraControls?{}:{x:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},y:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},z:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position}}),{near:{min:0,max:1e3,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}},far:{min:0,max:2e4,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}})});this.camera instanceof x.PerspectiveCamera&&(e.guiParams.camera.fov={min:0,max:90,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}),e.showGui(t)}}const pe={background:null,addCamera:!0};class ue{constructor(t){this.overrideMaterial=!1,this.options=t;const{camera:e,sceneParams:s}=t,{background:i,addCamera:o}=s,r=new x.Scene;i&&(r.background=i),o&&r.add(e),this.scene=r}dispose(){var t;(t=this.scene)==null||t.traverse(e=>{Xt.disposeMesh(e)})}}class fe{constructor(t){this.helpers={},this.options=t}add(t){const e=t.uuid,{scene:s}=this.options;let i=this.helpers[e];if(i===void 0){if(t.isScene)i=new x.AxesHelper(100);else if(t.isCamera)i=new x.CameraHelper(t);else if(t.isPointLight)i=new x.PointLightHelper(t,1);else if(t.isDirectionalLight)i=new x.DirectionalLightHelper(t,1);else if(t.isSpotLight)i=new x.SpotLightHelper(t);else if(t.isHemisphereLight)i=new x.HemisphereLightHelper(t,10);else if(t.isRectAreaLight)i=new Kt.RectAreaLightHelper(t);else{const o=new x.Box3;if(o.setFromObject(t,!0),o.isEmpty()===!1){i=new x.Box3Helper(o);const r=i.material;r.userData.object=t,r.depthTest=!1,r.transparent=!0}else return}s.add(i),this.helpers[e]=i}}remove(t){var i;const e=t.uuid,{scene:s}=this.options;if(this.helpers[e]!==void 0){const o=this.helpers[e];s.remove(o),delete this.helpers[e],(i=o.dispose)==null||i.call(o)}}removeAll(){Object.keys(this.helpers).forEach(t=>{this.remove({uuid:t})}),this.helpers={}}removeAllExcludeScene(){Object.keys(this.helpers).forEach(t=>{this.helpers[t]instanceof x.AxesHelper||this.remove({uuid:t})})}update(){Object.values(this.helpers).forEach(t=>{if(t.update&&t.update(),t instanceof x.Box3Helper){const e=t.material,{object:s}=e.userData;s&&t.box.setFromObject(s,!0)}})}dispose(){this.helpers={}}}class ge{constructor(t){this.autoRotateSpeed=0,this.options=t;const{camera:e,controlsParams:s,customControl:i}=t,{domElement:o}=s;if(i){const r=new i(e,o);r.enableDamping=!0,r.dampingFactor=.063,r.autoRotate=!1,r.autoRotateSpeed=-60,r.enableZoom=!0,r.zoomSpeed=.2,this.controls=r}else N.install({THREE:x}),this.cameraControls=new N(e,o)}addCameraControls2(t){const{controlsParams:e}=this.options,{domElement:s}=e;this.cameraControls2=new N(t,s),this.cameraControls2.addEventListener("update",()=>{this.cameraControls.enabled=!1}),this.cameraControls2.addEventListener("sleep",()=>{this.cameraControls.enabled=!0})}enable(){this.controls?this.controls.enabled=!0:this.cameraControls&&(this.cameraControls.enabled=!0,this.cameraControls2&&(this.cameraControls2.enabled=!0))}disable(){this.controls?this.controls.enabled=!1:this.cameraControls&&(this.cameraControls.enabled=!1,this.cameraControls2&&(this.cameraControls2.enabled=!1))}update(t){var e,s,i;(e=this.controls)==null||e.update(),(s=this.cameraControls)==null||s.update(t),(i=this.cameraControls2)==null||i.update(t),this.autoRotateSpeed&&this.cameraControls&&(this.cameraControls.azimuthAngle+=this.autoRotateSpeed*t*x.MathUtils.DEG2RAD)}dispose(){var t,e,s;(t=this.controls)==null||t.dispose(),(e=this.cameraControls)==null||e.dispose(),(s=this.cameraControls2)==null||s.dispose()}}class Ce{constructor(t){this.event=new Rt.eventsExports.EventEmitter;const{renderer:e,scene:s,camera:i}=t,o=new Qt.TransformControls(i,e.domElement);s.add(o),this.controls=o,this.addEvent()}get detach(){return this.controls.detach.bind(this.controls)}get attach(){return this.controls.attach.bind(this.controls)}addEvent(){let t=null,e=null,s=null;const i=this.controls;i.addEventListener("change",()=>{const o=i.object;o!==void 0&&this.event.emit("change",o)}),i.addEventListener("mouseDown",()=>{const o=i.object;t=o.position.clone(),e=o.rotation.clone(),s=o.scale.clone(),this.event.emit("mouseDown",o)}),i.addEventListener("mouseUp",()=>{const o=i.object;if(o!==void 0)switch(i.getMode()){case"translate":t.equals(o.position)||this.event.emit("translate",o,o.position,t);break;case"rotate":e.equals(o.rotation)||this.event.emit("rotate",o,o.rotation,e);break;case"scale":s.equals(o.scale)||this.event.emit("scale",o,o.scale,s);break}this.event.emit("mouseUp")})}dispose(){var t;this.event.removeAllListeners(),(t=this.controls)==null||t.dispose()}}const Ut={zIndex:"auto"};class ye{constructor(t){this.container=t}addRenderer(t,e){const s=e.container||this.container,i=s.offsetWidth,o=s.offsetHeight,r=t==="css2d"?new Jt.CSS2DRenderer:new Wt.CSS3DRenderer;r.domElement.style.position="absolute",r.domElement.style.top="0",r.domElement.style.pointerEvents="none",r.domElement.style.zIndex=e.zIndex,r.setSize(i,o),s.appendChild(r.domElement),t==="css2d"?this.css2Drenderer=r:t==="css3d"&&(this.css3Drenderer=r)}setSize(t,e){var s,i;(s=this.css2Drenderer)==null||s.setSize(t,e),(i=this.css3Drenderer)==null||i.setSize(t,e)}render(t,e){var s,i;(s=this.css2Drenderer)==null||s.render(t,e),(i=this.css3Drenderer)==null||i.render(t,e)}dispose(){var t,e;(t=this.css2Drenderer)==null||t.domElement.remove(),(e=this.css3Drenderer)==null||e.domElement.remove(),this.css2Drenderer=void 0,this.css3Drenderer=void 0}}const Ee={name:"OutputShader",uniforms:{tDiffuse:{value:null},toneMappingExposure:{value:1},premultiplieAlpha:{value:0}},vertexShader:`
1
+ "use strict";var Ht=Object.defineProperty,Vt=Object.defineProperties;var kt=Object.getOwnPropertyDescriptors;var Ct=Object.getOwnPropertySymbols;var Nt=Object.prototype.hasOwnProperty,Bt=Object.prototype.propertyIsEnumerable;var yt=(d,t,e)=>t in d?Ht(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,B=(d,t)=>{for(var e in t||(t={}))Nt.call(t,e)&&yt(d,e,t[e]);if(Ct)for(var e of Ct(t))Bt.call(t,e)&&yt(d,e,t[e]);return d},ht=(d,t)=>Vt(d,kt(t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const ft=require("three"),Yt=require("@tweenjs/tween.js"),Rt=require("./events.js"),Zt=require("deepmerge"),jt=require("stats-gl"),qt=require("lil-gui"),Gt=require("./colorCorrection.js"),Xt=require("./disposeMesh.js");require("idb-keyval");require("esus-lite");require("d3-geo");require("d3-geo-projection");const Kt=require("three/examples/jsm/helpers/RectAreaLightHelper"),Qt=require("three/examples/jsm/controls/TransformControls"),Wt=require("three/examples/jsm/renderers/CSS3DRenderer"),Jt=require("three/examples/jsm/renderers/CSS2DRenderer"),Et=require("three/examples/jsm/postprocessing/EffectComposer"),$t=require("three/examples/jsm/postprocessing/RenderPass"),te=require("three/examples/jsm/postprocessing/Pass"),ee=require("three/examples/jsm/postprocessing/OutputPass"),se=require("three/examples/jsm/postprocessing/ShaderPass"),ie=require("three/examples/jsm/postprocessing/UnrealBloomPass"),oe=require("./isPlainObject.js"),re=require("./BaseObject.js");function At(d){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(d){for(const e in d)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(d,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>d[e]})}}return t.default=d,Object.freeze(t)}const x=At(ft),Ot=At(Yt),R={LEFT:1,RIGHT:2,MIDDLE:4},n=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}),Y={NONE:0,IN:1,OUT:-1};function V(d){return d.isPerspectiveCamera}function H(d){return d.isOrthographicCamera}const Z=Math.PI*2,Tt=Math.PI/2,Lt=1e-5,G=Math.PI/180;function F(d,t,e){return Math.max(t,Math.min(e,d))}function D(d,t=Lt){return Math.abs(d)<t}function w(d,t,e=Lt){return D(d-t,e)}function vt(d,t){return Math.round(d/t)*t}function X(d){return isFinite(d)?d:d<0?-Number.MAX_VALUE:Number.MAX_VALUE}function K(d){return Math.abs(d)<Number.MAX_VALUE?d:d*(1/0)}function et(d,t,e,s,i=1/0,o){s=Math.max(1e-4,s);const r=2/s,a=r*o,l=1/(1+a+.48*a*a+.235*a*a*a);let c=d-t;const g=t,_=i*s;c=F(c,-_,_),t=d-c;const C=(e.value+r*c)*o;e.value=(e.value-r*C)*l;let p=t+(c+C)*l;return g-d>0==p>g&&(p=g,e.value=(p-g)/o),p}function xt(d,t,e,s,i=1/0,o,r){s=Math.max(1e-4,s);const a=2/s,l=a*o,c=1/(1+l+.48*l*l+.235*l*l*l);let g=t.x,_=t.y,C=t.z,p=d.x-g,P=d.y-_,f=d.z-C;const S=g,h=_,m=C,y=i*s,u=y*y,v=p*p+P*P+f*f;if(v>u){const at=Math.sqrt(v);p=p/at*y,P=P/at*y,f=f/at*y}g=d.x-p,_=d.y-P,C=d.z-f;const O=(e.x+a*p)*o,U=(e.y+a*P)*o,A=(e.z+a*f)*o;e.x=(e.x-a*O)*c,e.y=(e.y-a*U)*c,e.z=(e.z-a*A)*c,r.x=g+(p+O)*c,r.y=_+(P+U)*c,r.z=C+(f+A)*c;const $=S-d.x,tt=h-d.y,zt=m-d.z,Ft=r.x-S,Mt=r.y-h,It=r.z-m;return $*Ft+tt*Mt+zt*It>0&&(r.x=S,r.y=h,r.z=m,e.x=(r.x-S)/o,e.y=(r.y-h)/o,e.z=(r.z-m)/o),r}function lt(d,t){t.set(0,0),d.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=d.length,t.y/=d.length}function ct(d,t){return H(d)?(console.warn(`${t} is not supported in OrthographicCamera`),!0):!1}class ne{constructor(){this._listeners={}}addEventListener(t,e){const s=this._listeners;s[t]===void 0&&(s[t]=[]),s[t].indexOf(e)===-1&&s[t].push(e)}hasEventListener(t,e){const s=this._listeners;return s[t]!==void 0&&s[t].indexOf(e)!==-1}removeEventListener(t,e){const i=this._listeners[t];if(i!==void 0){const o=i.indexOf(e);o!==-1&&i.splice(o,1)}}removeAllEventListeners(t){if(!t){this._listeners={};return}Array.isArray(this._listeners[t])&&(this._listeners[t].length=0)}dispatchEvent(t){const s=this._listeners[t.type];if(s!==void 0){t.target=this;const i=s.slice(0);for(let o=0,r=i.length;o<r;o++)i[o].call(this,t)}}}const st=1/8,ae=/Mac/.test(navigator.platform);let E,Pt,it,dt,L,T,b,j,Q,M,I,k,bt,St,z,W,q,wt,mt,Dt,_t,pt,ot;class N extends ne{static install(t){E=t.THREE,Pt=Object.freeze(new E.Vector3(0,0,0)),it=Object.freeze(new E.Vector3(0,1,0)),dt=Object.freeze(new E.Vector3(0,0,1)),L=new E.Vector2,T=new E.Vector3,b=new E.Vector3,j=new E.Vector3,Q=new E.Vector3,M=new E.Vector3,I=new E.Vector3,k=new E.Vector3,bt=new E.Vector3,St=new E.Vector3,z=new E.Spherical,W=new E.Spherical,q=new E.Box3,wt=new E.Box3,mt=new E.Sphere,Dt=new E.Quaternion,_t=new E.Quaternion,pt=new E.Matrix4,ot=new E.Raycaster}static get ACTION(){return n}constructor(t,e){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=n.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=Y.NONE,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new E.Vector3,this._focalOffsetVelocity=new E.Vector3,this._zoomVelocity={value:0},this._truckInternal=(h,m,y)=>{let u,v;if(V(this._camera)){const O=T.copy(this._camera.position).sub(this._target),U=this._camera.getEffectiveFOV()*G,A=O.length()*Math.tan(U*.5);u=this.truckSpeed*h*A/this._elementRect.height,v=this.truckSpeed*m*A/this._elementRect.height}else if(H(this._camera)){const O=this._camera;u=h*(O.right-O.left)/O.zoom/this._elementRect.width,v=m*(O.top-O.bottom)/O.zoom/this._elementRect.height}else return;this.verticalDragToForward?(y?this.setFocalOffset(this._focalOffsetEnd.x+u,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(u,0,!0),this.forward(-v,!0)):y?this.setFocalOffset(this._focalOffsetEnd.x+u,this._focalOffsetEnd.y+v,this._focalOffsetEnd.z,!0):this.truck(u,v,!0)},this._rotateInternal=(h,m)=>{const y=Z*this.azimuthRotateSpeed*h/this._elementRect.height,u=Z*this.polarRotateSpeed*m/this._elementRect.height;this.rotate(y,u,!0)},this._dollyInternal=(h,m,y)=>{const u=Math.pow(.95,-h*this.dollySpeed),v=this._sphericalEnd.radius,O=this._sphericalEnd.radius*u,U=F(O,this.minDistance,this.maxDistance),A=U-O;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(O,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(A,!0),this._dollyToNoClamp(U,!0)):this._dollyToNoClamp(U,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?O:U)-v,this._dollyControlCoord.set(m,y)),this._lastDollyDirection=Math.sign(-h)},this._zoomInternal=(h,m,y)=>{const u=Math.pow(.95,h*this.dollySpeed),v=this._zoom,O=this._zoom*u;this.zoomTo(O,!0),this.dollyToCursor&&(this._changedZoom+=O-v,this._dollyControlCoord.set(m,y))},typeof E=="undefined"&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=t,this._yAxisUpSpace=new E.Quaternion().setFromUnitVectors(this._camera.up,it),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=n.NONE,this._target=new E.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new E.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new E.Spherical().setFromVector3(T.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 E.Vector3,new E.Vector3,new E.Vector3,new E.Vector3],this._updateNearPlaneCorners(),this._boundary=new E.Box3(new E.Vector3(-1/0,-1/0,-1/0),new E.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 E.Vector2,this.mouseButtons={left:n.ROTATE,middle:n.DOLLY,right:n.TRUCK,wheel:V(this._camera)?n.DOLLY:H(this._camera)?n.ZOOM:n.NONE},this.touches={one:n.TOUCH_ROTATE,two:V(this._camera)?n.TOUCH_DOLLY_TRUCK:H(this._camera)?n.TOUCH_ZOOM_TRUCK:n.NONE,three:n.TOUCH_TRUCK};const s=new E.Vector2,i=new E.Vector2,o=new E.Vector2,r=h=>{if(!this._enabled||!this._domElement)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const u=this._domElement.getBoundingClientRect(),v=(h.clientX-u.left)/(u.right-u.left),O=(h.clientY-u.top)/(u.bottom-u.top);if(v<this._interactiveArea.left||v>this._interactiveArea.right||O<this._interactiveArea.top||O>this._interactiveArea.bottom)return}const m=h.pointerType!=="mouse"?null:(h.buttons&R.LEFT)===R.LEFT?R.LEFT:(h.buttons&R.MIDDLE)===R.MIDDLE?R.MIDDLE:(h.buttons&R.RIGHT)===R.RIGHT?R.RIGHT:null;if(m!==null){const u=this._findPointerByMouseButton(m);u&&this._disposePointer(u)}if((h.buttons&R.LEFT)===R.LEFT&&this._lockedPointer)return;const y={pointerId:h.pointerId,clientX:h.clientX,clientY:h.clientY,deltaX:0,deltaY:0,mouseButton:m};this._activePointers.push(y),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",l),this._isDragging=!0,C(h)},a=h=>{h.cancelable&&h.preventDefault();const m=h.pointerId,y=this._lockedPointer||this._findPointerById(m);if(y){if(y.clientX=h.clientX,y.clientY=h.clientY,y.deltaX=h.movementX,y.deltaY=h.movementY,this._state=0,h.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(h.buttons&R.LEFT)===R.LEFT)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(h.buttons&R.MIDDLE)===R.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(h.buttons&R.RIGHT)===R.RIGHT&&(this._state=this._state|this.mouseButtons.right);p()}},l=h=>{const m=this._findPointerById(h.pointerId);if(!(m&&m===this._lockedPointer)){if(m&&this._disposePointer(m),h.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=n.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=n.NONE;P()}};let c=-1;const g=h=>{if(!this._domElement||!this._enabled||this.mouseButtons.wheel===n.NONE)return;if(this._interactiveArea.left!==0||this._interactiveArea.top!==0||this._interactiveArea.width!==1||this._interactiveArea.height!==1){const O=this._domElement.getBoundingClientRect(),U=(h.clientX-O.left)/(O.right-O.left),A=(h.clientY-O.top)/(O.bottom-O.top);if(U<this._interactiveArea.left||U>this._interactiveArea.right||A<this._interactiveArea.top||A>this._interactiveArea.bottom)return}if(h.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===n.ROTATE||this.mouseButtons.wheel===n.TRUCK){const O=performance.now();c-O<1e3&&this._getClientRect(this._elementRect),c=O}const m=ae?-1:-3,y=h.deltaMode===1?h.deltaY/m:h.deltaY/(m*10),u=this.dollyToCursor?(h.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,v=this.dollyToCursor?(h.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case n.ROTATE:{this._rotateInternal(h.deltaX,h.deltaY),this._isUserControllingRotate=!0;break}case n.TRUCK:{this._truckInternal(h.deltaX,h.deltaY,!1),this._isUserControllingTruck=!0;break}case n.OFFSET:{this._truckInternal(h.deltaX,h.deltaY,!0),this._isUserControllingOffset=!0;break}case n.DOLLY:{this._dollyInternal(-y,u,v),this._isUserControllingDolly=!0;break}case n.ZOOM:{this._zoomInternal(-y,u,v),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},_=h=>{if(!(!this._domElement||!this._enabled)){if(this.mouseButtons.right===N.ACTION.NONE){const m=h instanceof PointerEvent?h.pointerId:0,y=this._findPointerById(m);y&&this._disposePointer(y),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l);return}h.preventDefault()}},C=h=>{if(!this._enabled)return;if(lt(this._activePointers,L),this._getClientRect(this._elementRect),s.copy(L),i.copy(L),this._activePointers.length>=2){const y=L.x-this._activePointers[1].clientX,u=L.y-this._activePointers[1].clientY,v=Math.sqrt(y*y+u*u);o.set(0,v);const O=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,U=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;i.set(O,U)}if(this._state=0,!h)this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);else if("pointerType"in h&&h.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else!this._lockedPointer&&(h.buttons&R.LEFT)===R.LEFT&&(this._state=this._state|this.mouseButtons.left),(h.buttons&R.MIDDLE)===R.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(h.buttons&R.RIGHT)===R.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&n.ROTATE)===n.ROTATE||(this._state&n.TOUCH_ROTATE)===n.TOUCH_ROTATE||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_ZOOM_ROTATE)===n.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&n.TRUCK)===n.TRUCK||(this._state&n.TOUCH_TRUCK)===n.TOUCH_TRUCK||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&n.DOLLY)===n.DOLLY||(this._state&n.TOUCH_DOLLY)===n.TOUCH_DOLLY||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&n.ZOOM)===n.ZOOM||(this._state&n.TOUCH_ZOOM)===n.TOUCH_ZOOM||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET||(this._state&n.TOUCH_ZOOM_ROTATE)===n.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&n.OFFSET)===n.OFFSET||(this._state&n.TOUCH_OFFSET)===n.TOUCH_OFFSET||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},p=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,lt(this._activePointers,L);const m=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,y=m?-m.deltaX:i.x-L.x,u=m?-m.deltaY:i.y-L.y;if(i.copy(L),((this._state&n.ROTATE)===n.ROTATE||(this._state&n.TOUCH_ROTATE)===n.TOUCH_ROTATE||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_ZOOM_ROTATE)===n.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(y,u),this._isUserControllingRotate=!0),(this._state&n.DOLLY)===n.DOLLY||(this._state&n.ZOOM)===n.ZOOM){const v=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,O=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0,U=this.dollyDragInverted?-1:1;(this._state&n.DOLLY)===n.DOLLY?(this._dollyInternal(U*u*st,v,O),this._isUserControllingDolly=!0):(this._zoomInternal(U*u*st,v,O),this._isUserControllingZoom=!0)}if((this._state&n.TOUCH_DOLLY)===n.TOUCH_DOLLY||(this._state&n.TOUCH_ZOOM)===n.TOUCH_ZOOM||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_ZOOM_ROTATE)===n.TOUCH_ZOOM_ROTATE){const v=L.x-this._activePointers[1].clientX,O=L.y-this._activePointers[1].clientY,U=Math.sqrt(v*v+O*O),A=o.y-U;o.set(0,U);const $=this.dollyToCursor?(i.x-this._elementRect.x)/this._elementRect.width*2-1:0,tt=this.dollyToCursor?(i.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&n.TOUCH_DOLLY)===n.TOUCH_DOLLY||(this._state&n.TOUCH_DOLLY_ROTATE)===n.TOUCH_DOLLY_ROTATE||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET?(this._dollyInternal(A*st,$,tt),this._isUserControllingDolly=!0):(this._zoomInternal(A*st,$,tt),this._isUserControllingZoom=!0)}((this._state&n.TRUCK)===n.TRUCK||(this._state&n.TOUCH_TRUCK)===n.TOUCH_TRUCK||(this._state&n.TOUCH_DOLLY_TRUCK)===n.TOUCH_DOLLY_TRUCK||(this._state&n.TOUCH_ZOOM_TRUCK)===n.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(y,u,!1),this._isUserControllingTruck=!0),((this._state&n.OFFSET)===n.OFFSET||(this._state&n.TOUCH_OFFSET)===n.TOUCH_OFFSET||(this._state&n.TOUCH_DOLLY_OFFSET)===n.TOUCH_DOLLY_OFFSET||(this._state&n.TOUCH_ZOOM_OFFSET)===n.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(y,u,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},P=()=>{lt(this._activePointers,L),i.copy(L),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("pointerup",l),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",l),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",f),this._domElement.ownerDocument.addEventListener("pointerlockerror",S),this._domElement.ownerDocument.addEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",l),C())},this.unlockPointer=()=>{var h,m,y;this._lockedPointer!==null&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),(h=this._domElement)===null||h===void 0||h.ownerDocument.exitPointerLock(),(m=this._domElement)===null||m===void 0||m.ownerDocument.removeEventListener("pointerlockchange",f),(y=this._domElement)===null||y===void 0||y.ownerDocument.removeEventListener("pointerlockerror",S),this.cancel()};const f=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},S=()=>{this.unlockPointer()};this._addAllEventListeners=h=>{this._domElement=h,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",r),this._domElement.addEventListener("pointercancel",l),this._domElement.addEventListener("wheel",g,{passive:!1}),this._domElement.addEventListener("contextmenu",_)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",r),this._domElement.removeEventListener("pointercancel",l),this._domElement.removeEventListener("wheel",g,{passive:!1}),this._domElement.removeEventListener("contextmenu",_),this._domElement.ownerDocument.removeEventListener("pointermove",a,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",l),this._domElement.ownerDocument.removeEventListener("pointerlockchange",f),this._domElement.ownerDocument.removeEventListener("pointerlockerror",S))},this.cancel=()=>{this._state!==n.NONE&&(this._state=n.NONE,this._activePointers.length=0,P())},e&&this.connect(e),this.update(0)}get camera(){return this._camera}set camera(t){this._camera=t,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(t){this._enabled=t,this._domElement&&(t?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(t){this._spherical.radius===t&&this._sphericalEnd.radius===t||(this._spherical.radius=t,this._sphericalEnd.radius=t,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(t){this._spherical.theta===t&&this._sphericalEnd.theta===t||(this._spherical.theta=t,this._sphericalEnd.theta=t,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(t){this._spherical.phi===t&&this._sphericalEnd.phi===t||(this._spherical.phi=t,this._sphericalEnd.phi=t,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(t){this._boundaryEnclosesCamera=t,this._needsUpdate=!0}set interactiveArea(t){this._interactiveArea.width=F(t.width,0,1),this._interactiveArea.height=F(t.height,0,1),this._interactiveArea.x=F(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=F(t.y,0,1-this._interactiveArea.height)}addEventListener(t,e){super.addEventListener(t,e)}removeEventListener(t,e){super.removeEventListener(t,e)}rotate(t,e,s=!1){return this.rotateTo(this._sphericalEnd.theta+t,this._sphericalEnd.phi+e,s)}rotateAzimuthTo(t,e=!1){return this.rotateTo(t,this._sphericalEnd.phi,e)}rotatePolarTo(t,e=!1){return this.rotateTo(this._sphericalEnd.theta,t,e)}rotateTo(t,e,s=!1){this._isUserControllingRotate=!1;const i=F(t,this.minAzimuthAngle,this.maxAzimuthAngle),o=F(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=i,this._sphericalEnd.phi=o,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const r=!s||w(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&w(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(r)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Y.NONE,this._changedDolly=0,this._dollyToNoClamp(F(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const s=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const r=this._collisionTest(),a=w(r,this._spherical.radius);if(!(s>t)&&a)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,r)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const o=!e||w(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(o)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(Q).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const s=!e||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(s)}zoom(t,e=!1){return this.zoomTo(this._zoomEnd+t,e)}zoomTo(t,e=!1){this._isUserControllingZoom=!1,this._zoomEnd=F(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const s=!e||w(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(s)}pan(t,e,s=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(t,e,s)}truck(t,e,s=!1){this._camera.updateMatrix(),M.setFromMatrixColumn(this._camera.matrix,0),I.setFromMatrixColumn(this._camera.matrix,1),M.multiplyScalar(t),I.multiplyScalar(-e);const i=T.copy(M).add(I),o=b.copy(this._targetEnd).add(i);return this.moveTo(o.x,o.y,o.z,s)}forward(t,e=!1){T.setFromMatrixColumn(this._camera.matrix,0),T.crossVectors(this._camera.up,T),T.multiplyScalar(t);const s=b.copy(this._targetEnd).add(T);return this.moveTo(s.x,s.y,s.z,e)}elevate(t,e=!1){return T.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+T.x,this._targetEnd.y+T.y,this._targetEnd.z+T.z,e)}moveTo(t,e,s,i=!1){this._isUserControllingTruck=!1;const o=T.set(t,e,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,o,this.boundaryFriction),this._needsUpdate=!0,i||this._target.copy(this._targetEnd);const r=!i||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}lookInDirectionOf(t,e,s,i=!1){const a=T.set(t,e,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(a.x,a.y,a.z,i)}fitToBox(t,e,{cover:s=!1,paddingLeft:i=0,paddingRight:o=0,paddingBottom:r=0,paddingTop:a=0}={}){const l=[],c=t.isBox3?q.copy(t):q.setFromObject(t);c.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const g=vt(this._sphericalEnd.theta,Tt),_=vt(this._sphericalEnd.phi,Tt);l.push(this.rotateTo(g,_,e));const C=T.setFromSpherical(this._sphericalEnd).normalize(),p=Dt.setFromUnitVectors(C,dt),P=w(Math.abs(C.y),1);P&&p.multiply(_t.setFromAxisAngle(it,g)),p.multiply(this._yAxisUpSpaceInverse);const f=wt.makeEmpty();b.copy(c.min).applyQuaternion(p),f.expandByPoint(b),b.copy(c.min).setX(c.max.x).applyQuaternion(p),f.expandByPoint(b),b.copy(c.min).setY(c.max.y).applyQuaternion(p),f.expandByPoint(b),b.copy(c.max).setZ(c.min.z).applyQuaternion(p),f.expandByPoint(b),b.copy(c.min).setZ(c.max.z).applyQuaternion(p),f.expandByPoint(b),b.copy(c.max).setY(c.min.y).applyQuaternion(p),f.expandByPoint(b),b.copy(c.max).setX(c.min.x).applyQuaternion(p),f.expandByPoint(b),b.copy(c.max).applyQuaternion(p),f.expandByPoint(b),f.min.x-=i,f.min.y-=r,f.max.x+=o,f.max.y+=a,p.setFromUnitVectors(dt,C),P&&p.premultiply(_t.invert()),p.premultiply(this._yAxisUpSpace);const S=f.getSize(T),h=f.getCenter(b).applyQuaternion(p);if(V(this._camera)){const m=this.getDistanceToFitBox(S.x,S.y,S.z,s);l.push(this.moveTo(h.x,h.y,h.z,e)),l.push(this.dollyTo(m,e)),l.push(this.setFocalOffset(0,0,0,e))}else if(H(this._camera)){const m=this._camera,y=m.right-m.left,u=m.top-m.bottom,v=s?Math.max(y/S.x,u/S.y):Math.min(y/S.x,u/S.y);l.push(this.moveTo(h.x,h.y,h.z,e)),l.push(this.zoomTo(v,e)),l.push(this.setFocalOffset(0,0,0,e))}return Promise.all(l)}fitToSphere(t,e){const s=[],o="isObject3D"in t?N.createBoundingSphere(t,mt):mt.copy(t);if(s.push(this.moveTo(o.center.x,o.center.y,o.center.z,e)),V(this._camera)){const r=this.getDistanceToFitSphere(o.radius);s.push(this.dollyTo(r,e))}else if(H(this._camera)){const r=this._camera.right-this._camera.left,a=this._camera.top-this._camera.bottom,l=2*o.radius,c=Math.min(r/l,a/l);s.push(this.zoomTo(c,e))}return s.push(this.setFocalOffset(0,0,0,e)),Promise.all(s)}setLookAt(t,e,s,i,o,r,a=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Y.NONE,this._changedDolly=0;const l=b.set(i,o,r),c=T.set(t,e,s);this._targetEnd.copy(l),this._sphericalEnd.setFromVector3(c.sub(l).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,a||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const g=!a||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(this._target.z,this._targetEnd.z,this.restThreshold)&&w(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&w(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&w(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(g)}lerpLookAt(t,e,s,i,o,r,a,l,c,g,_,C,p,P=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Y.NONE,this._changedDolly=0;const f=T.set(i,o,r),S=b.set(t,e,s);z.setFromVector3(S.sub(f).applyQuaternion(this._yAxisUpSpace));const h=j.set(g,_,C),m=b.set(a,l,c);W.setFromVector3(m.sub(h).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(f.lerp(h,p));const y=W.theta-z.theta,u=W.phi-z.phi,v=W.radius-z.radius;this._sphericalEnd.set(z.radius+v*p,z.phi+u*p,z.theta+y*p),this.normalizeRotations(),this._needsUpdate=!0,P||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const O=!P||w(this._target.x,this._targetEnd.x,this.restThreshold)&&w(this._target.y,this._targetEnd.y,this.restThreshold)&&w(this._target.z,this._targetEnd.z,this.restThreshold)&&w(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&w(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&w(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(O)}setPosition(t,e,s,i=!1){return this.setLookAt(t,e,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,i)}setTarget(t,e,s,i=!1){const o=this.getPosition(T),r=this.setLookAt(o.x,o.y,o.z,t,e,s,i);return this._sphericalEnd.phi=F(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),r}setFocalOffset(t,e,s,i=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,s),this._needsUpdate=!0,i||this._focalOffset.copy(this._focalOffsetEnd);const o=!i||w(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&w(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&w(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(o)}setOrbitPoint(t,e,s){this._camera.updateMatrixWorld(),M.setFromMatrixColumn(this._camera.matrixWorldInverse,0),I.setFromMatrixColumn(this._camera.matrixWorldInverse,1),k.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const i=T.set(t,e,s),o=i.distanceTo(this._camera.position),r=i.sub(this._camera.position);M.multiplyScalar(r.x),I.multiplyScalar(r.y),k.multiplyScalar(r.z),T.copy(M).add(I).add(k),T.z=T.z+o,this.dollyTo(o,!1),this.setFocalOffset(-T.x,T.y,-T.z,!1),this.moveTo(t,e,s,!1)}setBoundary(t){if(!t){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(t),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(t,e,s,i){if(t===null){this._viewport=null;return}this._viewport=this._viewport||new E.Vector4,typeof t=="number"?this._viewport.set(t,e,s,i):this._viewport.copy(t)}getDistanceToFitBox(t,e,s,i=!1){if(ct(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const o=t/e,r=this._camera.getEffectiveFOV()*G,a=this._camera.aspect;return((i?o>a:o<a)?e:t/a)*.5/Math.tan(r*.5)+s*.5}getDistanceToFitSphere(t){if(ct(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*G,s=Math.atan(Math.tan(e*.5)*this._camera.aspect)*2,i=1<this._camera.aspect?e:s;return t/Math.sin(i*.5)}getTarget(t,e=!0){return(t&&t.isVector3?t:new E.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new E.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new E.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new E.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%Z,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=Z),this._spherical.theta+=Z*Math.round((this._sphericalEnd.theta-this._spherical.theta)/Z)}reset(t=!1){if(!w(this._camera.up.x,this._cameraUp0.x)||!w(this._camera.up.y,this._cameraUp0.y)||!w(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const s=this.getPosition(T);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}const e=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,t),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,t),this.zoomTo(this._zoom0,t)];return Promise.all(e)}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,it),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=T.subVectors(this._target,this._camera.position).normalize(),e=b.crossVectors(t,this._camera.up);this._camera.up.crossVectors(e,t).normalize(),this._camera.updateMatrixWorld();const s=this.getPosition(T);this.updateCameraUp(),this.setPosition(s.x,s.y,s.z)}update(t){const e=this._sphericalEnd.theta-this._spherical.theta,s=this._sphericalEnd.phi-this._spherical.phi,i=this._sphericalEnd.radius-this._spherical.radius,o=bt.subVectors(this._targetEnd,this._target),r=St.subVectors(this._focalOffsetEnd,this._focalOffset),a=this._zoomEnd-this._zoom;if(D(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const _=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=et(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,_,1/0,t),this._needsUpdate=!0}if(D(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const _=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=et(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,_,1/0,t),this._needsUpdate=!0}if(D(i))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const _=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=et(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,_,this.maxSpeed,t),this._needsUpdate=!0}if(D(o.x)&&D(o.y)&&D(o.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const _=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;xt(this._target,this._targetEnd,this._targetVelocity,_,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(D(r.x)&&D(r.y)&&D(r.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const _=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;xt(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,_,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(D(a))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const _=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=et(this._zoom,this._zoomEnd,this._zoomVelocity,_,1/0,t)}if(this.dollyToCursor){if(V(this._camera)&&this._changedDolly!==0){const _=this._spherical.radius-this._lastDistance,C=this._camera,p=this._getCameraDirection(Q),P=T.copy(p).cross(C.up).normalize();P.lengthSq()===0&&(P.x=1);const f=b.crossVectors(P,p),S=this._sphericalEnd.radius*Math.tan(C.getEffectiveFOV()*G*.5),m=(this._sphericalEnd.radius-_-this._sphericalEnd.radius)/this._sphericalEnd.radius,y=j.copy(this._targetEnd).add(P.multiplyScalar(this._dollyControlCoord.x*S*C.aspect)).add(f.multiplyScalar(this._dollyControlCoord.y*S)),u=T.copy(this._targetEnd).lerp(y,m),v=this._lastDollyDirection===Y.IN&&this._spherical.radius<=this.minDistance,O=this._lastDollyDirection===Y.OUT&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(v||O)){this._sphericalEnd.radius-=_,this._spherical.radius-=_;const A=b.copy(p).multiplyScalar(-_);u.add(A)}this._boundary.clampPoint(u,u);const U=b.subVectors(u,this._targetEnd);this._targetEnd.copy(u),this._target.add(U),this._changedDolly-=_,D(this._changedDolly)&&(this._changedDolly=0)}else if(H(this._camera)&&this._changedZoom!==0){const _=this._zoom-this._lastZoom,C=this._camera,p=T.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(C.near+C.far)/(C.near-C.far)).unproject(C),P=b.set(0,0,-1).applyQuaternion(C.quaternion),f=j.copy(p).add(P.multiplyScalar(-p.dot(C.up))),h=-(this._zoom-_-this._zoom)/this._zoom,m=this._getCameraDirection(Q),y=this._targetEnd.dot(m),u=T.copy(this._targetEnd).lerp(f,h),v=u.dot(m),O=m.multiplyScalar(v-y);u.sub(O),this._boundary.clampPoint(u,u);const U=b.subVectors(u,this._targetEnd);this._targetEnd.copy(u),this._target.add(U),this._changedZoom-=_,D(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 l=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,l),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!D(this._focalOffset.x)||!D(this._focalOffset.y)||!D(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),M.setFromMatrixColumn(this._camera.matrix,0),I.setFromMatrixColumn(this._camera.matrix,1),k.setFromMatrixColumn(this._camera.matrix,2),M.multiplyScalar(this._focalOffset.x),I.multiplyScalar(-this._focalOffset.y),k.multiplyScalar(this._focalOffset.z),T.copy(M).add(I).add(k),this._camera.position.add(T)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),T.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const g=this._needsUpdate;return g&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):g?(this.dispatchEvent({type:"update"}),D(e,this.restThreshold)&&D(s,this.restThreshold)&&D(i,this.restThreshold)&&D(o.x,this.restThreshold)&&D(o.y,this.restThreshold)&&D(o.z,this.restThreshold)&&D(r.x,this.restThreshold)&&D(r.y,this.restThreshold)&&D(r.z,this.restThreshold)&&D(a,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!g&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=g,this._needsUpdate=!1,g}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:X(this.maxDistance),minZoom:this.minZoom,maxZoom:X(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:X(this.maxPolarAngle),minAzimuthAngle:X(this.minAzimuthAngle),maxAzimuthAngle:X(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:T.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(t,e=!1){const s=JSON.parse(t);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=K(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=K(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=K(s.maxPolarAngle),this.minAzimuthAngle=K(s.minAzimuthAngle),this.maxAzimuthAngle=K(s.maxAzimuthAngle),this.smoothTime=s.smoothTime,this.draggingSmoothTime=s.draggingSmoothTime,this.dollySpeed=s.dollySpeed,this.truckSpeed=s.truckSpeed,this.dollyToCursor=s.dollyToCursor,this.verticalDragToForward=s.verticalDragToForward,this._target0.fromArray(s.target0),this._position0.fromArray(s.position0),this._zoom0=s.zoom0,this._focalOffset0.fromArray(s.focalOffset0),this.moveTo(s.target[0],s.target[1],s.target[2],e),z.setFromVector3(T.fromArray(s.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(z.theta,z.phi,e),this.dollyTo(z.radius,e),this.zoomTo(s.zoom,e),this.setFocalOffset(s.focalOffset[0],s.focalOffset[1],s.focalOffset[2],e),this._needsUpdate=!0}connect(t){if(this._domElement){console.warn("camera-controls is already connected.");return}this._addAllEventListeners(t),this._getClientRect(this._elementRect)}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_getTargetDirection(t){return t.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse)}_getCameraDirection(t){return this._getTargetDirection(t).negate()}_findPointerById(t){return this._activePointers.find(e=>e.pointerId===t)}_findPointerByMouseButton(t){return this._activePointers.find(e=>e.mouseButton===t)}_disposePointer(t){this._activePointers.splice(this._activePointers.indexOf(t),1)}_encloseToBoundary(t,e,s){const i=e.lengthSq();if(i===0)return t;const o=b.copy(e).add(t),a=this._boundary.clampPoint(o,j).sub(o),l=a.lengthSq();if(l===0)return t.add(e);if(l===i)return t;if(s===0)return t.add(e).add(a);{const c=1+s*l/e.dot(a);return t.add(b.copy(e).multiplyScalar(c)).add(a.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(V(this._camera)){const t=this._camera,e=t.near,s=t.getEffectiveFOV()*G,i=Math.tan(s*.5)*e,o=i*t.aspect;this._nearPlaneCorners[0].set(-o,-i,0),this._nearPlaneCorners[1].set(o,-i,0),this._nearPlaneCorners[2].set(o,i,0),this._nearPlaneCorners[3].set(-o,i,0)}else if(H(this._camera)){const t=this._camera,e=1/t.zoom,s=t.left*e,i=t.right*e,o=t.top*e,r=t.bottom*e;this._nearPlaneCorners[0].set(s,o,0),this._nearPlaneCorners[1].set(i,o,0),this._nearPlaneCorners[2].set(i,r,0),this._nearPlaneCorners[3].set(s,r,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1)||ct(this._camera,"_collisionTest"))return t;const s=this._getTargetDirection(Q);pt.lookAt(Pt,s,this._camera.up);for(let i=0;i<4;i++){const o=b.copy(this._nearPlaneCorners[i]);o.applyMatrix4(pt);const r=j.addVectors(this._target,o);ot.set(r,s),ot.far=this._spherical.radius+1;const a=ot.intersectObjects(this.colliderMeshes);a.length!==0&&a[0].distance<t&&(t=a[0].distance)}return t}_getClientRect(t){if(!this._domElement)return;const e=this._domElement.getBoundingClientRect();return t.x=e.left,t.y=e.top,this._viewport?(t.x+=this._viewport.x,t.y+=e.height-this._viewport.w-this._viewport.y,t.width=this._viewport.z,t.height=this._viewport.w):(t.width=e.width,t.height=e.height),t}_createOnRestPromise(t){return t?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(e=>{const s=()=>{this.removeEventListener("rest",s),e()};this.addEventListener("rest",s)}))}_addAllEventListeners(t){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(t){console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead.")}get draggingDampingFactor(){return console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead."),0}set draggingDampingFactor(t){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(t,e=new E.Sphere){const s=e,i=s.center;q.makeEmpty(),t.traverseVisible(r=>{r.isMesh&&q.expandByObject(r)}),q.getCenter(i);let o=0;return t.traverseVisible(r=>{if(!r.isMesh)return;const a=r,l=a.geometry.clone();l.applyMatrix4(a.matrixWorld);const g=l.attributes.position;for(let _=0,C=g.count;_<C;_++)T.fromBufferAttribute(g,_),o=Math.max(o,i.distanceToSquared(T))}),s.radius=Math.sqrt(o),s}}const he={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMappingExposure:1,alpha:!1,outputColorSpace:Gt.ColorSpace.sRGB,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,stencil:!1,depth:!1,physicallyCorrectLights:!1};class le{constructor(t){this.options=t;const{width:e,height:s,rendererParams:i}=t,{canvas:o,context:r,alpha:a,devicePixelRatio:l,antialias:c,powerPreference:g,toneMappingExposure:_,outputColorSpace:C,logarithmicDepthBuffer:p,preserveDrawingBuffer:P,stencil:f,depth:S,physicallyCorrectLights:h}=i,m=new x.WebGLRenderer({canvas:o,context:r,alpha:a,antialias:c,powerPreference:g,logarithmicDepthBuffer:p,preserveDrawingBuffer:P,stencil:f,depth:S});m.setSize(e,s),m.setPixelRatio(l),m.toneMappingExposure=_,m.outputColorSpace=C,+x.REVISION<155&&(m.useLegacyLights=h),this.renderer=m}setSize(t,e){this.renderer.setSize(t,e)}setPixelRatio(t){this.renderer.setPixelRatio(t)}render(t){const{scene:e,camera:s}=this.options;this.renderer.render(e,t||s)}dispose(){var t,e;this.setSize(1,1),(t=this.renderer)==null||t.clear(),(e=this.renderer)==null||e.dispose()}}const ce={antialias:!0,devicePixelRatio:window.devicePixelRatio};class de{constructor(t){this.options=t;const{width:e,height:s,rendererParams:i,renderer:o}=t,{devicePixelRatio:r,antialias:a}=i,l=new o({antialias:a});l.setSize(e,s),l.setPixelRatio(r),this.renderer=l}setSize(t,e){this.renderer.setSize(t,e)}render(t){const{scene:e,camera:s}=this.options;this.renderer.render(e,t||s)}dispose(){var t,e;this.setSize(1,1),(t=this.renderer)==null||t.clear(),(e=this.renderer)==null||e.dispose()}}class gt{constructor(t){this.guiParams={},t&&(this.guiParams=t)}showGui(t){t&&Object.keys(this.guiParams).forEach(e=>{const s=t.addFolder(e),i=this.guiParams[e];Object.keys(i).forEach(o=>{const{min:r,max:a,step:l,name:c,paramMap:g,items:_,value:C,target:p}=i[o],P=o.toLowerCase().indexOf("color")>-1;let f;const S=typeof C=="undefined"&&p,h=S?p():i[o],m=S?o:"value";_?f=s.add(h,m,_):P?f=s.addColor(h,m):f=s.add(h,m),f=f.name(c||o),typeof r!="undefined"&&(f=f.min(r)),typeof a!="undefined"&&(f=f.max(a)),typeof l!="undefined"&&(f=f.step(l)),f=f.onChange(()=>{this.setTargetValue(e,o,h[m],g)}),S&&f.listen()})})}setTargetValue(t,e,s,i){const{onChange:o,target:r,value:a}=this.guiParams[t][e],l=e.toLowerCase().indexOf("color")>-1;if(r&&!(typeof a=="undefined"&&r)){let g=r();Array.isArray(g)||(g=[g]),g.forEach(_=>{if(_)if(l)try{_[i||e].set(s)}catch(C){e!=="color"&&!i&&console.warn(`${e} is not a color,set paramMap`)}else _[i||e]=s})}o&&o(s)}setTargetValueByParams(){Object.keys(this.guiParams).forEach(t=>{Object.keys(this.guiParams[t]).forEach(e=>{const s=this.guiParams[t][e];typeof s.value!="undefined"&&this.setTargetValue(t,e,s.value,s.paramMap)})})}}const me={fov:45,near:1,far:1e3,up:new x.Vector3(0,1,0)};class _e{constructor(t){this.customCamera=!1,this.syncCamera=null,this.options=t;const{width:e,height:s,cameraParams:i}=t;if(i instanceof x.Camera)this.camera=i,this.customCamera=!0;else{const{fov:o,far:r,near:a,up:l}=i,c=new x.PerspectiveCamera(o,e/s,a,r);c.position.set(0,0,400),c.lookAt(0,0,0),c.up=l,this.camera=c}}setSize(t,e){this.camera instanceof x.PerspectiveCamera&&(this.camera.aspect=t/e),this.camera.updateProjectionMatrix(),this.camera2&&(this.camera2.aspect=t/e,this.camera2.updateProjectionMatrix())}addCamera2(){const t=new x.PerspectiveCamera(this.camera.fov,this.camera.aspect,this.camera.near,this.camera.far);return t.position.copy(this.camera.position),this.camera2=t,t}sync(){this.syncCamera&&!(this.camera.matrixWorld.equals(this.syncCamera.matrixWorld)&&this.camera.far===this.syncCamera.far&&this.camera.near===this.syncCamera.near&&this.camera.fov===this.syncCamera.fov&&this.camera.aspect===this.syncCamera.aspect)&&this.camera.copy(this.syncCamera)}setGui(t){const e=new gt({camera:ht(B({},this.options.cameraControls?{}:{x:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},y:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},z:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position}}),{near:{min:0,max:1e3,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}},far:{min:0,max:2e4,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}})});this.camera instanceof x.PerspectiveCamera&&(e.guiParams.camera.fov={min:0,max:90,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}),e.showGui(t)}}const pe={background:null,addCamera:!0};class ue{constructor(t){this.overrideMaterial=!1,this.options=t;const{camera:e,sceneParams:s}=t,{background:i,addCamera:o}=s,r=new x.Scene;i&&(r.background=i),o&&r.add(e),this.scene=r}dispose(){var t;(t=this.scene)==null||t.traverse(e=>{Xt.disposeMesh(e)})}}class fe{constructor(t){this.helpers={},this.options=t}add(t){const e=t.uuid,{scene:s}=this.options;let i=this.helpers[e];if(i===void 0){if(t.isScene)i=new x.AxesHelper(100);else if(t.isCamera)i=new x.CameraHelper(t);else if(t.isPointLight)i=new x.PointLightHelper(t,1);else if(t.isDirectionalLight)i=new x.DirectionalLightHelper(t,1);else if(t.isSpotLight)i=new x.SpotLightHelper(t);else if(t.isHemisphereLight)i=new x.HemisphereLightHelper(t,10);else if(t.isRectAreaLight)i=new Kt.RectAreaLightHelper(t);else{const o=new x.Box3;if(o.setFromObject(t,!0),o.isEmpty()===!1){i=new x.Box3Helper(o);const r=i.material;r.userData.object=t,r.depthTest=!1,r.transparent=!0}else return}s.add(i),this.helpers[e]=i}}remove(t){var i;const e=t.uuid,{scene:s}=this.options;if(this.helpers[e]!==void 0){const o=this.helpers[e];s.remove(o),delete this.helpers[e],(i=o.dispose)==null||i.call(o)}}removeAll(){Object.keys(this.helpers).forEach(t=>{this.remove({uuid:t})}),this.helpers={}}removeAllExcludeScene(){Object.keys(this.helpers).forEach(t=>{this.helpers[t]instanceof x.AxesHelper||this.remove({uuid:t})})}update(){Object.values(this.helpers).forEach(t=>{if(t.update&&t.update(),t instanceof x.Box3Helper){const e=t.material,{object:s}=e.userData;s&&t.box.setFromObject(s,!0)}})}dispose(){this.helpers={}}}class ge{constructor(t){this.autoRotateSpeed=0,this.options=t;const{camera:e,controlsParams:s,customControl:i}=t,{domElement:o}=s;if(i){const r=new i(e,o);r.enableDamping=!0,r.dampingFactor=.063,r.autoRotate=!1,r.autoRotateSpeed=-60,r.enableZoom=!0,r.zoomSpeed=.2,this.controls=r}else N.install({THREE:x}),this.cameraControls=new N(e,o)}addCameraControls2(t){const{controlsParams:e}=this.options,{domElement:s}=e;this.cameraControls2=new N(t,s),this.cameraControls2.addEventListener("update",()=>{this.cameraControls.enabled=!1}),this.cameraControls2.addEventListener("sleep",()=>{this.cameraControls.enabled=!0})}enable(){this.controls?this.controls.enabled=!0:this.cameraControls&&(this.cameraControls.enabled=!0,this.cameraControls2&&(this.cameraControls2.enabled=!0))}disable(){this.controls?this.controls.enabled=!1:this.cameraControls&&(this.cameraControls.enabled=!1,this.cameraControls2&&(this.cameraControls2.enabled=!1))}update(t){var e,s,i;(e=this.controls)==null||e.update(),(s=this.cameraControls)==null||s.update(t),(i=this.cameraControls2)==null||i.update(t),this.autoRotateSpeed&&this.cameraControls&&(this.cameraControls.azimuthAngle+=this.autoRotateSpeed*t*x.MathUtils.DEG2RAD)}dispose(){var t,e,s;(t=this.controls)==null||t.dispose(),(e=this.cameraControls)==null||e.dispose(),(s=this.cameraControls2)==null||s.dispose()}}class Ce{constructor(t){this.event=new Rt.eventsExports.EventEmitter;const{renderer:e,scene:s,camera:i}=t,o=new Qt.TransformControls(i,e.domElement);s.add(o),this.controls=o,this.addEvent()}get detach(){return this.controls.detach.bind(this.controls)}get attach(){return this.controls.attach.bind(this.controls)}addEvent(){let t=null,e=null,s=null;const i=this.controls;i.addEventListener("change",()=>{const o=i.object;o!==void 0&&this.event.emit("change",o)}),i.addEventListener("mouseDown",()=>{const o=i.object;t=o.position.clone(),e=o.rotation.clone(),s=o.scale.clone(),this.event.emit("mouseDown",o)}),i.addEventListener("mouseUp",()=>{const o=i.object;if(o!==void 0)switch(i.getMode()){case"translate":t.equals(o.position)||this.event.emit("translate",o,o.position,t);break;case"rotate":e.equals(o.rotation)||this.event.emit("rotate",o,o.rotation,e);break;case"scale":s.equals(o.scale)||this.event.emit("scale",o,o.scale,s);break}this.event.emit("mouseUp")})}dispose(){var t;this.event.removeAllListeners(),(t=this.controls)==null||t.dispose()}}const Ut={zIndex:"auto"};class ye{constructor(t){this.container=t}addRenderer(t,e){const s=e.container||this.container,i=s.offsetWidth,o=s.offsetHeight,r=t==="css2d"?new Jt.CSS2DRenderer:new Wt.CSS3DRenderer;r.domElement.style.position="absolute",r.domElement.style.top="0",r.domElement.style.pointerEvents="none",r.domElement.style.zIndex=e.zIndex,r.setSize(i,o),s.appendChild(r.domElement),t==="css2d"?this.css2Drenderer=r:t==="css3d"&&(this.css3Drenderer=r)}setSize(t,e){var s,i;(s=this.css2Drenderer)==null||s.setSize(t,e),(i=this.css3Drenderer)==null||i.setSize(t,e)}render(t,e){var s,i;(s=this.css2Drenderer)==null||s.render(t,e),(i=this.css3Drenderer)==null||i.render(t,e)}dispose(){var t,e;(t=this.css2Drenderer)==null||t.domElement.remove(),(e=this.css3Drenderer)==null||e.domElement.remove(),this.css2Drenderer=void 0,this.css3Drenderer=void 0}}const Ee={name:"OutputShader",uniforms:{tDiffuse:{value:null},toneMappingExposure:{value:1},premultiplieAlpha:{value:0}},vertexShader:`
2
2
  precision highp float;
3
3
 
4
4
  uniform mat4 modelViewMatrix;
@@ -70,25 +70,25 @@
70
70
 
71
71
  #endif
72
72
 
73
- }`};class Oe extends ee.OutputPass{constructor(){super();const t=Ee;this.uniforms=ft.UniformsUtils.clone(t.uniforms),this.material=new ft.RawShaderMaterial({name:t.name,uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader}),this.fsQuad=new te.FullScreenQuad(this.material)}}const ut=1,J=!1,Te={threshold:0,strength:.4,radius:.1,bloomAlphaType:0},ve={multisampling:4,premultiplieAlpha:!1};class xe{constructor(t){this.bloomComposerActive=!1,this.active=!0,this.bloomSelection=new Set,this.bloomLayer=new x.Layers,this.bloomVisible={},this.transformControlsVisible=!1,this.options=t;const{renderer:e,scene:s,camera:i,composerParams:o}=t,{multisampling:r}=o,{maxSamples:a}=e.capabilities,l=e.getDrawingBufferSize(new x.Vector2),c=new x.WebGLRenderTarget(l.width,l.height,{samples:Math.min(r,a),type:x.HalfFloatType}),g=new $t.RenderPass(s,i),_=new Et.EffectComposer(e,c);_.addPass(g),this.renderer=e,this.scene=s,this.camera=i,this.finalComposer=_,this.renderPass=g;const C=e.getSize(new x.Vector2);this.setSize(C.width,C.height)}setRenderPassCamera(t){this.renderPass.camera=t}resetRenderPassCamera(){this.renderPass.camera=this.camera}addOutputPass(){const{premultiplieAlpha:t}=this.options.composerParams,e=new Oe;this.outputPass=e,this.setPremultiplieAlpha(t),this.finalComposer.addPass(e)}setPremultiplieAlpha(t){this.outputPass&&(this.outputPass.uniforms.premultiplieAlpha.value=t?1:0)}addBloomPass(t){const{renderer:e}=this,{threshold:s,strength:i,radius:o,bloomAlphaType:r}=t,a=new ie.UnrealBloomPass(new x.Vector2(window.innerWidth,window.innerHeight),i,o,s);this.bloomPass=a;const l=new Et.EffectComposer(e);l.renderToScreen=!1,l.addPass(this.renderPass),l.addPass(a),this.bloomComposer=l;const c=new se.ShaderPass(new x.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:l.renderTarget2.texture},bloomAlphaType:{value:r}},vertexShader:`
74
- varying vec2 vUv;
75
- void main() {
76
- vUv = uv;
77
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
78
- }
79
- `,fragmentShader:`
80
- uniform sampler2D baseTexture;
81
- uniform sampler2D bloomTexture;
82
- uniform float bloomAlphaType;
83
- varying vec2 vUv;
73
+ }`};class Oe extends ee.OutputPass{constructor(){super();const t=Ee;this.uniforms=ft.UniformsUtils.clone(t.uniforms),this.material=new ft.RawShaderMaterial({name:t.name,uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader}),this.fsQuad=new te.FullScreenQuad(this.material)}}const Te=d=>{const t=new se.ShaderPass(new x.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:d.renderTarget2.texture},bloomAlphaType:{value:0}},vertexShader:`
74
+ varying vec2 vUv;
84
75
  void main() {
85
- vec4 base_color = texture2D(baseTexture, vUv);
86
- vec4 bloom_color = texture2D(bloomTexture, vUv);
87
- if (bloomAlphaType == 0.0){
88
- float lum = 0.21 * bloom_color.r + 0.71 * bloom_color.g + 0.07 * bloom_color.b;
89
- gl_FragColor = vec4(base_color.rgb + bloom_color.rgb, max(base_color.a, lum));
90
- }else{
91
- gl_FragColor = ( base_color + vec4( 1.0 ) * bloom_color );
92
- }
76
+ vUv = uv;
77
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
78
+ }
79
+ `,fragmentShader:`
80
+ uniform sampler2D baseTexture;
81
+ uniform sampler2D bloomTexture;
82
+ uniform float bloomAlphaType;
83
+ varying vec2 vUv;
84
+ void main() {
85
+ vec4 base_color = texture2D(baseTexture, vUv);
86
+ vec4 bloom_color = texture2D(bloomTexture, vUv);
87
+ if (bloomAlphaType == 0.0){
88
+ float lum = 0.21 * bloom_color.r + 0.71 * bloom_color.g + 0.07 * bloom_color.b;
89
+ gl_FragColor = vec4(base_color.rgb + bloom_color.rgb, max(base_color.a, lum));
90
+ }else{
91
+ gl_FragColor = ( base_color + vec4( 1.0 ) * bloom_color );
93
92
  }
94
- `,defines:{}}),"baseTexture");c.needsSwap=!0,this.bloomComposer=l,this.finalComposer.addPass(c),this.mixPass=c,this.bloomLayer.set(ut)}addBloomGui(t){if(!this.bloomComposer)return;new gt({bloom:{threshold:{min:0,max:1,step:.01,target:()=>this.bloomPass},radius:{min:0,max:1,step:.001,target:()=>this.bloomPass},strength:{min:0,max:10,step:.001,target:()=>this.bloomPass}}}).showGui(t)}toggleBloomSelection(t,e){if(!this.bloomComposer){console.warn("err:pencil.options.bloom");return}const{object3d:s}=t;if(!s)return;let i=e;e===void 0&&(i=!this.bloomSelection.has(s)),i?(this.bloomSelection.add(s),s.layers.enable(ut)):(this.bloomSelection.delete(s),s.layers.disable(ut)),this.bloomSelection.size===0?this.bloomComposerActive=!1:this.bloomComposerActive=!0}enable(){this.active||(this.active=!0)}disable(){this.active&&(this.active=!1)}setSize(t,e){var s;(s=this.bloomComposer)==null||s.setSize(t,e),this.finalComposer.setSize(t,e)}setPixelRatio(t){var e;(e=this.bloomComposer)==null||e.setPixelRatio(t),this.finalComposer.setPixelRatio(t)}darkenNonBloomed(){const t=this.scene.children.find(e=>e.isTransformControls);t&&(this.transformControlsVisible=t.visible,this.transformControlsVisible&&(t.visible=!1)),this.scene.traverse(e=>{const s=e;t&&t.getObjectById(s.id)||s.material&&this.bloomLayer.test(s.layers)===!1&&(this.bloomVisible[s.uuid]=s.visible,s.visible=!1)})}restoreNonBloomed(){if(this.transformControlsVisible){const t=this.scene.children.find(e=>e.isTransformControls);t&&(t.visible=!0)}this.scene.traverse(t=>{const e=t;this.bloomVisible[e.uuid]&&(e.visible=this.bloomVisible[e.uuid],delete this.bloomVisible[e.uuid])})}render(){this.active&&(this.bloomComposerActive&&this.bloomComposer?(this.mixPass.enabled=!0,this.darkenNonBloomed(),this.bloomComposer.render(),this.restoreNonBloomed()):this.mixPass&&(this.mixPass.enabled=!1),this.finalComposer.render())}render2(){this.active}dispose(){var t;this.bloomVisible={},this.bloomSelection.clear(),this.finalComposer.dispose(),(t=this.bloomComposer)==null||t.dispose()}}const nt=class nt{constructor(t,e){this.raycaster=new x.Raycaster,this.installPlugins=new Map,this.event=new Rt.eventsExports.EventEmitter,this.clock=new x.Clock,this.userData={},this.pipViewportState=!1,this.options=Zt(nt.options,t,{isMergeableObject:oe.isPlainObject}),this.event.setMaxListeners(1/0);const{container:s,stats:i,gui:o,resizeObserver:r}=this.options;if(o){const a=new qt;a.open(!1),this.gui=a}if(this.init(),i){const a=new jt({horizontal:!1});a.init(this.renderer),a.dom.style.position="absolute",s.appendChild(a.dom),this.stats=a}this.options.WebGPUTHREE||this.initComposer(),this.initCSSRenderer(),this.initControls(),r&&this.initResizeObserver(),this.clock.getDelta(),this.clock.getElapsedTime(),e&&(Array.isArray(e)||(e=[e]),e.forEach(a=>{Array.isArray(a)||(a=[a]),this.use(a[0],a[1])}))}getPlugin(t){return this.installPlugins.get(t)}get renderer(){return this.rendererController.renderer}get maxAnisotropy(){return this.options.WebGPUTHREE?0:this.renderer.capabilities.getMaxAnisotropy()}get cameraControls(){return this.controlsController.cameraControls}get cameraPositon(){return this.cameraControls.getPosition(new x.Vector3,!1)}get cameraTarget(){return this.cameraControls.getTarget(new x.Vector3,!1)}get camera(){return this.cameraController.camera}get scene(){return this.sceneController.scene}use(t,...e){this.installPlugins.has(t.pluginName)?console.log("plugin already installed"):typeof t.install=="function"&&(t.install(this,...e),this.installPlugins.set(t.pluginName,t))}init(){const{container:t,isdev:e,WebGPUTHREE:s,helper:i,renderer:o,scene:r,camera:a,control:l}=this.options,{width:c,height:g}=this.getSize(),_=new _e({isdev:e,width:c,height:g,cameraParams:a,cameraControls:l===!0});this.gui&&_.setGui(this.gui);const C=_.camera,p=new ue({camera:C,sceneParams:r}),P=p.scene,f=s?new de({width:c,height:g,scene:P,camera:C,isdev:e,renderer:s.WebGPURenderer,rendererParams:ce}):new le({width:c,height:g,scene:P,camera:C,isdev:e,rendererParams:ht(B({},o),{antialias:!1})});if(i){const S=new fe({scene:P});S.add(P),this.helperController=S}this.sceneController=p,this.rendererController=f,this.cameraController=_,t.appendChild(f.renderer.domElement)}initComposer(){const{bloom:t,bloomParams:e,composer:s}=this.options,i=new xe({renderer:this.renderer,scene:this.scene,camera:this.camera,composerParams:s});this.composerController=i,t&&(i.addBloomPass(B({},e)),this.gui&&i.addBloomGui(this.gui)),i.addOutputPass()}initCSSRenderer(){const{container:t,css2DRenderer:e,css3DRenderer:s,css2DRendererParams:i,css3DRendererParams:o}=this.options;if(e||s){const r=new ye(t);e&&r.addRenderer("css2d",i),s&&r.addRenderer("css3d",o),this.cssRendererController=r}}initControls(){const{control:t,controlParams:e,transformControls:s}=this.options;if(t){const i=new ge({camera:this.camera,controlsParams:{domElement:(e==null?void 0:e.domElement)||this.renderer.domElement},customControl:typeof t=="boolean"?void 0:t});this.controlsController=i}if(s){const i=new Ce({camera:this.camera,renderer:this.renderer,scene:this.scene});i.event.on("mouseDown",()=>{var o;(o=this.controlsController)==null||o.disable()}),i.event.on("mouseUp",()=>{var o;(o=this.controlsController)==null||o.enable()}),this.transformController=i}}getSize(){const{container:t}=this.options;return{width:t.offsetWidth,height:t.offsetHeight}}initResizeObserver(){const{container:t}=this.options;if(this.resizeObserver)return;const e=this.getSize(),s=new ResizeObserver(i=>{for(const o of i){const r=o.contentRect;(r.width!==e.width||r.height!==e.height)&&(e.width=r.width,e.height=r.height,this.handeleResize(r.width,r.height),this.render())}});s.observe(t),this.resizeObserver=s}handeleResize(t,e,s=!0){const{rendererController:i,cameraController:o,composerController:r,cssRendererController:a}=this;o==null||o.setSize(t,e),i==null||i.setSize(t,e),r==null||r.setSize(t,e),a==null||a.setSize(t,e),this.installPlugins.forEach(l=>{var c;(c=l.setSize)==null||c.call(l,t,e)}),s&&this.event.emit("resize",{width:t,height:e})}setDevicePixelRatio(t){var e;this.rendererController.setPixelRatio(t),(e=this.composerController)==null||e.setPixelRatio(t)}pick(t,e,s=!0){const{raycaster:i,options:o}=this,{container:r}=o,a=new x.Vector2,l=r.getBoundingClientRect();if(a.x=(t.clientX-l.left)/(l.right-l.left)*2-1,a.y=-((t.clientY-l.top)/(l.bottom-l.top))*2+1,this.camera&&this.scene){i.setFromCamera(a,this.camera);const c=i.intersectObjects(e||this.scene.children,s);if(c.length)return{object:c[0].object,intersects:c}}}render(){var r,a,l,c,g,_;const{scene:t,camera:e,clock:s}=this,i=s.getDelta(),o=s.getElapsedTime();Ot.update(),(r=this.controlsController)==null||r.update(i),this.installPlugins.forEach(C=>{var p;(p=C.update)==null||p.call(C,i,o)}),(a=this.helperController)==null||a.update(),this.cameraController.sync(),(l=this.composerController)!=null&&l.active?this.cameraController.camera2?(this.composerController.resetRenderPassCamera(),this.setViewportFull(),this.composerController.render(),this.pipViewportState&&(this.setViewportPip(),this.composerController.setRenderPassCamera(this.cameraController.camera2),this.composerController.render())):this.composerController.render():(c=this.rendererController)==null||c.render(),(g=this.cssRendererController)==null||g.render(t,e),(_=this.stats)==null||_.update(),this.event.emit("render",{delta:i,elapsed:o})}start(){this.renderer.setAnimationLoop(this.render.bind(this)),this.event.emit("start")}stop(){this.renderer.setAnimationLoop(null),this.event.emit("stop")}autoRotate(t){this.controlsController.autoRotateSpeed=t}showPipViewport(t){if(t===!0){const e=this.getSize(),s=240,i=s/e.width,o=s/e.height,r=1-i,a=1-o;t={left:r,top:a,width:i,height:o}}if(this.pipViewportState=t,t){if(this.controlsController.cameraControls2)this.controlsController.cameraControls2.enabled=!0,this.cameraController.camera2.position.copy(this.cameraController.camera.position);else{const e=this.cameraController.addCamera2();this.controlsController.addCameraControls2(e)}this.controlsController.cameraControls2.interactiveArea=new DOMRect(t.left,t.top,t.width,t.height)}else this.controlsController.cameraControls2&&(this.controlsController.cameraControls2.enabled=!1)}setViewportFull(){const t=this.getSize(),e=0,s=0,i=t.width,o=t.height,r=i/o;this.camera.aspect!==r&&(this.camera.aspect=r,this.camera.updateProjectionMatrix()),this.renderer.setViewport(e,s,i,o),this.renderer.setScissor(e,s,i,o),this.renderer.setScissorTest(!0)}setViewportPip(){if(!this.pipViewportState)return;const t=this.pipViewportState,e=this.getSize(),s=e.width*t.left,i=(1-(t.top+t.height))*e.height,o=e.width*t.width,r=e.height*t.height,a=o/r,l=this.cameraController.camera2;l&&l.aspect!==a&&(l.aspect=a,l.updateProjectionMatrix()),this.renderer.setViewport(s,i,o,r),this.renderer.setScissor(s,i,o,r),this.renderer.setScissorTest(!0)}dispose(){var t,e,s,i,o,r,a,l,c,g,_;this.stop(),Ot.removeAll(),this.event.removeAllListeners(),(t=this.resizeObserver)==null||t.unobserve(this.options.container),this.installPlugins.forEach(C=>{var p;(p=C.dispose)==null||p.call(C)}),(e=this.controlsController)==null||e.dispose(),(s=this.transformController)==null||s.dispose(),(i=this.cssRendererController)==null||i.dispose(),(o=this.sceneController)==null||o.dispose(),(r=this.helperController)==null||r.dispose(),(a=this.composerController)==null||a.dispose(),(l=this.rendererController)==null||l.dispose(),this.cssRendererController=void 0,(c=this.gui)==null||c.destroy(),this.installPlugins.clear(),(g=this.stats)==null||g.dom.remove(),(_=this.renderer)==null||_.domElement.remove()}};nt.options={isdev:J,stats:J,gui:J,helper:J,control:!0,transformControls:J,resizeObserver:!0,renderer:he,composer:ve,scene:pe,camera:me,bloom:!1,bloomParams:Te,css2DRenderer:!1,css2DRendererParams:B({},Ut),css3DRenderer:!1,css3DRendererParams:B({},Ut)};let rt=nt;const Pe=N.ACTION;exports.BaseObject=re.BaseObject;exports.GUIObject=gt;exports.Pencil=rt;exports.cameraControlsAction=Pe;exports.default=rt;
93
+ }
94
+ `,defines:{}}),"baseTexture");return t.needsSwap=!0,t},ut=1,J=!1,ve={threshold:0,strength:.4,radius:.1,bloomAlphaType:0},xe={multisampling:4,premultiplieAlpha:!1};class Pe{constructor(t){this.bloomComposerActive=!1,this.active=!0,this.bloomSelection=new Set,this.bloomLayer=new x.Layers,this.bloomVisible={},this.transformControlsVisible=!1,this.options=t;const{renderer:e,scene:s,camera:i,composerParams:o}=t,{multisampling:r}=o,{maxSamples:a}=e.capabilities,l=e.getDrawingBufferSize(new x.Vector2),c=new x.WebGLRenderTarget(l.width,l.height,{samples:Math.min(r,a),type:x.HalfFloatType}),g=new $t.RenderPass(s,i),_=new Et.EffectComposer(e,c);_.addPass(g),this.renderer=e,this.scene=s,this.camera=i,this.finalComposer=_,this.renderPass=g;const C=e.getSize(new x.Vector2);this.setSize(C.width,C.height)}setRenderPassCamera(t){this.renderPass.camera=t}resetRenderPassCamera(){this.renderPass.camera=this.camera}addOutputPass(){const{premultiplieAlpha:t}=this.options.composerParams,e=new Oe;this.outputPass=e,this.setPremultiplieAlpha(t),this.finalComposer.addPass(e)}setPremultiplieAlpha(t){this.outputPass&&(this.outputPass.uniforms.premultiplieAlpha.value=t?1:0)}addBloomPass(t){const{renderer:e}=this,{threshold:s,strength:i,radius:o,bloomAlphaType:r}=t,a=new ie.UnrealBloomPass(new x.Vector2(window.innerWidth,window.innerHeight),i,o,s);this.bloomPass=a;const l=new Et.EffectComposer(e);l.renderToScreen=!1,l.addPass(this.renderPass),l.addPass(a),this.bloomComposer=l;const c=Te(l);c.uniforms.bloomAlphaType.value=r,this.bloomComposer=l,this.finalComposer.addPass(c),this.mixPass=c,this.bloomLayer.set(ut)}addBloomGui(t){if(!this.bloomComposer)return;new gt({bloom:{threshold:{min:0,max:1,step:.01,target:()=>this.bloomPass},radius:{min:0,max:1,step:.001,target:()=>this.bloomPass},strength:{min:0,max:10,step:.001,target:()=>this.bloomPass}}}).showGui(t)}toggleBloomSelection(t,e){if(!this.bloomComposer){console.warn("err:pencil.options.bloom");return}const{object3d:s}=t;if(!s)return;let i=e;e===void 0&&(i=!this.bloomSelection.has(s)),i?(this.bloomSelection.add(s),s.layers.enable(ut)):(this.bloomSelection.delete(s),s.layers.disable(ut)),this.bloomSelection.size===0?this.bloomComposerActive=!1:this.bloomComposerActive=!0}enable(){this.active||(this.active=!0)}disable(){this.active&&(this.active=!1)}setSize(t,e){var s;(s=this.bloomComposer)==null||s.setSize(t,e),this.finalComposer.setSize(t,e)}setPixelRatio(t){var e;(e=this.bloomComposer)==null||e.setPixelRatio(t),this.finalComposer.setPixelRatio(t)}darkenNonBloomed(){const t=this.scene.children.find(e=>e.isTransformControls);t&&(this.transformControlsVisible=t.visible,this.transformControlsVisible&&(t.visible=!1)),this.scene.traverse(e=>{const s=e;t&&t.getObjectById(s.id)||s.material&&this.bloomLayer.test(s.layers)===!1&&(this.bloomVisible[s.uuid]=s.visible,s.visible=!1)})}restoreNonBloomed(){if(this.transformControlsVisible){const t=this.scene.children.find(e=>e.isTransformControls);t&&(t.visible=!0)}this.scene.traverse(t=>{const e=t;this.bloomVisible[e.uuid]&&(e.visible=this.bloomVisible[e.uuid],delete this.bloomVisible[e.uuid])})}render(){this.active&&(this.bloomComposerActive&&this.bloomComposer?(this.mixPass.enabled=!0,this.darkenNonBloomed(),this.bloomComposer.render(),this.restoreNonBloomed()):this.mixPass&&(this.mixPass.enabled=!1),this.finalComposer.render())}render2(){this.active}dispose(){var t;this.bloomVisible={},this.bloomSelection.clear(),this.finalComposer.dispose(),(t=this.bloomComposer)==null||t.dispose()}}const nt=class nt{constructor(t,e){this.raycaster=new x.Raycaster,this.installPlugins=new Map,this.event=new Rt.eventsExports.EventEmitter,this.clock=new x.Clock,this.userData={},this.pipViewportState=!1,this.options=Zt(nt.options,t,{isMergeableObject:oe.isPlainObject}),this.event.setMaxListeners(1/0);const{container:s,stats:i,gui:o,resizeObserver:r}=this.options;if(o){const a=new qt;a.open(!1),this.gui=a}if(this.init(),i){const a=new jt({horizontal:!1});a.init(this.renderer),a.dom.style.position="absolute",s.appendChild(a.dom),this.stats=a}this.options.WebGPUTHREE||this.initComposer(),this.initCSSRenderer(),this.initControls(),r&&this.initResizeObserver(),this.clock.getDelta(),this.clock.getElapsedTime(),e&&(Array.isArray(e)||(e=[e]),e.forEach(a=>{Array.isArray(a)||(a=[a]),this.use(a[0],a[1])}))}getPlugin(t){return this.installPlugins.get(t)}get renderer(){return this.rendererController.renderer}get maxAnisotropy(){return this.options.WebGPUTHREE?0:this.renderer.capabilities.getMaxAnisotropy()}get cameraControls(){return this.controlsController.cameraControls}get cameraPositon(){return this.cameraControls.getPosition(new x.Vector3,!1)}get cameraTarget(){return this.cameraControls.getTarget(new x.Vector3,!1)}get camera(){return this.cameraController.camera}get scene(){return this.sceneController.scene}use(t,...e){this.installPlugins.has(t.pluginName)?console.log("plugin already installed"):typeof t.install=="function"&&(t.install(this,...e),this.installPlugins.set(t.pluginName,t))}init(){const{container:t,isdev:e,WebGPUTHREE:s,helper:i,renderer:o,scene:r,camera:a,control:l}=this.options,{width:c,height:g}=this.getSize(),_=new _e({isdev:e,width:c,height:g,cameraParams:a,cameraControls:l===!0});this.gui&&_.setGui(this.gui);const C=_.camera,p=new ue({camera:C,sceneParams:r}),P=p.scene,f=s?new de({width:c,height:g,scene:P,camera:C,isdev:e,renderer:s.WebGPURenderer,rendererParams:ce}):new le({width:c,height:g,scene:P,camera:C,isdev:e,rendererParams:ht(B({},o),{antialias:!1})});if(i){const S=new fe({scene:P});S.add(P),this.helperController=S}this.sceneController=p,this.rendererController=f,this.cameraController=_,t.appendChild(f.renderer.domElement)}initComposer(){const{bloom:t,bloomParams:e,composer:s}=this.options,i=new Pe({renderer:this.renderer,scene:this.scene,camera:this.camera,composerParams:s});this.composerController=i,t&&(i.addBloomPass(B({},e)),this.gui&&i.addBloomGui(this.gui)),i.addOutputPass()}initCSSRenderer(){const{container:t,css2DRenderer:e,css3DRenderer:s,css2DRendererParams:i,css3DRendererParams:o}=this.options;if(e||s){const r=new ye(t);e&&r.addRenderer("css2d",i),s&&r.addRenderer("css3d",o),this.cssRendererController=r}}initControls(){const{control:t,controlParams:e,transformControls:s}=this.options;if(t){const i=new ge({camera:this.camera,controlsParams:{domElement:(e==null?void 0:e.domElement)||this.renderer.domElement},customControl:typeof t=="boolean"?void 0:t});this.controlsController=i}if(s){const i=new Ce({camera:this.camera,renderer:this.renderer,scene:this.scene});i.event.on("mouseDown",()=>{var o;(o=this.controlsController)==null||o.disable()}),i.event.on("mouseUp",()=>{var o;(o=this.controlsController)==null||o.enable()}),this.transformController=i}}getSize(){const{container:t}=this.options;return{width:t.offsetWidth,height:t.offsetHeight}}initResizeObserver(){const{container:t}=this.options;if(this.resizeObserver)return;const e=this.getSize(),s=new ResizeObserver(i=>{for(const o of i){const r=o.contentRect;(r.width!==e.width||r.height!==e.height)&&(e.width=r.width,e.height=r.height,this.handeleResize(r.width,r.height),this.render())}});s.observe(t),this.resizeObserver=s}handeleResize(t,e,s=!0){const{rendererController:i,cameraController:o,composerController:r,cssRendererController:a}=this;o==null||o.setSize(t,e),i==null||i.setSize(t,e),r==null||r.setSize(t,e),a==null||a.setSize(t,e),this.installPlugins.forEach(l=>{var c;(c=l.setSize)==null||c.call(l,t,e)}),s&&this.event.emit("resize",{width:t,height:e})}setDevicePixelRatio(t){var e;this.rendererController.setPixelRatio(t),(e=this.composerController)==null||e.setPixelRatio(t)}pick(t,e,s=!0){const{raycaster:i,options:o}=this,{container:r}=o,a=new x.Vector2,l=r.getBoundingClientRect();if(a.x=(t.clientX-l.left)/(l.right-l.left)*2-1,a.y=-((t.clientY-l.top)/(l.bottom-l.top))*2+1,this.camera&&this.scene){i.setFromCamera(a,this.camera);const c=i.intersectObjects(e||this.scene.children,s);if(c.length)return{object:c[0].object,intersects:c}}}render(){var r,a,l,c,g,_;const{scene:t,camera:e,clock:s}=this,i=s.getDelta(),o=s.getElapsedTime();Ot.update(),(r=this.controlsController)==null||r.update(i),this.installPlugins.forEach(C=>{var p;(p=C.update)==null||p.call(C,i,o)}),(a=this.helperController)==null||a.update(),this.cameraController.sync(),(l=this.composerController)!=null&&l.active?this.cameraController.camera2?(this.composerController.resetRenderPassCamera(),this.setViewportFull(),this.composerController.render(),this.pipViewportState&&(this.setViewportPip(),this.composerController.setRenderPassCamera(this.cameraController.camera2),this.composerController.render())):this.composerController.render():(c=this.rendererController)==null||c.render(),(g=this.cssRendererController)==null||g.render(t,e),(_=this.stats)==null||_.update(),this.event.emit("render",{delta:i,elapsed:o})}start(){this.renderer.setAnimationLoop(this.render.bind(this)),this.event.emit("start")}stop(){this.renderer.setAnimationLoop(null),this.event.emit("stop")}autoRotate(t){this.controlsController.autoRotateSpeed=t}showPipViewport(t){if(t===!0){const e=this.getSize(),s=240,i=s/e.width,o=s/e.height,r=1-i,a=1-o;t={left:r,top:a,width:i,height:o}}if(this.pipViewportState=t,t){if(this.controlsController.cameraControls2)this.controlsController.cameraControls2.enabled=!0,this.cameraController.camera2.position.copy(this.cameraController.camera.position);else{const e=this.cameraController.addCamera2();this.controlsController.addCameraControls2(e)}this.controlsController.cameraControls2.interactiveArea=new DOMRect(t.left,t.top,t.width,t.height)}else this.controlsController.cameraControls2&&(this.controlsController.cameraControls2.enabled=!1)}setViewportFull(){const t=this.getSize(),e=0,s=0,i=t.width,o=t.height,r=i/o;this.camera.aspect!==r&&(this.camera.aspect=r,this.camera.updateProjectionMatrix()),this.renderer.setViewport(e,s,i,o),this.renderer.setScissor(e,s,i,o),this.renderer.setScissorTest(!0)}setViewportPip(){if(!this.pipViewportState)return;const t=this.pipViewportState,e=this.getSize(),s=e.width*t.left,i=(1-(t.top+t.height))*e.height,o=e.width*t.width,r=e.height*t.height,a=o/r,l=this.cameraController.camera2;l&&l.aspect!==a&&(l.aspect=a,l.updateProjectionMatrix()),this.renderer.setViewport(s,i,o,r),this.renderer.setScissor(s,i,o,r),this.renderer.setScissorTest(!0)}dispose(){var t,e,s,i,o,r,a,l,c,g,_;this.stop(),Ot.removeAll(),this.event.removeAllListeners(),(t=this.resizeObserver)==null||t.unobserve(this.options.container),this.installPlugins.forEach(C=>{var p;(p=C.dispose)==null||p.call(C)}),(e=this.controlsController)==null||e.dispose(),(s=this.transformController)==null||s.dispose(),(i=this.cssRendererController)==null||i.dispose(),(o=this.sceneController)==null||o.dispose(),(r=this.helperController)==null||r.dispose(),(a=this.composerController)==null||a.dispose(),(l=this.rendererController)==null||l.dispose(),this.cssRendererController=void 0,(c=this.gui)==null||c.destroy(),this.installPlugins.clear(),(g=this.stats)==null||g.dom.remove(),(_=this.renderer)==null||_.domElement.remove()}};nt.options={isdev:J,stats:J,gui:J,helper:J,control:!0,transformControls:J,resizeObserver:!0,renderer:he,composer:xe,scene:pe,camera:me,bloom:!1,bloomParams:ve,css2DRenderer:!1,css2DRendererParams:B({},Ut),css3DRenderer:!1,css3DRendererParams:B({},Ut)};let rt=nt;const be=N.ACTION;exports.BaseObject=re.BaseObject;exports.GUIObject=gt;exports.Pencil=rt;exports.cameraControlsAction=be;exports.default=rt;