var fx=Object.defineProperty;var dx=(r,e)=>{for(var t in e)fx(r,t,{get:e[t],enumerable:!0})};async function px(r={}){var e,t=r,n=!!globalThis.window,i=!!globalThis.WorkerGlobalScope,s=!1;if(s)var o=void 0;var a=!1;t.setup=function(){if(a)return;a=!0,t.initTBB();function v(F,H,te=(le=>le)){if(H)for(let le of H)F.push_back(te(le));return F}function b(F,H=(te=>te)){let te=[],le=F.size();for(let Xe=0;Xete)){let te=[],le=F.size();for(let Xe=0;Xev(new t.Vector_vec2,H,te=>te instanceof Array?{x:te[0],y:te[1]}:te))}function B(F){for(let H=0;HF.min[H]),max:["x","y"].map(H=>F.max[H])}},t.CrossSection.prototype.offset=function(F,H="Round",te=2,le=0){return this._Offset(F,re(H),te,le)},t.CrossSection.prototype.simplify=function(F=1e-6){return this._Simplify(F)},t.CrossSection.prototype.extrude=function(F,H=0,te=0,le=[1,1],Xe=!1){le=W([le]);let ut=t._Extrude(this._ToPolygons(),F,H,te,le);return Xe?ut.translate([0,0,-F/2]):ut},t.CrossSection.prototype.revolve=function(F=0,H=360){return t._Revolve(this._ToPolygons(),F,H)},t.CrossSection.prototype.add=function(F){return this._add(xe(F))},t.CrossSection.prototype.subtract=function(F){return this._subtract(xe(F))},t.CrossSection.prototype.intersect=function(F){return this._intersect(xe(F))},t.CrossSection.prototype.toPolygons=function(){let F=this._ToPolygons(),H=D(F,te=>[te.x,te.y]);return F.delete(),H},t.Manifold.prototype.smoothOut=function(F=52.5,H=0){return this._SmoothOut(F,H)},t.Manifold.prototype.warp=function(F){let H=Tr(function(Xe){let ut=ve(Xe,"double"),Et=ve(Xe+8,"double"),kt=ve(Xe+16,"double"),Ot=[ut,Et,kt];F(Ot),we(Xe,Ot[0],"double"),we(Xe+8,Ot[1],"double"),we(Xe+16,Ot[2],"double")},"vi"),te=this._Warp(H);Ar(H);let le=te.status();if(le!=="NoError")throw new t.ManifoldError(le);return te},t.Manifold.prototype.warpBatch=function(F){let H=Tr(function(Xe,ut){let Et=t.HEAPF64??K;if(!Et)throw new Error("WASM heap is not initialized (HEAPF64 unavailable)");let kt=new Float64Array(Et.buffer,Xe,ut*3);F(kt,ut)},"vii"),te=this._WarpBatch(H);Ar(H);let le=te.status();if(le!=="NoError")throw new t.ManifoldError(le);return te},t.Manifold.prototype.calculateNormals=function(F=0,H=52.5){return this._CalculateNormals(F,H)},t.Manifold.prototype.smoothByNormals=function(F=0){return this._SmoothByNormals(F)},t.Manifold.prototype.setProperties=function(F,H){let te=this.numProp(),le=Tr(function(ut,Et,kt){let Ot=[];for(let Wt=0;Wt({faceID:Xe.faceID,distance:Xe.distance,position:["x","y","z"].map(ut=>Xe.position[ut]),normal:["x","y","z"].map(ut=>Xe.normal[ut])}));return te.delete(),le},t.Manifold.prototype.split=function(F){let H=this._Split(F),te=b(H);return H.delete(),te},t.Manifold.prototype.splitByPlane=function(F,H=0){let te=this._SplitByPlane(X([F]),H),le=b(te);return te.delete(),le},t.Manifold.prototype.decompose=function(){let F=this._Decompose(),H=b(F);return F.delete(),H},t.Manifold.prototype.boundingBox=function(){let F=this._boundingBox();return{min:["x","y","z"].map(H=>F.min[H]),max:["x","y","z"].map(H=>F.max[H])}},t.Manifold.prototype.simplify=function(F=0){return this._Simplify(F)};class Ce{constructor({numProp:H=3,triVerts:te=new Uint32Array,vertProperties:le=new Float32Array,mergeFromVert:Xe,mergeToVert:ut,runIndex:Et,runOriginalID:kt,faceID:Ot,halfedgeTangent:fi,runTransform:ji,runFlags:Wt,tolerance:af=0}={}){this.numProp=H,this.triVerts=te,this.vertProperties=le,this.mergeFromVert=Xe,this.mergeToVert=ut,this.runIndex=Et,this.runOriginalID=kt,this.faceID=Ot,this.halfedgeTangent=fi,this.runTransform=ji,this.runFlags=Wt,this.tolerance=af}get numTri(){return this.triVerts.length/3}get numVert(){return this.vertProperties.length/this.numProp}get numRun(){return this.runOriginalID.length}merge(){let{changed:H,mesh:te}=t._Merge(this);return Object.assign(this,{...te}),H}verts(H){return this.triVerts.subarray(3*H,3*(H+1))}position(H){return this.vertProperties.subarray(this.numProp*H,this.numProp*H+3)}extras(H){return this.vertProperties.subarray(this.numProp*H+3,this.numProp*(H+1))}tangent(H){return this.halfedgeTangent.subarray(4*H,4*(H+1))}transform(H){let te=new Array(16);for(let le of[0,1,2,3])for(let Xe of[0,1,2])te[4*le+Xe]=this.runTransform[12*H+3*le+Xe];return te[15]=1,te}backside(H){return this.runFlags!=null&&Hte instanceof Array?{x:te[0],y:te[1]}:te)}t.CrossSection.hull=function(...F){F.length==1&&(F=F[0]);let H=new t.Vector_vec2;for(let le of F)if(le instanceof ue)t._crossSectionCollectVertices(H,le);else if(le instanceof Array&&le.length==2&&typeof le[0]=="number")H.push_back({x:le[0],y:le[1]});else if(le.x)H.push_back(le);else{let ut=le[0].length==2&&typeof le[0][0]=="number"||le[0].x?[le]:le;for(let Et of ut)Ye(H,Et)}let te=t._crossSectionHullPoints(H);return H.delete(),te},t.CrossSection.prototype=Object.create(ue.prototype),Object.defineProperty(t.CrossSection,Symbol.hasInstance,{get:()=>F=>F instanceof ue});let nt=t.Manifold;t.Manifold=function(F){let H=new nt(F),te=H.status();if(te!=="NoError")throw new t.ManifoldError(te);return H},t.Manifold.ofMesh=function(F){return new t.Manifold(F)},t.Manifold.tetrahedron=function(){return t._Tetrahedron()},t.Manifold.cube=function(...F){let H;F.length==0?H={x:1,y:1,z:1}:typeof F[0]=="number"?H={x:F[0],y:F[0],z:F[0]}:H=X(F);let te=F[1]||!1;return t._Cube(H,te)},t.Manifold.cylinder=function(F,H,te=-1,le=0,Xe=!1){return t._Cylinder(F,H,te,le,Xe)},t.Manifold.sphere=function(F,H=0){return t._Sphere(F,H)},t.Manifold.smooth=function(F,H=[]){let te=new t.Vector_smoothness;v(te,H);let le=t._Smooth(F,te);return te.delete(),le},t.Manifold.extrude=function(F,H,te=0,le=0,Xe=[1,1],ut=!1){return(F instanceof ue?F:t.CrossSection(F,"Positive")).extrude(H,te,le,Xe,ut)},t.Manifold.revolve=function(F,H=0,te=360){return(F instanceof ue?F:t.CrossSection(F,"Positive")).revolve(H,te)},t.Manifold.reserveIDs=function(F){return t._ReserveIDs(F)};function ot(F){return function(...H){H.length==1&&(H=H[0]);let te=new t.Vector_manifold;for(let Xe of H)te.push_back(Xe);let le=t["_manifold"+F+"N"](te);return te.delete(),le}}t.Manifold.union=ot("Union"),t.Manifold.compose=t.Manifold.union,t.Manifold.difference=ot("Difference"),t.Manifold.intersection=ot("Intersection"),t.Manifold.levelSet=function(F,H,te,le=0,Xe=-1){let ut={min:{x:H.min[0],y:H.min[1],z:H.min[2]},max:{x:H.max[0],y:H.max[1],z:H.max[2]}},Et=Tr(function(Ot){let fi=ve(Ot,"double"),ji=ve(Ot+8,"double"),Wt=ve(Ot+16,"double");return F([fi,ji,Wt])},"di"),kt=t._LevelSet(Et,ut,te,le,Xe);return Ar(Et),kt},t.ExecutionContext.prototype.fromMesh=function(F){return this._FromMesh(F)},t.ExecutionContext.prototype.smooth=function(F,H=[]){let te=new t.Vector_smoothness;v(te,H);let le=this._Smooth(F,te);return te.delete(),le},t.ExecutionContext.prototype.levelSet=function(F,H,te,le=0,Xe=-1){let ut={min:{x:H.min[0],y:H.min[1],z:H.min[2]},max:{x:H.max[0],y:H.max[1],z:H.max[2]}},Et=Tr(function(Ot){let fi=ve(Ot,"double"),ji=ve(Ot+8,"double"),Wt=ve(Ot+16,"double");return F([fi,ji,Wt])},"di"),kt=this._LevelSet(Et,ut,te,le,Xe);return Ar(Et),kt};function mt(F,H){v(F,H,te=>te instanceof Array?{x:te[0],y:te[1],z:te[2]}:te)}t.Manifold.hull=function(...F){F.length==1&&(F=F[0]);let H=new t.Vector_vec3;for(let le of F)le instanceof nt?t._manifoldCollectVertices(H,le):le instanceof Array&&le.length==3&&typeof le[0]=="number"?H.push_back({x:le[0],y:le[1],z:le[2]}):le.x?H.push_back(le):mt(H,le);let te=t._manifoldHullPoints(H);return H.delete(),te},t.Manifold.prototype=Object.create(nt.prototype),Object.defineProperty(t.Manifold,Symbol.hasInstance,{get:()=>F=>F instanceof nt}),t.triangulate=function(F,H=-1,te=!0){let le=U(F),Xe=b(t._Triangulate(le,H,te),ut=>[ut[0],ut[1],ut[2]]);return B(le),Xe}};var l=[],c="./this.program",h=(v,b)=>{throw b},u=import.meta.url,f="";function d(v){return t.locateFile?t.locateFile(v,f):f+v}var m,_;if(s){var g=o("node:fs");u.startsWith("file:")&&(f=o("node:path").dirname(o("node:url").fileURLToPath(u))+"/"),_=v=>{v=E(v)?new URL(v):v;var b=g.readFileSync(v);return b},m=async(v,b=!0)=>{v=E(v)?new URL(v):v;var D=g.readFileSync(v,b?void 0:"utf8");return D},process.argv.length>1&&(c=process.argv[1].replace(/\\/g,"/")),l=process.argv.slice(2),h=(v,b)=>{throw process.exitCode=v,b}}else if(n||i){try{f=new URL(".",u).href}catch{}i&&(_=v=>{var b=new XMLHttpRequest;return b.open("GET",v,!1),b.responseType="arraybuffer",b.send(null),new Uint8Array(b.response)}),m=async v=>{if(E(v))return new Promise((D,U)=>{var B=new XMLHttpRequest;B.open("GET",v,!0),B.responseType="arraybuffer",B.onload=()=>{if(B.status==200||B.status==0&&B.response){D(B.response);return}U(B.status)},B.onerror=U,B.send(null)});var b=await fetch(v,{credentials:"same-origin"});if(b.ok)return b.arrayBuffer();throw new Error(b.status+" : "+b.url)}}var p=console.log.bind(console),M=console.error.bind(console),x,y=!1,E=v=>v.startsWith("file://"),S,R,P,w,T,N,V,G,Z,K,Q,_e,ne=!1;function Te(){var v=bc.buffer;P=new Int8Array(v),T=new Int16Array(v),w=new Uint8Array(v),N=new Uint16Array(v),V=new Int32Array(v),G=new Uint32Array(v),Z=new Float32Array(v),K=new Float64Array(v),Q=new BigInt64Array(v),_e=new BigUint64Array(v)}function Oe(){if(t.preRun)for(typeof t.preRun=="function"&&(t.preRun=[t.preRun]);t.preRun.length;)ae(t.preRun.shift());O(oe)}function Ge(){ne=!0,Rr.J()}function dt(){if(t.postRun)for(typeof t.postRun=="function"&&(t.postRun=[t.postRun]);t.postRun.length;)he(t.postRun.shift());O(pe)}function yt(v){t.onAbort?.(v),v="Aborted("+v+")",M(v),y=!0,v+=". Build with -sASSERTIONS for more info.";var b=new WebAssembly.RuntimeError(v);throw R?.(b),b}var Rt;function St(){return t.locateFile?d("manifold.wasm"):new URL("manifold.wasm",import.meta.url).href}function se(v){if(v==Rt&&x)return new Uint8Array(x);if(_)return _(v);throw"both async and sync fetching of the wasm failed"}async function ge(v){if(!x)try{var b=await m(v);return new Uint8Array(b)}catch{}return se(v)}async function Ve(v,b){try{var D=await ge(v),U=await WebAssembly.instantiate(D,b);return U}catch(B){M(`failed to asynchronously prepare wasm: ${B}`),yt(B)}}async function Ke(v,b,D){if(!v&&!E(b)&&!s)try{var U=fetch(b,{credentials:"same-origin"}),B=await WebAssembly.instantiateStreaming(U,D);return B}catch(W){M(`wasm streaming compile failed: ${W}`),M("falling back to ArrayBuffer instantiation")}return Ve(b,D)}function Ze(){var v={a:cx};return v}async function xt(){function v(W,X){return Rr=W.exports,Rr=ux(Rr),lx(Rr),Te(),Rr}function b(W){return v(W.instance)}var D=Ze();if(t.instantiateWasm)return new Promise((W,X)=>{t.instantiateWasm(D,(Y,re)=>{W(v(Y,re))})});Rt??=St();var U=await Ke(x,Rt,D),B=b(U);return B}class Bt{name="ExitStatus";constructor(b){this.message=`Program terminated with exit(${b})`,this.status=b}}var O=v=>{for(;v.length>0;)v.shift()(t)},pe=[],he=v=>pe.push(v),oe=[],ae=v=>oe.push(v);function ve(v,b="i8"){switch(b.endsWith("*")&&(b="*"),b){case"i1":return P[v>>>0];case"i8":return P[v>>>0];case"i16":return T[v>>>1>>>0];case"i32":return V[v>>>2>>>0];case"i64":return Q[v>>>3>>>0];case"float":return Z[v>>>2>>>0];case"double":return K[v>>>3>>>0];case"*":return G[v>>>2>>>0];default:yt(`invalid type for getValue: ${b}`)}}var be=!0;function we(v,b,D="i8"){switch(D.endsWith("*")&&(D="*"),D){case"i1":P[v>>>0]=b;break;case"i8":P[v>>>0]=b;break;case"i16":T[v>>>1>>>0]=b;break;case"i32":V[v>>>2>>>0]=b;break;case"i64":Q[v>>>3>>>0]=BigInt(b);break;case"float":Z[v>>>2>>>0]=b;break;case"double":K[v>>>3>>>0]=b;break;case"*":G[v>>>2>>>0]=b;break;default:yt(`invalid type for setValue: ${D}`)}}class ft{constructor(b){this.excPtr=b,this.ptr=b-24}set_type(b){G[this.ptr+4>>>2>>>0]=b}get_type(){return G[this.ptr+4>>>2>>>0]}set_destructor(b){G[this.ptr+8>>>2>>>0]=b}get_destructor(){return G[this.ptr+8>>>2>>>0]}set_caught(b){b=b?1:0,P[this.ptr+12>>>0]=b}get_caught(){return P[this.ptr+12>>>0]!=0}set_rethrown(b){b=b?1:0,P[this.ptr+13>>>0]=b}get_rethrown(){return P[this.ptr+13>>>0]!=0}init(b,D){this.set_adjusted_ptr(0),this.set_type(b),this.set_destructor(D)}set_adjusted_ptr(b){G[this.ptr+16>>>2>>>0]=b}get_adjusted_ptr(){return G[this.ptr+16>>>2>>>0]}}var lt=0,L=0;function A(v,b,D){v>>>=0,b>>>=0,D>>>=0;var U=new ft(v);throw U.init(b,D),lt=v,L++,lt}var q=()=>yt(""),ee={},de=v=>{for(;v.length;){var b=v.pop(),D=v.pop();D(b)}};function ie(v){return this.fromWireType(G[v>>>2>>>0])}var He={},Ee={},ke={},Je=class extends Error{constructor(b){super(b),this.name="InternalError"}},ye=v=>{throw new Je(v)},Re=(v,b,D)=>{v.forEach(Y=>ke[Y]=b);function U(Y){var re=D(Y);re.length!==v.length&&ye("Mismatched type converter count");for(var ue=0;ue{B[Y]=Ee[re],++X,X===W.length&&U(B)}));W.length===0&&U(B)},rt=function(v){v>>>=0;var b=ee[v];delete ee[v];var D=b.rawConstructor,U=b.rawDestructor,B=b.fields,W=B.map(X=>X.getterReturnType).concat(B.map(X=>X.setterArgumentType));Re([v],W,X=>{var Y={};for(var[re,ue]of B.entries()){let xe=X[re],Ce=ue.getter,Fe=ue.getterContext,Ye=X[re+B.length],nt=ue.setter,ot=ue.setterContext;Y[ue.fieldName]={read:mt=>xe.fromWireType(Ce(Fe,mt)),write:(mt,F)=>{var H=[];nt(ot,mt,Ye.toWireType(H,F)),de(H)},optional:xe.optional}}return[{name:b.name,fromWireType:xe=>{var Ce={};for(var Fe in Y)Ce[Fe]=Y[Fe].read(xe);return U(xe),Ce},toWireType:(xe,Ce)=>{for(var Fe in Y)if(!(Fe in Ce)&&!Y[Fe].optional)throw new TypeError(`Missing field: "${Fe}"`);var Ye=D();for(Fe in Y)Y[Fe].write(Ye,Ce[Fe]);return xe!==null&&xe.push(U,Ye),Ye},readValueFromPointer:ie,destructorFunction:U}]})},Ie=v=>{v>>>=0;for(var b="";;){var D=w[v++>>>0];if(!D)return b;b+=String.fromCharCode(D)}},Pe=class extends Error{constructor(b){super(b),this.name="BindingError"}},Ne=v=>{throw new Pe(v)};function z(v,b,D={}){var U=b.name;if(v||Ne(`type "${U}" must have a positive integer typeid pointer`),Ee.hasOwnProperty(v)){if(D.ignoreDuplicateRegistrations)return;Ne(`Cannot register type '${U}' twice`)}if(Ee[v]=b,delete ke[v],He.hasOwnProperty(v)){var B=He[v];delete He[v],B.forEach(W=>W())}}function me(v,b,D={}){return z(v,b,D)}var Ae=(v,b,D)=>{switch(b){case 1:return D?U=>P[U>>>0]:U=>w[U>>>0];case 2:return D?U=>T[U>>>1>>>0]:U=>N[U>>>1>>>0];case 4:return D?U=>V[U>>>2>>>0]:U=>G[U>>>2>>>0];case 8:return D?U=>Q[U>>>3>>>0]:U=>_e[U>>>3>>>0];default:throw new TypeError(`invalid integer width (${b}): ${v}`)}},We=function(v,b,D,U,B){v>>>=0,b>>>=0,D>>>=0,b=Ie(b);let W=U===0n,X=Y=>Y;if(W){let Y=D*8;X=re=>BigInt.asUintN(Y,re),B=X(B)}me(v,{name:b,fromWireType:X,toWireType:(Y,re)=>(typeof re=="number"&&(re=BigInt(re)),re),readValueFromPointer:Ae(b,D,!W),destructorFunction:null})};function Me(v,b,D,U){v>>>=0,b>>>=0,b=Ie(b),me(v,{name:b,fromWireType:function(B){return!!B},toWireType:function(B,W){return W?D:U},readValueFromPointer:function(B){return this.fromWireType(w[B>>>0])},destructorFunction:null})}var fe=v=>({count:v.count,deleteScheduled:v.deleteScheduled,preservePointerOnDelete:v.preservePointerOnDelete,ptr:v.ptr,ptrType:v.ptrType,smartPtr:v.smartPtr,smartPtrType:v.smartPtrType}),$e=v=>{function b(D){return D.$$.ptrType.registeredClass.name}Ne(b(v)+" instance already deleted")},ct=!1,Nt=v=>{},Pt=v=>{v.smartPtr?v.smartPtrType.rawDestructor(v.smartPtr):v.ptrType.registeredClass.rawDestructor(v.ptr)},qn=v=>{v.count.value-=1;var b=v.count.value===0;b&&Pt(v)},dn=v=>globalThis.FinalizationRegistry?(ct=new FinalizationRegistry(b=>{qn(b.$$)}),dn=b=>{var D=b.$$,U=!!D.smartPtr;if(U){var B={$$:D};ct.register(b,B,b)}return b},Nt=b=>ct.unregister(b),dn(v)):(dn=b=>b,v),br=[],Ti=()=>{for(;br.length;){var v=br.pop();v.$$.deleteScheduled=!1,v.delete()}},bs,xc=()=>{let v=Mr.prototype;Object.assign(v,{isAliasOf(D){if(!(this instanceof Mr)||!(D instanceof Mr))return!1;var U=this.$$.ptrType.registeredClass,B=this.$$.ptr;D.$$=D.$$;for(var W=D.$$.ptrType.registeredClass,X=D.$$.ptr;U.baseClass;)B=U.upcast(B),U=U.baseClass;for(;W.baseClass;)X=W.upcast(X),W=W.baseClass;return U===W&&B===X},clone(){if(this.$$.ptr||$e(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var D=dn(Object.create(Object.getPrototypeOf(this),{$$:{value:fe(this.$$)}}));return D.$$.count.value+=1,D.$$.deleteScheduled=!1,D},delete(){this.$$.ptr||$e(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&Ne("Object already scheduled for deletion"),Nt(this),qn(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)},isDeleted(){return!this.$$.ptr},deleteLater(){return this.$$.ptr||$e(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&Ne("Object already scheduled for deletion"),br.push(this),br.length===1&&bs&&bs(Ti),this.$$.deleteScheduled=!0,this}});let b=Symbol.dispose;b&&(v[b]=v.delete)};function Mr(){}var Ai=(v,b)=>Object.defineProperty(b,"name",{value:v}),Ho={},Er=(v,b,D)=>{if(v[b].overloadTable===void 0){var U=v[b];v[b]=function(...B){return v[b].overloadTable.hasOwnProperty(B.length)||Ne(`Function '${D}' called with an invalid number of arguments (${B.length}) - expects one of (${v[b].overloadTable})!`),v[b].overloadTable[B.length].apply(this,B)},v[b].overloadTable=[],v[b].overloadTable[U.argCount]=U}},Zi=(v,b,D)=>{t.hasOwnProperty(v)?((D===void 0||t[v].overloadTable!==void 0&&t[v].overloadTable[D]!==void 0)&&Ne(`Cannot register public name '${v}' twice`),Er(t,v,v),t[v].overloadTable.hasOwnProperty(D)&&Ne(`Cannot register multiple overloads of a function with the same number of arguments (${D})!`),t[v].overloadTable[D]=b):(t[v]=b,t[v].argCount=D)},vc=48,jh=57,Kh=v=>{v=v.replace(/[^a-zA-Z0-9_]/g,"$");var b=v.charCodeAt(0);return b>=vc&&b<=jh?`_${v}`:v};function Qh(v,b,D,U,B,W,X,Y){this.name=v,this.constructor=b,this.instancePrototype=D,this.rawDestructor=U,this.baseClass=B,this.getActualType=W,this.upcast=X,this.downcast=Y,this.pureVirtualFunctions=[]}var Go=(v,b,D)=>{for(;b!==D;)b.upcast||Ne(`Expected null or instance of ${D.name}, got an instance of ${b.name}`),v=b.upcast(v),b=b.baseClass;return v},ko=v=>{if(v===null)return"null";var b=typeof v;return b==="object"||b==="array"||b==="function"?v.toString():""+v};function ef(v,b){if(b===null)return this.isReference&&Ne(`null is not a valid ${this.name}`),0;b.$$||Ne(`Cannot pass "${ko(b)}" as a ${this.name}`),b.$$.ptr||Ne(`Cannot pass deleted object as a pointer of type ${this.name}`);var D=b.$$.ptrType.registeredClass,U=Go(b.$$.ptr,D,this.registeredClass);return U}function I(v,b){var D;if(b===null)return this.isReference&&Ne(`null is not a valid ${this.name}`),this.isSmartPointer?(D=this.rawConstructor(),v!==null&&v.push(this.rawDestructor,D),D):0;(!b||!b.$$)&&Ne(`Cannot pass "${ko(b)}" as a ${this.name}`),b.$$.ptr||Ne(`Cannot pass deleted object as a pointer of type ${this.name}`),!this.isConst&&b.$$.ptrType.isConst&&Ne(`Cannot convert argument of type ${b.$$.smartPtrType?b.$$.smartPtrType.name:b.$$.ptrType.name} to parameter type ${this.name}`);var U=b.$$.ptrType.registeredClass;if(D=Go(b.$$.ptr,U,this.registeredClass),this.isSmartPointer)switch(b.$$.smartPtr===void 0&&Ne("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:b.$$.smartPtrType===this?D=b.$$.smartPtr:Ne(`Cannot convert argument of type ${b.$$.smartPtrType?b.$$.smartPtrType.name:b.$$.ptrType.name} to parameter type ${this.name}`);break;case 1:D=b.$$.smartPtr;break;case 2:if(b.$$.smartPtrType===this)D=b.$$.smartPtr;else{var B=b.clone();D=this.rawShare(D,Ft.toHandle(()=>B.delete())),v!==null&&v.push(this.rawDestructor,D)}break;default:Ne("Unsupported sharing policy")}return D}function k(v,b){if(b===null)return this.isReference&&Ne(`null is not a valid ${this.name}`),0;b.$$||Ne(`Cannot pass "${ko(b)}" as a ${this.name}`),b.$$.ptr||Ne(`Cannot pass deleted object as a pointer of type ${this.name}`),b.$$.ptrType.isConst&&Ne(`Cannot convert argument of type ${b.$$.ptrType.name} to parameter type ${this.name}`);var D=b.$$.ptrType.registeredClass,U=Go(b.$$.ptr,D,this.registeredClass);return U}var J=(v,b,D)=>{if(b===D)return v;if(D.baseClass===void 0)return null;var U=J(v,b,D.baseClass);return U===null?null:D.downcast(U)},j={},$=(v,b)=>{for(b===void 0&&Ne("ptr should not be undefined");v.baseClass;)b=v.upcast(b),v=v.baseClass;return b},Se=(v,b)=>(b=$(v,b),j[b]),Le=(v,b)=>{(!b.ptrType||!b.ptr)&&ye("makeClassHandle requires ptr and ptrType");var D=!!b.smartPtrType,U=!!b.smartPtr;return D!==U&&ye("Both smartPtrType and smartPtr must be specified"),b.count={value:1},dn(Object.create(v,{$$:{value:b,writable:!0}}))};function qe(v){var b=this.getPointee(v);if(!b)return this.destructor(v),null;var D=Se(this.registeredClass,b);if(D!==void 0){if(D.$$.count.value===0)return D.$$.ptr=b,D.$$.smartPtr=v,D.clone();var U=D.clone();return this.destructor(v),U}function B(){return this.isSmartPointer?Le(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:b,smartPtrType:this,smartPtr:v}):Le(this.registeredClass.instancePrototype,{ptrType:this,ptr:v})}var W=this.registeredClass.getActualType(b),X=Ho[W];if(!X)return B.call(this);var Y;this.isConst?Y=X.constPointerType:Y=X.pointerType;var re=J(b,this.registeredClass,Y.registeredClass);return re===null?B.call(this):this.isSmartPointer?Le(Y.registeredClass.instancePrototype,{ptrType:Y,ptr:re,smartPtrType:this,smartPtr:v}):Le(Y.registeredClass.instancePrototype,{ptrType:Y,ptr:re})}var ze=()=>{Object.assign(it.prototype,{getPointee(v){return this.rawGetPointee&&(v=this.rawGetPointee(v)),v},destructor(v){this.rawDestructor?.(v)},readValueFromPointer:ie,fromWireType:qe})};function it(v,b,D,U,B,W,X,Y,re,ue,xe){this.name=v,this.registeredClass=b,this.isReference=D,this.isConst=U,this.isSmartPointer=B,this.pointeeType=W,this.sharingPolicy=X,this.rawGetPointee=Y,this.rawConstructor=re,this.rawShare=ue,this.rawDestructor=xe,!B&&b.baseClass===void 0?U?(this.toWireType=ef,this.destructorFunction=null):(this.toWireType=k,this.destructorFunction=null):this.toWireType=I}var st=(v,b,D)=>{t.hasOwnProperty(v)||ye("Replacing nonexistent public symbol"),t[v].overloadTable!==void 0&&D!==void 0?t[v].overloadTable[D]=b:(t[v]=b,t[v].argCount=D)},je=v=>Wo.get(v),vt=(v,b,D=[],U=!1)=>{var B=je(b),W=B(...D);function X(Y){return v[0]=="p"?Y>>>0:Y}return X(W)},It=(v,b,D=!1)=>(...U)=>vt(v,b,U,D),Tt=(v,b,D=!1)=>{v=Ie(v);function U(){if(v.includes("p"))return It(v,b,D);var W=je(b);return W}var B=U();return typeof B!="function"&&Ne(`unknown function pointer with signature ${v}: ${b}`),B};class zt extends Error{}var Dt=v=>{var b=Zp(v),D=Ie(b);return Ci(b),D},tt=(v,b)=>{var D=[],U={};function B(W){if(!U[W]&&!Ee[W]){if(ke[W]){ke[W].forEach(B);return}D.push(W),U[W]=!0}}throw b.forEach(B),new zt(`${v}: `+D.map(Dt).join([", "]))};function Ht(v,b,D,U,B,W,X,Y,re,ue,xe,Ce,Fe){v>>>=0,b>>>=0,D>>>=0,U>>>=0,B>>>=0,W>>>=0,X>>>=0,Y>>>=0,re>>>=0,ue>>>=0,xe>>>=0,Ce>>>=0,Fe>>>=0,xe=Ie(xe),W=Tt(B,W),Y&&=Tt(X,Y),ue&&=Tt(re,ue),Fe=Tt(Ce,Fe);var Ye=Kh(xe);Zi(Ye,function(){tt(`Cannot construct ${xe} due to unbound types`,[U])}),Re([v,b,D],U?[U]:[],nt=>{nt=nt[0];var ot,mt;U?(ot=nt.registeredClass,mt=ot.instancePrototype):mt=Mr.prototype;var F=Ai(xe,function(...Et){if(Object.getPrototypeOf(this)!==H)throw new Pe(`Use 'new' to construct ${xe}`);if(te.constructor_body===void 0)throw new Pe(`${xe} has no accessible constructor`);var kt=te.constructor_body[Et.length];if(kt===void 0)throw new Pe(`Tried to invoke ctor of ${xe} with invalid number of parameters (${Et.length}) - expected (${Object.keys(te.constructor_body).toString()}) parameters instead!`);return kt.apply(this,Et)}),H=Object.create(mt,{constructor:{value:F}});F.prototype=H;var te=new Qh(xe,F,H,Fe,ot,W,Y,ue);te.baseClass&&(te.baseClass.__derivedClasses??=[],te.baseClass.__derivedClasses.push(te));var le=new it(xe,te,!0,!1,!1),Xe=new it(xe+"*",te,!1,!1,!1),ut=new it(xe+" const*",te,!1,!0,!1);return Ho[v]={pointerType:Xe,constPointerType:ut},st(Ye,F),[le,Xe,ut]})}var Mt=(v,b)=>{for(var D=[],U=0;U>>2>>>0]);return D};function bn(v){for(var b=1;b>>=0,D>>>=0,U>>>=0,B>>>=0,W>>>=0;var X=Mt(b,D);B=Tt(U,B),Re([],[v],Y=>{Y=Y[0];var re=`constructor ${Y.name}`;if(Y.registeredClass.constructor_body===void 0&&(Y.registeredClass.constructor_body=[]),Y.registeredClass.constructor_body[b-1]!==void 0)throw new Pe(`Cannot register multiple constructors with identical number of parameters (${b-1}) for class '${Y.name}'! Overload resolution is currently only performed using the parameter count, not actual type info!`);return Y.registeredClass.constructor_body[b-1]=()=>{tt(`Cannot construct ${Y.name} due to unbound types`,X)},Re([],X,ue=>(ue.splice(1,0,null),Y.registeredClass.constructor_body[b-1]=Ri(re,ue,null,B,W),[])),[]})},En=v=>{v=v.trim();let b=v.indexOf("(");return b===-1?v:v.slice(0,b)},Dn=function(v,b,D,U,B,W,X,Y,re,ue){v>>>=0,b>>>=0,U>>>=0,B>>>=0,W>>>=0,X>>>=0;var xe=Mt(D,U);b=Ie(b),b=En(b),W=Tt(B,W,re),Re([],[v],Ce=>{Ce=Ce[0];var Fe=`${Ce.name}.${b}`;b.startsWith("@@")&&(b=Symbol[b.substring(2)]),Y&&Ce.registeredClass.pureVirtualFunctions.push(b);function Ye(){tt(`Cannot call ${Fe} due to unbound types`,xe)}var nt=Ce.registeredClass.instancePrototype,ot=nt[b];return ot===void 0||ot.overloadTable===void 0&&ot.className!==Ce.name&&ot.argCount===D-2?(Ye.argCount=D-2,Ye.className=Ce.name,nt[b]=Ye):(Er(nt,b,Fe),nt[b].overloadTable[D-2]=Ye),Re([],xe,mt=>{var F=Ri(Fe,mt,Ce,W,X,re);return nt[b].overloadTable===void 0?(F.argCount=D-2,nt[b]=F):nt[b].overloadTable[D-2]=F,[]}),[]})},ln=[],Yt=[0,1,,1,null,1,!0,1,!1,1];function Sr(v){v>>>=0,v>9&&--Yt[v+1]===0&&(Yt[v]=void 0,ln.push(v))}var Ft={toValue:v=>(v||Ne(`Cannot use deleted val. handle = ${v}`),Yt[v]),toHandle:v=>{switch(v){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:{let b=ln.pop()||Yt.length;return Yt[b]=v,Yt[b+1]=1,b}}}},Hp={name:"emscripten::val",fromWireType:v=>{var b=Ft.toValue(v);return Sr(v),b},toWireType:(v,b)=>Ft.toHandle(b),readValueFromPointer:ie,destructorFunction:null};function ly(v){return v>>>=0,me(v,Hp)}var tf=(v,b,D)=>{switch(b){case 1:return D?function(U){return this.fromWireType(P[U>>>0])}:function(U){return this.fromWireType(w[U>>>0])};case 2:return D?function(U){return this.fromWireType(T[U>>>1>>>0])}:function(U){return this.fromWireType(N[U>>>1>>>0])};case 4:return D?function(U){return this.fromWireType(V[U>>>2>>>0])}:function(U){return this.fromWireType(G[U>>>2>>>0])};default:throw new TypeError(`invalid integer width (${b}): ${v}`)}};function cy(v){return v===0?"object":v===1?"number":"string"}function uy(v,b,D,U,B){v>>>=0,b>>>=0,D>>>=0,b=Ie(b);let W=cy(B);switch(W){case"object":{let ue=function(){};ue.values={},me(v,{name:b,constructor:ue,valueType:W,fromWireType:function(xe){return this.constructor.values[xe]},toWireType:(xe,Ce)=>Ce.value,readValueFromPointer:tf(b,D,U),destructorFunction:null}),Zi(b,ue);break}case"number":{var X={};me(v,{name:b,keysMap:X,valueType:W,fromWireType:ue=>ue,toWireType:(ue,xe)=>xe,readValueFromPointer:tf(b,D,U),destructorFunction:null}),Zi(b,X),delete t[b].argCount;break}case"string":{var Y={},re={},X={};me(v,{name:b,valuesMap:Y,reverseMap:re,keysMap:X,valueType:W,fromWireType:function(xe){return this.reverseMap[xe]},toWireType:function(xe,Ce){return this.valuesMap[Ce]},readValueFromPointer:tf(b,D,U),destructorFunction:null}),Zi(b,X),delete t[b].argCount;break}}}var Gp=(v,b)=>{var D=Ee[v];return D===void 0&&Ne(`${b} has unknown type ${Dt(v)}`),D};function hy(v,b,D){v>>>=0,b>>>=0;var U=Gp(v,"enum");switch(b=Ie(b),U.valueType){case"object":{var B=U.constructor,W=Object.create(U.constructor.prototype,{value:{value:D},constructor:{value:Ai(`${U.name}_${b}`,function(){})}});B.values[D]=W,B[b]=W;break}case"number":{U.keysMap[b]=D;break}case"string":{U.valuesMap[b]=D,U.reverseMap[D]=b,U.keysMap[b]=b;break}}}var fy=(v,b)=>{switch(b){case 4:return function(D){return this.fromWireType(Z[D>>>2>>>0])};case 8:return function(D){return this.fromWireType(K[D>>>3>>>0])};default:throw new TypeError(`invalid float width (${b}): ${v}`)}},dy=function(v,b,D){v>>>=0,b>>>=0,D>>>=0,b=Ie(b),me(v,{name:b,fromWireType:U=>U,toWireType:(U,B)=>B,readValueFromPointer:fy(b,D),destructorFunction:null})};function py(v,b,D,U,B,W,X,Y){v>>>=0,D>>>=0,U>>>=0,B>>>=0,W>>>=0;var re=Mt(b,D);v=Ie(v),v=En(v),B=Tt(U,B,X),Zi(v,function(){tt(`Cannot call ${v} due to unbound types`,re)},b-1),Re([],re,ue=>{var xe=[ue[0],null].concat(ue.slice(1));return st(v,Ri(v,xe,null,B,W,X),b-1),[]})}var my=function(v,b,D,U,B){v>>>=0,b>>>=0,D>>>=0,b=Ie(b);let W=U===0,X=re=>re;if(W){var Y=32-8*D;X=re=>re<>>Y,B=X(B)}me(v,{name:b,fromWireType:X,toWireType:(re,ue)=>ue,readValueFromPointer:Ae(b,D,U!==0),destructorFunction:null})},gy=(v,b,D)=>{let U=(B,W)=>{let X=0;return{next(){if(X>=B)return{done:!0};let Y=X;return X++,{value:W(Y),done:!1}},[Symbol.iterator](){return this}}};v[Symbol.iterator]||(v[Symbol.iterator]=function(){let B=this[b]();return U(B,W=>this[D](W))})},_y=function(v,b,D,U){v>>>=0,b>>>=0,D>>>=0,U>>>=0,D=Ie(D),U=Ie(U),Re([],[v,b],B=>{let W=B[0];return gy(W.registeredClass.instancePrototype,D,U),[]})};function yy(v,b,D){v>>>=0,D>>>=0;var U=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array],B=U[b];function W(X){var Y=G[X>>>2>>>0],re=G[X+4>>>2>>>0];return new B(P.buffer,re,Y)}D=Ie(D),me(v,{name:D,fromWireType:W,readValueFromPointer:W},{ignoreDuplicateRegistrations:!0})}var xy=Object.assign({optional:!0},Hp);function vy(v,b){v>>>=0,b>>>=0,me(v,xy)}var by=(v,b,D,U)=>{if(D>>>=0,!(U>0))return 0;for(var B=D,W=D+U-1,X=0;X=W)break;b[D++>>>0]=Y}else if(Y<=2047){if(D+1>=W)break;b[D++>>>0]=192|Y>>6,b[D++>>>0]=128|Y&63}else if(Y<=65535){if(D+2>=W)break;b[D++>>>0]=224|Y>>12,b[D++>>>0]=128|Y>>6&63,b[D++>>>0]=128|Y&63}else{if(D+3>=W)break;b[D++>>>0]=240|Y>>18,b[D++>>>0]=128|Y>>12&63,b[D++>>>0]=128|Y>>6&63,b[D++>>>0]=128|Y&63,X++}}return b[D>>>0]=0,D-B},My=(v,b,D)=>by(v,w,b,D),Ey=v=>{for(var b=0,D=0;D=55296&&U<=57343?(b+=4,++D):b+=3}return b},kp=globalThis.TextDecoder&&new TextDecoder,Wp=(v,b,D,U)=>{var B=b+D;if(U)return B;for(;v[b]&&!(b>=B);)++b;return b},Sy=(v,b=0,D,U)=>{b>>>=0;var B=Wp(v,b,D,U);if(B-b>16&&v.buffer&&kp)return kp.decode(v.subarray(b,B));for(var W="";b>10,56320|ue&1023)}}return W},wy=(v,b,D)=>(v>>>=0,v?Sy(w,v,b,D):"");function Ty(v,b){v>>>=0,b>>>=0,b=Ie(b);var D=!0;me(v,{name:b,fromWireType(U){var B=G[U>>>2>>>0],W=U+4,X;if(D)X=wy(W,B,!0);else{X="";for(var Y=0;Y>>0])}return Ci(U),X},toWireType(U,B){B instanceof ArrayBuffer&&(B=new Uint8Array(B));var W,X=typeof B=="string";X||ArrayBuffer.isView(B)&&B.BYTES_PER_ELEMENT==1||Ne("Cannot pass non-string to std::string"),D&&X?W=Ey(B):W=B.length;var Y=of(4+W+1),re=Y+4;if(G[Y>>>2>>>0]=W,X)if(D)My(B,re,W+1);else for(var ue=0;ue255&&(Ci(Y),Ne("String has UTF-16 code units that do not fit in 8 bits")),w[re+ue>>>0]=xe}else w.set(B,re>>>0);return U!==null&&U.push(Ci,Y),Y},readValueFromPointer:ie,destructorFunction(U){Ci(U)}})}var Xp=globalThis.TextDecoder?new TextDecoder("utf-16le"):void 0,Ay=(v,b,D)=>{var U=v>>>1,B=Wp(N,U,b/2,D);if(B-U>16&&Xp)return Xp.decode(N.subarray(U>>>0,B>>>0));for(var W="",X=U;X>>0];W+=String.fromCharCode(Y)}return W},Ry=(v,b,D)=>{if(D??=2147483647,D<2)return 0;D-=2;for(var U=b,B=D>>1>>>0]=X,b+=2}return T[b>>>1>>>0]=0,b-U},Cy=v=>v.length*2,Py=(v,b,D)=>{for(var U="",B=v>>>2,W=0;!(W>=b/4);W++){var X=G[B+W>>>0];if(!X&&!D)break;U+=String.fromCodePoint(X)}return U},Iy=(v,b,D)=>{if(b>>>=0,D??=2147483647,D<4)return 0;for(var U=b,B=U+D-4,W=0;W65535&&W++,V[b>>>2>>>0]=X,b+=4,b+4>B)break}return V[b>>>2>>>0]=0,b-U},Dy=v=>{for(var b=0,D=0;D65535&&D++,b+=4}return b};function Ly(v,b,D){v>>>=0,b>>>=0,D>>>=0,D=Ie(D);var U,B,W;b===2?(U=Ay,B=Ry,W=Cy):(U=Py,B=Iy,W=Dy),me(v,{name:D,fromWireType:X=>{var Y=G[X>>>2>>>0],re=U(X+4,Y*b,!0);return Ci(X),re},toWireType:(X,Y)=>{typeof Y!="string"&&Ne(`Cannot pass non-string to C++ string type ${D}`);var re=W(Y),ue=of(4+re+b);return G[ue>>>2>>>0]=re/b,B(Y,ue+4,re+b),X!==null&&X.push(Ci,ue),ue},readValueFromPointer:ie,destructorFunction(X){Ci(X)}})}function Uy(v,b,D,U,B,W){v>>>=0,b>>>=0,D>>>=0,U>>>=0,B>>>=0,W>>>=0,ee[v]={name:Ie(b),rawConstructor:Tt(D,U),rawDestructor:Tt(B,W),fields:[]}}function Ny(v,b,D,U,B,W,X,Y,re,ue){v>>>=0,b>>>=0,D>>>=0,U>>>=0,B>>>=0,W>>>=0,X>>>=0,Y>>>=0,re>>>=0,ue>>>=0,ee[v].fields.push({fieldName:Ie(b),getterReturnType:D,getter:Tt(U,B),getterContext:W,setterArgumentType:X,setter:Tt(Y,re),setterContext:ue})}var Fy=function(v,b){v>>>=0,b>>>=0,b=Ie(b),me(v,{isVoid:!0,name:b,fromWireType:()=>{},toWireType:(D,U)=>{}})};function Oy(v,b){v>>>=0,b>>>=0,v=Ft.toValue(v),b=Ft.toValue(b),v.set(b)}var nf=[],By=v=>{var b=nf.length;return nf.push(v),b},zy=(v,b)=>{for(var D=new Array(v),U=0;U>>2>>>0],`parameter ${U}`);return D},Vy=(v,b,D)=>{var U=[],B=v(U,D);return U.length&&(G[b>>>2>>>0]=Ft.toHandle(U)),B},Hy={},$p=v=>{var b=Hy[v];return b===void 0?Ie(v):b},Gy=function(v,b,D){b>>>=0;var U=8,[B,...W]=zy(v,b),X=B.toWireType.bind(B),Y=W.map(Ce=>Ce.readValueFromPointer.bind(Ce));v--;var re=new Array(v),ue=(Ce,Fe,Ye,nt)=>{for(var ot=0,mt=0;mtCe.name)}) => ${B.name}>`;return By(Ai(xe,ue))};function ky(v,b){return v>>>=0,b>>>=0,v=Ft.toValue(v),b=Ft.toValue(b),v==b}function Wy(v,b){return v>>>=0,b>>>=0,v=Ft.toValue(v),b=Ft.toValue(b),Ft.toHandle(v[b])}function Xy(v){v>>>=0,v>9&&(Yt[v+1]+=1)}function $y(v,b,D,U,B){return v>>>=0,b>>>=0,D>>>=0,U>>>=0,B>>>=0,nf[v](b,D,U,B)}function qy(v){return v>>>=0,Ft.toHandle($p(v))}function Yy(){return Ft.toHandle({})}function Zy(v){v>>>=0;var b=Ft.toValue(v);de(b),Sr(v)}function Jy(v,b,D){v>>>=0,b>>>=0,D>>>=0,v=Ft.toValue(v),b=Ft.toValue(b),D=Ft.toValue(D),v[b]=D}var jy=()=>4294901760,Ky=(v,b)=>Math.ceil(v/b)*b,Qy=v=>{var b=bc.buffer.byteLength,D=(v-b+65535)/65536|0;try{return bc.grow(D),Te(),1}catch{}};function ex(v){v>>>=0;var b=w.length,D=jy();if(v>D)return!1;for(var U=1;U<=4;U*=2){var B=b*(1+.2/U);B=Math.min(B,v+100663296);var W=Math.min(D,Ky(Math.max(v,B),65536)),X=Qy(W);if(X)return!0}return!1}var tx=(v,b)=>{if(wr)for(var D=v;D(wr||(wr=new WeakMap,tx(0,Wo.length)),wr.get(v)||0),rf=[],ix=()=>rf.length?rf.pop():Wo.grow(1),sf=(v,b)=>Wo.set(v,b),qp=v=>{let b=v.length;return[b%128|128,b>>7,...v]},rx={i:127,p:127,j:126,f:125,d:124,e:111},Yp=v=>qp(Array.from(v,b=>{var D=rx[b];return D})),sx=(v,b)=>{var D=Uint8Array.of(0,97,115,109,1,0,0,0,1,...qp([1,96,...Yp(b.slice(1)),...Yp(b[0]==="v"?"":b[0])]),2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0),U=new WebAssembly.Module(D),B=new WebAssembly.Instance(U,{e:{f:v}}),W=B.exports.f;return W},Tr=(v,b)=>{var D=nx(v);if(D)return D;var U=ix();try{sf(U,v)}catch(W){if(!(W instanceof TypeError))throw W;var B=sx(v,b);sf(U,B)}return wr.set(v,U),U},Ar=v=>{wr.delete(je(v)),sf(v,null),rf.push(v)};if(xc(),ze(),t.noExitRuntime&&(be=t.noExitRuntime),t.print&&(p=t.print),t.printErr&&(M=t.printErr),t.wasmBinary&&(x=t.wasmBinary),t.arguments&&(l=t.arguments),t.thisProgram&&(c=t.thisProgram),t.preInit)for(typeof t.preInit=="function"&&(t.preInit=[t.preInit]);t.preInit.length>0;)t.preInit.shift()();t.addFunction=Tr,t.removeFunction=Ar;var Zp,of,Ci,ox,ax,bc,Wo;function lx(v){Zp=v.K,of=v.M,Ci=v.N,ox=bc=v.I,ax=Wo=v.L}var cx={l:A,C:q,q:rt,z:We,G:Me,j:Ht,i:Gt,a:Dn,E:ly,x:uy,d:hy,y:dy,c:py,p:my,m:_y,h:yy,n:vy,F:Ty,w:Ly,r:Uy,k:Ny,H:Fy,u:Oy,g:Gy,b:Sr,o:ky,B:Wy,t:Xy,f:$y,s:qy,A:Yy,e:Zy,v:Jy,D:ex};function ux(v){v=Object.assign({},v);var b=U=>B=>U(B)>>>0,D=U=>()=>U()>>>0;return v.K=b(v.K),v.M=b(v.M),v._emscripten_stack_alloc=b(v._emscripten_stack_alloc),v.emscripten_stack_get_current=D(v.emscripten_stack_get_current),v}function hx(){Oe();function v(){t.calledRun=!0,!y&&(Ge(),S?.(t),t.onRuntimeInitialized?.(),dt())}t.setStatus?(t.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>t.setStatus(""),1),v()},1)):v()}var Rr;return Rr=await xt(),hx(),ne?e=t:e=new Promise((v,b)=>{S=v,R=b}),e}var Jp=px;var Pn={};dx(Pn,{ACESFilmicToneMapping:()=>Id,AddEquation:()=>zi,AddOperation:()=>Ad,AdditiveAnimationBlendMode:()=>Ph,AdditiveBlending:()=>xh,AgXToneMapping:()=>Ld,AlphaFormat:()=>Ah,AlwaysCompare:()=>Yd,AlwaysDepth:()=>vl,AlwaysStencilFunc:()=>hu,AmbientLight:()=>al,AnimationAction:()=>yl,AnimationClip:()=>xr,AnimationLoader:()=>Pu,AnimationMixer:()=>ku,AnimationObjectGroup:()=>Gu,AnimationUtils:()=>Cu,ArcCurve:()=>Ia,ArrayCamera:()=>pl,ArrowHelper:()=>fh,AttachedBindMode:()=>uu,Audio:()=>gl,AudioAnalyser:()=>Hu,AudioContext:()=>vo,AudioListener:()=>zu,AudioLoader:()=>Ou,AxesHelper:()=>dh,BackSide:()=>xn,BasicDepthPacking:()=>zd,BasicShadowMap:()=>ag,BatchedMesh:()=>Sa,Bone:()=>no,BooleanKeyframeTrack:()=>xi,Box2:()=>ls,Box3:()=>Ct,Box3Helper:()=>uh,BoxGeometry:()=>Zn,BoxHelper:()=>ch,BufferAttribute:()=>ht,BufferGeometry:()=>et,BufferGeometryLoader:()=>dl,ByteType:()=>Eh,Cache:()=>si,Camera:()=>Zr,CameraHelper:()=>lh,CanvasTexture:()=>Au,CapsuleGeometry:()=>ki,CatmullRomCurve3:()=>es,CineonToneMapping:()=>Pd,CircleGeometry:()=>Ra,ClampToEdgeWrapping:()=>Vn,Clock:()=>ml,Color:()=>Be,ColorKeyframeTrack:()=>_o,ColorManagement:()=>wt,CompressedArrayTexture:()=>wu,CompressedCubeTexture:()=>Tu,CompressedTexture:()=>Kr,CompressedTextureLoader:()=>Iu,ConeGeometry:()=>dr,ConstantAlphaFactor:()=>Sd,ConstantColorFactor:()=>Md,Controls:()=>mh,CubeCamera:()=>da,CubeReflectionMapping:()=>Ei,CubeRefractionMapping:()=>$i,CubeTexture:()=>hr,CubeTextureLoader:()=>Du,CubeUVReflectionMapping:()=>cs,CubicBezierCurve:()=>oo,CubicBezierCurve3:()=>ts,CubicInterpolant:()=>Qa,CullFaceBack:()=>_h,CullFaceFront:()=>od,CullFaceFrontBack:()=>og,CullFaceNone:()=>sd,Curve:()=>On,CurvePath:()=>La,CustomBlending:()=>ld,CustomToneMapping:()=>Dd,CylinderGeometry:()=>_i,Cylindrical:()=>Ku,Data3DTexture:()=>qr,DataArrayTexture:()=>$r,DataTexture:()=>Gn,DataTextureLoader:()=>Lu,DataUtils:()=>pu,DecrementStencilOp:()=>bg,DecrementWrapStencilOp:()=>Eg,DefaultLoadingManager:()=>np,DepthFormat:()=>kr,DepthStencilFormat:()=>ps,DepthTexture:()=>ro,DetachedBindMode:()=>Nd,DirectionalLight:()=>ol,DirectionalLightHelper:()=>ah,DiscreteInterpolant:()=>el,DodecahedronGeometry:()=>Ca,DoubleSide:()=>ci,DstAlphaFactor:()=>_d,DstColorFactor:()=>xd,DynamicCopyUsage:()=>Bg,DynamicDrawUsage:()=>Dg,DynamicReadUsage:()=>Ng,EdgesGeometry:()=>Pa,EllipseCurve:()=>Qr,EqualCompare:()=>Wd,EqualDepth:()=>Ml,EqualStencilFunc:()=>Ag,EquirectangularReflectionMapping:()=>Mo,EquirectangularRefractionMapping:()=>Eo,Euler:()=>yn,EventDispatcher:()=>kn,ExternalTexture:()=>so,ExtrudeGeometry:()=>Oa,FileLoader:()=>Jn,Float16BufferAttribute:()=>vu,Float32BufferAttribute:()=>De,FloatType:()=>Rn,Fog:()=>ga,FogExp2:()=>ma,FramebufferTexture:()=>Su,FrontSide:()=>gi,Frustum:()=>Gi,FrustumArray:()=>Ea,GLBufferAttribute:()=>Yu,GLSL1:()=>Vg,GLSL3:()=>Dh,GreaterCompare:()=>Xd,GreaterDepth:()=>Sl,GreaterEqualCompare:()=>qd,GreaterEqualDepth:()=>El,GreaterEqualStencilFunc:()=>Ig,GreaterStencilFunc:()=>Cg,GridHelper:()=>sh,Group:()=>Oi,HalfFloatType:()=>fs,HemisphereLight:()=>nl,HemisphereLightHelper:()=>rh,IcosahedronGeometry:()=>Ba,ImageBitmapLoader:()=>Fu,ImageLoader:()=>vr,ImageUtils:()=>fa,IncrementStencilOp:()=>vg,IncrementWrapStencilOp:()=>Mg,InstancedBufferAttribute:()=>Hi,InstancedBufferGeometry:()=>fl,InstancedInterleavedBuffer:()=>qu,InstancedMesh:()=>Ma,Int16BufferAttribute:()=>yu,Int32BufferAttribute:()=>xu,Int8BufferAttribute:()=>mu,IntType:()=>Al,InterleavedBuffer:()=>jr,InterleavedBufferAttribute:()=>fr,Interpolant:()=>mr,InterpolateDiscrete:()=>$s,InterpolateLinear:()=>ha,InterpolateSmooth:()=>sa,InterpolationSamplingMode:()=>kg,InterpolationSamplingType:()=>Gg,InvertStencilOp:()=>Sg,KeepStencilOp:()=>sr,KeyframeTrack:()=>Cn,LOD:()=>xa,LatheGeometry:()=>rs,Layers:()=>Yr,LessCompare:()=>kd,LessDepth:()=>bl,LessEqualCompare:()=>Ih,LessEqualDepth:()=>cr,LessEqualStencilFunc:()=>Rg,LessStencilFunc:()=>Tg,Light:()=>ai,LightProbe:()=>ul,Line:()=>oi,Line3:()=>eh,LineBasicMaterial:()=>hn,LineCurve:()=>ao,LineCurve3:()=>Da,LineDashedMaterial:()=>Ka,LineLoop:()=>wa,LineSegments:()=>$n,LinearFilter:()=>tn,LinearInterpolant:()=>go,LinearMipMapLinearFilter:()=>hg,LinearMipMapNearestFilter:()=>ug,LinearMipmapLinearFilter:()=>ui,LinearMipmapNearestFilter:()=>So,LinearSRGBColorSpace:()=>ur,LinearToneMapping:()=>Rd,LinearTransfer:()=>Ys,Loader:()=>fn,LoaderUtils:()=>xo,LoadingManager:()=>yo,LoopOnce:()=>Fd,LoopPingPong:()=>Bd,LoopRepeat:()=>Od,MOUSE:()=>rg,Material:()=>rn,MaterialLoader:()=>hl,MathUtils:()=>sn,Matrix2:()=>Qu,Matrix3:()=>pt,Matrix4:()=>Qe,MaxEquation:()=>fd,Mesh:()=>Xt,MeshBasicMaterial:()=>Xn,MeshDepthMaterial:()=>po,MeshDistanceMaterial:()=>mo,MeshLambertMaterial:()=>Ja,MeshMatcapMaterial:()=>ja,MeshNormalMaterial:()=>Za,MeshPhongMaterial:()=>qa,MeshPhysicalMaterial:()=>$a,MeshStandardMaterial:()=>fo,MeshToonMaterial:()=>Ya,MinEquation:()=>hd,MirroredRepeatWrapping:()=>Xs,MixOperation:()=>Td,MultiplyBlending:()=>bh,MultiplyOperation:()=>bo,NearestFilter:()=>un,NearestMipMapLinearFilter:()=>cg,NearestMipMapNearestFilter:()=>lg,NearestMipmapLinearFilter:()=>us,NearestMipmapNearestFilter:()=>Mh,NeutralToneMapping:()=>Ud,NeverCompare:()=>Gd,NeverDepth:()=>xl,NeverStencilFunc:()=>wg,NoBlending:()=>bi,NoColorSpace:()=>wi,NoToneMapping:()=>Mi,NormalAnimationBlendMode:()=>ac,NormalBlending:()=>lr,NotEqualCompare:()=>$d,NotEqualDepth:()=>wl,NotEqualStencilFunc:()=>Pg,NumberKeyframeTrack:()=>gr,Object3D:()=>bt,ObjectLoader:()=>Nu,ObjectSpaceNormalMap:()=>Hd,OctahedronGeometry:()=>ho,OneFactor:()=>pd,OneMinusConstantAlphaFactor:()=>wd,OneMinusConstantColorFactor:()=>Ed,OneMinusDstAlphaFactor:()=>yd,OneMinusDstColorFactor:()=>vd,OneMinusSrcAlphaFactor:()=>ua,OneMinusSrcColorFactor:()=>gd,OrthographicCamera:()=>as,PCFShadowMap:()=>yh,PCFSoftShadowMap:()=>ad,PMREMGenerator:()=>cc,Path:()=>ns,PerspectiveCamera:()=>en,Plane:()=>ni,PlaneGeometry:()=>Xi,PlaneHelper:()=>hh,PointLight:()=>sl,PointLightHelper:()=>ih,Points:()=>Ta,PointsMaterial:()=>io,PolarGridHelper:()=>oh,PolyhedronGeometry:()=>Wi,PositionalAudio:()=>Vu,PropertyBinding:()=>Lt,PropertyMixer:()=>_l,QuadraticBezierCurve:()=>lo,QuadraticBezierCurve3:()=>pr,Quaternion:()=>Vt,QuaternionKeyframeTrack:()=>_r,QuaternionLinearInterpolant:()=>tl,RED_GREEN_RGTC2_Format:()=>sc,RED_RGTC1_Format:()=>ic,REVISION:()=>rd,RGBADepthPacking:()=>Vd,RGBAFormat:()=>_n,RGBAIntegerFormat:()=>Dl,RGBA_ASTC_10x10_Format:()=>jl,RGBA_ASTC_10x5_Format:()=>Yl,RGBA_ASTC_10x6_Format:()=>Zl,RGBA_ASTC_10x8_Format:()=>Jl,RGBA_ASTC_12x10_Format:()=>Kl,RGBA_ASTC_12x12_Format:()=>Ql,RGBA_ASTC_4x4_Format:()=>Vl,RGBA_ASTC_5x4_Format:()=>Hl,RGBA_ASTC_5x5_Format:()=>Gl,RGBA_ASTC_6x5_Format:()=>kl,RGBA_ASTC_6x6_Format:()=>Wl,RGBA_ASTC_8x5_Format:()=>Xl,RGBA_ASTC_8x6_Format:()=>$l,RGBA_ASTC_8x8_Format:()=>ql,RGBA_BPTC_Format:()=>ec,RGBA_ETC2_EAC_Format:()=>zl,RGBA_PVRTC_2BPPV1_Format:()=>Fl,RGBA_PVRTC_4BPPV1_Format:()=>Nl,RGBA_S3TC_DXT1_Format:()=>Ao,RGBA_S3TC_DXT3_Format:()=>Ro,RGBA_S3TC_DXT5_Format:()=>Co,RGBDepthPacking:()=>gg,RGBFormat:()=>Rh,RGBIntegerFormat:()=>fg,RGB_BPTC_SIGNED_Format:()=>tc,RGB_BPTC_UNSIGNED_Format:()=>nc,RGB_ETC1_Format:()=>Ol,RGB_ETC2_Format:()=>Bl,RGB_PVRTC_2BPPV1_Format:()=>Ul,RGB_PVRTC_4BPPV1_Format:()=>Ll,RGB_S3TC_DXT1_Format:()=>To,RGDepthPacking:()=>_g,RGFormat:()=>Ch,RGIntegerFormat:()=>Il,RawShaderMaterial:()=>Xa,Ray:()=>Vi,Raycaster:()=>Zu,RectAreaLight:()=>ll,RedFormat:()=>Pl,RedIntegerFormat:()=>wo,ReinhardToneMapping:()=>Cd,RenderTarget:()=>Ks,RenderTarget3D:()=>Wu,RepeatWrapping:()=>Ws,ReplaceStencilOp:()=>xg,ReverseSubtractEquation:()=>ud,RingGeometry:()=>za,SIGNED_RED_GREEN_RGTC2_Format:()=>oc,SIGNED_RED_RGTC1_Format:()=>rc,SRGBColorSpace:()=>wn,SRGBTransfer:()=>Ut,Scene:()=>_a,ShaderChunk:()=>_t,ShaderLib:()=>hi,ShaderMaterial:()=>Fn,ShadowMaterial:()=>Wa,Shape:()=>mi,ShapeGeometry:()=>Va,ShapePath:()=>ph,ShapeUtils:()=>An,ShortType:()=>Sh,Skeleton:()=>ba,SkeletonHelper:()=>nh,SkinnedMesh:()=>va,Source:()=>ri,Sphere:()=>nn,SphereGeometry:()=>yi,Spherical:()=>ju,SphericalHarmonics3:()=>cl,SplineCurve:()=>co,SpotLight:()=>rl,SpotLightHelper:()=>th,Sprite:()=>ya,SpriteMaterial:()=>to,SrcAlphaFactor:()=>ca,SrcAlphaSaturateFactor:()=>bd,SrcColorFactor:()=>md,StaticCopyUsage:()=>Og,StaticDrawUsage:()=>Zs,StaticReadUsage:()=>Ug,StereoCamera:()=>Bu,StreamCopyUsage:()=>zg,StreamDrawUsage:()=>Lg,StreamReadUsage:()=>Fg,StringKeyframeTrack:()=>vi,SubtractEquation:()=>cd,SubtractiveBlending:()=>vh,TOUCH:()=>sg,TangentSpaceNormalMap:()=>qi,TetrahedronGeometry:()=>Ha,Texture:()=>Kt,TextureLoader:()=>Uu,TextureUtils:()=>gh,Timer:()=>Ju,TimestampQuery:()=>Hg,TorusGeometry:()=>ss,TorusKnotGeometry:()=>Ga,Triangle:()=>ii,TriangleFanDrawMode:()=>mg,TriangleStripDrawMode:()=>pg,TrianglesDrawMode:()=>dg,TubeGeometry:()=>os,UVMapping:()=>Tl,Uint16BufferAttribute:()=>Qs,Uint32BufferAttribute:()=>eo,Uint8BufferAttribute:()=>gu,Uint8ClampedBufferAttribute:()=>_u,Uniform:()=>Xu,UniformsGroup:()=>$u,UniformsLib:()=>Ue,UniformsUtils:()=>Qd,UnsignedByteType:()=>jn,UnsignedInt101111Type:()=>Th,UnsignedInt248Type:()=>ds,UnsignedInt5999Type:()=>wh,UnsignedIntType:()=>Si,UnsignedShort4444Type:()=>Rl,UnsignedShort5551Type:()=>Cl,UnsignedShortType:()=>hs,VSMShadowMap:()=>li,Vector2:()=>ce,Vector3:()=>C,Vector4:()=>At,VectorKeyframeTrack:()=>yr,VideoFrameTexture:()=>Eu,VideoTexture:()=>Aa,WebGL3DRenderTarget:()=>du,WebGLArrayRenderTarget:()=>fu,WebGLCoordinateSystem:()=>Nn,WebGLCubeRenderTarget:()=>pa,WebGLRenderTarget:()=>Wn,WebGLRenderer:()=>xp,WebGLUtils:()=>R0,WebGPUCoordinateSystem:()=>Wr,WebXRController:()=>Jr,WireframeGeometry:()=>ka,WrapAroundEnding:()=>qs,ZeroCurvatureEnding:()=>or,ZeroFactor:()=>dd,ZeroSlopeEnding:()=>ar,ZeroStencilOp:()=>yg,createCanvasElement:()=>jd});var rd="180",rg={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},sg={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},sd=0,_h=1,od=2,og=3,ag=0,yh=1,ad=2,li=3,gi=0,xn=1,ci=2,bi=0,lr=1,xh=2,vh=3,bh=4,ld=5,zi=100,cd=101,ud=102,hd=103,fd=104,dd=200,pd=201,md=202,gd=203,ca=204,ua=205,_d=206,yd=207,xd=208,vd=209,bd=210,Md=211,Ed=212,Sd=213,wd=214,xl=0,vl=1,bl=2,cr=3,Ml=4,El=5,Sl=6,wl=7,bo=0,Td=1,Ad=2,Mi=0,Rd=1,Cd=2,Pd=3,Id=4,Dd=5,Ld=6,Ud=7,uu="attached",Nd="detached",Tl=300,Ei=301,$i=302,Mo=303,Eo=304,cs=306,Ws=1e3,Vn=1001,Xs=1002,un=1003,Mh=1004,lg=1004,us=1005,cg=1005,tn=1006,So=1007,ug=1007,ui=1008,hg=1008,jn=1009,Eh=1010,Sh=1011,hs=1012,Al=1013,Si=1014,Rn=1015,fs=1016,Rl=1017,Cl=1018,ds=1020,wh=35902,Th=35899,Ah=1021,Rh=1022,_n=1023,kr=1026,ps=1027,Pl=1028,wo=1029,Ch=1030,Il=1031,fg=1032,Dl=1033,To=33776,Ao=33777,Ro=33778,Co=33779,Ll=35840,Ul=35841,Nl=35842,Fl=35843,Ol=36196,Bl=37492,zl=37496,Vl=37808,Hl=37809,Gl=37810,kl=37811,Wl=37812,Xl=37813,$l=37814,ql=37815,Yl=37816,Zl=37817,Jl=37818,jl=37819,Kl=37820,Ql=37821,ec=36492,tc=36494,nc=36495,ic=36283,rc=36284,sc=36285,oc=36286,Fd=2200,Od=2201,Bd=2202,$s=2300,ha=2301,sa=2302,or=2400,ar=2401,qs=2402,ac=2500,Ph=2501,dg=0,pg=1,mg=2,zd=3200,Vd=3201,gg=3202,_g=3203,qi=0,Hd=1,wi="",wn="srgb",ur="srgb-linear",Ys="linear",Ut="srgb",yg=0,sr=7680,xg=7681,vg=7682,bg=7683,Mg=34055,Eg=34056,Sg=5386,wg=512,Tg=513,Ag=514,Rg=515,Cg=516,Pg=517,Ig=518,hu=519,Gd=512,kd=513,Wd=514,Ih=515,Xd=516,$d=517,qd=518,Yd=519,Zs=35044,Dg=35048,Lg=35040,Ug=35045,Ng=35049,Fg=35041,Og=35046,Bg=35050,zg=35042,Vg="100",Dh="300 es",Nn=2e3,Wr=2001,Hg={COMPUTE:"compute",RENDER:"render"},Gg={PERSPECTIVE:"perspective",LINEAR:"linear",FLAT:"flat"},kg={NORMAL:"normal",CENTROID:"centroid",SAMPLE:"sample",FIRST:"first",EITHER:"either"},kn=class{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});let n=this._listeners;n[e]===void 0&&(n[e]=[]),n[e].indexOf(t)===-1&&n[e].push(t)}hasEventListener(e,t){let n=this._listeners;return n===void 0?!1:n[e]!==void 0&&n[e].indexOf(t)!==-1}removeEventListener(e,t){let n=this._listeners;if(n===void 0)return;let i=n[e];if(i!==void 0){let s=i.indexOf(t);s!==-1&&i.splice(s,1)}}dispatchEvent(e){let t=this._listeners;if(t===void 0)return;let n=t[e.type];if(n!==void 0){e.target=this;let i=n.slice(0);for(let s=0,o=i.length;s>8&255]+pn[r>>16&255]+pn[r>>24&255]+"-"+pn[e&255]+pn[e>>8&255]+"-"+pn[e>>16&15|64]+pn[e>>24&255]+"-"+pn[t&63|128]+pn[t>>8&255]+"-"+pn[t>>16&255]+pn[t>>24&255]+pn[n&255]+pn[n>>8&255]+pn[n>>16&255]+pn[n>>24&255]).toLowerCase()}function at(r,e,t){return Math.max(e,Math.min(t,r))}function Zd(r,e){return(r%e+e)%e}function mx(r,e,t,n,i){return n+(r-e)*(i-n)/(t-e)}function gx(r,e,t){return r!==e?(t-r)/(e-r):0}function oa(r,e,t){return(1-t)*r+t*e}function _x(r,e,t,n){return oa(r,e,1-Math.exp(-t*n))}function yx(r,e=1){return e-Math.abs(Zd(r,e*2)-e)}function xx(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*(3-2*r))}function vx(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*r*(r*(r*6-15)+10))}function bx(r,e){return r+Math.floor(Math.random()*(e-r+1))}function Mx(r,e){return r+Math.random()*(e-r)}function Ex(r){return r*(.5-Math.random())}function Sx(r){r!==void 0&&(jp=r);let e=jp+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function wx(r){return r*Gr}function Tx(r){return r*Xr}function Ax(r){return(r&r-1)===0&&r!==0}function Rx(r){return Math.pow(2,Math.ceil(Math.log(r)/Math.LN2))}function Cx(r){return Math.pow(2,Math.floor(Math.log(r)/Math.LN2))}function Px(r,e,t,n,i){let s=Math.cos,o=Math.sin,a=s(t/2),l=o(t/2),c=s((e+n)/2),h=o((e+n)/2),u=s((e-n)/2),f=o((e-n)/2),d=s((n-e)/2),m=o((n-e)/2);switch(i){case"XYX":r.set(a*h,l*u,l*f,a*c);break;case"YZY":r.set(l*f,a*h,l*u,a*c);break;case"ZXZ":r.set(l*u,l*f,a*h,a*c);break;case"XZX":r.set(a*h,l*m,l*d,a*c);break;case"YXY":r.set(l*d,a*h,l*m,a*c);break;case"ZYZ":r.set(l*m,l*d,a*h,a*c);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function Tn(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return r/4294967295;case Uint16Array:return r/65535;case Uint8Array:return r/255;case Int32Array:return Math.max(r/2147483647,-1);case Int16Array:return Math.max(r/32767,-1);case Int8Array:return Math.max(r/127,-1);default:throw new Error("Invalid component type.")}}function gt(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return Math.round(r*4294967295);case Uint16Array:return Math.round(r*65535);case Uint8Array:return Math.round(r*255);case Int32Array:return Math.round(r*2147483647);case Int16Array:return Math.round(r*32767);case Int8Array:return Math.round(r*127);default:throw new Error("Invalid component type.")}}var sn={DEG2RAD:Gr,RAD2DEG:Xr,generateUUID:Hn,clamp:at,euclideanModulo:Zd,mapLinear:mx,inverseLerp:gx,lerp:oa,damp:_x,pingpong:yx,smoothstep:xx,smootherstep:vx,randInt:bx,randFloat:Mx,randFloatSpread:Ex,seededRandom:Sx,degToRad:wx,radToDeg:Tx,isPowerOfTwo:Ax,ceilPowerOfTwo:Rx,floorPowerOfTwo:Cx,setQuaternionFromProperEuler:Px,normalize:gt,denormalize:Tn},ce=class r{constructor(e=0,t=0){r.prototype.isVector2=!0,this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){let t=this.x,n=this.y,i=e.elements;return this.x=i[0]*t+i[3]*n+i[6],this.y=i[1]*t+i[4]*n+i[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=at(this.x,e.x,t.x),this.y=at(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=at(this.x,e,t),this.y=at(this.y,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(at(n,e,t))}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(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.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(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let n=this.dot(e)/t;return Math.acos(at(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,n=this.y-e.y;return t*t+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){let n=Math.cos(t),i=Math.sin(t),s=this.x-e.x,o=this.y-e.y;return this.x=s*n-o*i+e.x,this.y=s*i+o*n+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}},Vt=class{constructor(e=0,t=0,n=0,i=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=n,this._w=i}static slerpFlat(e,t,n,i,s,o,a){let l=n[i+0],c=n[i+1],h=n[i+2],u=n[i+3],f=s[o+0],d=s[o+1],m=s[o+2],_=s[o+3];if(a===0){e[t+0]=l,e[t+1]=c,e[t+2]=h,e[t+3]=u;return}if(a===1){e[t+0]=f,e[t+1]=d,e[t+2]=m,e[t+3]=_;return}if(u!==_||l!==f||c!==d||h!==m){let g=1-a,p=l*f+c*d+h*m+u*_,M=p>=0?1:-1,x=1-p*p;if(x>Number.EPSILON){let E=Math.sqrt(x),S=Math.atan2(E,p*M);g=Math.sin(g*S)/E,a=Math.sin(a*S)/E}let y=a*M;if(l=l*g+f*y,c=c*g+d*y,h=h*g+m*y,u=u*g+_*y,g===1-a){let E=1/Math.sqrt(l*l+c*c+h*h+u*u);l*=E,c*=E,h*=E,u*=E}}e[t]=l,e[t+1]=c,e[t+2]=h,e[t+3]=u}static multiplyQuaternionsFlat(e,t,n,i,s,o){let a=n[i],l=n[i+1],c=n[i+2],h=n[i+3],u=s[o],f=s[o+1],d=s[o+2],m=s[o+3];return e[t]=a*m+h*u+l*d-c*f,e[t+1]=l*m+h*f+c*u-a*d,e[t+2]=c*m+h*d+a*f-l*u,e[t+3]=h*m-a*u-l*f-c*d,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,n,i){return this._x=e,this._y=t,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){let n=e._x,i=e._y,s=e._z,o=e._order,a=Math.cos,l=Math.sin,c=a(n/2),h=a(i/2),u=a(s/2),f=l(n/2),d=l(i/2),m=l(s/2);switch(o){case"XYZ":this._x=f*h*u+c*d*m,this._y=c*d*u-f*h*m,this._z=c*h*m+f*d*u,this._w=c*h*u-f*d*m;break;case"YXZ":this._x=f*h*u+c*d*m,this._y=c*d*u-f*h*m,this._z=c*h*m-f*d*u,this._w=c*h*u+f*d*m;break;case"ZXY":this._x=f*h*u-c*d*m,this._y=c*d*u+f*h*m,this._z=c*h*m+f*d*u,this._w=c*h*u-f*d*m;break;case"ZYX":this._x=f*h*u-c*d*m,this._y=c*d*u+f*h*m,this._z=c*h*m-f*d*u,this._w=c*h*u+f*d*m;break;case"YZX":this._x=f*h*u+c*d*m,this._y=c*d*u+f*h*m,this._z=c*h*m-f*d*u,this._w=c*h*u-f*d*m;break;case"XZY":this._x=f*h*u-c*d*m,this._y=c*d*u-f*h*m,this._z=c*h*m+f*d*u,this._w=c*h*u+f*d*m;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+o)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){let n=t/2,i=Math.sin(n);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(e){let t=e.elements,n=t[0],i=t[4],s=t[8],o=t[1],a=t[5],l=t[9],c=t[2],h=t[6],u=t[10],f=n+a+u;if(f>0){let d=.5/Math.sqrt(f+1);this._w=.25/d,this._x=(h-l)*d,this._y=(s-c)*d,this._z=(o-i)*d}else if(n>a&&n>u){let d=2*Math.sqrt(1+n-a-u);this._w=(h-l)/d,this._x=.25*d,this._y=(i+o)/d,this._z=(s+c)/d}else if(a>u){let d=2*Math.sqrt(1+a-n-u);this._w=(s-c)/d,this._x=(i+o)/d,this._y=.25*d,this._z=(l+h)/d}else{let d=2*Math.sqrt(1+u-n-a);this._w=(o-i)/d,this._x=(s+c)/d,this._y=(l+h)/d,this._z=.25*d}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let n=e.dot(t)+1;return n<1e-8?(n=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=n):(this._x=0,this._y=-e.z,this._z=e.y,this._w=n)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=n),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(at(this.dot(e),-1,1)))}rotateTowards(e,t){let n=this.angleTo(e);if(n===0)return this;let i=Math.min(1,t/n);return this.slerp(e,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(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._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 e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){let n=e._x,i=e._y,s=e._z,o=e._w,a=t._x,l=t._y,c=t._z,h=t._w;return this._x=n*h+o*a+i*c-s*l,this._y=i*h+o*l+s*a-n*c,this._z=s*h+o*c+n*l-i*a,this._w=o*h-n*a-i*l-s*c,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);let n=this._x,i=this._y,s=this._z,o=this._w,a=o*e._w+n*e._x+i*e._y+s*e._z;if(a<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,a=-a):this.copy(e),a>=1)return this._w=o,this._x=n,this._y=i,this._z=s,this;let l=1-a*a;if(l<=Number.EPSILON){let d=1-t;return this._w=d*o+t*this._w,this._x=d*n+t*this._x,this._y=d*i+t*this._y,this._z=d*s+t*this._z,this.normalize(),this}let c=Math.sqrt(l),h=Math.atan2(c,a),u=Math.sin((1-t)*h)/c,f=Math.sin(t*h)/c;return this._w=o*u+this._w*f,this._x=n*u+this._x*f,this._y=i*u+this._y*f,this._z=s*u+this._z*f,this._onChangeCallback(),this}slerpQuaternions(e,t,n){return this.copy(e).slerp(t,n)}random(){let e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),s=Math.sqrt(n);return this.set(i*Math.sin(e),i*Math.cos(e),s*Math.sin(t),s*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}},C=class r{constructor(e=0,t=0,n=0){r.prototype.isVector3=!0,this.x=e,this.y=t,this.z=n}set(e,t,n){return n===void 0&&(n=this.z),this.x=e,this.y=t,this.z=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(Kp.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Kp.setFromAxisAngle(e,t))}applyMatrix3(e){let t=this.x,n=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[3]*n+s[6]*i,this.y=s[1]*t+s[4]*n+s[7]*i,this.z=s[2]*t+s[5]*n+s[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){let t=this.x,n=this.y,i=this.z,s=e.elements,o=1/(s[3]*t+s[7]*n+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*n+s[8]*i+s[12])*o,this.y=(s[1]*t+s[5]*n+s[9]*i+s[13])*o,this.z=(s[2]*t+s[6]*n+s[10]*i+s[14])*o,this}applyQuaternion(e){let t=this.x,n=this.y,i=this.z,s=e.x,o=e.y,a=e.z,l=e.w,c=2*(o*i-a*n),h=2*(a*t-s*i),u=2*(s*n-o*t);return this.x=t+l*c+o*u-a*h,this.y=n+l*h+a*c-s*u,this.z=i+l*u+s*h-o*c,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){let t=this.x,n=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[4]*n+s[8]*i,this.y=s[1]*t+s[5]*n+s[9]*i,this.z=s[2]*t+s[6]*n+s[10]*i,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=at(this.x,e.x,t.x),this.y=at(this.y,e.y,t.y),this.z=at(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=at(this.x,e,t),this.y=at(this.y,e,t),this.z=at(this.z,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(at(n,e,t))}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(e){return this.x*e.x+this.y*e.y+this.z*e.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(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){let n=e.x,i=e.y,s=e.z,o=t.x,a=t.y,l=t.z;return this.x=i*l-s*a,this.y=s*o-n*l,this.z=n*a-i*o,this}projectOnVector(e){let t=e.lengthSq();if(t===0)return this.set(0,0,0);let n=e.dot(this)/t;return this.copy(e).multiplyScalar(n)}projectOnPlane(e){return lf.copy(this).projectOnVector(e),this.sub(lf)}reflect(e){return this.sub(lf.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let n=this.dot(e)/t;return Math.acos(at(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,n=this.y-e.y,i=this.z-e.z;return t*t+n*n+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,n){let i=Math.sin(t)*e;return this.x=i*Math.sin(n),this.y=Math.cos(t)*e,this.z=i*Math.cos(n),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,n){return this.x=e*Math.sin(t),this.y=n,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){let t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){let t=this.setFromMatrixColumn(e,0).length(),n=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=n,this.z=i,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){let e=Math.random()*Math.PI*2,t=Math.random()*2-1,n=Math.sqrt(1-t*t);return this.x=n*Math.cos(e),this.y=t,this.z=n*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}},lf=new C,Kp=new Vt,pt=class r{constructor(e,t,n,i,s,o,a,l,c){r.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,n,i,s,o,a,l,c)}set(e,t,n,i,s,o,a,l,c){let h=this.elements;return h[0]=e,h[1]=i,h[2]=a,h[3]=t,h[4]=s,h[5]=l,h[6]=n,h[7]=o,h[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){let t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],this}extractBasis(e,t,n){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(e){let t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let n=e.elements,i=t.elements,s=this.elements,o=n[0],a=n[3],l=n[6],c=n[1],h=n[4],u=n[7],f=n[2],d=n[5],m=n[8],_=i[0],g=i[3],p=i[6],M=i[1],x=i[4],y=i[7],E=i[2],S=i[5],R=i[8];return s[0]=o*_+a*M+l*E,s[3]=o*g+a*x+l*S,s[6]=o*p+a*y+l*R,s[1]=c*_+h*M+u*E,s[4]=c*g+h*x+u*S,s[7]=c*p+h*y+u*R,s[2]=f*_+d*M+m*E,s[5]=f*g+d*x+m*S,s[8]=f*p+d*y+m*R,this}multiplyScalar(e){let t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){let e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],l=e[6],c=e[7],h=e[8];return t*o*h-t*a*c-n*s*h+n*a*l+i*s*c-i*o*l}invert(){let e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],l=e[6],c=e[7],h=e[8],u=h*o-a*c,f=a*l-h*s,d=c*s-o*l,m=t*u+n*f+i*d;if(m===0)return this.set(0,0,0,0,0,0,0,0,0);let _=1/m;return e[0]=u*_,e[1]=(i*c-h*n)*_,e[2]=(a*n-i*o)*_,e[3]=f*_,e[4]=(h*t-i*l)*_,e[5]=(i*s-a*t)*_,e[6]=d*_,e[7]=(n*l-c*t)*_,e[8]=(o*t-n*s)*_,this}transpose(){let e,t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){let t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,n,i,s,o,a){let l=Math.cos(s),c=Math.sin(s);return this.set(n*l,n*c,-n*(l*o+c*a)+o+e,-i*c,i*l,-i*(-c*o+l*a)+a+t,0,0,1),this}scale(e,t){return this.premultiply(cf.makeScale(e,t)),this}rotate(e){return this.premultiply(cf.makeRotation(-e)),this}translate(e,t){return this.premultiply(cf.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,n,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){let t=this.elements,n=e.elements;for(let i=0;i<9;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<9;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){let n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e}clone(){return new this.constructor().fromArray(this.elements)}},cf=new pt;function Jd(r){for(let e=r.length-1;e>=0;--e)if(r[e]>=65535)return!0;return!1}var Ix={Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array};function Gs(r,e){return new Ix[r](e)}function Js(r){return document.createElementNS("http://www.w3.org/1999/xhtml",r)}function jd(){let r=Js("canvas");return r.style.display="block",r}var Qp={};function js(r){r in Qp||(Qp[r]=!0,console.warn(r))}function Wg(r,e,t){return new Promise(function(n,i){function s(){switch(r.clientWaitSync(e,r.SYNC_FLUSH_COMMANDS_BIT,0)){case r.WAIT_FAILED:i();break;case r.TIMEOUT_EXPIRED:setTimeout(s,t);break;default:n()}}setTimeout(s,t)})}var em=new pt().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),tm=new pt().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function Dx(){let r={enabled:!0,workingColorSpace:ur,spaces:{},convert:function(i,s,o){return this.enabled===!1||s===o||!s||!o||(this.spaces[s].transfer===Ut&&(i.r=Bi(i.r),i.g=Bi(i.g),i.b=Bi(i.b)),this.spaces[s].primaries!==this.spaces[o].primaries&&(i.applyMatrix3(this.spaces[s].toXYZ),i.applyMatrix3(this.spaces[o].fromXYZ)),this.spaces[o].transfer===Ut&&(i.r=ks(i.r),i.g=ks(i.g),i.b=ks(i.b))),i},workingToColorSpace:function(i,s){return this.convert(i,this.workingColorSpace,s)},colorSpaceToWorking:function(i,s){return this.convert(i,s,this.workingColorSpace)},getPrimaries:function(i){return this.spaces[i].primaries},getTransfer:function(i){return i===wi?Ys:this.spaces[i].transfer},getToneMappingMode:function(i){return this.spaces[i].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(i,s=this.workingColorSpace){return i.fromArray(this.spaces[s].luminanceCoefficients)},define:function(i){Object.assign(this.spaces,i)},_getMatrix:function(i,s,o){return i.copy(this.spaces[s].toXYZ).multiply(this.spaces[o].fromXYZ)},_getDrawingBufferColorSpace:function(i){return this.spaces[i].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(i=this.workingColorSpace){return this.spaces[i].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(i,s){return js("THREE.ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),r.workingToColorSpace(i,s)},toWorkingColorSpace:function(i,s){return js("THREE.ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),r.colorSpaceToWorking(i,s)}},e=[.64,.33,.3,.6,.15,.06],t=[.2126,.7152,.0722],n=[.3127,.329];return r.define({[ur]:{primaries:e,whitePoint:n,transfer:Ys,toXYZ:em,fromXYZ:tm,luminanceCoefficients:t,workingColorSpaceConfig:{unpackColorSpace:wn},outputColorSpaceConfig:{drawingBufferColorSpace:wn}},[wn]:{primaries:e,whitePoint:n,transfer:Ut,toXYZ:em,fromXYZ:tm,luminanceCoefficients:t,outputColorSpaceConfig:{drawingBufferColorSpace:wn}}}),r}var wt=Dx();function Bi(r){return r<.04045?r*.0773993808:Math.pow(r*.9478672986+.0521327014,2.4)}function ks(r){return r<.0031308?r*12.92:1.055*Math.pow(r,.41666)-.055}var Ms,fa=class{static getDataURL(e,t="image/png"){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let n;if(e instanceof HTMLCanvasElement)n=e;else{Ms===void 0&&(Ms=Js("canvas")),Ms.width=e.width,Ms.height=e.height;let i=Ms.getContext("2d");e instanceof ImageData?i.putImageData(e,0,0):i.drawImage(e,0,0,e.width,e.height),n=Ms}return n.toDataURL(t)}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){let t=Js("canvas");t.width=e.width,t.height=e.height;let n=t.getContext("2d");n.drawImage(e,0,0,e.width,e.height);let i=n.getImageData(0,0,e.width,e.height),s=i.data;for(let o=0;o1),this.pmremVersion=0}get width(){return this.source.getSize(hf).x}get height(){return this.source.getSize(hf).y}get depth(){return this.source.getSize(hf).z}get image(){return this.source.data}set image(e=null){this.source.data=e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){for(let t in e){let n=e[t];if(n===void 0){console.warn(`THREE.Texture.setValues(): parameter '${t}' has value of undefined.`);continue}let i=this[t];if(i===void 0){console.warn(`THREE.Texture.setValues(): property '${t}' does not exist.`);continue}i&&n&&i.isVector2&&n.isVector2||i&&n&&i.isVector3&&n.isVector3||i&&n&&i.isMatrix3&&n.isMatrix3?i.copy(n):this[t]=n}}toJSON(e){let t=e===void 0||typeof e=="string";if(!t&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];let n={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(n.userData=this.userData),t||(e.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==Tl)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case Ws:e.x=e.x-Math.floor(e.x);break;case Vn:e.x=e.x<0?0:1;break;case Xs:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case Ws:e.y=e.y-Math.floor(e.y);break;case Vn:e.y=e.y<0?0:1;break;case Xs:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}};Kt.DEFAULT_IMAGE=null;Kt.DEFAULT_MAPPING=Tl;Kt.DEFAULT_ANISOTROPY=1;var At=class r{constructor(e=0,t=0,n=0,i=1){r.prototype.isVector4=!0,this.x=e,this.y=t,this.z=n,this.w=i}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,n,i){return this.x=e,this.y=t,this.z=n,this.w=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){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: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){let t=this.x,n=this.y,i=this.z,s=this.w,o=e.elements;return this.x=o[0]*t+o[4]*n+o[8]*i+o[12]*s,this.y=o[1]*t+o[5]*n+o[9]*i+o[13]*s,this.z=o[2]*t+o[6]*n+o[10]*i+o[14]*s,this.w=o[3]*t+o[7]*n+o[11]*i+o[15]*s,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);let t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,n,i,s,l=e.elements,c=l[0],h=l[4],u=l[8],f=l[1],d=l[5],m=l[9],_=l[2],g=l[6],p=l[10];if(Math.abs(h-f)<.01&&Math.abs(u-_)<.01&&Math.abs(m-g)<.01){if(Math.abs(h+f)<.1&&Math.abs(u+_)<.1&&Math.abs(m+g)<.1&&Math.abs(c+d+p-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;let x=(c+1)/2,y=(d+1)/2,E=(p+1)/2,S=(h+f)/4,R=(u+_)/4,P=(m+g)/4;return x>y&&x>E?x<.01?(n=0,i=.707106781,s=.707106781):(n=Math.sqrt(x),i=S/n,s=R/n):y>E?y<.01?(n=.707106781,i=0,s=.707106781):(i=Math.sqrt(y),n=S/i,s=P/i):E<.01?(n=.707106781,i=.707106781,s=0):(s=Math.sqrt(E),n=R/s,i=P/s),this.set(n,i,s,t),this}let M=Math.sqrt((g-m)*(g-m)+(u-_)*(u-_)+(f-h)*(f-h));return Math.abs(M)<.001&&(M=1),this.x=(g-m)/M,this.y=(u-_)/M,this.z=(f-h)/M,this.w=Math.acos((c+d+p-1)/2),this}setFromMatrixPosition(e){let t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=at(this.x,e.x,t.x),this.y=at(this.y,e.y,t.y),this.z=at(this.z,e.z,t.z),this.w=at(this.w,e.w,t.w),this}clampScalar(e,t){return this.x=at(this.x,e,t),this.y=at(this.y,e,t),this.z=at(this.z,e,t),this.w=at(this.w,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(at(n,e,t))}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(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.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(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this.w=e.w+(t.w-e.w)*n,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),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}},Ks=class extends kn{constructor(e=1,t=1,n={}){super(),n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:tn,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1},n),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=n.depth,this.scissor=new At(0,0,e,t),this.scissorTest=!1,this.viewport=new At(0,0,e,t);let i={width:e,height:t,depth:n.depth},s=new Kt(i);this.textures=[];let o=n.count;for(let a=0;a1;this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let t=0,n=e.textures.length;t=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,Qn),Qn.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,n;return e.normal.x>0?(t=e.normal.x*this.min.x,n=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,n=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,n+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,n+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,n+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,n+=e.normal.z*this.min.z),t<=-e.constant&&n>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(Xo),Ec.subVectors(this.max,Xo),Es.subVectors(e.a,Xo),Ss.subVectors(e.b,Xo),ws.subVectors(e.c,Xo),Ki.subVectors(Ss,Es),Qi.subVectors(ws,Ss),Cr.subVectors(Es,ws);let t=[0,-Ki.z,Ki.y,0,-Qi.z,Qi.y,0,-Cr.z,Cr.y,Ki.z,0,-Ki.x,Qi.z,0,-Qi.x,Cr.z,0,-Cr.x,-Ki.y,Ki.x,0,-Qi.y,Qi.x,0,-Cr.y,Cr.x,0];return!ff(t,Es,Ss,ws,Ec)||(t=[1,0,0,0,1,0,0,0,1],!ff(t,Es,Ss,ws,Ec))?!1:(Sc.crossVectors(Ki,Qi),t=[Sc.x,Sc.y,Sc.z],ff(t,Es,Ss,ws,Ec))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Qn).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(Qn).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(Pi[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),Pi[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),Pi[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),Pi[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),Pi[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),Pi[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),Pi[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),Pi[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(Pi),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}},Pi=[new C,new C,new C,new C,new C,new C,new C,new C],Qn=new C,Mc=new Ct,Es=new C,Ss=new C,ws=new C,Ki=new C,Qi=new C,Cr=new C,Xo=new C,Ec=new C,Sc=new C,Pr=new C;function ff(r,e,t,n,i){for(let s=0,o=r.length-3;s<=o;s+=3){Pr.fromArray(r,s);let a=i.x*Math.abs(Pr.x)+i.y*Math.abs(Pr.y)+i.z*Math.abs(Pr.z),l=e.dot(Pr),c=t.dot(Pr),h=n.dot(Pr);if(Math.max(-Math.max(l,c,h),Math.min(l,c,h))>a)return!1}return!0}var Nx=new Ct,$o=new C,df=new C,nn=class{constructor(e=new C,t=-1){this.isSphere=!0,this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){let n=this.center;t!==void 0?n.copy(t):Nx.setFromPoints(e).getCenter(n);let i=0;for(let s=0,o=e.length;sthis.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;$o.subVectors(e,this.center);let t=$o.lengthSq();if(t>this.radius*this.radius){let n=Math.sqrt(t),i=(n-this.radius)*.5;this.center.addScaledVector($o,i/n),this.radius+=i}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(df.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint($o.copy(e.center).add(df)),this.expandByPoint($o.copy(e.center).sub(df))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}},Ii=new C,pf=new C,wc=new C,er=new C,mf=new C,Tc=new C,gf=new C,Vi=class{constructor(e=new C,t=new C(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,Ii)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);let n=t.dot(this.direction);return n<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){let t=Ii.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(Ii.copy(this.origin).addScaledVector(this.direction,t),Ii.distanceToSquared(e))}distanceSqToSegment(e,t,n,i){pf.copy(e).add(t).multiplyScalar(.5),wc.copy(t).sub(e).normalize(),er.copy(this.origin).sub(pf);let s=e.distanceTo(t)*.5,o=-this.direction.dot(wc),a=er.dot(this.direction),l=-er.dot(wc),c=er.lengthSq(),h=Math.abs(1-o*o),u,f,d,m;if(h>0)if(u=o*l-a,f=o*a-l,m=s*h,u>=0)if(f>=-m)if(f<=m){let _=1/h;u*=_,f*=_,d=u*(u+o*f+2*a)+f*(o*u+f+2*l)+c}else f=s,u=Math.max(0,-(o*f+a)),d=-u*u+f*(f+2*l)+c;else f=-s,u=Math.max(0,-(o*f+a)),d=-u*u+f*(f+2*l)+c;else f<=-m?(u=Math.max(0,-(-o*s+a)),f=u>0?-s:Math.min(Math.max(-s,-l),s),d=-u*u+f*(f+2*l)+c):f<=m?(u=0,f=Math.min(Math.max(-s,-l),s),d=f*(f+2*l)+c):(u=Math.max(0,-(o*s+a)),f=u>0?s:Math.min(Math.max(-s,-l),s),d=-u*u+f*(f+2*l)+c);else f=o>0?-s:s,u=Math.max(0,-(o*f+a)),d=-u*u+f*(f+2*l)+c;return n&&n.copy(this.origin).addScaledVector(this.direction,u),i&&i.copy(pf).addScaledVector(wc,f),d}intersectSphere(e,t){Ii.subVectors(e.center,this.origin);let n=Ii.dot(this.direction),i=Ii.dot(Ii)-n*n,s=e.radius*e.radius;if(i>s)return null;let o=Math.sqrt(s-i),a=n-o,l=n+o;return l<0?null:a<0?this.at(l,t):this.at(a,t)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){let t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;let n=-(this.origin.dot(e.normal)+e.constant)/t;return n>=0?n:null}intersectPlane(e,t){let n=this.distanceToPlane(e);return n===null?null:this.at(n,t)}intersectsPlane(e){let t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let n,i,s,o,a,l,c=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,f=this.origin;return c>=0?(n=(e.min.x-f.x)*c,i=(e.max.x-f.x)*c):(n=(e.max.x-f.x)*c,i=(e.min.x-f.x)*c),h>=0?(s=(e.min.y-f.y)*h,o=(e.max.y-f.y)*h):(s=(e.max.y-f.y)*h,o=(e.min.y-f.y)*h),n>o||s>i||((s>n||isNaN(n))&&(n=s),(o=0?(a=(e.min.z-f.z)*u,l=(e.max.z-f.z)*u):(a=(e.max.z-f.z)*u,l=(e.min.z-f.z)*u),n>l||a>i)||((a>n||n!==n)&&(n=a),(l=0?n:i,t)}intersectsBox(e){return this.intersectBox(e,Ii)!==null}intersectTriangle(e,t,n,i,s){mf.subVectors(t,e),Tc.subVectors(n,e),gf.crossVectors(mf,Tc);let o=this.direction.dot(gf),a;if(o>0){if(i)return null;a=1}else if(o<0)a=-1,o=-o;else return null;er.subVectors(this.origin,e);let l=a*this.direction.dot(Tc.crossVectors(er,Tc));if(l<0)return null;let c=a*this.direction.dot(mf.cross(er));if(c<0||l+c>o)return null;let h=-a*er.dot(gf);return h<0?null:this.at(h/o,s)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}},Qe=class r{constructor(e,t,n,i,s,o,a,l,c,h,u,f,d,m,_,g){r.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,n,i,s,o,a,l,c,h,u,f,d,m,_,g)}set(e,t,n,i,s,o,a,l,c,h,u,f,d,m,_,g){let p=this.elements;return p[0]=e,p[4]=t,p[8]=n,p[12]=i,p[1]=s,p[5]=o,p[9]=a,p[13]=l,p[2]=c,p[6]=h,p[10]=u,p[14]=f,p[3]=d,p[7]=m,p[11]=_,p[15]=g,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 r().fromArray(this.elements)}copy(e){let t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],this}copyPosition(e){let t=this.elements,n=e.elements;return t[12]=n[12],t[13]=n[13],t[14]=n[14],this}setFromMatrix3(e){let t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,n){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(e,t,n){return this.set(e.x,t.x,n.x,0,e.y,t.y,n.y,0,e.z,t.z,n.z,0,0,0,0,1),this}extractRotation(e){let t=this.elements,n=e.elements,i=1/Ts.setFromMatrixColumn(e,0).length(),s=1/Ts.setFromMatrixColumn(e,1).length(),o=1/Ts.setFromMatrixColumn(e,2).length();return t[0]=n[0]*i,t[1]=n[1]*i,t[2]=n[2]*i,t[3]=0,t[4]=n[4]*s,t[5]=n[5]*s,t[6]=n[6]*s,t[7]=0,t[8]=n[8]*o,t[9]=n[9]*o,t[10]=n[10]*o,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){let t=this.elements,n=e.x,i=e.y,s=e.z,o=Math.cos(n),a=Math.sin(n),l=Math.cos(i),c=Math.sin(i),h=Math.cos(s),u=Math.sin(s);if(e.order==="XYZ"){let f=o*h,d=o*u,m=a*h,_=a*u;t[0]=l*h,t[4]=-l*u,t[8]=c,t[1]=d+m*c,t[5]=f-_*c,t[9]=-a*l,t[2]=_-f*c,t[6]=m+d*c,t[10]=o*l}else if(e.order==="YXZ"){let f=l*h,d=l*u,m=c*h,_=c*u;t[0]=f+_*a,t[4]=m*a-d,t[8]=o*c,t[1]=o*u,t[5]=o*h,t[9]=-a,t[2]=d*a-m,t[6]=_+f*a,t[10]=o*l}else if(e.order==="ZXY"){let f=l*h,d=l*u,m=c*h,_=c*u;t[0]=f-_*a,t[4]=-o*u,t[8]=m+d*a,t[1]=d+m*a,t[5]=o*h,t[9]=_-f*a,t[2]=-o*c,t[6]=a,t[10]=o*l}else if(e.order==="ZYX"){let f=o*h,d=o*u,m=a*h,_=a*u;t[0]=l*h,t[4]=m*c-d,t[8]=f*c+_,t[1]=l*u,t[5]=_*c+f,t[9]=d*c-m,t[2]=-c,t[6]=a*l,t[10]=o*l}else if(e.order==="YZX"){let f=o*l,d=o*c,m=a*l,_=a*c;t[0]=l*h,t[4]=_-f*u,t[8]=m*u+d,t[1]=u,t[5]=o*h,t[9]=-a*h,t[2]=-c*h,t[6]=d*u+m,t[10]=f-_*u}else if(e.order==="XZY"){let f=o*l,d=o*c,m=a*l,_=a*c;t[0]=l*h,t[4]=-u,t[8]=c*h,t[1]=f*u+_,t[5]=o*h,t[9]=d*u-m,t[2]=m*u-d,t[6]=a*h,t[10]=_*u+f}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(Fx,e,Ox)}lookAt(e,t,n){let i=this.elements;return Bn.subVectors(e,t),Bn.lengthSq()===0&&(Bn.z=1),Bn.normalize(),tr.crossVectors(n,Bn),tr.lengthSq()===0&&(Math.abs(n.z)===1?Bn.x+=1e-4:Bn.z+=1e-4,Bn.normalize(),tr.crossVectors(n,Bn)),tr.normalize(),Ac.crossVectors(Bn,tr),i[0]=tr.x,i[4]=Ac.x,i[8]=Bn.x,i[1]=tr.y,i[5]=Ac.y,i[9]=Bn.y,i[2]=tr.z,i[6]=Ac.z,i[10]=Bn.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let n=e.elements,i=t.elements,s=this.elements,o=n[0],a=n[4],l=n[8],c=n[12],h=n[1],u=n[5],f=n[9],d=n[13],m=n[2],_=n[6],g=n[10],p=n[14],M=n[3],x=n[7],y=n[11],E=n[15],S=i[0],R=i[4],P=i[8],w=i[12],T=i[1],N=i[5],V=i[9],G=i[13],Z=i[2],K=i[6],Q=i[10],_e=i[14],ne=i[3],Te=i[7],Oe=i[11],Ge=i[15];return s[0]=o*S+a*T+l*Z+c*ne,s[4]=o*R+a*N+l*K+c*Te,s[8]=o*P+a*V+l*Q+c*Oe,s[12]=o*w+a*G+l*_e+c*Ge,s[1]=h*S+u*T+f*Z+d*ne,s[5]=h*R+u*N+f*K+d*Te,s[9]=h*P+u*V+f*Q+d*Oe,s[13]=h*w+u*G+f*_e+d*Ge,s[2]=m*S+_*T+g*Z+p*ne,s[6]=m*R+_*N+g*K+p*Te,s[10]=m*P+_*V+g*Q+p*Oe,s[14]=m*w+_*G+g*_e+p*Ge,s[3]=M*S+x*T+y*Z+E*ne,s[7]=M*R+x*N+y*K+E*Te,s[11]=M*P+x*V+y*Q+E*Oe,s[15]=M*w+x*G+y*_e+E*Ge,this}multiplyScalar(e){let t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){let e=this.elements,t=e[0],n=e[4],i=e[8],s=e[12],o=e[1],a=e[5],l=e[9],c=e[13],h=e[2],u=e[6],f=e[10],d=e[14],m=e[3],_=e[7],g=e[11],p=e[15];return m*(+s*l*u-i*c*u-s*a*f+n*c*f+i*a*d-n*l*d)+_*(+t*l*d-t*c*f+s*o*f-i*o*d+i*c*h-s*l*h)+g*(+t*c*u-t*a*d-s*o*u+n*o*d+s*a*h-n*c*h)+p*(-i*a*h-t*l*u+t*a*f+i*o*u-n*o*f+n*l*h)}transpose(){let e=this.elements,t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,n){let i=this.elements;return e.isVector3?(i[12]=e.x,i[13]=e.y,i[14]=e.z):(i[12]=e,i[13]=t,i[14]=n),this}invert(){let e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],l=e[6],c=e[7],h=e[8],u=e[9],f=e[10],d=e[11],m=e[12],_=e[13],g=e[14],p=e[15],M=u*g*c-_*f*c+_*l*d-a*g*d-u*l*p+a*f*p,x=m*f*c-h*g*c-m*l*d+o*g*d+h*l*p-o*f*p,y=h*_*c-m*u*c+m*a*d-o*_*d-h*a*p+o*u*p,E=m*u*l-h*_*l-m*a*f+o*_*f+h*a*g-o*u*g,S=t*M+n*x+i*y+s*E;if(S===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);let R=1/S;return e[0]=M*R,e[1]=(_*f*s-u*g*s-_*i*d+n*g*d+u*i*p-n*f*p)*R,e[2]=(a*g*s-_*l*s+_*i*c-n*g*c-a*i*p+n*l*p)*R,e[3]=(u*l*s-a*f*s-u*i*c+n*f*c+a*i*d-n*l*d)*R,e[4]=x*R,e[5]=(h*g*s-m*f*s+m*i*d-t*g*d-h*i*p+t*f*p)*R,e[6]=(m*l*s-o*g*s-m*i*c+t*g*c+o*i*p-t*l*p)*R,e[7]=(o*f*s-h*l*s+h*i*c-t*f*c-o*i*d+t*l*d)*R,e[8]=y*R,e[9]=(m*u*s-h*_*s-m*n*d+t*_*d+h*n*p-t*u*p)*R,e[10]=(o*_*s-m*a*s+m*n*c-t*_*c-o*n*p+t*a*p)*R,e[11]=(h*a*s-o*u*s-h*n*c+t*u*c+o*n*d-t*a*d)*R,e[12]=E*R,e[13]=(h*_*i-m*u*i+m*n*f-t*_*f-h*n*g+t*u*g)*R,e[14]=(m*a*i-o*_*i-m*n*l+t*_*l+o*n*g-t*a*g)*R,e[15]=(o*u*i-h*a*i+h*n*l-t*u*l-o*n*f+t*a*f)*R,this}scale(e){let t=this.elements,n=e.x,i=e.y,s=e.z;return t[0]*=n,t[4]*=i,t[8]*=s,t[1]*=n,t[5]*=i,t[9]*=s,t[2]*=n,t[6]*=i,t[10]*=s,t[3]*=n,t[7]*=i,t[11]*=s,this}getMaxScaleOnAxis(){let e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],i=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,n,i))}makeTranslation(e,t,n){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,n,0,0,0,1),this}makeRotationX(e){let t=Math.cos(e),n=Math.sin(e);return this.set(1,0,0,0,0,t,-n,0,0,n,t,0,0,0,0,1),this}makeRotationY(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,0,n,0,0,1,0,0,-n,0,t,0,0,0,0,1),this}makeRotationZ(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,0,n,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){let n=Math.cos(t),i=Math.sin(t),s=1-n,o=e.x,a=e.y,l=e.z,c=s*o,h=s*a;return this.set(c*o+n,c*a-i*l,c*l+i*a,0,c*a+i*l,h*a+n,h*l-i*o,0,c*l-i*a,h*l+i*o,s*l*l+n,0,0,0,0,1),this}makeScale(e,t,n){return this.set(e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1),this}makeShear(e,t,n,i,s,o){return this.set(1,n,s,0,e,1,o,0,t,i,1,0,0,0,0,1),this}compose(e,t,n){let i=this.elements,s=t._x,o=t._y,a=t._z,l=t._w,c=s+s,h=o+o,u=a+a,f=s*c,d=s*h,m=s*u,_=o*h,g=o*u,p=a*u,M=l*c,x=l*h,y=l*u,E=n.x,S=n.y,R=n.z;return i[0]=(1-(_+p))*E,i[1]=(d+y)*E,i[2]=(m-x)*E,i[3]=0,i[4]=(d-y)*S,i[5]=(1-(f+p))*S,i[6]=(g+M)*S,i[7]=0,i[8]=(m+x)*R,i[9]=(g-M)*R,i[10]=(1-(f+_))*R,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,t,n){let i=this.elements,s=Ts.set(i[0],i[1],i[2]).length(),o=Ts.set(i[4],i[5],i[6]).length(),a=Ts.set(i[8],i[9],i[10]).length();this.determinant()<0&&(s=-s),e.x=i[12],e.y=i[13],e.z=i[14],ei.copy(this);let c=1/s,h=1/o,u=1/a;return ei.elements[0]*=c,ei.elements[1]*=c,ei.elements[2]*=c,ei.elements[4]*=h,ei.elements[5]*=h,ei.elements[6]*=h,ei.elements[8]*=u,ei.elements[9]*=u,ei.elements[10]*=u,t.setFromRotationMatrix(ei),n.x=s,n.y=o,n.z=a,this}makePerspective(e,t,n,i,s,o,a=Nn,l=!1){let c=this.elements,h=2*s/(t-e),u=2*s/(n-i),f=(t+e)/(t-e),d=(n+i)/(n-i),m,_;if(l)m=s/(o-s),_=o*s/(o-s);else if(a===Nn)m=-(o+s)/(o-s),_=-2*o*s/(o-s);else if(a===Wr)m=-o/(o-s),_=-o*s/(o-s);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=f,c[12]=0,c[1]=0,c[5]=u,c[9]=d,c[13]=0,c[2]=0,c[6]=0,c[10]=m,c[14]=_,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,n,i,s,o,a=Nn,l=!1){let c=this.elements,h=2/(t-e),u=2/(n-i),f=-(t+e)/(t-e),d=-(n+i)/(n-i),m,_;if(l)m=1/(o-s),_=o/(o-s);else if(a===Nn)m=-2/(o-s),_=-(o+s)/(o-s);else if(a===Wr)m=-1/(o-s),_=-s/(o-s);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=0,c[12]=f,c[1]=0,c[5]=u,c[9]=0,c[13]=d,c[2]=0,c[6]=0,c[10]=m,c[14]=_,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){let t=this.elements,n=e.elements;for(let i=0;i<16;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<16;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){let n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e[t+9]=n[9],e[t+10]=n[10],e[t+11]=n[11],e[t+12]=n[12],e[t+13]=n[13],e[t+14]=n[14],e[t+15]=n[15],e}},Ts=new C,ei=new Qe,Fx=new C(0,0,0),Ox=new C(1,1,1),tr=new C,Ac=new C,Bn=new C,nm=new Qe,im=new Vt,yn=class r{constructor(e=0,t=0,n=0,i=r.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=n,this._order=i}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,n,i=this._order){return this._x=e,this._y=t,this._z=n,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,n=!0){let i=e.elements,s=i[0],o=i[4],a=i[8],l=i[1],c=i[5],h=i[9],u=i[2],f=i[6],d=i[10];switch(t){case"XYZ":this._y=Math.asin(at(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,d),this._z=Math.atan2(-o,s)):(this._x=Math.atan2(f,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(l,c)):(this._y=Math.atan2(-u,s),this._z=0);break;case"ZXY":this._x=Math.asin(at(f,-1,1)),Math.abs(f)<.9999999?(this._y=Math.atan2(-u,d),this._z=Math.atan2(-o,c)):(this._y=0,this._z=Math.atan2(l,s));break;case"ZYX":this._y=Math.asin(-at(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(f,d),this._z=Math.atan2(l,s)):(this._x=0,this._z=Math.atan2(-o,c));break;case"YZX":this._z=Math.asin(at(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-h,c),this._y=Math.atan2(-u,s)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-at(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(f,c),this._y=Math.atan2(a,s)):(this._x=Math.atan2(-h,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,n===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,n){return nm.makeRotationFromQuaternion(e),this.setFromRotationMatrix(nm,t,n)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return im.setFromEuler(this),this.setFromQuaternion(im,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}};yn.DEFAULT_ORDER="XYZ";var Yr=class{constructor(){this.mask=1}set(e){this.mask=(1<>>0}enable(e){this.mask|=1<1){for(let t=0;t1){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.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),i.instanceInfo=this._instanceInfo.map(a=>({...a})),i.availableInstanceIds=this._availableInstanceIds.slice(),i.availableGeometryIds=this._availableGeometryIds.slice(),i.nextIndexStart=this._nextIndexStart,i.nextVertexStart=this._nextVertexStart,i.geometryCount=this._geometryCount,i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.matricesTexture=this._matricesTexture.toJSON(e),i.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(i.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(i.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(i.boundingBox=this.boundingBox.toJSON()));function s(a,l){return a[l.uuid]===void 0&&(a[l.uuid]=l.toJSON(e)),l.uuid}if(this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(i.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=s(e.geometries,this.geometry);let a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){let l=a.shapes;if(Array.isArray(l))for(let c=0,h=l.length;c0){i.children=[];for(let a=0;a0){i.animations=[];for(let a=0;a0&&(n.geometries=a),l.length>0&&(n.materials=l),c.length>0&&(n.textures=c),h.length>0&&(n.images=h),u.length>0&&(n.shapes=u),f.length>0&&(n.skeletons=f),d.length>0&&(n.animations=d),m.length>0&&(n.nodes=m)}return n.object=i,n;function o(a){let l=[];for(let c in a){let h=a[c];delete h.metadata,l.push(h)}return l}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let n=0;n0?i.multiplyScalar(1/Math.sqrt(s)):i.set(0,0,0)}static getBarycoord(e,t,n,i,s){ti.subVectors(i,t),Li.subVectors(n,t),yf.subVectors(e,t);let o=ti.dot(ti),a=ti.dot(Li),l=ti.dot(yf),c=Li.dot(Li),h=Li.dot(yf),u=o*c-a*a;if(u===0)return s.set(0,0,0),null;let f=1/u,d=(c*l-a*h)*f,m=(o*h-a*l)*f;return s.set(1-d-m,m,d)}static containsPoint(e,t,n,i){return this.getBarycoord(e,t,n,i,Ui)===null?!1:Ui.x>=0&&Ui.y>=0&&Ui.x+Ui.y<=1}static getInterpolation(e,t,n,i,s,o,a,l){return this.getBarycoord(e,t,n,i,Ui)===null?(l.x=0,l.y=0,"z"in l&&(l.z=0),"w"in l&&(l.w=0),null):(l.setScalar(0),l.addScaledVector(s,Ui.x),l.addScaledVector(o,Ui.y),l.addScaledVector(a,Ui.z),l)}static getInterpolatedAttribute(e,t,n,i,s,o){return Mf.setScalar(0),Ef.setScalar(0),Sf.setScalar(0),Mf.fromBufferAttribute(e,t),Ef.fromBufferAttribute(e,n),Sf.fromBufferAttribute(e,i),o.setScalar(0),o.addScaledVector(Mf,s.x),o.addScaledVector(Ef,s.y),o.addScaledVector(Sf,s.z),o}static isFrontFacing(e,t,n,i){return ti.subVectors(n,t),Li.subVectors(e,t),ti.cross(Li).dot(i)<0}set(e,t,n){return this.a.copy(e),this.b.copy(t),this.c.copy(n),this}setFromPointsAndIndices(e,t,n,i){return this.a.copy(e[t]),this.b.copy(e[n]),this.c.copy(e[i]),this}setFromAttributeAndIndices(e,t,n,i){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,n),this.c.fromBufferAttribute(e,i),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return ti.subVectors(this.c,this.b),Li.subVectors(this.a,this.b),ti.cross(Li).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return r.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,t){return r.getBarycoord(e,this.a,this.b,this.c,t)}getInterpolation(e,t,n,i,s){return r.getInterpolation(e,this.a,this.b,this.c,t,n,i,s)}containsPoint(e){return r.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return r.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){let n=this.a,i=this.b,s=this.c,o,a;Cs.subVectors(i,n),Ps.subVectors(s,n),xf.subVectors(e,n);let l=Cs.dot(xf),c=Ps.dot(xf);if(l<=0&&c<=0)return t.copy(n);vf.subVectors(e,i);let h=Cs.dot(vf),u=Ps.dot(vf);if(h>=0&&u<=h)return t.copy(i);let f=l*u-h*c;if(f<=0&&l>=0&&h<=0)return o=l/(l-h),t.copy(n).addScaledVector(Cs,o);bf.subVectors(e,s);let d=Cs.dot(bf),m=Ps.dot(bf);if(m>=0&&d<=m)return t.copy(s);let _=d*c-l*m;if(_<=0&&c>=0&&m<=0)return a=c/(c-m),t.copy(n).addScaledVector(Ps,a);let g=h*m-d*u;if(g<=0&&u-h>=0&&d-m>=0)return cm.subVectors(s,i),a=(u-h)/(u-h+(d-m)),t.copy(i).addScaledVector(cm,a);let p=1/(g+_+f);return o=_*p,a=f*p,t.copy(n).addScaledVector(Cs,o).addScaledVector(Ps,a)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}},Xg={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},nr={h:0,s:0,l:0},Cc={h:0,s:0,l:0};function wf(r,e,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?r+(e-r)*6*t:t<1/2?e:t<2/3?r+(e-r)*6*(2/3-t):r}var Be=class{constructor(e,t,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,n)}set(e,t,n){if(t===void 0&&n===void 0){let i=e;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}else this.setRGB(e,t,n);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=wn){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,wt.colorSpaceToWorking(this,t),this}setRGB(e,t,n,i=wt.workingColorSpace){return this.r=e,this.g=t,this.b=n,wt.colorSpaceToWorking(this,i),this}setHSL(e,t,n,i=wt.workingColorSpace){if(e=Zd(e,1),t=at(t,0,1),n=at(n,0,1),t===0)this.r=this.g=this.b=n;else{let s=n<=.5?n*(1+t):n+t-n*t,o=2*n-s;this.r=wf(o,s,e+1/3),this.g=wf(o,s,e),this.b=wf(o,s,e-1/3)}return wt.colorSpaceToWorking(this,i),this}setStyle(e,t=wn){function n(s){s!==void 0&&parseFloat(s)<1&&console.warn("THREE.Color: Alpha component of "+e+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(e)){let s,o=i[1],a=i[2];switch(o){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setRGB(Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,t);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setRGB(Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,t);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,t);break;default:console.warn("THREE.Color: Unknown color model "+e)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(e)){let s=i[1],o=s.length;if(o===3)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,t);if(o===6)return this.setHex(parseInt(s,16),t);console.warn("THREE.Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=wn){let n=Xg[e.toLowerCase()];return n!==void 0?this.setHex(n,t):console.warn("THREE.Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=Bi(e.r),this.g=Bi(e.g),this.b=Bi(e.b),this}copyLinearToSRGB(e){return this.r=ks(e.r),this.g=ks(e.g),this.b=ks(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=wn){return wt.workingToColorSpace(mn.copy(this),e),Math.round(at(mn.r*255,0,255))*65536+Math.round(at(mn.g*255,0,255))*256+Math.round(at(mn.b*255,0,255))}getHexString(e=wn){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=wt.workingColorSpace){wt.workingToColorSpace(mn.copy(this),t);let n=mn.r,i=mn.g,s=mn.b,o=Math.max(n,i,s),a=Math.min(n,i,s),l,c,h=(a+o)/2;if(a===o)l=0,c=0;else{let u=o-a;switch(c=h<=.5?u/(o+a):u/(2-o-a),o){case n:l=(i-s)/u+(i0!=e>0&&this.version++,this._alphaTest=e}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(let t in e){let n=e[t];if(n===void 0){console.warn(`THREE.Material: parameter '${t}' has value of undefined.`);continue}let i=this[t];if(i===void 0){console.warn(`THREE.Material: '${t}' 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[t]=n}}toJSON(e){let t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{}});let n={metadata:{version:4.7,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(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(n.sheenColorMap=this.sheenColorMap.toJSON(e).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(n.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(e).uuid),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(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).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(e).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(e).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(e).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(e).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(e).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(e).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(e).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(e).uuid),this.transmission!==void 0&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(e).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!==lr&&(n.blending=this.blending),this.side!==gi&&(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!==ca&&(n.blendSrc=this.blendSrc),this.blendDst!==ua&&(n.blendDst=this.blendDst),this.blendEquation!==zi&&(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!==cr&&(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!==hu&&(n.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(n.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==sr&&(n.stencilFail=this.stencilFail),this.stencilZFail!==sr&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==sr&&(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(s){let o=[];for(let a in s){let l=s[a];delete l.metadata,o.push(l)}return o}if(t){let s=i(e.textures),o=i(e.images);s.length>0&&(n.textures=s),o.length>0&&(n.images=o)}return n}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;let t=e.clippingPlanes,n=null;if(t!==null){let i=t.length;n=new Array(i);for(let s=0;s!==i;++s)n[s]=t[s].clone()}return this.clippingPlanes=n,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){e===!0&&this.version++}},Xn=class extends rn{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new Be(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 yn,this.combine=bo,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}},Fi=kx();function kx(){let r=new ArrayBuffer(4),e=new Float32Array(r),t=new Uint32Array(r),n=new Uint32Array(512),i=new Uint32Array(512);for(let l=0;l<256;++l){let c=l-127;c<-27?(n[l]=0,n[l|256]=32768,i[l]=24,i[l|256]=24):c<-14?(n[l]=1024>>-c-14,n[l|256]=1024>>-c-14|32768,i[l]=-c-1,i[l|256]=-c-1):c<=15?(n[l]=c+15<<10,n[l|256]=c+15<<10|32768,i[l]=13,i[l|256]=13):c<128?(n[l]=31744,n[l|256]=64512,i[l]=24,i[l|256]=24):(n[l]=31744,n[l|256]=64512,i[l]=13,i[l|256]=13)}let s=new Uint32Array(2048),o=new Uint32Array(64),a=new Uint32Array(64);for(let l=1;l<1024;++l){let c=l<<13,h=0;for(;(c&8388608)===0;)c<<=1,h-=8388608;c&=-8388609,h+=947912704,s[l]=c|h}for(let l=1024;l<2048;++l)s[l]=939524096+(l-1024<<13);for(let l=1;l<31;++l)o[l]=l<<23;o[31]=1199570944,o[32]=2147483648;for(let l=33;l<63;++l)o[l]=2147483648+(l-32<<23);o[63]=3347054592;for(let l=1;l<64;++l)l!==32&&(a[l]=1024);return{floatView:e,uint32View:t,baseTable:n,shiftTable:i,mantissaTable:s,exponentTable:o,offsetTable:a}}function Un(r){Math.abs(r)>65504&&console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."),r=at(r,-65504,65504),Fi.floatView[0]=r;let e=Fi.uint32View[0],t=e>>23&511;return Fi.baseTable[t]+((e&8388607)>>Fi.shiftTable[t])}function ia(r){let e=r>>10;return Fi.uint32View[0]=Fi.mantissaTable[Fi.offsetTable[e]+(r&1023)]+Fi.exponentTable[e],Fi.floatView[0]}var pu=class{static toHalfFloat(e){return Un(e)}static fromHalfFloat(e){return ia(e)}},Qt=new C,Pc=new ce,Wx=0,ht=class{constructor(e,t,n=!1){if(Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:Wx++}),this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=n,this.usage=Zs,this.updateRanges=[],this.gpuType=Rn,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,n){e*=this.itemSize,n*=t.itemSize;for(let i=0,s=this.itemSize;it.count&&console.warn("THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),t.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Ct);let e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new C(-1/0,-1/0,-1/0),new C(1/0,1/0,1/0));return}if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let n=0,i=t.length;n0&&(e.userData=this.userData),this.parameters!==void 0){let l=this.parameters;for(let c in l)l[c]!==void 0&&(e[c]=l[c]);return e}e.data={attributes:{}};let t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});let n=this.attributes;for(let l in n){let c=n[l];e.data.attributes[l]=c.toJSON(e.data)}let i={},s=!1;for(let l in this.morphAttributes){let c=this.morphAttributes[l],h=[];for(let u=0,f=c.length;u0&&(i[l]=h,s=!0)}s&&(e.data.morphAttributes=i,e.data.morphTargetsRelative=this.morphTargetsRelative);let o=this.groups;o.length>0&&(e.data.groups=JSON.parse(JSON.stringify(o)));let a=this.boundingSphere;return a!==null&&(e.data.boundingSphere=a.toJSON()),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;let t={};this.name=e.name;let n=e.index;n!==null&&this.setIndex(n.clone());let i=e.attributes;for(let c in i){let h=i[c];this.setAttribute(c,h.clone(t))}let s=e.morphAttributes;for(let c in s){let h=[],u=s[c];for(let f=0,d=u.length;f0){let i=t[n[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=i.length;s(e.far-e.near)**2))&&(um.copy(s).invert(),Ir.copy(e.ray).applyMatrix4(um),!(n.boundingBox!==null&&Ir.intersectsBox(n.boundingBox)===!1)&&this._computeIntersections(e,t,Ir)))}_computeIntersections(e,t,n){let i,s=this.geometry,o=this.material,a=s.index,l=s.attributes.position,c=s.attributes.uv,h=s.attributes.uv1,u=s.attributes.normal,f=s.groups,d=s.drawRange;if(a!==null)if(Array.isArray(o))for(let m=0,_=f.length;m<_;m++){let g=f[m],p=o[g.materialIndex],M=Math.max(g.start,d.start),x=Math.min(a.count,Math.min(g.start+g.count,d.start+d.count));for(let y=M,E=x;yt.far?null:{distance:c,point:Fc.clone(),object:r}}function Oc(r,e,t,n,i,s,o,a,l,c){r.getVertexPosition(a,Dc),r.getVertexPosition(l,Lc),r.getVertexPosition(c,Uc);let h=$x(r,e,t,n,Dc,Lc,Uc,fm);if(h){let u=new C;ii.getBarycoord(fm,Dc,Lc,Uc,u),i&&(h.uv=ii.getInterpolatedAttribute(i,a,l,c,u,new ce)),s&&(h.uv1=ii.getInterpolatedAttribute(s,a,l,c,u,new ce)),o&&(h.normal=ii.getInterpolatedAttribute(o,a,l,c,u,new C),h.normal.dot(n.direction)>0&&h.normal.multiplyScalar(-1));let f={a,b:l,c,normal:new C,materialIndex:0};ii.getNormal(Dc,Lc,Uc,f.normal),h.face=f,h.barycoord=u}return h}var Zn=class r extends et{constructor(e=1,t=1,n=1,i=1,s=1,o=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:t,depth:n,widthSegments:i,heightSegments:s,depthSegments:o};let a=this;i=Math.floor(i),s=Math.floor(s),o=Math.floor(o);let l=[],c=[],h=[],u=[],f=0,d=0;m("z","y","x",-1,-1,n,t,e,o,s,0),m("z","y","x",1,-1,n,t,-e,o,s,1),m("x","z","y",1,1,e,n,t,i,o,2),m("x","z","y",1,-1,e,n,-t,i,o,3),m("x","y","z",1,-1,e,t,n,i,s,4),m("x","y","z",-1,-1,e,t,-n,i,s,5),this.setIndex(l),this.setAttribute("position",new De(c,3)),this.setAttribute("normal",new De(h,3)),this.setAttribute("uv",new De(u,2));function m(_,g,p,M,x,y,E,S,R,P,w){let T=y/R,N=E/P,V=y/2,G=E/2,Z=S/2,K=R+1,Q=P+1,_e=0,ne=0,Te=new C;for(let Oe=0;Oe0?1:-1,h.push(Te.x,Te.y,Te.z),u.push(dt/R),u.push(1-Oe/P),_e+=1}}for(let Oe=0;Oe0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;let n={};for(let i in this.extensions)this.extensions[i]===!0&&(n[i]=!0);return Object.keys(n).length>0&&(t.extensions=n),t}},Zr=class extends bt{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new Qe,this.projectionMatrix=new Qe,this.projectionMatrixInverse=new Qe,this.coordinateSystem=Nn,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return new this.constructor().copy(this)}},ir=new C,dm=new ce,pm=new ce,en=class extends Zr{constructor(e=50,t=1,n=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=e,this.zoom=1,this.near=n,this.far=i,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=e.view===null?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){let t=.5*this.getFilmHeight()/e;this.fov=Xr*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){let e=Math.tan(Gr*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return Xr*2*Math.atan(Math.tan(Gr*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(e,t,n){ir.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),t.set(ir.x,ir.y).multiplyScalar(-e/ir.z),ir.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set(ir.x,ir.y).multiplyScalar(-e/ir.z)}getViewSize(e,t){return this.getViewBounds(e,dm,pm),t.subVectors(pm,dm)}setViewOffset(e,t,n,i,s,o){this.aspect=e/t,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=e,this.view.fullHeight=t,this.view.offsetX=n,this.view.offsetY=i,this.view.width=s,this.view.height=o,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let e=this.near,t=e*Math.tan(Gr*.5*this.fov)/this.zoom,n=2*t,i=this.aspect*n,s=-.5*i,o=this.view;if(this.view!==null&&this.view.enabled){let l=o.fullWidth,c=o.fullHeight;s+=o.offsetX*i/l,t-=o.offsetY*n/c,i*=o.width/l,n*=o.height/c}let a=this.filmOffset;a!==0&&(s+=e*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(s,s+i,t,t-n,e,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){let t=super.toJSON(e);return t.object.fov=this.fov,t.object.zoom=this.zoom,t.object.near=this.near,t.object.far=this.far,t.object.focus=this.focus,t.object.aspect=this.aspect,this.view!==null&&(t.object.view=Object.assign({},this.view)),t.object.filmGauge=this.filmGauge,t.object.filmOffset=this.filmOffset,t}},Ds=-90,Ls=1,da=class extends bt{constructor(e,t,n){super(),this.type="CubeCamera",this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;let i=new en(Ds,Ls,e,t);i.layers=this.layers,this.add(i);let s=new en(Ds,Ls,e,t);s.layers=this.layers,this.add(s);let o=new en(Ds,Ls,e,t);o.layers=this.layers,this.add(o);let a=new en(Ds,Ls,e,t);a.layers=this.layers,this.add(a);let l=new en(Ds,Ls,e,t);l.layers=this.layers,this.add(l);let c=new en(Ds,Ls,e,t);c.layers=this.layers,this.add(c)}updateCoordinateSystem(){let e=this.coordinateSystem,t=this.children.concat(),[n,i,s,o,a,l]=t;for(let c of t)this.remove(c);if(e===Nn)n.up.set(0,1,0),n.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),s.up.set(0,0,-1),s.lookAt(0,1,0),o.up.set(0,0,1),o.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),l.up.set(0,1,0),l.lookAt(0,0,-1);else if(e===Wr)n.up.set(0,-1,0),n.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),s.up.set(0,0,1),s.lookAt(0,1,0),o.up.set(0,0,-1),o.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),l.up.set(0,-1,0),l.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+e);for(let c of t)this.add(c),c.updateMatrixWorld()}update(e,t){this.parent===null&&this.updateMatrixWorld();let{renderTarget:n,activeMipmapLevel:i}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());let[s,o,a,l,c,h]=this.children,u=e.getRenderTarget(),f=e.getActiveCubeFace(),d=e.getActiveMipmapLevel(),m=e.xr.enabled;e.xr.enabled=!1;let _=n.texture.generateMipmaps;n.texture.generateMipmaps=!1,e.setRenderTarget(n,0,i),e.render(t,s),e.setRenderTarget(n,1,i),e.render(t,o),e.setRenderTarget(n,2,i),e.render(t,a),e.setRenderTarget(n,3,i),e.render(t,l),e.setRenderTarget(n,4,i),e.render(t,c),n.texture.generateMipmaps=_,e.setRenderTarget(n,5,i),e.render(t,h),e.setRenderTarget(u,f,d),e.xr.enabled=m,n.texture.needsPMREMUpdate=!0}},hr=class extends Kt{constructor(e=[],t=Ei,n,i,s,o,a,l,c,h){super(e,t,n,i,s,o,a,l,c,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}},pa=class extends Wn{constructor(e=1,t={}){super(e,e,t),this.isWebGLCubeRenderTarget=!0;let n={width:e,height:e,depth:1},i=[n,n,n,n,n,n];this.texture=new hr(i),this._setTextureOptions(t),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(e,t){this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;let 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 Zn(5,5,5),s=new Fn({name:"CubemapFromEquirect",uniforms:ms(n.uniforms),vertexShader:n.vertexShader,fragmentShader:n.fragmentShader,side:xn,blending:bi});s.uniforms.tEquirect.value=t;let o=new Xt(i,s),a=t.minFilter;return t.minFilter===ui&&(t.minFilter=tn),new da(1,10,this).update(e,o),t.minFilter=a,o.geometry.dispose(),o.material.dispose(),this}clear(e,t=!0,n=!0,i=!0){let s=e.getRenderTarget();for(let o=0;o<6;o++)e.setRenderTarget(this,o),e.clear(t,n,i);e.setRenderTarget(s)}},Oi=class extends bt{constructor(){super(),this.isGroup=!0,this.type="Group"}},Jx={type:"move"},Jr=class{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Oi,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 Oi,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new C,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new C),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new Oi,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new C,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new C),this._grip}dispatchEvent(e){return this._targetRay!==null&&this._targetRay.dispatchEvent(e),this._grip!==null&&this._grip.dispatchEvent(e),this._hand!==null&&this._hand.dispatchEvent(e),this}connect(e){if(e&&e.hand){let t=this._hand;if(t)for(let n of e.hand.values())this._getHandJoint(t,n)}return this.dispatchEvent({type:"connected",data:e}),this}disconnect(e){return this.dispatchEvent({type:"disconnected",data:e}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(e,t,n){let i=null,s=null,o=null,a=this._targetRay,l=this._grip,c=this._hand;if(e&&t.session.visibilityState!=="visible-blurred"){if(c&&e.hand){o=!0;for(let _ of e.hand.values()){let g=t.getJointPose(_,n),p=this._getHandJoint(c,_);g!==null&&(p.matrix.fromArray(g.transform.matrix),p.matrix.decompose(p.position,p.rotation,p.scale),p.matrixWorldNeedsUpdate=!0,p.jointRadius=g.radius),p.visible=g!==null}let h=c.joints["index-finger-tip"],u=c.joints["thumb-tip"],f=h.position.distanceTo(u.position),d=.02,m=.005;c.inputState.pinching&&f>d+m?(c.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:e.handedness,target:this})):!c.inputState.pinching&&f<=d-m&&(c.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:e.handedness,target:this}))}else l!==null&&e.gripSpace&&(s=t.getPose(e.gripSpace,n),s!==null&&(l.matrix.fromArray(s.transform.matrix),l.matrix.decompose(l.position,l.rotation,l.scale),l.matrixWorldNeedsUpdate=!0,s.linearVelocity?(l.hasLinearVelocity=!0,l.linearVelocity.copy(s.linearVelocity)):l.hasLinearVelocity=!1,s.angularVelocity?(l.hasAngularVelocity=!0,l.angularVelocity.copy(s.angularVelocity)):l.hasAngularVelocity=!1));a!==null&&(i=t.getPose(e.targetRaySpace,n),i===null&&s!==null&&(i=s),i!==null&&(a.matrix.fromArray(i.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),a.matrixWorldNeedsUpdate=!0,i.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(i.linearVelocity)):a.hasLinearVelocity=!1,i.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(i.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(Jx)))}return a!==null&&(a.visible=i!==null),l!==null&&(l.visible=s!==null),c!==null&&(c.visible=o!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){let n=new Oi;n.matrixAutoUpdate=!1,n.visible=!1,e.joints[t.jointName]=n,e.add(n)}return e.joints[t.jointName]}},ma=class r{constructor(e,t=25e-5){this.isFogExp2=!0,this.name="",this.color=new Be(e),this.density=t}clone(){return new r(this.color,this.density)}toJSON(){return{type:"FogExp2",name:this.name,color:this.color.getHex(),density:this.density}}},ga=class r{constructor(e,t=1,n=1e3){this.isFog=!0,this.name="",this.color=new Be(e),this.near=t,this.far=n}clone(){return new r(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}},_a=class extends bt{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new yn,this.environmentIntensity=1,this.environmentRotation=new yn,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(e,t){return super.copy(e,t),e.background!==null&&(this.background=e.background.clone()),e.environment!==null&&(this.environment=e.environment.clone()),e.fog!==null&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,this.backgroundRotation.copy(e.backgroundRotation),this.environmentIntensity=e.environmentIntensity,this.environmentRotation.copy(e.environmentRotation),e.overrideMaterial!==null&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){let t=super.toJSON(e);return this.fog!==null&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(t.object.environmentIntensity=this.environmentIntensity),t.object.environmentRotation=this.environmentRotation.toArray(),t}},jr=class{constructor(e,t){this.isInterleavedBuffer=!0,this.array=e,this.stride=t,this.count=e!==void 0?e.length/t:0,this.usage=Zs,this.updateRanges=[],this.version=0,this.uuid=Hn()}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.array=new e.array.constructor(e.array),this.count=e.count,this.stride=e.stride,this.usage=e.usage,this}copyAt(e,t,n){e*=this.stride,n*=t.stride;for(let i=0,s=this.stride;ie.far||t.push({distance:l,point:Zo.clone(),uv:ii.getInterpolation(Zo,Bc,jo,zc,mm,Rf,gm,new ce),face:null,object:this})}copy(e,t){return super.copy(e,t),e.center!==void 0&&this.center.copy(e.center),this.material=e.material,this}};function Vc(r,e,t,n,i,s){Os.subVectors(r,t).addScalar(.5).multiply(n),i!==void 0?(Jo.x=s*Os.x-i*Os.y,Jo.y=i*Os.x+s*Os.y):Jo.copy(Os),r.copy(e),r.x+=Jo.x,r.y+=Jo.y,r.applyMatrix4($g)}var Hc=new C,_m=new C,xa=class extends bt{constructor(){super(),this.isLOD=!0,this._currentLevel=0,this.type="LOD",Object.defineProperties(this,{levels:{enumerable:!0,value:[]}}),this.autoUpdate=!0}copy(e){super.copy(e,!1);let t=e.levels;for(let n=0,i=t.length;n0){let n,i;for(n=1,i=t.length;n0){Hc.setFromMatrixPosition(this.matrixWorld);let i=e.ray.origin.distanceTo(Hc);this.getObjectForDistance(i).raycast(e,t)}}update(e){let t=this.levels;if(t.length>1){Hc.setFromMatrixPosition(e.matrixWorld),_m.setFromMatrixPosition(this.matrixWorld);let n=Hc.distanceTo(_m)/e.zoom;t[0].object.visible=!0;let i,s;for(i=1,s=t.length;i=o)t[i-1].object.visible=!1,t[i].object.visible=!0;else break}for(this._currentLevel=i-1;i1?null:t.copy(e.start).addScaledVector(n,s)}intersectsLine(e){let t=this.distanceToPoint(e.start),n=this.distanceToPoint(e.end);return t<0&&n>0||n<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){let n=t||tv.getNormalMatrix(e),i=this.coplanarPoint(If).applyMatrix4(e),s=this.normal.applyMatrix3(n).normalize();return this.constant=-i.dot(s),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return new this.constructor().copy(this)}},Dr=new nn,nv=new ce(.5,.5),Wc=new C,Gi=class{constructor(e=new ni,t=new ni,n=new ni,i=new ni,s=new ni,o=new ni){this.planes=[e,t,n,i,s,o]}set(e,t,n,i,s,o){let a=this.planes;return a[0].copy(e),a[1].copy(t),a[2].copy(n),a[3].copy(i),a[4].copy(s),a[5].copy(o),this}copy(e){let t=this.planes;for(let n=0;n<6;n++)t[n].copy(e.planes[n]);return this}setFromProjectionMatrix(e,t=Nn,n=!1){let i=this.planes,s=e.elements,o=s[0],a=s[1],l=s[2],c=s[3],h=s[4],u=s[5],f=s[6],d=s[7],m=s[8],_=s[9],g=s[10],p=s[11],M=s[12],x=s[13],y=s[14],E=s[15];if(i[0].setComponents(c-o,d-h,p-m,E-M).normalize(),i[1].setComponents(c+o,d+h,p+m,E+M).normalize(),i[2].setComponents(c+a,d+u,p+_,E+x).normalize(),i[3].setComponents(c-a,d-u,p-_,E-x).normalize(),n)i[4].setComponents(l,f,g,y).normalize(),i[5].setComponents(c-l,d-f,p-g,E-y).normalize();else if(i[4].setComponents(c-l,d-f,p-g,E-y).normalize(),t===Nn)i[5].setComponents(c+l,d+f,p+g,E+y).normalize();else if(t===Wr)i[5].setComponents(l,f,g,y).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+t);return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),Dr.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{let t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),Dr.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(Dr)}intersectsSprite(e){Dr.center.set(0,0,0);let t=nv.distanceTo(e.center);return Dr.radius=.7071067811865476+t,Dr.applyMatrix4(e.matrixWorld),this.intersectsSphere(Dr)}intersectsSphere(e){let t=this.planes,n=e.center,i=-e.radius;for(let s=0;s<6;s++)if(t[s].distanceToPoint(n)0?e.max.x:e.min.x,Wc.y=i.normal.y>0?e.max.y:e.min.y,Wc.z=i.normal.z>0?e.max.z:e.min.z,i.distanceToPoint(Wc)<0)return!1}return!0}containsPoint(e){let t=this.planes;for(let n=0;n<6;n++)if(t[n].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}},di=new Qe,pi=new Gi,Ea=class r{constructor(){this.coordinateSystem=Nn}intersectsObject(e,t){if(!t.isArrayCamera||t.cameras.length===0)return!1;for(let n=0;n=s.length&&s.push({start:-1,count:-1,z:-1,index:-1});let a=s[this.index];o.push(a),this.index++,a.start=e,a.count=t,a.z=n,a.index=i}reset(){this.list.length=0,this.index=0}},Ln=new Qe,sv=new Be(1,1,1),Tm=new Gi,ov=new Ea,Xc=new Ct,Lr=new nn,ea=new C,Am=new C,av=new C,Lf=new $f,gn=new Xt,$c=[];function lv(r,e,t=0){let n=e.itemSize;if(r.isInterleavedBufferAttribute||r.array.constructor!==e.array.constructor){let i=r.count;for(let s=0;s65535?new Uint32Array(i):new Uint16Array(i);t.setIndex(new ht(s,1))}this._geometryInitialized=!0}}_validateGeometry(e){let t=this.geometry;if(!!e.getIndex()!=!!t.getIndex())throw new Error('THREE.BatchedMesh: All geometries must consistently have "index".');for(let n in t.attributes){if(!e.hasAttribute(n))throw new Error(`THREE.BatchedMesh: Added geometry missing "${n}". All geometries must have consistent attributes.`);let i=e.getAttribute(n),s=t.getAttribute(n);if(i.itemSize!==s.itemSize||i.normalized!==s.normalized)throw new Error("THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.")}}validateInstanceId(e){let t=this._instanceInfo;if(e<0||e>=t.length||t[e].active===!1)throw new Error(`THREE.BatchedMesh: Invalid instanceId ${e}. Instance is either out of range or has been deleted.`)}validateGeometryId(e){let t=this._geometryInfo;if(e<0||e>=t.length||t[e].active===!1)throw new Error(`THREE.BatchedMesh: Invalid geometryId ${e}. Geometry is either out of range or has been deleted.`)}setCustomSort(e){return this.customSort=e,this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Ct);let e=this.boundingBox,t=this._instanceInfo;e.makeEmpty();for(let n=0,i=t.length;n=this.maxInstanceCount&&this._availableInstanceIds.length===0)throw new Error("THREE.BatchedMesh: Maximum item count reached.");let n={visible:!0,active:!0,geometryIndex:e},i=null;this._availableInstanceIds.length>0?(this._availableInstanceIds.sort(Df),i=this._availableInstanceIds.shift(),this._instanceInfo[i]=n):(i=this._instanceInfo.length,this._instanceInfo.push(n));let s=this._matricesTexture;Ln.identity().toArray(s.image.data,i*16),s.needsUpdate=!0;let o=this._colorsTexture;return o&&(sv.toArray(o.image.data,i*4),o.needsUpdate=!0),this._visibilityChanged=!0,i}addGeometry(e,t=-1,n=-1){this._initializeGeometry(e),this._validateGeometry(e);let i={vertexStart:-1,vertexCount:-1,reservedVertexCount:-1,indexStart:-1,indexCount:-1,reservedIndexCount:-1,start:-1,count:-1,boundingBox:null,boundingSphere:null,active:!0},s=this._geometryInfo;i.vertexStart=this._nextVertexStart,i.reservedVertexCount=t===-1?e.getAttribute("position").count:t;let o=e.getIndex();if(o!==null&&(i.indexStart=this._nextIndexStart,i.reservedIndexCount=n===-1?o.count:n),i.indexStart!==-1&&i.indexStart+i.reservedIndexCount>this._maxIndexCount||i.vertexStart+i.reservedVertexCount>this._maxVertexCount)throw new Error("THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.");let l;return this._availableGeometryIds.length>0?(this._availableGeometryIds.sort(Df),l=this._availableGeometryIds.shift(),s[l]=i):(l=this._geometryCount,this._geometryCount++,s.push(i)),this.setGeometryAt(l,e),this._nextIndexStart=i.indexStart+i.reservedIndexCount,this._nextVertexStart=i.vertexStart+i.reservedVertexCount,l}setGeometryAt(e,t){if(e>=this._geometryCount)throw new Error("THREE.BatchedMesh: Maximum geometry count reached.");this._validateGeometry(t);let n=this.geometry,i=n.getIndex()!==null,s=n.getIndex(),o=t.getIndex(),a=this._geometryInfo[e];if(i&&o.count>a.reservedIndexCount||t.attributes.position.count>a.reservedVertexCount)throw new Error("THREE.BatchedMesh: Reserved space not large enough for provided geometry.");let l=a.vertexStart,c=a.reservedVertexCount;a.vertexCount=t.getAttribute("position").count;for(let h in n.attributes){let u=t.getAttribute(h),f=n.getAttribute(h);lv(u,f,l);let d=u.itemSize;for(let m=u.count,_=c;m<_;m++){let g=l+m;for(let p=0;p=t.length||t[e].active===!1)return this;let n=this._instanceInfo;for(let i=0,s=n.length;ia).sort((o,a)=>n[o].vertexStart-n[a].vertexStart),s=this.geometry;for(let o=0,a=n.length;o=this._geometryCount)return null;let n=this.geometry,i=this._geometryInfo[e];if(i.boundingBox===null){let s=new Ct,o=n.index,a=n.attributes.position;for(let l=i.start,c=i.start+i.count;l=this._geometryCount)return null;let n=this.geometry,i=this._geometryInfo[e];if(i.boundingSphere===null){let s=new nn;this.getBoundingBoxAt(e,Xc),Xc.getCenter(s.center);let o=n.index,a=n.attributes.position,l=0;for(let c=i.start,h=i.start+i.count;ca.active);if(Math.max(...n.map(a=>a.vertexStart+a.reservedVertexCount))>e)throw new Error(`BatchedMesh: Geometry vertex values are being used outside the range ${t}. Cannot shrink further.`);if(this.geometry.index&&Math.max(...n.map(l=>l.indexStart+l.reservedIndexCount))>t)throw new Error(`BatchedMesh: Geometry index values are being used outside the range ${t}. Cannot shrink further.`);let s=this.geometry;s.dispose(),this._maxVertexCount=e,this._maxIndexCount=t,this._geometryInitialized&&(this._geometryInitialized=!1,this.geometry=new et,this._initializeGeometry(s));let o=this.geometry;s.index&&Ur(s.index.array,o.index.array);for(let a in s.attributes)Ur(s.attributes[a].array,o.attributes[a].array)}raycast(e,t){let n=this._instanceInfo,i=this._geometryInfo,s=this.matrixWorld,o=this.geometry;gn.material=this.material,gn.geometry.index=o.index,gn.geometry.attributes=o.attributes,gn.geometry.boundingBox===null&&(gn.geometry.boundingBox=new Ct),gn.geometry.boundingSphere===null&&(gn.geometry.boundingSphere=new nn);for(let a=0,l=n.length;a({...t,boundingBox:t.boundingBox!==null?t.boundingBox.clone():null,boundingSphere:t.boundingSphere!==null?t.boundingSphere.clone():null})),this._instanceInfo=e._instanceInfo.map(t=>({...t})),this._availableInstanceIds=e._availableInstanceIds.slice(),this._availableGeometryIds=e._availableGeometryIds.slice(),this._nextIndexStart=e._nextIndexStart,this._nextVertexStart=e._nextVertexStart,this._geometryCount=e._geometryCount,this._maxInstanceCount=e._maxInstanceCount,this._maxVertexCount=e._maxVertexCount,this._maxIndexCount=e._maxIndexCount,this._geometryInitialized=e._geometryInitialized,this._multiDrawCounts=e._multiDrawCounts.slice(),this._multiDrawStarts=e._multiDrawStarts.slice(),this._indirectTexture=e._indirectTexture.clone(),this._indirectTexture.image.data=this._indirectTexture.image.data.slice(),this._matricesTexture=e._matricesTexture.clone(),this._matricesTexture.image.data=this._matricesTexture.image.data.slice(),this._colorsTexture!==null&&(this._colorsTexture=e._colorsTexture.clone(),this._colorsTexture.image.data=this._colorsTexture.image.data.slice()),this}dispose(){this.geometry.dispose(),this._matricesTexture.dispose(),this._matricesTexture=null,this._indirectTexture.dispose(),this._indirectTexture=null,this._colorsTexture!==null&&(this._colorsTexture.dispose(),this._colorsTexture=null)}onBeforeRender(e,t,n,i,s){if(!this._visibilityChanged&&!this.perObjectFrustumCulled&&!this.sortObjects)return;let o=i.getIndex(),a=o===null?1:o.array.BYTES_PER_ELEMENT,l=this._instanceInfo,c=this._multiDrawStarts,h=this._multiDrawCounts,u=this._geometryInfo,f=this.perObjectFrustumCulled,d=this._indirectTexture,m=d.image.data,_=n.isArrayCamera?ov:Tm;f&&!n.isArrayCamera&&(Ln.multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse).multiply(this.matrixWorld),Tm.setFromProjectionMatrix(Ln,n.coordinateSystem,n.reversedDepth));let g=0;if(this.sortObjects){Ln.copy(this.matrixWorld).invert(),ea.setFromMatrixPosition(n.matrixWorld).applyMatrix4(Ln),Am.set(0,0,-1).transformDirection(n.matrixWorld).transformDirection(Ln);for(let x=0,y=l.length;x0){let i=t[n[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=i.length;sn)return;Uf.applyMatrix4(r.matrixWorld);let c=e.ray.origin.distanceTo(Uf);if(!(ce.far))return{distance:c,point:Cm.clone().applyMatrix4(r.matrixWorld),index:o,face:null,faceIndex:null,barycoord:null,object:r}}var Pm=new C,Im=new C,$n=class extends oi{constructor(e,t){super(e,t),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){let e=this.geometry;if(e.index===null){let t=e.attributes.position,n=[];for(let i=0,s=t.count;i0){let i=t[n[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=i.length;si.far)return;s.push({distance:c,distanceToRay:Math.sqrt(a),point:l,index:e,face:null,faceIndex:null,barycoord:null,object:o})}}var Aa=class extends Kt{constructor(e,t,n,i,s=tn,o=tn,a,l,c){super(e,t,n,i,s,o,a,l,c),this.isVideoTexture=!0,this.generateMipmaps=!1,this._requestVideoFrameCallbackId=0;let h=this;function u(){h.needsUpdate=!0,h._requestVideoFrameCallbackId=e.requestVideoFrameCallback(u)}"requestVideoFrameCallback"in e&&(this._requestVideoFrameCallbackId=e.requestVideoFrameCallback(u))}clone(){return new this.constructor(this.image).copy(this)}update(){let e=this.image;"requestVideoFrameCallback"in e===!1&&e.readyState>=e.HAVE_CURRENT_DATA&&(this.needsUpdate=!0)}dispose(){this._requestVideoFrameCallbackId!==0&&this.source.data.cancelVideoFrameCallback(this._requestVideoFrameCallbackId),super.dispose()}},Eu=class extends Aa{constructor(e,t,n,i,s,o,a,l){super({},e,t,n,i,s,o,a,l),this.isVideoFrameTexture=!0}update(){}clone(){return new this.constructor().copy(this)}setFrame(e){this.image=e,this.needsUpdate=!0}},Su=class extends Kt{constructor(e,t){super({width:e,height:t}),this.isFramebufferTexture=!0,this.magFilter=un,this.minFilter=un,this.generateMipmaps=!1,this.needsUpdate=!0}},Kr=class extends Kt{constructor(e,t,n,i,s,o,a,l,c,h,u,f){super(null,o,a,l,c,h,i,s,u,f),this.isCompressedTexture=!0,this.image={width:t,height:n},this.mipmaps=e,this.flipY=!1,this.generateMipmaps=!1}},wu=class extends Kr{constructor(e,t,n,i,s,o){super(e,t,n,s,o),this.isCompressedArrayTexture=!0,this.image.depth=i,this.wrapR=Vn,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}},Tu=class extends Kr{constructor(e,t,n){super(void 0,e[0].width,e[0].height,t,n,Ei),this.isCompressedCubeTexture=!0,this.isCubeTexture=!0,this.image=e}},Au=class extends Kt{constructor(e,t,n,i,s,o,a,l,c){super(e,t,n,i,s,o,a,l,c),this.isCanvasTexture=!0,this.needsUpdate=!0}},ro=class extends Kt{constructor(e,t,n=Si,i,s,o,a=un,l=un,c,h=kr,u=1){if(h!==kr&&h!==ps)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");let f={width:e,height:t,depth:u};super(f,i,s,o,a,l,h,n,c),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.source=new ri(Object.assign({},e.image)),this.compareFunction=e.compareFunction,this}toJSON(e){let t=super.toJSON(e);return this.compareFunction!==null&&(t.compareFunction=this.compareFunction),t}},so=class extends Kt{constructor(e=null){super(),this.sourceTexture=e,this.isExternalTexture=!0}copy(e){return super.copy(e),this.sourceTexture=e.sourceTexture,this}},ki=class r extends et{constructor(e=1,t=1,n=4,i=8,s=1){super(),this.type="CapsuleGeometry",this.parameters={radius:e,height:t,capSegments:n,radialSegments:i,heightSegments:s},t=Math.max(0,t),n=Math.max(1,Math.floor(n)),i=Math.max(3,Math.floor(i)),s=Math.max(1,Math.floor(s));let o=[],a=[],l=[],c=[],h=t/2,u=Math.PI/2*e,f=t,d=2*u+f,m=n*2+s,_=i+1,g=new C,p=new C;for(let M=0;M<=m;M++){let x=0,y=0,E=0,S=0;if(M<=n){let w=M/n,T=w*Math.PI/2;y=-h-e*Math.cos(T),E=e*Math.sin(T),S=-e*Math.cos(T),x=w*u}else if(M<=n+s){let w=(M-n)/s;y=-h+w*t,E=e,S=0,x=u+w*f}else{let w=(M-n-s)/n,T=w*Math.PI/2;y=h+e*Math.sin(T),E=e*Math.cos(T),S=e*Math.sin(T),x=u+f+w*u}let R=Math.max(0,Math.min(1,x/d)),P=0;M===0?P=.5/i:M===m&&(P=-.5/i);for(let w=0;w<=i;w++){let T=w/i,N=T*Math.PI*2,V=Math.sin(N),G=Math.cos(N);p.x=-E*G,p.y=y,p.z=E*V,a.push(p.x,p.y,p.z),g.set(-E*G,S,E*V),g.normalize(),l.push(g.x,g.y,g.z),c.push(T+P,R)}if(M>0){let w=(M-1)*_;for(let T=0;T0&&x(!0),t>0&&x(!1)),this.setIndex(h),this.setAttribute("position",new De(u,3)),this.setAttribute("normal",new De(f,3)),this.setAttribute("uv",new De(d,2));function M(){let y=new C,E=new C,S=0,R=(t-e)/n;for(let P=0;P<=s;P++){let w=[],T=P/s,N=T*(t-e)+e;for(let V=0;V<=i;V++){let G=V/i,Z=G*l+a,K=Math.sin(Z),Q=Math.cos(Z);E.x=N*K,E.y=-T*n+g,E.z=N*Q,u.push(E.x,E.y,E.z),y.set(K,R,Q).normalize(),f.push(y.x,y.y,y.z),d.push(G,1-T),w.push(m++)}_.push(w)}for(let P=0;P0||w!==0)&&(h.push(T,N,G),S+=3),(t>0||w!==s-1)&&(h.push(N,V,G),S+=3)}c.addGroup(p,S,0),p+=S}function x(y){let E=m,S=new ce,R=new C,P=0,w=y===!0?e:t,T=y===!0?1:-1;for(let V=1;V<=i;V++)u.push(0,g*T,0),f.push(0,T,0),d.push(.5,.5),m++;let N=m;for(let V=0;V<=i;V++){let Z=V/i*l+a,K=Math.cos(Z),Q=Math.sin(Z);R.x=w*Q,R.y=g*T,R.z=w*K,u.push(R.x,R.y,R.z),f.push(0,T,0),S.x=K*.5+.5,S.y=Q*.5*T+.5,d.push(S.x,S.y),m++}for(let V=0;V.9&&R<.1&&(x<.2&&(o[M+0]+=1),y<.2&&(o[M+2]+=1),E<.2&&(o[M+4]+=1))}}function f(M){s.push(M.x,M.y,M.z)}function d(M,x){let y=M*3;x.x=e[y+0],x.y=e[y+1],x.z=e[y+2]}function m(){let M=new C,x=new C,y=new C,E=new C,S=new ce,R=new ce,P=new ce;for(let w=0,T=0;w0)l=i-1;else{l=i;break}if(i=l,n[i]===o)return i/(s-1);let h=n[i],f=n[i+1]-h,d=(o-h)/f;return(i+d)/(s-1)}getTangent(e,t){let i=e-1e-4,s=e+1e-4;i<0&&(i=0),s>1&&(s=1);let o=this.getPoint(i),a=this.getPoint(s),l=t||(o.isVector2?new ce:new C);return l.copy(a).sub(o).normalize(),l}getTangentAt(e,t){let n=this.getUtoTmapping(e);return this.getTangent(n,t)}computeFrenetFrames(e,t=!1){let n=new C,i=[],s=[],o=[],a=new C,l=new Qe;for(let d=0;d<=e;d++){let m=d/e;i[d]=this.getTangentAt(m,new C)}s[0]=new C,o[0]=new C;let c=Number.MAX_VALUE,h=Math.abs(i[0].x),u=Math.abs(i[0].y),f=Math.abs(i[0].z);h<=c&&(c=h,n.set(1,0,0)),u<=c&&(c=u,n.set(0,1,0)),f<=c&&n.set(0,0,1),a.crossVectors(i[0],n).normalize(),s[0].crossVectors(i[0],a),o[0].crossVectors(i[0],s[0]);for(let d=1;d<=e;d++){if(s[d]=s[d-1].clone(),o[d]=o[d-1].clone(),a.crossVectors(i[d-1],i[d]),a.length()>Number.EPSILON){a.normalize();let m=Math.acos(at(i[d-1].dot(i[d]),-1,1));s[d].applyMatrix4(l.makeRotationAxis(a,m))}o[d].crossVectors(i[d],s[d])}if(t===!0){let d=Math.acos(at(s[0].dot(s[e]),-1,1));d/=e,i[0].dot(a.crossVectors(s[0],s[e]))>0&&(d=-d);for(let m=1;m<=e;m++)s[m].applyMatrix4(l.makeRotationAxis(i[m],d*m)),o[m].crossVectors(i[m],s[m])}return{tangents:i,normals:s,binormals:o}}clone(){return new this.constructor().copy(this)}copy(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}toJSON(){let e={metadata:{version:4.7,type:"Curve",generator:"Curve.toJSON"}};return e.arcLengthDivisions=this.arcLengthDivisions,e.type=this.type,e}fromJSON(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}},Qr=class extends On{constructor(e=0,t=0,n=1,i=1,s=0,o=Math.PI*2,a=!1,l=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=e,this.aY=t,this.xRadius=n,this.yRadius=i,this.aStartAngle=s,this.aEndAngle=o,this.aClockwise=a,this.aRotation=l}getPoint(e,t=new ce){let n=t,i=Math.PI*2,s=this.aEndAngle-this.aStartAngle,o=Math.abs(s)i;)s-=i;s0?0:(Math.floor(Math.abs(a)/s)+1)*s:l===0&&a===s-1&&(a=s-2,l=1);let c,h;this.closed||a>0?c=i[(a-1)%s]:(eu.subVectors(i[0],i[1]).add(i[0]),c=eu);let u=i[a%s],f=i[(a+1)%s];if(this.closed||a+2i.length-2?i.length-1:o+1],u=i[o>i.length-3?i.length-1:o+2];return n.set(Um(a,l.x,c.x,h.x,u.x),Um(a,l.y,c.y,h.y,u.y)),n}copy(e){super.copy(e),this.points=[];for(let t=0,n=e.points.length;t=n){let o=i[s]-n,a=this.curves[s],l=a.getLength(),c=l===0?0:1-o/l;return a.getPointAt(c,t)}s++}return null}getLength(){let e=this.getCurveLengths();return e[e.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;let e=[],t=0;for(let n=0,i=this.curves.length;n1&&!t[t.length-1].equals(t[0])&&t.push(t[0]),t}copy(e){super.copy(e),this.curves=[];for(let t=0,n=e.curves.length;t0){let u=c.getPoint(0);u.equals(this.currentPoint)||this.lineTo(u.x,u.y)}this.curves.push(c);let h=c.getPoint(1);return this.currentPoint.copy(h),this}copy(e){return super.copy(e),this.currentPoint.copy(e.currentPoint),this}toJSON(){let e=super.toJSON();return e.currentPoint=this.currentPoint.toArray(),e}fromJSON(e){return super.fromJSON(e),this.currentPoint.fromArray(e.currentPoint),this}},mi=class extends ns{constructor(e){super(e),this.uuid=Hn(),this.type="Shape",this.holes=[]}getPointsHoles(e){let t=[];for(let n=0,i=this.holes.length;n80*t){a=1/0,l=1/0;let h=-1/0,u=-1/0;for(let f=t;fh&&(h=d),m>u&&(u=m)}c=Math.max(h-a,u-l),c=c!==0?32767/c:0}return Ua(s,o,t,a,l,c,0),o}function qg(r,e,t,n,i){let s;if(i===Dv(r,e,t,n)>0)for(let o=e;o=e;o-=n)s=Nm(o/n|0,r[o],r[o+1],s);return s&&uo(s,s.next)&&(Fa(s),s=s.next),s}function is(r,e){if(!r)return r;e||(e=r);let t=r,n;do if(n=!1,!t.steiner&&(uo(t,t.next)||qt(t.prev,t,t.next)===0)){if(Fa(t),t=e=t.prev,t===t.next)break;n=!0}else t=t.next;while(n||t!==e);return e}function Ua(r,e,t,n,i,s,o){if(!r)return;!o&&s&&Tv(r,n,i,s);let a=r;for(;r.prev!==r.next;){let l=r.prev,c=r.next;if(s?yv(r,n,i,s):_v(r)){e.push(l.i,r.i,c.i),Fa(r),r=c.next,a=c.next;continue}if(r=c,r===a){o?o===1?(r=xv(is(r),e),Ua(r,e,t,n,i,s,2)):o===2&&vv(r,e,t,n,i,s):Ua(is(r),e,t,n,i,s,1);break}}}function _v(r){let e=r.prev,t=r,n=r.next;if(qt(e,t,n)>=0)return!1;let i=e.x,s=t.x,o=n.x,a=e.y,l=t.y,c=n.y,h=Math.min(i,s,o),u=Math.min(a,l,c),f=Math.max(i,s,o),d=Math.max(a,l,c),m=n.next;for(;m!==e;){if(m.x>=h&&m.x<=f&&m.y>=u&&m.y<=d&&ra(i,a,s,l,o,c,m.x,m.y)&&qt(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function yv(r,e,t,n){let i=r.prev,s=r,o=r.next;if(qt(i,s,o)>=0)return!1;let a=i.x,l=s.x,c=o.x,h=i.y,u=s.y,f=o.y,d=Math.min(a,l,c),m=Math.min(h,u,f),_=Math.max(a,l,c),g=Math.max(h,u,f),p=Yf(d,m,e,t,n),M=Yf(_,g,e,t,n),x=r.prevZ,y=r.nextZ;for(;x&&x.z>=p&&y&&y.z<=M;){if(x.x>=d&&x.x<=_&&x.y>=m&&x.y<=g&&x!==i&&x!==o&&ra(a,h,l,u,c,f,x.x,x.y)&&qt(x.prev,x,x.next)>=0||(x=x.prevZ,y.x>=d&&y.x<=_&&y.y>=m&&y.y<=g&&y!==i&&y!==o&&ra(a,h,l,u,c,f,y.x,y.y)&&qt(y.prev,y,y.next)>=0))return!1;y=y.nextZ}for(;x&&x.z>=p;){if(x.x>=d&&x.x<=_&&x.y>=m&&x.y<=g&&x!==i&&x!==o&&ra(a,h,l,u,c,f,x.x,x.y)&&qt(x.prev,x,x.next)>=0)return!1;x=x.prevZ}for(;y&&y.z<=M;){if(y.x>=d&&y.x<=_&&y.y>=m&&y.y<=g&&y!==i&&y!==o&&ra(a,h,l,u,c,f,y.x,y.y)&&qt(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function xv(r,e){let t=r;do{let n=t.prev,i=t.next.next;!uo(n,i)&&Zg(n,t,t.next,i)&&Na(n,i)&&Na(i,n)&&(e.push(n.i,t.i,i.i),Fa(t),Fa(t.next),t=r=i),t=t.next}while(t!==r);return is(t)}function vv(r,e,t,n,i,s){let o=r;do{let a=o.next.next;for(;a!==o.prev;){if(o.i!==a.i&&Cv(o,a)){let l=Jg(o,a);o=is(o,o.next),l=is(l,l.next),Ua(o,e,t,n,i,s,0),Ua(l,e,t,n,i,s,0);return}a=a.next}o=o.next}while(o!==r)}function bv(r,e,t,n){let i=[];for(let s=0,o=e.length;s=t.next.y&&t.next.y!==t.y){let u=t.x+(i-t.y)*(t.next.x-t.x)/(t.next.y-t.y);if(u<=n&&u>s&&(s=u,o=t.x=t.x&&t.x>=l&&n!==t.x&&Yg(io.x||t.x===o.x&&wv(o,t)))&&(o=t,h=u)}t=t.next}while(t!==a);return o}function wv(r,e){return qt(r.prev,r,e.prev)<0&&qt(e.next,r,r.next)<0}function Tv(r,e,t,n){let i=r;do i.z===0&&(i.z=Yf(i.x,i.y,e,t,n)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next;while(i!==r);i.prevZ.nextZ=null,i.prevZ=null,Av(i)}function Av(r){let e,t=1;do{let n=r,i;r=null;let s=null;for(e=0;n;){e++;let o=n,a=0;for(let c=0;c0||l>0&&o;)a!==0&&(l===0||!o||n.z<=o.z)?(i=n,n=n.nextZ,a--):(i=o,o=o.nextZ,l--),s?s.nextZ=i:r=i,i.prevZ=s,s=i;n=o}s.nextZ=null,t*=2}while(e>1);return r}function Yf(r,e,t,n,i){return r=(r-t)*i|0,e=(e-n)*i|0,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,r|e<<1}function Rv(r){let e=r,t=r;do(e.x=(r-o)*(s-a)&&(r-o)*(n-a)>=(t-o)*(e-a)&&(t-o)*(s-a)>=(i-o)*(n-a)}function ra(r,e,t,n,i,s,o,a){return!(r===o&&e===a)&&Yg(r,e,t,n,i,s,o,a)}function Cv(r,e){return r.next.i!==e.i&&r.prev.i!==e.i&&!Pv(r,e)&&(Na(r,e)&&Na(e,r)&&Iv(r,e)&&(qt(r.prev,r,e.prev)||qt(r,e.prev,e))||uo(r,e)&&qt(r.prev,r,r.next)>0&&qt(e.prev,e,e.next)>0)}function qt(r,e,t){return(e.y-r.y)*(t.x-e.x)-(e.x-r.x)*(t.y-e.y)}function uo(r,e){return r.x===e.x&&r.y===e.y}function Zg(r,e,t,n){let i=nu(qt(r,e,t)),s=nu(qt(r,e,n)),o=nu(qt(t,n,r)),a=nu(qt(t,n,e));return!!(i!==s&&o!==a||i===0&&tu(r,t,e)||s===0&&tu(r,n,e)||o===0&&tu(t,r,n)||a===0&&tu(t,e,n))}function tu(r,e,t){return e.x<=Math.max(r.x,t.x)&&e.x>=Math.min(r.x,t.x)&&e.y<=Math.max(r.y,t.y)&&e.y>=Math.min(r.y,t.y)}function nu(r){return r>0?1:r<0?-1:0}function Pv(r,e){let t=r;do{if(t.i!==r.i&&t.next.i!==r.i&&t.i!==e.i&&t.next.i!==e.i&&Zg(t,t.next,r,e))return!0;t=t.next}while(t!==r);return!1}function Na(r,e){return qt(r.prev,r,r.next)<0?qt(r,e,r.next)>=0&&qt(r,r.prev,e)>=0:qt(r,e,r.prev)<0||qt(r,r.next,e)<0}function Iv(r,e){let t=r,n=!1,i=(r.x+e.x)/2,s=(r.y+e.y)/2;do t.y>s!=t.next.y>s&&t.next.y!==t.y&&i<(t.next.x-t.x)*(s-t.y)/(t.next.y-t.y)+t.x&&(n=!n),t=t.next;while(t!==r);return n}function Jg(r,e){let t=Zf(r.i,r.x,r.y),n=Zf(e.i,e.x,e.y),i=r.next,s=e.prev;return r.next=e,e.prev=r,t.next=i,i.prev=t,n.next=t,t.prev=n,s.next=n,n.prev=s,n}function Nm(r,e,t,n){let i=Zf(r,e,t);return n?(i.next=n.next,i.prev=n,n.next.prev=i,n.next=i):(i.prev=i,i.next=i),i}function Fa(r){r.next.prev=r.prev,r.prev.next=r.next,r.prevZ&&(r.prevZ.nextZ=r.nextZ),r.nextZ&&(r.nextZ.prevZ=r.prevZ)}function Zf(r,e,t){return{i:r,x:e,y:t,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function Dv(r,e,t,n){let i=0;for(let s=e,o=t-n;s2&&r[e-1].equals(r[0])&&r.pop()}function Om(r,e){for(let t=0;tNumber.EPSILON){let ee=Math.sqrt(A),de=Math.sqrt(lt*lt+L*L),ie=he.x-ft/ee,He=he.y+we/ee,Ee=oe.x-L/de,ke=oe.y+lt/de,Je=((Ee-ie)*L-(ke-He)*lt)/(we*L-ft*lt);ae=ie+we*Je-pe.x,ve=He+ft*Je-pe.y;let ye=ae*ae+ve*ve;if(ye<=2)return new ce(ae,ve);be=Math.sqrt(ye/2)}else{let ee=!1;we>Number.EPSILON?lt>Number.EPSILON&&(ee=!0):we<-Number.EPSILON?lt<-Number.EPSILON&&(ee=!0):Math.sign(ft)===Math.sign(L)&&(ee=!0),ee?(ae=-ft,ve=we,be=Math.sqrt(A)):(ae=we,ve=ft,be=Math.sqrt(A/2))}return new ce(ae/be,ve/be)}let Te=[];for(let pe=0,he=K.length,oe=he-1,ae=pe+1;pe=0;pe--){let he=pe/g,oe=d*Math.cos(he*Math.PI/2),ae=m*Math.sin(he*Math.PI/2)+_;for(let ve=0,be=K.length;ve=0;){let ae=oe,ve=oe-1;ve<0&&(ve=pe.length-1);for(let be=0,we=h+g*2;be0)&&d.push(x,y,S),(p!==n-1||l0!=e>0&&this.version++,this._anisotropy=e}get clearcoat(){return this._clearcoat}set clearcoat(e){this._clearcoat>0!=e>0&&this.version++,this._clearcoat=e}get iridescence(){return this._iridescence}set iridescence(e){this._iridescence>0!=e>0&&this.version++,this._iridescence=e}get dispersion(){return this._dispersion}set dispersion(e){this._dispersion>0!=e>0&&this.version++,this._dispersion=e}get sheen(){return this._sheen}set sheen(e){this._sheen>0!=e>0&&this.version++,this._sheen=e}get transmission(){return this._transmission}set transmission(e){this._transmission>0!=e>0&&this.version++,this._transmission=e}copy(e){return super.copy(e),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=e.anisotropy,this.anisotropyRotation=e.anisotropyRotation,this.anisotropyMap=e.anisotropyMap,this.clearcoat=e.clearcoat,this.clearcoatMap=e.clearcoatMap,this.clearcoatRoughness=e.clearcoatRoughness,this.clearcoatRoughnessMap=e.clearcoatRoughnessMap,this.clearcoatNormalMap=e.clearcoatNormalMap,this.clearcoatNormalScale.copy(e.clearcoatNormalScale),this.dispersion=e.dispersion,this.ior=e.ior,this.iridescence=e.iridescence,this.iridescenceMap=e.iridescenceMap,this.iridescenceIOR=e.iridescenceIOR,this.iridescenceThicknessRange=[...e.iridescenceThicknessRange],this.iridescenceThicknessMap=e.iridescenceThicknessMap,this.sheen=e.sheen,this.sheenColor.copy(e.sheenColor),this.sheenColorMap=e.sheenColorMap,this.sheenRoughness=e.sheenRoughness,this.sheenRoughnessMap=e.sheenRoughnessMap,this.transmission=e.transmission,this.transmissionMap=e.transmissionMap,this.thickness=e.thickness,this.thicknessMap=e.thicknessMap,this.attenuationDistance=e.attenuationDistance,this.attenuationColor.copy(e.attenuationColor),this.specularIntensity=e.specularIntensity,this.specularIntensityMap=e.specularIntensityMap,this.specularColor.copy(e.specularColor),this.specularColorMap=e.specularColorMap,this}},qa=class extends rn{constructor(e){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new Be(16777215),this.specular=new Be(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Be(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=qi,this.normalScale=new ce(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new yn,this.combine=bo,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(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.specular.copy(e.specular),this.shininess=e.shininess,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}},Ya=class extends rn{constructor(e){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new Be(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Be(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=qi,this.normalScale=new ce(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.gradientMap=e.gradientMap,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.alphaMap=e.alphaMap,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}},Za=class extends rn{constructor(e){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=qi,this.normalScale=new ce(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(e)}copy(e){return super.copy(e),this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.flatShading=e.flatShading,this}},Ja=class extends rn{constructor(e){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new Be(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Be(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=qi,this.normalScale=new ce(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new yn,this.combine=bo,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(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}},po=class extends rn{constructor(e){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=zd,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(e)}copy(e){return super.copy(e),this.depthPacking=e.depthPacking,this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this}},mo=class extends rn{constructor(e){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(e)}copy(e){return super.copy(e),this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this}},ja=class extends rn{constructor(e){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new Be(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=qi,this.normalScale=new ce(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={MATCAP:""},this.color.copy(e.color),this.matcap=e.matcap,this.map=e.map,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.alphaMap=e.alphaMap,this.flatShading=e.flatShading,this.fog=e.fog,this}},Ka=class extends hn{constructor(e){super(),this.isLineDashedMaterial=!0,this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(e)}copy(e){return super.copy(e),this.scale=e.scale,this.dashSize=e.dashSize,this.gapSize=e.gapSize,this}};function Hr(r,e){return!r||r.constructor===e?r:typeof e.BYTES_PER_ELEMENT=="number"?new e(r):Array.prototype.slice.call(r)}function jg(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}function Kg(r){function e(i,s){return r[i]-r[s]}let t=r.length,n=new Array(t);for(let i=0;i!==t;++i)n[i]=i;return n.sort(e),n}function jf(r,e,t){let n=r.length,i=new r.constructor(n);for(let s=0,o=0;o!==n;++s){let a=t[s]*e;for(let l=0;l!==e;++l)i[o++]=r[a+l]}return i}function tp(r,e,t,n){let i=1,s=r[0];for(;s!==void 0&&s[n]===void 0;)s=r[i++];if(s===void 0)return;let o=s[n];if(o!==void 0)if(Array.isArray(o))do o=s[n],o!==void 0&&(e.push(s.time),t.push(...o)),s=r[i++];while(s!==void 0);else if(o.toArray!==void 0)do o=s[n],o!==void 0&&(e.push(s.time),o.toArray(t,t.length)),s=r[i++];while(s!==void 0);else do o=s[n],o!==void 0&&(e.push(s.time),t.push(o)),s=r[i++];while(s!==void 0)}function Fv(r,e,t,n,i=30){let s=r.clone();s.name=e;let o=[];for(let l=0;l=n)){u.push(c.times[d]);for(let _=0;_s.tracks[l].times[0]&&(a=s.tracks[l].times[0]);for(let l=0;l=a.times[m]){let p=m*u+h,M=p+u-h;_=a.values.slice(p,M)}else{let p=a.createInterpolant(),M=h,x=u-h;p.evaluate(s),_=p.resultBuffer.slice(M,x)}l==="quaternion"&&new Vt().fromArray(_).normalize().conjugate().toArray(_);let g=c.times.length;for(let p=0;p=s)){let a=t[1];e=s)break t}o=n,n=0;break n}break e}for(;n>>1;et;)--o;if(++o,s!==0||o!==i){s>=o&&(o=Math.max(o,1),s=o-1);let a=this.getValueSize();this.times=n.slice(s,o),this.values=this.values.slice(s*a,o*a)}return this}validate(){let e=!0,t=this.getValueSize();t-Math.floor(t)!==0&&(console.error("THREE.KeyframeTrack: Invalid value size in track.",this),e=!1);let n=this.times,i=this.values,s=n.length;s===0&&(console.error("THREE.KeyframeTrack: Track is empty.",this),e=!1);let o=null;for(let a=0;a!==s;a++){let l=n[a];if(typeof l=="number"&&isNaN(l)){console.error("THREE.KeyframeTrack: Time is not a valid number.",this,a,l),e=!1;break}if(o!==null&&o>l){console.error("THREE.KeyframeTrack: Out of order keys.",this,a,l,o),e=!1;break}o=l}if(i!==void 0&&jg(i))for(let a=0,l=i.length;a!==l;++a){let c=i[a];if(isNaN(c)){console.error("THREE.KeyframeTrack: Value is not a valid number.",this,a,c),e=!1;break}}return e}optimize(){let e=this.times.slice(),t=this.values.slice(),n=this.getValueSize(),i=this.getInterpolation()===sa,s=e.length-1,o=1;for(let a=1;a0){e[o]=e[s];for(let a=s*n,l=o*n,c=0;c!==n;++c)t[l+c]=t[a+c];++o}return o!==e.length?(this.times=e.slice(0,o),this.values=t.slice(0,o*n)):(this.times=e,this.values=t),this}clone(){let e=this.times.slice(),t=this.values.slice(),n=this.constructor,i=new n(this.name,e,t);return i.createInterpolant=this.createInterpolant,i}};Cn.prototype.ValueTypeName="";Cn.prototype.TimeBufferType=Float32Array;Cn.prototype.ValueBufferType=Float32Array;Cn.prototype.DefaultInterpolation=ha;var xi=class extends Cn{constructor(e,t,n){super(e,t,n)}};xi.prototype.ValueTypeName="bool";xi.prototype.ValueBufferType=Array;xi.prototype.DefaultInterpolation=$s;xi.prototype.InterpolantFactoryMethodLinear=void 0;xi.prototype.InterpolantFactoryMethodSmooth=void 0;var _o=class extends Cn{constructor(e,t,n,i){super(e,t,n,i)}};_o.prototype.ValueTypeName="color";var gr=class extends Cn{constructor(e,t,n,i){super(e,t,n,i)}};gr.prototype.ValueTypeName="number";var tl=class extends mr{constructor(e,t,n,i){super(e,t,n,i)}interpolate_(e,t,n,i){let s=this.resultBuffer,o=this.sampleValues,a=this.valueSize,l=(n-t)/(i-t),c=e*a;for(let h=c+a;c!==h;c+=4)Vt.slerpFlat(s,0,o,c-a,o,c,l);return s}},_r=class extends Cn{constructor(e,t,n,i){super(e,t,n,i)}InterpolantFactoryMethodLinear(e){return new tl(this.times,this.values,this.getValueSize(),e)}};_r.prototype.ValueTypeName="quaternion";_r.prototype.InterpolantFactoryMethodSmooth=void 0;var vi=class extends Cn{constructor(e,t,n){super(e,t,n)}};vi.prototype.ValueTypeName="string";vi.prototype.ValueBufferType=Array;vi.prototype.DefaultInterpolation=$s;vi.prototype.InterpolantFactoryMethodLinear=void 0;vi.prototype.InterpolantFactoryMethodSmooth=void 0;var yr=class extends Cn{constructor(e,t,n,i){super(e,t,n,i)}};yr.prototype.ValueTypeName="vector";var xr=class{constructor(e="",t=-1,n=[],i=ac){this.name=e,this.tracks=n,this.duration=t,this.blendMode=i,this.uuid=Hn(),this.userData={},this.duration<0&&this.resetDuration()}static parse(e){let t=[],n=e.tracks,i=1/(e.fps||1);for(let o=0,a=n.length;o!==a;++o)t.push(zv(n[o]).scale(i));let s=new this(e.name,e.duration,t,e.blendMode);return s.uuid=e.uuid,s.userData=JSON.parse(e.userData||"{}"),s}static toJSON(e){let t=[],n=e.tracks,i={name:e.name,duration:e.duration,tracks:t,uuid:e.uuid,blendMode:e.blendMode,userData:JSON.stringify(e.userData)};for(let s=0,o=n.length;s!==o;++s)t.push(Cn.toJSON(n[s]));return i}static CreateFromMorphTargetSequence(e,t,n,i){let s=t.length,o=[];for(let a=0;a1){let u=h[1],f=i[u];f||(i[u]=f=[]),f.push(c)}}let o=[];for(let a in i)o.push(this.CreateFromMorphTargetSequence(a,i[a],t,n));return o}static parseAnimation(e,t){if(console.warn("THREE.AnimationClip: parseAnimation() is deprecated and will be removed with r185"),!e)return console.error("THREE.AnimationClip: No animation in JSONLoader data."),null;let n=function(u,f,d,m,_){if(d.length!==0){let g=[],p=[];tp(d,g,p,m),g.length!==0&&_.push(new u(f,g,p))}},i=[],s=e.name||"default",o=e.fps||30,a=e.blendMode,l=e.length||-1,c=e.hierarchy||[];for(let u=0;u{t&&t(s),this.manager.itemEnd(e)},0),s;if(Ni[e]!==void 0){Ni[e].push({onLoad:t,onProgress:n,onError:i});return}Ni[e]=[],Ni[e].push({onLoad:t,onProgress:n,onError:i});let o=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin",signal:typeof AbortSignal.any=="function"?AbortSignal.any([this._abortController.signal,this.manager.abortController.signal]):this._abortController.signal}),a=this.mimeType,l=this.responseType;fetch(o).then(c=>{if(c.status===200||c.status===0){if(c.status===0&&console.warn("THREE.FileLoader: HTTP Status 0 received."),typeof ReadableStream>"u"||c.body===void 0||c.body.getReader===void 0)return c;let h=Ni[e],u=c.body.getReader(),f=c.headers.get("X-File-Size")||c.headers.get("Content-Length"),d=f?parseInt(f):0,m=d!==0,_=0,g=new ReadableStream({start(p){M();function M(){u.read().then(({done:x,value:y})=>{if(x)p.close();else{_+=y.byteLength;let E=new ProgressEvent("progress",{lengthComputable:m,loaded:_,total:d});for(let S=0,R=h.length;S{p.error(x)})}}});return new Response(g)}else throw new Kf(`fetch for "${c.url}" responded with ${c.status}: ${c.statusText}`,c)}).then(c=>{switch(l){case"arraybuffer":return c.arrayBuffer();case"blob":return c.blob();case"document":return c.text().then(h=>new DOMParser().parseFromString(h,a));case"json":return c.json();default:if(a==="")return c.text();{let u=/charset="?([^;"\s]*)"?/i.exec(a),f=u&&u[1]?u[1].toLowerCase():void 0,d=new TextDecoder(f);return c.arrayBuffer().then(m=>d.decode(m))}}}).then(c=>{si.add(`file:${e}`,c);let h=Ni[e];delete Ni[e];for(let u=0,f=h.length;u{let h=Ni[e];if(h===void 0)throw this.manager.itemError(e),c;delete Ni[e];for(let u=0,f=h.length;u{this.manager.itemEnd(e)}),this.manager.itemStart(e)}setResponseType(e){return this.responseType=e,this}setMimeType(e){return this.mimeType=e,this}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}},Pu=class extends fn{constructor(e){super(e)}load(e,t,n,i){let s=this,o=new Jn(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(a){try{t(s.parse(JSON.parse(a)))}catch(l){i?i(l):console.error(l),s.manager.itemError(e)}},n,i)}parse(e){let t=[];for(let n=0;n0:i.vertexColors=e.vertexColors),e.uniforms!==void 0)for(let s in e.uniforms){let o=e.uniforms[s];switch(i.uniforms[s]={},o.type){case"t":i.uniforms[s].value=n(o.value);break;case"c":i.uniforms[s].value=new Be().setHex(o.value);break;case"v2":i.uniforms[s].value=new ce().fromArray(o.value);break;case"v3":i.uniforms[s].value=new C().fromArray(o.value);break;case"v4":i.uniforms[s].value=new At().fromArray(o.value);break;case"m3":i.uniforms[s].value=new pt().fromArray(o.value);break;case"m4":i.uniforms[s].value=new Qe().fromArray(o.value);break;default:i.uniforms[s].value=o.value}}if(e.defines!==void 0&&(i.defines=e.defines),e.vertexShader!==void 0&&(i.vertexShader=e.vertexShader),e.fragmentShader!==void 0&&(i.fragmentShader=e.fragmentShader),e.glslVersion!==void 0&&(i.glslVersion=e.glslVersion),e.extensions!==void 0)for(let s in e.extensions)i.extensions[s]=e.extensions[s];if(e.lights!==void 0&&(i.lights=e.lights),e.clipping!==void 0&&(i.clipping=e.clipping),e.size!==void 0&&(i.size=e.size),e.sizeAttenuation!==void 0&&(i.sizeAttenuation=e.sizeAttenuation),e.map!==void 0&&(i.map=n(e.map)),e.matcap!==void 0&&(i.matcap=n(e.matcap)),e.alphaMap!==void 0&&(i.alphaMap=n(e.alphaMap)),e.bumpMap!==void 0&&(i.bumpMap=n(e.bumpMap)),e.bumpScale!==void 0&&(i.bumpScale=e.bumpScale),e.normalMap!==void 0&&(i.normalMap=n(e.normalMap)),e.normalMapType!==void 0&&(i.normalMapType=e.normalMapType),e.normalScale!==void 0){let s=e.normalScale;Array.isArray(s)===!1&&(s=[s,s]),i.normalScale=new ce().fromArray(s)}return e.displacementMap!==void 0&&(i.displacementMap=n(e.displacementMap)),e.displacementScale!==void 0&&(i.displacementScale=e.displacementScale),e.displacementBias!==void 0&&(i.displacementBias=e.displacementBias),e.roughnessMap!==void 0&&(i.roughnessMap=n(e.roughnessMap)),e.metalnessMap!==void 0&&(i.metalnessMap=n(e.metalnessMap)),e.emissiveMap!==void 0&&(i.emissiveMap=n(e.emissiveMap)),e.emissiveIntensity!==void 0&&(i.emissiveIntensity=e.emissiveIntensity),e.specularMap!==void 0&&(i.specularMap=n(e.specularMap)),e.specularIntensityMap!==void 0&&(i.specularIntensityMap=n(e.specularIntensityMap)),e.specularColorMap!==void 0&&(i.specularColorMap=n(e.specularColorMap)),e.envMap!==void 0&&(i.envMap=n(e.envMap)),e.envMapRotation!==void 0&&i.envMapRotation.fromArray(e.envMapRotation),e.envMapIntensity!==void 0&&(i.envMapIntensity=e.envMapIntensity),e.reflectivity!==void 0&&(i.reflectivity=e.reflectivity),e.refractionRatio!==void 0&&(i.refractionRatio=e.refractionRatio),e.lightMap!==void 0&&(i.lightMap=n(e.lightMap)),e.lightMapIntensity!==void 0&&(i.lightMapIntensity=e.lightMapIntensity),e.aoMap!==void 0&&(i.aoMap=n(e.aoMap)),e.aoMapIntensity!==void 0&&(i.aoMapIntensity=e.aoMapIntensity),e.gradientMap!==void 0&&(i.gradientMap=n(e.gradientMap)),e.clearcoatMap!==void 0&&(i.clearcoatMap=n(e.clearcoatMap)),e.clearcoatRoughnessMap!==void 0&&(i.clearcoatRoughnessMap=n(e.clearcoatRoughnessMap)),e.clearcoatNormalMap!==void 0&&(i.clearcoatNormalMap=n(e.clearcoatNormalMap)),e.clearcoatNormalScale!==void 0&&(i.clearcoatNormalScale=new ce().fromArray(e.clearcoatNormalScale)),e.iridescenceMap!==void 0&&(i.iridescenceMap=n(e.iridescenceMap)),e.iridescenceThicknessMap!==void 0&&(i.iridescenceThicknessMap=n(e.iridescenceThicknessMap)),e.transmissionMap!==void 0&&(i.transmissionMap=n(e.transmissionMap)),e.thicknessMap!==void 0&&(i.thicknessMap=n(e.thicknessMap)),e.anisotropyMap!==void 0&&(i.anisotropyMap=n(e.anisotropyMap)),e.sheenColorMap!==void 0&&(i.sheenColorMap=n(e.sheenColorMap)),e.sheenRoughnessMap!==void 0&&(i.sheenRoughnessMap=n(e.sheenRoughnessMap)),i}setTextures(e){return this.textures=e,this}createMaterialFromType(e){return r.createMaterialFromType(e)}static createMaterialFromType(e){let t={ShadowMaterial:Wa,SpriteMaterial:to,RawShaderMaterial:Xa,ShaderMaterial:Fn,PointsMaterial:io,MeshPhysicalMaterial:$a,MeshStandardMaterial:fo,MeshPhongMaterial:qa,MeshToonMaterial:Ya,MeshNormalMaterial:Za,MeshLambertMaterial:Ja,MeshDepthMaterial:po,MeshDistanceMaterial:mo,MeshBasicMaterial:Xn,MeshMatcapMaterial:ja,LineDashedMaterial:Ka,LineBasicMaterial:hn,Material:rn};return new t[e]}},xo=class{static extractUrlBase(e){let t=e.lastIndexOf("/");return t===-1?"./":e.slice(0,t+1)}static resolveURL(e,t){return typeof e!="string"||e===""?"":(/^https?:\/\//i.test(t)&&/^\//.test(e)&&(t=t.replace(/(^https?:\/\/[^\/]+).*/i,"$1")),/^(https?:)?\/\//i.test(e)||/^data:.*,.*$/i.test(e)||/^blob:.*$/i.test(e)?e:t+e)}},fl=class extends et{constructor(){super(),this.isInstancedBufferGeometry=!0,this.type="InstancedBufferGeometry",this.instanceCount=1/0}copy(e){return super.copy(e),this.instanceCount=e.instanceCount,this}toJSON(){let e=super.toJSON();return e.instanceCount=this.instanceCount,e.isInstancedBufferGeometry=!0,e}},dl=class extends fn{constructor(e){super(e)}load(e,t,n,i){let s=this,o=new Jn(s.manager);o.setPath(s.path),o.setRequestHeader(s.requestHeader),o.setWithCredentials(s.withCredentials),o.load(e,function(a){try{t(s.parse(JSON.parse(a)))}catch(l){i?i(l):console.error(l),s.manager.itemError(e)}},n,i)}parse(e){let t={},n={};function i(d,m){if(t[m]!==void 0)return t[m];let g=d.interleavedBuffers[m],p=s(d,g.buffer),M=Gs(g.type,p),x=new jr(M,g.stride);return x.uuid=g.uuid,t[m]=x,x}function s(d,m){if(n[m]!==void 0)return n[m];let g=d.arrayBuffers[m],p=new Uint32Array(g).buffer;return n[m]=p,p}let o=e.isInstancedBufferGeometry?new fl:new et,a=e.data.index;if(a!==void 0){let d=Gs(a.type,a.array);o.setIndex(new ht(d,1))}let l=e.data.attributes;for(let d in l){let m=l[d],_;if(m.isInterleavedBufferAttribute){let g=i(e.data,m.data);_=new fr(g,m.itemSize,m.offset,m.normalized)}else{let g=Gs(m.type,m.array),p=m.isInstancedBufferAttribute?Hi:ht;_=new p(g,m.itemSize,m.normalized)}m.name!==void 0&&(_.name=m.name),m.usage!==void 0&&_.setUsage(m.usage),o.setAttribute(d,_)}let c=e.data.morphAttributes;if(c)for(let d in c){let m=c[d],_=[];for(let g=0,p=m.length;g0){let l=new yo(t);s=new vr(l),s.setCrossOrigin(this.crossOrigin);for(let c=0,h=e.length;c0){i=new vr(this.manager),i.setCrossOrigin(this.crossOrigin);for(let o=0,a=e.length;o{let g=null,p=null;return _.boundingBox!==void 0&&(g=new Ct().fromJSON(_.boundingBox)),_.boundingSphere!==void 0&&(p=new nn().fromJSON(_.boundingSphere)),{..._,boundingBox:g,boundingSphere:p}}),o._instanceInfo=e.instanceInfo,o._availableInstanceIds=e._availableInstanceIds,o._availableGeometryIds=e._availableGeometryIds,o._nextIndexStart=e.nextIndexStart,o._nextVertexStart=e.nextVertexStart,o._geometryCount=e.geometryCount,o._maxInstanceCount=e.maxInstanceCount,o._maxVertexCount=e.maxVertexCount,o._maxIndexCount=e.maxIndexCount,o._geometryInitialized=e.geometryInitialized,o._matricesTexture=c(e.matricesTexture.uuid),o._indirectTexture=c(e.indirectTexture.uuid),e.colorsTexture!==void 0&&(o._colorsTexture=c(e.colorsTexture.uuid)),e.boundingSphere!==void 0&&(o.boundingSphere=new nn().fromJSON(e.boundingSphere)),e.boundingBox!==void 0&&(o.boundingBox=new Ct().fromJSON(e.boundingBox));break;case"LOD":o=new xa;break;case"Line":o=new oi(a(e.geometry),l(e.material));break;case"LineLoop":o=new wa(a(e.geometry),l(e.material));break;case"LineSegments":o=new $n(a(e.geometry),l(e.material));break;case"PointCloud":case"Points":o=new Ta(a(e.geometry),l(e.material));break;case"Sprite":o=new ya(l(e.material));break;case"Group":o=new Oi;break;case"Bone":o=new no;break;default:o=new bt}if(o.uuid=e.uuid,e.name!==void 0&&(o.name=e.name),e.matrix!==void 0?(o.matrix.fromArray(e.matrix),e.matrixAutoUpdate!==void 0&&(o.matrixAutoUpdate=e.matrixAutoUpdate),o.matrixAutoUpdate&&o.matrix.decompose(o.position,o.quaternion,o.scale)):(e.position!==void 0&&o.position.fromArray(e.position),e.rotation!==void 0&&o.rotation.fromArray(e.rotation),e.quaternion!==void 0&&o.quaternion.fromArray(e.quaternion),e.scale!==void 0&&o.scale.fromArray(e.scale)),e.up!==void 0&&o.up.fromArray(e.up),e.castShadow!==void 0&&(o.castShadow=e.castShadow),e.receiveShadow!==void 0&&(o.receiveShadow=e.receiveShadow),e.shadow&&(e.shadow.intensity!==void 0&&(o.shadow.intensity=e.shadow.intensity),e.shadow.bias!==void 0&&(o.shadow.bias=e.shadow.bias),e.shadow.normalBias!==void 0&&(o.shadow.normalBias=e.shadow.normalBias),e.shadow.radius!==void 0&&(o.shadow.radius=e.shadow.radius),e.shadow.mapSize!==void 0&&o.shadow.mapSize.fromArray(e.shadow.mapSize),e.shadow.camera!==void 0&&(o.shadow.camera=this.parseObject(e.shadow.camera))),e.visible!==void 0&&(o.visible=e.visible),e.frustumCulled!==void 0&&(o.frustumCulled=e.frustumCulled),e.renderOrder!==void 0&&(o.renderOrder=e.renderOrder),e.userData!==void 0&&(o.userData=e.userData),e.layers!==void 0&&(o.layers.mask=e.layers),e.children!==void 0){let f=e.children;for(let d=0;d"u"&&console.warn("THREE.ImageBitmapLoader: createImageBitmap() not supported."),typeof fetch>"u"&&console.warn("THREE.ImageBitmapLoader: fetch() not supported."),this.options={premultiplyAlpha:"none"},this._abortController=new AbortController}setOptions(e){return this.options=e,this}load(e,t,n,i){e===void 0&&(e=""),this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);let s=this,o=si.get(`image-bitmap:${e}`);if(o!==void 0){if(s.manager.itemStart(e),o.then){o.then(c=>{if(Hf.has(o)===!0)i&&i(Hf.get(o)),s.manager.itemError(e),s.manager.itemEnd(e);else return t&&t(c),s.manager.itemEnd(e),c});return}return setTimeout(function(){t&&t(o),s.manager.itemEnd(e)},0),o}let a={};a.credentials=this.crossOrigin==="anonymous"?"same-origin":"include",a.headers=this.requestHeader,a.signal=typeof AbortSignal.any=="function"?AbortSignal.any([this._abortController.signal,this.manager.abortController.signal]):this._abortController.signal;let l=fetch(e,a).then(function(c){return c.blob()}).then(function(c){return createImageBitmap(c,Object.assign(s.options,{colorSpaceConversion:"none"}))}).then(function(c){return si.add(`image-bitmap:${e}`,c),t&&t(c),s.manager.itemEnd(e),c}).catch(function(c){i&&i(c),Hf.set(l,c),si.remove(`image-bitmap:${e}`),s.manager.itemError(e),s.manager.itemEnd(e)});si.add(`image-bitmap:${e}`,l),s.manager.itemStart(e)}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}},iu,vo=class{static getContext(){return iu===void 0&&(iu=new(window.AudioContext||window.webkitAudioContext)),iu}static setContext(e){iu=e}},Ou=class extends fn{constructor(e){super(e)}load(e,t,n,i){let s=this,o=new Jn(this.manager);o.setResponseType("arraybuffer"),o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(l){try{let c=l.slice(0);vo.getContext().decodeAudioData(c,function(u){t(u)}).catch(a)}catch(c){a(c)}},n,i);function a(l){i?i(l):console.error(l),s.manager.itemError(e)}}},Xm=new Qe,$m=new Qe,Nr=new Qe,Bu=class{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new en,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new en,this.cameraR.layers.enable(2),this.cameraR.matrixAutoUpdate=!1,this._cache={focus:null,fov:null,aspect:null,near:null,far:null,zoom:null,eyeSep:null}}update(e){let t=this._cache;if(t.focus!==e.focus||t.fov!==e.fov||t.aspect!==e.aspect*this.aspect||t.near!==e.near||t.far!==e.far||t.zoom!==e.zoom||t.eyeSep!==this.eyeSep){t.focus=e.focus,t.fov=e.fov,t.aspect=e.aspect*this.aspect,t.near=e.near,t.far=e.far,t.zoom=e.zoom,t.eyeSep=this.eyeSep,Nr.copy(e.projectionMatrix);let i=t.eyeSep/2,s=i*t.near/t.focus,o=t.near*Math.tan(Gr*t.fov*.5)/t.zoom,a,l;$m.elements[12]=-i,Xm.elements[12]=i,a=-o*t.aspect+s,l=o*t.aspect+s,Nr.elements[0]=2*t.near/(l-a),Nr.elements[8]=(l+a)/(l-a),this.cameraL.projectionMatrix.copy(Nr),a=-o*t.aspect-s,l=o*t.aspect-s,Nr.elements[0]=2*t.near/(l-a),Nr.elements[8]=(l+a)/(l-a),this.cameraR.projectionMatrix.copy(Nr)}this.cameraL.matrixWorld.copy(e.matrixWorld).multiply($m),this.cameraR.matrixWorld.copy(e.matrixWorld).multiply(Xm)}},pl=class extends en{constructor(e=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=e}},ml=class{constructor(e=!0){this.autoStart=e,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=performance.now(),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 e=0;if(this.autoStart&&!this.running)return this.start(),0;if(this.running){let t=performance.now();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}},Fr=new C,Gf=new Vt,Hv=new C,Or=new C,Br=new C,zu=class extends bt{constructor(){super(),this.type="AudioListener",this.context=vo.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._clock=new ml}getInput(){return this.gain}removeFilter(){return this.filter!==null&&(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination),this.gain.connect(this.context.destination),this.filter=null),this}getFilter(){return this.filter}setFilter(e){return this.filter!==null?(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination)):this.gain.disconnect(this.context.destination),this.filter=e,this.gain.connect(this.filter),this.filter.connect(this.context.destination),this}getMasterVolume(){return this.gain.gain.value}setMasterVolume(e){return this.gain.gain.setTargetAtTime(e,this.context.currentTime,.01),this}updateMatrixWorld(e){super.updateMatrixWorld(e);let t=this.context.listener;if(this.timeDelta=this._clock.getDelta(),this.matrixWorld.decompose(Fr,Gf,Hv),Or.set(0,0,-1).applyQuaternion(Gf),Br.set(0,1,0).applyQuaternion(Gf),t.positionX){let n=this.context.currentTime+this.timeDelta;t.positionX.linearRampToValueAtTime(Fr.x,n),t.positionY.linearRampToValueAtTime(Fr.y,n),t.positionZ.linearRampToValueAtTime(Fr.z,n),t.forwardX.linearRampToValueAtTime(Or.x,n),t.forwardY.linearRampToValueAtTime(Or.y,n),t.forwardZ.linearRampToValueAtTime(Or.z,n),t.upX.linearRampToValueAtTime(Br.x,n),t.upY.linearRampToValueAtTime(Br.y,n),t.upZ.linearRampToValueAtTime(Br.z,n)}else t.setPosition(Fr.x,Fr.y,Fr.z),t.setOrientation(Or.x,Or.y,Or.z,Br.x,Br.y,Br.z)}},gl=class extends bt{constructor(e){super(),this.type="Audio",this.listener=e,this.context=e.context,this.gain=this.context.createGain(),this.gain.connect(e.getInput()),this.autoplay=!1,this.buffer=null,this.detune=0,this.loop=!1,this.loopStart=0,this.loopEnd=0,this.offset=0,this.duration=void 0,this.playbackRate=1,this.isPlaying=!1,this.hasPlaybackControl=!0,this.source=null,this.sourceType="empty",this._startedAt=0,this._progress=0,this._connected=!1,this.filters=[]}getOutput(){return this.gain}setNodeSource(e){return this.hasPlaybackControl=!1,this.sourceType="audioNode",this.source=e,this.connect(),this}setMediaElementSource(e){return this.hasPlaybackControl=!1,this.sourceType="mediaNode",this.source=this.context.createMediaElementSource(e),this.connect(),this}setMediaStreamSource(e){return this.hasPlaybackControl=!1,this.sourceType="mediaStreamNode",this.source=this.context.createMediaStreamSource(e),this.connect(),this}setBuffer(e){return this.buffer=e,this.sourceType="buffer",this.autoplay&&this.play(),this}play(e=0){if(this.isPlaying===!0){console.warn("THREE.Audio: Audio is already playing.");return}if(this.hasPlaybackControl===!1){console.warn("THREE.Audio: this Audio has no playback control.");return}this._startedAt=this.context.currentTime+e;let t=this.context.createBufferSource();return t.buffer=this.buffer,t.loop=this.loop,t.loopStart=this.loopStart,t.loopEnd=this.loopEnd,t.onended=this.onEnded.bind(this),t.start(this._startedAt,this._progress+this.offset,this.duration),this.isPlaying=!0,this.source=t,this.setDetune(this.detune),this.setPlaybackRate(this.playbackRate),this.connect()}pause(){if(this.hasPlaybackControl===!1){console.warn("THREE.Audio: this Audio has no playback control.");return}return this.isPlaying===!0&&(this._progress+=Math.max(this.context.currentTime-this._startedAt,0)*this.playbackRate,this.loop===!0&&(this._progress=this._progress%(this.duration||this.buffer.duration)),this.source.stop(),this.source.onended=null,this.isPlaying=!1),this}stop(e=0){if(this.hasPlaybackControl===!1){console.warn("THREE.Audio: this Audio has no playback control.");return}return this._progress=0,this.source!==null&&(this.source.stop(this.context.currentTime+e),this.source.onended=null),this.isPlaying=!1,this}connect(){if(this.filters.length>0){this.source.connect(this.filters[0]);for(let e=1,t=this.filters.length;e0){this.source.disconnect(this.filters[0]);for(let e=1,t=this.filters.length;e0&&this._mixBufferRegionAdditive(n,i,this._addIndex*t,1,t);for(let l=t,c=t+t;l!==c;++l)if(n[l]!==n[l+t]){a.setValue(n,i);break}}saveOriginalState(){let e=this.binding,t=this.buffer,n=this.valueSize,i=n*this._origIndex;e.getValue(t,i);for(let s=n,o=i;s!==o;++s)t[s]=t[i+s%n];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){let e=this.valueSize*3;this.binding.setValue(this.buffer,e)}_setAdditiveIdentityNumeric(){let e=this._addIndex*this.valueSize,t=e+this.valueSize;for(let n=e;n=.5)for(let o=0;o!==s;++o)e[t+o]=e[n+o]}_slerp(e,t,n,i){Vt.slerpFlat(e,t,e,t,e,n,i)}_slerpAdditive(e,t,n,i,s){let o=this._workIndex*s;Vt.multiplyQuaternionsFlat(e,o,e,t,e,n),Vt.slerpFlat(e,t,e,t,e,o,i)}_lerp(e,t,n,i,s){let o=1-i;for(let a=0;a!==s;++a){let l=t+a;e[l]=e[l]*o+e[n+a]*i}}_lerpAdditive(e,t,n,i,s){for(let o=0;o!==s;++o){let a=t+o;e[a]=e[a]+e[n+o]*i}}},ip="\\[\\]\\.:\\/",kv=new RegExp("["+ip+"]","g"),rp="[^"+ip+"]",Wv="[^"+ip.replace("\\.","")+"]",Xv=/((?:WC+[\/:])*)/.source.replace("WC",rp),$v=/(WCOD+)?/.source.replace("WCOD",Wv),qv=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",rp),Yv=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",rp),Zv=new RegExp("^"+Xv+$v+qv+Yv+"$"),Jv=["material","materials","bones","map"],nd=class{constructor(e,t,n){let i=n||Lt.parseTrackName(t);this._targetGroup=e,this._bindings=e.subscribe_(t,i)}getValue(e,t){this.bind();let n=this._targetGroup.nCachedObjects_,i=this._bindings[n];i!==void 0&&i.getValue(e,t)}setValue(e,t){let n=this._bindings;for(let i=this._targetGroup.nCachedObjects_,s=n.length;i!==s;++i)n[i].setValue(e,t)}bind(){let e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,n=e.length;t!==n;++t)e[t].bind()}unbind(){let e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,n=e.length;t!==n;++t)e[t].unbind()}},Lt=class r{constructor(e,t,n){this.path=t,this.parsedPath=n||r.parseTrackName(t),this.node=r.findNode(e,this.parsedPath.nodeName),this.rootNode=e,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(e,t,n){return e&&e.isAnimationObjectGroup?new r.Composite(e,t,n):new r(e,t,n)}static sanitizeNodeName(e){return e.replace(/\s/g,"_").replace(kv,"")}static parseTrackName(e){let t=Zv.exec(e);if(t===null)throw new Error("PropertyBinding: Cannot parse trackName: "+e);let n={nodeName:t[2],objectName:t[3],objectIndex:t[4],propertyName:t[5],propertyIndex:t[6]},i=n.nodeName&&n.nodeName.lastIndexOf(".");if(i!==void 0&&i!==-1){let s=n.nodeName.substring(i+1);Jv.indexOf(s)!==-1&&(n.nodeName=n.nodeName.substring(0,i),n.objectName=s)}if(n.propertyName===null||n.propertyName.length===0)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+e);return n}static findNode(e,t){if(t===void 0||t===""||t==="."||t===-1||t===e.name||t===e.uuid)return e;if(e.skeleton){let n=e.skeleton.getBoneByName(t);if(n!==void 0)return n}if(e.children){let n=function(s){for(let o=0;o=s){let u=s++,f=e[u];t[f.uuid]=h,e[h]=f,t[c]=u,e[u]=l;for(let d=0,m=i;d!==m;++d){let _=n[d],g=_[u],p=_[h];_[h]=g,_[u]=p}}}this.nCachedObjects_=s}uncache(){let e=this._objects,t=this._indicesByUUID,n=this._bindings,i=n.length,s=this.nCachedObjects_,o=e.length;for(let a=0,l=arguments.length;a!==l;++a){let c=arguments[a],h=c.uuid,u=t[h];if(u!==void 0)if(delete t[h],u0&&(t[d.uuid]=u),e[u]=d,e.pop();for(let m=0,_=i;m!==_;++m){let g=n[m];g[u]=g[f],g.pop()}}}this.nCachedObjects_=s}subscribe_(e,t){let n=this._bindingsIndicesByPath,i=n[e],s=this._bindings;if(i!==void 0)return s[i];let o=this._paths,a=this._parsedPaths,l=this._objects,c=l.length,h=this.nCachedObjects_,u=new Array(c);i=s.length,n[e]=i,o.push(e),a.push(t),s.push(u);for(let f=h,d=l.length;f!==d;++f){let m=l[f];u[f]=new Lt(m,e,t)}return u}unsubscribe_(e){let t=this._bindingsIndicesByPath,n=t[e];if(n!==void 0){let i=this._paths,s=this._parsedPaths,o=this._bindings,a=o.length-1,l=o[a],c=e[a];t[c]=n,o[n]=l,o.pop(),s[n]=s[a],s.pop(),i[n]=i[a],i.pop()}}},yl=class{constructor(e,t,n=null,i=t.blendMode){this._mixer=e,this._clip=t,this._localRoot=n,this.blendMode=i;let s=t.tracks,o=s.length,a=new Array(o),l={endingStart:or,endingEnd:or};for(let c=0;c!==o;++c){let h=s[c].createInterpolant(null);a[c]=h,h.settings=l}this._interpolantSettings=l,this._interpolants=a,this._propertyBindings=new Array(o),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._weightInterpolant=null,this.loop=Od,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=1/0,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}play(){return this._mixer._activateAction(this),this}stop(){return this._mixer._deactivateAction(this),this.reset()}reset(){return this.paused=!1,this.enabled=!0,this.time=0,this._loopCount=-1,this._startTime=null,this.stopFading().stopWarping()}isRunning(){return this.enabled&&!this.paused&&this.timeScale!==0&&this._startTime===null&&this._mixer._isActiveAction(this)}isScheduled(){return this._mixer._isActiveAction(this)}startAt(e){return this._startTime=e,this}setLoop(e,t){return this.loop=e,this.repetitions=t,this}setEffectiveWeight(e){return this.weight=e,this._effectiveWeight=this.enabled?e:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(e){return this._scheduleFading(e,0,1)}fadeOut(e){return this._scheduleFading(e,1,0)}crossFadeFrom(e,t,n=!1){if(e.fadeOut(t),this.fadeIn(t),n===!0){let i=this._clip.duration,s=e._clip.duration,o=s/i,a=i/s;e.warp(1,o,t),this.warp(a,1,t)}return this}crossFadeTo(e,t,n=!1){return e.crossFadeFrom(this,t,n)}stopFading(){let e=this._weightInterpolant;return e!==null&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(e)),this}setEffectiveTimeScale(e){return this.timeScale=e,this._effectiveTimeScale=this.paused?0:e,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(e){return this.timeScale=this._clip.duration/e,this.stopWarping()}syncWith(e){return this.time=e.time,this.timeScale=e.timeScale,this.stopWarping()}halt(e){return this.warp(this._effectiveTimeScale,0,e)}warp(e,t,n){let i=this._mixer,s=i.time,o=this.timeScale,a=this._timeScaleInterpolant;a===null&&(a=i._lendControlInterpolant(),this._timeScaleInterpolant=a);let l=a.parameterPositions,c=a.sampleValues;return l[0]=s,l[1]=s+n,c[0]=e/o,c[1]=t/o,this}stopWarping(){let e=this._timeScaleInterpolant;return e!==null&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(e)),this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(e,t,n,i){if(!this.enabled){this._updateWeight(e);return}let s=this._startTime;if(s!==null){let l=(e-s)*n;l<0||n===0?t=0:(this._startTime=null,t=n*l)}t*=this._updateTimeScale(e);let o=this._updateTime(t),a=this._updateWeight(e);if(a>0){let l=this._interpolants,c=this._propertyBindings;switch(this.blendMode){case Ph:for(let h=0,u=l.length;h!==u;++h)l[h].evaluate(o),c[h].accumulateAdditive(a);break;case ac:default:for(let h=0,u=l.length;h!==u;++h)l[h].evaluate(o),c[h].accumulate(i,a)}}}_updateWeight(e){let t=0;if(this.enabled){t=this.weight;let n=this._weightInterpolant;if(n!==null){let i=n.evaluate(e)[0];t*=i,e>n.parameterPositions[1]&&(this.stopFading(),i===0&&(this.enabled=!1))}}return this._effectiveWeight=t,t}_updateTimeScale(e){let t=0;if(!this.paused){t=this.timeScale;let n=this._timeScaleInterpolant;if(n!==null){let i=n.evaluate(e)[0];t*=i,e>n.parameterPositions[1]&&(this.stopWarping(),t===0?this.paused=!0:this.timeScale=t)}}return this._effectiveTimeScale=t,t}_updateTime(e){let t=this._clip.duration,n=this.loop,i=this.time+e,s=this._loopCount,o=n===Bd;if(e===0)return s===-1?i:o&&(s&1)===1?t-i:i;if(n===Fd){s===-1&&(this._loopCount=0,this._setEndings(!0,!0,!1));e:{if(i>=t)i=t;else if(i<0)i=0;else{this.time=i;break e}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:e<0?-1:1})}}else{if(s===-1&&(e>=0?(s=0,this._setEndings(!0,this.repetitions===0,o)):this._setEndings(this.repetitions===0,!0,o)),i>=t||i<0){let a=Math.floor(i/t);i-=t*a,s+=Math.abs(a);let l=this.repetitions-s;if(l<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,i=e>0?t:0,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:e>0?1:-1});else{if(l===1){let c=e<0;this._setEndings(c,!c,o)}else this._setEndings(!1,!1,o);this._loopCount=s,this.time=i,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:a})}}else this.time=i;if(o&&(s&1)===1)return t-i}return i}_setEndings(e,t,n){let i=this._interpolantSettings;n?(i.endingStart=ar,i.endingEnd=ar):(e?i.endingStart=this.zeroSlopeAtStart?ar:or:i.endingStart=qs,t?i.endingEnd=this.zeroSlopeAtEnd?ar:or:i.endingEnd=qs)}_scheduleFading(e,t,n){let i=this._mixer,s=i.time,o=this._weightInterpolant;o===null&&(o=i._lendControlInterpolant(),this._weightInterpolant=o);let a=o.parameterPositions,l=o.sampleValues;return a[0]=s,l[0]=t,a[1]=s+e,l[1]=n,this}},jv=new Float32Array(1),ku=class extends kn{constructor(e){super(),this._root=e,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}_bindAction(e,t){let n=e._localRoot||this._root,i=e._clip.tracks,s=i.length,o=e._propertyBindings,a=e._interpolants,l=n.uuid,c=this._bindingsByRootAndName,h=c[l];h===void 0&&(h={},c[l]=h);for(let u=0;u!==s;++u){let f=i[u],d=f.name,m=h[d];if(m!==void 0)++m.referenceCount,o[u]=m;else{if(m=o[u],m!==void 0){m._cacheIndex===null&&(++m.referenceCount,this._addInactiveBinding(m,l,d));continue}let _=t&&t._propertyBindings[u].binding.parsedPath;m=new _l(Lt.create(n,d,_),f.ValueTypeName,f.getValueSize()),++m.referenceCount,this._addInactiveBinding(m,l,d),o[u]=m}a[u].resultBuffer=m.buffer}}_activateAction(e){if(!this._isActiveAction(e)){if(e._cacheIndex===null){let n=(e._localRoot||this._root).uuid,i=e._clip.uuid,s=this._actionsByClip[i];this._bindAction(e,s&&s.knownActions[0]),this._addInactiveAction(e,i,n)}let t=e._propertyBindings;for(let n=0,i=t.length;n!==i;++n){let s=t[n];s.useCount++===0&&(this._lendBinding(s),s.saveOriginalState())}this._lendAction(e)}}_deactivateAction(e){if(this._isActiveAction(e)){let t=e._propertyBindings;for(let n=0,i=t.length;n!==i;++n){let s=t[n];--s.useCount===0&&(s.restoreOriginalState(),this._takeBackBinding(s))}this._takeBackAction(e)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;let e=this;this.stats={actions:{get total(){return e._actions.length},get inUse(){return e._nActiveActions}},bindings:{get total(){return e._bindings.length},get inUse(){return e._nActiveBindings}},controlInterpolants:{get total(){return e._controlInterpolants.length},get inUse(){return e._nActiveControlInterpolants}}}}_isActiveAction(e){let t=e._cacheIndex;return t!==null&&t=0;--n)e[n].stop();return this}update(e){e*=this.timeScale;let t=this._actions,n=this._nActiveActions,i=this.time+=e,s=Math.sign(e),o=this._accuIndex^=1;for(let c=0;c!==n;++c)t[c]._update(i,e,s,o);let a=this._bindings,l=this._nActiveBindings;for(let c=0;c!==l;++c)a[c].apply(o);return this}setTime(e){this.time=0;for(let t=0;t=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Jm).distanceTo(e)}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}},jm=new C,ru=new C,Vs=new C,Hs=new C,kf=new C,eb=new C,tb=new C,eh=class{constructor(e=new C,t=new C){this.start=e,this.end=t}set(e,t){return this.start.copy(e),this.end.copy(t),this}copy(e){return this.start.copy(e.start),this.end.copy(e.end),this}getCenter(e){return e.addVectors(this.start,this.end).multiplyScalar(.5)}delta(e){return e.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(e,t){return this.delta(t).multiplyScalar(e).add(this.start)}closestPointToPointParameter(e,t){jm.subVectors(e,this.start),ru.subVectors(this.end,this.start);let n=ru.dot(ru),s=ru.dot(jm)/n;return t&&(s=at(s,0,1)),s}closestPointToPoint(e,t,n){let i=this.closestPointToPointParameter(e,t);return this.delta(n).multiplyScalar(i).add(this.start)}distanceSqToLine3(e,t=eb,n=tb){let i=10000000000000001e-32,s,o,a=this.start,l=e.start,c=this.end,h=e.end;Vs.subVectors(c,a),Hs.subVectors(h,l),kf.subVectors(a,l);let u=Vs.dot(Vs),f=Hs.dot(Hs),d=Hs.dot(kf);if(u<=i&&f<=i)return t.copy(a),n.copy(l),t.sub(n),t.dot(t);if(u<=i)s=0,o=d/f,o=at(o,0,1);else{let m=Vs.dot(kf);if(f<=i)o=0,s=at(-m/u,0,1);else{let _=Vs.dot(Hs),g=u*f-_*_;g!==0?s=at((_*d-m*f)/g,0,1):s=0,o=(_*s+d)/f,o<0?(o=0,s=at(-m/u,0,1)):o>1&&(o=1,s=at((_-m)/u,0,1))}}return t.copy(a).add(Vs.multiplyScalar(s)),n.copy(l).add(Hs.multiplyScalar(o)),t.sub(n),t.dot(t)}applyMatrix4(e){return this.start.applyMatrix4(e),this.end.applyMatrix4(e),this}equals(e){return e.start.equals(this.start)&&e.end.equals(this.end)}clone(){return new this.constructor().copy(this)}},Km=new C,th=class extends bt{constructor(e,t){super(),this.light=e,this.matrixAutoUpdate=!1,this.color=t,this.type="SpotLightHelper";let n=new et,i=[0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,-1,0,1,0,0,0,0,1,1,0,0,0,0,-1,1];for(let o=0,a=1,l=32;o1)for(let u=0;u.99999)this.quaternion.set(0,0,0,1);else if(e.y<-.99999)this.quaternion.set(1,0,0,0);else{ig.set(e.z,0,-e.x).normalize();let t=Math.acos(e.y);this.quaternion.setFromAxisAngle(ig,t)}}setLength(e,t=e*.2,n=t*.2){this.line.scale.set(1,Math.max(1e-4,e-t),1),this.line.updateMatrix(),this.cone.scale.set(n,t,n),this.cone.position.y=e,this.cone.updateMatrix()}setColor(e){this.line.material.color.set(e),this.cone.material.color.set(e)}copy(e){return super.copy(e,!1),this.line.copy(e.line),this.cone.copy(e.cone),this}dispose(){this.line.geometry.dispose(),this.line.material.dispose(),this.cone.geometry.dispose(),this.cone.material.dispose()}},dh=class extends $n{constructor(e=1){let t=[0,0,0,e,0,0,0,0,0,0,e,0,0,0,0,0,0,e],n=[1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],i=new et;i.setAttribute("position",new De(t,3)),i.setAttribute("color",new De(n,3));let s=new hn({vertexColors:!0,toneMapped:!1});super(i,s),this.type="AxesHelper"}setColors(e,t,n){let i=new Be,s=this.geometry.attributes.color.array;return i.set(e),i.toArray(s,0),i.toArray(s,3),i.set(t),i.toArray(s,6),i.toArray(s,9),i.set(n),i.toArray(s,12),i.toArray(s,15),this.geometry.attributes.color.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}},ph=class{constructor(){this.type="ShapePath",this.color=new Be,this.subPaths=[],this.currentPath=null}moveTo(e,t){return this.currentPath=new ns,this.subPaths.push(this.currentPath),this.currentPath.moveTo(e,t),this}lineTo(e,t){return this.currentPath.lineTo(e,t),this}quadraticCurveTo(e,t,n,i){return this.currentPath.quadraticCurveTo(e,t,n,i),this}bezierCurveTo(e,t,n,i,s,o){return this.currentPath.bezierCurveTo(e,t,n,i,s,o),this}splineThru(e){return this.currentPath.splineThru(e),this}toShapes(e){function t(p){let M=[];for(let x=0,y=p.length;xNumber.EPSILON){if(T<0&&(R=M[S],w=-w,P=M[E],T=-T),p.yP.y)continue;if(p.y===R.y){if(p.x===R.x)return!0}else{let N=T*(p.x-R.x)-w*(p.y-R.y);if(N===0)return!0;if(N<0)continue;y=!y}}else{if(p.y!==R.y)continue;if(P.x<=p.x&&p.x<=R.x||R.x<=p.x&&p.x<=P.x)return!0}}return y}let i=An.isClockWise,s=this.subPaths;if(s.length===0)return[];let o,a,l,c=[];if(s.length===1)return a=s[0],l=new mi,l.curves=a.curves,c.push(l),c;let h=!i(s[0].getPoints());h=e?!h:h;let u=[],f=[],d=[],m=0,_;f[m]=void 0,d[m]=[];for(let p=0,M=s.length;p1){let p=!1,M=0;for(let x=0,y=f.length;x0&&p===!1&&(d=u)}let g;for(let p=0,M=f.length;pe?(r.repeat.x=1,r.repeat.y=t/e,r.offset.x=0,r.offset.y=(1-r.repeat.y)/2):(r.repeat.x=e/t,r.repeat.y=1,r.offset.x=(1-r.repeat.x)/2,r.offset.y=0),r}function rb(r,e){let t=r.image&&r.image.width?r.image.width/r.image.height:1;return t>e?(r.repeat.x=e/t,r.repeat.y=1,r.offset.x=(1-r.repeat.x)/2,r.offset.y=0):(r.repeat.x=1,r.repeat.y=t/e,r.offset.x=0,r.offset.y=(1-r.repeat.y)/2),r}function sb(r){return r.repeat.x=1,r.repeat.y=1,r.offset.x=0,r.offset.y=0,r}function Lh(r,e,t,n){let i=ob(n);switch(t){case Ah:return r*e;case Pl:return r*e/i.components*i.byteLength;case wo:return r*e/i.components*i.byteLength;case Ch:return r*e*2/i.components*i.byteLength;case Il:return r*e*2/i.components*i.byteLength;case Rh:return r*e*3/i.components*i.byteLength;case _n:return r*e*4/i.components*i.byteLength;case Dl:return r*e*4/i.components*i.byteLength;case To:case Ao:return Math.floor((r+3)/4)*Math.floor((e+3)/4)*8;case Ro:case Co:return Math.floor((r+3)/4)*Math.floor((e+3)/4)*16;case Ul:case Fl:return Math.max(r,16)*Math.max(e,8)/4;case Ll:case Nl:return Math.max(r,8)*Math.max(e,8)/2;case Ol:case Bl:return Math.floor((r+3)/4)*Math.floor((e+3)/4)*8;case zl:return Math.floor((r+3)/4)*Math.floor((e+3)/4)*16;case Vl:return Math.floor((r+3)/4)*Math.floor((e+3)/4)*16;case Hl:return Math.floor((r+4)/5)*Math.floor((e+3)/4)*16;case Gl:return Math.floor((r+4)/5)*Math.floor((e+4)/5)*16;case kl:return Math.floor((r+5)/6)*Math.floor((e+4)/5)*16;case Wl:return Math.floor((r+5)/6)*Math.floor((e+5)/6)*16;case Xl:return Math.floor((r+7)/8)*Math.floor((e+4)/5)*16;case $l:return Math.floor((r+7)/8)*Math.floor((e+5)/6)*16;case ql:return Math.floor((r+7)/8)*Math.floor((e+7)/8)*16;case Yl:return Math.floor((r+9)/10)*Math.floor((e+4)/5)*16;case Zl:return Math.floor((r+9)/10)*Math.floor((e+5)/6)*16;case Jl:return Math.floor((r+9)/10)*Math.floor((e+7)/8)*16;case jl:return Math.floor((r+9)/10)*Math.floor((e+9)/10)*16;case Kl:return Math.floor((r+11)/12)*Math.floor((e+9)/10)*16;case Ql:return Math.floor((r+11)/12)*Math.floor((e+11)/12)*16;case ec:case tc:case nc:return Math.ceil(r/4)*Math.ceil(e/4)*16;case ic:case rc:return Math.ceil(r/4)*Math.ceil(e/4)*8;case sc:case oc:return Math.ceil(r/4)*Math.ceil(e/4)*16}throw new Error(`Unable to determine texture byte length for ${t} format.`)}function ob(r){switch(r){case jn:case Eh:return{byteLength:1,components:1};case hs:case Sh:case fs:return{byteLength:2,components:1};case Rl:case Cl:return{byteLength:2,components:4};case Si:case Al:case Rn:return{byteLength:4,components:1};case wh:case Th:return{byteLength:4,components:3}}throw new Error(`Unknown texture type ${r}.`)}var gh=class{static contain(e,t){return ib(e,t)}static cover(e,t){return rb(e,t)}static fill(e){return sb(e)}static getByteLength(e,t,n,i){return Lh(e,t,n,i)}};typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:"180"}}));typeof window<"u"&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__="180");function E0(){let r=null,e=!1,t=null,n=null;function i(s,o){t(s,o),n=r.requestAnimationFrame(i)}return{start:function(){e!==!0&&t!==null&&(n=r.requestAnimationFrame(i),e=!0)},stop:function(){r.cancelAnimationFrame(n),e=!1},setAnimationLoop:function(s){t=s},setContext:function(s){r=s}}}function ab(r){let e=new WeakMap;function t(a,l){let c=a.array,h=a.usage,u=c.byteLength,f=r.createBuffer();r.bindBuffer(l,f),r.bufferData(l,c,h),a.onUploadCallback();let d;if(c instanceof Float32Array)d=r.FLOAT;else if(typeof Float16Array<"u"&&c instanceof Float16Array)d=r.HALF_FLOAT;else if(c instanceof Uint16Array)a.isFloat16BufferAttribute?d=r.HALF_FLOAT:d=r.UNSIGNED_SHORT;else if(c instanceof Int16Array)d=r.SHORT;else if(c instanceof Uint32Array)d=r.UNSIGNED_INT;else if(c instanceof Int32Array)d=r.INT;else if(c instanceof Int8Array)d=r.BYTE;else if(c instanceof Uint8Array)d=r.UNSIGNED_BYTE;else if(c instanceof Uint8ClampedArray)d=r.UNSIGNED_BYTE;else throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: "+c);return{buffer:f,type:d,bytesPerElement:c.BYTES_PER_ELEMENT,version:a.version,size:u}}function n(a,l,c){let h=l.array,u=l.updateRanges;if(r.bindBuffer(c,a),u.length===0)r.bufferSubData(c,0,h);else{u.sort((d,m)=>d.start-m.start);let f=0;for(let d=1;d 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`,Sb=`#if NUM_CLIPPING_PLANES > 0 varying vec3 vClipPosition; uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ]; #endif`,wb=`#if NUM_CLIPPING_PLANES > 0 varying vec3 vClipPosition; #endif`,Tb=`#if NUM_CLIPPING_PLANES > 0 vClipPosition = - mvPosition.xyz; #endif`,Ab=`#if defined( USE_COLOR_ALPHA ) diffuseColor *= vColor; #elif defined( USE_COLOR ) diffuseColor.rgb *= vColor; #endif`,Rb=`#if defined( USE_COLOR_ALPHA ) varying vec4 vColor; #elif defined( USE_COLOR ) varying vec3 vColor; #endif`,Cb=`#if defined( USE_COLOR_ALPHA ) varying vec4 vColor; #elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR ) varying vec3 vColor; #endif`,Pb=`#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`,Ib=`#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`,Db=`#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`,Lb=`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`,Ub=`#ifdef USE_DISPLACEMENTMAP uniform sampler2D displacementMap; uniform float displacementScale; uniform float displacementBias; #endif`,Nb=`#ifdef USE_DISPLACEMENTMAP transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias ); #endif`,Fb=`#ifdef USE_EMISSIVEMAP vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv ); #ifdef DECODE_VIDEO_TEXTURE_EMISSIVE emissiveColor = sRGBTransferEOTF( emissiveColor ); #endif totalEmissiveRadiance *= emissiveColor.rgb; #endif`,Ob=`#ifdef USE_EMISSIVEMAP uniform sampler2D emissiveMap; #endif`,Bb="gl_FragColor = linearToOutputTexel( gl_FragColor );",zb=`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 ); }`,Vb=`#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`,Hb=`#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`,Gb=`#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`,kb=`#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`,Wb=`#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`,Xb=`#ifdef USE_FOG vFogDepth = - mvPosition.z; #endif`,$b=`#ifdef USE_FOG varying float vFogDepth; #endif`,qb=`#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`,Yb=`#ifdef USE_FOG uniform vec3 fogColor; varying float vFogDepth; #ifdef FOG_EXP2 uniform float fogDensity; #else uniform float fogNear; uniform float fogFar; #endif #endif`,Zb=`#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 }`,Jb=`#ifdef USE_LIGHTMAP uniform sampler2D lightMap; uniform float lightMapIntensity; #endif`,jb=`LambertMaterial material; material.diffuseColor = diffuseColor.rgb; material.specularStrength = specularStrength;`,Kb=`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`,Qb=`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`,eM=`#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`,tM=`ToonMaterial material; material.diffuseColor = diffuseColor.rgb;`,nM=`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`,iM=`BlinnPhongMaterial material; material.diffuseColor = diffuseColor.rgb; material.specularColor = specular; material.specularShininess = shininess; material.specularStrength = specularStrength;`,rM=`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`,sM=`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`,oM=`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 ); }`,aM=` 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`,lM=`#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`,cM=`#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`,uM=`#if defined( USE_LOGARITHMIC_DEPTH_BUFFER ) gl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5; #endif`,hM=`#if defined( USE_LOGARITHMIC_DEPTH_BUFFER ) uniform float logDepthBufFC; varying float vFragDepth; varying float vIsPerspective; #endif`,fM=`#ifdef USE_LOGARITHMIC_DEPTH_BUFFER varying float vFragDepth; varying float vIsPerspective; #endif`,dM=`#ifdef USE_LOGARITHMIC_DEPTH_BUFFER vFragDepth = 1.0 + gl_Position.w; vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) ); #endif`,pM=`#ifdef USE_MAP vec4 sampledDiffuseColor = texture2D( map, vMapUv ); #ifdef DECODE_VIDEO_TEXTURE sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor ); #endif diffuseColor *= sampledDiffuseColor; #endif`,mM=`#ifdef USE_MAP uniform sampler2D map; #endif`,gM=`#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`,_M=`#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`,yM=`float metalnessFactor = metalness; #ifdef USE_METALNESSMAP vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv ); metalnessFactor *= texelMetalness.b; #endif`,xM=`#ifdef USE_METALNESSMAP uniform sampler2D metalnessMap; #endif`,vM=`#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`,bM=`#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`,MM=`#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`,EM=`#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`,SM=`#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`,wM=`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;`,TM=`#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`,AM=`#ifndef FLAT_SHADED varying vec3 vNormal; #ifdef USE_TANGENT varying vec3 vTangent; varying vec3 vBitangent; #endif #endif`,RM=`#ifndef FLAT_SHADED varying vec3 vNormal; #ifdef USE_TANGENT varying vec3 vTangent; varying vec3 vBitangent; #endif #endif`,CM=`#ifndef FLAT_SHADED vNormal = normalize( transformedNormal ); #ifdef USE_TANGENT vTangent = normalize( transformedTangent ); vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w ); #endif #endif`,PM=`#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`,IM=`#ifdef USE_CLEARCOAT vec3 clearcoatNormal = nonPerturbedNormal; #endif`,DM=`#ifdef USE_CLEARCOAT_NORMALMAP vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0; clearcoatMapN.xy *= clearcoatNormalScale; clearcoatNormal = normalize( tbn2 * clearcoatMapN ); #endif`,LM=`#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`,UM=`#ifdef USE_IRIDESCENCEMAP uniform sampler2D iridescenceMap; #endif #ifdef USE_IRIDESCENCE_THICKNESSMAP uniform sampler2D iridescenceThicknessMap; #endif`,NM=`#ifdef OPAQUE diffuseColor.a = 1.0; #endif #ifdef USE_TRANSMISSION diffuseColor.a *= material.transmissionAlpha; #endif gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,FM=`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 ); }`,OM=`#ifdef PREMULTIPLIED_ALPHA gl_FragColor.rgb *= gl_FragColor.a; #endif`,BM=`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;`,zM=`#ifdef DITHERING gl_FragColor.rgb = dithering( gl_FragColor.rgb ); #endif`,VM=`#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`,HM=`float roughnessFactor = roughness; #ifdef USE_ROUGHNESSMAP vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv ); roughnessFactor *= texelRoughness.g; #endif`,GM=`#ifdef USE_ROUGHNESSMAP uniform sampler2D roughnessMap; #endif`,kM=`#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 ) { float depth = unpackRGBAToDepth( texture2D( depths, uv ) ); #ifdef USE_REVERSED_DEPTH_BUFFER return step( depth, compare ); #else return step( compare, depth ); #endif } 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 ); #ifdef USE_REVERSED_DEPTH_BUFFER float hard_shadow = step( distribution.x, compare ); #else float hard_shadow = step( compare, distribution.x ); #endif 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`,WM=`#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`,XM=`#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`,$M=`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; }`,qM=`#ifdef USE_SKINNING mat4 boneMatX = getBoneMatrix( skinIndex.x ); mat4 boneMatY = getBoneMatrix( skinIndex.y ); mat4 boneMatZ = getBoneMatrix( skinIndex.z ); mat4 boneMatW = getBoneMatrix( skinIndex.w ); #endif`,YM=`#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`,ZM=`#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`,JM=`#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`,jM=`float specularStrength; #ifdef USE_SPECULARMAP vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv ); specularStrength = texelSpecular.r; #else specularStrength = 1.0; #endif`,KM=`#ifdef USE_SPECULARMAP uniform sampler2D specularMap; #endif`,QM=`#if defined( TONE_MAPPING ) gl_FragColor.rgb = toneMapping( gl_FragColor.rgb ); #endif`,eE=`#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; }`,tE=`#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`,nE=`#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`,iE=`#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`,rE=`#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`,sE=`#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`,oE=`#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`,aE=`varying vec2 vUv; uniform mat3 uvTransform; void main() { vUv = ( uvTransform * vec3( uv, 1 ) ).xy; gl_Position = vec4( position.xy, 1.0, 1.0 ); }`,lE=`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 }`,cE=`varying vec3 vWorldDirection; #include void main() { vWorldDirection = transformDirection( position, modelMatrix ); #include #include gl_Position.z = gl_Position.w; }`,uE=`#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 }`,hE=`varying vec3 vWorldDirection; #include void main() { vWorldDirection = transformDirection( position, modelMatrix ); #include #include gl_Position.z = gl_Position.w; }`,fE=`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 }`,dE=`#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; }`,pE=`#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 #ifdef USE_REVERSED_DEPTH_BUFFER float fragCoordZ = vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ]; #else float fragCoordZ = 0.5 * vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ] + 0.5; #endif #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 }`,mE=`#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; }`,gE=`#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 ); }`,_E=`varying vec3 vWorldDirection; #include void main() { vWorldDirection = transformDirection( position, modelMatrix ); #include #include }`,yE=`uniform sampler2D tEquirect; varying vec3 vWorldDirection; #include void main() { vec3 direction = normalize( vWorldDirection ); vec2 sampleUV = equirectUv( direction ); gl_FragColor = texture2D( tEquirect, sampleUV ); #include #include }`,xE=`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 }`,vE=`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 }`,bE=`#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 }`,ME=`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 }`,EE=`#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 }`,SE=`#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 }`,wE=`#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; }`,TE=`#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 }`,AE=`#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 }`,RE=`#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 }`,CE=`#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 }`,PE=`#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 }`,IE=`#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 }`,DE=`#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 }`,LE=`#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 }`,UE=`#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 }`,NE=`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 }`,FE=`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 }`,OE=`#include #include #include #include #include #include #include void main() { #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include }`,BE=`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 }`,zE=`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 }`,VE=`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 }`,_t={alphahash_fragment:lb,alphahash_pars_fragment:cb,alphamap_fragment:ub,alphamap_pars_fragment:hb,alphatest_fragment:fb,alphatest_pars_fragment:db,aomap_fragment:pb,aomap_pars_fragment:mb,batching_pars_vertex:gb,batching_vertex:_b,begin_vertex:yb,beginnormal_vertex:xb,bsdfs:vb,iridescence_fragment:bb,bumpmap_pars_fragment:Mb,clipping_planes_fragment:Eb,clipping_planes_pars_fragment:Sb,clipping_planes_pars_vertex:wb,clipping_planes_vertex:Tb,color_fragment:Ab,color_pars_fragment:Rb,color_pars_vertex:Cb,color_vertex:Pb,common:Ib,cube_uv_reflection_fragment:Db,defaultnormal_vertex:Lb,displacementmap_pars_vertex:Ub,displacementmap_vertex:Nb,emissivemap_fragment:Fb,emissivemap_pars_fragment:Ob,colorspace_fragment:Bb,colorspace_pars_fragment:zb,envmap_fragment:Vb,envmap_common_pars_fragment:Hb,envmap_pars_fragment:Gb,envmap_pars_vertex:kb,envmap_physical_pars_fragment:eM,envmap_vertex:Wb,fog_vertex:Xb,fog_pars_vertex:$b,fog_fragment:qb,fog_pars_fragment:Yb,gradientmap_pars_fragment:Zb,lightmap_pars_fragment:Jb,lights_lambert_fragment:jb,lights_lambert_pars_fragment:Kb,lights_pars_begin:Qb,lights_toon_fragment:tM,lights_toon_pars_fragment:nM,lights_phong_fragment:iM,lights_phong_pars_fragment:rM,lights_physical_fragment:sM,lights_physical_pars_fragment:oM,lights_fragment_begin:aM,lights_fragment_maps:lM,lights_fragment_end:cM,logdepthbuf_fragment:uM,logdepthbuf_pars_fragment:hM,logdepthbuf_pars_vertex:fM,logdepthbuf_vertex:dM,map_fragment:pM,map_pars_fragment:mM,map_particle_fragment:gM,map_particle_pars_fragment:_M,metalnessmap_fragment:yM,metalnessmap_pars_fragment:xM,morphinstance_vertex:vM,morphcolor_vertex:bM,morphnormal_vertex:MM,morphtarget_pars_vertex:EM,morphtarget_vertex:SM,normal_fragment_begin:wM,normal_fragment_maps:TM,normal_pars_fragment:AM,normal_pars_vertex:RM,normal_vertex:CM,normalmap_pars_fragment:PM,clearcoat_normal_fragment_begin:IM,clearcoat_normal_fragment_maps:DM,clearcoat_pars_fragment:LM,iridescence_pars_fragment:UM,opaque_fragment:NM,packing:FM,premultiplied_alpha_fragment:OM,project_vertex:BM,dithering_fragment:zM,dithering_pars_fragment:VM,roughnessmap_fragment:HM,roughnessmap_pars_fragment:GM,shadowmap_pars_fragment:kM,shadowmap_pars_vertex:WM,shadowmap_vertex:XM,shadowmask_pars_fragment:$M,skinbase_vertex:qM,skinning_pars_vertex:YM,skinning_vertex:ZM,skinnormal_vertex:JM,specularmap_fragment:jM,specularmap_pars_fragment:KM,tonemapping_fragment:QM,tonemapping_pars_fragment:eE,transmission_fragment:tE,transmission_pars_fragment:nE,uv_pars_fragment:iE,uv_pars_vertex:rE,uv_vertex:sE,worldpos_vertex:oE,background_vert:aE,background_frag:lE,backgroundCube_vert:cE,backgroundCube_frag:uE,cube_vert:hE,cube_frag:fE,depth_vert:dE,depth_frag:pE,distanceRGBA_vert:mE,distanceRGBA_frag:gE,equirect_vert:_E,equirect_frag:yE,linedashed_vert:xE,linedashed_frag:vE,meshbasic_vert:bE,meshbasic_frag:ME,meshlambert_vert:EE,meshlambert_frag:SE,meshmatcap_vert:wE,meshmatcap_frag:TE,meshnormal_vert:AE,meshnormal_frag:RE,meshphong_vert:CE,meshphong_frag:PE,meshphysical_vert:IE,meshphysical_frag:DE,meshtoon_vert:LE,meshtoon_frag:UE,points_vert:NE,points_frag:FE,shadow_vert:OE,shadow_frag:BE,sprite_vert:zE,sprite_frag:VE},Ue={common:{diffuse:{value:new Be(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new pt},alphaMap:{value:null},alphaMapTransform:{value:new pt},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new pt}},envmap:{envMap:{value:null},envMapRotation:{value:new pt},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new pt}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new pt}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new pt},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new pt},normalScale:{value:new ce(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new pt},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new pt}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new pt}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new pt}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new Be(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 Be(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new pt},alphaTest:{value:0},uvTransform:{value:new pt}},sprite:{diffuse:{value:new Be(16777215)},opacity:{value:1},center:{value:new ce(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new pt},alphaMap:{value:null},alphaMapTransform:{value:new pt},alphaTest:{value:0}}},hi={basic:{uniforms:vn([Ue.common,Ue.specularmap,Ue.envmap,Ue.aomap,Ue.lightmap,Ue.fog]),vertexShader:_t.meshbasic_vert,fragmentShader:_t.meshbasic_frag},lambert:{uniforms:vn([Ue.common,Ue.specularmap,Ue.envmap,Ue.aomap,Ue.lightmap,Ue.emissivemap,Ue.bumpmap,Ue.normalmap,Ue.displacementmap,Ue.fog,Ue.lights,{emissive:{value:new Be(0)}}]),vertexShader:_t.meshlambert_vert,fragmentShader:_t.meshlambert_frag},phong:{uniforms:vn([Ue.common,Ue.specularmap,Ue.envmap,Ue.aomap,Ue.lightmap,Ue.emissivemap,Ue.bumpmap,Ue.normalmap,Ue.displacementmap,Ue.fog,Ue.lights,{emissive:{value:new Be(0)},specular:{value:new Be(1118481)},shininess:{value:30}}]),vertexShader:_t.meshphong_vert,fragmentShader:_t.meshphong_frag},standard:{uniforms:vn([Ue.common,Ue.envmap,Ue.aomap,Ue.lightmap,Ue.emissivemap,Ue.bumpmap,Ue.normalmap,Ue.displacementmap,Ue.roughnessmap,Ue.metalnessmap,Ue.fog,Ue.lights,{emissive:{value:new Be(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:_t.meshphysical_vert,fragmentShader:_t.meshphysical_frag},toon:{uniforms:vn([Ue.common,Ue.aomap,Ue.lightmap,Ue.emissivemap,Ue.bumpmap,Ue.normalmap,Ue.displacementmap,Ue.gradientmap,Ue.fog,Ue.lights,{emissive:{value:new Be(0)}}]),vertexShader:_t.meshtoon_vert,fragmentShader:_t.meshtoon_frag},matcap:{uniforms:vn([Ue.common,Ue.bumpmap,Ue.normalmap,Ue.displacementmap,Ue.fog,{matcap:{value:null}}]),vertexShader:_t.meshmatcap_vert,fragmentShader:_t.meshmatcap_frag},points:{uniforms:vn([Ue.points,Ue.fog]),vertexShader:_t.points_vert,fragmentShader:_t.points_frag},dashed:{uniforms:vn([Ue.common,Ue.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:_t.linedashed_vert,fragmentShader:_t.linedashed_frag},depth:{uniforms:vn([Ue.common,Ue.displacementmap]),vertexShader:_t.depth_vert,fragmentShader:_t.depth_frag},normal:{uniforms:vn([Ue.common,Ue.bumpmap,Ue.normalmap,Ue.displacementmap,{opacity:{value:1}}]),vertexShader:_t.meshnormal_vert,fragmentShader:_t.meshnormal_frag},sprite:{uniforms:vn([Ue.sprite,Ue.fog]),vertexShader:_t.sprite_vert,fragmentShader:_t.sprite_frag},background:{uniforms:{uvTransform:{value:new pt},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:_t.background_vert,fragmentShader:_t.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new pt}},vertexShader:_t.backgroundCube_vert,fragmentShader:_t.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:_t.cube_vert,fragmentShader:_t.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:_t.equirect_vert,fragmentShader:_t.equirect_frag},distanceRGBA:{uniforms:vn([Ue.common,Ue.displacementmap,{referencePosition:{value:new C},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:_t.distanceRGBA_vert,fragmentShader:_t.distanceRGBA_frag},shadow:{uniforms:vn([Ue.lights,Ue.fog,{color:{value:new Be(0)},opacity:{value:1}}]),vertexShader:_t.shadow_vert,fragmentShader:_t.shadow_frag}};hi.physical={uniforms:vn([hi.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new pt},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new pt},clearcoatNormalScale:{value:new ce(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new pt},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new pt},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new pt},sheen:{value:0},sheenColor:{value:new Be(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new pt},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new pt},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new pt},transmissionSamplerSize:{value:new ce},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new pt},attenuationDistance:{value:0},attenuationColor:{value:new Be(0)},specularColor:{value:new Be(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new pt},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new pt},anisotropyVector:{value:new ce},anisotropyMap:{value:null},anisotropyMapTransform:{value:new pt}}]),vertexShader:_t.meshphysical_vert,fragmentShader:_t.meshphysical_frag};var Uh={r:0,b:0,g:0},gs=new yn,HE=new Qe;function GE(r,e,t,n,i,s,o){let a=new Be(0),l=s===!0?0:1,c,h,u=null,f=0,d=null;function m(x){let y=x.isScene===!0?x.background:null;return y&&y.isTexture&&(y=(x.backgroundBlurriness>0?t:e).get(y)),y}function _(x){let y=!1,E=m(x);E===null?p(a,l):E&&E.isColor&&(p(E,1),y=!0);let S=r.xr.getEnvironmentBlendMode();S==="additive"?n.buffers.color.setClear(0,0,0,1,o):S==="alpha-blend"&&n.buffers.color.setClear(0,0,0,0,o),(r.autoClear||y)&&(n.buffers.depth.setTest(!0),n.buffers.depth.setMask(!0),n.buffers.color.setMask(!0),r.clear(r.autoClearColor,r.autoClearDepth,r.autoClearStencil))}function g(x,y){let E=m(y);E&&(E.isCubeTexture||E.mapping===cs)?(h===void 0&&(h=new Xt(new Zn(1,1,1),new Fn({name:"BackgroundCubeMaterial",uniforms:ms(hi.backgroundCube.uniforms),vertexShader:hi.backgroundCube.vertexShader,fragmentShader:hi.backgroundCube.fragmentShader,side:xn,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),h.geometry.deleteAttribute("normal"),h.geometry.deleteAttribute("uv"),h.onBeforeRender=function(S,R,P){this.matrixWorld.copyPosition(P.matrixWorld)},Object.defineProperty(h.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),i.update(h)),gs.copy(y.backgroundRotation),gs.x*=-1,gs.y*=-1,gs.z*=-1,E.isCubeTexture&&E.isRenderTargetTexture===!1&&(gs.y*=-1,gs.z*=-1),h.material.uniforms.envMap.value=E,h.material.uniforms.flipEnvMap.value=E.isCubeTexture&&E.isRenderTargetTexture===!1?-1:1,h.material.uniforms.backgroundBlurriness.value=y.backgroundBlurriness,h.material.uniforms.backgroundIntensity.value=y.backgroundIntensity,h.material.uniforms.backgroundRotation.value.setFromMatrix4(HE.makeRotationFromEuler(gs)),h.material.toneMapped=wt.getTransfer(E.colorSpace)!==Ut,(u!==E||f!==E.version||d!==r.toneMapping)&&(h.material.needsUpdate=!0,u=E,f=E.version,d=r.toneMapping),h.layers.enableAll(),x.unshift(h,h.geometry,h.material,0,0,null)):E&&E.isTexture&&(c===void 0&&(c=new Xt(new Xi(2,2),new Fn({name:"BackgroundMaterial",uniforms:ms(hi.background.uniforms),vertexShader:hi.background.vertexShader,fragmentShader:hi.background.fragmentShader,side:gi,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),c.geometry.deleteAttribute("normal"),Object.defineProperty(c.material,"map",{get:function(){return this.uniforms.t2D.value}}),i.update(c)),c.material.uniforms.t2D.value=E,c.material.uniforms.backgroundIntensity.value=y.backgroundIntensity,c.material.toneMapped=wt.getTransfer(E.colorSpace)!==Ut,E.matrixAutoUpdate===!0&&E.updateMatrix(),c.material.uniforms.uvTransform.value.copy(E.matrix),(u!==E||f!==E.version||d!==r.toneMapping)&&(c.material.needsUpdate=!0,u=E,f=E.version,d=r.toneMapping),c.layers.enableAll(),x.unshift(c,c.geometry,c.material,0,0,null))}function p(x,y){x.getRGB(Uh,Kd(r)),n.buffers.color.setClear(Uh.r,Uh.g,Uh.b,y,o)}function M(){h!==void 0&&(h.geometry.dispose(),h.material.dispose(),h=void 0),c!==void 0&&(c.geometry.dispose(),c.material.dispose(),c=void 0)}return{getClearColor:function(){return a},setClearColor:function(x,y=1){a.set(x),l=y,p(a,l)},getClearAlpha:function(){return l},setClearAlpha:function(x){l=x,p(a,l)},render:_,addToRenderList:g,dispose:M}}function kE(r,e){let t=r.getParameter(r.MAX_VERTEX_ATTRIBS),n={},i=f(null),s=i,o=!1;function a(T,N,V,G,Z){let K=!1,Q=u(G,V,N);s!==Q&&(s=Q,c(s.object)),K=d(T,G,V,Z),K&&m(T,G,V,Z),Z!==null&&e.update(Z,r.ELEMENT_ARRAY_BUFFER),(K||o)&&(o=!1,y(T,N,V,G),Z!==null&&r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,e.get(Z).buffer))}function l(){return r.createVertexArray()}function c(T){return r.bindVertexArray(T)}function h(T){return r.deleteVertexArray(T)}function u(T,N,V){let G=V.wireframe===!0,Z=n[T.id];Z===void 0&&(Z={},n[T.id]=Z);let K=Z[N.id];K===void 0&&(K={},Z[N.id]=K);let Q=K[G];return Q===void 0&&(Q=f(l()),K[G]=Q),Q}function f(T){let N=[],V=[],G=[];for(let Z=0;Z=0){let Oe=Z[ne],Ge=K[ne];if(Ge===void 0&&(ne==="instanceMatrix"&&T.instanceMatrix&&(Ge=T.instanceMatrix),ne==="instanceColor"&&T.instanceColor&&(Ge=T.instanceColor)),Oe===void 0||Oe.attribute!==Ge||Ge&&Oe.data!==Ge.data)return!0;Q++}return s.attributesNum!==Q||s.index!==G}function m(T,N,V,G){let Z={},K=N.attributes,Q=0,_e=V.getAttributes();for(let ne in _e)if(_e[ne].location>=0){let Oe=K[ne];Oe===void 0&&(ne==="instanceMatrix"&&T.instanceMatrix&&(Oe=T.instanceMatrix),ne==="instanceColor"&&T.instanceColor&&(Oe=T.instanceColor));let Ge={};Ge.attribute=Oe,Oe&&Oe.data&&(Ge.data=Oe.data),Z[ne]=Ge,Q++}s.attributes=Z,s.attributesNum=Q,s.index=G}function _(){let T=s.newAttributes;for(let N=0,V=T.length;N=0){let Te=Z[_e];if(Te===void 0&&(_e==="instanceMatrix"&&T.instanceMatrix&&(Te=T.instanceMatrix),_e==="instanceColor"&&T.instanceColor&&(Te=T.instanceColor)),Te!==void 0){let Oe=Te.normalized,Ge=Te.itemSize,dt=e.get(Te);if(dt===void 0)continue;let yt=dt.buffer,Rt=dt.type,St=dt.bytesPerElement,se=Rt===r.INT||Rt===r.UNSIGNED_INT||Te.gpuType===Al;if(Te.isInterleavedBufferAttribute){let ge=Te.data,Ve=ge.stride,Ke=Te.offset;if(ge.isInstancedInterleavedBuffer){for(let Ze=0;Ze0&&r.getShaderPrecisionFormat(r.FRAGMENT_SHADER,r.HIGH_FLOAT).precision>0)return"highp";R="mediump"}return R==="mediump"&&r.getShaderPrecisionFormat(r.VERTEX_SHADER,r.MEDIUM_FLOAT).precision>0&&r.getShaderPrecisionFormat(r.FRAGMENT_SHADER,r.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let c=t.precision!==void 0?t.precision:"highp",h=l(c);h!==c&&(console.warn("THREE.WebGLRenderer:",c,"not supported, using",h,"instead."),c=h);let u=t.logarithmicDepthBuffer===!0,f=t.reversedDepthBuffer===!0&&e.has("EXT_clip_control"),d=r.getParameter(r.MAX_TEXTURE_IMAGE_UNITS),m=r.getParameter(r.MAX_VERTEX_TEXTURE_IMAGE_UNITS),_=r.getParameter(r.MAX_TEXTURE_SIZE),g=r.getParameter(r.MAX_CUBE_MAP_TEXTURE_SIZE),p=r.getParameter(r.MAX_VERTEX_ATTRIBS),M=r.getParameter(r.MAX_VERTEX_UNIFORM_VECTORS),x=r.getParameter(r.MAX_VARYING_VECTORS),y=r.getParameter(r.MAX_FRAGMENT_UNIFORM_VECTORS),E=m>0,S=r.getParameter(r.MAX_SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:s,getMaxPrecision:l,textureFormatReadable:o,textureTypeReadable:a,precision:c,logarithmicDepthBuffer:u,reversedDepthBuffer:f,maxTextures:d,maxVertexTextures:m,maxTextureSize:_,maxCubemapSize:g,maxAttributes:p,maxVertexUniforms:M,maxVaryings:x,maxFragmentUniforms:y,vertexTextures:E,maxSamples:S}}function $E(r){let e=this,t=null,n=0,i=!1,s=!1,o=new ni,a=new pt,l={value:null,needsUpdate:!1};this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(u,f){let d=u.length!==0||f||n!==0||i;return i=f,n=u.length,d},this.beginShadows=function(){s=!0,h(null)},this.endShadows=function(){s=!1},this.setGlobalState=function(u,f){t=h(u,f,0)},this.setState=function(u,f,d){let m=u.clippingPlanes,_=u.clipIntersection,g=u.clipShadows,p=r.get(u);if(!i||m===null||m.length===0||s&&!g)s?h(null):c();else{let M=s?0:n,x=M*4,y=p.clippingState||null;l.value=y,y=h(m,f,x,d);for(let E=0;E!==x;++E)y[E]=t[E];p.clippingState=y,this.numIntersection=_?this.numPlanes:0,this.numPlanes+=M}};function c(){l.value!==t&&(l.value=t,l.needsUpdate=n>0),e.numPlanes=n,e.numIntersection=0}function h(u,f,d,m){let _=u!==null?u.length:0,g=null;if(_!==0){if(g=l.value,m!==!0||g===null){let p=d+_*4,M=f.matrixWorldInverse;a.getNormalMatrix(M),(g===null||g.length0){let c=new pa(l.height);return c.fromEquirectangularTexture(r,o),e.set(o,c),o.addEventListener("dispose",i),t(c.texture,o.mapping)}else return null}}return o}function i(o){let a=o.target;a.removeEventListener("dispose",i);let l=e.get(a);l!==void 0&&(e.delete(a),l.dispose())}function s(){e=new WeakMap}return{get:n,dispose:s}}var Io=4,e0=[.125,.215,.35,.446,.526,.582],xs=20,sp=new as,t0=new Be,op=null,ap=0,lp=0,cp=!1,ys=(1+Math.sqrt(5))/2,Po=1/ys,n0=[new C(-ys,Po,0),new C(ys,Po,0),new C(-Po,0,ys),new C(Po,0,ys),new C(0,ys,-Po),new C(0,ys,Po),new C(-1,1,-1),new C(1,1,-1),new C(-1,1,1),new C(1,1,1)],YE=new C,cc=class{constructor(e){this._renderer=e,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(e,t=0,n=.1,i=100,s={}){let{size:o=256,position:a=YE}=s;op=this._renderer.getRenderTarget(),ap=this._renderer.getActiveCubeFace(),lp=this._renderer.getActiveMipmapLevel(),cp=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(o);let l=this._allocateTargets();return l.depthBuffer=!0,this._sceneToCubeUV(e,n,i,l,a),t>0&&this._blur(l,0,0,t),this._applyPMREM(l),this._cleanup(l),l}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=s0(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=r0(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose()}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e2?E:0,E,E),u.setRenderTarget(i),p&&u.render(g,l),u.render(e,l)}g.geometry.dispose(),g.material.dispose(),u.toneMapping=d,u.autoClear=f,e.background=M}_textureToCubeUV(e,t){let n=this._renderer,i=e.mapping===Ei||e.mapping===$i;i?(this._cubemapMaterial===null&&(this._cubemapMaterial=s0()),this._cubemapMaterial.uniforms.flipEnvMap.value=e.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=r0());let s=i?this._cubemapMaterial:this._equirectMaterial,o=new Xt(this._lodPlanes[0],s),a=s.uniforms;a.envMap.value=e;let l=this._cubeSize;Nh(t,0,0,3*l,2*l),n.setRenderTarget(t),n.render(o,sp)}_applyPMREM(e){let t=this._renderer,n=t.autoClear;t.autoClear=!1;let i=this._lodPlanes.length;for(let s=1;sxs&&console.warn(`sigmaRadians, ${s}, is too large and will clip, as it requested ${g} samples when the maximum is set to ${xs}`);let p=[],M=0;for(let R=0;Rx-Io?i-x+Io:0),S=4*(this._cubeSize-y);Nh(t,E,S,3*y,2*y),l.setRenderTarget(t),l.render(u,sp)}};function ZE(r){let e=[],t=[],n=[],i=r,s=r-Io+1+e0.length;for(let o=0;or-Io?l=e0[o-r+Io-1]:o===0&&(l=0),n.push(l);let c=1/(a-2),h=-c,u=1+c,f=[h,h,u,h,u,u,h,h,u,u,h,u],d=6,m=6,_=3,g=2,p=1,M=new Float32Array(_*m*d),x=new Float32Array(g*m*d),y=new Float32Array(p*m*d);for(let S=0;S2?0:-1,w=[R,P,0,R+2/3,P,0,R+2/3,P+1,0,R,P,0,R+2/3,P+1,0,R,P+1,0];M.set(w,_*m*S),x.set(f,g*m*S);let T=[S,S,S,S,S,S];y.set(T,p*m*S)}let E=new et;E.setAttribute("position",new ht(M,_)),E.setAttribute("uv",new ht(x,g)),E.setAttribute("faceIndex",new ht(y,p)),e.push(E),i>Io&&i--}return{lodPlanes:e,sizeLods:t,sigmas:n}}function i0(r,e,t){let n=new Wn(r,e,t);return n.texture.mapping=cs,n.texture.name="PMREM.cubeUv",n.scissorTest=!0,n}function Nh(r,e,t,n,i){r.viewport.set(e,t,n,i),r.scissor.set(e,t,n,i)}function JE(r,e,t){let n=new Float32Array(xs),i=new C(0,1,0);return new Fn({name:"SphericalGaussianBlur",defines:{n:xs,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/t,CUBEUV_MAX_MIP:`${r}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:n},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:i}},vertexShader:vp(),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:bi,depthTest:!1,depthWrite:!1})}function r0(){return new Fn({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:vp(),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:bi,depthTest:!1,depthWrite:!1})}function s0(){return new Fn({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:vp(),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:bi,depthTest:!1,depthWrite:!1})}function vp(){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 jE(r){let e=new WeakMap,t=null;function n(a){if(a&&a.isTexture){let l=a.mapping,c=l===Mo||l===Eo,h=l===Ei||l===$i;if(c||h){let u=e.get(a),f=u!==void 0?u.texture.pmremVersion:0;if(a.isRenderTargetTexture&&a.pmremVersion!==f)return t===null&&(t=new cc(r)),u=c?t.fromEquirectangular(a,u):t.fromCubemap(a,u),u.texture.pmremVersion=a.pmremVersion,e.set(a,u),u.texture;if(u!==void 0)return u.texture;{let d=a.image;return c&&d&&d.height>0||h&&d&&i(d)?(t===null&&(t=new cc(r)),u=c?t.fromEquirectangular(a):t.fromCubemap(a),u.texture.pmremVersion=a.pmremVersion,e.set(a,u),a.addEventListener("dispose",s),u.texture):null}}}return a}function i(a){let l=0,c=6;for(let h=0;he.maxTextureSize&&(E=Math.ceil(y/e.maxTextureSize),y=e.maxTextureSize);let S=new Float32Array(y*E*4*u),R=new $r(S,y,E,u);R.type=Rn,R.needsUpdate=!0;let P=x*4;for(let T=0;T0)return r;let i=e*t,s=a0[i];if(s===void 0&&(s=new Float32Array(i),a0[i]=s),e!==0){n.toArray(s,0);for(let o=1,a=0;o!==e;++o)a+=t,r[o].toArray(s,a)}return s}function on(r,e){if(r.length!==e.length)return!1;for(let t=0,n=r.length;t":" "} ${a}: ${t[o]}`)}return n.join(` `)}var p0=new pt;function YS(r){wt._getMatrix(p0,wt.workingColorSpace,r);let e=`mat3( ${p0.elements.map(t=>t.toFixed(4))} )`;switch(wt.getTransfer(r)){case Ys:return[e,"LinearTransferOETF"];case Ut:return[e,"sRGBTransferOETF"];default:return console.warn("THREE.WebGLProgram: Unsupported color space: ",r),[e,"LinearTransferOETF"]}}function m0(r,e,t){let n=r.getShaderParameter(e,r.COMPILE_STATUS),s=(r.getShaderInfoLog(e)||"").trim();if(n&&s==="")return"";let o=/ERROR: 0:(\d+)/.exec(s);if(o){let a=parseInt(o[1]);return t.toUpperCase()+` `+s+` `+qS(r.getShaderSource(e),a)}else return s}function ZS(r,e){let t=YS(e);return[`vec4 ${r}( vec4 value ) {`,` return ${t[1]}( vec4( value.rgb * ${t[0]}, value.a ) );`,"}"].join(` `)}function JS(r,e){let t;switch(e){case Rd:t="Linear";break;case Cd:t="Reinhard";break;case Pd:t="Cineon";break;case Id:t="ACESFilmic";break;case Ld:t="AgX";break;case Ud:t="Neutral";break;case Dd:t="Custom";break;default:console.warn("THREE.WebGLProgram: Unsupported toneMapping:",e),t="Linear"}return"vec3 "+r+"( vec3 color ) { return "+t+"ToneMapping( color ); }"}var Fh=new C;function jS(){wt.getLuminanceCoefficients(Fh);let r=Fh.x.toFixed(4),e=Fh.y.toFixed(4),t=Fh.z.toFixed(4);return["float luminance( const in vec3 rgb ) {",` const vec3 weights = vec3( ${r}, ${e}, ${t} );`," return dot( weights, rgb );","}"].join(` `)}function KS(r){return[r.extensionClipCullDistance?"#extension GL_ANGLE_clip_cull_distance : require":"",r.extensionMultiDraw?"#extension GL_ANGLE_multi_draw : require":""].filter(lc).join(` `)}function QS(r){let e=[];for(let t in r){let n=r[t];n!==!1&&e.push("#define "+t+" "+n)}return e.join(` `)}function ew(r,e){let t={},n=r.getProgramParameter(e,r.ACTIVE_ATTRIBUTES);for(let i=0;i/gm;function pp(r){return r.replace(tw,iw)}var nw=new Map;function iw(r,e){let t=_t[e];if(t===void 0){let n=nw.get(e);if(n!==void 0)t=_t[n],console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',e,n);else throw new Error("Can not resolve #include <"+e+">")}return pp(t)}var rw=/#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 y0(r){return r.replace(rw,sw)}function sw(r,e,t,n){let i="";for(let s=parseInt(e);s0&&(g+=` `),p=["#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,m].filter(lc).join(` `),p.length>0&&(p+=` `)):(g=[x0(t),"#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,m,t.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",t.batching?"#define USE_BATCHING":"",t.batchingColor?"#define USE_BATCHING_COLOR":"",t.instancing?"#define USE_INSTANCING":"",t.instancingColor?"#define USE_INSTANCING_COLOR":"",t.instancingMorph?"#define USE_INSTANCING_MORPH":"",t.useFog&&t.fog?"#define USE_FOG":"",t.useFog&&t.fogExp2?"#define FOG_EXP2":"",t.map?"#define USE_MAP":"",t.envMap?"#define USE_ENVMAP":"",t.envMap?"#define "+h:"",t.lightMap?"#define USE_LIGHTMAP":"",t.aoMap?"#define USE_AOMAP":"",t.bumpMap?"#define USE_BUMPMAP":"",t.normalMap?"#define USE_NORMALMAP":"",t.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",t.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",t.displacementMap?"#define USE_DISPLACEMENTMAP":"",t.emissiveMap?"#define USE_EMISSIVEMAP":"",t.anisotropy?"#define USE_ANISOTROPY":"",t.anisotropyMap?"#define USE_ANISOTROPYMAP":"",t.clearcoatMap?"#define USE_CLEARCOATMAP":"",t.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",t.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",t.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",t.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",t.specularMap?"#define USE_SPECULARMAP":"",t.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",t.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",t.roughnessMap?"#define USE_ROUGHNESSMAP":"",t.metalnessMap?"#define USE_METALNESSMAP":"",t.alphaMap?"#define USE_ALPHAMAP":"",t.alphaHash?"#define USE_ALPHAHASH":"",t.transmission?"#define USE_TRANSMISSION":"",t.transmissionMap?"#define USE_TRANSMISSIONMAP":"",t.thicknessMap?"#define USE_THICKNESSMAP":"",t.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",t.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",t.mapUv?"#define MAP_UV "+t.mapUv:"",t.alphaMapUv?"#define ALPHAMAP_UV "+t.alphaMapUv:"",t.lightMapUv?"#define LIGHTMAP_UV "+t.lightMapUv:"",t.aoMapUv?"#define AOMAP_UV "+t.aoMapUv:"",t.emissiveMapUv?"#define EMISSIVEMAP_UV "+t.emissiveMapUv:"",t.bumpMapUv?"#define BUMPMAP_UV "+t.bumpMapUv:"",t.normalMapUv?"#define NORMALMAP_UV "+t.normalMapUv:"",t.displacementMapUv?"#define DISPLACEMENTMAP_UV "+t.displacementMapUv:"",t.metalnessMapUv?"#define METALNESSMAP_UV "+t.metalnessMapUv:"",t.roughnessMapUv?"#define ROUGHNESSMAP_UV "+t.roughnessMapUv:"",t.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+t.anisotropyMapUv:"",t.clearcoatMapUv?"#define CLEARCOATMAP_UV "+t.clearcoatMapUv:"",t.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+t.clearcoatNormalMapUv:"",t.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+t.clearcoatRoughnessMapUv:"",t.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+t.iridescenceMapUv:"",t.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+t.iridescenceThicknessMapUv:"",t.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+t.sheenColorMapUv:"",t.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+t.sheenRoughnessMapUv:"",t.specularMapUv?"#define SPECULARMAP_UV "+t.specularMapUv:"",t.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+t.specularColorMapUv:"",t.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+t.specularIntensityMapUv:"",t.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+t.transmissionMapUv:"",t.thicknessMapUv?"#define THICKNESSMAP_UV "+t.thicknessMapUv:"",t.vertexTangents&&t.flatShading===!1?"#define USE_TANGENT":"",t.vertexColors?"#define USE_COLOR":"",t.vertexAlphas?"#define USE_COLOR_ALPHA":"",t.vertexUv1s?"#define USE_UV1":"",t.vertexUv2s?"#define USE_UV2":"",t.vertexUv3s?"#define USE_UV3":"",t.pointsUvs?"#define USE_POINTS_UV":"",t.flatShading?"#define FLAT_SHADED":"",t.skinning?"#define USE_SKINNING":"",t.morphTargets?"#define USE_MORPHTARGETS":"",t.morphNormals&&t.flatShading===!1?"#define USE_MORPHNORMALS":"",t.morphColors?"#define USE_MORPHCOLORS":"",t.morphTargetsCount>0?"#define MORPHTARGETS_TEXTURE_STRIDE "+t.morphTextureStride:"",t.morphTargetsCount>0?"#define MORPHTARGETS_COUNT "+t.morphTargetsCount:"",t.doubleSided?"#define DOUBLE_SIDED":"",t.flipSided?"#define FLIP_SIDED":"",t.shadowMapEnabled?"#define USE_SHADOWMAP":"",t.shadowMapEnabled?"#define "+l:"",t.sizeAttenuation?"#define USE_SIZEATTENUATION":"",t.numLightProbes>0?"#define USE_LIGHT_PROBES":"",t.logarithmicDepthBuffer?"#define USE_LOGARITHMIC_DEPTH_BUFFER":"",t.reversedDepthBuffer?"#define USE_REVERSED_DEPTH_BUFFER":"","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(lc).join(` `),p=[x0(t),"#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,m,t.useFog&&t.fog?"#define USE_FOG":"",t.useFog&&t.fogExp2?"#define FOG_EXP2":"",t.alphaToCoverage?"#define ALPHA_TO_COVERAGE":"",t.map?"#define USE_MAP":"",t.matcap?"#define USE_MATCAP":"",t.envMap?"#define USE_ENVMAP":"",t.envMap?"#define "+c:"",t.envMap?"#define "+h:"",t.envMap?"#define "+u:"",f?"#define CUBEUV_TEXEL_WIDTH "+f.texelWidth:"",f?"#define CUBEUV_TEXEL_HEIGHT "+f.texelHeight:"",f?"#define CUBEUV_MAX_MIP "+f.maxMip+".0":"",t.lightMap?"#define USE_LIGHTMAP":"",t.aoMap?"#define USE_AOMAP":"",t.bumpMap?"#define USE_BUMPMAP":"",t.normalMap?"#define USE_NORMALMAP":"",t.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",t.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",t.emissiveMap?"#define USE_EMISSIVEMAP":"",t.anisotropy?"#define USE_ANISOTROPY":"",t.anisotropyMap?"#define USE_ANISOTROPYMAP":"",t.clearcoat?"#define USE_CLEARCOAT":"",t.clearcoatMap?"#define USE_CLEARCOATMAP":"",t.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",t.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",t.dispersion?"#define USE_DISPERSION":"",t.iridescence?"#define USE_IRIDESCENCE":"",t.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",t.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",t.specularMap?"#define USE_SPECULARMAP":"",t.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",t.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",t.roughnessMap?"#define USE_ROUGHNESSMAP":"",t.metalnessMap?"#define USE_METALNESSMAP":"",t.alphaMap?"#define USE_ALPHAMAP":"",t.alphaTest?"#define USE_ALPHATEST":"",t.alphaHash?"#define USE_ALPHAHASH":"",t.sheen?"#define USE_SHEEN":"",t.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",t.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",t.transmission?"#define USE_TRANSMISSION":"",t.transmissionMap?"#define USE_TRANSMISSIONMAP":"",t.thicknessMap?"#define USE_THICKNESSMAP":"",t.vertexTangents&&t.flatShading===!1?"#define USE_TANGENT":"",t.vertexColors||t.instancingColor||t.batchingColor?"#define USE_COLOR":"",t.vertexAlphas?"#define USE_COLOR_ALPHA":"",t.vertexUv1s?"#define USE_UV1":"",t.vertexUv2s?"#define USE_UV2":"",t.vertexUv3s?"#define USE_UV3":"",t.pointsUvs?"#define USE_POINTS_UV":"",t.gradientMap?"#define USE_GRADIENTMAP":"",t.flatShading?"#define FLAT_SHADED":"",t.doubleSided?"#define DOUBLE_SIDED":"",t.flipSided?"#define FLIP_SIDED":"",t.shadowMapEnabled?"#define USE_SHADOWMAP":"",t.shadowMapEnabled?"#define "+l:"",t.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",t.numLightProbes>0?"#define USE_LIGHT_PROBES":"",t.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",t.decodeVideoTextureEmissive?"#define DECODE_VIDEO_TEXTURE_EMISSIVE":"",t.logarithmicDepthBuffer?"#define USE_LOGARITHMIC_DEPTH_BUFFER":"",t.reversedDepthBuffer?"#define USE_REVERSED_DEPTH_BUFFER":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",t.toneMapping!==Mi?"#define TONE_MAPPING":"",t.toneMapping!==Mi?_t.tonemapping_pars_fragment:"",t.toneMapping!==Mi?JS("toneMapping",t.toneMapping):"",t.dithering?"#define DITHERING":"",t.opaque?"#define OPAQUE":"",_t.colorspace_pars_fragment,ZS("linearToOutputTexel",t.outputColorSpace),jS(),t.useDepthPacking?"#define DEPTH_PACKING "+t.depthPacking:"",` `].filter(lc).join(` `)),o=pp(o),o=g0(o,t),o=_0(o,t),a=pp(a),a=g0(a,t),a=_0(a,t),o=y0(o),a=y0(a),t.isRawShaderMaterial!==!0&&(M=`#version 300 es `,g=[d,"#define attribute in","#define varying out","#define texture2D texture"].join(` `)+` `+g,p=["#define varying in",t.glslVersion===Dh?"":"layout(location = 0) out highp vec4 pc_fragColor;",t.glslVersion===Dh?"":"#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(` `)+` `+p);let x=M+g+o,y=M+p+a,E=d0(i,i.VERTEX_SHADER,x),S=d0(i,i.FRAGMENT_SHADER,y);i.attachShader(_,E),i.attachShader(_,S),t.index0AttributeName!==void 0?i.bindAttribLocation(_,0,t.index0AttributeName):t.morphTargets===!0&&i.bindAttribLocation(_,0,"position"),i.linkProgram(_);function R(N){if(r.debug.checkShaderErrors){let V=i.getProgramInfoLog(_)||"",G=i.getShaderInfoLog(E)||"",Z=i.getShaderInfoLog(S)||"",K=V.trim(),Q=G.trim(),_e=Z.trim(),ne=!0,Te=!0;if(i.getProgramParameter(_,i.LINK_STATUS)===!1)if(ne=!1,typeof r.debug.onShaderError=="function")r.debug.onShaderError(i,_,E,S);else{let Oe=m0(i,E,"vertex"),Ge=m0(i,S,"fragment");console.error("THREE.WebGLProgram: Shader Error "+i.getError()+" - VALIDATE_STATUS "+i.getProgramParameter(_,i.VALIDATE_STATUS)+` Material Name: `+N.name+` Material Type: `+N.type+` Program Info Log: `+K+` `+Oe+` `+Ge)}else K!==""?console.warn("THREE.WebGLProgram: Program Info Log:",K):(Q===""||_e==="")&&(Te=!1);Te&&(N.diagnostics={runnable:ne,programLog:K,vertexShader:{log:Q,prefix:g},fragmentShader:{log:_e,prefix:p}})}i.deleteShader(E),i.deleteShader(S),P=new Do(i,_),w=ew(i,_)}let P;this.getUniforms=function(){return P===void 0&&R(this),P};let w;this.getAttributes=function(){return w===void 0&&R(this),w};let T=t.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return T===!1&&(T=i.getProgramParameter(_,XS)),T},this.destroy=function(){n.releaseStatesOfProgram(this),i.deleteProgram(_),this.program=void 0},this.type=t.shaderType,this.name=t.shaderName,this.id=$S++,this.cacheKey=e,this.usedTimes=1,this.program=_,this.vertexShader=E,this.fragmentShader=S,this}var fw=0,mp=class{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(e){let t=e.vertexShader,n=e.fragmentShader,i=this._getShaderStage(t),s=this._getShaderStage(n),o=this._getShaderCacheForMaterial(e);return o.has(i)===!1&&(o.add(i),i.usedTimes++),o.has(s)===!1&&(o.add(s),s.usedTimes++),this}remove(e){let t=this.materialCache.get(e);for(let n of t)n.usedTimes--,n.usedTimes===0&&this.shaderCache.delete(n.code);return this.materialCache.delete(e),this}getVertexShaderID(e){return this._getShaderStage(e.vertexShader).id}getFragmentShaderID(e){return this._getShaderStage(e.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(e){let t=this.materialCache,n=t.get(e);return n===void 0&&(n=new Set,t.set(e,n)),n}_getShaderStage(e){let t=this.shaderCache,n=t.get(e);return n===void 0&&(n=new gp(e),t.set(e,n)),n}},gp=class{constructor(e){this.id=fw++,this.code=e,this.usedTimes=0}};function dw(r,e,t,n,i,s,o){let a=new Yr,l=new mp,c=new Set,h=[],u=i.logarithmicDepthBuffer,f=i.vertexTextures,d=i.precision,m={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 _(w){return c.add(w),w===0?"uv":`uv${w}`}function g(w,T,N,V,G){let Z=V.fog,K=G.geometry,Q=w.isMeshStandardMaterial?V.environment:null,_e=(w.isMeshStandardMaterial?t:e).get(w.envMap||Q),ne=_e&&_e.mapping===cs?_e.image.height:null,Te=m[w.type];w.precision!==null&&(d=i.getMaxPrecision(w.precision),d!==w.precision&&console.warn("THREE.WebGLProgram.getParameters:",w.precision,"not supported, using",d,"instead."));let Oe=K.morphAttributes.position||K.morphAttributes.normal||K.morphAttributes.color,Ge=Oe!==void 0?Oe.length:0,dt=0;K.morphAttributes.position!==void 0&&(dt=1),K.morphAttributes.normal!==void 0&&(dt=2),K.morphAttributes.color!==void 0&&(dt=3);let yt,Rt,St,se;if(Te){let Pt=hi[Te];yt=Pt.vertexShader,Rt=Pt.fragmentShader}else yt=w.vertexShader,Rt=w.fragmentShader,l.update(w),St=l.getVertexShaderID(w),se=l.getFragmentShaderID(w);let ge=r.getRenderTarget(),Ve=r.state.buffers.depth.getReversed(),Ke=G.isInstancedMesh===!0,Ze=G.isBatchedMesh===!0,xt=!!w.map,Bt=!!w.matcap,O=!!_e,pe=!!w.aoMap,he=!!w.lightMap,oe=!!w.bumpMap,ae=!!w.normalMap,ve=!!w.displacementMap,be=!!w.emissiveMap,we=!!w.metalnessMap,ft=!!w.roughnessMap,lt=w.anisotropy>0,L=w.clearcoat>0,A=w.dispersion>0,q=w.iridescence>0,ee=w.sheen>0,de=w.transmission>0,ie=lt&&!!w.anisotropyMap,He=L&&!!w.clearcoatMap,Ee=L&&!!w.clearcoatNormalMap,ke=L&&!!w.clearcoatRoughnessMap,Je=q&&!!w.iridescenceMap,ye=q&&!!w.iridescenceThicknessMap,Re=ee&&!!w.sheenColorMap,rt=ee&&!!w.sheenRoughnessMap,Ie=!!w.specularMap,Pe=!!w.specularColorMap,Ne=!!w.specularIntensityMap,z=de&&!!w.transmissionMap,me=de&&!!w.thicknessMap,Ae=!!w.gradientMap,We=!!w.alphaMap,Me=w.alphaTest>0,fe=!!w.alphaHash,$e=!!w.extensions,ct=Mi;w.toneMapped&&(ge===null||ge.isXRRenderTarget===!0)&&(ct=r.toneMapping);let Nt={shaderID:Te,shaderType:w.type,shaderName:w.name,vertexShader:yt,fragmentShader:Rt,defines:w.defines,customVertexShaderID:St,customFragmentShaderID:se,isRawShaderMaterial:w.isRawShaderMaterial===!0,glslVersion:w.glslVersion,precision:d,batching:Ze,batchingColor:Ze&&G._colorsTexture!==null,instancing:Ke,instancingColor:Ke&&G.instanceColor!==null,instancingMorph:Ke&&G.morphTexture!==null,supportsVertexTextures:f,outputColorSpace:ge===null?r.outputColorSpace:ge.isXRRenderTarget===!0?ge.texture.colorSpace:ur,alphaToCoverage:!!w.alphaToCoverage,map:xt,matcap:Bt,envMap:O,envMapMode:O&&_e.mapping,envMapCubeUVHeight:ne,aoMap:pe,lightMap:he,bumpMap:oe,normalMap:ae,displacementMap:f&&ve,emissiveMap:be,normalMapObjectSpace:ae&&w.normalMapType===Hd,normalMapTangentSpace:ae&&w.normalMapType===qi,metalnessMap:we,roughnessMap:ft,anisotropy:lt,anisotropyMap:ie,clearcoat:L,clearcoatMap:He,clearcoatNormalMap:Ee,clearcoatRoughnessMap:ke,dispersion:A,iridescence:q,iridescenceMap:Je,iridescenceThicknessMap:ye,sheen:ee,sheenColorMap:Re,sheenRoughnessMap:rt,specularMap:Ie,specularColorMap:Pe,specularIntensityMap:Ne,transmission:de,transmissionMap:z,thicknessMap:me,gradientMap:Ae,opaque:w.transparent===!1&&w.blending===lr&&w.alphaToCoverage===!1,alphaMap:We,alphaTest:Me,alphaHash:fe,combine:w.combine,mapUv:xt&&_(w.map.channel),aoMapUv:pe&&_(w.aoMap.channel),lightMapUv:he&&_(w.lightMap.channel),bumpMapUv:oe&&_(w.bumpMap.channel),normalMapUv:ae&&_(w.normalMap.channel),displacementMapUv:ve&&_(w.displacementMap.channel),emissiveMapUv:be&&_(w.emissiveMap.channel),metalnessMapUv:we&&_(w.metalnessMap.channel),roughnessMapUv:ft&&_(w.roughnessMap.channel),anisotropyMapUv:ie&&_(w.anisotropyMap.channel),clearcoatMapUv:He&&_(w.clearcoatMap.channel),clearcoatNormalMapUv:Ee&&_(w.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:ke&&_(w.clearcoatRoughnessMap.channel),iridescenceMapUv:Je&&_(w.iridescenceMap.channel),iridescenceThicknessMapUv:ye&&_(w.iridescenceThicknessMap.channel),sheenColorMapUv:Re&&_(w.sheenColorMap.channel),sheenRoughnessMapUv:rt&&_(w.sheenRoughnessMap.channel),specularMapUv:Ie&&_(w.specularMap.channel),specularColorMapUv:Pe&&_(w.specularColorMap.channel),specularIntensityMapUv:Ne&&_(w.specularIntensityMap.channel),transmissionMapUv:z&&_(w.transmissionMap.channel),thicknessMapUv:me&&_(w.thicknessMap.channel),alphaMapUv:We&&_(w.alphaMap.channel),vertexTangents:!!K.attributes.tangent&&(ae||lt),vertexColors:w.vertexColors,vertexAlphas:w.vertexColors===!0&&!!K.attributes.color&&K.attributes.color.itemSize===4,pointsUvs:G.isPoints===!0&&!!K.attributes.uv&&(xt||We),fog:!!Z,useFog:w.fog===!0,fogExp2:!!Z&&Z.isFogExp2,flatShading:w.flatShading===!0&&w.wireframe===!1,sizeAttenuation:w.sizeAttenuation===!0,logarithmicDepthBuffer:u,reversedDepthBuffer:Ve,skinning:G.isSkinnedMesh===!0,morphTargets:K.morphAttributes.position!==void 0,morphNormals:K.morphAttributes.normal!==void 0,morphColors:K.morphAttributes.color!==void 0,morphTargetsCount:Ge,morphTextureStride:dt,numDirLights:T.directional.length,numPointLights:T.point.length,numSpotLights:T.spot.length,numSpotLightMaps:T.spotLightMap.length,numRectAreaLights:T.rectArea.length,numHemiLights:T.hemi.length,numDirLightShadows:T.directionalShadowMap.length,numPointLightShadows:T.pointShadowMap.length,numSpotLightShadows:T.spotShadowMap.length,numSpotLightShadowsWithMaps:T.numSpotLightShadowsWithMaps,numLightProbes:T.numLightProbes,numClippingPlanes:o.numPlanes,numClipIntersection:o.numIntersection,dithering:w.dithering,shadowMapEnabled:r.shadowMap.enabled&&N.length>0,shadowMapType:r.shadowMap.type,toneMapping:ct,decodeVideoTexture:xt&&w.map.isVideoTexture===!0&&wt.getTransfer(w.map.colorSpace)===Ut,decodeVideoTextureEmissive:be&&w.emissiveMap.isVideoTexture===!0&&wt.getTransfer(w.emissiveMap.colorSpace)===Ut,premultipliedAlpha:w.premultipliedAlpha,doubleSided:w.side===ci,flipSided:w.side===xn,useDepthPacking:w.depthPacking>=0,depthPacking:w.depthPacking||0,index0AttributeName:w.index0AttributeName,extensionClipCullDistance:$e&&w.extensions.clipCullDistance===!0&&n.has("WEBGL_clip_cull_distance"),extensionMultiDraw:($e&&w.extensions.multiDraw===!0||Ze)&&n.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:n.has("KHR_parallel_shader_compile"),customProgramCacheKey:w.customProgramCacheKey()};return Nt.vertexUv1s=c.has(1),Nt.vertexUv2s=c.has(2),Nt.vertexUv3s=c.has(3),c.clear(),Nt}function p(w){let T=[];if(w.shaderID?T.push(w.shaderID):(T.push(w.customVertexShaderID),T.push(w.customFragmentShaderID)),w.defines!==void 0)for(let N in w.defines)T.push(N),T.push(w.defines[N]);return w.isRawShaderMaterial===!1&&(M(T,w),x(T,w),T.push(r.outputColorSpace)),T.push(w.customProgramCacheKey),T.join()}function M(w,T){w.push(T.precision),w.push(T.outputColorSpace),w.push(T.envMapMode),w.push(T.envMapCubeUVHeight),w.push(T.mapUv),w.push(T.alphaMapUv),w.push(T.lightMapUv),w.push(T.aoMapUv),w.push(T.bumpMapUv),w.push(T.normalMapUv),w.push(T.displacementMapUv),w.push(T.emissiveMapUv),w.push(T.metalnessMapUv),w.push(T.roughnessMapUv),w.push(T.anisotropyMapUv),w.push(T.clearcoatMapUv),w.push(T.clearcoatNormalMapUv),w.push(T.clearcoatRoughnessMapUv),w.push(T.iridescenceMapUv),w.push(T.iridescenceThicknessMapUv),w.push(T.sheenColorMapUv),w.push(T.sheenRoughnessMapUv),w.push(T.specularMapUv),w.push(T.specularColorMapUv),w.push(T.specularIntensityMapUv),w.push(T.transmissionMapUv),w.push(T.thicknessMapUv),w.push(T.combine),w.push(T.fogExp2),w.push(T.sizeAttenuation),w.push(T.morphTargetsCount),w.push(T.morphAttributeCount),w.push(T.numDirLights),w.push(T.numPointLights),w.push(T.numSpotLights),w.push(T.numSpotLightMaps),w.push(T.numHemiLights),w.push(T.numRectAreaLights),w.push(T.numDirLightShadows),w.push(T.numPointLightShadows),w.push(T.numSpotLightShadows),w.push(T.numSpotLightShadowsWithMaps),w.push(T.numLightProbes),w.push(T.shadowMapType),w.push(T.toneMapping),w.push(T.numClippingPlanes),w.push(T.numClipIntersection),w.push(T.depthPacking)}function x(w,T){a.disableAll(),T.supportsVertexTextures&&a.enable(0),T.instancing&&a.enable(1),T.instancingColor&&a.enable(2),T.instancingMorph&&a.enable(3),T.matcap&&a.enable(4),T.envMap&&a.enable(5),T.normalMapObjectSpace&&a.enable(6),T.normalMapTangentSpace&&a.enable(7),T.clearcoat&&a.enable(8),T.iridescence&&a.enable(9),T.alphaTest&&a.enable(10),T.vertexColors&&a.enable(11),T.vertexAlphas&&a.enable(12),T.vertexUv1s&&a.enable(13),T.vertexUv2s&&a.enable(14),T.vertexUv3s&&a.enable(15),T.vertexTangents&&a.enable(16),T.anisotropy&&a.enable(17),T.alphaHash&&a.enable(18),T.batching&&a.enable(19),T.dispersion&&a.enable(20),T.batchingColor&&a.enable(21),T.gradientMap&&a.enable(22),w.push(a.mask),a.disableAll(),T.fog&&a.enable(0),T.useFog&&a.enable(1),T.flatShading&&a.enable(2),T.logarithmicDepthBuffer&&a.enable(3),T.reversedDepthBuffer&&a.enable(4),T.skinning&&a.enable(5),T.morphTargets&&a.enable(6),T.morphNormals&&a.enable(7),T.morphColors&&a.enable(8),T.premultipliedAlpha&&a.enable(9),T.shadowMapEnabled&&a.enable(10),T.doubleSided&&a.enable(11),T.flipSided&&a.enable(12),T.useDepthPacking&&a.enable(13),T.dithering&&a.enable(14),T.transmission&&a.enable(15),T.sheen&&a.enable(16),T.opaque&&a.enable(17),T.pointsUvs&&a.enable(18),T.decodeVideoTexture&&a.enable(19),T.decodeVideoTextureEmissive&&a.enable(20),T.alphaToCoverage&&a.enable(21),w.push(a.mask)}function y(w){let T=m[w.type],N;if(T){let V=hi[T];N=Qd.clone(V.uniforms)}else N=w.uniforms;return N}function E(w,T){let N;for(let V=0,G=h.length;V0?n.push(p):d.transparent===!0?i.push(p):t.push(p)}function l(u,f,d,m,_,g){let p=o(u,f,d,m,_,g);d.transmission>0?n.unshift(p):d.transparent===!0?i.unshift(p):t.unshift(p)}function c(u,f){t.length>1&&t.sort(u||mw),n.length>1&&n.sort(f||v0),i.length>1&&i.sort(f||v0)}function h(){for(let u=e,f=r.length;u=s.length?(o=new b0,s.push(o)):o=s[i],o}function t(){r=new WeakMap}return{get:e,dispose:t}}function _w(){let r={};return{get:function(e){if(r[e.id]!==void 0)return r[e.id];let t;switch(e.type){case"DirectionalLight":t={direction:new C,color:new Be};break;case"SpotLight":t={position:new C,direction:new C,color:new Be,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":t={position:new C,color:new Be,distance:0,decay:0};break;case"HemisphereLight":t={direction:new C,skyColor:new Be,groundColor:new Be};break;case"RectAreaLight":t={color:new Be,position:new C,halfWidth:new C,halfHeight:new C};break}return r[e.id]=t,t}}}function yw(){let r={};return{get:function(e){if(r[e.id]!==void 0)return r[e.id];let t;switch(e.type){case"DirectionalLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new ce};break;case"SpotLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new ce};break;case"PointLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new ce,shadowCameraNear:1,shadowCameraFar:1e3};break}return r[e.id]=t,t}}}var xw=0;function vw(r,e){return(e.castShadow?2:0)-(r.castShadow?2:0)+(e.map?1:0)-(r.map?1:0)}function bw(r){let e=new _w,t=yw(),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 c=0;c<9;c++)n.probe.push(new C);let i=new C,s=new Qe,o=new Qe;function a(c){let h=0,u=0,f=0;for(let w=0;w<9;w++)n.probe[w].set(0,0,0);let d=0,m=0,_=0,g=0,p=0,M=0,x=0,y=0,E=0,S=0,R=0;c.sort(vw);for(let w=0,T=c.length;w0&&(r.has("OES_texture_float_linear")===!0?(n.rectAreaLTC1=Ue.LTC_FLOAT_1,n.rectAreaLTC2=Ue.LTC_FLOAT_2):(n.rectAreaLTC1=Ue.LTC_HALF_1,n.rectAreaLTC2=Ue.LTC_HALF_2)),n.ambient[0]=h,n.ambient[1]=u,n.ambient[2]=f;let P=n.hash;(P.directionalLength!==d||P.pointLength!==m||P.spotLength!==_||P.rectAreaLength!==g||P.hemiLength!==p||P.numDirectionalShadows!==M||P.numPointShadows!==x||P.numSpotShadows!==y||P.numSpotMaps!==E||P.numLightProbes!==R)&&(n.directional.length=d,n.spot.length=_,n.rectArea.length=g,n.point.length=m,n.hemi.length=p,n.directionalShadow.length=M,n.directionalShadowMap.length=M,n.pointShadow.length=x,n.pointShadowMap.length=x,n.spotShadow.length=y,n.spotShadowMap.length=y,n.directionalShadowMatrix.length=M,n.pointShadowMatrix.length=x,n.spotLightMatrix.length=y+E-S,n.spotLightMap.length=E,n.numSpotLightShadowsWithMaps=S,n.numLightProbes=R,P.directionalLength=d,P.pointLength=m,P.spotLength=_,P.rectAreaLength=g,P.hemiLength=p,P.numDirectionalShadows=M,P.numPointShadows=x,P.numSpotShadows=y,P.numSpotMaps=E,P.numLightProbes=R,n.version=xw++)}function l(c,h){let u=0,f=0,d=0,m=0,_=0,g=h.matrixWorldInverse;for(let p=0,M=c.length;p=o.length?(a=new M0(r),o.push(a)):a=o[s],a}function n(){e=new WeakMap}return{get:t,dispose:n}}var Ew=`void main() { gl_Position = vec4( position, 1.0 ); }`,Sw=`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 ww(r,e,t){let n=new Gi,i=new ce,s=new ce,o=new At,a=new po({depthPacking:Vd}),l=new mo,c={},h=t.maxTextureSize,u={[gi]:xn,[xn]:gi,[ci]:ci},f=new Fn({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new ce},radius:{value:4}},vertexShader:Ew,fragmentShader:Sw}),d=f.clone();d.defines.HORIZONTAL_PASS=1;let m=new et;m.setAttribute("position",new ht(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));let _=new Xt(m,f),g=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=yh;let p=this.type;this.render=function(S,R,P){if(g.enabled===!1||g.autoUpdate===!1&&g.needsUpdate===!1||S.length===0)return;let w=r.getRenderTarget(),T=r.getActiveCubeFace(),N=r.getActiveMipmapLevel(),V=r.state;V.setBlending(bi),V.buffers.depth.getReversed()===!0?V.buffers.color.setClear(0,0,0,0):V.buffers.color.setClear(1,1,1,1),V.buffers.depth.setTest(!0),V.setScissorTest(!1);let G=p!==li&&this.type===li,Z=p===li&&this.type!==li;for(let K=0,Q=S.length;Kh||i.y>h)&&(i.x>h&&(s.x=Math.floor(h/Te.x),i.x=s.x*Te.x,ne.mapSize.x=s.x),i.y>h&&(s.y=Math.floor(h/Te.y),i.y=s.y*Te.y,ne.mapSize.y=s.y)),ne.map===null||G===!0||Z===!0){let Ge=this.type!==li?{minFilter:un,magFilter:un}:{};ne.map!==null&&ne.map.dispose(),ne.map=new Wn(i.x,i.y,Ge),ne.map.texture.name=_e.name+".shadowMap",ne.camera.updateProjectionMatrix()}r.setRenderTarget(ne.map),r.clear();let Oe=ne.getViewportCount();for(let Ge=0;Ge0||R.map&&R.alphaTest>0||R.alphaToCoverage===!0){let V=T.uuid,G=R.uuid,Z=c[V];Z===void 0&&(Z={},c[V]=Z);let K=Z[G];K===void 0&&(K=T.clone(),Z[G]=K,R.addEventListener("dispose",E)),T=K}if(T.visible=R.visible,T.wireframe=R.wireframe,w===li?T.side=R.shadowSide!==null?R.shadowSide:R.side:T.side=R.shadowSide!==null?R.shadowSide:u[R.side],T.alphaMap=R.alphaMap,T.alphaTest=R.alphaToCoverage===!0?.5:R.alphaTest,T.map=R.map,T.clipShadows=R.clipShadows,T.clippingPlanes=R.clippingPlanes,T.clipIntersection=R.clipIntersection,T.displacementMap=R.displacementMap,T.displacementScale=R.displacementScale,T.displacementBias=R.displacementBias,T.wireframeLinewidth=R.wireframeLinewidth,T.linewidth=R.linewidth,P.isPointLight===!0&&T.isMeshDistanceMaterial===!0){let V=r.properties.get(T);V.light=P}return T}function y(S,R,P,w,T){if(S.visible===!1)return;if(S.layers.test(R.layers)&&(S.isMesh||S.isLine||S.isPoints)&&(S.castShadow||S.receiveShadow&&T===li)&&(!S.frustumCulled||n.intersectsObject(S))){S.modelViewMatrix.multiplyMatrices(P.matrixWorldInverse,S.matrixWorld);let G=e.update(S),Z=S.material;if(Array.isArray(Z)){let K=G.groups;for(let Q=0,_e=K.length;Q<_e;Q++){let ne=K[Q],Te=Z[ne.materialIndex];if(Te&&Te.visible){let Oe=x(S,Te,w,T);S.onBeforeShadow(r,S,R,P,G,Oe,ne),r.renderBufferDirect(P,null,G,Oe,S,ne),S.onAfterShadow(r,S,R,P,G,Oe,ne)}}}else if(Z.visible){let K=x(S,Z,w,T);S.onBeforeShadow(r,S,R,P,G,K,null),r.renderBufferDirect(P,null,G,K,S,null),S.onAfterShadow(r,S,R,P,G,K,null)}}let V=S.children;for(let G=0,Z=V.length;G=1):ne.indexOf("OpenGL ES")!==-1&&(_e=parseFloat(/^OpenGL ES (\d)/.exec(ne)[1]),Q=_e>=2);let Te=null,Oe={},Ge=r.getParameter(r.SCISSOR_BOX),dt=r.getParameter(r.VIEWPORT),yt=new At().fromArray(Ge),Rt=new At().fromArray(dt);function St(z,me,Ae,We){let Me=new Uint8Array(4),fe=r.createTexture();r.bindTexture(z,fe),r.texParameteri(z,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(z,r.TEXTURE_MAG_FILTER,r.NEAREST);for(let $e=0;$e"u"?!1:/OculusBrowser/g.test(navigator.userAgent),c=new ce,h=new WeakMap,u,f=new WeakMap,d=!1;try{d=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function m(L,A){return d?new OffscreenCanvas(L,A):Js("canvas")}function _(L,A,q){let ee=1,de=lt(L);if((de.width>q||de.height>q)&&(ee=q/Math.max(de.width,de.height)),ee<1)if(typeof HTMLImageElement<"u"&&L instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&L instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&L instanceof ImageBitmap||typeof VideoFrame<"u"&&L instanceof VideoFrame){let ie=Math.floor(ee*de.width),He=Math.floor(ee*de.height);u===void 0&&(u=m(ie,He));let Ee=A?m(ie,He):u;return Ee.width=ie,Ee.height=He,Ee.getContext("2d").drawImage(L,0,0,ie,He),console.warn("THREE.WebGLRenderer: Texture has been resized from ("+de.width+"x"+de.height+") to ("+ie+"x"+He+")."),Ee}else return"data"in L&&console.warn("THREE.WebGLRenderer: Image in DataTexture is too big ("+de.width+"x"+de.height+")."),L;return L}function g(L){return L.generateMipmaps}function p(L){r.generateMipmap(L)}function M(L){return L.isWebGLCubeRenderTarget?r.TEXTURE_CUBE_MAP:L.isWebGL3DRenderTarget?r.TEXTURE_3D:L.isWebGLArrayRenderTarget||L.isCompressedArrayTexture?r.TEXTURE_2D_ARRAY:r.TEXTURE_2D}function x(L,A,q,ee,de=!1){if(L!==null){if(r[L]!==void 0)return r[L];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+L+"'")}let ie=A;if(A===r.RED&&(q===r.FLOAT&&(ie=r.R32F),q===r.HALF_FLOAT&&(ie=r.R16F),q===r.UNSIGNED_BYTE&&(ie=r.R8)),A===r.RED_INTEGER&&(q===r.UNSIGNED_BYTE&&(ie=r.R8UI),q===r.UNSIGNED_SHORT&&(ie=r.R16UI),q===r.UNSIGNED_INT&&(ie=r.R32UI),q===r.BYTE&&(ie=r.R8I),q===r.SHORT&&(ie=r.R16I),q===r.INT&&(ie=r.R32I)),A===r.RG&&(q===r.FLOAT&&(ie=r.RG32F),q===r.HALF_FLOAT&&(ie=r.RG16F),q===r.UNSIGNED_BYTE&&(ie=r.RG8)),A===r.RG_INTEGER&&(q===r.UNSIGNED_BYTE&&(ie=r.RG8UI),q===r.UNSIGNED_SHORT&&(ie=r.RG16UI),q===r.UNSIGNED_INT&&(ie=r.RG32UI),q===r.BYTE&&(ie=r.RG8I),q===r.SHORT&&(ie=r.RG16I),q===r.INT&&(ie=r.RG32I)),A===r.RGB_INTEGER&&(q===r.UNSIGNED_BYTE&&(ie=r.RGB8UI),q===r.UNSIGNED_SHORT&&(ie=r.RGB16UI),q===r.UNSIGNED_INT&&(ie=r.RGB32UI),q===r.BYTE&&(ie=r.RGB8I),q===r.SHORT&&(ie=r.RGB16I),q===r.INT&&(ie=r.RGB32I)),A===r.RGBA_INTEGER&&(q===r.UNSIGNED_BYTE&&(ie=r.RGBA8UI),q===r.UNSIGNED_SHORT&&(ie=r.RGBA16UI),q===r.UNSIGNED_INT&&(ie=r.RGBA32UI),q===r.BYTE&&(ie=r.RGBA8I),q===r.SHORT&&(ie=r.RGBA16I),q===r.INT&&(ie=r.RGBA32I)),A===r.RGB&&(q===r.UNSIGNED_INT_5_9_9_9_REV&&(ie=r.RGB9_E5),q===r.UNSIGNED_INT_10F_11F_11F_REV&&(ie=r.R11F_G11F_B10F)),A===r.RGBA){let He=de?Ys:wt.getTransfer(ee);q===r.FLOAT&&(ie=r.RGBA32F),q===r.HALF_FLOAT&&(ie=r.RGBA16F),q===r.UNSIGNED_BYTE&&(ie=He===Ut?r.SRGB8_ALPHA8:r.RGBA8),q===r.UNSIGNED_SHORT_4_4_4_4&&(ie=r.RGBA4),q===r.UNSIGNED_SHORT_5_5_5_1&&(ie=r.RGB5_A1)}return(ie===r.R16F||ie===r.R32F||ie===r.RG16F||ie===r.RG32F||ie===r.RGBA16F||ie===r.RGBA32F)&&e.get("EXT_color_buffer_float"),ie}function y(L,A){let q;return L?A===null||A===Si||A===ds?q=r.DEPTH24_STENCIL8:A===Rn?q=r.DEPTH32F_STENCIL8:A===hs&&(q=r.DEPTH24_STENCIL8,console.warn("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):A===null||A===Si||A===ds?q=r.DEPTH_COMPONENT24:A===Rn?q=r.DEPTH_COMPONENT32F:A===hs&&(q=r.DEPTH_COMPONENT16),q}function E(L,A){return g(L)===!0||L.isFramebufferTexture&&L.minFilter!==un&&L.minFilter!==tn?Math.log2(Math.max(A.width,A.height))+1:L.mipmaps!==void 0&&L.mipmaps.length>0?L.mipmaps.length:L.isCompressedTexture&&Array.isArray(L.image)?A.mipmaps.length:1}function S(L){let A=L.target;A.removeEventListener("dispose",S),P(A),A.isVideoTexture&&h.delete(A)}function R(L){let A=L.target;A.removeEventListener("dispose",R),T(A)}function P(L){let A=n.get(L);if(A.__webglInit===void 0)return;let q=L.source,ee=f.get(q);if(ee){let de=ee[A.__cacheKey];de.usedTimes--,de.usedTimes===0&&w(L),Object.keys(ee).length===0&&f.delete(q)}n.remove(L)}function w(L){let A=n.get(L);r.deleteTexture(A.__webglTexture);let q=L.source,ee=f.get(q);delete ee[A.__cacheKey],o.memory.textures--}function T(L){let A=n.get(L);if(L.depthTexture&&(L.depthTexture.dispose(),n.remove(L.depthTexture)),L.isWebGLCubeRenderTarget)for(let ee=0;ee<6;ee++){if(Array.isArray(A.__webglFramebuffer[ee]))for(let de=0;de=i.maxTextures&&console.warn("THREE.WebGLTextures: Trying to use "+L+" texture units while this GPU supports only "+i.maxTextures),N+=1,L}function Z(L){let A=[];return A.push(L.wrapS),A.push(L.wrapT),A.push(L.wrapR||0),A.push(L.magFilter),A.push(L.minFilter),A.push(L.anisotropy),A.push(L.internalFormat),A.push(L.format),A.push(L.type),A.push(L.generateMipmaps),A.push(L.premultiplyAlpha),A.push(L.flipY),A.push(L.unpackAlignment),A.push(L.colorSpace),A.join()}function K(L,A){let q=n.get(L);if(L.isVideoTexture&&we(L),L.isRenderTargetTexture===!1&&L.isExternalTexture!==!0&&L.version>0&&q.__version!==L.version){let ee=L.image;if(ee===null)console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found.");else if(ee.complete===!1)console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete");else{se(q,L,A);return}}else L.isExternalTexture&&(q.__webglTexture=L.sourceTexture?L.sourceTexture:null);t.bindTexture(r.TEXTURE_2D,q.__webglTexture,r.TEXTURE0+A)}function Q(L,A){let q=n.get(L);if(L.isRenderTargetTexture===!1&&L.version>0&&q.__version!==L.version){se(q,L,A);return}t.bindTexture(r.TEXTURE_2D_ARRAY,q.__webglTexture,r.TEXTURE0+A)}function _e(L,A){let q=n.get(L);if(L.isRenderTargetTexture===!1&&L.version>0&&q.__version!==L.version){se(q,L,A);return}t.bindTexture(r.TEXTURE_3D,q.__webglTexture,r.TEXTURE0+A)}function ne(L,A){let q=n.get(L);if(L.version>0&&q.__version!==L.version){ge(q,L,A);return}t.bindTexture(r.TEXTURE_CUBE_MAP,q.__webglTexture,r.TEXTURE0+A)}let Te={[Ws]:r.REPEAT,[Vn]:r.CLAMP_TO_EDGE,[Xs]:r.MIRRORED_REPEAT},Oe={[un]:r.NEAREST,[Mh]:r.NEAREST_MIPMAP_NEAREST,[us]:r.NEAREST_MIPMAP_LINEAR,[tn]:r.LINEAR,[So]:r.LINEAR_MIPMAP_NEAREST,[ui]:r.LINEAR_MIPMAP_LINEAR},Ge={[Gd]:r.NEVER,[Yd]:r.ALWAYS,[kd]:r.LESS,[Ih]:r.LEQUAL,[Wd]:r.EQUAL,[qd]:r.GEQUAL,[Xd]:r.GREATER,[$d]:r.NOTEQUAL};function dt(L,A){if(A.type===Rn&&e.has("OES_texture_float_linear")===!1&&(A.magFilter===tn||A.magFilter===So||A.magFilter===us||A.magFilter===ui||A.minFilter===tn||A.minFilter===So||A.minFilter===us||A.minFilter===ui)&&console.warn("THREE.WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),r.texParameteri(L,r.TEXTURE_WRAP_S,Te[A.wrapS]),r.texParameteri(L,r.TEXTURE_WRAP_T,Te[A.wrapT]),(L===r.TEXTURE_3D||L===r.TEXTURE_2D_ARRAY)&&r.texParameteri(L,r.TEXTURE_WRAP_R,Te[A.wrapR]),r.texParameteri(L,r.TEXTURE_MAG_FILTER,Oe[A.magFilter]),r.texParameteri(L,r.TEXTURE_MIN_FILTER,Oe[A.minFilter]),A.compareFunction&&(r.texParameteri(L,r.TEXTURE_COMPARE_MODE,r.COMPARE_REF_TO_TEXTURE),r.texParameteri(L,r.TEXTURE_COMPARE_FUNC,Ge[A.compareFunction])),e.has("EXT_texture_filter_anisotropic")===!0){if(A.magFilter===un||A.minFilter!==us&&A.minFilter!==ui||A.type===Rn&&e.has("OES_texture_float_linear")===!1)return;if(A.anisotropy>1||n.get(A).__currentAnisotropy){let q=e.get("EXT_texture_filter_anisotropic");r.texParameterf(L,q.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(A.anisotropy,i.getMaxAnisotropy())),n.get(A).__currentAnisotropy=A.anisotropy}}}function yt(L,A){let q=!1;L.__webglInit===void 0&&(L.__webglInit=!0,A.addEventListener("dispose",S));let ee=A.source,de=f.get(ee);de===void 0&&(de={},f.set(ee,de));let ie=Z(A);if(ie!==L.__cacheKey){de[ie]===void 0&&(de[ie]={texture:r.createTexture(),usedTimes:0},o.memory.textures++,q=!0),de[ie].usedTimes++;let He=de[L.__cacheKey];He!==void 0&&(de[L.__cacheKey].usedTimes--,He.usedTimes===0&&w(A)),L.__cacheKey=ie,L.__webglTexture=de[ie].texture}return q}function Rt(L,A,q){return Math.floor(Math.floor(L/q)/A)}function St(L,A,q,ee){let ie=L.updateRanges;if(ie.length===0)t.texSubImage2D(r.TEXTURE_2D,0,0,0,A.width,A.height,q,ee,A.data);else{ie.sort((ye,Re)=>ye.start-Re.start);let He=0;for(let ye=1;ye0){z&&me&&t.texStorage2D(r.TEXTURE_2D,We,Ie,Ne[0].width,Ne[0].height);for(let Me=0,fe=Ne.length;Me0){let $e=Lh(Pe.width,Pe.height,A.format,A.type);for(let ct of A.layerUpdates){let Nt=Pe.data.subarray(ct*$e/Pe.data.BYTES_PER_ELEMENT,(ct+1)*$e/Pe.data.BYTES_PER_ELEMENT);t.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,Me,0,0,ct,Pe.width,Pe.height,1,Re,Nt)}A.clearLayerUpdates()}else t.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,Me,0,0,0,Pe.width,Pe.height,ye.depth,Re,Pe.data)}else t.compressedTexImage3D(r.TEXTURE_2D_ARRAY,Me,Ie,Pe.width,Pe.height,ye.depth,0,Pe.data,0,0);else console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else z?Ae&&t.texSubImage3D(r.TEXTURE_2D_ARRAY,Me,0,0,0,Pe.width,Pe.height,ye.depth,Re,rt,Pe.data):t.texImage3D(r.TEXTURE_2D_ARRAY,Me,Ie,Pe.width,Pe.height,ye.depth,0,Re,rt,Pe.data)}else{z&&me&&t.texStorage2D(r.TEXTURE_2D,We,Ie,Ne[0].width,Ne[0].height);for(let Me=0,fe=Ne.length;Me0){let Me=Lh(ye.width,ye.height,A.format,A.type);for(let fe of A.layerUpdates){let $e=ye.data.subarray(fe*Me/ye.data.BYTES_PER_ELEMENT,(fe+1)*Me/ye.data.BYTES_PER_ELEMENT);t.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,fe,ye.width,ye.height,1,Re,rt,$e)}A.clearLayerUpdates()}else t.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,0,ye.width,ye.height,ye.depth,Re,rt,ye.data)}else t.texImage3D(r.TEXTURE_2D_ARRAY,0,Ie,ye.width,ye.height,ye.depth,0,Re,rt,ye.data);else if(A.isData3DTexture)z?(me&&t.texStorage3D(r.TEXTURE_3D,We,Ie,ye.width,ye.height,ye.depth),Ae&&t.texSubImage3D(r.TEXTURE_3D,0,0,0,0,ye.width,ye.height,ye.depth,Re,rt,ye.data)):t.texImage3D(r.TEXTURE_3D,0,Ie,ye.width,ye.height,ye.depth,0,Re,rt,ye.data);else if(A.isFramebufferTexture){if(me)if(z)t.texStorage2D(r.TEXTURE_2D,We,Ie,ye.width,ye.height);else{let Me=ye.width,fe=ye.height;for(let $e=0;$e>=1,fe>>=1}}else if(Ne.length>0){if(z&&me){let Me=lt(Ne[0]);t.texStorage2D(r.TEXTURE_2D,We,Ie,Me.width,Me.height)}for(let Me=0,fe=Ne.length;Me0&&We++;let fe=lt(Re[0]);t.texStorage2D(r.TEXTURE_CUBE_MAP,We,Ne,fe.width,fe.height)}for(let fe=0;fe<6;fe++)if(ye){z?Ae&&t.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+fe,0,0,0,Re[fe].width,Re[fe].height,Ie,Pe,Re[fe].data):t.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+fe,0,Ne,Re[fe].width,Re[fe].height,0,Ie,Pe,Re[fe].data);for(let $e=0;$e>ie),rt=Math.max(1,A.height>>ie);de===r.TEXTURE_3D||de===r.TEXTURE_2D_ARRAY?t.texImage3D(de,ie,ke,Re,rt,A.depth,0,He,Ee,null):t.texImage2D(de,ie,ke,Re,rt,0,He,Ee,null)}t.bindFramebuffer(r.FRAMEBUFFER,L),be(A)?a.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,ee,de,ye.__webglTexture,0,ve(A)):(de===r.TEXTURE_2D||de>=r.TEXTURE_CUBE_MAP_POSITIVE_X&&de<=r.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&r.framebufferTexture2D(r.FRAMEBUFFER,ee,de,ye.__webglTexture,ie),t.bindFramebuffer(r.FRAMEBUFFER,null)}function Ke(L,A,q){if(r.bindRenderbuffer(r.RENDERBUFFER,L),A.depthBuffer){let ee=A.depthTexture,de=ee&&ee.isDepthTexture?ee.type:null,ie=y(A.stencilBuffer,de),He=A.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,Ee=ve(A);be(A)?a.renderbufferStorageMultisampleEXT(r.RENDERBUFFER,Ee,ie,A.width,A.height):q?r.renderbufferStorageMultisample(r.RENDERBUFFER,Ee,ie,A.width,A.height):r.renderbufferStorage(r.RENDERBUFFER,ie,A.width,A.height),r.framebufferRenderbuffer(r.FRAMEBUFFER,He,r.RENDERBUFFER,L)}else{let ee=A.textures;for(let de=0;de{delete A.__boundDepthTexture,delete A.__depthDisposeCallback,ee.removeEventListener("dispose",de)};ee.addEventListener("dispose",de),A.__depthDisposeCallback=de}A.__boundDepthTexture=ee}if(L.depthTexture&&!A.__autoAllocateDepthBuffer){if(q)throw new Error("target.depthTexture not supported in Cube render targets");let ee=L.texture.mipmaps;ee&&ee.length>0?Ze(A.__webglFramebuffer[0],L):Ze(A.__webglFramebuffer,L)}else if(q){A.__webglDepthbuffer=[];for(let ee=0;ee<6;ee++)if(t.bindFramebuffer(r.FRAMEBUFFER,A.__webglFramebuffer[ee]),A.__webglDepthbuffer[ee]===void 0)A.__webglDepthbuffer[ee]=r.createRenderbuffer(),Ke(A.__webglDepthbuffer[ee],L,!1);else{let de=L.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,ie=A.__webglDepthbuffer[ee];r.bindRenderbuffer(r.RENDERBUFFER,ie),r.framebufferRenderbuffer(r.FRAMEBUFFER,de,r.RENDERBUFFER,ie)}}else{let ee=L.texture.mipmaps;if(ee&&ee.length>0?t.bindFramebuffer(r.FRAMEBUFFER,A.__webglFramebuffer[0]):t.bindFramebuffer(r.FRAMEBUFFER,A.__webglFramebuffer),A.__webglDepthbuffer===void 0)A.__webglDepthbuffer=r.createRenderbuffer(),Ke(A.__webglDepthbuffer,L,!1);else{let de=L.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,ie=A.__webglDepthbuffer;r.bindRenderbuffer(r.RENDERBUFFER,ie),r.framebufferRenderbuffer(r.FRAMEBUFFER,de,r.RENDERBUFFER,ie)}}t.bindFramebuffer(r.FRAMEBUFFER,null)}function Bt(L,A,q){let ee=n.get(L);A!==void 0&&Ve(ee.__webglFramebuffer,L,L.texture,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,0),q!==void 0&&xt(L)}function O(L){let A=L.texture,q=n.get(L),ee=n.get(A);L.addEventListener("dispose",R);let de=L.textures,ie=L.isWebGLCubeRenderTarget===!0,He=de.length>1;if(He||(ee.__webglTexture===void 0&&(ee.__webglTexture=r.createTexture()),ee.__version=A.version,o.memory.textures++),ie){q.__webglFramebuffer=[];for(let Ee=0;Ee<6;Ee++)if(A.mipmaps&&A.mipmaps.length>0){q.__webglFramebuffer[Ee]=[];for(let ke=0;ke0){q.__webglFramebuffer=[];for(let Ee=0;Ee0&&be(L)===!1){q.__webglMultisampledFramebuffer=r.createFramebuffer(),q.__webglColorRenderbuffer=[],t.bindFramebuffer(r.FRAMEBUFFER,q.__webglMultisampledFramebuffer);for(let Ee=0;Ee0)for(let ke=0;ke0)for(let ke=0;ke0){if(be(L)===!1){let A=L.textures,q=L.width,ee=L.height,de=r.COLOR_BUFFER_BIT,ie=L.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,He=n.get(L),Ee=A.length>1;if(Ee)for(let Je=0;Je0?t.bindFramebuffer(r.DRAW_FRAMEBUFFER,He.__webglFramebuffer[0]):t.bindFramebuffer(r.DRAW_FRAMEBUFFER,He.__webglFramebuffer);for(let Je=0;Je0&&e.has("WEBGL_multisampled_render_to_texture")===!0&&A.__useRenderToTexture!==!1}function we(L){let A=o.render.frame;h.get(L)!==A&&(h.set(L,A),L.update())}function ft(L,A){let q=L.colorSpace,ee=L.format,de=L.type;return L.isCompressedTexture===!0||L.isVideoTexture===!0||q!==ur&&q!==wi&&(wt.getTransfer(q)===Ut?(ee!==_n||de!==jn)&&console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):console.error("THREE.WebGLTextures: Unsupported texture color space:",q)),A}function lt(L){return typeof HTMLImageElement<"u"&&L instanceof HTMLImageElement?(c.width=L.naturalWidth||L.width,c.height=L.naturalHeight||L.height):typeof VideoFrame<"u"&&L instanceof VideoFrame?(c.width=L.displayWidth,c.height=L.displayHeight):(c.width=L.width,c.height=L.height),c}this.allocateTextureUnit=G,this.resetTextureUnits=V,this.setTexture2D=K,this.setTexture2DArray=Q,this.setTexture3D=_e,this.setTextureCube=ne,this.rebindTextures=Bt,this.setupRenderTarget=O,this.updateRenderTargetMipmap=pe,this.updateMultisampleRenderTarget=ae,this.setupDepthRenderbuffer=xt,this.setupFrameBufferTexture=Ve,this.useMultisampledRTT=be}function R0(r,e){function t(n,i=wi){let s,o=wt.getTransfer(i);if(n===jn)return r.UNSIGNED_BYTE;if(n===Rl)return r.UNSIGNED_SHORT_4_4_4_4;if(n===Cl)return r.UNSIGNED_SHORT_5_5_5_1;if(n===wh)return r.UNSIGNED_INT_5_9_9_9_REV;if(n===Th)return r.UNSIGNED_INT_10F_11F_11F_REV;if(n===Eh)return r.BYTE;if(n===Sh)return r.SHORT;if(n===hs)return r.UNSIGNED_SHORT;if(n===Al)return r.INT;if(n===Si)return r.UNSIGNED_INT;if(n===Rn)return r.FLOAT;if(n===fs)return r.HALF_FLOAT;if(n===Ah)return r.ALPHA;if(n===Rh)return r.RGB;if(n===_n)return r.RGBA;if(n===kr)return r.DEPTH_COMPONENT;if(n===ps)return r.DEPTH_STENCIL;if(n===Pl)return r.RED;if(n===wo)return r.RED_INTEGER;if(n===Ch)return r.RG;if(n===Il)return r.RG_INTEGER;if(n===Dl)return r.RGBA_INTEGER;if(n===To||n===Ao||n===Ro||n===Co)if(o===Ut)if(s=e.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(n===To)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(n===Ao)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(n===Ro)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(n===Co)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=e.get("WEBGL_compressed_texture_s3tc"),s!==null){if(n===To)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(n===Ao)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(n===Ro)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(n===Co)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(n===Ll||n===Ul||n===Nl||n===Fl)if(s=e.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(n===Ll)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(n===Ul)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(n===Nl)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(n===Fl)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(n===Ol||n===Bl||n===zl)if(s=e.get("WEBGL_compressed_texture_etc"),s!==null){if(n===Ol||n===Bl)return o===Ut?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(n===zl)return o===Ut?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC}else return null;if(n===Vl||n===Hl||n===Gl||n===kl||n===Wl||n===Xl||n===$l||n===ql||n===Yl||n===Zl||n===Jl||n===jl||n===Kl||n===Ql)if(s=e.get("WEBGL_compressed_texture_astc"),s!==null){if(n===Vl)return o===Ut?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(n===Hl)return o===Ut?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(n===Gl)return o===Ut?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(n===kl)return o===Ut?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(n===Wl)return o===Ut?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(n===Xl)return o===Ut?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(n===$l)return o===Ut?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(n===ql)return o===Ut?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(n===Yl)return o===Ut?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(n===Zl)return o===Ut?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(n===Jl)return o===Ut?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(n===jl)return o===Ut?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(n===Kl)return o===Ut?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(n===Ql)return o===Ut?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(n===ec||n===tc||n===nc)if(s=e.get("EXT_texture_compression_bptc"),s!==null){if(n===ec)return o===Ut?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(n===tc)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(n===nc)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(n===ic||n===rc||n===sc||n===oc)if(s=e.get("EXT_texture_compression_rgtc"),s!==null){if(n===ic)return s.COMPRESSED_RED_RGTC1_EXT;if(n===rc)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(n===sc)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(n===oc)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return n===ds?r.UNSIGNED_INT_24_8:r[n]!==void 0?r[n]:null}return{convert:t}}var Cw=` void main() { gl_Position = vec4( position, 1.0 ); }`,Pw=` 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; } }`,_p=class{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t){if(this.texture===null){let n=new so(e.texture);(e.depthNear!==t.depthNear||e.depthFar!==t.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=n}}getMesh(e){if(this.texture!==null&&this.mesh===null){let t=e.cameras[0].viewport,n=new Fn({vertexShader:Cw,fragmentShader:Pw,uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new Xt(new Xi(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}},yp=class extends kn{constructor(e,t){super();let n=this,i=null,s=1,o=null,a="local-floor",l=1,c=null,h=null,u=null,f=null,d=null,m=null,_=typeof XRWebGLBinding<"u",g=new _p,p={},M=t.getContextAttributes(),x=null,y=null,E=[],S=[],R=new ce,P=null,w=new en;w.viewport=new At;let T=new en;T.viewport=new At;let N=[w,T],V=new pl,G=null,Z=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(se){let ge=E[se];return ge===void 0&&(ge=new Jr,E[se]=ge),ge.getTargetRaySpace()},this.getControllerGrip=function(se){let ge=E[se];return ge===void 0&&(ge=new Jr,E[se]=ge),ge.getGripSpace()},this.getHand=function(se){let ge=E[se];return ge===void 0&&(ge=new Jr,E[se]=ge),ge.getHandSpace()};function K(se){let ge=S.indexOf(se.inputSource);if(ge===-1)return;let Ve=E[ge];Ve!==void 0&&(Ve.update(se.inputSource,se.frame,c||o),Ve.dispatchEvent({type:se.type,data:se.inputSource}))}function Q(){i.removeEventListener("select",K),i.removeEventListener("selectstart",K),i.removeEventListener("selectend",K),i.removeEventListener("squeeze",K),i.removeEventListener("squeezestart",K),i.removeEventListener("squeezeend",K),i.removeEventListener("end",Q),i.removeEventListener("inputsourceschange",_e);for(let se=0;se=0&&(S[Ke]=null,E[Ke].disconnect(Ve))}for(let ge=0;ge=S.length){S.push(Ve),Ke=xt;break}else if(S[xt]===null){S[xt]=Ve,Ke=xt;break}if(Ke===-1)break}let Ze=E[Ke];Ze&&Ze.connect(Ve)}}let ne=new C,Te=new C;function Oe(se,ge,Ve){ne.setFromMatrixPosition(ge.matrixWorld),Te.setFromMatrixPosition(Ve.matrixWorld);let Ke=ne.distanceTo(Te),Ze=ge.projectionMatrix.elements,xt=Ve.projectionMatrix.elements,Bt=Ze[14]/(Ze[10]-1),O=Ze[14]/(Ze[10]+1),pe=(Ze[9]+1)/Ze[5],he=(Ze[9]-1)/Ze[5],oe=(Ze[8]-1)/Ze[0],ae=(xt[8]+1)/xt[0],ve=Bt*oe,be=Bt*ae,we=Ke/(-oe+ae),ft=we*-oe;if(ge.matrixWorld.decompose(se.position,se.quaternion,se.scale),se.translateX(ft),se.translateZ(we),se.matrixWorld.compose(se.position,se.quaternion,se.scale),se.matrixWorldInverse.copy(se.matrixWorld).invert(),Ze[10]===-1)se.projectionMatrix.copy(ge.projectionMatrix),se.projectionMatrixInverse.copy(ge.projectionMatrixInverse);else{let lt=Bt+we,L=O+we,A=ve-ft,q=be+(Ke-ft),ee=pe*O/L*lt,de=he*O/L*lt;se.projectionMatrix.makePerspective(A,q,ee,de,lt,L),se.projectionMatrixInverse.copy(se.projectionMatrix).invert()}}function Ge(se,ge){ge===null?se.matrixWorld.copy(se.matrix):se.matrixWorld.multiplyMatrices(ge.matrixWorld,se.matrix),se.matrixWorldInverse.copy(se.matrixWorld).invert()}this.updateCamera=function(se){if(i===null)return;let ge=se.near,Ve=se.far;g.texture!==null&&(g.depthNear>0&&(ge=g.depthNear),g.depthFar>0&&(Ve=g.depthFar)),V.near=T.near=w.near=ge,V.far=T.far=w.far=Ve,(G!==V.near||Z!==V.far)&&(i.updateRenderState({depthNear:V.near,depthFar:V.far}),G=V.near,Z=V.far),V.layers.mask=se.layers.mask|6,w.layers.mask=V.layers.mask&3,T.layers.mask=V.layers.mask&5;let Ke=se.parent,Ze=V.cameras;Ge(V,Ke);for(let xt=0;xt0&&(g.alphaTest.value=p.alphaTest);let M=e.get(p),x=M.envMap,y=M.envMapRotation;x&&(g.envMap.value=x,_s.copy(y),_s.x*=-1,_s.y*=-1,_s.z*=-1,x.isCubeTexture&&x.isRenderTargetTexture===!1&&(_s.y*=-1,_s.z*=-1),g.envMapRotation.value.setFromMatrix4(Iw.makeRotationFromEuler(_s)),g.flipEnvMap.value=x.isCubeTexture&&x.isRenderTargetTexture===!1?-1:1,g.reflectivity.value=p.reflectivity,g.ior.value=p.ior,g.refractionRatio.value=p.refractionRatio),p.lightMap&&(g.lightMap.value=p.lightMap,g.lightMapIntensity.value=p.lightMapIntensity,t(p.lightMap,g.lightMapTransform)),p.aoMap&&(g.aoMap.value=p.aoMap,g.aoMapIntensity.value=p.aoMapIntensity,t(p.aoMap,g.aoMapTransform))}function o(g,p){g.diffuse.value.copy(p.color),g.opacity.value=p.opacity,p.map&&(g.map.value=p.map,t(p.map,g.mapTransform))}function a(g,p){g.dashSize.value=p.dashSize,g.totalSize.value=p.dashSize+p.gapSize,g.scale.value=p.scale}function l(g,p,M,x){g.diffuse.value.copy(p.color),g.opacity.value=p.opacity,g.size.value=p.size*M,g.scale.value=x*.5,p.map&&(g.map.value=p.map,t(p.map,g.uvTransform)),p.alphaMap&&(g.alphaMap.value=p.alphaMap,t(p.alphaMap,g.alphaMapTransform)),p.alphaTest>0&&(g.alphaTest.value=p.alphaTest)}function c(g,p){g.diffuse.value.copy(p.color),g.opacity.value=p.opacity,g.rotation.value=p.rotation,p.map&&(g.map.value=p.map,t(p.map,g.mapTransform)),p.alphaMap&&(g.alphaMap.value=p.alphaMap,t(p.alphaMap,g.alphaMapTransform)),p.alphaTest>0&&(g.alphaTest.value=p.alphaTest)}function h(g,p){g.specular.value.copy(p.specular),g.shininess.value=Math.max(p.shininess,1e-4)}function u(g,p){p.gradientMap&&(g.gradientMap.value=p.gradientMap)}function f(g,p){g.metalness.value=p.metalness,p.metalnessMap&&(g.metalnessMap.value=p.metalnessMap,t(p.metalnessMap,g.metalnessMapTransform)),g.roughness.value=p.roughness,p.roughnessMap&&(g.roughnessMap.value=p.roughnessMap,t(p.roughnessMap,g.roughnessMapTransform)),p.envMap&&(g.envMapIntensity.value=p.envMapIntensity)}function d(g,p,M){g.ior.value=p.ior,p.sheen>0&&(g.sheenColor.value.copy(p.sheenColor).multiplyScalar(p.sheen),g.sheenRoughness.value=p.sheenRoughness,p.sheenColorMap&&(g.sheenColorMap.value=p.sheenColorMap,t(p.sheenColorMap,g.sheenColorMapTransform)),p.sheenRoughnessMap&&(g.sheenRoughnessMap.value=p.sheenRoughnessMap,t(p.sheenRoughnessMap,g.sheenRoughnessMapTransform))),p.clearcoat>0&&(g.clearcoat.value=p.clearcoat,g.clearcoatRoughness.value=p.clearcoatRoughness,p.clearcoatMap&&(g.clearcoatMap.value=p.clearcoatMap,t(p.clearcoatMap,g.clearcoatMapTransform)),p.clearcoatRoughnessMap&&(g.clearcoatRoughnessMap.value=p.clearcoatRoughnessMap,t(p.clearcoatRoughnessMap,g.clearcoatRoughnessMapTransform)),p.clearcoatNormalMap&&(g.clearcoatNormalMap.value=p.clearcoatNormalMap,t(p.clearcoatNormalMap,g.clearcoatNormalMapTransform),g.clearcoatNormalScale.value.copy(p.clearcoatNormalScale),p.side===xn&&g.clearcoatNormalScale.value.negate())),p.dispersion>0&&(g.dispersion.value=p.dispersion),p.iridescence>0&&(g.iridescence.value=p.iridescence,g.iridescenceIOR.value=p.iridescenceIOR,g.iridescenceThicknessMinimum.value=p.iridescenceThicknessRange[0],g.iridescenceThicknessMaximum.value=p.iridescenceThicknessRange[1],p.iridescenceMap&&(g.iridescenceMap.value=p.iridescenceMap,t(p.iridescenceMap,g.iridescenceMapTransform)),p.iridescenceThicknessMap&&(g.iridescenceThicknessMap.value=p.iridescenceThicknessMap,t(p.iridescenceThicknessMap,g.iridescenceThicknessMapTransform))),p.transmission>0&&(g.transmission.value=p.transmission,g.transmissionSamplerMap.value=M.texture,g.transmissionSamplerSize.value.set(M.width,M.height),p.transmissionMap&&(g.transmissionMap.value=p.transmissionMap,t(p.transmissionMap,g.transmissionMapTransform)),g.thickness.value=p.thickness,p.thicknessMap&&(g.thicknessMap.value=p.thicknessMap,t(p.thicknessMap,g.thicknessMapTransform)),g.attenuationDistance.value=p.attenuationDistance,g.attenuationColor.value.copy(p.attenuationColor)),p.anisotropy>0&&(g.anisotropyVector.value.set(p.anisotropy*Math.cos(p.anisotropyRotation),p.anisotropy*Math.sin(p.anisotropyRotation)),p.anisotropyMap&&(g.anisotropyMap.value=p.anisotropyMap,t(p.anisotropyMap,g.anisotropyMapTransform))),g.specularIntensity.value=p.specularIntensity,g.specularColor.value.copy(p.specularColor),p.specularColorMap&&(g.specularColorMap.value=p.specularColorMap,t(p.specularColorMap,g.specularColorMapTransform)),p.specularIntensityMap&&(g.specularIntensityMap.value=p.specularIntensityMap,t(p.specularIntensityMap,g.specularIntensityMapTransform))}function m(g,p){p.matcap&&(g.matcap.value=p.matcap)}function _(g,p){let M=e.get(p).light;g.referencePosition.value.setFromMatrixPosition(M.matrixWorld),g.nearDistance.value=M.shadow.camera.near,g.farDistance.value=M.shadow.camera.far}return{refreshFogUniforms:n,refreshMaterialUniforms:i}}function Lw(r,e,t,n){let i={},s={},o=[],a=r.getParameter(r.MAX_UNIFORM_BUFFER_BINDINGS);function l(M,x){let y=x.program;n.uniformBlockBinding(M,y)}function c(M,x){let y=i[M.id];y===void 0&&(m(M),y=h(M),i[M.id]=y,M.addEventListener("dispose",g));let E=x.program;n.updateUBOMapping(M,E);let S=e.render.frame;s[M.id]!==S&&(f(M),s[M.id]=S)}function h(M){let x=u();M.__bindingPointIndex=x;let y=r.createBuffer(),E=M.__size,S=M.usage;return r.bindBuffer(r.UNIFORM_BUFFER,y),r.bufferData(r.UNIFORM_BUFFER,E,S),r.bindBuffer(r.UNIFORM_BUFFER,null),r.bindBufferBase(r.UNIFORM_BUFFER,x,y),y}function u(){for(let M=0;M0&&(y+=E-S),M.__size=y,M.__cache={},this}function _(M){let x={boundary:0,storage:0};return typeof M=="number"||typeof M=="boolean"?(x.boundary=4,x.storage=4):M.isVector2?(x.boundary=8,x.storage=8):M.isVector3||M.isColor?(x.boundary=16,x.storage=12):M.isVector4?(x.boundary=16,x.storage=16):M.isMatrix3?(x.boundary=48,x.storage=48):M.isMatrix4?(x.boundary=64,x.storage=64):M.isTexture?console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group."):console.warn("THREE.WebGLRenderer: Unsupported uniform value type.",M),x}function g(M){let x=M.target;x.removeEventListener("dispose",g);let y=o.indexOf(x.__bindingPointIndex);o.splice(y,1),r.deleteBuffer(i[x.id]),delete i[x.id],delete s[x.id]}function p(){for(let M in i)r.deleteBuffer(i[M]);o=[],i={},s={}}return{bind:l,update:c,dispose:p}}var xp=class{constructor(e={}){let{canvas:t=jd(),context:n=null,depth:i=!0,stencil:s=!1,alpha:o=!1,antialias:a=!1,premultipliedAlpha:l=!0,preserveDrawingBuffer:c=!1,powerPreference:h="default",failIfMajorPerformanceCaveat:u=!1,reversedDepthBuffer:f=!1}=e;this.isWebGLRenderer=!0;let d;if(n!==null){if(typeof WebGLRenderingContext<"u"&&n instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");d=n.getContextAttributes().alpha}else d=o;let m=new Uint32Array(4),_=new Int32Array(4),g=null,p=null,M=[],x=[];this.domElement=t,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.toneMapping=Mi,this.toneMappingExposure=1,this.transmissionResolutionScale=1;let y=this,E=!1;this._outputColorSpace=wn;let S=0,R=0,P=null,w=-1,T=null,N=new At,V=new At,G=null,Z=new Be(0),K=0,Q=t.width,_e=t.height,ne=1,Te=null,Oe=null,Ge=new At(0,0,Q,_e),dt=new At(0,0,Q,_e),yt=!1,Rt=new Gi,St=!1,se=!1,ge=new Qe,Ve=new C,Ke=new At,Ze={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0},xt=!1;function Bt(){return P===null?ne:1}let O=n;function pe(I,k){return t.getContext(I,k)}try{let I={alpha:!0,depth:i,stencil:s,antialias:a,premultipliedAlpha:l,preserveDrawingBuffer:c,powerPreference:h,failIfMajorPerformanceCaveat:u};if("setAttribute"in t&&t.setAttribute("data-engine",`three.js r${"180"}`),t.addEventListener("webglcontextlost",Ae,!1),t.addEventListener("webglcontextrestored",We,!1),t.addEventListener("webglcontextcreationerror",Me,!1),O===null){let k="webgl2";if(O=pe(k,I),O===null)throw pe(k)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}}catch(I){throw console.error("THREE.WebGLRenderer: "+I.message),I}let he,oe,ae,ve,be,we,ft,lt,L,A,q,ee,de,ie,He,Ee,ke,Je,ye,Re,rt,Ie,Pe,Ne;function z(){he=new KE(O),he.init(),Ie=new R0(O,he),oe=new XE(O,he,e,Ie),ae=new Aw(O,he),oe.reversedDepthBuffer&&f&&ae.buffers.depth.setReversed(!0),ve=new tS(O),be=new pw,we=new Rw(O,he,ae,be,oe,Ie,ve),ft=new qE(y),lt=new jE(y),L=new ab(O),Pe=new kE(O,L),A=new QE(O,L,ve,Pe),q=new iS(O,A,L,ve),ye=new nS(O,oe,we),Ee=new $E(be),ee=new dw(y,ft,lt,he,oe,Pe,Ee),de=new Dw(y,be),ie=new gw,He=new Mw(he),Je=new GE(y,ft,lt,ae,q,d,l),ke=new ww(y,q,oe),Ne=new Lw(O,ve,oe,ae),Re=new WE(O,he,ve),rt=new eS(O,he,ve),ve.programs=ee.programs,y.capabilities=oe,y.extensions=he,y.properties=be,y.renderLists=ie,y.shadowMap=ke,y.state=ae,y.info=ve}z();let me=new yp(y,O);this.xr=me,this.getContext=function(){return O},this.getContextAttributes=function(){return O.getContextAttributes()},this.forceContextLoss=function(){let I=he.get("WEBGL_lose_context");I&&I.loseContext()},this.forceContextRestore=function(){let I=he.get("WEBGL_lose_context");I&&I.restoreContext()},this.getPixelRatio=function(){return ne},this.setPixelRatio=function(I){I!==void 0&&(ne=I,this.setSize(Q,_e,!1))},this.getSize=function(I){return I.set(Q,_e)},this.setSize=function(I,k,J=!0){if(me.isPresenting){console.warn("THREE.WebGLRenderer: Can't change size while VR device is presenting.");return}Q=I,_e=k,t.width=Math.floor(I*ne),t.height=Math.floor(k*ne),J===!0&&(t.style.width=I+"px",t.style.height=k+"px"),this.setViewport(0,0,I,k)},this.getDrawingBufferSize=function(I){return I.set(Q*ne,_e*ne).floor()},this.setDrawingBufferSize=function(I,k,J){Q=I,_e=k,ne=J,t.width=Math.floor(I*J),t.height=Math.floor(k*J),this.setViewport(0,0,I,k)},this.getCurrentViewport=function(I){return I.copy(N)},this.getViewport=function(I){return I.copy(Ge)},this.setViewport=function(I,k,J,j){I.isVector4?Ge.set(I.x,I.y,I.z,I.w):Ge.set(I,k,J,j),ae.viewport(N.copy(Ge).multiplyScalar(ne).round())},this.getScissor=function(I){return I.copy(dt)},this.setScissor=function(I,k,J,j){I.isVector4?dt.set(I.x,I.y,I.z,I.w):dt.set(I,k,J,j),ae.scissor(V.copy(dt).multiplyScalar(ne).round())},this.getScissorTest=function(){return yt},this.setScissorTest=function(I){ae.setScissorTest(yt=I)},this.setOpaqueSort=function(I){Te=I},this.setTransparentSort=function(I){Oe=I},this.getClearColor=function(I){return I.copy(Je.getClearColor())},this.setClearColor=function(){Je.setClearColor(...arguments)},this.getClearAlpha=function(){return Je.getClearAlpha()},this.setClearAlpha=function(){Je.setClearAlpha(...arguments)},this.clear=function(I=!0,k=!0,J=!0){let j=0;if(I){let $=!1;if(P!==null){let Se=P.texture.format;$=Se===Dl||Se===Il||Se===wo}if($){let Se=P.texture.type,Le=Se===jn||Se===Si||Se===hs||Se===ds||Se===Rl||Se===Cl,qe=Je.getClearColor(),ze=Je.getClearAlpha(),it=qe.r,st=qe.g,je=qe.b;Le?(m[0]=it,m[1]=st,m[2]=je,m[3]=ze,O.clearBufferuiv(O.COLOR,0,m)):(_[0]=it,_[1]=st,_[2]=je,_[3]=ze,O.clearBufferiv(O.COLOR,0,_))}else j|=O.COLOR_BUFFER_BIT}k&&(j|=O.DEPTH_BUFFER_BIT),J&&(j|=O.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),O.clear(j)},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(){t.removeEventListener("webglcontextlost",Ae,!1),t.removeEventListener("webglcontextrestored",We,!1),t.removeEventListener("webglcontextcreationerror",Me,!1),Je.dispose(),ie.dispose(),He.dispose(),be.dispose(),ft.dispose(),lt.dispose(),q.dispose(),Pe.dispose(),Ne.dispose(),ee.dispose(),me.dispose(),me.removeEventListener("sessionstart",dn),me.removeEventListener("sessionend",br),Ti.stop()};function Ae(I){I.preventDefault(),console.log("THREE.WebGLRenderer: Context Lost."),E=!0}function We(){console.log("THREE.WebGLRenderer: Context Restored."),E=!1;let I=ve.autoReset,k=ke.enabled,J=ke.autoUpdate,j=ke.needsUpdate,$=ke.type;z(),ve.autoReset=I,ke.enabled=k,ke.autoUpdate=J,ke.needsUpdate=j,ke.type=$}function Me(I){console.error("THREE.WebGLRenderer: A WebGL context could not be created. Reason: ",I.statusMessage)}function fe(I){let k=I.target;k.removeEventListener("dispose",fe),$e(k)}function $e(I){ct(I),be.remove(I)}function ct(I){let k=be.get(I).programs;k!==void 0&&(k.forEach(function(J){ee.releaseProgram(J)}),I.isShaderMaterial&&ee.releaseShaderCache(I))}this.renderBufferDirect=function(I,k,J,j,$,Se){k===null&&(k=Ze);let Le=$.isMesh&&$.matrixWorld.determinant()<0,qe=jh(I,k,J,j,$);ae.setMaterial(j,Le);let ze=J.index,it=1;if(j.wireframe===!0){if(ze=A.getWireframeAttribute(J),ze===void 0)return;it=2}let st=J.drawRange,je=J.attributes.position,vt=st.start*it,It=(st.start+st.count)*it;Se!==null&&(vt=Math.max(vt,Se.start*it),It=Math.min(It,(Se.start+Se.count)*it)),ze!==null?(vt=Math.max(vt,0),It=Math.min(It,ze.count)):je!=null&&(vt=Math.max(vt,0),It=Math.min(It,je.count));let Tt=It-vt;if(Tt<0||Tt===1/0)return;Pe.setup($,j,qe,J,ze);let zt,Dt=Re;if(ze!==null&&(zt=L.get(ze),Dt=rt,Dt.setIndex(zt)),$.isMesh)j.wireframe===!0?(ae.setLineWidth(j.wireframeLinewidth*Bt()),Dt.setMode(O.LINES)):Dt.setMode(O.TRIANGLES);else if($.isLine){let tt=j.linewidth;tt===void 0&&(tt=1),ae.setLineWidth(tt*Bt()),$.isLineSegments?Dt.setMode(O.LINES):$.isLineLoop?Dt.setMode(O.LINE_LOOP):Dt.setMode(O.LINE_STRIP)}else $.isPoints?Dt.setMode(O.POINTS):$.isSprite&&Dt.setMode(O.TRIANGLES);if($.isBatchedMesh)if($._multiDrawInstances!==null)js("THREE.WebGLRenderer: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection."),Dt.renderMultiDrawInstances($._multiDrawStarts,$._multiDrawCounts,$._multiDrawCount,$._multiDrawInstances);else if(he.get("WEBGL_multi_draw"))Dt.renderMultiDraw($._multiDrawStarts,$._multiDrawCounts,$._multiDrawCount);else{let tt=$._multiDrawStarts,Ht=$._multiDrawCounts,Mt=$._multiDrawCount,bn=ze?L.get(ze).bytesPerElement:1,Ji=be.get(j).currentProgram.getUniforms();for(let Mn=0;Mn{function Se(){if(j.forEach(function(Le){be.get(Le).currentProgram.isReady()&&j.delete(Le)}),j.size===0){$(I);return}setTimeout(Se,10)}he.get("KHR_parallel_shader_compile")!==null?Se():setTimeout(Se,10)})};let Pt=null;function qn(I){Pt&&Pt(I)}function dn(){Ti.stop()}function br(){Ti.start()}let Ti=new E0;Ti.setAnimationLoop(qn),typeof self<"u"&&Ti.setContext(self),this.setAnimationLoop=function(I){Pt=I,me.setAnimationLoop(I),I===null?Ti.stop():Ti.start()},me.addEventListener("sessionstart",dn),me.addEventListener("sessionend",br),this.render=function(I,k){if(k!==void 0&&k.isCamera!==!0){console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(E===!0)return;if(I.matrixWorldAutoUpdate===!0&&I.updateMatrixWorld(),k.parent===null&&k.matrixWorldAutoUpdate===!0&&k.updateMatrixWorld(),me.enabled===!0&&me.isPresenting===!0&&(me.cameraAutoUpdate===!0&&me.updateCamera(k),k=me.getCamera()),I.isScene===!0&&I.onBeforeRender(y,I,k,P),p=He.get(I,x.length),p.init(k),x.push(p),ge.multiplyMatrices(k.projectionMatrix,k.matrixWorldInverse),Rt.setFromProjectionMatrix(ge,Nn,k.reversedDepth),se=this.localClippingEnabled,St=Ee.init(this.clippingPlanes,se),g=ie.get(I,M.length),g.init(),M.push(g),me.enabled===!0&&me.isPresenting===!0){let Se=y.xr.getDepthSensingMesh();Se!==null&&bs(Se,k,-1/0,y.sortObjects)}bs(I,k,0,y.sortObjects),g.finish(),y.sortObjects===!0&&g.sort(Te,Oe),xt=me.enabled===!1||me.isPresenting===!1||me.hasDepthSensing()===!1,xt&&Je.addToRenderList(g,I),this.info.render.frame++,St===!0&&Ee.beginShadows();let J=p.state.shadowsArray;ke.render(J,I,k),St===!0&&Ee.endShadows(),this.info.autoReset===!0&&this.info.reset();let j=g.opaque,$=g.transmissive;if(p.setupLights(),k.isArrayCamera){let Se=k.cameras;if($.length>0)for(let Le=0,qe=Se.length;Le0&&Mr(j,$,I,k),xt&&Je.render(I),xc(g,I,k);P!==null&&R===0&&(we.updateMultisampleRenderTarget(P),we.updateRenderTargetMipmap(P)),I.isScene===!0&&I.onAfterRender(y,I,k),Pe.resetDefaultState(),w=-1,T=null,x.pop(),x.length>0?(p=x[x.length-1],St===!0&&Ee.setGlobalState(y.clippingPlanes,p.state.camera)):p=null,M.pop(),M.length>0?g=M[M.length-1]:g=null};function bs(I,k,J,j){if(I.visible===!1)return;if(I.layers.test(k.layers)){if(I.isGroup)J=I.renderOrder;else if(I.isLOD)I.autoUpdate===!0&&I.update(k);else if(I.isLight)p.pushLight(I),I.castShadow&&p.pushShadow(I);else if(I.isSprite){if(!I.frustumCulled||Rt.intersectsSprite(I)){j&&Ke.setFromMatrixPosition(I.matrixWorld).applyMatrix4(ge);let Le=q.update(I),qe=I.material;qe.visible&&g.push(I,Le,qe,J,Ke.z,null)}}else if((I.isMesh||I.isLine||I.isPoints)&&(!I.frustumCulled||Rt.intersectsObject(I))){let Le=q.update(I),qe=I.material;if(j&&(I.boundingSphere!==void 0?(I.boundingSphere===null&&I.computeBoundingSphere(),Ke.copy(I.boundingSphere.center)):(Le.boundingSphere===null&&Le.computeBoundingSphere(),Ke.copy(Le.boundingSphere.center)),Ke.applyMatrix4(I.matrixWorld).applyMatrix4(ge)),Array.isArray(qe)){let ze=Le.groups;for(let it=0,st=ze.length;it0&&Ai($,k,J),Se.length>0&&Ai(Se,k,J),Le.length>0&&Ai(Le,k,J),ae.buffers.depth.setTest(!0),ae.buffers.depth.setMask(!0),ae.buffers.color.setMask(!0),ae.setPolygonOffset(!1)}function Mr(I,k,J,j){if((J.isScene===!0?J.overrideMaterial:null)!==null)return;p.state.transmissionRenderTarget[j.id]===void 0&&(p.state.transmissionRenderTarget[j.id]=new Wn(1,1,{generateMipmaps:!0,type:he.has("EXT_color_buffer_half_float")||he.has("EXT_color_buffer_float")?fs:jn,minFilter:ui,samples:4,stencilBuffer:s,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:wt.workingColorSpace}));let Se=p.state.transmissionRenderTarget[j.id],Le=j.viewport||N;Se.setSize(Le.z*y.transmissionResolutionScale,Le.w*y.transmissionResolutionScale);let qe=y.getRenderTarget(),ze=y.getActiveCubeFace(),it=y.getActiveMipmapLevel();y.setRenderTarget(Se),y.getClearColor(Z),K=y.getClearAlpha(),K<1&&y.setClearColor(16777215,.5),y.clear(),xt&&Je.render(J);let st=y.toneMapping;y.toneMapping=Mi;let je=j.viewport;if(j.viewport!==void 0&&(j.viewport=void 0),p.setupLightsView(j),St===!0&&Ee.setGlobalState(y.clippingPlanes,j),Ai(I,J,j),we.updateMultisampleRenderTarget(Se),we.updateRenderTargetMipmap(Se),he.has("WEBGL_multisampled_render_to_texture")===!1){let vt=!1;for(let It=0,Tt=k.length;It0),je=!!J.morphAttributes.position,vt=!!J.morphAttributes.normal,It=!!J.morphAttributes.color,Tt=Mi;j.toneMapped&&(P===null||P.isXRRenderTarget===!0)&&(Tt=y.toneMapping);let zt=J.morphAttributes.position||J.morphAttributes.normal||J.morphAttributes.color,Dt=zt!==void 0?zt.length:0,tt=be.get(j),Ht=p.state.lights;if(St===!0&&(se===!0||I!==T)){let ln=I===T&&j.id===w;Ee.setState(j,I,ln)}let Mt=!1;j.version===tt.__version?(tt.needsLights&&tt.lightsStateVersion!==Ht.state.version||tt.outputColorSpace!==qe||$.isBatchedMesh&&tt.batching===!1||!$.isBatchedMesh&&tt.batching===!0||$.isBatchedMesh&&tt.batchingColor===!0&&$.colorTexture===null||$.isBatchedMesh&&tt.batchingColor===!1&&$.colorTexture!==null||$.isInstancedMesh&&tt.instancing===!1||!$.isInstancedMesh&&tt.instancing===!0||$.isSkinnedMesh&&tt.skinning===!1||!$.isSkinnedMesh&&tt.skinning===!0||$.isInstancedMesh&&tt.instancingColor===!0&&$.instanceColor===null||$.isInstancedMesh&&tt.instancingColor===!1&&$.instanceColor!==null||$.isInstancedMesh&&tt.instancingMorph===!0&&$.morphTexture===null||$.isInstancedMesh&&tt.instancingMorph===!1&&$.morphTexture!==null||tt.envMap!==ze||j.fog===!0&&tt.fog!==Se||tt.numClippingPlanes!==void 0&&(tt.numClippingPlanes!==Ee.numPlanes||tt.numIntersection!==Ee.numIntersection)||tt.vertexAlphas!==it||tt.vertexTangents!==st||tt.morphTargets!==je||tt.morphNormals!==vt||tt.morphColors!==It||tt.toneMapping!==Tt||tt.morphTargetsCount!==Dt)&&(Mt=!0):(Mt=!0,tt.__version=j.version);let bn=tt.currentProgram;Mt===!0&&(bn=Er(j,k,$));let Ji=!1,Mn=!1,Ri=!1,Gt=bn.getUniforms(),En=tt.uniforms;if(ae.useProgram(bn.program)&&(Ji=!0,Mn=!0,Ri=!0),j.id!==w&&(w=j.id,Mn=!0),Ji||T!==I){ae.buffers.depth.getReversed()&&I.reversedDepth!==!0&&(I._reversedDepth=!0,I.updateProjectionMatrix()),Gt.setValue(O,"projectionMatrix",I.projectionMatrix),Gt.setValue(O,"viewMatrix",I.matrixWorldInverse);let Yt=Gt.map.cameraPosition;Yt!==void 0&&Yt.setValue(O,Ve.setFromMatrixPosition(I.matrixWorld)),oe.logarithmicDepthBuffer&&Gt.setValue(O,"logDepthBufFC",2/(Math.log(I.far+1)/Math.LN2)),(j.isMeshPhongMaterial||j.isMeshToonMaterial||j.isMeshLambertMaterial||j.isMeshBasicMaterial||j.isMeshStandardMaterial||j.isShaderMaterial)&&Gt.setValue(O,"isOrthographic",I.isOrthographicCamera===!0),T!==I&&(T=I,Mn=!0,Ri=!0)}if($.isSkinnedMesh){Gt.setOptional(O,$,"bindMatrix"),Gt.setOptional(O,$,"bindMatrixInverse");let ln=$.skeleton;ln&&(ln.boneTexture===null&&ln.computeBoneTexture(),Gt.setValue(O,"boneTexture",ln.boneTexture,we))}$.isBatchedMesh&&(Gt.setOptional(O,$,"batchingTexture"),Gt.setValue(O,"batchingTexture",$._matricesTexture,we),Gt.setOptional(O,$,"batchingIdTexture"),Gt.setValue(O,"batchingIdTexture",$._indirectTexture,we),Gt.setOptional(O,$,"batchingColorTexture"),$._colorsTexture!==null&&Gt.setValue(O,"batchingColorTexture",$._colorsTexture,we));let Dn=J.morphAttributes;if((Dn.position!==void 0||Dn.normal!==void 0||Dn.color!==void 0)&&ye.update($,J,bn),(Mn||tt.receiveShadow!==$.receiveShadow)&&(tt.receiveShadow=$.receiveShadow,Gt.setValue(O,"receiveShadow",$.receiveShadow)),j.isMeshGouraudMaterial&&j.envMap!==null&&(En.envMap.value=ze,En.flipEnvMap.value=ze.isCubeTexture&&ze.isRenderTargetTexture===!1?-1:1),j.isMeshStandardMaterial&&j.envMap===null&&k.environment!==null&&(En.envMapIntensity.value=k.environmentIntensity),Mn&&(Gt.setValue(O,"toneMappingExposure",y.toneMappingExposure),tt.needsLights&&Kh(En,Ri),Se&&j.fog===!0&&de.refreshFogUniforms(En,Se),de.refreshMaterialUniforms(En,j,ne,_e,p.state.transmissionRenderTarget[I.id]),Do.upload(O,Zi(tt),En,we)),j.isShaderMaterial&&j.uniformsNeedUpdate===!0&&(Do.upload(O,Zi(tt),En,we),j.uniformsNeedUpdate=!1),j.isSpriteMaterial&&Gt.setValue(O,"center",$.center),Gt.setValue(O,"modelViewMatrix",$.modelViewMatrix),Gt.setValue(O,"normalMatrix",$.normalMatrix),Gt.setValue(O,"modelMatrix",$.matrixWorld),j.isShaderMaterial||j.isRawShaderMaterial){let ln=j.uniformsGroups;for(let Yt=0,Sr=ln.length;Yt0&&we.useMultisampledRTT(I)===!1?$=be.get(I).__webglMultisampledFramebuffer:Array.isArray(st)?$=st[J]:$=st,N.copy(I.viewport),V.copy(I.scissor),G=I.scissorTest}else N.copy(Ge).multiplyScalar(ne).floor(),V.copy(dt).multiplyScalar(ne).floor(),G=yt;if(J!==0&&($=Go),ae.bindFramebuffer(O.FRAMEBUFFER,$)&&j&&ae.drawBuffers(I,$),ae.viewport(N),ae.scissor(V),ae.setScissorTest(G),Se){let ze=be.get(I.texture);O.framebufferTexture2D(O.FRAMEBUFFER,O.COLOR_ATTACHMENT0,O.TEXTURE_CUBE_MAP_POSITIVE_X+k,ze.__webglTexture,J)}else if(Le){let ze=k;for(let it=0;it=0&&k<=I.width-j&&J>=0&&J<=I.height-$&&(I.textures.length>1&&O.readBuffer(O.COLOR_ATTACHMENT0+qe),O.readPixels(k,J,j,$,Ie.convert(st),Ie.convert(je),Se))}finally{let it=P!==null?be.get(P).__webglFramebuffer:null;ae.bindFramebuffer(O.FRAMEBUFFER,it)}}},this.readRenderTargetPixelsAsync=async function(I,k,J,j,$,Se,Le,qe=0){if(!(I&&I.isWebGLRenderTarget))throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let ze=be.get(I).__webglFramebuffer;if(I.isWebGLCubeRenderTarget&&Le!==void 0&&(ze=ze[Le]),ze)if(k>=0&&k<=I.width-j&&J>=0&&J<=I.height-$){ae.bindFramebuffer(O.FRAMEBUFFER,ze);let it=I.textures[qe],st=it.format,je=it.type;if(!oe.textureFormatReadable(st))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!oe.textureTypeReadable(je))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");let vt=O.createBuffer();O.bindBuffer(O.PIXEL_PACK_BUFFER,vt),O.bufferData(O.PIXEL_PACK_BUFFER,Se.byteLength,O.STREAM_READ),I.textures.length>1&&O.readBuffer(O.COLOR_ATTACHMENT0+qe),O.readPixels(k,J,j,$,Ie.convert(st),Ie.convert(je),0);let It=P!==null?be.get(P).__webglFramebuffer:null;ae.bindFramebuffer(O.FRAMEBUFFER,It);let Tt=O.fenceSync(O.SYNC_GPU_COMMANDS_COMPLETE,0);return O.flush(),await Wg(O,Tt,4),O.bindBuffer(O.PIXEL_PACK_BUFFER,vt),O.getBufferSubData(O.PIXEL_PACK_BUFFER,0,Se),O.deleteBuffer(vt),O.deleteSync(Tt),Se}else throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")},this.copyFramebufferToTexture=function(I,k=null,J=0){let j=Math.pow(2,-J),$=Math.floor(I.image.width*j),Se=Math.floor(I.image.height*j),Le=k!==null?k.x:0,qe=k!==null?k.y:0;we.setTexture2D(I,0),O.copyTexSubImage2D(O.TEXTURE_2D,J,0,0,Le,qe,$,Se),ae.unbindTexture()};let ko=O.createFramebuffer(),ef=O.createFramebuffer();this.copyTextureToTexture=function(I,k,J=null,j=null,$=0,Se=null){Se===null&&($!==0?(js("WebGLRenderer: copyTextureToTexture function signature has changed to support src and dst mipmap levels."),Se=$,$=0):Se=0);let Le,qe,ze,it,st,je,vt,It,Tt,zt=I.isCompressedTexture?I.mipmaps[Se]:I.image;if(J!==null)Le=J.max.x-J.min.x,qe=J.max.y-J.min.y,ze=J.isBox3?J.max.z-J.min.z:1,it=J.min.x,st=J.min.y,je=J.isBox3?J.min.z:0;else{let Dn=Math.pow(2,-$);Le=Math.floor(zt.width*Dn),qe=Math.floor(zt.height*Dn),I.isDataArrayTexture?ze=zt.depth:I.isData3DTexture?ze=Math.floor(zt.depth*Dn):ze=1,it=0,st=0,je=0}j!==null?(vt=j.x,It=j.y,Tt=j.z):(vt=0,It=0,Tt=0);let Dt=Ie.convert(k.format),tt=Ie.convert(k.type),Ht;k.isData3DTexture?(we.setTexture3D(k,0),Ht=O.TEXTURE_3D):k.isDataArrayTexture||k.isCompressedArrayTexture?(we.setTexture2DArray(k,0),Ht=O.TEXTURE_2D_ARRAY):(we.setTexture2D(k,0),Ht=O.TEXTURE_2D),O.pixelStorei(O.UNPACK_FLIP_Y_WEBGL,k.flipY),O.pixelStorei(O.UNPACK_PREMULTIPLY_ALPHA_WEBGL,k.premultiplyAlpha),O.pixelStorei(O.UNPACK_ALIGNMENT,k.unpackAlignment);let Mt=O.getParameter(O.UNPACK_ROW_LENGTH),bn=O.getParameter(O.UNPACK_IMAGE_HEIGHT),Ji=O.getParameter(O.UNPACK_SKIP_PIXELS),Mn=O.getParameter(O.UNPACK_SKIP_ROWS),Ri=O.getParameter(O.UNPACK_SKIP_IMAGES);O.pixelStorei(O.UNPACK_ROW_LENGTH,zt.width),O.pixelStorei(O.UNPACK_IMAGE_HEIGHT,zt.height),O.pixelStorei(O.UNPACK_SKIP_PIXELS,it),O.pixelStorei(O.UNPACK_SKIP_ROWS,st),O.pixelStorei(O.UNPACK_SKIP_IMAGES,je);let Gt=I.isDataArrayTexture||I.isData3DTexture,En=k.isDataArrayTexture||k.isData3DTexture;if(I.isDepthTexture){let Dn=be.get(I),ln=be.get(k),Yt=be.get(Dn.__renderTarget),Sr=be.get(ln.__renderTarget);ae.bindFramebuffer(O.READ_FRAMEBUFFER,Yt.__webglFramebuffer),ae.bindFramebuffer(O.DRAW_FRAMEBUFFER,Sr.__webglFramebuffer);for(let Ft=0;FtYi.primitiveSegments)throw new RangeError(`${r} must be an integer from ${t} to ${Yi.primitiveSegments}.`)}function Bh(r,e,t){if((e+1)*(t+1)>Yi.primitiveGridVertices)throw new RangeError(`${r} exceeds ${Yi.primitiveGridVertices} grid vertices; reduce segment counts.`)}function bp(r,e){if(!Number.isSafeInteger(e)||e<1||e>Yi.repeatedMeshes)throw new RangeError(`${r} count must be an integer from 1 to ${Yi.repeatedMeshes}, including the source. Split large repetitions into intentional bounded groups.`)}function In(r,e){if(!Array.isArray(e)||e.length!==3||!e.every(Number.isFinite))throw new RangeError(`${r} must contain three finite numbers.`)}var C0=/^[a-z][a-z0-9_]*$/,Uo="vertex_colour",Uw=/^#[0-9a-f]{6}$/i,P0=["box","convex","mesh","none"],I0=["box","sphere","capsule","cylinder"],zh=class{constructor(e){this.key=e;Object.freeze(this)}key;isSlot=!0;toString(){return`slot('${this.key}')`}},uc=class{constructor(e){this.hex=e;Object.freeze(this)}hex;isColor=!0;toString(){return`color('${this.hex}')`}};function L0(r){let e=Number.parseInt(r.slice(1),16);return[e>>16&255,e>>8&255,e&255].map(t=>{let n=t/255,i=n<=.04045?n/12.92:((n+.055)/1.055)**2.4;return Math.round(i*1e6)/1e6})}var Mp=null;function Ep(){Mp={proxies:[],slots:new Map,placeholder:new Xn}}function hc(){return Mp||Ep(),Mp}function Sp(){return hc().proxies}function Vh(r){return r.userData.helixPart}function wp(r){return r.userData.helixProxy}function U0(r){if(typeof r!="string"||!C0.test(r))throw new Error(`slot(${JSON.stringify(r)}): slot keys are lowercase snake_case matching ${C0}, e.g. slot('painted_wood').`);if(r===Uo)throw new Error(`slot('${Uo}') is reserved for color() parts: pass color('#rrggbb') instead.`);let e=hc().slots,t=e.get(r);return t||(t=new zh(r),e.set(r,t)),t}function N0(r){if(typeof r!="string"||!Uw.test(r))throw new Error(`color(${JSON.stringify(r)}): colours are six-digit sRGB hex strings, e.g. color('#c8553d').`);return new uc(r.toLowerCase())}var F0="Model programs never create materials: a part binds a Palette material through a named slot or takes a flat colour, e.g. createPart('Seat', boxGeo(1, 0.1, 1), slot('wood'), { parent: root }) or createPart('Seat', boxGeo(1, 0.1, 1), color('#8a5a3b'), { parent: root }).";function No(r){return()=>{throw new Error(`${r}() is not available. ${F0}`)}}function fc(r,e,t){if(t.position!==void 0&&(In(`${e} position`,t.position),r.position.set(...t.position)),t.rotation!==void 0){In(`${e} rotation (degrees)`,t.rotation);let[n,i,s]=t.rotation.map(sn.degToRad);r.rotation.set(n,i,s,"XYZ")}if(t.scale!==void 0){if(In(`${e} scale`,t.scale),t.scale.some(n=>n===0))throw new RangeError(`${e} scale components must be non-zero.`);r.scale.set(...t.scale)}}function Hh(r,e){if(e!==void 0&&e?.isObject3D!==!0)throw new TypeError(`${r}: options.parent must be the root, a group or a part (got ${e===null?"null":typeof e}).`)}function dc(r,e,t){if(typeof e!="object"||e===null||Array.isArray(e))throw new TypeError(`${r}: options must be an object.`);let n=Object.keys(e).filter(i=>!t.includes(i));if(n.length)throw new TypeError(`${r}: unknown option(s) ${n.join(", ")}; allowed: ${t.join(", ")}.`)}function O0(r){if(typeof r!="string"||!r)throw new TypeError("createRoot(name): name must be a non-empty string.");let e=new bt;return e.name=r,e.userData.helixRoot=!0,e}function B0(r,e={}){if(typeof r!="string"||!r)throw new TypeError("createGroup(name, options): name must be a non-empty string.");dc(`createGroup("${r}")`,e,["position","rotation","scale","parent"]),Hh(`createGroup("${r}")`,e.parent);let t=new bt;return t.name=r,fc(t,`createGroup("${r}")`,e),e.parent?.add(t),t}var D0="Signature: createPart(name, geometry, slot('key') | color('#rrggbb'), { position, rotation, scale, parent, collision, walkable })";function z0(r,e,t,n={}){if(typeof r!="string"||!r){let a=r?.isObject3D?"an Object3D (put the parent in options as { parent })":typeof r;throw new TypeError(`createPart: the first argument is the part NAME, a string, but got ${a}. ${D0}.`)}if(e?.isBufferGeometry!==!0){let a=typeof e=="function"?"a function -- call the helper: boxGeo(1, 1, 1), not boxGeo":e instanceof Promise?"a Promise -- booleans, roundedBoxGeo, extrudeProfile and revolveProfile are async: await them inside async build()":e?.isMesh?"a part -- pass its geometry (part.geometry) or a new geometry":e===null?"null":typeof e;throw new TypeError(`createPart("${r}"): the second argument must be a geometry, but got ${a}. ${D0}.`)}if(!(t instanceof zh)&&!(t instanceof uc))throw new TypeError(`createPart("${r}"): the third argument must be slot('key') or color('#rrggbb'). ${F0}`);dc(`createPart("${r}")`,n,["position","rotation","scale","parent","collision","walkable"]),Hh(`createPart("${r}")`,n.parent);let i=n.collision??"none";if(!P0.includes(i))throw new RangeError(`createPart("${r}"): collision must be one of ${P0.join(", ")}.`);if(n.walkable!==void 0&&typeof n.walkable!="boolean")throw new TypeError(`createPart("${r}"): walkable must be true or false.`);let s=new Xt(e,hc().placeholder);s.name=r;let o=t instanceof uc?{name:r,slot:Uo,color:t.hex,collision:i}:{name:r,slot:t.key,collision:i};return n.walkable!==void 0&&(o.walkable=n.walkable),s.userData.helixPart=o,fc(s,`createPart("${r}")`,n),n.parent?.add(s),s}function Fo(r,e,t={}){if(e?.isObject3D!==!0)throw new TypeError(`createInstance("${r}"): source must be a part or group.`);dc(`createInstance("${r}")`,t,["position","rotation","scale","parent"]),Hh(`createInstance("${r}")`,t.parent);let n=e.clone(!0);return n.name=r,Vh(n)&&(n.userData.helixPart={...Vh(n),name:r}),fc(n,`createInstance("${r}")`,t),t.parent?.add(n),n}function V0(r,e={}){if(!I0.includes(r))throw new RangeError(`collisionProxy: kind must be one of ${I0.join(", ")} (got ${String(r)}).`);dc(`collisionProxy('${r}')`,e,["center","size","radius","height","rotation","walkable","parent"]),Hh(`collisionProxy('${r}')`,e.parent);let t=(s,o)=>{if(typeof o!="number"||!Number.isFinite(o)||o<=0)throw new RangeError(`collisionProxy('${r}'): ${s} must be a positive number.`);return o},n={kind:r};if(r==="box"){if(!Array.isArray(e.size))throw new TypeError("collisionProxy('box'): size [x, y, z] is required.");n.size=e.size.map((s,o)=>t(`size[${o}]`,s))}else if(n.radius=t("radius",e.radius),r!=="sphere"&&(n.height=t("height",e.height),r==="capsule"&&n.height<2*n.radius))throw new RangeError("collisionProxy('capsule'): height must be at least 2 * radius.");e.walkable!==void 0&&(n.walkable=!!e.walkable);let i=new bt;return i.name=`proxy_${r}_${hc().proxies.length}`,i.userData.helixProxy=n,fc(i,`collisionProxy('${r}')`,{position:e.center,rotation:e.rotation}),e.parent?.add(i),hc().proxies.push(i),i}function H0(r,e){if(r?.isBufferGeometry!==!0)throw new TypeError("transformGeo: first argument must be a geometry.");dc("transformGeo",e??{},["position","rotation","scale"]);let t=new bt;fc(t,"transformGeo",e??{}),t.updateMatrix();let n=r.clone().applyMatrix4(t.matrix);return t.matrix.determinant()<0&&Tp(n),n}function Tp(r){if(r.index){let e=r.index;for(let t=0;t+2>>=0;let t=()=>{e=e+1831565813>>>0;let n=e;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296};return Object.assign(t,{range:(n,i)=>n+(i-n)*t(),int:(n,i)=>Math.floor(n+(i-n+1)*t()),pick:n=>n[Math.floor(t()*n.length)]})}var Nw={TUBE_RADIUS:"curveToMesh and pipeAlongPath require an explicit positive finite radius in metres (half the tube diameter).",TAPER_CONE_AXIS:'taperConeGeo(radiusBottom, radiusTop, height, axis, segments): the fourth argument is the axis "x", "y" or "z"; segments is the fifth.',SOLID_FLOAT32_COLLAPSE:"Solid output cannot keep valid faces at Float32 precision. Simplify sub-millimetre features or review coincident cut boundaries.",MESH_DATA_NONFINITE:"meshGeo positions, normals and UVs must be finite numbers. Check missing components, undefined values and division by zero.",GEAR_RADII_ORDER:"gearGeo requires boreRadius < rootRadius < tipRadius; set rootRadius when changing tipRadius.",ROUNDED_BOX_RADIUS:"roundedBoxGeo: radius must be less than half the smallest dimension.",PARAMETRIC_PERIODIC_ENDPOINT:"Periodic parametricSurface endpoints must return matching positions: sample(uMin, v) must equal sample(uMax, v) for periodicU.",PROFILE_HOLES_UNSUPPORTED:"loftProfiles and sweepProfile do not support holes. Use extrudeProfile for a holed cross-section, or cut with boolDiff.",PROFILE_BEVEL_COLLAPSE:"extrudeProfile or revolveProfile: the bevel is too large for this profile. Reduce it below half the narrowest section width.",PROFILE_CORRESPONDENCE_COLLAPSE:"loftProfiles or sweepProfile: corresponding profile edges collapse between stations. Check matching start vertices and vertex order."},Jt=class extends Error{constructor(t,n=Nw[t]){super(n);this.diagnostic=t;this.name="AuthoringDiagnosticError"}diagnostic};function pc(r,e,t=6){return $t("capsuleGeo radius",r),$t("capsuleGeo height (straight middle length)",e,!0),Kn("capsuleGeo segments",t,3),new ki(r,e,2,t)}function k0(r,e,t=6){return pc(r,e,t).rotateZ(-Math.PI/2)}function W0(r,e,t=6){return pc(r,e,t).rotateX(Math.PI/2)}function vs(r,e,t,n=8){if($t("cylinderGeo radiusTop",r,!0),$t("cylinderGeo radiusBottom",e,!0),r===0&&e===0)throw new RangeError("cylinderGeo requires at least one positive radius.");return $t("cylinderGeo height",t),Kn("cylinderGeo segments",n,3),new _i(r,e,t,n)}function X0(r,e,t,n=8){return vs(r,e,t,n).rotateZ(-Math.PI/2)}function $0(r,e,t,n=8){return vs(r,e,t,n).rotateX(Math.PI/2)}function q0(r,e,t){for(let[n,i]of Object.entries({width:r,height:e,depth:t}))$t(`boxGeo ${n} (use planeGeo for a sheet)`,i);return new Zn(r,e,t)}function Y0(r,e=8,t=6){return $t("sphereGeo radius",r),Kn("sphereGeo widthSegments",e,3),Kn("sphereGeo heightSegments",t,2),Bh("sphereGeo",e,t),new yi(r,e,t)}function mc(r,e,t=8){return $t("coneGeo radius",r),$t("coneGeo height",e),Kn("coneGeo segments",t,3),new dr(r,e,t)}function Z0(r,e,t=8){return mc(r,e,t).rotateZ(-Math.PI/2)}function J0(r,e,t=8){return mc(r,e,t).rotateX(Math.PI/2)}function j0(r,e,t,n,i={}){In("cylinderOnAxis center",r),In("cylinderOnAxis normal",e);let s=Math.max(...e.map(Math.abs));if(!(s>1e-9))throw new Error(`cylinderOnAxis: normal must be a non-zero vector (got [${e.join(",")}]).`);let o=new C(e[0]/s,e[1]/s,e[2]/s).normalize(),a=vs(i.radiusTop??t,t,n,i.segments??8);return a.applyQuaternion(new Vt().setFromUnitVectors(new C(0,1,0),o)),a.translate(r[0],r[1],r[2])}function K0(r,e,t,n="y",i=8){if(!["x","y","z"].includes(n))throw new Jt("TAPER_CONE_AXIS");let s=vs(e,r,t,i);return n==="x"?s.rotateZ(-Math.PI/2):n==="z"&&s.rotateX(Math.PI/2),s}function Q0(r,e,t=8,n=12){return $t("torusGeo radius",r),$t("torusGeo tube",e),Kn("torusGeo radialSegments",t,3),Kn("torusGeo tubularSegments",n,3),Bh("torusGeo",t,n),new ss(r,e,t,n)}function e_(r,e,t=1,n=1){return $t("planeGeo width",r),$t("planeGeo height",e),Kn("planeGeo widthSegments",t,1),Kn("planeGeo heightSegments",n,1),Bh("planeGeo",t,n),new Xi(r,e,t,n)}function t_(r={}){let e=r.span??1,t=r.rootChord??.6,n=r.tipChord??t*.5,i=r.sweep??0,s=r.thickness??.04,o=r.dihedral??0;for(let[g,p]of Object.entries({span:e,rootChord:t,thickness:s}))$t(`wingGeo ${g}`,p);$t("wingGeo tipChord",n,!0);for(let[g,p]of Object.entries({sweep:i,dihedral:o}))if(!Number.isFinite(p)||!Number.isFinite(Math.fround(p)))throw new RangeError(`wingGeo ${g} must be finite and Float32-representable.`);let a=t/2,l=-t/2,c=a-i,h=c-n,u=s/2,f=new Float32Array([a,u,0,l,u,0,c,o+u,e,h,o+u,e,a,-u,0,l,-u,0,c,o-u,e,h,o-u,e]);if(!f.every(Number.isFinite))throw new RangeError("wingGeo dimensions and offsets produce nonfinite Float32 vertices.");let d=[0,3,2,0,1,3,4,6,7,4,7,5,0,2,6,0,6,4,1,5,7,1,7,3,0,4,5,0,5,1,2,3,7,2,7,6],m=new et;m.setAttribute("position",new ht(f,3)),m.setIndex(n===0?[0,1,3,4,7,5,0,2,6,0,6,4,1,5,7,1,7,3,0,4,5,0,5,1]:d);let _=m.toNonIndexed();return _.computeVertexNormals(),_}function n_(r){return r.clone()}function i_(r){let e=n=>Math.floor((n.index?n.index.count:n.getAttribute("position")?.count??0)/3);if(r.isBufferGeometry)return e(r);let t=0;return r.traverse(n=>{n.isMesh&&(t+=e(n.geometry))}),t}function Ap(r,e=1e-4){e=Math.max(e,Number.EPSILON);let t={},n=r.getIndex(),i=r.getAttribute("position"),s=n?n.count:i.count,o=0,a=Object.keys(r.attributes),l={},c={},h=[],u=["getX","getY","getZ","getW"],f=["setX","setY","setZ","setW"];for(let M=0,x=a.length;M{let w=new R.array.constructor(R.count*R.itemSize);c[y][P]=new R.constructor(w,R.itemSize,R.normalized)}))}let d=e*.5,m=Math.log10(1/e),_=Math.pow(10,m),g=d*_;for(let M=0;MMath.abs(u-l.elements[f])>1e-8*Math.max(1,Math.abs(u))))throw new RangeError(`mirror("${r}"): local shear cannot be represented by a reflected TRS.`);let c=Fo(r,e);return c.position.copy(s),c.quaternion.copy(o),c.scale.copy(a),(n??e.parent)?.add(c),c}function l_(r,e={}){let{tolerance:t=1e-4,positionOnly:n=!1}=typeof e=="number"?{tolerance:e}:e;if(!n)return Ap(r,t);let i=r.getAttribute("position");if(!i)return r;let s=new et;return s.setAttribute("position",new ht(new Float32Array(i.array),i.itemSize,i.normalized)),r.index&&s.setIndex(new ht(new Uint32Array(r.index.array),1)),Ap(s,t)}function c_(r){try{$t("Tube radius",r)}catch{throw new Jt("TUBE_RADIUS")}}function Rp(r,e,t=32,n=8,i=!1){if(c_(e),!Array.isArray(r)||r.length<2)throw new Error("curveToMesh: need at least 2 points.");r.forEach((o,a)=>In(`curveToMesh point ${a}`,o));let s=new es(r.map(o=>new C(o[0],o[1],o[2])),i);return new os(s,t,e,n,i)}function Bw(r){let e=r.getAttribute("normal");if(!e)return r;for(let t=0;t1e-6&&e.setXYZ(t,n/o,i/o,s/o)}return e.needsUpdate=!0,r}function zw(r){let e=r.index,t=r.getAttribute("position");if(!e)return;let n=(s,o)=>t.getX(s)===t.getX(o)&&t.getY(s)===t.getY(o)&&t.getZ(s)===t.getZ(o),i=[];for(let s=0;s+2!Array.isArray(a)||!Number.isFinite(a[0])||!Number.isFinite(a[1])))throw new Error("revolveGeo/lathe: every profile point must be a finite [radius, height] pair.");let s=Bw(new rs(r.map(a=>new ce(a[0],a[1])),i,0,t));zw(s);let o=new C(n[0],n[1],n[2]);if(o.lengthSq()<1e-12)throw new Error(`revolveGeo: axis must be a non-zero vector (got [${n.join(",")}]).`);return o.normalize(),(o.x!==0||o.y!==1||o.z!==0)&&s.applyQuaternion(new Vt().setFromUnitVectors(new C(0,1,0),o)),s}function h_(r,e,t={}){let{bendRadius:n=0,closed:i=!1,tubularSegments:s=32,radialSegments:o=8}=t;if(c_(e),!Array.isArray(r)||r.length<2)throw new Error(`pipeAlongPath: need at least 2 points (got ${r?.length}).`);let a=r;if(n>0&&r.length>=3){let l=[r[0]];for(let c=1;cnew C(i[0],i[1],i[2])),n;if(t.length===3)n=new pr(t[0],t[1],t[2]);else if(t.length===4)n=new ts(t[0],t[1],t[2],t[3]);else throw new Error(`bezierCurve: need 3 or 4 control points, got ${t.length}`);return n.getPoints(e).map(i=>[i.x,i.y,i.z])}function Pp(r,e,t){let n=Array.from(r);if(t!==void 0&&n.length!==t)throw new Error(`${e}: expected ${t} values, got ${n.length}`);if(!n.every(i=>Number.isFinite(Math.fround(i))))throw new Jt("MESH_DATA_NONFINITE",`${e}: all values must be finite Float32 values`);return n}function gc(r){let e=Pp(r.positions,"meshGeo positions");if(e.length<9||e.length%3)throw new Error("meshGeo positions: need at least three xyz vertices");let t=e.length/3,n=new et;if(n.setAttribute("position",new De(e,3)),r.indices){let i=Array.from(r.indices);if(!i.length||i.length%3)throw new Error("meshGeo indices: need complete triangles");if(!i.every(s=>Number.isInteger(s)&&s>=0&&sNumber.MAX_SAFE_INTEGER)throw new Error("Geometry tolerance is too small to resolve the position extent safely");return e}function g_(r,e,t){return t===0?r.toArray().join(","):r.clone().sub(e).toArray().map(n=>Math.round(n/t)).join(",")}function Gh(r,e){let t=r.getAttribute("position");if(t?.itemSize!==3)throw new Error("geometryDiagnostics requires xyz positions");let n=p_(t),i=m_(n.scale,e,1e-6),s={tolerance:i,vertices:t.count,triangles:0,boundaryEdges:0,nonManifoldEdges:0,orientationConflicts:0,degenerateTriangles:0,collapsedByToleranceTriangles:0,invalidIndices:0,nonFiniteVertices:0},o=[],a=new Map,l=[],c=new C;for(let _=0;_g),u=new Map,f=new C,d=new C,m=new C;for(let _=0;_!Number.isInteger(E)||E<0||E>=t.count)){s.invalidIndices++;continue}let[p,M,x]=g;if(!l[p]||!l[M]||!l[x])continue;f.fromBufferAttribute(t,p),d.fromBufferAttribute(t,M),m.fromBufferAttribute(t,x);let y=n.scale||1;if(d.sub(f).divideScalar(y),m.sub(f).divideScalar(y),d.cross(m).length()<=(i/y)**2&&s.degenerateTriangles++,o[p]===o[M]||o[M]===o[x]||o[x]===o[p]){s.collapsedByToleranceTriangles++;continue}for(let[E,S]of[[p,M],[M,x],[x,p]]){let R=o[E],P=o[S],w=R2?s.nonManifoldEdges++:_.direction!==0&&s.orientationConflicts++;return s}function __(r,e={}){let{u:t=[0,1],v:n=[0,1],uSegments:i=24,vSegments:s=24,periodicU:o=!1,periodicV:a=!1,orientation:l="uv"}=e;for(let[y,E]of[["uSegments",i],["vSegments",s]])if(!Number.isSafeInteger(E)||E<1)throw new Error(`parametricSurface ${y} must be a positive integer`);let c=(i+1)*(s+1);if(!Number.isSafeInteger(c)||c>Yi.parametricSamples)throw new RangeError(`parametricSurface sample budget exceeded: requested ${c}, limit ${Yi.parametricSamples}.`);for(let[y,E]of[["u",t],["v",n]])if(E.length!==2||!E.every(Number.isFinite)||E[0]===E[1]||!Number.isFinite(E[1]-E[0]))throw new Error(`parametricSurface ${y} must be a finite nonzero domain`);if(l!=="uv"&&l!=="vu")throw new Error("parametricSurface orientation must be uv or vu");let h=[],u=[],f=[],d=new Ct,m=new C;for(let y=0;y<=s;y++)for(let E=0;E<=i;E++){let S=r(t[0]+(t[1]-t[0])*E/i,n[0]+(n[1]-n[0])*y/s);if(!S||S.length!==3||!S.every(Number.isFinite))throw new Error(`parametricSurface: sample (${E},${y}) must return three finite coordinates`);h.push(...S),d.expandByPoint(m.set(...S)),u.push(E/i,y/s)}let _=Array.from({length:(i+1)*(s+1)},(y,E)=>E),g=d_(d),p=y=>{for(;_[y]!==y;)y=_[y];return y},M=(y,E)=>{let S=h.slice(y*3,y*3+3),R=h.slice(E*3,E*3+3);if(Math.hypot(...S.map((P,w)=>P-R[w]))>g*1e-6)throw new Jt("PARAMETRIC_PERIODIC_ENDPOINT");_[p(E)]=p(y);for(let P=0;P<3;P++)h[E*3+P]=h[y*3+P]};if(o)for(let y=0;y<=s;y++)M(y*(i+1),y*(i+1)+i);if(a)for(let y=0;y<=i;y++)M(y,s*(i+1)+y);for(let y=0;y180)throw new Error("creaseNormals angle must be between 0 and 180 degrees");let n=r.index?r.toNonIndexed():r.clone(),i=n.getAttribute("position");if(i?.itemSize!==3||i.count%3!==0)throw new Error("creaseNormals requires complete xyz triangles");let s=p_(i),o=m_(s.scale,e.tolerance,1e-8),a=s.scale||1,l=new Map,c=[],h=[];for(let d=0;d=f-1e-12&&_.add(h[g]);_.normalize().toArray(u,d*3)}return n.setAttribute("normal",new ht(u,3)),n.computeBoundingBox(),n.computeBoundingSphere(),n}function y_(r,e){let t=r.getAttribute("position"),n=r.getAttribute("normal"),i=e.getAttribute("position"),s=y=>{let E=new Ct().setFromBufferAttribute(y);return{center:E.getCenter(new C),size:E.getSize(new C).length()||1}},o=s(t),a=s(i),l=new C,c=new C,h=(y,E,S)=>(l.fromBufferAttribute(y,E).sub(S.center).divideScalar(S.size),l.toArray().map(R=>Math.round(R*1e7)).join(",")),u=new Map,f=new Uint32Array(i.count);for(let y=0;yMath.round(R*1e6)).join(",")}:${h(i,y,a)}`);let S=u.get(E);S===void 0&&(S=u.size,u.set(E,S)),f[y]=S}let d=new Float64Array(u.size*3),m=e.index,_=m?.count??i.count,g=new C,p=new C,M=new C;for(let y=0;y<_;y+=3){let E=m?m.getX(y):y,S=m?m.getX(y+1):y+1,R=m?m.getX(y+2):y+2;g.fromBufferAttribute(i,E),p.fromBufferAttribute(i,S).sub(g).divideScalar(a.size),M.fromBufferAttribute(i,R).sub(g).divideScalar(a.size),c.crossVectors(p,M);for(let P of[E,S,R]){let w=f[P]*3;d[w]+=c.x,d[w+1]+=c.y,d[w+2]+=c.z}}let x=new Float32Array(i.count*3);for(let y=0;y2e6)throw new Error("deformation requires 1..2000000 xyz positions");if(Object.keys(r.morphAttributes).length)throw new Error("deformation of morph targets needs a separate mapping contract; deform before creating morph targets.");let i=r.index,s=i?.count??n.count;if(!Number.isSafeInteger(s)||s<3||s%3||s>3e6)throw new Error("deformation requires complete triangles and at most 3000000 corners");if(i)for(let p=0;p=n.count)throw new Error("deformation index is invalid")}let o=r.getAttribute("normal");if(o){if(o.itemSize!==3||o.count!==n.count)throw new Error("deformation normals must match xyz positions");for(let p=0;pnew C().fromBufferAttribute(n,M).applyMatrix4(l));if(c.some(p=>![p.x,p.y,p.z].every(Number.isFinite)))throw new Error("deformation positions must be finite");let h=1/0,u=-1/0;for(let p of c)h=Math.min(h,p.y),u=Math.max(u,p.y);if(e.interval){if(e.interval.length!==2||!e.interval.every(Number.isFinite)||e.interval[1]<=e.interval[0])throw new Error("deformation interval must be finite and increasing");[h,u]=e.interval}let f=u-h,d=r.clone();d.userData=structuredClone(r.userData);let m=d.getAttribute("position"),_=!1,g=f>0?Math.min(Math.max(Math.abs(h),Math.abs(u),f)*1e-7,f*1e-6):0;for(let p=0;pu+g)continue;let x=f>0?sn.clamp((M.y-h)/f,0,1):0,y=e.falloff?.(x)??1;if(!Number.isFinite(y)||y<0||y>1)throw new Error("deformation falloff must return a finite weight between 0 and 1");let E=t(M.clone(),x,h,f);if(![E.x,E.y,E.z].every(Number.isFinite))throw new Error("deformation callback must return finite coordinates");if(M.lerp(E,y).applyMatrix4(a),![M.x,M.y,M.z].every(S=>Number.isFinite(Math.fround(S))))throw new Error("deformation output must fit finite Float32 coordinates");m.setXYZ(p,M.x,M.y,M.z),_||=m.getX(p)!==n.getX(p)||m.getY(p)!==n.getY(p)||m.getZ(p)!==n.getZ(p)}if(m.needsUpdate=!0,d.hasAttribute("tangent")){d.deleteAttribute("tangent");let p=d.userData.kilnAttributeWarnings;d.userData.kilnAttributeWarnings=[...Array.isArray(p)?p:[],{code:"DEFORM_TANGENTS_DROPPED",message:"Deformation invalidated tangents; regenerate for normal mapping."}]}return(_||!o)&&y_(r,d),d.computeBoundingBox(),d.computeBoundingSphere(),d}function x_(r,e){if(!Number.isFinite(e.angle))throw new Error("twist angle must be finite degrees");return Wh(r,e,(t,n)=>t.applyAxisAngle(new C(0,1,0),sn.degToRad(e.angle)*n))}function v_(r,e){if(!Number.isFinite(e.angle))throw new Error("bend angle must be finite degrees");let t=sn.degToRad(e.angle);return Wh(r,e,(n,i,s,o)=>{if(Math.abs(t)<1e-10||o===0)return n;let a=o/t,l=t*i;return new C(a-(a-n.x)*Math.cos(l),s+(a-n.x)*Math.sin(l),n.z)})}function b_(r,e){let t=e.startScale??[1,1],n=e.endScale;if(t.length!==2||n.length!==2||![...t,...n].every(i=>Number.isFinite(i)&&i>0))throw new Error("taper scales must be two finite positive values");return Wh(r,e,(i,s)=>i.set(i.x*sn.lerp(t[0],n[0],s),i.y,i.z*sn.lerp(t[1],n[1],s)))}function M_(r,e,t={}){return Wh(r,t,(n,i)=>{let s=e([n.x,n.y,n.z],i);if(s.length!==3||!s.every(Number.isFinite))throw new Error("displace callback must return three finite offsets");return n.add(new C(...s))})}function Ip(r,e){if("holes"in r&&r.holes!==void 0)throw new Jt("PROFILE_HOLES_UNSUPPORTED",`${e}: holes are unsupported. Use extrudeProfile for a holed cross-section with optional twist/taper; independently varying contours need explicit geometry or solid subtraction.`)}function E_(r){if(r.length<3||r.some(a=>a.length!==2||!a.every(Number.isFinite)))throw new Error("profile requires at least three finite xy points");let e=r.map(a=>new ce(...a)),t=new ls().setFromPoints(e),n=t.getSize(new ce).length();if(!(n>0)||!Number.isFinite(n))throw new Error("profile requires a finite nonzero extent");let i=e.map(a=>a.clone().sub(t.min).divideScalar(n));if(i[0].distanceTo(i[i.length-1])<1e-10&&(e.pop(),i.pop()),e.length<3)throw new Error("profile requires three distinct points");let s=(a,l,c)=>(l.x-a.x)*(c.y-a.y)-(l.y-a.y)*(c.x-a.x);for(let a=0;am.reduce((_,g)=>_.add(g),new C).multiplyScalar(1/s)),h=[0];for(let m=1;m0)||!Number.isFinite(u))throw new Error("loft section centers must progress along a finite nonzero path");for(let m=0;m0){let V=E.clone().divideScalar(w),G=P.divideScalar(w).sub(V),Z=G.lengthSq(),K=Z>0?-V.dot(G)/Z:0;if(K>0&&K<1&&V.addScaledVector(G,K).lengthSq()<=1e-20)throw new Jt("PROFILE_CORRESPONDENCE_COLLAPSE")}let T=Math.max(E.length(),S.length(),R.length());if((T>0?Math.abs(E.clone().divideScalar(T).dot(S.clone().divideScalar(T).cross(R.clone().divideScalar(T)))):0)>1e-10){let V=o.length/3;o.push(...y.clone().addScaledVector(E,.25).addScaledVector(S,.25).addScaledVector(R,.25).toArray()),a.push((a[g*2]+a[p*2]+a[M*2]+a[x*2])/4,(a[g*2+1]+a[p*2+1]+a[M*2+1]+a[x*2+1])/4),l.push(g,M,V,M,x,V,x,p,V,p,g,V)}else l.push(g,M,p,p,M,x)}if(n&&!t)for(let m of[0,r.length-1]){let _=r[m],g=e[m],p=o.length/3,M=new ls().setFromPoints(g),x=M.getSize(new ce);for(let y=0;yp+E)):l.push(...y.toReversed().map(E=>p+E))}if(i&&i.dot(c[1].clone().sub(c[0]))<0)for(let m=0;m(Ip(o,`loftProfiles section ${a}`),E_(o.profile)));if(t.some(o=>o.length!==t[0].length))throw new Error("loftProfiles sections must have the same point count and correspondence");let n=r.map(o=>_c(o.frame)),i=t.map((o,a)=>o.map(l=>new C(l.x,0,l.y).applyMatrix4(n[a]))),s=S_(i,t,!1,e.cap??!0,new C(0,1,0).transformDirection(n[0]));return s.userData.kilnGeometryWarnings=[{code:"LOFT_SELF_INTERSECTION_UNCHECKED",message:"Corresponding profiles are connected directly. Caps and closed boundaries do not prove the loft is free of self-intersections."}],s}function T_(r,e,t={}){Ip(t,"sweepProfile");let n=E_(r),i=t.closed??!1,s=t.twist??0;if(!Number.isFinite(s))throw new Error("sweepProfile twist must be finite degrees");if(i&&Math.abs(s/360-Math.round(s/360))>1e-8)throw new Error("closed sweep twist must be a multiple of 360 degrees");if(e.length<(i?3:2)||e.some(S=>S.length!==3||!S.every(Number.isFinite)))throw new Error("sweepProfile requires finite path points (two open or three closed)");let o=e.map(S=>new C(...S)),a=new Ct().setFromPoints(o).getSize(new C).length();if(!(a>0)||!Number.isFinite(a))throw new Error("sweepProfile path stations must be distinct with finite extent");let l=a*1e-10;if(i&&o[0].distanceTo(o[o.length-1]){let P=typeof t.scale=="number"?[t.scale,t.scale]:t.scale?.[R]??[1,1];if(P.length!==2||!P.every(w=>Number.isFinite(w)&&w>0))throw new Error("sweepProfile scale requires positive finite pairs");return P});if(Array.isArray(t.scale)&&t.scale.length!==o.length)throw new Error("sweepProfile scale needs one pair per path station");let f=o.map((S,R)=>{if(!i&&R===0)return c[0].clone();if(!i&&R===o.length-1)return c[c.length-1].clone();let P=c[(R-1+c.length)%c.length],w=c[R];if(P.dot(w)<-.9999)throw new Error("sweepProfile path has a reversal; split it into separate sweeps");let T=P.angleTo(w),N=Math.min(o[R].distanceTo(o[(R-1+o.length)%o.length]),o[R].distanceTo(o[(R+1)%o.length])),V=u[R];return n.reduce((Z,K)=>Math.max(Z,Math.hypot(K.x*V[0],K.y*V[1])),0)*Math.tan(T/2)>=N*.5&&h.push({code:"SWEEP_TIGHT_TURN",message:`Path station ${R} turns tightly relative to the profile; reduce its size or widen the turn. Self-intersection is possible.`}),P.clone().add(w).normalize()}),d=t.up?new C(...t.up):Math.abs(f[0].z)<.9?new C(0,0,1):new C(1,0,0),m=Math.hypot(d.x,d.y,d.z);if(!(m>0)||!Number.isFinite(m))throw new Error("sweepProfile up must be a finite nonzero vector");d.divideScalar(m);let _=d.clone().addScaledVector(f[0],-d.dot(f[0]));if(_.lengthSq()<1e-12)throw new Error("sweepProfile up must not be parallel to the first path tangent");_.normalize();let g=[_.clone()];i&&(o.push(o[0].clone()),f.push(f[0].clone()),u.push(u[0]));let p=[0];for(let S=1;S{let P=f[R],w=p[R]/M,T=g[R].clone().applyAxisAngle(P,(x+sn.degToRad(s))*w),N=P.clone().cross(T).normalize(),V=u[R];return n.map(G=>S.clone().addScaledVector(N,G.x*V[0]).addScaledVector(T,G.y*V[1]))});i&&(y[y.length-1]=y[0].map(S=>S.clone()));let E=S_(y,y.map(()=>n),i,t.cap??!0);return h.push({code:"SWEEP_SELF_INTERSECTION_UNCHECKED",message:"Transported frames and caps do not prove a sweep is free of self-intersections. Review tight turns and nearby path segments."}),E.userData.kilnGeometryWarnings=h,E}var Xh=2e6,Ww=128*1024*1024;function Oo(r,e){if(!e||typeof e!="object"||Array.isArray(e)||!["planar","box","cylindrical"].includes(e.projection)||Object.keys(e).some(E=>!["projection","frame","seamDegrees","angularRange","caps"].includes(E)))throw new Error("projectUV: select an explicit planar, box or cylindrical projection with documented options.");let t=e.projection==="cylindrical";if(!t&&[e.seamDegrees,e.angularRange,e.caps].some(E=>E!==void 0))throw new Error("projectUV: seamDegrees, angularRange and caps apply only to cylindrical projection.");if(e.seamDegrees!==void 0&&(!Number.isFinite(e.seamDegrees)||e.angularRange!==void 0))throw new Error("projectUV: seamDegrees must be finite and cannot accompany angularRange.");if(e.angularRange!==void 0&&(!Array.isArray(e.angularRange)||e.angularRange.length!==2||!e.angularRange.every(Number.isFinite)||e.angularRange[1]<=0||e.angularRange[1]>360))throw new Error("projectUV: angularRange must be [finite start degrees, positive sweep <=360].");if(e.caps!==void 0&&e.caps!=="planar"&&e.caps!=="side")throw new Error("projectUV: caps must be planar or side.");let n=_c(e.frame).invert(),i=r.getAttribute("position");if(i?.itemSize!==3||i.count<1||i.count>Xh)throw new Error(`projectUV: position requires 1..${Xh} xyz samples.`);if(Object.keys(r.morphAttributes).length)throw new Error("projectUV: morph targets need a separate mapping contract.");let s=r.index,o=s?.count??i.count;if(!Number.isSafeInteger(o)||o<3||o%3!==0||o>Xh)throw new Error(`projectUV: triangle corner count must be divisible by three and <=${Xh}.`);let a=o*8;for(let[E,S]of Object.entries(r.attributes)){if(S.count!==i.count||!Number.isInteger(S.itemSize)||S.itemSize<1||S.itemSize>16||S.isInstancedBufferAttribute)throw new Error(`projectUV: ${E} must be a matching per-vertex attribute of 1..16 components.`);a+=o*S.itemSize*S.array.BYTES_PER_ELEMENT}if(a>Ww)throw new Error("projectUV: expanded attributes exceed 128 MiB.");if(s)for(let E=0;E=i.count)throw new Error("projectUV: index contains an invalid vertex reference.")}let l=[],c=new Ct;for(let E=0;Eh[S]>0?(E[S]-c.min[S])/h[S]:.5,f=new Float32Array(o*2),m=(e.angularRange?.[0]??e.seamDegrees??180)%360*Math.PI/180,_=(e.angularRange?.[1]??360)*Math.PI/180,g=e.angularRange===void 0||e.angularRange[1]===360,p=E=>(E%(2*Math.PI)+2*Math.PI)%(2*Math.PI),M=new C,x=new C;for(let E=0;El[s?s.getX(E+w):E+w]);M.subVectors(S[1],S[0]).cross(x.subVectors(S[2],S[0])).normalize();let R=t&&e.caps!=="side"&&Math.abs(M.y)>=1-1e-6,P;if(t&&!R){let w=S.map(T=>{let N=p(Math.atan2(T.z,T.x)-m);if(N>2*Math.PI-1e-6&&(N=0),!g&&N>_+1e-6)throw new Error("projectUV: side vertex lies outside angularRange; choose a range covering the profile.");return(g?N:Math.min(N,_))/_});if(g&&Math.max(...w)-Math.min(...w)>.5)for(let T=0;T<3;T++)w[T]<.5&&(w[T]+=1);if(g&&Math.max(...w)-Math.min(...w)>.5+1e-6)throw new Error("projectUV: side triangle spans more than half a revolution; add profile segments to resolve the mapping.");P=S.map((T,N)=>[w[N],u(T,"y")])}else if(R)P=S.map(w=>[u(w,"x"),u(w,"z")]);else if(e.projection==="box"){let w=Math.abs(M.x)>=Math.abs(M.y)&&Math.abs(M.x)>=Math.abs(M.z)?"x":Math.abs(M.y)>=Math.abs(M.z)?"y":"z";P=S.map(T=>w==="x"?[M.x>0?1-u(T,"z"):u(T,"z"),u(T,"y")]:w==="y"?[u(T,"x"),M.y>0?1-u(T,"z"):u(T,"z")]:[M.z<0?1-u(T,"x"):u(T,"x"),u(T,"y")])}else P=S.map(w=>[u(w,"x"),u(w,"y")]);for(let w=0;w<3;w++){let T=P[w];if(!T.every(N=>Number.isFinite(Math.fround(N))))throw new Error("projectUV: projected UVs must fit finite Float32.");f[(E+w)*2]=T[0],f[(E+w)*2+1]=T[1]}}let y=r.index?r.toNonIndexed():r.clone();if(y.userData=structuredClone(r.userData),y.setDrawRange(r.drawRange.start,r.drawRange.count),y.setAttribute("uv",new De(f,2)),y.hasAttribute("tangent")){y.deleteAttribute("tangent");let E=y.userData.kilnAttributeWarnings;y.userData.kilnAttributeWarnings=[...Array.isArray(E)?E:[],{code:"UV_PROJECTION_TANGENTS_DROPPED",message:"UV projection invalidated tangents; regenerate them when needed for normal mapping."}]}return y}var $h=null;function A_(r){$h=r}async function Bo(){if(!$h)throw new Error("manifold is not initialised in this runtime.");return $h}function Xw(r,e){if(r?.isBufferGeometry)return[{geometry:r,matrix:new Qe,label:e}];if(r?.isObject3D!==!0)throw new TypeError(`${e}: operands must be geometries or parts (got ${r===null?"null":typeof r}).`);let t=r;t.updateWorldMatrix(!0,!0);let n=[];return t.traverse(i=>{let s=i;s.isMesh&&s.geometry.getAttribute("position")?.count&&n.push({geometry:s.geometry,matrix:s.matrixWorld.clone(),label:`${e} (${s.name||"part"})`})}),n}function $w(r){let e=new Ct,t=new C;for(let{geometry:s,matrix:o}of r){let a=s.getAttribute("position");for(let l=0;lNumber.isFinite(Math.fround(S))))throw new Error(`CSG ${_}: transformed positions must be finite Float32 coordinates`);o.push(c.x,c.y,c.z),i&&o.push(x?x.getX(E):0,x?x.getY(E):0)}let y=m.determinant()<0;for(let E=0;E!Number.isInteger(R)||R<0||R>=g.count))throw new Error(`CSG ${_}: index outside positions`);y&&([S[1],S[2]]=[S[2],S[1]]),a.push(S[0]+l,S[1]+l,S[2]+l)}l+=g.count}if(!a.length)throw new Error(`CSG ${t}: contributes no triangles. Every CSG operand must be a solid with triangles.`);let h=new e.Mesh({numProp:s,vertProperties:new Float32Array(o),triVerts:new Uint32Array(a)});h.merge();let u=d=>new Error(`CSG ${t}: the operand is not a closed solid (${d}). Open surfaces (lathe, planeGeo, tubes) cannot enter a boolean.`),f;try{f=e.Manifold.ofMesh(h)}catch(d){throw u(d instanceof Error?d.message:String(d))}if(f.status()!=="NoError"){let d=f.status();throw f.delete(),u(d)}return f}function Dp(r){let e=r.vertProperties,t=r.numProp,n=r.triVerts,i=[];for(let s=0;si[c/3])}function R_(r){let e=$h,t=r.getMesh();if(!Dp(t).length)return t;let n=0;for(let s=0;s=5?new Float32Array(t.length/3*2):void 0;for(let o=0,a=0;o{let u=r==="boolDiff"?h===0?"boolDiff body":`boolDiff cutter ${h}`:`${r} operand ${h+1}`;return{label:u,parts:Xw(c,u)}}),s=$w(i.flatMap(c=>c.parts)),o=r!=="hull"&&i.some(c=>c.parts.some(h=>h.geometry.getAttribute("uv"))),a=new Set,l=c=>(a.add(c),c);try{let c;if(r==="hull"){let u=[],f=new C;for(let d of i)for(let{geometry:m,matrix:_}of d.parts){let g=m.getAttribute("position");for(let p=0;pl(qw(f.parts,n,f.label,s,o)));if(r==="boolUnion")c=l(n.Manifold.union(u));else if(r==="boolDiff"){let f=u.length===2?u[1]:l(n.Manifold.union(u.slice(1)));c=l(u[0].subtract(f))}else c=l(u[0].intersect(u[1]))}if(c.numTri()===0){let u=r==="boolDiff"?"The cutters removed the entire body -- check their size and position.":r==="boolIntersect"?"The two operands do not overlap -- position them so their volumes intersect.":r==="hull"?"The inputs are coplanar or collinear, so they enclose no volume.":"Every operand was empty.";throw new Error(`${r}: the result is empty (zero triangles). ${u}`)}let h=l(l(c.scale(s.scale)).translate(s.center.toArray()));return C_(R_(h),{smooth:t.smooth??r==="hull",preserveUV:o})}finally{for(let c of a)c.delete()}}async function P_(...r){let{operands:e,opts:t}=Lp(r);if(e.length<2)throw new Error("boolUnion requires at least two operands");return Yh("boolUnion",e,t)}async function I_(r,...e){let{operands:t,opts:n}=Lp(e);if(t.length<1)throw new Error("boolDiff requires at least one cutter");return Yh("boolDiff",[r,...t],n)}async function D_(r,e,t={}){return Yh("boolIntersect",[r,e],t)}async function L_(...r){let{operands:e,opts:t}=Lp(r);if(e.length<1)throw new Error("hull requires at least one operand");return Yh("hull",e,t)}async function U_(r){let t=(await Bo()).Manifold.hull(r);try{if(t.numTri()===0)throw new Error("hull: the points enclose no volume.");let n=t.getMesh(),i=new Float32Array(n.vertProperties.length/n.numProp*3);for(let o=0,a=0;o= 0 (got ${r}).`);return[r,r]}if(!Array.isArray(r)||r.length!==2||!r.every(e=>Number.isFinite(e)&&e>=0))throw new Error(`taper must be a number or [x, y] pair of numbers >= 0 (got ${JSON.stringify(r)}).`);return[r[0],r[1]]}async function O_(r,e={}){Up(r,"extrudeProfile");let{depth:t=1,holes:n=[],bevel:i=0,bevelStyle:s="round",segments:o=12,twist:a=0,taper:l,divisions:c,axis:h="y",center:u=!0,smooth:f=!1}=e;if(zo(t,"extrudeProfile: depth"),i<0)throw new Error(`extrudeProfile: bevel must be >= 0 (got ${i}).`);for(let p=0;p(_.push(p),p);try{let p=g(new m([r],"NonZero"));if(n.length>0){let y=n.map(E=>g(new m([E],"NonZero")));if(p=g(m.difference(p,m.union(y))),p.isEmpty())throw new Error("extrudeProfile: the holes consume the whole profile \u2014 nothing left to extrude.")}i>0&&(p=g(F_(p,i,s,o,"extrudeProfile")));let M=c??(a!==0?16:1),x=p.extrude(t,M,a,jw(l),u);try{return N_(qh(x,{smooth:f}),h)}finally{x.delete()}}finally{for(let p of _)p.delete()}}async function B_(r,e={}){Up(r,"revolveProfile");let{segments:t=24,angle:n=360,bevel:i=0,bevelStyle:s="round",bevelSegments:o=12,axis:a="y",smooth:l=!0}=e;if(i<0)throw new Error(`revolveProfile: bevel must be >= 0 (got ${i}).`);if(!Number.isFinite(n)||n<=0||n>360)throw new Error(`revolveProfile: angle must be in (0, 360] degrees (got ${n}).`);let c=await Bo(),{CrossSection:h}=c,u=[];try{let f=new h([r],"NonZero");u.push(f),i>0&&(f=F_(f,i,s,o,"revolveProfile"),u.push(f));let d=f.revolve(t,n);try{return N_(qh(d,{smooth:l}),a)}finally{d.delete()}}finally{for(let f of u)f.delete()}}async function z_(r,e,t,n,i={}){zo(r,"roundedBoxGeo: width"),zo(e,"roundedBoxGeo: height"),zo(t,"roundedBoxGeo: depth"),zo(n,"roundedBoxGeo: radius");let{style:s="round",segments:o=12,smooth:a}=i,l=Math.min(r,e,t);if(n>=l/2)throw new Jt("ROUNDED_BOX_RADIUS");let h=(await Bo()).Manifold,u=[];try{let f;if(s==="round"){let d=[];for(let m of[-1,1])for(let _ of[-1,1])for(let g of[-1,1]){let p=h.sphere(n,o).translate([m*(r-2*n)/2,_*(e-2*n)/2,g*(t-2*n)/2]);u.push(p),d.push(p)}f=h.hull(d)}else if(s==="chamfer"){let d=[h.cube([r,e-2*n,t-2*n],!0),h.cube([r-2*n,e,t-2*n],!0),h.cube([r-2*n,e-2*n,t],!0)];u.push(...d),f=h.hull(d)}else throw new Error(`roundedBoxGeo: style must be 'round' or 'chamfer' (got ${String(s)}).`);try{return qh(f,{smooth:a??s==="round"})}finally{f.delete()}}finally{for(let f of u)f.delete()}}function V_(r,e=24,t=[0,0]){if(zo(r,"circleProfile: radius"),!Number.isInteger(e)||e<3)throw new Error(`circleProfile: segments must be an integer >= 3 (got ${e}).`);let n=[];for(let i=0;i!["scale","offset"].includes(l)))throw new Error("remapUV: options may contain only scale and offset.");let t=e.scale===void 0?[1,1]:e.scale,n=e.offset===void 0?[0,0]:e.offset;for(let[l,c]of Object.entries({scale:t,offset:n}))if(!Array.isArray(c)||c.length!==2||!c.every(Number.isFinite))throw new Error(`remapUV: ${l} must contain two finite numbers.`);let i=r.getAttribute("uv"),s=r.getAttribute("position");if(i?.itemSize!==2||!s||i.count!==s.count)throw new Error("remapUV: existing UV0 with two components per vertex is required; project or unwrap first.");let o=new Float32Array(i.count*2);for(let l=0;l=1)throw new RangeError("gearGeo toothWidthFrac must be strictly between 0 and 1.");if(n<=t||i>=t)throw new Jt("GEAR_RADII_ORDER");let a=Math.PI*2/e,l=(1-o)*(a/2),c=[];for(let E=0;E0&&m.push(w,T,P)}for(let E=0;E0&&m.push(w,P,T)}for(let E=0;E0&&E1)throw new RangeError("bladeGeo edgeBevel must be between 0 and 1.");if(i>=e)throw new Error("bladeGeo: tipLength must be less than length");let o=t/2,a=n/2,l=e-i,c=[[-o,0],[o,0],[o,l],[0,e],[-o,l]],h=c.length,u=[],f=[];if(s<=0){for(let[_,g]of c)u.push(_,g,a);for(let[_,g]of c)u.push(_,g,-a);for(let _=1;_!Qw.test(r)))),tT=Object.freeze(Object.fromEntries([...Object.getOwnPropertyNames(Math).map(r=>[r,Math[r]]),["random",()=>{throw new Error("Math.random() is unavailable in model programs: use random(seed) so builds are reproducible.")}]]));function Np(){throw new Error("Date is unavailable in model programs: builds must be reproducible, so nothing may depend on the clock.")}Np.now=Np;var nT=Object.freeze({createRoot:O0,createPart:z0,createGroup:B0,createInstance:Fo,slot:U0,color:N0,collisionProxy:V0,random:G0,transformGeo:H0,THREE:eT,boxGeo:q0,sphereGeo:Y0,torusGeo:Q0,planeGeo:e_,cylinderGeo:vs,cylinderXGeo:X0,cylinderYGeo:vs,cylinderZGeo:$0,capsuleGeo:pc,capsuleXGeo:k0,capsuleYGeo:pc,capsuleZGeo:W0,coneGeo:mc,coneXGeo:Z0,coneYGeo:mc,coneZGeo:J0,cylinderOnAxis:j0,taperConeGeo:K0,wingGeo:t_,copyGeometry:n_,countTriangles:i_,arrayLinear:s_,arrayRadial:o_,mirror:a_,mergeVertices:l_,curveToMesh:Rp,pipeAlongPath:h_,lathe:u_,revolveGeo:Cp,bezierCurve:f_,meshGeo:gc,parametricSurface:__,creaseNormals:kh,geometryDiagnostics:Gh,sweepProfile:T_,loftProfiles:w_,bend:v_,twist:x_,taper:b_,displace:M_,roundedBoxGeo:z_,extrudeProfile:O_,revolveProfile:B_,circleProfile:V_,boolUnion:P_,boolDiff:I_,boolIntersect:D_,hull:L_,projectUV:Oo,remapUV:H_,gearGeo:G_,bladeGeo:k_,Math:tT,Date:Np,gameMaterial:No("gameMaterial"),basicMaterial:No("basicMaterial"),glassMaterial:No("glassMaterial"),lambertMaterial:No("lambertMaterial"),pbrMaterial:No("pbrMaterial")});var Fp=Object.freeze({triangles:6e4,slots:8,parts:300,colliderTriangles:2e4});var lA=Object.freeze({realistic:Fp,"hand-painted":Object.freeze({triangles:2e4,slots:6,parts:200,colliderTriangles:1e4}),"low-poly":Object.freeze({triangles:6e3,slots:6,parts:120,colliderTriangles:4e3})}),W_=.02;var Op=2e7;var Zh=["budget-triangles","budget-slots","budget-parts","budget-collider-triangles"];function X_(r,e={},t){let n={...Fp,...e},i=t?`the ${t} budget`:"the budget";return[[Zh[0],r.triangles,n.triangles,"triangles"],[Zh[1],r.slots,n.slots,"material slots"],[Zh[2],r.parts,n.parts,"parts"],[Zh[3],r.colliderTriangles,n.colliderTriangles,"collider triangles"]].filter(([,o,a])=>o>a).map(([o,a,l,c])=>({severity:"warning",code:o,message:`${a} ${c} exceeds ${i} of ${l}.`}))}var iT="modeler@2";var rT=["createRoot","createPart","createGroup","createInstance","slot","color","collisionProxy","random","transformGeo","THREE","boxGeo","sphereGeo","torusGeo","planeGeo","cylinderGeo","cylinderXGeo","cylinderYGeo","cylinderZGeo","capsuleGeo","capsuleXGeo","capsuleYGeo","capsuleZGeo","coneGeo","coneXGeo","coneYGeo","coneZGeo","cylinderOnAxis","taperConeGeo","wingGeo","copyGeometry","countTriangles","arrayLinear","arrayRadial","mirror","mergeVertices","curveToMesh","pipeAlongPath","lathe","revolveGeo","bezierCurve","meshGeo","parametricSurface","creaseNormals","geometryDiagnostics","sweepProfile","loftProfiles","bend","twist","taper","displace","roundedBoxGeo","extrudeProfile","revolveProfile","circleProfile","boolUnion","boolDiff","boolIntersect","hull","projectUV","remapUV","gearGeo","bladeGeo"],sT=["Math","Date","gameMaterial","basicMaterial","glassMaterial","lambertMaterial","pbrMaterial"],fA=[...rT,...sT];var oT=.02;function $_(r,e){let t=Math.max(0,r.min.x-e.max.x,e.min.x-r.max.x),n=Math.max(0,r.min.y-e.max.y,e.min.y-r.max.y),i=Math.max(0,r.min.z-e.max.z,e.min.z-r.max.z);return Math.hypot(t,n,i)}function q_(r){if(r.length<2)return[];let e=r.map(()=>[]);for(let a=0;au-f),n.push(c)}if(n.length<2)return[];let i=0;for(let a=1;an[i].length,c=n[a].length===n[i].length&&n[a][0]{if(l===i)return;let c=Number.POSITIVE_INFINITY;for(let h of a)for(let u of s)c=Math.min(c,$_(r[h].box,r[u].box));o.push({parts:a.map(h=>r[h].name),gap:Math.round(c*1e6)/1e6})}),o.sort((a,l)=>l.parts.length-a.parts.length||a.gap-l.gap),o}var aT="HELIX modeler";function Bp(r){let e=[],t=0,n=[],i=[],s=(x,y)=>{let E=(4-t%4)%4;return E&&(e.push(new Uint8Array(E)),t+=E),n.push({buffer:0,byteOffset:t,byteLength:x.byteLength,target:y}),e.push(x),t+=x.byteLength,n.length-1},o=x=>new Uint8Array(x.buffer,x.byteOffset,x.byteLength),a=(x,y,E)=>{let S=x.length/y,R={bufferView:s(o(x),34962),componentType:5126,count:S,type:y===3?"VEC3":"VEC2"};if(E){let P=new Array(y).fill(1/0),w=new Array(y).fill(-1/0);for(let T=0;Tw[N]&&(w[N]=x[T])}R.min=P.map(Math.fround),R.max=w.map(Math.fround)}return i.push(R),i.length-1},l=(x,y)=>{let E=y<65536,S=E?Uint16Array.from(x):x;return i.push({bufferView:s(o(S),34963),componentType:E?5123:5125,count:x.length,type:"SCALAR"}),i.length-1},c=r.meshes.map(x=>({name:x.name,primitives:x.primitives.map(y=>{let E=y.positions.length/3,S={POSITION:a(y.positions,3,!0)};y.normals&&(S.NORMAL=a(y.normals,3,!1)),y.uvs&&(S.TEXCOORD_0=a(y.uvs,2,!1)),y.colors&&(S.COLOR_0=a(y.colors,3,!1));let R={attributes:S,indices:l(y.indices,E),mode:4};return y.material!==void 0&&(R.material=y.material),R}),...x.extras?{extras:x.extras}:{}})),h=[{name:r.rootName,children:r.meshes.map((x,y)=>y+1)}];r.meshes.forEach((x,y)=>h.push({name:x.name,mesh:y})),r.meshes.length||delete h[0].children;let u={asset:{version:"2.0",generator:aT},scene:0,scenes:[{nodes:[0]}],nodes:h,meshes:c,accessors:i,bufferViews:n,buffers:[{byteLength:t}]};r.materials.length&&(u.materials=r.materials.map(x=>({name:x.name,pbrMetallicRoughness:x.vertexColors?{baseColorFactor:[1,1,1,1],metallicFactor:0,roughnessFactor:.9}:{baseColorFactor:[.8,.8,.8,1],metallicFactor:0,roughnessFactor:.8}}))),c.length||(delete u.meshes,delete u.accessors,delete u.bufferViews,delete u.buffers);let f=new TextEncoder().encode(JSON.stringify(u)),d=(4-f.length%4)%4,m=(4-t%4)%4,_=t>0,g=20+f.length+d+(_?8+t+m:0),p=new Uint8Array(g),M=new DataView(p.buffer);if(M.setUint32(0,1179937895,!0),M.setUint32(4,2,!0),M.setUint32(8,g,!0),M.setUint32(12,f.length+d,!0),M.setUint32(16,1313821514,!0),p.set(f,20),p.fill(32,20+f.length,20+f.length+d),_){let x=20+f.length+d;M.setUint32(x,t+m,!0),M.setUint32(x+4,5130562,!0),x+=8;for(let y of e)p.set(y,x),x+=y.byteLength}return p}var Y_={helixUvUnits:"metre"};function Z_(r,e,t,n){let i=r.length/3,s=new Int32Array(i);for(let u=0;u{for(;s[u]!==u;)s[u]=s[s[u]],u=s[u];return u},a=(u,f)=>{let d=o(u),m=o(f);d!==m&&(s[d]=m)},l=new Map,c=u=>[r[u*3],r[u*3+1],r[u*3+2],e[u*3],e[u*3+1],e[u*3+2],t[u*2],t[u*2+1]].map(f=>Math.round(f*1e5)).join(",");for(let u=0;uOp)throw yc=new zp(r)}function cT(){return J_=0,yc=null,lT}function Vp(){return yc}function j_(r){return r instanceof RangeError&&/maximum call stack size exceeded/i.test(r.message)}var K_=()=>typeof performance<"u"?performance.now():0;function Q_(r){let e=t=>Math.round(t*1e6)/1e6;return{min:[e(r.min.x),e(r.min.y),e(r.min.z)],max:[e(r.max.x),e(r.max.y),e(r.max.z)]}}function hT(r){let e=r instanceof Error?r.stack??"":"",t=/model\.js:(\d+):\d+/.exec(e);if(!t)return;let n=Number(t[1])-1;return n>0?n:void 0}function iy(r){let e=r instanceof Error?r.message:String(r);return r instanceof ReferenceError&&/ is not defined/.test(e)?`${e}. Only the documented helpers exist as globals; search them (model_search / searchHelpers) for the exact name.`:e}function ry(r){let e=Vp();if(e)return{code:"loop-budget",message:e.message,line:e.line};let t=hT(r);return j_(r)?{code:"loop-budget",message:"The program recursed too deeply (maximum call stack size exceeded) \u2014 likely runaway recursion.",...t?{line:t}:{}}:{code:"build-error",message:iy(r),...t?{line:t}:{}}}function sy(r){return{ok:!1,errors:[],meta:r,slots:[],parts:[],metrics:{triangles:0,slots:0,parts:0,colliderTriangles:0,buildMs:0},findings:[]}}function Jh(r){for(let e=0;e0||o.invalidIndices>0)return t.push({severity:"error",code:"non-finite-geometry",message:`Part "${e.name}" has ${o.nonFiniteVertices} non-finite vertices and ${o.invalidIndices} invalid triangles.`,part:e.name}),null;let a=new et;a.setAttribute("position",s.clone()),i.index&&a.setIndex(i.index.clone());let l=i.getAttribute("normal");l&&l.itemSize===3&&l.count===s.count?a.setAttribute("normal",l.clone()):a.computeVertexNormals();let c=i.getAttribute("uv");c&&c.itemSize===2&&c.count===s.count?a.setAttribute("uv",c.clone()):(a=Oo(a,{projection:"box"}),n.push(e.name)),a.computeBoundingBox();let h=a.boundingBox.clone(),u=a.clone().applyMatrix4(r.matrixWorld);r.matrixWorld.determinant()<0&&Tp(u);let f=u.getAttribute("position").count,d=u.index?Uint32Array.from(u.index.array):Uint32Array.from({length:f-f%3},(x,y)=>y);if(!d.length)return t.push({severity:"warning",code:"empty-part",message:`Part "${e.name}" has zero triangles and was skipped.`,part:e.name}),null;if(o.degenerateTriangles>0){let x=o.degenerateTriangles/Math.max(1,o.triangles);t.push({severity:x>.1?"warning":"info",code:"degenerate-triangles",message:`Part "${e.name}" has ${o.degenerateTriangles} zero-area triangles of ${o.triangles}.`,part:e.name})}let m=i.userData.kilnGeometryWarnings;if(Array.isArray(m))for(let x of m)x&&typeof x=="object"&&x.code==="SWEEP_TIGHT_TURN"&&t.push({severity:"warning",code:"sweep-tight-turn",message:`Part "${e.name}": ${String(x.message)}`,part:e.name});let _=Jh(Float32Array.from(u.getAttribute("position").array)),g=new Ct;for(let x=0;x<_.length;x+=3)g.expandByPoint(new C(_[x],_[x+1],_[x+2]));let p=Jh(Float32Array.from(u.getAttribute("normal").array)),M=Float32Array.from(u.getAttribute("uv").array);return Z_(_,p,M,d),{info:e,positions:_,normals:p,uvs:Jh(M),indices:d,bounds:g,localBox:h,matrix:r.matrixWorld.clone()}}var dT=[0,2,1,2,3,1,4,5,6,6,5,7,0,1,4,4,1,5,2,6,3,6,7,3,0,4,2,2,4,6,1,3,5,5,3,7];function pT(r,e){let t=new Float32Array(24),n=new C;for(let i=0;i<8;i++)n.set(i&4?r.max.x:r.min.x,i&2?r.max.y:r.min.y,i&1?r.max.z:r.min.z).applyMatrix4(e),t.set([n.x,n.y,n.z],i*3);return t}function mT(r,e){let t=new C;for(let o=0;oa);if(e.determinant()<0)for(let o=0;oa+l.positions.length/3,0),t=r.reduce((a,l)=>a+l.indices.length,0),n=new Float32Array(e*3),i=new Uint32Array(t),s=0,o=0;for(let a of r){n.set(a.positions,s*3);for(let l=0;l(s.metrics.buildMs=Math.round(K_()-t),s.ok=s.errors.length===0&&!s.findings.some(h=>h.severity==="error"),s);if(typeof r.__build!="function")return s.errors.push({code:"missing-build",message:"The program must define a build() function returning createRoot(...)."}),o();let a;try{a=await r.__build()}catch(h){return s.errors.push(ry(h)),o()}let l=Vp();if(l)return s.errors.push({code:"loop-budget",message:l.message,line:l.line}),o();let c=a;if(c?.isObject3D!==!0||c.userData.helixRoot!==!0)return s.errors.push({code:"build-return",message:"build() must return the object created by createRoot(name), with every part under it."}),o();try{await xT(c,s,e.budgets??{})}catch(h){s.errors.push({code:"export-error",message:iy(h)})}return o()}async function xT(r,e,t){let n=e.findings;r.updateWorldMatrix(!0,!0);for(let u of Sp())u.updateWorldMatrix(!0,!1);let i=[],s=[],o=0;r.traverse(u=>{let f=u;if(!f.isMesh)return;o++;let d=Vh(f);if(!d){n.push({severity:"error",code:"unbound-mesh",message:`Mesh "${f.name||"(unnamed)"}" was not made with createPart, so it has no slot. Use createPart(name, geometry, slot('key') | color('#rrggbb'), ...).`});return}let m=fT(f,d,n,s);m&&i.push(m)}),s.length&&n.push({severity:"info",code:"uv-generated",message:`${s.length} part(s) had no UVs and were box-projected: ${s.slice(0,10).join(", ")}${s.length>10?", ...":""}.`}),e.parts=i.map(u=>({name:u.info.name,slot:u.info.slot,...u.info.color!==void 0?{color:u.info.color}:{},triangles:u.indices.length/3,collision:u.info.collision,...u.info.walkable!==void 0?{walkable:u.info.walkable}:{},bounds:Q_(u.bounds)}));let a=[...new Set(i.map(u=>u.info.slot))].sort();e.slots=a;let l=new Ct;for(let u of i)l.union(u.bounds);if(i.length){let u=a.map((d,m)=>{let _=i.filter(E=>E.info.slot===d),g=ny(_),p=new Float32Array(g.positions.length),M=new Float32Array(g.positions.length/3*2),x=d===Uo?new Float32Array(g.positions.length):void 0,y=0;for(let E of _){if(p.set(E.normals,y*3),M.set(E.uvs,y*2),x){let S=L0(E.info.color);for(let R=0;Rd===Uo?{name:d,vertexColors:!0}:{name:d});e.glb=Bp({rootName:r.name,meshes:u,materials:f}),e.bounds=Q_(l)}else n.push({severity:"error",code:"empty-model",message:"The model has no parts with triangles."});let c=[];for(let u of i){let f=u.info.walkable===!0;if(u.info.collision==="box")c.push(ey(u.localBox,u.matrix,f));else if(u.info.collision==="mesh")c.push({positions:u.positions,indices:u.indices,walkable:f});else if(u.info.collision==="convex"){let d=[];for(let m=0;m({name:f.info.name,box:f.bounds})))){let f=u.parts.slice(0,8).join(", ")+(u.parts.length>8?", ...":"");n.push({severity:"warning",code:"floating-part",message:`${u.parts.length===1?"Part":`${u.parts.length} parts`} (${f}) ${u.parts.length===1?"is":"are"} not connected to the main body; nearest gap ${u.gap.toFixed(3)} m.`,part:u.parts[0]})}let h=i.reduce((u,f)=>u+f.indices.length/3,0);e.metrics.triangles=h,e.metrics.slots=a.length,e.metrics.parts=o,n.push(...X_(e.metrics,t)),i.length&&Math.abs(l.min.y)>W_&&n.push({severity:"warning",code:"model-not-grounded",message:`The model's lowest point is y = ${l.min.y.toFixed(3)} m; the origin is the base centre, so it should stand on y = 0.`})}var Vo="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",IA=(()=>{let r=new Int16Array(128).fill(-1);for(let e=0;e>18&63]+Vo[a>>12&63]+(n+1>6&63]:"=")+(n+2=8192&&(e.push(t),t="")}return e.push(t),e.join("")}function vT(r){let{glb:e,colliderGlb:t,...n}=r;return JSON.stringify({...n,...e?{glb:oy(e)}:{},...t?{colliderGlb:oy(t)}:{}})}var ay=null;function VA(r){return ay??=Jp({instantiateWasm(e,t){return WebAssembly.instantiate(r,e).then(n=>t(n,r)),{}}}).then(e=>(e.setup(),A_(e),e)),ay}export{iT as MODEL_RUNTIME_VERSION,vT as encodeBuildResult,nT as helpers,VA as initManifold,_T as loadFailure,yT as runModel,cT as startLoopGuard};