phy-engine
Version:
JavaScript 3D Physics for three.js
1 lines • 3.62 MB
JavaScript
!function(A,I){"object"==typeof exports&&"undefined"!=typeof module?I(exports):"function"==typeof define&&define.amd?define(["exports"],I):I((A="undefined"!=typeof globalThis?globalThis:A||self).JOLT={})}(this,(function(A){"use strict";var I="undefined"!=typeof document?document.currentScript:null;const g=new Map,C=new Map,B={LAYER_NON_MOVING:0,LAYER_MOVING:1,LAYER_ALL:1,Ar:null,ArPos:{},ms:0,deltaTime:0,invDelta:0,physicsSystem:null,bodyInterface:null,world:null,groupFilter:null,delta:0,tmpStep:0,gravity:null,key:[],reflow:{ray:[],point:{},contact:{},velocity:{},stat:{fps:0,delta:0,ms:0}}},Q={clear:()=>{g.clear(),C.clear()},byName:A=>g.has(A)?g.get(A):null,byContact:A=>C.has(A),clearContact:()=>{C.clear()},addContact:(A,I={})=>{Q.byContact(A)||C.set(A,I)},removeContact:A=>{C.delete(A)},add:A=>{if("ray"!==A.type&&"contact"!==A.type)switch(A.type){case"joint":B.physicsSystem.AddConstraint(A);break;case"body":case"solid":B.bodyInterface.AddBody(A.GetID(),Jolt.EActivation_Activate)}g.set(A.name,A)},remove:A=>{if("ray"!==A.type&&"contact"!==A.type)switch(A.type){case"terrain":A.release();break;case"joint":B.physicsSystem.RemoveConstraint(A);break;case"body":case"solid":B.bodyInterface.RemoveBody(A.GetID()),B.bodyInterface.DestroyBody(A.GetID())}g.delete(A.name)},stats:()=>{},extends:()=>{Jolt.Vec3.prototype.set=function(A,I,g){return this.Set(A,I,g),this},Jolt.Vec3.prototype.clone=function(A){return new Jolt.RVec3(A.GetX(),A.GetY(),A.GetZ())},Jolt.Vec3.prototype.fromArray=function(A,I){return I=I||0,this.Set(A[I],A[I+1],A[I+2]),this},Jolt.Vec3.prototype.toArray=function(A,I){let g=void 0!==A;if(g||(A=[]),A[I=I||0]=this.GetX(),A[I+1]=this.GetY(),A[I+2]=this.GetZ(),!g)return A},Jolt.RVec3.prototype.set=function(A,I,g){return this.Set(A,I,g),this},Jolt.RVec3.prototype.clone=function(A){return new Jolt.RVec3(A.GetX(),A.GetY(),A.GetZ())},Jolt.RVec3.prototype.fromArray=function(A,I){return I=I||0,this.Set(A[I],A[I+1],A[I+2]),this},Jolt.RVec3.prototype.toArray=function(A,I){let g=void 0!==A;if(g||(A=[]),A[I=I||0]=this.GetX(),A[I+1]=this.GetY(),A[I+2]=this.GetZ(),!g)return A},Jolt.Quat.prototype.set=function(A,I,g,C){return this.Set(A,I,g,C),this},Jolt.Quat.prototype.fromArray=function(A,I){return I=I||0,this.Set(A[I],A[I+1],A[I+2],A[I+3]),this},Jolt.Quat.prototype.toArray=function(A,I){let g=void 0!==A;if(g||(A=[]),A[I=I||0]=this.GetX(),A[I+1]=this.GetY(),A[I+2]=this.GetZ(),A[I+3]=this.GetW(),!g)return A},Jolt.Quat.prototype.identity=function(){return this.Set(0,0,0,1),this},Jolt.Mat44.prototype.toArray=function(A,I){return[this.GetTranslation().toArray(),this.GetQuaternion().toArray()]}}},E=4e3,i=1e3,o=4e3,t=100,D=100,e={bodyFull:14,body:8,joint:16,contact:1,ray:11,character:16,vehicle:72,solver:128};class S{constructor(){this.id=0,this.list=[],this.type="item",this.Utils=null}reset(){let A=this.list.length;for(;A--;)this.dispose(this.list[A]);this.list=[],this.id=0}byName(A){return this.Utils.byName(A)}setName(A={}){let I=void 0!==A.name?A.name:this.type+this.id++;return A.id=this.remove(I,!0),A.name=I,I}addToWorld(A,I=-1){this.Utils.add(A),-1!==I?this.list[I]=A:this.list.push(A)}remove(A,I){let g=this.byName(A);return g?this.clear(g,I):-1}clear(A,I){let g=this.list.indexOf(A);return-1===g||I?this.list[g]=null:this.list.splice(g,1),this.dispose(A),g}dispose(A){null!==A&&this.Utils.remove(A)}add(A={}){}set(A={}){}step(A,I){}}const y=Math.PI,a=y/180,p=180/y,K=Number.EPSILON,s=.5*y,r={luminousPowers:{"110000 lm (1000W)":11e4,"3500 lm (300W)":3500,"1700 lm (100W)":1700,"800 lm (60W)":800,"400 lm (40W)":400,"180 lm (25W)":180,"20 lm (4W)":20,Off:0},luminousIrradiances:{"0.0001 lx (Moonless Night)":1e-4,"0.002 lx (Night Airglow)":.002,"0.5 lx (Full Moon)":.5,"3.4 lx (City Twilight)":3.4,"50 lx (Living Room)":50,"100 lx (Very Overcast)":100,"350 lx (Office Room)":350,"400 lx (Sunrise/Sunset)":400,"1000 lx (Overcast)":1e3,"18000 lx (Daylight)":18e3,"50000 lx (Direct Sun)":5e4},exposure:A=>Math.pow(A,5),candelaToLumens:A=>4*A*Math.PI,lumensToCandela:A=>A/(4*Math.PI),todeg:p,torad:a,toFixed:(A,I=3)=>1*A.toFixed(I),toRound:(A,I=3)=>Math.trunc(A),clamp:(A,I=0,g=1)=>A=(A=A<I?I:A)>g?g:A,clampA:(A,I,g)=>Math.max(I,Math.min(g,A)),smoothstep:(A,I,g)=>A*(g=-2*(g=r.clamp(g))*g*g+3*g*g)+I*(1-g),remap:(A,I,g,C,B)=>C+(A-I)*(B-C)/(g-I),lerp:(A,I,g)=>(1-g)*A+g*I,damp:(A,I,g,C)=>r.lerp(A,I,1-Math.exp(-g*C)),nearAngle:(A,I,g=!1)=>I+Math.atan2(Math.sin(A-I),Math.cos(A-I))*(g?p:1),unwrapDeg:A=>A-360*Math.floor((A+180)/360),unwrapRad:A=>Math.atan2(Math.sin(A),Math.cos(A)),nearEquals:(A,I,g=1e-4)=>Math.abs(A-I)<=g,autoSize:(A=[1,1,1],I="box")=>{1===A.length&&(A[1]=A[0]);let g=A[0],C=A[1];return"sphere"===I&&(A=[g,g,g]),"cylinder"!==I&&"wheel"!==I&&"capsule"!==I||(A=[g,C,g]),"cone"!==I&&"pyramid"!==I||(A=[g,C,g]),2===A.length&&(A[2]=A[0]),A},shuffle:A=>A.map((A=>({value:A,sort:Math.random()}))).sort(((A,I)=>A.sort-I.sort)).map((({value:A})=>A)),randomSign:()=>Math.random()<.5?-1:1,randSpread:A=>A*(.5-Math.random()),rand:(A=0,I=1)=>A+Math.random()*(I-A),randInt:(A,I)=>A+Math.floor(Math.random()*(I-A+1)),randIntUnic:(A,I,g)=>{for(var C=[];C.length<g;){var B=r.randInt(A,I);-1===C.indexOf(B)&&C.push(B)}return C},fromTransform:(A,I,g,C=[0,0,0,1],B=!1)=>{let Q=r.composeMatrixArray(A,I),E=r.composeMatrixArray(g,C);return B&&(Q=r.invertMatrixArray(Q)),Q=r.multiplyMatrixArray(Q,E),[Q[12],Q[13],Q[14]]},fromTransformToQ:(A,I,g=!1)=>{let C=r.composeMatrixArray(A,I),B=r.decomposeFullMatrixArray(C).q;return g&&(B=r.quatInvert(B)),B},lerpTransform:(A,I,g)=>{let C=A[0],B=A[1],Q=I[0],E=I[1];return Q=r.lerpArray(C,Q,g),E=r.slerpQuatArray(B,E,g),[Q,E]},composeMatrixArray:(A,I,g=[1,1,1])=>{const C=I[0],B=I[1],Q=I[2],E=I[3],i=C+C,o=B+B,t=Q+Q,D=C*i,e=C*o,S=C*t,y=B*o,a=B*t,p=Q*t,K=E*i,s=E*o,r=E*t,w=g[0],n=g[1],M=g[2];return[(1-(y+p))*w,(e+r)*w,(S-s)*w,0,(e-r)*n,(1-(D+p))*n,(a+K)*n,0,(S+s)*M,(a-K)*M,(1-(D+y))*M,0,A[0],A[1],A[2],1]},multiplyMatrixArray:(A,I)=>{const g=A,C=I,B=[],Q=g[0],E=g[4],i=g[8],o=g[12],t=g[1],D=g[5],e=g[9],S=g[13],y=g[2],a=g[6],p=g[10],K=g[14],s=g[3],r=g[7],w=g[11],n=g[15],M=C[0],c=C[4],k=C[8],h=C[12],G=C[1],J=C[5],U=C[9],N=C[13],_=C[2],l=C[6],F=C[10],f=C[14],Y=C[3],R=C[7],q=C[11],d=C[15];return B[0]=Q*M+E*G+i*_+o*Y,B[4]=Q*c+E*J+i*l+o*R,B[8]=Q*k+E*U+i*F+o*q,B[12]=Q*h+E*N+i*f+o*d,B[1]=t*M+D*G+e*_+S*Y,B[5]=t*c+D*J+e*l+S*R,B[9]=t*k+D*U+e*F+S*q,B[13]=t*h+D*N+e*f+S*d,B[2]=y*M+a*G+p*_+K*Y,B[6]=y*c+a*J+p*l+K*R,B[10]=y*k+a*U+p*F+K*q,B[14]=y*h+a*N+p*f+K*d,B[3]=s*M+r*G+w*_+n*Y,B[7]=s*c+r*J+w*l+n*R,B[11]=s*k+r*U+w*F+n*q,B[15]=s*h+r*N+w*f+n*d,B},invertMatrixArray:A=>{const I=A,g=I[0],C=I[1],B=I[2],Q=I[3],E=I[4],i=I[5],o=I[6],t=I[7],D=I[8],e=I[9],S=I[10],y=I[11],a=I[12],p=I[13],K=I[14],s=I[15],r=e*K*t-p*S*t+p*o*y-i*K*y-e*o*s+i*S*s,w=a*S*t-D*K*t-a*o*y+E*K*y+D*o*s-E*S*s,n=D*p*t-a*e*t+a*i*y-E*p*y-D*i*s+E*e*s,M=a*e*o-D*p*o-a*i*S+E*p*S+D*i*K-E*e*K,c=g*r+C*w+B*n+Q*M;if(0===c)return[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];const k=1/c;return I[0]=r*k,I[1]=(p*S*Q-e*K*Q-p*B*y+C*K*y+e*B*s-C*S*s)*k,I[2]=(i*K*Q-p*o*Q+p*B*t-C*K*t-i*B*s+C*o*s)*k,I[3]=(e*o*Q-i*S*Q-e*B*t+C*S*t+i*B*y-C*o*y)*k,I[4]=w*k,I[5]=(D*K*Q-a*S*Q+a*B*y-g*K*y-D*B*s+g*S*s)*k,I[6]=(a*o*Q-E*K*Q-a*B*t+g*K*t+E*B*s-g*o*s)*k,I[7]=(E*S*Q-D*o*Q+D*B*t-g*S*t-E*B*y+g*o*y)*k,I[8]=n*k,I[9]=(a*e*Q-D*p*Q-a*C*y+g*p*y+D*C*s-g*e*s)*k,I[10]=(E*p*Q-a*i*Q+a*C*t-g*p*t-E*C*s+g*i*s)*k,I[11]=(D*i*Q-E*e*Q-D*C*t+g*e*t+E*C*y-g*i*y)*k,I[12]=M*k,I[13]=(D*p*B-a*e*B+a*C*S-g*p*S-D*C*K+g*e*K)*k,I[14]=(a*i*B-E*p*B-a*C*o+g*p*o+E*C*K-g*i*K)*k,I[15]=(E*e*B-D*i*B+D*C*o-g*e*o-E*C*S+g*i*S)*k,I},matrixArrayDeterminant:A=>{const I=A,g=I[0],C=I[4],B=I[8],Q=I[12],E=I[1],i=I[5],o=I[9],t=I[13],D=I[2],e=I[6],S=I[10],y=I[14];return I[3]*(+Q*o*e-B*t*e-Q*i*S+C*t*S+B*i*y-C*o*y)+I[7]*(+g*o*y-g*t*S+Q*E*S-B*E*y+B*t*D-Q*o*D)+I[11]*(+g*t*e-g*i*y-Q*E*e+C*E*y+Q*i*D-C*t*D)+I[15]*(-B*i*D-g*o*e+g*i*S+B*E*e-C*E*S+C*o*D)},decomposeMatrixArray:A=>[A[12],A[13],A[14]],decomposeFullMatrixArray:A=>{const I=A;let g=r.lengthArray([I[0],I[1],I[2]]);const C=r.lengthArray([I[4],I[5],I[6]]),B=r.lengthArray([I[8],I[9],I[10]]);r.matrixArrayDeterminant(A)<0&&(g=-g);let Q=[...A];const E=1/g,i=1/C,o=1/B;Q[0]*=E,Q[1]*=E,Q[2]*=E,Q[4]*=i,Q[5]*=i,Q[6]*=i,Q[8]*=o,Q[9]*=o,Q[10]*=o;let t=r.quatFromRotationMatrix(Q);return{p:[A[12],A[13],A[14]],q:t,s:[g,C,B]}},applyTransformArray:(A,I,g,C=[1,1,1])=>{const B=r.composeMatrixArray(I,g,C),Q=A[0],E=A[1],i=A[2],o=1/(B[3]*Q+B[7]*E+B[11]*i+B[15]);return[(B[0]*Q+B[4]*E+B[8]*i+B[12])*o,(B[1]*Q+B[5]*E+B[9]*i+B[13])*o,(B[2]*Q+B[6]*E+B[10]*i+B[14])*o]},slerpQuatArray:(A,I,g)=>{if(0===g)return A;if(1===g)return I;let C=[...A];const B=A[0],Q=A[1],E=A[2],i=A[3],o=I[0],t=I[1],D=I[2],e=I[3];let S=i*e+B*o+Q*t+E*D;if(S<0?(C=[-o,-t,-D,-e],S=-S):C=[...I],S>=1)return A;const y=1-S*S;if(y<=K){const A=1-g;return C[3]=A*i+g*C[3],C[0]=A*B+g*C[0],C[1]=A*Q+g*C[1],C[2]=A*E+g*C[2],r.quatNomalize(C)}const a=Math.sqrt(y),p=Math.atan2(a,S),s=Math.sin((1-g)*p)/a,w=Math.sin(g*p)/a;return C[3]=i*s+C[3]*w,C[0]=B*s+C[0]*w,C[1]=Q*s+C[1]*w,C[2]=E*s+C[2]*w,C},toLocalQuatArray:(A=[0,0,0],I)=>{let g=r.quatFromEuler(A),C=r.quatInvert(I.quaternion.toArray());return r.quatMultiply(C,g)},quatFromRotationMatrix:A=>{let I=[0,0,0,1];const g=A,C=g[0],B=g[4],Q=g[8],E=g[1],i=g[5],o=g[9],t=g[2],D=g[6],e=g[10],S=C+i+e;if(S>0){const A=.5/Math.sqrt(S+1);I[3]=.25/A,I[0]=(D-o)*A,I[1]=(Q-t)*A,I[2]=(E-B)*A}else if(C>i&&C>e){const A=2*Math.sqrt(1+C-i-e);I[3]=(D-o)/A,I[0]=.25*A,I[1]=(B+E)/A,I[2]=(Q+t)/A}else if(i>e){const A=2*Math.sqrt(1+i-C-e);I[3]=(Q-t)/A,I[0]=(B+E)/A,I[1]=.25*A,I[2]=(o+D)/A}else{const A=2*Math.sqrt(1+e-C-i);I[3]=(E-B)/A,I[0]=(Q+t)/A,I[1]=(o+D)/A,I[2]=.25*A}return I},quatFromEuler:(A=[0,0,0],I=!0)=>{const g=Math.cos,C=Math.sin,B=I?a:1,Q=A[0]*B*.5,E=A[1]*B*.5,i=A[2]*B*.5,o=g(Q),t=g(E),D=g(i),e=C(Q),S=C(E),y=C(i);return[e*t*D+o*S*y,o*S*D-e*t*y,o*t*y+e*S*D,o*t*D-e*S*y]},quatFromAxis:(A=[0,0,0],I,g=!0)=>{const C=.5*I*(g?a:1),B=Math.sin(C);return[A[0]*B,A[1]*B,A[2]*B,Math.cos(C)]},quatNomalize:A=>{let I=r.lengthArray(A);return 0===I?[0,0,0,1]:(I=1/I,r.scaleArray(A,I,4))},quatInvert:A=>[-A[0],-A[1],-A[2],A[3]],quatMultiply:(A,I)=>{const g=A[0],C=A[1],B=A[2],Q=A[3],E=I[0],i=I[1],o=I[2],t=I[3];return[g*t+Q*E+C*o-B*i,C*t+Q*i+B*E-g*o,B*t+Q*o+g*i-C*E,Q*t-g*E-C*i-B*o]},quatToAxis:A=>{let I=2*Math.acos(A[3]);const g=Math.sqrt(1-A[3]*A[3]);return g<1e-4?[1,0,0]:[A[0]/g,A[1]/g,A[2]/g,I]},eulerFromMatrix:A=>{const I=A[0],g=A[4],C=A[8];A[1];const B=A[5],Q=A[9];A[2];const E=A[6],i=A[10];let o=[0,0,0];return o[1]=Math.asin(r.clamp(C,-1,1)),Math.abs(C)<.9999999?(o[0]=Math.atan2(-Q,i),o[2]=Math.atan2(-g,I)):(o[0]=Math.atan2(E,B),o[2]=0),o},angleTo:(A,I)=>2*Math.acos(Math.abs(r.clamp(r.dotArray(A,I),-1,1))),fixedArray:(A,I)=>{let g=A.length,C=[];for(;g--;)C[g]=r.toFixed(A[g],I);return C},getSize:A=>.001*A.byteLength+"kb",perpendicularArray:A=>{const I=Math.sqrt(A[0]*A[0]+A[1]*A[1]+A[2]*A[2]);let g=Math.acos(A[1]/I);const C=Math.atan2(A[2],A[0]);g>s?g-=s:g+=s;return[I*Math.sin(g)*Math.cos(C),I*Math.cos(g),I*Math.sin(g)*Math.sin(C)]},crossArray:(A,I)=>{const g=A[0],C=A[1],B=A[2],Q=I[0],E=I[1],i=I[2];return[C*i-B*E,B*Q-g*i,g*E-C*Q]},applyQuaternion:(A,I)=>{const g=A[0],C=A[1],B=A[2],Q=I[0],E=I[1],i=I[2],o=I[3],t=2*(E*B-i*C),D=2*(i*g-Q*B),e=2*(Q*C-E*g);return[g+o*t+E*e-i*D,C+o*D+i*t-Q*e,B+o*e+Q*D-E*t]},nullArray:(A,I,g)=>{let C=0;for(;g--;)C+=A[I+g];return C},equalArray:(A,I)=>{let g=A.length;for(;g--;)if(A[g]!==I[g])return!1;return!0},lerpArray:(A,I,g)=>{if(0===g)return A;if(1===g)return I;let C=A.length,B=[];for(;C--;)B[C]=A[C],B[C]+=(I[C]-B[C])*g;return B},zeroArray:(A,I=0,g)=>{for(g=g??A.length;g--;)A[I+g]=0;return A},lengthArray:A=>{let I=A.length,g=0;for(;I--;)g+=A[I]*A[I];return Math.sqrt(g)},dotArray:(A,I)=>{let g=A.length,C=0;for(;g--;)C+=A[g]*I[g];return C},addArray:(A,I,g)=>{g=g??A.length;let C=[];for(;g--;)C[g]=A[g]+I[g];return C},subArray:(A,I,g)=>{g=g??A.length;let C=[];for(;g--;)C[g]=A[g]-I[g];return C},mulArray:(A,I,g)=>{if(I instanceof Array){let C=[];for(g=g??A.length;g--;)C[g]=A[g]*I[g];return C}return A.map((A=>A*I))},worldscale:(A,I)=>A.map((A=>A*I)),divArray:(A,I,g)=>r.mulArray(A,1/I,g),scaleArray:(A,I,g)=>r.mulArray(A,I,g),fillArray:(A,I,g=0,C)=>{for(C=C??A.length;C--;)I[g+C]=A[C]},copyArray:(A,I)=>{},cloneArray:A=>[...A],distanceArray:(A,I=[0,0,0])=>r.lengthArray(r.subArray(A,I)),normalizeArray:A=>r.divArray(A,r.lengthArray(A)||1),normalArray:(A,I=[0,0,0])=>r.normalizeArray(r.subArray(I,A)),getCenter:(A,I)=>(A.computeBoundingBox(),A.boundingBox.getCenter(I)),getVolume:(A,I,g=null)=>{let C=1,B=I;switch(A){case"sphere":C=4*Math.PI*B[0]*B[0]*B[0]/3;break;case"cone":C=Math.PI*B[0]*(.5*B[1])*2;break;case"box":C=.5*B[0]*8*(.5*B[1])*(.5*B[2]);break;case"cylinder":C=Math.PI*B[0]*B[0]*(.5*B[1])*2;break;case"capsule":C=4*Math.PI*B[0]*B[0]*B[0]/3+Math.PI*B[0]*B[0]*(.5*B[1])*2;break;case"convex":case"mesh":C=r.getConvexVolume(g)}return C},getConvexVolume:A=>{let I,g=A.length/3,C=[0,0,0],B=[0,0,0];for(;g--;)I=3*g,A[I]<C[0]?C[0]=A[I]:A[I]>B[0]&&(B[0]=A[I]),A[I+1]<C[1]?C[1]=A[I+1]:A[I+1]>B[1]&&(B[1]=A[I+1]),A[I+2]<C[2]?C[2]=A[I+2]:A[I+2]>B[2]&&(B[2]=A[I+2]);let Q=[B[0]-C[0],B[1]-C[1],B[2]-C[2]];return.5*Q[0]*8*(.5*Q[1])*(.5*Q[2])},massFromDensity:(A,I)=>A*I,densityFromMass:(A,I)=>A/I,toNonIndexed:A=>A.index?A.clone().toNonIndexed():A,getIndex:(A,I)=>!A.index||I?null:A.index.array||null,getSameVertex:A=>{const I=A.getAttribute("position"),g=I.array,C=[],B=[],Q={};new THREE.Vector3;let E,i=0;r.getHash(A);let o,t,D=!1,e=0;for(let A=0;A<I.count;A++){i=3*A,o={x:g[i],y:g[i+1],z:g[i+2],id:A},D=!1,E=C.length;for(let I=0;I<E;I++)t=C[I],o.x===t.x&&o.y===t.y&&o.z===t.z&&(D=!0,Q[A]=t.id);D||(o.id=e++,C.push(o),B.push([o.x,o.y,o.z]))}return[B,Q]},getVertex:(A,I)=>{let g=A.attributes.position.array;return I&&A.index&&(g=(A=A.clone().toNonIndexed()).attributes.position.array),g},getNormal:A=>A.attributes.normal.array,getFaces:A=>{let I=[];if(A.index){let g=A.getIndex();for(let A=0;A<g.count;A+=3)I.push([g.getX(A),g.getX(A+1),g.getX(A+2)])}else{let g=A.getAttribute("position").count;for(let A=0;A<g;A+=3)I.push([A,A+1,A+2])}return I},getConnectedFaces:A=>{const I=[];let g,C,B,Q,E,i,o,t=A.length,D=t;for(;D--;)for(C=A[D],g=t;g--;)g!==D&&(B=A[g],Q=C.filter((A=>B.includes(A))),Q.length>1&&(o=[],E=[...C],i=E.indexOf(Q[0]),E.splice(i,1),i=E.indexOf(Q[1]),E.splice(i,1),o.push(E[0]),E=[...B],i=E.indexOf(Q[0]),E.splice(i,1),i=E.indexOf(Q[1]),E.splice(i,1),o.push(E[0]),I.push(o)));return I},reduce:A=>{},barycentric:(A,I)=>{},solve:(A,I)=>{},getHash:(A,I=1e-4)=>{I=Math.max(I,Number.EPSILON);const g={},C={},B=A.getAttribute("position"),Q=B.count,E=B.array,i=.5*I,o=Math.log10(1/I),t=Math.pow(10,o),D=i*t;let e;for(let A=0;A<Q;A++){e=3*A;let I=`${~~(E[e]*t+D)},${~~(E[e+1]*t+D)},${~~(E[e+2]*t+D)}`;g[I]?g[I].push(A):g[I]=[A]}let S=0;for(let A in g)C[S++]=g[A];return C}},w=r;class n extends S{constructor(){super(),this.Utils=Q,this.type="body",this.itype="body",this.num=e[this.type],this.full=!1,this.v=new Jolt.RVec3,this.q=new Jolt.Quat,this.v2=new Jolt.RVec3,this.q2=new Jolt.Quat}setFull(A){this.num=e[A?"bodyFull":"body"],this.full=A}step(){const A=B.Ar,I=B.ArPos[this.itype];let g,C,Q,E,i,o,t=this.list.length;for(;t--;)g=this.list[t],g&&(C=I+t*this.num,g.lockPos&&B.bodyInterface.MoveKinematic(g.GetID(),g.GetPosition(),g.GetRotation(),B.deltaTime),A[C]=g.IsActive()?1:0,Q=g.GetPosition(),E=g.GetRotation(),Q.toArray(A,C+1),E.toArray(A,C+4),this.full?(i=g.GetLinearVelocity(),o=g.GetAngularVelocity(),i.toArray(A,C+8),o.toArray(A,C+11),1===A[C]&&(A[C]=9.8*i.Length())):g.getVelocity&&(i=g.GetLinearVelocity().toArray(),o=g.GetAngularVelocity().toArray(),B.reflow.velocity[g.name]=[...i,...o]))}shape(A={}){let I,g,C,B,Q=null,E=A.type||"box",i=A.size||[1,1,1],o=.01,t=null;switch(E){case"plane":i=[300,1,300],B=new Jolt.ConvexHullShapeSettings;let E=[.5*i[0],0,.5*i[2],.5*i[0],0,.5*-i[2],.5*-i[0],0,.5*-i[2],.5*-i[0],0,.5*i[2]];for(I=4;I--;)g=3*I,B.mPoints.push_back(this.v.fromArray(E,g));Q=B.Create().Get();break;case"box":Q=new Jolt.BoxShape(this.v.set(.5*i[0],.5*i[1],.5*i[2]),o,t);break;case"sphere":Q=new Jolt.SphereShape(i[0],t);break;case"cylinder":Q=new Jolt.CylinderShape(.5*i[1],i[0],o,t);break;case"capsule":Q=new Jolt.CapsuleShape(.5*i[1],i[0],o,t);break;case"particle":Q=new Jolt.SphereShape(A.pSize||.05,t);break;case"convex":for(B=new Jolt.ConvexHullShapeSettings,I=Math.floor(A.v.length/3),C=0;I--;)g=3*C,B.mPoints.push_back(this.v.fromArray(A.v,g)),C++;Q=B.Create().Get();break;case"mesh":let D=new Jolt.TriangleList,e=A.v,S=Math.floor(e.length/3);for(D.resize(S),I=S/3,C=0;I--;){g=9*C;let A=D.at(C),I=A.get_mV(0),B=A.get_mV(1),Q=A.get_mV(2);I.x=e[g+0],I.y=e[g+1],I.z=e[g+2],B.x=e[g+3],B.y=e[g+4],B.z=e[g+5],Q.x=e[g+6],Q.y=e[g+7],Q.z=e[g+8],C++}Q=new Jolt.MeshShapeSettings(D,t).Create().Get()}return A.density&&Q.SetDensity,Q.volume=w.getVolume(E,i,A.v),Q}shapeSetting(A={}){let I,g,C,B=null,Q=A.type||"box",E=A.size||[1,1,1],i=null;switch(Q){case"box":B=new Jolt.BoxShapeSettings(this.v.set(.5*E[0],.5*E[1],.5*E[2]),0,i);break;case"sphere":B=new Jolt.SphereShapeSettings(E[0],i);break;case"cylinder":B=new Jolt.CylinderShapeSettings(.5*E[1],E[0],0,i);break;case"capsule":B=new Jolt.CapsuleShapeSettings(.5*E[1],E[0],0,i);break;case"convex":for(B=new Jolt.ConvexHullShapeSettings,I=Math.floor(A.v.length/3),C=0;I--;)g=3*C,B.mPoints.push_back(this.v.fromArray(A.v,g)),C++;break;case"mesh":let Q=new Jolt.TriangleList,o=A.v,t=Math.floor(o.length/3);for(Q.resize(t),I=t/3,C=0;I--;){g=9*C;let A=Q.at(C),I=A.get_mV(0),B=A.get_mV(1),E=A.get_mV(2);I.x=o[g+0],I.y=o[g+1],I.z=o[g+2],B.x=o[g+3],B.y=o[g+4],B.z=o[g+5],E.x=o[g+6],E.y=o[g+7],E.z=o[g+8],C++}B=new Jolt.MeshShapeSettings(Q,i)}return B.volume=w.getVolume(Q,E,A.v),B}add(A={}){let I,g=this.setName(A),C="body"===this.type?A.kinematic?Jolt.EMotionType_Kinematic:Jolt.EMotionType_Dynamic:Jolt.EMotionType_Static,Q="body"===this.type?B.LAYER_MOVING:B.LAYER_NON_MOVING,E=0;switch(void 0!==A.move&&(Q=A.move?B.LAYER_MOVING:B.LAYER_NON_MOVING),this.v.fromArray(A.pos||[0,0,0]),this.q.fromArray(A.quat||[0,0,0,1]),A.type){case"null":I=new Jolt.BodyCreationSettings(this.shape({type:"sphere",size:[.01]}),this.v.fromArray(A.pos||[0,0,0]),this.q.fromArray(A.quat||[0,0,0,1]),C,Q);break;case"compound":let g,B,o=new Jolt.StaticCompoundShapeSettings;for(var i=0;i<A.shapes.length;i++)g=A.shapes[i],B=this.shapeSetting(g),E+=B.volume,o.AddShape(this.v2.fromArray(g.pos||[0,0,0]),this.q2.fromArray(g.quat||[0,0,0,1]),B);I=new Jolt.BodyCreationSettings(o.Create().Get(),this.v.fromArray(A.pos||[0,0,0]),this.q.fromArray(A.quat||[0,0,0,1]),C,Q),Jolt.destroy(o);break;default:A.shapeType&&(A.type=A.shapeType);let t=this.shape(A);E=t.volume,I=new Jolt.BodyCreationSettings(t,this.v.fromArray(A.pos||[0,0,0]),this.q.fromArray(A.quat||[0,0,0,1]),C,Q)}if(A.density&&(A.mass=w.massFromDensity(A.density||0,E)),A.mass&&(I.mOverrideMassProperties=1,I.mMassPropertiesOverride.mMass=A.mass),A.massCenter&&console.log(I.mMassPropertiesOverride),A.inertia&&(I.mOverrideMassProperties=1,I.mMassPropertiesOverride.mInertia.PostScaled(this.v.fromArray(A.inertia))),A.linearFactor||A.angularFactor){let g=0;A.linearFactor?(A.linearFactor[0]>0&&(g|=Jolt.EAllowedDOFs_TranslationX),A.linearFactor[1]>0&&(g|=Jolt.EAllowedDOFs_TranslationY),A.linearFactor[2]>0&&(g|=Jolt.EAllowedDOFs_TranslationZ)):g|=Jolt.EAllowedDOFs_TranslationX|Jolt.EAllowedDOFs_TranslationY|Jolt.EAllowedDOFs_TranslationZ,A.angularFactor?(A.angularFactor[0]>0&&(g|=Jolt.EAllowedDOFs_RotationX),A.angularFactor[1]>0&&(g|=Jolt.EAllowedDOFs_RotationY),A.angularFactor[2]>0&&(g|=Jolt.EAllowedDOFs_RotationZ)):g|=Jolt.EAllowedDOFs_RotationX|Jolt.EAllowedDOFs_RotationY|Jolt.EAllowedDOFs_RotationZ,I.mAllowedDOFs=g}void 0!==A.motionQuality&&(I.mMotionQuality=A.motionQuality),void 0!==A.useCCD&&(I.mMotionQuality=1),void 0!==A.maxLinear&&(I.mMaxLinearVelocity=A.maxLinear),void 0!==A.maxAngular&&(I.mMaxAngularVelocity=A.maxAngular),void 0!==A.noGravity&&(I.mGravityFactor=A.noGravity?0:1),void 0!==A.gravityScale&&(I.mGravityFactor=A.gravityScale),void 0!==A.kinematic&&(I.mAllowDynamicOrKinematic=A.kinematic),void 0!==A.sensor&&(I.mIsSensor=A.sensor),void 0!==A.damping&&(I.mLinearDamping=A.damping[0],I.mAngularDamping=A.damping[1]);const o=B.bodyInterface.CreateBody(I);Jolt.destroy(I),o.name=g,o.type=this.type,o.isKinematic=A.kinematic||!1,o.breakable=A.breakable||!1,this.addToWorld(o,A.id),delete A.pos,delete A.quat,delete A.mass,delete A.kinematic,this.set(A,o)}set(A={},I=null){if(null===I&&(I=this.byName(A.name)),null!==I){if(void 0!==A.getVelocity&&(I.getVelocity=A.getVelocity),void 0!==A.friction&&I.SetFriction(A.friction),void 0!==A.restitution&&I.SetRestitution(A.restitution),void 0!==A.group&&void 0!==A.mask&&(A.filter=[A.group,A.mask]),A.filter){const g=I.GetCollisionGroup();g.SetGroupFilter(B.groupFilter),g.SetGroupID(A.filter[0]),g.SetSubGroupID(A.filter[1])}if(void 0!==A.kinematic&&"body"===I.type&&(I.isKinematic=A.kinematic||!1,I.mMotionType=0==A.kinematic?Jolt.EMotionType_Kinematic:Jolt.EMotionType_Dynamic),void 0!==A.bullet&&B.bodyInterface.SetMotionQuality(I.GetID(),A.bullet?1:0),void 0!==A.motionQuality&&B.bodyInterface.SetMotionQuality(I.GetID(),A.motionQuality),A.gravityScale&&B.bodyInterface.SetGravityFactor(I.GetID(),A.gravityScale),A.sleep&&B.bodyInterface.DeactivateBody(I.GetID()),(A.activate||A.wake)&&B.bodyInterface.ActivateBody(I.GetID()),void 0!==A.neverSleep&&I.SetAllowSleeping(!A.neverSleep),A.noGravity,void 0!==A.linearVelocity&&I.SetLinearVelocity(this.v.fromArray(A.linearVelocity)),void 0!==A.linearVelocityClamped&&I.SetLinearVelocityClamped(this.v.fromArray(A.linearVelocityClamped)),void 0!==A.angularVelocity&&I.SetAngularVelocity(this.v.fromArray(A.angularVelocity)),void 0!==A.angularVelocityClamped&&I.SetAngularVelocityClamped(this.v.fromArray(A.angularVelocityClamped)),A.angularFactor,A.reset&&(I.SetLinearVelocity(this.v.set(0,0,0)),I.SetAngularVelocity(this.v.set(0,0,0)),I.ResetForce(),I.ResetTorque()),A.pos||A.quat)if(I.isKinematic){let g=A.pos?this.v.fromArray(A.pos):I.GetPosition(),C=A.quat?this.q.fromArray(A.quat):I.GetRotation();B.bodyInterface.MoveKinematic(I.GetID(),g,C,B.deltaTime),I.old={p:g,q:C},I.lockPos=!0}else A.pos&&B.bodyInterface.SetPosition(I.GetID(),this.v.fromArray(A.pos),null),A.quat&&B.bodyInterface.SetRotation(I.GetID(),this.q.fromArray(A.quat),null);if(A.impulse&&(I.IsActive()||B.bodyInterface.ActivateBody(I.GetID()),I.AddImpulse(this.v.fromArray(A.impulse),A.impulseCenter?this.v2.fromArray(A.impulseCenter):I.GetPosition())),A.angularImpulse&&I.AddAngularImpulse(this.v.fromArray(A.angularImpulse)),A.force&&I.AddForce(this.v.fromArray(A.force),A.forcePosition?this.v2.fromArray(A.forcePosition):I.GetPosition()),A.torque&&I.AddTorque(this.v.fromArray(A.torque)),void 0!==A.useManifoldReduction&&I.SetUseManifoldReduction(A.useManifoldReduction),I.GetMotionProperties&&(A.massInfo&&this.getMassInfo(I),A.mass&&this.setMass(I,A.mass),void 0!==A.damping&&(I.GetMotionProperties().SetLinearDamping(A.damping[0]),I.GetMotionProperties().SetAngularDamping(A.damping[1])),void 0!==A.inertiaScale)){let g=I.GetMotionProperties().GetInverseInertiaDiagonal().toArray(),C=I.GetMotionProperties().GetInertiaRotation();g=w.mulArray(g,1/A.inertiaScale),I.GetMotionProperties().SetInverseInertia(this.v2.fromArray(g),C)}}}setMass(A,I){A.GetMotionProperties().SetInverseMass(1/I)}getMassInfo(A){if("string"==typeof A&&(A=this.byName(A)),null===A)return;if("body"!==this.type)return;const I={invMass:A.GetMotionProperties().GetInverseMass(),massCenter:A.GetCenterOfMassPosition().toArray(),inertia:A.GetMotionProperties().GetInverseInertiaDiagonal().toArray(),inertiaRotation:A.GetMotionProperties().GetInertiaRotation().toArray(),invInertia:A.GetInverseInertia().toArray(),damping:[A.GetMotionProperties().GetLinearDamping(),A.GetMotionProperties().GetAngularDamping()]};console.log(I)}getShape(A){return A.GetShape()}}class M extends S{constructor(){super(),this.Utils=Q,this.type="joint",this.v=new Jolt.RVec3,this.min=new Jolt.RVec3(0,0,0),this.max=new Jolt.RVec3(0,0,0)}step(){}add(A={}){let I,g=this.setName(A),C=A.mode||"hinge",B=this.byName(A.b1),Q=this.byName(A.b2),E=A.pos1?A.pos1:[0,0,0],i=A.axis1?A.axis1:[1,0,0],o=A.pos2?A.pos2:[0,0,0],t=A.axis2?A.axis2:[1,0,0],D=w.perpendicularArray(i),e=w.perpendicularArray(t),S=null;switch(C){case"fixe":I=new Jolt.FixedConstraintSettings,I.mAutoDetectPoint=!0,S="FixedConstraint";break;case"hinge":I=new Jolt.HingeConstraintSettings,S="HingeConstraint";break;case"distance":I=new Jolt.DistanceConstraintSettings,S="DistanceConstraint";break;case"prismatic":I=new Jolt.SliderConstraintSettings,S="SliderConstraint";break;case"spherical":I=new Jolt.PointConstraintSettings,S="PointConstraintConstraint";break;case"cone":I=new Jolt.ConeConstraintSettings,S="ConeConstraint";break;case"ragdoll":I=new Jolt.SwingTwistConstraintSettings,S="SwingTwistConstraint";break;case"generic":case"cylindrical":I=new Jolt.SixDOFConstraintSettings,S="SixDOFConstraint"}if(!I)return;switch(I.mPoint1&&I.mPoint1.fromArray(E),I.mPoint2&&I.mPoint2.fromArray(o),I.mPosition1&&I.mPosition1.fromArray(E),I.mPosition2&&I.mPosition2.fromArray(o),I.mAxisX1&&I.mAxisX1.fromArray(i),I.mAxisY1&&I.mAxisY1.fromArray(D),I.mAxisX2&&I.mAxisX2.fromArray(t),I.mAxisY2&&I.mAxisY2.fromArray(e),I.mHingeAxis1&&I.mHingeAxis1.fromArray(i),I.mHingeAxis2&&I.mHingeAxis2.fromArray(t),I.mSliderAxis1&&I.mSliderAxis1.fromArray(i),I.mSliderAxis2&&I.mSliderAxis2.fromArray(t),I.mNormalAxis1&&I.mNormalAxis1.fromArray(D),I.mNormalAxis2&&I.mNormalAxis2.fromArray(e),I.mSpace&&(I.mSpace=0),C){case"generic":I.MakeFixedAxis(0),I.MakeFixedAxis(1),I.MakeFixedAxis(2),I.MakeFixedAxis(3),I.MakeFixedAxis(4),I.MakeFixedAxis(5);break;case"cylindrical":I.MakeFixedAxis(1),I.MakeFixedAxis(2),I.MakeFixedAxis(4),I.MakeFixedAxis(5)}const y=Jolt.castObject(I.Create(B,Q),Jolt[S]);y.name=g,y.type=this.type,y.mode=C,y.visible=void 0===A.visible||A.visible,Jolt.destroy(I),this.set(A,y),this.addToWorld(y)}set(A={},I=null){if(null===I&&(I=this.byName(A.name)),null!==I)switch(void 0!==A.enable&&I.SetEnabled(A.enable),I.mode){case"hinge":A.lm&&I.SetLimits(A.lm[0]*a,A.lm[1]*a);break;case"spherical":break;case"prismatic":if(A.lm&&(I.SetLimits(A.lm[0],A.lm[1]),A.spring)){let g=I.GetLimitsSpringSettings();g.mStiffness=A.spring[0],g.mDamping=A.spring[1],g.mFrequency=A.spring[0],g.mMode=1}break;case"cylindrical":A.lm&&(this.min.set(A.lm[0],0,0),this.max.set(A.lm[1],0,0),I.SetTranslationLimits(this.min,this.max)),A.lmr&&(this.min.set(A.lmr[0]*a,0,0),this.max.set(A.lmr[1]*a,0,0),I.SetRotationLimits(this.min,this.max)),I.SetEnabled(!0);break;case"generic":A.lm&&(I.SetTranslationLimits(this.min,this.max),I.SetRotationLimits(this.min,this.max))}}setSpring(A,I){}}class c extends S{constructor(){super(),this.Utils=Q,this.type="ray",this.initRay=!1}reset(){super.reset(),this.initRay&&(this.initRay=!1,Jolt.destroy(this.ray),Jolt.destroy(this.bp_filter),Jolt.destroy(this.object_filter),Jolt.destroy(this.body_filter),Jolt.destroy(this.shape_filter),this.collector.body=null,this.collector.OnBody=null,this.collector.AddHit=null,Jolt.destroy(this.collector))}init(){this.initRay||(this.initRay=!0,this.v1=new Jolt.RVec3,this.v2=new Jolt.RVec3,this.ray=new Jolt.RRayCast,this.ray_settings=new Jolt.RayCastSettings,this.ray_settings.mTreatConvexAsSolid=!1,this.bp_filter=new Jolt.DefaultBroadPhaseLayerFilter(B.world.GetObjectVsBroadPhaseLayerFilter(),B.LAYER_MOVING),this.object_filter=new Jolt.DefaultObjectLayerFilter(B.world.GetObjectLayerPairFilter(),B.LAYER_ALL),this.body_filter=new Jolt.BodyFilter,this.shape_filter=new Jolt.ShapeFilter,this.collector=new Jolt.CastRayCollectorJS,this.collector.OnBody=function(A){A=Jolt.wrapPointer(A,Jolt.Body),this.collector.body=A}.bind(this),this.collector.AddHit=function(A){A=Jolt.wrapPointer(A,Jolt.RayCastResult);const I=this.ray.n,g=B.Ar;if(0!==g[I])return;let C=this.ray.GetPointOnRay(A.mFraction),Q=this.collector.body.GetWorldSpaceSurfaceNormal(A.mSubShapeID2,C),E=this.ray.mOrigin.toArray(),i=C.toArray();Q.toArray(g,I+8),g[I]=1,g[I+1]=w.distanceArray(E,i),g[I+2]=E[0],g[I+3]=E[1],g[I+4]=E[2],g[I+5]=i[0],g[I+6]=i[1],g[I+7]=i[2],B.reflow.ray[this.ray.id]=this.collector.body.name}.bind(this),this.collector.Reset=function(){this.collector.ResetEarlyOutFraction()}.bind(this))}step(){const A=B.Ar,I=B.ArPos[this.type];B.reflow.ray=[];let g,C,Q,E=this.list.length;for(;E--;)C=I+E*e.ray,g=this.list[E],Q=g.getPoint(),this.ray.mOrigin.fromArray(Q[0]),this.ray.mDirection.fromArray(w.subArray(Q[1],Q[0])),this.ray.n=C,this.ray.id=E,A[C]=0,this.collector.Reset(),this.ray_settings.mTreatConvexAsSolid=g.selfHit,B.physicsSystem.GetNarrowPhaseQuery().CastRay(this.ray,this.ray_settings,this.collector,this.bp_filter,this.object_filter,this.body_filter,this.shape_filter)}add(A={}){this.setName(A);let I=new k(A);this.addToWorld(I,A.id),this.init()}set(A={},I=null){null===I&&(I=this.byName(A.name)),null!==I&&(A.begin&&(I.begin=A.begin),A.end&&(I.end=A.end))}}class k{constructor(A={}){this.type="ray",this.name=A.name,this.parent=A.parent||"",this.selfHit=A.selfHit||!1,this.noRotation=A.noRotation||!1,this.begin=A.begin||[0,0,0],this.end=A.end||[0,0,1]}getPoint(){if(this.parent){const A=Q.byName(this.parent);if(A){const I=A.GetPosition().toArray(),g=this.noRotation?[0,0,0,1]:A.GetRotation().toArray();return[w.applyTransformArray(this.begin,I,g),w.applyTransformArray(this.end,I,g)]}}return[this.begin,this.end]}}class h extends S{constructor(){super(),this.Utils=Q,this.type="contact",this.initContact=!1}reset(){super.reset(),this.initContact&&(this.initContact=!1,Jolt.destroy(this.contactListener))}init(){this.initContact||(this.initContact=!0,this.contactListener=new Jolt.ContactListenerJS,this.contactListener.OnContactValidate=(A,I,g,C)=>{A=Jolt.wrapPointer(A,Jolt.Body),I=Jolt.wrapPointer(I,Jolt.Body);const B=A.name,Q=I.name;return B&&Q&&(C=Jolt.wrapPointer(C,Jolt.CollideShapeResult)),Jolt.ValidateResult_AcceptAllContactsForThisBodyPair},this.contactListener.OnContactAdded=(A,I,g,C)=>{A=Jolt.wrapPointer(A,Jolt.Body),I=Jolt.wrapPointer(I,Jolt.Body);const B=A.name,E=I.name;g=Jolt.wrapPointer(g,Jolt.ContactManifold),(C=Jolt.wrapPointer(C,Jolt.ContactSettings)).mCombinedRestitution=.5,B&&E&&Q.addContact(B+"_"+E)},this.contactListener.OnContactPersisted=(A,I,g,C)=>{A=Jolt.wrapPointer(A,Jolt.Body),I=Jolt.wrapPointer(I,Jolt.Body);const B=A.name,E=I.name;g=Jolt.wrapPointer(g,Jolt.ContactManifold),(C=Jolt.wrapPointer(C,Jolt.ContactSettings)).mCombinedRestitution=.5,B&&E&&Q.addContact(B+"_"+E)},this.contactListener.OnContactRemoved=A=>{},B.physicsSystem.SetContactListener(this.contactListener))}step(){const A=B.Ar,I=B.ArPos[this.type];let g,C,E,i=this.list.length;for(;i--;)g=this.list[i],C=I+i*e.contact,E=Q.byContact(g.cc)?1:0,E||(E=Q.byContact(g.cr)?1:0),A[C]=E;Q.clearContact()}add(A={}){this.setName(A);let I=this.byName(A.b1);if(this.byName(A.b2),null===I)return;let g=new G(A);this.addToWorld(g,A.id),this.init()}}class G{constructor(A={}){this.type="contact",this.name=A.name,this.cc=A.b1+"_"+A.b2,this.cr=A.b2+"_"+A.b1}}class J extends S{constructor(){super(),this.type="terrain",this.Utils=Q}add(A){this.setName(A);let I=new U(A);this.addToWorld(I,A.id)}set(A={},I=null){null===I&&(I=this.byName(A.name)),null!==I&&I.set(A)}}class U{constructor(A){this.type="terrain",this.name=A.name,this.needUpdate=!1,this.heightField=null,this.heights=null,this.shape=null,this.init(A)}init(A){this.size=A.size,this.sample=A.sample,this.squarSize=[this.size[0]/(this.sample[0]-1),this.size[2]/(this.sample[1]-1)],this.scale=[this.squarSize[0],this.size[1],this.squarSize[1]],this.setData(A);let I=A.pos||[0,0,0];I[0]=I[0]-.5*this.size[0],I[2]=I[2]-.5*this.size[2];const g=new Jolt.RVec3(0,0,0).fromArray(I),C=new Jolt.Quat(0,0,0,1);let Q=new Jolt.BodyCreationSettings(this.shape,g,C,Jolt.EMotionType_Static,B.LAYER_NON_MOVING);this.body=B.bodyInterface.CreateBody(Q),Jolt.destroy(Q),B.bodyInterface.AddBody(this.body.GetID(),Jolt.EActivation_Activate)}setData(A){let I=A.heightData;const g=new Jolt.HeightFieldShapeSettings;g.mOffset.Set(0,0,0),g.mScale.Set(this.scale[0],this.scale[1],this.scale[2]),g.mSampleCount=this.sample[0],g.mBlockSize=2;const C=I.length;g.mHeightSamples.resize(C),this.heightSamples=new Float32Array(Jolt.HEAPF32.buffer,Jolt.getPointer(g.mHeightSamples.data()),C);for(let A=0;A<C;A++)this.heightSamples[A]=I[A];this.shape=g.Create().Get()}release(){B.bodyInterface.RemoveBody(this.body.GetID()),B.bodyInterface.DestroyBody(this.body.GetID()),Jolt.destroy(this.shape)}set(A){if(A.heightData){let I=A.heightData;const g=this.sample[0],C=Jolt._webidl_malloc(g*g*4),Q=new Float32Array(Jolt.HEAPF32.buffer,C,g*g),E=Jolt.castObject(this.body.GetShape(),Jolt.HeightFieldShape),i=I.length;for(let A=0;A<i;A++)Q[A]=I[A]*this.size[1];const o=this.body.GetCenterOfMassPosition();E.SetHeights(0,0,g,g,C,g,B.world.GetTempAllocator()),B.bodyInterface.NotifyShapeChanged(this.body,o,!1,Jolt.EActivation_Activate)}}}var N=async function(A={}){var g,C,B=A,Q=new Promise(((A,I)=>{g=A,C=I})),E="object"==typeof window,i="undefined"!=typeof WorkerGlobalScope,o="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node&&"renderer"!=process.type;if(o){const{createRequire:A}=await import("module");var t=A("undefined"==typeof document&&"undefined"==typeof location?require("url").pathToFileURL(__filename).href:"undefined"==typeof document?location.href:I&&"SCRIPT"===I.tagName.toUpperCase()&&I.src||new URL("Jolt.min.js",document.baseURI).href)}var D,e="./this.program",S="undefined"==typeof document&&"undefined"==typeof location?require("url").pathToFileURL(__filename).href:"undefined"==typeof document?location.href:I&&"SCRIPT"===I.tagName.toUpperCase()&&I.src||new URL("Jolt.min.js",document.baseURI).href;if(o){var y=t("fs"),a=t("path");S.startsWith("file:")&&a.dirname(t("url").fileURLToPath(S)),D=A=>(A=J(A)?new URL(A):A,y.readFileSync(A)),1<process.argv.length&&(e=process.argv[1].replace(/\\/g,"/")),process.argv.slice(2)}else if(E||i){try{new URL(".",S)}catch{}i&&(D=A=>{var I=new XMLHttpRequest;return I.open("GET",A,!1),I.responseType="arraybuffer",I.send(null),new Uint8Array(I.response)})}var p,K,s,r,w,n,M,c=console.log.bind(console),k=console.error.bind(console),h=!1,G=!1,J=A=>A.startsWith("file://"),U=0,N=null;function _(A){throw B.onAbort?.(A),k(A="Aborted("+A+")"),h=!0,A=new WebAssembly.RuntimeError(A+". Build with -sASSERTIONS for more info."),C(A),A}async function l(A){var I=M;try{var g=await async function(A){if(!ArrayBuffer.isView(A))if(A==M&&p)A=new Uint8Array(p);else{if(!D)throw"both async and sync fetching of the wasm failed";A=D(A)}return A}(I);return await WebAssembly.instantiate(g,A)}catch(A){k(`failed to asynchronously prepare wasm: ${A}`),_(A)}}for(var F,f=A=>{for(;0<A.length;)A.shift()(B)},Y=[],R=[],q=()=>{var A=B.preRun.shift();R.push(A)},d=(A,I,g,C)=>{if(!(0<C))return 0;var B=g;C=g+C-1;for(var Q=0;Q<A.length;++Q){var E=A.charCodeAt(Q);if(55296<=E&&57343>=E&&(E=65536+((1023&E)<<10)|1023&A.charCodeAt(++Q)),127>=E){if(g>=C)break;I[g++]=E}else{if(2047>=E){if(g+1>=C)break;I[g++]=192|E>>6}else{if(65535>=E){if(g+2>=C)break;I[g++]=224|E>>12}else{if(g+3>=C)break;I[g++]=240|E>>18,I[g++]=128|E>>12&63}I[g++]=128|E>>6&63}I[g++]=128|63&E}}return I[g]=0,g-B},L=[],O=(A,I,g)=>{L.length=0;for(var C;C=s[I++];){var B=105!=C;g+=(B&=112!=C)&&g%8?4:0,L.push(112==C?w[g>>2]:105==C?r[g>>2]:n[g>>3]),g+=B?8:4}return V[A](...L)},H={},u=()=>{if(!F){var A,I={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:e||"./this.program"};for(A in H)void 0===H[A]?delete I[A]:I[A]=H[A];var g=[];for(A in I)g.push(`${A}=${I[A]}`);F=g}return F},m=A=>{for(var I=0,g=0;g<A.length;++g){var C=A.charCodeAt(g);127>=C?I++:2047>=C?I+=2:55296<=C&&57343>=C?(I+=4,++g):I+=3}return I},b=[null,[],[]],j="undefined"!=typeof TextDecoder?new TextDecoder:void 0,T=(A,I=0)=>{for(var g=I+NaN,C=I;A[C]&&!(C>=g);)++C;if(16<C-I&&A.buffer&&j)return j.decode(A.subarray(I,C));for(g="";I<C;){var B=A[I++];if(128&B){var Q=63&A[I++];if(192==(224&B))g+=String.fromCharCode((31&B)<<6|Q);else{var E=63&A[I++];65536>(B=224==(240&B)?(15&B)<<12|Q<<6|E:(7&B)<<18|Q<<12|E<<6|63&A[I++])?g+=String.fromCharCode(B):(B-=65536,g+=String.fromCharCode(55296|B>>10,56320|1023&B))}}else g+=String.fromCharCode(B)}return g},P=[],x=new Uint8Array(123),Z=25;0<=Z;--Z)x[48+Z]=52+Z,x[65+Z]=Z,x[97+Z]=26+Z;x[43]=62,x[47]=63,B.print&&(c=B.print),B.printErr&&(k=B.printErr),B.wasmBinary&&(p=B.wasmBinary),B.thisProgram&&(e=B.thisProgram);var V={36114:A=>{if(!(A=B.getCache(B.PathConstraintPathJS)[A]).hasOwnProperty("GetPathMaxFraction"))throw"a JSImplementation must implement all functions, you forgot PathConstraintPathJS::GetPathMaxFraction.";return A.GetPathMaxFraction()},36381:(A,I,g)=>{if(!(A=B.getCache(B.PathConstraintPathJS)[A]).hasOwnProperty("GetClosestPoint"))throw"a JSImplementation must implement all functions, you forgot PathConstraintPathJS::GetClosestPoint.";return A.GetClosestPoint(I,g)},36644:(A,I,g,C,Q,E)=>{if(!(A=B.getCache(B.PathConstraintPathJS)[A]).hasOwnProperty("GetPointOnPath"))throw"a JSImplementation must implement all functions, you forgot PathConstraintPathJS::GetPointOnPath.";A.GetPointOnPath(I,g,C,Q,E)},36906:(A,I,g)=>{if(!(A=B.getCache(B.GroupFilterJS)[A]).hasOwnProperty("CanCollide"))throw"a JSImplementation must implement all functions, you forgot GroupFilterJS::CanCollide.";return A.CanCollide(I,g)},37140:(A,I)=>{if(!(A=B.getCache(B.StateRecorderFilterJS)[A]).hasOwnProperty("ShouldSaveBody"))throw"a JSImplementation must implement all functions, you forgot StateRecorderFilterJS::ShouldSaveBody.";return A.ShouldSaveBody(I)},37399:(A,I)=>{if(!(A=B.getCache(B.StateRecorderFilterJS)[A]).hasOwnProperty("ShouldSaveConstraint"))throw"a JSImplementation must implement all functions, you forgot StateRecorderFilterJS::ShouldSaveConstraint.";return A.ShouldSaveConstraint(I)},37676:(A,I,g)=>{if(!(A=B.getCache(B.StateRecorderFilterJS)[A]).hasOwnProperty("ShouldSaveContact"))throw"a JSImplementation must implement all functions, you forgot StateRecorderFilterJS::ShouldSaveContact.";return A.ShouldSaveContact(I,g)},37947:(A,I,g)=>{if(!(A=B.getCache(B.StateRecorderFilterJS)[A]).hasOwnProperty("ShouldRestoreContact"))throw"a JSImplementation must implement all functions, you forgot StateRecorderFilterJS::ShouldRestoreContact.";return A.ShouldRestoreContact(I,g)},38227:A=>{if(!(A=B.getCache(B.StateRecorderJS)[A]).hasOwnProperty("IsEOF"))throw"a JSImplementation must implement all functions, you forgot StateRecorderJS::IsEOF.";return A.IsEOF()},38445:A=>{if(!(A=B.getCache(B.StateRecorderJS)[A]).hasOwnProperty("IsFailed"))throw"a JSImplementation must implement all functions, you forgot StateRecorderJS::IsFailed.";return A.IsFailed()},38672:(A,I,g)=>{if(!(A=B.getCache(B.StateRecorderJS)[A]).hasOwnProperty("WriteBytes"))throw"a JSImplementation must implement all functions, you forgot StateRecorderJS::WriteBytes.";A.WriteBytes(I,g)},38903:(A,I,g)=>{if(!(A=B.getCache(B.StateRecorderJS)[A]).hasOwnProperty("ReadBytes"))throw"a JSImplementation must implement all functions, you forgot StateRecorderJS::ReadBytes.";A.ReadBytes(I,g)},39131:(A,I,g,C,Q)=>{if(!(A=B.getCache(B.ContactListenerJS)[A]).hasOwnProperty("OnContactAdded"))throw"a JSImplementation must implement all functions, you forgot ContactListenerJS::OnContactAdded.";A.OnContactAdded(I,g,C,Q)},39384:(A,I,g,C,Q)=>{if(!(A=B.getCache(B.ContactListenerJS)[A]).hasOwnProperty("OnContactPersisted"))throw"a JSImplementation must implement all functions, you forgot ContactListenerJS::OnContactPersisted.";A.OnContactPersisted(I,g,C,Q)},39649:(A,I)=>{if(!(A=B.getCache(B.ContactListenerJS)[A]).hasOwnProperty("OnContactRemoved"))throw"a JSImplementation must implement all functions, you forgot ContactListenerJS::OnContactRemoved.";A.OnContactRemoved(I)},39899:(A,I,g,C,Q)=>{if(!(A=B.getCache(B.ContactListenerJS)[A]).hasOwnProperty("OnContactValidate"))throw"a JSImplementation must implement all functions, you forgot ContactListenerJS::OnContactValidate.";return A.OnContactValidate(I,g,C,Q)},40168:(A,I,g)=>{if(!(A=B.getCache(B.SoftBodyContactListenerJS)[A]).hasOwnProperty("OnSoftBodyContactAdded"))throw"a JSImplementation must implement all functions, you forgot SoftBodyContactListenerJS::OnSoftBodyContactAdded.";A.OnSoftBodyContactAdded(I,g)},40455:(A,I,g,C)=>{if(!(A=B.getCache(B.SoftBodyContactListenerJS)[A]).hasOwnProperty("OnSoftBodyContactValidate"))throw"a JSImplementation must implement all functions, you forgot SoftBodyContactListenerJS::OnSoftBodyContactValidate.";return A.OnSoftBodyContactValidate(I,g,C)},40761:A=>{if(!(A=B.getCache(B.RayCastBodyCollectorJS)[A]).hasOwnProperty("Reset"))throw"a JSImplementation must implement all functions, you forgot RayCastBodyCollectorJS::Reset.";A.Reset()},40986:(A,I)=>{if(!(A=B.getCache(B.RayCastBodyCollectorJS)[A]).hasOwnProperty("AddHit"))throw"a JSImplementation must implement all functions, you forgot RayCastBodyCollectorJS::AddHit.";A.AddHit(I)},41216:A=>{if(!(A=B.getCache(B.CollideShapeBodyCollectorJS)[A]).hasOwnProperty("Reset"))throw"a JSImplementation must implement all functions, you forgot CollideShapeBodyCollectorJS::Reset.";A.Reset()},41451:(A,I)=>{if(!(A=B.getCache(B.CollideShapeBodyCollectorJS)[A]).hasOwnProperty("AddHit"))throw"a JSImplementation must implement all functions, you forgot CollideShapeBodyCollectorJS::AddHit.";A.AddHit(I)},41691:A=>{if(!(A=B.getCache(B.CastShapeBodyCollectorJS)[A]).hasOwnProperty("Reset"))throw"a JSImplementation must implement all functions, you forgot CastShapeBodyCollectorJS::Reset.";A.Reset()},41920:(A,I)=>{if(!(A=B.getCache(B.CastShapeBodyCollectorJS)[A]).hasOwnProperty("AddHit"))throw"a JSImplementation must implement all functions, you forgot CastShapeBodyCollectorJS::AddHit.";A.AddHit(I)},42154:A=>{if(!(A=B.getCache(B.CastRayCollectorJS)[A]).hasOwnProperty("Reset"))throw"a JSImplementation must implement all functions, you forgot CastRayCollectorJS::Reset.";A.Reset()},42371:(A,I)=>{if(!(A=B.getCache(B.CastRayCollectorJS)[A]).hasOwnProperty("OnBody"))throw"a JSImplementation must implement all functions, you forgot CastRayCollectorJS::OnBody.";A.OnBody(I)},42593:(A,I)=>{if(!(A=B.getCache(B.CastRayCollectorJS)[A]).hasOwnProperty("AddHit"))throw"a JSImplementation must implement all functions, you forgot CastRayCollectorJS::AddHit.";A.AddHit(I)},42815:A=>{if(!(A=B.getCache(B.CollidePointCollectorJS)[A]).hasOwnProperty("Reset"))throw"a JSImplementation must implement all functions, you forgot CollidePointCollectorJS::Reset.";A.Reset()},43042:(A,I)=>{if(!(A=B.getCache(B.CollidePointCollectorJS)[A]).hasOwnProperty("OnBody"))throw"a JSImplementation must implement all functions, you forgot CollidePointCollectorJS::OnBody.";A.OnBody(I)},43274:(A,I)=>{if(!(A=B.getCache(B.CollidePointCollectorJS)[A]).hasOwnProperty("AddHit"))throw"a JSImplementation must implement all functions, you forgot CollidePointCollectorJS::AddHit.";A.AddHit(I)},43506:A=>{if(!(A=B.getCache(B.CollideShapeCollectorJS)[A]).hasOwnProperty("Reset"))throw"a JSImplementation must implement all functions, you forgot CollideShapeCollectorJS::Reset.";A.Reset()},43733:(A,I)=>{if(!(A=B.getCache(B.CollideShapeCollectorJS)[A]).hasOwnProperty("OnBody"))throw"a JSImplementation must implement all functions, you forgot CollideShapeCollectorJS::OnBody.";A.OnBody(I)},43965:(A,I)=>{if(!(A=B.getCache(B.CollideShapeCollectorJS)[A]).hasOwnProperty("AddHit"))throw"a JSImplementation must implement all functions, you forgot CollideShapeCollectorJS::AddHit.";A.AddHit(I)},44197:A=>{if(!(A=B.getCache(B.CastShapeCollectorJS)[A]).hasOwnProperty("Reset"))throw"a JSImplementation must implement all functions, you forgot CastShapeCollectorJS::Reset.";A.Reset()},44418:(A,I)=>{if(!(A=B.getCache(B.CastShapeCollectorJS)[A]).hasOwnProperty("OnBody"))throw"a JSImplementation must implement all functions, you forgot CastShapeCollectorJS::OnBody.";A.OnBody(I)},44644:(A,I)=>{if(!(A=B.getCache(B.CastShapeCollectorJS)[A]).hasOwnProperty("AddHit"))throw"a JSImplementation must implement all functions, you forgot CastShapeCollectorJS::AddHit.";A.AddHit(I)},44870:A=>{if(!(A=B.getCache(B.TransformedShapeCollectorJS)[A]).hasOwnProperty("Reset"))throw"a JSImplementation must implement all functions, you forgot TransformedShapeCollectorJS::Reset.";A.Reset()},45105:(A,I)=>{if(!(A=B.getCache(B.TransformedShapeCollectorJS)[A]).hasOwnProperty("OnBody"))throw"a JSImplementation must implement all functions, you forgot TransformedShapeCollectorJS::OnBody.";A.OnBody(I)},45345:(A,I)=>{if(!(A=B.getCache(B.TransformedShapeCollectorJS)[A]).hasOwnProperty("AddHit"))throw"a JSImplementation must implement all functions, you forgot TransformedShapeCollectorJS::AddHit.";A.AddHit(I)},45585:(A,I)=>{if(!(A=B.getCache(B.PhysicsStepListenerJS)[A]).hasOwnProperty("OnStep"))throw"a JSImplementation must implement all functions, you forgot PhysicsStepListenerJS::OnStep.";A.OnStep(I)},45813:(A,I,g)=>{if(!(A=B.getCache(B.BodyActivationListenerJS)[A]).hasOwnProperty("OnBodyActivated"))throw"a JSImplementation must implement all functions, you forgot BodyActivationListenerJS::OnBodyActivated.";A.OnBodyActivated(I,g)},46077:(A,I,g)=>{if(!(A=B.getCache(B.BodyActivationListenerJS)[A]).hasOwnProperty("OnBodyDeactivated"))throw"a JSImplementation must implement all functions, you forgot BodyActivationListenerJS::OnBodyDeactivated.";A.OnBodyDeactivated(I,g)},46347:(A,I,g,C,Q)=>{if(!(A=B.getCache(B.CharacterContactListenerJS)[A]).hasOwnProperty("OnAdjustBodyVelocity"))throw"a JSImplementation must implement all functions, you forgot CharacterContactListenerJS::OnAdjustBodyVelocity.";A.OnAdjustBodyVelocity(I,g,C,Q)},46636:(A,I,g,C)=>{if(!(A=B.getCache(B.CharacterContactListenerJS)[A]).hasOwnProperty("OnContactValidate"))throw"a JSImplementation must implement all functions, you forgot CharacterContactListenerJS::OnContactValidate.";return A.OnContactValidate(I,g,C)},46920:(A,I,g,C)=>{if(!(A=B.getCache(B.CharacterContactListenerJS)[A]).hasOwnProperty("OnCharacterContactValidate"))throw"a JSImplementation must implement all functions, you forgot CharacterContactListenerJS::OnCharacterContactValidate.";return A.OnCharacterContactValidate(I,g,C)},47231:(A,I,g,C)=>{if(!(A=B.getCache(B.CharacterContactListenerJS)[A]).hasOwnProperty("OnContactRemoved"))throw"a JSImplementation must implement all functions, you forgot CharacterContactListenerJS::OnContactRemoved.";A.OnContactRemoved(I,g,C)},47505:(A,I,g,C)=>{if(!(A=B.getCache(B.CharacterContactListenerJS)[A]).hasOwnProperty("OnCharacterContactRemoved"))throw"a JSImplementation must implement all functions, you forgot CharacterContactListenerJS::OnCharacterContactRemoved.";A.OnCharacterContactRemoved(I,g,C)},47806:(A,I,g,C,Q,E,i)=>{if(!(A=B.getCache(B.CharacterContactListenerJS)[A]).hasOwnProperty("OnContactAdded"))throw"a JSImplementation must implement all functions, you forgot CharacterContactListenerJS::OnContactAdded.";A.OnContactAdded(I,g,C,Q,E,i)},48083:(A,I,g,C,Q,E,i)=>{if(!(A=B.getCache(B.CharacterContactListenerJS)[A]).hasOwnProperty("OnContactPersisted"))throw"a JSImplementation must implement all functions, you forgot CharacterContactListenerJS::OnContactPersisted.";A.OnContactPersisted(I,g,C,Q,E,i)},48372:(A,I,g,C,Q,E,i)=>{if(!(A=B.getCache(B.CharacterContactListenerJS)[A]).hasOwnProperty("OnCharacterContactAdded"))throw"a JSImplementation must implement all functions, you forgot CharacterContactListenerJS::OnCharacterContactAdded.";A.OnCharacterContactAdded(I,g,C,Q,E,i)},48676:(A,I,g,C,Q,E,i)=>{if(!(A=B.getCache(B.CharacterContactListenerJS)[A]).hasOwnProperty("OnCharacterContactPersisted"))throw"a JSImplementation must implement all functions, you forgot CharacterContactListenerJS::OnCharacterContactPersisted.";A.OnCharacterContactPersisted(I,g,C,Q,E,i)},48992:(A,I,g,C,Q,E,i,o,t,D)=>{if(!(A=B.getCache(B.CharacterContactListenerJS)[A]).hasOwnProperty("OnContactSolve"))throw"a JSImplementation must implement all functions, you forgot CharacterContactListenerJS::OnContactSolve.";A.OnContactSolve(I,g,C,Q,E,i,o,t,D)},49278:(A,I,g,C,Q,E,i,o,t,D)=>{if(!(A=B.getCache(B.CharacterContactListenerJS)[A]).hasOwnProperty("OnCharacterContactSolve"))throw"a JSImplementation must implement all functions, you forgot CharacterContactListenerJS::OnCharacterContactSolve.";A.OnCharacterContactSolve(I,g,C,Q,E,i,o,t,D)},49591:(A,I,g)=>{if(!(A=B.getCache(B.ObjectVsBroadPhaseLayerFilterJS)[A]).hasOwnProperty("ShouldCollide"))throw"a JSImplementation must implement all functions, you forgot ObjectVsBroadPhaseLayerFilterJS::ShouldCollide.";return A.ShouldCollide(I,g)},49870:(A,I)=>{if(!(A=B.getCache(B.ObjectLayerFilterJS)[A]).hasOwnProperty("ShouldCollide"))throw"a JSImplementation must implement all functions, you forgot ObjectLayerFilterJS::ShouldCollide.";return A.ShouldCollide(I)},50122:(A,I,g)=>{if(!(A=B.getCache(B.ObjectLayerPairFilterJS)[A]).hasOwnProperty("ShouldCollide"))throw"a JSImplementation must implement all functions, you forgot ObjectLayerPairFilterJS::ShouldCollide.";return A.ShouldCollide(I,g)},50385:(A,I)=>{if(!(A=B.getCache(B.BodyFilterJS)[A]).hasOwnProperty("ShouldCollide"))throw"a JSImplementation must implement all functions, you forgot BodyFilterJS::ShouldCollide.";return A.ShouldCollide(I)},50623:(A,I)=>{if(!(A=B.getCache(B.BodyFilterJS)[A]).hasOwnProperty("ShouldCollideLocked"))throw"a JSImplementation must implement all functions, you forgot BodyFilterJS::ShouldCollideLocked.";return A.ShouldCollideLocked(I)},50879:(A,I,g)=>{if(!(A=B.getCache(B.ShapeFilterJS)[A]).hasOwnProperty("ShouldCollide"))throw"a JSImplementation must implement all functions, you forgot ShapeFilterJS::ShouldCollide.";return A.ShouldCollide(I,g)},51122:(A,I,g,C,Q)=>{if(!(A=B.getCache(B.ShapeFilterJS2)[A]).hasOwnProperty("ShouldCollide"))throw"a JSImplementation must implement all functions, you forgot ShapeFilterJS2::ShouldCollide.";return A.ShouldCollide(I,g,C,Q)},51373:(A,I,g,C,Q,E,i)=>{if(!(A=B.getCache(B.SimShapeFilterJS)[A]