@thatopen/components 2.0.21 → 2.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ export declare class Components implements Disposable {
6
6
  /**
7
7
  * The version of the @thatopen/components library.
8
8
  */
9
- static readonly release = "2.0.21";
9
+ static readonly release = "2.0.22";
10
10
  /** {@link Disposable.onDisposed} */
11
11
  readonly onDisposed: Event<void>;
12
12
  /**
package/dist/index.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  - If you're the tool creator, you can take one from https://www.uuidgenerator.net/.
4
4
 
5
- - If you're using a platform tool, verify the uuid isn't misspelled or contact the tool creator.`)}};I(K,"_pattern",/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/),I(K,"_lut",["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"]);let re=K;class hr extends ${constructor(t,s){super(t);I(this,"onDisposed",new D);I(this,"onVertexFound",new D);I(this,"onVertexLost",new D);I(this,"components");I(this,"workingPlane",null);I(this,"_pickedPoint",null);I(this,"_config");I(this,"_enabled",!1);this.components=t,this.config={snapDistance:.25,showOnlyVertex:!1,...s},this.enabled=!1}set enabled(t){this._enabled=t,t||(this._pickedPoint=null)}get enabled(){return this._enabled}set config(t){this._config={...this._config,...t}}get config(){return this._config}dispose(){this.onVertexFound.reset(),this.onVertexLost.reset(),this.components=null,this.onDisposed.trigger(),this.onDisposed.reset()}get(t){if(!this.enabled)return this._pickedPoint;const o=this.components.get(ae).get(t).castRay();if(!o)return this._pickedPoint!==null&&(this.onVertexLost.trigger(),this._pickedPoint=null),this._pickedPoint;const n=this.getClosestVertex(o);return n?(this.workingPlane?Math.abs(this.workingPlane.distanceToPoint(n))<.001:!0)?((this._pickedPoint===null||!this._pickedPoint.equals(n))&&(this._pickedPoint=n.clone(),this.onVertexFound.trigger(this._pickedPoint)),this._pickedPoint):(this._pickedPoint=null,this._pickedPoint):(this._pickedPoint!==null&&(this.onVertexLost.trigger(),this._pickedPoint=null),this._pickedPoint)}getClosestVertex(t){let s=new S.Vector3,i=!1,o=Number.MAX_SAFE_INTEGER;const n=this.getVertices(t);if(n===null)return null;for(const r of n){if(!r)continue;const a=t.point.distanceTo(r);a>o||a>this._config.snapDistance||(i=!0,s=r,o=t.point.distanceTo(r))}return i?s:this.config.showOnlyVertex?null:t.point}getVertices(t){const s=t.object;if(!t.face||!s)return null;const i=s.geometry,o=new S.Matrix4,{instanceId:n}=t,r=n!==void 0,a=s instanceof S.InstancedMesh;return a&&r&&s.getMatrixAt(n,o),[this.getVertex(t.face.a,i),this.getVertex(t.face.b,i),this.getVertex(t.face.c,i)].map(l=>(l&&(a&&r&&l.applyMatrix4(o),l.applyMatrix4(s.matrixWorld)),l))}getVertex(t,s){if(t===void 0)return null;const i=s.attributes.position;return new S.Vector3(i.getX(t),i.getY(t),i.getZ(t))}}const ps=class ps{constructor(){I(this,"onDisposed",new D);I(this,"list",new Map);I(this,"enabled",!1);I(this,"_clock");I(this,"update",()=>{if(!this.enabled)return;const e=this._clock.getDelta();for(const[t,s]of this.list)s.enabled&&s.isUpdateable()&&s.update(e);requestAnimationFrame(this.update)});this._clock=new S.Clock,ps.setupBVH()}add(e,t){if(this.list.has(e))throw new Error("You're trying to add a component that already exists in the components instance. Use Components.get() instead.");re.validate(e),this.list.set(e,t)}get(e){const t=e.uuid;if(!this.list.has(t)){const s=new e(this);return this.list.has(t)||this.add(t,s),s}return this.list.get(t)}init(){this.enabled=!0,this._clock.start(),this.update()}dispose(){this.enabled=!1;for(const[e,t]of this.list)t.enabled=!1,t.isDisposeable()&&t.dispose();this._clock.stop(),this.onDisposed.trigger(),this.onDisposed.reset()}static setupBVH(){S.BufferGeometry.prototype.computeBoundsTree=tr,S.BufferGeometry.prototype.disposeBoundsTree=er,S.Mesh.prototype.raycast=Jo}};I(ps,"release","2.0.21");let hs=ps;class gn{constructor(e){I(this,"_event");I(this,"_position",new S.Vector2);I(this,"onDisposed",new D);I(this,"updateMouseInfo",e=>{this._event=e});this.dom=e,this.setupEvents(!0)}get position(){if(this._event){const e=this.dom.getBoundingClientRect();this._position.x=this.getPositionX(e,this._event),this._position.y=this.getPositionY(e,this._event)}return this._position}dispose(){this.setupEvents(!1),this.onDisposed.trigger(),this.onDisposed.reset()}getPositionY(e,t){return-((t.clientY-e.top)/(e.bottom-e.top))*2+1}getPositionX(e,t){return(t.clientX-e.left)/(e.right-e.left)*2-1}setupEvents(e){e?this.dom.addEventListener("pointermove",this.updateMouseInfo):this.dom.removeEventListener("pointermove",this.updateMouseInfo)}}class Sn{constructor(e,t){I(this,"enabled",!0);I(this,"components");I(this,"onDisposed",new D);I(this,"mouse");I(this,"three",new S.Raycaster);I(this,"world");const s=t.renderer;if(!s)throw new Error("A renderer is needed for the raycaster to work!");this.world=t,this.mouse=new gn(s.three.domElement),this.components=e}dispose(){this.mouse.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}castRay(e=Array.from(this.world.meshes)){if(!this.world)throw new Error("A world is needed to cast rays!");const t=this.world.camera.three;return this.three.setFromCamera(this.mouse.position,t),this.intersect(e)}castRayFromVector(e,t,s=Array.from(this.world.meshes)){return this.three.set(e,t),this.intersect(s)}intersect(e=Array.from(this.world.meshes)){const t=this.three.intersectObjects(e),s=this.filterClippingPlanes(t);return s.length>0?s[0]:null}filterClippingPlanes(e){if(!this.world.renderer)throw new Error("Renderer not found!");const t=this.world.renderer.three;if(!t.clippingPlanes)return e;const s=t.clippingPlanes;return e.length<=0||!s||(s==null?void 0:s.length)<=0?e:e.filter(i=>s.every(o=>o.distanceToPoint(i.point)>0))}}const Cs=class Cs extends ${constructor(t){super(t);I(this,"enabled",!0);I(this,"list",new Map);I(this,"onDisposed",new D);t.add(Cs.uuid,this)}get(t){if(this.list.has(t.uuid))return this.list.get(t.uuid);const s=new Sn(this.components,t);return this.list.set(t.uuid,s),t.onDisposed.add(()=>{this.delete(t)}),s}delete(t){const s=this.list.get(t.uuid);s&&s.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,s]of this.list)s.dispose();this.list.clear(),this.onDisposed.trigger()}};I(Cs,"uuid","d5d8bdf0-db25-4952-b951-b643af207ace");let ae=Cs;class _n extends Ps{constructor(){super(...arguments);I(this,"meshes",new Set);I(this,"onAfterUpdate",new D);I(this,"onBeforeUpdate",new D);I(this,"onDisposed",new D);I(this,"isDisposing",!1);I(this,"enabled",!0);I(this,"uuid",re.create());I(this,"name");I(this,"_scene");I(this,"_camera");I(this,"_renderer",null)}get scene(){if(!this._scene)throw new Error("No scene initialized!");return this._scene}set scene(t){this._scene=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get camera(){if(!this._camera)throw new Error("No camera initialized!");return this._camera}set camera(t){this._camera=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get renderer(){return this._renderer}set renderer(t){this._renderer=t,t&&(t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"}))}update(t){this.enabled&&(!this._scene||!this._camera||(this.scene.currentWorld=this,this.camera.currentWorld=this,this.renderer&&(this.renderer.currentWorld=this),this.onBeforeUpdate.trigger(),this.scene.isUpdateable()&&this.scene.update(t),this.camera.isUpdateable()&&this.camera.update(t),this.renderer&&this.renderer.update(t),this.onAfterUpdate.trigger()))}dispose(t=!0){if(this.enabled=!1,this.isDisposing=!0,this.scene.onWorldChanged.trigger({world:this,action:"removed"}),this.camera.onWorldChanged.trigger({world:this,action:"removed"}),this.renderer&&this.renderer.onWorldChanged.trigger({world:this,action:"removed"}),t){const s=this.components.get(_t);this.scene.dispose(),this.camera.isDisposeable()&&this.camera.dispose(),this.renderer&&this.renderer.dispose();for(const i of this.meshes)s.destroy(i);this.meshes.clear()}this._scene=null,this._camera=null,this._renderer=null,this.onDisposed.trigger()}}class Er extends An{constructor(t){super(t);I(this,"isSetup",!1);I(this,"three");I(this,"onSetup",new D);I(this,"config",{directionalLight:{color:new S.Color("white"),intensity:1.5,position:new S.Vector3(5,10,3)},ambientLight:{color:new S.Color("white"),intensity:1}});this.three=new S.Scene,this.three.background=new S.Color(2107698)}setup(t){this.config={...this.config,...t};const s=new S.DirectionalLight(this.config.directionalLight.color,this.config.directionalLight.intensity);s.position.copy(this.config.directionalLight.position);const i=new S.AmbientLight(this.config.ambientLight.color,this.config.ambientLight.intensity);this.three.add(s,i),this.isSetup=!0,this.onSetup.trigger(this)}}class dr extends Rn{constructor(t,s,i){super(t);I(this,"enabled",!0);I(this,"container");I(this,"three");I(this,"_canvas");I(this,"_parameters");I(this,"_resizeObserver",null);I(this,"onContainerUpdated",new D);I(this,"_resizing",!1);I(this,"resize",t=>{if(this._resizing)return;this._resizing=!0,this.onContainerUpdated.trigger();const s=t?t.x:this.container.clientWidth,i=t?t.y:this.container.clientHeight;this.three.setSize(s,i),this.onResize.trigger(new S.Vector2(s,i)),this._resizing=!1});I(this,"resizeEvent",()=>{this.resize()});I(this,"onContextLost",t=>{t.preventDefault(),this.enabled=!1});I(this,"onContextBack",()=>{this.three.setRenderTarget(null),this.three.dispose(),this.three=new S.WebGLRenderer({canvas:this._canvas,antialias:!0,alpha:!0,...this._parameters}),this.enabled=!0});this.container=s,this._parameters=i,this.three=new S.WebGLRenderer({antialias:!0,alpha:!0,...i}),this.three.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.setupRenderer(),this.setupEvents(!0),this.resize(),this._canvas=this.three.domElement;const o=this.three.getContext(),{canvas:n}=o;n.addEventListener("webglcontextlost",this.onContextLost,!1),n.addEventListener("webglcontextrestored",this.onContextBack,!1)}update(){if(!this.enabled||!this.currentWorld)return;this.onBeforeUpdate.trigger(this);const t=this.currentWorld.scene.three,s=this.currentWorld.camera.three;this.three.render(t,s),this.onAfterUpdate.trigger(this)}dispose(){this.enabled=!1,this.setupEvents(!1),this.three.domElement.remove(),this.three.dispose(),this.onResize.reset(),this.onAfterUpdate.reset(),this.onBeforeUpdate.reset(),this.onDisposed.trigger(),this.onDisposed.reset()}getSize(){return new S.Vector2(this.three.domElement.clientWidth,this.three.domElement.clientHeight)}setupEvents(t){const s=this.three.domElement.parentElement;if(!s)throw new Error("This renderer needs to have an HTML container!");this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),window.removeEventListener("resize",this.resizeEvent),t&&(this._resizeObserver=new ResizeObserver(this.resizeEvent),this._resizeObserver.observe(s),window.addEventListener("resize",this.resizeEvent))}setupRenderer(){this.three.localClippingEnabled=!0,this.container&&this.container.appendChild(this.three.domElement),this.onContainerUpdated.trigger()}}/*!
5
+ - If you're using a platform tool, verify the uuid isn't misspelled or contact the tool creator.`)}};I(K,"_pattern",/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/),I(K,"_lut",["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"]);let re=K;class hr extends ${constructor(t,s){super(t);I(this,"onDisposed",new D);I(this,"onVertexFound",new D);I(this,"onVertexLost",new D);I(this,"components");I(this,"workingPlane",null);I(this,"_pickedPoint",null);I(this,"_config");I(this,"_enabled",!1);this.components=t,this.config={snapDistance:.25,showOnlyVertex:!1,...s},this.enabled=!1}set enabled(t){this._enabled=t,t||(this._pickedPoint=null)}get enabled(){return this._enabled}set config(t){this._config={...this._config,...t}}get config(){return this._config}dispose(){this.onVertexFound.reset(),this.onVertexLost.reset(),this.components=null,this.onDisposed.trigger(),this.onDisposed.reset()}get(t){if(!this.enabled)return this._pickedPoint;const o=this.components.get(ae).get(t).castRay();if(!o)return this._pickedPoint!==null&&(this.onVertexLost.trigger(),this._pickedPoint=null),this._pickedPoint;const n=this.getClosestVertex(o);return n?(this.workingPlane?Math.abs(this.workingPlane.distanceToPoint(n))<.001:!0)?((this._pickedPoint===null||!this._pickedPoint.equals(n))&&(this._pickedPoint=n.clone(),this.onVertexFound.trigger(this._pickedPoint)),this._pickedPoint):(this._pickedPoint=null,this._pickedPoint):(this._pickedPoint!==null&&(this.onVertexLost.trigger(),this._pickedPoint=null),this._pickedPoint)}getClosestVertex(t){let s=new S.Vector3,i=!1,o=Number.MAX_SAFE_INTEGER;const n=this.getVertices(t);if(n===null)return null;for(const r of n){if(!r)continue;const a=t.point.distanceTo(r);a>o||a>this._config.snapDistance||(i=!0,s=r,o=t.point.distanceTo(r))}return i?s:this.config.showOnlyVertex?null:t.point}getVertices(t){const s=t.object;if(!t.face||!s)return null;const i=s.geometry,o=new S.Matrix4,{instanceId:n}=t,r=n!==void 0,a=s instanceof S.InstancedMesh;return a&&r&&s.getMatrixAt(n,o),[this.getVertex(t.face.a,i),this.getVertex(t.face.b,i),this.getVertex(t.face.c,i)].map(l=>(l&&(a&&r&&l.applyMatrix4(o),l.applyMatrix4(s.matrixWorld)),l))}getVertex(t,s){if(t===void 0)return null;const i=s.attributes.position;return new S.Vector3(i.getX(t),i.getY(t),i.getZ(t))}}const ps=class ps{constructor(){I(this,"onDisposed",new D);I(this,"list",new Map);I(this,"enabled",!1);I(this,"_clock");I(this,"update",()=>{if(!this.enabled)return;const e=this._clock.getDelta();for(const[t,s]of this.list)s.enabled&&s.isUpdateable()&&s.update(e);requestAnimationFrame(this.update)});this._clock=new S.Clock,ps.setupBVH()}add(e,t){if(this.list.has(e))throw new Error("You're trying to add a component that already exists in the components instance. Use Components.get() instead.");re.validate(e),this.list.set(e,t)}get(e){const t=e.uuid;if(!this.list.has(t)){const s=new e(this);return this.list.has(t)||this.add(t,s),s}return this.list.get(t)}init(){this.enabled=!0,this._clock.start(),this.update()}dispose(){this.enabled=!1;for(const[e,t]of this.list)t.enabled=!1,t.isDisposeable()&&t.dispose();this._clock.stop(),this.onDisposed.trigger(),this.onDisposed.reset()}static setupBVH(){S.BufferGeometry.prototype.computeBoundsTree=tr,S.BufferGeometry.prototype.disposeBoundsTree=er,S.Mesh.prototype.raycast=Jo}};I(ps,"release","2.0.22");let hs=ps;class gn{constructor(e){I(this,"_event");I(this,"_position",new S.Vector2);I(this,"onDisposed",new D);I(this,"updateMouseInfo",e=>{this._event=e});this.dom=e,this.setupEvents(!0)}get position(){if(this._event){const e=this.dom.getBoundingClientRect();this._position.x=this.getPositionX(e,this._event),this._position.y=this.getPositionY(e,this._event)}return this._position}dispose(){this.setupEvents(!1),this.onDisposed.trigger(),this.onDisposed.reset()}getPositionY(e,t){return-((t.clientY-e.top)/(e.bottom-e.top))*2+1}getPositionX(e,t){return(t.clientX-e.left)/(e.right-e.left)*2-1}setupEvents(e){e?this.dom.addEventListener("pointermove",this.updateMouseInfo):this.dom.removeEventListener("pointermove",this.updateMouseInfo)}}class Sn{constructor(e,t){I(this,"enabled",!0);I(this,"components");I(this,"onDisposed",new D);I(this,"mouse");I(this,"three",new S.Raycaster);I(this,"world");const s=t.renderer;if(!s)throw new Error("A renderer is needed for the raycaster to work!");this.world=t,this.mouse=new gn(s.three.domElement),this.components=e}dispose(){this.mouse.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}castRay(e=Array.from(this.world.meshes)){if(!this.world)throw new Error("A world is needed to cast rays!");const t=this.world.camera.three;return this.three.setFromCamera(this.mouse.position,t),this.intersect(e)}castRayFromVector(e,t,s=Array.from(this.world.meshes)){return this.three.set(e,t),this.intersect(s)}intersect(e=Array.from(this.world.meshes)){const t=this.three.intersectObjects(e),s=this.filterClippingPlanes(t);return s.length>0?s[0]:null}filterClippingPlanes(e){if(!this.world.renderer)throw new Error("Renderer not found!");const t=this.world.renderer.three;if(!t.clippingPlanes)return e;const s=t.clippingPlanes;return e.length<=0||!s||(s==null?void 0:s.length)<=0?e:e.filter(i=>s.every(o=>o.distanceToPoint(i.point)>0))}}const Cs=class Cs extends ${constructor(t){super(t);I(this,"enabled",!0);I(this,"list",new Map);I(this,"onDisposed",new D);t.add(Cs.uuid,this)}get(t){if(this.list.has(t.uuid))return this.list.get(t.uuid);const s=new Sn(this.components,t);return this.list.set(t.uuid,s),t.onDisposed.add(()=>{this.delete(t)}),s}delete(t){const s=this.list.get(t.uuid);s&&s.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,s]of this.list)s.dispose();this.list.clear(),this.onDisposed.trigger()}};I(Cs,"uuid","d5d8bdf0-db25-4952-b951-b643af207ace");let ae=Cs;class _n extends Ps{constructor(){super(...arguments);I(this,"meshes",new Set);I(this,"onAfterUpdate",new D);I(this,"onBeforeUpdate",new D);I(this,"onDisposed",new D);I(this,"isDisposing",!1);I(this,"enabled",!0);I(this,"uuid",re.create());I(this,"name");I(this,"_scene");I(this,"_camera");I(this,"_renderer",null)}get scene(){if(!this._scene)throw new Error("No scene initialized!");return this._scene}set scene(t){this._scene=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get camera(){if(!this._camera)throw new Error("No camera initialized!");return this._camera}set camera(t){this._camera=t,t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"})}get renderer(){return this._renderer}set renderer(t){this._renderer=t,t&&(t.worlds.set(this.uuid,this),t.currentWorld=this,t.onWorldChanged.trigger({world:this,action:"added"}))}update(t){this.enabled&&(!this._scene||!this._camera||(this.scene.currentWorld=this,this.camera.currentWorld=this,this.renderer&&(this.renderer.currentWorld=this),this.onBeforeUpdate.trigger(),this.scene.isUpdateable()&&this.scene.update(t),this.camera.isUpdateable()&&this.camera.update(t),this.renderer&&this.renderer.update(t),this.onAfterUpdate.trigger()))}dispose(t=!0){if(this.enabled=!1,this.isDisposing=!0,this.scene.onWorldChanged.trigger({world:this,action:"removed"}),this.camera.onWorldChanged.trigger({world:this,action:"removed"}),this.renderer&&this.renderer.onWorldChanged.trigger({world:this,action:"removed"}),t){const s=this.components.get(_t);this.scene.dispose(),this.camera.isDisposeable()&&this.camera.dispose(),this.renderer&&this.renderer.dispose();for(const i of this.meshes)s.destroy(i);this.meshes.clear()}this._scene=null,this._camera=null,this._renderer=null,this.onDisposed.trigger()}}class Er extends An{constructor(t){super(t);I(this,"isSetup",!1);I(this,"three");I(this,"onSetup",new D);I(this,"config",{directionalLight:{color:new S.Color("white"),intensity:1.5,position:new S.Vector3(5,10,3)},ambientLight:{color:new S.Color("white"),intensity:1}});this.three=new S.Scene,this.three.background=new S.Color(2107698)}setup(t){this.config={...this.config,...t};const s=new S.DirectionalLight(this.config.directionalLight.color,this.config.directionalLight.intensity);s.position.copy(this.config.directionalLight.position);const i=new S.AmbientLight(this.config.ambientLight.color,this.config.ambientLight.intensity);this.three.add(s,i),this.isSetup=!0,this.onSetup.trigger(this)}}class dr extends Rn{constructor(t,s,i){super(t);I(this,"enabled",!0);I(this,"container");I(this,"three");I(this,"_canvas");I(this,"_parameters");I(this,"_resizeObserver",null);I(this,"onContainerUpdated",new D);I(this,"_resizing",!1);I(this,"resize",t=>{if(this._resizing)return;this._resizing=!0,this.onContainerUpdated.trigger();const s=t?t.x:this.container.clientWidth,i=t?t.y:this.container.clientHeight;this.three.setSize(s,i),this.onResize.trigger(new S.Vector2(s,i)),this._resizing=!1});I(this,"resizeEvent",()=>{this.resize()});I(this,"onContextLost",t=>{t.preventDefault(),this.enabled=!1});I(this,"onContextBack",()=>{this.three.setRenderTarget(null),this.three.dispose(),this.three=new S.WebGLRenderer({canvas:this._canvas,antialias:!0,alpha:!0,...this._parameters}),this.enabled=!0});this.container=s,this._parameters=i,this.three=new S.WebGLRenderer({antialias:!0,alpha:!0,...i}),this.three.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.setupRenderer(),this.setupEvents(!0),this.resize(),this._canvas=this.three.domElement;const o=this.three.getContext(),{canvas:n}=o;n.addEventListener("webglcontextlost",this.onContextLost,!1),n.addEventListener("webglcontextrestored",this.onContextBack,!1)}update(){if(!this.enabled||!this.currentWorld)return;this.onBeforeUpdate.trigger(this);const t=this.currentWorld.scene.three,s=this.currentWorld.camera.three;this.three.render(t,s),this.onAfterUpdate.trigger(this)}dispose(){this.enabled=!1,this.setupEvents(!1),this.three.domElement.remove(),this.three.dispose(),this.onResize.reset(),this.onAfterUpdate.reset(),this.onBeforeUpdate.reset(),this.onDisposed.trigger(),this.onDisposed.reset()}getSize(){return new S.Vector2(this.three.domElement.clientWidth,this.three.domElement.clientHeight)}setupEvents(t){const s=this.three.domElement.parentElement;if(!s)throw new Error("This renderer needs to have an HTML container!");this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),window.removeEventListener("resize",this.resizeEvent),t&&(this._resizeObserver=new ResizeObserver(this.resizeEvent),this._resizeObserver.observe(s),window.addEventListener("resize",this.resizeEvent))}setupRenderer(){this.three.localClippingEnabled=!0,this.container&&this.container.appendChild(this.three.domElement),this.onContainerUpdated.trigger()}}/*!
6
6
  * camera-controls
7
7
  * https://github.com/yomotsu/camera-controls
8
8
  * (c) 2017 @yomotsu
@@ -68,7 +68,7 @@
68
68
 
69
69
  }
70
70
 
71
- `,extensions:{derivatives:!0}});this.three=new S.Mesh(a,l),this.three.frustumCulled=!1,t.scene.three.add(this.three),this.setupEvents(!0)}get visible(){return this.three.visible}set visible(e){e?this.world.scene.three.add(this.three):this.three.removeFromParent()}get material(){return this.three.material}get fade(){return this._fade===3}set fade(e){this._fade=e?3:0,this.material.uniforms.uFade.value=this._fade}dispose(){this.setupEvents(!1),this.components.get(_t).destroy(this.three),this.onDisposed.trigger(),this.onDisposed.reset(),this.world=null,this.components=null}setupEvents(e){if(this.world.isDisposing||!(this.world.camera instanceof ce))return;const t=this.world.camera.controls;e?t.addEventListener("update",this.updateZoom):t.removeEventListener("update",this.updateZoom)}}const ms=class ms extends ${constructor(t){super(t);I(this,"list",new Map);I(this,"config",{color:new S.Color(12303291),size1:1,size2:10,distance:500});I(this,"onDisposed",new D);I(this,"enabled",!0);t.add(ms.uuid,this)}create(t){if(this.list.has(t.uuid))throw new Error("This world already has a grid!");const s=new Ln(this.components,t,this.config);return this.list.set(t.uuid,s),t.onDisposed.add(()=>{this.delete(t)}),s}delete(t){const s=this.list.get(t.uuid);s&&s.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,s]of this.list)s.dispose();this.list.clear(),this.onDisposed.trigger(),this.onDisposed.reset()}};I(ms,"uuid","d1e814d5-b81c-4452-87a2-f039375e0489");let Ii=ms;const zt=new C.Raycaster,it=new C.Vector3,yt=new C.Vector3,Q=new C.Quaternion,an={X:new C.Vector3(1,0,0),Y:new C.Vector3(0,1,0),Z:new C.Vector3(0,0,1)},si={type:"change"},cn={type:"mouseDown"},ln={type:"mouseUp",mode:null},hn={type:"objectChange"};class Cr extends C.Object3D{constructor(e,t){super(),t===void 0&&(console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.'),t=document),this.isTransformControls=!0,this.visible=!1,this.domElement=t,this.domElement.style.touchAction="none";const s=new Or;this._gizmo=s,this.add(s);const i=new gr;this._plane=i,this.add(i);const o=this;function n(A,O){let f=O;Object.defineProperty(o,A,{get:function(){return f!==void 0?f:O},set:function(m){f!==m&&(f=m,i[A]=m,s[A]=m,o.dispatchEvent({type:A+"-changed",value:m}),o.dispatchEvent(si))}}),o[A]=O,i[A]=O,s[A]=O}n("camera",e),n("object",void 0),n("enabled",!0),n("axis",null),n("mode","translate"),n("translationSnap",null),n("rotationSnap",null),n("scaleSnap",null),n("space","world"),n("size",1),n("dragging",!1),n("showX",!0),n("showY",!0),n("showZ",!0);const r=new C.Vector3,a=new C.Vector3,l=new C.Quaternion,h=new C.Quaternion,d=new C.Vector3,E=new C.Quaternion,u=new C.Vector3,p=new C.Vector3,F=new C.Vector3,R=0,T=new C.Vector3;n("worldPosition",r),n("worldPositionStart",a),n("worldQuaternion",l),n("worldQuaternionStart",h),n("cameraPosition",d),n("cameraQuaternion",E),n("pointStart",u),n("pointEnd",p),n("rotationAxis",F),n("rotationAngle",R),n("eye",T),this._offset=new C.Vector3,this._startNorm=new C.Vector3,this._endNorm=new C.Vector3,this._cameraScale=new C.Vector3,this._parentPosition=new C.Vector3,this._parentQuaternion=new C.Quaternion,this._parentQuaternionInv=new C.Quaternion,this._parentScale=new C.Vector3,this._worldScaleStart=new C.Vector3,this._worldQuaternionInv=new C.Quaternion,this._worldScale=new C.Vector3,this._positionStart=new C.Vector3,this._quaternionStart=new C.Quaternion,this._scaleStart=new C.Vector3,this._getPointer=Tr.bind(this),this._onPointerDown=Rr.bind(this),this._onPointerHover=mr.bind(this),this._onPointerMove=Ar.bind(this),this._onPointerUp=Fr.bind(this),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp)}updateMatrixWorld(){this.object!==void 0&&(this.object.updateMatrixWorld(),this.object.parent===null?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):this.object.parent.matrixWorld.decompose(this._parentPosition,this._parentQuaternion,this._parentScale),this.object.matrixWorld.decompose(this.worldPosition,this.worldQuaternion,this._worldScale),this._parentQuaternionInv.copy(this._parentQuaternion).invert(),this._worldQuaternionInv.copy(this.worldQuaternion).invert()),this.camera.updateMatrixWorld(),this.camera.matrixWorld.decompose(this.cameraPosition,this.cameraQuaternion,this._cameraScale),this.camera.isOrthographicCamera?this.camera.getWorldDirection(this.eye).negate():this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize(),super.updateMatrixWorld(this)}pointerHover(e){if(this.object===void 0||this.dragging===!0)return;zt.setFromCamera(e,this.camera);const t=ii(this._gizmo.picker[this.mode],zt);t?this.axis=t.object.name:this.axis=null}pointerDown(e){if(!(this.object===void 0||this.dragging===!0||e.button!==0)&&this.axis!==null){zt.setFromCamera(e,this.camera);const t=ii(this._plane,zt,!0);t&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(t.point).sub(this.worldPositionStart)),this.dragging=!0,cn.mode=this.mode,this.dispatchEvent(cn)}}pointerMove(e){const t=this.axis,s=this.mode,i=this.object;let o=this.space;if(s==="scale"?o="local":(t==="E"||t==="XYZE"||t==="XYZ")&&(o="world"),i===void 0||t===null||this.dragging===!1||e.button!==-1)return;zt.setFromCamera(e,this.camera);const n=ii(this._plane,zt,!0);if(n){if(this.pointEnd.copy(n.point).sub(this.worldPositionStart),s==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),o==="local"&&t!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),t.indexOf("X")===-1&&(this._offset.x=0),t.indexOf("Y")===-1&&(this._offset.y=0),t.indexOf("Z")===-1&&(this._offset.z=0),o==="local"&&t!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),i.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(o==="local"&&(i.position.applyQuaternion(Q.copy(this._quaternionStart).invert()),t.search("X")!==-1&&(i.position.x=Math.round(i.position.x/this.translationSnap)*this.translationSnap),t.search("Y")!==-1&&(i.position.y=Math.round(i.position.y/this.translationSnap)*this.translationSnap),t.search("Z")!==-1&&(i.position.z=Math.round(i.position.z/this.translationSnap)*this.translationSnap),i.position.applyQuaternion(this._quaternionStart)),o==="world"&&(i.parent&&i.position.add(it.setFromMatrixPosition(i.parent.matrixWorld)),t.search("X")!==-1&&(i.position.x=Math.round(i.position.x/this.translationSnap)*this.translationSnap),t.search("Y")!==-1&&(i.position.y=Math.round(i.position.y/this.translationSnap)*this.translationSnap),t.search("Z")!==-1&&(i.position.z=Math.round(i.position.z/this.translationSnap)*this.translationSnap),i.parent&&i.position.sub(it.setFromMatrixPosition(i.parent.matrixWorld))));else if(s==="scale"){if(t.search("XYZ")!==-1){let r=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(r*=-1),yt.set(r,r,r)}else it.copy(this.pointStart),yt.copy(this.pointEnd),it.applyQuaternion(this._worldQuaternionInv),yt.applyQuaternion(this._worldQuaternionInv),yt.divide(it),t.search("X")===-1&&(yt.x=1),t.search("Y")===-1&&(yt.y=1),t.search("Z")===-1&&(yt.z=1);i.scale.copy(this._scaleStart).multiply(yt),this.scaleSnap&&(t.search("X")!==-1&&(i.scale.x=Math.round(i.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search("Y")!==-1&&(i.scale.y=Math.round(i.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search("Z")!==-1&&(i.scale.z=Math.round(i.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(s==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const r=20/this.worldPosition.distanceTo(it.setFromMatrixPosition(this.camera.matrixWorld));let a=!1;t==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(it.copy(this.rotationAxis).cross(this.eye))*r):(t==="X"||t==="Y"||t==="Z")&&(this.rotationAxis.copy(an[t]),it.copy(an[t]),o==="local"&&it.applyQuaternion(this.worldQuaternion),it.cross(this.eye),it.length()===0?a=!0:this.rotationAngle=this._offset.dot(it.normalize())*r),(t==="E"||a)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),o==="local"&&t!=="E"&&t!=="XYZE"?(i.quaternion.copy(this._quaternionStart),i.quaternion.multiply(Q.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),i.quaternion.copy(Q.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),i.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(si),this.dispatchEvent(hn)}}pointerUp(e){e.button===0&&(this.dragging&&this.axis!==null&&(ln.mode=this.mode,this.dispatchEvent(ln)),this.dragging=!1,this.axis=null)}dispose(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.traverse(function(e){e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose()})}attach(e){return this.object=e,this.visible=!0,this}detach(){return this.object=void 0,this.visible=!1,this.axis=null,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(si),this.dispatchEvent(hn),this.pointStart.copy(this.pointEnd))}getRaycaster(){return zt}getMode(){return this.mode}setMode(e){this.mode=e}setTranslationSnap(e){this.translationSnap=e}setRotationSnap(e){this.rotationSnap=e}setScaleSnap(e){this.scaleSnap=e}setSize(e){this.size=e}setSpace(e){this.space=e}}function Tr(c){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:c.button};{const e=this.domElement.getBoundingClientRect();return{x:(c.clientX-e.left)/e.width*2-1,y:-(c.clientY-e.top)/e.height*2+1,button:c.button}}}function mr(c){if(this.enabled)switch(c.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(c));break}}function Rr(c){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(c.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(c)),this.pointerDown(this._getPointer(c)))}function Ar(c){this.enabled&&this.pointerMove(this._getPointer(c))}function Fr(c){this.enabled&&(this.domElement.releasePointerCapture(c.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(c)))}function ii(c,e,t){const s=e.intersectObject(c,!0);for(let i=0;i<s.length;i++)if(s[i].object.visible||t)return s[i];return!1}const is=new C.Euler,k=new C.Vector3(0,1,0),En=new C.Vector3(0,0,0),dn=new C.Matrix4,ns=new C.Quaternion,cs=new C.Quaternion,Ft=new C.Vector3,un=new C.Matrix4,_e=new C.Vector3(1,0,0),Ht=new C.Vector3(0,1,0),Ne=new C.Vector3(0,0,1),os=new C.Vector3,ge=new C.Vector3,Se=new C.Vector3;class Or extends C.Object3D{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const e=new C.MeshBasicMaterial({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),t=new C.LineBasicMaterial({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),s=e.clone();s.opacity=.15;const i=t.clone();i.opacity=.5;const o=e.clone();o.color.setHex(16711680);const n=e.clone();n.color.setHex(65280);const r=e.clone();r.color.setHex(255);const a=e.clone();a.color.setHex(16711680),a.opacity=.5;const l=e.clone();l.color.setHex(65280),l.opacity=.5;const h=e.clone();h.color.setHex(255),h.opacity=.5;const d=e.clone();d.opacity=.25;const E=e.clone();E.color.setHex(16776960),E.opacity=.25,e.clone().color.setHex(16776960);const p=e.clone();p.color.setHex(7895160);const F=new C.CylinderGeometry(0,.04,.1,12);F.translate(0,.05,0);const R=new C.BoxGeometry(.08,.08,.08);R.translate(0,.04,0);const T=new C.BufferGeometry;T.setAttribute("position",new C.Float32BufferAttribute([0,0,0,1,0,0],3));const A=new C.CylinderGeometry(.0075,.0075,.5,3);A.translate(0,.25,0);function O(v,z){const j=new C.TorusGeometry(v,.0075,3,64,z*Math.PI*2);return j.rotateY(Math.PI/2),j.rotateX(Math.PI/2),j}function f(){const v=new C.BufferGeometry;return v.setAttribute("position",new C.Float32BufferAttribute([0,0,0,1,1,1],3)),v}const m={X:[[new C.Mesh(F,o),[.5,0,0],[0,0,-Math.PI/2]],[new C.Mesh(F,o),[-.5,0,0],[0,0,Math.PI/2]],[new C.Mesh(A,o),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new C.Mesh(F,n),[0,.5,0]],[new C.Mesh(F,n),[0,-.5,0],[Math.PI,0,0]],[new C.Mesh(A,n)]],Z:[[new C.Mesh(F,r),[0,0,.5],[Math.PI/2,0,0]],[new C.Mesh(F,r),[0,0,-.5],[-Math.PI/2,0,0]],[new C.Mesh(A,r),null,[Math.PI/2,0,0]]],XYZ:[[new C.Mesh(new C.OctahedronGeometry(.1,0),d.clone()),[0,0,0]]],XY:[[new C.Mesh(new C.BoxGeometry(.15,.15,.01),h.clone()),[.15,.15,0]]],YZ:[[new C.Mesh(new C.BoxGeometry(.15,.15,.01),a.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new C.Mesh(new C.BoxGeometry(.15,.15,.01),l.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},g={X:[[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[.3,0,0],[0,0,-Math.PI/2]],[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,.3,0]],[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,-.3,0],[0,0,Math.PI]]],Z:[[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,0,.3],[Math.PI/2,0,0]],[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new C.Mesh(new C.OctahedronGeometry(.2,0),s)]],XY:[[new C.Mesh(new C.BoxGeometry(.2,.2,.01),s),[.15,.15,0]]],YZ:[[new C.Mesh(new C.BoxGeometry(.2,.2,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new C.Mesh(new C.BoxGeometry(.2,.2,.01),s),[.15,0,.15],[-Math.PI/2,0,0]]]},_={START:[[new C.Mesh(new C.OctahedronGeometry(.01,2),i),null,null,null,"helper"]],END:[[new C.Mesh(new C.OctahedronGeometry(.01,2),i),null,null,null,"helper"]],DELTA:[[new C.Line(f(),i),null,null,null,"helper"]],X:[[new C.Line(T,i.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new C.Line(T,i.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new C.Line(T,i.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},N={XYZE:[[new C.Mesh(O(.5,1),p),null,[0,Math.PI/2,0]]],X:[[new C.Mesh(O(.5,.5),o)]],Y:[[new C.Mesh(O(.5,.5),n),null,[0,0,-Math.PI/2]]],Z:[[new C.Mesh(O(.5,.5),r),null,[0,Math.PI/2,0]]],E:[[new C.Mesh(O(.75,1),E),null,[0,Math.PI/2,0]]]},y={AXIS:[[new C.Line(T,i.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},P={XYZE:[[new C.Mesh(new C.SphereGeometry(.25,10,8),s)]],X:[[new C.Mesh(new C.TorusGeometry(.5,.1,4,24),s),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new C.Mesh(new C.TorusGeometry(.5,.1,4,24),s),[0,0,0],[Math.PI/2,0,0]]],Z:[[new C.Mesh(new C.TorusGeometry(.5,.1,4,24),s),[0,0,0],[0,0,-Math.PI/2]]],E:[[new C.Mesh(new C.TorusGeometry(.75,.1,2,24),s)]]},w={X:[[new C.Mesh(R,o),[.5,0,0],[0,0,-Math.PI/2]],[new C.Mesh(A,o),[0,0,0],[0,0,-Math.PI/2]],[new C.Mesh(R,o),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new C.Mesh(R,n),[0,.5,0]],[new C.Mesh(A,n)],[new C.Mesh(R,n),[0,-.5,0],[0,0,Math.PI]]],Z:[[new C.Mesh(R,r),[0,0,.5],[Math.PI/2,0,0]],[new C.Mesh(A,r),[0,0,0],[Math.PI/2,0,0]],[new C.Mesh(R,r),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new C.Mesh(new C.BoxGeometry(.15,.15,.01),h),[.15,.15,0]]],YZ:[[new C.Mesh(new C.BoxGeometry(.15,.15,.01),a),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new C.Mesh(new C.BoxGeometry(.15,.15,.01),l),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new C.Mesh(new C.BoxGeometry(.1,.1,.1),d.clone())]]},M={X:[[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[.3,0,0],[0,0,-Math.PI/2]],[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,.3,0]],[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,-.3,0],[0,0,Math.PI]]],Z:[[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,0,.3],[Math.PI/2,0,0]],[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new C.Mesh(new C.BoxGeometry(.2,.2,.01),s),[.15,.15,0]]],YZ:[[new C.Mesh(new C.BoxGeometry(.2,.2,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new C.Mesh(new C.BoxGeometry(.2,.2,.01),s),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new C.Mesh(new C.BoxGeometry(.2,.2,.2),s),[0,0,0]]]},U={X:[[new C.Line(T,i.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new C.Line(T,i.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new C.Line(T,i.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function x(v){const z=new C.Object3D;for(const j in v)for(let et=v[j].length;et--;){const Z=v[j][et][0].clone(),bt=v[j][et][1],vt=v[j][et][2],Bt=v[j][et][3],xe=v[j][et][4];Z.name=j,Z.tag=xe,bt&&Z.position.set(bt[0],bt[1],bt[2]),vt&&Z.rotation.set(vt[0],vt[1],vt[2]),Bt&&Z.scale.set(Bt[0],Bt[1],Bt[2]),Z.updateMatrix();const Ee=Z.geometry.clone();Ee.applyMatrix4(Z.matrix),Z.geometry=Ee,Z.renderOrder=1/0,Z.position.set(0,0,0),Z.rotation.set(0,0,0),Z.scale.set(1,1,1),z.add(Z)}return z}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=x(m)),this.add(this.gizmo.rotate=x(N)),this.add(this.gizmo.scale=x(w)),this.add(this.picker.translate=x(g)),this.add(this.picker.rotate=x(P)),this.add(this.picker.scale=x(M)),this.add(this.helper.translate=x(_)),this.add(this.helper.rotate=x(y)),this.add(this.helper.scale=x(U)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(e){const s=(this.mode==="scale"?"local":this.space)==="local"?this.worldQuaternion:cs;this.gizmo.translate.visible=this.mode==="translate",this.gizmo.rotate.visible=this.mode==="rotate",this.gizmo.scale.visible=this.mode==="scale",this.helper.translate.visible=this.mode==="translate",this.helper.rotate.visible=this.mode==="rotate",this.helper.scale.visible=this.mode==="scale";let i=[];i=i.concat(this.picker[this.mode].children),i=i.concat(this.gizmo[this.mode].children),i=i.concat(this.helper[this.mode].children);for(let o=0;o<i.length;o++){const n=i[o];n.visible=!0,n.rotation.set(0,0,0),n.position.copy(this.worldPosition);let r;if(this.camera.isOrthographicCamera?r=(this.camera.top-this.camera.bottom)/this.camera.zoom:r=this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),n.scale.set(1,1,1).multiplyScalar(r*this.size/4),n.tag==="helper"){n.visible=!1,n.name==="AXIS"?(n.visible=!!this.axis,this.axis==="X"&&(Q.setFromEuler(is.set(0,0,0)),n.quaternion.copy(s).multiply(Q),Math.abs(k.copy(_e).applyQuaternion(s).dot(this.eye))>.9&&(n.visible=!1)),this.axis==="Y"&&(Q.setFromEuler(is.set(0,0,Math.PI/2)),n.quaternion.copy(s).multiply(Q),Math.abs(k.copy(Ht).applyQuaternion(s).dot(this.eye))>.9&&(n.visible=!1)),this.axis==="Z"&&(Q.setFromEuler(is.set(0,Math.PI/2,0)),n.quaternion.copy(s).multiply(Q),Math.abs(k.copy(Ne).applyQuaternion(s).dot(this.eye))>.9&&(n.visible=!1)),this.axis==="XYZE"&&(Q.setFromEuler(is.set(0,Math.PI/2,0)),k.copy(this.rotationAxis),n.quaternion.setFromRotationMatrix(dn.lookAt(En,k,Ht)),n.quaternion.multiply(Q),n.visible=this.dragging),this.axis==="E"&&(n.visible=!1)):n.name==="START"?(n.position.copy(this.worldPositionStart),n.visible=this.dragging):n.name==="END"?(n.position.copy(this.worldPosition),n.visible=this.dragging):n.name==="DELTA"?(n.position.copy(this.worldPositionStart),n.quaternion.copy(this.worldQuaternionStart),it.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),it.applyQuaternion(this.worldQuaternionStart.clone().invert()),n.scale.copy(it),n.visible=this.dragging):(n.quaternion.copy(s),this.dragging?n.position.copy(this.worldPositionStart):n.position.copy(this.worldPosition),this.axis&&(n.visible=this.axis.search(n.name)!==-1));continue}n.quaternion.copy(s),this.mode==="translate"||this.mode==="scale"?(n.name==="X"&&Math.abs(k.copy(_e).applyQuaternion(s).dot(this.eye))>.99&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="Y"&&Math.abs(k.copy(Ht).applyQuaternion(s).dot(this.eye))>.99&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="Z"&&Math.abs(k.copy(Ne).applyQuaternion(s).dot(this.eye))>.99&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="XY"&&Math.abs(k.copy(Ne).applyQuaternion(s).dot(this.eye))<.2&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="YZ"&&Math.abs(k.copy(_e).applyQuaternion(s).dot(this.eye))<.2&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="XZ"&&Math.abs(k.copy(Ht).applyQuaternion(s).dot(this.eye))<.2&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1)):this.mode==="rotate"&&(ns.copy(s),k.copy(this.eye).applyQuaternion(Q.copy(s).invert()),n.name.search("E")!==-1&&n.quaternion.setFromRotationMatrix(dn.lookAt(this.eye,En,Ht)),n.name==="X"&&(Q.setFromAxisAngle(_e,Math.atan2(-k.y,k.z)),Q.multiplyQuaternions(ns,Q),n.quaternion.copy(Q)),n.name==="Y"&&(Q.setFromAxisAngle(Ht,Math.atan2(k.x,k.z)),Q.multiplyQuaternions(ns,Q),n.quaternion.copy(Q)),n.name==="Z"&&(Q.setFromAxisAngle(Ne,Math.atan2(k.y,k.x)),Q.multiplyQuaternions(ns,Q),n.quaternion.copy(Q))),n.visible=n.visible&&(n.name.indexOf("X")===-1||this.showX),n.visible=n.visible&&(n.name.indexOf("Y")===-1||this.showY),n.visible=n.visible&&(n.name.indexOf("Z")===-1||this.showZ),n.visible=n.visible&&(n.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),n.material._color=n.material._color||n.material.color.clone(),n.material._opacity=n.material._opacity||n.material.opacity,n.material.color.copy(n.material._color),n.material.opacity=n.material._opacity,this.enabled&&this.axis&&(n.name===this.axis||this.axis.split("").some(function(a){return n.name===a}))&&(n.material.color.setHex(16776960),n.material.opacity=1)}super.updateMatrixWorld(e)}}class gr extends C.Mesh{constructor(){super(new C.PlaneGeometry(1e5,1e5,2,2),new C.MeshBasicMaterial({visible:!1,wireframe:!0,side:C.DoubleSide,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(e){let t=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(t="local"),os.copy(_e).applyQuaternion(t==="local"?this.worldQuaternion:cs),ge.copy(Ht).applyQuaternion(t==="local"?this.worldQuaternion:cs),Se.copy(Ne).applyQuaternion(t==="local"?this.worldQuaternion:cs),k.copy(ge),this.mode){case"translate":case"scale":switch(this.axis){case"X":k.copy(this.eye).cross(os),Ft.copy(os).cross(k);break;case"Y":k.copy(this.eye).cross(ge),Ft.copy(ge).cross(k);break;case"Z":k.copy(this.eye).cross(Se),Ft.copy(Se).cross(k);break;case"XY":Ft.copy(Se);break;case"YZ":Ft.copy(os);break;case"XZ":k.copy(Se),Ft.copy(ge);break;case"XYZ":case"E":Ft.set(0,0,0);break}break;case"rotate":default:Ft.set(0,0,0)}Ft.length()===0?this.quaternion.copy(this.cameraQuaternion):(un.lookAt(it.set(0,0,0),Ft,k),this.quaternion.setFromRotationMatrix(un)),super.updateMatrixWorld(e)}}class ws{constructor(e,t,s,i,o,n=5,r=!0){I(this,"onDraggingStarted",new D);I(this,"onDraggingEnded",new D);I(this,"onDisposed",new D);I(this,"normal");I(this,"origin");I(this,"three",new S.Plane);I(this,"components");I(this,"world");I(this,"_helper");I(this,"_visible",!0);I(this,"_enabled",!0);I(this,"_controlsActive",!1);I(this,"_arrowBoundBox",new S.Mesh);I(this,"_planeMesh");I(this,"_controls");I(this,"_hiddenMaterial",new S.MeshBasicMaterial({visible:!1}));I(this,"update",()=>{this._enabled&&this.three.setFromNormalAndCoplanarPoint(this.normal,this._helper.position)});I(this,"changeDrag",e=>{this._visible=!e.value,this.preventCameraMovement(),this.notifyDraggingChanged(e)});if(this.components=e,this.world=t,!t.renderer)throw new Error("The given world must have a renderer!");this.normal=i,this.origin=s,t.renderer.setPlane(!0,this.three),this._planeMesh=ws.newPlaneMesh(n,o),this._helper=this.newHelper(),this._controls=this.newTransformControls(),this.three.setFromNormalAndCoplanarPoint(i,s),r&&this.toggleControls(!0)}get enabled(){return this._enabled}set enabled(e){if(!this.world.renderer)throw new Error("No renderer found for clipping plane!");this._enabled=e,this.world.renderer.setPlane(e,this.three)}get visible(){return this._visible}set visible(e){this._visible=e,this._controls.visible=e,this._helper.visible=e,this.toggleControls(e)}get meshes(){return[this._planeMesh,this._arrowBoundBox]}get planeMaterial(){return this._planeMesh.material}set planeMaterial(e){this._planeMesh.material=e}get size(){return this._planeMesh.scale.x}set size(e){this._planeMesh.scale.set(e,e,e)}get helper(){return this._helper}setFromNormalAndCoplanarPoint(e,t){this.reset(),this.normal.equals(e)||(this.normal.copy(e),this._helper.lookAt(e)),this.origin.copy(t),this._helper.position.copy(t),this._helper.updateMatrix(),this.update()}dispose(){this._enabled=!1,this.onDraggingStarted.reset(),this.onDraggingEnded.reset(),this._helper.removeFromParent(),this.world.renderer&&this.world.renderer.setPlane(!1,this.three),this._arrowBoundBox.removeFromParent(),this._arrowBoundBox.geometry.dispose(),this._planeMesh.geometry.dispose(),this._controls.removeFromParent(),this._controls.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}reset(){const e=new S.Vector3(1,0,0),t=new S.Vector3;this.normal.equals(e)||(this.normal.copy(e),this._helper.lookAt(e)),this.origin.copy(t),this._helper.position.copy(t),this._helper.updateMatrix()}toggleControls(e){if(e){if(this._controlsActive)return;this._controls.addEventListener("change",this.update),this._controls.addEventListener("dragging-changed",this.changeDrag)}else this._controls.removeEventListener("change",this.update),this._controls.removeEventListener("dragging-changed",this.changeDrag);this._controlsActive=e}newTransformControls(){if(!this.world.renderer)throw new Error("No renderer found for clipping plane!");const e=this.world.camera.three,t=this.world.renderer.three.domElement,s=new Cr(e,t);return this.initializeControls(s),this.world.scene.three.add(s),s}initializeControls(e){e.attach(this._helper),e.showX=!1,e.showY=!1,e.setSpace("local"),this.createArrowBoundingBox(),e.children[0].children[0].add(this._arrowBoundBox)}createArrowBoundingBox(){this._arrowBoundBox.geometry=new S.CylinderGeometry(.18,.18,1.2),this._arrowBoundBox.material=this._hiddenMaterial,this._arrowBoundBox.rotateX(Math.PI/2),this._arrowBoundBox.updateMatrix(),this._arrowBoundBox.geometry.applyMatrix4(this._arrowBoundBox.matrix)}notifyDraggingChanged(e){e.value?this.onDraggingStarted.trigger():this.onDraggingEnded.trigger()}preventCameraMovement(){this.world.camera.enabled=this._visible}newHelper(){const e=new S.Object3D;return e.lookAt(this.normal),e.position.copy(this.origin),this._planeMesh.position.z+=.01,e.add(this._planeMesh),this.world.scene.three.add(e),e}static newPlaneMesh(e,t){const s=new S.PlaneGeometry(1),i=new S.Mesh(s,t);return i.scale.set(e,e,e),i}}const Me=class Me extends ${constructor(t){super(t);I(this,"onBeforeDrag",new D);I(this,"onAfterDrag",new D);I(this,"onBeforeCreate",new D);I(this,"onBeforeCancel",new D);I(this,"onAfterCancel",new D);I(this,"onBeforeDelete",new D);I(this,"onAfterCreate",new D);I(this,"onAfterDelete",new D);I(this,"onDisposed",new D);I(this,"orthogonalY",!1);I(this,"toleranceOrthogonalY",.7);I(this,"Type",ws);I(this,"list",[]);I(this,"_material",new S.MeshBasicMaterial({color:12255487,side:S.DoubleSide,transparent:!0,opacity:.2}));I(this,"_size",5);I(this,"_enabled",!1);I(this,"_visible",!0);I(this,"_onStartDragging",()=>{this.onBeforeDrag.trigger()});I(this,"_onEndDragging",()=>{this.onAfterDrag.trigger()});this.components.add(Me.uuid,this)}get enabled(){return this._enabled}set enabled(t){this._enabled=t;for(const s of this.list)s.enabled=t;this.updateMaterialsAndPlanes()}get visible(){return this._visible}set visible(t){this._visible=t;for(const s of this.list)s.visible=t}get material(){return this._material}set material(t){this._material=t;for(const s of this.list)s.planeMaterial=t}get size(){return this._size}set size(t){this._size=t;for(const s of this.list)s.size=t}dispose(){this._enabled=!1;for(const t of this.list)t.dispose();this.list.length=0,this._material.dispose(),this.onBeforeCreate.reset(),this.onBeforeCancel.reset(),this.onBeforeDelete.reset(),this.onBeforeDrag.reset(),this.onAfterCreate.reset(),this.onAfterCancel.reset(),this.onAfterDelete.reset(),this.onAfterDrag.reset(),this.onDisposed.trigger(Me.uuid),this.onDisposed.reset()}create(t){const o=this.components.get(ae).get(t).castRay();o&&this.createPlaneFromIntersection(t,o)}createFromNormalAndCoplanarPoint(t,s,i){const o=this.newPlane(t,i,s);return this.updateMaterialsAndPlanes(),o}delete(t,s){s||(s=this.pickPlane(t)),s&&this.deletePlane(s)}deleteAll(){for(;this.list.length>0;){const t=this.list[0];this.delete(t.world,t)}}deletePlane(t){const s=this.list.indexOf(t);if(s!==-1){if(this.list.splice(s,1),!t.world.renderer)throw new Error("Renderer not found for this plane's world!");t.world.renderer.setPlane(!1,t.three),t.dispose(),this.updateMaterialsAndPlanes(),this.onAfterDelete.trigger(t)}}pickPlane(t){const i=this.components.get(ae).get(t),o=this.getAllPlaneMeshes(),n=i.castRay(o);if(n){const r=n.object;return this.list.find(a=>a.meshes.includes(r))}}getAllPlaneMeshes(){const t=[];for(const s of this.list)t.push(...s.meshes);return t}createPlaneFromIntersection(t,s){var a;if(!t.renderer)throw new Error("The given world must have a renderer!");const i=s.point.distanceTo(new S.Vector3(0,0,0)),o=(a=s.face)==null?void 0:a.normal;if(!i||!o)return;const n=this.getWorldNormal(s,o),r=this.newPlane(t,s.point,n.negate());r.visible=this._visible,r.size=this._size,t.renderer.setPlane(!0,r.three),this.updateMaterialsAndPlanes()}getWorldNormal(t,s){const i=t.object;let o=t.object.matrixWorld.clone();if(i instanceof S.InstancedMesh&&t.instanceId!==void 0){const l=new S.Matrix4;i.getMatrixAt(t.instanceId,l),o=l.multiply(o)}const r=new S.Matrix3().getNormalMatrix(o),a=s.clone().applyMatrix3(r).normalize();return this.normalizePlaneDirectionY(a),a}normalizePlaneDirectionY(t){this.orthogonalY&&(t.y>this.toleranceOrthogonalY&&(t.x=0,t.y=1,t.z=0),t.y<-this.toleranceOrthogonalY&&(t.x=0,t.y=-1,t.z=0))}newPlane(t,s,i){const o=new this.Type(this.components,t,s,i,this._material);return o.onDraggingStarted.add(this._onStartDragging),o.onDraggingEnded.add(this._onEndDragging),this.list.push(o),this.onAfterCreate.trigger(o),o}updateMaterialsAndPlanes(){const t=this.components.get(Es);for(const[s,i]of t.list){if(!i.renderer)continue;i.renderer.updateClippingPlanes();const{clippingPlanes:o}=i.renderer;for(const n of i.meshes)if(Array.isArray(n.material))for(const r of n.material)r.clippingPlanes=o;else n.material.clippingPlanes=o}}};I(Me,"uuid","66290bc5-18c4-4cd1-9379-2e17a0617611");let fi=Me;function Sr(c,e,t,s){return new Promise((i,o)=>{function n(){const r=c.clientWaitSync(e,t,0);if(r===c.WAIT_FAILED){o();return}if(r===c.TIMEOUT_EXPIRED){setTimeout(n,s);return}i()}n()})}async function _r(c,e,t,s,i,o,n){const r=c.fenceSync(c.SYNC_GPU_COMMANDS_COMPLETE,0);c.flush(),await Sr(c,r,0,10),c.deleteSync(r),c.bindBuffer(e,t),c.getBufferSubData(e,s,i,o,n),c.bindBuffer(e,null)}async function Pn(c,e,t,s,i,o,n,r){const a=c.createBuffer();return c.bindBuffer(c.PIXEL_PACK_BUFFER,a),c.bufferData(c.PIXEL_PACK_BUFFER,r.byteLength,c.STREAM_READ),c.readPixels(e,t,s,i,o,n,0),c.bindBuffer(c.PIXEL_PACK_BUFFER,null),await _r(c,c.PIXEL_PACK_BUFFER,a,0,r),c.deleteBuffer(a),r}class Mn{constructor(e,t,s){I(this,"onDisposed",new D);I(this,"onViewUpdated",new Le);I(this,"enabled",!0);I(this,"needsUpdate",!1);I(this,"renderDebugFrame",!1);I(this,"components");I(this,"world");I(this,"renderer");I(this,"autoUpdate",!0);I(this,"updateInterval",1e3);I(this,"worker");I(this,"scene",new S.Scene);I(this,"_width",512);I(this,"_height",512);I(this,"_availableColor",1);I(this,"renderTarget");I(this,"bufferSize");I(this,"_buffer");I(this,"_isWorkerBusy",!1);I(this,"updateVisibility",async e=>{if(!this.enabled||!this.needsUpdate&&!e||this._isWorkerBusy)return;this._isWorkerBusy=!0;const t=this.world.camera.three;t.updateMatrix(),this.renderer.setSize(this._width,this._height),this.renderer.setRenderTarget(this.renderTarget),this.renderer.render(this.scene,t);const s=this.renderer.getContext();await Pn(s,0,0,this._width,this._height,s.RGBA,s.UNSIGNED_BYTE,this._buffer),this.renderer.setRenderTarget(null),this.renderDebugFrame&&this.renderer.render(this.scene,t),this.worker.postMessage({buffer:this._buffer}),this.needsUpdate=!1});if(!t.renderer)throw new Error("The given world must have a renderer!");this.components=e,this.applySettings(s),this.world=t,this.renderer=new S.WebGLRenderer,this.renderTarget=new S.WebGLRenderTarget(this._width,this._height),this.bufferSize=this._width*this._height*4,this._buffer=new Uint8Array(this.bufferSize),this.renderer.clippingPlanes=t.renderer.clippingPlanes;const i=`
71
+ `,extensions:{derivatives:!0}});this.three=new S.Mesh(a,l),this.three.frustumCulled=!1,t.scene.three.add(this.three),this.setupEvents(!0)}get visible(){return this.three.visible}set visible(e){e?this.world.scene.three.add(this.three):this.three.removeFromParent()}get material(){return this.three.material}get fade(){return this._fade===3}set fade(e){this._fade=e?3:0,this.material.uniforms.uFade.value=this._fade}dispose(){this.setupEvents(!1),this.components.get(_t).destroy(this.three),this.onDisposed.trigger(),this.onDisposed.reset(),this.world=null,this.components=null}setupEvents(e){if(this.world.isDisposing||!(this.world.camera instanceof ce))return;const t=this.world.camera.controls;e?t.addEventListener("update",this.updateZoom):t.removeEventListener("update",this.updateZoom)}}const ms=class ms extends ${constructor(t){super(t);I(this,"list",new Map);I(this,"config",{color:new S.Color(12303291),size1:1,size2:10,distance:500});I(this,"onDisposed",new D);I(this,"enabled",!0);t.add(ms.uuid,this)}create(t){if(this.list.has(t.uuid))throw new Error("This world already has a grid!");const s=new Ln(this.components,t,this.config);return this.list.set(t.uuid,s),t.onDisposed.add(()=>{this.delete(t)}),s}delete(t){const s=this.list.get(t.uuid);s&&s.dispose(),this.list.delete(t.uuid)}dispose(){for(const[t,s]of this.list)s.dispose();this.list.clear(),this.onDisposed.trigger(),this.onDisposed.reset()}};I(ms,"uuid","d1e814d5-b81c-4452-87a2-f039375e0489");let Ii=ms;const zt=new C.Raycaster,it=new C.Vector3,yt=new C.Vector3,Q=new C.Quaternion,an={X:new C.Vector3(1,0,0),Y:new C.Vector3(0,1,0),Z:new C.Vector3(0,0,1)},si={type:"change"},cn={type:"mouseDown"},ln={type:"mouseUp",mode:null},hn={type:"objectChange"};class Cr extends C.Object3D{constructor(e,t){super(),t===void 0&&(console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.'),t=document),this.isTransformControls=!0,this.visible=!1,this.domElement=t,this.domElement.style.touchAction="none";const s=new Or;this._gizmo=s,this.add(s);const i=new gr;this._plane=i,this.add(i);const o=this;function n(A,O){let f=O;Object.defineProperty(o,A,{get:function(){return f!==void 0?f:O},set:function(m){f!==m&&(f=m,i[A]=m,s[A]=m,o.dispatchEvent({type:A+"-changed",value:m}),o.dispatchEvent(si))}}),o[A]=O,i[A]=O,s[A]=O}n("camera",e),n("object",void 0),n("enabled",!0),n("axis",null),n("mode","translate"),n("translationSnap",null),n("rotationSnap",null),n("scaleSnap",null),n("space","world"),n("size",1),n("dragging",!1),n("showX",!0),n("showY",!0),n("showZ",!0);const r=new C.Vector3,a=new C.Vector3,l=new C.Quaternion,h=new C.Quaternion,d=new C.Vector3,E=new C.Quaternion,u=new C.Vector3,p=new C.Vector3,F=new C.Vector3,R=0,T=new C.Vector3;n("worldPosition",r),n("worldPositionStart",a),n("worldQuaternion",l),n("worldQuaternionStart",h),n("cameraPosition",d),n("cameraQuaternion",E),n("pointStart",u),n("pointEnd",p),n("rotationAxis",F),n("rotationAngle",R),n("eye",T),this._offset=new C.Vector3,this._startNorm=new C.Vector3,this._endNorm=new C.Vector3,this._cameraScale=new C.Vector3,this._parentPosition=new C.Vector3,this._parentQuaternion=new C.Quaternion,this._parentQuaternionInv=new C.Quaternion,this._parentScale=new C.Vector3,this._worldScaleStart=new C.Vector3,this._worldQuaternionInv=new C.Quaternion,this._worldScale=new C.Vector3,this._positionStart=new C.Vector3,this._quaternionStart=new C.Quaternion,this._scaleStart=new C.Vector3,this._getPointer=Tr.bind(this),this._onPointerDown=Rr.bind(this),this._onPointerHover=mr.bind(this),this._onPointerMove=Ar.bind(this),this._onPointerUp=Fr.bind(this),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp)}updateMatrixWorld(){this.object!==void 0&&(this.object.updateMatrixWorld(),this.object.parent===null?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):this.object.parent.matrixWorld.decompose(this._parentPosition,this._parentQuaternion,this._parentScale),this.object.matrixWorld.decompose(this.worldPosition,this.worldQuaternion,this._worldScale),this._parentQuaternionInv.copy(this._parentQuaternion).invert(),this._worldQuaternionInv.copy(this.worldQuaternion).invert()),this.camera.updateMatrixWorld(),this.camera.matrixWorld.decompose(this.cameraPosition,this.cameraQuaternion,this._cameraScale),this.camera.isOrthographicCamera?this.camera.getWorldDirection(this.eye).negate():this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize(),super.updateMatrixWorld(this)}pointerHover(e){if(this.object===void 0||this.dragging===!0)return;zt.setFromCamera(e,this.camera);const t=ii(this._gizmo.picker[this.mode],zt);t?this.axis=t.object.name:this.axis=null}pointerDown(e){if(!(this.object===void 0||this.dragging===!0||e.button!==0)&&this.axis!==null){zt.setFromCamera(e,this.camera);const t=ii(this._plane,zt,!0);t&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(t.point).sub(this.worldPositionStart)),this.dragging=!0,cn.mode=this.mode,this.dispatchEvent(cn)}}pointerMove(e){const t=this.axis,s=this.mode,i=this.object;let o=this.space;if(s==="scale"?o="local":(t==="E"||t==="XYZE"||t==="XYZ")&&(o="world"),i===void 0||t===null||this.dragging===!1||e.button!==-1)return;zt.setFromCamera(e,this.camera);const n=ii(this._plane,zt,!0);if(n){if(this.pointEnd.copy(n.point).sub(this.worldPositionStart),s==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),o==="local"&&t!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),t.indexOf("X")===-1&&(this._offset.x=0),t.indexOf("Y")===-1&&(this._offset.y=0),t.indexOf("Z")===-1&&(this._offset.z=0),o==="local"&&t!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),i.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(o==="local"&&(i.position.applyQuaternion(Q.copy(this._quaternionStart).invert()),t.search("X")!==-1&&(i.position.x=Math.round(i.position.x/this.translationSnap)*this.translationSnap),t.search("Y")!==-1&&(i.position.y=Math.round(i.position.y/this.translationSnap)*this.translationSnap),t.search("Z")!==-1&&(i.position.z=Math.round(i.position.z/this.translationSnap)*this.translationSnap),i.position.applyQuaternion(this._quaternionStart)),o==="world"&&(i.parent&&i.position.add(it.setFromMatrixPosition(i.parent.matrixWorld)),t.search("X")!==-1&&(i.position.x=Math.round(i.position.x/this.translationSnap)*this.translationSnap),t.search("Y")!==-1&&(i.position.y=Math.round(i.position.y/this.translationSnap)*this.translationSnap),t.search("Z")!==-1&&(i.position.z=Math.round(i.position.z/this.translationSnap)*this.translationSnap),i.parent&&i.position.sub(it.setFromMatrixPosition(i.parent.matrixWorld))));else if(s==="scale"){if(t.search("XYZ")!==-1){let r=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(r*=-1),yt.set(r,r,r)}else it.copy(this.pointStart),yt.copy(this.pointEnd),it.applyQuaternion(this._worldQuaternionInv),yt.applyQuaternion(this._worldQuaternionInv),yt.divide(it),t.search("X")===-1&&(yt.x=1),t.search("Y")===-1&&(yt.y=1),t.search("Z")===-1&&(yt.z=1);i.scale.copy(this._scaleStart).multiply(yt),this.scaleSnap&&(t.search("X")!==-1&&(i.scale.x=Math.round(i.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search("Y")!==-1&&(i.scale.y=Math.round(i.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search("Z")!==-1&&(i.scale.z=Math.round(i.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(s==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const r=20/this.worldPosition.distanceTo(it.setFromMatrixPosition(this.camera.matrixWorld));let a=!1;t==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(it.copy(this.rotationAxis).cross(this.eye))*r):(t==="X"||t==="Y"||t==="Z")&&(this.rotationAxis.copy(an[t]),it.copy(an[t]),o==="local"&&it.applyQuaternion(this.worldQuaternion),it.cross(this.eye),it.length()===0?a=!0:this.rotationAngle=this._offset.dot(it.normalize())*r),(t==="E"||a)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),o==="local"&&t!=="E"&&t!=="XYZE"?(i.quaternion.copy(this._quaternionStart),i.quaternion.multiply(Q.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),i.quaternion.copy(Q.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),i.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(si),this.dispatchEvent(hn)}}pointerUp(e){e.button===0&&(this.dragging&&this.axis!==null&&(ln.mode=this.mode,this.dispatchEvent(ln)),this.dragging=!1,this.axis=null)}dispose(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.traverse(function(e){e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose()})}attach(e){return this.object=e,this.visible=!0,this}detach(){return this.object=void 0,this.visible=!1,this.axis=null,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(si),this.dispatchEvent(hn),this.pointStart.copy(this.pointEnd))}getRaycaster(){return zt}getMode(){return this.mode}setMode(e){this.mode=e}setTranslationSnap(e){this.translationSnap=e}setRotationSnap(e){this.rotationSnap=e}setScaleSnap(e){this.scaleSnap=e}setSize(e){this.size=e}setSpace(e){this.space=e}}function Tr(c){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:c.button};{const e=this.domElement.getBoundingClientRect();return{x:(c.clientX-e.left)/e.width*2-1,y:-(c.clientY-e.top)/e.height*2+1,button:c.button}}}function mr(c){if(this.enabled)switch(c.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(c));break}}function Rr(c){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(c.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(c)),this.pointerDown(this._getPointer(c)))}function Ar(c){this.enabled&&this.pointerMove(this._getPointer(c))}function Fr(c){this.enabled&&(this.domElement.releasePointerCapture(c.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(c)))}function ii(c,e,t){const s=e.intersectObject(c,!0);for(let i=0;i<s.length;i++)if(s[i].object.visible||t)return s[i];return!1}const is=new C.Euler,k=new C.Vector3(0,1,0),En=new C.Vector3(0,0,0),dn=new C.Matrix4,ns=new C.Quaternion,cs=new C.Quaternion,Ft=new C.Vector3,un=new C.Matrix4,_e=new C.Vector3(1,0,0),Ht=new C.Vector3(0,1,0),Ne=new C.Vector3(0,0,1),os=new C.Vector3,ge=new C.Vector3,Se=new C.Vector3;class Or extends C.Object3D{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const e=new C.MeshBasicMaterial({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),t=new C.LineBasicMaterial({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),s=e.clone();s.opacity=.15;const i=t.clone();i.opacity=.5;const o=e.clone();o.color.setHex(16711680);const n=e.clone();n.color.setHex(65280);const r=e.clone();r.color.setHex(255);const a=e.clone();a.color.setHex(16711680),a.opacity=.5;const l=e.clone();l.color.setHex(65280),l.opacity=.5;const h=e.clone();h.color.setHex(255),h.opacity=.5;const d=e.clone();d.opacity=.25;const E=e.clone();E.color.setHex(16776960),E.opacity=.25,e.clone().color.setHex(16776960);const p=e.clone();p.color.setHex(7895160);const F=new C.CylinderGeometry(0,.04,.1,12);F.translate(0,.05,0);const R=new C.BoxGeometry(.08,.08,.08);R.translate(0,.04,0);const T=new C.BufferGeometry;T.setAttribute("position",new C.Float32BufferAttribute([0,0,0,1,0,0],3));const A=new C.CylinderGeometry(.0075,.0075,.5,3);A.translate(0,.25,0);function O(v,z){const j=new C.TorusGeometry(v,.0075,3,64,z*Math.PI*2);return j.rotateY(Math.PI/2),j.rotateX(Math.PI/2),j}function f(){const v=new C.BufferGeometry;return v.setAttribute("position",new C.Float32BufferAttribute([0,0,0,1,1,1],3)),v}const m={X:[[new C.Mesh(F,o),[.5,0,0],[0,0,-Math.PI/2]],[new C.Mesh(F,o),[-.5,0,0],[0,0,Math.PI/2]],[new C.Mesh(A,o),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new C.Mesh(F,n),[0,.5,0]],[new C.Mesh(F,n),[0,-.5,0],[Math.PI,0,0]],[new C.Mesh(A,n)]],Z:[[new C.Mesh(F,r),[0,0,.5],[Math.PI/2,0,0]],[new C.Mesh(F,r),[0,0,-.5],[-Math.PI/2,0,0]],[new C.Mesh(A,r),null,[Math.PI/2,0,0]]],XYZ:[[new C.Mesh(new C.OctahedronGeometry(.1,0),d.clone()),[0,0,0]]],XY:[[new C.Mesh(new C.BoxGeometry(.15,.15,.01),h.clone()),[.15,.15,0]]],YZ:[[new C.Mesh(new C.BoxGeometry(.15,.15,.01),a.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new C.Mesh(new C.BoxGeometry(.15,.15,.01),l.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},g={X:[[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[.3,0,0],[0,0,-Math.PI/2]],[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,.3,0]],[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,-.3,0],[0,0,Math.PI]]],Z:[[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,0,.3],[Math.PI/2,0,0]],[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new C.Mesh(new C.OctahedronGeometry(.2,0),s)]],XY:[[new C.Mesh(new C.BoxGeometry(.2,.2,.01),s),[.15,.15,0]]],YZ:[[new C.Mesh(new C.BoxGeometry(.2,.2,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new C.Mesh(new C.BoxGeometry(.2,.2,.01),s),[.15,0,.15],[-Math.PI/2,0,0]]]},_={START:[[new C.Mesh(new C.OctahedronGeometry(.01,2),i),null,null,null,"helper"]],END:[[new C.Mesh(new C.OctahedronGeometry(.01,2),i),null,null,null,"helper"]],DELTA:[[new C.Line(f(),i),null,null,null,"helper"]],X:[[new C.Line(T,i.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new C.Line(T,i.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new C.Line(T,i.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},N={XYZE:[[new C.Mesh(O(.5,1),p),null,[0,Math.PI/2,0]]],X:[[new C.Mesh(O(.5,.5),o)]],Y:[[new C.Mesh(O(.5,.5),n),null,[0,0,-Math.PI/2]]],Z:[[new C.Mesh(O(.5,.5),r),null,[0,Math.PI/2,0]]],E:[[new C.Mesh(O(.75,1),E),null,[0,Math.PI/2,0]]]},y={AXIS:[[new C.Line(T,i.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},P={XYZE:[[new C.Mesh(new C.SphereGeometry(.25,10,8),s)]],X:[[new C.Mesh(new C.TorusGeometry(.5,.1,4,24),s),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new C.Mesh(new C.TorusGeometry(.5,.1,4,24),s),[0,0,0],[Math.PI/2,0,0]]],Z:[[new C.Mesh(new C.TorusGeometry(.5,.1,4,24),s),[0,0,0],[0,0,-Math.PI/2]]],E:[[new C.Mesh(new C.TorusGeometry(.75,.1,2,24),s)]]},w={X:[[new C.Mesh(R,o),[.5,0,0],[0,0,-Math.PI/2]],[new C.Mesh(A,o),[0,0,0],[0,0,-Math.PI/2]],[new C.Mesh(R,o),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new C.Mesh(R,n),[0,.5,0]],[new C.Mesh(A,n)],[new C.Mesh(R,n),[0,-.5,0],[0,0,Math.PI]]],Z:[[new C.Mesh(R,r),[0,0,.5],[Math.PI/2,0,0]],[new C.Mesh(A,r),[0,0,0],[Math.PI/2,0,0]],[new C.Mesh(R,r),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new C.Mesh(new C.BoxGeometry(.15,.15,.01),h),[.15,.15,0]]],YZ:[[new C.Mesh(new C.BoxGeometry(.15,.15,.01),a),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new C.Mesh(new C.BoxGeometry(.15,.15,.01),l),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new C.Mesh(new C.BoxGeometry(.1,.1,.1),d.clone())]]},M={X:[[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[.3,0,0],[0,0,-Math.PI/2]],[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,.3,0]],[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,-.3,0],[0,0,Math.PI]]],Z:[[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,0,.3],[Math.PI/2,0,0]],[new C.Mesh(new C.CylinderGeometry(.2,0,.6,4),s),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new C.Mesh(new C.BoxGeometry(.2,.2,.01),s),[.15,.15,0]]],YZ:[[new C.Mesh(new C.BoxGeometry(.2,.2,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new C.Mesh(new C.BoxGeometry(.2,.2,.01),s),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new C.Mesh(new C.BoxGeometry(.2,.2,.2),s),[0,0,0]]]},U={X:[[new C.Line(T,i.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new C.Line(T,i.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new C.Line(T,i.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function x(v){const z=new C.Object3D;for(const j in v)for(let et=v[j].length;et--;){const Z=v[j][et][0].clone(),bt=v[j][et][1],vt=v[j][et][2],Bt=v[j][et][3],xe=v[j][et][4];Z.name=j,Z.tag=xe,bt&&Z.position.set(bt[0],bt[1],bt[2]),vt&&Z.rotation.set(vt[0],vt[1],vt[2]),Bt&&Z.scale.set(Bt[0],Bt[1],Bt[2]),Z.updateMatrix();const Ee=Z.geometry.clone();Ee.applyMatrix4(Z.matrix),Z.geometry=Ee,Z.renderOrder=1/0,Z.position.set(0,0,0),Z.rotation.set(0,0,0),Z.scale.set(1,1,1),z.add(Z)}return z}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=x(m)),this.add(this.gizmo.rotate=x(N)),this.add(this.gizmo.scale=x(w)),this.add(this.picker.translate=x(g)),this.add(this.picker.rotate=x(P)),this.add(this.picker.scale=x(M)),this.add(this.helper.translate=x(_)),this.add(this.helper.rotate=x(y)),this.add(this.helper.scale=x(U)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(e){const s=(this.mode==="scale"?"local":this.space)==="local"?this.worldQuaternion:cs;this.gizmo.translate.visible=this.mode==="translate",this.gizmo.rotate.visible=this.mode==="rotate",this.gizmo.scale.visible=this.mode==="scale",this.helper.translate.visible=this.mode==="translate",this.helper.rotate.visible=this.mode==="rotate",this.helper.scale.visible=this.mode==="scale";let i=[];i=i.concat(this.picker[this.mode].children),i=i.concat(this.gizmo[this.mode].children),i=i.concat(this.helper[this.mode].children);for(let o=0;o<i.length;o++){const n=i[o];n.visible=!0,n.rotation.set(0,0,0),n.position.copy(this.worldPosition);let r;if(this.camera.isOrthographicCamera?r=(this.camera.top-this.camera.bottom)/this.camera.zoom:r=this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),n.scale.set(1,1,1).multiplyScalar(r*this.size/4),n.tag==="helper"){n.visible=!1,n.name==="AXIS"?(n.visible=!!this.axis,this.axis==="X"&&(Q.setFromEuler(is.set(0,0,0)),n.quaternion.copy(s).multiply(Q),Math.abs(k.copy(_e).applyQuaternion(s).dot(this.eye))>.9&&(n.visible=!1)),this.axis==="Y"&&(Q.setFromEuler(is.set(0,0,Math.PI/2)),n.quaternion.copy(s).multiply(Q),Math.abs(k.copy(Ht).applyQuaternion(s).dot(this.eye))>.9&&(n.visible=!1)),this.axis==="Z"&&(Q.setFromEuler(is.set(0,Math.PI/2,0)),n.quaternion.copy(s).multiply(Q),Math.abs(k.copy(Ne).applyQuaternion(s).dot(this.eye))>.9&&(n.visible=!1)),this.axis==="XYZE"&&(Q.setFromEuler(is.set(0,Math.PI/2,0)),k.copy(this.rotationAxis),n.quaternion.setFromRotationMatrix(dn.lookAt(En,k,Ht)),n.quaternion.multiply(Q),n.visible=this.dragging),this.axis==="E"&&(n.visible=!1)):n.name==="START"?(n.position.copy(this.worldPositionStart),n.visible=this.dragging):n.name==="END"?(n.position.copy(this.worldPosition),n.visible=this.dragging):n.name==="DELTA"?(n.position.copy(this.worldPositionStart),n.quaternion.copy(this.worldQuaternionStart),it.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),it.applyQuaternion(this.worldQuaternionStart.clone().invert()),n.scale.copy(it),n.visible=this.dragging):(n.quaternion.copy(s),this.dragging?n.position.copy(this.worldPositionStart):n.position.copy(this.worldPosition),this.axis&&(n.visible=this.axis.search(n.name)!==-1));continue}n.quaternion.copy(s),this.mode==="translate"||this.mode==="scale"?(n.name==="X"&&Math.abs(k.copy(_e).applyQuaternion(s).dot(this.eye))>.99&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="Y"&&Math.abs(k.copy(Ht).applyQuaternion(s).dot(this.eye))>.99&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="Z"&&Math.abs(k.copy(Ne).applyQuaternion(s).dot(this.eye))>.99&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="XY"&&Math.abs(k.copy(Ne).applyQuaternion(s).dot(this.eye))<.2&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="YZ"&&Math.abs(k.copy(_e).applyQuaternion(s).dot(this.eye))<.2&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1),n.name==="XZ"&&Math.abs(k.copy(Ht).applyQuaternion(s).dot(this.eye))<.2&&(n.scale.set(1e-10,1e-10,1e-10),n.visible=!1)):this.mode==="rotate"&&(ns.copy(s),k.copy(this.eye).applyQuaternion(Q.copy(s).invert()),n.name.search("E")!==-1&&n.quaternion.setFromRotationMatrix(dn.lookAt(this.eye,En,Ht)),n.name==="X"&&(Q.setFromAxisAngle(_e,Math.atan2(-k.y,k.z)),Q.multiplyQuaternions(ns,Q),n.quaternion.copy(Q)),n.name==="Y"&&(Q.setFromAxisAngle(Ht,Math.atan2(k.x,k.z)),Q.multiplyQuaternions(ns,Q),n.quaternion.copy(Q)),n.name==="Z"&&(Q.setFromAxisAngle(Ne,Math.atan2(k.y,k.x)),Q.multiplyQuaternions(ns,Q),n.quaternion.copy(Q))),n.visible=n.visible&&(n.name.indexOf("X")===-1||this.showX),n.visible=n.visible&&(n.name.indexOf("Y")===-1||this.showY),n.visible=n.visible&&(n.name.indexOf("Z")===-1||this.showZ),n.visible=n.visible&&(n.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),n.material._color=n.material._color||n.material.color.clone(),n.material._opacity=n.material._opacity||n.material.opacity,n.material.color.copy(n.material._color),n.material.opacity=n.material._opacity,this.enabled&&this.axis&&(n.name===this.axis||this.axis.split("").some(function(a){return n.name===a}))&&(n.material.color.setHex(16776960),n.material.opacity=1)}super.updateMatrixWorld(e)}}class gr extends C.Mesh{constructor(){super(new C.PlaneGeometry(1e5,1e5,2,2),new C.MeshBasicMaterial({visible:!1,wireframe:!0,side:C.DoubleSide,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(e){let t=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(t="local"),os.copy(_e).applyQuaternion(t==="local"?this.worldQuaternion:cs),ge.copy(Ht).applyQuaternion(t==="local"?this.worldQuaternion:cs),Se.copy(Ne).applyQuaternion(t==="local"?this.worldQuaternion:cs),k.copy(ge),this.mode){case"translate":case"scale":switch(this.axis){case"X":k.copy(this.eye).cross(os),Ft.copy(os).cross(k);break;case"Y":k.copy(this.eye).cross(ge),Ft.copy(ge).cross(k);break;case"Z":k.copy(this.eye).cross(Se),Ft.copy(Se).cross(k);break;case"XY":Ft.copy(Se);break;case"YZ":Ft.copy(os);break;case"XZ":k.copy(Se),Ft.copy(ge);break;case"XYZ":case"E":Ft.set(0,0,0);break}break;case"rotate":default:Ft.set(0,0,0)}Ft.length()===0?this.quaternion.copy(this.cameraQuaternion):(un.lookAt(it.set(0,0,0),Ft,k),this.quaternion.setFromRotationMatrix(un)),super.updateMatrixWorld(e)}}class ws{constructor(e,t,s,i,o,n=5,r=!0){I(this,"onDraggingStarted",new D);I(this,"onDraggingEnded",new D);I(this,"onDisposed",new D);I(this,"normal");I(this,"origin");I(this,"three",new S.Plane);I(this,"components");I(this,"world");I(this,"_helper");I(this,"_visible",!0);I(this,"_enabled",!0);I(this,"_controlsActive",!1);I(this,"_arrowBoundBox",new S.Mesh);I(this,"_planeMesh");I(this,"_controls");I(this,"_hiddenMaterial",new S.MeshBasicMaterial({visible:!1}));I(this,"update",()=>{this._enabled&&this.three.setFromNormalAndCoplanarPoint(this.normal,this._helper.position)});I(this,"changeDrag",e=>{this._visible=!e.value,this.preventCameraMovement(),this.notifyDraggingChanged(e)});if(this.components=e,this.world=t,!t.renderer)throw new Error("The given world must have a renderer!");this.normal=i,this.origin=s,t.renderer.setPlane(!0,this.three),this._planeMesh=ws.newPlaneMesh(n,o),this._helper=this.newHelper(),this._controls=this.newTransformControls(),this.three.setFromNormalAndCoplanarPoint(i,s),r&&this.toggleControls(!0)}get enabled(){return this._enabled}set enabled(e){if(!this.world.renderer)throw new Error("No renderer found for clipping plane!");this._enabled=e,this.world.renderer.setPlane(e,this.three)}get visible(){return this._visible}set visible(e){this._visible=e,this._controls.visible=e,this._helper.visible=e,this.toggleControls(e)}get meshes(){return[this._planeMesh,this._arrowBoundBox]}get planeMaterial(){return this._planeMesh.material}set planeMaterial(e){this._planeMesh.material=e}get size(){return this._planeMesh.scale.x}set size(e){this._planeMesh.scale.set(e,e,e)}get helper(){return this._helper}setFromNormalAndCoplanarPoint(e,t){this.reset(),this.normal.equals(e)||(this.normal.copy(e),this._helper.lookAt(e)),this.origin.copy(t),this._helper.position.copy(t),this._helper.updateMatrix(),this.update()}dispose(){this._enabled=!1,this.onDraggingStarted.reset(),this.onDraggingEnded.reset(),this._helper.removeFromParent(),this.world.renderer&&this.world.renderer.setPlane(!1,this.three),this._arrowBoundBox.removeFromParent(),this._arrowBoundBox.geometry.dispose(),this._planeMesh.geometry.dispose(),this._controls.removeFromParent(),this._controls.dispose(),this.onDisposed.trigger(),this.onDisposed.reset()}reset(){const e=new S.Vector3(1,0,0),t=new S.Vector3;this.normal.equals(e)||(this.normal.copy(e),this._helper.lookAt(e)),this.origin.copy(t),this._helper.position.copy(t),this._helper.updateMatrix()}toggleControls(e){if(e){if(this._controlsActive)return;this._controls.addEventListener("change",this.update),this._controls.addEventListener("dragging-changed",this.changeDrag)}else this._controls.removeEventListener("change",this.update),this._controls.removeEventListener("dragging-changed",this.changeDrag);this._controlsActive=e}newTransformControls(){if(!this.world.renderer)throw new Error("No renderer found for clipping plane!");const e=this.world.camera.three,t=this.world.renderer.three.domElement,s=new Cr(e,t);return this.initializeControls(s),this.world.scene.three.add(s),s}initializeControls(e){e.attach(this._helper),e.showX=!1,e.showY=!1,e.setSpace("local"),this.createArrowBoundingBox(),e.children[0].children[0].add(this._arrowBoundBox)}createArrowBoundingBox(){this._arrowBoundBox.geometry=new S.CylinderGeometry(.18,.18,1.2),this._arrowBoundBox.material=this._hiddenMaterial,this._arrowBoundBox.rotateX(Math.PI/2),this._arrowBoundBox.updateMatrix(),this._arrowBoundBox.geometry.applyMatrix4(this._arrowBoundBox.matrix)}notifyDraggingChanged(e){e.value?this.onDraggingStarted.trigger():this.onDraggingEnded.trigger()}preventCameraMovement(){this.world.camera.enabled=this._visible}newHelper(){const e=new S.Object3D;return e.lookAt(this.normal),e.position.copy(this.origin),this._planeMesh.position.z+=.01,e.add(this._planeMesh),this.world.scene.three.add(e),e}static newPlaneMesh(e,t){const s=new S.PlaneGeometry(1),i=new S.Mesh(s,t);return i.scale.set(e,e,e),i}}const Me=class Me extends ${constructor(t){super(t);I(this,"onBeforeDrag",new D);I(this,"onAfterDrag",new D);I(this,"onBeforeCreate",new D);I(this,"onBeforeCancel",new D);I(this,"onAfterCancel",new D);I(this,"onBeforeDelete",new D);I(this,"onAfterCreate",new D);I(this,"onAfterDelete",new D);I(this,"onDisposed",new D);I(this,"orthogonalY",!1);I(this,"toleranceOrthogonalY",.7);I(this,"Type",ws);I(this,"list",[]);I(this,"_material",new S.MeshBasicMaterial({color:12255487,side:S.DoubleSide,transparent:!0,opacity:.2}));I(this,"_size",5);I(this,"_enabled",!1);I(this,"_visible",!0);I(this,"_onStartDragging",()=>{this.onBeforeDrag.trigger()});I(this,"_onEndDragging",()=>{this.onAfterDrag.trigger()});this.components.add(Me.uuid,this)}get enabled(){return this._enabled}set enabled(t){this._enabled=t;for(const s of this.list)s.enabled=t;this.updateMaterialsAndPlanes()}get visible(){return this._visible}set visible(t){this._visible=t;for(const s of this.list)s.visible=t}get material(){return this._material}set material(t){this._material=t;for(const s of this.list)s.planeMaterial=t}get size(){return this._size}set size(t){this._size=t;for(const s of this.list)s.size=t}dispose(){this._enabled=!1;for(const t of this.list)t.dispose();this.list.length=0,this._material.dispose(),this.onBeforeCreate.reset(),this.onBeforeCancel.reset(),this.onBeforeDelete.reset(),this.onBeforeDrag.reset(),this.onAfterCreate.reset(),this.onAfterCancel.reset(),this.onAfterDelete.reset(),this.onAfterDrag.reset(),this.onDisposed.trigger(Me.uuid),this.onDisposed.reset()}create(t){const o=this.components.get(ae).get(t).castRay();o&&this.createPlaneFromIntersection(t,o)}createFromNormalAndCoplanarPoint(t,s,i){const o=this.newPlane(t,i,s);return this.updateMaterialsAndPlanes(),o}delete(t,s){s||(s=this.pickPlane(t)),s&&this.deletePlane(s)}deleteAll(){for(;this.list.length>0;){const t=this.list[0];this.delete(t.world,t)}}deletePlane(t){const s=this.list.indexOf(t);if(s!==-1){if(this.list.splice(s,1),!t.world.renderer)throw new Error("Renderer not found for this plane's world!");t.world.renderer.setPlane(!1,t.three),t.dispose(),this.updateMaterialsAndPlanes(),this.onAfterDelete.trigger(t)}}pickPlane(t){const i=this.components.get(ae).get(t),o=this.getAllPlaneMeshes(),n=i.castRay(o);if(n){const r=n.object;return this.list.find(a=>a.meshes.includes(r))}}getAllPlaneMeshes(){const t=[];for(const s of this.list)t.push(...s.meshes);return t}createPlaneFromIntersection(t,s){var a;if(!t.renderer)throw new Error("The given world must have a renderer!");const i=s.point.distanceTo(new S.Vector3(0,0,0)),o=(a=s.face)==null?void 0:a.normal;if(!i||!o)return;const n=this.getWorldNormal(s,o),r=this.newPlane(t,s.point,n.negate());r.visible=this._visible,r.size=this._size,t.renderer.setPlane(!0,r.three),this.updateMaterialsAndPlanes()}getWorldNormal(t,s){const i=t.object;let o=t.object.matrixWorld.clone();if(i instanceof S.InstancedMesh&&t.instanceId!==void 0){const l=new S.Matrix4;i.getMatrixAt(t.instanceId,l),o=l.multiply(o)}const r=new S.Matrix3().getNormalMatrix(o),a=s.clone().applyMatrix3(r).normalize();return this.normalizePlaneDirectionY(a),a}normalizePlaneDirectionY(t){this.orthogonalY&&(t.y>this.toleranceOrthogonalY&&(t.x=0,t.y=1,t.z=0),t.y<-this.toleranceOrthogonalY&&(t.x=0,t.y=-1,t.z=0))}newPlane(t,s,i){const o=new this.Type(this.components,t,s,i,this._material);return o.onDraggingStarted.add(this._onStartDragging),o.onDraggingEnded.add(this._onEndDragging),this.list.push(o),this.onAfterCreate.trigger(o),o}updateMaterialsAndPlanes(){const t=this.components.get(Es);for(const[s,i]of t.list){if(!i.renderer)continue;i.renderer.updateClippingPlanes();const{clippingPlanes:o}=i.renderer;for(const n of i.meshes)if(n.material)if(Array.isArray(n.material))for(const r of n.material)r.clippingPlanes=o;else n.material.clippingPlanes=o}}};I(Me,"uuid","66290bc5-18c4-4cd1-9379-2e17a0617611");let fi=Me;function Sr(c,e,t,s){return new Promise((i,o)=>{function n(){const r=c.clientWaitSync(e,t,0);if(r===c.WAIT_FAILED){o();return}if(r===c.TIMEOUT_EXPIRED){setTimeout(n,s);return}i()}n()})}async function _r(c,e,t,s,i,o,n){const r=c.fenceSync(c.SYNC_GPU_COMMANDS_COMPLETE,0);c.flush(),await Sr(c,r,0,10),c.deleteSync(r),c.bindBuffer(e,t),c.getBufferSubData(e,s,i,o,n),c.bindBuffer(e,null)}async function Pn(c,e,t,s,i,o,n,r){const a=c.createBuffer();return c.bindBuffer(c.PIXEL_PACK_BUFFER,a),c.bufferData(c.PIXEL_PACK_BUFFER,r.byteLength,c.STREAM_READ),c.readPixels(e,t,s,i,o,n,0),c.bindBuffer(c.PIXEL_PACK_BUFFER,null),await _r(c,c.PIXEL_PACK_BUFFER,a,0,r),c.deleteBuffer(a),r}class Mn{constructor(e,t,s){I(this,"onDisposed",new D);I(this,"onViewUpdated",new Le);I(this,"enabled",!0);I(this,"needsUpdate",!1);I(this,"renderDebugFrame",!1);I(this,"components");I(this,"world");I(this,"renderer");I(this,"autoUpdate",!0);I(this,"updateInterval",1e3);I(this,"worker");I(this,"scene",new S.Scene);I(this,"_width",512);I(this,"_height",512);I(this,"_availableColor",1);I(this,"renderTarget");I(this,"bufferSize");I(this,"_buffer");I(this,"_isWorkerBusy",!1);I(this,"updateVisibility",async e=>{if(!this.enabled||!this.needsUpdate&&!e||this._isWorkerBusy)return;this._isWorkerBusy=!0;const t=this.world.camera.three;t.updateMatrix(),this.renderer.setSize(this._width,this._height),this.renderer.setRenderTarget(this.renderTarget),this.renderer.render(this.scene,t);const s=this.renderer.getContext();await Pn(s,0,0,this._width,this._height,s.RGBA,s.UNSIGNED_BYTE,this._buffer),this.renderer.setRenderTarget(null),this.renderDebugFrame&&this.renderer.render(this.scene,t),this.worker.postMessage({buffer:this._buffer}),this.needsUpdate=!1});if(!t.renderer)throw new Error("The given world must have a renderer!");this.components=e,this.applySettings(s),this.world=t,this.renderer=new S.WebGLRenderer,this.renderTarget=new S.WebGLRenderTarget(this._width,this._height),this.bufferSize=this._width*this._height*4,this._buffer=new Uint8Array(this.bufferSize),this.renderer.clippingPlanes=t.renderer.clippingPlanes;const i=`
72
72
  addEventListener("message", (event) => {
73
73
  const { buffer } = event.data;
74
74
  const colors = new Map();
package/dist/index.mjs CHANGED
@@ -2964,7 +2964,7 @@ const Fs = class Fs {
2964
2964
  /**
2965
2965
  * The version of the @thatopen/components library.
2966
2966
  */
2967
- I(Fs, "release", "2.0.21");
2967
+ I(Fs, "release", "2.0.22");
2968
2968
  let pi = Fs;
2969
2969
  class Rr {
2970
2970
  constructor(e) {
@@ -6000,11 +6000,12 @@ const ve = class ve extends et {
6000
6000
  i.renderer.updateClippingPlanes();
6001
6001
  const { clippingPlanes: o } = i.renderer;
6002
6002
  for (const n of i.meshes)
6003
- if (Array.isArray(n.material))
6004
- for (const r of n.material)
6005
- r.clippingPlanes = o;
6006
- else
6007
- n.material.clippingPlanes = o;
6003
+ if (n.material)
6004
+ if (Array.isArray(n.material))
6005
+ for (const r of n.material)
6006
+ r.clippingPlanes = o;
6007
+ else
6008
+ n.material.clippingPlanes = o;
6008
6009
  }
6009
6010
  }
6010
6011
  };