0?G.start.copy(R.start):G.start.copy(g.start),p.subVectors(R.end,g.end),p.dot(h)<0?G.end.copy(R.end):G.end.copy(g.end)),!0)}}}();C5.prototype.distanceToPoint=function(){const e=new Ne;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}}();C5.prototype.distanceToTriangle=function(){const e=new Ne,t=new Ne,n=["a","b","c"],s=new xr,l=new xr;return function(a,o=null,h=null){const f=o||h?s:null;if(this.intersectsTriangle(a,f))return(o||h)&&(o&&f.getCenter(o),h&&f.getCenter(h)),0;let p=1/0;for(let E=0;E<3;E++){let R;const g=n[E],D=a[g];this.closestPointToPoint(D,e),R=D.distanceToSquared(e),Rnew Ne),this.satAxes=new Array(3).fill().map(()=>new Ne),this.satBounds=new Array(3).fill().map(()=>new US),this.alignedSatBounds=new Array(3).fill().map(()=>new US),this.needsUpdate=!1,t&&this.min.copy(t),n&&this.max.copy(n),s&&this.matrix.copy(s)}set(t,n,s){this.min.copy(t),this.max.copy(n),this.matrix.copy(s),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}Y3.prototype.update=function(){return function(){const e=this.matrix,t=this.min,n=this.max,s=this.points;for(let f=0;f<=1;f++)for(let p=0;p<=1;p++)for(let E=0;E<=1;E++){const R=1*f|2*p|4*E,g=s[R];g.x=f?n.x:t.x,g.y=p?n.y:t.y,g.z=E?n.z:t.z,g.applyMatrix4(e)}const l=this.satBounds,a=this.satAxes,o=s[0];for(let f=0;f<3;f++){const p=a[f],E=l[f],R=1<new xr),n=new Array(12).fill().map(()=>new xr),s=new Ne,l=new Ne;return function(a,o=0,h=null,f=null){if(this.needsUpdate&&this.update(),this.intersectsBox(a))return(h||f)&&(a.getCenter(l),this.closestPointToPoint(l,s),a.closestPointToPoint(s,l),h&&h.copy(s),f&&f.copy(l)),0;const p=o*o,E=a.min,R=a.max,g=this.points;let D=1/0;for(let Y=0;Y<8;Y++){const G=g[Y];l.copy(G).clamp(E,R);const W=G.distanceToSquared(l);if(Wnew C5)}};const aE=new wwe;function b4(e,t){return t[e+15]===65535}function w2(e,t){return t[e+6]}function uE(e,t){return t[e+14]}function oE(e){return e+8}function cE(e,t){return t[e+6]}function Jle(e,t){return t[e+7]}let Ewe=class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let n=null;this.setBuffer=s=>{n&&t.push(n),n=s,this.float32Array=new Float32Array(s),this.uint16Array=new Uint16Array(s),this.uint32Array=new Uint32Array(s)},this.clearBuffer=()=>{n=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}};const au=new Ewe;let AN,DM;const yx=[],dW=new Z$(()=>new Ms);function mwe(e,t,n,s,l,a){AN=dW.getPrimitive(),DM=dW.getPrimitive(),yx.push(AN,DM),au.setBuffer(e._roots[t]);const o=kZ(0,e.geometry,n,s,l,a);au.clearBuffer(),dW.releasePrimitive(AN),dW.releasePrimitive(DM),yx.pop(),yx.pop();const h=yx.length;return h>0&&(DM=yx[h-1],AN=yx[h-2]),o}function kZ(e,t,n,s,l=null,a=0,o=0){const{float32Array:h,uint16Array:f,uint32Array:p}=au;let E=e*2;if(b4(E,f)){const R=w2(e,p),g=uE(E,f);return Vu(e,h,AN),s(R,g,!1,o,a+e,AN)}else{let R=function(Me){const{uint16Array:Ge,uint32Array:et}=au;let je=Me*2;for(;!b4(je,Ge);)Me=oE(Me),je=Me*2;return w2(Me,et)},g=function(Me){const{uint16Array:Ge,uint32Array:et}=au;let je=Me*2;for(;!b4(je,Ge);)Me=cE(Me,et),je=Me*2;return w2(Me,et)+uE(je,Ge)};const D=oE(e),B=cE(e,p);let Y=D,G=B,W,ee,te,K;if(l&&(te=AN,K=DM,Vu(Y,h,te),Vu(G,h,K),W=l(te),ee=l(K),ee(H_.copy(t).clamp(E.min,E.max),H_.distanceToSquared(t)),intersectsBounds:(E,R,g)=>g{E.closestPointToPoint(t,H_);const g=t.distanceToSquared(H_);return g0&&p.normal.multiplyScalar(-1));const E={a,b:o,c:h,normal:new Ne,materialIndex:0};si.getNormal(wx,Ex,mx,E.normal),p.face=E,p.faceIndex=a}return p}function kj(e,t,n,s,l){const a=s*3;let o=a+0,h=a+1,f=a+2;const p=e.index;e.index&&(o=p.getX(o),h=p.getX(h),f=p.getX(f));const{position:E,normal:R,uv:g,uv1:D}=e.attributes,B=gwe(n,E,R,g,D,o,h,f,t);return B?(B.faceIndex=s,l&&l.push(B),B):null}function hh(e,t,n,s){const l=e.a,a=e.b,o=e.c;let h=t,f=t+1,p=t+2;n&&(h=n.getX(h),f=n.getX(f),p=n.getX(p)),l.x=s.getX(h),l.y=s.getY(h),l.z=s.getZ(h),a.x=s.getX(f),a.y=s.getY(f),a.z=s.getZ(f),o.x=s.getX(p),o.y=s.getY(p),o.z=s.getZ(p)}function Awe(e,t,n,s,l,a){const{geometry:o,_indirectBuffer:h}=e;for(let f=s,p=s+l;fde&&(de=Me),Gewe&&(we=Ge),etTe&&(Te=et)}return f[g+0]!==ee||f[g+1]!==te||f[g+2]!==K||f[g+3]!==de||f[g+4]!==we||f[g+5]!==Te?(f[g+0]=ee,f[g+1]=te,f[g+2]=K,f[g+3]=de,f[g+4]=we,f[g+5]=Te,!0):!1}else{const G=g+8,W=o[g+6],ee=G+D,te=W+D;let K=B,de=!1,we=!1;t?K||(de=t.has(ee),we=t.has(te),K=!de&&!we):(de=!0,we=!0);const Te=K||de,De=K||we;let me=!1;Te&&(me=R(G,D,K));let Re=!1;De&&(Re=R(W,D,K));const Me=me||Re;if(Me)for(let Ge=0;Ge<3;Ge++){const et=G+Ge,je=W+Ge,ft=f[et],ht=f[et+3],wt=f[je],mt=f[je+3];f[g+Ge]=ftmt?ht:mt}return Me}}}const hee=new Ms;function BN(e,t,n,s){return Vu(e,t,hee),n.intersectBox(hee,s)}function bwe(e,t,n,s,l,a){const{geometry:o,_indirectBuffer:h}=e;for(let f=s,p=s+l;f=0;let R,g;E?(R=oE(e),g=cE(e,o)):(R=cE(e,o),g=oE(e));const D=BN(R,l,s,fee)?qZ(R,t,n,s):null;if(D){const Y=D.point[p];if(E?Y<=l[g+f]:Y>=l[g+f+3])return D}const B=BN(g,l,s,fee)?qZ(g,t,n,s):null;return D&&B?D.distance<=B.distance?D:B:D||B||null}}const wW=new Ms,Tx=new C5,Rx=new C5,__=new rn,Iee=new Y3,EW=new Y3;function Mwe(e,t,n,s){au.setBuffer(e._roots[t]);const l=KZ(0,e,n,s);return au.clearBuffer(),l}function KZ(e,t,n,s,l=null){const{float32Array:a,uint16Array:o,uint32Array:h}=au;let f=e*2;if(l===null&&(n.boundingBox||n.computeBoundingBox(),Iee.set(n.boundingBox.min,n.boundingBox.max,s),l=Iee),b4(f,o)){const p=t.geometry,E=p.index,R=p.attributes.position,g=n.index,D=n.attributes.position,B=w2(e,h),Y=uE(f,o);if(__.copy(s).invert(),n.boundsTree)return Vu(e,a,EW),EW.matrix.copy(__),EW.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:G=>EW.intersectsBox(G),intersectsTriangle:G=>{G.a.applyMatrix4(s),G.b.applyMatrix4(s),G.c.applyMatrix4(s),G.needsUpdate=!0;for(let W=B*3,ee=(Y+B)*3;Wvq.distanceToBox(de),intersectsBounds:(de,we,Te)=>Te{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:Te=>G_.distanceToBox(Te),intersectsBounds:(Te,De,me)=>me{for(let me=Te,Re=Te+De;mede&&(de=et),jewe&&(we=je),ftTe&&(Te=ft)}}return f[g+0]!==ee||f[g+1]!==te||f[g+2]!==K||f[g+3]!==de||f[g+4]!==we||f[g+5]!==Te?(f[g+0]=ee,f[g+1]=te,f[g+2]=K,f[g+3]=de,f[g+4]=we,f[g+5]=Te,!0):!1}else{const G=g+8,W=o[g+6],ee=G+D,te=W+D;let K=B,de=!1,we=!1;t?K||(de=t.has(ee),we=t.has(te),K=!de&&!we):(de=!0,we=!0);const Te=K||de,De=K||we;let me=!1;Te&&(me=R(G,D,K));let Re=!1;De&&(Re=R(W,D,K));const Me=me||Re;if(Me)for(let Ge=0;Ge<3;Ge++){const et=G+Ge,je=W+Ge,ft=f[et],ht=f[et+3],wt=f[je],mt=f[je+3];f[g+Ge]=ftmt?ht:mt}return Me}}}const pee=new Ne;function Vwe(e,t,n,s,l){au.setBuffer(e._roots[t]),ZZ(0,e,n,s,l),au.clearBuffer()}function ZZ(e,t,n,s,l){const{float32Array:a,uint16Array:o,uint32Array:h}=au,f=e*2;if(b4(f,o)){const p=w2(e,h),E=uE(f,o);bwe(t,n,s,p,E,l)}else{const p=oE(e);BN(p,a,s,pee)&&ZZ(p,t,n,s,l);const E=cE(e,h);BN(E,a,s,pee)&&ZZ(E,t,n,s,l)}}const yee=new Ne,zwe=["x","y","z"];function Wwe(e,t,n,s){au.setBuffer(e._roots[t]);const l=QZ(0,e,n,s);return au.clearBuffer(),l}function QZ(e,t,n,s){const{float32Array:l,uint16Array:a,uint32Array:o}=au;let h=e*2;if(b4(h,a)){const f=w2(e,o),p=uE(h,a);return Owe(t,n,s,f,p)}else{const f=Jle(e,o),p=zwe[f],E=s.direction[p]>=0;let R,g;E?(R=oE(e),g=cE(e,o)):(R=cE(e,o),g=oE(e));const D=BN(R,l,s,yee)?QZ(R,t,n,s):null;if(D){const Y=D.point[p];if(E?Y<=l[g+f]:Y>=l[g+f+3])return D}const B=BN(g,l,s,yee)?QZ(g,t,n,s):null;return D&&B?D.distance<=B.distance?D:B:D||B||null}}const TW=new Ms,gx=new C5,Ax=new C5,V_=new rn,wee=new Y3,RW=new Y3;function Ywe(e,t,n,s){au.setBuffer(e._roots[t]);const l=$Z(0,e,n,s);return au.clearBuffer(),l}function $Z(e,t,n,s,l=null){const{float32Array:a,uint16Array:o,uint32Array:h}=au;let f=e*2;if(l===null&&(n.boundingBox||n.computeBoundingBox(),wee.set(n.boundingBox.min,n.boundingBox.max,s),l=wee),b4(f,o)){const p=t.geometry,E=p.index,R=p.attributes.position,g=n.index,D=n.attributes.position,B=w2(e,h),Y=uE(f,o);if(V_.copy(s).invert(),n.boundsTree)return Vu(e,a,RW),RW.matrix.copy(V_),RW.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:G=>RW.intersectsBox(G),intersectsTriangle:G=>{G.a.applyMatrix4(s),G.b.applyMatrix4(s),G.c.applyMatrix4(s),G.needsUpdate=!0;for(let W=B,ee=Y+B;WeK.distanceToBox(de),intersectsBounds:(de,we,Te)=>Te{if(t.boundsTree){const Te=t.boundsTree;return Te.shapecast({boundsTraverseOrder:De=>z_.distanceToBox(De),intersectsBounds:(De,me,Re)=>Re{for(let Re=De,Me=De+me;Renew Ms),Sx=new Ms,Dx=new Ms,tK=new Ms,nK=new Ms;let sK=!1;function $we(e,t,n,s){if(sK)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");sK=!0;const l=e._roots,a=t._roots;let o,h=0,f=0;const p=new rn().copy(n).invert();for(let E=0,R=l.length;Ef.slice()),index:o.array.slice(),indirectBuffer:a?a.slice():null}:h={roots:l,index:o.array,indirectBuffer:a},h}static deserialize(t,n,s={}){s={setIndex:!0,indirect:!!t.indirectBuffer,...s};const{index:l,roots:a,indirectBuffer:o}=t,h=new Q$(n,{...s,[Qq]:!0});if(h._roots=a,h._indirectBuffer=o||null,s.setIndex){const f=n.getIndex();if(f===null){const p=new zl(t.index,1,!1);n.setIndex(p)}else f.array!==l&&(f.array.set(l),f.needsUpdate=!0)}return h}get indirect(){return!!this._indirectBuffer}constructor(t,n={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(n=Object.assign({strategy:Zle,maxDepth:40,maxLeafTris:10,verbose:!0,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,[Qq]:!1},n),n.useSharedArrayBuffer&&!Qwe())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,n[Qq]||(fwe(this,n),!t.boundingBox&&n.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new Ms)));const{_indirectBuffer:s}=this;this.resolveTriangleIndex=n.indirect?l=>s[l]:l=>l}refit(t=null){return(this.indirect?Gwe:Nwe)(this,t)}traverse(t,n=0){const s=this._roots[n],l=new Uint32Array(s),a=new Uint16Array(s);o(0);function o(h,f=0){const p=h*2,E=a[p+15]===Yj;if(E){const R=l[h+6],g=a[p+14];t(f,E,new Float32Array(s,h*4,6),R,g)}else{const R=h+qY/4,g=l[h+6],D=l[h+7];t(f,E,new Float32Array(s,h*4,6),D)||(o(R,f+1),o(g,f+1))}}}raycast(t,n=jp){const s=this._roots,l=this.geometry,a=[],o=n.isMaterial,h=Array.isArray(n),f=l.groups,p=o?n.side:n,E=this.indirect?Vwe:Lwe;for(let R=0,g=s.length;RR(g,D,B,Y,G)?!0:s(g,D,this,h,B,Y,n)}else o||(h?o=(R,g,D,B)=>s(R,g,this,h,D,B,n):o=(R,g,D)=>D);let f=!1,p=0;const E=this._roots;for(let R=0,g=E.length;R{const Y=this.resolveTriangleIndex(B);hh(o,Y*3,h,f)}:B=>{hh(o,B*3,h,f)},E=aE.getPrimitive(),R=t.geometry.index,g=t.geometry.attributes.position,D=t.indirect?B=>{const Y=t.resolveTriangleIndex(B);hh(E,Y*3,R,g)}:B=>{hh(E,B*3,R,g)};if(a){const B=(Y,G,W,ee,te,K,de,we)=>{for(let Te=W,De=W+ee;TeAW.intersectsBox(s),intersectsTriangle:s=>AW.intersectsTriangle(s)})}intersectsSphere(t){return this.shapecast({intersectsBounds:n=>t.intersectsBox(n),intersectsTriangle:n=>n.intersectsSphere(t)})}closestPointToGeometry(t,n,s={},l={},a=0,o=1/0){return(this.indirect?Zwe:_we)(this,t,n,s,l,a,o)}closestPointToPoint(t,n={},s=0,l=1/0){return Twe(this,t,n,s,l)}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(n=>{Vu(0,new Float32Array(n),Eee),t.union(Eee)}),t}}function mee(e,t,n){return e===null||(e.point.applyMatrix4(t.matrixWorld),e.distance=e.point.distanceTo(n.ray.origin),e.object=t,e.distancen.far)?null:e}const lK=new GL,Tee=new rn,Jwe=jt.prototype.raycast;function Xwe(e,t){if(this.geometry.boundsTree){if(this.material===void 0)return;Tee.copy(this.matrixWorld).invert(),lK.copy(e.ray).applyMatrix4(Tee);const n=this.geometry.boundsTree;if(e.firstHitOnly===!0){const s=mee(n.raycastFirst(lK,this.material),this,e);s&&t.push(s)}else{const s=n.raycast(lK,this.material);for(let l=0,a=s.length;l{const n=this.handlers.slice(0);for(const s of n)s(t)}),nt(this,"handlers",[])}add(t){this.handlers.push(t)}remove(t){this.handlers=this.handlers.filter(n=>n!==t)}reset(){this.handlers.length=0}};class KY{constructor(){nt(this,"trigger",async t=>{const n=this.handlers.slice(0);for(const s of n)await s(t)}),nt(this,"handlers",[])}add(t){this.handlers.push(t)}remove(t){this.handlers=this.handlers.filter(n=>n!==t)}reset(){this.handlers.length=0}}class $${constructor(t){nt(this,"isDisposeable",()=>"dispose"in this&&"onDisposed"in this),nt(this,"isResizeable",()=>"resize"in this&&"getSize"in this),nt(this,"isUpdateable",()=>"onAfterUpdate"in this&&"onBeforeUpdate"in this&&"update"in this),nt(this,"isHideable",()=>"visible"in this),nt(this,"isConfigurable",()=>"setup"in this&&"config"in this&&"onSetup"in this),this.components=t}}let Jd=class extends $${};class J$ extends $${constructor(t){super(t),nt(this,"worlds",new Map),nt(this,"onWorldChanged",new ls),nt(this,"currentWorld",null),this.onWorldChanged.add(({world:n,action:s})=>{s==="removed"&&this.worlds.delete(n.uuid)})}}let tEe=class extends J${constructor(){super(...arguments),nt(this,"hasCameraControls",()=>"controls"in this)}},nEe=class extends J${constructor(){super(...arguments),nt(this,"onAfterUpdate",new ls),nt(this,"onBeforeUpdate",new ls),nt(this,"onDisposed",new ls),nt(this,"onResize",new ls),nt(this,"onClippingPlanesUpdated",new ls),nt(this,"clippingPlanes",[])}updateClippingPlanes(){this.onClippingPlanesUpdated.trigger()}setPlane(t,n,s){n.isLocal=s;const l=this.clippingPlanes.indexOf(n);t&&l===-1?this.clippingPlanes.push(n):!t&&l>-1&&this.clippingPlanes.splice(l,1),this.three.clippingPlanes=this.clippingPlanes.filter(a=>!a.isLocal)}};const Xle=class JZ extends Jd{constructor(t){super(t),nt(this,"_disposedComponents",new Set),nt(this,"enabled",!0),t.add(JZ.uuid,this)}get(){return this._disposedComponents}destroy(t,n=!0,s=!0){t.removeFromParent();const l=t;l.dispose&&l.dispose(),this.disposeGeometryAndMaterials(t,n),s&&l.children&&l.children.length&&this.disposeChildren(l),t.children.length=0}disposeGeometry(t){t.boundsTree&&t.disposeBoundsTree&&t.disposeBoundsTree(),t.dispose()}disposeGeometryAndMaterials(t,n){const s=t;s.geometry&&this.disposeGeometry(s.geometry),n&&s.material&&JZ.disposeMaterial(s),s.material=[],s.geometry=null}disposeChildren(t){for(const n of t.children)this.destroy(n)}static disposeMaterial(t){if(t.material)if(Array.isArray(t.material))for(const n of t.material)n.dispose();else t.material.dispose()}};nt(Xle,"uuid","76e9cd8e-ad8f-4753-9ef6-cbc60f7247fe");let lU=Xle,sEe=class extends J${constructor(t){super(t),nt(this,"onDisposed",new ls),nt(this,"directionalLights",new Map),nt(this,"ambientLights",new Map)}dispose(){const t=this.components.get(lU);for(const n of this.three.children){const s=n;s.geometry&&t.destroy(s)}for(const[,n]of this.directionalLights)n.removeFromParent(),n.target.removeFromParent(),n.dispose();for(const[,n]of this.ambientLights)n.removeFromParent(),n.dispose();this.three.children=[],this.onDisposed.trigger(),this.onDisposed.reset()}},Ree=class extends Map{constructor(t){super(t),nt(this,"onItemSet",new ls),nt(this,"onItemUpdated",new ls),nt(this,"onItemDeleted",new ls),nt(this,"onCleared",new ls)}clear(){super.clear(),this.onCleared.trigger()}set(t,n){const s=this.has(t),l=super.set(t,n);return s?(this.onItemUpdated||(this.onItemUpdated=new ls),this.onItemUpdated.trigger({key:t,value:n})):(this.onItemSet||(this.onItemSet=new ls),this.onItemSet.trigger({key:t,value:n})),l}delete(t){const n=super.delete(t);return n&&this.onItemDeleted.trigger(),n}dispose(){this.clear(),this.onItemSet.reset(),this.onItemDeleted.reset(),this.onCleared.reset()}};const ZY=0,lEe=1,rEe=new Ne,gee=new xr,rK=new qu,Aee=new Ne,SW=new si;let iEe=class{constructor(){this.tolerance=-1,this.faces=[],this.newFaces=[],this.assigned=new See,this.unassigned=new See,this.vertices=[]}setFromPoints(t){if(t.length>=4){this.makeEmpty();for(let n=0,s=t.length;nthis.tolerance)return!1;return!0}intersectRay(t,n){const s=this.faces;let l=-1/0,a=1/0;for(let o=0,h=s.length;o0&&E>=0)return null;const R=E!==0?-p/E:0;if(!(R<=0)&&(E>0?a=Math.min(R,a):l=Math.max(R,l),l>a))return null}return l!==-1/0?t.at(l,n):t.at(a,n),n}intersectsRay(t){return this.intersectRay(t,rEe)!==null}makeEmpty(){return this.faces=[],this.vertices=[],this}addVertexToFace(t,n){return t.face=n,n.outside===null?this.assigned.append(t):this.assigned.insertBefore(n.outside,t),n.outside=t,this}removeVertexFromFace(t,n){return t===n.outside&&(t.next!==null&&t.next.face===n?n.outside=t.next:n.outside=null),this.assigned.remove(t),this}removeAllVerticesFromFace(t){if(t.outside!==null){const n=t.outside;let s=t.outside;for(;s.next!==null&&s.next.face===t;)s=s.next;return this.assigned.removeSubList(n,s),n.prev=s.next=null,t.outside=null,n}}deleteFaceVertices(t,n){const s=this.removeAllVerticesFromFace(t);if(s!==void 0)if(n===void 0)this.unassigned.appendChain(s);else{let l=s;do{const a=l.next;n.distanceToPoint(l.point)>this.tolerance?this.addVertexToFace(l,n):this.unassigned.append(l),l=a}while(l!==null)}return this}resolveUnassignedPoints(t){if(this.unassigned.isEmpty()===!1){let n=this.unassigned.first();do{const s=n.next;let l=this.tolerance,a=null;for(let o=0;ol&&(l=f,a=h),l>1e3*this.tolerance)break}}a!==null&&this.addVertexToFace(n,a),n=s}while(n!==null)}return this}computeExtremes(){const t=new Ne,n=new Ne,s=[],l=[];for(let a=0;a<3;a++)s[a]=l[a]=this.vertices[0];t.copy(this.vertices[0].point),n.copy(this.vertices[0].point);for(let a=0,o=this.vertices.length;an.getComponent(p)&&(n.setComponent(p,f.getComponent(p)),l[p]=h)}return this.tolerance=3*Number.EPSILON*(Math.max(Math.abs(t.x),Math.abs(n.x))+Math.max(Math.abs(t.y),Math.abs(n.y))+Math.max(Math.abs(t.z),Math.abs(n.z))),{min:s,max:l}}computeInitialHull(){const t=this.vertices,n=this.computeExtremes(),s=n.min,l=n.max;let a=0,o=0;for(let g=0;g<3;g++){const D=l[g].point.getComponent(g)-s[g].point.getComponent(g);D>a&&(a=D,o=g)}const h=s[o],f=l[o];let p,E;a=0,gee.set(h.point,f.point);for(let g=0,D=this.vertices.length;ga&&(a=Y,p=B)}}a=-1,rK.setFromCoplanarPoints(h.point,f.point,p.point);for(let g=0,D=this.vertices.length;ga&&(a=Y,E=B)}}const R=[];if(rK.distanceToPoint(E.point)<0){R.push(Qm.create(h,f,p),Qm.create(E,f,h),Qm.create(E,p,f),Qm.create(E,h,p));for(let g=0;g<3;g++){const D=(g+1)%3;R[g+1].getEdge(2).setTwin(R[0].getEdge(D)),R[g+1].getEdge(1).setTwin(R[D+1].getEdge(0))}}else{R.push(Qm.create(h,p,f),Qm.create(E,h,f),Qm.create(E,f,p),Qm.create(E,p,h));for(let g=0;g<3;g++){const D=(g+1)%3;R[g+1].getEdge(2).setTwin(R[0].getEdge((3-g)%3)),R[g+1].getEdge(0).setTwin(R[D+1].getEdge(1))}}for(let g=0;g<4;g++)this.faces.push(R[g]);for(let g=0,D=t.length;ga&&(a=W,Y=this.faces[G])}Y!==null&&this.addVertexToFace(B,Y)}}return this}reindexFaces(){const t=[];for(let n=0;nn&&(n=a,t=l),l=l.next}while(l!==null&&l.face===s);return t}}computeHorizon(t,n,s,l){this.deleteFaceVertices(s),s.mark=lEe;let a;n===null?a=n=s.getEdge(0):a=n.next;do{const o=a.twin,h=o.face;h.mark===ZY&&(h.distanceToPoint(t)>this.tolerance?this.computeHorizon(t,o,h,l):l.push(a)),a=a.next}while(a!==n);return this}addAdjoiningFace(t,n){const s=Qm.create(t,n.tail(),n.head());return this.faces.push(s),s.getEdge(-1).setTwin(n.twin),s.getEdge(0)}addNewFaces(t,n){this.newFaces=[];let s=null,l=null;for(let a=0;a0;)n=n.next,t--;for(;t<0;)n=n.prev,t++;return n}compute(){const t=this.edge.tail(),n=this.edge.head(),s=this.edge.next.head();return SW.set(t.point,n.point,s.point),SW.getNormal(this.normal),SW.getMidpoint(this.midpoint),this.area=SW.getArea(),this.constant=this.normal.dot(this.midpoint),this}distanceToPoint(t){return this.normal.dot(t)-this.constant}}let iK=class{constructor(t,n){this.vertex=t,this.prev=null,this.next=null,this.twin=null,this.face=n}head(){return this.vertex}tail(){return this.prev?this.prev.vertex:null}length(){const t=this.head(),n=this.tail();return n!==null?n.point.distanceTo(t.point):-1}lengthSquared(){const t=this.head(),n=this.tail();return n!==null?n.point.distanceToSquared(t.point):-1}setTwin(t){return this.twin=t,t.twin=this,this}},aEe=class{constructor(t){this.point=t,this.prev=null,this.next=null,this.face=null}},See=class{constructor(){this.head=null,this.tail=null}first(){return this.head}last(){return this.tail}clear(){return this.head=this.tail=null,this}insertBefore(t,n){return n.prev=t.prev,n.next=t,n.prev===null?this.head=n:n.prev.next=n,t.prev=n,this}insertAfter(t,n){return n.prev=t,n.next=t.next,n.next===null?this.tail=n:n.next.prev=n,t.next=n,this}append(t){return this.head===null?this.head=t:this.tail.next=t,t.prev=this.tail,t.next=null,this.tail=t,this}appendChain(t){for(this.head===null?this.head=t:this.tail.next=t,t.prev=this.tail;t.next!==null;)t=t.next;return this.tail=t,this}remove(t){return t.prev===null?this.head=t.next:t.prev.next=t.next,t.next===null?this.tail=t.prev:t.next.prev=t.prev,this}removeSubList(t,n){return t.prev===null?this.head=n.next:t.prev.next=n.next,n.next===null?this.tail=t.prev:n.next.prev=t.prev,this}isEmpty(){return this.head===null}};const XZ=[2,2,1],vZ=[1,0,0];function rR(e,t){return e*3+t}function uEe(e){const t=e.elements;let n=0;for(let s=0;s<9;s++)n+=t[s]*t[s];return Math.sqrt(n)}function oEe(e){const t=e.elements;let n=0;for(let s=0;s<3;s++){const l=t[rR(XZ[s],vZ[s])];n+=2*l*l}return Math.sqrt(n)}function cEe(e,t){let n=0,s=1;const l=e.elements;for(let p=0;p<3;p++){const E=Math.abs(l[rR(XZ[p],vZ[p])]);E>n&&(n=E,s=p)}let a=1,o=0;const h=vZ[s],f=XZ[s];if(Math.abs(l[rR(f,h)])>Number.EPSILON){const p=l[rR(f,f)],E=l[rR(h,h)],R=l[rR(f,h)],g=(p-E)/2/R;let D;g<0?D=-1/(-g+Math.sqrt(1+g*g)):D=1/(g+Math.sqrt(1+g*g)),a=1/Math.sqrt(1+D*D),o=D*a}return t.identity(),t.elements[rR(h,h)]=a,t.elements[rR(f,f)]=a,t.elements[rR(f,h)]=o,t.elements[rR(h,f)]=-o,t}function hEe(e,t){let n=0,s=0;const l=10;t.unitary.identity(),t.diagonal.copy(e);const a=t.unitary,o=t.diagonal,h=new nl,f=new nl,p=Number.EPSILON*uEe(o);for(;sp;)cEe(o,h),f.copy(h).transpose(),o.multiply(h),o.premultiply(f),a.multiply(h),++n>2&&(s++,n=0);return t}function dEe(e){const t=[];for(let Ln=0;Ln0}class Dee{static isTransparent(t){return t.transparent&&t.opacity<1}}const eQ=class Nf{static create(){const t=Math.random()*4294967295|0,n=Math.random()*4294967295|0,s=Math.random()*4294967295|0,l=Math.random()*4294967295|0;return`${Nf._lut[t&255]+Nf._lut[t>>8&255]+Nf._lut[t>>16&255]+Nf._lut[t>>24&255]}-${Nf._lut[n&255]}${Nf._lut[n>>8&255]}-${Nf._lut[n>>16&15|64]}${Nf._lut[n>>24&255]}-${Nf._lut[s&63|128]}${Nf._lut[s>>8&255]}-${Nf._lut[s>>16&255]}${Nf._lut[s>>24&255]}${Nf._lut[l&255]}${Nf._lut[l>>8&255]}${Nf._lut[l>>16&255]}${Nf._lut[l>>24&255]}`.toLowerCase()}static validate(t){if(!Nf._pattern.test(t))throw new Error(`${t} is not a valid UUID v4.
- If you're the tool creator, you can take one from https://www.uuidgenerator.net/.
diff --git a/examples/assets/viewCube.js b/examples/assets/viewCube.js
index 74a944d..6d2f293 100644
--- a/examples/assets/viewCube.js
+++ b/examples/assets/viewCube.js
@@ -1,3 +1,3 @@
-import"./modulepreload-polyfill-B5Qt9EMX.js";import{m as r,p as o,C as i,O as m,a as s,H as c,u as p}from"./template-DMFEDxph.js";import{M as d}from"./index-DuOGq7b3.js";import"./state-QpXUsnxS.js";r.init();d.init();const e=new o,w=e.get(i),t=w.create();t.scene=new m(e);const a=document.createElement("bim-viewport");t.renderer=new s(e,a);t.camera=new c(e);const n=document.createElement("bim-view-cube");n.camera=t.camera.three;a.append(n);t.camera.controls.addEventListener("update",()=>n.updateOrientation());const u=document.getElementById("app");u.layouts={main:{template:`
+import"./modulepreload-polyfill-B5Qt9EMX.js";import{m as r,p as o,C as i,O as m,a as s,H as c,u as p}from"./template-CbfBv3iq.js";import{M as d}from"./index-BavxEBZ0.js";import"./state-QpXUsnxS.js";r.init();d.init();const e=new o,w=e.get(i),t=w.create();t.scene=new m(e);const a=document.createElement("bim-viewport");t.renderer=new s(e,a);t.camera=new c(e);const n=document.createElement("bim-view-cube");n.camera=t.camera.three;a.append(n);t.camera.controls.addEventListener("update",()=>n.updateOrientation());const u=document.getElementById("app");u.layouts={main:{template:`
"viewport"
`,elements:{viewport:a}}};const l=e.get(p);l.create(t);e.init();
diff --git a/examples/assets/world2D.js b/examples/assets/world2D.js
index 79813a1..e2a7e18 100644
--- a/examples/assets/world2D.js
+++ b/examples/assets/world2D.js
@@ -1,4 +1,4 @@
-import"./modulepreload-polyfill-B5Qt9EMX.js";import{m as p,p as h,C as u,O as w,k as f,l as v,u as y,h as b,I as E,g as A}from"./template-DMFEDxph.js";import{M as C}from"./index-DuOGq7b3.js";import"./state-QpXUsnxS.js";p.init();C.init();const t=new h,M=t.get(u),e=M.create();e.scene=new w(t);e.scene.setup();const i=document.createElement("bim-viewport");e.renderer=new f(t,i);e.camera=new v(t);i.addEventListener("resize",()=>{var r;(r=e.renderer)==null||r.resize(),e.camera.updateAspect()});t.init();const O=t.get(y);O.create(e);const S=t.get(b),k=await fetch("https://thatopen.github.io/engine_ui-components/resources/road.frag"),x=await k.arrayBuffer(),z=new Uint8Array(x),s=S.load(z);e.scene.three.add(s);const o=new E(t);o.world=e;o.draw(s);o.highlighter.hoverCurve.material.color.set(1,1,1);const{material:a}=o.highlighter.hoverPoints;if(Array.isArray(a)){const r=a[0];"color"in r&&r.color.set(1,1,1)}else"color"in a&&a.color.set(1,1,1);const c=new A(t),n=document.createElement("bim-world-2d");n.components=t;if(!n.world)throw new Error("World not found!");n.gridOffsetX=1e4;c.world=n.world;await c.draw(s);c.onHighlight.add(({mesh:r})=>{o.highlighter.select(r);const g=r.curve.index,l=r.curve.alignment.absolute[g];l.mesh.geometry.computeBoundingSphere();const m=l.mesh.geometry.boundingSphere;m&&e.camera.controls.fitToSphere(m,!0)});const d=document.createElement("bim-grid");d.layouts={main:{template:`
+import"./modulepreload-polyfill-B5Qt9EMX.js";import{m as p,p as h,C as u,O as w,k as f,l as v,u as y,h as b,I as E,g as A}from"./template-CbfBv3iq.js";import{M as C}from"./index-BavxEBZ0.js";import"./state-QpXUsnxS.js";p.init();C.init();const t=new h,M=t.get(u),e=M.create();e.scene=new w(t);e.scene.setup();const i=document.createElement("bim-viewport");e.renderer=new f(t,i);e.camera=new v(t);i.addEventListener("resize",()=>{var r;(r=e.renderer)==null||r.resize(),e.camera.updateAspect()});t.init();const O=t.get(y);O.create(e);const S=t.get(b),k=await fetch("https://thatopen.github.io/engine_ui-components/resources/road.frag"),x=await k.arrayBuffer(),z=new Uint8Array(x),s=S.load(z);e.scene.three.add(s);const o=new E(t);o.world=e;o.draw(s);o.highlighter.hoverCurve.material.color.set(1,1,1);const{material:a}=o.highlighter.hoverPoints;if(Array.isArray(a)){const r=a[0];"color"in r&&r.color.set(1,1,1)}else"color"in a&&a.color.set(1,1,1);const c=new A(t),n=document.createElement("bim-world-2d");n.components=t;if(!n.world)throw new Error("World not found!");n.gridOffsetX=1e4;c.world=n.world;await c.draw(s);c.onHighlight.add(({mesh:r})=>{o.highlighter.select(r);const g=r.curve.index,l=r.curve.alignment.absolute[g];l.mesh.geometry.computeBoundingSphere();const m=l.mesh.geometry.boundingSphere;m&&e.camera.controls.fitToSphere(m,!0)});const d=document.createElement("bim-grid");d.layouts={main:{template:`
"world2d" 2fr
"container" 3fr
`,elements:{world2d:n,container:i}}};d.layout="main";document.body.append(d);
diff --git a/examples/assets/worldsConfiguration.js b/examples/assets/worldsConfiguration.js
index 9ea8adb..50a8e64 100644
--- a/examples/assets/worldsConfiguration.js
+++ b/examples/assets/worldsConfiguration.js
@@ -1,4 +1,4 @@
-import"./modulepreload-polyfill-B5Qt9EMX.js";import{m as d,p,C as m,O as u,x as f,H as b,u as w,f as g,R as h,i as x,j as y}from"./template-DMFEDxph.js";import{t as v}from"./index-Du0rpbBE.js";d.init();const a=document.createElement("bim-viewport"),t=new p,C=t.get(m),e=C.create();e.name="Default World";e.scene=new u(t);e.scene.three.background=null;e.scene.setup();e.renderer=new f(t,a);const{postproduction:o}=e.renderer;e.camera=new b(t);e.camera.controls.setLookAt(1.5,1.4,.12,-3.5,-.5,-7);a.addEventListener("resize",()=>{e.renderer&&e.renderer.resize(),e.camera.updateAspect()});t.init();const A=t.get(w),i=A.create(e);i.material.uniforms.uColor.value=new g("#4D4D4D");const l=t.get(h);await l.setup();const D=await fetch("https://thatopen.github.io/engine_ui-components/resources/small.ifc"),E=await D.arrayBuffer(),S=new Uint8Array(E),k=await l.load(S);e.scene.three.add(k);o.enabled=!0;o.customEffects.excludedMeshes.push(i.three);o.setPasses({ao:!0});const[n]=v.worldsConfiguration({components:t}),L=x.create(()=>y`
+import"./modulepreload-polyfill-B5Qt9EMX.js";import{m as d,p,C as m,O as u,x as f,H as b,u as w,f as g,R as h,i as x,j as y}from"./template-CbfBv3iq.js";import{t as v}from"./index-BiD-LIPr.js";d.init();const a=document.createElement("bim-viewport"),t=new p,C=t.get(m),e=C.create();e.name="Default World";e.scene=new u(t);e.scene.three.background=null;e.scene.setup();e.renderer=new f(t,a);const{postproduction:o}=e.renderer;e.camera=new b(t);e.camera.controls.setLookAt(1.5,1.4,.12,-3.5,-.5,-7);a.addEventListener("resize",()=>{e.renderer&&e.renderer.resize(),e.camera.updateAspect()});t.init();const A=t.get(w),i=A.create(e);i.material.uniforms.uColor.value=new g("#4D4D4D");const l=t.get(h);await l.setup();const D=await fetch("https://thatopen.github.io/engine_ui-components/resources/small.ifc"),E=await D.arrayBuffer(),S=new Uint8Array(E),k=await l.load(S);e.scene.three.add(k);o.enabled=!0;o.customEffects.excludedMeshes.push(i.three);o.setPasses({ao:!0});const[n]=v.worldsConfiguration({components:t}),L=x.create(()=>y`