@fleox/agent3d 0.3.1 → 0.4.0

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.
Files changed (65) hide show
  1. package/README.md +11 -11
  2. package/changelog.json +10 -0
  3. package/dist/agent/agent3d.mjs +30 -12
  4. package/dist/agent/chunks/{export-bJwh2SqG.mjs → export-CEX5DFLo.mjs} +79 -3
  5. package/dist/agent/chunks/{package-fMbw9UGh.mjs → package-DjRnLzcU.mjs} +2 -2
  6. package/dist/agent/chunks/{tools-Cm4BqDkO.mjs → tools-CZyIc4zw.mjs} +13 -3
  7. package/dist/runtime/agent3d-photo.js +31 -0
  8. package/dist/runtime/agent3d-runtime.js +41 -41
  9. package/dist/runtime/agent3d-runtime.single.js +251 -246
  10. package/dist/runtime/chunks/assets-kC2Z1Xy_.js +1 -0
  11. package/dist/runtime/chunks/game-CbQaEB4q.js +20 -0
  12. package/dist/runtime/chunks/materials-jwhXlLYl.js +107 -0
  13. package/dist/runtime/chunks/model-CG5T_jcB.js +1 -0
  14. package/dist/runtime/chunks/num-CQNAlL82.js +1 -0
  15. package/dist/runtime/chunks/{photo-DNf14X7B.js → photo-w6dwHX7j.js} +25 -20
  16. package/dist/runtime/chunks/physicsHost-BU-2V-CZ.js +1 -0
  17. package/dist/runtime/chunks/{postfx-Cbf_vvOr.js → postfx-DnIeKXAh.js} +1 -1
  18. package/dist/runtime/chunks/postfx-ylpcQcVK.js +1 -0
  19. package/dist/runtime/chunks/svg-fYjsY-rV.js +1 -0
  20. package/dist/runtime/chunks/{text-rSo_2Luk.js → text-CySfj5sH.js} +1 -1
  21. package/dist/runtime/chunks/util-BEflQURG.js +1 -0
  22. package/dist/studio/assets/assets--ehPZf8R.js +1 -0
  23. package/dist/studio/assets/camera-C0sxfRxy.js +2 -0
  24. package/dist/studio/assets/{editor-NkBUKsDB.js → editor-DzyukvQl.js} +1 -1
  25. package/dist/studio/assets/game-DNpTN_Ga.js +19 -0
  26. package/dist/studio/assets/{generators-BjIs-kHx.js → generators-BuVeRXnC.js} +5 -5
  27. package/dist/studio/assets/index-C2nMYSoW.js +479 -0
  28. package/dist/studio/assets/model-DQgOrTs4.js +2 -0
  29. package/dist/studio/assets/num-CQNAlL82.js +1 -0
  30. package/dist/studio/assets/{params-DhsDKSDs.js → params-D-Ul6GSt.js} +1 -1
  31. package/dist/studio/assets/{photo-DAHd1yNF.js → photo-Dx2IBJ11.js} +25 -20
  32. package/dist/studio/assets/physicsHost-z9qn_mpg.js +1 -0
  33. package/dist/studio/assets/{postfx-BGu30OJK.js → postfx-B3jDEaEK.js} +13 -13
  34. package/dist/studio/assets/runtime-rd9RW3WH.js +572 -0
  35. package/dist/studio/assets/{shaders-Dt6FGXH_.js → shaders-bFhELLmD.js} +1 -1
  36. package/dist/studio/assets/svg-BkV9LeqP.js +2 -0
  37. package/dist/studio/assets/{text-B-HM422i.js → text-Dp8gdjSA.js} +1 -1
  38. package/dist/studio/index.html +1 -1
  39. package/package.json +2 -2
  40. package/plugin/.claude-plugin/plugin.json +1 -1
  41. package/plugin/skills/agent3d-assets/SKILL.md +26 -26
  42. package/plugin/skills/agent3d-create/SKILL.md +26 -26
  43. package/plugin/skills/agent3d-create/references/art-direction.md +3 -3
  44. package/plugin/skills/agent3d-create/references/recipes.md +6 -6
  45. package/plugin/skills/agent3d-edit/SKILL.md +22 -22
  46. package/plugin/skills/agent3d-edit/references/patch-ops.md +2 -2
  47. package/plugin/skills/agent3d-game/SKILL.md +7 -7
  48. package/plugin/skills/agent3d-publish/SKILL.md +24 -22
  49. package/plugin/skills/agent3d-publish/references/integrations.md +1 -1
  50. package/dist/runtime/chunks/assets-qnxDnVkj.js +0 -1
  51. package/dist/runtime/chunks/game-BoEiyZrL.js +0 -20
  52. package/dist/runtime/chunks/materials-dC4vDNHh.js +0 -107
  53. package/dist/runtime/chunks/model-BCAl_NRl.js +0 -1
  54. package/dist/runtime/chunks/physicsHost-ChPgysMQ.js +0 -1
  55. package/dist/runtime/chunks/postfx-CFucYRev.js +0 -1
  56. package/dist/runtime/chunks/svg-CLUxY6Zy.js +0 -1
  57. package/dist/runtime/chunks/util-CyaW1fcW.js +0 -1
  58. package/dist/studio/assets/assets-BW5lQkYR.js +0 -1
  59. package/dist/studio/assets/camera-BgzPVnn-.js +0 -2
  60. package/dist/studio/assets/game-DARpu0ah.js +0 -19
  61. package/dist/studio/assets/index-L-N-e2KM.js +0 -479
  62. package/dist/studio/assets/model-CqI8j03Z.js +0 -2
  63. package/dist/studio/assets/physicsHost-tEUto2-_.js +0 -1
  64. package/dist/studio/assets/runtime-C_qkIpAK.js +0 -572
  65. package/dist/studio/assets/svg-ZZt5MdNf.js +0 -2
@@ -0,0 +1 @@
1
+ import{t as e}from"./num-CQNAlL82.js";import{F as t,H as n,Lt as r,M as i,Nn as a,Ut as o,at as s,d as c,m as l,nt as u,rt as d,vt as f,wn as p}from"./three.module-DnaBiDAJ.js";var m=class e{constructor(e){e===void 0&&(e=[0,0,0,0,0,0,0,0,0]),this.elements=e}identity(){let e=this.elements;e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1}setZero(){let e=this.elements;e[0]=0,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=0,e[6]=0,e[7]=0,e[8]=0}setTrace(e){let t=this.elements;t[0]=e.x,t[4]=e.y,t[8]=e.z}getTrace(e){e===void 0&&(e=new g);let t=this.elements;return e.x=t[0],e.y=t[4],e.z=t[8],e}vmult(e,t){t===void 0&&(t=new g);let n=this.elements,r=e.x,i=e.y,a=e.z;return t.x=n[0]*r+n[1]*i+n[2]*a,t.y=n[3]*r+n[4]*i+n[5]*a,t.z=n[6]*r+n[7]*i+n[8]*a,t}smult(e){for(let t=0;t<this.elements.length;t++)this.elements[t]*=e}mmult(t,n){n===void 0&&(n=new e);let r=this.elements,i=t.elements,a=n.elements,o=r[0],s=r[1],c=r[2],l=r[3],u=r[4],d=r[5],f=r[6],p=r[7],m=r[8],h=i[0],g=i[1],_=i[2],v=i[3],y=i[4],b=i[5],x=i[6],S=i[7],C=i[8];return a[0]=o*h+s*v+c*x,a[1]=o*g+s*y+c*S,a[2]=o*_+s*b+c*C,a[3]=l*h+u*v+d*x,a[4]=l*g+u*y+d*S,a[5]=l*_+u*b+d*C,a[6]=f*h+p*v+m*x,a[7]=f*g+p*y+m*S,a[8]=f*_+p*b+m*C,n}scale(t,n){n===void 0&&(n=new e);let r=this.elements,i=n.elements;for(let e=0;e!==3;e++)i[3*e+0]=t.x*r[3*e+0],i[3*e+1]=t.y*r[3*e+1],i[3*e+2]=t.z*r[3*e+2];return n}solve(e,t){t===void 0&&(t=new g);let n=[],r,i;for(r=0;r<12;r++)n.push(0);for(r=0;r<3;r++)for(i=0;i<3;i++)n[r+4*i]=this.elements[r+3*i];n[3]=e.x,n[7]=e.y,n[11]=e.z;let a=3,o=a,s,c;do{if(r=o-a,n[r+4*r]===0){for(i=r+1;i<o;i++)if(n[r+4*i]!==0){s=4;do c=4-s,n[c+4*r]+=n[c+4*i];while(--s);break}}if(n[r+4*r]!==0)for(i=r+1;i<o;i++){let e=n[r+4*i]/n[r+4*r];s=4;do c=4-s,n[c+4*i]=c<=r?0:n[c+4*i]-n[c+4*r]*e;while(--s)}}while(--a);if(t.z=n[11]/n[10],t.y=(n[7]-n[6]*t.z)/n[5],t.x=(n[3]-n[2]*t.z-n[1]*t.y)/n[0],isNaN(t.x)||isNaN(t.y)||isNaN(t.z)||t.x===1/0||t.y===1/0||t.z===1/0)throw`Could not solve equation! Got x=[${t.toString()}], b=[${e.toString()}], A=[${this.toString()}]`;return t}e(e,t,n){if(n===void 0)return this.elements[t+3*e];this.elements[t+3*e]=n}copy(e){for(let t=0;t<e.elements.length;t++)this.elements[t]=e.elements[t];return this}toString(){let e=``;for(let t=0;t<9;t++)e+=this.elements[t]+`,`;return e}reverse(t){t===void 0&&(t=new e);let n=h,r,i;for(r=0;r<3;r++)for(i=0;i<3;i++)n[r+6*i]=this.elements[r+3*i];n[3]=1,n[9]=0,n[15]=0,n[4]=0,n[10]=1,n[16]=0,n[5]=0,n[11]=0,n[17]=1;let a=3,o=a,s,c;do{if(r=o-a,n[r+6*r]===0){for(i=r+1;i<o;i++)if(n[r+6*i]!==0){s=6;do c=6-s,n[c+6*r]+=n[c+6*i];while(--s);break}}if(n[r+6*r]!==0)for(i=r+1;i<o;i++){let e=n[r+6*i]/n[r+6*r];s=6;do c=6-s,n[c+6*i]=c<=r?0:n[c+6*i]-n[c+6*r]*e;while(--s)}}while(--a);r=2;do{i=r-1;do{let e=n[r+6*i]/n[r+6*r];s=6;do c=6-s,n[c+6*i]=n[c+6*i]-n[c+6*r]*e;while(--s)}while(i--)}while(--r);r=2;do{let e=1/n[r+6*r];s=6;do c=6-s,n[c+6*r]=n[c+6*r]*e;while(--s)}while(r--);r=2;do{i=2;do{if(c=n[3+i+6*r],isNaN(c)||c===1/0)throw`Could not reverse! A=[${this.toString()}]`;t.e(r,i,c)}while(i--)}while(r--);return t}setRotationFromQuaternion(e){let t=e.x,n=e.y,r=e.z,i=e.w,a=t+t,o=n+n,s=r+r,c=t*a,l=t*o,u=t*s,d=n*o,f=n*s,p=r*s,m=i*a,h=i*o,g=i*s,_=this.elements;return _[0]=1-(d+p),_[1]=l-g,_[2]=u+h,_[3]=l+g,_[4]=1-(c+p),_[5]=f-m,_[6]=u-h,_[7]=f+m,_[8]=1-(c+d),this}transpose(t){t===void 0&&(t=new e);let n=this.elements,r=t.elements,i;return r[0]=n[0],r[4]=n[4],r[8]=n[8],i=n[1],r[1]=n[3],r[3]=i,i=n[2],r[2]=n[6],r[6]=i,i=n[5],r[5]=n[7],r[7]=i,t}},h=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],g=class e{constructor(e,t,n){e===void 0&&(e=0),t===void 0&&(t=0),n===void 0&&(n=0),this.x=e,this.y=t,this.z=n}cross(t,n){n===void 0&&(n=new e);let r=t.x,i=t.y,a=t.z,o=this.x,s=this.y,c=this.z;return n.x=s*a-c*i,n.y=c*r-o*a,n.z=o*i-s*r,n}set(e,t,n){return this.x=e,this.y=t,this.z=n,this}setZero(){this.x=this.y=this.z=0}vadd(t,n){if(n)n.x=t.x+this.x,n.y=t.y+this.y,n.z=t.z+this.z;else return new e(this.x+t.x,this.y+t.y,this.z+t.z)}vsub(t,n){if(n)n.x=this.x-t.x,n.y=this.y-t.y,n.z=this.z-t.z;else return new e(this.x-t.x,this.y-t.y,this.z-t.z)}crossmat(){return new m([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])}normalize(){let e=this.x,t=this.y,n=this.z,r=Math.sqrt(e*e+t*t+n*n);if(r>0){let e=1/r;this.x*=e,this.y*=e,this.z*=e}else this.x=0,this.y=0,this.z=0;return r}unit(t){t===void 0&&(t=new e);let n=this.x,r=this.y,i=this.z,a=Math.sqrt(n*n+r*r+i*i);return a>0?(a=1/a,t.x=n*a,t.y=r*a,t.z=i*a):(t.x=1,t.y=0,t.z=0),t}length(){let e=this.x,t=this.y,n=this.z;return Math.sqrt(e*e+t*t+n*n)}lengthSquared(){return this.dot(this)}distanceTo(e){let t=this.x,n=this.y,r=this.z,i=e.x,a=e.y,o=e.z;return Math.sqrt((i-t)*(i-t)+(a-n)*(a-n)+(o-r)*(o-r))}distanceSquared(e){let t=this.x,n=this.y,r=this.z,i=e.x,a=e.y,o=e.z;return(i-t)*(i-t)+(a-n)*(a-n)+(o-r)*(o-r)}scale(t,n){n===void 0&&(n=new e);let r=this.x,i=this.y,a=this.z;return n.x=t*r,n.y=t*i,n.z=t*a,n}vmul(t,n){return n===void 0&&(n=new e),n.x=t.x*this.x,n.y=t.y*this.y,n.z=t.z*this.z,n}addScaledVector(t,n,r){return r===void 0&&(r=new e),r.x=this.x+t*n.x,r.y=this.y+t*n.y,r.z=this.z+t*n.z,r}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}isZero(){return this.x===0&&this.y===0&&this.z===0}negate(t){return t===void 0&&(t=new e),t.x=-this.x,t.y=-this.y,t.z=-this.z,t}tangents(e,t){let n=this.length();if(n>0){let r=_,i=1/n;r.set(this.x*i,this.y*i,this.z*i);let a=v;Math.abs(r.x)<.9?(a.set(1,0,0),r.cross(a,e)):(a.set(0,1,0),r.cross(a,e)),r.cross(e,t)}else e.set(1,0,0),t.set(0,1,0)}toString(){return`${this.x},${this.y},${this.z}`}toArray(){return[this.x,this.y,this.z]}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}lerp(e,t,n){let r=this.x,i=this.y,a=this.z;n.x=r+(e.x-r)*t,n.y=i+(e.y-i)*t,n.z=a+(e.z-a)*t}almostEquals(e,t){return t===void 0&&(t=1e-6),!(Math.abs(this.x-e.x)>t||Math.abs(this.y-e.y)>t||Math.abs(this.z-e.z)>t)}almostZero(e){return e===void 0&&(e=1e-6),!(Math.abs(this.x)>e||Math.abs(this.y)>e||Math.abs(this.z)>e)}isAntiparallelTo(e,t){return this.negate(y),y.almostEquals(e,t)}clone(){return new e(this.x,this.y,this.z)}};g.ZERO=new g(0,0,0),g.UNIT_X=new g(1,0,0),g.UNIT_Y=new g(0,1,0),g.UNIT_Z=new g(0,0,1);var _=new g,v=new g,y=new g,b=class e{constructor(e){e===void 0&&(e={}),this.lowerBound=new g,this.upperBound=new g,e.lowerBound&&this.lowerBound.copy(e.lowerBound),e.upperBound&&this.upperBound.copy(e.upperBound)}setFromPoints(e,t,n,r){let i=this.lowerBound,a=this.upperBound,o=n;i.copy(e[0]),o&&o.vmult(i,i),a.copy(i);for(let t=1;t<e.length;t++){let n=e[t];o&&(o.vmult(n,x),n=x),n.x>a.x&&(a.x=n.x),n.x<i.x&&(i.x=n.x),n.y>a.y&&(a.y=n.y),n.y<i.y&&(i.y=n.y),n.z>a.z&&(a.z=n.z),n.z<i.z&&(i.z=n.z)}return t&&(t.vadd(i,i),t.vadd(a,a)),r&&(i.x-=r,i.y-=r,i.z-=r,a.x+=r,a.y+=r,a.z+=r),this}copy(e){return this.lowerBound.copy(e.lowerBound),this.upperBound.copy(e.upperBound),this}clone(){return new e().copy(this)}extend(e){this.lowerBound.x=Math.min(this.lowerBound.x,e.lowerBound.x),this.upperBound.x=Math.max(this.upperBound.x,e.upperBound.x),this.lowerBound.y=Math.min(this.lowerBound.y,e.lowerBound.y),this.upperBound.y=Math.max(this.upperBound.y,e.upperBound.y),this.lowerBound.z=Math.min(this.lowerBound.z,e.lowerBound.z),this.upperBound.z=Math.max(this.upperBound.z,e.upperBound.z)}overlaps(e){let t=this.lowerBound,n=this.upperBound,r=e.lowerBound,i=e.upperBound,a=r.x<=n.x&&n.x<=i.x||t.x<=i.x&&i.x<=n.x,o=r.y<=n.y&&n.y<=i.y||t.y<=i.y&&i.y<=n.y,s=r.z<=n.z&&n.z<=i.z||t.z<=i.z&&i.z<=n.z;return a&&o&&s}volume(){let e=this.lowerBound,t=this.upperBound;return(t.x-e.x)*(t.y-e.y)*(t.z-e.z)}contains(e){let t=this.lowerBound,n=this.upperBound,r=e.lowerBound,i=e.upperBound;return t.x<=r.x&&n.x>=i.x&&t.y<=r.y&&n.y>=i.y&&t.z<=r.z&&n.z>=i.z}getCorners(e,t,n,r,i,a,o,s){let c=this.lowerBound,l=this.upperBound;e.copy(c),t.set(l.x,c.y,c.z),n.set(l.x,l.y,c.z),r.set(c.x,l.y,l.z),i.set(l.x,c.y,l.z),a.set(c.x,l.y,c.z),o.set(c.x,c.y,l.z),s.copy(l)}toLocalFrame(e,t){let n=S,r=n[0],i=n[1],a=n[2],o=n[3],s=n[4],c=n[5],l=n[6],u=n[7];this.getCorners(r,i,a,o,s,c,l,u);for(let t=0;t!==8;t++){let r=n[t];e.pointToLocal(r,r)}return t.setFromPoints(n)}toWorldFrame(e,t){let n=S,r=n[0],i=n[1],a=n[2],o=n[3],s=n[4],c=n[5],l=n[6],u=n[7];this.getCorners(r,i,a,o,s,c,l,u);for(let t=0;t!==8;t++){let r=n[t];e.pointToWorld(r,r)}return t.setFromPoints(n)}overlapsRay(e){let{direction:t,from:n}=e,r=1/t.x,i=1/t.y,a=1/t.z,o=(this.lowerBound.x-n.x)*r,s=(this.upperBound.x-n.x)*r,c=(this.lowerBound.y-n.y)*i,l=(this.upperBound.y-n.y)*i,u=(this.lowerBound.z-n.z)*a,d=(this.upperBound.z-n.z)*a,f=Math.max(Math.max(Math.min(o,s),Math.min(c,l)),Math.min(u,d)),p=Math.min(Math.min(Math.max(o,s),Math.max(c,l)),Math.max(u,d));return!(p<0||f>p)}},x=new g,S=[new g,new g,new g,new g,new g,new g,new g,new g],C=class{constructor(){this.matrix=[]}get(e,t){let{index:n}=e,{index:r}=t;if(r>n){let e=r;r=n,n=e}return this.matrix[(n*(n+1)>>1)+r-1]}set(e,t,n){let{index:r}=e,{index:i}=t;if(i>r){let e=i;i=r,r=e}this.matrix[(r*(r+1)>>1)+i-1]=+!!n}reset(){for(let e=0,t=this.matrix.length;e!==t;e++)this.matrix[e]=0}setNumObjects(e){this.matrix.length=e*(e-1)>>1}},w=class{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});let n=this._listeners;return n[e]===void 0&&(n[e]=[]),n[e].includes(t)||n[e].push(t),this}hasEventListener(e,t){if(this._listeners===void 0)return!1;let n=this._listeners;return!!(n[e]!==void 0&&n[e].includes(t))}hasAnyEventListener(e){return this._listeners!==void 0&&this._listeners[e]!==void 0}removeEventListener(e,t){if(this._listeners===void 0)return this;let n=this._listeners;if(n[e]===void 0)return this;let r=n[e].indexOf(t);return r!==-1&&n[e].splice(r,1),this}dispatchEvent(e){if(this._listeners===void 0)return this;let t=this._listeners[e.type];if(t!==void 0){e.target=this;for(let n=0,r=t.length;n<r;n++)t[n].call(this,e)}return this}},T=class e{constructor(e,t,n,r){e===void 0&&(e=0),t===void 0&&(t=0),n===void 0&&(n=0),r===void 0&&(r=1),this.x=e,this.y=t,this.z=n,this.w=r}set(e,t,n,r){return this.x=e,this.y=t,this.z=n,this.w=r,this}toString(){return`${this.x},${this.y},${this.z},${this.w}`}toArray(){return[this.x,this.y,this.z,this.w]}setFromAxisAngle(e,t){let n=Math.sin(t*.5);return this.x=e.x*n,this.y=e.y*n,this.z=e.z*n,this.w=Math.cos(t*.5),this}toAxisAngle(e){e===void 0&&(e=new g),this.normalize();let t=2*Math.acos(this.w),n=Math.sqrt(1-this.w*this.w);return n<.001?(e.x=this.x,e.y=this.y,e.z=this.z):(e.x=this.x/n,e.y=this.y/n,e.z=this.z/n),[e,t]}setFromVectors(e,t){if(e.isAntiparallelTo(t)){let t=E,n=D;e.tangents(t,n),this.setFromAxisAngle(t,Math.PI)}else{let n=e.cross(t);this.x=n.x,this.y=n.y,this.z=n.z,this.w=Math.sqrt(e.length()**2*t.length()**2)+e.dot(t),this.normalize()}return this}mult(t,n){n===void 0&&(n=new e);let r=this.x,i=this.y,a=this.z,o=this.w,s=t.x,c=t.y,l=t.z,u=t.w;return n.x=r*u+o*s+i*l-a*c,n.y=i*u+o*c+a*s-r*l,n.z=a*u+o*l+r*c-i*s,n.w=o*u-r*s-i*c-a*l,n}inverse(t){t===void 0&&(t=new e);let n=this.x,r=this.y,i=this.z,a=this.w;this.conjugate(t);let o=1/(n*n+r*r+i*i+a*a);return t.x*=o,t.y*=o,t.z*=o,t.w*=o,t}conjugate(t){return t===void 0&&(t=new e),t.x=-this.x,t.y=-this.y,t.z=-this.z,t.w=this.w,t}normalize(){let e=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);return e===0?(this.x=0,this.y=0,this.z=0,this.w=0):(e=1/e,this.x*=e,this.y*=e,this.z*=e,this.w*=e),this}normalizeFast(){let e=(3-(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w))/2;return e===0?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x*=e,this.y*=e,this.z*=e,this.w*=e),this}vmult(e,t){t===void 0&&(t=new g);let n=e.x,r=e.y,i=e.z,a=this.x,o=this.y,s=this.z,c=this.w,l=c*n+o*i-s*r,u=c*r+s*n-a*i,d=c*i+a*r-o*n,f=-a*n-o*r-s*i;return t.x=l*c+f*-a+u*-s-d*-o,t.y=u*c+f*-o+d*-a-l*-s,t.z=d*c+f*-s+l*-o-u*-a,t}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}toEuler(e,t){t===void 0&&(t=`YZX`);let n,r,i,a=this.x,o=this.y,s=this.z,c=this.w;switch(t){case`YZX`:let e=a*o+s*c;if(e>.499&&(n=2*Math.atan2(a,c),r=Math.PI/2,i=0),e<-.499&&(n=-2*Math.atan2(a,c),r=-Math.PI/2,i=0),n===void 0){let t=a*a,l=o*o,u=s*s;n=Math.atan2(2*o*c-2*a*s,1-2*l-2*u),r=Math.asin(2*e),i=Math.atan2(2*a*c-2*o*s,1-2*t-2*u)}break;default:throw Error(`Euler order ${t} not supported yet.`)}e.y=n,e.z=r,e.x=i}setFromEuler(e,t,n,r){r===void 0&&(r=`XYZ`);let i=Math.cos(e/2),a=Math.cos(t/2),o=Math.cos(n/2),s=Math.sin(e/2),c=Math.sin(t/2),l=Math.sin(n/2);return r===`XYZ`?(this.x=s*a*o+i*c*l,this.y=i*c*o-s*a*l,this.z=i*a*l+s*c*o,this.w=i*a*o-s*c*l):r===`YXZ`?(this.x=s*a*o+i*c*l,this.y=i*c*o-s*a*l,this.z=i*a*l-s*c*o,this.w=i*a*o+s*c*l):r===`ZXY`?(this.x=s*a*o-i*c*l,this.y=i*c*o+s*a*l,this.z=i*a*l+s*c*o,this.w=i*a*o-s*c*l):r===`ZYX`?(this.x=s*a*o-i*c*l,this.y=i*c*o+s*a*l,this.z=i*a*l-s*c*o,this.w=i*a*o+s*c*l):r===`YZX`?(this.x=s*a*o+i*c*l,this.y=i*c*o+s*a*l,this.z=i*a*l-s*c*o,this.w=i*a*o-s*c*l):r===`XZY`&&(this.x=s*a*o-i*c*l,this.y=i*c*o-s*a*l,this.z=i*a*l+s*c*o,this.w=i*a*o+s*c*l),this}clone(){return new e(this.x,this.y,this.z,this.w)}slerp(t,n,r){r===void 0&&(r=new e);let i=this.x,a=this.y,o=this.z,s=this.w,c=t.x,l=t.y,u=t.z,d=t.w,f,p,m,h,g;return p=i*c+a*l+o*u+s*d,p<0&&(p=-p,c=-c,l=-l,u=-u,d=-d),1-p>1e-6?(f=Math.acos(p),m=Math.sin(f),h=Math.sin((1-n)*f)/m,g=Math.sin(n*f)/m):(h=1-n,g=n),r.x=h*i+g*c,r.y=h*a+g*l,r.z=h*o+g*u,r.w=h*s+g*d,r}integrate(t,n,r,i){i===void 0&&(i=new e);let a=t.x*r.x,o=t.y*r.y,s=t.z*r.z,c=this.x,l=this.y,u=this.z,d=this.w,f=n*.5;return i.x+=f*(a*d+o*u-s*l),i.y+=f*(o*d+s*c-a*u),i.z+=f*(s*d+a*l-o*c),i.w+=f*(-a*c-o*l-s*u),i}},E=new g,D=new g,O={SPHERE:1,PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16,HEIGHTFIELD:32,PARTICLE:64,CYLINDER:128,TRIMESH:256},k=class e{constructor(t){t===void 0&&(t={}),this.id=e.idCounter++,this.type=t.type||0,this.boundingSphereRadius=0,this.collisionResponse=!t.collisionResponse||t.collisionResponse,this.collisionFilterGroup=t.collisionFilterGroup===void 0?1:t.collisionFilterGroup,this.collisionFilterMask=t.collisionFilterMask===void 0?-1:t.collisionFilterMask,this.material=t.material?t.material:null,this.body=null}updateBoundingSphereRadius(){throw`computeBoundingSphereRadius() not implemented for shape type ${this.type}`}volume(){throw`volume() not implemented for shape type ${this.type}`}calculateLocalInertia(e,t){throw`calculateLocalInertia() not implemented for shape type ${this.type}`}calculateWorldAABB(e,t,n,r){throw`calculateWorldAABB() not implemented for shape type ${this.type}`}};k.idCounter=0,k.types=O;var A=class e{constructor(e){e===void 0&&(e={}),this.position=new g,this.quaternion=new T,e.position&&this.position.copy(e.position),e.quaternion&&this.quaternion.copy(e.quaternion)}pointToLocal(t,n){return e.pointToLocalFrame(this.position,this.quaternion,t,n)}pointToWorld(t,n){return e.pointToWorldFrame(this.position,this.quaternion,t,n)}vectorToWorldFrame(e,t){return t===void 0&&(t=new g),this.quaternion.vmult(e,t),t}static pointToLocalFrame(e,t,n,r){return r===void 0&&(r=new g),n.vsub(e,r),t.conjugate(ee),ee.vmult(r,r),r}static pointToWorldFrame(e,t,n,r){return r===void 0&&(r=new g),t.vmult(n,r),r.vadd(e,r),r}static vectorToWorldFrame(e,t,n){return n===void 0&&(n=new g),e.vmult(t,n),n}static vectorToLocalFrame(e,t,n,r){return r===void 0&&(r=new g),t.w*=-1,t.vmult(n,r),t.w*=-1,r}},ee=new T,j=class e extends k{constructor(e){e===void 0&&(e={});let{vertices:t=[],faces:n=[],normals:r=[],axes:i,boundingSphereRadius:a}=e;super({type:k.types.CONVEXPOLYHEDRON}),this.vertices=t,this.faces=n,this.faceNormals=r,this.faceNormals.length===0&&this.computeNormals(),a?this.boundingSphereRadius=a:this.updateBoundingSphereRadius(),this.worldVertices=[],this.worldVerticesNeedsUpdate=!0,this.worldFaceNormals=[],this.worldFaceNormalsNeedsUpdate=!0,this.uniqueAxes=i?i.slice():null,this.uniqueEdges=[],this.computeEdges()}computeEdges(){let e=this.faces,t=this.vertices,n=this.uniqueEdges;n.length=0;let r=new g;for(let i=0;i!==e.length;i++){let a=e[i],o=a.length;for(let e=0;e!==o;e++){let i=(e+1)%o;t[a[e]].vsub(t[a[i]],r),r.normalize();let s=!1;for(let e=0;e!==n.length;e++)if(n[e].almostEquals(r)||n[e].almostEquals(r)){s=!0;break}s||n.push(r.clone())}}}computeNormals(){this.faceNormals.length=this.faces.length;for(let e=0;e<this.faces.length;e++){for(let t=0;t<this.faces[e].length;t++)if(!this.vertices[this.faces[e][t]])throw Error(`Vertex ${this.faces[e][t]} not found!`);let t=this.faceNormals[e]||new g;this.getFaceNormal(e,t),t.negate(t),this.faceNormals[e]=t;let n=this.vertices[this.faces[e][0]];if(t.dot(n)<0){console.error(`.faceNormals[${e}] = Vec3(${t.toString()}) looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.`);for(let t=0;t<this.faces[e].length;t++)console.warn(`.vertices[${this.faces[e][t]}] = Vec3(${this.vertices[this.faces[e][t]].toString()})`)}}}getFaceNormal(t,n){let r=this.faces[t],i=this.vertices[r[0]],a=this.vertices[r[1]],o=this.vertices[r[2]];e.computeNormal(i,a,o,n)}static computeNormal(e,t,n,r){let i=new g,a=new g;t.vsub(e,a),n.vsub(t,i),i.cross(a,r),r.isZero()||r.normalize()}clipAgainstHull(e,t,n,r,i,a,o,s,c){let l=new g,u=-1,d=-Number.MAX_VALUE;for(let e=0;e<n.faces.length;e++){l.copy(n.faceNormals[e]),i.vmult(l,l);let t=l.dot(a);t>d&&(d=t,u=e)}let f=[];for(let e=0;e<n.faces[u].length;e++){let t=n.vertices[n.faces[u][e]],a=new g;a.copy(t),i.vmult(a,a),r.vadd(a,a),f.push(a)}u>=0&&this.clipFaceAgainstHull(a,e,t,f,o,s,c)}findSeparatingAxis(e,t,n,r,i,a,o,s){let c=new g,l=new g,u=new g,d=new g,f=new g,p=new g,m=Number.MAX_VALUE,h=this;if(h.uniqueAxes)for(let o=0;o!==h.uniqueAxes.length;o++){n.vmult(h.uniqueAxes[o],c);let s=h.testSepAxis(c,e,t,n,r,i);if(s===!1)return!1;s<m&&(m=s,a.copy(c))}else{let s=o?o.length:h.faces.length;for(let l=0;l<s;l++){let s=o?o[l]:l;c.copy(h.faceNormals[s]),n.vmult(c,c);let u=h.testSepAxis(c,e,t,n,r,i);if(u===!1)return!1;u<m&&(m=u,a.copy(c))}}if(e.uniqueAxes)for(let o=0;o!==e.uniqueAxes.length;o++){i.vmult(e.uniqueAxes[o],l);let s=h.testSepAxis(l,e,t,n,r,i);if(s===!1)return!1;s<m&&(m=s,a.copy(l))}else{let o=s?s.length:e.faces.length;for(let c=0;c<o;c++){let o=s?s[c]:c;l.copy(e.faceNormals[o]),i.vmult(l,l);let u=h.testSepAxis(l,e,t,n,r,i);if(u===!1)return!1;u<m&&(m=u,a.copy(l))}}for(let o=0;o!==h.uniqueEdges.length;o++){n.vmult(h.uniqueEdges[o],d);for(let o=0;o!==e.uniqueEdges.length;o++)if(i.vmult(e.uniqueEdges[o],f),d.cross(f,p),!p.almostZero()){p.normalize();let o=h.testSepAxis(p,e,t,n,r,i);if(o===!1)return!1;o<m&&(m=o,a.copy(p))}}return r.vsub(t,u),u.dot(a)>0&&a.negate(a),!0}testSepAxis(t,n,r,i,a,o){let s=this;e.project(s,t,r,i,te),e.project(n,t,a,o,ne);let c=te[0],l=te[1],u=ne[0],d=ne[1];if(c<d||u<l)return!1;let f=c-d,p=u-l;return f<p?f:p}calculateLocalInertia(e,t){let n=new g,r=new g;this.computeLocalAABB(r,n);let i=n.x-r.x,a=n.y-r.y,o=n.z-r.z;t.x=1/12*e*(2*a*2*a+2*o*2*o),t.y=1/12*e*(2*i*2*i+2*o*2*o),t.z=1/12*e*(2*a*2*a+2*i*2*i)}getPlaneConstantOfFace(e){let t=this.faces[e],n=this.faceNormals[e],r=this.vertices[t[0]];return-n.dot(r)}clipFaceAgainstHull(e,t,n,r,i,a,o){let s=new g,c=new g,l=new g,u=new g,d=new g,f=new g,p=new g,m=new g,h=this,_=[],v=r,y=_,b=-1,x=Number.MAX_VALUE;for(let t=0;t<h.faces.length;t++){s.copy(h.faceNormals[t]),n.vmult(s,s);let r=s.dot(e);r<x&&(x=r,b=t)}if(b<0)return;let S=h.faces[b];S.connectedFaces=[];for(let e=0;e<h.faces.length;e++)for(let t=0;t<h.faces[e].length;t++)S.indexOf(h.faces[e][t])!==-1&&e!==b&&S.connectedFaces.indexOf(e)===-1&&S.connectedFaces.push(e);let C=S.length;for(let e=0;e<C;e++){let r=h.vertices[S[e]],i=h.vertices[S[(e+1)%C]];r.vsub(i,c),l.copy(c),n.vmult(l,l),t.vadd(l,l),u.copy(this.faceNormals[b]),n.vmult(u,u),t.vadd(u,u),l.cross(u,d),d.negate(d),f.copy(r),n.vmult(f,f),t.vadd(f,f);let a=S.connectedFaces[e];p.copy(this.faceNormals[a]);let o=this.getPlaneConstantOfFace(a);m.copy(p),n.vmult(m,m);let s=o-m.dot(t);for(this.clipFaceAgainstPlane(v,y,m,s);v.length;)v.shift();for(;y.length;)v.push(y.shift())}p.copy(this.faceNormals[b]);let w=this.getPlaneConstantOfFace(b);m.copy(p),n.vmult(m,m);let T=w-m.dot(t);for(let e=0;e<v.length;e++){let t=m.dot(v[e])+T;if(t<=i&&(console.log(`clamped: depth=${t} to minDist=${i}`),t=i),t<=a){let n=v[e];if(t<=1e-6){let e={point:n,normal:m,depth:t};o.push(e)}}}}clipFaceAgainstPlane(e,t,n,r){let i,a,o=e.length;if(o<2)return t;let s=e[e.length-1],c=e[0];i=n.dot(s)+r;for(let l=0;l<o;l++){if(c=e[l],a=n.dot(c)+r,i<0){if(a<0){let e=new g;e.copy(c),t.push(e)}else{let e=new g;s.lerp(c,i/(i-a),e),t.push(e)}}else if(a<0){let e=new g;s.lerp(c,i/(i-a),e),t.push(e),t.push(c)}s=c,i=a}return t}computeWorldVertices(e,t){for(;this.worldVertices.length<this.vertices.length;)this.worldVertices.push(new g);let n=this.vertices,r=this.worldVertices;for(let i=0;i!==this.vertices.length;i++)t.vmult(n[i],r[i]),e.vadd(r[i],r[i]);this.worldVerticesNeedsUpdate=!1}computeLocalAABB(e,t){let n=this.vertices;e.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),t.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(let r=0;r<this.vertices.length;r++){let i=n[r];i.x<e.x?e.x=i.x:i.x>t.x&&(t.x=i.x),i.y<e.y?e.y=i.y:i.y>t.y&&(t.y=i.y),i.z<e.z?e.z=i.z:i.z>t.z&&(t.z=i.z)}}computeWorldFaceNormals(e){let t=this.faceNormals.length;for(;this.worldFaceNormals.length<t;)this.worldFaceNormals.push(new g);let n=this.faceNormals,r=this.worldFaceNormals;for(let i=0;i!==t;i++)e.vmult(n[i],r[i]);this.worldFaceNormalsNeedsUpdate=!1}updateBoundingSphereRadius(){let e=0,t=this.vertices;for(let n=0;n!==t.length;n++){let r=t[n].lengthSquared();r>e&&(e=r)}this.boundingSphereRadius=Math.sqrt(e)}calculateWorldAABB(e,t,n,r){let i=this.vertices,a,o,s,c,l,u,d=new g;for(let n=0;n<i.length;n++){d.copy(i[n]),t.vmult(d,d),e.vadd(d,d);let r=d;(a===void 0||r.x<a)&&(a=r.x),(c===void 0||r.x>c)&&(c=r.x),(o===void 0||r.y<o)&&(o=r.y),(l===void 0||r.y>l)&&(l=r.y),(s===void 0||r.z<s)&&(s=r.z),(u===void 0||r.z>u)&&(u=r.z)}n.set(a,o,s),r.set(c,l,u)}volume(){return 4*Math.PI*this.boundingSphereRadius/3}getAveragePointLocal(e){e===void 0&&(e=new g);let t=this.vertices;for(let n=0;n<t.length;n++)e.vadd(t[n],e);return e.scale(1/t.length,e),e}transformAllPoints(e,t){let n=this.vertices.length,r=this.vertices;if(t){for(let e=0;e<n;e++){let n=r[e];t.vmult(n,n)}for(let e=0;e<this.faceNormals.length;e++){let n=this.faceNormals[e];t.vmult(n,n)}}if(e)for(let t=0;t<n;t++){let n=r[t];n.vadd(e,n)}}pointIsInside(e){let t=this.vertices,n=this.faces,r=this.faceNormals,i=new g;this.getAveragePointLocal(i);for(let a=0;a<this.faces.length;a++){let o=r[a],s=t[n[a][0]],c=new g;e.vsub(s,c);let l=o.dot(c),u=new g;i.vsub(s,u);let d=o.dot(u);if(l<0&&d>0||l>0&&d<0)return!1}return-1}static project(e,t,n,r,i){let a=e.vertices.length,o=re,s=0,c=0,l=ie,u=e.vertices;l.setZero(),A.vectorToLocalFrame(n,r,t,o),A.pointToLocalFrame(n,r,l,l);let d=l.dot(o);c=s=u[0].dot(o);for(let e=1;e<a;e++){let t=u[e].dot(o);t>s&&(s=t),t<c&&(c=t)}if(c-=d,s-=d,c>s){let e=c;c=s,s=e}i[0]=s,i[1]=c}},te=[],ne=[];new g;var re=new g,ie=new g,ae=class e extends k{constructor(e){super({type:k.types.BOX}),this.halfExtents=e,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}updateConvexPolyhedronRepresentation(){let e=this.halfExtents.x,t=this.halfExtents.y,n=this.halfExtents.z,r=g,i=new j({vertices:[new r(-e,-t,-n),new r(e,-t,-n),new r(e,t,-n),new r(-e,t,-n),new r(-e,-t,n),new r(e,-t,n),new r(e,t,n),new r(-e,t,n)],faces:[[3,2,1,0],[4,5,6,7],[5,4,0,1],[2,3,7,6],[0,4,7,3],[1,2,6,5]],axes:[new r(0,0,1),new r(0,1,0),new r(1,0,0)]});this.convexPolyhedronRepresentation=i,i.material=this.material}calculateLocalInertia(t,n){return n===void 0&&(n=new g),e.calculateInertia(this.halfExtents,t,n),n}static calculateInertia(e,t,n){let r=e;n.x=1/12*t*(2*r.y*2*r.y+2*r.z*2*r.z),n.y=1/12*t*(2*r.x*2*r.x+2*r.z*2*r.z),n.z=1/12*t*(2*r.y*2*r.y+2*r.x*2*r.x)}getSideNormals(e,t){let n=e,r=this.halfExtents;if(n[0].set(r.x,0,0),n[1].set(0,r.y,0),n[2].set(0,0,r.z),n[3].set(-r.x,0,0),n[4].set(0,-r.y,0),n[5].set(0,0,-r.z),t!==void 0)for(let e=0;e!==n.length;e++)t.vmult(n[e],n[e]);return n}volume(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z}updateBoundingSphereRadius(){this.boundingSphereRadius=this.halfExtents.length()}forEachWorldCorner(e,t,n){let r=this.halfExtents,i=[[r.x,r.y,r.z],[-r.x,r.y,r.z],[-r.x,-r.y,r.z],[-r.x,-r.y,-r.z],[r.x,-r.y,-r.z],[r.x,r.y,-r.z],[-r.x,r.y,-r.z],[r.x,-r.y,r.z]];for(let r=0;r<i.length;r++)M.set(i[r][0],i[r][1],i[r][2]),t.vmult(M,M),e.vadd(M,M),n(M.x,M.y,M.z)}calculateWorldAABB(e,t,n,r){let i=this.halfExtents;N[0].set(i.x,i.y,i.z),N[1].set(-i.x,i.y,i.z),N[2].set(-i.x,-i.y,i.z),N[3].set(-i.x,-i.y,-i.z),N[4].set(i.x,-i.y,-i.z),N[5].set(i.x,i.y,-i.z),N[6].set(-i.x,i.y,-i.z),N[7].set(i.x,-i.y,i.z);let a=N[0];t.vmult(a,a),e.vadd(a,a),r.copy(a),n.copy(a);for(let i=1;i<8;i++){let a=N[i];t.vmult(a,a),e.vadd(a,a);let o=a.x,s=a.y,c=a.z;o>r.x&&(r.x=o),s>r.y&&(r.y=s),c>r.z&&(r.z=c),o<n.x&&(n.x=o),s<n.y&&(n.y=s),c<n.z&&(n.z=c)}}},M=new g,N=[new g,new g,new g,new g,new g,new g,new g,new g],oe={DYNAMIC:1,STATIC:2,KINEMATIC:4},se={AWAKE:0,SLEEPY:1,SLEEPING:2},P=class e extends w{constructor(t){t===void 0&&(t={}),super(),this.id=e.idCounter++,this.index=-1,this.world=null,this.vlambda=new g,this.collisionFilterGroup=typeof t.collisionFilterGroup==`number`?t.collisionFilterGroup:1,this.collisionFilterMask=typeof t.collisionFilterMask==`number`?t.collisionFilterMask:-1,this.collisionResponse=typeof t.collisionResponse!=`boolean`||t.collisionResponse,this.position=new g,this.previousPosition=new g,this.interpolatedPosition=new g,this.initPosition=new g,t.position&&(this.position.copy(t.position),this.previousPosition.copy(t.position),this.interpolatedPosition.copy(t.position),this.initPosition.copy(t.position)),this.velocity=new g,t.velocity&&this.velocity.copy(t.velocity),this.initVelocity=new g,this.force=new g;let n=typeof t.mass==`number`?t.mass:0;this.mass=n,this.invMass=n>0?1/n:0,this.material=t.material||null,this.linearDamping=typeof t.linearDamping==`number`?t.linearDamping:.01,this.type=n<=0?e.STATIC:e.DYNAMIC,typeof t.type==typeof e.STATIC&&(this.type=t.type),this.allowSleep=t.allowSleep===void 0||t.allowSleep,this.sleepState=e.AWAKE,this.sleepSpeedLimit=t.sleepSpeedLimit===void 0?.1:t.sleepSpeedLimit,this.sleepTimeLimit=t.sleepTimeLimit===void 0?1:t.sleepTimeLimit,this.timeLastSleepy=0,this.wakeUpAfterNarrowphase=!1,this.torque=new g,this.quaternion=new T,this.initQuaternion=new T,this.previousQuaternion=new T,this.interpolatedQuaternion=new T,t.quaternion&&(this.quaternion.copy(t.quaternion),this.initQuaternion.copy(t.quaternion),this.previousQuaternion.copy(t.quaternion),this.interpolatedQuaternion.copy(t.quaternion)),this.angularVelocity=new g,t.angularVelocity&&this.angularVelocity.copy(t.angularVelocity),this.initAngularVelocity=new g,this.shapes=[],this.shapeOffsets=[],this.shapeOrientations=[],this.inertia=new g,this.invInertia=new g,this.invInertiaWorld=new m,this.invMassSolve=0,this.invInertiaSolve=new g,this.invInertiaWorldSolve=new m,this.fixedRotation=t.fixedRotation!==void 0&&t.fixedRotation,this.angularDamping=t.angularDamping===void 0?.01:t.angularDamping,this.linearFactor=new g(1,1,1),t.linearFactor&&this.linearFactor.copy(t.linearFactor),this.angularFactor=new g(1,1,1),t.angularFactor&&this.angularFactor.copy(t.angularFactor),this.aabb=new b,this.aabbNeedsUpdate=!0,this.boundingRadius=0,this.wlambda=new g,this.isTrigger=!!t.isTrigger,t.shape&&this.addShape(t.shape),this.updateMassProperties()}wakeUp(){let t=this.sleepState;this.sleepState=e.AWAKE,this.wakeUpAfterNarrowphase=!1,t===e.SLEEPING&&this.dispatchEvent(e.wakeupEvent)}sleep(){this.sleepState=e.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0),this.wakeUpAfterNarrowphase=!1}sleepTick(t){if(this.allowSleep){let n=this.sleepState,r=this.velocity.lengthSquared()+this.angularVelocity.lengthSquared(),i=this.sleepSpeedLimit**2;n===e.AWAKE&&r<i?(this.sleepState=e.SLEEPY,this.timeLastSleepy=t,this.dispatchEvent(e.sleepyEvent)):n===e.SLEEPY&&r>i?this.wakeUp():n===e.SLEEPY&&t-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(e.sleepEvent))}}updateSolveMassProperties(){this.sleepState===e.SLEEPING||this.type===e.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))}pointToLocalFrame(e,t){return t===void 0&&(t=new g),e.vsub(this.position,t),this.quaternion.conjugate().vmult(t,t),t}vectorToLocalFrame(e,t){return t===void 0&&(t=new g),this.quaternion.conjugate().vmult(e,t),t}pointToWorldFrame(e,t){return t===void 0&&(t=new g),this.quaternion.vmult(e,t),t.vadd(this.position,t),t}vectorToWorldFrame(e,t){return t===void 0&&(t=new g),this.quaternion.vmult(e,t),t}addShape(e,t,n){let r=new g,i=new T;return t&&r.copy(t),n&&i.copy(n),this.shapes.push(e),this.shapeOffsets.push(r),this.shapeOrientations.push(i),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,e.body=this,this}removeShape(e){let t=this.shapes.indexOf(e);return t===-1?(console.warn(`Shape does not belong to the body`),this):(this.shapes.splice(t,1),this.shapeOffsets.splice(t,1),this.shapeOrientations.splice(t,1),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,e.body=null,this)}updateBoundingRadius(){let e=this.shapes,t=this.shapeOffsets,n=e.length,r=0;for(let i=0;i!==n;i++){let n=e[i];n.updateBoundingSphereRadius();let a=t[i].length(),o=n.boundingSphereRadius;a+o>r&&(r=a+o)}this.boundingRadius=r}updateAABB(){let e=this.shapes,t=this.shapeOffsets,n=this.shapeOrientations,r=e.length,i=ce,a=le,o=this.quaternion,s=this.aabb,c=ue;for(let l=0;l!==r;l++){let r=e[l];o.vmult(t[l],i),i.vadd(this.position,i),o.mult(n[l],a),r.calculateWorldAABB(i,a,c.lowerBound,c.upperBound),l===0?s.copy(c):s.extend(c)}this.aabbNeedsUpdate=!1}updateInertiaWorld(e){let t=this.invInertia;if(t.x!==t.y||t.y!==t.z||e){let e=de,n=fe;e.setRotationFromQuaternion(this.quaternion),e.transpose(n),e.scale(t,e),e.mmult(n,this.invInertiaWorld)}}applyForce(t,n){if(n===void 0&&(n=new g),this.type!==e.DYNAMIC)return;this.sleepState===e.SLEEPING&&this.wakeUp();let r=pe;n.cross(t,r),this.force.vadd(t,this.force),this.torque.vadd(r,this.torque)}applyLocalForce(t,n){if(n===void 0&&(n=new g),this.type!==e.DYNAMIC)return;let r=me,i=he;this.vectorToWorldFrame(t,r),this.vectorToWorldFrame(n,i),this.applyForce(r,i)}applyTorque(t){this.type===e.DYNAMIC&&(this.sleepState===e.SLEEPING&&this.wakeUp(),this.torque.vadd(t,this.torque))}applyImpulse(t,n){if(n===void 0&&(n=new g),this.type!==e.DYNAMIC)return;this.sleepState===e.SLEEPING&&this.wakeUp();let r=n,i=ge;i.copy(t),i.scale(this.invMass,i),this.velocity.vadd(i,this.velocity);let a=_e;r.cross(t,a),this.invInertiaWorld.vmult(a,a),this.angularVelocity.vadd(a,this.angularVelocity)}applyLocalImpulse(t,n){if(n===void 0&&(n=new g),this.type!==e.DYNAMIC)return;let r=ve,i=ye;this.vectorToWorldFrame(t,r),this.vectorToWorldFrame(n,i),this.applyImpulse(r,i)}updateMassProperties(){let e=be;this.invMass=this.mass>0?1/this.mass:0;let t=this.inertia,n=this.fixedRotation;this.updateAABB(),e.set((this.aabb.upperBound.x-this.aabb.lowerBound.x)/2,(this.aabb.upperBound.y-this.aabb.lowerBound.y)/2,(this.aabb.upperBound.z-this.aabb.lowerBound.z)/2),ae.calculateInertia(e,this.mass,t),this.invInertia.set(t.x>0&&!n?1/t.x:0,t.y>0&&!n?1/t.y:0,t.z>0&&!n?1/t.z:0),this.updateInertiaWorld(!0)}getVelocityAtWorldPoint(e,t){let n=new g;return e.vsub(this.position,n),this.angularVelocity.cross(n,t),this.velocity.vadd(t,t),t}integrate(t,n,r){if(this.previousPosition.copy(this.position),this.previousQuaternion.copy(this.quaternion),this.type!==e.DYNAMIC&&this.type!==e.KINEMATIC||this.sleepState===e.SLEEPING)return;let i=this.velocity,a=this.angularVelocity,o=this.position,s=this.force,c=this.torque,l=this.quaternion,u=this.invMass,d=this.invInertiaWorld,f=this.linearFactor,p=u*t;i.x+=s.x*p*f.x,i.y+=s.y*p*f.y,i.z+=s.z*p*f.z;let m=d.elements,h=this.angularFactor,g=c.x*h.x,_=c.y*h.y,v=c.z*h.z;a.x+=t*(m[0]*g+m[1]*_+m[2]*v),a.y+=t*(m[3]*g+m[4]*_+m[5]*v),a.z+=t*(m[6]*g+m[7]*_+m[8]*v),o.x+=i.x*t,o.y+=i.y*t,o.z+=i.z*t,l.integrate(this.angularVelocity,t,this.angularFactor,l),n&&(r?l.normalizeFast():l.normalize()),this.aabbNeedsUpdate=!0,this.updateInertiaWorld()}};P.idCounter=0,P.COLLIDE_EVENT_NAME=`collide`,P.DYNAMIC=oe.DYNAMIC,P.STATIC=oe.STATIC,P.KINEMATIC=oe.KINEMATIC,P.AWAKE=se.AWAKE,P.SLEEPY=se.SLEEPY,P.SLEEPING=se.SLEEPING,P.wakeupEvent={type:`wakeup`},P.sleepyEvent={type:`sleepy`},P.sleepEvent={type:`sleep`};var ce=new g,le=new T,ue=new b,de=new m,fe=new m;new m;var pe=new g,me=new g,he=new g,ge=new g,_e=new g,ve=new g,ye=new g,be=new g,xe=class{constructor(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}collisionPairs(e,t,n){throw Error(`collisionPairs not implemented for this BroadPhase class!`)}needBroadphaseCollision(e,t){return(e.collisionFilterGroup&t.collisionFilterMask)!==0&&(t.collisionFilterGroup&e.collisionFilterMask)!==0&&((e.type&P.STATIC)===0&&e.sleepState!==P.SLEEPING||(t.type&P.STATIC)===0&&t.sleepState!==P.SLEEPING)}intersectionTest(e,t,n,r){this.useBoundingBoxes?this.doBoundingBoxBroadphase(e,t,n,r):this.doBoundingSphereBroadphase(e,t,n,r)}doBoundingSphereBroadphase(e,t,n,r){let i=Se;t.position.vsub(e.position,i);let a=(e.boundingRadius+t.boundingRadius)**2;i.lengthSquared()<a&&(n.push(e),r.push(t))}doBoundingBoxBroadphase(e,t,n,r){e.aabbNeedsUpdate&&e.updateAABB(),t.aabbNeedsUpdate&&t.updateAABB(),e.aabb.overlaps(t.aabb)&&(n.push(e),r.push(t))}makePairsUnique(e,t){let n=Ce,r=we,i=Te,a=e.length;for(let n=0;n!==a;n++)r[n]=e[n],i[n]=t[n];e.length=0,t.length=0;for(let e=0;e!==a;e++){let t=r[e].id,a=i[e].id,o=t<a?`${t},${a}`:`${a},${t}`;n[o]=e,n.keys.push(o)}for(let a=0;a!==n.keys.length;a++){let a=n.keys.pop(),o=n[a];e.push(r[o]),t.push(i[o]),delete n[a]}}setWorld(e){}static boundingSphereCheck(e,t){let n=new g;e.position.vsub(t.position,n);let r=e.shapes[0],i=t.shapes[0];return(r.boundingSphereRadius+i.boundingSphereRadius)**2>n.lengthSquared()}aabbQuery(e,t,n){return console.warn(`.aabbQuery is not implemented in this Broadphase subclass.`),[]}},Se=new g;new g,new T,new g;var Ce={keys:[]},we=[],Te=[];new g,new g,new g;var Ee=class extends xe{constructor(){super()}collisionPairs(e,t,n){let r=e.bodies,i=r.length,a,o;for(let e=0;e!==i;e++)for(let i=0;i!==e;i++)a=r[e],o=r[i],this.needBroadphaseCollision(a,o)&&this.intersectionTest(a,o,t,n)}aabbQuery(e,t,n){n===void 0&&(n=[]);for(let r=0;r<e.bodies.length;r++){let i=e.bodies[r];i.aabbNeedsUpdate&&i.updateAABB(),i.aabb.overlaps(t)&&n.push(i)}return n}},De=class{constructor(){this.rayFromWorld=new g,this.rayToWorld=new g,this.hitNormalWorld=new g,this.hitPointWorld=new g,this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this.shouldStop=!1}reset(){this.rayFromWorld.setZero(),this.rayToWorld.setZero(),this.hitNormalWorld.setZero(),this.hitPointWorld.setZero(),this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this.shouldStop=!1}abort(){this.shouldStop=!0}set(e,t,n,r,i,a,o){this.rayFromWorld.copy(e),this.rayToWorld.copy(t),this.hitNormalWorld.copy(n),this.hitPointWorld.copy(r),this.shape=i,this.body=a,this.distance=o}},Oe,ke,Ae,je,Me,Ne,Pe,Fe={CLOSEST:1,ANY:2,ALL:4};Oe=k.types.SPHERE,ke=k.types.PLANE,Ae=k.types.BOX,je=k.types.CYLINDER,Me=k.types.CONVEXPOLYHEDRON,Ne=k.types.HEIGHTFIELD,Pe=k.types.TRIMESH;var F=class e{get[Oe](){return this._intersectSphere}get[ke](){return this._intersectPlane}get[Ae](){return this._intersectBox}get[je](){return this._intersectConvex}get[Me](){return this._intersectConvex}get[Ne](){return this._intersectHeightfield}get[Pe](){return this._intersectTrimesh}constructor(t,n){t===void 0&&(t=new g),n===void 0&&(n=new g),this.from=t.clone(),this.to=n.clone(),this.direction=new g,this.precision=1e-4,this.checkCollisionResponse=!0,this.skipBackfaces=!1,this.collisionFilterMask=-1,this.collisionFilterGroup=-1,this.mode=e.ANY,this.result=new De,this.hasHit=!1,this.callback=e=>{}}intersectWorld(t,n){return this.mode=n.mode||e.ANY,this.result=n.result||new De,this.skipBackfaces=!!n.skipBackfaces,this.collisionFilterMask=n.collisionFilterMask===void 0?-1:n.collisionFilterMask,this.collisionFilterGroup=n.collisionFilterGroup===void 0?-1:n.collisionFilterGroup,this.checkCollisionResponse=n.checkCollisionResponse===void 0||n.checkCollisionResponse,n.from&&this.from.copy(n.from),n.to&&this.to.copy(n.to),this.callback=n.callback||(()=>{}),this.hasHit=!1,this.result.reset(),this.updateDirection(),this.getAABB(Ie),Le.length=0,t.broadphase.aabbQuery(t,Ie,Le),this.intersectBodies(Le),this.hasHit}intersectBody(e,t){t&&(this.result=t,this.updateDirection());let n=this.checkCollisionResponse;if(n&&!e.collisionResponse||(this.collisionFilterGroup&e.collisionFilterMask)===0||(e.collisionFilterGroup&this.collisionFilterMask)===0)return;let r=Be,i=Ve;for(let t=0,a=e.shapes.length;t<a;t++){let a=e.shapes[t];if((!n||a.collisionResponse)&&(e.quaternion.mult(e.shapeOrientations[t],i),e.quaternion.vmult(e.shapeOffsets[t],r),r.vadd(e.position,r),this.intersectShape(a,i,r,e),this.result.shouldStop))break}}intersectBodies(e,t){t&&(this.result=t,this.updateDirection());for(let t=0,n=e.length;!this.result.shouldStop&&t<n;t++)this.intersectBody(e[t])}updateDirection(){this.to.vsub(this.from,this.direction),this.direction.normalize()}intersectShape(e,t,n,r){let i=this.from;if(at(i,this.direction,n)>e.boundingSphereRadius)return;let a=this[e.type];a&&a.call(this,e,t,n,r,e)}_intersectBox(e,t,n,r,i){return this._intersectConvex(e.convexPolyhedronRepresentation,t,n,r,i)}_intersectPlane(e,t,n,r,i){let a=this.from,o=this.to,s=this.direction,c=new g(0,0,1);t.vmult(c,c);let l=new g;a.vsub(n,l);let u=l.dot(c);if(o.vsub(n,l),u*l.dot(c)>0||a.distanceTo(o)<u)return;let d=c.dot(s);if(Math.abs(d)<this.precision)return;let f=new g,p=new g,m=new g;a.vsub(n,f);let h=-c.dot(f)/d;s.scale(h,p),a.vadd(p,m),this.reportIntersection(c,m,i,r,-1)}getAABB(e){let{lowerBound:t,upperBound:n}=e,r=this.to,i=this.from;t.x=Math.min(r.x,i.x),t.y=Math.min(r.y,i.y),t.z=Math.min(r.z,i.z),n.x=Math.max(r.x,i.x),n.y=Math.max(r.y,i.y),n.z=Math.max(r.z,i.z)}_intersectHeightfield(e,t,n,r,i){e.data,e.elementSize;let a=We;a.from.copy(this.from),a.to.copy(this.to),A.pointToLocalFrame(n,t,a.from,a.from),A.pointToLocalFrame(n,t,a.to,a.to),a.updateDirection();let o=Ge,s,c,l,u;s=c=0,l=u=e.data.length-1;let d=new b;a.getAABB(d),e.getIndexOfPosition(d.lowerBound.x,d.lowerBound.y,o,!0),s=Math.max(s,o[0]),c=Math.max(c,o[1]),e.getIndexOfPosition(d.upperBound.x,d.upperBound.y,o,!0),l=Math.min(l,o[0]+1),u=Math.min(u,o[1]+1);for(let o=s;o<l;o++)for(let s=c;s<u;s++){if(this.result.shouldStop)return;if(e.getAabbAtIndex(o,s,d),d.overlapsRay(a)){if(e.getConvexTrianglePillar(o,s,!1),A.pointToWorldFrame(n,t,e.pillarOffset,Ue),this._intersectConvex(e.pillarConvex,t,Ue,r,i,He),this.result.shouldStop)return;e.getConvexTrianglePillar(o,s,!0),A.pointToWorldFrame(n,t,e.pillarOffset,Ue),this._intersectConvex(e.pillarConvex,t,Ue,r,i,He)}}}_intersectSphere(e,t,n,r,i){let a=this.from,o=this.to,s=e.radius,c=(o.x-a.x)**2+(o.y-a.y)**2+(o.z-a.z)**2,l=2*((o.x-a.x)*(a.x-n.x)+(o.y-a.y)*(a.y-n.y)+(o.z-a.z)*(a.z-n.z)),u=(a.x-n.x)**2+(a.y-n.y)**2+(a.z-n.z)**2-s**2,d=l**2-4*c*u,f=Ke,p=qe;if(!(d<0)){if(d===0)a.lerp(o,d,f),f.vsub(n,p),p.normalize(),this.reportIntersection(p,f,i,r,-1);else{let e=(-l-Math.sqrt(d))/(2*c),t=(-l+Math.sqrt(d))/(2*c);if(e>=0&&e<=1&&(a.lerp(o,e,f),f.vsub(n,p),p.normalize(),this.reportIntersection(p,f,i,r,-1)),this.result.shouldStop)return;t>=0&&t<=1&&(a.lerp(o,t,f),f.vsub(n,p),p.normalize(),this.reportIntersection(p,f,i,r,-1))}}}_intersectConvex(t,n,r,i,a,o){let s=Je,c=Ye,l=o&&o.faceList||null,u=t.faces,d=t.vertices,f=t.faceNormals,p=this.direction,m=this.from,h=this.to,g=m.distanceTo(h),_=l?l.length:u.length,v=this.result;for(let t=0;!v.shouldStop&&t<_;t++){let o=l?l[t]:t,h=u[o],_=f[o],y=n,b=r;c.copy(d[h[0]]),y.vmult(c,c),c.vadd(b,c),c.vsub(m,c),y.vmult(_,s);let x=p.dot(s);if(Math.abs(x)<this.precision)continue;let S=s.dot(c)/x;if(!(S<0)){p.scale(S,I),I.vadd(m,I),L.copy(d[h[0]]),y.vmult(L,L),b.vadd(L,L);for(let t=1;!v.shouldStop&&t<h.length-1;t++){R.copy(d[h[t]]),z.copy(d[h[t+1]]),y.vmult(R,R),y.vmult(z,z),b.vadd(R,R),b.vadd(z,z);let n=I.distanceTo(m);!(e.pointInTriangle(I,L,R,z)||e.pointInTriangle(I,R,L,z))||n>g||this.reportIntersection(s,I,a,i,o)}}}}_intersectTrimesh(t,n,r,i,a,o){let s=Xe,c=nt,l=rt,u=Ye,d=Ze,f=Qe,p=$e,m=tt,h=et,g=t.indices;t.vertices;let _=this.from,v=this.to,y=this.direction;l.position.copy(r),l.quaternion.copy(n),A.vectorToLocalFrame(r,n,y,d),A.pointToLocalFrame(r,n,_,f),A.pointToLocalFrame(r,n,v,p),p.x*=t.scale.x,p.y*=t.scale.y,p.z*=t.scale.z,f.x*=t.scale.x,f.y*=t.scale.y,f.z*=t.scale.z,p.vsub(f,d),d.normalize();let b=f.distanceSquared(p);t.tree.rayQuery(this,l,c);for(let o=0,l=c.length;!this.result.shouldStop&&o!==l;o++){let l=c[o];t.getNormal(l,s),t.getVertex(g[l*3],L),L.vsub(f,u);let p=d.dot(s),_=s.dot(u)/p;if(_<0)continue;d.scale(_,I),I.vadd(f,I),t.getVertex(g[l*3+1],R),t.getVertex(g[l*3+2],z);let v=I.distanceSquared(f);!(e.pointInTriangle(I,R,L,z)||e.pointInTriangle(I,L,R,z))||v>b||(A.vectorToWorldFrame(n,s,h),A.pointToWorldFrame(r,n,I,m),this.reportIntersection(h,m,a,i,l))}c.length=0}reportIntersection(t,n,r,i,a){let o=this.from,s=this.to,c=o.distanceTo(n),l=this.result;if(!(this.skipBackfaces&&t.dot(this.direction)>0))switch(l.hitFaceIndex=a===void 0?-1:a,this.mode){case e.ALL:this.hasHit=!0,l.set(o,s,t,n,r,i,c),l.hasHit=!0,this.callback(l);break;case e.CLOSEST:(c<l.distance||!l.hasHit)&&(this.hasHit=!0,l.hasHit=!0,l.set(o,s,t,n,r,i,c));break;case e.ANY:this.hasHit=!0,l.hasHit=!0,l.set(o,s,t,n,r,i,c),l.shouldStop=!0}}static pointInTriangle(e,t,n,r){r.vsub(t,B),n.vsub(t,Re),e.vsub(t,ze);let i=B.dot(B),a=B.dot(Re),o=B.dot(ze),s=Re.dot(Re),c=Re.dot(ze),l,u;return(l=s*o-a*c)>=0&&(u=i*c-a*o)>=0&&l+u<i*s-a*a}};F.CLOSEST=Fe.CLOSEST,F.ANY=Fe.ANY,F.ALL=Fe.ALL;var Ie=new b,Le=[],Re=new g,ze=new g,Be=new g,Ve=new T,I=new g,L=new g,R=new g,z=new g;new g,new De;var He={faceList:[0]},Ue=new g,We=new F,Ge=[],Ke=new g,qe=new g,Je=new g;new g,new g;var Ye=new g,Xe=new g,Ze=new g,Qe=new g,$e=new g,et=new g,tt=new g;new b;var nt=[],rt=new A,B=new g,it=new g;function at(e,t,n){n.vsub(e,B);let r=B.dot(t);return t.scale(r,it),it.vadd(e,it),n.distanceTo(it)}var ot=class{static defaults(e,t){e===void 0&&(e={});for(let n in t)n in e||(e[n]=t[n]);return e}},st=class e{constructor(t,n,r){r===void 0&&(r={}),r=ot.defaults(r,{collideConnected:!0,wakeUpBodies:!0}),this.equations=[],this.bodyA=t,this.bodyB=n,this.id=e.idCounter++,this.collideConnected=r.collideConnected,r.wakeUpBodies&&(t&&t.wakeUp(),n&&n.wakeUp())}update(){throw Error(`method update() not implmemented in this Constraint subclass!`)}enable(){let e=this.equations;for(let t=0;t<e.length;t++)e[t].enabled=!0}disable(){let e=this.equations;for(let t=0;t<e.length;t++)e[t].enabled=!1}};st.idCounter=0;var ct=class{constructor(){this.spatial=new g,this.rotational=new g}multiplyElement(e){return e.spatial.dot(this.spatial)+e.rotational.dot(this.rotational)}multiplyVectors(e,t){return e.dot(this.spatial)+t.dot(this.rotational)}},lt=class e{constructor(t,n,r,i){r===void 0&&(r=-1e6),i===void 0&&(i=1e6),this.id=e.idCounter++,this.minForce=r,this.maxForce=i,this.bi=t,this.bj=n,this.a=0,this.b=0,this.eps=0,this.jacobianElementA=new ct,this.jacobianElementB=new ct,this.enabled=!0,this.multiplier=0,this.setSpookParams(1e7,4,1/60)}setSpookParams(e,t,n){let r=t,i=e,a=n;this.a=4/(a*(1+4*r)),this.b=4*r/(1+4*r),this.eps=4/(a*a*i*(1+4*r))}computeB(e,t,n){let r=this.computeGW(),i=this.computeGq(),a=this.computeGiMf();return-i*e-r*t-a*n}computeGq(){let e=this.jacobianElementA,t=this.jacobianElementB,n=this.bi,r=this.bj,i=n.position,a=r.position;return e.spatial.dot(i)+t.spatial.dot(a)}computeGW(){let e=this.jacobianElementA,t=this.jacobianElementB,n=this.bi,r=this.bj,i=n.velocity,a=r.velocity,o=n.angularVelocity,s=r.angularVelocity;return e.multiplyVectors(i,o)+t.multiplyVectors(a,s)}computeGWlambda(){let e=this.jacobianElementA,t=this.jacobianElementB,n=this.bi,r=this.bj,i=n.vlambda,a=r.vlambda,o=n.wlambda,s=r.wlambda;return e.multiplyVectors(i,o)+t.multiplyVectors(a,s)}computeGiMf(){let e=this.jacobianElementA,t=this.jacobianElementB,n=this.bi,r=this.bj,i=n.force,a=n.torque,o=r.force,s=r.torque,c=n.invMassSolve,l=r.invMassSolve;return i.scale(c,ut),o.scale(l,dt),n.invInertiaWorldSolve.vmult(a,ft),r.invInertiaWorldSolve.vmult(s,pt),e.multiplyVectors(ut,ft)+t.multiplyVectors(dt,pt)}computeGiMGt(){let e=this.jacobianElementA,t=this.jacobianElementB,n=this.bi,r=this.bj,i=n.invMassSolve,a=r.invMassSolve,o=n.invInertiaWorldSolve,s=r.invInertiaWorldSolve,c=i+a;return o.vmult(e.rotational,mt),c+=mt.dot(e.rotational),s.vmult(t.rotational,mt),c+=mt.dot(t.rotational),c}addToWlambda(e){let t=this.jacobianElementA,n=this.jacobianElementB,r=this.bi,i=this.bj,a=ht;r.vlambda.addScaledVector(r.invMassSolve*e,t.spatial,r.vlambda),i.vlambda.addScaledVector(i.invMassSolve*e,n.spatial,i.vlambda),r.invInertiaWorldSolve.vmult(t.rotational,a),r.wlambda.addScaledVector(e,a,r.wlambda),i.invInertiaWorldSolve.vmult(n.rotational,a),i.wlambda.addScaledVector(e,a,i.wlambda)}computeC(){return this.computeGiMGt()+this.eps}};lt.idCounter=0;var ut=new g,dt=new g,ft=new g,pt=new g,mt=new g,ht=new g,gt=class extends lt{constructor(e,t,n){n===void 0&&(n=1e6),super(e,t,0,n),this.restitution=0,this.ri=new g,this.rj=new g,this.ni=new g}computeB(e){let t=this.a,n=this.b,r=this.bi,i=this.bj,a=this.ri,o=this.rj,s=_t,c=vt,l=r.velocity,u=r.angularVelocity;r.force,r.torque;let d=i.velocity,f=i.angularVelocity;i.force,i.torque;let p=yt,m=this.jacobianElementA,h=this.jacobianElementB,g=this.ni;a.cross(g,s),o.cross(g,c),g.negate(m.spatial),s.negate(m.rotational),h.spatial.copy(g),h.rotational.copy(c),p.copy(i.position),p.vadd(o,p),p.vsub(r.position,p),p.vsub(a,p);let _=g.dot(p),v=this.restitution+1,y=v*d.dot(g)-v*l.dot(g)+f.dot(c)-u.dot(s),b=this.computeGiMf();return-_*t-y*n-e*b}getImpactVelocityAlongNormal(){let e=bt,t=xt,n=St,r=Ct,i=wt;return this.bi.position.vadd(this.ri,n),this.bj.position.vadd(this.rj,r),this.bi.getVelocityAtWorldPoint(n,e),this.bj.getVelocityAtWorldPoint(r,t),e.vsub(t,i),this.ni.dot(i)}},_t=new g,vt=new g,yt=new g,bt=new g,xt=new g,St=new g,Ct=new g,wt=new g,Tt=class extends st{constructor(e,t,n,r,i){t===void 0&&(t=new g),r===void 0&&(r=new g),i===void 0&&(i=1e6),super(e,n),this.pivotA=t.clone(),this.pivotB=r.clone();let a=this.equationX=new gt(e,n),o=this.equationY=new gt(e,n),s=this.equationZ=new gt(e,n);this.equations.push(a,o,s),a.minForce=o.minForce=s.minForce=-i,a.maxForce=o.maxForce=s.maxForce=i,a.ni.set(1,0,0),o.ni.set(0,1,0),s.ni.set(0,0,1)}update(){let e=this.bodyA,t=this.bodyB,n=this.equationX,r=this.equationY,i=this.equationZ;e.quaternion.vmult(this.pivotA,n.ri),t.quaternion.vmult(this.pivotB,n.rj),r.ri.copy(n.ri),r.rj.copy(n.rj),i.ri.copy(n.ri),i.rj.copy(n.rj)}};new g,new g;var Et=class extends lt{constructor(e,t,n){n===void 0&&(n={});let r=n.maxForce===void 0?1e6:n.maxForce;super(e,t,-r,r),this.axisA=n.axisA?n.axisA.clone():new g(1,0,0),this.axisB=n.axisB?n.axisB.clone():new g(0,1,0),this.maxAngle=Math.PI/2}computeB(e){let t=this.a,n=this.b,r=this.axisA,i=this.axisB,a=Dt,o=Ot,s=this.jacobianElementA,c=this.jacobianElementB;r.cross(i,a),i.cross(r,o),s.rotational.copy(o),c.rotational.copy(a);let l=Math.cos(this.maxAngle)-r.dot(i),u=this.computeGW(),d=this.computeGiMf();return-l*t-u*n-e*d}},Dt=new g,Ot=new g;new g,new g;var kt=class extends st{constructor(e,t,n,r){r===void 0&&(r=1e6),super(e,t),n===void 0&&(n=e.position.distanceTo(t.position)),this.distance=n;let i=this.distanceEquation=new gt(e,t);this.equations.push(i),i.minForce=-r,i.maxForce=r}update(){let e=this.bodyA,t=this.bodyB,n=this.distanceEquation,r=this.distance*.5,i=n.ni;t.position.vsub(e.position,i),i.normalize(),i.scale(r,n.ri),i.scale(-r,n.rj)}},At=class extends Tt{constructor(e,t,n){n===void 0&&(n={});let r=n.maxForce===void 0?1e6:n.maxForce,i=new g,a=new g,o=new g;e.position.vadd(t.position,o),o.scale(.5,o),t.pointToLocalFrame(o,a),e.pointToLocalFrame(o,i),super(e,i,t,a,r),this.xA=e.vectorToLocalFrame(g.UNIT_X),this.xB=t.vectorToLocalFrame(g.UNIT_X),this.yA=e.vectorToLocalFrame(g.UNIT_Y),this.yB=t.vectorToLocalFrame(g.UNIT_Y),this.zA=e.vectorToLocalFrame(g.UNIT_Z),this.zB=t.vectorToLocalFrame(g.UNIT_Z);let s=this.rotationalEquation1=new Et(e,t,n),c=this.rotationalEquation2=new Et(e,t,n),l=this.rotationalEquation3=new Et(e,t,n);this.equations.push(s,c,l)}update(){let e=this.bodyA,t=this.bodyB;this.motorEquation;let n=this.rotationalEquation1,r=this.rotationalEquation2,i=this.rotationalEquation3;super.update(),e.vectorToWorldFrame(this.xA,n.axisA),t.vectorToWorldFrame(this.yB,n.axisB),e.vectorToWorldFrame(this.yA,r.axisA),t.vectorToWorldFrame(this.zB,r.axisB),e.vectorToWorldFrame(this.zA,i.axisA),t.vectorToWorldFrame(this.xB,i.axisB)}};new g,new g;var jt=class extends lt{constructor(e,t,n){n===void 0&&(n=1e6),super(e,t,-n,n),this.axisA=new g,this.axisB=new g,this.targetVelocity=0}computeB(e){this.a;let t=this.b;this.bi,this.bj;let n=this.axisA,r=this.axisB,i=this.jacobianElementA,a=this.jacobianElementB;i.rotational.copy(n),r.negate(a.rotational);let o=this.computeGW()-this.targetVelocity,s=this.computeGiMf();return-o*t-e*s}},Mt=class extends Tt{constructor(e,t,n){n===void 0&&(n={});let r=n.maxForce===void 0?1e6:n.maxForce,i=n.pivotA?n.pivotA.clone():new g,a=n.pivotB?n.pivotB.clone():new g;super(e,i,t,a,r),(this.axisA=n.axisA?n.axisA.clone():new g(1,0,0)).normalize(),(this.axisB=n.axisB?n.axisB.clone():new g(1,0,0)).normalize(),this.collideConnected=!!n.collideConnected;let o=this.rotationalEquation1=new Et(e,t,n),s=this.rotationalEquation2=new Et(e,t,n),c=this.motorEquation=new jt(e,t,r);c.enabled=!1,this.equations.push(o,s,c)}enableMotor(){this.motorEquation.enabled=!0}disableMotor(){this.motorEquation.enabled=!1}setMotorSpeed(e){this.motorEquation.targetVelocity=e}setMotorMaxForce(e){this.motorEquation.maxForce=e,this.motorEquation.minForce=-e}update(){let e=this.bodyA,t=this.bodyB,n=this.motorEquation,r=this.rotationalEquation1,i=this.rotationalEquation2,a=Nt,o=Pt,s=this.axisA,c=this.axisB;super.update(),e.quaternion.vmult(s,a),t.quaternion.vmult(c,o),a.tangents(r.axisA,i.axisA),r.axisB.copy(o),i.axisB.copy(o),this.motorEquation.enabled&&(e.quaternion.vmult(this.axisA,n.axisA),t.quaternion.vmult(this.axisB,n.axisB))}},Nt=new g,Pt=new g,Ft=class extends lt{constructor(e,t,n){super(e,t,-n,n),this.ri=new g,this.rj=new g,this.t=new g}computeB(e){this.a;let t=this.b;this.bi,this.bj;let n=this.ri,r=this.rj,i=It,a=Lt,o=this.t;n.cross(o,i),r.cross(o,a);let s=this.jacobianElementA,c=this.jacobianElementB;o.negate(s.spatial),i.negate(s.rotational),c.spatial.copy(o),c.rotational.copy(a);let l=this.computeGW(),u=this.computeGiMf();return-l*t-e*u}},It=new g,Lt=new g,Rt=class e{constructor(t,n,r){r=ot.defaults(r,{friction:.3,restitution:.3,contactEquationStiffness:1e7,contactEquationRelaxation:3,frictionEquationStiffness:1e7,frictionEquationRelaxation:3}),this.id=e.idCounter++,this.materials=[t,n],this.friction=r.friction,this.restitution=r.restitution,this.contactEquationStiffness=r.contactEquationStiffness,this.contactEquationRelaxation=r.contactEquationRelaxation,this.frictionEquationStiffness=r.frictionEquationStiffness,this.frictionEquationRelaxation=r.frictionEquationRelaxation}};Rt.idCounter=0;var zt=class e{constructor(t){t===void 0&&(t={});let n=``;typeof t==`string`&&(n=t,t={}),this.name=n,this.id=e.idCounter++,this.friction=t.friction===void 0?-1:t.friction,this.restitution=t.restitution===void 0?-1:t.restitution}};zt.idCounter=0;var Bt=class{constructor(e,t,n){n===void 0&&(n={}),this.restLength=typeof n.restLength==`number`?n.restLength:1,this.stiffness=n.stiffness||100,this.damping=n.damping||1,this.bodyA=e,this.bodyB=t,this.localAnchorA=new g,this.localAnchorB=new g,n.localAnchorA&&this.localAnchorA.copy(n.localAnchorA),n.localAnchorB&&this.localAnchorB.copy(n.localAnchorB),n.worldAnchorA&&this.setWorldAnchorA(n.worldAnchorA),n.worldAnchorB&&this.setWorldAnchorB(n.worldAnchorB)}setWorldAnchorA(e){this.bodyA.pointToLocalFrame(e,this.localAnchorA)}setWorldAnchorB(e){this.bodyB.pointToLocalFrame(e,this.localAnchorB)}getWorldAnchorA(e){this.bodyA.pointToWorldFrame(this.localAnchorA,e)}getWorldAnchorB(e){this.bodyB.pointToWorldFrame(this.localAnchorB,e)}applyForce(){let e=this.stiffness,t=this.damping,n=this.restLength,r=this.bodyA,i=this.bodyB,a=Vt,o=Ht,s=Ut,c=Wt,l=Zt,u=Gt,d=Kt,f=qt,p=Jt,m=Yt,h=Xt;this.getWorldAnchorA(u),this.getWorldAnchorB(d),u.vsub(r.position,f),d.vsub(i.position,p),d.vsub(u,a);let g=a.length();o.copy(a),o.normalize(),i.velocity.vsub(r.velocity,s),i.angularVelocity.cross(p,l),s.vadd(l,s),r.angularVelocity.cross(f,l),s.vsub(l,s),o.scale(-e*(g-n)-t*s.dot(o),c),r.force.vsub(c,r.force),i.force.vadd(c,i.force),f.cross(c,m),p.cross(c,h),r.torque.vsub(m,r.torque),i.torque.vadd(h,i.torque)}},Vt=new g,Ht=new g,Ut=new g,Wt=new g,Gt=new g,Kt=new g,qt=new g,Jt=new g,Yt=new g,Xt=new g,Zt=new g;new g,new g,new g,new g,new g,new g,new g,new g,new F,new g,new g,new g,new g(1,0,0),new g(0,1,0),new g(0,0,1),new g,new g,new g,new g,new g,new g,new g,new g,new g,new g,new g;var Qt=class extends k{constructor(e){if(super({type:k.types.SPHERE}),this.radius=e===void 0?1:e,this.radius<0)throw Error(`The sphere radius cannot be negative.`);this.updateBoundingSphereRadius()}calculateLocalInertia(e,t){t===void 0&&(t=new g);let n=2*e*this.radius*this.radius/5;return t.x=n,t.y=n,t.z=n,t}volume(){return 4*Math.PI*this.radius**3/3}updateBoundingSphereRadius(){this.boundingSphereRadius=this.radius}calculateWorldAABB(e,t,n,r){let i=this.radius,a=[`x`,`y`,`z`];for(let t=0;t<a.length;t++){let o=a[t];n[o]=e[o]-i,r[o]=e[o]+i}}};new g,new g,new g,new g,new g,new g,new g,new g,new g;var $t=class extends j{constructor(e,t,n,r){if(e===void 0&&(e=1),t===void 0&&(t=1),n===void 0&&(n=1),r===void 0&&(r=8),e<0)throw Error(`The cylinder radiusTop cannot be negative.`);if(t<0)throw Error(`The cylinder radiusBottom cannot be negative.`);let i=r,a=[],o=[],s=[],c=[],l=[],u=Math.cos,d=Math.sin;a.push(new g(-t*d(0),-n*.5,t*u(0))),c.push(0),a.push(new g(-e*d(0),n*.5,e*u(0))),l.push(1);for(let r=0;r<i;r++){let f=2*Math.PI/i*(r+1),p=2*Math.PI/i*(r+.5);r<i-1?(a.push(new g(-t*d(f),-n*.5,t*u(f))),c.push(2*r+2),a.push(new g(-e*d(f),n*.5,e*u(f))),l.push(2*r+3),s.push([2*r,2*r+1,2*r+3,2*r+2])):s.push([2*r,2*r+1,1,0]),(i%2==1||r<i/2)&&o.push(new g(-d(p),0,u(p)))}s.push(c),o.push(new g(0,1,0));let f=[];for(let e=0;e<l.length;e++)f.push(l[l.length-e-1]);s.push(f),super({vertices:a,faces:s,axes:o}),this.type=k.types.CYLINDER,this.radiusTop=e,this.radiusBottom=t,this.height=n,this.numSegments=r}};new g;var en=class extends k{constructor(e,t){t===void 0&&(t={}),t=ot.defaults(t,{maxValue:null,minValue:null,elementSize:1}),super({type:k.types.HEIGHTFIELD}),this.data=e,this.maxValue=t.maxValue,this.minValue=t.minValue,this.elementSize=t.elementSize,t.minValue===null&&this.updateMinValue(),t.maxValue===null&&this.updateMaxValue(),this.cacheEnabled=!0,this.pillarConvex=new j,this.pillarOffset=new g,this.updateBoundingSphereRadius(),this._cachedPillars={}}update(){this._cachedPillars={}}updateMinValue(){let e=this.data,t=e[0][0];for(let n=0;n!==e.length;n++)for(let r=0;r!==e[n].length;r++){let i=e[n][r];i<t&&(t=i)}this.minValue=t}updateMaxValue(){let e=this.data,t=e[0][0];for(let n=0;n!==e.length;n++)for(let r=0;r!==e[n].length;r++){let i=e[n][r];i>t&&(t=i)}this.maxValue=t}setHeightValueAtIndex(e,t,n){let r=this.data;r[e][t]=n,this.clearCachedConvexTrianglePillar(e,t,!1),e>0&&(this.clearCachedConvexTrianglePillar(e-1,t,!0),this.clearCachedConvexTrianglePillar(e-1,t,!1)),t>0&&(this.clearCachedConvexTrianglePillar(e,t-1,!0),this.clearCachedConvexTrianglePillar(e,t-1,!1)),t>0&&e>0&&this.clearCachedConvexTrianglePillar(e-1,t-1,!0)}getRectMinMax(e,t,n,r,i){i===void 0&&(i=[]);let a=this.data,o=this.minValue;for(let i=e;i<=n;i++)for(let e=t;e<=r;e++){let t=a[i][e];t>o&&(o=t)}i[0]=this.minValue,i[1]=o}getIndexOfPosition(e,t,n,r){let i=this.elementSize,a=this.data,o=Math.floor(e/i),s=Math.floor(t/i);return n[0]=o,n[1]=s,r&&(o<0&&(o=0),s<0&&(s=0),o>=a.length-1&&(o=a.length-1),s>=a[0].length-1&&(s=a[0].length-1)),!(o<0||s<0||o>=a.length-1||s>=a[0].length-1)}getTriangleAt(e,t,n,r,i,a){let o=tn;this.getIndexOfPosition(e,t,o,n);let s=o[0],c=o[1],l=this.data;n&&(s=Math.min(l.length-2,Math.max(0,s)),c=Math.min(l[0].length-2,Math.max(0,c)));let u=this.elementSize,d=(e/u-s)**2+(t/u-c)**2>(e/u-(s+1))**2+(t/u-(c+1))**2;return this.getTriangle(s,c,d,r,i,a),d}getNormalAt(e,t,n,r){let i=sn,a=cn,o=ln,s=un,c=dn;this.getTriangleAt(e,t,n,i,a,o),a.vsub(i,s),o.vsub(i,c),s.cross(c,r),r.normalize()}getAabbAtIndex(e,t,n){let{lowerBound:r,upperBound:i}=n,a=this.data,o=this.elementSize;r.set(e*o,t*o,a[e][t]),i.set((e+1)*o,(t+1)*o,a[e+1][t+1])}getHeightAt(e,t,n){let r=this.data,i=rn,a=an,o=on,s=tn;this.getIndexOfPosition(e,t,s,n);let c=s[0],l=s[1];n&&(c=Math.min(r.length-2,Math.max(0,c)),l=Math.min(r[0].length-2,Math.max(0,l)));let u=this.getTriangleAt(e,t,n,i,a,o);fn(e,t,i.x,i.y,a.x,a.y,o.x,o.y,nn);let d=nn;return u?r[c+1][l+1]*d.x+r[c][l+1]*d.y+r[c+1][l]*d.z:r[c][l]*d.x+r[c+1][l]*d.y+r[c][l+1]*d.z}getCacheConvexTrianglePillarKey(e,t,n){return`${e}_${t}_${+!!n}`}getCachedConvexTrianglePillar(e,t,n){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(e,t,n)]}setCachedConvexTrianglePillar(e,t,n,r,i){this._cachedPillars[this.getCacheConvexTrianglePillarKey(e,t,n)]={convex:r,offset:i}}clearCachedConvexTrianglePillar(e,t,n){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(e,t,n)]}getTriangle(e,t,n,r,i,a){let o=this.data,s=this.elementSize;n?(r.set((e+1)*s,(t+1)*s,o[e+1][t+1]),i.set(e*s,(t+1)*s,o[e][t+1]),a.set((e+1)*s,t*s,o[e+1][t])):(r.set(e*s,t*s,o[e][t]),i.set((e+1)*s,t*s,o[e+1][t]),a.set(e*s,(t+1)*s,o[e][t+1]))}getConvexTrianglePillar(e,t,n){let r=this.pillarConvex,i=this.pillarOffset;if(this.cacheEnabled){let a=this.getCachedConvexTrianglePillar(e,t,n);if(a){this.pillarConvex=a.convex,this.pillarOffset=a.offset;return}r=new j,i=new g,this.pillarConvex=r,this.pillarOffset=i}let a=this.data,o=this.elementSize,s=r.faces;r.vertices.length=6;for(let e=0;e<6;e++)r.vertices[e]||(r.vertices[e]=new g);s.length=5;for(let e=0;e<5;e++)s[e]||(s[e]=[]);let c=r.vertices,l=(Math.min(a[e][t],a[e+1][t],a[e][t+1],a[e+1][t+1])-this.minValue)/2+this.minValue;n?(i.set((e+.75)*o,(t+.75)*o,l),c[0].set(.25*o,.25*o,a[e+1][t+1]-l),c[1].set(-.75*o,.25*o,a[e][t+1]-l),c[2].set(.25*o,-.75*o,a[e+1][t]-l),c[3].set(.25*o,.25*o,-Math.abs(l)-1),c[4].set(-.75*o,.25*o,-Math.abs(l)-1),c[5].set(.25*o,-.75*o,-Math.abs(l)-1),s[0][0]=0,s[0][1]=1,s[0][2]=2,s[1][0]=5,s[1][1]=4,s[1][2]=3,s[2][0]=2,s[2][1]=5,s[2][2]=3,s[2][3]=0,s[3][0]=3,s[3][1]=4,s[3][2]=1,s[3][3]=0,s[4][0]=1,s[4][1]=4,s[4][2]=5,s[4][3]=2):(i.set((e+.25)*o,(t+.25)*o,l),c[0].set(-.25*o,-.25*o,a[e][t]-l),c[1].set(.75*o,-.25*o,a[e+1][t]-l),c[2].set(-.25*o,.75*o,a[e][t+1]-l),c[3].set(-.25*o,-.25*o,-Math.abs(l)-1),c[4].set(.75*o,-.25*o,-Math.abs(l)-1),c[5].set(-.25*o,.75*o,-Math.abs(l)-1),s[0][0]=0,s[0][1]=1,s[0][2]=2,s[1][0]=5,s[1][1]=4,s[1][2]=3,s[2][0]=0,s[2][1]=2,s[2][2]=5,s[2][3]=3,s[3][0]=1,s[3][1]=0,s[3][2]=3,s[3][3]=4,s[4][0]=4,s[4][1]=5,s[4][2]=2,s[4][3]=1),r.computeNormals(),r.computeEdges(),r.updateBoundingSphereRadius(),this.setCachedConvexTrianglePillar(e,t,n,r,i)}calculateLocalInertia(e,t){return t===void 0&&(t=new g),t.set(0,0,0),t}volume(){return Number.MAX_VALUE}calculateWorldAABB(e,t,n,r){n.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),r.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)}updateBoundingSphereRadius(){let e=this.data,t=this.elementSize;this.boundingSphereRadius=new g(e.length*t,e[0].length*t,Math.max(Math.abs(this.maxValue),Math.abs(this.minValue))).length()}setHeightsFromImage(e,t){let{x:n,z:r,y:i}=t,a=document.createElement(`canvas`);a.width=e.width,a.height=e.height;let o=a.getContext(`2d`);o.drawImage(e,0,0);let s=o.getImageData(0,0,e.width,e.height),c=this.data;c.length=0,this.elementSize=Math.abs(n)/s.width;for(let e=0;e<s.height;e++){let t=[];for(let i=0;i<s.width;i++){let a=s.data[(e*s.height+i)*4],o=s.data[(e*s.height+i)*4+1],c=s.data[(e*s.height+i)*4+2],l=(a+o+c)/4/255*r;n<0?t.push(l):t.unshift(l)}i<0?c.unshift(t):c.push(t)}this.updateMaxValue(),this.updateMinValue(),this.update()}},tn=[],nn=new g,rn=new g,an=new g,on=new g,sn=new g,cn=new g,ln=new g,un=new g,dn=new g;function fn(e,t,n,r,i,a,o,s,c){c.x=((a-s)*(e-o)+(o-i)*(t-s))/((a-s)*(n-o)+(o-i)*(r-s)),c.y=((s-r)*(e-o)+(n-o)*(t-s))/((a-s)*(n-o)+(o-i)*(r-s)),c.z=1-c.x-c.y}new g,new b,new g,new b,new g,new g,new g,new g,new g,new g,new g,new b,new g,new A,new b;var pn=class{constructor(){this.equations=[]}solve(e,t){return 0}addEquation(e){e.enabled&&!e.bi.isTrigger&&!e.bj.isTrigger&&this.equations.push(e)}removeEquation(e){let t=this.equations,n=t.indexOf(e);n!==-1&&t.splice(n,1)}removeAllEquations(){this.equations.length=0}},mn=class extends pn{constructor(){super(),this.iterations=10,this.tolerance=1e-7}solve(e,t){let n=0,r=this.iterations,i=this.tolerance*this.tolerance,a=this.equations,o=a.length,s=t.bodies,c=s.length,l=e,u,d,f,p,m,h;if(o!==0)for(let e=0;e!==c;e++)s[e].updateSolveMassProperties();let g=gn,_=_n,v=hn;g.length=o,_.length=o,v.length=o;for(let e=0;e!==o;e++){let t=a[e];v[e]=0,_[e]=t.computeB(l),g[e]=1/t.computeC()}if(o!==0){for(let e=0;e!==c;e++){let t=s[e],n=t.vlambda,r=t.wlambda;n.set(0,0,0),r.set(0,0,0)}for(n=0;n!==r;n++){p=0;for(let e=0;e!==o;e++){let t=a[e];u=_[e],d=g[e],h=v[e],m=t.computeGWlambda(),f=d*(u-m-t.eps*h),h+f<t.minForce?f=t.minForce-h:h+f>t.maxForce&&(f=t.maxForce-h),v[e]+=f,p+=f>0?f:-f,t.addToWlambda(f)}if(p*p<i)break}for(let e=0;e!==c;e++){let t=s[e],n=t.velocity,r=t.angularVelocity;t.vlambda.vmul(t.linearFactor,t.vlambda),n.vadd(t.vlambda,n),t.wlambda.vmul(t.angularFactor,t.wlambda),r.vadd(t.wlambda,r)}let e=a.length,t=1/l;for(;e--;)a[e].multiplier=v[e]*t}return n}},hn=[],gn=[],_n=[];P.STATIC;var vn=class{constructor(){this.objects=[],this.type=Object}release(){let e=arguments.length;for(let t=0;t!==e;t++)this.objects.push(t<0||arguments.length<=t?void 0:arguments[t]);return this}get(){return this.objects.length===0?this.constructObject():this.objects.pop()}constructObject(){throw Error(`constructObject() not implemented in this Pool subclass yet!`)}resize(e){let t=this.objects;for(;t.length>e;)t.pop();for(;t.length<e;)t.push(this.constructObject());return this}},yn=class extends vn{constructor(){super(...arguments),this.type=g}constructObject(){return new g}},V={sphereSphere:k.types.SPHERE,spherePlane:k.types.SPHERE|k.types.PLANE,boxBox:k.types.BOX|k.types.BOX,sphereBox:k.types.SPHERE|k.types.BOX,planeBox:k.types.PLANE|k.types.BOX,convexConvex:k.types.CONVEXPOLYHEDRON,sphereConvex:k.types.SPHERE|k.types.CONVEXPOLYHEDRON,planeConvex:k.types.PLANE|k.types.CONVEXPOLYHEDRON,boxConvex:k.types.BOX|k.types.CONVEXPOLYHEDRON,sphereHeightfield:k.types.SPHERE|k.types.HEIGHTFIELD,boxHeightfield:k.types.BOX|k.types.HEIGHTFIELD,convexHeightfield:k.types.CONVEXPOLYHEDRON|k.types.HEIGHTFIELD,sphereParticle:k.types.PARTICLE|k.types.SPHERE,planeParticle:k.types.PLANE|k.types.PARTICLE,boxParticle:k.types.BOX|k.types.PARTICLE,convexParticle:k.types.PARTICLE|k.types.CONVEXPOLYHEDRON,cylinderCylinder:k.types.CYLINDER,sphereCylinder:k.types.SPHERE|k.types.CYLINDER,planeCylinder:k.types.PLANE|k.types.CYLINDER,boxCylinder:k.types.BOX|k.types.CYLINDER,convexCylinder:k.types.CONVEXPOLYHEDRON|k.types.CYLINDER,heightfieldCylinder:k.types.HEIGHTFIELD|k.types.CYLINDER,particleCylinder:k.types.PARTICLE|k.types.CYLINDER,sphereTrimesh:k.types.SPHERE|k.types.TRIMESH,planeTrimesh:k.types.PLANE|k.types.TRIMESH},bn=class{get[V.sphereSphere](){return this.sphereSphere}get[V.spherePlane](){return this.spherePlane}get[V.boxBox](){return this.boxBox}get[V.sphereBox](){return this.sphereBox}get[V.planeBox](){return this.planeBox}get[V.convexConvex](){return this.convexConvex}get[V.sphereConvex](){return this.sphereConvex}get[V.planeConvex](){return this.planeConvex}get[V.boxConvex](){return this.boxConvex}get[V.sphereHeightfield](){return this.sphereHeightfield}get[V.boxHeightfield](){return this.boxHeightfield}get[V.convexHeightfield](){return this.convexHeightfield}get[V.sphereParticle](){return this.sphereParticle}get[V.planeParticle](){return this.planeParticle}get[V.boxParticle](){return this.boxParticle}get[V.convexParticle](){return this.convexParticle}get[V.cylinderCylinder](){return this.convexConvex}get[V.sphereCylinder](){return this.sphereConvex}get[V.planeCylinder](){return this.planeConvex}get[V.boxCylinder](){return this.boxConvex}get[V.convexCylinder](){return this.convexConvex}get[V.heightfieldCylinder](){return this.heightfieldCylinder}get[V.particleCylinder](){return this.particleCylinder}get[V.sphereTrimesh](){return this.sphereTrimesh}get[V.planeTrimesh](){return this.planeTrimesh}constructor(e){this.contactPointPool=[],this.frictionEquationPool=[],this.result=[],this.frictionResult=[],this.v3pool=new yn,this.world=e,this.currentContactMaterial=e.defaultContactMaterial,this.enableFrictionReduction=!1}createContactEquation(e,t,n,r,i,a){let o;this.contactPointPool.length?(o=this.contactPointPool.pop(),o.bi=e,o.bj=t):o=new gt(e,t),o.enabled=e.collisionResponse&&t.collisionResponse&&n.collisionResponse&&r.collisionResponse;let s=this.currentContactMaterial;o.restitution=s.restitution,o.setSpookParams(s.contactEquationStiffness,s.contactEquationRelaxation,this.world.dt);let c=n.material||e.material,l=r.material||t.material;return c&&l&&c.restitution>=0&&l.restitution>=0&&(o.restitution=c.restitution*l.restitution),o.si=i||n,o.sj=a||r,o}createFrictionEquationsFromContact(e,t){let n=e.bi,r=e.bj,i=e.si,a=e.sj,o=this.world,s=this.currentContactMaterial,c=s.friction,l=i.material||n.material,u=a.material||r.material;if(l&&u&&l.friction>=0&&u.friction>=0&&(c=l.friction*u.friction),c>0){let i=c*(o.frictionGravity||o.gravity).length(),a=n.invMass+r.invMass;a>0&&(a=1/a);let l=this.frictionEquationPool,u=l.length?l.pop():new Ft(n,r,i*a),d=l.length?l.pop():new Ft(n,r,i*a);return u.bi=d.bi=n,u.bj=d.bj=r,u.minForce=d.minForce=-i*a,u.maxForce=d.maxForce=i*a,u.ri.copy(e.ri),u.rj.copy(e.rj),d.ri.copy(e.ri),d.rj.copy(e.rj),e.ni.tangents(u.t,d.t),u.setSpookParams(s.frictionEquationStiffness,s.frictionEquationRelaxation,o.dt),d.setSpookParams(s.frictionEquationStiffness,s.frictionEquationRelaxation,o.dt),u.enabled=d.enabled=e.enabled,t.push(u,d),!0}return!1}createFrictionFromAverage(e){let t=this.result[this.result.length-1];if(!this.createFrictionEquationsFromContact(t,this.frictionResult)||e===1)return;let n=this.frictionResult[this.frictionResult.length-2],r=this.frictionResult[this.frictionResult.length-1];H.setZero(),U.setZero(),W.setZero();let i=t.bi;t.bj;for(let n=0;n!==e;n++)t=this.result[this.result.length-1-n],t.bi===i?(H.vsub(t.ni,H),U.vadd(t.rj,U),W.vadd(t.ri,W)):(H.vadd(t.ni,H),U.vadd(t.ri,U),W.vadd(t.rj,W));let a=1/e;U.scale(a,n.ri),W.scale(a,n.rj),r.ri.copy(n.ri),r.rj.copy(n.rj),H.normalize(),H.tangents(n.t,r.t)}getContacts(e,t,n,r,i,a,o){this.contactPointPool=i,this.frictionEquationPool=o,this.result=r,this.frictionResult=a;let s=Cn,c=wn,l=xn,u=Sn;for(let r=0,i=e.length;r!==i;r++){let i=e[r],a=t[r],o=null;i.material&&a.material&&(o=n.getContactMaterial(i.material,a.material)||null);let d=i.type&P.KINEMATIC&&a.type&P.STATIC||i.type&P.STATIC&&a.type&P.KINEMATIC||i.type&P.KINEMATIC&&a.type&P.KINEMATIC;for(let e=0;e<i.shapes.length;e++){i.quaternion.mult(i.shapeOrientations[e],s),i.quaternion.vmult(i.shapeOffsets[e],l),l.vadd(i.position,l);let t=i.shapes[e];for(let e=0;e<a.shapes.length;e++){a.quaternion.mult(a.shapeOrientations[e],c),a.quaternion.vmult(a.shapeOffsets[e],u),u.vadd(a.position,u);let r=a.shapes[e];if(!(t.collisionFilterMask&r.collisionFilterGroup&&r.collisionFilterMask&t.collisionFilterGroup)||l.distanceTo(u)>t.boundingSphereRadius+r.boundingSphereRadius)continue;let f=null;t.material&&r.material&&(f=n.getContactMaterial(t.material,r.material)||null),this.currentContactMaterial=f||o||n.defaultContactMaterial;let p=t.type|r.type,m=this[p];if(m){let e=!1;e=t.type<r.type?m.call(this,t,r,l,u,s,c,i,a,t,r,d):m.call(this,r,t,u,l,c,s,a,i,t,r,d),e&&d&&(n.shapeOverlapKeeper.set(t.id,r.id),n.bodyOverlapKeeper.set(i.id,a.id))}}}}}sphereSphere(e,t,n,r,i,a,o,s,c,l,u){if(u)return n.distanceSquared(r)<(e.radius+t.radius)**2;let d=this.createContactEquation(o,s,e,t,c,l);r.vsub(n,d.ni),d.ni.normalize(),d.ri.copy(d.ni),d.rj.copy(d.ni),d.ri.scale(e.radius,d.ri),d.rj.scale(-t.radius,d.rj),d.ri.vadd(n,d.ri),d.ri.vsub(o.position,d.ri),d.rj.vadd(r,d.rj),d.rj.vsub(s.position,d.rj),this.result.push(d),this.createFrictionEquationsFromContact(d,this.frictionResult)}spherePlane(e,t,n,r,i,a,o,s,c,l,u){let d=this.createContactEquation(o,s,e,t,c,l);if(d.ni.set(0,0,1),a.vmult(d.ni,d.ni),d.ni.negate(d.ni),d.ni.normalize(),d.ni.scale(e.radius,d.ri),n.vsub(r,Un),d.ni.scale(d.ni.dot(Un),Wn),Un.vsub(Wn,d.rj),-Un.dot(d.ni)<=e.radius){if(u)return!0;let e=d.ri,t=d.rj;e.vadd(n,e),e.vsub(o.position,e),t.vadd(r,t),t.vsub(s.position,t),this.result.push(d),this.createFrictionEquationsFromContact(d,this.frictionResult)}}boxBox(e,t,n,r,i,a,o,s,c,l,u){return e.convexPolyhedronRepresentation.material=e.material,t.convexPolyhedronRepresentation.material=t.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexConvex(e.convexPolyhedronRepresentation,t.convexPolyhedronRepresentation,n,r,i,a,o,s,e,t,u)}sphereBox(e,t,n,r,i,a,o,s,c,l,u){let d=this.v3pool,f=$n;n.vsub(r,Yn),t.getSideNormals(f,a);let p=e.radius,m=!1,h=tr,g=nr,_=rr,v=null,y=0,b=0,x=0,S=null;for(let e=0,t=f.length;e!==t&&m===!1;e++){let t=Xn;t.copy(f[e]);let n=t.length();t.normalize();let r=Yn.dot(t);if(r<n+p&&r>0){let i=Zn,a=Qn;i.copy(f[(e+1)%3]),a.copy(f[(e+2)%3]);let o=i.length(),s=a.length();i.normalize(),a.normalize();let c=Yn.dot(i),l=Yn.dot(a);if(c<o&&c>-o&&l<s&&l>-s){let e=Math.abs(r-n-p);if((S===null||e<S)&&(S=e,b=c,x=l,v=n,h.copy(t),g.copy(i),_.copy(a),y++,u))return!0}}}if(y){m=!0;let i=this.createContactEquation(o,s,e,t,c,l);h.scale(-p,i.ri),i.ni.copy(h),i.ni.negate(i.ni),h.scale(v,h),g.scale(b,g),h.vadd(g,h),_.scale(x,_),h.vadd(_,i.rj),i.ri.vadd(n,i.ri),i.ri.vsub(o.position,i.ri),i.rj.vadd(r,i.rj),i.rj.vsub(s.position,i.rj),this.result.push(i),this.createFrictionEquationsFromContact(i,this.frictionResult)}let C=d.get(),w=er;for(let i=0;i!==2&&!m;i++)for(let a=0;a!==2&&!m;a++)for(let d=0;d!==2&&!m;d++)if(C.set(0,0,0),i?C.vadd(f[0],C):C.vsub(f[0],C),a?C.vadd(f[1],C):C.vsub(f[1],C),d?C.vadd(f[2],C):C.vsub(f[2],C),r.vadd(C,w),w.vsub(n,w),w.lengthSquared()<p*p){if(u)return!0;m=!0;let i=this.createContactEquation(o,s,e,t,c,l);i.ri.copy(w),i.ri.normalize(),i.ni.copy(i.ri),i.ri.scale(p,i.ri),i.rj.copy(C),i.ri.vadd(n,i.ri),i.ri.vsub(o.position,i.ri),i.rj.vadd(r,i.rj),i.rj.vsub(s.position,i.rj),this.result.push(i),this.createFrictionEquationsFromContact(i,this.frictionResult)}d.release(C),C=null;let T=d.get(),E=d.get(),D=d.get(),O=d.get(),k=d.get(),A=f.length;for(let i=0;i!==A&&!m;i++)for(let a=0;a!==A&&!m;a++)if(i%3!=a%3){f[a].cross(f[i],T),T.normalize(),f[i].vadd(f[a],E),D.copy(n),D.vsub(E,D),D.vsub(r,D);let d=D.dot(T);T.scale(d,O);let h=0;for(;h===i%3||h===a%3;)h++;k.copy(n),k.vsub(O,k),k.vsub(E,k),k.vsub(r,k);let g=Math.abs(d),_=k.length();if(g<f[h].length()&&_<p){if(u)return!0;m=!0;let i=this.createContactEquation(o,s,e,t,c,l);E.vadd(O,i.rj),i.rj.copy(i.rj),k.negate(i.ni),i.ni.normalize(),i.ri.copy(i.rj),i.ri.vadd(r,i.ri),i.ri.vsub(n,i.ri),i.ri.normalize(),i.ri.scale(p,i.ri),i.ri.vadd(n,i.ri),i.ri.vsub(o.position,i.ri),i.rj.vadd(r,i.rj),i.rj.vsub(s.position,i.rj),this.result.push(i),this.createFrictionEquationsFromContact(i,this.frictionResult)}}d.release(T,E,D,O,k)}planeBox(e,t,n,r,i,a,o,s,c,l,u){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,t.convexPolyhedronRepresentation.id=t.id,this.planeConvex(e,t.convexPolyhedronRepresentation,n,r,i,a,o,s,e,t,u)}convexConvex(e,t,n,r,i,a,o,s,c,l,u,d,f){let p=vr;if(!(n.distanceTo(r)>e.boundingSphereRadius+t.boundingSphereRadius)&&e.findSeparatingAxis(t,n,i,r,a,p,d,f)){let d=[],f=yr;e.clipAgainstHull(n,i,t,r,a,p,-100,100,d);let m=0;for(let i=0;i!==d.length;i++){if(u)return!0;let a=this.createContactEquation(o,s,e,t,c,l),h=a.ri,g=a.rj;p.negate(a.ni),d[i].normal.negate(f),f.scale(d[i].depth,f),d[i].point.vadd(f,h),g.copy(d[i].point),h.vsub(n,h),g.vsub(r,g),h.vadd(n,h),h.vsub(o.position,h),g.vadd(r,g),g.vsub(s.position,g),this.result.push(a),m++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(a,this.frictionResult)}this.enableFrictionReduction&&m&&this.createFrictionFromAverage(m)}}sphereConvex(e,t,n,r,i,a,o,s,c,l,u){let d=this.v3pool;n.vsub(r,ir);let f=t.faceNormals,p=t.faces,m=t.vertices,h=e.radius,g=!1;for(let i=0;i!==m.length;i++){let d=m[i],f=cr;a.vmult(d,f),r.vadd(f,f);let p=sr;if(f.vsub(n,p),p.lengthSquared()<h*h){if(u)return!0;g=!0;let i=this.createContactEquation(o,s,e,t,c,l);i.ri.copy(p),i.ri.normalize(),i.ni.copy(i.ri),i.ri.scale(h,i.ri),f.vsub(r,i.rj),i.ri.vadd(n,i.ri),i.ri.vsub(o.position,i.ri),i.rj.vadd(r,i.rj),i.rj.vsub(s.position,i.rj),this.result.push(i),this.createFrictionEquationsFromContact(i,this.frictionResult);return}}for(let i=0,_=p.length;i!==_&&g===!1;i++){let _=f[i],v=p[i],y=lr;a.vmult(_,y);let b=ur;a.vmult(m[v[0]],b),b.vadd(r,b);let x=dr;y.scale(-h,x),n.vadd(x,x);let S=fr;x.vsub(b,S);let C=S.dot(y),w=pr;if(n.vsub(b,w),C<0&&w.dot(y)>0){let i=[];for(let e=0,t=v.length;e!==t;e++){let t=d.get();a.vmult(m[v[e]],t),r.vadd(t,t),i.push(t)}if(Jn(i,y,n)){if(u)return!0;g=!0;let a=this.createContactEquation(o,s,e,t,c,l);y.scale(-h,a.ri),y.negate(a.ni);let f=d.get();y.scale(-C,f);let p=d.get();y.scale(-h,p),n.vsub(r,a.rj),a.rj.vadd(p,a.rj),a.rj.vadd(f,a.rj),a.rj.vadd(r,a.rj),a.rj.vsub(s.position,a.rj),a.ri.vadd(n,a.ri),a.ri.vsub(o.position,a.ri),d.release(f),d.release(p),this.result.push(a),this.createFrictionEquationsFromContact(a,this.frictionResult);for(let e=0,t=i.length;e!==t;e++)d.release(i[e]);return}for(let f=0;f!==v.length;f++){let p=d.get(),g=d.get();a.vmult(m[v[(f+1)%v.length]],p),a.vmult(m[v[(f+2)%v.length]],g),r.vadd(p,p),r.vadd(g,g);let _=ar;g.vsub(p,_);let y=or;_.unit(y);let b=d.get(),x=d.get();n.vsub(p,x);let S=x.dot(y);y.scale(S,b),b.vadd(p,b);let C=d.get();if(b.vsub(n,C),S>0&&S*S<_.lengthSquared()&&C.lengthSquared()<h*h){if(u)return!0;let a=this.createContactEquation(o,s,e,t,c,l);b.vsub(r,a.rj),b.vsub(n,a.ni),a.ni.normalize(),a.ni.scale(h,a.ri),a.rj.vadd(r,a.rj),a.rj.vsub(s.position,a.rj),a.ri.vadd(n,a.ri),a.ri.vsub(o.position,a.ri),this.result.push(a),this.createFrictionEquationsFromContact(a,this.frictionResult);for(let e=0,t=i.length;e!==t;e++)d.release(i[e]);d.release(p),d.release(g),d.release(b),d.release(C),d.release(x);return}d.release(p),d.release(g),d.release(b),d.release(C),d.release(x)}for(let e=0,t=i.length;e!==t;e++)d.release(i[e])}}}planeConvex(e,t,n,r,i,a,o,s,c,l,u){let d=mr,f=hr;f.set(0,0,1),i.vmult(f,f);let p=0,m=gr;for(let i=0;i!==t.vertices.length;i++)if(d.copy(t.vertices[i]),a.vmult(d,d),r.vadd(d,d),d.vsub(n,m),f.dot(m)<=0){if(u)return!0;let i=this.createContactEquation(o,s,e,t,c,l),a=_r;f.scale(f.dot(m),a),d.vsub(a,a),a.vsub(n,i.ri),i.ni.copy(f),d.vsub(r,i.rj),i.ri.vadd(n,i.ri),i.ri.vsub(o.position,i.ri),i.rj.vadd(r,i.rj),i.rj.vsub(s.position,i.rj),this.result.push(i),p++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(i,this.frictionResult)}this.enableFrictionReduction&&p&&this.createFrictionFromAverage(p)}boxConvex(e,t,n,r,i,a,o,s,c,l,u){return e.convexPolyhedronRepresentation.material=e.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,this.convexConvex(e.convexPolyhedronRepresentation,t,n,r,i,a,o,s,e,t,u)}sphereHeightfield(e,t,n,r,i,a,o,s,c,l,u){let d=t.data,f=e.radius,p=t.elementSize,m=Nr,h=Mr;A.pointToLocalFrame(r,a,n,h);let g=Math.floor((h.x-f)/p)-1,_=Math.ceil((h.x+f)/p)+1,v=Math.floor((h.y-f)/p)-1,y=Math.ceil((h.y+f)/p)+1;if(_<0||y<0||g>d.length||v>d[0].length)return;g<0&&(g=0),_<0&&(_=0),v<0&&(v=0),y<0&&(y=0),g>=d.length&&(g=d.length-1),_>=d.length&&(_=d.length-1),y>=d[0].length&&(y=d[0].length-1),v>=d[0].length&&(v=d[0].length-1);let b=[];t.getRectMinMax(g,v,_,y,b);let x=b[0],S=b[1];if(h.z-f>S||h.z+f<x)return;let C=this.result;for(let c=g;c<_;c++)for(let l=v;l<y;l++){let d=C.length,f=!1;if(t.getConvexTrianglePillar(c,l,!1),A.pointToWorldFrame(r,a,t.pillarOffset,m),n.distanceTo(m)<t.pillarConvex.boundingSphereRadius+e.boundingSphereRadius&&(f=this.sphereConvex(e,t.pillarConvex,n,m,i,a,o,s,e,t,u)),u&&f||(t.getConvexTrianglePillar(c,l,!0),A.pointToWorldFrame(r,a,t.pillarOffset,m),n.distanceTo(m)<t.pillarConvex.boundingSphereRadius+e.boundingSphereRadius&&(f=this.sphereConvex(e,t.pillarConvex,n,m,i,a,o,s,e,t,u)),u&&f))return!0;if(C.length-d>2)return}}boxHeightfield(e,t,n,r,i,a,o,s,c,l,u){return e.convexPolyhedronRepresentation.material=e.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,this.convexHeightfield(e.convexPolyhedronRepresentation,t,n,r,i,a,o,s,e,t,u)}convexHeightfield(e,t,n,r,i,a,o,s,c,l,u){let d=t.data,f=t.elementSize,p=e.boundingSphereRadius,m=Ar,h=jr,g=kr;A.pointToLocalFrame(r,a,n,g);let _=Math.floor((g.x-p)/f)-1,v=Math.ceil((g.x+p)/f)+1,y=Math.floor((g.y-p)/f)-1,b=Math.ceil((g.y+p)/f)+1;if(v<0||b<0||_>d.length||y>d[0].length)return;_<0&&(_=0),v<0&&(v=0),y<0&&(y=0),b<0&&(b=0),_>=d.length&&(_=d.length-1),v>=d.length&&(v=d.length-1),b>=d[0].length&&(b=d[0].length-1),y>=d[0].length&&(y=d[0].length-1);let x=[];t.getRectMinMax(_,y,v,b,x);let S=x[0],C=x[1];if(!(g.z-p>C||g.z+p<S))for(let c=_;c<v;c++)for(let l=y;l<b;l++){let d=!1;if(t.getConvexTrianglePillar(c,l,!1),A.pointToWorldFrame(r,a,t.pillarOffset,m),n.distanceTo(m)<t.pillarConvex.boundingSphereRadius+e.boundingSphereRadius&&(d=this.convexConvex(e,t.pillarConvex,n,m,i,a,o,s,null,null,u,h,null)),u&&d||(t.getConvexTrianglePillar(c,l,!0),A.pointToWorldFrame(r,a,t.pillarOffset,m),n.distanceTo(m)<t.pillarConvex.boundingSphereRadius+e.boundingSphereRadius&&(d=this.convexConvex(e,t.pillarConvex,n,m,i,a,o,s,null,null,u,h,null)),u&&d))return!0}}sphereParticle(e,t,n,r,i,a,o,s,c,l,u){let d=Cr;if(d.set(0,0,1),r.vsub(n,d),d.lengthSquared()<=e.radius*e.radius){if(u)return!0;let n=this.createContactEquation(s,o,t,e,c,l);d.normalize(),n.rj.copy(d),n.rj.scale(e.radius,n.rj),n.ni.copy(d),n.ni.negate(n.ni),n.ri.set(0,0,0),this.result.push(n),this.createFrictionEquationsFromContact(n,this.frictionResult)}}planeParticle(e,t,n,r,i,a,o,s,c,l,u){let d=br;d.set(0,0,1),o.quaternion.vmult(d,d);let f=xr;if(r.vsub(o.position,f),d.dot(f)<=0){if(u)return!0;let n=this.createContactEquation(s,o,t,e,c,l);n.ni.copy(d),n.ni.negate(n.ni),n.ri.set(0,0,0);let i=Sr;d.scale(d.dot(r),i),r.vsub(i,i),n.rj.copy(i),this.result.push(n),this.createFrictionEquationsFromContact(n,this.frictionResult)}}boxParticle(e,t,n,r,i,a,o,s,c,l,u){return e.convexPolyhedronRepresentation.material=e.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,this.convexParticle(e.convexPolyhedronRepresentation,t,n,r,i,a,o,s,e,t,u)}convexParticle(e,t,n,r,i,a,o,s,c,l,u){let d=-1,f=Er,p=Or,m=null,h=Tr;if(h.copy(r),h.vsub(n,h),i.conjugate(wr),wr.vmult(h,h),e.pointIsInside(h)){e.worldVerticesNeedsUpdate&&e.computeWorldVertices(n,i),e.worldFaceNormalsNeedsUpdate&&e.computeWorldFaceNormals(i);for(let t=0,n=e.faces.length;t!==n;t++){let n=[e.worldVertices[e.faces[t][0]]],i=e.worldFaceNormals[t];r.vsub(n[0],Dr);let a=-i.dot(Dr);if(m===null||Math.abs(a)<Math.abs(m)){if(u)return!0;m=a,d=t,f.copy(i)}}if(d!==-1){let i=this.createContactEquation(s,o,t,e,c,l);f.scale(m,p),p.vadd(r,p),p.vsub(n,p),i.rj.copy(p),f.negate(i.ni),i.ri.set(0,0,0);let a=i.ri,u=i.rj;a.vadd(r,a),a.vsub(s.position,a),u.vadd(n,u),u.vsub(o.position,u),this.result.push(i),this.createFrictionEquationsFromContact(i,this.frictionResult)}else console.warn(`Point found inside convex, but did not find penetrating face!`)}}heightfieldCylinder(e,t,n,r,i,a,o,s,c,l,u){return this.convexHeightfield(t,e,r,n,a,i,s,o,c,l,u)}particleCylinder(e,t,n,r,i,a,o,s,c,l,u){return this.convexParticle(t,e,r,n,a,i,s,o,c,l,u)}sphereTrimesh(e,t,n,r,i,a,o,s,c,l,u){let d=Mn,f=Nn,p=Pn,m=Fn,h=In,g=Ln,_=Vn,v=jn,y=kn,b=Hn;A.pointToLocalFrame(r,a,n,h);let x=e.radius;_.lowerBound.set(h.x-x,h.y-x,h.z-x),_.upperBound.set(h.x+x,h.y+x,h.z+x),t.getTrianglesInAABB(_,b);let S=An,C=e.radius*e.radius;for(let i=0;i<b.length;i++)for(let d=0;d<3;d++)if(t.getVertex(t.indices[b[i]*3+d],S),S.vsub(h,y),y.lengthSquared()<=C){if(v.copy(S),A.pointToWorldFrame(r,a,v,S),S.vsub(n,y),u)return!0;let i=this.createContactEquation(o,s,e,t,c,l);i.ni.copy(y),i.ni.normalize(),i.ri.copy(i.ni),i.ri.scale(e.radius,i.ri),i.ri.vadd(n,i.ri),i.ri.vsub(o.position,i.ri),i.rj.copy(S),i.rj.vsub(s.position,i.rj),this.result.push(i),this.createFrictionEquationsFromContact(i,this.frictionResult)}for(let i=0;i<b.length;i++)for(let _=0;_<3;_++){t.getVertex(t.indices[b[i]*3+_],d),t.getVertex(t.indices[b[i]*3+(_+1)%3],f),f.vsub(d,p),h.vsub(f,g);let v=g.dot(p);h.vsub(d,g);let y=g.dot(p);if(y>0&&v<0&&(h.vsub(d,g),m.copy(p),m.normalize(),y=g.dot(m),m.scale(y,g),g.vadd(d,g),g.distanceTo(h)<e.radius)){if(u)return!0;let i=this.createContactEquation(o,s,e,t,c,l);g.vsub(h,i.ni),i.ni.normalize(),i.ni.scale(e.radius,i.ri),i.ri.vadd(n,i.ri),i.ri.vsub(o.position,i.ri),A.pointToWorldFrame(r,a,g,g),g.vsub(s.position,i.rj),A.vectorToWorldFrame(a,i.ni,i.ni),A.vectorToWorldFrame(a,i.ri,i.ri),this.result.push(i),this.createFrictionEquationsFromContact(i,this.frictionResult)}}let w=Rn,T=zn,E=Bn,D=On;for(let i=0,d=b.length;i!==d;i++){t.getTriangleVertices(b[i],w,T,E),t.getNormal(b[i],D),h.vsub(w,g);let d=g.dot(D);if(D.scale(d,g),h.vsub(g,g),d=g.distanceTo(h),F.pointInTriangle(g,w,T,E)&&d<e.radius){if(u)return!0;let i=this.createContactEquation(o,s,e,t,c,l);g.vsub(h,i.ni),i.ni.normalize(),i.ni.scale(e.radius,i.ri),i.ri.vadd(n,i.ri),i.ri.vsub(o.position,i.ri),A.pointToWorldFrame(r,a,g,g),g.vsub(s.position,i.rj),A.vectorToWorldFrame(a,i.ni,i.ni),A.vectorToWorldFrame(a,i.ri,i.ri),this.result.push(i),this.createFrictionEquationsFromContact(i,this.frictionResult)}}b.length=0}planeTrimesh(e,t,n,r,i,a,o,s,c,l,u){let d=new g,f=Tn;f.set(0,0,1),i.vmult(f,f);for(let i=0;i<t.vertices.length/3;i++){t.getVertex(i,d);let p=new g;p.copy(d),A.pointToWorldFrame(r,a,p,d);let m=En;if(d.vsub(n,m),f.dot(m)<=0){if(u)return!0;let n=this.createContactEquation(o,s,e,t,c,l);n.ni.copy(f);let r=Dn;f.scale(m.dot(f),r),d.vsub(r,r),n.ri.copy(r),n.ri.vsub(o.position,n.ri),n.rj.copy(d),n.rj.vsub(s.position,n.rj),this.result.push(n),this.createFrictionEquationsFromContact(n,this.frictionResult)}}}},H=new g,U=new g,W=new g,xn=new g,Sn=new g,Cn=new T,wn=new T,Tn=new g,En=new g,Dn=new g,On=new g,kn=new g;new g;var An=new g,jn=new g,Mn=new g,Nn=new g,Pn=new g,Fn=new g,In=new g,Ln=new g,Rn=new g,zn=new g,Bn=new g,Vn=new b,Hn=[],Un=new g,Wn=new g,Gn=new g,Kn=new g,qn=new g;function Jn(e,t,n){let r=null,i=e.length;for(let a=0;a!==i;a++){let o=e[a],s=Gn;e[(a+1)%i].vsub(o,s);let c=Kn;s.cross(t,c);let l=qn;n.vsub(o,l);let u=c.dot(l);if(r===null||u>0&&r===!0||u<=0&&r===!1)r===null&&(r=u>0);else return!1}return!0}var Yn=new g,Xn=new g,Zn=new g,Qn=new g,$n=[new g,new g,new g,new g,new g,new g],er=new g,tr=new g,nr=new g,rr=new g,ir=new g,ar=new g,or=new g,sr=new g,cr=new g,lr=new g,ur=new g,dr=new g,fr=new g,pr=new g;new g,new g;var mr=new g,hr=new g,gr=new g,_r=new g,vr=new g,yr=new g,br=new g,xr=new g,Sr=new g,Cr=new g,wr=new T,Tr=new g;new g;var Er=new g,Dr=new g,Or=new g,kr=new g,Ar=new g,jr=[0],Mr=new g,Nr=new g,Pr=class{constructor(){this.current=[],this.previous=[]}getKey(e,t){if(t<e){let n=t;t=e,e=n}return e<<16|t}set(e,t){let n=this.getKey(e,t),r=this.current,i=0;for(;n>r[i];)i++;if(n!==r[i]){for(let e=r.length-1;e>=i;e--)r[e+1]=r[e];r[i]=n}}tick(){let e=this.current;this.current=this.previous,this.previous=e,this.current.length=0}getDiff(e,t){let n=this.current,r=this.previous,i=n.length,a=r.length,o=0;for(let t=0;t<i;t++){let i=!1,a=n[t];for(;a>r[o];)o++;i=a===r[o],i||Fr(e,a)}o=0;for(let e=0;e<a;e++){let i=!1,a=r[e];for(;a>n[o];)o++;i=n[o]===a,i||Fr(t,a)}}};function Fr(e,t){e.push((t&4294901760)>>16,t&65535)}var Ir=(e,t)=>e<t?`${e}-${t}`:`${t}-${e}`,Lr=class{constructor(){this.data={keys:[]}}get(e,t){let n=Ir(e,t);return this.data[n]}set(e,t,n){let r=Ir(e,t);this.get(e,t)||this.data.keys.push(r),this.data[r]=n}delete(e,t){let n=Ir(e,t),r=this.data.keys.indexOf(n);r!==-1&&this.data.keys.splice(r,1),delete this.data[n]}reset(){let e=this.data,t=e.keys;for(;t.length>0;){let n=t.pop();delete e[n]}}},Rr=class extends w{constructor(e){e===void 0&&(e={}),super(),this.dt=-1,this.allowSleep=!!e.allowSleep,this.contacts=[],this.frictionEquations=[],this.quatNormalizeSkip=e.quatNormalizeSkip===void 0?0:e.quatNormalizeSkip,this.quatNormalizeFast=e.quatNormalizeFast!==void 0&&e.quatNormalizeFast,this.time=0,this.stepnumber=0,this.default_dt=1/60,this.nextId=0,this.gravity=new g,e.gravity&&this.gravity.copy(e.gravity),e.frictionGravity&&(this.frictionGravity=new g,this.frictionGravity.copy(e.frictionGravity)),this.broadphase=e.broadphase===void 0?new Ee:e.broadphase,this.bodies=[],this.hasActiveBodies=!1,this.solver=e.solver===void 0?new mn:e.solver,this.constraints=[],this.narrowphase=new bn(this),this.collisionMatrix=new C,this.collisionMatrixPrevious=new C,this.bodyOverlapKeeper=new Pr,this.shapeOverlapKeeper=new Pr,this.contactmaterials=[],this.contactMaterialTable=new Lr,this.defaultMaterial=new zt(`default`),this.defaultContactMaterial=new Rt(this.defaultMaterial,this.defaultMaterial,{friction:.3,restitution:0}),this.doProfiling=!1,this.profile={solve:0,makeContactConstraints:0,broadphase:0,integrate:0,narrowphase:0},this.accumulator=0,this.subsystems=[],this.addBodyEvent={type:`addBody`,body:null},this.removeBodyEvent={type:`removeBody`,body:null},this.idToBodyMap={},this.broadphase.setWorld(this)}getContactMaterial(e,t){return this.contactMaterialTable.get(e.id,t.id)}collisionMatrixTick(){let e=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=e,this.collisionMatrix.reset(),this.bodyOverlapKeeper.tick(),this.shapeOverlapKeeper.tick()}addConstraint(e){this.constraints.push(e)}removeConstraint(e){let t=this.constraints.indexOf(e);t!==-1&&this.constraints.splice(t,1)}rayTest(e,t,n){n instanceof De?this.raycastClosest(e,t,{skipBackfaces:!0},n):this.raycastAll(e,t,{skipBackfaces:!0},n)}raycastAll(e,t,n,r){return n===void 0&&(n={}),n.mode=F.ALL,n.from=e,n.to=t,n.callback=r,zr.intersectWorld(this,n)}raycastAny(e,t,n,r){return n===void 0&&(n={}),n.mode=F.ANY,n.from=e,n.to=t,n.result=r,zr.intersectWorld(this,n)}raycastClosest(e,t,n,r){return n===void 0&&(n={}),n.mode=F.CLOSEST,n.from=e,n.to=t,n.result=r,zr.intersectWorld(this,n)}addBody(e){this.bodies.includes(e)||(e.index=this.bodies.length,this.bodies.push(e),e.world=this,e.initPosition.copy(e.position),e.initVelocity.copy(e.velocity),e.timeLastSleepy=this.time,e instanceof P&&(e.initAngularVelocity.copy(e.angularVelocity),e.initQuaternion.copy(e.quaternion)),this.collisionMatrix.setNumObjects(this.bodies.length),this.addBodyEvent.body=e,this.idToBodyMap[e.id]=e,this.dispatchEvent(this.addBodyEvent))}removeBody(e){e.world=null;let t=this.bodies.length-1,n=this.bodies,r=n.indexOf(e);if(r!==-1){n.splice(r,1);for(let e=0;e!==n.length;e++)n[e].index=e;this.collisionMatrix.setNumObjects(t),this.removeBodyEvent.body=e,delete this.idToBodyMap[e.id],this.dispatchEvent(this.removeBodyEvent)}}getBodyById(e){return this.idToBodyMap[e]}getShapeById(e){let t=this.bodies;for(let n=0;n<t.length;n++){let r=t[n].shapes;for(let t=0;t<r.length;t++){let n=r[t];if(n.id===e)return n}}return null}addContactMaterial(e){this.contactmaterials.push(e),this.contactMaterialTable.set(e.materials[0].id,e.materials[1].id,e)}removeContactMaterial(e){let t=this.contactmaterials.indexOf(e);t!==-1&&(this.contactmaterials.splice(t,1),this.contactMaterialTable.delete(e.materials[0].id,e.materials[1].id))}fixedStep(e,t){e===void 0&&(e=1/60),t===void 0&&(t=10);let n=G.now()/1e3;if(!this.lastCallTime)this.step(e,void 0,t);else{let r=n-this.lastCallTime;this.step(e,r,t)}this.lastCallTime=n}step(e,t,n){if(n===void 0&&(n=10),t===void 0)this.internalStep(e),this.time+=e;else{this.accumulator+=t;let r=G.now(),i=0;for(;this.accumulator>=e&&i<n&&(this.internalStep(e),this.accumulator-=e,i++,!(G.now()-r>e*1e3)););this.accumulator%=e;let a=this.accumulator/e;for(let e=0;e!==this.bodies.length;e++){let t=this.bodies[e];t.previousPosition.lerp(t.position,a,t.interpolatedPosition),t.previousQuaternion.slerp(t.quaternion,a,t.interpolatedQuaternion),t.previousQuaternion.normalize()}this.time+=t}}internalStep(e){this.dt=e;let t=this.contacts,n=Gr,r=Kr,i=this.bodies.length,a=this.bodies,o=this.solver,s=this.gravity,c=this.doProfiling,l=this.profile,u=P.DYNAMIC,d=-1/0,f=this.constraints,p=Wr;s.length();let m=s.x,h=s.y,g=s.z,_=0;for(c&&(d=G.now()),_=0;_!==i;_++){let e=a[_];if(e.type===u){let t=e.force,n=e.mass;t.x+=n*m,t.y+=n*h,t.z+=n*g}}for(let e=0,t=this.subsystems.length;e!==t;e++)this.subsystems[e].update();c&&(d=G.now()),n.length=0,r.length=0,this.broadphase.collisionPairs(this,n,r),c&&(l.broadphase=G.now()-d);let v=f.length;for(_=0;_!==v;_++){let e=f[_];if(!e.collideConnected)for(let t=n.length-1;t>=0;--t)(e.bodyA===n[t]&&e.bodyB===r[t]||e.bodyB===n[t]&&e.bodyA===r[t])&&(n.splice(t,1),r.splice(t,1))}this.collisionMatrixTick(),c&&(d=G.now());let y=Ur,b=t.length;for(_=0;_!==b;_++)y.push(t[_]);t.length=0;let x=this.frictionEquations.length;for(_=0;_!==x;_++)p.push(this.frictionEquations[_]);for(this.frictionEquations.length=0,this.narrowphase.getContacts(n,r,this,t,y,this.frictionEquations,p),c&&(l.narrowphase=G.now()-d),c&&(d=G.now()),_=0;_<this.frictionEquations.length;_++)o.addEquation(this.frictionEquations[_]);let S=t.length;for(let e=0;e!==S;e++){let n=t[e],r=n.bi,i=n.bj,a=n.si,s=n.sj,c;c=r.material&&i.material&&this.getContactMaterial(r.material,i.material)||this.defaultContactMaterial,c.friction,r.material&&i.material&&(r.material.friction>=0&&i.material.friction>=0&&r.material.friction*i.material.friction,r.material.restitution>=0&&i.material.restitution>=0&&(n.restitution=r.material.restitution*i.material.restitution)),o.addEquation(n),r.allowSleep&&r.type===P.DYNAMIC&&r.sleepState===P.SLEEPING&&i.sleepState===P.AWAKE&&i.type!==P.STATIC&&i.velocity.lengthSquared()+i.angularVelocity.lengthSquared()>=i.sleepSpeedLimit**2*2&&(r.wakeUpAfterNarrowphase=!0),i.allowSleep&&i.type===P.DYNAMIC&&i.sleepState===P.SLEEPING&&r.sleepState===P.AWAKE&&r.type!==P.STATIC&&r.velocity.lengthSquared()+r.angularVelocity.lengthSquared()>=r.sleepSpeedLimit**2*2&&(i.wakeUpAfterNarrowphase=!0),this.collisionMatrix.set(r,i,!0),this.collisionMatrixPrevious.get(r,i)||(Hr.body=i,Hr.contact=n,r.dispatchEvent(Hr),Hr.body=r,i.dispatchEvent(Hr)),this.bodyOverlapKeeper.set(r.id,i.id),this.shapeOverlapKeeper.set(a.id,s.id)}for(this.emitContactEvents(),c&&(l.makeContactConstraints=G.now()-d,d=G.now()),_=0;_!==i;_++){let e=a[_];e.wakeUpAfterNarrowphase&&=(e.wakeUp(),!1)}for(v=f.length,_=0;_!==v;_++){let e=f[_];e.update();for(let t=0,n=e.equations.length;t!==n;t++){let n=e.equations[t];o.addEquation(n)}}o.solve(e,this),c&&(l.solve=G.now()-d),o.removeAllEquations();let C=Math.pow;for(_=0;_!==i;_++){let t=a[_];if(t.type&u){let n=C(1-t.linearDamping,e),r=t.velocity;r.scale(n,r);let i=t.angularVelocity;if(i){let n=C(1-t.angularDamping,e);i.scale(n,i)}}}this.dispatchEvent(Vr),c&&(d=G.now());let w=this.stepnumber%(this.quatNormalizeSkip+1)===0,T=this.quatNormalizeFast;for(_=0;_!==i;_++)a[_].integrate(e,w,T);this.clearForces(),this.broadphase.dirty=!0,c&&(l.integrate=G.now()-d),this.stepnumber+=1,this.dispatchEvent(Br);let E=!0;if(this.allowSleep)for(E=!1,_=0;_!==i;_++){let e=a[_];e.sleepTick(this.time),e.sleepState!==P.SLEEPING&&(E=!0)}this.hasActiveBodies=E}emitContactEvents(){let e=this.hasAnyEventListener(`beginContact`),t=this.hasAnyEventListener(`endContact`);if((e||t)&&this.bodyOverlapKeeper.getDiff(K,q),e){for(let e=0,t=K.length;e<t;e+=2)qr.bodyA=this.getBodyById(K[e]),qr.bodyB=this.getBodyById(K[e+1]),this.dispatchEvent(qr);qr.bodyA=qr.bodyB=null}if(t){for(let e=0,t=q.length;e<t;e+=2)Jr.bodyA=this.getBodyById(q[e]),Jr.bodyB=this.getBodyById(q[e+1]),this.dispatchEvent(Jr);Jr.bodyA=Jr.bodyB=null}K.length=q.length=0;let n=this.hasAnyEventListener(`beginShapeContact`),r=this.hasAnyEventListener(`endShapeContact`);if((n||r)&&this.shapeOverlapKeeper.getDiff(K,q),n){for(let e=0,t=K.length;e<t;e+=2){let t=this.getShapeById(K[e]),n=this.getShapeById(K[e+1]);J.shapeA=t,J.shapeB=n,t&&(J.bodyA=t.body),n&&(J.bodyB=n.body),this.dispatchEvent(J)}J.bodyA=J.bodyB=J.shapeA=J.shapeB=null}if(r){for(let e=0,t=q.length;e<t;e+=2){let t=this.getShapeById(q[e]),n=this.getShapeById(q[e+1]);Y.shapeA=t,Y.shapeB=n,t&&(Y.bodyA=t.body),n&&(Y.bodyB=n.body),this.dispatchEvent(Y)}Y.bodyA=Y.bodyB=Y.shapeA=Y.shapeB=null}}clearForces(){let e=this.bodies,t=e.length;for(let n=0;n!==t;n++){let t=e[n];t.force,t.torque,t.force.set(0,0,0),t.torque.set(0,0,0)}}};new b;var zr=new F,G=globalThis.performance||{};if(!G.now){let e=Date.now();G.timing&&G.timing.navigationStart&&(e=G.timing.navigationStart),G.now=()=>Date.now()-e}new g;var Br={type:`postStep`},Vr={type:`preStep`},Hr={type:P.COLLIDE_EVENT_NAME,body:null,contact:null},Ur=[],Wr=[],Gr=[],Kr=[],K=[],q=[],qr={type:`beginContact`,bodyA:null,bodyB:null},Jr={type:`endContact`,bodyA:null,bodyB:null},J={type:`beginShapeContact`,bodyA:null,bodyB:null,shapeA:null,shapeB:null},Y={type:`endShapeContact`,bodyA:null,bodyB:null,shapeA:null,shapeB:null};function Yr(e){let t=e.B.quaternion.conjugate().mult(e.A.quaternion).mult(e.rel0.conjugate()),n=t.x*e.axisB.x+t.y*e.axisB.y+t.z*e.axisB.z,r=2*Math.atan2(n,t.w);return r>Math.PI&&(r-=2*Math.PI),r<-Math.PI&&(r+=2*Math.PI),r}function Xr(e){let t=Yr(e),n=t>e.max?t-e.max:t<e.min?t-e.min:0;if(!n)return;let r=e.A.mass>0||e.B.mass<=0,i=r?e.A:e.B;if(i.mass<=0)return;let a=e.B.quaternion.vmult(e.axisB);a.normalize();let o=e.B.quaternion.vmult(e.pivotB).vadd(e.B.position),s=new T().setFromAxisAngle(a,r?-n:n),c=i.position.vsub(o);i.position.copy(s.vmult(c).vadd(o)),i.quaternion.copy(s.mult(i.quaternion)),i.quaternion.normalize();let l=e.A.angularVelocity.vsub(e.B.angularVelocity).dot(a);if(l*n>0){let e=a.scale(r?l:-l);i.angularVelocity.vsub(e,i.angularVelocity);let t=i.position.vsub(o);i.velocity.vsub(e.cross(t),i.velocity)}i.aabbNeedsUpdate=!0}var X=e=>[e.x,e.y,e.z],Zr=(e,t=[0,0,0])=>new g(...e??t),Qr=e=>e?new T(e[0],e[1],e[2],e[3]):new T,$r=.5,ei=.2,ti=.08,ni=.08,ri=.5,ii=48;function ai(e,t){let n=[],r=t?t.length:e.length/3,i=n=>{let r=(t?t[n]:n)*3;return new g(e[r],e[r+1],e[r+2])};for(let e=0;e+2<r;e+=3){let t=i(e),r=i(e+1),a=i(e+2),o=r.vsub(t).cross(a.vsub(t)),s=o.length();if(s<1e-9)continue;o.scale(ti/s,o);let c=t.vadd(r).vadd(a).scale(1/3).vsub(o.scale(.5)),l=new j({vertices:[t,r,a,t.vsub(o),r.vsub(o),a.vsub(o)].map(e=>e.vsub(c)),faces:[[0,1,2],[3,5,4],[0,3,4,1],[1,4,5,2],[2,5,3,0]]});n.push({shape:l,center:X(c)})}return n}function oi(e,t){if(e.length<=t)return e.length?[e]:[];let n=[1/0,1/0,1/0],r=[-1/0,-1/0,-1/0];for(let t of e)for(let e=0;e<3;e++)n[e]=Math.min(n[e],t.center[e]),r[e]=Math.max(r[e],t.center[e]);let i=[0,1,2].reduce((e,t)=>r[t]-n[t]>r[e]-n[e]?t:e,0),a=[...e].sort((e,t)=>e.center[i]-t.center[i]),o=a.length>>1;return[...oi(a.slice(0,o),t),...oi(a.slice(o),t)]}function si(e){let t=1/0;for(let n of e)if(n.type===`box`)t=Math.min(t,2*Math.min(...n.half));else if(n.type===`sphere`||n.type===`cylinder`||n.type===`capsule`)t=Math.min(t,2*n.radius);else if(n.type===`convex`){let e=[0,1,2].map(e=>Math.max(...n.vertices.map(t=>t[e]))-Math.min(...n.vertices.map(t=>t[e])));t=Math.min(t,...e)}return Number.isFinite(t)?Math.max(t,.01):1}var ci=class{world;recs=[];byId=/* @__PURE__ */ new Map;byBody=/* @__PURE__ */ new Map;order=0;materials=/* @__PURE__ */ new Map;materialProps=/* @__PURE__ */ new Map;namedMaterials;pairOverrides=/* @__PURE__ */ new Map;layerBits=/* @__PURE__ */ new Map;joints=[];contactsNow=/* @__PURE__ */ new Map;contactsPrev=/* @__PURE__ */ new Map;beginHandlers=[];endHandlers=[];substeps;time=0;preVel=/* @__PURE__ */ new Map;stepDt=1/60;constructor(e={}){let t=Array.isArray(e)?{gravity:e}:e;this.world=new Rr({gravity:Zr(t.gravity,[0,-9.81,0]),allowSleep:t.sleep??!0}),this.world.broadphase.useBoundingBoxes=!0,this.world.solver.iterations=t.iterations??10,this.world.defaultContactMaterial.friction=$r,this.world.defaultContactMaterial.restitution=ei,this.substeps=Math.min(8,Math.max(1,Math.round(t.substeps??1))),this.namedMaterials=t.materials??{};for(let e of t.contacts??[])this.pairOverrides.set([e.a,e.b].sort().join(`|`),e);this.layerBits.set(`default`,1);for(let e of t.layers??[])this.layerBit(e)}get bodies(){return this.recs.map(e=>e.view)}get(e){return this.byId.get(e)?.view}layerBit(e){let t=this.layerBits.get(e);if(t===void 0){if(this.layerBits.size>=16)return 1;t=1<<this.layerBits.size,this.layerBits.set(e,t)}return t}layerMask(e){return e?e.reduce((e,t)=>e|this.layerBit(t),0):-1}material(e,t,n){let r=`${e??``}|${t}|${n}`,i=this.materials.get(r);if(i)return i;i=new zt({friction:-1,restitution:-1}),this.materialProps.set(i,{name:e,friction:t,restitution:n}),this.materials.set(r,i);for(let e of this.materials.values()){let t=this.materialProps.get(i),n=this.materialProps.get(e),r=t.name&&n.name?this.pairOverrides.get([t.name,n.name].sort().join(`|`)):void 0;this.world.addContactMaterial(new Rt(i,e,{friction:r?.friction??Math.sqrt(t.friction*n.friction),restitution:r?.restitution??Math.max(t.restitution,n.restitution)}))}return i}add(e){let t=this.byId.get(e.id),n=t?[...this.contactsNow].filter(([,e])=>e.a===t||e.b===t):[],r=t?[...this.contactsPrev].filter(([,e])=>e.a===t||e.b===t):[];this.remove(e.id);let i=e.material?this.namedMaterials[e.material]:void 0,a=!!e.character,o=a?0:e.friction??i?.friction??$r,s=a?0:e.restitution??i?.restitution??ei,c=e.type,l=c===`dynamic`,u=l?Math.max(e.mass??1,1e-4):0,d=this.material(e.material,o,s),f=this.layerBit(e.layer??`default`),p=this.layerMask(e.collidesWith),m=()=>new P({mass:u,type:l?P.DYNAMIC:c===`static`?P.STATIC:P.KINEMATIC,position:Zr(e.position),quaternion:Qr(e.quaternion),material:d,isTrigger:c===`trigger`,linearDamping:e.linearDamping??.01,angularDamping:e.angularDamping??(a?1:.01),fixedRotation:a||!!e.fixedRotation,allowSleep:l&&!a&&e.sleep!==!1,sleepSpeedLimit:.12,sleepTimeLimit:.6,collisionFilterGroup:f,collisionFilterMask:p}),h=m(),_=[];for(let t of e.shapes)this.addShape(h,t,_,m);e.velocity&&h.velocity.set(...e.velocity),e.angularVelocity&&l&&h.angularVelocity.set(...e.angularVelocity),c===`kinematic`&&e.velocity&&h.velocity.set(...e.velocity),h.updateMassProperties(),this.world.addBody(h);for(let e of _)this.world.addBody(e);let v={id:e.id,type:c,shapes:e.shapes,main:h,extra:_,order:this.order++,gravityScale:e.gravityScale??1,ccd:!!e.ccd,character:a,minExtent:si(e.shapes),userVel:c===`kinematic`||c===`trigger`?h.velocity.clone():new g,kinFrom:null,forces:[],torques:[],lastGrounded:-1/0,jumpedAt:-1/0,ground:null,onGround:!1,carry:null,view:null};v.view=this.viewOf(v),this.recs.push(v),this.byId.set(v.id,v),this.byBody.set(h,v);for(let e of _)this.byBody.set(e,v);if(t){v.order=t.order,v.lastGrounded=t.lastGrounded,v.jumpedAt=t.jumpedAt,v.ground=t.ground,v.onGround=t.onGround,t.character&&this.makeCharacter(v);let e=e=>({...e,a:e.a===t?v:e.a,b:e.b===t?v:e.b});for(let[t,r]of n)this.contactsNow.set(t,e(r));for(let[t,n]of r)this.contactsPrev.set(t,e(n));for(let e of this.recs)e.ground===t&&(e.ground=v)}return v.view}viewOf(e){let t=this;return{id:e.id,type:e.type,shapes:e.shapes,get position(){return X(e.main.position)},get quaternion(){let t=e.main.quaternion;return[t.x,t.y,t.z,t.w]},get velocity(){return X(e.main.velocity)},get angularVelocity(){return X(e.main.angularVelocity)},get mass(){return e.main.mass},get sleeping(){return e.main.sleepState===P.SLEEPING},get grounded(){return t.isGrounded(e)},character:e.character}}addShape(e,t,n,r){let i=Zr(t.offset),a=Qr(t.quat);switch(t.type){case`box`:e.addShape(new ae(new g(Math.max(t.half[0],.001),Math.max(t.half[1],.001),Math.max(t.half[2],.001))),i,a);break;case`sphere`:e.addShape(new Qt(Math.max(t.radius,.001)),i,a);break;case`cylinder`:e.addShape(new $t(t.radius,t.radius,Math.max(t.height,.001),t.segments??16),i,a);break;case`capsule`:{let n=Math.max(t.radius,.001),r=Math.max(t.height-2*n,0);r>.001&&e.addShape(new $t(n,n,r,12),i,a);for(let t of r>.001?[1,-1]:[0]){let o=a.vmult(new g(0,t*r/2,0));e.addShape(new Qt(n),i.vadd(o),a)}break}case`convex`:{let n=new j({vertices:t.vertices.map(e=>new g(...e)),faces:t.faces});e.addShape(n,i,a);break}case`heightfield`:e.addShape(new en(t.data,{elementSize:t.elementSize}),i,a);break;case`trimesh`:oi(ai(t.vertices,t.indices),ii).forEach((t,o)=>{let s=o===0?e:r();for(let e of t)s.addShape(e.shape,i.vadd(a.vmult(new g(...e.center))),a);o>0&&n.push(s)})}}remove(e){let t=this.byId.get(e);if(t){for(let t of this.joints.filter(t=>t.a===e||t.b===e))this.removeJoint(t.id);this.world.removeBody(t.main);for(let e of t.extra)this.world.removeBody(e);this.byId.delete(e),this.byBody.delete(t.main);for(let e of t.extra)this.byBody.delete(e);this.recs.splice(this.recs.indexOf(t),1);for(let[e,n]of this.contactsNow)(n.a===t||n.b===t)&&this.contactsNow.delete(e);for(let[e,n]of this.contactsPrev)(n.a===t||n.b===t)&&this.contactsPrev.delete(e);for(let e of this.recs)e.ground===t&&(e.ground=null)}}setPose(e,t,n){let r=this.byId.get(e);if(!r)return;let i=r.main;r.type!==`kinematic`&&r.type!==`trigger`||r.kinFrom||(r.kinFrom={p:i.position.clone(),q:i.quaternion.clone()}),r.character&&Math.hypot(t[0]-i.position.x,t[1]-i.position.y,t[2]-i.position.z)>ri&&(r.ground=null,r.onGround=!1,r.lastGrounded=-1/0);for(let e of[i,...r.extra])e.position.set(...t),n&&e.quaternion.set(...n),e.previousPosition.copy(e.position),e.interpolatedPosition.copy(e.position),e.previousQuaternion.copy(e.quaternion),e.interpolatedQuaternion.copy(e.quaternion),e.aabbNeedsUpdate=!0;r.type===`dynamic`?i.wakeUp():this.wakeAround(r)}wakeAround(e){let t=this.aabb(e);if(t)for(let e of this.recs){if(e.type!==`dynamic`||e.main.sleepState!==P.SLEEPING)continue;let n=this.aabb(e);n&&n.overlaps(t)&&this.wakeIsland(e)}}aabb(e){let t=[e.main,...e.extra].filter(e=>e.shapes.length);if(!t.length)return null;let n=new b;return t.forEach((e,t)=>{e.aabbNeedsUpdate&&e.updateAABB(),t===0?n.copy(e.aabb):n.extend(e.aabb)}),n.lowerBound.vsub(new g(.001,.001,.001),n.lowerBound),n.upperBound.vadd(new g(.001,.001,.001),n.upperBound),n}setVelocity(e,t){let n=this.byId.get(e);n&&n.type!==`static`&&(n.main.velocity.set(...t),n.type!==`dynamic`&&n.userVel.set(...t),n.main.wakeUp())}setAngularVelocity(e,t){let n=this.byId.get(e);n&&n.type!==`static`&&(n.main.angularVelocity.set(...t),n.main.wakeUp())}applyImpulse(e,t,n){let r=this.byId.get(e);if(!r||r.type!==`dynamic`)return;let i=n?new g(...n).vsub(r.main.position):new g;r.main.applyImpulse(new g(...t),i),r.main.wakeUp()}applyForce(e,t,n){let r=this.byId.get(e);r&&r.type===`dynamic`&&(r.forces.push({f:new g(...t),p:n?new g(...n):null}),r.main.wakeUp())}applyTorque(e,t){let n=this.byId.get(e);n&&n.type===`dynamic`&&(n.torques.push(new g(...t)),n.main.wakeUp())}wake(e){this.byId.get(e)?.main.wakeUp()}addJoint(e){let t=this.byId.get(e.a),n=e.b?this.byId.get(e.b):void 0;if(!t||e.b&&!n)return null;let r=e.id??`joint-${this.joints.length+1}`,i=t.main,a=new g(...e.pivot??X(n?n.main.position:i.position)),o,s;n?s=n.main:(o=new P({mass:0,type:P.STATIC,position:a.clone(),collisionFilterGroup:0,collisionFilterMask:0}),this.world.addBody(o),s=o);let c=(e,t)=>e.quaternion.conjugate().vmult(t.vsub(e.position)),l=(e,t)=>e.quaternion.conjugate().vmult(t),u=e.maxForce??1e6,d=e.collideConnected??!1,f,p,m;switch(e.type){case`hinge`:{let t=new g(...e.axis??[0,1,0]);t.length()<1e-9&&t.set(0,1,0),t.normalize();let r=new Mt(i,s,{pivotA:c(i,a),pivotB:c(s,a),axisA:l(i,t),axisB:l(s,t),maxForce:u,collideConnected:d});e.limits&&(m={A:i,B:s,pivotB:c(s,a),axisB:l(s,t),rel0:s.quaternion.conjugate().mult(i.quaternion),min:Math.min(e.limits[0],e.limits[1]),max:Math.max(e.limits[0],e.limits[1])}),e.motor&&(r.enableMotor(),r.setMotorSpeed(n?e.motor.speed:-e.motor.speed),r.setMotorMaxForce(e.motor.maxForce??100)),f=r;break}case`point`:f=new Tt(i,c(i,a),s,c(s,a),u),f.collideConnected=d;break;case`distance`:{let t=e.distance??i.position.distanceTo(s.position);f=new kt(i,s,t,u),f.collideConnected=d;break}case`lock`:f=new At(i,s,{maxForce:u}),f.collideConnected=d;break;case`spring`:{let t=e.pivot&&n?c(i,a):new g,r=e.pivot?c(s,a):new g,o=i.quaternion.vmult(t).vadd(i.position),l=s.quaternion.vmult(r).vadd(s.position);p=new Bt(i,s,{localAnchorA:t,localAnchorB:r,restLength:e.restLength??o.distanceTo(l),stiffness:e.stiffness??50,damping:e.damping??1});break}}return f&&this.world.addConstraint(f),this.joints.push({id:r,a:e.a,b:e.b,constraint:f,spring:p,anchor:o,limit:m}),r}removeJoint(e){let t=this.joints.findIndex(t=>t.id===e);if(t<0)return;let n=this.joints[t];n.constraint&&this.world.removeConstraint(n.constraint),n.anchor&&this.world.removeBody(n.anchor),this.joints.splice(t,1)}setMotorSpeed(e,t){let n=this.joints.find(t=>t.id===e);n?.constraint instanceof Mt&&(n.constraint.enableMotor(),n.constraint.setMotorSpeed(n.b?t:-t),this.byId.get(n.a)?.main.wakeUp())}hasJoints(e){return this.joints.some(t=>t.a===e||t.b===e)}jointIds(){return this.joints.map(e=>e.id)}onCollision(e){this.beginHandlers.push(e)}onCollisionEnd(e){this.endHandlers.push(e)}isGrounded(e){return e.character?e.onGround:!!this.contactGround(e)}contactGround(e){let t=null;for(let n of this.contactsNow.values()){if(n.trigger)continue;let r=n.a===e&&-n.info.normal[1]>.5?n.b:n.b===e&&n.info.normal[1]>.5?n.a:null;if(r){if(r.type===`kinematic`)return r;t??=r}}return t}updateGround(e){let t=e.main,n=this.contactGround(e),r=this.time-e.jumpedAt<.15,i=t.velocity.y>1,a=r&&i?null:n;if(!a&&!i&&!r){let n=this.aabb(e);if(n){let r=[t.position.x,t.position.y,t.position.z],i=t.position.y-n.lowerBound.y+ni,o=this.raycast(r,[0,-1,0],i,{triggers:!1,mask:t.collisionFilterMask,ignore:t=>t.id===e.id});if(o&&o.normal[1]>.5&&(a=this.byId.get(o.body.id)??null,a)){let[t,n]=e.order<a.order?[e,a]:[a,e],r=`${t.id}|${n.id}`,i=o.normal;if(!this.contactsNow.has(r)){let a=t===e?[-i[0],-i[1],-i[2]]:[i[0],i[1],i[2]];this.contactsNow.set(r,{a:t,b:n,trigger:!1,info:{point:o.point,normal:a,impulse:0,speed:0}})}}}}e.ground=a,e.onGround=!!a}groundOf(e){let t=this.byId.get(e);if(!t)return null;let n=t.character?t.ground:this.contactGround(t);return n?n.view:null}grounded(e){let t=this.byId.get(e);return!!t&&this.isGrounded(t)}moveCharacter(e,t,n={}){let r=this.byId.get(e);if(!r||r.type===`static`)return;this.makeCharacter(r);let i=r.main,[a,o]=t,s=Math.hypot(a,o);s>1&&(a/=s,o/=s);let c=n.speed??5,l=(n.acceleration??40)*(this.isGrounded(r)||r.type!==`dynamic`?1:n.airControl??.35)*this.stepDt,u=(e,t)=>e+Math.max(-l,Math.min(l,t-e)),d=u(i.velocity.x,a*c),f=u(i.velocity.z,o*c);i.velocity.set(d,i.velocity.y,f),r.type!==`dynamic`&&r.userVel.set(d,i.velocity.y,f),i.wakeUp()}jump(e,t=6){let n=this.byId.get(e);return!n||n.type!==`dynamic`||(this.makeCharacter(n),!(this.isGrounded(n)||this.time-n.lastGrounded<=.12)||this.time-n.jumpedAt<.2)?!1:(n.jumpedAt=this.time,n.lastGrounded=-1/0,n.onGround=!1,n.main.velocity.y=t,n.main.wakeUp(),!0)}makeCharacter(e){if(e.character)return;e.character=!0,e.view.character=!0;let t=e.main;t.fixedRotation=!0,t.angularVelocity.set(0,0,0),t.allowSleep=!1,t.updateMassProperties();let n=t.material?this.materialProps.get(t.material):void 0;t.material=this.material(n?.name,0,0)}step(e){this.stepDt=e;let t=this.substeps;for(let n of this.recs){if(!n.ccd||n.main.sleepState===P.SLEEPING)continue;let r=n.main.velocity.length()*e;t=Math.max(t,Math.min(8,Math.ceil(r/(.5*n.minExtent))))}let n=e/t;this.wakeAhead(e);let r=[];for(let t of this.recs){if(!t.kinFrom)continue;let n={p:t.main.position.clone(),q:t.main.quaternion.clone()},i=n.p.vsub(t.kinFrom.p);if(i.length()<2.5&&t.type===`kinematic`){for(let e of[t.main,...t.extra])e.position.copy(t.kinFrom.p),e.quaternion.copy(t.kinFrom.q);t.main.velocity.copy(i.scale(1/e).vadd(t.userVel));let a=n.q.mult(t.kinFrom.q.conjugate());a.w<0&&a.set(-a.x,-a.y,-a.z,-a.w);let o=Math.sqrt(Math.max(0,1-a.w*a.w)),s=2*Math.acos(Math.min(1,a.w));o>1e-6?t.main.angularVelocity.set(a.x/o*s/e,a.y/o*s/e,a.z/o*s/e):t.main.angularVelocity.set(0,0,0);for(let e of t.extra)e.velocity.copy(t.main.velocity),e.angularVelocity.copy(t.main.angularVelocity);r.push({rec:t,...n})}t.kinFrom=null}for(let e of this.recs){if(e.carry=null,!e.character||e.type!==`dynamic`||!e.onGround||e.ground?.type!==`kinematic`)continue;let t=e.ground.main,n=e.main.position.vsub(t.position),r=t.velocity.vadd(t.angularVelocity.cross(n));r.lengthSquared()<1e-10||(e.carry=r,e.main.velocity.vadd(r,e.main.velocity))}let i=/* @__PURE__ */ new Map,a=this.world.gravity;for(let e=0;e<t;e++){for(let e of this.recs){if(e.type!==`dynamic`)continue;let t=e.main;e.gravityScale!==1&&t.force.vadd(a.scale(t.mass*(e.gravityScale-1)),t.force);for(let n of e.forces)t.applyForce(n.f,n.p?n.p.vsub(t.position):new g);for(let n of e.torques)t.torque.vadd(n,t.torque)}for(let e of this.joints)e.spring?.applyForce();this.preVel.clear();for(let e of this.recs)e.type!==`static`&&this.preVel.set(e,e.main.velocity.clone());this.world.step(n);for(let e of this.joints)e.limit&&Xr(e.limit);this.time+=n,this.collectContacts(i,n)}for(let e of this.recs)e.forces=[],e.torques=[];for(let e of this.recs)e.carry&&e.main.velocity.vsub(e.carry,e.main.velocity);for(let e of r)for(let t of[e.rec.main,...e.rec.extra])t.position.copy(e.p),t.quaternion.copy(e.q),t.velocity.copy(e.rec.userVel),t.angularVelocity.set(0,0,0),t.aabbNeedsUpdate=!0;for(let e of this.recs)if(e.type===`trigger`)for(let t of this.recs){if(t===e||t.type===`dynamic`||t.type===`trigger`||t.type===`static`||!this.filterOk(e,t))continue;let[n,r]=e.order<t.order?[e,t]:[t,e],a=`${n.id}|${r.id}`;if(i.has(a)||!this.overlapRecs(n,r))continue;let o=n.main.position,s=r.main.position,c=s.vsub(o),l=c.length()||1;i.set(a,{a:n,b:r,trigger:!0,info:{point:X(o.vadd(s).scale(.5)),normal:[c.x/l,c.y/l,c.z/l],impulse:0,speed:0}})}let o=e=>e.type===`static`||e.main.sleepState===P.SLEEPING;for(let[e,t]of this.contactsNow)!i.has(e)&&o(t.a)&&o(t.b)&&this.byId.has(t.a.id)&&this.byId.has(t.b.id)&&i.set(e,{...t,info:{...t.info,impulse:0,speed:0}});this.contactsPrev=this.contactsNow,this.contactsNow=i;for(let e of this.recs)e.character&&this.updateGround(e),this.isGrounded(e)&&(e.lastGrounded=this.time);for(let[e,t]of i)if(!this.contactsPrev.has(e))for(let e of this.beginHandlers)e(t.a.view,t.b.view,t.info);for(let[e,t]of this.contactsPrev)if(!i.has(e)&&this.byId.has(t.a.id)&&this.byId.has(t.b.id))for(let e of this.endHandlers)e(t.a.view,t.b.view)}wakeAhead(e){let t=null;for(let n of this.recs){if(n.type===`static`||n.type===`trigger`||n.main.sleepState===P.SLEEPING)continue;let r=n.main.velocity;if(r.length()<.5)continue;let i=this.aabb(n);if(!i)continue;if(!t){t=[];for(let e of this.recs){if(e.type!==`dynamic`||e.main.sleepState!==P.SLEEPING)continue;let n=this.aabb(e);n&&t.push({r:e,box:n})}}if(!t.length)return;let a=new g(Math.abs(r.x)*e*2+.05,Math.abs(r.y)*e*2+.05,Math.abs(r.z)*e*2+.05);i.lowerBound.vsub(a,i.lowerBound),i.upperBound.vadd(a,i.upperBound);for(let e of t)e.r.main.sleepState===P.SLEEPING&&e.box.overlaps(i)&&this.wakeIsland(e.r)}}wakeIsland(e){let t=[e];for(e.main.wakeUp();t.length;){let e=t.pop();for(let n of this.contactsNow.values()){let r=n.a===e?n.b:n.b===e?n.a:null;r&&r.type===`dynamic`&&r.main.sleepState===P.SLEEPING&&(r.main.wakeUp(),t.push(r))}}}filterOk(e,t){return(e.main.collisionFilterGroup&t.main.collisionFilterMask)!==0&&(t.main.collisionFilterGroup&e.main.collisionFilterMask)!==0}collectContacts(e,t){for(let n of this.world.contacts){let r=this.byBody.get(n.bi),i=this.byBody.get(n.bj);if(!r||!i||r===i)continue;let a=X(n.ni),o=X(n.bi.position.vadd(n.ri));i.order<r.order&&([r,i]=[i,r],a=[-a[0],-a[1],-a[2]],o=X(n.bj.position.vadd(n.rj)));let s=`${r.id}|${i.id}`,c=Math.abs(n.multiplier)*t,l=e.get(s);if(l){c>l.info.impulse&&(l.info.impulse=c);continue}let u=new g,d=(this.preVel.get(i)??u).vsub(this.preVel.get(r)??u),f=Math.max(0,-(d.x*a[0]+d.y*a[1]+d.z*a[2]));e.set(s,{a:r,b:i,trigger:r.type===`trigger`||i.type===`trigger`,info:{point:o,normal:a,impulse:c,speed:this.contactsPrev.has(s)?0:f}})}}contacts(){return[...this.contactsNow.values()].map(e=>({a:e.a.view,b:e.b.view,info:e.info,trigger:e.trigger}))}contactsOf(e){let t=[];for(let n of this.contactsNow.values())n.a.id===e?t.push(n.b.view):n.b.id===e&&t.push(n.a.view);return t}overlaps(e,t){let n=this.byId.get(e),r=this.byId.get(t);return!n||!r||n===r?!1:this.overlapRecs(n,r)}overlapRecs(e,t){let n=this.aabb(e),r=this.aabb(t);if(!n||!r||!n.overlaps(r))return!1;for(let n of[e.main,...e.extra])for(let e of[t.main,...t.extra])if(this.bodiesOverlap(n,e))return!0;return!1}bodiesOverlap(e,t){let n=this.world.narrowphase,r=new T,i=new T,a=new g,o=new g;for(let s=0;s<e.shapes.length;s++){e.quaternion.mult(e.shapeOrientations[s],r),e.quaternion.vmult(e.shapeOffsets[s],a),a.vadd(e.position,a);let c=e.shapes[s];for(let s=0;s<t.shapes.length;s++){t.quaternion.mult(t.shapeOrientations[s],i),t.quaternion.vmult(t.shapeOffsets[s],o),o.vadd(t.position,o);let l=t.shapes[s];if(a.distanceTo(o)>c.boundingSphereRadius+l.boundingSphereRadius+.001)continue;let u=n[c.type|l.type];if(u&&(c.type<l.type?u.call(n,c,l,a,o,r,i,e,t,c,l,!0):u.call(n,l,c,o,a,i,r,t,e,c,l,!0)))return!0}}return!1}raycast(e,t,n=1/0,r={}){let i=Math.hypot(t[0],t[1],t[2]);if(i<1e-12)return null;let a=Number.isFinite(n)?n:1e4,o=[t[0]/i,t[1]/i,t[2]/i],s=new g(...e),c=new g(e[0]+o[0]*a,e[1]+o[1]*a,e[2]+o[2]*a),l=null;return this.world.raycastAll(s,c,{skipBackfaces:!0,collisionFilterMask:r.mask??-1,checkCollisionResponse:!1},e=>{let t=this.byBody.get(e.body);!t||r.triggers===!1&&t.type===`trigger`||r.ignore?.(t.view)||l&&e.distance>=l.distance||(l={body:t.view,distance:e.distance,point:X(e.hitPointWorld),normal:X(e.hitNormalWorld)})}),l}},li={dynamic:4054148,static:5155071,kinematic:16755008,trigger:16732120,sleeping:10133670};function Z(e,t,n,r=0,i=24){for(let a=0;a<i;a++){let o=a/i*Math.PI*2,s=(a+1)/i*Math.PI*2,c=e=>n===`y`?[Math.cos(e)*t,r,Math.sin(e)*t]:n===`x`?[r,Math.cos(e)*t,Math.sin(e)*t]:[Math.cos(e)*t,Math.sin(e)*t,r];e.push(...c(o),...c(s))}}function ui(e){let t=[];switch(e.type){case`box`:{let[n,r,i]=e.half,a=[[-n,-r,-i],[n,-r,-i],[n,r,-i],[-n,r,-i],[-n,-r,i],[n,-r,i],[n,r,i],[-n,r,i]];for(let[e,n]of[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]])t.push(...a[e],...a[n]);break}case`sphere`:Z(t,e.radius,`x`),Z(t,e.radius,`y`),Z(t,e.radius,`z`);break;case`cylinder`:case`capsule`:{let n=e.radius,r=e.type===`capsule`?Math.max(e.height-2*n,0):e.height;Z(t,n,`y`,r/2),Z(t,n,`y`,-r/2);for(let e=0;e<8;e++){let i=e/8*Math.PI*2;t.push(Math.cos(i)*n,-r/2,Math.sin(i)*n,Math.cos(i)*n,r/2,Math.sin(i)*n)}if(e.type===`capsule`)for(let e of[1,-1])for(let i=0;i<12;i++){let a=i/12*(Math.PI/2),o=(i+1)/12*(Math.PI/2);for(let[i,s]of[[1,0],[0,1],[-1,0],[0,-1]])t.push(i*Math.cos(a)*n,e*(r/2+Math.sin(a)*n),s*Math.cos(a)*n,i*Math.cos(o)*n,e*(r/2+Math.sin(o)*n),s*Math.cos(o)*n)}break}case`convex`:for(let n of e.faces)for(let r=0;r<n.length;r++)t.push(...e.vertices[n[r]],...e.vertices[n[(r+1)%n.length]]);break;case`trimesh`:{let n=e.vertices,r=e.indices,i=r?r.length:n.length/3,a=e=>{let t=(r?r[e]:e)*3;return[n[t],n[t+1],n[t+2]]};for(let e=0;e+2<i;e+=3){let n=a(e),r=a(e+1),i=a(e+2);t.push(...n,...r,...r,...i,...i,...n)}break}case`heightfield`:{let n=e.data,r=e.elementSize,i=Math.max(1,Math.round(n.length/48));for(let e=0;e<n.length;e+=i)for(let a=0;a+i<n[e].length;a+=i)t.push(e*r,a*r,n[e][a],e*r,(a+i)*r,n[e][a+i]);for(let e=0;e<n[0].length;e+=i)for(let a=0;a+i<n.length;a+=i)t.push(a*r,e*r,n[a][e],(a+i)*r,e*r,n[a+i][e]);break}}if(e.offset||e.quat){let n=new f().compose(new a(...e.offset??[0,0,0]),new o(...e.quat??[0,0,0,1]),new a(1,1,1)),r=new a;for(let e=0;e<t.length;e+=3)r.set(t[e],t[e+1],t[e+2]).applyMatrix4(n),t[e]=r.x,t[e+1]=r.y,t[e+2]=r.z}return t}var di=class{group=new n;items=/* @__PURE__ */ new Map;constructor(e){this.group.name=`agent3d-physics-debug`,this.group.renderOrder=999,e.add(this.group)}sync(e){let n=/* @__PURE__ */ new Set;for(let r of e){n.add(r.id);let e=this.items.get(r.id);if(!e||e.body!==r){e&&this.drop(r.id);let n=r.shapes.flatMap(ui),i=new l;i.setAttribute(`position`,new t(n,3));let a=new d({color:li[r.type],depthTest:!1,depthWrite:!1,transparent:!0,opacity:.9,toneMapped:!1}),o=new s(i,a);o.renderOrder=999,o.frustumCulled=!1,this.group.add(o),e={lines:o,body:r},this.items.set(r.id,e)}let[i,a,o]=r.position,[c,u,f,p]=r.quaternion;e.lines.position.set(i,a,o),e.lines.quaternion.set(c,u,f,p),e.lines.material.color.setHex(r.sleeping?li.sleeping:li[r.type])}for(let e of[...this.items.keys()])n.has(e)||this.drop(e)}drop(e){let t=this.items.get(e);t&&(t.lines.removeFromParent(),t.lines.geometry.dispose(),t.lines.material.dispose(),this.items.delete(e))}dispose(){for(let e of[...this.items.keys()])this.drop(e);this.group.removeFromParent()}},fi=0,pi=1,mi=new a,hi=new u,gi=new r,_i=new a,vi=new p,yi=class{constructor(){this.tolerance=-1,this.faces=[],this.newFaces=[],this.assigned=new Si,this.unassigned=new Si,this.vertices=[]}setFromPoints(e){if(e.length>=4){this.makeEmpty();for(let t=0,n=e.length;t<n;t++)this.vertices.push(new xi(e[t]));this._compute()}return this}setFromObject(e){let t=[];return e.updateMatrixWorld(!0),e.traverse(function(e){let n=e.geometry;if(n!==void 0){let r=n.attributes.position;if(r!==void 0)for(let n=0,i=r.count;n<i;n++){let i=new a;i.fromBufferAttribute(r,n).applyMatrix4(e.matrixWorld),t.push(i)}}}),this.setFromPoints(t)}containsPoint(e){let t=this.faces;for(let n=0,r=t.length;n<r;n++)if(t[n].distanceToPoint(e)>this.tolerance)return!1;return!0}intersectRay(e,t){let n=this.faces,r=-1/0,i=1/0;for(let t=0,a=n.length;t<a;t++){let a=n[t],o=a.distanceToPoint(e.origin),s=a.normal.dot(e.direction);if(o>0&&s>=0)return null;let c=s===0?0:-o/s;if(!(c<=0)&&(s>0?i=Math.min(c,i):r=Math.max(c,r),r>i))return null}return r===-1/0?e.at(i,t):e.at(r,t),t}intersectsRay(e){return this.intersectRay(e,mi)!==null}makeEmpty(){return this.faces=[],this.vertices=[],this}_addVertexToFace(e,t){return e.face=t,t.outside===null?this.assigned.append(e):this.assigned.insertBefore(t.outside,e),t.outside=e,this}_removeVertexFromFace(e,t){return e===t.outside&&(t.outside=e.next!==null&&e.next.face===t?e.next:null),this.assigned.remove(e),this}_removeAllVerticesFromFace(e){if(e.outside!==null){let t=e.outside,n=e.outside;for(;n.next!==null&&n.next.face===e;)n=n.next;return this.assigned.removeSubList(t,n),t.prev=n.next=null,e.outside=null,t}}_deleteFaceVertices(e,t){let n=this._removeAllVerticesFromFace(e);if(n!==void 0){if(t===void 0)this.unassigned.appendChain(n);else{let e=n;do{let n=e.next;t.distanceToPoint(e.point)>this.tolerance?this._addVertexToFace(e,t):this.unassigned.append(e),e=n}while(e!==null)}}return this}_resolveUnassignedPoints(e){if(this.unassigned.isEmpty()===!1){let t=this.unassigned.first();do{let n=t.next,r=this.tolerance,i=null;for(let n=0;n<e.length;n++){let a=e[n];if(a.mark===fi){let e=a.distanceToPoint(t.point);if(e>r&&(r=e,i=a),r>1e3*this.tolerance)break}}i!==null&&this._addVertexToFace(t,i),t=n}while(t!==null)}return this}_computeExtremes(){let e=new a,t=new a,n=[],r=[];for(let e=0;e<3;e++)n[e]=r[e]=this.vertices[0];e.copy(this.vertices[0].point),t.copy(this.vertices[0].point);for(let i=0,a=this.vertices.length;i<a;i++){let a=this.vertices[i],o=a.point;for(let t=0;t<3;t++)o.getComponent(t)<e.getComponent(t)&&(e.setComponent(t,o.getComponent(t)),n[t]=a);for(let e=0;e<3;e++)o.getComponent(e)>t.getComponent(e)&&(t.setComponent(e,o.getComponent(e)),r[e]=a)}return this.tolerance=3*2**-52*(Math.max(Math.abs(e.x),Math.abs(t.x))+Math.max(Math.abs(e.y),Math.abs(t.y))+Math.max(Math.abs(e.z),Math.abs(t.z))),{min:n,max:r}}_computeInitialHull(){let e=this.vertices,t=this._computeExtremes(),n=t.min,r=t.max,i=0,a=0;for(let e=0;e<3;e++){let t=r[e].point.getComponent(e)-n[e].point.getComponent(e);t>i&&(i=t,a=e)}let o=n[a],s=r[a],c,l;i=0,hi.set(o.point,s.point);for(let t=0,n=this.vertices.length;t<n;t++){let n=e[t];if(n!==o&&n!==s){hi.closestPointToPoint(n.point,!0,_i);let e=_i.distanceToSquared(n.point);e>i&&(i=e,c=n)}}i=-1,gi.setFromCoplanarPoints(o.point,s.point,c.point);for(let t=0,n=this.vertices.length;t<n;t++){let n=e[t];if(n!==o&&n!==s&&n!==c){let e=Math.abs(gi.distanceToPoint(n.point));e>i&&(i=e,l=n)}}let u=[];if(gi.distanceToPoint(l.point)<0){u.push(Q.create(o,s,c),Q.create(l,s,o),Q.create(l,c,s),Q.create(l,o,c));for(let e=0;e<3;e++){let t=(e+1)%3;u[e+1].getEdge(2).setTwin(u[0].getEdge(t)),u[e+1].getEdge(1).setTwin(u[t+1].getEdge(0))}}else{u.push(Q.create(o,c,s),Q.create(l,o,s),Q.create(l,s,c),Q.create(l,c,o));for(let e=0;e<3;e++){let t=(e+1)%3;u[e+1].getEdge(2).setTwin(u[0].getEdge((3-e)%3)),u[e+1].getEdge(0).setTwin(u[t+1].getEdge(1))}}for(let e=0;e<4;e++)this.faces.push(u[e]);for(let t=0,n=e.length;t<n;t++){let n=e[t];if(n!==o&&n!==s&&n!==c&&n!==l){i=this.tolerance;let e=null;for(let t=0;t<4;t++){let r=this.faces[t].distanceToPoint(n.point);r>i&&(i=r,e=this.faces[t])}e!==null&&this._addVertexToFace(n,e)}}return this}_reindexFaces(){let e=[];for(let t=0;t<this.faces.length;t++){let n=this.faces[t];n.mark===fi&&e.push(n)}return this.faces=e,this}_nextVertexToAdd(){if(this.assigned.isEmpty()===!1){let e,t=0,n=this.assigned.first().face,r=n.outside;do{let i=n.distanceToPoint(r.point);i>t&&(t=i,e=r),r=r.next}while(r!==null&&r.face===n);return e}}_computeHorizon(e,t,n,r){this._deleteFaceVertices(n),n.mark=pi;let i;i=t===null?t=n.getEdge(0):t.next;do{let t=i.twin,n=t.face;n.mark===fi&&(n.distanceToPoint(e)>this.tolerance?this._computeHorizon(e,t,n,r):r.push(i)),i=i.next}while(i!==t);return this}_addAdjoiningFace(e,t){let n=Q.create(e,t.tail(),t.head());return this.faces.push(n),n.getEdge(-1).setTwin(t.twin),n.getEdge(0)}_addNewFaces(e,t){this.newFaces=[];let n=null,r=null;for(let i=0;i<t.length;i++){let a=t[i],o=this._addAdjoiningFace(e,a);n===null?n=o:o.next.setTwin(r),this.newFaces.push(o.face),r=o}return n.next.setTwin(r),this}_addVertexToHull(e){let t=[];return this.unassigned.clear(),this._removeVertexFromFace(e,e.face),this._computeHorizon(e.point,null,e.face,t),this._addNewFaces(e,t),this._resolveUnassignedPoints(this.newFaces),this}_cleanup(){return this.assigned.clear(),this.unassigned.clear(),this.newFaces=[],this}_compute(){let e;for(this._computeInitialHull();(e=this._nextVertexToAdd())!==void 0;)this._addVertexToHull(e);return this._reindexFaces(),this._cleanup(),this}},Q=class e{constructor(){this.normal=new a,this.midpoint=new a,this.area=0,this.constant=0,this.outside=null,this.mark=fi,this.edge=null}static create(t,n,r){let i=new e,a=new bi(t,i),o=new bi(n,i),s=new bi(r,i);return a.next=s.prev=o,o.next=a.prev=s,s.next=o.prev=a,i.edge=a,i.compute()}getEdge(e){let t=this.edge;for(;e>0;)t=t.next,e--;for(;e<0;)t=t.prev,e++;return t}compute(){let e=this.edge.tail(),t=this.edge.head(),n=this.edge.next.head();return vi.set(e.point,t.point,n.point),vi.getNormal(this.normal),vi.getMidpoint(this.midpoint),this.area=vi.getArea(),this.constant=this.normal.dot(this.midpoint),this}distanceToPoint(e){return this.normal.dot(e)-this.constant}},bi=class{constructor(e,t){this.vertex=e,this.prev=null,this.next=null,this.twin=null,this.face=t}head(){return this.vertex}tail(){return this.prev?this.prev.vertex:null}length(){let e=this.head(),t=this.tail();return t===null?-1:t.point.distanceTo(e.point)}lengthSquared(){let e=this.head(),t=this.tail();return t===null?-1:t.point.distanceToSquared(e.point)}setTwin(e){return this.twin=e,e.twin=this,this}},xi=class{constructor(e){this.point=e,this.prev=null,this.next=null,this.face=null}},Si=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(e,t){return t.prev=e.prev,t.next=e,t.prev===null?this.head=t:t.prev.next=t,e.prev=t,this}insertAfter(e,t){return t.prev=e,t.next=e.next,t.next===null?this.tail=t:t.next.prev=t,e.next=t,this}append(e){return this.head===null?this.head=e:this.tail.next=e,e.prev=this.tail,e.next=null,this.tail=e,this}appendChain(e){for(this.head===null?this.head=e:this.tail.next=e,e.prev=this.tail;e.next!==null;)e=e.next;return this.tail=e,this}remove(e){return e.prev===null?this.head=e.next:e.prev.next=e.next,e.next===null?this.tail=e.prev:e.next.prev=e.prev,this}removeSubList(e,t){return e.prev===null?this.head=t.next:e.prev.next=t.next,t.next===null?this.tail=e.prev:t.next.prev=e.prev,this}isEmpty(){return this.head===null}},Ci=12e3,wi=600;function Ti(e){e.updateWorldMatrix(!0,!0);let t=new a,n=new o,r=new a;return e.matrixWorld.decompose(t,n,r),{inv:new f().compose(t,n,new a(1,1,1)).invert(),scale:r}}function Ei(e,t){let n=e.userData?.a3dId;return!!n&&n!==t&&!n.includes(`/`)}function $(e,t=`own`,n){let r=[],i=e.userData?.a3dId,a=o=>{if(o!==e&&(t===`own`&&Ei(o,i)||n?.(o)))return;let s=o;s.isMesh&&s.geometry?.getAttribute(`position`)&&!o.userData.noCollide&&r.push(s);for(let e of o.children)a(e)};return a(e),r}function Di(e){let t=$(e.object);return t.length?t:$(e.object,`tree`,Oi(e.objectDef))}function Oi(e){let t=/* @__PURE__ */ new Set,n=e=>{for(let r of e??[])r.body&&t.add(r.id),n(r.children)};return n(e?.children),e=>t.has(e.userData?.a3dId)}function ki(e,t){let n=new c,r=new c,i=new f;for(let a of e){let e=a;e.isInstancedMesh?(e.boundingBox||e.computeBoundingBox(),e.boundingBox&&r.copy(e.boundingBox)):(a.geometry.boundingBox||a.geometry.computeBoundingBox(),r.copy(a.geometry.boundingBox)),r.isEmpty()||n.union(r.applyMatrix4(i.multiplyMatrices(t,a.matrixWorld)))}return n}function Ai(e,t){return ki(Di({object:e,objectDef:t}),Ti(e).inv)}function ji(e,t){let{inv:n}=Ti(e),r=[ki($(e),n)],i=Oi(t),o=e.userData?.a3dId,s=e=>{for(let t of e.children)i(t)||(Ei(t,o)?r.push(ki($(t,`tree`,i),n)):s(t))};return s(e),r.filter(e=>!e.isEmpty()).map(e=>({size:e.getSize(new a),center:e.getCenter(new a)}))}function Mi(e,t){let{inv:n}=Ti(e.object),r=new f,i=new a,o=[],s=0;for(let a of Di(e)){if(a.isInstancedMesh)continue;let e=a.geometry,c=e.getAttribute(`position`),l=e.getIndex(),u=l?l.count:c.count;if(s+=u/3,s>t)return null;r.multiplyMatrices(n,a.matrixWorld);let d=new Float32Array(u*3);for(let e=0;e<u;e++)i.fromBufferAttribute(c,l?l.getX(e):e).applyMatrix4(r),d[e*3]=i.x,d[e*3+1]=i.y,d[e*3+2]=i.z;o.push(d)}let c=new Float32Array(o.reduce((e,t)=>e+t.length,0)),l=0;for(let e of o)c.set(e,l),l+=e.length;return c}function Ni(e,t){let{inv:n}=Ti(e.object),r=new f,i=[],o=Di(e),s=o.reduce((e,t)=>e+t.geometry.getAttribute(`position`).count,0),l=Math.max(1,Math.ceil(s/t));for(let e of o){let t=e.geometry.getAttribute(`position`);r.multiplyMatrices(n,e.matrixWorld);for(let e=0;e<t.count;e+=l)i.push(new a().fromBufferAttribute(t,e).applyMatrix4(r))}let u=new c;for(let e of o){let t=e.geometry.getAttribute(`position`);r.multiplyMatrices(n,e.matrixWorld);let o=[];for(let e=0;e<t.count;e++){let n=new a().fromBufferAttribute(t,e).applyMatrix4(r);for(let e=0;e<3;e++)(!o[e*2]||n.getComponent(e)<o[e*2].getComponent(e))&&(o[e*2]=n),(!o[e*2+1]||n.getComponent(e)>o[e*2+1].getComponent(e))&&(o[e*2+1]=n)}for(let e of o)e&&(i.push(e),u.expandByPoint(e))}return i}function Pi(e,t){if(e.length<4)return null;let n;try{n=new yi().setFromPoints(e)}catch{return null}let r=/* @__PURE__ */ new Map,i=[],a=[];for(let e of n.faces){let n=[],o=e.edge;do{let e=o.head().point,a=r.get(e);a===void 0&&(a=i.length,r.set(e,a),i.push([e.x-t.x,e.y-t.y,e.z-t.z])),n.push(a),o=o.next}while(o!==e.edge);n.length>=3&&a.push(n)}return a.length>=4?{vertices:i,faces:a}:null}var Fi=t=>{if(!t)return;let n=new o().setFromEuler(new i(t[0]*e,t[1]*e,t[2]*e));return[n.x,n.y,n.z,n.w]};function Ii(e,t){let n=e.offset,r=Fi(e.rotation),i=e.size?new a(...e.size):t;switch(e.shape){case`sphere`:return{type:`sphere`,radius:e.radius??Math.max(i.x,i.y,i.z)/2,offset:n,quat:r};case`cylinder`:return{type:`cylinder`,radius:e.radius??Math.max(i.x,i.z)/2,height:e.height??i.y,offset:n,quat:r};case`capsule`:return{type:`capsule`,radius:e.radius??Math.max(i.x,i.z)/2,height:e.height??i.y,offset:n,quat:r};default:return{type:`box`,half:[i.x/2,i.y/2,i.z/2],offset:n,quat:r}}}function Li(e){let t=e.objectDef,n=e.def.type===`static`||e.def.type===`kinematic`;if(e.built?.heightAt&&n&&typeof e.object.userData.size==`number`)return`heightfield`;if(t?.kind===`mesh`){let e=t.geometry?.type;return e===`sphere`||e===`icosahedron`||e===`dodecahedron`?`sphere`:e===`capsule`?`capsule`:e===`cylinder`?t.geometry.radiusTop===void 0||t.geometry.radiusTop===t.geometry.radiusBottom?`cylinder`:`convex`:e===`box`||e===`roundedBox`||e===`plane`?`box`:n?`trimesh`:`convex`}return t?.kind===`model`||t?.kind===`svg`?n?`trimesh`:`convex`:t?.kind===`generator`&&n?`trimesh`:`box`}function Ri(e){let t=e.def,n=Ai(e.object,e.objectDef),r=n.isEmpty(),i=r?new a(1,1,1):n.getSize(new a),o=r?new a:n.getCenter(new a);t.size&&i.set(t.size[0],t.size[1],t.size[2]);let s=t.offset?new a(...t.offset):o.clone(),c=t.shape??`box`;c===`auto`&&(c=Li(e));let l=()=>({type:`box`,half:[i.x/2,i.y/2,i.z/2]});switch(c){case`sphere`:return{shapes:[{type:`sphere`,radius:t.radius??Math.max(i.x,i.y,i.z)/2}],offset:s};case`cylinder`:return{shapes:[{type:`cylinder`,radius:t.radius??Math.max(i.x,i.z)/2,height:t.height??i.y}],offset:s};case`capsule`:return{shapes:[{type:`capsule`,radius:t.radius??Math.max(i.x,i.z)/2,height:t.height??i.y}],offset:s};case`compound`:{let n=t.offset?new a(...t.offset):new a;if(!t.shapes?.length){let t=ji(e.object,e.objectDef);if(t.length)return{shapes:t.map(e=>({type:`box`,half:[e.size.x/2,e.size.y/2,e.size.z/2],offset:[e.center.x-n.x,e.center.y-n.y,e.center.z-n.z]})),offset:n}}let r=(t.shapes??[]).map(e=>{let t=Ii(e,i),r=e.offset??[0,0,0];return{...t,offset:[r[0]-n.x,r[1]-n.y,r[2]-n.z]}});return r.length?{shapes:r,offset:n}:{shapes:[l()],offset:s}}case`convex`:{let t=Pi(Ni(e,wi),s);return t?{shapes:[{type:`convex`,...t}],offset:s}:{shapes:[l()],offset:s,note:`convex hull failed (too few points): using the bounding box`}}case`heightfield`:return zi(e)||u(e,`heightfield needs a terrain generator (heightAt): using the triangles`);case`trimesh`:return u(e);default:return{shapes:[l()],offset:s}}function u(e,t){let n=Mi(e,Ci);if(!n||n.length===0)return{shapes:[l()],offset:s,note:n?`no triangles: using the bounding box`:`more than ${Ci} triangles: using the bounding box (use a simpler collision mesh, "compound" or "box")`};for(let e=0;e<n.length;e+=3)n[e]-=s.x,n[e+1]-=s.y,n[e+2]-=s.z;return{shapes:[{type:`trimesh`,vertices:n}],offset:s,note:t}}}function zi(e){let t=e.built?.heightAt?.bind(e.built),n=e.object.userData.size;if(!t||typeof n!=`number`||!(n>0))return null;let{scale:r}=Ti(e.object),i=0;for(let t of $(e.object))if(t.userData.materialTarget||t.name===`terrain-ground`){let e=t.geometry;i=(e.getIndex()?.count??e.getAttribute(`position`).count)/3;break}let o=Math.min(160,Math.max(8,i?Math.round(Math.sqrt(i/2)):64)),s=o+1,c=n/o,l=[];for(let e=0;e<s;e++){let i=[];for(let a=0;a<s;a++)i.push(t(-n/2+e*c,n/2-a*c)*r.y);l.push(i)}let u=r.x,d=new a;return{shapes:[{type:`heightfield`,data:l,elementSize:c*u,offset:[-n/2*u,0,n/2*u],quat:[-Math.SQRT1_2,0,0,Math.SQRT1_2]}],offset:d}}function Bi(e,t){e.updateWorldMatrix(!0,!1);let n=new a,r=new o,i=new a;return e.matrixWorld.decompose(n,r,i),n.add(t.clone().applyQuaternion(r)),{position:[n.x,n.y,n.z],quaternion:[r.x,r.y,r.z,r.w]}}function Vi(t,n){let{shapes:r,offset:i,note:a}=Ri(n),o=Bi(n.object,i),s=n.def,c=s.angularVelocity;return{init:{id:t,type:s.type,shapes:r,position:o.position,quaternion:o.quaternion,velocity:s.velocity,angularVelocity:c?[c[0]*e,c[1]*e,c[2]*e]:void 0,mass:s.mass,friction:s.friction,restitution:s.restitution,material:s.material,linearDamping:s.linearDamping,angularDamping:s.angularDamping,gravityScale:s.gravityScale,fixedRotation:s.fixedRotation,character:s.character,sleep:s.sleep,ccd:s.ccd,layer:s.layer,collidesWith:s.collidesWith},offset:i,note:a}}var Hi=class{def;issue;engine;offsets=/* @__PURE__ */ new Map;scales=/* @__PURE__ */ new Map;scaleWarned=/* @__PURE__ */ new Set;debug=null;world;constructor(e,t,n){this.def=e,this.issue=n,this.world=t;let r=e?.gravity??[0,-9.81,0];this.engine=new ci({gravity:[r[0],r[1],r[2]],iterations:e?.iterations,substeps:e?.substeps,sleep:e?.sleep,materials:e?.materials,contacts:e?.contacts,layers:e?.layers}),e?.debug&&(this.debug=new di(t.scene))}attachAll(){this.world.scene.updateMatrixWorld(!0);for(let e of this.world.entries.values())this.addEntry(e),this.addGeneratorBodies(e);(this.def?.joints??[]).forEach((t,n)=>{this.engine.addJoint({id:t.id??`joint-${n+1}`,type:t.type,a:t.a,b:t.b,pivot:t.pivot,axis:t.axis,distance:t.distance,restLength:t.restLength,stiffness:t.stiffness,damping:t.damping,motor:t.motor?{speed:t.motor.speed*e,maxForce:t.motor.maxForce}:void 0,limits:t.limits?[t.limits[0]*e,t.limits[1]*e]:void 0,maxForce:t.maxForce,collideConnected:t.collideConnected})||this.issue({code:`physics`,message:`physics.joints[${n}]: "${t.a}"${t.b?` or "${t.b}"`:``} has no body.`,path:`physics.joints[${n}]`})}),this.debug?.sync(this.engine.bodies)}addEntry(e,t){let n=t??e.def.body;if(!n||e.kind===`light`)return!1;let{init:r,offset:i,note:o}=Vi(e.id,{object:e.object,def:n,objectDef:e.def,built:e.built});return o&&this.issue({code:`physics`,message:`objects#${e.id}.body: ${o}.`,path:`objects#${e.id}.body`}),this.offsets.set(e.id,i),this.scales.set(e.id,e.object.getWorldScale(new a)),this.engine.add(r),!0}addGeneratorBodies(e){if(e.kind===`light`||e.def.body)return;let t=e.object.userData.bodies;if(!Array.isArray(t)||!t.length)return;e.object.updateWorldMatrix(!0,!1);let n=new a,r=new o,i=new a;e.object.matrixWorld.decompose(n,r,i);let s=t.map(e=>({type:`box`,half:[Math.abs(e.max[0]-e.min[0])*i.x/2,Math.abs(e.max[1]-e.min[1])*i.y/2,Math.abs(e.max[2]-e.min[2])*i.z/2],offset:[(e.min[0]+e.max[0])/2*i.x,(e.min[1]+e.max[1])/2*i.y,(e.min[2]+e.max[2])/2*i.z]}));this.offsets.set(e.id,new a),this.engine.add({id:e.id,type:`static`,shapes:s,position:[n.x,n.y,n.z],quaternion:[r.x,r.y,r.z,r.w]})}has(e){return!!this.engine.get(e)}moved(e){let t=this.world.entries.get(e),n=this.offsets.get(e),r=this.engine.get(e);if(!t||!n||!r)return;let i=this.scales.get(e);if(i&&t.def.body){let n=t.object.getWorldScale(new a);if(Math.abs(n.x-i.x)>1e-4*Math.abs(i.x)+1e-6||Math.abs(n.y-i.y)>1e-4*Math.abs(i.y)+1e-6||Math.abs(n.z-i.z)>1e-4*Math.abs(i.z)+1e-6){if(this.engine.hasJoints(e))this.scaleWarned.has(e)||(this.scaleWarned.add(e),this.issue({code:`physics`,message:`objects#${e}: its scale changed but its collider keeps the start size (the body is held by a joint).`,path:`objects#${e}.body`}));else{let n=[...r.velocity],i=[...r.angularVelocity];t.object.updateWorldMatrix(!0,!1),this.addEntry(t),this.engine.setVelocity(e,n),this.engine.setAngularVelocity(e,i),this.debug?.sync(this.engine.bodies);return}}}let o=Bi(t.object,n);this.engine.setPose(e,o.position,o.quaternion)}remove(e){this.engine.remove(e),this.offsets.delete(e),this.scales.delete(e)}step(e){this.engine.step(e),this.syncObjects(),this.debug?.sync(this.engine.bodies)}syncObjects(){let e=new a,t=new o,n=new o;for(let r of this.engine.bodies){if(r.type!==`dynamic`&&r.type!==`kinematic`||r.sleeping)continue;if(r.type===`kinematic`){let e=r.velocity,t=r.angularVelocity;if(!e[0]&&!e[1]&&!e[2]&&!t[0]&&!t[1]&&!t[2])continue}let i=this.world.entries.get(r.id);if(!i)continue;let o=i.object;t.set(...r.quaternion),e.set(...r.position).sub((this.offsets.get(r.id)??new a).clone().applyQuaternion(t)),o.parent&&(o.parent.updateWorldMatrix(!0,!1),o.parent.worldToLocal(e),o.parent.getWorldQuaternion(n),t.premultiply(n.invert())),o.position.copy(e),o.quaternion.copy(t),i.animated&&(i.rest.position.copy(e),i.rest.quaternion.copy(t))}}dispose(){this.debug?.dispose(),this.debug=null}};export{Hi as PhysicsBridge,ci as PhysicsWorld};
@@ -1,4 +1,4 @@
1
- import{An as e,B as t,F as n,Gt as r,In as i,Mn as a,Nn as o,O as s,On as c,Ot as l,Pt as u,Qt as d,Rt as f,T as p,U as m,b as h,bn as g,d as _,gt as v,jn as y,k as b,kn as x,m as S,nn as C,ot as w,qt as T,rn as E,vt as D,wt as O,x as k,yt as A}from"./three.module-DnaBiDAJ.js";import{a as j,i as ee,t as te}from"./postfx-CFucYRev.js";import{c as M,d as N,n as P}from"./util-CyaW1fcW.js";var F=class{constructor(){this.isPass=!0,this.enabled=!0,this.needsSwap=!0,this.clear=!1,this.renderToScreen=!1}setSize(){}render(){console.error(`THREE.Pass: .render() must be implemented in derived pass.`)}dispose(){}},ne=new u(-1,1,1,-1,0,1),I=new class extends S{constructor(){super(),this.setAttribute(`position`,new n([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute(`uv`,new n([0,2,0,0,2,0],2))}},L=class{constructor(e){this._mesh=new A(I,e)}dispose(){this._mesh.geometry.dispose()}render(e){e.render(this._mesh,ne)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}},R={1:`LINEAR_TONE_MAPPING`,2:`REINHARD_TONE_MAPPING`,3:`CINEON_TONE_MAPPING`,4:`ACES_FILMIC_TONE_MAPPING`,6:`AGX_TONE_MAPPING`,7:`NEUTRAL_TONE_MAPPING`,5:`CUSTOM_TONE_MAPPING`},z=`
1
+ import{An as e,B as t,F as n,Gt as r,In as i,Mn as a,Nn as o,O as s,On as c,Ot as l,Pt as u,Qt as d,Rt as f,T as p,U as m,b as h,bn as g,d as _,gt as v,jn as y,k as b,kn as x,m as S,nn as C,ot as w,qt as T,rn as E,vt as D,wt as O,x as k,yt as A}from"./three.module-DnaBiDAJ.js";import{a as j,i as ee,t as te}from"./postfx-ylpcQcVK.js";import{r as M}from"./num-CQNAlL82.js";import{c as N,t as P}from"./util-BEflQURG.js";var F=class{constructor(){this.isPass=!0,this.enabled=!0,this.needsSwap=!0,this.clear=!1,this.renderToScreen=!1}setSize(){}render(){console.error(`THREE.Pass: .render() must be implemented in derived pass.`)}dispose(){}},ne=new u(-1,1,1,-1,0,1),I=new class extends S{constructor(){super(),this.setAttribute(`position`,new n([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute(`uv`,new n([0,2,0,0,2,0],2))}},L=class{constructor(e){this._mesh=new A(I,e)}dispose(){this._mesh.geometry.dispose()}render(e){e.render(this._mesh,ne)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}},R={1:`LINEAR_TONE_MAPPING`,2:`REINHARD_TONE_MAPPING`,3:`CINEON_TONE_MAPPING`,4:`ACES_FILMIC_TONE_MAPPING`,6:`AGX_TONE_MAPPING`,7:`NEUTRAL_TONE_MAPPING`,5:`CUSTOM_TONE_MAPPING`},z=`
2
2
  vec4 a3dSanitize(vec4 c) {
3
3
  bvec4 bad = bvec4(isnan(c.r) || isinf(c.r), isnan(c.g) || isinf(c.g), isnan(c.b) || isinf(c.b), isnan(c.a) || isinf(c.a));
4
4
  c = vec4(bad.r ? 0.0 : c.r, bad.g ? 0.0 : c.g, bad.b ? 0.0 : c.b, bad.a ? 1.0 : c.a);
@@ -0,0 +1 @@
1
+ import{l as e,o as t,r as n}from"./catalog--OTp4gjy.js";var r=[`low`,`medium`,`high`,`ultra`],i={low:1,medium:1.5,high:2,ultra:3};function a(e,t={}){return e&&e!==`auto`?e:t.deterministic?`high`:t.gpu&&/swiftshader|llvmpipe|softpipe|software|microsoft basic render/i.test(t.gpu)?`low`:t.mobile?(t.memoryGb??4)<=2||(t.cores??8)<=4?`low`:`medium`:t.cores!==void 0&&t.cores<=2||t.memoryGb!==void 0&&t.memoryGb<=2?`low`:t.cores!==void 0&&t.cores<=4||t.memoryGb!==void 0&&t.memoryGb<=4||t.gpu&&/intel|mali|adreno|powervr/i.test(t.gpu)?`medium`:`high`}var o=/* @__PURE__ */ new Set([`strength`,`intensity`,`darkness`,`amount`,`toning`,`streaks`,`ghosts`,`halo`,`bleach`,`scanlines`]);function s(e){if(!e?.length)return[];let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map;for(let i of e){if(!i||typeof i.type!=`string`)continue;if(i.type!==`look`){n.has(i.type)||n.set(i.type,i);continue}let e=t[String(i.preset??`cinematic`)];if(!e)continue;let a=typeof i.intensity==`number`?Math.max(0,Math.min(1,i.intensity)):1;for(let t of e.effects){if(r.has(t.type))continue;let e={...t};if(a!==1){for(let[n,r]of Object.entries(t))o.has(n)&&typeof r==`number`&&(e[n]=r*a);t.type===`grading`&&t.look&&(e.intensity=a)}r.set(t.type,e)}}let i=[],a=/* @__PURE__ */ new Set,s=e=>{if(a.has(e))return;a.add(e);let t=n.get(e),o=r.get(e);i.push(t&&o?{...o,...t}:t??o)};for(let r of e)if(r&&typeof r.type==`string`){if(r.type!==`look`)s(r.type);else for(let e of t[String(r.preset??`cinematic`)]?.effects??[])n.has(e.type)||s(e.type)}return i}function c(e){let t={exposure:0,contrast:1,saturation:1,vibrance:0,temperature:0,tint:0,lift:0,gamma:1,gain:1,toning:0,bleach:0},r=e.look&&e.look!==`none`?n[e.look]:void 0,i=typeof e.intensity==`number`?Math.max(0,Math.min(1,e.intensity)):1,a={...t};if(r)for(let[e,n]of Object.entries(r.values))a[e]=typeof n==`number`?t[e]+(n-t[e])*i:n;for(let[t,n]of Object.entries(e))t!==`type`&&t!==`look`&&t!==`intensity`&&(typeof n==`number`||typeof n==`string`)&&(a[t]=n);return a}var l={low:0,medium:1,high:2};function u(e){switch(e){case`low`:return{tier:e,dprCap:i.low,msaa:0,effectScale:.5,maxCost:`medium`,aoSamples:8,dofSamples:16,rays:24,maxStillSamples:4};case`medium`:return{tier:e,dprCap:i.medium,msaa:4,effectScale:.5,maxCost:`high`,aoSamples:12,dofSamples:24,rays:32,maxStillSamples:8};case`ultra`:return{tier:e,dprCap:i.ultra,msaa:8,effectScale:1,maxCost:`high`,aoSamples:24,dofSamples:64,rays:64,maxStillSamples:64};default:return{tier:`high`,dprCap:i.high,msaa:4,effectScale:.5,maxCost:`high`,aoSamples:16,dofSamples:40,rays:48,maxStillSamples:32}}}function d(e){let t=r.indexOf(e);return t>0?r[t-1]:null}function f(t){return e(`postfx`,t)?.gpu??`low`}function p(e,t){let n=l[u(t).maxCost],r=[],i=[];for(let t of s(e))l[f(t.type)]>n?i.push(t.type):r.push(t);return{active:r,dropped:i}}export{c as a,u as i,s as n,a as o,d as r,p as t};
@@ -0,0 +1 @@
1
+ import{F as e,H as t,Mn as n,N as r,b as i,en as a,m as o,on as s,p as c,u as l,yt as u}from"./three.module-DnaBiDAJ.js";import{n as d}from"./assets-kC2Z1Xy_.js";import{r as f}from"./num-CQNAlL82.js";import{i as p,n as m,r as h,t as g}from"./extrude-D6WnITQq.js";import{n as _,o as v}from"./materials-jwhXlLYl.js";var y=e=>!!e&&e!==`none`&&e!==`transparent`;function b(e,t,n){if(e===`currentColor`)return n;let r=/^url\(\s*['"]?#([^'")]+)['"]?\s*\)/.exec(e);if(r){let e=t.userData?.gradients?.[r[1]]?.stops??[];if(!e.length)return n;let a=new i(e[0].color),o=new i(e[e.length-1].color);return`#${a.lerp(o,.5).getHexString()}`}try{let t=new i;return t.setStyle(e,a),`#${t.getHexString(a)}`}catch{return n}}function x(e,t){let n=new l;for(let t of e.paths)for(let e of t.subPaths)for(let t of e.getPoints(4))n.expandByPoint(t);return(n.isEmpty()?100:Math.max(n.max.x-n.min.x,n.max.y-n.min.y,1e-6))/(t*10)}function S(e,t,n={}){let r=[],i=Math.max(1,Math.round(f(n.curveSegments,12))),a=x(e,i),o=n.currentColor??`#1f2330`;for(let s of e.paths){let e=s.userData?.style??{};if(e.visibility===`hidden`||e.visibility===`collapse`)continue;let c=f(e.opacity,1);if(y(e.fill)){let t=s.toShapes().map(e=>h(e,a));t.length&&r.push({kind:`fill`,color:b(e.fill,s,o),opacity:f(e.fillOpacity,1)*c,shapes:t})}if(n.strokes!==!1&&y(e.stroke)&&f(e.strokeWidth,1)>0){let n=t.getStrokeStyle(f(e.strokeWidth,1),`#000`,e.strokeLineJoin??`miter`,e.strokeLineCap??`butt`,f(e.strokeMiterLimit,4)),l=[];for(let e of s.subPaths){let r=m(e,a);if(r.length<2)continue;let o=t.pointsToStroke(r,n,i);o&&l.push(o)}if(l.length){let t=l.length===1?l[0]:C(l);r.push({kind:`stroke`,color:b(e.stroke,s,o),opacity:f(e.strokeOpacity,1)*c,stroke:t})}}}return r}function C(e){let t=0;for(let n of e)t+=n.getAttribute(`position`).count;let n=new Float32Array(t*3),r=0;for(let t of e){let e=t.getAttribute(`position`).array;n.set(e,r),r+=e.length,t.dispose()}let i=new o;return i.setAttribute(`position`,new c(n,3)),i}function w(e,t=12){let r=new l;for(let i of e){if(i.shapes)for(let e of i.shapes)for(let n of e.getPoints(t))r.expandByPoint(n);if(i.stroke){let e=i.stroke.getAttribute(`position`);for(let t=0;t<e.count;t++)r.expandByPoint(new n(e.getX(t),e.getY(t)))}}return r}function T(e,t,n,i,a){if(e.kind===`stroke`)return e.stroke?g(e.stroke,t):null;if(!e.shapes?.length)return null;if(t<=0)return new s(e.shapes,i);let o=Math.min(n,t*.45),c=new r(e.shapes,{depth:Math.max(t-o*2,t*.05),curveSegments:i,bevelEnabled:o>0,bevelThickness:o,bevelSize:o*.6,bevelOffset:0,bevelSegments:3});return c.translate(0,0,o),c.clearGroups(),p(c,50*Math.PI/180,a)}async function E(n,r){let[{SVGLoader:i},a]=await Promise.all([import(`./SVGLoader-CV0U1EIF.js`),import(`./BufferGeometryUtils-XmME4f7Z.js`).then(e=>e.t)]),o=n.src.trim().startsWith(`<`)?n.src:await d(r.resolveAsset(n.src)),s=new i().parse(o),c=n.material?v(n.material):void 0,l=typeof c?.color==`string`?c.color:void 0,p=Math.max(1,Math.round(f(n.curveSegments,12))),m=S(s,i,{strokes:n.strokes,curveSegments:p,currentColor:l}),h=new t,g=w(m,p);if(!m.length||g.isEmpty())return h;let y=f(n.size,2),b=Math.max(g.max.x-g.min.x,1e-6),x=Math.max(g.max.y-g.min.y,1e-6),C=n.fit??`width`,E=y/(C===`height`?x:C===`max`?Math.max(b,x):b),D=Math.max(0,f(n.depth,.2)),O=D/E,k=f(n.bevel,0)/E,A=f(n.layerGap,D>0?D*.02:y*.002),j=n.keepColors??!n.material,M=/* @__PURE__ */ new Map,N=async(e,t)=>{let i=j?`${e}|${t}`:`|${t}`,a=M.get(i);if(!a){let o=j?{roughness:.4,metalness:.1,...n.material??{},color:e,...t<1?{opacity:t}:{}}:n.material?{...n.material,...t<1?{opacity:t}:{}}:{color:`#dddddd`,roughness:.4,metalness:.1};a=await _(o,r,{defaultColor:e}),t<1&&(a.transparent=!0),D<=0&&(a.side=2),M.set(i,a)}return a},P=[];for(let e of m){let t=T(e,O,k,p,a);if(!t)continue;t.getAttribute(`normal`)||t.computeVertexNormals();let n=j?`${e.color}|${e.opacity}`:`|${e.opacity}`,r=P[P.length-1];r&&r.key===n?r.geos.push(t):P.push({key:n,color:e.color,opacity:e.opacity,geos:[t]})}let F=new t;for(let[t,n]of P.entries()){for(let t of n.geos){for(let e of Object.keys(t.attributes))[`position`,`normal`,`uv`].includes(e)||t.deleteAttribute(e);t.getAttribute(`uv`)||t.setAttribute(`uv`,new e(new Float32Array(t.getAttribute(`position`).count*2),2))}let r=n.geos.length===1?n.geos[0]:a.mergeGeometries(n.geos.map(e=>e.index?e.toNonIndexed():e),!1)??n.geos[0],i=new u(r,await N(n.color,n.opacity));i.position.z=t*A/E,F.add(i)}let I=(g.min.x+g.max.x)/2,L=(g.min.y+g.max.y)/2;return F.scale.set(E,-E,E),F.position.set(-I*E,L*E,-(D+Math.max(0,P.length-1)*A)/2),h.add(F),h}export{E as buildSvg};
@@ -1,2 +1,2 @@
1
- import{Ft as e,H as t,Mn as n,N as r,an as i,bt as a,m as o,on as s,yt as c}from"./three.module-DnaBiDAJ.js";import{n as l}from"./assets-qnxDnVkj.js";import{t as u}from"./easing-CXSz2e6P.js";import{c as d}from"./util-CyaW1fcW.js";import{i as f,r as p}from"./extrude-D6WnITQq.js";import{n as m}from"./materials-dC4vDNHh.js";var h=/* @__PURE__ */ new Map;function g(e){let t=h.get(e);return t||(t=Promise.all([import(`./FontLoader-dVu9WH2X.js`),l(e)]).then(([e,t])=>new e.FontLoader().parse(t)),t.catch(()=>h.delete(e)),h.set(e,t)),t}var _=e=>{let t=e.normalize(`NFD`);return t.length>1?t[0]:e};function v(e,t,n){let r=e.kerning;if(!r)return 0;let i=r[t]?.[n];if(i!==void 0)return i;let a=_(t),o=_(n);return a===t&&o===n?0:r[a]?.[o]??0}function y(e,t){let n=t.em/e.resolution,r=d(t.letterSpacing,0),i=d(t.lineHeight,1.25)*t.em,a=t.kerning!==!1,o=t=>(e.glyphs[t]??e.glyphs[`?`])?.ha??e.resolution*.5,s=t=>{let i=[],s=0;return t.forEach((c,l)=>{l>0&&(s+=r+(a?v(e,t[l-1],c)*n:0)),i.push(s),s+=o(c)*n}),{xs:i,width:s}},c=[],l=typeof t.maxWidth==`number`&&t.maxWidth>0?t.maxWidth:1/0;for(let e of String(t.text??``).split(`
1
+ import{Ft as e,H as t,Mn as n,N as r,an as i,bt as a,m as o,on as s,yt as c}from"./three.module-DnaBiDAJ.js";import{t as l}from"./assets-kC2Z1Xy_.js";import{t as u}from"./easing-CXSz2e6P.js";import{r as d}from"./num-CQNAlL82.js";import{i as f,r as p}from"./extrude-D6WnITQq.js";import{n as m}from"./materials-jwhXlLYl.js";var h=/* @__PURE__ */ new Map;function g(e){let t=h.get(e);return t||(t=Promise.all([import(`./FontLoader-dVu9WH2X.js`),l(e)]).then(([e,t])=>new e.FontLoader().parse(t)),t.catch(()=>h.delete(e)),h.set(e,t)),t}var _=e=>{let t=e.normalize(`NFD`);return t.length>1?t[0]:e};function v(e,t,n){let r=e.kerning;if(!r)return 0;let i=r[t]?.[n];if(i!==void 0)return i;let a=_(t),o=_(n);return a===t&&o===n?0:r[a]?.[o]??0}function y(e,t){let n=t.em/e.resolution,r=d(t.letterSpacing,0),i=d(t.lineHeight,1.25)*t.em,a=t.kerning!==!1,o=t=>(e.glyphs[t]??e.glyphs[`?`])?.ha??e.resolution*.5,s=t=>{let i=[],s=0;return t.forEach((c,l)=>{l>0&&(s+=r+(a?v(e,t[l-1],c)*n:0)),i.push(s),s+=o(c)*n}),{xs:i,width:s}},c=[],l=typeof t.maxWidth==`number`&&t.maxWidth>0?t.maxWidth:1/0;for(let e of String(t.text??``).split(`
2
2
  `)){if(l===1/0){c.push(Array.from(e));continue}let t=e.split(/ +/),n=[];for(let e of t){let t=n.length?[...n,` `,...Array.from(e)]:Array.from(e);n.length&&s(t).width>l?(c.push(n),n=Array.from(e)):n=t}c.push(n)}let u=[],f=[],p=0;return c.forEach((e,n)=>{for(;e.length&&e[e.length-1]===` `;)e.pop();let{xs:r,width:a}=s(e);p=Math.max(p,a);let o=t.align===`left`?0:t.align===`right`?-a:-a/2;e.forEach((e,t)=>{e.trim()&&u.push({ch:e,x:r[t]+o,line:n})}),f.push({width:a,y:-n*i})}),{glyphs:u,lines:f,lineHeight:i,width:p}}function b(e){let t=e.data;if(t.capHeight&&t.resolution)return t.capHeight/t.resolution;let n=e.generateShapes(`H`,1);if(!n.length)return .72;let r=new s(n);r.computeBoundingBox();let i=r.boundingBox.max.y-r.boundingBox.min.y;return r.dispose(),i>0?i:.72}function x(e,t){let n=e.data,r=d(t.size,1),i=r/b(e),a=Math.max(0,d(t.depth,.2)),o=a>0?Math.max(0,Math.min(d(t.bevel,Math.min(a*.3,r*.035)),a*.45,r*.08)):0,s=Math.round(Math.max(2,Math.min(32,d(t.curveSegments,a>0?5+r*3:8+r*4)))),c=y(n,{text:t.text,em:i,letterSpacing:t.letterSpacing,lineHeight:t.lineHeight,align:t.align??`center`,maxWidth:t.maxWidth,kerning:t.kerning});return{size:r,em:i,depth:a,bevel:o,curveSegments:s,layout:c,offsetY:-(r+(c.lines.length?c.lines[c.lines.length-1].y:0))/2,frontZ:a/2,backZ:-a/2}}function S(e){let t=e.bevel;return{depth:Math.max(e.depth-t*2,1e-4),curveSegments:e.curveSegments,bevelEnabled:t>0,bevelThickness:t,bevelSize:t*.6,bevelOffset:0,bevelSegments:3}}function C(e,t,n){let r=n.em/(n.curveSegments*5);return e.generateShapes(t,n.em).map(e=>p(e,r,1,n.curveSegments))}function w(e,t,n,i){let a=C(e,t,n);if(!a.length)return null;if(n.depth<=0)return new s(a,n.curveSegments);let o=new r(a,S(n));return o.translate(0,0,n.backZ+n.bevel),o.clearGroups(),f(o,50*Math.PI/180,i)}function T(e,t){let n=e.outline;if(!n)return null;let r=n===!0?{}:n,i=Math.max(1e-4,d(r.width,t.size*.06)),a=t.depth>0?t.depth*.5:t.size*.01,o=t.frontZ-a;return{width:i,frontZ:o,backZ:o-Math.max(d(r.depth,t.depth>0?t.depth*.6:t.size*.01),1e-4),material:r.material,color:r.color??`#111111`}}function E(e){let t=0;for(let n=0,r=e.length-1;n<e.length;r=n++)t+=(e[r].x-e[n].x)*(e[r].y+e[n].y);return t/2}function D(e,t,r=2){let i=e.filter((t,n)=>{let r=e[(n+1)%e.length];return Math.hypot(r.x-t.x,r.y-t.y)>1e-9}),a=i.length,o=[];if(a<3)return i.map(e=>new n(e.x,e.y));let s=(e,t)=>{let n=t.x-e.x,r=t.y-e.y,i=Math.hypot(n,r)||1;return{x:r/i,y:-n/i}};for(let e=0;e<a;e++){let c=i[(e-1+a)%a],l=i[e],u=i[(e+1)%a],d=s(c,l),f=s(l,u),p=(l.x-c.x)*(u.y-l.y)-(l.y-c.y)*(u.x-l.x),m=d.x*f.x+d.y*f.y;if(p>0&&m<.995){let e=Math.atan2(d.y,d.x),r=Math.atan2(f.y,f.x);for(;r<e;)r+=Math.PI*2;for(;r>e+Math.PI*2;)r-=Math.PI*2;let i=Math.max(1,Math.ceil(Math.abs(r-e)/(Math.PI/8)));for(let a=0;a<=i;a++){let s=e+(r-e)*a/i;o.push(new n(l.x+Math.cos(s)*t,l.y+Math.sin(s)*t))}}else{let e=d.x+f.x,i=d.y+f.y,a=Math.hypot(e,i)||1;e/=a,i/=a;let s=Math.max(e*d.x+i*d.y,1/r);o.push(new n(l.x+e*t/s,l.y+i*t/s))}}return o}function O(t,n){let r=[];for(let a of t){let{shape:t,holes:o}=a.extractPoints(1),s=t.slice();E(s)<0&&(s=s.reverse());let c=new i(D(s,n));for(let t of o){let r=t.slice(),i=Math.abs(E(r));E(r)>0&&(r=r.reverse());let a=r.map(e=>e.x),o=r.map(e=>e.y);if(Math.max(...a)-Math.min(...a)<=2*n||Math.max(...o)-Math.min(...o)<=2*n)continue;let s=D(r,n),l=E(s);l<0&&-l>i*.02&&c.holes.push(new e(s))}r.push(c)}return r}function k(e,t,n,i,a){let o=C(e,t,n);if(!o.length)return null;let s=new r(O(o,i.width),{depth:i.frontZ-i.backZ,curveSegments:1,bevelEnabled:!1});return s.translate(0,0,i.backZ),s.clearGroups(),f(s,40*Math.PI/180,a)}function A(e,t,n){let r=/* @__PURE__ */ new Map,i=[];for(let n of e.layout.glyphs){r.has(n.ch)||r.set(n.ch,t(n.ch));let a=r.get(n.ch);if(!a)continue;let o=a.clone();o.translate(n.x,e.layout.lines[n.line].y+e.offsetY,0),i.push(o)}for(let e of r.values())e?.dispose();let a;if(!i.length)a=new o;else{a=(i.length===1?i[0].clone():n.mergeGeometries(i,!1))??new o;for(let e of i)e.dispose()}return a.computeBoundingBox(),a.computeBoundingSphere(),a}function j(e,t,n){let r=d(e.stagger,.04),i=t;if(e.order===`reverse`)i=n-1-t;else if(e.order===`center`)i=Math.abs(t-(n-1)/2);else if(e.order===`random`){let e=(t+1)*2654435761;e=(e^e>>>13)>>>0,i=e%1e3/1e3*(n-1)}return d(e.delay,0)+i*r}function M(e,t){return(n,r)=>{let i=e.effect??`rise`,a=Math.max(d(e.duration,.6),.001),o=e.ease??(i===`scale`||i===`spin`?`outBack`:`outCubic`),s=i!==`scale`,c=[],l=[];if(s){let e=[];r.object.traverse(t=>{let n=t.material;if(n&&!t.userData.depthTwin){e.push(t);for(let e of Array.isArray(n)?n:[n])e.userData.baseOpacity===void 0&&(e.userData.baseOpacity=e.opacity),e.userData.baseTransparent===void 0&&(e.userData.baseTransparent=e.transparent),c.push(e)}});for(let t of e)l.push(P(t))}return{update(e){let n=Math.min(Math.max(e/a,0),1),d=u(o,n),f=r.object;if(s){let e=u(`outCubic`,Math.min(1,n*1.6));for(let t of c)t.opacity=t.userData.baseOpacity*e,t.transparent=e<1||t.userData.baseTransparent;for(let t of l)t.visible=e>0&&e<1}switch(n<=0&&(f.visible=!1),i){case`rise`:f.position.y-=(1-d)*t*.6;break;case`drop`:f.position.y+=(1-d)*t*1.2;break;case`scale`:f.scale.multiplyScalar(Math.max(1e-4,d));break;case`spin`:f.rotation.y+=(1-d)*Math.PI,f.scale.multiplyScalar(Math.max(1e-4,Math.min(1,n*2)))}}}}}var N=null;function P(e){N??=new a({colorWrite:!1,depthWrite:!0});let t=new c(e.geometry,N);return t.name=`${e.name}#depth`,t.visible=!1,t.castShadow=!1,t.receiveShadow=!1,t.renderOrder=-1,t.userData.helper=!0,t.userData.depthTwin=!0,e.add(t),t}function F(e,t){let n=e.font??`sans-bold`;return t.resolveAsset(n.includes(`/`)||n.includes(`:`)?n:`library:fonts/${n}`)}function I(e,t,n){let r=e.userData.gradient;r&&(r.uGradMin.value=t,r.uGradMax.value=n)}async function L(e,n){let[r,i]=await Promise.all([g(F(e,n)),import(`./BufferGeometryUtils-XmME4f7Z.js`).then(e=>e.t)]),a=x(r,e),o=T(e,a),s=!!e.splitLetters||!!e.reveal,l=a.depth<=0,u=()=>m(e.material,n,{defaultColor:`#ffffff`}),d=()=>o?m(o.material??{color:o.color,roughness:.55},n):null,f=(a.layout.lines.length?a.layout.lines[a.layout.lines.length-1].y:0)+a.offsetY,p=a.size+a.offsetY,h=e=>(l&&(e.side=2),e);if(!s){let t=A(a,e=>w(r,e,a,i),i),n=h(await u());I(n,f,p);let s=new c(t,n);if(o){let t=A(a,e=>k(r,e,a,o,i),i),n=await d();if(n){I(n,f,p);let r=new c(t,n);r.name=`${e.id}/outline`,s.add(r)}}return{object:s,letters:[]}}let _=new t,v=/* @__PURE__ */ new Map,y=/* @__PURE__ */ new Map,b=a.size/2,S=[],C=a.layout.glyphs.length,E=0;for(let t of a.layout.glyphs){if(!v.has(t.ch)){let e=w(r,t.ch,a,i),n=0;if(e&&(e.computeBoundingBox(),n=(e.boundingBox.min.x+e.boundingBox.max.x)/2,e.translate(-n,-b,0),e.computeBoundingSphere()),v.set(t.ch,e),o){let e=k(r,t.ch,a,o,i);e?.translate(-n,-b,0),y.set(t.ch,e)}e&&(e.userData.cx=n)}let n=v.get(t.ch);if(!n)continue;let s=n.userData.cx,l=a.layout.lines[t.line].y+a.offsetY,m=h(await u());I(m,f-l-b,p-l-b);let g=new c(n,m);g.position.set(t.x+s,l+b,0);let x=`${e.id}/${E}`;g.name=x,g.userData.a3dId=x;let T=y.get(t.ch);if(T){let e=await d();if(e){I(e,f-l-b,p-l-b);let t=new c(T,e);t.name=`${x}/outline`,g.add(t)}}_.add(g);let D={id:x,object:g,def:{id:x,kind:`text`,text:t.ch}};e.reveal&&(D.reveal={def:{type:`appear`,when:`visible`,delay:j(e.reveal,E,C)},impl:M(e.reveal,a.size)}),S.push(D),E++}return{object:_,letters:S}}export{L as buildText};
@@ -0,0 +1 @@
1
+ import{b as e,bn as t}from"./three.module-DnaBiDAJ.js";import{n}from"./num-CQNAlL82.js";function r(e,t){return typeof e==`boolean`?e:t}function i(e,t){return typeof e==`string`?e:t}function a(e,t){return Array.isArray(e)&&e.length>=3&&e.every(e=>typeof e==`number`)?[e[0],e[1],e[2]]:t}function o(e,t){return typeof e==`string`?[e]:Array.isArray(e)&&e.length&&e.every(e=>typeof e==`string`)?e:t}var s=/* @__PURE__ */ new Map;function c(t,n=`#ffffff`){let r=typeof t==`string`&&t?t:n,i=s.get(r);if(!i){i=new e;try{i.setStyle(r)}catch{i.setStyle(n)}s.size>512&&s.clear(),s.set(r,i)}return i.clone()}function l(e,t){let n={};if(e)for(let t of e.params)t.default!==void 0&&(n[t.name]=t.default);for(let[e,r]of Object.entries(t))r!==void 0&&(n[e]=r);return n}function u(e,t){let r=n(e,0,.999);return r<=0?1:1-r**(t*60)}function d(e){let t=Math.sin(e*127.1+311.7)*43758.5453123;return t-Math.floor(t)}function f(e){e.traverse(e=>{let t=e;t.geometry&&t.geometry.dispose();let n=t.material;if(n)for(let e of Array.isArray(n)?n:[n])p(e)})}function p(e){for(let n of Object.values(e))n instanceof t&&n.dispose();e.dispose()}function m(e){let t=/* @__PURE__ */ new Set;return e.traverse(e=>{let n=e.material;if(n&&!e.userData.depthTwin)for(let e of Array.isArray(n)?n:[n])t.add(e)}),[...t]}export{m as a,c,d as i,a as l,o as n,u as o,f as r,i as s,r as t,l as u};
@@ -0,0 +1 @@
1
+ import{h as e}from"./index-C2nMYSoW.js";var t=new Map;function n(e){let n=t.get(e);return n||(n=fetch(e).then(t=>{if(!t.ok)throw Error(`HTTP ${t.status} for ${e}`);return t.text()}),n.catch(()=>t.delete(e)),t.set(e,n)),n}async function r(e){return JSON.parse(await n(e))}var i=new Map;function a(t){let n=i.get(t);return n||(n=e(()=>import(`./three.module-CnI50X0U.js`).then(e=>e.a).then(e=>new Promise((n,r)=>{new e.TextureLoader().load(t,n,void 0,()=>r(Error(`Cannot load texture ${t}`)))})),[],import.meta.url),n.catch(()=>i.delete(t)),i.set(t,n)),n.then(e=>{let t=e.clone();return t.needsUpdate=!0,t})}export{n,a as r,r as t};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./OrbitControls-MlE9XiCg.js","./three.module-CnI50X0U.js"])))=>i.map(i=>d[i]);
2
+ import{In as e,It as t,Ln as n,Rt as r,wn as i,x as a}from"./three.module-CnI50X0U.js";import{n as o,r as s,t as c}from"./num-CQNAlL82.js";import{h as l}from"./index-C2nMYSoW.js";function u(e,t){return typeof e==`boolean`?e:t}function d(e,t){return typeof e==`string`?e:t}function f(e,t){return Array.isArray(e)&&e.length>=3&&e.every(e=>typeof e==`number`)?[e[0],e[1],e[2]]:t}function p(e,t){return typeof e==`string`?[e]:Array.isArray(e)&&e.length&&e.every(e=>typeof e==`string`)?e:t}var m=new Map;function h(e,t=`#ffffff`){let n=typeof e==`string`&&e?e:t,r=m.get(n);if(!r){r=new a;try{r.setStyle(n)}catch{r.setStyle(t)}m.size>512&&m.clear(),m.set(n,r)}return r.clone()}function g(e,t){let n={};if(e)for(let t of e.params)t.default!==void 0&&(n[t.name]=t.default);for(let[e,r]of Object.entries(t))r!==void 0&&(n[e]=r);return n}function _(e,t){let n=o(e,0,.999);return n<=0?1:1-n**(t*60)}function v(e){let t=Math.sin(e*127.1+311.7)*43758.5453123;return t-Math.floor(t)}function y(e){e.traverse(e=>{let t=e;t.geometry&&t.geometry.dispose();let n=t.material;if(n)for(let e of Array.isArray(n)?n:[n])b(e)})}function b(e){for(let t of Object.values(e))t instanceof i&&t.dispose();e.dispose()}function x(e){let t=new Set;return e.traverse(e=>{let n=e.material;if(n&&!e.userData.depthTwin)for(let e of Array.isArray(n)?n:[n])t.add(e)}),[...t]}function S(e){let t=(Math.floor(e)|0)^2654435769,n=()=>{t=t+2654435769|0;let e=t;return e=Math.imul(e^e>>>16,2246822507),e=Math.imul(e^e>>>13,3266489909),(e^e>>>16)>>>0},r=n(),i=n(),a=n(),o=n(),s=()=>{r>>>=0,i>>>=0,a>>>=0,o>>>=0;let e=(r+i|0)+o|0;return o=o+1|0,r=i^i>>>9,i=a+(a<<3)|0,a=a<<21|a>>>11,a=a+e|0,(e>>>0)/4294967296};for(let e=0;e<12;e++)s();return{next:s,range:(e,t)=>e+(t-e)*s(),int:(e,t)=>e+Math.floor(s()*(t-e+1)),pick:e=>e[Math.floor(s()*e.length)]}}function C(e,t){let n=(e|0)^2166136261;for(let e=0;e<t.length;e++)n^=t.charCodeAt(e),n=Math.imul(n,16777619);return n>>>0}var w=new Uint8Array(512),T=new Uint8Array(512);{let e=new Uint8Array(256);for(let t=0;t<256;t++)e[t]=t;let t=S(1337);for(let n=255;n>0;n--){let r=Math.floor(t.next()*(n+1)),i=e[n];e[n]=e[r],e[r]=i}for(let t=0;t<512;t++)w[t]=e[t&255],T[t]=w[t]%12}var E=new Float32Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]),D=.5*(Math.sqrt(3)-1),O=(3-Math.sqrt(3))/6;function k(e,t){let n=(e+t)*D,r=Math.floor(e+n),i=Math.floor(t+n),a=(r+i)*O,o=e-(r-a),s=t-(i-a),c=+(o>s),l=o>s?0:1,u=o-c+O,d=s-l+O,f=o-1+2*O,p=s-1+2*O,m=r&255,h=i&255,g=0,_=.5-o*o-s*s;if(_>0){let e=T[m+w[h]]*3;_*=_,g+=_*_*(E[e]*o+E[e+1]*s)}let v=.5-u*u-d*d;if(v>0){let e=T[m+c+w[h+l]]*3;v*=v,g+=v*v*(E[e]*u+E[e+1]*d)}let y=.5-f*f-p*p;if(y>0){let e=T[m+1+w[h+1]]*3;y*=y,g+=y*y*(E[e]*f+E[e+1]*p)}return 70*g}var A=1/3,j=1/6;function M(e,t,n){let r=(e+t+n)*A,i=Math.floor(e+r),a=Math.floor(t+r),o=Math.floor(n+r),s=(i+a+o)*j,c=e-(i-s),l=t-(a-s),u=n-(o-s),d,f,p,m,h,g;c>=l?l>=u?[d,f,p,m,h,g]=[1,0,0,1,1,0]:c>=u?[d,f,p,m,h,g]=[1,0,0,1,0,1]:[d,f,p,m,h,g]=[0,0,1,1,0,1]:l<u?[d,f,p,m,h,g]=[0,0,1,0,1,1]:c<u?[d,f,p,m,h,g]=[0,1,0,0,1,1]:[d,f,p,m,h,g]=[0,1,0,1,1,0];let _=c-d+j,v=l-f+j,y=u-p+j,b=c-m+2*j,x=l-h+2*j,S=u-g+2*j,C=c-1+3*j,D=l-1+3*j,O=u-1+3*j,k=i&255,M=a&255,N=o&255,P=0,F=(e,t,n,r)=>{let i=.6-e*e-t*t-n*n;if(i>0){let a=r*3;i*=i,P+=i*i*(E[a]*e+E[a+1]*t+E[a+2]*n)}};return F(c,l,u,T[k+w[M+w[N]]]),F(_,v,y,T[k+d+w[M+f+w[N+p]]]),F(b,x,S,T[k+m+w[M+h+w[N+g]]]),F(C,D,O,T[k+1+w[M+1+w[N+1]]]),32*P}function N(e,t,n,r=2,i=.5){let a=0,o=1,s=1,c=0;for(let l=0;l<n;l++)a+=o*k(e*s+l*17.31,t*s-l*9.17),c+=o,o*=i,s*=r;return c>0?a/c:0}function P(e,t,n,r,i=2,a=.5){let o=0,s=1,c=1,l=0;for(let u=0;u<r;u++)o+=s*M(e*c+u*17.31,t*c-u*9.17,n*c+u*3.7),l+=s,s*=a,c*=i;return l>0?o/l:0}function F(e,t,n,r=2,i=.5){let a=0,o=1,s=1,c=0;for(let l=0;l<n;l++){let n=1-Math.abs(k(e*s+l*31.7,t*s+l*11.3));a+=o*n*n,c+=o,o*=i,s*=r}return c>0?a/c:0}function I(e,t){return!t||!(e>0)||e>=t?1:Math.min(t/e,3)}function L(e,t){return t<=1?e:Math.min(100,2*Math.atan(Math.tan(e*c/2)*t)/c)}function R(e){let t=/^\s*([\d.]+)\s*[:/x]\s*([\d.]+)\s*$/.exec(e??``),n=t?Number(t[1])/Number(t[2]):void 0;return n&&Number.isFinite(n)&&n>0?n:void 0}function z(e,t){let n=t.x-e.x,r=t.y-e.y,i=t.z-e.z,a=Math.hypot(n,r,i);if(a<1e-9)return;let o=-1e-4/a;e.set(e.x+n*o,e.y+r*o,e.z+i*o)}function B(e,i){let a=s(e.near,.1),o=s(e.far,1e3),c;if(e.type===`orthographic`){let n=s(e.zoom,10)/2;c=new t(-n*i,n*i,n,-n,a,o)}else c=new r(s(e.fov,45),i,a,o);c.position.set(...e.position);let l=e.target??[0,0,0];return z(c.position,new n(l[0],l[1],l[2])),c.lookAt(l[0],l[1],l[2]),c}function V(e,n,i,a){let o=I(i,a);if(e.userData.fitScale=o,e instanceof r)e.aspect=i,e.fov=L(s(e.userData.restFov,s(n.fov,45)),o),e.updateProjectionMatrix();else if(e instanceof t){let t=(e.userData.zoomHeight??s(n.zoom,10))/2*o;e.left=-t*i,e.right=t*i,e.top=t,e.bottom=-t,e.updateProjectionMatrix()}}async function H(i,a,u,d){let f=new n(...i.target??[0,0,0]),p={position:new n(...i.position),target:f.clone(),fov:s(i.fov,45),zoom:s(i.zoom,10)},m=i.controls??`none`,h=p.position.clone(),g=p.target.clone(),v=new e,y=new n,b=!0,x=null;if(m===`orbit`&&u&&!d){let{OrbitControls:e}=await l(async()=>{let{OrbitControls:e}=await import(`./OrbitControls-MlE9XiCg.js`);return{OrbitControls:e}},__vite__mapDeps([0,1]),import.meta.url),t=new e(a,u);t.target.copy(p.target),t.enableDamping=!0,t.dampingFactor=.08,t.enableZoom=i.orbitZoom!==!1,t.enablePan=!1;let n=i.orbitLimits??{};n.minDistance!==void 0&&(t.minDistance=n.minDistance),n.maxDistance!==void 0&&(t.maxDistance=n.maxDistance),n.minPolar!==void 0&&(t.minPolarAngle=n.minPolar*c),n.maxPolar!==void 0&&(t.maxPolarAngle=n.maxPolar*c),n.minAzimuth!==void 0&&(t.minAzimuthAngle=n.minAzimuth*c),n.maxAzimuth!==void 0&&(t.maxAzimuthAngle=n.maxAzimuth*c),i.autoRotate&&(t.autoRotate=!0,t.autoRotateSpeed=i.autoRotate/360*60),x=t}let S=new n,C=new n;return{rest:p,shake:y,orbit:x,update(e,l,u){if(a instanceof r){a.userData.restFov=p.fov;let e=L(p.fov,s(a.userData.fitScale,1));a.fov!==e&&(a.fov=e,a.updateProjectionMatrix())}else if(a instanceof t&&s(a.userData.zoomHeight,s(i.zoom,10))!==p.zoom){a.userData.zoomHeight=p.zoom;let e=(a.right-a.left)/Math.max(a.top-a.bottom,1e-6),t=p.zoom/2*s(a.userData.fitScale,1);a.left=-t*e,a.right=t*e,a.top=t,a.bottom=-t,a.updateProjectionMatrix()}if(x){x.update(),a.position.add(y);return}let d=S.copy(p.position),f=g;if(m===`scroll`&&i.scrollPath?.length){let e=i.scrollPath,t=o(u.scroll,0,1)*(e.length-1),r=Math.min(Math.floor(t),e.length-2),a=e.length===1?0:t-Math.max(r,0),s=a*a*(3-2*a),c=e[Math.max(r,0)],l=e[Math.min(Math.max(r,0)+1,e.length-1)];d.set(...c.position).lerp(new n(...l.position),s);let p=new n(...c.target??i.target??[0,0,0]),m=new n(...l.target??i.target??[0,0,0]);f.copy(p.lerp(m,s))}else if(m===`follow`&&u.followTarget){let e=i.follow??{target:``},t=u.followTarget.getWorldPosition(new n),r=new n(...e.offset??[0,4,8]),a=t.clone().add(r),o=t.clone().add(new n(0,0,-s(e.lookAhead,0))),c=b?1:_(s(e.smoothing,.85),l);h.lerp(a,c),f.lerp(o,c),d=S.copy(h)}else f.copy(p.target);if(u.lookAt&&f.copy(u.lookAt),i.autoRotate&&m!==`follow`){let t=i.autoRotate*c*e,r=d.clone().sub(f);r.applyAxisAngle(new n(0,1,0),t),d.copy(f).add(r)}if(m===`parallax`){let e=i.parallax??{},t=s(e.strength,.5),r=_(s(e.smoothing,.92),l);v.x+=(u.pointer.x*t-v.x)*r,v.y+=(u.pointer.y*t*.6-v.y)*r;let o=f.clone().sub(d).normalize(),c=new n().crossVectors(o,a.up).normalize(),p=new n().crossVectors(c,o).normalize();d.addScaledVector(c,v.x).addScaledVector(p,v.y)}if(i.shake){let t=i.shake,r=s(t.speed,.5),o=s(t.amount,.03),l=s(t.rotation,.4)*c,u=s(t.seed,1)*17.31,p=t=>k(e*r+u,t*7.13)*.75+k(e*r*2.7+u,t*7.13+3.1)*.25,m=f.clone().sub(d),h=m.length()||1;m.divideScalar(h);let g=new n().crossVectors(m,a.up).normalize(),_=new n().crossVectors(g,m).normalize();d.addScaledVector(g,p(0)*o).addScaledVector(_,p(1)*o),C.copy(f).addScaledVector(g,Math.tan(p(2)*l)*h).addScaledVector(_,Math.tan(p(3)*l)*h)}else C.copy(f);a.position.copy(d).add(y),z(a.position,C),a.lookAt(C),b=!1},dispose(){x?.dispose()}}}export{_,S as a,f as b,C as c,F as d,u as f,x as g,v as h,R as i,k as l,y as m,H as n,N as o,p,V as r,P as s,B as t,M as u,d as v,g as x,h as y};
@@ -1,4 +1,4 @@
1
- import{OrbitControls as e}from"./OrbitControls-MlE9XiCg.js";import{Bt as t,En as n,Ft as r,Ht as i,I as a,In as o,It as s,Kt as c,Ln as l,N as u,Pt as d,Qt as f,Rt as p,St as m,T as h,an as g,at as _,bt as v,d as y,f as b,h as x,hn as ee,it as te,m as S,mn as C,nt as w,on as T,p as E,st as D,vt as O,w as ne,x as k,xt as A,yn as re,zt as ie}from"./three.module-CnI50X0U.js";import{r as ae}from"./camera-BgzPVnn-.js";import{a as j,i as M,n as N,o as oe}from"./index-L-N-e2KM.js";var P=new f,F=new l,I=new l,L=new c,se={X:new l(1,0,0),Y:new l(0,1,0),Z:new l(0,0,1)},R={type:`change`},z={type:`mouseDown`,mode:null},ce={type:`mouseUp`,mode:null},le={type:`objectChange`},ue=class extends ne{constructor(e,t=null){super(void 0,t);let n=new ve(this);this._root=n;let r=new ye;this._gizmo=r,n.add(r);let i=new be;this._plane=i,n.add(i);let a=this;function o(e,t){let n=t;Object.defineProperty(a,e,{get:function(){return n===void 0?t:n},set:function(t){n!==t&&(n=t,i[e]=t,r[e]=t,a.dispatchEvent({type:e+`-changed`,value:t}),a.dispatchEvent(R))}}),a[e]=t,i[e]=t,r[e]=t}o(`camera`,e),o(`object`,void 0),o(`enabled`,!0),o(`axis`,null),o(`mode`,`translate`),o(`translationSnap`,null),o(`rotationSnap`,null),o(`scaleSnap`,null),o(`space`,`world`),o(`size`,1),this.viewport=null,o(`dragging`,!1),o(`showX`,!0),o(`showY`,!0),o(`showZ`,!0),o(`showXY`,!0),o(`showYZ`,!0),o(`showXZ`,!0),o(`showXYZE`,!0),o(`showE`,!0),o(`minX`,-1/0),o(`maxX`,1/0),o(`minY`,-1/0),o(`maxY`,1/0),o(`minZ`,-1/0),o(`maxZ`,1/0);let s=new l,u=new l,d=new c,f=new c,p=new l,m=new c,h=new l,g=new l,_=new l,v=new l;o(`worldPosition`,s),o(`worldPositionStart`,u),o(`worldQuaternion`,d),o(`worldQuaternionStart`,f),o(`cameraPosition`,p),o(`cameraQuaternion`,m),o(`pointStart`,h),o(`pointEnd`,g),o(`rotationAxis`,_),o(`rotationAngle`,0),o(`eye`,v),this._offset=new l,this._startNorm=new l,this._endNorm=new l,this._cameraScale=new l,this._parentPosition=new l,this._parentQuaternion=new c,this._parentQuaternionInv=new c,this._parentScale=new l,this._worldScaleStart=new l,this._worldQuaternionInv=new c,this._worldScale=new l,this._positionStart=new l,this._quaternionStart=new c,this._scaleStart=new l,this._getPointer=de.bind(this),this._onPointerDown=pe.bind(this),this._onPointerHover=fe.bind(this),this._onPointerMove=me.bind(this),this._onPointerUp=he.bind(this),t!==null&&this.connect(t)}connect(e){super.connect(e),this.domElement.addEventListener(`pointerdown`,this._onPointerDown),this.domElement.addEventListener(`pointermove`,this._onPointerHover),this.domElement.addEventListener(`pointerup`,this._onPointerUp),this.domElement.style.touchAction=`none`}disconnect(){this.domElement.removeEventListener(`pointerdown`,this._onPointerDown),this.domElement.removeEventListener(`pointermove`,this._onPointerHover),this.domElement.removeEventListener(`pointermove`,this._onPointerMove),this.domElement.removeEventListener(`pointerup`,this._onPointerUp),this.domElement.style.touchAction=``}getHelper(){return this._root}pointerHover(e){if(this.object===void 0||this.dragging===!0)return;e!==null&&P.setFromCamera(e,this.camera);let t=B(this._gizmo.picker[this.mode],P);this.axis=t?t.object.name:null}pointerDown(e){if(!(this.object===void 0||this.dragging===!0||e!=null&&e.button!==0)&&this.axis!==null){e!==null&&P.setFromCamera(e,this.camera);let t=B(this._plane,P,!0);t&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(t.point).sub(this.worldPositionStart)),this.dragging=!0,z.mode=this.mode,this.dispatchEvent(z)}}pointerMove(e){let t=this.axis,n=this.mode,r=this.object,i=this.space;if(n===`scale`?i=`local`:(t===`E`||t===`XYZE`||t===`XYZ`)&&(i=`world`),r===void 0||t===null||this.dragging===!1||e!==null&&e.button!==-1)return;e!==null&&P.setFromCamera(e,this.camera);let a=B(this._plane,P,!0);if(a){if(this.pointEnd.copy(a.point).sub(this.worldPositionStart),n===`translate`)this._offset.copy(this.pointEnd).sub(this.pointStart),i===`local`&&t!==`XYZ`&&this._offset.applyQuaternion(this._worldQuaternionInv),t.indexOf(`X`)===-1&&(this._offset.x=0),t.indexOf(`Y`)===-1&&(this._offset.y=0),t.indexOf(`Z`)===-1&&(this._offset.z=0),i===`local`&&t!==`XYZ`?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),r.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(i===`local`&&(r.position.applyQuaternion(L.copy(this._quaternionStart).invert()),t.search(`X`)!==-1&&(r.position.x=Math.round(r.position.x/this.translationSnap)*this.translationSnap),t.search(`Y`)!==-1&&(r.position.y=Math.round(r.position.y/this.translationSnap)*this.translationSnap),t.search(`Z`)!==-1&&(r.position.z=Math.round(r.position.z/this.translationSnap)*this.translationSnap),r.position.applyQuaternion(this._quaternionStart)),i===`world`&&(r.getWorldPosition(F),t.search(`X`)!==-1&&(F.x=Math.round(F.x/this.translationSnap)*this.translationSnap),t.search(`Y`)!==-1&&(F.y=Math.round(F.y/this.translationSnap)*this.translationSnap),t.search(`Z`)!==-1&&(F.z=Math.round(F.z/this.translationSnap)*this.translationSnap),r.position.copy(r.parent.worldToLocal(F)))),r.position.x=Math.max(this.minX,Math.min(this.maxX,r.position.x)),r.position.y=Math.max(this.minY,Math.min(this.maxY,r.position.y)),r.position.z=Math.max(this.minZ,Math.min(this.maxZ,r.position.z));else if(n===`scale`){if(t.search(`XYZ`)!==-1){let e=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(e*=-1),I.set(e,e,e)}else F.copy(this.pointStart),I.copy(this.pointEnd),F.applyQuaternion(this._worldQuaternionInv),I.applyQuaternion(this._worldQuaternionInv),I.divide(F),t.search(`X`)===-1&&(I.x=1),t.search(`Y`)===-1&&(I.y=1),t.search(`Z`)===-1&&(I.z=1);r.scale.copy(this._scaleStart).multiply(I),this.scaleSnap&&(t.search(`X`)!==-1&&(r.scale.x=Math.round(r.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search(`Y`)!==-1&&(r.scale.y=Math.round(r.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search(`Z`)!==-1&&(r.scale.z=Math.round(r.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(n===`rotate`){this._offset.copy(this.pointEnd).sub(this.pointStart);let e=20/this.worldPosition.distanceTo(F.setFromMatrixPosition(this.camera.matrixWorld)),n=!1;t===`XYZE`?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(F.copy(this.rotationAxis).cross(this.eye))*e):(t===`X`||t===`Y`||t===`Z`)&&(this.rotationAxis.copy(se[t]),F.copy(se[t]),i===`local`&&F.applyQuaternion(this.worldQuaternion),F.cross(this.eye),F.length()===0?n=!0:this.rotationAngle=this._offset.dot(F.normalize())*e),(t===`E`||n)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),i===`local`&&t!==`E`&&t!==`XYZE`?(r.quaternion.copy(this._quaternionStart),r.quaternion.multiply(L.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),r.quaternion.copy(L.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),r.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(R),this.dispatchEvent(le)}}pointerUp(e){(e===null||e.button===0)&&(this.dragging&&this.axis!==null&&(ce.mode=this.mode,this.dispatchEvent(ce)),this.dragging=!1,this.axis=null)}dispose(){this.disconnect(),this._root.dispose()}attach(e){return this.object=e,this._root.visible=!0,this}detach(){return this.object=void 0,this.axis=null,this._root.visible=!1,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(R),this.dispatchEvent(le),this.pointStart.copy(this.pointEnd))}getRaycaster(){return P}getMode(){return this.mode}setMode(e){this.mode=e}setTranslationSnap(e){this.translationSnap=e}setRotationSnap(e){this.rotationSnap=e}setScaleSnap(e){this.scaleSnap=e}setSize(e){this.size=e}setSpace(e){this.space=e}setColors(e,t,n,r){let i=this._gizmo.materialLib;i.xAxis.color.set(e),i.yAxis.color.set(t),i.zAxis.color.set(n),i.active.color.set(r),i.xAxisTransparent.color.set(e),i.yAxisTransparent.color.set(t),i.zAxisTransparent.color.set(n),i.activeTransparent.color.set(r),i.xAxis._color&&i.xAxis._color.set(e),i.yAxis._color&&i.yAxis._color.set(t),i.zAxis._color&&i.zAxis._color.set(n),i.active._color&&i.active._color.set(r),i.xAxisTransparent._color&&i.xAxisTransparent._color.set(e),i.yAxisTransparent._color&&i.yAxisTransparent._color.set(t),i.zAxisTransparent._color&&i.zAxisTransparent._color.set(n),i.activeTransparent._color&&i.activeTransparent._color.set(r)}};function de(e){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:e.button};{let t=this.domElement.getBoundingClientRect(),n=this.viewport,r,i,a,o;return n===null?(r=0,i=0,a=t.width,o=t.height):(r=n.x,i=t.height-n.y-n.w,a=n.z,o=n.w),{x:(e.clientX-t.left-r)/a*2-1,y:-(e.clientY-t.top-i)/o*2+1,button:e.button}}}function fe(e){if(this.enabled)switch(e.pointerType){case`mouse`:case`pen`:this.pointerHover(this._getPointer(e))}}function pe(e){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(e.pointerId),this.domElement.addEventListener(`pointermove`,this._onPointerMove),this.pointerHover(this._getPointer(e)),this.pointerDown(this._getPointer(e)))}function me(e){this.enabled&&this.pointerMove(this._getPointer(e))}function he(e){this.enabled&&(this.domElement.releasePointerCapture(e.pointerId),this.domElement.removeEventListener(`pointermove`,this._onPointerMove),this.pointerUp(this._getPointer(e)))}function B(e,t,n){let r=t.intersectObject(e,!0);for(let e=0;e<r.length;e++)if(r[e].object.visible||n)return r[e];return!1}var V=new u,H=new l(0,1,0),ge=new l(0,0,0),_e=new v,U=new c,W=new c,G=new l,K=new v,q=new l(1,0,0),J=new l(0,1,0),Y=new l(0,0,1),X=new l,Z=new l,Q=new l,ve=class extends d{constructor(e){super(),this.isTransformControlsRoot=!0,this.controls=e,this.visible=!1}updateMatrixWorld(e){let t=this.controls;t.object!==void 0&&(t.object.updateMatrixWorld(),t.object.parent===null?console.error(`TransformControls: The attached 3D object must be a part of the scene graph.`):t.object.parent.matrixWorld.decompose(t._parentPosition,t._parentQuaternion,t._parentScale),t.object.matrixWorld.decompose(t.worldPosition,t.worldQuaternion,t._worldScale),t._parentQuaternionInv.copy(t._parentQuaternion).invert(),t._worldQuaternionInv.copy(t.worldQuaternion).invert()),t.camera.updateMatrixWorld(),t.camera.matrixWorld.decompose(t.cameraPosition,t.cameraQuaternion,t._cameraScale),t.camera.isOrthographicCamera?t.camera.getWorldDirection(t.eye).negate():t.eye.copy(t.cameraPosition).sub(t.worldPosition).normalize(),this.parent&&(K.copy(this.parent.matrixWorld).invert(),K.decompose(this.position,this.quaternion,this.scale)),super.updateMatrixWorld(e)}dispose(){this.traverse(function(e){e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose()})}},ye=class extends d{constructor(){super(),this.isTransformControlsGizmo=!0,this.type=`TransformControlsGizmo`;let e=new m({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),t=new te({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),i=e.clone();i.opacity=.15;let o=t.clone();o.opacity=.5;let s=e.clone();s.color.setHex(16711680);let c=e.clone();c.color.setHex(65280);let l=e.clone();l.color.setHex(255);let u=e.clone();u.color.setHex(16711680),u.opacity=.5;let f=e.clone();f.color.setHex(65280),f.opacity=.5;let p=e.clone();p.color.setHex(255),p.opacity=.5;let g=e.clone();g.opacity=.25;let _=e.clone();_.color.setHex(16776960),_.opacity=.25;let v=e.clone();v.color.setHex(16776960);let y=e.clone();y.color.setHex(7895160),this.materialLib={xAxis:s,yAxis:c,zAxis:l,active:v,xAxisTransparent:u,yAxisTransparent:f,zAxisTransparent:p,activeTransparent:_};let b=new h(0,.04,.1,12);b.translate(0,.05,0);let S=new E(.08,.08,.08);S.translate(0,.04,0);let C=new x;C.setAttribute(`position`,new a([0,0,0,1,0,0],3));let T=new h(.0075,.0075,.5,3);T.translate(0,.25,0);function D(e,t){let r=new n(e,.0075,3,64,t*Math.PI*2);return r.rotateY(Math.PI/2),r.rotateX(Math.PI/2),r}function O(){let e=new x;return e.setAttribute(`position`,new a([0,0,0,1,1,1],3)),e}let ne={X:[[new A(b,s),[.5,0,0],[0,0,-Math.PI/2]],[new A(b,s),[-.5,0,0],[0,0,Math.PI/2]],[new A(T,s),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new A(b,c),[0,.5,0]],[new A(b,c),[0,-.5,0],[Math.PI,0,0]],[new A(T,c)]],Z:[[new A(b,l),[0,0,.5],[Math.PI/2,0,0]],[new A(b,l),[0,0,-.5],[-Math.PI/2,0,0]],[new A(T,l),null,[Math.PI/2,0,0]]],XYZ:[[new A(new r(.1,0),g),[0,0,0]]],XY:[[new A(new E(.15,.15,.01),p),[.15,.15,0]]],YZ:[[new A(new E(.15,.15,.01),u),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.15,.15,.01),f),[.15,0,.15],[-Math.PI/2,0,0]]]},k={X:[[new A(new h(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new A(new h(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new A(new h(.2,0,.6,4),i),[0,.3,0]],[new A(new h(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new A(new h(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new A(new h(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new A(new r(.2,0),i)]],XY:[[new A(new E(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new A(new E(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]]},re={START:[[new A(new r(.01,2),o),null,null,null,`helper`]],END:[[new A(new r(.01,2),o),null,null,null,`helper`]],DELTA:[[new w(O(),o),null,null,null,`helper`]],X:[[new w(C,o),[-1e3,0,0],null,[1e6,1,1],`helper`]],Y:[[new w(C,o),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],`helper`]],Z:[[new w(C,o),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],`helper`]]},ie={XYZE:[[new A(D(.5,1),y),null,[0,Math.PI/2,0]]],X:[[new A(D(.5,.5),s)]],Y:[[new A(D(.5,.5),c),null,[0,0,-Math.PI/2]]],Z:[[new A(D(.5,.5),l),null,[0,Math.PI/2,0]]],E:[[new A(D(.75,1),_),null,[0,Math.PI/2,0]]]},ae={AXIS:[[new w(C,o),[-1e3,0,0],null,[1e6,1,1],`helper`]]},j={XYZE:[[new A(new ee(.25,10,8),i)]],X:[[new A(new n(.5,.1,4,24),i),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new A(new n(.5,.1,4,24),i),[0,0,0],[Math.PI/2,0,0]]],Z:[[new A(new n(.5,.1,4,24),i),[0,0,0],[0,0,-Math.PI/2]]],E:[[new A(new n(.75,.1,2,24),i)]]},M={X:[[new A(S,s),[.5,0,0],[0,0,-Math.PI/2]],[new A(T,s),[0,0,0],[0,0,-Math.PI/2]],[new A(S,s),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new A(S,c),[0,.5,0]],[new A(T,c)],[new A(S,c),[0,-.5,0],[0,0,Math.PI]]],Z:[[new A(S,l),[0,0,.5],[Math.PI/2,0,0]],[new A(T,l),[0,0,0],[Math.PI/2,0,0]],[new A(S,l),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new A(new E(.15,.15,.01),p),[.15,.15,0]]],YZ:[[new A(new E(.15,.15,.01),u),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.15,.15,.01),f),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new A(new E(.1,.1,.1),g)]]},N={X:[[new A(new h(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new A(new h(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new A(new h(.2,0,.6,4),i),[0,.3,0]],[new A(new h(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new A(new h(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new A(new h(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new A(new E(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new A(new E(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new A(new E(.2,.2,.2),i),[0,0,0]]]},oe={X:[[new w(C,o),[-1e3,0,0],null,[1e6,1,1],`helper`]],Y:[[new w(C,o),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],`helper`]],Z:[[new w(C,o),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],`helper`]]};function P(e){let t=new d;for(let n in e)for(let r=e[n].length;r--;){let i=e[n][r][0].clone(),a=e[n][r][1],o=e[n][r][2],s=e[n][r][3],c=e[n][r][4];i.name=n,i.tag=c,a&&i.position.set(a[0],a[1],a[2]),o&&i.rotation.set(o[0],o[1],o[2]),s&&i.scale.set(s[0],s[1],s[2]),i.updateMatrix();let l=i.geometry.clone();l.applyMatrix4(i.matrix),i.geometry=l,i.renderOrder=1/0,i.position.set(0,0,0),i.rotation.set(0,0,0),i.scale.set(1,1,1),t.add(i)}return t}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=P(ne)),this.add(this.gizmo.rotate=P(ie)),this.add(this.gizmo.scale=P(M)),this.add(this.picker.translate=P(k)),this.add(this.picker.rotate=P(j)),this.add(this.picker.scale=P(N)),this.add(this.helper.translate=P(re)),this.add(this.helper.rotate=P(ae)),this.add(this.helper.scale=P(oe)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(e){let t=(this.mode===`scale`?`local`:this.space)===`local`?this.worldQuaternion:W;this.gizmo.translate.visible=this.mode===`translate`,this.gizmo.rotate.visible=this.mode===`rotate`,this.gizmo.scale.visible=this.mode===`scale`,this.helper.translate.visible=this.mode===`translate`,this.helper.rotate.visible=this.mode===`rotate`,this.helper.scale.visible=this.mode===`scale`;let n=[];n=n.concat(this.picker[this.mode].children),n=n.concat(this.gizmo[this.mode].children),n=n.concat(this.helper[this.mode].children);for(let e=0;e<n.length;e++){let r=n[e];r.visible=!0,r.rotation.set(0,0,0),r.position.copy(this.worldPosition);let i;if(i=this.camera.isOrthographicCamera?(this.camera.top-this.camera.bottom)/this.camera.zoom:this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),r.scale.set(1,1,1).multiplyScalar(i*this.size/4),r.tag===`helper`)r.visible=!1,r.name===`AXIS`?(r.visible=!!this.axis,this.axis===`X`&&(L.setFromEuler(V.set(0,0,0)),r.quaternion.copy(t).multiply(L),Math.abs(H.copy(q).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),this.axis===`Y`&&(L.setFromEuler(V.set(0,0,Math.PI/2)),r.quaternion.copy(t).multiply(L),Math.abs(H.copy(J).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),this.axis===`Z`&&(L.setFromEuler(V.set(0,Math.PI/2,0)),r.quaternion.copy(t).multiply(L),Math.abs(H.copy(Y).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),this.axis===`XYZE`&&(L.setFromEuler(V.set(0,Math.PI/2,0)),H.copy(this.rotationAxis),r.quaternion.setFromRotationMatrix(_e.lookAt(ge,H,J)),r.quaternion.multiply(L),r.visible=this.dragging),this.axis===`E`&&(r.visible=!1)):r.name===`START`?(r.position.copy(this.worldPositionStart),r.visible=this.dragging):r.name===`END`?(r.position.copy(this.worldPosition),r.visible=this.dragging):r.name===`DELTA`?(r.position.copy(this.worldPositionStart),r.quaternion.copy(this.worldQuaternionStart),F.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),F.applyQuaternion(this.worldQuaternionStart.clone().invert()),r.scale.copy(F),r.visible=this.dragging):(r.quaternion.copy(t),this.dragging?r.position.copy(this.worldPositionStart):r.position.copy(this.worldPosition),this.axis&&(r.visible=this.axis.search(r.name)!==-1));else{if(r.quaternion.copy(t),this.mode===`translate`||this.mode===`scale`){let e=.99,n=.2;r.name===`X`&&Math.abs(H.copy(q).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`Y`&&Math.abs(H.copy(J).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`Z`&&Math.abs(H.copy(Y).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`XY`&&Math.abs(H.copy(Y).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`YZ`&&Math.abs(H.copy(q).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`XZ`&&Math.abs(H.copy(J).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1)}else this.mode===`rotate`&&(U.copy(t),H.copy(this.eye).applyQuaternion(L.copy(t).invert()),r.name.search(`E`)!==-1&&r.quaternion.setFromRotationMatrix(_e.lookAt(this.eye,ge,J)),r.name===`X`&&(L.setFromAxisAngle(q,Math.atan2(-H.y,H.z)),L.multiplyQuaternions(U,L),r.quaternion.copy(L)),r.name===`Y`&&(L.setFromAxisAngle(J,Math.atan2(H.x,H.z)),L.multiplyQuaternions(U,L),r.quaternion.copy(L)),r.name===`Z`&&(L.setFromAxisAngle(Y,Math.atan2(H.y,H.x)),L.multiplyQuaternions(U,L),r.quaternion.copy(L)));r.visible=r.visible&&(r.name.indexOf(`X`)===-1||this.showX),r.visible=r.visible&&(r.name.indexOf(`Y`)===-1||this.showY),r.visible=r.visible&&(r.name.indexOf(`Z`)===-1||this.showZ),r.visible=r.visible&&(r.name.indexOf(`E`)===-1||this.showX&&this.showY&&this.showZ),r.visible=r.visible&&(r.name.indexOf(`XY`)===-1||this.showXY),r.visible=r.visible&&(r.name.indexOf(`YZ`)===-1||this.showYZ),r.visible=r.visible&&(r.name.indexOf(`XZ`)===-1||this.showXZ),r.visible=r.visible&&(r.name!==`E`||this.showE),r.visible=r.visible&&(r.name!==`XYZE`||this.showXYZE),r.material._color=r.material._color||r.material.color.clone(),r.material._opacity=r.material._opacity||r.material.opacity,r.material.color.copy(r.material._color),r.material.opacity=r.material._opacity,this.enabled&&this.axis&&(r.name===this.axis||this.axis.split(``).some(function(e){return r.name===e}))&&(r.material.color.copy(this.materialLib.active.color),r.material.opacity=1)}}super.updateMatrixWorld(e)}},be=class extends A{constructor(){super(new t(1e5,1e5,2,2),new m({visible:!1,wireframe:!0,side:2,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type=`TransformControlsPlane`}updateMatrixWorld(e){let t=this.space;switch(this.position.copy(this.worldPosition),this.mode===`scale`&&(t=`local`),X.copy(q).applyQuaternion(t===`local`?this.worldQuaternion:W),Z.copy(J).applyQuaternion(t===`local`?this.worldQuaternion:W),Q.copy(Y).applyQuaternion(t===`local`?this.worldQuaternion:W),H.copy(Z),this.mode){case`translate`:case`scale`:switch(this.axis){case`X`:H.copy(this.eye).cross(X),G.copy(X).cross(H);break;case`Y`:H.copy(this.eye).cross(Z),G.copy(Z).cross(H);break;case`Z`:H.copy(this.eye).cross(Q),G.copy(Q).cross(H);break;case`XY`:G.copy(Q);break;case`YZ`:G.copy(X);break;case`XZ`:H.copy(Q),G.copy(Z);break;case`XYZ`:case`E`:G.set(0,0,0)}break;default:G.set(0,0,0)}G.length()===0?this.quaternion.copy(this.cameraQuaternion):(K.lookAt(F.set(0,0,0),G,H),this.quaternion.setFromRotationMatrix(K)),super.updateMatrixWorld(e)}},xe=`
1
+ import{OrbitControls as e}from"./OrbitControls-MlE9XiCg.js";import{Bt as t,En as n,Ft as r,Ht as i,I as a,In as o,It as s,Kt as c,Ln as l,N as u,Pt as d,Qt as f,Rt as p,St as m,T as h,an as g,at as _,bt as v,d as y,f as b,h as x,hn as ee,it as te,m as S,mn as C,nt as w,on as T,p as E,st as D,vt as O,w as ne,x as k,xt as A,yn as re,zt as ie}from"./three.module-CnI50X0U.js";import{r as ae}from"./camera-C0sxfRxy.js";import{a as j,i as M,n as N,o as oe}from"./index-C2nMYSoW.js";var P=new f,F=new l,I=new l,L=new c,se={X:new l(1,0,0),Y:new l(0,1,0),Z:new l(0,0,1)},R={type:`change`},z={type:`mouseDown`,mode:null},ce={type:`mouseUp`,mode:null},le={type:`objectChange`},ue=class extends ne{constructor(e,t=null){super(void 0,t);let n=new ve(this);this._root=n;let r=new ye;this._gizmo=r,n.add(r);let i=new be;this._plane=i,n.add(i);let a=this;function o(e,t){let n=t;Object.defineProperty(a,e,{get:function(){return n===void 0?t:n},set:function(t){n!==t&&(n=t,i[e]=t,r[e]=t,a.dispatchEvent({type:e+`-changed`,value:t}),a.dispatchEvent(R))}}),a[e]=t,i[e]=t,r[e]=t}o(`camera`,e),o(`object`,void 0),o(`enabled`,!0),o(`axis`,null),o(`mode`,`translate`),o(`translationSnap`,null),o(`rotationSnap`,null),o(`scaleSnap`,null),o(`space`,`world`),o(`size`,1),this.viewport=null,o(`dragging`,!1),o(`showX`,!0),o(`showY`,!0),o(`showZ`,!0),o(`showXY`,!0),o(`showYZ`,!0),o(`showXZ`,!0),o(`showXYZE`,!0),o(`showE`,!0),o(`minX`,-1/0),o(`maxX`,1/0),o(`minY`,-1/0),o(`maxY`,1/0),o(`minZ`,-1/0),o(`maxZ`,1/0);let s=new l,u=new l,d=new c,f=new c,p=new l,m=new c,h=new l,g=new l,_=new l,v=new l;o(`worldPosition`,s),o(`worldPositionStart`,u),o(`worldQuaternion`,d),o(`worldQuaternionStart`,f),o(`cameraPosition`,p),o(`cameraQuaternion`,m),o(`pointStart`,h),o(`pointEnd`,g),o(`rotationAxis`,_),o(`rotationAngle`,0),o(`eye`,v),this._offset=new l,this._startNorm=new l,this._endNorm=new l,this._cameraScale=new l,this._parentPosition=new l,this._parentQuaternion=new c,this._parentQuaternionInv=new c,this._parentScale=new l,this._worldScaleStart=new l,this._worldQuaternionInv=new c,this._worldScale=new l,this._positionStart=new l,this._quaternionStart=new c,this._scaleStart=new l,this._getPointer=de.bind(this),this._onPointerDown=pe.bind(this),this._onPointerHover=fe.bind(this),this._onPointerMove=me.bind(this),this._onPointerUp=he.bind(this),t!==null&&this.connect(t)}connect(e){super.connect(e),this.domElement.addEventListener(`pointerdown`,this._onPointerDown),this.domElement.addEventListener(`pointermove`,this._onPointerHover),this.domElement.addEventListener(`pointerup`,this._onPointerUp),this.domElement.style.touchAction=`none`}disconnect(){this.domElement.removeEventListener(`pointerdown`,this._onPointerDown),this.domElement.removeEventListener(`pointermove`,this._onPointerHover),this.domElement.removeEventListener(`pointermove`,this._onPointerMove),this.domElement.removeEventListener(`pointerup`,this._onPointerUp),this.domElement.style.touchAction=``}getHelper(){return this._root}pointerHover(e){if(this.object===void 0||this.dragging===!0)return;e!==null&&P.setFromCamera(e,this.camera);let t=B(this._gizmo.picker[this.mode],P);this.axis=t?t.object.name:null}pointerDown(e){if(!(this.object===void 0||this.dragging===!0||e!=null&&e.button!==0)&&this.axis!==null){e!==null&&P.setFromCamera(e,this.camera);let t=B(this._plane,P,!0);t&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(t.point).sub(this.worldPositionStart)),this.dragging=!0,z.mode=this.mode,this.dispatchEvent(z)}}pointerMove(e){let t=this.axis,n=this.mode,r=this.object,i=this.space;if(n===`scale`?i=`local`:(t===`E`||t===`XYZE`||t===`XYZ`)&&(i=`world`),r===void 0||t===null||this.dragging===!1||e!==null&&e.button!==-1)return;e!==null&&P.setFromCamera(e,this.camera);let a=B(this._plane,P,!0);if(a){if(this.pointEnd.copy(a.point).sub(this.worldPositionStart),n===`translate`)this._offset.copy(this.pointEnd).sub(this.pointStart),i===`local`&&t!==`XYZ`&&this._offset.applyQuaternion(this._worldQuaternionInv),t.indexOf(`X`)===-1&&(this._offset.x=0),t.indexOf(`Y`)===-1&&(this._offset.y=0),t.indexOf(`Z`)===-1&&(this._offset.z=0),i===`local`&&t!==`XYZ`?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),r.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(i===`local`&&(r.position.applyQuaternion(L.copy(this._quaternionStart).invert()),t.search(`X`)!==-1&&(r.position.x=Math.round(r.position.x/this.translationSnap)*this.translationSnap),t.search(`Y`)!==-1&&(r.position.y=Math.round(r.position.y/this.translationSnap)*this.translationSnap),t.search(`Z`)!==-1&&(r.position.z=Math.round(r.position.z/this.translationSnap)*this.translationSnap),r.position.applyQuaternion(this._quaternionStart)),i===`world`&&(r.getWorldPosition(F),t.search(`X`)!==-1&&(F.x=Math.round(F.x/this.translationSnap)*this.translationSnap),t.search(`Y`)!==-1&&(F.y=Math.round(F.y/this.translationSnap)*this.translationSnap),t.search(`Z`)!==-1&&(F.z=Math.round(F.z/this.translationSnap)*this.translationSnap),r.position.copy(r.parent.worldToLocal(F)))),r.position.x=Math.max(this.minX,Math.min(this.maxX,r.position.x)),r.position.y=Math.max(this.minY,Math.min(this.maxY,r.position.y)),r.position.z=Math.max(this.minZ,Math.min(this.maxZ,r.position.z));else if(n===`scale`){if(t.search(`XYZ`)!==-1){let e=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(e*=-1),I.set(e,e,e)}else F.copy(this.pointStart),I.copy(this.pointEnd),F.applyQuaternion(this._worldQuaternionInv),I.applyQuaternion(this._worldQuaternionInv),I.divide(F),t.search(`X`)===-1&&(I.x=1),t.search(`Y`)===-1&&(I.y=1),t.search(`Z`)===-1&&(I.z=1);r.scale.copy(this._scaleStart).multiply(I),this.scaleSnap&&(t.search(`X`)!==-1&&(r.scale.x=Math.round(r.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search(`Y`)!==-1&&(r.scale.y=Math.round(r.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search(`Z`)!==-1&&(r.scale.z=Math.round(r.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(n===`rotate`){this._offset.copy(this.pointEnd).sub(this.pointStart);let e=20/this.worldPosition.distanceTo(F.setFromMatrixPosition(this.camera.matrixWorld)),n=!1;t===`XYZE`?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(F.copy(this.rotationAxis).cross(this.eye))*e):(t===`X`||t===`Y`||t===`Z`)&&(this.rotationAxis.copy(se[t]),F.copy(se[t]),i===`local`&&F.applyQuaternion(this.worldQuaternion),F.cross(this.eye),F.length()===0?n=!0:this.rotationAngle=this._offset.dot(F.normalize())*e),(t===`E`||n)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),i===`local`&&t!==`E`&&t!==`XYZE`?(r.quaternion.copy(this._quaternionStart),r.quaternion.multiply(L.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),r.quaternion.copy(L.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),r.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(R),this.dispatchEvent(le)}}pointerUp(e){(e===null||e.button===0)&&(this.dragging&&this.axis!==null&&(ce.mode=this.mode,this.dispatchEvent(ce)),this.dragging=!1,this.axis=null)}dispose(){this.disconnect(),this._root.dispose()}attach(e){return this.object=e,this._root.visible=!0,this}detach(){return this.object=void 0,this.axis=null,this._root.visible=!1,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(R),this.dispatchEvent(le),this.pointStart.copy(this.pointEnd))}getRaycaster(){return P}getMode(){return this.mode}setMode(e){this.mode=e}setTranslationSnap(e){this.translationSnap=e}setRotationSnap(e){this.rotationSnap=e}setScaleSnap(e){this.scaleSnap=e}setSize(e){this.size=e}setSpace(e){this.space=e}setColors(e,t,n,r){let i=this._gizmo.materialLib;i.xAxis.color.set(e),i.yAxis.color.set(t),i.zAxis.color.set(n),i.active.color.set(r),i.xAxisTransparent.color.set(e),i.yAxisTransparent.color.set(t),i.zAxisTransparent.color.set(n),i.activeTransparent.color.set(r),i.xAxis._color&&i.xAxis._color.set(e),i.yAxis._color&&i.yAxis._color.set(t),i.zAxis._color&&i.zAxis._color.set(n),i.active._color&&i.active._color.set(r),i.xAxisTransparent._color&&i.xAxisTransparent._color.set(e),i.yAxisTransparent._color&&i.yAxisTransparent._color.set(t),i.zAxisTransparent._color&&i.zAxisTransparent._color.set(n),i.activeTransparent._color&&i.activeTransparent._color.set(r)}};function de(e){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:e.button};{let t=this.domElement.getBoundingClientRect(),n=this.viewport,r,i,a,o;return n===null?(r=0,i=0,a=t.width,o=t.height):(r=n.x,i=t.height-n.y-n.w,a=n.z,o=n.w),{x:(e.clientX-t.left-r)/a*2-1,y:-(e.clientY-t.top-i)/o*2+1,button:e.button}}}function fe(e){if(this.enabled)switch(e.pointerType){case`mouse`:case`pen`:this.pointerHover(this._getPointer(e))}}function pe(e){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(e.pointerId),this.domElement.addEventListener(`pointermove`,this._onPointerMove),this.pointerHover(this._getPointer(e)),this.pointerDown(this._getPointer(e)))}function me(e){this.enabled&&this.pointerMove(this._getPointer(e))}function he(e){this.enabled&&(this.domElement.releasePointerCapture(e.pointerId),this.domElement.removeEventListener(`pointermove`,this._onPointerMove),this.pointerUp(this._getPointer(e)))}function B(e,t,n){let r=t.intersectObject(e,!0);for(let e=0;e<r.length;e++)if(r[e].object.visible||n)return r[e];return!1}var V=new u,H=new l(0,1,0),ge=new l(0,0,0),_e=new v,U=new c,W=new c,G=new l,K=new v,q=new l(1,0,0),J=new l(0,1,0),Y=new l(0,0,1),X=new l,Z=new l,Q=new l,ve=class extends d{constructor(e){super(),this.isTransformControlsRoot=!0,this.controls=e,this.visible=!1}updateMatrixWorld(e){let t=this.controls;t.object!==void 0&&(t.object.updateMatrixWorld(),t.object.parent===null?console.error(`TransformControls: The attached 3D object must be a part of the scene graph.`):t.object.parent.matrixWorld.decompose(t._parentPosition,t._parentQuaternion,t._parentScale),t.object.matrixWorld.decompose(t.worldPosition,t.worldQuaternion,t._worldScale),t._parentQuaternionInv.copy(t._parentQuaternion).invert(),t._worldQuaternionInv.copy(t.worldQuaternion).invert()),t.camera.updateMatrixWorld(),t.camera.matrixWorld.decompose(t.cameraPosition,t.cameraQuaternion,t._cameraScale),t.camera.isOrthographicCamera?t.camera.getWorldDirection(t.eye).negate():t.eye.copy(t.cameraPosition).sub(t.worldPosition).normalize(),this.parent&&(K.copy(this.parent.matrixWorld).invert(),K.decompose(this.position,this.quaternion,this.scale)),super.updateMatrixWorld(e)}dispose(){this.traverse(function(e){e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose()})}},ye=class extends d{constructor(){super(),this.isTransformControlsGizmo=!0,this.type=`TransformControlsGizmo`;let e=new m({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),t=new te({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),i=e.clone();i.opacity=.15;let o=t.clone();o.opacity=.5;let s=e.clone();s.color.setHex(16711680);let c=e.clone();c.color.setHex(65280);let l=e.clone();l.color.setHex(255);let u=e.clone();u.color.setHex(16711680),u.opacity=.5;let f=e.clone();f.color.setHex(65280),f.opacity=.5;let p=e.clone();p.color.setHex(255),p.opacity=.5;let g=e.clone();g.opacity=.25;let _=e.clone();_.color.setHex(16776960),_.opacity=.25;let v=e.clone();v.color.setHex(16776960);let y=e.clone();y.color.setHex(7895160),this.materialLib={xAxis:s,yAxis:c,zAxis:l,active:v,xAxisTransparent:u,yAxisTransparent:f,zAxisTransparent:p,activeTransparent:_};let b=new h(0,.04,.1,12);b.translate(0,.05,0);let S=new E(.08,.08,.08);S.translate(0,.04,0);let C=new x;C.setAttribute(`position`,new a([0,0,0,1,0,0],3));let T=new h(.0075,.0075,.5,3);T.translate(0,.25,0);function D(e,t){let r=new n(e,.0075,3,64,t*Math.PI*2);return r.rotateY(Math.PI/2),r.rotateX(Math.PI/2),r}function O(){let e=new x;return e.setAttribute(`position`,new a([0,0,0,1,1,1],3)),e}let ne={X:[[new A(b,s),[.5,0,0],[0,0,-Math.PI/2]],[new A(b,s),[-.5,0,0],[0,0,Math.PI/2]],[new A(T,s),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new A(b,c),[0,.5,0]],[new A(b,c),[0,-.5,0],[Math.PI,0,0]],[new A(T,c)]],Z:[[new A(b,l),[0,0,.5],[Math.PI/2,0,0]],[new A(b,l),[0,0,-.5],[-Math.PI/2,0,0]],[new A(T,l),null,[Math.PI/2,0,0]]],XYZ:[[new A(new r(.1,0),g),[0,0,0]]],XY:[[new A(new E(.15,.15,.01),p),[.15,.15,0]]],YZ:[[new A(new E(.15,.15,.01),u),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.15,.15,.01),f),[.15,0,.15],[-Math.PI/2,0,0]]]},k={X:[[new A(new h(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new A(new h(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new A(new h(.2,0,.6,4),i),[0,.3,0]],[new A(new h(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new A(new h(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new A(new h(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new A(new r(.2,0),i)]],XY:[[new A(new E(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new A(new E(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]]},re={START:[[new A(new r(.01,2),o),null,null,null,`helper`]],END:[[new A(new r(.01,2),o),null,null,null,`helper`]],DELTA:[[new w(O(),o),null,null,null,`helper`]],X:[[new w(C,o),[-1e3,0,0],null,[1e6,1,1],`helper`]],Y:[[new w(C,o),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],`helper`]],Z:[[new w(C,o),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],`helper`]]},ie={XYZE:[[new A(D(.5,1),y),null,[0,Math.PI/2,0]]],X:[[new A(D(.5,.5),s)]],Y:[[new A(D(.5,.5),c),null,[0,0,-Math.PI/2]]],Z:[[new A(D(.5,.5),l),null,[0,Math.PI/2,0]]],E:[[new A(D(.75,1),_),null,[0,Math.PI/2,0]]]},ae={AXIS:[[new w(C,o),[-1e3,0,0],null,[1e6,1,1],`helper`]]},j={XYZE:[[new A(new ee(.25,10,8),i)]],X:[[new A(new n(.5,.1,4,24),i),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new A(new n(.5,.1,4,24),i),[0,0,0],[Math.PI/2,0,0]]],Z:[[new A(new n(.5,.1,4,24),i),[0,0,0],[0,0,-Math.PI/2]]],E:[[new A(new n(.75,.1,2,24),i)]]},M={X:[[new A(S,s),[.5,0,0],[0,0,-Math.PI/2]],[new A(T,s),[0,0,0],[0,0,-Math.PI/2]],[new A(S,s),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new A(S,c),[0,.5,0]],[new A(T,c)],[new A(S,c),[0,-.5,0],[0,0,Math.PI]]],Z:[[new A(S,l),[0,0,.5],[Math.PI/2,0,0]],[new A(T,l),[0,0,0],[Math.PI/2,0,0]],[new A(S,l),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new A(new E(.15,.15,.01),p),[.15,.15,0]]],YZ:[[new A(new E(.15,.15,.01),u),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.15,.15,.01),f),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new A(new E(.1,.1,.1),g)]]},N={X:[[new A(new h(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new A(new h(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new A(new h(.2,0,.6,4),i),[0,.3,0]],[new A(new h(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new A(new h(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new A(new h(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new A(new E(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new A(new E(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new A(new E(.2,.2,.2),i),[0,0,0]]]},oe={X:[[new w(C,o),[-1e3,0,0],null,[1e6,1,1],`helper`]],Y:[[new w(C,o),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],`helper`]],Z:[[new w(C,o),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],`helper`]]};function P(e){let t=new d;for(let n in e)for(let r=e[n].length;r--;){let i=e[n][r][0].clone(),a=e[n][r][1],o=e[n][r][2],s=e[n][r][3],c=e[n][r][4];i.name=n,i.tag=c,a&&i.position.set(a[0],a[1],a[2]),o&&i.rotation.set(o[0],o[1],o[2]),s&&i.scale.set(s[0],s[1],s[2]),i.updateMatrix();let l=i.geometry.clone();l.applyMatrix4(i.matrix),i.geometry=l,i.renderOrder=1/0,i.position.set(0,0,0),i.rotation.set(0,0,0),i.scale.set(1,1,1),t.add(i)}return t}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=P(ne)),this.add(this.gizmo.rotate=P(ie)),this.add(this.gizmo.scale=P(M)),this.add(this.picker.translate=P(k)),this.add(this.picker.rotate=P(j)),this.add(this.picker.scale=P(N)),this.add(this.helper.translate=P(re)),this.add(this.helper.rotate=P(ae)),this.add(this.helper.scale=P(oe)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(e){let t=(this.mode===`scale`?`local`:this.space)===`local`?this.worldQuaternion:W;this.gizmo.translate.visible=this.mode===`translate`,this.gizmo.rotate.visible=this.mode===`rotate`,this.gizmo.scale.visible=this.mode===`scale`,this.helper.translate.visible=this.mode===`translate`,this.helper.rotate.visible=this.mode===`rotate`,this.helper.scale.visible=this.mode===`scale`;let n=[];n=n.concat(this.picker[this.mode].children),n=n.concat(this.gizmo[this.mode].children),n=n.concat(this.helper[this.mode].children);for(let e=0;e<n.length;e++){let r=n[e];r.visible=!0,r.rotation.set(0,0,0),r.position.copy(this.worldPosition);let i;if(i=this.camera.isOrthographicCamera?(this.camera.top-this.camera.bottom)/this.camera.zoom:this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),r.scale.set(1,1,1).multiplyScalar(i*this.size/4),r.tag===`helper`)r.visible=!1,r.name===`AXIS`?(r.visible=!!this.axis,this.axis===`X`&&(L.setFromEuler(V.set(0,0,0)),r.quaternion.copy(t).multiply(L),Math.abs(H.copy(q).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),this.axis===`Y`&&(L.setFromEuler(V.set(0,0,Math.PI/2)),r.quaternion.copy(t).multiply(L),Math.abs(H.copy(J).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),this.axis===`Z`&&(L.setFromEuler(V.set(0,Math.PI/2,0)),r.quaternion.copy(t).multiply(L),Math.abs(H.copy(Y).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),this.axis===`XYZE`&&(L.setFromEuler(V.set(0,Math.PI/2,0)),H.copy(this.rotationAxis),r.quaternion.setFromRotationMatrix(_e.lookAt(ge,H,J)),r.quaternion.multiply(L),r.visible=this.dragging),this.axis===`E`&&(r.visible=!1)):r.name===`START`?(r.position.copy(this.worldPositionStart),r.visible=this.dragging):r.name===`END`?(r.position.copy(this.worldPosition),r.visible=this.dragging):r.name===`DELTA`?(r.position.copy(this.worldPositionStart),r.quaternion.copy(this.worldQuaternionStart),F.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),F.applyQuaternion(this.worldQuaternionStart.clone().invert()),r.scale.copy(F),r.visible=this.dragging):(r.quaternion.copy(t),this.dragging?r.position.copy(this.worldPositionStart):r.position.copy(this.worldPosition),this.axis&&(r.visible=this.axis.search(r.name)!==-1));else{if(r.quaternion.copy(t),this.mode===`translate`||this.mode===`scale`){let e=.99,n=.2;r.name===`X`&&Math.abs(H.copy(q).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`Y`&&Math.abs(H.copy(J).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`Z`&&Math.abs(H.copy(Y).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`XY`&&Math.abs(H.copy(Y).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`YZ`&&Math.abs(H.copy(q).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`XZ`&&Math.abs(H.copy(J).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1)}else this.mode===`rotate`&&(U.copy(t),H.copy(this.eye).applyQuaternion(L.copy(t).invert()),r.name.search(`E`)!==-1&&r.quaternion.setFromRotationMatrix(_e.lookAt(this.eye,ge,J)),r.name===`X`&&(L.setFromAxisAngle(q,Math.atan2(-H.y,H.z)),L.multiplyQuaternions(U,L),r.quaternion.copy(L)),r.name===`Y`&&(L.setFromAxisAngle(J,Math.atan2(H.x,H.z)),L.multiplyQuaternions(U,L),r.quaternion.copy(L)),r.name===`Z`&&(L.setFromAxisAngle(Y,Math.atan2(H.y,H.x)),L.multiplyQuaternions(U,L),r.quaternion.copy(L)));r.visible=r.visible&&(r.name.indexOf(`X`)===-1||this.showX),r.visible=r.visible&&(r.name.indexOf(`Y`)===-1||this.showY),r.visible=r.visible&&(r.name.indexOf(`Z`)===-1||this.showZ),r.visible=r.visible&&(r.name.indexOf(`E`)===-1||this.showX&&this.showY&&this.showZ),r.visible=r.visible&&(r.name.indexOf(`XY`)===-1||this.showXY),r.visible=r.visible&&(r.name.indexOf(`YZ`)===-1||this.showYZ),r.visible=r.visible&&(r.name.indexOf(`XZ`)===-1||this.showXZ),r.visible=r.visible&&(r.name!==`E`||this.showE),r.visible=r.visible&&(r.name!==`XYZE`||this.showXYZE),r.material._color=r.material._color||r.material.color.clone(),r.material._opacity=r.material._opacity||r.material.opacity,r.material.color.copy(r.material._color),r.material.opacity=r.material._opacity,this.enabled&&this.axis&&(r.name===this.axis||this.axis.split(``).some(function(e){return r.name===e}))&&(r.material.color.copy(this.materialLib.active.color),r.material.opacity=1)}}super.updateMatrixWorld(e)}},be=class extends A{constructor(){super(new t(1e5,1e5,2,2),new m({visible:!1,wireframe:!0,side:2,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type=`TransformControlsPlane`}updateMatrixWorld(e){let t=this.space;switch(this.position.copy(this.worldPosition),this.mode===`scale`&&(t=`local`),X.copy(q).applyQuaternion(t===`local`?this.worldQuaternion:W),Z.copy(J).applyQuaternion(t===`local`?this.worldQuaternion:W),Q.copy(Y).applyQuaternion(t===`local`?this.worldQuaternion:W),H.copy(Z),this.mode){case`translate`:case`scale`:switch(this.axis){case`X`:H.copy(this.eye).cross(X),G.copy(X).cross(H);break;case`Y`:H.copy(this.eye).cross(Z),G.copy(Z).cross(H);break;case`Z`:H.copy(this.eye).cross(Q),G.copy(Q).cross(H);break;case`XY`:G.copy(Q);break;case`YZ`:G.copy(X);break;case`XZ`:H.copy(Q),G.copy(Z);break;case`XYZ`:case`E`:G.set(0,0,0)}break;default:G.set(0,0,0)}G.length()===0?this.quaternion.copy(this.cameraQuaternion):(K.lookAt(F.set(0,0,0),G,H),this.quaternion.setFromRotationMatrix(K)),super.updateMatrixWorld(e)}},xe=`
2
2
  varying vec3 vWorld;
3
3
  void main() {
4
4
  vec4 w = modelMatrix * vec4(position, 1.0);