@thatopen/components 2.4.5 → 2.4.6
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.
- package/README.md +92 -0
- package/dist/core/Components/index.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.min.cjs +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/namespace.d.ts +4051 -4051
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://thatopen.com/">TOC</a>
|
|
3
|
+
|
|
|
4
|
+
<a href="https://docs.thatopen.com/intro">documentation</a>
|
|
5
|
+
|
|
|
6
|
+
<a href="https://thatopen.github.io/engine_components/examples/IfcLoader/index.html">demo</a>
|
|
7
|
+
|
|
|
8
|
+
<a href="https://people.thatopen.com/">community</a>
|
|
9
|
+
|
|
|
10
|
+
<a href="https://www.npmjs.com/org/thatopen">npm package</a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
<h1>Open BIM Components <img src="https://thatopen.github.io/engine_components/resources/favicon.ico" width="32"/></h1>
|
|
16
|
+
|
|
17
|
+
[![NPM Package][npm]][npm-url]
|
|
18
|
+
[![NPM Package][npm-downloads]][npm-url]
|
|
19
|
+
|
|
20
|
+
This library is a collection of BIM tools based on [Three.js](https://github.com/mrdoob/three.js/) and other libraries. It includes pre-made features to easily build browser-based 3D BIM applications, such as postproduction, dimensions, floorplan navigation, DXF export and much more.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## 🤝 Want our help?
|
|
24
|
+
Are you developing a project with our technology and would like our help?
|
|
25
|
+
Apply now to join [That Open Accelerator Program](https://thatopen.com/accelerator)!
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## 🧩 Integration with fragments
|
|
29
|
+
As you might know, we have 4 open source libraries:
|
|
30
|
+
- [web-ifc](https://github.com/ThatOpen/engine_web-ifc): the IFC parser and geometry engine.
|
|
31
|
+
- [fragments](https://github.com/ThatOpen/engine_fragment): the open source format and 3D engine.
|
|
32
|
+
- [components](https://github.com/ThatOpen/engine_components): a set of tools to build BIM software fast.
|
|
33
|
+
- [ui components](https://github.com/ThatOpen/engine_ui-components): our agnostic UI system.
|
|
34
|
+
|
|
35
|
+
Components doesn't work with this new version of Fragments yet. In the next release, at the end of Q2, all components will be updated to work with this new version of Fragments. In the meantime, you have 3 options:
|
|
36
|
+
|
|
37
|
+
- Work with Fragments and build your own BIM components from scratch.
|
|
38
|
+
- Work with Components (which don't use this new version of Fragments).
|
|
39
|
+
- Check out our [Accelerator Program](https://thatopen.com/accelerator) to get previous access to the upcoming components.
|
|
40
|
+
|
|
41
|
+
Once the release at the end of Q2 is made, Components will work natively with this new version of Fragments.
|
|
42
|
+
|
|
43
|
+
## Packages
|
|
44
|
+
|
|
45
|
+
This library contains 2 packages:
|
|
46
|
+
|
|
47
|
+
`@thatopen/components` - The core functionality. Compatible both with browser and Node.js environments.
|
|
48
|
+
|
|
49
|
+
`@thatopen/components-front` - Features exclusive for browser environments.
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
You need to be familiar with [Three.js API](https://github.com/mrdoob/three.js/) to be able to use this library effectively. In the following example, we will create a cube in a 3D scene that can be navigated with the mouse or touch events. You can see the full example [here](https://github.com/ThatOpen/engine_components/blob/main/packages/core/src/core/Worlds/example.ts) and the deployed app [here](https://thatopen.github.io/engine_components/examples/Worlds/index.html).
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
/* eslint import/no-extraneous-dependencies: 0 */
|
|
57
|
+
|
|
58
|
+
import * as THREE from "three";
|
|
59
|
+
import * as OBC from "../..";
|
|
60
|
+
|
|
61
|
+
const container = document.getElementById("container")!;
|
|
62
|
+
|
|
63
|
+
const components = new OBC.Components();
|
|
64
|
+
|
|
65
|
+
const worlds = components.get(OBC.Worlds);
|
|
66
|
+
|
|
67
|
+
const world = worlds.create<
|
|
68
|
+
OBC.SimpleScene,
|
|
69
|
+
OBC.SimpleCamera,
|
|
70
|
+
OBC.SimpleRenderer
|
|
71
|
+
>();
|
|
72
|
+
|
|
73
|
+
world.scene = new OBC.SimpleScene(components);
|
|
74
|
+
world.renderer = new OBC.SimpleRenderer(components, container);
|
|
75
|
+
world.camera = new OBC.SimpleCamera(components);
|
|
76
|
+
|
|
77
|
+
components.init();
|
|
78
|
+
|
|
79
|
+
const material = new THREE.MeshLambertMaterial({ color: "#6528D7" });
|
|
80
|
+
const geometry = new THREE.BoxGeometry();
|
|
81
|
+
const cube = new THREE.Mesh(geometry, material);
|
|
82
|
+
world.scene.three.add(cube);
|
|
83
|
+
|
|
84
|
+
world.scene.setup();
|
|
85
|
+
|
|
86
|
+
world.camera.controls.setLookAt(3, 3, 3, 0, 0, 0);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
[npm]: https://img.shields.io/npm/v/@thatopen/components
|
|
91
|
+
[npm-url]: https://www.npmjs.com/package/@thatopen/components
|
|
92
|
+
[npm-downloads]: https://img.shields.io/npm/dw/@thatopen/components
|
|
@@ -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.4.
|
|
9
|
+
static readonly release = "2.4.6";
|
|
10
10
|
/** {@link Disposable.onDisposed} */
|
|
11
11
|
readonly onDisposed: Event<void>;
|
|
12
12
|
/**
|
package/dist/index.cjs
CHANGED
|
@@ -6312,7 +6312,7 @@ const _Components = class _Components {
|
|
|
6312
6312
|
/**
|
|
6313
6313
|
* The version of the @thatopen/components library.
|
|
6314
6314
|
*/
|
|
6315
|
-
__publicField(_Components, "release", "2.4.
|
|
6315
|
+
__publicField(_Components, "release", "2.4.6");
|
|
6316
6316
|
let Components = _Components;
|
|
6317
6317
|
class SimpleWorld extends Base {
|
|
6318
6318
|
constructor() {
|
package/dist/index.min.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var e=Object.defineProperty,t=(t,i,s)=>(((t,i,s)=>{i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[i]=s})(t,"symbol"!=typeof i?i+"":i,s),s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("three"),s=require("@thatopen/fragments"),n=require("web-ifc");function r(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const i in e)if("default"!==i){const s=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,s.get?s:{enumerable:!0,get:()=>e[i]})}return t.default=e,Object.freeze(t)}const o=r(i),a=r(s),c=r(n),l=1.25,h=65535,u=Math.pow(2,-24),I=Symbol("SKIP_GENERATION");function d(e){return function(e){return e.index?e.index.count:e.attributes.position.count}(e)/3}function E(e,t){if(!e.index){const s=e.attributes.position.count,n=function(e,t=ArrayBuffer){return e>65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}(s,t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);e.setIndex(new i.BufferAttribute(n,1));for(let e=0;e<s;e++)n[e]=e}}function f(e){const t=d(e),i=e.drawRange,s=i.start/3,n=(i.start+i.count)/3,r=Math.max(0,s),o=Math.min(t,n)-r;return[{offset:Math.floor(r),count:Math.floor(o)}]}function p(e){if(!e.groups||!e.groups.length)return f(e);const t=[],i=new Set,s=e.drawRange,n=s.start/3,r=(s.start+s.count)/3;for(const t of e.groups){const e=t.start/3,s=(t.start+t.count)/3;i.add(Math.max(n,e)),i.add(Math.min(r,s))}const o=Array.from(i.values()).sort(((e,t)=>e-t));for(let e=0;e<o.length-1;e++){const i=o[e],s=o[e+1];t.push({offset:Math.floor(i),count:Math.floor(s-i)})}return t}function C(e,t,i){return i.min.x=t[e],i.min.y=t[e+1],i.min.z=t[e+2],i.max.x=t[e+3],i.max.y=t[e+4],i.max.z=t[e+5],i}function T(e){let t=-1,i=-1/0;for(let s=0;s<3;s++){const n=e[s+3]-e[s];n>i&&(i=n,t=s)}return t}function m(e,t){t.set(e)}function R(e,t,i){let s,n;for(let r=0;r<3;r++){const o=r+3;s=e[r],n=t[r],i[r]=s<n?s:n,s=e[o],n=t[o],i[o]=s>n?s:n}}function g(e,t,i){for(let s=0;s<3;s++){const n=t[e+2*s],r=t[e+2*s+1],o=n-r,a=n+r;o<i[s]&&(i[s]=o),a>i[s+3]&&(i[s+3]=a)}}function A(e){const t=e[3]-e[0],i=e[4]-e[1],s=e[5]-e[2];return 2*(t*i+i*s+s*t)}function F(e,t,i,s,n=null){let r=1/0,o=1/0,a=1/0,c=-1/0,l=-1/0,h=-1/0,u=1/0,I=1/0,d=1/0,E=-1/0,f=-1/0,p=-1/0;const C=null!==n;for(let s=6*t,n=6*(t+i);s<n;s+=6){const t=e[s+0],i=e[s+1],n=t-i,T=t+i;n<r&&(r=n),T>c&&(c=T),C&&t<u&&(u=t),C&&t>E&&(E=t);const m=e[s+2],R=e[s+3],g=m-R,A=m+R;g<o&&(o=g),A>l&&(l=A),C&&m<I&&(I=m),C&&m>f&&(f=m);const F=e[s+4],S=e[s+5],O=F-S,N=F+S;O<a&&(a=O),N>h&&(h=N),C&&F<d&&(d=F),C&&F>p&&(p=F)}s[0]=r,s[1]=o,s[2]=a,s[3]=c,s[4]=l,s[5]=h,C&&(n[0]=u,n[1]=I,n[2]=d,n[3]=E,n[4]=f,n[5]=p)}const S=32,O=(e,t)=>e.candidate-t.candidate,N=new Array(S).fill().map((()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0}))),y=new Float32Array(6);class _{constructor(){}}function L(e,t,i,s,n,r){let o=s,a=s+n-1;const c=r.pos,l=2*r.axis;for(;;){for(;o<=a&&i[6*o+l]<c;)o++;for(;o<=a&&i[6*a+l]>=c;)a--;if(!(o<a))return o;for(let e=0;e<3;e++){let i=t[3*o+e];t[3*o+e]=t[3*a+e],t[3*a+e]=i}for(let e=0;e<6;e++){let t=i[6*o+e];i[6*o+e]=i[6*a+e],i[6*a+e]=t}o++,a--}}function P(e,t,i,s,n,r){let o=s,a=s+n-1;const c=r.pos,l=2*r.axis;for(;;){for(;o<=a&&i[6*o+l]<c;)o++;for(;o<=a&&i[6*a+l]>=c;)a--;if(!(o<a))return o;{let t=e[o];e[o]=e[a],e[a]=t;for(let e=0;e<6;e++){let t=i[6*o+e];i[6*o+e]=i[6*a+e],i[6*a+e]=t}o++,a--}}}function w(e,t){const i=e.geometry,s=i.index?i.index.array:null,n=t.maxDepth,r=t.verbose,o=t.maxLeafTris,a=t.strategy,c=t.onProgress,h=d(i),I=e._indirectBuffer;let E=!1;const C=new Float32Array(6),w=new Float32Array(6),M=function(e,t){var i;(i=t)[0]=i[1]=i[2]=1/0,i[3]=i[4]=i[5]=-1/0;const s=e.attributes.position,n=e.index?e.index.array:null,r=d(e),o=new Float32Array(6*r),a=s.normalized,c=s.array,l=s.offset||0;let h=3;s.isInterleavedBufferAttribute&&(h=s.data.stride);const I=["getX","getY","getZ"];for(let e=0;e<r;e++){const i=3*e,r=6*e;let d=i+0,E=i+1,f=i+2;n&&(d=n[d],E=n[E],f=n[f]),a||(d=d*h+l,E=E*h+l,f=f*h+l);for(let e=0;e<3;e++){let i,n,l;a?(i=s[I[e]](d),n=s[I[e]](E),l=s[I[e]](f)):(i=c[d+e],n=c[E+e],l=c[f+e]);let h=i;n<h&&(h=n),l<h&&(h=l);let p=i;n>p&&(p=n),l>p&&(p=l);const C=(p-h)/2,T=2*e;o[r+T+0]=h+C,o[r+T+1]=C+(Math.abs(h)+C)*u,h<t[e]&&(t[e]=h),p>t[e+3]&&(t[e+3]=p)}}return o}(i,C),v=t.indirect?P:L,D=[],x=t.indirect?f(i):p(i);if(1===x.length){const e=x[0],t=new _;t.boundingData=C,function(e,t,i,s){let n=1/0,r=1/0,o=1/0,a=-1/0,c=-1/0,l=-1/0;for(let s=6*t,h=6*(t+i);s<h;s+=6){const t=e[s+0];t<n&&(n=t),t>a&&(a=t);const i=e[s+2];i<r&&(r=i),i>c&&(c=i);const h=e[s+4];h<o&&(o=h),h>l&&(l=h)}s[0]=n,s[1]=r,s[2]=o,s[3]=a,s[4]=c,s[5]=l}(M,e.offset,e.count,w),U(t,e.offset,e.count,w),D.push(t)}else for(let e of x){const t=new _;t.boundingData=new Float32Array(6),F(M,e.offset,e.count,t.boundingData,w),U(t,e.offset,e.count,w),D.push(t)}return D;function b(e){c&&c(e/h)}function U(e,t,c,h=null,u=0){if(!E&&u>=n&&(E=!0,r&&(console.warn(`MeshBVH: Max depth of ${n} reached when generating BVH. Consider increasing maxDepth.`),console.warn(i))),c<=o||u>=n)return b(t+c),e.offset=t,e.count=c,e;const d=function(e,t,i,s,n,r){let o=-1,a=0;if(0===r)o=T(t),-1!==o&&(a=(t[o]+t[o+3])/2);else if(1===r)o=T(e),-1!==o&&(a=function(e,t,i,s){let n=0;for(let r=t,o=t+i;r<o;r++)n+=e[6*r+2*s];return n/i}(i,s,n,o));else if(2===r){const r=A(e);let c=l*n;const h=6*s,u=6*(s+n);for(let e=0;e<3;e++){const s=t[e],I=(t[e+3]-s)/S;if(n<8){const t=[...N];t.length=n;let s=0;for(let n=h;n<u;n+=6,s++){const r=t[s];r.candidate=i[n+2*e],r.count=0;const{bounds:o,leftCacheBounds:a,rightCacheBounds:c}=r;for(let e=0;e<3;e++)c[e]=1/0,c[e+3]=-1/0,a[e]=1/0,a[e+3]=-1/0,o[e]=1/0,o[e+3]=-1/0;g(n,i,o)}t.sort(O);let I=n;for(let e=0;e<I;e++){const i=t[e];for(;e+1<I&&t[e+1].candidate===i.candidate;)t.splice(e+1,1),I--}for(let s=h;s<u;s+=6){const n=i[s+2*e];for(let e=0;e<I;e++){const r=t[e];n>=r.candidate?g(s,i,r.rightCacheBounds):(g(s,i,r.leftCacheBounds),r.count++)}}for(let i=0;i<I;i++){const s=t[i],h=s.count,u=n-s.count,I=s.leftCacheBounds,d=s.rightCacheBounds;let E=0;0!==h&&(E=A(I)/r);let f=0;0!==u&&(f=A(d)/r);const p=1+l*(E*h+f*u);p<c&&(o=e,c=p,a=s.candidate)}}else{for(let e=0;e<S;e++){const t=N[e];t.count=0,t.candidate=s+I+e*I;const i=t.bounds;for(let e=0;e<3;e++)i[e]=1/0,i[e+3]=-1/0}for(let t=h;t<u;t+=6){let n=~~((i[t+2*e]-s)/I);n>=S&&(n=31);const r=N[n];r.count++,g(t,i,r.bounds)}const t=N[31];m(t.bounds,t.rightCacheBounds);for(let e=30;e>=0;e--){const t=N[e],i=N[e+1];R(t.bounds,i.rightCacheBounds,t.rightCacheBounds)}let d=0;for(let t=0;t<31;t++){const i=N[t],s=i.count,h=i.bounds,u=N[t+1].rightCacheBounds;0!==s&&(0===d?m(h,y):R(h,y,y)),d+=s;let I=0,E=0;0!==d&&(I=A(y)/r);const f=n-d;0!==f&&(E=A(u)/r);const p=1+l*(I*d+E*f);p<c&&(o=e,c=p,a=i.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${r} used.`);return{axis:o,pos:a}}(e.boundingData,h,M,t,c,a);if(-1===d.axis)return b(t+c),e.offset=t,e.count=c,e;const f=v(I,s,M,t,c,d);if(f===t||f===t+c)b(t+c),e.offset=t,e.count=c;else{e.splitAxis=d.axis;const i=new _,s=t,n=f-t;e.left=i,i.boundingData=new Float32Array(6),F(M,s,n,i.boundingData,w),U(i,s,n,w,u+1);const r=new _,o=f,a=c-n;e.right=r,r.boundingData=new Float32Array(6),F(M,o,a,r.boundingData,w),U(r,o,a,w,u+1)}return e}}function M(e,t){const i=e.geometry;t.indirect&&(e._indirectBuffer=function(e,t){const i=(e.index?e.index.count:e.attributes.position.count)/3,s=i>65536,n=s?4:2,r=t?new SharedArrayBuffer(i*n):new ArrayBuffer(i*n),o=s?new Uint32Array(r):new Uint16Array(r);for(let e=0,t=o.length;e<t;e++)o[e]=e;return o}(i,t.useSharedArrayBuffer),function(e){if(0===e.groups.length)return!1;const t=d(e),i=p(e).sort(((e,t)=>e.offset-t.offset)),s=i[i.length-1];s.count=Math.min(t-s.offset,s.count);let n=0;return i.forEach((({count:e})=>n+=e)),t!==n}(i)&&!t.verbose&&console.warn('MeshBVH: Provided geometry contains groups that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),e._indirectBuffer||E(i,t);const s=w(e,t);let n,r,o;const a=[],c=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer;for(let e=0;e<s.length;e++){const t=s[e];const i=new c(32*l(t));n=new Float32Array(i),r=new Uint32Array(i),o=new Uint16Array(i),u(0,t),a.push(i)}return void(e._roots=a);function l(e){return e.count?1:1+l(e.left)+l(e.right)}function u(e,t){const i=e/4,s=e/2,a=!!t.count,c=t.boundingData;for(let e=0;e<6;e++)n[i+e]=c[e];if(a){const n=t.offset,a=t.count;return r[i+6]=n,o[s+14]=a,o[s+15]=h,e+32}{const s=t.left,n=t.right,o=t.splitAxis;let a;if(a=u(e+32,s),a/4>Math.pow(2,32))throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return r[i+6]=a/4,a=u(a,n),r[i+7]=o,a}}}class v{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let i=1/0,s=-1/0;for(let n=0,r=e.length;n<r;n++){const r=e[n][t];i=r<i?r:i,s=r>s?r:s}this.min=i,this.max=s}setFromPoints(e,t){let i=1/0,s=-1/0;for(let n=0,r=t.length;n<r;n++){const r=t[n],o=e.dot(r);i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}isSeparated(e){return this.min>e.max||e.min>this.max}}v.prototype.setFromBox=function(){const e=new i.Vector3;return function(t,i){const s=i.min,n=i.max;let r=1/0,o=-1/0;for(let i=0;i<=1;i++)for(let a=0;a<=1;a++)for(let c=0;c<=1;c++){e.x=s.x*i+n.x*(1-i),e.y=s.y*a+n.y*(1-a),e.z=s.z*c+n.z*(1-c);const l=t.dot(e);r=Math.min(l,r),o=Math.max(l,o)}this.min=r,this.max=o}}();const D=function(){const e=new i.Vector3,t=new i.Vector3,s=new i.Vector3;return function(i,n,r){const o=i.start,a=e,c=n.start,l=t;s.subVectors(o,c),e.subVectors(i.end,i.start),t.subVectors(n.end,n.start);const h=s.dot(l),u=l.dot(a),I=l.dot(l),d=s.dot(a),E=a.dot(a)*I-u*u;let f,p;f=0!==E?(h*u-d*I)/E:0,p=(h+f*u)/I,r.x=f,r.y=p}}(),x=function(){const e=new i.Vector2,t=new i.Vector3,s=new i.Vector3;return function(i,n,r,o){D(i,n,e);let a=e.x,c=e.y;if(a>=0&&a<=1&&c>=0&&c<=1)return i.at(a,r),void n.at(c,o);if(a>=0&&a<=1)return c<0?n.at(0,o):n.at(1,o),void i.closestPointToPoint(o,!0,r);if(c>=0&&c<=1)return a<0?i.at(0,r):i.at(1,r),void n.closestPointToPoint(r,!0,o);{let e,l;e=a<0?i.start:i.end,l=c<0?n.start:n.end;const h=t,u=s;return i.closestPointToPoint(l,!0,t),n.closestPointToPoint(e,!0,s),h.distanceToSquared(l)<=u.distanceToSquared(e)?(r.copy(h),void o.copy(l)):(r.copy(e),void o.copy(u))}}}(),b=function(){const e=new i.Vector3,t=new i.Vector3,s=new i.Plane,n=new i.Line3;return function(i,r){const{radius:o,center:a}=i,{a:c,b:l,c:h}=r;n.start=c,n.end=l;if(n.closestPointToPoint(a,!0,e).distanceTo(a)<=o)return!0;n.start=c,n.end=h;if(n.closestPointToPoint(a,!0,e).distanceTo(a)<=o)return!0;n.start=l,n.end=h;if(n.closestPointToPoint(a,!0,e).distanceTo(a)<=o)return!0;const u=r.getPlane(s);if(Math.abs(u.distanceToPoint(a))<=o){const e=u.projectPoint(a,t);if(r.containsPoint(e))return!0}return!1}}();function U(e){return Math.abs(e)<1e-15}class B extends i.Triangle{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map((()=>new i.Vector3)),this.satBounds=new Array(4).fill().map((()=>new v)),this.points=[this.a,this.b,this.c],this.sphere=new i.Sphere,this.plane=new i.Plane,this.needsUpdate=!0}intersectsSphere(e){return b(e,this)}update(){const e=this.a,t=this.b,i=this.c,s=this.points,n=this.satAxes,r=this.satBounds,o=n[0],a=r[0];this.getNormal(o),a.setFromPoints(o,s);const c=n[1],l=r[1];c.subVectors(e,t),l.setFromPoints(c,s);const h=n[2],u=r[2];h.subVectors(t,i),u.setFromPoints(h,s);const I=n[3],d=r[3];I.subVectors(i,e),d.setFromPoints(I,s),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}}B.prototype.closestPointToSegment=function(){const e=new i.Vector3,t=new i.Vector3,s=new i.Line3;return function(i,n=null,r=null){const{start:o,end:a}=i,c=this.points;let l,h=1/0;for(let o=0;o<3;o++){const a=(o+1)%3;s.start.copy(c[o]),s.end.copy(c[a]),x(s,i,e,t),l=e.distanceToSquared(t),l<h&&(h=l,n&&n.copy(e),r&&r.copy(t))}return this.closestPointToPoint(o,e),l=o.distanceToSquared(e),l<h&&(h=l,n&&n.copy(e),r&&r.copy(o)),this.closestPointToPoint(a,e),l=a.distanceToSquared(e),l<h&&(h=l,n&&n.copy(e),r&&r.copy(a)),Math.sqrt(h)}}(),B.prototype.intersectsTriangle=function(){const e=new B,t=new Array(3),s=new Array(3),n=new v,r=new v,o=new i.Vector3,a=new i.Vector3,c=new i.Vector3,l=new i.Vector3,h=new i.Vector3,u=new i.Line3,I=new i.Line3,d=new i.Line3,E=new i.Vector3;function f(e,t,i){const s=e.points;let n=0,r=-1;for(let e=0;e<3;e++){const{start:o,end:c}=u;o.copy(s[e]),c.copy(s[(e+1)%3]),u.delta(a);const l=U(t.distanceToPoint(o));if(U(t.normal.dot(a))&&l){i.copy(u),n=2;break}const h=t.intersectLine(u,E);if(!h&&l&&E.copy(o),(h||l)&&!U(E.distanceTo(c))){if(n<=1){(1===n?i.start:i.end).copy(E),l&&(r=n)}else if(n>=2){(1===r?i.start:i.end).copy(E),n=2;break}if(n++,2===n&&-1===r)break}}return n}return function(i,a=null,u=!1){this.needsUpdate&&this.update(),i.isExtendedTriangle?i.needsUpdate&&i.update():(e.copy(i),e.update(),i=e);const E=this.plane,p=i.plane;if(Math.abs(E.normal.dot(p.normal))>1-1e-10){const e=this.satBounds,c=this.satAxes;s[0]=i.a,s[1]=i.b,s[2]=i.c;for(let t=0;t<4;t++){const i=e[t],r=c[t];if(n.setFromPoints(r,s),i.isSeparated(n))return!1}const l=i.satBounds,h=i.satAxes;t[0]=this.a,t[1]=this.b,t[2]=this.c;for(let e=0;e<4;e++){const i=l[e],s=h[e];if(n.setFromPoints(s,t),i.isSeparated(n))return!1}for(let e=0;e<4;e++){const i=c[e];for(let e=0;e<4;e++){const a=h[e];if(o.crossVectors(i,a),n.setFromPoints(o,t),r.setFromPoints(o,s),n.isSeparated(r))return!1}}return a&&(u||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),a.start.set(0,0,0),a.end.set(0,0,0)),!0}{const e=f(this,p,I);if(1===e&&i.containsPoint(I.end))return a&&(a.start.copy(I.end),a.end.copy(I.end)),!0;if(2!==e)return!1;const t=f(i,E,d);if(1===t&&this.containsPoint(d.end))return a&&(a.start.copy(d.end),a.end.copy(d.end)),!0;if(2!==t)return!1;if(I.delta(c),d.delta(l),c.dot(l)<0){let e=d.start;d.start=d.end,d.end=e}const s=I.start.dot(c),n=I.end.dot(c),r=d.start.dot(c),o=d.end.dot(c);return(s===o||r===n||n<r!==s<o)&&(a&&(h.subVectors(I.start,d.start),h.dot(c)>0?a.start.copy(I.start):a.start.copy(d.start),h.subVectors(I.end,d.end),h.dot(c)<0?a.end.copy(I.end):a.end.copy(d.end)),!0)}}}(),B.prototype.distanceToPoint=function(){const e=new i.Vector3;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}}(),B.prototype.distanceToTriangle=function(){const e=new i.Vector3,t=new i.Vector3,s=["a","b","c"],n=new i.Line3,r=new i.Line3;return function(i,o=null,a=null){const c=o||a?n:null;if(this.intersectsTriangle(i,c))return(o||a)&&(o&&c.getCenter(o),a&&c.getCenter(a)),0;let l=1/0;for(let t=0;t<3;t++){let n;const r=s[t],c=i[r];this.closestPointToPoint(c,e),n=c.distanceToSquared(e),n<l&&(l=n,o&&o.copy(e),a&&a.copy(c));const h=this[r];i.closestPointToPoint(h,e),n=h.distanceToSquared(e),n<l&&(l=n,o&&o.copy(h),a&&a.copy(e))}for(let c=0;c<3;c++){const h=s[c],u=s[(c+1)%3];n.set(this[h],this[u]);for(let c=0;c<3;c++){const h=s[c],u=s[(c+1)%3];r.set(i[h],i[u]),x(n,r,e,t);const I=e.distanceToSquared(t);I<l&&(l=I,o&&o.copy(e),a&&a.copy(t))}}return Math.sqrt(l)}}();class V{constructor(e,t,s){this.isOrientedBox=!0,this.min=new i.Vector3,this.max=new i.Vector3,this.matrix=new i.Matrix4,this.invMatrix=new i.Matrix4,this.points=new Array(8).fill().map((()=>new i.Vector3)),this.satAxes=new Array(3).fill().map((()=>new i.Vector3)),this.satBounds=new Array(3).fill().map((()=>new v)),this.alignedSatBounds=new Array(3).fill().map((()=>new v)),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),s&&this.matrix.copy(s)}set(e,t,i){this.min.copy(e),this.max.copy(t),this.matrix.copy(i),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}V.prototype.update=function(){return function(){const e=this.matrix,t=this.min,i=this.max,s=this.points;for(let n=0;n<=1;n++)for(let r=0;r<=1;r++)for(let o=0;o<=1;o++){const a=s[1*n|2*r|4*o];a.x=n?i.x:t.x,a.y=r?i.y:t.y,a.z=o?i.z:t.z,a.applyMatrix4(e)}const n=this.satBounds,r=this.satAxes,o=s[0];for(let e=0;e<3;e++){const t=r[e],i=n[e],a=s[1<<e];t.subVectors(o,a),i.setFromPoints(t,s)}const a=this.alignedSatBounds;a[0].setFromPointsField(s,"x"),a[1].setFromPointsField(s,"y"),a[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),V.prototype.intersectsBox=function(){const e=new v;return function(t){this.needsUpdate&&this.update();const i=t.min,s=t.max,n=this.satBounds,r=this.satAxes,o=this.alignedSatBounds;if(e.min=i.x,e.max=s.x,o[0].isSeparated(e))return!1;if(e.min=i.y,e.max=s.y,o[1].isSeparated(e))return!1;if(e.min=i.z,e.max=s.z,o[2].isSeparated(e))return!1;for(let i=0;i<3;i++){const s=r[i],o=n[i];if(e.setFromBox(s,t),o.isSeparated(e))return!1}return!0}}(),V.prototype.intersectsTriangle=function(){const e=new B,t=new Array(3),s=new v,n=new v,r=new i.Vector3;return function(i){this.needsUpdate&&this.update(),i.isExtendedTriangle?i.needsUpdate&&i.update():(e.copy(i),e.update(),i=e);const o=this.satBounds,a=this.satAxes;t[0]=i.a,t[1]=i.b,t[2]=i.c;for(let e=0;e<3;e++){const i=o[e],n=a[e];if(s.setFromPoints(n,t),i.isSeparated(s))return!1}const c=i.satBounds,l=i.satAxes,h=this.points;for(let e=0;e<3;e++){const t=c[e],i=l[e];if(s.setFromPoints(i,h),t.isSeparated(s))return!1}for(let e=0;e<3;e++){const i=a[e];for(let e=0;e<4;e++){const o=l[e];if(r.crossVectors(i,o),s.setFromPoints(r,t),n.setFromPoints(r,h),s.isSeparated(n))return!1}}return!0}}(),V.prototype.closestPointToPoint=function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}}(),V.prototype.distanceToPoint=function(){const e=new i.Vector3;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}}(),V.prototype.distanceToBox=function(){const e=["x","y","z"],t=new Array(12).fill().map((()=>new i.Line3)),s=new Array(12).fill().map((()=>new i.Line3)),n=new i.Vector3,r=new i.Vector3;return function(i,o=0,a=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(i))return(a||c)&&(i.getCenter(r),this.closestPointToPoint(r,n),i.closestPointToPoint(n,r),a&&a.copy(n),c&&c.copy(r)),0;const l=o*o,h=i.min,u=i.max,I=this.points;let d=1/0;for(let e=0;e<8;e++){const t=I[e];r.copy(t).clamp(h,u);const i=t.distanceToSquared(r);if(i<d&&(d=i,a&&a.copy(t),c&&c.copy(r),i<l))return Math.sqrt(i)}let E=0;for(let i=0;i<3;i++)for(let n=0;n<=1;n++)for(let r=0;r<=1;r++){const o=(i+1)%3,a=(i+2)%3,c=1<<i|n<<o|r<<a,l=I[n<<o|r<<a],d=I[c];t[E].set(l,d);const f=e[i],p=e[o],C=e[a],T=s[E],m=T.start,R=T.end;m[f]=h[f],m[p]=n?h[p]:u[p],m[C]=r?h[C]:u[p],R[f]=u[f],R[p]=n?h[p]:u[p],R[C]=r?h[C]:u[p],E++}for(let e=0;e<=1;e++)for(let t=0;t<=1;t++)for(let i=0;i<=1;i++){r.x=e?u.x:h.x,r.y=t?u.y:h.y,r.z=i?u.z:h.z,this.closestPointToPoint(r,n);const s=r.distanceToSquared(n);if(s<d&&(d=s,a&&a.copy(n),c&&c.copy(r),s<l))return Math.sqrt(s)}for(let e=0;e<12;e++){const i=t[e];for(let e=0;e<12;e++){const t=s[e];x(i,t,n,r);const o=n.distanceToSquared(r);if(o<d&&(d=o,a&&a.copy(n),c&&c.copy(r),o<l))return Math.sqrt(o)}}return Math.sqrt(d)}}();class Y{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return 0===e.length?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class G extends Y{constructor(){super((()=>new B))}}const z=new G;function k(e,t){return 65535===t[e+15]}function H(e,t){return t[e+6]}function W(e,t){return t[e+14]}function X(e){return e+8}function Z(e,t){return t[e+6]}function j(e,t){return t[e+7]}const $=new class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=i=>{t&&e.push(t),t=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,0!==e.length&&this.setBuffer(e.pop())}}};let Q,q;const K=[],J=new Y((()=>new i.Box3));function ee(e,t,i,s,n,r){Q=J.getPrimitive(),q=J.getPrimitive(),K.push(Q,q),$.setBuffer(e._roots[t]);const o=te(0,e.geometry,i,s,n,r);$.clearBuffer(),J.releasePrimitive(Q),J.releasePrimitive(q),K.pop(),K.pop();const a=K.length;return a>0&&(q=K[a-1],Q=K[a-2]),o}function te(e,t,i,s,n=null,r=0,o=0){const{float32Array:a,uint16Array:c,uint32Array:l}=$;let h=2*e;if(k(h,c)){const t=H(e,l),i=W(h,c);return C(e,a,Q),s(t,i,!1,o,r+e,Q)}{let h=function(e){const{uint16Array:t,uint32Array:i}=$;let s=2*e;for(;!k(s,t);)s=2*(e=X(e));return H(e,i)},u=function(e){const{uint16Array:t,uint32Array:i}=$;let s=2*e;for(;!k(s,t);)s=2*(e=Z(e,i));return H(e,i)+W(s,t)};const I=X(e),d=Z(e,l);let E,f,p,T,m=I,R=d;if(n&&(p=Q,T=q,C(m,a,p),C(R,a,T),E=n(p),f=n(T),f<E)){m=d,R=I;const e=E;E=f,f=e,p=T}p||(p=Q,C(m,a,p));const g=i(p,k(2*m,c),E,o+1,r+m);let A;if(2===g){const e=h(m);A=s(e,u(m)-e,!0,o+1,r+m,p)}else A=g&&te(m,t,i,s,n,r,o+1);if(A)return!0;T=q,C(R,a,T);const F=i(T,k(2*R,c),f,o+1,r+R);let S;if(2===F){const e=h(R);S=s(e,u(R)-e,!0,o+1,r+R,T)}else S=F&&te(R,t,i,s,n,r,o+1);return!!S}}const ie=new i.Vector3,se=new i.Vector3;const ne=new i.Vector3,re=new i.Vector3,oe=new i.Vector3,ae=new i.Vector2,ce=new i.Vector2,le=new i.Vector2,he=new i.Vector3,ue=new i.Vector3,Ie=new i.Vector3,de=new i.Vector3;function Ee(e,t,s,n,r,o,a,c,l){ne.fromBufferAttribute(t,o),re.fromBufferAttribute(t,a),oe.fromBufferAttribute(t,c);const h=function(e,t,s,n,r,o){let a;return a=o===i.BackSide?e.intersectTriangle(n,s,t,!0,r):e.intersectTriangle(t,s,n,o!==i.DoubleSide,r),null===a?null:{distance:e.origin.distanceTo(r),point:r.clone()}}(e,ne,re,oe,de,l);if(h){n&&(ae.fromBufferAttribute(n,o),ce.fromBufferAttribute(n,a),le.fromBufferAttribute(n,c),h.uv=i.Triangle.getInterpolation(de,ne,re,oe,ae,ce,le,new i.Vector2)),r&&(ae.fromBufferAttribute(r,o),ce.fromBufferAttribute(r,a),le.fromBufferAttribute(r,c),h.uv1=i.Triangle.getInterpolation(de,ne,re,oe,ae,ce,le,new i.Vector2)),s&&(he.fromBufferAttribute(s,o),ue.fromBufferAttribute(s,a),Ie.fromBufferAttribute(s,c),h.normal=i.Triangle.getInterpolation(de,ne,re,oe,he,ue,Ie,new i.Vector3),h.normal.dot(e.direction)>0&&h.normal.multiplyScalar(-1));const t={a:o,b:a,c:c,normal:new i.Vector3,materialIndex:0};i.Triangle.getNormal(ne,re,oe,t.normal),h.face=t,h.faceIndex=o}return h}function fe(e,t,i,s,n){const r=3*s;let o=r+0,a=r+1,c=r+2;const l=e.index;e.index&&(o=l.getX(o),a=l.getX(a),c=l.getX(c));const{position:h,normal:u,uv:I,uv1:d}=e.attributes,E=Ee(i,h,u,I,d,o,a,c,t);return E?(E.faceIndex=s,n&&n.push(E),E):null}function pe(e,t,i,s){const n=e.a,r=e.b,o=e.c;let a=t,c=t+1,l=t+2;i&&(a=i.getX(a),c=i.getX(c),l=i.getX(l)),n.x=s.getX(a),n.y=s.getY(a),n.z=s.getZ(a),r.x=s.getX(c),r.y=s.getY(c),r.z=s.getZ(c),o.x=s.getX(l),o.y=s.getY(l),o.z=s.getZ(l)}function Ce(e,t,i,s,n,r,o){const{geometry:a}=i,{index:c}=a,l=a.attributes.position;for(let i=e,a=t+e;i<a;i++){let e;if(e=i,pe(o,3*e,c,l),o.needsUpdate=!0,s(o,e,n,r))return!0}return!1}function Te(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));const i=e.geometry,s=i.index?i.index.array:null,n=i.attributes.position;let r,o,a,c,l=0;const u=e._roots;for(let e=0,t=u.length;e<t;e++)r=u[e],o=new Uint32Array(r),a=new Uint16Array(r),c=new Float32Array(r),I(0,l),l+=r.byteLength;function I(e,i,r=!1){const l=2*e;if(a[l+15]===h){const t=o[e+6];let i=1/0,r=1/0,h=1/0,u=-1/0,I=-1/0,d=-1/0;for(let e=3*t,o=3*(t+a[l+14]);e<o;e++){let t=s[e];const o=n.getX(t),a=n.getY(t),c=n.getZ(t);o<i&&(i=o),o>u&&(u=o),a<r&&(r=a),a>I&&(I=a),c<h&&(h=c),c>d&&(d=c)}return(c[e+0]!==i||c[e+1]!==r||c[e+2]!==h||c[e+3]!==u||c[e+4]!==I||c[e+5]!==d)&&(c[e+0]=i,c[e+1]=r,c[e+2]=h,c[e+3]=u,c[e+4]=I,c[e+5]=d,!0)}{const s=e+8,n=o[e+6],a=s+i,l=n+i;let h=r,u=!1,d=!1;t?h||(u=t.has(a),d=t.has(l),h=!u&&!d):(u=!0,d=!0);const E=h||d;let f=!1;(h||u)&&(f=I(s,i,h));let p=!1;E&&(p=I(n,i,h));const C=f||p;if(C)for(let t=0;t<3;t++){const i=s+t,r=n+t,o=c[i],a=c[i+3],l=c[r],h=c[r+3];c[e+t]=o<l?o:l,c[e+t+3]=a>h?a:h}return C}}}const me=new i.Box3;function Re(e,t,i,s){return C(e,t,me),i.intersectBox(me,s)}function ge(e,t,i,s,n,r,o){const{geometry:a}=i,{index:c}=a,l=a.attributes.position;for(let a=e,h=t+e;a<h;a++){let e;if(e=i.resolveTriangleIndex(a),pe(o,3*e,c,l),o.needsUpdate=!0,s(o,e,n,r))return!0}return!1}const Ae=new i.Vector3;function Fe(e,t,i,s,n){$.setBuffer(e._roots[t]),Se(0,e,i,s,n),$.clearBuffer()}function Se(e,t,i,s,n){const{float32Array:r,uint16Array:o,uint32Array:a}=$,c=2*e;if(k(c,o)){!function(e,t,i,s,n,r){const{geometry:o,_indirectBuffer:a}=e;for(let e=s,a=s+n;e<a;e++)fe(o,t,i,e,r)}(t,i,s,H(e,a),W(c,o),n)}else{const o=X(e);Re(o,r,s,Ae)&&Se(o,t,i,s,n);const c=Z(e,a);Re(c,r,s,Ae)&&Se(c,t,i,s,n)}}const Oe=new i.Vector3,Ne=["x","y","z"];function ye(e,t,i,s){$.setBuffer(e._roots[t]);const n=_e(0,e,i,s);return $.clearBuffer(),n}function _e(e,t,i,s){const{float32Array:n,uint16Array:r,uint32Array:o}=$;let a=2*e;if(k(a,r)){return function(e,t,i,s,n){const{geometry:r,_indirectBuffer:o}=e;let a=1/0,c=null;for(let e=s,o=s+n;e<o;e++){let s;s=fe(r,t,i,e),s&&s.distance<a&&(c=s,a=s.distance)}return c}(t,i,s,H(e,o),W(a,r))}{const r=j(e,o),a=Ne[r],c=s.direction[a]>=0;let l,h;c?(l=X(e),h=Z(e,o)):(l=Z(e,o),h=X(e));const u=Re(l,n,s,Oe)?_e(l,t,i,s):null;if(u){const e=u.point[a];if(c?e<=n[h+r]:e>=n[h+r+3])return u}const I=Re(h,n,s,Oe)?_e(h,t,i,s):null;return u&&I?u.distance<=I.distance?u:I:u||I||null}}const Le=new i.Box3,Pe=new B,we=new B,Me=new i.Matrix4,ve=new V,De=new V;function xe(e,t,i,s){$.setBuffer(e._roots[t]);const n=be(0,e,i,s);return $.clearBuffer(),n}function be(e,t,i,s,n=null){const{float32Array:r,uint16Array:o,uint32Array:a}=$;let c=2*e;null===n&&(i.boundingBox||i.computeBoundingBox(),ve.set(i.boundingBox.min,i.boundingBox.max,s),n=ve);if(!k(c,o)){const o=e+8,c=a[e+6];C(o,r,Le);if(n.intersectsBox(Le)&&be(o,t,i,s,n))return!0;C(c,r,Le);return!!(n.intersectsBox(Le)&&be(c,t,i,s,n))}{const n=t.geometry,l=n.index,h=n.attributes.position,u=i.index,I=i.attributes.position,d=H(e,a),E=W(c,o);if(Me.copy(s).invert(),i.boundsTree){C(e,r,De),De.matrix.copy(Me),De.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:e=>De.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(s),e.b.applyMatrix4(s),e.c.applyMatrix4(s),e.needsUpdate=!0;for(let t=3*d,i=3*(E+d);t<i;t+=3)if(pe(we,t,l,h),we.needsUpdate=!0,e.intersectsTriangle(we))return!0;return!1}})}for(let e=3*d,t=3*(E+d);e<t;e+=3){pe(Pe,e,l,h),Pe.a.applyMatrix4(Me),Pe.b.applyMatrix4(Me),Pe.c.applyMatrix4(Me),Pe.needsUpdate=!0;for(let e=0,t=u.count;e<t;e+=3)if(pe(we,e,u,I),we.needsUpdate=!0,Pe.intersectsTriangle(we))return!0}}}const Ue=new i.Matrix4,Be=new V,Ve=new V,Ye=new i.Vector3,Ge=new i.Vector3,ze=new i.Vector3,ke=new i.Vector3;function He(e,t,i,s={},n={},r=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Be.set(t.boundingBox.min,t.boundingBox.max,i),Be.needsUpdate=!0;const a=e.geometry,c=a.attributes.position,l=a.index,h=t.attributes.position,u=t.index,I=z.getPrimitive(),E=z.getPrimitive();let f=Ye,p=Ge,C=null,T=null;n&&(C=ze,T=ke);let m=1/0,R=null,g=null;return Ue.copy(i).invert(),Ve.matrix.copy(Ue),e.shapecast({boundsTraverseOrder:e=>Be.distanceToBox(e),intersectsBounds:(e,t,i)=>i<m&&i<o&&(t&&(Ve.min.copy(e.min),Ve.max.copy(e.max),Ve.needsUpdate=!0),!0),intersectsRange:(e,s)=>{if(t.boundsTree){return t.boundsTree.shapecast({boundsTraverseOrder:e=>Ve.distanceToBox(e),intersectsBounds:(e,t,i)=>i<m&&i<o,intersectsRange:(t,n)=>{for(let o=t,a=t+n;o<a;o++){pe(E,3*o,u,h),E.a.applyMatrix4(i),E.b.applyMatrix4(i),E.c.applyMatrix4(i),E.needsUpdate=!0;for(let t=e,i=e+s;t<i;t++){pe(I,3*t,l,c),I.needsUpdate=!0;const e=I.distanceToTriangle(E,f,C);if(e<m&&(p.copy(f),T&&T.copy(C),m=e,R=t,g=o),e<r)return!0}}}})}for(let n=0,o=d(t);n<o;n++){pe(E,3*n,u,h),E.a.applyMatrix4(i),E.b.applyMatrix4(i),E.c.applyMatrix4(i),E.needsUpdate=!0;for(let t=e,i=e+s;t<i;t++){pe(I,3*t,l,c),I.needsUpdate=!0;const e=I.distanceToTriangle(E,f,C);if(e<m&&(p.copy(f),T&&T.copy(C),m=e,R=t,g=n),e<r)return!0}}}}),z.releasePrimitive(I),z.releasePrimitive(E),m===1/0?null:(s.point?s.point.copy(p):s.point=p.clone(),s.distance=m,s.faceIndex=R,n&&(n.point?n.point.copy(T):n.point=T.clone(),n.point.applyMatrix4(Ue),p.applyMatrix4(Ue),n.distance=p.sub(n.point).length(),n.faceIndex=g),s)}function We(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));const i=e.geometry,s=i.index?i.index.array:null,n=i.attributes.position;let r,o,a,c,l=0;const u=e._roots;for(let e=0,t=u.length;e<t;e++)r=u[e],o=new Uint32Array(r),a=new Uint16Array(r),c=new Float32Array(r),I(0,l),l+=r.byteLength;function I(i,r,l=!1){const u=2*i;if(a[u+15]===h){const t=o[i+6];let r=1/0,l=1/0,h=1/0,I=-1/0,d=-1/0,E=-1/0;for(let i=t,o=t+a[u+14];i<o;i++){const t=3*e.resolveTriangleIndex(i);for(let e=0;e<3;e++){let i=t+e;i=s?s[i]:i;const o=n.getX(i),a=n.getY(i),c=n.getZ(i);o<r&&(r=o),o>I&&(I=o),a<l&&(l=a),a>d&&(d=a),c<h&&(h=c),c>E&&(E=c)}}return(c[i+0]!==r||c[i+1]!==l||c[i+2]!==h||c[i+3]!==I||c[i+4]!==d||c[i+5]!==E)&&(c[i+0]=r,c[i+1]=l,c[i+2]=h,c[i+3]=I,c[i+4]=d,c[i+5]=E,!0)}{const e=i+8,s=o[i+6],n=e+r,a=s+r;let h=l,u=!1,d=!1;t?h||(u=t.has(n),d=t.has(a),h=!u&&!d):(u=!0,d=!0);const E=h||d;let f=!1;(h||u)&&(f=I(e,r,h));let p=!1;E&&(p=I(s,r,h));const C=f||p;if(C)for(let t=0;t<3;t++){const n=e+t,r=s+t,o=c[n],a=c[n+3],l=c[r],h=c[r+3];c[i+t]=o<l?o:l,c[i+t+3]=a>h?a:h}return C}}}const Xe=new i.Vector3;function Ze(e,t,i,s,n){$.setBuffer(e._roots[t]),je(0,e,i,s,n),$.clearBuffer()}function je(e,t,i,s,n){const{float32Array:r,uint16Array:o,uint32Array:a}=$,c=2*e;if(k(c,o)){!function(e,t,i,s,n,r){const{geometry:o,_indirectBuffer:a}=e;for(let e=s,c=s+n;e<c;e++)fe(o,t,i,a?a[e]:e,r)}(t,i,s,H(e,a),W(c,o),n)}else{const o=X(e);Re(o,r,s,Xe)&&je(o,t,i,s,n);const c=Z(e,a);Re(c,r,s,Xe)&&je(c,t,i,s,n)}}const $e=new i.Vector3,Qe=["x","y","z"];function qe(e,t,i,s){$.setBuffer(e._roots[t]);const n=Ke(0,e,i,s);return $.clearBuffer(),n}function Ke(e,t,i,s){const{float32Array:n,uint16Array:r,uint32Array:o}=$;let a=2*e;if(k(a,r)){return function(e,t,i,s,n){const{geometry:r,_indirectBuffer:o}=e;let a=1/0,c=null;for(let e=s,l=s+n;e<l;e++){let s;s=fe(r,t,i,o?o[e]:e),s&&s.distance<a&&(c=s,a=s.distance)}return c}(t,i,s,H(e,o),W(a,r))}{const r=j(e,o),a=Qe[r],c=s.direction[a]>=0;let l,h;c?(l=X(e),h=Z(e,o)):(l=Z(e,o),h=X(e));const u=Re(l,n,s,$e)?Ke(l,t,i,s):null;if(u){const e=u.point[a];if(c?e<=n[h+r]:e>=n[h+r+3])return u}const I=Re(h,n,s,$e)?Ke(h,t,i,s):null;return u&&I?u.distance<=I.distance?u:I:u||I||null}}const Je=new i.Box3,et=new B,tt=new B,it=new i.Matrix4,st=new V,nt=new V;function rt(e,t,i,s){$.setBuffer(e._roots[t]);const n=ot(0,e,i,s);return $.clearBuffer(),n}function ot(e,t,i,s,n=null){const{float32Array:r,uint16Array:o,uint32Array:a}=$;let c=2*e;null===n&&(i.boundingBox||i.computeBoundingBox(),st.set(i.boundingBox.min,i.boundingBox.max,s),n=st);if(!k(c,o)){const o=e+8,c=a[e+6];C(o,r,Je);if(n.intersectsBox(Je)&&ot(o,t,i,s,n))return!0;C(c,r,Je);return!!(n.intersectsBox(Je)&&ot(c,t,i,s,n))}{const n=t.geometry,l=n.index,h=n.attributes.position,u=i.index,I=i.attributes.position,d=H(e,a),E=W(c,o);if(it.copy(s).invert(),i.boundsTree){C(e,r,nt),nt.matrix.copy(it),nt.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:e=>nt.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(s),e.b.applyMatrix4(s),e.c.applyMatrix4(s),e.needsUpdate=!0;for(let i=d,s=E+d;i<s;i++)if(pe(tt,3*t.resolveTriangleIndex(i),l,h),tt.needsUpdate=!0,e.intersectsTriangle(tt))return!0;return!1}})}for(let e=d,i=E+d;e<i;e++){const i=t.resolveTriangleIndex(e);pe(et,3*i,l,h),et.a.applyMatrix4(it),et.b.applyMatrix4(it),et.c.applyMatrix4(it),et.needsUpdate=!0;for(let e=0,t=u.count;e<t;e+=3)if(pe(tt,e,u,I),tt.needsUpdate=!0,et.intersectsTriangle(tt))return!0}}}const at=new i.Matrix4,ct=new V,lt=new V,ht=new i.Vector3,ut=new i.Vector3,It=new i.Vector3,dt=new i.Vector3;function Et(e,t,i,s={},n={},r=0,o=1/0){t.boundingBox||t.computeBoundingBox(),ct.set(t.boundingBox.min,t.boundingBox.max,i),ct.needsUpdate=!0;const a=e.geometry,c=a.attributes.position,l=a.index,h=t.attributes.position,u=t.index,I=z.getPrimitive(),E=z.getPrimitive();let f=ht,p=ut,C=null,T=null;n&&(C=It,T=dt);let m=1/0,R=null,g=null;return at.copy(i).invert(),lt.matrix.copy(at),e.shapecast({boundsTraverseOrder:e=>ct.distanceToBox(e),intersectsBounds:(e,t,i)=>i<m&&i<o&&(t&&(lt.min.copy(e.min),lt.max.copy(e.max),lt.needsUpdate=!0),!0),intersectsRange:(s,n)=>{if(t.boundsTree){const a=t.boundsTree;return a.shapecast({boundsTraverseOrder:e=>lt.distanceToBox(e),intersectsBounds:(e,t,i)=>i<m&&i<o,intersectsRange:(t,o)=>{for(let d=t,A=t+o;d<A;d++){const t=a.resolveTriangleIndex(d);pe(E,3*t,u,h),E.a.applyMatrix4(i),E.b.applyMatrix4(i),E.c.applyMatrix4(i),E.needsUpdate=!0;for(let t=s,i=s+n;t<i;t++){const i=e.resolveTriangleIndex(t);pe(I,3*i,l,c),I.needsUpdate=!0;const s=I.distanceToTriangle(E,f,C);if(s<m&&(p.copy(f),T&&T.copy(C),m=s,R=t,g=d),s<r)return!0}}}})}for(let o=0,a=d(t);o<a;o++){pe(E,3*o,u,h),E.a.applyMatrix4(i),E.b.applyMatrix4(i),E.c.applyMatrix4(i),E.needsUpdate=!0;for(let t=s,i=s+n;t<i;t++){const i=e.resolveTriangleIndex(t);pe(I,3*i,l,c),I.needsUpdate=!0;const s=I.distanceToTriangle(E,f,C);if(s<m&&(p.copy(f),T&&T.copy(C),m=s,R=t,g=o),s<r)return!0}}}}),z.releasePrimitive(I),z.releasePrimitive(E),m===1/0?null:(s.point?s.point.copy(p):s.point=p.clone(),s.distance=m,s.faceIndex=R,n&&(n.point?n.point.copy(T):n.point=T.clone(),n.point.applyMatrix4(at),p.applyMatrix4(at),n.distance=p.sub(n.point).length(),n.faceIndex=g),s)}const ft=new $.constructor,pt=new $.constructor,Ct=new Y((()=>new i.Box3)),Tt=new i.Box3,mt=new i.Box3,Rt=new i.Box3,gt=new i.Box3;let At=!1;function Ft(e,t,i,s,n,r=0,o=0,a=0,c=0,l=null,h=!1){let u,I;h?(u=pt,I=ft):(u=ft,I=pt);const d=u.float32Array,E=u.uint32Array,f=u.uint16Array,p=I.float32Array,T=I.uint32Array,m=I.uint16Array,R=2*t,g=k(2*e,f),A=k(R,m);let F=!1;if(A&&g)F=h?n(H(t,T),W(2*t,m),H(e,E),W(2*e,f),c,o+t,a,r+e):n(H(e,E),W(2*e,f),H(t,T),W(2*t,m),a,r+e,c,o+t);else if(A){const l=Ct.getPrimitive();C(t,p,l),l.applyMatrix4(i);const u=X(e),I=Z(e,E);C(u,d,Tt),C(I,d,mt);const f=l.intersectsBox(Tt),T=l.intersectsBox(mt);F=f&&Ft(t,u,s,i,n,o,r,c,a+1,l,!h)||T&&Ft(t,I,s,i,n,o,r,c,a+1,l,!h),Ct.releasePrimitive(l)}else{const u=X(t),I=Z(t,T);C(u,p,Rt),C(I,p,gt);const f=l.intersectsBox(Rt),m=l.intersectsBox(gt);if(f&&m)F=Ft(e,u,i,s,n,r,o,a,c+1,l,h)||Ft(e,I,i,s,n,r,o,a,c+1,l,h);else if(f)if(g)F=Ft(e,u,i,s,n,r,o,a,c+1,l,h);else{const t=Ct.getPrimitive();t.copy(Rt).applyMatrix4(i);const l=X(e),I=Z(e,E);C(l,d,Tt),C(I,d,mt);const f=t.intersectsBox(Tt),p=t.intersectsBox(mt);F=f&&Ft(u,l,s,i,n,o,r,c,a+1,t,!h)||p&&Ft(u,I,s,i,n,o,r,c,a+1,t,!h),Ct.releasePrimitive(t)}else if(m)if(g)F=Ft(e,I,i,s,n,r,o,a,c+1,l,h);else{const t=Ct.getPrimitive();t.copy(gt).applyMatrix4(i);const l=X(e),u=Z(e,E);C(l,d,Tt),C(u,d,mt);const f=t.intersectsBox(Tt),p=t.intersectsBox(mt);F=f&&Ft(I,l,s,i,n,o,r,c,a+1,t,!h)||p&&Ft(I,u,s,i,n,o,r,c,a+1,t,!h),Ct.releasePrimitive(t)}}return F}const St=new V,Ot=new i.Box3;class Nt{static serialize(e,t={}){t={cloneBuffers:!0,...t};const i=e.geometry,s=e._roots,n=e._indirectBuffer,r=i.getIndex();let o;return o=t.cloneBuffers?{roots:s.map((e=>e.slice())),index:r.array.slice(),indirectBuffer:n?n.slice():null}:{roots:s,index:r.array,indirectBuffer:n},o}static deserialize(e,t,s={}){s={setIndex:!0,indirect:Boolean(e.indirectBuffer),...s};const{index:n,roots:r,indirectBuffer:o}=e,a=new Nt(t,{...s,[I]:!0});if(a._roots=r,a._indirectBuffer=o||null,s.setIndex){const s=t.getIndex();if(null===s){const s=new i.BufferAttribute(e.index,1,!1);t.setIndex(s)}else s.array!==n&&(s.array.set(n),s.needsUpdate=!0)}return a}get indirect(){return!!this._indirectBuffer}constructor(e,t={}){if(!e.isBufferGeometry)throw new Error("MeshBVH: Only BufferGeometries are supported.");if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.");if((t=Object.assign({strategy:0,maxDepth:40,maxLeafTris:10,verbose:!0,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,[I]:!1},t)).useSharedArrayBuffer&&"undefined"==typeof SharedArrayBuffer)throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[I]||(M(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new i.Box3)));const{_indirectBuffer:s}=this;this.resolveTriangleIndex=t.indirect?e=>s[e]:e=>e}refit(e=null){return(this.indirect?We:Te)(this,e)}traverse(e,t=0){const i=this._roots[t],s=new Uint32Array(i),n=new Uint16Array(i);!function t(r,o=0){const a=2*r,c=n[a+15]===h;if(c){const t=s[r+6],l=n[a+14];e(o,c,new Float32Array(i,4*r,6),t,l)}else{const n=r+8,a=s[r+6],l=s[r+7];e(o,c,new Float32Array(i,4*r,6),l)||(t(n,o+1),t(a,o+1))}}(0)}raycast(e,t=i.FrontSide){const s=this._roots,n=this.geometry,r=[],o=t.isMaterial,a=Array.isArray(t),c=n.groups,l=o?t.side:t,h=this.indirect?Ze:Fe;for(let i=0,n=s.length;i<n;i++){const s=a?t[c[i].materialIndex].side:l,n=r.length;if(h(this,i,s,e,r),a){const e=c[i].materialIndex;for(let t=n,i=r.length;t<i;t++)r[t].face.materialIndex=e}}return r}raycastFirst(e,t=i.FrontSide){const s=this._roots,n=this.geometry,r=t.isMaterial,o=Array.isArray(t);let a=null;const c=n.groups,l=r?t.side:t,h=this.indirect?qe:ye;for(let i=0,n=s.length;i<n;i++){const s=h(this,i,o?t[c[i].materialIndex].side:l,e);null!=s&&(null==a||s.distance<a.distance)&&(a=s,o&&(s.face.materialIndex=c[i].materialIndex))}return a}intersectsGeometry(e,t){let i=!1;const s=this._roots,n=this.indirect?rt:xe;for(let r=0,o=s.length;r<o&&(i=n(this,r,e,t),!i);r++);return i}shapecast(e){const t=z.getPrimitive(),i=this.indirect?ge:Ce;let{boundsTraverseOrder:s,intersectsBounds:n,intersectsRange:r,intersectsTriangle:o}=e;if(r&&o){const e=r;r=(s,n,r,a,c)=>!!e(s,n,r,a,c)||i(s,n,this,o,r,a,t)}else r||(r=o?(e,s,n,r)=>i(e,s,this,o,n,r,t):(e,t,i)=>i);let a=!1,c=0;const l=this._roots;for(let e=0,t=l.length;e<t;e++){const t=l[e];if(a=ee(this,e,n,r,s,c),a)break;c+=t.byteLength}return z.releasePrimitive(t),a}bvhcast(e,t,s){let{intersectsRanges:n,intersectsTriangles:r}=s;const o=z.getPrimitive(),a=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?e=>{const t=this.resolveTriangleIndex(e);pe(o,3*t,a,c)}:e=>{pe(o,3*e,a,c)},h=z.getPrimitive(),u=e.geometry.index,I=e.geometry.attributes.position,d=e.indirect?t=>{const i=e.resolveTriangleIndex(t);pe(h,3*i,u,I)}:e=>{pe(h,3*e,u,I)};if(r){const e=(e,i,s,n,a,c,u,I)=>{for(let E=s,f=s+n;E<f;E++){d(E),h.a.applyMatrix4(t),h.b.applyMatrix4(t),h.c.applyMatrix4(t),h.needsUpdate=!0;for(let t=e,s=e+i;t<s;t++)if(l(t),o.needsUpdate=!0,r(o,h,t,E,a,c,u,I))return!0}return!1};if(n){const t=n;n=function(i,s,n,r,o,a,c,l){return!!t(i,s,n,r,o,a,c,l)||e(i,s,n,r,o,a,c,l)}}else n=e}return function(e,t,s,n){if(At)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");At=!0;const r=e._roots,o=t._roots;let a,c=0,l=0;const h=(new i.Matrix4).copy(s).invert();for(let e=0,t=r.length;e<t;e++){ft.setBuffer(r[e]),l=0;const t=Ct.getPrimitive();C(0,ft.float32Array,t),t.applyMatrix4(h);for(let i=0,r=o.length;i<r&&(pt.setBuffer(o[e]),a=Ft(0,0,s,h,n,c,l,0,0,t),pt.clearBuffer(),l+=o[i].length,!a);i++);if(Ct.releasePrimitive(t),ft.clearBuffer(),c+=r[e].length,a)break}return At=!1,a}(this,e,t,n)}intersectsBox(e,t){return St.set(e.min,e.max,t),St.needsUpdate=!0,this.shapecast({intersectsBounds:e=>St.intersectsBox(e),intersectsTriangle:e=>St.intersectsTriangle(e)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,i={},s={},n=0,r=1/0){return(this.indirect?Et:He)(this,e,t,i,s,n,r)}closestPointToPoint(e,t={},i=0,s=1/0){return function(e,t,i={},s=0,n=1/0){const r=s*s,o=n*n;let a=1/0,c=null;if(e.shapecast({boundsTraverseOrder:e=>(ie.copy(t).clamp(e.min,e.max),ie.distanceToSquared(t)),intersectsBounds:(e,t,i)=>i<a&&i<o,intersectsTriangle:(e,i)=>{e.closestPointToPoint(t,ie);const s=t.distanceToSquared(ie);return s<a&&(se.copy(ie),a=s,c=i),s<r}}),a===1/0)return null;const l=Math.sqrt(a);return i.point?i.point.copy(se):i.point=se.clone(),i.distance=l,i.faceIndex=c,i}(this,e,t,i,s)}getBoundingBox(e){e.makeEmpty();return this._roots.forEach((t=>{C(0,new Float32Array(t),Ot),e.union(Ot)})),e}}function yt(e,t,i){return null===e?null:(e.point.applyMatrix4(t.matrixWorld),e.distance=e.point.distanceTo(i.ray.origin),e.object=t,e.distance<i.near||e.distance>i.far?null:e)}const _t=new i.Ray,Lt=new i.Matrix4,Pt=i.Mesh.prototype.raycast;function wt(e,t){if(this.geometry.boundsTree){if(void 0===this.material)return;Lt.copy(this.matrixWorld).invert(),_t.copy(e.ray).applyMatrix4(Lt);const i=this.geometry.boundsTree;if(!0===e.firstHitOnly){const s=yt(i.raycastFirst(_t,this.material),this,e);s&&t.push(s)}else{const s=i.raycast(_t,this.material);for(let i=0,n=s.length;i<n;i++){const n=yt(s[i],this,e);n&&t.push(n)}}}else Pt.call(this,e,t)}function Mt(e){return this.boundsTree=new Nt(this,e),this.boundsTree}function vt(){this.boundsTree=null}class Dt{constructor(){t(this,"enabled",!0),t(this,"trigger",(e=>{if(!this.enabled)return;const t=this.handlers.slice(0);for(const i of t)i(e)})),t(this,"handlers",[])}add(e){this.handlers.push(e)}remove(e){this.handlers=this.handlers.filter((t=>t!==e))}reset(){this.handlers.length=0}}class xt{constructor(){t(this,"enabled",!0),t(this,"trigger",(async e=>{if(!this.enabled)return;const t=this.handlers.slice(0);for(const i of t)await i(e)})),t(this,"handlers",[])}add(e){this.handlers.push(e)}remove(e){this.handlers=this.handlers.filter((t=>t!==e))}reset(){this.handlers.length=0}}class bt{constructor(e){t(this,"isDisposeable",(()=>"dispose"in this&&"onDisposed"in this)),t(this,"isResizeable",(()=>"resize"in this&&"getSize"in this)),t(this,"isUpdateable",(()=>"onAfterUpdate"in this&&"onBeforeUpdate"in this&&"update"in this)),t(this,"isHideable",(()=>"visible"in this)),t(this,"isConfigurable",(()=>"setup"in this&&"config"in this&&"onSetup"in this)),this.components=e}}class Ut extends bt{}class Bt extends bt{constructor(e){super(e),t(this,"worlds",new Map),t(this,"onWorldChanged",new Dt),t(this,"currentWorld",null),this.onWorldChanged.add((({world:e,action:t})=>{"removed"===t&&this.worlds.delete(e.uuid)}))}}class Vt extends Bt{constructor(){super(...arguments),t(this,"hasCameraControls",(()=>"controls"in this))}}class Yt extends Bt{constructor(){super(...arguments),t(this,"onAfterUpdate",new Dt),t(this,"onBeforeUpdate",new Dt),t(this,"onDisposed",new Dt),t(this,"onResize",new Dt),t(this,"onClippingPlanesUpdated",new Dt),t(this,"clippingPlanes",[])}updateClippingPlanes(){this.onClippingPlanesUpdated.trigger()}setPlane(e,t,i){t.isLocal=i;const s=this.clippingPlanes.indexOf(t);e&&-1===s?this.clippingPlanes.push(t):!e&&s>-1&&this.clippingPlanes.splice(s,1),this.three.clippingPlanes=this.clippingPlanes.filter((e=>!e.isLocal))}}const Gt=class e extends Ut{constructor(i){super(i),t(this,"_disposedComponents",new Set),t(this,"enabled",!0),i.add(e.uuid,this)}get(){return this._disposedComponents}destroy(e,t=!0,i=!0){e.removeFromParent();const s=e;s.dispose&&s.dispose(),this.disposeGeometryAndMaterials(e,t),i&&s.children&&s.children.length&&this.disposeChildren(s),e.children.length=0}disposeGeometry(e){e.boundsTree&&e.disposeBoundsTree&&e.disposeBoundsTree(),e.dispose()}disposeGeometryAndMaterials(t,i){const s=t;s.geometry&&this.disposeGeometry(s.geometry),i&&s.material&&e.disposeMaterial(s),s.material=[],s.geometry=null}disposeChildren(e){for(const t of e.children)this.destroy(t)}static disposeMaterial(e){if(e.material)if(Array.isArray(e.material))for(const t of e.material)t.dispose();else e.material.dispose()}};t(Gt,"uuid","76e9cd8e-ad8f-4753-9ef6-cbc60f7247fe");let zt=Gt;class kt extends Bt{constructor(e){super(e),t(this,"onDisposed",new Dt),t(this,"directionalLights",new Map),t(this,"ambientLights",new Map)}dispose(){const e=this.components.get(zt);for(const t of this.three.children){const i=t;i.geometry&&e.destroy(i)}this.deleteAllLights(),this.three.children=[],this.onDisposed.trigger(),this.onDisposed.reset()}deleteAllLights(){for(const[,e]of this.directionalLights)e.removeFromParent(),e.target.removeFromParent(),e.dispose();this.directionalLights.clear();for(const[,e]of this.ambientLights)e.removeFromParent(),e.dispose();this.ambientLights.clear()}}class Ht extends Set{constructor(e){super(e),t(this,"onItemAdded",new Dt),t(this,"onItemDeleted",new Dt),t(this,"onCleared",new Dt),t(this,"guard",(()=>!0))}clear(){super.clear(),this.onCleared.trigger()}add(...e){for(const t of e){if(this.has(t))continue;this.guard(t)&&(super.add(t),this.onItemAdded||(this.onItemAdded=new Dt),this.onItemAdded.trigger(t))}return this}delete(e){const t=super.delete(e);return t&&this.onItemDeleted.trigger(),t}dispose(){this.clear(),this.onItemAdded.reset(),this.onItemDeleted.reset(),this.onCleared.reset()}}class Wt extends Map{constructor(e){super(e),t(this,"onItemSet",new Dt),t(this,"onItemUpdated",new Dt),t(this,"onItemDeleted",new Dt),t(this,"onCleared",new Dt),t(this,"guard",(()=>!0))}clear(){super.clear(),this.onCleared.trigger()}set(e,t){const i=this.has(e);if(!(this.guard??(()=>!0))(e,t))return this;const s=super.set(e,t);return i?(this.onItemUpdated||(this.onItemUpdated=new Dt),this.onItemUpdated.trigger({key:e,value:t})):(this.onItemSet||(this.onItemSet=new Dt),this.onItemSet.trigger({key:e,value:t})),s}delete(e){const t=super.delete(e);return t&&this.onItemDeleted.trigger(e),t}dispose(){this.clear(),this.onItemSet.reset(),this.onItemDeleted.reset(),this.onCleared.reset()}}class Xt{static isEntry(e){return new Set(["Boolean","Color","Text","Number","Select","Vector3","TextSet","None"]).has(e.type)}static copySchema(e,t={}){for(const i in e){const s=e[i];this.isEntry(s)?t[i]=this.copyEntry(s):(t[i]={},this.copySchema(s,t[i]))}return t}static copyEntry(e){if("Boolean"===e.type){const t=e;return{type:t.type,value:t.value}}if("Color"===e.type){const t=e;return{type:t.type,value:t.value.clone()}}if("Text"===e.type){const t=e;return{type:t.type,value:t.value}}if("Number"===e.type){const t=e;return{type:t.type,value:t.value,min:t.min,max:t.max,interpolable:t.interpolable}}if("Select"===e.type){const t=e;return{type:t.type,value:t.value,multiple:t.multiple,options:new Set(t.options)}}if("Vector3"===e.type){const t=e;return{type:t.type,value:t.value.clone()}}if("TextSet"===e.type){const t=e;return{type:t.type,value:new Set(t.value)}}if("None"===e.type){const t=e;return{type:t.type,value:t.value}}throw new Error("Invalid entry!")}}const Zt=new i.Vector3,jt=new i.Line3,$t=new i.Plane,Qt=new i.Vector3,qt=new i.Triangle;class Kt{constructor(){this.tolerance=-1,this.faces=[],this.newFaces=[],this.assigned=new ii,this.unassigned=new ii,this.vertices=[]}setFromPoints(e){if(e.length>=4){this.makeEmpty();for(let t=0,i=e.length;t<i;t++)this.vertices.push(new ti(e[t]));this.compute()}return this}setFromObject(e){const t=[];return e.updateMatrixWorld(!0),e.traverse((function(e){const s=e.geometry;if(void 0!==s){const n=s.attributes.position;if(void 0!==n)for(let s=0,r=n.count;s<r;s++){const r=new i.Vector3;r.fromBufferAttribute(n,s).applyMatrix4(e.matrixWorld),t.push(r)}}})),this.setFromPoints(t)}containsPoint(e){const t=this.faces;for(let i=0,s=t.length;i<s;i++){if(t[i].distanceToPoint(e)>this.tolerance)return!1}return!0}intersectRay(e,t){const i=this.faces;let s=-1/0,n=1/0;for(let t=0,r=i.length;t<r;t++){const r=i[t],o=r.distanceToPoint(e.origin),a=r.normal.dot(e.direction);if(o>0&&a>=0)return null;const c=0!==a?-o/a:0;if(!(c<=0)&&(a>0?n=Math.min(c,n):s=Math.max(c,s),s>n))return null}return s!==-1/0?e.at(s,t):e.at(n,t),t}intersectsRay(e){return null!==this.intersectRay(e,Zt)}makeEmpty(){return this.faces=[],this.vertices=[],this}addVertexToFace(e,t){return e.face=t,null===t.outside?this.assigned.append(e):this.assigned.insertBefore(t.outside,e),t.outside=e,this}removeVertexFromFace(e,t){return e===t.outside&&(null!==e.next&&e.next.face===t?t.outside=e.next:t.outside=null),this.assigned.remove(e),this}removeAllVerticesFromFace(e){if(null!==e.outside){const t=e.outside;let i=e.outside;for(;null!==i.next&&i.next.face===e;)i=i.next;return this.assigned.removeSubList(t,i),t.prev=i.next=null,e.outside=null,t}}deleteFaceVertices(e,t){const i=this.removeAllVerticesFromFace(e);if(void 0!==i)if(void 0===t)this.unassigned.appendChain(i);else{let e=i;do{const i=e.next;t.distanceToPoint(e.point)>this.tolerance?this.addVertexToFace(e,t):this.unassigned.append(e),e=i}while(null!==e)}return this}resolveUnassignedPoints(e){if(!1===this.unassigned.isEmpty()){let t=this.unassigned.first();do{const i=t.next;let s=this.tolerance,n=null;for(let i=0;i<e.length;i++){const r=e[i];if(0===r.mark){const e=r.distanceToPoint(t.point);if(e>s&&(s=e,n=r),s>1e3*this.tolerance)break}}null!==n&&this.addVertexToFace(t,n),t=i}while(null!==t)}return this}computeExtremes(){const e=new i.Vector3,t=new i.Vector3,s=[],n=[];for(let e=0;e<3;e++)s[e]=n[e]=this.vertices[0];e.copy(this.vertices[0].point),t.copy(this.vertices[0].point);for(let i=0,r=this.vertices.length;i<r;i++){const r=this.vertices[i],o=r.point;for(let t=0;t<3;t++)o.getComponent(t)<e.getComponent(t)&&(e.setComponent(t,o.getComponent(t)),s[t]=r);for(let e=0;e<3;e++)o.getComponent(e)>t.getComponent(e)&&(t.setComponent(e,o.getComponent(e)),n[e]=r)}return this.tolerance=3*Number.EPSILON*(Math.max(Math.abs(e.x),Math.abs(t.x))+Math.max(Math.abs(e.y),Math.abs(t.y))+Math.max(Math.abs(e.z),Math.abs(t.z))),{min:s,max:n}}computeInitialHull(){const e=this.vertices,t=this.computeExtremes(),i=t.min,s=t.max;let n=0,r=0;for(let e=0;e<3;e++){const t=s[e].point.getComponent(e)-i[e].point.getComponent(e);t>n&&(n=t,r=e)}const o=i[r],a=s[r];let c,l;n=0,jt.set(o.point,a.point);for(let t=0,i=this.vertices.length;t<i;t++){const i=e[t];if(i!==o&&i!==a){jt.closestPointToPoint(i.point,!0,Qt);const e=Qt.distanceToSquared(i.point);e>n&&(n=e,c=i)}}n=-1,$t.setFromCoplanarPoints(o.point,a.point,c.point);for(let t=0,i=this.vertices.length;t<i;t++){const i=e[t];if(i!==o&&i!==a&&i!==c){const e=Math.abs($t.distanceToPoint(i.point));e>n&&(n=e,l=i)}}const h=[];if($t.distanceToPoint(l.point)<0){h.push(Jt.create(o,a,c),Jt.create(l,a,o),Jt.create(l,c,a),Jt.create(l,o,c));for(let e=0;e<3;e++){const t=(e+1)%3;h[e+1].getEdge(2).setTwin(h[0].getEdge(t)),h[e+1].getEdge(1).setTwin(h[t+1].getEdge(0))}}else{h.push(Jt.create(o,c,a),Jt.create(l,o,a),Jt.create(l,a,c),Jt.create(l,c,o));for(let e=0;e<3;e++){const t=(e+1)%3;h[e+1].getEdge(2).setTwin(h[0].getEdge((3-e)%3)),h[e+1].getEdge(0).setTwin(h[t+1].getEdge(1))}}for(let e=0;e<4;e++)this.faces.push(h[e]);for(let t=0,i=e.length;t<i;t++){const i=e[t];if(i!==o&&i!==a&&i!==c&&i!==l){n=this.tolerance;let e=null;for(let t=0;t<4;t++){const s=this.faces[t].distanceToPoint(i.point);s>n&&(n=s,e=this.faces[t])}null!==e&&this.addVertexToFace(i,e)}}return this}reindexFaces(){const e=[];for(let t=0;t<this.faces.length;t++){const i=this.faces[t];0===i.mark&&e.push(i)}return this.faces=e,this}nextVertexToAdd(){if(!1===this.assigned.isEmpty()){let e,t=0;const i=this.assigned.first().face;let s=i.outside;do{const n=i.distanceToPoint(s.point);n>t&&(t=n,e=s),s=s.next}while(null!==s&&s.face===i);return e}}computeHorizon(e,t,i,s){let n;this.deleteFaceVertices(i),i.mark=1,n=null===t?t=i.getEdge(0):t.next;do{const t=n.twin,i=t.face;0===i.mark&&(i.distanceToPoint(e)>this.tolerance?this.computeHorizon(e,t,i,s):s.push(n)),n=n.next}while(n!==t);return this}addAdjoiningFace(e,t){const i=Jt.create(e,t.tail(),t.head());return this.faces.push(i),i.getEdge(-1).setTwin(t.twin),i.getEdge(0)}addNewFaces(e,t){this.newFaces=[];let i=null,s=null;for(let n=0;n<t.length;n++){const r=t[n],o=this.addAdjoiningFace(e,r);null===i?i=o:o.next.setTwin(s),this.newFaces.push(o.face),s=o}return i.next.setTwin(s),this}addVertexToHull(e){const t=[];return this.unassigned.clear(),this.removeVertexFromFace(e,e.face),this.computeHorizon(e.point,null,e.face,t),this.addNewFaces(e,t),this.resolveUnassignedPoints(this.newFaces),this}cleanup(){return this.assigned.clear(),this.unassigned.clear(),this.newFaces=[],this}compute(){let e;for(this.computeInitialHull();void 0!==(e=this.nextVertexToAdd());)this.addVertexToHull(e);return this.reindexFaces(),this.cleanup(),this}}class Jt{constructor(){this.normal=new i.Vector3,this.midpoint=new i.Vector3,this.area=0,this.constant=0,this.outside=null,this.mark=0,this.edge=null}static create(e,t,i){const s=new Jt,n=new ei(e,s),r=new ei(t,s),o=new ei(i,s);return n.next=o.prev=r,r.next=n.prev=o,o.next=r.prev=n,s.edge=n,s.compute()}getEdge(e){let t=this.edge;for(;e>0;)t=t.next,e--;for(;e<0;)t=t.prev,e++;return t}compute(){const e=this.edge.tail(),t=this.edge.head(),i=this.edge.next.head();return qt.set(e.point,t.point,i.point),qt.getNormal(this.normal),qt.getMidpoint(this.midpoint),this.area=qt.getArea(),this.constant=this.normal.dot(this.midpoint),this}distanceToPoint(e){return this.normal.dot(e)-this.constant}}class ei{constructor(e,t){this.vertex=e,this.prev=null,this.next=null,this.twin=null,this.face=t}head(){return this.vertex}tail(){return this.prev?this.prev.vertex:null}length(){const e=this.head(),t=this.tail();return null!==t?t.point.distanceTo(e.point):-1}lengthSquared(){const e=this.head(),t=this.tail();return null!==t?t.point.distanceToSquared(e.point):-1}setTwin(e){return this.twin=e,e.twin=this,this}}class ti{constructor(e){this.point=e,this.prev=null,this.next=null,this.face=null}}class ii{constructor(){this.head=null,this.tail=null}first(){return this.head}last(){return this.tail}clear(){return this.head=this.tail=null,this}insertBefore(e,t){return t.prev=e.prev,t.next=e,null===t.prev?this.head=t:t.prev.next=t,e.prev=t,this}insertAfter(e,t){return t.prev=e,t.next=e.next,null===t.next?this.tail=t:t.next.prev=t,e.next=t,this}append(e){return null===this.head?this.head=e:this.tail.next=e,e.prev=this.tail,e.next=null,this.tail=e,this}appendChain(e){for(null===this.head?this.head=e:this.tail.next=e,e.prev=this.tail;null!==e.next;)e=e.next;return this.tail=e,this}remove(e){return null===e.prev?this.head=e.next:e.prev.next=e.next,null===e.next?this.tail=e.prev:e.next.prev=e.prev,this}removeSubList(e,t){return null===e.prev?this.head=t.next:e.prev.next=t.next,null===t.next?this.tail=e.prev:t.next.prev=e.prev,this}isEmpty(){return null===this.head}}const si=[2,2,1],ni=[1,0,0];function ri(e,t){return 3*e+t}function oi(e){const t=e.elements;let i=0;for(let e=0;e<3;e++){const s=t[ri(si[e],ni[e])];i+=2*s*s}return Math.sqrt(i)}function ai(e,t){let i=0,s=1;const n=e.elements;for(let e=0;e<3;e++){const t=Math.abs(n[ri(si[e],ni[e])]);t>i&&(i=t,s=e)}let r=1,o=0;const a=ni[s],c=si[s];if(Math.abs(n[ri(c,a)])>Number.EPSILON){const e=(n[ri(c,c)]-n[ri(a,a)])/2/n[ri(c,a)];let t;t=e<0?-1/(-e+Math.sqrt(1+e*e)):1/(e+Math.sqrt(1+e*e)),r=1/Math.sqrt(1+t*t),o=t*r}return t.identity(),t.elements[ri(a,a)]=r,t.elements[ri(c,c)]=r,t.elements[ri(c,a)]=o,t.elements[ri(a,c)]=-o,t}function ci(e,t){let i=0,s=0;t.unitary.identity(),t.diagonal.copy(e);const n=t.unitary,r=t.diagonal,a=new o.Matrix3,c=new o.Matrix3,l=Number.EPSILON*function(e){const t=e.elements;let i=0;for(let e=0;e<9;e++)i+=t[e]*t[e];return Math.sqrt(i)}(r);for(;s<10&&oi(r)>l;)ai(r,a),c.copy(a).transpose(),r.multiply(a),r.premultiply(c),n.multiply(a),++i>2&&(s++,i=0);return t}function li(e){const t=[];for(let i=0;i<e.length-2;i+=3){const s=e[i],n=e[i+1],r=e[i+2];t.push(new o.Vector3(s,n,r))}const i=new Kt;i.setFromPoints(t);const s={unitary:new o.Matrix3,diagonal:new o.Matrix3},n=i.faces,r=[],a=[];for(let e=0,t=n.length;e<t;e++){const t=n[e];let i=t.edge;r.length=0;do{r.push(i),i=i.next}while(i!==t.edge);for(let e=1,t=r.length-2;e<=t;e++){const t=r[0].vertex,i=r[e+0].vertex,s=r[e+1].vertex;a.push(t.point.x,t.point.y,t.point.z),a.push(i.point.x,i.point.y,i.point.z),a.push(s.point.x,s.point.y,s.point.z)}}const c=new o.Vector3,l=new o.Vector3,h=new o.Vector3,u=new o.Vector3,I=new o.Vector3,d=new o.Vector3,E=new o.Vector3,f=new o.Vector3;let p=0,C=0,T=0,m=0,R=0,g=0,A=0;for(let e=0,t=a.length;e<t;e+=9){c.fromArray(a,e),l.fromArray(a,e+3),h.fromArray(a,e+6),E.set(0,0,0),E.add(c).add(l).add(h).divideScalar(3),u.subVectors(l,c),I.subVectors(h,c);const t=d.crossVectors(u,I).length()/2;f.add(d.copy(E).multiplyScalar(t)),p+=t,C+=(9*E.x*E.x+c.x*c.x+l.x*l.x+h.x*h.x)*(t/12),T+=(9*E.x*E.y+c.x*c.y+l.x*l.y+h.x*h.y)*(t/12),m+=(9*E.x*E.z+c.x*c.z+l.x*l.z+h.x*h.z)*(t/12),R+=(9*E.y*E.y+c.y*c.y+l.y*l.y+h.y*h.y)*(t/12),g+=(9*E.y*E.z+c.y*c.z+l.y*l.z+h.y*h.z)*(t/12),A+=(9*E.z*E.z+c.z*c.z+l.z*l.z+h.z*h.z)*(t/12)}f.divideScalar(p),C/=p,T/=p,m/=p,R/=p,g/=p,A/=p,C-=f.x*f.x,T-=f.x*f.y,m-=f.x*f.z,R-=f.y*f.y,g-=f.y*f.z,A-=f.z*f.z;const F=new o.Matrix3;F.elements[0]=C,F.elements[1]=T,F.elements[2]=m,F.elements[3]=T,F.elements[4]=R,F.elements[5]=g,F.elements[6]=m,F.elements[7]=g,F.elements[8]=A,ci(F,s);const S=s.unitary,O=new o.Vector3,N=new o.Vector3,y=new o.Vector3;S.extractBasis(O,N,y);let _=-1/0,L=-1/0,P=-1/0,w=1/0,M=1/0,v=1/0;for(let e=0,i=t.length;e<i;e++){const i=t[e];_=Math.max(O.dot(i),_),L=Math.max(N.dot(i),L),P=Math.max(y.dot(i),P),w=Math.min(O.dot(i),w),M=Math.min(N.dot(i),M),v=Math.min(y.dot(i),v)}O.multiplyScalar(.5*(w+_)),N.multiplyScalar(.5*(M+L)),y.multiplyScalar(.5*(v+P));const D=new o.Vector3,x=new o.Vector3,b=new o.Matrix3;D.add(O).add(N).add(y),x.x=_-w,x.y=L-M,x.z=P-v,x.multiplyScalar(.5),b.copy(S);const{x:U,y:B,z:V}=x,Y=new o.Matrix4;Y.makeScale(2*U,2*B,2*V);const G=new o.Matrix4;G.makeTranslation(-U,-B,-V);const z=new o.Matrix4;z.makeTranslation(D.x,D.y,D.z);const k=new o.Matrix4;k.setFromMatrix3(b);const H=new o.Matrix4;return H.multiply(z),H.multiply(k),H.multiply(G),H.multiply(Y),{center:D,halfSizes:x,rotation:b,transformation:H}}class hi{static isTransparent(e){return e.transparent&&e.opacity<1}}const ui=class e{static create(){const t=4294967295*Math.random()|0,i=4294967295*Math.random()|0,s=4294967295*Math.random()|0,n=4294967295*Math.random()|0;return`${e._lut[255&t]+e._lut[t>>8&255]+e._lut[t>>16&255]+e._lut[t>>24&255]}-${e._lut[255&i]}${e._lut[i>>8&255]}-${e._lut[i>>16&15|64]}${e._lut[i>>24&255]}-${e._lut[63&s|128]}${e._lut[s>>8&255]}-${e._lut[s>>16&255]}${e._lut[s>>24&255]}${e._lut[255&n]}${e._lut[n>>8&255]}${e._lut[n>>16&255]}${e._lut[n>>24&255]}`.toLowerCase()}static validate(t){if(!e._pattern.test(t))throw new Error(`${t} is not a valid UUID v4.\n\n- If you're the tool creator, you can take one from https://www.uuidgenerator.net/.\n\n- If you're using a platform tool, verify the uuid isn't misspelled or contact the tool creator.`)}};t(ui,"_pattern",/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/),t(ui,"_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 Ii=ui;var di="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Ei(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var fi={exports:{}};function pi(e,t,i){i=i||2;var s,n,r,o,a,c,l,h=t&&t.length,u=h?t[0]*i:e.length,I=Ci(e,0,u,i,!0),d=[];if(!I||I.next===I.prev)return d;if(h&&(I=function(e,t,i,s){var n,r,o,a=[];for(n=0,r=t.length;n<r;n++)(o=Ci(e,t[n]*s,n<r-1?t[n+1]*s:e.length,s,!1))===o.next&&(o.steiner=!0),a.push(_i(o));for(a.sort(Si),n=0;n<a.length;n++)i=Oi(a[n],i);return i}(e,t,I,i)),e.length>80*i){s=r=e[0],n=o=e[1];for(var E=i;E<u;E+=i)(a=e[E])<s&&(s=a),(c=e[E+1])<n&&(n=c),a>r&&(r=a),c>o&&(o=c);l=0!==(l=Math.max(r-s,o-n))?32767/l:0}return mi(I,d,i,s,n,l,0),d}function Ci(e,t,i,s,n){var r,o;if(n===Gi(e,t,i,s)>0)for(r=t;r<i;r+=s)o=Bi(r,e[r],e[r+1],o);else for(r=i-s;r>=t;r-=s)o=Bi(r,e[r],e[r+1],o);return o&&Mi(o,o.next)&&(Vi(o),o=o.next),o}function Ti(e,t){if(!e)return e;t||(t=e);var i,s=e;do{if(i=!1,s.steiner||!Mi(s,s.next)&&0!==wi(s.prev,s,s.next))s=s.next;else{if(Vi(s),(s=t=s.prev)===s.next)break;i=!0}}while(i||s!==t);return t}function mi(e,t,i,s,n,r,o){if(e){!o&&r&&function(e,t,i,s){var n=e;do{0===n.z&&(n.z=yi(n.x,n.y,t,i,s)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next}while(n!==e);n.prevZ.nextZ=null,n.prevZ=null,function(e){var t,i,s,n,r,o,a,c,l=1;do{for(i=e,e=null,r=null,o=0;i;){for(o++,s=i,a=0,t=0;t<l&&(a++,s=s.nextZ);t++);for(c=l;a>0||c>0&&s;)0!==a&&(0===c||!s||i.z<=s.z)?(n=i,i=i.nextZ,a--):(n=s,s=s.nextZ,c--),r?r.nextZ=n:e=n,n.prevZ=r,r=n;i=s}r.nextZ=null,l*=2}while(o>1)}(n)}(e,s,n,r);for(var a,c,l=e;e.prev!==e.next;)if(a=e.prev,c=e.next,r?gi(e,s,n,r):Ri(e))t.push(a.i/i|0),t.push(e.i/i|0),t.push(c.i/i|0),Vi(e),e=c.next,l=c.next;else if((e=c)===l){o?1===o?mi(e=Ai(Ti(e),t,i),t,i,s,n,r,2):2===o&&Fi(e,t,i,s,n,r):mi(Ti(e),t,i,s,n,r,1);break}}}function Ri(e){var t=e.prev,i=e,s=e.next;if(wi(t,i,s)>=0)return!1;for(var n=t.x,r=i.x,o=s.x,a=t.y,c=i.y,l=s.y,h=n<r?n<o?n:o:r<o?r:o,u=a<c?a<l?a:l:c<l?c:l,I=n>r?n>o?n:o:r>o?r:o,d=a>c?a>l?a:l:c>l?c:l,E=s.next;E!==t;){if(E.x>=h&&E.x<=I&&E.y>=u&&E.y<=d&&Li(n,a,r,c,o,l,E.x,E.y)&&wi(E.prev,E,E.next)>=0)return!1;E=E.next}return!0}function gi(e,t,i,s){var n=e.prev,r=e,o=e.next;if(wi(n,r,o)>=0)return!1;for(var a=n.x,c=r.x,l=o.x,h=n.y,u=r.y,I=o.y,d=a<c?a<l?a:l:c<l?c:l,E=h<u?h<I?h:I:u<I?u:I,f=a>c?a>l?a:l:c>l?c:l,p=h>u?h>I?h:I:u>I?u:I,C=yi(d,E,t,i,s),T=yi(f,p,t,i,s),m=e.prevZ,R=e.nextZ;m&&m.z>=C&&R&&R.z<=T;){if(m.x>=d&&m.x<=f&&m.y>=E&&m.y<=p&&m!==n&&m!==o&&Li(a,h,c,u,l,I,m.x,m.y)&&wi(m.prev,m,m.next)>=0)return!1;if(m=m.prevZ,R.x>=d&&R.x<=f&&R.y>=E&&R.y<=p&&R!==n&&R!==o&&Li(a,h,c,u,l,I,R.x,R.y)&&wi(R.prev,R,R.next)>=0)return!1;R=R.nextZ}for(;m&&m.z>=C;){if(m.x>=d&&m.x<=f&&m.y>=E&&m.y<=p&&m!==n&&m!==o&&Li(a,h,c,u,l,I,m.x,m.y)&&wi(m.prev,m,m.next)>=0)return!1;m=m.prevZ}for(;R&&R.z<=T;){if(R.x>=d&&R.x<=f&&R.y>=E&&R.y<=p&&R!==n&&R!==o&&Li(a,h,c,u,l,I,R.x,R.y)&&wi(R.prev,R,R.next)>=0)return!1;R=R.nextZ}return!0}function Ai(e,t,i){var s=e;do{var n=s.prev,r=s.next.next;!Mi(n,r)&&vi(n,s,s.next,r)&&bi(n,r)&&bi(r,n)&&(t.push(n.i/i|0),t.push(s.i/i|0),t.push(r.i/i|0),Vi(s),Vi(s.next),s=e=r),s=s.next}while(s!==e);return Ti(s)}function Fi(e,t,i,s,n,r){var o=e;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&Pi(o,a)){var c=Ui(o,a);return o=Ti(o,o.next),c=Ti(c,c.next),mi(o,t,i,s,n,r,0),void mi(c,t,i,s,n,r,0)}a=a.next}o=o.next}while(o!==e)}function Si(e,t){return e.x-t.x}function Oi(e,t){var i=function(e,t){var i,s=t,n=e.x,r=e.y,o=-1/0;do{if(r<=s.y&&r>=s.next.y&&s.next.y!==s.y){var a=s.x+(r-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(a<=n&&a>o&&(o=a,i=s.x<s.next.x?s:s.next,a===n))return i}s=s.next}while(s!==t);if(!i)return null;var c,l=i,h=i.x,u=i.y,I=1/0;s=i;do{n>=s.x&&s.x>=h&&n!==s.x&&Li(r<u?n:o,r,h,u,r<u?o:n,r,s.x,s.y)&&(c=Math.abs(r-s.y)/(n-s.x),bi(s,e)&&(c<I||c===I&&(s.x>i.x||s.x===i.x&&Ni(i,s)))&&(i=s,I=c)),s=s.next}while(s!==l);return i}(e,t);if(!i)return t;var s=Ui(i,e);return Ti(s,s.next),Ti(i,i.next)}function Ni(e,t){return wi(e.prev,e,t.prev)<0&&wi(t.next,e,e.next)<0}function yi(e,t,i,s,n){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*n|0)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-s)*n|0)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function _i(e){var t=e,i=e;do{(t.x<i.x||t.x===i.x&&t.y<i.y)&&(i=t),t=t.next}while(t!==e);return i}function Li(e,t,i,s,n,r,o,a){return(n-o)*(t-a)>=(e-o)*(r-a)&&(e-o)*(s-a)>=(i-o)*(t-a)&&(i-o)*(r-a)>=(n-o)*(s-a)}function Pi(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){var i=e;do{if(i.i!==e.i&&i.next.i!==e.i&&i.i!==t.i&&i.next.i!==t.i&&vi(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}(e,t)&&(bi(e,t)&&bi(t,e)&&function(e,t){var i=e,s=!1,n=(e.x+t.x)/2,r=(e.y+t.y)/2;do{i.y>r!=i.next.y>r&&i.next.y!==i.y&&n<(i.next.x-i.x)*(r-i.y)/(i.next.y-i.y)+i.x&&(s=!s),i=i.next}while(i!==e);return s}(e,t)&&(wi(e.prev,e,t.prev)||wi(e,t.prev,t))||Mi(e,t)&&wi(e.prev,e,e.next)>0&&wi(t.prev,t,t.next)>0)}function wi(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function Mi(e,t){return e.x===t.x&&e.y===t.y}function vi(e,t,i,s){var n=xi(wi(e,t,i)),r=xi(wi(e,t,s)),o=xi(wi(i,s,e)),a=xi(wi(i,s,t));return n!==r&&o!==a||(!(0!==n||!Di(e,i,t))||(!(0!==r||!Di(e,s,t))||(!(0!==o||!Di(i,e,s))||!(0!==a||!Di(i,t,s)))))}function Di(e,t,i){return t.x<=Math.max(e.x,i.x)&&t.x>=Math.min(e.x,i.x)&&t.y<=Math.max(e.y,i.y)&&t.y>=Math.min(e.y,i.y)}function xi(e){return e>0?1:e<0?-1:0}function bi(e,t){return wi(e.prev,e,e.next)<0?wi(e,t,e.next)>=0&&wi(e,e.prev,t)>=0:wi(e,t,e.prev)<0||wi(e,e.next,t)<0}function Ui(e,t){var i=new Yi(e.i,e.x,e.y),s=new Yi(t.i,t.x,t.y),n=e.next,r=t.prev;return e.next=t,t.prev=e,i.next=n,n.prev=i,s.next=i,i.prev=s,r.next=s,s.prev=r,s}function Bi(e,t,i,s){var n=new Yi(e,t,i);return s?(n.next=s.next,n.prev=s,s.next.prev=n,s.next=n):(n.prev=n,n.next=n),n}function Vi(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function Yi(e,t,i){this.i=e,this.x=t,this.y=i,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function Gi(e,t,i,s){for(var n=0,r=t,o=i-s;r<i;r+=s)n+=(e[o]-e[r])*(e[r+1]+e[o+1]),o=r;return n}fi.exports=pi,fi.exports.default=pi,pi.deviation=function(e,t,i,s){var n=t&&t.length,r=n?t[0]*i:e.length,o=Math.abs(Gi(e,0,r,i));if(n)for(var a=0,c=t.length;a<c;a++){var l=t[a]*i,h=a<c-1?t[a+1]*i:e.length;o-=Math.abs(Gi(e,l,h,i))}var u=0;for(a=0;a<s.length;a+=3){var I=s[a]*i,d=s[a+1]*i,E=s[a+2]*i;u+=Math.abs((e[I]-e[E])*(e[d+1]-e[I+1])-(e[I]-e[d])*(e[E+1]-e[I+1]))}return 0===o&&0===u?0:Math.abs((u-o)/o)},pi.flatten=function(e){for(var t=e[0][0].length,i={vertices:[],holes:[],dimensions:t},s=0,n=0;n<e.length;n++){for(var r=0;r<e[n].length;r++)for(var o=0;o<t;o++)i.vertices.push(e[n][r][o]);n>0&&(s+=e[n-1].length,i.holes.push(s))}return i};const zi=Ei(fi.exports);class ki extends Ut{constructor(){super(...arguments),t(this,"enabled",!0),t(this,"_inverseMatrix",new o.Matrix4),t(this,"_localPlane",new o.Plane),t(this,"_tempLine",new o.Line3),t(this,"_tempVector",new o.Vector3),t(this,"_plane"),t(this,"_plane2DCoordinateSystem",new o.Matrix4),t(this,"_precission",1e4),t(this,"_planeAxis")}get plane(){if(!this._plane)throw new Error("Plane not set");return this._plane}set plane(e){this._plane=e}createEdges(e){const{meshes:t,posAttr:i}=e;let s=0;i.array.fill(0);const n=[];let r=0;const a=new o.Mesh;for(const e of t)if(e.geometry){if(e.geometry.boundsTree||e.geometry.computeBoundsTree(),!e.geometry.boundsTree)throw new Error("Bounds tree not found for edges generation.");if(e instanceof o.InstancedMesh){if(0===e.count)continue;const t=e;for(let c=0;c<t.count;c++){a.geometry=e.geometry,a.matrix.copy(e.matrix);const l=new o.Matrix4;t.getMatrixAt(c,l),a.applyMatrix4(l),a.applyMatrix4(e.matrixWorld),a.updateMatrix(),a.updateMatrixWorld(),this._inverseMatrix.copy(a.matrixWorld).invert(),this._localPlane.copy(this.plane).applyMatrix4(this._inverseMatrix),s=this.shapecast(a,i,s),s!==r&&(n.push(s),r=s)}}else this._inverseMatrix.copy(e.matrixWorld).invert(),this._localPlane.copy(this.plane).applyMatrix4(this._inverseMatrix),s=this.shapecast(e,i,s),s!==r&&(n.push(s),r=s)}return{indexes:n,index:s}}createFills(e,t){this.updatePlane2DCoordinateSystem();const i=[];let s=0;for(let n=0;n<t.length;n++){const r=t[n],o=[];for(let e=s;e<r;e+=2)o.push(3*e);const a=this.computeFill(o,e);for(const e of a)i.push(e);s=r}return i}computeFill(e,t){const i=new Map,s={},n=new Map;let r=0;const o=new Map,a=new Map,c=new Set,l=this._precission;for(let h=0;h<e.length;h++){const u=e[h];let I=0,d=0,E=0,f=0;const p=t[u],C=t[u+1],T=t[u+2],m=t[u+3],R=t[u+4],g=t[u+5];if(this._tempVector.set(p,C,T),this._tempVector.applyMatrix4(this._plane2DCoordinateSystem),I=Math.trunc(this._tempVector.x*l)/l,d=Math.trunc(this._tempVector.y*l)/l,this._tempVector.set(m,R,g),this._tempVector.applyMatrix4(this._plane2DCoordinateSystem),E=Math.trunc(this._tempVector.x*l)/l,f=Math.trunc(this._tempVector.y*l)/l,I===E&&d===f)continue;const A=`${I}|${d}`,F=`${E}|${f}`;i.has(A)||i.set(A,u/3),i.has(F)||i.set(F,u/3+1);const S=i.get(A),O=i.get(F);s[S]=[I,d],s[O]=[E,f];const N=a.has(S),y=o.has(S),_=a.has(O),L=o.has(O);if(!(N||y||_||L))a.set(S,r),o.set(O,r),c.add(r),n.set(r,[S,O]),r++;else if(N&&L){const e=a.get(S),t=o.get(O);if(e!==t){const i=n.get(t),s=n.get(e);if(!i||!s)continue;n.delete(e),c.delete(e),o.set(s[s.length-1],t),o.delete(i[i.length-1]);for(const e of s)i.push(e)}else c.delete(t);a.delete(S),o.delete(O)}else if(y&&_){const e=a.get(O),t=o.get(S);if(e!==t){const i=n.get(t),s=n.get(e);if(!i||!s)continue;n.delete(e),c.delete(e),o.set(s[s.length-1],t),o.delete(i[i.length-1]);for(const e of s)i.push(e)}else c.delete(t);a.delete(O),o.delete(S)}else if(N&&_){const e=a.get(O),t=a.get(S),i=n.get(t),s=n.get(e);if(!i||!s)continue;n.delete(e),c.delete(e),a.delete(i[0]),a.delete(s[0]),o.delete(s[s.length-1]),a.set(s[s.length-1],t),s.reverse(),i.splice(0,0,...s)}else if(y&&L){const e=o.get(O),t=o.get(S),i=n.get(t),s=n.get(e);if(!i||!s)continue;n.delete(e),c.delete(e),o.delete(i[i.length-1]),o.delete(s[s.length-1]),a.delete(s[0]),o.set(s[0],t),s.reverse(),i.push(...s)}else if(N){const e=a.get(S),t=n.get(e);if(!t)continue;t.unshift(O),a.delete(S),a.set(O,e)}else if(y){const e=o.get(S),t=n.get(e);if(!t)continue;t.push(O),o.delete(S),o.set(O,e)}else if(_){const e=a.get(O),t=n.get(e);if(!t)continue;t.unshift(S),a.delete(O),a.set(S,e)}else if(L){const e=o.get(O),t=n.get(e);if(!t)continue;t.push(S),o.delete(O),o.set(S,e)}}const h=[];for(const[e,t]of n){if(c.has(e))continue;const i=[],n=new Map;let r=0;for(const e of t){const t=s[e];i.push(t[0],t[1]),n.set(r++,e)}const o=zi(i);for(const e of o){const t=n.get(e);if(void 0===t)throw new Error("Map error!");h.push(t)}}return h}updatePlane2DCoordinateSystem(){this._plane2DCoordinateSystem=new o.Matrix4;const e=new o.Vector3(1,0,0),t=new o.Vector3(0,1,0),i=this.plane.normal,s=new o.Vector3;this.plane.coplanarPoint(s),"x"===this._planeAxis?e.crossVectors(t,i):"y"===this._planeAxis?t.crossVectors(i,e):"z"===this._planeAxis||(e.crossVectors(t,i).normalize(),t.crossVectors(i,e)),this._plane2DCoordinateSystem.fromArray([e.x,e.y,e.z,0,t.x,t.y,t.z,0,i.x,i.y,i.z,0,s.x,s.y,s.z,1]),this._plane2DCoordinateSystem.invert()}shapecast(e,t,i){return e.geometry.boundsTree.shapecast({intersectsBounds:e=>this._localPlane.intersectsBox(e),intersectsTriangle:s=>{let n=0;if(this._tempLine.start.copy(s.a),this._tempLine.end.copy(s.b),this._localPlane.intersectLine(this._tempLine,this._tempVector)){const s=this._tempVector.applyMatrix4(e.matrixWorld);t.setXYZ(i,s.x,s.y,s.z),n++,i++}if(this._tempLine.start.copy(s.b),this._tempLine.end.copy(s.c),this._localPlane.intersectLine(this._tempLine,this._tempVector)){const s=this._tempVector.applyMatrix4(e.matrixWorld);t.setXYZ(i,s.x,s.y,s.z),n++,i++}if(this._tempLine.start.copy(s.c),this._tempLine.end.copy(s.a),this._localPlane.intersectLine(this._tempLine,this._tempVector)){const s=this._tempVector.applyMatrix4(e.matrixWorld);t.setXYZ(i,s.x,s.y,s.z),n++,i++}2!==n&&(i-=n)}}),i}}t(ki,"uuid","1a193b87-6376-46c8-9e65-62a1576fdb64");const Hi=class e{constructor(){t(this,"onDisposed",new Dt),t(this,"list",new Map),t(this,"enabled",!1),t(this,"_clock"),t(this,"onInit",new Dt),t(this,"update",(()=>{if(!this.enabled)return;const e=this._clock.getDelta();for(const[t,i]of this.list)i.enabled&&i.isUpdateable()&&i.update(e);requestAnimationFrame(this.update)})),this._clock=new o.Clock,e.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.");Ii.validate(e),this.list.set(e,t)}get(e){const t=e.uuid;if(!this.list.has(t)){const i=new e(this);return this.list.has(t)||this.add(t,i),i}return this.list.get(t)}init(){this.enabled=!0,this._clock.start(),this.update(),this.onInit.trigger()}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(){o.BufferGeometry.prototype.computeBoundsTree=Mt,o.BufferGeometry.prototype.disposeBoundsTree=vt,o.Mesh.prototype.raycast=wt}};t(Hi,"release","2.4.5");let Wi=Hi;class Xi extends bt{constructor(){super(...arguments),t(this,"meshes",new Set),t(this,"onAfterUpdate",new Dt),t(this,"onBeforeUpdate",new Dt),t(this,"onDisposed",new Dt),t(this,"isDisposing",!1),t(this,"enabled",!0),t(this,"uuid",Ii.create()),t(this,"name"),t(this,"_scene"),t(this,"_camera"),t(this,"_renderer",null)}get scene(){if(!this._scene)throw new Error("No scene initialized!");return this._scene}set scene(e){this._scene=e,e.worlds.set(this.uuid,this),e.currentWorld=this,e.onWorldChanged.trigger({world:this,action:"added"})}get camera(){if(!this._camera)throw new Error("No camera initialized!");return this._camera}set camera(e){this._camera=e,e.worlds.set(this.uuid,this),e.currentWorld=this,e.onWorldChanged.trigger({world:this,action:"added"})}get renderer(){return this._renderer}set renderer(e){this._renderer=e,e&&(e.worlds.set(this.uuid,this),e.currentWorld=this,e.onWorldChanged.trigger({world:this,action:"added"}))}update(e){this.enabled&&this._scene&&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(e),this.camera.isUpdateable()&&this.camera.update(e),this.renderer&&this.renderer.update(e),this.onAfterUpdate.trigger())}dispose(e=!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"}),e){const e=this.components.get(zt);this.scene.dispose(),this.camera.isDisposeable()&&this.camera.dispose(),this.renderer&&this.renderer.dispose();for(const t of this.meshes)e.destroy(t);this.meshes.clear()}this._scene=null,this._camera=null,this._renderer=null;this.components.get(Js).list.delete(this.uuid),this.onDisposed.trigger(),this.onDisposed.reset()}}class Zi{constructor(e,i,s,n){t(this,"_component"),t(this,"name"),t(this,"uuid"),this._component=e,this.name=s,this.uuid=n??Ii.create();i.get($i).list.set(this.uuid,this)}get controls(){return Xt.copySchema(this._config)}set(e){for(const t in e)if(t in this){this[t]=e[t].value}}export(e=this._config,t={}){for(const i in e){const s=e[i];if(Xt.isEntry(s))if("Color"===s.type){const{r:e,g:n,b:r}=s.value;t[i]={...s,value:{r:e,g:n,b:r}}}else if("Vector3"===s.type){const{x:e,y:n,z:r}=s.value;t[i]={...s,value:{x:e,y:n,z:r}}}else if("TextSet"===s.type){const e=Array.from(s.value);t[i]={...s,value:e}}else if("Select"===s.type){const e=Array.from(s.options);t[i]={...s,options:e}}else t[i]={...s};else t[i]={},this.export(s,t[i])}return t}import(e,t={},i=!0){for(const i in e){const s=e[i];if(Xt.isEntry(s))if("Color"===s.type){const{r:e,g:n,b:r}=s.value;t[i]={...s,value:new o.Color(e,n,r)}}else if("Vector3"===s.type){const{x:e,y:n,z:r}=s.value;t[i]={...s,value:new o.Vector3(e,n,r)}}else"TextSet"===s.type?t[i]={...s,value:new Set(s.value)}:"Select"===s.type?t[i]={...s,options:new Set(s.options)}:t[i]={...s};else t[i]={},this.import(s,t[i],!1)}i&&this.set(t)}}const ji=class e extends Ut{constructor(i){super(i),t(this,"list",new Wt),t(this,"enabled",!0),i.add(e.uuid,this)}};t(ji,"uuid","b8c764e0-6b24-4e77-9a32-35fa728ee5b4");let $i=ji;class Qi{constructor(e,i){t(this,"_list"),t(this,"_scene"),this._list=e,this._scene=i}get color(){return this._list.directionalLight.color.value}set color(e){this._list.directionalLight.color.value=e;for(const[,t]of this._scene.directionalLights)t.color.copy(e)}get intensity(){return this._list.directionalLight.intensity.value}set intensity(e){this._list.directionalLight.intensity.value=e;for(const[,t]of this._scene.directionalLights)t.intensity=e}get position(){return this._list.directionalLight.position.value.clone()}set position(e){this._list.directionalLight.position.value=e;for(const[,t]of this._scene.directionalLights)t.position.copy(e)}}class qi{constructor(e,i){t(this,"_list"),t(this,"_scene"),this._list=e,this._scene=i}get color(){return this._list.ambientLight.color.value}set color(e){this._list.ambientLight.color.value=e;for(const[,t]of this._scene.ambientLights)t.color.copy(e)}get intensity(){return this._list.ambientLight.intensity.value}set intensity(e){this._list.ambientLight.intensity.value=e;for(const[,t]of this._scene.ambientLights)t.intensity=e}}class Ki extends Zi{constructor(){super(...arguments),t(this,"_config",{backgroundColor:{value:new o.Color,type:"Color"},ambientLight:{color:{type:"Color",value:new o.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2}},directionalLight:{color:{type:"Color",value:new o.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2},position:{type:"Vector3",value:new o.Vector3}}}),t(this,"ambientLight",new qi(this._config,this._component)),t(this,"directionalLight",new Qi(this._config,this._component))}get backgroundColor(){return this._config.backgroundColor.value}set backgroundColor(e){this._config.backgroundColor.value=e,this._component.three.background=e}}class Ji extends kt{constructor(e){super(e),t(this,"onSetup",new Dt),t(this,"isSetup",!1),t(this,"three"),t(this,"config",new Ki(this,this.components,"Scene")),t(this,"_defaultConfig",{backgroundColor:new o.Color(2107698),directionalLight:{color:new o.Color("white"),intensity:1.5,position:new o.Vector3(5,10,3)},ambientLight:{color:new o.Color("white"),intensity:1}}),this.three=new o.Scene,this.three.background=new o.Color(2107698)}setup(e){const t={...this._defaultConfig,...e};this.config.backgroundColor=t.backgroundColor;const i=t.ambientLight;this.config.ambientLight.color=i.color,this.config.ambientLight.intensity=i.intensity;const s=t.directionalLight;this.config.directionalLight.color=s.color,this.config.directionalLight.intensity=s.intensity,this.config.directionalLight.position=s.position,this.deleteAllLights();const{color:n,intensity:r}=this.config.directionalLight,a=new o.DirectionalLight(n,r);a.position.copy(s.position);const{color:c,intensity:l}=this.config.directionalLight,h=new o.AmbientLight(c,l);this.three.add(a,h),this.directionalLights.set(a.uuid,a),this.ambientLights.set(h.uuid,h),this.isSetup=!0,this.onSetup.trigger()}dispose(){super.dispose();this.components.get($i).list.delete(this.config.uuid)}}
|
|
1
|
+
"use strict";var e=Object.defineProperty,t=(t,i,s)=>(((t,i,s)=>{i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[i]=s})(t,"symbol"!=typeof i?i+"":i,s),s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("three"),s=require("@thatopen/fragments"),n=require("web-ifc");function r(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const i in e)if("default"!==i){const s=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,s.get?s:{enumerable:!0,get:()=>e[i]})}return t.default=e,Object.freeze(t)}const o=r(i),a=r(s),c=r(n),l=1.25,h=65535,u=Math.pow(2,-24),I=Symbol("SKIP_GENERATION");function d(e){return function(e){return e.index?e.index.count:e.attributes.position.count}(e)/3}function E(e,t){if(!e.index){const s=e.attributes.position.count,n=function(e,t=ArrayBuffer){return e>65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}(s,t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);e.setIndex(new i.BufferAttribute(n,1));for(let e=0;e<s;e++)n[e]=e}}function f(e){const t=d(e),i=e.drawRange,s=i.start/3,n=(i.start+i.count)/3,r=Math.max(0,s),o=Math.min(t,n)-r;return[{offset:Math.floor(r),count:Math.floor(o)}]}function p(e){if(!e.groups||!e.groups.length)return f(e);const t=[],i=new Set,s=e.drawRange,n=s.start/3,r=(s.start+s.count)/3;for(const t of e.groups){const e=t.start/3,s=(t.start+t.count)/3;i.add(Math.max(n,e)),i.add(Math.min(r,s))}const o=Array.from(i.values()).sort(((e,t)=>e-t));for(let e=0;e<o.length-1;e++){const i=o[e],s=o[e+1];t.push({offset:Math.floor(i),count:Math.floor(s-i)})}return t}function C(e,t,i){return i.min.x=t[e],i.min.y=t[e+1],i.min.z=t[e+2],i.max.x=t[e+3],i.max.y=t[e+4],i.max.z=t[e+5],i}function T(e){let t=-1,i=-1/0;for(let s=0;s<3;s++){const n=e[s+3]-e[s];n>i&&(i=n,t=s)}return t}function m(e,t){t.set(e)}function R(e,t,i){let s,n;for(let r=0;r<3;r++){const o=r+3;s=e[r],n=t[r],i[r]=s<n?s:n,s=e[o],n=t[o],i[o]=s>n?s:n}}function g(e,t,i){for(let s=0;s<3;s++){const n=t[e+2*s],r=t[e+2*s+1],o=n-r,a=n+r;o<i[s]&&(i[s]=o),a>i[s+3]&&(i[s+3]=a)}}function A(e){const t=e[3]-e[0],i=e[4]-e[1],s=e[5]-e[2];return 2*(t*i+i*s+s*t)}function F(e,t,i,s,n=null){let r=1/0,o=1/0,a=1/0,c=-1/0,l=-1/0,h=-1/0,u=1/0,I=1/0,d=1/0,E=-1/0,f=-1/0,p=-1/0;const C=null!==n;for(let s=6*t,n=6*(t+i);s<n;s+=6){const t=e[s+0],i=e[s+1],n=t-i,T=t+i;n<r&&(r=n),T>c&&(c=T),C&&t<u&&(u=t),C&&t>E&&(E=t);const m=e[s+2],R=e[s+3],g=m-R,A=m+R;g<o&&(o=g),A>l&&(l=A),C&&m<I&&(I=m),C&&m>f&&(f=m);const F=e[s+4],S=e[s+5],O=F-S,N=F+S;O<a&&(a=O),N>h&&(h=N),C&&F<d&&(d=F),C&&F>p&&(p=F)}s[0]=r,s[1]=o,s[2]=a,s[3]=c,s[4]=l,s[5]=h,C&&(n[0]=u,n[1]=I,n[2]=d,n[3]=E,n[4]=f,n[5]=p)}const S=32,O=(e,t)=>e.candidate-t.candidate,N=new Array(S).fill().map((()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0}))),y=new Float32Array(6);class _{constructor(){}}function L(e,t,i,s,n,r){let o=s,a=s+n-1;const c=r.pos,l=2*r.axis;for(;;){for(;o<=a&&i[6*o+l]<c;)o++;for(;o<=a&&i[6*a+l]>=c;)a--;if(!(o<a))return o;for(let e=0;e<3;e++){let i=t[3*o+e];t[3*o+e]=t[3*a+e],t[3*a+e]=i}for(let e=0;e<6;e++){let t=i[6*o+e];i[6*o+e]=i[6*a+e],i[6*a+e]=t}o++,a--}}function P(e,t,i,s,n,r){let o=s,a=s+n-1;const c=r.pos,l=2*r.axis;for(;;){for(;o<=a&&i[6*o+l]<c;)o++;for(;o<=a&&i[6*a+l]>=c;)a--;if(!(o<a))return o;{let t=e[o];e[o]=e[a],e[a]=t;for(let e=0;e<6;e++){let t=i[6*o+e];i[6*o+e]=i[6*a+e],i[6*a+e]=t}o++,a--}}}function w(e,t){const i=e.geometry,s=i.index?i.index.array:null,n=t.maxDepth,r=t.verbose,o=t.maxLeafTris,a=t.strategy,c=t.onProgress,h=d(i),I=e._indirectBuffer;let E=!1;const C=new Float32Array(6),w=new Float32Array(6),M=function(e,t){var i;(i=t)[0]=i[1]=i[2]=1/0,i[3]=i[4]=i[5]=-1/0;const s=e.attributes.position,n=e.index?e.index.array:null,r=d(e),o=new Float32Array(6*r),a=s.normalized,c=s.array,l=s.offset||0;let h=3;s.isInterleavedBufferAttribute&&(h=s.data.stride);const I=["getX","getY","getZ"];for(let e=0;e<r;e++){const i=3*e,r=6*e;let d=i+0,E=i+1,f=i+2;n&&(d=n[d],E=n[E],f=n[f]),a||(d=d*h+l,E=E*h+l,f=f*h+l);for(let e=0;e<3;e++){let i,n,l;a?(i=s[I[e]](d),n=s[I[e]](E),l=s[I[e]](f)):(i=c[d+e],n=c[E+e],l=c[f+e]);let h=i;n<h&&(h=n),l<h&&(h=l);let p=i;n>p&&(p=n),l>p&&(p=l);const C=(p-h)/2,T=2*e;o[r+T+0]=h+C,o[r+T+1]=C+(Math.abs(h)+C)*u,h<t[e]&&(t[e]=h),p>t[e+3]&&(t[e+3]=p)}}return o}(i,C),v=t.indirect?P:L,D=[],x=t.indirect?f(i):p(i);if(1===x.length){const e=x[0],t=new _;t.boundingData=C,function(e,t,i,s){let n=1/0,r=1/0,o=1/0,a=-1/0,c=-1/0,l=-1/0;for(let s=6*t,h=6*(t+i);s<h;s+=6){const t=e[s+0];t<n&&(n=t),t>a&&(a=t);const i=e[s+2];i<r&&(r=i),i>c&&(c=i);const h=e[s+4];h<o&&(o=h),h>l&&(l=h)}s[0]=n,s[1]=r,s[2]=o,s[3]=a,s[4]=c,s[5]=l}(M,e.offset,e.count,w),U(t,e.offset,e.count,w),D.push(t)}else for(let e of x){const t=new _;t.boundingData=new Float32Array(6),F(M,e.offset,e.count,t.boundingData,w),U(t,e.offset,e.count,w),D.push(t)}return D;function b(e){c&&c(e/h)}function U(e,t,c,h=null,u=0){if(!E&&u>=n&&(E=!0,r&&(console.warn(`MeshBVH: Max depth of ${n} reached when generating BVH. Consider increasing maxDepth.`),console.warn(i))),c<=o||u>=n)return b(t+c),e.offset=t,e.count=c,e;const d=function(e,t,i,s,n,r){let o=-1,a=0;if(0===r)o=T(t),-1!==o&&(a=(t[o]+t[o+3])/2);else if(1===r)o=T(e),-1!==o&&(a=function(e,t,i,s){let n=0;for(let r=t,o=t+i;r<o;r++)n+=e[6*r+2*s];return n/i}(i,s,n,o));else if(2===r){const r=A(e);let c=l*n;const h=6*s,u=6*(s+n);for(let e=0;e<3;e++){const s=t[e],I=(t[e+3]-s)/S;if(n<8){const t=[...N];t.length=n;let s=0;for(let n=h;n<u;n+=6,s++){const r=t[s];r.candidate=i[n+2*e],r.count=0;const{bounds:o,leftCacheBounds:a,rightCacheBounds:c}=r;for(let e=0;e<3;e++)c[e]=1/0,c[e+3]=-1/0,a[e]=1/0,a[e+3]=-1/0,o[e]=1/0,o[e+3]=-1/0;g(n,i,o)}t.sort(O);let I=n;for(let e=0;e<I;e++){const i=t[e];for(;e+1<I&&t[e+1].candidate===i.candidate;)t.splice(e+1,1),I--}for(let s=h;s<u;s+=6){const n=i[s+2*e];for(let e=0;e<I;e++){const r=t[e];n>=r.candidate?g(s,i,r.rightCacheBounds):(g(s,i,r.leftCacheBounds),r.count++)}}for(let i=0;i<I;i++){const s=t[i],h=s.count,u=n-s.count,I=s.leftCacheBounds,d=s.rightCacheBounds;let E=0;0!==h&&(E=A(I)/r);let f=0;0!==u&&(f=A(d)/r);const p=1+l*(E*h+f*u);p<c&&(o=e,c=p,a=s.candidate)}}else{for(let e=0;e<S;e++){const t=N[e];t.count=0,t.candidate=s+I+e*I;const i=t.bounds;for(let e=0;e<3;e++)i[e]=1/0,i[e+3]=-1/0}for(let t=h;t<u;t+=6){let n=~~((i[t+2*e]-s)/I);n>=S&&(n=31);const r=N[n];r.count++,g(t,i,r.bounds)}const t=N[31];m(t.bounds,t.rightCacheBounds);for(let e=30;e>=0;e--){const t=N[e],i=N[e+1];R(t.bounds,i.rightCacheBounds,t.rightCacheBounds)}let d=0;for(let t=0;t<31;t++){const i=N[t],s=i.count,h=i.bounds,u=N[t+1].rightCacheBounds;0!==s&&(0===d?m(h,y):R(h,y,y)),d+=s;let I=0,E=0;0!==d&&(I=A(y)/r);const f=n-d;0!==f&&(E=A(u)/r);const p=1+l*(I*d+E*f);p<c&&(o=e,c=p,a=i.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${r} used.`);return{axis:o,pos:a}}(e.boundingData,h,M,t,c,a);if(-1===d.axis)return b(t+c),e.offset=t,e.count=c,e;const f=v(I,s,M,t,c,d);if(f===t||f===t+c)b(t+c),e.offset=t,e.count=c;else{e.splitAxis=d.axis;const i=new _,s=t,n=f-t;e.left=i,i.boundingData=new Float32Array(6),F(M,s,n,i.boundingData,w),U(i,s,n,w,u+1);const r=new _,o=f,a=c-n;e.right=r,r.boundingData=new Float32Array(6),F(M,o,a,r.boundingData,w),U(r,o,a,w,u+1)}return e}}function M(e,t){const i=e.geometry;t.indirect&&(e._indirectBuffer=function(e,t){const i=(e.index?e.index.count:e.attributes.position.count)/3,s=i>65536,n=s?4:2,r=t?new SharedArrayBuffer(i*n):new ArrayBuffer(i*n),o=s?new Uint32Array(r):new Uint16Array(r);for(let e=0,t=o.length;e<t;e++)o[e]=e;return o}(i,t.useSharedArrayBuffer),function(e){if(0===e.groups.length)return!1;const t=d(e),i=p(e).sort(((e,t)=>e.offset-t.offset)),s=i[i.length-1];s.count=Math.min(t-s.offset,s.count);let n=0;return i.forEach((({count:e})=>n+=e)),t!==n}(i)&&!t.verbose&&console.warn('MeshBVH: Provided geometry contains groups that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),e._indirectBuffer||E(i,t);const s=w(e,t);let n,r,o;const a=[],c=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer;for(let e=0;e<s.length;e++){const t=s[e];const i=new c(32*l(t));n=new Float32Array(i),r=new Uint32Array(i),o=new Uint16Array(i),u(0,t),a.push(i)}return void(e._roots=a);function l(e){return e.count?1:1+l(e.left)+l(e.right)}function u(e,t){const i=e/4,s=e/2,a=!!t.count,c=t.boundingData;for(let e=0;e<6;e++)n[i+e]=c[e];if(a){const n=t.offset,a=t.count;return r[i+6]=n,o[s+14]=a,o[s+15]=h,e+32}{const s=t.left,n=t.right,o=t.splitAxis;let a;if(a=u(e+32,s),a/4>Math.pow(2,32))throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return r[i+6]=a/4,a=u(a,n),r[i+7]=o,a}}}class v{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let i=1/0,s=-1/0;for(let n=0,r=e.length;n<r;n++){const r=e[n][t];i=r<i?r:i,s=r>s?r:s}this.min=i,this.max=s}setFromPoints(e,t){let i=1/0,s=-1/0;for(let n=0,r=t.length;n<r;n++){const r=t[n],o=e.dot(r);i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}isSeparated(e){return this.min>e.max||e.min>this.max}}v.prototype.setFromBox=function(){const e=new i.Vector3;return function(t,i){const s=i.min,n=i.max;let r=1/0,o=-1/0;for(let i=0;i<=1;i++)for(let a=0;a<=1;a++)for(let c=0;c<=1;c++){e.x=s.x*i+n.x*(1-i),e.y=s.y*a+n.y*(1-a),e.z=s.z*c+n.z*(1-c);const l=t.dot(e);r=Math.min(l,r),o=Math.max(l,o)}this.min=r,this.max=o}}();const D=function(){const e=new i.Vector3,t=new i.Vector3,s=new i.Vector3;return function(i,n,r){const o=i.start,a=e,c=n.start,l=t;s.subVectors(o,c),e.subVectors(i.end,i.start),t.subVectors(n.end,n.start);const h=s.dot(l),u=l.dot(a),I=l.dot(l),d=s.dot(a),E=a.dot(a)*I-u*u;let f,p;f=0!==E?(h*u-d*I)/E:0,p=(h+f*u)/I,r.x=f,r.y=p}}(),x=function(){const e=new i.Vector2,t=new i.Vector3,s=new i.Vector3;return function(i,n,r,o){D(i,n,e);let a=e.x,c=e.y;if(a>=0&&a<=1&&c>=0&&c<=1)return i.at(a,r),void n.at(c,o);if(a>=0&&a<=1)return c<0?n.at(0,o):n.at(1,o),void i.closestPointToPoint(o,!0,r);if(c>=0&&c<=1)return a<0?i.at(0,r):i.at(1,r),void n.closestPointToPoint(r,!0,o);{let e,l;e=a<0?i.start:i.end,l=c<0?n.start:n.end;const h=t,u=s;return i.closestPointToPoint(l,!0,t),n.closestPointToPoint(e,!0,s),h.distanceToSquared(l)<=u.distanceToSquared(e)?(r.copy(h),void o.copy(l)):(r.copy(e),void o.copy(u))}}}(),b=function(){const e=new i.Vector3,t=new i.Vector3,s=new i.Plane,n=new i.Line3;return function(i,r){const{radius:o,center:a}=i,{a:c,b:l,c:h}=r;n.start=c,n.end=l;if(n.closestPointToPoint(a,!0,e).distanceTo(a)<=o)return!0;n.start=c,n.end=h;if(n.closestPointToPoint(a,!0,e).distanceTo(a)<=o)return!0;n.start=l,n.end=h;if(n.closestPointToPoint(a,!0,e).distanceTo(a)<=o)return!0;const u=r.getPlane(s);if(Math.abs(u.distanceToPoint(a))<=o){const e=u.projectPoint(a,t);if(r.containsPoint(e))return!0}return!1}}();function U(e){return Math.abs(e)<1e-15}class B extends i.Triangle{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map((()=>new i.Vector3)),this.satBounds=new Array(4).fill().map((()=>new v)),this.points=[this.a,this.b,this.c],this.sphere=new i.Sphere,this.plane=new i.Plane,this.needsUpdate=!0}intersectsSphere(e){return b(e,this)}update(){const e=this.a,t=this.b,i=this.c,s=this.points,n=this.satAxes,r=this.satBounds,o=n[0],a=r[0];this.getNormal(o),a.setFromPoints(o,s);const c=n[1],l=r[1];c.subVectors(e,t),l.setFromPoints(c,s);const h=n[2],u=r[2];h.subVectors(t,i),u.setFromPoints(h,s);const I=n[3],d=r[3];I.subVectors(i,e),d.setFromPoints(I,s),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}}B.prototype.closestPointToSegment=function(){const e=new i.Vector3,t=new i.Vector3,s=new i.Line3;return function(i,n=null,r=null){const{start:o,end:a}=i,c=this.points;let l,h=1/0;for(let o=0;o<3;o++){const a=(o+1)%3;s.start.copy(c[o]),s.end.copy(c[a]),x(s,i,e,t),l=e.distanceToSquared(t),l<h&&(h=l,n&&n.copy(e),r&&r.copy(t))}return this.closestPointToPoint(o,e),l=o.distanceToSquared(e),l<h&&(h=l,n&&n.copy(e),r&&r.copy(o)),this.closestPointToPoint(a,e),l=a.distanceToSquared(e),l<h&&(h=l,n&&n.copy(e),r&&r.copy(a)),Math.sqrt(h)}}(),B.prototype.intersectsTriangle=function(){const e=new B,t=new Array(3),s=new Array(3),n=new v,r=new v,o=new i.Vector3,a=new i.Vector3,c=new i.Vector3,l=new i.Vector3,h=new i.Vector3,u=new i.Line3,I=new i.Line3,d=new i.Line3,E=new i.Vector3;function f(e,t,i){const s=e.points;let n=0,r=-1;for(let e=0;e<3;e++){const{start:o,end:c}=u;o.copy(s[e]),c.copy(s[(e+1)%3]),u.delta(a);const l=U(t.distanceToPoint(o));if(U(t.normal.dot(a))&&l){i.copy(u),n=2;break}const h=t.intersectLine(u,E);if(!h&&l&&E.copy(o),(h||l)&&!U(E.distanceTo(c))){if(n<=1){(1===n?i.start:i.end).copy(E),l&&(r=n)}else if(n>=2){(1===r?i.start:i.end).copy(E),n=2;break}if(n++,2===n&&-1===r)break}}return n}return function(i,a=null,u=!1){this.needsUpdate&&this.update(),i.isExtendedTriangle?i.needsUpdate&&i.update():(e.copy(i),e.update(),i=e);const E=this.plane,p=i.plane;if(Math.abs(E.normal.dot(p.normal))>1-1e-10){const e=this.satBounds,c=this.satAxes;s[0]=i.a,s[1]=i.b,s[2]=i.c;for(let t=0;t<4;t++){const i=e[t],r=c[t];if(n.setFromPoints(r,s),i.isSeparated(n))return!1}const l=i.satBounds,h=i.satAxes;t[0]=this.a,t[1]=this.b,t[2]=this.c;for(let e=0;e<4;e++){const i=l[e],s=h[e];if(n.setFromPoints(s,t),i.isSeparated(n))return!1}for(let e=0;e<4;e++){const i=c[e];for(let e=0;e<4;e++){const a=h[e];if(o.crossVectors(i,a),n.setFromPoints(o,t),r.setFromPoints(o,s),n.isSeparated(r))return!1}}return a&&(u||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),a.start.set(0,0,0),a.end.set(0,0,0)),!0}{const e=f(this,p,I);if(1===e&&i.containsPoint(I.end))return a&&(a.start.copy(I.end),a.end.copy(I.end)),!0;if(2!==e)return!1;const t=f(i,E,d);if(1===t&&this.containsPoint(d.end))return a&&(a.start.copy(d.end),a.end.copy(d.end)),!0;if(2!==t)return!1;if(I.delta(c),d.delta(l),c.dot(l)<0){let e=d.start;d.start=d.end,d.end=e}const s=I.start.dot(c),n=I.end.dot(c),r=d.start.dot(c),o=d.end.dot(c);return(s===o||r===n||n<r!==s<o)&&(a&&(h.subVectors(I.start,d.start),h.dot(c)>0?a.start.copy(I.start):a.start.copy(d.start),h.subVectors(I.end,d.end),h.dot(c)<0?a.end.copy(I.end):a.end.copy(d.end)),!0)}}}(),B.prototype.distanceToPoint=function(){const e=new i.Vector3;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}}(),B.prototype.distanceToTriangle=function(){const e=new i.Vector3,t=new i.Vector3,s=["a","b","c"],n=new i.Line3,r=new i.Line3;return function(i,o=null,a=null){const c=o||a?n:null;if(this.intersectsTriangle(i,c))return(o||a)&&(o&&c.getCenter(o),a&&c.getCenter(a)),0;let l=1/0;for(let t=0;t<3;t++){let n;const r=s[t],c=i[r];this.closestPointToPoint(c,e),n=c.distanceToSquared(e),n<l&&(l=n,o&&o.copy(e),a&&a.copy(c));const h=this[r];i.closestPointToPoint(h,e),n=h.distanceToSquared(e),n<l&&(l=n,o&&o.copy(h),a&&a.copy(e))}for(let c=0;c<3;c++){const h=s[c],u=s[(c+1)%3];n.set(this[h],this[u]);for(let c=0;c<3;c++){const h=s[c],u=s[(c+1)%3];r.set(i[h],i[u]),x(n,r,e,t);const I=e.distanceToSquared(t);I<l&&(l=I,o&&o.copy(e),a&&a.copy(t))}}return Math.sqrt(l)}}();class V{constructor(e,t,s){this.isOrientedBox=!0,this.min=new i.Vector3,this.max=new i.Vector3,this.matrix=new i.Matrix4,this.invMatrix=new i.Matrix4,this.points=new Array(8).fill().map((()=>new i.Vector3)),this.satAxes=new Array(3).fill().map((()=>new i.Vector3)),this.satBounds=new Array(3).fill().map((()=>new v)),this.alignedSatBounds=new Array(3).fill().map((()=>new v)),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),s&&this.matrix.copy(s)}set(e,t,i){this.min.copy(e),this.max.copy(t),this.matrix.copy(i),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}V.prototype.update=function(){return function(){const e=this.matrix,t=this.min,i=this.max,s=this.points;for(let n=0;n<=1;n++)for(let r=0;r<=1;r++)for(let o=0;o<=1;o++){const a=s[1*n|2*r|4*o];a.x=n?i.x:t.x,a.y=r?i.y:t.y,a.z=o?i.z:t.z,a.applyMatrix4(e)}const n=this.satBounds,r=this.satAxes,o=s[0];for(let e=0;e<3;e++){const t=r[e],i=n[e],a=s[1<<e];t.subVectors(o,a),i.setFromPoints(t,s)}const a=this.alignedSatBounds;a[0].setFromPointsField(s,"x"),a[1].setFromPointsField(s,"y"),a[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),V.prototype.intersectsBox=function(){const e=new v;return function(t){this.needsUpdate&&this.update();const i=t.min,s=t.max,n=this.satBounds,r=this.satAxes,o=this.alignedSatBounds;if(e.min=i.x,e.max=s.x,o[0].isSeparated(e))return!1;if(e.min=i.y,e.max=s.y,o[1].isSeparated(e))return!1;if(e.min=i.z,e.max=s.z,o[2].isSeparated(e))return!1;for(let i=0;i<3;i++){const s=r[i],o=n[i];if(e.setFromBox(s,t),o.isSeparated(e))return!1}return!0}}(),V.prototype.intersectsTriangle=function(){const e=new B,t=new Array(3),s=new v,n=new v,r=new i.Vector3;return function(i){this.needsUpdate&&this.update(),i.isExtendedTriangle?i.needsUpdate&&i.update():(e.copy(i),e.update(),i=e);const o=this.satBounds,a=this.satAxes;t[0]=i.a,t[1]=i.b,t[2]=i.c;for(let e=0;e<3;e++){const i=o[e],n=a[e];if(s.setFromPoints(n,t),i.isSeparated(s))return!1}const c=i.satBounds,l=i.satAxes,h=this.points;for(let e=0;e<3;e++){const t=c[e],i=l[e];if(s.setFromPoints(i,h),t.isSeparated(s))return!1}for(let e=0;e<3;e++){const i=a[e];for(let e=0;e<4;e++){const o=l[e];if(r.crossVectors(i,o),s.setFromPoints(r,t),n.setFromPoints(r,h),s.isSeparated(n))return!1}}return!0}}(),V.prototype.closestPointToPoint=function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}}(),V.prototype.distanceToPoint=function(){const e=new i.Vector3;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}}(),V.prototype.distanceToBox=function(){const e=["x","y","z"],t=new Array(12).fill().map((()=>new i.Line3)),s=new Array(12).fill().map((()=>new i.Line3)),n=new i.Vector3,r=new i.Vector3;return function(i,o=0,a=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(i))return(a||c)&&(i.getCenter(r),this.closestPointToPoint(r,n),i.closestPointToPoint(n,r),a&&a.copy(n),c&&c.copy(r)),0;const l=o*o,h=i.min,u=i.max,I=this.points;let d=1/0;for(let e=0;e<8;e++){const t=I[e];r.copy(t).clamp(h,u);const i=t.distanceToSquared(r);if(i<d&&(d=i,a&&a.copy(t),c&&c.copy(r),i<l))return Math.sqrt(i)}let E=0;for(let i=0;i<3;i++)for(let n=0;n<=1;n++)for(let r=0;r<=1;r++){const o=(i+1)%3,a=(i+2)%3,c=1<<i|n<<o|r<<a,l=I[n<<o|r<<a],d=I[c];t[E].set(l,d);const f=e[i],p=e[o],C=e[a],T=s[E],m=T.start,R=T.end;m[f]=h[f],m[p]=n?h[p]:u[p],m[C]=r?h[C]:u[p],R[f]=u[f],R[p]=n?h[p]:u[p],R[C]=r?h[C]:u[p],E++}for(let e=0;e<=1;e++)for(let t=0;t<=1;t++)for(let i=0;i<=1;i++){r.x=e?u.x:h.x,r.y=t?u.y:h.y,r.z=i?u.z:h.z,this.closestPointToPoint(r,n);const s=r.distanceToSquared(n);if(s<d&&(d=s,a&&a.copy(n),c&&c.copy(r),s<l))return Math.sqrt(s)}for(let e=0;e<12;e++){const i=t[e];for(let e=0;e<12;e++){const t=s[e];x(i,t,n,r);const o=n.distanceToSquared(r);if(o<d&&(d=o,a&&a.copy(n),c&&c.copy(r),o<l))return Math.sqrt(o)}}return Math.sqrt(d)}}();class Y{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return 0===e.length?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class G extends Y{constructor(){super((()=>new B))}}const z=new G;function k(e,t){return 65535===t[e+15]}function H(e,t){return t[e+6]}function W(e,t){return t[e+14]}function X(e){return e+8}function Z(e,t){return t[e+6]}function j(e,t){return t[e+7]}const $=new class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=i=>{t&&e.push(t),t=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,0!==e.length&&this.setBuffer(e.pop())}}};let Q,q;const K=[],J=new Y((()=>new i.Box3));function ee(e,t,i,s,n,r){Q=J.getPrimitive(),q=J.getPrimitive(),K.push(Q,q),$.setBuffer(e._roots[t]);const o=te(0,e.geometry,i,s,n,r);$.clearBuffer(),J.releasePrimitive(Q),J.releasePrimitive(q),K.pop(),K.pop();const a=K.length;return a>0&&(q=K[a-1],Q=K[a-2]),o}function te(e,t,i,s,n=null,r=0,o=0){const{float32Array:a,uint16Array:c,uint32Array:l}=$;let h=2*e;if(k(h,c)){const t=H(e,l),i=W(h,c);return C(e,a,Q),s(t,i,!1,o,r+e,Q)}{let h=function(e){const{uint16Array:t,uint32Array:i}=$;let s=2*e;for(;!k(s,t);)s=2*(e=X(e));return H(e,i)},u=function(e){const{uint16Array:t,uint32Array:i}=$;let s=2*e;for(;!k(s,t);)s=2*(e=Z(e,i));return H(e,i)+W(s,t)};const I=X(e),d=Z(e,l);let E,f,p,T,m=I,R=d;if(n&&(p=Q,T=q,C(m,a,p),C(R,a,T),E=n(p),f=n(T),f<E)){m=d,R=I;const e=E;E=f,f=e,p=T}p||(p=Q,C(m,a,p));const g=i(p,k(2*m,c),E,o+1,r+m);let A;if(2===g){const e=h(m);A=s(e,u(m)-e,!0,o+1,r+m,p)}else A=g&&te(m,t,i,s,n,r,o+1);if(A)return!0;T=q,C(R,a,T);const F=i(T,k(2*R,c),f,o+1,r+R);let S;if(2===F){const e=h(R);S=s(e,u(R)-e,!0,o+1,r+R,T)}else S=F&&te(R,t,i,s,n,r,o+1);return!!S}}const ie=new i.Vector3,se=new i.Vector3;const ne=new i.Vector3,re=new i.Vector3,oe=new i.Vector3,ae=new i.Vector2,ce=new i.Vector2,le=new i.Vector2,he=new i.Vector3,ue=new i.Vector3,Ie=new i.Vector3,de=new i.Vector3;function Ee(e,t,s,n,r,o,a,c,l){ne.fromBufferAttribute(t,o),re.fromBufferAttribute(t,a),oe.fromBufferAttribute(t,c);const h=function(e,t,s,n,r,o){let a;return a=o===i.BackSide?e.intersectTriangle(n,s,t,!0,r):e.intersectTriangle(t,s,n,o!==i.DoubleSide,r),null===a?null:{distance:e.origin.distanceTo(r),point:r.clone()}}(e,ne,re,oe,de,l);if(h){n&&(ae.fromBufferAttribute(n,o),ce.fromBufferAttribute(n,a),le.fromBufferAttribute(n,c),h.uv=i.Triangle.getInterpolation(de,ne,re,oe,ae,ce,le,new i.Vector2)),r&&(ae.fromBufferAttribute(r,o),ce.fromBufferAttribute(r,a),le.fromBufferAttribute(r,c),h.uv1=i.Triangle.getInterpolation(de,ne,re,oe,ae,ce,le,new i.Vector2)),s&&(he.fromBufferAttribute(s,o),ue.fromBufferAttribute(s,a),Ie.fromBufferAttribute(s,c),h.normal=i.Triangle.getInterpolation(de,ne,re,oe,he,ue,Ie,new i.Vector3),h.normal.dot(e.direction)>0&&h.normal.multiplyScalar(-1));const t={a:o,b:a,c:c,normal:new i.Vector3,materialIndex:0};i.Triangle.getNormal(ne,re,oe,t.normal),h.face=t,h.faceIndex=o}return h}function fe(e,t,i,s,n){const r=3*s;let o=r+0,a=r+1,c=r+2;const l=e.index;e.index&&(o=l.getX(o),a=l.getX(a),c=l.getX(c));const{position:h,normal:u,uv:I,uv1:d}=e.attributes,E=Ee(i,h,u,I,d,o,a,c,t);return E?(E.faceIndex=s,n&&n.push(E),E):null}function pe(e,t,i,s){const n=e.a,r=e.b,o=e.c;let a=t,c=t+1,l=t+2;i&&(a=i.getX(a),c=i.getX(c),l=i.getX(l)),n.x=s.getX(a),n.y=s.getY(a),n.z=s.getZ(a),r.x=s.getX(c),r.y=s.getY(c),r.z=s.getZ(c),o.x=s.getX(l),o.y=s.getY(l),o.z=s.getZ(l)}function Ce(e,t,i,s,n,r,o){const{geometry:a}=i,{index:c}=a,l=a.attributes.position;for(let i=e,a=t+e;i<a;i++){let e;if(e=i,pe(o,3*e,c,l),o.needsUpdate=!0,s(o,e,n,r))return!0}return!1}function Te(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));const i=e.geometry,s=i.index?i.index.array:null,n=i.attributes.position;let r,o,a,c,l=0;const u=e._roots;for(let e=0,t=u.length;e<t;e++)r=u[e],o=new Uint32Array(r),a=new Uint16Array(r),c=new Float32Array(r),I(0,l),l+=r.byteLength;function I(e,i,r=!1){const l=2*e;if(a[l+15]===h){const t=o[e+6];let i=1/0,r=1/0,h=1/0,u=-1/0,I=-1/0,d=-1/0;for(let e=3*t,o=3*(t+a[l+14]);e<o;e++){let t=s[e];const o=n.getX(t),a=n.getY(t),c=n.getZ(t);o<i&&(i=o),o>u&&(u=o),a<r&&(r=a),a>I&&(I=a),c<h&&(h=c),c>d&&(d=c)}return(c[e+0]!==i||c[e+1]!==r||c[e+2]!==h||c[e+3]!==u||c[e+4]!==I||c[e+5]!==d)&&(c[e+0]=i,c[e+1]=r,c[e+2]=h,c[e+3]=u,c[e+4]=I,c[e+5]=d,!0)}{const s=e+8,n=o[e+6],a=s+i,l=n+i;let h=r,u=!1,d=!1;t?h||(u=t.has(a),d=t.has(l),h=!u&&!d):(u=!0,d=!0);const E=h||d;let f=!1;(h||u)&&(f=I(s,i,h));let p=!1;E&&(p=I(n,i,h));const C=f||p;if(C)for(let t=0;t<3;t++){const i=s+t,r=n+t,o=c[i],a=c[i+3],l=c[r],h=c[r+3];c[e+t]=o<l?o:l,c[e+t+3]=a>h?a:h}return C}}}const me=new i.Box3;function Re(e,t,i,s){return C(e,t,me),i.intersectBox(me,s)}function ge(e,t,i,s,n,r,o){const{geometry:a}=i,{index:c}=a,l=a.attributes.position;for(let a=e,h=t+e;a<h;a++){let e;if(e=i.resolveTriangleIndex(a),pe(o,3*e,c,l),o.needsUpdate=!0,s(o,e,n,r))return!0}return!1}const Ae=new i.Vector3;function Fe(e,t,i,s,n){$.setBuffer(e._roots[t]),Se(0,e,i,s,n),$.clearBuffer()}function Se(e,t,i,s,n){const{float32Array:r,uint16Array:o,uint32Array:a}=$,c=2*e;if(k(c,o)){!function(e,t,i,s,n,r){const{geometry:o,_indirectBuffer:a}=e;for(let e=s,a=s+n;e<a;e++)fe(o,t,i,e,r)}(t,i,s,H(e,a),W(c,o),n)}else{const o=X(e);Re(o,r,s,Ae)&&Se(o,t,i,s,n);const c=Z(e,a);Re(c,r,s,Ae)&&Se(c,t,i,s,n)}}const Oe=new i.Vector3,Ne=["x","y","z"];function ye(e,t,i,s){$.setBuffer(e._roots[t]);const n=_e(0,e,i,s);return $.clearBuffer(),n}function _e(e,t,i,s){const{float32Array:n,uint16Array:r,uint32Array:o}=$;let a=2*e;if(k(a,r)){return function(e,t,i,s,n){const{geometry:r,_indirectBuffer:o}=e;let a=1/0,c=null;for(let e=s,o=s+n;e<o;e++){let s;s=fe(r,t,i,e),s&&s.distance<a&&(c=s,a=s.distance)}return c}(t,i,s,H(e,o),W(a,r))}{const r=j(e,o),a=Ne[r],c=s.direction[a]>=0;let l,h;c?(l=X(e),h=Z(e,o)):(l=Z(e,o),h=X(e));const u=Re(l,n,s,Oe)?_e(l,t,i,s):null;if(u){const e=u.point[a];if(c?e<=n[h+r]:e>=n[h+r+3])return u}const I=Re(h,n,s,Oe)?_e(h,t,i,s):null;return u&&I?u.distance<=I.distance?u:I:u||I||null}}const Le=new i.Box3,Pe=new B,we=new B,Me=new i.Matrix4,ve=new V,De=new V;function xe(e,t,i,s){$.setBuffer(e._roots[t]);const n=be(0,e,i,s);return $.clearBuffer(),n}function be(e,t,i,s,n=null){const{float32Array:r,uint16Array:o,uint32Array:a}=$;let c=2*e;null===n&&(i.boundingBox||i.computeBoundingBox(),ve.set(i.boundingBox.min,i.boundingBox.max,s),n=ve);if(!k(c,o)){const o=e+8,c=a[e+6];C(o,r,Le);if(n.intersectsBox(Le)&&be(o,t,i,s,n))return!0;C(c,r,Le);return!!(n.intersectsBox(Le)&&be(c,t,i,s,n))}{const n=t.geometry,l=n.index,h=n.attributes.position,u=i.index,I=i.attributes.position,d=H(e,a),E=W(c,o);if(Me.copy(s).invert(),i.boundsTree){C(e,r,De),De.matrix.copy(Me),De.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:e=>De.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(s),e.b.applyMatrix4(s),e.c.applyMatrix4(s),e.needsUpdate=!0;for(let t=3*d,i=3*(E+d);t<i;t+=3)if(pe(we,t,l,h),we.needsUpdate=!0,e.intersectsTriangle(we))return!0;return!1}})}for(let e=3*d,t=3*(E+d);e<t;e+=3){pe(Pe,e,l,h),Pe.a.applyMatrix4(Me),Pe.b.applyMatrix4(Me),Pe.c.applyMatrix4(Me),Pe.needsUpdate=!0;for(let e=0,t=u.count;e<t;e+=3)if(pe(we,e,u,I),we.needsUpdate=!0,Pe.intersectsTriangle(we))return!0}}}const Ue=new i.Matrix4,Be=new V,Ve=new V,Ye=new i.Vector3,Ge=new i.Vector3,ze=new i.Vector3,ke=new i.Vector3;function He(e,t,i,s={},n={},r=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Be.set(t.boundingBox.min,t.boundingBox.max,i),Be.needsUpdate=!0;const a=e.geometry,c=a.attributes.position,l=a.index,h=t.attributes.position,u=t.index,I=z.getPrimitive(),E=z.getPrimitive();let f=Ye,p=Ge,C=null,T=null;n&&(C=ze,T=ke);let m=1/0,R=null,g=null;return Ue.copy(i).invert(),Ve.matrix.copy(Ue),e.shapecast({boundsTraverseOrder:e=>Be.distanceToBox(e),intersectsBounds:(e,t,i)=>i<m&&i<o&&(t&&(Ve.min.copy(e.min),Ve.max.copy(e.max),Ve.needsUpdate=!0),!0),intersectsRange:(e,s)=>{if(t.boundsTree){return t.boundsTree.shapecast({boundsTraverseOrder:e=>Ve.distanceToBox(e),intersectsBounds:(e,t,i)=>i<m&&i<o,intersectsRange:(t,n)=>{for(let o=t,a=t+n;o<a;o++){pe(E,3*o,u,h),E.a.applyMatrix4(i),E.b.applyMatrix4(i),E.c.applyMatrix4(i),E.needsUpdate=!0;for(let t=e,i=e+s;t<i;t++){pe(I,3*t,l,c),I.needsUpdate=!0;const e=I.distanceToTriangle(E,f,C);if(e<m&&(p.copy(f),T&&T.copy(C),m=e,R=t,g=o),e<r)return!0}}}})}for(let n=0,o=d(t);n<o;n++){pe(E,3*n,u,h),E.a.applyMatrix4(i),E.b.applyMatrix4(i),E.c.applyMatrix4(i),E.needsUpdate=!0;for(let t=e,i=e+s;t<i;t++){pe(I,3*t,l,c),I.needsUpdate=!0;const e=I.distanceToTriangle(E,f,C);if(e<m&&(p.copy(f),T&&T.copy(C),m=e,R=t,g=n),e<r)return!0}}}}),z.releasePrimitive(I),z.releasePrimitive(E),m===1/0?null:(s.point?s.point.copy(p):s.point=p.clone(),s.distance=m,s.faceIndex=R,n&&(n.point?n.point.copy(T):n.point=T.clone(),n.point.applyMatrix4(Ue),p.applyMatrix4(Ue),n.distance=p.sub(n.point).length(),n.faceIndex=g),s)}function We(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));const i=e.geometry,s=i.index?i.index.array:null,n=i.attributes.position;let r,o,a,c,l=0;const u=e._roots;for(let e=0,t=u.length;e<t;e++)r=u[e],o=new Uint32Array(r),a=new Uint16Array(r),c=new Float32Array(r),I(0,l),l+=r.byteLength;function I(i,r,l=!1){const u=2*i;if(a[u+15]===h){const t=o[i+6];let r=1/0,l=1/0,h=1/0,I=-1/0,d=-1/0,E=-1/0;for(let i=t,o=t+a[u+14];i<o;i++){const t=3*e.resolveTriangleIndex(i);for(let e=0;e<3;e++){let i=t+e;i=s?s[i]:i;const o=n.getX(i),a=n.getY(i),c=n.getZ(i);o<r&&(r=o),o>I&&(I=o),a<l&&(l=a),a>d&&(d=a),c<h&&(h=c),c>E&&(E=c)}}return(c[i+0]!==r||c[i+1]!==l||c[i+2]!==h||c[i+3]!==I||c[i+4]!==d||c[i+5]!==E)&&(c[i+0]=r,c[i+1]=l,c[i+2]=h,c[i+3]=I,c[i+4]=d,c[i+5]=E,!0)}{const e=i+8,s=o[i+6],n=e+r,a=s+r;let h=l,u=!1,d=!1;t?h||(u=t.has(n),d=t.has(a),h=!u&&!d):(u=!0,d=!0);const E=h||d;let f=!1;(h||u)&&(f=I(e,r,h));let p=!1;E&&(p=I(s,r,h));const C=f||p;if(C)for(let t=0;t<3;t++){const n=e+t,r=s+t,o=c[n],a=c[n+3],l=c[r],h=c[r+3];c[i+t]=o<l?o:l,c[i+t+3]=a>h?a:h}return C}}}const Xe=new i.Vector3;function Ze(e,t,i,s,n){$.setBuffer(e._roots[t]),je(0,e,i,s,n),$.clearBuffer()}function je(e,t,i,s,n){const{float32Array:r,uint16Array:o,uint32Array:a}=$,c=2*e;if(k(c,o)){!function(e,t,i,s,n,r){const{geometry:o,_indirectBuffer:a}=e;for(let e=s,c=s+n;e<c;e++)fe(o,t,i,a?a[e]:e,r)}(t,i,s,H(e,a),W(c,o),n)}else{const o=X(e);Re(o,r,s,Xe)&&je(o,t,i,s,n);const c=Z(e,a);Re(c,r,s,Xe)&&je(c,t,i,s,n)}}const $e=new i.Vector3,Qe=["x","y","z"];function qe(e,t,i,s){$.setBuffer(e._roots[t]);const n=Ke(0,e,i,s);return $.clearBuffer(),n}function Ke(e,t,i,s){const{float32Array:n,uint16Array:r,uint32Array:o}=$;let a=2*e;if(k(a,r)){return function(e,t,i,s,n){const{geometry:r,_indirectBuffer:o}=e;let a=1/0,c=null;for(let e=s,l=s+n;e<l;e++){let s;s=fe(r,t,i,o?o[e]:e),s&&s.distance<a&&(c=s,a=s.distance)}return c}(t,i,s,H(e,o),W(a,r))}{const r=j(e,o),a=Qe[r],c=s.direction[a]>=0;let l,h;c?(l=X(e),h=Z(e,o)):(l=Z(e,o),h=X(e));const u=Re(l,n,s,$e)?Ke(l,t,i,s):null;if(u){const e=u.point[a];if(c?e<=n[h+r]:e>=n[h+r+3])return u}const I=Re(h,n,s,$e)?Ke(h,t,i,s):null;return u&&I?u.distance<=I.distance?u:I:u||I||null}}const Je=new i.Box3,et=new B,tt=new B,it=new i.Matrix4,st=new V,nt=new V;function rt(e,t,i,s){$.setBuffer(e._roots[t]);const n=ot(0,e,i,s);return $.clearBuffer(),n}function ot(e,t,i,s,n=null){const{float32Array:r,uint16Array:o,uint32Array:a}=$;let c=2*e;null===n&&(i.boundingBox||i.computeBoundingBox(),st.set(i.boundingBox.min,i.boundingBox.max,s),n=st);if(!k(c,o)){const o=e+8,c=a[e+6];C(o,r,Je);if(n.intersectsBox(Je)&&ot(o,t,i,s,n))return!0;C(c,r,Je);return!!(n.intersectsBox(Je)&&ot(c,t,i,s,n))}{const n=t.geometry,l=n.index,h=n.attributes.position,u=i.index,I=i.attributes.position,d=H(e,a),E=W(c,o);if(it.copy(s).invert(),i.boundsTree){C(e,r,nt),nt.matrix.copy(it),nt.needsUpdate=!0;return i.boundsTree.shapecast({intersectsBounds:e=>nt.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(s),e.b.applyMatrix4(s),e.c.applyMatrix4(s),e.needsUpdate=!0;for(let i=d,s=E+d;i<s;i++)if(pe(tt,3*t.resolveTriangleIndex(i),l,h),tt.needsUpdate=!0,e.intersectsTriangle(tt))return!0;return!1}})}for(let e=d,i=E+d;e<i;e++){const i=t.resolveTriangleIndex(e);pe(et,3*i,l,h),et.a.applyMatrix4(it),et.b.applyMatrix4(it),et.c.applyMatrix4(it),et.needsUpdate=!0;for(let e=0,t=u.count;e<t;e+=3)if(pe(tt,e,u,I),tt.needsUpdate=!0,et.intersectsTriangle(tt))return!0}}}const at=new i.Matrix4,ct=new V,lt=new V,ht=new i.Vector3,ut=new i.Vector3,It=new i.Vector3,dt=new i.Vector3;function Et(e,t,i,s={},n={},r=0,o=1/0){t.boundingBox||t.computeBoundingBox(),ct.set(t.boundingBox.min,t.boundingBox.max,i),ct.needsUpdate=!0;const a=e.geometry,c=a.attributes.position,l=a.index,h=t.attributes.position,u=t.index,I=z.getPrimitive(),E=z.getPrimitive();let f=ht,p=ut,C=null,T=null;n&&(C=It,T=dt);let m=1/0,R=null,g=null;return at.copy(i).invert(),lt.matrix.copy(at),e.shapecast({boundsTraverseOrder:e=>ct.distanceToBox(e),intersectsBounds:(e,t,i)=>i<m&&i<o&&(t&&(lt.min.copy(e.min),lt.max.copy(e.max),lt.needsUpdate=!0),!0),intersectsRange:(s,n)=>{if(t.boundsTree){const a=t.boundsTree;return a.shapecast({boundsTraverseOrder:e=>lt.distanceToBox(e),intersectsBounds:(e,t,i)=>i<m&&i<o,intersectsRange:(t,o)=>{for(let d=t,A=t+o;d<A;d++){const t=a.resolveTriangleIndex(d);pe(E,3*t,u,h),E.a.applyMatrix4(i),E.b.applyMatrix4(i),E.c.applyMatrix4(i),E.needsUpdate=!0;for(let t=s,i=s+n;t<i;t++){const i=e.resolveTriangleIndex(t);pe(I,3*i,l,c),I.needsUpdate=!0;const s=I.distanceToTriangle(E,f,C);if(s<m&&(p.copy(f),T&&T.copy(C),m=s,R=t,g=d),s<r)return!0}}}})}for(let o=0,a=d(t);o<a;o++){pe(E,3*o,u,h),E.a.applyMatrix4(i),E.b.applyMatrix4(i),E.c.applyMatrix4(i),E.needsUpdate=!0;for(let t=s,i=s+n;t<i;t++){const i=e.resolveTriangleIndex(t);pe(I,3*i,l,c),I.needsUpdate=!0;const s=I.distanceToTriangle(E,f,C);if(s<m&&(p.copy(f),T&&T.copy(C),m=s,R=t,g=o),s<r)return!0}}}}),z.releasePrimitive(I),z.releasePrimitive(E),m===1/0?null:(s.point?s.point.copy(p):s.point=p.clone(),s.distance=m,s.faceIndex=R,n&&(n.point?n.point.copy(T):n.point=T.clone(),n.point.applyMatrix4(at),p.applyMatrix4(at),n.distance=p.sub(n.point).length(),n.faceIndex=g),s)}const ft=new $.constructor,pt=new $.constructor,Ct=new Y((()=>new i.Box3)),Tt=new i.Box3,mt=new i.Box3,Rt=new i.Box3,gt=new i.Box3;let At=!1;function Ft(e,t,i,s,n,r=0,o=0,a=0,c=0,l=null,h=!1){let u,I;h?(u=pt,I=ft):(u=ft,I=pt);const d=u.float32Array,E=u.uint32Array,f=u.uint16Array,p=I.float32Array,T=I.uint32Array,m=I.uint16Array,R=2*t,g=k(2*e,f),A=k(R,m);let F=!1;if(A&&g)F=h?n(H(t,T),W(2*t,m),H(e,E),W(2*e,f),c,o+t,a,r+e):n(H(e,E),W(2*e,f),H(t,T),W(2*t,m),a,r+e,c,o+t);else if(A){const l=Ct.getPrimitive();C(t,p,l),l.applyMatrix4(i);const u=X(e),I=Z(e,E);C(u,d,Tt),C(I,d,mt);const f=l.intersectsBox(Tt),T=l.intersectsBox(mt);F=f&&Ft(t,u,s,i,n,o,r,c,a+1,l,!h)||T&&Ft(t,I,s,i,n,o,r,c,a+1,l,!h),Ct.releasePrimitive(l)}else{const u=X(t),I=Z(t,T);C(u,p,Rt),C(I,p,gt);const f=l.intersectsBox(Rt),m=l.intersectsBox(gt);if(f&&m)F=Ft(e,u,i,s,n,r,o,a,c+1,l,h)||Ft(e,I,i,s,n,r,o,a,c+1,l,h);else if(f)if(g)F=Ft(e,u,i,s,n,r,o,a,c+1,l,h);else{const t=Ct.getPrimitive();t.copy(Rt).applyMatrix4(i);const l=X(e),I=Z(e,E);C(l,d,Tt),C(I,d,mt);const f=t.intersectsBox(Tt),p=t.intersectsBox(mt);F=f&&Ft(u,l,s,i,n,o,r,c,a+1,t,!h)||p&&Ft(u,I,s,i,n,o,r,c,a+1,t,!h),Ct.releasePrimitive(t)}else if(m)if(g)F=Ft(e,I,i,s,n,r,o,a,c+1,l,h);else{const t=Ct.getPrimitive();t.copy(gt).applyMatrix4(i);const l=X(e),u=Z(e,E);C(l,d,Tt),C(u,d,mt);const f=t.intersectsBox(Tt),p=t.intersectsBox(mt);F=f&&Ft(I,l,s,i,n,o,r,c,a+1,t,!h)||p&&Ft(I,u,s,i,n,o,r,c,a+1,t,!h),Ct.releasePrimitive(t)}}return F}const St=new V,Ot=new i.Box3;class Nt{static serialize(e,t={}){t={cloneBuffers:!0,...t};const i=e.geometry,s=e._roots,n=e._indirectBuffer,r=i.getIndex();let o;return o=t.cloneBuffers?{roots:s.map((e=>e.slice())),index:r.array.slice(),indirectBuffer:n?n.slice():null}:{roots:s,index:r.array,indirectBuffer:n},o}static deserialize(e,t,s={}){s={setIndex:!0,indirect:Boolean(e.indirectBuffer),...s};const{index:n,roots:r,indirectBuffer:o}=e,a=new Nt(t,{...s,[I]:!0});if(a._roots=r,a._indirectBuffer=o||null,s.setIndex){const s=t.getIndex();if(null===s){const s=new i.BufferAttribute(e.index,1,!1);t.setIndex(s)}else s.array!==n&&(s.array.set(n),s.needsUpdate=!0)}return a}get indirect(){return!!this._indirectBuffer}constructor(e,t={}){if(!e.isBufferGeometry)throw new Error("MeshBVH: Only BufferGeometries are supported.");if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.");if((t=Object.assign({strategy:0,maxDepth:40,maxLeafTris:10,verbose:!0,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,[I]:!1},t)).useSharedArrayBuffer&&"undefined"==typeof SharedArrayBuffer)throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[I]||(M(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new i.Box3)));const{_indirectBuffer:s}=this;this.resolveTriangleIndex=t.indirect?e=>s[e]:e=>e}refit(e=null){return(this.indirect?We:Te)(this,e)}traverse(e,t=0){const i=this._roots[t],s=new Uint32Array(i),n=new Uint16Array(i);!function t(r,o=0){const a=2*r,c=n[a+15]===h;if(c){const t=s[r+6],l=n[a+14];e(o,c,new Float32Array(i,4*r,6),t,l)}else{const n=r+8,a=s[r+6],l=s[r+7];e(o,c,new Float32Array(i,4*r,6),l)||(t(n,o+1),t(a,o+1))}}(0)}raycast(e,t=i.FrontSide){const s=this._roots,n=this.geometry,r=[],o=t.isMaterial,a=Array.isArray(t),c=n.groups,l=o?t.side:t,h=this.indirect?Ze:Fe;for(let i=0,n=s.length;i<n;i++){const s=a?t[c[i].materialIndex].side:l,n=r.length;if(h(this,i,s,e,r),a){const e=c[i].materialIndex;for(let t=n,i=r.length;t<i;t++)r[t].face.materialIndex=e}}return r}raycastFirst(e,t=i.FrontSide){const s=this._roots,n=this.geometry,r=t.isMaterial,o=Array.isArray(t);let a=null;const c=n.groups,l=r?t.side:t,h=this.indirect?qe:ye;for(let i=0,n=s.length;i<n;i++){const s=h(this,i,o?t[c[i].materialIndex].side:l,e);null!=s&&(null==a||s.distance<a.distance)&&(a=s,o&&(s.face.materialIndex=c[i].materialIndex))}return a}intersectsGeometry(e,t){let i=!1;const s=this._roots,n=this.indirect?rt:xe;for(let r=0,o=s.length;r<o&&(i=n(this,r,e,t),!i);r++);return i}shapecast(e){const t=z.getPrimitive(),i=this.indirect?ge:Ce;let{boundsTraverseOrder:s,intersectsBounds:n,intersectsRange:r,intersectsTriangle:o}=e;if(r&&o){const e=r;r=(s,n,r,a,c)=>!!e(s,n,r,a,c)||i(s,n,this,o,r,a,t)}else r||(r=o?(e,s,n,r)=>i(e,s,this,o,n,r,t):(e,t,i)=>i);let a=!1,c=0;const l=this._roots;for(let e=0,t=l.length;e<t;e++){const t=l[e];if(a=ee(this,e,n,r,s,c),a)break;c+=t.byteLength}return z.releasePrimitive(t),a}bvhcast(e,t,s){let{intersectsRanges:n,intersectsTriangles:r}=s;const o=z.getPrimitive(),a=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?e=>{const t=this.resolveTriangleIndex(e);pe(o,3*t,a,c)}:e=>{pe(o,3*e,a,c)},h=z.getPrimitive(),u=e.geometry.index,I=e.geometry.attributes.position,d=e.indirect?t=>{const i=e.resolveTriangleIndex(t);pe(h,3*i,u,I)}:e=>{pe(h,3*e,u,I)};if(r){const e=(e,i,s,n,a,c,u,I)=>{for(let E=s,f=s+n;E<f;E++){d(E),h.a.applyMatrix4(t),h.b.applyMatrix4(t),h.c.applyMatrix4(t),h.needsUpdate=!0;for(let t=e,s=e+i;t<s;t++)if(l(t),o.needsUpdate=!0,r(o,h,t,E,a,c,u,I))return!0}return!1};if(n){const t=n;n=function(i,s,n,r,o,a,c,l){return!!t(i,s,n,r,o,a,c,l)||e(i,s,n,r,o,a,c,l)}}else n=e}return function(e,t,s,n){if(At)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");At=!0;const r=e._roots,o=t._roots;let a,c=0,l=0;const h=(new i.Matrix4).copy(s).invert();for(let e=0,t=r.length;e<t;e++){ft.setBuffer(r[e]),l=0;const t=Ct.getPrimitive();C(0,ft.float32Array,t),t.applyMatrix4(h);for(let i=0,r=o.length;i<r&&(pt.setBuffer(o[e]),a=Ft(0,0,s,h,n,c,l,0,0,t),pt.clearBuffer(),l+=o[i].length,!a);i++);if(Ct.releasePrimitive(t),ft.clearBuffer(),c+=r[e].length,a)break}return At=!1,a}(this,e,t,n)}intersectsBox(e,t){return St.set(e.min,e.max,t),St.needsUpdate=!0,this.shapecast({intersectsBounds:e=>St.intersectsBox(e),intersectsTriangle:e=>St.intersectsTriangle(e)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,i={},s={},n=0,r=1/0){return(this.indirect?Et:He)(this,e,t,i,s,n,r)}closestPointToPoint(e,t={},i=0,s=1/0){return function(e,t,i={},s=0,n=1/0){const r=s*s,o=n*n;let a=1/0,c=null;if(e.shapecast({boundsTraverseOrder:e=>(ie.copy(t).clamp(e.min,e.max),ie.distanceToSquared(t)),intersectsBounds:(e,t,i)=>i<a&&i<o,intersectsTriangle:(e,i)=>{e.closestPointToPoint(t,ie);const s=t.distanceToSquared(ie);return s<a&&(se.copy(ie),a=s,c=i),s<r}}),a===1/0)return null;const l=Math.sqrt(a);return i.point?i.point.copy(se):i.point=se.clone(),i.distance=l,i.faceIndex=c,i}(this,e,t,i,s)}getBoundingBox(e){e.makeEmpty();return this._roots.forEach((t=>{C(0,new Float32Array(t),Ot),e.union(Ot)})),e}}function yt(e,t,i){return null===e?null:(e.point.applyMatrix4(t.matrixWorld),e.distance=e.point.distanceTo(i.ray.origin),e.object=t,e.distance<i.near||e.distance>i.far?null:e)}const _t=new i.Ray,Lt=new i.Matrix4,Pt=i.Mesh.prototype.raycast;function wt(e,t){if(this.geometry.boundsTree){if(void 0===this.material)return;Lt.copy(this.matrixWorld).invert(),_t.copy(e.ray).applyMatrix4(Lt);const i=this.geometry.boundsTree;if(!0===e.firstHitOnly){const s=yt(i.raycastFirst(_t,this.material),this,e);s&&t.push(s)}else{const s=i.raycast(_t,this.material);for(let i=0,n=s.length;i<n;i++){const n=yt(s[i],this,e);n&&t.push(n)}}}else Pt.call(this,e,t)}function Mt(e){return this.boundsTree=new Nt(this,e),this.boundsTree}function vt(){this.boundsTree=null}class Dt{constructor(){t(this,"enabled",!0),t(this,"trigger",(e=>{if(!this.enabled)return;const t=this.handlers.slice(0);for(const i of t)i(e)})),t(this,"handlers",[])}add(e){this.handlers.push(e)}remove(e){this.handlers=this.handlers.filter((t=>t!==e))}reset(){this.handlers.length=0}}class xt{constructor(){t(this,"enabled",!0),t(this,"trigger",(async e=>{if(!this.enabled)return;const t=this.handlers.slice(0);for(const i of t)await i(e)})),t(this,"handlers",[])}add(e){this.handlers.push(e)}remove(e){this.handlers=this.handlers.filter((t=>t!==e))}reset(){this.handlers.length=0}}class bt{constructor(e){t(this,"isDisposeable",(()=>"dispose"in this&&"onDisposed"in this)),t(this,"isResizeable",(()=>"resize"in this&&"getSize"in this)),t(this,"isUpdateable",(()=>"onAfterUpdate"in this&&"onBeforeUpdate"in this&&"update"in this)),t(this,"isHideable",(()=>"visible"in this)),t(this,"isConfigurable",(()=>"setup"in this&&"config"in this&&"onSetup"in this)),this.components=e}}class Ut extends bt{}class Bt extends bt{constructor(e){super(e),t(this,"worlds",new Map),t(this,"onWorldChanged",new Dt),t(this,"currentWorld",null),this.onWorldChanged.add((({world:e,action:t})=>{"removed"===t&&this.worlds.delete(e.uuid)}))}}class Vt extends Bt{constructor(){super(...arguments),t(this,"hasCameraControls",(()=>"controls"in this))}}class Yt extends Bt{constructor(){super(...arguments),t(this,"onAfterUpdate",new Dt),t(this,"onBeforeUpdate",new Dt),t(this,"onDisposed",new Dt),t(this,"onResize",new Dt),t(this,"onClippingPlanesUpdated",new Dt),t(this,"clippingPlanes",[])}updateClippingPlanes(){this.onClippingPlanesUpdated.trigger()}setPlane(e,t,i){t.isLocal=i;const s=this.clippingPlanes.indexOf(t);e&&-1===s?this.clippingPlanes.push(t):!e&&s>-1&&this.clippingPlanes.splice(s,1),this.three.clippingPlanes=this.clippingPlanes.filter((e=>!e.isLocal))}}const Gt=class e extends Ut{constructor(i){super(i),t(this,"_disposedComponents",new Set),t(this,"enabled",!0),i.add(e.uuid,this)}get(){return this._disposedComponents}destroy(e,t=!0,i=!0){e.removeFromParent();const s=e;s.dispose&&s.dispose(),this.disposeGeometryAndMaterials(e,t),i&&s.children&&s.children.length&&this.disposeChildren(s),e.children.length=0}disposeGeometry(e){e.boundsTree&&e.disposeBoundsTree&&e.disposeBoundsTree(),e.dispose()}disposeGeometryAndMaterials(t,i){const s=t;s.geometry&&this.disposeGeometry(s.geometry),i&&s.material&&e.disposeMaterial(s),s.material=[],s.geometry=null}disposeChildren(e){for(const t of e.children)this.destroy(t)}static disposeMaterial(e){if(e.material)if(Array.isArray(e.material))for(const t of e.material)t.dispose();else e.material.dispose()}};t(Gt,"uuid","76e9cd8e-ad8f-4753-9ef6-cbc60f7247fe");let zt=Gt;class kt extends Bt{constructor(e){super(e),t(this,"onDisposed",new Dt),t(this,"directionalLights",new Map),t(this,"ambientLights",new Map)}dispose(){const e=this.components.get(zt);for(const t of this.three.children){const i=t;i.geometry&&e.destroy(i)}this.deleteAllLights(),this.three.children=[],this.onDisposed.trigger(),this.onDisposed.reset()}deleteAllLights(){for(const[,e]of this.directionalLights)e.removeFromParent(),e.target.removeFromParent(),e.dispose();this.directionalLights.clear();for(const[,e]of this.ambientLights)e.removeFromParent(),e.dispose();this.ambientLights.clear()}}class Ht extends Set{constructor(e){super(e),t(this,"onItemAdded",new Dt),t(this,"onItemDeleted",new Dt),t(this,"onCleared",new Dt),t(this,"guard",(()=>!0))}clear(){super.clear(),this.onCleared.trigger()}add(...e){for(const t of e){if(this.has(t))continue;this.guard(t)&&(super.add(t),this.onItemAdded||(this.onItemAdded=new Dt),this.onItemAdded.trigger(t))}return this}delete(e){const t=super.delete(e);return t&&this.onItemDeleted.trigger(),t}dispose(){this.clear(),this.onItemAdded.reset(),this.onItemDeleted.reset(),this.onCleared.reset()}}class Wt extends Map{constructor(e){super(e),t(this,"onItemSet",new Dt),t(this,"onItemUpdated",new Dt),t(this,"onItemDeleted",new Dt),t(this,"onCleared",new Dt),t(this,"guard",(()=>!0))}clear(){super.clear(),this.onCleared.trigger()}set(e,t){const i=this.has(e);if(!(this.guard??(()=>!0))(e,t))return this;const s=super.set(e,t);return i?(this.onItemUpdated||(this.onItemUpdated=new Dt),this.onItemUpdated.trigger({key:e,value:t})):(this.onItemSet||(this.onItemSet=new Dt),this.onItemSet.trigger({key:e,value:t})),s}delete(e){const t=super.delete(e);return t&&this.onItemDeleted.trigger(e),t}dispose(){this.clear(),this.onItemSet.reset(),this.onItemDeleted.reset(),this.onCleared.reset()}}class Xt{static isEntry(e){return new Set(["Boolean","Color","Text","Number","Select","Vector3","TextSet","None"]).has(e.type)}static copySchema(e,t={}){for(const i in e){const s=e[i];this.isEntry(s)?t[i]=this.copyEntry(s):(t[i]={},this.copySchema(s,t[i]))}return t}static copyEntry(e){if("Boolean"===e.type){const t=e;return{type:t.type,value:t.value}}if("Color"===e.type){const t=e;return{type:t.type,value:t.value.clone()}}if("Text"===e.type){const t=e;return{type:t.type,value:t.value}}if("Number"===e.type){const t=e;return{type:t.type,value:t.value,min:t.min,max:t.max,interpolable:t.interpolable}}if("Select"===e.type){const t=e;return{type:t.type,value:t.value,multiple:t.multiple,options:new Set(t.options)}}if("Vector3"===e.type){const t=e;return{type:t.type,value:t.value.clone()}}if("TextSet"===e.type){const t=e;return{type:t.type,value:new Set(t.value)}}if("None"===e.type){const t=e;return{type:t.type,value:t.value}}throw new Error("Invalid entry!")}}const Zt=new i.Vector3,jt=new i.Line3,$t=new i.Plane,Qt=new i.Vector3,qt=new i.Triangle;class Kt{constructor(){this.tolerance=-1,this.faces=[],this.newFaces=[],this.assigned=new ii,this.unassigned=new ii,this.vertices=[]}setFromPoints(e){if(e.length>=4){this.makeEmpty();for(let t=0,i=e.length;t<i;t++)this.vertices.push(new ti(e[t]));this.compute()}return this}setFromObject(e){const t=[];return e.updateMatrixWorld(!0),e.traverse((function(e){const s=e.geometry;if(void 0!==s){const n=s.attributes.position;if(void 0!==n)for(let s=0,r=n.count;s<r;s++){const r=new i.Vector3;r.fromBufferAttribute(n,s).applyMatrix4(e.matrixWorld),t.push(r)}}})),this.setFromPoints(t)}containsPoint(e){const t=this.faces;for(let i=0,s=t.length;i<s;i++){if(t[i].distanceToPoint(e)>this.tolerance)return!1}return!0}intersectRay(e,t){const i=this.faces;let s=-1/0,n=1/0;for(let t=0,r=i.length;t<r;t++){const r=i[t],o=r.distanceToPoint(e.origin),a=r.normal.dot(e.direction);if(o>0&&a>=0)return null;const c=0!==a?-o/a:0;if(!(c<=0)&&(a>0?n=Math.min(c,n):s=Math.max(c,s),s>n))return null}return s!==-1/0?e.at(s,t):e.at(n,t),t}intersectsRay(e){return null!==this.intersectRay(e,Zt)}makeEmpty(){return this.faces=[],this.vertices=[],this}addVertexToFace(e,t){return e.face=t,null===t.outside?this.assigned.append(e):this.assigned.insertBefore(t.outside,e),t.outside=e,this}removeVertexFromFace(e,t){return e===t.outside&&(null!==e.next&&e.next.face===t?t.outside=e.next:t.outside=null),this.assigned.remove(e),this}removeAllVerticesFromFace(e){if(null!==e.outside){const t=e.outside;let i=e.outside;for(;null!==i.next&&i.next.face===e;)i=i.next;return this.assigned.removeSubList(t,i),t.prev=i.next=null,e.outside=null,t}}deleteFaceVertices(e,t){const i=this.removeAllVerticesFromFace(e);if(void 0!==i)if(void 0===t)this.unassigned.appendChain(i);else{let e=i;do{const i=e.next;t.distanceToPoint(e.point)>this.tolerance?this.addVertexToFace(e,t):this.unassigned.append(e),e=i}while(null!==e)}return this}resolveUnassignedPoints(e){if(!1===this.unassigned.isEmpty()){let t=this.unassigned.first();do{const i=t.next;let s=this.tolerance,n=null;for(let i=0;i<e.length;i++){const r=e[i];if(0===r.mark){const e=r.distanceToPoint(t.point);if(e>s&&(s=e,n=r),s>1e3*this.tolerance)break}}null!==n&&this.addVertexToFace(t,n),t=i}while(null!==t)}return this}computeExtremes(){const e=new i.Vector3,t=new i.Vector3,s=[],n=[];for(let e=0;e<3;e++)s[e]=n[e]=this.vertices[0];e.copy(this.vertices[0].point),t.copy(this.vertices[0].point);for(let i=0,r=this.vertices.length;i<r;i++){const r=this.vertices[i],o=r.point;for(let t=0;t<3;t++)o.getComponent(t)<e.getComponent(t)&&(e.setComponent(t,o.getComponent(t)),s[t]=r);for(let e=0;e<3;e++)o.getComponent(e)>t.getComponent(e)&&(t.setComponent(e,o.getComponent(e)),n[e]=r)}return this.tolerance=3*Number.EPSILON*(Math.max(Math.abs(e.x),Math.abs(t.x))+Math.max(Math.abs(e.y),Math.abs(t.y))+Math.max(Math.abs(e.z),Math.abs(t.z))),{min:s,max:n}}computeInitialHull(){const e=this.vertices,t=this.computeExtremes(),i=t.min,s=t.max;let n=0,r=0;for(let e=0;e<3;e++){const t=s[e].point.getComponent(e)-i[e].point.getComponent(e);t>n&&(n=t,r=e)}const o=i[r],a=s[r];let c,l;n=0,jt.set(o.point,a.point);for(let t=0,i=this.vertices.length;t<i;t++){const i=e[t];if(i!==o&&i!==a){jt.closestPointToPoint(i.point,!0,Qt);const e=Qt.distanceToSquared(i.point);e>n&&(n=e,c=i)}}n=-1,$t.setFromCoplanarPoints(o.point,a.point,c.point);for(let t=0,i=this.vertices.length;t<i;t++){const i=e[t];if(i!==o&&i!==a&&i!==c){const e=Math.abs($t.distanceToPoint(i.point));e>n&&(n=e,l=i)}}const h=[];if($t.distanceToPoint(l.point)<0){h.push(Jt.create(o,a,c),Jt.create(l,a,o),Jt.create(l,c,a),Jt.create(l,o,c));for(let e=0;e<3;e++){const t=(e+1)%3;h[e+1].getEdge(2).setTwin(h[0].getEdge(t)),h[e+1].getEdge(1).setTwin(h[t+1].getEdge(0))}}else{h.push(Jt.create(o,c,a),Jt.create(l,o,a),Jt.create(l,a,c),Jt.create(l,c,o));for(let e=0;e<3;e++){const t=(e+1)%3;h[e+1].getEdge(2).setTwin(h[0].getEdge((3-e)%3)),h[e+1].getEdge(0).setTwin(h[t+1].getEdge(1))}}for(let e=0;e<4;e++)this.faces.push(h[e]);for(let t=0,i=e.length;t<i;t++){const i=e[t];if(i!==o&&i!==a&&i!==c&&i!==l){n=this.tolerance;let e=null;for(let t=0;t<4;t++){const s=this.faces[t].distanceToPoint(i.point);s>n&&(n=s,e=this.faces[t])}null!==e&&this.addVertexToFace(i,e)}}return this}reindexFaces(){const e=[];for(let t=0;t<this.faces.length;t++){const i=this.faces[t];0===i.mark&&e.push(i)}return this.faces=e,this}nextVertexToAdd(){if(!1===this.assigned.isEmpty()){let e,t=0;const i=this.assigned.first().face;let s=i.outside;do{const n=i.distanceToPoint(s.point);n>t&&(t=n,e=s),s=s.next}while(null!==s&&s.face===i);return e}}computeHorizon(e,t,i,s){let n;this.deleteFaceVertices(i),i.mark=1,n=null===t?t=i.getEdge(0):t.next;do{const t=n.twin,i=t.face;0===i.mark&&(i.distanceToPoint(e)>this.tolerance?this.computeHorizon(e,t,i,s):s.push(n)),n=n.next}while(n!==t);return this}addAdjoiningFace(e,t){const i=Jt.create(e,t.tail(),t.head());return this.faces.push(i),i.getEdge(-1).setTwin(t.twin),i.getEdge(0)}addNewFaces(e,t){this.newFaces=[];let i=null,s=null;for(let n=0;n<t.length;n++){const r=t[n],o=this.addAdjoiningFace(e,r);null===i?i=o:o.next.setTwin(s),this.newFaces.push(o.face),s=o}return i.next.setTwin(s),this}addVertexToHull(e){const t=[];return this.unassigned.clear(),this.removeVertexFromFace(e,e.face),this.computeHorizon(e.point,null,e.face,t),this.addNewFaces(e,t),this.resolveUnassignedPoints(this.newFaces),this}cleanup(){return this.assigned.clear(),this.unassigned.clear(),this.newFaces=[],this}compute(){let e;for(this.computeInitialHull();void 0!==(e=this.nextVertexToAdd());)this.addVertexToHull(e);return this.reindexFaces(),this.cleanup(),this}}class Jt{constructor(){this.normal=new i.Vector3,this.midpoint=new i.Vector3,this.area=0,this.constant=0,this.outside=null,this.mark=0,this.edge=null}static create(e,t,i){const s=new Jt,n=new ei(e,s),r=new ei(t,s),o=new ei(i,s);return n.next=o.prev=r,r.next=n.prev=o,o.next=r.prev=n,s.edge=n,s.compute()}getEdge(e){let t=this.edge;for(;e>0;)t=t.next,e--;for(;e<0;)t=t.prev,e++;return t}compute(){const e=this.edge.tail(),t=this.edge.head(),i=this.edge.next.head();return qt.set(e.point,t.point,i.point),qt.getNormal(this.normal),qt.getMidpoint(this.midpoint),this.area=qt.getArea(),this.constant=this.normal.dot(this.midpoint),this}distanceToPoint(e){return this.normal.dot(e)-this.constant}}class ei{constructor(e,t){this.vertex=e,this.prev=null,this.next=null,this.twin=null,this.face=t}head(){return this.vertex}tail(){return this.prev?this.prev.vertex:null}length(){const e=this.head(),t=this.tail();return null!==t?t.point.distanceTo(e.point):-1}lengthSquared(){const e=this.head(),t=this.tail();return null!==t?t.point.distanceToSquared(e.point):-1}setTwin(e){return this.twin=e,e.twin=this,this}}class ti{constructor(e){this.point=e,this.prev=null,this.next=null,this.face=null}}class ii{constructor(){this.head=null,this.tail=null}first(){return this.head}last(){return this.tail}clear(){return this.head=this.tail=null,this}insertBefore(e,t){return t.prev=e.prev,t.next=e,null===t.prev?this.head=t:t.prev.next=t,e.prev=t,this}insertAfter(e,t){return t.prev=e,t.next=e.next,null===t.next?this.tail=t:t.next.prev=t,e.next=t,this}append(e){return null===this.head?this.head=e:this.tail.next=e,e.prev=this.tail,e.next=null,this.tail=e,this}appendChain(e){for(null===this.head?this.head=e:this.tail.next=e,e.prev=this.tail;null!==e.next;)e=e.next;return this.tail=e,this}remove(e){return null===e.prev?this.head=e.next:e.prev.next=e.next,null===e.next?this.tail=e.prev:e.next.prev=e.prev,this}removeSubList(e,t){return null===e.prev?this.head=t.next:e.prev.next=t.next,null===t.next?this.tail=e.prev:t.next.prev=e.prev,this}isEmpty(){return null===this.head}}const si=[2,2,1],ni=[1,0,0];function ri(e,t){return 3*e+t}function oi(e){const t=e.elements;let i=0;for(let e=0;e<3;e++){const s=t[ri(si[e],ni[e])];i+=2*s*s}return Math.sqrt(i)}function ai(e,t){let i=0,s=1;const n=e.elements;for(let e=0;e<3;e++){const t=Math.abs(n[ri(si[e],ni[e])]);t>i&&(i=t,s=e)}let r=1,o=0;const a=ni[s],c=si[s];if(Math.abs(n[ri(c,a)])>Number.EPSILON){const e=(n[ri(c,c)]-n[ri(a,a)])/2/n[ri(c,a)];let t;t=e<0?-1/(-e+Math.sqrt(1+e*e)):1/(e+Math.sqrt(1+e*e)),r=1/Math.sqrt(1+t*t),o=t*r}return t.identity(),t.elements[ri(a,a)]=r,t.elements[ri(c,c)]=r,t.elements[ri(c,a)]=o,t.elements[ri(a,c)]=-o,t}function ci(e,t){let i=0,s=0;t.unitary.identity(),t.diagonal.copy(e);const n=t.unitary,r=t.diagonal,a=new o.Matrix3,c=new o.Matrix3,l=Number.EPSILON*function(e){const t=e.elements;let i=0;for(let e=0;e<9;e++)i+=t[e]*t[e];return Math.sqrt(i)}(r);for(;s<10&&oi(r)>l;)ai(r,a),c.copy(a).transpose(),r.multiply(a),r.premultiply(c),n.multiply(a),++i>2&&(s++,i=0);return t}function li(e){const t=[];for(let i=0;i<e.length-2;i+=3){const s=e[i],n=e[i+1],r=e[i+2];t.push(new o.Vector3(s,n,r))}const i=new Kt;i.setFromPoints(t);const s={unitary:new o.Matrix3,diagonal:new o.Matrix3},n=i.faces,r=[],a=[];for(let e=0,t=n.length;e<t;e++){const t=n[e];let i=t.edge;r.length=0;do{r.push(i),i=i.next}while(i!==t.edge);for(let e=1,t=r.length-2;e<=t;e++){const t=r[0].vertex,i=r[e+0].vertex,s=r[e+1].vertex;a.push(t.point.x,t.point.y,t.point.z),a.push(i.point.x,i.point.y,i.point.z),a.push(s.point.x,s.point.y,s.point.z)}}const c=new o.Vector3,l=new o.Vector3,h=new o.Vector3,u=new o.Vector3,I=new o.Vector3,d=new o.Vector3,E=new o.Vector3,f=new o.Vector3;let p=0,C=0,T=0,m=0,R=0,g=0,A=0;for(let e=0,t=a.length;e<t;e+=9){c.fromArray(a,e),l.fromArray(a,e+3),h.fromArray(a,e+6),E.set(0,0,0),E.add(c).add(l).add(h).divideScalar(3),u.subVectors(l,c),I.subVectors(h,c);const t=d.crossVectors(u,I).length()/2;f.add(d.copy(E).multiplyScalar(t)),p+=t,C+=(9*E.x*E.x+c.x*c.x+l.x*l.x+h.x*h.x)*(t/12),T+=(9*E.x*E.y+c.x*c.y+l.x*l.y+h.x*h.y)*(t/12),m+=(9*E.x*E.z+c.x*c.z+l.x*l.z+h.x*h.z)*(t/12),R+=(9*E.y*E.y+c.y*c.y+l.y*l.y+h.y*h.y)*(t/12),g+=(9*E.y*E.z+c.y*c.z+l.y*l.z+h.y*h.z)*(t/12),A+=(9*E.z*E.z+c.z*c.z+l.z*l.z+h.z*h.z)*(t/12)}f.divideScalar(p),C/=p,T/=p,m/=p,R/=p,g/=p,A/=p,C-=f.x*f.x,T-=f.x*f.y,m-=f.x*f.z,R-=f.y*f.y,g-=f.y*f.z,A-=f.z*f.z;const F=new o.Matrix3;F.elements[0]=C,F.elements[1]=T,F.elements[2]=m,F.elements[3]=T,F.elements[4]=R,F.elements[5]=g,F.elements[6]=m,F.elements[7]=g,F.elements[8]=A,ci(F,s);const S=s.unitary,O=new o.Vector3,N=new o.Vector3,y=new o.Vector3;S.extractBasis(O,N,y);let _=-1/0,L=-1/0,P=-1/0,w=1/0,M=1/0,v=1/0;for(let e=0,i=t.length;e<i;e++){const i=t[e];_=Math.max(O.dot(i),_),L=Math.max(N.dot(i),L),P=Math.max(y.dot(i),P),w=Math.min(O.dot(i),w),M=Math.min(N.dot(i),M),v=Math.min(y.dot(i),v)}O.multiplyScalar(.5*(w+_)),N.multiplyScalar(.5*(M+L)),y.multiplyScalar(.5*(v+P));const D=new o.Vector3,x=new o.Vector3,b=new o.Matrix3;D.add(O).add(N).add(y),x.x=_-w,x.y=L-M,x.z=P-v,x.multiplyScalar(.5),b.copy(S);const{x:U,y:B,z:V}=x,Y=new o.Matrix4;Y.makeScale(2*U,2*B,2*V);const G=new o.Matrix4;G.makeTranslation(-U,-B,-V);const z=new o.Matrix4;z.makeTranslation(D.x,D.y,D.z);const k=new o.Matrix4;k.setFromMatrix3(b);const H=new o.Matrix4;return H.multiply(z),H.multiply(k),H.multiply(G),H.multiply(Y),{center:D,halfSizes:x,rotation:b,transformation:H}}class hi{static isTransparent(e){return e.transparent&&e.opacity<1}}const ui=class e{static create(){const t=4294967295*Math.random()|0,i=4294967295*Math.random()|0,s=4294967295*Math.random()|0,n=4294967295*Math.random()|0;return`${e._lut[255&t]+e._lut[t>>8&255]+e._lut[t>>16&255]+e._lut[t>>24&255]}-${e._lut[255&i]}${e._lut[i>>8&255]}-${e._lut[i>>16&15|64]}${e._lut[i>>24&255]}-${e._lut[63&s|128]}${e._lut[s>>8&255]}-${e._lut[s>>16&255]}${e._lut[s>>24&255]}${e._lut[255&n]}${e._lut[n>>8&255]}${e._lut[n>>16&255]}${e._lut[n>>24&255]}`.toLowerCase()}static validate(t){if(!e._pattern.test(t))throw new Error(`${t} is not a valid UUID v4.\n\n- If you're the tool creator, you can take one from https://www.uuidgenerator.net/.\n\n- If you're using a platform tool, verify the uuid isn't misspelled or contact the tool creator.`)}};t(ui,"_pattern",/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/),t(ui,"_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 Ii=ui;var di="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Ei(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var fi={exports:{}};function pi(e,t,i){i=i||2;var s,n,r,o,a,c,l,h=t&&t.length,u=h?t[0]*i:e.length,I=Ci(e,0,u,i,!0),d=[];if(!I||I.next===I.prev)return d;if(h&&(I=function(e,t,i,s){var n,r,o,a=[];for(n=0,r=t.length;n<r;n++)(o=Ci(e,t[n]*s,n<r-1?t[n+1]*s:e.length,s,!1))===o.next&&(o.steiner=!0),a.push(_i(o));for(a.sort(Si),n=0;n<a.length;n++)i=Oi(a[n],i);return i}(e,t,I,i)),e.length>80*i){s=r=e[0],n=o=e[1];for(var E=i;E<u;E+=i)(a=e[E])<s&&(s=a),(c=e[E+1])<n&&(n=c),a>r&&(r=a),c>o&&(o=c);l=0!==(l=Math.max(r-s,o-n))?32767/l:0}return mi(I,d,i,s,n,l,0),d}function Ci(e,t,i,s,n){var r,o;if(n===Gi(e,t,i,s)>0)for(r=t;r<i;r+=s)o=Bi(r,e[r],e[r+1],o);else for(r=i-s;r>=t;r-=s)o=Bi(r,e[r],e[r+1],o);return o&&Mi(o,o.next)&&(Vi(o),o=o.next),o}function Ti(e,t){if(!e)return e;t||(t=e);var i,s=e;do{if(i=!1,s.steiner||!Mi(s,s.next)&&0!==wi(s.prev,s,s.next))s=s.next;else{if(Vi(s),(s=t=s.prev)===s.next)break;i=!0}}while(i||s!==t);return t}function mi(e,t,i,s,n,r,o){if(e){!o&&r&&function(e,t,i,s){var n=e;do{0===n.z&&(n.z=yi(n.x,n.y,t,i,s)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next}while(n!==e);n.prevZ.nextZ=null,n.prevZ=null,function(e){var t,i,s,n,r,o,a,c,l=1;do{for(i=e,e=null,r=null,o=0;i;){for(o++,s=i,a=0,t=0;t<l&&(a++,s=s.nextZ);t++);for(c=l;a>0||c>0&&s;)0!==a&&(0===c||!s||i.z<=s.z)?(n=i,i=i.nextZ,a--):(n=s,s=s.nextZ,c--),r?r.nextZ=n:e=n,n.prevZ=r,r=n;i=s}r.nextZ=null,l*=2}while(o>1)}(n)}(e,s,n,r);for(var a,c,l=e;e.prev!==e.next;)if(a=e.prev,c=e.next,r?gi(e,s,n,r):Ri(e))t.push(a.i/i|0),t.push(e.i/i|0),t.push(c.i/i|0),Vi(e),e=c.next,l=c.next;else if((e=c)===l){o?1===o?mi(e=Ai(Ti(e),t,i),t,i,s,n,r,2):2===o&&Fi(e,t,i,s,n,r):mi(Ti(e),t,i,s,n,r,1);break}}}function Ri(e){var t=e.prev,i=e,s=e.next;if(wi(t,i,s)>=0)return!1;for(var n=t.x,r=i.x,o=s.x,a=t.y,c=i.y,l=s.y,h=n<r?n<o?n:o:r<o?r:o,u=a<c?a<l?a:l:c<l?c:l,I=n>r?n>o?n:o:r>o?r:o,d=a>c?a>l?a:l:c>l?c:l,E=s.next;E!==t;){if(E.x>=h&&E.x<=I&&E.y>=u&&E.y<=d&&Li(n,a,r,c,o,l,E.x,E.y)&&wi(E.prev,E,E.next)>=0)return!1;E=E.next}return!0}function gi(e,t,i,s){var n=e.prev,r=e,o=e.next;if(wi(n,r,o)>=0)return!1;for(var a=n.x,c=r.x,l=o.x,h=n.y,u=r.y,I=o.y,d=a<c?a<l?a:l:c<l?c:l,E=h<u?h<I?h:I:u<I?u:I,f=a>c?a>l?a:l:c>l?c:l,p=h>u?h>I?h:I:u>I?u:I,C=yi(d,E,t,i,s),T=yi(f,p,t,i,s),m=e.prevZ,R=e.nextZ;m&&m.z>=C&&R&&R.z<=T;){if(m.x>=d&&m.x<=f&&m.y>=E&&m.y<=p&&m!==n&&m!==o&&Li(a,h,c,u,l,I,m.x,m.y)&&wi(m.prev,m,m.next)>=0)return!1;if(m=m.prevZ,R.x>=d&&R.x<=f&&R.y>=E&&R.y<=p&&R!==n&&R!==o&&Li(a,h,c,u,l,I,R.x,R.y)&&wi(R.prev,R,R.next)>=0)return!1;R=R.nextZ}for(;m&&m.z>=C;){if(m.x>=d&&m.x<=f&&m.y>=E&&m.y<=p&&m!==n&&m!==o&&Li(a,h,c,u,l,I,m.x,m.y)&&wi(m.prev,m,m.next)>=0)return!1;m=m.prevZ}for(;R&&R.z<=T;){if(R.x>=d&&R.x<=f&&R.y>=E&&R.y<=p&&R!==n&&R!==o&&Li(a,h,c,u,l,I,R.x,R.y)&&wi(R.prev,R,R.next)>=0)return!1;R=R.nextZ}return!0}function Ai(e,t,i){var s=e;do{var n=s.prev,r=s.next.next;!Mi(n,r)&&vi(n,s,s.next,r)&&bi(n,r)&&bi(r,n)&&(t.push(n.i/i|0),t.push(s.i/i|0),t.push(r.i/i|0),Vi(s),Vi(s.next),s=e=r),s=s.next}while(s!==e);return Ti(s)}function Fi(e,t,i,s,n,r){var o=e;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&Pi(o,a)){var c=Ui(o,a);return o=Ti(o,o.next),c=Ti(c,c.next),mi(o,t,i,s,n,r,0),void mi(c,t,i,s,n,r,0)}a=a.next}o=o.next}while(o!==e)}function Si(e,t){return e.x-t.x}function Oi(e,t){var i=function(e,t){var i,s=t,n=e.x,r=e.y,o=-1/0;do{if(r<=s.y&&r>=s.next.y&&s.next.y!==s.y){var a=s.x+(r-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(a<=n&&a>o&&(o=a,i=s.x<s.next.x?s:s.next,a===n))return i}s=s.next}while(s!==t);if(!i)return null;var c,l=i,h=i.x,u=i.y,I=1/0;s=i;do{n>=s.x&&s.x>=h&&n!==s.x&&Li(r<u?n:o,r,h,u,r<u?o:n,r,s.x,s.y)&&(c=Math.abs(r-s.y)/(n-s.x),bi(s,e)&&(c<I||c===I&&(s.x>i.x||s.x===i.x&&Ni(i,s)))&&(i=s,I=c)),s=s.next}while(s!==l);return i}(e,t);if(!i)return t;var s=Ui(i,e);return Ti(s,s.next),Ti(i,i.next)}function Ni(e,t){return wi(e.prev,e,t.prev)<0&&wi(t.next,e,e.next)<0}function yi(e,t,i,s,n){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*n|0)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-s)*n|0)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function _i(e){var t=e,i=e;do{(t.x<i.x||t.x===i.x&&t.y<i.y)&&(i=t),t=t.next}while(t!==e);return i}function Li(e,t,i,s,n,r,o,a){return(n-o)*(t-a)>=(e-o)*(r-a)&&(e-o)*(s-a)>=(i-o)*(t-a)&&(i-o)*(r-a)>=(n-o)*(s-a)}function Pi(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){var i=e;do{if(i.i!==e.i&&i.next.i!==e.i&&i.i!==t.i&&i.next.i!==t.i&&vi(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}(e,t)&&(bi(e,t)&&bi(t,e)&&function(e,t){var i=e,s=!1,n=(e.x+t.x)/2,r=(e.y+t.y)/2;do{i.y>r!=i.next.y>r&&i.next.y!==i.y&&n<(i.next.x-i.x)*(r-i.y)/(i.next.y-i.y)+i.x&&(s=!s),i=i.next}while(i!==e);return s}(e,t)&&(wi(e.prev,e,t.prev)||wi(e,t.prev,t))||Mi(e,t)&&wi(e.prev,e,e.next)>0&&wi(t.prev,t,t.next)>0)}function wi(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function Mi(e,t){return e.x===t.x&&e.y===t.y}function vi(e,t,i,s){var n=xi(wi(e,t,i)),r=xi(wi(e,t,s)),o=xi(wi(i,s,e)),a=xi(wi(i,s,t));return n!==r&&o!==a||(!(0!==n||!Di(e,i,t))||(!(0!==r||!Di(e,s,t))||(!(0!==o||!Di(i,e,s))||!(0!==a||!Di(i,t,s)))))}function Di(e,t,i){return t.x<=Math.max(e.x,i.x)&&t.x>=Math.min(e.x,i.x)&&t.y<=Math.max(e.y,i.y)&&t.y>=Math.min(e.y,i.y)}function xi(e){return e>0?1:e<0?-1:0}function bi(e,t){return wi(e.prev,e,e.next)<0?wi(e,t,e.next)>=0&&wi(e,e.prev,t)>=0:wi(e,t,e.prev)<0||wi(e,e.next,t)<0}function Ui(e,t){var i=new Yi(e.i,e.x,e.y),s=new Yi(t.i,t.x,t.y),n=e.next,r=t.prev;return e.next=t,t.prev=e,i.next=n,n.prev=i,s.next=i,i.prev=s,r.next=s,s.prev=r,s}function Bi(e,t,i,s){var n=new Yi(e,t,i);return s?(n.next=s.next,n.prev=s,s.next.prev=n,s.next=n):(n.prev=n,n.next=n),n}function Vi(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function Yi(e,t,i){this.i=e,this.x=t,this.y=i,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function Gi(e,t,i,s){for(var n=0,r=t,o=i-s;r<i;r+=s)n+=(e[o]-e[r])*(e[r+1]+e[o+1]),o=r;return n}fi.exports=pi,fi.exports.default=pi,pi.deviation=function(e,t,i,s){var n=t&&t.length,r=n?t[0]*i:e.length,o=Math.abs(Gi(e,0,r,i));if(n)for(var a=0,c=t.length;a<c;a++){var l=t[a]*i,h=a<c-1?t[a+1]*i:e.length;o-=Math.abs(Gi(e,l,h,i))}var u=0;for(a=0;a<s.length;a+=3){var I=s[a]*i,d=s[a+1]*i,E=s[a+2]*i;u+=Math.abs((e[I]-e[E])*(e[d+1]-e[I+1])-(e[I]-e[d])*(e[E+1]-e[I+1]))}return 0===o&&0===u?0:Math.abs((u-o)/o)},pi.flatten=function(e){for(var t=e[0][0].length,i={vertices:[],holes:[],dimensions:t},s=0,n=0;n<e.length;n++){for(var r=0;r<e[n].length;r++)for(var o=0;o<t;o++)i.vertices.push(e[n][r][o]);n>0&&(s+=e[n-1].length,i.holes.push(s))}return i};const zi=Ei(fi.exports);class ki extends Ut{constructor(){super(...arguments),t(this,"enabled",!0),t(this,"_inverseMatrix",new o.Matrix4),t(this,"_localPlane",new o.Plane),t(this,"_tempLine",new o.Line3),t(this,"_tempVector",new o.Vector3),t(this,"_plane"),t(this,"_plane2DCoordinateSystem",new o.Matrix4),t(this,"_precission",1e4),t(this,"_planeAxis")}get plane(){if(!this._plane)throw new Error("Plane not set");return this._plane}set plane(e){this._plane=e}createEdges(e){const{meshes:t,posAttr:i}=e;let s=0;i.array.fill(0);const n=[];let r=0;const a=new o.Mesh;for(const e of t)if(e.geometry){if(e.geometry.boundsTree||e.geometry.computeBoundsTree(),!e.geometry.boundsTree)throw new Error("Bounds tree not found for edges generation.");if(e instanceof o.InstancedMesh){if(0===e.count)continue;const t=e;for(let c=0;c<t.count;c++){a.geometry=e.geometry,a.matrix.copy(e.matrix);const l=new o.Matrix4;t.getMatrixAt(c,l),a.applyMatrix4(l),a.applyMatrix4(e.matrixWorld),a.updateMatrix(),a.updateMatrixWorld(),this._inverseMatrix.copy(a.matrixWorld).invert(),this._localPlane.copy(this.plane).applyMatrix4(this._inverseMatrix),s=this.shapecast(a,i,s),s!==r&&(n.push(s),r=s)}}else this._inverseMatrix.copy(e.matrixWorld).invert(),this._localPlane.copy(this.plane).applyMatrix4(this._inverseMatrix),s=this.shapecast(e,i,s),s!==r&&(n.push(s),r=s)}return{indexes:n,index:s}}createFills(e,t){this.updatePlane2DCoordinateSystem();const i=[];let s=0;for(let n=0;n<t.length;n++){const r=t[n],o=[];for(let e=s;e<r;e+=2)o.push(3*e);const a=this.computeFill(o,e);for(const e of a)i.push(e);s=r}return i}computeFill(e,t){const i=new Map,s={},n=new Map;let r=0;const o=new Map,a=new Map,c=new Set,l=this._precission;for(let h=0;h<e.length;h++){const u=e[h];let I=0,d=0,E=0,f=0;const p=t[u],C=t[u+1],T=t[u+2],m=t[u+3],R=t[u+4],g=t[u+5];if(this._tempVector.set(p,C,T),this._tempVector.applyMatrix4(this._plane2DCoordinateSystem),I=Math.trunc(this._tempVector.x*l)/l,d=Math.trunc(this._tempVector.y*l)/l,this._tempVector.set(m,R,g),this._tempVector.applyMatrix4(this._plane2DCoordinateSystem),E=Math.trunc(this._tempVector.x*l)/l,f=Math.trunc(this._tempVector.y*l)/l,I===E&&d===f)continue;const A=`${I}|${d}`,F=`${E}|${f}`;i.has(A)||i.set(A,u/3),i.has(F)||i.set(F,u/3+1);const S=i.get(A),O=i.get(F);s[S]=[I,d],s[O]=[E,f];const N=a.has(S),y=o.has(S),_=a.has(O),L=o.has(O);if(!(N||y||_||L))a.set(S,r),o.set(O,r),c.add(r),n.set(r,[S,O]),r++;else if(N&&L){const e=a.get(S),t=o.get(O);if(e!==t){const i=n.get(t),s=n.get(e);if(!i||!s)continue;n.delete(e),c.delete(e),o.set(s[s.length-1],t),o.delete(i[i.length-1]);for(const e of s)i.push(e)}else c.delete(t);a.delete(S),o.delete(O)}else if(y&&_){const e=a.get(O),t=o.get(S);if(e!==t){const i=n.get(t),s=n.get(e);if(!i||!s)continue;n.delete(e),c.delete(e),o.set(s[s.length-1],t),o.delete(i[i.length-1]);for(const e of s)i.push(e)}else c.delete(t);a.delete(O),o.delete(S)}else if(N&&_){const e=a.get(O),t=a.get(S),i=n.get(t),s=n.get(e);if(!i||!s)continue;n.delete(e),c.delete(e),a.delete(i[0]),a.delete(s[0]),o.delete(s[s.length-1]),a.set(s[s.length-1],t),s.reverse(),i.splice(0,0,...s)}else if(y&&L){const e=o.get(O),t=o.get(S),i=n.get(t),s=n.get(e);if(!i||!s)continue;n.delete(e),c.delete(e),o.delete(i[i.length-1]),o.delete(s[s.length-1]),a.delete(s[0]),o.set(s[0],t),s.reverse(),i.push(...s)}else if(N){const e=a.get(S),t=n.get(e);if(!t)continue;t.unshift(O),a.delete(S),a.set(O,e)}else if(y){const e=o.get(S),t=n.get(e);if(!t)continue;t.push(O),o.delete(S),o.set(O,e)}else if(_){const e=a.get(O),t=n.get(e);if(!t)continue;t.unshift(S),a.delete(O),a.set(S,e)}else if(L){const e=o.get(O),t=n.get(e);if(!t)continue;t.push(S),o.delete(O),o.set(S,e)}}const h=[];for(const[e,t]of n){if(c.has(e))continue;const i=[],n=new Map;let r=0;for(const e of t){const t=s[e];i.push(t[0],t[1]),n.set(r++,e)}const o=zi(i);for(const e of o){const t=n.get(e);if(void 0===t)throw new Error("Map error!");h.push(t)}}return h}updatePlane2DCoordinateSystem(){this._plane2DCoordinateSystem=new o.Matrix4;const e=new o.Vector3(1,0,0),t=new o.Vector3(0,1,0),i=this.plane.normal,s=new o.Vector3;this.plane.coplanarPoint(s),"x"===this._planeAxis?e.crossVectors(t,i):"y"===this._planeAxis?t.crossVectors(i,e):"z"===this._planeAxis||(e.crossVectors(t,i).normalize(),t.crossVectors(i,e)),this._plane2DCoordinateSystem.fromArray([e.x,e.y,e.z,0,t.x,t.y,t.z,0,i.x,i.y,i.z,0,s.x,s.y,s.z,1]),this._plane2DCoordinateSystem.invert()}shapecast(e,t,i){return e.geometry.boundsTree.shapecast({intersectsBounds:e=>this._localPlane.intersectsBox(e),intersectsTriangle:s=>{let n=0;if(this._tempLine.start.copy(s.a),this._tempLine.end.copy(s.b),this._localPlane.intersectLine(this._tempLine,this._tempVector)){const s=this._tempVector.applyMatrix4(e.matrixWorld);t.setXYZ(i,s.x,s.y,s.z),n++,i++}if(this._tempLine.start.copy(s.b),this._tempLine.end.copy(s.c),this._localPlane.intersectLine(this._tempLine,this._tempVector)){const s=this._tempVector.applyMatrix4(e.matrixWorld);t.setXYZ(i,s.x,s.y,s.z),n++,i++}if(this._tempLine.start.copy(s.c),this._tempLine.end.copy(s.a),this._localPlane.intersectLine(this._tempLine,this._tempVector)){const s=this._tempVector.applyMatrix4(e.matrixWorld);t.setXYZ(i,s.x,s.y,s.z),n++,i++}2!==n&&(i-=n)}}),i}}t(ki,"uuid","1a193b87-6376-46c8-9e65-62a1576fdb64");const Hi=class e{constructor(){t(this,"onDisposed",new Dt),t(this,"list",new Map),t(this,"enabled",!1),t(this,"_clock"),t(this,"onInit",new Dt),t(this,"update",(()=>{if(!this.enabled)return;const e=this._clock.getDelta();for(const[t,i]of this.list)i.enabled&&i.isUpdateable()&&i.update(e);requestAnimationFrame(this.update)})),this._clock=new o.Clock,e.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.");Ii.validate(e),this.list.set(e,t)}get(e){const t=e.uuid;if(!this.list.has(t)){const i=new e(this);return this.list.has(t)||this.add(t,i),i}return this.list.get(t)}init(){this.enabled=!0,this._clock.start(),this.update(),this.onInit.trigger()}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(){o.BufferGeometry.prototype.computeBoundsTree=Mt,o.BufferGeometry.prototype.disposeBoundsTree=vt,o.Mesh.prototype.raycast=wt}};t(Hi,"release","2.4.6");let Wi=Hi;class Xi extends bt{constructor(){super(...arguments),t(this,"meshes",new Set),t(this,"onAfterUpdate",new Dt),t(this,"onBeforeUpdate",new Dt),t(this,"onDisposed",new Dt),t(this,"isDisposing",!1),t(this,"enabled",!0),t(this,"uuid",Ii.create()),t(this,"name"),t(this,"_scene"),t(this,"_camera"),t(this,"_renderer",null)}get scene(){if(!this._scene)throw new Error("No scene initialized!");return this._scene}set scene(e){this._scene=e,e.worlds.set(this.uuid,this),e.currentWorld=this,e.onWorldChanged.trigger({world:this,action:"added"})}get camera(){if(!this._camera)throw new Error("No camera initialized!");return this._camera}set camera(e){this._camera=e,e.worlds.set(this.uuid,this),e.currentWorld=this,e.onWorldChanged.trigger({world:this,action:"added"})}get renderer(){return this._renderer}set renderer(e){this._renderer=e,e&&(e.worlds.set(this.uuid,this),e.currentWorld=this,e.onWorldChanged.trigger({world:this,action:"added"}))}update(e){this.enabled&&this._scene&&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(e),this.camera.isUpdateable()&&this.camera.update(e),this.renderer&&this.renderer.update(e),this.onAfterUpdate.trigger())}dispose(e=!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"}),e){const e=this.components.get(zt);this.scene.dispose(),this.camera.isDisposeable()&&this.camera.dispose(),this.renderer&&this.renderer.dispose();for(const t of this.meshes)e.destroy(t);this.meshes.clear()}this._scene=null,this._camera=null,this._renderer=null;this.components.get(Js).list.delete(this.uuid),this.onDisposed.trigger(),this.onDisposed.reset()}}class Zi{constructor(e,i,s,n){t(this,"_component"),t(this,"name"),t(this,"uuid"),this._component=e,this.name=s,this.uuid=n??Ii.create();i.get($i).list.set(this.uuid,this)}get controls(){return Xt.copySchema(this._config)}set(e){for(const t in e)if(t in this){this[t]=e[t].value}}export(e=this._config,t={}){for(const i in e){const s=e[i];if(Xt.isEntry(s))if("Color"===s.type){const{r:e,g:n,b:r}=s.value;t[i]={...s,value:{r:e,g:n,b:r}}}else if("Vector3"===s.type){const{x:e,y:n,z:r}=s.value;t[i]={...s,value:{x:e,y:n,z:r}}}else if("TextSet"===s.type){const e=Array.from(s.value);t[i]={...s,value:e}}else if("Select"===s.type){const e=Array.from(s.options);t[i]={...s,options:e}}else t[i]={...s};else t[i]={},this.export(s,t[i])}return t}import(e,t={},i=!0){for(const i in e){const s=e[i];if(Xt.isEntry(s))if("Color"===s.type){const{r:e,g:n,b:r}=s.value;t[i]={...s,value:new o.Color(e,n,r)}}else if("Vector3"===s.type){const{x:e,y:n,z:r}=s.value;t[i]={...s,value:new o.Vector3(e,n,r)}}else"TextSet"===s.type?t[i]={...s,value:new Set(s.value)}:"Select"===s.type?t[i]={...s,options:new Set(s.options)}:t[i]={...s};else t[i]={},this.import(s,t[i],!1)}i&&this.set(t)}}const ji=class e extends Ut{constructor(i){super(i),t(this,"list",new Wt),t(this,"enabled",!0),i.add(e.uuid,this)}};t(ji,"uuid","b8c764e0-6b24-4e77-9a32-35fa728ee5b4");let $i=ji;class Qi{constructor(e,i){t(this,"_list"),t(this,"_scene"),this._list=e,this._scene=i}get color(){return this._list.directionalLight.color.value}set color(e){this._list.directionalLight.color.value=e;for(const[,t]of this._scene.directionalLights)t.color.copy(e)}get intensity(){return this._list.directionalLight.intensity.value}set intensity(e){this._list.directionalLight.intensity.value=e;for(const[,t]of this._scene.directionalLights)t.intensity=e}get position(){return this._list.directionalLight.position.value.clone()}set position(e){this._list.directionalLight.position.value=e;for(const[,t]of this._scene.directionalLights)t.position.copy(e)}}class qi{constructor(e,i){t(this,"_list"),t(this,"_scene"),this._list=e,this._scene=i}get color(){return this._list.ambientLight.color.value}set color(e){this._list.ambientLight.color.value=e;for(const[,t]of this._scene.ambientLights)t.color.copy(e)}get intensity(){return this._list.ambientLight.intensity.value}set intensity(e){this._list.ambientLight.intensity.value=e;for(const[,t]of this._scene.ambientLights)t.intensity=e}}class Ki extends Zi{constructor(){super(...arguments),t(this,"_config",{backgroundColor:{value:new o.Color,type:"Color"},ambientLight:{color:{type:"Color",value:new o.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2}},directionalLight:{color:{type:"Color",value:new o.Color},intensity:{type:"Number",interpolable:!0,min:0,max:10,value:2},position:{type:"Vector3",value:new o.Vector3}}}),t(this,"ambientLight",new qi(this._config,this._component)),t(this,"directionalLight",new Qi(this._config,this._component))}get backgroundColor(){return this._config.backgroundColor.value}set backgroundColor(e){this._config.backgroundColor.value=e,this._component.three.background=e}}class Ji extends kt{constructor(e){super(e),t(this,"onSetup",new Dt),t(this,"isSetup",!1),t(this,"three"),t(this,"config",new Ki(this,this.components,"Scene")),t(this,"_defaultConfig",{backgroundColor:new o.Color(2107698),directionalLight:{color:new o.Color("white"),intensity:1.5,position:new o.Vector3(5,10,3)},ambientLight:{color:new o.Color("white"),intensity:1}}),this.three=new o.Scene,this.three.background=new o.Color(2107698)}setup(e){const t={...this._defaultConfig,...e};this.config.backgroundColor=t.backgroundColor;const i=t.ambientLight;this.config.ambientLight.color=i.color,this.config.ambientLight.intensity=i.intensity;const s=t.directionalLight;this.config.directionalLight.color=s.color,this.config.directionalLight.intensity=s.intensity,this.config.directionalLight.position=s.position,this.deleteAllLights();const{color:n,intensity:r}=this.config.directionalLight,a=new o.DirectionalLight(n,r);a.position.copy(s.position);const{color:c,intensity:l}=this.config.directionalLight,h=new o.AmbientLight(c,l);this.three.add(a,h),this.directionalLights.set(a.uuid,a),this.ambientLights.set(h.uuid,h),this.isSetup=!0,this.onSetup.trigger()}dispose(){super.dispose();this.components.get($i).list.delete(this.config.uuid)}}
|
|
2
2
|
/*!
|
|
3
3
|
* camera-controls
|
|
4
4
|
* https://github.com/yomotsu/camera-controls
|