UNPKG

phy-engine

Version:

JavaScript 3D Physics for three.js

6 lines 624 kB
/** * @license * Copyright 2010-2025 Phy.js Authors * SPDX-License-Identifier: MIT */ import{LineSegments as e,BufferGeometry as t,BufferAttribute as i,Float32BufferAttribute as s,LineBasicMaterial as a,SphereGeometry as r,CylinderGeometry as n,BoxGeometry as l,PlaneGeometry as h,CanvasTexture as c,RepeatWrapping as A,SRGBColorSpace as u,MeshPhysicalMaterial as d,Color as p,Vector2 as g,MeshStandardMaterial as f,ShadowMaterial as b,MeshToonMaterial as y,MeshBasicMaterial as w,MeshLambertMaterial as I,MeshPhongMaterial as E,DoubleSide as C,BackSide as v,FrontSide as B,SrcAlphaSaturateFactor as x,OneMinusDstColorFactor as k,DstColorFactor as Q,OneMinusDstAlphaFactor as S,DstAlphaFactor as M,OneMinusSrcAlphaFactor as R,SrcAlphaFactor as D,OneMinusSrcColorFactor as T,SrcColorFactor as F,OneFactor as L,ZeroFactor as P,MaxEquation as _,MinEquation as z,ReverseSubtractEquation as U,SubtractEquation as N,AddEquation as G,MultiplyBlending as O,SubtractiveBlending as q,AdditiveBlending as j,NormalBlending as H,NoBlending as V,Line as K,Vector3 as W,Matrix4 as J,InstancedMesh as X,Quaternion as Y,Mesh as Z,InstancedBufferAttribute as $,CircleGeometry as ee,Box3 as te,Object3D as ie,Line3 as se,Plane as ae,Triangle as re,Loader as ne,FileLoader as oe,Matrix3 as le,Box2 as he,ShapeUtils as ce,Shape as Ae,Path as ue,ShapePath as de,ShapeGeometry as pe,Euler as ge,TrianglesDrawMode as me,TriangleFanDrawMode as fe,TriangleStripDrawMode as be,LoaderUtils as ye,LinearSRGBColorSpace as we,SpotLight as Ie,PointLight as Ee,DirectionalLight as Ce,TextureLoader as ve,ImageBitmapLoader as Be,InterleavedBuffer as xe,InterleavedBufferAttribute as ke,LinearMipmapLinearFilter as Qe,NearestMipmapLinearFilter as Se,LinearMipmapNearestFilter as Me,NearestMipmapNearestFilter as Re,LinearFilter as De,NearestFilter as Te,MirroredRepeatWrapping as Fe,ClampToEdgeWrapping as Le,PointsMaterial as Pe,Material as _e,PropertyBinding as ze,SkinnedMesh as Ue,LineLoop as Ne,Points as Ge,Group as Oe,PerspectiveCamera as qe,MathUtils as je,OrthographicCamera as He,Skeleton as Ve,AnimationClip as Ke,Bone as We,InterpolateDiscrete as Je,InterpolateLinear as Xe,Texture as Ye,VectorKeyframeTrack as Ze,NumberKeyframeTrack as $e,QuaternionKeyframeTrack as et,ColorManagement as tt,Interpolant as it,Sphere as st,Vector4 as at,Curve as rt,EquirectangularReflectionMapping as nt,AmbientLight as ot,Uint16BufferAttribute as lt,DataTextureLoader as ht,HalfFloatType as ct,FloatType as At,DataUtils as ut,RGBAFormat as dt,RedFormat as pt,NoColorSpace as gt,DataTexture as mt,UVMapping as ft,LinearMipMapLinearFilter as bt,RGBA_S3TC_DXT1_Format as yt,RGB_PVRTC_4BPPV1_Format as wt,RGB_ETC2_Format as It,RGB_ETC1_Format as Et,RGBA_S3TC_DXT5_Format as Ct,RGBA_PVRTC_4BPPV1_Format as vt,RGBA_ETC2_EAC_Format as Bt,RGBA_BPTC_Format as xt,RGB_BPTC_UNSIGNED_Format as kt,RGBA_ASTC_4x4_Format as Qt,UnsignedByteType as St,CompressedCubeTexture as Mt,CompressedArrayTexture as Rt,CompressedTexture as Dt,RGBA_S3TC_DXT3_Format as Tt,RGB_S3TC_DXT1_Format as Ft,RGBA_ASTC_6x6_Format as Lt,RGFormat as Pt,Data3DTexture as _t,LoadingManager as zt,AnimationMixer as Ut,ObjectSpaceNormalMap as Nt,CustomBlending as Gt,SkeletonHelper as Ot,AnimationUtils as qt,AdditiveAnimationBlendMode as jt,NormalAnimationBlendMode as Ht,Raycaster as Vt,PMREMGenerator as Kt,Scene as Wt,WebGLCubeRenderTarget as Jt,CubeCamera as Xt,IcosahedronGeometry as Yt,ShaderMaterial as Zt,NoToneMapping as $t,AxesHelper as ei,InstancedBufferGeometry as ti,InstancedInterleavedBuffer as ii,DynamicDrawUsage as si}from"three";const ai=Math.PI,ri=ai/180,ni=180/ai,oi=Number.EPSILON,li=.5*ai,hi={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:e=>Math.pow(e,5),candelaToLumens:e=>4*e*Math.PI,lumensToCandela:e=>e/(4*Math.PI),todeg:ni,torad:ri,toFixed:(e,t=3)=>1*e.toFixed(t),toRound:(e,t=3)=>Math.trunc(e),clamp:(e,t=0,i=1)=>e=(e=e<t?t:e)>i?i:e,clampA:(e,t,i)=>Math.max(t,Math.min(i,e)),smoothstep:(e,t,i)=>e*(i=-2*(i=hi.clamp(i))*i*i+3*i*i)+t*(1-i),remap:(e,t,i,s,a)=>s+(e-t)*(a-s)/(i-t),lerp:(e,t,i)=>(1-i)*e+i*t,damp:(e,t,i,s)=>hi.lerp(e,t,1-Math.exp(-i*s)),nearAngle:(e,t,i=!1)=>t+Math.atan2(Math.sin(e-t),Math.cos(e-t))*(i?ni:1),unwrapDeg:e=>e-360*Math.floor((e+180)/360),unwrapRad:e=>Math.atan2(Math.sin(e),Math.cos(e)),nearEquals:(e,t,i=1e-4)=>Math.abs(e-t)<=i,autoSize:(e=[1,1,1],t="box")=>{1===e.length&&(e[1]=e[0]);let i=e[0],s=e[1];return"sphere"===t&&(e=[i,i,i]),"cylinder"!==t&&"wheel"!==t&&"capsule"!==t||(e=[i,s,i]),"cone"!==t&&"pyramid"!==t||(e=[i,s,i]),2===e.length&&(e[2]=e[0]),e},shuffle:e=>{let t=e.map((e=>({value:e,sort:Math.random()}))).sort(((e,t)=>e.sort-t.sort)).map((({value:e})=>e));return t},randomSign:()=>Math.random()<.5?-1:1,randSpread:e=>e*(.5-Math.random()),rand:(e=0,t=1)=>e+Math.random()*(t-e),randInt:(e,t)=>e+Math.floor(Math.random()*(t-e+1)),randIntUnic:(e,t,i)=>{for(var s=[];s.length<i;){var a=hi.randInt(e,t);-1===s.indexOf(a)&&s.push(a)}return s},fromTransform:(e,t,i,s=[0,0,0,1],a=!1)=>{let r=hi.composeMatrixArray(e,t),n=hi.composeMatrixArray(i,s);return a&&(r=hi.invertMatrixArray(r)),r=hi.multiplyMatrixArray(r,n),[r[12],r[13],r[14]]},fromTransformToQ:(e,t,i=!1)=>{let s=hi.composeMatrixArray(e,t),a=hi.decomposeFullMatrixArray(s).q;return i&&(a=hi.quatInvert(a)),a},lerpTransform:(e,t,i)=>{let s=e[0],a=e[1],r=t[0],n=t[1];return r=hi.lerpArray(s,r,i),n=hi.slerpQuatArray(a,n,i),[r,n]},composeMatrixArray:(e,t,i=[1,1,1])=>{const s=t[0],a=t[1],r=t[2],n=t[3],o=s+s,l=a+a,h=r+r,c=s*o,A=s*l,u=s*h,d=a*l,p=a*h,g=r*h,m=n*o,f=n*l,b=n*h,y=i[0],w=i[1],I=i[2];return[(1-(d+g))*y,(A+b)*y,(u-f)*y,0,(A-b)*w,(1-(c+g))*w,(p+m)*w,0,(u+f)*I,(p-m)*I,(1-(c+d))*I,0,e[0],e[1],e[2],1]},multiplyMatrixArray:(e,t)=>{const i=e,s=t,a=[],r=i[0],n=i[4],o=i[8],l=i[12],h=i[1],c=i[5],A=i[9],u=i[13],d=i[2],p=i[6],g=i[10],m=i[14],f=i[3],b=i[7],y=i[11],w=i[15],I=s[0],E=s[4],C=s[8],v=s[12],B=s[1],x=s[5],k=s[9],Q=s[13],S=s[2],M=s[6],R=s[10],D=s[14],T=s[3],F=s[7],L=s[11],P=s[15];return a[0]=r*I+n*B+o*S+l*T,a[4]=r*E+n*x+o*M+l*F,a[8]=r*C+n*k+o*R+l*L,a[12]=r*v+n*Q+o*D+l*P,a[1]=h*I+c*B+A*S+u*T,a[5]=h*E+c*x+A*M+u*F,a[9]=h*C+c*k+A*R+u*L,a[13]=h*v+c*Q+A*D+u*P,a[2]=d*I+p*B+g*S+m*T,a[6]=d*E+p*x+g*M+m*F,a[10]=d*C+p*k+g*R+m*L,a[14]=d*v+p*Q+g*D+m*P,a[3]=f*I+b*B+y*S+w*T,a[7]=f*E+b*x+y*M+w*F,a[11]=f*C+b*k+y*R+w*L,a[15]=f*v+b*Q+y*D+w*P,a},invertMatrixArray:e=>{const t=e,i=t[0],s=t[1],a=t[2],r=t[3],n=t[4],o=t[5],l=t[6],h=t[7],c=t[8],A=t[9],u=t[10],d=t[11],p=t[12],g=t[13],m=t[14],f=t[15],b=A*m*h-g*u*h+g*l*d-o*m*d-A*l*f+o*u*f,y=p*u*h-c*m*h-p*l*d+n*m*d+c*l*f-n*u*f,w=c*g*h-p*A*h+p*o*d-n*g*d-c*o*f+n*A*f,I=p*A*l-c*g*l-p*o*u+n*g*u+c*o*m-n*A*m,E=i*b+s*y+a*w+r*I;if(0===E)return[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];const C=1/E;return t[0]=b*C,t[1]=(g*u*r-A*m*r-g*a*d+s*m*d+A*a*f-s*u*f)*C,t[2]=(o*m*r-g*l*r+g*a*h-s*m*h-o*a*f+s*l*f)*C,t[3]=(A*l*r-o*u*r-A*a*h+s*u*h+o*a*d-s*l*d)*C,t[4]=y*C,t[5]=(c*m*r-p*u*r+p*a*d-i*m*d-c*a*f+i*u*f)*C,t[6]=(p*l*r-n*m*r-p*a*h+i*m*h+n*a*f-i*l*f)*C,t[7]=(n*u*r-c*l*r+c*a*h-i*u*h-n*a*d+i*l*d)*C,t[8]=w*C,t[9]=(p*A*r-c*g*r-p*s*d+i*g*d+c*s*f-i*A*f)*C,t[10]=(n*g*r-p*o*r+p*s*h-i*g*h-n*s*f+i*o*f)*C,t[11]=(c*o*r-n*A*r-c*s*h+i*A*h+n*s*d-i*o*d)*C,t[12]=I*C,t[13]=(c*g*a-p*A*a+p*s*u-i*g*u-c*s*m+i*A*m)*C,t[14]=(p*o*a-n*g*a-p*s*l+i*g*l+n*s*m-i*o*m)*C,t[15]=(n*A*a-c*o*a+c*s*l-i*A*l-n*s*u+i*o*u)*C,t},matrixArrayDeterminant:e=>{const t=e,i=t[0],s=t[4],a=t[8],r=t[12],n=t[1],o=t[5],l=t[9],h=t[13],c=t[2],A=t[6],u=t[10],d=t[14];return t[3]*(+r*l*A-a*h*A-r*o*u+s*h*u+a*o*d-s*l*d)+t[7]*(+i*l*d-i*h*u+r*n*u-a*n*d+a*h*c-r*l*c)+t[11]*(+i*h*A-i*o*d-r*n*A+s*n*d+r*o*c-s*h*c)+t[15]*(-a*o*c-i*l*A+i*o*u+a*n*A-s*n*u+s*l*c)},decomposeMatrixArray:e=>[e[12],e[13],e[14]],decomposeFullMatrixArray:e=>{const t=e;let i=hi.lengthArray([t[0],t[1],t[2]]);const s=hi.lengthArray([t[4],t[5],t[6]]),a=hi.lengthArray([t[8],t[9],t[10]]);hi.matrixArrayDeterminant(e)<0&&(i=-i);let r=[...e];const n=1/i,o=1/s,l=1/a;r[0]*=n,r[1]*=n,r[2]*=n,r[4]*=o,r[5]*=o,r[6]*=o,r[8]*=l,r[9]*=l,r[10]*=l;let h=hi.quatFromRotationMatrix(r);return{p:[e[12],e[13],e[14]],q:h,s:[i,s,a]}},applyTransformArray:(e,t,i,s=[1,1,1])=>{const a=hi.composeMatrixArray(t,i,s),r=e[0],n=e[1],o=e[2],l=1/(a[3]*r+a[7]*n+a[11]*o+a[15]);return[(a[0]*r+a[4]*n+a[8]*o+a[12])*l,(a[1]*r+a[5]*n+a[9]*o+a[13])*l,(a[2]*r+a[6]*n+a[10]*o+a[14])*l]},slerpQuatArray:(e,t,i)=>{if(0===i)return e;if(1===i)return t;let s=[...e];const a=e[0],r=e[1],n=e[2],o=e[3],l=t[0],h=t[1],c=t[2],A=t[3];let u=o*A+a*l+r*h+n*c;if(u<0?(s=[-l,-h,-c,-A],u=-u):s=[...t],u>=1)return e;const d=1-u*u;if(d<=oi){const e=1-i;return s[3]=e*o+i*s[3],s[0]=e*a+i*s[0],s[1]=e*r+i*s[1],s[2]=e*n+i*s[2],hi.quatNomalize(s)}const p=Math.sqrt(d),g=Math.atan2(p,u),m=Math.sin((1-i)*g)/p,f=Math.sin(i*g)/p;return s[3]=o*m+s[3]*f,s[0]=a*m+s[0]*f,s[1]=r*m+s[1]*f,s[2]=n*m+s[2]*f,s},toLocalQuatArray:(e=[0,0,0],t)=>{let i=hi.quatFromEuler(e),s=hi.quatInvert(t.quaternion.toArray());return hi.quatMultiply(s,i)},quatFromRotationMatrix:e=>{let t=[0,0,0,1];const i=e,s=i[0],a=i[4],r=i[8],n=i[1],o=i[5],l=i[9],h=i[2],c=i[6],A=i[10],u=s+o+A;if(u>0){const e=.5/Math.sqrt(u+1);t[3]=.25/e,t[0]=(c-l)*e,t[1]=(r-h)*e,t[2]=(n-a)*e}else if(s>o&&s>A){const e=2*Math.sqrt(1+s-o-A);t[3]=(c-l)/e,t[0]=.25*e,t[1]=(a+n)/e,t[2]=(r+h)/e}else if(o>A){const e=2*Math.sqrt(1+o-s-A);t[3]=(r-h)/e,t[0]=(a+n)/e,t[1]=.25*e,t[2]=(l+c)/e}else{const e=2*Math.sqrt(1+A-s-o);t[3]=(n-a)/e,t[0]=(r+h)/e,t[1]=(l+c)/e,t[2]=.25*e}return t},quatFromEuler:(e=[0,0,0],t=!0)=>{const i=Math.cos,s=Math.sin,a=t?ri:1,r=e[0]*a*.5,n=e[1]*a*.5,o=e[2]*a*.5,l=i(r),h=i(n),c=i(o),A=s(r),u=s(n),d=s(o);return[A*h*c+l*u*d,l*u*c-A*h*d,l*h*d+A*u*c,l*h*c-A*u*d]},quatFromAxis:(e=[0,0,0],t,i=!0)=>{const s=.5*t*(i?ri:1),a=Math.sin(s);return[e[0]*a,e[1]*a,e[2]*a,Math.cos(s)]},quatNomalize:e=>{let t=hi.lengthArray(e);return 0===t?[0,0,0,1]:(t=1/t,hi.scaleArray(e,t,4))},quatInvert:e=>[-e[0],-e[1],-e[2],e[3]],quatMultiply:(e,t)=>{const i=e[0],s=e[1],a=e[2],r=e[3],n=t[0],o=t[1],l=t[2],h=t[3];return[i*h+r*n+s*l-a*o,s*h+r*o+a*n-i*l,a*h+r*l+i*o-s*n,r*h-i*n-s*o-a*l]},quatToAxis:e=>{let t=2*Math.acos(e[3]);const i=Math.sqrt(1-e[3]*e[3]);return i<1e-4?[1,0,0]:[e[0]/i,e[1]/i,e[2]/i,t]},eulerFromMatrix:e=>{const t=e[0],i=e[4],s=e[8];e[1];const a=e[5],r=e[9];e[2];const n=e[6],o=e[10];let l=[0,0,0];return l[1]=Math.asin(hi.clamp(s,-1,1)),Math.abs(s)<.9999999?(l[0]=Math.atan2(-r,o),l[2]=Math.atan2(-i,t)):(l[0]=Math.atan2(n,a),l[2]=0),l},angleTo:(e,t)=>2*Math.acos(Math.abs(hi.clamp(hi.dotArray(e,t),-1,1))),fixedArray:(e,t)=>{let i=e.length,s=[];for(;i--;)s[i]=hi.toFixed(e[i],t);return s},getSize:e=>.001*e.byteLength+"kb",perpendicularArray:e=>{const t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);let i=Math.acos(e[1]/t);const s=Math.atan2(e[2],e[0]);i>li?i-=li:i+=li;return[t*Math.sin(i)*Math.cos(s),t*Math.cos(i),t*Math.sin(i)*Math.sin(s)]},crossArray:(e,t)=>{const i=e[0],s=e[1],a=e[2],r=t[0],n=t[1],o=t[2];return[s*o-a*n,a*r-i*o,i*n-s*r]},applyQuaternion:(e,t)=>{const i=e[0],s=e[1],a=e[2],r=t[0],n=t[1],o=t[2],l=t[3],h=2*(n*a-o*s),c=2*(o*i-r*a),A=2*(r*s-n*i);return[i+l*h+n*A-o*c,s+l*c+o*h-r*A,a+l*A+r*c-n*h]},nullArray:(e,t,i)=>{let s=0;for(;i--;)s+=e[t+i];return s},equalArray:(e,t)=>{let i=e.length;for(;i--;)if(e[i]!==t[i])return!1;return!0},lerpArray:(e,t,i)=>{if(0===i)return e;if(1===i)return t;let s=e.length,a=[];for(;s--;)a[s]=e[s],a[s]+=(t[s]-a[s])*i;return a},zeroArray:(e,t=0,i)=>{for(i=i??e.length;i--;)e[t+i]=0;return e},lengthArray:e=>{let t=e.length,i=0;for(;t--;)i+=e[t]*e[t];return Math.sqrt(i)},dotArray:(e,t)=>{let i=e.length,s=0;for(;i--;)s+=e[i]*t[i];return s},addArray:(e,t,i)=>{i=i??e.length;let s=[];for(;i--;)s[i]=e[i]+t[i];return s},subArray:(e,t,i)=>{i=i??e.length;let s=[];for(;i--;)s[i]=e[i]-t[i];return s},mulArray:(e,t,i)=>{if(t instanceof Array){let s=[];for(i=i??e.length;i--;)s[i]=e[i]*t[i];return s}return e.map((e=>e*t))},worldscale:(e,t)=>e.map((e=>e*t)),divArray:(e,t,i)=>hi.mulArray(e,1/t,i),scaleArray:(e,t,i)=>hi.mulArray(e,t,i),fillArray:(e,t,i=0,s)=>{for(s=s??e.length;s--;)t[i+s]=e[s]},copyArray:(e,t)=>{},cloneArray:e=>[...e],distanceArray:(e,t=[0,0,0])=>hi.lengthArray(hi.subArray(e,t)),normalizeArray:e=>hi.divArray(e,hi.lengthArray(e)||1),normalArray:(e,t=[0,0,0])=>hi.normalizeArray(hi.subArray(t,e)),getCenter:(e,t)=>(e.computeBoundingBox(),e.boundingBox.getCenter(t)),getVolume:(e,t,i=null)=>{let s=1,a=t;switch(e){case"sphere":s=4*Math.PI*a[0]*a[0]*a[0]/3;break;case"cone":s=Math.PI*a[0]*(.5*a[1])*2;break;case"box":s=.5*a[0]*8*(.5*a[1])*(.5*a[2]);break;case"cylinder":s=Math.PI*a[0]*a[0]*(.5*a[1])*2;break;case"capsule":s=4*Math.PI*a[0]*a[0]*a[0]/3+Math.PI*a[0]*a[0]*(.5*a[1])*2;break;case"convex":case"mesh":s=hi.getConvexVolume(i)}return s},getConvexVolume:e=>{let t,i=e.length/3,s=[0,0,0],a=[0,0,0];for(;i--;)t=3*i,e[t]<s[0]?s[0]=e[t]:e[t]>a[0]&&(a[0]=e[t]),e[t+1]<s[1]?s[1]=e[t+1]:e[t+1]>a[1]&&(a[1]=e[t+1]),e[t+2]<s[2]?s[2]=e[t+2]:e[t+2]>a[2]&&(a[2]=e[t+2]);let r=[a[0]-s[0],a[1]-s[1],a[2]-s[2]];return.5*r[0]*8*(.5*r[1])*(.5*r[2])},massFromDensity:(e,t)=>e*t,densityFromMass:(e,t)=>e/t,toNonIndexed:e=>e.index?e.clone().toNonIndexed():e,getIndex:(e,t)=>!e.index||t?null:e.index.array||null,getSameVertex:e=>{const t=e.getAttribute("position"),i=t.array,s=[],a=[],r={};new THREE.Vector3;let n,o=0;hi.getHash(e);let l,h,c=!1,A=0;for(let e=0;e<t.count;e++){o=3*e,l={x:i[o],y:i[o+1],z:i[o+2],id:e},c=!1,n=s.length;for(let t=0;t<n;t++)h=s[t],l.x===h.x&&l.y===h.y&&l.z===h.z&&(c=!0,r[e]=h.id);c||(l.id=A++,s.push(l),a.push([l.x,l.y,l.z]))}return[a,r]},getVertex:(e,t)=>{let i=e.attributes.position.array;return t&&e.index&&(i=(e=e.clone().toNonIndexed()).attributes.position.array),i},getNormal:e=>e.attributes.normal.array,getFaces:e=>{let t=[];if(e.index){let i=e.getIndex();for(let e=0;e<i.count;e+=3)t.push([i.getX(e),i.getX(e+1),i.getX(e+2)])}else{let i=e.getAttribute("position").count;for(let e=0;e<i;e+=3)t.push([e,e+1,e+2])}return t},getConnectedFaces:e=>{const t=[];let i,s,a,r,n,o,l,h=e.length,c=h;for(;c--;)for(s=e[c],i=h;i--;)i!==c&&(a=e[i],r=s.filter((e=>a.includes(e))),r.length>1&&(l=[],n=[...s],o=n.indexOf(r[0]),n.splice(o,1),o=n.indexOf(r[1]),n.splice(o,1),l.push(n[0]),n=[...a],o=n.indexOf(r[0]),n.splice(o,1),o=n.indexOf(r[1]),n.splice(o,1),l.push(n[0]),t.push(l)));return t},reduce:e=>{},barycentric:(e,t)=>{},solve:(e,t)=>{},getHash:(e,t=1e-4)=>{t=Math.max(t,Number.EPSILON);const i={},s={},a=e.getAttribute("position"),r=a.count,n=a.array,o=.5*t,l=Math.log10(1/t),h=Math.pow(10,l),c=o*h;let A;for(let e=0;e<r;e++){A=3*e;let t=`${~~(n[A]*h+c)},${~~(n[A+1]*h+c)},${~~(n[A+2]*h+c)}`;i[t]?i[t].push(e):i[t]=[e]}let u=0;for(let e in i)s[u++]=i[e];return s}},ci=hi,Ai=["PHYSX","HAVOK"],ui=4e3,di=1e3,pi=4e3,gi=100,mi=100,fi=50,bi=20,yi={bodyFull:14,body:8,joint:16,contact:1,ray:11,character:16,vehicle:72,solver:128},wi=function(e,t=!1){const i={};let s={body:ui*(t?yi.bodyFull:yi.body),joint:di*yi.joint,ray:gi*yi.ray,contact:pi*yi.contact,character:mi*yi.character};"PHYSX"!==e&&"AMMO"!==e||(s.vehicle=fi*yi.vehicle),"PHYSX"===e&&(s.solver=bi*yi.solver),"HAVOK"!==e&&"RAPIER"!==e&&"JOLT"!==e||(yi.joint=0);let a=0;for(let e in s)i[e]=a,a+=s[e];return i.total=a,i};class Ii extends e{constructor(e,r=16776960){const n=new Uint16Array([0,1,1,2,2,3,3,4,4,5,5,0,6,7,7,8,8,9,9,10,10,11,11,6,12,13,13,14,14,15,15,16,16,17,17,12,18,19,20,21,22,23]),o=[.5,0,0,.25,.433,0,-.25,.433,0,-.5,0,0,-.25,-.433,0,.25,-.433,0,.5,0,0,.25,0,.433,-.25,0,.433,-.5,0,0,-.25,0,-.433,.25,0,-.433,0,.5,0,0,.25,.433,0,-.25,.433,0,-.5,0,0,-.25,-.433,0,.25,-.433,0,0,0,.6,0,0,0,0,0,0,.6,0,0,0,0,0,0,.6],l=new t;l.setIndex(new i(n,1)),l.setAttribute("position",new s(o,3)),l.setAttribute("color",new s([0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,1],3)),super(l,new a({color:r,depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0})),this.box=e,this.type="CircleHelper",this.geometry.computeBoundingSphere()}updateMatrixWorld(e){const t=this.box;t.isEmpty()||(t.getCenter(this.position),t.getSize(this.scale),this.scale.multiplyScalar(.5),super.updateMatrixWorld(e))}dispose(){this.geometry.dispose(),this.material.dispose()}}let Ei=class{constructor(){this.geoN=0,this.geo={}}unic(e){this.geo["geo"+this.geoN++]=e}set(e){this.geo[e.name]=e}get(e,t={}){if(!this.geo[e]){let t;switch(e){case"plane":t=new h(1,1),t.rotateX(.5*-Math.PI);break;case"box":t=new l(1,1,1);break;case"sphere":t=new r(1,16,12);break;case"cylinder":t=new n(1,1,1,16);break;case"cone":t=new n(.001,1,1,16);break;case"particle":t=new r(1,6,4);break;case"joint":t=(new Ii).geometry;break;default:return null}this.geo[e]=t}return this.geo[e]}dispose(){for(let e in this.geo)this.geo[e].isBufferGeometry?this.geo[e].dispose():console.log(this.geo[e]);this.geo={},this.geoN=0}};class Ci{constructor(e,t="rgb(69,69,69)",i="rgb(39,39,39)"){const s=document.createElement("canvas");s.width=s.height=128;const a=s.getContext("2d");if(a.fillStyle=t,a.fillRect(0,0,128,128),e){let s,r,n,o,l=[[0,0],[32,32],[64,64],[96,96],[96,-32]],h=[[0,64],[32,96],[64,128],[96,160],[-32,32]],c=e?"rgb(128,128,255)":t,A=e?"rgb(160,100,255)":i,u=e?"rgba(100,160,255, 0.5)":"rgba(0,0,0, 0.1)";for(a.strokeStyle=u,a.lineWidth=1,s=0;s<5;s++){o=a.createLinearGradient(0,h[s][0],0,h[s][1]),o.addColorStop(0,A),o.addColorStop(1,c),a.beginPath(),a.fillStyle=o,a.rect(l[s][0],l[s][1],32,64),a.fill();for(let e=0;e<8;e++)n=2*(Math.random()-.5),a.beginPath(),a.moveTo(l[s][0]+n+2+4*e,l[s][1]),a.lineTo(l[s][0]+n+2+4*e,l[s][1]+64),a.stroke()}for(l=[[32,0],[64,32],[96,64],[-32,64],[0,96]],h=[[32,96],[64,128],[96,160],[-32,32],[0,64]],s=0;s<5;s++)for(o=a.createLinearGradient(h[s][0],0,h[s][1],0),o.addColorStop(0,c),o.addColorStop(1,A),a.beginPath(),a.fillStyle=o,a.rect(l[s][0],l[s][1],64,32),a.fill(),r=0;r<8;r++)n=2*(Math.random()-.5),a.beginPath(),a.moveTo(l[s][0],l[s][1]+n+2+4*r),a.lineTo(l[s][0]+64,l[s][1]+n+2+4*r),a.stroke()}else a.beginPath(),a.fillStyle=i,a.rect(0,0,32,64),a.rect(32,32,32,64),a.rect(64,64,32,64),a.rect(96,96,32,64),a.rect(96,-32,32,64),a.fill();const r=new c(s);return r.wrapS=r.wrapT=A,r.repeat.x=r.repeat.y=60,e||(r.colorSpace=u),r}}class vi extends d{constructor(e){super(),this.defines={STANDARD:"",PHYSICAL:"",SUBSURFACE:"",USE_UV:""},this.extra={},this.addParametre("sssMap",null),this.addParametre("sssColor",new p(0,0,0)),this.addParametre("sssAmbient",.5),this.addParametre("sssDistortion",.6),this.addParametre("sssAttenuation",.1),this.addParametre("sssPower",1),this.addParametre("sssScale",6),this.setValues(e);let t=this;t.onBeforeCompile=function(e){for(let i in t.extra)e.uniforms[i]={value:t.extra[i]};e.fragmentShader=e.fragmentShader.replace("#include <common>",Bi.common),e.fragmentShader=e.fragmentShader.replace("#include <lights_fragment_begin>",t.replaceAll(xi,"RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );",Bi.light)),t.userData.shader=e}}addParametre(e,t){this.extra[e]=t,Object.defineProperty(this,e,{get:()=>this.extra[e],set:t=>{this.extra[e]=t,this.userData.shader&&(this.userData.shader.uniforms[e].value=this.extra[e])}})}replaceAll(e,t,i){return e.split(t).join(i)}}const Bi={common:"\n\t#include <common>\n\tuniform sampler2D sssMap;\n\tuniform float sssPower;\n\tuniform float sssScale;\n\tuniform float sssDistortion;\n\tuniform float sssAmbient;\n\tuniform float sssAttenuation;\n\tuniform vec3 sssColor;\n\n\tvoid RE_Direct_Scattering(const in IncidentLight directLight, const in vec2 uv, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, inout ReflectedLight reflectedLight) {\n\t\tvec3 thickness = sssColor * texture2D(sssMap, uv).r;\n\t\tvec3 scatteringHalf = normalize(directLight.direction + (geometryNormal * sssDistortion));\n\t\tfloat scatteringDot = pow(saturate(dot(geometryViewDir, -scatteringHalf)), sssPower) * sssScale;\n\t\tvec3 scatteringIllu = (scatteringDot + sssAmbient) * thickness;\n\t\treflectedLight.directDiffuse += scatteringIllu * sssAttenuation * directLight.color;\n\t}\n\t",light:"\n\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t#if defined( SUBSURFACE ) && defined( USE_UV )\n\t\tRE_Direct_Scattering(directLight, vUv, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, reflectedLight);\n\t#endif\n\t"},xi="\n\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n\nvec3 geometryClearcoatNormal = vec3( 0.0 );\n\n#ifdef USE_CLEARCOAT\n\n\tgeometryClearcoatNormal = clearcoatNormal;\n\n#endif\n\n#ifdef USE_IRIDESCENCE\n\n\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\n\n\tif ( material.iridescenceThickness == 0.0 ) {\n\n\t\tmaterial.iridescence = 0.0;\n\n\t} else {\n\n\t\tmaterial.iridescence = saturate( material.iridescence );\n\n\t}\n\n\tif ( material.iridescence > 0.0 ) {\n\n\t\tmaterial.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\n\t\t// Iridescence F0 approximation\n\t\tmaterial.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n\n\t}\n\n#endif\n\nIncidentLight directLight;\n\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\n\t\tpointLight = pointLights[ i ];\n\n\t\tgetPointLightInfo( pointLight, geometryPosition, directLight );\n\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\tSpotLight spotLight;\n\tvec4 spotColor;\n\tvec3 spotLightCoord;\n\tbool inSpotLightMap;\n\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\n\t\tspotLight = spotLights[ i ];\n\n\t\tgetSpotLightInfo( spotLight, geometryPosition, directLight );\n\n\t\t// spot lights are ordered [shadows with maps, shadows without maps, maps without shadows, none]\n\t\t#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n\t\t#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n\t\t#else\n\t\t#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#endif\n\n\t\t#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n\t\t\tspotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n\t\t\tinSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n\t\t\tspotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n\t\t\tdirectLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n\t\t#endif\n\n\t\t#undef SPOT_LIGHT_MAP_INDEX\n\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t\t#endif\n\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\n\t\tdirectionalLight = directionalLights[ i ];\n\n\t\tgetDirectionalLightInfo( directionalLight, directLight );\n\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\n\tRectAreaLight rectAreaLight;\n\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n\t}\n\t#pragma unroll_loop_end\n\n#endif\n\n#if defined( RE_IndirectDiffuse )\n\n\tvec3 iblIrradiance = vec3( 0.0 );\n\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\n\t#if defined( USE_LIGHT_PROBES )\n\n\t\tirradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n\n\t#endif\n\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n\n\t\t}\n\t\t#pragma unroll_loop_end\n\n\t#endif\n\n#endif\n\n#if defined( RE_IndirectSpecular )\n\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n\n#endif\n",ki={metalness:.1,roughness:.9},Qi={grey:new p(.18,.18,.18),black:new p(.039,.039,.039),body:new p(13289155),sleep:new p("hsl(33, 15%, 54%)"),solid:new p(7105128),base:new p(13224135),brick:new p(.262,.095,.061),sand:new p(.44,.386,.231),gold:new p(.944,.776,.373),gold2:new p(.998,.981,.751),titanium:new p(.633,.578,.503),titaniumSpec:new p(.728,.68,.55),chrome:new p(.653,.65,.615),chromeSpec:new p(.675,.72,.711),copper:new p(.988,.688,.448),carPaint:new p(.1037792,.59212029,.85064936),clay:new p("hsl(12, 30%, 40%)"),clayWhite:new p(11119017),concrete:new p(.51,.51,.51),Raw_Fire:new p("hsl(40, 18%, 54%)"),Raw_Buff:new p("hsl(33, 15%, 54%)"),Raw_Terracotta:new p("hsl(12, 30%, 40%)"),Raw_Porcelain:new p("hsl(45, 15%, 90%)")},Si={No:V,Normal:H,Additive:j,Subtractive:q,Multiply:O,Eadd:G,Esub:N,Erev:U,Emin:z,Emaw:_,Fzero:P,Fone:L,Fcolor:F,Fcolorm:T,Falpha:D,Falpham:R,Fdstalpha:M,Fdstalpham:S,Fdstcolor:Q,Fdstcolorm:k,Falphasaturate:x,Front:B,Back:v,Double:C};let Mi=class{constructor(){this.renderMode={value:0},this.depthPacking={value:0},this.extendMat=!1,this.isRealism=!1,this.realismOption={},this.envMapIntensity=1,this.mat={},this.TmpMat=[]}changeRenderMode(e){this.renderMode.value=e}initExtandShader(){}useRealLight(e){}setColor(e){}set(e,t,i=null){i||(i=e.onBeforeCompile),this.mat[e.name]=e}extendShader(e,t=null){}addToTmp(e){this.TmpMat.push(e)}create(e){let t,i=null;if(e.isMaterial)t=e;else{let s=void 0!==e.type?e.type:"Standard";switch(e.type&&delete e.type,i=e.beforeCompile||null,e.beforeCompile&&delete e.beforeCompile,(e.thickness||e.sheen||e.clearcoat||e.transmission||e.specularColor)&&(s="Physical"),e.normalScale&&(e.normalScale.isVector2||(e.normalScale=(new g).fromArray(e.normalScale))),e.side&&(e.side=this.findValue(e.side)),e.shadowSide&&(e.shadowSide=this.findValue(e.shadowSide)),e.blending&&(e.blending=this.findValue(e.blending)),e.blendEquation&&(e.blendEquation=this.findValue(e.blendEquation)),e.blendEquationAlpha&&(e.blendEquationAlpha=this.findValue(e.blendEquationAlpha)),e.blendSrc&&(e.blendSrc=this.findValue(e.blendSrc)),e.blendDst&&(e.blendDst=this.findValue(e.blendDst)),e.blendDstAlpha&&(e.blendDstAlpha=this.findValue(e.blendDstAlpha)),e.blendSrcAlpha&&(e.blendSrcAlpha=this.findValue(e.blendSrcAlpha)),e.clearcoatNormalScale&&(e.clearcoatNormalScale.isVector2||(e.clearcoatNormalScale=(new g).fromArray(e.clearcoatNormalScale))),s=s.toLowerCase(),s){case"physical":t=new d(e),t.defines={STANDARD:"",PHYSICAL:"",USE_UV:"",USE_SPECULAR:""};break;case"phong":t=new E(e);break;case"lambert":t=new I(e);break;case"basic":t=new w(e);break;case"line":t=new a(e);break;case"toon":t=new y(e);break;case"shadow":t=new b(e);break;case"sss":t=new vi(e);break;default:t=new f(e)}}return this.mat[t.name]?null:(this.set(t,!1,i),t)}findValue(e){return"string"===e?Si[e.charAt(0).toUpperCase()+e.slice(1)]:e}addToMat(e){if(this.isRealism)for(let t in e)e[t].onBeforeCompile=function(i){EnhanceLighting(i,this.realismOption),e[t].userData.isRealism=!0,e[t].userData.shader=i};this.mat={...this.mat,...e}}changeType(){}directIntensity(e){for(let e in this.mat);}getList(){let e={...this.mat};const t=["line","debug","hide","svg"];let i=t.length;for(;i--;)delete e[t[i]];return e}get(e){if(!this.mat[e])switch(e){case"grey":this.create({name:"grey",color:Qi.grey,metalness:0,roughness:.5});break;case"black":this.create({name:"black",color:Qi.black,metalness:0,roughness:.5});break;case"body":this.create({name:"body",color:Qi.body,...ki});break;case"sleep":this.create({name:"sleep",color:Qi.sleep,...ki});break;case"solid":this.create({name:"solid",color:Qi.solid,...ki});break;case"base":this.create({name:"base",color:Qi.base,...ki});break;case"clay":this.create({name:"clay",color:Qi.clay,metalness:.1,roughness:.7});break;case"clayWhite":this.create({name:"clayWhite",color:Qi.clayWhite,metalness:.1,roughness:.7});break;case"concrete":this.create({name:"concrete",color:Qi.concrete,metalness:0,roughness:.9});break;case"brick":this.create({name:"brick",color:Qi.brick,metalness:0,roughness:.6});break;case"sand":this.create({name:"sand",color:Qi.sand,metalness:0,roughness:.9});break;case"chrome":this.create({name:"chrome",color:Qi.chrome,specularColor:Qi.chromeSpec,metalness:1,roughness:.075});break;case"silver":this.create({name:"silver",color:11184810,metalness:.8,roughness:.22});break;case"gold":this.create({name:"gold",color:Qi.gold,specularColor:Qi.gold2,metalness:1,roughness:.02});break;case"copper":this.create({name:"copper",color:Qi.copper,metalness:1,roughness:.05});break;case"titanium":this.create({name:"titanium",color:Qi.titanium,metalness:1,roughness:0,specularColor:Qi.titaniumSpec});break;case"carPaint":this.create({name:"carPaint",color:Qi.carPaint,metalness:0,anisotropy:new g(.5,.5),roughness:.4,clearcoat:1,clearcoatRoughness:0});break;case"carbon":this.create({name:"carbon",map:new Ci,normalMap:new Ci(!0),clearcoat:1,clearcoatRoughness:.1,roughness:.5});break;case"cloth":this.create({name:"cloth",color:8391119,roughness:.5,sheenColor:13335807,sheen:1,sheenRoughness:.2});break;case"skinny":this.create({name:"skinny",color:14724201,...ki});break;case"glass":this.create({name:"glass",color:16777215,transparent:!0,roughness:.02,metalness:0,side:C,alphaToCoverage:!0,premultipliedAlpha:!0,transmission:1,clearcoat:1,thickness:.01});break;case"glassX":this.create({name:"glassX",color:16777215,alphaToCoverage:!0,transparent:!0,opacity:1,roughness:0,metalness:0,side:C,transmission:1,clearcoat:1,clearcoatRoughness:0,thickness:.05,ior:1.52,shadowSide:1,reflectivity:.5,iridescence:0,specularIntensity:1,specularColor:16777215});break;case"plexi":this.create({name:"plexi",blending:j,color:65793,transparent:!0,opacity:.7,reflectivity:.3,metalness:.6,roughness:.1,clearcoat:.2,clearcoatRoughness:.02,side:C,alphaToCoverage:!0,premultipliedAlpha:!0});break;case"plexi2":this.create({name:"plexi2",blending:j,color:65793,transparent:!1,opacity:.7,reflectivity:.3,metalness:.6,roughness:.1,clearcoat:.2,clearcoatRoughness:.02,side:C,alphaToCoverage:!1,premultipliedAlpha:!0});break;case"glass2":this.create({name:"glass2",color:15658734,transparent:!0,roughness:0,alphaToCoverage:!0,opacity:.3});break;case"glass3":this.create({name:"glass3",color:0,transparent:!0,roughness:0,alphaToCoverage:!0,opacity:.4});break;case"glass_red":this.create({name:"glass_red",color:16711680,transparent:!0,roughness:0,alphaToCoverage:!0,opacity:.8});break;case"car":this.create({name:"car",color:3158064,metalness:1,roughness:.5,clearcoat:1,clearcoatRoughness:.03,sheen:.5});break;case"carGlass":this.create({name:"carGlass",color:16777215,metalness:0,roughness:0,transmission:1,ior:1.52});break;case"outline":this.create({name:"outline",color:16777215,type:"Basic",side:v,toneMapped:!1,wireframe:!0,transparent:!0,opacity:.25});break;case"debug":this.create({name:"debug",type:"Basic",color:15953986,wireframe:!0,toneMapped:!1,transparent:!0,opacity:.5});break;case"shadow":this.create({name:"shadow",type:"shadow",color:0,opacity:.5});break;case"bones":this.create({name:"bones",color:16639958,wireframe:!0});break;case"bones2":this.create({name:"bones2",type:"basic",color:14664872,transparent:!0,opacity:.5,depthTest:!0,depthWrite:!1,alphaToCoverage:!0});break;case"button":this.create({name:"button",color:16728139,...ki});break;case"line":this.create({name:"line",type:"line",vertexColors:!0,toneMapped:!1});break;case"liner":this.create({name:"liner",type:"line",vertexColors:!0,toneMapped:!1,depthTest:!0,depthWrite:!0,alphaToCoverage:!0});break;case"hide":this.create({name:"hide",type:"basic",visible:!1});break;case"particle":this.create({name:"particle",type:"basic",toneMapped:!1,color:16776960,transparent:!0,opacity:.2});break;case"svg":this.create({name:"svg",type:"basic",toneMapped:!1,vertexColors:!0,transparent:!1,side:C})}return this.mat[e]}dispose(){this.isRealism=!1;for(let e in this.mat)this.mat[e].dispose(),delete this.mat[e];let e=this.TmpMat.length;for(;e--;)this.TmpMat[e].dispose();this.TmpMat=[]}upShader(){let e=this.realismOption;for(let t in this.mat){const i=this.mat[t],s=i.userData.shader;for(let t in e)s&&void 0!==s.uniforms[t]&&(s.uniforms[t].value=e[t]),i[t]&&(i[t]=e[t])}}};class Ri{constructor(e=-1){this.perf=window.performance,this.time={now:0,delta:0,then:0,interval:0,tmp:0,n:0,dt:0},this.fps=0,this.delta=0,this.elapsedTime=0,this.unlimited=!1,this.setFramerate(e),this.force=!1}up(e){let t=this.time;return this.unlimited&&(this.force=!0),t.now=void 0!==e?e:this.now(),t.delta=t.now-t.then,this.force&&(t.delta=t.interval,this.force=!1),!!(t.delta>=t.interval||this.unlimited)&&(t.then=this.unlimited?t.now:t.now-t.delta%t.interval,this.delta=.001*t.interval,this.elapsedTime+=this.delta,!0)}setFramerate(e){this.elapsedTime=0,this.framerate=e,this.unlimited=this.framerate<0,this.time.interval=1e3/e,60===e&&(this.time.interval=16.67)}static now(){return this.perf?this.perf.now():Date.now()}static format_time(e){return e>1e3?e/1e3+" sec":e+" ms"}}class Di{constructor(){this.key=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],this.key2=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],this.gamepad=new Ti(this.key),this.useGamepad=!1,this.sameAxis=!0,document.addEventListener("keydown",function(e){this.keyDown(e)}.bind(this),!1),document.addEventListener("keyup",function(e){this.keyUp(e)}.bind(this),!1)}setKey(e,t){this.key[e]=t}update(){return this.gamepad.update(),this.gamepad.ready&&(this.useGamepad||(this.useGamepad=!0),this.gamepad.getValue(0)),this.sameAxis&&(this.key[2]=this.key[0],this.key[3]=this.key[1]),this.key}keyDown(e){var t=this.key,i=this.key2;if(e=e||window.event,this.sameAxis)switch(e.which){case 65:case 81:case 37:t[0]=-1,i[0]=1;break;case 68:case 39:t[0]=1,i[1]=1;break;case 87:case 90:case 38:t[1]=-1;break;case 83:case 40:t[1]=1;break;case 32:t[4]=1;break;case 17:case 67:t[5]=1;break;case 69:t[6]=1;break;case 16:t[7]=1}else switch(e.which){case 65:case 81:t[0]=-1,i[0]=1;break;case 68:t[0]=1,i[1]=1;break;case 87:case 90:t[1]=-1;break;case 83:t[1]=1;break;case 37:t[2]=-1,i[0]=1;break;case 39:t[2]=1,i[1]=1;break;case 38:t[3]=-1;break;case 40:t[3]=1;break;case 32:t[4]=1;break;case 17:case 67:t[5]=1;break;case 69:t[6]=1;break;case 16:t[7]=1}this.gamepad.reset()}keyUp(e){var t=this.key,i=this.key2;if(e=e||window.event,this.sameAxis)switch(e.which){case 65:case 81:case 37:t[0]=t[0]<0?0:t[0],i[0]=0;break;case 68:case 39:t[0]=t[0]>0?0:t[0],i[1]=0;break;case 87:case 90:case 38:t[1]=t[1]<0?0:t[1];break;case 83:case 40:t[1]=t[1]>0?0:t[1];break;case 32:t[4]=0;break;case 17:case 67:t[5]=0;break;case 69:t[6]=0;break;case 16:t[7]=0}else switch(e.which){case 65:case 81:t[0]=t[0]<0?0:t[0],i[0]=0;break;case 68:t[0]=t[0]>0?0:t[0],i[1]=0;break;case 87:case 90:t[1]=t[1]<0?0:t[1];break;case 83:t[1]=t[1]>0?0:t[1];break;case 37:t[2]=t[2]<0?0:t[2],i[0]=0;break;case 39:t[2]=t[2]>0?0:t[2],i[1]=0;break;case 38:t[3]=t[3]<0?0:t[3];break;case 40:t[3]=t[3]>0?0:t[3];break;case 32:t[4]=0;break;case 17:case 67:t[5]=0;break;case 69:t[6]=0;break;case 16:t[7]=0}}}class Ti{constructor(e){this.values=[],this.ready=0,this.key=e}update(){var e,t,i,s,a,r,n=this.fix,o=navigator.getGamepads();for(e=0;e<o.length;e++)if(r=o[e])if(i=r.axes.length,s=r.buttons.length){for(this.values[e]||(this.values[e]=[]),t=0;t<i;t++)a=n(r.axes[t],.08),0==this.ready&&0!==a&&(this.ready=1),this.values[e][t]=a;for(t=0;t<s;t++)a=n(r.buttons[t].value),0==this.ready&&0!==a&&(this.ready=1),this.values[e][i+t]=a}else this.values[e]&&(this.values[e]=null)}getValue(e){for(var t,i=19;i--;)t=this.values[e][i],0==this.ready&&0!==t&&(this.ready=1),this.key[i]=t}reset(){this.ready=0}fix(e,t){let i=Number(e.toString().substring(0,5));return t&&i<t&&i>-t&&(i=0),i}}class Fi{constructor(){this.id=0,this.list=[],this.type="item",this.Utils=null}reset(){let e=this.list.length;for(;e--;)this.dispose(this.list[e]);this.list=[],this.id=0}byName(e){return this.Utils.byName(e)}setName(e={}){let t=void 0!==e.name?e.name:this.type+this.id++;return e.id=this.remove(t,!0),e.name=t,t}addToWorld(e,t=-1){this.Utils.add(e),-1!==t?this.list[t]=e:this.list.push(e)}remove(e,t){let i=this.byName(e);return i?this.clear(i,t):-1}clear(e,t){let i=this.list.indexOf(e);return-1===i||t?this.list[i]=null:this.list.splice(i,1),this.dispose(e),i}dispose(e){null!==e&&this.Utils.remove(e)}add(e={}){}set(e={}){}step(e,t){}}class Li extends Fi{constructor(e){super(),this.motor=e,this.Utils=this.motor.utils,this.type="ray",this.iType="ray"}step(e,t){let i,s,a=this.list.length;for(;a--;)i=this.list[a],s=t+a*yi.ray,i.update(e,s,this.motor.reflow.ray[a]||null)}add(e={}){this.setName(e);let t=new Pi(e,this.motor);return t.visible=void 0===e.visible||e.visible,this.addToWorld(t,e.id),e.parent&&"string"!=typeof e.parent&&(e.parent=e.parent.name),e.callback&&delete e.callback,this.motor.post({m:"add",o:e}),t}set(e={},t=null){null===t&&(t=this.byName(e.name)),null!==t&&t.setRay(e)}}class Pi extends K{constructor(e={},i){super(new t,i.getMat("line")),this.motor=i,this.Utils=this.motor.utils,this.isRay=!0,this.data={hit:!1,body:"",point:[0,0,0],normal:[0,0,0],distance:0,angle:0,parent:null},this.type="ray",this.name=e.name,this.parentMesh=null,e.parent&&(this.parentMesh="string"==typeof e.parent?this.Utils.byName(e.parent):e.parent,this.data.parent=this.parentMesh),this.callback=e.callback||null,this.c0=[.1,.1,.3],this.c1=[.1,.4,.6],this.c2=[1,.1,.1],this.c3=[.1,1,.1],this.begin=new W,this.end=new W(0,1,0),this.tmp=new W,this.vnormal=new W,this.vv1=new W,this.vv2=new W,this.fullDistance=0,this.setRay(e);this.geometry.setAttribute("position",new s([0,0,0,0,0,0,0,0,0],3)),this.geometry.setAttribute("color",new s([0,0,0,0,0,0,0,0,0],3)),this.vertices=this.geometry.attributes.position,this.colors=this.geometry.attributes.color,this.local=[0,0,0,0,0,0,0,0,0],this.noRotation=e.noRotation||!1,this.fakeMatrix=new J,this.matrixAutoUpdate=!1,this.frustumCulled=!1}setRay(e){e.begin&&this.begin.fromArray(e.begin),e.end&&this.end.fromArray(e.end),this.fullDistance=this.begin.distanceTo(this.end)}update(e,t=0,i=null){if(this.data.hit=0!==e[t],this.data.body=i||"",this.data.distance=e[t+1],this.data.hit)this.local[0]=e[t+2],this.local[1]=e[t+3],this.local[2]=e[t+4],this.tmp.fromArray(e,t+5),this.vnormal.fromArray(e,t+8),this.data.point=this.tmp.toArray(),this.data.normal=this.vnormal.toArray(),this.tmp.toArray(this.local,3),this.vv1.fromArray(this.local).sub(this.tmp).normalize(),this.tmp.addScaledVector(this.vnormal,this.fullDistance-this.data.distance),this.tmp.toArray(this.local,6),this.data.angle=Math.floor(ci.angleTo(this.vv1.toArray(),this.data.normal)*ni);else if(this.parentMesh){let e;e=this.noRotation?this.fakeMatrix.setPosition(this.parentMesh.position.x,this.parentMesh.position.y,this.parentMesh.position.z):this.parentMesh.matrixWorld,this.tmp.copy(this.begin).applyMatrix4(e).toArray(this.local,0),this.tmp.copy(this.end).applyMatrix4(e),this.tmp.toArray(this.local,3),this.tmp.toArray(this.local,6)}else this.begin.toArray(this.local,0),this.end.toArray(this.local,3),this.end.toArray(this.local,6);this.updateGeometry(),this.updateMatrix(),this.callback&&this.callback(this.data)}dispose(){this.callback=null,this.parentMesh=null,this.data={},this.geometry.dispose()}raycast(){}updateGeometry(){if(!this.visible)return;let e=this.vertices.array,t=this.colors.array,i=this.local,s=this.data.hit,a=s?this.c2:this.c1,r=s?this.c3:this.c1;t[3]=a[0],t[4]=a[1],t[5]=a[2],t[6]=r[0],t[7]=r[1],t[8]=r[2],e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this.vertices.needsUpdate=!0,this.colors.needsUpdate=!0}}class _i extends X{constructor(e,t,i=0){super(e,t,i),this.matrixAutoUpdate=!1,this.tmpMatrix=new J,this.tmpQuat=new Y,this.instanceUv=null,this.instanceColor=null,this.needSphereUp=!1,this.isRay=!0,this.overMaterial=null,this.currentOver=-1,this.isOver=!1,this.outline=null,this.tmpElement=[]}clearOutLine(){this.overMaterial&&this.outline&&(this.parent.remove(this.outline),this.outline=null,this.currentOver=-1)}addOutLine(e){this.overMaterial&&(this.outline||(this.outline=new Z(this.geometry,this.overMaterial)),this.outline.matrixAutoUpdate=!1,this.tmpMatrix.fromArray(this.instanceMatrix.array,16*e.idx),this.outline.matrix.copy(this.tmpMatrix),this.outline.matrixWorldNeedsUpdate=!0,this.parent.add(this.outline),this.currentOver=e.idx)}over(e){e&&!this.instance.isOver&&(this.instance.isOver=!0,this.instance.addOutLine(this)),!e&&this.instance.isOver&&(this.instance.isOver=!1,this.instance.clearOutLine())}setColorAt(e,t){null===this.instanceColor&&(this.instanceColor=new $(new Float32Array(3*this.instanceMatrix.count),3)),t.isColor&&(t=t.toArray());let i=3*e;this.instanceColor.array[i]=t[0],this.instanceColor.array[i+1]=t[1],this.instanceColor.array[i+2]=t[2]}add(e,t=[0,0,0],i=[0,0,0,1],s=[1,1,1],a=null,r=null){3===i.length&&(i=this.tmpQuat.setFromEuler({_x:i[0],_y:i[1],_z:i[2],_order:"XYZ"},!1).toArray()),a&&(a.isColor&&(a=a.toArray()),null===this.instanceColor&&(this.instanceColor=new $(new Float32Array(3*this.instanceMatrix.count),3))),this.expand(t,i,s,a,r),this.tmpElement.push(e)}slice(e,t,i){let s=new Float32Array(i-t);for(let a=0;a<t+i;++a)s[a]=e[t+a];return s}remove(e){if(!this.count)return;this.tmpElement.splice(e,1);let t=[...this.instanceMatrix.array];t.splice(16*e,16),this.instanceMatrix=new $(new Float32Array(t),16),null!==this.instanceColor&&(t=[...this.instanceColor.array],t.splice(3*e,3),this.instanceColor=new $(new Float32Array(t),3)),null!==this.instanceUv&&(t=[...this.instanceUv.array],t.splice(2*e,2),this.instanceUv=new $(new Float32Array(t),2)),this.count--,this.reDistribute()}reDistribute(){let e=this.count;for(;e--;)this.tmpElement[e].idx=e}getIDName(e){return this.tmpElement[e].name}getBodyList(){let e=[],t=this.count;for(;t--;)e.push(this.tmpElement[t].name);return e}expand(e,t,i,s=[1,1,1],a){let r=null!==this.instanceMatrix?this.instanceMatrix.array:[];this.tmpMatrix.compose({x:e[0],y:e[1],z:e[2]},{_x:t[0],_y:t[1],_z:t[2],_w:t[3]},{x:i[0],y:i[1],z:i[2]}),this.instanceMatrix=new $(new Float32Array([...r,...this.tmpMatrix.toArray()]),16),null!==this.instanceColor&&(r=this.instanceColor.array,this.instanceColor=new $(new Float32Array([...r,...s]),3)),this.count++}setTransformAt(e,t,i,s){this.tmpMatrix.compose({x:t[0],y:t[1],z:t[2]},{_x:i[0],_y:i[1],_z:i[2],_w:i[3]},{x:s[0],y:s[1],z:s[2]}),this.tmpMatrix.toArray(this.instanceMatrix.array,16*e),this.needSphereUp=!0,this.outline&&this.currentOver===e&&(this.outline.matrix.copy(this.tmpMatrix),this.outline.matrixWorldNeedsUpdate=!0)}dispose(){this.clearOutLine(),this.parent.remove(this),this.geometry.dispose(),this.instanceColor=null,this.count=0,this.tmpElement=[],this.dispatchEvent({type:"dispose"})}setRaycast(e){void 0!==e&&(this.isRay=e)}raycast(e,t){this.isRay&&(this.instanceMatrix.needsUpdate=!0,super.raycast(e,t))}update(){this.instanceMatrix&&(this.instanceMatrix.needsUpdate=!0),this.instanceColor&&(this.instanceColor.needsUpdate=!0),this.needSphereUp&&this.computeBoundingSphere(),this.needSphereUp=!1,this.updateMatrix()}}class zi{constructor(e=0,t=0,i=0,s=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=i,this._w=s}set(e,t,i,s){return this._x=e,this._y=t,this._z=i,this._w=s,this}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}}function Ui(e,i=!1){const s=null!==e[0].index,a=new Set(Object.keys(e[0].attributes)),r=new Set(Object.keys(e[0].morphAttributes)),n={},o={},l=e[0].morphTargetsRelative,h=new t;let c=0;for(let t=0;t<e.length;++t){const A=e[t];let u=0;if(s!==(null!==A.index))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+t+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const e in A.attributes){if(!a.has(e))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+t+'. All geometries must have compatible attributes; make sure "'+e+'" attribute exists among all geometries, or in none of them.'),null;void 0===n[e]&&(n[e]=[]),n[e].push(A.attributes[e]),u++}if(u!==a.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+t+". Make sure all geometries have the same number of attributes."),null;if(l!==A.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+t+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const e in A.morphAttributes){if(!r.has(e))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+t+". .morphAttributes must be consistent throughout all geometries."),null;void 0===o[e]&&(o[e]=[]),o[e].push(A.morphAttributes[e])}if(i){let e;if(s)e=A.index.count;else{if(void 0===A.attributes.position)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+t+". The geometry must have either an index or a position attribute"),null;e=A.attributes.position.count}h.addGroup(c,e,t),c+=e}}if(s){let t=0;const i=[];for(let s=0;s<e.length;++s){const a=e[s].index;for(let e=0;e<a.count;++e)i.push(a.getX(e)+t);t+=e[s].attributes.position.count}h.setIndex(i)}for(const e in n){const t=Ni(n[e]);if(!t)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+e+" attribute."),null;h.setAttribute(e,t)}for(const e in o){const t=o[e][0].length;if(0===t)break;h.morphAttributes=h.morphAttributes||{},h.morphAttributes[e]=[];for(let i=0;i<t;++i){const t=[];for(let s=0;s<o[e].length;++s)t.push(o[e][s][i]);const s=Ni(t);if(!s)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+e+" morphAttribute."),null;h.morphAttributes[e].push(s)}}return h}function Ni(e){let t,s,a,r=-1,n=0;for(let i=0;i<e.length;++i){const o=e[i];if(void 0===t&&(t=o.array.constructor),t!==o.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(void 0===s&&(s=o.itemSize),s!==o.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(void 0===a&&(a=o.normalized),a!==o.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(-1===r&&(r=o.gpuType),r!==o.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;n+=o.count*s}const o=new t(n),l=new i(o,s,a);let h=0;for(let t=0;t<e.length;++t){const i=e[t];if(i.isInterleavedBufferAttribute){const e=h/s;for(let t=0,a=i.count;t<a;t++)for(let a=0;a<s;a++){const s=i.getComponent(t,a);l.setComponent(t+e,a,s)}}else o.set(i.array,h);h+=i.count*s}return void 0!==r&&(l.gpuType=r),l}fu