UNPKG

phy-engine

Version:

JavaScript 3D Physics for three.js

6 lines 598 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 A,RepeatWrapping as c,SRGBColorSpace as d,MeshPhysicalMaterial as u,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 M,DstAlphaFactor as S,OneMinusSrcAlphaFactor as R,SrcAlphaFactor as D,OneMinusSrcColorFactor as T,SrcColorFactor as F,OneFactor as L,ZeroFactor as P,MaxEquation as _,MinEquation as N,ReverseSubtractEquation as z,SubtractEquation as G,AddEquation as U,MultiplyBlending as O,SubtractiveBlending as q,AdditiveBlending as j,NormalBlending as H,NoBlending as V,Line as K,Vector3 as J,Matrix4 as W,InstancedMesh as Y,Quaternion as X,Mesh as Z,InstancedBufferAttribute as $,CircleGeometry as ee,Box3 as te,Object3D as ie,Line3 as se,Plane as ae,Triangle as re,TrianglesDrawMode as ne,TriangleFanDrawMode as oe,TriangleStripDrawMode as le,Loader as he,FileLoader as Ae,Matrix3 as ce,Box2 as de,ShapeUtils as ue,Shape as pe,Path as ge,ShapePath as me,ShapeGeometry as fe,Euler 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 Me,LinearMipmapNearestFilter as Se,NearestMipmapNearestFilter as Re,LinearFilter as De,NearestFilter as Te,MirroredRepeatWrapping as Fe,ClampToEdgeWrapping as Le,PointsMaterial as Pe,Material as _e,PropertyBinding as Ne,SkinnedMesh as ze,LineLoop as Ge,Points as Ue,Group as Oe,PerspectiveCamera as qe,MathUtils as je,OrthographicCamera as He,Skeleton as Ve,AnimationClip as Ke,Bone as Je,InterpolateDiscrete as We,InterpolateLinear as Ye,Texture as Xe,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 At,FloatType as ct,DataUtils as dt,RGBAFormat as ut,RGFormat as pt,RedFormat 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 Mt,CompressedCubeTexture as St,CompressedArrayTexture as Rt,CompressedTexture as Dt,NoColorSpace as Tt,RGBA_PVRTC_2BPPV1_Format as Ft,RED_GREEN_RGTC2_Format as Lt,SIGNED_RED_GREEN_RGTC2_Format as Pt,RED_RGTC1_Format as _t,SIGNED_RED_RGTC1_Format as Nt,RGBA_S3TC_DXT3_Format as zt,RGB_S3TC_DXT1_Format as Gt,RGBA_ASTC_6x6_Format as Ut,RGBFormat as Ot,UnsignedInt101111Type as qt,UnsignedInt5999Type as jt,Data3DTexture as Ht,LoadingManager as Vt,AnimationMixer as Kt,ObjectSpaceNormalMap as Jt,CustomBlending as Wt,SkeletonHelper as Yt,AnimationUtils as Xt,AdditiveAnimationBlendMode as Zt,NormalAnimationBlendMode as $t,Raycaster as ei,PMREMGenerator as ti,Scene as ii,WebGLCubeRenderTarget as si,CubeCamera as ai,IcosahedronGeometry as ri,ShaderMaterial as ni,NoToneMapping as oi,AxesHelper as li,InstancedBufferGeometry as hi,InstancedInterleavedBuffer as Ai,DynamicDrawUsage as ci}from"three";const di=Math.PI,ui=di/180,pi=180/di,gi=Number.EPSILON,mi=.5*di,fi={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:pi,torad:ui,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=fi.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)=>fi.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?pi: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=fi.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=fi.composeMatrixArray(e,t),n=fi.composeMatrixArray(i,s);return a&&(r=fi.invertMatrixArray(r)),r=fi.multiplyMatrixArray(r,n),[r[12],r[13],r[14]]},fromTransformToQ:(e,t,i=!1)=>{let s=fi.composeMatrixArray(e,t),a=fi.decomposeFullMatrixArray(s).q;return i&&(a=fi.quatInvert(a)),a},lerpTransform:(e,t,i)=>{let s=e[0],a=e[1],r=t[0],n=t[1];return r=fi.lerpArray(s,r,i),n=fi.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,A=s*o,c=s*l,d=s*h,u=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-(u+g))*y,(c+b)*y,(d-f)*y,0,(c-b)*w,(1-(A+g))*w,(p+m)*w,0,(d+f)*I,(p-m)*I,(1-(A+u))*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],A=i[5],c=i[9],d=i[13],u=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],M=s[2],S=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*M+l*T,a[4]=r*E+n*x+o*S+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+A*B+c*M+d*T,a[5]=h*E+A*x+c*S+d*F,a[9]=h*C+A*k+c*R+d*L,a[13]=h*v+A*Q+c*D+d*P,a[2]=u*I+p*B+g*M+m*T,a[6]=u*E+p*x+g*S+m*F,a[10]=u*C+p*k+g*R+m*L,a[14]=u*v+p*Q+g*D+m*P,a[3]=f*I+b*B+y*M+w*T,a[7]=f*E+b*x+y*S+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],A=t[8],c=t[9],d=t[10],u=t[11],p=t[12],g=t[13],m=t[14],f=t[15],b=c*m*h-g*d*h+g*l*u-o*m*u-c*l*f+o*d*f,y=p*d*h-A*m*h-p*l*u+n*m*u+A*l*f-n*d*f,w=A*g*h-p*c*h+p*o*u-n*g*u-A*o*f+n*c*f,I=p*c*l-A*g*l-p*o*d+n*g*d+A*o*m-n*c*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*d*r-c*m*r-g*a*u+s*m*u+c*a*f-s*d*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]=(c*l*r-o*d*r-c*a*h+s*d*h+o*a*u-s*l*u)*C,t[4]=y*C,t[5]=(A*m*r-p*d*r+p*a*u-i*m*u-A*a*f+i*d*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*d*r-A*l*r+A*a*h-i*d*h-n*a*u+i*l*u)*C,t[8]=w*C,t[9]=(p*c*r-A*g*r-p*s*u+i*g*u+A*s*f-i*c*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]=(A*o*r-n*c*r-A*s*h+i*c*h+n*s*u-i*o*u)*C,t[12]=I*C,t[13]=(A*g*a-p*c*a+p*s*d-i*g*d-A*s*m+i*c*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*c*a-A*o*a+A*s*l-i*c*l-n*s*d+i*o*d)*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],A=t[2],c=t[6],d=t[10],u=t[14];return t[3]*(+r*l*c-a*h*c-r*o*d+s*h*d+a*o*u-s*l*u)+t[7]*(+i*l*u-i*h*d+r*n*d-a*n*u+a*h*A-r*l*A)+t[11]*(+i*h*c-i*o*u-r*n*c+s*n*u+r*o*A-s*h*A)+t[15]*(-a*o*A-i*l*c+i*o*d+a*n*c-s*n*d+s*l*A)},decomposeMatrixArray:e=>[e[12],e[13],e[14]],decomposeFullMatrixArray:e=>{const t=e;let i=fi.lengthArray([t[0],t[1],t[2]]);const s=fi.lengthArray([t[4],t[5],t[6]]),a=fi.lengthArray([t[8],t[9],t[10]]);fi.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=fi.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=fi.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],A=t[2],c=t[3];let d=o*c+a*l+r*h+n*A;if(d<0?(s=[-l,-h,-A,-c],d=-d):s=[...t],d>=1)return e;const u=1-d*d;if(u<=gi){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],fi.quatNomalize(s)}const p=Math.sqrt(u),g=Math.atan2(p,d),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=fi.quatFromEuler(e),s=fi.quatInvert(t.quaternion.toArray());return fi.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],A=i[6],c=i[10],d=s+o+c;if(d>0){const e=.5/Math.sqrt(d+1);t[3]=.25/e,t[0]=(A-l)*e,t[1]=(r-h)*e,t[2]=(n-a)*e}else if(s>o&&s>c){const e=2*Math.sqrt(1+s-o-c);t[3]=(A-l)/e,t[0]=.25*e,t[1]=(a+n)/e,t[2]=(r+h)/e}else if(o>c){const e=2*Math.sqrt(1+o-s-c);t[3]=(r-h)/e,t[0]=(a+n)/e,t[1]=.25*e,t[2]=(l+A)/e}else{const e=2*Math.sqrt(1+c-s-o);t[3]=(n-a)/e,t[0]=(r+h)/e,t[1]=(l+A)/e,t[2]=.25*e}return t},quatFromEuler:(e=[0,0,0],t=!0)=>{const i=Math.cos,s=Math.sin,a=t?ui:1,r=e[0]*a*.5,n=e[1]*a*.5,o=e[2]*a*.5,l=i(r),h=i(n),A=i(o),c=s(r),d=s(n),u=s(o);return[c*h*A+l*d*u,l*d*A-c*h*u,l*h*u+c*d*A,l*h*A-c*d*u]},quatFromAxis:(e=[0,0,0],t,i=!0)=>{const s=.5*t*(i?ui:1),a=Math.sin(s);return[e[0]*a,e[1]*a,e[2]*a,Math.cos(s)]},quatNomalize:e=>{let t=fi.lengthArray(e);return 0===t?[0,0,0,1]:(t=1/t,fi.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(fi.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(fi.clamp(fi.dotArray(e,t),-1,1))),fixedArray:(e,t)=>{let i=e.length,s=[];for(;i--;)s[i]=fi.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>mi?i-=mi:i+=mi;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),A=2*(o*i-r*a),c=2*(r*s-n*i);return[i+l*h+n*c-o*A,s+l*A+o*h-r*c,a+l*c+r*A-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)=>fi.mulArray(e,1/t,i),scaleArray:(e,t,i)=>fi.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])=>fi.lengthArray(fi.subArray(e,t)),normalizeArray:e=>fi.divArray(e,fi.lengthArray(e)||1),normalArray:(e,t=[0,0,0])=>fi.normalizeArray(fi.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=fi.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;fi.getHash(e);let l,h,A=!1,c=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},A=!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&&(A=!0,r[e]=h.id);A||(l.id=c++,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,A=h;for(;A--;)for(s=e[A],i=h;i--;)i!==A&&(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),A=o*h;let c;for(let e=0;e<r;e++){c=3*e;let t=`${~~(n[c]*h+A)},${~~(n[c+1]*h+A)},${~~(n[c+2]*h+A)}`;i[t]?i[t].push(e):i[t]=[e]}let d=0;for(let e in i)s[d++]=i[e];return s}},bi=fi,yi=["PHYSX","HAVOK"],wi=4e3,Ii=1e3,Ei=4e3,Ci=100,vi=100,Bi=50,xi=20,ki={bodyFull:14,body:8,joint:16,contact:1,ray:11,character:16,vehicle:72,solver:128},Qi=function(e,t=!1){const i={};let s={body:wi*(t?ki.bodyFull:ki.body),joint:Ii*ki.joint,ray:Ci*ki.ray,contact:Ei*ki.contact,character:vi*ki.character};"PHYSX"!==e&&"AMMO"!==e||(s.vehicle=Bi*ki.vehicle),"PHYSX"===e&&(s.solver=xi*ki.solver),"HAVOK"!==e&&"RAPIER"!==e&&"JOLT"!==e||(ki.joint=0);let a=0;for(let e in s)i[e]=a,a+=s[e];return i.total=a,i};class Mi 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 Si=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 Mi).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 Ri{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]],A=e?"rgb(128,128,255)":t,c=e?"rgb(160,100,255)":i,d=e?"rgba(100,160,255, 0.5)":"rgba(0,0,0, 0.1)";for(a.strokeStyle=d,a.lineWidth=1,s=0;s<5;s++){o=a.createLinearGradient(0,h[s][0],0,h[s][1]),o.addColorStop(0,c),o.addColorStop(1,A),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,A),o.addColorStop(1,c),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 A(s);return r.wrapS=r.wrapT=c,r.repeat.x=r.repeat.y=60,e||(r.colorSpace=d),r}}class Di extends u{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>",Ti.common),e.fragmentShader=e.fragmentShader.replace("#include <lights_fragment_begin>",t.replaceAll(Fi,"RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );",Ti.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 Ti={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"},Fi="\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",Li={metalness:.1,roughness:.9},Pi={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%)")},_i={No:V,Normal:H,Additive:j,Subtractive:q,Multiply:O,Eadd:U,Esub:G,Erev:z,Emin:N,Emaw:_,Fzero:P,Fone:L,Fcolor:F,Fcolorm:T,Falpha:D,Falpham:R,Fdstalpha:S,Fdstalpham:M,Fdstcolor:Q,Fdstcolorm:k,Falphasaturate:x,Front:B,Back:v,Double:C};let Ni=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 u(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 Di(e);break;default:t=new f(e)}}return this.mat[t.name]?null:(this.set(t,!1,i),t)}findValue(e){return"string"===e?_i[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:Pi.grey,metalness:0,roughness:.5});break;case"black":this.create({name:"black",color:Pi.black,metalness:0,roughness:.5});break;case"body":this.create({name:"body",color:Pi.body,...Li});break;case"sleep":this.create({name:"sleep",color:Pi.sleep,...Li});break;case"solid":this.create({name:"solid",color:Pi.solid,...Li});break;case"base":this.create({name:"base",color:Pi.base,...Li});break;case"clay":this.create({name:"clay",color:Pi.clay,metalness:.1,roughness:.7});break;case"clayWhite":this.create({name:"clayWhite",color:Pi.clayWhite,metalness:.1,roughness:.7});break;case"concrete":this.create({name:"concrete",color:Pi.concrete,metalness:0,roughness:.9});break;case"brick":this.create({name:"brick",color:Pi.brick,metalness:0,roughness:.6});break;case"sand":this.create({name:"sand",color:Pi.sand,metalness:0,roughness:.9});break;case"chrome":this.create({name:"chrome",color:Pi.chrome,specularColor:Pi.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:Pi.gold,specularColor:Pi.gold2,metalness:1,roughness:.02});break;case"copper":this.create({name:"copper",color:Pi.copper,metalness:1,roughness:.05});break;case"titanium":this.create({name:"titanium",color:Pi.titanium,metalness:1,roughness:0,specularColor:Pi.titaniumSpec});break;case"carPaint":this.create({name:"carPaint",color:Pi.carPaint,metalness:0,anisotropy:new g(.5,.5),roughness:.4,clearcoat:1,clearcoatRoughness:0});break;case"carbon":this.create({name:"carbon",map:new Ri,normalMap:new Ri(!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,...Li});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,...Li});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 zi{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 Gi{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 Ui(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 Ui{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 Oi{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 qi extends Oi{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*ki.ray,i.update(e,s,this.motor.reflow.ray[a]||null)}add(e={}){this.setName(e);let t=new ji(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 ji 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 J,this.end=new J(0,1,0),this.tmp=new J,this.vnormal=new J,this.vv1=new J,this.vv2=new J,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 W,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(bi.angleTo(this.vv1.toArray(),this.data.normal)*pi);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 Hi extends Y{constructor(e,t,i=0){super(e,t,i),this.matrixAutoUpdate=!1,this.tmpMatrix=new W,this.tmpQuat=new X,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 Vi{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 Ki(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 A=0;for(let t=0;t<e.length;++t){const c=e[t];let d=0;if(s!==(null!==c.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 c.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(c.attributes[e]),d++}if(d!==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!==c.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 c.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(c.morphAttributes[e])}if(i){let e;if(s)e=c.index.count;else{if(void 0===c.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=c.attributes.position.count}h.addGroup(A,e,t),A+=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=Ji(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=Ji(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 Ji(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