diff --git a/example/bundle/3dtex_repro.html b/example/bundle/3dtex_repro.html new file mode 100644 index 000000000..ca64ac0de --- /dev/null +++ b/example/bundle/3dtex_repro.html @@ -0,0 +1,51 @@ + + + + three-mesh-bvh - Fast SDF Generation + + + + + + + + + + + + diff --git a/example/bundle/assets/3dtex_repro-DUwHz_l8.js b/example/bundle/assets/3dtex_repro-DUwHz_l8.js new file mode 100644 index 000000000..7cce48414 --- /dev/null +++ b/example/bundle/assets/3dtex_repro-DUwHz_l8.js @@ -0,0 +1,288 @@ +import{W as c,T as d,a as l,R as u,F as v,H as f,L as a,S as h}from"./ExtendedTriangle-CNpFv597.js";import{F as x}from"./Pass-Bx56TwXN.js";import{M as b}from"./MeshBVH-ujCvfObx.js";import{M as m}from"./MeshBVHUniformStruct-CwgYze0J.js";class p extends h{constructor(n){super({uniforms:{bvh:{value:new m}},vertexShader:` + + void main() { + + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + + } + + `,fragmentShader:` + + precision highp isampler2D; + precision highp usampler2D; + + /* common_functions.glsl.js */ + + // A stack of uint32 indices can can store the indices for + // a perfectly balanced tree with a depth up to 31. Lower stack + // depth gets higher performance. + // + // However not all trees are balanced. Best value to set this to + // is the trees max depth. + #ifndef BVH_STACK_DEPTH + #define BVH_STACK_DEPTH 60 + #endif + + #ifndef INFINITY + #define INFINITY 1e20 + #endif + + // Utilities + uvec4 uTexelFetch1D( usampler2D tex, uint index ) { + + uint width = uint( textureSize( tex, 0 ).x ); + uvec2 uv; + uv.x = index % width; + uv.y = index / width; + + return texelFetch( tex, ivec2( uv ), 0 ); + + } + + vec4 texelFetch1D( sampler2D tex, uint index ) { + + uint width = uint( textureSize( tex, 0 ).x ); + uvec2 uv; + uv.x = index % width; + uv.y = index / width; + + return texelFetch( tex, ivec2( uv ), 0 ); + + } + + /* bvh_struct_definitions.glsl.js */ + struct BVH { + + usampler2D index; + sampler2D position; + + sampler2D bvhBounds; + usampler2D bvhContents; + + }; + + /* bvh_ray_functions.glsl.js */ + #ifndef TRI_INTERSECT_EPSILON + #define TRI_INTERSECT_EPSILON 1e-5 + #endif + + // Raycasting + bool intersectsBounds( vec3 rayOrigin, vec3 rayDirection, vec3 boundsMin, vec3 boundsMax, out float dist ) { + + // https://www.reddit.com/r/opengl/comments/8ntzz5/fast_glsl_ray_box_intersection/ + // https://tavianator.com/2011/ray_box.html + vec3 invDir = 1.0 / rayDirection; + + // find intersection distances for each plane + vec3 tMinPlane = invDir * ( boundsMin - rayOrigin ); + vec3 tMaxPlane = invDir * ( boundsMax - rayOrigin ); + + // get the min and max distances from each intersection + vec3 tMinHit = min( tMaxPlane, tMinPlane ); + vec3 tMaxHit = max( tMaxPlane, tMinPlane ); + + // get the furthest hit distance + vec2 t = max( tMinHit.xx, tMinHit.yz ); + float t0 = max( t.x, t.y ); + + // get the minimum hit distance + t = min( tMaxHit.xx, tMaxHit.yz ); + float t1 = min( t.x, t.y ); + + // set distance to 0.0 if the ray starts inside the box + dist = max( t0, 0.0 ); + + return t1 >= dist; + + } + + bool intersectsTriangle( + vec3 rayOrigin, vec3 rayDirection, vec3 a, vec3 b, vec3 c, + out vec3 barycoord, out vec3 norm, out float dist, out float side + ) { + + // https://stackoverflow.com/questions/42740765/intersection-between-line-and-triangle-in-3d + vec3 edge1 = b - a; + vec3 edge2 = c - a; + norm = cross( edge1, edge2 ); + + float det = - dot( rayDirection, norm ); + float invdet = 1.0 / det; + + vec3 AO = rayOrigin - a; + vec3 DAO = cross( AO, rayDirection ); + + vec4 uvt; + uvt.x = dot( edge2, DAO ) * invdet; + uvt.y = - dot( edge1, DAO ) * invdet; + uvt.z = dot( AO, norm ) * invdet; + uvt.w = 1.0 - uvt.x - uvt.y; + + // set the hit information + barycoord = uvt.wxy; // arranged in A, B, C order + dist = uvt.z; + side = sign( det ); + norm = side * normalize( norm ); + + // add an epsilon to avoid misses between triangles + uvt += vec4( TRI_INTERSECT_EPSILON ); + + return all( greaterThanEqual( uvt, vec4( 0.0 ) ) ); + + } + + bool intersectTriangles( + // geometry info and triangle range + sampler2D positionAttr, usampler2D indexAttr, uint offset, uint count, + + // ray + vec3 rayOrigin, vec3 rayDirection, + + // outputs + inout float minDistance, inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord, + inout float side, inout float dist + ) { + + bool found = false; + vec3 localBarycoord, localNormal; + float localDist, localSide; + for ( uint i = offset, l = offset + count; i < l; i ++ ) { + + uvec3 indices = uTexelFetch1D( indexAttr, i ).xyz; + vec3 a = texelFetch1D( positionAttr, indices.x ).rgb; + vec3 b = texelFetch1D( positionAttr, indices.y ).rgb; + vec3 c = texelFetch1D( positionAttr, indices.z ).rgb; + + if ( + intersectsTriangle( rayOrigin, rayDirection, a, b, c, localBarycoord, localNormal, localDist, localSide ) + && localDist < minDistance + ) { + + found = true; + minDistance = localDist; + + faceIndices = uvec4( indices.xyz, i ); + faceNormal = localNormal; + + side = localSide; + barycoord = localBarycoord; + dist = localDist; + + } + + } + + return found; + + } + + bool intersectsBVHNodeBounds( vec3 rayOrigin, vec3 rayDirection, sampler2D bvhBounds, uint currNodeIndex, out float dist ) { + + uint cni2 = currNodeIndex * 2u; + vec3 boundsMin = texelFetch1D( bvhBounds, cni2 ).xyz; + vec3 boundsMax = texelFetch1D( bvhBounds, cni2 + 1u ).xyz; + return intersectsBounds( rayOrigin, rayDirection, boundsMin, boundsMax, dist ); + + } + + bool _bvhIntersectFirstHit( + // bvh info + sampler2D bvh_position, usampler2D bvh_index, sampler2D bvh_bvhBounds, usampler2D bvh_bvhContents, + + // ray + vec3 rayOrigin, vec3 rayDirection, + + // output variables split into separate variables due to output precision + inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord, + inout float side, inout float dist + ) { + + // stack needs to be twice as long as the deepest tree we expect because + // we push both the left and right child onto the stack every traversal + int ptr = 0; + uint stack[ BVH_STACK_DEPTH ]; + stack[ 0 ] = 0u; + + float triangleDistance = INFINITY; + bool found = false; + while ( ptr > - 1 && ptr < BVH_STACK_DEPTH ) { + + uint currNodeIndex = stack[ ptr ]; + ptr --; + + // check if we intersect the current bounds + float boundsHitDistance; + if ( + ! intersectsBVHNodeBounds( rayOrigin, rayDirection, bvh_bvhBounds, currNodeIndex, boundsHitDistance ) + || boundsHitDistance > triangleDistance + ) { + + continue; + + } + + uvec2 boundsInfo = uTexelFetch1D( bvh_bvhContents, currNodeIndex ).xy; + bool isLeaf = bool( boundsInfo.x & 0xffff0000u ); + + if ( isLeaf ) { + + uint count = boundsInfo.x & 0x0000ffffu; + uint offset = boundsInfo.y; + + found = intersectTriangles( + bvh_position, bvh_index, offset, count, + rayOrigin, rayDirection, triangleDistance, + faceIndices, faceNormal, barycoord, side, dist + ) || found; + + } else { + + uint leftIndex = currNodeIndex + 1u; + uint splitAxis = boundsInfo.x & 0x0000ffffu; + uint rightIndex = boundsInfo.y; + + bool leftToRight = rayDirection[ splitAxis ] >= 0.0; + uint c1 = leftToRight ? leftIndex : rightIndex; + uint c2 = leftToRight ? rightIndex : leftIndex; + + // set c2 in the stack so we traverse it later. We need to keep track of a pointer in + // the stack while we traverse. The second pointer added is the one that will be + // traversed first + ptr ++; + stack[ ptr ] = c2; + + ptr ++; + stack[ ptr ] = c1; + + } + + } + + return found; + + } + + /* main */ + uniform BVH bvh; + void main() { + + // compute the point in space to check + vec3 point = vec3( 0.0 ); + uvec4 faceIndices; + vec3 faceNormal; + vec3 barycoord; + float side; + float rayDist; + + side = 1.0; + _bvhIntersectFirstHit( + bvh.position, bvh.index, bvh.bvhBounds, bvh.bvhContents, + point.xyz, vec3( 0, 0, 1 ), faceIndices, faceNormal, barycoord, side, rayDist + ); + + // if the triangle side is the back then it must be on the inside and the value negative + gl_FragColor = vec4( side, 0, 0, 0 ); + + } + + `}),this.setValues(n)}}const g={resolution:75};let e,s,i,r;y();function y(){e=new c({antialias:!0}),e.setPixelRatio(window.devicePixelRatio),e.setSize(window.innerWidth,window.innerHeight),document.body.appendChild(e.domElement),r=new x(new p);const t=new d(1,.4,1e3,500);s=new b(t,{maxLeafTris:1}),D()}function D(){const t=g.resolution,n=e.extensions.get("OES_texture_float_linear");i=new l(t,t,t),i.texture.format=u,i.texture.type=n?v:f,i.texture.minFilter=a,i.texture.magFilter=a,r.material.uniforms.bvh.value.updateFrom(s);for(let o=0;o{const E=new A.array.constructor(A.count*A.itemSize);a[h][x]=new A.constructor(E,A.itemSize,A.normalized)}))}const i=c*.5,p=Math.log10(1/c),T=Math.pow(10,p),M=i*T;for(let b=0;b{const f=n[3]-n[0],c=n[4]-n[1],m=n[5]-n[2],u=2*(f*c+c*m+m*f);e.nodeCount++,s?(e.leafNodeCount++,e.depth.min=Math.min(i,e.depth.min),e.depth.max=Math.max(i,e.depth.max),e.tris.min=Math.min(a,e.tris.min),e.tris.max=Math.max(a,e.tris.max),e.surfaceAreaScore+=u*y*a):(e.splits[t]++,e.surfaceAreaScore+=u*l)},o),e.tris.min===1/0&&(e.tris.min=0,e.tris.max=0),e.depth.min===1/0&&(e.depth.min=0,e.depth.max=0),e}function S(r){return r._roots.map((o,e)=>d(r,e))}function I(r){const o=new Set,e=[r];let i=0;for(;e.length;){const s=e.pop();if(!o.has(s)){o.add(s);for(let n in s){if(!Object.hasOwn(s,n))continue;i+=h(n);const t=s[n];t&&(typeof t=="object"||typeof t=="function")?x(t)||p()&&t instanceof SharedArrayBuffer||t instanceof ArrayBuffer?i+=t.byteLength:e.push(t):i+=h(t)}}}return i}export{I as e,S as g}; diff --git a/example/bundle/assets/ExtendedTriangle-CNpFv597.js b/example/bundle/assets/ExtendedTriangle-CNpFv597.js new file mode 100644 index 000000000..a9dea18dc --- /dev/null +++ b/example/bundle/assets/ExtendedTriangle-CNpFv597.js @@ -0,0 +1,3828 @@ +(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))n(i);new MutationObserver(i=>{for(const r of i)if(r.type==="childList")for(const a of r.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&n(a)}).observe(document,{childList:!0,subtree:!0});function e(i){const r={};return i.integrity&&(r.integrity=i.integrity),i.referrerPolicy&&(r.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?r.credentials="include":i.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function n(i){if(i.ep)return;i.ep=!0;const r=e(i);fetch(i.href,r)}})();/** + * @license + * Copyright 2010-2024 Three.js Authors + * SPDX-License-Identifier: MIT + */const Fa="170",Fg={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},Bg={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},Tl=0,ro=1,Al=2,Ic=1,wl=2,cn=3,Pn=0,Ae=1,hn=2,Cn=0,pi=1,ao=2,oo=3,co=4,Rl=5,qn=100,Cl=101,Il=102,Pl=103,Ll=104,Dl=200,Ul=201,Nl=202,Fl=203,qr=204,Yr=205,Bl=206,Ol=207,zl=208,Vl=209,kl=210,Hl=211,Gl=212,Wl=213,Xl=214,jr=0,Kr=1,Zr=2,xi=3,$r=4,Jr=5,Qr=6,ta=7,Ba=0,ql=1,Yl=2,In=0,jl=1,Kl=2,Zl=3,$l=4,Jl=5,Ql=6,th=7,lo="attached",eh="detached",Pc=300,vi=301,Mi=302,ea=303,na=304,Zs=306,ia=1e3,dn=1001,sa=1002,Ue=1003,nh=1004,ns=1005,Le=1006,or=1007,wn=1008,gn=1009,Lc=1010,Dc=1011,Xi=1012,Oa=1013,Ln=1014,De=1015,ji=1016,za=1017,Va=1018,yi=1020,Uc=35902,Nc=1021,Fc=1022,be=1023,Bc=1024,Oc=1025,mi=1026,Si=1027,ka=1028,$s=1029,zc=1030,Ha=1031,Ga=1033,Fs=33776,Bs=33777,Os=33778,zs=33779,ra=35840,aa=35841,oa=35842,ca=35843,la=36196,ha=37492,ua=37496,da=37808,fa=37809,pa=37810,ma=37811,ga=37812,_a=37813,xa=37814,va=37815,Ma=37816,ya=37817,Sa=37818,Ea=37819,ba=37820,Ta=37821,Vs=36492,Aa=36494,wa=36495,Vc=36283,Ra=36284,Ca=36285,Ia=36286,ih=2200,sh=2201,rh=2202,Hs=2300,Pa=2301,cr=2302,ui=2400,di=2401,Gs=2402,Wa=2500,ah=2501,Og=0,zg=1,Vg=2,oh=3200,ch=3201,Ki=0,lh=1,An="",ze="srgb",Ti="srgb-linear",Js="linear",$t="srgb",kg=0,Zn=7680,Hg=34055,Gg=34056,Wg=517,ho=519,hh=512,uh=513,dh=514,kc=515,fh=516,ph=517,mh=518,gh=519,La=35044,Xg=35048,uo="300 es",fn=2e3,Ws=2001;class Nn{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const n=this._listeners;n[t]===void 0&&(n[t]=[]),n[t].indexOf(e)===-1&&n[t].push(e)}hasEventListener(t,e){if(this._listeners===void 0)return!1;const n=this._listeners;return n[t]!==void 0&&n[t].indexOf(e)!==-1}removeEventListener(t,e){if(this._listeners===void 0)return;const i=this._listeners[t];if(i!==void 0){const r=i.indexOf(e);r!==-1&&i.splice(r,1)}}dispatchEvent(t){if(this._listeners===void 0)return;const n=this._listeners[t.type];if(n!==void 0){t.target=this;const i=n.slice(0);for(let r=0,a=i.length;r>8&255]+ge[s>>16&255]+ge[s>>24&255]+"-"+ge[t&255]+ge[t>>8&255]+"-"+ge[t>>16&15|64]+ge[t>>24&255]+"-"+ge[e&63|128]+ge[e>>8&255]+"-"+ge[e>>16&255]+ge[e>>24&255]+ge[n&255]+ge[n>>8&255]+ge[n>>16&255]+ge[n>>24&255]).toLowerCase()}function he(s,t,e){return Math.max(t,Math.min(e,s))}function Xa(s,t){return(s%t+t)%t}function _h(s,t,e,n,i){return n+(s-t)*(i-n)/(e-t)}function xh(s,t,e){return s!==t?(e-s)/(t-s):0}function Wi(s,t,e){return(1-e)*s+e*t}function vh(s,t,e,n){return Wi(s,t,1-Math.exp(-e*n))}function Mh(s,t=1){return t-Math.abs(Xa(s,t*2)-t)}function yh(s,t,e){return s<=t?0:s>=e?1:(s=(s-t)/(e-t),s*s*(3-2*s))}function Sh(s,t,e){return s<=t?0:s>=e?1:(s=(s-t)/(e-t),s*s*s*(s*(s*6-15)+10))}function Eh(s,t){return s+Math.floor(Math.random()*(t-s+1))}function bh(s,t){return s+Math.random()*(t-s)}function Th(s){return s*(.5-Math.random())}function Ah(s){s!==void 0&&(fo=s);let t=fo+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function wh(s){return s*Gi}function Rh(s){return s*Ei}function Ch(s){return(s&s-1)===0&&s!==0}function Ih(s){return Math.pow(2,Math.ceil(Math.log(s)/Math.LN2))}function Ph(s){return Math.pow(2,Math.floor(Math.log(s)/Math.LN2))}function Lh(s,t,e,n,i){const r=Math.cos,a=Math.sin,o=r(e/2),c=a(e/2),l=r((t+n)/2),h=a((t+n)/2),u=r((t-n)/2),d=a((t-n)/2),p=r((n-t)/2),g=a((n-t)/2);switch(i){case"XYX":s.set(o*h,c*u,c*d,o*l);break;case"YZY":s.set(c*d,o*h,c*u,o*l);break;case"ZXZ":s.set(c*u,c*d,o*h,o*l);break;case"XZX":s.set(o*h,c*g,c*p,o*l);break;case"YXY":s.set(c*p,o*h,c*g,o*l);break;case"ZYZ":s.set(c*g,c*p,o*h,o*l);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function qe(s,t){switch(t.constructor){case Float32Array:return s;case Uint32Array:return s/4294967295;case Uint16Array:return s/65535;case Uint8Array:return s/255;case Int32Array:return Math.max(s/2147483647,-1);case Int16Array:return Math.max(s/32767,-1);case Int8Array:return Math.max(s/127,-1);default:throw new Error("Invalid component type.")}}function Kt(s,t){switch(t.constructor){case Float32Array:return s;case Uint32Array:return Math.round(s*4294967295);case Uint16Array:return Math.round(s*65535);case Uint8Array:return Math.round(s*255);case Int32Array:return Math.round(s*2147483647);case Int16Array:return Math.round(s*32767);case Int8Array:return Math.round(s*127);default:throw new Error("Invalid component type.")}}const qg={DEG2RAD:Gi,RAD2DEG:Ei,generateUUID:Ye,clamp:he,euclideanModulo:Xa,mapLinear:_h,inverseLerp:xh,lerp:Wi,damp:vh,pingpong:Mh,smoothstep:yh,smootherstep:Sh,randInt:Eh,randFloat:bh,randFloatSpread:Th,seededRandom:Ah,degToRad:wh,radToDeg:Rh,isPowerOfTwo:Ch,ceilPowerOfTwo:Ih,floorPowerOfTwo:Ph,setQuaternionFromProperEuler:Lh,normalize:Kt,denormalize:qe};class Pt{constructor(t=0,e=0){Pt.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,n=this.y,i=t.elements;return this.x=i[0]*e+i[3]*n+i[6],this.y=i[1]*e+i[4]*n+i[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(he(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y;return e*e+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const n=Math.cos(e),i=Math.sin(e),r=this.x-t.x,a=this.y-t.y;return this.x=r*n-a*i+t.x,this.y=r*i+a*n+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class It{constructor(t,e,n,i,r,a,o,c,l){It.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,n,i,r,a,o,c,l)}set(t,e,n,i,r,a,o,c,l){const h=this.elements;return h[0]=t,h[1]=i,h[2]=o,h[3]=e,h[4]=r,h[5]=c,h[6]=n,h[7]=a,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],this}extractBasis(t,e,n){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,i=e.elements,r=this.elements,a=n[0],o=n[3],c=n[6],l=n[1],h=n[4],u=n[7],d=n[2],p=n[5],g=n[8],_=i[0],m=i[3],f=i[6],b=i[1],E=i[4],x=i[7],P=i[2],A=i[5],w=i[8];return r[0]=a*_+o*b+c*P,r[3]=a*m+o*E+c*A,r[6]=a*f+o*x+c*w,r[1]=l*_+h*b+u*P,r[4]=l*m+h*E+u*A,r[7]=l*f+h*x+u*w,r[2]=d*_+p*b+g*P,r[5]=d*m+p*E+g*A,r[8]=d*f+p*x+g*w,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],a=t[4],o=t[5],c=t[6],l=t[7],h=t[8];return e*a*h-e*o*l-n*r*h+n*o*c+i*r*l-i*a*c}invert(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],a=t[4],o=t[5],c=t[6],l=t[7],h=t[8],u=h*a-o*l,d=o*c-h*r,p=l*r-a*c,g=e*u+n*d+i*p;if(g===0)return this.set(0,0,0,0,0,0,0,0,0);const _=1/g;return t[0]=u*_,t[1]=(i*l-h*n)*_,t[2]=(o*n-i*a)*_,t[3]=d*_,t[4]=(h*e-i*c)*_,t[5]=(i*r-o*e)*_,t[6]=p*_,t[7]=(n*c-l*e)*_,t[8]=(a*e-n*r)*_,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,n,i,r,a,o){const c=Math.cos(r),l=Math.sin(r);return this.set(n*c,n*l,-n*(c*a+l*o)+a+t,-i*l,i*c,-i*(-l*a+c*o)+o+e,0,0,1),this}scale(t,e){return this.premultiply(lr.makeScale(t,e)),this}rotate(t){return this.premultiply(lr.makeRotation(-t)),this}translate(t,e){return this.premultiply(lr.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,n,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,n=t.elements;for(let i=0;i<9;i++)if(e[i]!==n[i])return!1;return!0}fromArray(t,e=0){for(let n=0;n<9;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t}clone(){return new this.constructor().fromArray(this.elements)}}const lr=new It;function Hc(s){for(let t=s.length-1;t>=0;--t)if(s[t]>=65535)return!0;return!1}function qi(s){return document.createElementNS("http://www.w3.org/1999/xhtml",s)}function Dh(){const s=qi("canvas");return s.style.display="block",s}const po={};function ki(s){s in po||(po[s]=!0,console.warn(s))}function Uh(s,t,e){return new Promise(function(n,i){function r(){switch(s.clientWaitSync(t,s.SYNC_FLUSH_COMMANDS_BIT,0)){case s.WAIT_FAILED:i();break;case s.TIMEOUT_EXPIRED:setTimeout(r,e);break;default:n()}}setTimeout(r,e)})}function Nh(s){const t=s.elements;t[2]=.5*t[2]+.5*t[3],t[6]=.5*t[6]+.5*t[7],t[10]=.5*t[10]+.5*t[11],t[14]=.5*t[14]+.5*t[15]}function Fh(s){const t=s.elements;t[11]===-1?(t[10]=-t[10]-1,t[14]=-t[14]):(t[10]=-t[10],t[14]=-t[14]+1)}const Vt={enabled:!0,workingColorSpace:Ti,spaces:{},convert:function(s,t,e){return this.enabled===!1||t===e||!t||!e||(this.spaces[t].transfer===$t&&(s.r=pn(s.r),s.g=pn(s.g),s.b=pn(s.b)),this.spaces[t].primaries!==this.spaces[e].primaries&&(s.applyMatrix3(this.spaces[t].toXYZ),s.applyMatrix3(this.spaces[e].fromXYZ)),this.spaces[e].transfer===$t&&(s.r=gi(s.r),s.g=gi(s.g),s.b=gi(s.b))),s},fromWorkingColorSpace:function(s,t){return this.convert(s,this.workingColorSpace,t)},toWorkingColorSpace:function(s,t){return this.convert(s,t,this.workingColorSpace)},getPrimaries:function(s){return this.spaces[s].primaries},getTransfer:function(s){return s===An?Js:this.spaces[s].transfer},getLuminanceCoefficients:function(s,t=this.workingColorSpace){return s.fromArray(this.spaces[t].luminanceCoefficients)},define:function(s){Object.assign(this.spaces,s)},_getMatrix:function(s,t,e){return s.copy(this.spaces[t].toXYZ).multiply(this.spaces[e].fromXYZ)},_getDrawingBufferColorSpace:function(s){return this.spaces[s].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(s=this.workingColorSpace){return this.spaces[s].workingColorSpaceConfig.unpackColorSpace}};function pn(s){return s<.04045?s*.0773993808:Math.pow(s*.9478672986+.0521327014,2.4)}function gi(s){return s<.0031308?s*12.92:1.055*Math.pow(s,.41666)-.055}const mo=[.64,.33,.3,.6,.15,.06],go=[.2126,.7152,.0722],_o=[.3127,.329],xo=new It().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),vo=new It().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);Vt.define({[Ti]:{primaries:mo,whitePoint:_o,transfer:Js,toXYZ:xo,fromXYZ:vo,luminanceCoefficients:go,workingColorSpaceConfig:{unpackColorSpace:ze},outputColorSpaceConfig:{drawingBufferColorSpace:ze}},[ze]:{primaries:mo,whitePoint:_o,transfer:$t,toXYZ:xo,fromXYZ:vo,luminanceCoefficients:go,outputColorSpaceConfig:{drawingBufferColorSpace:ze}}});let $n;class Bh{static getDataURL(t){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{$n===void 0&&($n=qi("canvas")),$n.width=t.width,$n.height=t.height;const n=$n.getContext("2d");t instanceof ImageData?n.putImageData(t,0,0):n.drawImage(t,0,0,t.width,t.height),e=$n}return e.width>2048||e.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",t),e.toDataURL("image/jpeg",.6)):e.toDataURL("image/png")}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=qi("canvas");e.width=t.width,e.height=t.height;const n=e.getContext("2d");n.drawImage(t,0,0,t.width,t.height);const i=n.getImageData(0,0,t.width,t.height),r=i.data;for(let a=0;a0&&(n.userData=this.userData),e||(t.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==Pc)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case ia:t.x=t.x-Math.floor(t.x);break;case dn:t.x=t.x<0?0:1;break;case sa:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case ia:t.y=t.y-Math.floor(t.y);break;case dn:t.y=t.y<0?0:1;break;case sa:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}ve.DEFAULT_IMAGE=null;ve.DEFAULT_MAPPING=Pc;ve.DEFAULT_ANISOTROPY=1;class Xt{constructor(t=0,e=0,n=0,i=1){Xt.prototype.isVector4=!0,this.x=t,this.y=e,this.z=n,this.w=i}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,n,i){return this.x=t,this.y=e,this.z=n,this.w=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,n=this.y,i=this.z,r=this.w,a=t.elements;return this.x=a[0]*e+a[4]*n+a[8]*i+a[12]*r,this.y=a[1]*e+a[5]*n+a[9]*i+a[13]*r,this.z=a[2]*e+a[6]*n+a[10]*i+a[14]*r,this.w=a[3]*e+a[7]*n+a[11]*i+a[15]*r,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,n,i,r;const c=t.elements,l=c[0],h=c[4],u=c[8],d=c[1],p=c[5],g=c[9],_=c[2],m=c[6],f=c[10];if(Math.abs(h-d)<.01&&Math.abs(u-_)<.01&&Math.abs(g-m)<.01){if(Math.abs(h+d)<.1&&Math.abs(u+_)<.1&&Math.abs(g+m)<.1&&Math.abs(l+p+f-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const E=(l+1)/2,x=(p+1)/2,P=(f+1)/2,A=(h+d)/4,w=(u+_)/4,C=(g+m)/4;return E>x&&E>P?E<.01?(n=0,i=.707106781,r=.707106781):(n=Math.sqrt(E),i=A/n,r=w/n):x>P?x<.01?(n=.707106781,i=0,r=.707106781):(i=Math.sqrt(x),n=A/i,r=C/i):P<.01?(n=.707106781,i=.707106781,r=0):(r=Math.sqrt(P),n=w/r,i=C/r),this.set(n,i,r,e),this}let b=Math.sqrt((m-g)*(m-g)+(u-_)*(u-_)+(d-h)*(d-h));return Math.abs(b)<.001&&(b=1),this.x=(m-g)/b,this.y=(u-_)/b,this.z=(d-h)/b,this.w=Math.acos((l+p+f-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this.w=Math.max(t.w,Math.min(e.w,this.w)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this.w=Math.max(t,Math.min(e,this.w)),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this.w=t.w+(e.w-t.w)*n,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class Vh extends Nn{constructor(t=1,e=1,n={}){super(),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=1,this.scissor=new Xt(0,0,t,e),this.scissorTest=!1,this.viewport=new Xt(0,0,t,e);const i={width:t,height:e,depth:1};n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:Le,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1},n);const r=new ve(i,n.mapping,n.wrapS,n.wrapT,n.magFilter,n.minFilter,n.format,n.type,n.anisotropy,n.colorSpace);r.flipY=!1,r.generateMipmaps=n.generateMipmaps,r.internalFormat=n.internalFormat,this.textures=[];const a=n.count;for(let o=0;o=0?1:-1,E=1-f*f;if(E>Number.EPSILON){const P=Math.sqrt(E),A=Math.atan2(P,f*b);m=Math.sin(m*A)/P,o=Math.sin(o*A)/P}const x=o*b;if(c=c*m+d*x,l=l*m+p*x,h=h*m+g*x,u=u*m+_*x,m===1-o){const P=1/Math.sqrt(c*c+l*l+h*h+u*u);c*=P,l*=P,h*=P,u*=P}}t[e]=c,t[e+1]=l,t[e+2]=h,t[e+3]=u}static multiplyQuaternionsFlat(t,e,n,i,r,a){const o=n[i],c=n[i+1],l=n[i+2],h=n[i+3],u=r[a],d=r[a+1],p=r[a+2],g=r[a+3];return t[e]=o*g+h*u+c*p-l*d,t[e+1]=c*g+h*d+l*u-o*p,t[e+2]=l*g+h*p+o*d-c*u,t[e+3]=h*g-o*u-c*d-l*p,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,n,i){return this._x=t,this._y=e,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const n=t._x,i=t._y,r=t._z,a=t._order,o=Math.cos,c=Math.sin,l=o(n/2),h=o(i/2),u=o(r/2),d=c(n/2),p=c(i/2),g=c(r/2);switch(a){case"XYZ":this._x=d*h*u+l*p*g,this._y=l*p*u-d*h*g,this._z=l*h*g+d*p*u,this._w=l*h*u-d*p*g;break;case"YXZ":this._x=d*h*u+l*p*g,this._y=l*p*u-d*h*g,this._z=l*h*g-d*p*u,this._w=l*h*u+d*p*g;break;case"ZXY":this._x=d*h*u-l*p*g,this._y=l*p*u+d*h*g,this._z=l*h*g+d*p*u,this._w=l*h*u-d*p*g;break;case"ZYX":this._x=d*h*u-l*p*g,this._y=l*p*u+d*h*g,this._z=l*h*g-d*p*u,this._w=l*h*u+d*p*g;break;case"YZX":this._x=d*h*u+l*p*g,this._y=l*p*u+d*h*g,this._z=l*h*g-d*p*u,this._w=l*h*u-d*p*g;break;case"XZY":this._x=d*h*u-l*p*g,this._y=l*p*u-d*h*g,this._z=l*h*g+d*p*u,this._w=l*h*u+d*p*g;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+a)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const n=e/2,i=Math.sin(n);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,n=e[0],i=e[4],r=e[8],a=e[1],o=e[5],c=e[9],l=e[2],h=e[6],u=e[10],d=n+o+u;if(d>0){const p=.5/Math.sqrt(d+1);this._w=.25/p,this._x=(h-c)*p,this._y=(r-l)*p,this._z=(a-i)*p}else if(n>o&&n>u){const p=2*Math.sqrt(1+n-o-u);this._w=(h-c)/p,this._x=.25*p,this._y=(i+a)/p,this._z=(r+l)/p}else if(o>u){const p=2*Math.sqrt(1+o-n-u);this._w=(r-l)/p,this._x=(i+a)/p,this._y=.25*p,this._z=(c+h)/p}else{const p=2*Math.sqrt(1+u-n-o);this._w=(a-i)/p,this._x=(r+l)/p,this._y=(c+h)/p,this._z=.25*p}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let n=t.dot(e)+1;return nMath.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=n):(this._x=0,this._y=-t.z,this._z=t.y,this._w=n)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=n),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(he(this.dot(t),-1,1)))}rotateTowards(t,e){const n=this.angleTo(t);if(n===0)return this;const i=Math.min(1,e/n);return this.slerp(t,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const n=t._x,i=t._y,r=t._z,a=t._w,o=e._x,c=e._y,l=e._z,h=e._w;return this._x=n*h+a*o+i*l-r*c,this._y=i*h+a*c+r*o-n*l,this._z=r*h+a*l+n*c-i*o,this._w=a*h-n*o-i*c-r*l,this._onChangeCallback(),this}slerp(t,e){if(e===0)return this;if(e===1)return this.copy(t);const n=this._x,i=this._y,r=this._z,a=this._w;let o=a*t._w+n*t._x+i*t._y+r*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),o>=1)return this._w=a,this._x=n,this._y=i,this._z=r,this;const c=1-o*o;if(c<=Number.EPSILON){const p=1-e;return this._w=p*a+e*this._w,this._x=p*n+e*this._x,this._y=p*i+e*this._y,this._z=p*r+e*this._z,this.normalize(),this}const l=Math.sqrt(c),h=Math.atan2(l,o),u=Math.sin((1-e)*h)/l,d=Math.sin(e*h)/l;return this._w=a*u+this._w*d,this._x=n*u+this._x*d,this._y=i*u+this._y*d,this._z=r*u+this._z*d,this._onChangeCallback(),this}slerpQuaternions(t,e,n){return this.copy(t).slerp(e,n)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),r=Math.sqrt(n);return this.set(i*Math.sin(t),i*Math.cos(t),r*Math.sin(e),r*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class R{constructor(t=0,e=0,n=0){R.prototype.isVector3=!0,this.x=t,this.y=e,this.z=n}set(t,e,n){return n===void 0&&(n=this.z),this.x=t,this.y=e,this.z=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(Mo.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Mo.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*n+r[6]*i,this.y=r[1]*e+r[4]*n+r[7]*i,this.z=r[2]*e+r[5]*n+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,n=this.y,i=this.z,r=t.elements,a=1/(r[3]*e+r[7]*n+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*n+r[8]*i+r[12])*a,this.y=(r[1]*e+r[5]*n+r[9]*i+r[13])*a,this.z=(r[2]*e+r[6]*n+r[10]*i+r[14])*a,this}applyQuaternion(t){const e=this.x,n=this.y,i=this.z,r=t.x,a=t.y,o=t.z,c=t.w,l=2*(a*i-o*n),h=2*(o*e-r*i),u=2*(r*n-a*e);return this.x=e+c*l+a*u-o*h,this.y=n+c*h+o*l-r*u,this.z=i+c*u+r*h-a*l,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*n+r[8]*i,this.y=r[1]*e+r[5]*n+r[9]*i,this.z=r[2]*e+r[6]*n+r[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const n=t.x,i=t.y,r=t.z,a=e.x,o=e.y,c=e.z;return this.x=i*c-r*o,this.y=r*a-n*c,this.z=n*o-i*a,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const n=t.dot(this)/e;return this.copy(t).multiplyScalar(n)}projectOnPlane(t){return ur.copy(this).projectOnVector(t),this.sub(ur)}reflect(t){return this.sub(ur.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(he(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return e*e+n*n+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,n){const i=Math.sin(e)*t;return this.x=i*Math.sin(n),this.y=Math.cos(e)*t,this.z=i*Math.cos(n),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,n){return this.x=t*Math.sin(e),this.y=n,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),n=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=n,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=Math.random()*2-1,n=Math.sqrt(1-e*e);return this.x=n*Math.cos(t),this.y=e,this.z=n*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const ur=new R,Mo=new mn;class Ne{constructor(t=new R(1/0,1/0,1/0),e=new R(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,n=t.length;e=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,Ge),Ge.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,n;return t.normal.x>0?(e=t.normal.x*this.min.x,n=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,n=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,n+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,n+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,n+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,n+=t.normal.z*this.min.z),e<=-t.constant&&n>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(Li),ss.subVectors(this.max,Li),Jn.subVectors(t.a,Li),Qn.subVectors(t.b,Li),ti.subVectors(t.c,Li),vn.subVectors(Qn,Jn),Mn.subVectors(ti,Qn),Bn.subVectors(Jn,ti);let e=[0,-vn.z,vn.y,0,-Mn.z,Mn.y,0,-Bn.z,Bn.y,vn.z,0,-vn.x,Mn.z,0,-Mn.x,Bn.z,0,-Bn.x,-vn.y,vn.x,0,-Mn.y,Mn.x,0,-Bn.y,Bn.x,0];return!dr(e,Jn,Qn,ti,ss)||(e=[1,0,0,0,1,0,0,0,1],!dr(e,Jn,Qn,ti,ss))?!1:(rs.crossVectors(vn,Mn),e=[rs.x,rs.y,rs.z],dr(e,Jn,Qn,ti,ss))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Ge).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(Ge).length()*.5),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()?this:(en[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),en[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),en[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),en[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),en[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),en[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),en[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),en[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(en),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const en=[new R,new R,new R,new R,new R,new R,new R,new R],Ge=new R,is=new Ne,Jn=new R,Qn=new R,ti=new R,vn=new R,Mn=new R,Bn=new R,Li=new R,ss=new R,rs=new R,On=new R;function dr(s,t,e,n,i){for(let r=0,a=s.length-3;r<=a;r+=3){On.fromArray(s,r);const o=i.x*Math.abs(On.x)+i.y*Math.abs(On.y)+i.z*Math.abs(On.z),c=t.dot(On),l=e.dot(On),h=n.dot(On);if(Math.max(-Math.max(c,l,h),Math.min(c,l,h))>o)return!1}return!0}const kh=new Ne,Di=new R,fr=new R;class we{constructor(t=new R,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const n=this.center;e!==void 0?n.copy(e):kh.setFromPoints(t).getCenter(n);let i=0;for(let r=0,a=t.length;rthis.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;Di.subVectors(t,this.center);const e=Di.lengthSq();if(e>this.radius*this.radius){const n=Math.sqrt(e),i=(n-this.radius)*.5;this.center.addScaledVector(Di,i/n),this.radius+=i}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(fr.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(Di.copy(t.center).add(fr)),this.expandByPoint(Di.copy(t.center).sub(fr))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}}const nn=new R,pr=new R,as=new R,yn=new R,mr=new R,os=new R,gr=new R;class Zi{constructor(t=new R,e=new R(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,nn)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const n=e.dot(this.direction);return n<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=nn.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(nn.copy(this.origin).addScaledVector(this.direction,e),nn.distanceToSquared(t))}distanceSqToSegment(t,e,n,i){pr.copy(t).add(e).multiplyScalar(.5),as.copy(e).sub(t).normalize(),yn.copy(this.origin).sub(pr);const r=t.distanceTo(e)*.5,a=-this.direction.dot(as),o=yn.dot(this.direction),c=-yn.dot(as),l=yn.lengthSq(),h=Math.abs(1-a*a);let u,d,p,g;if(h>0)if(u=a*c-o,d=a*o-c,g=r*h,u>=0)if(d>=-g)if(d<=g){const _=1/h;u*=_,d*=_,p=u*(u+a*d+2*o)+d*(a*u+d+2*c)+l}else d=r,u=Math.max(0,-(a*d+o)),p=-u*u+d*(d+2*c)+l;else d=-r,u=Math.max(0,-(a*d+o)),p=-u*u+d*(d+2*c)+l;else d<=-g?(u=Math.max(0,-(-a*r+o)),d=u>0?-r:Math.min(Math.max(-r,-c),r),p=-u*u+d*(d+2*c)+l):d<=g?(u=0,d=Math.min(Math.max(-r,-c),r),p=d*(d+2*c)+l):(u=Math.max(0,-(a*r+o)),d=u>0?r:Math.min(Math.max(-r,-c),r),p=-u*u+d*(d+2*c)+l);else d=a>0?-r:r,u=Math.max(0,-(a*d+o)),p=-u*u+d*(d+2*c)+l;return n&&n.copy(this.origin).addScaledVector(this.direction,u),i&&i.copy(pr).addScaledVector(as,d),p}intersectSphere(t,e){nn.subVectors(t.center,this.origin);const n=nn.dot(this.direction),i=nn.dot(nn)-n*n,r=t.radius*t.radius;if(i>r)return null;const a=Math.sqrt(r-i),o=n-a,c=n+a;return c<0?null:o<0?this.at(c,e):this.at(o,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?0:null;const n=-(this.origin.dot(t.normal)+t.constant)/e;return n>=0?n:null}intersectPlane(t,e){const n=this.distanceToPlane(t);return n===null?null:this.at(n,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let n,i,r,a,o,c;const l=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,d=this.origin;return l>=0?(n=(t.min.x-d.x)*l,i=(t.max.x-d.x)*l):(n=(t.max.x-d.x)*l,i=(t.min.x-d.x)*l),h>=0?(r=(t.min.y-d.y)*h,a=(t.max.y-d.y)*h):(r=(t.max.y-d.y)*h,a=(t.min.y-d.y)*h),n>a||r>i||((r>n||isNaN(n))&&(n=r),(a=0?(o=(t.min.z-d.z)*u,c=(t.max.z-d.z)*u):(o=(t.max.z-d.z)*u,c=(t.min.z-d.z)*u),n>c||o>i)||((o>n||n!==n)&&(n=o),(c=0?n:i,e)}intersectsBox(t){return this.intersectBox(t,nn)!==null}intersectTriangle(t,e,n,i,r){mr.subVectors(e,t),os.subVectors(n,t),gr.crossVectors(mr,os);let a=this.direction.dot(gr),o;if(a>0){if(i)return null;o=1}else if(a<0)o=-1,a=-a;else return null;yn.subVectors(this.origin,t);const c=o*this.direction.dot(os.crossVectors(yn,os));if(c<0)return null;const l=o*this.direction.dot(mr.cross(yn));if(l<0||c+l>a)return null;const h=-o*yn.dot(gr);return h<0?null:this.at(h/a,r)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class Lt{constructor(t,e,n,i,r,a,o,c,l,h,u,d,p,g,_,m){Lt.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,n,i,r,a,o,c,l,h,u,d,p,g,_,m)}set(t,e,n,i,r,a,o,c,l,h,u,d,p,g,_,m){const f=this.elements;return f[0]=t,f[4]=e,f[8]=n,f[12]=i,f[1]=r,f[5]=a,f[9]=o,f[13]=c,f[2]=l,f[6]=h,f[10]=u,f[14]=d,f[3]=p,f[7]=g,f[11]=_,f[15]=m,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new Lt().fromArray(this.elements)}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15],this}copyPosition(t){const e=this.elements,n=t.elements;return e[12]=n[12],e[13]=n[13],e[14]=n[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,n){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(t,e,n){return this.set(t.x,e.x,n.x,0,t.y,e.y,n.y,0,t.z,e.z,n.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,n=t.elements,i=1/ei.setFromMatrixColumn(t,0).length(),r=1/ei.setFromMatrixColumn(t,1).length(),a=1/ei.setFromMatrixColumn(t,2).length();return e[0]=n[0]*i,e[1]=n[1]*i,e[2]=n[2]*i,e[3]=0,e[4]=n[4]*r,e[5]=n[5]*r,e[6]=n[6]*r,e[7]=0,e[8]=n[8]*a,e[9]=n[9]*a,e[10]=n[10]*a,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,n=t.x,i=t.y,r=t.z,a=Math.cos(n),o=Math.sin(n),c=Math.cos(i),l=Math.sin(i),h=Math.cos(r),u=Math.sin(r);if(t.order==="XYZ"){const d=a*h,p=a*u,g=o*h,_=o*u;e[0]=c*h,e[4]=-c*u,e[8]=l,e[1]=p+g*l,e[5]=d-_*l,e[9]=-o*c,e[2]=_-d*l,e[6]=g+p*l,e[10]=a*c}else if(t.order==="YXZ"){const d=c*h,p=c*u,g=l*h,_=l*u;e[0]=d+_*o,e[4]=g*o-p,e[8]=a*l,e[1]=a*u,e[5]=a*h,e[9]=-o,e[2]=p*o-g,e[6]=_+d*o,e[10]=a*c}else if(t.order==="ZXY"){const d=c*h,p=c*u,g=l*h,_=l*u;e[0]=d-_*o,e[4]=-a*u,e[8]=g+p*o,e[1]=p+g*o,e[5]=a*h,e[9]=_-d*o,e[2]=-a*l,e[6]=o,e[10]=a*c}else if(t.order==="ZYX"){const d=a*h,p=a*u,g=o*h,_=o*u;e[0]=c*h,e[4]=g*l-p,e[8]=d*l+_,e[1]=c*u,e[5]=_*l+d,e[9]=p*l-g,e[2]=-l,e[6]=o*c,e[10]=a*c}else if(t.order==="YZX"){const d=a*c,p=a*l,g=o*c,_=o*l;e[0]=c*h,e[4]=_-d*u,e[8]=g*u+p,e[1]=u,e[5]=a*h,e[9]=-o*h,e[2]=-l*h,e[6]=p*u+g,e[10]=d-_*u}else if(t.order==="XZY"){const d=a*c,p=a*l,g=o*c,_=o*l;e[0]=c*h,e[4]=-u,e[8]=l*h,e[1]=d*u+_,e[5]=a*h,e[9]=p*u-g,e[2]=g*u-p,e[6]=o*h,e[10]=_*u+d}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(Hh,t,Gh)}lookAt(t,e,n){const i=this.elements;return Ce.subVectors(t,e),Ce.lengthSq()===0&&(Ce.z=1),Ce.normalize(),Sn.crossVectors(n,Ce),Sn.lengthSq()===0&&(Math.abs(n.z)===1?Ce.x+=1e-4:Ce.z+=1e-4,Ce.normalize(),Sn.crossVectors(n,Ce)),Sn.normalize(),cs.crossVectors(Ce,Sn),i[0]=Sn.x,i[4]=cs.x,i[8]=Ce.x,i[1]=Sn.y,i[5]=cs.y,i[9]=Ce.y,i[2]=Sn.z,i[6]=cs.z,i[10]=Ce.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,i=e.elements,r=this.elements,a=n[0],o=n[4],c=n[8],l=n[12],h=n[1],u=n[5],d=n[9],p=n[13],g=n[2],_=n[6],m=n[10],f=n[14],b=n[3],E=n[7],x=n[11],P=n[15],A=i[0],w=i[4],C=i[8],y=i[12],v=i[1],I=i[5],V=i[9],B=i[13],G=i[2],K=i[6],W=i[10],Q=i[14],H=i[3],it=i[7],lt=i[11],vt=i[15];return r[0]=a*A+o*v+c*G+l*H,r[4]=a*w+o*I+c*K+l*it,r[8]=a*C+o*V+c*W+l*lt,r[12]=a*y+o*B+c*Q+l*vt,r[1]=h*A+u*v+d*G+p*H,r[5]=h*w+u*I+d*K+p*it,r[9]=h*C+u*V+d*W+p*lt,r[13]=h*y+u*B+d*Q+p*vt,r[2]=g*A+_*v+m*G+f*H,r[6]=g*w+_*I+m*K+f*it,r[10]=g*C+_*V+m*W+f*lt,r[14]=g*y+_*B+m*Q+f*vt,r[3]=b*A+E*v+x*G+P*H,r[7]=b*w+E*I+x*K+P*it,r[11]=b*C+E*V+x*W+P*lt,r[15]=b*y+E*B+x*Q+P*vt,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[4],i=t[8],r=t[12],a=t[1],o=t[5],c=t[9],l=t[13],h=t[2],u=t[6],d=t[10],p=t[14],g=t[3],_=t[7],m=t[11],f=t[15];return g*(+r*c*u-i*l*u-r*o*d+n*l*d+i*o*p-n*c*p)+_*(+e*c*p-e*l*d+r*a*d-i*a*p+i*l*h-r*c*h)+m*(+e*l*u-e*o*p-r*a*u+n*a*p+r*o*h-n*l*h)+f*(-i*o*h-e*c*u+e*o*d+i*a*u-n*a*d+n*c*h)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,n){const i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=n),this}invert(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],a=t[4],o=t[5],c=t[6],l=t[7],h=t[8],u=t[9],d=t[10],p=t[11],g=t[12],_=t[13],m=t[14],f=t[15],b=u*m*l-_*d*l+_*c*p-o*m*p-u*c*f+o*d*f,E=g*d*l-h*m*l-g*c*p+a*m*p+h*c*f-a*d*f,x=h*_*l-g*u*l+g*o*p-a*_*p-h*o*f+a*u*f,P=g*u*c-h*_*c-g*o*d+a*_*d+h*o*m-a*u*m,A=e*b+n*E+i*x+r*P;if(A===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const w=1/A;return t[0]=b*w,t[1]=(_*d*r-u*m*r-_*i*p+n*m*p+u*i*f-n*d*f)*w,t[2]=(o*m*r-_*c*r+_*i*l-n*m*l-o*i*f+n*c*f)*w,t[3]=(u*c*r-o*d*r-u*i*l+n*d*l+o*i*p-n*c*p)*w,t[4]=E*w,t[5]=(h*m*r-g*d*r+g*i*p-e*m*p-h*i*f+e*d*f)*w,t[6]=(g*c*r-a*m*r-g*i*l+e*m*l+a*i*f-e*c*f)*w,t[7]=(a*d*r-h*c*r+h*i*l-e*d*l-a*i*p+e*c*p)*w,t[8]=x*w,t[9]=(g*u*r-h*_*r-g*n*p+e*_*p+h*n*f-e*u*f)*w,t[10]=(a*_*r-g*o*r+g*n*l-e*_*l-a*n*f+e*o*f)*w,t[11]=(h*o*r-a*u*r-h*n*l+e*u*l+a*n*p-e*o*p)*w,t[12]=P*w,t[13]=(h*_*i-g*u*i+g*n*d-e*_*d-h*n*m+e*u*m)*w,t[14]=(g*o*i-a*_*i-g*n*c+e*_*c+a*n*m-e*o*m)*w,t[15]=(a*u*i-h*o*i+h*n*c-e*u*c-a*n*d+e*o*d)*w,this}scale(t){const e=this.elements,n=t.x,i=t.y,r=t.z;return e[0]*=n,e[4]*=i,e[8]*=r,e[1]*=n,e[5]*=i,e[9]*=r,e[2]*=n,e[6]*=i,e[10]*=r,e[3]*=n,e[7]*=i,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],n=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,n,i))}makeTranslation(t,e,n){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),n=Math.sin(t);return this.set(1,0,0,0,0,e,-n,0,0,n,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,0,n,0,0,1,0,0,-n,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,0,n,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const n=Math.cos(e),i=Math.sin(e),r=1-n,a=t.x,o=t.y,c=t.z,l=r*a,h=r*o;return this.set(l*a+n,l*o-i*c,l*c+i*o,0,l*o+i*c,h*o+n,h*c-i*a,0,l*c-i*o,h*c+i*a,r*c*c+n,0,0,0,0,1),this}makeScale(t,e,n){return this.set(t,0,0,0,0,e,0,0,0,0,n,0,0,0,0,1),this}makeShear(t,e,n,i,r,a){return this.set(1,n,r,0,t,1,a,0,e,i,1,0,0,0,0,1),this}compose(t,e,n){const i=this.elements,r=e._x,a=e._y,o=e._z,c=e._w,l=r+r,h=a+a,u=o+o,d=r*l,p=r*h,g=r*u,_=a*h,m=a*u,f=o*u,b=c*l,E=c*h,x=c*u,P=n.x,A=n.y,w=n.z;return i[0]=(1-(_+f))*P,i[1]=(p+x)*P,i[2]=(g-E)*P,i[3]=0,i[4]=(p-x)*A,i[5]=(1-(d+f))*A,i[6]=(m+b)*A,i[7]=0,i[8]=(g+E)*w,i[9]=(m-b)*w,i[10]=(1-(d+_))*w,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,n){const i=this.elements;let r=ei.set(i[0],i[1],i[2]).length();const a=ei.set(i[4],i[5],i[6]).length(),o=ei.set(i[8],i[9],i[10]).length();this.determinant()<0&&(r=-r),t.x=i[12],t.y=i[13],t.z=i[14],We.copy(this);const l=1/r,h=1/a,u=1/o;return We.elements[0]*=l,We.elements[1]*=l,We.elements[2]*=l,We.elements[4]*=h,We.elements[5]*=h,We.elements[6]*=h,We.elements[8]*=u,We.elements[9]*=u,We.elements[10]*=u,e.setFromRotationMatrix(We),n.x=r,n.y=a,n.z=o,this}makePerspective(t,e,n,i,r,a,o=fn){const c=this.elements,l=2*r/(e-t),h=2*r/(n-i),u=(e+t)/(e-t),d=(n+i)/(n-i);let p,g;if(o===fn)p=-(a+r)/(a-r),g=-2*a*r/(a-r);else if(o===Ws)p=-a/(a-r),g=-a*r/(a-r);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);return c[0]=l,c[4]=0,c[8]=u,c[12]=0,c[1]=0,c[5]=h,c[9]=d,c[13]=0,c[2]=0,c[6]=0,c[10]=p,c[14]=g,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(t,e,n,i,r,a,o=fn){const c=this.elements,l=1/(e-t),h=1/(n-i),u=1/(a-r),d=(e+t)*l,p=(n+i)*h;let g,_;if(o===fn)g=(a+r)*u,_=-2*u;else if(o===Ws)g=r*u,_=-1*u;else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return c[0]=2*l,c[4]=0,c[8]=0,c[12]=-d,c[1]=0,c[5]=2*h,c[9]=0,c[13]=-p,c[2]=0,c[6]=0,c[10]=_,c[14]=-g,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(t){const e=this.elements,n=t.elements;for(let i=0;i<16;i++)if(e[i]!==n[i])return!1;return!0}fromArray(t,e=0){for(let n=0;n<16;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t[e+9]=n[9],t[e+10]=n[10],t[e+11]=n[11],t[e+12]=n[12],t[e+13]=n[13],t[e+14]=n[14],t[e+15]=n[15],t}}const ei=new R,We=new Lt,Hh=new R(0,0,0),Gh=new R(1,1,1),Sn=new R,cs=new R,Ce=new R,yo=new Lt,So=new mn;class je{constructor(t=0,e=0,n=0,i=je.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=n,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,n,i=this._order){return this._x=t,this._y=e,this._z=n,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,n=!0){const i=t.elements,r=i[0],a=i[4],o=i[8],c=i[1],l=i[5],h=i[9],u=i[2],d=i[6],p=i[10];switch(e){case"XYZ":this._y=Math.asin(he(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,p),this._z=Math.atan2(-a,r)):(this._x=Math.atan2(d,l),this._z=0);break;case"YXZ":this._x=Math.asin(-he(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(o,p),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-u,r),this._z=0);break;case"ZXY":this._x=Math.asin(he(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,p),this._z=Math.atan2(-a,l)):(this._y=0,this._z=Math.atan2(c,r));break;case"ZYX":this._y=Math.asin(-he(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,p),this._z=Math.atan2(c,r)):(this._x=0,this._z=Math.atan2(-a,l));break;case"YZX":this._z=Math.asin(he(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-u,r)):(this._x=0,this._y=Math.atan2(o,p));break;case"XZY":this._z=Math.asin(-he(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(d,l),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-h,p),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,n===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,n){return yo.makeRotationFromQuaternion(t),this.setFromRotationMatrix(yo,e,n)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return So.setFromEuler(this),this.setFromQuaternion(So,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}je.DEFAULT_ORDER="XYZ";class qa{constructor(){this.mask=1}set(t){this.mask=(1<>>0}enable(t){this.mask|=1<1){for(let e=0;e1){for(let n=0;n0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(i.matrixAutoUpdate=!1),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.visibility=this._visibility,i.active=this._active,i.bounds=this._bounds.map(o=>({boxInitialized:o.boxInitialized,boxMin:o.box.min.toArray(),boxMax:o.box.max.toArray(),sphereInitialized:o.sphereInitialized,sphereRadius:o.sphere.radius,sphereCenter:o.sphere.center.toArray()})),i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.geometryCount=this._geometryCount,i.matricesTexture=this._matricesTexture.toJSON(t),this._colorsTexture!==null&&(i.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(i.boundingSphere={center:i.boundingSphere.center.toArray(),radius:i.boundingSphere.radius}),this.boundingBox!==null&&(i.boundingBox={min:i.boundingBox.min.toArray(),max:i.boundingBox.max.toArray()}));function r(o,c){return o[c.uuid]===void 0&&(o[c.uuid]=c.toJSON(t)),c.uuid}if(this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(i.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=r(t.geometries,this.geometry);const o=this.geometry.parameters;if(o!==void 0&&o.shapes!==void 0){const c=o.shapes;if(Array.isArray(c))for(let l=0,h=c.length;l0){i.children=[];for(let o=0;o0){i.animations=[];for(let o=0;o0&&(n.geometries=o),c.length>0&&(n.materials=c),l.length>0&&(n.textures=l),h.length>0&&(n.images=h),u.length>0&&(n.shapes=u),d.length>0&&(n.skeletons=d),p.length>0&&(n.animations=p),g.length>0&&(n.nodes=g)}return n.object=i,n;function a(o){const c=[];for(const l in o){const h=o[l];delete h.metadata,c.push(h)}return c}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let n=0;n0?i.multiplyScalar(1/Math.sqrt(r)):i.set(0,0,0)}static getBarycoord(t,e,n,i,r){Xe.subVectors(i,e),rn.subVectors(n,e),xr.subVectors(t,e);const a=Xe.dot(Xe),o=Xe.dot(rn),c=Xe.dot(xr),l=rn.dot(rn),h=rn.dot(xr),u=a*l-o*o;if(u===0)return r.set(0,0,0),null;const d=1/u,p=(l*c-o*h)*d,g=(a*h-o*c)*d;return r.set(1-p-g,g,p)}static containsPoint(t,e,n,i){return this.getBarycoord(t,e,n,i,an)===null?!1:an.x>=0&&an.y>=0&&an.x+an.y<=1}static getInterpolation(t,e,n,i,r,a,o,c){return this.getBarycoord(t,e,n,i,an)===null?(c.x=0,c.y=0,"z"in c&&(c.z=0),"w"in c&&(c.w=0),null):(c.setScalar(0),c.addScaledVector(r,an.x),c.addScaledVector(a,an.y),c.addScaledVector(o,an.z),c)}static getInterpolatedAttribute(t,e,n,i,r,a){return Sr.setScalar(0),Er.setScalar(0),br.setScalar(0),Sr.fromBufferAttribute(t,e),Er.fromBufferAttribute(t,n),br.fromBufferAttribute(t,i),a.setScalar(0),a.addScaledVector(Sr,r.x),a.addScaledVector(Er,r.y),a.addScaledVector(br,r.z),a}static isFrontFacing(t,e,n,i){return Xe.subVectors(n,e),rn.subVectors(t,e),Xe.cross(rn).dot(i)<0}set(t,e,n){return this.a.copy(t),this.b.copy(e),this.c.copy(n),this}setFromPointsAndIndices(t,e,n,i){return this.a.copy(t[e]),this.b.copy(t[n]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,n,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,n),this.c.fromBufferAttribute(t,i),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return Xe.subVectors(this.c,this.b),rn.subVectors(this.a,this.b),Xe.cross(rn).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Ve.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return Ve.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,n,i,r){return Ve.getInterpolation(t,this.a,this.b,this.c,e,n,i,r)}containsPoint(t){return Ve.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Ve.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const n=this.a,i=this.b,r=this.c;let a,o;si.subVectors(i,n),ri.subVectors(r,n),vr.subVectors(t,n);const c=si.dot(vr),l=ri.dot(vr);if(c<=0&&l<=0)return e.copy(n);Mr.subVectors(t,i);const h=si.dot(Mr),u=ri.dot(Mr);if(h>=0&&u<=h)return e.copy(i);const d=c*u-h*l;if(d<=0&&c>=0&&h<=0)return a=c/(c-h),e.copy(n).addScaledVector(si,a);yr.subVectors(t,r);const p=si.dot(yr),g=ri.dot(yr);if(g>=0&&p<=g)return e.copy(r);const _=p*l-c*g;if(_<=0&&l>=0&&g<=0)return o=l/(l-g),e.copy(n).addScaledVector(ri,o);const m=h*g-p*u;if(m<=0&&u-h>=0&&p-g>=0)return Ro.subVectors(r,i),o=(u-h)/(u-h+(p-g)),e.copy(i).addScaledVector(Ro,o);const f=1/(m+_+d);return a=_*f,o=d*f,e.copy(n).addScaledVector(si,a).addScaledVector(ri,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const qc={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},En={h:0,s:0,l:0},hs={h:0,s:0,l:0};function Tr(s,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?s+(t-s)*6*e:e<1/2?t:e<2/3?s+(t-s)*6*(2/3-e):s}class Et{constructor(t,e,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,n)}set(t,e,n){if(e===void 0&&n===void 0){const i=t;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}else this.setRGB(t,e,n);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=ze){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,Vt.toWorkingColorSpace(this,e),this}setRGB(t,e,n,i=Vt.workingColorSpace){return this.r=t,this.g=e,this.b=n,Vt.toWorkingColorSpace(this,i),this}setHSL(t,e,n,i=Vt.workingColorSpace){if(t=Xa(t,1),e=he(e,0,1),n=he(n,0,1),e===0)this.r=this.g=this.b=n;else{const r=n<=.5?n*(1+e):n+e-n*e,a=2*n-r;this.r=Tr(a,r,t+1/3),this.g=Tr(a,r,t),this.b=Tr(a,r,t-1/3)}return Vt.toWorkingColorSpace(this,i),this}setStyle(t,e=ze){function n(r){r!==void 0&&parseFloat(r)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(t)){let r;const a=i[1],o=i[2];switch(a){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,e);if(r=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,e);break;case"hsl":case"hsla":if(r=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(t)){const r=i[1],a=r.length;if(a===3)return this.setRGB(parseInt(r.charAt(0),16)/15,parseInt(r.charAt(1),16)/15,parseInt(r.charAt(2),16)/15,e);if(a===6)return this.setHex(parseInt(r,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=ze){const n=qc[t.toLowerCase()];return n!==void 0?this.setHex(n,e):console.warn("THREE.Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=pn(t.r),this.g=pn(t.g),this.b=pn(t.b),this}copyLinearToSRGB(t){return this.r=gi(t.r),this.g=gi(t.g),this.b=gi(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=ze){return Vt.fromWorkingColorSpace(_e.copy(this),t),Math.round(he(_e.r*255,0,255))*65536+Math.round(he(_e.g*255,0,255))*256+Math.round(he(_e.b*255,0,255))}getHexString(t=ze){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=Vt.workingColorSpace){Vt.fromWorkingColorSpace(_e.copy(this),e);const n=_e.r,i=_e.g,r=_e.b,a=Math.max(n,i,r),o=Math.min(n,i,r);let c,l;const h=(o+a)/2;if(o===a)c=0,l=0;else{const u=a-o;switch(l=h<=.5?u/(a+o):u/(2-a-o),a){case n:c=(i-r)/u+(i0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(t!==void 0)for(const e in t){const n=t[e];if(n===void 0){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}const i=this[e];if(i===void 0){console.warn(`THREE.Material: '${e}' is not a property of THREE.${this.type}.`);continue}i&&i.isColor?i.set(n):i&&i.isVector3&&n&&n.isVector3?i.copy(n):this[e]=n}}toJSON(t){const e=t===void 0||typeof t=="string";e&&(t={textures:{},images:{}});const n={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};n.uuid=this.uuid,n.type=this.type,this.name!==""&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),this.roughness!==void 0&&(n.roughness=this.roughness),this.metalness!==void 0&&(n.metalness=this.metalness),this.sheen!==void 0&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(n.shininess=this.shininess),this.clearcoat!==void 0&&(n.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.dispersion!==void 0&&(n.dispersion=this.dispersion),this.iridescence!==void 0&&(n.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(n.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),this.anisotropy!==void 0&&(n.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(t).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(t).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(t).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(t).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(t).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(t).uuid,this.combine!==void 0&&(n.combine=this.combine)),this.envMapRotation!==void 0&&(n.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(n.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(n.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(t).uuid),this.transmission!==void 0&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(t).uuid),this.thickness!==void 0&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(t).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(n.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(n.size=this.size),this.shadowSide!==null&&(n.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(n.sizeAttenuation=this.sizeAttenuation),this.blending!==pi&&(n.blending=this.blending),this.side!==Pn&&(n.side=this.side),this.vertexColors===!0&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),this.transparent===!0&&(n.transparent=!0),this.blendSrc!==qr&&(n.blendSrc=this.blendSrc),this.blendDst!==Yr&&(n.blendDst=this.blendDst),this.blendEquation!==qn&&(n.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(n.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(n.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(n.blendAlpha=this.blendAlpha),this.depthFunc!==xi&&(n.depthFunc=this.depthFunc),this.depthTest===!1&&(n.depthTest=this.depthTest),this.depthWrite===!1&&(n.depthWrite=this.depthWrite),this.colorWrite===!1&&(n.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(n.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==ho&&(n.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(n.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==Zn&&(n.stencilFail=this.stencilFail),this.stencilZFail!==Zn&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==Zn&&(n.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(n.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(n.rotation=this.rotation),this.polygonOffset===!0&&(n.polygonOffset=!0),this.polygonOffsetFactor!==0&&(n.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(n.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(n.linewidth=this.linewidth),this.dashSize!==void 0&&(n.dashSize=this.dashSize),this.gapSize!==void 0&&(n.gapSize=this.gapSize),this.scale!==void 0&&(n.scale=this.scale),this.dithering===!0&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),this.alphaHash===!0&&(n.alphaHash=!0),this.alphaToCoverage===!0&&(n.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(n.premultipliedAlpha=!0),this.forceSinglePass===!0&&(n.forceSinglePass=!0),this.wireframe===!0&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(n.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(n.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(n.flatShading=!0),this.visible===!1&&(n.visible=!1),this.toneMapped===!1&&(n.toneMapped=!1),this.fog===!1&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData);function i(r){const a=[];for(const o in r){const c=r[o];delete c.metadata,a.push(c)}return a}if(e){const r=i(t.textures),a=i(t.images);r.length>0&&(n.textures=r),a.length>0&&(n.images=a)}return n}clone(){return new this.constructor().copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let n=null;if(e!==null){const i=e.length;n=new Array(i);for(let r=0;r!==i;++r)n[r]=e[r].clone()}return this.clippingPlanes=n,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){t===!0&&this.version++}onBuild(){console.warn("Material: onBuild() has been removed.")}}class Yc extends Ke{static get type(){return"MeshBasicMaterial"}constructor(t){super(),this.isMeshBasicMaterial=!0,this.color=new Et(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new je,this.combine=Ba,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const un=Kh();function Kh(){const s=new ArrayBuffer(4),t=new Float32Array(s),e=new Uint32Array(s),n=new Uint32Array(512),i=new Uint32Array(512);for(let c=0;c<256;++c){const l=c-127;l<-27?(n[c]=0,n[c|256]=32768,i[c]=24,i[c|256]=24):l<-14?(n[c]=1024>>-l-14,n[c|256]=1024>>-l-14|32768,i[c]=-l-1,i[c|256]=-l-1):l<=15?(n[c]=l+15<<10,n[c|256]=l+15<<10|32768,i[c]=13,i[c|256]=13):l<128?(n[c]=31744,n[c|256]=64512,i[c]=24,i[c|256]=24):(n[c]=31744,n[c|256]=64512,i[c]=13,i[c|256]=13)}const r=new Uint32Array(2048),a=new Uint32Array(64),o=new Uint32Array(64);for(let c=1;c<1024;++c){let l=c<<13,h=0;for(;!(l&8388608);)l<<=1,h-=8388608;l&=-8388609,h+=947912704,r[c]=l|h}for(let c=1024;c<2048;++c)r[c]=939524096+(c-1024<<13);for(let c=1;c<31;++c)a[c]=c<<23;a[31]=1199570944,a[32]=2147483648;for(let c=33;c<63;++c)a[c]=2147483648+(c-32<<23);a[63]=3347054592;for(let c=1;c<64;++c)c!==32&&(o[c]=1024);return{floatView:t,uint32View:e,baseTable:n,shiftTable:i,mantissaTable:r,exponentTable:a,offsetTable:o}}function Zh(s){Math.abs(s)>65504&&console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."),s=he(s,-65504,65504),un.floatView[0]=s;const t=un.uint32View[0],e=t>>23&511;return un.baseTable[e]+((t&8388607)>>un.shiftTable[e])}function $h(s){const t=s>>10;return un.uint32View[0]=un.mantissaTable[un.offsetTable[t]+(s&1023)]+un.exponentTable[t],un.floatView[0]}const jg={toHalfFloat:Zh,fromHalfFloat:$h},le=new R,us=new Pt;class pe{constructor(t,e,n=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=n,this.usage=La,this.updateRanges=[],this.gpuType=De,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,n){t*=this.itemSize,n*=e.itemSize;for(let i=0,r=this.itemSize;ie.count&&console.warn("THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Ne);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new R(-1/0,-1/0,-1/0),new R(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let n=0,i=e.length;n0&&(t.userData=this.userData),this.parameters!==void 0){const c=this.parameters;for(const l in c)c[l]!==void 0&&(t[l]=c[l]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const n=this.attributes;for(const c in n){const l=n[c];t.data.attributes[c]=l.toJSON(t.data)}const i={};let r=!1;for(const c in this.morphAttributes){const l=this.morphAttributes[c],h=[];for(let u=0,d=l.length;u0&&(i[c]=h,r=!0)}r&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const a=this.groups;a.length>0&&(t.data.groups=JSON.parse(JSON.stringify(a)));const o=this.boundingSphere;return o!==null&&(t.data.boundingSphere={center:o.center.toArray(),radius:o.radius}),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const n=t.index;n!==null&&this.setIndex(n.clone(e));const i=t.attributes;for(const l in i){const h=i[l];this.setAttribute(l,h.clone(e))}const r=t.morphAttributes;for(const l in r){const h=[],u=r[l];for(let d=0,p=u.length;d0){const i=e[n[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let r=0,a=i.length;r(t.far-t.near)**2))&&(Co.copy(r).invert(),zn.copy(t.ray).applyMatrix4(Co),!(n.boundingBox!==null&&zn.intersectsBox(n.boundingBox)===!1)&&this._computeIntersections(t,e,zn)))}_computeIntersections(t,e,n){let i;const r=this.geometry,a=this.material,o=r.index,c=r.attributes.position,l=r.attributes.uv,h=r.attributes.uv1,u=r.attributes.normal,d=r.groups,p=r.drawRange;if(o!==null)if(Array.isArray(a))for(let g=0,_=d.length;g<_;g++){const m=d[g],f=a[m.materialIndex],b=Math.max(m.start,p.start),E=Math.min(o.count,Math.min(m.start+m.count,p.start+p.count));for(let x=b,P=E;xe.far?null:{distance:l,point:_s.clone(),object:s}}function xs(s,t,e,n,i,r,a,o,c,l){s.getVertexPosition(o,fs),s.getVertexPosition(c,ps),s.getVertexPosition(l,ms);const h=Qh(s,t,e,n,fs,ps,ms,Po);if(h){const u=new R;Ve.getBarycoord(Po,fs,ps,ms,u),i&&(h.uv=Ve.getInterpolatedAttribute(i,o,c,l,u,new Pt)),r&&(h.uv1=Ve.getInterpolatedAttribute(r,o,c,l,u,new Pt)),a&&(h.normal=Ve.getInterpolatedAttribute(a,o,c,l,u,new R),h.normal.dot(n.direction)>0&&h.normal.multiplyScalar(-1));const d={a:o,b:c,c:l,normal:new R,materialIndex:0};Ve.getNormal(fs,ps,ms,d.normal),h.face=d,h.barycoord=u}return h}class $i extends ce{constructor(t=1,e=1,n=1,i=1,r=1,a=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:n,widthSegments:i,heightSegments:r,depthSegments:a};const o=this;i=Math.floor(i),r=Math.floor(r),a=Math.floor(a);const c=[],l=[],h=[],u=[];let d=0,p=0;g("z","y","x",-1,-1,n,e,t,a,r,0),g("z","y","x",1,-1,n,e,-t,a,r,1),g("x","z","y",1,1,t,n,e,i,a,2),g("x","z","y",1,-1,t,n,-e,i,a,3),g("x","y","z",1,-1,t,e,n,i,r,4),g("x","y","z",-1,-1,t,e,-n,i,r,5),this.setIndex(c),this.setAttribute("position",new Wt(l,3)),this.setAttribute("normal",new Wt(h,3)),this.setAttribute("uv",new Wt(u,2));function g(_,m,f,b,E,x,P,A,w,C,y){const v=x/w,I=P/C,V=x/2,B=P/2,G=A/2,K=w+1,W=C+1;let Q=0,H=0;const it=new R;for(let lt=0;lt0?1:-1,h.push(it.x,it.y,it.z),u.push(Nt/w),u.push(1-lt/C),Q+=1}}for(let lt=0;lt0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;const n={};for(const i in this.extensions)this.extensions[i]===!0&&(n[i]=!0);return Object.keys(n).length>0&&(e.extensions=n),e}}class $c extends ae{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new Lt,this.projectionMatrix=new Lt,this.projectionMatrixInverse=new Lt,this.coordinateSystem=fn}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this.coordinateSystem=t.coordinateSystem,this}getWorldDirection(t){return super.getWorldDirection(t).negate()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return new this.constructor().copy(this)}}const bn=new R,Lo=new Pt,Do=new Pt;class Pe extends $c{constructor(t=50,e=1,n=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=n,this.far=i,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=t.view===null?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=Ei*2*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(Gi*.5*this.fov);return .5*this.getFilmHeight()/t}getEffectiveFOV(){return Ei*2*Math.atan(Math.tan(Gi*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(t,e,n){bn.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(bn.x,bn.y).multiplyScalar(-t/bn.z),bn.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set(bn.x,bn.y).multiplyScalar(-t/bn.z)}getViewSize(t,e){return this.getViewBounds(t,Lo,Do),e.subVectors(Do,Lo)}setViewOffset(t,e,n,i,r,a){this.aspect=t/e,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=n,this.view.offsetY=i,this.view.width=r,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(Gi*.5*this.fov)/this.zoom,n=2*e,i=this.aspect*n,r=-.5*i;const a=this.view;if(this.view!==null&&this.view.enabled){const c=a.fullWidth,l=a.fullHeight;r+=a.offsetX*i/c,e-=a.offsetY*n/l,i*=a.width/c,n*=a.height/l}const o=this.filmOffset;o!==0&&(r+=t*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+i,e,e-n,t,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,this.view!==null&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}const oi=-90,ci=1;class su extends ae{constructor(t,e,n){super(),this.type="CubeCamera",this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new Pe(oi,ci,t,e);i.layers=this.layers,this.add(i);const r=new Pe(oi,ci,t,e);r.layers=this.layers,this.add(r);const a=new Pe(oi,ci,t,e);a.layers=this.layers,this.add(a);const o=new Pe(oi,ci,t,e);o.layers=this.layers,this.add(o);const c=new Pe(oi,ci,t,e);c.layers=this.layers,this.add(c);const l=new Pe(oi,ci,t,e);l.layers=this.layers,this.add(l)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[n,i,r,a,o,c]=e;for(const l of e)this.remove(l);if(t===fn)n.up.set(0,1,0),n.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),r.up.set(0,0,-1),r.lookAt(0,1,0),a.up.set(0,0,1),a.lookAt(0,-1,0),o.up.set(0,1,0),o.lookAt(0,0,1),c.up.set(0,1,0),c.lookAt(0,0,-1);else if(t===Ws)n.up.set(0,-1,0),n.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),r.up.set(0,0,1),r.lookAt(0,1,0),a.up.set(0,0,-1),a.lookAt(0,-1,0),o.up.set(0,-1,0),o.lookAt(0,0,1),c.up.set(0,-1,0),c.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);for(const l of e)this.add(l),l.updateMatrixWorld()}update(t,e){this.parent===null&&this.updateMatrixWorld();const{renderTarget:n,activeMipmapLevel:i}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[r,a,o,c,l,h]=this.children,u=t.getRenderTarget(),d=t.getActiveCubeFace(),p=t.getActiveMipmapLevel(),g=t.xr.enabled;t.xr.enabled=!1;const _=n.texture.generateMipmaps;n.texture.generateMipmaps=!1,t.setRenderTarget(n,0,i),t.render(e,r),t.setRenderTarget(n,1,i),t.render(e,a),t.setRenderTarget(n,2,i),t.render(e,o),t.setRenderTarget(n,3,i),t.render(e,c),t.setRenderTarget(n,4,i),t.render(e,l),n.texture.generateMipmaps=_,t.setRenderTarget(n,5,i),t.render(e,h),t.setRenderTarget(u,d,p),t.xr.enabled=g,n.texture.needsPMREMUpdate=!0}}class Jc extends ve{constructor(t,e,n,i,r,a,o,c,l,h){t=t!==void 0?t:[],e=e!==void 0?e:vi,super(t,e,n,i,r,a,o,c,l,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class ru extends Dn{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const n={width:t,height:t,depth:1},i=[n,n,n,n,n,n];this.texture=new Jc(i,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=e.generateMipmaps!==void 0?e.generateMipmaps:!1,this.texture.minFilter=e.minFilter!==void 0?e.minFilter:Le}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const n={uniforms:{tEquirect:{value:null}},vertexShader:` + + varying vec3 vWorldDirection; + + vec3 transformDirection( in vec3 dir, in mat4 matrix ) { + + return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz ); + + } + + void main() { + + vWorldDirection = transformDirection( position, modelMatrix ); + + #include + #include + + } + `,fragmentShader:` + + uniform sampler2D tEquirect; + + varying vec3 vWorldDirection; + + #include + + void main() { + + vec3 direction = normalize( vWorldDirection ); + + vec2 sampleUV = equirectUv( direction ); + + gl_FragColor = texture2D( tEquirect, sampleUV ); + + } + `},i=new $i(5,5,5),r=new Un({name:"CubemapFromEquirect",uniforms:bi(n.uniforms),vertexShader:n.vertexShader,fragmentShader:n.fragmentShader,side:Ae,blending:Cn});r.uniforms.tEquirect.value=e;const a=new Te(i,r),o=e.minFilter;return e.minFilter===wn&&(e.minFilter=Le),new su(1,10,this).update(t,a),e.minFilter=o,a.geometry.dispose(),a.material.dispose(),this}clear(t,e,n,i){const r=t.getRenderTarget();for(let a=0;a<6;a++)t.setRenderTarget(this,a),t.clear(e,n,i);t.setRenderTarget(r)}}const Rr=new R,au=new R,ou=new It;class ln{constructor(t=new R(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,n,i){return this.normal.set(t,e,n),this.constant=i,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,n){const i=Rr.subVectors(n,e).cross(au.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(i,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const n=t.delta(Rr),i=this.normal.dot(n);if(i===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const r=-(t.start.dot(this.normal)+this.constant)/i;return r<0||r>1?null:e.copy(t.start).addScaledVector(n,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),n=this.distanceToPoint(t.end);return e<0&&n>0||n<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const n=e||ou.getNormalMatrix(t),i=this.coplanarPoint(Rr).applyMatrix4(t),r=this.normal.applyMatrix3(n).normalize();return this.constant=-i.dot(r),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return new this.constructor().copy(this)}}const Vn=new we,vs=new R;class Qs{constructor(t=new ln,e=new ln,n=new ln,i=new ln,r=new ln,a=new ln){this.planes=[t,e,n,i,r,a]}set(t,e,n,i,r,a){const o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(n),o[3].copy(i),o[4].copy(r),o[5].copy(a),this}copy(t){const e=this.planes;for(let n=0;n<6;n++)e[n].copy(t.planes[n]);return this}setFromProjectionMatrix(t,e=fn){const n=this.planes,i=t.elements,r=i[0],a=i[1],o=i[2],c=i[3],l=i[4],h=i[5],u=i[6],d=i[7],p=i[8],g=i[9],_=i[10],m=i[11],f=i[12],b=i[13],E=i[14],x=i[15];if(n[0].setComponents(c-r,d-l,m-p,x-f).normalize(),n[1].setComponents(c+r,d+l,m+p,x+f).normalize(),n[2].setComponents(c+a,d+h,m+g,x+b).normalize(),n[3].setComponents(c-a,d-h,m-g,x-b).normalize(),n[4].setComponents(c-o,d-u,m-_,x-E).normalize(),e===fn)n[5].setComponents(c+o,d+u,m+_,x+E).normalize();else if(e===Ws)n[5].setComponents(o,u,_,E).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);return this}intersectsObject(t){if(t.boundingSphere!==void 0)t.boundingSphere===null&&t.computeBoundingSphere(),Vn.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;e.boundingSphere===null&&e.computeBoundingSphere(),Vn.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(Vn)}intersectsSprite(t){return Vn.center.set(0,0,0),Vn.radius=.7071067811865476,Vn.applyMatrix4(t.matrixWorld),this.intersectsSphere(Vn)}intersectsSphere(t){const e=this.planes,n=t.center,i=-t.radius;for(let r=0;r<6;r++)if(e[r].distanceToPoint(n)0?t.max.x:t.min.x,vs.y=i.normal.y>0?t.max.y:t.min.y,vs.z=i.normal.z>0?t.max.z:t.min.z,i.distanceToPoint(vs)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let n=0;n<6;n++)if(e[n].distanceToPoint(t)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}function Qc(){let s=null,t=!1,e=null,n=null;function i(r,a){e(r,a),n=s.requestAnimationFrame(i)}return{start:function(){t!==!0&&e!==null&&(n=s.requestAnimationFrame(i),t=!0)},stop:function(){s.cancelAnimationFrame(n),t=!1},setAnimationLoop:function(r){e=r},setContext:function(r){s=r}}}function cu(s){const t=new WeakMap;function e(o,c){const l=o.array,h=o.usage,u=l.byteLength,d=s.createBuffer();s.bindBuffer(c,d),s.bufferData(c,l,h),o.onUploadCallback();let p;if(l instanceof Float32Array)p=s.FLOAT;else if(l instanceof Uint16Array)o.isFloat16BufferAttribute?p=s.HALF_FLOAT:p=s.UNSIGNED_SHORT;else if(l instanceof Int16Array)p=s.SHORT;else if(l instanceof Uint32Array)p=s.UNSIGNED_INT;else if(l instanceof Int32Array)p=s.INT;else if(l instanceof Int8Array)p=s.BYTE;else if(l instanceof Uint8Array)p=s.UNSIGNED_BYTE;else if(l instanceof Uint8ClampedArray)p=s.UNSIGNED_BYTE;else throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: "+l);return{buffer:d,type:p,bytesPerElement:l.BYTES_PER_ELEMENT,version:o.version,size:u}}function n(o,c,l){const h=c.array,u=c.updateRanges;if(s.bindBuffer(l,o),u.length===0)s.bufferSubData(l,0,h);else{u.sort((p,g)=>p.start-g.start);let d=0;for(let p=1;p 0 + vec4 plane; + #ifdef ALPHA_TO_COVERAGE + float distanceToPlane, distanceGradient; + float clipOpacity = 1.0; + #pragma unroll_loop_start + for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) { + plane = clippingPlanes[ i ]; + distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w; + distanceGradient = fwidth( distanceToPlane ) / 2.0; + clipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane ); + if ( clipOpacity == 0.0 ) discard; + } + #pragma unroll_loop_end + #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES + float unionClipOpacity = 1.0; + #pragma unroll_loop_start + for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) { + plane = clippingPlanes[ i ]; + distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w; + distanceGradient = fwidth( distanceToPlane ) / 2.0; + unionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane ); + } + #pragma unroll_loop_end + clipOpacity *= 1.0 - unionClipOpacity; + #endif + diffuseColor.a *= clipOpacity; + if ( diffuseColor.a == 0.0 ) discard; + #else + #pragma unroll_loop_start + for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) { + plane = clippingPlanes[ i ]; + if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard; + } + #pragma unroll_loop_end + #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES + bool clipped = true; + #pragma unroll_loop_start + for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) { + plane = clippingPlanes[ i ]; + clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped; + } + #pragma unroll_loop_end + if ( clipped ) discard; + #endif + #endif +#endif`,Tu=`#if NUM_CLIPPING_PLANES > 0 + varying vec3 vClipPosition; + uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ]; +#endif`,Au=`#if NUM_CLIPPING_PLANES > 0 + varying vec3 vClipPosition; +#endif`,wu=`#if NUM_CLIPPING_PLANES > 0 + vClipPosition = - mvPosition.xyz; +#endif`,Ru=`#if defined( USE_COLOR_ALPHA ) + diffuseColor *= vColor; +#elif defined( USE_COLOR ) + diffuseColor.rgb *= vColor; +#endif`,Cu=`#if defined( USE_COLOR_ALPHA ) + varying vec4 vColor; +#elif defined( USE_COLOR ) + varying vec3 vColor; +#endif`,Iu=`#if defined( USE_COLOR_ALPHA ) + varying vec4 vColor; +#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR ) + varying vec3 vColor; +#endif`,Pu=`#if defined( USE_COLOR_ALPHA ) + vColor = vec4( 1.0 ); +#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR ) + vColor = vec3( 1.0 ); +#endif +#ifdef USE_COLOR + vColor *= color; +#endif +#ifdef USE_INSTANCING_COLOR + vColor.xyz *= instanceColor.xyz; +#endif +#ifdef USE_BATCHING_COLOR + vec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) ); + vColor.xyz *= batchingColor.xyz; +#endif`,Lu=`#define PI 3.141592653589793 +#define PI2 6.283185307179586 +#define PI_HALF 1.5707963267948966 +#define RECIPROCAL_PI 0.3183098861837907 +#define RECIPROCAL_PI2 0.15915494309189535 +#define EPSILON 1e-6 +#ifndef saturate +#define saturate( a ) clamp( a, 0.0, 1.0 ) +#endif +#define whiteComplement( a ) ( 1.0 - saturate( a ) ) +float pow2( const in float x ) { return x*x; } +vec3 pow2( const in vec3 x ) { return x*x; } +float pow3( const in float x ) { return x*x*x; } +float pow4( const in float x ) { float x2 = x*x; return x2*x2; } +float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); } +float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); } +highp float rand( const in vec2 uv ) { + const highp float a = 12.9898, b = 78.233, c = 43758.5453; + highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI ); + return fract( sin( sn ) * c ); +} +#ifdef HIGH_PRECISION + float precisionSafeLength( vec3 v ) { return length( v ); } +#else + float precisionSafeLength( vec3 v ) { + float maxComponent = max3( abs( v ) ); + return length( v / maxComponent ) * maxComponent; + } +#endif +struct IncidentLight { + vec3 color; + vec3 direction; + bool visible; +}; +struct ReflectedLight { + vec3 directDiffuse; + vec3 directSpecular; + vec3 indirectDiffuse; + vec3 indirectSpecular; +}; +#ifdef USE_ALPHAHASH + varying vec3 vPosition; +#endif +vec3 transformDirection( in vec3 dir, in mat4 matrix ) { + return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz ); +} +vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) { + return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz ); +} +mat3 transposeMat3( const in mat3 m ) { + mat3 tmp; + tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x ); + tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y ); + tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z ); + return tmp; +} +bool isPerspectiveMatrix( mat4 m ) { + return m[ 2 ][ 3 ] == - 1.0; +} +vec2 equirectUv( in vec3 dir ) { + float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5; + float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5; + return vec2( u, v ); +} +vec3 BRDF_Lambert( const in vec3 diffuseColor ) { + return RECIPROCAL_PI * diffuseColor; +} +vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) { + float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH ); + return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel ); +} +float F_Schlick( const in float f0, const in float f90, const in float dotVH ) { + float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH ); + return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel ); +} // validated`,Du=`#ifdef ENVMAP_TYPE_CUBE_UV + #define cubeUV_minMipLevel 4.0 + #define cubeUV_minTileSize 16.0 + float getFace( vec3 direction ) { + vec3 absDirection = abs( direction ); + float face = - 1.0; + if ( absDirection.x > absDirection.z ) { + if ( absDirection.x > absDirection.y ) + face = direction.x > 0.0 ? 0.0 : 3.0; + else + face = direction.y > 0.0 ? 1.0 : 4.0; + } else { + if ( absDirection.z > absDirection.y ) + face = direction.z > 0.0 ? 2.0 : 5.0; + else + face = direction.y > 0.0 ? 1.0 : 4.0; + } + return face; + } + vec2 getUV( vec3 direction, float face ) { + vec2 uv; + if ( face == 0.0 ) { + uv = vec2( direction.z, direction.y ) / abs( direction.x ); + } else if ( face == 1.0 ) { + uv = vec2( - direction.x, - direction.z ) / abs( direction.y ); + } else if ( face == 2.0 ) { + uv = vec2( - direction.x, direction.y ) / abs( direction.z ); + } else if ( face == 3.0 ) { + uv = vec2( - direction.z, direction.y ) / abs( direction.x ); + } else if ( face == 4.0 ) { + uv = vec2( - direction.x, direction.z ) / abs( direction.y ); + } else { + uv = vec2( direction.x, direction.y ) / abs( direction.z ); + } + return 0.5 * ( uv + 1.0 ); + } + vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) { + float face = getFace( direction ); + float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 ); + mipInt = max( mipInt, cubeUV_minMipLevel ); + float faceSize = exp2( mipInt ); + highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0; + if ( face > 2.0 ) { + uv.y += faceSize; + face -= 3.0; + } + uv.x += face * faceSize; + uv.x += filterInt * 3.0 * cubeUV_minTileSize; + uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize ); + uv.x *= CUBEUV_TEXEL_WIDTH; + uv.y *= CUBEUV_TEXEL_HEIGHT; + #ifdef texture2DGradEXT + return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb; + #else + return texture2D( envMap, uv ).rgb; + #endif + } + #define cubeUV_r0 1.0 + #define cubeUV_m0 - 2.0 + #define cubeUV_r1 0.8 + #define cubeUV_m1 - 1.0 + #define cubeUV_r4 0.4 + #define cubeUV_m4 2.0 + #define cubeUV_r5 0.305 + #define cubeUV_m5 3.0 + #define cubeUV_r6 0.21 + #define cubeUV_m6 4.0 + float roughnessToMip( float roughness ) { + float mip = 0.0; + if ( roughness >= cubeUV_r1 ) { + mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0; + } else if ( roughness >= cubeUV_r4 ) { + mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1; + } else if ( roughness >= cubeUV_r5 ) { + mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4; + } else if ( roughness >= cubeUV_r6 ) { + mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5; + } else { + mip = - 2.0 * log2( 1.16 * roughness ); } + return mip; + } + vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) { + float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP ); + float mipF = fract( mip ); + float mipInt = floor( mip ); + vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt ); + if ( mipF == 0.0 ) { + return vec4( color0, 1.0 ); + } else { + vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 ); + return vec4( mix( color0, color1, mipF ), 1.0 ); + } + } +#endif`,Uu=`vec3 transformedNormal = objectNormal; +#ifdef USE_TANGENT + vec3 transformedTangent = objectTangent; +#endif +#ifdef USE_BATCHING + mat3 bm = mat3( batchingMatrix ); + transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) ); + transformedNormal = bm * transformedNormal; + #ifdef USE_TANGENT + transformedTangent = bm * transformedTangent; + #endif +#endif +#ifdef USE_INSTANCING + mat3 im = mat3( instanceMatrix ); + transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) ); + transformedNormal = im * transformedNormal; + #ifdef USE_TANGENT + transformedTangent = im * transformedTangent; + #endif +#endif +transformedNormal = normalMatrix * transformedNormal; +#ifdef FLIP_SIDED + transformedNormal = - transformedNormal; +#endif +#ifdef USE_TANGENT + transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz; + #ifdef FLIP_SIDED + transformedTangent = - transformedTangent; + #endif +#endif`,Nu=`#ifdef USE_DISPLACEMENTMAP + uniform sampler2D displacementMap; + uniform float displacementScale; + uniform float displacementBias; +#endif`,Fu=`#ifdef USE_DISPLACEMENTMAP + transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias ); +#endif`,Bu=`#ifdef USE_EMISSIVEMAP + vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv ); + #ifdef DECODE_VIDEO_TEXTURE_EMISSIVE + emissiveColor = sRGBTransferEOTF( emissiveColor ); + #endif + totalEmissiveRadiance *= emissiveColor.rgb; +#endif`,Ou=`#ifdef USE_EMISSIVEMAP + uniform sampler2D emissiveMap; +#endif`,zu="gl_FragColor = linearToOutputTexel( gl_FragColor );",Vu=`vec4 LinearTransferOETF( in vec4 value ) { + return value; +} +vec4 sRGBTransferEOTF( in vec4 value ) { + return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a ); +} +vec4 sRGBTransferOETF( in vec4 value ) { + return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a ); +}`,ku=`#ifdef USE_ENVMAP + #ifdef ENV_WORLDPOS + vec3 cameraToFrag; + if ( isOrthographic ) { + cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) ); + } else { + cameraToFrag = normalize( vWorldPosition - cameraPosition ); + } + vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); + #ifdef ENVMAP_MODE_REFLECTION + vec3 reflectVec = reflect( cameraToFrag, worldNormal ); + #else + vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio ); + #endif + #else + vec3 reflectVec = vReflect; + #endif + #ifdef ENVMAP_TYPE_CUBE + vec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) ); + #else + vec4 envColor = vec4( 0.0 ); + #endif + #ifdef ENVMAP_BLENDING_MULTIPLY + outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity ); + #elif defined( ENVMAP_BLENDING_MIX ) + outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity ); + #elif defined( ENVMAP_BLENDING_ADD ) + outgoingLight += envColor.xyz * specularStrength * reflectivity; + #endif +#endif`,Hu=`#ifdef USE_ENVMAP + uniform float envMapIntensity; + uniform float flipEnvMap; + uniform mat3 envMapRotation; + #ifdef ENVMAP_TYPE_CUBE + uniform samplerCube envMap; + #else + uniform sampler2D envMap; + #endif + +#endif`,Gu=`#ifdef USE_ENVMAP + uniform float reflectivity; + #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT ) + #define ENV_WORLDPOS + #endif + #ifdef ENV_WORLDPOS + varying vec3 vWorldPosition; + uniform float refractionRatio; + #else + varying vec3 vReflect; + #endif +#endif`,Wu=`#ifdef USE_ENVMAP + #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT ) + #define ENV_WORLDPOS + #endif + #ifdef ENV_WORLDPOS + + varying vec3 vWorldPosition; + #else + varying vec3 vReflect; + uniform float refractionRatio; + #endif +#endif`,Xu=`#ifdef USE_ENVMAP + #ifdef ENV_WORLDPOS + vWorldPosition = worldPosition.xyz; + #else + vec3 cameraToVertex; + if ( isOrthographic ) { + cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) ); + } else { + cameraToVertex = normalize( worldPosition.xyz - cameraPosition ); + } + vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix ); + #ifdef ENVMAP_MODE_REFLECTION + vReflect = reflect( cameraToVertex, worldNormal ); + #else + vReflect = refract( cameraToVertex, worldNormal, refractionRatio ); + #endif + #endif +#endif`,qu=`#ifdef USE_FOG + vFogDepth = - mvPosition.z; +#endif`,Yu=`#ifdef USE_FOG + varying float vFogDepth; +#endif`,ju=`#ifdef USE_FOG + #ifdef FOG_EXP2 + float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth ); + #else + float fogFactor = smoothstep( fogNear, fogFar, vFogDepth ); + #endif + gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor ); +#endif`,Ku=`#ifdef USE_FOG + uniform vec3 fogColor; + varying float vFogDepth; + #ifdef FOG_EXP2 + uniform float fogDensity; + #else + uniform float fogNear; + uniform float fogFar; + #endif +#endif`,Zu=`#ifdef USE_GRADIENTMAP + uniform sampler2D gradientMap; +#endif +vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) { + float dotNL = dot( normal, lightDirection ); + vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 ); + #ifdef USE_GRADIENTMAP + return vec3( texture2D( gradientMap, coord ).r ); + #else + vec2 fw = fwidth( coord ) * 0.5; + return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) ); + #endif +}`,$u=`#ifdef USE_LIGHTMAP + uniform sampler2D lightMap; + uniform float lightMapIntensity; +#endif`,Ju=`LambertMaterial material; +material.diffuseColor = diffuseColor.rgb; +material.specularStrength = specularStrength;`,Qu=`varying vec3 vViewPosition; +struct LambertMaterial { + vec3 diffuseColor; + float specularStrength; +}; +void RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) { + float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); + vec3 irradiance = dotNL * directLight.color; + reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) { + reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +#define RE_Direct RE_Direct_Lambert +#define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert`,td=`uniform bool receiveShadow; +uniform vec3 ambientLightColor; +#if defined( USE_LIGHT_PROBES ) + uniform vec3 lightProbe[ 9 ]; +#endif +vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) { + float x = normal.x, y = normal.y, z = normal.z; + vec3 result = shCoefficients[ 0 ] * 0.886227; + result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y; + result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z; + result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x; + result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y; + result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z; + result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 ); + result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z; + result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y ); + return result; +} +vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) { + vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); + vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe ); + return irradiance; +} +vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) { + vec3 irradiance = ambientLightColor; + return irradiance; +} +float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) { + float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 ); + if ( cutoffDistance > 0.0 ) { + distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) ); + } + return distanceFalloff; +} +float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) { + return smoothstep( coneCosine, penumbraCosine, angleCosine ); +} +#if NUM_DIR_LIGHTS > 0 + struct DirectionalLight { + vec3 direction; + vec3 color; + }; + uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ]; + void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) { + light.color = directionalLight.color; + light.direction = directionalLight.direction; + light.visible = true; + } +#endif +#if NUM_POINT_LIGHTS > 0 + struct PointLight { + vec3 position; + vec3 color; + float distance; + float decay; + }; + uniform PointLight pointLights[ NUM_POINT_LIGHTS ]; + void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) { + vec3 lVector = pointLight.position - geometryPosition; + light.direction = normalize( lVector ); + float lightDistance = length( lVector ); + light.color = pointLight.color; + light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay ); + light.visible = ( light.color != vec3( 0.0 ) ); + } +#endif +#if NUM_SPOT_LIGHTS > 0 + struct SpotLight { + vec3 position; + vec3 direction; + vec3 color; + float distance; + float decay; + float coneCos; + float penumbraCos; + }; + uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ]; + void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) { + vec3 lVector = spotLight.position - geometryPosition; + light.direction = normalize( lVector ); + float angleCos = dot( light.direction, spotLight.direction ); + float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos ); + if ( spotAttenuation > 0.0 ) { + float lightDistance = length( lVector ); + light.color = spotLight.color * spotAttenuation; + light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay ); + light.visible = ( light.color != vec3( 0.0 ) ); + } else { + light.color = vec3( 0.0 ); + light.visible = false; + } + } +#endif +#if NUM_RECT_AREA_LIGHTS > 0 + struct RectAreaLight { + vec3 color; + vec3 position; + vec3 halfWidth; + vec3 halfHeight; + }; + uniform sampler2D ltc_1; uniform sampler2D ltc_2; + uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ]; +#endif +#if NUM_HEMI_LIGHTS > 0 + struct HemisphereLight { + vec3 direction; + vec3 skyColor; + vec3 groundColor; + }; + uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ]; + vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) { + float dotNL = dot( normal, hemiLight.direction ); + float hemiDiffuseWeight = 0.5 * dotNL + 0.5; + vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight ); + return irradiance; + } +#endif`,ed=`#ifdef USE_ENVMAP + vec3 getIBLIrradiance( const in vec3 normal ) { + #ifdef ENVMAP_TYPE_CUBE_UV + vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); + vec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 ); + return PI * envMapColor.rgb * envMapIntensity; + #else + return vec3( 0.0 ); + #endif + } + vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) { + #ifdef ENVMAP_TYPE_CUBE_UV + vec3 reflectVec = reflect( - viewDir, normal ); + reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) ); + reflectVec = inverseTransformDirection( reflectVec, viewMatrix ); + vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness ); + return envMapColor.rgb * envMapIntensity; + #else + return vec3( 0.0 ); + #endif + } + #ifdef USE_ANISOTROPY + vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) { + #ifdef ENVMAP_TYPE_CUBE_UV + vec3 bentNormal = cross( bitangent, viewDir ); + bentNormal = normalize( cross( bentNormal, bitangent ) ); + bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) ); + return getIBLRadiance( viewDir, bentNormal, roughness ); + #else + return vec3( 0.0 ); + #endif + } + #endif +#endif`,nd=`ToonMaterial material; +material.diffuseColor = diffuseColor.rgb;`,id=`varying vec3 vViewPosition; +struct ToonMaterial { + vec3 diffuseColor; +}; +void RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) { + vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color; + reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) { + reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +#define RE_Direct RE_Direct_Toon +#define RE_IndirectDiffuse RE_IndirectDiffuse_Toon`,sd=`BlinnPhongMaterial material; +material.diffuseColor = diffuseColor.rgb; +material.specularColor = specular; +material.specularShininess = shininess; +material.specularStrength = specularStrength;`,rd=`varying vec3 vViewPosition; +struct BlinnPhongMaterial { + vec3 diffuseColor; + vec3 specularColor; + float specularShininess; + float specularStrength; +}; +void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) { + float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); + vec3 irradiance = dotNL * directLight.color; + reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); + reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength; +} +void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) { + reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +#define RE_Direct RE_Direct_BlinnPhong +#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong`,ad=`PhysicalMaterial material; +material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor ); +vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) ); +float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z ); +material.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness; +material.roughness = min( material.roughness, 1.0 ); +#ifdef IOR + material.ior = ior; + #ifdef USE_SPECULAR + float specularIntensityFactor = specularIntensity; + vec3 specularColorFactor = specularColor; + #ifdef USE_SPECULAR_COLORMAP + specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb; + #endif + #ifdef USE_SPECULAR_INTENSITYMAP + specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a; + #endif + material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor ); + #else + float specularIntensityFactor = 1.0; + vec3 specularColorFactor = vec3( 1.0 ); + material.specularF90 = 1.0; + #endif + material.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor ); +#else + material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor ); + material.specularF90 = 1.0; +#endif +#ifdef USE_CLEARCOAT + material.clearcoat = clearcoat; + material.clearcoatRoughness = clearcoatRoughness; + material.clearcoatF0 = vec3( 0.04 ); + material.clearcoatF90 = 1.0; + #ifdef USE_CLEARCOATMAP + material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x; + #endif + #ifdef USE_CLEARCOAT_ROUGHNESSMAP + material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y; + #endif + material.clearcoat = saturate( material.clearcoat ); material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 ); + material.clearcoatRoughness += geometryRoughness; + material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 ); +#endif +#ifdef USE_DISPERSION + material.dispersion = dispersion; +#endif +#ifdef USE_IRIDESCENCE + material.iridescence = iridescence; + material.iridescenceIOR = iridescenceIOR; + #ifdef USE_IRIDESCENCEMAP + material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r; + #endif + #ifdef USE_IRIDESCENCE_THICKNESSMAP + material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum; + #else + material.iridescenceThickness = iridescenceThicknessMaximum; + #endif +#endif +#ifdef USE_SHEEN + material.sheenColor = sheenColor; + #ifdef USE_SHEEN_COLORMAP + material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb; + #endif + material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 ); + #ifdef USE_SHEEN_ROUGHNESSMAP + material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a; + #endif +#endif +#ifdef USE_ANISOTROPY + #ifdef USE_ANISOTROPYMAP + mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x ); + vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb; + vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b; + #else + vec2 anisotropyV = anisotropyVector; + #endif + material.anisotropy = length( anisotropyV ); + if( material.anisotropy == 0.0 ) { + anisotropyV = vec2( 1.0, 0.0 ); + } else { + anisotropyV /= material.anisotropy; + material.anisotropy = saturate( material.anisotropy ); + } + material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) ); + material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y; + material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y; +#endif`,od=`struct PhysicalMaterial { + vec3 diffuseColor; + float roughness; + vec3 specularColor; + float specularF90; + float dispersion; + #ifdef USE_CLEARCOAT + float clearcoat; + float clearcoatRoughness; + vec3 clearcoatF0; + float clearcoatF90; + #endif + #ifdef USE_IRIDESCENCE + float iridescence; + float iridescenceIOR; + float iridescenceThickness; + vec3 iridescenceFresnel; + vec3 iridescenceF0; + #endif + #ifdef USE_SHEEN + vec3 sheenColor; + float sheenRoughness; + #endif + #ifdef IOR + float ior; + #endif + #ifdef USE_TRANSMISSION + float transmission; + float transmissionAlpha; + float thickness; + float attenuationDistance; + vec3 attenuationColor; + #endif + #ifdef USE_ANISOTROPY + float anisotropy; + float alphaT; + vec3 anisotropyT; + vec3 anisotropyB; + #endif +}; +vec3 clearcoatSpecularDirect = vec3( 0.0 ); +vec3 clearcoatSpecularIndirect = vec3( 0.0 ); +vec3 sheenSpecularDirect = vec3( 0.0 ); +vec3 sheenSpecularIndirect = vec3(0.0 ); +vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) { + float x = clamp( 1.0 - dotVH, 0.0, 1.0 ); + float x2 = x * x; + float x5 = clamp( x * x2 * x2, 0.0, 0.9999 ); + return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 ); +} +float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) { + float a2 = pow2( alpha ); + float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) ); + float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) ); + return 0.5 / max( gv + gl, EPSILON ); +} +float D_GGX( const in float alpha, const in float dotNH ) { + float a2 = pow2( alpha ); + float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; + return RECIPROCAL_PI * a2 / pow2( denom ); +} +#ifdef USE_ANISOTROPY + float V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) { + float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) ); + float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) ); + float v = 0.5 / ( gv + gl ); + return saturate(v); + } + float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) { + float a2 = alphaT * alphaB; + highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH ); + highp float v2 = dot( v, v ); + float w2 = a2 / v2; + return RECIPROCAL_PI * a2 * pow2 ( w2 ); + } +#endif +#ifdef USE_CLEARCOAT + vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) { + vec3 f0 = material.clearcoatF0; + float f90 = material.clearcoatF90; + float roughness = material.clearcoatRoughness; + float alpha = pow2( roughness ); + vec3 halfDir = normalize( lightDir + viewDir ); + float dotNL = saturate( dot( normal, lightDir ) ); + float dotNV = saturate( dot( normal, viewDir ) ); + float dotNH = saturate( dot( normal, halfDir ) ); + float dotVH = saturate( dot( viewDir, halfDir ) ); + vec3 F = F_Schlick( f0, f90, dotVH ); + float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV ); + float D = D_GGX( alpha, dotNH ); + return F * ( V * D ); + } +#endif +vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) { + vec3 f0 = material.specularColor; + float f90 = material.specularF90; + float roughness = material.roughness; + float alpha = pow2( roughness ); + vec3 halfDir = normalize( lightDir + viewDir ); + float dotNL = saturate( dot( normal, lightDir ) ); + float dotNV = saturate( dot( normal, viewDir ) ); + float dotNH = saturate( dot( normal, halfDir ) ); + float dotVH = saturate( dot( viewDir, halfDir ) ); + vec3 F = F_Schlick( f0, f90, dotVH ); + #ifdef USE_IRIDESCENCE + F = mix( F, material.iridescenceFresnel, material.iridescence ); + #endif + #ifdef USE_ANISOTROPY + float dotTL = dot( material.anisotropyT, lightDir ); + float dotTV = dot( material.anisotropyT, viewDir ); + float dotTH = dot( material.anisotropyT, halfDir ); + float dotBL = dot( material.anisotropyB, lightDir ); + float dotBV = dot( material.anisotropyB, viewDir ); + float dotBH = dot( material.anisotropyB, halfDir ); + float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL ); + float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH ); + #else + float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV ); + float D = D_GGX( alpha, dotNH ); + #endif + return F * ( V * D ); +} +vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) { + const float LUT_SIZE = 64.0; + const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE; + const float LUT_BIAS = 0.5 / LUT_SIZE; + float dotNV = saturate( dot( N, V ) ); + vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) ); + uv = uv * LUT_SCALE + LUT_BIAS; + return uv; +} +float LTC_ClippedSphereFormFactor( const in vec3 f ) { + float l = length( f ); + return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 ); +} +vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) { + float x = dot( v1, v2 ); + float y = abs( x ); + float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y; + float b = 3.4175940 + ( 4.1616724 + y ) * y; + float v = a / b; + float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v; + return cross( v1, v2 ) * theta_sintheta; +} +vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) { + vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ]; + vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ]; + vec3 lightNormal = cross( v1, v2 ); + if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 ); + vec3 T1, T2; + T1 = normalize( V - N * dot( V, N ) ); + T2 = - cross( N, T1 ); + mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) ); + vec3 coords[ 4 ]; + coords[ 0 ] = mat * ( rectCoords[ 0 ] - P ); + coords[ 1 ] = mat * ( rectCoords[ 1 ] - P ); + coords[ 2 ] = mat * ( rectCoords[ 2 ] - P ); + coords[ 3 ] = mat * ( rectCoords[ 3 ] - P ); + coords[ 0 ] = normalize( coords[ 0 ] ); + coords[ 1 ] = normalize( coords[ 1 ] ); + coords[ 2 ] = normalize( coords[ 2 ] ); + coords[ 3 ] = normalize( coords[ 3 ] ); + vec3 vectorFormFactor = vec3( 0.0 ); + vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] ); + vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] ); + vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] ); + vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] ); + float result = LTC_ClippedSphereFormFactor( vectorFormFactor ); + return vec3( result ); +} +#if defined( USE_SHEEN ) +float D_Charlie( float roughness, float dotNH ) { + float alpha = pow2( roughness ); + float invAlpha = 1.0 / alpha; + float cos2h = dotNH * dotNH; + float sin2h = max( 1.0 - cos2h, 0.0078125 ); + return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI ); +} +float V_Neubelt( float dotNV, float dotNL ) { + return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) ); +} +vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) { + vec3 halfDir = normalize( lightDir + viewDir ); + float dotNL = saturate( dot( normal, lightDir ) ); + float dotNV = saturate( dot( normal, viewDir ) ); + float dotNH = saturate( dot( normal, halfDir ) ); + float D = D_Charlie( sheenRoughness, dotNH ); + float V = V_Neubelt( dotNV, dotNL ); + return sheenColor * ( D * V ); +} +#endif +float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) { + float dotNV = saturate( dot( normal, viewDir ) ); + float r2 = roughness * roughness; + float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95; + float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72; + float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) ); + return saturate( DG * RECIPROCAL_PI ); +} +vec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) { + float dotNV = saturate( dot( normal, viewDir ) ); + const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 ); + const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 ); + vec4 r = roughness * c0 + c1; + float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y; + vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw; + return fab; +} +vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) { + vec2 fab = DFGApprox( normal, viewDir, roughness ); + return specularColor * fab.x + specularF90 * fab.y; +} +#ifdef USE_IRIDESCENCE +void computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) { +#else +void computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) { +#endif + vec2 fab = DFGApprox( normal, viewDir, roughness ); + #ifdef USE_IRIDESCENCE + vec3 Fr = mix( specularColor, iridescenceF0, iridescence ); + #else + vec3 Fr = specularColor; + #endif + vec3 FssEss = Fr * fab.x + specularF90 * fab.y; + float Ess = fab.x + fab.y; + float Ems = 1.0 - Ess; + vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg ); + singleScatter += FssEss; + multiScatter += Fms * Ems; +} +#if NUM_RECT_AREA_LIGHTS > 0 + void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { + vec3 normal = geometryNormal; + vec3 viewDir = geometryViewDir; + vec3 position = geometryPosition; + vec3 lightPos = rectAreaLight.position; + vec3 halfWidth = rectAreaLight.halfWidth; + vec3 halfHeight = rectAreaLight.halfHeight; + vec3 lightColor = rectAreaLight.color; + float roughness = material.roughness; + vec3 rectCoords[ 4 ]; + rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; rectCoords[ 1 ] = lightPos - halfWidth - halfHeight; + rectCoords[ 2 ] = lightPos - halfWidth + halfHeight; + rectCoords[ 3 ] = lightPos + halfWidth + halfHeight; + vec2 uv = LTC_Uv( normal, viewDir, roughness ); + vec4 t1 = texture2D( ltc_1, uv ); + vec4 t2 = texture2D( ltc_2, uv ); + mat3 mInv = mat3( + vec3( t1.x, 0, t1.y ), + vec3( 0, 1, 0 ), + vec3( t1.z, 0, t1.w ) + ); + vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y ); + reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords ); + reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords ); + } +#endif +void RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { + float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); + vec3 irradiance = dotNL * directLight.color; + #ifdef USE_CLEARCOAT + float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) ); + vec3 ccIrradiance = dotNLcc * directLight.color; + clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material ); + #endif + #ifdef USE_SHEEN + sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness ); + #endif + reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material ); + reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { + reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); +} +void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) { + #ifdef USE_CLEARCOAT + clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness ); + #endif + #ifdef USE_SHEEN + sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ); + #endif + vec3 singleScattering = vec3( 0.0 ); + vec3 multiScattering = vec3( 0.0 ); + vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI; + #ifdef USE_IRIDESCENCE + computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering ); + #else + computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering ); + #endif + vec3 totalScattering = singleScattering + multiScattering; + vec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) ); + reflectedLight.indirectSpecular += radiance * singleScattering; + reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance; + reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance; +} +#define RE_Direct RE_Direct_Physical +#define RE_Direct_RectArea RE_Direct_RectArea_Physical +#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical +#define RE_IndirectSpecular RE_IndirectSpecular_Physical +float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) { + return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion ); +}`,cd=` +vec3 geometryPosition = - vViewPosition; +vec3 geometryNormal = normal; +vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition ); +vec3 geometryClearcoatNormal = vec3( 0.0 ); +#ifdef USE_CLEARCOAT + geometryClearcoatNormal = clearcoatNormal; +#endif +#ifdef USE_IRIDESCENCE + float dotNVi = saturate( dot( normal, geometryViewDir ) ); + if ( material.iridescenceThickness == 0.0 ) { + material.iridescence = 0.0; + } else { + material.iridescence = saturate( material.iridescence ); + } + if ( material.iridescence > 0.0 ) { + material.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor ); + material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi ); + } +#endif +IncidentLight directLight; +#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct ) + PointLight pointLight; + #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0 + PointLightShadow pointLightShadow; + #endif + #pragma unroll_loop_start + for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) { + pointLight = pointLights[ i ]; + getPointLightInfo( pointLight, geometryPosition, directLight ); + #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS ) + pointLightShadow = pointLightShadows[ i ]; + directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0; + #endif + RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); + } + #pragma unroll_loop_end +#endif +#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct ) + SpotLight spotLight; + vec4 spotColor; + vec3 spotLightCoord; + bool inSpotLightMap; + #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0 + SpotLightShadow spotLightShadow; + #endif + #pragma unroll_loop_start + for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) { + spotLight = spotLights[ i ]; + getSpotLightInfo( spotLight, geometryPosition, directLight ); + #if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS ) + #define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX + #elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) + #define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS + #else + #define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS ) + #endif + #if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS ) + spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w; + inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) ); + spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy ); + directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color; + #endif + #undef SPOT_LIGHT_MAP_INDEX + #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) + spotLightShadow = spotLightShadows[ i ]; + directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0; + #endif + RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); + } + #pragma unroll_loop_end +#endif +#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct ) + DirectionalLight directionalLight; + #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0 + DirectionalLightShadow directionalLightShadow; + #endif + #pragma unroll_loop_start + for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) { + directionalLight = directionalLights[ i ]; + getDirectionalLightInfo( directionalLight, directLight ); + #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS ) + directionalLightShadow = directionalLightShadows[ i ]; + directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0; + #endif + RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); + } + #pragma unroll_loop_end +#endif +#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea ) + RectAreaLight rectAreaLight; + #pragma unroll_loop_start + for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) { + rectAreaLight = rectAreaLights[ i ]; + RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); + } + #pragma unroll_loop_end +#endif +#if defined( RE_IndirectDiffuse ) + vec3 iblIrradiance = vec3( 0.0 ); + vec3 irradiance = getAmbientLightIrradiance( ambientLightColor ); + #if defined( USE_LIGHT_PROBES ) + irradiance += getLightProbeIrradiance( lightProbe, geometryNormal ); + #endif + #if ( NUM_HEMI_LIGHTS > 0 ) + #pragma unroll_loop_start + for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) { + irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal ); + } + #pragma unroll_loop_end + #endif +#endif +#if defined( RE_IndirectSpecular ) + vec3 radiance = vec3( 0.0 ); + vec3 clearcoatRadiance = vec3( 0.0 ); +#endif`,ld=`#if defined( RE_IndirectDiffuse ) + #ifdef USE_LIGHTMAP + vec4 lightMapTexel = texture2D( lightMap, vLightMapUv ); + vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity; + irradiance += lightMapIrradiance; + #endif + #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV ) + iblIrradiance += getIBLIrradiance( geometryNormal ); + #endif +#endif +#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular ) + #ifdef USE_ANISOTROPY + radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy ); + #else + radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness ); + #endif + #ifdef USE_CLEARCOAT + clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness ); + #endif +#endif`,hd=`#if defined( RE_IndirectDiffuse ) + RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); +#endif +#if defined( RE_IndirectSpecular ) + RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); +#endif`,ud=`#if defined( USE_LOGDEPTHBUF ) + gl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5; +#endif`,dd=`#if defined( USE_LOGDEPTHBUF ) + uniform float logDepthBufFC; + varying float vFragDepth; + varying float vIsPerspective; +#endif`,fd=`#ifdef USE_LOGDEPTHBUF + varying float vFragDepth; + varying float vIsPerspective; +#endif`,pd=`#ifdef USE_LOGDEPTHBUF + vFragDepth = 1.0 + gl_Position.w; + vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) ); +#endif`,md=`#ifdef USE_MAP + vec4 sampledDiffuseColor = texture2D( map, vMapUv ); + #ifdef DECODE_VIDEO_TEXTURE + sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor ); + #endif + diffuseColor *= sampledDiffuseColor; +#endif`,gd=`#ifdef USE_MAP + uniform sampler2D map; +#endif`,_d=`#if defined( USE_MAP ) || defined( USE_ALPHAMAP ) + #if defined( USE_POINTS_UV ) + vec2 uv = vUv; + #else + vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy; + #endif +#endif +#ifdef USE_MAP + diffuseColor *= texture2D( map, uv ); +#endif +#ifdef USE_ALPHAMAP + diffuseColor.a *= texture2D( alphaMap, uv ).g; +#endif`,xd=`#if defined( USE_POINTS_UV ) + varying vec2 vUv; +#else + #if defined( USE_MAP ) || defined( USE_ALPHAMAP ) + uniform mat3 uvTransform; + #endif +#endif +#ifdef USE_MAP + uniform sampler2D map; +#endif +#ifdef USE_ALPHAMAP + uniform sampler2D alphaMap; +#endif`,vd=`float metalnessFactor = metalness; +#ifdef USE_METALNESSMAP + vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv ); + metalnessFactor *= texelMetalness.b; +#endif`,Md=`#ifdef USE_METALNESSMAP + uniform sampler2D metalnessMap; +#endif`,yd=`#ifdef USE_INSTANCING_MORPH + float morphTargetInfluences[ MORPHTARGETS_COUNT ]; + float morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r; + for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { + morphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r; + } +#endif`,Sd=`#if defined( USE_MORPHCOLORS ) + vColor *= morphTargetBaseInfluence; + for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { + #if defined( USE_COLOR_ALPHA ) + if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ]; + #elif defined( USE_COLOR ) + if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ]; + #endif + } +#endif`,Ed=`#ifdef USE_MORPHNORMALS + objectNormal *= morphTargetBaseInfluence; + for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { + if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ]; + } +#endif`,bd=`#ifdef USE_MORPHTARGETS + #ifndef USE_INSTANCING_MORPH + uniform float morphTargetBaseInfluence; + uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ]; + #endif + uniform sampler2DArray morphTargetsTexture; + uniform ivec2 morphTargetsTextureSize; + vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) { + int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset; + int y = texelIndex / morphTargetsTextureSize.x; + int x = texelIndex - y * morphTargetsTextureSize.x; + ivec3 morphUV = ivec3( x, y, morphTargetIndex ); + return texelFetch( morphTargetsTexture, morphUV, 0 ); + } +#endif`,Td=`#ifdef USE_MORPHTARGETS + transformed *= morphTargetBaseInfluence; + for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { + if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ]; + } +#endif`,Ad=`float faceDirection = gl_FrontFacing ? 1.0 : - 1.0; +#ifdef FLAT_SHADED + vec3 fdx = dFdx( vViewPosition ); + vec3 fdy = dFdy( vViewPosition ); + vec3 normal = normalize( cross( fdx, fdy ) ); +#else + vec3 normal = normalize( vNormal ); + #ifdef DOUBLE_SIDED + normal *= faceDirection; + #endif +#endif +#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) + #ifdef USE_TANGENT + mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal ); + #else + mat3 tbn = getTangentFrame( - vViewPosition, normal, + #if defined( USE_NORMALMAP ) + vNormalMapUv + #elif defined( USE_CLEARCOAT_NORMALMAP ) + vClearcoatNormalMapUv + #else + vUv + #endif + ); + #endif + #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED ) + tbn[0] *= faceDirection; + tbn[1] *= faceDirection; + #endif +#endif +#ifdef USE_CLEARCOAT_NORMALMAP + #ifdef USE_TANGENT + mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal ); + #else + mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv ); + #endif + #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED ) + tbn2[0] *= faceDirection; + tbn2[1] *= faceDirection; + #endif +#endif +vec3 nonPerturbedNormal = normal;`,wd=`#ifdef USE_NORMALMAP_OBJECTSPACE + normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0; + #ifdef FLIP_SIDED + normal = - normal; + #endif + #ifdef DOUBLE_SIDED + normal = normal * faceDirection; + #endif + normal = normalize( normalMatrix * normal ); +#elif defined( USE_NORMALMAP_TANGENTSPACE ) + vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0; + mapN.xy *= normalScale; + normal = normalize( tbn * mapN ); +#elif defined( USE_BUMPMAP ) + normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection ); +#endif`,Rd=`#ifndef FLAT_SHADED + varying vec3 vNormal; + #ifdef USE_TANGENT + varying vec3 vTangent; + varying vec3 vBitangent; + #endif +#endif`,Cd=`#ifndef FLAT_SHADED + varying vec3 vNormal; + #ifdef USE_TANGENT + varying vec3 vTangent; + varying vec3 vBitangent; + #endif +#endif`,Id=`#ifndef FLAT_SHADED + vNormal = normalize( transformedNormal ); + #ifdef USE_TANGENT + vTangent = normalize( transformedTangent ); + vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w ); + #endif +#endif`,Pd=`#ifdef USE_NORMALMAP + uniform sampler2D normalMap; + uniform vec2 normalScale; +#endif +#ifdef USE_NORMALMAP_OBJECTSPACE + uniform mat3 normalMatrix; +#endif +#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) ) + mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) { + vec3 q0 = dFdx( eye_pos.xyz ); + vec3 q1 = dFdy( eye_pos.xyz ); + vec2 st0 = dFdx( uv.st ); + vec2 st1 = dFdy( uv.st ); + vec3 N = surf_norm; + vec3 q1perp = cross( q1, N ); + vec3 q0perp = cross( N, q0 ); + vec3 T = q1perp * st0.x + q0perp * st1.x; + vec3 B = q1perp * st0.y + q0perp * st1.y; + float det = max( dot( T, T ), dot( B, B ) ); + float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det ); + return mat3( T * scale, B * scale, N ); + } +#endif`,Ld=`#ifdef USE_CLEARCOAT + vec3 clearcoatNormal = nonPerturbedNormal; +#endif`,Dd=`#ifdef USE_CLEARCOAT_NORMALMAP + vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0; + clearcoatMapN.xy *= clearcoatNormalScale; + clearcoatNormal = normalize( tbn2 * clearcoatMapN ); +#endif`,Ud=`#ifdef USE_CLEARCOATMAP + uniform sampler2D clearcoatMap; +#endif +#ifdef USE_CLEARCOAT_NORMALMAP + uniform sampler2D clearcoatNormalMap; + uniform vec2 clearcoatNormalScale; +#endif +#ifdef USE_CLEARCOAT_ROUGHNESSMAP + uniform sampler2D clearcoatRoughnessMap; +#endif`,Nd=`#ifdef USE_IRIDESCENCEMAP + uniform sampler2D iridescenceMap; +#endif +#ifdef USE_IRIDESCENCE_THICKNESSMAP + uniform sampler2D iridescenceThicknessMap; +#endif`,Fd=`#ifdef OPAQUE +diffuseColor.a = 1.0; +#endif +#ifdef USE_TRANSMISSION +diffuseColor.a *= material.transmissionAlpha; +#endif +gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,Bd=`vec3 packNormalToRGB( const in vec3 normal ) { + return normalize( normal ) * 0.5 + 0.5; +} +vec3 unpackRGBToNormal( const in vec3 rgb ) { + return 2.0 * rgb.xyz - 1.0; +} +const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.; +const float Inv255 = 1. / 255.; +const vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 ); +const vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g ); +const vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b ); +const vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a ); +vec4 packDepthToRGBA( const in float v ) { + if( v <= 0.0 ) + return vec4( 0., 0., 0., 0. ); + if( v >= 1.0 ) + return vec4( 1., 1., 1., 1. ); + float vuf; + float af = modf( v * PackFactors.a, vuf ); + float bf = modf( vuf * ShiftRight8, vuf ); + float gf = modf( vuf * ShiftRight8, vuf ); + return vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af ); +} +vec3 packDepthToRGB( const in float v ) { + if( v <= 0.0 ) + return vec3( 0., 0., 0. ); + if( v >= 1.0 ) + return vec3( 1., 1., 1. ); + float vuf; + float bf = modf( v * PackFactors.b, vuf ); + float gf = modf( vuf * ShiftRight8, vuf ); + return vec3( vuf * Inv255, gf * PackUpscale, bf ); +} +vec2 packDepthToRG( const in float v ) { + if( v <= 0.0 ) + return vec2( 0., 0. ); + if( v >= 1.0 ) + return vec2( 1., 1. ); + float vuf; + float gf = modf( v * 256., vuf ); + return vec2( vuf * Inv255, gf ); +} +float unpackRGBAToDepth( const in vec4 v ) { + return dot( v, UnpackFactors4 ); +} +float unpackRGBToDepth( const in vec3 v ) { + return dot( v, UnpackFactors3 ); +} +float unpackRGToDepth( const in vec2 v ) { + return v.r * UnpackFactors2.r + v.g * UnpackFactors2.g; +} +vec4 pack2HalfToRGBA( const in vec2 v ) { + vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) ); + return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w ); +} +vec2 unpackRGBATo2Half( const in vec4 v ) { + return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) ); +} +float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) { + return ( viewZ + near ) / ( near - far ); +} +float orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) { + return depth * ( near - far ) - near; +} +float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) { + return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ ); +} +float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) { + return ( near * far ) / ( ( far - near ) * depth - far ); +}`,Od=`#ifdef PREMULTIPLIED_ALPHA + gl_FragColor.rgb *= gl_FragColor.a; +#endif`,zd=`vec4 mvPosition = vec4( transformed, 1.0 ); +#ifdef USE_BATCHING + mvPosition = batchingMatrix * mvPosition; +#endif +#ifdef USE_INSTANCING + mvPosition = instanceMatrix * mvPosition; +#endif +mvPosition = modelViewMatrix * mvPosition; +gl_Position = projectionMatrix * mvPosition;`,Vd=`#ifdef DITHERING + gl_FragColor.rgb = dithering( gl_FragColor.rgb ); +#endif`,kd=`#ifdef DITHERING + vec3 dithering( vec3 color ) { + float grid_position = rand( gl_FragCoord.xy ); + vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 ); + dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position ); + return color + dither_shift_RGB; + } +#endif`,Hd=`float roughnessFactor = roughness; +#ifdef USE_ROUGHNESSMAP + vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv ); + roughnessFactor *= texelRoughness.g; +#endif`,Gd=`#ifdef USE_ROUGHNESSMAP + uniform sampler2D roughnessMap; +#endif`,Wd=`#if NUM_SPOT_LIGHT_COORDS > 0 + varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ]; +#endif +#if NUM_SPOT_LIGHT_MAPS > 0 + uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ]; +#endif +#ifdef USE_SHADOWMAP + #if NUM_DIR_LIGHT_SHADOWS > 0 + uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ]; + varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ]; + struct DirectionalLightShadow { + float shadowIntensity; + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + }; + uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ]; + #endif + #if NUM_SPOT_LIGHT_SHADOWS > 0 + uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ]; + struct SpotLightShadow { + float shadowIntensity; + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + }; + uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ]; + #endif + #if NUM_POINT_LIGHT_SHADOWS > 0 + uniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ]; + varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ]; + struct PointLightShadow { + float shadowIntensity; + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + float shadowCameraNear; + float shadowCameraFar; + }; + uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ]; + #endif + float texture2DCompare( sampler2D depths, vec2 uv, float compare ) { + return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) ); + } + vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) { + return unpackRGBATo2Half( texture2D( shadow, uv ) ); + } + float VSMShadow (sampler2D shadow, vec2 uv, float compare ){ + float occlusion = 1.0; + vec2 distribution = texture2DDistribution( shadow, uv ); + float hard_shadow = step( compare , distribution.x ); + if (hard_shadow != 1.0 ) { + float distance = compare - distribution.x ; + float variance = max( 0.00000, distribution.y * distribution.y ); + float softness_probability = variance / (variance + distance * distance ); softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 ); occlusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 ); + } + return occlusion; + } + float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) { + float shadow = 1.0; + shadowCoord.xyz /= shadowCoord.w; + shadowCoord.z += shadowBias; + bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0; + bool frustumTest = inFrustum && shadowCoord.z <= 1.0; + if ( frustumTest ) { + #if defined( SHADOWMAP_TYPE_PCF ) + vec2 texelSize = vec2( 1.0 ) / shadowMapSize; + float dx0 = - texelSize.x * shadowRadius; + float dy0 = - texelSize.y * shadowRadius; + float dx1 = + texelSize.x * shadowRadius; + float dy1 = + texelSize.y * shadowRadius; + float dx2 = dx0 / 2.0; + float dy2 = dy0 / 2.0; + float dx3 = dx1 / 2.0; + float dy3 = dy1 / 2.0; + shadow = ( + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) + + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z ) + ) * ( 1.0 / 17.0 ); + #elif defined( SHADOWMAP_TYPE_PCF_SOFT ) + vec2 texelSize = vec2( 1.0 ) / shadowMapSize; + float dx = texelSize.x; + float dy = texelSize.y; + vec2 uv = shadowCoord.xy; + vec2 f = fract( uv * shadowMapSize + 0.5 ); + uv -= f * texelSize; + shadow = ( + texture2DCompare( shadowMap, uv, shadowCoord.z ) + + texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) + + texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) + + texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) + + mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ), + f.x ) + + mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ), + f.x ) + + mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ), + f.y ) + + mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ), + f.y ) + + mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ), + f.x ), + mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), + texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ), + f.x ), + f.y ) + ) * ( 1.0 / 9.0 ); + #elif defined( SHADOWMAP_TYPE_VSM ) + shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z ); + #else + shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ); + #endif + } + return mix( 1.0, shadow, shadowIntensity ); + } + vec2 cubeToUV( vec3 v, float texelSizeY ) { + vec3 absV = abs( v ); + float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) ); + absV *= scaleToCube; + v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY ); + vec2 planar = v.xy; + float almostATexel = 1.5 * texelSizeY; + float almostOne = 1.0 - almostATexel; + if ( absV.z >= almostOne ) { + if ( v.z > 0.0 ) + planar.x = 4.0 - v.x; + } else if ( absV.x >= almostOne ) { + float signX = sign( v.x ); + planar.x = v.z * signX + 2.0 * signX; + } else if ( absV.y >= almostOne ) { + float signY = sign( v.y ); + planar.x = v.x + 2.0 * signY + 2.0; + planar.y = v.z * signY - 2.0; + } + return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 ); + } + float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) { + float shadow = 1.0; + vec3 lightToPosition = shadowCoord.xyz; + + float lightToPositionLength = length( lightToPosition ); + if ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) { + float dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); dp += shadowBias; + vec3 bd3D = normalize( lightToPosition ); + vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) ); + #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM ) + vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y; + shadow = ( + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) + + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp ) + ) * ( 1.0 / 9.0 ); + #else + shadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ); + #endif + } + return mix( 1.0, shadow, shadowIntensity ); + } +#endif`,Xd=`#if NUM_SPOT_LIGHT_COORDS > 0 + uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ]; + varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ]; +#endif +#ifdef USE_SHADOWMAP + #if NUM_DIR_LIGHT_SHADOWS > 0 + uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ]; + varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ]; + struct DirectionalLightShadow { + float shadowIntensity; + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + }; + uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ]; + #endif + #if NUM_SPOT_LIGHT_SHADOWS > 0 + struct SpotLightShadow { + float shadowIntensity; + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + }; + uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ]; + #endif + #if NUM_POINT_LIGHT_SHADOWS > 0 + uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ]; + varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ]; + struct PointLightShadow { + float shadowIntensity; + float shadowBias; + float shadowNormalBias; + float shadowRadius; + vec2 shadowMapSize; + float shadowCameraNear; + float shadowCameraFar; + }; + uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ]; + #endif +#endif`,qd=`#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 ) + vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix ); + vec4 shadowWorldPosition; +#endif +#if defined( USE_SHADOWMAP ) + #if NUM_DIR_LIGHT_SHADOWS > 0 + #pragma unroll_loop_start + for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) { + shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 ); + vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition; + } + #pragma unroll_loop_end + #endif + #if NUM_POINT_LIGHT_SHADOWS > 0 + #pragma unroll_loop_start + for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) { + shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 ); + vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition; + } + #pragma unroll_loop_end + #endif +#endif +#if NUM_SPOT_LIGHT_COORDS > 0 + #pragma unroll_loop_start + for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) { + shadowWorldPosition = worldPosition; + #if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) + shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias; + #endif + vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition; + } + #pragma unroll_loop_end +#endif`,Yd=`float getShadowMask() { + float shadow = 1.0; + #ifdef USE_SHADOWMAP + #if NUM_DIR_LIGHT_SHADOWS > 0 + DirectionalLightShadow directionalLight; + #pragma unroll_loop_start + for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) { + directionalLight = directionalLightShadows[ i ]; + shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0; + } + #pragma unroll_loop_end + #endif + #if NUM_SPOT_LIGHT_SHADOWS > 0 + SpotLightShadow spotLight; + #pragma unroll_loop_start + for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) { + spotLight = spotLightShadows[ i ]; + shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0; + } + #pragma unroll_loop_end + #endif + #if NUM_POINT_LIGHT_SHADOWS > 0 + PointLightShadow pointLight; + #pragma unroll_loop_start + for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) { + pointLight = pointLightShadows[ i ]; + shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0; + } + #pragma unroll_loop_end + #endif + #endif + return shadow; +}`,jd=`#ifdef USE_SKINNING + mat4 boneMatX = getBoneMatrix( skinIndex.x ); + mat4 boneMatY = getBoneMatrix( skinIndex.y ); + mat4 boneMatZ = getBoneMatrix( skinIndex.z ); + mat4 boneMatW = getBoneMatrix( skinIndex.w ); +#endif`,Kd=`#ifdef USE_SKINNING + uniform mat4 bindMatrix; + uniform mat4 bindMatrixInverse; + uniform highp sampler2D boneTexture; + mat4 getBoneMatrix( const in float i ) { + int size = textureSize( boneTexture, 0 ).x; + int j = int( i ) * 4; + int x = j % size; + int y = j / size; + vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 ); + vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 ); + vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 ); + vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 ); + return mat4( v1, v2, v3, v4 ); + } +#endif`,Zd=`#ifdef USE_SKINNING + vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 ); + vec4 skinned = vec4( 0.0 ); + skinned += boneMatX * skinVertex * skinWeight.x; + skinned += boneMatY * skinVertex * skinWeight.y; + skinned += boneMatZ * skinVertex * skinWeight.z; + skinned += boneMatW * skinVertex * skinWeight.w; + transformed = ( bindMatrixInverse * skinned ).xyz; +#endif`,$d=`#ifdef USE_SKINNING + mat4 skinMatrix = mat4( 0.0 ); + skinMatrix += skinWeight.x * boneMatX; + skinMatrix += skinWeight.y * boneMatY; + skinMatrix += skinWeight.z * boneMatZ; + skinMatrix += skinWeight.w * boneMatW; + skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix; + objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz; + #ifdef USE_TANGENT + objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz; + #endif +#endif`,Jd=`float specularStrength; +#ifdef USE_SPECULARMAP + vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv ); + specularStrength = texelSpecular.r; +#else + specularStrength = 1.0; +#endif`,Qd=`#ifdef USE_SPECULARMAP + uniform sampler2D specularMap; +#endif`,tf=`#if defined( TONE_MAPPING ) + gl_FragColor.rgb = toneMapping( gl_FragColor.rgb ); +#endif`,ef=`#ifndef saturate +#define saturate( a ) clamp( a, 0.0, 1.0 ) +#endif +uniform float toneMappingExposure; +vec3 LinearToneMapping( vec3 color ) { + return saturate( toneMappingExposure * color ); +} +vec3 ReinhardToneMapping( vec3 color ) { + color *= toneMappingExposure; + return saturate( color / ( vec3( 1.0 ) + color ) ); +} +vec3 CineonToneMapping( vec3 color ) { + color *= toneMappingExposure; + color = max( vec3( 0.0 ), color - 0.004 ); + return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) ); +} +vec3 RRTAndODTFit( vec3 v ) { + vec3 a = v * ( v + 0.0245786 ) - 0.000090537; + vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081; + return a / b; +} +vec3 ACESFilmicToneMapping( vec3 color ) { + const mat3 ACESInputMat = mat3( + vec3( 0.59719, 0.07600, 0.02840 ), vec3( 0.35458, 0.90834, 0.13383 ), + vec3( 0.04823, 0.01566, 0.83777 ) + ); + const mat3 ACESOutputMat = mat3( + vec3( 1.60475, -0.10208, -0.00327 ), vec3( -0.53108, 1.10813, -0.07276 ), + vec3( -0.07367, -0.00605, 1.07602 ) + ); + color *= toneMappingExposure / 0.6; + color = ACESInputMat * color; + color = RRTAndODTFit( color ); + color = ACESOutputMat * color; + return saturate( color ); +} +const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3( + vec3( 1.6605, - 0.1246, - 0.0182 ), + vec3( - 0.5876, 1.1329, - 0.1006 ), + vec3( - 0.0728, - 0.0083, 1.1187 ) +); +const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3( + vec3( 0.6274, 0.0691, 0.0164 ), + vec3( 0.3293, 0.9195, 0.0880 ), + vec3( 0.0433, 0.0113, 0.8956 ) +); +vec3 agxDefaultContrastApprox( vec3 x ) { + vec3 x2 = x * x; + vec3 x4 = x2 * x2; + return + 15.5 * x4 * x2 + - 40.14 * x4 * x + + 31.96 * x4 + - 6.868 * x2 * x + + 0.4298 * x2 + + 0.1191 * x + - 0.00232; +} +vec3 AgXToneMapping( vec3 color ) { + const mat3 AgXInsetMatrix = mat3( + vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ), + vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ), + vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 ) + ); + const mat3 AgXOutsetMatrix = mat3( + vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ), + vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ), + vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 ) + ); + const float AgxMinEv = - 12.47393; const float AgxMaxEv = 4.026069; + color *= toneMappingExposure; + color = LINEAR_SRGB_TO_LINEAR_REC2020 * color; + color = AgXInsetMatrix * color; + color = max( color, 1e-10 ); color = log2( color ); + color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv ); + color = clamp( color, 0.0, 1.0 ); + color = agxDefaultContrastApprox( color ); + color = AgXOutsetMatrix * color; + color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) ); + color = LINEAR_REC2020_TO_LINEAR_SRGB * color; + color = clamp( color, 0.0, 1.0 ); + return color; +} +vec3 NeutralToneMapping( vec3 color ) { + const float StartCompression = 0.8 - 0.04; + const float Desaturation = 0.15; + color *= toneMappingExposure; + float x = min( color.r, min( color.g, color.b ) ); + float offset = x < 0.08 ? x - 6.25 * x * x : 0.04; + color -= offset; + float peak = max( color.r, max( color.g, color.b ) ); + if ( peak < StartCompression ) return color; + float d = 1. - StartCompression; + float newPeak = 1. - d * d / ( peak + d - StartCompression ); + color *= newPeak / peak; + float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. ); + return mix( color, vec3( newPeak ), g ); +} +vec3 CustomToneMapping( vec3 color ) { return color; }`,nf=`#ifdef USE_TRANSMISSION + material.transmission = transmission; + material.transmissionAlpha = 1.0; + material.thickness = thickness; + material.attenuationDistance = attenuationDistance; + material.attenuationColor = attenuationColor; + #ifdef USE_TRANSMISSIONMAP + material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r; + #endif + #ifdef USE_THICKNESSMAP + material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g; + #endif + vec3 pos = vWorldPosition; + vec3 v = normalize( cameraPosition - pos ); + vec3 n = inverseTransformDirection( normal, viewMatrix ); + vec4 transmitted = getIBLVolumeRefraction( + n, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90, + pos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness, + material.attenuationColor, material.attenuationDistance ); + material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission ); + totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission ); +#endif`,sf=`#ifdef USE_TRANSMISSION + uniform float transmission; + uniform float thickness; + uniform float attenuationDistance; + uniform vec3 attenuationColor; + #ifdef USE_TRANSMISSIONMAP + uniform sampler2D transmissionMap; + #endif + #ifdef USE_THICKNESSMAP + uniform sampler2D thicknessMap; + #endif + uniform vec2 transmissionSamplerSize; + uniform sampler2D transmissionSamplerMap; + uniform mat4 modelMatrix; + uniform mat4 projectionMatrix; + varying vec3 vWorldPosition; + float w0( float a ) { + return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 ); + } + float w1( float a ) { + return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 ); + } + float w2( float a ){ + return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 ); + } + float w3( float a ) { + return ( 1.0 / 6.0 ) * ( a * a * a ); + } + float g0( float a ) { + return w0( a ) + w1( a ); + } + float g1( float a ) { + return w2( a ) + w3( a ); + } + float h0( float a ) { + return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) ); + } + float h1( float a ) { + return 1.0 + w3( a ) / ( w2( a ) + w3( a ) ); + } + vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) { + uv = uv * texelSize.zw + 0.5; + vec2 iuv = floor( uv ); + vec2 fuv = fract( uv ); + float g0x = g0( fuv.x ); + float g1x = g1( fuv.x ); + float h0x = h0( fuv.x ); + float h1x = h1( fuv.x ); + float h0y = h0( fuv.y ); + float h1y = h1( fuv.y ); + vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy; + vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy; + vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy; + vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy; + return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) + + g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) ); + } + vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) { + vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) ); + vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) ); + vec2 fLodSizeInv = 1.0 / fLodSize; + vec2 cLodSizeInv = 1.0 / cLodSize; + vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) ); + vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) ); + return mix( fSample, cSample, fract( lod ) ); + } + vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) { + vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior ); + vec3 modelScale; + modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) ); + modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) ); + modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) ); + return normalize( refractionVector ) * thickness * modelScale; + } + float applyIorToRoughness( const in float roughness, const in float ior ) { + return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 ); + } + vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) { + float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior ); + return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod ); + } + vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) { + if ( isinf( attenuationDistance ) ) { + return vec3( 1.0 ); + } else { + vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance; + vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance; + } + } + vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor, + const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix, + const in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness, + const in vec3 attenuationColor, const in float attenuationDistance ) { + vec4 transmittedLight; + vec3 transmittance; + #ifdef USE_DISPERSION + float halfSpread = ( ior - 1.0 ) * 0.025 * dispersion; + vec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread ); + for ( int i = 0; i < 3; i ++ ) { + vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix ); + vec3 refractedRayExit = position + transmissionRay; + + vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 ); + vec2 refractionCoords = ndcPos.xy / ndcPos.w; + refractionCoords += 1.0; + refractionCoords /= 2.0; + + vec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] ); + transmittedLight[ i ] = transmissionSample[ i ]; + transmittedLight.a += transmissionSample.a; + transmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ]; + } + transmittedLight.a /= 3.0; + + #else + + vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix ); + vec3 refractedRayExit = position + transmissionRay; + vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 ); + vec2 refractionCoords = ndcPos.xy / ndcPos.w; + refractionCoords += 1.0; + refractionCoords /= 2.0; + transmittedLight = getTransmissionSample( refractionCoords, roughness, ior ); + transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance ); + + #endif + vec3 attenuatedColor = transmittance * transmittedLight.rgb; + vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness ); + float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0; + return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor ); + } +#endif`,rf=`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) + varying vec2 vUv; +#endif +#ifdef USE_MAP + varying vec2 vMapUv; +#endif +#ifdef USE_ALPHAMAP + varying vec2 vAlphaMapUv; +#endif +#ifdef USE_LIGHTMAP + varying vec2 vLightMapUv; +#endif +#ifdef USE_AOMAP + varying vec2 vAoMapUv; +#endif +#ifdef USE_BUMPMAP + varying vec2 vBumpMapUv; +#endif +#ifdef USE_NORMALMAP + varying vec2 vNormalMapUv; +#endif +#ifdef USE_EMISSIVEMAP + varying vec2 vEmissiveMapUv; +#endif +#ifdef USE_METALNESSMAP + varying vec2 vMetalnessMapUv; +#endif +#ifdef USE_ROUGHNESSMAP + varying vec2 vRoughnessMapUv; +#endif +#ifdef USE_ANISOTROPYMAP + varying vec2 vAnisotropyMapUv; +#endif +#ifdef USE_CLEARCOATMAP + varying vec2 vClearcoatMapUv; +#endif +#ifdef USE_CLEARCOAT_NORMALMAP + varying vec2 vClearcoatNormalMapUv; +#endif +#ifdef USE_CLEARCOAT_ROUGHNESSMAP + varying vec2 vClearcoatRoughnessMapUv; +#endif +#ifdef USE_IRIDESCENCEMAP + varying vec2 vIridescenceMapUv; +#endif +#ifdef USE_IRIDESCENCE_THICKNESSMAP + varying vec2 vIridescenceThicknessMapUv; +#endif +#ifdef USE_SHEEN_COLORMAP + varying vec2 vSheenColorMapUv; +#endif +#ifdef USE_SHEEN_ROUGHNESSMAP + varying vec2 vSheenRoughnessMapUv; +#endif +#ifdef USE_SPECULARMAP + varying vec2 vSpecularMapUv; +#endif +#ifdef USE_SPECULAR_COLORMAP + varying vec2 vSpecularColorMapUv; +#endif +#ifdef USE_SPECULAR_INTENSITYMAP + varying vec2 vSpecularIntensityMapUv; +#endif +#ifdef USE_TRANSMISSIONMAP + uniform mat3 transmissionMapTransform; + varying vec2 vTransmissionMapUv; +#endif +#ifdef USE_THICKNESSMAP + uniform mat3 thicknessMapTransform; + varying vec2 vThicknessMapUv; +#endif`,af=`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) + varying vec2 vUv; +#endif +#ifdef USE_MAP + uniform mat3 mapTransform; + varying vec2 vMapUv; +#endif +#ifdef USE_ALPHAMAP + uniform mat3 alphaMapTransform; + varying vec2 vAlphaMapUv; +#endif +#ifdef USE_LIGHTMAP + uniform mat3 lightMapTransform; + varying vec2 vLightMapUv; +#endif +#ifdef USE_AOMAP + uniform mat3 aoMapTransform; + varying vec2 vAoMapUv; +#endif +#ifdef USE_BUMPMAP + uniform mat3 bumpMapTransform; + varying vec2 vBumpMapUv; +#endif +#ifdef USE_NORMALMAP + uniform mat3 normalMapTransform; + varying vec2 vNormalMapUv; +#endif +#ifdef USE_DISPLACEMENTMAP + uniform mat3 displacementMapTransform; + varying vec2 vDisplacementMapUv; +#endif +#ifdef USE_EMISSIVEMAP + uniform mat3 emissiveMapTransform; + varying vec2 vEmissiveMapUv; +#endif +#ifdef USE_METALNESSMAP + uniform mat3 metalnessMapTransform; + varying vec2 vMetalnessMapUv; +#endif +#ifdef USE_ROUGHNESSMAP + uniform mat3 roughnessMapTransform; + varying vec2 vRoughnessMapUv; +#endif +#ifdef USE_ANISOTROPYMAP + uniform mat3 anisotropyMapTransform; + varying vec2 vAnisotropyMapUv; +#endif +#ifdef USE_CLEARCOATMAP + uniform mat3 clearcoatMapTransform; + varying vec2 vClearcoatMapUv; +#endif +#ifdef USE_CLEARCOAT_NORMALMAP + uniform mat3 clearcoatNormalMapTransform; + varying vec2 vClearcoatNormalMapUv; +#endif +#ifdef USE_CLEARCOAT_ROUGHNESSMAP + uniform mat3 clearcoatRoughnessMapTransform; + varying vec2 vClearcoatRoughnessMapUv; +#endif +#ifdef USE_SHEEN_COLORMAP + uniform mat3 sheenColorMapTransform; + varying vec2 vSheenColorMapUv; +#endif +#ifdef USE_SHEEN_ROUGHNESSMAP + uniform mat3 sheenRoughnessMapTransform; + varying vec2 vSheenRoughnessMapUv; +#endif +#ifdef USE_IRIDESCENCEMAP + uniform mat3 iridescenceMapTransform; + varying vec2 vIridescenceMapUv; +#endif +#ifdef USE_IRIDESCENCE_THICKNESSMAP + uniform mat3 iridescenceThicknessMapTransform; + varying vec2 vIridescenceThicknessMapUv; +#endif +#ifdef USE_SPECULARMAP + uniform mat3 specularMapTransform; + varying vec2 vSpecularMapUv; +#endif +#ifdef USE_SPECULAR_COLORMAP + uniform mat3 specularColorMapTransform; + varying vec2 vSpecularColorMapUv; +#endif +#ifdef USE_SPECULAR_INTENSITYMAP + uniform mat3 specularIntensityMapTransform; + varying vec2 vSpecularIntensityMapUv; +#endif +#ifdef USE_TRANSMISSIONMAP + uniform mat3 transmissionMapTransform; + varying vec2 vTransmissionMapUv; +#endif +#ifdef USE_THICKNESSMAP + uniform mat3 thicknessMapTransform; + varying vec2 vThicknessMapUv; +#endif`,of=`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) + vUv = vec3( uv, 1 ).xy; +#endif +#ifdef USE_MAP + vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy; +#endif +#ifdef USE_ALPHAMAP + vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_LIGHTMAP + vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_AOMAP + vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_BUMPMAP + vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_NORMALMAP + vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_DISPLACEMENTMAP + vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_EMISSIVEMAP + vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_METALNESSMAP + vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_ROUGHNESSMAP + vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_ANISOTROPYMAP + vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_CLEARCOATMAP + vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_CLEARCOAT_NORMALMAP + vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_CLEARCOAT_ROUGHNESSMAP + vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_IRIDESCENCEMAP + vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_IRIDESCENCE_THICKNESSMAP + vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_SHEEN_COLORMAP + vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_SHEEN_ROUGHNESSMAP + vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_SPECULARMAP + vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_SPECULAR_COLORMAP + vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_SPECULAR_INTENSITYMAP + vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_TRANSMISSIONMAP + vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy; +#endif +#ifdef USE_THICKNESSMAP + vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy; +#endif`,cf=`#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0 + vec4 worldPosition = vec4( transformed, 1.0 ); + #ifdef USE_BATCHING + worldPosition = batchingMatrix * worldPosition; + #endif + #ifdef USE_INSTANCING + worldPosition = instanceMatrix * worldPosition; + #endif + worldPosition = modelMatrix * worldPosition; +#endif`;const lf=`varying vec2 vUv; +uniform mat3 uvTransform; +void main() { + vUv = ( uvTransform * vec3( uv, 1 ) ).xy; + gl_Position = vec4( position.xy, 1.0, 1.0 ); +}`,hf=`uniform sampler2D t2D; +uniform float backgroundIntensity; +varying vec2 vUv; +void main() { + vec4 texColor = texture2D( t2D, vUv ); + #ifdef DECODE_VIDEO_TEXTURE + texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w ); + #endif + texColor.rgb *= backgroundIntensity; + gl_FragColor = texColor; + #include + #include +}`,uf=`varying vec3 vWorldDirection; +#include +void main() { + vWorldDirection = transformDirection( position, modelMatrix ); + #include + #include + gl_Position.z = gl_Position.w; +}`,df=`#ifdef ENVMAP_TYPE_CUBE + uniform samplerCube envMap; +#elif defined( ENVMAP_TYPE_CUBE_UV ) + uniform sampler2D envMap; +#endif +uniform float flipEnvMap; +uniform float backgroundBlurriness; +uniform float backgroundIntensity; +uniform mat3 backgroundRotation; +varying vec3 vWorldDirection; +#include +void main() { + #ifdef ENVMAP_TYPE_CUBE + vec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) ); + #elif defined( ENVMAP_TYPE_CUBE_UV ) + vec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness ); + #else + vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 ); + #endif + texColor.rgb *= backgroundIntensity; + gl_FragColor = texColor; + #include + #include +}`,ff=`varying vec3 vWorldDirection; +#include +void main() { + vWorldDirection = transformDirection( position, modelMatrix ); + #include + #include + gl_Position.z = gl_Position.w; +}`,pf=`uniform samplerCube tCube; +uniform float tFlip; +uniform float opacity; +varying vec3 vWorldDirection; +void main() { + vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) ); + gl_FragColor = texColor; + gl_FragColor.a *= opacity; + #include + #include +}`,mf=`#include +#include +#include +#include +#include +#include +#include +#include +varying vec2 vHighPrecisionZW; +void main() { + #include + #include + #include + #include + #ifdef USE_DISPLACEMENTMAP + #include + #include + #include + #endif + #include + #include + #include + #include + #include + #include + #include + vHighPrecisionZW = gl_Position.zw; +}`,gf=`#if DEPTH_PACKING == 3200 + uniform float opacity; +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +varying vec2 vHighPrecisionZW; +void main() { + vec4 diffuseColor = vec4( 1.0 ); + #include + #if DEPTH_PACKING == 3200 + diffuseColor.a = opacity; + #endif + #include + #include + #include + #include + #include + float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5; + #if DEPTH_PACKING == 3200 + gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity ); + #elif DEPTH_PACKING == 3201 + gl_FragColor = packDepthToRGBA( fragCoordZ ); + #elif DEPTH_PACKING == 3202 + gl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 ); + #elif DEPTH_PACKING == 3203 + gl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 ); + #endif +}`,_f=`#define DISTANCE +varying vec3 vWorldPosition; +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #ifdef USE_DISPLACEMENTMAP + #include + #include + #include + #endif + #include + #include + #include + #include + #include + #include + #include + vWorldPosition = worldPosition.xyz; +}`,xf=`#define DISTANCE +uniform vec3 referencePosition; +uniform float nearDistance; +uniform float farDistance; +varying vec3 vWorldPosition; +#include +#include +#include +#include +#include +#include +#include +#include +void main () { + vec4 diffuseColor = vec4( 1.0 ); + #include + #include + #include + #include + #include + float dist = length( vWorldPosition - referencePosition ); + dist = ( dist - nearDistance ) / ( farDistance - nearDistance ); + dist = saturate( dist ); + gl_FragColor = packDepthToRGBA( dist ); +}`,vf=`varying vec3 vWorldDirection; +#include +void main() { + vWorldDirection = transformDirection( position, modelMatrix ); + #include + #include +}`,Mf=`uniform sampler2D tEquirect; +varying vec3 vWorldDirection; +#include +void main() { + vec3 direction = normalize( vWorldDirection ); + vec2 sampleUV = equirectUv( direction ); + gl_FragColor = texture2D( tEquirect, sampleUV ); + #include + #include +}`,yf=`uniform float scale; +attribute float lineDistance; +varying float vLineDistance; +#include +#include +#include +#include +#include +#include +#include +void main() { + vLineDistance = scale * lineDistance; + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include +}`,Sf=`uniform vec3 diffuse; +uniform float opacity; +uniform float dashSize; +uniform float totalSize; +varying float vLineDistance; +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + if ( mod( vLineDistance, totalSize ) > dashSize ) { + discard; + } + vec3 outgoingLight = vec3( 0.0 ); + #include + #include + #include + outgoingLight = diffuseColor.rgb; + #include + #include + #include + #include + #include +}`,Ef=`#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #if defined ( USE_ENVMAP ) || defined ( USE_SKINNING ) + #include + #include + #include + #include + #include + #endif + #include + #include + #include + #include + #include + #include + #include + #include + #include +}`,bf=`uniform vec3 diffuse; +uniform float opacity; +#ifndef FLAT_SHADED + varying vec3 vNormal; +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + #include + #include + #include + #include + #include + #include + #include + ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); + #ifdef USE_LIGHTMAP + vec4 lightMapTexel = texture2D( lightMap, vLightMapUv ); + reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI; + #else + reflectedLight.indirectDiffuse += vec3( 1.0 ); + #endif + #include + reflectedLight.indirectDiffuse *= diffuseColor.rgb; + vec3 outgoingLight = reflectedLight.indirectDiffuse; + #include + #include + #include + #include + #include + #include + #include +}`,Tf=`#define LAMBERT +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vViewPosition = - mvPosition.xyz; + #include + #include + #include + #include +}`,Af=`#define LAMBERT +uniform vec3 diffuse; +uniform vec3 emissive; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); + vec3 totalEmissiveRadiance = emissive; + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance; + #include + #include + #include + #include + #include + #include + #include +}`,wf=`#define MATCAP +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vViewPosition = - mvPosition.xyz; +}`,Rf=`#define MATCAP +uniform vec3 diffuse; +uniform float opacity; +uniform sampler2D matcap; +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + #include + #include + #include + #include + #include + #include + #include + #include + vec3 viewDir = normalize( vViewPosition ); + vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) ); + vec3 y = cross( viewDir, x ); + vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5; + #ifdef USE_MATCAP + vec4 matcapColor = texture2D( matcap, uv ); + #else + vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 ); + #endif + vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb; + #include + #include + #include + #include + #include + #include +}`,Cf=`#define NORMAL +#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) + varying vec3 vViewPosition; +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include +#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) + vViewPosition = - mvPosition.xyz; +#endif +}`,If=`#define NORMAL +uniform float opacity; +#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) + varying vec3 vViewPosition; +#endif +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity ); + #include + #include + #include + #include + gl_FragColor = vec4( packNormalToRGB( normal ), diffuseColor.a ); + #ifdef OPAQUE + gl_FragColor.a = 1.0; + #endif +}`,Pf=`#define PHONG +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vViewPosition = - mvPosition.xyz; + #include + #include + #include + #include +}`,Lf=`#define PHONG +uniform vec3 diffuse; +uniform vec3 emissive; +uniform vec3 specular; +uniform float shininess; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); + vec3 totalEmissiveRadiance = emissive; + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance; + #include + #include + #include + #include + #include + #include + #include +}`,Df=`#define STANDARD +varying vec3 vViewPosition; +#ifdef USE_TRANSMISSION + varying vec3 vWorldPosition; +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vViewPosition = - mvPosition.xyz; + #include + #include + #include +#ifdef USE_TRANSMISSION + vWorldPosition = worldPosition.xyz; +#endif +}`,Uf=`#define STANDARD +#ifdef PHYSICAL + #define IOR + #define USE_SPECULAR +#endif +uniform vec3 diffuse; +uniform vec3 emissive; +uniform float roughness; +uniform float metalness; +uniform float opacity; +#ifdef IOR + uniform float ior; +#endif +#ifdef USE_SPECULAR + uniform float specularIntensity; + uniform vec3 specularColor; + #ifdef USE_SPECULAR_COLORMAP + uniform sampler2D specularColorMap; + #endif + #ifdef USE_SPECULAR_INTENSITYMAP + uniform sampler2D specularIntensityMap; + #endif +#endif +#ifdef USE_CLEARCOAT + uniform float clearcoat; + uniform float clearcoatRoughness; +#endif +#ifdef USE_DISPERSION + uniform float dispersion; +#endif +#ifdef USE_IRIDESCENCE + uniform float iridescence; + uniform float iridescenceIOR; + uniform float iridescenceThicknessMinimum; + uniform float iridescenceThicknessMaximum; +#endif +#ifdef USE_SHEEN + uniform vec3 sheenColor; + uniform float sheenRoughness; + #ifdef USE_SHEEN_COLORMAP + uniform sampler2D sheenColorMap; + #endif + #ifdef USE_SHEEN_ROUGHNESSMAP + uniform sampler2D sheenRoughnessMap; + #endif +#endif +#ifdef USE_ANISOTROPY + uniform vec2 anisotropyVector; + #ifdef USE_ANISOTROPYMAP + uniform sampler2D anisotropyMap; + #endif +#endif +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); + vec3 totalEmissiveRadiance = emissive; + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse; + vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular; + #include + vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance; + #ifdef USE_SHEEN + float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor ); + outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect; + #endif + #ifdef USE_CLEARCOAT + float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) ); + vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc ); + outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat; + #endif + #include + #include + #include + #include + #include + #include +}`,Nf=`#define TOON +varying vec3 vViewPosition; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vViewPosition = - mvPosition.xyz; + #include + #include + #include +}`,Ff=`#define TOON +uniform vec3 diffuse; +uniform vec3 emissive; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); + vec3 totalEmissiveRadiance = emissive; + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance; + #include + #include + #include + #include + #include + #include +}`,Bf=`uniform float size; +uniform float scale; +#include +#include +#include +#include +#include +#include +#ifdef USE_POINTS_UV + varying vec2 vUv; + uniform mat3 uvTransform; +#endif +void main() { + #ifdef USE_POINTS_UV + vUv = ( uvTransform * vec3( uv, 1 ) ).xy; + #endif + #include + #include + #include + #include + #include + #include + gl_PointSize = size; + #ifdef USE_SIZEATTENUATION + bool isPerspective = isPerspectiveMatrix( projectionMatrix ); + if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z ); + #endif + #include + #include + #include + #include +}`,Of=`uniform vec3 diffuse; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + vec3 outgoingLight = vec3( 0.0 ); + #include + #include + #include + #include + #include + outgoingLight = diffuseColor.rgb; + #include + #include + #include + #include + #include +}`,zf=`#include +#include +#include +#include +#include +#include +#include +void main() { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include +}`,Vf=`uniform vec3 color; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + #include + gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) ); + #include + #include + #include +}`,kf=`uniform float rotation; +uniform vec2 center; +#include +#include +#include +#include +#include +void main() { + #include + vec4 mvPosition = modelViewMatrix[ 3 ]; + vec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) ); + #ifndef USE_SIZEATTENUATION + bool isPerspective = isPerspectiveMatrix( projectionMatrix ); + if ( isPerspective ) scale *= - mvPosition.z; + #endif + vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale; + vec2 rotatedPosition; + rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y; + rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y; + mvPosition.xy += rotatedPosition; + gl_Position = projectionMatrix * mvPosition; + #include + #include + #include +}`,Hf=`uniform vec3 diffuse; +uniform float opacity; +#include +#include +#include +#include +#include +#include +#include +#include +#include +void main() { + vec4 diffuseColor = vec4( diffuse, opacity ); + #include + vec3 outgoingLight = vec3( 0.0 ); + #include + #include + #include + #include + #include + outgoingLight = diffuseColor.rgb; + #include + #include + #include + #include +}`,Ut={alphahash_fragment:lu,alphahash_pars_fragment:hu,alphamap_fragment:uu,alphamap_pars_fragment:du,alphatest_fragment:fu,alphatest_pars_fragment:pu,aomap_fragment:mu,aomap_pars_fragment:gu,batching_pars_vertex:_u,batching_vertex:xu,begin_vertex:vu,beginnormal_vertex:Mu,bsdfs:yu,iridescence_fragment:Su,bumpmap_pars_fragment:Eu,clipping_planes_fragment:bu,clipping_planes_pars_fragment:Tu,clipping_planes_pars_vertex:Au,clipping_planes_vertex:wu,color_fragment:Ru,color_pars_fragment:Cu,color_pars_vertex:Iu,color_vertex:Pu,common:Lu,cube_uv_reflection_fragment:Du,defaultnormal_vertex:Uu,displacementmap_pars_vertex:Nu,displacementmap_vertex:Fu,emissivemap_fragment:Bu,emissivemap_pars_fragment:Ou,colorspace_fragment:zu,colorspace_pars_fragment:Vu,envmap_fragment:ku,envmap_common_pars_fragment:Hu,envmap_pars_fragment:Gu,envmap_pars_vertex:Wu,envmap_physical_pars_fragment:ed,envmap_vertex:Xu,fog_vertex:qu,fog_pars_vertex:Yu,fog_fragment:ju,fog_pars_fragment:Ku,gradientmap_pars_fragment:Zu,lightmap_pars_fragment:$u,lights_lambert_fragment:Ju,lights_lambert_pars_fragment:Qu,lights_pars_begin:td,lights_toon_fragment:nd,lights_toon_pars_fragment:id,lights_phong_fragment:sd,lights_phong_pars_fragment:rd,lights_physical_fragment:ad,lights_physical_pars_fragment:od,lights_fragment_begin:cd,lights_fragment_maps:ld,lights_fragment_end:hd,logdepthbuf_fragment:ud,logdepthbuf_pars_fragment:dd,logdepthbuf_pars_vertex:fd,logdepthbuf_vertex:pd,map_fragment:md,map_pars_fragment:gd,map_particle_fragment:_d,map_particle_pars_fragment:xd,metalnessmap_fragment:vd,metalnessmap_pars_fragment:Md,morphinstance_vertex:yd,morphcolor_vertex:Sd,morphnormal_vertex:Ed,morphtarget_pars_vertex:bd,morphtarget_vertex:Td,normal_fragment_begin:Ad,normal_fragment_maps:wd,normal_pars_fragment:Rd,normal_pars_vertex:Cd,normal_vertex:Id,normalmap_pars_fragment:Pd,clearcoat_normal_fragment_begin:Ld,clearcoat_normal_fragment_maps:Dd,clearcoat_pars_fragment:Ud,iridescence_pars_fragment:Nd,opaque_fragment:Fd,packing:Bd,premultiplied_alpha_fragment:Od,project_vertex:zd,dithering_fragment:Vd,dithering_pars_fragment:kd,roughnessmap_fragment:Hd,roughnessmap_pars_fragment:Gd,shadowmap_pars_fragment:Wd,shadowmap_pars_vertex:Xd,shadowmap_vertex:qd,shadowmask_pars_fragment:Yd,skinbase_vertex:jd,skinning_pars_vertex:Kd,skinning_vertex:Zd,skinnormal_vertex:$d,specularmap_fragment:Jd,specularmap_pars_fragment:Qd,tonemapping_fragment:tf,tonemapping_pars_fragment:ef,transmission_fragment:nf,transmission_pars_fragment:sf,uv_pars_fragment:rf,uv_pars_vertex:af,uv_vertex:of,worldpos_vertex:cf,background_vert:lf,background_frag:hf,backgroundCube_vert:uf,backgroundCube_frag:df,cube_vert:ff,cube_frag:pf,depth_vert:mf,depth_frag:gf,distanceRGBA_vert:_f,distanceRGBA_frag:xf,equirect_vert:vf,equirect_frag:Mf,linedashed_vert:yf,linedashed_frag:Sf,meshbasic_vert:Ef,meshbasic_frag:bf,meshlambert_vert:Tf,meshlambert_frag:Af,meshmatcap_vert:wf,meshmatcap_frag:Rf,meshnormal_vert:Cf,meshnormal_frag:If,meshphong_vert:Pf,meshphong_frag:Lf,meshphysical_vert:Df,meshphysical_frag:Uf,meshtoon_vert:Nf,meshtoon_frag:Ff,points_vert:Bf,points_frag:Of,shadow_vert:zf,shadow_frag:Vf,sprite_vert:kf,sprite_frag:Hf},et={common:{diffuse:{value:new Et(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new It},alphaMap:{value:null},alphaMapTransform:{value:new It},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new It}},envmap:{envMap:{value:null},envMapRotation:{value:new It},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new It}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new It}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new It},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new It},normalScale:{value:new Pt(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new It},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new It}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new It}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new It}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new Et(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new Et(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new It},alphaTest:{value:0},uvTransform:{value:new It}},sprite:{diffuse:{value:new Et(16777215)},opacity:{value:1},center:{value:new Pt(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new It},alphaMap:{value:null},alphaMapTransform:{value:new It},alphaTest:{value:0}}},$e={basic:{uniforms:ye([et.common,et.specularmap,et.envmap,et.aomap,et.lightmap,et.fog]),vertexShader:Ut.meshbasic_vert,fragmentShader:Ut.meshbasic_frag},lambert:{uniforms:ye([et.common,et.specularmap,et.envmap,et.aomap,et.lightmap,et.emissivemap,et.bumpmap,et.normalmap,et.displacementmap,et.fog,et.lights,{emissive:{value:new Et(0)}}]),vertexShader:Ut.meshlambert_vert,fragmentShader:Ut.meshlambert_frag},phong:{uniforms:ye([et.common,et.specularmap,et.envmap,et.aomap,et.lightmap,et.emissivemap,et.bumpmap,et.normalmap,et.displacementmap,et.fog,et.lights,{emissive:{value:new Et(0)},specular:{value:new Et(1118481)},shininess:{value:30}}]),vertexShader:Ut.meshphong_vert,fragmentShader:Ut.meshphong_frag},standard:{uniforms:ye([et.common,et.envmap,et.aomap,et.lightmap,et.emissivemap,et.bumpmap,et.normalmap,et.displacementmap,et.roughnessmap,et.metalnessmap,et.fog,et.lights,{emissive:{value:new Et(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Ut.meshphysical_vert,fragmentShader:Ut.meshphysical_frag},toon:{uniforms:ye([et.common,et.aomap,et.lightmap,et.emissivemap,et.bumpmap,et.normalmap,et.displacementmap,et.gradientmap,et.fog,et.lights,{emissive:{value:new Et(0)}}]),vertexShader:Ut.meshtoon_vert,fragmentShader:Ut.meshtoon_frag},matcap:{uniforms:ye([et.common,et.bumpmap,et.normalmap,et.displacementmap,et.fog,{matcap:{value:null}}]),vertexShader:Ut.meshmatcap_vert,fragmentShader:Ut.meshmatcap_frag},points:{uniforms:ye([et.points,et.fog]),vertexShader:Ut.points_vert,fragmentShader:Ut.points_frag},dashed:{uniforms:ye([et.common,et.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Ut.linedashed_vert,fragmentShader:Ut.linedashed_frag},depth:{uniforms:ye([et.common,et.displacementmap]),vertexShader:Ut.depth_vert,fragmentShader:Ut.depth_frag},normal:{uniforms:ye([et.common,et.bumpmap,et.normalmap,et.displacementmap,{opacity:{value:1}}]),vertexShader:Ut.meshnormal_vert,fragmentShader:Ut.meshnormal_frag},sprite:{uniforms:ye([et.sprite,et.fog]),vertexShader:Ut.sprite_vert,fragmentShader:Ut.sprite_frag},background:{uniforms:{uvTransform:{value:new It},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:Ut.background_vert,fragmentShader:Ut.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new It}},vertexShader:Ut.backgroundCube_vert,fragmentShader:Ut.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:Ut.cube_vert,fragmentShader:Ut.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Ut.equirect_vert,fragmentShader:Ut.equirect_frag},distanceRGBA:{uniforms:ye([et.common,et.displacementmap,{referencePosition:{value:new R},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Ut.distanceRGBA_vert,fragmentShader:Ut.distanceRGBA_frag},shadow:{uniforms:ye([et.lights,et.fog,{color:{value:new Et(0)},opacity:{value:1}}]),vertexShader:Ut.shadow_vert,fragmentShader:Ut.shadow_frag}};$e.physical={uniforms:ye([$e.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new It},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new It},clearcoatNormalScale:{value:new Pt(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new It},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new It},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new It},sheen:{value:0},sheenColor:{value:new Et(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new It},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new It},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new It},transmissionSamplerSize:{value:new Pt},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new It},attenuationDistance:{value:0},attenuationColor:{value:new Et(0)},specularColor:{value:new Et(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new It},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new It},anisotropyVector:{value:new Pt},anisotropyMap:{value:null},anisotropyMapTransform:{value:new It}}]),vertexShader:Ut.meshphysical_vert,fragmentShader:Ut.meshphysical_frag};const Ms={r:0,b:0,g:0},kn=new je,Gf=new Lt;function Wf(s,t,e,n,i,r,a){const o=new Et(0);let c=r===!0?0:1,l,h,u=null,d=0,p=null;function g(b){let E=b.isScene===!0?b.background:null;return E&&E.isTexture&&(E=(b.backgroundBlurriness>0?e:t).get(E)),E}function _(b){let E=!1;const x=g(b);x===null?f(o,c):x&&x.isColor&&(f(x,1),E=!0);const P=s.xr.getEnvironmentBlendMode();P==="additive"?n.buffers.color.setClear(0,0,0,1,a):P==="alpha-blend"&&n.buffers.color.setClear(0,0,0,0,a),(s.autoClear||E)&&(n.buffers.depth.setTest(!0),n.buffers.depth.setMask(!0),n.buffers.color.setMask(!0),s.clear(s.autoClearColor,s.autoClearDepth,s.autoClearStencil))}function m(b,E){const x=g(E);x&&(x.isCubeTexture||x.mapping===Zs)?(h===void 0&&(h=new Te(new $i(1,1,1),new Un({name:"BackgroundCubeMaterial",uniforms:bi($e.backgroundCube.uniforms),vertexShader:$e.backgroundCube.vertexShader,fragmentShader:$e.backgroundCube.fragmentShader,side:Ae,depthTest:!1,depthWrite:!1,fog:!1})),h.geometry.deleteAttribute("normal"),h.geometry.deleteAttribute("uv"),h.onBeforeRender=function(P,A,w){this.matrixWorld.copyPosition(w.matrixWorld)},Object.defineProperty(h.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),i.update(h)),kn.copy(E.backgroundRotation),kn.x*=-1,kn.y*=-1,kn.z*=-1,x.isCubeTexture&&x.isRenderTargetTexture===!1&&(kn.y*=-1,kn.z*=-1),h.material.uniforms.envMap.value=x,h.material.uniforms.flipEnvMap.value=x.isCubeTexture&&x.isRenderTargetTexture===!1?-1:1,h.material.uniforms.backgroundBlurriness.value=E.backgroundBlurriness,h.material.uniforms.backgroundIntensity.value=E.backgroundIntensity,h.material.uniforms.backgroundRotation.value.setFromMatrix4(Gf.makeRotationFromEuler(kn)),h.material.toneMapped=Vt.getTransfer(x.colorSpace)!==$t,(u!==x||d!==x.version||p!==s.toneMapping)&&(h.material.needsUpdate=!0,u=x,d=x.version,p=s.toneMapping),h.layers.enableAll(),b.unshift(h,h.geometry,h.material,0,0,null)):x&&x.isTexture&&(l===void 0&&(l=new Te(new tr(2,2),new Un({name:"BackgroundMaterial",uniforms:bi($e.background.uniforms),vertexShader:$e.background.vertexShader,fragmentShader:$e.background.fragmentShader,side:Pn,depthTest:!1,depthWrite:!1,fog:!1})),l.geometry.deleteAttribute("normal"),Object.defineProperty(l.material,"map",{get:function(){return this.uniforms.t2D.value}}),i.update(l)),l.material.uniforms.t2D.value=x,l.material.uniforms.backgroundIntensity.value=E.backgroundIntensity,l.material.toneMapped=Vt.getTransfer(x.colorSpace)!==$t,x.matrixAutoUpdate===!0&&x.updateMatrix(),l.material.uniforms.uvTransform.value.copy(x.matrix),(u!==x||d!==x.version||p!==s.toneMapping)&&(l.material.needsUpdate=!0,u=x,d=x.version,p=s.toneMapping),l.layers.enableAll(),b.unshift(l,l.geometry,l.material,0,0,null))}function f(b,E){b.getRGB(Ms,Zc(s)),n.buffers.color.setClear(Ms.r,Ms.g,Ms.b,E,a)}return{getClearColor:function(){return o},setClearColor:function(b,E=1){o.set(b),c=E,f(o,c)},getClearAlpha:function(){return c},setClearAlpha:function(b){c=b,f(o,c)},render:_,addToRenderList:m}}function Xf(s,t){const e=s.getParameter(s.MAX_VERTEX_ATTRIBS),n={},i=d(null);let r=i,a=!1;function o(v,I,V,B,G){let K=!1;const W=u(B,V,I);r!==W&&(r=W,l(r.object)),K=p(v,B,V,G),K&&g(v,B,V,G),G!==null&&t.update(G,s.ELEMENT_ARRAY_BUFFER),(K||a)&&(a=!1,x(v,I,V,B),G!==null&&s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,t.get(G).buffer))}function c(){return s.createVertexArray()}function l(v){return s.bindVertexArray(v)}function h(v){return s.deleteVertexArray(v)}function u(v,I,V){const B=V.wireframe===!0;let G=n[v.id];G===void 0&&(G={},n[v.id]=G);let K=G[I.id];K===void 0&&(K={},G[I.id]=K);let W=K[B];return W===void 0&&(W=d(c()),K[B]=W),W}function d(v){const I=[],V=[],B=[];for(let G=0;G=0){const lt=G[H];let vt=K[H];if(vt===void 0&&(H==="instanceMatrix"&&v.instanceMatrix&&(vt=v.instanceMatrix),H==="instanceColor"&&v.instanceColor&&(vt=v.instanceColor)),lt===void 0||lt.attribute!==vt||vt&<.data!==vt.data)return!0;W++}return r.attributesNum!==W||r.index!==B}function g(v,I,V,B){const G={},K=I.attributes;let W=0;const Q=V.getAttributes();for(const H in Q)if(Q[H].location>=0){let lt=K[H];lt===void 0&&(H==="instanceMatrix"&&v.instanceMatrix&&(lt=v.instanceMatrix),H==="instanceColor"&&v.instanceColor&&(lt=v.instanceColor));const vt={};vt.attribute=lt,lt&<.data&&(vt.data=lt.data),G[H]=vt,W++}r.attributes=G,r.attributesNum=W,r.index=B}function _(){const v=r.newAttributes;for(let I=0,V=v.length;I=0){let it=G[Q];if(it===void 0&&(Q==="instanceMatrix"&&v.instanceMatrix&&(it=v.instanceMatrix),Q==="instanceColor"&&v.instanceColor&&(it=v.instanceColor)),it!==void 0){const lt=it.normalized,vt=it.itemSize,Nt=t.get(it);if(Nt===void 0)continue;const Jt=Nt.buffer,q=Nt.type,tt=Nt.bytesPerElement,gt=q===s.INT||q===s.UNSIGNED_INT||it.gpuType===Oa;if(it.isInterleavedBufferAttribute){const st=it.data,bt=st.stride,wt=it.offset;if(st.isInstancedInterleavedBuffer){for(let Ft=0;Ft0&&s.getShaderPrecisionFormat(s.FRAGMENT_SHADER,s.HIGH_FLOAT).precision>0)return"highp";w="mediump"}return w==="mediump"&&s.getShaderPrecisionFormat(s.VERTEX_SHADER,s.MEDIUM_FLOAT).precision>0&&s.getShaderPrecisionFormat(s.FRAGMENT_SHADER,s.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let l=e.precision!==void 0?e.precision:"highp";const h=c(l);h!==l&&(console.warn("THREE.WebGLRenderer:",l,"not supported, using",h,"instead."),l=h);const u=e.logarithmicDepthBuffer===!0,d=e.reverseDepthBuffer===!0&&t.has("EXT_clip_control"),p=s.getParameter(s.MAX_TEXTURE_IMAGE_UNITS),g=s.getParameter(s.MAX_VERTEX_TEXTURE_IMAGE_UNITS),_=s.getParameter(s.MAX_TEXTURE_SIZE),m=s.getParameter(s.MAX_CUBE_MAP_TEXTURE_SIZE),f=s.getParameter(s.MAX_VERTEX_ATTRIBS),b=s.getParameter(s.MAX_VERTEX_UNIFORM_VECTORS),E=s.getParameter(s.MAX_VARYING_VECTORS),x=s.getParameter(s.MAX_FRAGMENT_UNIFORM_VECTORS),P=g>0,A=s.getParameter(s.MAX_SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:r,getMaxPrecision:c,textureFormatReadable:a,textureTypeReadable:o,precision:l,logarithmicDepthBuffer:u,reverseDepthBuffer:d,maxTextures:p,maxVertexTextures:g,maxTextureSize:_,maxCubemapSize:m,maxAttributes:f,maxVertexUniforms:b,maxVaryings:E,maxFragmentUniforms:x,vertexTextures:P,maxSamples:A}}function jf(s){const t=this;let e=null,n=0,i=!1,r=!1;const a=new ln,o=new It,c={value:null,needsUpdate:!1};this.uniform=c,this.numPlanes=0,this.numIntersection=0,this.init=function(u,d){const p=u.length!==0||d||n!==0||i;return i=d,n=u.length,p},this.beginShadows=function(){r=!0,h(null)},this.endShadows=function(){r=!1},this.setGlobalState=function(u,d){e=h(u,d,0)},this.setState=function(u,d,p){const g=u.clippingPlanes,_=u.clipIntersection,m=u.clipShadows,f=s.get(u);if(!i||g===null||g.length===0||r&&!m)r?h(null):l();else{const b=r?0:n,E=b*4;let x=f.clippingState||null;c.value=x,x=h(g,d,E,p);for(let P=0;P!==E;++P)x[P]=e[P];f.clippingState=x,this.numIntersection=_?this.numPlanes:0,this.numPlanes+=b}};function l(){c.value!==e&&(c.value=e,c.needsUpdate=n>0),t.numPlanes=n,t.numIntersection=0}function h(u,d,p,g){const _=u!==null?u.length:0;let m=null;if(_!==0){if(m=c.value,g!==!0||m===null){const f=p+_*4,b=d.matrixWorldInverse;o.getNormalMatrix(b),(m===null||m.length0){const l=new ru(c.height);return l.fromEquirectangularTexture(s,a),t.set(a,l),a.addEventListener("dispose",i),e(l.texture,a.mapping)}else return null}}return a}function i(a){const o=a.target;o.removeEventListener("dispose",i);const c=t.get(o);c!==void 0&&(t.delete(o),c.dispose())}function r(){t=new WeakMap}return{get:n,dispose:r}}class tl extends $c{constructor(t=-1,e=1,n=1,i=-1,r=.1,a=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=n,this.bottom=i,this.near=r,this.far=a,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom,this.near=t.near,this.far=t.far,this.zoom=t.zoom,this.view=t.view===null?null:Object.assign({},t.view),this}setViewOffset(t,e,n,i,r,a){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=n,this.view.offsetY=i,this.view.width=r,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=(this.right-this.left)/(2*this.zoom),e=(this.top-this.bottom)/(2*this.zoom),n=(this.right+this.left)/2,i=(this.top+this.bottom)/2;let r=n-t,a=n+t,o=i+e,c=i-e;if(this.view!==null&&this.view.enabled){const l=(this.right-this.left)/this.view.fullWidth/this.zoom,h=(this.top-this.bottom)/this.view.fullHeight/this.zoom;r+=l*this.view.offsetX,a=r+l*this.view.width,o-=h*this.view.offsetY,c=o-h*this.view.height}this.projectionMatrix.makeOrthographic(r,a,o,c,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,this.view!==null&&(e.object.view=Object.assign({},this.view)),e}}const fi=4,Uo=[.125,.215,.35,.446,.526,.582],Yn=20,Cr=new tl,No=new Et;let Ir=null,Pr=0,Lr=0,Dr=!1;const Xn=(1+Math.sqrt(5))/2,li=1/Xn,Fo=[new R(-Xn,li,0),new R(Xn,li,0),new R(-li,0,Xn),new R(li,0,Xn),new R(0,Xn,-li),new R(0,Xn,li),new R(-1,1,-1),new R(1,1,-1),new R(-1,1,1),new R(1,1,1)];class Bo{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._compileMaterial(this._blurMaterial)}fromScene(t,e=0,n=.1,i=100){Ir=this._renderer.getRenderTarget(),Pr=this._renderer.getActiveCubeFace(),Lr=this._renderer.getActiveMipmapLevel(),Dr=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(256);const r=this._allocateTargets();return r.depthBuffer=!0,this._sceneToCubeUV(t,n,i,r),e>0&&this._blur(r,0,0,e),this._applyPMREM(r),this._cleanup(r),r}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=Vo(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=zo(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose()}_setSize(t){this._lodMax=Math.floor(Math.log2(t)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let t=0;t2?E:0,E,E),h.setRenderTarget(i),_&&h.render(g,o),h.render(t,o)}g.geometry.dispose(),g.material.dispose(),h.toneMapping=d,h.autoClear=u,t.background=m}_textureToCubeUV(t,e){const n=this._renderer,i=t.mapping===vi||t.mapping===Mi;i?(this._cubemapMaterial===null&&(this._cubemapMaterial=Vo()),this._cubemapMaterial.uniforms.flipEnvMap.value=t.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=zo());const r=i?this._cubemapMaterial:this._equirectMaterial,a=new Te(this._lodPlanes[0],r),o=r.uniforms;o.envMap.value=t;const c=this._cubeSize;ys(e,0,0,3*c,2*c),n.setRenderTarget(e),n.render(a,Cr)}_applyPMREM(t){const e=this._renderer,n=e.autoClear;e.autoClear=!1;const i=this._lodPlanes.length;for(let r=1;rYn&&console.warn(`sigmaRadians, ${r}, is too large and will clip, as it requested ${m} samples when the maximum is set to ${Yn}`);const f=[];let b=0;for(let w=0;wE-fi?i-E+fi:0),A=4*(this._cubeSize-x);ys(e,P,A,3*x,2*x),c.setRenderTarget(e),c.render(u,Cr)}}function Zf(s){const t=[],e=[],n=[];let i=s;const r=s-fi+1+Uo.length;for(let a=0;as-fi?c=Uo[a-s+fi-1]:a===0&&(c=0),n.push(c);const l=1/(o-2),h=-l,u=1+l,d=[h,h,u,h,u,u,h,h,u,u,h,u],p=6,g=6,_=3,m=2,f=1,b=new Float32Array(_*g*p),E=new Float32Array(m*g*p),x=new Float32Array(f*g*p);for(let A=0;A2?0:-1,y=[w,C,0,w+2/3,C,0,w+2/3,C+1,0,w,C,0,w+2/3,C+1,0,w,C+1,0];b.set(y,_*g*A),E.set(d,m*g*A);const v=[A,A,A,A,A,A];x.set(v,f*g*A)}const P=new ce;P.setAttribute("position",new pe(b,_)),P.setAttribute("uv",new pe(E,m)),P.setAttribute("faceIndex",new pe(x,f)),t.push(P),i>fi&&i--}return{lodPlanes:t,sizeLods:e,sigmas:n}}function Oo(s,t,e){const n=new Dn(s,t,e);return n.texture.mapping=Zs,n.texture.name="PMREM.cubeUv",n.scissorTest=!0,n}function ys(s,t,e,n,i){s.viewport.set(t,e,n,i),s.scissor.set(t,e,n,i)}function $f(s,t,e){const n=new Float32Array(Yn),i=new R(0,1,0);return new Un({name:"SphericalGaussianBlur",defines:{n:Yn,CUBEUV_TEXEL_WIDTH:1/t,CUBEUV_TEXEL_HEIGHT:1/e,CUBEUV_MAX_MIP:`${s}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:n},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:i}},vertexShader:Ya(),fragmentShader:` + + precision mediump float; + precision mediump int; + + varying vec3 vOutputDirection; + + uniform sampler2D envMap; + uniform int samples; + uniform float weights[ n ]; + uniform bool latitudinal; + uniform float dTheta; + uniform float mipInt; + uniform vec3 poleAxis; + + #define ENVMAP_TYPE_CUBE_UV + #include + + vec3 getSample( float theta, vec3 axis ) { + + float cosTheta = cos( theta ); + // Rodrigues' axis-angle rotation + vec3 sampleDirection = vOutputDirection * cosTheta + + cross( axis, vOutputDirection ) * sin( theta ) + + axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta ); + + return bilinearCubeUV( envMap, sampleDirection, mipInt ); + + } + + void main() { + + vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection ); + + if ( all( equal( axis, vec3( 0.0 ) ) ) ) { + + axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x ); + + } + + axis = normalize( axis ); + + gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 ); + gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis ); + + for ( int i = 1; i < n; i++ ) { + + if ( i >= samples ) { + + break; + + } + + float theta = dTheta * float( i ); + gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis ); + gl_FragColor.rgb += weights[ i ] * getSample( theta, axis ); + + } + + } + `,blending:Cn,depthTest:!1,depthWrite:!1})}function zo(){return new Un({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:Ya(),fragmentShader:` + + precision mediump float; + precision mediump int; + + varying vec3 vOutputDirection; + + uniform sampler2D envMap; + + #include + + void main() { + + vec3 outputDirection = normalize( vOutputDirection ); + vec2 uv = equirectUv( outputDirection ); + + gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 ); + + } + `,blending:Cn,depthTest:!1,depthWrite:!1})}function Vo(){return new Un({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:Ya(),fragmentShader:` + + precision mediump float; + precision mediump int; + + uniform float flipEnvMap; + + varying vec3 vOutputDirection; + + uniform samplerCube envMap; + + void main() { + + gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) ); + + } + `,blending:Cn,depthTest:!1,depthWrite:!1})}function Ya(){return` + + precision mediump float; + precision mediump int; + + attribute float faceIndex; + + varying vec3 vOutputDirection; + + // RH coordinate system; PMREM face-indexing convention + vec3 getDirection( vec2 uv, float face ) { + + uv = 2.0 * uv - 1.0; + + vec3 direction = vec3( uv, 1.0 ); + + if ( face == 0.0 ) { + + direction = direction.zyx; // ( 1, v, u ) pos x + + } else if ( face == 1.0 ) { + + direction = direction.xzy; + direction.xz *= -1.0; // ( -u, 1, -v ) pos y + + } else if ( face == 2.0 ) { + + direction.x *= -1.0; // ( -u, v, 1 ) pos z + + } else if ( face == 3.0 ) { + + direction = direction.zyx; + direction.xz *= -1.0; // ( -1, v, -u ) neg x + + } else if ( face == 4.0 ) { + + direction = direction.xzy; + direction.xy *= -1.0; // ( -u, -1, v ) neg y + + } else if ( face == 5.0 ) { + + direction.z *= -1.0; // ( u, v, -1 ) neg z + + } + + return direction; + + } + + void main() { + + vOutputDirection = getDirection( uv, faceIndex ); + gl_Position = vec4( position, 1.0 ); + + } + `}function Jf(s){let t=new WeakMap,e=null;function n(o){if(o&&o.isTexture){const c=o.mapping,l=c===ea||c===na,h=c===vi||c===Mi;if(l||h){let u=t.get(o);const d=u!==void 0?u.texture.pmremVersion:0;if(o.isRenderTargetTexture&&o.pmremVersion!==d)return e===null&&(e=new Bo(s)),u=l?e.fromEquirectangular(o,u):e.fromCubemap(o,u),u.texture.pmremVersion=o.pmremVersion,t.set(o,u),u.texture;if(u!==void 0)return u.texture;{const p=o.image;return l&&p&&p.height>0||h&&p&&i(p)?(e===null&&(e=new Bo(s)),u=l?e.fromEquirectangular(o):e.fromCubemap(o),u.texture.pmremVersion=o.pmremVersion,t.set(o,u),o.addEventListener("dispose",r),u.texture):null}}}return o}function i(o){let c=0;const l=6;for(let h=0;ht.maxTextureSize&&(P=Math.ceil(x/t.maxTextureSize),x=t.maxTextureSize);const A=new Float32Array(x*P*4*u),w=new Wc(A,x,P,u);w.type=De,w.needsUpdate=!0;const C=E*4;for(let v=0;v0)return s;const i=t*e;let r=Ho[i];if(r===void 0&&(r=new Float32Array(i),Ho[i]=r),t!==0){n.toArray(r,0);for(let a=1,o=0;a!==t;++a)o+=e,s[a].toArray(r,o)}return r}function ue(s,t){if(s.length!==t.length)return!1;for(let e=0,n=s.length;e":" "} ${o}: ${e[a]}`)}return n.join(` +`)}const Ko=new It;function Jp(s){Vt._getMatrix(Ko,Vt.workingColorSpace,s);const t=`mat3( ${Ko.elements.map(e=>e.toFixed(4))} )`;switch(Vt.getTransfer(s)){case Js:return[t,"LinearTransferOETF"];case $t:return[t,"sRGBTransferOETF"];default:return console.warn("THREE.WebGLProgram: Unsupported color space: ",s),[t,"LinearTransferOETF"]}}function Zo(s,t,e){const n=s.getShaderParameter(t,s.COMPILE_STATUS),i=s.getShaderInfoLog(t).trim();if(n&&i==="")return"";const r=/ERROR: 0:(\d+)/.exec(i);if(r){const a=parseInt(r[1]);return e.toUpperCase()+` + +`+i+` + +`+$p(s.getShaderSource(t),a)}else return i}function Qp(s,t){const e=Jp(t);return[`vec4 ${s}( vec4 value ) {`,` return ${e[1]}( vec4( value.rgb * ${e[0]}, value.a ) );`,"}"].join(` +`)}function tm(s,t){let e;switch(t){case jl:e="Linear";break;case Kl:e="Reinhard";break;case Zl:e="Cineon";break;case $l:e="ACESFilmic";break;case Ql:e="AgX";break;case th:e="Neutral";break;case Jl:e="Custom";break;default:console.warn("THREE.WebGLProgram: Unsupported toneMapping:",t),e="Linear"}return"vec3 "+s+"( vec3 color ) { return "+e+"ToneMapping( color ); }"}const Ss=new R;function em(){Vt.getLuminanceCoefficients(Ss);const s=Ss.x.toFixed(4),t=Ss.y.toFixed(4),e=Ss.z.toFixed(4);return["float luminance( const in vec3 rgb ) {",` const vec3 weights = vec3( ${s}, ${t}, ${e} );`," return dot( weights, rgb );","}"].join(` +`)}function nm(s){return[s.extensionClipCullDistance?"#extension GL_ANGLE_clip_cull_distance : require":"",s.extensionMultiDraw?"#extension GL_ANGLE_multi_draw : require":""].filter(Hi).join(` +`)}function im(s){const t=[];for(const e in s){const n=s[e];n!==!1&&t.push("#define "+e+" "+n)}return t.join(` +`)}function sm(s,t){const e={},n=s.getProgramParameter(t,s.ACTIVE_ATTRIBUTES);for(let i=0;i/gm;function Da(s){return s.replace(rm,om)}const am=new Map;function om(s,t){let e=Ut[t];if(e===void 0){const n=am.get(t);if(n!==void 0)e=Ut[n],console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',t,n);else throw new Error("Can not resolve #include <"+t+">")}return Da(e)}const cm=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function Qo(s){return s.replace(cm,lm)}function lm(s,t,e,n){let i="";for(let r=parseInt(t);r0&&(m+=` +`),f=["#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,g].filter(Hi).join(` +`),f.length>0&&(f+=` +`)):(m=[tc(e),"#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,g,e.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",e.batching?"#define USE_BATCHING":"",e.batchingColor?"#define USE_BATCHING_COLOR":"",e.instancing?"#define USE_INSTANCING":"",e.instancingColor?"#define USE_INSTANCING_COLOR":"",e.instancingMorph?"#define USE_INSTANCING_MORPH":"",e.useFog&&e.fog?"#define USE_FOG":"",e.useFog&&e.fogExp2?"#define FOG_EXP2":"",e.map?"#define USE_MAP":"",e.envMap?"#define USE_ENVMAP":"",e.envMap?"#define "+h:"",e.lightMap?"#define USE_LIGHTMAP":"",e.aoMap?"#define USE_AOMAP":"",e.bumpMap?"#define USE_BUMPMAP":"",e.normalMap?"#define USE_NORMALMAP":"",e.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",e.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",e.displacementMap?"#define USE_DISPLACEMENTMAP":"",e.emissiveMap?"#define USE_EMISSIVEMAP":"",e.anisotropy?"#define USE_ANISOTROPY":"",e.anisotropyMap?"#define USE_ANISOTROPYMAP":"",e.clearcoatMap?"#define USE_CLEARCOATMAP":"",e.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",e.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",e.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",e.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",e.specularMap?"#define USE_SPECULARMAP":"",e.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",e.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",e.roughnessMap?"#define USE_ROUGHNESSMAP":"",e.metalnessMap?"#define USE_METALNESSMAP":"",e.alphaMap?"#define USE_ALPHAMAP":"",e.alphaHash?"#define USE_ALPHAHASH":"",e.transmission?"#define USE_TRANSMISSION":"",e.transmissionMap?"#define USE_TRANSMISSIONMAP":"",e.thicknessMap?"#define USE_THICKNESSMAP":"",e.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",e.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",e.mapUv?"#define MAP_UV "+e.mapUv:"",e.alphaMapUv?"#define ALPHAMAP_UV "+e.alphaMapUv:"",e.lightMapUv?"#define LIGHTMAP_UV "+e.lightMapUv:"",e.aoMapUv?"#define AOMAP_UV "+e.aoMapUv:"",e.emissiveMapUv?"#define EMISSIVEMAP_UV "+e.emissiveMapUv:"",e.bumpMapUv?"#define BUMPMAP_UV "+e.bumpMapUv:"",e.normalMapUv?"#define NORMALMAP_UV "+e.normalMapUv:"",e.displacementMapUv?"#define DISPLACEMENTMAP_UV "+e.displacementMapUv:"",e.metalnessMapUv?"#define METALNESSMAP_UV "+e.metalnessMapUv:"",e.roughnessMapUv?"#define ROUGHNESSMAP_UV "+e.roughnessMapUv:"",e.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+e.anisotropyMapUv:"",e.clearcoatMapUv?"#define CLEARCOATMAP_UV "+e.clearcoatMapUv:"",e.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+e.clearcoatNormalMapUv:"",e.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+e.clearcoatRoughnessMapUv:"",e.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+e.iridescenceMapUv:"",e.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+e.iridescenceThicknessMapUv:"",e.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+e.sheenColorMapUv:"",e.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+e.sheenRoughnessMapUv:"",e.specularMapUv?"#define SPECULARMAP_UV "+e.specularMapUv:"",e.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+e.specularColorMapUv:"",e.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+e.specularIntensityMapUv:"",e.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+e.transmissionMapUv:"",e.thicknessMapUv?"#define THICKNESSMAP_UV "+e.thicknessMapUv:"",e.vertexTangents&&e.flatShading===!1?"#define USE_TANGENT":"",e.vertexColors?"#define USE_COLOR":"",e.vertexAlphas?"#define USE_COLOR_ALPHA":"",e.vertexUv1s?"#define USE_UV1":"",e.vertexUv2s?"#define USE_UV2":"",e.vertexUv3s?"#define USE_UV3":"",e.pointsUvs?"#define USE_POINTS_UV":"",e.flatShading?"#define FLAT_SHADED":"",e.skinning?"#define USE_SKINNING":"",e.morphTargets?"#define USE_MORPHTARGETS":"",e.morphNormals&&e.flatShading===!1?"#define USE_MORPHNORMALS":"",e.morphColors?"#define USE_MORPHCOLORS":"",e.morphTargetsCount>0?"#define MORPHTARGETS_TEXTURE_STRIDE "+e.morphTextureStride:"",e.morphTargetsCount>0?"#define MORPHTARGETS_COUNT "+e.morphTargetsCount:"",e.doubleSided?"#define DOUBLE_SIDED":"",e.flipSided?"#define FLIP_SIDED":"",e.shadowMapEnabled?"#define USE_SHADOWMAP":"",e.shadowMapEnabled?"#define "+c:"",e.sizeAttenuation?"#define USE_SIZEATTENUATION":"",e.numLightProbes>0?"#define USE_LIGHT_PROBES":"",e.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",e.reverseDepthBuffer?"#define USE_REVERSEDEPTHBUF":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING"," attribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR"," attribute vec3 instanceColor;","#endif","#ifdef USE_INSTANCING_MORPH"," uniform sampler2D morphTexture;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1"," attribute vec2 uv1;","#endif","#ifdef USE_UV2"," attribute vec2 uv2;","#endif","#ifdef USE_UV3"," attribute vec2 uv3;","#endif","#ifdef USE_TANGENT"," attribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )"," attribute vec4 color;","#elif defined( USE_COLOR )"," attribute vec3 color;","#endif","#ifdef USE_SKINNING"," attribute vec4 skinIndex;"," attribute vec4 skinWeight;","#endif",` +`].filter(Hi).join(` +`),f=[tc(e),"#define SHADER_TYPE "+e.shaderType,"#define SHADER_NAME "+e.shaderName,g,e.useFog&&e.fog?"#define USE_FOG":"",e.useFog&&e.fogExp2?"#define FOG_EXP2":"",e.alphaToCoverage?"#define ALPHA_TO_COVERAGE":"",e.map?"#define USE_MAP":"",e.matcap?"#define USE_MATCAP":"",e.envMap?"#define USE_ENVMAP":"",e.envMap?"#define "+l:"",e.envMap?"#define "+h:"",e.envMap?"#define "+u:"",d?"#define CUBEUV_TEXEL_WIDTH "+d.texelWidth:"",d?"#define CUBEUV_TEXEL_HEIGHT "+d.texelHeight:"",d?"#define CUBEUV_MAX_MIP "+d.maxMip+".0":"",e.lightMap?"#define USE_LIGHTMAP":"",e.aoMap?"#define USE_AOMAP":"",e.bumpMap?"#define USE_BUMPMAP":"",e.normalMap?"#define USE_NORMALMAP":"",e.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",e.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",e.emissiveMap?"#define USE_EMISSIVEMAP":"",e.anisotropy?"#define USE_ANISOTROPY":"",e.anisotropyMap?"#define USE_ANISOTROPYMAP":"",e.clearcoat?"#define USE_CLEARCOAT":"",e.clearcoatMap?"#define USE_CLEARCOATMAP":"",e.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",e.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",e.dispersion?"#define USE_DISPERSION":"",e.iridescence?"#define USE_IRIDESCENCE":"",e.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",e.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",e.specularMap?"#define USE_SPECULARMAP":"",e.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",e.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",e.roughnessMap?"#define USE_ROUGHNESSMAP":"",e.metalnessMap?"#define USE_METALNESSMAP":"",e.alphaMap?"#define USE_ALPHAMAP":"",e.alphaTest?"#define USE_ALPHATEST":"",e.alphaHash?"#define USE_ALPHAHASH":"",e.sheen?"#define USE_SHEEN":"",e.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",e.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",e.transmission?"#define USE_TRANSMISSION":"",e.transmissionMap?"#define USE_TRANSMISSIONMAP":"",e.thicknessMap?"#define USE_THICKNESSMAP":"",e.vertexTangents&&e.flatShading===!1?"#define USE_TANGENT":"",e.vertexColors||e.instancingColor||e.batchingColor?"#define USE_COLOR":"",e.vertexAlphas?"#define USE_COLOR_ALPHA":"",e.vertexUv1s?"#define USE_UV1":"",e.vertexUv2s?"#define USE_UV2":"",e.vertexUv3s?"#define USE_UV3":"",e.pointsUvs?"#define USE_POINTS_UV":"",e.gradientMap?"#define USE_GRADIENTMAP":"",e.flatShading?"#define FLAT_SHADED":"",e.doubleSided?"#define DOUBLE_SIDED":"",e.flipSided?"#define FLIP_SIDED":"",e.shadowMapEnabled?"#define USE_SHADOWMAP":"",e.shadowMapEnabled?"#define "+c:"",e.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",e.numLightProbes>0?"#define USE_LIGHT_PROBES":"",e.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",e.decodeVideoTextureEmissive?"#define DECODE_VIDEO_TEXTURE_EMISSIVE":"",e.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",e.reverseDepthBuffer?"#define USE_REVERSEDEPTHBUF":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",e.toneMapping!==In?"#define TONE_MAPPING":"",e.toneMapping!==In?Ut.tonemapping_pars_fragment:"",e.toneMapping!==In?tm("toneMapping",e.toneMapping):"",e.dithering?"#define DITHERING":"",e.opaque?"#define OPAQUE":"",Ut.colorspace_pars_fragment,Qp("linearToOutputTexel",e.outputColorSpace),em(),e.useDepthPacking?"#define DEPTH_PACKING "+e.depthPacking:"",` +`].filter(Hi).join(` +`)),a=Da(a),a=$o(a,e),a=Jo(a,e),o=Da(o),o=$o(o,e),o=Jo(o,e),a=Qo(a),o=Qo(o),e.isRawShaderMaterial!==!0&&(b=`#version 300 es +`,m=[p,"#define attribute in","#define varying out","#define texture2D texture"].join(` +`)+` +`+m,f=["#define varying in",e.glslVersion===uo?"":"layout(location = 0) out highp vec4 pc_fragColor;",e.glslVersion===uo?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join(` +`)+` +`+f);const E=b+m+a,x=b+f+o,P=jo(i,i.VERTEX_SHADER,E),A=jo(i,i.FRAGMENT_SHADER,x);i.attachShader(_,P),i.attachShader(_,A),e.index0AttributeName!==void 0?i.bindAttribLocation(_,0,e.index0AttributeName):e.morphTargets===!0&&i.bindAttribLocation(_,0,"position"),i.linkProgram(_);function w(I){if(s.debug.checkShaderErrors){const V=i.getProgramInfoLog(_).trim(),B=i.getShaderInfoLog(P).trim(),G=i.getShaderInfoLog(A).trim();let K=!0,W=!0;if(i.getProgramParameter(_,i.LINK_STATUS)===!1)if(K=!1,typeof s.debug.onShaderError=="function")s.debug.onShaderError(i,_,P,A);else{const Q=Zo(i,P,"vertex"),H=Zo(i,A,"fragment");console.error("THREE.WebGLProgram: Shader Error "+i.getError()+" - VALIDATE_STATUS "+i.getProgramParameter(_,i.VALIDATE_STATUS)+` + +Material Name: `+I.name+` +Material Type: `+I.type+` + +Program Info Log: `+V+` +`+Q+` +`+H)}else V!==""?console.warn("THREE.WebGLProgram: Program Info Log:",V):(B===""||G==="")&&(W=!1);W&&(I.diagnostics={runnable:K,programLog:V,vertexShader:{log:B,prefix:m},fragmentShader:{log:G,prefix:f}})}i.deleteShader(P),i.deleteShader(A),C=new ks(i,_),y=sm(i,_)}let C;this.getUniforms=function(){return C===void 0&&w(this),C};let y;this.getAttributes=function(){return y===void 0&&w(this),y};let v=e.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return v===!1&&(v=i.getProgramParameter(_,Kp)),v},this.destroy=function(){n.releaseStatesOfProgram(this),i.deleteProgram(_),this.program=void 0},this.type=e.shaderType,this.name=e.shaderName,this.id=Zp++,this.cacheKey=t,this.usedTimes=1,this.program=_,this.vertexShader=P,this.fragmentShader=A,this}let gm=0;class _m{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(t){const e=t.vertexShader,n=t.fragmentShader,i=this._getShaderStage(e),r=this._getShaderStage(n),a=this._getShaderCacheForMaterial(t);return a.has(i)===!1&&(a.add(i),i.usedTimes++),a.has(r)===!1&&(a.add(r),r.usedTimes++),this}remove(t){const e=this.materialCache.get(t);for(const n of e)n.usedTimes--,n.usedTimes===0&&this.shaderCache.delete(n.code);return this.materialCache.delete(t),this}getVertexShaderID(t){return this._getShaderStage(t.vertexShader).id}getFragmentShaderID(t){return this._getShaderStage(t.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(t){const e=this.materialCache;let n=e.get(t);return n===void 0&&(n=new Set,e.set(t,n)),n}_getShaderStage(t){const e=this.shaderCache;let n=e.get(t);return n===void 0&&(n=new xm(t),e.set(t,n)),n}}class xm{constructor(t){this.id=gm++,this.code=t,this.usedTimes=0}}function vm(s,t,e,n,i,r,a){const o=new qa,c=new _m,l=new Set,h=[],u=i.logarithmicDepthBuffer,d=i.vertexTextures;let p=i.precision;const g={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distanceRGBA",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function _(y){return l.add(y),y===0?"uv":`uv${y}`}function m(y,v,I,V,B){const G=V.fog,K=B.geometry,W=y.isMeshStandardMaterial?V.environment:null,Q=(y.isMeshStandardMaterial?e:t).get(y.envMap||W),H=Q&&Q.mapping===Zs?Q.image.height:null,it=g[y.type];y.precision!==null&&(p=i.getMaxPrecision(y.precision),p!==y.precision&&console.warn("THREE.WebGLProgram.getParameters:",y.precision,"not supported, using",p,"instead."));const lt=K.morphAttributes.position||K.morphAttributes.normal||K.morphAttributes.color,vt=lt!==void 0?lt.length:0;let Nt=0;K.morphAttributes.position!==void 0&&(Nt=1),K.morphAttributes.normal!==void 0&&(Nt=2),K.morphAttributes.color!==void 0&&(Nt=3);let Jt,q,tt,gt;if(it){const jt=$e[it];Jt=jt.vertexShader,q=jt.fragmentShader}else Jt=y.vertexShader,q=y.fragmentShader,c.update(y),tt=c.getVertexShaderID(y),gt=c.getFragmentShaderID(y);const st=s.getRenderTarget(),bt=s.state.buffers.depth.getReversed(),wt=B.isInstancedMesh===!0,Ft=B.isBatchedMesh===!0,se=!!y.map,kt=!!y.matcap,oe=!!Q,N=!!y.aoMap,Fe=!!y.lightMap,Bt=!!y.bumpMap,Ot=!!y.normalMap,yt=!!y.displacementMap,ee=!!y.emissiveMap,Mt=!!y.metalnessMap,T=!!y.roughnessMap,M=y.anisotropy>0,F=y.clearcoat>0,Y=y.dispersion>0,Z=y.iridescence>0,X=y.sheen>0,_t=y.transmission>0,rt=M&&!!y.anisotropyMap,ht=F&&!!y.clearcoatMap,Ht=F&&!!y.clearcoatNormalMap,$=F&&!!y.clearcoatRoughnessMap,ut=Z&&!!y.iridescenceMap,St=Z&&!!y.iridescenceThicknessMap,Tt=X&&!!y.sheenColorMap,dt=X&&!!y.sheenRoughnessMap,zt=!!y.specularMap,Dt=!!y.specularColorMap,Qt=!!y.specularIntensityMap,L=_t&&!!y.transmissionMap,nt=_t&&!!y.thicknessMap,k=!!y.gradientMap,j=!!y.alphaMap,ct=y.alphaTest>0,at=!!y.alphaHash,Rt=!!y.extensions;let re=In;y.toneMapped&&(st===null||st.isXRRenderTarget===!0)&&(re=s.toneMapping);const me={shaderID:it,shaderType:y.type,shaderName:y.name,vertexShader:Jt,fragmentShader:q,defines:y.defines,customVertexShaderID:tt,customFragmentShaderID:gt,isRawShaderMaterial:y.isRawShaderMaterial===!0,glslVersion:y.glslVersion,precision:p,batching:Ft,batchingColor:Ft&&B._colorsTexture!==null,instancing:wt,instancingColor:wt&&B.instanceColor!==null,instancingMorph:wt&&B.morphTexture!==null,supportsVertexTextures:d,outputColorSpace:st===null?s.outputColorSpace:st.isXRRenderTarget===!0?st.texture.colorSpace:Ti,alphaToCoverage:!!y.alphaToCoverage,map:se,matcap:kt,envMap:oe,envMapMode:oe&&Q.mapping,envMapCubeUVHeight:H,aoMap:N,lightMap:Fe,bumpMap:Bt,normalMap:Ot,displacementMap:d&&yt,emissiveMap:ee,normalMapObjectSpace:Ot&&y.normalMapType===lh,normalMapTangentSpace:Ot&&y.normalMapType===Ki,metalnessMap:Mt,roughnessMap:T,anisotropy:M,anisotropyMap:rt,clearcoat:F,clearcoatMap:ht,clearcoatNormalMap:Ht,clearcoatRoughnessMap:$,dispersion:Y,iridescence:Z,iridescenceMap:ut,iridescenceThicknessMap:St,sheen:X,sheenColorMap:Tt,sheenRoughnessMap:dt,specularMap:zt,specularColorMap:Dt,specularIntensityMap:Qt,transmission:_t,transmissionMap:L,thicknessMap:nt,gradientMap:k,opaque:y.transparent===!1&&y.blending===pi&&y.alphaToCoverage===!1,alphaMap:j,alphaTest:ct,alphaHash:at,combine:y.combine,mapUv:se&&_(y.map.channel),aoMapUv:N&&_(y.aoMap.channel),lightMapUv:Fe&&_(y.lightMap.channel),bumpMapUv:Bt&&_(y.bumpMap.channel),normalMapUv:Ot&&_(y.normalMap.channel),displacementMapUv:yt&&_(y.displacementMap.channel),emissiveMapUv:ee&&_(y.emissiveMap.channel),metalnessMapUv:Mt&&_(y.metalnessMap.channel),roughnessMapUv:T&&_(y.roughnessMap.channel),anisotropyMapUv:rt&&_(y.anisotropyMap.channel),clearcoatMapUv:ht&&_(y.clearcoatMap.channel),clearcoatNormalMapUv:Ht&&_(y.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:$&&_(y.clearcoatRoughnessMap.channel),iridescenceMapUv:ut&&_(y.iridescenceMap.channel),iridescenceThicknessMapUv:St&&_(y.iridescenceThicknessMap.channel),sheenColorMapUv:Tt&&_(y.sheenColorMap.channel),sheenRoughnessMapUv:dt&&_(y.sheenRoughnessMap.channel),specularMapUv:zt&&_(y.specularMap.channel),specularColorMapUv:Dt&&_(y.specularColorMap.channel),specularIntensityMapUv:Qt&&_(y.specularIntensityMap.channel),transmissionMapUv:L&&_(y.transmissionMap.channel),thicknessMapUv:nt&&_(y.thicknessMap.channel),alphaMapUv:j&&_(y.alphaMap.channel),vertexTangents:!!K.attributes.tangent&&(Ot||M),vertexColors:y.vertexColors,vertexAlphas:y.vertexColors===!0&&!!K.attributes.color&&K.attributes.color.itemSize===4,pointsUvs:B.isPoints===!0&&!!K.attributes.uv&&(se||j),fog:!!G,useFog:y.fog===!0,fogExp2:!!G&&G.isFogExp2,flatShading:y.flatShading===!0,sizeAttenuation:y.sizeAttenuation===!0,logarithmicDepthBuffer:u,reverseDepthBuffer:bt,skinning:B.isSkinnedMesh===!0,morphTargets:K.morphAttributes.position!==void 0,morphNormals:K.morphAttributes.normal!==void 0,morphColors:K.morphAttributes.color!==void 0,morphTargetsCount:vt,morphTextureStride:Nt,numDirLights:v.directional.length,numPointLights:v.point.length,numSpotLights:v.spot.length,numSpotLightMaps:v.spotLightMap.length,numRectAreaLights:v.rectArea.length,numHemiLights:v.hemi.length,numDirLightShadows:v.directionalShadowMap.length,numPointLightShadows:v.pointShadowMap.length,numSpotLightShadows:v.spotShadowMap.length,numSpotLightShadowsWithMaps:v.numSpotLightShadowsWithMaps,numLightProbes:v.numLightProbes,numClippingPlanes:a.numPlanes,numClipIntersection:a.numIntersection,dithering:y.dithering,shadowMapEnabled:s.shadowMap.enabled&&I.length>0,shadowMapType:s.shadowMap.type,toneMapping:re,decodeVideoTexture:se&&y.map.isVideoTexture===!0&&Vt.getTransfer(y.map.colorSpace)===$t,decodeVideoTextureEmissive:ee&&y.emissiveMap.isVideoTexture===!0&&Vt.getTransfer(y.emissiveMap.colorSpace)===$t,premultipliedAlpha:y.premultipliedAlpha,doubleSided:y.side===hn,flipSided:y.side===Ae,useDepthPacking:y.depthPacking>=0,depthPacking:y.depthPacking||0,index0AttributeName:y.index0AttributeName,extensionClipCullDistance:Rt&&y.extensions.clipCullDistance===!0&&n.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(Rt&&y.extensions.multiDraw===!0||Ft)&&n.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:n.has("KHR_parallel_shader_compile"),customProgramCacheKey:y.customProgramCacheKey()};return me.vertexUv1s=l.has(1),me.vertexUv2s=l.has(2),me.vertexUv3s=l.has(3),l.clear(),me}function f(y){const v=[];if(y.shaderID?v.push(y.shaderID):(v.push(y.customVertexShaderID),v.push(y.customFragmentShaderID)),y.defines!==void 0)for(const I in y.defines)v.push(I),v.push(y.defines[I]);return y.isRawShaderMaterial===!1&&(b(v,y),E(v,y),v.push(s.outputColorSpace)),v.push(y.customProgramCacheKey),v.join()}function b(y,v){y.push(v.precision),y.push(v.outputColorSpace),y.push(v.envMapMode),y.push(v.envMapCubeUVHeight),y.push(v.mapUv),y.push(v.alphaMapUv),y.push(v.lightMapUv),y.push(v.aoMapUv),y.push(v.bumpMapUv),y.push(v.normalMapUv),y.push(v.displacementMapUv),y.push(v.emissiveMapUv),y.push(v.metalnessMapUv),y.push(v.roughnessMapUv),y.push(v.anisotropyMapUv),y.push(v.clearcoatMapUv),y.push(v.clearcoatNormalMapUv),y.push(v.clearcoatRoughnessMapUv),y.push(v.iridescenceMapUv),y.push(v.iridescenceThicknessMapUv),y.push(v.sheenColorMapUv),y.push(v.sheenRoughnessMapUv),y.push(v.specularMapUv),y.push(v.specularColorMapUv),y.push(v.specularIntensityMapUv),y.push(v.transmissionMapUv),y.push(v.thicknessMapUv),y.push(v.combine),y.push(v.fogExp2),y.push(v.sizeAttenuation),y.push(v.morphTargetsCount),y.push(v.morphAttributeCount),y.push(v.numDirLights),y.push(v.numPointLights),y.push(v.numSpotLights),y.push(v.numSpotLightMaps),y.push(v.numHemiLights),y.push(v.numRectAreaLights),y.push(v.numDirLightShadows),y.push(v.numPointLightShadows),y.push(v.numSpotLightShadows),y.push(v.numSpotLightShadowsWithMaps),y.push(v.numLightProbes),y.push(v.shadowMapType),y.push(v.toneMapping),y.push(v.numClippingPlanes),y.push(v.numClipIntersection),y.push(v.depthPacking)}function E(y,v){o.disableAll(),v.supportsVertexTextures&&o.enable(0),v.instancing&&o.enable(1),v.instancingColor&&o.enable(2),v.instancingMorph&&o.enable(3),v.matcap&&o.enable(4),v.envMap&&o.enable(5),v.normalMapObjectSpace&&o.enable(6),v.normalMapTangentSpace&&o.enable(7),v.clearcoat&&o.enable(8),v.iridescence&&o.enable(9),v.alphaTest&&o.enable(10),v.vertexColors&&o.enable(11),v.vertexAlphas&&o.enable(12),v.vertexUv1s&&o.enable(13),v.vertexUv2s&&o.enable(14),v.vertexUv3s&&o.enable(15),v.vertexTangents&&o.enable(16),v.anisotropy&&o.enable(17),v.alphaHash&&o.enable(18),v.batching&&o.enable(19),v.dispersion&&o.enable(20),v.batchingColor&&o.enable(21),y.push(o.mask),o.disableAll(),v.fog&&o.enable(0),v.useFog&&o.enable(1),v.flatShading&&o.enable(2),v.logarithmicDepthBuffer&&o.enable(3),v.reverseDepthBuffer&&o.enable(4),v.skinning&&o.enable(5),v.morphTargets&&o.enable(6),v.morphNormals&&o.enable(7),v.morphColors&&o.enable(8),v.premultipliedAlpha&&o.enable(9),v.shadowMapEnabled&&o.enable(10),v.doubleSided&&o.enable(11),v.flipSided&&o.enable(12),v.useDepthPacking&&o.enable(13),v.dithering&&o.enable(14),v.transmission&&o.enable(15),v.sheen&&o.enable(16),v.opaque&&o.enable(17),v.pointsUvs&&o.enable(18),v.decodeVideoTexture&&o.enable(19),v.decodeVideoTextureEmissive&&o.enable(20),v.alphaToCoverage&&o.enable(21),y.push(o.mask)}function x(y){const v=g[y.type];let I;if(v){const V=$e[v];I=eu.clone(V.uniforms)}else I=y.uniforms;return I}function P(y,v){let I;for(let V=0,B=h.length;V0?n.push(f):p.transparent===!0?i.push(f):e.push(f)}function c(u,d,p,g,_,m){const f=a(u,d,p,g,_,m);p.transmission>0?n.unshift(f):p.transparent===!0?i.unshift(f):e.unshift(f)}function l(u,d){e.length>1&&e.sort(u||ym),n.length>1&&n.sort(d||ec),i.length>1&&i.sort(d||ec)}function h(){for(let u=t,d=s.length;u=r.length?(a=new nc,r.push(a)):a=r[i],a}function e(){s=new WeakMap}return{get:t,dispose:e}}function Em(){const s={};return{get:function(t){if(s[t.id]!==void 0)return s[t.id];let e;switch(t.type){case"DirectionalLight":e={direction:new R,color:new Et};break;case"SpotLight":e={position:new R,direction:new R,color:new Et,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":e={position:new R,color:new Et,distance:0,decay:0};break;case"HemisphereLight":e={direction:new R,skyColor:new Et,groundColor:new Et};break;case"RectAreaLight":e={color:new Et,position:new R,halfWidth:new R,halfHeight:new R};break}return s[t.id]=e,e}}}function bm(){const s={};return{get:function(t){if(s[t.id]!==void 0)return s[t.id];let e;switch(t.type){case"DirectionalLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Pt};break;case"SpotLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Pt};break;case"PointLight":e={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Pt,shadowCameraNear:1,shadowCameraFar:1e3};break}return s[t.id]=e,e}}}let Tm=0;function Am(s,t){return(t.castShadow?2:0)-(s.castShadow?2:0)+(t.map?1:0)-(s.map?1:0)}function wm(s){const t=new Em,e=bm(),n={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let l=0;l<9;l++)n.probe.push(new R);const i=new R,r=new Lt,a=new Lt;function o(l){let h=0,u=0,d=0;for(let y=0;y<9;y++)n.probe[y].set(0,0,0);let p=0,g=0,_=0,m=0,f=0,b=0,E=0,x=0,P=0,A=0,w=0;l.sort(Am);for(let y=0,v=l.length;y0&&(s.has("OES_texture_float_linear")===!0?(n.rectAreaLTC1=et.LTC_FLOAT_1,n.rectAreaLTC2=et.LTC_FLOAT_2):(n.rectAreaLTC1=et.LTC_HALF_1,n.rectAreaLTC2=et.LTC_HALF_2)),n.ambient[0]=h,n.ambient[1]=u,n.ambient[2]=d;const C=n.hash;(C.directionalLength!==p||C.pointLength!==g||C.spotLength!==_||C.rectAreaLength!==m||C.hemiLength!==f||C.numDirectionalShadows!==b||C.numPointShadows!==E||C.numSpotShadows!==x||C.numSpotMaps!==P||C.numLightProbes!==w)&&(n.directional.length=p,n.spot.length=_,n.rectArea.length=m,n.point.length=g,n.hemi.length=f,n.directionalShadow.length=b,n.directionalShadowMap.length=b,n.pointShadow.length=E,n.pointShadowMap.length=E,n.spotShadow.length=x,n.spotShadowMap.length=x,n.directionalShadowMatrix.length=b,n.pointShadowMatrix.length=E,n.spotLightMatrix.length=x+P-A,n.spotLightMap.length=P,n.numSpotLightShadowsWithMaps=A,n.numLightProbes=w,C.directionalLength=p,C.pointLength=g,C.spotLength=_,C.rectAreaLength=m,C.hemiLength=f,C.numDirectionalShadows=b,C.numPointShadows=E,C.numSpotShadows=x,C.numSpotMaps=P,C.numLightProbes=w,n.version=Tm++)}function c(l,h){let u=0,d=0,p=0,g=0,_=0;const m=h.matrixWorldInverse;for(let f=0,b=l.length;f=a.length?(o=new ic(s),a.push(o)):o=a[r],o}function n(){t=new WeakMap}return{get:e,dispose:n}}class Cm extends Ke{static get type(){return"MeshDepthMaterial"}constructor(t){super(),this.isMeshDepthMaterial=!0,this.depthPacking=oh,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}class Im extends Ke{static get type(){return"MeshDistanceMaterial"}constructor(t){super(),this.isMeshDistanceMaterial=!0,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}const Pm=`void main() { + gl_Position = vec4( position, 1.0 ); +}`,Lm=`uniform sampler2D shadow_pass; +uniform vec2 resolution; +uniform float radius; +#include +void main() { + const float samples = float( VSM_SAMPLES ); + float mean = 0.0; + float squared_mean = 0.0; + float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 ); + float uvStart = samples <= 1.0 ? 0.0 : - 1.0; + for ( float i = 0.0; i < samples; i ++ ) { + float uvOffset = uvStart + i * uvStride; + #ifdef HORIZONTAL_PASS + vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) ); + mean += distribution.x; + squared_mean += distribution.y * distribution.y + distribution.x * distribution.x; + #else + float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) ); + mean += depth; + squared_mean += depth * depth; + #endif + } + mean = mean / samples; + squared_mean = squared_mean / samples; + float std_dev = sqrt( squared_mean - mean * mean ); + gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) ); +}`;function Dm(s,t,e){let n=new Qs;const i=new Pt,r=new Pt,a=new Xt,o=new Cm({depthPacking:ch}),c=new Im,l={},h=e.maxTextureSize,u={[Pn]:Ae,[Ae]:Pn,[hn]:hn},d=new Un({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new Pt},radius:{value:4}},vertexShader:Pm,fragmentShader:Lm}),p=d.clone();p.defines.HORIZONTAL_PASS=1;const g=new ce;g.setAttribute("position",new pe(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const _=new Te(g,d),m=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=Ic;let f=this.type;this.render=function(A,w,C){if(m.enabled===!1||m.autoUpdate===!1&&m.needsUpdate===!1||A.length===0)return;const y=s.getRenderTarget(),v=s.getActiveCubeFace(),I=s.getActiveMipmapLevel(),V=s.state;V.setBlending(Cn),V.buffers.color.setClear(1,1,1,1),V.buffers.depth.setTest(!0),V.setScissorTest(!1);const B=f!==cn&&this.type===cn,G=f===cn&&this.type!==cn;for(let K=0,W=A.length;Kh||i.y>h)&&(i.x>h&&(r.x=Math.floor(h/it.x),i.x=r.x*it.x,H.mapSize.x=r.x),i.y>h&&(r.y=Math.floor(h/it.y),i.y=r.y*it.y,H.mapSize.y=r.y)),H.map===null||B===!0||G===!0){const vt=this.type!==cn?{minFilter:Ue,magFilter:Ue}:{};H.map!==null&&H.map.dispose(),H.map=new Dn(i.x,i.y,vt),H.map.texture.name=Q.name+".shadowMap",H.camera.updateProjectionMatrix()}s.setRenderTarget(H.map),s.clear();const lt=H.getViewportCount();for(let vt=0;vt0||w.map&&w.alphaTest>0){const V=v.uuid,B=w.uuid;let G=l[V];G===void 0&&(G={},l[V]=G);let K=G[B];K===void 0&&(K=v.clone(),G[B]=K,w.addEventListener("dispose",P)),v=K}if(v.visible=w.visible,v.wireframe=w.wireframe,y===cn?v.side=w.shadowSide!==null?w.shadowSide:w.side:v.side=w.shadowSide!==null?w.shadowSide:u[w.side],v.alphaMap=w.alphaMap,v.alphaTest=w.alphaTest,v.map=w.map,v.clipShadows=w.clipShadows,v.clippingPlanes=w.clippingPlanes,v.clipIntersection=w.clipIntersection,v.displacementMap=w.displacementMap,v.displacementScale=w.displacementScale,v.displacementBias=w.displacementBias,v.wireframeLinewidth=w.wireframeLinewidth,v.linewidth=w.linewidth,C.isPointLight===!0&&v.isMeshDistanceMaterial===!0){const V=s.properties.get(v);V.light=C}return v}function x(A,w,C,y,v){if(A.visible===!1)return;if(A.layers.test(w.layers)&&(A.isMesh||A.isLine||A.isPoints)&&(A.castShadow||A.receiveShadow&&v===cn)&&(!A.frustumCulled||n.intersectsObject(A))){A.modelViewMatrix.multiplyMatrices(C.matrixWorldInverse,A.matrixWorld);const B=t.update(A),G=A.material;if(Array.isArray(G)){const K=B.groups;for(let W=0,Q=K.length;W=1):H.indexOf("OpenGL ES")!==-1&&(Q=parseFloat(/^OpenGL ES (\d)/.exec(H)[1]),W=Q>=2);let it=null,lt={};const vt=s.getParameter(s.SCISSOR_BOX),Nt=s.getParameter(s.VIEWPORT),Jt=new Xt().fromArray(vt),q=new Xt().fromArray(Nt);function tt(L,nt,k,j){const ct=new Uint8Array(4),at=s.createTexture();s.bindTexture(L,at),s.texParameteri(L,s.TEXTURE_MIN_FILTER,s.NEAREST),s.texParameteri(L,s.TEXTURE_MAG_FILTER,s.NEAREST);for(let Rt=0;Rt"u"?!1:/OculusBrowser/g.test(navigator.userAgent),l=new Pt,h=new WeakMap;let u;const d=new WeakMap;let p=!1;try{p=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function g(T,M){return p?new OffscreenCanvas(T,M):qi("canvas")}function _(T,M,F){let Y=1;const Z=Mt(T);if((Z.width>F||Z.height>F)&&(Y=F/Math.max(Z.width,Z.height)),Y<1)if(typeof HTMLImageElement<"u"&&T instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&T instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&T instanceof ImageBitmap||typeof VideoFrame<"u"&&T instanceof VideoFrame){const X=Math.floor(Y*Z.width),_t=Math.floor(Y*Z.height);u===void 0&&(u=g(X,_t));const rt=M?g(X,_t):u;return rt.width=X,rt.height=_t,rt.getContext("2d").drawImage(T,0,0,X,_t),console.warn("THREE.WebGLRenderer: Texture has been resized from ("+Z.width+"x"+Z.height+") to ("+X+"x"+_t+")."),rt}else return"data"in T&&console.warn("THREE.WebGLRenderer: Image in DataTexture is too big ("+Z.width+"x"+Z.height+")."),T;return T}function m(T){return T.generateMipmaps}function f(T){s.generateMipmap(T)}function b(T){return T.isWebGLCubeRenderTarget?s.TEXTURE_CUBE_MAP:T.isWebGL3DRenderTarget?s.TEXTURE_3D:T.isWebGLArrayRenderTarget||T.isCompressedArrayTexture?s.TEXTURE_2D_ARRAY:s.TEXTURE_2D}function E(T,M,F,Y,Z=!1){if(T!==null){if(s[T]!==void 0)return s[T];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+T+"'")}let X=M;if(M===s.RED&&(F===s.FLOAT&&(X=s.R32F),F===s.HALF_FLOAT&&(X=s.R16F),F===s.UNSIGNED_BYTE&&(X=s.R8)),M===s.RED_INTEGER&&(F===s.UNSIGNED_BYTE&&(X=s.R8UI),F===s.UNSIGNED_SHORT&&(X=s.R16UI),F===s.UNSIGNED_INT&&(X=s.R32UI),F===s.BYTE&&(X=s.R8I),F===s.SHORT&&(X=s.R16I),F===s.INT&&(X=s.R32I)),M===s.RG&&(F===s.FLOAT&&(X=s.RG32F),F===s.HALF_FLOAT&&(X=s.RG16F),F===s.UNSIGNED_BYTE&&(X=s.RG8)),M===s.RG_INTEGER&&(F===s.UNSIGNED_BYTE&&(X=s.RG8UI),F===s.UNSIGNED_SHORT&&(X=s.RG16UI),F===s.UNSIGNED_INT&&(X=s.RG32UI),F===s.BYTE&&(X=s.RG8I),F===s.SHORT&&(X=s.RG16I),F===s.INT&&(X=s.RG32I)),M===s.RGB_INTEGER&&(F===s.UNSIGNED_BYTE&&(X=s.RGB8UI),F===s.UNSIGNED_SHORT&&(X=s.RGB16UI),F===s.UNSIGNED_INT&&(X=s.RGB32UI),F===s.BYTE&&(X=s.RGB8I),F===s.SHORT&&(X=s.RGB16I),F===s.INT&&(X=s.RGB32I)),M===s.RGBA_INTEGER&&(F===s.UNSIGNED_BYTE&&(X=s.RGBA8UI),F===s.UNSIGNED_SHORT&&(X=s.RGBA16UI),F===s.UNSIGNED_INT&&(X=s.RGBA32UI),F===s.BYTE&&(X=s.RGBA8I),F===s.SHORT&&(X=s.RGBA16I),F===s.INT&&(X=s.RGBA32I)),M===s.RGB&&F===s.UNSIGNED_INT_5_9_9_9_REV&&(X=s.RGB9_E5),M===s.RGBA){const _t=Z?Js:Vt.getTransfer(Y);F===s.FLOAT&&(X=s.RGBA32F),F===s.HALF_FLOAT&&(X=s.RGBA16F),F===s.UNSIGNED_BYTE&&(X=_t===$t?s.SRGB8_ALPHA8:s.RGBA8),F===s.UNSIGNED_SHORT_4_4_4_4&&(X=s.RGBA4),F===s.UNSIGNED_SHORT_5_5_5_1&&(X=s.RGB5_A1)}return(X===s.R16F||X===s.R32F||X===s.RG16F||X===s.RG32F||X===s.RGBA16F||X===s.RGBA32F)&&t.get("EXT_color_buffer_float"),X}function x(T,M){let F;return T?M===null||M===Ln||M===yi?F=s.DEPTH24_STENCIL8:M===De?F=s.DEPTH32F_STENCIL8:M===Xi&&(F=s.DEPTH24_STENCIL8,console.warn("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):M===null||M===Ln||M===yi?F=s.DEPTH_COMPONENT24:M===De?F=s.DEPTH_COMPONENT32F:M===Xi&&(F=s.DEPTH_COMPONENT16),F}function P(T,M){return m(T)===!0||T.isFramebufferTexture&&T.minFilter!==Ue&&T.minFilter!==Le?Math.log2(Math.max(M.width,M.height))+1:T.mipmaps!==void 0&&T.mipmaps.length>0?T.mipmaps.length:T.isCompressedTexture&&Array.isArray(T.image)?M.mipmaps.length:1}function A(T){const M=T.target;M.removeEventListener("dispose",A),C(M),M.isVideoTexture&&h.delete(M)}function w(T){const M=T.target;M.removeEventListener("dispose",w),v(M)}function C(T){const M=n.get(T);if(M.__webglInit===void 0)return;const F=T.source,Y=d.get(F);if(Y){const Z=Y[M.__cacheKey];Z.usedTimes--,Z.usedTimes===0&&y(T),Object.keys(Y).length===0&&d.delete(F)}n.remove(T)}function y(T){const M=n.get(T);s.deleteTexture(M.__webglTexture);const F=T.source,Y=d.get(F);delete Y[M.__cacheKey],a.memory.textures--}function v(T){const M=n.get(T);if(T.depthTexture&&(T.depthTexture.dispose(),n.remove(T.depthTexture)),T.isWebGLCubeRenderTarget)for(let Y=0;Y<6;Y++){if(Array.isArray(M.__webglFramebuffer[Y]))for(let Z=0;Z=i.maxTextures&&console.warn("THREE.WebGLTextures: Trying to use "+T+" texture units while this GPU supports only "+i.maxTextures),I+=1,T}function G(T){const M=[];return M.push(T.wrapS),M.push(T.wrapT),M.push(T.wrapR||0),M.push(T.magFilter),M.push(T.minFilter),M.push(T.anisotropy),M.push(T.internalFormat),M.push(T.format),M.push(T.type),M.push(T.generateMipmaps),M.push(T.premultiplyAlpha),M.push(T.flipY),M.push(T.unpackAlignment),M.push(T.colorSpace),M.join()}function K(T,M){const F=n.get(T);if(T.isVideoTexture&&yt(T),T.isRenderTargetTexture===!1&&T.version>0&&F.__version!==T.version){const Y=T.image;if(Y===null)console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found.");else if(Y.complete===!1)console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete");else{q(F,T,M);return}}e.bindTexture(s.TEXTURE_2D,F.__webglTexture,s.TEXTURE0+M)}function W(T,M){const F=n.get(T);if(T.version>0&&F.__version!==T.version){q(F,T,M);return}e.bindTexture(s.TEXTURE_2D_ARRAY,F.__webglTexture,s.TEXTURE0+M)}function Q(T,M){const F=n.get(T);if(T.version>0&&F.__version!==T.version){q(F,T,M);return}e.bindTexture(s.TEXTURE_3D,F.__webglTexture,s.TEXTURE0+M)}function H(T,M){const F=n.get(T);if(T.version>0&&F.__version!==T.version){tt(F,T,M);return}e.bindTexture(s.TEXTURE_CUBE_MAP,F.__webglTexture,s.TEXTURE0+M)}const it={[ia]:s.REPEAT,[dn]:s.CLAMP_TO_EDGE,[sa]:s.MIRRORED_REPEAT},lt={[Ue]:s.NEAREST,[nh]:s.NEAREST_MIPMAP_NEAREST,[ns]:s.NEAREST_MIPMAP_LINEAR,[Le]:s.LINEAR,[or]:s.LINEAR_MIPMAP_NEAREST,[wn]:s.LINEAR_MIPMAP_LINEAR},vt={[hh]:s.NEVER,[gh]:s.ALWAYS,[uh]:s.LESS,[kc]:s.LEQUAL,[dh]:s.EQUAL,[mh]:s.GEQUAL,[fh]:s.GREATER,[ph]:s.NOTEQUAL};function Nt(T,M){if(M.type===De&&t.has("OES_texture_float_linear")===!1&&(M.magFilter===Le||M.magFilter===or||M.magFilter===ns||M.magFilter===wn||M.minFilter===Le||M.minFilter===or||M.minFilter===ns||M.minFilter===wn)&&console.warn("THREE.WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),s.texParameteri(T,s.TEXTURE_WRAP_S,it[M.wrapS]),s.texParameteri(T,s.TEXTURE_WRAP_T,it[M.wrapT]),(T===s.TEXTURE_3D||T===s.TEXTURE_2D_ARRAY)&&s.texParameteri(T,s.TEXTURE_WRAP_R,it[M.wrapR]),s.texParameteri(T,s.TEXTURE_MAG_FILTER,lt[M.magFilter]),s.texParameteri(T,s.TEXTURE_MIN_FILTER,lt[M.minFilter]),M.compareFunction&&(s.texParameteri(T,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(T,s.TEXTURE_COMPARE_FUNC,vt[M.compareFunction])),t.has("EXT_texture_filter_anisotropic")===!0){if(M.magFilter===Ue||M.minFilter!==ns&&M.minFilter!==wn||M.type===De&&t.has("OES_texture_float_linear")===!1)return;if(M.anisotropy>1||n.get(M).__currentAnisotropy){const F=t.get("EXT_texture_filter_anisotropic");s.texParameterf(T,F.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(M.anisotropy,i.getMaxAnisotropy())),n.get(M).__currentAnisotropy=M.anisotropy}}}function Jt(T,M){let F=!1;T.__webglInit===void 0&&(T.__webglInit=!0,M.addEventListener("dispose",A));const Y=M.source;let Z=d.get(Y);Z===void 0&&(Z={},d.set(Y,Z));const X=G(M);if(X!==T.__cacheKey){Z[X]===void 0&&(Z[X]={texture:s.createTexture(),usedTimes:0},a.memory.textures++,F=!0),Z[X].usedTimes++;const _t=Z[T.__cacheKey];_t!==void 0&&(Z[T.__cacheKey].usedTimes--,_t.usedTimes===0&&y(M)),T.__cacheKey=X,T.__webglTexture=Z[X].texture}return F}function q(T,M,F){let Y=s.TEXTURE_2D;(M.isDataArrayTexture||M.isCompressedArrayTexture)&&(Y=s.TEXTURE_2D_ARRAY),M.isData3DTexture&&(Y=s.TEXTURE_3D);const Z=Jt(T,M),X=M.source;e.bindTexture(Y,T.__webglTexture,s.TEXTURE0+F);const _t=n.get(X);if(X.version!==_t.__version||Z===!0){e.activeTexture(s.TEXTURE0+F);const rt=Vt.getPrimaries(Vt.workingColorSpace),ht=M.colorSpace===An?null:Vt.getPrimaries(M.colorSpace),Ht=M.colorSpace===An||rt===ht?s.NONE:s.BROWSER_DEFAULT_WEBGL;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,M.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,M.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,M.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,Ht);let $=_(M.image,!1,i.maxTextureSize);$=ee(M,$);const ut=r.convert(M.format,M.colorSpace),St=r.convert(M.type);let Tt=E(M.internalFormat,ut,St,M.colorSpace,M.isVideoTexture);Nt(Y,M);let dt;const zt=M.mipmaps,Dt=M.isVideoTexture!==!0,Qt=_t.__version===void 0||Z===!0,L=X.dataReady,nt=P(M,$);if(M.isDepthTexture)Tt=x(M.format===Si,M.type),Qt&&(Dt?e.texStorage2D(s.TEXTURE_2D,1,Tt,$.width,$.height):e.texImage2D(s.TEXTURE_2D,0,Tt,$.width,$.height,0,ut,St,null));else if(M.isDataTexture)if(zt.length>0){Dt&&Qt&&e.texStorage2D(s.TEXTURE_2D,nt,Tt,zt[0].width,zt[0].height);for(let k=0,j=zt.length;k0){const ct=sc(dt.width,dt.height,M.format,M.type);for(const at of M.layerUpdates){const Rt=dt.data.subarray(at*ct/dt.data.BYTES_PER_ELEMENT,(at+1)*ct/dt.data.BYTES_PER_ELEMENT);e.compressedTexSubImage3D(s.TEXTURE_2D_ARRAY,k,0,0,at,dt.width,dt.height,1,ut,Rt)}M.clearLayerUpdates()}else e.compressedTexSubImage3D(s.TEXTURE_2D_ARRAY,k,0,0,0,dt.width,dt.height,$.depth,ut,dt.data)}else e.compressedTexImage3D(s.TEXTURE_2D_ARRAY,k,Tt,dt.width,dt.height,$.depth,0,dt.data,0,0);else console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else Dt?L&&e.texSubImage3D(s.TEXTURE_2D_ARRAY,k,0,0,0,dt.width,dt.height,$.depth,ut,St,dt.data):e.texImage3D(s.TEXTURE_2D_ARRAY,k,Tt,dt.width,dt.height,$.depth,0,ut,St,dt.data)}else{Dt&&Qt&&e.texStorage2D(s.TEXTURE_2D,nt,Tt,zt[0].width,zt[0].height);for(let k=0,j=zt.length;k0){const k=sc($.width,$.height,M.format,M.type);for(const j of M.layerUpdates){const ct=$.data.subarray(j*k/$.data.BYTES_PER_ELEMENT,(j+1)*k/$.data.BYTES_PER_ELEMENT);e.texSubImage3D(s.TEXTURE_2D_ARRAY,0,0,0,j,$.width,$.height,1,ut,St,ct)}M.clearLayerUpdates()}else e.texSubImage3D(s.TEXTURE_2D_ARRAY,0,0,0,0,$.width,$.height,$.depth,ut,St,$.data)}else e.texImage3D(s.TEXTURE_2D_ARRAY,0,Tt,$.width,$.height,$.depth,0,ut,St,$.data);else if(M.isData3DTexture)Dt?(Qt&&e.texStorage3D(s.TEXTURE_3D,nt,Tt,$.width,$.height,$.depth),L&&e.texSubImage3D(s.TEXTURE_3D,0,0,0,0,$.width,$.height,$.depth,ut,St,$.data)):e.texImage3D(s.TEXTURE_3D,0,Tt,$.width,$.height,$.depth,0,ut,St,$.data);else if(M.isFramebufferTexture){if(Qt)if(Dt)e.texStorage2D(s.TEXTURE_2D,nt,Tt,$.width,$.height);else{let k=$.width,j=$.height;for(let ct=0;ct>=1,j>>=1}}else if(zt.length>0){if(Dt&&Qt){const k=Mt(zt[0]);e.texStorage2D(s.TEXTURE_2D,nt,Tt,k.width,k.height)}for(let k=0,j=zt.length;k0&&nt++;const j=Mt(ut[0]);e.texStorage2D(s.TEXTURE_CUBE_MAP,nt,zt,j.width,j.height)}for(let j=0;j<6;j++)if($){Dt?L&&e.texSubImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+j,0,0,0,ut[j].width,ut[j].height,Tt,dt,ut[j].data):e.texImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+j,0,zt,ut[j].width,ut[j].height,0,Tt,dt,ut[j].data);for(let ct=0;ct>X),St=Math.max(1,M.height>>X);Z===s.TEXTURE_3D||Z===s.TEXTURE_2D_ARRAY?e.texImage3D(Z,X,ht,ut,St,M.depth,0,_t,rt,null):e.texImage2D(Z,X,ht,ut,St,0,_t,rt,null)}e.bindFramebuffer(s.FRAMEBUFFER,T),Ot(M)?o.framebufferTexture2DMultisampleEXT(s.FRAMEBUFFER,Y,Z,$.__webglTexture,0,Bt(M)):(Z===s.TEXTURE_2D||Z>=s.TEXTURE_CUBE_MAP_POSITIVE_X&&Z<=s.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&s.framebufferTexture2D(s.FRAMEBUFFER,Y,Z,$.__webglTexture,X),e.bindFramebuffer(s.FRAMEBUFFER,null)}function st(T,M,F){if(s.bindRenderbuffer(s.RENDERBUFFER,T),M.depthBuffer){const Y=M.depthTexture,Z=Y&&Y.isDepthTexture?Y.type:null,X=x(M.stencilBuffer,Z),_t=M.stencilBuffer?s.DEPTH_STENCIL_ATTACHMENT:s.DEPTH_ATTACHMENT,rt=Bt(M);Ot(M)?o.renderbufferStorageMultisampleEXT(s.RENDERBUFFER,rt,X,M.width,M.height):F?s.renderbufferStorageMultisample(s.RENDERBUFFER,rt,X,M.width,M.height):s.renderbufferStorage(s.RENDERBUFFER,X,M.width,M.height),s.framebufferRenderbuffer(s.FRAMEBUFFER,_t,s.RENDERBUFFER,T)}else{const Y=M.textures;for(let Z=0;Z{delete M.__boundDepthTexture,delete M.__depthDisposeCallback,Y.removeEventListener("dispose",Z)};Y.addEventListener("dispose",Z),M.__depthDisposeCallback=Z}M.__boundDepthTexture=Y}if(T.depthTexture&&!M.__autoAllocateDepthBuffer){if(F)throw new Error("target.depthTexture not supported in Cube render targets");bt(M.__webglFramebuffer,T)}else if(F){M.__webglDepthbuffer=[];for(let Y=0;Y<6;Y++)if(e.bindFramebuffer(s.FRAMEBUFFER,M.__webglFramebuffer[Y]),M.__webglDepthbuffer[Y]===void 0)M.__webglDepthbuffer[Y]=s.createRenderbuffer(),st(M.__webglDepthbuffer[Y],T,!1);else{const Z=T.stencilBuffer?s.DEPTH_STENCIL_ATTACHMENT:s.DEPTH_ATTACHMENT,X=M.__webglDepthbuffer[Y];s.bindRenderbuffer(s.RENDERBUFFER,X),s.framebufferRenderbuffer(s.FRAMEBUFFER,Z,s.RENDERBUFFER,X)}}else if(e.bindFramebuffer(s.FRAMEBUFFER,M.__webglFramebuffer),M.__webglDepthbuffer===void 0)M.__webglDepthbuffer=s.createRenderbuffer(),st(M.__webglDepthbuffer,T,!1);else{const Y=T.stencilBuffer?s.DEPTH_STENCIL_ATTACHMENT:s.DEPTH_ATTACHMENT,Z=M.__webglDepthbuffer;s.bindRenderbuffer(s.RENDERBUFFER,Z),s.framebufferRenderbuffer(s.FRAMEBUFFER,Y,s.RENDERBUFFER,Z)}e.bindFramebuffer(s.FRAMEBUFFER,null)}function Ft(T,M,F){const Y=n.get(T);M!==void 0&>(Y.__webglFramebuffer,T,T.texture,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,0),F!==void 0&&wt(T)}function se(T){const M=T.texture,F=n.get(T),Y=n.get(M);T.addEventListener("dispose",w);const Z=T.textures,X=T.isWebGLCubeRenderTarget===!0,_t=Z.length>1;if(_t||(Y.__webglTexture===void 0&&(Y.__webglTexture=s.createTexture()),Y.__version=M.version,a.memory.textures++),X){F.__webglFramebuffer=[];for(let rt=0;rt<6;rt++)if(M.mipmaps&&M.mipmaps.length>0){F.__webglFramebuffer[rt]=[];for(let ht=0;ht0){F.__webglFramebuffer=[];for(let rt=0;rt0&&Ot(T)===!1){F.__webglMultisampledFramebuffer=s.createFramebuffer(),F.__webglColorRenderbuffer=[],e.bindFramebuffer(s.FRAMEBUFFER,F.__webglMultisampledFramebuffer);for(let rt=0;rt0)for(let ht=0;ht0)for(let ht=0;ht0){if(Ot(T)===!1){const M=T.textures,F=T.width,Y=T.height;let Z=s.COLOR_BUFFER_BIT;const X=T.stencilBuffer?s.DEPTH_STENCIL_ATTACHMENT:s.DEPTH_ATTACHMENT,_t=n.get(T),rt=M.length>1;if(rt)for(let ht=0;ht0&&t.has("WEBGL_multisampled_render_to_texture")===!0&&M.__useRenderToTexture!==!1}function yt(T){const M=a.render.frame;h.get(T)!==M&&(h.set(T,M),T.update())}function ee(T,M){const F=T.colorSpace,Y=T.format,Z=T.type;return T.isCompressedTexture===!0||T.isVideoTexture===!0||F!==Ti&&F!==An&&(Vt.getTransfer(F)===$t?(Y!==be||Z!==gn)&&console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):console.error("THREE.WebGLTextures: Unsupported texture color space:",F)),M}function Mt(T){return typeof HTMLImageElement<"u"&&T instanceof HTMLImageElement?(l.width=T.naturalWidth||T.width,l.height=T.naturalHeight||T.height):typeof VideoFrame<"u"&&T instanceof VideoFrame?(l.width=T.displayWidth,l.height=T.displayHeight):(l.width=T.width,l.height=T.height),l}this.allocateTextureUnit=B,this.resetTextureUnits=V,this.setTexture2D=K,this.setTexture2DArray=W,this.setTexture3D=Q,this.setTextureCube=H,this.rebindTextures=Ft,this.setupRenderTarget=se,this.updateRenderTargetMipmap=kt,this.updateMultisampleRenderTarget=Fe,this.setupDepthRenderbuffer=wt,this.setupFrameBufferTexture=gt,this.useMultisampledRTT=Ot}function Om(s,t){function e(n,i=An){let r;const a=Vt.getTransfer(i);if(n===gn)return s.UNSIGNED_BYTE;if(n===za)return s.UNSIGNED_SHORT_4_4_4_4;if(n===Va)return s.UNSIGNED_SHORT_5_5_5_1;if(n===Uc)return s.UNSIGNED_INT_5_9_9_9_REV;if(n===Lc)return s.BYTE;if(n===Dc)return s.SHORT;if(n===Xi)return s.UNSIGNED_SHORT;if(n===Oa)return s.INT;if(n===Ln)return s.UNSIGNED_INT;if(n===De)return s.FLOAT;if(n===ji)return s.HALF_FLOAT;if(n===Nc)return s.ALPHA;if(n===Fc)return s.RGB;if(n===be)return s.RGBA;if(n===Bc)return s.LUMINANCE;if(n===Oc)return s.LUMINANCE_ALPHA;if(n===mi)return s.DEPTH_COMPONENT;if(n===Si)return s.DEPTH_STENCIL;if(n===ka)return s.RED;if(n===$s)return s.RED_INTEGER;if(n===zc)return s.RG;if(n===Ha)return s.RG_INTEGER;if(n===Ga)return s.RGBA_INTEGER;if(n===Fs||n===Bs||n===Os||n===zs)if(a===$t)if(r=t.get("WEBGL_compressed_texture_s3tc_srgb"),r!==null){if(n===Fs)return r.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(n===Bs)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(n===Os)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(n===zs)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(r=t.get("WEBGL_compressed_texture_s3tc"),r!==null){if(n===Fs)return r.COMPRESSED_RGB_S3TC_DXT1_EXT;if(n===Bs)return r.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(n===Os)return r.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(n===zs)return r.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(n===ra||n===aa||n===oa||n===ca)if(r=t.get("WEBGL_compressed_texture_pvrtc"),r!==null){if(n===ra)return r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(n===aa)return r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(n===oa)return r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(n===ca)return r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(n===la||n===ha||n===ua)if(r=t.get("WEBGL_compressed_texture_etc"),r!==null){if(n===la||n===ha)return a===$t?r.COMPRESSED_SRGB8_ETC2:r.COMPRESSED_RGB8_ETC2;if(n===ua)return a===$t?r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:r.COMPRESSED_RGBA8_ETC2_EAC}else return null;if(n===da||n===fa||n===pa||n===ma||n===ga||n===_a||n===xa||n===va||n===Ma||n===ya||n===Sa||n===Ea||n===ba||n===Ta)if(r=t.get("WEBGL_compressed_texture_astc"),r!==null){if(n===da)return a===$t?r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:r.COMPRESSED_RGBA_ASTC_4x4_KHR;if(n===fa)return a===$t?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:r.COMPRESSED_RGBA_ASTC_5x4_KHR;if(n===pa)return a===$t?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:r.COMPRESSED_RGBA_ASTC_5x5_KHR;if(n===ma)return a===$t?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:r.COMPRESSED_RGBA_ASTC_6x5_KHR;if(n===ga)return a===$t?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:r.COMPRESSED_RGBA_ASTC_6x6_KHR;if(n===_a)return a===$t?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:r.COMPRESSED_RGBA_ASTC_8x5_KHR;if(n===xa)return a===$t?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:r.COMPRESSED_RGBA_ASTC_8x6_KHR;if(n===va)return a===$t?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:r.COMPRESSED_RGBA_ASTC_8x8_KHR;if(n===Ma)return a===$t?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:r.COMPRESSED_RGBA_ASTC_10x5_KHR;if(n===ya)return a===$t?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:r.COMPRESSED_RGBA_ASTC_10x6_KHR;if(n===Sa)return a===$t?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:r.COMPRESSED_RGBA_ASTC_10x8_KHR;if(n===Ea)return a===$t?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:r.COMPRESSED_RGBA_ASTC_10x10_KHR;if(n===ba)return a===$t?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:r.COMPRESSED_RGBA_ASTC_12x10_KHR;if(n===Ta)return a===$t?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:r.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(n===Vs||n===Aa||n===wa)if(r=t.get("EXT_texture_compression_bptc"),r!==null){if(n===Vs)return a===$t?r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:r.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(n===Aa)return r.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(n===wa)return r.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(n===Vc||n===Ra||n===Ca||n===Ia)if(r=t.get("EXT_texture_compression_rgtc"),r!==null){if(n===Vs)return r.COMPRESSED_RED_RGTC1_EXT;if(n===Ra)return r.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(n===Ca)return r.COMPRESSED_RED_GREEN_RGTC2_EXT;if(n===Ia)return r.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return n===yi?s.UNSIGNED_INT_24_8:s[n]!==void 0?s[n]:null}return{convert:e}}class zm extends Pe{constructor(t=[]){super(),this.isArrayCamera=!0,this.cameras=t}}class Es extends ae{constructor(){super(),this.isGroup=!0,this.type="Group"}}const Vm={type:"move"};class Nr{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Es,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new Es,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new R,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new R),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new Es,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new R,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new R),this._grip}dispatchEvent(t){return this._targetRay!==null&&this._targetRay.dispatchEvent(t),this._grip!==null&&this._grip.dispatchEvent(t),this._hand!==null&&this._hand.dispatchEvent(t),this}connect(t){if(t&&t.hand){const e=this._hand;if(e)for(const n of t.hand.values())this._getHandJoint(e,n)}return this.dispatchEvent({type:"connected",data:t}),this}disconnect(t){return this.dispatchEvent({type:"disconnected",data:t}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(t,e,n){let i=null,r=null,a=null;const o=this._targetRay,c=this._grip,l=this._hand;if(t&&e.session.visibilityState!=="visible-blurred"){if(l&&t.hand){a=!0;for(const _ of t.hand.values()){const m=e.getJointPose(_,n),f=this._getHandJoint(l,_);m!==null&&(f.matrix.fromArray(m.transform.matrix),f.matrix.decompose(f.position,f.rotation,f.scale),f.matrixWorldNeedsUpdate=!0,f.jointRadius=m.radius),f.visible=m!==null}const h=l.joints["index-finger-tip"],u=l.joints["thumb-tip"],d=h.position.distanceTo(u.position),p=.02,g=.005;l.inputState.pinching&&d>p+g?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:t.handedness,target:this})):!l.inputState.pinching&&d<=p-g&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:t.handedness,target:this}))}else c!==null&&t.gripSpace&&(r=e.getPose(t.gripSpace,n),r!==null&&(c.matrix.fromArray(r.transform.matrix),c.matrix.decompose(c.position,c.rotation,c.scale),c.matrixWorldNeedsUpdate=!0,r.linearVelocity?(c.hasLinearVelocity=!0,c.linearVelocity.copy(r.linearVelocity)):c.hasLinearVelocity=!1,r.angularVelocity?(c.hasAngularVelocity=!0,c.angularVelocity.copy(r.angularVelocity)):c.hasAngularVelocity=!1));o!==null&&(i=e.getPose(t.targetRaySpace,n),i===null&&r!==null&&(i=r),i!==null&&(o.matrix.fromArray(i.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,i.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(i.linearVelocity)):o.hasLinearVelocity=!1,i.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(i.angularVelocity)):o.hasAngularVelocity=!1,this.dispatchEvent(Vm)))}return o!==null&&(o.visible=i!==null),c!==null&&(c.visible=r!==null),l!==null&&(l.visible=a!==null),this}_getHandJoint(t,e){if(t.joints[e.jointName]===void 0){const n=new Es;n.matrixAutoUpdate=!1,n.visible=!1,t.joints[e.jointName]=n,t.add(n)}return t.joints[e.jointName]}}const km=` +void main() { + + gl_Position = vec4( position, 1.0 ); + +}`,Hm=` +uniform sampler2DArray depthColor; +uniform float depthWidth; +uniform float depthHeight; + +void main() { + + vec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight ); + + if ( coord.x >= 1.0 ) { + + gl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r; + + } else { + + gl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r; + + } + +}`;class Gm{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(t,e,n){if(this.texture===null){const i=new ve,r=t.properties.get(i);r.__webglTexture=e.texture,(e.depthNear!=n.depthNear||e.depthFar!=n.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=i}}getMesh(t){if(this.texture!==null&&this.mesh===null){const e=t.cameras[0].viewport,n=new Un({vertexShader:km,fragmentShader:Hm,uniforms:{depthColor:{value:this.texture},depthWidth:{value:e.z},depthHeight:{value:e.w}}});this.mesh=new Te(new tr(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class Wm extends Nn{constructor(t,e){super();const n=this;let i=null,r=1,a=null,o="local-floor",c=1,l=null,h=null,u=null,d=null,p=null,g=null;const _=new Gm,m=e.getContextAttributes();let f=null,b=null;const E=[],x=[],P=new Pt;let A=null;const w=new Pe;w.viewport=new Xt;const C=new Pe;C.viewport=new Xt;const y=[w,C],v=new zm;let I=null,V=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(q){let tt=E[q];return tt===void 0&&(tt=new Nr,E[q]=tt),tt.getTargetRaySpace()},this.getControllerGrip=function(q){let tt=E[q];return tt===void 0&&(tt=new Nr,E[q]=tt),tt.getGripSpace()},this.getHand=function(q){let tt=E[q];return tt===void 0&&(tt=new Nr,E[q]=tt),tt.getHandSpace()};function B(q){const tt=x.indexOf(q.inputSource);if(tt===-1)return;const gt=E[tt];gt!==void 0&&(gt.update(q.inputSource,q.frame,l||a),gt.dispatchEvent({type:q.type,data:q.inputSource}))}function G(){i.removeEventListener("select",B),i.removeEventListener("selectstart",B),i.removeEventListener("selectend",B),i.removeEventListener("squeeze",B),i.removeEventListener("squeezestart",B),i.removeEventListener("squeezeend",B),i.removeEventListener("end",G),i.removeEventListener("inputsourceschange",K);for(let q=0;q=0&&(x[st]=null,E[st].disconnect(gt))}for(let tt=0;tt=x.length){x.push(gt),st=wt;break}else if(x[wt]===null){x[wt]=gt,st=wt;break}if(st===-1)break}const bt=E[st];bt&&bt.connect(gt)}}const W=new R,Q=new R;function H(q,tt,gt){W.setFromMatrixPosition(tt.matrixWorld),Q.setFromMatrixPosition(gt.matrixWorld);const st=W.distanceTo(Q),bt=tt.projectionMatrix.elements,wt=gt.projectionMatrix.elements,Ft=bt[14]/(bt[10]-1),se=bt[14]/(bt[10]+1),kt=(bt[9]+1)/bt[5],oe=(bt[9]-1)/bt[5],N=(bt[8]-1)/bt[0],Fe=(wt[8]+1)/wt[0],Bt=Ft*N,Ot=Ft*Fe,yt=st/(-N+Fe),ee=yt*-N;if(tt.matrixWorld.decompose(q.position,q.quaternion,q.scale),q.translateX(ee),q.translateZ(yt),q.matrixWorld.compose(q.position,q.quaternion,q.scale),q.matrixWorldInverse.copy(q.matrixWorld).invert(),bt[10]===-1)q.projectionMatrix.copy(tt.projectionMatrix),q.projectionMatrixInverse.copy(tt.projectionMatrixInverse);else{const Mt=Ft+yt,T=se+yt,M=Bt-ee,F=Ot+(st-ee),Y=kt*se/T*Mt,Z=oe*se/T*Mt;q.projectionMatrix.makePerspective(M,F,Y,Z,Mt,T),q.projectionMatrixInverse.copy(q.projectionMatrix).invert()}}function it(q,tt){tt===null?q.matrixWorld.copy(q.matrix):q.matrixWorld.multiplyMatrices(tt.matrixWorld,q.matrix),q.matrixWorldInverse.copy(q.matrixWorld).invert()}this.updateCamera=function(q){if(i===null)return;let tt=q.near,gt=q.far;_.texture!==null&&(_.depthNear>0&&(tt=_.depthNear),_.depthFar>0&&(gt=_.depthFar)),v.near=C.near=w.near=tt,v.far=C.far=w.far=gt,(I!==v.near||V!==v.far)&&(i.updateRenderState({depthNear:v.near,depthFar:v.far}),I=v.near,V=v.far),w.layers.mask=q.layers.mask|2,C.layers.mask=q.layers.mask|4,v.layers.mask=w.layers.mask|C.layers.mask;const st=q.parent,bt=v.cameras;it(v,st);for(let wt=0;wt0&&(m.alphaTest.value=f.alphaTest);const b=t.get(f),E=b.envMap,x=b.envMapRotation;E&&(m.envMap.value=E,Hn.copy(x),Hn.x*=-1,Hn.y*=-1,Hn.z*=-1,E.isCubeTexture&&E.isRenderTargetTexture===!1&&(Hn.y*=-1,Hn.z*=-1),m.envMapRotation.value.setFromMatrix4(Xm.makeRotationFromEuler(Hn)),m.flipEnvMap.value=E.isCubeTexture&&E.isRenderTargetTexture===!1?-1:1,m.reflectivity.value=f.reflectivity,m.ior.value=f.ior,m.refractionRatio.value=f.refractionRatio),f.lightMap&&(m.lightMap.value=f.lightMap,m.lightMapIntensity.value=f.lightMapIntensity,e(f.lightMap,m.lightMapTransform)),f.aoMap&&(m.aoMap.value=f.aoMap,m.aoMapIntensity.value=f.aoMapIntensity,e(f.aoMap,m.aoMapTransform))}function a(m,f){m.diffuse.value.copy(f.color),m.opacity.value=f.opacity,f.map&&(m.map.value=f.map,e(f.map,m.mapTransform))}function o(m,f){m.dashSize.value=f.dashSize,m.totalSize.value=f.dashSize+f.gapSize,m.scale.value=f.scale}function c(m,f,b,E){m.diffuse.value.copy(f.color),m.opacity.value=f.opacity,m.size.value=f.size*b,m.scale.value=E*.5,f.map&&(m.map.value=f.map,e(f.map,m.uvTransform)),f.alphaMap&&(m.alphaMap.value=f.alphaMap,e(f.alphaMap,m.alphaMapTransform)),f.alphaTest>0&&(m.alphaTest.value=f.alphaTest)}function l(m,f){m.diffuse.value.copy(f.color),m.opacity.value=f.opacity,m.rotation.value=f.rotation,f.map&&(m.map.value=f.map,e(f.map,m.mapTransform)),f.alphaMap&&(m.alphaMap.value=f.alphaMap,e(f.alphaMap,m.alphaMapTransform)),f.alphaTest>0&&(m.alphaTest.value=f.alphaTest)}function h(m,f){m.specular.value.copy(f.specular),m.shininess.value=Math.max(f.shininess,1e-4)}function u(m,f){f.gradientMap&&(m.gradientMap.value=f.gradientMap)}function d(m,f){m.metalness.value=f.metalness,f.metalnessMap&&(m.metalnessMap.value=f.metalnessMap,e(f.metalnessMap,m.metalnessMapTransform)),m.roughness.value=f.roughness,f.roughnessMap&&(m.roughnessMap.value=f.roughnessMap,e(f.roughnessMap,m.roughnessMapTransform)),f.envMap&&(m.envMapIntensity.value=f.envMapIntensity)}function p(m,f,b){m.ior.value=f.ior,f.sheen>0&&(m.sheenColor.value.copy(f.sheenColor).multiplyScalar(f.sheen),m.sheenRoughness.value=f.sheenRoughness,f.sheenColorMap&&(m.sheenColorMap.value=f.sheenColorMap,e(f.sheenColorMap,m.sheenColorMapTransform)),f.sheenRoughnessMap&&(m.sheenRoughnessMap.value=f.sheenRoughnessMap,e(f.sheenRoughnessMap,m.sheenRoughnessMapTransform))),f.clearcoat>0&&(m.clearcoat.value=f.clearcoat,m.clearcoatRoughness.value=f.clearcoatRoughness,f.clearcoatMap&&(m.clearcoatMap.value=f.clearcoatMap,e(f.clearcoatMap,m.clearcoatMapTransform)),f.clearcoatRoughnessMap&&(m.clearcoatRoughnessMap.value=f.clearcoatRoughnessMap,e(f.clearcoatRoughnessMap,m.clearcoatRoughnessMapTransform)),f.clearcoatNormalMap&&(m.clearcoatNormalMap.value=f.clearcoatNormalMap,e(f.clearcoatNormalMap,m.clearcoatNormalMapTransform),m.clearcoatNormalScale.value.copy(f.clearcoatNormalScale),f.side===Ae&&m.clearcoatNormalScale.value.negate())),f.dispersion>0&&(m.dispersion.value=f.dispersion),f.iridescence>0&&(m.iridescence.value=f.iridescence,m.iridescenceIOR.value=f.iridescenceIOR,m.iridescenceThicknessMinimum.value=f.iridescenceThicknessRange[0],m.iridescenceThicknessMaximum.value=f.iridescenceThicknessRange[1],f.iridescenceMap&&(m.iridescenceMap.value=f.iridescenceMap,e(f.iridescenceMap,m.iridescenceMapTransform)),f.iridescenceThicknessMap&&(m.iridescenceThicknessMap.value=f.iridescenceThicknessMap,e(f.iridescenceThicknessMap,m.iridescenceThicknessMapTransform))),f.transmission>0&&(m.transmission.value=f.transmission,m.transmissionSamplerMap.value=b.texture,m.transmissionSamplerSize.value.set(b.width,b.height),f.transmissionMap&&(m.transmissionMap.value=f.transmissionMap,e(f.transmissionMap,m.transmissionMapTransform)),m.thickness.value=f.thickness,f.thicknessMap&&(m.thicknessMap.value=f.thicknessMap,e(f.thicknessMap,m.thicknessMapTransform)),m.attenuationDistance.value=f.attenuationDistance,m.attenuationColor.value.copy(f.attenuationColor)),f.anisotropy>0&&(m.anisotropyVector.value.set(f.anisotropy*Math.cos(f.anisotropyRotation),f.anisotropy*Math.sin(f.anisotropyRotation)),f.anisotropyMap&&(m.anisotropyMap.value=f.anisotropyMap,e(f.anisotropyMap,m.anisotropyMapTransform))),m.specularIntensity.value=f.specularIntensity,m.specularColor.value.copy(f.specularColor),f.specularColorMap&&(m.specularColorMap.value=f.specularColorMap,e(f.specularColorMap,m.specularColorMapTransform)),f.specularIntensityMap&&(m.specularIntensityMap.value=f.specularIntensityMap,e(f.specularIntensityMap,m.specularIntensityMapTransform))}function g(m,f){f.matcap&&(m.matcap.value=f.matcap)}function _(m,f){const b=t.get(f).light;m.referencePosition.value.setFromMatrixPosition(b.matrixWorld),m.nearDistance.value=b.shadow.camera.near,m.farDistance.value=b.shadow.camera.far}return{refreshFogUniforms:n,refreshMaterialUniforms:i}}function Ym(s,t,e,n){let i={},r={},a=[];const o=s.getParameter(s.MAX_UNIFORM_BUFFER_BINDINGS);function c(b,E){const x=E.program;n.uniformBlockBinding(b,x)}function l(b,E){let x=i[b.id];x===void 0&&(g(b),x=h(b),i[b.id]=x,b.addEventListener("dispose",m));const P=E.program;n.updateUBOMapping(b,P);const A=t.render.frame;r[b.id]!==A&&(d(b),r[b.id]=A)}function h(b){const E=u();b.__bindingPointIndex=E;const x=s.createBuffer(),P=b.__size,A=b.usage;return s.bindBuffer(s.UNIFORM_BUFFER,x),s.bufferData(s.UNIFORM_BUFFER,P,A),s.bindBuffer(s.UNIFORM_BUFFER,null),s.bindBufferBase(s.UNIFORM_BUFFER,E,x),x}function u(){for(let b=0;b0&&(x+=P-A),b.__size=x,b.__cache={},this}function _(b){const E={boundary:0,storage:0};return typeof b=="number"||typeof b=="boolean"?(E.boundary=4,E.storage=4):b.isVector2?(E.boundary=8,E.storage=8):b.isVector3||b.isColor?(E.boundary=16,E.storage=12):b.isVector4?(E.boundary=16,E.storage=16):b.isMatrix3?(E.boundary=48,E.storage=48):b.isMatrix4?(E.boundary=64,E.storage=64):b.isTexture?console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group."):console.warn("THREE.WebGLRenderer: Unsupported uniform value type.",b),E}function m(b){const E=b.target;E.removeEventListener("dispose",m);const x=a.indexOf(E.__bindingPointIndex);a.splice(x,1),s.deleteBuffer(i[E.id]),delete i[E.id],delete r[E.id]}function f(){for(const b in i)s.deleteBuffer(i[b]);a=[],i={},r={}}return{bind:c,update:l,dispose:f}}class Zg{constructor(t={}){const{canvas:e=Dh(),context:n=null,depth:i=!0,stencil:r=!1,alpha:a=!1,antialias:o=!1,premultipliedAlpha:c=!0,preserveDrawingBuffer:l=!1,powerPreference:h="default",failIfMajorPerformanceCaveat:u=!1,reverseDepthBuffer:d=!1}=t;this.isWebGLRenderer=!0;let p;if(n!==null){if(typeof WebGLRenderingContext<"u"&&n instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");p=n.getContextAttributes().alpha}else p=a;const g=new Uint32Array(4),_=new Int32Array(4);let m=null,f=null;const b=[],E=[];this.domElement=e,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this._outputColorSpace=ze,this.toneMapping=In,this.toneMappingExposure=1;const x=this;let P=!1,A=0,w=0,C=null,y=-1,v=null;const I=new Xt,V=new Xt;let B=null;const G=new Et(0);let K=0,W=e.width,Q=e.height,H=1,it=null,lt=null;const vt=new Xt(0,0,W,Q),Nt=new Xt(0,0,W,Q);let Jt=!1;const q=new Qs;let tt=!1,gt=!1;const st=new Lt,bt=new Lt,wt=new R,Ft=new Xt,se={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};let kt=!1;function oe(){return C===null?H:1}let N=n;function Fe(S,D){return e.getContext(S,D)}try{const S={alpha:!0,depth:i,stencil:r,antialias:o,premultipliedAlpha:c,preserveDrawingBuffer:l,powerPreference:h,failIfMajorPerformanceCaveat:u};if("setAttribute"in e&&e.setAttribute("data-engine",`three.js r${Fa}`),e.addEventListener("webglcontextlost",j,!1),e.addEventListener("webglcontextrestored",ct,!1),e.addEventListener("webglcontextcreationerror",at,!1),N===null){const D="webgl2";if(N=Fe(D,S),N===null)throw Fe(D)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}}catch(S){throw console.error("THREE.WebGLRenderer: "+S.message),S}let Bt,Ot,yt,ee,Mt,T,M,F,Y,Z,X,_t,rt,ht,Ht,$,ut,St,Tt,dt,zt,Dt,Qt,L;function nt(){Bt=new Qf(N),Bt.init(),Dt=new Om(N,Bt),Ot=new Yf(N,Bt,t,Dt),yt=new Nm(N,Bt),Ot.reverseDepthBuffer&&d&&yt.buffers.depth.setReversed(!0),ee=new np(N),Mt=new Mm,T=new Bm(N,Bt,yt,Mt,Ot,Dt,ee),M=new Kf(x),F=new Jf(x),Y=new cu(N),Qt=new Xf(N,Y),Z=new tp(N,Y,ee,Qt),X=new sp(N,Z,Y,ee),Tt=new ip(N,Ot,T),$=new jf(Mt),_t=new vm(x,M,F,Bt,Ot,Qt,$),rt=new qm(x,Mt),ht=new Sm,Ht=new Rm(Bt),St=new Wf(x,M,F,yt,X,p,c),ut=new Dm(x,X,Ot),L=new Ym(N,ee,Ot,yt),dt=new qf(N,Bt,ee),zt=new ep(N,Bt,ee),ee.programs=_t.programs,x.capabilities=Ot,x.extensions=Bt,x.properties=Mt,x.renderLists=ht,x.shadowMap=ut,x.state=yt,x.info=ee}nt();const k=new Wm(x,N);this.xr=k,this.getContext=function(){return N},this.getContextAttributes=function(){return N.getContextAttributes()},this.forceContextLoss=function(){const S=Bt.get("WEBGL_lose_context");S&&S.loseContext()},this.forceContextRestore=function(){const S=Bt.get("WEBGL_lose_context");S&&S.restoreContext()},this.getPixelRatio=function(){return H},this.setPixelRatio=function(S){S!==void 0&&(H=S,this.setSize(W,Q,!1))},this.getSize=function(S){return S.set(W,Q)},this.setSize=function(S,D,O=!0){if(k.isPresenting){console.warn("THREE.WebGLRenderer: Can't change size while VR device is presenting.");return}W=S,Q=D,e.width=Math.floor(S*H),e.height=Math.floor(D*H),O===!0&&(e.style.width=S+"px",e.style.height=D+"px"),this.setViewport(0,0,S,D)},this.getDrawingBufferSize=function(S){return S.set(W*H,Q*H).floor()},this.setDrawingBufferSize=function(S,D,O){W=S,Q=D,H=O,e.width=Math.floor(S*O),e.height=Math.floor(D*O),this.setViewport(0,0,S,D)},this.getCurrentViewport=function(S){return S.copy(I)},this.getViewport=function(S){return S.copy(vt)},this.setViewport=function(S,D,O,z){S.isVector4?vt.set(S.x,S.y,S.z,S.w):vt.set(S,D,O,z),yt.viewport(I.copy(vt).multiplyScalar(H).round())},this.getScissor=function(S){return S.copy(Nt)},this.setScissor=function(S,D,O,z){S.isVector4?Nt.set(S.x,S.y,S.z,S.w):Nt.set(S,D,O,z),yt.scissor(V.copy(Nt).multiplyScalar(H).round())},this.getScissorTest=function(){return Jt},this.setScissorTest=function(S){yt.setScissorTest(Jt=S)},this.setOpaqueSort=function(S){it=S},this.setTransparentSort=function(S){lt=S},this.getClearColor=function(S){return S.copy(St.getClearColor())},this.setClearColor=function(){St.setClearColor.apply(St,arguments)},this.getClearAlpha=function(){return St.getClearAlpha()},this.setClearAlpha=function(){St.setClearAlpha.apply(St,arguments)},this.clear=function(S=!0,D=!0,O=!0){let z=0;if(S){let U=!1;if(C!==null){const J=C.texture.format;U=J===Ga||J===Ha||J===$s}if(U){const J=C.texture.type,ot=J===gn||J===Ln||J===Xi||J===yi||J===za||J===Va,ft=St.getClearColor(),pt=St.getClearAlpha(),At=ft.r,Ct=ft.g,mt=ft.b;ot?(g[0]=At,g[1]=Ct,g[2]=mt,g[3]=pt,N.clearBufferuiv(N.COLOR,0,g)):(_[0]=At,_[1]=Ct,_[2]=mt,_[3]=pt,N.clearBufferiv(N.COLOR,0,_))}else z|=N.COLOR_BUFFER_BIT}D&&(z|=N.DEPTH_BUFFER_BIT),O&&(z|=N.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),N.clear(z)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.dispose=function(){e.removeEventListener("webglcontextlost",j,!1),e.removeEventListener("webglcontextrestored",ct,!1),e.removeEventListener("webglcontextcreationerror",at,!1),ht.dispose(),Ht.dispose(),Mt.dispose(),M.dispose(),F.dispose(),X.dispose(),Qt.dispose(),L.dispose(),_t.dispose(),k.dispose(),k.removeEventListener("sessionstart",$a),k.removeEventListener("sessionend",Ja),Fn.stop()};function j(S){S.preventDefault(),console.log("THREE.WebGLRenderer: Context Lost."),P=!0}function ct(){console.log("THREE.WebGLRenderer: Context Restored."),P=!1;const S=ee.autoReset,D=ut.enabled,O=ut.autoUpdate,z=ut.needsUpdate,U=ut.type;nt(),ee.autoReset=S,ut.enabled=D,ut.autoUpdate=O,ut.needsUpdate=z,ut.type=U}function at(S){console.error("THREE.WebGLRenderer: A WebGL context could not be created. Reason: ",S.statusMessage)}function Rt(S){const D=S.target;D.removeEventListener("dispose",Rt),re(D)}function re(S){me(S),Mt.remove(S)}function me(S){const D=Mt.get(S).programs;D!==void 0&&(D.forEach(function(O){_t.releaseProgram(O)}),S.isShaderMaterial&&_t.releaseShaderCache(S))}this.renderBufferDirect=function(S,D,O,z,U,J){D===null&&(D=se);const ot=U.isMesh&&U.matrixWorld.determinant()<0,ft=Sl(S,D,O,z,U);yt.setMaterial(z,ot);let pt=O.index,At=1;if(z.wireframe===!0){if(pt=Z.getWireframeAttribute(O),pt===void 0)return;At=2}const Ct=O.drawRange,mt=O.attributes.position;let Gt=Ct.start*At,te=(Ct.start+Ct.count)*At;J!==null&&(Gt=Math.max(Gt,J.start*At),te=Math.min(te,(J.start+J.count)*At)),pt!==null?(Gt=Math.max(Gt,0),te=Math.min(te,pt.count)):mt!=null&&(Gt=Math.max(Gt,0),te=Math.min(te,mt.count));const ne=te-Gt;if(ne<0||ne===1/0)return;Qt.setup(U,z,ft,O,pt);let Se,qt=dt;if(pt!==null&&(Se=Y.get(pt),qt=zt,qt.setIndex(Se)),U.isMesh)z.wireframe===!0?(yt.setLineWidth(z.wireframeLinewidth*oe()),qt.setMode(N.LINES)):qt.setMode(N.TRIANGLES);else if(U.isLine){let xt=z.linewidth;xt===void 0&&(xt=1),yt.setLineWidth(xt*oe()),U.isLineSegments?qt.setMode(N.LINES):U.isLineLoop?qt.setMode(N.LINE_LOOP):qt.setMode(N.LINE_STRIP)}else U.isPoints?qt.setMode(N.POINTS):U.isSprite&&qt.setMode(N.TRIANGLES);if(U.isBatchedMesh)if(U._multiDrawInstances!==null)qt.renderMultiDrawInstances(U._multiDrawStarts,U._multiDrawCounts,U._multiDrawCount,U._multiDrawInstances);else if(Bt.get("WEBGL_multi_draw"))qt.renderMultiDraw(U._multiDrawStarts,U._multiDrawCounts,U._multiDrawCount);else{const xt=U._multiDrawStarts,tn=U._multiDrawCounts,Yt=U._multiDrawCount,He=pt?Y.get(pt).bytesPerElement:1,Kn=Mt.get(z).currentProgram.getUniforms();for(let Re=0;Re{function J(){if(z.forEach(function(ot){Mt.get(ot).currentProgram.isReady()&&z.delete(ot)}),z.size===0){U(S);return}setTimeout(J,10)}Bt.get("KHR_parallel_shader_compile")!==null?J():setTimeout(J,10)})};let ke=null;function Qe(S){ke&&ke(S)}function $a(){Fn.stop()}function Ja(){Fn.start()}const Fn=new Qc;Fn.setAnimationLoop(Qe),typeof self<"u"&&Fn.setContext(self),this.setAnimationLoop=function(S){ke=S,k.setAnimationLoop(S),S===null?Fn.stop():Fn.start()},k.addEventListener("sessionstart",$a),k.addEventListener("sessionend",Ja),this.render=function(S,D){if(D!==void 0&&D.isCamera!==!0){console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(P===!0)return;if(S.matrixWorldAutoUpdate===!0&&S.updateMatrixWorld(),D.parent===null&&D.matrixWorldAutoUpdate===!0&&D.updateMatrixWorld(),k.enabled===!0&&k.isPresenting===!0&&(k.cameraAutoUpdate===!0&&k.updateCamera(D),D=k.getCamera()),S.isScene===!0&&S.onBeforeRender(x,S,D,C),f=Ht.get(S,E.length),f.init(D),E.push(f),bt.multiplyMatrices(D.projectionMatrix,D.matrixWorldInverse),q.setFromProjectionMatrix(bt),gt=this.localClippingEnabled,tt=$.init(this.clippingPlanes,gt),m=ht.get(S,b.length),m.init(),b.push(m),k.enabled===!0&&k.isPresenting===!0){const J=x.xr.getDepthSensingMesh();J!==null&&ar(J,D,-1/0,x.sortObjects)}ar(S,D,0,x.sortObjects),m.finish(),x.sortObjects===!0&&m.sort(it,lt),kt=k.enabled===!1||k.isPresenting===!1||k.hasDepthSensing()===!1,kt&&St.addToRenderList(m,S),this.info.render.frame++,tt===!0&&$.beginShadows();const O=f.state.shadowsArray;ut.render(O,S,D),tt===!0&&$.endShadows(),this.info.autoReset===!0&&this.info.reset();const z=m.opaque,U=m.transmissive;if(f.setupLights(),D.isArrayCamera){const J=D.cameras;if(U.length>0)for(let ot=0,ft=J.length;ot0&&to(z,U,S,D),kt&&St.render(S),Qa(m,S,D);C!==null&&(T.updateMultisampleRenderTarget(C),T.updateRenderTargetMipmap(C)),S.isScene===!0&&S.onAfterRender(x,S,D),Qt.resetDefaultState(),y=-1,v=null,E.pop(),E.length>0?(f=E[E.length-1],tt===!0&&$.setGlobalState(x.clippingPlanes,f.state.camera)):f=null,b.pop(),b.length>0?m=b[b.length-1]:m=null};function ar(S,D,O,z){if(S.visible===!1)return;if(S.layers.test(D.layers)){if(S.isGroup)O=S.renderOrder;else if(S.isLOD)S.autoUpdate===!0&&S.update(D);else if(S.isLight)f.pushLight(S),S.castShadow&&f.pushShadow(S);else if(S.isSprite){if(!S.frustumCulled||q.intersectsSprite(S)){z&&Ft.setFromMatrixPosition(S.matrixWorld).applyMatrix4(bt);const ot=X.update(S),ft=S.material;ft.visible&&m.push(S,ot,ft,O,Ft.z,null)}}else if((S.isMesh||S.isLine||S.isPoints)&&(!S.frustumCulled||q.intersectsObject(S))){const ot=X.update(S),ft=S.material;if(z&&(S.boundingSphere!==void 0?(S.boundingSphere===null&&S.computeBoundingSphere(),Ft.copy(S.boundingSphere.center)):(ot.boundingSphere===null&&ot.computeBoundingSphere(),Ft.copy(ot.boundingSphere.center)),Ft.applyMatrix4(S.matrixWorld).applyMatrix4(bt)),Array.isArray(ft)){const pt=ot.groups;for(let At=0,Ct=pt.length;At0&&ts(U,D,O),J.length>0&&ts(J,D,O),ot.length>0&&ts(ot,D,O),yt.buffers.depth.setTest(!0),yt.buffers.depth.setMask(!0),yt.buffers.color.setMask(!0),yt.setPolygonOffset(!1)}function to(S,D,O,z){if((O.isScene===!0?O.overrideMaterial:null)!==null)return;f.state.transmissionRenderTarget[z.id]===void 0&&(f.state.transmissionRenderTarget[z.id]=new Dn(1,1,{generateMipmaps:!0,type:Bt.has("EXT_color_buffer_half_float")||Bt.has("EXT_color_buffer_float")?ji:gn,minFilter:wn,samples:4,stencilBuffer:r,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:Vt.workingColorSpace}));const J=f.state.transmissionRenderTarget[z.id],ot=z.viewport||I;J.setSize(ot.z,ot.w);const ft=x.getRenderTarget();x.setRenderTarget(J),x.getClearColor(G),K=x.getClearAlpha(),K<1&&x.setClearColor(16777215,.5),x.clear(),kt&&St.render(O);const pt=x.toneMapping;x.toneMapping=In;const At=z.viewport;if(z.viewport!==void 0&&(z.viewport=void 0),f.setupLightsView(z),tt===!0&&$.setGlobalState(x.clippingPlanes,z),ts(S,O,z),T.updateMultisampleRenderTarget(J),T.updateRenderTargetMipmap(J),Bt.has("WEBGL_multisampled_render_to_texture")===!1){let Ct=!1;for(let mt=0,Gt=D.length;mt0),mt=!!O.morphAttributes.position,Gt=!!O.morphAttributes.normal,te=!!O.morphAttributes.color;let ne=In;z.toneMapped&&(C===null||C.isXRRenderTarget===!0)&&(ne=x.toneMapping);const Se=O.morphAttributes.position||O.morphAttributes.normal||O.morphAttributes.color,qt=Se!==void 0?Se.length:0,xt=Mt.get(z),tn=f.state.lights;if(tt===!0&&(gt===!0||S!==v)){const Be=S===v&&z.id===y;$.setState(z,S,Be)}let Yt=!1;z.version===xt.__version?(xt.needsLights&&xt.lightsStateVersion!==tn.state.version||xt.outputColorSpace!==ft||U.isBatchedMesh&&xt.batching===!1||!U.isBatchedMesh&&xt.batching===!0||U.isBatchedMesh&&xt.batchingColor===!0&&U.colorTexture===null||U.isBatchedMesh&&xt.batchingColor===!1&&U.colorTexture!==null||U.isInstancedMesh&&xt.instancing===!1||!U.isInstancedMesh&&xt.instancing===!0||U.isSkinnedMesh&&xt.skinning===!1||!U.isSkinnedMesh&&xt.skinning===!0||U.isInstancedMesh&&xt.instancingColor===!0&&U.instanceColor===null||U.isInstancedMesh&&xt.instancingColor===!1&&U.instanceColor!==null||U.isInstancedMesh&&xt.instancingMorph===!0&&U.morphTexture===null||U.isInstancedMesh&&xt.instancingMorph===!1&&U.morphTexture!==null||xt.envMap!==pt||z.fog===!0&&xt.fog!==J||xt.numClippingPlanes!==void 0&&(xt.numClippingPlanes!==$.numPlanes||xt.numIntersection!==$.numIntersection)||xt.vertexAlphas!==At||xt.vertexTangents!==Ct||xt.morphTargets!==mt||xt.morphNormals!==Gt||xt.morphColors!==te||xt.toneMapping!==ne||xt.morphTargetsCount!==qt)&&(Yt=!0):(Yt=!0,xt.__version=z.version);let He=xt.currentProgram;Yt===!0&&(He=es(z,D,U));let Kn=!1,Re=!1,Ii=!1;const ie=He.getUniforms(),Ze=xt.uniforms;if(yt.useProgram(He.program)&&(Kn=!0,Re=!0,Ii=!0),z.id!==y&&(y=z.id,Re=!0),Kn||v!==S){yt.buffers.depth.getReversed()?(st.copy(S.projectionMatrix),Nh(st),Fh(st),ie.setValue(N,"projectionMatrix",st)):ie.setValue(N,"projectionMatrix",S.projectionMatrix),ie.setValue(N,"viewMatrix",S.matrixWorldInverse);const _n=ie.map.cameraPosition;_n!==void 0&&_n.setValue(N,wt.setFromMatrixPosition(S.matrixWorld)),Ot.logarithmicDepthBuffer&&ie.setValue(N,"logDepthBufFC",2/(Math.log(S.far+1)/Math.LN2)),(z.isMeshPhongMaterial||z.isMeshToonMaterial||z.isMeshLambertMaterial||z.isMeshBasicMaterial||z.isMeshStandardMaterial||z.isShaderMaterial)&&ie.setValue(N,"isOrthographic",S.isOrthographicCamera===!0),v!==S&&(v=S,Re=!0,Ii=!0)}if(U.isSkinnedMesh){ie.setOptional(N,U,"bindMatrix"),ie.setOptional(N,U,"bindMatrixInverse");const Be=U.skeleton;Be&&(Be.boneTexture===null&&Be.computeBoneTexture(),ie.setValue(N,"boneTexture",Be.boneTexture,T))}U.isBatchedMesh&&(ie.setOptional(N,U,"batchingTexture"),ie.setValue(N,"batchingTexture",U._matricesTexture,T),ie.setOptional(N,U,"batchingIdTexture"),ie.setValue(N,"batchingIdTexture",U._indirectTexture,T),ie.setOptional(N,U,"batchingColorTexture"),U._colorsTexture!==null&&ie.setValue(N,"batchingColorTexture",U._colorsTexture,T));const Pi=O.morphAttributes;if((Pi.position!==void 0||Pi.normal!==void 0||Pi.color!==void 0)&&Tt.update(U,O,He),(Re||xt.receiveShadow!==U.receiveShadow)&&(xt.receiveShadow=U.receiveShadow,ie.setValue(N,"receiveShadow",U.receiveShadow)),z.isMeshGouraudMaterial&&z.envMap!==null&&(Ze.envMap.value=pt,Ze.flipEnvMap.value=pt.isCubeTexture&&pt.isRenderTargetTexture===!1?-1:1),z.isMeshStandardMaterial&&z.envMap===null&&D.environment!==null&&(Ze.envMapIntensity.value=D.environmentIntensity),Re&&(ie.setValue(N,"toneMappingExposure",x.toneMappingExposure),xt.needsLights&&El(Ze,Ii),J&&z.fog===!0&&rt.refreshFogUniforms(Ze,J),rt.refreshMaterialUniforms(Ze,z,H,Q,f.state.transmissionRenderTarget[S.id]),ks.upload(N,no(xt),Ze,T)),z.isShaderMaterial&&z.uniformsNeedUpdate===!0&&(ks.upload(N,no(xt),Ze,T),z.uniformsNeedUpdate=!1),z.isSpriteMaterial&&ie.setValue(N,"center",U.center),ie.setValue(N,"modelViewMatrix",U.modelViewMatrix),ie.setValue(N,"normalMatrix",U.normalMatrix),ie.setValue(N,"modelMatrix",U.matrixWorld),z.isShaderMaterial||z.isRawShaderMaterial){const Be=z.uniformsGroups;for(let _n=0,xn=Be.length;_n0&&T.useMultisampledRTT(S)===!1?U=Mt.get(S).__webglMultisampledFramebuffer:Array.isArray(Ct)?U=Ct[O]:U=Ct,I.copy(S.viewport),V.copy(S.scissor),B=S.scissorTest}else I.copy(vt).multiplyScalar(H).floor(),V.copy(Nt).multiplyScalar(H).floor(),B=Jt;if(yt.bindFramebuffer(N.FRAMEBUFFER,U)&&z&&yt.drawBuffers(S,U),yt.viewport(I),yt.scissor(V),yt.setScissorTest(B),J){const pt=Mt.get(S.texture);N.framebufferTexture2D(N.FRAMEBUFFER,N.COLOR_ATTACHMENT0,N.TEXTURE_CUBE_MAP_POSITIVE_X+D,pt.__webglTexture,O)}else if(ot){const pt=Mt.get(S.texture),At=D||0;N.framebufferTextureLayer(N.FRAMEBUFFER,N.COLOR_ATTACHMENT0,pt.__webglTexture,O||0,At)}y=-1},this.readRenderTargetPixels=function(S,D,O,z,U,J,ot){if(!(S&&S.isWebGLRenderTarget)){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let ft=Mt.get(S).__webglFramebuffer;if(S.isWebGLCubeRenderTarget&&ot!==void 0&&(ft=ft[ot]),ft){yt.bindFramebuffer(N.FRAMEBUFFER,ft);try{const pt=S.texture,At=pt.format,Ct=pt.type;if(!Ot.textureFormatReadable(At)){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}if(!Ot.textureTypeReadable(Ct)){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");return}D>=0&&D<=S.width-z&&O>=0&&O<=S.height-U&&N.readPixels(D,O,z,U,Dt.convert(At),Dt.convert(Ct),J)}finally{const pt=C!==null?Mt.get(C).__webglFramebuffer:null;yt.bindFramebuffer(N.FRAMEBUFFER,pt)}}},this.readRenderTargetPixelsAsync=async function(S,D,O,z,U,J,ot){if(!(S&&S.isWebGLRenderTarget))throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let ft=Mt.get(S).__webglFramebuffer;if(S.isWebGLCubeRenderTarget&&ot!==void 0&&(ft=ft[ot]),ft){const pt=S.texture,At=pt.format,Ct=pt.type;if(!Ot.textureFormatReadable(At))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!Ot.textureTypeReadable(Ct))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");if(D>=0&&D<=S.width-z&&O>=0&&O<=S.height-U){yt.bindFramebuffer(N.FRAMEBUFFER,ft);const mt=N.createBuffer();N.bindBuffer(N.PIXEL_PACK_BUFFER,mt),N.bufferData(N.PIXEL_PACK_BUFFER,J.byteLength,N.STREAM_READ),N.readPixels(D,O,z,U,Dt.convert(At),Dt.convert(Ct),0);const Gt=C!==null?Mt.get(C).__webglFramebuffer:null;yt.bindFramebuffer(N.FRAMEBUFFER,Gt);const te=N.fenceSync(N.SYNC_GPU_COMMANDS_COMPLETE,0);return N.flush(),await Uh(N,te,4),N.bindBuffer(N.PIXEL_PACK_BUFFER,mt),N.getBufferSubData(N.PIXEL_PACK_BUFFER,0,J),N.deleteBuffer(mt),N.deleteSync(te),J}else throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")}},this.copyFramebufferToTexture=function(S,D=null,O=0){S.isTexture!==!0&&(ki("WebGLRenderer: copyFramebufferToTexture function signature has changed."),D=arguments[0]||null,S=arguments[1]);const z=Math.pow(2,-O),U=Math.floor(S.image.width*z),J=Math.floor(S.image.height*z),ot=D!==null?D.x:0,ft=D!==null?D.y:0;T.setTexture2D(S,0),N.copyTexSubImage2D(N.TEXTURE_2D,O,0,0,ot,ft,U,J),yt.unbindTexture()},this.copyTextureToTexture=function(S,D,O=null,z=null,U=0){S.isTexture!==!0&&(ki("WebGLRenderer: copyTextureToTexture function signature has changed."),z=arguments[0]||null,S=arguments[1],D=arguments[2],U=arguments[3]||0,O=null);let J,ot,ft,pt,At,Ct,mt,Gt,te;const ne=S.isCompressedTexture?S.mipmaps[U]:S.image;O!==null?(J=O.max.x-O.min.x,ot=O.max.y-O.min.y,ft=O.isBox3?O.max.z-O.min.z:1,pt=O.min.x,At=O.min.y,Ct=O.isBox3?O.min.z:0):(J=ne.width,ot=ne.height,ft=ne.depth||1,pt=0,At=0,Ct=0),z!==null?(mt=z.x,Gt=z.y,te=z.z):(mt=0,Gt=0,te=0);const Se=Dt.convert(D.format),qt=Dt.convert(D.type);let xt;D.isData3DTexture?(T.setTexture3D(D,0),xt=N.TEXTURE_3D):D.isDataArrayTexture||D.isCompressedArrayTexture?(T.setTexture2DArray(D,0),xt=N.TEXTURE_2D_ARRAY):(T.setTexture2D(D,0),xt=N.TEXTURE_2D),N.pixelStorei(N.UNPACK_FLIP_Y_WEBGL,D.flipY),N.pixelStorei(N.UNPACK_PREMULTIPLY_ALPHA_WEBGL,D.premultiplyAlpha),N.pixelStorei(N.UNPACK_ALIGNMENT,D.unpackAlignment);const tn=N.getParameter(N.UNPACK_ROW_LENGTH),Yt=N.getParameter(N.UNPACK_IMAGE_HEIGHT),He=N.getParameter(N.UNPACK_SKIP_PIXELS),Kn=N.getParameter(N.UNPACK_SKIP_ROWS),Re=N.getParameter(N.UNPACK_SKIP_IMAGES);N.pixelStorei(N.UNPACK_ROW_LENGTH,ne.width),N.pixelStorei(N.UNPACK_IMAGE_HEIGHT,ne.height),N.pixelStorei(N.UNPACK_SKIP_PIXELS,pt),N.pixelStorei(N.UNPACK_SKIP_ROWS,At),N.pixelStorei(N.UNPACK_SKIP_IMAGES,Ct);const Ii=S.isDataArrayTexture||S.isData3DTexture,ie=D.isDataArrayTexture||D.isData3DTexture;if(S.isRenderTargetTexture||S.isDepthTexture){const Ze=Mt.get(S),Pi=Mt.get(D),Be=Mt.get(Ze.__renderTarget),_n=Mt.get(Pi.__renderTarget);yt.bindFramebuffer(N.READ_FRAMEBUFFER,Be.__webglFramebuffer),yt.bindFramebuffer(N.DRAW_FRAMEBUFFER,_n.__webglFramebuffer);for(let xn=0;xn0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(e.object.backgroundIntensity=this.backgroundIntensity),e.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(e.object.environmentIntensity=this.environmentIntensity),e.object.environmentRotation=this.environmentRotation.toArray(),e}}class Jg{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=t!==void 0?t.length/e:0,this.usage=La,this.updateRanges=[],this.version=0,this.uuid=Ye()}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,n){t*=this.stride,n*=e.stride;for(let i=0,r=this.stride;i=r.length&&r.push({start:-1,count:-1,z:-1,index:-1});const o=r[this.index];a.push(o),this.index++,o.start=t,o.count=e,o.z=n,o.index=i}reset(){this.list.length=0,this.index=0}}const Ee=new Lt,eg=new Et(1,1,1),zr=new Qs,As=new Ne,Gn=new we,Oi=new R,pc=new R,ng=new R,Vr=new tg,xe=new Te,ws=[];function ig(s,t,e=0){const n=t.itemSize;if(s.isInterleavedBufferAttribute||s.array.constructor!==t.array.constructor){const i=s.count;for(let r=0;r65535?new Uint32Array(i):new Uint16Array(i);e.setIndex(new pe(r,1))}this._geometryInitialized=!0}}_validateGeometry(t){const e=this.geometry;if(!!t.getIndex()!=!!e.getIndex())throw new Error('BatchedMesh: All geometries must consistently have "index".');for(const n in e.attributes){if(!t.hasAttribute(n))throw new Error(`BatchedMesh: Added geometry missing "${n}". All geometries must have consistent attributes.`);const i=t.getAttribute(n),r=e.getAttribute(n);if(i.itemSize!==r.itemSize||i.normalized!==r.normalized)throw new Error("BatchedMesh: All attributes must have a consistent itemSize and normalized value.")}}setCustomSort(t){return this.customSort=t,this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Ne);const t=this.boundingBox,e=this._instanceInfo;t.makeEmpty();for(let n=0,i=e.length;n=this.maxInstanceCount&&this._availableInstanceIds.length===0)throw new Error("BatchedMesh: Maximum item count reached.");const n={visible:!0,active:!0,geometryIndex:t};let i=null;this._availableInstanceIds.length>0?(this._availableInstanceIds.sort(Or),i=this._availableInstanceIds.shift(),this._instanceInfo[i]=n):(i=this._instanceInfo.length,this._instanceInfo.push(n));const r=this._matricesTexture;Ee.identity().toArray(r.image.data,i*16),r.needsUpdate=!0;const a=this._colorsTexture;return a&&(eg.toArray(a.image.data,i*4),a.needsUpdate=!0),this._visibilityChanged=!0,i}addGeometry(t,e=-1,n=-1){this._initializeGeometry(t),this._validateGeometry(t);const i={vertexStart:-1,vertexCount:-1,reservedVertexCount:-1,indexStart:-1,indexCount:-1,reservedIndexCount:-1,start:-1,count:-1,boundingBox:null,boundingSphere:null,active:!0},r=this._geometryInfo;i.vertexStart=this._nextVertexStart,i.reservedVertexCount=e===-1?t.getAttribute("position").count:e;const a=t.getIndex();if(a!==null&&(i.indexStart=this._nextIndexStart,i.reservedIndexCount=n===-1?a.count:n),i.indexStart!==-1&&i.indexStart+i.reservedIndexCount>this._maxIndexCount||i.vertexStart+i.reservedVertexCount>this._maxVertexCount)throw new Error("BatchedMesh: Reserved space request exceeds the maximum buffer size.");let c;return this._availableGeometryIds.length>0?(this._availableGeometryIds.sort(Or),c=this._availableGeometryIds.shift(),r[c]=i):(c=this._geometryCount,this._geometryCount++,r.push(i)),this.setGeometryAt(c,t),this._nextIndexStart=i.indexStart+i.reservedIndexCount,this._nextVertexStart=i.vertexStart+i.reservedVertexCount,c}setGeometryAt(t,e){if(t>=this._geometryCount)throw new Error("BatchedMesh: Maximum geometry count reached.");this._validateGeometry(e);const n=this.geometry,i=n.getIndex()!==null,r=n.getIndex(),a=e.getIndex(),o=this._geometryInfo[t];if(i&&a.count>o.reservedIndexCount||e.attributes.position.count>o.reservedVertexCount)throw new Error("BatchedMesh: Reserved space not large enough for provided geometry.");const c=o.vertexStart,l=o.reservedVertexCount;o.vertexCount=e.getAttribute("position").count;for(const h in n.attributes){const u=e.getAttribute(h),d=n.getAttribute(h);ig(u,d,c);const p=u.itemSize;for(let g=u.count,_=l;g<_;g++){const m=c+g;for(let f=0;f=e.length||e[t].active===!1)return this;const n=this._instanceInfo;for(let i=0,r=n.length;i=e.length||e[t].active===!1?this:(e[t].active=!1,this._availableInstanceIds.push(t),this._visibilityChanged=!0,this)}optimize(){let t=0,e=0;const n=this._geometryInfo,i=n.map((a,o)=>o).sort((a,o)=>n[a].vertexStart-n[o].vertexStart),r=this.geometry;for(let a=0,o=n.length;a=this._geometryCount)return null;const n=this.geometry,i=this._geometryInfo[t];if(i.boundingBox===null){const r=new Ne,a=n.index,o=n.attributes.position;for(let c=i.start,l=i.start+i.count;c=this._geometryCount)return null;const n=this.geometry,i=this._geometryInfo[t];if(i.boundingSphere===null){const r=new we;this.getBoundingBoxAt(t,As),As.getCenter(r.center);const a=n.index,o=n.attributes.position;let c=0;for(let l=i.start,h=i.start+i.count;l=n.length||n[t].active===!1?this:(e.toArray(r,t*16),i.needsUpdate=!0,this)}getMatrixAt(t,e){const n=this._instanceInfo,i=this._matricesTexture.image.data;return t>=n.length||n[t].active===!1?null:e.fromArray(i,t*16)}setColorAt(t,e){this._colorsTexture===null&&this._initColorsTexture();const n=this._colorsTexture,i=this._colorsTexture.image.data,r=this._instanceInfo;return t>=r.length||r[t].active===!1?this:(e.toArray(i,t*4),n.needsUpdate=!0,this)}getColorAt(t,e){const n=this._colorsTexture.image.data,i=this._instanceInfo;return t>=i.length||i[t].active===!1?null:e.fromArray(n,t*4)}setVisibleAt(t,e){const n=this._instanceInfo;return t>=n.length||n[t].active===!1||n[t].visible===e?this:(n[t].visible=e,this._visibilityChanged=!0,this)}getVisibleAt(t){const e=this._instanceInfo;return t>=e.length||e[t].active===!1?!1:e[t].visible}setGeometryIdAt(t,e){const n=this._instanceInfo,i=this._geometryInfo;return t>=n.length||n[t].active===!1||e>=i.length||i[e].active===!1?null:(n[t].geometryIndex=e,this)}getGeometryIdAt(t){const e=this._instanceInfo;return t>=e.length||e[t].active===!1?-1:e[t].geometryIndex}getGeometryRangeAt(t,e={}){if(t<0||t>=this._geometryCount)return null;const n=this._geometryInfo[t];return e.vertexStart=n.vertexStart,e.vertexCount=n.vertexCount,e.reservedVertexCount=n.reservedVertexCount,e.indexStart=n.indexStart,e.indexCount=n.indexCount,e.reservedIndexCount=n.reservedIndexCount,e.start=n.start,e.count=n.count,e}setInstanceCount(t){const e=this._availableInstanceIds,n=this._instanceInfo;for(e.sort(Or);e[e.length-1]===n.length;)n.pop(),e.pop();if(to.active);if(Math.max(...n.map(o=>o.vertexStart+o.reservedVertexCount))>t)throw new Error(`BatchedMesh: Geometry vertex values are being used outside the range ${e}. Cannot shrink further.`);if(this.geometry.index&&Math.max(...n.map(c=>c.indexStart+c.reservedIndexCount))>e)throw new Error(`BatchedMesh: Geometry index values are being used outside the range ${e}. Cannot shrink further.`);const r=this.geometry;r.dispose(),this._maxVertexCount=t,this._maxIndexCount=e,this._geometryInitialized&&(this._geometryInitialized=!1,this.geometry=new ce,this._initializeGeometry(r));const a=this.geometry;r.index&&Wn(r.index.array,a.index.array);for(const o in r.attributes)Wn(r.attributes[o].array,a.attributes[o].array)}raycast(t,e){const n=this._instanceInfo,i=this._geometryInfo,r=this.matrixWorld,a=this.geometry;xe.material=this.material,xe.geometry.index=a.index,xe.geometry.attributes=a.attributes,xe.geometry.boundingBox===null&&(xe.geometry.boundingBox=new Ne),xe.geometry.boundingSphere===null&&(xe.geometry.boundingSphere=new we);for(let o=0,c=n.length;o({...e,boundingBox:e.boundingBox!==null?e.boundingBox.clone():null,boundingSphere:e.boundingSphere!==null?e.boundingSphere.clone():null})),this._instanceInfo=t._instanceInfo.map(e=>({...e})),this._maxInstanceCount=t._maxInstanceCount,this._maxVertexCount=t._maxVertexCount,this._maxIndexCount=t._maxIndexCount,this._geometryInitialized=t._geometryInitialized,this._geometryCount=t._geometryCount,this._multiDrawCounts=t._multiDrawCounts.slice(),this._multiDrawStarts=t._multiDrawStarts.slice(),this._matricesTexture=t._matricesTexture.clone(),this._matricesTexture.image.data=this._matricesTexture.image.data.slice(),this._colorsTexture!==null&&(this._colorsTexture=t._colorsTexture.clone(),this._colorsTexture.image.data=this._colorsTexture.image.data.slice()),this}dispose(){return this.geometry.dispose(),this._matricesTexture.dispose(),this._matricesTexture=null,this._indirectTexture.dispose(),this._indirectTexture=null,this._colorsTexture!==null&&(this._colorsTexture.dispose(),this._colorsTexture=null),this}onBeforeRender(t,e,n,i,r){if(!this._visibilityChanged&&!this.perObjectFrustumCulled&&!this.sortObjects)return;const a=i.getIndex(),o=a===null?1:a.array.BYTES_PER_ELEMENT,c=this._instanceInfo,l=this._multiDrawStarts,h=this._multiDrawCounts,u=this._geometryInfo,d=this.perObjectFrustumCulled,p=this._indirectTexture,g=p.image.data;d&&(Ee.multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse).multiply(this.matrixWorld),zr.setFromProjectionMatrix(Ee,t.coordinateSystem));let _=0;if(this.sortObjects){Ee.copy(this.matrixWorld).invert(),Oi.setFromMatrixPosition(n.matrixWorld).applyMatrix4(Ee),pc.set(0,0,-1).transformDirection(n.matrixWorld).transformDirection(Ee);for(let b=0,E=c.length;b0){const i=e[n[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let r=0,a=i.length;rn)return;kr.applyMatrix4(s.matrixWorld);const c=t.ray.origin.distanceTo(kr);if(!(ct.far))return{distance:c,point:gc.clone().applyMatrix4(s.matrixWorld),index:i,face:null,faceIndex:null,barycoord:null,object:s}}const _c=new R,xc=new R;class nr extends ll{constructor(t,e){super(t,e),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const t=this.geometry;if(t.index===null){const e=t.attributes.position,n=[];for(let i=0,r=e.count;i0){const i=e[n[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let r=0,a=i.length;ri.far)return;r.push({distance:l,distanceToRay:Math.sqrt(o),point:c,index:t,face:null,faceIndex:null,barycoord:null,object:a})}}class hl extends ce{constructor(t=1,e=1,n=1,i=32,r=1,a=!1,o=0,c=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:t,radiusBottom:e,height:n,radialSegments:i,heightSegments:r,openEnded:a,thetaStart:o,thetaLength:c};const l=this;i=Math.floor(i),r=Math.floor(r);const h=[],u=[],d=[],p=[];let g=0;const _=[],m=n/2;let f=0;b(),a===!1&&(t>0&&E(!0),e>0&&E(!1)),this.setIndex(h),this.setAttribute("position",new Wt(u,3)),this.setAttribute("normal",new Wt(d,3)),this.setAttribute("uv",new Wt(p,2));function b(){const x=new R,P=new R;let A=0;const w=(e-t)/n;for(let C=0;C<=r;C++){const y=[],v=C/r,I=v*(e-t)+t;for(let V=0;V<=i;V++){const B=V/i,G=B*c+o,K=Math.sin(G),W=Math.cos(G);P.x=I*K,P.y=-v*n+m,P.z=I*W,u.push(P.x,P.y,P.z),x.set(K,w,W).normalize(),d.push(x.x,x.y,x.z),p.push(B,1-v),y.push(g++)}_.push(y)}for(let C=0;C0||y!==0)&&(h.push(v,I,B),A+=3),(e>0||y!==r-1)&&(h.push(I,V,B),A+=3)}l.addGroup(f,A,0),f+=A}function E(x){const P=g,A=new Pt,w=new R;let C=0;const y=x===!0?t:e,v=x===!0?1:-1;for(let V=1;V<=i;V++)u.push(0,m*v,0),d.push(0,v,0),p.push(.5,.5),g++;const I=g;for(let V=0;V<=i;V++){const G=V/i*c+o,K=Math.cos(G),W=Math.sin(G);w.x=y*W,w.y=m*v,w.z=y*K,u.push(w.x,w.y,w.z),d.push(0,v,0),A.x=K*.5+.5,A.y=W*.5*v+.5,p.push(A.x,A.y),g++}for(let V=0;V.9&&w<.1&&(E<.2&&(a[b+0]+=1),x<.2&&(a[b+2]+=1),P<.2&&(a[b+4]+=1))}}function d(b){r.push(b.x,b.y,b.z)}function p(b,E){const x=b*3;E.x=t[x+0],E.y=t[x+1],E.z=t[x+2]}function g(){const b=new R,E=new R,x=new R,P=new R,A=new Pt,w=new Pt,C=new Pt;for(let y=0,v=0;y0)&&p.push(E,x,A),(f!==n-1||c0!=t>0&&this.version++,this._anisotropy=t}get clearcoat(){return this._clearcoat}set clearcoat(t){this._clearcoat>0!=t>0&&this.version++,this._clearcoat=t}get iridescence(){return this._iridescence}set iridescence(t){this._iridescence>0!=t>0&&this.version++,this._iridescence=t}get dispersion(){return this._dispersion}set dispersion(t){this._dispersion>0!=t>0&&this.version++,this._dispersion=t}get sheen(){return this._sheen}set sheen(t){this._sheen>0!=t>0&&this.version++,this._sheen=t}get transmission(){return this._transmission}set transmission(t){this._transmission>0!=t>0&&this.version++,this._transmission=t}copy(t){return super.copy(t),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=t.anisotropy,this.anisotropyRotation=t.anisotropyRotation,this.anisotropyMap=t.anisotropyMap,this.clearcoat=t.clearcoat,this.clearcoatMap=t.clearcoatMap,this.clearcoatRoughness=t.clearcoatRoughness,this.clearcoatRoughnessMap=t.clearcoatRoughnessMap,this.clearcoatNormalMap=t.clearcoatNormalMap,this.clearcoatNormalScale.copy(t.clearcoatNormalScale),this.dispersion=t.dispersion,this.ior=t.ior,this.iridescence=t.iridescence,this.iridescenceMap=t.iridescenceMap,this.iridescenceIOR=t.iridescenceIOR,this.iridescenceThicknessRange=[...t.iridescenceThicknessRange],this.iridescenceThicknessMap=t.iridescenceThicknessMap,this.sheen=t.sheen,this.sheenColor.copy(t.sheenColor),this.sheenColorMap=t.sheenColorMap,this.sheenRoughness=t.sheenRoughness,this.sheenRoughnessMap=t.sheenRoughnessMap,this.transmission=t.transmission,this.transmissionMap=t.transmissionMap,this.thickness=t.thickness,this.thicknessMap=t.thicknessMap,this.attenuationDistance=t.attenuationDistance,this.attenuationColor.copy(t.attenuationColor),this.specularIntensity=t.specularIntensity,this.specularIntensityMap=t.specularIntensityMap,this.specularColor.copy(t.specularColor),this.specularColorMap=t.specularColorMap,this}}class a_ extends Ke{static get type(){return"MeshPhongMaterial"}constructor(t){super(),this.isMeshPhongMaterial=!0,this.color=new Et(16777215),this.specular=new Et(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Et(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Ki,this.normalScale=new Pt(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new je,this.combine=Ba,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.specular.copy(t.specular),this.shininess=t.shininess,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class o_ extends Ke{static get type(){return"MeshNormalMaterial"}constructor(t){super(),this.isMeshNormalMaterial=!0,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Ki,this.normalScale=new Pt(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.flatShading=t.flatShading,this}}class c_ extends Ke{static get type(){return"MeshMatcapMaterial"}constructor(t){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.color=new Et(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Ki,this.normalScale=new Pt(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.defines={MATCAP:""},this.color.copy(t.color),this.matcap=t.matcap,this.map=t.map,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.flatShading=t.flatShading,this.fog=t.fog,this}}function Ls(s,t,e){return!s||!e&&s.constructor===t?s:typeof t.BYTES_PER_ELEMENT=="number"?new t(s):Array.prototype.slice.call(s)}function ag(s){return ArrayBuffer.isView(s)&&!(s instanceof DataView)}function og(s){function t(i,r){return s[i]-s[r]}const e=s.length,n=new Array(e);for(let i=0;i!==e;++i)n[i]=i;return n.sort(t),n}function yc(s,t,e){const n=s.length,i=new s.constructor(n);for(let r=0,a=0;a!==n;++r){const o=e[r]*t;for(let c=0;c!==t;++c)i[a++]=s[o+c]}return i}function _l(s,t,e,n){let i=1,r=s[0];for(;r!==void 0&&r[n]===void 0;)r=s[i++];if(r===void 0)return;let a=r[n];if(a!==void 0)if(Array.isArray(a))do a=r[n],a!==void 0&&(t.push(r.time),e.push.apply(e,a)),r=s[i++];while(r!==void 0);else if(a.toArray!==void 0)do a=r[n],a!==void 0&&(t.push(r.time),a.toArray(e,e.length)),r=s[i++];while(r!==void 0);else do a=r[n],a!==void 0&&(t.push(r.time),e.push(a)),r=s[i++];while(r!==void 0)}class sr{constructor(t,e,n,i){this.parameterPositions=t,this._cachedIndex=0,this.resultBuffer=i!==void 0?i:new e.constructor(n),this.sampleValues=e,this.valueSize=n,this.settings=null,this.DefaultSettings_={}}evaluate(t){const e=this.parameterPositions;let n=this._cachedIndex,i=e[n],r=e[n-1];t:{e:{let a;n:{i:if(!(t=r)){const o=e[1];t=r)break e}a=n,n=0;break n}break t}for(;n>>1;te;)--a;if(++a,r!==0||a!==i){r>=a&&(a=Math.max(a,1),r=a-1);const o=this.getValueSize();this.times=n.slice(r,a),this.values=this.values.slice(r*o,a*o)}return this}validate(){let t=!0;const e=this.getValueSize();e-Math.floor(e)!==0&&(console.error("THREE.KeyframeTrack: Invalid value size in track.",this),t=!1);const n=this.times,i=this.values,r=n.length;r===0&&(console.error("THREE.KeyframeTrack: Track is empty.",this),t=!1);let a=null;for(let o=0;o!==r;o++){const c=n[o];if(typeof c=="number"&&isNaN(c)){console.error("THREE.KeyframeTrack: Time is not a valid number.",this,o,c),t=!1;break}if(a!==null&&a>c){console.error("THREE.KeyframeTrack: Out of order keys.",this,o,c,a),t=!1;break}a=c}if(i!==void 0&&ag(i))for(let o=0,c=i.length;o!==c;++o){const l=i[o];if(isNaN(l)){console.error("THREE.KeyframeTrack: Value is not a valid number.",this,o,l),t=!1;break}}return t}optimize(){const t=this.times.slice(),e=this.values.slice(),n=this.getValueSize(),i=this.getInterpolation()===cr,r=t.length-1;let a=1;for(let o=1;o0){t[a]=t[r];for(let o=r*n,c=a*n,l=0;l!==n;++l)e[c+l]=e[o+l];++a}return a!==t.length?(this.times=t.slice(0,a),this.values=e.slice(0,a*n)):(this.times=t,this.values=e),this}clone(){const t=this.times.slice(),e=this.values.slice(),n=this.constructor,i=new n(this.name,t,e);return i.createInterpolant=this.createInterpolant,i}}Je.prototype.TimeBufferType=Float32Array;Je.prototype.ValueBufferType=Float32Array;Je.prototype.DefaultInterpolation=Pa;class wi extends Je{constructor(t,e,n){super(t,e,n)}}wi.prototype.ValueTypeName="bool";wi.prototype.ValueBufferType=Array;wi.prototype.DefaultInterpolation=Hs;wi.prototype.InterpolantFactoryMethodLinear=void 0;wi.prototype.InterpolantFactoryMethodSmooth=void 0;class vl extends Je{}vl.prototype.ValueTypeName="color";class Ys extends Je{}Ys.prototype.ValueTypeName="number";class hg extends sr{constructor(t,e,n,i){super(t,e,n,i)}interpolate_(t,e,n,i){const r=this.resultBuffer,a=this.sampleValues,o=this.valueSize,c=(n-e)/(i-e);let l=t*o;for(let h=l+o;l!==h;l+=4)mn.slerpFlat(r,0,a,l-o,a,l,c);return r}}class rr extends Je{InterpolantFactoryMethodLinear(t){return new hg(this.times,this.values,this.getValueSize(),t)}}rr.prototype.ValueTypeName="quaternion";rr.prototype.InterpolantFactoryMethodSmooth=void 0;class Ri extends Je{constructor(t,e,n){super(t,e,n)}}Ri.prototype.ValueTypeName="string";Ri.prototype.ValueBufferType=Array;Ri.prototype.DefaultInterpolation=Hs;Ri.prototype.InterpolantFactoryMethodLinear=void 0;Ri.prototype.InterpolantFactoryMethodSmooth=void 0;class js extends Je{}js.prototype.ValueTypeName="vector";class Sc{constructor(t="",e=-1,n=[],i=Wa){this.name=t,this.tracks=n,this.duration=e,this.blendMode=i,this.uuid=Ye(),this.duration<0&&this.resetDuration()}static parse(t){const e=[],n=t.tracks,i=1/(t.fps||1);for(let a=0,o=n.length;a!==o;++a)e.push(dg(n[a]).scale(i));const r=new this(t.name,t.duration,e,t.blendMode);return r.uuid=t.uuid,r}static toJSON(t){const e=[],n=t.tracks,i={name:t.name,duration:t.duration,tracks:e,uuid:t.uuid,blendMode:t.blendMode};for(let r=0,a=n.length;r!==a;++r)e.push(Je.toJSON(n[r]));return i}static CreateFromMorphTargetSequence(t,e,n,i){const r=e.length,a=[];for(let o=0;o1){const u=h[1];let d=i[u];d||(i[u]=d=[]),d.push(l)}}const a=[];for(const o in i)a.push(this.CreateFromMorphTargetSequence(o,i[o],e,n));return a}static parseAnimation(t,e){if(!t)return console.error("THREE.AnimationClip: No animation in JSONLoader data."),null;const n=function(u,d,p,g,_){if(p.length!==0){const m=[],f=[];_l(p,m,f,g),m.length!==0&&_.push(new u(d,m,f))}},i=[],r=t.name||"default",a=t.fps||30,o=t.blendMode;let c=t.length||-1;const l=t.hierarchy||[];for(let u=0;u{e&&e(r),this.manager.itemEnd(t)},0),r;if(on[t]!==void 0){on[t].push({onLoad:e,onProgress:n,onError:i});return}on[t]=[],on[t].push({onLoad:e,onProgress:n,onError:i});const a=new Request(t,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),o=this.mimeType,c=this.responseType;fetch(a).then(l=>{if(l.status===200||l.status===0){if(l.status===0&&console.warn("THREE.FileLoader: HTTP Status 0 received."),typeof ReadableStream>"u"||l.body===void 0||l.body.getReader===void 0)return l;const h=on[t],u=l.body.getReader(),d=l.headers.get("X-File-Size")||l.headers.get("Content-Length"),p=d?parseInt(d):0,g=p!==0;let _=0;const m=new ReadableStream({start(f){b();function b(){u.read().then(({done:E,value:x})=>{if(E)f.close();else{_+=x.byteLength;const P=new ProgressEvent("progress",{lengthComputable:g,loaded:_,total:p});for(let A=0,w=h.length;A{f.error(E)})}}});return new Response(m)}else throw new mg(`fetch for "${l.url}" responded with ${l.status}: ${l.statusText}`,l)}).then(l=>{switch(c){case"arraybuffer":return l.arrayBuffer();case"blob":return l.blob();case"document":return l.text().then(h=>new DOMParser().parseFromString(h,o));case"json":return l.json();default:if(o===void 0)return l.text();{const u=/charset="?([^;"\s]*)"?/i.exec(o),d=u&&u[1]?u[1].toLowerCase():void 0,p=new TextDecoder(d);return l.arrayBuffer().then(g=>p.decode(g))}}}).then(l=>{Rn.add(t,l);const h=on[t];delete on[t];for(let u=0,d=h.length;u{const h=on[t];if(h===void 0)throw this.manager.itemError(t),l;delete on[t];for(let u=0,d=h.length;u{this.manager.itemEnd(t)}),this.manager.itemStart(t)}setResponseType(t){return this.responseType=t,this}setMimeType(t){return this.mimeType=t,this}}class _g extends Ci{constructor(t){super(t)}load(t,e,n,i){this.path!==void 0&&(t=this.path+t),t=this.manager.resolveURL(t);const r=this,a=Rn.get(t);if(a!==void 0)return r.manager.itemStart(t),setTimeout(function(){e&&e(a),r.manager.itemEnd(t)},0),a;const o=qi("img");function c(){h(),Rn.add(t,this),e&&e(this),r.manager.itemEnd(t)}function l(u){h(),i&&i(u),r.manager.itemError(t),r.manager.itemEnd(t)}function h(){o.removeEventListener("load",c,!1),o.removeEventListener("error",l,!1)}return o.addEventListener("load",c,!1),o.addEventListener("error",l,!1),t.slice(0,5)!=="data:"&&this.crossOrigin!==void 0&&(o.crossOrigin=this.crossOrigin),r.manager.itemStart(t),o.src=t,o}}class l_ extends Ci{constructor(t){super(t)}load(t,e,n,i){const r=this,a=new _i,o=new gg(this.manager);return o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setPath(this.path),o.setWithCredentials(r.withCredentials),o.load(t,function(c){let l;try{l=r.parse(c)}catch(h){if(i!==void 0)i(h);else{console.error(h);return}}l.image!==void 0?a.image=l.image:l.data!==void 0&&(a.image.width=l.width,a.image.height=l.height,a.image.data=l.data),a.wrapS=l.wrapS!==void 0?l.wrapS:dn,a.wrapT=l.wrapT!==void 0?l.wrapT:dn,a.magFilter=l.magFilter!==void 0?l.magFilter:Le,a.minFilter=l.minFilter!==void 0?l.minFilter:Le,a.anisotropy=l.anisotropy!==void 0?l.anisotropy:1,l.colorSpace!==void 0&&(a.colorSpace=l.colorSpace),l.flipY!==void 0&&(a.flipY=l.flipY),l.format!==void 0&&(a.format=l.format),l.type!==void 0&&(a.type=l.type),l.mipmaps!==void 0&&(a.mipmaps=l.mipmaps,a.minFilter=wn),l.mipmapCount===1&&(a.minFilter=Le),l.generateMipmaps!==void 0&&(a.generateMipmaps=l.generateMipmaps),a.needsUpdate=!0,e&&e(a,l)},n,i),a}}class h_ extends Ci{constructor(t){super(t)}load(t,e,n,i){const r=new ve,a=new _g(this.manager);return a.setCrossOrigin(this.crossOrigin),a.setPath(this.path),a.load(t,function(o){r.image=o,r.needsUpdate=!0,e!==void 0&&e(r)},n,i),r}}class Qi extends ae{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new Et(t),this.intensity=e}dispose(){}copy(t,e){return super.copy(t,e),this.color.copy(t.color),this.intensity=t.intensity,this}toJSON(t){const e=super.toJSON(t);return e.object.color=this.color.getHex(),e.object.intensity=this.intensity,this.groundColor!==void 0&&(e.object.groundColor=this.groundColor.getHex()),this.distance!==void 0&&(e.object.distance=this.distance),this.angle!==void 0&&(e.object.angle=this.angle),this.decay!==void 0&&(e.object.decay=this.decay),this.penumbra!==void 0&&(e.object.penumbra=this.penumbra),this.shadow!==void 0&&(e.object.shadow=this.shadow.toJSON()),this.target!==void 0&&(e.object.target=this.target.uuid),e}}class u_ extends Qi{constructor(t,e,n){super(t,n),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(ae.DEFAULT_UP),this.updateMatrix(),this.groundColor=new Et(e)}copy(t,e){return super.copy(t,e),this.groundColor.copy(t.groundColor),this}}const Hr=new Lt,Ec=new R,bc=new R;class ja{constructor(t){this.camera=t,this.intensity=1,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new Pt(512,512),this.map=null,this.mapPass=null,this.matrix=new Lt,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new Qs,this._frameExtents=new Pt(1,1),this._viewportCount=1,this._viewports=[new Xt(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,n=this.matrix;Ec.setFromMatrixPosition(t.matrixWorld),e.position.copy(Ec),bc.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(bc),e.updateMatrixWorld(),Hr.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Hr),n.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),n.multiply(Hr)}getViewport(t){return this._viewports[t]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(t){return this.camera=t.camera.clone(),this.intensity=t.intensity,this.bias=t.bias,this.radius=t.radius,this.mapSize.copy(t.mapSize),this}clone(){return new this.constructor().copy(this)}toJSON(){const t={};return this.intensity!==1&&(t.intensity=this.intensity),this.bias!==0&&(t.bias=this.bias),this.normalBias!==0&&(t.normalBias=this.normalBias),this.radius!==1&&(t.radius=this.radius),(this.mapSize.x!==512||this.mapSize.y!==512)&&(t.mapSize=this.mapSize.toArray()),t.camera=this.camera.toJSON(!1).object,delete t.camera.matrix,t}}class xg extends ja{constructor(){super(new Pe(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1}updateMatrices(t){const e=this.camera,n=Ei*2*t.angle*this.focus,i=this.mapSize.width/this.mapSize.height,r=t.distance||e.far;(n!==e.fov||i!==e.aspect||r!==e.far)&&(e.fov=n,e.aspect=i,e.far=r,e.updateProjectionMatrix()),super.updateMatrices(t)}copy(t){return super.copy(t),this.focus=t.focus,this}}class d_ extends Qi{constructor(t,e,n=0,i=Math.PI/3,r=0,a=2){super(t,e),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(ae.DEFAULT_UP),this.updateMatrix(),this.target=new ae,this.distance=n,this.angle=i,this.penumbra=r,this.decay=a,this.map=null,this.shadow=new xg}get power(){return this.intensity*Math.PI}set power(t){this.intensity=t/Math.PI}dispose(){this.shadow.dispose()}copy(t,e){return super.copy(t,e),this.distance=t.distance,this.angle=t.angle,this.penumbra=t.penumbra,this.decay=t.decay,this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}const Tc=new Lt,Vi=new R,Gr=new R;class vg extends ja{constructor(){super(new Pe(90,1,.5,500)),this.isPointLightShadow=!0,this._frameExtents=new Pt(4,2),this._viewportCount=6,this._viewports=[new Xt(2,1,1,1),new Xt(0,1,1,1),new Xt(3,1,1,1),new Xt(1,1,1,1),new Xt(3,0,1,1),new Xt(1,0,1,1)],this._cubeDirections=[new R(1,0,0),new R(-1,0,0),new R(0,0,1),new R(0,0,-1),new R(0,1,0),new R(0,-1,0)],this._cubeUps=[new R(0,1,0),new R(0,1,0),new R(0,1,0),new R(0,1,0),new R(0,0,1),new R(0,0,-1)]}updateMatrices(t,e=0){const n=this.camera,i=this.matrix,r=t.distance||n.far;r!==n.far&&(n.far=r,n.updateProjectionMatrix()),Vi.setFromMatrixPosition(t.matrixWorld),n.position.copy(Vi),Gr.copy(n.position),Gr.add(this._cubeDirections[e]),n.up.copy(this._cubeUps[e]),n.lookAt(Gr),n.updateMatrixWorld(),i.makeTranslation(-Vi.x,-Vi.y,-Vi.z),Tc.multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Tc)}}class f_ extends Qi{constructor(t,e,n=0,i=2){super(t,e),this.isPointLight=!0,this.type="PointLight",this.distance=n,this.decay=i,this.shadow=new vg}get power(){return this.intensity*4*Math.PI}set power(t){this.intensity=t/(4*Math.PI)}dispose(){this.shadow.dispose()}copy(t,e){return super.copy(t,e),this.distance=t.distance,this.decay=t.decay,this.shadow=t.shadow.clone(),this}}class Mg extends ja{constructor(){super(new tl(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class p_ extends Qi{constructor(t,e){super(t,e),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(ae.DEFAULT_UP),this.updateMatrix(),this.target=new ae,this.shadow=new Mg}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}class m_ extends Qi{constructor(t,e){super(t,e),this.isAmbientLight=!0,this.type="AmbientLight"}}class g_{static decodeText(t){if(console.warn("THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead."),typeof TextDecoder<"u")return new TextDecoder().decode(t);let e="";for(let n=0,i=t.length;n"u"&&console.warn("THREE.ImageBitmapLoader: createImageBitmap() not supported."),typeof fetch>"u"&&console.warn("THREE.ImageBitmapLoader: fetch() not supported."),this.options={premultiplyAlpha:"none"}}setOptions(t){return this.options=t,this}load(t,e,n,i){t===void 0&&(t=""),this.path!==void 0&&(t=this.path+t),t=this.manager.resolveURL(t);const r=this,a=Rn.get(t);if(a!==void 0){if(r.manager.itemStart(t),a.then){a.then(l=>{e&&e(l),r.manager.itemEnd(t)}).catch(l=>{i&&i(l)});return}return setTimeout(function(){e&&e(a),r.manager.itemEnd(t)},0),a}const o={};o.credentials=this.crossOrigin==="anonymous"?"same-origin":"include",o.headers=this.requestHeader;const c=fetch(t,o).then(function(l){return l.blob()}).then(function(l){return createImageBitmap(l,Object.assign(r.options,{colorSpaceConversion:"none"}))}).then(function(l){return Rn.add(t,l),e&&e(l),r.manager.itemEnd(t),l}).catch(function(l){i&&i(l),Rn.remove(t),r.manager.itemError(t),r.manager.itemEnd(t)});Rn.add(t,c),r.manager.itemStart(t)}}class x_{constructor(t=!0){this.autoStart=t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=Ac(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running)return this.start(),0;if(this.running){const e=Ac();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}}function Ac(){return performance.now()}class yg{constructor(t,e,n){this.binding=t,this.valueSize=n;let i,r,a;switch(e){case"quaternion":i=this._slerp,r=this._slerpAdditive,a=this._setAdditiveIdentityQuaternion,this.buffer=new Float64Array(n*6),this._workIndex=5;break;case"string":case"bool":i=this._select,r=this._select,a=this._setAdditiveIdentityOther,this.buffer=new Array(n*5);break;default:i=this._lerp,r=this._lerpAdditive,a=this._setAdditiveIdentityNumeric,this.buffer=new Float64Array(n*5)}this._mixBufferRegion=i,this._mixBufferRegionAdditive=r,this._setIdentity=a,this._origIndex=3,this._addIndex=4,this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,this.useCount=0,this.referenceCount=0}accumulate(t,e){const n=this.buffer,i=this.valueSize,r=t*i+i;let a=this.cumulativeWeight;if(a===0){for(let o=0;o!==i;++o)n[r+o]=n[o];a=e}else{a+=e;const o=e/a;this._mixBufferRegion(n,r,0,o,i)}this.cumulativeWeight=a}accumulateAdditive(t){const e=this.buffer,n=this.valueSize,i=n*this._addIndex;this.cumulativeWeightAdditive===0&&this._setIdentity(),this._mixBufferRegionAdditive(e,i,0,t,n),this.cumulativeWeightAdditive+=t}apply(t){const e=this.valueSize,n=this.buffer,i=t*e+e,r=this.cumulativeWeight,a=this.cumulativeWeightAdditive,o=this.binding;if(this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,r<1){const c=e*this._origIndex;this._mixBufferRegion(n,i,c,1-r,e)}a>0&&this._mixBufferRegionAdditive(n,i,this._addIndex*e,1,e);for(let c=e,l=e+e;c!==l;++c)if(n[c]!==n[c+e]){o.setValue(n,i);break}}saveOriginalState(){const t=this.binding,e=this.buffer,n=this.valueSize,i=n*this._origIndex;t.getValue(e,i);for(let r=n,a=i;r!==a;++r)e[r]=e[i+r%n];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const t=this.valueSize*3;this.binding.setValue(this.buffer,t)}_setAdditiveIdentityNumeric(){const t=this._addIndex*this.valueSize,e=t+this.valueSize;for(let n=t;n=.5)for(let a=0;a!==r;++a)t[e+a]=t[n+a]}_slerp(t,e,n,i){mn.slerpFlat(t,e,t,e,t,n,i)}_slerpAdditive(t,e,n,i,r){const a=this._workIndex*r;mn.multiplyQuaternionsFlat(t,a,t,e,t,n),mn.slerpFlat(t,e,t,e,t,a,i)}_lerp(t,e,n,i,r){const a=1-i;for(let o=0;o!==r;++o){const c=e+o;t[c]=t[c]*a+t[n+o]*i}}_lerpAdditive(t,e,n,i,r){for(let a=0;a!==r;++a){const o=e+a;t[o]=t[o]+t[n+a]*i}}}const Ka="\\[\\]\\.:\\/",Sg=new RegExp("["+Ka+"]","g"),Za="[^"+Ka+"]",Eg="[^"+Ka.replace("\\.","")+"]",bg=/((?:WC+[\/:])*)/.source.replace("WC",Za),Tg=/(WCOD+)?/.source.replace("WCOD",Eg),Ag=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",Za),wg=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",Za),Rg=new RegExp("^"+bg+Tg+Ag+wg+"$"),Cg=["material","materials","bones","map"];class Ig{constructor(t,e,n){const i=n||Zt.parseTrackName(e);this._targetGroup=t,this._bindings=t.subscribe_(e,i)}getValue(t,e){this.bind();const n=this._targetGroup.nCachedObjects_,i=this._bindings[n];i!==void 0&&i.getValue(t,e)}setValue(t,e){const n=this._bindings;for(let i=this._targetGroup.nCachedObjects_,r=n.length;i!==r;++i)n[i].setValue(t,e)}bind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,n=t.length;e!==n;++e)t[e].bind()}unbind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,n=t.length;e!==n;++e)t[e].unbind()}}class Zt{constructor(t,e,n){this.path=e,this.parsedPath=n||Zt.parseTrackName(e),this.node=Zt.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,n){return t&&t.isAnimationObjectGroup?new Zt.Composite(t,e,n):new Zt(t,e,n)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(Sg,"")}static parseTrackName(t){const e=Rg.exec(t);if(e===null)throw new Error("PropertyBinding: Cannot parse trackName: "+t);const n={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},i=n.nodeName&&n.nodeName.lastIndexOf(".");if(i!==void 0&&i!==-1){const r=n.nodeName.substring(i+1);Cg.indexOf(r)!==-1&&(n.nodeName=n.nodeName.substring(0,i),n.objectName=r)}if(n.propertyName===null||n.propertyName.length===0)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+t);return n}static findNode(t,e){if(e===void 0||e===""||e==="."||e===-1||e===t.name||e===t.uuid)return t;if(t.skeleton){const n=t.skeleton.getBoneByName(e);if(n!==void 0)return n}if(t.children){const n=function(r){for(let a=0;a0){const c=this._interpolants,l=this._propertyBindings;switch(this.blendMode){case ah:for(let h=0,u=c.length;h!==u;++h)c[h].evaluate(a),l[h].accumulateAdditive(o);break;case Wa:default:for(let h=0,u=c.length;h!==u;++h)c[h].evaluate(a),l[h].accumulate(i,o)}}}_updateWeight(t){let e=0;if(this.enabled){e=this.weight;const n=this._weightInterpolant;if(n!==null){const i=n.evaluate(t)[0];e*=i,t>n.parameterPositions[1]&&(this.stopFading(),i===0&&(this.enabled=!1))}}return this._effectiveWeight=e,e}_updateTimeScale(t){let e=0;if(!this.paused){e=this.timeScale;const n=this._timeScaleInterpolant;if(n!==null){const i=n.evaluate(t)[0];e*=i,t>n.parameterPositions[1]&&(this.stopWarping(),e===0?this.paused=!0:this.timeScale=e)}}return this._effectiveTimeScale=e,e}_updateTime(t){const e=this._clip.duration,n=this.loop;let i=this.time+t,r=this._loopCount;const a=n===rh;if(t===0)return r===-1?i:a&&(r&1)===1?e-i:i;if(n===ih){r===-1&&(this._loopCount=0,this._setEndings(!0,!0,!1));t:{if(i>=e)i=e;else if(i<0)i=0;else{this.time=i;break t}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t<0?-1:1})}}else{if(r===-1&&(t>=0?(r=0,this._setEndings(!0,this.repetitions===0,a)):this._setEndings(this.repetitions===0,!0,a)),i>=e||i<0){const o=Math.floor(i/e);i-=e*o,r+=Math.abs(o);const c=this.repetitions-r;if(c<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,i=t>0?e:0,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t>0?1:-1});else{if(c===1){const l=t<0;this._setEndings(l,!l,a)}else this._setEndings(!1,!1,a);this._loopCount=r,this.time=i,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:o})}}else this.time=i;if(a&&(r&1)===1)return e-i}return i}_setEndings(t,e,n){const i=this._interpolantSettings;n?(i.endingStart=di,i.endingEnd=di):(t?i.endingStart=this.zeroSlopeAtStart?di:ui:i.endingStart=Gs,e?i.endingEnd=this.zeroSlopeAtEnd?di:ui:i.endingEnd=Gs)}_scheduleFading(t,e,n){const i=this._mixer,r=i.time;let a=this._weightInterpolant;a===null&&(a=i._lendControlInterpolant(),this._weightInterpolant=a);const o=a.parameterPositions,c=a.sampleValues;return o[0]=r,c[0]=e,o[1]=r+t,c[1]=n,this}}const Lg=new Float32Array(1);class v_ extends Nn{constructor(t){super(),this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}_bindAction(t,e){const n=t._localRoot||this._root,i=t._clip.tracks,r=i.length,a=t._propertyBindings,o=t._interpolants,c=n.uuid,l=this._bindingsByRootAndName;let h=l[c];h===void 0&&(h={},l[c]=h);for(let u=0;u!==r;++u){const d=i[u],p=d.name;let g=h[p];if(g!==void 0)++g.referenceCount,a[u]=g;else{if(g=a[u],g!==void 0){g._cacheIndex===null&&(++g.referenceCount,this._addInactiveBinding(g,c,p));continue}const _=e&&e._propertyBindings[u].binding.parsedPath;g=new yg(Zt.create(n,p,_),d.ValueTypeName,d.getValueSize()),++g.referenceCount,this._addInactiveBinding(g,c,p),a[u]=g}o[u].resultBuffer=g.buffer}}_activateAction(t){if(!this._isActiveAction(t)){if(t._cacheIndex===null){const n=(t._localRoot||this._root).uuid,i=t._clip.uuid,r=this._actionsByClip[i];this._bindAction(t,r&&r.knownActions[0]),this._addInactiveAction(t,i,n)}const e=t._propertyBindings;for(let n=0,i=e.length;n!==i;++n){const r=e[n];r.useCount++===0&&(this._lendBinding(r),r.saveOriginalState())}this._lendAction(t)}}_deactivateAction(t){if(this._isActiveAction(t)){const e=t._propertyBindings;for(let n=0,i=e.length;n!==i;++n){const r=e[n];--r.useCount===0&&(r.restoreOriginalState(),this._takeBackBinding(r))}this._takeBackAction(t)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;const t=this;this.stats={actions:{get total(){return t._actions.length},get inUse(){return t._nActiveActions}},bindings:{get total(){return t._bindings.length},get inUse(){return t._nActiveBindings}},controlInterpolants:{get total(){return t._controlInterpolants.length},get inUse(){return t._nActiveControlInterpolants}}}}_isActiveAction(t){const e=t._cacheIndex;return e!==null&&e=0;--n)t[n].stop();return this}update(t){t*=this.timeScale;const e=this._actions,n=this._nActiveActions,i=this.time+=t,r=Math.sign(t),a=this._accuIndex^=1;for(let l=0;l!==n;++l)e[l]._update(i,t,r,a);const o=this._bindings,c=this._nActiveBindings;for(let l=0;l!==c;++l)o[l].apply(a);return this}setTime(t){this.time=0;for(let e=0;ei?c:i}this.min=n,this.max=i}setFromPoints(t,e){let n=1/0,i=-1/0;for(let r=0,a=e.length;ri?c:i}this.min=n,this.max=i}isSeparated(t){return this.min>t.max||t.min>this.max}}Ks.prototype.setFromBox=function(){const s=new R;return function(e,n){const i=n.min,r=n.max;let a=1/0,o=-1/0;for(let c=0;c<=1;c++)for(let l=0;l<=1;l++)for(let h=0;h<=1;h++){s.x=i.x*c+r.x*(1-c),s.y=i.y*l+r.y*(1-l),s.z=i.z*h+r.z*(1-h);const u=e.dot(s);a=Math.min(u,a),o=Math.max(u,o)}this.min=a,this.max=o}}();const Dg=function(){const s=new R,t=new R,e=new R;return function(i,r,a){const o=i.start,c=s,l=r.start,h=t;e.subVectors(o,l),s.subVectors(i.end,i.start),t.subVectors(r.end,r.start);const u=e.dot(h),d=h.dot(c),p=h.dot(h),g=e.dot(c),m=c.dot(c)*p-d*d;let f,b;m!==0?f=(u*d-g*p)/m:f=0,b=(u+f*d)/p,a.x=f,a.y=b}}(),yl=function(){const s=new Pt,t=new R,e=new R;return function(i,r,a,o){Dg(i,r,s);let c=s.x,l=s.y;if(c>=0&&c<=1&&l>=0&&l<=1){i.at(c,a),r.at(l,o);return}else if(c>=0&&c<=1){l<0?r.at(0,o):r.at(1,o),i.closestPointToPoint(o,!0,a);return}else if(l>=0&&l<=1){c<0?i.at(0,a):i.at(1,a),r.closestPointToPoint(a,!0,o);return}else{let h;c<0?h=i.start:h=i.end;let u;l<0?u=r.start:u=r.end;const d=t,p=e;if(i.closestPointToPoint(u,!0,t),r.closestPointToPoint(h,!0,e),d.distanceToSquared(u)<=p.distanceToSquared(h)){a.copy(d),o.copy(u);return}else{a.copy(h),o.copy(p);return}}}}(),Ug=function(){const s=new R,t=new R,e=new ln,n=new jn;return function(r,a){const{radius:o,center:c}=r,{a:l,b:h,c:u}=a;if(n.start=l,n.end=h,n.closestPointToPoint(c,!0,s).distanceTo(c)<=o||(n.start=l,n.end=u,n.closestPointToPoint(c,!0,s).distanceTo(c)<=o)||(n.start=h,n.end=u,n.closestPointToPoint(c,!0,s).distanceTo(c)<=o))return!0;const _=a.getPlane(e);if(Math.abs(_.distanceToPoint(c))<=o){const f=_.projectPoint(c,t);if(a.containsPoint(f))return!0}return!1}}(),Ng=1e-15;function Xr(s){return Math.abs(s)new R),this.satBounds=new Array(4).fill().map(()=>new Ks),this.points=[this.a,this.b,this.c],this.sphere=new we,this.plane=new ln,this.needsUpdate=!0}intersectsSphere(t){return Ug(t,this)}update(){const t=this.a,e=this.b,n=this.c,i=this.points,r=this.satAxes,a=this.satBounds,o=r[0],c=a[0];this.getNormal(o),c.setFromPoints(o,i);const l=r[1],h=a[1];l.subVectors(t,e),h.setFromPoints(l,i);const u=r[2],d=a[2];u.subVectors(e,n),d.setFromPoints(u,i);const p=r[3],g=a[3];p.subVectors(n,t),g.setFromPoints(p,i),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,t),this.needsUpdate=!1}}Yi.prototype.closestPointToSegment=function(){const s=new R,t=new R,e=new jn;return function(i,r=null,a=null){const{start:o,end:c}=i,l=this.points;let h,u=1/0;for(let d=0;d<3;d++){const p=(d+1)%3;e.start.copy(l[d]),e.end.copy(l[p]),yl(e,i,s,t),h=s.distanceToSquared(t),h=2){(x===1?f.start:f.end).copy(p),E=2;break}if(E++,E===2&&x===-1)break}}return E}return function(m,f=null,b=!1){this.needsUpdate&&this.update(),m.isExtendedTriangle?m.needsUpdate&&m.update():(s.copy(m),s.update(),m=s);const E=this.plane,x=m.plane;if(Math.abs(E.normal.dot(x.normal))>1-1e-10){const P=this.satBounds,A=this.satAxes;e[0]=m.a,e[1]=m.b,e[2]=m.c;for(let y=0;y<4;y++){const v=P[y],I=A[y];if(n.setFromPoints(I,e),v.isSeparated(n))return!1}const w=m.satBounds,C=m.satAxes;t[0]=this.a,t[1]=this.b,t[2]=this.c;for(let y=0;y<4;y++){const v=w[y],I=C[y];if(n.setFromPoints(I,t),v.isSeparated(n))return!1}for(let y=0;y<4;y++){const v=A[y];for(let I=0;I<4;I++){const V=C[I];if(r.crossVectors(v,V),n.setFromPoints(r,t),i.setFromPoints(r,e),n.isSeparated(i))return!1}}return f&&(b||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),f.start.set(0,0,0),f.end.set(0,0,0)),!0}else{const P=g(this,x,u);if(P===1&&m.containsPoint(u.end))return f&&(f.start.copy(u.end),f.end.copy(u.end)),!0;if(P!==2)return!1;const A=g(m,E,d);if(A===1&&this.containsPoint(d.end))return f&&(f.start.copy(d.end),f.end.copy(d.end)),!0;if(A!==2)return!1;if(u.delta(o),d.delta(c),o.dot(c)<0){let B=d.start;d.start=d.end,d.end=B}const w=u.start.dot(o),C=u.end.dot(o),y=d.start.dot(o),v=d.end.dot(o),I=C0?f.start.copy(u.start):f.start.copy(d.start),l.subVectors(u.end,d.end),l.dot(o)<0?f.end.copy(u.end):f.end.copy(d.end)),!0)}}}();Yi.prototype.distanceToPoint=function(){const s=new R;return function(e){return this.closestPointToPoint(e,s),e.distanceTo(s)}}();Yi.prototype.distanceToTriangle=function(){const s=new R,t=new R,e=["a","b","c"],n=new jn,i=new jn;return function(a,o=null,c=null){const l=o||c?n:null;if(this.intersectsTriangle(a,l))return(o||c)&&(o&&l.getCenter(o),c&&l.getCenter(c)),0;let h=1/0;for(let u=0;u<3;u++){let d;const p=e[u],g=a[p];this.closestPointToPoint(g,s),d=g.distanceToSquared(s),d=166,g=new A,w=new M,T=new V,F=B.prototype.raycast,v=S.prototype.raycast,R=new M,s=new B,m=[],b={};function C(e,t){this.isBatchedMesh?j.call(this,e,t):E.call(this,e,t)}function j(e,t){if(this.boundsTrees){const n=this.boundsTrees,i=this._drawInfo,r=this._drawRanges,o=this.matrixWorld;s.material=this.material,s.geometry=this.geometry;const l=s.geometry.boundsTree,h=s.geometry.drawRange;s.geometry.boundingSphere===null&&(s.geometry.boundingSphere=new _);for(let a=0,d=i.length;a=2.0 are supported."));return}const c=new kn(s,{path:e||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let l=0;l=0&&a[u]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+u+'".')}}c.setExtensions(i),c.setPlugins(a),c.parse(r,t)}parseAsync(n,e){const r=this;return new Promise(function(t,s){r.parse(n,e,t,s)})}}function sn(){let h={};return{get:function(n){return h[n]},add:function(n,e){h[n]=e},remove:function(n){delete h[n]},removeAll:function(){h={}}}}const A={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class rn{constructor(n){this.parser=n,this.name=A.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const n=this.parser,e=this.parser.json.nodes||[];for(let r=0,t=e.length;r=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return e.loadTextureImage(n,s.source,i)}}class Rn{constructor(n){this.parser=n,this.name=A.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(n){const e=this.name,r=this.parser,t=r.json,s=t.textures[n];if(!s.extensions||!s.extensions[e])return null;const i=s.extensions[e],a=t.images[i.source];let o=r.textureLoader;if(a.uri){const c=r.options.manager.getHandler(a.uri);c!==null&&(o=c)}return this.detectSupport().then(function(c){if(c)return r.loadTextureImage(n,i.source,o);if(t.extensionsRequired&&t.extensionsRequired.indexOf(e)>=0)throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return r.loadTexture(n)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(n){const e=new Image;e.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",e.onload=e.onerror=function(){n(e.height===1)}})),this.isSupported}}class xn{constructor(n){this.parser=n,this.name=A.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(n){const e=this.name,r=this.parser,t=r.json,s=t.textures[n];if(!s.extensions||!s.extensions[e])return null;const i=s.extensions[e],a=t.images[i.source];let o=r.textureLoader;if(a.uri){const c=r.options.manager.getHandler(a.uri);c!==null&&(o=c)}return this.detectSupport().then(function(c){if(c)return r.loadTextureImage(n,i.source,o);if(t.extensionsRequired&&t.extensionsRequired.indexOf(e)>=0)throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return r.loadTexture(n)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(n){const e=new Image;e.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",e.onload=e.onerror=function(){n(e.height===1)}})),this.isSupported}}class En{constructor(n){this.name=A.EXT_MESHOPT_COMPRESSION,this.parser=n}loadBufferView(n){const e=this.parser.json,r=e.bufferViews[n];if(r.extensions&&r.extensions[this.name]){const t=r.extensions[this.name],s=this.parser.getDependency("buffer",t.buffer),i=this.parser.options.meshoptDecoder;if(!i||!i.supported){if(e.extensionsRequired&&e.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return s.then(function(a){const o=t.byteOffset||0,c=t.byteLength||0,l=t.count,u=t.byteStride,f=new Uint8Array(a,o,c);return i.decodeGltfBufferAsync?i.decodeGltfBufferAsync(l,u,f,t.mode,t.filter).then(function(d){return d.buffer}):i.ready.then(function(){const d=new ArrayBuffer(l*u);return i.decodeGltfBuffer(new Uint8Array(d),l,u,f,t.mode,t.filter),d})})}else return null}}class _n{constructor(n){this.name=A.EXT_MESH_GPU_INSTANCING,this.parser=n}createNodeMesh(n){const e=this.parser.json,r=e.nodes[n];if(!r.extensions||!r.extensions[this.name]||r.mesh===void 0)return null;const t=e.meshes[r.mesh];for(const c of t.primitives)if(c.mode!==_.TRIANGLES&&c.mode!==_.TRIANGLE_STRIP&&c.mode!==_.TRIANGLE_FAN&&c.mode!==void 0)return null;const i=r.extensions[this.name].attributes,a=[],o={};for(const c in i)a.push(this.parser.getDependency("accessor",i[c]).then(l=>(o[c]=l,o[c])));return a.length<1?null:(a.push(this.parser.createNodeMesh(n)),Promise.all(a).then(c=>{const l=c.pop(),u=l.isGroup?l.children:[l],f=c[0].count,d=[];for(const m of u){const T=new v,p=new F,g=new me,x=new F(1,1,1),E=new _e(m.geometry,m.material,f);for(let R=0;R0||h.search(/^data\:image\/jpeg/)===0?"image/jpeg":h.search(/\.webp($|\?)/i)>0||h.search(/^data\:image\/webp/)===0?"image/webp":h.search(/\.ktx2($|\?)/i)>0||h.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}const Pn=new v;class kn{constructor(n={},e={}){this.json=n,this.extensions={},this.plugins={},this.options=e,this.cache=new sn,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let r=!1,t=-1,s=!1,i=-1;if(typeof navigator<"u"){const a=navigator.userAgent;r=/^((?!chrome|android).)*safari/i.test(a)===!0;const o=a.match(/Version\/(\d+)/);t=r&&o?parseInt(o[1],10):-1,s=a.indexOf("Firefox")>-1,i=s?a.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||r&&t<17||s&&i<98?this.textureLoader=new Se(this.options.manager):this.textureLoader=new Me(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new ce(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(n){this.extensions=n}setPlugins(n){this.plugins=n}parse(n,e){const r=this,t=this.json,s=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(i){return i._markDefs&&i._markDefs()}),Promise.all(this._invokeAll(function(i){return i.beforeRoot&&i.beforeRoot()})).then(function(){return Promise.all([r.getDependencies("scene"),r.getDependencies("animation"),r.getDependencies("camera")])}).then(function(i){const a={scene:i[0][t.scene||0],scenes:i[0],animations:i[1],cameras:i[2],asset:t.asset,parser:r,userData:{}};return O(s,a,t),b(a,t),Promise.all(r._invokeAll(function(o){return o.afterRoot&&o.afterRoot(a)})).then(function(){for(const o of a.scenes)o.updateMatrixWorld();n(a)})}).catch(e)}_markDefs(){const n=this.json.nodes||[],e=this.json.skins||[],r=this.json.meshes||[];for(let t=0,s=e.length;t{const o=this.associations.get(i);o!=null&&this.associations.set(a,o);for(const[c,l]of i.children.entries())s(l,a.children[c])};return s(r,t),t.name+="_instance_"+n.uses[e]++,t}_invokeOne(n){const e=Object.values(this.plugins);e.push(this);for(let r=0;r=2&&p.setY(N,w[L*o+1]),o>=3&&p.setZ(N,w[L*o+2]),o>=4&&p.setW(N,w[L*o+3]),o>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}p.normalized=m}return p})}loadTexture(n){const e=this.json,r=this.options,s=e.textures[n].source,i=e.images[s];let a=this.textureLoader;if(i.uri){const o=r.manager.getHandler(i.uri);o!==null&&(a=o)}return this.loadTextureImage(n,s,a)}loadTextureImage(n,e,r){const t=this,s=this.json,i=s.textures[n],a=s.images[e],o=(a.uri||a.bufferView)+":"+i.sampler;if(this.textureCache[o])return this.textureCache[o];const c=this.loadImageSource(e,r).then(function(l){l.flipY=!1,l.name=i.name||a.name||"",l.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(l.name=a.uri);const f=(s.samplers||{})[i.sampler]||{};return l.magFilter=ie[f.magFilter]||W,l.minFilter=ie[f.minFilter]||fe,l.wrapS=oe[f.wrapS]||Y,l.wrapT=oe[f.wrapT]||Y,l.generateMipmaps=!l.isCompressedTexture&&l.minFilter!==he&&l.minFilter!==W,t.associations.set(l,{textures:n}),l}).catch(function(){return null});return this.textureCache[o]=c,c}loadImageSource(n,e){const r=this,t=this.json,s=this.options;if(this.sourceCache[n]!==void 0)return this.sourceCache[n].then(u=>u.clone());const i=t.images[n],a=self.URL||self.webkitURL;let o=i.uri||"",c=!1;if(i.bufferView!==void 0)o=r.getDependency("bufferView",i.bufferView).then(function(u){c=!0;const f=new Blob([u],{type:i.mimeType});return o=a.createObjectURL(f),o});else if(i.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+n+" is missing URI and bufferView");const l=Promise.resolve(o).then(function(u){return new Promise(function(f,d){let m=f;e.isImageBitmapLoader===!0&&(m=function(T){const p=new $(T);p.needsUpdate=!0,f(p)}),e.load(G.resolveURL(u,s.path),m,void 0,d)})}).then(function(u){return c===!0&&a.revokeObjectURL(o),b(u,i),u.userData.mimeType=i.mimeType||Dn(i.uri),u}).catch(function(u){throw console.error("THREE.GLTFLoader: Couldn't load texture",o),u});return this.sourceCache[n]=l,l}assignTexture(n,e,r,t){const s=this;return this.getDependency("texture",r.index).then(function(i){if(!i)return null;if(r.texCoord!==void 0&&r.texCoord>0&&(i=i.clone(),i.channel=r.texCoord),s.extensions[A.KHR_TEXTURE_TRANSFORM]){const a=r.extensions!==void 0?r.extensions[A.KHR_TEXTURE_TRANSFORM]:void 0;if(a){const o=s.associations.get(i);i=s.extensions[A.KHR_TEXTURE_TRANSFORM].extendTexture(i,a),s.associations.set(i,o)}}return t!==void 0&&(i.colorSpace=t),n[e]=i,i})}assignFinalMaterial(n){const e=n.geometry;let r=n.material;const t=e.attributes.tangent===void 0,s=e.attributes.color!==void 0,i=e.attributes.normal===void 0;if(n.isPoints){const a="PointsMaterial:"+r.uuid;let o=this.cache.get(a);o||(o=new ye,K.prototype.copy.call(o,r),o.color.copy(r.color),o.map=r.map,o.sizeAttenuation=!1,this.cache.add(a,o)),r=o}else if(n.isLine){const a="LineBasicMaterial:"+r.uuid;let o=this.cache.get(a);o||(o=new we,K.prototype.copy.call(o,r),o.color.copy(r.color),o.map=r.map,this.cache.add(a,o)),r=o}if(t||s||i){let a="ClonedMaterial:"+r.uuid+":";t&&(a+="derivative-tangents:"),s&&(a+="vertex-colors:"),i&&(a+="flat-shading:");let o=this.cache.get(a);o||(o=r.clone(),s&&(o.vertexColors=!0),i&&(o.flatShading=!0),t&&(o.normalScale&&(o.normalScale.y*=-1),o.clearcoatNormalScale&&(o.clearcoatNormalScale.y*=-1)),this.cache.add(a,o),this.associations.set(o,this.associations.get(r))),r=o}n.material=r}getMaterialType(){return de}loadMaterial(n){const e=this,r=this.json,t=this.extensions,s=r.materials[n];let i;const a={},o=s.extensions||{},c=[];if(o[A.KHR_MATERIALS_UNLIT]){const u=t[A.KHR_MATERIALS_UNLIT];i=u.getMaterialType(),c.push(u.extendParams(a,s,e))}else{const u=s.pbrMetallicRoughness||{};if(a.color=new C(1,1,1),a.opacity=1,Array.isArray(u.baseColorFactor)){const f=u.baseColorFactor;a.color.setRGB(f[0],f[1],f[2],y),a.opacity=f[3]}u.baseColorTexture!==void 0&&c.push(e.assignTexture(a,"map",u.baseColorTexture,B)),a.metalness=u.metallicFactor!==void 0?u.metallicFactor:1,a.roughness=u.roughnessFactor!==void 0?u.roughnessFactor:1,u.metallicRoughnessTexture!==void 0&&(c.push(e.assignTexture(a,"metalnessMap",u.metallicRoughnessTexture)),c.push(e.assignTexture(a,"roughnessMap",u.metallicRoughnessTexture))),i=this._invokeOne(function(f){return f.getMaterialType&&f.getMaterialType(n)}),c.push(Promise.all(this._invokeAll(function(f){return f.extendMaterialParams&&f.extendMaterialParams(n,a)})))}s.doubleSided===!0&&(a.side=Ne);const l=s.alphaMode||z.OPAQUE;if(l===z.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,l===z.MASK&&(a.alphaTest=s.alphaCutoff!==void 0?s.alphaCutoff:.5)),s.normalTexture!==void 0&&i!==H&&(c.push(e.assignTexture(a,"normalMap",s.normalTexture)),a.normalScale=new ue(1,1),s.normalTexture.scale!==void 0)){const u=s.normalTexture.scale;a.normalScale.set(u,u)}if(s.occlusionTexture!==void 0&&i!==H&&(c.push(e.assignTexture(a,"aoMap",s.occlusionTexture)),s.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=s.occlusionTexture.strength)),s.emissiveFactor!==void 0&&i!==H){const u=s.emissiveFactor;a.emissive=new C().setRGB(u[0],u[1],u[2],y)}return s.emissiveTexture!==void 0&&i!==H&&c.push(e.assignTexture(a,"emissiveMap",s.emissiveTexture,B)),Promise.all(c).then(function(){const u=new i(a);return s.name&&(u.name=s.name),b(u,s),e.associations.set(u,{materials:n}),s.extensions&&O(t,u,s),u})}createUniqueName(n){const e=Ie.sanitizeNodeName(n||"");return e in this.nodeNamesUsed?e+"_"+ ++this.nodeNamesUsed[e]:(this.nodeNamesUsed[e]=0,e)}loadGeometries(n){const e=this,r=this.extensions,t=this.primitiveCache;function s(a){return r[A.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,e).then(function(o){return ae(o,a,e)})}const i=[];for(let a=0,o=n.length;a0&&Cn(g,s),g.name=e.createUniqueName(s.name||"mesh_"+n),b(g,s),p.extensions&&O(t,g,p),e.assignFinalMaterial(g),u.push(g)}for(let d=0,m=u.length;d1?l=new V:c.length===1?l=c[0]:l=new le,l!==c[0])for(let u=0,f=c.length;u{const u=new Map;for(const[f,d]of t.associations)(f instanceof K||f instanceof $)&&u.set(f,d);return l.traverse(f=>{const d=t.associations.get(f);d!=null&&u.set(f,d)}),u};return t.associations=c(s),s})}_createAnimationTracks(n,e,r,t,s){const i=[],a=n.name?n.name:n.uuid,o=[];I[s.path]===I.weights?n.traverse(function(f){f.morphTargetInfluences&&o.push(f.name?f.name:f.uuid)}):o.push(a);let c;switch(I[s.path]){case I.weights:c=ne;break;case I.rotation:c=te;break;case I.position:case I.scale:c=ee;break;default:switch(r.itemSize){case 1:c=ne;break;case 2:case 3:default:c=ee;break}break}const l=t.interpolation!==void 0?Nn[t.interpolation]:pe,u=this._getArrayFromAccessor(r);for(let f=0,d=o.length;f{throw e.message?new Error(`${this.name}: Could not create Web Worker with error "${e.message}"`):new Error(`${this.name}: Could not create Web Worker.`)}}runTask(){}generate(...r){if(this.running)throw new Error("GenerateMeshBVHWorker: Already running job.");if(this.worker===null)throw new Error("GenerateMeshBVHWorker: Worker has been disposed.");this.running=!0;const e=this.runTask(this.worker,...r);return e.finally(()=>{this.running=!1}),e}dispose(){this.worker.terminate(),this.worker=null}}class m extends k{constructor(){const r=new Worker(new URL(""+new URL("generateMeshBVH.worker-BQRNzfDQ.js",import.meta.url).href,import.meta.url),{type:"module"});super(r),this.name="GenerateMeshBVHWorker"}runTask(r,e,s={}){return new Promise((h,a)=>{if(e.getAttribute("position").isInterleavedBufferAttribute||e.index&&e.index.isInterleavedBufferAttribute)throw new Error("GenerateMeshBVHWorker: InterleavedBufferAttribute are not supported for the geometry attributes.");r.onerror=n=>{a(new Error(`GenerateMeshBVHWorker: ${n.message}`))},r.onmessage=n=>{const{data:o}=n;if(o.error)a(new Error(o.error)),r.onmessage=null;else if(o.serialized){const{serialized:t,position:B}=o,f=b.deserialize(t,e,{setIndex:!1}),w=Object.assign({setBoundingBox:!0},s);if(e.attributes.position.array=B,t.index)if(e.index)e.index.array=t.index;else{const c=new g(t.index,1,!1);e.setIndex(c)}w.setBoundingBox&&(e.boundingBox=f.getBoundingBox(new p)),s.onProgress&&s.onProgress(o.progress),h(f),r.onmessage=null}else s.onProgress&&s.onProgress(o.progress)};const i=e.index?e.index.array:null,u=e.attributes.position.array,l=[u];i&&l.push(i),r.postMessage({index:i,position:u,options:{...s,onProgress:null,includedProgressCallback:!!s.onProgress,groups:[...e.groups]}},l.map(n=>n.buffer).filter(n=>typeof SharedArrayBuffer>"u"||!(n instanceof SharedArrayBuffer)))})}}export{m as G,k as W}; diff --git a/example/bundle/assets/MeshBVH-ujCvfObx.js b/example/bundle/assets/MeshBVH-ujCvfObx.js new file mode 100644 index 000000000..09544ecb6 --- /dev/null +++ b/example/bundle/assets/MeshBVH-ujCvfObx.js @@ -0,0 +1 @@ +import{B as _n,V as z,n as nt,bn as Pt,aR as ft,o as un,bo as zn,b as j,U as xt,J as Mt,aQ as Rn,y as Dn,t as Fn,x as pn}from"./ExtendedTriangle-CNpFv597.js";const Pn=0,Nn=1,vn=2,vi=0,Vi=1,yn=2,Ht=1.25,xn=1,bt=6*4+4+4,qt=65535,Vn=Math.pow(2,-24),jt=Symbol("SKIP_GENERATION");function $n(i){return i.index?i.index.count:i.attributes.position.count}function ut(i){return $n(i)/3}function In(i,n=ArrayBuffer){return i>65535?new Uint32Array(new n(4*i)):new Uint16Array(new n(2*i))}function kn(i,n){if(!i.index){const t=i.attributes.position.count,e=n.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=In(t,e);i.setIndex(new _n(s,1));for(let c=0;co-u);for(let o=0;or.offset-l.offset),s=e[e.length-1];s.count=Math.min(t-s.offset,s.count);let c=0;return e.forEach(({count:r})=>c+=r),t!==c}function Yt(i,n,t,e,s){let c=1/0,r=1/0,l=1/0,o=-1/0,u=-1/0,f=-1/0,y=1/0,a=1/0,p=1/0,d=-1/0,b=-1/0,g=-1/0;for(let h=n*6,x=(n+t)*6;ho&&(o=T),md&&(d=m);const B=i[h+2],P=i[h+3],S=B-P,M=B+P;Su&&(u=M),Bb&&(b=B);const U=i[h+4],_=i[h+5],C=U-_,L=U+_;Cf&&(f=L),Ug&&(g=U)}e[0]=c,e[1]=r,e[2]=l,e[3]=o,e[4]=u,e[5]=f,s[0]=y,s[1]=a,s[2]=p,s[3]=d,s[4]=b,s[5]=g}function Xn(i,n=null,t=null,e=null){const s=i.attributes.position,c=i.index?i.index.array:null,r=ut(i),l=s.normalized;let o;n===null?(o=new Float32Array(r*6),t=0,e=r):(o=n,t=t||0,e=e||r);const u=s.array,f=s.offset||0;let y=3;s.isInterleavedBufferAttribute&&(y=s.data.stride);const a=["getX","getY","getZ"];for(let p=t;pP&&(P=A),T>P&&(P=T);const S=(P-B)/2,M=m*2;o[b+M+0]=B+S,o[b+M+1]=S+(Math.abs(B)+S)*Vn}}return o}function D(i,n,t){return t.min.x=n[i],t.min.y=n[i+1],t.min.z=n[i+2],t.max.x=n[i+3],t.max.y=n[i+4],t.max.z=n[i+5],t}function An(i){let n=-1,t=-1/0;for(let e=0;e<3;e++){const s=i[e+3]-i[e];s>t&&(t=s,n=e)}return n}function mn(i,n){n.set(i)}function hn(i,n,t){let e,s;for(let c=0;c<3;c++){const r=c+3;e=i[c],s=n[c],t[c]=es?e:s}}function St(i,n,t){for(let e=0;e<3;e++){const s=n[i+2*e],c=n[i+2*e+1],r=s-c,l=s+c;rt[e+3]&&(t[e+3]=l)}}function At(i){const n=i[3]-i[0],t=i[4]-i[1],e=i[5]-i[2];return 2*(n*t+t*e+e*n)}const Y=32,Hn=(i,n)=>i.candidate-n.candidate,K=new Array(Y).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ct=new Float32Array(6);function jn(i,n,t,e,s,c){let r=-1,l=0;if(c===Pn)r=An(n),r!==-1&&(l=(n[r]+n[r+3])/2);else if(c===Nn)r=An(i),r!==-1&&(l=Yn(t,e,s,r));else if(c===vn){const o=At(i);let u=Ht*s;const f=e*6,y=(e+s)*6;for(let a=0;a<3;a++){const p=n[a],g=(n[a+3]-p)/Y;if(s=B.candidate?St(w,t,B.rightCacheBounds):(St(w,t,B.leftCacheBounds),B.count++)}}for(let w=0;w=Y&&(T=Y-1);const B=K[T];B.count++,St(m,t,B.bounds)}const h=K[Y-1];mn(h.bounds,h.rightCacheBounds);for(let m=Y-2;m>=0;m--){const w=K[m],A=K[m+1];hn(w.bounds,A.rightCacheBounds,w.rightCacheBounds)}let x=0;for(let m=0;m=o;)l--;if(r=o;)l--;if(rJn)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return Tt[t+6]=u/4,u=nn(u,l),Tt[t+7]=o,u}}function Wn(i,n){const t=(i.index?i.index.count:i.attributes.position.count)/3,e=t>2**16,s=e?4:2,c=n?new SharedArrayBuffer(t*s):new ArrayBuffer(t*s),r=e?new Uint32Array(c):new Uint16Array(c);for(let l=0,o=r.length;l=c&&(h=!0,r&&(console.warn(`MeshBVH: Max depth of ${c} reached when generating BVH. Consider increasing maxDepth.`),console.warn(a))),B<=l||S>=c)return m(T+B),A.offset=T,A.count=B,A;const M=jn(A.boundingData,P,n,T,B,o);if(M.axis===-1)return m(T+B),A.offset=T,A.count=B,A;const U=d(y,p,n,T,B,M);if(U===T||U===T+B)m(T+B),A.offset=T,A.count=B;else{A.splitAxis=M.axis;const _=new Zt,C=T,L=U-T;A.left=_,Yt(n,C,L,_.boundingData,g),w(_,C,L,g,S+1);const E=new Zt,F=U,Z=B-L;A.right=E,Yt(n,F,Z,E.boundingData,g),w(E,F,Z,g,S+1)}return A}}function On(i,n){const t=i.geometry;n.indirect&&(i._indirectBuffer=Wn(t,n.useSharedArrayBuffer),qn(t,n.range)&&!n.verbose&&console.warn('MeshBVH: Provided geometry contains groups or a range that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),i._indirectBuffer||kn(t,n);const e=n.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=Xn(t),c=n.indirect?Mn(t,n.range):Sn(t,n.range);i._roots=c.map(r=>{const l=Gn(i,s,r.offset,r.count,n),o=tn(l),u=new e(bt*o);return Qn(0,l,u),u})}class v{constructor(n,t,e){this.isOrientedBox=!0,this.min=new z,this.max=new z,this.matrix=new nt,this.invMatrix=new nt,this.points=new Array(8).fill().map(()=>new z),this.satAxes=new Array(3).fill().map(()=>new z),this.satBounds=new Array(3).fill().map(()=>new Pt),this.alignedSatBounds=new Array(3).fill().map(()=>new Pt),this.needsUpdate=!1,n&&this.min.copy(n),t&&this.max.copy(t),e&&this.matrix.copy(e)}set(n,t,e){this.min.copy(n),this.max.copy(t),this.matrix.copy(e),this.needsUpdate=!0}copy(n){this.min.copy(n.min),this.max.copy(n.max),this.matrix.copy(n.matrix),this.needsUpdate=!0}}v.prototype.update=function(){return function(){const n=this.matrix,t=this.min,e=this.max,s=this.points;for(let u=0;u<=1;u++)for(let f=0;f<=1;f++)for(let y=0;y<=1;y++){const a=1*u|2*f|4*y,p=s[a];p.x=u?e.x:t.x,p.y=f?e.y:t.y,p.z=y?e.z:t.z,p.applyMatrix4(n)}const c=this.satBounds,r=this.satAxes,l=s[0];for(let u=0;u<3;u++){const f=r[u],y=c[u],a=1<new un),t=new Array(12).fill().map(()=>new un),e=new z,s=new z;return function(r,l=0,o=null,u=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(o||u)&&(r.getCenter(s),this.closestPointToPoint(s,e),r.closestPointToPoint(e,s),o&&o.copy(e),u&&u.copy(s)),0;const f=l*l,y=r.min,a=r.max,p=this.points;let d=1/0;for(let g=0;g<8;g++){const h=p[g];s.copy(h).clamp(y,a);const x=h.distanceToSquared(s);if(xnew ft)}}const X=new ti;class ni{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const n=[];let t=null;this.setBuffer=e=>{t&&n.push(t),t=e,this.float32Array=new Float32Array(e),this.uint16Array=new Uint16Array(e),this.uint32Array=new Uint32Array(e)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,n.length!==0&&this.setBuffer(n.pop())}}}const R=new ni;let Q,at;const it=[],Ut=new fn(()=>new j);function ii(i,n,t,e,s,c){Q=Ut.getPrimitive(),at=Ut.getPrimitive(),it.push(Q,at),R.setBuffer(i._roots[n]);const r=en(0,i.geometry,t,e,s,c);R.clearBuffer(),Ut.releasePrimitive(Q),Ut.releasePrimitive(at),it.pop(),it.pop();const l=it.length;return l>0&&(at=it[l-1],Q=it[l-2]),r}function en(i,n,t,e,s=null,c=0,r=0){const{float32Array:l,uint16Array:o,uint32Array:u}=R;let f=i*2;if(V(f,o)){const a=$(i,u),p=I(f,o);return D(i,l,Q),e(a,p,!1,r,c+i,Q)}else{let M=function(_){const{uint16Array:C,uint32Array:L}=R;let E=_*2;for(;!V(E,C);)_=k(_),E=_*2;return $(_,L)},U=function(_){const{uint16Array:C,uint32Array:L}=R;let E=_*2;for(;!V(E,C);)_=q(_,L),E=_*2;return $(_,L)+I(E,C)};const a=k(i),p=q(i,u);let d=a,b=p,g,h,x,m;if(s&&(x=Q,m=at,D(d,l,x),D(b,l,m),g=s(x),h=s(m),h(mt.copy(n).clamp(f.min,f.max),mt.distanceToSquared(n)),intersectsBounds:(f,y,a)=>a{f.closestPointToPoint(n,mt);const a=n.distanceToSquared(mt);return a=169,G=new z,O=new z,tt=new z,Lt=new Mt,Et=new Mt,zt=new Mt,gn=new z,wn=new z,Bn=new z,ht=new z;function ri(i,n,t,e,s,c,r,l){let o;if(c===Dn?o=i.intersectTriangle(e,t,n,!0,s):o=i.intersectTriangle(n,t,e,c!==Fn,s),o===null)return null;const u=i.origin.distanceTo(s);return ul?null:{distance:u,point:s.clone()}}function oi(i,n,t,e,s,c,r,l,o,u,f){G.fromBufferAttribute(n,c),O.fromBufferAttribute(n,r),tt.fromBufferAttribute(n,l);const y=ri(i,G,O,tt,ht,o,u,f);if(y){const a=new z;xt.getBarycoord(ht,G,O,tt,a),e&&(Lt.fromBufferAttribute(e,c),Et.fromBufferAttribute(e,r),zt.fromBufferAttribute(e,l),y.uv=xt.getInterpolation(ht,G,O,tt,Lt,Et,zt,new Mt)),s&&(Lt.fromBufferAttribute(s,c),Et.fromBufferAttribute(s,r),zt.fromBufferAttribute(s,l),y.uv1=xt.getInterpolation(ht,G,O,tt,Lt,Et,zt,new Mt)),t&&(gn.fromBufferAttribute(t,c),wn.fromBufferAttribute(t,r),Bn.fromBufferAttribute(t,l),y.normal=xt.getInterpolation(ht,G,O,tt,gn,wn,Bn,new z),y.normal.dot(i.direction)>0&&y.normal.multiplyScalar(-1));const p={a:c,b:r,c:l,normal:new z,materialIndex:0};xt.getNormal(G,O,tt,p.normal),y.face=p,y.faceIndex=c,si&&(y.barycoord=a)}return y}function Xt(i,n,t,e,s,c,r){const l=e*3;let o=l+0,u=l+1,f=l+2;const y=i.index;i.index&&(o=y.getX(o),u=y.getX(u),f=y.getX(f));const{position:a,normal:p,uv:d,uv1:b}=i.attributes,g=oi(t,a,p,d,b,o,u,f,n,c,r);return g?(g.faceIndex=e,s&&s.push(g),g):null}function N(i,n,t,e){const s=i.a,c=i.b,r=i.c;let l=n,o=n+1,u=n+2;t&&(l=t.getX(l),o=t.getX(o),u=t.getX(u)),s.x=e.getX(l),s.y=e.getY(l),s.z=e.getZ(l),c.x=e.getX(o),c.y=e.getY(o),c.z=e.getZ(o),r.x=e.getX(u),r.y=e.getY(u),r.z=e.getZ(u)}function ci(i,n,t,e,s,c,r,l){const{geometry:o,_indirectBuffer:u}=i;for(let f=e,y=e+s;fT&&(T=_),CB&&(B=C),LP&&(P=L)}return o[a+0]!==m||o[a+1]!==w||o[a+2]!==A||o[a+3]!==T||o[a+4]!==B||o[a+5]!==P?(o[a+0]=m,o[a+1]=w,o[a+2]=A,o[a+3]=T,o[a+4]=B,o[a+5]=P,!0):!1}else{const h=a+8,x=r[a+6],m=h+p,w=x+p;let A=d,T=!1,B=!1;n?A||(T=n.has(m),B=n.has(w),A=!T&&!B):(T=!0,B=!0);const P=A||T,S=A||B;let M=!1;P&&(M=y(h,p,A));let U=!1;S&&(U=y(x,p,A));const _=M||U;if(_)for(let C=0;C<3;C++){const L=h+C,E=x+C,F=o[L],Z=o[L+3],pt=o[E],yt=o[E+3];o[a+C]=Fyt?Z:yt}return _}}}function W(i,n,t,e,s){let c,r,l,o,u,f;const y=1/t.direction.x,a=1/t.direction.y,p=1/t.direction.z,d=t.origin.x,b=t.origin.y,g=t.origin.z;let h=n[i],x=n[i+3],m=n[i+1],w=n[i+3+1],A=n[i+2],T=n[i+3+2];return y>=0?(c=(h-d)*y,r=(x-d)*y):(c=(x-d)*y,r=(h-d)*y),a>=0?(l=(m-b)*a,o=(w-b)*a):(l=(w-b)*a,o=(m-b)*a),c>o||l>r||((l>c||isNaN(c))&&(c=l),(o=0?(u=(A-g)*p,f=(T-g)*p):(u=(T-g)*p,f=(A-g)*p),c>f||u>r)?!1:((u>c||c!==c)&&(c=u),(f=e)}function ui(i,n,t,e,s,c,r,l){const{geometry:o,_indirectBuffer:u}=i;for(let f=e,y=e+s;f=0;let b,g;d?(b=k(i),g=q(i,o)):(b=q(i,o),g=k(i));const x=W(b,r,e,s,c)?rn(b,n,t,e,s,c):null;if(x){const A=x.point[a];if(d?A<=r[g+y]:A>=r[g+y+3])return x}const w=W(g,r,e,s,c)?rn(g,n,t,e,s,c):null;return x&&w?x.distance<=w.distance?x:w:x||w||null}}const Rt=new j,et=new ft,st=new ft,gt=new nt,dn=new v,Dt=new v;function hi(i,n,t,e){R.setBuffer(i._roots[n]);const s=on(0,i,t,e);return R.clearBuffer(),s}function on(i,n,t,e,s=null){const{float32Array:c,uint16Array:r,uint32Array:l}=R;let o=i*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),dn.set(t.boundingBox.min,t.boundingBox.max,e),s=dn),V(o,r)){const f=n.geometry,y=f.index,a=f.attributes.position,p=t.index,d=t.attributes.position,b=$(i,l),g=I(o,r);if(gt.copy(e).invert(),t.boundsTree)return D(i,c,Dt),Dt.matrix.copy(gt),Dt.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:x=>Dt.intersectsBox(x),intersectsTriangle:x=>{x.a.applyMatrix4(e),x.b.applyMatrix4(e),x.c.applyMatrix4(e),x.needsUpdate=!0;for(let m=b*3,w=(g+b)*3;mJt.distanceToBox(A),intersectsBounds:(A,T,B)=>B{if(n.boundsTree)return n.boundsTree.shapecast({boundsTraverseOrder:P=>wt.distanceToBox(P),intersectsBounds:(P,S,M)=>M{for(let M=P,U=P+S;MT&&(T=L),EB&&(B=E),FP&&(P=F)}}return o[a+0]!==m||o[a+1]!==w||o[a+2]!==A||o[a+3]!==T||o[a+4]!==B||o[a+5]!==P?(o[a+0]=m,o[a+1]=w,o[a+2]=A,o[a+3]=T,o[a+4]=B,o[a+5]=P,!0):!1}else{const h=a+8,x=r[a+6],m=h+p,w=x+p;let A=d,T=!1,B=!1;n?A||(T=n.has(m),B=n.has(w),A=!T&&!B):(T=!0,B=!0);const P=A||T,S=A||B;let M=!1;P&&(M=y(h,p,A));let U=!1;S&&(U=y(x,p,A));const _=M||U;if(_)for(let C=0;C<3;C++){const L=h+C,E=x+C,F=o[L],Z=o[L+3],pt=o[E],yt=o[E+3];o[a+C]=Fyt?Z:yt}return _}}}function _i(i,n,t,e,s,c,r){R.setBuffer(i._roots[n]),cn(0,i,t,e,s,c,r),R.clearBuffer()}function cn(i,n,t,e,s,c,r){const{float32Array:l,uint16Array:o,uint32Array:u}=R,f=i*2;if(V(f,o)){const a=$(i,u),p=I(f,o);ui(n,t,e,a,p,s,c,r)}else{const a=k(i);W(a,l,e,c,r)&&cn(a,n,t,e,s,c,r);const p=q(i,u);W(p,l,e,c,r)&&cn(p,n,t,e,s,c,r)}}const Pi=["x","y","z"];function Mi(i,n,t,e,s,c){R.setBuffer(i._roots[n]);const r=ln(0,i,t,e,s,c);return R.clearBuffer(),r}function ln(i,n,t,e,s,c){const{float32Array:r,uint16Array:l,uint32Array:o}=R;let u=i*2;if(V(u,l)){const y=$(i,o),a=I(u,l);return pi(n,t,e,y,a,s,c)}else{const y=Cn(i,o),a=Pi[y],d=e.direction[a]>=0;let b,g;d?(b=k(i),g=q(i,o)):(b=q(i,o),g=k(i));const x=W(b,r,e,s,c)?ln(b,n,t,e,s,c):null;if(x){const A=x.point[a];if(d?A<=r[g+y]:A>=r[g+y+3])return x}const w=W(g,r,e,s,c)?ln(g,n,t,e,s,c):null;return x&&w?x.distance<=w.distance?x:w:x||w||null}}const Nt=new j,rt=new ft,ot=new ft,Bt=new nt,Tn=new v,vt=new v;function Si(i,n,t,e){R.setBuffer(i._roots[n]);const s=an(0,i,t,e);return R.clearBuffer(),s}function an(i,n,t,e,s=null){const{float32Array:c,uint16Array:r,uint32Array:l}=R;let o=i*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),Tn.set(t.boundingBox.min,t.boundingBox.max,e),s=Tn),V(o,r)){const f=n.geometry,y=f.index,a=f.attributes.position,p=t.index,d=t.attributes.position,b=$(i,l),g=I(o,r);if(Bt.copy(e).invert(),t.boundsTree)return D(i,c,vt),vt.matrix.copy(Bt),vt.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:x=>vt.intersectsBox(x),intersectsTriangle:x=>{x.a.applyMatrix4(e),x.b.applyMatrix4(e),x.c.applyMatrix4(e),x.needsUpdate=!0;for(let m=b,w=g+b;mQt.distanceToBox(A),intersectsBounds:(A,T,B)=>B{if(n.boundsTree){const B=n.boundsTree;return B.shapecast({boundsTraverseOrder:P=>dt.distanceToBox(P),intersectsBounds:(P,S,M)=>M{for(let M=P,U=P+S;Mnew j),ct=new j,lt=new j,Wt=new j,Gt=new j;let Ot=!1;function Di(i,n,t,e){if(Ot)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Ot=!0;const s=i._roots,c=n._roots;let r,l=0,o=0;const u=new nt().copy(t).invert();for(let f=0,y=s.length;fo.slice()),index:r?r.array.slice():null,indirectBuffer:c?c.slice():null}:l={roots:s,index:r?r.array:null,indirectBuffer:c},l}static deserialize(n,t,e={}){e={setIndex:!0,indirect:!!n.indirectBuffer,...e};const{index:s,roots:c,indirectBuffer:r}=n,l=new En(t,{...e,[jt]:!0});if(l._roots=c,l._indirectBuffer=r||null,e.setIndex){const o=t.getIndex();if(o===null){const u=new _n(n.index,1,!1);t.setIndex(u)}else o.array!==s&&(o.array.set(s),o.needsUpdate=!0)}return l}get indirect(){return!!this._indirectBuffer}constructor(n,t={}){if(n.isBufferGeometry){if(n.index&&n.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t=Object.assign({...Fi,[jt]:!1},t),t.useSharedArrayBuffer&&!Ri())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=n,this._roots=null,this._indirectBuffer=null,t[jt]||(On(this,t),!n.boundingBox&&t.setBoundingBox&&(n.boundingBox=this.getBoundingBox(new j))),this.resolveTriangleIndex=t.indirect?e=>this._indirectBuffer[e]:e=>e}refit(n=null){return(this.indirect?bi:fi)(this,n)}traverse(n,t=0){const e=this._roots[t],s=new Uint32Array(e),c=new Uint16Array(e);r(0);function r(l,o=0){const u=l*2,f=c[u+15]===qt;if(f){const y=s[l+6],a=c[u+14];n(o,f,new Float32Array(e,l*4,6),y,a)}else{const y=l+bt/4,a=s[l+6],p=s[l+7];n(o,f,new Float32Array(e,l*4,6),p)||(r(y,o+1),r(a,o+1))}}}raycast(n,t=pn,e=0,s=1/0){const c=this._roots,r=this.geometry,l=[],o=t.isMaterial,u=Array.isArray(t),f=r.groups,y=o?t.side:t,a=this.indirect?_i:xi;for(let p=0,d=c.length;py(a,p,d,b,g)?!0:e(a,p,this,l,d,b,t)}else r||(l?r=(y,a,p,d)=>e(y,a,this,l,p,d,t):r=(y,a,p)=>p);let o=!1,u=0;const f=this._roots;for(let y=0,a=f.length;y{const b=this.resolveTriangleIndex(d);N(r,b*3,l,o)}:d=>{N(r,d*3,l,o)},f=X.getPrimitive(),y=n.geometry.index,a=n.geometry.attributes.position,p=n.indirect?d=>{const b=n.resolveTriangleIndex(d);N(f,b*3,y,a)}:d=>{N(f,d*3,y,a)};if(c){const d=(b,g,h,x,m,w,A,T)=>{for(let B=h,P=h+x;B$t.intersectsBox(e),intersectsTriangle:e=>$t.intersectsTriangle(e)})}intersectsSphere(n){return this.shapecast({intersectsBounds:t=>n.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(n)})}closestPointToGeometry(n,t,e={},s={},c=0,r=1/0){return(this.indirect?zi:Ti)(this,n,t,e,s,c,r)}closestPointToPoint(n,t={},e=0,s=1/0){return ei(this,n,t,e,s)}getBoundingBox(n){return n.makeEmpty(),this._roots.forEach(e=>{D(0,new Float32Array(e),bn),n.union(bn)}),n}}export{Nn as A,bt as B,Pn as C,Vi as I,En as M,vi as N,$ as O,q as R,vn as S,Ht as T,yn as a,$n as b,Ii as c,V as d,kn as e,I as f,In as g,Cn as h,Ri as i,$i as j,xn as k,D as l}; diff --git a/example/bundle/assets/MeshBVHHelper-DbtlD37d.js b/example/bundle/assets/MeshBVHHelper-DbtlD37d.js new file mode 100644 index 000000000..83b3eced0 --- /dev/null +++ b/example/bundle/assets/MeshBVHHelper-DbtlD37d.js @@ -0,0 +1 @@ +import{G as _,w as E,f as P,n as W,O as H,M as j,i as F,B as b,b as T}from"./ExtendedTriangle-CNpFv597.js";import{l as z,M as L}from"./MeshBVH-ujCvfObx.js";const w=new T,B=new W;class O extends H{get isMesh(){return!this.displayEdges}get isLineSegments(){return this.displayEdges}get isLine(){return this.displayEdges}getVertexPosition(...t){return j.prototype.getVertexPosition.call(this,...t)}constructor(t,e,i=10,s=0){super(),this.material=e,this.geometry=new F,this.name="MeshBVHRootHelper",this.depth=i,this.displayParents=!1,this.bvh=t,this.displayEdges=!0,this._group=s}raycast(){}update(){const t=this.geometry,e=this.bvh,i=this._group;if(t.dispose(),this.visible=!1,e){const s=this.depth-1,a=this.displayParents;let o=0;e.traverse((n,y)=>{if(n>=s||y)return o++,!0;a&&o++},i);let p=0;const h=new Float32Array(8*3*o);e.traverse((n,y,u)=>{const d=n>=s||y;if(d||a){z(0,u,w);const{min:g,max:f}=w;for(let m=-1;m<=1;m+=2){const v=m<0?g.x:f.x;for(let x=-1;x<=1;x+=2){const I=x<0?g.y:f.y;for(let M=-1;M<=1;M+=2){const V=M<0?g.z:f.z;h[p+0]=v,h[p+1]=I,h[p+2]=V,p+=3}}}return d}},i);let l,r;this.displayEdges?r=new Uint8Array([0,4,1,5,2,6,3,7,0,2,1,3,4,6,5,7,0,1,2,3,4,5,6,7]):r=new Uint8Array([0,1,2,2,1,3,4,6,5,6,7,5,1,4,5,0,4,1,2,3,6,3,7,6,0,2,4,2,6,4,1,5,3,3,5,7]),h.length>65535?l=new Uint32Array(r.length*o):l=new Uint16Array(r.length*o);const c=r.length;for(let n=0;ni;){const s=this._roots.pop();s.geometry.dispose(),this.remove(s)}for(let s=0;s=this._roots.length){const c=new O(e,o,a,s);this.add(c),this._roots.push(c)}const r=this._roots[s];r.bvh=e,r.depth=a,r.displayParents=h,r.displayEdges=l,r.material=l?o:p,r.update()}}updateMatrixWorld(...t){const e=this.mesh,i=this.parent;e!==null&&(e.updateWorldMatrix(!0,!1),i?this.matrix.copy(i.matrixWorld).invert().multiply(e.matrixWorld):this.matrix.copy(e.matrixWorld),(e.isInstancedMesh||e.isBatchedMesh)&&(e.getMatrixAt(this.objectIndex,B),this.matrix.multiply(B)),this.matrix.decompose(this.position,this.quaternion,this.scale)),super.updateMatrixWorld(...t)}copy(t){this.depth=t.depth,this.mesh=t.mesh,this.bvh=t.bvh,this.opacity=t.opacity,this.color.copy(t.color)}clone(){return new A(this.mesh,this.bvh,this.depth)}dispose(){this.edgeMaterial.dispose(),this.meshMaterial.dispose();const t=this.children;for(let e=0,i=t.length;e=2&&(g[_+1]=e.getY(I)/h),n>=3&&(g[_+2]=e.getZ(I)/h,m===4&&(g[_+3]=1)),n>=4&&(g[_+3]=e.getW(I)/h)}e.normalized=N,this.internalFormat=p,this.format=a,this.type=s,this.image.width=o,this.image.height=o,this.image.data=g,this.needsUpdate=!0,this.dispose(),e.itemSize=d,e.count=r}}class K extends C{constructor(){super(),this._forcedType=B}}class Q extends C{constructor(){super(),this._forcedType=S}}class ne{constructor(){this.index=new K,this.position=new Q,this.bvhBounds=new R,this.bvhContents=new R,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(e){const{geometry:t}=e;if(te(e,this.bvhBounds,this.bvhContents),this.position.updateFrom(t.attributes.position),e.indirect){const d=e._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==d.length)if(t.index)this._cachedIndexAttr=t.index.clone();else{const r=P(Y(t));this._cachedIndexAttr=new O(r,1,!1)}ee(t,d,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(t.index)}dispose(){const{index:e,position:t,bvhBounds:d,bvhContents:r}=this;e&&e.dispose(),t&&t.dispose(),d&&d.dispose(),r&&r.dispose()}}function ee(c,e,t){const d=t.array,r=c.index?c.index.array:null;for(let n=0,y=e.length;nMath.PI&&(s-=r),a<-Math.PI?a+=r:a>Math.PI&&(a-=r),s<=a?this._spherical.theta=Math.max(s,Math.min(a,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(s+a)/2?Math.max(s,this._spherical.theta):Math.min(a,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let h=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const l=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),h=l!=this._spherical.radius}if(n.setFromSpherical(this._spherical),n.applyQuaternion(this._quatInverse),e.copy(this.target).add(n),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let l=null;if(this.object.isPerspectiveCamera){const d=n.length();l=this._clampDistance(d*this._scale);const m=d-l;this.object.position.addScaledVector(this._dollyDirection,m),this.object.updateMatrixWorld(),h=!!m}else if(this.object.isOrthographicCamera){const d=new p(this._mouse.x,this._mouse.y,0);d.unproject(this.object);const m=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),h=m!==this.object.zoom;const g=new p(this._mouse.x,this._mouse.y,0);g.unproject(this.object),this.object.position.sub(g).add(d),this.object.updateMatrixWorld(),l=n.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;l!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(l).add(this.object.position):(f.origin.copy(this.object.position),f.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(f.direction))y||8*(1-this._lastQuaternion.dot(this.object.quaternion))>y||this._lastTargetPosition.distanceToSquared(this.target)>y?(this.dispatchEvent(D),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(t){return t!==null?r/60*this.autoRotateSpeed*t:r/60/60*this.autoRotateSpeed}_getZoomScale(t){const e=Math.abs(t*.01);return Math.pow(.95,this.zoomSpeed*e)}_rotateLeft(t){this._sphericalDelta.theta-=t}_rotateUp(t){this._sphericalDelta.phi-=t}_panLeft(t,e){n.setFromMatrixColumn(e,0),n.multiplyScalar(-t),this._panOffset.add(n)}_panUp(t,e){this.screenSpacePanning===!0?n.setFromMatrixColumn(e,1):(n.setFromMatrixColumn(e,0),n.crossVectors(this.object.up,n)),n.multiplyScalar(t),this._panOffset.add(n)}_pan(t,e){const s=this.domElement;if(this.object.isPerspectiveCamera){const a=this.object.position;n.copy(a).sub(this.target);let h=n.length();h*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*t*h/s.clientHeight,this.object.matrix),this._panUp(2*e*h/s.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(t*(this.object.right-this.object.left)/this.object.zoom/s.clientWidth,this.object.matrix),this._panUp(e*(this.object.top-this.object.bottom)/this.object.zoom/s.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(t,e){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const s=this.domElement.getBoundingClientRect(),a=t-s.left,h=e-s.top,l=s.width,d=s.height;this._mouse.x=a/l*2-1,this._mouse.y=-(h/d)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(t){return Math.max(this.minDistance,Math.min(this.maxDistance,t))}_handleMouseDownRotate(t){this._rotateStart.set(t.clientX,t.clientY)}_handleMouseDownDolly(t){this._updateZoomParameters(t.clientX,t.clientX),this._dollyStart.set(t.clientX,t.clientY)}_handleMouseDownPan(t){this._panStart.set(t.clientX,t.clientY)}_handleMouseMoveRotate(t){this._rotateEnd.set(t.clientX,t.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(r*this._rotateDelta.x/e.clientHeight),this._rotateUp(r*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(t){this._dollyEnd.set(t.clientX,t.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(t){this._panEnd.set(t.clientX,t.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(t){this._updateZoomParameters(t.clientX,t.clientY),t.deltaY<0?this._dollyIn(this._getZoomScale(t.deltaY)):t.deltaY>0&&this._dollyOut(this._getZoomScale(t.deltaY)),this.update()}_handleKeyDown(t){let e=!1;switch(t.code){case this.keys.UP:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateUp(r*this.rotateSpeed/this.domElement.clientHeight):this._pan(0,this.keyPanSpeed),e=!0;break;case this.keys.BOTTOM:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateUp(-r*this.rotateSpeed/this.domElement.clientHeight):this._pan(0,-this.keyPanSpeed),e=!0;break;case this.keys.LEFT:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateLeft(r*this.rotateSpeed/this.domElement.clientHeight):this._pan(this.keyPanSpeed,0),e=!0;break;case this.keys.RIGHT:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateLeft(-r*this.rotateSpeed/this.domElement.clientHeight):this._pan(-this.keyPanSpeed,0),e=!0;break}e&&(t.preventDefault(),this.update())}_handleTouchStartRotate(t){if(this._pointers.length===1)this._rotateStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),s=.5*(t.pageX+e.x),a=.5*(t.pageY+e.y);this._rotateStart.set(s,a)}}_handleTouchStartPan(t){if(this._pointers.length===1)this._panStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),s=.5*(t.pageX+e.x),a=.5*(t.pageY+e.y);this._panStart.set(s,a)}}_handleTouchStartDolly(t){const e=this._getSecondPointerPosition(t),s=t.pageX-e.x,a=t.pageY-e.y,h=Math.sqrt(s*s+a*a);this._dollyStart.set(0,h)}_handleTouchStartDollyPan(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enablePan&&this._handleTouchStartPan(t)}_handleTouchStartDollyRotate(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enableRotate&&this._handleTouchStartRotate(t)}_handleTouchMoveRotate(t){if(this._pointers.length==1)this._rotateEnd.set(t.pageX,t.pageY);else{const s=this._getSecondPointerPosition(t),a=.5*(t.pageX+s.x),h=.5*(t.pageY+s.y);this._rotateEnd.set(a,h)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(r*this._rotateDelta.x/e.clientHeight),this._rotateUp(r*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(t){if(this._pointers.length===1)this._panEnd.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),s=.5*(t.pageX+e.x),a=.5*(t.pageY+e.y);this._panEnd.set(s,a)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(t){const e=this._getSecondPointerPosition(t),s=t.pageX-e.x,a=t.pageY-e.y,h=Math.sqrt(s*s+a*a);this._dollyEnd.set(0,h),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const l=(t.pageX+e.x)*.5,d=(t.pageY+e.y)*.5;this._updateZoomParameters(l,d)}_handleTouchMoveDollyPan(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enablePan&&this._handleTouchMovePan(t)}_handleTouchMoveDollyRotate(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enableRotate&&this._handleTouchMoveRotate(t)}_addPointer(t){this._pointers.push(t.pointerId)}_removePointer(t){delete this._pointerPositions[t.pointerId];for(let e=0;e=2&&t.setY(l,i.getY(o)),n>=3&&t.setZ(l,i.getZ(o)),n>=4&&t.setW(l,i.getW(o))}}else{const n=t.array,o=n.constructor,r=n.BYTES_PER_ELEMENT*i.itemSize*e;new o(n.buffer,r,i.array.length).set(i.array)}}function H(i,t,e){const n=i.elements,o=t.elements;for(let r=0,l=o.length;r{n.traverseVisible(o=>{o.isMesh&&e.push(o)})}),this.meshes=e,this.useGroups=!0,this.applyWorldTransforms=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Array(e.length).fill().map(()=>new W),this._diffMap=new WeakMap}getMaterials(){const t=[];return this.meshes.forEach(e=>{Array.isArray(e.material)?t.push(...e.material):t.push(e.material)}),t}generate(t=new W){let e=[];const{meshes:n,useGroups:o,_intermediateGeometry:r,_diffMap:l}=this;for(let s=0,a=n.length;sr+1e3&&(u.update(e*1e3/(n-r),100),r=n,e=0,h)){var l=performance.memory;h.update(l.usedJSHeapSize/1048576,l.jsHeapSizeLimit/1048576)}return n},update:function(){f=this.end()},domElement:a,setMode:o}};P.Panel=function(m,a,i){var o=1/0,f=0,r=Math.round,e=r(window.devicePixelRatio||1),u=80*e,v=48*e,h=3*e,n=2*e,l=3*e,c=15*e,d=74*e,s=30*e,p=document.createElement("canvas");p.width=u,p.height=v,p.style.cssText="width:80px;height:48px";var t=p.getContext("2d");return t.font="bold "+9*e+"px Helvetica,Arial,sans-serif",t.textBaseline="top",t.fillStyle=i,t.fillRect(0,0,u,v),t.fillStyle=a,t.fillText(m,h,n),t.fillRect(l,c,d,s),t.fillStyle=i,t.globalAlpha=.9,t.fillRect(l,c,d,s),{dom:p,update:function(x,S){o=Math.min(o,x),f=Math.max(f,x),t.fillStyle=i,t.globalAlpha=1,t.fillRect(0,0,u,c),t.fillStyle=a,t.fillText(r(x)+" "+m+" ("+r(o)+"-"+r(f)+")",h,n),t.drawImage(p,l+e,c,d-e,s,l,c,d-e,s),t.fillRect(l+d-e,c,e,s),t.fillStyle=i,t.globalAlpha=.9,t.fillRect(l+d-e,c,e,r((1-x/S)*s))}}};export{P as S}; diff --git a/example/bundle/assets/TransformControls-xd0I7183.js b/example/bundle/assets/TransformControls-xd0I7183.js new file mode 100644 index 000000000..97a2eb908 --- /dev/null +++ b/example/bundle/assets/TransformControls-xd0I7183.js @@ -0,0 +1 @@ +import{k as gt,V as r,aJ as vt,ar as M,n as ut,O as it,f as ft,w as Et,l as f,X as m,i as st,ag as at,M as o,aK as N,al as I,e as It,ak as q,s as Xt,t as Qt,a7 as Yt}from"./ExtendedTriangle-CNpFv597.js";const A=new gt,d=new r,X=new r,c=new M,rt={X:new r(1,0,0),Y:new r(0,1,0),Z:new r(0,0,1)},tt={type:"change"},lt={type:"mouseDown",mode:null},ht={type:"mouseUp",mode:null},ct={type:"objectChange"};class Lt extends vt{constructor(n,e=null){super(void 0,e);const s=new Dt(this);this._root=s;const i=new jt;this._gizmo=i,s.add(i);const h=new kt;this._plane=h,s.add(h);const t=this;function a(w,Y){let z=Y;Object.defineProperty(t,w,{get:function(){return z!==void 0?z:Y},set:function(Z){z!==Z&&(z=Z,h[w]=Z,i[w]=Z,t.dispatchEvent({type:w+"-changed",value:Z}),t.dispatchEvent(tt))}}),t[w]=Y,h[w]=Y,i[w]=Y}a("camera",n),a("object",void 0),a("enabled",!0),a("axis",null),a("mode","translate"),a("translationSnap",null),a("rotationSnap",null),a("scaleSnap",null),a("space","world"),a("size",1),a("dragging",!1),a("showX",!0),a("showY",!0),a("showZ",!0),a("minX",-1/0),a("maxX",1/0),a("minY",-1/0),a("maxY",1/0),a("minZ",-1/0),a("maxZ",1/0);const y=new r,Q=new r,T=new M,j=new M,k=new r,nt=new M,W=new r,S=new r,g=new r,b=0,v=new r;a("worldPosition",y),a("worldPositionStart",Q),a("worldQuaternion",T),a("worldQuaternionStart",j),a("cameraPosition",k),a("cameraQuaternion",nt),a("pointStart",W),a("pointEnd",S),a("rotationAxis",g),a("rotationAngle",b),a("eye",v),this._offset=new r,this._startNorm=new r,this._endNorm=new r,this._cameraScale=new r,this._parentPosition=new r,this._parentQuaternion=new M,this._parentQuaternionInv=new M,this._parentScale=new r,this._worldScaleStart=new r,this._worldQuaternionInv=new M,this._worldScale=new r,this._positionStart=new r,this._quaternionStart=new M,this._scaleStart=new r,this._getPointer=Zt.bind(this),this._onPointerDown=Ht.bind(this),this._onPointerHover=At.bind(this),this._onPointerMove=Tt.bind(this),this._onPointerUp=zt.bind(this),e!==null&&this.connect()}connect(){this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.style.touchAction="auto"}getHelper(){return this._root}pointerHover(n){if(this.object===void 0||this.dragging===!0)return;n!==null&&A.setFromCamera(n,this.camera);const e=et(this._gizmo.picker[this.mode],A);e?this.axis=e.object.name:this.axis=null}pointerDown(n){if(!(this.object===void 0||this.dragging===!0||n!=null&&n.button!==0)&&this.axis!==null){n!==null&&A.setFromCamera(n,this.camera);const e=et(this._plane,A,!0);e&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(e.point).sub(this.worldPositionStart)),this.dragging=!0,lt.mode=this.mode,this.dispatchEvent(lt)}}pointerMove(n){const e=this.axis,s=this.mode,i=this.object;let h=this.space;if(s==="scale"?h="local":(e==="E"||e==="XYZE"||e==="XYZ")&&(h="world"),i===void 0||e===null||this.dragging===!1||n!==null&&n.button!==-1)return;n!==null&&A.setFromCamera(n,this.camera);const t=et(this._plane,A,!0);if(t){if(this.pointEnd.copy(t.point).sub(this.worldPositionStart),s==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),h==="local"&&e!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),e.indexOf("X")===-1&&(this._offset.x=0),e.indexOf("Y")===-1&&(this._offset.y=0),e.indexOf("Z")===-1&&(this._offset.z=0),h==="local"&&e!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),i.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(h==="local"&&(i.position.applyQuaternion(c.copy(this._quaternionStart).invert()),e.search("X")!==-1&&(i.position.x=Math.round(i.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(i.position.y=Math.round(i.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(i.position.z=Math.round(i.position.z/this.translationSnap)*this.translationSnap),i.position.applyQuaternion(this._quaternionStart)),h==="world"&&(i.parent&&i.position.add(d.setFromMatrixPosition(i.parent.matrixWorld)),e.search("X")!==-1&&(i.position.x=Math.round(i.position.x/this.translationSnap)*this.translationSnap),e.search("Y")!==-1&&(i.position.y=Math.round(i.position.y/this.translationSnap)*this.translationSnap),e.search("Z")!==-1&&(i.position.z=Math.round(i.position.z/this.translationSnap)*this.translationSnap),i.parent&&i.position.sub(d.setFromMatrixPosition(i.parent.matrixWorld)))),i.position.x=Math.max(this.minX,Math.min(this.maxX,i.position.x)),i.position.y=Math.max(this.minY,Math.min(this.maxY,i.position.y)),i.position.z=Math.max(this.minZ,Math.min(this.maxZ,i.position.z));else if(s==="scale"){if(e.search("XYZ")!==-1){let a=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(a*=-1),X.set(a,a,a)}else d.copy(this.pointStart),X.copy(this.pointEnd),d.applyQuaternion(this._worldQuaternionInv),X.applyQuaternion(this._worldQuaternionInv),X.divide(d),e.search("X")===-1&&(X.x=1),e.search("Y")===-1&&(X.y=1),e.search("Z")===-1&&(X.z=1);i.scale.copy(this._scaleStart).multiply(X),this.scaleSnap&&(e.search("X")!==-1&&(i.scale.x=Math.round(i.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Y")!==-1&&(i.scale.y=Math.round(i.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),e.search("Z")!==-1&&(i.scale.z=Math.round(i.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(s==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const a=20/this.worldPosition.distanceTo(d.setFromMatrixPosition(this.camera.matrixWorld));let y=!1;e==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(d.copy(this.rotationAxis).cross(this.eye))*a):(e==="X"||e==="Y"||e==="Z")&&(this.rotationAxis.copy(rt[e]),d.copy(rt[e]),h==="local"&&d.applyQuaternion(this.worldQuaternion),d.cross(this.eye),d.length()===0?y=!0:this.rotationAngle=this._offset.dot(d.normalize())*a),(e==="E"||y)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),h==="local"&&e!=="E"&&e!=="XYZE"?(i.quaternion.copy(this._quaternionStart),i.quaternion.multiply(c.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),i.quaternion.copy(c.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),i.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(tt),this.dispatchEvent(ct)}}pointerUp(n){n!==null&&n.button!==0||(this.dragging&&this.axis!==null&&(ht.mode=this.mode,this.dispatchEvent(ht)),this.dragging=!1,this.axis=null)}dispose(){this.disconnect(),this._root.dispose()}attach(n){return this.object=n,this._root.visible=!0,this}detach(){return this.object=void 0,this.axis=null,this._root.visible=!1,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(tt),this.dispatchEvent(ct),this.pointStart.copy(this.pointEnd))}getRaycaster(){return A}getMode(){return this.mode}setMode(n){this.mode=n}setTranslationSnap(n){this.translationSnap=n}setRotationSnap(n){this.rotationSnap=n}setScaleSnap(n){this.scaleSnap=n}setSize(n){this.size=n}setSpace(n){this.space=n}}function Zt(p){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:p.button};{const n=this.domElement.getBoundingClientRect();return{x:(p.clientX-n.left)/n.width*2-1,y:-(p.clientY-n.top)/n.height*2+1,button:p.button}}}function At(p){if(this.enabled)switch(p.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(p));break}}function Ht(p){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(p.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(p)),this.pointerDown(this._getPointer(p)))}function Tt(p){this.enabled&&this.pointerMove(this._getPointer(p))}function zt(p){this.enabled&&(this.domElement.releasePointerCapture(p.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(p)))}function et(p,n,e){const s=n.intersectObject(p,!0);for(let i=0;i.9&&(t.visible=!1)),this.axis==="Y"&&(c.setFromEuler(V.set(0,0,Math.PI/2)),t.quaternion.copy(s).multiply(c),Math.abs(l.copy(H).applyQuaternion(s).dot(this.eye))>.9&&(t.visible=!1)),this.axis==="Z"&&(c.setFromEuler(V.set(0,Math.PI/2,0)),t.quaternion.copy(s).multiply(c),Math.abs(l.copy(C).applyQuaternion(s).dot(this.eye))>.9&&(t.visible=!1)),this.axis==="XYZE"&&(c.setFromEuler(V.set(0,Math.PI/2,0)),l.copy(this.rotationAxis),t.quaternion.setFromRotationMatrix(dt.lookAt(pt,l,H)),t.quaternion.multiply(c),t.visible=this.dragging),this.axis==="E"&&(t.visible=!1)):t.name==="START"?(t.position.copy(this.worldPositionStart),t.visible=this.dragging):t.name==="END"?(t.position.copy(this.worldPosition),t.visible=this.dragging):t.name==="DELTA"?(t.position.copy(this.worldPositionStart),t.quaternion.copy(this.worldQuaternionStart),d.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),d.applyQuaternion(this.worldQuaternionStart.clone().invert()),t.scale.copy(d),t.visible=this.dragging):(t.quaternion.copy(s),this.dragging?t.position.copy(this.worldPositionStart):t.position.copy(this.worldPosition),this.axis&&(t.visible=this.axis.search(t.name)!==-1));continue}t.quaternion.copy(s),this.mode==="translate"||this.mode==="scale"?(t.name==="X"&&Math.abs(l.copy(O).applyQuaternion(s).dot(this.eye))>.99&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1),t.name==="Y"&&Math.abs(l.copy(H).applyQuaternion(s).dot(this.eye))>.99&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1),t.name==="Z"&&Math.abs(l.copy(C).applyQuaternion(s).dot(this.eye))>.99&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1),t.name==="XY"&&Math.abs(l.copy(C).applyQuaternion(s).dot(this.eye))<.2&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1),t.name==="YZ"&&Math.abs(l.copy(O).applyQuaternion(s).dot(this.eye))<.2&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1),t.name==="XZ"&&Math.abs(l.copy(H).applyQuaternion(s).dot(this.eye))<.2&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1)):this.mode==="rotate"&&(J.copy(s),l.copy(this.eye).applyQuaternion(c.copy(s).invert()),t.name.search("E")!==-1&&t.quaternion.setFromRotationMatrix(dt.lookAt(this.eye,pt,H)),t.name==="X"&&(c.setFromAxisAngle(O,Math.atan2(-l.y,l.z)),c.multiplyQuaternions(J,c),t.quaternion.copy(c)),t.name==="Y"&&(c.setFromAxisAngle(H,Math.atan2(l.x,l.z)),c.multiplyQuaternions(J,c),t.quaternion.copy(c)),t.name==="Z"&&(c.setFromAxisAngle(C,Math.atan2(l.y,l.x)),c.multiplyQuaternions(J,c),t.quaternion.copy(c))),t.visible=t.visible&&(t.name.indexOf("X")===-1||this.showX),t.visible=t.visible&&(t.name.indexOf("Y")===-1||this.showY),t.visible=t.visible&&(t.name.indexOf("Z")===-1||this.showZ),t.visible=t.visible&&(t.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),t.material._color=t.material._color||t.material.color.clone(),t.material._opacity=t.material._opacity||t.material.opacity,t.material.color.copy(t.material._color),t.material.opacity=t.material._opacity,this.enabled&&this.axis&&(t.name===this.axis||this.axis.split("").some(function(y){return t.name===y}))&&(t.material.color.setHex(16776960),t.material.opacity=1)}super.updateMatrixWorld(n)}}class kt extends o{constructor(){super(new Xt(1e5,1e5,2,2),new ft({visible:!1,wireframe:!0,side:Qt,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(n){let e=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(e="local"),K.copy(O).applyQuaternion(e==="local"?this.worldQuaternion:$),L.copy(H).applyQuaternion(e==="local"?this.worldQuaternion:$),R.copy(C).applyQuaternion(e==="local"?this.worldQuaternion:$),l.copy(L),this.mode){case"translate":case"scale":switch(this.axis){case"X":l.copy(this.eye).cross(K),P.copy(K).cross(l);break;case"Y":l.copy(this.eye).cross(L),P.copy(L).cross(l);break;case"Z":l.copy(this.eye).cross(R),P.copy(R).cross(l);break;case"XY":P.copy(R);break;case"YZ":P.copy(K);break;case"XZ":l.copy(R),P.copy(L);break;case"XYZ":case"E":P.set(0,0,0);break}break;case"rotate":default:P.set(0,0,0)}P.length()===0?this.quaternion.copy(this.cameraQuaternion):(mt.lookAt(d.set(0,0,0),P,l),this.quaternion.setFromRotationMatrix(mt)),super.updateMatrixWorld(n)}}export{Lt as T}; diff --git a/example/bundle/assets/_commonjsHelpers-Cpj98o6Y.js b/example/bundle/assets/_commonjsHelpers-Cpj98o6Y.js new file mode 100644 index 000000000..b285ce543 --- /dev/null +++ b/example/bundle/assets/_commonjsHelpers-Cpj98o6Y.js @@ -0,0 +1 @@ +var o=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function l(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}export{o as c,l as g}; diff --git a/example/bundle/assets/asyncGenerate-CmbG9MXp.js b/example/bundle/assets/asyncGenerate-CmbG9MXp.js new file mode 100644 index 000000000..00ff0ba0d --- /dev/null +++ b/example/bundle/assets/asyncGenerate-CmbG9MXp.js @@ -0,0 +1,6 @@ +import{B as q,b as z,W as K,c as U,d as _,D as j,A as O,P as N,G as J,M as P,e as Q,f as X,T as Y,g as Z,C as ee,h as re}from"./ExtendedTriangle-CNpFv597.js";import{S as ne}from"./stats.min-GTpOrGrX.js";import{g as te}from"./lil-gui.module.min-Bc0DeA9g.js";import{i as v,e as oe,M as A,c as M,C as F,A as ae,S as ie}from"./MeshBVH-ujCvfObx.js";import{G as se,W as de}from"./GenerateMeshBVHWorker-CkitdNK9.js";import{M as H}from"./MeshBVHHelper-DbtlD37d.js";import"./_commonjsHelpers-Cpj98o6Y.js";const G=typeof navigator<"u"?navigator.hardwareConcurrency:4;class le extends de{constructor(){const o=new Worker(new URL(""+new URL("parallelMeshBVH.worker-DB_vNiSj.js",import.meta.url).href,import.meta.url),{type:"module"});if(super(o),this.name="ParallelMeshBVHWorker",this.maxWorkerCount=Math.max(G,4),!v())throw new Error("ParallelMeshBVHWorker: Shared Array Buffers are not supported.")}runTask(o,r,n={}){return new Promise((u,a)=>{if(!r.index&&!n.indirect&&oe(r,n),r.getAttribute("position").isInterleavedBufferAttribute||r.index&&r.index.isInterleavedBufferAttribute)throw new Error("ParallelMeshBVHWorker: InterleavedBufferAttribute are not supported for the geometry attributes.");o.onerror=p=>{a(new Error(`ParallelMeshBVHWorker: ${p.message}`))},o.onmessage=p=>{const{data:f}=p;if(f.error)a(new Error(f.error)),o.onmessage=null;else if(f.serialized){const{serialized:x,position:I}=f,k=A.deserialize(x,r,{setIndex:!1}),$={setBoundingBox:!0,...n};if(r.attributes.position.array=I,x.index)if(r.index)r.index.array=x.index;else{const L=new q(x.index,1,!1);r.setIndex(L)}$.setBoundingBox&&(r.boundingBox=k.getBoundingBox(new z)),n.onProgress&&n.onProgress(f.progress),u(k),o.onmessage=null}else n.onProgress&&n.onProgress(f.progress)};const d=r.index?r.index.array:null,h=r.attributes.position.array;o.postMessage({operation:"BUILD_BVH",maxWorkerCount:this.maxWorkerCount,index:M(d,SharedArrayBuffer),position:M(h,SharedArrayBuffer),options:{...n,onProgress:null,includedProgressCallback:!!n.onProgress,groups:[...r.groups]}})})}}class ue{constructor(){if(v())return new le;{console.warn("ParallelMeshBVHWorker: SharedArrayBuffers not supported. Falling back to single-threaded GenerateMeshBVHWorker.");const o=new se;return o.maxWorkerCount=G,o}}}const C=typeof SharedArrayBuffer<"u",e={useWebWorker:!0,maxWorkerCount:C?navigator.hardwareConcurrency:1,strategy:F,radius:1,tube:.3,tubularSegments:500,radialSegments:500,p:3,q:5,displayHelper:!1,helperDepth:10};let m,c,w,i,V,g,t,s,y,S,W,E,R,B,b=!1;pe();D();function pe(){S=document.getElementById("output"),W=document.getElementById("loading-container"),E=document.querySelector("#loading-container .bar"),R=document.querySelector("#loading-container .text"),m=new K({antialias:!0}),m.setPixelRatio(window.devicePixelRatio),m.setSize(window.innerWidth,window.innerHeight),m.setClearColor(16763432,1),document.body.appendChild(m.domElement),w=new U,w.fog=new _(16763432,20,60);const o=new j(16777215,3);o.position.set(1,1,1),w.add(o),w.add(new O(11583173,2.5)),c=new N(75,window.innerWidth/window.innerHeight,.1,50),c.position.set(0,0,4),c.far=100,c.updateProjectionMatrix(),V=new re,y=new ne,document.body.appendChild(y.dom),s=new J,w.add(s);for(let a=0;a<400;a++){const d=new P(new Q(1,32,32),new X);d.position.set(Math.random()-.5,Math.random()-.5,Math.random()-.5).multiplyScalar(70),d.scale.setScalar(Math.random()*.3+.1),s.add(d)}B=new ue,window.WORKER=B,g=new te;const r=g.addFolder("helper");r.add(e,"displayHelper").name("enabled").onChange(a=>{a&&t&&t.update()}),r.add(e,"helperDepth",1,50,1).onChange(a=>{t&&(t.depth=a,t.update())}),r.open();const n=g.addFolder("knot");n.add(e,"radius",.5,2,.01),n.add(e,"tube",.2,1.2,.01),n.add(e,"tubularSegments",50,2e3,1),n.add(e,"radialSegments",5,2e3,1),n.add(e,"p",1,10,1),n.add(e,"q",1,10,1),n.open();const u=g.addFolder("bvh");u.add(e,"useWebWorker"),u.add(e,"maxWorkerCount",1,16,1).disable(!C),u.add(e,"strategy",{CENTER:F,AVERAGE:ae,SAH:ie}),g.add({regenerateKnot:T},"regenerateKnot").name("regenerate"),T(),window.addEventListener("resize",function(){c.aspect=window.innerWidth/window.innerHeight,c.updateProjectionMatrix(),m.setSize(window.innerWidth,window.innerHeight)},!1)}function T(){if(b)return;b=!0,i&&(i.material.dispose(),i.geometry.dispose(),s.remove(i),s.remove(t));const l=window.performance.now(),o=window.performance.now();i=new P(new Y(e.radius,e.tube,e.tubularSegments,e.radialSegments,e.p,e.q),new Z({color:new ee(5093036),roughness:.75}));const r=window.performance.now()-o,n=window.performance.now(),u={strategy:e.strategy};let a;if(e.useWebWorker){const d=h=>{const p=(h*100).toFixed(0);W.style.visibility="visible",E.style.width=`${p}%`,R.innerText=`${p}%`};B.maxWorkerCount=e.maxWorkerCount,B.generate(i.geometry,{onProgress:d,...u}).then(h=>{W.style.visibility="hidden",i.geometry.boundsTree=h,s.add(i);const p=window.performance.now()-n;b=!1,t=new H(i,0),t.depth=e.helperDepth,e.displayHelper&&t.update(),s.add(t),S.textContent=`Geometry Generation Time : ${r.toFixed(3)}ms +BVH Generation Time : ${p.toFixed(3)}ms +Frame Stall Time : ${a.toFixed(3)} +SharedArrayBuffer Support : ${C}`}),a=window.performance.now()-l}else{i.geometry.boundsTree=new A(i.geometry,u),a=window.performance.now()-l,s.add(i);const d=window.performance.now()-n;b=!1,t=new H(i),t.depth=e.helperDepth,t.update(),s.add(t),S.textContent=`Geometry Generation Time : ${r.toFixed(3)}ms +BVH Generation Time : ${d.toFixed(3)}ms +Frame Stall Time : ${a.toFixed(3)}`}}function D(){y.update(),requestAnimationFrame(D);let l=V.getDelta();s.rotation.x+=.4*l,s.rotation.y+=.6*l,t&&(t.visible=e.displayHelper),m.render(w,c)} diff --git a/example/bundle/assets/batchedMesh-C2k2xUbg.js b/example/bundle/assets/batchedMesh-C2k2xUbg.js new file mode 100644 index 000000000..f9dff4d94 --- /dev/null +++ b/example/bundle/assets/batchedMesh-C2k2xUbg.js @@ -0,0 +1 @@ +import{M as B,i as W,j as A,k as N,e as j,l as K,O as I,W as J,c as Q,d as U,D as X,A as Y,m as Z,P as _,T as R,f as F,V}from"./ExtendedTriangle-CNpFv597.js";import{S as $}from"./stats.min-GTpOrGrX.js";import{g as ee}from"./lil-gui.module.min-Bc0DeA9g.js";import{a as D,c as te,d as oe,b as ne,e as se}from"./ExtensionUtilities-DGy5CKFv.js";import{C as H,S as ae,A as re}from"./MeshBVH-ujCvfObx.js";import"./_commonjsHelpers-Cpj98o6Y.js";B.prototype.raycast=D;W.prototype.computeBoundsTree=te;W.prototype.disposeBoundsTree=oe;A.prototype.raycast=D;A.prototype.computeBoundsTree=ne;A.prototype.disposeBoundsTree=se;const k=13621468,ie=2503224,z=14162784;let p,c,S,u,O,i,t;const M=[],d=new N,P=new j(.25,20,20),de=new K(.01,.01),m=25,e=new I;let T=null,h=0;const o={raycasters:{count:150,speed:1,near:0,far:m},mesh:{splitStrategy:H,useBoundsTree:!0,speed:1}};ce();y();v();function ce(){p=new J({antialias:!0}),p.setPixelRatio(window.devicePixelRatio),p.setSize(window.innerWidth,window.innerHeight),p.setClearColor(k,1),document.body.appendChild(p.domElement),c=new Q,c.fog=new U(k,40,100);const n=new X(16777215,1.5);n.position.set(1,1,1),c.add(n),c.add(new Y(16777215,1.2)),i=new I,O=new Z({color:ie}),i.scale.multiplyScalar(10),i.rotation.x=10.989999999999943,i.rotation.y=10.989999999999943,c.add(i),me(),u=new _(75,window.innerWidth/window.innerHeight,.1,50),u.position.z=60,u.far=100,u.updateProjectionMatrix(),S=new $,document.body.appendChild(S.dom);const r=new ee,s=r.addFolder("Raycasters");s.add(o.raycasters,"count").min(1).max(1e3).step(1).onChange(()=>y()),s.add(o.raycasters,"speed").min(0).max(20),s.add(o.raycasters,"near").min(0).max(m).onChange(()=>y()),s.add(o.raycasters,"far").min(0).max(m).onChange(()=>y()),s.open();const a=r.addFolder("Mesh");a.add(o.mesh,"useBoundsTree").onChange(()=>y()),a.add(o.mesh,"splitStrategy",{CENTER:H,SAH:ae,AVERAGE:re}).onChange(()=>y()),a.add(o.mesh,"speed").min(0).max(20),a.open(),window.addEventListener("resize",function(){u.aspect=window.innerWidth/window.innerHeight,u.updateProjectionMatrix(),p.setSize(window.innerWidth,window.innerHeight)},!1)}function me(){const r=new R(.5,.2,200,100,2,3),s=new R(.5,.2,200,100,3,4),a=new j(.5,100,100),l=r.attributes.position.count,x=s.attributes.position.count,g=a.attributes.position.count,C=l+x+g,G=r.index.count,E=s.index.count,w=a.index.count,f=G+E+w;t=new A(3,C,f,O);const b=t.addGeometry(r),L=t.addGeometry(s),q=t.addGeometry(a);t.addInstance(b),t.addInstance(L),t.addInstance(q),e.position.x=-1.5,e.updateMatrix(),t.setMatrixAt(0,e.matrix),e.position.x=0,e.updateMatrix(),t.setMatrixAt(1,e.matrix),e.position.x=1.5,e.updateMatrix(),t.setMatrixAt(2,e.matrix),t.rotation.x=Math.random()*10,t.rotation.y=Math.random()*10,i.add(t)}function pe(n){t.getMatrixAt(0,e.matrix),e.matrix.decompose(e.position,e.quaternion,e.scale),e.rotation.x+=3e-4*o.mesh.speed*n,e.rotation.y+=3e-4*o.mesh.speed*n,e.updateMatrix(),t.setMatrixAt(0,e.matrix),t.getMatrixAt(1,e.matrix),e.matrix.decompose(e.position,e.quaternion,e.scale),e.rotation.x+=9e-4*o.mesh.speed*n,e.rotation.y+=9e-4*o.mesh.speed*n,e.updateMatrix(),t.setMatrixAt(1,e.matrix),t.getMatrixAt(2,e.matrix),e.matrix.decompose(e.position,e.quaternion,e.scale),e.rotation.x+=5e-4*o.mesh.speed*n,e.rotation.y+=5e-4*o.mesh.speed*n,e.updateMatrix(),t.setMatrixAt(2,e.matrix)}function ue(){const n=new I,r=new F({color:z}),s=new B(P,r),a=new B(P,r);a.scale.multiplyScalar(.25),s.scale.multiplyScalar(.5);const l=new B(de,new F({color:z,transparent:!0,opacity:.5}));n.add(l),n.add(s),n.add(a),c.add(n),s.position.set(m,0,0),n.rotation.x=Math.random()*10,n.rotation.y=Math.random()*10,n.rotation.z=Math.random()*10;const x=new V,g=new V,C=Math.random()-.5,G=Math.random()-.5,E=Math.random()-.5;M.push({update:()=>{n.rotation.x+=C*1e-4*o.raycasters.speed*h,n.rotation.y+=G*1e-4*o.raycasters.speed*h,n.rotation.z+=E*1e-4*o.raycasters.speed*h,s.updateMatrixWorld(),x.setFromMatrixPosition(s.matrixWorld),g.copy(x).multiplyScalar(-1).normalize(),d.set(x,g),d.firstHitOnly=!0;const w=d.intersectObject(i,!0),f=w.length?w[0].distance:m;a.position.set(m-f,0,0);const b=w.length?f-d.near:f-d.near-(m-d.far);l.position.set(m-d.near-b/2,0,0),l.scale.set(1,b,1),l.rotation.z=Math.PI/2},remove:()=>{c.remove(n)}})}function y(){for(d.near=o.raycasters.near,d.far=o.raycasters.far;M.length>o.raycasters.count;)M.pop().remove();for(;M.lengthr.update()),p.render(c,u),T=n,S.end(),requestAnimationFrame(v)} diff --git a/example/bundle/assets/bvh_struct_definitions.glsl-SZg5BxSQ.js b/example/bundle/assets/bvh_struct_definitions.glsl-SZg5BxSQ.js new file mode 100644 index 000000000..bba926964 --- /dev/null +++ b/example/bundle/assets/bvh_struct_definitions.glsl-SZg5BxSQ.js @@ -0,0 +1,297 @@ +const e=` + +// A stack of uint32 indices can can store the indices for +// a perfectly balanced tree with a depth up to 31. Lower stack +// depth gets higher performance. +// +// However not all trees are balanced. Best value to set this to +// is the trees max depth. +#ifndef BVH_STACK_DEPTH +#define BVH_STACK_DEPTH 60 +#endif + +#ifndef INFINITY +#define INFINITY 1e20 +#endif + +// Utilities +uvec4 uTexelFetch1D( usampler2D tex, uint index ) { + + uint width = uint( textureSize( tex, 0 ).x ); + uvec2 uv; + uv.x = index % width; + uv.y = index / width; + + return texelFetch( tex, ivec2( uv ), 0 ); + +} + +ivec4 iTexelFetch1D( isampler2D tex, uint index ) { + + uint width = uint( textureSize( tex, 0 ).x ); + uvec2 uv; + uv.x = index % width; + uv.y = index / width; + + return texelFetch( tex, ivec2( uv ), 0 ); + +} + +vec4 texelFetch1D( sampler2D tex, uint index ) { + + uint width = uint( textureSize( tex, 0 ).x ); + uvec2 uv; + uv.x = index % width; + uv.y = index / width; + + return texelFetch( tex, ivec2( uv ), 0 ); + +} + +vec4 textureSampleBarycoord( sampler2D tex, vec3 barycoord, uvec3 faceIndices ) { + + return + barycoord.x * texelFetch1D( tex, faceIndices.x ) + + barycoord.y * texelFetch1D( tex, faceIndices.y ) + + barycoord.z * texelFetch1D( tex, faceIndices.z ); + +} + +void ndcToCameraRay( + vec2 coord, mat4 cameraWorld, mat4 invProjectionMatrix, + out vec3 rayOrigin, out vec3 rayDirection +) { + + // get camera look direction and near plane for camera clipping + vec4 lookDirection = cameraWorld * vec4( 0.0, 0.0, - 1.0, 0.0 ); + vec4 nearVector = invProjectionMatrix * vec4( 0.0, 0.0, - 1.0, 1.0 ); + float near = abs( nearVector.z / nearVector.w ); + + // get the camera direction and position from camera matrices + vec4 origin = cameraWorld * vec4( 0.0, 0.0, 0.0, 1.0 ); + vec4 direction = invProjectionMatrix * vec4( coord, 0.5, 1.0 ); + direction /= direction.w; + direction = cameraWorld * direction - origin; + + // slide the origin along the ray until it sits at the near clip plane position + origin.xyz += direction.xyz * near / dot( direction, lookDirection ); + + rayOrigin = origin.xyz; + rayDirection = direction.xyz; + +} +`,t=` + +#ifndef TRI_INTERSECT_EPSILON +#define TRI_INTERSECT_EPSILON 1e-5 +#endif + +// Raycasting +bool intersectsBounds( vec3 rayOrigin, vec3 rayDirection, vec3 boundsMin, vec3 boundsMax, out float dist ) { + + // https://www.reddit.com/r/opengl/comments/8ntzz5/fast_glsl_ray_box_intersection/ + // https://tavianator.com/2011/ray_box.html + vec3 invDir = 1.0 / rayDirection; + + // find intersection distances for each plane + vec3 tMinPlane = invDir * ( boundsMin - rayOrigin ); + vec3 tMaxPlane = invDir * ( boundsMax - rayOrigin ); + + // get the min and max distances from each intersection + vec3 tMinHit = min( tMaxPlane, tMinPlane ); + vec3 tMaxHit = max( tMaxPlane, tMinPlane ); + + // get the furthest hit distance + vec2 t = max( tMinHit.xx, tMinHit.yz ); + float t0 = max( t.x, t.y ); + + // get the minimum hit distance + t = min( tMaxHit.xx, tMaxHit.yz ); + float t1 = min( t.x, t.y ); + + // set distance to 0.0 if the ray starts inside the box + dist = max( t0, 0.0 ); + + return t1 >= dist; + +} + +bool intersectsTriangle( + vec3 rayOrigin, vec3 rayDirection, vec3 a, vec3 b, vec3 c, + out vec3 barycoord, out vec3 norm, out float dist, out float side +) { + + // https://stackoverflow.com/questions/42740765/intersection-between-line-and-triangle-in-3d + vec3 edge1 = b - a; + vec3 edge2 = c - a; + norm = cross( edge1, edge2 ); + + float det = - dot( rayDirection, norm ); + float invdet = 1.0 / det; + + vec3 AO = rayOrigin - a; + vec3 DAO = cross( AO, rayDirection ); + + vec4 uvt; + uvt.x = dot( edge2, DAO ) * invdet; + uvt.y = - dot( edge1, DAO ) * invdet; + uvt.z = dot( AO, norm ) * invdet; + uvt.w = 1.0 - uvt.x - uvt.y; + + // set the hit information + barycoord = uvt.wxy; // arranged in A, B, C order + dist = uvt.z; + side = sign( det ); + norm = side * normalize( norm ); + + // add an epsilon to avoid misses between triangles + uvt += vec4( TRI_INTERSECT_EPSILON ); + + return all( greaterThanEqual( uvt, vec4( 0.0 ) ) ); + +} + +bool intersectTriangles( + // geometry info and triangle range + sampler2D positionAttr, usampler2D indexAttr, uint offset, uint count, + + // ray + vec3 rayOrigin, vec3 rayDirection, + + // outputs + inout float minDistance, inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord, + inout float side, inout float dist +) { + + bool found = false; + vec3 localBarycoord, localNormal; + float localDist, localSide; + for ( uint i = offset, l = offset + count; i < l; i ++ ) { + + uvec3 indices = uTexelFetch1D( indexAttr, i ).xyz; + vec3 a = texelFetch1D( positionAttr, indices.x ).rgb; + vec3 b = texelFetch1D( positionAttr, indices.y ).rgb; + vec3 c = texelFetch1D( positionAttr, indices.z ).rgb; + + if ( + intersectsTriangle( rayOrigin, rayDirection, a, b, c, localBarycoord, localNormal, localDist, localSide ) + && localDist < minDistance + ) { + + found = true; + minDistance = localDist; + + faceIndices = uvec4( indices.xyz, i ); + faceNormal = localNormal; + + side = localSide; + barycoord = localBarycoord; + dist = localDist; + + } + + } + + return found; + +} + +bool intersectsBVHNodeBounds( vec3 rayOrigin, vec3 rayDirection, sampler2D bvhBounds, uint currNodeIndex, out float dist ) { + + uint cni2 = currNodeIndex * 2u; + vec3 boundsMin = texelFetch1D( bvhBounds, cni2 ).xyz; + vec3 boundsMax = texelFetch1D( bvhBounds, cni2 + 1u ).xyz; + return intersectsBounds( rayOrigin, rayDirection, boundsMin, boundsMax, dist ); + +} + +// use a macro to hide the fact that we need to expand the struct into separate fields +#define bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist ) _bvhIntersectFirstHit( bvh.position, bvh.index, bvh.bvhBounds, bvh.bvhContents, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist ) + +bool _bvhIntersectFirstHit( + // bvh info + sampler2D bvh_position, usampler2D bvh_index, sampler2D bvh_bvhBounds, usampler2D bvh_bvhContents, + + // ray + vec3 rayOrigin, vec3 rayDirection, + + // output variables split into separate variables due to output precision + inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord, + inout float side, inout float dist +) { + + // stack needs to be twice as long as the deepest tree we expect because + // we push both the left and right child onto the stack every traversal + int ptr = 0; + uint stack[ BVH_STACK_DEPTH ]; + stack[ 0 ] = 0u; + + float triangleDistance = INFINITY; + bool found = false; + while ( ptr > - 1 && ptr < BVH_STACK_DEPTH ) { + + uint currNodeIndex = stack[ ptr ]; + ptr --; + + // check if we intersect the current bounds + float boundsHitDistance; + if ( + ! intersectsBVHNodeBounds( rayOrigin, rayDirection, bvh_bvhBounds, currNodeIndex, boundsHitDistance ) + || boundsHitDistance > triangleDistance + ) { + + continue; + + } + + uvec2 boundsInfo = uTexelFetch1D( bvh_bvhContents, currNodeIndex ).xy; + bool isLeaf = bool( boundsInfo.x & 0xffff0000u ); + + if ( isLeaf ) { + + uint count = boundsInfo.x & 0x0000ffffu; + uint offset = boundsInfo.y; + + found = intersectTriangles( + bvh_position, bvh_index, offset, count, + rayOrigin, rayDirection, triangleDistance, + faceIndices, faceNormal, barycoord, side, dist + ) || found; + + } else { + + uint leftIndex = currNodeIndex + 1u; + uint splitAxis = boundsInfo.x & 0x0000ffffu; + uint rightIndex = boundsInfo.y; + + bool leftToRight = rayDirection[ splitAxis ] >= 0.0; + uint c1 = leftToRight ? leftIndex : rightIndex; + uint c2 = leftToRight ? rightIndex : leftIndex; + + // set c2 in the stack so we traverse it later. We need to keep track of a pointer in + // the stack while we traverse. The second pointer added is the one that will be + // traversed first + ptr ++; + stack[ ptr ] = c2; + + ptr ++; + stack[ ptr ] = c1; + + } + + } + + return found; + +} +`,i=` +struct BVH { + + usampler2D index; + sampler2D position; + + sampler2D bvhBounds; + usampler2D bvhContents; + +}; +`;export{t as a,i as b,e as c}; diff --git a/example/bundle/assets/characterMovement-Dv60yoUe.js b/example/bundle/assets/characterMovement-Dv60yoUe.js new file mode 100644 index 000000000..b3e4b1766 --- /dev/null +++ b/example/bundle/assets/characterMovement-Dv60yoUe.js @@ -0,0 +1 @@ +import{V as P,b as K,n as O,o as I,W as q,p as J,c as N,d as Q,D as U,q as X,P as Y,M as G,g as R,G as Z,h as _}from"./ExtendedTriangle-CNpFv597.js";import{R as $}from"./RoundedBoxGeometry-V9OB1gSg.js";import{G as ee}from"./GLTFLoader-CPZ_tJoX.js";import{O as te}from"./OrbitControls-I50Ha_kb.js";import{m as ae}from"./BufferGeometryUtils-BjOdgyuH.js";import{S as oe}from"./stats.min-GTpOrGrX.js";import{g as ie}from"./lil-gui.module.min-Bc0DeA9g.js";import{S as se}from"./StaticGeometryGenerator-BuhbcQd1.js";import{M as re}from"./MeshBVH-ujCvfObx.js";import{M as ne}from"./MeshBVHHelper-DbtlD37d.js";import"./_commonjsHelpers-Cpj98o6Y.js";const a={firstPerson:!1,displayCollider:!1,displayBVH:!1,visualizeDepth:10,gravity:-30,playerSpeed:10,physicsSteps:5,reset:F};let f,d,g,T,b,W,v,c,V,e,r,C=!1,z=!1,B=!1,D=!1,H=!1,h=new P,k=new P(0,1,0),w=new P,L=new P,M=new K,A=new O,y=new I;de();j();function de(){f=new q({antialias:!0}),f.setPixelRatio(window.devicePixelRatio),f.setSize(window.innerWidth,window.innerHeight),f.setClearColor(1251612,1),f.shadowMap.enabled=!0,f.shadowMap.type=J,document.body.appendChild(f.domElement),g=new N,g.fog=new Q(1251612,20,70);const t=new U(16777215,3);t.position.set(1,1.5,1).multiplyScalar(50),t.shadow.mapSize.setScalar(2048),t.shadow.bias=-1e-4,t.shadow.normalBias=.05,t.castShadow=!0;const i=t.shadow.camera;i.bottom=i.left=-30,i.top=30,i.right=45,g.add(t),g.add(new X(16777215,2241348,.4)),d=new Y(75,window.innerWidth/window.innerHeight,.1,50),d.position.set(10,10,-10),d.far=100,d.updateProjectionMatrix(),window.camera=d,T=new _,r=new te(d,f.domElement),W=new oe,document.body.appendChild(W.dom),le(),e=new G(new $(1,2,1,10,.5),new R),e.geometry.translate(0,-.5,0),e.capsuleInfo={radius:.5,segment:new I(new P,new P(0,-1,0))},e.castShadow=!0,e.receiveShadow=!0,e.material.shadowSide=2,g.add(e),F(),b=new ie,b.add(a,"firstPerson").onChange(n=>{n||d.position.sub(r.target).normalize().multiplyScalar(10).add(r.target)});const p=b.addFolder("Visualization");p.add(a,"displayCollider"),p.add(a,"displayBVH"),p.add(a,"visualizeDepth",1,20,1).onChange(n=>{V.depth=n,V.update()}),p.open();const s=b.addFolder("Player");s.add(a,"physicsSteps",0,30,1),s.add(a,"gravity",-100,100,.01).onChange(n=>{a.gravity=parseFloat(n)}),s.add(a,"playerSpeed",1,20),s.open(),b.add(a,"reset"),b.open(),window.addEventListener("resize",function(){d.aspect=window.innerWidth/window.innerHeight,d.updateProjectionMatrix(),f.setSize(window.innerWidth,window.innerHeight)},!1),window.addEventListener("keydown",function(n){switch(n.code){case"KeyW":z=!0;break;case"KeyS":B=!0;break;case"KeyD":H=!0;break;case"KeyA":D=!0;break;case"Space":C&&(h.y=10,C=!1);break}}),window.addEventListener("keyup",function(n){switch(n.code){case"KeyW":z=!1;break;case"KeyS":B=!1;break;case"KeyD":H=!1;break;case"KeyA":D=!1;break}})}function le(){new ee().load("https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/dungeon-warkarma/scene.gltf",l=>{const t=l.scene;t.scale.setScalar(.01);const i=new K;i.setFromObject(t),i.getCenter(t.position).negate(),t.updateMatrixWorld(!0);const p={};t.traverse(o=>{if(!(/Boss/.test(o.name)||/Enemie/.test(o.name)||/Shield/.test(o.name)||/Sword/.test(o.name)||/Character/.test(o.name)||/Gate/.test(o.name)||/Cube/.test(o.name)||o.material&&o.material.color.r===1)&&o.isMesh){const S=o.material.color.getHex();p[S]=p[S]||[],p[S].push(o)}}),v=new Z;for(const o in p){const S=p[o],x=[];if(S.forEach(u=>{if(u.material.emissive.r!==0)v.attach(u);else{const m=u.geometry.clone();m.applyMatrix4(u.matrixWorld),x.push(m)}}),x.length){const u=ae(x),m=new G(u,new R({color:parseInt(o),shadowSide:2}));m.castShadow=!0,m.receiveShadow=!0,m.material.shadowSide=2,v.add(m)}}const s=new se(v);s.attributes=["position"];const n=s.generate();n.boundsTree=new re(n),c=new G(n),c.material.wireframe=!0,c.material.opacity=.5,c.material.transparent=!0,V=new ne(c,a.visualizeDepth),g.add(V),g.add(c),g.add(v)})}function F(){h.set(0,0,0),e.position.set(15.75,-3,30),d.position.sub(r.target),r.target.copy(e.position),d.position.add(e.position),r.update()}function pe(l){C?h.y=l*a.gravity:h.y+=l*a.gravity,e.position.addScaledVector(h,l);const t=r.getAzimuthalAngle();z&&(w.set(0,0,-1).applyAxisAngle(k,t),e.position.addScaledVector(w,a.playerSpeed*l)),B&&(w.set(0,0,1).applyAxisAngle(k,t),e.position.addScaledVector(w,a.playerSpeed*l)),D&&(w.set(-1,0,0).applyAxisAngle(k,t),e.position.addScaledVector(w,a.playerSpeed*l)),H&&(w.set(1,0,0).applyAxisAngle(k,t),e.position.addScaledVector(w,a.playerSpeed*l)),e.updateMatrixWorld();const i=e.capsuleInfo;M.makeEmpty(),A.copy(c.matrixWorld).invert(),y.copy(i.segment),y.start.applyMatrix4(e.matrixWorld).applyMatrix4(A),y.end.applyMatrix4(e.matrixWorld).applyMatrix4(A),M.expandByPoint(y.start),M.expandByPoint(y.end),M.min.addScalar(-i.radius),M.max.addScalar(i.radius),c.geometry.boundsTree.shapecast({intersectsBounds:o=>o.intersectsBox(M),intersectsTriangle:o=>{const S=w,x=L,u=o.closestPointToSegment(y,S,x);if(uMath.abs(l*h.y*.25);const n=Math.max(0,s.length()-1e-5);s.normalize().multiplyScalar(n),e.position.add(s),C?h.set(0,0,0):(s.normalize(),h.addScaledVector(s,-s.dot(h))),d.position.sub(r.target),r.target.copy(e.position),d.position.add(e.position),e.position.y<-25&&F()}function j(){W.update(),requestAnimationFrame(j);const l=Math.min(T.getDelta(),.1);if(a.firstPerson?(r.maxPolarAngle=Math.PI,r.minDistance=1e-4,r.maxDistance=1e-4):(r.maxPolarAngle=Math.PI/2,r.minDistance=1,r.maxDistance=20),c){c.visible=a.displayCollider,V.visible=a.displayBVH;const t=a.physicsSteps;for(let i=0;i{const t=s.scene.children[0],E=t.geometry;t.material=new I,t.position.set(0,0,0),t.quaternion.identity();const H=t.clone();H.material=new ue({depthFunc:we}),H.renderOrder=1,d.scale.copy(t.scale),d.position.set(0,0,0),d.quaternion.identity(),t.updateMatrixWorld(!0);const $=new Set,y=new Map;g=t,g.updateMatrixWorld(!0),g.traverse(n=>{if(n.isMesh){if(y.has(n.material)){n.material=y.get(n.material);return}$.add(n.material);const e=n.material.clone();e.color.set(16777215),e.roughness=1,e.metalness=0,e.side=he,e.stencilWrite=!0,e.stencilFail=Z,e.stencilZFail=Z,e.stencilZPass=Z,e.clippingPlanes=v,y.set(n.material,e),n.material=e}}),y.clear(),W=g.clone(),W.traverse(n=>{if(n.isMesh){if(y.has(n.material)){n.material=y.get(n.material);return}const e=n.material.clone();e.color.set(16777215),e.roughness=1,e.metalness=0,e.colorWrite=!1,e.depthWrite=!1,e.side=ye,e.stencilWrite=!0,e.stencilFail=A,e.stencilZFail=A,e.stencilZPass=A,e.clippingPlanes=v,y.set(n.material,e),n.material=e}}),C=new Fe(E,{maxLeafTris:3}),E.boundsTree=C,m=new z(E,new I({wireframe:!0,transparent:!0,opacity:.01,depthWrite:!1})),m.renderOrder=2,m.position.copy(t.position),m.rotation.copy(t.rotation),m.scale.copy(t.scale),f=new ve(m,parseInt(a.helperDepth)),f.depth=parseInt(a.helperDepth),f.update();const B=new Me;B.add(g,W,H,m,f,d);const T=new ge;T.setFromObject(g),T.getCenter(B.position).multiplyScalar(-1),B.updateMatrixWorld(!0),M.add(B)}),w=new Be,w.add(a,"invert"),w.add(a,"animate"),w.add(a,"animation",["SPIN","OSCILLATE"]).onChange(()=>{S=0}),w.add(a,"displayModel"),w.add(a,"useBVH");const x=w.addFolder("helper");x.add(a,"wireframeDisplay"),x.add(a,"helperDisplay"),x.add(a,"helperDepth",1,20,1).onChange(s=>{f&&(f.depth=parseInt(s),f.update())}),x.open(),w.open(),q=new De,document.body.appendChild(q.domElement),window.addEventListener("resize",function(){h.aspect=window.innerWidth/window.innerHeight,h.updateProjectionMatrix(),l.setSize(window.innerWidth,window.innerHeight),l.setPixelRatio(window.devicePixelRatio)},!1)}function U(){f&&(f.visible=a.helperDisplay,m.visible=a.wireframeDisplay,g.visible=a.displayModel,W.visible=a.displayModel),d.material.color.set(a.displayModel?44225:5099745).convertSRGBToLinear();const P=Math.min(X.getDelta(),.03);a.animate&&(S+=P,a.animation==="SPIN"?(r.rotation.x=.25*S,r.rotation.y=.25*S,r.rotation.z=.25*S,r.position.set(0,0,0)):(r.position.set(Math.sin(.25*S)*.325,0,0),r.rotation.set(0,Math.PI/2,0)),r.updateMatrixWorld());const u=v[0];if(u.normal.set(0,0,a.invert?1:-1),u.constant=0,u.applyMatrix4(r.matrixWorld),C&&(a.animate||!N)){N=!0,R.copy(m.matrixWorld).invert(),b.copy(u).applyMatrix4(R);let i=0;const p=d.geometry.attributes.position,D=window.performance.now();C.shapecast({intersectsBounds:s=>a.useBVH?b.intersectsBox(s):We,intersectsTriangle:s=>{let t=0;c.start.copy(s.a),c.end.copy(s.b),b.intersectLine(c,o)&&(p.setXYZ(i,o.x,o.y,o.z),i++,t++),c.start.copy(s.b),c.end.copy(s.c),b.intersectLine(c,o)&&(p.setXYZ(i,o.x,o.y,o.z),t++,i++),c.start.copy(s.c),c.end.copy(s.a),b.intersectLine(c,o)&&(p.setXYZ(i,o.x,o.y,o.z),t++,i++),t===3&&(V.fromBufferAttribute(p,i-3),G.fromBufferAttribute(p,i-2),F.fromBufferAttribute(p,i-1),F.equals(V)||F.equals(G)?(t--,i--):V.equals(G)&&(p.setXYZ(i-2,F),t--,i--)),t!==2&&(i-=t)}}),d.geometry.setDrawRange(0,i),d.position.copy(u.normal).multiplyScalar(-1e-5),p.needsUpdate=!0;const x=window.performance.now()-D;Y.innerText=`${parseFloat(x.toFixed(3))}ms`}q.update(),requestAnimationFrame(U),j.update(),l.render(M,h)} diff --git a/example/bundle/assets/collectTriangles-BXQSyYeP.js b/example/bundle/assets/collectTriangles-BXQSyYeP.js new file mode 100644 index 000000000..9bf3449d1 --- /dev/null +++ b/example/bundle/assets/collectTriangles-BXQSyYeP.js @@ -0,0 +1 @@ +import{M as L,i as H,J as N,W as P,c as G,d as I,D as j,A as F,T as U,B as V,u as X,g as D,e as Y,P as k,k as O,n as K,K as q,V as J}from"./ExtendedTriangle-CNpFv597.js";import{S as Z}from"./Stats-9dH8FB2H.js";import{g as _}from"./lil-gui.module.min-Bc0DeA9g.js";import{O as Q}from"./OrbitControls-I50Ha_kb.js";import{I as W,a as $,N as ee}from"./MeshBVH-ujCvfObx.js";import{a as te,c as ne,d as oe}from"./ExtensionUtilities-DGy5CKFv.js";L.prototype.raycast=te;H.prototype.computeBoundsTree=ne;H.prototype.disposeBoundsTree=oe;const d={size:.1,rotate:!0};let C,w,o,s,m,l,c,y=new N,x=-1,M=!1,B;function re(){s=new P({antialias:!0}),s.setPixelRatio(window.devicePixelRatio),s.setSize(window.innerWidth,window.innerHeight),s.setClearColor(1251612,1),document.body.appendChild(s.domElement),s.domElement.style.touchAction="none",w=new G,w.fog=new I(2503224/2,20,60);const E=new j(16777215,1.5);E.position.set(1,1,1),w.add(E),w.add(new F(16777215,1.2));const p=1,S=.4,T=800,u=400,h=new U(p,S,T,u).toNonIndexed(),g=new Uint8Array(h.attributes.position.count*3);g.fill(255);const a=new V(g,3,!0);a.setUsage(X),h.setAttribute("color",a);const b=new D({color:16777215,roughness:.3,metalness:0,vertexColors:!0});l=new L(h,b),l.geometry.computeBoundsTree(),w.add(l);const A=new Y(1,40,40),r=new D({color:15483002,roughness:.75,metalness:0,transparent:!0,opacity:.5,premultipliedAlpha:!0,emissive:15483002,emissiveIntensity:.5});c=new L(A,r),w.add(c),o=new k(75,window.innerWidth/window.innerHeight,.1,50),o.position.set(3,3,3),o.far=100,o.updateProjectionMatrix(),C=new Z,document.body.appendChild(C.dom);const n=new _;n.add(d,"size").min(.1).max(1).step(.1),n.add(d,"rotate"),n.open(),window.addEventListener("resize",function(){o.aspect=window.innerWidth/window.innerHeight,o.updateProjectionMatrix(),s.setSize(window.innerWidth,window.innerHeight)},!1),window.addEventListener("pointermove",function(e){y.x=e.clientX/window.innerWidth*2-1,y.y=-(e.clientY/window.innerHeight)*2+1,M=!0}),window.addEventListener("pointerdown",function(e){y.x=e.clientX/window.innerWidth*2-1,y.y=-(e.clientY/window.innerHeight)*2+1,x=e.button;const t=new O;t.setFromCamera(y,o),t.firstHitOnly=!0;const i=t.intersectObject(l,!0);M=!0,m.enabled=i.length===0},!0),window.addEventListener("pointerup",function(e){x=-1,e.pointerType==="touch"&&(M=!1)},!0),window.addEventListener("contextmenu",function(e){e.preventDefault()}),window.addEventListener("wheel",function(e){let t=e.deltaY;e.deltaMode===1&&(t*=40),e.deltaMode===2&&(t*=40),d.size+=t*5e-4,d.size=Math.max(Math.min(d.size,1),.1),n.controllersRecursive().forEach(i=>i.updateDisplay())}),m=new Q(o,s.domElement),m.addEventListener("start",function(){this.active=!0}),m.addEventListener("end",function(){this.active=!1}),B=window.performance.now()}function R(){requestAnimationFrame(R),C.begin();const v=l.geometry,E=v.boundsTree,p=v.getAttribute("color"),S=v.index;if(m.active||!M)c.visible=!1;else{c.scale.setScalar(d.size);const u=new O;u.setFromCamera(y,o),u.firstHitOnly=!0;const h=u.intersectObject(l,!0);if(h.length){c.position.copy(h[0].point),m.enabled=!1,c.visible=!0;const g=new K;g.copy(l.matrixWorld).invert();const a=new q;a.center.copy(c.position).applyMatrix4(g),a.radius=d.size;const b=[],A=new J;if(E.shapecast({intersectsBounds:r=>{const n=a.intersectsBox(r),{min:e,max:t}=r;if(n){for(let i=0;i<=1;i++)for(let f=0;f<=1;f++)for(let z=0;z<=1;z++)if(A.set(i===0?e.x:t.x,f===0?e.y:t.y,z===0?e.z:t.z),!a.containsPoint(A))return W;return $}return n?W:ee},intersectsTriangle:(r,n,e)=>{if(e||r.intersectsSphere(a)){const t=3*n;b.push(t,t+1,t+2)}return!1}}),x===0||x===2){let r=1,n=1,e=1;x===0&&(r=15/255,n=78/255,e=85/255);for(let t=0,i=b.length;t.5?oe.set(0,1,0):oe.set(1,0,0),be.crossVectors(o,oe).normalize(),We.crossVectors(o,be).normalize(),e.makeBasis(We,be,o)}function Ye(o,e,t){return t.addVectors(o,e).normalize()}function Le(o,e,t){const n=o.dot(e)>0,r=o.dot(t)>0;return n===r}const Rt=new T,Ge=new T,Wt=new T,Vt=new T,Et=new T(0,0,1),xe=Math.PI;function Lt(o,e,t,n,r,s){const m=Rt.set(e*o.x,t*o.y,o.z).normalize(),c=m.z<.9999?Ge.crossVectors(m,Et).normalize():Ge.set(1,0,0),i=Wt.crossVectors(c,m),l=1/(1+m.z),d=Math.sqrt(n),g=r1&&(b=1),r.lerpColors(qt,t.color,s).multiplyScalar(d*g/(4*Math.abs(e.z*o.z))).multiplyScalar(E.lerp(b,1,s)).multiplyScalar(e.z)}function Xt(o,e,t,n){const{ior:r}=t,{frontFace:s}=n,m=s?1/r:r,c=Math.min(o.z,1),i=Math.sqrt(1-c*c);let l=ue(c,m);return m*i>1?0:1/(1-l)}function Yt(o,e,t,n){const{roughness:r,ior:s}=t,{frontFace:m}=e,c=m?1/s:s;se.copy(o).multiplyScalar(-1),kt(se,new T(0,0,1),c,n),se.randomDirection().multiplyScalar(r),n.add(se)}function Qt(o,e,t,n,r){const{metalness:s,transmission:m}=t;r.copy(t.color).multiplyScalar(1-s).multiplyScalar(m)}function Ze(o,e,t,n){const{ior:r,metalness:s,transmission:m}=t,{frontFace:c}=n,i=c?1/r:r,l=Math.min(o.z,1),d=Math.sqrt(1-l*l);let g=ue(l,i);i*d>1&&(g=1);let u=0,M=0,I=0;e.z<0?I=Xt(o,e,t,n):(u=Ot(o,e,t,n),M=$t(o,e));const F=E.lerp(g,1,s),$=.5+.5*s;return u*m*F+I*m*(1-F)+u*(1-m)*$+M*(1-m)*(1-$)}function Je(o,e,t,n,r){e.z<0?Qt(o,e,t,n,r):(jt(o,e,t,n,r),r.multiplyScalar(1-t.transmission),Ut(o,e,t,n,He),r.add(He))}function Zt(o,e,t,n){const r=n.direction,{ior:s,metalness:m,transmission:c}=t,{frontFace:i}=e,l=i?1/s:s,d=Math.min(o.z,1),g=Math.sqrt(1-d*d);let b=ue(d,l);if(l*g>1&&(b=1),Math.random(){let i;c.scene.traverse(u=>{u.isMesh&&u.name==="Dragon"&&(i=u)}),i.material=new k,i.geometry.center().scale(.25,.25,.25).rotateX(Math.PI/2),i.position.set(0,0,0),i.scale.set(1,1,1),i.quaternion.identity();const{geometry:l,materials:d}=ze([i],!0),g=new D(l,new k),b=new Re;b.generate(l,{maxLeafTris:1,strategy:we}).then(u=>{R.Dragon={mesh:g,materials:d,floorHeight:i.geometry.boundingBox.min.y},l.boundsTree=u,b.dispose(),_.add(g)})}),R.Engine=null,new De().setMeshoptDecoder(zt).load("https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/internal-combustion-engine/model.gltf",c=>{const i=c.scene.children[0],l=i.geometry,d=new ve,g=l.attributes.position,b=l.attributes.normal,u=new he(new Float32Array(g.count*3),3,!1),M=new he(new Float32Array(b.count*3),3,!1),I=new T;for(let v=0,ie=g.count;v{R.Engine={mesh:F,materials:[new k],floorHeight:d.boundingBox.min.y},d.boundsTree=v,$.dispose(),_.add(F)})}),O=0,Ke=new wt;const o=new Ct;o.add(a,"model",Object.keys(R)).onChange(p);const e=o.addFolder("resolution");e.add(a.resolution,"resolutionScale",.1,1,.01).onChange(J),e.add(a.resolution,"smoothImageScaling").onChange(J),e.add(a.resolution,"stretchImage").onChange(J),e.open();const t=o.addFolder("path tracing");t.add(a.pathTracing,"pause"),t.add(a.pathTracing,"displayScanLine").onChange(c=>{G.style.visibility=c?"visible":"hidden"}),t.add(a.pathTracing,"antialiasing").onChange(p),t.add(a.pathTracing,"directLightSampling").onChange(p),t.add(a.pathTracing,"smoothNormals").onChange(p),t.add(a.pathTracing,"bounces",1,50,1).onChange(p),t.add(a.pathTracing,"filterGlossyFactor",0,1,.001).onChange(p),t.open();const n=o.addFolder("model");n.addColor(a.material,"color").onChange(p),n.addColor(a.material,"emissive").onChange(p),n.add(a.material,"emissiveIntensity",0,5,.001).onChange(p),n.add(a.material,"roughness",0,1,.001).onChange(p),n.add(a.material,"metalness",0,1,.001).onChange(p),n.add(a.material,"transmission",0,1,.001).onChange(p),n.add(a.material,"ior",1,2.5,.001).onChange(p),n.open();const r=o.addFolder("floor");r.add(a.floor,"enable").onChange(p),r.addColor(a.floor,"color").onChange(p),r.add(a.floor,"roughness",0,1,.001).onChange(p),r.add(a.floor,"metalness",0,1,.001).onChange(p),r.add(a.floor,"width",3,20,.001).onChange(p),r.add(a.floor,"height",3,20,.001).onChange(p);const s=o.addFolder("light");s.add(a.light,"enable").onChange(p),s.addColor(a.light,"color").onChange(p),s.add(a.light,"intensity",0,100,.001).onChange(p),s.add(a.light,"width",0,5,.001).onChange(p),s.add(a.light,"height",0,5,.001).onChange(p),s.add(a.light,"position",["Diagonal","Above","Below"]).onChange(p);const m=o.addFolder("environment");m.add(a.environment,"skyMode",["sky","sun","checkerboard"]).onChange(p),m.add(a.environment,"skyIntensity",0,5,.001).onChange(p),J()}function ze(o,e=!0){const t=[],n=[];for(let s=0,m=o.length;snew ke),u=new T(0,0,1).transformDirection(y.matrixWorld),M=y.scale.x,I=y.scale.y,F=new gt;F.firstHitOnly=!0;const $=new ke,v={pdf:0,color:new te,direction:new T};let ie=performance.now();for(ot=performance.now(),Ie=0,fe=100,G.style.visibility=a.pathTracing.displayScanLine?"visible":"hidden",re.material.side=Z,ee.forEach(S=>{S.side=Z});;){let S=0,h=0;if(a.pathTracing.antialiasing){const f=O%Ee.length;[S,h]=Ee[f],S=S/Ve/o,h=h/Ve/e}for(let f=e-1;f>=0;f--)for(let x=0;x16&&(Ie+=z,fe=100*f/e,yield,ie=performance.now())}O++}function at(S,h,f){const x=S.object,P=x.geometry.attributes.position,V=x.geometry.attributes.normal,w=x.geometry.attributes.materialIndex,B=S.face,z=S.face.normal;if(m){const H=S.point;le.a.fromBufferAttribute(P,B.a),le.b.fromBufferAttribute(P,B.b),le.c.fromBufferAttribute(P,B.c),ce.fromBufferAttribute(V,B.a),je.fromBufferAttribute(V,B.b),Oe.fromBufferAttribute(V,B.c),le.getBarycoord(H,de),d.setScalar(0).addScaledVector(ce,de.x).addScaledVector(je,de.y).addScaledVector(Oe,de.z).normalize()}else d.copy(z);z.transformDirection(x.matrixWorld),d.transformDirection(x.matrixWorld);const C=z.dot(h.direction)<0;C||(d.multiplyScalar(-1),z.multiplyScalar(-1));let X=x.material;if(w){const H=w.getX(B.a);X=ee[H]}S.material=X,S.normal=d,S.geometryNormal=z,S.frontFace=C,S.filteredSurfaceRoughness=Math.min(Math.max(1e-6,X.roughness,f*a.pathTracing.filterGlossyFactor*5),1)}function rt(S,h){let f=S,x=0,P=0;i.set(16777215);for(let V=0;V.95){let x=(f-.95)/.05;x*=x,h.r=E.lerp(.5,10,x),h.g=E.lerp(.7,10,x),h.b=E.lerp(1,10,x)}h.multiplyScalar(r)}else{const f=(S.y+.5)/2;h.r=E.lerp(1,.5,f),h.g=E.lerp(1,.7,f),h.b=E.lerp(1,1,f),h.multiplyScalar(r)}}}function Ue(o){o=o||0;let e=o*.001;const t=Math.floor(e/60);e=e-t*60;const n=(t<10?"0":"")+t,r=(e<10?"0":"")+e.toFixed(3);return`${n}m ${r}s`}function nt(){requestAnimationFrame(nt);for(const e in R)R[e]&&(R[e].mesh.visible=!1);if(R[a.model]){const e=R[a.model];e.mesh.visible=!0,re=e.mesh,ee=e.materials,W.position.y=e.floorHeight,ee.forEach(n=>{n.ior===void 0&&(n.ior=1),n.transmission===void 0&&(n.transmission=0)});const t=ee[0];switch(t.color.set(a.material.color).convertSRGBToLinear(),t.emissive.set(a.material.emissive).convertSRGBToLinear(),t.emissiveIntensity=parseFloat(a.material.emissiveIntensity),t.ior=parseFloat(a.material.ior),t.metalness=parseFloat(a.material.metalness),t.transmission=parseFloat(a.material.transmission),t.roughness=Math.pow(parseFloat(a.material.roughness),2),a.light.position){case"Below":y.rotation.set(-Math.PI/2,0,0),y.position.set(0,e.floorHeight+.001,0);break;case"Above":y.rotation.set(Math.PI/2,0,0),y.position.set(0,2-.001,0);break;default:y.position.set(2,2,2),y.lookAt(0,0,0);break}}else re=null,ee=null,W.position.y=0;let o=0;ae>Se&&(o=Math.min((ae-Se)/(_e-Se),1)),G.style.bottom=`${fe}%`,a.resolution.stretchImage?G.style.borderBottomWidth=`${Math.ceil(1/a.resolution.resolutionScale)}px`:G.style.borderBottomWidth="1px",A.render(_,q),A.autoClear=!1,K.material.map=N,K.material.opacity=o,K.render(A),A.autoClear=!0,re&&!a.pathTracing.pause&&et.next(),N.needsUpdate=!0,A.compile(K._mesh),ae<_e&&(ae+=Ke.getDelta()*1e3),tt.innerText=`completed samples : ${O} +computation time : ${Ue(Ie)} +elapsed time : ${Ue(performance.now()-ot)}`} diff --git a/example/bundle/assets/diamond-DQoWKGpc.js b/example/bundle/assets/diamond-DQoWKGpc.js new file mode 100644 index 000000000..3c3c55736 --- /dev/null +++ b/example/bundle/assets/diamond-DQoWKGpc.js @@ -0,0 +1,161 @@ +import{a1 as ne,H as W,F as X,a2 as V,a3 as te,L as q,c as ie,P as oe,W as le,a4 as ce,a5 as se,a6 as me,S as de,J as fe,C as he,M as pe,h as ve}from"./ExtendedTriangle-CNpFv597.js";import{g as ge}from"./lil-gui.module.min-Bc0DeA9g.js";import{O as ue}from"./OrbitControls-I50Ha_kb.js";import{G as ye}from"./GLTFLoader-CPZ_tJoX.js";import{M as we,S as _e}from"./MeshBVH-ujCvfObx.js";import{M as be}from"./MeshBVHUniformStruct-CwgYze0J.js";import{c as Re,b as Me,a as Ee}from"./bvh_struct_definitions.glsl-SZg5BxSQ.js";import"./BufferGeometryUtils-BjOdgyuH.js";class De extends ne{constructor(c){super(c),this.type=W}parse(c){const e=function(r,n){switch(r){case 1:throw new Error("THREE.RGBELoader: Read Error: "+(n||""));case 2:throw new Error("THREE.RGBELoader: Write Error: "+(n||""));case 3:throw new Error("THREE.RGBELoader: Bad File Format: "+(n||""));default:case 4:throw new Error("THREE.RGBELoader: Memory Error: "+(n||""))}},f=` +`,h=function(r,n,o){n=n||1024;let m=r.pos,s=-1,a=0,d="",t=String.fromCharCode.apply(null,new Uint16Array(r.subarray(m,m+128)));for(;0>(s=t.indexOf(f))&&a=r.byteLength||!(d=h(r)))&&e(1,"no header found"),(t=d.match(n))||e(3,"bad initial token"),a.valid|=1,a.programtype=t[1],a.string+=d+` +`;d=h(r),d!==!1;){if(a.string+=d+` +`,d.charAt(0)==="#"){a.comments+=d+` +`;continue}if((t=d.match(o))&&(a.gamma=parseFloat(t[1])),(t=d.match(l))&&(a.exposure=parseFloat(t[1])),(t=d.match(m))&&(a.valid|=2,a.format=t[1]),(t=d.match(s))&&(a.valid|=4,a.height=parseInt(t[1],10),a.width=parseInt(t[2],10)),a.valid&2&&a.valid&4)break}return a.valid&2||e(3,"missing format specifier"),a.valid&4||e(3,"missing image size specifier"),a},S=function(r,n,o){const l=n;if(l<8||l>32767||r[0]!==2||r[1]!==2||r[2]&128)return new Uint8Array(r);l!==(r[2]<<8|r[3])&&e(3,"wrong scanline width");const m=new Uint8Array(4*n*o);m.length||e(4,"unable to allocate buffer space");let s=0,a=0;const d=4*l,t=new Uint8Array(4),C=new Uint8Array(d);let K=o;for(;K>0&&ar.byteLength&&e(1),t[0]=r[a++],t[1]=r[a++],t[2]=r[a++],t[3]=r[a++],(t[0]!=2||t[1]!=2||(t[2]<<8|t[3])!=l)&&e(3,"bad rgbe scanline format");let k=0,_;for(;k128;if(b&&(_-=128),(_===0||k+_>d)&&e(3,"bad scanline data"),b){const R=r[a++];for(let Q=0;Q<_;Q++)C[k++]=R}else C.set(r.subarray(a,a+_),k),k+=_,a+=_}const ae=l;for(let b=0;b=u+1e3&&(D.update(e*1e3/(f-u),100),u=f,e=0,A)){var h=performance.memory;A.update(h.usedJSHeapSize/1048576,h.jsHeapSizeLimit/1048576)}return f},update:function(){v=this.end()},domElement:c,setMode:g}};O.Panel=function(E,c,p){var g=1/0,v=0,u=Math.round,e=u(window.devicePixelRatio||1),D=80*e,L=48*e,A=3*e,f=2*e,h=3*e,w=15*e,S=74*e,x=30*e,I=document.createElement("canvas");I.width=D,I.height=L,I.style.cssText="width:80px;height:48px";var i=I.getContext("2d");return i.font="bold "+9*e+"px Helvetica,Arial,sans-serif",i.textBaseline="top",i.fillStyle=p,i.fillRect(0,0,D,L),i.fillStyle=c,i.fillText(E,A,f),i.fillRect(h,w,S,x),i.fillStyle=p,i.globalAlpha=.9,i.fillRect(h,w,S,x),{dom:I,update:function(y,z){g=Math.min(g,y),v=Math.max(v,y),i.fillStyle=p,i.globalAlpha=1,i.fillRect(0,0,D,w),i.fillStyle=c,i.fillText(u(y)+" "+E+" ("+u(g)+"-"+u(v)+")",A,f),i.drawImage(I,h+e,w,S-e,x,h,w,S-e,x),i.fillRect(h+S-e,w,e,x),i.fillStyle=p,i.globalAlpha=.9,i.fillRect(h+S-e,w,e,u((1-y/z)*x))}}};let U,F,P,G,Z,M,B,j,ee;const T={color:"#ffffff",bounces:3,ior:2.4,aberrationStrength:.01,fastChroma:!1,animate:!0};Se();async function Se(){U=new ie,F=new oe(75,window.innerWidth/window.innerHeight,.1,1e3),F.position.set(28,15,7),P=new le({antialias:!1}),P.setSize(window.innerWidth,window.innerHeight),P.toneMapping=ce,document.body.appendChild(P.domElement),Z=new ue(F,P.domElement),ee=new ve;const E=new De().loadAsync("https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/textures/equirectangular/venice_sunset_1k.hdr"),c=new ye().loadAsync("https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/diamond/diamond.glb");let p;[G,p]=await Promise.all([E,c]),G.mapping=se,G.generateMipmaps=!0,G.minFilter=me,G.magFilter=q,U.background=G;const g=new de({uniforms:{envMap:{value:G},bvh:{value:new be},projectionMatrixInv:{value:F.projectionMatrixInverse},viewMatrixInv:{value:F.matrixWorld},resolution:{value:new fe},bounces:{value:3},ior:{value:2.4},color:{value:new he(1,1,1)},fastChroma:{value:!1},aberrationStrength:{value:.01}},vertexShader:` + varying vec3 vWorldPosition; + varying vec3 vNormal; + uniform mat4 viewMatrixInv; + void main() { + + vWorldPosition = ( modelMatrix * vec4( position, 1.0 ) ).xyz; + vNormal = ( viewMatrixInv * vec4( normalMatrix * normal, 0.0 ) ).xyz; + gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4( position , 1.0 ); + + } + `,fragmentShader:` + #define RAY_OFFSET 0.001 + + #include + precision highp isampler2D; + precision highp usampler2D; + + ${Re} + ${Me} + ${Ee} + + varying vec3 vWorldPosition; + varying vec3 vNormal; + + uniform sampler2D envMap; + uniform float bounces; + uniform BVH bvh; + uniform float ior; + uniform vec3 color; + uniform bool fastChroma; + uniform mat4 projectionMatrixInv; + uniform mat4 viewMatrixInv; + uniform mat4 modelMatrix; + uniform vec2 resolution; + uniform float aberrationStrength; + + #include + + // performs an iterative bounce lookup modeling internal reflection and returns + // a final ray direction. + vec3 totalInternalReflection( vec3 incomingOrigin, vec3 incomingDirection, vec3 normal, float ior, mat4 modelMatrixInverse ) { + + vec3 rayOrigin = incomingOrigin; + vec3 rayDirection = incomingDirection; + + // refract the ray direction on the way into the diamond and adjust offset from + // the diamond surface for raytracing + rayDirection = refract( rayDirection, normal, 1.0 / ior ); + rayOrigin = vWorldPosition + rayDirection * RAY_OFFSET; + + // transform the ray into the local coordinates of the model + rayOrigin = ( modelMatrixInverse * vec4( rayOrigin, 1.0 ) ).xyz; + rayDirection = normalize( ( modelMatrixInverse * vec4( rayDirection, 0.0 ) ).xyz ); + + // perform multiple ray casts + for( float i = 0.0; i < bounces; i ++ ) { + + // results + uvec4 faceIndices = uvec4( 0u ); + vec3 faceNormal = vec3( 0.0, 0.0, 1.0 ); + vec3 barycoord = vec3( 0.0 ); + float side = 1.0; + float dist = 0.0; + + // perform the raycast + // the diamond is a water tight model so we assume we always hit a surface + bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist ); + + // derive the new ray origin from the hit results + vec3 hitPos = rayOrigin + rayDirection * dist; + + // if we don't internally reflect then end the ray tracing and sample + vec3 refractedDirection = refract( rayDirection, faceNormal, ior ); + bool totalInternalReflection = length( refract( rayDirection, faceNormal, ior ) ) == 0.0; + if ( ! totalInternalReflection ) { + + rayDirection = refractedDirection; + break; + + } + + // otherwise reflect off the surface internally for another hit + rayDirection = reflect( rayDirection, faceNormal ); + rayOrigin = hitPos + rayDirection * RAY_OFFSET; + + } + + // return the final ray direction in world space + return normalize( ( modelMatrix * vec4( rayDirection, 0.0 ) ).xyz ); + } + + vec4 envSample( sampler2D envMap, vec3 rayDirection ) { + + vec2 uvv = equirectUv( rayDirection ); + return texture( envMap, uvv ); + + } + + void main() { + + mat4 modelMatrixInverse = inverse( modelMatrix ); + vec2 uv = gl_FragCoord.xy / resolution; + + vec3 normal = vNormal; + vec3 rayOrigin = cameraPosition; + vec3 rayDirection = normalize( vWorldPosition - cameraPosition ); + + if ( aberrationStrength != 0.0 ) { + + // perform chromatic aberration lookups + vec3 rayDirectionG = totalInternalReflection( rayOrigin, rayDirection, normal, max( ior, 1.0 ), modelMatrixInverse ); + vec3 rayDirectionR, rayDirectionB; + + if ( fastChroma ) { + + // fast chroma does a quick uv offset on lookup + rayDirectionR = normalize( rayDirectionG + 1.0 * vec3( aberrationStrength / 2.0 ) ); + rayDirectionB = normalize( rayDirectionG - 1.0 * vec3( aberrationStrength / 2.0 ) ); + + } else { + + // compared to a proper ray trace of diffracted rays + float iorR = max( ior * ( 1.0 - aberrationStrength ), 1.0 ); + float iorB = max( ior * ( 1.0 + aberrationStrength ), 1.0 ); + rayDirectionR = totalInternalReflection( + rayOrigin, rayDirection, normal, + iorR, modelMatrixInverse + ); + rayDirectionB = totalInternalReflection( + rayOrigin, rayDirection, normal, + iorB, modelMatrixInverse + ); + + } + + // get the color lookup + float r = envSample( envMap, rayDirectionR ).r; + float g = envSample( envMap, rayDirectionG ).g; + float b = envSample( envMap, rayDirectionB ).b; + gl_FragColor.rgb = vec3( r, g, b ) * color; + gl_FragColor.a = 1.0; + + } else { + + // no chromatic aberration lookups + rayDirection = totalInternalReflection( rayOrigin, rayDirection, normal, max( ior, 1.0 ), modelMatrixInverse ); + gl_FragColor.rgb = envSample( envMap, rayDirection ).rgb * color; + gl_FragColor.a = 1.0; + + } + + #include + #include + + } + `}),v=p.scene.children[0].children[0].children[0].children[0].children[0].geometry;v.scale(10,10,10);const u=new we(v,{strategy:_e,maxLeafTris:1});g.uniforms.bvh.value.updateFrom(u),M=new pe(v,g),U.add(M),B=new ge,B.add(T,"animate"),B.addColor(T,"color").name("Color").onChange(e=>{M.material.uniforms.color.value.set(e)}),B.add(T,"bounces",1,10,1).name("Bounces").onChange(e=>{M.material.uniforms.bounces.value=e}),B.add(T,"ior",1,5,.01).name("IOR").onChange(e=>{M.material.uniforms.ior.value=e}),B.add(T,"fastChroma").onChange(e=>{M.material.uniforms.fastChroma.value=e}),B.add(T,"aberrationStrength",0,.1,1e-4).onChange(e=>{M.material.uniforms.aberrationStrength.value=e}),j=new O,j.showPanel(0),document.body.appendChild(j.dom),re(),window.addEventListener("resize",function(){F.aspect=window.innerWidth/window.innerHeight,F.updateProjectionMatrix(),M.material.uniforms.resolution.value.set(window.innerWidth,window.innerHeight),P.setSize(window.innerWidth,window.innerHeight)},!1)}function re(){T.animate&&(M.rotation.y+=ee.getDelta()*.25),j.update(),Z.update(),P.render(U,F),requestAnimationFrame(re)} diff --git a/example/bundle/assets/distancecast-BMV0TfDt.js b/example/bundle/assets/distancecast-BMV0TfDt.js new file mode 100644 index 000000000..1876269d1 --- /dev/null +++ b/example/bundle/assets/distancecast-BMV0TfDt.js @@ -0,0 +1 @@ +import{M as z1,i as a0,B as G1,u as I1,C as D1,W as d0,p as c0,c as x0,d as f0,D as h0,A as u0,s as v0,g as Q1,t as r0,P as p0,G as n0,l as m0,e as y0,f as w0,X as z0,O as A0,n as q1,V as M0}from"./ExtendedTriangle-CNpFv597.js";import{S as b0}from"./Stats-9dH8FB2H.js";import{g as g0}from"./lil-gui.module.min-Bc0DeA9g.js";import{O as C0}from"./OrbitControls-I50Ha_kb.js";import{T as F0}from"./TransformControls-xd0I7183.js";import{g as S0}from"./_commonjsHelpers-Cpj98o6Y.js";import{M as P0}from"./MeshBVHHelper-DbtlD37d.js";import{a as B0,c as D0,d as T0}from"./ExtensionUtilities-DGy5CKFv.js";import"./MeshBVH-ujCvfObx.js";class o0 extends z1{constructor(U,I,X=!1,Y=!1,D=1e4){const k=new a0;super(k,I);const e=this,T=new Float32Array(12*3),E=new Float32Array(12*3),R=new Float32Array(12*3);this.enableUvs=X,this.enableColors=Y,this.autoUpdate=!0,this.init=function(t){this.resolution=t,this.isolation=80,this.size=t,this.size2=this.size*this.size,this.size3=this.size2*this.size,this.halfsize=this.size/2,this.delta=2/this.size,this.yd=this.size,this.zd=this.size2,this.field=new Float32Array(this.size3),this.normal_cache=new Float32Array(this.size3*3),this.palette=new Float32Array(this.size3*3),this.count=0;const a=D*3;this.positionArray=new Float32Array(a*3);const r=new G1(this.positionArray,3);r.setUsage(I1),k.setAttribute("position",r),this.normalArray=new Float32Array(a*3);const s=new G1(this.normalArray,3);if(s.setUsage(I1),k.setAttribute("normal",s),this.enableUvs){this.uvArray=new Float32Array(a*2);const n=new G1(this.uvArray,2);n.setUsage(I1),k.setAttribute("uv",n)}if(this.enableColors){this.colorArray=new Float32Array(a*3);const n=new G1(this.colorArray,3);n.setUsage(I1),k.setAttribute("color",n)}};function C(t,a,r){return t+(a-t)*r}function p(t,a,r,s,n,o,i,c,l,f){const x=(r-i)/(c-i),u=e.normal_cache;T[a+0]=s+x*e.delta,T[a+1]=n,T[a+2]=o,E[a+0]=C(u[t+0],u[t+3],x),E[a+1]=C(u[t+1],u[t+4],x),E[a+2]=C(u[t+2],u[t+5],x),R[a+0]=C(e.palette[l*3+0],e.palette[f*3+0],x),R[a+1]=C(e.palette[l*3+1],e.palette[f*3+1],x),R[a+2]=C(e.palette[l*3+2],e.palette[f*3+2],x)}function h(t,a,r,s,n,o,i,c,l,f){const x=(r-i)/(c-i),u=e.normal_cache;T[a+0]=s,T[a+1]=n+x*e.delta,T[a+2]=o;const m=t+e.yd*3;E[a+0]=C(u[t+0],u[m+0],x),E[a+1]=C(u[t+1],u[m+1],x),E[a+2]=C(u[t+2],u[m+2],x),R[a+0]=C(e.palette[l*3+0],e.palette[f*3+0],x),R[a+1]=C(e.palette[l*3+1],e.palette[f*3+1],x),R[a+2]=C(e.palette[l*3+2],e.palette[f*3+2],x)}function w(t,a,r,s,n,o,i,c,l,f){const x=(r-i)/(c-i),u=e.normal_cache;T[a+0]=s,T[a+1]=n,T[a+2]=o+x*e.delta;const m=t+e.zd*3;E[a+0]=C(u[t+0],u[m+0],x),E[a+1]=C(u[t+1],u[m+1],x),E[a+2]=C(u[t+2],u[m+2],x),R[a+0]=C(e.palette[l*3+0],e.palette[f*3+0],x),R[a+1]=C(e.palette[l*3+1],e.palette[f*3+1],x),R[a+2]=C(e.palette[l*3+2],e.palette[f*3+2],x)}function v(t){const a=t*3;e.normal_cache[a]===0&&(e.normal_cache[a+0]=e.field[t-1]-e.field[t+1],e.normal_cache[a+1]=e.field[t-e.yd]-e.field[t+e.yd],e.normal_cache[a+2]=e.field[t-e.zd]-e.field[t+e.zd])}function d(t,a,r,s,n){const o=s+1,i=s+e.yd,c=s+e.zd,l=o+e.yd,f=o+e.zd,x=s+e.yd+e.zd,u=o+e.yd+e.zd;let m=0;const z=e.field[s],A=e.field[o],M=e.field[i],b=e.field[l],S=e.field[c],g=e.field[f],P=e.field[x],B=e.field[u];zthis.size-1&&(A=this.size-1);let M=Math.floor(u-f);M<1&&(M=1);let b=Math.floor(u+f);b>this.size-1&&(b=this.size-1);let S=Math.floor(m-f);S<1&&(S=1);let g=Math.floor(m+f);g>this.size-1&&(g=this.size-1);let P,B,F,W,V,H,L,N,J,K,Z;for(F=z;F0){this.field[W+P]+=Z*i;const G=Math.sqrt((P-m)*(P-m)+(B-u)*(B-u)+(F-x)*(F-x))/f,q=1-G*G*G*(G*(G*6-15)+10);this.palette[(W+P)*3+0]+=l.r*q,this.palette[(W+P)*3+1]+=l.g*q,this.palette[(W+P)*3+2]+=l.b*q}},this.addPlaneX=function(t,a){const r=this.size,s=this.yd,n=this.zd,o=this.field;let i,c,l,f,x,u,m,z=r*Math.sqrt(t/a);for(z>r&&(z=r),i=0;i0)for(c=0;cr&&(A=r),c=0;c0)for(m=c*s,i=0;ir&&(A=r),l=0;l0)for(m=n*l,c=0;c=s))for(let z=-1;z<=1;z+=2){const A=z+i;if(!(A<0||A>=s))for(let M=-1;M<=1;M+=2){const b=M+c;if(b<0||b>=s)continue;const S=n*b+s*A+m,g=r[S];x++,f+=t*(g-f)/x}}}a[l]=f}},this.reset=function(){for(let t=0;tD&&console.warn("THREE.MarchingCubes: Geometry buffers too small for rendering. Please create an instance with a higher poly count.")},this.onBeforeRender=function(){this.autoUpdate&&this.update()},this.init(U)}}o0.prototype.isMarchingCubes=!0;const W0=new Int32Array([0,265,515,778,1030,1295,1541,1804,2060,2309,2575,2822,3082,3331,3593,3840,400,153,915,666,1430,1183,1941,1692,2460,2197,2975,2710,3482,3219,3993,3728,560,825,51,314,1590,1855,1077,1340,2620,2869,2111,2358,3642,3891,3129,3376,928,681,419,170,1958,1711,1445,1196,2988,2725,2479,2214,4010,3747,3497,3232,1120,1385,1635,1898,102,367,613,876,3180,3429,3695,3942,2154,2403,2665,2912,1520,1273,2035,1786,502,255,1013,764,3580,3317,4095,3830,2554,2291,3065,2800,1616,1881,1107,1370,598,863,85,348,3676,3925,3167,3414,2650,2899,2137,2384,1984,1737,1475,1226,966,719,453,204,4044,3781,3535,3270,3018,2755,2505,2240,2240,2505,2755,3018,3270,3535,3781,4044,204,453,719,966,1226,1475,1737,1984,2384,2137,2899,2650,3414,3167,3925,3676,348,85,863,598,1370,1107,1881,1616,2800,3065,2291,2554,3830,4095,3317,3580,764,1013,255,502,1786,2035,1273,1520,2912,2665,2403,2154,3942,3695,3429,3180,876,613,367,102,1898,1635,1385,1120,3232,3497,3747,4010,2214,2479,2725,2988,1196,1445,1711,1958,170,419,681,928,3376,3129,3891,3642,2358,2111,2869,2620,1340,1077,1855,1590,314,51,825,560,3728,3993,3219,3482,2710,2975,2197,2460,1692,1941,1183,1430,666,915,153,400,3840,3593,3331,3082,2822,2575,2309,2060,1804,1541,1295,1030,778,515,265,0]),R1=new Int32Array([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,8,3,9,8,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,1,2,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,2,10,0,2,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,8,3,2,10,8,10,9,8,-1,-1,-1,-1,-1,-1,-1,3,11,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,11,2,8,11,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,9,0,2,3,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,11,2,1,9,11,9,8,11,-1,-1,-1,-1,-1,-1,-1,3,10,1,11,10,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,10,1,0,8,10,8,11,10,-1,-1,-1,-1,-1,-1,-1,3,9,0,3,11,9,11,10,9,-1,-1,-1,-1,-1,-1,-1,9,8,10,10,8,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,7,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,3,0,7,3,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,8,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,1,9,4,7,1,7,3,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,8,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,4,7,3,0,4,1,2,10,-1,-1,-1,-1,-1,-1,-1,9,2,10,9,0,2,8,4,7,-1,-1,-1,-1,-1,-1,-1,2,10,9,2,9,7,2,7,3,7,9,4,-1,-1,-1,-1,8,4,7,3,11,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,4,7,11,2,4,2,0,4,-1,-1,-1,-1,-1,-1,-1,9,0,1,8,4,7,2,3,11,-1,-1,-1,-1,-1,-1,-1,4,7,11,9,4,11,9,11,2,9,2,1,-1,-1,-1,-1,3,10,1,3,11,10,7,8,4,-1,-1,-1,-1,-1,-1,-1,1,11,10,1,4,11,1,0,4,7,11,4,-1,-1,-1,-1,4,7,8,9,0,11,9,11,10,11,0,3,-1,-1,-1,-1,4,7,11,4,11,9,9,11,10,-1,-1,-1,-1,-1,-1,-1,9,5,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,5,4,0,8,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,5,4,1,5,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,5,4,8,3,5,3,1,5,-1,-1,-1,-1,-1,-1,-1,1,2,10,9,5,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,8,1,2,10,4,9,5,-1,-1,-1,-1,-1,-1,-1,5,2,10,5,4,2,4,0,2,-1,-1,-1,-1,-1,-1,-1,2,10,5,3,2,5,3,5,4,3,4,8,-1,-1,-1,-1,9,5,4,2,3,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,11,2,0,8,11,4,9,5,-1,-1,-1,-1,-1,-1,-1,0,5,4,0,1,5,2,3,11,-1,-1,-1,-1,-1,-1,-1,2,1,5,2,5,8,2,8,11,4,8,5,-1,-1,-1,-1,10,3,11,10,1,3,9,5,4,-1,-1,-1,-1,-1,-1,-1,4,9,5,0,8,1,8,10,1,8,11,10,-1,-1,-1,-1,5,4,0,5,0,11,5,11,10,11,0,3,-1,-1,-1,-1,5,4,8,5,8,10,10,8,11,-1,-1,-1,-1,-1,-1,-1,9,7,8,5,7,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,3,0,9,5,3,5,7,3,-1,-1,-1,-1,-1,-1,-1,0,7,8,0,1,7,1,5,7,-1,-1,-1,-1,-1,-1,-1,1,5,3,3,5,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,7,8,9,5,7,10,1,2,-1,-1,-1,-1,-1,-1,-1,10,1,2,9,5,0,5,3,0,5,7,3,-1,-1,-1,-1,8,0,2,8,2,5,8,5,7,10,5,2,-1,-1,-1,-1,2,10,5,2,5,3,3,5,7,-1,-1,-1,-1,-1,-1,-1,7,9,5,7,8,9,3,11,2,-1,-1,-1,-1,-1,-1,-1,9,5,7,9,7,2,9,2,0,2,7,11,-1,-1,-1,-1,2,3,11,0,1,8,1,7,8,1,5,7,-1,-1,-1,-1,11,2,1,11,1,7,7,1,5,-1,-1,-1,-1,-1,-1,-1,9,5,8,8,5,7,10,1,3,10,3,11,-1,-1,-1,-1,5,7,0,5,0,9,7,11,0,1,0,10,11,10,0,-1,11,10,0,11,0,3,10,5,0,8,0,7,5,7,0,-1,11,10,5,7,11,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,6,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,5,10,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,0,1,5,10,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,8,3,1,9,8,5,10,6,-1,-1,-1,-1,-1,-1,-1,1,6,5,2,6,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,6,5,1,2,6,3,0,8,-1,-1,-1,-1,-1,-1,-1,9,6,5,9,0,6,0,2,6,-1,-1,-1,-1,-1,-1,-1,5,9,8,5,8,2,5,2,6,3,2,8,-1,-1,-1,-1,2,3,11,10,6,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,0,8,11,2,0,10,6,5,-1,-1,-1,-1,-1,-1,-1,0,1,9,2,3,11,5,10,6,-1,-1,-1,-1,-1,-1,-1,5,10,6,1,9,2,9,11,2,9,8,11,-1,-1,-1,-1,6,3,11,6,5,3,5,1,3,-1,-1,-1,-1,-1,-1,-1,0,8,11,0,11,5,0,5,1,5,11,6,-1,-1,-1,-1,3,11,6,0,3,6,0,6,5,0,5,9,-1,-1,-1,-1,6,5,9,6,9,11,11,9,8,-1,-1,-1,-1,-1,-1,-1,5,10,6,4,7,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,3,0,4,7,3,6,5,10,-1,-1,-1,-1,-1,-1,-1,1,9,0,5,10,6,8,4,7,-1,-1,-1,-1,-1,-1,-1,10,6,5,1,9,7,1,7,3,7,9,4,-1,-1,-1,-1,6,1,2,6,5,1,4,7,8,-1,-1,-1,-1,-1,-1,-1,1,2,5,5,2,6,3,0,4,3,4,7,-1,-1,-1,-1,8,4,7,9,0,5,0,6,5,0,2,6,-1,-1,-1,-1,7,3,9,7,9,4,3,2,9,5,9,6,2,6,9,-1,3,11,2,7,8,4,10,6,5,-1,-1,-1,-1,-1,-1,-1,5,10,6,4,7,2,4,2,0,2,7,11,-1,-1,-1,-1,0,1,9,4,7,8,2,3,11,5,10,6,-1,-1,-1,-1,9,2,1,9,11,2,9,4,11,7,11,4,5,10,6,-1,8,4,7,3,11,5,3,5,1,5,11,6,-1,-1,-1,-1,5,1,11,5,11,6,1,0,11,7,11,4,0,4,11,-1,0,5,9,0,6,5,0,3,6,11,6,3,8,4,7,-1,6,5,9,6,9,11,4,7,9,7,11,9,-1,-1,-1,-1,10,4,9,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,10,6,4,9,10,0,8,3,-1,-1,-1,-1,-1,-1,-1,10,0,1,10,6,0,6,4,0,-1,-1,-1,-1,-1,-1,-1,8,3,1,8,1,6,8,6,4,6,1,10,-1,-1,-1,-1,1,4,9,1,2,4,2,6,4,-1,-1,-1,-1,-1,-1,-1,3,0,8,1,2,9,2,4,9,2,6,4,-1,-1,-1,-1,0,2,4,4,2,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,3,2,8,2,4,4,2,6,-1,-1,-1,-1,-1,-1,-1,10,4,9,10,6,4,11,2,3,-1,-1,-1,-1,-1,-1,-1,0,8,2,2,8,11,4,9,10,4,10,6,-1,-1,-1,-1,3,11,2,0,1,6,0,6,4,6,1,10,-1,-1,-1,-1,6,4,1,6,1,10,4,8,1,2,1,11,8,11,1,-1,9,6,4,9,3,6,9,1,3,11,6,3,-1,-1,-1,-1,8,11,1,8,1,0,11,6,1,9,1,4,6,4,1,-1,3,11,6,3,6,0,0,6,4,-1,-1,-1,-1,-1,-1,-1,6,4,8,11,6,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,10,6,7,8,10,8,9,10,-1,-1,-1,-1,-1,-1,-1,0,7,3,0,10,7,0,9,10,6,7,10,-1,-1,-1,-1,10,6,7,1,10,7,1,7,8,1,8,0,-1,-1,-1,-1,10,6,7,10,7,1,1,7,3,-1,-1,-1,-1,-1,-1,-1,1,2,6,1,6,8,1,8,9,8,6,7,-1,-1,-1,-1,2,6,9,2,9,1,6,7,9,0,9,3,7,3,9,-1,7,8,0,7,0,6,6,0,2,-1,-1,-1,-1,-1,-1,-1,7,3,2,6,7,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,11,10,6,8,10,8,9,8,6,7,-1,-1,-1,-1,2,0,7,2,7,11,0,9,7,6,7,10,9,10,7,-1,1,8,0,1,7,8,1,10,7,6,7,10,2,3,11,-1,11,2,1,11,1,7,10,6,1,6,7,1,-1,-1,-1,-1,8,9,6,8,6,7,9,1,6,11,6,3,1,3,6,-1,0,9,1,11,6,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,8,0,7,0,6,3,11,0,11,6,0,-1,-1,-1,-1,7,11,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,6,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,8,11,7,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,11,7,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,1,9,8,3,1,11,7,6,-1,-1,-1,-1,-1,-1,-1,10,1,2,6,11,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,10,3,0,8,6,11,7,-1,-1,-1,-1,-1,-1,-1,2,9,0,2,10,9,6,11,7,-1,-1,-1,-1,-1,-1,-1,6,11,7,2,10,3,10,8,3,10,9,8,-1,-1,-1,-1,7,2,3,6,2,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,0,8,7,6,0,6,2,0,-1,-1,-1,-1,-1,-1,-1,2,7,6,2,3,7,0,1,9,-1,-1,-1,-1,-1,-1,-1,1,6,2,1,8,6,1,9,8,8,7,6,-1,-1,-1,-1,10,7,6,10,1,7,1,3,7,-1,-1,-1,-1,-1,-1,-1,10,7,6,1,7,10,1,8,7,1,0,8,-1,-1,-1,-1,0,3,7,0,7,10,0,10,9,6,10,7,-1,-1,-1,-1,7,6,10,7,10,8,8,10,9,-1,-1,-1,-1,-1,-1,-1,6,8,4,11,8,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,6,11,3,0,6,0,4,6,-1,-1,-1,-1,-1,-1,-1,8,6,11,8,4,6,9,0,1,-1,-1,-1,-1,-1,-1,-1,9,4,6,9,6,3,9,3,1,11,3,6,-1,-1,-1,-1,6,8,4,6,11,8,2,10,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,3,0,11,0,6,11,0,4,6,-1,-1,-1,-1,4,11,8,4,6,11,0,2,9,2,10,9,-1,-1,-1,-1,10,9,3,10,3,2,9,4,3,11,3,6,4,6,3,-1,8,2,3,8,4,2,4,6,2,-1,-1,-1,-1,-1,-1,-1,0,4,2,4,6,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,9,0,2,3,4,2,4,6,4,3,8,-1,-1,-1,-1,1,9,4,1,4,2,2,4,6,-1,-1,-1,-1,-1,-1,-1,8,1,3,8,6,1,8,4,6,6,10,1,-1,-1,-1,-1,10,1,0,10,0,6,6,0,4,-1,-1,-1,-1,-1,-1,-1,4,6,3,4,3,8,6,10,3,0,3,9,10,9,3,-1,10,9,4,6,10,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,9,5,7,6,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,4,9,5,11,7,6,-1,-1,-1,-1,-1,-1,-1,5,0,1,5,4,0,7,6,11,-1,-1,-1,-1,-1,-1,-1,11,7,6,8,3,4,3,5,4,3,1,5,-1,-1,-1,-1,9,5,4,10,1,2,7,6,11,-1,-1,-1,-1,-1,-1,-1,6,11,7,1,2,10,0,8,3,4,9,5,-1,-1,-1,-1,7,6,11,5,4,10,4,2,10,4,0,2,-1,-1,-1,-1,3,4,8,3,5,4,3,2,5,10,5,2,11,7,6,-1,7,2,3,7,6,2,5,4,9,-1,-1,-1,-1,-1,-1,-1,9,5,4,0,8,6,0,6,2,6,8,7,-1,-1,-1,-1,3,6,2,3,7,6,1,5,0,5,4,0,-1,-1,-1,-1,6,2,8,6,8,7,2,1,8,4,8,5,1,5,8,-1,9,5,4,10,1,6,1,7,6,1,3,7,-1,-1,-1,-1,1,6,10,1,7,6,1,0,7,8,7,0,9,5,4,-1,4,0,10,4,10,5,0,3,10,6,10,7,3,7,10,-1,7,6,10,7,10,8,5,4,10,4,8,10,-1,-1,-1,-1,6,9,5,6,11,9,11,8,9,-1,-1,-1,-1,-1,-1,-1,3,6,11,0,6,3,0,5,6,0,9,5,-1,-1,-1,-1,0,11,8,0,5,11,0,1,5,5,6,11,-1,-1,-1,-1,6,11,3,6,3,5,5,3,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,9,5,11,9,11,8,11,5,6,-1,-1,-1,-1,0,11,3,0,6,11,0,9,6,5,6,9,1,2,10,-1,11,8,5,11,5,6,8,0,5,10,5,2,0,2,5,-1,6,11,3,6,3,5,2,10,3,10,5,3,-1,-1,-1,-1,5,8,9,5,2,8,5,6,2,3,8,2,-1,-1,-1,-1,9,5,6,9,6,0,0,6,2,-1,-1,-1,-1,-1,-1,-1,1,5,8,1,8,0,5,6,8,3,8,2,6,2,8,-1,1,5,6,2,1,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,3,6,1,6,10,3,8,6,5,6,9,8,9,6,-1,10,1,0,10,0,6,9,5,0,5,6,0,-1,-1,-1,-1,0,3,8,5,6,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,5,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,5,10,7,5,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,5,10,11,7,5,8,3,0,-1,-1,-1,-1,-1,-1,-1,5,11,7,5,10,11,1,9,0,-1,-1,-1,-1,-1,-1,-1,10,7,5,10,11,7,9,8,1,8,3,1,-1,-1,-1,-1,11,1,2,11,7,1,7,5,1,-1,-1,-1,-1,-1,-1,-1,0,8,3,1,2,7,1,7,5,7,2,11,-1,-1,-1,-1,9,7,5,9,2,7,9,0,2,2,11,7,-1,-1,-1,-1,7,5,2,7,2,11,5,9,2,3,2,8,9,8,2,-1,2,5,10,2,3,5,3,7,5,-1,-1,-1,-1,-1,-1,-1,8,2,0,8,5,2,8,7,5,10,2,5,-1,-1,-1,-1,9,0,1,5,10,3,5,3,7,3,10,2,-1,-1,-1,-1,9,8,2,9,2,1,8,7,2,10,2,5,7,5,2,-1,1,3,5,3,7,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,7,0,7,1,1,7,5,-1,-1,-1,-1,-1,-1,-1,9,0,3,9,3,5,5,3,7,-1,-1,-1,-1,-1,-1,-1,9,8,7,5,9,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,5,8,4,5,10,8,10,11,8,-1,-1,-1,-1,-1,-1,-1,5,0,4,5,11,0,5,10,11,11,3,0,-1,-1,-1,-1,0,1,9,8,4,10,8,10,11,10,4,5,-1,-1,-1,-1,10,11,4,10,4,5,11,3,4,9,4,1,3,1,4,-1,2,5,1,2,8,5,2,11,8,4,5,8,-1,-1,-1,-1,0,4,11,0,11,3,4,5,11,2,11,1,5,1,11,-1,0,2,5,0,5,9,2,11,5,4,5,8,11,8,5,-1,9,4,5,2,11,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,5,10,3,5,2,3,4,5,3,8,4,-1,-1,-1,-1,5,10,2,5,2,4,4,2,0,-1,-1,-1,-1,-1,-1,-1,3,10,2,3,5,10,3,8,5,4,5,8,0,1,9,-1,5,10,2,5,2,4,1,9,2,9,4,2,-1,-1,-1,-1,8,4,5,8,5,3,3,5,1,-1,-1,-1,-1,-1,-1,-1,0,4,5,1,0,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,4,5,8,5,3,9,0,5,0,3,5,-1,-1,-1,-1,9,4,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,11,7,4,9,11,9,10,11,-1,-1,-1,-1,-1,-1,-1,0,8,3,4,9,7,9,11,7,9,10,11,-1,-1,-1,-1,1,10,11,1,11,4,1,4,0,7,4,11,-1,-1,-1,-1,3,1,4,3,4,8,1,10,4,7,4,11,10,11,4,-1,4,11,7,9,11,4,9,2,11,9,1,2,-1,-1,-1,-1,9,7,4,9,11,7,9,1,11,2,11,1,0,8,3,-1,11,7,4,11,4,2,2,4,0,-1,-1,-1,-1,-1,-1,-1,11,7,4,11,4,2,8,3,4,3,2,4,-1,-1,-1,-1,2,9,10,2,7,9,2,3,7,7,4,9,-1,-1,-1,-1,9,10,7,9,7,4,10,2,7,8,7,0,2,0,7,-1,3,7,10,3,10,2,7,4,10,1,10,0,4,0,10,-1,1,10,2,8,7,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,9,1,4,1,7,7,1,3,-1,-1,-1,-1,-1,-1,-1,4,9,1,4,1,7,0,8,1,8,7,1,-1,-1,-1,-1,4,0,3,7,4,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,8,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,10,8,10,11,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,9,3,9,11,11,9,10,-1,-1,-1,-1,-1,-1,-1,0,1,10,0,10,8,8,10,11,-1,-1,-1,-1,-1,-1,-1,3,1,10,11,3,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,11,1,11,9,9,11,8,-1,-1,-1,-1,-1,-1,-1,3,0,9,3,9,11,1,2,9,2,11,9,-1,-1,-1,-1,0,2,11,8,0,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,2,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,8,2,8,10,10,8,9,-1,-1,-1,-1,-1,-1,-1,9,10,2,0,9,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,8,2,8,10,0,1,8,1,10,8,-1,-1,-1,-1,1,10,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,3,8,9,1,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,9,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,3,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]);var e0={exports:{}};(function($,U){(function(){var I=.5*(Math.sqrt(3)-1),X=(3-Math.sqrt(3))/6,Y=1/3,D=1/6,k=(Math.sqrt(5)-1)/4,e=(5-Math.sqrt(5))/20;function T(p){var h;typeof p=="function"?h=p:p?h=R(p):h=Math.random,this.p=E(h),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(var w=0;w<512;w++)this.perm[w]=this.p[w&255],this.permMod12[w]=this.perm[w]%12}T.prototype={grad3:new Float32Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]),grad4:new Float32Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]),noise2D:function(p,h){var w=this.permMod12,v=this.perm,d=this.grad3,y=0,t=0,a=0,r=(p+h)*I,s=Math.floor(p+r),n=Math.floor(h+r),o=(s+n)*X,i=s-o,c=n-o,l=p-i,f=h-c,x,u;l>f?(x=1,u=0):(x=0,u=1);var m=l-x+X,z=f-u+X,A=l-1+2*X,M=f-1+2*X,b=s&255,S=n&255,g=.5-l*l-f*f;if(g>=0){var P=w[b+v[S]]*3;g*=g,y=g*g*(d[P]*l+d[P+1]*f)}var B=.5-m*m-z*z;if(B>=0){var F=w[b+x+v[S+u]]*3;B*=B,t=B*B*(d[F]*m+d[F+1]*z)}var W=.5-A*A-M*M;if(W>=0){var V=w[b+1+v[S+1]]*3;W*=W,a=W*W*(d[V]*A+d[V+1]*M)}return 70*(y+t+a)},noise3D:function(p,h,w){var v=this.permMod12,d=this.perm,y=this.grad3,t,a,r,s,n=(p+h+w)*Y,o=Math.floor(p+n),i=Math.floor(h+n),c=Math.floor(w+n),l=(o+i+c)*D,f=o-l,x=i-l,u=c-l,m=p-f,z=h-x,A=w-u,M,b,S,g,P,B;m>=z?z>=A?(M=1,b=0,S=0,g=1,P=1,B=0):m>=A?(M=1,b=0,S=0,g=1,P=0,B=1):(M=0,b=0,S=1,g=1,P=0,B=1):zb?P++:B++,M>S?P++:F++,M>g?P++:W++,b>S?B++:F++,b>g?B++:W++,S>g?F++:W++;var V,H,L,N,J,K,Z,G,q,c1,n1,u1;V=P>=3?1:0,H=B>=3?1:0,L=F>=3?1:0,N=W>=3?1:0,J=P>=2?1:0,K=B>=2?1:0,Z=F>=2?1:0,G=W>=2?1:0,q=P>=1?1:0,c1=B>=1?1:0,n1=F>=1?1:0,u1=W>=1?1:0;var s1=M-V+e,v1=b-H+e,o1=S-L+e,p1=g-N+e,l1=M-J+2*e,m1=b-K+2*e,H1=S-Z+2*e,L1=g-G+2*e,N1=M-q+3*e,O1=b-c1+3*e,X1=S-n1+3*e,Y1=g-u1+3*e,Z1=M-1+4*e,$1=b-1+4*e,J1=S-1+4*e,K1=g-1+4*e,A1=i&255,M1=c&255,b1=l&255,g1=f&255,C1=.6-M*M-b*b-S*S-g*g;if(C1<0)t=0;else{var W1=d[A1+d[M1+d[b1+d[g1]]]]%32*4;C1*=C1,t=C1*C1*(y[W1]*M+y[W1+1]*b+y[W1+2]*S+y[W1+3]*g)}var F1=.6-s1*s1-v1*v1-o1*o1-p1*p1;if(F1<0)a=0;else{var k1=d[A1+V+d[M1+H+d[b1+L+d[g1+N]]]]%32*4;F1*=F1,a=F1*F1*(y[k1]*s1+y[k1+1]*v1+y[k1+2]*o1+y[k1+3]*p1)}var S1=.6-l1*l1-m1*m1-H1*H1-L1*L1;if(S1<0)r=0;else{var E1=d[A1+J+d[M1+K+d[b1+Z+d[g1+G]]]]%32*4;S1*=S1,r=S1*S1*(y[E1]*l1+y[E1+1]*m1+y[E1+2]*H1+y[E1+3]*L1)}var P1=.6-N1*N1-O1*O1-X1*X1-Y1*Y1;if(P1<0)s=0;else{var j1=d[A1+q+d[M1+c1+d[b1+n1+d[g1+u1]]]]%32*4;P1*=P1,s=P1*P1*(y[j1]*N1+y[j1+1]*O1+y[j1+2]*X1+y[j1+3]*Y1)}var B1=.6-Z1*Z1-$1*$1-J1*J1-K1*K1;if(B1<0)n=0;else{var U1=d[A1+1+d[M1+1+d[b1+1+d[g1+1]]]]%32*4;B1*=B1,n=B1*B1*(y[U1]*Z1+y[U1+1]*$1+y[U1+2]*J1+y[U1+3]*K1)}return 27*(t+a+r+s+n)}};function E(p){var h,w=new Uint8Array(256);for(h=0;h<256;h++)w[h]=h;for(h=0;h<255;h++){var v=h+~~(p()*(256-h)),d=w[h];w[h]=w[v],w[v]=d}return w}T._buildPermutationTable=E;function R(){var p=0,h=0,w=0,v=1,d=C();p=d(" "),h=d(" "),w=d(" ");for(var y=0;y>>0,v-=p,v*=p,p=v>>>0,v-=p,p+=v*4294967296}return(p>>>0)*23283064365386963e-26}}U.SimplexNoise=T,$.exports=T})()})(e0,e0.exports);var k0=e0.exports;const E0=S0(k0);z1.prototype.raycast=B0;a0.prototype.computeBoundsTree=D0;a0.prototype.disposeBoundsTree=T0;const j={visualizeBounds:!1,visualBoundsDepth:10,volume:{display:1,hideWhileGenerating:!1,alwaysShowDistance:!0,surfaceOnly:!1,distance:1,resolution:100,radius:4},displayClosestPoint:!0};let V1,O,d1,t1,s0,i1,e1,Q,a1,x1,_,h1,r1,f1,w1,_1=!1;function j0(){t1=new d0({antialias:!0}),t1.setPixelRatio(window.devicePixelRatio),t1.setSize(window.innerWidth,window.innerHeight),t1.setClearColor(1251612,1),t1.shadowMap.enabled=!0,t1.shadowMap.type=c0,document.body.appendChild(t1.domElement),O=new x0,O.fog=new f0(2503224/2,10,45);const U=new h0(16777215,1.5);U.position.set(20,20,20),U.castShadow=!0,U.shadow.mapSize.set(2048,2048);const I=U.shadow.camera;I.left=I.bottom=-15,I.right=I.top=15,I.updateProjectionMatrix(),O.add(U),O.add(new u0(14743546,1.5));const X=50,Y=250,D=new v0(X,X,Y-1,Y-1),k=D.attributes.position,e=Math.floor(Math.random()*100),T=new E0(e);for(let d=0;d{s0.enabled=!d.value,d.value||(_1=!0)}),x1.addEventListener("objectChange",d=>{_1=!0}),O.add(x1);const R=new Q1({flatShading:!0,color:15277667,metalness:0,roughness:.35,transparent:!0,depthWrite:!1,opacity:.15,premultipliedAlpha:!0,side:r0});_=new o0(100,R,!1,!1,1e6),_.isolation=0,_.autoUpdate=!1,h1=new n0,h1.scale.multiplyScalar(5),h1.add(_),O.add(h1),r1=new z1(new y0(.025,20,20),new w0({color:15277667})),r1.castShadow=!0,O.add(r1),f1=r1.clone(),f1.castShadow=!0,O.add(f1);const C=new z1(new z0,r1.material);C.castShadow=!0,C.position.z=.5,w1=new A0,w1.add(C),O.add(w1),O.updateMatrixWorld(!0);const p=new g0({width:300});p.add(j,"visualizeBounds").onChange(()=>t0()),p.add(j,"visualBoundsDepth").min(1).max(40).step(1).onChange(()=>t0());const h=p.addFolder("distanceVisualization");h.add(j.volume,"display",{hide:0,"distance to terrain":1,"distance to mesh":2}).onChange(()=>{y1=!0}),h.add(j.volume,"hideWhileGenerating"),h.add(j.volume,"alwaysShowDistance"),h.add(j.volume,"surfaceOnly").onChange(()=>y1=!0),h.add(j.volume,"distance").min(0).max(2).step(.01).onChange(()=>y1=!0),h.add(j.volume,"radius").min(1).max(20).onChange(()=>y1=!0),h.add(j.volume,"resolution",5,200,1).onChange(()=>y1=!0),h.open(),p.add(x1,"mode",["translate","rotate"]);const w=p.addFolder("position");w.add(Q.position,"x").min(-5).max(5).step(.001).listen(),w.add(Q.position,"y").min(-5).max(5).step(.001).listen(),w.add(Q.position,"z").min(-5).max(5).step(.001).listen();const v=p.addFolder("rotation");v.add(Q.rotation,"x").min(-Math.PI).max(Math.PI).step(.001).listen(),v.add(Q.rotation,"y").min(-Math.PI).max(Math.PI).step(.001).listen(),v.add(Q.rotation,"z").min(-Math.PI).max(Math.PI).step(.001).listen(),p.open(),i0(),window.addEventListener("resize",function(){d1.aspect=window.innerWidth/window.innerHeight,d1.updateProjectionMatrix(),t1.setSize(window.innerWidth,window.innerHeight)},!1),window.addEventListener("keydown",function(d){switch(d.key){case"w":x1.mode="translate";break;case"e":x1.mode="rotate";break}p.controllersRecursive().forEach(y=>y.updateDisplay())})}function t0(){i1&&!j.visualizeBounds&&(O.remove(i1),i1=null),!i1&&j.visualizeBounds&&(i1=new P0(e1),O.add(i1)),i1&&(i1.depth=j.visualBoundsDepth)}function i0($){Q.updateMatrixWorld();const U=new q1().copy(e1.matrixWorld).invert().multiply(Q.matrixWorld),I=j.volume.distance,X=I,Y=$?I:0,D={},k={},T=!!e1.geometry.boundsTree.closestPointToGeometry(a1.geometry,U,D,k,Y,X)&&D.distance>8&255]+D[l>>16&255]+D[l>>24&255]+"-"+D[t&255]+D[t>>8&255]+"-"+D[t>>16&15|64]+D[t>>24&255]+"-"+D[i&63|128]+D[i>>8&255]+"-"+D[i>>16&255]+D[i>>24&255]+D[s&255]+D[s>>8&255]+D[s>>16&255]+D[s>>24&255]).toLowerCase()}function at(l,t,i){return Math.max(t,Math.min(i,l))}function Kt(l,t){switch(t.constructor){case Float32Array:return l;case Uint32Array:return l/4294967295;case Uint16Array:return l/65535;case Uint8Array:return l/255;case Int32Array:return Math.max(l/2147483647,-1);case Int16Array:return Math.max(l/32767,-1);case Int8Array:return Math.max(l/127,-1);default:throw new Error("Invalid component type.")}}function O(l,t){switch(t.constructor){case Float32Array:return l;case Uint32Array:return Math.round(l*4294967295);case Uint16Array:return Math.round(l*65535);case Uint8Array:return Math.round(l*255);case Int32Array:return Math.round(l*2147483647);case Int16Array:return Math.round(l*32767);case Int8Array:return Math.round(l*127);default:throw new Error("Invalid component type.")}}class X{constructor(t=0,i=0){X.prototype.isVector2=!0,this.x=t,this.y=i}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,i){return this.x=t,this.y=i,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,i){switch(t){case 0:this.x=i;break;case 1:this.y=i;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,i){return this.x=t.x+i.x,this.y=t.y+i.y,this}addScaledVector(t,i){return this.x+=t.x*i,this.y+=t.y*i,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,i){return this.x=t.x-i.x,this.y=t.y-i.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const i=this.x,s=this.y,e=t.elements;return this.x=e[0]*i+e[3]*s+e[6],this.y=e[1]*i+e[4]*s+e[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,i){return this.x=Math.max(t.x,Math.min(i.x,this.x)),this.y=Math.max(t.y,Math.min(i.y,this.y)),this}clampScalar(t,i){return this.x=Math.max(t,Math.min(i,this.x)),this.y=Math.max(t,Math.min(i,this.y)),this}clampLength(t,i){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(i,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const i=Math.sqrt(this.lengthSq()*t.lengthSq());if(i===0)return Math.PI/2;const s=this.dot(t)/i;return Math.acos(at(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const i=this.x-t.x,s=this.y-t.y;return i*i+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,i){return this.x+=(t.x-this.x)*i,this.y+=(t.y-this.y)*i,this}lerpVectors(t,i,s){return this.x=t.x+(i.x-t.x)*s,this.y=t.y+(i.y-t.y)*s,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,i=0){return this.x=t[i],this.y=t[i+1],this}toArray(t=[],i=0){return t[i]=this.x,t[i+1]=this.y,t}fromBufferAttribute(t,i){return this.x=t.getX(i),this.y=t.getY(i),this}rotateAround(t,i){const s=Math.cos(i),e=Math.sin(i),n=this.x-t.x,r=this.y-t.y;return this.x=n*s-r*e+t.x,this.y=n*e+r*s+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class ut{constructor(t,i,s,e,n,r,a,o,c){ut.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,i,s,e,n,r,a,o,c)}set(t,i,s,e,n,r,a,o,c){const h=this.elements;return h[0]=t,h[1]=e,h[2]=a,h[3]=i,h[4]=n,h[5]=o,h[6]=s,h[7]=r,h[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const i=this.elements,s=t.elements;return i[0]=s[0],i[1]=s[1],i[2]=s[2],i[3]=s[3],i[4]=s[4],i[5]=s[5],i[6]=s[6],i[7]=s[7],i[8]=s[8],this}extractBasis(t,i,s){return t.setFromMatrix3Column(this,0),i.setFromMatrix3Column(this,1),s.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const i=t.elements;return this.set(i[0],i[4],i[8],i[1],i[5],i[9],i[2],i[6],i[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,i){const s=t.elements,e=i.elements,n=this.elements,r=s[0],a=s[3],o=s[6],c=s[1],h=s[4],f=s[7],u=s[2],d=s[5],m=s[8],y=e[0],x=e[3],p=e[6],g=e[1],b=e[4],M=e[7],w=e[2],A=e[5],_=e[8];return n[0]=r*y+a*g+o*w,n[3]=r*x+a*b+o*A,n[6]=r*p+a*M+o*_,n[1]=c*y+h*g+f*w,n[4]=c*x+h*b+f*A,n[7]=c*p+h*M+f*_,n[2]=u*y+d*g+m*w,n[5]=u*x+d*b+m*A,n[8]=u*p+d*M+m*_,this}multiplyScalar(t){const i=this.elements;return i[0]*=t,i[3]*=t,i[6]*=t,i[1]*=t,i[4]*=t,i[7]*=t,i[2]*=t,i[5]*=t,i[8]*=t,this}determinant(){const t=this.elements,i=t[0],s=t[1],e=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8];return i*r*h-i*a*c-s*n*h+s*a*o+e*n*c-e*r*o}invert(){const t=this.elements,i=t[0],s=t[1],e=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8],f=h*r-a*c,u=a*o-h*n,d=c*n-r*o,m=i*f+s*u+e*d;if(m===0)return this.set(0,0,0,0,0,0,0,0,0);const y=1/m;return t[0]=f*y,t[1]=(e*c-h*s)*y,t[2]=(a*s-e*r)*y,t[3]=u*y,t[4]=(h*i-e*o)*y,t[5]=(e*n-a*i)*y,t[6]=d*y,t[7]=(s*o-c*i)*y,t[8]=(r*i-s*n)*y,this}transpose(){let t;const i=this.elements;return t=i[1],i[1]=i[3],i[3]=t,t=i[2],i[2]=i[6],i[6]=t,t=i[5],i[5]=i[7],i[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const i=this.elements;return t[0]=i[0],t[1]=i[3],t[2]=i[6],t[3]=i[1],t[4]=i[4],t[5]=i[7],t[6]=i[2],t[7]=i[5],t[8]=i[8],this}setUvTransform(t,i,s,e,n,r,a){const o=Math.cos(n),c=Math.sin(n);return this.set(s*o,s*c,-s*(o*r+c*a)+r+t,-e*c,e*o,-e*(-c*r+o*a)+a+i,0,0,1),this}scale(t,i){return this.premultiply(ji.makeScale(t,i)),this}rotate(t){return this.premultiply(ji.makeRotation(-t)),this}translate(t,i){return this.premultiply(ji.makeTranslation(t,i)),this}makeTranslation(t,i){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,i,0,0,1),this}makeRotation(t){const i=Math.cos(t),s=Math.sin(t);return this.set(i,-s,0,s,i,0,0,0,1),this}makeScale(t,i){return this.set(t,0,0,0,i,0,0,0,1),this}equals(t){const i=this.elements,s=t.elements;for(let e=0;e<9;e++)if(i[e]!==s[e])return!1;return!0}fromArray(t,i=0){for(let s=0;s<9;s++)this.elements[s]=t[s+i];return this}toArray(t=[],i=0){const s=this.elements;return t[i]=s[0],t[i+1]=s[1],t[i+2]=s[2],t[i+3]=s[3],t[i+4]=s[4],t[i+5]=s[5],t[i+6]=s[6],t[i+7]=s[7],t[i+8]=s[8],t}clone(){return new this.constructor().fromArray(this.elements)}}const ji=new ut;function ge(l){for(let t=l.length-1;t>=0;--t)if(l[t]>=65535)return!0;return!1}function Vs(l){return document.createElementNS("http://www.w3.org/1999/xhtml",l)}const we={enabled:!0,workingColorSpace:Is,spaces:{},convert:function(l,t,i){return this.enabled===!1||t===i||!t||!i||(this.spaces[t].transfer===$i&&(l.r=Rt(l.r),l.g=Rt(l.g),l.b=Rt(l.b)),this.spaces[t].primaries!==this.spaces[i].primaries&&(l.applyMatrix3(this.spaces[t].toXYZ),l.applyMatrix3(this.spaces[i].fromXYZ)),this.spaces[i].transfer===$i&&(l.r=Gi(l.r),l.g=Gi(l.g),l.b=Gi(l.b))),l},fromWorkingColorSpace:function(l,t){return this.convert(l,this.workingColorSpace,t)},toWorkingColorSpace:function(l,t){return this.convert(l,t,this.workingColorSpace)},getPrimaries:function(l){return this.spaces[l].primaries},getTransfer:function(l){return l===Us?Ls:this.spaces[l].transfer},getLuminanceCoefficients:function(l,t=this.workingColorSpace){return l.fromArray(this.spaces[t].luminanceCoefficients)},define:function(l){Object.assign(this.spaces,l)},_getMatrix:function(l,t,i){return l.copy(this.spaces[t].toXYZ).multiply(this.spaces[i].fromXYZ)},_getDrawingBufferColorSpace:function(l){return this.spaces[l].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(l=this.workingColorSpace){return this.spaces[l].workingColorSpaceConfig.unpackColorSpace}};function Rt(l){return l<.04045?l*.0773993808:Math.pow(l*.9478672986+.0521327014,2.4)}function Gi(l){return l<.0031308?l*12.92:1.055*Math.pow(l,.41666)-.055}const Ns=[.64,.33,.3,.6,.15,.06],qs=[.2126,.7152,.0722],Ds=[.3127,.329],Xs=new ut().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),Ws=new ut().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);we.define({[Is]:{primaries:Ns,whitePoint:Ds,transfer:Ls,toXYZ:Xs,fromXYZ:Ws,luminanceCoefficients:qs,workingColorSpaceConfig:{unpackColorSpace:yi},outputColorSpaceConfig:{drawingBufferColorSpace:yi}},[yi]:{primaries:Ns,whitePoint:Ds,transfer:$i,toXYZ:Xs,fromXYZ:Ws,luminanceCoefficients:qs,outputColorSpaceConfig:{drawingBufferColorSpace:yi}}});let Ut;class be{static getDataURL(t){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let i;if(t instanceof HTMLCanvasElement)i=t;else{Ut===void 0&&(Ut=Vs("canvas")),Ut.width=t.width,Ut.height=t.height;const s=Ut.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),i=Ut}return i.width>2048||i.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",t),i.toDataURL("image/jpeg",.6)):i.toDataURL("image/png")}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const i=Vs("canvas");i.width=t.width,i.height=t.height;const s=i.getContext("2d");s.drawImage(t,0,0,t.width,t.height);const e=s.getImageData(0,0,t.width,t.height),n=e.data;for(let r=0;r0&&(s.userData=this.userData),i||(t.textures[this.uuid]=s),s}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==300)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case 1e3:t.x=t.x-Math.floor(t.x);break;case 1001:t.x=t.x<0?0:1;break;case 1002:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case 1e3:t.y=t.y-Math.floor(t.y);break;case 1001:t.y=t.y<0?0:1;break;case 1002:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}Tt.DEFAULT_IMAGE=null,Tt.DEFAULT_MAPPING=300,Tt.DEFAULT_ANISOTROPY=1;class ti{constructor(t=0,i=0,s=0,e=1){ti.prototype.isVector4=!0,this.x=t,this.y=i,this.z=s,this.w=e}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,i,s,e){return this.x=t,this.y=i,this.z=s,this.w=e,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,i){switch(t){case 0:this.x=i;break;case 1:this.y=i;break;case 2:this.z=i;break;case 3:this.w=i;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,i){return this.x=t.x+i.x,this.y=t.y+i.y,this.z=t.z+i.z,this.w=t.w+i.w,this}addScaledVector(t,i){return this.x+=t.x*i,this.y+=t.y*i,this.z+=t.z*i,this.w+=t.w*i,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,i){return this.x=t.x-i.x,this.y=t.y-i.y,this.z=t.z-i.z,this.w=t.w-i.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const i=this.x,s=this.y,e=this.z,n=this.w,r=t.elements;return this.x=r[0]*i+r[4]*s+r[8]*e+r[12]*n,this.y=r[1]*i+r[5]*s+r[9]*e+r[13]*n,this.z=r[2]*i+r[6]*s+r[10]*e+r[14]*n,this.w=r[3]*i+r[7]*s+r[11]*e+r[15]*n,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const i=Math.sqrt(1-t.w*t.w);return i<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/i,this.y=t.y/i,this.z=t.z/i),this}setAxisAngleFromRotationMatrix(t){let i,s,e,n;const o=t.elements,c=o[0],h=o[4],f=o[8],u=o[1],d=o[5],m=o[9],y=o[2],x=o[6],p=o[10];if(Math.abs(h-u)<.01&&Math.abs(f-y)<.01&&Math.abs(m-x)<.01){if(Math.abs(h+u)<.1&&Math.abs(f+y)<.1&&Math.abs(m+x)<.1&&Math.abs(c+d+p-3)<.1)return this.set(1,0,0,0),this;i=Math.PI;const b=(c+1)/2,M=(d+1)/2,w=(p+1)/2,A=(h+u)/4,_=(f+y)/4,S=(m+x)/4;return b>M&&b>w?b<.01?(s=0,e=.707106781,n=.707106781):(s=Math.sqrt(b),e=A/s,n=_/s):M>w?M<.01?(s=.707106781,e=0,n=.707106781):(e=Math.sqrt(M),s=A/e,n=S/e):w<.01?(s=.707106781,e=.707106781,n=0):(n=Math.sqrt(w),s=_/n,e=S/n),this.set(s,e,n,i),this}let g=Math.sqrt((x-m)*(x-m)+(f-y)*(f-y)+(u-h)*(u-h));return Math.abs(g)<.001&&(g=1),this.x=(x-m)/g,this.y=(f-y)/g,this.z=(u-h)/g,this.w=Math.acos((c+d+p-1)/2),this}setFromMatrixPosition(t){const i=t.elements;return this.x=i[12],this.y=i[13],this.z=i[14],this.w=i[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,i){return this.x=Math.max(t.x,Math.min(i.x,this.x)),this.y=Math.max(t.y,Math.min(i.y,this.y)),this.z=Math.max(t.z,Math.min(i.z,this.z)),this.w=Math.max(t.w,Math.min(i.w,this.w)),this}clampScalar(t,i){return this.x=Math.max(t,Math.min(i,this.x)),this.y=Math.max(t,Math.min(i,this.y)),this.z=Math.max(t,Math.min(i,this.z)),this.w=Math.max(t,Math.min(i,this.w)),this}clampLength(t,i){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(i,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,i){return this.x+=(t.x-this.x)*i,this.y+=(t.y-this.y)*i,this.z+=(t.z-this.z)*i,this.w+=(t.w-this.w)*i,this}lerpVectors(t,i,s){return this.x=t.x+(i.x-t.x)*s,this.y=t.y+(i.y-t.y)*s,this.z=t.z+(i.z-t.z)*s,this.w=t.w+(i.w-t.w)*s,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,i=0){return this.x=t[i],this.y=t[i+1],this.z=t[i+2],this.w=t[i+3],this}toArray(t=[],i=0){return t[i]=this.x,t[i+1]=this.y,t[i+2]=this.z,t[i+3]=this.w,t}fromBufferAttribute(t,i){return this.x=t.getX(i),this.y=t.getY(i),this.z=t.getZ(i),this.w=t.getW(i),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class ii{constructor(t=0,i=0,s=0,e=1){this.isQuaternion=!0,this._x=t,this._y=i,this._z=s,this._w=e}static slerpFlat(t,i,s,e,n,r,a){let o=s[e+0],c=s[e+1],h=s[e+2],f=s[e+3];const u=n[r+0],d=n[r+1],m=n[r+2],y=n[r+3];if(a===0){t[i+0]=o,t[i+1]=c,t[i+2]=h,t[i+3]=f;return}if(a===1){t[i+0]=u,t[i+1]=d,t[i+2]=m,t[i+3]=y;return}if(f!==y||o!==u||c!==d||h!==m){let x=1-a;const p=o*u+c*d+h*m+f*y,g=p>=0?1:-1,b=1-p*p;if(b>Number.EPSILON){const w=Math.sqrt(b),A=Math.atan2(w,p*g);x=Math.sin(x*A)/w,a=Math.sin(a*A)/w}const M=a*g;if(o=o*x+u*M,c=c*x+d*M,h=h*x+m*M,f=f*x+y*M,x===1-a){const w=1/Math.sqrt(o*o+c*c+h*h+f*f);o*=w,c*=w,h*=w,f*=w}}t[i]=o,t[i+1]=c,t[i+2]=h,t[i+3]=f}static multiplyQuaternionsFlat(t,i,s,e,n,r){const a=s[e],o=s[e+1],c=s[e+2],h=s[e+3],f=n[r],u=n[r+1],d=n[r+2],m=n[r+3];return t[i]=a*m+h*f+o*d-c*u,t[i+1]=o*m+h*u+c*f-a*d,t[i+2]=c*m+h*d+a*u-o*f,t[i+3]=h*m-a*f-o*u-c*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,i,s,e){return this._x=t,this._y=i,this._z=s,this._w=e,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,i=!0){const s=t._x,e=t._y,n=t._z,r=t._order,a=Math.cos,o=Math.sin,c=a(s/2),h=a(e/2),f=a(n/2),u=o(s/2),d=o(e/2),m=o(n/2);switch(r){case"XYZ":this._x=u*h*f+c*d*m,this._y=c*d*f-u*h*m,this._z=c*h*m+u*d*f,this._w=c*h*f-u*d*m;break;case"YXZ":this._x=u*h*f+c*d*m,this._y=c*d*f-u*h*m,this._z=c*h*m-u*d*f,this._w=c*h*f+u*d*m;break;case"ZXY":this._x=u*h*f-c*d*m,this._y=c*d*f+u*h*m,this._z=c*h*m+u*d*f,this._w=c*h*f-u*d*m;break;case"ZYX":this._x=u*h*f-c*d*m,this._y=c*d*f+u*h*m,this._z=c*h*m-u*d*f,this._w=c*h*f+u*d*m;break;case"YZX":this._x=u*h*f+c*d*m,this._y=c*d*f+u*h*m,this._z=c*h*m-u*d*f,this._w=c*h*f-u*d*m;break;case"XZY":this._x=u*h*f-c*d*m,this._y=c*d*f-u*h*m,this._z=c*h*m+u*d*f,this._w=c*h*f+u*d*m;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+r)}return i===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,i){const s=i/2,e=Math.sin(s);return this._x=t.x*e,this._y=t.y*e,this._z=t.z*e,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const i=t.elements,s=i[0],e=i[4],n=i[8],r=i[1],a=i[5],o=i[9],c=i[2],h=i[6],f=i[10],u=s+a+f;if(u>0){const d=.5/Math.sqrt(u+1);this._w=.25/d,this._x=(h-o)*d,this._y=(n-c)*d,this._z=(r-e)*d}else if(s>a&&s>f){const d=2*Math.sqrt(1+s-a-f);this._w=(h-o)/d,this._x=.25*d,this._y=(e+r)/d,this._z=(n+c)/d}else if(a>f){const d=2*Math.sqrt(1+a-s-f);this._w=(n-c)/d,this._x=(e+r)/d,this._y=.25*d,this._z=(o+h)/d}else{const d=2*Math.sqrt(1+f-s-a);this._w=(r-e)/d,this._x=(n+c)/d,this._y=(o+h)/d,this._z=.25*d}return this._onChangeCallback(),this}setFromUnitVectors(t,i){let s=t.dot(i)+1;return sMath.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(this._x=t.y*i.z-t.z*i.y,this._y=t.z*i.x-t.x*i.z,this._z=t.x*i.y-t.y*i.x,this._w=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(at(this.dot(t),-1,1)))}rotateTowards(t,i){const s=this.angleTo(t);if(s===0)return this;const e=Math.min(1,i/s);return this.slerp(t,e),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,i){const s=t._x,e=t._y,n=t._z,r=t._w,a=i._x,o=i._y,c=i._z,h=i._w;return this._x=s*h+r*a+e*c-n*o,this._y=e*h+r*o+n*a-s*c,this._z=n*h+r*c+s*o-e*a,this._w=r*h-s*a-e*o-n*c,this._onChangeCallback(),this}slerp(t,i){if(i===0)return this;if(i===1)return this.copy(t);const s=this._x,e=this._y,n=this._z,r=this._w;let a=r*t._w+s*t._x+e*t._y+n*t._z;if(a<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,a=-a):this.copy(t),a>=1)return this._w=r,this._x=s,this._y=e,this._z=n,this;const o=1-a*a;if(o<=Number.EPSILON){const d=1-i;return this._w=d*r+i*this._w,this._x=d*s+i*this._x,this._y=d*e+i*this._y,this._z=d*n+i*this._z,this.normalize(),this}const c=Math.sqrt(o),h=Math.atan2(c,a),f=Math.sin((1-i)*h)/c,u=Math.sin(i*h)/c;return this._w=r*f+this._w*u,this._x=s*f+this._x*u,this._y=e*f+this._y*u,this._z=n*f+this._z*u,this._onChangeCallback(),this}slerpQuaternions(t,i,s){return this.copy(t).slerp(i,s)}random(){const t=2*Math.PI*Math.random(),i=2*Math.PI*Math.random(),s=Math.random(),e=Math.sqrt(1-s),n=Math.sqrt(s);return this.set(e*Math.sin(t),e*Math.cos(t),n*Math.sin(i),n*Math.cos(i))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,i=0){return this._x=t[i],this._y=t[i+1],this._z=t[i+2],this._w=t[i+3],this._onChangeCallback(),this}toArray(t=[],i=0){return t[i]=this._x,t[i+1]=this._y,t[i+2]=this._z,t[i+3]=this._w,t}fromBufferAttribute(t,i){return this._x=t.getX(i),this._y=t.getY(i),this._z=t.getZ(i),this._w=t.getW(i),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class z{constructor(t=0,i=0,s=0){z.prototype.isVector3=!0,this.x=t,this.y=i,this.z=s}set(t,i,s){return s===void 0&&(s=this.z),this.x=t,this.y=i,this.z=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,i){switch(t){case 0:this.x=i;break;case 1:this.y=i;break;case 2:this.z=i;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,i){return this.x=t.x+i.x,this.y=t.y+i.y,this.z=t.z+i.z,this}addScaledVector(t,i){return this.x+=t.x*i,this.y+=t.y*i,this.z+=t.z*i,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,i){return this.x=t.x-i.x,this.y=t.y-i.y,this.z=t.z-i.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,i){return this.x=t.x*i.x,this.y=t.y*i.y,this.z=t.z*i.z,this}applyEuler(t){return this.applyQuaternion(Ys.setFromEuler(t))}applyAxisAngle(t,i){return this.applyQuaternion(Ys.setFromAxisAngle(t,i))}applyMatrix3(t){const i=this.x,s=this.y,e=this.z,n=t.elements;return this.x=n[0]*i+n[3]*s+n[6]*e,this.y=n[1]*i+n[4]*s+n[7]*e,this.z=n[2]*i+n[5]*s+n[8]*e,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const i=this.x,s=this.y,e=this.z,n=t.elements,r=1/(n[3]*i+n[7]*s+n[11]*e+n[15]);return this.x=(n[0]*i+n[4]*s+n[8]*e+n[12])*r,this.y=(n[1]*i+n[5]*s+n[9]*e+n[13])*r,this.z=(n[2]*i+n[6]*s+n[10]*e+n[14])*r,this}applyQuaternion(t){const i=this.x,s=this.y,e=this.z,n=t.x,r=t.y,a=t.z,o=t.w,c=2*(r*e-a*s),h=2*(a*i-n*e),f=2*(n*s-r*i);return this.x=i+o*c+r*f-a*h,this.y=s+o*h+a*c-n*f,this.z=e+o*f+n*h-r*c,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const i=this.x,s=this.y,e=this.z,n=t.elements;return this.x=n[0]*i+n[4]*s+n[8]*e,this.y=n[1]*i+n[5]*s+n[9]*e,this.z=n[2]*i+n[6]*s+n[10]*e,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,i){return this.x=Math.max(t.x,Math.min(i.x,this.x)),this.y=Math.max(t.y,Math.min(i.y,this.y)),this.z=Math.max(t.z,Math.min(i.z,this.z)),this}clampScalar(t,i){return this.x=Math.max(t,Math.min(i,this.x)),this.y=Math.max(t,Math.min(i,this.y)),this.z=Math.max(t,Math.min(i,this.z)),this}clampLength(t,i){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(i,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,i){return this.x+=(t.x-this.x)*i,this.y+=(t.y-this.y)*i,this.z+=(t.z-this.z)*i,this}lerpVectors(t,i,s){return this.x=t.x+(i.x-t.x)*s,this.y=t.y+(i.y-t.y)*s,this.z=t.z+(i.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,i){const s=t.x,e=t.y,n=t.z,r=i.x,a=i.y,o=i.z;return this.x=e*o-n*a,this.y=n*r-s*o,this.z=s*a-e*r,this}projectOnVector(t){const i=t.lengthSq();if(i===0)return this.set(0,0,0);const s=t.dot(this)/i;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return Qi.copy(this).projectOnVector(t),this.sub(Qi)}reflect(t){return this.sub(Qi.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const i=Math.sqrt(this.lengthSq()*t.lengthSq());if(i===0)return Math.PI/2;const s=this.dot(t)/i;return Math.acos(at(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const i=this.x-t.x,s=this.y-t.y,e=this.z-t.z;return i*i+s*s+e*e}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,i,s){const e=Math.sin(i)*t;return this.x=e*Math.sin(s),this.y=Math.cos(i)*t,this.z=e*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,i,s){return this.x=t*Math.sin(i),this.y=s,this.z=t*Math.cos(i),this}setFromMatrixPosition(t){const i=t.elements;return this.x=i[12],this.y=i[13],this.z=i[14],this}setFromMatrixScale(t){const i=this.setFromMatrixColumn(t,0).length(),s=this.setFromMatrixColumn(t,1).length(),e=this.setFromMatrixColumn(t,2).length();return this.x=i,this.y=s,this.z=e,this}setFromMatrixColumn(t,i){return this.fromArray(t.elements,i*4)}setFromMatrix3Column(t,i){return this.fromArray(t.elements,i*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,i=0){return this.x=t[i],this.y=t[i+1],this.z=t[i+2],this}toArray(t=[],i=0){return t[i]=this.x,t[i+1]=this.y,t[i+2]=this.z,t}fromBufferAttribute(t,i){return this.x=t.getX(i),this.y=t.getY(i),this.z=t.getZ(i),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,i=Math.random()*2-1,s=Math.sqrt(1-i*i);return this.x=s*Math.cos(t),this.y=i,this.z=s*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Qi=new z,Ys=new ii;class W{constructor(t=new z(1/0,1/0,1/0),i=new z(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=i}set(t,i){return this.min.copy(t),this.max.copy(i),this}setFromArray(t){this.makeEmpty();for(let i=0,s=t.length;i=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,i){return i.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,st),st.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let i,s;return t.normal.x>0?(i=t.normal.x*this.min.x,s=t.normal.x*this.max.x):(i=t.normal.x*this.max.x,s=t.normal.x*this.min.x),t.normal.y>0?(i+=t.normal.y*this.min.y,s+=t.normal.y*this.max.y):(i+=t.normal.y*this.max.y,s+=t.normal.y*this.min.y),t.normal.z>0?(i+=t.normal.z*this.min.z,s+=t.normal.z*this.max.z):(i+=t.normal.z*this.max.z,s+=t.normal.z*this.min.z),i<=-t.constant&&s>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(si),wi.subVectors(this.max,si),It.subVectors(t.a,si),Lt.subVectors(t.b,si),Vt.subVectors(t.c,si),wt.subVectors(Lt,It),bt.subVectors(Vt,Lt),Pt.subVectors(It,Vt);let i=[0,-wt.z,wt.y,0,-bt.z,bt.y,0,-Pt.z,Pt.y,wt.z,0,-wt.x,bt.z,0,-bt.x,Pt.z,0,-Pt.x,-wt.y,wt.x,0,-bt.y,bt.x,0,-Pt.y,Pt.x,0];return!Ki(i,It,Lt,Vt,wi)||(i=[1,0,0,0,1,0,0,0,1],!Ki(i,It,Lt,Vt,wi))?!1:(bi.crossVectors(wt,bt),i=[bi.x,bi.y,bi.z],Ki(i,It,Lt,Vt,wi))}clampPoint(t,i){return i.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,st).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(st).length()*.5),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()?this:(ft[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),ft[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),ft[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),ft[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),ft[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),ft[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),ft[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),ft[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(ft),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const ft=[new z,new z,new z,new z,new z,new z,new z,new z],st=new z,gi=new W,It=new z,Lt=new z,Vt=new z,wt=new z,bt=new z,Pt=new z,si=new z,wi=new z,bi=new z,Ct=new z;function Ki(l,t,i,s,e){for(let n=0,r=l.length-3;n<=r;n+=3){Ct.fromArray(l,n);const a=e.x*Math.abs(Ct.x)+e.y*Math.abs(Ct.y)+e.z*Math.abs(Ct.z),o=t.dot(Ct),c=i.dot(Ct),h=s.dot(Ct);if(Math.max(-Math.max(o,c,h),Math.min(o,c,h))>a)return!1}return!0}const Ae=new W,ei=new z,ts=new z;class Os{constructor(t=new z,i=-1){this.isSphere=!0,this.center=t,this.radius=i}set(t,i){return this.center.copy(t),this.radius=i,this}setFromPoints(t,i){const s=this.center;i!==void 0?s.copy(i):Ae.setFromPoints(t).getCenter(s);let e=0;for(let n=0,r=t.length;nthis.radius*this.radius&&(i.sub(this.center).normalize(),i.multiplyScalar(this.radius).add(this.center)),i}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;ei.subVectors(t,this.center);const i=ei.lengthSq();if(i>this.radius*this.radius){const s=Math.sqrt(i),e=(s-this.radius)*.5;this.center.addScaledVector(ei,e/s),this.radius+=e}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(ts.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(ei.copy(t.center).add(ts)),this.expandByPoint(ei.copy(t.center).sub(ts))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}}class q{constructor(t,i,s,e,n,r,a,o,c,h,f,u,d,m,y,x){q.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,i,s,e,n,r,a,o,c,h,f,u,d,m,y,x)}set(t,i,s,e,n,r,a,o,c,h,f,u,d,m,y,x){const p=this.elements;return p[0]=t,p[4]=i,p[8]=s,p[12]=e,p[1]=n,p[5]=r,p[9]=a,p[13]=o,p[2]=c,p[6]=h,p[10]=f,p[14]=u,p[3]=d,p[7]=m,p[11]=y,p[15]=x,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new q().fromArray(this.elements)}copy(t){const i=this.elements,s=t.elements;return i[0]=s[0],i[1]=s[1],i[2]=s[2],i[3]=s[3],i[4]=s[4],i[5]=s[5],i[6]=s[6],i[7]=s[7],i[8]=s[8],i[9]=s[9],i[10]=s[10],i[11]=s[11],i[12]=s[12],i[13]=s[13],i[14]=s[14],i[15]=s[15],this}copyPosition(t){const i=this.elements,s=t.elements;return i[12]=s[12],i[13]=s[13],i[14]=s[14],this}setFromMatrix3(t){const i=t.elements;return this.set(i[0],i[3],i[6],0,i[1],i[4],i[7],0,i[2],i[5],i[8],0,0,0,0,1),this}extractBasis(t,i,s){return t.setFromMatrixColumn(this,0),i.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this}makeBasis(t,i,s){return this.set(t.x,i.x,s.x,0,t.y,i.y,s.y,0,t.z,i.z,s.z,0,0,0,0,1),this}extractRotation(t){const i=this.elements,s=t.elements,e=1/Nt.setFromMatrixColumn(t,0).length(),n=1/Nt.setFromMatrixColumn(t,1).length(),r=1/Nt.setFromMatrixColumn(t,2).length();return i[0]=s[0]*e,i[1]=s[1]*e,i[2]=s[2]*e,i[3]=0,i[4]=s[4]*n,i[5]=s[5]*n,i[6]=s[6]*n,i[7]=0,i[8]=s[8]*r,i[9]=s[9]*r,i[10]=s[10]*r,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,this}makeRotationFromEuler(t){const i=this.elements,s=t.x,e=t.y,n=t.z,r=Math.cos(s),a=Math.sin(s),o=Math.cos(e),c=Math.sin(e),h=Math.cos(n),f=Math.sin(n);if(t.order==="XYZ"){const u=r*h,d=r*f,m=a*h,y=a*f;i[0]=o*h,i[4]=-o*f,i[8]=c,i[1]=d+m*c,i[5]=u-y*c,i[9]=-a*o,i[2]=y-u*c,i[6]=m+d*c,i[10]=r*o}else if(t.order==="YXZ"){const u=o*h,d=o*f,m=c*h,y=c*f;i[0]=u+y*a,i[4]=m*a-d,i[8]=r*c,i[1]=r*f,i[5]=r*h,i[9]=-a,i[2]=d*a-m,i[6]=y+u*a,i[10]=r*o}else if(t.order==="ZXY"){const u=o*h,d=o*f,m=c*h,y=c*f;i[0]=u-y*a,i[4]=-r*f,i[8]=m+d*a,i[1]=d+m*a,i[5]=r*h,i[9]=y-u*a,i[2]=-r*c,i[6]=a,i[10]=r*o}else if(t.order==="ZYX"){const u=r*h,d=r*f,m=a*h,y=a*f;i[0]=o*h,i[4]=m*c-d,i[8]=u*c+y,i[1]=o*f,i[5]=y*c+u,i[9]=d*c-m,i[2]=-c,i[6]=a*o,i[10]=r*o}else if(t.order==="YZX"){const u=r*o,d=r*c,m=a*o,y=a*c;i[0]=o*h,i[4]=y-u*f,i[8]=m*f+d,i[1]=f,i[5]=r*h,i[9]=-a*h,i[2]=-c*h,i[6]=d*f+m,i[10]=u-y*f}else if(t.order==="XZY"){const u=r*o,d=r*c,m=a*o,y=a*c;i[0]=o*h,i[4]=-f,i[8]=c*h,i[1]=u*f+y,i[5]=r*h,i[9]=d*f-m,i[2]=m*f-d,i[6]=a*h,i[10]=y*f+u}return i[3]=0,i[7]=0,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,this}makeRotationFromQuaternion(t){return this.compose(Se,t,Be)}lookAt(t,i,s){const e=this.elements;return v.subVectors(t,i),v.lengthSq()===0&&(v.z=1),v.normalize(),Mt.crossVectors(s,v),Mt.lengthSq()===0&&(Math.abs(s.z)===1?v.x+=1e-4:v.z+=1e-4,v.normalize(),Mt.crossVectors(s,v)),Mt.normalize(),Mi.crossVectors(v,Mt),e[0]=Mt.x,e[4]=Mi.x,e[8]=v.x,e[1]=Mt.y,e[5]=Mi.y,e[9]=v.y,e[2]=Mt.z,e[6]=Mi.z,e[10]=v.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,i){const s=t.elements,e=i.elements,n=this.elements,r=s[0],a=s[4],o=s[8],c=s[12],h=s[1],f=s[5],u=s[9],d=s[13],m=s[2],y=s[6],x=s[10],p=s[14],g=s[3],b=s[7],M=s[11],w=s[15],A=e[0],_=e[4],S=e[8],B=e[12],T=e[1],C=e[5],P=e[9],E=e[13],F=e[2],k=e[6],R=e[10],j=e[14],ct=e[3],lt=e[7],Oi=e[11],Zi=e[15];return n[0]=r*A+a*T+o*F+c*ct,n[4]=r*_+a*C+o*k+c*lt,n[8]=r*S+a*P+o*R+c*Oi,n[12]=r*B+a*E+o*j+c*Zi,n[1]=h*A+f*T+u*F+d*ct,n[5]=h*_+f*C+u*k+d*lt,n[9]=h*S+f*P+u*R+d*Oi,n[13]=h*B+f*E+u*j+d*Zi,n[2]=m*A+y*T+x*F+p*ct,n[6]=m*_+y*C+x*k+p*lt,n[10]=m*S+y*P+x*R+p*Oi,n[14]=m*B+y*E+x*j+p*Zi,n[3]=g*A+b*T+M*F+w*ct,n[7]=g*_+b*C+M*k+w*lt,n[11]=g*S+b*P+M*R+w*Oi,n[15]=g*B+b*E+M*j+w*Zi,this}multiplyScalar(t){const i=this.elements;return i[0]*=t,i[4]*=t,i[8]*=t,i[12]*=t,i[1]*=t,i[5]*=t,i[9]*=t,i[13]*=t,i[2]*=t,i[6]*=t,i[10]*=t,i[14]*=t,i[3]*=t,i[7]*=t,i[11]*=t,i[15]*=t,this}determinant(){const t=this.elements,i=t[0],s=t[4],e=t[8],n=t[12],r=t[1],a=t[5],o=t[9],c=t[13],h=t[2],f=t[6],u=t[10],d=t[14],m=t[3],y=t[7],x=t[11],p=t[15];return m*(+n*o*f-e*c*f-n*a*u+s*c*u+e*a*d-s*o*d)+y*(+i*o*d-i*c*u+n*r*u-e*r*d+e*c*h-n*o*h)+x*(+i*c*f-i*a*d-n*r*f+s*r*d+n*a*h-s*c*h)+p*(-e*a*h-i*o*f+i*a*u+e*r*f-s*r*u+s*o*h)}transpose(){const t=this.elements;let i;return i=t[1],t[1]=t[4],t[4]=i,i=t[2],t[2]=t[8],t[8]=i,i=t[6],t[6]=t[9],t[9]=i,i=t[3],t[3]=t[12],t[12]=i,i=t[7],t[7]=t[13],t[13]=i,i=t[11],t[11]=t[14],t[14]=i,this}setPosition(t,i,s){const e=this.elements;return t.isVector3?(e[12]=t.x,e[13]=t.y,e[14]=t.z):(e[12]=t,e[13]=i,e[14]=s),this}invert(){const t=this.elements,i=t[0],s=t[1],e=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8],f=t[9],u=t[10],d=t[11],m=t[12],y=t[13],x=t[14],p=t[15],g=f*x*c-y*u*c+y*o*d-a*x*d-f*o*p+a*u*p,b=m*u*c-h*x*c-m*o*d+r*x*d+h*o*p-r*u*p,M=h*y*c-m*f*c+m*a*d-r*y*d-h*a*p+r*f*p,w=m*f*o-h*y*o-m*a*u+r*y*u+h*a*x-r*f*x,A=i*g+s*b+e*M+n*w;if(A===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const _=1/A;return t[0]=g*_,t[1]=(y*u*n-f*x*n-y*e*d+s*x*d+f*e*p-s*u*p)*_,t[2]=(a*x*n-y*o*n+y*e*c-s*x*c-a*e*p+s*o*p)*_,t[3]=(f*o*n-a*u*n-f*e*c+s*u*c+a*e*d-s*o*d)*_,t[4]=b*_,t[5]=(h*x*n-m*u*n+m*e*d-i*x*d-h*e*p+i*u*p)*_,t[6]=(m*o*n-r*x*n-m*e*c+i*x*c+r*e*p-i*o*p)*_,t[7]=(r*u*n-h*o*n+h*e*c-i*u*c-r*e*d+i*o*d)*_,t[8]=M*_,t[9]=(m*f*n-h*y*n-m*s*d+i*y*d+h*s*p-i*f*p)*_,t[10]=(r*y*n-m*a*n+m*s*c-i*y*c-r*s*p+i*a*p)*_,t[11]=(h*a*n-r*f*n-h*s*c+i*f*c+r*s*d-i*a*d)*_,t[12]=w*_,t[13]=(h*y*e-m*f*e+m*s*u-i*y*u-h*s*x+i*f*x)*_,t[14]=(m*a*e-r*y*e-m*s*o+i*y*o+r*s*x-i*a*x)*_,t[15]=(r*f*e-h*a*e+h*s*o-i*f*o-r*s*u+i*a*u)*_,this}scale(t){const i=this.elements,s=t.x,e=t.y,n=t.z;return i[0]*=s,i[4]*=e,i[8]*=n,i[1]*=s,i[5]*=e,i[9]*=n,i[2]*=s,i[6]*=e,i[10]*=n,i[3]*=s,i[7]*=e,i[11]*=n,this}getMaxScaleOnAxis(){const t=this.elements,i=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],s=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],e=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(i,s,e))}makeTranslation(t,i,s){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,i,0,0,1,s,0,0,0,1),this}makeRotationX(t){const i=Math.cos(t),s=Math.sin(t);return this.set(1,0,0,0,0,i,-s,0,0,s,i,0,0,0,0,1),this}makeRotationY(t){const i=Math.cos(t),s=Math.sin(t);return this.set(i,0,s,0,0,1,0,0,-s,0,i,0,0,0,0,1),this}makeRotationZ(t){const i=Math.cos(t),s=Math.sin(t);return this.set(i,-s,0,0,s,i,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,i){const s=Math.cos(i),e=Math.sin(i),n=1-s,r=t.x,a=t.y,o=t.z,c=n*r,h=n*a;return this.set(c*r+s,c*a-e*o,c*o+e*a,0,c*a+e*o,h*a+s,h*o-e*r,0,c*o-e*a,h*o+e*r,n*o*o+s,0,0,0,0,1),this}makeScale(t,i,s){return this.set(t,0,0,0,0,i,0,0,0,0,s,0,0,0,0,1),this}makeShear(t,i,s,e,n,r){return this.set(1,s,n,0,t,1,r,0,i,e,1,0,0,0,0,1),this}compose(t,i,s){const e=this.elements,n=i._x,r=i._y,a=i._z,o=i._w,c=n+n,h=r+r,f=a+a,u=n*c,d=n*h,m=n*f,y=r*h,x=r*f,p=a*f,g=o*c,b=o*h,M=o*f,w=s.x,A=s.y,_=s.z;return e[0]=(1-(y+p))*w,e[1]=(d+M)*w,e[2]=(m-b)*w,e[3]=0,e[4]=(d-M)*A,e[5]=(1-(u+p))*A,e[6]=(x+g)*A,e[7]=0,e[8]=(m+b)*_,e[9]=(x-g)*_,e[10]=(1-(u+y))*_,e[11]=0,e[12]=t.x,e[13]=t.y,e[14]=t.z,e[15]=1,this}decompose(t,i,s){const e=this.elements;let n=Nt.set(e[0],e[1],e[2]).length();const r=Nt.set(e[4],e[5],e[6]).length(),a=Nt.set(e[8],e[9],e[10]).length();this.determinant()<0&&(n=-n),t.x=e[12],t.y=e[13],t.z=e[14],et.copy(this);const c=1/n,h=1/r,f=1/a;return et.elements[0]*=c,et.elements[1]*=c,et.elements[2]*=c,et.elements[4]*=h,et.elements[5]*=h,et.elements[6]*=h,et.elements[8]*=f,et.elements[9]*=f,et.elements[10]*=f,i.setFromRotationMatrix(et),s.x=n,s.y=r,s.z=a,this}makePerspective(t,i,s,e,n,r,a=2e3){const o=this.elements,c=2*n/(i-t),h=2*n/(s-e),f=(i+t)/(i-t),u=(s+e)/(s-e);let d,m;if(a===2e3)d=-(r+n)/(r-n),m=-2*r*n/(r-n);else if(a===2001)d=-r/(r-n),m=-r*n/(r-n);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return o[0]=c,o[4]=0,o[8]=f,o[12]=0,o[1]=0,o[5]=h,o[9]=u,o[13]=0,o[2]=0,o[6]=0,o[10]=d,o[14]=m,o[3]=0,o[7]=0,o[11]=-1,o[15]=0,this}makeOrthographic(t,i,s,e,n,r,a=2e3){const o=this.elements,c=1/(i-t),h=1/(s-e),f=1/(r-n),u=(i+t)*c,d=(s+e)*h;let m,y;if(a===2e3)m=(r+n)*f,y=-2*f;else if(a===2001)m=n*f,y=-1*f;else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return o[0]=2*c,o[4]=0,o[8]=0,o[12]=-u,o[1]=0,o[5]=2*h,o[9]=0,o[13]=-d,o[2]=0,o[6]=0,o[10]=y,o[14]=-m,o[3]=0,o[7]=0,o[11]=0,o[15]=1,this}equals(t){const i=this.elements,s=t.elements;for(let e=0;e<16;e++)if(i[e]!==s[e])return!1;return!0}fromArray(t,i=0){for(let s=0;s<16;s++)this.elements[s]=t[s+i];return this}toArray(t=[],i=0){const s=this.elements;return t[i]=s[0],t[i+1]=s[1],t[i+2]=s[2],t[i+3]=s[3],t[i+4]=s[4],t[i+5]=s[5],t[i+6]=s[6],t[i+7]=s[7],t[i+8]=s[8],t[i+9]=s[9],t[i+10]=s[10],t[i+11]=s[11],t[i+12]=s[12],t[i+13]=s[13],t[i+14]=s[14],t[i+15]=s[15],t}}const Nt=new z,et=new q,Se=new z(0,0,0),Be=new z(1,1,1),Mt=new z,Mi=new z,v=new z,Zs=new q,vs=new ii;class _i{constructor(t=0,i=0,s=0,e=_i.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=i,this._z=s,this._order=e}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,i,s,e=this._order){return this._x=t,this._y=i,this._z=s,this._order=e,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,i=this._order,s=!0){const e=t.elements,n=e[0],r=e[4],a=e[8],o=e[1],c=e[5],h=e[9],f=e[2],u=e[6],d=e[10];switch(i){case"XYZ":this._y=Math.asin(at(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,d),this._z=Math.atan2(-r,n)):(this._x=Math.atan2(u,c),this._z=0);break;case"YXZ":this._x=Math.asin(-at(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,c)):(this._y=Math.atan2(-f,n),this._z=0);break;case"ZXY":this._x=Math.asin(at(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-f,d),this._z=Math.atan2(-r,c)):(this._y=0,this._z=Math.atan2(o,n));break;case"ZYX":this._y=Math.asin(-at(f,-1,1)),Math.abs(f)<.9999999?(this._x=Math.atan2(u,d),this._z=Math.atan2(o,n)):(this._x=0,this._z=Math.atan2(-r,c));break;case"YZX":this._z=Math.asin(at(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,c),this._y=Math.atan2(-f,n)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-at(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(u,c),this._y=Math.atan2(a,n)):(this._x=Math.atan2(-h,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+i)}return this._order=i,s===!0&&this._onChangeCallback(),this}setFromQuaternion(t,i,s){return Zs.makeRotationFromQuaternion(t),this.setFromRotationMatrix(Zs,i,s)}setFromVector3(t,i=this._order){return this.set(t.x,t.y,t.z,i)}reorder(t){return vs.setFromEuler(this),this.setFromQuaternion(vs,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],i=0){return t[i]=this._x,t[i+1]=this._y,t[i+2]=this._z,t[i+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}_i.DEFAULT_ORDER="XYZ";class Te{constructor(){this.mask=1}set(t){this.mask=(1<>>0}enable(t){this.mask|=1<1){for(let i=0;i1){for(let s=0;s0&&(e.userData=this.userData),e.layers=this.layers.mask,e.matrix=this.matrix.toArray(),e.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(e.matrixAutoUpdate=!1),this.isInstancedMesh&&(e.type="InstancedMesh",e.count=this.count,e.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(e.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(e.type="BatchedMesh",e.perObjectFrustumCulled=this.perObjectFrustumCulled,e.sortObjects=this.sortObjects,e.drawRanges=this._drawRanges,e.reservedRanges=this._reservedRanges,e.visibility=this._visibility,e.active=this._active,e.bounds=this._bounds.map(a=>({boxInitialized:a.boxInitialized,boxMin:a.box.min.toArray(),boxMax:a.box.max.toArray(),sphereInitialized:a.sphereInitialized,sphereRadius:a.sphere.radius,sphereCenter:a.sphere.center.toArray()})),e.maxInstanceCount=this._maxInstanceCount,e.maxVertexCount=this._maxVertexCount,e.maxIndexCount=this._maxIndexCount,e.geometryInitialized=this._geometryInitialized,e.geometryCount=this._geometryCount,e.matricesTexture=this._matricesTexture.toJSON(t),this._colorsTexture!==null&&(e.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(e.boundingSphere={center:e.boundingSphere.center.toArray(),radius:e.boundingSphere.radius}),this.boundingBox!==null&&(e.boundingBox={min:e.boundingBox.min.toArray(),max:e.boundingBox.max.toArray()}));function n(a,o){return a[o.uuid]===void 0&&(a[o.uuid]=o.toJSON(t)),o.uuid}if(this.isScene)this.background&&(this.background.isColor?e.background=this.background.toJSON():this.background.isTexture&&(e.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(e.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){e.geometry=n(t.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const o=a.shapes;if(Array.isArray(o))for(let c=0,h=o.length;c0){e.children=[];for(let a=0;a0){e.animations=[];for(let a=0;a0&&(s.geometries=a),o.length>0&&(s.materials=o),c.length>0&&(s.textures=c),h.length>0&&(s.images=h),f.length>0&&(s.shapes=f),u.length>0&&(s.skeletons=u),d.length>0&&(s.animations=d),m.length>0&&(s.nodes=m)}return s.object=e,s;function r(a){const o=[];for(const c in a){const h=a[c];delete h.metadata,o.push(h)}return o}}clone(t){return new this.constructor().copy(this,t)}copy(t,i=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),i===!0)for(let s=0;s0?e.multiplyScalar(1/Math.sqrt(n)):e.set(0,0,0)}static getBarycoord(t,i,s,e,n){nt.subVectors(e,i),mt.subVectors(s,i),ss.subVectors(t,i);const r=nt.dot(nt),a=nt.dot(mt),o=nt.dot(ss),c=mt.dot(mt),h=mt.dot(ss),f=r*c-a*a;if(f===0)return n.set(0,0,0),null;const u=1/f,d=(c*o-a*h)*u,m=(r*h-a*o)*u;return n.set(1-d-m,m,d)}static containsPoint(t,i,s,e){return this.getBarycoord(t,i,s,e,pt)===null?!1:pt.x>=0&&pt.y>=0&&pt.x+pt.y<=1}static getInterpolation(t,i,s,e,n,r,a,o){return this.getBarycoord(t,i,s,e,pt)===null?(o.x=0,o.y=0,"z"in o&&(o.z=0),"w"in o&&(o.w=0),null):(o.setScalar(0),o.addScaledVector(n,pt.x),o.addScaledVector(r,pt.y),o.addScaledVector(a,pt.z),o)}static getInterpolatedAttribute(t,i,s,e,n,r){return os.setScalar(0),as.setScalar(0),hs.setScalar(0),os.fromBufferAttribute(t,i),as.fromBufferAttribute(t,s),hs.fromBufferAttribute(t,e),r.setScalar(0),r.addScaledVector(os,n.x),r.addScaledVector(as,n.y),r.addScaledVector(hs,n.z),r}static isFrontFacing(t,i,s,e){return nt.subVectors(s,i),mt.subVectors(t,i),nt.cross(mt).dot(e)<0}set(t,i,s){return this.a.copy(t),this.b.copy(i),this.c.copy(s),this}setFromPointsAndIndices(t,i,s,e){return this.a.copy(t[i]),this.b.copy(t[s]),this.c.copy(t[e]),this}setFromAttributeAndIndices(t,i,s,e){return this.a.fromBufferAttribute(t,i),this.b.fromBufferAttribute(t,s),this.c.fromBufferAttribute(t,e),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return nt.subVectors(this.c,this.b),mt.subVectors(this.a,this.b),nt.cross(mt).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return G.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,i){return G.getBarycoord(t,this.a,this.b,this.c,i)}getInterpolation(t,i,s,e,n){return G.getInterpolation(t,this.a,this.b,this.c,i,s,e,n)}containsPoint(t){return G.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return G.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,i){const s=this.a,e=this.b,n=this.c;let r,a;Xt.subVectors(e,s),Wt.subVectors(n,s),es.subVectors(t,s);const o=Xt.dot(es),c=Wt.dot(es);if(o<=0&&c<=0)return i.copy(s);ns.subVectors(t,e);const h=Xt.dot(ns),f=Wt.dot(ns);if(h>=0&&f<=h)return i.copy(e);const u=o*f-h*c;if(u<=0&&o>=0&&h<=0)return r=o/(o-h),i.copy(s).addScaledVector(Xt,r);rs.subVectors(t,n);const d=Xt.dot(rs),m=Wt.dot(rs);if(m>=0&&d<=m)return i.copy(n);const y=d*c-o*m;if(y<=0&&c>=0&&m<=0)return a=c/(c-m),i.copy(s).addScaledVector(Wt,a);const x=h*m-d*f;if(x<=0&&f-h>=0&&d-m>=0)return Qs.subVectors(n,e),a=(f-h)/(f-h+(d-m)),i.copy(e).addScaledVector(Qs,a);const p=1/(x+y+u);return r=y*p,a=u*p,i.copy(s).addScaledVector(Xt,r).addScaledVector(Wt,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const L=new z,Ai=new X;class ht{constructor(t,i,s=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=i,this.count=t!==void 0?t.length/i:0,this.normalized=s,this.usage=35044,this.updateRanges=[],this.gpuType=1015,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,i){this.updateRanges.push({start:t,count:i})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,i,s){t*=this.itemSize,s*=i.itemSize;for(let e=0,n=this.itemSize;ei.count&&console.warn("THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),i.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new W);const t=this.attributes.position,i=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new z(-1/0,-1/0,-1/0),new z(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),i)for(let s=0,e=i.length;s0&&(t.userData=this.userData),this.parameters!==void 0){const o=this.parameters;for(const c in o)o[c]!==void 0&&(t[c]=o[c]);return t}t.data={attributes:{}};const i=this.index;i!==null&&(t.data.index={type:i.array.constructor.name,array:Array.prototype.slice.call(i.array)});const s=this.attributes;for(const o in s){const c=s[o];t.data.attributes[o]=c.toJSON(t.data)}const e={};let n=!1;for(const o in this.morphAttributes){const c=this.morphAttributes[o],h=[];for(let f=0,u=c.length;f0&&(e[o]=h,n=!0)}n&&(t.data.morphAttributes=e,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const a=this.boundingSphere;return a!==null&&(t.data.boundingSphere={center:a.center.toArray(),radius:a.radius}),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const i={};this.name=t.name;const s=t.index;s!==null&&this.setIndex(s.clone(i));const e=t.attributes;for(const c in e){const h=e[c];this.setAttribute(c,h.clone(i))}const n=t.morphAttributes;for(const c in n){const h=[],f=n[c];for(let u=0,d=f.length;u1?null:i.copy(t.start).addScaledVector(s,n)}intersectsLine(t){const i=this.distanceToPoint(t.start),s=this.distanceToPoint(t.end);return i<0&&s>0||s<0&&i>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,i){const s=i||Ve.getNormalMatrix(t),e=this.coplanarPoint(us).applyMatrix4(t),n=this.normal.applyMatrix3(s).normalize();return this.constant=-e.dot(n),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return new this.constructor().copy(this)}}const te=new z,Si=new z;class yt{constructor(t=new z,i=new z){this.start=t,this.end=i}set(t,i){return this.start.copy(t),this.end.copy(i),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,i){return this.delta(i).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,i){te.subVectors(t,this.start),Si.subVectors(this.end,this.start);const s=Si.dot(Si);let n=Si.dot(te)/s;return i&&(n=at(n,0,1)),n}closestPointToPoint(t,i,s){const e=this.closestPointToPointParameter(t,i);return this.delta(s).multiplyScalar(e).add(this.start)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return new this.constructor().copy(this)}}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:vi}})),typeof window<"u"&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=vi);const ie=0,Ne=1,qe=2,se=2,fs=1.25,ee=1,oi=6*4+4+4,Bi=65535,De=Math.pow(2,-24),ds=Symbol("SKIP_GENERATION");function Xe(l){return l.index?l.index.count:l.attributes.position.count}function Ot(l){return Xe(l)/3}function We(l,t=ArrayBuffer){return l>65535?new Uint32Array(new t(4*l)):new Uint16Array(new t(2*l))}function Ye(l,t){if(!l.index){const i=l.attributes.position.count,s=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,e=We(i,s);l.setIndex(new ht(e,1));for(let n=0;no-c);for(let o=0;or.offset-a.offset),e=s[s.length-1];e.count=Math.min(i-e.offset,e.count);let n=0;return s.forEach(({count:r})=>n+=r),i!==n}function ms(l,t,i,s,e){let n=1/0,r=1/0,a=1/0,o=-1/0,c=-1/0,h=-1/0,f=1/0,u=1/0,d=1/0,m=-1/0,y=-1/0,x=-1/0;for(let p=t*6,g=(t+i)*6;po&&(o=A),bm&&(m=b);const _=l[p+2],S=l[p+3],B=_-S,T=_+S;Bc&&(c=T),_y&&(y=_);const C=l[p+4],P=l[p+5],E=C-P,F=C+P;Eh&&(h=F),Cx&&(x=C)}s[0]=n,s[1]=r,s[2]=a,s[3]=o,s[4]=c,s[5]=h,e[0]=f,e[1]=u,e[2]=d,e[3]=m,e[4]=y,e[5]=x}function Ze(l,t=null,i=null,s=null){const e=l.attributes.position,n=l.index?l.index.array:null,r=Ot(l),a=e.normalized;let o;t===null?(o=new Float32Array(r*6),i=0,s=r):(o=t,i=i||0,s=s||r);const c=e.array,h=e.offset||0;let f=3;e.isInterleavedBufferAttribute&&(f=e.data.stride);const u=["getX","getY","getZ"];for(let d=i;dS&&(S=w),A>S&&(S=A);const B=(S-_)/2,T=b*2;o[y+T+0]=_+B,o[y+T+1]=B+(Math.abs(_)+B)*De}}return o}function I(l,t,i){return i.min.x=t[l],i.min.y=t[l+1],i.min.z=t[l+2],i.max.x=t[l+3],i.max.y=t[l+4],i.max.z=t[l+5],i}function oe(l){let t=-1,i=-1/0;for(let s=0;s<3;s++){const e=l[s+3]-l[s];e>i&&(i=e,t=s)}return t}function ae(l,t){t.set(l)}function he(l,t,i){let s,e;for(let n=0;n<3;n++){const r=n+3;s=l[n],e=t[n],i[n]=se?s:e}}function Ti(l,t,i){for(let s=0;s<3;s++){const e=t[l+2*s],n=t[l+2*s+1],r=e-n,a=e+n;ri[s+3]&&(i[s+3]=a)}}function ai(l){const t=l[3]-l[0],i=l[4]-l[1],s=l[5]-l[2];return 2*(t*i+i*s+s*t)}const xt=32,ve=(l,t)=>l.candidate-t.candidate,zt=new Array(xt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Pi=new Float32Array(6);function $e(l,t,i,s,e,n){let r=-1,a=0;if(n===ie)r=oe(t),r!==-1&&(a=(t[r]+t[r+3])/2);else if(n===Ne)r=oe(l),r!==-1&&(a=He(i,s,e,r));else if(n===qe){const o=ai(l);let c=fs*e;const h=s*6,f=(s+e)*6;for(let u=0;u<3;u++){const d=t[u],x=(t[u+3]-d)/xt;if(e=_.candidate?Ti(M,i,_.rightCacheBounds):(Ti(M,i,_.leftCacheBounds),_.count++)}}for(let M=0;M=xt&&(A=xt-1);const _=zt[A];_.count++,Ti(b,i,_.bounds)}const p=zt[xt-1];ae(p.bounds,p.rightCacheBounds);for(let b=xt-2;b>=0;b--){const M=zt[b],w=zt[b+1];he(M.bounds,w.rightCacheBounds,M.rightCacheBounds)}let g=0;for(let b=0;b=o;)a--;if(r=o;)a--;if(rJe)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return hi[i+6]=c/4,c=xs(c,a),hi[i+7]=o,c}}function Ke(l,t){const i=(l.index?l.index.count:l.attributes.position.count)/3,s=i>2**16,e=s?4:2,n=t?new SharedArrayBuffer(i*e):new ArrayBuffer(i*e),r=s?new Uint32Array(n):new Uint16Array(n);for(let a=0,o=r.length;a=n&&(p=!0,r&&(console.warn(`MeshBVH: Max depth of ${n} reached when generating BVH. Consider increasing maxDepth.`),console.warn(u))),_<=a||B>=n)return b(A+_),w.offset=A,w.count=_,w;const T=$e(w.boundingData,S,t,A,_,o);if(T.axis===-1)return b(A+_),w.offset=A,w.count=_,w;const C=m(f,d,t,A,_,T);if(C===A||C===A+_)b(A+_),w.offset=A,w.count=_;else{w.splitAxis=T.axis;const P=new ps,E=A,F=C-A;w.left=P,ms(t,E,F,P.boundingData,x),M(P,E,F,x,B+1);const k=new ps,R=C,j=_-F;w.right=k,ms(t,R,j,k.boundingData,x),M(k,R,j,x,B+1)}return w}}function sn(l,t){const i=l.geometry;t.indirect&&(l._indirectBuffer=Ke(i,t.useSharedArrayBuffer),Oe(i,t.range)&&!t.verbose&&console.warn('MeshBVH: Provided geometry contains groups or a range that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),l._indirectBuffer||Ye(i,t);const s=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,e=Ze(i),n=t.indirect?ne(i,t.range):re(i,t.range);l._roots=n.map(r=>{const a=tn(l,e,r.offset,r.count,t),o=ys(a),c=new s(oi*o);return Qe(0,a,c),c})}class gt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,i){let s=1/0,e=-1/0;for(let n=0,r=t.length;ne?o:e}this.min=s,this.max=e}setFromPoints(t,i){let s=1/0,e=-1/0;for(let n=0,r=i.length;ne?o:e}this.min=s,this.max=e}isSeparated(t){return this.min>t.max||t.min>this.max}}gt.prototype.setFromBox=function(){const l=new z;return function(i,s){const e=s.min,n=s.max;let r=1/0,a=-1/0;for(let o=0;o<=1;o++)for(let c=0;c<=1;c++)for(let h=0;h<=1;h++){l.x=e.x*o+n.x*(1-o),l.y=e.y*c+n.y*(1-c),l.z=e.z*h+n.z*(1-h);const f=i.dot(l);r=Math.min(f,r),a=Math.max(f,a)}this.min=r,this.max=a}}();const en=function(){const l=new z,t=new z,i=new z;return function(e,n,r){const a=e.start,o=l,c=n.start,h=t;i.subVectors(a,c),l.subVectors(e.end,e.start),t.subVectors(n.end,n.start);const f=i.dot(h),u=h.dot(o),d=h.dot(h),m=i.dot(o),x=o.dot(o)*d-u*u;let p,g;x!==0?p=(f*u-m*d)/x:p=0,g=(f+p*u)/d,r.x=p,r.y=g}}(),gs=function(){const l=new X,t=new z,i=new z;return function(e,n,r,a){en(e,n,l);let o=l.x,c=l.y;if(o>=0&&o<=1&&c>=0&&c<=1){e.at(o,r),n.at(c,a);return}else if(o>=0&&o<=1){c<0?n.at(0,a):n.at(1,a),e.closestPointToPoint(a,!0,r);return}else if(c>=0&&c<=1){o<0?e.at(0,r):e.at(1,r),n.closestPointToPoint(r,!0,a);return}else{let h;o<0?h=e.start:h=e.end;let f;c<0?f=n.start:f=n.end;const u=t,d=i;if(e.closestPointToPoint(f,!0,t),n.closestPointToPoint(h,!0,i),u.distanceToSquared(f)<=d.distanceToSquared(h)){r.copy(u),a.copy(f);return}else{r.copy(h),a.copy(d);return}}}}(),nn=function(){const l=new z,t=new z,i=new Ks,s=new yt;return function(n,r){const{radius:a,center:o}=n,{a:c,b:h,c:f}=r;if(s.start=c,s.end=h,s.closestPointToPoint(o,!0,l).distanceTo(o)<=a||(s.start=c,s.end=f,s.closestPointToPoint(o,!0,l).distanceTo(o)<=a)||(s.start=h,s.end=f,s.closestPointToPoint(o,!0,l).distanceTo(o)<=a))return!0;const y=r.getPlane(i);if(Math.abs(y.distanceToPoint(o))<=a){const p=y.projectPoint(o,t);if(r.containsPoint(p))return!0}return!1}}(),rn=1e-15;function ws(l){return Math.abs(l)new z),this.satBounds=new Array(4).fill().map(()=>new gt),this.points=[this.a,this.b,this.c],this.sphere=new Os,this.plane=new Ks,this.needsUpdate=!0}intersectsSphere(t){return nn(t,this)}update(){const t=this.a,i=this.b,s=this.c,e=this.points,n=this.satAxes,r=this.satBounds,a=n[0],o=r[0];this.getNormal(a),o.setFromPoints(a,e);const c=n[1],h=r[1];c.subVectors(t,i),h.setFromPoints(c,e);const f=n[2],u=r[2];f.subVectors(i,s),u.setFromPoints(f,e);const d=n[3],m=r[3];d.subVectors(s,t),m.setFromPoints(d,e),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}rt.prototype.closestPointToSegment=function(){const l=new z,t=new z,i=new yt;return function(e,n=null,r=null){const{start:a,end:o}=e,c=this.points;let h,f=1/0;for(let u=0;u<3;u++){const d=(u+1)%3;i.start.copy(c[u]),i.end.copy(c[d]),gs(i,e,l,t),h=l.distanceToSquared(t),h=2){(M===1?p.start:p.end).copy(d),b=2;break}if(b++,b===2&&M===-1)break}}return b}return function(x,p=null,g=!1){this.needsUpdate&&this.update(),x.isExtendedTriangle?x.needsUpdate&&x.update():(l.copy(x),l.update(),x=l);const b=this.plane,M=x.plane;if(Math.abs(b.normal.dot(M.normal))>1-1e-10){const w=this.satBounds,A=this.satAxes;i[0]=x.a,i[1]=x.b,i[2]=x.c;for(let B=0;B<4;B++){const T=w[B],C=A[B];if(s.setFromPoints(C,i),T.isSeparated(s))return!1}const _=x.satBounds,S=x.satAxes;t[0]=this.a,t[1]=this.b,t[2]=this.c;for(let B=0;B<4;B++){const T=_[B],C=S[B];if(s.setFromPoints(C,t),T.isSeparated(s))return!1}for(let B=0;B<4;B++){const T=A[B];for(let C=0;C<4;C++){const P=S[C];if(n.crossVectors(T,P),s.setFromPoints(n,t),e.setFromPoints(n,i),s.isSeparated(e))return!1}}return p&&(g||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),p.start.set(0,0,0),p.end.set(0,0,0)),!0}else{const w=m(this,M,f);if(w===1&&x.containsPoint(f.end))return p&&(p.start.copy(f.end),p.end.copy(f.end)),!0;if(w!==2)return!1;const A=m(x,b,u);if(A===1&&this.containsPoint(u.end))return p&&(p.start.copy(u.end),p.end.copy(u.end)),!0;if(A!==2)return!1;if(f.delta(a),u.delta(o),a.dot(o)<0){let E=u.start;u.start=u.end,u.end=E}const _=f.start.dot(a),S=f.end.dot(a),B=u.start.dot(a),T=u.end.dot(a),C=S0?p.start.copy(f.start):p.start.copy(u.start),c.subVectors(f.end,u.end),c.dot(a)<0?p.end.copy(f.end):p.end.copy(u.end)),!0)}}}(),rt.prototype.distanceToPoint=function(){const l=new z;return function(i){return this.closestPointToPoint(i,l),i.distanceTo(l)}}(),rt.prototype.distanceToTriangle=function(){const l=new z,t=new z,i=["a","b","c"],s=new yt,e=new yt;return function(r,a=null,o=null){const c=a||o?s:null;if(this.intersectsTriangle(r,c))return(a||o)&&(a&&c.getCenter(a),o&&c.getCenter(o)),0;let h=1/0;for(let f=0;f<3;f++){let u;const d=i[f],m=r[d];this.closestPointToPoint(m,l),u=m.distanceToSquared(l),unew z),this.satAxes=new Array(3).fill().map(()=>new z),this.satBounds=new Array(3).fill().map(()=>new gt),this.alignedSatBounds=new Array(3).fill().map(()=>new gt),this.needsUpdate=!1,t&&this.min.copy(t),i&&this.max.copy(i),s&&this.matrix.copy(s)}set(t,i,s){this.min.copy(t),this.max.copy(i),this.matrix.copy(s),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}Y.prototype.update=function(){return function(){const t=this.matrix,i=this.min,s=this.max,e=this.points;for(let c=0;c<=1;c++)for(let h=0;h<=1;h++)for(let f=0;f<=1;f++){const u=1*c|2*h|4*f,d=e[u];d.x=c?s.x:i.x,d.y=h?s.y:i.y,d.z=f?s.z:i.z,d.applyMatrix4(t)}const n=this.satBounds,r=this.satAxes,a=e[0];for(let c=0;c<3;c++){const h=r[c],f=n[c],u=1<new yt),i=new Array(12).fill().map(()=>new yt),s=new z,e=new z;return function(r,a=0,o=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(o||c)&&(r.getCenter(e),this.closestPointToPoint(e,s),r.closestPointToPoint(s,e),o&&o.copy(s),c&&c.copy(e)),0;const h=a*a,f=r.min,u=r.max,d=this.points;let m=1/0;for(let x=0;x<8;x++){const p=d[x];e.copy(p).clamp(f,u);const g=p.distanceToSquared(e);if(gnew rt)}}const it=new on;class an{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let i=null;this.setBuffer=s=>{i&&t.push(i),i=s,this.float32Array=new Float32Array(s),this.uint16Array=new Uint16Array(s),this.uint32Array=new Uint32Array(s)},this.clearBuffer=()=>{i=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const U=new an;let At,Zt;const vt=[],Ei=new bs(()=>new W);function hn(l,t,i,s,e,n){At=Ei.getPrimitive(),Zt=Ei.getPrimitive(),vt.push(At,Zt),U.setBuffer(l._roots[t]);const r=Ms(0,l.geometry,i,s,e,n);U.clearBuffer(),Ei.releasePrimitive(At),Ei.releasePrimitive(Zt),vt.pop(),vt.pop();const a=vt.length;return a>0&&(Zt=vt[a-1],At=vt[a-2]),r}function Ms(l,t,i,s,e=null,n=0,r=0){const{float32Array:a,uint16Array:o,uint32Array:c}=U;let h=l*2;if(Z(h,o)){const u=H(l,c),d=Q(h,o);return I(l,a,At),s(u,d,!1,r,n+l,At)}else{let T=function(P){const{uint16Array:E,uint32Array:F}=U;let k=P*2;for(;!Z(k,E);)P=K(P),k=P*2;return H(P,F)},C=function(P){const{uint16Array:E,uint32Array:F}=U;let k=P*2;for(;!Z(k,E);)P=tt(P,F),k=P*2;return H(P,F)+Q(k,E)};const u=K(l),d=tt(l,c);let m=u,y=d,x,p,g,b;if(e&&(g=At,b=Zt,I(m,a,g),I(y,a,b),x=e(g),p=e(b),p(ci.copy(t).clamp(h.min,h.max),ci.distanceToSquared(t)),intersectsBounds:(h,f,u)=>u{h.closestPointToPoint(t,ci);const u=t.distanceToSquared(ci);return u=169,Et=new z,Ft=new z,kt=new z,Fi=new X,ki=new X,Ri=new X,fe=new z,de=new z,me=new z,li=new z;function un(l,t,i,s,e,n,r,a){let o;if(n===1?o=l.intersectTriangle(s,i,t,!0,e):o=l.intersectTriangle(t,i,s,n!==2,e),o===null)return null;const c=l.origin.distanceTo(e);return ca?null:{distance:c,point:e.clone()}}function fn(l,t,i,s,e,n,r,a,o,c,h){Et.fromBufferAttribute(t,n),Ft.fromBufferAttribute(t,r),kt.fromBufferAttribute(t,a);const f=un(l,Et,Ft,kt,li,o,c,h);if(f){const u=new z;G.getBarycoord(li,Et,Ft,kt,u),s&&(Fi.fromBufferAttribute(s,n),ki.fromBufferAttribute(s,r),Ri.fromBufferAttribute(s,a),f.uv=G.getInterpolation(li,Et,Ft,kt,Fi,ki,Ri,new X)),e&&(Fi.fromBufferAttribute(e,n),ki.fromBufferAttribute(e,r),Ri.fromBufferAttribute(e,a),f.uv1=G.getInterpolation(li,Et,Ft,kt,Fi,ki,Ri,new X)),i&&(fe.fromBufferAttribute(i,n),de.fromBufferAttribute(i,r),me.fromBufferAttribute(i,a),f.normal=G.getInterpolation(li,Et,Ft,kt,fe,de,me,new z),f.normal.dot(l.direction)>0&&f.normal.multiplyScalar(-1));const d={a:n,b:r,c:a,normal:new z,materialIndex:0};G.getNormal(Et,Ft,kt,d.normal),f.face=d,f.faceIndex=n,ln&&(f.barycoord=u)}return f}function Ui(l,t,i,s,e,n,r){const a=s*3;let o=a+0,c=a+1,h=a+2;const f=l.index;l.index&&(o=f.getX(o),c=f.getX(c),h=f.getX(h));const{position:u,normal:d,uv:m,uv1:y}=l.attributes,x=fn(i,u,d,m,y,o,c,h,t,n,r);return x?(x.faceIndex=s,e&&e.push(x),x):null}function V(l,t,i,s){const e=l.a,n=l.b,r=l.c;let a=t,o=t+1,c=t+2;i&&(a=i.getX(a),o=i.getX(o),c=i.getX(c)),e.x=s.getX(a),e.y=s.getY(a),e.z=s.getZ(a),n.x=s.getX(o),n.y=s.getY(o),n.z=s.getZ(o),r.x=s.getX(c),r.y=s.getY(c),r.z=s.getZ(c)}function dn(l,t,i,s,e,n,r,a){const{geometry:o,_indirectBuffer:c}=l;for(let h=s,f=s+e;hA&&(A=P),E_&&(_=E),FS&&(S=F)}return o[u+0]!==b||o[u+1]!==M||o[u+2]!==w||o[u+3]!==A||o[u+4]!==_||o[u+5]!==S?(o[u+0]=b,o[u+1]=M,o[u+2]=w,o[u+3]=A,o[u+4]=_,o[u+5]=S,!0):!1}else{const p=u+8,g=r[u+6],b=p+d,M=g+d;let w=m,A=!1,_=!1;t?w||(A=t.has(b),_=t.has(M),w=!A&&!_):(A=!0,_=!0);const S=w||A,B=w||_;let T=!1;S&&(T=f(p,d,w));let C=!1;B&&(C=f(g,d,w));const P=T||C;if(P)for(let E=0;E<3;E++){const F=p+E,k=g+E,R=o[F],j=o[F+3],ct=o[k],lt=o[k+3];o[u+E]=Rlt?j:lt}return P}}}function St(l,t,i,s,e){let n,r,a,o,c,h;const f=1/i.direction.x,u=1/i.direction.y,d=1/i.direction.z,m=i.origin.x,y=i.origin.y,x=i.origin.z;let p=t[l],g=t[l+3],b=t[l+1],M=t[l+3+1],w=t[l+2],A=t[l+3+2];return f>=0?(n=(p-m)*f,r=(g-m)*f):(n=(g-m)*f,r=(p-m)*f),u>=0?(a=(b-y)*u,o=(M-y)*u):(a=(M-y)*u,o=(b-y)*u),n>o||a>r||((a>n||isNaN(n))&&(n=a),(o=0?(c=(w-x)*d,h=(A-x)*d):(c=(A-x)*d,h=(w-x)*d),n>h||c>r)?!1:((c>n||n!==n)&&(n=c),(h=s)}function xn(l,t,i,s,e,n,r,a){const{geometry:o,_indirectBuffer:c}=l;for(let h=s,f=s+e;h=0;let y,x;m?(y=K(l),x=tt(l,o)):(y=tt(l,o),x=K(l));const g=St(y,r,s,e,n)?As(y,t,i,s,e,n):null;if(g){const w=g.point[u];if(m?w<=r[x+f]:w>=r[x+f+3])return g}const M=St(x,r,s,e,n)?As(x,t,i,s,e,n):null;return g&&M?g.distance<=M.distance?g:M:g||M||null}}const Ii=new W,$t=new rt,Ht=new rt,ui=new q,pe=new Y,Li=new Y;function zn(l,t,i,s){U.setBuffer(l._roots[t]);const e=Ss(0,l,i,s);return U.clearBuffer(),e}function Ss(l,t,i,s,e=null){const{float32Array:n,uint16Array:r,uint32Array:a}=U;let o=l*2;if(e===null&&(i.boundingBox||i.computeBoundingBox(),pe.set(i.boundingBox.min,i.boundingBox.max,s),e=pe),Z(o,r)){const h=t.geometry,f=h.index,u=h.attributes.position,d=i.index,m=i.attributes.position,y=H(l,a),x=Q(o,r);if(ui.copy(s).invert(),i.boundsTree)return I(l,n,Li),Li.matrix.copy(ui),Li.needsUpdate=!0,i.boundsTree.shapecast({intersectsBounds:g=>Li.intersectsBox(g),intersectsTriangle:g=>{g.a.applyMatrix4(s),g.b.applyMatrix4(s),g.c.applyMatrix4(s),g.needsUpdate=!0;for(let b=y*3,M=(x+y)*3;bBs.distanceToBox(w),intersectsBounds:(w,A,_)=>_{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:S=>fi.distanceToBox(S),intersectsBounds:(S,B,T)=>T{for(let T=S,C=S+B;TA&&(A=F),k_&&(_=k),RS&&(S=R)}}return o[u+0]!==b||o[u+1]!==M||o[u+2]!==w||o[u+3]!==A||o[u+4]!==_||o[u+5]!==S?(o[u+0]=b,o[u+1]=M,o[u+2]=w,o[u+3]=A,o[u+4]=_,o[u+5]=S,!0):!1}else{const p=u+8,g=r[u+6],b=p+d,M=g+d;let w=m,A=!1,_=!1;t?w||(A=t.has(b),_=t.has(M),w=!A&&!_):(A=!0,_=!0);const S=w||A,B=w||_;let T=!1;S&&(T=f(p,d,w));let C=!1;B&&(C=f(g,d,w));const P=T||C;if(P)for(let E=0;E<3;E++){const F=p+E,k=g+E,R=o[F],j=o[F+3],ct=o[k],lt=o[k+3];o[u+E]=Rlt?j:lt}return P}}}function En(l,t,i,s,e,n,r){U.setBuffer(l._roots[t]),Ts(0,l,i,s,e,n,r),U.clearBuffer()}function Ts(l,t,i,s,e,n,r){const{float32Array:a,uint16Array:o,uint32Array:c}=U,h=l*2;if(Z(h,o)){const u=H(l,c),d=Q(h,o);xn(t,i,s,u,d,e,n,r)}else{const u=K(l);St(u,a,s,n,r)&&Ts(u,t,i,s,e,n,r);const d=tt(l,c);St(d,a,s,n,r)&&Ts(d,t,i,s,e,n,r)}}const Fn=["x","y","z"];function kn(l,t,i,s,e,n){U.setBuffer(l._roots[t]);const r=Ps(0,l,i,s,e,n);return U.clearBuffer(),r}function Ps(l,t,i,s,e,n){const{float32Array:r,uint16Array:a,uint32Array:o}=U;let c=l*2;if(Z(c,a)){const f=H(l,o),u=Q(c,a);return gn(t,i,s,f,u,e,n)}else{const f=ce(l,o),u=Fn[f],m=s.direction[u]>=0;let y,x;m?(y=K(l),x=tt(l,o)):(y=tt(l,o),x=K(l));const g=St(y,r,s,e,n)?Ps(y,t,i,s,e,n):null;if(g){const w=g.point[u];if(m?w<=r[x+f]:w>=r[x+f+3])return g}const M=St(x,r,s,e,n)?Ps(x,t,i,s,e,n):null;return g&&M?g.distance<=M.distance?g:M:g||M||null}}const Ni=new W,jt=new rt,Gt=new rt,di=new q,ye=new Y,qi=new Y;function Rn(l,t,i,s){U.setBuffer(l._roots[t]);const e=Cs(0,l,i,s);return U.clearBuffer(),e}function Cs(l,t,i,s,e=null){const{float32Array:n,uint16Array:r,uint32Array:a}=U;let o=l*2;if(e===null&&(i.boundingBox||i.computeBoundingBox(),ye.set(i.boundingBox.min,i.boundingBox.max,s),e=ye),Z(o,r)){const h=t.geometry,f=h.index,u=h.attributes.position,d=i.index,m=i.attributes.position,y=H(l,a),x=Q(o,r);if(di.copy(s).invert(),i.boundsTree)return I(l,n,qi),qi.matrix.copy(di),qi.needsUpdate=!0,i.boundsTree.shapecast({intersectsBounds:g=>qi.intersectsBox(g),intersectsTriangle:g=>{g.a.applyMatrix4(s),g.b.applyMatrix4(s),g.c.applyMatrix4(s),g.needsUpdate=!0;for(let b=y,M=x+y;bEs.distanceToBox(w),intersectsBounds:(w,A,_)=>_{if(t.boundsTree){const _=t.boundsTree;return _.shapecast({boundsTraverseOrder:S=>mi.distanceToBox(S),intersectsBounds:(S,B,T)=>T{for(let T=S,C=S+B;Tnew W),Jt=new W,Qt=new W,Fs=new W,ks=new W;let Rs=!1;function Dn(l,t,i,s){if(Rs)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Rs=!0;const e=l._roots,n=t._roots;let r,a=0,o=0;const c=new q().copy(i).invert();for(let h=0,f=e.length;ho.slice()),index:r?r.array.slice():null,indirectBuffer:n?n.slice():null}:a={roots:e,index:r?r.array:null,indirectBuffer:n},a}static deserialize(t,i,s={}){s={setIndex:!0,indirect:!!t.indirectBuffer,...s};const{index:e,roots:n,indirectBuffer:r}=t,a=new Yi(i,{...s,[ds]:!0});if(a._roots=n,a._indirectBuffer=r||null,s.setIndex){const o=i.getIndex();if(o===null){const c=new ht(t.index,1,!1);i.setIndex(c)}else o.array!==e&&(o.array.set(e),o.needsUpdate=!0)}return a}get indirect(){return!!this._indirectBuffer}constructor(t,i={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(i=Object.assign({...Xn,[ds]:!1},i),i.useSharedArrayBuffer&&!qn())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,i[ds]||(sn(this,i),!t.boundingBox&&i.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new W))),this.resolveTriangleIndex=i.indirect?s=>this._indirectBuffer[s]:s=>s}refit(t=null){return(this.indirect?Cn:yn)(this,t)}traverse(t,i=0){const s=this._roots[i],e=new Uint32Array(s),n=new Uint16Array(s);r(0);function r(a,o=0){const c=a*2,h=n[c+15]===Bi;if(h){const f=e[a+6],u=n[c+14];t(o,h,new Float32Array(s,a*4,6),f,u)}else{const f=a+oi/4,u=e[a+6],d=e[a+7];t(o,h,new Float32Array(s,a*4,6),d)||(r(f,o+1),r(u,o+1))}}}raycast(t,i=0,s=0,e=1/0){const n=this._roots,r=this.geometry,a=[],o=i.isMaterial,c=Array.isArray(i),h=r.groups,f=o?i.side:i,u=this.indirect?En:bn;for(let d=0,m=n.length;df(u,d,m,y,x)?!0:s(u,d,this,a,m,y,i)}else r||(a?r=(f,u,d,m)=>s(f,u,this,a,d,m,i):r=(f,u,d)=>d);let o=!1,c=0;const h=this._roots;for(let f=0,u=h.length;f{const y=this.resolveTriangleIndex(m);V(r,y*3,a,o)}:m=>{V(r,m*3,a,o)},h=it.getPrimitive(),f=t.geometry.index,u=t.geometry.attributes.position,d=t.indirect?m=>{const y=t.resolveTriangleIndex(m);V(h,y*3,f,u)}:m=>{V(h,m*3,f,u)};if(n){const m=(y,x,p,g,b,M,w,A)=>{for(let _=p,S=p+g;_Wi.intersectsBox(s),intersectsTriangle:s=>Wi.intersectsTriangle(s)})}intersectsSphere(t){return this.shapecast({intersectsBounds:i=>t.intersectsBox(i),intersectsTriangle:i=>i.intersectsSphere(t)})}closestPointToGeometry(t,i,s={},e={},n=0,r=1/0){return(this.indirect?Nn:Pn)(this,t,i,s,e,n,r)}closestPointToPoint(t,i={},s=0,e=1/0){return cn(this,t,i,s,e)}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(s=>{I(0,new Float32Array(s),xe),t.union(xe)}),t}}onmessage=({data:l})=>{let t=performance.now();function i(r){r=Math.min(r,1);const a=performance.now();a-t>=10&&r!==1&&(postMessage({error:null,serialized:null,position:null,progress:r}),t=a)}const{index:s,position:e,options:n}=l;try{const r=new ls;if(r.setAttribute("position",new ht(e,3,!1)),s&&r.setIndex(new ht(s,1,!1)),n.includedProgressCallback&&(n.onProgress=i),n.groups){const h=n.groups;for(const f in h){const u=h[f];r.addGroup(u.start,u.count,u.materialIndex)}}const a=new Yi(r,n),o=Yi.serialize(a,{copyIndexBuffer:!1});let c=[e.buffer,...o.roots];o.index&&c.push(o.index.buffer),c=c.filter(h=>typeof SharedArrayBuffer>"u"||!(h instanceof SharedArrayBuffer)),a._indirectBuffer&&c.push(o.indirectBuffer.buffer),postMessage({error:null,serialized:o,position:e,progress:1},c)}catch(r){postMessage({error:r,serialized:null,position:null,progress:1})}}})(); diff --git a/example/bundle/assets/gpuPathTracing-qHS4Iprb.js b/example/bundle/assets/gpuPathTracing-qHS4Iprb.js new file mode 100644 index 000000000..7d99853d3 --- /dev/null +++ b/example/bundle/assets/gpuPathTracing-qHS4Iprb.js @@ -0,0 +1,108 @@ +import{W as F,c as R,D as O,A as E,P as I,S as W,n as x,s as _,M as A,g as D,aa as L,a0 as T,F as U,H,f as j}from"./ExtendedTriangle-CNpFv597.js";import{F as b}from"./Pass-Bx56TwXN.js";import{G as z}from"./GLTFLoader-CPZ_tJoX.js";import{O as B}from"./OrbitControls-I50Ha_kb.js";import{m as G}from"./BufferGeometryUtils-BjOdgyuH.js";import{S as V}from"./stats.min-GTpOrGrX.js";import{g as N}from"./lil-gui.module.min-Bc0DeA9g.js";import{M as k,F as $}from"./MeshBVHUniformStruct-CwgYze0J.js";import{M as Q,S as X}from"./MeshBVH-ujCvfObx.js";import{c as Y,b as q,a as J}from"./bvh_struct_definitions.glsl-SZg5BxSQ.js";import"./_commonjsHelpers-Cpj98o6Y.js";const o={enableRaytracing:!0,smoothImageScaling:!0,resolutionScale:.5/window.devicePixelRatio,bounces:3,accumulate:!0};let e,t,l,i,h,s,P,m,c,d=0,M;K();S();function K(){e=new F({antialias:!1}),e.setPixelRatio(window.devicePixelRatio),e.setClearColor(594970),e.setSize(window.innerWidth,window.innerHeight),e.outputEncoding=void 0,document.body.appendChild(e.domElement),M=document.getElementById("output"),l=new R;const n=new O(16777215,1);n.position.set(1,1,1),l.add(n),l.add(new E(11583173,.5)),t=new I(75,window.innerWidth/window.innerHeight,.1,50),t.position.set(-2,2,3),t.far=100,t.updateProjectionMatrix(),h=new V,document.body.appendChild(h.dom);const a=new W({defines:{BOUNCES:5},uniforms:{bvh:{value:new k},normalAttribute:{value:new $},cameraWorldMatrix:{value:new x},invProjectionMatrix:{value:new x},seed:{value:0},opacity:{value:1}},vertexShader:` + + varying vec2 vUv; + void main() { + + vec4 mvPosition = vec4( position, 1.0 ); + mvPosition = modelViewMatrix * mvPosition; + gl_Position = projectionMatrix * mvPosition; + + vUv = uv; + + } + + `,fragmentShader:` + #define RAY_OFFSET 1e-5 + + precision highp isampler2D; + precision highp usampler2D; + ${Y} + ${q} + ${J} + #include + + uniform mat4 cameraWorldMatrix; + uniform mat4 invProjectionMatrix; + uniform sampler2D normalAttribute; + uniform BVH bvh; + uniform float seed; + uniform float opacity; + varying vec2 vUv; + + void main() { + + // get [-1, 1] normalized device coordinates + vec2 ndc = 2.0 * vUv - vec2( 1.0 ); + vec3 rayOrigin, rayDirection; + ndcToCameraRay( ndc, cameraWorldMatrix, invProjectionMatrix, rayOrigin, rayDirection ); + + // Lambertian render + gl_FragColor = vec4( 0.0 ); + + vec3 throughputColor = vec3( 1.0 ); + vec3 randomPoint = vec3( .0 ); + + // hit results + uvec4 faceIndices = uvec4( 0u ); + vec3 faceNormal = vec3( 0.0, 0.0, 1.0 ); + vec3 barycoord = vec3( 0.0 ); + float side = 1.0; + float dist = 0.0; + + for ( int i = 0; i < BOUNCES; i ++ ) { + + if ( ! bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist ) ) { + + float value = ( rayDirection.y + 0.5 ) / 1.5; + vec3 skyColor = mix( vec3( 1.0 ), vec3( 0.75, 0.85, 1.0 ), value ); + + gl_FragColor = vec4( skyColor * throughputColor * 2.0, 1.0 ); + + break; + + } + + // 1 / PI attenuation for physically correct lambert model + // https://www.rorydriscoll.com/2009/01/25/energy-conservation-in-games/ + throughputColor *= 1.0 / PI; + + randomPoint = vec3( + rand( vUv + float( i + 1 ) + vec2( seed, seed ) ), + rand( - vUv * seed + float( i ) - seed ), + rand( - vUv * float( i + 1 ) - vec2( seed, - seed ) ) + ); + randomPoint -= 0.5; + randomPoint *= 2.0; + + // ensure the random vector is not 0,0,0 and that it won't exactly negate + // the surface normal + + float pointLength = max( length( randomPoint ), 1e-4 ); + randomPoint /= pointLength; + randomPoint *= 0.999; + + // fetch the interpolated smooth normal + vec3 normal = + side * + textureSampleBarycoord( + normalAttribute, + barycoord, + faceIndices.xyz + ).xyz; + + // adjust the hit point by the surface normal by a factor of some offset and the + // maximum component-wise value of the current point to accommodate floating point + // error as values increase. + vec3 point = rayOrigin + rayDirection * dist; + vec3 absPoint = abs( point ); + float maxPoint = max( absPoint.x, max( absPoint.y, absPoint.z ) ); + rayOrigin = point + faceNormal * ( maxPoint + 1.0 ) * RAY_OFFSET; + rayDirection = normalize( normal + randomPoint ); + + } + + gl_FragColor.a = opacity; + + } + + `});s=new b(a),a.transparent=!0,a.depthWrite=!1,new z().load("https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/dragon-attenuation/DragonAttenuation.glb",v=>{let g;v.scene.traverse(f=>{f.isMesh&&f.name==="Dragon"&&(g=f,f.geometry.scale(.25,.25,.25).rotateX(Math.PI/2))});const w=new _(5,5,1,1);w.rotateX(-Math.PI/2);const y=G([w,g.geometry],!1);y.translate(0,-.5,0),c=new A(y,new D),l.add(c);const C=new Q(c.geometry,{maxLeafTris:1,strategy:X});a.uniforms.bvh.value.updateFrom(C),a.uniforms.normalAttribute.value.updateFrom(c.geometry.attributes.normal)});const r=e.extensions.get("OES_texture_float_linear");m=new L(1,1,{format:T,type:r?U:H}),P=new b(new j({map:m.texture})),new B(t,e.domElement).addEventListener("change",()=>{u()}),i=new N,i.add(o,"enableRaytracing").name("enable"),i.add(o,"accumulate"),i.add(o,"smoothImageScaling"),i.add(o,"resolutionScale",.1,1,.01).onChange(p),i.add(o,"bounces",1,10,1).onChange(v=>{a.defines.BOUNCES=parseInt(v),a.needsUpdate=!0,u()}),i.open(),window.addEventListener("resize",p,!1),p()}function u(){d=0}function p(){t.aspect=window.innerWidth/window.innerHeight,t.updateProjectionMatrix();const n=window.innerWidth,a=window.innerHeight,r=window.devicePixelRatio*o.resolutionScale;e.setSize(n,a),e.setPixelRatio(r),m.setSize(n*r,a*r),u()}function S(){if(h.update(),requestAnimationFrame(S),e.domElement.style.imageRendering=o.smoothImageScaling?"auto":"pixelated",c&&o.enableRaytracing){if(o.accumulate)if(d===0)t.clearViewOffset();else{const a=m.width,r=m.height;t.setViewOffset(a,r,Math.random()-.5,Math.random()-.5,a,r)}else u();t.updateMatrixWorld();const n=(s.material.uniforms.seed.value+.11111)%2;s.material.uniforms.seed.value=n,s.material.uniforms.cameraWorldMatrix.value.copy(t.matrixWorld),s.material.uniforms.invProjectionMatrix.value.copy(t.projectionMatrixInverse),s.material.uniforms.opacity.value=1/(d+1),e.autoClear=d===0,e.setRenderTarget(m),s.render(e),e.setRenderTarget(null),P.render(e),e.autoClear=!0,d++}else u(),t.clearViewOffset(),e.render(l,t);M.innerText=`samples: ${d}`} diff --git a/example/bundle/assets/gpuPathTracingSimple-BIA0EFOj.js b/example/bundle/assets/gpuPathTracingSimple-BIA0EFOj.js new file mode 100644 index 000000000..561688473 --- /dev/null +++ b/example/bundle/assets/gpuPathTracingSimple-BIA0EFOj.js @@ -0,0 +1,67 @@ +import{W as h,c as M,D as x,A as g,P as b,T as y,M as S,g as P,S as H,n as l,h as O}from"./ExtendedTriangle-CNpFv597.js";import{O as W}from"./OrbitControls-I50Ha_kb.js";import{F as R}from"./Pass-Bx56TwXN.js";import{S as A}from"./stats.min-GTpOrGrX.js";import{g as C}from"./lil-gui.module.min-Bc0DeA9g.js";import{M as _,S as D}from"./MeshBVH-ujCvfObx.js";import{M as F,F as j}from"./MeshBVHUniformStruct-CwgYze0J.js";import{c as L,b as N,a as T}from"./bvh_struct_definitions.glsl-SZg5BxSQ.js";import"./_commonjsHelpers-Cpj98o6Y.js";const r={enableRaytracing:!0,animate:!0,resolutionScale:1/window.devicePixelRatio,smoothNormals:!0};let e,i,o,n,u,d,s,f;z();w();function z(){e=new h({antialias:!1}),e.setPixelRatio(window.devicePixelRatio),e.setClearColor(594970),e.setSize(window.innerWidth,window.innerHeight),e.outputEncoding=void 0,document.body.appendChild(e.domElement),o=new M;const a=new x(16777215,1);a.position.set(1,1,1),o.add(a),o.add(new g(11583173,.5)),i=new b(75,window.innerWidth/window.innerHeight,.1,50),i.position.set(0,0,4),i.far=100,i.updateProjectionMatrix(),u=new A,document.body.appendChild(u.dom);const t=new y(1,.3,300,50),c=new _(t,{maxLeafTris:1,strategy:D});s=new S(t,new P),o.add(s),f=new O;const m=new H({defines:{SMOOTH_NORMALS:1},uniforms:{bvh:{value:new F},normalAttribute:{value:new j},cameraWorldMatrix:{value:new l},invProjectionMatrix:{value:new l},invModelMatrix:{value:new l}},vertexShader:` + + varying vec2 vUv; + void main() { + + vec4 mvPosition = vec4( position, 1.0 ); + mvPosition = modelViewMatrix * mvPosition; + gl_Position = projectionMatrix * mvPosition; + + vUv = uv; + + } + + `,fragmentShader:` + precision highp isampler2D; + precision highp usampler2D; + + ${L} + ${N} + ${T} + + uniform mat4 cameraWorldMatrix; + uniform mat4 invProjectionMatrix; + uniform mat4 invModelMatrix; + uniform sampler2D normalAttribute; + uniform BVH bvh; + varying vec2 vUv; + + void main() { + + // get [-1, 1] normalized device coordinates + vec2 ndc = 2.0 * vUv - vec2( 1.0 ); + vec3 rayOrigin, rayDirection; + ndcToCameraRay( + ndc, invModelMatrix * cameraWorldMatrix, invProjectionMatrix, + rayOrigin, rayDirection + ); + + // hit results + uvec4 faceIndices = uvec4( 0u ); + vec3 faceNormal = vec3( 0.0, 0.0, 1.0 ); + vec3 barycoord = vec3( 0.0 ); + float side = 1.0; + float dist = 0.0; + + // get intersection + bool didHit = bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist ); + + #if SMOOTH_NORMALS + + vec3 normal = textureSampleBarycoord( + normalAttribute, + barycoord, + faceIndices.xyz + ).xyz; + + #else + + vec3 normal = face.normal; + + #endif + + // set the color + gl_FragColor = ! didHit ? vec4( 0.0366, 0.0813, 0.1057, 1.0 ) : vec4( normal, 1.0 ); + + } + `});d=new R(m),m.uniforms.bvh.value.updateFrom(c),m.uniforms.normalAttribute.value.updateFrom(t.attributes.normal),new W(i,e.domElement),n=new C,n.add(r,"enableRaytracing"),n.add(r,"animate"),n.add(r,"smoothNormals").onChange(p=>{d.material.defines.SMOOTH_NORMALS=Number(p),d.material.needsUpdate=!0}),n.add(r,"resolutionScale",.1,1,.01).onChange(v),n.open(),window.addEventListener("resize",v,!1),v()}function v(){i.aspect=window.innerWidth/window.innerHeight,i.updateProjectionMatrix();const a=window.innerWidth,t=window.innerHeight,c=window.devicePixelRatio*r.resolutionScale;e.setSize(a,t),e.setPixelRatio(c)}function w(){u.update(),requestAnimationFrame(w);const a=f.getDelta();if(r.animate&&(s.rotation.y+=a),r.enableRaytracing){i.updateMatrixWorld(),s.updateMatrixWorld();const t=d.material.uniforms;t.cameraWorldMatrix.value.copy(i.matrixWorld),t.invProjectionMatrix.value.copy(i.projectionMatrixInverse),t.invModelMatrix.value.copy(s.matrixWorld).invert(),d.render(e)}else e.render(o,i)} diff --git a/example/bundle/assets/inspector-B-d8VBog.js b/example/bundle/assets/inspector-B-d8VBog.js new file mode 100644 index 000000000..93abb466a --- /dev/null +++ b/example/bundle/assets/inspector-B-d8VBog.js @@ -0,0 +1,68 @@ +import{M as $,i as R,J as z,C as x,W as _,aa as U,R as I,F as j,c as G,P as N,f as Q,a8 as q,ab as J,v as X,k as Y,V as K,S as Z}from"./ExtendedTriangle-CNpFv597.js";import{O as ee}from"./OrbitControls-I50Ha_kb.js";import{G as te}from"./GLTFLoader-CPZ_tJoX.js";import{F as oe}from"./Pass-Bx56TwXN.js";import{g as ae}from"./lil-gui.module.min-Bc0DeA9g.js";import{M as re}from"./MeshBVHHelper-DbtlD37d.js";import{C as ne,A as ie,S as O}from"./MeshBVH-ujCvfObx.js";import{g as se,e as B}from"./Debug-CxembHqK.js";import{a as le,c as de,d as me}from"./ExtensionUtilities-DGy5CKFv.js";import"./BufferGeometryUtils-BjOdgyuH.js";$.prototype.raycast=le;R.prototype.computeBoundsTree=de;R.prototype.disposeBoundsTree=me;let w,c,o,u,a,S,L,l,h,s,M=new z;const P=new Float32Array(1),ce="https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/dragon-attenuation/DragonAttenuation.glb",e={options:{strategy:O,maxLeafTris:10,maxDepth:40,rebuild:function(){D()}},visualization:{displayMesh:!0,simpleColors:!1,outline:!0,traversalThreshold:50},benchmark:{displayRays:!1,firstHitOnly:!0,rotations:10,castCount:1e3}},ue=new x(16770670).convertLinearToSRGB().getHex(),fe=25453,he=16081063;class pe extends Z{constructor(n){super({uniforms:{map:{value:null},threshold:{value:35},boundsColor:{value:new x(16777215)},backgroundColor:{value:new x(0)},thresholdColor:{value:new x(16711680)},resolution:{value:new z},outlineAlpha:{value:.5}},vertexShader:` + varying vec2 vUv; + void main() { + + vUv = uv; + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + + } + `,fragmentShader:` + uniform sampler2D map; + uniform float threshold; + + uniform vec3 thresholdColor; + uniform vec3 boundsColor; + uniform vec3 backgroundColor; + uniform vec2 resolution; + uniform float outlineAlpha; + + varying vec2 vUv; + void main() { + + float count = texture2D( map, vUv ).r; + + if ( count == 0.0 ) { + + vec2 offset = 1.0 / resolution; + float c1 = texture2D( map, vUv + offset * vec2( 1.0, 0.0 ) ).r; + float c2 = texture2D( map, vUv + offset * vec2( - 1.0, 0.0 ) ).r; + float c3 = texture2D( map, vUv + offset * vec2( 0.0, 1.0 ) ).r; + float c4 = texture2D( map, vUv + offset * vec2( 0.0, - 1.0 ) ).r; + + float maxC = max( c1, max( c2, max( c3, c4 ) ) ); + if ( maxC != 0.0 ) { + + gl_FragColor.rgb = mix( backgroundColor, mix( boundsColor, vec3( 1.0 ), 0.5 ), outlineAlpha ); + gl_FragColor.a = 1.0; + return; + + } + + } + + if ( count > threshold ) { + + gl_FragColor.rgb = thresholdColor.rgb; + gl_FragColor.a = 1.0; + + } else { + + float alpha = count / threshold; + vec3 color = mix( boundsColor, vec3( 1.0 ), pow( alpha, 1.75 ) ); + + gl_FragColor.rgb = mix( backgroundColor, color, alpha ).rgb ; + gl_FragColor.a = 1.0; + + } + + } + `});const t=this.uniforms;for(const r in t)Object.defineProperty(this,r,{get(){return this.uniforms[r].value},set(i){this.uniforms[r].value=i}});this.setValues(n)}}function ve(){S=document.getElementById("output"),L=document.getElementById("benchmark"),o=new _({antialias:!0}),o.setPixelRatio(window.devicePixelRatio),o.setSize(window.innerWidth,window.innerHeight),o.setClearColor(0,1),document.body.appendChild(o.domElement),h=new U(1,1,{format:I,type:j}),s=new oe(new pe({map:h.texture,depthWrite:!1})),w=new G,c=new N(75,window.innerWidth/window.innerHeight,.1,50),c.position.set(-2.5,1.5,2.5),c.far=100,c.updateProjectionMatrix(),new ee(c,o.domElement),window.addEventListener("resize",H,!1),H(),new te().load(ce,m=>{m.scene.traverse(f=>{f.isMesh&&f.name==="Dragon"&&(a=f)}),a.material=new Q({colorWrite:!1}),a.geometry.center(),a.position.set(0,0,0),w.add(a),u=new re(a,40),u.displayEdges=!1,u.displayParents=!0,u.color.set(16777215),u.opacity=1,u.depth=40;const v=u.meshMaterial;v.blending=q,v.blendDst=J,w.add(u),D(),y(!0)}),l=new X,l.material.opacity=.1,l.material.transparent=!0,l.material.depthWrite=!1,l.frustumCulled=!1,w.add(l);const n=new ae,t=n.addFolder("BVH");t.add(e.options,"strategy",{CENTER:ne,AVERAGE:ie,SAH:O}),t.add(e.options,"maxLeafTris",1,30,1),t.add(e.options,"maxDepth",1,40,1),t.add(e.options,"rebuild"),t.open();const r=n.addFolder("Visualization");r.add(e.visualization,"displayMesh"),r.add(e.visualization,"simpleColors"),r.add(e.visualization,"outline"),r.add(e.visualization,"traversalThreshold",1,300,1),r.open();const i=n.addFolder("Benchmark");i.add(e.benchmark,"displayRays"),i.add(e.benchmark,"firstHitOnly").onChange(T),i.add(e.benchmark,"castCount",100,5e3,1).onChange(()=>{T(),y(!0)}),i.add(e.benchmark,"rotations",1,20,1).onChange(()=>{T(),y(!0)}),i.open(),window.addEventListener("pointermove",m=>{M.set(m.clientX,window.innerHeight-m.clientY)})}function H(){c.aspect=window.innerWidth/window.innerHeight,c.updateProjectionMatrix(),o.setSize(window.innerWidth,window.innerHeight),o.setPixelRatio(window.devicePixelRatio),h.setSize(window.innerWidth*window.devicePixelRatio,window.innerHeight*window.devicePixelRatio)}function D(){const d=performance.now();a.geometry.computeBoundsTree({strategy:parseInt(e.options.strategy),maxLeafTris:e.options.maxLeafTris,maxDepth:e.options.maxDepth});const n=performance.now()-d;u.update(),T();const t=se(a.geometry.boundsTree)[0];S.innerText=`construction time : ${n.toFixed(2)}ms +surface area score : ${t.surfaceAreaScore.toFixed(2)} +total nodes : ${t.nodeCount} +total leaf nodes : ${t.leafNodeCount} +min / max tris per leaf : ${t.tris.min} / ${t.tris.max} +min / max depth : ${t.depth.min} / ${t.depth.max} +memory (incl. geometry) : ${(B(a.geometry.boundsTree)*1e-6).toFixed(3)} mb +memory (excl. geometry) : ${(B(a.geometry.boundsTree._roots)*1e-6).toFixed(3)} mb`}function y(d=!1){let n=null,t=null;d&&(a.updateMatrixWorld(),t=new R,l.geometry.dispose(),n=[]);const r=new Y;r.firstHitOnly=e.benchmark.firstHitOnly;const i=e.benchmark.castCount,m=e.benchmark.rotations,{ray:v}=r,{origin:f,direction:A}=v,V=performance.now();for(let g=0;g{this.setValue(this.$input.checked),this._callOnFinishChange()}),this.$disable=this.$input,this.updateDisplay()}updateDisplay(){return this.$input.checked=this.getValue(),this}}function w(l){let t,i;return(t=l.match(/(#|0x)?([a-f0-9]{6})/i))?i=t[2]:(t=l.match(/rgb\(\s*(\d*)\s*,\s*(\d*)\s*,\s*(\d*)\s*\)/))?i=parseInt(t[1]).toString(16).padStart(2,0)+parseInt(t[2]).toString(16).padStart(2,0)+parseInt(t[3]).toString(16).padStart(2,0):(t=l.match(/^#?([a-f0-9])([a-f0-9])([a-f0-9])$/i))&&(i=t[1]+t[1]+t[2]+t[2]+t[3]+t[3]),!!i&&"#"+i}const k={isPrimitive:!0,match:l=>typeof l=="string",fromHexString:w,toHexString:w},m={isPrimitive:!0,match:l=>typeof l=="number",fromHexString:l=>parseInt(l.substring(1),16),toHexString:l=>"#"+l.toString(16).padStart(6,0)},L={isPrimitive:!1,match:Array.isArray,fromHexString(l,t,i=1){const e=m.fromHexString(l);t[0]=(e>>16&255)/255*i,t[1]=(e>>8&255)/255*i,t[2]=(255&e)/255*i},toHexString:([l,t,i],e=1)=>m.toHexString(l*(e=255/e)<<16^t*e<<8^i*e<<0)},S={isPrimitive:!1,match:l=>Object(l)===l,fromHexString(l,t,i=1){const e=m.fromHexString(l);t.r=(e>>16&255)/255*i,t.g=(e>>8&255)/255*i,t.b=(255&e)/255*i},toHexString:({r:l,g:t,b:i},e=1)=>m.toHexString(l*(e=255/e)<<16^t*e<<8^i*e<<0)},D=[k,m,L,S];class F extends u{constructor(t,i,e,n){var a;super(t,i,e,"color"),this.$input=document.createElement("input"),this.$input.setAttribute("type","color"),this.$input.setAttribute("tabindex",-1),this.$input.setAttribute("aria-labelledby",this.$name.id),this.$text=document.createElement("input"),this.$text.setAttribute("type","text"),this.$text.setAttribute("spellcheck","false"),this.$text.setAttribute("aria-labelledby",this.$name.id),this.$display=document.createElement("div"),this.$display.classList.add("display"),this.$display.appendChild(this.$input),this.$widget.appendChild(this.$display),this.$widget.appendChild(this.$text),this._format=(a=this.initialValue,D.find(r=>r.match(a))),this._rgbScale=n,this._initialValueHexString=this.save(),this._textFocused=!1,this.$input.addEventListener("input",()=>{this._setValueFromHexString(this.$input.value)}),this.$input.addEventListener("blur",()=>{this._callOnFinishChange()}),this.$text.addEventListener("input",()=>{const r=w(this.$text.value);r&&this._setValueFromHexString(r)}),this.$text.addEventListener("focus",()=>{this._textFocused=!0,this.$text.select()}),this.$text.addEventListener("blur",()=>{this._textFocused=!1,this.updateDisplay(),this._callOnFinishChange()}),this.$disable=this.$text,this.updateDisplay()}reset(){return this._setValueFromHexString(this._initialValueHexString),this}_setValueFromHexString(t){if(this._format.isPrimitive){const i=this._format.fromHexString(t);this.setValue(i)}else this._format.fromHexString(t,this.getValue(),this._rgbScale),this._callOnChange(),this.updateDisplay()}save(){return this._format.toHexString(this.getValue(),this._rgbScale)}load(t){return this._setValueFromHexString(t),this._callOnFinishChange(),this}updateDisplay(){return this.$input.value=this._format.toHexString(this.getValue(),this._rgbScale),this._textFocused||(this.$text.value=this.$input.value.substring(1)),this.$display.style.backgroundColor=this.$input.value,this}}class f extends u{constructor(t,i,e){super(t,i,e,"function"),this.$button=document.createElement("button"),this.$button.appendChild(this.$name),this.$widget.appendChild(this.$button),this.$button.addEventListener("click",n=>{n.preventDefault(),this.getValue().call(this.object)}),this.$button.addEventListener("touchstart",()=>{},{passive:!0}),this.$disable=this.$button}}class V extends u{constructor(t,i,e,n,a,r){super(t,i,e,"number"),this._initInput(),this.min(n),this.max(a);const d=r!==void 0;this.step(d?r:this._getImplicitStep(),d),this.updateDisplay()}decimals(t){return this._decimals=t,this.updateDisplay(),this}min(t){return this._min=t,this._onUpdateMinMax(),this}max(t){return this._max=t,this._onUpdateMinMax(),this}step(t,i=!0){return this._step=t,this._stepExplicit=i,this}updateDisplay(){const t=this.getValue();if(this._hasSlider){let i=(t-this._min)/(this._max-this._min);i=Math.max(0,Math.min(i,1)),this.$fill.style.width=100*i+"%"}return this._inputFocused||(this.$input.value=this._decimals===void 0?t:t.toFixed(this._decimals)),this}_initInput(){this.$input=document.createElement("input"),this.$input.setAttribute("type","number"),this.$input.setAttribute("step","any"),this.$input.setAttribute("aria-labelledby",this.$name.id),this.$widget.appendChild(this.$input),this.$disable=this.$input;const t=s=>{const p=parseFloat(this.$input.value);isNaN(p)||(this._snapClampSetValue(p+s),this.$input.value=this.getValue())};let i,e,n,a,r,d=!1;const h=s=>{if(d){const p=s.clientX-i,o=s.clientY-e;Math.abs(o)>5?(s.preventDefault(),this.$input.blur(),d=!1,this._setDraggingStyle(!0,"vertical")):Math.abs(p)>5&&c()}if(!d){const p=s.clientY-n;r-=p*this._step*this._arrowKeyMultiplier(s),a+r>this._max?r=this._max-a:a+r{this._setDraggingStyle(!1,"vertical"),this._callOnFinishChange(),window.removeEventListener("mousemove",h),window.removeEventListener("mouseup",c)};this.$input.addEventListener("input",()=>{let s=parseFloat(this.$input.value);isNaN(s)||(this._stepExplicit&&(s=this._snap(s)),this.setValue(this._clamp(s)))}),this.$input.addEventListener("keydown",s=>{s.code==="Enter"&&this.$input.blur(),s.code==="ArrowUp"&&(s.preventDefault(),t(this._step*this._arrowKeyMultiplier(s))),s.code==="ArrowDown"&&(s.preventDefault(),t(this._step*this._arrowKeyMultiplier(s)*-1))}),this.$input.addEventListener("wheel",s=>{this._inputFocused&&(s.preventDefault(),t(this._step*this._normalizeMouseWheel(s)))},{passive:!1}),this.$input.addEventListener("mousedown",s=>{i=s.clientX,e=n=s.clientY,d=!0,a=this.getValue(),r=0,window.addEventListener("mousemove",h),window.addEventListener("mouseup",c)}),this.$input.addEventListener("focus",()=>{this._inputFocused=!0}),this.$input.addEventListener("blur",()=>{this._inputFocused=!1,this.updateDisplay(),this._callOnFinishChange()})}_initSlider(){this._hasSlider=!0,this.$slider=document.createElement("div"),this.$slider.classList.add("slider"),this.$fill=document.createElement("div"),this.$fill.classList.add("fill"),this.$slider.appendChild(this.$fill),this.$widget.insertBefore(this.$slider,this.$input),this.domElement.classList.add("hasSlider");const t=o=>{const g=this.$slider.getBoundingClientRect();let b=(x=o,v=g.left,y=g.right,A=this._min,_=this._max,(x-v)/(y-v)*(_-A)+A);var x,v,y,A,_;this._snapClampSetValue(b)},i=o=>{t(o.clientX)},e=()=>{this._callOnFinishChange(),this._setDraggingStyle(!1),window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",e)};let n,a,r=!1;const d=o=>{o.preventDefault(),this._setDraggingStyle(!0),t(o.touches[0].clientX),r=!1},h=o=>{if(r){const g=o.touches[0].clientX-n,b=o.touches[0].clientY-a;Math.abs(g)>Math.abs(b)?d(o):(window.removeEventListener("touchmove",h),window.removeEventListener("touchend",c))}else o.preventDefault(),t(o.touches[0].clientX)},c=()=>{this._callOnFinishChange(),this._setDraggingStyle(!1),window.removeEventListener("touchmove",h),window.removeEventListener("touchend",c)},s=this._callOnFinishChange.bind(this);let p;this.$slider.addEventListener("mousedown",o=>{this._setDraggingStyle(!0),t(o.clientX),window.addEventListener("mousemove",i),window.addEventListener("mouseup",e)}),this.$slider.addEventListener("touchstart",o=>{o.touches.length>1||(this._hasScrollBar?(n=o.touches[0].clientX,a=o.touches[0].clientY,r=!0):d(o),window.addEventListener("touchmove",h,{passive:!1}),window.addEventListener("touchend",c))},{passive:!1}),this.$slider.addEventListener("wheel",o=>{if(Math.abs(o.deltaX)this._max&&(t=this._max),t}_snapClampSetValue(t){this.setValue(this._clamp(this._snap(t)))}get _hasScrollBar(){const t=this.parent.root.$children;return t.scrollHeight>t.clientHeight}get _hasMin(){return this._min!==void 0}get _hasMax(){return this._max!==void 0}}class M extends u{constructor(t,i,e,n){super(t,i,e,"option"),this.$select=document.createElement("select"),this.$select.setAttribute("aria-labelledby",this.$name.id),this.$display=document.createElement("div"),this.$display.classList.add("display"),this._values=Array.isArray(n)?n:Object.values(n),this._names=Array.isArray(n)?n:Object.keys(n),this._names.forEach(a=>{const r=document.createElement("option");r.innerHTML=a,this.$select.appendChild(r)}),this.$select.addEventListener("change",()=>{this.setValue(this._values[this.$select.selectedIndex]),this._callOnFinishChange()}),this.$select.addEventListener("focus",()=>{this.$display.classList.add("focus")}),this.$select.addEventListener("blur",()=>{this.$display.classList.remove("focus")}),this.$widget.appendChild(this.$select),this.$widget.appendChild(this.$display),this.$disable=this.$select,this.updateDisplay()}updateDisplay(){const t=this.getValue(),i=this._values.indexOf(t);return this.$select.selectedIndex=i,this.$display.innerHTML=i===-1?t:this._names[i],this}}class H extends u{constructor(t,i,e){super(t,i,e,"string"),this.$input=document.createElement("input"),this.$input.setAttribute("type","text"),this.$input.setAttribute("aria-labelledby",this.$name.id),this.$input.addEventListener("input",()=>{this.setValue(this.$input.value)}),this.$input.addEventListener("keydown",n=>{n.code==="Enter"&&this.$input.blur()}),this.$input.addEventListener("blur",()=>{this._callOnFinishChange()}),this.$widget.appendChild(this.$input),this.$disable=this.$input,this.updateDisplay()}updateDisplay(){return this.$input.value=this.getValue(),this}}let $=!1;class E{constructor({parent:t,autoPlace:i=t===void 0,container:e,width:n,title:a="Controls",injectStyles:r=!0,touchStyles:d=!0}={}){if(this.parent=t,this.root=t?t.root:this,this.children=[],this.controllers=[],this.folders=[],this._closed=!1,this._hidden=!1,this.domElement=document.createElement("div"),this.domElement.classList.add("lil-gui"),this.$title=document.createElement("div"),this.$title.classList.add("title"),this.$title.setAttribute("role","button"),this.$title.setAttribute("aria-expanded",!0),this.$title.setAttribute("tabindex",0),this.$title.addEventListener("click",()=>this.openAnimated(this._closed)),this.$title.addEventListener("keydown",h=>{h.code!=="Enter"&&h.code!=="Space"||(h.preventDefault(),this.$title.click())}),this.$title.addEventListener("touchstart",()=>{},{passive:!0}),this.$children=document.createElement("div"),this.$children.classList.add("children"),this.domElement.appendChild(this.$title),this.domElement.appendChild(this.$children),this.title(a),d&&this.domElement.classList.add("allow-touch-styles"),this.parent)return this.parent.children.push(this),this.parent.folders.push(this),void this.parent.$children.appendChild(this.domElement);this.domElement.classList.add("root"),!$&&r&&(function(h){const c=document.createElement("style");c.innerHTML=h;const s=document.querySelector("head link[rel=stylesheet], head style");s?document.head.insertBefore(c,s):document.head.appendChild(c)}('.lil-gui{--background-color:#1f1f1f;--text-color:#ebebeb;--title-background-color:#111;--title-text-color:#ebebeb;--widget-color:#424242;--hover-color:#4f4f4f;--focus-color:#595959;--number-color:#2cc9ff;--string-color:#a2db3c;--font-size:11px;--input-font-size:11px;--font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif;--font-family-mono:Menlo,Monaco,Consolas,"Droid Sans Mono",monospace;--padding:4px;--spacing:4px;--widget-height:20px;--name-width:45%;--slider-knob-width:2px;--slider-input-width:27%;--color-input-width:27%;--slider-input-min-width:45px;--color-input-min-width:45px;--folder-indent:7px;--widget-padding:0 0 0 3px;--widget-border-radius:2px;--checkbox-size:calc(var(--widget-height)*0.75);--scrollbar-width:5px;background-color:var(--background-color);color:var(--text-color);font-family:var(--font-family);font-size:var(--font-size);font-style:normal;font-weight:400;line-height:1;text-align:left;touch-action:manipulation;user-select:none;-webkit-user-select:none}.lil-gui,.lil-gui *{box-sizing:border-box;margin:0;padding:0}.lil-gui.root{display:flex;flex-direction:column;width:var(--width,245px)}.lil-gui.root>.title{background:var(--title-background-color);color:var(--title-text-color)}.lil-gui.root>.children{overflow-x:hidden;overflow-y:auto}.lil-gui.root>.children::-webkit-scrollbar{background:var(--background-color);height:var(--scrollbar-width);width:var(--scrollbar-width)}.lil-gui.root>.children::-webkit-scrollbar-thumb{background:var(--focus-color);border-radius:var(--scrollbar-width)}.lil-gui.force-touch-styles{--widget-height:28px;--padding:6px;--spacing:6px;--font-size:13px;--input-font-size:16px;--folder-indent:10px;--scrollbar-width:7px;--slider-input-min-width:50px;--color-input-min-width:65px}.lil-gui.autoPlace{max-height:100%;position:fixed;right:15px;top:0;z-index:1001}.lil-gui .controller{align-items:center;display:flex;margin:var(--spacing) 0;padding:0 var(--padding)}.lil-gui .controller.disabled{opacity:.5}.lil-gui .controller.disabled,.lil-gui .controller.disabled *{pointer-events:none!important}.lil-gui .controller>.name{flex-shrink:0;line-height:var(--widget-height);min-width:var(--name-width);padding-right:var(--spacing);white-space:pre}.lil-gui .controller .widget{align-items:center;display:flex;min-height:var(--widget-height);position:relative;width:100%}.lil-gui .controller.string input{color:var(--string-color)}.lil-gui .controller.boolean .widget{cursor:pointer}.lil-gui .controller.color .display{border-radius:var(--widget-border-radius);height:var(--widget-height);position:relative;width:100%}.lil-gui .controller.color input[type=color]{cursor:pointer;height:100%;opacity:0;width:100%}.lil-gui .controller.color input[type=text]{flex-shrink:0;font-family:var(--font-family-mono);margin-left:var(--spacing);min-width:var(--color-input-min-width);width:var(--color-input-width)}.lil-gui .controller.option select{max-width:100%;opacity:0;position:absolute;width:100%}.lil-gui .controller.option .display{background:var(--widget-color);border-radius:var(--widget-border-radius);height:var(--widget-height);line-height:var(--widget-height);max-width:100%;overflow:hidden;padding-left:.55em;padding-right:1.75em;pointer-events:none;position:relative;word-break:break-all}.lil-gui .controller.option .display.active{background:var(--focus-color)}.lil-gui .controller.option .display:after{bottom:0;content:"↕";font-family:lil-gui;padding-right:.375em;position:absolute;right:0;top:0}.lil-gui .controller.option .widget,.lil-gui .controller.option select{cursor:pointer}.lil-gui .controller.number input{color:var(--number-color)}.lil-gui .controller.number.hasSlider input{flex-shrink:0;margin-left:var(--spacing);min-width:var(--slider-input-min-width);width:var(--slider-input-width)}.lil-gui .controller.number .slider{background-color:var(--widget-color);border-radius:var(--widget-border-radius);cursor:ew-resize;height:var(--widget-height);overflow:hidden;padding-right:var(--slider-knob-width);touch-action:pan-y;width:100%}.lil-gui .controller.number .slider.active{background-color:var(--focus-color)}.lil-gui .controller.number .slider.active .fill{opacity:.95}.lil-gui .controller.number .fill{border-right:var(--slider-knob-width) solid var(--number-color);box-sizing:content-box;height:100%}.lil-gui-dragging .lil-gui{--hover-color:var(--widget-color)}.lil-gui-dragging *{cursor:ew-resize!important}.lil-gui-dragging.lil-gui-vertical *{cursor:ns-resize!important}.lil-gui .title{--title-height:calc(var(--widget-height) + var(--spacing)*1.25);-webkit-tap-highlight-color:transparent;text-decoration-skip:objects;cursor:pointer;font-weight:600;height:var(--title-height);line-height:calc(var(--title-height) - 4px);outline:none;padding:0 var(--padding)}.lil-gui .title:before{content:"▾";display:inline-block;font-family:lil-gui;padding-right:2px}.lil-gui .title:active{background:var(--title-background-color);opacity:.75}.lil-gui.root>.title:focus{text-decoration:none!important}.lil-gui.closed>.title:before{content:"▸"}.lil-gui.closed>.children{opacity:0;transform:translateY(-7px)}.lil-gui.closed:not(.transition)>.children{display:none}.lil-gui.transition>.children{overflow:hidden;pointer-events:none;transition-duration:.3s;transition-property:height,opacity,transform;transition-timing-function:cubic-bezier(.2,.6,.35,1)}.lil-gui .children:empty:before{content:"Empty";display:block;font-style:italic;height:var(--widget-height);line-height:var(--widget-height);margin:var(--spacing) 0;opacity:.5;padding:0 var(--padding)}.lil-gui.root>.children>.lil-gui>.title{border-width:0;border-bottom:1px solid var(--widget-color);border-left:0 solid var(--widget-color);border-right:0 solid var(--widget-color);border-top:1px solid var(--widget-color);transition:border-color .3s}.lil-gui.root>.children>.lil-gui.closed>.title{border-bottom-color:transparent}.lil-gui+.controller{border-top:1px solid var(--widget-color);margin-top:0;padding-top:var(--spacing)}.lil-gui .lil-gui .lil-gui>.title{border:none}.lil-gui .lil-gui .lil-gui>.children{border:none;border-left:2px solid var(--widget-color);margin-left:var(--folder-indent)}.lil-gui .lil-gui .controller{border:none}.lil-gui input{-webkit-tap-highlight-color:transparent;background:var(--widget-color);border:0;border-radius:var(--widget-border-radius);color:var(--text-color);font-family:var(--font-family);font-size:var(--input-font-size);height:var(--widget-height);outline:none;width:100%}.lil-gui input:disabled{opacity:1}.lil-gui input[type=number],.lil-gui input[type=text]{padding:var(--widget-padding)}.lil-gui input[type=number]:focus,.lil-gui input[type=text]:focus{background:var(--focus-color)}.lil-gui input::-webkit-inner-spin-button,.lil-gui input::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.lil-gui input[type=number]{-moz-appearance:textfield}.lil-gui input[type=checkbox]{appearance:none;-webkit-appearance:none;border-radius:var(--widget-border-radius);cursor:pointer;height:var(--checkbox-size);text-align:center;width:var(--checkbox-size)}.lil-gui input[type=checkbox]:checked:before{content:"✓";font-family:lil-gui;font-size:var(--checkbox-size);line-height:var(--checkbox-size)}.lil-gui button{-webkit-tap-highlight-color:transparent;background:var(--widget-color);border:1px solid var(--widget-color);border-radius:var(--widget-border-radius);color:var(--text-color);cursor:pointer;font-family:var(--font-family);font-size:var(--font-size);height:var(--widget-height);line-height:calc(var(--widget-height) - 4px);outline:none;text-align:center;text-transform:none;width:100%}.lil-gui button:active{background:var(--focus-color)}@font-face{font-family:lil-gui;src:url("data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAAUsAAsAAAAACJwAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAAH4AAADAImwmYE9TLzIAAAGIAAAAPwAAAGBKqH5SY21hcAAAAcgAAAD0AAACrukyyJBnbHlmAAACvAAAAF8AAACEIZpWH2hlYWQAAAMcAAAAJwAAADZfcj2zaGhlYQAAA0QAAAAYAAAAJAC5AHhobXR4AAADXAAAABAAAABMAZAAAGxvY2EAAANsAAAAFAAAACgCEgIybWF4cAAAA4AAAAAeAAAAIAEfABJuYW1lAAADoAAAASIAAAIK9SUU/XBvc3QAAATEAAAAZgAAAJCTcMc2eJxVjbEOgjAURU+hFRBK1dGRL+ALnAiToyMLEzFpnPz/eAshwSa97517c/MwwJmeB9kwPl+0cf5+uGPZXsqPu4nvZabcSZldZ6kfyWnomFY/eScKqZNWupKJO6kXN3K9uCVoL7iInPr1X5baXs3tjuMqCtzEuagm/AAlzQgPAAB4nGNgYRBlnMDAysDAYM/gBiT5oLQBAwuDJAMDEwMrMwNWEJDmmsJwgCFeXZghBcjlZMgFCzOiKOIFAB71Bb8AeJy1kjFuwkAQRZ+DwRAwBtNQRUGKQ8OdKCAWUhAgKLhIuAsVSpWz5Bbkj3dEgYiUIszqWdpZe+Z7/wB1oCYmIoboiwiLT2WjKl/jscrHfGg/pKdMkyklC5Zs2LEfHYpjcRoPzme9MWWmk3dWbK9ObkWkikOetJ554fWyoEsmdSlt+uR0pCJR34b6t/TVg1SY3sYvdf8vuiKrpyaDXDISiegp17p7579Gp3p++y7HPAiY9pmTibljrr85qSidtlg4+l25GLCaS8e6rRxNBmsnERunKbaOObRz7N72ju5vdAjYpBXHgJylOAVsMseDAPEP8LYoUHicY2BiAAEfhiAGJgZWBgZ7RnFRdnVJELCQlBSRlATJMoLV2DK4glSYs6ubq5vbKrJLSbGrgEmovDuDJVhe3VzcXFwNLCOILB/C4IuQ1xTn5FPilBTj5FPmBAB4WwoqAHicY2BkYGAA4sk1sR/j+W2+MnAzpDBgAyEMQUCSg4EJxAEAwUgFHgB4nGNgZGBgSGFggJMhDIwMqEAYAByHATJ4nGNgAIIUNEwmAABl3AGReJxjYAACIQYlBiMGJ3wQAEcQBEV4nGNgZGBgEGZgY2BiAAEQyQWEDAz/wXwGAAsPATIAAHicXdBNSsNAHAXwl35iA0UQXYnMShfS9GPZA7T7LgIu03SSpkwzYTIt1BN4Ak/gKTyAeCxfw39jZkjymzcvAwmAW/wgwHUEGDb36+jQQ3GXGot79L24jxCP4gHzF/EIr4jEIe7wxhOC3g2TMYy4Q7+Lu/SHuEd/ivt4wJd4wPxbPEKMX3GI5+DJFGaSn4qNzk8mcbKSR6xdXdhSzaOZJGtdapd4vVPbi6rP+cL7TGXOHtXKll4bY1Xl7EGnPtp7Xy2n00zyKLVHfkHBa4IcJ2oD3cgggWvt/V/FbDrUlEUJhTn/0azVWbNTNr0Ens8de1tceK9xZmfB1CPjOmPH4kitmvOubcNpmVTN3oFJyjzCvnmrwhJTzqzVj9jiSX911FjeAAB4nG3HMRKCMBBA0f0giiKi4DU8k0V2GWbIZDOh4PoWWvq6J5V8If9NVNQcaDhyouXMhY4rPTcG7jwYmXhKq8Wz+p762aNaeYXom2n3m2dLTVgsrCgFJ7OTmIkYbwIbC6vIB7WmFfAAAA==") format("woff")}@media (pointer:coarse){.lil-gui.allow-touch-styles{--widget-height:28px;--padding:6px;--spacing:6px;--font-size:13px;--input-font-size:16px;--folder-indent:10px;--scrollbar-width:7px;--slider-input-min-width:50px;--color-input-min-width:65px}}@media (hover:hover){.lil-gui .controller.color .display:hover:before{border:1px solid #fff9;border-radius:var(--widget-border-radius);bottom:0;content:" ";display:block;left:0;position:absolute;right:0;top:0}.lil-gui .controller.option .display.focus{background:var(--focus-color)}.lil-gui .controller.option .widget:hover .display{background:var(--hover-color)}.lil-gui .controller.number .slider:hover{background-color:var(--hover-color)}body:not(.lil-gui-dragging) .lil-gui .title:hover{background:var(--title-background-color);opacity:.85}.lil-gui .title:focus{text-decoration:underline var(--focus-color)}.lil-gui input:hover{background:var(--hover-color)}.lil-gui input:active{background:var(--focus-color)}.lil-gui input[type=checkbox]:focus{box-shadow:inset 0 0 0 1px var(--focus-color)}.lil-gui button:hover{background:var(--hover-color);border-color:var(--hover-color)}.lil-gui button:focus{border-color:var(--focus-color)}}'),$=!0),e?e.appendChild(this.domElement):i&&(this.domElement.classList.add("autoPlace"),document.body.appendChild(this.domElement)),n&&this.domElement.style.setProperty("--width",n+"px"),this.domElement.addEventListener("keydown",h=>h.stopPropagation()),this.domElement.addEventListener("keyup",h=>h.stopPropagation())}add(t,i,e,n,a){if(Object(e)===e)return new M(this,t,i,e);const r=t[i];switch(typeof r){case"number":return new V(this,t,i,e,n,a);case"boolean":return new C(this,t,i);case"string":return new H(this,t,i);case"function":return new f(this,t,i)}console.error(`gui.add failed + property:`,i,` + object:`,t,` + value:`,r)}addColor(t,i,e=1){return new F(this,t,i,e)}addFolder(t){return new E({parent:this,title:t})}load(t,i=!0){return t.controllers&&this.controllers.forEach(e=>{e instanceof f||e._name in t.controllers&&e.load(t.controllers[e._name])}),i&&t.folders&&this.folders.forEach(e=>{e._title in t.folders&&e.load(t.folders[e._title])}),this}save(t=!0){const i={controllers:{},folders:{}};return this.controllers.forEach(e=>{if(!(e instanceof f)){if(e._name in i.controllers)throw new Error(`Cannot save GUI with duplicate property "${e._name}"`);i.controllers[e._name]=e.save()}}),t&&this.folders.forEach(e=>{if(e._title in i.folders)throw new Error(`Cannot save GUI with duplicate folder "${e._title}"`);i.folders[e._title]=e.save()}),i}open(t=!0){return this._closed=!t,this.$title.setAttribute("aria-expanded",!this._closed),this.domElement.classList.toggle("closed",this._closed),this}close(){return this.open(!1)}show(t=!0){return this._hidden=!t,this.domElement.style.display=this._hidden?"none":"",this}hide(){return this.show(!1)}openAnimated(t=!0){return this._closed=!t,this.$title.setAttribute("aria-expanded",!this._closed),requestAnimationFrame(()=>{const i=this.$children.clientHeight;this.$children.style.height=i+"px",this.domElement.classList.add("transition");const e=a=>{a.target===this.$children&&(this.$children.style.height="",this.domElement.classList.remove("transition"),this.$children.removeEventListener("transitionend",e))};this.$children.addEventListener("transitionend",e);const n=t?this.$children.scrollHeight:0;this.domElement.classList.toggle("closed",!t),requestAnimationFrame(()=>{this.$children.style.height=n+"px"})}),this}title(t){return this._title=t,this.$title.innerHTML=t,this}reset(t=!0){return(t?this.controllersRecursive():this.controllers).forEach(i=>i.reset()),this}onChange(t){return this._onChange=t,this}_callOnChange(t){this.parent&&this.parent._callOnChange(t),this._onChange!==void 0&&this._onChange.call(this,{object:t.object,property:t.property,value:t.getValue(),controller:t})}onFinishChange(t){return this._onFinishChange=t,this}_callOnFinishChange(t){this.parent&&this.parent._callOnFinishChange(t),this._onFinishChange!==void 0&&this._onFinishChange.call(this,{object:t.object,property:t.property,value:t.getValue(),controller:t})}destroy(){this.parent&&(this.parent.children.splice(this.parent.children.indexOf(this),1),this.parent.folders.splice(this.parent.folders.indexOf(this),1)),this.domElement.parentElement&&this.domElement.parentElement.removeChild(this.domElement),Array.from(this.children).forEach(t=>t.destroy())}controllersRecursive(){let t=Array.from(this.controllers);return this.folders.forEach(i=>{t=t.concat(i.controllersRecursive())}),t}foldersRecursive(){let t=Array.from(this.folders);return this.folders.forEach(i=>{t=t.concat(i.foldersRecursive())}),t}}export{E as g}; diff --git a/example/bundle/assets/meshopt_decoder.module-Cf1-17OU.js b/example/bundle/assets/meshopt_decoder.module-Cf1-17OU.js new file mode 100644 index 000000000..915074629 --- /dev/null +++ b/example/bundle/assets/meshopt_decoder.module-Cf1-17OU.js @@ -0,0 +1 @@ +var P=function(){var v="b9H79Tebbbe8Fv9Gbb9Gvuuuuueu9Giuuub9Geueu9Giuuueuikqbeeedddillviebeoweuec:q;iekr;leDo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbeY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVbdE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbiL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtblK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949Wbol79IV9Rbrq:P8Yqdbk;3sezu8Jjjjjbcj;eb9Rgv8Kjjjjbc9:hodnadcefal0mbcuhoaiRbbc:Ge9hmbavaialfgrad9Radz1jjjbhwcj;abad9UhoaicefhldnadTmbaoc;WFbGgocjdaocjd6EhDcbhqinaqae9pmeaDaeaq9RaqaDfae6Egkcsfgocl4cifcd4hxdndndndnaoc9WGgmTmbcbhPcehsawcjdfhzalhHinaraH9Rax6midnaraHaxfgl9RcK6mbczhoinawcj;cbfaogifgoc9WfhOdndndndndnaHaic9WfgAco4fRbbaAci4coG4ciGPlbedibkaO9cb83ibaOcwf9cb83ibxikaOalRblalRbbgAco4gCaCciSgCE86bbaocGfalclfaCfgORbbaAcl4ciGgCaCciSgCE86bbaocVfaOaCfgORbbaAcd4ciGgCaCciSgCE86bbaoc7faOaCfgORbbaAciGgAaAciSgAE86bbaoctfaOaAfgARbbalRbegOco4gCaCciSgCE86bbaoc91faAaCfgARbbaOcl4ciGgCaCciSgCE86bbaoc4faAaCfgARbbaOcd4ciGgCaCciSgCE86bbaoc93faAaCfgARbbaOciGgOaOciSgOE86bbaoc94faAaOfgARbbalRbdgOco4gCaCciSgCE86bbaoc95faAaCfgARbbaOcl4ciGgCaCciSgCE86bbaoc96faAaCfgARbbaOcd4ciGgCaCciSgCE86bbaoc97faAaCfgARbbaOciGgOaOciSgOE86bbaoc98faAaOfgORbbalRbiglco4gAaAciSgAE86bbaoc99faOaAfgORbbalcl4ciGgAaAciSgAE86bbaoc9:faOaAfgORbbalcd4ciGgAaAciSgAE86bbaocufaOaAfgoRbbalciGglalciSglE86bbaoalfhlxdkaOalRbwalRbbgAcl4gCaCcsSgCE86bbaocGfalcwfaCfgORbbaAcsGgAaAcsSgAE86bbaocVfaOaAfgORbbalRbegAcl4gCaCcsSgCE86bbaoc7faOaCfgORbbaAcsGgAaAcsSgAE86bbaoctfaOaAfgORbbalRbdgAcl4gCaCcsSgCE86bbaoc91faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc4faOaAfgORbbalRbigAcl4gCaCcsSgCE86bbaoc93faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc94faOaAfgORbbalRblgAcl4gCaCcsSgCE86bbaoc95faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc96faOaAfgORbbalRbvgAcl4gCaCcsSgCE86bbaoc97faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc98faOaAfgORbbalRbogAcl4gCaCcsSgCE86bbaoc99faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc9:faOaAfgORbbalRbrglcl4gAaAcsSgAE86bbaocufaOaAfgoRbbalcsGglalcsSglE86bbaoalfhlxekaOal8Pbb83bbaOcwfalcwf8Pbb83bbalczfhlkdnaiam9pmbaiczfhoaral9RcL0mekkaiam6mialTmidnakTmbawaPfRbbhOcbhoazhiinaiawcj;cbfaofRbbgAce4cbaAceG9R7aOfgO86bbaiadfhiaocefgoak9hmbkkazcefhzaPcefgPad6hsalhHaPad9hmexvkkcbhlasceGmdxikalaxad2fhCdnakTmbcbhHcehsawcjdfhminaral9Rax6mialTmdalaxfhlawaHfRbbhOcbhoamhiinaiawcj;cbfaofRbbgAce4cbaAceG9R7aOfgO86bbaiadfhiaocefgoak9hmbkamcefhmaHcefgHad6hsaHad9hmbkaChlxikcbhocehsinaral9Rax6mdalTmealaxfhlaocefgoad6hsadao9hmbkaChlxdkcbhlasceGTmekc9:hoxikabaqad2fawcjdfakad2z1jjjb8Aawawcjdfakcufad2fadz1jjjb8Aakaqfhqalmbkc9:hoxekcbc99aral9Radcaadca0ESEhokavcj;ebf8Kjjjjbaok;yzeHu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecjez:jjjjb8AavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhodnaeTmbcmcsaDceSEhkcbhxcbhmcbhDcbhicbhlindnaoaq9nmbc9:hoxikdndnawRbbgrc;Ve0mbavc;abfalarcl4cu7fcsGcitfgPydlhsaPydbhzdnarcsGgPak9pmbavaiarcu7fcsGcdtfydbaxaPEhraPThPdndnadcd9hmbabaDcetfgHaz87ebaHcdfas87ebaHclfar87ebxekabaDcdtfgHazBdbaHclfasBdbaHcwfarBdbkaxaPfhxavc;abfalcitfgHarBdbaHasBdlavaicdtfarBdbavc;abfalcefcsGglcitfgHazBdbaHarBdlaiaPfhialcefhlxdkdndnaPcsSmbamaPfaPc987fcefhmxekaocefhrao8SbbgPcFeGhHdndnaPcu9mmbarhoxekaocvfhoaHcFbGhHcrhPdninar8SbbgOcFbGaPtaHVhHaOcu9kmearcefhraPcrfgPc8J9hmbxdkkarcefhokaHce4cbaHceG9R7amfhmkdndnadcd9hmbabaDcetfgraz87ebarcdfas87ebarclfam87ebxekabaDcdtfgrazBdbarclfasBdbarcwfamBdbkavc;abfalcitfgramBdbarasBdlavaicdtfamBdbavc;abfalcefcsGglcitfgrazBdbaramBdlaicefhialcefhlxekdnarcpe0mbaxcefgOavaiaqarcsGfRbbgPcl49RcsGcdtfydbaPcz6gHEhravaiaP9RcsGcdtfydbaOaHfgsaPcsGgOEhPaOThOdndnadcd9hmbabaDcetfgzax87ebazcdfar87ebazclfaP87ebxekabaDcdtfgzaxBdbazclfarBdbazcwfaPBdbkavaicdtfaxBdbavc;abfalcitfgzarBdbazaxBdlavaicefgicsGcdtfarBdbavc;abfalcefcsGcitfgzaPBdbazarBdlavaiaHfcsGgicdtfaPBdbavc;abfalcdfcsGglcitfgraxBdbaraPBdlalcefhlaiaOfhiasaOfhxxekaxcbaoRbbgzEgAarc;:eSgrfhsazcsGhCazcl4hXdndnazcs0mbascefhOxekashOavaiaX9RcsGcdtfydbhskdndnaCmbaOcefhxxekaOhxavaiaz9RcsGcdtfydbhOkdndnarTmbaocefhrxekaocdfhrao8SbegHcFeGhPdnaHcu9kmbaocofhAaPcFbGhPcrhodninar8SbbgHcFbGaotaPVhPaHcu9kmearcefhraocrfgoc8J9hmbkaAhrxekarcefhrkaPce4cbaPceG9R7amfgmhAkdndnaXcsSmbarhPxekarcefhPar8SbbgocFeGhHdnaocu9kmbarcvfhsaHcFbGhHcrhodninaP8SbbgrcFbGaotaHVhHarcu9kmeaPcefhPaocrfgoc8J9hmbkashPxekaPcefhPkaHce4cbaHceG9R7amfgmhskdndnaCcsSmbaPhoxekaPcefhoaP8SbbgrcFeGhHdnarcu9kmbaPcvfhOaHcFbGhHcrhrdninao8SbbgPcFbGartaHVhHaPcu9kmeaocefhoarcrfgrc8J9hmbkaOhoxekaocefhokaHce4cbaHceG9R7amfgmhOkdndnadcd9hmbabaDcetfgraA87ebarcdfas87ebarclfaO87ebxekabaDcdtfgraABdbarclfasBdbarcwfaOBdbkavc;abfalcitfgrasBdbaraABdlavaicdtfaABdbavc;abfalcefcsGcitfgraOBdbarasBdlavaicefgicsGcdtfasBdbavc;abfalcdfcsGcitfgraABdbaraOBdlavaiazcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhialcifhlkawcefhwalcsGhlaicsGhiaDcifgDae6mbkkcbc99aoaqSEhokavc;aef8Kjjjjbaok:llevu8Jjjjjbcz9Rhvc9:hodnaecvfal0mbcuhoaiRbbc;:eGc;qe9hmbav9cb83iwaicefhraialfc98fhwdnaeTmbdnadcdSmbcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcdtfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfglBdbaoalBdbaDcefgDae9hmbxdkkcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcetfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfgl87ebaoalBdbaDcefgDae9hmbkkcbc99arawSEhokaok:Lvoeue99dud99eud99dndnadcl9hmbaeTmeindndnabcdfgd8Sbb:Yab8Sbbgi:Ygl:l:tabcefgv8Sbbgo:Ygr:l:tgwJbb;:9cawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai86bbdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad86bbdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad86bbabclfhbaecufgembxdkkaeTmbindndnabclfgd8Ueb:Yab8Uebgi:Ygl:l:tabcdfgv8Uebgo:Ygr:l:tgwJb;:FSawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai87ebdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad87ebdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad87ebabcwfhbaecufgembkkk;siliui99iue99dnaeTmbcbhiabhlindndnJ;Zl81Zalcof8UebgvciV:Y:vgoal8Ueb:YNgrJb;:FSNJbbbZJbbb:;arJbbbb9GEMgw:lJbbb9p9DTmbaw:OhDxekcjjjj94hDkalclf8Uebhqalcdf8UebhkabavcefciGaiVcetfaD87ebdndnaoak:YNgwJb;:FSNJbbbZJbbb:;awJbbbb9GEMgx:lJbbb9p9DTmbax:Ohkxekcjjjj94hkkabavcdfciGaiVcetfak87ebdndnaoaq:YNgoJb;:FSNJbbbZJbbb:;aoJbbbb9GEMgx:lJbbb9p9DTmbax:Ohqxekcjjjj94hqkabavcufciGaiVcetfaq87ebdndnJbbjZararN:tawawN:taoaoN:tgrJbbbbarJbbbb9GE:rJb;:FSNJbbbZMgr:lJbbb9p9DTmbar:Ohqxekcjjjj94hqkabavciGaiVcetfaq87ebalcwfhlaiclfhiaecufgembkkk9mbdnadcd4ae2geTmbinababydbgdcwtcw91:Yadce91cjjj;8ifcjjj98G::NUdbabclfhbaecufgembkkk9teiucbcbydj1jjbgeabcifc98GfgbBdj1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaik;LeeeudndnaeabVciGTmbabhixekdndnadcz9pmbabhixekabhiinaiaeydbBdbaiclfaeclfydbBdbaicwfaecwfydbBdbaicxfaecxfydbBdbaiczfhiaeczfheadc9Wfgdcs0mbkkadcl6mbinaiaeydbBdbaeclfheaiclfhiadc98fgdci0mbkkdnadTmbinaiaeRbb86bbaicefhiaecefheadcufgdmbkkabk;aeedudndnabciGTmbabhixekaecFeGc:b:c:ew2hldndnadcz9pmbabhixekabhiinaialBdbaicxfalBdbaicwfalBdbaiclfalBdbaiczfhiadc9Wfgdcs0mbkkadcl6mbinaialBdbaiclfhiadc98fgdci0mbkkdnadTmbinaiae86bbaicefhiadcufgdmbkkabkkkebcjwklz9Kbb",F="b9H79TebbbeKl9Gbb9Gvuuuuueu9Giuuub9Geueuikqbbebeedddilve9Weeeviebeoweuec:q;Aekr;leDo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbdY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVblE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtboK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbrL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949Wbwl79IV9RbDq;t9tqlbzik9:evu8Jjjjjbcz9Rhbcbheincbhdcbhiinabcwfadfaicjuaead4ceGglE86bbaialfhiadcefgdcw9hmbkaec:q:yjjbfai86bbaecitc:q1jjbfab8Piw83ibaecefgecjd9hmbkk;h8JlHud97euo978Jjjjjbcj;kb9Rgv8Kjjjjbc9:hodnadcefal0mbcuhoaiRbbc:Ge9hmbavaialfgrad9Rad;8qbbcj;abad9UhoaicefhldnadTmbaoc;WFbGgocjdaocjd6EhwcbhDinaDae9pmeawaeaD9RaDawfae6Egqcsfgoc9WGgkci2hxakcethmaocl4cifcd4hPabaDad2fhscbhzdnincehHalhOcbhAdninaraO9RaP6miavcj;cbfaAak2fhCaOaPfhlcbhidnakc;ab6mbaral9Rc;Gb6mbcbhoinaCaofhidndndndndnaOaoco4fRbbgXciGPlbedibkaipxbbbbbbbbbbbbbbbbpklbxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklbalczfhlkdndndndndnaXcd4ciGPlbedibkaipxbbbbbbbbbbbbbbbbpklzxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklzalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklzalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklzalczfhlkdndndndndnaXcl4ciGPlbedibkaipxbbbbbbbbbbbbbbbbpklaxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklaalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklaalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklaalczfhlkdndndndndnaXco4Plbedibkaipxbbbbbbbbbbbbbbbbpkl8WxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibaXc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spkl8WalclfaYpQbfaXc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibaXc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spkl8WalcwfaYpQbfaXc:q:yjjbfRbbfhlxekaialpbbbpkl8Walczfhlkaoc;abfhiaocjefak0meaihoaral9Rc;Fb0mbkkdndnaiak9pmbaici4hoinaral9RcK6mdaCaifhXdndndndndnaOaico4fRbbaocoG4ciGPlbedibkaXpxbbbbbbbbbbbbbbbbpklbxikaXalpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaXalpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaXalpbbbpklbalczfhlkaocdfhoaiczfgiak6mbkkalTmbaAci6hHalhOaAcefgohAaoclSmdxekkcbhlaHceGmdkdnakTmbavcjdfazfhiavazfpbdbhYcbhXinaiavcj;cbfaXfgopblbgLcep9TaLpxeeeeeeeeeeeeeeeegQp9op9Hp9rgLaoakfpblbg8Acep9Ta8AaQp9op9Hp9rg8ApmbzeHdOiAlCvXoQrLgEaoamfpblbg3cep9Ta3aQp9op9Hp9rg3aoaxfpblbg5cep9Ta5aQp9op9Hp9rg5pmbzeHdOiAlCvXoQrLg8EpmbezHdiOAlvCXorQLgQaQpmbedibedibedibediaYp9UgYp9AdbbaiadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfgoaYaEa8EpmwDKYqk8AExm35Ps8E8FgQaQpmbedibedibedibedip9UgYp9AdbbaoadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfgoaYaLa8ApmwKDYq8AkEx3m5P8Es8FgLa3a5pmwKDYq8AkEx3m5P8Es8Fg8ApmbezHdiOAlvCXorQLgQaQpmbedibedibedibedip9UgYp9AdbbaoadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfgoaYaLa8ApmwDKYqk8AExm35Ps8E8FgQaQpmbedibedibedibedip9UgYp9AdbbaoadfgoaYaQaQpmlvorlvorlvorlvorp9UgYp9AdbbaoadfgoaYaQaQpmwDqkwDqkwDqkwDqkp9UgYp9AdbbaoadfgoaYaQaQpmxmPsxmPsxmPsxmPsp9UgYp9AdbbaoadfhiaXczfgXak6mbkkazclfgzad6mbkasavcjdfaqad2;8qbbavavcjdfaqcufad2fad;8qbbaqaDfhDc9:hoalmexikkc9:hoxekcbc99aral9Radcaadca0ESEhokavcj;kbf8Kjjjjbaokwbz:bjjjbk;uzeHu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecje;8kbavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhodnaeTmbcmcsaDceSEhkcbhxcbhmcbhDcbhicbhlindnaoaq9nmbc9:hoxikdndnawRbbgrc;Ve0mbavc;abfalarcl4cu7fcsGcitfgPydlhsaPydbhzdnarcsGgPak9pmbavaiarcu7fcsGcdtfydbaxaPEhraPThPdndnadcd9hmbabaDcetfgHaz87ebaHcdfas87ebaHclfar87ebxekabaDcdtfgHazBdbaHclfasBdbaHcwfarBdbkaxaPfhxavc;abfalcitfgHarBdbaHasBdlavaicdtfarBdbavc;abfalcefcsGglcitfgHazBdbaHarBdlaiaPfhialcefhlxdkdndnaPcsSmbamaPfaPc987fcefhmxekaocefhrao8SbbgPcFeGhHdndnaPcu9mmbarhoxekaocvfhoaHcFbGhHcrhPdninar8SbbgOcFbGaPtaHVhHaOcu9kmearcefhraPcrfgPc8J9hmbxdkkarcefhokaHce4cbaHceG9R7amfhmkdndnadcd9hmbabaDcetfgraz87ebarcdfas87ebarclfam87ebxekabaDcdtfgrazBdbarclfasBdbarcwfamBdbkavc;abfalcitfgramBdbarasBdlavaicdtfamBdbavc;abfalcefcsGglcitfgrazBdbaramBdlaicefhialcefhlxekdnarcpe0mbaxcefgOavaiaqarcsGfRbbgPcl49RcsGcdtfydbaPcz6gHEhravaiaP9RcsGcdtfydbaOaHfgsaPcsGgOEhPaOThOdndnadcd9hmbabaDcetfgzax87ebazcdfar87ebazclfaP87ebxekabaDcdtfgzaxBdbazclfarBdbazcwfaPBdbkavaicdtfaxBdbavc;abfalcitfgzarBdbazaxBdlavaicefgicsGcdtfarBdbavc;abfalcefcsGcitfgzaPBdbazarBdlavaiaHfcsGgicdtfaPBdbavc;abfalcdfcsGglcitfgraxBdbaraPBdlalcefhlaiaOfhiasaOfhxxekaxcbaoRbbgzEgAarc;:eSgrfhsazcsGhCazcl4hXdndnazcs0mbascefhOxekashOavaiaX9RcsGcdtfydbhskdndnaCmbaOcefhxxekaOhxavaiaz9RcsGcdtfydbhOkdndnarTmbaocefhrxekaocdfhrao8SbegHcFeGhPdnaHcu9kmbaocofhAaPcFbGhPcrhodninar8SbbgHcFbGaotaPVhPaHcu9kmearcefhraocrfgoc8J9hmbkaAhrxekarcefhrkaPce4cbaPceG9R7amfgmhAkdndnaXcsSmbarhPxekarcefhPar8SbbgocFeGhHdnaocu9kmbarcvfhsaHcFbGhHcrhodninaP8SbbgrcFbGaotaHVhHarcu9kmeaPcefhPaocrfgoc8J9hmbkashPxekaPcefhPkaHce4cbaHceG9R7amfgmhskdndnaCcsSmbaPhoxekaPcefhoaP8SbbgrcFeGhHdnarcu9kmbaPcvfhOaHcFbGhHcrhrdninao8SbbgPcFbGartaHVhHaPcu9kmeaocefhoarcrfgrc8J9hmbkaOhoxekaocefhokaHce4cbaHceG9R7amfgmhOkdndnadcd9hmbabaDcetfgraA87ebarcdfas87ebarclfaO87ebxekabaDcdtfgraABdbarclfasBdbarcwfaOBdbkavc;abfalcitfgrasBdbaraABdlavaicdtfaABdbavc;abfalcefcsGcitfgraOBdbarasBdlavaicefgicsGcdtfasBdbavc;abfalcdfcsGcitfgraABdbaraOBdlavaiazcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhialcifhlkawcefhwalcsGhlaicsGhiaDcifgDae6mbkkcbc99aoaqSEhokavc;aef8Kjjjjbaok:llevu8Jjjjjbcz9Rhvc9:hodnaecvfal0mbcuhoaiRbbc;:eGc;qe9hmbav9cb83iwaicefhraialfc98fhwdnaeTmbdnadcdSmbcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcdtfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfglBdbaoalBdbaDcefgDae9hmbxdkkcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcetfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfgl87ebaoalBdbaDcefgDae9hmbkkcbc99arawSEhokaok:EPliuo97eue978Jjjjjbca9Rhidndnadcl9hmbdnaec98GglTmbcbhvabhdinadadpbbbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDpxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpkbbadczfhdavclfgval6mbkkalae9pmeaiaeciGgvcdtgdVcbczad9R;8kbaiabalcdtfglad;8qbbdnavTmbaiaipblbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDpxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpklbkalaiad;8qbbskdnaec98GgxTmbcbhvabhdinadczfglalpbbbgopxbbbbbbFFbbbbbbFFgkp9oadpbbbgDaopmlvorxmPsCXQL358E8FpxFubbFubbFubbFubbp9op;6eaDaopmbediwDqkzHOAKY8AEgoczp:Sep;6egrp;Geaoczp:Reczp:Sep;6egwp;Gep;Kep;Legopxb;:FSb;:FSb;:FSb;:FSawaopxbbbbbbbbbbbbbbbbp:2egqawpxbbbjbbbjbbbjbbbjgmp9op9rp;Kegwawp;Meaoaop;Mearaqaramp9op9rp;Kegoaop;Mep;Kep;Kep;Jep;Negrp;Mepxbbn0bbn0bbn0bbn0gqp;Keczp:Reawarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9op9qgwaoarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogopmwDKYqk8AExm35Ps8E8Fp9qpkbbadaDakp9oawaopmbezHdiOAlvCXorQLp9qpkbbadcafhdavclfgvax6mbkkaxae9pmbaiaeciGgvcitgdfcbcaad9R;8kbaiabaxcitfglad;8qbbdnavTmbaiaipblzgopxbbbbbbFFbbbbbbFFgkp9oaipblbgDaopmlvorxmPsCXQL358E8FpxFubbFubbFubbFubbp9op;6eaDaopmbediwDqkzHOAKY8AEgoczp:Sep;6egrp;Geaoczp:Reczp:Sep;6egwp;Gep;Kep;Legopxb;:FSb;:FSb;:FSb;:FSawaopxbbbbbbbbbbbbbbbbp:2egqawpxbbbjbbbjbbbjbbbjgmp9op9rp;Kegwawp;Meaoaop;Mearaqaramp9op9rp;Kegoaop;Mep;Kep;Kep;Jep;Negrp;Mepxbbn0bbn0bbn0bbn0gqp;Keczp:Reawarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9op9qgwaoarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogopmwDKYqk8AExm35Ps8E8Fp9qpklzaiaDakp9oawaopmbezHdiOAlvCXorQLp9qpklbkalaiad;8qbbkk;4wllue97euv978Jjjjjbc8W9Rhidnaec98GglTmbcbhvabhoinaiaopbbbgraoczfgwpbbbgDpmlvorxmPsCXQL358E8Fgqczp:Segkclp:RepklbaopxbbjZbbjZbbjZbbjZpx;Zl81Z;Zl81Z;Zl81Z;Zl81Zakpxibbbibbbibbbibbbp9qp;6ep;NegkaraDpmbediwDqkzHOAKY8AEgrczp:Reczp:Sep;6ep;MegDaDp;Meakarczp:Sep;6ep;Megxaxp;Meakaqczp:Reczp:Sep;6ep;Megqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jepxb;:FSb;:FSb;:FSb;:FSgkp;Mepxbbn0bbn0bbn0bbn0grp;KepxFFbbFFbbFFbbFFbbgmp9oaxakp;Mearp;Keczp:Rep9qgxaqakp;Mearp;Keczp:ReaDakp;Mearp;Keamp9op9qgkpmbezHdiOAlvCXorQLgrp5baipblbpEb:T:j83ibaocwfarp5eaipblbpEe:T:j83ibawaxakpmwDKYqk8AExm35Ps8E8Fgkp5baipblbpEd:T:j83ibaocKfakp5eaipblbpEi:T:j83ibaocafhoavclfgval6mbkkdnalae9pmbaiaeciGgvcitgofcbcaao9R;8kbaiabalcitfgwao;8qbbdnavTmbaiaipblbgraipblzgDpmlvorxmPsCXQL358E8Fgqczp:Segkclp:RepklaaipxbbjZbbjZbbjZbbjZpx;Zl81Z;Zl81Z;Zl81Z;Zl81Zakpxibbbibbbibbbibbbp9qp;6ep;NegkaraDpmbediwDqkzHOAKY8AEgrczp:Reczp:Sep;6ep;MegDaDp;Meakarczp:Sep;6ep;Megxaxp;Meakaqczp:Reczp:Sep;6ep;Megqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jepxb;:FSb;:FSb;:FSb;:FSgkp;Mepxbbn0bbn0bbn0bbn0grp;KepxFFbbFFbbFFbbFFbbgmp9oaxakp;Mearp;Keczp:Rep9qgxaqakp;Mearp;Keczp:ReaDakp;Mearp;Keamp9op9qgkpmbezHdiOAlvCXorQLgrp5baipblapEb:T:j83ibaiarp5eaipblapEe:T:j83iwaiaxakpmwDKYqk8AExm35Ps8E8Fgkp5baipblapEd:T:j83izaiakp5eaipblapEi:T:j83iKkawaiao;8qbbkk:Pddiue978Jjjjjbc;ab9Rhidnadcd4ae2glc98GgvTmbcbhdabheinaeaepbbbgocwp:Recwp:Sep;6eaocep:SepxbbjZbbjZbbjZbbjZp:UepxbbjFbbjFbbjFbbjFp9op;Mepkbbaeczfheadclfgdav6mbkkdnaval9pmbaialciGgdcdtgeVcbc;abae9R;8kbaiabavcdtfgvae;8qbbdnadTmbaiaipblbgocwp:Recwp:Sep;6eaocep:SepxbbjZbbjZbbjZbbjZp:UepxbbjFbbjFbbjFbbjFp9op;Mepklbkavaiae;8qbbkk9teiucbcbydj1jjbgeabcifc98GfgbBdj1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaikkkebcjwklz9Tbb",G=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,3,2,0,0,5,3,1,0,1,12,1,0,10,22,2,12,0,65,0,65,0,65,0,252,10,0,0,11,7,0,65,0,253,15,26,11]),w=new Uint8Array([32,0,65,2,1,106,34,33,3,128,11,4,13,64,6,253,10,7,15,116,127,5,8,12,40,16,19,54,20,9,27,255,113,17,42,67,24,23,146,148,18,14,22,45,70,69,56,114,101,21,25,63,75,136,108,28,118,29,73,115]);if(typeof WebAssembly!="object")return{supported:!1};var t=WebAssembly.validate(G)?F:v,d,n=WebAssembly.instantiate(x(t),{}).then(function(e){d=e.instance,d.exports.__wasm_call_ctors()});function x(e){for(var b=new Uint8Array(e.length),a=0;a96?c-97:c>64?c-39:c+4}for(var i=0,a=0;a0?O(e,b,a,m[c],s[i]):n.then(function(){var p=new Uint8Array(e*b);return g(d.exports[m[c]],p,e,b,a,d.exports[s[i]]),p})}}}();export{P as M}; diff --git a/example/bundle/assets/parallelMeshBVH.worker-DB_vNiSj.js b/example/bundle/assets/parallelMeshBVH.worker-DB_vNiSj.js new file mode 100644 index 000000000..5de7f991b --- /dev/null +++ b/example/bundle/assets/parallelMeshBVH.worker-DB_vNiSj.js @@ -0,0 +1,5 @@ +(function(){"use strict";/** + * @license + * Copyright 2010-2024 Three.js Authors + * SPDX-License-Identifier: MIT + */const ue="170",le="",Et="srgb",ce="srgb-linear",de="linear",qt="srgb";class Vt{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){if(this._listeners===void 0)return!1;const i=this._listeners;return i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){if(this._listeners===void 0)return;const s=this._listeners[t];if(s!==void 0){const n=s.indexOf(e);n!==-1&&s.splice(n,1)}}dispatchEvent(t){if(this._listeners===void 0)return;const i=this._listeners[t.type];if(i!==void 0){t.target=this;const s=i.slice(0);for(let n=0,r=s.length;n>8&255]+F[l>>16&255]+F[l>>24&255]+"-"+F[t&255]+F[t>>8&255]+"-"+F[t>>16&15|64]+F[t>>24&255]+"-"+F[e&63|128]+F[e>>8&255]+"-"+F[e>>16&255]+F[e>>24&255]+F[i&255]+F[i>>8&255]+F[i>>16&255]+F[i>>24&255]).toLowerCase()}function q(l,t,e){return Math.max(t,Math.min(e,l))}function ye(l,t){return(l%t+t)%t}function Ve(l,t,e,i,s){return i+(l-t)*(s-i)/(e-t)}function Ze(l,t,e){return l!==t?(e-l)/(t-l):0}function xe(l,t,e){return(1-e)*l+e*t}function Ge(l,t,e,i){return xe(l,t,1-Math.exp(-e*i))}function ve(l,t=1){return t-Math.abs(ye(l,t*2)-t)}function He(l,t,e){return l<=t?0:l>=e?1:(l=(l-t)/(e-t),l*l*(3-2*l))}function je(l,t,e){return l<=t?0:l>=e?1:(l=(l-t)/(e-t),l*l*l*(l*(l*6-15)+10))}function $e(l,t){return l+Math.floor(Math.random()*(t-l+1))}function Je(l,t){return l+Math.random()*(t-l)}function Qe(l){return l*(.5-Math.random())}function Ke(l){l!==void 0&&(me=l);let t=me+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function ti(l){return l*fe}function ei(l){return l*pe}function ii(l){return(l&l-1)===0&&l!==0}function si(l){return Math.pow(2,Math.ceil(Math.log(l)/Math.LN2))}function ni(l){return Math.pow(2,Math.floor(Math.log(l)/Math.LN2))}function ri(l,t,e,i,s){const n=Math.cos,r=Math.sin,a=n(e/2),o=r(e/2),h=n((t+i)/2),u=r((t+i)/2),c=n((t-i)/2),m=r((t-i)/2),d=n((i-t)/2),f=r((i-t)/2);switch(s){case"XYX":l.set(a*u,o*c,o*m,a*h);break;case"YZY":l.set(o*m,a*u,o*c,a*h);break;case"ZXZ":l.set(o*c,o*m,a*u,a*h);break;case"XZX":l.set(a*u,o*f,o*d,a*h);break;case"YXY":l.set(o*d,a*u,o*f,a*h);break;case"ZYZ":l.set(o*f,o*d,a*u,a*h);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+s)}}function ot(l,t){switch(t.constructor){case Float32Array:return l;case Uint32Array:return l/4294967295;case Uint16Array:return l/65535;case Uint8Array:return l/255;case Int32Array:return Math.max(l/2147483647,-1);case Int16Array:return Math.max(l/32767,-1);case Int8Array:return Math.max(l/127,-1);default:throw new Error("Invalid component type.")}}function P(l,t){switch(t.constructor){case Float32Array:return l;case Uint32Array:return Math.round(l*4294967295);case Uint16Array:return Math.round(l*65535);case Uint8Array:return Math.round(l*255);case Int32Array:return Math.round(l*2147483647);case Int16Array:return Math.round(l*32767);case Int8Array:return Math.round(l*127);default:throw new Error("Invalid component type.")}}const ai={DEG2RAD:fe,RAD2DEG:pe,generateUUID:xt,clamp:q,euclideanModulo:ye,mapLinear:Ve,inverseLerp:Ze,lerp:xe,damp:Ge,pingpong:ve,smoothstep:He,smootherstep:je,randInt:$e,randFloat:Je,randFloatSpread:Qe,seededRandom:Ke,degToRad:ti,radToDeg:ei,isPowerOfTwo:ii,ceilPowerOfTwo:si,floorPowerOfTwo:ni,setQuaternionFromProperEuler:ri,normalize:P,denormalize:ot};class Z{constructor(t=0,e=0){Z.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,i=this.y,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6],this.y=s[1]*e+s[4]*i+s[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(q(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const i=Math.cos(e),s=Math.sin(e),n=this.x-t.x,r=this.y-t.y;return this.x=n*i-r*s+t.x,this.y=n*s+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class ${constructor(t,e,i,s,n,r,a,o,h){$.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,h)}set(t,e,i,s,n,r,a,o,h){const u=this.elements;return u[0]=t,u[1]=s,u[2]=a,u[3]=e,u[4]=n,u[5]=o,u[6]=i,u[7]=r,u[8]=h,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return 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}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[3],o=i[6],h=i[1],u=i[4],c=i[7],m=i[2],d=i[5],f=i[8],p=s[0],x=s[3],y=s[6],A=s[1],M=s[4],b=s[7],g=s[2],w=s[5],_=s[8];return n[0]=r*p+a*A+o*g,n[3]=r*x+a*M+o*w,n[6]=r*y+a*b+o*_,n[1]=h*p+u*A+c*g,n[4]=h*x+u*M+c*w,n[7]=h*y+u*b+c*_,n[2]=m*p+d*A+f*g,n[5]=m*x+d*M+f*w,n[8]=m*y+d*b+f*_,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],h=t[7],u=t[8];return e*r*u-e*a*h-i*n*u+i*a*o+s*n*h-s*r*o}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],h=t[7],u=t[8],c=u*r-a*h,m=a*o-u*n,d=h*n-r*o,f=e*c+i*m+s*d;if(f===0)return this.set(0,0,0,0,0,0,0,0,0);const p=1/f;return t[0]=c*p,t[1]=(s*h-u*i)*p,t[2]=(a*i-s*r)*p,t[3]=m*p,t[4]=(u*e-s*o)*p,t[5]=(s*n-a*e)*p,t[6]=d*p,t[7]=(i*o-h*e)*p,t[8]=(r*e-i*n)*p,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,i,s,n,r,a){const o=Math.cos(n),h=Math.sin(n);return this.set(i*o,i*h,-i*(o*r+h*a)+r+t,-s*h,s*o,-s*(-h*r+o*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(Zt.makeScale(t,e)),this}rotate(t){return this.premultiply(Zt.makeRotation(-t)),this}translate(t,e){return this.premultiply(Zt.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,i,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<9;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return new this.constructor().fromArray(this.elements)}}const Zt=new $;function oi(l){for(let t=l.length-1;t>=0;--t)if(l[t]>=65535)return!0;return!1}function ge(l){return document.createElementNS("http://www.w3.org/1999/xhtml",l)}const hi={enabled:!0,workingColorSpace:ce,spaces:{},convert:function(l,t,e){return this.enabled===!1||t===e||!t||!e||(this.spaces[t].transfer===qt&&(l.r=ht(l.r),l.g=ht(l.g),l.b=ht(l.b)),this.spaces[t].primaries!==this.spaces[e].primaries&&(l.applyMatrix3(this.spaces[t].toXYZ),l.applyMatrix3(this.spaces[e].fromXYZ)),this.spaces[e].transfer===qt&&(l.r=Gt(l.r),l.g=Gt(l.g),l.b=Gt(l.b))),l},fromWorkingColorSpace:function(l,t){return this.convert(l,this.workingColorSpace,t)},toWorkingColorSpace:function(l,t){return this.convert(l,t,this.workingColorSpace)},getPrimaries:function(l){return this.spaces[l].primaries},getTransfer:function(l){return l===le?de:this.spaces[l].transfer},getLuminanceCoefficients:function(l,t=this.workingColorSpace){return l.fromArray(this.spaces[t].luminanceCoefficients)},define:function(l){Object.assign(this.spaces,l)},_getMatrix:function(l,t,e){return l.copy(this.spaces[t].toXYZ).multiply(this.spaces[e].fromXYZ)},_getDrawingBufferColorSpace:function(l){return this.spaces[l].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(l=this.workingColorSpace){return this.spaces[l].workingColorSpaceConfig.unpackColorSpace}};function ht(l){return l<.04045?l*.0773993808:Math.pow(l*.9478672986+.0521327014,2.4)}function Gt(l){return l<.0031308?l*12.92:1.055*Math.pow(l,.41666)-.055}const _e=[.64,.33,.3,.6,.15,.06],Me=[.2126,.7152,.0722],be=[.3127,.329],we=new $().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),ze=new $().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);hi.define({[ce]:{primaries:_e,whitePoint:be,transfer:de,toXYZ:we,fromXYZ:ze,luminanceCoefficients:Me,workingColorSpaceConfig:{unpackColorSpace:Et},outputColorSpaceConfig:{drawingBufferColorSpace:Et}},[Et]:{primaries:_e,whitePoint:be,transfer:qt,toXYZ:we,fromXYZ:ze,luminanceCoefficients:Me,outputColorSpaceConfig:{drawingBufferColorSpace:Et}}});let ut;class ui{static getDataURL(t){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{ut===void 0&&(ut=ge("canvas")),ut.width=t.width,ut.height=t.height;const i=ut.getContext("2d");t instanceof ImageData?i.putImageData(t,0,0):i.drawImage(t,0,0,t.width,t.height),e=ut}return e.width>2048||e.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",t),e.toDataURL("image/jpeg",.6)):e.toDataURL("image/png")}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=ge("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.drawImage(t,0,0,t.width,t.height);const s=i.getImageData(0,0,t.width,t.height),n=s.data;for(let r=0;r0&&(i.userData=this.userData),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==300)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case 1e3:t.x=t.x-Math.floor(t.x);break;case 1001:t.x=t.x<0?0:1;break;case 1002:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case 1e3:t.y=t.y-Math.floor(t.y);break;case 1001:t.y=t.y<0?0:1;break;case 1002:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}st.DEFAULT_IMAGE=null,st.DEFAULT_MAPPING=300,st.DEFAULT_ANISOTROPY=1;class gt{constructor(t=0,e=0,i=0,s=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=i,this._w=s}static slerpFlat(t,e,i,s,n,r,a){let o=i[s+0],h=i[s+1],u=i[s+2],c=i[s+3];const m=n[r+0],d=n[r+1],f=n[r+2],p=n[r+3];if(a===0){t[e+0]=o,t[e+1]=h,t[e+2]=u,t[e+3]=c;return}if(a===1){t[e+0]=m,t[e+1]=d,t[e+2]=f,t[e+3]=p;return}if(c!==p||o!==m||h!==d||u!==f){let x=1-a;const y=o*m+h*d+u*f+c*p,A=y>=0?1:-1,M=1-y*y;if(M>Number.EPSILON){const g=Math.sqrt(M),w=Math.atan2(g,y*A);x=Math.sin(x*w)/g,a=Math.sin(a*w)/g}const b=a*A;if(o=o*x+m*b,h=h*x+d*b,u=u*x+f*b,c=c*x+p*b,x===1-a){const g=1/Math.sqrt(o*o+h*h+u*u+c*c);o*=g,h*=g,u*=g,c*=g}}t[e]=o,t[e+1]=h,t[e+2]=u,t[e+3]=c}static multiplyQuaternionsFlat(t,e,i,s,n,r){const a=i[s],o=i[s+1],h=i[s+2],u=i[s+3],c=n[r],m=n[r+1],d=n[r+2],f=n[r+3];return t[e]=a*f+u*c+o*d-h*m,t[e+1]=o*f+u*m+h*c-a*d,t[e+2]=h*f+u*d+a*m-o*c,t[e+3]=u*f-a*c-o*m-h*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,i,s){return this._x=t,this._y=e,this._z=i,this._w=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const i=t._x,s=t._y,n=t._z,r=t._order,a=Math.cos,o=Math.sin,h=a(i/2),u=a(s/2),c=a(n/2),m=o(i/2),d=o(s/2),f=o(n/2);switch(r){case"XYZ":this._x=m*u*c+h*d*f,this._y=h*d*c-m*u*f,this._z=h*u*f+m*d*c,this._w=h*u*c-m*d*f;break;case"YXZ":this._x=m*u*c+h*d*f,this._y=h*d*c-m*u*f,this._z=h*u*f-m*d*c,this._w=h*u*c+m*d*f;break;case"ZXY":this._x=m*u*c-h*d*f,this._y=h*d*c+m*u*f,this._z=h*u*f+m*d*c,this._w=h*u*c-m*d*f;break;case"ZYX":this._x=m*u*c-h*d*f,this._y=h*d*c+m*u*f,this._z=h*u*f-m*d*c,this._w=h*u*c+m*d*f;break;case"YZX":this._x=m*u*c+h*d*f,this._y=h*d*c+m*u*f,this._z=h*u*f-m*d*c,this._w=h*u*c-m*d*f;break;case"XZY":this._x=m*u*c-h*d*f,this._y=h*d*c-m*u*f,this._z=h*u*f+m*d*c,this._w=h*u*c+m*d*f;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+r)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,s=Math.sin(i);return this._x=t.x*s,this._y=t.y*s,this._z=t.z*s,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],s=e[4],n=e[8],r=e[1],a=e[5],o=e[9],h=e[2],u=e[6],c=e[10],m=i+a+c;if(m>0){const d=.5/Math.sqrt(m+1);this._w=.25/d,this._x=(u-o)*d,this._y=(n-h)*d,this._z=(r-s)*d}else if(i>a&&i>c){const d=2*Math.sqrt(1+i-a-c);this._w=(u-o)/d,this._x=.25*d,this._y=(s+r)/d,this._z=(n+h)/d}else if(a>c){const d=2*Math.sqrt(1+a-i-c);this._w=(n-h)/d,this._x=(s+r)/d,this._y=.25*d,this._z=(o+u)/d}else{const d=2*Math.sqrt(1+c-i-a);this._w=(r-s)/d,this._x=(n+h)/d,this._y=(o+u)/d,this._z=.25*d}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return iMath.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(q(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(i===0)return this;const s=Math.min(1,e/i);return this.slerp(t,s),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const i=t._x,s=t._y,n=t._z,r=t._w,a=e._x,o=e._y,h=e._z,u=e._w;return this._x=i*u+r*a+s*h-n*o,this._y=s*u+r*o+n*a-i*h,this._z=n*u+r*h+i*o-s*a,this._w=r*u-i*a-s*o-n*h,this._onChangeCallback(),this}slerp(t,e){if(e===0)return this;if(e===1)return this.copy(t);const i=this._x,s=this._y,n=this._z,r=this._w;let a=r*t._w+i*t._x+s*t._y+n*t._z;if(a<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,a=-a):this.copy(t),a>=1)return this._w=r,this._x=i,this._y=s,this._z=n,this;const o=1-a*a;if(o<=Number.EPSILON){const d=1-e;return this._w=d*r+e*this._w,this._x=d*i+e*this._x,this._y=d*s+e*this._y,this._z=d*n+e*this._z,this.normalize(),this}const h=Math.sqrt(o),u=Math.atan2(h,a),c=Math.sin((1-e)*u)/h,m=Math.sin(e*u)/h;return this._w=r*c+this._w*m,this._x=i*c+this._x*m,this._y=s*c+this._y*m,this._z=n*c+this._z*m,this._onChangeCallback(),this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),i=Math.random(),s=Math.sqrt(1-i),n=Math.sqrt(i);return this.set(s*Math.sin(t),s*Math.cos(t),n*Math.sin(e),n*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class z{constructor(t=0,e=0,i=0){z.prototype.isVector3=!0,this.x=t,this.y=e,this.z=i}set(t,e,i){return i===void 0&&(i=this.z),this.x=t,this.y=e,this.z=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(Ae.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Ae.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6]*s,this.y=n[1]*e+n[4]*i+n[7]*s,this.z=n[2]*e+n[5]*i+n[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=t.elements,r=1/(n[3]*e+n[7]*i+n[11]*s+n[15]);return this.x=(n[0]*e+n[4]*i+n[8]*s+n[12])*r,this.y=(n[1]*e+n[5]*i+n[9]*s+n[13])*r,this.z=(n[2]*e+n[6]*i+n[10]*s+n[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,s=this.z,n=t.x,r=t.y,a=t.z,o=t.w,h=2*(r*s-a*i),u=2*(a*e-n*s),c=2*(n*i-r*e);return this.x=e+o*h+r*c-a*u,this.y=i+o*u+a*h-n*c,this.z=s+o*c+n*u-r*h,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[4]*i+n[8]*s,this.y=n[1]*e+n[5]*i+n[9]*s,this.z=n[2]*e+n[6]*i+n[10]*s,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,s=t.y,n=t.z,r=e.x,a=e.y,o=e.z;return this.x=s*o-n*a,this.y=n*r-i*o,this.z=i*a-s*r,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return Ht.copy(this).projectOnVector(t),this.sub(Ht)}reflect(t){return this.sub(Ht.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(q(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,s=this.z-t.z;return e*e+i*i+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,i){const s=Math.sin(e)*t;return this.x=s*Math.sin(i),this.y=Math.cos(e)*t,this.z=s*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),i=this.setFromMatrixColumn(t,1).length(),s=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=s,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=Math.random()*2-1,i=Math.sqrt(1-e*e);return this.x=i*Math.cos(t),this.y=e,this.z=i*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Ht=new z,Ae=new gt;class _t{constructor(t=new z(1/0,1/0,1/0),e=new z(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,i=t.length;e=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,W),W.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,i;return t.normal.x>0?(e=t.normal.x*this.min.x,i=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,i=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,i+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,i+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,i+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,i+=t.normal.z*this.min.z),e<=-t.constant&&i>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(Mt),kt.subVectors(this.max,Mt),lt.subVectors(t.a,Mt),ct.subVectors(t.b,Mt),dt.subVectors(t.c,Mt),J.subVectors(ct,lt),Q.subVectors(dt,ct),nt.subVectors(lt,dt);let e=[0,-J.z,J.y,0,-Q.z,Q.y,0,-nt.z,nt.y,J.z,0,-J.x,Q.z,0,-Q.x,nt.z,0,-nt.x,-J.y,J.x,0,-Q.y,Q.x,0,-nt.y,nt.x,0];return!jt(e,lt,ct,dt,kt)||(e=[1,0,0,0,1,0,0,0,1],!jt(e,lt,ct,dt,kt))?!1:(Rt.crossVectors(J,Q),e=[Rt.x,Rt.y,Rt.z],jt(e,lt,ct,dt,kt))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,W).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(W).length()*.5),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()?this:(G[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),G[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),G[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),G[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),G[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),G[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),G[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),G[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(G),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const G=[new z,new z,new z,new z,new z,new z,new z,new z],W=new z,Tt=new _t,lt=new z,ct=new z,dt=new z,J=new z,Q=new z,nt=new z,Mt=new z,kt=new z,Rt=new z,rt=new z;function jt(l,t,e,i,s){for(let n=0,r=l.length-3;n<=r;n+=3){rt.fromArray(l,n);const a=s.x*Math.abs(rt.x)+s.y*Math.abs(rt.y)+s.z*Math.abs(rt.z),o=t.dot(rt),h=e.dot(rt),u=i.dot(rt);if(Math.max(-Math.max(o,h,u),Math.min(o,h,u))>a)return!1}return!0}const mi=new _t,bt=new z,$t=new z;class fi{constructor(t=new z,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const i=this.center;e!==void 0?i.copy(e):mi.setFromPoints(t).getCenter(i);let s=0;for(let n=0,r=t.length;nthis.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;bt.subVectors(t,this.center);const e=bt.lengthSq();if(e>this.radius*this.radius){const i=Math.sqrt(e),s=(i-this.radius)*.5;this.center.addScaledVector(bt,s/i),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):($t.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(bt.copy(t.center).add($t)),this.expandByPoint(bt.copy(t.center).sub($t))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}}class V{constructor(t,e,i,s,n,r,a,o,h,u,c,m,d,f,p,x){V.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,h,u,c,m,d,f,p,x)}set(t,e,i,s,n,r,a,o,h,u,c,m,d,f,p,x){const y=this.elements;return y[0]=t,y[4]=e,y[8]=i,y[12]=s,y[1]=n,y[5]=r,y[9]=a,y[13]=o,y[2]=h,y[6]=u,y[10]=c,y[14]=m,y[3]=d,y[7]=f,y[11]=p,y[15]=x,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new V().fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return 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],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,i){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,i=t.elements,s=1/mt.setFromMatrixColumn(t,0).length(),n=1/mt.setFromMatrixColumn(t,1).length(),r=1/mt.setFromMatrixColumn(t,2).length();return e[0]=i[0]*s,e[1]=i[1]*s,e[2]=i[2]*s,e[3]=0,e[4]=i[4]*n,e[5]=i[5]*n,e[6]=i[6]*n,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,i=t.x,s=t.y,n=t.z,r=Math.cos(i),a=Math.sin(i),o=Math.cos(s),h=Math.sin(s),u=Math.cos(n),c=Math.sin(n);if(t.order==="XYZ"){const m=r*u,d=r*c,f=a*u,p=a*c;e[0]=o*u,e[4]=-o*c,e[8]=h,e[1]=d+f*h,e[5]=m-p*h,e[9]=-a*o,e[2]=p-m*h,e[6]=f+d*h,e[10]=r*o}else if(t.order==="YXZ"){const m=o*u,d=o*c,f=h*u,p=h*c;e[0]=m+p*a,e[4]=f*a-d,e[8]=r*h,e[1]=r*c,e[5]=r*u,e[9]=-a,e[2]=d*a-f,e[6]=p+m*a,e[10]=r*o}else if(t.order==="ZXY"){const m=o*u,d=o*c,f=h*u,p=h*c;e[0]=m-p*a,e[4]=-r*c,e[8]=f+d*a,e[1]=d+f*a,e[5]=r*u,e[9]=p-m*a,e[2]=-r*h,e[6]=a,e[10]=r*o}else if(t.order==="ZYX"){const m=r*u,d=r*c,f=a*u,p=a*c;e[0]=o*u,e[4]=f*h-d,e[8]=m*h+p,e[1]=o*c,e[5]=p*h+m,e[9]=d*h-f,e[2]=-h,e[6]=a*o,e[10]=r*o}else if(t.order==="YZX"){const m=r*o,d=r*h,f=a*o,p=a*h;e[0]=o*u,e[4]=p-m*c,e[8]=f*c+d,e[1]=c,e[5]=r*u,e[9]=-a*u,e[2]=-h*u,e[6]=d*c+f,e[10]=m-p*c}else if(t.order==="XZY"){const m=r*o,d=r*h,f=a*o,p=a*h;e[0]=o*u,e[4]=-c,e[8]=h*u,e[1]=m*c+p,e[5]=r*u,e[9]=d*c-f,e[2]=f*c-d,e[6]=a*u,e[10]=p*c+m}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(pi,t,yi)}lookAt(t,e,i){const s=this.elements;return L.subVectors(t,e),L.lengthSq()===0&&(L.z=1),L.normalize(),K.crossVectors(i,L),K.lengthSq()===0&&(Math.abs(i.z)===1?L.x+=1e-4:L.z+=1e-4,L.normalize(),K.crossVectors(i,L)),K.normalize(),It.crossVectors(L,K),s[0]=K.x,s[4]=It.x,s[8]=L.x,s[1]=K.y,s[5]=It.y,s[9]=L.y,s[2]=K.z,s[6]=It.z,s[10]=L.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[4],o=i[8],h=i[12],u=i[1],c=i[5],m=i[9],d=i[13],f=i[2],p=i[6],x=i[10],y=i[14],A=i[3],M=i[7],b=i[11],g=i[15],w=s[0],_=s[4],S=s[8],C=s[12],E=s[1],B=s[5],k=s[9],T=s[13],U=s[2],N=s[6],j=s[10],Y=s[14],at=s[3],Wt=s[7],Xt=s[11],Yt=s[15];return n[0]=r*w+a*E+o*U+h*at,n[4]=r*_+a*B+o*N+h*Wt,n[8]=r*S+a*k+o*j+h*Xt,n[12]=r*C+a*T+o*Y+h*Yt,n[1]=u*w+c*E+m*U+d*at,n[5]=u*_+c*B+m*N+d*Wt,n[9]=u*S+c*k+m*j+d*Xt,n[13]=u*C+c*T+m*Y+d*Yt,n[2]=f*w+p*E+x*U+y*at,n[6]=f*_+p*B+x*N+y*Wt,n[10]=f*S+p*k+x*j+y*Xt,n[14]=f*C+p*T+x*Y+y*Yt,n[3]=A*w+M*E+b*U+g*at,n[7]=A*_+M*B+b*N+g*Wt,n[11]=A*S+M*k+b*j+g*Xt,n[15]=A*C+M*T+b*Y+g*Yt,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[4],s=t[8],n=t[12],r=t[1],a=t[5],o=t[9],h=t[13],u=t[2],c=t[6],m=t[10],d=t[14],f=t[3],p=t[7],x=t[11],y=t[15];return f*(+n*o*c-s*h*c-n*a*m+i*h*m+s*a*d-i*o*d)+p*(+e*o*d-e*h*m+n*r*m-s*r*d+s*h*u-n*o*u)+x*(+e*h*c-e*a*d-n*r*c+i*r*d+n*a*u-i*h*u)+y*(-s*a*u-e*o*c+e*a*m+s*r*c-i*r*m+i*o*u)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,i){const s=this.elements;return t.isVector3?(s[12]=t.x,s[13]=t.y,s[14]=t.z):(s[12]=t,s[13]=e,s[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],h=t[7],u=t[8],c=t[9],m=t[10],d=t[11],f=t[12],p=t[13],x=t[14],y=t[15],A=c*x*h-p*m*h+p*o*d-a*x*d-c*o*y+a*m*y,M=f*m*h-u*x*h-f*o*d+r*x*d+u*o*y-r*m*y,b=u*p*h-f*c*h+f*a*d-r*p*d-u*a*y+r*c*y,g=f*c*o-u*p*o-f*a*m+r*p*m+u*a*x-r*c*x,w=e*A+i*M+s*b+n*g;if(w===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const _=1/w;return t[0]=A*_,t[1]=(p*m*n-c*x*n-p*s*d+i*x*d+c*s*y-i*m*y)*_,t[2]=(a*x*n-p*o*n+p*s*h-i*x*h-a*s*y+i*o*y)*_,t[3]=(c*o*n-a*m*n-c*s*h+i*m*h+a*s*d-i*o*d)*_,t[4]=M*_,t[5]=(u*x*n-f*m*n+f*s*d-e*x*d-u*s*y+e*m*y)*_,t[6]=(f*o*n-r*x*n-f*s*h+e*x*h+r*s*y-e*o*y)*_,t[7]=(r*m*n-u*o*n+u*s*h-e*m*h-r*s*d+e*o*d)*_,t[8]=b*_,t[9]=(f*c*n-u*p*n-f*i*d+e*p*d+u*i*y-e*c*y)*_,t[10]=(r*p*n-f*a*n+f*i*h-e*p*h-r*i*y+e*a*y)*_,t[11]=(u*a*n-r*c*n-u*i*h+e*c*h+r*i*d-e*a*d)*_,t[12]=g*_,t[13]=(u*p*s-f*c*s+f*i*m-e*p*m-u*i*x+e*c*x)*_,t[14]=(f*a*s-r*p*s-f*i*o+e*p*o+r*i*x-e*a*x)*_,t[15]=(r*c*s-u*a*s+u*i*o-e*c*o-r*i*m+e*a*m)*_,this}scale(t){const e=this.elements,i=t.x,s=t.y,n=t.z;return e[0]*=i,e[4]*=s,e[8]*=n,e[1]*=i,e[5]*=s,e[9]*=n,e[2]*=i,e[6]*=s,e[10]*=n,e[3]*=i,e[7]*=s,e[11]*=n,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],s=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,s))}makeTranslation(t,e,i){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),s=Math.sin(e),n=1-i,r=t.x,a=t.y,o=t.z,h=n*r,u=n*a;return this.set(h*r+i,h*a-s*o,h*o+s*a,0,h*a+s*o,u*a+i,u*o-s*r,0,h*o-s*a,u*o+s*r,n*o*o+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,s,n,r){return this.set(1,i,n,0,t,1,r,0,e,s,1,0,0,0,0,1),this}compose(t,e,i){const s=this.elements,n=e._x,r=e._y,a=e._z,o=e._w,h=n+n,u=r+r,c=a+a,m=n*h,d=n*u,f=n*c,p=r*u,x=r*c,y=a*c,A=o*h,M=o*u,b=o*c,g=i.x,w=i.y,_=i.z;return s[0]=(1-(p+y))*g,s[1]=(d+b)*g,s[2]=(f-M)*g,s[3]=0,s[4]=(d-b)*w,s[5]=(1-(m+y))*w,s[6]=(x+A)*w,s[7]=0,s[8]=(f+M)*_,s[9]=(x-A)*_,s[10]=(1-(m+p))*_,s[11]=0,s[12]=t.x,s[13]=t.y,s[14]=t.z,s[15]=1,this}decompose(t,e,i){const s=this.elements;let n=mt.set(s[0],s[1],s[2]).length();const r=mt.set(s[4],s[5],s[6]).length(),a=mt.set(s[8],s[9],s[10]).length();this.determinant()<0&&(n=-n),t.x=s[12],t.y=s[13],t.z=s[14],X.copy(this);const h=1/n,u=1/r,c=1/a;return X.elements[0]*=h,X.elements[1]*=h,X.elements[2]*=h,X.elements[4]*=u,X.elements[5]*=u,X.elements[6]*=u,X.elements[8]*=c,X.elements[9]*=c,X.elements[10]*=c,e.setFromRotationMatrix(X),i.x=n,i.y=r,i.z=a,this}makePerspective(t,e,i,s,n,r,a=2e3){const o=this.elements,h=2*n/(e-t),u=2*n/(i-s),c=(e+t)/(e-t),m=(i+s)/(i-s);let d,f;if(a===2e3)d=-(r+n)/(r-n),f=-2*r*n/(r-n);else if(a===2001)d=-r/(r-n),f=-r*n/(r-n);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return o[0]=h,o[4]=0,o[8]=c,o[12]=0,o[1]=0,o[5]=u,o[9]=m,o[13]=0,o[2]=0,o[6]=0,o[10]=d,o[14]=f,o[3]=0,o[7]=0,o[11]=-1,o[15]=0,this}makeOrthographic(t,e,i,s,n,r,a=2e3){const o=this.elements,h=1/(e-t),u=1/(i-s),c=1/(r-n),m=(e+t)*h,d=(i+s)*u;let f,p;if(a===2e3)f=(r+n)*c,p=-2*c;else if(a===2001)f=n*c,p=-1*c;else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return o[0]=2*h,o[4]=0,o[8]=0,o[12]=-m,o[1]=0,o[5]=2*u,o[9]=0,o[13]=-d,o[2]=0,o[6]=0,o[10]=p,o[14]=-f,o[3]=0,o[7]=0,o[11]=0,o[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<16;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}}const mt=new z,X=new V,pi=new z(0,0,0),yi=new z(1,1,1),K=new z,It=new z,L=new z,Se=new V,Ce=new gt;class Ft{constructor(t=0,e=0,i=0,s=Ft.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=i,this._order=s}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,i,s=this._order){return this._x=t,this._y=e,this._z=i,this._order=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,i=!0){const s=t.elements,n=s[0],r=s[4],a=s[8],o=s[1],h=s[5],u=s[9],c=s[2],m=s[6],d=s[10];switch(e){case"XYZ":this._y=Math.asin(q(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-u,d),this._z=Math.atan2(-r,n)):(this._x=Math.atan2(m,h),this._z=0);break;case"YXZ":this._x=Math.asin(-q(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,h)):(this._y=Math.atan2(-c,n),this._z=0);break;case"ZXY":this._x=Math.asin(q(m,-1,1)),Math.abs(m)<.9999999?(this._y=Math.atan2(-c,d),this._z=Math.atan2(-r,h)):(this._y=0,this._z=Math.atan2(o,n));break;case"ZYX":this._y=Math.asin(-q(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(m,d),this._z=Math.atan2(o,n)):(this._x=0,this._z=Math.atan2(-r,h));break;case"YZX":this._z=Math.asin(q(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-u,h),this._y=Math.atan2(-c,n)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-q(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(m,h),this._y=Math.atan2(a,n)):(this._x=Math.atan2(-u,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,i===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return Se.makeRotationFromQuaternion(t),this.setFromRotationMatrix(Se,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return Ce.setFromEuler(this),this.setFromQuaternion(Ce,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Ft.DEFAULT_ORDER="XYZ";class xi{constructor(){this.mask=1}set(t){this.mask=(1<>>0}enable(t){this.mask|=1<1){for(let e=0;e1){for(let i=0;i0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(s.matrixAutoUpdate=!1),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(s.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(s.type="BatchedMesh",s.perObjectFrustumCulled=this.perObjectFrustumCulled,s.sortObjects=this.sortObjects,s.drawRanges=this._drawRanges,s.reservedRanges=this._reservedRanges,s.visibility=this._visibility,s.active=this._active,s.bounds=this._bounds.map(a=>({boxInitialized:a.boxInitialized,boxMin:a.box.min.toArray(),boxMax:a.box.max.toArray(),sphereInitialized:a.sphereInitialized,sphereRadius:a.sphere.radius,sphereCenter:a.sphere.center.toArray()})),s.maxInstanceCount=this._maxInstanceCount,s.maxVertexCount=this._maxVertexCount,s.maxIndexCount=this._maxIndexCount,s.geometryInitialized=this._geometryInitialized,s.geometryCount=this._geometryCount,s.matricesTexture=this._matricesTexture.toJSON(t),this._colorsTexture!==null&&(s.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(s.boundingSphere={center:s.boundingSphere.center.toArray(),radius:s.boundingSphere.radius}),this.boundingBox!==null&&(s.boundingBox={min:s.boundingBox.min.toArray(),max:s.boundingBox.max.toArray()}));function n(a,o){return a[o.uuid]===void 0&&(a[o.uuid]=o.toJSON(t)),o.uuid}if(this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(s.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=n(t.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const o=a.shapes;if(Array.isArray(o))for(let h=0,u=o.length;h0){s.children=[];for(let a=0;a0){s.animations=[];for(let a=0;a0&&(i.geometries=a),o.length>0&&(i.materials=o),h.length>0&&(i.textures=h),u.length>0&&(i.images=u),c.length>0&&(i.shapes=c),m.length>0&&(i.skeletons=m),d.length>0&&(i.animations=d),f.length>0&&(i.nodes=f)}return i.object=s,i;function r(a){const o=[];for(const h in a){const u=a[h];delete u.metadata,o.push(u)}return o}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let i=0;ie.count&&console.warn("THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new _t);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new z(-1/0,-1/0,-1/0),new z(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let i=0,s=e.length;i0&&(t.userData=this.userData),this.parameters!==void 0){const o=this.parameters;for(const h in o)o[h]!==void 0&&(t[h]=o[h]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const i=this.attributes;for(const o in i){const h=i[o];t.data.attributes[o]=h.toJSON(t.data)}const s={};let n=!1;for(const o in this.morphAttributes){const h=this.morphAttributes[o],u=[];for(let c=0,m=h.length;c0&&(s[o]=u,n=!0)}n&&(t.data.morphAttributes=s,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const a=this.boundingSphere;return a!==null&&(t.data.boundingSphere={center:a.center.toArray(),radius:a.radius}),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const i=t.index;i!==null&&this.setIndex(i.clone(e));const s=t.attributes;for(const h in s){const u=s[h];this.setAttribute(h,u.clone(e))}const n=t.morphAttributes;for(const h in n){const u=[],c=n[h];for(let m=0,d=c.length;mt;)e.pop().terminate()}runSubTask(t,e,i){return new Promise((s,n)=>{const r=this.workers[t];if(r.isRunning)throw new Error(`${this.name}: Worker ${t} is already running.`);r.isRunning=!0,r.postMessage(e),r.onerror=a=>{r.isRunning=!1,n(a)},r.onmessage=a=>{a.data.type==="progress"?i&&i(a.data.progress):(i&&i(1),r.isRunning=!1,s(a.data))}})}}const Ie=0,Bi=1,Ei=2,te=1.25,Fe=1,At=6*4+4+4,Ti=65535,ki=Math.pow(2,-24);function Ri(l){return l.index?l.index.count:l.attributes.position.count}function Lt(l){return Ri(l)/3}function Ue(l,t){const e=Lt(l),i=t||l.drawRange,s=i.start/3,n=(i.start+i.count)/3,r=Math.max(0,s),a=Math.min(e,n)-r;return[{offset:Math.floor(r),count:Math.floor(a)}]}function Ii(l,t){if(!l.groups||!l.groups.length)return Ue(l,t);const e=[],i=new Set,s=t||l.drawRange,n=s.start/3,r=(s.start+s.count)/3;for(const o of l.groups){const h=o.start/3,u=(o.start+o.count)/3;i.add(Math.max(n,h)),i.add(Math.min(r,u))}const a=Array.from(i.values()).sort((o,h)=>o-h);for(let o=0;oo&&(o=w),Mf&&(f=M);const _=l[y+2],S=l[y+3],C=_-S,E=_+S;Ch&&(h=E),_p&&(p=_);const B=l[y+4],k=l[y+5],T=B-k,U=B+k;Tu&&(u=U),Bx&&(x=B)}i[0]=n,i[1]=r,i[2]=a,i[3]=o,i[4]=h,i[5]=u,s[0]=c,s[1]=m,s[2]=d,s[3]=f,s[4]=p,s[5]=x}function Fi(l,t=null,e=null,i=null){const s=l.attributes.position,n=l.index?l.index.array:null,r=Lt(l),a=s.normalized;let o;t===null?(o=new Float32Array(r*6),e=0,i=r):(o=t,e=e||0,i=i||r);const h=s.array,u=s.offset||0;let c=3;s.isInterleavedBufferAttribute&&(c=s.data.stride);const m=["getX","getY","getZ"];for(let d=e;dS&&(S=g),w>S&&(S=w);const C=(S-_)/2,E=M*2;o[p+E+0]=_+C,o[p+E+1]=C+(Math.abs(_)+C)*ki}}return o}function Pe(l){let t=-1,e=-1/0;for(let i=0;i<3;i++){const s=l[i+3]-l[i];s>e&&(e=s,t=i)}return t}function Le(l,t){t.set(l)}function De(l,t,e){let i,s;for(let n=0;n<3;n++){const r=n+3;i=l[n],s=t[n],e[n]=is?i:s}}function Dt(l,t,e){for(let i=0;i<3;i++){const s=t[l+2*i],n=t[l+2*i+1],r=s-n,a=s+n;re[i+3]&&(e[i+3]=a)}}function St(l){const t=l[3]-l[0],e=l[4]-l[1],i=l[5]-l[2];return 2*(t*e+e*i+i*t)}const H=32,Ui=(l,t)=>l.candidate-t.candidate,it=new Array(H).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ot=new Float32Array(6);function Pi(l,t,e,i,s,n){let r=-1,a=0;if(n===Ie)r=Pe(t),r!==-1&&(a=(t[r]+t[r+3])/2);else if(n===Bi)r=Pe(l),r!==-1&&(a=Li(e,i,s,r));else if(n===Ei){const o=St(l);let h=te*s;const u=i*6,c=(i+s)*6;for(let m=0;m<3;m++){const d=t[m],x=(t[m+3]-d)/H;if(s=_.candidate?Dt(b,e,_.rightCacheBounds):(Dt(b,e,_.leftCacheBounds),_.count++)}}for(let b=0;b=H&&(w=H-1);const _=it[w];_.count++,Dt(M,e,_.bounds)}const y=it[H-1];Le(y.bounds,y.rightCacheBounds);for(let M=H-2;M>=0;M--){const b=it[M],g=it[M+1];De(b.bounds,g.rightCacheBounds,b.rightCacheBounds)}let A=0;for(let M=0;M=o;)a--;if(r=o;)a--;if(rWi)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return Ct[e+6]=h/4,h=ne(h,a),Ct[e+7]=o,h}}function Xi(l,t){const e=(l.index?l.index.count:l.attributes.position.count)/3,i=e>2**16,s=i?4:2,n=new SharedArrayBuffer(e*s),r=i?new Uint32Array(n):new Uint16Array(n);for(let a=0,o=r.length;a=n&&(y=!0,r&&(console.warn(`MeshBVH: Max depth of ${n} reached when generating BVH. Consider increasing maxDepth.`),console.warn(m))),_<=a||C>=n)return M(w+_),g.offset=w,g.count=_,g;const E=Pi(g.boundingData,S,t,w,_,o);if(E.axis===-1)return M(w+_),g.offset=w,g.count=_,g;const B=f(c,d,t,w,_,E);if(B===w||B===w+_)M(w+_),g.offset=w,g.count=_;else{g.splitAxis=E.axis;const k=new ie,T=w,U=B-w;g.left=k,ee(t,T,U,k.boundingData,x),b(k,T,U,x,C+1);const N=new ie,j=B,Y=_-U;g.right=N,ee(t,j,Y,N.boundingData,x),b(N,j,Y,x,C+1)}return g}}const re={strategy:Ie,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};let ae=!1,Ye=0;const Bt=new Ci(()=>new Worker(self.location.href,{type:"module"}));onmessage=async({data:l})=>{if(ae)throw new Error("Worker is already running a task.");const{operation:t}=l;if(t==="BUILD_BVH"){ae=!0;const{maxWorkerCount:e,index:i,position:s,options:n}=l;Bt.setWorkerCount(ai.floorPowerOfTwo(e));const r=he(i,s),a=n.indirect?Ue(r,n.range):Ii(r,n.range),o=n.indirect?Xi(r):null,h=Lt(r),u=new Float32Array(new SharedArrayBuffer(h*6*4)),c=[];for(let x=0,y=Bt.workerCount;x{d+=.1*x,oe(d)}):null},p=[];for(let x=0,y=a.length;x{d+=.9*Y/S,oe(d)})).then(Y=>{const at=Y.buffer;T.buffer=at,w+=at.byteLength});A.push(j)}else _++}await Promise.all(A);const C=n.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,E=new C(w+_*At);We(0,b,E),p.push(E)}postMessage({error:null,serialized:{roots:p,index:i,indirectBuffer:o},position:s,progress:1}),ae=!1}else if(t==="BUILD_SUBTREE"){const{offset:e,count:i,indirectBuffer:s,index:n,position:r,triangleBounds:a,options:o}=l,h={_indirectBuffer:s,geometry:he(n,r)},u={...re,...o,onProgress:o.includedProgressCallback?oe:null},c=Xe(h,a,e,i,u),m=se(c),d=new ArrayBuffer(At*m);We(0,c,d),postMessage({type:"result",buffer:d,progress:1},[d])}else if(t==="BUILD_TRIANGLE_BOUNDS"){const{index:e,position:i,triangleBounds:s,offset:n,count:r}=l,a=he(e,i);Fi(a,s,n,r),postMessage({type:"result"})}};function qe(l){let t=0;return function(i){l(i-t),t=i}}function oe(l){l=Math.min(l,1);const t=performance.now();t-Ye>=10&&l!==1&&(postMessage({error:null,progress:l,type:"progress"}),Ye=t)}function he(l,t){const e=new Kt;return l&&(e.index=new et(l,1,!1)),e.setAttribute("position",new et(t,3)),e}function Yi(l){const t=[];return e(l),t;function e(i,s=0){i.depth=s,t.push(i),!!i.count||(e(i.left,s+1),e(i.right,s+1))}}})(); diff --git a/example/bundle/assets/physics-CQ78Z0rW.js b/example/bundle/assets/physics-CQ78Z0rW.js new file mode 100644 index 000000000..006c7b302 --- /dev/null +++ b/example/bundle/assets/physics-CQ78Z0rW.js @@ -0,0 +1 @@ +import{K as O,V as P,W as U,p as N,c as Q,d as Z,D as _,q as $,P as ee,k as te,J as ae,ac as k,M as W,C as I,e as oe,g as ie,h as ne,ad as se,f as re}from"./ExtendedTriangle-CNpFv597.js";import{G as de}from"./GLTFLoader-CPZ_tJoX.js";import{O as ce}from"./OrbitControls-I50Ha_kb.js";import{S as le}from"./stats.min-GTpOrGrX.js";import{g as pe}from"./lil-gui.module.min-Bc0DeA9g.js";import{M as he}from"./MeshBVH-ujCvfObx.js";import{M as me}from"./MeshBVHHelper-DbtlD37d.js";import{S as we}from"./StaticGeometryGenerator-BuhbcQd1.js";import"./BufferGeometryUtils-BjOdgyuH.js";import"./_commonjsHelpers-Cpj98o6Y.js";const r={displayCollider:!1,displayBVH:!1,displayParents:!1,visualizeDepth:10,gravity:-9.8,physicsSteps:5,simulationSpeed:1,sphereSize:1,pause:!1,step:()=>{const a=r.physicsSteps;for(let i=0;i{x.displayParents=c,x.update()}),o.add(r,"visualizeDepth",1,20,1).onChange(c=>{x.depth=c,x.update()}),o.open();const t=C.addFolder("Physics");t.add(r,"physicsSteps",0,30,1),t.add(r,"gravity",-100,100,.01).onChange(c=>{r.gravity=parseFloat(c)}),t.add(r,"simulationSpeed",0,5,.01),t.add(r,"sphereSize",.2,5,.1),t.add(r,"pause"),t.add(r,"step"),t.open(),C.add(r,"explode"),C.add(r,"reset"),C.open();const n=new te,m=new ae;let s=0,f=0;p.domElement.addEventListener("pointerdown",c=>{s=c.clientX,f=c.clientY}),p.domElement.addEventListener("pointerup",c=>{if(Math.abs(c.clientX-s)+Math.abs(c.clientY-f)>2)return;m.x=c.clientX/window.innerWidth*2-1,m.y=-(c.clientY/window.innerHeight)*2+1,n.setFromCamera(m,w);const L=q();L.position.copy(w.position).addScaledVector(n.ray.direction,3),L.velocity.set(Math.random()-.5,Math.random()-.5,Math.random()-.5).addScaledVector(n.ray.direction,10*Math.random()+15).multiplyScalar(.5)}),window.addEventListener("resize",function(){w.aspect=window.innerWidth/window.innerHeight,w.updateProjectionMatrix(),p.setSize(window.innerWidth,window.innerHeight)},!1),window.createSphere=q}function ye(){new de().load("https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/low-poly-jungle-scene/scene.gltf",a=>{S=a.scene,S.scale.setScalar(.05);const i=new k(65535,9);i.distance=7,i.position.set(-100,-40,100),S.add(i);const e=new k(16768358,9);e.distance=15,e.intensity=5,e.position.set(80,80,135),e.shadow.normalBias=.01,e.shadow.bias=-.001,e.shadow.mapSize.setScalar(1024),e.castShadow=!0,S.add(e),S.updateMatrixWorld(!0);const o=new we(S);o.attributes=["position"];const t=o.generate();t.boundsTree=new he(t),u=new W(t),u.material.wireframe=!0,u.material.opacity=.5,u.material.transparent=!0,x=new me(u,r.visualizeDepth),h.add(x),h.add(u),h.add(S),S.traverse(n=>{n.material&&(n.castShadow=!0,n.receiveShadow=!0,n.material.shadowSide=2)})})}function j(a,i,e,o,t,n=0){if(ts.intersectsSphere(l),intersectsTriangle:s=>{s.closestPointToPoint(l.center,d),d.sub(l.center);const f=d.length();if(fs.distanceToPoint(l.center)-l.radius}),m){d.subVectors(l.center,n.center).normalize(),t.velocity.reflect(d);const s=t.velocity.dot(d);t.velocity.addScaledVector(d,-s*.5),t.velocity.multiplyScalar(Math.max(1-a,0)),n.center.copy(l.center),D.copy(l.center).addScaledVector(d,-l.radius),j(t,null,D,d,s,.05)}}for(let e=0,o=y.length;eg.dot(s.velocity)?(E=F*v*(M-V)/(M+V),H=F*v*2*M/(M+V),E-=v):(E=F*v*2*V/(M+V),H=F*v*(V-M)/(M+V),H-=v),g.normalize(),t.velocity.addScaledVector(g,E),s.velocity.addScaledVector(g,H),D.copy(n.center).addScaledVector(d,-n.radius),j(t,s,D,d,v,0)}}t.position.copy(n.center)}}function ge(){y.forEach(a=>{a.material.dispose(),a.geometry.dispose(),h.remove(a)}),y.length=0,b.forEach(a=>{a.material.dispose(),a.geometry.dispose(),h.remove(a)}),b.length=0}function ve(){const a=new P;y.forEach(i=>{a.copy(i.position),a.y+=10,a.normalize(),i.velocity.addScaledVector(a,120)})}function Y(a){if(u){const i=r.physicsSteps;for(let e=0;e=1&&(b.splice(i,1),o.parent.remove(o),o.geometry.dispose(),o.material.dispose(),i--,e--)}}function A(){G.update(),requestAnimationFrame(A);const a=Math.min(X.getDelta(),.1);u&&(u.visible=r.displayCollider,x.visible=r.displayBVH,r.pause||Y(r.simulationSpeed*a)),p.render(h,w)} diff --git a/example/bundle/assets/pointCloudIntersection-CQp53kpf.js b/example/bundle/assets/pointCloudIntersection-CQp53kpf.js new file mode 100644 index 000000000..d0b6fb373 --- /dev/null +++ b/example/bundle/assets/pointCloudIntersection-CQp53kpf.js @@ -0,0 +1,2 @@ +import{C as J,ae as K,af as Q,i as k,ag as A,ah as O,M as W,J as E,k as ee,W as te,c as ne,P as se,ai as re,aj as oe,f as q,e as ae,n as ie}from"./ExtendedTriangle-CNpFv597.js";import{S as le}from"./Stats-9dH8FB2H.js";import{O as ce}from"./OrbitControls-I50Ha_kb.js";import{g as ue}from"./lil-gui.module.min-Bc0DeA9g.js";import{M as de}from"./MeshBVHHelper-DbtlD37d.js";import{C as X,A as pe,S as me,N as Y,I as he}from"./MeshBVH-ujCvfObx.js";import{a as fe,c as ge,d as ye}from"./ExtensionUtilities-DGy5CKFv.js";const g=new J;class xe extends K{constructor(c){super(c),this.propertyNameMapping={},this.customPropertyMapping={}}load(c,P,T,x){const h=this,p=new Q(this.manager);p.setPath(this.path),p.setResponseType("arraybuffer"),p.setRequestHeader(this.requestHeader),p.setWithCredentials(this.withCredentials),p.load(c,function(u){try{P(h.parse(u))}catch(C){x?x(C):console.error(C),h.manager.itemError(c)}},T,x)}setPropertyNameMapping(c){this.propertyNameMapping=c}setCustomPropertyNameMapping(c){this.customPropertyMapping=c}parse(c){function P(e,r=0){const n=/^ply([\s\S]*)end_header(\r\n|\r|\n)/;let t="";const s=n.exec(e);s!==null&&(t=s[1]);const o={comments:[],elements:[],headerLength:r,objInfo:""},i=t.split(/\r\n|\r|\n/);let a;function w(d,m){const l={type:d[0]};return l.type==="list"?(l.name=d[3],l.countType=d[1],l.itemType=d[2]):l.name=d[1],l.name in m&&(l.name=m[l.name]),l}for(let d=0;dt.name);function n(t){for(let s=0,o=t.length;s0&&r.setIndex(e.indices),r.setAttribute("position",new A(e.vertices,3)),e.normals.length>0&&r.setAttribute("normal",new A(e.normals,3)),e.uvs.length>0&&r.setAttribute("uv",new A(e.uvs,2)),e.colors.length>0&&r.setAttribute("color",new A(e.colors,3)),(e.faceVertexUvs.length>0||e.faceVertexColors.length>0)&&(r=r.toNonIndexed(),e.faceVertexUvs.length>0&&r.setAttribute("uv",new A(e.faceVertexUvs,2)),e.faceVertexColors.length>0&&r.setAttribute("color",new A(e.faceVertexColors,3)));for(const n of Object.keys(H.customPropertyMapping))e[n].length>0&&r.setAttribute(n,new A(e[n],H.customPropertyMapping[n].length));return r.computeBoundingSphere(),r}function f(e,r,n,t){if(r==="vertex"){e.vertices.push(n[t.attrX],n[t.attrY],n[t.attrZ]),t.attrNX!==null&&t.attrNY!==null&&t.attrNZ!==null&&e.normals.push(n[t.attrNX],n[t.attrNY],n[t.attrNZ]),t.attrS!==null&&t.attrT!==null&&e.uvs.push(n[t.attrS],n[t.attrT]),t.attrR!==null&&t.attrG!==null&&t.attrB!==null&&(g.setRGB(n[t.attrR]/255,n[t.attrG]/255,n[t.attrB]/255,O),e.colors.push(g.r,g.g,g.b));for(const s of Object.keys(H.customPropertyMapping))for(const o of H.customPropertyMapping[s])e[s].push(n[o])}else if(r==="face"){const s=n.vertex_indices||n.vertex_index,o=n.texcoord;s.length===3?(e.indices.push(s[0],s[1],s[2]),o&&o.length===6&&(e.faceVertexUvs.push(o[0],o[1]),e.faceVertexUvs.push(o[2],o[3]),e.faceVertexUvs.push(o[4],o[5]))):s.length===4&&(e.indices.push(s[0],s[1],s[3]),e.indices.push(s[1],s[2],s[3])),t.attrR!==null&&t.attrG!==null&&t.attrB!==null&&(g.setRGB(n[t.attrR]/255,n[t.attrG]/255,n[t.attrB]/255,O),e.faceVertexColors.push(g.r,g.g,g.b),e.faceVertexColors.push(g.r,g.g,g.b),e.faceVertexColors.push(g.r,g.g,g.b))}}function z(e,r){const n={};let t=0;for(let s=0;ss.getInt8(a),size:1};case"uint8":case"uchar":return{read:a=>s.getUint8(a),size:1};case"int16":case"short":return{read:a=>s.getInt16(a,i),size:2};case"uint16":case"ushort":return{read:a=>s.getUint16(a,i),size:2};case"int32":case"int":return{read:a=>s.getInt32(a,i),size:4};case"uint32":case"uint":return{read:a=>s.getUint32(a,i),size:4};case"float32":case"float":return{read:a=>s.getFloat32(a,i),size:4};case"float64":case"double":return{read:a=>s.getFloat64(a,i),size:8}}}for(let s=0,o=e.length;s=this.arr.length}next(){return this.arr[this.i++]}}W.prototype.raycast=fe;k.prototype.computeBoundsTree=ge;k.prototype.disposeBoundsTree=ye;let F,L,B,b,v,M,j,Z,D=new E,S;const Te="https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/point-cloud-porsche/scene.ply",V=new ee,y={displayHelper:!1,helperDepth:10,displayParents:!1,strategy:X,pointSize:.005,raycastThreshold:.005,useBVH:!0};function Ce(){Z=document.getElementById("output"),b=new te({antialias:!0}),b.setPixelRatio(window.devicePixelRatio),b.setSize(window.innerWidth,window.innerHeight),b.setClearColor(1251612,1),document.body.appendChild(b.domElement),L=new ne,B=new se(75,window.innerWidth/window.innerHeight,.1,50),B.position.set(3,3,3),B.far=100,B.updateProjectionMatrix(),new ce(B,b.domElement),F=new le,document.body.appendChild(F.dom),window.addEventListener("resize",function(){B.aspect=window.innerWidth/window.innerHeight,B.updateProjectionMatrix(),b.setSize(window.innerWidth,window.innerHeight)},!1),new xe().load(Te,u=>{u.center();const C=new re({size:y.pointSize,vertexColors:!0});j=new oe(u,C),j.matrixAutoUpdate=!1,L.add(j);const f=[],z=u.clone();let R=z.attributes.position.count;for(let I=0,N=R;I{M.displayParents=u,M.update()}),h.add(y,"helperDepth",1,20,1).name("depth").onChange(u=>{M.depth=parseInt(u),M.update()}),h.open();const p=x.addFolder("points");p.add(y,"useBVH"),p.add(y,"strategy",{CENTER:X,AVERAGE:pe,SAH:me}).onChange(u=>{console.time("computeBoundsTree"),v.geometry.computeBoundsTree({strategy:parseInt(u)}),console.timeEnd("computeBoundsTree"),M.update()}),p.add(y,"pointSize",.001,.01,.001),p.add(y,"raycastThreshold",.001,.01,.001),p.open()}window.addEventListener("pointermove",_=>{if(!v)return;D.x=_.clientX/window.innerWidth*2-1,D.y=-(_.clientY/window.innerHeight)*2+1,V.setFromCamera(D,B);const c=window.performance.now();if(y.useBVH){S.visible=!1;const T=new ie;T.copy(v.matrixWorld).invert(),V.ray.applyMatrix4(T);const h=V.params.Points.threshold/((v.scale.x+v.scale.y+v.scale.z)/3),p=h*h,{ray:u}=V;let C=1/0;v.geometry.boundsTree.shapecast({boundsTraverseOrder:f=>f.distanceToPoint(u.origin),intersectsBounds:(f,z,R)=>R>C?Y:(f.expandByScalar(h),u.intersectsBox(f)?he:Y),intersectsTriangle:f=>{if(u.distanceSqToPoint(f.a)c()),a.add(e.raycasters,"speed").min(0).max(20),a.add(e.raycasters,"near").min(0).max(f).onChange(()=>c()),a.add(e.raycasters,"far").min(0).max(f).onChange(()=>c()),a.open();const n=u.addFolder("Mesh");n.add(e.mesh,"useBoundsTree").onChange(()=>c()),n.add(e.mesh,"splitStrategy",{CENTER:F,SAH:Y,AVERAGE:Z}).onChange(()=>c()),n.add(e.mesh,"count").min(1).max(300).step(1).onChange(()=>c()),n.add(e.mesh,"speed").min(0).max(20),n.add(e.mesh,"visualizeBounds").onChange(()=>c()),n.add(e.mesh,"displayParents").onChange(()=>c()),n.add(e.mesh,"visualBoundsDepth").min(1).max(20).step(1).onChange(()=>c()),n.open(),window.addEventListener("resize",function(){x.aspect=window.innerWidth/window.innerHeight,x.updateProjectionMatrix(),g.setSize(window.innerWidth,window.innerHeight)},!1)}function oe(){const t=new M(i,H);t.rotation.x=Math.random()*10,t.rotation.y=Math.random()*10,l.push(t),s.add(t)}function re(){const t=new R,o=new P({color:16777215}),d=new M(z,o),p=new M(z,o);p.scale.multiplyScalar(.25),d.scale.multiplyScalar(.5);const h=new M(ae,new P({color:16777215,transparent:!0,opacity:.25}));t.add(h),t.add(d),t.add(p),y.add(t),d.position.set(f,0,0),t.rotation.x=Math.random()*10,t.rotation.y=Math.random()*10,t.rotation.z=Math.random()*10;const u=new S,a=new S,n=Math.random()-.5,C=Math.random()-.5,V=Math.random()-.5;T.push({update:()=>{t.rotation.x+=n*1e-4*e.raycasters.speed*w,t.rotation.y+=C*1e-4*e.raycasters.speed*w,t.rotation.z+=V*1e-4*e.raycasters.speed*w,d.updateMatrixWorld(),u.setFromMatrixPosition(d.matrixWorld),a.copy(u).multiplyScalar(-1).normalize(),m.set(u,a),m.firstHitOnly=!0;const E=m.intersectObject(s,!0),v=E.length?E[0].distance:f;p.position.set(f-v,0,0);const A=E.length?v-m.near:v-m.near-(f-m.far);h.position.set(f-m.near-A/2,0,0),h.scale.set(1,A,1),h.rotation.z=Math.PI/2},remove:()=>{y.remove(t)}})}function c(){for(m.near=e.raycasters.near,m.far=e.raycasters.far;T.length>e.raycasters.count;)T.pop().remove();for(;T.lengthe.mesh.count;)s.remove(l.pop());for(;l.lengtha+(n-a)*C,p=(l.length-1)/299,h=d(0,2,p),u=d(1,.2,p);l.forEach(a=>{a.scale.set(1,1,1).multiplyScalar(u);const n=new S(0,1,0);n.applyAxisAngle(new S(1,0,0),Math.PI*Math.random()),n.applyAxisAngle(new S(0,1,0),2*Math.PI*Math.random()),n.multiplyScalar(h),a.position.set(n.x,n.y,n.z)})}const o=e.mesh.visualizeBounds&&i.boundsTree;r&&!o&&(s.remove(r),r=null),!r&&o&&(r=new _(l[0]),s.add(r)),r&&(r.depth=e.mesh.visualBoundsDepth,r.displayParents=e.mesh.displayParents,r.update())}function W(){B.begin();const t=window.performance.now();b=b||t,w=t-b,s.rotation.x+=1e-4*e.mesh.speed*w,s.rotation.y+=1e-4*e.mesh.speed*w,s.children.forEach(o=>{o.rotation.x+=1e-4*e.mesh.speed*w,o.rotation.y+=1e-4*e.mesh.speed*w}),s.updateMatrixWorld(),T.forEach(o=>o.update()),g.render(y,x),b=t,B.end(),requestAnimationFrame(W)} diff --git a/example/bundle/assets/sculpt-DzLeUcaz.js b/example/bundle/assets/sculpt-DzLeUcaz.js new file mode 100644 index 000000000..36af3fabc --- /dev/null +++ b/example/bundle/assets/sculpt-DzLeUcaz.js @@ -0,0 +1 @@ +import{M as ne,i as ae,V as b,J as se,W as de,c as ce,d as le,D as me,A as pe,v as fe,P as ue,am as Y,an as we,k as ie,ao as he,u as Q,n as ye,K as ge,r as xe,U as be}from"./ExtendedTriangle-CNpFv597.js";import{S as ve}from"./Stats-9dH8FB2H.js";import{g as Se}from"./lil-gui.module.min-Bc0DeA9g.js";import{O as Be}from"./OrbitControls-I50Ha_kb.js";import{a as Ce}from"./BufferGeometryUtils-BjOdgyuH.js";import{M as Me}from"./MeshBVHHelper-DbtlD37d.js";import{I as $,a as Ee,N as ze}from"./MeshBVH-ujCvfObx.js";import{a as Ae,c as Te,d as Pe}from"./ExtensionUtilities-DGy5CKFv.js";ne.prototype.raycast=Ae;ae.prototype.computeBoundsTree=Te;ae.prototype.disposeBoundsTree=Pe;let U,x,M,C,I,o,h,S,y,He=new b(0,0,1),O=!1,B=new se,W=new se,Z=!1,ee=!1,v=new b,q,oe=!1;const t={matcap:"Clay",size:.1,brush:"clay",intensity:50,maxSteps:10,invert:!1,symmetrical:!0,flatShading:!1,depth:10,displayHelper:!1},H={};Ie();re();function te(){o&&(o.geometry.dispose(),o.material.dispose(),x.remove(o));let m=new he(1,100);m.deleteAttribute("uv"),m=Ce(m),m.attributes.position.setUsage(Q),m.attributes.normal.setUsage(Q),m.computeBoundsTree({setBoundingBox:!1}),o=new ne(m,q),o.frustumCulled=!1,x.add(o),y||(y=new Me(o,t.depth),t.displayHelper&&x.add(y)),y.mesh=o,y.update()}function Ie(){C=new de({antialias:!0}),C.setPixelRatio(window.devicePixelRatio),C.setSize(window.innerWidth,window.innerHeight),C.setClearColor(394761,1),C.outputEncoding=void 0,document.body.appendChild(C.domElement),C.domElement.style.touchAction="none",x=new ce,x.fog=new le(2503224/2,20,60);const a=new me(16777215,.5);a.position.set(1,1,1),x.add(a),x.add(new pe(16777215,.4));const n=[new b,new b(0,0,1)];for(let e=0;e<50;e++){const s=e+1,r=Math.sin(2*Math.PI*e/50),d=Math.cos(2*Math.PI*e/50),i=Math.sin(2*Math.PI*s/50),f=Math.cos(2*Math.PI*s/50);n.push(new b(r,d,0),new b(i,f,0))}h=new fe,h.geometry.setFromPoints(n),h.material.color.set(16485376),x.add(h),S=h.clone(),x.add(S),M=new ue(75,window.innerWidth/window.innerHeight,.1,50),M.position.set(0,0,3),M.far=100,M.updateProjectionMatrix(),U=new ve,document.body.appendChild(U.dom),H.Clay=new Y().load("../textures/B67F6B_4B2E2A_6C3A34_F3DBC6-256px.png"),H["Red Wax"]=new Y().load("../textures/763C39_431510_210504_55241C-256px.png"),H["Shiny Green"]=new Y().load("../textures/3B6E10_E3F2C3_88AC2E_99CE51-256px.png"),H.Normal=new Y().load("../textures/7877EE_D87FC5_75D9C7_1C78C0-256px.png"),q=new we({flatShading:t.flatShading});for(const e in H)H[e].encoding=void 0;te();const p=new Se;p.add(t,"matcap",Object.keys(H));const c=p.addFolder("Sculpting");c.add(t,"brush",["normal","clay","flatten"]),c.add(t,"size").min(.025).max(.25).step(.005),c.add(t,"intensity").min(1).max(100).step(1),c.add(t,"maxSteps").min(1).max(25).step(1),c.add(t,"symmetrical"),c.add(t,"invert"),c.add(t,"flatShading").onChange(e=>{o.material.flatShading=e,o.material.needsUpdate=!0}),c.open();const l=p.addFolder("BVH Helper");l.add(t,"depth").min(1).max(20).step(1).onChange(e=>{y.depth=parseFloat(e),y.update()}),l.add(t,"displayHelper").onChange(e=>{e?(x.add(y),y.update()):x.remove(y)}),l.open(),p.add({reset:te},"reset"),p.add({rebuildBVH:()=>{o.geometry.computeBoundsTree({setBoundingBox:!1}),y.update()}},"rebuildBVH"),p.open(),window.addEventListener("resize",function(){M.aspect=window.innerWidth/window.innerHeight,M.updateProjectionMatrix(),C.setSize(window.innerWidth,window.innerHeight)},!1),window.addEventListener("pointermove",function(e){B.x=e.clientX/window.innerWidth*2-1,B.y=-(e.clientY/window.innerHeight)*2+1,O=!0}),window.addEventListener("pointerdown",e=>{B.x=e.clientX/window.innerWidth*2-1,B.y=-(e.clientY/window.innerHeight)*2+1,Z=!!(e.buttons&3),oe=!!(e.buttons&2),O=!0;const s=new ie;s.setFromCamera(B,M),s.firstHitOnly=!0;const r=s.intersectObject(o);I.enabled=r.length===0},!0),window.addEventListener("pointerup",e=>{Z=!!(e.buttons&3),e.pointerType==="touch"&&(O=!1)}),window.addEventListener("contextmenu",function(e){e.preventDefault()}),window.addEventListener("wheel",function(e){let s=e.deltaY;e.deltaMode===1&&(s*=40),e.deltaMode===2&&(s*=40),t.size+=s*1e-4,t.size=Math.max(Math.min(t.size,.25),.025),p.controllersRecursive().forEach(r=>r.updateDisplay())}),I=new Be(M,C.domElement),I.minDistance=1.5,I.addEventListener("start",function(){this.active=!0}),I.addEventListener("end",function(){this.active=!1})}function X(m,a,n=!1,p={}){const{accumulatedTriangles:c=new Set,accumulatedIndices:l=new Set,accumulatedTraversedNodeIndices:e=new Set}=p,s=new ye;s.copy(o.matrixWorld).invert();const r=new ge;r.center.copy(m).applyMatrix4(s),r.radius=t.size;const d=new Set,i=new b,f=new b,z=o.geometry.index,g=o.geometry.attributes.position,D=o.geometry.attributes.normal,V=new Set;o.geometry.boundsTree.shapecast({intersectsBounds:(u,N,L,w,E)=>{e.add(E);const F=r.intersectsBox(u),{min:_,max:R}=u;if(F){for(let A=0;A<=1;A++)for(let T=0;T<=1;T++)for(let P=0;P<=1;P++)if(i.set(A===0?_.x:R.x,T===0?_.y:R.y,P===0?_.z:R.z),!r.containsPoint(i))return $;return Ee}return F?$:ze},intersectsTriangle:(u,N,L)=>{const w=N;V.add(w),c.add(w);const E=3*N,F=E+0,_=E+1,R=E+2,A=z.getX(F),T=z.getX(_),P=z.getX(R);return L?(d.add(A),d.add(T),d.add(P),l.add(A),l.add(T),l.add(P)):(r.containsPoint(u.a)&&(d.add(A),l.add(A)),r.containsPoint(u.b)&&(d.add(T),l.add(T)),r.containsPoint(u.c)&&(d.add(P),l.add(P))),!1}});const J=new b;J.copy(m).applyMatrix4(s);const k=new b;let j=0;if(d.forEach(u=>{i.fromBufferAttribute(D,u),f.add(i),n||(j++,i.fromBufferAttribute(g,u),k.add(i))}),f.normalize(),a.quaternion.setFromUnitVectors(He,f),j&&k.multiplyScalar(1/j),n)return;const K=t.intensity*1e-4,G=new xe;G.setFromNormalAndCoplanarPoint(f,k),d.forEach(u=>{i.fromBufferAttribute(g,u);const N=i.distanceTo(J),L=t.invert!==oe?-1:1;let w=1-N/t.size;if(t.brush==="clay"){w=Math.pow(w,3);const E=G.distanceToPoint(i),F=L*Math.min(w*4,1);i.addScaledVector(f,F*K-L*E*F*.3)}else if(t.brush==="normal")w=Math.pow(w,2),i.addScaledVector(f,L*w*K);else if(t.brush==="flatten"){w=Math.pow(w,2);const E=G.distanceToPoint(i);i.addScaledVector(f,-E*w*t.intensity*.01*.5)}g.setXYZ(u,i.x,i.y,i.z),D.setXYZ(u,0,0,0)}),d.size&&(g.needsUpdate=!0)}function De(m,a){const n=new b,p=new b,c=o.geometry.index,l=o.geometry.attributes.position,e=o.geometry.attributes.normal,s=new be;m.forEach(r=>{const d=r*3,i=d+0,f=d+1,z=d+2,g=c.getX(i),D=c.getX(f),V=c.getX(z);s.a.fromBufferAttribute(l,g),s.b.fromBufferAttribute(l,D),s.c.fromBufferAttribute(l,V),s.getNormal(p),a.has(g)&&(n.fromBufferAttribute(e,g),n.add(p),e.setXYZ(g,n.x,n.y,n.z)),a.has(D)&&(n.fromBufferAttribute(e,D),n.add(p),e.setXYZ(D,n.x,n.y,n.z)),a.has(V)&&(n.fromBufferAttribute(e,V),n.add(p),e.setXYZ(V,n.x,n.y,n.z))}),a.forEach(r=>{n.fromBufferAttribute(e,r),n.normalize(),e.setXYZ(r,n.x,n.y,n.z)}),e.needsUpdate=!0}function re(){if(requestAnimationFrame(re),U.begin(),q.matcap=H[t.matcap],I.active||!O)h.visible=!1,S.visible=!1,v.setScalar(1/0);else{const m=new ie;m.setFromCamera(B,M),m.firstHitOnly=!0;const a=m.intersectObject(o,!0)[0];if(a)if(h.visible=!0,h.scale.set(t.size,t.size,.1),h.position.copy(a.point),S.visible=t.symmetrical,S.scale.set(t.size,t.size,.1),S.position.copy(a.point),S.position.x*=-1,I.enabled=!1,v.x===1/0&&v.copy(a.point),!(Z||ee))X(a.point,h,!0),t.symmetrical&&(a.point.x*=-1,X(a.point,S,!0),a.point.x*=-1),W.copy(B),v.copy(a.point);else{const n=(B.x-W.x)*window.innerWidth*window.devicePixelRatio,p=(B.y-W.y)*window.innerHeight*window.devicePixelRatio;let c=Math.sqrt(n*n+p*p),l=a.point.distanceTo(v);const e=t.size*.15,s=Math.max(e/l,1/t.maxSteps),r=c*s;let d=0;const i=new Set,f=new Set,z=new Set,g={accumulatedTriangles:i,accumulatedIndices:f,accumulatedTraversedNodeIndices:z};for(;l>e&&c>t.size*200/a.distance&&(W.lerp(B,s),v.lerp(a.point,s),l-=e,c-=r,X(v,h,!1,g),t.symmetrical&&(v.x*=-1,X(v,S,!1,g),v.x*=-1),d++,!(d>t.maxSteps)););d>0?(De(i,f),o.geometry.boundsTree.refit(z),y.parent!==null&&y.update()):(X(a.point,h,!0),t.symmetrical&&(a.point.x*=-1,X(a.point,S,!0),a.point.x*=-1))}else I.enabled=!0,h.visible=!1,S.visible=!1,W.copy(B),v.setScalar(1/0)}ee=Z,C.render(x,M),U.end()} diff --git a/example/bundle/assets/sdfGeneration-Dbz2SQyC.js b/example/bundle/assets/sdfGeneration-Dbz2SQyC.js new file mode 100644 index 000000000..405efd372 --- /dev/null +++ b/example/bundle/assets/sdfGeneration-Dbz2SQyC.js @@ -0,0 +1,409 @@ +import{S as R,n as b,V as y,W as Y,c as $,D as K,A as Q,P as X,ap as J,b as Z,M as ee,g as te,a as oe,R as B,F as M,H as L,L as S,aa as ne,aq as re,Y as ie,t as ae,ar as se}from"./ExtendedTriangle-CNpFv597.js";import{G as ce}from"./GLTFLoader-CPZ_tJoX.js";import{F}from"./Pass-Bx56TwXN.js";import{O as de}from"./OrbitControls-I50Ha_kb.js";import{g as le}from"./lil-gui.module.min-Bc0DeA9g.js";import{S as ue}from"./stats.min-GTpOrGrX.js";import{G as ve}from"./GenerateMeshBVHWorker-CkitdNK9.js";import{M as fe}from"./MeshBVHUniformStruct-CwgYze0J.js";import{c as me,b as pe,a as xe}from"./bvh_struct_definitions.glsl-SZg5BxSQ.js";import{M as he}from"./meshopt_decoder.module-Cf1-17OU.js";import{S as ye}from"./StaticGeometryGenerator-BuhbcQd1.js";import"./BufferGeometryUtils-BjOdgyuH.js";import"./_commonjsHelpers-Cpj98o6Y.js";import"./MeshBVH-ujCvfObx.js";const ge=` + +float dot2( vec3 v ) { + + return dot( v, v ); + +} + +// https://www.shadertoy.com/view/ttfGWl +vec3 closestPointToTriangle( vec3 p, vec3 v0, vec3 v1, vec3 v2, out vec3 barycoord ) { + + vec3 v10 = v1 - v0; + vec3 v21 = v2 - v1; + vec3 v02 = v0 - v2; + + vec3 p0 = p - v0; + vec3 p1 = p - v1; + vec3 p2 = p - v2; + + vec3 nor = cross( v10, v02 ); + + // method 2, in barycentric space + vec3 q = cross( nor, p0 ); + float d = 1.0 / dot2( nor ); + float u = d * dot( q, v02 ); + float v = d * dot( q, v10 ); + float w = 1.0 - u - v; + + if( u < 0.0 ) { + + w = clamp( dot( p2, v02 ) / dot2( v02 ), 0.0, 1.0 ); + u = 0.0; + v = 1.0 - w; + + } else if( v < 0.0 ) { + + u = clamp( dot( p0, v10 ) / dot2( v10 ), 0.0, 1.0 ); + v = 0.0; + w = 1.0 - u; + + } else if( w < 0.0 ) { + + v = clamp( dot( p1, v21 ) / dot2( v21 ), 0.0, 1.0 ); + w = 0.0; + u = 1.0-v; + + } + + barycoord = vec3( u, v, w ); + return u * v1 + v * v2 + w * v0; + +} + +float distanceToTriangles( + // geometry info and triangle range + sampler2D positionAttr, usampler2D indexAttr, uint offset, uint count, + + // point and cut off range + vec3 point, float closestDistanceSquared, + + // outputs + inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord, inout float side, inout vec3 outPoint +) { + + bool found = false; + vec3 localBarycoord; + for ( uint i = offset, l = offset + count; i < l; i ++ ) { + + uvec3 indices = uTexelFetch1D( indexAttr, i ).xyz; + vec3 a = texelFetch1D( positionAttr, indices.x ).rgb; + vec3 b = texelFetch1D( positionAttr, indices.y ).rgb; + vec3 c = texelFetch1D( positionAttr, indices.z ).rgb; + + // get the closest point and barycoord + vec3 closestPoint = closestPointToTriangle( point, a, b, c, localBarycoord ); + vec3 delta = point - closestPoint; + float sqDist = dot2( delta ); + if ( sqDist < closestDistanceSquared ) { + + // set the output results + closestDistanceSquared = sqDist; + faceIndices = uvec4( indices.xyz, i ); + faceNormal = normalize( cross( a - b, b - c ) ); + barycoord = localBarycoord; + outPoint = closestPoint; + side = sign( dot( faceNormal, delta ) ); + + } + + } + + return closestDistanceSquared; + +} + +float distanceSqToBounds( vec3 point, vec3 boundsMin, vec3 boundsMax ) { + + vec3 clampedPoint = clamp( point, boundsMin, boundsMax ); + vec3 delta = point - clampedPoint; + return dot( delta, delta ); + +} + +float distanceSqToBVHNodeBoundsPoint( vec3 point, sampler2D bvhBounds, uint currNodeIndex ) { + + uint cni2 = currNodeIndex * 2u; + vec3 boundsMin = texelFetch1D( bvhBounds, cni2 ).xyz; + vec3 boundsMax = texelFetch1D( bvhBounds, cni2 + 1u ).xyz; + return distanceSqToBounds( point, boundsMin, boundsMax ); + +} + +// use a macro to hide the fact that we need to expand the struct into separate fields +#define bvhClosestPointToPoint( bvh, point, faceIndices, faceNormal, barycoord, side, outPoint ) _bvhClosestPointToPoint( bvh.position, bvh.index, bvh.bvhBounds, bvh.bvhContents, point, faceIndices, faceNormal, barycoord, side, outPoint ) + +float _bvhClosestPointToPoint( + // bvh info + sampler2D bvh_position, usampler2D bvh_index, sampler2D bvh_bvhBounds, usampler2D bvh_bvhContents, + + // point to check + vec3 point, + + // output variables + inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord, + inout float side, inout vec3 outPoint + ) { + + // stack needs to be twice as long as the deepest tree we expect because + // we push both the left and right child onto the stack every traversal + int ptr = 0; + uint stack[ BVH_STACK_DEPTH ]; + stack[ 0 ] = 0u; + + float closestDistanceSquared = pow( 100000.0, 2.0 ); + bool found = false; + while ( ptr > - 1 && ptr < BVH_STACK_DEPTH ) { + + uint currNodeIndex = stack[ ptr ]; + ptr --; + + // check if we intersect the current bounds + float boundsHitDistance = distanceSqToBVHNodeBoundsPoint( point, bvh_bvhBounds, currNodeIndex ); + if ( boundsHitDistance > closestDistanceSquared ) { + + continue; + + } + + uvec2 boundsInfo = uTexelFetch1D( bvh_bvhContents, currNodeIndex ).xy; + bool isLeaf = bool( boundsInfo.x & 0xffff0000u ); + if ( isLeaf ) { + + uint count = boundsInfo.x & 0x0000ffffu; + uint offset = boundsInfo.y; + closestDistanceSquared = distanceToTriangles( + bvh_position, bvh_index, offset, count, point, closestDistanceSquared, + + // outputs + faceIndices, faceNormal, barycoord, side, outPoint + ); + + } else { + + uint leftIndex = currNodeIndex + 1u; + uint splitAxis = boundsInfo.x & 0x0000ffffu; + uint rightIndex = boundsInfo.y; + bool leftToRight = distanceSqToBVHNodeBoundsPoint( point, bvh_bvhBounds, leftIndex ) < distanceSqToBVHNodeBoundsPoint( point, bvh_bvhBounds, rightIndex );//rayDirection[ splitAxis ] >= 0.0; + uint c1 = leftToRight ? leftIndex : rightIndex; + uint c2 = leftToRight ? rightIndex : leftIndex; + + // set c2 in the stack so we traverse it later. We need to keep track of a pointer in + // the stack while we traverse. The second pointer added is the one that will be + // traversed first + ptr ++; + stack[ ptr ] = c2; + ptr ++; + stack[ ptr ] = c1; + + } + + } + + return sqrt( closestDistanceSquared ); + +} +`;class be extends R{constructor(o){super({defines:{USE_SHADER_RAYCAST:window.location.hash.includes("USE_SHADER_RAYCAST")?1:0},uniforms:{matrix:{value:new b},zValue:{value:0},bvh:{value:new fe}},vertexShader:` + + varying vec2 vUv; + + void main() { + + vUv = uv; + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + + } + + `,fragmentShader:` + + precision highp isampler2D; + precision highp usampler2D; + + ${me} + ${pe} + ${xe} + ${ge} + + varying vec2 vUv; + + uniform BVH bvh; + uniform float zValue; + uniform mat4 matrix; + + void main() { + + // compute the point in space to check + vec3 point = vec3( vUv, zValue ); + point -= vec3( 0.5 ); + point = ( matrix * vec4( point, 1.0 ) ).xyz; + + // retrieve the distance and other values + uvec4 faceIndices; + vec3 faceNormal; + vec3 barycoord; + float side; + float rayDist; + vec3 outPoint; + float dist = bvhClosestPointToPoint( bvh, point.xyz, faceIndices, faceNormal, barycoord, side, outPoint ); + + // This currently causes issues on some devices when rendering to 3d textures and texture arrays + #if USE_SHADER_RAYCAST + + side = 1.0; + bvhIntersectFirstHit( bvh, point.xyz, vec3( 0.0, 0.0, 1.0 ), faceIndices, faceNormal, barycoord, side, rayDist ); + + #endif + + // if the triangle side is the back then it must be on the inside and the value negative + gl_FragColor = vec4( side * dist, 0, 0, 0 ); + + } + + `}),this.setValues(o)}}class we extends R{constructor(o){super({defines:{DISPLAY_GRID:0},uniforms:{sdfTex:{value:null},layer:{value:0},layers:{value:0}},vertexShader:` + + varying vec2 vUv; + + void main() { + + vUv = uv; + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + + } + + `,fragmentShader:` + precision highp sampler3D; + + varying vec2 vUv; + uniform sampler3D sdfTex; + uniform float layer; + uniform float layers; + + void main() { + + #if DISPLAY_GRID + + float dim = ceil( sqrt( layers ) ); + vec2 cell = floor( vUv * dim ); + vec2 frac = vUv * dim - cell; + float zLayer = ( cell.y * dim + cell.x ) / ( dim * dim ); + + float dist = texture( sdfTex, vec3( frac, zLayer ) ).r; + gl_FragColor.rgb = dist > 0.0 ? vec3( 0, dist, 0 ) : vec3( - dist, 0, 0 ); + gl_FragColor.a = 1.0; + + #else + + float dist = texture( sdfTex, vec3( vUv, layer ) ).r; + gl_FragColor.rgb = dist > 0.0 ? vec3( 0, dist, 0 ) : vec3( - dist, 0, 0 ); + gl_FragColor.a = 1.0; + + #endif + + #include + + } + `}),this.setValues(o)}}class Te extends R{constructor(o){super({defines:{MAX_STEPS:500,SURFACE_EPSILON:.001},uniforms:{surface:{value:0},sdfTex:{value:null},normalStep:{value:new y},projectionInverse:{value:new b},sdfTransformInverse:{value:new b}},vertexShader:` + + varying vec2 vUv; + + void main() { + + vUv = uv; + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + + } + + `,fragmentShader:` + precision highp sampler3D; + + varying vec2 vUv; + + uniform float surface; + uniform sampler3D sdfTex; + uniform vec3 normalStep; + uniform mat4 projectionInverse; + uniform mat4 sdfTransformInverse; + + #include + + // distance to box bounds + vec2 rayBoxDist( vec3 boundsMin, vec3 boundsMax, vec3 rayOrigin, vec3 rayDir ) { + + vec3 t0 = ( boundsMin - rayOrigin ) / rayDir; + vec3 t1 = ( boundsMax - rayOrigin ) / rayDir; + vec3 tmin = min( t0, t1 ); + vec3 tmax = max( t0, t1 ); + + float distA = max( max( tmin.x, tmin.y ), tmin.z ); + float distB = min( tmax.x, min( tmax.y, tmax.z ) ); + + float distToBox = max( 0.0, distA ); + float distInsideBox = max( 0.0, distB - distToBox ); + return vec2( distToBox, distInsideBox ); + + } + + void main() { + + // get the inverse of the sdf box transform + mat4 sdfTransform = inverse( sdfTransformInverse ); + + // convert the uv to clip space for ray transformation + vec2 clipSpace = 2.0 * vUv - vec2( 1.0 ); + + // get world ray direction + vec3 rayOrigin = vec3( 0.0 ); + vec4 homogenousDirection = projectionInverse * vec4( clipSpace, - 1.0, 1.0 ); + vec3 rayDirection = normalize( homogenousDirection.xyz / homogenousDirection.w ); + + // transform ray into local coordinates of sdf bounds + vec3 sdfRayOrigin = ( sdfTransformInverse * vec4( rayOrigin, 1.0 ) ).xyz; + vec3 sdfRayDirection = normalize( ( sdfTransformInverse * vec4( rayDirection, 0.0 ) ).xyz ); + + // find whether our ray hits the box bounds in the local box space + vec2 boxIntersectionInfo = rayBoxDist( vec3( - 0.5 ), vec3( 0.5 ), sdfRayOrigin, sdfRayDirection ); + float distToBox = boxIntersectionInfo.x; + float distInsideBox = boxIntersectionInfo.y; + bool intersectsBox = distInsideBox > 0.0; + + gl_FragColor = vec4( 0.0 ); + if ( intersectsBox ) { + + // find the surface point in world space + bool intersectsSurface = false; + vec4 localPoint = vec4( sdfRayOrigin + sdfRayDirection * ( distToBox + 1e-5 ), 1.0 ); + vec4 point = sdfTransform * localPoint; + + // ray march + for ( int i = 0; i < MAX_STEPS; i ++ ) { + + // sdf box extends from - 0.5 to 0.5 + // transform into the local bounds space [ 0, 1 ] and check if we're inside the bounds + vec3 uv = ( sdfTransformInverse * point ).xyz + vec3( 0.5 ); + if ( uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0 || uv.z < 0.0 || uv.z > 1.0 ) { + + break; + + } + + // get the distance to surface and exit the loop if we're close to the surface + float distanceToSurface = texture2D( sdfTex, uv ).r - surface; + if ( distanceToSurface < SURFACE_EPSILON ) { + + intersectsSurface = true; + break; + + } + + // step the ray + point.xyz += rayDirection * abs( distanceToSurface ); + + } + + // find the surface normal + if ( intersectsSurface ) { + + // compute the surface normal + vec3 uv = ( sdfTransformInverse * point ).xyz + vec3( 0.5 ); + float dx = texture( sdfTex, uv + vec3( normalStep.x, 0.0, 0.0 ) ).r - texture( sdfTex, uv - vec3( normalStep.x, 0.0, 0.0 ) ).r; + float dy = texture( sdfTex, uv + vec3( 0.0, normalStep.y, 0.0 ) ).r - texture( sdfTex, uv - vec3( 0.0, normalStep.y, 0.0 ) ).r; + float dz = texture( sdfTex, uv + vec3( 0.0, 0.0, normalStep.z ) ).r - texture( sdfTex, uv - vec3( 0.0, 0.0, normalStep.z ) ).r; + vec3 normal = normalize( vec3( dx, dy, dz ) ); + + // compute some basic lighting effects + vec3 lightDirection = normalize( vec3( 1.0 ) ); + float lightIntensity = + saturate( dot( normal, lightDirection ) ) + + saturate( dot( normal, - lightDirection ) ) * 0.05 + + 0.1; + gl_FragColor.rgb = vec3( lightIntensity ); + gl_FragColor.a = 1.0; + + } + + } + + #include + + } + `}),this.setValues(o)}}const t={gpuGeneration:!0,resolution:75,margin:.2,regenerate:()=>N(),mode:"raymarching",layer:0,surface:.1};let r,a,m,h,z,c,V,I,v,n,P,g,A,u,U;const G=new b;De();k();function De(){V=document.getElementById("output"),r=new Y({antialias:!0}),r.setPixelRatio(window.devicePixelRatio),r.setSize(window.innerWidth,window.innerHeight),r.setClearColor(0,0),document.body.appendChild(r.domElement),m=new $;const e=new K(16777215,1);e.position.set(1,1,1),m.add(e),m.add(new Q(16777215,.2)),a=new X(75,window.innerWidth/window.innerHeight,.1,50),a.position.set(1,1,2),a.far=100,a.updateProjectionMatrix(),c=new J(new Z),m.add(c),new de(a,r.domElement),z=new ue,document.body.appendChild(z.dom),g=new F(new be),A=new F(new we),u=new F(new Te),U=new ve,new ce().setMeshoptDecoder(he).loadAsync("https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/stanford-bunny/bunny.glb").then(o=>{o.scene.updateMatrixWorld(!0);const i=new ye(o.scene);return i.attributes=["position","normal"],i.useGroups=!1,v=i.generate().center(),U.generate(v,{maxLeafTris:1})}).then(o=>{I=o,P=new ee(v,new te),m.add(P),N()}),C(),window.addEventListener("resize",function(){a.aspect=window.innerWidth/window.innerHeight,a.updateProjectionMatrix(),r.setSize(window.innerWidth,window.innerHeight)},!1)}function C(){h&&h.destroy(),t.layer=Math.min(t.resolution,t.layer),h=new le;const e=h.addFolder("generation");e.add(t,"gpuGeneration"),e.add(t,"resolution",10,200,1),e.add(t,"margin",0,1),e.add(t,"regenerate");const o=h.addFolder("display");o.add(t,"mode",["geometry","raymarching","layer","grid layers"]).onChange(()=>{C()}),t.mode==="layer"&&o.add(t,"layer",0,t.resolution,1),t.mode==="raymarching"&&o.add(t,"surface",-.2,.5)}function N(){const e=t.resolution,o=new b,i=new y,_=new se,p=new y;v.boundingBox.getCenter(i),p.subVectors(v.boundingBox.max,v.boundingBox.min),p.x+=2*t.margin,p.y+=2*t.margin,p.z+=2*t.margin,o.compose(i,_,p),G.copy(o).invert(),c.box.copy(v.boundingBox),c.box.min.x-=t.margin,c.box.min.y-=t.margin,c.box.min.z-=t.margin,c.box.max.x+=t.margin,c.box.max.y+=t.margin,c.box.max.z+=t.margin,n&&n.dispose();const x=1/e,w=.5*x,E=window.performance.now();if(t.gpuGeneration){const f=r.extensions.get("OES_texture_float_linear");n=new oe(e,e,e),n.texture.format=B,n.texture.type=f?M:L,n.texture.minFilter=S,n.texture.magFilter=S,r.initRenderTarget(n),g.material.uniforms.bvh.value.updateFrom(I),g.material.uniforms.matrix.value.copy(o);const l=new y,d=new ne(e,e);d.texture.format=B,d.texture.type=f?M:L;for(let s=0;s0;n.image.data[O]=j?-q:q}}const W=window.performance.now()-E;V.innerText=`${W.toFixed(2)}ms`,C()}function k(){if(z.update(),requestAnimationFrame(k),n){if(t.mode==="geometry")r.render(m,a);else if(t.mode==="layer"||t.mode==="grid layers"){let e;const o=A.material;n.isData3DTexture?(o.uniforms.layer.value=t.layer/n.image.width,o.uniforms.sdfTex.value=n,e=n):(o.uniforms.layer.value=t.layer/n.width,o.uniforms.sdfTex.value=n.texture,e=n.texture),o.uniforms.layers.value=e.image.width;const i=t.mode==="layer"?0:1;i!==o.defines.DISPLAY_GRID&&(o.defines.DISPLAY_GRID=i,o.needsUpdate=!0),A.render(r)}else if(t.mode==="raymarching"){a.updateMatrixWorld(),P.updateMatrixWorld();let e;n.isData3DTexture?e=n:e=n.texture;const{width:o,depth:i,height:_}=e.image;u.material.uniforms.sdfTex.value=e,u.material.uniforms.normalStep.value.set(1/o,1/_,1/i),u.material.uniforms.surface.value=t.surface,u.material.uniforms.projectionInverse.value.copy(a.projectionMatrixInverse),u.material.uniforms.sdfTransformInverse.value.copy(P.matrixWorld).invert().premultiply(G).multiply(a.matrixWorld),u.render(r)}}else return} diff --git a/example/bundle/assets/selection-DRTOrerZ.js b/example/bundle/assets/selection-DRTOrerZ.js new file mode 100644 index 000000000..cb880510b --- /dev/null +++ b/example/bundle/assets/selection-DRTOrerZ.js @@ -0,0 +1 @@ +import{C as Me,W as be,c as ve,D as Se,A as Te,P as Ce,al as Ee,G as Ie,M as F,T as Ae,g as He,aE as We,f as ee,aF as Le,s as Re,aG as Be,aH as te,aI as ne,J as Q,ag as oe,Q as Oe,n as fe,V as U,Y as Pe,o as ue,t as Ne}from"./ExtendedTriangle-CNpFv597.js";import{S as De}from"./stats.min-GTpOrGrX.js";import{g as Ue}from"./lil-gui.module.min-Bc0DeA9g.js";import{O as ze}from"./OrbitControls-I50Ha_kb.js";import{M as Fe,I as X,N as se,a as Xe}from"./MeshBVH-ujCvfObx.js";import{M as Ve}from"./MeshBVHHelper-DbtlD37d.js";import"./_commonjsHelpers-Cpj98o6Y.js";const d={toolMode:"lasso",selectionMode:"intersection",liveUpdate:!1,selectModel:!1,wireframe:!1,useBoundsTree:!0,displayHelper:!1,helperDepth:10,rotate:!0};let A,C,L,V,$,R,T,b,D,H,O,pe,B;const n=[];let Z=!1,K=!1,N=!1;Ye();ye();function Ye(){pe=document.getElementById("output");const s=new Me(2503224);A=new be({antialias:!0}),A.setPixelRatio(window.devicePixelRatio),A.setSize(window.innerWidth,window.innerHeight),A.setClearColor(s,1),A.shadowMap.enabled=!0,document.body.appendChild(A.domElement),L=new ve;const l=new Se(16777215,3);l.castShadow=!0,l.shadow.mapSize.set(2048,2048),l.position.set(10,10,10),L.add(l),L.add(new Te(11583173,2.5)),C=new Ce(75,window.innerWidth/window.innerHeight,.1,50),C.position.set(2,4,6),C.far=100,C.updateProjectionMatrix(),L.add(C),T=new Ee,T.material.color.set(16750592),T.renderOrder=1,T.position.z=-.2,T.depthTest=!1,T.scale.setScalar(1),C.add(T),B=new Ie,L.add(B),b=new F(new Ae(1.5,.5,500,60).toNonIndexed(),new He({polygonOffset:!0,polygonOffsetFactor:1})),b.geometry.boundsTree=new Fe(b.geometry),b.geometry.setAttribute("color",new We(new Array(b.geometry.index.count*3).fill(255),3,!0)),b.castShadow=!0,b.receiveShadow=!0,B.add(b),D=new Ve(b,10),B.add(D),H=new F,H.geometry=b.geometry.clone(),H.geometry.drawRange.count=0,H.material=new ee({opacity:.05,transparent:!0,depthWrite:!1}),H.material.color.set(16750592),H.renderOrder=1,B.add(H),O=new F,O.geometry=H.geometry,O.material=new ee({opacity:.25,transparent:!0,wireframe:!0,depthWrite:!1}),O.material.color.copy(H.material.color),O.renderOrder=2,B.add(O);const g=new Le(10,10,16777215,16777215);g.material.opacity=.2,g.material.transparent=!0,g.position.y=-2.75,L.add(g);const h=new F(new Re,new Be({color:0,opacity:.2,depthWrite:!1}));h.position.y=-2.74,h.rotation.x=-Math.PI/2,h.scale.setScalar(20),h.renderOrder=2,h.receiveShadow=!0,L.add(h),$=new De,document.body.appendChild($.dom),R=new ze(C,A.domElement),R.minDistance=3,R.touches.ONE=te.PAN,R.mouseButtons.LEFT=ne.PAN,R.touches.TWO=te.ROTATE,R.mouseButtons.RIGHT=ne.ROTATE,R.enablePan=!1,V=new Ue;const u=V.addFolder("selection");u.add(d,"toolMode",["lasso","box"]),u.add(d,"selectionMode",["centroid","centroid-visible","intersection"]),u.add(d,"selectModel"),u.add(d,"liveUpdate"),u.add(d,"useBoundsTree"),u.open();const e=V.addFolder("display");e.add(d,"wireframe"),e.add(d,"rotate"),e.add(d,"displayHelper"),e.add(d,"helperDepth",1,30,1).onChange(f=>{D.depth=f,D.update()}),e.open(),V.open();let r=-1/0,o=-1/0,i=-1/0,c=-1/0;const t=new Q,a=new Q,p=new Q;A.domElement.addEventListener("pointerdown",f=>{i=f.clientX,c=f.clientY,r=f.clientX/window.innerWidth*2-1,o=-(f.clientY/window.innerHeight*2-1),n.length=0,Z=!0}),A.domElement.addEventListener("pointerup",()=>{T.visible=!1,Z=!1,n.length&&(N=!0)}),A.domElement.addEventListener("pointermove",f=>{if(!(1&f.buttons))return;const v=f.clientX,M=f.clientY,y=f.clientX/window.innerWidth*2-1,x=-(f.clientY/window.innerHeight*2-1);if(d.toolMode==="box")n.length=3*5,n[0]=r,n[1]=o,n[2]=0,n[3]=y,n[4]=o,n[5]=0,n[6]=y,n[7]=x,n[8]=0,n[9]=r,n[10]=x,n[11]=0,n[12]=r,n[13]=o,n[14]=0,(v!==i||M!==c)&&(K=!0),i=v,c=M,T.visible=!0,d.liveUpdate&&(N=!0);else if(Math.abs(v-i)>=3||Math.abs(M-c)>=3){const E=(n.length/3-1)*3;let w=!1;n.length>3&&(t.set(n[E-3],n[E-3+1]),a.set(n[E],n[E+1]),a.sub(t).normalize(),t.set(n[E],n[E+1]),p.set(y,x),p.sub(t).normalize(),w=a.dot(p)>.99),w?(n[E]=y,n[E+1]=x):n.push(y,x,0),K=!0,T.visible=!0,i=v,c=M,d.liveUpdate&&(N=!0)}}),window.addEventListener("resize",function(){C.aspect=window.innerWidth/window.innerHeight,C.updateProjectionMatrix(),A.setSize(window.innerWidth,window.innerHeight)},!1)}function ye(){if($.update(),requestAnimationFrame(ye),b.material.wireframe=d.wireframe,D.visible=d.displayHelper,K){if(d.toolMode==="lasso"){const l=n.length;n.push(n[0],n[1],n[2]),T.geometry.setAttribute("position",new oe(n,3,!1)),n.length=l}else T.geometry.setAttribute("position",new oe(n,3,!1));T.frustumCulled=!1,K=!1}N&&(N=!1,n.length>0&&Ge());const s=Math.tan(Oe.DEG2RAD*C.fov/2)*T.position.z;T.scale.set(-s*C.aspect,-s,1),A.render(L,C),d.rotate&&(B.rotation.y+=.01,d.liveUpdate&&Z&&(N=!0))}const re=new fe,ie=new U,_=new Pe,Y=new U,ae=new U,le=new U,G=new fe,ce=new Array(8).fill().map(()=>new U),j=new Array(12).fill().map(()=>new ue),P=[],k=[];function Ge(){for(G.copy(b.matrixWorld).premultiply(C.matrixWorldInverse).premultiply(C.projectionMatrix);P.length{if(!d.useBoundsTree)return X;const{min:c,max:t}=e;let a=0,p=1/0,f=-1/0,v=1/0;for(let w=0;w<=1;w++)for(let I=0;I<=1;I++)for(let S=0;S<=1;S++){const m=ce[a];m.x=w===0?c.x:t.x,m.y=I===0?c.y:t.y,m.z=S===0?c.z:t.z,m.w=1,m.applyMatrix4(G),a++,m.yf&&(f=m.y),m.xf,we=q>f;if(he&&we)continue;const ge=z{const S=x[(I+1)%x.length],m=j[I];return m.start.copy(w),m.end.copy(S),m});if(J(y[0].start,W)%2===1)return X;let E=0;for(let w=0,I=x.length;w{const c=r*3,t=c+0,a=c+1,p=c+2,f=d.useBoundsTree?k[i]:P;if(d.selectionMode==="centroid"||d.selectionMode==="centroid-visible"){if(Y.copy(e.a).add(e.b).add(e.c).multiplyScalar(1/3),ae.copy(Y).applyMatrix4(G),o||J(ae,f)%2===1)return d.selectionMode==="centroid-visible"&&(e.getNormal(le),_.origin.copy(Y).addScaledVector(le,1e-6),_.direction.subVectors(ie,Y),b.geometry.boundsTree.raycastFirst(_,Ne))?!1:(l.push(t,a,p),d.selectModel)}else if(d.selectionMode==="intersection"){if(o)return l.push(t,a,p),d.selectModel;const v=[e.a,e.b,e.c];for(let y=0;y<3;y++){const x=v[y];if(x.applyMatrix4(G),J(x,f)%2===1)return l.push(t,a,p),d.selectModel}const M=[j[0],j[1],j[2]];M[0].start.copy(e.a),M[0].end.copy(e.b),M[1].start.copy(e.b),M[1].end.copy(e.c),M[2].start.copy(e.c),M[2].end.copy(e.a);for(let y=0;y<3;y++){const x=M[y];for(let W=0,E=f.length;W0?1:2}function g(t,a){return(t.x-a.x)*(t.x-a.x)+(t.y-a.y)*(t.y-a.y)}function h(t,a){const p=l(r,t,a);return p==0?g(r,a)>=g(r,t)?-1:1:p==2?-1:1}let u=1/0,e=-1;for(let t=0,a=s.length;ti&&o>c||ot&&r>a)return!1;if(rh.end.y;for(let e=0,r=l.length;eo.end.y;ke(s,o,u,i)&&g++,u=i}return g}function de(s,l){function g(o,i,c){return(c.y-o.y)*(i.x-o.x)>(i.y-o.y)*(c.x-o.x)}const h=s.start,u=s.end,e=l.start,r=l.end;return g(h,e,r)!==g(u,e,r)&&g(h,u,e)!==g(h,u,r)} diff --git a/example/bundle/assets/shapecast-vR8b137q.js b/example/bundle/assets/shapecast-vR8b137q.js new file mode 100644 index 000000000..fafe9055c --- /dev/null +++ b/example/bundle/assets/shapecast-vR8b137q.js @@ -0,0 +1 @@ +import{M as w,i as T,V as M,a7 as D,W,c as F,d as G,D as H,A as I,T as B,m as R,t as k,P as A,g as V,e as j,X as O,n as K,K as q,b as U}from"./ExtendedTriangle-CNpFv597.js";import{S as X}from"./stats.min-GTpOrGrX.js";import{g as J}from"./lil-gui.module.min-Bc0DeA9g.js";import{O as N}from"./OrbitControls-I50Ha_kb.js";import{T as Q}from"./TransformControls-xd0I7183.js";import{M as Y}from"./MeshBVHHelper-DbtlD37d.js";import{a as Z,c as _,d as $}from"./ExtensionUtilities-DGy5CKFv.js";import"./_commonjsHelpers-Cpj98o6Y.js";import"./MeshBVH-ujCvfObx.js";w.prototype.raycast=Z;T.prototype.computeBoundsTree=_;T.prototype.disposeBoundsTree=$;const e={speed:1,visualizeBounds:!1,visualBoundsDepth:10,shape:"sphere",position:new M,rotation:new D,scale:new M(1,1,1)};let x,s,p,m,f,r,a,d,n={};function ee(){m=new W({antialias:!0}),m.setPixelRatio(window.devicePixelRatio),m.setSize(window.innerWidth,window.innerHeight),m.setClearColor(1251612,1),document.body.appendChild(m.domElement),s=new F,s.fog=new G(2503224/2,20,60);const l=new H(16777215,1.5);l.position.set(1,1,1),s.add(l),s.add(new I(16777215,1.2));const t=1,u=.4,o=400,c=100,P=new B(t,u,o,c),z=new R({color:16777215,side:k});d=new w(P,z),d.geometry.computeBoundsTree(),s.add(d),p=new A(75,window.innerWidth/window.innerHeight,.1,50),p.position.set(3,3,3),p.far=100,p.updateProjectionMatrix(),a=new Q(p,m.domElement),s.add(a),f=new N(p,m.domElement),x=new X,document.body.appendChild(x.dom);const g=new V({metalness:.1,transparent:!0,opacity:.75,premultipliedAlpha:!0});n.sphere=new w(new j(1,50,50),g),s.add(n.sphere),n.box=new w(new O(1,1,1),g),s.add(n.box),n.geometry=new w(new B(.5,.2,200,50),g),n.geometry.geometry.computeBoundsTree(),s.add(n.geometry);const i=new J;i.add(e,"speed").min(0).max(10),i.add(e,"visualizeBounds").onChange(()=>v()),i.add(e,"visualBoundsDepth").min(1).max(40).step(1).onChange(()=>v()),i.add(e,"shape",["sphere","box","geometry"]),i.add(a,"mode",["translate","rotate"]);const h=i.addFolder("position");h.add(e.position,"x").min(-5).max(5).step(.001),h.add(e.position,"y").min(-5).max(5).step(.001),h.add(e.position,"z").min(-5).max(5).step(.001),h.open();const y=i.addFolder("rotation");y.add(e.rotation,"x").min(-Math.PI).max(Math.PI).step(.001),y.add(e.rotation,"y").min(-Math.PI).max(Math.PI).step(.001),y.add(e.rotation,"z").min(-Math.PI).max(Math.PI).step(.001),y.open(),i.open(),a.addEventListener("change",function(){e.position.copy(n[e.shape].position),e.rotation.copy(n[e.shape].rotation),e.scale.copy(n[e.shape].scale),i.controllersRecursive().forEach(b=>b.updateDisplay())}),a.addEventListener("mouseDown",function(){f.enabled=!1}),a.addEventListener("mouseUp",function(){f.enabled=!0}),f.addEventListener("start",function(){a.enabled=!1}),f.addEventListener("end",function(){a.enabled=!0}),window.addEventListener("resize",function(){p.aspect=window.innerWidth/window.innerHeight,p.updateProjectionMatrix(),m.setSize(window.innerWidth,window.innerHeight)},!1),window.addEventListener("keydown",function(b){switch(b.key){case"w":a.mode="translate";break;case"e":a.mode="rotate";break}i.controllersRecursive().forEach(L=>L.updateDisplay())})}function v(){r&&!e.visualizeBounds&&(s.remove(r),r=null),!r&&e.visualizeBounds&&(r=new Y(d),s.add(r)),r&&(r.depth=e.visualBoundsDepth)}let S=window.performance.now();function C(){const E=window.performance.now()-S;S=window.performance.now(),d.rotation.y+=e.speed*E*.001,d.updateMatrixWorld(),x.begin(),r&&r.update(),m.render(s,p),x.end();for(const o in n)n[o].visible=!1;const l=e.shape,t=n[l];t.visible=!0,t.position.copy(e.position),t.rotation.copy(e.rotation),t.scale.copy(e.scale);const u=new K().copy(d.matrixWorld).invert().multiply(t.matrixWorld);if(l==="sphere"){const o=new q(void 0,1);o.applyMatrix4(u);const c=d.geometry.boundsTree.intersectsSphere(o);t.material.color.set(c?15277667:6710886),t.material.emissive.set(15277667).multiplyScalar(c?.25:0)}else if(l==="box"){const o=new U;o.min.set(-.5,-.5,-.5),o.max.set(.5,.5,.5);const c=d.geometry.boundsTree.intersectsBox(o,u);t.material.color.set(c?15277667:6710886),t.material.emissive.set(15277667).multiplyScalar(c?.25:0)}else if(l==="geometry"){const o=d.geometry.boundsTree.intersectsGeometry(t.geometry,u);t.material.color.set(o?15277667:6710886),t.material.emissive.set(15277667).multiplyScalar(o?.25:0)}a.object!==t&&a.attach(t),requestAnimationFrame(C)}ee();v();C(); diff --git a/example/bundle/assets/skinnedMesh-BENrCUFW.js b/example/bundle/assets/skinnedMesh-BENrCUFW.js new file mode 100644 index 000000000..2a8bcb6c3 --- /dev/null +++ b/example/bundle/assets/skinnedMesh-BENrCUFW.js @@ -0,0 +1,3 @@ +import{i as A,W as E,p as R,c as z,D,A as U,P as I,aL as $,aM as j,b as N,aN as V,f as q,M as B,s as J,aG as K,h as Q}from"./ExtendedTriangle-CNpFv597.js";import{G as X}from"./GLTFLoader-CPZ_tJoX.js";import{S as Y}from"./stats.min-GTpOrGrX.js";import{g as Z}from"./lil-gui.module.min-Bc0DeA9g.js";import{O as _}from"./OrbitControls-I50Ha_kb.js";import{M as ee}from"./MeshBVHHelper-DbtlD37d.js";import{g as te}from"./Debug-CxembHqK.js";import{c as ae}from"./ExtensionUtilities-DGy5CKFv.js";import{S as re}from"./StaticGeometryGenerator-BuhbcQd1.js";import"./BufferGeometryUtils-BjOdgyuH.js";import"./_commonjsHelpers-Cpj98o6Y.js";import"./MeshBVH-ujCvfObx.js";A.prototype.computeBoundsTree=ae;const e={display:!0,displayOriginal:!0,material:"wireframe",updatePositionOnly:!1,skeletonHelper:!1,bvhHelper:!0,bvhHelperDepth:10,autoUpdate:!0,updateRate:2.5,pause:!1,regenerate:()=>{T()}};let r,o,s,W,b,P,L,H,v,M,d,f,y,t,S,x=0,C=null,F,G,k;oe();O();function oe(){L=document.getElementById("output"),r=new E({antialias:!0}),r.setPixelRatio(window.devicePixelRatio),r.setSize(window.innerWidth,window.innerHeight),r.setClearColor(1118481,1),r.shadowMap.enabled=!0,r.shadowMap.type=R,r.outputEncoding=void 0,document.body.appendChild(r.domElement),s=new z;const i=new D(16777215,3);i.position.set(5,5,2.5),i.shadow.mapSize.setScalar(1024),i.shadow.normalBias=.01,i.castShadow=!0;const n=i.shadow.camera;n.left=n.bottom=-7.5,n.right=n.top=7.5,n.updateProjectionMatrix(),s.add(i),s.add(new U(11583173,2.4)),o=new I(75,window.innerWidth/window.innerHeight,.1,50),o.position.set(10,0,0),o.far=100,o.updateProjectionMatrix(),H=new _(o,r.domElement),W=new Q,P=new Y,document.body.appendChild(P.dom),new X().load("https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/trex/scene.gltf",a=>{d=a.scene,d.traverse(w=>{w.isMesh&&(w.castShadow=!0,w.receiveShadow=!0,w.frustumCulled=!1)}),d.updateMatrixWorld(!0),s.add(d),y=new $(d),y.visible=!1,s.add(y);const h=a.animations;v=new j(d),M=v.clipAction(h[0]),M.play(),M.paused=e.pause;const g=new N;g.setFromObject(d),g.getCenter(H.target),g.getCenter(o.position),o.position.x=7.5,o.position.z=3.5,H.update(),S=new re(d),k=S.getMaterials(),G=k.map(w=>new V({normalMap:w.normalMap})),F=new q({wireframe:!0,transparent:!0,opacity:.05,depthWrite:!1}),t=new B(new A,F),t.receiveShadow=!0,s.add(t),f=new ee(t,10),s.add(f),T()});const l=new B(new J,new K({color:16777215,opacity:.025,transparent:!0}));l.rotation.x=-Math.PI/2,l.receiveShadow=!0,l.scale.setScalar(50),s.add(l),b=new Z;const p=b.addFolder("static mesh");p.add(e,"display"),p.add(e,"displayOriginal"),p.add(e,"material",["wireframe","normal","original"]).onChange(a=>{if(t)switch(a){case"wireframe":t.material=F,t.castShadow=!1;break;case"normal":t.material=G,t.castShadow=!0;break;case"original":t.material=k,t.castShadow=!0;break}}),p.add(e,"updatePositionOnly").onChange(a=>{S.attributes=a?["position"]:["position","normal","tangent","uv","uv2"];const h=t.geometry;h.dispose();for(const g in h.attributes)h.deleteAttribute(g)}),p.open();const m=b.addFolder("helpers");m.add(e,"skeletonHelper"),m.add(e,"bvhHelper"),m.add(e,"bvhHelperDepth",1,20,1).onChange(a=>{f.depth=parseInt(a),f.update()}),m.open();const c=b.addFolder("bvh animation");c.add(e,"autoUpdate"),c.add(e,"updateRate",0,5,.001),c.add(e,"pause").onChange(a=>{M&&(M.paused=a)}),c.add(e,"regenerate"),c.open(),b.open(),window.addEventListener("resize",function(){o.aspect=window.innerWidth/window.innerHeight,o.updateProjectionMatrix(),r.setSize(window.innerWidth,window.innerHeight)},!1)}function T(){if(t){let u,i,n;n=window.performance.now(),S.generate(t.geometry),u=window.performance.now()-n,n=window.performance.now(),t.geometry.boundsTree?(t.geometry.boundsTree.refit(),i=(window.performance.now()-n).toFixed(2)):(t.geometry.computeBoundsTree(),i="-"),f.update(),x=0;const l=te(t.geometry.boundsTree);C===null&&(C=l);let p=0,m=0;for(const a in l)p+=l[a].surfaceAreaScore,m+=C[a].surfaceAreaScore;const c=p/m-1;L.innerHTML=`mesh generation time: ${u.toFixed(2)} ms +refit time: ${i} ms +bvh degradation: ${(100*c).toFixed(2)}%`}}function O(){P.update(),requestAnimationFrame(O);const u=Math.min(W.getDelta(),30*.001);v&&(v.update(u),y.visible=e.skeletonHelper,t.visible=e.display,f.visible=e.bvhHelper,d.visible=e.displayOriginal),s.updateMatrixWorld(!0),e.autoUpdate&&!e.pause?(x>e.updateRate&&T(),x+=u):x=0,r.render(s,o)} diff --git a/example/bundle/assets/stats.min-GTpOrGrX.js b/example/bundle/assets/stats.min-GTpOrGrX.js new file mode 100644 index 000000000..a421bec34 --- /dev/null +++ b/example/bundle/assets/stats.min-GTpOrGrX.js @@ -0,0 +1 @@ +import{c as E,g as b}from"./_commonjsHelpers-Cpj98o6Y.js";var y={exports:{}};(function(S,R){(function(p,i){S.exports=i()})(E,function(){var p=function(){function i(n){return a.appendChild(n.dom),n}function f(n){for(var l=0;lo+1e3&&(x.update(1e3*e/(n-o),100),o=n,e=0,h)){var l=performance.memory;h.update(l.usedJSHeapSize/1048576,l.jsHeapSizeLimit/1048576)}return n},update:function(){r=this.end()},domElement:a,setMode:f}};return p.Panel=function(i,f,c){var a=1/0,r=0,o=Math.round,e=o(window.devicePixelRatio||1),x=80*e,v=48*e,h=3*e,n=2*e,l=3*e,s=15*e,d=74*e,m=30*e,u=document.createElement("canvas");u.width=x,u.height=v,u.style.cssText="width:80px;height:48px";var t=u.getContext("2d");return t.font="bold "+9*e+"px Helvetica,Arial,sans-serif",t.textBaseline="top",t.fillStyle=c,t.fillRect(0,0,x,v),t.fillStyle=f,t.fillText(i,h,n),t.fillRect(l,s,d,m),t.fillStyle=c,t.globalAlpha=.9,t.fillRect(l,s,d,m),{dom:u,update:function(g,w){a=Math.min(a,g),r=Math.max(r,g),t.fillStyle=c,t.globalAlpha=1,t.fillRect(0,0,x,s),t.fillStyle=f,t.fillText(o(g)+" "+i+" ("+o(a)+"-"+o(r)+")",h,n),t.drawImage(u,l+e,s,d-e,m,l,s,d-e,m),t.fillRect(l+d-e,s,e,m),t.fillStyle=c,t.globalAlpha=.9,t.fillRect(l+d-e,s,e,o((1-g/w)*m))}}},p})})(y);var P=y.exports;const D=b(P);export{D as S}; diff --git a/example/bundle/assets/triangleIntersect-xgifnFZZ.js b/example/bundle/assets/triangleIntersect-xgifnFZZ.js new file mode 100644 index 000000000..cb7a886fd --- /dev/null +++ b/example/bundle/assets/triangleIntersect-xgifnFZZ.js @@ -0,0 +1 @@ +import{aR as P,o as X,W as L,c as T,D as U,A as V,m as v,t as I,e as W,M as g,l as A,i as Y,B as Z,P as D,V as H,n as G,Q as k}from"./ExtendedTriangle-CNpFv597.js";import{S as B}from"./stats.min-GTpOrGrX.js";import{g as F}from"./lil-gui.module.min-Bc0DeA9g.js";import{O as N}from"./OrbitControls-I50Ha_kb.js";import"./_commonjsHelpers-Cpj98o6Y.js";const E={sphereSize:1},e=new P,t=new P;e.a.set(-1,0,0);e.b.set(2,0,-2);e.c.set(2,0,2);t.a.set(1,0,0);t.b.set(-2,-2,0);t.c.set(-2,2,0);e.needsUpdate=!0;t.needsUpdate=!0;let M,r,d,f,x,c=[],a=[],y,m=new X,S,z,h;function j(){f=new L({antialias:!0}),f.setPixelRatio(window.devicePixelRatio),f.setSize(window.innerWidth,window.innerHeight),f.setClearColor(1251612,1),document.body.appendChild(f.domElement),r=new T;const n=new U(16777215,.3);n.position.set(10,10,10),r.add(n),r.add(new V(16777215,.8));const w=new v({color:16711680,side:I}),b=new v({color:255,side:I}),i=new v({color:65280,side:I}),s=new W(1);for(let l=0;l<2;l++){const p=new g(s,w);a.push(p),r.add(p)}for(let l=0;l<3;l++){const p=new g(s,b);c.push(p),r.add(p)}for(let l=0;l<3;l++){const p=new g(s,i);c.push(p),r.add(p)}const R=new A;y=new g(R,w),r.add(y);const C=new Y;C.setAttribute("position",new Z(new Float32Array([1,1,1,2,2,2,3,3,3]),3)),S=new g(C.clone(),b),r.add(S),z=new g(C.clone(),i),r.add(z),d=new D(75,window.innerWidth/window.innerHeight,.1,50),d.position.set(10,10,10),d.far=100,d.updateProjectionMatrix(),x=new N(d,f.domElement),x.target.add(e.a).add(e.b).add(e.c).add(t.a).add(t.b).add(t.c).multiplyScalar(1/6),d.position.add(x.target),x.update(),M=new B,document.body.appendChild(M.dom),x.addEventListener("change",function(){u()}),window.addEventListener("resize",function(){d.aspect=window.innerWidth/window.innerHeight,d.updateProjectionMatrix(),f.setSize(window.innerWidth,window.innerHeight),u()},!1)}function O(){h=new F,h.add(E,"sphereSize",0,5,.001).onChange(u);const o=["a1","b1","c1","a2","b2","c2"],n=[e.a,e.b,e.c,t.a,t.b,t.c];for(let i=0;i<6;i++){const s=h.addFolder(o[i]);s.add(n[i],"x").min(-10).max(10).step(.001).onChange(u),s.add(n[i],"y").min(-10).max(10).step(.001).onChange(u),s.add(n[i],"z").min(-10).max(10).step(.001).onChange(u),s.open()}const w=["Inter1","Inter2"],b=[m.start,m.end];for(let i=0;i<2;i++){const s=h.addFolder(w[i]);s.add(b[i],"x").step(.001),s.add(b[i],"y").step(.001),s.add(b[i],"z").step(.001),s.open()}h.open()}function Q(o,n){o.geometry.dispose();const w=new H().subVectors(n.start,n.end);o.geometry=new A(1,1,w.length(),6,4,!0),o.geometry.applyMatrix4(new G().makeTranslation(0,w.length()/2,0)),o.geometry.applyMatrix4(new G().makeRotationX(k.degToRad(90))),o.geometry.computeVertexNormals(),o.position.copy(n.start),o.lookAt(n.end)}function q(){c[0].position.copy(e.a),c[1].position.copy(e.b),c[2].position.copy(e.c),c[3].position.copy(t.a),c[4].position.copy(t.b),c[5].position.copy(t.c),a[0].position.copy(m.start),a[1].position.copy(m.end)}function J(){const o=S.geometry.getAttribute("position");o.setXYZ(0,e.a.x,e.a.y,e.a.z),o.setXYZ(1,e.b.x,e.b.y,e.b.z),o.setXYZ(2,e.c.x,e.c.y,e.c.z),o.needsUpdate=!0,S.geometry.computeVertexNormals();const n=z.geometry.getAttribute("position");n.setXYZ(0,t.a.x,t.a.y,t.a.z),n.setXYZ(1,t.b.x,t.b.y,t.b.z),n.setXYZ(2,t.c.x,t.c.y,t.c.z),n.needsUpdate=!0,z.geometry.computeVertexNormals()}function u(){M.begin(),y.visible=!1,a[0].visible=!1,a[1].visible=!1,e.update(),t.update(),e.intersectsTriangle(t,m)?(Q(y,m),y.visible=!0,a[0].visible=!0,a[1].visible=!0):(m.start.set(1/0,1/0,1/0),m.end.set(1/0,1/0,1/0)),q(),J(),[...c,...a].forEach(n=>{n.scale.setScalar(.005*E.sphereSize*n.position.distanceTo(d.position))}),a.forEach(n=>n.scale.multiplyScalar(1.5)),y.scale.setScalar(.5*Math.min(a[0].scale.x,a[1].scale.x)),y.scale.z=1,h.controllersRecursive().forEach(n=>n.updateDisplay()),f.render(r,d),M.end()}j();O();u(); diff --git a/example/bundle/assets/voxelize-esb_wY32.js b/example/bundle/assets/voxelize-esb_wY32.js new file mode 100644 index 000000000..4eb850462 --- /dev/null +++ b/example/bundle/assets/voxelize-esb_wY32.js @@ -0,0 +1 @@ +import{W as U,c as V,D as L,A as I,P as K,f as q,M as P,T as Q,X,aS as Y,C as j,aT as J,g as N,V as k,n as R,b as Z,Y as _,ar as $}from"./ExtendedTriangle-CNpFv597.js";import{G as O}from"./GLTFLoader-CPZ_tJoX.js";import{M as z}from"./meshopt_decoder.module-Cf1-17OU.js";import{S as ee}from"./stats.min-GTpOrGrX.js";import{g as te}from"./lil-gui.module.min-Bc0DeA9g.js";import{O as oe}from"./OrbitControls-I50Ha_kb.js";import{R as ne}from"./RoundedBoxGeometry-V9OB1gSg.js";import{G as D}from"./GenerateMeshBVHWorker-CkitdNK9.js";import{M as re}from"./MeshBVH-ujCvfObx.js";import"./BufferGeometryUtils-BjOdgyuH.js";import"./_commonjsHelpers-Cpj98o6Y.js";let m,w,r,C,H,t,u,a=!1,v=null;const o={model:"Torus Knot",scale:.75,resolution:30,solid:!0,displayMesh:!0,displayBounds:!1,insideOnly:!1,rebuild:()=>a=!0},s={};ae();E();function ae(){document.getElementById("output"),m=new U({antialias:!0}),m.setPixelRatio(window.devicePixelRatio),m.setSize(window.innerWidth,window.innerHeight),m.setClearColor(1449501,1),m.outputEncoding=void 0,document.body.appendChild(m.domElement),r=new V;const d=new L(16777215,3);d.position.set(3,6,9),r.add(d);const l=new L(16777215,.3);l.position.set(-3,-6,-9),r.add(l);const c=new I(16777215,.75);r.add(c),w=new K(75,window.innerWidth/window.innerHeight,.1,50),w.position.set(1,.5,1),w.far=100,w.updateProjectionMatrix(),new oe(w,m.domElement),H=new ee,document.body.appendChild(H.dom);const h=new q({transparent:!0,wireframe:!0,depthWrite:!1,opacity:.02});new O().setMeshoptDecoder(z).load("https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/happy-buddha/buddha.glb",n=>{const e=n.scene.children[0];e.geometry.center(),e.material=h,e.scale.setScalar(1.5),e.rotation.y=-Math.PI/2,new D().generate(e.geometry).then(y=>{r.add(e),s.Buddha={model:e,bvh:y},o.model==="Buddha"&&(a=!0)})}),new O().setMeshoptDecoder(z).load("https://raw.githubusercontent.com/gkjohnson/3d-demo-data/main/models/stanford-bunny/bunny.glb",n=>{const e=n.scene.children[0];e.geometry.center(),e.material=h,e.rotation.y=Math.PI/2,e.scale.setScalar(.65),new D().generate(e.geometry).then(y=>{r.add(e),s.Bunny={model:e,bvh:y},o.model==="Bunny"&&(a=!0)})});{const n=new P(new Q(.3,.1,400,60),h),e=new re(n.geometry);r.add(n),s["Torus Knot"]={bvh:e,model:n},a=!0}s.Buddha={model:null,bvh:null},s.Bunny={model:null,bvh:null};const B=new P(new X);u=new Y(B,16777215),u.material.opacity=.35,u.material.transparent=!0,r.add(u),C=new te,C.add(o,"model",Object.keys(s)).onChange(()=>{a=!0});const f=C.addFolder("voxelize");f.add(o,"resolution",5,75,1).onChange(()=>{a=!0}),f.add(o,"scale",.1,4).onChange(()=>{a=!0}),f.add(o,"solid").onChange(()=>{a=!0}),f.add(o,"insideOnly").onChange(()=>{a=!0}),f.add(o,"rebuild");const g=C.addFolder("helpers");g.add(o,"displayMesh"),g.add(o,"displayBounds"),window.addEventListener("resize",function(){w.aspect=window.innerWidth/window.innerHeight,w.updateProjectionMatrix(),m.setSize(window.innerWidth,window.innerHeight)},!1)}function*se(){const i=o.resolution,d=i**3,l=o.scale,c=l/i,h=new j(16777215),B=new j(16761095).convertSRGBToLinear();t&&t.instanceMatrix.count!==d&&(t.material.dispose(),t.dispose(),t.parent.remove(t),t=null);const{model:f,bvh:g}=s[o.model];if(!f)return;t||(t=new J(new ne(1,1,1,4,.1),new N,d),t.setColorAt(0,h),r.add(t));const n=-l/2+c*.5,e=new k,x=new $,y=new k().setScalar(c),b=new R,S=new Z,T=new R().copy(f.matrixWorld).invert(),M=new _;M.direction.set(0,0,1);let p=0;for(let W=0;W0&&(b.compose(e,x,y),t.setMatrixAt(p,b),t.setColorAt(p,B),t.instanceMatrix.needsUpdate=!0,t.instanceColor.needsUpdate=!0,p++)}t.count=p,yield}t.count=p}function E(){if(H.update(),requestAnimationFrame(E),r.updateMatrixWorld(!0),a&&(v=se(),a=!1),v){let d=window.performance.now();for(;window.performance.now()-d<16;)if(v.next().done){v=null;break}}u&&(u.object.scale.setScalar(o.scale),u.object.updateMatrixWorld(!0),u.update());for(const d in s){const l=s[d];l.model&&(l.model.visible=!1)}const{model:i}=s[o.model];i&&(i.visible=o.displayMesh,u.visible=o.displayBounds),m.render(r,w)} diff --git a/example/bundle/asyncGenerate.html b/example/bundle/asyncGenerate.html new file mode 100644 index 000000000..648ad5c76 --- /dev/null +++ b/example/bundle/asyncGenerate.html @@ -0,0 +1,68 @@ + + + + three-mesh-bvh - Async BVH Generation + + + + + + + + + + + + + + + +
+
+
100%
+
+
+ + diff --git a/example/bundle/batchedMesh.html b/example/bundle/batchedMesh.html new file mode 100644 index 000000000..44a5d9107 --- /dev/null +++ b/example/bundle/batchedMesh.html @@ -0,0 +1,43 @@ + + + + three-mesh-bvh - Complex Geometry Raycasting + + + + + + + + + + + + +
+ BatchedMesh with 3 geometries. +
+ + diff --git a/example/bundle/characterMovement.html b/example/bundle/characterMovement.html new file mode 100644 index 000000000..0b25b69f5 --- /dev/null +++ b/example/bundle/characterMovement.html @@ -0,0 +1,56 @@ + + + + three-mesh-bvh - Character Movement + + + + + + + + + + + + + + + + + +
+ Basic character movement example. Click and drag to rotate the camera direction and use WASD to move. + +
+
+ + Model by Warkarma on Sketchfab. +
+ + diff --git a/example/bundle/clippedEdges.html b/example/bundle/clippedEdges.html new file mode 100644 index 000000000..d0a238ce4 --- /dev/null +++ b/example/bundle/clippedEdges.html @@ -0,0 +1,68 @@ + + + + three-mesh-bvh - Clipped Edges + + + + + + + + + + + + + + + + +
+ + Using MeshBVH to quickly detect plane-clipped triangle edges on static, +
+ merged 2 million polygon model. Stencil buffer used for solid clip cap. +
+ + Model by T-FLEX CAD on Sketchfab. +
+
+ + diff --git a/example/bundle/coi-serviceworker.js b/example/bundle/coi-serviceworker.js new file mode 100644 index 000000000..921ff82a0 --- /dev/null +++ b/example/bundle/coi-serviceworker.js @@ -0,0 +1,121 @@ +/* eslint-disable */ +// copied from https://github.com/gzuidhof/coi-serviceworker + +/*! coi-serviceworker v0.1.7 - Guido Zuidhof and contributors, licensed under MIT */ +let coepCredentialless = false; +if (typeof window === 'undefined') { + self.addEventListener("install", () => self.skipWaiting()); + self.addEventListener("activate", (event) => event.waitUntil(self.clients.claim())); + + self.addEventListener("message", (ev) => { + if (!ev.data) { + return; + } else if (ev.data.type === "deregister") { + self.registration + .unregister() + .then(() => { + return self.clients.matchAll(); + }) + .then(clients => { + clients.forEach((client) => client.navigate(client.url)); + }); + } else if (ev.data.type === "coepCredentialless") { + coepCredentialless = ev.data.value; + } + }); + + self.addEventListener("fetch", function (event) { + const r = event.request; + if (r.cache === "only-if-cached" && r.mode !== "same-origin") { + return; + } + + const request = (coepCredentialless && r.mode === "no-cors") + ? new Request(r, { + credentials: "omit", + }) + : r; + event.respondWith( + fetch(request) + .then((response) => { + if (response.status === 0) { + return response; + } + + const newHeaders = new Headers(response.headers); + newHeaders.set("Cross-Origin-Embedder-Policy", + coepCredentialless ? "credentialless" : "require-corp" + ); + if (!coepCredentialless) { + newHeaders.set("Cross-Origin-Resource-Policy", "cross-origin"); + } + newHeaders.set("Cross-Origin-Opener-Policy", "same-origin"); + + return new Response(response.body, { + status: response.status, + statusText: response.statusText, + headers: newHeaders, + }); + }) + .catch((e) => console.error(e)) + ); + }); + +} else { + (() => { + // You can customize the behavior of this script through a global `coi` variable. + const coi = { + shouldRegister: () => true, + shouldDeregister: () => false, + coepCredentialless: () => !(window.chrome || window.netscape), + doReload: () => window.location.reload(), + quiet: false, + ...window.coi + }; + + const n = navigator; + + if (n.serviceWorker && n.serviceWorker.controller) { + n.serviceWorker.controller.postMessage({ + type: "coepCredentialless", + value: coi.coepCredentialless(), + }); + + if (coi.shouldDeregister()) { + n.serviceWorker.controller.postMessage({ type: "deregister" }); + } + } + + // If we're already coi: do nothing. Perhaps it's due to this script doing its job, or COOP/COEP are + // already set from the origin server. Also if the browser has no notion of crossOriginIsolated, just give up here. + if (window.crossOriginIsolated !== false || !coi.shouldRegister()) return; + + if (!window.isSecureContext) { + !coi.quiet && console.log("COOP/COEP Service Worker not registered, a secure context is required."); + return; + } + + // In some environments (e.g. Chrome incognito mode) this won't be available + if (n.serviceWorker) { + n.serviceWorker.register(window.document.currentScript.src).then( + (registration) => { + !coi.quiet && console.log("COOP/COEP Service Worker registered", registration.scope); + + registration.addEventListener("updatefound", () => { + !coi.quiet && console.log("Reloading page to make use of updated COOP/COEP Service Worker."); + coi.doReload(); + }); + + // If the registration is active, but it's not controlling the page + if (registration.active && !n.serviceWorker.controller) { + !coi.quiet && console.log("Reloading page to make use of COOP/COEP Service Worker."); + coi.doReload(); + } + }, + (err) => { + !coi.quiet && console.error("COOP/COEP Service Worker failed to register:", err); + } + ); + } + })(); +} diff --git a/example/bundle/collectTriangles.html b/example/bundle/collectTriangles.html new file mode 100644 index 000000000..eab287385 --- /dev/null +++ b/example/bundle/collectTriangles.html @@ -0,0 +1,29 @@ + + + + three-mesh-bvh - Geometry Collect Triangles + + + + + + + + + + + + + + diff --git a/example/bundle/cpuPathTracing.html b/example/bundle/cpuPathTracing.html new file mode 100644 index 000000000..fbeb7437a --- /dev/null +++ b/example/bundle/cpuPathTracing.html @@ -0,0 +1,68 @@ + + + + three-mesh-bvh - CPU Path Tracing + + + + + + + + + + + + + + + + +
+ CPU Path Tracer demo based on a smattering of online resources. Engine by T-FLEX CAD on Sketchfab. +

+ Checkout the Raytracing in One Weekend series and PBR Book for some great introductions to path tracing! +
+
+
+ + diff --git a/example/bundle/diamond.html b/example/bundle/diamond.html new file mode 100644 index 000000000..957dad46a --- /dev/null +++ b/example/bundle/diamond.html @@ -0,0 +1,54 @@ + + + + + Total Internal Refraction + + + + + + + + + + + + + + + +
+ Using shader ray tracing to model internal reflection for a diamond material. +
+ Model from Sketchfab. Full material implementation available here. +
+ + + diff --git a/example/bundle/distancecast.html b/example/bundle/distancecast.html new file mode 100644 index 000000000..26f562787 --- /dev/null +++ b/example/bundle/distancecast.html @@ -0,0 +1,42 @@ + + + + three-mesh-bvh - Geometry Closest Distance + + + + + + + + + + + + + + + +
+ + diff --git a/example/bundle/edgeIntersect.html b/example/bundle/edgeIntersect.html new file mode 100644 index 000000000..71af9ddd1 --- /dev/null +++ b/example/bundle/edgeIntersect.html @@ -0,0 +1,30 @@ + + + + three-mesh-bvh - Geometry Edge Intersection + + + + + + + + + + + + + + + diff --git a/example/bundle/gpuPathTracing.html b/example/bundle/gpuPathTracing.html new file mode 100644 index 000000000..d1fed566d --- /dev/null +++ b/example/bundle/gpuPathTracing.html @@ -0,0 +1,61 @@ + + + + three-mesh-bvh - GPU Path Tracing + + + + + + + + + + + + + + + + + +
+ Lambertian material Path Tracer implemented using BVH intersections on the GPU. +
+
+ + diff --git a/example/bundle/gpuPathTracingSimple.html b/example/bundle/gpuPathTracingSimple.html new file mode 100644 index 000000000..adedc4def --- /dev/null +++ b/example/bundle/gpuPathTracingSimple.html @@ -0,0 +1,46 @@ + + + + three-mesh-bvh - GPU Path Tracing + + + + + + + + + + + + + + + +
+ Simple example of running BVH intersections on an animated geometry on the GPU in a shader. +
+ + diff --git a/example/bundle/inspector.html b/example/bundle/inspector.html new file mode 100644 index 000000000..e14a8558b --- /dev/null +++ b/example/bundle/inspector.html @@ -0,0 +1,73 @@ + + + + three-mesh-bvh - BVH Inspector + + + + + + + + + + + + + + + + +
+ BVH inspector showing the number of traversals at a given pixel, various BVH construction stats, and basic raycast benchmark. +
+
+ Pixels with traversal counts above the "traversalTreshold" are highlighted in red. +
+
+
+
+
+ + diff --git a/example/bundle/physics.html b/example/bundle/physics.html new file mode 100644 index 000000000..76e85d97e --- /dev/null +++ b/example/bundle/physics.html @@ -0,0 +1,55 @@ + + + + three-mesh-bvh - Rudimentary Sphere Physics + + + + + + + + + + + + + + + + +
+ Rudimentary sphere collision physics with an environment using MeshBVH. + +
+
+ + Model by Lowpolyprincipal on Sketchfab. +
+ + diff --git a/example/bundle/pointCloudIntersection.html b/example/bundle/pointCloudIntersection.html new file mode 100644 index 000000000..1effe861f --- /dev/null +++ b/example/bundle/pointCloudIntersection.html @@ -0,0 +1,63 @@ + + + + three-mesh-bvh - Geometry point clouds + + + + + + + + + + + + + +
+ Point cloud intersection by modeling points as degenerate triangles with MeshBVH. + +
+
+ + Model by SiteScape on Sketchfab. +
+
+ + diff --git a/example/bundle/randomSampleDebug.html b/example/bundle/randomSampleDebug.html new file mode 100644 index 000000000..d6cf1dd2f --- /dev/null +++ b/example/bundle/randomSampleDebug.html @@ -0,0 +1,38 @@ + + + + three-mesh-bvh - Random Sample Debug + + + + + + + + + + + +
+ + diff --git a/example/bundle/raycast.html b/example/bundle/raycast.html new file mode 100644 index 000000000..d52b9d4d8 --- /dev/null +++ b/example/bundle/raycast.html @@ -0,0 +1,30 @@ + + + + three-mesh-bvh - Complex Geometry Raycasting + + + + + + + + + + + + + + + diff --git a/example/bundle/sculpt.html b/example/bundle/sculpt.html new file mode 100644 index 000000000..3fdf97924 --- /dev/null +++ b/example/bundle/sculpt.html @@ -0,0 +1,51 @@ + + + + three-mesh-bvh - Geometry Sculpting + + + + + + + + + + + + + + +
+ Inspired by SculptGL. +
+
+ Matcap textures from nidorx/matcaps repo. +
+ + diff --git a/example/bundle/sdfGeneration.html b/example/bundle/sdfGeneration.html new file mode 100644 index 000000000..1dd89d5c4 --- /dev/null +++ b/example/bundle/sdfGeneration.html @@ -0,0 +1,70 @@ + + + + three-mesh-bvh - Fast SDF Generation + + + + + + + + + + + + + + + + + + + + +
+ 3D Texture Signed Distance Field generation on the gpu and raymarching. +
+ "Surface" sets the distance at which the surface is rendered. +
+ "Layers" show the raw signed distance values. + +
+
+ + diff --git a/example/bundle/selection.html b/example/bundle/selection.html new file mode 100644 index 000000000..da39acbdf --- /dev/null +++ b/example/bundle/selection.html @@ -0,0 +1,58 @@ + + + + three-mesh-bvh - Geometry Collect Triangles + + + + + + + + + + + + + +
+ Right click rotate, left click drag selection +
+ NOTE: Triangles and bounds clipped by the camera not supported +
+
+ + diff --git a/example/bundle/shapecast.html b/example/bundle/shapecast.html new file mode 100644 index 000000000..2d0e3b127 --- /dev/null +++ b/example/bundle/shapecast.html @@ -0,0 +1,32 @@ + + + + three-mesh-bvh - Geometry Lasso Selection + + + + + + + + + + + + + + + + + diff --git a/example/bundle/skinnedMesh.html b/example/bundle/skinnedMesh.html new file mode 100644 index 000000000..1fd0584e2 --- /dev/null +++ b/example/bundle/skinnedMesh.html @@ -0,0 +1,68 @@ + + + + three-mesh-bvh - Skinned Mesh BVH + + + + + + + + + + + + + + + + + + +
+ SkinnedMesh and morph target BVH support by iteratively generating a static version of
+ the geometry and refitting the existing BVH. +
+
+
+
Model by DailyArt on Sketchfab
+
+ + diff --git a/example/bundle/triangleIntersect.html b/example/bundle/triangleIntersect.html new file mode 100644 index 000000000..7c689bd78 --- /dev/null +++ b/example/bundle/triangleIntersect.html @@ -0,0 +1,28 @@ + + + + three-mesh-bvh - Triangle-Triangle Intersection + + + + + + + + + + + + + diff --git a/example/bundle/voxelize.html b/example/bundle/voxelize.html new file mode 100644 index 000000000..cbb15e21e --- /dev/null +++ b/example/bundle/voxelize.html @@ -0,0 +1,65 @@ + + + + three-mesh-bvh - Geometry Voxelization + + + + + + + + + + + + + + + + + +
+ Demonstration of voxelizing a mesh with the ability to detect the inside and outside of a model. +
+
+
+
+ +