@thatopen/components 2.4.0 → 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ export declare class Components implements Disposable {
6
6
  /**
7
7
  * The version of the @thatopen/components library.
8
8
  */
9
- static readonly release = "2.4.0";
9
+ static readonly release = "2.4.2";
10
10
  /** {@link Disposable.onDisposed} */
11
11
  readonly onDisposed: Event<void>;
12
12
  /**
package/dist/index.cjs CHANGED
@@ -5478,7 +5478,7 @@ const _Components = class _Components {
5478
5478
  /**
5479
5479
  * The version of the @thatopen/components library.
5480
5480
  */
5481
- __publicField(_Components, "release", "2.4.0");
5481
+ __publicField(_Components, "release", "2.4.2");
5482
5482
  let Components = _Components;
5483
5483
  class SimpleWorld extends Base {
5484
5484
  constructor() {
@@ -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 L{constructor(){}}function _(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:_,D=[],b=t.indirect?f(i):p(i);if(1===b.length){const e=b[0],t=new L;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),x(t,e.offset,e.count,w),D.push(t)}else for(let e of b){const t=new L;t.boundingData=new Float32Array(6),F(M,e.offset,e.count,t.boundingData,w),x(t,e.offset,e.count,w),D.push(t)}return D;function U(e){c&&c(e/h)}function x(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 U(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 U(t+c),e.offset=t,e.count=c,e;const f=v(I,s,M,t,c,d);if(f===t||f===t+c)U(t+c),e.offset=t,e.count=c;else{e.splitAxis=d.axis;const i=new L,s=t,n=f-t;e.left=i,i.boundingData=new Float32Array(6),F(M,s,n,i.boundingData,w),x(i,s,n,w,u+1);const r=new L,o=f,a=c-n;e.right=r,r.boundingData=new Float32Array(6),F(M,o,a,r.boundingData,w),x(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}}(),b=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))}}}(),U=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 x(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 U(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]),b(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=x(t.distanceToPoint(o));if(x(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)&&!x(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]),b(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];b(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 j(e,t){return t[e+6]}function Z(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=j(e,i));return H(e,i)+W(s,t)};const I=X(e),d=j(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=j(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=Le(0,e,i,s);return $.clearBuffer(),n}function Le(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=Z(e,o),a=Ne[r],c=s.direction[a]>=0;let l,h;c?(l=X(e),h=j(e,o)):(l=j(e,o),h=X(e));const u=Re(l,n,s,Oe)?Le(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)?Le(h,t,i,s):null;return u&&I?u.distance<=I.distance?u:I:u||I||null}}const _e=new i.Box3,Pe=new B,we=new B,Me=new i.Matrix4,ve=new V,De=new V;function be(e,t,i,s){$.setBuffer(e._roots[t]);const n=Ue(0,e,i,s);return $.clearBuffer(),n}function Ue(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,_e);if(n.intersectsBox(_e)&&Ue(o,t,i,s,n))return!0;C(c,r,_e);return!!(n.intersectsBox(_e)&&Ue(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 xe=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 xe.copy(i).invert(),Ve.matrix.copy(xe),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(xe),p.applyMatrix4(xe),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 je(e,t,i,s,n){$.setBuffer(e._roots[t]),Ze(0,e,i,s,n),$.clearBuffer()}function Ze(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)&&Ze(o,t,i,s,n);const c=j(e,a);Re(c,r,s,Xe)&&Ze(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=Z(e,o),a=Qe[r],c=s.direction[a]>=0;let l,h;c?(l=X(e),h=j(e,o)):(l=j(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=j(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=j(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=j(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=j(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?je: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:be;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 Lt=new i.Ray,_t=new i.Matrix4,Pt=i.Mesh.prototype.raycast;function wt(e,t){if(this.geometry.boundsTree){if(void 0===this.material)return;_t.copy(this.matrixWorld).invert(),Lt.copy(e.ray).applyMatrix4(_t);const i=this.geometry.boundsTree;if(!0===e.firstHitOnly){const s=yt(i.raycastFirst(Lt,this.material),this,e);s&&t.push(s)}else{const s=i.raycast(Lt,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 bt{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 Ut{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 xt extends Ut{}class Bt extends Ut{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 xt{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 jt=new i.Vector3,Zt=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,jt)}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,Zt.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){Zt.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 L=-1/0,_=-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];L=Math.max(O.dot(i),L),_=Math.max(N.dot(i),_),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+L)),N.multiplyScalar(.5*(M+_)),y.multiplyScalar(.5*(v+P));const D=new o.Vector3,b=new o.Vector3,U=new o.Matrix3;D.add(O).add(N).add(y),b.x=L-w,b.y=_-M,b.z=P-v,b.multiplyScalar(.5),U.copy(S);const{x:x,y:B,z:V}=b,Y=new o.Matrix4;Y.makeScale(2*x,2*B,2*V);const G=new o.Matrix4;G.makeTranslation(-x,-B,-V);const z=new o.Matrix4;z.makeTranslation(D.x,D.y,D.z);const k=new o.Matrix4;k.setFromMatrix3(U);const H=new o.Matrix4;return H.multiply(z),H.multiply(k),H.multiply(G),H.multiply(Y),{center:D,halfSizes:b,rotation:U,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;const di=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(di,"release","2.4.0");let Ei=di;class fi extends Ut{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(As).list.delete(this.uuid),this.onDisposed.trigger(),this.onDisposed.reset()}}class pi{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(Ti).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 Ci=class e extends xt{constructor(i){super(i),t(this,"list",new Wt),t(this,"enabled",!0),i.add(e.uuid,this)}};t(Ci,"uuid","b8c764e0-6b24-4e77-9a32-35fa728ee5b4");let Ti=Ci;class mi{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 Ri{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 gi extends pi{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 Ri(this._config,this._component)),t(this,"directionalLight",new mi(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 Ai extends kt{constructor(e){super(e),t(this,"onSetup",new Dt),t(this,"isSetup",!1),t(this,"three"),t(this,"config",new gi(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(Ti).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 L{constructor(){}}function _(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:_,D=[],b=t.indirect?f(i):p(i);if(1===b.length){const e=b[0],t=new L;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),x(t,e.offset,e.count,w),D.push(t)}else for(let e of b){const t=new L;t.boundingData=new Float32Array(6),F(M,e.offset,e.count,t.boundingData,w),x(t,e.offset,e.count,w),D.push(t)}return D;function U(e){c&&c(e/h)}function x(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 U(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 U(t+c),e.offset=t,e.count=c,e;const f=v(I,s,M,t,c,d);if(f===t||f===t+c)U(t+c),e.offset=t,e.count=c;else{e.splitAxis=d.axis;const i=new L,s=t,n=f-t;e.left=i,i.boundingData=new Float32Array(6),F(M,s,n,i.boundingData,w),x(i,s,n,w,u+1);const r=new L,o=f,a=c-n;e.right=r,r.boundingData=new Float32Array(6),F(M,o,a,r.boundingData,w),x(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}}(),b=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))}}}(),U=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 x(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 U(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]),b(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=x(t.distanceToPoint(o));if(x(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)&&!x(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]),b(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];b(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 j(e,t){return t[e+6]}function Z(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=j(e,i));return H(e,i)+W(s,t)};const I=X(e),d=j(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=j(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=Le(0,e,i,s);return $.clearBuffer(),n}function Le(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=Z(e,o),a=Ne[r],c=s.direction[a]>=0;let l,h;c?(l=X(e),h=j(e,o)):(l=j(e,o),h=X(e));const u=Re(l,n,s,Oe)?Le(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)?Le(h,t,i,s):null;return u&&I?u.distance<=I.distance?u:I:u||I||null}}const _e=new i.Box3,Pe=new B,we=new B,Me=new i.Matrix4,ve=new V,De=new V;function be(e,t,i,s){$.setBuffer(e._roots[t]);const n=Ue(0,e,i,s);return $.clearBuffer(),n}function Ue(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,_e);if(n.intersectsBox(_e)&&Ue(o,t,i,s,n))return!0;C(c,r,_e);return!!(n.intersectsBox(_e)&&Ue(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 xe=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 xe.copy(i).invert(),Ve.matrix.copy(xe),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(xe),p.applyMatrix4(xe),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 je(e,t,i,s,n){$.setBuffer(e._roots[t]),Ze(0,e,i,s,n),$.clearBuffer()}function Ze(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)&&Ze(o,t,i,s,n);const c=j(e,a);Re(c,r,s,Xe)&&Ze(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=Z(e,o),a=Qe[r],c=s.direction[a]>=0;let l,h;c?(l=X(e),h=j(e,o)):(l=j(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=j(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=j(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=j(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=j(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?je: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:be;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 Lt=new i.Ray,_t=new i.Matrix4,Pt=i.Mesh.prototype.raycast;function wt(e,t){if(this.geometry.boundsTree){if(void 0===this.material)return;_t.copy(this.matrixWorld).invert(),Lt.copy(e.ray).applyMatrix4(_t);const i=this.geometry.boundsTree;if(!0===e.firstHitOnly){const s=yt(i.raycastFirst(Lt,this.material),this,e);s&&t.push(s)}else{const s=i.raycast(Lt,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 bt{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 Ut{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 xt extends Ut{}class Bt extends Ut{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 xt{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 jt=new i.Vector3,Zt=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,jt)}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,Zt.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){Zt.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 L=-1/0,_=-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];L=Math.max(O.dot(i),L),_=Math.max(N.dot(i),_),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+L)),N.multiplyScalar(.5*(M+_)),y.multiplyScalar(.5*(v+P));const D=new o.Vector3,b=new o.Vector3,U=new o.Matrix3;D.add(O).add(N).add(y),b.x=L-w,b.y=_-M,b.z=P-v,b.multiplyScalar(.5),U.copy(S);const{x:x,y:B,z:V}=b,Y=new o.Matrix4;Y.makeScale(2*x,2*B,2*V);const G=new o.Matrix4;G.makeTranslation(-x,-B,-V);const z=new o.Matrix4;z.makeTranslation(D.x,D.y,D.z);const k=new o.Matrix4;k.setFromMatrix3(U);const H=new o.Matrix4;return H.multiply(z),H.multiply(k),H.multiply(G),H.multiply(Y),{center:D,halfSizes:b,rotation:U,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;const di=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(di,"release","2.4.2");let Ei=di;class fi extends Ut{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(As).list.delete(this.uuid),this.onDisposed.trigger(),this.onDisposed.reset()}}class pi{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(Ti).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 Ci=class e extends xt{constructor(i){super(i),t(this,"list",new Wt),t(this,"enabled",!0),i.add(e.uuid,this)}};t(Ci,"uuid","b8c764e0-6b24-4e77-9a32-35fa728ee5b4");let Ti=Ci;class mi{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 Ri{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 gi extends pi{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 Ri(this._config,this._component)),t(this,"directionalLight",new mi(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 Ai extends kt{constructor(e){super(e),t(this,"onSetup",new Dt),t(this,"isSetup",!1),t(this,"three"),t(this,"config",new gi(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(Ti).list.delete(this.config.uuid)}}
2
2
  /*!
3
3
  * camera-controls
4
4
  * https://github.com/yomotsu/camera-controls