@thatopen/components 2.0.0-alpha.3 → 2.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import * as THREE from "three";
2
- import * as FRAGS from "bim-fragment";
3
- import { FragmentsGroup } from "bim-fragment";
2
+ import * as FRAGS from "@thatopen/fragments";
3
+ import { FragmentsGroup } from "@thatopen/fragments";
4
4
  import { Component, Components, Disposable, Event } from "../../core";
5
5
  /**
6
6
  * A simple implementation of bounding box that works for fragments. The resulting bbox is not 100% precise, but
@@ -1,4 +1,4 @@
1
- import * as FRAGS from "bim-fragment";
1
+ import * as FRAGS from "@thatopen/fragments";
2
2
  import { Disposable, Component, Event, Components } from "../../core";
3
3
  export interface Classification {
4
4
  [system: string]: {
@@ -1,4 +1,4 @@
1
- import * as FRAGS from "bim-fragment";
1
+ import * as FRAGS from "@thatopen/fragments";
2
2
  import { Components, Component } from "../../core";
3
3
  export declare class FragmentHider extends Component {
4
4
  static readonly uuid: "dd9ccf2d-8a21-4821-b7f6-2949add16a29";
@@ -1,5 +1,5 @@
1
1
  import * as WEBIFC from "web-ifc";
2
- import * as FRAGS from "bim-fragment";
2
+ import * as FRAGS from "@thatopen/fragments";
3
3
  import { IfcFragmentSettings } from "./src";
4
4
  import { Component, Components, Event, Disposable } from "../../core";
5
5
  export declare class FragmentIfcLoader extends Component implements Disposable {
@@ -1,6 +1,6 @@
1
1
  import * as THREE from "three";
2
2
  import * as WEBIFC from "web-ifc";
3
- import * as FRAGS from "bim-fragment";
3
+ import * as FRAGS from "@thatopen/fragments";
4
4
  export declare class CivilReader {
5
5
  defLineMat: THREE.LineBasicMaterial;
6
6
  read(webIfc: WEBIFC.IfcAPI): {
@@ -1,4 +1,4 @@
1
- import { Fragment, FragmentsGroup } from "bim-fragment";
1
+ import { Fragment, FragmentsGroup } from "@thatopen/fragments";
2
2
  import * as THREE from "three";
3
3
  import { Component, Components, Event, Disposable } from "../../core";
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import * as WEBIFC from "web-ifc";
2
- import * as FRAG from "bim-fragment";
2
+ import * as FRAG from "@thatopen/fragments";
3
3
  /**
4
4
  * Object to export all the properties from an IFC to a JS object.
5
5
  */
@@ -1,5 +1,5 @@
1
- import * as FRAGS from "bim-fragment";
2
- import { FragmentsGroup } from "bim-fragment";
1
+ import * as FRAGS from "@thatopen/fragments";
2
+ import { FragmentsGroup } from "@thatopen/fragments";
3
3
  import { Disposable, Event, Component, Components } from "../../core";
4
4
  import { QueryGroup } from "./src/types";
5
5
  export interface QueryResult {
@@ -1,4 +1,4 @@
1
- import { FragmentsGroup } from "bim-fragment";
1
+ import { FragmentsGroup } from "@thatopen/fragments";
2
2
  import { Disposable, Event, Component, Components } from "../../core";
3
3
  import { IfcPropertiesManager } from "../IfcPropertiesManager";
4
4
  interface IndexMap {
@@ -1,5 +1,5 @@
1
1
  import * as WEBIFC from "web-ifc";
2
- import { FragmentsGroup } from "bim-fragment";
2
+ import { FragmentsGroup } from "@thatopen/fragments";
3
3
  import { Component, Disposable, Event, Components } from "../../core";
4
4
  type BooleanPropTypes = "IfcBoolean" | "IfcLogical";
5
5
  type StringPropTypes = "IfcText" | "IfcLabel" | "IfcIdentifier";
@@ -50,7 +50,7 @@ export declare class IfcPropertiesManager extends Component implements Disposabl
50
50
  get(): ChangeMap;
51
51
  dispose(): void;
52
52
  private increaseMaxID;
53
- static getIFCSchema(model: FragmentsGroup): import("bim-fragment").IfcSchema;
53
+ static getIFCSchema(model: FragmentsGroup): import("@thatopen/fragments").IfcSchema;
54
54
  private newGUID;
55
55
  private getOwnerHistory;
56
56
  private registerChange;
@@ -1,4 +1,4 @@
1
- import * as FRAGS from "bim-fragment";
1
+ import * as FRAGS from "@thatopen/fragments";
2
2
  export declare class IfcPropertiesUtils {
3
3
  static getUnits(group: FRAGS.FragmentsGroup): Promise<number>;
4
4
  static findItemByGuid(model: FRAGS.FragmentsGroup, guid: string): Promise<{
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Bn=Object.defineProperty;var Vn=(c,s,t)=>s in c?Bn(c,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[s]=t;var I=(c,s,t)=>(Vn(c,typeof s!="symbol"?s+"":s,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("three"),Yn=require("web-ifc"),rn=require("bim-fragment");function fi(c){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const t in c)if(t!=="default"){const e=Object.getOwnPropertyDescriptor(c,t);Object.defineProperty(s,t,e.get?e:{enumerable:!0,get:()=>c[t]})}}return s.default=c,Object.freeze(s)}const S=fi(C),b=fi(Yn),Ht=fi(rn),an=0,Gn=1,zn=2,gi=2,Ls=1.25,Oi=1,rs=6*4+4+4,Fs=65535,Hn=Math.pow(2,-24),Ms=Symbol("SKIP_GENERATION");function kn(c){return c.index?c.index.count:c.attributes.position.count}function le(c){return kn(c)/3}function Wn(c,s=ArrayBuffer){return c>65535?new Uint32Array(new s(4*c)):new Uint16Array(new s(2*c))}function Xn(c,s){if(!c.index){const t=c.attributes.position.count,e=s.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=Wn(t,e);c.setIndex(new C.BufferAttribute(i,1));for(let o=0;o<t;o++)i[o]=o}}function cn(c){const s=le(c),t=c.drawRange,e=t.start/3,i=(t.start+t.count)/3,o=Math.max(0,e),n=Math.min(s,i)-o;return[{offset:Math.floor(o),count:Math.floor(n)}]}function ln(c){if(!c.groups||!c.groups.length)return cn(c);const s=[],t=new Set,e=c.drawRange,i=e.start/3,o=(e.start+e.count)/3;for(const r of c.groups){const a=r.start/3,l=(r.start+r.count)/3;t.add(Math.max(i,a)),t.add(Math.min(o,l))}const n=Array.from(t.values()).sort((r,a)=>r-a);for(let r=0;r<n.length-1;r++){const a=n[r],l=n[r+1];s.push({offset:Math.floor(a),count:Math.floor(l-a)})}return s}function Zn(c){if(c.groups.length===0)return!1;const s=le(c),t=ln(c).sort((o,n)=>o.offset-n.offset),e=t[t.length-1];e.count=Math.min(s-e.offset,e.count);let i=0;return t.forEach(({count:o})=>i+=o),s!==i}function q(c,s,t){return t.min.x=s[c],t.min.y=s[c+1],t.min.z=s[c+2],t.max.x=s[c+3],t.max.y=s[c+4],t.max.z=s[c+5],t}function Qn(c){c[0]=c[1]=c[2]=1/0,c[3]=c[4]=c[5]=-1/0}function Si(c){let s=-1,t=-1/0;for(let e=0;e<3;e++){const i=c[e+3]-c[e];i>t&&(t=i,s=e)}return s}function _i(c,s){s.set(c)}function yi(c,s,t){let e,i;for(let o=0;o<3;o++){const n=o+3;e=c[o],i=s[o],t[o]=e<i?e:i,e=c[n],i=s[n],t[n]=e>i?e:i}}function ve(c,s,t){for(let e=0;e<3;e++){const i=s[c+2*e],o=s[c+2*e+1],n=i-o,r=i+o;n<t[e]&&(t[e]=n),r>t[e+3]&&(t[e+3]=r)}}function de(c){const s=c[3]-c[0],t=c[4]-c[1],e=c[5]-c[2];return 2*(s*t+t*e+e*s)}function ws(c,s,t,e,i=null){let o=1/0,n=1/0,r=1/0,a=-1/0,l=-1/0,E=-1/0,d=1/0,h=1/0,u=1/0,p=-1/0,A=-1/0,F=-1/0;const T=i!==null;for(let m=s*6,g=(s+t)*6;m<g;m+=6){const f=c[m+0],R=c[m+1],O=f-R,_=f+R;O<o&&(o=O),_>a&&(a=_),T&&f<d&&(d=f),T&&f>p&&(p=f);const y=c[m+2],N=c[m+3],L=y-N,w=y+N;L<n&&(n=L),w>l&&(l=w),T&&y<h&&(h=y),T&&y>A&&(A=y);const M=c[m+4],U=c[m+5],x=M-U,v=M+U;x<r&&(r=x),v>E&&(E=v),T&&M<u&&(u=M),T&&M>F&&(F=M)}e[0]=o,e[1]=n,e[2]=r,e[3]=a,e[4]=l,e[5]=E,T&&(i[0]=d,i[1]=h,i[2]=u,i[3]=p,i[4]=A,i[5]=F)}function jn(c,s,t,e){let i=1/0,o=1/0,n=1/0,r=-1/0,a=-1/0,l=-1/0;for(let E=s*6,d=(s+t)*6;E<d;E+=6){const h=c[E+0];h<i&&(i=h),h>r&&(r=h);const u=c[E+2];u<o&&(o=u),u>a&&(a=u);const p=c[E+4];p<n&&(n=p),p>l&&(l=p)}e[0]=i,e[1]=o,e[2]=n,e[3]=r,e[4]=a,e[5]=l}function qn(c,s){Qn(s);const t=c.attributes.position,e=c.index?c.index.array:null,i=le(c),o=new Float32Array(i*6),n=t.normalized,r=t.array,a=t.offset||0;let l=3;t.isInterleavedBufferAttribute&&(l=t.data.stride);const E=["getX","getY","getZ"];for(let d=0;d<i;d++){const h=d*3,u=d*6;let p=h+0,A=h+1,F=h+2;e&&(p=e[p],A=e[A],F=e[F]),n||(p=p*l+a,A=A*l+a,F=F*l+a);for(let T=0;T<3;T++){let m,g,f;n?(m=t[E[T]](p),g=t[E[T]](A),f=t[E[T]](F)):(m=r[p+T],g=r[A+T],f=r[F+T]);let R=m;g<R&&(R=g),f<R&&(R=f);let O=m;g>O&&(O=g),f>O&&(O=f);const _=(O-R)/2,y=T*2;o[u+y+0]=R+_,o[u+y+1]=_+(Math.abs(R)+_)*Hn,R<s[T]&&(s[T]=R),O>s[T+3]&&(s[T+3]=O)}}return o}const St=32,$n=(c,s)=>c.candidate-s.candidate,Nt=new Array(St).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Be=new Float32Array(6);function Kn(c,s,t,e,i,o){let n=-1,r=0;if(o===an)n=Si(s),n!==-1&&(r=(s[n]+s[n+3])/2);else if(o===Gn)n=Si(c),n!==-1&&(r=Jn(t,e,i,n));else if(o===zn){const a=de(c);let l=Ls*i;const E=e*6,d=(e+i)*6;for(let h=0;h<3;h++){const u=s[h],F=(s[h+3]-u)/St;if(i<St/4){const T=[...Nt];T.length=i;let m=0;for(let f=E;f<d;f+=6,m++){const R=T[m];R.candidate=t[f+2*h],R.count=0;const{bounds:O,leftCacheBounds:_,rightCacheBounds:y}=R;for(let N=0;N<3;N++)y[N]=1/0,y[N+3]=-1/0,_[N]=1/0,_[N+3]=-1/0,O[N]=1/0,O[N+3]=-1/0;ve(f,t,O)}T.sort($n);let g=i;for(let f=0;f<g;f++){const R=T[f];for(;f+1<g&&T[f+1].candidate===R.candidate;)T.splice(f+1,1),g--}for(let f=E;f<d;f+=6){const R=t[f+2*h];for(let O=0;O<g;O++){const _=T[O];R>=_.candidate?ve(f,t,_.rightCacheBounds):(ve(f,t,_.leftCacheBounds),_.count++)}}for(let f=0;f<g;f++){const R=T[f],O=R.count,_=i-R.count,y=R.leftCacheBounds,N=R.rightCacheBounds;let L=0;O!==0&&(L=de(y)/a);let w=0;_!==0&&(w=de(N)/a);const M=Oi+Ls*(L*O+w*_);M<l&&(n=h,l=M,r=R.candidate)}}else{for(let g=0;g<St;g++){const f=Nt[g];f.count=0,f.candidate=u+F+g*F;const R=f.bounds;for(let O=0;O<3;O++)R[O]=1/0,R[O+3]=-1/0}for(let g=E;g<d;g+=6){let O=~~((t[g+2*h]-u)/F);O>=St&&(O=St-1);const _=Nt[O];_.count++,ve(g,t,_.bounds)}const T=Nt[St-1];_i(T.bounds,T.rightCacheBounds);for(let g=St-2;g>=0;g--){const f=Nt[g],R=Nt[g+1];yi(f.bounds,R.rightCacheBounds,f.rightCacheBounds)}let m=0;for(let g=0;g<St-1;g++){const f=Nt[g],R=f.count,O=f.bounds,y=Nt[g+1].rightCacheBounds;R!==0&&(m===0?_i(O,Be):yi(O,Be,Be)),m+=R;let N=0,L=0;m!==0&&(N=de(Be)/a);const w=i-m;w!==0&&(L=de(y)/a);const M=Oi+Ls*(N*m+L*w);M<l&&(n=h,l=M,r=f.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${o} used.`);return{axis:n,pos:r}}function Jn(c,s,t,e){let i=0;for(let o=s,n=s+t;o<n;o++)i+=c[o*6+e*2];return i/t}class Ve{constructor(){}}function to(c,s,t,e,i,o){let n=e,r=e+i-1;const a=o.pos,l=o.axis*2;for(;;){for(;n<=r&&t[n*6+l]<a;)n++;for(;n<=r&&t[r*6+l]>=a;)r--;if(n<r){for(let E=0;E<3;E++){let d=s[n*3+E];s[n*3+E]=s[r*3+E],s[r*3+E]=d}for(let E=0;E<6;E++){let d=t[n*6+E];t[n*6+E]=t[r*6+E],t[r*6+E]=d}n++,r--}else return n}}function eo(c,s,t,e,i,o){let n=e,r=e+i-1;const a=o.pos,l=o.axis*2;for(;;){for(;n<=r&&t[n*6+l]<a;)n++;for(;n<=r&&t[r*6+l]>=a;)r--;if(n<r){let E=c[n];c[n]=c[r],c[r]=E;for(let d=0;d<6;d++){let h=t[n*6+d];t[n*6+d]=t[r*6+d],t[r*6+d]=h}n++,r--}else return n}}function so(c,s){const t=(c.index?c.index.count:c.attributes.position.count)/3,e=t>2**16,i=e?4:2,o=s?new SharedArrayBuffer(t*i):new ArrayBuffer(t*i),n=e?new Uint32Array(o):new Uint16Array(o);for(let r=0,a=n.length;r<a;r++)n[r]=r;return n}function io(c,s){const t=c.geometry,e=t.index?t.index.array:null,i=s.maxDepth,o=s.verbose,n=s.maxLeafTris,r=s.strategy,a=s.onProgress,l=le(t),E=c._indirectBuffer;let d=!1;const h=new Float32Array(6),u=new Float32Array(6),p=qn(t,h),A=s.indirect?eo:to,F=[],T=s.indirect?cn(t):ln(t);if(T.length===1){const f=T[0],R=new Ve;R.boundingData=h,jn(p,f.offset,f.count,u),g(R,f.offset,f.count,u),F.push(R)}else for(let f of T){const R=new Ve;R.boundingData=new Float32Array(6),ws(p,f.offset,f.count,R.boundingData,u),g(R,f.offset,f.count,u),F.push(R)}return F;function m(f){a&&a(f/l)}function g(f,R,O,_=null,y=0){if(!d&&y>=i&&(d=!0,o&&(console.warn(`MeshBVH: Max depth of ${i} reached when generating BVH. Consider increasing maxDepth.`),console.warn(t))),O<=n||y>=i)return m(R+O),f.offset=R,f.count=O,f;const N=Kn(f.boundingData,_,p,R,O,r);if(N.axis===-1)return m(R+O),f.offset=R,f.count=O,f;const L=A(E,e,p,R,O,N);if(L===R||L===R+O)m(R+O),f.offset=R,f.count=O;else{f.splitAxis=N.axis;const w=new Ve,M=R,U=L-R;f.left=w,w.boundingData=new Float32Array(6),ws(p,M,U,w.boundingData,u),g(w,M,U,u,y+1);const x=new Ve,v=L,z=O-U;f.right=x,x.boundingData=new Float32Array(6),ws(p,v,z,x.boundingData,u),g(x,v,z,u,y+1)}return f}}function no(c,s){const t=c.geometry;s.indirect&&(c._indirectBuffer=so(t,s.useSharedArrayBuffer),Zn(t)&&!s.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.')),c._indirectBuffer||Xn(t,s);const e=io(c,s);let i,o,n;const r=[],a=s.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer;for(let d=0;d<e.length;d++){const h=e[d];let u=l(h);const p=new a(rs*u);i=new Float32Array(p),o=new Uint32Array(p),n=new Uint16Array(p),E(0,h),r.push(p)}c._roots=r;return;function l(d){return d.count?1:1+l(d.left)+l(d.right)}function E(d,h){const u=d/4,p=d/2,A=!!h.count,F=h.boundingData;for(let T=0;T<6;T++)i[u+T]=F[T];if(A){const T=h.offset,m=h.count;return o[u+6]=T,n[p+14]=m,n[p+15]=Fs,d+rs}else{const T=h.left,m=h.right,g=h.splitAxis;let f;if(f=E(d+rs,T),f/4>Math.pow(2,32))throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return o[u+6]=f/4,f=E(f,m),o[u+7]=g,f}}}class _t{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(s,t){let e=1/0,i=-1/0;for(let o=0,n=s.length;o<n;o++){const a=s[o][t];e=a<e?a:e,i=a>i?a:i}this.min=e,this.max=i}setFromPoints(s,t){let e=1/0,i=-1/0;for(let o=0,n=t.length;o<n;o++){const r=t[o],a=s.dot(r);e=a<e?a:e,i=a>i?a:i}this.min=e,this.max=i}isSeparated(s){return this.min>s.max||s.min>this.max}}_t.prototype.setFromBox=function(){const c=new C.Vector3;return function(t,e){const i=e.min,o=e.max;let n=1/0,r=-1/0;for(let a=0;a<=1;a++)for(let l=0;l<=1;l++)for(let E=0;E<=1;E++){c.x=i.x*a+o.x*(1-a),c.y=i.y*l+o.y*(1-l),c.z=i.z*E+o.z*(1-E);const d=t.dot(c);n=Math.min(d,n),r=Math.max(d,r)}this.min=n,this.max=r}}();const oo=function(){const c=new C.Vector3,s=new C.Vector3,t=new C.Vector3;return function(i,o,n){const r=i.start,a=c,l=o.start,E=s;t.subVectors(r,l),c.subVectors(i.end,i.start),s.subVectors(o.end,o.start);const d=t.dot(E),h=E.dot(a),u=E.dot(E),p=t.dot(a),F=a.dot(a)*u-h*h;let T,m;F!==0?T=(d*h-p*u)/F:T=0,m=(d+T*h)/u,n.x=T,n.y=m}}(),pi=function(){const c=new C.Vector2,s=new C.Vector3,t=new C.Vector3;return function(i,o,n,r){oo(i,o,c);let a=c.x,l=c.y;if(a>=0&&a<=1&&l>=0&&l<=1){i.at(a,n),o.at(l,r);return}else if(a>=0&&a<=1){l<0?o.at(0,r):o.at(1,r),i.closestPointToPoint(r,!0,n);return}else if(l>=0&&l<=1){a<0?i.at(0,n):i.at(1,n),o.closestPointToPoint(n,!0,r);return}else{let E;a<0?E=i.start:E=i.end;let d;l<0?d=o.start:d=o.end;const h=s,u=t;if(i.closestPointToPoint(d,!0,s),o.closestPointToPoint(E,!0,t),h.distanceToSquared(d)<=u.distanceToSquared(E)){n.copy(h),r.copy(d);return}else{n.copy(E),r.copy(u);return}}}}(),ro=function(){const c=new C.Vector3,s=new C.Vector3,t=new C.Plane,e=new C.Line3;return function(o,n){const{radius:r,center:a}=o,{a:l,b:E,c:d}=n;if(e.start=l,e.end=E,e.closestPointToPoint(a,!0,c).distanceTo(a)<=r||(e.start=l,e.end=d,e.closestPointToPoint(a,!0,c).distanceTo(a)<=r)||(e.start=E,e.end=d,e.closestPointToPoint(a,!0,c).distanceTo(a)<=r))return!0;const A=n.getPlane(t);if(Math.abs(A.distanceToPoint(a))<=r){const T=A.projectPoint(a,s);if(n.containsPoint(T))return!0}return!1}}(),ao=1e-15;function Ds(c){return Math.abs(c)<ao}class Rt extends C.Triangle{constructor(...s){super(...s),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new C.Vector3),this.satBounds=new Array(4).fill().map(()=>new _t),this.points=[this.a,this.b,this.c],this.sphere=new C.Sphere,this.plane=new C.Plane,this.needsUpdate=!0}intersectsSphere(s){return ro(s,this)}update(){const s=this.a,t=this.b,e=this.c,i=this.points,o=this.satAxes,n=this.satBounds,r=o[0],a=n[0];this.getNormal(r),a.setFromPoints(r,i);const l=o[1],E=n[1];l.subVectors(s,t),E.setFromPoints(l,i);const d=o[2],h=n[2];d.subVectors(t,e),h.setFromPoints(d,i);const u=o[3],p=n[3];u.subVectors(e,s),p.setFromPoints(u,i),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(r,s),this.needsUpdate=!1}}Rt.prototype.closestPointToSegment=function(){const c=new C.Vector3,s=new C.Vector3,t=new C.Line3;return function(i,o=null,n=null){const{start:r,end:a}=i,l=this.points;let E,d=1/0;for(let h=0;h<3;h++){const u=(h+1)%3;t.start.copy(l[h]),t.end.copy(l[u]),pi(t,i,c,s),E=c.distanceToSquared(s),E<d&&(d=E,o&&o.copy(c),n&&n.copy(s))}return this.closestPointToPoint(r,c),E=r.distanceToSquared(c),E<d&&(d=E,o&&o.copy(c),n&&n.copy(r)),this.closestPointToPoint(a,c),E=a.distanceToSquared(c),E<d&&(d=E,o&&o.copy(c),n&&n.copy(a)),Math.sqrt(d)}}();Rt.prototype.intersectsTriangle=function(){const c=new Rt,s=new Array(3),t=new Array(3),e=new _t,i=new _t,o=new C.Vector3,n=new C.Vector3,r=new C.Vector3,a=new C.Vector3,l=new C.Vector3,E=new C.Line3,d=new C.Line3,h=new C.Line3,u=new C.Vector3;function p(A,F,T){const m=A.points;let g=0,f=-1;for(let R=0;R<3;R++){const{start:O,end:_}=E;O.copy(m[R]),_.copy(m[(R+1)%3]),E.delta(n);const y=Ds(F.distanceToPoint(O));if(Ds(F.normal.dot(n))&&y){T.copy(E),g=2;break}const N=F.intersectLine(E,u);if(!N&&y&&u.copy(O),(N||y)&&!Ds(u.distanceTo(_))){if(g<=1)(g===1?T.start:T.end).copy(u),y&&(f=g);else if(g>=2){(f===1?T.start:T.end).copy(u),g=2;break}if(g++,g===2&&f===-1)break}}return g}return function(F,T=null,m=!1){this.needsUpdate&&this.update(),F.isExtendedTriangle?F.needsUpdate&&F.update():(c.copy(F),c.update(),F=c);const g=this.plane,f=F.plane;if(Math.abs(g.normal.dot(f.normal))>1-1e-10){const R=this.satBounds,O=this.satAxes;t[0]=F.a,t[1]=F.b,t[2]=F.c;for(let N=0;N<4;N++){const L=R[N],w=O[N];if(e.setFromPoints(w,t),L.isSeparated(e))return!1}const _=F.satBounds,y=F.satAxes;s[0]=this.a,s[1]=this.b,s[2]=this.c;for(let N=0;N<4;N++){const L=_[N],w=y[N];if(e.setFromPoints(w,s),L.isSeparated(e))return!1}for(let N=0;N<4;N++){const L=O[N];for(let w=0;w<4;w++){const M=y[w];if(o.crossVectors(L,M),e.setFromPoints(o,s),i.setFromPoints(o,t),e.isSeparated(i))return!1}}return T&&(m||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),T.start.set(0,0,0),T.end.set(0,0,0)),!0}else{const R=p(this,f,d);if(R===1&&F.containsPoint(d.end))return T&&(T.start.copy(d.end),T.end.copy(d.end)),!0;if(R!==2)return!1;const O=p(F,g,h);if(O===1&&this.containsPoint(h.end))return T&&(T.start.copy(h.end),T.end.copy(h.end)),!0;if(O!==2)return!1;if(d.delta(r),h.delta(a),r.dot(a)<0){let U=h.start;h.start=h.end,h.end=U}const _=d.start.dot(r),y=d.end.dot(r),N=h.start.dot(r),L=h.end.dot(r),w=y<N,M=_<L;return _!==L&&N!==y&&w===M?!1:(T&&(l.subVectors(d.start,h.start),l.dot(r)>0?T.start.copy(d.start):T.start.copy(h.start),l.subVectors(d.end,h.end),l.dot(r)<0?T.end.copy(d.end):T.end.copy(h.end)),!0)}}}();Rt.prototype.distanceToPoint=function(){const c=new C.Vector3;return function(t){return this.closestPointToPoint(t,c),t.distanceTo(c)}}();Rt.prototype.distanceToTriangle=function(){const c=new C.Vector3,s=new C.Vector3,t=["a","b","c"],e=new C.Line3,i=new C.Line3;return function(n,r=null,a=null){const l=r||a?e:null;if(this.intersectsTriangle(n,l))return(r||a)&&(r&&l.getCenter(r),a&&l.getCenter(a)),0;let E=1/0;for(let d=0;d<3;d++){let h;const u=t[d],p=n[u];this.closestPointToPoint(p,c),h=p.distanceToSquared(c),h<E&&(E=h,r&&r.copy(c),a&&a.copy(p));const A=this[u];n.closestPointToPoint(A,c),h=A.distanceToSquared(c),h<E&&(E=h,r&&r.copy(A),a&&a.copy(c))}for(let d=0;d<3;d++){const h=t[d],u=t[(d+1)%3];e.set(this[h],this[u]);for(let p=0;p<3;p++){const A=t[p],F=t[(p+1)%3];i.set(n[A],n[F]),pi(e,i,c,s);const T=c.distanceToSquared(s);T<E&&(E=T,r&&r.copy(c),a&&a.copy(s))}}return Math.sqrt(E)}}();class ot{constructor(s,t,e){this.isOrientedBox=!0,this.min=new C.Vector3,this.max=new C.Vector3,this.matrix=new C.Matrix4,this.invMatrix=new C.Matrix4,this.points=new Array(8).fill().map(()=>new C.Vector3),this.satAxes=new Array(3).fill().map(()=>new C.Vector3),this.satBounds=new Array(3).fill().map(()=>new _t),this.alignedSatBounds=new Array(3).fill().map(()=>new _t),this.needsUpdate=!1,s&&this.min.copy(s),t&&this.max.copy(t),e&&this.matrix.copy(e)}set(s,t,e){this.min.copy(s),this.max.copy(t),this.matrix.copy(e),this.needsUpdate=!0}copy(s){this.min.copy(s.min),this.max.copy(s.max),this.matrix.copy(s.matrix),this.needsUpdate=!0}}ot.prototype.update=function(){return function(){const s=this.matrix,t=this.min,e=this.max,i=this.points;for(let l=0;l<=1;l++)for(let E=0;E<=1;E++)for(let d=0;d<=1;d++){const h=1*l|2*E|4*d,u=i[h];u.x=l?e.x:t.x,u.y=E?e.y:t.y,u.z=d?e.z:t.z,u.applyMatrix4(s)}const o=this.satBounds,n=this.satAxes,r=i[0];for(let l=0;l<3;l++){const E=n[l],d=o[l],h=1<<l,u=i[h];E.subVectors(r,u),d.setFromPoints(E,i)}const a=this.alignedSatBounds;a[0].setFromPointsField(i,"x"),a[1].setFromPointsField(i,"y"),a[2].setFromPointsField(i,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}();ot.prototype.intersectsBox=function(){const c=new _t;return function(t){this.needsUpdate&&this.update();const e=t.min,i=t.max,o=this.satBounds,n=this.satAxes,r=this.alignedSatBounds;if(c.min=e.x,c.max=i.x,r[0].isSeparated(c)||(c.min=e.y,c.max=i.y,r[1].isSeparated(c))||(c.min=e.z,c.max=i.z,r[2].isSeparated(c)))return!1;for(let a=0;a<3;a++){const l=n[a],E=o[a];if(c.setFromBox(l,t),E.isSeparated(c))return!1}return!0}}();ot.prototype.intersectsTriangle=function(){const c=new Rt,s=new Array(3),t=new _t,e=new _t,i=new C.Vector3;return function(n){this.needsUpdate&&this.update(),n.isExtendedTriangle?n.needsUpdate&&n.update():(c.copy(n),c.update(),n=c);const r=this.satBounds,a=this.satAxes;s[0]=n.a,s[1]=n.b,s[2]=n.c;for(let h=0;h<3;h++){const u=r[h],p=a[h];if(t.setFromPoints(p,s),u.isSeparated(t))return!1}const l=n.satBounds,E=n.satAxes,d=this.points;for(let h=0;h<3;h++){const u=l[h],p=E[h];if(t.setFromPoints(p,d),u.isSeparated(t))return!1}for(let h=0;h<3;h++){const u=a[h];for(let p=0;p<4;p++){const A=E[p];if(i.crossVectors(u,A),t.setFromPoints(i,s),e.setFromPoints(i,d),t.isSeparated(e))return!1}}return!0}}();ot.prototype.closestPointToPoint=function(){return function(s,t){return this.needsUpdate&&this.update(),t.copy(s).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}}();ot.prototype.distanceToPoint=function(){const c=new C.Vector3;return function(t){return this.closestPointToPoint(t,c),t.distanceTo(c)}}();ot.prototype.distanceToBox=function(){const c=["x","y","z"],s=new Array(12).fill().map(()=>new C.Line3),t=new Array(12).fill().map(()=>new C.Line3),e=new C.Vector3,i=new C.Vector3;return function(n,r=0,a=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(n))return(a||l)&&(n.getCenter(i),this.closestPointToPoint(i,e),n.closestPointToPoint(e,i),a&&a.copy(e),l&&l.copy(i)),0;const E=r*r,d=n.min,h=n.max,u=this.points;let p=1/0;for(let F=0;F<8;F++){const T=u[F];i.copy(T).clamp(d,h);const m=T.distanceToSquared(i);if(m<p&&(p=m,a&&a.copy(T),l&&l.copy(i),m<E))return Math.sqrt(m)}let A=0;for(let F=0;F<3;F++)for(let T=0;T<=1;T++)for(let m=0;m<=1;m++){const g=(F+1)%3,f=(F+2)%3,R=T<<g|m<<f,O=1<<F|T<<g|m<<f,_=u[R],y=u[O];s[A].set(_,y);const L=c[F],w=c[g],M=c[f],U=t[A],x=U.start,v=U.end;x[L]=d[L],x[w]=T?d[w]:h[w],x[M]=m?d[M]:h[w],v[L]=h[L],v[w]=T?d[w]:h[w],v[M]=m?d[M]:h[w],A++}for(let F=0;F<=1;F++)for(let T=0;T<=1;T++)for(let m=0;m<=1;m++){i.x=F?h.x:d.x,i.y=T?h.y:d.y,i.z=m?h.z:d.z,this.closestPointToPoint(i,e);const g=i.distanceToSquared(e);if(g<p&&(p=g,a&&a.copy(e),l&&l.copy(i),g<E))return Math.sqrt(g)}for(let F=0;F<12;F++){const T=s[F];for(let m=0;m<12;m++){const g=t[m];pi(T,g,e,i);const f=e.distanceToSquared(i);if(f<p&&(p=f,a&&a.copy(e),l&&l.copy(i),f<E))return Math.sqrt(f)}}return Math.sqrt(p)}}();class Ci{constructor(s){this._getNewPrimitive=s,this._primitives=[]}getPrimitive(){const s=this._primitives;return s.length===0?this._getNewPrimitive():s.pop()}releasePrimitive(s){this._primitives.push(s)}}class co extends Ci{constructor(){super(()=>new Rt)}}const Et=new co;function ct(c,s){return s[c+15]===65535}function lt(c,s){return s[c+6]}function dt(c,s){return s[c+14]}function ut(c){return c+8}function It(c,s){return s[c+6]}function hn(c,s){return s[c+7]}class lo{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const s=[];let t=null;this.setBuffer=e=>{t&&s.push(t),t=e,this.float32Array=new Float32Array(e),this.uint16Array=new Uint16Array(e),this.uint32Array=new Uint32Array(e)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,s.length!==0&&this.setBuffer(s.pop())}}}const X=new lo;let Dt,oe;const Wt=[],Ye=new Ci(()=>new C.Box3);function ho(c,s,t,e,i,o){Dt=Ye.getPrimitive(),oe=Ye.getPrimitive(),Wt.push(Dt,oe),X.setBuffer(c._roots[s]);const n=$s(0,c.geometry,t,e,i,o);X.clearBuffer(),Ye.releasePrimitive(Dt),Ye.releasePrimitive(oe),Wt.pop(),Wt.pop();const r=Wt.length;return r>0&&(oe=Wt[r-1],Dt=Wt[r-2]),n}function $s(c,s,t,e,i=null,o=0,n=0){const{float32Array:r,uint16Array:a,uint32Array:l}=X;let E=c*2;if(ct(E,a)){const h=lt(c,l),u=dt(E,a);return q(c,r,Dt),e(h,u,!1,n,o+c,Dt)}else{let L=function(M){const{uint16Array:U,uint32Array:x}=X;let v=M*2;for(;!ct(v,U);)M=ut(M),v=M*2;return lt(M,x)},w=function(M){const{uint16Array:U,uint32Array:x}=X;let v=M*2;for(;!ct(v,U);)M=It(M,x),v=M*2;return lt(M,x)+dt(v,U)};const h=ut(c),u=It(c,l);let p=h,A=u,F,T,m,g;if(i&&(m=Dt,g=oe,q(p,r,m),q(A,r,g),F=i(m),T=i(g),T<F)){p=u,A=h;const M=F;F=T,T=M,m=g}m||(m=Dt,q(p,r,m));const f=ct(p*2,a),R=t(m,f,F,n+1,o+p);let O;if(R===gi){const M=L(p),x=w(p)-M;O=e(M,x,!0,n+1,o+p,m)}else O=R&&$s(p,s,t,e,i,o,n+1);if(O)return!0;g=oe,q(A,r,g);const _=ct(A*2,a),y=t(g,_,T,n+1,o+A);let N;if(y===gi){const M=L(A),x=w(A)-M;N=e(M,x,!0,n+1,o+A,g)}else N=y&&$s(A,s,t,e,i,o,n+1);return!!N}}const ue=new C.Vector3,Us=new C.Vector3;function Eo(c,s,t={},e=0,i=1/0){const o=e*e,n=i*i;let r=1/0,a=null;if(c.shapecast({boundsTraverseOrder:E=>(ue.copy(s).clamp(E.min,E.max),ue.distanceToSquared(s)),intersectsBounds:(E,d,h)=>h<r&&h<n,intersectsTriangle:(E,d)=>{E.closestPointToPoint(s,ue);const h=s.distanceToSquared(ue);return h<r&&(Us.copy(ue),r=h,a=d),h<o}}),r===1/0)return null;const l=Math.sqrt(r);return t.point?t.point.copy(Us):t.point=Us.clone(),t.distance=l,t.faceIndex=a,t}const Xt=new C.Vector3,Zt=new C.Vector3,Qt=new C.Vector3,Ge=new C.Vector2,ze=new C.Vector2,He=new C.Vector2,Ni=new C.Vector3,Pi=new C.Vector3,Li=new C.Vector3,ke=new C.Vector3;function uo(c,s,t,e,i,o){let n;return o===C.BackSide?n=c.intersectTriangle(e,t,s,!0,i):n=c.intersectTriangle(s,t,e,o!==C.DoubleSide,i),n===null?null:{distance:c.origin.distanceTo(i),point:i.clone()}}function Io(c,s,t,e,i,o,n,r,a){Xt.fromBufferAttribute(s,o),Zt.fromBufferAttribute(s,n),Qt.fromBufferAttribute(s,r);const l=uo(c,Xt,Zt,Qt,ke,a);if(l){e&&(Ge.fromBufferAttribute(e,o),ze.fromBufferAttribute(e,n),He.fromBufferAttribute(e,r),l.uv=C.Triangle.getInterpolation(ke,Xt,Zt,Qt,Ge,ze,He,new C.Vector2)),i&&(Ge.fromBufferAttribute(i,o),ze.fromBufferAttribute(i,n),He.fromBufferAttribute(i,r),l.uv1=C.Triangle.getInterpolation(ke,Xt,Zt,Qt,Ge,ze,He,new C.Vector2)),t&&(Ni.fromBufferAttribute(t,o),Pi.fromBufferAttribute(t,n),Li.fromBufferAttribute(t,r),l.normal=C.Triangle.getInterpolation(ke,Xt,Zt,Qt,Ni,Pi,Li,new C.Vector3),l.normal.dot(c.direction)>0&&l.normal.multiplyScalar(-1));const E={a:o,b:n,c:r,normal:new C.Vector3,materialIndex:0};C.Triangle.getNormal(Xt,Zt,Qt,E.normal),l.face=E,l.faceIndex=o}return l}function gs(c,s,t,e,i){const o=e*3;let n=o+0,r=o+1,a=o+2;const l=c.index;c.index&&(n=l.getX(n),r=l.getX(r),a=l.getX(a));const{position:E,normal:d,uv:h,uv1:u}=c.attributes,p=Io(t,E,d,h,u,n,r,a,s);return p?(p.faceIndex=e,i&&i.push(p),p):null}function J(c,s,t,e){const i=c.a,o=c.b,n=c.c;let r=s,a=s+1,l=s+2;t&&(r=t.getX(r),a=t.getX(a),l=t.getX(l)),i.x=e.getX(r),i.y=e.getY(r),i.z=e.getZ(r),o.x=e.getX(a),o.y=e.getY(a),o.z=e.getZ(a),n.x=e.getX(l),n.y=e.getY(l),n.z=e.getZ(l)}function fo(c,s,t,e,i,o){const{geometry:n,_indirectBuffer:r}=c;for(let a=e,l=e+i;a<l;a++)gs(n,s,t,a,o)}function po(c,s,t,e,i){const{geometry:o,_indirectBuffer:n}=c;let r=1/0,a=null;for(let l=e,E=e+i;l<E;l++){let d;d=gs(o,s,t,l),d&&d.distance<r&&(a=d,r=d.distance)}return a}function Co(c,s,t,e,i,o,n){const{geometry:r}=t,{index:a}=r,l=r.attributes.position;for(let E=c,d=s+c;E<d;E++){let h;if(h=E,J(n,h*3,a,l),n.needsUpdate=!0,e(n,h,i,o))return!0}return!1}function To(c,s=null){s&&Array.isArray(s)&&(s=new Set(s));const t=c.geometry,e=t.index?t.index.array:null,i=t.attributes.position;let o,n,r,a,l=0;const E=c._roots;for(let h=0,u=E.length;h<u;h++)o=E[h],n=new Uint32Array(o),r=new Uint16Array(o),a=new Float32Array(o),d(0,l),l+=o.byteLength;function d(h,u,p=!1){const A=h*2;if(r[A+15]===Fs){const T=n[h+6],m=r[A+14];let g=1/0,f=1/0,R=1/0,O=-1/0,_=-1/0,y=-1/0;for(let N=3*T,L=3*(T+m);N<L;N++){let w=e[N];const M=i.getX(w),U=i.getY(w),x=i.getZ(w);M<g&&(g=M),M>O&&(O=M),U<f&&(f=U),U>_&&(_=U),x<R&&(R=x),x>y&&(y=x)}return a[h+0]!==g||a[h+1]!==f||a[h+2]!==R||a[h+3]!==O||a[h+4]!==_||a[h+5]!==y?(a[h+0]=g,a[h+1]=f,a[h+2]=R,a[h+3]=O,a[h+4]=_,a[h+5]=y,!0):!1}else{const T=h+8,m=n[h+6],g=T+u,f=m+u;let R=p,O=!1,_=!1;s?R||(O=s.has(g),_=s.has(f),R=!O&&!_):(O=!0,_=!0);const y=R||O,N=R||_;let L=!1;y&&(L=d(T,u,R));let w=!1;N&&(w=d(m,u,R));const M=L||w;if(M)for(let U=0;U<3;U++){const x=T+U,v=m+U,z=a[x],j=a[x+3],et=a[v],Z=a[v+3];a[h+U]=z<et?z:et,a[h+U+3]=j>Z?j:Z}return M}}}const Mi=new C.Box3;function Ut(c,s,t,e){return q(c,s,Mi),t.intersectBox(Mi,e)}function mo(c,s,t,e,i,o){const{geometry:n,_indirectBuffer:r}=c;for(let a=e,l=e+i;a<l;a++){let E=r?r[a]:a;gs(n,s,t,E,o)}}function Ro(c,s,t,e,i){const{geometry:o,_indirectBuffer:n}=c;let r=1/0,a=null;for(let l=e,E=e+i;l<E;l++){let d;d=gs(o,s,t,n?n[l]:l),d&&d.distance<r&&(a=d,r=d.distance)}return a}function Ao(c,s,t,e,i,o,n){const{geometry:r}=t,{index:a}=r,l=r.attributes.position;for(let E=c,d=s+c;E<d;E++){let h;if(h=t.resolveTriangleIndex(E),J(n,h*3,a,l),n.needsUpdate=!0,e(n,h,i,o))return!0}return!1}const wi=new C.Vector3;function Fo(c,s,t,e,i){X.setBuffer(c._roots[s]),Ks(0,c,t,e,i),X.clearBuffer()}function Ks(c,s,t,e,i){const{float32Array:o,uint16Array:n,uint32Array:r}=X,a=c*2;if(ct(a,n)){const E=lt(c,r),d=dt(a,n);fo(s,t,e,E,d,i)}else{const E=ut(c);Ut(E,o,e,wi)&&Ks(E,s,t,e,i);const d=It(c,r);Ut(d,o,e,wi)&&Ks(d,s,t,e,i)}}const Di=new C.Vector3,go=["x","y","z"];function Oo(c,s,t,e){X.setBuffer(c._roots[s]);const i=Js(0,c,t,e);return X.clearBuffer(),i}function Js(c,s,t,e){const{float32Array:i,uint16Array:o,uint32Array:n}=X;let r=c*2;if(ct(r,o)){const l=lt(c,n),E=dt(r,o);return po(s,t,e,l,E)}else{const l=hn(c,n),E=go[l],h=e.direction[E]>=0;let u,p;h?(u=ut(c),p=It(c,n)):(u=It(c,n),p=ut(c));const F=Ut(u,i,e,Di)?Js(u,s,t,e):null;if(F){const g=F.point[E];if(h?g<=i[p+l]:g>=i[p+l+3])return F}const m=Ut(p,i,e,Di)?Js(p,s,t,e):null;return F&&m?F.distance<=m.distance?F:m:F||m||null}}const We=new C.Box3,jt=new Rt,qt=new Rt,Ie=new C.Matrix4,Ui=new ot,Xe=new ot;function So(c,s,t,e){X.setBuffer(c._roots[s]);const i=ti(0,c,t,e);return X.clearBuffer(),i}function ti(c,s,t,e,i=null){const{float32Array:o,uint16Array:n,uint32Array:r}=X;let a=c*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Ui.set(t.boundingBox.min,t.boundingBox.max,e),i=Ui),ct(a,n)){const E=s.geometry,d=E.index,h=E.attributes.position,u=t.index,p=t.attributes.position,A=lt(c,r),F=dt(a,n);if(Ie.copy(e).invert(),t.boundsTree)return q(c,o,Xe),Xe.matrix.copy(Ie),Xe.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:m=>Xe.intersectsBox(m),intersectsTriangle:m=>{m.a.applyMatrix4(e),m.b.applyMatrix4(e),m.c.applyMatrix4(e),m.needsUpdate=!0;for(let g=A*3,f=(F+A)*3;g<f;g+=3)if(J(qt,g,d,h),qt.needsUpdate=!0,m.intersectsTriangle(qt))return!0;return!1}});for(let T=A*3,m=(F+A)*3;T<m;T+=3){J(jt,T,d,h),jt.a.applyMatrix4(Ie),jt.b.applyMatrix4(Ie),jt.c.applyMatrix4(Ie),jt.needsUpdate=!0;for(let g=0,f=u.count;g<f;g+=3)if(J(qt,g,u,p),qt.needsUpdate=!0,jt.intersectsTriangle(qt))return!0}}else{const E=c+8,d=r[c+6];return q(E,o,We),!!(i.intersectsBox(We)&&ti(E,s,t,e,i)||(q(d,o,We),i.intersectsBox(We)&&ti(d,s,t,e,i)))}}const Ze=new C.Matrix4,xs=new ot,fe=new ot,_o=new C.Vector3,yo=new C.Vector3,No=new C.Vector3,Po=new C.Vector3;function Lo(c,s,t,e={},i={},o=0,n=1/0){s.boundingBox||s.computeBoundingBox(),xs.set(s.boundingBox.min,s.boundingBox.max,t),xs.needsUpdate=!0;const r=c.geometry,a=r.attributes.position,l=r.index,E=s.attributes.position,d=s.index,h=Et.getPrimitive(),u=Et.getPrimitive();let p=_o,A=yo,F=null,T=null;i&&(F=No,T=Po);let m=1/0,g=null,f=null;return Ze.copy(t).invert(),fe.matrix.copy(Ze),c.shapecast({boundsTraverseOrder:R=>xs.distanceToBox(R),intersectsBounds:(R,O,_)=>_<m&&_<n?(O&&(fe.min.copy(R.min),fe.max.copy(R.max),fe.needsUpdate=!0),!0):!1,intersectsRange:(R,O)=>{if(s.boundsTree)return s.boundsTree.shapecast({boundsTraverseOrder:y=>fe.distanceToBox(y),intersectsBounds:(y,N,L)=>L<m&&L<n,intersectsRange:(y,N)=>{for(let L=y,w=y+N;L<w;L++){J(u,3*L,d,E),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let M=R,U=R+O;M<U;M++){J(h,3*M,l,a),h.needsUpdate=!0;const x=h.distanceToTriangle(u,p,F);if(x<m&&(A.copy(p),T&&T.copy(F),m=x,g=M,f=L),x<o)return!0}}}});{const _=le(s);for(let y=0,N=_;y<N;y++){J(u,3*y,d,E),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let L=R,w=R+O;L<w;L++){J(h,3*L,l,a),h.needsUpdate=!0;const M=h.distanceToTriangle(u,p,F);if(M<m&&(A.copy(p),T&&T.copy(F),m=M,g=L,f=y),M<o)return!0}}}}}),Et.releasePrimitive(h),Et.releasePrimitive(u),m===1/0?null:(e.point?e.point.copy(A):e.point=A.clone(),e.distance=m,e.faceIndex=g,i&&(i.point?i.point.copy(T):i.point=T.clone(),i.point.applyMatrix4(Ze),A.applyMatrix4(Ze),i.distance=A.sub(i.point).length(),i.faceIndex=f),e)}function Mo(c,s=null){s&&Array.isArray(s)&&(s=new Set(s));const t=c.geometry,e=t.index?t.index.array:null,i=t.attributes.position;let o,n,r,a,l=0;const E=c._roots;for(let h=0,u=E.length;h<u;h++)o=E[h],n=new Uint32Array(o),r=new Uint16Array(o),a=new Float32Array(o),d(0,l),l+=o.byteLength;function d(h,u,p=!1){const A=h*2;if(r[A+15]===Fs){const T=n[h+6],m=r[A+14];let g=1/0,f=1/0,R=1/0,O=-1/0,_=-1/0,y=-1/0;for(let N=T,L=T+m;N<L;N++){const w=3*c.resolveTriangleIndex(N);for(let M=0;M<3;M++){let U=w+M;U=e?e[U]:U;const x=i.getX(U),v=i.getY(U),z=i.getZ(U);x<g&&(g=x),x>O&&(O=x),v<f&&(f=v),v>_&&(_=v),z<R&&(R=z),z>y&&(y=z)}}return a[h+0]!==g||a[h+1]!==f||a[h+2]!==R||a[h+3]!==O||a[h+4]!==_||a[h+5]!==y?(a[h+0]=g,a[h+1]=f,a[h+2]=R,a[h+3]=O,a[h+4]=_,a[h+5]=y,!0):!1}else{const T=h+8,m=n[h+6],g=T+u,f=m+u;let R=p,O=!1,_=!1;s?R||(O=s.has(g),_=s.has(f),R=!O&&!_):(O=!0,_=!0);const y=R||O,N=R||_;let L=!1;y&&(L=d(T,u,R));let w=!1;N&&(w=d(m,u,R));const M=L||w;if(M)for(let U=0;U<3;U++){const x=T+U,v=m+U,z=a[x],j=a[x+3],et=a[v],Z=a[v+3];a[h+U]=z<et?z:et,a[h+U+3]=j>Z?j:Z}return M}}}const xi=new C.Vector3;function wo(c,s,t,e,i){X.setBuffer(c._roots[s]),ei(0,c,t,e,i),X.clearBuffer()}function ei(c,s,t,e,i){const{float32Array:o,uint16Array:n,uint32Array:r}=X,a=c*2;if(ct(a,n)){const E=lt(c,r),d=dt(a,n);mo(s,t,e,E,d,i)}else{const E=ut(c);Ut(E,o,e,xi)&&ei(E,s,t,e,i);const d=It(c,r);Ut(d,o,e,xi)&&ei(d,s,t,e,i)}}const bi=new C.Vector3,Do=["x","y","z"];function Uo(c,s,t,e){X.setBuffer(c._roots[s]);const i=si(0,c,t,e);return X.clearBuffer(),i}function si(c,s,t,e){const{float32Array:i,uint16Array:o,uint32Array:n}=X;let r=c*2;if(ct(r,o)){const l=lt(c,n),E=dt(r,o);return Ro(s,t,e,l,E)}else{const l=hn(c,n),E=Do[l],h=e.direction[E]>=0;let u,p;h?(u=ut(c),p=It(c,n)):(u=It(c,n),p=ut(c));const F=Ut(u,i,e,bi)?si(u,s,t,e):null;if(F){const g=F.point[E];if(h?g<=i[p+l]:g>=i[p+l+3])return F}const m=Ut(p,i,e,bi)?si(p,s,t,e):null;return F&&m?F.distance<=m.distance?F:m:F||m||null}}const Qe=new C.Box3,$t=new Rt,Kt=new Rt,pe=new C.Matrix4,vi=new ot,je=new ot;function xo(c,s,t,e){X.setBuffer(c._roots[s]);const i=ii(0,c,t,e);return X.clearBuffer(),i}function ii(c,s,t,e,i=null){const{float32Array:o,uint16Array:n,uint32Array:r}=X;let a=c*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),vi.set(t.boundingBox.min,t.boundingBox.max,e),i=vi),ct(a,n)){const E=s.geometry,d=E.index,h=E.attributes.position,u=t.index,p=t.attributes.position,A=lt(c,r),F=dt(a,n);if(pe.copy(e).invert(),t.boundsTree)return q(c,o,je),je.matrix.copy(pe),je.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:m=>je.intersectsBox(m),intersectsTriangle:m=>{m.a.applyMatrix4(e),m.b.applyMatrix4(e),m.c.applyMatrix4(e),m.needsUpdate=!0;for(let g=A,f=F+A;g<f;g++)if(J(Kt,3*s.resolveTriangleIndex(g),d,h),Kt.needsUpdate=!0,m.intersectsTriangle(Kt))return!0;return!1}});for(let T=A,m=F+A;T<m;T++){const g=s.resolveTriangleIndex(T);J($t,3*g,d,h),$t.a.applyMatrix4(pe),$t.b.applyMatrix4(pe),$t.c.applyMatrix4(pe),$t.needsUpdate=!0;for(let f=0,R=u.count;f<R;f+=3)if(J(Kt,f,u,p),Kt.needsUpdate=!0,$t.intersectsTriangle(Kt))return!0}}else{const E=c+8,d=r[c+6];return q(E,o,Qe),!!(i.intersectsBox(Qe)&&ii(E,s,t,e,i)||(q(d,o,Qe),i.intersectsBox(Qe)&&ii(d,s,t,e,i)))}}const qe=new C.Matrix4,bs=new ot,Ce=new ot,bo=new C.Vector3,vo=new C.Vector3,Bo=new C.Vector3,Vo=new C.Vector3;function Yo(c,s,t,e={},i={},o=0,n=1/0){s.boundingBox||s.computeBoundingBox(),bs.set(s.boundingBox.min,s.boundingBox.max,t),bs.needsUpdate=!0;const r=c.geometry,a=r.attributes.position,l=r.index,E=s.attributes.position,d=s.index,h=Et.getPrimitive(),u=Et.getPrimitive();let p=bo,A=vo,F=null,T=null;i&&(F=Bo,T=Vo);let m=1/0,g=null,f=null;return qe.copy(t).invert(),Ce.matrix.copy(qe),c.shapecast({boundsTraverseOrder:R=>bs.distanceToBox(R),intersectsBounds:(R,O,_)=>_<m&&_<n?(O&&(Ce.min.copy(R.min),Ce.max.copy(R.max),Ce.needsUpdate=!0),!0):!1,intersectsRange:(R,O)=>{if(s.boundsTree){const _=s.boundsTree;return _.shapecast({boundsTraverseOrder:y=>Ce.distanceToBox(y),intersectsBounds:(y,N,L)=>L<m&&L<n,intersectsRange:(y,N)=>{for(let L=y,w=y+N;L<w;L++){const M=_.resolveTriangleIndex(L);J(u,3*M,d,E),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let U=R,x=R+O;U<x;U++){const v=c.resolveTriangleIndex(U);J(h,3*v,l,a),h.needsUpdate=!0;const z=h.distanceToTriangle(u,p,F);if(z<m&&(A.copy(p),T&&T.copy(F),m=z,g=U,f=L),z<o)return!0}}}})}else{const _=le(s);for(let y=0,N=_;y<N;y++){J(u,3*y,d,E),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let L=R,w=R+O;L<w;L++){const M=c.resolveTriangleIndex(L);J(h,3*M,l,a),h.needsUpdate=!0;const U=h.distanceToTriangle(u,p,F);if(U<m&&(A.copy(p),T&&T.copy(F),m=U,g=L,f=y),U<o)return!0}}}}}),Et.releasePrimitive(h),Et.releasePrimitive(u),m===1/0?null:(e.point?e.point.copy(A):e.point=A.clone(),e.distance=m,e.faceIndex=g,i&&(i.point?i.point.copy(T):i.point=T.clone(),i.point.applyMatrix4(qe),A.applyMatrix4(qe),i.distance=A.sub(i.point).length(),i.faceIndex=f),e)}function Go(){return typeof SharedArrayBuffer<"u"}const ye=new X.constructor,ls=new X.constructor,Mt=new Ci(()=>new C.Box3),Jt=new C.Box3,te=new C.Box3,vs=new C.Box3,Bs=new C.Box3;let Vs=!1;function zo(c,s,t,e){if(Vs)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Vs=!0;const i=c._roots,o=s._roots;let n,r=0,a=0;const l=new C.Matrix4().copy(t).invert();for(let E=0,d=i.length;E<d;E++){ye.setBuffer(i[E]),a=0;const h=Mt.getPrimitive();q(0,ye.float32Array,h),h.applyMatrix4(l);for(let u=0,p=o.length;u<p&&(ls.setBuffer(o[E]),n=pt(0,0,t,l,e,r,a,0,0,h),ls.clearBuffer(),a+=o[u].length,!n);u++);if(Mt.releasePrimitive(h),ye.clearBuffer(),r+=i[E].length,n)break}return Vs=!1,n}function pt(c,s,t,e,i,o=0,n=0,r=0,a=0,l=null,E=!1){let d,h;E?(d=ls,h=ye):(d=ye,h=ls);const u=d.float32Array,p=d.uint32Array,A=d.uint16Array,F=h.float32Array,T=h.uint32Array,m=h.uint16Array,g=c*2,f=s*2,R=ct(g,A),O=ct(f,m);let _=!1;if(O&&R)E?_=i(lt(s,T),dt(s*2,m),lt(c,p),dt(c*2,A),a,n+s,r,o+c):_=i(lt(c,p),dt(c*2,A),lt(s,T),dt(s*2,m),r,o+c,a,n+s);else if(O){const y=Mt.getPrimitive();q(s,F,y),y.applyMatrix4(t);const N=ut(c),L=It(c,p);q(N,u,Jt),q(L,u,te);const w=y.intersectsBox(Jt),M=y.intersectsBox(te);_=w&&pt(s,N,e,t,i,n,o,a,r+1,y,!E)||M&&pt(s,L,e,t,i,n,o,a,r+1,y,!E),Mt.releasePrimitive(y)}else{const y=ut(s),N=It(s,T);q(y,F,vs),q(N,F,Bs);const L=l.intersectsBox(vs),w=l.intersectsBox(Bs);if(L&&w)_=pt(c,y,t,e,i,o,n,r,a+1,l,E)||pt(c,N,t,e,i,o,n,r,a+1,l,E);else if(L)if(R)_=pt(c,y,t,e,i,o,n,r,a+1,l,E);else{const M=Mt.getPrimitive();M.copy(vs).applyMatrix4(t);const U=ut(c),x=It(c,p);q(U,u,Jt),q(x,u,te);const v=M.intersectsBox(Jt),z=M.intersectsBox(te);_=v&&pt(y,U,e,t,i,n,o,a,r+1,M,!E)||z&&pt(y,x,e,t,i,n,o,a,r+1,M,!E),Mt.releasePrimitive(M)}else if(w)if(R)_=pt(c,N,t,e,i,o,n,r,a+1,l,E);else{const M=Mt.getPrimitive();M.copy(Bs).applyMatrix4(t);const U=ut(c),x=It(c,p);q(U,u,Jt),q(x,u,te);const v=M.intersectsBox(Jt),z=M.intersectsBox(te);_=v&&pt(N,U,e,t,i,n,o,a,r+1,M,!E)||z&&pt(N,x,e,t,i,n,o,a,r+1,M,!E),Mt.releasePrimitive(M)}}return _}const $e=new ot,Bi=new C.Box3;class Ti{static serialize(s,t={}){t={cloneBuffers:!0,...t};const e=s.geometry,i=s._roots,o=s._indirectBuffer,n=e.getIndex();let r;return t.cloneBuffers?r={roots:i.map(a=>a.slice()),index:n.array.slice(),indirectBuffer:o?o.slice():null}:r={roots:i,index:n.array,indirectBuffer:o},r}static deserialize(s,t,e={}){e={setIndex:!0,indirect:!!s.indirectBuffer,...e};const{index:i,roots:o,indirectBuffer:n}=s,r=new Ti(t,{...e,[Ms]:!0});if(r._roots=o,r._indirectBuffer=n||null,e.setIndex){const a=t.getIndex();if(a===null){const l=new C.BufferAttribute(s.index,1,!1);t.setIndex(l)}else a.array!==i&&(a.array.set(i),a.needsUpdate=!0)}return r}get indirect(){return!!this._indirectBuffer}constructor(s,t={}){if(s.isBufferGeometry){if(s.index&&s.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t=Object.assign({strategy:an,maxDepth:40,maxLeafTris:10,verbose:!0,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,[Ms]:!1},t),t.useSharedArrayBuffer&&!Go())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=s,this._roots=null,this._indirectBuffer=null,t[Ms]||(no(this,t),!s.boundingBox&&t.setBoundingBox&&(s.boundingBox=this.getBoundingBox(new C.Box3)));const{_indirectBuffer:e}=this;this.resolveTriangleIndex=t.indirect?i=>e[i]:i=>i}refit(s=null){return(this.indirect?Mo:To)(this,s)}traverse(s,t=0){const e=this._roots[t],i=new Uint32Array(e),o=new Uint16Array(e);n(0);function n(r,a=0){const l=r*2,E=o[l+15]===Fs;if(E){const d=i[r+6],h=o[l+14];s(a,E,new Float32Array(e,r*4,6),d,h)}else{const d=r+rs/4,h=i[r+6],u=i[r+7];s(a,E,new Float32Array(e,r*4,6),u)||(n(d,a+1),n(h,a+1))}}}raycast(s,t=C.FrontSide){const e=this._roots,i=this.geometry,o=[],n=t.isMaterial,r=Array.isArray(t),a=i.groups,l=n?t.side:t,E=this.indirect?wo:Fo;for(let d=0,h=e.length;d<h;d++){const u=r?t[a[d].materialIndex].side:l,p=o.length;if(E(this,d,u,s,o),r){const A=a[d].materialIndex;for(let F=p,T=o.length;F<T;F++)o[F].face.materialIndex=A}}return o}raycastFirst(s,t=C.FrontSide){const e=this._roots,i=this.geometry,o=t.isMaterial,n=Array.isArray(t);let r=null;const a=i.groups,l=o?t.side:t,E=this.indirect?Uo:Oo;for(let d=0,h=e.length;d<h;d++){const u=n?t[a[d].materialIndex].side:l,p=E(this,d,u,s);p!=null&&(r==null||p.distance<r.distance)&&(r=p,n&&(p.face.materialIndex=a[d].materialIndex))}return r}intersectsGeometry(s,t){let e=!1;const i=this._roots,o=this.indirect?xo:So;for(let n=0,r=i.length;n<r&&(e=o(this,n,s,t),!e);n++);return e}shapecast(s){const t=Et.getPrimitive(),e=this.indirect?Ao:Co;let{boundsTraverseOrder:i,intersectsBounds:o,intersectsRange:n,intersectsTriangle:r}=s;if(n&&r){const d=n;n=(h,u,p,A,F)=>d(h,u,p,A,F)?!0:e(h,u,this,r,p,A,t)}else n||(r?n=(d,h,u,p)=>e(d,h,this,r,u,p,t):n=(d,h,u)=>u);let a=!1,l=0;const E=this._roots;for(let d=0,h=E.length;d<h;d++){const u=E[d];if(a=ho(this,d,o,n,i,l),a)break;l+=u.byteLength}return Et.releasePrimitive(t),a}bvhcast(s,t,e){let{intersectsRanges:i,intersectsTriangles:o}=e;const n=Et.getPrimitive(),r=this.geometry.index,a=this.geometry.attributes.position,l=this.indirect?p=>{const A=this.resolveTriangleIndex(p);J(n,A*3,r,a)}:p=>{J(n,p*3,r,a)},E=Et.getPrimitive(),d=s.geometry.index,h=s.geometry.attributes.position,u=s.indirect?p=>{const A=s.resolveTriangleIndex(p);J(E,A*3,d,h)}:p=>{J(E,p*3,d,h)};if(o){const p=(A,F,T,m,g,f,R,O)=>{for(let _=T,y=T+m;_<y;_++){u(_),E.a.applyMatrix4(t),E.b.applyMatrix4(t),E.c.applyMatrix4(t),E.needsUpdate=!0;for(let N=A,L=A+F;N<L;N++)if(l(N),n.needsUpdate=!0,o(n,E,N,_,g,f,R,O))return!0}return!1};if(i){const A=i;i=function(F,T,m,g,f,R,O,_){return A(F,T,m,g,f,R,O,_)?!0:p(F,T,m,g,f,R,O,_)}}else i=p}return zo(this,s,t,i)}intersectsBox(s,t){return $e.set(s.min,s.max,t),$e.needsUpdate=!0,this.shapecast({intersectsBounds:e=>$e.intersectsBox(e),intersectsTriangle:e=>$e.intersectsTriangle(e)})}intersectsSphere(s){return this.shapecast({intersectsBounds:t=>s.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(s)})}closestPointToGeometry(s,t,e={},i={},o=0,n=1/0){return(this.indirect?Yo:Lo)(this,s,t,e,i,o,n)}closestPointToPoint(s,t={},e=0,i=1/0){return Eo(this,s,t,e,i)}getBoundingBox(s){return s.makeEmpty(),this._roots.forEach(e=>{q(0,new Float32Array(e),Bi),s.union(Bi)}),s}}function Vi(c,s,t){return c===null||(c.point.applyMatrix4(s.matrixWorld),c.distance=c.point.distanceTo(t.ray.origin),c.object=s,c.distance<t.near||c.distance>t.far)?null:c}const Ys=new C.Ray,Yi=new C.Matrix4,Ho=C.Mesh.prototype.raycast;function ko(c,s){if(this.geometry.boundsTree){if(this.material===void 0)return;Yi.copy(this.matrixWorld).invert(),Ys.copy(c.ray).applyMatrix4(Yi);const t=this.geometry.boundsTree;if(c.firstHitOnly===!0){const e=Vi(t.raycastFirst(Ys,this.material),this,c);e&&s.push(e)}else{const e=t.raycast(Ys,this.material);for(let i=0,o=e.length;i<o;i++){const n=Vi(e[i],this,c);n&&s.push(n)}}}else Ho.call(this,c,s)}function Wo(c){return this.boundsTree=new Ti(this,c),this.boundsTree}function Xo(){this.boundsTree=null}class D{constructor(){I(this,"trigger",s=>{const t=this.handlers.slice(0);for(const e of t)e(s)});I(this,"handlers",[])}add(s){this.handlers.push(s)}remove(s){this.handlers=this.handlers.filter(t=>t!==s)}reset(){this.handlers.length=0}}class Os{constructor(s){I(this,"isDisposeable",()=>"dispose"in this&&"onDisposed"in this);I(this,"isResizeable",()=>"resize"in this&&"getSize"in this);I(this,"isUpdateable",()=>"onAfterUpdate"in this&&"onBeforeUpdate"in this&&"update"in this);I(this,"isHideable",()=>"visible"in this);I(this,"isConfigurable",()=>"setup"in this&&"config"in this&&"onSetup"in this);this.components=s}}class tt extends Os{}class Ss extends Os{constructor(t){super(t);I(this,"worlds",new Map);I(this,"onWorldChanged",new D);I(this,"currentWorld",null);this.onWorldChanged.add(({world:e,action:i})=>{i==="removed"&&this.worlds.delete(e.uuid)})}}class En extends Ss{constructor(){super(...arguments);I(this,"hasCameraControls",()=>"controls"in this)}}class dn extends Ss{constructor(){super(...arguments);I(this,"onAfterUpdate",new D);I(this,"onBeforeUpdate",new D);I(this,"onDisposed",new D);I(this,"onResize",new D);I(this,"onClippingPlanesUpdated",new D);I(this,"clippingPlanes",[])}updateClippingPlanes(){this.onClippingPlanesUpdated.trigger()}setPlane(t,e,i){e.isLocal=i;const o=this.clippingPlanes.indexOf(e);t&&o===-1?this.clippingPlanes.push(e):!t&&o>-1&&this.clippingPlanes.splice(o,1),this.three.clippingPlanes=this.clippingPlanes.filter(n=>!n.isLocal)}}const Ne=class Ne extends tt{constructor(t){super(t);I(this,"_disposedComponents",new Set);I(this,"enabled",!0);t.add(Ne.uuid,this)}get(){return this._disposedComponents}destroy(t,e=!0,i=!0){t.removeFromParent();const o=t;o.dispose&&o.dispose(),this.disposeGeometryAndMaterials(t,e),i&&o.children&&o.children.length&&this.disposeChildren(o),t.children.length=0}disposeGeometry(t){const e=t;e.boundsTree&&e.disposeBoundsTree(),t.dispose()}disposeGeometryAndMaterials(t,e){const i=t;i.geometry&&this.disposeGeometry(i.geometry),e&&i.material&&Ne.disposeMaterial(i),i.material=[],i.geometry=null}disposeChildren(t){for(const e of t.children)this.destroy(e)}static disposeMaterial(t){if(t.material)if(Array.isArray(t.material))for(const e of t.material)e.dispose();else t.material.dispose()}};I(Ne,"uuid","76e9cd8e-ad8f-4753-9ef6-cbc60f7247fe");let yt=Ne;class un extends Ss{constructor(t){super(t);I(this,"onDisposed",new D)}dispose(){const t=this.components.get(yt);for(const e of this.three.children){const i=e;i.geometry&&t.destroy(i)}this.three.children=[],this.onDisposed.trigger(),this.onDisposed.reset()}}const as=0,Zo=1,Qo=new C.Vector3,Gi=new C.Line3,Gs=new C.Plane,zi=new C.Vector3,Ke=new C.Triangle;class jo{constructor(){this.tolerance=-1,this.faces=[],this.newFaces=[],this.assigned=new Hi,this.unassigned=new Hi,this.vertices=[]}setFromPoints(s){if(s.length>=4){this.makeEmpty();for(let t=0,e=s.length;t<e;t++)this.vertices.push(new qo(s[t]));this.compute()}return this}setFromObject(s){const t=[];return s.updateMatrixWorld(!0),s.traverse(function(e){const i=e.geometry;if(i!==void 0){const o=i.attributes.position;if(o!==void 0)for(let n=0,r=o.count;n<r;n++){const a=new C.Vector3;a.fromBufferAttribute(o,n).applyMatrix4(e.matrixWorld),t.push(a)}}}),this.setFromPoints(t)}containsPoint(s){const t=this.faces;for(let e=0,i=t.length;e<i;e++)if(t[e].distanceToPoint(s)>this.tolerance)return!1;return!0}intersectRay(s,t){const e=this.faces;let i=-1/0,o=1/0;for(let n=0,r=e.length;n<r;n++){const a=e[n],l=a.distanceToPoint(s.origin),E=a.normal.dot(s.direction);if(l>0&&E>=0)return null;const d=E!==0?-l/E:0;if(!(d<=0)&&(E>0?o=Math.min(d,o):i=Math.max(d,i),i>o))return null}return i!==-1/0?s.at(i,t):s.at(o,t),t}intersectsRay(s){return this.intersectRay(s,Qo)!==null}makeEmpty(){return this.faces=[],this.vertices=[],this}addVertexToFace(s,t){return s.face=t,t.outside===null?this.assigned.append(s):this.assigned.insertBefore(t.outside,s),t.outside=s,this}removeVertexFromFace(s,t){return s===t.outside&&(s.next!==null&&s.next.face===t?t.outside=s.next:t.outside=null),this.assigned.remove(s),this}removeAllVerticesFromFace(s){if(s.outside!==null){const t=s.outside;let e=s.outside;for(;e.next!==null&&e.next.face===s;)e=e.next;return this.assigned.removeSubList(t,e),t.prev=e.next=null,s.outside=null,t}}deleteFaceVertices(s,t){const e=this.removeAllVerticesFromFace(s);if(e!==void 0)if(t===void 0)this.unassigned.appendChain(e);else{let i=e;do{const o=i.next;t.distanceToPoint(i.point)>this.tolerance?this.addVertexToFace(i,t):this.unassigned.append(i),i=o}while(i!==null)}return this}resolveUnassignedPoints(s){if(this.unassigned.isEmpty()===!1){let t=this.unassigned.first();do{const e=t.next;let i=this.tolerance,o=null;for(let n=0;n<s.length;n++){const r=s[n];if(r.mark===as){const a=r.distanceToPoint(t.point);if(a>i&&(i=a,o=r),i>1e3*this.tolerance)break}}o!==null&&this.addVertexToFace(t,o),t=e}while(t!==null)}return this}computeExtremes(){const s=new C.Vector3,t=new C.Vector3,e=[],i=[];for(let o=0;o<3;o++)e[o]=i[o]=this.vertices[0];s.copy(this.vertices[0].point),t.copy(this.vertices[0].point);for(let o=0,n=this.vertices.length;o<n;o++){const r=this.vertices[o],a=r.point;for(let l=0;l<3;l++)a.getComponent(l)<s.getComponent(l)&&(s.setComponent(l,a.getComponent(l)),e[l]=r);for(let l=0;l<3;l++)a.getComponent(l)>t.getComponent(l)&&(t.setComponent(l,a.getComponent(l)),i[l]=r)}return this.tolerance=3*Number.EPSILON*(Math.max(Math.abs(s.x),Math.abs(t.x))+Math.max(Math.abs(s.y),Math.abs(t.y))+Math.max(Math.abs(s.z),Math.abs(t.z))),{min:e,max:i}}computeInitialHull(){const s=this.vertices,t=this.computeExtremes(),e=t.min,i=t.max;let o=0,n=0;for(let h=0;h<3;h++){const u=i[h].point.getComponent(h)-e[h].point.getComponent(h);u>o&&(o=u,n=h)}const r=e[n],a=i[n];let l,E;o=0,Gi.set(r.point,a.point);for(let h=0,u=this.vertices.length;h<u;h++){const p=s[h];if(p!==r&&p!==a){Gi.closestPointToPoint(p.point,!0,zi);const A=zi.distanceToSquared(p.point);A>o&&(o=A,l=p)}}o=-1,Gs.setFromCoplanarPoints(r.point,a.point,l.point);for(let h=0,u=this.vertices.length;h<u;h++){const p=s[h];if(p!==r&&p!==a&&p!==l){const A=Math.abs(Gs.distanceToPoint(p.point));A>o&&(o=A,E=p)}}const d=[];if(Gs.distanceToPoint(E.point)<0){d.push(Tt.create(r,a,l),Tt.create(E,a,r),Tt.create(E,l,a),Tt.create(E,r,l));for(let h=0;h<3;h++){const u=(h+1)%3;d[h+1].getEdge(2).setTwin(d[0].getEdge(u)),d[h+1].getEdge(1).setTwin(d[u+1].getEdge(0))}}else{d.push(Tt.create(r,l,a),Tt.create(E,r,a),Tt.create(E,a,l),Tt.create(E,l,r));for(let h=0;h<3;h++){const u=(h+1)%3;d[h+1].getEdge(2).setTwin(d[0].getEdge((3-h)%3)),d[h+1].getEdge(0).setTwin(d[u+1].getEdge(1))}}for(let h=0;h<4;h++)this.faces.push(d[h]);for(let h=0,u=s.length;h<u;h++){const p=s[h];if(p!==r&&p!==a&&p!==l&&p!==E){o=this.tolerance;let A=null;for(let F=0;F<4;F++){const T=this.faces[F].distanceToPoint(p.point);T>o&&(o=T,A=this.faces[F])}A!==null&&this.addVertexToFace(p,A)}}return this}reindexFaces(){const s=[];for(let t=0;t<this.faces.length;t++){const e=this.faces[t];e.mark===as&&s.push(e)}return this.faces=s,this}nextVertexToAdd(){if(this.assigned.isEmpty()===!1){let s,t=0;const e=this.assigned.first().face;let i=e.outside;do{const o=e.distanceToPoint(i.point);o>t&&(t=o,s=i),i=i.next}while(i!==null&&i.face===e);return s}}computeHorizon(s,t,e,i){this.deleteFaceVertices(e),e.mark=Zo;let o;t===null?o=t=e.getEdge(0):o=t.next;do{const n=o.twin,r=n.face;r.mark===as&&(r.distanceToPoint(s)>this.tolerance?this.computeHorizon(s,n,r,i):i.push(o)),o=o.next}while(o!==t);return this}addAdjoiningFace(s,t){const e=Tt.create(s,t.tail(),t.head());return this.faces.push(e),e.getEdge(-1).setTwin(t.twin),e.getEdge(0)}addNewFaces(s,t){this.newFaces=[];let e=null,i=null;for(let o=0;o<t.length;o++){const n=t[o],r=this.addAdjoiningFace(s,n);e===null?e=r:r.next.setTwin(i),this.newFaces.push(r.face),i=r}return e.next.setTwin(i),this}addVertexToHull(s){const t=[];return this.unassigned.clear(),this.removeVertexFromFace(s,s.face),this.computeHorizon(s.point,null,s.face,t),this.addNewFaces(s,t),this.resolveUnassignedPoints(this.newFaces),this}cleanup(){return this.assigned.clear(),this.unassigned.clear(),this.newFaces=[],this}compute(){let s;for(this.computeInitialHull();(s=this.nextVertexToAdd())!==void 0;)this.addVertexToHull(s);return this.reindexFaces(),this.cleanup(),this}}class Tt{constructor(){this.normal=new C.Vector3,this.midpoint=new C.Vector3,this.area=0,this.constant=0,this.outside=null,this.mark=as,this.edge=null}static create(s,t,e){const i=new Tt,o=new zs(s,i),n=new zs(t,i),r=new zs(e,i);return o.next=r.prev=n,n.next=o.prev=r,r.next=n.prev=o,i.edge=o,i.compute()}getEdge(s){let t=this.edge;for(;s>0;)t=t.next,s--;for(;s<0;)t=t.prev,s++;return t}compute(){const s=this.edge.tail(),t=this.edge.head(),e=this.edge.next.head();return Ke.set(s.point,t.point,e.point),Ke.getNormal(this.normal),Ke.getMidpoint(this.midpoint),this.area=Ke.getArea(),this.constant=this.normal.dot(this.midpoint),this}distanceToPoint(s){return this.normal.dot(s)-this.constant}}class zs{constructor(s,t){this.vertex=s,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 s=this.head(),t=this.tail();return t!==null?t.point.distanceTo(s.point):-1}lengthSquared(){const s=this.head(),t=this.tail();return t!==null?t.point.distanceToSquared(s.point):-1}setTwin(s){return this.twin=s,s.twin=this,this}}class qo{constructor(s){this.point=s,this.prev=null,this.next=null,this.face=null}}class Hi{constructor(){this.head=null,this.tail=null}first(){return this.head}last(){return this.tail}clear(){return this.head=this.tail=null,this}insertBefore(s,t){return t.prev=s.prev,t.next=s,t.prev===null?this.head=t:t.prev.next=t,s.prev=t,this}insertAfter(s,t){return t.prev=s,t.next=s.next,t.next===null?this.tail=t:t.next.prev=t,s.next=t,this}append(s){return this.head===null?this.head=s:this.tail.next=s,s.prev=this.tail,s.next=null,this.tail=s,this}appendChain(s){for(this.head===null?this.head=s:this.tail.next=s,s.prev=this.tail;s.next!==null;)s=s.next;return this.tail=s,this}remove(s){return s.prev===null?this.head=s.next:s.prev.next=s.next,s.next===null?this.tail=s.prev:s.next.prev=s.prev,this}removeSubList(s,t){return s.prev===null?this.head=t.next:s.prev.next=t.next,t.next===null?this.tail=s.prev:t.next.prev=s.prev,this}isEmpty(){return this.head===null}}const ni=[2,2,1],oi=[1,0,0];function Ot(c,s){return c*3+s}function $o(c){const s=c.elements;let t=0;for(let e=0;e<9;e++)t+=s[e]*s[e];return Math.sqrt(t)}function Ko(c){const s=c.elements;let t=0;for(let e=0;e<3;e++){const i=s[Ot(ni[e],oi[e])];t+=2*i*i}return Math.sqrt(t)}function Jo(c,s){let t=0,e=1;const i=c.elements;for(let l=0;l<3;l++){const E=Math.abs(i[Ot(ni[l],oi[l])]);E>t&&(t=E,e=l)}let o=1,n=0;const r=oi[e],a=ni[e];if(Math.abs(i[Ot(a,r)])>Number.EPSILON){const l=i[Ot(a,a)],E=i[Ot(r,r)],d=i[Ot(a,r)],h=(l-E)/2/d;let u;h<0?u=-1/(-h+Math.sqrt(1+h*h)):u=1/(h+Math.sqrt(1+h*h)),o=1/Math.sqrt(1+u*u),n=u*o}return s.identity(),s.elements[Ot(r,r)]=o,s.elements[Ot(a,a)]=o,s.elements[Ot(a,r)]=n,s.elements[Ot(r,a)]=-n,s}function tr(c,s){let t=0,e=0;const i=10;s.unitary.identity(),s.diagonal.copy(c);const o=s.unitary,n=s.diagonal,r=new S.Matrix3,a=new S.Matrix3,l=Number.EPSILON*$o(n);for(;e<i&&Ko(n)>l;)Jo(n,r),a.copy(r).transpose(),n.multiply(r),n.premultiply(a),o.multiply(r),++t>2&&(e++,t=0);return s}function In(c){const s=[];for(let st=0;st<c.length-2;st+=3){const Bt=c[st],K=c[st+1],kt=c[st+2];s.push(new S.Vector3(Bt,K,kt))}const t=new jo;t.setFromPoints(s);const e={unitary:new S.Matrix3,diagonal:new S.Matrix3},i=t.faces,o=[],n=[];for(let st=0,Bt=i.length;st<Bt;st++){const K=i[st];let kt=K.edge;o.length=0;do o.push(kt),kt=kt.next;while(kt!==K.edge);const bn=o.length-2;for(let be=1,vn=bn;be<=vn;be++){const ys=o[0].vertex,Ns=o[be+0].vertex,Ps=o[be+1].vertex;n.push(ys.point.x,ys.point.y,ys.point.z),n.push(Ns.point.x,Ns.point.y,Ns.point.z),n.push(Ps.point.x,Ps.point.y,Ps.point.z)}}const r=new S.Vector3,a=new S.Vector3,l=new S.Vector3,E=new S.Vector3,d=new S.Vector3,h=new S.Vector3,u=new S.Vector3,p=new S.Vector3;let A=0,F=0,T=0,m=0,g=0,f=0,R=0;for(let st=0,Bt=n.length;st<Bt;st+=9){r.fromArray(n,st),a.fromArray(n,st+3),l.fromArray(n,st+6),u.set(0,0,0),u.add(r).add(a).add(l).divideScalar(3),E.subVectors(a,r),d.subVectors(l,r);const K=h.crossVectors(E,d).length()/2;p.add(h.copy(u).multiplyScalar(K)),A+=K,F+=(9*u.x*u.x+r.x*r.x+a.x*a.x+l.x*l.x)*(K/12),T+=(9*u.x*u.y+r.x*r.y+a.x*a.y+l.x*l.y)*(K/12),m+=(9*u.x*u.z+r.x*r.z+a.x*a.z+l.x*l.z)*(K/12),g+=(9*u.y*u.y+r.y*r.y+a.y*a.y+l.y*l.y)*(K/12),f+=(9*u.y*u.z+r.y*r.z+a.y*a.z+l.y*l.z)*(K/12),R+=(9*u.z*u.z+r.z*r.z+a.z*a.z+l.z*l.z)*(K/12)}p.divideScalar(A),F/=A,T/=A,m/=A,g/=A,f/=A,R/=A,F-=p.x*p.x,T-=p.x*p.y,m-=p.x*p.z,g-=p.y*p.y,f-=p.y*p.z,R-=p.z*p.z;const O=new S.Matrix3;O.elements[0]=F,O.elements[1]=T,O.elements[2]=m,O.elements[3]=T,O.elements[4]=g,O.elements[5]=f,O.elements[6]=m,O.elements[7]=f,O.elements[8]=R,tr(O,e);const _=e.unitary,y=new S.Vector3,N=new S.Vector3,L=new S.Vector3;_.extractBasis(y,N,L);let w=-1/0,M=-1/0,U=-1/0,x=1/0,v=1/0,z=1/0;for(let st=0,Bt=s.length;st<Bt;st++){const K=s[st];w=Math.max(y.dot(K),w),M=Math.max(N.dot(K),M),U=Math.max(L.dot(K),U),x=Math.min(y.dot(K),x),v=Math.min(N.dot(K),v),z=Math.min(L.dot(K),z)}y.multiplyScalar(.5*(x+w)),N.multiplyScalar(.5*(v+M)),L.multiplyScalar(.5*(z+U));const j=new S.Vector3,et=new S.Vector3,Z=new S.Matrix3;j.add(y).add(N).add(L),et.x=w-x,et.y=M-v,et.z=U-z,et.multiplyScalar(.5),Z.copy(_);const{x:xt,y:bt,z:vt}=et,xe=new S.Matrix4;xe.makeScale(xt*2,bt*2,vt*2);const he=new S.Matrix4;he.makeTranslation(-xt,-bt,-vt);const Ai=new S.Matrix4;Ai.makeTranslation(j.x,j.y,j.z);const Fi=new S.Matrix4;Fi.setFromMatrix3(Z);const Ee=new S.Matrix4;return Ee.multiply(Ai),Ee.multiply(Fi),Ee.multiply(he),Ee.multiply(xe),{center:j,halfSizes:et,rotation:Z,transformation:Ee}}function fn(c,s,t){const e=[c[0]-s[0],c[1]-s[1],c[2]-s[2]];return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]>0}class ri{static isTransparent(s){return s.transparent&&s.opacity<1}}const $=class ${static create(){const s=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return`${$._lut[s&255]+$._lut[s>>8&255]+$._lut[s>>16&255]+$._lut[s>>24&255]}-${$._lut[t&255]}${$._lut[t>>8&255]}-${$._lut[t>>16&15|64]}${$._lut[t>>24&255]}-${$._lut[e&63|128]}${$._lut[e>>8&255]}-${$._lut[e>>16&255]}${$._lut[e>>24&255]}${$._lut[i&255]}${$._lut[i>>8&255]}${$._lut[i>>16&255]}${$._lut[i>>24&255]}`.toLowerCase()}static validate(s){if(!$._pattern.test(s))throw new Error(`${s} is not a valid UUID v4.
1
+ "use strict";var Bn=Object.defineProperty;var Vn=(c,s,t)=>s in c?Bn(c,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[s]=t;var I=(c,s,t)=>(Vn(c,typeof s!="symbol"?s+"":s,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("three"),Yn=require("web-ifc"),rn=require("@thatopen/fragments");function fi(c){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const t in c)if(t!=="default"){const e=Object.getOwnPropertyDescriptor(c,t);Object.defineProperty(s,t,e.get?e:{enumerable:!0,get:()=>c[t]})}}return s.default=c,Object.freeze(s)}const S=fi(C),b=fi(Yn),Ht=fi(rn),an=0,Gn=1,zn=2,gi=2,Ls=1.25,Oi=1,rs=6*4+4+4,Fs=65535,Hn=Math.pow(2,-24),Ms=Symbol("SKIP_GENERATION");function kn(c){return c.index?c.index.count:c.attributes.position.count}function le(c){return kn(c)/3}function Wn(c,s=ArrayBuffer){return c>65535?new Uint32Array(new s(4*c)):new Uint16Array(new s(2*c))}function Xn(c,s){if(!c.index){const t=c.attributes.position.count,e=s.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=Wn(t,e);c.setIndex(new C.BufferAttribute(i,1));for(let o=0;o<t;o++)i[o]=o}}function cn(c){const s=le(c),t=c.drawRange,e=t.start/3,i=(t.start+t.count)/3,o=Math.max(0,e),n=Math.min(s,i)-o;return[{offset:Math.floor(o),count:Math.floor(n)}]}function ln(c){if(!c.groups||!c.groups.length)return cn(c);const s=[],t=new Set,e=c.drawRange,i=e.start/3,o=(e.start+e.count)/3;for(const r of c.groups){const a=r.start/3,l=(r.start+r.count)/3;t.add(Math.max(i,a)),t.add(Math.min(o,l))}const n=Array.from(t.values()).sort((r,a)=>r-a);for(let r=0;r<n.length-1;r++){const a=n[r],l=n[r+1];s.push({offset:Math.floor(a),count:Math.floor(l-a)})}return s}function Zn(c){if(c.groups.length===0)return!1;const s=le(c),t=ln(c).sort((o,n)=>o.offset-n.offset),e=t[t.length-1];e.count=Math.min(s-e.offset,e.count);let i=0;return t.forEach(({count:o})=>i+=o),s!==i}function q(c,s,t){return t.min.x=s[c],t.min.y=s[c+1],t.min.z=s[c+2],t.max.x=s[c+3],t.max.y=s[c+4],t.max.z=s[c+5],t}function Qn(c){c[0]=c[1]=c[2]=1/0,c[3]=c[4]=c[5]=-1/0}function Si(c){let s=-1,t=-1/0;for(let e=0;e<3;e++){const i=c[e+3]-c[e];i>t&&(t=i,s=e)}return s}function _i(c,s){s.set(c)}function yi(c,s,t){let e,i;for(let o=0;o<3;o++){const n=o+3;e=c[o],i=s[o],t[o]=e<i?e:i,e=c[n],i=s[n],t[n]=e>i?e:i}}function ve(c,s,t){for(let e=0;e<3;e++){const i=s[c+2*e],o=s[c+2*e+1],n=i-o,r=i+o;n<t[e]&&(t[e]=n),r>t[e+3]&&(t[e+3]=r)}}function de(c){const s=c[3]-c[0],t=c[4]-c[1],e=c[5]-c[2];return 2*(s*t+t*e+e*s)}function ws(c,s,t,e,i=null){let o=1/0,n=1/0,r=1/0,a=-1/0,l=-1/0,E=-1/0,d=1/0,h=1/0,u=1/0,p=-1/0,A=-1/0,F=-1/0;const T=i!==null;for(let m=s*6,g=(s+t)*6;m<g;m+=6){const f=c[m+0],R=c[m+1],O=f-R,_=f+R;O<o&&(o=O),_>a&&(a=_),T&&f<d&&(d=f),T&&f>p&&(p=f);const y=c[m+2],N=c[m+3],L=y-N,w=y+N;L<n&&(n=L),w>l&&(l=w),T&&y<h&&(h=y),T&&y>A&&(A=y);const M=c[m+4],U=c[m+5],x=M-U,v=M+U;x<r&&(r=x),v>E&&(E=v),T&&M<u&&(u=M),T&&M>F&&(F=M)}e[0]=o,e[1]=n,e[2]=r,e[3]=a,e[4]=l,e[5]=E,T&&(i[0]=d,i[1]=h,i[2]=u,i[3]=p,i[4]=A,i[5]=F)}function jn(c,s,t,e){let i=1/0,o=1/0,n=1/0,r=-1/0,a=-1/0,l=-1/0;for(let E=s*6,d=(s+t)*6;E<d;E+=6){const h=c[E+0];h<i&&(i=h),h>r&&(r=h);const u=c[E+2];u<o&&(o=u),u>a&&(a=u);const p=c[E+4];p<n&&(n=p),p>l&&(l=p)}e[0]=i,e[1]=o,e[2]=n,e[3]=r,e[4]=a,e[5]=l}function qn(c,s){Qn(s);const t=c.attributes.position,e=c.index?c.index.array:null,i=le(c),o=new Float32Array(i*6),n=t.normalized,r=t.array,a=t.offset||0;let l=3;t.isInterleavedBufferAttribute&&(l=t.data.stride);const E=["getX","getY","getZ"];for(let d=0;d<i;d++){const h=d*3,u=d*6;let p=h+0,A=h+1,F=h+2;e&&(p=e[p],A=e[A],F=e[F]),n||(p=p*l+a,A=A*l+a,F=F*l+a);for(let T=0;T<3;T++){let m,g,f;n?(m=t[E[T]](p),g=t[E[T]](A),f=t[E[T]](F)):(m=r[p+T],g=r[A+T],f=r[F+T]);let R=m;g<R&&(R=g),f<R&&(R=f);let O=m;g>O&&(O=g),f>O&&(O=f);const _=(O-R)/2,y=T*2;o[u+y+0]=R+_,o[u+y+1]=_+(Math.abs(R)+_)*Hn,R<s[T]&&(s[T]=R),O>s[T+3]&&(s[T+3]=O)}}return o}const St=32,$n=(c,s)=>c.candidate-s.candidate,Nt=new Array(St).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Be=new Float32Array(6);function Kn(c,s,t,e,i,o){let n=-1,r=0;if(o===an)n=Si(s),n!==-1&&(r=(s[n]+s[n+3])/2);else if(o===Gn)n=Si(c),n!==-1&&(r=Jn(t,e,i,n));else if(o===zn){const a=de(c);let l=Ls*i;const E=e*6,d=(e+i)*6;for(let h=0;h<3;h++){const u=s[h],F=(s[h+3]-u)/St;if(i<St/4){const T=[...Nt];T.length=i;let m=0;for(let f=E;f<d;f+=6,m++){const R=T[m];R.candidate=t[f+2*h],R.count=0;const{bounds:O,leftCacheBounds:_,rightCacheBounds:y}=R;for(let N=0;N<3;N++)y[N]=1/0,y[N+3]=-1/0,_[N]=1/0,_[N+3]=-1/0,O[N]=1/0,O[N+3]=-1/0;ve(f,t,O)}T.sort($n);let g=i;for(let f=0;f<g;f++){const R=T[f];for(;f+1<g&&T[f+1].candidate===R.candidate;)T.splice(f+1,1),g--}for(let f=E;f<d;f+=6){const R=t[f+2*h];for(let O=0;O<g;O++){const _=T[O];R>=_.candidate?ve(f,t,_.rightCacheBounds):(ve(f,t,_.leftCacheBounds),_.count++)}}for(let f=0;f<g;f++){const R=T[f],O=R.count,_=i-R.count,y=R.leftCacheBounds,N=R.rightCacheBounds;let L=0;O!==0&&(L=de(y)/a);let w=0;_!==0&&(w=de(N)/a);const M=Oi+Ls*(L*O+w*_);M<l&&(n=h,l=M,r=R.candidate)}}else{for(let g=0;g<St;g++){const f=Nt[g];f.count=0,f.candidate=u+F+g*F;const R=f.bounds;for(let O=0;O<3;O++)R[O]=1/0,R[O+3]=-1/0}for(let g=E;g<d;g+=6){let O=~~((t[g+2*h]-u)/F);O>=St&&(O=St-1);const _=Nt[O];_.count++,ve(g,t,_.bounds)}const T=Nt[St-1];_i(T.bounds,T.rightCacheBounds);for(let g=St-2;g>=0;g--){const f=Nt[g],R=Nt[g+1];yi(f.bounds,R.rightCacheBounds,f.rightCacheBounds)}let m=0;for(let g=0;g<St-1;g++){const f=Nt[g],R=f.count,O=f.bounds,y=Nt[g+1].rightCacheBounds;R!==0&&(m===0?_i(O,Be):yi(O,Be,Be)),m+=R;let N=0,L=0;m!==0&&(N=de(Be)/a);const w=i-m;w!==0&&(L=de(y)/a);const M=Oi+Ls*(N*m+L*w);M<l&&(n=h,l=M,r=f.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${o} used.`);return{axis:n,pos:r}}function Jn(c,s,t,e){let i=0;for(let o=s,n=s+t;o<n;o++)i+=c[o*6+e*2];return i/t}class Ve{constructor(){}}function to(c,s,t,e,i,o){let n=e,r=e+i-1;const a=o.pos,l=o.axis*2;for(;;){for(;n<=r&&t[n*6+l]<a;)n++;for(;n<=r&&t[r*6+l]>=a;)r--;if(n<r){for(let E=0;E<3;E++){let d=s[n*3+E];s[n*3+E]=s[r*3+E],s[r*3+E]=d}for(let E=0;E<6;E++){let d=t[n*6+E];t[n*6+E]=t[r*6+E],t[r*6+E]=d}n++,r--}else return n}}function eo(c,s,t,e,i,o){let n=e,r=e+i-1;const a=o.pos,l=o.axis*2;for(;;){for(;n<=r&&t[n*6+l]<a;)n++;for(;n<=r&&t[r*6+l]>=a;)r--;if(n<r){let E=c[n];c[n]=c[r],c[r]=E;for(let d=0;d<6;d++){let h=t[n*6+d];t[n*6+d]=t[r*6+d],t[r*6+d]=h}n++,r--}else return n}}function so(c,s){const t=(c.index?c.index.count:c.attributes.position.count)/3,e=t>2**16,i=e?4:2,o=s?new SharedArrayBuffer(t*i):new ArrayBuffer(t*i),n=e?new Uint32Array(o):new Uint16Array(o);for(let r=0,a=n.length;r<a;r++)n[r]=r;return n}function io(c,s){const t=c.geometry,e=t.index?t.index.array:null,i=s.maxDepth,o=s.verbose,n=s.maxLeafTris,r=s.strategy,a=s.onProgress,l=le(t),E=c._indirectBuffer;let d=!1;const h=new Float32Array(6),u=new Float32Array(6),p=qn(t,h),A=s.indirect?eo:to,F=[],T=s.indirect?cn(t):ln(t);if(T.length===1){const f=T[0],R=new Ve;R.boundingData=h,jn(p,f.offset,f.count,u),g(R,f.offset,f.count,u),F.push(R)}else for(let f of T){const R=new Ve;R.boundingData=new Float32Array(6),ws(p,f.offset,f.count,R.boundingData,u),g(R,f.offset,f.count,u),F.push(R)}return F;function m(f){a&&a(f/l)}function g(f,R,O,_=null,y=0){if(!d&&y>=i&&(d=!0,o&&(console.warn(`MeshBVH: Max depth of ${i} reached when generating BVH. Consider increasing maxDepth.`),console.warn(t))),O<=n||y>=i)return m(R+O),f.offset=R,f.count=O,f;const N=Kn(f.boundingData,_,p,R,O,r);if(N.axis===-1)return m(R+O),f.offset=R,f.count=O,f;const L=A(E,e,p,R,O,N);if(L===R||L===R+O)m(R+O),f.offset=R,f.count=O;else{f.splitAxis=N.axis;const w=new Ve,M=R,U=L-R;f.left=w,w.boundingData=new Float32Array(6),ws(p,M,U,w.boundingData,u),g(w,M,U,u,y+1);const x=new Ve,v=L,z=O-U;f.right=x,x.boundingData=new Float32Array(6),ws(p,v,z,x.boundingData,u),g(x,v,z,u,y+1)}return f}}function no(c,s){const t=c.geometry;s.indirect&&(c._indirectBuffer=so(t,s.useSharedArrayBuffer),Zn(t)&&!s.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.')),c._indirectBuffer||Xn(t,s);const e=io(c,s);let i,o,n;const r=[],a=s.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer;for(let d=0;d<e.length;d++){const h=e[d];let u=l(h);const p=new a(rs*u);i=new Float32Array(p),o=new Uint32Array(p),n=new Uint16Array(p),E(0,h),r.push(p)}c._roots=r;return;function l(d){return d.count?1:1+l(d.left)+l(d.right)}function E(d,h){const u=d/4,p=d/2,A=!!h.count,F=h.boundingData;for(let T=0;T<6;T++)i[u+T]=F[T];if(A){const T=h.offset,m=h.count;return o[u+6]=T,n[p+14]=m,n[p+15]=Fs,d+rs}else{const T=h.left,m=h.right,g=h.splitAxis;let f;if(f=E(d+rs,T),f/4>Math.pow(2,32))throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return o[u+6]=f/4,f=E(f,m),o[u+7]=g,f}}}class _t{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(s,t){let e=1/0,i=-1/0;for(let o=0,n=s.length;o<n;o++){const a=s[o][t];e=a<e?a:e,i=a>i?a:i}this.min=e,this.max=i}setFromPoints(s,t){let e=1/0,i=-1/0;for(let o=0,n=t.length;o<n;o++){const r=t[o],a=s.dot(r);e=a<e?a:e,i=a>i?a:i}this.min=e,this.max=i}isSeparated(s){return this.min>s.max||s.min>this.max}}_t.prototype.setFromBox=function(){const c=new C.Vector3;return function(t,e){const i=e.min,o=e.max;let n=1/0,r=-1/0;for(let a=0;a<=1;a++)for(let l=0;l<=1;l++)for(let E=0;E<=1;E++){c.x=i.x*a+o.x*(1-a),c.y=i.y*l+o.y*(1-l),c.z=i.z*E+o.z*(1-E);const d=t.dot(c);n=Math.min(d,n),r=Math.max(d,r)}this.min=n,this.max=r}}();const oo=function(){const c=new C.Vector3,s=new C.Vector3,t=new C.Vector3;return function(i,o,n){const r=i.start,a=c,l=o.start,E=s;t.subVectors(r,l),c.subVectors(i.end,i.start),s.subVectors(o.end,o.start);const d=t.dot(E),h=E.dot(a),u=E.dot(E),p=t.dot(a),F=a.dot(a)*u-h*h;let T,m;F!==0?T=(d*h-p*u)/F:T=0,m=(d+T*h)/u,n.x=T,n.y=m}}(),pi=function(){const c=new C.Vector2,s=new C.Vector3,t=new C.Vector3;return function(i,o,n,r){oo(i,o,c);let a=c.x,l=c.y;if(a>=0&&a<=1&&l>=0&&l<=1){i.at(a,n),o.at(l,r);return}else if(a>=0&&a<=1){l<0?o.at(0,r):o.at(1,r),i.closestPointToPoint(r,!0,n);return}else if(l>=0&&l<=1){a<0?i.at(0,n):i.at(1,n),o.closestPointToPoint(n,!0,r);return}else{let E;a<0?E=i.start:E=i.end;let d;l<0?d=o.start:d=o.end;const h=s,u=t;if(i.closestPointToPoint(d,!0,s),o.closestPointToPoint(E,!0,t),h.distanceToSquared(d)<=u.distanceToSquared(E)){n.copy(h),r.copy(d);return}else{n.copy(E),r.copy(u);return}}}}(),ro=function(){const c=new C.Vector3,s=new C.Vector3,t=new C.Plane,e=new C.Line3;return function(o,n){const{radius:r,center:a}=o,{a:l,b:E,c:d}=n;if(e.start=l,e.end=E,e.closestPointToPoint(a,!0,c).distanceTo(a)<=r||(e.start=l,e.end=d,e.closestPointToPoint(a,!0,c).distanceTo(a)<=r)||(e.start=E,e.end=d,e.closestPointToPoint(a,!0,c).distanceTo(a)<=r))return!0;const A=n.getPlane(t);if(Math.abs(A.distanceToPoint(a))<=r){const T=A.projectPoint(a,s);if(n.containsPoint(T))return!0}return!1}}(),ao=1e-15;function Ds(c){return Math.abs(c)<ao}class Rt extends C.Triangle{constructor(...s){super(...s),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new C.Vector3),this.satBounds=new Array(4).fill().map(()=>new _t),this.points=[this.a,this.b,this.c],this.sphere=new C.Sphere,this.plane=new C.Plane,this.needsUpdate=!0}intersectsSphere(s){return ro(s,this)}update(){const s=this.a,t=this.b,e=this.c,i=this.points,o=this.satAxes,n=this.satBounds,r=o[0],a=n[0];this.getNormal(r),a.setFromPoints(r,i);const l=o[1],E=n[1];l.subVectors(s,t),E.setFromPoints(l,i);const d=o[2],h=n[2];d.subVectors(t,e),h.setFromPoints(d,i);const u=o[3],p=n[3];u.subVectors(e,s),p.setFromPoints(u,i),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(r,s),this.needsUpdate=!1}}Rt.prototype.closestPointToSegment=function(){const c=new C.Vector3,s=new C.Vector3,t=new C.Line3;return function(i,o=null,n=null){const{start:r,end:a}=i,l=this.points;let E,d=1/0;for(let h=0;h<3;h++){const u=(h+1)%3;t.start.copy(l[h]),t.end.copy(l[u]),pi(t,i,c,s),E=c.distanceToSquared(s),E<d&&(d=E,o&&o.copy(c),n&&n.copy(s))}return this.closestPointToPoint(r,c),E=r.distanceToSquared(c),E<d&&(d=E,o&&o.copy(c),n&&n.copy(r)),this.closestPointToPoint(a,c),E=a.distanceToSquared(c),E<d&&(d=E,o&&o.copy(c),n&&n.copy(a)),Math.sqrt(d)}}();Rt.prototype.intersectsTriangle=function(){const c=new Rt,s=new Array(3),t=new Array(3),e=new _t,i=new _t,o=new C.Vector3,n=new C.Vector3,r=new C.Vector3,a=new C.Vector3,l=new C.Vector3,E=new C.Line3,d=new C.Line3,h=new C.Line3,u=new C.Vector3;function p(A,F,T){const m=A.points;let g=0,f=-1;for(let R=0;R<3;R++){const{start:O,end:_}=E;O.copy(m[R]),_.copy(m[(R+1)%3]),E.delta(n);const y=Ds(F.distanceToPoint(O));if(Ds(F.normal.dot(n))&&y){T.copy(E),g=2;break}const N=F.intersectLine(E,u);if(!N&&y&&u.copy(O),(N||y)&&!Ds(u.distanceTo(_))){if(g<=1)(g===1?T.start:T.end).copy(u),y&&(f=g);else if(g>=2){(f===1?T.start:T.end).copy(u),g=2;break}if(g++,g===2&&f===-1)break}}return g}return function(F,T=null,m=!1){this.needsUpdate&&this.update(),F.isExtendedTriangle?F.needsUpdate&&F.update():(c.copy(F),c.update(),F=c);const g=this.plane,f=F.plane;if(Math.abs(g.normal.dot(f.normal))>1-1e-10){const R=this.satBounds,O=this.satAxes;t[0]=F.a,t[1]=F.b,t[2]=F.c;for(let N=0;N<4;N++){const L=R[N],w=O[N];if(e.setFromPoints(w,t),L.isSeparated(e))return!1}const _=F.satBounds,y=F.satAxes;s[0]=this.a,s[1]=this.b,s[2]=this.c;for(let N=0;N<4;N++){const L=_[N],w=y[N];if(e.setFromPoints(w,s),L.isSeparated(e))return!1}for(let N=0;N<4;N++){const L=O[N];for(let w=0;w<4;w++){const M=y[w];if(o.crossVectors(L,M),e.setFromPoints(o,s),i.setFromPoints(o,t),e.isSeparated(i))return!1}}return T&&(m||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),T.start.set(0,0,0),T.end.set(0,0,0)),!0}else{const R=p(this,f,d);if(R===1&&F.containsPoint(d.end))return T&&(T.start.copy(d.end),T.end.copy(d.end)),!0;if(R!==2)return!1;const O=p(F,g,h);if(O===1&&this.containsPoint(h.end))return T&&(T.start.copy(h.end),T.end.copy(h.end)),!0;if(O!==2)return!1;if(d.delta(r),h.delta(a),r.dot(a)<0){let U=h.start;h.start=h.end,h.end=U}const _=d.start.dot(r),y=d.end.dot(r),N=h.start.dot(r),L=h.end.dot(r),w=y<N,M=_<L;return _!==L&&N!==y&&w===M?!1:(T&&(l.subVectors(d.start,h.start),l.dot(r)>0?T.start.copy(d.start):T.start.copy(h.start),l.subVectors(d.end,h.end),l.dot(r)<0?T.end.copy(d.end):T.end.copy(h.end)),!0)}}}();Rt.prototype.distanceToPoint=function(){const c=new C.Vector3;return function(t){return this.closestPointToPoint(t,c),t.distanceTo(c)}}();Rt.prototype.distanceToTriangle=function(){const c=new C.Vector3,s=new C.Vector3,t=["a","b","c"],e=new C.Line3,i=new C.Line3;return function(n,r=null,a=null){const l=r||a?e:null;if(this.intersectsTriangle(n,l))return(r||a)&&(r&&l.getCenter(r),a&&l.getCenter(a)),0;let E=1/0;for(let d=0;d<3;d++){let h;const u=t[d],p=n[u];this.closestPointToPoint(p,c),h=p.distanceToSquared(c),h<E&&(E=h,r&&r.copy(c),a&&a.copy(p));const A=this[u];n.closestPointToPoint(A,c),h=A.distanceToSquared(c),h<E&&(E=h,r&&r.copy(A),a&&a.copy(c))}for(let d=0;d<3;d++){const h=t[d],u=t[(d+1)%3];e.set(this[h],this[u]);for(let p=0;p<3;p++){const A=t[p],F=t[(p+1)%3];i.set(n[A],n[F]),pi(e,i,c,s);const T=c.distanceToSquared(s);T<E&&(E=T,r&&r.copy(c),a&&a.copy(s))}}return Math.sqrt(E)}}();class ot{constructor(s,t,e){this.isOrientedBox=!0,this.min=new C.Vector3,this.max=new C.Vector3,this.matrix=new C.Matrix4,this.invMatrix=new C.Matrix4,this.points=new Array(8).fill().map(()=>new C.Vector3),this.satAxes=new Array(3).fill().map(()=>new C.Vector3),this.satBounds=new Array(3).fill().map(()=>new _t),this.alignedSatBounds=new Array(3).fill().map(()=>new _t),this.needsUpdate=!1,s&&this.min.copy(s),t&&this.max.copy(t),e&&this.matrix.copy(e)}set(s,t,e){this.min.copy(s),this.max.copy(t),this.matrix.copy(e),this.needsUpdate=!0}copy(s){this.min.copy(s.min),this.max.copy(s.max),this.matrix.copy(s.matrix),this.needsUpdate=!0}}ot.prototype.update=function(){return function(){const s=this.matrix,t=this.min,e=this.max,i=this.points;for(let l=0;l<=1;l++)for(let E=0;E<=1;E++)for(let d=0;d<=1;d++){const h=1*l|2*E|4*d,u=i[h];u.x=l?e.x:t.x,u.y=E?e.y:t.y,u.z=d?e.z:t.z,u.applyMatrix4(s)}const o=this.satBounds,n=this.satAxes,r=i[0];for(let l=0;l<3;l++){const E=n[l],d=o[l],h=1<<l,u=i[h];E.subVectors(r,u),d.setFromPoints(E,i)}const a=this.alignedSatBounds;a[0].setFromPointsField(i,"x"),a[1].setFromPointsField(i,"y"),a[2].setFromPointsField(i,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}();ot.prototype.intersectsBox=function(){const c=new _t;return function(t){this.needsUpdate&&this.update();const e=t.min,i=t.max,o=this.satBounds,n=this.satAxes,r=this.alignedSatBounds;if(c.min=e.x,c.max=i.x,r[0].isSeparated(c)||(c.min=e.y,c.max=i.y,r[1].isSeparated(c))||(c.min=e.z,c.max=i.z,r[2].isSeparated(c)))return!1;for(let a=0;a<3;a++){const l=n[a],E=o[a];if(c.setFromBox(l,t),E.isSeparated(c))return!1}return!0}}();ot.prototype.intersectsTriangle=function(){const c=new Rt,s=new Array(3),t=new _t,e=new _t,i=new C.Vector3;return function(n){this.needsUpdate&&this.update(),n.isExtendedTriangle?n.needsUpdate&&n.update():(c.copy(n),c.update(),n=c);const r=this.satBounds,a=this.satAxes;s[0]=n.a,s[1]=n.b,s[2]=n.c;for(let h=0;h<3;h++){const u=r[h],p=a[h];if(t.setFromPoints(p,s),u.isSeparated(t))return!1}const l=n.satBounds,E=n.satAxes,d=this.points;for(let h=0;h<3;h++){const u=l[h],p=E[h];if(t.setFromPoints(p,d),u.isSeparated(t))return!1}for(let h=0;h<3;h++){const u=a[h];for(let p=0;p<4;p++){const A=E[p];if(i.crossVectors(u,A),t.setFromPoints(i,s),e.setFromPoints(i,d),t.isSeparated(e))return!1}}return!0}}();ot.prototype.closestPointToPoint=function(){return function(s,t){return this.needsUpdate&&this.update(),t.copy(s).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}}();ot.prototype.distanceToPoint=function(){const c=new C.Vector3;return function(t){return this.closestPointToPoint(t,c),t.distanceTo(c)}}();ot.prototype.distanceToBox=function(){const c=["x","y","z"],s=new Array(12).fill().map(()=>new C.Line3),t=new Array(12).fill().map(()=>new C.Line3),e=new C.Vector3,i=new C.Vector3;return function(n,r=0,a=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(n))return(a||l)&&(n.getCenter(i),this.closestPointToPoint(i,e),n.closestPointToPoint(e,i),a&&a.copy(e),l&&l.copy(i)),0;const E=r*r,d=n.min,h=n.max,u=this.points;let p=1/0;for(let F=0;F<8;F++){const T=u[F];i.copy(T).clamp(d,h);const m=T.distanceToSquared(i);if(m<p&&(p=m,a&&a.copy(T),l&&l.copy(i),m<E))return Math.sqrt(m)}let A=0;for(let F=0;F<3;F++)for(let T=0;T<=1;T++)for(let m=0;m<=1;m++){const g=(F+1)%3,f=(F+2)%3,R=T<<g|m<<f,O=1<<F|T<<g|m<<f,_=u[R],y=u[O];s[A].set(_,y);const L=c[F],w=c[g],M=c[f],U=t[A],x=U.start,v=U.end;x[L]=d[L],x[w]=T?d[w]:h[w],x[M]=m?d[M]:h[w],v[L]=h[L],v[w]=T?d[w]:h[w],v[M]=m?d[M]:h[w],A++}for(let F=0;F<=1;F++)for(let T=0;T<=1;T++)for(let m=0;m<=1;m++){i.x=F?h.x:d.x,i.y=T?h.y:d.y,i.z=m?h.z:d.z,this.closestPointToPoint(i,e);const g=i.distanceToSquared(e);if(g<p&&(p=g,a&&a.copy(e),l&&l.copy(i),g<E))return Math.sqrt(g)}for(let F=0;F<12;F++){const T=s[F];for(let m=0;m<12;m++){const g=t[m];pi(T,g,e,i);const f=e.distanceToSquared(i);if(f<p&&(p=f,a&&a.copy(e),l&&l.copy(i),f<E))return Math.sqrt(f)}}return Math.sqrt(p)}}();class Ci{constructor(s){this._getNewPrimitive=s,this._primitives=[]}getPrimitive(){const s=this._primitives;return s.length===0?this._getNewPrimitive():s.pop()}releasePrimitive(s){this._primitives.push(s)}}class co extends Ci{constructor(){super(()=>new Rt)}}const Et=new co;function ct(c,s){return s[c+15]===65535}function lt(c,s){return s[c+6]}function dt(c,s){return s[c+14]}function ut(c){return c+8}function It(c,s){return s[c+6]}function hn(c,s){return s[c+7]}class lo{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const s=[];let t=null;this.setBuffer=e=>{t&&s.push(t),t=e,this.float32Array=new Float32Array(e),this.uint16Array=new Uint16Array(e),this.uint32Array=new Uint32Array(e)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,s.length!==0&&this.setBuffer(s.pop())}}}const X=new lo;let Dt,oe;const Wt=[],Ye=new Ci(()=>new C.Box3);function ho(c,s,t,e,i,o){Dt=Ye.getPrimitive(),oe=Ye.getPrimitive(),Wt.push(Dt,oe),X.setBuffer(c._roots[s]);const n=$s(0,c.geometry,t,e,i,o);X.clearBuffer(),Ye.releasePrimitive(Dt),Ye.releasePrimitive(oe),Wt.pop(),Wt.pop();const r=Wt.length;return r>0&&(oe=Wt[r-1],Dt=Wt[r-2]),n}function $s(c,s,t,e,i=null,o=0,n=0){const{float32Array:r,uint16Array:a,uint32Array:l}=X;let E=c*2;if(ct(E,a)){const h=lt(c,l),u=dt(E,a);return q(c,r,Dt),e(h,u,!1,n,o+c,Dt)}else{let L=function(M){const{uint16Array:U,uint32Array:x}=X;let v=M*2;for(;!ct(v,U);)M=ut(M),v=M*2;return lt(M,x)},w=function(M){const{uint16Array:U,uint32Array:x}=X;let v=M*2;for(;!ct(v,U);)M=It(M,x),v=M*2;return lt(M,x)+dt(v,U)};const h=ut(c),u=It(c,l);let p=h,A=u,F,T,m,g;if(i&&(m=Dt,g=oe,q(p,r,m),q(A,r,g),F=i(m),T=i(g),T<F)){p=u,A=h;const M=F;F=T,T=M,m=g}m||(m=Dt,q(p,r,m));const f=ct(p*2,a),R=t(m,f,F,n+1,o+p);let O;if(R===gi){const M=L(p),x=w(p)-M;O=e(M,x,!0,n+1,o+p,m)}else O=R&&$s(p,s,t,e,i,o,n+1);if(O)return!0;g=oe,q(A,r,g);const _=ct(A*2,a),y=t(g,_,T,n+1,o+A);let N;if(y===gi){const M=L(A),x=w(A)-M;N=e(M,x,!0,n+1,o+A,g)}else N=y&&$s(A,s,t,e,i,o,n+1);return!!N}}const ue=new C.Vector3,Us=new C.Vector3;function Eo(c,s,t={},e=0,i=1/0){const o=e*e,n=i*i;let r=1/0,a=null;if(c.shapecast({boundsTraverseOrder:E=>(ue.copy(s).clamp(E.min,E.max),ue.distanceToSquared(s)),intersectsBounds:(E,d,h)=>h<r&&h<n,intersectsTriangle:(E,d)=>{E.closestPointToPoint(s,ue);const h=s.distanceToSquared(ue);return h<r&&(Us.copy(ue),r=h,a=d),h<o}}),r===1/0)return null;const l=Math.sqrt(r);return t.point?t.point.copy(Us):t.point=Us.clone(),t.distance=l,t.faceIndex=a,t}const Xt=new C.Vector3,Zt=new C.Vector3,Qt=new C.Vector3,Ge=new C.Vector2,ze=new C.Vector2,He=new C.Vector2,Ni=new C.Vector3,Pi=new C.Vector3,Li=new C.Vector3,ke=new C.Vector3;function uo(c,s,t,e,i,o){let n;return o===C.BackSide?n=c.intersectTriangle(e,t,s,!0,i):n=c.intersectTriangle(s,t,e,o!==C.DoubleSide,i),n===null?null:{distance:c.origin.distanceTo(i),point:i.clone()}}function Io(c,s,t,e,i,o,n,r,a){Xt.fromBufferAttribute(s,o),Zt.fromBufferAttribute(s,n),Qt.fromBufferAttribute(s,r);const l=uo(c,Xt,Zt,Qt,ke,a);if(l){e&&(Ge.fromBufferAttribute(e,o),ze.fromBufferAttribute(e,n),He.fromBufferAttribute(e,r),l.uv=C.Triangle.getInterpolation(ke,Xt,Zt,Qt,Ge,ze,He,new C.Vector2)),i&&(Ge.fromBufferAttribute(i,o),ze.fromBufferAttribute(i,n),He.fromBufferAttribute(i,r),l.uv1=C.Triangle.getInterpolation(ke,Xt,Zt,Qt,Ge,ze,He,new C.Vector2)),t&&(Ni.fromBufferAttribute(t,o),Pi.fromBufferAttribute(t,n),Li.fromBufferAttribute(t,r),l.normal=C.Triangle.getInterpolation(ke,Xt,Zt,Qt,Ni,Pi,Li,new C.Vector3),l.normal.dot(c.direction)>0&&l.normal.multiplyScalar(-1));const E={a:o,b:n,c:r,normal:new C.Vector3,materialIndex:0};C.Triangle.getNormal(Xt,Zt,Qt,E.normal),l.face=E,l.faceIndex=o}return l}function gs(c,s,t,e,i){const o=e*3;let n=o+0,r=o+1,a=o+2;const l=c.index;c.index&&(n=l.getX(n),r=l.getX(r),a=l.getX(a));const{position:E,normal:d,uv:h,uv1:u}=c.attributes,p=Io(t,E,d,h,u,n,r,a,s);return p?(p.faceIndex=e,i&&i.push(p),p):null}function J(c,s,t,e){const i=c.a,o=c.b,n=c.c;let r=s,a=s+1,l=s+2;t&&(r=t.getX(r),a=t.getX(a),l=t.getX(l)),i.x=e.getX(r),i.y=e.getY(r),i.z=e.getZ(r),o.x=e.getX(a),o.y=e.getY(a),o.z=e.getZ(a),n.x=e.getX(l),n.y=e.getY(l),n.z=e.getZ(l)}function fo(c,s,t,e,i,o){const{geometry:n,_indirectBuffer:r}=c;for(let a=e,l=e+i;a<l;a++)gs(n,s,t,a,o)}function po(c,s,t,e,i){const{geometry:o,_indirectBuffer:n}=c;let r=1/0,a=null;for(let l=e,E=e+i;l<E;l++){let d;d=gs(o,s,t,l),d&&d.distance<r&&(a=d,r=d.distance)}return a}function Co(c,s,t,e,i,o,n){const{geometry:r}=t,{index:a}=r,l=r.attributes.position;for(let E=c,d=s+c;E<d;E++){let h;if(h=E,J(n,h*3,a,l),n.needsUpdate=!0,e(n,h,i,o))return!0}return!1}function To(c,s=null){s&&Array.isArray(s)&&(s=new Set(s));const t=c.geometry,e=t.index?t.index.array:null,i=t.attributes.position;let o,n,r,a,l=0;const E=c._roots;for(let h=0,u=E.length;h<u;h++)o=E[h],n=new Uint32Array(o),r=new Uint16Array(o),a=new Float32Array(o),d(0,l),l+=o.byteLength;function d(h,u,p=!1){const A=h*2;if(r[A+15]===Fs){const T=n[h+6],m=r[A+14];let g=1/0,f=1/0,R=1/0,O=-1/0,_=-1/0,y=-1/0;for(let N=3*T,L=3*(T+m);N<L;N++){let w=e[N];const M=i.getX(w),U=i.getY(w),x=i.getZ(w);M<g&&(g=M),M>O&&(O=M),U<f&&(f=U),U>_&&(_=U),x<R&&(R=x),x>y&&(y=x)}return a[h+0]!==g||a[h+1]!==f||a[h+2]!==R||a[h+3]!==O||a[h+4]!==_||a[h+5]!==y?(a[h+0]=g,a[h+1]=f,a[h+2]=R,a[h+3]=O,a[h+4]=_,a[h+5]=y,!0):!1}else{const T=h+8,m=n[h+6],g=T+u,f=m+u;let R=p,O=!1,_=!1;s?R||(O=s.has(g),_=s.has(f),R=!O&&!_):(O=!0,_=!0);const y=R||O,N=R||_;let L=!1;y&&(L=d(T,u,R));let w=!1;N&&(w=d(m,u,R));const M=L||w;if(M)for(let U=0;U<3;U++){const x=T+U,v=m+U,z=a[x],j=a[x+3],et=a[v],Z=a[v+3];a[h+U]=z<et?z:et,a[h+U+3]=j>Z?j:Z}return M}}}const Mi=new C.Box3;function Ut(c,s,t,e){return q(c,s,Mi),t.intersectBox(Mi,e)}function mo(c,s,t,e,i,o){const{geometry:n,_indirectBuffer:r}=c;for(let a=e,l=e+i;a<l;a++){let E=r?r[a]:a;gs(n,s,t,E,o)}}function Ro(c,s,t,e,i){const{geometry:o,_indirectBuffer:n}=c;let r=1/0,a=null;for(let l=e,E=e+i;l<E;l++){let d;d=gs(o,s,t,n?n[l]:l),d&&d.distance<r&&(a=d,r=d.distance)}return a}function Ao(c,s,t,e,i,o,n){const{geometry:r}=t,{index:a}=r,l=r.attributes.position;for(let E=c,d=s+c;E<d;E++){let h;if(h=t.resolveTriangleIndex(E),J(n,h*3,a,l),n.needsUpdate=!0,e(n,h,i,o))return!0}return!1}const wi=new C.Vector3;function Fo(c,s,t,e,i){X.setBuffer(c._roots[s]),Ks(0,c,t,e,i),X.clearBuffer()}function Ks(c,s,t,e,i){const{float32Array:o,uint16Array:n,uint32Array:r}=X,a=c*2;if(ct(a,n)){const E=lt(c,r),d=dt(a,n);fo(s,t,e,E,d,i)}else{const E=ut(c);Ut(E,o,e,wi)&&Ks(E,s,t,e,i);const d=It(c,r);Ut(d,o,e,wi)&&Ks(d,s,t,e,i)}}const Di=new C.Vector3,go=["x","y","z"];function Oo(c,s,t,e){X.setBuffer(c._roots[s]);const i=Js(0,c,t,e);return X.clearBuffer(),i}function Js(c,s,t,e){const{float32Array:i,uint16Array:o,uint32Array:n}=X;let r=c*2;if(ct(r,o)){const l=lt(c,n),E=dt(r,o);return po(s,t,e,l,E)}else{const l=hn(c,n),E=go[l],h=e.direction[E]>=0;let u,p;h?(u=ut(c),p=It(c,n)):(u=It(c,n),p=ut(c));const F=Ut(u,i,e,Di)?Js(u,s,t,e):null;if(F){const g=F.point[E];if(h?g<=i[p+l]:g>=i[p+l+3])return F}const m=Ut(p,i,e,Di)?Js(p,s,t,e):null;return F&&m?F.distance<=m.distance?F:m:F||m||null}}const We=new C.Box3,jt=new Rt,qt=new Rt,Ie=new C.Matrix4,Ui=new ot,Xe=new ot;function So(c,s,t,e){X.setBuffer(c._roots[s]);const i=ti(0,c,t,e);return X.clearBuffer(),i}function ti(c,s,t,e,i=null){const{float32Array:o,uint16Array:n,uint32Array:r}=X;let a=c*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Ui.set(t.boundingBox.min,t.boundingBox.max,e),i=Ui),ct(a,n)){const E=s.geometry,d=E.index,h=E.attributes.position,u=t.index,p=t.attributes.position,A=lt(c,r),F=dt(a,n);if(Ie.copy(e).invert(),t.boundsTree)return q(c,o,Xe),Xe.matrix.copy(Ie),Xe.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:m=>Xe.intersectsBox(m),intersectsTriangle:m=>{m.a.applyMatrix4(e),m.b.applyMatrix4(e),m.c.applyMatrix4(e),m.needsUpdate=!0;for(let g=A*3,f=(F+A)*3;g<f;g+=3)if(J(qt,g,d,h),qt.needsUpdate=!0,m.intersectsTriangle(qt))return!0;return!1}});for(let T=A*3,m=(F+A)*3;T<m;T+=3){J(jt,T,d,h),jt.a.applyMatrix4(Ie),jt.b.applyMatrix4(Ie),jt.c.applyMatrix4(Ie),jt.needsUpdate=!0;for(let g=0,f=u.count;g<f;g+=3)if(J(qt,g,u,p),qt.needsUpdate=!0,jt.intersectsTriangle(qt))return!0}}else{const E=c+8,d=r[c+6];return q(E,o,We),!!(i.intersectsBox(We)&&ti(E,s,t,e,i)||(q(d,o,We),i.intersectsBox(We)&&ti(d,s,t,e,i)))}}const Ze=new C.Matrix4,xs=new ot,fe=new ot,_o=new C.Vector3,yo=new C.Vector3,No=new C.Vector3,Po=new C.Vector3;function Lo(c,s,t,e={},i={},o=0,n=1/0){s.boundingBox||s.computeBoundingBox(),xs.set(s.boundingBox.min,s.boundingBox.max,t),xs.needsUpdate=!0;const r=c.geometry,a=r.attributes.position,l=r.index,E=s.attributes.position,d=s.index,h=Et.getPrimitive(),u=Et.getPrimitive();let p=_o,A=yo,F=null,T=null;i&&(F=No,T=Po);let m=1/0,g=null,f=null;return Ze.copy(t).invert(),fe.matrix.copy(Ze),c.shapecast({boundsTraverseOrder:R=>xs.distanceToBox(R),intersectsBounds:(R,O,_)=>_<m&&_<n?(O&&(fe.min.copy(R.min),fe.max.copy(R.max),fe.needsUpdate=!0),!0):!1,intersectsRange:(R,O)=>{if(s.boundsTree)return s.boundsTree.shapecast({boundsTraverseOrder:y=>fe.distanceToBox(y),intersectsBounds:(y,N,L)=>L<m&&L<n,intersectsRange:(y,N)=>{for(let L=y,w=y+N;L<w;L++){J(u,3*L,d,E),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let M=R,U=R+O;M<U;M++){J(h,3*M,l,a),h.needsUpdate=!0;const x=h.distanceToTriangle(u,p,F);if(x<m&&(A.copy(p),T&&T.copy(F),m=x,g=M,f=L),x<o)return!0}}}});{const _=le(s);for(let y=0,N=_;y<N;y++){J(u,3*y,d,E),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let L=R,w=R+O;L<w;L++){J(h,3*L,l,a),h.needsUpdate=!0;const M=h.distanceToTriangle(u,p,F);if(M<m&&(A.copy(p),T&&T.copy(F),m=M,g=L,f=y),M<o)return!0}}}}}),Et.releasePrimitive(h),Et.releasePrimitive(u),m===1/0?null:(e.point?e.point.copy(A):e.point=A.clone(),e.distance=m,e.faceIndex=g,i&&(i.point?i.point.copy(T):i.point=T.clone(),i.point.applyMatrix4(Ze),A.applyMatrix4(Ze),i.distance=A.sub(i.point).length(),i.faceIndex=f),e)}function Mo(c,s=null){s&&Array.isArray(s)&&(s=new Set(s));const t=c.geometry,e=t.index?t.index.array:null,i=t.attributes.position;let o,n,r,a,l=0;const E=c._roots;for(let h=0,u=E.length;h<u;h++)o=E[h],n=new Uint32Array(o),r=new Uint16Array(o),a=new Float32Array(o),d(0,l),l+=o.byteLength;function d(h,u,p=!1){const A=h*2;if(r[A+15]===Fs){const T=n[h+6],m=r[A+14];let g=1/0,f=1/0,R=1/0,O=-1/0,_=-1/0,y=-1/0;for(let N=T,L=T+m;N<L;N++){const w=3*c.resolveTriangleIndex(N);for(let M=0;M<3;M++){let U=w+M;U=e?e[U]:U;const x=i.getX(U),v=i.getY(U),z=i.getZ(U);x<g&&(g=x),x>O&&(O=x),v<f&&(f=v),v>_&&(_=v),z<R&&(R=z),z>y&&(y=z)}}return a[h+0]!==g||a[h+1]!==f||a[h+2]!==R||a[h+3]!==O||a[h+4]!==_||a[h+5]!==y?(a[h+0]=g,a[h+1]=f,a[h+2]=R,a[h+3]=O,a[h+4]=_,a[h+5]=y,!0):!1}else{const T=h+8,m=n[h+6],g=T+u,f=m+u;let R=p,O=!1,_=!1;s?R||(O=s.has(g),_=s.has(f),R=!O&&!_):(O=!0,_=!0);const y=R||O,N=R||_;let L=!1;y&&(L=d(T,u,R));let w=!1;N&&(w=d(m,u,R));const M=L||w;if(M)for(let U=0;U<3;U++){const x=T+U,v=m+U,z=a[x],j=a[x+3],et=a[v],Z=a[v+3];a[h+U]=z<et?z:et,a[h+U+3]=j>Z?j:Z}return M}}}const xi=new C.Vector3;function wo(c,s,t,e,i){X.setBuffer(c._roots[s]),ei(0,c,t,e,i),X.clearBuffer()}function ei(c,s,t,e,i){const{float32Array:o,uint16Array:n,uint32Array:r}=X,a=c*2;if(ct(a,n)){const E=lt(c,r),d=dt(a,n);mo(s,t,e,E,d,i)}else{const E=ut(c);Ut(E,o,e,xi)&&ei(E,s,t,e,i);const d=It(c,r);Ut(d,o,e,xi)&&ei(d,s,t,e,i)}}const bi=new C.Vector3,Do=["x","y","z"];function Uo(c,s,t,e){X.setBuffer(c._roots[s]);const i=si(0,c,t,e);return X.clearBuffer(),i}function si(c,s,t,e){const{float32Array:i,uint16Array:o,uint32Array:n}=X;let r=c*2;if(ct(r,o)){const l=lt(c,n),E=dt(r,o);return Ro(s,t,e,l,E)}else{const l=hn(c,n),E=Do[l],h=e.direction[E]>=0;let u,p;h?(u=ut(c),p=It(c,n)):(u=It(c,n),p=ut(c));const F=Ut(u,i,e,bi)?si(u,s,t,e):null;if(F){const g=F.point[E];if(h?g<=i[p+l]:g>=i[p+l+3])return F}const m=Ut(p,i,e,bi)?si(p,s,t,e):null;return F&&m?F.distance<=m.distance?F:m:F||m||null}}const Qe=new C.Box3,$t=new Rt,Kt=new Rt,pe=new C.Matrix4,vi=new ot,je=new ot;function xo(c,s,t,e){X.setBuffer(c._roots[s]);const i=ii(0,c,t,e);return X.clearBuffer(),i}function ii(c,s,t,e,i=null){const{float32Array:o,uint16Array:n,uint32Array:r}=X;let a=c*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),vi.set(t.boundingBox.min,t.boundingBox.max,e),i=vi),ct(a,n)){const E=s.geometry,d=E.index,h=E.attributes.position,u=t.index,p=t.attributes.position,A=lt(c,r),F=dt(a,n);if(pe.copy(e).invert(),t.boundsTree)return q(c,o,je),je.matrix.copy(pe),je.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:m=>je.intersectsBox(m),intersectsTriangle:m=>{m.a.applyMatrix4(e),m.b.applyMatrix4(e),m.c.applyMatrix4(e),m.needsUpdate=!0;for(let g=A,f=F+A;g<f;g++)if(J(Kt,3*s.resolveTriangleIndex(g),d,h),Kt.needsUpdate=!0,m.intersectsTriangle(Kt))return!0;return!1}});for(let T=A,m=F+A;T<m;T++){const g=s.resolveTriangleIndex(T);J($t,3*g,d,h),$t.a.applyMatrix4(pe),$t.b.applyMatrix4(pe),$t.c.applyMatrix4(pe),$t.needsUpdate=!0;for(let f=0,R=u.count;f<R;f+=3)if(J(Kt,f,u,p),Kt.needsUpdate=!0,$t.intersectsTriangle(Kt))return!0}}else{const E=c+8,d=r[c+6];return q(E,o,Qe),!!(i.intersectsBox(Qe)&&ii(E,s,t,e,i)||(q(d,o,Qe),i.intersectsBox(Qe)&&ii(d,s,t,e,i)))}}const qe=new C.Matrix4,bs=new ot,Ce=new ot,bo=new C.Vector3,vo=new C.Vector3,Bo=new C.Vector3,Vo=new C.Vector3;function Yo(c,s,t,e={},i={},o=0,n=1/0){s.boundingBox||s.computeBoundingBox(),bs.set(s.boundingBox.min,s.boundingBox.max,t),bs.needsUpdate=!0;const r=c.geometry,a=r.attributes.position,l=r.index,E=s.attributes.position,d=s.index,h=Et.getPrimitive(),u=Et.getPrimitive();let p=bo,A=vo,F=null,T=null;i&&(F=Bo,T=Vo);let m=1/0,g=null,f=null;return qe.copy(t).invert(),Ce.matrix.copy(qe),c.shapecast({boundsTraverseOrder:R=>bs.distanceToBox(R),intersectsBounds:(R,O,_)=>_<m&&_<n?(O&&(Ce.min.copy(R.min),Ce.max.copy(R.max),Ce.needsUpdate=!0),!0):!1,intersectsRange:(R,O)=>{if(s.boundsTree){const _=s.boundsTree;return _.shapecast({boundsTraverseOrder:y=>Ce.distanceToBox(y),intersectsBounds:(y,N,L)=>L<m&&L<n,intersectsRange:(y,N)=>{for(let L=y,w=y+N;L<w;L++){const M=_.resolveTriangleIndex(L);J(u,3*M,d,E),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let U=R,x=R+O;U<x;U++){const v=c.resolveTriangleIndex(U);J(h,3*v,l,a),h.needsUpdate=!0;const z=h.distanceToTriangle(u,p,F);if(z<m&&(A.copy(p),T&&T.copy(F),m=z,g=U,f=L),z<o)return!0}}}})}else{const _=le(s);for(let y=0,N=_;y<N;y++){J(u,3*y,d,E),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let L=R,w=R+O;L<w;L++){const M=c.resolveTriangleIndex(L);J(h,3*M,l,a),h.needsUpdate=!0;const U=h.distanceToTriangle(u,p,F);if(U<m&&(A.copy(p),T&&T.copy(F),m=U,g=L,f=y),U<o)return!0}}}}}),Et.releasePrimitive(h),Et.releasePrimitive(u),m===1/0?null:(e.point?e.point.copy(A):e.point=A.clone(),e.distance=m,e.faceIndex=g,i&&(i.point?i.point.copy(T):i.point=T.clone(),i.point.applyMatrix4(qe),A.applyMatrix4(qe),i.distance=A.sub(i.point).length(),i.faceIndex=f),e)}function Go(){return typeof SharedArrayBuffer<"u"}const ye=new X.constructor,ls=new X.constructor,Mt=new Ci(()=>new C.Box3),Jt=new C.Box3,te=new C.Box3,vs=new C.Box3,Bs=new C.Box3;let Vs=!1;function zo(c,s,t,e){if(Vs)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Vs=!0;const i=c._roots,o=s._roots;let n,r=0,a=0;const l=new C.Matrix4().copy(t).invert();for(let E=0,d=i.length;E<d;E++){ye.setBuffer(i[E]),a=0;const h=Mt.getPrimitive();q(0,ye.float32Array,h),h.applyMatrix4(l);for(let u=0,p=o.length;u<p&&(ls.setBuffer(o[E]),n=pt(0,0,t,l,e,r,a,0,0,h),ls.clearBuffer(),a+=o[u].length,!n);u++);if(Mt.releasePrimitive(h),ye.clearBuffer(),r+=i[E].length,n)break}return Vs=!1,n}function pt(c,s,t,e,i,o=0,n=0,r=0,a=0,l=null,E=!1){let d,h;E?(d=ls,h=ye):(d=ye,h=ls);const u=d.float32Array,p=d.uint32Array,A=d.uint16Array,F=h.float32Array,T=h.uint32Array,m=h.uint16Array,g=c*2,f=s*2,R=ct(g,A),O=ct(f,m);let _=!1;if(O&&R)E?_=i(lt(s,T),dt(s*2,m),lt(c,p),dt(c*2,A),a,n+s,r,o+c):_=i(lt(c,p),dt(c*2,A),lt(s,T),dt(s*2,m),r,o+c,a,n+s);else if(O){const y=Mt.getPrimitive();q(s,F,y),y.applyMatrix4(t);const N=ut(c),L=It(c,p);q(N,u,Jt),q(L,u,te);const w=y.intersectsBox(Jt),M=y.intersectsBox(te);_=w&&pt(s,N,e,t,i,n,o,a,r+1,y,!E)||M&&pt(s,L,e,t,i,n,o,a,r+1,y,!E),Mt.releasePrimitive(y)}else{const y=ut(s),N=It(s,T);q(y,F,vs),q(N,F,Bs);const L=l.intersectsBox(vs),w=l.intersectsBox(Bs);if(L&&w)_=pt(c,y,t,e,i,o,n,r,a+1,l,E)||pt(c,N,t,e,i,o,n,r,a+1,l,E);else if(L)if(R)_=pt(c,y,t,e,i,o,n,r,a+1,l,E);else{const M=Mt.getPrimitive();M.copy(vs).applyMatrix4(t);const U=ut(c),x=It(c,p);q(U,u,Jt),q(x,u,te);const v=M.intersectsBox(Jt),z=M.intersectsBox(te);_=v&&pt(y,U,e,t,i,n,o,a,r+1,M,!E)||z&&pt(y,x,e,t,i,n,o,a,r+1,M,!E),Mt.releasePrimitive(M)}else if(w)if(R)_=pt(c,N,t,e,i,o,n,r,a+1,l,E);else{const M=Mt.getPrimitive();M.copy(Bs).applyMatrix4(t);const U=ut(c),x=It(c,p);q(U,u,Jt),q(x,u,te);const v=M.intersectsBox(Jt),z=M.intersectsBox(te);_=v&&pt(N,U,e,t,i,n,o,a,r+1,M,!E)||z&&pt(N,x,e,t,i,n,o,a,r+1,M,!E),Mt.releasePrimitive(M)}}return _}const $e=new ot,Bi=new C.Box3;class Ti{static serialize(s,t={}){t={cloneBuffers:!0,...t};const e=s.geometry,i=s._roots,o=s._indirectBuffer,n=e.getIndex();let r;return t.cloneBuffers?r={roots:i.map(a=>a.slice()),index:n.array.slice(),indirectBuffer:o?o.slice():null}:r={roots:i,index:n.array,indirectBuffer:o},r}static deserialize(s,t,e={}){e={setIndex:!0,indirect:!!s.indirectBuffer,...e};const{index:i,roots:o,indirectBuffer:n}=s,r=new Ti(t,{...e,[Ms]:!0});if(r._roots=o,r._indirectBuffer=n||null,e.setIndex){const a=t.getIndex();if(a===null){const l=new C.BufferAttribute(s.index,1,!1);t.setIndex(l)}else a.array!==i&&(a.array.set(i),a.needsUpdate=!0)}return r}get indirect(){return!!this._indirectBuffer}constructor(s,t={}){if(s.isBufferGeometry){if(s.index&&s.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t=Object.assign({strategy:an,maxDepth:40,maxLeafTris:10,verbose:!0,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,[Ms]:!1},t),t.useSharedArrayBuffer&&!Go())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=s,this._roots=null,this._indirectBuffer=null,t[Ms]||(no(this,t),!s.boundingBox&&t.setBoundingBox&&(s.boundingBox=this.getBoundingBox(new C.Box3)));const{_indirectBuffer:e}=this;this.resolveTriangleIndex=t.indirect?i=>e[i]:i=>i}refit(s=null){return(this.indirect?Mo:To)(this,s)}traverse(s,t=0){const e=this._roots[t],i=new Uint32Array(e),o=new Uint16Array(e);n(0);function n(r,a=0){const l=r*2,E=o[l+15]===Fs;if(E){const d=i[r+6],h=o[l+14];s(a,E,new Float32Array(e,r*4,6),d,h)}else{const d=r+rs/4,h=i[r+6],u=i[r+7];s(a,E,new Float32Array(e,r*4,6),u)||(n(d,a+1),n(h,a+1))}}}raycast(s,t=C.FrontSide){const e=this._roots,i=this.geometry,o=[],n=t.isMaterial,r=Array.isArray(t),a=i.groups,l=n?t.side:t,E=this.indirect?wo:Fo;for(let d=0,h=e.length;d<h;d++){const u=r?t[a[d].materialIndex].side:l,p=o.length;if(E(this,d,u,s,o),r){const A=a[d].materialIndex;for(let F=p,T=o.length;F<T;F++)o[F].face.materialIndex=A}}return o}raycastFirst(s,t=C.FrontSide){const e=this._roots,i=this.geometry,o=t.isMaterial,n=Array.isArray(t);let r=null;const a=i.groups,l=o?t.side:t,E=this.indirect?Uo:Oo;for(let d=0,h=e.length;d<h;d++){const u=n?t[a[d].materialIndex].side:l,p=E(this,d,u,s);p!=null&&(r==null||p.distance<r.distance)&&(r=p,n&&(p.face.materialIndex=a[d].materialIndex))}return r}intersectsGeometry(s,t){let e=!1;const i=this._roots,o=this.indirect?xo:So;for(let n=0,r=i.length;n<r&&(e=o(this,n,s,t),!e);n++);return e}shapecast(s){const t=Et.getPrimitive(),e=this.indirect?Ao:Co;let{boundsTraverseOrder:i,intersectsBounds:o,intersectsRange:n,intersectsTriangle:r}=s;if(n&&r){const d=n;n=(h,u,p,A,F)=>d(h,u,p,A,F)?!0:e(h,u,this,r,p,A,t)}else n||(r?n=(d,h,u,p)=>e(d,h,this,r,u,p,t):n=(d,h,u)=>u);let a=!1,l=0;const E=this._roots;for(let d=0,h=E.length;d<h;d++){const u=E[d];if(a=ho(this,d,o,n,i,l),a)break;l+=u.byteLength}return Et.releasePrimitive(t),a}bvhcast(s,t,e){let{intersectsRanges:i,intersectsTriangles:o}=e;const n=Et.getPrimitive(),r=this.geometry.index,a=this.geometry.attributes.position,l=this.indirect?p=>{const A=this.resolveTriangleIndex(p);J(n,A*3,r,a)}:p=>{J(n,p*3,r,a)},E=Et.getPrimitive(),d=s.geometry.index,h=s.geometry.attributes.position,u=s.indirect?p=>{const A=s.resolveTriangleIndex(p);J(E,A*3,d,h)}:p=>{J(E,p*3,d,h)};if(o){const p=(A,F,T,m,g,f,R,O)=>{for(let _=T,y=T+m;_<y;_++){u(_),E.a.applyMatrix4(t),E.b.applyMatrix4(t),E.c.applyMatrix4(t),E.needsUpdate=!0;for(let N=A,L=A+F;N<L;N++)if(l(N),n.needsUpdate=!0,o(n,E,N,_,g,f,R,O))return!0}return!1};if(i){const A=i;i=function(F,T,m,g,f,R,O,_){return A(F,T,m,g,f,R,O,_)?!0:p(F,T,m,g,f,R,O,_)}}else i=p}return zo(this,s,t,i)}intersectsBox(s,t){return $e.set(s.min,s.max,t),$e.needsUpdate=!0,this.shapecast({intersectsBounds:e=>$e.intersectsBox(e),intersectsTriangle:e=>$e.intersectsTriangle(e)})}intersectsSphere(s){return this.shapecast({intersectsBounds:t=>s.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(s)})}closestPointToGeometry(s,t,e={},i={},o=0,n=1/0){return(this.indirect?Yo:Lo)(this,s,t,e,i,o,n)}closestPointToPoint(s,t={},e=0,i=1/0){return Eo(this,s,t,e,i)}getBoundingBox(s){return s.makeEmpty(),this._roots.forEach(e=>{q(0,new Float32Array(e),Bi),s.union(Bi)}),s}}function Vi(c,s,t){return c===null||(c.point.applyMatrix4(s.matrixWorld),c.distance=c.point.distanceTo(t.ray.origin),c.object=s,c.distance<t.near||c.distance>t.far)?null:c}const Ys=new C.Ray,Yi=new C.Matrix4,Ho=C.Mesh.prototype.raycast;function ko(c,s){if(this.geometry.boundsTree){if(this.material===void 0)return;Yi.copy(this.matrixWorld).invert(),Ys.copy(c.ray).applyMatrix4(Yi);const t=this.geometry.boundsTree;if(c.firstHitOnly===!0){const e=Vi(t.raycastFirst(Ys,this.material),this,c);e&&s.push(e)}else{const e=t.raycast(Ys,this.material);for(let i=0,o=e.length;i<o;i++){const n=Vi(e[i],this,c);n&&s.push(n)}}}else Ho.call(this,c,s)}function Wo(c){return this.boundsTree=new Ti(this,c),this.boundsTree}function Xo(){this.boundsTree=null}class D{constructor(){I(this,"trigger",s=>{const t=this.handlers.slice(0);for(const e of t)e(s)});I(this,"handlers",[])}add(s){this.handlers.push(s)}remove(s){this.handlers=this.handlers.filter(t=>t!==s)}reset(){this.handlers.length=0}}class Os{constructor(s){I(this,"isDisposeable",()=>"dispose"in this&&"onDisposed"in this);I(this,"isResizeable",()=>"resize"in this&&"getSize"in this);I(this,"isUpdateable",()=>"onAfterUpdate"in this&&"onBeforeUpdate"in this&&"update"in this);I(this,"isHideable",()=>"visible"in this);I(this,"isConfigurable",()=>"setup"in this&&"config"in this&&"onSetup"in this);this.components=s}}class tt extends Os{}class Ss extends Os{constructor(t){super(t);I(this,"worlds",new Map);I(this,"onWorldChanged",new D);I(this,"currentWorld",null);this.onWorldChanged.add(({world:e,action:i})=>{i==="removed"&&this.worlds.delete(e.uuid)})}}class En extends Ss{constructor(){super(...arguments);I(this,"hasCameraControls",()=>"controls"in this)}}class dn extends Ss{constructor(){super(...arguments);I(this,"onAfterUpdate",new D);I(this,"onBeforeUpdate",new D);I(this,"onDisposed",new D);I(this,"onResize",new D);I(this,"onClippingPlanesUpdated",new D);I(this,"clippingPlanes",[])}updateClippingPlanes(){this.onClippingPlanesUpdated.trigger()}setPlane(t,e,i){e.isLocal=i;const o=this.clippingPlanes.indexOf(e);t&&o===-1?this.clippingPlanes.push(e):!t&&o>-1&&this.clippingPlanes.splice(o,1),this.three.clippingPlanes=this.clippingPlanes.filter(n=>!n.isLocal)}}const Ne=class Ne extends tt{constructor(t){super(t);I(this,"_disposedComponents",new Set);I(this,"enabled",!0);t.add(Ne.uuid,this)}get(){return this._disposedComponents}destroy(t,e=!0,i=!0){t.removeFromParent();const o=t;o.dispose&&o.dispose(),this.disposeGeometryAndMaterials(t,e),i&&o.children&&o.children.length&&this.disposeChildren(o),t.children.length=0}disposeGeometry(t){const e=t;e.boundsTree&&e.disposeBoundsTree(),t.dispose()}disposeGeometryAndMaterials(t,e){const i=t;i.geometry&&this.disposeGeometry(i.geometry),e&&i.material&&Ne.disposeMaterial(i),i.material=[],i.geometry=null}disposeChildren(t){for(const e of t.children)this.destroy(e)}static disposeMaterial(t){if(t.material)if(Array.isArray(t.material))for(const e of t.material)e.dispose();else t.material.dispose()}};I(Ne,"uuid","76e9cd8e-ad8f-4753-9ef6-cbc60f7247fe");let yt=Ne;class un extends Ss{constructor(t){super(t);I(this,"onDisposed",new D)}dispose(){const t=this.components.get(yt);for(const e of this.three.children){const i=e;i.geometry&&t.destroy(i)}this.three.children=[],this.onDisposed.trigger(),this.onDisposed.reset()}}const as=0,Zo=1,Qo=new C.Vector3,Gi=new C.Line3,Gs=new C.Plane,zi=new C.Vector3,Ke=new C.Triangle;class jo{constructor(){this.tolerance=-1,this.faces=[],this.newFaces=[],this.assigned=new Hi,this.unassigned=new Hi,this.vertices=[]}setFromPoints(s){if(s.length>=4){this.makeEmpty();for(let t=0,e=s.length;t<e;t++)this.vertices.push(new qo(s[t]));this.compute()}return this}setFromObject(s){const t=[];return s.updateMatrixWorld(!0),s.traverse(function(e){const i=e.geometry;if(i!==void 0){const o=i.attributes.position;if(o!==void 0)for(let n=0,r=o.count;n<r;n++){const a=new C.Vector3;a.fromBufferAttribute(o,n).applyMatrix4(e.matrixWorld),t.push(a)}}}),this.setFromPoints(t)}containsPoint(s){const t=this.faces;for(let e=0,i=t.length;e<i;e++)if(t[e].distanceToPoint(s)>this.tolerance)return!1;return!0}intersectRay(s,t){const e=this.faces;let i=-1/0,o=1/0;for(let n=0,r=e.length;n<r;n++){const a=e[n],l=a.distanceToPoint(s.origin),E=a.normal.dot(s.direction);if(l>0&&E>=0)return null;const d=E!==0?-l/E:0;if(!(d<=0)&&(E>0?o=Math.min(d,o):i=Math.max(d,i),i>o))return null}return i!==-1/0?s.at(i,t):s.at(o,t),t}intersectsRay(s){return this.intersectRay(s,Qo)!==null}makeEmpty(){return this.faces=[],this.vertices=[],this}addVertexToFace(s,t){return s.face=t,t.outside===null?this.assigned.append(s):this.assigned.insertBefore(t.outside,s),t.outside=s,this}removeVertexFromFace(s,t){return s===t.outside&&(s.next!==null&&s.next.face===t?t.outside=s.next:t.outside=null),this.assigned.remove(s),this}removeAllVerticesFromFace(s){if(s.outside!==null){const t=s.outside;let e=s.outside;for(;e.next!==null&&e.next.face===s;)e=e.next;return this.assigned.removeSubList(t,e),t.prev=e.next=null,s.outside=null,t}}deleteFaceVertices(s,t){const e=this.removeAllVerticesFromFace(s);if(e!==void 0)if(t===void 0)this.unassigned.appendChain(e);else{let i=e;do{const o=i.next;t.distanceToPoint(i.point)>this.tolerance?this.addVertexToFace(i,t):this.unassigned.append(i),i=o}while(i!==null)}return this}resolveUnassignedPoints(s){if(this.unassigned.isEmpty()===!1){let t=this.unassigned.first();do{const e=t.next;let i=this.tolerance,o=null;for(let n=0;n<s.length;n++){const r=s[n];if(r.mark===as){const a=r.distanceToPoint(t.point);if(a>i&&(i=a,o=r),i>1e3*this.tolerance)break}}o!==null&&this.addVertexToFace(t,o),t=e}while(t!==null)}return this}computeExtremes(){const s=new C.Vector3,t=new C.Vector3,e=[],i=[];for(let o=0;o<3;o++)e[o]=i[o]=this.vertices[0];s.copy(this.vertices[0].point),t.copy(this.vertices[0].point);for(let o=0,n=this.vertices.length;o<n;o++){const r=this.vertices[o],a=r.point;for(let l=0;l<3;l++)a.getComponent(l)<s.getComponent(l)&&(s.setComponent(l,a.getComponent(l)),e[l]=r);for(let l=0;l<3;l++)a.getComponent(l)>t.getComponent(l)&&(t.setComponent(l,a.getComponent(l)),i[l]=r)}return this.tolerance=3*Number.EPSILON*(Math.max(Math.abs(s.x),Math.abs(t.x))+Math.max(Math.abs(s.y),Math.abs(t.y))+Math.max(Math.abs(s.z),Math.abs(t.z))),{min:e,max:i}}computeInitialHull(){const s=this.vertices,t=this.computeExtremes(),e=t.min,i=t.max;let o=0,n=0;for(let h=0;h<3;h++){const u=i[h].point.getComponent(h)-e[h].point.getComponent(h);u>o&&(o=u,n=h)}const r=e[n],a=i[n];let l,E;o=0,Gi.set(r.point,a.point);for(let h=0,u=this.vertices.length;h<u;h++){const p=s[h];if(p!==r&&p!==a){Gi.closestPointToPoint(p.point,!0,zi);const A=zi.distanceToSquared(p.point);A>o&&(o=A,l=p)}}o=-1,Gs.setFromCoplanarPoints(r.point,a.point,l.point);for(let h=0,u=this.vertices.length;h<u;h++){const p=s[h];if(p!==r&&p!==a&&p!==l){const A=Math.abs(Gs.distanceToPoint(p.point));A>o&&(o=A,E=p)}}const d=[];if(Gs.distanceToPoint(E.point)<0){d.push(Tt.create(r,a,l),Tt.create(E,a,r),Tt.create(E,l,a),Tt.create(E,r,l));for(let h=0;h<3;h++){const u=(h+1)%3;d[h+1].getEdge(2).setTwin(d[0].getEdge(u)),d[h+1].getEdge(1).setTwin(d[u+1].getEdge(0))}}else{d.push(Tt.create(r,l,a),Tt.create(E,r,a),Tt.create(E,a,l),Tt.create(E,l,r));for(let h=0;h<3;h++){const u=(h+1)%3;d[h+1].getEdge(2).setTwin(d[0].getEdge((3-h)%3)),d[h+1].getEdge(0).setTwin(d[u+1].getEdge(1))}}for(let h=0;h<4;h++)this.faces.push(d[h]);for(let h=0,u=s.length;h<u;h++){const p=s[h];if(p!==r&&p!==a&&p!==l&&p!==E){o=this.tolerance;let A=null;for(let F=0;F<4;F++){const T=this.faces[F].distanceToPoint(p.point);T>o&&(o=T,A=this.faces[F])}A!==null&&this.addVertexToFace(p,A)}}return this}reindexFaces(){const s=[];for(let t=0;t<this.faces.length;t++){const e=this.faces[t];e.mark===as&&s.push(e)}return this.faces=s,this}nextVertexToAdd(){if(this.assigned.isEmpty()===!1){let s,t=0;const e=this.assigned.first().face;let i=e.outside;do{const o=e.distanceToPoint(i.point);o>t&&(t=o,s=i),i=i.next}while(i!==null&&i.face===e);return s}}computeHorizon(s,t,e,i){this.deleteFaceVertices(e),e.mark=Zo;let o;t===null?o=t=e.getEdge(0):o=t.next;do{const n=o.twin,r=n.face;r.mark===as&&(r.distanceToPoint(s)>this.tolerance?this.computeHorizon(s,n,r,i):i.push(o)),o=o.next}while(o!==t);return this}addAdjoiningFace(s,t){const e=Tt.create(s,t.tail(),t.head());return this.faces.push(e),e.getEdge(-1).setTwin(t.twin),e.getEdge(0)}addNewFaces(s,t){this.newFaces=[];let e=null,i=null;for(let o=0;o<t.length;o++){const n=t[o],r=this.addAdjoiningFace(s,n);e===null?e=r:r.next.setTwin(i),this.newFaces.push(r.face),i=r}return e.next.setTwin(i),this}addVertexToHull(s){const t=[];return this.unassigned.clear(),this.removeVertexFromFace(s,s.face),this.computeHorizon(s.point,null,s.face,t),this.addNewFaces(s,t),this.resolveUnassignedPoints(this.newFaces),this}cleanup(){return this.assigned.clear(),this.unassigned.clear(),this.newFaces=[],this}compute(){let s;for(this.computeInitialHull();(s=this.nextVertexToAdd())!==void 0;)this.addVertexToHull(s);return this.reindexFaces(),this.cleanup(),this}}class Tt{constructor(){this.normal=new C.Vector3,this.midpoint=new C.Vector3,this.area=0,this.constant=0,this.outside=null,this.mark=as,this.edge=null}static create(s,t,e){const i=new Tt,o=new zs(s,i),n=new zs(t,i),r=new zs(e,i);return o.next=r.prev=n,n.next=o.prev=r,r.next=n.prev=o,i.edge=o,i.compute()}getEdge(s){let t=this.edge;for(;s>0;)t=t.next,s--;for(;s<0;)t=t.prev,s++;return t}compute(){const s=this.edge.tail(),t=this.edge.head(),e=this.edge.next.head();return Ke.set(s.point,t.point,e.point),Ke.getNormal(this.normal),Ke.getMidpoint(this.midpoint),this.area=Ke.getArea(),this.constant=this.normal.dot(this.midpoint),this}distanceToPoint(s){return this.normal.dot(s)-this.constant}}class zs{constructor(s,t){this.vertex=s,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 s=this.head(),t=this.tail();return t!==null?t.point.distanceTo(s.point):-1}lengthSquared(){const s=this.head(),t=this.tail();return t!==null?t.point.distanceToSquared(s.point):-1}setTwin(s){return this.twin=s,s.twin=this,this}}class qo{constructor(s){this.point=s,this.prev=null,this.next=null,this.face=null}}class Hi{constructor(){this.head=null,this.tail=null}first(){return this.head}last(){return this.tail}clear(){return this.head=this.tail=null,this}insertBefore(s,t){return t.prev=s.prev,t.next=s,t.prev===null?this.head=t:t.prev.next=t,s.prev=t,this}insertAfter(s,t){return t.prev=s,t.next=s.next,t.next===null?this.tail=t:t.next.prev=t,s.next=t,this}append(s){return this.head===null?this.head=s:this.tail.next=s,s.prev=this.tail,s.next=null,this.tail=s,this}appendChain(s){for(this.head===null?this.head=s:this.tail.next=s,s.prev=this.tail;s.next!==null;)s=s.next;return this.tail=s,this}remove(s){return s.prev===null?this.head=s.next:s.prev.next=s.next,s.next===null?this.tail=s.prev:s.next.prev=s.prev,this}removeSubList(s,t){return s.prev===null?this.head=t.next:s.prev.next=t.next,t.next===null?this.tail=s.prev:t.next.prev=s.prev,this}isEmpty(){return this.head===null}}const ni=[2,2,1],oi=[1,0,0];function Ot(c,s){return c*3+s}function $o(c){const s=c.elements;let t=0;for(let e=0;e<9;e++)t+=s[e]*s[e];return Math.sqrt(t)}function Ko(c){const s=c.elements;let t=0;for(let e=0;e<3;e++){const i=s[Ot(ni[e],oi[e])];t+=2*i*i}return Math.sqrt(t)}function Jo(c,s){let t=0,e=1;const i=c.elements;for(let l=0;l<3;l++){const E=Math.abs(i[Ot(ni[l],oi[l])]);E>t&&(t=E,e=l)}let o=1,n=0;const r=oi[e],a=ni[e];if(Math.abs(i[Ot(a,r)])>Number.EPSILON){const l=i[Ot(a,a)],E=i[Ot(r,r)],d=i[Ot(a,r)],h=(l-E)/2/d;let u;h<0?u=-1/(-h+Math.sqrt(1+h*h)):u=1/(h+Math.sqrt(1+h*h)),o=1/Math.sqrt(1+u*u),n=u*o}return s.identity(),s.elements[Ot(r,r)]=o,s.elements[Ot(a,a)]=o,s.elements[Ot(a,r)]=n,s.elements[Ot(r,a)]=-n,s}function tr(c,s){let t=0,e=0;const i=10;s.unitary.identity(),s.diagonal.copy(c);const o=s.unitary,n=s.diagonal,r=new S.Matrix3,a=new S.Matrix3,l=Number.EPSILON*$o(n);for(;e<i&&Ko(n)>l;)Jo(n,r),a.copy(r).transpose(),n.multiply(r),n.premultiply(a),o.multiply(r),++t>2&&(e++,t=0);return s}function In(c){const s=[];for(let st=0;st<c.length-2;st+=3){const Bt=c[st],K=c[st+1],kt=c[st+2];s.push(new S.Vector3(Bt,K,kt))}const t=new jo;t.setFromPoints(s);const e={unitary:new S.Matrix3,diagonal:new S.Matrix3},i=t.faces,o=[],n=[];for(let st=0,Bt=i.length;st<Bt;st++){const K=i[st];let kt=K.edge;o.length=0;do o.push(kt),kt=kt.next;while(kt!==K.edge);const bn=o.length-2;for(let be=1,vn=bn;be<=vn;be++){const ys=o[0].vertex,Ns=o[be+0].vertex,Ps=o[be+1].vertex;n.push(ys.point.x,ys.point.y,ys.point.z),n.push(Ns.point.x,Ns.point.y,Ns.point.z),n.push(Ps.point.x,Ps.point.y,Ps.point.z)}}const r=new S.Vector3,a=new S.Vector3,l=new S.Vector3,E=new S.Vector3,d=new S.Vector3,h=new S.Vector3,u=new S.Vector3,p=new S.Vector3;let A=0,F=0,T=0,m=0,g=0,f=0,R=0;for(let st=0,Bt=n.length;st<Bt;st+=9){r.fromArray(n,st),a.fromArray(n,st+3),l.fromArray(n,st+6),u.set(0,0,0),u.add(r).add(a).add(l).divideScalar(3),E.subVectors(a,r),d.subVectors(l,r);const K=h.crossVectors(E,d).length()/2;p.add(h.copy(u).multiplyScalar(K)),A+=K,F+=(9*u.x*u.x+r.x*r.x+a.x*a.x+l.x*l.x)*(K/12),T+=(9*u.x*u.y+r.x*r.y+a.x*a.y+l.x*l.y)*(K/12),m+=(9*u.x*u.z+r.x*r.z+a.x*a.z+l.x*l.z)*(K/12),g+=(9*u.y*u.y+r.y*r.y+a.y*a.y+l.y*l.y)*(K/12),f+=(9*u.y*u.z+r.y*r.z+a.y*a.z+l.y*l.z)*(K/12),R+=(9*u.z*u.z+r.z*r.z+a.z*a.z+l.z*l.z)*(K/12)}p.divideScalar(A),F/=A,T/=A,m/=A,g/=A,f/=A,R/=A,F-=p.x*p.x,T-=p.x*p.y,m-=p.x*p.z,g-=p.y*p.y,f-=p.y*p.z,R-=p.z*p.z;const O=new S.Matrix3;O.elements[0]=F,O.elements[1]=T,O.elements[2]=m,O.elements[3]=T,O.elements[4]=g,O.elements[5]=f,O.elements[6]=m,O.elements[7]=f,O.elements[8]=R,tr(O,e);const _=e.unitary,y=new S.Vector3,N=new S.Vector3,L=new S.Vector3;_.extractBasis(y,N,L);let w=-1/0,M=-1/0,U=-1/0,x=1/0,v=1/0,z=1/0;for(let st=0,Bt=s.length;st<Bt;st++){const K=s[st];w=Math.max(y.dot(K),w),M=Math.max(N.dot(K),M),U=Math.max(L.dot(K),U),x=Math.min(y.dot(K),x),v=Math.min(N.dot(K),v),z=Math.min(L.dot(K),z)}y.multiplyScalar(.5*(x+w)),N.multiplyScalar(.5*(v+M)),L.multiplyScalar(.5*(z+U));const j=new S.Vector3,et=new S.Vector3,Z=new S.Matrix3;j.add(y).add(N).add(L),et.x=w-x,et.y=M-v,et.z=U-z,et.multiplyScalar(.5),Z.copy(_);const{x:xt,y:bt,z:vt}=et,xe=new S.Matrix4;xe.makeScale(xt*2,bt*2,vt*2);const he=new S.Matrix4;he.makeTranslation(-xt,-bt,-vt);const Ai=new S.Matrix4;Ai.makeTranslation(j.x,j.y,j.z);const Fi=new S.Matrix4;Fi.setFromMatrix3(Z);const Ee=new S.Matrix4;return Ee.multiply(Ai),Ee.multiply(Fi),Ee.multiply(he),Ee.multiply(xe),{center:j,halfSizes:et,rotation:Z,transformation:Ee}}function fn(c,s,t){const e=[c[0]-s[0],c[1]-s[1],c[2]-s[2]];return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]>0}class ri{static isTransparent(s){return s.transparent&&s.opacity<1}}const $=class ${static create(){const s=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return`${$._lut[s&255]+$._lut[s>>8&255]+$._lut[s>>16&255]+$._lut[s>>24&255]}-${$._lut[t&255]}${$._lut[t>>8&255]}-${$._lut[t>>16&15|64]}${$._lut[t>>24&255]}-${$._lut[e&63|128]}${$._lut[e>>8&255]}-${$._lut[e>>16&255]}${$._lut[e>>24&255]}${$._lut[i&255]}${$._lut[i>>8&255]}${$._lut[i>>16&255]}${$._lut[i>>24&255]}`.toLowerCase()}static validate(s){if(!$._pattern.test(s))throw new Error(`${s} is not a valid UUID v4.
2
2
 
3
3
  - If you're the tool creator, you can take one from https://www.uuidgenerator.net/.
4
4
 
package/dist/index.mjs CHANGED
@@ -4,8 +4,8 @@ var I = (c, s, t) => (Bn(c, typeof s != "symbol" ? s + "" : s, t), t);
4
4
  import * as O from "three";
5
5
  import { BufferAttribute as An, Vector3 as M, Vector2 as fe, Plane as pi, Line3 as Lt, Triangle as ue, Sphere as Yn, Matrix4 as Mt, Box3 as Ot, BackSide as Vn, DoubleSide as Fn, FrontSide as _i, Mesh as v, Ray as Gn, Raycaster as zn, Quaternion as yt, Object3D as ei, Euler as Hn, MeshBasicMaterial as gn, LineBasicMaterial as kn, CylinderGeometry as ct, BoxGeometry as rt, BufferGeometry as Ni, Float32BufferAttribute as Pi, OctahedronGeometry as Qe, Line as Ut, SphereGeometry as Wn, TorusGeometry as me, PlaneGeometry as Xn } from "three";
6
6
  import * as b from "web-ifc";
7
- import * as $t from "bim-fragment";
8
- import { Serializer as Zn } from "bim-fragment";
7
+ import * as $t from "@thatopen/fragments";
8
+ import { Serializer as Zn } from "@thatopen/fragments";
9
9
  const On = 0, Qn = 1, jn = 2, yi = 2, Us = 1.25, Li = 1, Ts = 6 * 4 + 4 + 4, ys = 65535, qn = Math.pow(2, -24), xs = Symbol("SKIP_GENERATION");
10
10
  function $n(c) {
11
11
  return c.index ? c.index.count : c.attributes.position.count;