@konfigure/sdk 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +41 -0
- package/README.md +325 -2
- package/THIRD_PARTY_NOTICES.md +283 -0
- package/dist/chunk-ARGXORCF.js +1 -0
- package/dist/chunk-OOVVLYAY.js +482 -0
- package/dist/chunk-XUSV3KOD.js +1 -0
- package/dist/configurator-6ISAZiAx.d.ts +468 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.js +4 -0
- package/dist/src-GJ5RXX7G.js +3811 -0
- package/dist/view.d.ts +674 -0
- package/dist/view.js +801 -0
- package/package.json +46 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {a}from'./chunk-XUSV3KOD.js';var T=class extends Error{static{a(this,"KonfigureError");}code;status;details;constructor(n,t,o={}){super(t,o.cause===void 0?void 0:{cause:o.cause}),this.name="KonfigureError",this.code=n,this.status=o.status,this.details=o.details;}};function Y(e,n,t){let o=e.allowedSurfaceIds??[],s=e.allowedSurfaceGroupIds??[];return o.length===0&&s.length===0||o.includes(n)?true:t!=null&&s.includes(t)}a(Y,"isSurfaceAllowed");function B({preferred:e,inherited:n}){let t=e===void 0?[]:typeof e=="number"?[e]:[...e];return n!==void 0&&t.push(n),t}a(B,"surfaceCandidates");function Q(e,n,t){for(let o of B(n))if(t(o))return o;return e.defaultSurfaceId??void 0}a(Q,"choosePartSurface");function X(e,n){return e.defaultPartId!=null&&n.includes(e.defaultPartId)?e.defaultPartId:n[0]}a(X,"startingPartId");function Z(e){return e.mandatory&&e.defaultPartId?e.defaultPartId:void 0}a(Z,"mandatoryPartId");function H(){return !(typeof process<"u")}a(H,"isDev");function L(e){return e==="error"?"error":e==="warn"?"warn":"log"}a(L,"getConsoleMethod");var m={reset:"\x1B[0m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",cyan:"\x1B[36m",white:"\x1B[37m",gray:"\x1B[90m"};function k(e){switch(e){case "error":return m.red;case "warn":return m.yellow;case "info":return m.cyan;case "debug":return m.gray;default:return m.white}}a(k,"getLevelColor");var ee={service:"app",environment:"development"},G=H(),te={};function z(e){let{rates:n}=te;if(!n)return true;let t=e==="error"&&n.error===void 0?100:n[e]??100;return t<=0?false:t>=100?true:Math.random()*100<t}a(z,"shouldSample");function K(e,n,t=false){if(!t&&!z(e))return null;let o={timestamp:new Date().toISOString(),level:e,...ee,...n};return G?ne(o):console[L(e)](JSON.stringify(o)),o}a(K,"emitWideEvent");function V(e,n,t){if(G){if(!z(e))return;let o=k(e),s=new Date().toISOString().slice(11,23);console.log(`${m.dim}${s}${m.reset} ${o}[${n}]${m.reset} ${t}`);}else K(e,{tag:n,message:t});}a(V,"emitTaggedLog");function oe(e){if(e==null)return String(e);if(typeof e=="object"){let n=[];for(let[t,o]of Object.entries(e))o!=null&&(typeof o=="object"?n.push(`${t}=${JSON.stringify(o)}`):n.push(`${t}=${o}`));return n.join(" ")}return String(e)}a(oe,"formatValue");function ne(e){let{timestamp:n,level:t,service:o,environment:s,version:a,...u}=e,i=k(t),d=n.slice(11,23),S=`${m.dim}${d}${m.reset} ${i}${t.toUpperCase()}${m.reset}`;if(S+=` ${m.cyan}[${o}]${m.reset}`,u.method&&u.path&&(S+=` ${u.method} ${u.path}`,delete u.method,delete u.path),u.status){let c=u.status>=400?m.red:m.green;S+=` ${c}${u.status}${m.reset}`,delete u.status;}u.duration&&(S+=` ${m.dim}in ${u.duration}${m.reset}`,delete u.duration),console.log(S);let M=Object.entries(u).filter(([c,f])=>f!==void 0),l=M.length-1;M.forEach(([c,f],R)=>{let p=R===l?"\u2514\u2500":"\u251C\u2500",b=oe(f);console.log(` ${m.dim}${p}${m.reset} ${m.cyan}${c}:${m.reset} ${b}`);});}a(ne,"prettyPrintWideEvent");function E(e){return a(function(t,o){typeof t=="string"&&o!==void 0?V(e,t,o):typeof t=="object"?K(e,t):V(e,"log",String(t));},"logMethod")}a(E,"createLogMethod");var x={info:E("info"),error:E("error"),warn:E("warn"),debug:E("debug")};function re(){let e=import.meta;return e.dev?true:e.server||typeof localStorage>"u"?false:localStorage.getItem("debug")==="true"}a(re,"isLoggingEnabled");function se(e){let n=a(()=>re(),"shouldLog");return {debug:a((t,o)=>{n()&&(o?x.debug({tag:e,message:t,...o}):x.debug(e,t));},"debug"),info:a((t,o)=>{n()&&(o?x.info({tag:e,message:t,...o}):x.info(e,t));},"info"),warn:a((t,o)=>{n()&&(o?x.warn({tag:e,message:t,...o}):x.warn(e,t));},"warn"),error:a((t,o)=>{o?x.error({tag:e,message:t,...o}):x.error(e,t);},"error")}}a(se,"createClientLogger");var N=new WeakMap,ue=0,{toString:ae}=Object.prototype,F=a((e,n)=>ae.call(e)===`[object ${n}]`,"isType"),ie=a(e=>{let n=Object.getPrototypeOf(e);return n===null||n===Object.prototype||Object.getPrototypeOf(n)===null},"isPlainObject");function _(e,n){let t=typeof e,o=e?.constructor,s=n?F(e,"Date"):o===Date;if(Object(e)===e&&!s&&!(n?F(e,"RegExp"):o===RegExp)){let a=e,u=N.get(a);if(u)return u;u=++ue+"~",N.set(a,u);let i;if(n?Array.isArray(e):o===Array){let d=e;for(u="@",i=0;i<d.length;i++)u+=_(d[i],n)+",";N.set(d,u);}else if(n?ie(a):o===null||o===Object){u="#";let d=Object.keys(a).sort();for(;(i=d.pop())!==void 0;){let S=i;a[S]!==void 0&&(u+=i+":"+_(a[S],n)+",");}N.set(a,u);}return u}return s?e.toJSON():t==="symbol"?e.toString():t==="string"?JSON.stringify(e):""+e}a(_,"stableHash");function le(e){let n=Object.fromEntries(Object.entries(e.basePartSlots).map(([t,{hidden:o,...s}])=>[t,s]));return _({apiModuleId:e.apiModuleId,basePartSlots:n,invertedSlots:e.invertedSlots,rotatedSlots:e.rotatedSlots,childrenHashes:e.childrenHashes,...e.size&&{size:{width:e.size.width,height:e.size.height}}})}a(le,"computeModuleContentHash");function ce(e,n,t){let o=e.x-t.x,s=e.z-t.z,a=n.x-t.x,u=n.z-t.z,i=o*u-s*a,d=o*a+s*u;return Math.atan2(i,d)}a(ce,"calculateAngle");function de(e,n){for(let t=0;t<e.length;t++){let o=e[t];if(o&&o.module&&Object.values(o.module.moduleSlots).some(u=>u.id===n))return [t,o]}return [-1,null]}a(de,"findConnectedModuleSlot");function fe(e,n,t){let o=[],s=new Set;t&&s.add(t.id),s.add(n.id);function a$1(u){for(let i of Object.values(u)){let d=i.module;!d||s.has(d.id)||(s.add(d.id),o.push(d),a$1(d.moduleSlots));}}return a(a$1,"collectRecursive"),a$1(e),o}a(fe,"collectChildModules");function C(e){return e.apiModuleId}a(C,"getModuleApiId");function O(e,n){return j(e,n).map(t=>t.module)}a(O,"getNeighborModules");function W(e,n){for(let[t,o]of Object.entries(e.moduleSlots))if(o.module?.id===n.id)return t}a(W,"findSlotFacing");function j(e,n){let t=[],o=new Set;for(let[s,a]of Object.entries(e.moduleSlots))if(a.module&&!o.has(a.module.id)){o.add(a.module.id);let u=W(a.module,e);t.push({module:a.module,ourSlotName:s,theirSlotName:u});}for(let s of n)if(!(s.id===e.id||o.has(s.id))){for(let[a,u]of Object.entries(s.moduleSlots))if(u.module?.id===e.id){o.add(s.id);let i=W(e,s)??me(e,s,a);t.push({module:s,ourSlotName:i,theirSlotName:a});break}}return t}a(j,"getDirectionalNeighbors");function me(e,n,t){let o=C(e),s=n.moduleSlots[t];if(o&&s){let i=s.compatibleModules?.find(d=>d.id===o)?.allowedSlotNames;if(i?.length===1)return i[0];if(i&&i.length>1){let d=i.filter(S=>{let M=e.moduleSlots[S];return M&&!M.module});if(d.length===1)return d[0]}}let a=Object.entries(e.moduleSlots).filter(([u,i])=>!i.module);if(a.length===1)return a[0][0]}a(me,"determineConnectingSlot");function ge(e){return e?.apiPartId}a(ge,"getPartApiId");function A(e,n,t){let o=0;switch(e){case "module":for(let s of t){let a=C(s);a!==void 0&&n.includes(a)&&o++;}break;case "part":for(let s of t)for(let a of Object.values(s.basePartSlots)){let u=ge(a.part);u!==void 0&&n.includes(u)&&o++;}break}return o}a(A,"countTargets");function J(e,n,t){return !e||e==="current_module"||e==="all_modules"?true:e==="neighbors"?O(n,t).length>0:true}a(J,"checkScope");function I(e,n){if(!e)return false;if(n.includes(e.apiPartId))return true;for(let t of Object.values(e.partSlots))if(I(t.part,n))return true;return false}a(I,"partMatchesRecursively");function D(e,n,t){let o=0;for(let s of n){let a=e.basePartSlots[s];a&&I(a.part,t)&&o++;}return o}a(D,"countTargetsInSlots");function q(e,n,t){if(!e?.partSlots)return false;let o=e.partSlots[n];if(o&&o.part&&t.includes(o.part.apiPartId))return true;for(let s of Object.values(e.partSlots))if(q(s.part,n,t))return true;return false}a(q,"nestedSlotHoldsPart");function pe(e,n){let{currentModule:t,accessoryPartIdsBySlot:o}=n;if(!t)return false;let s=e.targetIds??[],a=e.slotName;if(a){let u=t.basePartSlots[a];if(u&&I(u.part,s))return true;for(let d of Object.values(t.basePartSlots))if(q(d.part,a,s))return true;let i=o?.[a];return !!(i&&i.some(d=>s.includes(d)))}if(Object.values(t.basePartSlots).some(u=>I(u.part,s)))return true;if(o){for(let u of Object.values(o))if(u.some(i=>s.includes(i)))return true}return false}a(pe,"evaluateHasPart");function he(e,n){let{allModules:t}=n,o=e.targetIds??[];return t.some(s=>{let a=C(s);return a!==void 0&&o.includes(a)})}a(he,"evaluateHasModule");function be(e,n){return false}a(be,"evaluateHasSurface");function Se(e,n,t){if(t&&e.theirSlotName){let o=t.replace("{slotName}",e.theirSlotName),s=e.module.basePartSlots[o];if(s)return I(s.part,n)}return Object.values(e.module.basePartSlots).some(o=>I(o.part,n))}a(Se,"neighborHasTargetPart");function ye(e,n){let{currentModule:t,allModules:o}=n;if(!t)return false;let s=e.targetIds??[],a=e.moduleSlotName,u=e.neighborBaseSlotPattern,i=j(t,o);return (a?i.filter(S=>S.ourSlotName===a):i).some(S=>Se(S,s,u))}a(ye,"evaluateNeighborHasPart");function Re(e,n){let{currentModule:t,allModules:o}=n;if(!t)return false;let s=e.targetIds??[];return O(t,o).some(u=>{let i=C(u);return i!==void 0&&s.includes(i)})}a(Re,"evaluateNeighborHasModule");function xe(e,n){let{changedSlotName:t}=n;return t===e.slotName}a(xe,"evaluateSlotIs");function ve(e,n){let{allModules:t}=n,o=e.targetIds??[];return A(e.targetType??"",o,t)>=(Number(e.value)||0)}a(ve,"evaluateCountGte");function Ce(e,n){let{allModules:t}=n,o=e.targetIds??[];return A(e.targetType??"",o,t)<=(Number(e.value)||0)}a(Ce,"evaluateCountLte");function Me(e,n){let{currentModule:t}=n;if(!t)return false;let o=e.targetIds??[];return D(t,e.slotNames??[],o)>=(Number(e.value)||0)}a(Me,"evaluateCountInSlotsGte");function Ie(e,n){let{currentModule:t}=n;if(!t)return false;let o=e.targetIds??[],s=D(t,e.slotNames??[],o),a=D(t,e.compareSlotNames??[],o);return s-a>=(Number(e.value)||0)}a(Ie,"evaluateCountInSlotsDiffGte");function we(e,n){let{changedPartId:t,changedSlotName:o}=n;if(!t)return false;let s=e.targetIds??[];return (!e.slotName||e.slotName===o)&&(s.length===0||s.includes(t))}a(we,"evaluatePartChanged");function Pe(e,n){let{changedSurfaceId:t}=n;if(!t)return false;let o=e.targetIds??[];return o.length===0||o.includes(t)}a(Pe,"evaluateSurfaceChanged");var Ee={has_part:pe,has_module:he,has_surface:be,neighbor_has_part:ye,neighbor_has_module:Re,slot_is:xe,count_gte:ve,count_lte:Ce,count_in_slots_gte:Me,count_in_slots_diff_gte:Ie,part_changed:we,surface_changed:Pe};function U(e,n){let t=Ee[e.type];return t?t(e,n):false}a(U,"evaluateCondition");function w(e){return e?.apiPartId}a(w,"partApiId");function Ne(e){let n=new Set;for(let l of e)for(let c of l.actions)if(c.type==="forbid"&&c.targetType==="module"&&c.adjacencyCheck)for(let f of c.targetIds)n.add(f);function t(l,c){return l.conditions.every(f=>U(f,c))}a(t,"evaluateConditions");function o(l,c){if(!l.targetModuleIds||l.targetModuleIds.length===0)return true;let f=C(c);return f===void 0?true:l.targetModuleIds.includes(f)}a(o,"ruleAppliesToModule");function s(l,c,f,R,h){let p={currentModule:f,allModules:R,targetPartId:l,changedSlotName:c,baseSlotName:h};for(let b of e)if(o(b,f)&&t(b,p))for(let g of b.actions){if(g.type!=="forbid"||g.targetType!=="part"||!g.targetIds.includes(l))continue;let y=J(g.scope,f,R),v=!g.slotName||g.slotName===c||g.slotName===h;if(y&&v)return {ruleName:b.name,message:g.message||b.name}}return null}a(s,"checkPart");function a$1(l,c,f){let R={currentModule:c,allModules:f,targetModuleId:l};for(let h of e)if(o(h,c)&&t(h,R)){for(let p of h.actions)if(!(p.type!=="forbid"||p.targetType!=="module")&&!p.adjacencyCheck&&p.targetIds.includes(l))return {ruleName:h.name,message:p.message||h.name}}return null}a(a$1,"checkModule");function u(l){return n.has(l)}a(u,"needsAdjacencyCheck");let i=e.filter(l=>l.ruleType==="sync_parts"||l.ruleType==="cascade_change");function d(l,c,f,R){let h=f.basePartSlots[R];if(!h)return;let p=h.compatibleParts??[];if(p.some(y=>w(y)===c))return c;let b=C(f),g=l.partMappings?.find(y=>y.sourcePartId===c&&y.targetModuleId===b);if(g)return p.some(y=>w(y)===g.targetPartId)?g.targetPartId:void 0}a(d,"mapPartForModule");function S(l,c,f,R){let h=[],p={currentModule:f,allModules:R,changedPartId:l,changedSlotName:c};for(let b of i)if(o(b,f)&&t(b,p))for(let g of b.actions){if(g.type!=="sync"||g.scope!=="all_modules")continue;let y=g.slotName||c;for(let v of R){if(v.id===f.id)continue;let P=v.basePartSlots[y];if(!P)continue;let $=d(b,l,v,y);$!==void 0&&w(P.part)!==$&&h.push({moduleId:v.id,slotName:y,newPartId:$});}}return h}a(S,"partChangeSyncs");function M(l,c){let f=[];if(c.length===0)return f;for(let R of i)if(o(R,l))for(let h of R.actions){if(h.type!=="sync"||h.scope!=="all_modules")continue;let p=h.slotName;if(!p)continue;let b=l.basePartSlots[p];if(!b)continue;let g;for(let v of c){let P=v.basePartSlots[p];if(P&&(g=w(P.part),g!==void 0))break}if(g===void 0||w(b.part)===g)continue;let y=d(R,g,l,p);y===void 0||y===w(b.part)||f.push({moduleId:l.id,slotName:p,newPartId:y});}return f}return a(M,"newModuleSyncs"),{count:e.length,checkPart:s,checkModule:a$1,needsAdjacencyCheck:u,partChangeSyncs:S,newModuleSyncs:M}}a(Ne,"createRuleEngine");export{T as a,le as b,ce as c,de as d,fe as e,Ne as f,Y as g,Q as h,X as i,Z as j,se as k};
|
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
import {a,b}from'./chunk-XUSV3KOD.js';import {Vector3,Vector2,Plane,Line3,Triangle,Matrix4,Box3,Ray,BufferAttribute,FrontSide,DataTexture,NearestFilter,UnsignedIntType,IntType,FloatType,RGBAFormat,RGIntegerFormat,BackSide,DoubleSide,RGFormat,RedFormat,RGBAIntegerFormat,RedIntegerFormat,UnsignedByteType,UnsignedShortType,ByteType,ShortType,REVISION}from'three';var mt=Math.pow(2,-24),It=Symbol("SKIP_GENERATION"),kt={strategy:0,maxDepth:40,maxLeafSize:10,useSharedArrayBuffer:false,setBoundingBox:true,onProgress:null,indirect:false,verbose:true,range:null,[It]:false};var K=class{static{a(this,"SeparatingAxisBounds");}constructor(){this.min=1/0,this.max=-1/0;}setFromPointsField(t,e){let n=1/0,o=-1/0;for(let c=0,s=t.length;c<s;c++){let r=t[c][e];n=r<n?r:n,o=r>o?r:o;}this.min=n,this.max=o;}setFromPoints(t,e){let n=1/0,o=-1/0;for(let c=0,s=e.length;c<s;c++){let a=e[c],r=t.dot(a);n=r<n?r:n,o=r>o?r:o;}this.min=n,this.max=o;}isSeparated(t){return this.min>t.max||t.min>this.max}};K.prototype.setFromBox=(function(){let i=new Vector3;return a(function(e,n){let o=n.min,c=n.max,s=1/0,a=-1/0;for(let r=0;r<=1;r++)for(let p=0;p<=1;p++)for(let u=0;u<=1;u++){i.x=o.x*r+c.x*(1-r),i.y=o.y*p+c.y*(1-p),i.z=o.z*u+c.z*(1-u);let f=e.dot(i);s=Math.min(f,s),a=Math.max(f,a);}this.min=s,this.max=a;},"setFromBox")})();var yi=(function(){let i=new Vector3,t=new Vector3,e=new Vector3;return a(function(o,c,s){let a=o.start,r=i,p=c.start,u=t;e.subVectors(a,p),i.subVectors(o.end,o.start),t.subVectors(c.end,c.start);let f=e.dot(u),l=u.dot(r),d=u.dot(u),v=e.dot(r),A=r.dot(r)*d-l*l,g,m;A!==0?g=(f*l-v*d)/A:g=0,m=(f+g*l)/d,s.x=g,s.y=m;},"closestPointLineToLine")})(),Et=(function(){let i=new Vector2,t=new Vector3,e=new Vector3;return a(function(o,c,s,a){yi(o,c,i);let r=i.x,p=i.y;if(r>=0&&r<=1&&p>=0&&p<=1){o.at(r,s),c.at(p,a);return}else if(r>=0&&r<=1){p<0?c.at(0,a):c.at(1,a),o.closestPointToPoint(a,true,s);return}else if(p>=0&&p<=1){r<0?o.at(0,s):o.at(1,s),c.closestPointToPoint(s,true,a);return}else {let u;r<0?u=o.start:u=o.end;let f;p<0?f=c.start:f=c.end;let l=t,d=e;if(o.closestPointToPoint(f,true,t),c.closestPointToPoint(u,true,e),l.distanceToSquared(f)<=d.distanceToSquared(u)){s.copy(l),a.copy(f);return}else {s.copy(u),a.copy(d);return}}},"closestPointsSegmentToSegment")})(),en=(function(){let i=new Vector3,t=new Vector3,e=new Plane,n=new Line3;return a(function(c,s){let{radius:a,center:r}=c,{a:p,b:u,c:f}=s;if(n.start=p,n.end=u,n.closestPointToPoint(r,true,i).distanceTo(r)<=a||(n.start=p,n.end=f,n.closestPointToPoint(r,true,i).distanceTo(r)<=a)||(n.start=u,n.end=f,n.closestPointToPoint(r,true,i).distanceTo(r)<=a))return true;let b=s.getPlane(e);if(Math.abs(b.distanceToPoint(r))<=a){let g=b.projectPoint(r,t);if(s.containsPoint(g))return true}return false},"sphereIntersectTriangle")})();var gi=["x","y","z"],tt=1e-15,on=tt*tt;function Z(i){return Math.abs(i)<tt}a(Z,"isNearZero");var X=class extends Triangle{static{a(this,"ExtendedTriangle");}constructor(...t){super(...t),this.isExtendedTriangle=true,this.satAxes=new Array(4).fill().map(()=>new Vector3),this.satBounds=new Array(4).fill().map(()=>new K),this.points=[this.a,this.b,this.c],this.plane=new Plane,this.isDegenerateIntoSegment=false,this.isDegenerateIntoPoint=false,this.degenerateSegment=new Line3,this.needsUpdate=true;}intersectsSphere(t){return en(t,this)}update(){let t=this.a,e=this.b,n=this.c,o=this.points,c=this.satAxes,s=this.satBounds,a=c[0],r=s[0];this.getNormal(a),r.setFromPoints(a,o);let p=c[1],u=s[1];p.subVectors(t,e),u.setFromPoints(p,o);let f=c[2],l=s[2];f.subVectors(e,n),l.setFromPoints(f,o);let d=c[3],v=s[3];d.subVectors(n,t),v.setFromPoints(d,o);let b=p.length(),A=f.length(),g=d.length();this.isDegenerateIntoPoint=false,this.isDegenerateIntoSegment=false,b<tt?A<tt||g<tt?this.isDegenerateIntoPoint=true:(this.isDegenerateIntoSegment=true,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(n)):A<tt?g<tt?this.isDegenerateIntoPoint=true:(this.isDegenerateIntoSegment=true,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):g<tt&&(this.isDegenerateIntoSegment=true,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=false;}};X.prototype.closestPointToSegment=(function(){let i=new Vector3,t=new Vector3,e=new Line3;return a(function(o,c=null,s=null){let{start:a,end:r}=o,p=this.points,u,f=1/0;for(let l=0;l<3;l++){let d=(l+1)%3;e.start.copy(p[l]),e.end.copy(p[d]),Et(e,o,i,t),u=i.distanceToSquared(t),u<f&&(f=u,c&&c.copy(i),s&&s.copy(t));}return this.closestPointToPoint(a,i),u=a.distanceToSquared(i),u<f&&(f=u,c&&c.copy(i),s&&s.copy(a)),this.closestPointToPoint(r,i),u=r.distanceToSquared(i),u<f&&(f=u,c&&c.copy(i),s&&s.copy(r)),Math.sqrt(f)},"distanceToSegment")})();X.prototype.intersectsTriangle=(function(){let i=new X,t=new K,e=new K,n=new Vector3,o=new Vector3,c=new Vector3,s=new Vector3,a$1=new Line3,r=new Line3,p=new Vector3,u=new Vector2,f=new Vector2;function l(T,h,y,B){let w=n;!T.isDegenerateIntoPoint&&!T.isDegenerateIntoSegment?w.copy(T.plane.normal):w.copy(h.plane.normal);let S=T.satBounds,I=T.satAxes;for(let P=1;P<4;P++){let D=S[P],N=I[P];if(t.setFromPoints(N,h.points),D.isSeparated(t)||(s.copy(w).cross(N),t.setFromPoints(s,T.points),e.setFromPoints(s,h.points),t.isSeparated(e)))return false}let _=h.satBounds,E=h.satAxes;for(let P=1;P<4;P++){let D=_[P],N=E[P];if(t.setFromPoints(N,T.points),D.isSeparated(t)||(s.crossVectors(w,N),t.setFromPoints(s,T.points),e.setFromPoints(s,h.points),t.isSeparated(e)))return false}return y&&(B||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),y.start.set(0,0,0),y.end.set(0,0,0)),true}a(l,"coplanarIntersectsTriangle");function d(T,h,y,B,w,S,I,_,E,P,D){let N=I/(I-_);P.x=B+(w-B)*N,D.start.subVectors(h,T).multiplyScalar(N).add(T),N=I/(I-E),P.y=B+(S-B)*N,D.end.subVectors(y,T).multiplyScalar(N).add(T);}a(d,"findSingleBounds");function v(T,h,y,B,w,S,I,_,E,P,D){if(w>0)d(T.c,T.a,T.b,B,h,y,E,I,_,P,D);else if(S>0)d(T.b,T.a,T.c,y,h,B,_,I,E,P,D);else if(_*E>0||I!=0)d(T.a,T.b,T.c,h,y,B,I,_,E,P,D);else if(_!=0)d(T.b,T.a,T.c,y,h,B,_,I,E,P,D);else if(E!=0)d(T.c,T.a,T.b,B,h,y,E,I,_,P,D);else return true;return false}a(v,"findIntersectionLineBounds");function b(T,h,y,B){let w=h.degenerateSegment,S=T.plane.distanceToPoint(w.start),I=T.plane.distanceToPoint(w.end);return Z(S)?Z(I)?l(T,h,y,B):(y&&(y.start.copy(w.start),y.end.copy(w.start)),T.containsPoint(w.start)):Z(I)?(y&&(y.start.copy(w.end),y.end.copy(w.end)),T.containsPoint(w.end)):T.plane.intersectLine(w,n)!=null?(y&&(y.start.copy(n),y.end.copy(n)),T.containsPoint(n)):false}a(b,"intersectTriangleSegment");function A(T,h,y){let B=h.a;return Z(T.plane.distanceToPoint(B))&&T.containsPoint(B)?(y&&(y.start.copy(B),y.end.copy(B)),true):false}a(A,"intersectTrianglePoint");function g(T,h,y){let B=T.degenerateSegment,w=h.a;return B.closestPointToPoint(w,true,n),w.distanceToSquared(n)<on?(y&&(y.start.copy(w),y.end.copy(w)),true):false}a(g,"intersectSegmentPoint");function m(T,h,y,B){if(T.isDegenerateIntoSegment)if(h.isDegenerateIntoSegment){let w=T.degenerateSegment,S=h.degenerateSegment,I=o,_=c;w.delta(I),S.delta(_);let E=n.subVectors(S.start,w.start),P=I.x*_.y-I.y*_.x;if(Z(P))return false;let D=(E.x*_.y-E.y*_.x)/P,N=-(I.x*E.y-I.y*E.x)/P;if(D<0||D>1||N<0||N>1)return false;let F=w.start.z+I.z*D,L=S.start.z+_.z*N;return Z(F-L)?(y&&(y.start.copy(w.start).addScaledVector(I,D),y.end.copy(w.start).addScaledVector(I,D)),true):false}else return h.isDegenerateIntoPoint?g(T,h,y):b(h,T,y,B);else {if(T.isDegenerateIntoPoint)return h.isDegenerateIntoPoint?h.a.distanceToSquared(T.a)<on?(y&&(y.start.copy(T.a),y.end.copy(T.a)),true):false:h.isDegenerateIntoSegment?g(h,T,y):A(h,T,y);if(h.isDegenerateIntoPoint)return A(T,h,y);if(h.isDegenerateIntoSegment)return b(T,h,y,B)}}return a(m,"handleDegenerateCases"),a(function(h,y=null,B=false){this.needsUpdate&&this.update(),h.isExtendedTriangle?h.needsUpdate&&h.update():(i.copy(h),i.update(),h=i);let w=m(this,h,y,B);if(w!==void 0)return w;let S=this.plane,I=h.plane,_=I.distanceToPoint(this.a),E=I.distanceToPoint(this.b),P=I.distanceToPoint(this.c);Z(_)&&(_=0),Z(E)&&(E=0),Z(P)&&(P=0);let D=_*E,N=_*P;if(D>0&&N>0)return false;let F=S.distanceToPoint(h.a),L=S.distanceToPoint(h.b),$=S.distanceToPoint(h.c);Z(F)&&(F=0),Z(L)&&(L=0),Z($)&&($=0);let Qe=F*L,je=F*$;if(Qe>0&&je>0)return false;o.copy(S.normal),c.copy(I.normal);let Te=o.cross(c),ge=0,ve=Math.abs(Te.x),tn=Math.abs(Te.y);tn>ve&&(ve=tn,ge=1),Math.abs(Te.z)>ve&&(ge=2);let dt=gi[ge],si=this.a[dt],ri=this.b[dt],ci=this.c[dt],ai=h.a[dt],li=h.b[dt],fi=h.c[dt];if(v(this,si,ri,ci,D,N,_,E,P,u,a$1))return l(this,h,y,B);if(v(h,ai,li,fi,Qe,je,F,L,$,f,r))return l(this,h,y,B);if(u.y<u.x){let Ae=u.y;u.y=u.x,u.x=Ae,p.copy(a$1.start),a$1.start.copy(a$1.end),a$1.end.copy(p);}if(f.y<f.x){let Ae=f.y;f.y=f.x,f.x=Ae,p.copy(r.start),r.start.copy(r.end),r.end.copy(p);}return u.y<f.x||f.y<u.x?false:(y&&(f.x>u.x?y.start.copy(r.start):y.start.copy(a$1.start),f.y<u.y?y.end.copy(r.end):y.end.copy(a$1.end)),true)},"intersectsTriangle")})();X.prototype.distanceToPoint=(function(){let i=new Vector3;return a(function(e){return this.closestPointToPoint(e,i),e.distanceTo(i)},"distanceToPoint")})();X.prototype.distanceToTriangle=(function(){let i=new Vector3,t=new Vector3,e=["a","b","c"],n=new Line3,o=new Line3;return a(function(s,a=null,r=null){let p=a||r?n:null;if(this.intersectsTriangle(s,p))return (a||r)&&(a&&p.getCenter(a),r&&p.getCenter(r)),0;let u=1/0;for(let f=0;f<3;f++){let l,d=e[f],v=s[d];this.closestPointToPoint(v,i),l=v.distanceToSquared(i),l<u&&(u=l,a&&a.copy(i),r&&r.copy(v));let b=this[d];s.closestPointToPoint(b,i),l=b.distanceToSquared(i),l<u&&(u=l,a&&a.copy(b),r&&r.copy(i));}for(let f=0;f<3;f++){let l=e[f],d=e[(f+1)%3];n.set(this[l],this[d]);for(let v=0;v<3;v++){let b=e[v],A=e[(v+1)%3];o.set(s[b],s[A]),Et(n,o,i,t);let g=i.distanceToSquared(t);g<u&&(u=g,a&&a.copy(i),r&&r.copy(t));}}return Math.sqrt(u)},"distanceToTriangle")})();var k=class{static{a(this,"OrientedBox");}constructor(t,e,n){this.isOrientedBox=true,this.min=new Vector3,this.max=new Vector3,this.matrix=new Matrix4,this.invMatrix=new Matrix4,this.points=new Array(8).fill().map(()=>new Vector3),this.satAxes=new Array(3).fill().map(()=>new Vector3),this.satBounds=new Array(3).fill().map(()=>new K),this.alignedSatBounds=new Array(3).fill().map(()=>new K),this.needsUpdate=false,t&&this.min.copy(t),e&&this.max.copy(e),n&&this.matrix.copy(n);}set(t,e,n){this.min.copy(t),this.max.copy(e),this.matrix.copy(n),this.needsUpdate=true;}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=true;}};k.prototype.update=(function(){return a(function(){let t=this.matrix,e=this.min,n=this.max,o=this.points;for(let p=0;p<=1;p++)for(let u=0;u<=1;u++)for(let f=0;f<=1;f++){let l=1*p|2*u|4*f,d=o[l];d.x=p?n.x:e.x,d.y=u?n.y:e.y,d.z=f?n.z:e.z,d.applyMatrix4(t);}let c=this.satBounds,s=this.satAxes,a=o[0];for(let p=0;p<3;p++){let u=s[p],f=c[p],l=1<<p,d=o[l];u.subVectors(a,d),f.setFromPoints(u,o);}let r=this.alignedSatBounds;r[0].setFromPointsField(o,"x"),r[1].setFromPointsField(o,"y"),r[2].setFromPointsField(o,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=false;},"update")})();k.prototype.intersectsBox=(function(){let i=new K;return a(function(e){this.needsUpdate&&this.update();let n=e.min,o=e.max,c=this.satBounds,s=this.satAxes,a=this.alignedSatBounds;if(i.min=n.x,i.max=o.x,a[0].isSeparated(i)||(i.min=n.y,i.max=o.y,a[1].isSeparated(i))||(i.min=n.z,i.max=o.z,a[2].isSeparated(i)))return false;for(let r=0;r<3;r++){let p=s[r],u=c[r];if(i.setFromBox(p,e),u.isSeparated(i))return false}return true},"intersectsBox")})();k.prototype.intersectsTriangle=(function(){let i=new X,t=new Array(3),e=new K,n=new K,o=new Vector3;return a(function(s){this.needsUpdate&&this.update(),s.isExtendedTriangle?s.needsUpdate&&s.update():(i.copy(s),i.update(),s=i);let a=this.satBounds,r=this.satAxes;t[0]=s.a,t[1]=s.b,t[2]=s.c;for(let l=0;l<3;l++){let d=a[l],v=r[l];if(e.setFromPoints(v,t),d.isSeparated(e))return false}let p=s.satBounds,u=s.satAxes,f=this.points;for(let l=0;l<3;l++){let d=p[l],v=u[l];if(e.setFromPoints(v,f),d.isSeparated(e))return false}for(let l=0;l<3;l++){let d=r[l];for(let v=0;v<4;v++){let b=u[v];if(o.crossVectors(d,b),e.setFromPoints(o,t),n.setFromPoints(o,f),e.isSeparated(n))return false}}return true},"intersectsTriangle")})();k.prototype.closestPointToPoint=(function(){return a(function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e},"closestPointToPoint")})();k.prototype.distanceToPoint=(function(){let i=new Vector3;return a(function(e){return this.closestPointToPoint(e,i),e.distanceTo(i)},"distanceToPoint")})();k.prototype.distanceToBox=(function(){let i=["x","y","z"],t=new Array(12).fill().map(()=>new Line3),e=new Array(12).fill().map(()=>new Line3),n=new Vector3,o=new Vector3;return a(function(s,a=0,r=null,p=null){if(this.needsUpdate&&this.update(),this.intersectsBox(s))return (r||p)&&(s.getCenter(o),this.closestPointToPoint(o,n),s.closestPointToPoint(n,o),r&&r.copy(n),p&&p.copy(o)),0;let u=a*a,f=s.min,l=s.max,d=this.points,v=1/0;for(let A=0;A<8;A++){let g=d[A];o.copy(g).clamp(f,l);let m=g.distanceToSquared(o);if(m<v&&(v=m,r&&r.copy(g),p&&p.copy(o),m<u))return Math.sqrt(m)}let b=0;for(let A=0;A<3;A++)for(let g=0;g<=1;g++)for(let m=0;m<=1;m++){let T=(A+1)%3,h=(A+2)%3,y=g<<T|m<<h,B=1<<A|g<<T|m<<h,w=d[y],S=d[B];t[b].set(w,S);let _=i[A],E=i[T],P=i[h],D=e[b],N=D.start,F=D.end;N[_]=f[_],N[E]=g?f[E]:l[E],N[P]=m?f[P]:l[E],F[_]=l[_],F[E]=g?f[E]:l[E],F[P]=m?f[P]:l[E],b++;}for(let A=0;A<=1;A++)for(let g=0;g<=1;g++)for(let m=0;m<=1;m++){o.x=A?l.x:f.x,o.y=g?l.y:f.y,o.z=m?l.z:f.z,this.closestPointToPoint(o,n);let T=o.distanceToSquared(n);if(T<v&&(v=T,r&&r.copy(n),p&&p.copy(o),T<u))return Math.sqrt(T)}for(let A=0;A<12;A++){let g=t[A];for(let m=0;m<12;m++){let T=e[m];Et(g,T,n,o);let h=n.distanceToSquared(o);if(h<v&&(v=h,r&&r.copy(n),p&&p.copy(o),h<u))return Math.sqrt(h)}}return Math.sqrt(v)},"distanceToBox")})();var it=class{static{a(this,"PrimitivePool");}constructor(t){this._getNewPrimitive=t,this._primitives=[];}getPrimitive(){let t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t);}};var be=class extends it{static{a(this,"ExtendedTrianglePoolBase");}constructor(){super(()=>new X);}},Y=new be;var Dt=new Vector3,we=new Vector3;function an(i,t,e={},n=0,o=1/0){let c=n*n,s=o*o,a$1=1/0,r=null;if(i.shapecast({boundsTraverseOrder:a(u=>(Dt.copy(t).clamp(u.min,u.max),Dt.distanceToSquared(t)),"boundsTraverseOrder"),intersectsBounds:a((u,f,l)=>l<a$1&&l<s,"intersectsBounds"),intersectsTriangle:a((u,f)=>{u.closestPointToPoint(t,Dt);let l=t.distanceToSquared(Dt);return l<a$1&&(we.copy(Dt),a$1=l,r=f),l<c},"intersectsTriangle")}),a$1===1/0)return null;let p=Math.sqrt(a$1);return e.point?e.point.copy(we):e.point=we.clone(),e.distance=p,e.faceIndex=r,e}a(an,"closestPointToPoint");function M(i,t){return t[i+15]===65535}a(M,"IS_LEAF");function C(i,t){return t[i+6]}a(C,"OFFSET");function U(i,t){return t[i+14]}a(U,"COUNT");function O(i){return i+8}a(O,"LEFT_NODE");function z(i,t){let e=t[i+6];return i+e*8}a(z,"RIGHT_NODE");function ot(i,t){return t[i+7]}a(ot,"SPLIT_AXIS");var qt=parseInt(REVISION)>=169,wi=parseInt(REVISION)<=161,ft=new Vector3,ut=new Vector3,pt=new Vector3,Gt=new Vector2,Xt=new Vector2,Yt=new Vector2,ln=new Vector3,fn=new Vector3,un=new Vector3,Ft=new Vector3;function Bi(i,t,e,n,o,c,s,a){let r;if(c===BackSide?r=i.intersectTriangle(n,e,t,true,o):r=i.intersectTriangle(t,e,n,c!==DoubleSide,o),r===null)return null;let p=i.origin.distanceTo(o);return p<s||p>a?null:{distance:p,point:o.clone()}}a(Bi,"checkIntersection");function pn(i,t,e,n,o,c,s,a,r,p,u){ft.fromBufferAttribute(t,c),ut.fromBufferAttribute(t,s),pt.fromBufferAttribute(t,a);let f=Bi(i,ft,ut,pt,Ft,r,p,u);if(f){if(n){Gt.fromBufferAttribute(n,c),Xt.fromBufferAttribute(n,s),Yt.fromBufferAttribute(n,a),f.uv=new Vector2;let d=Triangle.getInterpolation(Ft,ft,ut,pt,Gt,Xt,Yt,f.uv);qt||(f.uv=d);}if(o){Gt.fromBufferAttribute(o,c),Xt.fromBufferAttribute(o,s),Yt.fromBufferAttribute(o,a),f.uv1=new Vector2;let d=Triangle.getInterpolation(Ft,ft,ut,pt,Gt,Xt,Yt,f.uv1);qt||(f.uv1=d),wi&&(f.uv2=f.uv1);}if(e){ln.fromBufferAttribute(e,c),fn.fromBufferAttribute(e,s),un.fromBufferAttribute(e,a),f.normal=new Vector3;let d=Triangle.getInterpolation(Ft,ft,ut,pt,ln,fn,un,f.normal);f.normal.dot(i.direction)>0&&f.normal.multiplyScalar(-1),qt||(f.normal=d);}let l={a:c,b:s,c:a,normal:new Vector3,materialIndex:0};if(Triangle.getNormal(ft,ut,pt,l.normal),f.face=l,f.faceIndex=c,qt){let d=new Vector3;Triangle.getBarycoord(Ft,ft,ut,pt,d),f.barycoord=d;}}return f}a(pn,"checkBufferGeometryIntersection");function dn(i){return i&&i.isMaterial?i.side:i}a(dn,"getSide");function yt(i,t,e,n,o,c,s){let a=n*3,r=a+0,p=a+1,u=a+2,{index:f,groups:l}=i;i.index&&(r=f.getX(r),p=f.getX(p),u=f.getX(u));let{position:d,normal:v,uv:b,uv1:A}=i.attributes;if(Array.isArray(t)){let g=n*3;for(let m=0,T=l.length;m<T;m++){let{start:h,count:y,materialIndex:B}=l[m];if(g>=h&&g<h+y){let w=dn(t[B]),S=pn(e,d,v,b,A,r,p,u,w,c,s);if(S)if(S.faceIndex=n,S.face.materialIndex=B,o)o.push(S);else return S}}}else {let g=dn(t),m=pn(e,d,v,b,A,r,p,u,g,c,s);if(m)if(m.faceIndex=n,m.face.materialIndex=0,o)o.push(m);else return m}return null}a(yt,"intersectTri");function V(i,t,e,n){let o=i.a,c=i.b,s=i.c,a=t,r=t+1,p=t+2;e&&(a=e.getX(a),r=e.getX(r),p=e.getX(p)),o.x=n.getX(a),o.y=n.getY(a),o.z=n.getZ(a),c.x=n.getX(r),c.y=n.getY(r),c.z=n.getZ(r),s.x=n.getX(p),s.y=n.getY(p),s.z=n.getZ(p);}a(V,"setTriangle");function xn(i,t,e,n,o,c,s,a){let{geometry:r,_indirectBuffer:p}=i;for(let u=n,f=n+o;u<f;u++)yt(r,t,e,u,c,s,a);}a(xn,"intersectTris");function yn(i,t,e,n,o,c,s){let{geometry:a,_indirectBuffer:r}=i,p=1/0,u=null;for(let f=n,l=n+o;f<l;f++){let d;d=yt(a,t,e,f,null,c,s),d&&d.distance<p&&(u=d,p=d.distance);}return u}a(yn,"intersectClosestTri");function hn(i,t,e,n,o,c,s){let{geometry:a}=e,{index:r}=a,p=a.attributes.position;for(let u=i,f=t+i;u<f;u++){let l;if(l=u,V(s,l*3,r,p),s.needsUpdate=true,n(s,l,o,c))return true}return false}a(hn,"iterateOverTriangles");function Tn(i,t=null){t&&Array.isArray(t)&&(t=new Set(t));let e=i.geometry,n=e.index?e.index.array:null,o=e.attributes.position,c,s,a$1,r,p=0,u=i._roots;for(let l=0,d=u.length;l<d;l++)c=u[l],s=new Uint32Array(c),a$1=new Uint16Array(c),r=new Float32Array(c),f(0,p),p+=c.byteLength;function f(l,d,v=false){let b=l*2;if(M(b,a$1)){let A=C(l,s),g=U(b,a$1),m=1/0,T=1/0,h=1/0,y=-1/0,B=-1/0,w=-1/0;for(let S=3*A,I=3*(A+g);S<I;S++){let _=n[S],E=o.getX(_),P=o.getY(_),D=o.getZ(_);E<m&&(m=E),E>y&&(y=E),P<T&&(T=P),P>B&&(B=P),D<h&&(h=D),D>w&&(w=D);}return r[l+0]!==m||r[l+1]!==T||r[l+2]!==h||r[l+3]!==y||r[l+4]!==B||r[l+5]!==w?(r[l+0]=m,r[l+1]=T,r[l+2]=h,r[l+3]=y,r[l+4]=B,r[l+5]=w,true):false}else {let A=O(l),g=z(l,s),m=v,T=false,h=false;if(t){if(!m){let _=A/8+d/32,E=g/8+d/32;T=t.has(_),h=t.has(E),m=!T&&!h;}}else T=true,h=true;let y=m||T,B=m||h,w=false;y&&(w=f(A,d,m));let S=false;B&&(S=f(g,d,m));let I=w||S;if(I)for(let _=0;_<3;_++){let E=A+_,P=g+_,D=r[E],N=r[E+3],F=r[P],L=r[P+3];r[l+_]=D<F?D:F,r[l+_+3]=N>L?N:L;}return I}}a(f,"_traverse");}a(Tn,"refit");function W(i,t,e,n,o){let c,s,a,r,p,u,f=1/e.direction.x,l=1/e.direction.y,d=1/e.direction.z,v=e.origin.x,b=e.origin.y,A=e.origin.z,g=t[i],m=t[i+3],T=t[i+1],h=t[i+3+1],y=t[i+2],B=t[i+3+2];return f>=0?(c=(g-v)*f,s=(m-v)*f):(c=(m-v)*f,s=(g-v)*f),l>=0?(a=(T-b)*l,r=(h-b)*l):(a=(h-b)*l,r=(T-b)*l),c>r||a>s||((a>c||isNaN(c))&&(c=a),(r<s||isNaN(s))&&(s=r),d>=0?(p=(y-A)*d,u=(B-A)*d):(p=(B-A)*d,u=(y-A)*d),c>u||p>s)?false:((p>c||c!==c)&&(c=p),(u<s||s!==s)&&(s=u),c<=o&&s>=n)}a(W,"intersectRay");var Be=class{static{a(this,"_BufferStack");}constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;let t=[],e=null;this.setBuffer=n=>{e&&t.push(e),e=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n);},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop());};}},R=new Be;function gn(i,t,e,n,o,c,s,a){let{geometry:r,_indirectBuffer:p}=i;for(let u=n,f=n+o;u<f;u++){let l=p?p[u]:u;yt(r,t,e,l,c,s,a);}}a(gn,"intersectTris_indirect");function vn(i,t,e,n,o,c,s){let{geometry:a,_indirectBuffer:r}=i,p=1/0,u=null;for(let f=n,l=n+o;f<l;f++){let d;d=yt(a,t,e,r?r[f]:f,null,c,s),d&&d.distance<p&&(u=d,p=d.distance);}return u}a(vn,"intersectClosestTri_indirect");function An(i,t,e,n,o,c,s){let{geometry:a}=e,{index:r}=a,p=a.attributes.position;for(let u=i,f=t+i;u<f;u++){let l;if(l=e.resolveTriangleIndex(u),V(s,l*3,r,p),s.needsUpdate=true,n(s,l,o,c))return true}return false}a(An,"iterateOverTriangles_indirect");function bn(i,t,e,n,o,c,s){R.setBuffer(i._roots[t]),_e(0,i,e,n,o,c,s),R.clearBuffer();}a(bn,"raycast");function _e(i,t,e,n,o,c,s){let{float32Array:a,uint16Array:r,uint32Array:p}=R,u=i*2;if(M(u,r)){let l=C(i,p),d=U(u,r);xn(t,e,n,l,d,o,c,s);}else {let l=O(i);W(l,a,n,c,s)&&_e(l,t,e,n,o,c,s);let d=z(i,p);W(d,a,n,c,s)&&_e(d,t,e,n,o,c,s);}}a(_e,"_raycast");var _i=["x","y","z"];function wn(i,t,e,n,o,c){R.setBuffer(i._roots[t]);let s=Se(0,i,e,n,o,c);return R.clearBuffer(),s}a(wn,"raycastFirst");function Se(i,t,e,n,o,c){let{float32Array:s,uint16Array:a,uint32Array:r}=R,p=i*2;if(M(p,a)){let f=C(i,r),l=U(p,a);return yn(t,e,n,f,l,o,c)}else {let f=ot(i,r),l=_i[f],v=n.direction[l]>=0,b,A;v?(b=O(i),A=z(i,r)):(b=z(i,r),A=O(i));let m=W(b,s,n,o,c)?Se(b,t,e,n,o,c):null;if(m){let y=m.point[l];if(v?y<=s[A+f]:y>=s[A+f+3])return m}let h=W(A,s,n,o,c)?Se(A,t,e,n,o,c):null;return m&&h?m.distance<=h.distance?m:h:m||h||null}}a(Se,"_raycastFirst");function H(i,t,e){return e.min.x=t[i],e.min.y=t[i+1],e.min.z=t[i+2],e.max.x=t[i+3],e.max.y=t[i+4],e.max.z=t[i+5],e}a(H,"arrayToBox");function Pe(i){let t=-1,e=-1/0;for(let n=0;n<3;n++){let o=i[n+3]-i[n];o>e&&(e=o,t=n);}return t}a(Pe,"getLongestEdgeIndex");function Ie(i,t){t.set(i);}a(Ie,"copyBounds");function Ee(i,t,e){let n,o;for(let c=0;c<3;c++){let s=c+3;n=i[c],o=t[c],e[c]=n<o?n:o,n=i[s],o=t[s],e[s]=n>o?n:o;}}a(Ee,"unionBounds");function Rt(i,t,e){for(let n=0;n<3;n++){let o=t[i+2*n],c=t[i+2*n+1],s=o-c,a=o+c;s<e[n]&&(e[n]=s),a>e[n+3]&&(e[n+3]=a);}}a(Rt,"expandByPrimitiveBounds");function ht(i){let t=i[3]-i[0],e=i[4]-i[1],n=i[5]-i[2];return 2*(t*e+e*n+n*t)}a(ht,"computeSurfaceArea");function Lt(i){return i.index?i.index.count:i.attributes.position.count}a(Lt,"getVertexCount");function st(i){return Lt(i)/3}a(st,"getTriCount");function De(i,t=ArrayBuffer){return i>65535?new Uint32Array(new t(4*i)):new Uint16Array(new t(2*i))}a(De,"getIndexArray");function Bn(i,t){if(!i.index){let e=i.attributes.position.count,n=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,o=De(e,n);i.setIndex(new BufferAttribute(o,1));for(let c=0;c<e;c++)o[c]=c;}}a(Bn,"ensureIndex");function Pi(i,t,e){let n=Lt(i)/e,o=t||i.drawRange,c=o.start/e,s=(o.start+o.count)/e,a=Math.max(0,c),r=Math.min(n,s)-a;return {offset:Math.floor(a),count:Math.floor(r)}}a(Pi,"getFullPrimitiveRange");function Ii(i,t){return i.groups.map(e=>({offset:e.start/t,count:e.count/t}))}a(Ii,"getPrimitiveGroupRanges");function Ne(i,t,e){let n=Pi(i,t,e),o=Ii(i,e);if(!o.length)return [n];let c=[],s=n.offset,a=n.offset+n.count,r=Lt(i)/e,p=[];for(let l of o){let{offset:d,count:v}=l,b=d,A=isFinite(v)?v:r-d,g=d+A;b<a&&g>s&&(p.push({pos:Math.max(s,b),isStart:true}),p.push({pos:Math.min(a,g),isStart:false}));}p.sort((l,d)=>l.pos!==d.pos?l.pos-d.pos:l.type==="end"?-1:1);let u=0,f=null;for(let l of p){let d=l.pos;u!==0&&d!==f&&c.push({offset:f,count:d-f}),u+=l.isStart?1:-1,f=d;}return c}a(Ne,"getRootPrimitiveRanges");var Kt=new Box3,Tt=new X,gt=new X,Ct=new Matrix4,_n=new k,Zt=new k;function Sn(i,t,e,n){R.setBuffer(i._roots[t]);let o=Fe(0,i,e,n);return R.clearBuffer(),o}a(Sn,"intersectsGeometry");function Fe(i,t,e,n,o=null){let{float32Array:c,uint16Array:s,uint32Array:a$1}=R,r=i*2;if(o===null&&(e.boundingBox||e.computeBoundingBox(),_n.set(e.boundingBox.min,e.boundingBox.max,n),o=_n),M(r,s)){let u=t.geometry,f=u.index,l=u.attributes.position,d=e.index,v=e.attributes.position,b=C(i,a$1),A=U(r,s);if(Ct.copy(n).invert(),e.boundsTree)return H(i,c,Zt),Zt.matrix.copy(Ct),Zt.needsUpdate=true,e.boundsTree.shapecast({intersectsBounds:a(m=>Zt.intersectsBox(m),"intersectsBounds"),intersectsTriangle:a(m=>{m.a.applyMatrix4(n),m.b.applyMatrix4(n),m.c.applyMatrix4(n),m.needsUpdate=true;for(let T=b*3,h=(A+b)*3;T<h;T+=3)if(V(gt,T,f,l),gt.needsUpdate=true,m.intersectsTriangle(gt))return true;return false},"intersectsTriangle")});{let g=st(e);for(let m=b*3,T=(A+b)*3;m<T;m+=3){V(Tt,m,f,l),Tt.a.applyMatrix4(Ct),Tt.b.applyMatrix4(Ct),Tt.c.applyMatrix4(Ct),Tt.needsUpdate=true;for(let h=0,y=g*3;h<y;h+=3)if(V(gt,h,d,v),gt.needsUpdate=true,Tt.intersectsTriangle(gt))return true}}}else {let u=O(i),f=z(i,a$1);return H(u,c,Kt),!!(o.intersectsBox(Kt)&&Fe(u,t,e,n,o)||(H(f,c,Kt),o.intersectsBox(Kt)&&Fe(f,t,e,n,o)))}}a(Fe,"_intersectsGeometry");var $t=new Matrix4,Me=new k,Ot=new k,Fi=new Vector3,Mi=new Vector3,Ri=new Vector3,Li=new Vector3;function Pn(i,t,e,n={},o={},c=0,s=1/0){t.boundingBox||t.computeBoundingBox(),Me.set(t.boundingBox.min,t.boundingBox.max,e),Me.needsUpdate=true;let a$1=i.geometry,r=a$1.attributes.position,p=a$1.index,u=t.attributes.position,f=t.index,l=Y.getPrimitive(),d=Y.getPrimitive(),v=Fi,b=Mi,A=null,g=null;o&&(A=Ri,g=Li);let m=1/0,T=null,h=null;return $t.copy(e).invert(),Ot.matrix.copy($t),i.shapecast({boundsTraverseOrder:a(y=>Me.distanceToBox(y),"boundsTraverseOrder"),intersectsBounds:a((y,B,w)=>w<m&&w<s?(B&&(Ot.min.copy(y.min),Ot.max.copy(y.max),Ot.needsUpdate=true),true):false,"intersectsBounds"),intersectsRange:a((y,B)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:a(S=>Ot.distanceToBox(S),"boundsTraverseOrder"),intersectsBounds:a((S,I,_)=>_<m&&_<s,"intersectsBounds"),intersectsRange:a((S,I)=>{for(let _=S,E=S+I;_<E;_++){V(d,3*_,f,u),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=true;for(let P=y,D=y+B;P<D;P++){V(l,3*P,p,r),l.needsUpdate=true;let N=l.distanceToTriangle(d,v,A);if(N<m&&(b.copy(v),g&&g.copy(A),m=N,T=P,h=_),N<c)return true}}},"intersectsRange")});{let w=st(t);for(let S=0,I=w;S<I;S++){V(d,3*S,f,u),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=true;for(let _=y,E=y+B;_<E;_++){V(l,3*_,p,r),l.needsUpdate=true;let P=l.distanceToTriangle(d,v,A);if(P<m&&(b.copy(v),g&&g.copy(A),m=P,T=_,h=S),P<c)return true}}}},"intersectsRange")}),Y.releasePrimitive(l),Y.releasePrimitive(d),m===1/0?null:(n.point?n.point.copy(b):n.point=b.clone(),n.distance=m,n.faceIndex=T,o&&(o.point?o.point.copy(g):o.point=g.clone(),o.point.applyMatrix4($t),b.applyMatrix4($t),o.distance=b.sub(o.point).length(),o.faceIndex=h),n)}a(Pn,"closestPointToGeometry");function In(i,t=null){t&&Array.isArray(t)&&(t=new Set(t));let e=i.geometry,n=e.index?e.index.array:null,o=e.attributes.position,c,s,a$1,r,p=0,u=i._roots;for(let l=0,d=u.length;l<d;l++)c=u[l],s=new Uint32Array(c),a$1=new Uint16Array(c),r=new Float32Array(c),f(0,p),p+=c.byteLength;function f(l,d,v=false){let b=l*2;if(M(b,a$1)){let A=C(l,s),g=U(b,a$1),m=1/0,T=1/0,h=1/0,y=-1/0,B=-1/0,w=-1/0;for(let S=A,I=A+g;S<I;S++){let _=3*i.resolveTriangleIndex(S);for(let E=0;E<3;E++){let P=_+E;P=n?n[P]:P;let D=o.getX(P),N=o.getY(P),F=o.getZ(P);D<m&&(m=D),D>y&&(y=D),N<T&&(T=N),N>B&&(B=N),F<h&&(h=F),F>w&&(w=F);}}return r[l+0]!==m||r[l+1]!==T||r[l+2]!==h||r[l+3]!==y||r[l+4]!==B||r[l+5]!==w?(r[l+0]=m,r[l+1]=T,r[l+2]=h,r[l+3]=y,r[l+4]=B,r[l+5]=w,true):false}else {let A=O(l),g=z(l,s),m=v,T=false,h=false;if(t){if(!m){let _=A/8+d/32,E=g/8+d/32;T=t.has(_),h=t.has(E),m=!T&&!h;}}else T=true,h=true;let y=m||T,B=m||h,w=false;y&&(w=f(A,d,m));let S=false;B&&(S=f(g,d,m));let I=w||S;if(I)for(let _=0;_<3;_++){let E=A+_,P=g+_,D=r[E],N=r[E+3],F=r[P],L=r[P+3];r[l+_]=D<F?D:F,r[l+_+3]=N>L?N:L;}return I}}a(f,"_traverse");}a(In,"refit_indirect");function En(i,t,e,n,o,c,s){R.setBuffer(i._roots[t]),Re(0,i,e,n,o,c,s),R.clearBuffer();}a(En,"raycast_indirect");function Re(i,t,e,n,o,c,s){let{float32Array:a,uint16Array:r,uint32Array:p}=R,u=i*2;if(M(u,r)){let l=C(i,p),d=U(u,r);gn(t,e,n,l,d,o,c,s);}else {let l=O(i);W(l,a,n,c,s)&&Re(l,t,e,n,o,c,s);let d=z(i,p);W(d,a,n,c,s)&&Re(d,t,e,n,o,c,s);}}a(Re,"_raycast");var Ci=["x","y","z"];function Dn(i,t,e,n,o,c){R.setBuffer(i._roots[t]);let s=Le(0,i,e,n,o,c);return R.clearBuffer(),s}a(Dn,"raycastFirst_indirect");function Le(i,t,e,n,o,c){let{float32Array:s,uint16Array:a,uint32Array:r}=R,p=i*2;if(M(p,a)){let f=C(i,r),l=U(p,a);return vn(t,e,n,f,l,o,c)}else {let f=ot(i,r),l=Ci[f],v=n.direction[l]>=0,b,A;v?(b=O(i),A=z(i,r)):(b=z(i,r),A=O(i));let m=W(b,s,n,o,c)?Le(b,t,e,n,o,c):null;if(m){let y=m.point[l];if(v?y<=s[A+f]:y>=s[A+f+3])return m}let h=W(A,s,n,o,c)?Le(A,t,e,n,o,c):null;return m&&h?m.distance<=h.distance?m:h:m||h||null}}a(Le,"_raycastFirst");var Qt=new Box3,vt=new X,At=new X,zt=new Matrix4,Nn=new k,jt=new k;function Fn(i,t,e,n){R.setBuffer(i._roots[t]);let o=Ce(0,i,e,n);return R.clearBuffer(),o}a(Fn,"intersectsGeometry_indirect");function Ce(i,t,e,n,o=null){let{float32Array:c,uint16Array:s,uint32Array:a$1}=R,r=i*2;if(o===null&&(e.boundingBox||e.computeBoundingBox(),Nn.set(e.boundingBox.min,e.boundingBox.max,n),o=Nn),M(r,s)){let u=t.geometry,f=u.index,l=u.attributes.position,d=e.index,v=e.attributes.position,b=C(i,a$1),A=U(r,s);if(zt.copy(n).invert(),e.boundsTree)return H(i,c,jt),jt.matrix.copy(zt),jt.needsUpdate=true,e.boundsTree.shapecast({intersectsBounds:a(m=>jt.intersectsBox(m),"intersectsBounds"),intersectsTriangle:a(m=>{m.a.applyMatrix4(n),m.b.applyMatrix4(n),m.c.applyMatrix4(n),m.needsUpdate=true;for(let T=b,h=A+b;T<h;T++)if(V(At,3*t.resolveTriangleIndex(T),f,l),At.needsUpdate=true,m.intersectsTriangle(At))return true;return false},"intersectsTriangle")});{let g=st(e);for(let m=b,T=A+b;m<T;m++){let h=t.resolveTriangleIndex(m);V(vt,3*h,f,l),vt.a.applyMatrix4(zt),vt.b.applyMatrix4(zt),vt.c.applyMatrix4(zt),vt.needsUpdate=true;for(let y=0,B=g*3;y<B;y+=3)if(V(At,y,d,v),At.needsUpdate=true,vt.intersectsTriangle(At))return true}}}else {let u=O(i),f=z(i,a$1);return H(u,c,Qt),!!(o.intersectsBox(Qt)&&Ce(u,t,e,n,o)||(H(f,c,Qt),o.intersectsBox(Qt)&&Ce(f,t,e,n,o)))}}a(Ce,"_intersectsGeometry");var te=new Matrix4,Oe=new k,Ut=new k,Vi=new Vector3,Hi=new Vector3,ki=new Vector3,qi=new Vector3;function Mn(i,t,e,n={},o={},c=0,s=1/0){t.boundingBox||t.computeBoundingBox(),Oe.set(t.boundingBox.min,t.boundingBox.max,e),Oe.needsUpdate=true;let a$1=i.geometry,r=a$1.attributes.position,p=a$1.index,u=t.attributes.position,f=t.index,l=Y.getPrimitive(),d=Y.getPrimitive(),v=Vi,b=Hi,A=null,g=null;o&&(A=ki,g=qi);let m=1/0,T=null,h=null;return te.copy(e).invert(),Ut.matrix.copy(te),i.shapecast({boundsTraverseOrder:a(y=>Oe.distanceToBox(y),"boundsTraverseOrder"),intersectsBounds:a((y,B,w)=>w<m&&w<s?(B&&(Ut.min.copy(y.min),Ut.max.copy(y.max),Ut.needsUpdate=true),true):false,"intersectsBounds"),intersectsRange:a((y,B)=>{if(t.boundsTree){let w=t.boundsTree;return w.shapecast({boundsTraverseOrder:a(S=>Ut.distanceToBox(S),"boundsTraverseOrder"),intersectsBounds:a((S,I,_)=>_<m&&_<s,"intersectsBounds"),intersectsRange:a((S,I)=>{for(let _=S,E=S+I;_<E;_++){let P=w.resolveTriangleIndex(_);V(d,3*P,f,u),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=true;for(let D=y,N=y+B;D<N;D++){let F=i.resolveTriangleIndex(D);V(l,3*F,p,r),l.needsUpdate=true;let L=l.distanceToTriangle(d,v,A);if(L<m&&(b.copy(v),g&&g.copy(A),m=L,T=D,h=_),L<c)return true}}},"intersectsRange")})}else {let w=st(t);for(let S=0,I=w;S<I;S++){V(d,3*S,f,u),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=true;for(let _=y,E=y+B;_<E;_++){let P=i.resolveTriangleIndex(_);V(l,3*P,p,r),l.needsUpdate=true;let D=l.distanceToTriangle(d,v,A);if(D<m&&(b.copy(v),g&&g.copy(A),m=D,T=_,h=S),D<c)return true}}}},"intersectsRange")}),Y.releasePrimitive(l),Y.releasePrimitive(d),m===1/0?null:(n.point?n.point.copy(b):n.point=b.clone(),n.distance=m,n.faceIndex=T,o&&(o.point?o.point.copy(g):o.point=g.clone(),o.point.applyMatrix4(te),b.applyMatrix4(te),o.distance=b.sub(o.point).length(),o.faceIndex=h),n)}a(Mn,"closestPointToGeometry_indirect");function ze(i,t,e){return i===null?null:(i.point.applyMatrix4(t.matrixWorld),i.distance=i.point.distanceTo(e.ray.origin),i.object=t,i)}a(ze,"convertRaycastIntersect");function Rn(){return typeof SharedArrayBuffer<"u"}a(Rn,"isSharedArrayBufferSupported");function ne(i,t,e,n,o){let c=1/0,s=1/0,a=1/0,r=-1/0,p=-1/0,u=-1/0,f=1/0,l=1/0,d=1/0,v=-1/0,b=-1/0,A=-1/0,g=i.offset||0;for(let m=(t-g)*6,T=(t+e-g)*6;m<T;m+=6){let h=i[m+0],y=i[m+1],B=h-y,w=h+y;B<c&&(c=B),w>r&&(r=w),h<f&&(f=h),h>v&&(v=h);let S=i[m+2],I=i[m+3],_=S-I,E=S+I;_<s&&(s=_),E>p&&(p=E),S<l&&(l=S),S>b&&(b=S);let P=i[m+4],D=i[m+5],N=P-D,F=P+D;N<a&&(a=N),F>u&&(u=F),P<d&&(d=P),P>A&&(A=P);}n[0]=c,n[1]=s,n[2]=a,n[3]=r,n[4]=p,n[5]=u,o[0]=f,o[1]=l,o[2]=d,o[3]=v,o[4]=b,o[5]=A;}a(ne,"getBounds");var et=32,Xi=a((i,t)=>i.candidate-t.candidate,"binsSort"),rt=new Array(et).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),ie=new Float32Array(6);function Cn(i,t,e,n,o,c){let s=-1,a=0;if(c===0)s=Pe(t),s!==-1&&(a=(t[s]+t[s+3])/2);else if(c===1)s=Pe(i),s!==-1&&(a=Yi(e,n,o,s));else if(c===2){let r=ht(i),p=1.25*o,u=e.offset||0,f=(n-u)*6,l=(n+o-u)*6;for(let d=0;d<3;d++){let v=t[d],g=(t[d+3]-v)/et;if(o<et/4){let m=[...rt];m.length=o;let T=0;for(let y=f;y<l;y+=6,T++){let B=m[T];B.candidate=e[y+2*d],B.count=0;let{bounds:w,leftCacheBounds:S,rightCacheBounds:I}=B;for(let _=0;_<3;_++)I[_]=1/0,I[_+3]=-1/0,S[_]=1/0,S[_+3]=-1/0,w[_]=1/0,w[_+3]=-1/0;Rt(y,e,w);}m.sort(Xi);let h=o;for(let y=0;y<h;y++){let B=m[y];for(;y+1<h&&m[y+1].candidate===B.candidate;)m.splice(y+1,1),h--;}for(let y=f;y<l;y+=6){let B=e[y+2*d];for(let w=0;w<h;w++){let S=m[w];B>=S.candidate?Rt(y,e,S.rightCacheBounds):(Rt(y,e,S.leftCacheBounds),S.count++);}}for(let y=0;y<h;y++){let B=m[y],w=B.count,S=o-B.count,I=B.leftCacheBounds,_=B.rightCacheBounds,E=0;w!==0&&(E=ht(I)/r);let P=0;S!==0&&(P=ht(_)/r);let D=1+1.25*(E*w+P*S);D<p&&(s=d,p=D,a=B.candidate);}}else {for(let h=0;h<et;h++){let y=rt[h];y.count=0,y.candidate=v+g+h*g;let B=y.bounds;for(let w=0;w<3;w++)B[w]=1/0,B[w+3]=-1/0;}for(let h=f;h<l;h+=6){let w=~~((e[h+2*d]-v)/g);w>=et&&(w=et-1);let S=rt[w];S.count++,Rt(h,e,S.bounds);}let m=rt[et-1];Ie(m.bounds,m.rightCacheBounds);for(let h=et-2;h>=0;h--){let y=rt[h],B=rt[h+1];Ee(y.bounds,B.rightCacheBounds,y.rightCacheBounds);}let T=0;for(let h=0;h<et-1;h++){let y=rt[h],B=y.count,w=y.bounds,I=rt[h+1].rightCacheBounds;B!==0&&(T===0?Ie(w,ie):Ee(w,ie,ie)),T+=B;let _=0,E=0;T!==0&&(_=ht(ie)/r);let P=o-T;P!==0&&(E=ht(I)/r);let D=1+1.25*(_*T+E*P);D<p&&(s=d,p=D,a=y.candidate);}}}}else console.warn(`BVH: Invalid build strategy value ${c} used.`);return {axis:s,pos:a}}a(Cn,"getOptimalSplit");function Yi(i,t,e,n){let o=0,c=i.offset;for(let s=t,a=t+e;s<a;s++)o+=i[(s-c)*6+n*2];return o/e}a(Yi,"getAverage");var bt=class{static{a(this,"BVHNode");}constructor(){this.boundingData=new Float32Array(6);}};function On(i,t,e,n,o,c){let s=n,a=n+o-1,r=c.pos,p=c.axis*2,u=e.offset||0;for(;;){for(;s<=a&&e[(s-u)*6+p]<r;)s++;for(;s<=a&&e[(a-u)*6+p]>=r;)a--;if(s<a){for(let f=0;f<t;f++){let l=i[s*t+f];i[s*t+f]=i[a*t+f],i[a*t+f]=l;}for(let f=0;f<6;f++){let l=s-u,d=a-u,v=e[l*6+f];e[l*6+f]=e[d*6+f],e[d*6+f]=v;}s++,a--;}else return s}}a(On,"partition");var zn,oe,Ue,Un,Ki=Math.pow(2,32);function se(i){return "count"in i?1:1+se(i.left)+se(i.right)}a(se,"countNodes");function Vn(i,t,e){return zn=new Float32Array(e),oe=new Uint32Array(e),Ue=new Uint16Array(e),Un=new Uint8Array(e),Ve(i,t)}a(Vn,"populateBuffer");function Ve(i,t){let e=i/4,n=i/2,o="count"in t,c=t.boundingData;for(let s=0;s<6;s++)zn[e+s]=c[s];if(o)return t.buffer?(Un.set(new Uint8Array(t.buffer),i),i+t.buffer.byteLength):(oe[e+6]=t.offset,Ue[n+14]=t.count,Ue[n+15]=65535,i+32);{let{left:s,right:a,splitAxis:r}=t,p=i+32,u=Ve(p,s),f=i/32,d=u/32-f;if(d>Ki)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return oe[e+6]=d,oe[e+7]=r,Ve(u,a)}}a(Ve,"_populateBuffer");function Zi(i,t,e,n,o){let{maxDepth:c,verbose:s,maxLeafSize:a$1,strategy:r,onProgress:p}=o,u=i.primitiveBuffer,f=i.primitiveBufferStride,l=new Float32Array(6),d=false,v=new bt;return ne(t,e,n,v.boundingData,l),A(v,e,n,l),v;function b(g){p&&p(g/n);}function A(g,m,T,h=null,y=0){if(!d&&y>=c&&(d=true,s&&console.warn(`BVH: Max depth of ${c} reached when generating BVH. Consider increasing maxDepth.`)),T<=a$1||y>=c)return b(m+T),g.offset=m,g.count=T,g;let B=Cn(g.boundingData,h,t,m,T,r);if(B.axis===-1)return b(m+T),g.offset=m,g.count=T,g;let w=On(u,f,t,m,T,B);if(w===m||w===m+T)b(m+T),g.offset=m,g.count=T;else {g.splitAxis=B.axis;let S=new bt,I=m,_=w-m;g.left=S,ne(t,I,_,S.boundingData,l),A(S,I,_,l,y+1);let E=new bt,P=w,D=T-_;g.right=E,ne(t,P,D,E.boundingData,l),A(E,P,D,l,y+1);}return g}}a(Zi,"buildTree");function Hn(i,t){let e=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=i.getRootRanges(t.range),o=n[0],c=n[n.length-1],s={offset:o.offset,count:c.offset+c.count-o.offset},a=new Float32Array(6*s.count);a.offset=s.offset,i.computePrimitiveBounds(s.offset,s.count,a),i._roots=n.map(r=>{let p=Zi(i,a,r.offset,r.count,t),u=se(p),f=new e(32*u);return Vn(0,p,f),f});}a(Hn,"buildPackedTree");var ct,Bt,wt=[],re=new it(()=>new Box3);function kn(i,t,e,n,o,c){ct=re.getPrimitive(),Bt=re.getPrimitive(),wt.push(ct,Bt),R.setBuffer(i._roots[t]);let s=He(0,i.geometry,e,n,o,c);R.clearBuffer(),re.releasePrimitive(ct),re.releasePrimitive(Bt),wt.pop(),wt.pop();let a=wt.length;return a>0&&(Bt=wt[a-1],ct=wt[a-2]),s}a(kn,"shapecast");function He(i,t,e,n,o=null,c=0,s=0){let{float32Array:a$1,uint16Array:r,uint32Array:p}=R,u=i*2;if(M(u,r)){let v=C(i,p),b=U(u,r);return H(i,a$1,ct),n(v,b,false,s,c+i/8,ct)}else {let P=function(N){let{uint16Array:F,uint32Array:L}=R,$=N*2;for(;!M($,F);)N=O(N),$=N*2;return C(N,L)},D=function(N){let{uint16Array:F,uint32Array:L}=R,$=N*2;for(;!M($,F);)N=z(N,L),$=N*2;return C(N,L)+U($,F)};a(P,"getLeftOffset"),a(D,"getRightEndOffset");let v=O(i),b=z(i,p),A=v,g=b,m,T,h,y;if(o&&(h=ct,y=Bt,H(A,a$1,h),H(g,a$1,y),m=o(h),T=o(y),T<m)){A=b,g=v;let N=m;m=T,T=N,h=y;}h||(h=ct,H(A,a$1,h));let B=M(A*2,r),w=e(h,B,m,s+1,c+A/8),S;if(w===2){let N=P(A),L=D(A)-N;S=n(N,L,true,s+1,c+A/8,h);}else S=w&&He(A,t,e,n,o,c,s+1);if(S)return true;y=Bt,H(g,a$1,y);let I=M(g*2,r),_=e(y,I,T,s+1,c+g/8),E;if(_===2){let N=P(g),L=D(g)-N;E=n(N,L,true,s+1,c+g/8,y);}else E=_&&He(g,t,e,n,o,c,s+1);return !!E}}a(He,"shapecastTraverse");var Vt=new R.constructor,ce=new R.constructor,at=new it(()=>new Box3),_t=new Box3,St=new Box3,ke=new Box3,qe=new Box3,Ge=false;function qn(i,t,e,n){if(Ge)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Ge=true;let o=i._roots,c=t._roots,s,a=0,r=0,p=new Matrix4().copy(e).invert();for(let u=0,f=o.length;u<f;u++){Vt.setBuffer(o[u]),r=0;let l=at.getPrimitive();H(0,Vt.float32Array,l),l.applyMatrix4(p);for(let d=0,v=c.length;d<v&&(ce.setBuffer(c[d]),s=Q(0,0,e,p,n,a,r,0,0,l),ce.clearBuffer(),r+=c[d].byteLength/32,!s);d++);if(at.releasePrimitive(l),Vt.clearBuffer(),a+=o[u].byteLength/32,s)break}return Ge=false,s}a(qn,"bvhcast");function Q(i,t,e,n,o,c=0,s=0,a=0,r=0,p=null,u=false){let f,l;u?(f=ce,l=Vt):(f=Vt,l=ce);let d=f.float32Array,v=f.uint32Array,b=f.uint16Array,A=l.float32Array,g=l.uint32Array,m=l.uint16Array,T=i*2,h=t*2,y=M(T,b),B=M(h,m),w=false;if(B&&y)u?w=o(C(t,g),U(t*2,m),C(i,v),U(i*2,b),r,s+t/8,a,c+i/8):w=o(C(i,v),U(i*2,b),C(t,g),U(t*2,m),a,c+i/8,r,s+t/8);else if(B){let S=at.getPrimitive();H(t,A,S),S.applyMatrix4(e);let I=O(i),_=z(i,v);H(I,d,_t),H(_,d,St);let E=S.intersectsBox(_t),P=S.intersectsBox(St);w=E&&Q(t,I,n,e,o,s,c,r,a+1,S,!u)||P&&Q(t,_,n,e,o,s,c,r,a+1,S,!u),at.releasePrimitive(S);}else {let S=O(t),I=z(t,g);H(S,A,ke),H(I,A,qe);let _=p.intersectsBox(ke),E=p.intersectsBox(qe);if(_&&E)w=Q(i,S,e,n,o,c,s,a,r+1,p,u)||Q(i,I,e,n,o,c,s,a,r+1,p,u);else if(_)if(y)w=Q(i,S,e,n,o,c,s,a,r+1,p,u);else {let P=at.getPrimitive();P.copy(ke).applyMatrix4(e);let D=O(i),N=z(i,v);H(D,d,_t),H(N,d,St);let F=P.intersectsBox(_t),L=P.intersectsBox(St);w=F&&Q(S,D,n,e,o,s,c,r,a+1,P,!u)||L&&Q(S,N,n,e,o,s,c,r,a+1,P,!u),at.releasePrimitive(P);}else if(E)if(y)w=Q(i,I,e,n,o,c,s,a,r+1,p,u);else {let P=at.getPrimitive();P.copy(qe).applyMatrix4(e);let D=O(i),N=z(i,v);H(D,d,_t),H(N,d,St);let F=P.intersectsBox(_t),L=P.intersectsBox(St);w=F&&Q(I,D,n,e,o,s,c,r,a+1,P,!u)||L&&Q(I,N,n,e,o,s,c,r,a+1,P,!u),at.releasePrimitive(P);}}return w}a(Q,"_traverse");var Gn=new Box3,Pt=new Float32Array(6),ae=class{static{a(this,"BVH");}constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null;}init(t){t={...kt,...t},Hn(this,t);}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(t,e,n,o){let c=1/0,s=1/0,a=1/0,r=-1/0,p=-1/0,u=-1/0;for(let f=t,l=t+e;f<l;f++){this.writePrimitiveBounds(f,Pt,0);let[d,v,b,A,g,m]=Pt;d<c&&(c=d),A>r&&(r=A),v<s&&(s=v),g>p&&(p=g),b<a&&(a=b),m>u&&(u=m);}return n[o+0]=c,n[o+1]=s,n[o+2]=a,n[o+3]=r,n[o+4]=p,n[o+5]=u,n}computePrimitiveBounds(t,e,n){let o=n.offset||0;for(let c=t,s=t+e;c<s;c++){this.writePrimitiveBounds(c,Pt,0);let[a,r,p,u,f,l]=Pt,d=(a+u)/2,v=(r+f)/2,b=(p+l)/2,A=(u-a)/2,g=(f-r)/2,m=(l-p)/2,T=(c-o)*6;n[T+0]=d,n[T+1]=A+(Math.abs(d)+A)*mt,n[T+2]=v,n[T+3]=g+(Math.abs(v)+g)*mt,n[T+4]=b,n[T+5]=m+(Math.abs(b)+m)*mt;}return n}shiftPrimitiveOffsets(t){let e=this._indirectBuffer;if(e)for(let n=0,o=e.length;n<o;n++)e[n]+=t;else {let n=this._roots;for(let o=0;o<n.length;o++){let c=n[o],s=new Uint32Array(c),a=new Uint16Array(c),r=c.byteLength/32;for(let p=0;p<r;p++){let u=8*p,f=2*u;M(f,a)&&(s[u+6]+=t);}}}}traverse(t,e=0){let n=this._roots[e],o=new Uint32Array(n),c=new Uint16Array(n);s(0);function s(a,r=0){let p=a*2,u=M(p,c);if(u){let f=o[a+6],l=c[p+14];t(r,u,new Float32Array(n,a*4,6),f,l);}else {let f=O(a),l=z(a,o),d=ot(a,o);t(r,u,new Float32Array(n,a*4,6),d)||(s(f,r+1),s(l,r+1));}}a(s,"_traverse");}refit(){let t=this._roots;for(let e=0,n=t.length;e<n;e++){let o=t[e],c=new Uint32Array(o),s=new Uint16Array(o),a=new Float32Array(o),r=o.byteLength/32;for(let p=r-1;p>=0;p--){let u=p*8,f=u*2;if(M(f,s)){let d=C(u,c),v=U(f,s);this.writePrimitiveRangeBounds(d,v,Pt,0),a.set(Pt,u);}else {let d=O(u),v=z(u,c);for(let b=0;b<3;b++){let A=a[d+b],g=a[d+b+3],m=a[v+b],T=a[v+b+3];a[u+b]=A<m?A:m,a[u+b+3]=g>T?g:T;}}}}}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(n=>{H(0,new Float32Array(n),Gn),t.union(Gn);}),t}shapecast(t){let{boundsTraverseOrder:e,intersectsBounds:n,intersectsRange:o,intersectsPrimitive:c,scratchPrimitive:s,iterate:a$1}=t;if(o&&c){let f=o;o=a((l,d,v,b,A)=>f(l,d,v,b,A)?true:a$1(l,d,this,c,v,b,s),"intersectsRange");}else o||(c?o=a((f,l,d,v)=>a$1(f,l,this,c,d,v,s),"intersectsRange"):o=a((f,l,d)=>d,"intersectsRange"));let r=false,p=0,u=this._roots;for(let f=0,l=u.length;f<l;f++){let d=u[f];if(r=kn(this,f,n,o,e,p),r)break;p+=d.byteLength/32;}return r}bvhcast(t,e,n){let{intersectsRanges:o}=n;return qn(this,t,e,o)}};function to(i,t){let e=i[i.length-1],n=e.offset+e.count>2**16,o=i.reduce((p,u)=>p+u.count,0),c=n?4:2,s=t?new SharedArrayBuffer(o*c):new ArrayBuffer(o*c),a=n?new Uint32Array(s):new Uint16Array(s),r=0;for(let p=0;p<i.length;p++){let{offset:u,count:f}=i[p];for(let l=0;l<f;l++)a[r+l]=u+l;r+=f;}return a}a(to,"generateIndirectBuffer");var le=class extends ae{static{a(this,"GeometryBVH");}get indirect(){return !!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(t){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(t){}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("BVH: Only BufferGeometries are supported.");if(e.useSharedArrayBuffer&&!Rn())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=t,this.resolvePrimitiveIndex=e.indirect?n=>this._indirectBuffer[n]:n=>n,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,e={...kt,...e},e[It]||this.init(e);}init(t){let{geometry:e,primitiveStride:n}=this;if(t.indirect){let o=Ne(e,t.range,n),c=to(o,t.useSharedArrayBuffer);this._indirectBuffer=c;}else Bn(e,t);super.init(t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new Box3));}getRootRanges(t){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Ne(this.geometry,t,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}};var fe=new k,ue=new Ray,Yn=new Vector3,Kn=new Matrix4,Zn=new Vector3,Xe=["getX","getY","getZ"],Wn=class i extends le{static{a(this,"MeshBVH");}static serialize(t,e={}){e={cloneBuffers:true,...e};let n=t.geometry,o=t._roots,c=t._indirectBuffer,s=n.getIndex(),a={version:1,roots:null,index:null,indirectBuffer:null};return e.cloneBuffers?(a.roots=o.map(r=>r.slice()),a.index=s?s.array.slice():null,a.indirectBuffer=c?c.slice():null):(a.roots=o,a.index=s?s.array:null,a.indirectBuffer=c),a}static deserialize(t,e,n={}){n={setIndex:true,indirect:!!t.indirectBuffer,...n};let{index:o,roots:c,indirectBuffer:s}=t;t.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),r(c));let a=new i(e,{...n,[It]:true});if(a._roots=c,a._indirectBuffer=s||null,n.setIndex){let p=e.getIndex();if(p===null){let u=new BufferAttribute(t.index,1,false);e.setIndex(u);}else p.array!==o&&(p.array.set(o),p.needsUpdate=true);}return a;function r(p){for(let u=0;u<p.length;u++){let f=p[u],l=new Uint32Array(f),d=new Uint16Array(f);for(let v=0,b=f.byteLength/32;v<b;v++){let A=8*v,g=2*A;M(g,d)||(l[A+6]=l[A+6]/8-v);}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(t,e={}){e.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use maxLeafSize, instead.'),e={...e,maxLeafSize:e.maxLeafTris}),super(t,e);}shiftTriangleOffsets(t){return super.shiftPrimitiveOffsets(t)}writePrimitiveBounds(t,e,n){let o=this.geometry,c=this._indirectBuffer,s=o.attributes.position,a=o.index?o.index.array:null,p=(c?c[t]:t)*3,u=p+0,f=p+1,l=p+2;a&&(u=a[u],f=a[f],l=a[l]);for(let d=0;d<3;d++){let v=s[Xe[d]](u),b=s[Xe[d]](f),A=s[Xe[d]](l),g=v;b<g&&(g=b),A<g&&(g=A);let m=v;b>m&&(m=b),A>m&&(m=A),e[n+d]=g,e[n+d+3]=m;}return e}computePrimitiveBounds(t,e,n){let o=this.geometry,c=this._indirectBuffer,s=o.attributes.position,a=o.index?o.index.array:null,r=s.normalized;if(t<0||e+t-n.offset>n.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");let p=s.array,u=s.offset||0,f=3;s.isInterleavedBufferAttribute&&(f=s.data.stride);let l=["getX","getY","getZ"],d=n.offset;for(let v=t,b=t+e;v<b;v++){let g=(c?c[v]:v)*3,m=(v-d)*6,T=g+0,h=g+1,y=g+2;a&&(T=a[T],h=a[h],y=a[y]),r||(T=T*f+u,h=h*f+u,y=y*f+u);for(let B=0;B<3;B++){let w,S,I;r?(w=s[l[B]](T),S=s[l[B]](h),I=s[l[B]](y)):(w=p[T+B],S=p[h+B],I=p[y+B]);let _=w;S<_&&(_=S),I<_&&(_=I);let E=w;S>E&&(E=S),I>E&&(E=I);let P=(E-_)/2,D=B*2;n[m+D+0]=_+P,n[m+D+1]=P+(Math.abs(_)+P)*mt;}}return n}raycastObject3D(t,e,n=[]){let{material:o}=t;if(o===void 0)return;Kn.copy(t.matrixWorld).invert(),ue.copy(e.ray).applyMatrix4(Kn),Zn.setFromMatrixScale(t.matrixWorld),Yn.copy(ue.direction).multiply(Zn);let c=Yn.length(),s=e.near/c,a=e.far/c;if(e.firstHitOnly===true){let r=this.raycastFirst(ue,o,s,a);r=ze(r,t,e),r&&n.push(r);}else {let r=this.raycast(ue,o,s,a);for(let p=0,u=r.length;p<u;p++){let f=ze(r[p],t,e);f&&n.push(f);}}return n}refit(t=null){return (this.indirect?In:Tn)(this,t)}raycast(t,e=FrontSide,n=0,o=1/0){let c=this._roots,s=[],a=this.indirect?En:bn;for(let r=0,p=c.length;r<p;r++)a(this,r,e,t,s,n,o);return s}raycastFirst(t,e=FrontSide,n=0,o=1/0){let c=this._roots,s=null,a=this.indirect?Dn:wn;for(let r=0,p=c.length;r<p;r++){let u=a(this,r,e,t,n,o);u!=null&&(s==null||u.distance<s.distance)&&(s=u);}return s}intersectsGeometry(t,e){let n=false,o=this._roots,c=this.indirect?Fn:Sn;for(let s=0,a=o.length;s<a&&(n=c(this,s,t,e),!n);s++);return n}shapecast(t){let e=Y.getPrimitive(),n=super.shapecast({...t,intersectsPrimitive:t.intersectsTriangle,scratchPrimitive:e,iterate:this.indirect?An:hn});return Y.releasePrimitive(e),n}bvhcast(t,e,n){let{intersectsRanges:o,intersectsTriangles:c}=n,s=Y.getPrimitive(),a$1=this.geometry.index,r=this.geometry.attributes.position,p=this.indirect?v=>{let b=this.resolveTriangleIndex(v);V(s,b*3,a$1,r);}:v=>{V(s,v*3,a$1,r);},u=Y.getPrimitive(),f=t.geometry.index,l=t.geometry.attributes.position,d=t.indirect?v=>{let b=t.resolveTriangleIndex(v);V(u,b*3,f,l);}:v=>{V(u,v*3,f,l);};if(c){if(!(t instanceof i))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');let v=a((b,A,g,m,T,h,y,B)=>{for(let w=g,S=g+m;w<S;w++){d(w),u.a.applyMatrix4(e),u.b.applyMatrix4(e),u.c.applyMatrix4(e),u.needsUpdate=true;for(let I=b,_=b+A;I<_;I++)if(p(I),s.needsUpdate=true,c(s,u,I,w,T,h,y,B))return true}return false},"iterateOverDoubleTriangles");if(o){let b=o;o=a(function(A,g,m,T,h,y,B,w){return b(A,g,m,T,h,y,B,w)?true:v(A,g,m,T,h,y,B,w)},"intersectsRanges");}else o=v;}return super.bvhcast(t,e,{intersectsRanges:o})}intersectsBox(t,e){return fe.set(t.min,t.max,e),fe.needsUpdate=true,this.shapecast({intersectsBounds:a(n=>fe.intersectsBox(n),"intersectsBounds"),intersectsTriangle:a(n=>fe.intersectsTriangle(n),"intersectsTriangle")})}intersectsSphere(t){return this.shapecast({intersectsBounds:a(e=>t.intersectsBox(e),"intersectsBounds"),intersectsTriangle:a(e=>e.intersectsSphere(t),"intersectsTriangle")})}closestPointToGeometry(t,e,n={},o={},c=0,s=1/0){return (this.indirect?Mn:Pn)(this,t,e,n,o,c,s)}closestPointToPoint(t,e={},n=0,o=1/0){return an(this,t,e,n,o)}};function uo(i){switch(i){case 1:return "R";case 2:return "RG";case 3:return "RGBA";case 4:return "RGBA"}throw new Error}a(uo,"countToStringFormat");function po(i){switch(i){case 1:return RedFormat;case 2:return RGFormat;case 3:return RGBAFormat;case 4:return RGBAFormat}}a(po,"countToFormat");function ti(i){switch(i){case 1:return RedIntegerFormat;case 2:return RGIntegerFormat;case 3:return RGBAIntegerFormat;case 4:return RGBAIntegerFormat}}a(ti,"countToIntFormat");var me=class extends DataTexture{static{a(this,"VertexAttributeTexture");}constructor(){super(),this.minFilter=NearestFilter,this.magFilter=NearestFilter,this.generateMipmaps=false,this.overrideItemSize=null,this._forcedType=null;}updateFrom(t){let e=this.overrideItemSize,n=t.itemSize,o=t.count;if(e!==null){if(n*o%e!==0)throw new Error("VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.");t.itemSize=e,t.count=o*n/e;}let c=t.itemSize,s=t.count,a=t.normalized,r=t.array.constructor,p=r.BYTES_PER_ELEMENT,u=this._forcedType,f=c;if(u===null)switch(r){case Float32Array:u=FloatType;break;case Uint8Array:case Uint16Array:case Uint32Array:u=UnsignedIntType;break;case Int8Array:case Int16Array:case Int32Array:u=IntType;break}let l,d,v,b,A=uo(c);switch(u){case FloatType:v=1,d=po(c),a&&p===1?(b=r,A+="8",r===Uint8Array?l=UnsignedByteType:(l=ByteType,A+="_SNORM")):(b=Float32Array,A+="32F",l=FloatType);break;case IntType:A+=p*8+"I",v=a?Math.pow(2,r.BYTES_PER_ELEMENT*8-1):1,d=ti(c),p===1?(b=Int8Array,l=ByteType):p===2?(b=Int16Array,l=ShortType):(b=Int32Array,l=IntType);break;case UnsignedIntType:A+=p*8+"UI",v=a?Math.pow(2,r.BYTES_PER_ELEMENT*8-1):1,d=ti(c),p===1?(b=Uint8Array,l=UnsignedByteType):p===2?(b=Uint16Array,l=UnsignedShortType):(b=Uint32Array,l=UnsignedIntType);break}f===3&&(d===RGBAFormat||d===RGBAIntegerFormat)&&(f=4);let g=Math.ceil(Math.sqrt(s))||1,m=f*g*g,T=new b(m),h=t.normalized;t.normalized=false;for(let y=0;y<s;y++){let B=f*y;T[B]=t.getX(y)/v,c>=2&&(T[B+1]=t.getY(y)/v),c>=3&&(T[B+2]=t.getZ(y)/v,f===4&&(T[B+3]=1)),c>=4&&(T[B+3]=t.getW(y)/v);}t.normalized=h,this.internalFormat=A,this.format=d,this.type=l,this.image.width=g,this.image.height=g,this.image.data=T,this.needsUpdate=true,this.dispose(),t.itemSize=n,t.count=o;}},xe=class extends me{static{a(this,"UIntVertexAttributeTexture");}constructor(){super(),this._forcedType=UnsignedIntType;}};var ye=class extends me{static{a(this,"FloatVertexAttributeTexture");}constructor(){super(),this._forcedType=FloatType;}};var ni=class{static{a(this,"MeshBVHUniformStruct");}constructor(){this.index=new xe,this.position=new ye,this.bvhBounds=new DataTexture,this.bvhContents=new DataTexture,this._cachedIndexAttr=null,this.index.overrideItemSize=3;}updateFrom(t){let{geometry:e}=t;if(vo(t,this.bvhBounds,this.bvhContents),this.position.updateFrom(e.attributes.position),t.indirect){let n=t._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==n.length)if(e.index)this._cachedIndexAttr=e.index.clone();else {let o=De(Lt(e));this._cachedIndexAttr=new BufferAttribute(o,1,false);}go(e,n,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr);}else this.index.updateFrom(e.index);}dispose(){let{index:t,position:e,bvhBounds:n,bvhContents:o}=this;t&&t.dispose(),e&&e.dispose(),n&&n.dispose(),o&&o.dispose();}};function go(i,t,e){let n=e.array,o=i.index?i.index.array:null;for(let c=0,s=t.length;c<s;c++){let a=3*c,r=3*t[c];for(let p=0;p<3;p++)n[a+p]=o?o[r+p]:r+p;}}a(go,"dereferenceIndex");function vo(i,t,e){let n=i._roots;if(n.length!==1)throw new Error("MeshBVHUniformStruct: Multi-root BVHs not supported.");let o=n[0],c=new Uint16Array(o),s=new Uint32Array(o),a=new Float32Array(o),r=o.byteLength/32,p=2*Math.ceil(Math.sqrt(r/2)),u=new Float32Array(4*p*p),f=Math.ceil(Math.sqrt(r)),l=new Uint32Array(2*f*f);for(let d=0;d<r;d++){let v=d*32/4,b=v*2,A=v;for(let g=0;g<3;g++)u[8*d+0+g]=a[A+0+g],u[8*d+4+g]=a[A+3+g];if(M(b,c)){let g=U(b,c),m=C(v,s),T=-65536|g;l[d*2+0]=T,l[d*2+1]=m;}else {let g=s[v+6],m=ot(v,s);l[d*2+0]=m,l[d*2+1]=g;}}t.image.data=u,t.image.width=p,t.image.height=p,t.format=RGBAFormat,t.type=FloatType,t.internalFormat="RGBA32F",t.minFilter=NearestFilter,t.magFilter=NearestFilter,t.generateMipmaps=false,t.needsUpdate=true,t.dispose(),e.image.data=l,e.image.width=f,e.image.height=f,e.format=RGIntegerFormat,e.type=UnsignedIntType,e.internalFormat="RG32UI",e.minFilter=NearestFilter,e.magFilter=NearestFilter,e.generateMipmaps=false,e.needsUpdate=true,e.dispose();}a(vo,"bvhToTextures");var Je={};b(Je,{bvh_distance_functions:()=>ii,bvh_ray_functions:()=>$e,bvh_struct_definitions:()=>oi,common_functions:()=>We});var We=`
|
|
2
|
+
|
|
3
|
+
// A stack of uint32 indices can can store the indices for
|
|
4
|
+
// a perfectly balanced tree with a depth up to 31. Lower stack
|
|
5
|
+
// depth gets higher performance.
|
|
6
|
+
//
|
|
7
|
+
// However not all trees are balanced. Best value to set this to
|
|
8
|
+
// is the trees max depth.
|
|
9
|
+
#ifndef BVH_STACK_DEPTH
|
|
10
|
+
#define BVH_STACK_DEPTH 60
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
#ifndef INFINITY
|
|
14
|
+
#define INFINITY 1e20
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
// Utilities
|
|
18
|
+
uvec4 uTexelFetch1D( usampler2D tex, uint index ) {
|
|
19
|
+
|
|
20
|
+
uint width = uint( textureSize( tex, 0 ).x );
|
|
21
|
+
uvec2 uv;
|
|
22
|
+
uv.x = index % width;
|
|
23
|
+
uv.y = index / width;
|
|
24
|
+
|
|
25
|
+
return texelFetch( tex, ivec2( uv ), 0 );
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
ivec4 iTexelFetch1D( isampler2D tex, uint index ) {
|
|
30
|
+
|
|
31
|
+
uint width = uint( textureSize( tex, 0 ).x );
|
|
32
|
+
uvec2 uv;
|
|
33
|
+
uv.x = index % width;
|
|
34
|
+
uv.y = index / width;
|
|
35
|
+
|
|
36
|
+
return texelFetch( tex, ivec2( uv ), 0 );
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
vec4 texelFetch1D( sampler2D tex, uint index ) {
|
|
41
|
+
|
|
42
|
+
uint width = uint( textureSize( tex, 0 ).x );
|
|
43
|
+
uvec2 uv;
|
|
44
|
+
uv.x = index % width;
|
|
45
|
+
uv.y = index / width;
|
|
46
|
+
|
|
47
|
+
return texelFetch( tex, ivec2( uv ), 0 );
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
vec4 textureSampleBarycoord( sampler2D tex, vec3 barycoord, uvec3 faceIndices ) {
|
|
52
|
+
|
|
53
|
+
return
|
|
54
|
+
barycoord.x * texelFetch1D( tex, faceIndices.x ) +
|
|
55
|
+
barycoord.y * texelFetch1D( tex, faceIndices.y ) +
|
|
56
|
+
barycoord.z * texelFetch1D( tex, faceIndices.z );
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
void ndcToCameraRay(
|
|
61
|
+
vec2 coord, mat4 cameraWorld, mat4 invProjectionMatrix,
|
|
62
|
+
out vec3 rayOrigin, out vec3 rayDirection
|
|
63
|
+
) {
|
|
64
|
+
|
|
65
|
+
// get camera look direction and near plane for camera clipping
|
|
66
|
+
vec4 lookDirection = cameraWorld * vec4( 0.0, 0.0, - 1.0, 0.0 );
|
|
67
|
+
vec4 nearVector = invProjectionMatrix * vec4( 0.0, 0.0, - 1.0, 1.0 );
|
|
68
|
+
float near = abs( nearVector.z / nearVector.w );
|
|
69
|
+
|
|
70
|
+
// get the camera direction and position from camera matrices
|
|
71
|
+
vec4 origin = cameraWorld * vec4( 0.0, 0.0, 0.0, 1.0 );
|
|
72
|
+
vec4 direction = invProjectionMatrix * vec4( coord, 0.5, 1.0 );
|
|
73
|
+
direction /= direction.w;
|
|
74
|
+
direction = cameraWorld * direction - origin;
|
|
75
|
+
|
|
76
|
+
// slide the origin along the ray until it sits at the near clip plane position
|
|
77
|
+
origin.xyz += direction.xyz * near / dot( direction, lookDirection );
|
|
78
|
+
|
|
79
|
+
rayOrigin = origin.xyz;
|
|
80
|
+
rayDirection = direction.xyz;
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
`;var ii=`
|
|
84
|
+
|
|
85
|
+
float dot2( vec3 v ) {
|
|
86
|
+
|
|
87
|
+
return dot( v, v );
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// https://www.shadertoy.com/view/ttfGWl
|
|
92
|
+
vec3 closestPointToTriangle( vec3 p, vec3 v0, vec3 v1, vec3 v2, out vec3 barycoord ) {
|
|
93
|
+
|
|
94
|
+
vec3 v10 = v1 - v0;
|
|
95
|
+
vec3 v21 = v2 - v1;
|
|
96
|
+
vec3 v02 = v0 - v2;
|
|
97
|
+
|
|
98
|
+
vec3 p0 = p - v0;
|
|
99
|
+
vec3 p1 = p - v1;
|
|
100
|
+
vec3 p2 = p - v2;
|
|
101
|
+
|
|
102
|
+
vec3 nor = cross( v10, v02 );
|
|
103
|
+
|
|
104
|
+
// method 2, in barycentric space
|
|
105
|
+
vec3 q = cross( nor, p0 );
|
|
106
|
+
float d = 1.0 / dot2( nor );
|
|
107
|
+
float u = d * dot( q, v02 );
|
|
108
|
+
float v = d * dot( q, v10 );
|
|
109
|
+
float w = 1.0 - u - v;
|
|
110
|
+
|
|
111
|
+
if( u < 0.0 ) {
|
|
112
|
+
|
|
113
|
+
w = clamp( dot( p2, v02 ) / dot2( v02 ), 0.0, 1.0 );
|
|
114
|
+
u = 0.0;
|
|
115
|
+
v = 1.0 - w;
|
|
116
|
+
|
|
117
|
+
} else if( v < 0.0 ) {
|
|
118
|
+
|
|
119
|
+
u = clamp( dot( p0, v10 ) / dot2( v10 ), 0.0, 1.0 );
|
|
120
|
+
v = 0.0;
|
|
121
|
+
w = 1.0 - u;
|
|
122
|
+
|
|
123
|
+
} else if( w < 0.0 ) {
|
|
124
|
+
|
|
125
|
+
v = clamp( dot( p1, v21 ) / dot2( v21 ), 0.0, 1.0 );
|
|
126
|
+
w = 0.0;
|
|
127
|
+
u = 1.0 - v;
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
barycoord = vec3( u, v, w );
|
|
132
|
+
return u * v1 + v * v2 + w * v0;
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
float distanceToTriangles(
|
|
137
|
+
// geometry info and triangle range
|
|
138
|
+
sampler2D positionAttr, usampler2D indexAttr, uint offset, uint count,
|
|
139
|
+
|
|
140
|
+
// point and cut off range
|
|
141
|
+
vec3 point, float closestDistanceSquared,
|
|
142
|
+
|
|
143
|
+
// outputs
|
|
144
|
+
inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord, inout float side, inout vec3 outPoint
|
|
145
|
+
) {
|
|
146
|
+
|
|
147
|
+
bool found = false;
|
|
148
|
+
vec3 localBarycoord;
|
|
149
|
+
for ( uint i = offset, l = offset + count; i < l; i ++ ) {
|
|
150
|
+
|
|
151
|
+
uvec3 indices = uTexelFetch1D( indexAttr, i ).xyz;
|
|
152
|
+
vec3 a = texelFetch1D( positionAttr, indices.x ).rgb;
|
|
153
|
+
vec3 b = texelFetch1D( positionAttr, indices.y ).rgb;
|
|
154
|
+
vec3 c = texelFetch1D( positionAttr, indices.z ).rgb;
|
|
155
|
+
|
|
156
|
+
// get the closest point and barycoord
|
|
157
|
+
vec3 closestPoint = closestPointToTriangle( point, a, b, c, localBarycoord );
|
|
158
|
+
vec3 delta = point - closestPoint;
|
|
159
|
+
float sqDist = dot2( delta );
|
|
160
|
+
if ( sqDist < closestDistanceSquared ) {
|
|
161
|
+
|
|
162
|
+
// set the output results
|
|
163
|
+
closestDistanceSquared = sqDist;
|
|
164
|
+
faceIndices = uvec4( indices.xyz, i );
|
|
165
|
+
faceNormal = normalize( cross( a - b, b - c ) );
|
|
166
|
+
barycoord = localBarycoord;
|
|
167
|
+
outPoint = closestPoint;
|
|
168
|
+
side = sign( dot( faceNormal, delta ) );
|
|
169
|
+
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return closestDistanceSquared;
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
float distanceSqToBounds( vec3 point, vec3 boundsMin, vec3 boundsMax ) {
|
|
179
|
+
|
|
180
|
+
vec3 clampedPoint = clamp( point, boundsMin, boundsMax );
|
|
181
|
+
vec3 delta = point - clampedPoint;
|
|
182
|
+
return dot( delta, delta );
|
|
183
|
+
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
float distanceSqToBVHNodeBoundsPoint( vec3 point, sampler2D bvhBounds, uint currNodeIndex ) {
|
|
187
|
+
|
|
188
|
+
uint cni2 = currNodeIndex * 2u;
|
|
189
|
+
vec3 boundsMin = texelFetch1D( bvhBounds, cni2 ).xyz;
|
|
190
|
+
vec3 boundsMax = texelFetch1D( bvhBounds, cni2 + 1u ).xyz;
|
|
191
|
+
return distanceSqToBounds( point, boundsMin, boundsMax );
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// use a macro to hide the fact that we need to expand the struct into separate fields
|
|
196
|
+
#define bvhClosestPointToPoint( bvh, point, maxDistance, faceIndices, faceNormal, barycoord, side, outPoint ) _bvhClosestPointToPoint( bvh.position, bvh.index, bvh.bvhBounds, bvh.bvhContents, point, maxDistance, faceIndices, faceNormal, barycoord, side, outPoint )
|
|
197
|
+
|
|
198
|
+
float _bvhClosestPointToPoint(
|
|
199
|
+
// bvh info
|
|
200
|
+
sampler2D bvh_position, usampler2D bvh_index, sampler2D bvh_bvhBounds, usampler2D bvh_bvhContents,
|
|
201
|
+
|
|
202
|
+
// point to check
|
|
203
|
+
vec3 point, float maxDistance,
|
|
204
|
+
|
|
205
|
+
// output variables
|
|
206
|
+
inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord,
|
|
207
|
+
inout float side, inout vec3 outPoint
|
|
208
|
+
) {
|
|
209
|
+
|
|
210
|
+
// stack needs to be twice as long as the deepest tree we expect because
|
|
211
|
+
// we push both the left and right child onto the stack every traversal
|
|
212
|
+
int pointer = 0;
|
|
213
|
+
uint stack[ BVH_STACK_DEPTH ];
|
|
214
|
+
stack[ 0 ] = 0u;
|
|
215
|
+
|
|
216
|
+
float closestDistanceSquared = maxDistance * maxDistance;
|
|
217
|
+
bool found = false;
|
|
218
|
+
while ( pointer > - 1 && pointer < BVH_STACK_DEPTH ) {
|
|
219
|
+
|
|
220
|
+
uint currNodeIndex = stack[ pointer ];
|
|
221
|
+
pointer --;
|
|
222
|
+
|
|
223
|
+
// check if we intersect the current bounds
|
|
224
|
+
float boundsHitDistance = distanceSqToBVHNodeBoundsPoint( point, bvh_bvhBounds, currNodeIndex );
|
|
225
|
+
if ( boundsHitDistance > closestDistanceSquared ) {
|
|
226
|
+
|
|
227
|
+
continue;
|
|
228
|
+
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
uvec2 boundsInfo = uTexelFetch1D( bvh_bvhContents, currNodeIndex ).xy;
|
|
232
|
+
bool isLeaf = bool( boundsInfo.x & 0xffff0000u );
|
|
233
|
+
if ( isLeaf ) {
|
|
234
|
+
|
|
235
|
+
uint count = boundsInfo.x & 0x0000ffffu;
|
|
236
|
+
uint offset = boundsInfo.y;
|
|
237
|
+
closestDistanceSquared = distanceToTriangles(
|
|
238
|
+
bvh_position, bvh_index, offset, count, point, closestDistanceSquared,
|
|
239
|
+
|
|
240
|
+
// outputs
|
|
241
|
+
faceIndices, faceNormal, barycoord, side, outPoint
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
} else {
|
|
245
|
+
|
|
246
|
+
uint leftIndex = currNodeIndex + 1u;
|
|
247
|
+
uint splitAxis = boundsInfo.x & 0x0000ffffu;
|
|
248
|
+
uint rightIndex = currNodeIndex + boundsInfo.y;
|
|
249
|
+
bool leftToRight = distanceSqToBVHNodeBoundsPoint( point, bvh_bvhBounds, leftIndex ) < distanceSqToBVHNodeBoundsPoint( point, bvh_bvhBounds, rightIndex );//rayDirection[ splitAxis ] >= 0.0;
|
|
250
|
+
uint c1 = leftToRight ? leftIndex : rightIndex;
|
|
251
|
+
uint c2 = leftToRight ? rightIndex : leftIndex;
|
|
252
|
+
|
|
253
|
+
// set c2 in the stack so we traverse it later. We need to keep track of a pointer in
|
|
254
|
+
// the stack while we traverse. The second pointer added is the one that will be
|
|
255
|
+
// traversed first
|
|
256
|
+
pointer ++;
|
|
257
|
+
stack[ pointer ] = c2;
|
|
258
|
+
pointer ++;
|
|
259
|
+
stack[ pointer ] = c1;
|
|
260
|
+
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return sqrt( closestDistanceSquared );
|
|
266
|
+
|
|
267
|
+
}
|
|
268
|
+
`;var $e=`
|
|
269
|
+
|
|
270
|
+
#ifndef TRI_INTERSECT_EPSILON
|
|
271
|
+
#define TRI_INTERSECT_EPSILON 1e-5
|
|
272
|
+
#endif
|
|
273
|
+
|
|
274
|
+
// Raycasting
|
|
275
|
+
bool intersectsBounds( vec3 rayOrigin, vec3 rayDirection, vec3 boundsMin, vec3 boundsMax, out float dist ) {
|
|
276
|
+
|
|
277
|
+
// https://www.reddit.com/r/opengl/comments/8ntzz5/fast_glsl_ray_box_intersection/
|
|
278
|
+
// https://tavianator.com/2011/ray_box.html
|
|
279
|
+
vec3 invDir = 1.0 / rayDirection;
|
|
280
|
+
|
|
281
|
+
// find intersection distances for each plane
|
|
282
|
+
vec3 tMinPlane = invDir * ( boundsMin - rayOrigin );
|
|
283
|
+
vec3 tMaxPlane = invDir * ( boundsMax - rayOrigin );
|
|
284
|
+
|
|
285
|
+
// get the min and max distances from each intersection
|
|
286
|
+
vec3 tMinHit = min( tMaxPlane, tMinPlane );
|
|
287
|
+
vec3 tMaxHit = max( tMaxPlane, tMinPlane );
|
|
288
|
+
|
|
289
|
+
// get the furthest hit distance
|
|
290
|
+
vec2 t = max( tMinHit.xx, tMinHit.yz );
|
|
291
|
+
float t0 = max( t.x, t.y );
|
|
292
|
+
|
|
293
|
+
// get the minimum hit distance
|
|
294
|
+
t = min( tMaxHit.xx, tMaxHit.yz );
|
|
295
|
+
float t1 = min( t.x, t.y );
|
|
296
|
+
|
|
297
|
+
// set distance to 0.0 if the ray starts inside the box
|
|
298
|
+
dist = max( t0, 0.0 );
|
|
299
|
+
|
|
300
|
+
return t1 >= dist;
|
|
301
|
+
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
bool intersectsTriangle(
|
|
305
|
+
vec3 rayOrigin, vec3 rayDirection, vec3 a, vec3 b, vec3 c,
|
|
306
|
+
out vec3 barycoord, out vec3 norm, out float dist, out float side
|
|
307
|
+
) {
|
|
308
|
+
|
|
309
|
+
// https://stackoverflow.com/questions/42740765/intersection-between-line-and-triangle-in-3d
|
|
310
|
+
vec3 edge1 = b - a;
|
|
311
|
+
vec3 edge2 = c - a;
|
|
312
|
+
norm = cross( edge1, edge2 );
|
|
313
|
+
|
|
314
|
+
float det = - dot( rayDirection, norm );
|
|
315
|
+
float invdet = 1.0 / det;
|
|
316
|
+
|
|
317
|
+
vec3 AO = rayOrigin - a;
|
|
318
|
+
vec3 DAO = cross( AO, rayDirection );
|
|
319
|
+
|
|
320
|
+
vec4 uvt;
|
|
321
|
+
uvt.x = dot( edge2, DAO ) * invdet;
|
|
322
|
+
uvt.y = - dot( edge1, DAO ) * invdet;
|
|
323
|
+
uvt.z = dot( AO, norm ) * invdet;
|
|
324
|
+
uvt.w = 1.0 - uvt.x - uvt.y;
|
|
325
|
+
|
|
326
|
+
// set the hit information
|
|
327
|
+
barycoord = uvt.wxy; // arranged in A, B, C order
|
|
328
|
+
dist = uvt.z;
|
|
329
|
+
side = sign( det );
|
|
330
|
+
norm = side * normalize( norm );
|
|
331
|
+
|
|
332
|
+
// add an epsilon to avoid misses between triangles
|
|
333
|
+
uvt += vec4( TRI_INTERSECT_EPSILON );
|
|
334
|
+
|
|
335
|
+
return all( greaterThanEqual( uvt, vec4( 0.0 ) ) );
|
|
336
|
+
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
bool intersectTriangles(
|
|
340
|
+
// geometry info and triangle range
|
|
341
|
+
sampler2D positionAttr, usampler2D indexAttr, uint offset, uint count,
|
|
342
|
+
|
|
343
|
+
// ray
|
|
344
|
+
vec3 rayOrigin, vec3 rayDirection,
|
|
345
|
+
|
|
346
|
+
// outputs
|
|
347
|
+
inout float minDistance, inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord,
|
|
348
|
+
inout float side, inout float dist
|
|
349
|
+
) {
|
|
350
|
+
|
|
351
|
+
bool found = false;
|
|
352
|
+
vec3 localBarycoord, localNormal;
|
|
353
|
+
float localDist, localSide;
|
|
354
|
+
for ( uint i = offset, l = offset + count; i < l; i ++ ) {
|
|
355
|
+
|
|
356
|
+
uvec3 indices = uTexelFetch1D( indexAttr, i ).xyz;
|
|
357
|
+
vec3 a = texelFetch1D( positionAttr, indices.x ).rgb;
|
|
358
|
+
vec3 b = texelFetch1D( positionAttr, indices.y ).rgb;
|
|
359
|
+
vec3 c = texelFetch1D( positionAttr, indices.z ).rgb;
|
|
360
|
+
|
|
361
|
+
if (
|
|
362
|
+
intersectsTriangle( rayOrigin, rayDirection, a, b, c, localBarycoord, localNormal, localDist, localSide )
|
|
363
|
+
&& localDist < minDistance
|
|
364
|
+
) {
|
|
365
|
+
|
|
366
|
+
found = true;
|
|
367
|
+
minDistance = localDist;
|
|
368
|
+
|
|
369
|
+
faceIndices = uvec4( indices.xyz, i );
|
|
370
|
+
faceNormal = localNormal;
|
|
371
|
+
|
|
372
|
+
side = localSide;
|
|
373
|
+
barycoord = localBarycoord;
|
|
374
|
+
dist = localDist;
|
|
375
|
+
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return found;
|
|
381
|
+
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
bool intersectsBVHNodeBounds( vec3 rayOrigin, vec3 rayDirection, sampler2D bvhBounds, uint currNodeIndex, out float dist ) {
|
|
385
|
+
|
|
386
|
+
uint cni2 = currNodeIndex * 2u;
|
|
387
|
+
vec3 boundsMin = texelFetch1D( bvhBounds, cni2 ).xyz;
|
|
388
|
+
vec3 boundsMax = texelFetch1D( bvhBounds, cni2 + 1u ).xyz;
|
|
389
|
+
return intersectsBounds( rayOrigin, rayDirection, boundsMin, boundsMax, dist );
|
|
390
|
+
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// use a macro to hide the fact that we need to expand the struct into separate fields
|
|
394
|
+
#define bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist ) _bvhIntersectFirstHit( bvh.position, bvh.index, bvh.bvhBounds, bvh.bvhContents, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist )
|
|
395
|
+
|
|
396
|
+
bool _bvhIntersectFirstHit(
|
|
397
|
+
// bvh info
|
|
398
|
+
sampler2D bvh_position, usampler2D bvh_index, sampler2D bvh_bvhBounds, usampler2D bvh_bvhContents,
|
|
399
|
+
|
|
400
|
+
// ray
|
|
401
|
+
vec3 rayOrigin, vec3 rayDirection,
|
|
402
|
+
|
|
403
|
+
// output variables split into separate variables due to output precision
|
|
404
|
+
inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord,
|
|
405
|
+
inout float side, inout float dist
|
|
406
|
+
) {
|
|
407
|
+
|
|
408
|
+
// stack needs to be twice as long as the deepest tree we expect because
|
|
409
|
+
// we push both the left and right child onto the stack every traversal
|
|
410
|
+
int pointer = 0;
|
|
411
|
+
uint stack[ BVH_STACK_DEPTH ];
|
|
412
|
+
stack[ 0 ] = 0u;
|
|
413
|
+
|
|
414
|
+
float triangleDistance = INFINITY;
|
|
415
|
+
bool found = false;
|
|
416
|
+
while ( pointer > - 1 && pointer < BVH_STACK_DEPTH ) {
|
|
417
|
+
|
|
418
|
+
uint currNodeIndex = stack[ pointer ];
|
|
419
|
+
pointer --;
|
|
420
|
+
|
|
421
|
+
// check if we intersect the current bounds
|
|
422
|
+
float boundsHitDistance;
|
|
423
|
+
if (
|
|
424
|
+
! intersectsBVHNodeBounds( rayOrigin, rayDirection, bvh_bvhBounds, currNodeIndex, boundsHitDistance )
|
|
425
|
+
|| boundsHitDistance > triangleDistance
|
|
426
|
+
) {
|
|
427
|
+
|
|
428
|
+
continue;
|
|
429
|
+
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
uvec2 boundsInfo = uTexelFetch1D( bvh_bvhContents, currNodeIndex ).xy;
|
|
433
|
+
bool isLeaf = bool( boundsInfo.x & 0xffff0000u );
|
|
434
|
+
|
|
435
|
+
if ( isLeaf ) {
|
|
436
|
+
|
|
437
|
+
uint count = boundsInfo.x & 0x0000ffffu;
|
|
438
|
+
uint offset = boundsInfo.y;
|
|
439
|
+
|
|
440
|
+
found = intersectTriangles(
|
|
441
|
+
bvh_position, bvh_index, offset, count,
|
|
442
|
+
rayOrigin, rayDirection, triangleDistance,
|
|
443
|
+
faceIndices, faceNormal, barycoord, side, dist
|
|
444
|
+
) || found;
|
|
445
|
+
|
|
446
|
+
} else {
|
|
447
|
+
|
|
448
|
+
uint leftIndex = currNodeIndex + 1u;
|
|
449
|
+
uint splitAxis = boundsInfo.x & 0x0000ffffu;
|
|
450
|
+
uint rightIndex = currNodeIndex + boundsInfo.y;
|
|
451
|
+
|
|
452
|
+
bool leftToRight = rayDirection[ splitAxis ] >= 0.0;
|
|
453
|
+
uint c1 = leftToRight ? leftIndex : rightIndex;
|
|
454
|
+
uint c2 = leftToRight ? rightIndex : leftIndex;
|
|
455
|
+
|
|
456
|
+
// set c2 in the stack so we traverse it later. We need to keep track of a pointer in
|
|
457
|
+
// the stack while we traverse. The second pointer added is the one that will be
|
|
458
|
+
// traversed first
|
|
459
|
+
pointer ++;
|
|
460
|
+
stack[ pointer ] = c2;
|
|
461
|
+
|
|
462
|
+
pointer ++;
|
|
463
|
+
stack[ pointer ] = c1;
|
|
464
|
+
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
return found;
|
|
470
|
+
|
|
471
|
+
}
|
|
472
|
+
`;var oi=`
|
|
473
|
+
struct BVH {
|
|
474
|
+
|
|
475
|
+
usampler2D index;
|
|
476
|
+
sampler2D position;
|
|
477
|
+
|
|
478
|
+
sampler2D bvhBounds;
|
|
479
|
+
usampler2D bvhContents;
|
|
480
|
+
|
|
481
|
+
};
|
|
482
|
+
`;export{Wn as a,xe as b,ye as c,ni as d,Je as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var d=Object.defineProperty;var e=(b,a)=>d(b,"name",{value:a,configurable:true});var f=(b,a)=>{for(var c in a)d(b,c,{get:a[c],enumerable:true});};export{e as a,f as b};
|