4310 lines
927 KiB
JavaScript
4310 lines
927 KiB
JavaScript
/*! NextFloor, MIT licence. Includes three.js (MIT) and Lit (BSD-3-Clause); see LICENSE and THIRD_PARTY_NOTICES.md */
|
|
var f0=1.3,d0=(i,e=new Date().toISOString().slice(0,10))=>!!i.due&&i.due<=e;var Ll={lawn:.012,terrace:.12,path:.02,driveway:.02,pool:-.25,bed:.15,wild:.03,hedge:1.2,fence:1,pergola:2.2};function Jr(i){return i==="hedge"||i==="fence"||i==="pergola"}function zh(i,e,t){let n=i.slope??0;if(!n||i.type==="pool")return 0;let r=i.slope_dir??"x",s=(c,u)=>r==="x"?c:r==="-x"?-c:r==="z"?u:-u,o=1/0,a=-1/0;for(let[c,u]of i.points){let h=s(c,u);o=Math.min(o,h),a=Math.max(a,h)}if(a-o<1e-6)return 0;let l=Math.min(1,Math.max(0,(s(e,t)-o)/(a-o)));return n*l}function t1(i,e,t,n){return Ko(i)+(e.offset??0)+Ll[e.type]-zh(e,t,n)}function Ko(i){return i.elevation>.3?0:-.2}function p0(i,e,t){let n=(i.outdoor??[]).filter(s=>!Jr(s.type)&&s.type!=="pool"&&Ve([e,t],s.points)),r=[...n].reverse().find(s=>s.cut)??n[0];return r?t1(i,r,e,t):Ko(i)}var m0=i=>i.cut??i.type==="pool";var n1={type:"none",pitch:35,overhang:.4},g0="#d6cfc2",Vh="#e8e3da",FP={wall_exterior:.24,wall_interior:.12,grid:.05,north:0,roof:{...n1}};var x0=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_uplight","lamp_table","lamp_wall","led_strip","lamp_bollard","lamp_garden"]),Fl=1.75;function b0(i){return x0.has(i)||!!vt(i)?.light}var i1=new Set(["table","table_round","coffee_table","desk","nightstand","sideboard","dresser","kitchen","island","worktop","tv_board","dishwasher","washer","dryer"]);function jr(i){switch(i.type){case"home_battery":return i.variant==="wall"?.5:0;case"kitchen_wall":return 1.45;case"tv_wall":return Math.max(0,1.3-i.h/2);case"radiator":return .12;case"inverter":return 1.1;case"wallbox":return 1;case"meter":return .4;default:return 0}}var y0=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan"]);function _0(i,e){return i.filter(t=>t.elevation<e.elevation).flatMap(t=>t.rooms.filter(n=>n.points.length>=3&&n.ceiling!=null&&n.ceiling>t.height+.005&&t.elevation+n.ceiling>e.elevation+.05)).map(t=>t.points)}var Qr=i=>i?.floor_offset&&Number.isFinite(i.floor_offset)?i.floor_offset:0;function v0(i,e,t){let n=i.rooms.find(r=>r.points.length>=3&&r.floor_offset&&Ve([e,t],r.points));return Qr(n)}function Gh(i,e,t){let n=i.rooms.find(r=>r.points.length>=3&&Ve([e,t],r.points));return n?.ceiling!=null&&n.ceiling>0?n.ceiling:i.height}var Ol=(i,e)=>e.ceiling_y!=null&&e.ceiling_y>0?e.ceiling_y:Gh(i,e.x,e.z);function M0(i,e,t){let n=0;for(let r of i.furniture)!(i1.has(r.type)||vt(r.type)?.surface)||!Ve([e,t],ts(r))||(n=Math.max(n,r.h));return n}var r1=new Set([...x0,"radiator","robot_vacuum","inverter","home_battery","wallbox","meter","tv_board","tv_wall","desk","fridge","fridge_smart","stove","kitchen_tall","dishwasher","washer","dryer","kitchen","island","sink"]);var s1=["interior","front","front_glass","sidelight","sidelights","glass","sliding","passage"],o1=["standard","bars","glass_wall"];function _r(i,e){return i.type==="door"?i.style&&s1.includes(i.style)?i.style:e?"front":"interior":i.style&&o1.includes(i.style)?i.style:"standard"}function S0(i,e,t,n){if(e!=="sidelight"&&e!=="sidelights")return null;let r=e==="sidelights",s=i-.04,o=Math.min(1.05,Math.max(.6,s-(r?.6:.3))),a=(s-o)/(r?2:1),l=n.sidelight_width??a,c=r?n.sidelight_width2??n.sidelight_width??a:0;l=Math.max(.1,l),c=r?Math.max(.1,c):0;let u=s-.5;if(l+c>u){let f=Math.max(0,u)/(l+c);l*=f,c*=f}return r?{panels:[[.02,.02+l],[i-.02-c,i-.02]],x0:.02+l,x1:i-.02-c}:(t?!!n.sidelight_hinge:!n.sidelight_hinge)?{panels:[[.02,.02+l]],x0:.02+l,x1:i-.02}:{panels:[[i-.02-l,i-.02]],x0:.02,x1:i-.02-l}}function w0(i){return i==="front"||i==="front_glass"||i==="sidelight"||i==="sidelights"}function es(i){let e=0;for(let t=0;t<i.length;t++){let[n,r]=i[t],[s,o]=i[(t+1)%i.length];e+=n*o-s*r}return e/2}function vr(i){return Math.abs(es(i))}function Bs(i){let e=es(i);if(Math.abs(e)<1e-9){let r=i.length||1;return[i.reduce((s,o)=>s+o[0],0)/r,i.reduce((s,o)=>s+o[1],0)/r]}let t=0,n=0;for(let r=0;r<i.length;r++){let[s,o]=i[r],[a,l]=i[(r+1)%i.length],c=s*l-a*o;t+=(s+a)*c,n+=(o+l)*c}return[t/(6*e),n/(6*e)]}function T0(i){if(i.length!==4)return!1;for(let e=0;e<4;e++){let[t,n]=i[e],[r,s]=i[(e+1)%4];if(Math.abs(t-r)>1e-6&&Math.abs(n-s)>1e-6)return!1}return!0}function A0(i){let e=1/0,t=1/0,n=-1/0,r=-1/0;for(let[s,o]of i)e=Math.min(e,s),t=Math.min(t,o),n=Math.max(n,s),r=Math.max(r,o);return{x0:e,z0:t,x1:n,z1:r}}function ts(i){let e=i.rotation*Math.PI/180,t=Math.cos(e),n=Math.sin(e),r=i.w/2,s=i.d/2;return[[-r,-s],[r,-s],[r,s],[-r,s]].map(([o,a])=>[i.x+o*t-a*n,i.z+o*n+a*t])}function Ve(i,e){let t=!1;for(let n=0,r=e.length-1;n<e.length;r=n++){let[s,o]=e[n],[a,l]=e[r];o>i[1]!=l>i[1]&&i[0]<(a-s)*(i[1]-o)/(l-o)+s&&(t=!t)}return t}var a1=[],Jo=new Map,l1=0,C0=(i,e)=>`pack:${i}:${e}`,c1=i=>i.startsWith("pack:");function Nl(i){a1=i,Jo=new Map;for(let e of i)for(let t of e.items)Jo.set(C0(e.id,t.id),t);l1+=1}var u1={};function vt(i){if(!c1(i))return;let e=Jo.get(i);if(e)return e;let[,t,...n]=i.split(":"),r=u1[t];return r?Jo.get(C0(r,n.join(":"))):void 0}var h1=.22;function E0(i,e,t,n){let r=Math.min(h1,t/3);if(n<=r*2.4||Math.abs(n-t)<1e-6)return e*(n/t)+(i-e)*(n/t);let s=e*(n/t),o=i-e;return o<=r?s+o:o>=t-r?s+n-(t-o):s+r+(o-r)*(n-2*r)/(t-2*r)}function Zo(i,e,t,n,r){return[E0(i*n,t*n,n,r)/r,E0(e*n,t*n,n,r)/r]}var R0=new WeakMap;function jo(i,e,t,n){let[r,s,o]=i.size;if(i.vehicle||i.stretch||Math.abs(e-r)<1e-4&&Math.abs(t-s)<1e-4&&Math.abs(n-o)<1e-4)return i.parts;let a=`${e.toFixed(4)}|${t.toFixed(4)}|${n.toFixed(4)}`,l=R0.get(i),c=l?.get(a);if(c)return c;let u=i.parts.map(h=>{if(h.shape==="sweep")return h;let[f,d]=Zo(h.x-h.w/2,h.x+h.w/2,-.5,r,e),[p,x]=Zo(h.z-h.d/2,h.z+h.d/2,-.5,s,t),[g,m]=Zo(h.y,h.y+h.h,0,o,n);if(h.rot)return{...h,x:(f+d)/2,z:(p+x)/2,w:h.w*r/e,d:h.d*s/t,y:g,h:m-g};let b={...h,x:(f+d)/2,z:(p+x)/2,w:d-f,d:x-p,y:g,h:m-g};if(h.shape==="loft"){let[v,y,M,S]=[h.tx??h.x,h.tz??h.z,h.tw??h.w,h.td??h.d],[_,w]=Zo(v-M/2,v+M/2,-.5,r,e),[R,A]=Zo(y-S/2,y+S/2,-.5,s,t);Object.assign(b,{tx:(_+w)/2,tz:(R+A)/2,tw:w-_,td:A-R})}return b});return l||R0.set(i,l=new Map),l.size>32&&l.clear(),l.set(a,u),u}var P0=i=>!!i?.parts.some(e=>e.move);function I0(i,e){if(e===null)return Math.min(1,Math.max(0,i.cover_rest??1));let t=Math.min(1,Math.max(0,e/100));return i.cover==="extends"?t:1-t}function L0(i,e){let t=[];for(let n of i){if(!n.move)continue;let r={...n},s=(o,a)=>a+(o-a)*e;if(n.move==="down"){let[o,a]=[s(n.y,1),s(n.y+n.h,1)];Object.assign(r,{y:o,h:a-o})}else if(n.move==="left"||n.move==="right"){let o=n.move==="left"?-.5:.5,[a,l]=[s(n.x-n.w/2,o),s(n.x+n.w/2,o)];if(Object.assign(r,{x:(a+l)/2,w:Math.abs(l-a)}),n.tx!==void 0||n.tw!==void 0){let[c,u]=[s((n.tx??n.x)-(n.tw??n.w)/2,o),s((n.tx??n.x)+(n.tw??n.w)/2,o)];Object.assign(r,{tx:(c+u)/2,tw:Math.abs(u-c)})}}else if(n.move==="out"){let[o,a]=[s(n.z-n.d/2,-.5),s(n.z+n.d/2,-.5)];if(Object.assign(r,{z:(o+a)/2,d:a-o}),n.tz!==void 0||n.td!==void 0){let[l,c]=[s((n.tz??n.z)-(n.td??n.d)/2,-.5),s((n.tz??n.z)+(n.td??n.d)/2,-.5)];Object.assign(r,{tz:(l+c)/2,td:c-l})}}else{let o=(1-e)*n.w*(n.move==="slide_left"?-1:1);Object.assign(r,{x:n.x+o,...n.tx!==void 0?{tx:n.tx+o}:{}})}r.w>.002&&r.d>.002&&r.h>.002&&t.push(r)}return t}function Gt(i,e){return e.mount_y!=null?e.mount_y:d1(i,e)+(f1(e)?0:v0(i,e.x,e.z))}var f1=i=>i.type==="led_strip"||vt(i.type)?.mount==="ceiling";function d1(i,e){if(e.type==="lamp_wall")return Fl;if(e.type==="led_strip")return Math.max(0,Gh(i,e.x,e.z)-.04-Math.max(.02,e.h));let t=vt(e.type);if(!t)return jr(e);switch(t.mount){case"surface":return M0(i,e.x,e.z);case"wall":return t.wall_y??1;case"ceiling":return Math.max(0,Ol(i,e)-e.h);default:return 0}}var F0=null,O0=new Set,N0=i=>{F0=i},D0=()=>F0,U0=i=>{O0.add(i)};function Dl(i){let e=Jo.get(i)?.mesh;return e!==void 0&&O0.has(e)}var Ig=0,If=1,Lg=2;var ka=1,Fg=2,bo=3,Ti=0,un=1,ut=2,ms=0,Ai=1,Ft=2,Lf=3,za=4,Og=5;var gs=100,Ng=101,Dg=102,Ug=103,Bg=104,kg=200,zg=201,Vg=202,Gg=203,Ff=204,Of=205,Hg=206,Wg=207,Xg=208,Yg=209,qg=210,$g=211,Kg=212,Zg=213,Jg=214,mc=0,gc=1,xc=2,ro=3,bc=4,yc=5,_c=6,vc=7,kc=0,jg=1,Qg=2,Ei=0,Nf=1,Df=2,Uf=3,Bf=4,kf=5,zf=6,Vf=7,mf="attached",ex="detached",Gf=300,xs=301,yo=302,zc=303,Vc=304,kn=1e3,ln=1001,Rr=1002,Ut=1003,_o=1004;var ar=1005;var Ht=1006,Dr=1007;var Fn=1008;var On=1009,Hf=1010,Wf=1011,vo=1012,Gc=1013,oi=1014,Vn=1015,ai=1016,Hc=1017,Wc=1018,bs=1020,Xf=35902,Yf=35899,qf=1021,$f=1022,Nn=1023,$i=1026,lr=1027,Xc=1028,Yc=1029,Ur=1030,qc=1031;var $c=1033,Va=33776,Ga=33777,Ha=33778,Wa=33779,Kc=35840,Zc=35841,Jc=35842,jc=35843,Qc=36196,eu=37492,tu=37496,nu=37488,iu=37489,Xa=37490,ru=37491,su=37808,ou=37809,au=37810,lu=37811,cu=37812,uu=37813,hu=37814,fu=37815,du=37816,pu=37817,mu=37818,gu=37819,xu=37820,bu=37821,yu=36492,_u=36494,vu=36495,Mu=36283,Su=36284,Ya=36285,wu=36286;var Ki=2300,Zi=2301,dc=2302,gf=2303,xf=2400,bf=2401,yf=2402,tx=2500;var Kf=0,qa=1,Mo=2,nx=3200;var $a=0,ix=1,li="",ft="srgb",Mn="srgb-linear",pa="linear",Mt="srgb";var pc=7680;var rx=519,sx=512,ox=513,ax=514,Zf=515,lx=516,cx=517,Jf=518,jf=519,Qf=35044,ed=35048;var td="300 es",$n=2e3,so=2001;function p1(i){for(let e=i.length-1;e>=0;--e)if(i[e]>=65535)return!0;return!1}function m1(i){return ArrayBuffer.isView(i)&&!(i instanceof DataView)}function oo(i){return document.createElementNS("http://www.w3.org/1999/xhtml",i)}function ux(){let i=oo("canvas");return i.style.display="block",i}var B0={},ao=null;function ma(...i){let e="THREE."+i.shift();ao?ao("log",e,...i):console.log(e,...i)}function hx(i){let e=i[0];if(typeof e=="string"&&e.startsWith("TSL:")){let t=i[1];t&&t.isStackTrace?i[0]+=" "+t.getLocation():i[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return i}function Le(...i){i=hx(i);let e="THREE."+i.shift();if(ao)ao("warn",e,...i);else{let t=i[0];t&&t.isStackTrace?console.warn(t.getError(e)):console.warn(e,...i)}}function Ge(...i){i=hx(i);let e="THREE."+i.shift();if(ao)ao("error",e,...i);else{let t=i[0];t&&t.isStackTrace?console.error(t.getError(e)):console.error(e,...i)}}function os(...i){let e=i.join(" ");e in B0||(B0[e]=!0,Le(...i))}function fx(i,e,t){return new Promise(function(n,r){function s(){switch(i.clientWaitSync(e,i.SYNC_FLUSH_COMMANDS_BIT,0)){case i.WAIT_FAILED:r();break;case i.TIMEOUT_EXPIRED:setTimeout(s,t);break;default:n()}}setTimeout(s,t)})}var dx={[mc]:mc,[xc]:_c,[bc]:bc,[ro]:yc,[gc]:gc,[_c]:xc,[vc]:vc,[yc]:ro},yi=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 r=n[e];if(r!==void 0){let s=r.indexOf(t);s!==-1&&r.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 r=n.slice(0);for(let s=0,o=r.length;s<o;s++)r[s].call(this,e);e.target=null}}},dn=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"],k0=1234567,fa=Math.PI/180,as=180/Math.PI;function Ri(){let i=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,n=Math.random()*4294967295|0;return(dn[i&255]+dn[i>>8&255]+dn[i>>16&255]+dn[i>>24&255]+"-"+dn[e&255]+dn[e>>8&255]+"-"+dn[e>>16&15|64]+dn[e>>24&255]+"-"+dn[t&63|128]+dn[t>>8&255]+"-"+dn[t>>16&255]+dn[t>>24&255]+dn[n&255]+dn[n>>8&255]+dn[n>>16&255]+dn[n>>24&255]).toLowerCase()}function it(i,e,t){return Math.max(e,Math.min(t,i))}function nd(i,e){return(i%e+e)%e}function g1(i,e,t,n,r){return n+(i-e)*(r-n)/(t-e)}function x1(i,e,t){return i!==e?(t-i)/(e-i):0}function da(i,e,t){return(1-t)*i+t*e}function b1(i,e,t,n){return da(i,e,1-Math.exp(-t*n))}function y1(i,e=1){return e-Math.abs(nd(i,e*2)-e)}function _1(i,e,t){return i<=e?0:i>=t?1:(i=(i-e)/(t-e),i*i*(3-2*i))}function v1(i,e,t){return i<=e?0:i>=t?1:(i=(i-e)/(t-e),i*i*i*(i*(i*6-15)+10))}function M1(i,e){return i+Math.floor(Math.random()*(e-i+1))}function S1(i,e){return i+Math.random()*(e-i)}function w1(i){return i*(.5-Math.random())}function T1(i){i!==void 0&&(k0=i);let e=k0+=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 A1(i){return i*fa}function E1(i){return i*as}function R1(i){return i>0&&Number.isInteger(i)&&2**Math.round(Math.log2(i))===i}function C1(i){return Math.pow(2,Math.ceil(Math.log(i)/Math.LN2))}function id(i){return Math.pow(2,Math.floor(Math.log(i)/Math.LN2))}function P1(i,e,t,n,r){let s=Math.cos,o=Math.sin,a=s(t/2),l=o(t/2),c=s((e+n)/2),u=o((e+n)/2),h=s((e-n)/2),f=o((e-n)/2),d=s((n-e)/2),p=o((n-e)/2);switch(r){case"XYX":i.set(a*u,l*h,l*f,a*c);break;case"YZY":i.set(l*f,a*u,l*h,a*c);break;case"ZXZ":i.set(l*h,l*f,a*u,a*c);break;case"XZX":i.set(a*u,l*p,l*d,a*c);break;case"YXY":i.set(l*d,a*u,l*p,a*c);break;case"ZYZ":i.set(l*p,l*d,a*u,a*c);break;default:Le("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}}function Tu(i){switch(i.constructor){case Uint32Array:return 4294967295;case Uint16Array:return 65535;case Uint8Array:case Uint8ClampedArray:return 255;case Int32Array:return 2147483647;case Int16Array:return 32767;case Int8Array:return 127;default:return}}function rd(i,e){if(e.constructor===Float32Array)return i;let t=Tu(e);if(t===void 0)throw new Error("THREE.MathUtils: Invalid component type.");return Math.max(i/t,-1)}function sd(i,e){if(e.constructor===Float32Array)return i;let t=Tu(e);if(t===void 0)throw new Error("THREE.MathUtils: Invalid component type.");return Math.round(i*t)}var Br={DEG2RAD:fa,RAD2DEG:as,generateUUID:Ri,clamp:it,euclideanModulo:nd,mapLinear:g1,inverseLerp:x1,lerp:da,damp:b1,pingpong:y1,smoothstep:_1,smootherstep:v1,randInt:M1,randFloat:S1,randFloatSpread:w1,seededRandom:T1,degToRad:A1,radToDeg:E1,isPowerOfTwo:R1,ceilPowerOfTwo:C1,floorPowerOfTwo:id,setQuaternionFromProperEuler:P1,normalize:sd,denormalize:rd},ud=class ud{constructor(e=0,t=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("THREE.Vector2: 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("THREE.Vector2: 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,r=e.elements;return this.x=r[0]*t+r[3]*n+r[6],this.y=r[1]*t+r[4]*n+r[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=it(this.x,e.x,t.x),this.y=it(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=it(this.x,e,t),this.y=it(this.y,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(it(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(it(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),r=Math.sin(t),s=this.x-e.x,o=this.y-e.y;return this.x=s*n-o*r+e.x,this.y=s*r+o*n+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}};ud.prototype.isVector2=!0;var De=ud,Sn=class{constructor(e=0,t=0,n=0,r=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=n,this._w=r}static slerpFlat(e,t,n,r,s,o,a){let l=n[r+0],c=n[r+1],u=n[r+2],h=n[r+3],f=s[o+0],d=s[o+1],p=s[o+2],x=s[o+3];if(h!==x||l!==f||c!==d||u!==p){let g=l*f+c*d+u*p+h*x;g<0&&(f=-f,d=-d,p=-p,x=-x,g=-g);let m=1-a;if(g<.9995){let b=Math.acos(g),v=Math.sin(b);m=Math.sin(m*b)/v,a=Math.sin(a*b)/v,l=l*m+f*a,c=c*m+d*a,u=u*m+p*a,h=h*m+x*a}else{l=l*m+f*a,c=c*m+d*a,u=u*m+p*a,h=h*m+x*a;let b=1/Math.sqrt(l*l+c*c+u*u+h*h);l*=b,c*=b,u*=b,h*=b}}e[t]=l,e[t+1]=c,e[t+2]=u,e[t+3]=h}static multiplyQuaternionsFlat(e,t,n,r,s,o){let a=n[r],l=n[r+1],c=n[r+2],u=n[r+3],h=s[o],f=s[o+1],d=s[o+2],p=s[o+3];return e[t]=a*p+u*h+l*d-c*f,e[t+1]=l*p+u*f+c*h-a*d,e[t+2]=c*p+u*d+a*f-l*h,e[t+3]=u*p-a*h-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,r){return this._x=e,this._y=t,this._z=n,this._w=r,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,r=e._y,s=e._z,o=e._order,a=Math.cos,l=Math.sin,c=a(n/2),u=a(r/2),h=a(s/2),f=l(n/2),d=l(r/2),p=l(s/2);switch(o){case"XYZ":this._x=f*u*h+c*d*p,this._y=c*d*h-f*u*p,this._z=c*u*p+f*d*h,this._w=c*u*h-f*d*p;break;case"YXZ":this._x=f*u*h+c*d*p,this._y=c*d*h-f*u*p,this._z=c*u*p-f*d*h,this._w=c*u*h+f*d*p;break;case"ZXY":this._x=f*u*h-c*d*p,this._y=c*d*h+f*u*p,this._z=c*u*p+f*d*h,this._w=c*u*h-f*d*p;break;case"ZYX":this._x=f*u*h-c*d*p,this._y=c*d*h+f*u*p,this._z=c*u*p-f*d*h,this._w=c*u*h+f*d*p;break;case"YZX":this._x=f*u*h+c*d*p,this._y=c*d*h+f*u*p,this._z=c*u*p-f*d*h,this._w=c*u*h-f*d*p;break;case"XZY":this._x=f*u*h-c*d*p,this._y=c*d*h-f*u*p,this._z=c*u*p+f*d*h,this._w=c*u*h+f*d*p;break;default:Le("Quaternion: .setFromEuler() encountered an unknown order: "+o)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){let n=t/2,r=Math.sin(n);return this._x=e.x*r,this._y=e.y*r,this._z=e.z*r,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(e){let t=e.elements,n=t[0],r=t[4],s=t[8],o=t[1],a=t[5],l=t[9],c=t[2],u=t[6],h=t[10],f=n+a+h;if(f>0){let d=.5/Math.sqrt(f+1);this._w=.25/d,this._x=(u-l)*d,this._y=(s-c)*d,this._z=(o-r)*d}else if(n>a&&n>h){let d=2*Math.sqrt(1+n-a-h);this._w=(u-l)/d,this._x=.25*d,this._y=(r+o)/d,this._z=(s+c)/d}else if(a>h){let d=2*Math.sqrt(1+a-n-h);this._w=(s-c)/d,this._x=(r+o)/d,this._y=.25*d,this._z=(l+u)/d}else{let d=2*Math.sqrt(1+h-n-a);this._w=(o-r)/d,this._x=(s+c)/d,this._y=(l+u)/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(it(this.dot(e),-1,1)))}rotateTowards(e,t){let n=this.angleTo(e);if(n===0)return this;let r=Math.min(1,t/n);return this.slerp(e,r),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,r=e._y,s=e._z,o=e._w,a=t._x,l=t._y,c=t._z,u=t._w;return this._x=n*u+o*a+r*c-s*l,this._y=r*u+o*l+s*a-n*c,this._z=s*u+o*c+n*l-r*a,this._w=o*u-n*a-r*l-s*c,this._onChangeCallback(),this}slerp(e,t){let n=e._x,r=e._y,s=e._z,o=e._w,a=this.dot(e);a<0&&(n=-n,r=-r,s=-s,o=-o,a=-a);let l=1-t;if(a<.9995){let c=Math.acos(a),u=Math.sin(c);l=Math.sin(l*c)/u,t=Math.sin(t*c)/u,this._x=this._x*l+n*t,this._y=this._y*l+r*t,this._z=this._z*l+s*t,this._w=this._w*l+o*t,this._onChangeCallback()}else this._x=this._x*l+n*t,this._y=this._y*l+r*t,this._z=this._z*l+s*t,this._w=this._w*l+o*t,this.normalize();return 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(),r=Math.sqrt(1-n),s=Math.sqrt(n);return this.set(r*Math.sin(e),r*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}},hd=class hd{constructor(e=0,t=0,n=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("THREE.Vector3: 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("THREE.Vector3: 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(z0.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(z0.setFromAxisAngle(e,t))}applyMatrix3(e){let t=this.x,n=this.y,r=this.z,s=e.elements;return this.x=s[0]*t+s[3]*n+s[6]*r,this.y=s[1]*t+s[4]*n+s[7]*r,this.z=s[2]*t+s[5]*n+s[8]*r,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){let t=this.x,n=this.y,r=this.z,s=e.elements,o=1/(s[3]*t+s[7]*n+s[11]*r+s[15]);return this.x=(s[0]*t+s[4]*n+s[8]*r+s[12])*o,this.y=(s[1]*t+s[5]*n+s[9]*r+s[13])*o,this.z=(s[2]*t+s[6]*n+s[10]*r+s[14])*o,this}applyQuaternion(e){let t=this.x,n=this.y,r=this.z,s=e.x,o=e.y,a=e.z,l=e.w,c=2*(o*r-a*n),u=2*(a*t-s*r),h=2*(s*n-o*t);return this.x=t+l*c+o*h-a*u,this.y=n+l*u+a*c-s*h,this.z=r+l*h+s*u-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,r=this.z,s=e.elements;return this.x=s[0]*t+s[4]*n+s[8]*r,this.y=s[1]*t+s[5]*n+s[9]*r,this.z=s[2]*t+s[6]*n+s[10]*r,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=it(this.x,e.x,t.x),this.y=it(this.y,e.y,t.y),this.z=it(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=it(this.x,e,t),this.y=it(this.y,e,t),this.z=it(this.z,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(it(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,r=e.y,s=e.z,o=t.x,a=t.y,l=t.z;return this.x=r*l-s*a,this.y=s*o-n*l,this.z=n*a-r*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 Hh.copy(this).projectOnVector(e),this.sub(Hh)}reflect(e){return this.sub(Hh.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(it(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,n=this.y-e.y,r=this.z-e.z;return t*t+n*n+r*r}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 r=Math.sin(t)*e;return this.x=r*Math.sin(n),this.y=Math.cos(t)*e,this.z=r*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(),r=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=n,this.z=r,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}};hd.prototype.isVector3=!0;var U=hd,Hh=new U,z0=new Sn,fd=class fd{constructor(e,t,n,r,s,o,a,l,c){this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,n,r,s,o,a,l,c)}set(e,t,n,r,s,o,a,l,c){let u=this.elements;return u[0]=e,u[1]=r,u[2]=a,u[3]=t,u[4]=s,u[5]=l,u[6]=n,u[7]=o,u[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,r=t.elements,s=this.elements,o=n[0],a=n[3],l=n[6],c=n[1],u=n[4],h=n[7],f=n[2],d=n[5],p=n[8],x=r[0],g=r[3],m=r[6],b=r[1],v=r[4],y=r[7],M=r[2],S=r[5],_=r[8];return s[0]=o*x+a*b+l*M,s[3]=o*g+a*v+l*S,s[6]=o*m+a*y+l*_,s[1]=c*x+u*b+h*M,s[4]=c*g+u*v+h*S,s[7]=c*m+u*y+h*_,s[2]=f*x+d*b+p*M,s[5]=f*g+d*v+p*S,s[8]=f*m+d*y+p*_,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],r=e[2],s=e[3],o=e[4],a=e[5],l=e[6],c=e[7],u=e[8];return t*o*u-t*a*c-n*s*u+n*a*l+r*s*c-r*o*l}invert(){let e=this.elements,t=e[0],n=e[1],r=e[2],s=e[3],o=e[4],a=e[5],l=e[6],c=e[7],u=e[8],h=u*o-a*c,f=a*l-u*s,d=c*s-o*l,p=t*h+n*f+r*d;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);let x=1/p;return e[0]=h*x,e[1]=(r*c-u*n)*x,e[2]=(a*n-r*o)*x,e[3]=f*x,e[4]=(u*t-r*l)*x,e[5]=(r*s-a*t)*x,e[6]=d*x,e[7]=(n*l-c*t)*x,e[8]=(o*t-n*s)*x,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,r,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,-r*c,r*l,-r*(-c*o+l*a)+a+t,0,0,1),this}scale(e,t){return os("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(Wh.makeScale(e,t)),this}rotate(e){return os("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(Wh.makeRotation(-e)),this}translate(e,t){return os("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(Wh.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 r=0;r<9;r++)if(t[r]!==n[r])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)}};fd.prototype.isMatrix3=!0;var He=fd,Wh=new He,V0=new He().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),G0=new He().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function I1(){let i={enabled:!0,workingColorSpace:Mn,spaces:{},convert:function(r,s,o){return this.enabled===!1||s===o||!s||!o||(this.spaces[s].transfer===Mt&&(r.r=qi(r.r),r.g=qi(r.g),r.b=qi(r.b)),this.spaces[s].primaries!==this.spaces[o].primaries&&(r.applyMatrix3(this.spaces[s].toXYZ),r.applyMatrix3(this.spaces[o].fromXYZ)),this.spaces[o].transfer===Mt&&(r.r=io(r.r),r.g=io(r.g),r.b=io(r.b))),r},workingToColorSpace:function(r,s){return this.convert(r,this.workingColorSpace,s)},colorSpaceToWorking:function(r,s){return this.convert(r,s,this.workingColorSpace)},getPrimaries:function(r){return this.spaces[r].primaries},getTransfer:function(r){return r===li?pa:this.spaces[r].transfer},getToneMappingMode:function(r){return this.spaces[r].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(r,s=this.workingColorSpace){return r.fromArray(this.spaces[s].luminanceCoefficients)},define:function(r){Object.assign(this.spaces,r)},_getMatrix:function(r,s,o){return r.copy(this.spaces[o].fromXYZ).multiply(this.spaces[s].toXYZ)},_getDrawingBufferColorSpace:function(r){return this.spaces[r].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(r=this.workingColorSpace){return this.spaces[r].workingColorSpaceConfig.unpackColorSpace}},e=[.64,.33,.3,.6,.15,.06],t=[.2126,.7152,.0722],n=[.3127,.329];return i.define({[Mn]:{primaries:e,whitePoint:n,transfer:pa,toXYZ:V0,fromXYZ:G0,luminanceCoefficients:t,workingColorSpaceConfig:{unpackColorSpace:ft},outputColorSpaceConfig:{drawingBufferColorSpace:ft}},[ft]:{primaries:e,whitePoint:n,transfer:Mt,toXYZ:V0,fromXYZ:G0,luminanceCoefficients:t,outputColorSpaceConfig:{drawingBufferColorSpace:ft}}}),i}var tt=I1();function qi(i){return i<.04045?i*.0773993808:Math.pow(i*.9478672986+.0521327014,2.4)}function io(i){return i<.0031308?i*12.92:1.055*Math.pow(i,.41666)-.055}var ks,lo=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{ks===void 0&&(ks=oo("canvas")),ks.width=e.width,ks.height=e.height;let r=ks.getContext("2d");e instanceof ImageData?r.putImageData(e,0,0):r.drawImage(e,0,0,e.width,e.height),n=ks}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=oo("canvas");t.width=e.width,t.height=e.height;let n=t.getContext("2d");n.drawImage(e,0,0,e.width,e.height);let r=n.getImageData(0,0,e.width,e.height),s=r.data;for(let o=0;o<s.length;o++)s[o]=qi(s[o]/255)*255;return n.putImageData(r,0,0),t}else if(e.data){let t=e.data.slice(0);for(let n=0;n<t.length;n++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[n]=Math.floor(qi(t[n]/255)*255):t[n]=qi(t[n]);return{data:t,width:e.width,height:e.height}}else return Le("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),e}},L1=0,Ji=class{constructor(e=null){this.isTextureSource=!0,Object.defineProperty(this,"id",{value:L1++}),this.uuid=Ri(),this.data=e,this.dataReady=!0,this.version=0}getSize(e){let t=this.data;return typeof HTMLVideoElement<"u"&&t instanceof HTMLVideoElement?e.set(t.videoWidth,t.videoHeight,0):typeof VideoFrame<"u"&&t instanceof VideoFrame?e.set(t.displayWidth,t.displayHeight,0):t!==null?e.set(t.width||0,t.height||0,t.depth||0):e.set(0,0,0),e}set needsUpdate(e){e===!0&&this.version++}toJSON(e){let t=e===void 0||typeof e=="string";if(!t&&e.images[this.uuid]!==void 0)return e.images[this.uuid];let n={uuid:this.uuid,url:""},r=this.data;if(r!==null){let s;if(Array.isArray(r)){s=[];for(let o=0,a=r.length;o<a;o++)r[o].isDataTexture?s.push(Xh(r[o].image)):s.push(Xh(r[o]))}else s=Xh(r);n.url=s}return t||(e.images[this.uuid]=n),n}};function Xh(i){return typeof HTMLImageElement<"u"&&i instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&i instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&i instanceof ImageBitmap?lo.getDataURL(i):i.data?{data:Array.from(i.data),width:i.width,height:i.height,type:i.data.constructor.name}:(Le("Texture: Unable to serialize Texture."),{})}var F1=0,Yh=new U,Kt=class i extends yi{constructor(e=i.DEFAULT_IMAGE,t=i.DEFAULT_MAPPING,n=ln,r=ln,s=Ht,o=Fn,a=Nn,l=On,c=i.DEFAULT_ANISOTROPY,u=li){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:F1++}),this.uuid=Ri(),this.name="",this.source=new Ji(e),this.mipmaps=[],this.mapping=t,this.channel=0,this.wrapS=n,this.wrapT=r,this.magFilter=s,this.minFilter=o,this.anisotropy=c,this.format=a,this.internalFormat=null,this.type=l,this.offset=new De(0,0),this.repeat=new De(1,1),this.center=new De(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new He,this.generateMipmaps=!0,this.mipmapsAutoUpdate=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=u,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(e&&e.depth&&e.depth>1),this.pmremVersion=0,this.isPMREMTexture=!1,this.normalized=!1}get width(){return this.source.getSize(Yh).x}get height(){return this.source.getSize(Yh).y}get depth(){return this.source.getSize(Yh).z}get image(){return this.source.data}set image(e){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.normalized=e.normalized,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.mipmapsAutoUpdate=e.mipmapsAutoUpdate,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.isPMREMTexture=e.isPMREMTexture,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){Le(`Texture.setValues(): parameter '${t}' has value of undefined.`);continue}let r=this[t];if(r===void 0){Le(`Texture.setValues(): property '${t}' does not exist.`);continue}r&&n&&r.isVector2&&n.isVector2||r&&n&&r.isVector3&&n.isVector3||r&&n&&r.isMatrix3&&n.isMatrix3?r.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,normalized:this.normalized,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,mipmapsAutoUpdate:this.mipmapsAutoUpdate,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!==Gf)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case kn:e.x=e.x-Math.floor(e.x);break;case ln:e.x=e.x<0?0:1;break;case Rr: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 kn:e.y=e.y-Math.floor(e.y);break;case ln:e.y=e.y<0?0:1;break;case Rr: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=Gf;Kt.DEFAULT_ANISOTROPY=1;var dd=class dd{constructor(e=0,t=0,n=0,r=1){this.x=e,this.y=t,this.z=n,this.w=r}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,r){return this.x=e,this.y=t,this.z=n,this.w=r,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("THREE.Vector4: 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("THREE.Vector4: 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,r=this.z,s=this.w,o=e.elements;return this.x=o[0]*t+o[4]*n+o[8]*r+o[12]*s,this.y=o[1]*t+o[5]*n+o[9]*r+o[13]*s,this.z=o[2]*t+o[6]*n+o[10]*r+o[14]*s,this.w=o[3]*t+o[7]*n+o[11]*r+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,r,s,l=e.elements,c=l[0],u=l[4],h=l[8],f=l[1],d=l[5],p=l[9],x=l[2],g=l[6],m=l[10];if(Math.abs(u-f)<.01&&Math.abs(h-x)<.01&&Math.abs(p-g)<.01){if(Math.abs(u+f)<.1&&Math.abs(h+x)<.1&&Math.abs(p+g)<.1&&Math.abs(c+d+m-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;let v=(c+1)/2,y=(d+1)/2,M=(m+1)/2,S=(u+f)/4,_=(h+x)/4,w=(p+g)/4;return v>y&&v>M?v<.01?(n=0,r=.707106781,s=.707106781):(n=Math.sqrt(v),r=S/n,s=_/n):y>M?y<.01?(n=.707106781,r=0,s=.707106781):(r=Math.sqrt(y),n=S/r,s=w/r):M<.01?(n=.707106781,r=.707106781,s=0):(s=Math.sqrt(M),n=_/s,r=w/s),this.set(n,r,s,t),this}let b=Math.sqrt((g-p)*(g-p)+(h-x)*(h-x)+(f-u)*(f-u));return Math.abs(b)<.001&&(b=1),this.x=(g-p)/b,this.y=(h-x)/b,this.z=(f-u)/b,this.w=Math.acos((c+d+m-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=it(this.x,e.x,t.x),this.y=it(this.y,e.y,t.y),this.z=it(this.z,e.z,t.z),this.w=it(this.w,e.w,t.w),this}clampScalar(e,t){return this.x=it(this.x,e,t),this.y=it(this.y,e,t),this.z=it(this.z,e,t),this.w=it(this.w,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(it(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}};dd.prototype.isVector4=!0;var _t=dd,Mc=class extends yi{constructor(e=1,t=1,n={}){super(),n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:Ht,depthBuffer:!0,stencilBuffer:!1,resolveColorBuffer:!0,resolveDepthBuffer:!0,resolveStencilBuffer:!0,storeMultisampledColorBuffer:!0,storeMultisampledDepthBuffer:!0,storeMultisampledStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1,useArrayDepthTexture:!1},n),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=n.depth,this.scissor=new _t(0,0,e,t),this.scissorTest=!1,this.viewport=new _t(0,0,e,t),this.textures=[];let r=n.count;for(let s=0;s<r;s++)this.textures[s]=new Kt({width:e,height:t,depth:n.depth}),this.textures[s].isRenderTargetTexture=!0,this.textures[s].renderTarget=this;this._setTextureOptions(n),this.depthBuffer=n.depthBuffer,this.stencilBuffer=n.stencilBuffer,this.resolveColorBuffer=n.resolveColorBuffer,this.resolveDepthBuffer=n.resolveDepthBuffer,this.resolveStencilBuffer=n.resolveStencilBuffer,this.storeMultisampledColorBuffer=n.storeMultisampledColorBuffer,this.storeMultisampledDepthBuffer=n.storeMultisampledDepthBuffer,this.storeMultisampledStencilBuffer=n.storeMultisampledStencilBuffer,this._depthTexture=null,this.depthTexture=n.depthTexture,this.samples=n.samples,this.multiview=n.multiview,this.useArrayDepthTexture=n.useArrayDepthTexture}_setTextureOptions(e={}){let t={minFilter:Ht,generateMipmaps:!1,flipY:!1,internalFormat:null};e.mapping!==void 0&&(t.mapping=e.mapping),e.wrapS!==void 0&&(t.wrapS=e.wrapS),e.wrapT!==void 0&&(t.wrapT=e.wrapT),e.wrapR!==void 0&&(t.wrapR=e.wrapR),e.magFilter!==void 0&&(t.magFilter=e.magFilter),e.minFilter!==void 0&&(t.minFilter=e.minFilter),e.format!==void 0&&(t.format=e.format),e.type!==void 0&&(t.type=e.type),e.anisotropy!==void 0&&(t.anisotropy=e.anisotropy),e.colorSpace!==void 0&&(t.colorSpace=e.colorSpace),e.flipY!==void 0&&(t.flipY=e.flipY),e.generateMipmaps!==void 0&&(t.generateMipmaps=e.generateMipmaps),e.mipmapsAutoUpdate!==void 0&&(t.mipmapsAutoUpdate=e.mipmapsAutoUpdate),e.internalFormat!==void 0&&(t.internalFormat=e.internalFormat);for(let n=0;n<this.textures.length;n++)this.textures[n].setValues(t)}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}set depthTexture(e){this._depthTexture!==null&&this._depthTexture.renderTarget===this&&(this._depthTexture.renderTarget=null),e!==null&&e.renderTarget===null&&(e.renderTarget=this),this._depthTexture=e}get depthTexture(){return this._depthTexture}setSize(e,t,n=1){if(this.width!==e||this.height!==t||this.depth!==n){this.width=e,this.height=t,this.depth=n;for(let r=0,s=this.textures.length;r<s;r++)this.textures[r].image.width=e,this.textures[r].image.height=t,this.textures[r].image.depth=n,this.textures[r].isData3DTexture!==!0&&(this.textures[r].isArrayTexture=this.textures[r].image.depth>1);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<n;t++){this.textures[t]=e.textures[t].clone(),this.textures[t].isRenderTargetTexture=!0,this.textures[t].renderTarget=this;let r=Object.assign({},e.textures[t].image);this.textures[t].source=new Ji(r)}if(this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveColorBuffer=e.resolveColorBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,this.storeMultisampledColorBuffer=e.storeMultisampledColorBuffer,this.storeMultisampledDepthBuffer=e.storeMultisampledDepthBuffer,this.storeMultisampledStencilBuffer=e.storeMultisampledStencilBuffer,e.depthTexture!==null)if(e.depthTexture.renderTarget===e){let t=e.depthTexture.clone();t.renderTarget=null,this.depthTexture=t}else this.depthTexture=e.depthTexture;else this.depthTexture=null;return this.samples=e.samples,this.multiview=e.multiview,this.useArrayDepthTexture=e.useArrayDepthTexture,this}dispose(){this.dispatchEvent({type:"dispose"})}},wn=class extends Mc{constructor(e=1,t=1,n={}){super(e,t,n),this.isWebGLRenderTarget=!0}},ga=class extends Kt{constructor(e=null,t=1,n=1,r=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:n,depth:r},this.magFilter=Ut,this.minFilter=Ut,this.wrapR=ln,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}copy(e){return super.copy(e),this.wrapR=e.wrapR,this}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}};var Sc=class extends Kt{constructor(e=null,t=1,n=1,r=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:n,depth:r},this.magFilter=Ut,this.minFilter=Ut,this.wrapR=ln,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}copy(e){return super.copy(e),this.wrapR=e.wrapR,this}};var Bc=class Bc{constructor(e,t,n,r,s,o,a,l,c,u,h,f,d,p,x,g){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,r,s,o,a,l,c,u,h,f,d,p,x,g)}set(e,t,n,r,s,o,a,l,c,u,h,f,d,p,x,g){let m=this.elements;return m[0]=e,m[4]=t,m[8]=n,m[12]=r,m[1]=s,m[5]=o,m[9]=a,m[13]=l,m[2]=c,m[6]=u,m[10]=h,m[14]=f,m[3]=d,m[7]=p,m[11]=x,m[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 Bc().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 this.determinantAffine()===0?(e.set(1,0,0),t.set(0,1,0),n.set(0,0,1),this):(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){if(e.determinantAffine()===0)return this.identity();let t=this.elements,n=e.elements,r=1/zs.setFromMatrixColumn(e,0).length(),s=1/zs.setFromMatrixColumn(e,1).length(),o=1/zs.setFromMatrixColumn(e,2).length();return t[0]=n[0]*r,t[1]=n[1]*r,t[2]=n[2]*r,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,r=e.y,s=e.z,o=Math.cos(n),a=Math.sin(n),l=Math.cos(r),c=Math.sin(r),u=Math.cos(s),h=Math.sin(s);if(e.order==="XYZ"){let f=o*u,d=o*h,p=a*u,x=a*h;t[0]=l*u,t[4]=-l*h,t[8]=c,t[1]=d+p*c,t[5]=f-x*c,t[9]=-a*l,t[2]=x-f*c,t[6]=p+d*c,t[10]=o*l}else if(e.order==="YXZ"){let f=l*u,d=l*h,p=c*u,x=c*h;t[0]=f+x*a,t[4]=p*a-d,t[8]=o*c,t[1]=o*h,t[5]=o*u,t[9]=-a,t[2]=d*a-p,t[6]=x+f*a,t[10]=o*l}else if(e.order==="ZXY"){let f=l*u,d=l*h,p=c*u,x=c*h;t[0]=f-x*a,t[4]=-o*h,t[8]=p+d*a,t[1]=d+p*a,t[5]=o*u,t[9]=x-f*a,t[2]=-o*c,t[6]=a,t[10]=o*l}else if(e.order==="ZYX"){let f=o*u,d=o*h,p=a*u,x=a*h;t[0]=l*u,t[4]=p*c-d,t[8]=f*c+x,t[1]=l*h,t[5]=x*c+f,t[9]=d*c-p,t[2]=-c,t[6]=a*l,t[10]=o*l}else if(e.order==="YZX"){let f=o*l,d=o*c,p=a*l,x=a*c;t[0]=l*u,t[4]=x-f*h,t[8]=p*h+d,t[1]=h,t[5]=o*u,t[9]=-a*u,t[2]=-c*u,t[6]=d*h+p,t[10]=f-x*h}else if(e.order==="XZY"){let f=o*l,d=o*c,p=a*l,x=a*c;t[0]=l*u,t[4]=-h,t[8]=c*u,t[1]=f*h+x,t[5]=o*u,t[9]=d*h-p,t[2]=p*h-d,t[6]=a*u,t[10]=x*h+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(O1,e,N1)}lookAt(e,t,n){let r=this.elements;return Un.subVectors(e,t),Un.lengthSq()===0&&(Un.z=1),Un.normalize(),Mr.crossVectors(n,Un),Mr.lengthSq()===0&&(Math.abs(n.z)===1?Un.x+=1e-4:Un.z+=1e-4,Un.normalize(),Mr.crossVectors(n,Un)),Mr.normalize(),Ul.crossVectors(Un,Mr),r[0]=Mr.x,r[4]=Ul.x,r[8]=Un.x,r[1]=Mr.y,r[5]=Ul.y,r[9]=Un.y,r[2]=Mr.z,r[6]=Ul.z,r[10]=Un.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let n=e.elements,r=t.elements,s=this.elements,o=n[0],a=n[4],l=n[8],c=n[12],u=n[1],h=n[5],f=n[9],d=n[13],p=n[2],x=n[6],g=n[10],m=n[14],b=n[3],v=n[7],y=n[11],M=n[15],S=r[0],_=r[4],w=r[8],R=r[12],A=r[1],C=r[5],O=r[9],D=r[13],P=r[2],I=r[6],N=r[10],F=r[14],H=r[3],B=r[7],X=r[11],V=r[15];return s[0]=o*S+a*A+l*P+c*H,s[4]=o*_+a*C+l*I+c*B,s[8]=o*w+a*O+l*N+c*X,s[12]=o*R+a*D+l*F+c*V,s[1]=u*S+h*A+f*P+d*H,s[5]=u*_+h*C+f*I+d*B,s[9]=u*w+h*O+f*N+d*X,s[13]=u*R+h*D+f*F+d*V,s[2]=p*S+x*A+g*P+m*H,s[6]=p*_+x*C+g*I+m*B,s[10]=p*w+x*O+g*N+m*X,s[14]=p*R+x*D+g*F+m*V,s[3]=b*S+v*A+y*P+M*H,s[7]=b*_+v*C+y*I+M*B,s[11]=b*w+v*O+y*N+M*X,s[15]=b*R+v*D+y*F+M*V,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],r=e[8],s=e[12],o=e[1],a=e[5],l=e[9],c=e[13],u=e[2],h=e[6],f=e[10],d=e[14],p=e[3],x=e[7],g=e[11],m=e[15],b=l*d-c*f,v=a*d-c*h,y=a*f-l*h,M=o*d-c*u,S=o*f-l*u,_=o*h-a*u;return t*(x*b-g*v+m*y)-n*(p*b-g*M+m*S)+r*(p*v-x*M+m*_)-s*(p*y-x*S+g*_)}determinantAffine(){let e=this.elements,t=e[0],n=e[4],r=e[8],s=e[1],o=e[5],a=e[9],l=e[2],c=e[6],u=e[10];return t*(o*u-a*c)-n*(s*u-a*l)+r*(s*c-o*l)}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 r=this.elements;return e.isVector3?(r[12]=e.x,r[13]=e.y,r[14]=e.z):(r[12]=e,r[13]=t,r[14]=n),this}invert(){let e=this.elements,t=e[0],n=e[1],r=e[2],s=e[3],o=e[4],a=e[5],l=e[6],c=e[7],u=e[8],h=e[9],f=e[10],d=e[11],p=e[12],x=e[13],g=e[14],m=e[15],b=t*a-n*o,v=t*l-r*o,y=t*c-s*o,M=n*l-r*a,S=n*c-s*a,_=r*c-s*l,w=u*x-h*p,R=u*g-f*p,A=u*m-d*p,C=h*g-f*x,O=h*m-d*x,D=f*m-d*g,P=b*D-v*O+y*C+M*A-S*R+_*w;if(P===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);let I=1/P;return e[0]=(a*D-l*O+c*C)*I,e[1]=(r*O-n*D-s*C)*I,e[2]=(x*_-g*S+m*M)*I,e[3]=(f*S-h*_-d*M)*I,e[4]=(l*A-o*D-c*R)*I,e[5]=(t*D-r*A+s*R)*I,e[6]=(g*y-p*_-m*v)*I,e[7]=(u*_-f*y+d*v)*I,e[8]=(o*O-a*A+c*w)*I,e[9]=(n*A-t*O-s*w)*I,e[10]=(p*S-x*y+m*b)*I,e[11]=(h*y-u*S-d*b)*I,e[12]=(a*R-o*C-l*w)*I,e[13]=(t*C-n*R+r*w)*I,e[14]=(x*v-p*M-g*b)*I,e[15]=(u*M-h*v+f*b)*I,this}scale(e){let t=this.elements,n=e.x,r=e.y,s=e.z;return t[0]*=n,t[4]*=r,t[8]*=s,t[1]*=n,t[5]*=r,t[9]*=s,t[2]*=n,t[6]*=r,t[10]*=s,t[3]*=n,t[7]*=r,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],r=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,n,r))}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),r=Math.sin(t),s=1-n,o=e.x,a=e.y,l=e.z,c=s*o,u=s*a;return this.set(c*o+n,c*a-r*l,c*l+r*a,0,c*a+r*l,u*a+n,u*l-r*o,0,c*l-r*a,u*l+r*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,r,s,o){return this.set(1,n,s,0,e,1,o,0,t,r,1,0,0,0,0,1),this}compose(e,t,n){let r=this.elements,s=t._x,o=t._y,a=t._z,l=t._w,c=s+s,u=o+o,h=a+a,f=s*c,d=s*u,p=s*h,x=o*u,g=o*h,m=a*h,b=l*c,v=l*u,y=l*h,M=n.x,S=n.y,_=n.z;return r[0]=(1-(x+m))*M,r[1]=(d+y)*M,r[2]=(p-v)*M,r[3]=0,r[4]=(d-y)*S,r[5]=(1-(f+m))*S,r[6]=(g+b)*S,r[7]=0,r[8]=(p+v)*_,r[9]=(g-b)*_,r[10]=(1-(f+x))*_,r[11]=0,r[12]=e.x,r[13]=e.y,r[14]=e.z,r[15]=1,this}decompose(e,t,n){let r=this.elements;e.x=r[12],e.y=r[13],e.z=r[14];let s=this.determinantAffine();if(s===0)return n.set(1,1,1),t.identity(),this;let o=zs.set(r[0],r[1],r[2]).length(),a=zs.set(r[4],r[5],r[6]).length(),l=zs.set(r[8],r[9],r[10]).length();s<0&&(o=-o),ni.copy(this);let c=1/o,u=1/a,h=1/l;return ni.elements[0]*=c,ni.elements[1]*=c,ni.elements[2]*=c,ni.elements[4]*=u,ni.elements[5]*=u,ni.elements[6]*=u,ni.elements[8]*=h,ni.elements[9]*=h,ni.elements[10]*=h,t.setFromRotationMatrix(ni),n.x=o,n.y=a,n.z=l,this}makePerspective(e,t,n,r,s,o,a=$n,l=!1){let c=this.elements,u=2*s/(t-e),h=2*s/(n-r),f=(t+e)/(t-e),d=(n+r)/(n-r),p,x;if(l)p=s/(o-s),x=o*s/(o-s);else if(a===$n)p=-(o+s)/(o-s),x=-2*o*s/(o-s);else if(a===so)p=-o/(o-s),x=-o*s/(o-s);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return c[0]=u,c[4]=0,c[8]=f,c[12]=0,c[1]=0,c[5]=h,c[9]=d,c[13]=0,c[2]=0,c[6]=0,c[10]=p,c[14]=x,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,n,r,s,o,a=$n,l=!1){let c=this.elements,u=2/(t-e),h=2/(n-r),f=-(t+e)/(t-e),d=-(n+r)/(n-r),p,x;if(l)p=1/(o-s),x=o/(o-s);else if(a===$n)p=-2/(o-s),x=-(o+s)/(o-s);else if(a===so)p=-1/(o-s),x=-s/(o-s);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return c[0]=u,c[4]=0,c[8]=0,c[12]=f,c[1]=0,c[5]=h,c[9]=0,c[13]=d,c[2]=0,c[6]=0,c[10]=p,c[14]=x,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){let t=this.elements,n=e.elements;for(let r=0;r<16;r++)if(t[r]!==n[r])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}};Bc.prototype.isMatrix4=!0;var Be=Bc,zs=new U,ni=new Be,O1=new U(0,0,0),N1=new U(1,1,1),Mr=new U,Ul=new U,Un=new U,H0=new Be,W0=new Sn,_i=class i{constructor(e=0,t=0,n=0,r=i.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=n,this._order=r}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,r=this._order){return this._x=e,this._y=t,this._z=n,this._order=r,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 r=e.elements,s=r[0],o=r[4],a=r[8],l=r[1],c=r[5],u=r[9],h=r[2],f=r[6],d=r[10];switch(t){case"XYZ":this._y=Math.asin(it(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-u,d),this._z=Math.atan2(-o,s)):(this._x=Math.atan2(f,c),this._z=0);break;case"YXZ":this._x=Math.asin(-it(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(l,c)):(this._y=Math.atan2(-h,s),this._z=0);break;case"ZXY":this._x=Math.asin(it(f,-1,1)),Math.abs(f)<.9999999?(this._y=Math.atan2(-h,d),this._z=Math.atan2(-o,c)):(this._y=0,this._z=Math.atan2(l,s));break;case"ZYX":this._y=Math.asin(-it(h,-1,1)),Math.abs(h)<.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(it(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-u,c),this._y=Math.atan2(-h,s)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-it(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(f,c),this._y=Math.atan2(a,s)):(this._x=Math.atan2(-u,d),this._y=0);break;default:Le("Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,n===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,n){return H0.makeRotationFromQuaternion(e),this.setFromRotationMatrix(H0,t,n)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return W0.setFromEuler(this),this.setFromQuaternion(W0,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}};_i.DEFAULT_ORDER="XYZ";var co=class{constructor(){this.mask=1}set(e){this.mask=(1<<e|0)>>>0}enable(e){this.mask|=1<<e|0}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e|0}disable(e){this.mask&=~(1<<e|0)}disableAll(){this.mask=0}test(e){return(this.mask&e.mask)!==0}isEnabled(e){return(this.mask&(1<<e|0))!==0}},D1=0,X0=new U,Vs=new Sn,zi=new Be,Bl=new U,Qo=new U,U1=new U,B1=new Sn,Y0=new U(1,0,0),q0=new U(0,1,0),$0=new U(0,0,1),K0={type:"added"},k1={type:"removed"},Gs={type:"childadded",child:null},qh={type:"childremoved",child:null},Et=class i extends yi{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:D1++}),this.uuid=Ri(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=i.DEFAULT_UP.clone();let e=new U,t=new _i,n=new Sn,r=new U(1,1,1);function s(){n.setFromEuler(t,!1)}function o(){t.setFromQuaternion(n,void 0,!1)}t._onChange(s),n._onChange(o),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:e},rotation:{configurable:!0,enumerable:!0,value:t},quaternion:{configurable:!0,enumerable:!0,value:n},scale:{configurable:!0,enumerable:!0,value:r},modelViewMatrix:{value:new Be},normalMatrix:{value:new He}}),this.matrix=new Be,this.matrixWorld=new Be,this.matrixAutoUpdate=i.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=i.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new co,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale),this.pivot!==null&&this.position.copy(this.pivot).applyMatrix4(this.matrix).sub(this.pivot)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return Vs.setFromAxisAngle(e,t),this.quaternion.multiply(Vs),this}rotateOnWorldAxis(e,t){return Vs.setFromAxisAngle(e,t),this.quaternion.premultiply(Vs),this}rotateX(e){return this.rotateOnAxis(Y0,e)}rotateY(e){return this.rotateOnAxis(q0,e)}rotateZ(e){return this.rotateOnAxis($0,e)}translateOnAxis(e,t){return X0.copy(e).applyQuaternion(this.quaternion),this.position.add(X0.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(Y0,e)}translateY(e){return this.translateOnAxis(q0,e)}translateZ(e){return this.translateOnAxis($0,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(zi.copy(this.matrixWorld).invert())}lookAt(e,t,n){e.isVector3?Bl.copy(e):Bl.set(e,t,n);let r=this.parent;this.updateWorldMatrix(!0,!1),Qo.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?zi.lookAt(Qo,Bl,this.up):zi.lookAt(Bl,Qo,this.up),this.quaternion.setFromRotationMatrix(zi),r&&(zi.extractRotation(r.matrixWorld),Vs.setFromRotationMatrix(zi),this.quaternion.premultiply(Vs.invert()))}add(e){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return e===this?(Ge("Object3D.add: object can't be added as a child of itself.",e),this):(e&&e.isObject3D?(e.removeFromParent(),e.parent=this,this.children.push(e),e.dispatchEvent(K0),Gs.child=e,this.dispatchEvent(Gs),Gs.child=null):Ge("Object3D.add: object not an instance of THREE.Object3D.",e),this)}remove(e){if(arguments.length>1){for(let n=0;n<arguments.length;n++)this.remove(arguments[n]);return this}let t=this.children.indexOf(e);return t!==-1&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(k1),qh.child=e,this.dispatchEvent(qh),qh.child=null),this}removeFromParent(){let e=this.parent;return e!==null&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),zi.copy(this.matrixWorld).invert(),e.parent!==null&&(e.parent.updateWorldMatrix(!0,!1),zi.multiply(e.parent.matrixWorld)),e.applyMatrix4(zi),e.removeFromParent(),e.parent=this,this.children.push(e),e.updateWorldMatrix(!1,!0),e.dispatchEvent(K0),Gs.child=e,this.dispatchEvent(Gs),Gs.child=null,this}getObjectById(e){return this.getObjectByProperty("id",e)}getObjectByName(e){return this.getObjectByProperty("name",e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let n=0,r=this.children.length;n<r;n++){let o=this.children[n].getObjectByProperty(e,t);if(o!==void 0)return o}}getObjectsByProperty(e,t,n=[]){this[e]===t&&n.push(this);let r=this.children;for(let s=0,o=r.length;s<o;s++)r[s].getObjectsByProperty(e,t,n);return n}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Qo,e,U1),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Qo,B1,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);let t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}intersectsFrustum(){return!0}traverse(e){e(this);let t=this.children;for(let n=0,r=t.length;n<r;n++)t[n].traverse(e)}traverseVisible(e){if(this.visible===!1)return;e(this);let t=this.children;for(let n=0,r=t.length;n<r;n++)t[n].traverseVisible(e)}traverseAncestors(e){let t=this.parent;t!==null&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);let e=this.pivot;if(e!==null){let t=e.x,n=e.y,r=e.z,s=this.matrix.elements;s[12]+=t-s[0]*t-s[4]*n-s[8]*r,s[13]+=n-s[1]*t-s[5]*n-s[9]*r,s[14]+=r-s[2]*t-s[6]*n-s[10]*r}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,e=!0);let t=this.children;for(let n=0,r=t.length;n<r;n++)t[n].updateMatrixWorld(e)}updateWorldMatrix(e,t,n=!1){let r=this.parent;if(e===!0&&r!==null&&r.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||n)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,n=!0),t===!0){let s=this.children;for(let o=0,a=s.length;o<a;o++)s[o].updateWorldMatrix(!1,!0,n)}}toJSON(e){let t=e===void 0||typeof e=="string",n={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});let r={};r.uuid=this.uuid,r.type=this.type,r.name=this.name,r.castShadow=this.castShadow,r.receiveShadow=this.receiveShadow,r.visible=this.visible,r.frustumCulled=this.frustumCulled,r.renderOrder=this.renderOrder,r.static=this.static,r.matrixAutoUpdate=this.matrixAutoUpdate,Object.keys(this.userData).length>0&&(r.userData=this.userData),r.layers=this.layers.mask,r.matrix=this.matrix.toArray(),r.up=this.up.toArray(),this.pivot!==null&&(r.pivot=this.pivot.toArray()),this.morphTargetDictionary!==void 0&&(r.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(r.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(r.type="InstancedMesh",r.count=this.count,r.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(r.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(r.type="BatchedMesh",r.perObjectFrustumCulled=this.perObjectFrustumCulled,r.sortObjects=this.sortObjects,r.drawRanges=this._drawRanges,r.reservedRanges=this._reservedRanges,r.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),r.instanceInfo=this._instanceInfo.map(a=>({...a})),r.availableInstanceIds=this._availableInstanceIds.slice(),r.availableGeometryIds=this._availableGeometryIds.slice(),r.nextIndexStart=this._nextIndexStart,r.nextVertexStart=this._nextVertexStart,r.geometryCount=this._geometryCount,r.maxInstanceCount=this._maxInstanceCount,r.maxVertexCount=this._maxVertexCount,r.maxIndexCount=this._maxIndexCount,r.geometryInitialized=this._geometryInitialized,r.matricesTexture=this._matricesTexture.toJSON(e),r.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(r.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(r.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(r.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?r.background=this.background.toJSON():this.background.isTexture&&(r.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(r.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){r.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,u=l.length;c<u;c++){let h=l[c];s(e.shapes,h)}else s(e.shapes,l)}}if(this.isSkinnedMesh&&(r.bindMode=this.bindMode,r.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(s(e.skeletons,this.skeleton),r.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){let a=[];for(let l=0,c=this.material.length;l<c;l++)a.push(s(e.materials,this.material[l]));r.material=a}else r.material=s(e.materials,this.material);if(this.children.length>0){r.children=[];for(let a=0;a<this.children.length;a++)r.children.push(this.children[a].toJSON(e).object)}if(this.animations.length>0){r.animations=[];for(let a=0;a<this.animations.length;a++){let l=this.animations[a];r.animations.push(s(e.animations,l))}}if(t){let a=o(e.geometries),l=o(e.materials),c=o(e.textures),u=o(e.images),h=o(e.shapes),f=o(e.skeletons),d=o(e.animations),p=o(e.nodes);a.length>0&&(n.geometries=a),l.length>0&&(n.materials=l),c.length>0&&(n.textures=c),u.length>0&&(n.images=u),h.length>0&&(n.shapes=h),f.length>0&&(n.skeletons=f),d.length>0&&(n.animations=d),p.length>0&&(n.nodes=p)}return n.object=r,n;function o(a){let l=[];for(let c in a){let u=a[c];delete u.metadata,l.push(u)}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.pivot=e.pivot!==null?e.pivot.clone():null,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.static=e.static,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let n=0;n<e.children.length;n++){let r=e.children[n];this.add(r.clone())}return this}dispose(){this.dispatchEvent({type:"dispose"})}};Et.DEFAULT_UP=new U(0,1,0);Et.DEFAULT_MATRIX_AUTO_UPDATE=!0;Et.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;var ct=class extends Et{constructor(){super(),this.isGroup=!0,this.type="Group"}},z1={type:"move"},uo=class{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new ct,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 ct,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new U,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new U),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new ct,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new U,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new U,this._grip.eventsEnabled=!1),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 r=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 x of e.hand.values()){let g=t.getJointPose(x,n),m=this._getHandJoint(c,x);g!==null&&(m.matrix.fromArray(g.transform.matrix),m.matrix.decompose(m.position,m.quaternion,m.scale),m.matrixWorldNeedsUpdate=!0,m.jointRadius=g.radius),m.visible=g!==null}let u=c.joints["index-finger-tip"],h=c.joints["thumb-tip"],f=u.position.distanceTo(h.position),d=.02,p=.005;c.inputState.pinching&&f>d+p?(c.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:e.handedness,target:this})):!c.inputState.pinching&&f<=d-p&&(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.quaternion,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,l.eventsEnabled&&l.dispatchEvent({type:"gripUpdated",data:e,target:this})));a!==null&&(r=t.getPose(e.targetRaySpace,n),r===null&&s!==null&&(r=s),r!==null&&(a.matrix.fromArray(r.transform.matrix),a.matrix.decompose(a.position,a.quaternion,a.scale),a.matrixWorldNeedsUpdate=!0,r.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(r.linearVelocity)):a.hasLinearVelocity=!1,r.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(r.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(z1)))}return a!==null&&(a.visible=r!==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 ct;n.matrixAutoUpdate=!1,n.visible=!1,e.joints[t.jointName]=n,e.add(n)}return e.joints[t.jointName]}},px={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},Sr={h:0,s:0,l:0},kl={h:0,s:0,l:0};function $h(i,e,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?i+(e-i)*6*t:t<1/2?e:t<2/3?i+(e-i)*6*(2/3-t):i}var W=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 r=e;r&&r.isColor?this.copy(r):typeof r=="number"?this.setHex(r):typeof r=="string"&&this.setStyle(r)}else this.setRGB(e,t,n);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=ft){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,tt.colorSpaceToWorking(this,t),this}setRGB(e,t,n,r=tt.workingColorSpace){return this.r=e,this.g=t,this.b=n,tt.colorSpaceToWorking(this,r),this}setHSL(e,t,n,r=tt.workingColorSpace){if(e=nd(e,1),t=it(t,0,1),n=it(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=$h(o,s,e+1/3),this.g=$h(o,s,e),this.b=$h(o,s,e-1/3)}return tt.colorSpaceToWorking(this,r),this}setStyle(e,t=ft){function n(s){s!==void 0&&parseFloat(s)<1&&Le("Color: Alpha component of "+e+" will be ignored.")}let r;if(r=/^(\w+)\(([^\)]*)\)/.exec(e)){let s,o=r[1],a=r[2];switch(o){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+(?:\.\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+(?:\.\d+)?|\.\d+)\%\s*,\s*(\d+(?:\.\d+)?|\.\d+)\%\s*,\s*(\d+(?:\.\d+)?|\.\d+)\%\s*(?:,\s*(\d+(?:\.\d+)?|\.\d+)\s*)?$/.exec(a))return n(s[4]),this.setRGB(Math.min(100,parseFloat(s[1]))/100,Math.min(100,parseFloat(s[2]))/100,Math.min(100,parseFloat(s[3]))/100,t);break;case"hsl":case"hsla":if(s=/^\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*(\d+(?:\.\d+)?|\.\d+)\%\s*,\s*(\d+(?:\.\d+)?|\.\d+)\%\s*(?:,\s*(\d+(?:\.\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:Le("Color: Unknown color model "+e)}}else if(r=/^\#([A-Fa-f\d]+)$/.exec(e)){let s=r[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);Le("Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=ft){let n=px[e.toLowerCase()];return n!==void 0?this.setHex(n,t):Le("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=qi(e.r),this.g=qi(e.g),this.b=qi(e.b),this}copyLinearToSRGB(e){return this.r=io(e.r),this.g=io(e.g),this.b=io(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=ft){return tt.workingToColorSpace(pn.copy(this),e),Math.round(it(pn.r*255,0,255))*65536+Math.round(it(pn.g*255,0,255))*256+Math.round(it(pn.b*255,0,255))}getHexString(e=ft){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=tt.workingColorSpace){tt.workingToColorSpace(pn.copy(this),t);let n=pn.r,r=pn.g,s=pn.b,o=Math.max(n,r,s),a=Math.min(n,r,s),l,c,u=(a+o)/2;if(a===o)l=0,c=0;else{let h=o-a;switch(c=u<=.5?h/(o+a):h/(2-o-a),o){case n:l=(r-s)/h+(r<s?6:0);break;case r:l=(s-n)/h+2;break;case s:l=(n-r)/h+4;break}l/=6}return e.h=l,e.s=c,e.l=u,e}getRGB(e,t=tt.workingColorSpace){return tt.workingToColorSpace(pn.copy(this),t),e.r=pn.r,e.g=pn.g,e.b=pn.b,e}getStyle(e=ft){tt.workingToColorSpace(pn.copy(this),e);let t=pn.r,n=pn.g,r=pn.b;return e!==ft?`color(${e} ${t.toFixed(3)} ${n.toFixed(3)} ${r.toFixed(3)})`:`rgb(${Math.round(t*255)},${Math.round(n*255)},${Math.round(r*255)})`}offsetHSL(e,t,n){return this.getHSL(Sr),this.setHSL(Sr.h+e,Sr.s+t,Sr.l+n)}add(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this}addColors(e,t){return this.r=e.r+t.r,this.g=e.g+t.g,this.b=e.b+t.b,this}addScalar(e){return this.r+=e,this.g+=e,this.b+=e,this}sub(e){return this.r=Math.max(0,this.r-e.r),this.g=Math.max(0,this.g-e.g),this.b=Math.max(0,this.b-e.b),this}multiply(e){return this.r*=e.r,this.g*=e.g,this.b*=e.b,this}multiplyScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}lerp(e,t){return this.r+=(e.r-this.r)*t,this.g+=(e.g-this.g)*t,this.b+=(e.b-this.b)*t,this}lerpColors(e,t,n){return this.r=e.r+(t.r-e.r)*n,this.g=e.g+(t.g-e.g)*n,this.b=e.b+(t.b-e.b)*n,this}lerpHSL(e,t){this.getHSL(Sr),e.getHSL(kl);let n=da(Sr.h,kl.h,t),r=da(Sr.s,kl.s,t),s=da(Sr.l,kl.l,t);return this.setHSL(n,r,s),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){let t=this.r,n=this.g,r=this.b,s=e.elements;return this.r=s[0]*t+s[3]*n+s[6]*r,this.g=s[1]*t+s[4]*n+s[7]*r,this.b=s[2]*t+s[5]*n+s[8]*r,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}fromArray(e,t=0){return this.r=e[t],this.g=e[t+1],this.b=e[t+2],this}toArray(e=[],t=0){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e}fromBufferAttribute(e,t){return this.r=e.getX(t),this.g=e.getY(t),this.b=e.getZ(t),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}},pn=new W;W.NAMES=px;var ls=class i{constructor(e,t=25e-5){this.isFogExp2=!0,this.name="",this.color=new W(e),this.density=t}clone(){return new i(this.color,this.density)}toJSON(){return{type:"FogExp2",name:this.name,color:this.color.getHex(),density:this.density}}};var Tn=class extends Et{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 _i,this.environmentIntensity=1,this.environmentRotation=new _i,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(e,t){return super.copy(e,t),this.background=e.background!==null?e.background.clone():null,this.environment=e.environment!==null?e.environment.clone():null,this.fog=e.fog!==null?e.fog.clone():null,this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,this.backgroundRotation.copy(e.backgroundRotation),this.environmentIntensity=e.environmentIntensity,this.environmentRotation.copy(e.environmentRotation),this.overrideMaterial=e.overrideMaterial!==null?e.overrideMaterial.clone():null,this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){let t=super.toJSON(e);return this.fog!==null&&(t.object.fog=this.fog.toJSON()),t.object.backgroundBlurriness=this.backgroundBlurriness,t.object.backgroundIntensity=this.backgroundIntensity,t.object.backgroundRotation=this.backgroundRotation.toArray(),t.object.environmentIntensity=this.environmentIntensity,t.object.environmentRotation=this.environmentRotation.toArray(),t}},ii=new U,Vi=new U,Kh=new U,Gi=new U,Hs=new U,Ws=new U,Z0=new U,Zh=new U,Jh=new U,jh=new U,Qh=new _t,ef=new _t,tf=new _t,Yi=class i{constructor(e=new U,t=new U,n=new U){this.a=e,this.b=t,this.c=n}static getNormal(e,t,n,r){r.subVectors(n,t),ii.subVectors(e,t),r.cross(ii);let s=r.lengthSq();return s>0?r.multiplyScalar(1/Math.sqrt(s)):r.set(0,0,0)}static getBarycoord(e,t,n,r,s){ii.subVectors(r,t),Vi.subVectors(n,t),Kh.subVectors(e,t);let o=ii.dot(ii),a=ii.dot(Vi),l=ii.dot(Kh),c=Vi.dot(Vi),u=Vi.dot(Kh),h=o*c-a*a;if(h===0)return s.set(0,0,0),null;let f=1/h,d=(c*l-a*u)*f,p=(o*u-a*l)*f;return s.set(1-d-p,p,d)}static containsPoint(e,t,n,r){return this.getBarycoord(e,t,n,r,Gi)===null?!1:Gi.x>=0&&Gi.y>=0&&Gi.x+Gi.y<=1}static getInterpolation(e,t,n,r,s,o,a,l){return this.getBarycoord(e,t,n,r,Gi)===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,Gi.x),l.addScaledVector(o,Gi.y),l.addScaledVector(a,Gi.z),l)}static getInterpolatedAttribute(e,t,n,r,s,o){return Qh.setScalar(0),ef.setScalar(0),tf.setScalar(0),Qh.fromBufferAttribute(e,t),ef.fromBufferAttribute(e,n),tf.fromBufferAttribute(e,r),o.setScalar(0),o.addScaledVector(Qh,s.x),o.addScaledVector(ef,s.y),o.addScaledVector(tf,s.z),o}static isFrontFacing(e,t,n,r){return ii.subVectors(n,t),Vi.subVectors(e,t),ii.cross(Vi).dot(r)<0}set(e,t,n){return this.a.copy(e),this.b.copy(t),this.c.copy(n),this}setFromPointsAndIndices(e,t,n,r){return this.a.copy(e[t]),this.b.copy(e[n]),this.c.copy(e[r]),this}setFromAttributeAndIndices(e,t,n,r){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,n),this.c.fromBufferAttribute(e,r),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 ii.subVectors(this.c,this.b),Vi.subVectors(this.a,this.b),ii.cross(Vi).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return i.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,t){return i.getBarycoord(e,this.a,this.b,this.c,t)}getInterpolation(e,t,n,r,s){return i.getInterpolation(e,this.a,this.b,this.c,t,n,r,s)}containsPoint(e){return i.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return i.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){let n=this.a,r=this.b,s=this.c,o,a;Hs.subVectors(r,n),Ws.subVectors(s,n),Zh.subVectors(e,n);let l=Hs.dot(Zh),c=Ws.dot(Zh);if(l<=0&&c<=0)return t.copy(n);Jh.subVectors(e,r);let u=Hs.dot(Jh),h=Ws.dot(Jh);if(u>=0&&h<=u)return t.copy(r);let f=l*h-u*c;if(f<=0&&l>=0&&u<=0&&l-u>0)return o=l/(l-u),t.copy(n).addScaledVector(Hs,o);jh.subVectors(e,s);let d=Hs.dot(jh),p=Ws.dot(jh);if(p>=0&&d<=p)return t.copy(s);let x=d*c-l*p;if(x<=0&&c>=0&&p<=0)return a=c/(c-p),t.copy(n).addScaledVector(Ws,a);let g=u*p-d*h;if(g<=0&&h-u>=0&&d-p>=0)return Z0.subVectors(s,r),a=(h-u)/(h-u+(d-p)),t.copy(r).addScaledVector(Z0,a);let m=1/(g+x+f);return o=x*m,a=f*m,t.copy(n).addScaledVector(Hs,o).addScaledVector(Ws,a)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}},Ct=class{constructor(e=new U(1/0,1/0,1/0),t=new U(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,n=e.length;t<n;t+=3)this.expandByPoint(ri.fromArray(e,t));return this}setFromBufferAttribute(e){this.makeEmpty();for(let t=0,n=e.count;t<n;t++)this.expandByPoint(ri.fromBufferAttribute(e,t));return this}setFromPoints(e){this.makeEmpty();for(let t=0,n=e.length;t<n;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){let n=ri.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(n),this.max.copy(e).add(n),this}setFromObject(e,t=!1){return this.makeEmpty(),this.expandByObject(e,t)}clone(){return new this.constructor().copy(this)}copy(e){return this.min.copy(e.min),this.max.copy(e.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(e){return this.isEmpty()?e.set(0,0,0):e.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(e){return this.isEmpty()?e.set(0,0,0):e.subVectors(this.max,this.min)}expandByPoint(e){return this.min.min(e),this.max.max(e),this}expandByVector(e){return this.min.sub(e),this.max.add(e),this}expandByScalar(e){return this.min.addScalar(-e),this.max.addScalar(e),this}expandByObject(e,t=!1){e.updateWorldMatrix(!1,!1);let n=e.geometry;if(n!==void 0){let s=n.getAttribute("position");if(t===!0&&s!==void 0&&e.isInstancedMesh!==!0&&e.isBatchedMesh!==!0)for(let o=0,a=s.count;o<a;o++)e.isMesh===!0?e.getVertexPosition(o,ri):ri.fromBufferAttribute(s,o),ri.applyMatrix4(e.matrixWorld),this.expandByPoint(ri);else e.boundingBox!==void 0?(e.boundingBox===null&&e.computeBoundingBox(),zl.copy(e.boundingBox)):(n.boundingBox===null&&n.computeBoundingBox(),zl.copy(n.boundingBox)),zl.applyMatrix4(e.matrixWorld),this.union(zl)}let r=e.children;for(let s=0,o=r.length;s<o;s++)this.expandByObject(r[s],t);return this}containsPoint(e){return e.x>=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,ri),ri.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(ea),Vl.subVectors(this.max,ea),Xs.subVectors(e.a,ea),Ys.subVectors(e.b,ea),qs.subVectors(e.c,ea),wr.subVectors(Ys,Xs),Tr.subVectors(qs,Ys),ns.subVectors(Xs,qs);let t=[0,-wr.z,wr.y,0,-Tr.z,Tr.y,0,-ns.z,ns.y,wr.z,0,-wr.x,Tr.z,0,-Tr.x,ns.z,0,-ns.x,-wr.y,wr.x,0,-Tr.y,Tr.x,0,-ns.y,ns.x,0];return!nf(t,Xs,Ys,qs,Vl)||(t=[1,0,0,0,1,0,0,0,1],!nf(t,Xs,Ys,qs,Vl))?!1:(Gl.crossVectors(wr,Tr),t=[Gl.x,Gl.y,Gl.z],nf(t,Xs,Ys,qs,Vl))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,ri).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(ri).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:(Hi[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),Hi[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),Hi[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),Hi[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),Hi[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),Hi[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),Hi[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),Hi[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(Hi),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}},Hi=[new U,new U,new U,new U,new U,new U,new U,new U],ri=new U,zl=new Ct,Xs=new U,Ys=new U,qs=new U,wr=new U,Tr=new U,ns=new U,ea=new U,Vl=new U,Gl=new U,is=new U;function nf(i,e,t,n,r){for(let s=0,o=i.length-3;s<=o;s+=3){is.fromArray(i,s);let a=r.x*Math.abs(is.x)+r.y*Math.abs(is.y)+r.z*Math.abs(is.z),l=e.dot(is),c=t.dot(is),u=n.dot(is);if(Math.max(-Math.max(l,c,u),Math.min(l,c,u))>a)return!1}return!0}var $t=new U,Hl=new De,V1=0,wt=class extends yi{constructor(e,t,n=!1){if(super(),Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:V1++}),this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=n,this.usage=Qf,this.updateRanges=[],this.gpuType=Vn,this.version=0,this._normalizationScale=e!==void 0?Tu(e):void 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._normalizationScale=e._normalizationScale,this}copyAt(e,t,n){e*=this.itemSize,n*=t.itemSize;for(let r=0,s=this.itemSize;r<s;r++)this.array[e+r]=t.array[n+r];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(this.itemSize===2)for(let t=0,n=this.count;t<n;t++)Hl.fromBufferAttribute(this,t),Hl.applyMatrix3(e),this.setXY(t,Hl.x,Hl.y);else if(this.itemSize===3)for(let t=0,n=this.count;t<n;t++)$t.fromBufferAttribute(this,t),$t.applyMatrix3(e),this.setXYZ(t,$t.x,$t.y,$t.z);return this}applyMatrix4(e){for(let t=0,n=this.count;t<n;t++)$t.fromBufferAttribute(this,t),$t.applyMatrix4(e),this.setXYZ(t,$t.x,$t.y,$t.z);return this}applyNormalMatrix(e){for(let t=0,n=this.count;t<n;t++)$t.fromBufferAttribute(this,t),$t.applyNormalMatrix(e),this.setXYZ(t,$t.x,$t.y,$t.z);return this}transformDirection(e){for(let t=0,n=this.count;t<n;t++)$t.fromBufferAttribute(this,t),$t.transformDirection(e),this.setXYZ(t,$t.x,$t.y,$t.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let n=this.array[e*this.itemSize+t];return this.normalized&&(n=this._denormalize(n)),n}setComponent(e,t,n){return this.normalized&&(n=this._normalize(n)),this.array[e*this.itemSize+t]=n,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=this._denormalize(t)),t}setX(e,t){return this.normalized&&(t=this._normalize(t)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=this._denormalize(t)),t}setY(e,t){return this.normalized&&(t=this._normalize(t)),this.array[e*this.itemSize+1]=t,this}getZ(e){let t=this.array[e*this.itemSize+2];return this.normalized&&(t=this._denormalize(t)),t}setZ(e,t){return this.normalized&&(t=this._normalize(t)),this.array[e*this.itemSize+2]=t,this}getW(e){let t=this.array[e*this.itemSize+3];return this.normalized&&(t=this._denormalize(t)),t}setW(e,t){return this.normalized&&(t=this._normalize(t)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,n){return e*=this.itemSize,this.normalized&&(t=this._normalize(t),n=this._normalize(n)),this.array[e+0]=t,this.array[e+1]=n,this}setXYZ(e,t,n,r){return e*=this.itemSize,this.normalized&&(t=this._normalize(t),n=this._normalize(n),r=this._normalize(r)),this.array[e+0]=t,this.array[e+1]=n,this.array[e+2]=r,this}setXYZW(e,t,n,r,s){return e*=this.itemSize,this.normalized&&(t=this._normalize(t),n=this._normalize(n),r=this._normalize(r),s=this._normalize(s)),this.array[e+0]=t,this.array[e+1]=n,this.array[e+2]=r,this.array[e+3]=s,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){let e={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return e.name=this.name,e.usage=this.usage,e.gpuType=this.gpuType,e}dispose(){this.dispatchEvent({type:"dispose"})}_denormalize(e){let t=this._normalizationScale;return t!==void 0?Math.max(e/t,-1):rd(e,this.array)}_normalize(e){let t=this._normalizationScale;return t!==void 0?Math.round(e*t):sd(e,this.array)}};var xa=class extends wt{constructor(e,t,n){super(new Uint16Array(e),t,n)}};var cs=class extends wt{constructor(e,t,n){super(new Uint32Array(e),t,n)}};var ke=class extends wt{constructor(e,t,n){super(new Float32Array(e),t,n)}},G1=new Ct,ta=new U,rf=new U,Cn=class{constructor(e=new U,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):G1.setFromPoints(e).getCenter(n);let r=0;for(let s=0,o=e.length;s<o;s++)r=Math.max(r,n.distanceToSquared(e[s]));return this.radius=Math.sqrt(r),this}copy(e){return this.center.copy(e.center),this.radius=e.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(e){return e.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(e){return e.distanceTo(this.center)-this.radius}intersectsSphere(e){let t=this.radius+e.radius;return e.center.distanceToSquared(this.center)<=t*t}intersectsBox(e){return e.intersectsSphere(this)}intersectsPlane(e){return Math.abs(e.distanceToPoint(this.center))<=this.radius}clampPoint(e,t){let n=this.center.distanceToSquared(e);return t.copy(e),n>this.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;ta.subVectors(e,this.center);let t=ta.lengthSq();if(t>this.radius*this.radius){let n=Math.sqrt(t),r=(n-this.radius)*.5;this.center.addScaledVector(ta,r/n),this.radius+=r}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):(rf.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(ta.copy(e.center).add(rf)),this.expandByPoint(ta.copy(e.center).sub(rf))),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}},H1=0,qn=new Be,sf=new Et,$s=new U,Bn=new Ct,na=new Ct,rn=new U,Fe=class i extends yi{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:H1++}),this.uuid=Ri(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={},this._transformed=!1}getIndex(){return this.index}setIndex(e){return Array.isArray(e)?this.index=new(p1(e)?cs:xa)(e,1):this.index=e,this}setIndirect(e,t=0){return this.indirect=e,this.indirectOffset=t,this}getIndirect(){return this.indirect}getAttribute(e){return this.attributes[e]}setAttribute(e,t){return this.attributes[e]=t,this}deleteAttribute(e){return delete this.attributes[e],this}hasAttribute(e){return this.attributes[e]!==void 0}addGroup(e,t,n=0){this.groups.push({start:e,count:t,materialIndex:n})}clearGroups(){this.groups=[]}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}applyMatrix4(e){let t=this.attributes.position;t!==void 0&&(t.applyMatrix4(e),t.needsUpdate=!0);let n=this.attributes.normal;if(n!==void 0){let s=new He().getNormalMatrix(e);n.applyNormalMatrix(s),n.needsUpdate=!0}let r=this.attributes.tangent;return r!==void 0&&(r.transformDirection(e),r.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(e){return qn.makeRotationFromQuaternion(e),this.applyMatrix4(qn),this}rotateX(e){return qn.makeRotationX(e),this.applyMatrix4(qn),this}rotateY(e){return qn.makeRotationY(e),this.applyMatrix4(qn),this}rotateZ(e){return qn.makeRotationZ(e),this.applyMatrix4(qn),this}translate(e,t,n){return qn.makeTranslation(e,t,n),this.applyMatrix4(qn),this}scale(e,t,n){return qn.makeScale(e,t,n),this.applyMatrix4(qn),this}lookAt(e){return sf.lookAt(e),sf.updateMatrix(),this.applyMatrix4(sf.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter($s).negate(),this.translate($s.x,$s.y,$s.z),this}setFromPoints(e){let t=this.getAttribute("position");if(t===void 0){let n=[];for(let r=0,s=e.length;r<s;r++){let o=e[r];n.push(o.x,o.y,o.z||0)}this.setAttribute("position",new ke(n,3))}else{let n=Math.min(e.length,t.count);for(let r=0;r<n;r++){let s=e[r];t.setXYZ(r,s.x,s.y,s.z||0)}e.length>t.count&&Le("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){Ge("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new U(-1/0,-1/0,-1/0),new U(1/0,1/0,1/0));return}if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let n=0,r=t.length;n<r;n++){let s=t[n];Bn.setFromBufferAttribute(s),this.morphTargetsRelative?(rn.addVectors(this.boundingBox.min,Bn.min),this.boundingBox.expandByPoint(rn),rn.addVectors(this.boundingBox.max,Bn.max),this.boundingBox.expandByPoint(rn)):(this.boundingBox.expandByPoint(Bn.min),this.boundingBox.expandByPoint(Bn.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&Ge('BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new Cn);let e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){Ge("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new U,1/0);return}if(e){let n=this.boundingSphere.center;if(Bn.setFromBufferAttribute(e),t)for(let s=0,o=t.length;s<o;s++){let a=t[s];na.setFromBufferAttribute(a),this.morphTargetsRelative?(rn.addVectors(Bn.min,na.min),Bn.expandByPoint(rn),rn.addVectors(Bn.max,na.max),Bn.expandByPoint(rn)):(Bn.expandByPoint(na.min),Bn.expandByPoint(na.max))}Bn.getCenter(n);let r=0;for(let s=0,o=e.count;s<o;s++)rn.fromBufferAttribute(e,s),r=Math.max(r,n.distanceToSquared(rn));if(t)for(let s=0,o=t.length;s<o;s++){let a=t[s],l=this.morphTargetsRelative;for(let c=0,u=a.count;c<u;c++)rn.fromBufferAttribute(a,c),l&&($s.fromBufferAttribute(e,c),rn.add($s)),r=Math.max(r,n.distanceToSquared(rn))}this.boundingSphere.radius=Math.sqrt(r),isNaN(this.boundingSphere.radius)&&Ge('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){let e=this.index,t=this.attributes;if(e===null||t.position===void 0||t.normal===void 0||t.uv===void 0){Ge("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}let n=t.position,r=t.normal,s=t.uv,o=this.getAttribute("tangent");(o===void 0||o.count!==n.count)&&(o=new wt(new Float32Array(4*n.count),4),this.setAttribute("tangent",o));let a=[],l=[],c=new Uint8Array(n.count);for(let R=0;R<n.count;R++)a[R]=new U,l[R]=new U;let u=new U,h=new U,f=new U,d=new De,p=new De,x=new De,g=new U,m=new U;function b(R,A,C){c[R]=c[A]=c[C]=1,u.fromBufferAttribute(n,R),h.fromBufferAttribute(n,A),f.fromBufferAttribute(n,C),d.fromBufferAttribute(s,R),p.fromBufferAttribute(s,A),x.fromBufferAttribute(s,C),h.sub(u),f.sub(u),p.sub(d),x.sub(d);let O=1/(p.x*x.y-x.x*p.y);isFinite(O)&&(g.copy(h).multiplyScalar(x.y).addScaledVector(f,-p.y).multiplyScalar(O),m.copy(f).multiplyScalar(p.x).addScaledVector(h,-x.x).multiplyScalar(O),a[R].add(g),a[A].add(g),a[C].add(g),l[R].add(m),l[A].add(m),l[C].add(m))}let v=this.groups;v.length===0&&(v=[{start:0,count:e.count}]);for(let R=0,A=v.length;R<A;++R){let C=v[R],O=C.start,D=C.count;for(let P=O,I=O+D;P<I;P+=3)b(e.getX(P+0),e.getX(P+1),e.getX(P+2))}let y=new U,M=new U,S=new U,_=new U;function w(R){S.fromBufferAttribute(r,R),_.copy(S);let A=a[R];y.copy(A),y.sub(S.multiplyScalar(S.dot(A))).normalize(),M.crossVectors(_,A);let O=M.dot(l[R])<0?-1:1;o.setXYZW(R,y.x,y.y,y.z,O)}for(let R=0,A=n.count;R<A;++R)c[R]&&w(R);this._transformed=!0}computeVertexNormals(){let e=this.index,t=this.getAttribute("position");if(t!==void 0){let n=this.getAttribute("normal");if(n===void 0||n.count!==t.count)n=new wt(new Float32Array(t.count*3),3),this.setAttribute("normal",n);else for(let f=0,d=n.count;f<d;f++)n.setXYZ(f,0,0,0);let r=new U,s=new U,o=new U,a=new U,l=new U,c=new U,u=new U,h=new U;if(e)for(let f=0,d=e.count;f<d;f+=3){let p=e.getX(f+0),x=e.getX(f+1),g=e.getX(f+2);r.fromBufferAttribute(t,p),s.fromBufferAttribute(t,x),o.fromBufferAttribute(t,g),u.subVectors(o,s),h.subVectors(r,s),u.cross(h),a.fromBufferAttribute(n,p),l.fromBufferAttribute(n,x),c.fromBufferAttribute(n,g),a.add(u),l.add(u),c.add(u),n.setXYZ(p,a.x,a.y,a.z),n.setXYZ(x,l.x,l.y,l.z),n.setXYZ(g,c.x,c.y,c.z)}else for(let f=0,d=t.count;f<d;f+=3)r.fromBufferAttribute(t,f+0),s.fromBufferAttribute(t,f+1),o.fromBufferAttribute(t,f+2),u.subVectors(o,s),h.subVectors(r,s),u.cross(h),n.setXYZ(f+0,u.x,u.y,u.z),n.setXYZ(f+1,u.x,u.y,u.z),n.setXYZ(f+2,u.x,u.y,u.z);this.normalizeNormals(),n.needsUpdate=!0}}normalizeNormals(){let e=this.attributes.normal;for(let t=0,n=e.count;t<n;t++)rn.fromBufferAttribute(e,t),rn.normalize(),e.setXYZ(t,rn.x,rn.y,rn.z)}toNonIndexed(){function e(a,l){let c=a.array,u=a.itemSize,h=a.normalized,f=new c.constructor(l.length*u),d=0,p=0;for(let x=0,g=l.length;x<g;x++){a.isInterleavedBufferAttribute?d=l[x]*a.data.stride+a.offset:d=l[x]*u;for(let m=0;m<u;m++)f[p++]=c[d++]}return new wt(f,u,h)}if(this.index===null)return Le("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;let t=new i,n=this.index.array,r=this.attributes;for(let a in r){let l=r[a],c=e(l,n);t.setAttribute(a,c)}let s=this.morphAttributes;for(let a in s){let l=[],c=s[a];for(let u=0,h=c.length;u<h;u++){let f=c[u],d=e(f,n);l.push(d)}t.morphAttributes[a]=l}t.morphTargetsRelative=this.morphTargetsRelative;let o=this.groups;for(let a=0,l=o.length;a<l;a++){let c=o[a];t.addGroup(c.start,c.count,c.materialIndex)}return t}toJSON(){let e={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(e.uuid=this.uuid,e.type=this.parameters!==void 0&&this._transformed===!0?"BufferGeometry":this.type,e.name=this.name,Object.keys(this.userData).length>0&&(e.userData=this.userData),this.parameters!==void 0&&this._transformed!==!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 r={},s=!1;for(let l in this.morphAttributes){let c=this.morphAttributes[l],u=[];for(let h=0,f=c.length;h<f;h++){let d=c[h];u.push(d.toJSON(e.data))}u.length>0&&(r[l]=u,s=!0)}s&&(e.data.morphAttributes=r,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 r=e.attributes;for(let c in r){let u=r[c];this.setAttribute(c,u.clone(t))}let s=e.morphAttributes;for(let c in s){let u=[],h=s[c];for(let f=0,d=h.length;f<d;f++)u.push(h[f].clone(t));this.morphAttributes[c]=u}this.morphTargetsRelative=e.morphTargetsRelative;let o=e.groups;for(let c=0,u=o.length;c<u;c++){let h=o[c];this.addGroup(h.start,h.count,h.materialIndex)}let a=e.boundingBox;a!==null&&(this.boundingBox=a.clone());let l=e.boundingSphere;return l!==null&&(this.boundingSphere=l.clone()),this.drawRange.start=e.drawRange.start,this.drawRange.count=e.drawRange.count,this.userData=e.userData,this._transformed=e._transformed,this}dispose(){this.dispatchEvent({type:"dispose"})}},us=class{constructor(e,t){this.isInterleavedBuffer=!0,this.array=e,this.stride=t,this.count=e!==void 0?e.length/t:0,this.usage=Qf,this.updateRanges=[],this.version=0,this.uuid=Ri()}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 r=0,s=this.stride;r<s;r++)this.array[e+r]=t.array[n+r];return this}set(e,t=0){return this.array.set(e,t),this}clone(e){e.arrayBuffers===void 0&&(e.arrayBuffers={});let t=J0(this.array);e.arrayBuffers[t]===void 0&&(e.arrayBuffers[t]=this.array.slice(0).buffer);let n=new this.array.constructor(e.arrayBuffers[t]),r=new this.constructor(n,this.stride);return r.setUsage(this.usage),r}onUpload(e){return this.onUploadCallback=e,this}toJSON(e){e.arrayBuffers===void 0&&(e.arrayBuffers={});let t=J0(this.array);e.arrayBuffers[t]===void 0&&(e.arrayBuffers[t]=Array.from(new Uint32Array(this.array.slice(0).buffer)));let n={uuid:this.uuid,buffer:t,type:this.array.constructor.name,stride:this.stride};return n.usage=this.usage,n}};function J0(i){return i.buffer._uuid===void 0&&(i.buffer._uuid=Ri()),i.byteOffset===0&&i.byteLength===i.buffer.byteLength?i.buffer._uuid:i.buffer._uuid+":"+i.byteOffset+":"+i.byteLength}var vn=new U,Cr=class i{constructor(e,t,n,r=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=e,this.itemSize=t,this.offset=n,this.normalized=r,this._normalizationScale=e!==void 0?Tu(e.array):void 0}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(e){this.data.needsUpdate=e}applyMatrix4(e){for(let t=0,n=this.data.count;t<n;t++)vn.fromBufferAttribute(this,t),vn.applyMatrix4(e),this.setXYZ(t,vn.x,vn.y,vn.z);return this}applyNormalMatrix(e){for(let t=0,n=this.count;t<n;t++)vn.fromBufferAttribute(this,t),vn.applyNormalMatrix(e),this.setXYZ(t,vn.x,vn.y,vn.z);return this}transformDirection(e){for(let t=0,n=this.count;t<n;t++)vn.fromBufferAttribute(this,t),vn.transformDirection(e),this.setXYZ(t,vn.x,vn.y,vn.z);return this}getComponent(e,t){let n=this.array[e*this.data.stride+this.offset+t];return this.normalized&&(n=this._denormalize(n)),n}setComponent(e,t,n){return this.normalized&&(n=this._normalize(n)),this.data.array[e*this.data.stride+this.offset+t]=n,this}setX(e,t){return this.normalized&&(t=this._normalize(t)),this.data.array[e*this.data.stride+this.offset]=t,this}setY(e,t){return this.normalized&&(t=this._normalize(t)),this.data.array[e*this.data.stride+this.offset+1]=t,this}setZ(e,t){return this.normalized&&(t=this._normalize(t)),this.data.array[e*this.data.stride+this.offset+2]=t,this}setW(e,t){return this.normalized&&(t=this._normalize(t)),this.data.array[e*this.data.stride+this.offset+3]=t,this}getX(e){let t=this.data.array[e*this.data.stride+this.offset];return this.normalized&&(t=this._denormalize(t)),t}getY(e){let t=this.data.array[e*this.data.stride+this.offset+1];return this.normalized&&(t=this._denormalize(t)),t}getZ(e){let t=this.data.array[e*this.data.stride+this.offset+2];return this.normalized&&(t=this._denormalize(t)),t}getW(e){let t=this.data.array[e*this.data.stride+this.offset+3];return this.normalized&&(t=this._denormalize(t)),t}setXY(e,t,n){return e=e*this.data.stride+this.offset,this.normalized&&(t=this._normalize(t),n=this._normalize(n)),this.data.array[e+0]=t,this.data.array[e+1]=n,this}setXYZ(e,t,n,r){return e=e*this.data.stride+this.offset,this.normalized&&(t=this._normalize(t),n=this._normalize(n),r=this._normalize(r)),this.data.array[e+0]=t,this.data.array[e+1]=n,this.data.array[e+2]=r,this}setXYZW(e,t,n,r,s){return e=e*this.data.stride+this.offset,this.normalized&&(t=this._normalize(t),n=this._normalize(n),r=this._normalize(r),s=this._normalize(s)),this.data.array[e+0]=t,this.data.array[e+1]=n,this.data.array[e+2]=r,this.data.array[e+3]=s,this}clone(e){if(e===void 0){ma("InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");let t=[];for(let n=0;n<this.count;n++){let r=n*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[r+s])}return new wt(new this.array.constructor(t),this.itemSize,this.normalized)}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.clone(e)),new i(e.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(e){if(e===void 0){ma("InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");let t=[];for(let n=0;n<this.count;n++){let r=n*this.data.stride+this.offset;for(let s=0;s<this.itemSize;s++)t.push(this.data.array[r+s])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:t,normalized:this.normalized}}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.toJSON(e)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}_denormalize(e){let t=this._normalizationScale;return t!==void 0?Math.max(e/t,-1):rd(e,this.data.array)}_normalize(e){let t=this._normalizationScale;return t!==void 0?Math.round(e*t):sd(e,this.data.array)}},of=new U,W1=new U,X1=new He,si=class{constructor(e=new U(1,0,0),t=0){this.isPlane=!0,this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,n,r){return this.normal.set(e,t,n),this.constant=r,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,n){let r=of.subVectors(n,t).cross(W1.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(r,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){let e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t,n=!0){let r=e.delta(of),s=this.normal.dot(r);if(s===0)return this.distanceToPoint(e.start)===0?t.copy(e.start):null;let o=-(e.start.dot(this.normal)+this.constant)/s;return n===!0&&(o<0||o>1)?null:t.copy(e.start).addScaledVector(r,o)}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||X1.getNormalMatrix(e),r=this.coplanarPoint(of).applyMatrix4(e),s=this.normal.applyMatrix3(n).normalize();return this.constant=-r.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)}toJSON(){return{normal:this.normal.toArray(),constant:this.constant}}fromJSON(e){return this.normal.fromArray(e.normal),this.constant=e.constant,this}},Y1=0,mn=class extends yi{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:Y1++}),this.uuid=Ri(),this.name="",this.type="Material",this.blending=Ai,this.side=Ti,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=Ff,this.blendDst=Of,this.blendEquation=gs,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new W(0,0,0),this.blendAlpha=0,this.depthFunc=ro,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=rx,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=pc,this.stencilZFail=pc,this.stencilZPass=pc,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(e){this._alphaTest>0!=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){Le(`Material: parameter '${t}' has value of undefined.`);continue}let r=this[t];if(r===void 0){Le(`Material: '${t}' is not a property of THREE.${this.type}.`);continue}r&&r.isColor?r.set(n):r&&r.isVector2&&n&&n.isVector2||r&&r.isEuler&&n&&n.isEuler||r&&r.isVector3&&n&&n.isVector3?r.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,n.blending=this.blending,n.side=this.side,n.shadowSide=this.shadowSide,n.vertexColors=this.vertexColors,n.opacity=this.opacity,n.transparent=this.transparent,n.blendSrc=this.blendSrc,n.blendDst=this.blendDst,n.blendEquation=this.blendEquation,n.blendSrcAlpha=this.blendSrcAlpha,n.blendDstAlpha=this.blendDstAlpha,n.blendEquationAlpha=this.blendEquationAlpha,n.blendColor=this.blendColor.getHex(),n.blendAlpha=this.blendAlpha,n.depthFunc=this.depthFunc,n.depthTest=this.depthTest,n.depthWrite=this.depthWrite,n.colorWrite=this.colorWrite,n.clipIntersection=this.clipIntersection,n.clipShadows=this.clipShadows,n.stencilWriteMask=this.stencilWriteMask,n.stencilFunc=this.stencilFunc,n.stencilRef=this.stencilRef,n.stencilFuncMask=this.stencilFuncMask,n.stencilFail=this.stencilFail,n.stencilZFail=this.stencilZFail,n.stencilZPass=this.stencilZPass,n.stencilWrite=this.stencilWrite,n.polygonOffset=this.polygonOffset,n.polygonOffsetFactor=this.polygonOffsetFactor,n.polygonOffsetUnits=this.polygonOffsetUnits,n.dithering=this.dithering,n.alphaTest=this.alphaTest,n.alphaHash=this.alphaHash,n.alphaToCoverage=this.alphaToCoverage,n.premultipliedAlpha=this.premultipliedAlpha,n.forceSinglePass=this.forceSinglePass,n.allowOverride=this.allowOverride,n.visible=this.visible,n.toneMapped=this.toneMapped,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&&(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.diffuseRoughness!==void 0&&(n.diffuseRoughness=this.diffuseRoughness),this.diffuseRoughnessMap&&this.diffuseRoughnessMap.isTexture&&(n.diffuseRoughnessMap=this.diffuseRoughnessMap.toJSON(e).uuid),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.retroreflectivity!==void 0&&(n.retroreflectivity=this.retroreflectivity),this.iridescence!==void 0&&(n.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(n.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessMinimum!==void 0&&(n.iridescenceThicknessMinimum=this.iridescenceThicknessMinimum),this.iridescenceThicknessMaximum!==void 0&&(n.iridescenceThicknessMaximum=this.iridescenceThicknessMaximum),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&&(n.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(n.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(n.size=this.size),this.sizeAttenuation!==void 0&&(n.sizeAttenuation=this.sizeAttenuation),Array.isArray(this.clippingPlanes)&&this.clippingPlanes.length>0&&(n.clippingPlanes=this.clippingPlanes.map(s=>s.toJSON())),this.rotation!==void 0&&(n.rotation=this.rotation),this.depthPacking!==void 0&&(n.depthPacking=this.depthPacking),this.linewidth!==void 0&&(n.linewidth=this.linewidth),this.linecap!==void 0&&(n.linecap=this.linecap),this.linejoin!==void 0&&(n.linejoin=this.linejoin),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.wireframe!==void 0&&(n.wireframe=this.wireframe),this.wireframeLinewidth!==void 0&&(n.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!==void 0&&(n.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!==void 0&&(n.wireframeLinejoin=this.wireframeLinejoin),this.flatShading!==void 0&&(n.flatShading=this.flatShading),this.fog!==void 0&&(n.fog=this.fog),Object.keys(this.userData).length>0&&(n.userData=this.userData);function r(s){let o=[];for(let a in s){let l=s[a];delete l.metadata,o.push(l)}return o}if(t){let s=r(e.textures),o=r(e.images);s.length>0&&(n.textures=s),o.length>0&&(n.images=o)}return n}fromJSON(e,t){if(e.uuid!==void 0&&(this.uuid=e.uuid),e.name!==void 0&&(this.name=e.name),e.color!==void 0&&this.color!==void 0&&this.color.setHex(e.color),e.roughness!==void 0&&(this.roughness=e.roughness),e.metalness!==void 0&&(this.metalness=e.metalness),e.sheen!==void 0&&(this.sheen=e.sheen),e.sheenColor!==void 0&&(this.sheenColor=new W().setHex(e.sheenColor)),e.sheenRoughness!==void 0&&(this.sheenRoughness=e.sheenRoughness),e.emissive!==void 0&&this.emissive!==void 0&&this.emissive.setHex(e.emissive),e.specular!==void 0&&this.specular!==void 0&&this.specular.setHex(e.specular),e.specularIntensity!==void 0&&(this.specularIntensity=e.specularIntensity),e.specularColor!==void 0&&this.specularColor!==void 0&&this.specularColor.setHex(e.specularColor),e.shininess!==void 0&&(this.shininess=e.shininess),e.clearcoat!==void 0&&(this.clearcoat=e.clearcoat),e.clearcoatRoughness!==void 0&&(this.clearcoatRoughness=e.clearcoatRoughness),e.diffuseRoughness!==void 0&&(this.diffuseRoughness=e.diffuseRoughness),e.dispersion!==void 0&&(this.dispersion=e.dispersion),e.retroreflectivity!==void 0&&(this.retroreflectivity=e.retroreflectivity),e.iridescence!==void 0&&(this.iridescence=e.iridescence),e.iridescenceIOR!==void 0&&(this.iridescenceIOR=e.iridescenceIOR),e.iridescenceThicknessMinimum!==void 0&&(this.iridescenceThicknessMinimum=e.iridescenceThicknessMinimum),e.iridescenceThicknessMaximum!==void 0&&(this.iridescenceThicknessMaximum=e.iridescenceThicknessMaximum),e.iridescenceThicknessRange!==void 0&&(this.iridescenceThicknessMinimum=e.iridescenceThicknessRange[0],this.iridescenceThicknessMaximum=e.iridescenceThicknessRange[1]),e.transmission!==void 0&&(this.transmission=e.transmission),e.thickness!==void 0&&(this.thickness=e.thickness),e.attenuationDistance!==void 0&&(this.attenuationDistance=e.attenuationDistance),e.attenuationColor!==void 0&&this.attenuationColor!==void 0&&this.attenuationColor.setHex(e.attenuationColor),e.anisotropy!==void 0&&(this.anisotropy=e.anisotropy),e.anisotropyRotation!==void 0&&(this.anisotropyRotation=e.anisotropyRotation),e.fog!==void 0&&(this.fog=e.fog),e.flatShading!==void 0&&(this.flatShading=e.flatShading),e.blending!==void 0&&(this.blending=e.blending),e.combine!==void 0&&(this.combine=e.combine),e.side!==void 0&&(this.side=e.side),e.shadowSide!==void 0&&(this.shadowSide=e.shadowSide),e.opacity!==void 0&&(this.opacity=e.opacity),e.transparent!==void 0&&(this.transparent=e.transparent),e.alphaTest!==void 0&&(this.alphaTest=e.alphaTest),e.alphaHash!==void 0&&(this.alphaHash=e.alphaHash),e.depthFunc!==void 0&&(this.depthFunc=e.depthFunc),e.depthTest!==void 0&&(this.depthTest=e.depthTest),e.depthWrite!==void 0&&(this.depthWrite=e.depthWrite),e.colorWrite!==void 0&&(this.colorWrite=e.colorWrite),e.clippingPlanes!==void 0&&(this.clippingPlanes=e.clippingPlanes.map(n=>new si().fromJSON(n))),e.clipIntersection!==void 0&&(this.clipIntersection=e.clipIntersection),e.clipShadows!==void 0&&(this.clipShadows=e.clipShadows),e.depthPacking!==void 0&&(this.depthPacking=e.depthPacking),e.blendSrc!==void 0&&(this.blendSrc=e.blendSrc),e.blendDst!==void 0&&(this.blendDst=e.blendDst),e.blendEquation!==void 0&&(this.blendEquation=e.blendEquation),e.blendSrcAlpha!==void 0&&(this.blendSrcAlpha=e.blendSrcAlpha),e.blendDstAlpha!==void 0&&(this.blendDstAlpha=e.blendDstAlpha),e.blendEquationAlpha!==void 0&&(this.blendEquationAlpha=e.blendEquationAlpha),e.blendColor!==void 0&&this.blendColor!==void 0&&this.blendColor.setHex(e.blendColor),e.blendAlpha!==void 0&&(this.blendAlpha=e.blendAlpha),e.stencilWriteMask!==void 0&&(this.stencilWriteMask=e.stencilWriteMask),e.stencilFunc!==void 0&&(this.stencilFunc=e.stencilFunc),e.stencilRef!==void 0&&(this.stencilRef=e.stencilRef),e.stencilFuncMask!==void 0&&(this.stencilFuncMask=e.stencilFuncMask),e.stencilFail!==void 0&&(this.stencilFail=e.stencilFail),e.stencilZFail!==void 0&&(this.stencilZFail=e.stencilZFail),e.stencilZPass!==void 0&&(this.stencilZPass=e.stencilZPass),e.stencilWrite!==void 0&&(this.stencilWrite=e.stencilWrite),e.wireframe!==void 0&&(this.wireframe=e.wireframe),e.wireframeLinewidth!==void 0&&(this.wireframeLinewidth=e.wireframeLinewidth),e.wireframeLinecap!==void 0&&(this.wireframeLinecap=e.wireframeLinecap),e.wireframeLinejoin!==void 0&&(this.wireframeLinejoin=e.wireframeLinejoin),e.rotation!==void 0&&(this.rotation=e.rotation),e.linewidth!==void 0&&(this.linewidth=e.linewidth),e.linecap!==void 0&&(this.linecap=e.linecap),e.linejoin!==void 0&&(this.linejoin=e.linejoin),e.dashSize!==void 0&&(this.dashSize=e.dashSize),e.gapSize!==void 0&&(this.gapSize=e.gapSize),e.scale!==void 0&&(this.scale=e.scale),e.polygonOffset!==void 0&&(this.polygonOffset=e.polygonOffset),e.polygonOffsetFactor!==void 0&&(this.polygonOffsetFactor=e.polygonOffsetFactor),e.polygonOffsetUnits!==void 0&&(this.polygonOffsetUnits=e.polygonOffsetUnits),e.dithering!==void 0&&(this.dithering=e.dithering),e.alphaToCoverage!==void 0&&(this.alphaToCoverage=e.alphaToCoverage),e.premultipliedAlpha!==void 0&&(this.premultipliedAlpha=e.premultipliedAlpha),e.forceSinglePass!==void 0&&(this.forceSinglePass=e.forceSinglePass),e.allowOverride!==void 0&&(this.allowOverride=e.allowOverride),e.visible!==void 0&&(this.visible=e.visible),e.toneMapped!==void 0&&(this.toneMapped=e.toneMapped),e.userData!==void 0&&(this.userData=e.userData),e.vertexColors!==void 0&&(typeof e.vertexColors=="number"?this.vertexColors=e.vertexColors>0:this.vertexColors=e.vertexColors),e.size!==void 0&&(this.size=e.size),e.sizeAttenuation!==void 0&&(this.sizeAttenuation=e.sizeAttenuation),e.map!==void 0&&(this.map=t[e.map]||null),e.matcap!==void 0&&(this.matcap=t[e.matcap]||null),e.alphaMap!==void 0&&(this.alphaMap=t[e.alphaMap]||null),e.bumpMap!==void 0&&(this.bumpMap=t[e.bumpMap]||null),e.bumpScale!==void 0&&(this.bumpScale=e.bumpScale),e.normalMap!==void 0&&(this.normalMap=t[e.normalMap]||null),e.normalMapType!==void 0&&(this.normalMapType=e.normalMapType),e.normalScale!==void 0){let n=e.normalScale;Array.isArray(n)===!1&&(n=[n,n]),this.normalScale=new De().fromArray(n)}return e.displacementMap!==void 0&&(this.displacementMap=t[e.displacementMap]||null),e.displacementScale!==void 0&&(this.displacementScale=e.displacementScale),e.displacementBias!==void 0&&(this.displacementBias=e.displacementBias),e.roughnessMap!==void 0&&(this.roughnessMap=t[e.roughnessMap]||null),e.metalnessMap!==void 0&&(this.metalnessMap=t[e.metalnessMap]||null),e.emissiveMap!==void 0&&(this.emissiveMap=t[e.emissiveMap]||null),e.emissiveIntensity!==void 0&&(this.emissiveIntensity=e.emissiveIntensity),e.specularMap!==void 0&&(this.specularMap=t[e.specularMap]||null),e.specularIntensityMap!==void 0&&(this.specularIntensityMap=t[e.specularIntensityMap]||null),e.specularColorMap!==void 0&&(this.specularColorMap=t[e.specularColorMap]||null),e.envMap!==void 0&&(this.envMap=t[e.envMap]||null),e.envMapRotation!==void 0&&this.envMapRotation.fromArray(e.envMapRotation),e.envMapIntensity!==void 0&&(this.envMapIntensity=e.envMapIntensity),e.reflectivity!==void 0&&(this.reflectivity=e.reflectivity),e.refractionRatio!==void 0&&(this.refractionRatio=e.refractionRatio),e.lightMap!==void 0&&(this.lightMap=t[e.lightMap]||null),e.lightMapIntensity!==void 0&&(this.lightMapIntensity=e.lightMapIntensity),e.aoMap!==void 0&&(this.aoMap=t[e.aoMap]||null),e.aoMapIntensity!==void 0&&(this.aoMapIntensity=e.aoMapIntensity),e.gradientMap!==void 0&&(this.gradientMap=t[e.gradientMap]||null),e.clearcoatMap!==void 0&&(this.clearcoatMap=t[e.clearcoatMap]||null),e.clearcoatRoughnessMap!==void 0&&(this.clearcoatRoughnessMap=t[e.clearcoatRoughnessMap]||null),e.clearcoatNormalMap!==void 0&&(this.clearcoatNormalMap=t[e.clearcoatNormalMap]||null),e.clearcoatNormalScale!==void 0&&(this.clearcoatNormalScale=new De().fromArray(e.clearcoatNormalScale)),e.diffuseRoughnessMap!==void 0&&(this.diffuseRoughnessMap=t[e.diffuseRoughnessMap]||null),e.iridescenceMap!==void 0&&(this.iridescenceMap=t[e.iridescenceMap]||null),e.iridescenceThicknessMap!==void 0&&(this.iridescenceThicknessMap=t[e.iridescenceThicknessMap]||null),e.transmissionMap!==void 0&&(this.transmissionMap=t[e.transmissionMap]||null),e.thicknessMap!==void 0&&(this.thicknessMap=t[e.thicknessMap]||null),e.anisotropyMap!==void 0&&(this.anisotropyMap=t[e.anisotropyMap]||null),e.sheenColorMap!==void 0&&(this.sheenColorMap=t[e.sheenColorMap]||null),e.sheenRoughnessMap!==void 0&&(this.sheenRoughnessMap=t[e.sheenRoughnessMap]||null),this}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 r=t.length;n=new Array(r);for(let s=0;s!==r;++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.allowOverride=e.allowOverride,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++}},vi=class extends mn{constructor(e){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new W(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.rotation=e.rotation,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}},Ks,ia=new U,Zs=new U,Js=new U,js=new De,ra=new De,mx=new Be,Wl=new U,sa=new U,Xl=new U,j0=new De,af=new De,Q0=new De,ji=class extends Et{constructor(e=new vi){if(super(),this.isSprite=!0,this.type="Sprite",Ks===void 0){Ks=new Fe;let t=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),n=new us(t,5);Ks.setIndex([0,1,2,0,2,3]),Ks.setAttribute("position",new Cr(n,3,0,!1)),Ks.setAttribute("uv",new Cr(n,2,3,!1))}this.geometry=Ks,this.material=e,this.center=new De(.5,.5),this.count=1}intersectsFrustum(e){return e.intersectsSprite(this)}raycast(e,t){e.camera===null&&Ge('Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),Zs.setFromMatrixScale(this.matrixWorld),mx.copy(e.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(e.camera.matrixWorldInverse,this.matrixWorld),Js.setFromMatrixPosition(this.modelViewMatrix),e.camera.isPerspectiveCamera&&this.material.sizeAttenuation===!1&&Zs.multiplyScalar(-Js.z);let n=this.material.rotation,r,s;n!==0&&(s=Math.cos(n),r=Math.sin(n));let o=this.center;Yl(Wl.set(-.5,-.5,0),Js,o,Zs,r,s),Yl(sa.set(.5,-.5,0),Js,o,Zs,r,s),Yl(Xl.set(.5,.5,0),Js,o,Zs,r,s),j0.set(0,0),af.set(1,0),Q0.set(1,1);let a=e.ray.intersectTriangle(Wl,sa,Xl,!1,ia);if(a===null&&(Yl(sa.set(-.5,.5,0),Js,o,Zs,r,s),af.set(0,1),a=e.ray.intersectTriangle(Wl,Xl,sa,!1,ia),a===null))return;let l=e.ray.origin.distanceTo(ia);l<e.near||l>e.far||t.push({distance:l,point:ia.clone(),uv:Yi.getInterpolation(ia,Wl,sa,Xl,j0,af,Q0,new De),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}toJSON(e){let t=super.toJSON(e);return t.object.center=this.center.toArray(),t}};function Yl(i,e,t,n,r,s){js.subVectors(i,t).addScalar(.5).multiply(n),r!==void 0?(ra.x=s*js.x-r*js.y,ra.y=r*js.x+s*js.y):ra.copy(js),i.copy(e),i.x+=ra.x,i.y+=ra.y,i.applyMatrix4(mx)}var Wi=new U,lf=new U,ql=new U,$l=new U,Pr=class{constructor(e=new U,t=new U(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,Wi)),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=Wi.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(Wi.copy(this.origin).addScaledVector(this.direction,t),Wi.distanceToSquared(e))}distanceSqToSegment(e,t,n,r){lf.copy(e).add(t).multiplyScalar(.5),ql.copy(t).sub(e).normalize(),$l.copy(this.origin).sub(lf);let s=e.distanceTo(t)*.5,o=-this.direction.dot(ql),a=$l.dot(this.direction),l=-$l.dot(ql),c=$l.lengthSq(),u=Math.abs(1-o*o),h,f,d,p;if(u>0)if(h=o*l-a,f=o*a-l,p=s*u,h>=0)if(f>=-p)if(f<=p){let x=1/u;h*=x,f*=x,d=h*(h+o*f+2*a)+f*(o*h+f+2*l)+c}else f=s,h=Math.max(0,-(o*f+a)),d=-h*h+f*(f+2*l)+c;else f=-s,h=Math.max(0,-(o*f+a)),d=-h*h+f*(f+2*l)+c;else f<=-p?(h=Math.max(0,-(-o*s+a)),f=h>0?-s:Math.min(Math.max(-s,-l),s),d=-h*h+f*(f+2*l)+c):f<=p?(h=0,f=Math.min(Math.max(-s,-l),s),d=f*(f+2*l)+c):(h=Math.max(0,-(o*s+a)),f=h>0?s:Math.min(Math.max(-s,-l),s),d=-h*h+f*(f+2*l)+c);else f=o>0?-s:s,h=Math.max(0,-(o*f+a)),d=-h*h+f*(f+2*l)+c;return n&&n.copy(this.origin).addScaledVector(this.direction,h),r&&r.copy(lf).addScaledVector(ql,f),d}intersectSphere(e,t){if(e.radius<0)return null;Wi.subVectors(e.center,this.origin);let n=Wi.dot(this.direction),r=Wi.dot(Wi)-n*n,s=e.radius*e.radius;if(r>s)return null;let o=Math.sqrt(s-r),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,r,s,o,a,l,c=1/this.direction.x,u=1/this.direction.y,h=1/this.direction.z,f=this.origin;return c>=0?(n=(e.min.x-f.x)*c,r=(e.max.x-f.x)*c):(n=(e.max.x-f.x)*c,r=(e.min.x-f.x)*c),u>=0?(s=(e.min.y-f.y)*u,o=(e.max.y-f.y)*u):(s=(e.max.y-f.y)*u,o=(e.min.y-f.y)*u),n>o||s>r||((s>n||isNaN(n))&&(n=s),(o<r||isNaN(r))&&(r=o),h>=0?(a=(e.min.z-f.z)*h,l=(e.max.z-f.z)*h):(a=(e.max.z-f.z)*h,l=(e.min.z-f.z)*h),n>l||a>r)||((a>n||n!==n)&&(n=a),(l<r||r!==r)&&(r=l),r<0)?null:this.at(n>=0?n:r,t)}intersectsBox(e){return this.intersectBox(e,Wi)!==null}intersectTriangle(e,t,n,r,s){let o=this.origin,a=this.direction,l=a.x,c=a.y,u=a.z,h=e.x-o.x,f=e.y-o.y,d=e.z-o.z,p=t.x-o.x,x=t.y-o.y,g=t.z-o.z,m=n.x-o.x,b=n.y-o.y,v=n.z-o.z,y=Math.abs(l),M=Math.abs(c),S=Math.abs(u),_,w,R,A,C,O,D,P,I,N,F,H;if(y>=M&&y>=S?(R=l,O=h,I=p,H=m,l>=0?(_=c,w=u,A=f,C=d,D=x,P=g,N=b,F=v):(_=u,w=c,A=d,C=f,D=g,P=x,N=v,F=b)):M>=S?(R=c,O=f,I=x,H=b,c>=0?(_=u,w=l,A=d,C=h,D=g,P=p,N=v,F=m):(_=l,w=u,A=h,C=d,D=p,P=g,N=m,F=v)):(R=u,O=d,I=g,H=v,u>=0?(_=l,w=c,A=h,C=f,D=p,P=x,N=m,F=b):(_=c,w=l,A=f,C=h,D=x,P=p,N=b,F=m)),R===0)return null;let B=_/R,X=w/R,V=1/R,re=A-B*O,be=C-X*O,Y=D-B*I,Q=P-X*I,se=N-B*H,Se=F-X*H,le=se*Q-Se*Y,Ie=re*Se-be*se,st=Y*be-Q*re;if(r){if(le<0||Ie<0||st<0)return null}else if((le<0||Ie<0||st<0)&&(le>0||Ie>0||st>0))return null;let Te=le+Ie+st;if(Te===0)return null;let ht=V*(le*O+Ie*I+st*H);return(Te>0?ht<0:ht>0)?null:this.at(ht/Te,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)}},Ke=class extends mn{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new W(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 _i,this.combine=kc,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}},eg=new Be,rs=new Pr,Kl=new Cn,tg=new U,Zl=new U,Jl=new U,jl=new U,cf=new U,Ql=new U,ng=new U,ec=new U,we=class extends Et{constructor(e=new Fe,t=new Ke){super(),this.isMesh=!0,this.type="Mesh",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0?this.morphTargetInfluences=e.morphTargetInfluences.slice():this.morphTargetInfluences=void 0,e.morphTargetDictionary!==void 0?this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary):this.morphTargetDictionary=void 0,this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){let t=this.geometry.morphAttributes,n=Object.keys(t);if(n.length>0){let r=t[n[0]];if(r!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=r.length;s<o;s++){let a=r[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=s}}}}getVertexPosition(e,t){let n=this.geometry,r=n.attributes.position,s=n.morphAttributes.position,o=n.morphTargetsRelative;t.fromBufferAttribute(r,e);let a=this.morphTargetInfluences;if(s&&a){Ql.set(0,0,0);for(let l=0,c=s.length;l<c;l++){let u=a[l],h=s[l];u!==0&&(cf.fromBufferAttribute(h,e),o?Ql.addScaledVector(cf,u):Ql.addScaledVector(cf.sub(t),u))}t.add(Ql)}return t}intersectsFrustum(e){return e.intersectsObject(this)}raycast(e,t){let n=this.geometry,r=this.material,s=this.matrixWorld;r!==void 0&&(n.boundingSphere===null&&n.computeBoundingSphere(),Kl.copy(n.boundingSphere),Kl.applyMatrix4(s),rs.copy(e.ray).recast(e.near),!(Kl.containsPoint(rs.origin)===!1&&(rs.intersectSphere(Kl,tg)===null||rs.origin.distanceToSquared(tg)>(e.far-e.near)**2))&&(eg.copy(s).invert(),rs.copy(e.ray).applyMatrix4(eg),!(n.boundingBox!==null&&rs.intersectsBox(n.boundingBox)===!1)&&this._computeIntersections(e,t,rs)))}_computeIntersections(e,t,n){let r,s=this.geometry,o=this.material,a=s.index,l=s.attributes.position,c=s.attributes.uv,u=s.attributes.uv1,h=s.attributes.normal,f=s.groups,d=s.drawRange;if(a!==null)if(Array.isArray(o))for(let p=0,x=f.length;p<x;p++){let g=f[p],m=o[g.materialIndex],b=Math.max(g.start,d.start),v=Math.min(a.count,Math.min(g.start+g.count,d.start+d.count));for(let y=b,M=v;y<M;y+=3){let S=a.getX(y),_=a.getX(y+1),w=a.getX(y+2);r=tc(this,m,e,n,c,u,h,S,_,w),r&&(r.faceIndex=Math.floor(y/3),r.face.materialIndex=g.materialIndex,t.push(r))}}else{let p=Math.max(0,d.start),x=Math.min(a.count,d.start+d.count);for(let g=p,m=x;g<m;g+=3){let b=a.getX(g),v=a.getX(g+1),y=a.getX(g+2);r=tc(this,o,e,n,c,u,h,b,v,y),r&&(r.faceIndex=Math.floor(g/3),t.push(r))}}else if(l!==void 0)if(Array.isArray(o))for(let p=0,x=f.length;p<x;p++){let g=f[p],m=o[g.materialIndex],b=Math.max(g.start,d.start),v=Math.min(l.count,Math.min(g.start+g.count,d.start+d.count));for(let y=b,M=v;y<M;y+=3){let S=y,_=y+1,w=y+2;r=tc(this,m,e,n,c,u,h,S,_,w),r&&(r.faceIndex=Math.floor(y/3),r.face.materialIndex=g.materialIndex,t.push(r))}}else{let p=Math.max(0,d.start),x=Math.min(l.count,d.start+d.count);for(let g=p,m=x;g<m;g+=3){let b=g,v=g+1,y=g+2;r=tc(this,o,e,n,c,u,h,b,v,y),r&&(r.faceIndex=Math.floor(g/3),t.push(r))}}}};function q1(i,e,t,n,r,s,o,a){let l;if(e.side===un?l=n.intersectTriangle(o,s,r,!0,a):l=n.intersectTriangle(r,s,o,e.side===Ti,a),l===null)return null;ec.copy(a),ec.applyMatrix4(i.matrixWorld);let c=t.ray.origin.distanceTo(ec);return c<t.near||c>t.far?null:{distance:c,point:ec.clone(),object:i}}function tc(i,e,t,n,r,s,o,a,l,c){i.getVertexPosition(a,Zl),i.getVertexPosition(l,Jl),i.getVertexPosition(c,jl);let u=q1(i,e,t,n,Zl,Jl,jl,ng);if(u){let h=new U;Yi.getBarycoord(ng,Zl,Jl,jl,h),r&&(u.uv=Yi.getInterpolatedAttribute(r,a,l,c,h,new De)),s&&(u.uv1=Yi.getInterpolatedAttribute(s,a,l,c,h,new De)),o&&(u.normal=Yi.getInterpolatedAttribute(o,a,l,c,h,new U),u.normal.dot(n.direction)>0&&u.normal.multiplyScalar(-1));let f={a,b:l,c,normal:new U,materialIndex:0};Yi.getNormal(Zl,Jl,jl,f.normal),u.face=f,u.barycoord=h}return u}var oa=new _t,ig=new _t,rg=new _t,$1=new _t,sg=new Be,nc=new U,uf=new Cn,og=new Be,hf=new Pr,ba=class extends we{constructor(e,t){super(e,t),this.isSkinnedMesh=!0,this.type="SkinnedMesh",this.bindMode=mf,this.bindMatrix=new Be,this.bindMatrixInverse=new Be,this.boundingBox=null,this.boundingSphere=null}computeBoundingBox(){let e=this.geometry;this.boundingBox===null&&(this.boundingBox=new Ct),this.boundingBox.makeEmpty();let t=e.getAttribute("position");for(let n=0;n<t.count;n++)this.getVertexPosition(n,nc),this.boundingBox.expandByPoint(nc)}computeBoundingSphere(){let e=this.geometry;this.boundingSphere===null&&(this.boundingSphere=new Cn),this.boundingSphere.makeEmpty();let t=e.getAttribute("position");for(let n=0;n<t.count;n++)this.getVertexPosition(n,nc),this.boundingSphere.expandByPoint(nc)}copy(e,t){return super.copy(e,t),this.bindMode=e.bindMode,this.bindMatrix.copy(e.bindMatrix),this.bindMatrixInverse.copy(e.bindMatrixInverse),this.skeleton=e.skeleton,this.boundingBox=e.boundingBox!==null?e.boundingBox.clone():null,this.boundingSphere=e.boundingSphere!==null?e.boundingSphere.clone():null,this}raycast(e,t){let n=this.material,r=this.matrixWorld;n!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),uf.copy(this.boundingSphere),uf.applyMatrix4(r),e.ray.intersectsSphere(uf)!==!1&&(og.copy(r).invert(),hf.copy(e.ray).applyMatrix4(og),!(this.boundingBox!==null&&hf.intersectsBox(this.boundingBox)===!1)&&this._computeIntersections(e,t,hf)))}getVertexPosition(e,t){return super.getVertexPosition(e,t),this.applyBoneTransform(e,t),t}bind(e,t){this.skeleton=e,t===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),t=this.matrixWorld),this.bindMatrix.copy(t),this.bindMatrixInverse.copy(t).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(){let e=new _t,t=this.geometry.attributes.skinWeight;for(let n=0,r=t.count;n<r;n++){e.fromBufferAttribute(t,n);let s=1/e.manhattanLength();s!==1/0?e.multiplyScalar(s):e.set(1,0,0,0),t.setXYZW(n,e.x,e.y,e.z,e.w)}}updateMatrixWorld(e){super.updateMatrixWorld(e),this.bindMode===mf?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode===ex?this.bindMatrixInverse.copy(this.bindMatrix).invert():Le("SkinnedMesh: Unrecognized bindMode: "+this.bindMode)}applyBoneTransform(e,t){let n=this.skeleton,r=this.geometry;ig.fromBufferAttribute(r.attributes.skinIndex,e),rg.fromBufferAttribute(r.attributes.skinWeight,e),t.isVector4?(oa.copy(t),t.set(0,0,0,0)):(oa.set(t.x,t.y,t.z,1),t.set(0,0,0)),oa.applyMatrix4(this.bindMatrix);for(let s=0;s<4;s++){let o=rg.getComponent(s);if(o!==0){let a=ig.getComponent(s);sg.multiplyMatrices(n.bones[a].matrixWorld,n.boneInverses[a]),t.addScaledVector($1.copy(oa).applyMatrix4(sg),o)}}return t.isVector4&&(t.w=oa.w),t.applyMatrix4(this.bindMatrixInverse)}},ho=class extends Et{constructor(){super(),this.isBone=!0,this.type="Bone"}},fo=class extends Kt{constructor(e=null,t=1,n=1,r,s,o,a,l,c=Ut,u=Ut,h,f){super(null,o,a,l,c,u,r,s,h,f),this.isDataTexture=!0,this.image={data:e,width:t,height:n},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}},ag=new Be,K1=new Be,ya=class i{constructor(e=[],t=[]){this.uuid=Ri(),this.bones=e.slice(0),this.boneInverses=t,this.boneMatrices=null,this.previousBoneMatrices=null,this.boneTexture=null,this.previousBoneTexture=null,this.init()}init(){let e=this.bones,t=this.boneInverses;if(this.boneMatrices=new Float32Array(e.length*16),t.length===0)this.calculateInverses();else if(e.length!==t.length){Le("Skeleton: Number of inverse bone matrices does not match amount of bones."),this.boneInverses=[];for(let n=0,r=this.bones.length;n<r;n++)this.boneInverses.push(new Be)}}calculateInverses(){this.boneInverses.length=0;for(let e=0,t=this.bones.length;e<t;e++){let n=new Be;this.bones[e]&&n.copy(this.bones[e].matrixWorld).invert(),this.boneInverses.push(n)}}pose(){for(let e=0,t=this.bones.length;e<t;e++){let n=this.bones[e];n&&n.matrixWorld.copy(this.boneInverses[e]).invert()}for(let e=0,t=this.bones.length;e<t;e++){let n=this.bones[e];n&&(n.parent&&n.parent.isBone?(n.matrix.copy(n.parent.matrixWorld).invert(),n.matrix.multiply(n.matrixWorld)):n.matrix.copy(n.matrixWorld),n.matrix.decompose(n.position,n.quaternion,n.scale))}}update(){let e=this.bones,t=this.boneInverses,n=this.boneMatrices,r=this.boneTexture;for(let s=0,o=e.length;s<o;s++){let a=e[s]?e[s].matrixWorld:K1;ag.multiplyMatrices(a,t[s]),ag.toArray(n,s*16)}r!==null&&(r.needsUpdate=!0)}clone(){return new i(this.bones,this.boneInverses)}computeBoneTexture(){let e=Math.sqrt(this.bones.length*4);e=Math.ceil(e/4)*4,e=Math.max(e,4);let t=new Float32Array(e*e*4);t.set(this.boneMatrices);let n=new fo(t,e,e,Nn,Vn);return n.needsUpdate=!0,this.boneMatrices=t,this.boneTexture=n,this}getBoneByName(e){for(let t=0,n=this.bones.length;t<n;t++){let r=this.bones[t];if(r.name===e)return r}}dispose(){this.boneTexture!==null&&(this.boneTexture.dispose(),this.boneTexture=null),this.previousBoneTexture!==null&&(this.previousBoneTexture.dispose(),this.previousBoneTexture=null)}fromJSON(e,t){this.uuid=e.uuid;for(let n=0,r=e.bones.length;n<r;n++){let s=e.bones[n],o=t[s];o===void 0&&(Le("Skeleton: No bone found with UUID:",s),o=new ho),this.bones.push(o),this.boneInverses.push(new Be().fromArray(e.boneInverses[n]))}return this.init(),this}toJSON(){let e={metadata:{version:4.7,type:"Skeleton",generator:"Skeleton.toJSON"},bones:[],boneInverses:[]};e.uuid=this.uuid;let t=this.bones,n=this.boneInverses;for(let r=0,s=t.length;r<s;r++){let o=t[r];e.bones.push(o.uuid);let a=n[r];e.boneInverses.push(a.toArray())}return e}},Qi=class extends wt{constructor(e,t,n,r=1){super(e,t,n),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=r}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}toJSON(){let e=super.toJSON();return e.meshPerAttribute=this.meshPerAttribute,e.isInstancedBufferAttribute=!0,e}},Qs=new Be,lg=new Be,ic=[],cg=new Ct,Z1=new Be,aa=new we,la=new Cn,hs=class extends we{constructor(e,t,n){super(e,t),this.isInstancedMesh=!0,this.instanceMatrix=new Qi(new Float32Array(n*16),16),this.instanceColor=null,this.morphTexture=null,this.count=n,this.boundingBox=null,this.boundingSphere=null;for(let r=0;r<n;r++)this.setMatrixAt(r,Z1)}computeBoundingBox(){let e=this.geometry,t=this.count;this.boundingBox===null&&(this.boundingBox=new Ct),e.boundingBox===null&&e.computeBoundingBox(),this.boundingBox.makeEmpty();for(let n=0;n<t;n++)this.getMatrixAt(n,Qs),cg.copy(e.boundingBox).applyMatrix4(Qs),this.boundingBox.union(cg)}computeBoundingSphere(){let e=this.geometry,t=this.count;this.boundingSphere===null&&(this.boundingSphere=new Cn),e.boundingSphere===null&&e.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let n=0;n<t;n++)this.getMatrixAt(n,Qs),la.copy(e.boundingSphere).applyMatrix4(Qs),this.boundingSphere.union(la)}copy(e,t){return super.copy(e,t),this.instanceMatrix.copy(e.instanceMatrix),this.morphTexture=e.morphTexture!==null?e.morphTexture.clone():null,this.instanceColor=e.instanceColor!==null?e.instanceColor.clone():null,this.count=e.count,this.boundingBox=e.boundingBox!==null?e.boundingBox.clone():null,this.boundingSphere=e.boundingSphere!==null?e.boundingSphere.clone():null,this}getColorAt(e,t){return this.instanceColor===null?t.setRGB(1,1,1):t.fromArray(this.instanceColor.array,e*3)}getMatrixAt(e,t){return t.fromArray(this.instanceMatrix.array,e*16)}getMorphAt(e,t){let n=t.morphTargetInfluences,r=this.morphTexture.source.data.data,s=n.length+1,o=e*s+1;for(let a=0;a<n.length;a++)n[a]=r[o+a]}raycast(e,t){let n=this.matrixWorld,r=this.count;if(aa.geometry=this.geometry,aa.material=this.material,aa.material!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),la.copy(this.boundingSphere),la.applyMatrix4(n),e.ray.intersectsSphere(la)!==!1))for(let s=0;s<r;s++){this.getMatrixAt(s,Qs),lg.multiplyMatrices(n,Qs),aa.matrixWorld=lg,aa.raycast(e,ic);for(let o=0,a=ic.length;o<a;o++){let l=ic[o];l.instanceId=s,l.object=this,t.push(l)}ic.length=0}}setColorAt(e,t){return this.instanceColor===null&&(this.instanceColor=new Qi(new Float32Array(this.instanceMatrix.count*3).fill(1),3)),t.toArray(this.instanceColor.array,e*3),this}setMatrixAt(e,t){return t.toArray(this.instanceMatrix.array,e*16),this}setMorphAt(e,t){let n=t.morphTargetInfluences,r=n.length+1;this.morphTexture===null&&(this.morphTexture=new fo(new Float32Array(r*this.count),r,this.count,Xc,Vn));let s=this.morphTexture.source.data.data,o=0;for(let c=0;c<n.length;c++)o+=n[c];let a=this.geometry.morphTargetsRelative?1:1-o,l=r*e;return s[l]=a,s.set(n,l+1),this}updateMorphTargets(){}dispose(){super.dispose(),this.instanceMatrix.dispose(),this.instanceColor!==null&&this.instanceColor.dispose(),this.morphTexture!==null&&(this.morphTexture.dispose(),this.morphTexture=null)}},ss=new Cn,J1=new De(.5,.5),rc=new U,Ir=class{constructor(e=new si,t=new si,n=new si,r=new si,s=new si,o=new si){this.planes=[e,t,n,r,s,o]}set(e,t,n,r,s,o){let a=this.planes;return a[0].copy(e),a[1].copy(t),a[2].copy(n),a[3].copy(r),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=$n,n=!1){let r=this.planes,s=e.elements,o=s[0],a=s[1],l=s[2],c=s[3],u=s[4],h=s[5],f=s[6],d=s[7],p=s[8],x=s[9],g=s[10],m=s[11],b=s[12],v=s[13],y=s[14],M=s[15];if(r[0].setComponents(c-o,d-u,m-p,M-b).normalize(),r[1].setComponents(c+o,d+u,m+p,M+b).normalize(),r[2].setComponents(c+a,d+h,m+x,M+v).normalize(),r[3].setComponents(c-a,d-h,m-x,M-v).normalize(),n)r[4].setComponents(l,f,g,y).normalize(),r[5].setComponents(c-l,d-f,m-g,M-y).normalize();else if(r[4].setComponents(c-l,d-f,m-g,M-y).normalize(),t===$n)r[5].setComponents(c+l,d+f,m+g,M+y).normalize();else if(t===so)r[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(),ss.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{let t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),ss.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(ss)}intersectsSprite(e){ss.center.set(0,0,0);let t=J1.distanceTo(e.center);return ss.radius=.7071067811865476+t,ss.applyMatrix4(e.matrixWorld),this.intersectsSphere(ss)}intersectsSphere(e){let t=this.planes,n=e.center,r=-e.radius;for(let s=0;s<6;s++)if(t[s].distanceToPoint(n)<r)return!1;return!0}intersectsBox(e){let t=this.planes;for(let n=0;n<6;n++){let r=t[n];if(rc.x=r.normal.x>0?e.max.x:e.min.x,rc.y=r.normal.y>0?e.max.y:e.min.y,rc.z=r.normal.z>0?e.max.z:e.min.z,r.distanceToPoint(rc)<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)}},ug=new Be,wc=class i{constructor(){this.coordinateSystem=$n,this._frustums=[],this._count=0}setFromArrayCamera(e){let t=e.cameras,n=this._frustums;for(let r=0;r<t.length;r++){let s=t[r];ug.multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse),n[r]===void 0&&(n[r]=new Ir),n[r].setFromProjectionMatrix(ug,s.coordinateSystem,s.reversedDepth)}return this._count=t.length,this}getFrustum(e){return this._frustums[e]}intersectsObject(e){let t=this._frustums;for(let n=0;n<this._count;n++)if(t[n].intersectsObject(e))return!0;return!1}intersectsSprite(e){let t=this._frustums;for(let n=0;n<this._count;n++)if(t[n].intersectsSprite(e))return!0;return!1}intersectsSphere(e){let t=this._frustums;for(let n=0;n<this._count;n++)if(t[n].intersectsSphere(e))return!0;return!1}intersectsBox(e){let t=this._frustums;for(let n=0;n<this._count;n++)if(t[n].intersectsBox(e))return!0;return!1}containsPoint(e){let t=this._frustums;for(let n=0;n<this._count;n++)if(t[n].containsPoint(e))return!0;return!1}copy(e){this.coordinateSystem=e.coordinateSystem;let t=this._frustums,n=e._frustums;for(let r=0;r<e._count;r++)t[r]===void 0&&(t[r]=new Ir),t[r].copy(n[r]);return this._count=e._count,this}clone(){return new i().copy(this)}};var Lt=class extends mn{constructor(e){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new W(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.linewidth=e.linewidth,this.linecap=e.linecap,this.linejoin=e.linejoin,this.fog=e.fog,this}},Tc=new U,Ac=new U,hg=new Be,ca=new Pr,sc=new Cn,ff=new U,fg=new U,Pn=class extends Et{constructor(e=new Fe,t=new Lt){super(),this.isLine=!0,this.type="Line",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0?this.morphTargetInfluences=e.morphTargetInfluences.slice():this.morphTargetInfluences=void 0,e.morphTargetDictionary!==void 0?this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary):this.morphTargetDictionary=void 0,this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}computeLineDistances(){let e=this.geometry;if(e.index===null){let t=e.attributes.position,n=[0];for(let r=1,s=t.count;r<s;r++)Tc.fromBufferAttribute(t,r-1),Ac.fromBufferAttribute(t,r),n[r]=n[r-1],n[r]+=Tc.distanceTo(Ac);e.setAttribute("lineDistance",new ke(n,1))}else Le("Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}intersectsFrustum(e){return e.intersectsObject(this)}raycast(e,t){let n=this.geometry,r=this.matrixWorld,s=e.params.Line.threshold,o=n.drawRange;if(n.boundingSphere===null&&n.computeBoundingSphere(),sc.copy(n.boundingSphere),sc.applyMatrix4(r),sc.radius+=s,e.ray.intersectsSphere(sc)===!1)return;hg.copy(r).invert(),ca.copy(e.ray).applyMatrix4(hg);let a=s/((this.scale.x+this.scale.y+this.scale.z)/3),l=a*a,c=this.isLineSegments?2:1,u=n.index,f=n.attributes.position;if(u!==null){let d=Math.max(0,o.start),p=Math.min(u.count,o.start+o.count);for(let x=d,g=p-1;x<g;x+=c){let m=u.getX(x),b=u.getX(x+1),v=oc(this,e,ca,l,m,b,x);v&&t.push(v)}if(this.isLineLoop){let x=u.getX(p-1),g=u.getX(d),m=oc(this,e,ca,l,x,g,p-1);m&&t.push(m)}}else{let d=Math.max(0,o.start),p=Math.min(f.count,o.start+o.count);for(let x=d,g=p-1;x<g;x+=c){let m=oc(this,e,ca,l,x,x+1,x);m&&t.push(m)}if(this.isLineLoop){let x=oc(this,e,ca,l,p-1,d,p-1);x&&t.push(x)}}}updateMorphTargets(){let t=this.geometry.morphAttributes,n=Object.keys(t);if(n.length>0){let r=t[n[0]];if(r!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=r.length;s<o;s++){let a=r[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=s}}}}};function oc(i,e,t,n,r,s,o){let a=i.geometry.attributes.position;if(Tc.fromBufferAttribute(a,r),Ac.fromBufferAttribute(a,s),t.distanceSqToSegment(Tc,Ac,ff,fg)>n)return;ff.applyMatrix4(i.matrixWorld);let c=e.ray.origin.distanceTo(ff);if(!(c<e.near||c>e.far))return{distance:c,point:fg.clone().applyMatrix4(i.matrixWorld),index:o,face:null,faceIndex:null,barycoord:null,object:i}}var dg=new U,pg=new U,gn=class extends Pn{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 r=0,s=t.count;r<s;r+=2)dg.fromBufferAttribute(t,r),pg.fromBufferAttribute(t,r+1),n[r]=r===0?0:n[r-1],n[r+1]=n[r]+dg.distanceTo(pg);e.setAttribute("lineDistance",new ke(n,1))}else Le("LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}},_a=class extends Pn{constructor(e,t){super(e,t),this.isLineLoop=!0,this.type="LineLoop"}},cn=class extends mn{constructor(e){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new W(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.size=e.size,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}},mg=new Be,_f=new Pr,ac=new Cn,lc=new U,xn=class extends Et{constructor(e=new Fe,t=new cn){super(),this.isPoints=!0,this.type="Points",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0?this.morphTargetInfluences=e.morphTargetInfluences.slice():this.morphTargetInfluences=void 0,e.morphTargetDictionary!==void 0?this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary):this.morphTargetDictionary=void 0,this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}intersectsFrustum(e){return e.intersectsObject(this)}raycast(e,t){let n=this.geometry,r=this.matrixWorld,s=e.params.Points.threshold,o=n.drawRange;if(n.boundingSphere===null&&n.computeBoundingSphere(),ac.copy(n.boundingSphere),ac.applyMatrix4(r),ac.radius+=s,e.ray.intersectsSphere(ac)===!1)return;mg.copy(r).invert(),_f.copy(e.ray).applyMatrix4(mg);let a=s/((this.scale.x+this.scale.y+this.scale.z)/3),l=a*a,c=n.index,h=n.attributes.position;if(c!==null){let f=Math.max(0,o.start),d=Math.min(c.count,o.start+o.count);for(let p=f,x=d;p<x;p++){let g=c.getX(p);lc.fromBufferAttribute(h,g),gg(lc,g,l,r,e,t,this)}}else{let f=Math.max(0,o.start),d=Math.min(h.count,o.start+o.count);for(let p=f,x=d;p<x;p++)lc.fromBufferAttribute(h,p),gg(lc,p,l,r,e,t,this)}}updateMorphTargets(){let t=this.geometry.morphAttributes,n=Object.keys(t);if(n.length>0){let r=t[n[0]];if(r!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let s=0,o=r.length;s<o;s++){let a=r[s].name||String(s);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=s}}}}};function gg(i,e,t,n,r,s,o){let a=_f.distanceSqToPoint(i);if(a<t){let l=new U;_f.closestPointToPoint(i,l),l.applyMatrix4(n);let c=r.ray.origin.distanceTo(l);if(c<r.near||c>r.far)return;s.push({distance:c,distanceToRay:Math.sqrt(a),point:l,index:e,face:null,faceIndex:null,barycoord:null,object:o})}}var Lr=class extends Kt{constructor(e=[],t,n,r,s,o,a,l,c,u,h,f){super(null,o,a,l,c,u,r,s,h,f),this.isCompressedTexture=!0,this.image={width:t,height:n},this.mipmaps=e,this.flipY=!1,this.generateMipmaps=!1}};var va=class extends Kt{constructor(e=[],t=xs,n,r,s,o,a,l,c,u){super(e,t,n,r,s,o,a,l,c,u),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}},zt=class extends Kt{constructor(e,t,n,r,s,o,a,l,c){super(e,t,n,r,s,o,a,l,c),this.isCanvasTexture=!0,this.needsUpdate=!0}};var er=class extends Kt{constructor(e,t,n=oi,r,s,o,a=Ut,l=Ut,c,u=$i,h=1){if(u!==$i&&u!==lr)throw new Error("THREE.DepthTexture: format must be either THREE.DepthFormat or THREE.DepthStencilFormat");let f={width:e,height:t,depth:h};super(f,r,s,o,a,l,u,n,c),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.source=new Ji(Object.assign({},e.image)),this.compareFunction=e.compareFunction,this}toJSON(e){let t=super.toJSON(e);return t.compareFunction=this.compareFunction,t}},Ma=class extends er{constructor(e,t=oi,n=xs,r,s,o=Ut,a=Ut,l,c=$i){let u={width:e,height:e,depth:1},h=[u,u,u,u,u,u];super(e,e,t,n,r,s,o,a,l,c),this.image=h,this.isCubeDepthTexture=!0,this.isCubeTexture=!0}get images(){return this.image}set images(e){this.image=e}},Sa=class extends Kt{constructor(e=null){super(),this.sourceTexture=e,this.isExternalTexture=!0}copy(e){return super.copy(e),this.sourceTexture=e.sourceTexture,this}},Fr=class i extends Fe{constructor(e=1,t=1,n=1,r=1,s=1,o=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:t,depth:n,widthSegments:r,heightSegments:s,depthSegments:o};let a=this;r=Math.floor(r),s=Math.floor(s),o=Math.floor(o);let l=[],c=[],u=[],h=[],f=0,d=0;p("z","y","x",-1,-1,n,t,e,o,s,0),p("z","y","x",1,-1,n,t,-e,o,s,1),p("x","z","y",1,1,e,n,t,r,o,2),p("x","z","y",1,-1,e,n,-t,r,o,3),p("x","y","z",1,-1,e,t,n,r,s,4),p("x","y","z",-1,-1,e,t,-n,r,s,5),this.setIndex(l),this.setAttribute("position",new ke(c,3)),this.setAttribute("normal",new ke(u,3)),this.setAttribute("uv",new ke(h,2));function p(x,g,m,b,v,y,M,S,_,w,R){let A=y/_,C=M/w,O=y/2,D=M/2,P=S/2,I=_+1,N=w+1,F=0,H=0,B=new U;for(let X=0;X<N;X++){let V=X*C-D;for(let re=0;re<I;re++){let be=re*A-O;B[x]=be*b,B[g]=V*v,B[m]=P,c.push(B.x,B.y,B.z),B[x]=0,B[g]=0,B[m]=S>0?1:-1,u.push(B.x,B.y,B.z),h.push(re/_),h.push(1-X/w),F+=1}}for(let X=0;X<w;X++)for(let V=0;V<_;V++){let re=f+V+I*X,be=f+V+I*(X+1),Y=f+(V+1)+I*(X+1),Q=f+(V+1)+I*X;l.push(re,be,Q),l.push(be,Y,Q),H+=6}a.addGroup(d,H,R),d+=H,f+=F}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new i(e.width,e.height,e.depth,e.widthSegments,e.heightSegments,e.depthSegments)}};function j1(i,e,t=2){let n=e&&e.length,r=n?e[0]*t:i.length,s=gx(i,0,r,t,!0),o=[];if(!s||s.next===s.prev)return o;let a,l,c;if(n&&(s=iS(i,e,s,t)),i.length>80*t){a=i[0],l=i[1];let u=a,h=l;for(let f=t;f<r;f+=t){let d=i[f],p=i[f+1];d<a&&(a=d),p<l&&(l=p),d>u&&(u=d),p>h&&(h=p)}c=Math.max(u-a,h-l),c=c!==0?32767/c:0}return wa(s,o,t,a,l,c,0),o}function gx(i,e,t,n,r){let s;if(r===pS(i,e,t,n)>0)for(let o=e;o<t;o+=n)s=xg(o/n|0,i[o],i[o+1],s);else for(let o=t-n;o>=e;o-=n)s=xg(o/n|0,i[o],i[o+1],s);return s&&po(s,s.next)&&(Aa(s),s=s.next),s}function fs(i,e){if(!i)return i;e||(e=i);let t=i,n;do if(n=!1,!t.steiner&&(po(t,t.next)||Dt(t.prev,t,t.next)===0)){if(Aa(t),t=e=t.prev,t===t.next)break;n=!0}else t=t.next;while(n||t!==e);return e}function wa(i,e,t,n,r,s,o){if(!i)return;!o&&s&&lS(i,n,r,s);let a=i;for(;i.prev!==i.next;){let l=i.prev,c=i.next;if(s?eS(i,n,r,s):Q1(i)){e.push(l.i,i.i,c.i),Aa(i),i=c.next,a=c.next;continue}if(i=c,i===a){o?o===1?(i=tS(fs(i),e),wa(i,e,t,n,r,s,2)):o===2&&nS(i,e,t,n,r,s):wa(fs(i),e,t,n,r,s,1);break}}}function Q1(i){let e=i.prev,t=i,n=i.next;if(Dt(e,t,n)>=0)return!1;let r=e.x,s=t.x,o=n.x,a=e.y,l=t.y,c=n.y,u=Math.min(r,s,o),h=Math.min(a,l,c),f=Math.max(r,s,o),d=Math.max(a,l,c),p=n.next;for(;p!==e;){if(p.x>=u&&p.x<=f&&p.y>=h&&p.y<=d&&ua(r,a,s,l,o,c,p.x,p.y)&&Dt(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function eS(i,e,t,n){let r=i.prev,s=i,o=i.next;if(Dt(r,s,o)>=0)return!1;let a=r.x,l=s.x,c=o.x,u=r.y,h=s.y,f=o.y,d=Math.min(a,l,c),p=Math.min(u,h,f),x=Math.max(a,l,c),g=Math.max(u,h,f),m=vf(d,p,e,t,n),b=vf(x,g,e,t,n),v=i.prevZ,y=i.nextZ;for(;v&&v.z>=m&&y&&y.z<=b;){if(v.x>=d&&v.x<=x&&v.y>=p&&v.y<=g&&v!==r&&v!==o&&ua(a,u,l,h,c,f,v.x,v.y)&&Dt(v.prev,v,v.next)>=0||(v=v.prevZ,y.x>=d&&y.x<=x&&y.y>=p&&y.y<=g&&y!==r&&y!==o&&ua(a,u,l,h,c,f,y.x,y.y)&&Dt(y.prev,y,y.next)>=0))return!1;y=y.nextZ}for(;v&&v.z>=m;){if(v.x>=d&&v.x<=x&&v.y>=p&&v.y<=g&&v!==r&&v!==o&&ua(a,u,l,h,c,f,v.x,v.y)&&Dt(v.prev,v,v.next)>=0)return!1;v=v.prevZ}for(;y&&y.z<=b;){if(y.x>=d&&y.x<=x&&y.y>=p&&y.y<=g&&y!==r&&y!==o&&ua(a,u,l,h,c,f,y.x,y.y)&&Dt(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function tS(i,e){let t=i;do{let n=t.prev,r=t.next.next;!po(n,r)&&bx(n,t,t.next,r)&&Ta(n,r)&&Ta(r,n)&&(e.push(n.i,t.i,r.i),Aa(t),Aa(t.next),t=i=r),t=t.next}while(t!==i);return fs(t)}function nS(i,e,t,n,r,s){let o=i;do{let a=o.next.next;for(;a!==o.prev;){if(o.i!==a.i&&hS(o,a)){let l=yx(o,a);o=fs(o,o.next),l=fs(l,l.next),wa(o,e,t,n,r,s,0),wa(l,e,t,n,r,s,0);return}a=a.next}o=o.next}while(o!==i)}function iS(i,e,t,n){let r=[];for(let s=0,o=e.length;s<o;s++){let a=e[s]*n,l=s<o-1?e[s+1]*n:i.length,c=gx(i,a,l,n,!1);c===c.next&&(c.steiner=!0),r.push(uS(c))}r.sort(rS);for(let s=0;s<r.length;s++)t=sS(r[s],t);return t}function rS(i,e){let t=i.x-e.x;if(t===0&&(t=i.y-e.y,t===0)){let n=(i.next.y-i.y)/(i.next.x-i.x),r=(e.next.y-e.y)/(e.next.x-e.x);t=n-r}return t}function sS(i,e){let t=oS(i,e);if(!t)return e;let n=yx(t,i);return fs(n,n.next),fs(t,t.next)}function oS(i,e){let t=e,n=i.x,r=i.y,s=-1/0,o;if(po(i,t))return t;do{if(po(i,t.next))return t.next;if(r<=t.y&&r>=t.next.y&&t.next.y!==t.y){let h=t.x+(r-t.y)*(t.next.x-t.x)/(t.next.y-t.y);if(h<=n&&h>s&&(s=h,o=t.x<t.next.x?t:t.next,h===n))return o}t=t.next}while(t!==e);if(!o)return null;let a=o,l=o.x,c=o.y,u=1/0;t=o;do{if(n>=t.x&&t.x>=l&&n!==t.x&&xx(r<c?n:s,r,l,c,r<c?s:n,r,t.x,t.y)){let h=Math.abs(r-t.y)/(n-t.x);Ta(t,i)&&(h<u||h===u&&(t.x>o.x||t.x===o.x&&aS(o,t)))&&(o=t,u=h)}t=t.next}while(t!==a);return o}function aS(i,e){return Dt(i.prev,i,e.prev)<0&&Dt(e.next,i,i.next)<0}function lS(i,e,t,n){let r=i;do r.z===0&&(r.z=vf(r.x,r.y,e,t,n)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next;while(r!==i);r.prevZ.nextZ=null,r.prevZ=null,cS(r)}function cS(i){let e,t=1;do{let n=i,r;i=null;let s=null;for(e=0;n;){e++;let o=n,a=0;for(let c=0;c<t&&(a++,o=o.nextZ,!!o);c++);let l=t;for(;a>0||l>0&&o;)a!==0&&(l===0||!o||n.z<=o.z)?(r=n,n=n.nextZ,a--):(r=o,o=o.nextZ,l--),s?s.nextZ=r:i=r,r.prevZ=s,s=r;n=o}s.nextZ=null,t*=2}while(e>1);return i}function vf(i,e,t,n,r){return i=(i-t)*r|0,e=(e-n)*r|0,i=(i|i<<8)&16711935,i=(i|i<<4)&252645135,i=(i|i<<2)&858993459,i=(i|i<<1)&1431655765,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,i|e<<1}function uS(i){let e=i,t=i;do(e.x<t.x||e.x===t.x&&e.y<t.y)&&(t=e),e=e.next;while(e!==i);return t}function xx(i,e,t,n,r,s,o,a){return(r-o)*(e-a)>=(i-o)*(s-a)&&(i-o)*(n-a)>=(t-o)*(e-a)&&(t-o)*(s-a)>=(r-o)*(n-a)}function ua(i,e,t,n,r,s,o,a){return!(i===o&&e===a)&&xx(i,e,t,n,r,s,o,a)}function hS(i,e){return i.next.i!==e.i&&i.prev.i!==e.i&&!fS(i,e)&&(Ta(i,e)&&Ta(e,i)&&dS(i,e)&&(Dt(i.prev,i,e.prev)||Dt(i,e.prev,e))||po(i,e)&&Dt(i.prev,i,i.next)>0&&Dt(e.prev,e,e.next)>0)}function Dt(i,e,t){return(e.y-i.y)*(t.x-e.x)-(e.x-i.x)*(t.y-e.y)}function po(i,e){return i.x===e.x&&i.y===e.y}function bx(i,e,t,n){let r=uc(Dt(i,e,t)),s=uc(Dt(i,e,n)),o=uc(Dt(t,n,i)),a=uc(Dt(t,n,e));return!!(r!==s&&o!==a||r===0&&cc(i,t,e)||s===0&&cc(i,n,e)||o===0&&cc(t,i,n)||a===0&&cc(t,e,n))}function cc(i,e,t){return e.x<=Math.max(i.x,t.x)&&e.x>=Math.min(i.x,t.x)&&e.y<=Math.max(i.y,t.y)&&e.y>=Math.min(i.y,t.y)}function uc(i){return i>0?1:i<0?-1:0}function fS(i,e){let t=i;do{if(t.i!==i.i&&t.next.i!==i.i&&t.i!==e.i&&t.next.i!==e.i&&bx(t,t.next,i,e))return!0;t=t.next}while(t!==i);return!1}function Ta(i,e){return Dt(i.prev,i,i.next)<0?Dt(i,e,i.next)>=0&&Dt(i,i.prev,e)>=0:Dt(i,e,i.prev)<0||Dt(i,i.next,e)<0}function dS(i,e){let t=i,n=!1,r=(i.x+e.x)/2,s=(i.y+e.y)/2;do t.y>s!=t.next.y>s&&t.next.y!==t.y&&r<(t.next.x-t.x)*(s-t.y)/(t.next.y-t.y)+t.x&&(n=!n),t=t.next;while(t!==i);return n}function yx(i,e){let t=Mf(i.i,i.x,i.y),n=Mf(e.i,e.x,e.y),r=i.next,s=e.prev;return i.next=e,e.prev=i,t.next=r,r.prev=t,n.next=t,t.prev=n,s.next=n,n.prev=s,n}function xg(i,e,t,n){let r=Mf(i,e,t);return n?(r.next=n.next,r.prev=n,n.next.prev=r,n.next=r):(r.prev=r,r.next=r),r}function Aa(i){i.next.prev=i.prev,i.prev.next=i.next,i.prevZ&&(i.prevZ.nextZ=i.nextZ),i.nextZ&&(i.nextZ.prevZ=i.prevZ)}function Mf(i,e,t){return{i,x:e,y:t,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function pS(i,e,t,n){let r=0;for(let s=e,o=t-n;s<t;s+=n)r+=(i[o]-i[s])*(i[s+1]+i[o+1]),o=s;return r}var Sf=class{static triangulate(e,t,n=2){return j1(e,t,n)}},Ea=class i{static area(e){let t=e.length,n=0;for(let r=t-1,s=0;s<t;r=s++)n+=e[r].x*e[s].y-e[s].x*e[r].y;return n*.5}static isClockWise(e){return i.area(e)<0}static triangulateShape(e,t){let n=[],r=[],s=[];bg(e),yg(n,e);let o=e.length;t.forEach(bg);for(let l=0;l<t.length;l++)r.push(o),o+=t[l].length,yg(n,t[l]);let a=Sf.triangulate(n,r);for(let l=0;l<a.length;l+=3)s.push(a.slice(l,l+3));return s}};function bg(i){let e=i.length;e>2&&i[e-1].equals(i[0])&&i.pop()}function yg(i,e){for(let t=0;t<e.length;t++)i.push(e[t].x),i.push(e[t].y)}var sn=class i extends Fe{constructor(e=1,t=1,n=1,r=1){super(),this.type="PlaneGeometry",this.parameters={width:e,height:t,widthSegments:n,heightSegments:r};let s=e/2,o=t/2,a=Math.floor(n),l=Math.floor(r),c=a+1,u=l+1,h=e/a,f=t/l,d=[],p=[],x=[],g=[];for(let m=0;m<u;m++){let b=m*f-o;for(let v=0;v<c;v++){let y=v*h-s;p.push(y,-b,0),x.push(0,0,1),g.push(v/a),g.push(1-m/l)}}for(let m=0;m<l;m++)for(let b=0;b<a;b++){let v=b+c*m,y=b+c*(m+1),M=b+1+c*(m+1),S=b+1+c*m;d.push(v,y,S),d.push(y,M,S)}this.setIndex(d),this.setAttribute("position",new ke(p,3)),this.setAttribute("normal",new ke(x,3)),this.setAttribute("uv",new ke(g,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new i(e.width,e.height,e.widthSegments,e.heightSegments)}},Ra=class i extends Fe{constructor(e=.5,t=1,n=32,r=1,s=0,o=Math.PI*2){super(),this.type="RingGeometry",this.parameters={innerRadius:e,outerRadius:t,thetaSegments:n,phiSegments:r,thetaStart:s,thetaLength:o},n=Math.max(3,n),r=Math.max(1,r);let a=[],l=[],c=[],u=[],h=e,f=(t-e)/r,d=new U,p=new De;for(let x=0;x<=r;x++){for(let g=0;g<=n;g++){let m=s+g/n*o;d.x=h*Math.cos(m),d.y=h*Math.sin(m),l.push(d.x,d.y,d.z),c.push(0,0,1),p.x=(d.x/t+1)/2,p.y=(d.y/t+1)/2,u.push(p.x,p.y)}h+=f}for(let x=0;x<r;x++){let g=x*(n+1);for(let m=0;m<n;m++){let b=m+g,v=b,y=b+n+1,M=b+n+2,S=b+1;a.push(v,y,S),a.push(y,M,S)}}this.setIndex(a),this.setAttribute("position",new ke(l,3)),this.setAttribute("normal",new ke(c,3)),this.setAttribute("uv",new ke(u,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new i(e.innerRadius,e.outerRadius,e.thetaSegments,e.phiSegments,e.thetaStart,e.thetaLength)}};var Ca=class i extends Fe{constructor(e=1,t=32,n=16,r=0,s=Math.PI*2,o=0,a=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:e,widthSegments:t,heightSegments:n,phiStart:r,phiLength:s,thetaStart:o,thetaLength:a},t=Math.max(3,Math.floor(t)),n=Math.max(2,Math.floor(n));let l=Math.min(o+a,Math.PI),c=0,u=[],h=new U,f=new U,d=[],p=[],x=[],g=[];for(let m=0;m<=n;m++){let b=[],v=m/n,y=o+v*a,M=e*Math.cos(y),S=Math.sqrt(e*e-M*M),_=0;m===0&&o===0?_=.5/t:m===n&&l===Math.PI&&(_=-.5/t);for(let w=0;w<=t;w++){let R=w/t,A=r+R*s;h.x=-S*Math.cos(A),h.y=M,h.z=S*Math.sin(A),p.push(h.x,h.y,h.z),f.copy(h).normalize(),x.push(f.x,f.y,f.z),g.push(R+_,1-v),b.push(c++)}u.push(b)}for(let m=0;m<n;m++)for(let b=0;b<t;b++){let v=u[m][b+1],y=u[m][b],M=u[m+1][b],S=u[m+1][b+1];(m!==0||o>0)&&d.push(v,y,S),(m!==n-1||l<Math.PI)&&d.push(y,M,S)}this.setIndex(d),this.setAttribute("position",new ke(p,3)),this.setAttribute("normal",new ke(x,3)),this.setAttribute("uv",new ke(g,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new i(e.radius,e.widthSegments,e.heightSegments,e.phiStart,e.phiLength,e.thetaStart,e.thetaLength)}};function ys(i){let e={};for(let t in i){e[t]={};for(let n in i[t]){let r=i[t][n];if(_g(r))r.isRenderTargetTexture?(Le("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),e[t][n]=null):e[t][n]=r.clone();else if(Array.isArray(r))if(_g(r[0])){let s=[];for(let o=0,a=r.length;o<a;o++)s[o]=r[o].clone();e[t][n]=s}else e[t][n]=r.slice();else e[t][n]=r}}return e}function bn(i){let e={};for(let t=0;t<i.length;t++){let n=ys(i[t]);for(let r in n)e[r]=n[r]}return e}function _g(i){return i&&(i.isColor||i.isMatrix3||i.isMatrix4||i.isVector2||i.isVector3||i.isVector4||i.isTexture||i.isQuaternion)}function mS(i){let e=[];for(let t=0;t<i.length;t++)e.push(i[t].clone());return e}function od(i){let e=i.getRenderTarget();return e===null?i.outputColorSpace:e.isXRRenderTarget===!0?e.texture.colorSpace:tt.workingColorSpace}var _x={clone:ys,merge:bn},gS=`void main() {
|
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
}`,xS=`void main() {
|
|
gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
|
|
}`,Mi=class extends mn{constructor(e){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=gS,this.fragmentShader=xS,this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.forceSinglePass=!0,this.extensions={clipCullDistance:!1,multiDraw:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv1:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,e!==void 0&&this.setValues(e)}copy(e){return super.copy(e),this.fragmentShader=e.fragmentShader,this.vertexShader=e.vertexShader,this.uniforms=ys(e.uniforms),this.uniformsGroups=mS(e.uniformsGroups),this.defines=Object.assign({},e.defines),this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.fog=e.fog,this.lights=e.lights,this.clipping=e.clipping,this.extensions=Object.assign({},e.extensions),this.glslVersion=e.glslVersion,this.defaultAttributeValues=Object.assign({},e.defaultAttributeValues),this.index0AttributeName=e.index0AttributeName,this.uniformsNeedUpdate=e.uniformsNeedUpdate,this}toJSON(e){let t=super.toJSON(e);t.glslVersion=this.glslVersion,t.uniforms={};for(let r in this.uniforms){let o=this.uniforms[r].value;o&&o.isTexture?t.uniforms[r]={type:"t",value:o.toJSON(e).uuid}:o&&o.isColor?t.uniforms[r]={type:"c",value:o.getHex()}:o&&o.isVector2?t.uniforms[r]={type:"v2",value:o.toArray()}:o&&o.isVector3?t.uniforms[r]={type:"v3",value:o.toArray()}:o&&o.isVector4?t.uniforms[r]={type:"v4",value:o.toArray()}:o&&o.isMatrix3?t.uniforms[r]={type:"m3",value:o.toArray()}:o&&o.isMatrix4?t.uniforms[r]={type:"m4",value:o.toArray()}:t.uniforms[r]={value:o}}Object.keys(this.defines).length>0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;let n={};for(let r in this.extensions)this.extensions[r]===!0&&(n[r]=!0);return Object.keys(n).length>0&&(t.extensions=n),t}fromJSON(e,t){if(super.fromJSON(e,t),e.uniforms!==void 0)for(let n in e.uniforms){let r=e.uniforms[n];switch(this.uniforms[n]={},r.type){case"t":this.uniforms[n].value=t[r.value]||null;break;case"c":this.uniforms[n].value=new W().setHex(r.value);break;case"v2":this.uniforms[n].value=new De().fromArray(r.value);break;case"v3":this.uniforms[n].value=new U().fromArray(r.value);break;case"v4":this.uniforms[n].value=new _t().fromArray(r.value);break;case"m3":this.uniforms[n].value=new He().fromArray(r.value);break;case"m4":this.uniforms[n].value=new Be().fromArray(r.value);break;default:this.uniforms[n].value=r.value}}if(e.defines!==void 0&&(this.defines=e.defines),e.vertexShader!==void 0&&(this.vertexShader=e.vertexShader),e.fragmentShader!==void 0&&(this.fragmentShader=e.fragmentShader),e.glslVersion!==void 0&&(this.glslVersion=e.glslVersion),e.extensions!==void 0)for(let n in e.extensions)this.extensions[n]=e.extensions[n];return e.lights!==void 0&&(this.lights=e.lights),e.clipping!==void 0&&(this.clipping=e.clipping),this}},Ec=class extends Mi{constructor(e){super(e),this.isRawShaderMaterial=!0,this.type="RawShaderMaterial"}},In=class extends mn{constructor(e){super(),this.isMeshStandardMaterial=!0,this.type="MeshStandardMaterial",this.defines={STANDARD:""},this.color=new W(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new W(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=$a,this.normalScale=new De(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new _i,this.envMapIntensity=1,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.defines={STANDARD:""},this.color.copy(e.color),this.roughness=e.roughness,this.metalness=e.metalness,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.roughnessMap=e.roughnessMap,this.metalnessMap=e.metalnessMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.envMapIntensity=e.envMapIntensity,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}},An=class extends In{constructor(e){super(),this.isMeshPhysicalMaterial=!0,this.defines={STANDARD:"",PHYSICAL:""},this.type="MeshPhysicalMaterial",this.anisotropyRotation=0,this.anisotropyMap=null,this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new De(1,1),this.clearcoatNormalMap=null,this.diffuseRoughnessMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return it(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(t){this.ior=(1+.4*t)/(1-.4*t)}}),this.iridescenceMap=null,this.iridescenceIOR=1.3,this.iridescenceThicknessMinimum=100,this.iridescenceThicknessMaximum=400,this.iridescenceThicknessMap=null,this.sheenColor=new W(0),this.sheenColorMap=null,this.sheenRoughness=1,this.sheenRoughnessMap=null,this.transmissionMap=null,this.thickness=0,this.thicknessMap=null,this.attenuationDistance=1/0,this.attenuationColor=new W(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new W(1,1,1),this.specularColorMap=null,this._anisotropy=0,this._clearcoat=0,this._diffuseRoughness=0,this._dispersion=0,this._iridescence=0,this._retroreflectivity=0,this._sheen=0,this._transmission=0,this.setValues(e)}get anisotropy(){return this._anisotropy}set anisotropy(e){this._anisotropy>0!=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 diffuseRoughness(){return this._diffuseRoughness}set diffuseRoughness(e){this._diffuseRoughness>0!=e>0&&this.version++,this._diffuseRoughness=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 retroreflectivity(){return this._retroreflectivity}set retroreflectivity(e){this._retroreflectivity>0!=e>0&&this.version++,this._retroreflectivity=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}get iridescenceThicknessRange(){return os('MeshPhysicalMaterial: The "iridescenceThicknessRange" property has been replaced by "iridescenceThicknessMinimum" and "iridescenceThicknessMaximum".'),[this.iridescenceThicknessMinimum,this.iridescenceThicknessMaximum]}set iridescenceThicknessRange(e){os('MeshPhysicalMaterial: The "iridescenceThicknessRange" property has been replaced by "iridescenceThicknessMinimum" and "iridescenceThicknessMaximum".'),this.iridescenceThicknessMinimum=e[0],this.iridescenceThicknessMaximum=e[1]}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.diffuseRoughness=e.diffuseRoughness,this.diffuseRoughnessMap=e.diffuseRoughnessMap,this.dispersion=e.dispersion,this.ior=e.ior,this.iridescence=e.iridescence,this.iridescenceMap=e.iridescenceMap,this.iridescenceIOR=e.iridescenceIOR,this.iridescenceThicknessMinimum=e.iridescenceThicknessMinimum,this.iridescenceThicknessMaximum=e.iridescenceThicknessMaximum,this.iridescenceThicknessMap=e.iridescenceThicknessMap,this.retroreflectivity=e.retroreflectivity,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}};var Pa=class extends mn{constructor(e){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new W(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new W(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=$a,this.normalScale=new De(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new _i,this.combine=kc,this.reflectivity=1,this.envMapIntensity=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.envMapIntensity=e.envMapIntensity,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}},Rc=class extends mn{constructor(e){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=nx,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}},Cc=class extends mn{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}};function Er(i,e){return!i||i.constructor===e?i:typeof e.BYTES_PER_ELEMENT=="number"?new e(i):Array.prototype.slice.call(i)}function ha(i){return i!==void 0&&i.inTangents!==void 0&&i.outTangents!==void 0}function bS(i){function e(r,s){return i[r]-i[s]}let t=i.length,n=new Array(t);for(let r=0;r!==t;++r)n[r]=r;return n.sort(e),n}function vg(i,e,t){let n=i.length,r=new i.constructor(n);for(let s=0,o=0;o!==n;++s){let a=t[s]*e;for(let l=0;l!==e;++l)r[o++]=i[a+l]}return r}function yS(i,e,t,n){let r=1,s=i[0];for(;s!==void 0&&s[n]===void 0;)s=i[r++];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=i[r++];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=i[r++];while(s!==void 0);else do o=s[n],o!==void 0&&(e.push(s.time),t.push(o)),s=i[r++];while(s!==void 0)}var Si=class{constructor(e,t,n,r){this.parameterPositions=e,this._cachedIndex=0,this.resultBuffer=r!==void 0?r:new t.constructor(n),this.sampleValues=t,this.valueSize=n,this.settings=null,this.DefaultSettings_={}}evaluate(e){let t=this.parameterPositions,n=this._cachedIndex,r=t[n],s=t[n-1];n:{e:{let o;t:{i:if(!(e<r)){for(let a=n+2;;){if(r===void 0){if(e<s)break i;return n=t.length,this._cachedIndex=n,this.copySampleValue_(n-1)}if(n===a)break;if(s=r,r=t[++n],e<r)break e}o=t.length;break t}if(!(e>=s)){let a=t[1];e<a&&(n=2,s=a);for(let l=n-2;;){if(s===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(n===l)break;if(r=s,s=t[--n-1],e>=s)break e}o=n,n=0;break t}break n}for(;n<o;){let a=n+o>>>1;e<t[a]?o=a:n=a+1}if(r=t[n],s=t[n-1],s===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(r===void 0)return n=t.length,this._cachedIndex=n,this.copySampleValue_(n-1)}this._cachedIndex=n,this.intervalChanged_(n,s,r)}return this.interpolate_(n,s,e,r)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(e){let t=this.resultBuffer,n=this.sampleValues,r=this.valueSize,s=e*r;for(let o=0;o!==r;++o)t[o]=n[s+o];return t}interpolate_(){throw new Error("THREE.Interpolant: Call to abstract method.")}intervalChanged_(){}},Pc=class extends Si{constructor(e,t,n,r){super(e,t,n,r),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:xf,endingEnd:xf}}intervalChanged_(e,t,n){let r=this.parameterPositions,s=e-2,o=e+1,a=r[s],l=r[o];if(a===void 0)switch(this.getSettings_().endingStart){case bf:s=e,a=2*t-n;break;case yf:s=r.length-2,a=t+r[s]-r[s+1];break;default:s=e,a=n}if(l===void 0)switch(this.getSettings_().endingEnd){case bf:o=e,l=2*n-t;break;case yf:o=1,l=n+r[1]-r[0];break;default:o=e-1,l=t}let c=(n-t)*.5,u=this.valueSize;this._weightPrev=c/(t-a),this._weightNext=c/(l-n),this._offsetPrev=s*u,this._offsetNext=o*u}interpolate_(e,t,n,r){let s=this.resultBuffer,o=this.sampleValues,a=this.valueSize,l=e*a,c=l-a,u=this._offsetPrev,h=this._offsetNext,f=this._weightPrev,d=this._weightNext,p=(n-t)/(r-t),x=p*p,g=x*p,m=-f*g+2*f*x-f*p,b=(1+f)*g+(-1.5-2*f)*x+(-.5+f)*p+1,v=(-1-d)*g+(1.5+d)*x+.5*p,y=d*g-d*x;for(let M=0;M!==a;++M)s[M]=m*o[u+M]+b*o[c+M]+v*o[l+M]+y*o[h+M];return s}},Ic=class extends Si{constructor(e,t,n,r){super(e,t,n,r)}interpolate_(e,t,n,r){let s=this.resultBuffer,o=this.sampleValues,a=this.valueSize,l=e*a,c=l-a,u=(n-t)/(r-t),h=1-u;for(let f=0;f!==a;++f)s[f]=o[c+f]*h+o[l+f]*u;return s}},Lc=class extends Si{constructor(e,t,n,r){super(e,t,n,r)}interpolate_(e){return this.copySampleValue_(e-1)}},Fc=class extends Si{interpolate_(e,t,n,r){let s=this.resultBuffer,o=this.sampleValues,a=this.valueSize,l=e*a,c=l-a,u=this.inTangents,h=this.outTangents;if(!u||!h){let p=(n-t)/(r-t),x=1-p;for(let g=0;g!==a;++g)s[g]=o[c+g]*x+o[l+g]*p;return s}let f=a*2,d=e-1;for(let p=0;p!==a;++p){let x=o[c+p],g=o[l+p],m=d*f+p*2,b=h[m],v=h[m+1],y=e*f+p*2,M=u[y],S=u[y+1],_=vS(n,t,b,M,r);s[p]=vx(_,x,v,S,g)}return s}};function vx(i,e,t,n,r){let s=1-i;return s*s*s*e+3*s*s*i*t+3*s*i*i*n+i*i*i*r}function _S(i,e,t,n,r){let s=1-i;return 3*s*s*(t-e)+6*s*i*(n-t)+3*i*i*(r-n)}function vS(i,e,t,n,r){let s=(i-e)/(r-e);for(let o=0;o<8;o++){let a=vx(s,e,t,n,r)-i;if(Math.abs(a)<1e-10)break;let l=_S(s,e,t,n,r);if(Math.abs(l)<1e-10)break;s=Math.max(0,Math.min(1,s-a/l))}return s}var Ln=class{constructor(e,t,n,r){if(e===void 0)throw new Error("THREE.KeyframeTrack: track name is undefined");if(t===void 0||t.length===0)throw new Error("THREE.KeyframeTrack: no keyframes in track named "+e);this.name=e,this.times=Er(t,this.TimeBufferType),this.values=Er(n,this.ValueBufferType),this.setInterpolation(r||this.DefaultInterpolation)}static toJSON(e){let t=e.constructor,n;if(t.toJSON!==this.toJSON)n=t.toJSON(e);else{n={name:e.name,times:Er(e.times,Array),values:Er(e.values,Array)};let r=e.getInterpolation();r!==e.DefaultInterpolation&&(n.interpolation=r),ha(e.settings)&&(n.settings={inTangents:Er(e.settings.inTangents,Array),outTangents:Er(e.settings.outTangents,Array)})}return n.type=e.ValueTypeName,n}InterpolantFactoryMethodDiscrete(e){return new Lc(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodLinear(e){return new Ic(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodSmooth(e){return new Pc(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodBezier(e){let t=new Fc(this.times,this.values,this.getValueSize(),e);return this.settings&&(t.inTangents=this.settings.inTangents,t.outTangents=this.settings.outTangents),t}setInterpolation(e){let t;switch(e){case Ki:t=this.InterpolantFactoryMethodDiscrete;break;case Zi:t=this.InterpolantFactoryMethodLinear;break;case dc:t=this.InterpolantFactoryMethodSmooth;break;case gf:t=this.InterpolantFactoryMethodBezier;break}if(t===void 0){let n="unsupported interpolation for "+this.ValueTypeName+" keyframe track named "+this.name;if(this.createInterpolant===void 0)if(e!==this.DefaultInterpolation)this.setInterpolation(this.DefaultInterpolation);else throw new Error(n);return Le("KeyframeTrack:",n),this}return this.createInterpolant=t,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return Ki;case this.InterpolantFactoryMethodLinear:return Zi;case this.InterpolantFactoryMethodSmooth:return dc;case this.InterpolantFactoryMethodBezier:return gf}}getValueSize(){return this.values.length/this.times.length}shift(e){if(e!==0){let t=this.times;for(let n=0,r=t.length;n!==r;++n)t[n]+=e;ha(this.settings)&&(Mg(this.settings.inTangents,e),Mg(this.settings.outTangents,e))}return this}scale(e){if(e!==1){let t=this.times;for(let n=0,r=t.length;n!==r;++n)t[n]*=e;ha(this.settings)&&(Sg(this.settings.inTangents,e),Sg(this.settings.outTangents,e))}return this}trim(e,t){let n=this.times,r=n.length,s=0,o=r-1;for(;s!==r&&n[s]<e;)++s;for(;o!==-1&&n[o]>t;)--o;if(++o,s!==0||o!==r){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&&(Ge("KeyframeTrack: Invalid value size in track.",this),e=!1);let n=this.times,r=this.values,s=n.length;s===0&&(Ge("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)){Ge("KeyframeTrack: Time is not a valid number.",this,a,l),e=!1;break}if(o!==null&&o>l){Ge("KeyframeTrack: Out of order keys.",this,a,l,o),e=!1;break}o=l}if(r!==void 0&&m1(r))for(let a=0,l=r.length;a!==l;++a){let c=r[a];if(isNaN(c)){Ge("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(),r=this.getInterpolation()===dc,s=e.length-1,o=1;for(let a=1;a<s;++a){let l=!1,c=e[a],u=e[a+1];if(c!==u&&(a!==1||c!==e[0]))if(r)l=!0;else{let h=a*n,f=h-n,d=h+n;for(let p=0;p!==n;++p){let x=t[h+p];if(x!==t[f+p]||x!==t[d+p]){l=!0;break}}}if(l){if(a!==o){e[o]=e[a];let h=a*n,f=o*n;for(let d=0;d!==n;++d)t[f+d]=t[h+d]}++o}}if(s>0){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,r=new n(this.name,e,t);return r.createInterpolant=this.createInterpolant,ha(this.settings)&&(r.settings={inTangents:this.settings.inTangents.slice(),outTangents:this.settings.outTangents.slice()}),r}};function Mg(i,e){for(let t=0,n=i.length;t!==n;t+=2)i[t]+=e}function Sg(i,e){for(let t=0,n=i.length;t!==n;t+=2)i[t]*=e}Ln.prototype.ValueTypeName="";Ln.prototype.TimeBufferType=Float32Array;Ln.prototype.ValueBufferType=Float32Array;Ln.prototype.DefaultInterpolation=Zi;var tr=class extends Ln{constructor(e,t,n){super(e,t,n)}};tr.prototype.ValueTypeName="bool";tr.prototype.ValueBufferType=Array;tr.prototype.DefaultInterpolation=Ki;tr.prototype.InterpolantFactoryMethodLinear=void 0;tr.prototype.InterpolantFactoryMethodSmooth=void 0;var Ia=class extends Ln{constructor(e,t,n,r){super(e,t,n,r)}};Ia.prototype.ValueTypeName="color";var nr=class extends Ln{constructor(e,t,n,r){super(e,t,n,r)}};nr.prototype.ValueTypeName="number";var Oc=class extends Si{constructor(e,t,n,r){super(e,t,n,r)}interpolate_(e,t,n,r){let s=this.resultBuffer,o=this.sampleValues,a=this.valueSize,l=(n-t)/(r-t),c=e*a;for(let u=c+a;c!==u;c+=4)Sn.slerpFlat(s,0,o,c-a,o,c,l);return s}},ir=class extends Ln{constructor(e,t,n,r){super(e,t,n,r)}InterpolantFactoryMethodLinear(e){return new Oc(this.times,this.values,this.getValueSize(),e)}};ir.prototype.ValueTypeName="quaternion";ir.prototype.InterpolantFactoryMethodSmooth=void 0;var rr=class extends Ln{constructor(e,t,n){super(e,t,n)}};rr.prototype.ValueTypeName="string";rr.prototype.ValueBufferType=Array;rr.prototype.DefaultInterpolation=Ki;rr.prototype.InterpolantFactoryMethodLinear=void 0;rr.prototype.InterpolantFactoryMethodSmooth=void 0;var Or=class extends Ln{constructor(e,t,n,r){super(e,t,n,r)}};Or.prototype.ValueTypeName="vector";var La=class{constructor(e="",t=-1,n=[],r=tx){this.name=e,this.tracks=n,this.duration=t,this.blendMode=r,this.uuid=Ri(),this.userData={},this.duration<0&&this.resetDuration()}static parse(e){let t=[],n=e.tracks,r=1/(e.fps||1);for(let o=0,a=n.length;o!==a;++o)t.push(SS(n[o]).scale(r));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,r={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(Ln.toJSON(n[s]));return r}static CreateFromMorphTargetSequence(e,t,n,r){let s=t.length,o=[];for(let a=0;a<s;a++){let l=[],c=[];l.push((a+s-1)%s,a,(a+1)%s),c.push(0,1,0);let u=bS(l);l=vg(l,1,u),c=vg(c,1,u),!r&&l[0]===0&&(l.push(s),c.push(c[0])),o.push(new nr(".morphTargetInfluences["+t[a].name+"]",l,c).scale(1/n))}return new this(e,-1,o)}static findByName(e,t){let n=e;if(!Array.isArray(e)){let r=e;n=r.geometry&&r.geometry.animations||r.animations}for(let r=0;r<n.length;r++)if(n[r].name===t)return n[r];return null}static CreateClipsFromMorphTargetSequences(e,t,n){let r={},s=/^([\w-]*?)([\d]+)$/;for(let a=0,l=e.length;a<l;a++){let c=e[a],u=c.name.match(s);if(u&&u.length>1){let h=u[1],f=r[h];f||(r[h]=f=[]),f.push(c)}}let o=[];for(let a in r)o.push(this.CreateFromMorphTargetSequence(a,r[a],t,n));return o}resetDuration(){let e=this.tracks,t=0;for(let n=0,r=e.length;n!==r;++n){let s=this.tracks[n];t=Math.max(t,s.times[s.times.length-1])}return this.duration=t,this}trim(){for(let e=0;e<this.tracks.length;e++)this.tracks[e].trim(0,this.duration);return this}validate(){let e=!0;for(let t=0;t<this.tracks.length;t++)e=e&&this.tracks[t].validate();return e}optimize(){for(let e=0;e<this.tracks.length;e++)this.tracks[e].optimize();return this}clone(){let e=[];for(let n=0;n<this.tracks.length;n++)e.push(this.tracks[n].clone());let t=new this.constructor(this.name,this.duration,e,this.blendMode);return t.userData=JSON.parse(JSON.stringify(this.userData)),t}toJSON(){return this.constructor.toJSON(this)}};function MS(i){switch(i.toLowerCase()){case"scalar":case"double":case"float":case"number":case"integer":return nr;case"vector":case"vector2":case"vector3":case"vector4":return Or;case"color":return Ia;case"quaternion":return ir;case"bool":case"boolean":return tr;case"string":return rr}throw new Error("THREE.KeyframeTrack: Unsupported typeName: "+i)}function SS(i){if(i.type===void 0)throw new Error("THREE.KeyframeTrack: track type undefined, can not parse");let e=MS(i.type);if(i.times===void 0){let n=[],r=[];yS(i.keys,n,r,"value"),i.times=n,i.values=r}let t;return e.parse!==void 0?t=e.parse(i):t=new e(i.name,i.times,i.values,i.interpolation),ha(i.settings)&&(t.settings={inTangents:Er(i.settings.inTangents,Float32Array),outTangents:Er(i.settings.outTangents,Float32Array)}),t}var bi={enabled:!1,files:{},add:function(i,e){this.enabled!==!1&&(wg(i)||(this.files[i]=e))},get:function(i){if(this.enabled!==!1&&!wg(i))return this.files[i]},remove:function(i){delete this.files[i]},clear:function(){this.files={}}};function wg(i){try{let e=i.slice(i.indexOf(":")+1);return new URL(e).protocol==="blob:"}catch{return!1}}var Nc=class{constructor(e,t,n){let r=this,s=!1,o=0,a=0,l,c=[];this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=n,this._abortController=null,this.itemStart=function(u){a++,s===!1&&r.onStart!==void 0&&r.onStart(u,o,a),s=!0},this.itemEnd=function(u){o++,r.onProgress!==void 0&&r.onProgress(u,o,a),o===a&&(s=!1,r.onLoad!==void 0&&r.onLoad())},this.itemError=function(u){r.onError!==void 0&&r.onError(u)},this.resolveURL=function(u){return u=u.normalize("NFC"),l?l(u):u},this.setURLModifier=function(u){return l=u,this},this.addHandler=function(u,h){return c.push(u,h),this},this.removeHandler=function(u){let h=c.indexOf(u);return h!==-1&&c.splice(h,2),this},this.getHandler=function(u){for(let h=0,f=c.length;h<f;h+=2){let d=c[h],p=c[h+1];if(d.global&&(d.lastIndex=0),d.test(u))return p}return null},this.abort=function(){return this.abortController.abort(),this._abortController=null,this}}get abortController(){return this._abortController||(this._abortController=new AbortController),this._abortController}},Mx=new Nc,wi=class{constructor(e){this.manager=e!==void 0?e:Mx,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={},this.priority="auto",this.cache="default",typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}load(){}loadAsync(e,t){let n=this;return new Promise(function(r,s){n.load(e,r,t,s)})}parse(){}setCrossOrigin(e){return this.crossOrigin=e,this}setWithCredentials(e){return this.withCredentials=e,this}setPath(e){return this.path=e,this}setResourcePath(e){return this.resourcePath=e,this}setRequestHeader(e){return this.requestHeader=e,this}setPriority(e){return this.priority=e,this}setCache(e){return this.cache=e,this}abort(){return this}};wi.DEFAULT_MATERIAL_NAME="__DEFAULT";var Xi={},wf=class extends Error{constructor(e,t){super(e),this.response=t}},mo=class extends wi{constructor(e){super(e),this.mimeType="",this.responseType="",this._abortController=new AbortController}load(e,t,n,r){e===void 0&&(e=""),this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);let s=bi.get(`file:${e}`);if(s!==void 0){this.manager.itemStart(e),setTimeout(()=>{t&&t(s),this.manager.itemEnd(e)},0);return}if(Xi[e]!==void 0){Xi[e].push({onLoad:t,onProgress:n,onError:r});return}Xi[e]=[],Xi[e].push({onLoad:t,onProgress:n,onError:r});let o=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin",priority:this.priority,cache:this.cache,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&&Le("FileLoader: HTTP Status 0 received."),typeof ReadableStream>"u"||c.body===void 0||c.body.getReader===void 0)return c;let u=Xi[e],h=c.body.getReader(),f=c.headers.get("X-File-Size")||c.headers.get("Content-Length"),d=f?parseInt(f):0,p=d!==0,x=0,g=new ReadableStream({start(m){b();function b(){h.read().then(({done:v,value:y})=>{if(v)m.close();else{x+=y.byteLength;let M=new ProgressEvent("progress",{lengthComputable:p,loaded:x,total:d});for(let S=0,_=u.length;S<_;S++){let w=u[S];w.onProgress&&w.onProgress(M)}m.enqueue(y),b()}},v=>{m.error(v)})}}});return new Response(g)}else throw new wf(`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(u=>new DOMParser().parseFromString(u,a));case"json":return c.json();default:if(a==="")return c.text();{let h=/charset="?([^;"\s]*)"?/i.exec(a),f=h&&h[1]?h[1].toLowerCase():void 0,d=new TextDecoder(f);return c.arrayBuffer().then(p=>d.decode(p))}}}).then(c=>{bi.add(`file:${e}`,c);let u=Xi[e];delete Xi[e];for(let h=0,f=u.length;h<f;h++){let d=u[h];d.onLoad&&d.onLoad(c)}}).catch(c=>{let u=Xi[e];if(u===void 0)throw this.manager.itemError(e),c;delete Xi[e];for(let h=0,f=u.length;h<f;h++){let d=u[h];d.onError&&d.onError(c)}this.manager.itemError(e)}).finally(()=>{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}};var eo=new WeakMap,Dc=class extends wi{constructor(e){super(e)}load(e,t,n,r){this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);let s=this,o=bi.get(`image:${e}`);if(o!==void 0){if(o.complete===!0)s.manager.itemStart(e),setTimeout(function(){t&&t(o),s.manager.itemEnd(e)},0);else{let h=eo.get(o);h===void 0&&(h=[],eo.set(o,h)),h.push({onLoad:t,onError:r})}return o}let a=oo("img");function l(){u(),t&&t(this);let h=eo.get(this)||[];for(let f=0;f<h.length;f++){let d=h[f];d.onLoad&&d.onLoad(this)}eo.delete(this),s.manager.itemEnd(e)}function c(h){u(),r&&r(h),bi.remove(`image:${e}`);let f=eo.get(this)||[];for(let d=0;d<f.length;d++){let p=f[d];p.onError&&p.onError(h)}eo.delete(this),s.manager.itemError(e),s.manager.itemEnd(e)}function u(){a.removeEventListener("load",l,!1),a.removeEventListener("error",c,!1)}return a.addEventListener("load",l,!1),a.addEventListener("error",c,!1),e.slice(0,5)!=="data:"&&this.crossOrigin!==void 0&&(a.crossOrigin=this.crossOrigin),bi.add(`image:${e}`,a),s.manager.itemStart(e),a.fetchPriority=this.priority,a.src=e,a}};var Fa=class extends wi{constructor(e){super(e)}load(e,t,n,r){let s=new Kt,o=new Dc(this.manager);return o.setPriority(this.priority),o.setCache(this.cache),o.setCrossOrigin(this.crossOrigin),o.setPath(this.path),o.load(e,function(a){s.image=a,s.needsUpdate=!0,t!==void 0&&t(s)},n,r),s}},Nr=class extends Et{static registerNode(e){this.prototype._lightNode=e}constructor(e,t=1){super(),this.isLight=!0,this.type="Light",this.color=new W(e),this.intensity=t}copy(e,t){return super.copy(e,t),this.color.copy(e.color),this.intensity=e.intensity,this}toJSON(e){let t=super.toJSON(e);return t.object.color=this.color.getHex(),t.object.intensity=this.intensity,t}},ds=class extends Nr{constructor(e,t,n){super(e,n),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(Et.DEFAULT_UP),this.updateMatrix(),this.groundColor=new W(t)}copy(e,t){return super.copy(e,t),this.groundColor.copy(e.groundColor),this}toJSON(e){let t=super.toJSON(e);return t.object.groundColor=this.groundColor.getHex(),t}},df=new Be,Tg=new U,Ag=new U,go=class{constructor(e){this.camera=e,this.intensity=1,this.bias=0,this.biasNode=null,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new De(512,512),this.mapType=On,this.map=null,this.mapPass=null,this.matrix=new Be,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new Ir,this._frameExtents=new De(1,1),this._viewportCount=1,this._viewports=[new _t(0,0,1,1)]}getViewportCount(){return this._viewportCount}getCamera(){return this.camera}getFrustum(){return this._frustum}updateMatrices(e){let t=this.camera;Tg.setFromMatrixPosition(e.matrixWorld),t.position.copy(Tg),Ag.setFromMatrixPosition(e.target.matrixWorld),t.lookAt(Ag),t.updateMatrixWorld(),this._updateMatrix(t,this.matrix,this._frustum)}_updateMatrix(e,t,n,r){df.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),n.setFromProjectionMatrix(df,e.coordinateSystem,e.reversedDepth);let s=this._frameExtents,o=r?r.z/s.x:1,a=r?r.w/s.y:1,l=r?r.x/s.x:0,c=r?r.y/s.y:0;e.coordinateSystem===so||e.reversedDepth?t.set(.5*o,0,0,.5*o+l,0,.5*a,0,.5*a+c,0,0,1,0,0,0,0,1):t.set(.5*o,0,0,.5*o+l,0,.5*a,0,.5*a+c,0,0,.5,.5,0,0,0,1),t.multiply(df)}getViewport(e){return this._viewports[e]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(e){return this.camera=e.camera.clone(),this.intensity=e.intensity,this.bias=e.bias,this.radius=e.radius,this.autoUpdate=e.autoUpdate,this.needsUpdate=e.needsUpdate,this.normalBias=e.normalBias,this.blurSamples=e.blurSamples,this.mapSize.copy(e.mapSize),this.mapType=e.mapType,this.biasNode=e.biasNode,this}clone(){return new this.constructor().copy(this)}toJSON(){let e={};return e.intensity=this.intensity,e.bias=this.bias,e.normalBias=this.normalBias,e.radius=this.radius,e.blurSamples=this.blurSamples,e.mapSize=this.mapSize.toArray(),e.mapType=this.mapType,e.camera=this.camera.toJSON(!1).object,delete e.camera.matrix,e}},hc=new U,fc=new Sn,xi=new U,Oa=class extends Et{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new Be,this.projectionMatrix=new Be,this.projectionMatrixInverse=new Be,this.coordinateSystem=$n,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.matrixWorld.decompose(hc,fc,xi),xi.x===1&&xi.y===1&&xi.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(hc,fc,xi.set(1,1,1)).invert()}updateWorldMatrix(e,t,n=!1){super.updateWorldMatrix(e,t,n),this.matrixWorld.decompose(hc,fc,xi),xi.x===1&&xi.y===1&&xi.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(hc,fc,xi.set(1,1,1)).invert()}clone(){return new this.constructor().copy(this)}},Ar=new U,Eg=new De,Rg=new De,Jt=class extends Oa{constructor(e=50,t=1,n=.1,r=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=e,this.zoom=1,this.near=n,this.far=r,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=as*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){let e=Math.tan(fa*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return as*2*Math.atan(Math.tan(fa*.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){Ar.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),t.set(Ar.x,Ar.y).multiplyScalar(-e/Ar.z),Ar.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set(Ar.x,Ar.y).multiplyScalar(-e/Ar.z)}getViewSize(e,t){return this.getViewBounds(e,Eg,Rg),t.subVectors(Rg,Eg)}setViewOffset(e,t,n,r,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=r,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(fa*.5*this.fov)/this.zoom,n=2*t,r=this.aspect*n,s=-.5*r,o=this.view;if(this.view!==null&&this.view.enabled){let l=o.fullWidth,c=o.fullHeight;s+=o.offsetX*r/l,t-=o.offsetY*n/c,r*=o.width/l,n*=o.height/c}let a=this.filmOffset;a!==0&&(s+=e*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(s,s+r,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}},Tf=class extends go{constructor(){super(new Jt(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1,this.aspect=1}updateMatrices(e){let t=this.camera,n=as*2*e.angle*this.focus,r=this.mapSize.width/this.mapSize.height*this.aspect,s=e.distance||t.far;(n!==t.fov||r!==t.aspect||s!==t.far)&&(t.fov=n,t.aspect=r,t.far=s,t.updateProjectionMatrix()),super.updateMatrices(e)}copy(e){return super.copy(e),this.focus=e.focus,this.aspect=e.aspect,this}toJSON(){let e=super.toJSON();return e.focus=this.focus,e.aspect=this.aspect,e}},Na=class extends Nr{constructor(e,t,n=0,r=Math.PI/3,s=0,o=2){super(e,t),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(Et.DEFAULT_UP),this.updateMatrix(),this.target=new Et,this.distance=n,this.angle=r,this.penumbra=s,this.decay=o,this.map=null,this.shadow=new Tf}get power(){return this.intensity*Math.PI}set power(e){this.intensity=e/Math.PI}dispose(){super.dispose(),this.shadow.dispose()}copy(e,t){return super.copy(e,t),this.distance=e.distance,this.angle=e.angle,this.penumbra=e.penumbra,this.decay=e.decay,this.target=e.target.clone(),this.map=e.map,this.shadow=e.shadow.clone(),this}toJSON(e){let t=super.toJSON(e);return t.object.distance=this.distance,t.object.angle=this.angle,t.object.decay=this.decay,t.object.penumbra=this.penumbra,t.object.target=this.target.uuid,this.map&&this.map.isTexture&&(t.object.map=this.map.toJSON(e).uuid),t.object.shadow=this.shadow.toJSON(),t}},Af=class extends go{constructor(){super(new Jt(90,1,.5,500)),this.isPointLightShadow=!0}},ps=class extends Nr{constructor(e,t,n=0,r=2){super(e,t),this.isPointLight=!0,this.type="PointLight",this.distance=n,this.decay=r,this.shadow=new Af}get power(){return this.intensity*4*Math.PI}set power(e){this.intensity=e/(4*Math.PI)}dispose(){super.dispose(),this.shadow.dispose()}copy(e,t){return super.copy(e,t),this.distance=e.distance,this.decay=e.decay,this.shadow=e.shadow.clone(),this}toJSON(e){let t=super.toJSON(e);return t.object.distance=this.distance,t.object.decay=this.decay,t.object.shadow=this.shadow.toJSON(),t}},zn=class extends Oa{constructor(e=-1,t=1,n=1,r=-1,s=.1,o=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=n,this.bottom=r,this.near=s,this.far=o,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=e.view===null?null:Object.assign({},e.view),this}setViewOffset(e,t,n,r,s,o){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=r,this.view.width=s,this.view.height=o,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),n=(this.right+this.left)/2,r=(this.top+this.bottom)/2,s=n-e,o=n+e,a=r+t,l=r-t;if(this.view!==null&&this.view.enabled){let c=(this.right-this.left)/this.view.fullWidth/this.zoom,u=(this.top-this.bottom)/this.view.fullHeight/this.zoom;s+=c*this.view.offsetX,o=s+c*this.view.width,a-=u*this.view.offsetY,l=a-u*this.view.height}this.projectionMatrix.makeOrthographic(s,o,a,l,this.near,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){let t=super.toJSON(e);return t.object.zoom=this.zoom,t.object.left=this.left,t.object.right=this.right,t.object.top=this.top,t.object.bottom=this.bottom,t.object.near=this.near,t.object.far=this.far,this.view!==null&&(t.object.view=Object.assign({},this.view)),t}},Ef=class extends go{constructor(){super(new zn(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}},sr=class extends Nr{constructor(e,t){super(e,t),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(Et.DEFAULT_UP),this.updateMatrix(),this.target=new Et,this.shadow=new Ef}dispose(){super.dispose(),this.shadow.dispose()}copy(e){return super.copy(e),this.target=e.target.clone(),this.shadow=e.shadow.clone(),this}toJSON(e){let t=super.toJSON(e);return t.object.shadow=this.shadow.toJSON(),t.object.target=this.target.uuid,t}},Da=class extends Nr{constructor(e,t){super(e,t),this.isAmbientLight=!0,this.type="AmbientLight"}};var or=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)}};var pf=new WeakMap,Ua=class extends wi{constructor(e){super(e),this.isImageBitmapLoader=!0,typeof createImageBitmap>"u"&&Le("ImageBitmapLoader: createImageBitmap() not supported."),typeof fetch>"u"&&Le("ImageBitmapLoader: fetch() not supported."),this.options={premultiplyAlpha:"none"},this._abortController=new AbortController}setOptions(e){return this.options=e,this}load(e,t,n,r){e===void 0&&(e=""),this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);let s=this,o=bi.get(`image-bitmap:${e}`);if(o!==void 0){if(s.manager.itemStart(e),o.then){o.then(c=>{pf.has(o)===!0?(r&&r(pf.get(o)),s.manager.itemError(e),s.manager.itemEnd(e)):(t&&t(c),s.manager.itemEnd(e))});return}setTimeout(function(){t&&t(o),s.manager.itemEnd(e)},0);return}let a={};a.credentials=this.withCredentials||this.crossOrigin!=="anonymous"?"include":"same-origin",a.headers=this.requestHeader,a.priority=this.priority,a.cache=this.cache,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 bi.add(`image-bitmap:${e}`,c),t&&t(c),s.manager.itemEnd(e),c}).catch(function(c){r&&r(c),pf.set(l,c),bi.remove(`image-bitmap:${e}`),s.manager.itemError(e),s.manager.itemEnd(e)});bi.add(`image-bitmap:${e}`,l),s.manager.itemStart(e)}abort(){return this._abortController.abort(),this._abortController=new AbortController,this}};var to=-90,no=1,xo=class extends Et{constructor(e,t,n){super(),this.type="CubeCamera",this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;let r=new Jt(to,no,e,t);r.layers=this.layers,this.add(r);let s=new Jt(to,no,e,t);s.layers=this.layers,this.add(s);let o=new Jt(to,no,e,t);o.layers=this.layers,this.add(o);let a=new Jt(to,no,e,t);a.layers=this.layers,this.add(a);let l=new Jt(to,no,e,t);l.layers=this.layers,this.add(l);let c=new Jt(to,no,e,t);c.layers=this.layers,this.add(c)}updateCoordinateSystem(){let e=this.coordinateSystem,t=this.children.concat(),[n,r,s,o,a,l]=t;for(let c of t)this.remove(c);if(e===$n)n.up.set(0,1,0),n.lookAt(1,0,0),r.up.set(0,1,0),r.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===so)n.up.set(0,-1,0),n.lookAt(-1,0,0),r.up.set(0,-1,0),r.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:r}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());let[s,o,a,l,c,u]=this.children,h=e.getRenderTarget(),f=e.getActiveCubeFace(),d=e.getActiveMipmapLevel(),p=e.xr.enabled;e.xr.enabled=!1;let x=n.texture.mipmapsAutoUpdate;n.texture.mipmapsAutoUpdate=!1;let g=!1;e.isWebGLRenderer===!0?g=e.state.buffers.depth.getReversed():g=e.reversedDepthBuffer,e.setRenderTarget(n,0,r),g&&e.autoClear===!1&&e.clearDepth(),e.render(t,s),e.setRenderTarget(n,1,r),g&&e.autoClear===!1&&e.clearDepth(),e.render(t,o),e.setRenderTarget(n,2,r),g&&e.autoClear===!1&&e.clearDepth(),e.render(t,a),e.setRenderTarget(n,3,r),g&&e.autoClear===!1&&e.clearDepth(),e.render(t,l),e.setRenderTarget(n,4,r),g&&e.autoClear===!1&&e.clearDepth(),e.render(t,c),n.texture.mipmapsAutoUpdate=x,e.setRenderTarget(n,5,r),g&&e.autoClear===!1&&e.clearDepth(),e.render(t,u),e.setRenderTarget(h,f,d),e.xr.enabled=p,n.texture.needsPMREMUpdate=!0}},Uc=class extends Jt{constructor(e=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=e,this.perCameraFrustumCulled=!1}};var ad="\\[\\]\\.:\\/",wS=new RegExp("["+ad+"]","g"),ld="[^"+ad+"]",TS="[^"+ad.replace("\\.","")+"]",AS=/((?:WC+[\/:])*)/.source.replace("WC",ld),ES=/(WCOD+)?/.source.replace("WCOD",TS),RS=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",ld),CS=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",ld),PS=new RegExp("^"+AS+ES+RS+CS+"$"),IS=["material","materials","bones","map"],Rf=class{constructor(e,t,n){let r=n||gt.parseTrackName(t);this._targetGroup=e,this._bindings=e.subscribe_(t,r)}getValue(e,t){this.bind();let n=this._targetGroup.nCachedObjects_,r=this._bindings[n];r!==void 0&&r.getValue(e,t)}setValue(e,t){let n=this._bindings;for(let r=this._targetGroup.nCachedObjects_,s=n.length;r!==s;++r)n[r].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()}},gt=class i{constructor(e,t,n){this.path=t,this.parsedPath=n||i.parseTrackName(t),this.node=i.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 i.Composite(e,t,n):new i(e,t,n)}static sanitizeNodeName(e){return e.replace(/\s/g,"_").replace(wS,"")}static parseTrackName(e){let t=PS.exec(e);if(t===null)throw new Error("THREE.PropertyBinding: Cannot parse trackName: "+e);let n={nodeName:t[2],objectName:t[3],objectIndex:t[4],propertyName:t[5],propertyIndex:t[6]},r=n.nodeName&&n.nodeName.lastIndexOf(".");if(r!==void 0&&r!==-1){let s=n.nodeName.substring(r+1);IS.indexOf(s)!==-1&&(n.nodeName=n.nodeName.substring(0,r),n.objectName=s)}if(n.propertyName===null||n.propertyName.length===0)throw new Error("THREE.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.length;o++){let a=s[o];if(a.name===t||a.uuid===t)return a;let l=n(a.children);if(l)return l}return null},r=n(e.children);if(r)return r}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(e,t){e[t]=this.targetObject[this.propertyName]}_getValue_array(e,t){let n=this.resolvedProperty;for(let r=0,s=n.length;r!==s;++r)e[t++]=n[r]}_getValue_arrayElement(e,t){e[t]=this.resolvedProperty[this.propertyIndex]}_getValue_toArray(e,t){this.resolvedProperty.toArray(e,t)}_setValue_direct(e,t){this.targetObject[this.propertyName]=e[t]}_setValue_direct_setNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.needsUpdate=!0}_setValue_direct_setMatrixWorldNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_array(e,t){let n=this.resolvedProperty;for(let r=0,s=n.length;r!==s;++r)n[r]=e[t++]}_setValue_array_setNeedsUpdate(e,t){let n=this.resolvedProperty;for(let r=0,s=n.length;r!==s;++r)n[r]=e[t++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(e,t){let n=this.resolvedProperty;for(let r=0,s=n.length;r!==s;++r)n[r]=e[t++];this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_arrayElement(e,t){this.resolvedProperty[this.propertyIndex]=e[t]}_setValue_arrayElement_setNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.needsUpdate=!0}_setValue_arrayElement_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_fromArray(e,t){this.resolvedProperty.fromArray(e,t)}_setValue_fromArray_setNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.needsUpdate=!0}_setValue_fromArray_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.matrixWorldNeedsUpdate=!0}_getValue_unbound(e,t){this.bind(),this.getValue(e,t)}_setValue_unbound(e,t){this.bind(),this.setValue(e,t)}bind(){let e=this.node,t=this.parsedPath,n=t.objectName,r=t.propertyName,s=t.propertyIndex;if(e||(e=i.findNode(this.rootNode,t.nodeName),this.node=e),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!e){Le("PropertyBinding: No target node found for track: "+this.path+".");return}if(n){let c=t.objectIndex;switch(n){case"materials":if(!e.material){Ge("PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!e.material.materials){Ge("PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.",this);return}e=e.material.materials;break;case"bones":if(!e.skeleton){Ge("PropertyBinding: Can not bind to bones as node does not have a skeleton.",this);return}e=e.skeleton.bones;for(let u=0;u<e.length;u++)if(e[u].name===c){c=u;break}break;case"map":if("map"in e){e=e.map;break}if(!e.material){Ge("PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!e.material.map){Ge("PropertyBinding: Can not bind to material.map as node.material does not have a map.",this);return}e=e.material.map;break;default:if(e[n]===void 0){Ge("PropertyBinding: Can not bind to objectName of node undefined.",this);return}e=e[n]}if(c!==void 0){if(e[c]===void 0){Ge("PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.",this,e);return}e=e[c]}}let o=e[r];if(o===void 0){let c=t.nodeName;Ge("PropertyBinding: Trying to update property for track: "+c+"."+r+" but it wasn't found.",e);return}let a=this.Versioning.None;this.targetObject=e,e.isMaterial===!0?a=this.Versioning.NeedsUpdate:e.isObject3D===!0&&(a=this.Versioning.MatrixWorldNeedsUpdate);let l=this.BindingType.Direct;if(s!==void 0){if(r==="morphTargetInfluences"){if(!e.geometry){Ge("PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.",this);return}if(!e.geometry.morphAttributes){Ge("PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.",this);return}e.morphTargetDictionary[s]!==void 0&&(s=e.morphTargetDictionary[s])}l=this.BindingType.ArrayElement,this.resolvedProperty=o,this.propertyIndex=s}else o.fromArray!==void 0&&o.toArray!==void 0?(l=this.BindingType.HasFromToArray,this.resolvedProperty=o):Array.isArray(o)?(l=this.BindingType.EntireArray,this.resolvedProperty=o):this.propertyName=r;this.getValue=this.GetterByBindingType[l],this.setValue=this.SetterByBindingTypeAndVersioning[l][a]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}};gt.Composite=Rf;gt.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3};gt.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2};gt.prototype.GetterByBindingType=[gt.prototype._getValue_direct,gt.prototype._getValue_array,gt.prototype._getValue_arrayElement,gt.prototype._getValue_toArray];gt.prototype.SetterByBindingTypeAndVersioning=[[gt.prototype._setValue_direct,gt.prototype._setValue_direct_setNeedsUpdate,gt.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[gt.prototype._setValue_array,gt.prototype._setValue_array_setNeedsUpdate,gt.prototype._setValue_array_setMatrixWorldNeedsUpdate],[gt.prototype._setValue_arrayElement,gt.prototype._setValue_arrayElement_setNeedsUpdate,gt.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[gt.prototype._setValue_fromArray,gt.prototype._setValue_fromArray_setNeedsUpdate,gt.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];var BP=new Float32Array(1);var Cg=new Be,Ba=class{constructor(e,t,n=0,r=1/0){this.ray=new Pr(e,t),this.near=n,this.far=r,this.camera=null,this.layers=new co,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(e,t){this.ray.set(e,t)}setFromCamera(e,t){t.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(e.x,e.y,.5).unproject(t).sub(this.ray.origin).normalize(),this.camera=t):t.isOrthographicCamera?(this.ray.origin.set(e.x,e.y,t.projectionMatrix.elements[14]).unproject(t),this.ray.direction.set(0,0,-1).transformDirection(t.matrixWorld),this.camera=t):Ge("Raycaster: Unsupported camera type: "+t.type)}setFromXRController(e){return Cg.identity().extractRotation(e.matrixWorld),this.ray.origin.setFromMatrixPosition(e.matrixWorld),this.ray.direction.set(0,0,-1).applyMatrix4(Cg),this}intersectObject(e,t=!0,n=[]){return Cf(e,this,n,t),n.sort(Pg),n}intersectObjects(e,t=!0,n=[]){for(let r=0,s=e.length;r<s;r++)Cf(e[r],this,n,t);return n.sort(Pg),n}};function Pg(i,e){return i.distance-e.distance}function Cf(i,e,t,n){let r=!0;if(i.layers.test(e.layers)&&i.raycast(e,t)===!1&&(r=!1),r===!0&&n===!0){let s=i.children;for(let o=0,a=s.length;o<a;o++)Cf(s[o],e,t,!0)}}var pd=class pd{constructor(e,t,n,r){this.elements=[1,0,0,1],e!==void 0&&this.set(e,t,n,r)}identity(){return this.set(1,0,0,1),this}fromArray(e,t=0){for(let n=0;n<4;n++)this.elements[n]=e[n+t];return this}set(e,t,n,r){let s=this.elements;return s[0]=e,s[2]=t,s[1]=n,s[3]=r,this}};pd.prototype.isMatrix2=!0;var Pf=pd;function cd(i,e,t,n){let r=LS(n);switch(t){case qf:return i*e;case Xc:return i*e/r.components*r.byteLength;case Yc:return i*e/r.components*r.byteLength;case Ur:return i*e*2/r.components*r.byteLength;case qc:return i*e*2/r.components*r.byteLength;case $f:return i*e*3/r.components*r.byteLength;case Nn:return i*e*4/r.components*r.byteLength;case $c:return i*e*4/r.components*r.byteLength;case Va:case Ga:return Math.floor((i+3)/4)*Math.floor((e+3)/4)*8;case Ha:case Wa:return Math.floor((i+3)/4)*Math.floor((e+3)/4)*16;case Zc:case jc:return Math.max(i,16)*Math.max(e,8)/4;case Kc:case Jc:return Math.max(i,8)*Math.max(e,8)/2;case Qc:case eu:case nu:case iu:return Math.floor((i+3)/4)*Math.floor((e+3)/4)*8;case tu:case Xa:case ru:return Math.floor((i+3)/4)*Math.floor((e+3)/4)*16;case su:return Math.floor((i+3)/4)*Math.floor((e+3)/4)*16;case ou:return Math.floor((i+4)/5)*Math.floor((e+3)/4)*16;case au:return Math.floor((i+4)/5)*Math.floor((e+4)/5)*16;case lu:return Math.floor((i+5)/6)*Math.floor((e+4)/5)*16;case cu:return Math.floor((i+5)/6)*Math.floor((e+5)/6)*16;case uu:return Math.floor((i+7)/8)*Math.floor((e+4)/5)*16;case hu:return Math.floor((i+7)/8)*Math.floor((e+5)/6)*16;case fu:return Math.floor((i+7)/8)*Math.floor((e+7)/8)*16;case du:return Math.floor((i+9)/10)*Math.floor((e+4)/5)*16;case pu:return Math.floor((i+9)/10)*Math.floor((e+5)/6)*16;case mu:return Math.floor((i+9)/10)*Math.floor((e+7)/8)*16;case gu:return Math.floor((i+9)/10)*Math.floor((e+9)/10)*16;case xu:return Math.floor((i+11)/12)*Math.floor((e+9)/10)*16;case bu:return Math.floor((i+11)/12)*Math.floor((e+11)/12)*16;case yu:case _u:case vu:return Math.ceil(i/4)*Math.ceil(e/4)*16;case Mu:case Su:return Math.ceil(i/4)*Math.ceil(e/4)*8;case Ya:case wu:return Math.ceil(i/4)*Math.ceil(e/4)*16}throw new Error(`Unable to determine texture byte length for ${t} format.`)}function LS(i){switch(i){case On:case Hf:return{byteLength:1,components:1};case vo:case Wf:case ai:return{byteLength:2,components:1};case Hc:case Wc:return{byteLength:2,components:4};case oi:case Gc:case Vn:return{byteLength:4,components:1};case Xf:case Yf:return{byteLength:4,components:3}}throw new Error(`THREE.TextureUtils: Unknown texture type ${i}.`)}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:"187"}}));typeof window<"u"&&(window.__THREE__?Le("WARNING: Multiple instances of Three.js being imported."):window.__THREE__="187");function Wx(){let i=null,e=!1,t=null,n=null;function r(s,o){n=i.requestAnimationFrame(r),t(s,o)}return{start:function(){e!==!0&&t!==null&&i!==null&&(n=i.requestAnimationFrame(r),e=!0)},stop:function(){i!==null&&i.cancelAnimationFrame(n),e=!1},setAnimationLoop:function(s){t=s},setContext:function(s){i=s}}}function FS(i){let e=new WeakMap;function t(a,l){let c=a.array,u=a.usage,h=c.byteLength,f=i.createBuffer();i.bindBuffer(l,f),i.bufferData(l,c,u),a.onUploadCallback();let d;if(c instanceof Float32Array)d=i.FLOAT;else if(typeof Float16Array<"u"&&c instanceof Float16Array)d=i.HALF_FLOAT;else if(c instanceof Uint16Array)a.isFloat16BufferAttribute?d=i.HALF_FLOAT:d=i.UNSIGNED_SHORT;else if(c instanceof Int16Array)d=i.SHORT;else if(c instanceof Uint32Array)d=i.UNSIGNED_INT;else if(c instanceof Int32Array)d=i.INT;else if(c instanceof Int8Array)d=i.BYTE;else if(c instanceof Uint8Array)d=i.UNSIGNED_BYTE;else if(c instanceof Uint8ClampedArray)d=i.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:h}}function n(a,l,c){let u=l.array,h=l.updateRanges;if(i.bindBuffer(c,a),h.length===0)i.bufferSubData(c,0,u);else{h.sort((d,p)=>d.start-p.start);let f=0;for(let d=1;d<h.length;d++){let p=h[f],x=h[d];x.start<=p.start+p.count+1?p.count=Math.max(p.count,x.start+x.count-p.start):(++f,h[f]=x)}h.length=f+1;for(let d=0,p=h.length;d<p;d++){let x=h[d];i.bufferSubData(c,x.start*u.BYTES_PER_ELEMENT,u,x.start,x.count)}l.clearUpdateRanges()}l.onUploadCallback()}function r(a){return a.isInterleavedBufferAttribute&&(a=a.data),e.get(a)}function s(a){a.isInterleavedBufferAttribute&&(a=a.data);let l=e.get(a);l&&(i.deleteBuffer(l.buffer),e.delete(a))}function o(a,l){if(a.isInterleavedBufferAttribute&&(a=a.data),a.isGLBufferAttribute){let u=e.get(a);(!u||u.version<a.version)&&e.set(a,{buffer:a.buffer,type:a.type,bytesPerElement:a.elementSize,version:a.version});return}let c=e.get(a);if(c===void 0)e.set(a,t(a,l));else if(c.version<a.version){if(c.size!==a.array.byteLength)throw new Error("THREE.WebGLAttributes: The size of the buffer attribute's array buffer does not match the original size. Resizing buffer attributes is not supported.");n(c.buffer,a,l),c.version=a.version}}return{get:r,remove:s,update:o}}var OS=`#ifdef USE_ALPHAHASH
|
|
if ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;
|
|
#endif`,NS=`#ifdef USE_ALPHAHASH
|
|
const float ALPHA_HASH_SCALE = 0.05;
|
|
float hash2D( vec2 value ) {
|
|
return fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );
|
|
}
|
|
float hash3D( vec3 value ) {
|
|
return hash2D( vec2( hash2D( value.xy ), value.z ) );
|
|
}
|
|
float getAlphaHashThreshold( vec3 position ) {
|
|
float maxDeriv = max(
|
|
length( dFdx( position.xyz ) ),
|
|
length( dFdy( position.xyz ) )
|
|
);
|
|
float pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );
|
|
vec2 pixScales = vec2(
|
|
exp2( floor( log2( pixScale ) ) ),
|
|
exp2( ceil( log2( pixScale ) ) )
|
|
);
|
|
vec2 alpha = vec2(
|
|
hash3D( floor( pixScales.x * position.xyz ) ),
|
|
hash3D( floor( pixScales.y * position.xyz ) )
|
|
);
|
|
float lerpFactor = fract( log2( pixScale ) );
|
|
float x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;
|
|
float a = min( lerpFactor, 1.0 - lerpFactor );
|
|
vec3 cases = vec3(
|
|
x * x / ( 2.0 * a * ( 1.0 - a ) ),
|
|
( x - 0.5 * a ) / ( 1.0 - a ),
|
|
1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )
|
|
);
|
|
float threshold = ( x < ( 1.0 - a ) )
|
|
? ( ( x < a ) ? cases.x : cases.y )
|
|
: cases.z;
|
|
return clamp( threshold , 1.0e-6, 1.0 );
|
|
}
|
|
#endif`,DS=`#ifdef USE_ALPHAMAP
|
|
diffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;
|
|
#endif`,US=`#ifdef USE_ALPHAMAP
|
|
uniform sampler2D alphaMap;
|
|
#endif`,BS=`#ifdef USE_ALPHATEST
|
|
#ifdef ALPHA_TO_COVERAGE
|
|
diffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );
|
|
if ( diffuseColor.a == 0.0 ) discard;
|
|
#else
|
|
if ( diffuseColor.a < alphaTest ) discard;
|
|
#endif
|
|
#endif`,kS=`#ifdef USE_ALPHATEST
|
|
uniform float alphaTest;
|
|
#endif`,zS=`#ifdef USE_AOMAP
|
|
float ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;
|
|
reflectedLight.indirectDiffuse *= ambientOcclusion;
|
|
#if defined( USE_CLEARCOAT )
|
|
clearcoatSpecularIndirect *= ambientOcclusion;
|
|
#endif
|
|
#if defined( USE_SHEEN )
|
|
sheenSpecularIndirect *= ambientOcclusion;
|
|
#endif
|
|
#if defined( USE_ENVMAP ) && defined( STANDARD )
|
|
float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
|
|
reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );
|
|
#endif
|
|
#endif`,VS=`#ifdef USE_AOMAP
|
|
uniform sampler2D aoMap;
|
|
uniform float aoMapIntensity;
|
|
#endif`,GS=`#ifdef USE_BATCHING
|
|
#if ! defined( GL_ANGLE_multi_draw )
|
|
#define gl_DrawID _gl_DrawID
|
|
uniform int _gl_DrawID;
|
|
#endif
|
|
uniform highp sampler2D batchingTexture;
|
|
uniform highp usampler2D batchingIdTexture;
|
|
mat4 getBatchingMatrix( const in float i ) {
|
|
int size = textureSize( batchingTexture, 0 ).x;
|
|
int j = int( i ) * 4;
|
|
int x = j % size;
|
|
int y = j / size;
|
|
vec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );
|
|
vec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );
|
|
vec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );
|
|
vec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );
|
|
return mat4( v1, v2, v3, v4 );
|
|
}
|
|
float getIndirectIndex( const in int i ) {
|
|
int size = textureSize( batchingIdTexture, 0 ).x;
|
|
int x = i % size;
|
|
int y = i / size;
|
|
return float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );
|
|
}
|
|
#endif
|
|
#ifdef USE_BATCHING_COLOR
|
|
uniform sampler2D batchingColorTexture;
|
|
vec4 getBatchingColor( const in float i ) {
|
|
int size = textureSize( batchingColorTexture, 0 ).x;
|
|
int j = int( i );
|
|
int x = j % size;
|
|
int y = j / size;
|
|
return texelFetch( batchingColorTexture, ivec2( x, y ), 0 );
|
|
}
|
|
#endif`,HS=`#ifdef USE_BATCHING
|
|
mat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );
|
|
#endif`,WS=`vec3 transformed = vec3( position );
|
|
#ifdef USE_ALPHAHASH
|
|
vPosition = vec3( position );
|
|
#endif`,XS=`vec3 objectNormal = vec3( normal );
|
|
#ifdef USE_TANGENT
|
|
vec3 objectTangent = vec3( tangent.xyz );
|
|
#endif`,YS=`float G_BlinnPhong_Implicit( ) {
|
|
return 0.25;
|
|
}
|
|
float D_BlinnPhong( const in float shininess, const in float dotNH ) {
|
|
return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
|
|
}
|
|
vec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {
|
|
vec3 halfDir = normalize( lightDir + viewDir );
|
|
float dotNH = saturate( dot( normal, halfDir ) );
|
|
float dotVH = saturate( dot( viewDir, halfDir ) );
|
|
vec3 F = F_Schlick( specularColor, 1.0, dotVH );
|
|
float G = G_BlinnPhong_Implicit( );
|
|
float D = D_BlinnPhong( shininess, dotNH );
|
|
return F * ( G * D );
|
|
} // validated`,qS=`#ifdef USE_IRIDESCENCE
|
|
const mat3 XYZ_TO_REC709 = mat3(
|
|
3.2404542, -0.9692660, 0.0556434,
|
|
-1.5371385, 1.8760108, -0.2040259,
|
|
-0.4985314, 0.0415560, 1.0572252
|
|
);
|
|
vec3 Fresnel0ToIor( vec3 fresnel0 ) {
|
|
vec3 sqrtF0 = sqrt( fresnel0 );
|
|
return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );
|
|
}
|
|
vec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {
|
|
return pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );
|
|
}
|
|
float IorToFresnel0( float transmittedIor, float incidentIor ) {
|
|
return pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));
|
|
}
|
|
vec3 evalSensitivity( float OPD, vec3 shift ) {
|
|
float phase = 2.0 * PI * OPD * 1.0e-9;
|
|
vec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );
|
|
vec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );
|
|
vec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );
|
|
vec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );
|
|
xyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );
|
|
xyz /= 1.0685e-7;
|
|
vec3 rgb = XYZ_TO_REC709 * xyz;
|
|
return rgb;
|
|
}
|
|
vec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {
|
|
vec3 I;
|
|
float iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );
|
|
float sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );
|
|
float cosTheta2Sq = 1.0 - sinTheta2Sq;
|
|
if ( cosTheta2Sq < 0.0 ) {
|
|
return vec3( 1.0 );
|
|
}
|
|
float cosTheta2 = sqrt( cosTheta2Sq );
|
|
float R0 = IorToFresnel0( iridescenceIOR, outsideIOR );
|
|
float R12 = F_Schlick( R0, 1.0, cosTheta1 );
|
|
float T121 = 1.0 - R12;
|
|
float phi12 = 0.0;
|
|
if ( iridescenceIOR < outsideIOR ) phi12 = PI;
|
|
float phi21 = PI - phi12;
|
|
vec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) ); vec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );
|
|
vec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );
|
|
vec3 phi23 = vec3( 0.0 );
|
|
if ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;
|
|
if ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;
|
|
if ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;
|
|
float OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;
|
|
vec3 phi = vec3( phi21 ) + phi23;
|
|
vec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );
|
|
vec3 r123 = sqrt( R123 );
|
|
vec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );
|
|
vec3 C0 = R12 + Rs;
|
|
I = C0;
|
|
vec3 Cm = Rs - T121;
|
|
for ( int m = 1; m <= 2; ++ m ) {
|
|
Cm *= r123;
|
|
vec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );
|
|
I += Cm * Sm;
|
|
}
|
|
return max( I, vec3( 0.0 ) );
|
|
}
|
|
#endif`,$S=`#ifdef USE_BUMPMAP
|
|
uniform sampler2D bumpMap;
|
|
uniform float bumpScale;
|
|
vec2 dHdxy_fwd() {
|
|
vec2 dSTdx = dFdx( vBumpMapUv );
|
|
vec2 dSTdy = dFdy( vBumpMapUv );
|
|
float Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;
|
|
float dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;
|
|
float dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;
|
|
return vec2( dBx, dBy );
|
|
}
|
|
vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {
|
|
vec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );
|
|
vec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );
|
|
vec3 vN = surf_norm;
|
|
vec3 R1 = cross( vSigmaY, vN );
|
|
vec3 R2 = cross( vN, vSigmaX );
|
|
float fDet = dot( vSigmaX, R1 ) * faceDirection;
|
|
vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
|
|
return normalize( abs( fDet ) * surf_norm - vGrad );
|
|
}
|
|
#endif`,KS=`#if NUM_CLIPPING_PLANES > 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`,ZS=`#if NUM_CLIPPING_PLANES > 0
|
|
varying vec3 vClipPosition;
|
|
uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];
|
|
#endif`,JS=`#if NUM_CLIPPING_PLANES > 0
|
|
varying vec3 vClipPosition;
|
|
#endif`,jS=`#if NUM_CLIPPING_PLANES > 0
|
|
vClipPosition = - mvPosition.xyz;
|
|
#endif`,QS=`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )
|
|
diffuseColor *= vColor;
|
|
#endif`,ew=`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )
|
|
varying vec4 vColor;
|
|
#endif`,tw=`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
|
|
varying vec4 vColor;
|
|
#endif`,nw=`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
|
|
vColor = vec4( 1.0 );
|
|
#endif
|
|
#ifdef USE_COLOR_ALPHA
|
|
vColor *= color;
|
|
#elif defined( USE_COLOR )
|
|
vColor.rgb *= color;
|
|
#endif
|
|
#ifdef USE_INSTANCING_COLOR
|
|
vColor.rgb *= instanceColor.rgb;
|
|
#endif
|
|
#ifdef USE_BATCHING_COLOR
|
|
vColor *= getBatchingColor( getIndirectIndex( gl_DrawID ) );
|
|
#endif`,iw=`#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 );
|
|
}
|
|
#define inverseTransformDirection transformDirectionByInverseViewMatrix
|
|
vec3 transformNormalByInverseViewMatrix( in vec3 normal, in mat4 viewMatrix ) {
|
|
return normalize( ( vec4( normal, 0.0 ) * viewMatrix ).xyz );
|
|
}
|
|
vec3 transformDirectionByInverseViewMatrix( in vec3 dir, in mat4 viewMatrix ) {
|
|
return normalize( ( vec4( dir, 0.0 ) * viewMatrix ).xyz );
|
|
}
|
|
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`,rw=`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;
|
|
#endif`,sw=`#ifdef USE_DISPLACEMENTMAP
|
|
uniform sampler2D displacementMap;
|
|
uniform float displacementScale;
|
|
uniform float displacementBias;
|
|
#endif`,ow=`#ifdef USE_DISPLACEMENTMAP
|
|
transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );
|
|
#endif`,aw=`#ifdef USE_EMISSIVEMAP
|
|
vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );
|
|
#ifdef DECODE_VIDEO_TEXTURE_EMISSIVE
|
|
emissiveColor = sRGBTransferEOTF( emissiveColor );
|
|
#endif
|
|
totalEmissiveRadiance *= emissiveColor.rgb;
|
|
#endif`,lw=`#ifdef USE_EMISSIVEMAP
|
|
uniform sampler2D emissiveMap;
|
|
#endif`,cw="gl_FragColor = linearToOutputTexel( gl_FragColor );",uw=`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 );
|
|
}`,hw=`#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 = transformNormalByInverseViewMatrix( 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 * reflectVec );
|
|
#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
|
|
#endif`,fw=`#ifdef USE_ENVMAP
|
|
uniform float envMapIntensity;
|
|
uniform mat3 envMapRotation;
|
|
uniform samplerCube envMap;
|
|
#ifdef ENVMAP_TYPE_PMREM
|
|
float roughnessToMip( const in float roughness ) {
|
|
float r = clamp( roughness, 0.0, 1.0 );
|
|
return ENVMAP_MAX_LOD * r * ( 2.0 - r );
|
|
}
|
|
#endif
|
|
#endif`,dw=`#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`,pw=`#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`,mw=`#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 = transformNormalByInverseViewMatrix( transformedNormal, viewMatrix );
|
|
#ifdef ENVMAP_MODE_REFLECTION
|
|
vReflect = reflect( cameraToVertex, worldNormal );
|
|
#else
|
|
vReflect = refract( cameraToVertex, worldNormal, refractionRatio );
|
|
#endif
|
|
#endif
|
|
#endif`,gw=`#ifdef USE_FOG
|
|
vFogDepth = - mvPosition.z;
|
|
#endif`,xw=`#ifdef USE_FOG
|
|
varying float vFogDepth;
|
|
#endif`,bw=`#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`,yw=`#ifdef USE_FOG
|
|
uniform vec3 fogColor;
|
|
varying float vFogDepth;
|
|
#ifdef FOG_EXP2
|
|
uniform float fogDensity;
|
|
#else
|
|
uniform float fogNear;
|
|
uniform float fogFar;
|
|
#endif
|
|
#endif`,_w=`#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
|
|
}`,vw=`#ifdef USE_LIGHTMAP
|
|
uniform sampler2D lightMap;
|
|
uniform float lightMapIntensity;
|
|
#endif`,Mw=`LambertMaterial material;
|
|
material.diffuseColor = diffuseColor.rgb;
|
|
material.specularStrength = specularStrength;`,Sw=`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`,ww=`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 = transformNormalByInverseViewMatrix( 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_SUN_LIGHTS > 0
|
|
struct SunLight {
|
|
vec3 direction;
|
|
vec3 color;
|
|
};
|
|
uniform SunLight sunLights[ NUM_SUN_LIGHTS ];
|
|
void getSunLightInfo( const in SunLight sunLight, out IncidentLight light ) {
|
|
light.color = sunLight.color;
|
|
light.direction = sunLight.direction;
|
|
light.visible = true;
|
|
}
|
|
#endif
|
|
#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
|
|
#include <lightprobes_pars_fragment>`,Tw=`#ifdef USE_ENVMAP
|
|
vec3 getIBLIrradiance( const in vec3 normal ) {
|
|
#ifdef ENVMAP_TYPE_PMREM
|
|
vec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );
|
|
vec4 envMapColor = textureLod( envMap, envMapRotation * worldNormal, ENVMAP_MAX_LOD );
|
|
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_PMREM
|
|
vec3 reflectVec = reflect( - viewDir, normal );
|
|
reflectVec = normalize( mix( reflectVec, normal, pow4( roughness ) ) );
|
|
reflectVec = transformDirectionByInverseViewMatrix( reflectVec, viewMatrix );
|
|
vec4 envMapColor = textureLod( envMap, envMapRotation * reflectVec, roughnessToMip( roughness ) );
|
|
return envMapColor.rgb * envMapIntensity;
|
|
#else
|
|
return vec3( 0.0 );
|
|
#endif
|
|
}
|
|
#ifdef USE_RETROREFLECTION
|
|
vec3 getIBLRetroRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {
|
|
#ifdef ENVMAP_TYPE_PMREM
|
|
vec3 retroVec = normalize( mix( viewDir, normal, pow4( roughness ) ) );
|
|
retroVec = transformDirectionByInverseViewMatrix( retroVec, viewMatrix );
|
|
vec4 envMapColor = textureLod( envMap, envMapRotation * retroVec, roughnessToMip( roughness ) );
|
|
return envMapColor.rgb * envMapIntensity;
|
|
#else
|
|
return vec3( 0.0 );
|
|
#endif
|
|
}
|
|
#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_PMREM
|
|
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
|
|
}
|
|
#ifdef USE_RETROREFLECTION
|
|
vec3 getIBLAnisotropyRetroRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {
|
|
#ifdef ENVMAP_TYPE_PMREM
|
|
vec3 bentNormal = cross( bitangent, viewDir );
|
|
bentNormal = normalize( cross( bentNormal, bitangent ) );
|
|
bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );
|
|
return getIBLRetroRadiance( viewDir, bentNormal, roughness );
|
|
#else
|
|
return vec3( 0.0 );
|
|
#endif
|
|
}
|
|
#endif
|
|
#endif
|
|
#endif`,Aw=`ToonMaterial material;
|
|
material.diffuseColor = diffuseColor.rgb;`,Ew=`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`,Rw=`BlinnPhongMaterial material;
|
|
material.diffuseColor = diffuseColor.rgb;
|
|
material.specularColor = specular;
|
|
material.specularShininess = shininess;
|
|
material.specularStrength = specularStrength;`,Cw=`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`,Pw=`PhysicalMaterial material;
|
|
material.diffuseColor = diffuseColor.rgb;
|
|
material.diffuseContribution = diffuseColor.rgb * ( 1.0 - metalnessFactor );
|
|
material.metalness = 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.045 );
|
|
material.roughness += geometryRoughness;
|
|
material.roughness = min( material.roughness, 1.0 );
|
|
#ifdef USE_DIFFUSE_ROUGHNESS
|
|
float diffuseRoughnessFactor = diffuseRoughness;
|
|
#ifdef USE_DIFFUSE_ROUGHNESSMAP
|
|
diffuseRoughnessFactor *= texture2D( diffuseRoughnessMap, vDiffuseRoughnessMapUv ).r;
|
|
#endif
|
|
material.diffuseRoughness = saturate( diffuseRoughnessFactor );
|
|
#endif
|
|
#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 = min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor;
|
|
material.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );
|
|
#else
|
|
material.specularColor = vec3( 0.04 );
|
|
material.specularColorBlended = mix( material.specularColor, 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.045 );
|
|
material.clearcoatRoughness += geometryRoughness;
|
|
material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );
|
|
#endif
|
|
#ifdef USE_DISPERSION
|
|
material.dispersion = dispersion;
|
|
#endif
|
|
#ifdef USE_RETROREFLECTION
|
|
material.retroreflectivity = retroreflectivity;
|
|
#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.0001, 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`,Iw=`uniform sampler2D dfgLUT;
|
|
struct PhysicalMaterial {
|
|
vec3 diffuseColor;
|
|
vec3 diffuseContribution;
|
|
vec3 specularColor;
|
|
vec3 specularColorBlended;
|
|
float roughness;
|
|
float metalness;
|
|
float specularF90;
|
|
float dispersion;
|
|
vec2 dfg;
|
|
vec3 multiScatteringCompensation;
|
|
#ifdef USE_DIFFUSE_ROUGHNESS
|
|
float diffuseRoughness;
|
|
#endif
|
|
#ifdef USE_RETROREFLECTION
|
|
float retroreflectivity;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT
|
|
float clearcoat;
|
|
float clearcoatRoughness;
|
|
vec3 clearcoatF0;
|
|
float clearcoatF90;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE
|
|
float iridescence;
|
|
float iridescenceIOR;
|
|
float iridescenceThickness;
|
|
vec3 iridescenceFresnel;
|
|
vec3 iridescenceF0Dielectric;
|
|
vec3 iridescenceF0Metallic;
|
|
#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 );
|
|
}
|
|
#ifdef USE_DIFFUSE_ROUGHNESS
|
|
const float EON_EPSILON = 1e-7;
|
|
float FON_DirectionalAlbedo( const in float mu, const in float roughness, const in float A ) {
|
|
float muComp = 1.0 - mu;
|
|
float gOverPi = muComp * ( 0.0571085289 + muComp * ( 0.491881867 + muComp * ( - 0.332181442 + muComp * 0.0714429953 ) ) );
|
|
return A * ( 1.0 + roughness * gOverPi );
|
|
}
|
|
vec3 BRDF_EON( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 diffuseColor, const in float roughness ) {
|
|
vec3 rho = saturate( diffuseColor );
|
|
if ( roughness <= EON_EPSILON ) return BRDF_Lambert( rho );
|
|
float dotNL = saturate( dot( normal, lightDir ) );
|
|
float dotNV = saturate( dot( normal, viewDir ) );
|
|
float s = dot( lightDir, viewDir ) - dotNL * dotNV;
|
|
float sOverT = ( s > 0.0 ) ? s / max( max( dotNL, dotNV ), EON_EPSILON ) : s;
|
|
float A = 1.0 / ( 1.0 + ( 0.5 - 2.0 / ( 3.0 * PI ) ) * roughness );
|
|
vec3 singleScatter = rho * RECIPROCAL_PI * A * ( 1.0 + roughness * sOverT );
|
|
float averageAlbedo = A * ( 1.0 + ( 2.0 / 3.0 - 28.0 / ( 15.0 * PI ) ) * roughness );
|
|
float albedoV = FON_DirectionalAlbedo( dotNV, roughness, A );
|
|
float albedoL = FON_DirectionalAlbedo( dotNL, roughness, A );
|
|
vec3 rhoMultiScatter = rho * rho * averageAlbedo / max( vec3( EON_EPSILON ), vec3( 1.0 ) - rho * ( 1.0 - averageAlbedo ) );
|
|
vec3 multiScatter = rhoMultiScatter * RECIPROCAL_PI
|
|
* max( EON_EPSILON, 1.0 - albedoV )
|
|
* max( EON_EPSILON, 1.0 - albedoL )
|
|
/ max( EON_EPSILON, 1.0 - averageAlbedo );
|
|
return singleScatter + multiScatter;
|
|
}
|
|
vec3 EON_DirectionalAlbedo( const in vec3 diffuseColor, const in float roughness, const in float dotNV ) {
|
|
vec3 rho = saturate( diffuseColor );
|
|
if ( roughness <= EON_EPSILON ) return rho;
|
|
float A = 1.0 / ( 1.0 + ( 0.5 - 2.0 / ( 3.0 * PI ) ) * roughness );
|
|
float directionalAlbedo = FON_DirectionalAlbedo( dotNV, roughness, A );
|
|
float averageAlbedo = A * ( 1.0 + ( 2.0 / 3.0 - 28.0 / ( 15.0 * PI ) ) * roughness );
|
|
vec3 rhoMultiScatter = rho * rho * averageAlbedo / max( vec3( EON_EPSILON ), vec3( 1.0 ) - rho * ( 1.0 - averageAlbedo ) );
|
|
return rho * directionalAlbedo + rhoMultiScatter * ( 1.0 - directionalAlbedo );
|
|
}
|
|
#endif
|
|
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 ) );
|
|
return 0.5 / max( gv + gl, EPSILON );
|
|
}
|
|
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 = max( material.clearcoatRoughness, 0.045 );
|
|
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.specularColorBlended;
|
|
float f90 = material.specularF90;
|
|
float roughness = max( material.roughness, 0.045 );
|
|
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 alphaT = max( material.alphaT, alpha );
|
|
float V = V_GGX_SmithCorrelated_Anisotropic( alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );
|
|
float D = D_GGX_Anisotropic( 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 * transpose( 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 rInv = 1.0 / ( roughness + 0.1 );
|
|
float a = -1.9362 + 1.0678 * roughness + 0.4573 * r2 - 0.8469 * rInv;
|
|
float b = -0.6014 + 0.5538 * roughness - 0.4670 * r2 - 0.1255 * rInv;
|
|
float DG = exp( a * dotNV + b );
|
|
return saturate( DG );
|
|
}
|
|
vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {
|
|
float dotNV = saturate( dot( normal, viewDir ) );
|
|
vec2 fab = texture2D( dfgLUT, vec2( roughness, dotNV ) ).rg;
|
|
return specularColor * fab.x + specularF90 * fab.y;
|
|
}
|
|
#ifdef USE_IRIDESCENCE
|
|
void computeMultiscatteringIridescence( const in vec2 fab, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, inout vec3 singleScatter, inout vec3 multiScatter ) {
|
|
#else
|
|
void computeMultiscattering( const in vec2 fab, const in vec3 specularColor, const in float specularF90, inout vec3 singleScatter, inout vec3 multiScatter ) {
|
|
#endif
|
|
#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.specularColorBlended * t2.x + ( material.specularF90 - material.specularColorBlended ) * t2.y );
|
|
reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );
|
|
reflectedLight.directDiffuse += lightColor * material.diffuseContribution * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );
|
|
#ifdef USE_CLEARCOAT
|
|
vec3 Ncc = geometryClearcoatNormal;
|
|
vec2 uvClearcoat = LTC_Uv( Ncc, viewDir, material.clearcoatRoughness );
|
|
vec4 t1Clearcoat = texture2D( ltc_1, uvClearcoat );
|
|
vec4 t2Clearcoat = texture2D( ltc_2, uvClearcoat );
|
|
mat3 mInvClearcoat = mat3(
|
|
vec3( t1Clearcoat.x, 0, t1Clearcoat.y ),
|
|
vec3( 0, 1, 0 ),
|
|
vec3( t1Clearcoat.z, 0, t1Clearcoat.w )
|
|
);
|
|
vec3 fresnelClearcoat = material.clearcoatF0 * t2Clearcoat.x + ( material.clearcoatF90 - material.clearcoatF0 ) * t2Clearcoat.y;
|
|
clearcoatSpecularDirect += lightColor * fresnelClearcoat * LTC_Evaluate( Ncc, viewDir, position, mInvClearcoat, rectCoords );
|
|
#endif
|
|
}
|
|
#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 );
|
|
|
|
float sheenAlbedoV = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
|
|
float sheenAlbedoL = IBLSheenBRDF( geometryNormal, directLight.direction, material.sheenRoughness );
|
|
|
|
float sheenEnergyComp = 1.0 - max3( material.sheenColor ) * max( sheenAlbedoV, sheenAlbedoL );
|
|
|
|
irradiance *= sheenEnergyComp;
|
|
|
|
#endif
|
|
vec3 specularBRDF = BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );
|
|
#ifdef USE_RETROREFLECTION
|
|
vec3 retroViewDir = reflect( - geometryViewDir, geometryNormal );
|
|
vec3 retroSpecularBRDF = BRDF_GGX( directLight.direction, retroViewDir, geometryNormal, material );
|
|
specularBRDF = mix( specularBRDF, retroSpecularBRDF, saturate( material.retroreflectivity ) );
|
|
#endif
|
|
reflectedLight.directSpecular += irradiance * specularBRDF * material.multiScatteringCompensation;
|
|
vec3 halfDir = normalize( directLight.direction + geometryViewDir );
|
|
float dotVH = saturate( dot( geometryViewDir, halfDir ) );
|
|
vec3 F = F_Schlick( material.specularColor, material.specularF90, dotVH );
|
|
#ifdef USE_RETROREFLECTION
|
|
vec3 retroHalfDir = normalize( directLight.direction + retroViewDir );
|
|
float dotRetroVH = saturate( dot( retroViewDir, retroHalfDir ) );
|
|
vec3 retroF = F_Schlick( material.specularColor, material.specularF90, dotRetroVH );
|
|
F = mix( F, retroF, saturate( material.retroreflectivity ) );
|
|
#endif
|
|
#ifdef USE_DIFFUSE_ROUGHNESS
|
|
vec3 diffuseBRDF = BRDF_EON( directLight.direction, geometryViewDir, geometryNormal, material.diffuseColor, material.diffuseRoughness ) * ( 1.0 - material.metalness );
|
|
#else
|
|
vec3 diffuseBRDF = BRDF_Lambert( material.diffuseContribution );
|
|
#endif
|
|
reflectedLight.directDiffuse += irradiance * diffuseBRDF * ( 1.0 - F );
|
|
}
|
|
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 ) {
|
|
vec3 singleScattering = vec3( 0.0 );
|
|
vec3 multiScattering = vec3( 0.0 );
|
|
#ifdef USE_IRIDESCENCE
|
|
computeMultiscatteringIridescence( material.dfg, material.specularColor, material.specularF90, material.iridescence, material.iridescenceF0Dielectric, singleScattering, multiScattering );
|
|
#else
|
|
computeMultiscattering( material.dfg, material.specularColor, material.specularF90, singleScattering, multiScattering );
|
|
#endif
|
|
#ifdef USE_DIFFUSE_ROUGHNESS
|
|
float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
|
|
vec3 diffuseAlbedo = EON_DirectionalAlbedo( material.diffuseColor, material.diffuseRoughness, dotNV ) * ( 1.0 - material.metalness );
|
|
vec3 diffuse = irradiance * RECIPROCAL_PI * diffuseAlbedo * ( 1.0 - singleScattering - multiScattering );
|
|
#else
|
|
vec3 diffuse = irradiance * BRDF_Lambert( material.diffuseContribution ) * ( 1.0 - singleScattering - multiScattering );
|
|
#endif
|
|
#ifdef USE_SHEEN
|
|
float sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
|
|
sheenSpecularIndirect += irradiance * material.sheenColor * sheenAlbedo * RECIPROCAL_PI;
|
|
float sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;
|
|
diffuse *= sheenEnergyComp;
|
|
#endif
|
|
reflectedLight.indirectDiffuse += diffuse;
|
|
}
|
|
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 ) * RECIPROCAL_PI;
|
|
#endif
|
|
vec3 singleScatteringDielectric = vec3( 0.0 );
|
|
vec3 multiScatteringDielectric = vec3( 0.0 );
|
|
vec3 singleScatteringMetallic = vec3( 0.0 );
|
|
vec3 multiScatteringMetallic = vec3( 0.0 );
|
|
#ifdef USE_IRIDESCENCE
|
|
computeMultiscatteringIridescence( material.dfg, material.specularColor, material.specularF90, material.iridescence, material.iridescenceF0Dielectric, singleScatteringDielectric, multiScatteringDielectric );
|
|
computeMultiscatteringIridescence( material.dfg, material.diffuseColor, material.specularF90, material.iridescence, material.iridescenceF0Metallic, singleScatteringMetallic, multiScatteringMetallic );
|
|
#else
|
|
computeMultiscattering( material.dfg, material.specularColor, material.specularF90, singleScatteringDielectric, multiScatteringDielectric );
|
|
computeMultiscattering( material.dfg, material.diffuseColor, material.specularF90, singleScatteringMetallic, multiScatteringMetallic );
|
|
#endif
|
|
vec3 singleScattering = mix( singleScatteringDielectric, singleScatteringMetallic, material.metalness );
|
|
vec3 multiScattering = mix( multiScatteringDielectric, multiScatteringMetallic, material.metalness );
|
|
vec3 totalScatteringDielectric = singleScatteringDielectric + multiScatteringDielectric;
|
|
#ifdef USE_DIFFUSE_ROUGHNESS
|
|
float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
|
|
vec3 diffuse = EON_DirectionalAlbedo( material.diffuseColor, material.diffuseRoughness, dotNV ) * ( 1.0 - material.metalness ) * ( 1.0 - totalScatteringDielectric );
|
|
#else
|
|
vec3 diffuse = material.diffuseContribution * ( 1.0 - totalScatteringDielectric );
|
|
#endif
|
|
vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;
|
|
vec3 indirectSpecular = radiance * singleScattering;
|
|
indirectSpecular += multiScattering * cosineWeightedIrradiance;
|
|
vec3 indirectDiffuse = diffuse * cosineWeightedIrradiance;
|
|
#ifdef USE_SHEEN
|
|
float sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
|
|
float sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;
|
|
indirectSpecular *= sheenEnergyComp;
|
|
indirectDiffuse *= sheenEnergyComp;
|
|
#endif
|
|
reflectedLight.indirectSpecular += indirectSpecular;
|
|
reflectedLight.indirectDiffuse += indirectDiffuse;
|
|
}
|
|
#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 );
|
|
}`,Lw=`
|
|
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 ) {
|
|
vec3 iridescenceFresnelDielectric = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );
|
|
vec3 iridescenceFresnelMetallic = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.diffuseColor );
|
|
material.iridescenceFresnel = mix( iridescenceFresnelDielectric, iridescenceFresnelMetallic, material.metalness );
|
|
material.iridescenceF0Dielectric = Schlick_to_F0( iridescenceFresnelDielectric, 1.0, dotNVi );
|
|
material.iridescenceF0Metallic = Schlick_to_F0( iridescenceFresnelMetallic, 1.0, dotNVi );
|
|
}
|
|
#endif
|
|
#ifdef STANDARD
|
|
float dotNVms = saturate( dot( geometryNormal, geometryViewDir ) );
|
|
material.dfg = texture2D( dfgLUT, vec2( material.roughness, dotNVms ) ).rg;
|
|
#if ( NUM_SUN_LIGHTS > 0 || NUM_DIR_LIGHTS > 0 || NUM_POINT_LIGHTS > 0 || NUM_SPOT_LIGHTS > 0 )
|
|
float EssMs = material.dfg.x + material.dfg.y;
|
|
material.multiScatteringCompensation = 1.0 + material.specularColorBlended * ( 1.0 / EssMs - 1.0 );
|
|
#endif
|
|
#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 ) && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )
|
|
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_SUN_LIGHTS > 0 ) && defined( RE_Direct )
|
|
SunLight sunLight;
|
|
#if defined( USE_SHADOWMAP ) && NUM_SUN_LIGHT_SHADOWS > 0
|
|
SunLightShadow sunLightShadow;
|
|
#endif
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_SUN_LIGHTS; i ++ ) {
|
|
sunLight = sunLights[ i ];
|
|
getSunLightInfo( sunLight, directLight );
|
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SUN_LIGHT_SHADOWS )
|
|
sunLightShadow = sunLightShadows[ i ];
|
|
directLight.color *= ( directLight.visible && receiveShadow ) ? getSunShadow( sunShadowMap[ i ], sunLightShadow, UNROLLED_LOOP_INDEX ) : 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
|
|
#if NUM_LIGHT_PROBE_GRIDS > 0
|
|
vec3 probeWorldPos = ( ( vec4( geometryPosition, 1.0 ) - viewMatrix[ 3 ] ) * viewMatrix ).xyz;
|
|
vec3 probeWorldNormal = transformNormalByInverseViewMatrix( geometryNormal, viewMatrix );
|
|
int probeGrid = - 1;
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_LIGHT_PROBE_GRIDS; i ++ ) {
|
|
if ( isInsideLightProbeGrid( probeWorldPos, probeWorldNormal, probesMin[ i ], probesMax[ i ], probesResolution[ i ] ) ) probeGrid = UNROLLED_LOOP_INDEX;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_LIGHT_PROBE_GRIDS; i ++ ) {
|
|
if ( probeGrid == UNROLLED_LOOP_INDEX ) irradiance += getLightProbeGridIrradiance( probesSH[ i ], probesMin[ i ], probesMax[ i ], probesResolution[ i ], probeWorldPos, probeWorldNormal );
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#endif
|
|
#if defined( RE_IndirectSpecular )
|
|
vec3 radiance = vec3( 0.0 );
|
|
vec3 clearcoatRadiance = vec3( 0.0 );
|
|
#endif`,Fw=`#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( ENVMAP_TYPE_PMREM )
|
|
#if defined( STANDARD ) || defined( LAMBERT ) || defined( PHONG )
|
|
iblIrradiance += getIBLIrradiance( geometryNormal );
|
|
#endif
|
|
#endif
|
|
#endif
|
|
#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
|
|
#ifdef USE_ANISOTROPY
|
|
vec3 iblRadiance = getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );
|
|
#else
|
|
vec3 iblRadiance = getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );
|
|
#endif
|
|
#ifdef USE_RETROREFLECTION
|
|
#ifdef USE_ANISOTROPY
|
|
vec3 retroIBLRadiance = getIBLAnisotropyRetroRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );
|
|
#else
|
|
vec3 retroIBLRadiance = getIBLRetroRadiance( geometryViewDir, geometryNormal, material.roughness );
|
|
#endif
|
|
iblRadiance = mix( iblRadiance, retroIBLRadiance, saturate( material.retroreflectivity ) );
|
|
#endif
|
|
radiance += iblRadiance;
|
|
#ifdef USE_CLEARCOAT
|
|
clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );
|
|
#endif
|
|
#endif`,Ow=`#if defined( RE_IndirectDiffuse )
|
|
#if defined( LAMBERT ) || defined( PHONG )
|
|
irradiance += iblIrradiance;
|
|
#endif
|
|
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`,Nw=`#if NUM_LIGHT_PROBE_GRIDS > 0
|
|
uniform highp sampler3D probesSH[ NUM_LIGHT_PROBE_GRIDS ];
|
|
uniform vec3 probesMin[ NUM_LIGHT_PROBE_GRIDS ];
|
|
uniform vec3 probesMax[ NUM_LIGHT_PROBE_GRIDS ];
|
|
uniform vec3 probesResolution[ NUM_LIGHT_PROBE_GRIDS ];
|
|
bool isInsideLightProbeGrid( vec3 worldPos, vec3 worldNormal, vec3 probesMin, vec3 probesMax, vec3 probesResolution ) {
|
|
vec3 spacing = ( probesMax - probesMin ) / probesResolution;
|
|
vec3 samplePos = worldPos + worldNormal * spacing * 0.5;
|
|
vec3 margin = spacing * 0.01;
|
|
return all( greaterThanEqual( samplePos, probesMin - margin ) ) && all( lessThanEqual( samplePos, probesMax + margin ) );
|
|
}
|
|
vec3 getLightProbeGridIrradiance( highp sampler3D probesSH, vec3 probesMin, vec3 probesMax, vec3 probesResolution, vec3 worldPos, vec3 worldNormal ) {
|
|
vec3 res = probesResolution;
|
|
vec3 gridRange = probesMax - probesMin;
|
|
vec3 probeSpacing = gridRange / res;
|
|
vec3 samplePos = worldPos + worldNormal * probeSpacing * 0.5;
|
|
vec3 uvw = clamp( ( samplePos - probesMin ) / gridRange, 0.5 / res, 1.0 - 0.5 / res );
|
|
float nz = res.z;
|
|
float paddedSlices = nz + 2.0;
|
|
float atlasDepth = 7.0 * paddedSlices;
|
|
float uvZBase = uvw.z * nz + 1.0;
|
|
vec4 s0 = texture( probesSH, vec3( uvw.xy, ( uvZBase ) / atlasDepth ) );
|
|
vec4 s1 = texture( probesSH, vec3( uvw.xy, ( uvZBase + paddedSlices ) / atlasDepth ) );
|
|
vec4 s2 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 2.0 * paddedSlices ) / atlasDepth ) );
|
|
vec4 s3 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 3.0 * paddedSlices ) / atlasDepth ) );
|
|
vec4 s4 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 4.0 * paddedSlices ) / atlasDepth ) );
|
|
vec4 s5 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 5.0 * paddedSlices ) / atlasDepth ) );
|
|
vec4 s6 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 6.0 * paddedSlices ) / atlasDepth ) );
|
|
vec3 c0 = s0.xyz;
|
|
vec3 c1 = vec3( s0.w, s1.xy );
|
|
vec3 c2 = vec3( s1.zw, s2.x );
|
|
vec3 c3 = s2.yzw;
|
|
vec3 c4 = s3.xyz;
|
|
vec3 c5 = vec3( s3.w, s4.xy );
|
|
vec3 c6 = vec3( s4.zw, s5.x );
|
|
vec3 c7 = s5.yzw;
|
|
vec3 c8 = s6.xyz;
|
|
float x = worldNormal.x, y = worldNormal.y, z = worldNormal.z;
|
|
vec3 result = c0 * 0.886227;
|
|
result += c1 * 2.0 * 0.511664 * y;
|
|
result += c2 * 2.0 * 0.511664 * z;
|
|
result += c3 * 2.0 * 0.511664 * x;
|
|
result += c4 * 2.0 * 0.429043 * x * y;
|
|
result += c5 * 2.0 * 0.429043 * y * z;
|
|
result += c6 * ( 0.743125 * z * z - 0.247708 );
|
|
result += c7 * 2.0 * 0.429043 * x * z;
|
|
result += c8 * 0.429043 * ( x * x - y * y );
|
|
return max( result, vec3( 0.0 ) );
|
|
}
|
|
#endif`,Dw=`#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )
|
|
gl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;
|
|
#endif`,Uw=`#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )
|
|
uniform float logDepthBufFC;
|
|
varying float vFragDepth;
|
|
varying float vIsPerspective;
|
|
#endif`,Bw=`#ifdef USE_LOGARITHMIC_DEPTH_BUFFER
|
|
varying float vFragDepth;
|
|
varying float vIsPerspective;
|
|
#endif`,kw=`#ifdef USE_LOGARITHMIC_DEPTH_BUFFER
|
|
vFragDepth = 1.0 + gl_Position.w;
|
|
vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );
|
|
#endif`,zw=`#ifdef USE_MAP
|
|
vec4 sampledDiffuseColor = texture2D( map, vMapUv );
|
|
#ifdef DECODE_VIDEO_TEXTURE
|
|
sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );
|
|
#endif
|
|
diffuseColor *= sampledDiffuseColor;
|
|
#endif`,Vw=`#ifdef USE_MAP
|
|
uniform sampler2D map;
|
|
#endif`,Gw=`#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`,Hw=`#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`,Ww=`float metalnessFactor = metalness;
|
|
#ifdef USE_METALNESSMAP
|
|
vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );
|
|
metalnessFactor *= texelMetalness.b;
|
|
#endif`,Xw=`#ifdef USE_METALNESSMAP
|
|
uniform sampler2D metalnessMap;
|
|
#endif`,Yw=`#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`,qw=`#if defined( USE_MORPHCOLORS )
|
|
#if defined( USE_COLOR_ALPHA )
|
|
vColor *= morphTargetBaseInfluence;
|
|
#elif defined( USE_COLOR )
|
|
vColor.rgb *= morphTargetBaseInfluence;
|
|
#endif
|
|
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.rgb += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];
|
|
#endif
|
|
}
|
|
#endif`,$w=`#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`,Kw=`#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`,Zw=`#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`,Jw=`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
|
|
#ifdef DOUBLE_SIDED
|
|
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
|
|
#ifdef DOUBLE_SIDED
|
|
tbn2[0] *= faceDirection;
|
|
tbn2[1] *= faceDirection;
|
|
#endif
|
|
#endif
|
|
vec3 nonPerturbedNormal = normal;`,jw=`#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;
|
|
#if defined( USE_PACKED_NORMALMAP )
|
|
mapN = vec3( mapN.xy, sqrt( saturate( 1.0 - dot( mapN.xy, mapN.xy ) ) ) );
|
|
#endif
|
|
mapN.xy *= normalScale;
|
|
normal = normalize( tbn * mapN );
|
|
#elif defined( USE_BUMPMAP )
|
|
normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );
|
|
#endif`,Qw=`#ifndef FLAT_SHADED
|
|
varying vec3 vNormal;
|
|
#ifdef USE_TANGENT
|
|
varying vec3 vTangent;
|
|
varying vec3 vBitangent;
|
|
#endif
|
|
#endif`,e2=`#ifndef FLAT_SHADED
|
|
varying vec3 vNormal;
|
|
#ifdef USE_TANGENT
|
|
varying vec3 vTangent;
|
|
varying vec3 vBitangent;
|
|
#endif
|
|
#endif`,t2=`#ifndef FLAT_SHADED
|
|
vNormal = normalize( transformedNormal );
|
|
#ifdef USE_TANGENT
|
|
vTangent = normalize( transformedTangent );
|
|
vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );
|
|
#ifdef FLIP_SIDED
|
|
vBitangent = - vBitangent;
|
|
#endif
|
|
#endif
|
|
#endif`,n2=`#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`,i2=`#ifdef USE_CLEARCOAT
|
|
vec3 clearcoatNormal = nonPerturbedNormal;
|
|
#endif`,r2=`#ifdef USE_CLEARCOAT_NORMALMAP
|
|
vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;
|
|
clearcoatMapN.xy *= clearcoatNormalScale;
|
|
clearcoatNormal = normalize( tbn2 * clearcoatMapN );
|
|
#endif`,s2=`#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`,o2=`#ifdef USE_IRIDESCENCEMAP
|
|
uniform sampler2D iridescenceMap;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE_THICKNESSMAP
|
|
uniform sampler2D iridescenceThicknessMap;
|
|
#endif`,a2=`#ifdef OPAQUE
|
|
diffuseColor.a = 1.0;
|
|
#endif
|
|
#ifdef USE_TRANSMISSION
|
|
diffuseColor.a *= material.transmissionAlpha;
|
|
#endif
|
|
gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,l2=`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 ) {
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
|
|
return depth * ( far - near ) - far;
|
|
#else
|
|
return depth * ( near - far ) - near;
|
|
#endif
|
|
}
|
|
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 ) {
|
|
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
return ( near * far ) / ( ( near - far ) * depth - near );
|
|
#else
|
|
return ( near * far ) / ( ( far - near ) * depth - far );
|
|
#endif
|
|
}`,c2=`#ifdef PREMULTIPLIED_ALPHA
|
|
gl_FragColor.rgb *= gl_FragColor.a;
|
|
#endif`,u2=`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;`,h2=`#ifdef DITHERING
|
|
gl_FragColor.rgb = dithering( gl_FragColor.rgb );
|
|
#endif`,f2=`#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`,d2=`float roughnessFactor = roughness;
|
|
#ifdef USE_ROUGHNESSMAP
|
|
vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );
|
|
roughnessFactor *= texelRoughness.g;
|
|
#endif`,p2=`#ifdef USE_ROUGHNESSMAP
|
|
uniform sampler2D roughnessMap;
|
|
#endif`,m2=`#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_SUN_LIGHT_SHADOWS > 0
|
|
#define SUN_LIGHT_CASCADES 2
|
|
#if defined( SHADOWMAP_TYPE_PCF )
|
|
uniform sampler2DShadow sunShadowMap[ NUM_SUN_LIGHT_SHADOWS ];
|
|
#else
|
|
uniform sampler2D sunShadowMap[ NUM_SUN_LIGHT_SHADOWS ];
|
|
#endif
|
|
uniform mat4 sunShadowMatrix[ NUM_SUN_LIGHT_SHADOWS * SUN_LIGHT_CASCADES ];
|
|
uniform vec4 sunShadowCascade[ NUM_SUN_LIGHT_SHADOWS * SUN_LIGHT_CASCADES ];
|
|
varying vec4 vSunShadowWorldPosition;
|
|
varying vec3 vSunShadowWorldNormal;
|
|
struct SunLightShadow {
|
|
float shadowIntensity;
|
|
float shadowBias;
|
|
float shadowNormalBias;
|
|
float shadowRadius;
|
|
vec2 shadowMapSize;
|
|
};
|
|
uniform SunLightShadow sunLightShadows[ NUM_SUN_LIGHT_SHADOWS ];
|
|
#endif
|
|
#if NUM_DIR_LIGHT_SHADOWS > 0
|
|
#if defined( SHADOWMAP_TYPE_PCF )
|
|
uniform sampler2DShadow directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
|
|
#else
|
|
uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
|
|
#endif
|
|
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
|
|
#if defined( SHADOWMAP_TYPE_PCF )
|
|
uniform sampler2DShadow spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
|
|
#else
|
|
uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
|
|
#endif
|
|
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
|
|
#if defined( SHADOWMAP_TYPE_PCF )
|
|
uniform samplerCubeShadow pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];
|
|
#elif defined( SHADOWMAP_TYPE_BASIC )
|
|
uniform samplerCube pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];
|
|
#endif
|
|
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
|
|
#if defined( SHADOWMAP_TYPE_PCF )
|
|
float interleavedGradientNoise( vec2 position ) {
|
|
return fract( 52.9829189 * fract( dot( position, vec2( 0.06711056, 0.00583715 ) ) ) );
|
|
}
|
|
vec2 vogelDiskSample( int sampleIndex, int samplesCount, float phi ) {
|
|
const float goldenAngle = 2.399963229728653;
|
|
float r = sqrt( ( float( sampleIndex ) + 0.5 ) / float( samplesCount ) );
|
|
float theta = float( sampleIndex ) * goldenAngle + phi;
|
|
return vec2( cos( theta ), sin( theta ) ) * r;
|
|
}
|
|
#endif
|
|
#if defined( SHADOWMAP_TYPE_PCF )
|
|
float getShadow( sampler2DShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
|
|
float shadow = 1.0;
|
|
shadowCoord.xyz /= shadowCoord.w;
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
shadowCoord.z -= shadowBias;
|
|
#else
|
|
shadowCoord.z += shadowBias;
|
|
#endif
|
|
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 ) {
|
|
vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
|
|
vec2 radius = shadowRadius * texelSize;
|
|
float phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;
|
|
shadow = (
|
|
texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 0, 5, phi ) * radius, shadowCoord.z ) ) +
|
|
texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 1, 5, phi ) * radius, shadowCoord.z ) ) +
|
|
texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 2, 5, phi ) * radius, shadowCoord.z ) ) +
|
|
texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 3, 5, phi ) * radius, shadowCoord.z ) ) +
|
|
texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 4, 5, phi ) * radius, shadowCoord.z ) )
|
|
) * 0.2;
|
|
}
|
|
return mix( 1.0, shadow, shadowIntensity );
|
|
}
|
|
#elif defined( SHADOWMAP_TYPE_VSM )
|
|
float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
|
|
float shadow = 1.0;
|
|
shadowCoord.xyz /= shadowCoord.w;
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
shadowCoord.z -= shadowBias;
|
|
#else
|
|
shadowCoord.z += shadowBias;
|
|
#endif
|
|
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 ) {
|
|
vec2 distribution = texture2D( shadowMap, shadowCoord.xy ).rg;
|
|
float mean = distribution.x;
|
|
float variance = distribution.y * distribution.y;
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
float hard_shadow = step( mean, shadowCoord.z );
|
|
#else
|
|
float hard_shadow = step( shadowCoord.z, mean );
|
|
#endif
|
|
|
|
if ( hard_shadow == 1.0 ) {
|
|
shadow = 1.0;
|
|
} else {
|
|
variance = max( variance, 0.0000001 );
|
|
float d = shadowCoord.z - mean;
|
|
float p_max = variance / ( variance + d * d );
|
|
p_max = clamp( ( p_max - 0.3 ) / 0.65, 0.0, 1.0 );
|
|
shadow = max( hard_shadow, p_max );
|
|
}
|
|
}
|
|
return mix( 1.0, shadow, shadowIntensity );
|
|
}
|
|
#else
|
|
float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
|
|
float shadow = 1.0;
|
|
shadowCoord.xyz /= shadowCoord.w;
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
shadowCoord.z -= shadowBias;
|
|
#else
|
|
shadowCoord.z += shadowBias;
|
|
#endif
|
|
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 ) {
|
|
float depth = texture2D( shadowMap, shadowCoord.xy ).r;
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
shadow = step( depth, shadowCoord.z );
|
|
#else
|
|
shadow = step( shadowCoord.z, depth );
|
|
#endif
|
|
}
|
|
return mix( 1.0, shadow, shadowIntensity );
|
|
}
|
|
#endif
|
|
#if NUM_SUN_LIGHT_SHADOWS > 0
|
|
float getSunShadow(
|
|
#if defined( SHADOWMAP_TYPE_PCF )
|
|
sampler2DShadow shadowMap,
|
|
#else
|
|
sampler2D shadowMap,
|
|
#endif
|
|
SunLightShadow sunLightShadow,
|
|
int shadowIndex
|
|
) {
|
|
vec4 shadowWorldPosition = vec4( vSunShadowWorldPosition.xyz + vSunShadowWorldNormal * sunLightShadow.shadowNormalBias, 1.0 );
|
|
float viewDepth = vSunShadowWorldPosition.w;
|
|
int cascadeOffset = shadowIndex * SUN_LIGHT_CASCADES;
|
|
float shadow = 1.0;
|
|
for ( int i = SUN_LIGHT_CASCADES - 1; i >= 0; i -- ) {
|
|
vec4 cascade = sunShadowCascade[ cascadeOffset + i ];
|
|
if ( viewDepth >= cascade.x && viewDepth < cascade.y ) {
|
|
float cascadeShadow = getShadow(
|
|
shadowMap,
|
|
sunLightShadow.shadowMapSize,
|
|
sunLightShadow.shadowIntensity,
|
|
sunLightShadow.shadowBias,
|
|
sunLightShadow.shadowRadius,
|
|
sunShadowMatrix[ cascadeOffset + i ] * shadowWorldPosition
|
|
);
|
|
shadow = mix( cascadeShadow, shadow, smoothstep( cascade.z, cascade.y, viewDepth ) );
|
|
}
|
|
}
|
|
return shadow;
|
|
}
|
|
#endif
|
|
#if NUM_POINT_LIGHT_SHADOWS > 0
|
|
#if defined( SHADOWMAP_TYPE_PCF )
|
|
float getPointShadow( samplerCubeShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
|
|
float shadow = 1.0;
|
|
vec3 lightToPosition = shadowCoord.xyz;
|
|
vec3 bd3D = normalize( lightToPosition );
|
|
vec3 absVec = abs( lightToPosition );
|
|
float viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );
|
|
if ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {
|
|
float lightDistance = length( lightToPosition );
|
|
float depthRange = shadowCameraFar - shadowCameraNear;
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
float depthA = - shadowCameraNear / depthRange - shadowBias;
|
|
float depthB = shadowCameraNear * shadowCameraFar / ( depthRange * lightDistance );
|
|
#else
|
|
float depthA = shadowCameraFar / depthRange + shadowBias;
|
|
float depthB = - shadowCameraNear * shadowCameraFar / ( depthRange * lightDistance );
|
|
#endif
|
|
float texelSize = shadowRadius / shadowMapSize.x;
|
|
vec3 absDir = abs( bd3D );
|
|
vec3 tangent = absDir.x > absDir.z ? vec3( 0.0, 1.0, 0.0 ) : vec3( 1.0, 0.0, 0.0 );
|
|
tangent = normalize( cross( bd3D, tangent ) );
|
|
vec3 bitangent = cross( bd3D, tangent );
|
|
float phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;
|
|
shadow = 0.0;
|
|
for ( int i = 0; i < 5; i ++ ) {
|
|
vec2 offset = vogelDiskSample( i, 5, phi );
|
|
vec3 direction = bd3D + ( tangent * offset.x + bitangent * offset.y ) * texelSize;
|
|
vec3 absDirection = abs( direction );
|
|
float dp = depthA + depthB / max( max( absDirection.x, absDirection.y ), absDirection.z );
|
|
shadow += texture( shadowMap, vec4( direction, dp ) );
|
|
}
|
|
shadow *= 0.2;
|
|
}
|
|
return mix( 1.0, shadow, shadowIntensity );
|
|
}
|
|
#elif defined( SHADOWMAP_TYPE_BASIC )
|
|
float getPointShadow( samplerCube shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
|
|
float shadow = 1.0;
|
|
vec3 lightToPosition = shadowCoord.xyz;
|
|
vec3 absVec = abs( lightToPosition );
|
|
float viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );
|
|
if ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {
|
|
float dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );
|
|
dp += shadowBias;
|
|
vec3 bd3D = normalize( lightToPosition );
|
|
float depth = textureCube( shadowMap, bd3D ).r;
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
depth = 1.0 - depth;
|
|
#endif
|
|
shadow = step( dp, depth );
|
|
}
|
|
return mix( 1.0, shadow, shadowIntensity );
|
|
}
|
|
#endif
|
|
#endif
|
|
#endif`,g2=`#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_SUN_LIGHT_SHADOWS > 0
|
|
varying vec4 vSunShadowWorldPosition;
|
|
varying vec3 vSunShadowWorldNormal;
|
|
#endif
|
|
#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`,x2=`#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_SUN_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )
|
|
#ifdef HAS_NORMAL
|
|
vec3 shadowWorldNormal = transformNormalByInverseViewMatrix( transformedNormal, viewMatrix );
|
|
#else
|
|
vec3 shadowWorldNormal = vec3( 0.0 );
|
|
#endif
|
|
vec4 shadowWorldPosition;
|
|
#endif
|
|
#if defined( USE_SHADOWMAP )
|
|
#if NUM_SUN_LIGHT_SHADOWS > 0
|
|
vSunShadowWorldPosition = vec4( worldPosition.xyz, - mvPosition.z );
|
|
vSunShadowWorldNormal = shadowWorldNormal;
|
|
#endif
|
|
#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`,b2=`float getShadowMask() {
|
|
float shadow = 1.0;
|
|
#ifdef USE_SHADOWMAP
|
|
#if NUM_SUN_LIGHT_SHADOWS > 0
|
|
SunLightShadow sunLight;
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_SUN_LIGHT_SHADOWS; i ++ ) {
|
|
sunLight = sunLightShadows[ i ];
|
|
shadow *= receiveShadow ? getSunShadow( sunShadowMap[ i ], sunLight, UNROLLED_LOOP_INDEX ) : 1.0;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#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 && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )
|
|
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;
|
|
}`,y2=`#ifdef USE_SKINNING
|
|
mat4 boneMatX = getBoneMatrix( skinIndex.x );
|
|
mat4 boneMatY = getBoneMatrix( skinIndex.y );
|
|
mat4 boneMatZ = getBoneMatrix( skinIndex.z );
|
|
mat4 boneMatW = getBoneMatrix( skinIndex.w );
|
|
#endif`,_2=`#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`,v2=`#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`,M2=`#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`,S2=`float specularStrength;
|
|
#ifdef USE_SPECULARMAP
|
|
vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );
|
|
specularStrength = texelSpecular.r;
|
|
#else
|
|
specularStrength = 1.0;
|
|
#endif`,w2=`#ifdef USE_SPECULARMAP
|
|
uniform sampler2D specularMap;
|
|
#endif`,T2=`#if defined( TONE_MAPPING )
|
|
gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
|
|
#endif`,A2=`#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; }`,E2=`#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 = transformNormalByInverseViewMatrix( normal, viewMatrix );
|
|
vec4 transmitted = getIBLVolumeRefraction(
|
|
n, v, material.roughness, material.diffuseContribution, material.specularColorBlended, 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`,R2=`#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`,C2=`#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_DIFFUSE_ROUGHNESSMAP
|
|
varying vec2 vDiffuseRoughnessMapUv;
|
|
#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`,P2=`#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_DIFFUSE_ROUGHNESSMAP
|
|
uniform mat3 diffuseRoughnessMapTransform;
|
|
varying vec2 vDiffuseRoughnessMapUv;
|
|
#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`,I2=`#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_DIFFUSE_ROUGHNESSMAP
|
|
vDiffuseRoughnessMapUv = ( diffuseRoughnessMapTransform * vec3( DIFFUSE_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`,L2=`#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`,F2=`varying vec2 vUv;
|
|
uniform mat3 uvTransform;
|
|
void main() {
|
|
vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
|
|
gl_Position = vec4( position.xy, 1.0, 1.0 );
|
|
}`,O2=`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 <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
}`,N2=`varying vec3 vWorldDirection;
|
|
#include <common>
|
|
void main() {
|
|
vWorldDirection = transformDirection( position, modelMatrix );
|
|
#include <begin_vertex>
|
|
#include <project_vertex>
|
|
gl_Position.z = gl_Position.w;
|
|
}`,D2=`uniform float backgroundBlurriness;
|
|
uniform float backgroundIntensity;
|
|
uniform mat3 backgroundRotation;
|
|
varying vec3 vWorldDirection;
|
|
#include <envmap_common_pars_fragment>
|
|
void main() {
|
|
#ifdef ENVMAP_TYPE_PMREM
|
|
vec4 texColor = textureLod( envMap, backgroundRotation * vWorldDirection, roughnessToMip( backgroundBlurriness ) );
|
|
#else
|
|
vec4 texColor = textureCube( envMap, backgroundRotation * vWorldDirection );
|
|
#endif
|
|
texColor.rgb *= backgroundIntensity;
|
|
gl_FragColor = texColor;
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
}`,U2=`varying vec3 vWorldDirection;
|
|
#include <common>
|
|
void main() {
|
|
vWorldDirection = transformDirection( position, modelMatrix );
|
|
#include <begin_vertex>
|
|
#include <project_vertex>
|
|
gl_Position.z = gl_Position.w;
|
|
}`,B2=`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 <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
}`,k2=`#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
varying vec2 vHighPrecisionZW;
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <batching_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <morphinstance_vertex>
|
|
#ifdef USE_DISPLACEMENTMAP
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinnormal_vertex>
|
|
#endif
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vHighPrecisionZW = gl_Position.zw;
|
|
}`,z2=`#if DEPTH_PACKING == 3200
|
|
uniform float opacity;
|
|
#endif
|
|
#include <common>
|
|
#include <packing>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
varying vec2 vHighPrecisionZW;
|
|
void main() {
|
|
vec4 diffuseColor = vec4( 1.0 );
|
|
#include <clipping_planes_fragment>
|
|
#if DEPTH_PACKING == 3200
|
|
diffuseColor.a = opacity;
|
|
#endif
|
|
#include <map_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <logdepthbuf_fragment>
|
|
#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
|
|
}`,V2=`#define DISTANCE
|
|
varying vec3 vWorldPosition;
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <batching_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <morphinstance_vertex>
|
|
#ifdef USE_DISPLACEMENTMAP
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinnormal_vertex>
|
|
#endif
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <worldpos_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vWorldPosition = worldPosition.xyz;
|
|
}`,G2=`#define DISTANCE
|
|
uniform vec3 referencePosition;
|
|
uniform float nearDistance;
|
|
uniform float farDistance;
|
|
varying vec3 vWorldPosition;
|
|
#include <common>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( 1.0 );
|
|
#include <clipping_planes_fragment>
|
|
#include <map_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
float dist = length( vWorldPosition - referencePosition );
|
|
dist = ( dist - nearDistance ) / ( farDistance - nearDistance );
|
|
dist = saturate( dist );
|
|
gl_FragColor = vec4( dist, 0.0, 0.0, 1.0 );
|
|
}`,H2=`varying vec3 vWorldDirection;
|
|
#include <common>
|
|
void main() {
|
|
vWorldDirection = transformDirection( position, modelMatrix );
|
|
#include <begin_vertex>
|
|
#include <project_vertex>
|
|
}`,W2=`uniform sampler2D tEquirect;
|
|
varying vec3 vWorldDirection;
|
|
#include <common>
|
|
void main() {
|
|
vec3 direction = normalize( vWorldDirection );
|
|
vec2 sampleUV = equirectUv( direction );
|
|
gl_FragColor = texture2D( tEquirect, sampleUV );
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
}`,X2=`uniform float scale;
|
|
attribute float lineDistance;
|
|
varying float vLineDistance;
|
|
#include <common>
|
|
#include <uv_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
vLineDistance = scale * lineDistance;
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#include <fog_vertex>
|
|
}`,Y2=`uniform vec3 diffuse;
|
|
uniform float opacity;
|
|
uniform float dashSize;
|
|
uniform float totalSize;
|
|
varying float vLineDistance;
|
|
#include <common>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
if ( mod( vLineDistance, totalSize ) > dashSize ) {
|
|
discard;
|
|
}
|
|
vec3 outgoingLight = vec3( 0.0 );
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
outgoingLight = diffuseColor.rgb;
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
}`,q2=`#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <envmap_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#endif
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#include <worldpos_vertex>
|
|
#include <envmap_vertex>
|
|
#include <fog_vertex>
|
|
}`,$2=`uniform vec3 diffuse;
|
|
uniform float opacity;
|
|
#ifndef FLAT_SHADED
|
|
varying vec3 vNormal;
|
|
#endif
|
|
#include <common>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <aomap_pars_fragment>
|
|
#include <lightmap_pars_fragment>
|
|
#include <envmap_common_pars_fragment>
|
|
#include <envmap_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <specularmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <specularmap_fragment>
|
|
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 <aomap_fragment>
|
|
reflectedLight.indirectDiffuse *= diffuseColor.rgb;
|
|
vec3 outgoingLight = reflectedLight.indirectDiffuse;
|
|
#include <envmap_fragment>
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`,K2=`#define LAMBERT
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <envmap_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <shadowmap_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vViewPosition = - mvPosition.xyz;
|
|
#include <worldpos_vertex>
|
|
#include <envmap_vertex>
|
|
#include <shadowmap_vertex>
|
|
#include <fog_vertex>
|
|
}`,Z2=`#define LAMBERT
|
|
uniform vec3 diffuse;
|
|
uniform vec3 emissive;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <aomap_pars_fragment>
|
|
#include <lightmap_pars_fragment>
|
|
#include <emissivemap_pars_fragment>
|
|
#include <envmap_common_pars_fragment>
|
|
#include <envmap_pars_fragment>
|
|
#include <envmap_physical_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <bsdfs>
|
|
#include <lights_pars_begin>
|
|
#include <normal_pars_fragment>
|
|
#include <lights_lambert_pars_fragment>
|
|
#include <shadowmap_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <specularmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
vec3 totalEmissiveRadiance = emissive;
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <specularmap_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
#include <emissivemap_fragment>
|
|
#include <lights_lambert_fragment>
|
|
#include <lights_fragment_begin>
|
|
#include <lights_fragment_maps>
|
|
#include <lights_fragment_end>
|
|
#include <aomap_fragment>
|
|
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
|
|
#include <envmap_fragment>
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`,J2=`#define MATCAP
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#include <fog_vertex>
|
|
vViewPosition = - mvPosition.xyz;
|
|
}`,j2=`#define MATCAP
|
|
uniform vec3 diffuse;
|
|
uniform float opacity;
|
|
uniform sampler2D matcap;
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <normal_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
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 <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`,Q2=`#define NORMAL
|
|
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
|
|
varying vec3 vViewPosition;
|
|
#endif
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
|
|
vViewPosition = - mvPosition.xyz;
|
|
#endif
|
|
}`,eT=`#define NORMAL
|
|
uniform float opacity;
|
|
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
|
|
varying vec3 vViewPosition;
|
|
#endif
|
|
#include <uv_pars_fragment>
|
|
#include <normal_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );
|
|
#include <clipping_planes_fragment>
|
|
#include <logdepthbuf_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
gl_FragColor = vec4( normalize( normal ) * 0.5 + 0.5, diffuseColor.a );
|
|
#ifdef OPAQUE
|
|
gl_FragColor.a = 1.0;
|
|
#endif
|
|
}`,tT=`#define PHONG
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <envmap_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <shadowmap_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vViewPosition = - mvPosition.xyz;
|
|
#include <worldpos_vertex>
|
|
#include <envmap_vertex>
|
|
#include <shadowmap_vertex>
|
|
#include <fog_vertex>
|
|
}`,nT=`#define PHONG
|
|
uniform vec3 diffuse;
|
|
uniform vec3 emissive;
|
|
uniform vec3 specular;
|
|
uniform float shininess;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <aomap_pars_fragment>
|
|
#include <lightmap_pars_fragment>
|
|
#include <emissivemap_pars_fragment>
|
|
#include <envmap_common_pars_fragment>
|
|
#include <envmap_pars_fragment>
|
|
#include <envmap_physical_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <bsdfs>
|
|
#include <lights_pars_begin>
|
|
#include <normal_pars_fragment>
|
|
#include <lights_phong_pars_fragment>
|
|
#include <shadowmap_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <specularmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
vec3 totalEmissiveRadiance = emissive;
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <specularmap_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
#include <emissivemap_fragment>
|
|
#include <lights_phong_fragment>
|
|
#include <lights_fragment_begin>
|
|
#include <lights_fragment_maps>
|
|
#include <lights_fragment_end>
|
|
#include <aomap_fragment>
|
|
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;
|
|
#include <envmap_fragment>
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`,iT=`#define STANDARD
|
|
varying vec3 vViewPosition;
|
|
#ifdef USE_TRANSMISSION
|
|
varying vec3 vWorldPosition;
|
|
#endif
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <shadowmap_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vViewPosition = - mvPosition.xyz;
|
|
#include <worldpos_vertex>
|
|
#include <shadowmap_vertex>
|
|
#include <fog_vertex>
|
|
#ifdef USE_TRANSMISSION
|
|
vWorldPosition = worldPosition.xyz;
|
|
#endif
|
|
}`,rT=`#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_DIFFUSE_ROUGHNESS
|
|
uniform float diffuseRoughness;
|
|
#ifdef USE_DIFFUSE_ROUGHNESSMAP
|
|
uniform sampler2D diffuseRoughnessMap;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_DISPERSION
|
|
uniform float dispersion;
|
|
#endif
|
|
#ifdef USE_RETROREFLECTION
|
|
uniform float retroreflectivity;
|
|
#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 <common>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <aomap_pars_fragment>
|
|
#include <lightmap_pars_fragment>
|
|
#include <emissivemap_pars_fragment>
|
|
#include <iridescence_fragment>
|
|
#include <envmap_common_pars_fragment>
|
|
#include <envmap_physical_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <lights_pars_begin>
|
|
#include <normal_pars_fragment>
|
|
#include <lights_physical_pars_fragment>
|
|
#include <transmission_pars_fragment>
|
|
#include <shadowmap_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <clearcoat_pars_fragment>
|
|
#include <iridescence_pars_fragment>
|
|
#include <roughnessmap_pars_fragment>
|
|
#include <metalnessmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
vec3 totalEmissiveRadiance = emissive;
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <roughnessmap_fragment>
|
|
#include <metalnessmap_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
#include <clearcoat_normal_fragment_begin>
|
|
#include <clearcoat_normal_fragment_maps>
|
|
#include <emissivemap_fragment>
|
|
#include <lights_physical_fragment>
|
|
#include <lights_fragment_begin>
|
|
#include <lights_fragment_maps>
|
|
#include <lights_fragment_end>
|
|
#include <aomap_fragment>
|
|
vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;
|
|
vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;
|
|
#include <transmission_fragment>
|
|
vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
|
|
#ifdef USE_SHEEN
|
|
|
|
outgoingLight = outgoingLight + 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 <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`,sT=`#define TOON
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <shadowmap_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vViewPosition = - mvPosition.xyz;
|
|
#include <worldpos_vertex>
|
|
#include <shadowmap_vertex>
|
|
#include <fog_vertex>
|
|
}`,oT=`#define TOON
|
|
uniform vec3 diffuse;
|
|
uniform vec3 emissive;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <aomap_pars_fragment>
|
|
#include <lightmap_pars_fragment>
|
|
#include <emissivemap_pars_fragment>
|
|
#include <gradientmap_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <bsdfs>
|
|
#include <lights_pars_begin>
|
|
#include <normal_pars_fragment>
|
|
#include <lights_toon_pars_fragment>
|
|
#include <shadowmap_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
vec3 totalEmissiveRadiance = emissive;
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
#include <emissivemap_fragment>
|
|
#include <lights_toon_fragment>
|
|
#include <lights_fragment_begin>
|
|
#include <lights_fragment_maps>
|
|
#include <lights_fragment_end>
|
|
#include <aomap_fragment>
|
|
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`,aT=`uniform float size;
|
|
uniform float scale;
|
|
#include <common>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
#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 <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <project_vertex>
|
|
gl_PointSize = size;
|
|
#ifdef USE_SIZEATTENUATION
|
|
bool isPerspective = isPerspectiveMatrix( projectionMatrix );
|
|
if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );
|
|
#endif
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#include <worldpos_vertex>
|
|
#include <fog_vertex>
|
|
}`,lT=`uniform vec3 diffuse;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <color_pars_fragment>
|
|
#include <map_particle_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
vec3 outgoingLight = vec3( 0.0 );
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_particle_fragment>
|
|
#include <color_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
outgoingLight = diffuseColor.rgb;
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
}`,cT=`#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <shadowmap_pars_vertex>
|
|
void main() {
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <worldpos_vertex>
|
|
#include <shadowmap_vertex>
|
|
#include <fog_vertex>
|
|
}`,uT=`uniform vec3 color;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <fog_pars_fragment>
|
|
#include <bsdfs>
|
|
#include <lights_pars_begin>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <shadowmap_pars_fragment>
|
|
#include <shadowmask_pars_fragment>
|
|
void main() {
|
|
#include <logdepthbuf_fragment>
|
|
gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
}`,hT=`uniform float rotation;
|
|
uniform vec2 center;
|
|
#include <common>
|
|
#include <uv_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
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 <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#include <fog_vertex>
|
|
}`,fT=`uniform vec3 diffuse;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
vec3 outgoingLight = vec3( 0.0 );
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
outgoingLight = diffuseColor.rgb;
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
}`,Qe={alphahash_fragment:OS,alphahash_pars_fragment:NS,alphamap_fragment:DS,alphamap_pars_fragment:US,alphatest_fragment:BS,alphatest_pars_fragment:kS,aomap_fragment:zS,aomap_pars_fragment:VS,batching_pars_vertex:GS,batching_vertex:HS,begin_vertex:WS,beginnormal_vertex:XS,bsdfs:YS,iridescence_fragment:qS,bumpmap_pars_fragment:$S,clipping_planes_fragment:KS,clipping_planes_pars_fragment:ZS,clipping_planes_pars_vertex:JS,clipping_planes_vertex:jS,color_fragment:QS,color_pars_fragment:ew,color_pars_vertex:tw,color_vertex:nw,common:iw,defaultnormal_vertex:rw,displacementmap_pars_vertex:sw,displacementmap_vertex:ow,emissivemap_fragment:aw,emissivemap_pars_fragment:lw,colorspace_fragment:cw,colorspace_pars_fragment:uw,envmap_fragment:hw,envmap_common_pars_fragment:fw,envmap_pars_fragment:dw,envmap_pars_vertex:pw,envmap_physical_pars_fragment:Tw,envmap_vertex:mw,fog_vertex:gw,fog_pars_vertex:xw,fog_fragment:bw,fog_pars_fragment:yw,gradientmap_pars_fragment:_w,lightmap_pars_fragment:vw,lights_lambert_fragment:Mw,lights_lambert_pars_fragment:Sw,lights_pars_begin:ww,lights_toon_fragment:Aw,lights_toon_pars_fragment:Ew,lights_phong_fragment:Rw,lights_phong_pars_fragment:Cw,lights_physical_fragment:Pw,lights_physical_pars_fragment:Iw,lights_fragment_begin:Lw,lights_fragment_maps:Fw,lights_fragment_end:Ow,lightprobes_pars_fragment:Nw,logdepthbuf_fragment:Dw,logdepthbuf_pars_fragment:Uw,logdepthbuf_pars_vertex:Bw,logdepthbuf_vertex:kw,map_fragment:zw,map_pars_fragment:Vw,map_particle_fragment:Gw,map_particle_pars_fragment:Hw,metalnessmap_fragment:Ww,metalnessmap_pars_fragment:Xw,morphinstance_vertex:Yw,morphcolor_vertex:qw,morphnormal_vertex:$w,morphtarget_pars_vertex:Kw,morphtarget_vertex:Zw,normal_fragment_begin:Jw,normal_fragment_maps:jw,normal_pars_fragment:Qw,normal_pars_vertex:e2,normal_vertex:t2,normalmap_pars_fragment:n2,clearcoat_normal_fragment_begin:i2,clearcoat_normal_fragment_maps:r2,clearcoat_pars_fragment:s2,iridescence_pars_fragment:o2,opaque_fragment:a2,packing:l2,premultiplied_alpha_fragment:c2,project_vertex:u2,dithering_fragment:h2,dithering_pars_fragment:f2,roughnessmap_fragment:d2,roughnessmap_pars_fragment:p2,shadowmap_pars_fragment:m2,shadowmap_pars_vertex:g2,shadowmap_vertex:x2,shadowmask_pars_fragment:b2,skinbase_vertex:y2,skinning_pars_vertex:_2,skinning_vertex:v2,skinnormal_vertex:M2,specularmap_fragment:S2,specularmap_pars_fragment:w2,tonemapping_fragment:T2,tonemapping_pars_fragment:A2,transmission_fragment:E2,transmission_pars_fragment:R2,uv_pars_fragment:C2,uv_pars_vertex:P2,uv_vertex:I2,worldpos_vertex:L2,background_vert:F2,background_frag:O2,backgroundCube_vert:N2,backgroundCube_frag:D2,cube_vert:U2,cube_frag:B2,depth_vert:k2,depth_frag:z2,distance_vert:V2,distance_frag:G2,equirect_vert:H2,equirect_frag:W2,linedashed_vert:X2,linedashed_frag:Y2,meshbasic_vert:q2,meshbasic_frag:$2,meshlambert_vert:K2,meshlambert_frag:Z2,meshmatcap_vert:J2,meshmatcap_frag:j2,meshnormal_vert:Q2,meshnormal_frag:eT,meshphong_vert:tT,meshphong_frag:nT,meshphysical_vert:iT,meshphysical_frag:rT,meshtoon_vert:sT,meshtoon_frag:oT,points_vert:aT,points_frag:lT,shadow_vert:cT,shadow_frag:uT,sprite_vert:hT,sprite_frag:fT},ve={common:{diffuse:{value:new W(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new He},alphaMap:{value:null},alphaMapTransform:{value:new He},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new He}},envmap:{envMap:{value:null},envMapRotation:{value:new He},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98},dfgLUT:{value:null}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new He}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new He}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new He},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new He},normalScale:{value:new De(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new He},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new He}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new He}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new He}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new W(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},sunLights:{value:[],properties:{direction:{},color:{}}},sunLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},sunShadowMatrix:{value:[]},sunShadowCascade:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null},probesSH:{value:[]},probesMin:{value:[]},probesMax:{value:[]},probesResolution:{value:[]}},points:{diffuse:{value:new W(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new He},alphaTest:{value:0},uvTransform:{value:new He}},sprite:{diffuse:{value:new W(16777215)},opacity:{value:1},center:{value:new De(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new He},alphaMap:{value:null},alphaMapTransform:{value:new He},alphaTest:{value:0}}},Pi={basic:{uniforms:bn([ve.common,ve.specularmap,ve.envmap,ve.aomap,ve.lightmap,ve.fog]),vertexShader:Qe.meshbasic_vert,fragmentShader:Qe.meshbasic_frag},lambert:{uniforms:bn([ve.common,ve.specularmap,ve.envmap,ve.aomap,ve.lightmap,ve.emissivemap,ve.bumpmap,ve.normalmap,ve.displacementmap,ve.fog,ve.lights,{emissive:{value:new W(0)},envMapIntensity:{value:1}}]),vertexShader:Qe.meshlambert_vert,fragmentShader:Qe.meshlambert_frag},phong:{uniforms:bn([ve.common,ve.specularmap,ve.envmap,ve.aomap,ve.lightmap,ve.emissivemap,ve.bumpmap,ve.normalmap,ve.displacementmap,ve.fog,ve.lights,{emissive:{value:new W(0)},specular:{value:new W(1118481)},shininess:{value:30},envMapIntensity:{value:1}}]),vertexShader:Qe.meshphong_vert,fragmentShader:Qe.meshphong_frag},standard:{uniforms:bn([ve.common,ve.envmap,ve.aomap,ve.lightmap,ve.emissivemap,ve.bumpmap,ve.normalmap,ve.displacementmap,ve.roughnessmap,ve.metalnessmap,ve.fog,ve.lights,{emissive:{value:new W(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Qe.meshphysical_vert,fragmentShader:Qe.meshphysical_frag},toon:{uniforms:bn([ve.common,ve.aomap,ve.lightmap,ve.emissivemap,ve.bumpmap,ve.normalmap,ve.displacementmap,ve.gradientmap,ve.fog,ve.lights,{emissive:{value:new W(0)}}]),vertexShader:Qe.meshtoon_vert,fragmentShader:Qe.meshtoon_frag},matcap:{uniforms:bn([ve.common,ve.bumpmap,ve.normalmap,ve.displacementmap,ve.fog,{matcap:{value:null}}]),vertexShader:Qe.meshmatcap_vert,fragmentShader:Qe.meshmatcap_frag},points:{uniforms:bn([ve.points,ve.fog]),vertexShader:Qe.points_vert,fragmentShader:Qe.points_frag},dashed:{uniforms:bn([ve.common,ve.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Qe.linedashed_vert,fragmentShader:Qe.linedashed_frag},depth:{uniforms:bn([ve.common,ve.displacementmap]),vertexShader:Qe.depth_vert,fragmentShader:Qe.depth_frag},normal:{uniforms:bn([ve.common,ve.bumpmap,ve.normalmap,ve.displacementmap,{opacity:{value:1}}]),vertexShader:Qe.meshnormal_vert,fragmentShader:Qe.meshnormal_frag},sprite:{uniforms:bn([ve.sprite,ve.fog]),vertexShader:Qe.sprite_vert,fragmentShader:Qe.sprite_frag},background:{uniforms:{uvTransform:{value:new He},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:Qe.background_vert,fragmentShader:Qe.background_frag},backgroundCube:{uniforms:{envMap:{value:null},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new He}},vertexShader:Qe.backgroundCube_vert,fragmentShader:Qe.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:Qe.cube_vert,fragmentShader:Qe.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Qe.equirect_vert,fragmentShader:Qe.equirect_frag},distance:{uniforms:bn([ve.common,ve.displacementmap,{referencePosition:{value:new U},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Qe.distance_vert,fragmentShader:Qe.distance_frag},shadow:{uniforms:bn([ve.lights,ve.fog,{color:{value:new W(0)},opacity:{value:1}}]),vertexShader:Qe.shadow_vert,fragmentShader:Qe.shadow_frag}};Pi.physical={uniforms:bn([Pi.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new He},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new He},clearcoatNormalScale:{value:new De(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new He},diffuseRoughness:{value:0},diffuseRoughnessMap:{value:null},diffuseRoughnessMapTransform:{value:new He},dispersion:{value:0},retroreflectivity:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new He},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new He},sheen:{value:0},sheenColor:{value:new W(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new He},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new He},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new He},transmissionSamplerSize:{value:new De},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new He},attenuationDistance:{value:0},attenuationColor:{value:new W(0)},specularColor:{value:new W(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new He},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new He},anisotropyVector:{value:new De},anisotropyMap:{value:null},anisotropyMapTransform:{value:new He}}]),vertexShader:Qe.meshphysical_vert,fragmentShader:Qe.meshphysical_frag};var Au={r:0,b:0,g:0},dT=new Be,Xx=new He;Xx.set(-1,0,0,0,1,0,0,0,1);function pT(i,e,t,n,r,s){let o=new W(0),a=r===!0?0:1,l,c,u=null,h=0,f=null;function d(b){let v=b.isScene===!0?b.background:null;if(v&&v.isTexture){let y=b.backgroundBlurriness>0;v=e.get(v,y)}return v}function p(b){let v=!1,y=d(b);y===null?g(o,a):y&&y.isColor&&(g(y,1),v=!0);let M=i.xr.getEnvironmentBlendMode();M==="additive"?t.buffers.color.setClear(0,0,0,1,s):M==="alpha-blend"&&t.buffers.color.setClear(0,0,0,0,s),(i.autoClear||v)&&(t.buffers.depth.setTest(!0),t.buffers.depth.setMask(!0),t.buffers.color.setMask(!0),i.clear(i.autoClearColor,i.autoClearDepth,i.autoClearStencil))}function x(b,v){let y=d(v);y&&y.isCubeTexture?(c===void 0&&(c=new we(new Fr(1,1,1),new Mi({name:"BackgroundCubeMaterial",uniforms:ys(Pi.backgroundCube.uniforms),vertexShader:Pi.backgroundCube.vertexShader,fragmentShader:Pi.backgroundCube.fragmentShader,side:un,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),c.geometry.deleteAttribute("normal"),c.geometry.deleteAttribute("uv"),c.onBeforeRender=function(M,S,_){this.matrixWorld.copyPosition(_.matrixWorld)},Object.defineProperty(c.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),n.update(c)),c.material.uniforms.envMap.value=y,c.material.uniforms.backgroundBlurriness.value=v.backgroundBlurriness,c.material.uniforms.backgroundIntensity.value=v.backgroundIntensity,c.material.uniforms.backgroundRotation.value.setFromMatrix4(dT.makeRotationFromEuler(v.backgroundRotation)).transpose(),y.isRenderTargetTexture===!1&&c.material.uniforms.backgroundRotation.value.premultiply(Xx),c.material.toneMapped=tt.getTransfer(y.colorSpace)!==Mt,(u!==y||h!==y.version||f!==i.toneMapping)&&(c.material.needsUpdate=!0,u=y,h=y.version,f=i.toneMapping),c.layers.enableAll(),b.unshift(c,c.geometry,c.material,0,0,null)):y&&y.isTexture&&(l===void 0&&(l=new we(new sn(2,2),new Mi({name:"BackgroundMaterial",uniforms:ys(Pi.background.uniforms),vertexShader:Pi.background.vertexShader,fragmentShader:Pi.background.fragmentShader,side:Ti,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),l.geometry.deleteAttribute("normal"),Object.defineProperty(l.material,"map",{get:function(){return this.uniforms.t2D.value}}),n.update(l)),l.material.uniforms.t2D.value=y,l.material.uniforms.backgroundIntensity.value=v.backgroundIntensity,l.material.toneMapped=tt.getTransfer(y.colorSpace)!==Mt,y.matrixAutoUpdate===!0&&y.updateMatrix(),l.material.uniforms.uvTransform.value.copy(y.matrix),(u!==y||h!==y.version||f!==i.toneMapping)&&(l.material.needsUpdate=!0,u=y,h=y.version,f=i.toneMapping),l.layers.enableAll(),b.unshift(l,l.geometry,l.material,0,0,null))}function g(b,v){b.getRGB(Au,od(i)),t.buffers.color.setClear(Au.r,Au.g,Au.b,v,s)}function m(){c!==void 0&&(c.geometry.dispose(),c.material.dispose(),c=void 0),l!==void 0&&(l.geometry.dispose(),l.material.dispose(),l=void 0)}return{getClearColor:function(){return o},setClearColor:function(b,v=1){o.set(b),a=v,g(o,a)},getClearAlpha:function(){return a},setClearAlpha:function(b){a=b,g(o,a)},render:p,addToRenderList:x,dispose:m}}function mT(i,e){let t=i.getParameter(i.MAX_VERTEX_ATTRIBS),n={},r=f(null),s=r,o=!1;function a(C,O,D,P,I){let N=!1,F=h(C,P,D,O);s!==F&&(s=F,c(s.object)),N=d(C,P,D,I),N&&p(C,P,D,I),I!==null&&e.update(I,i.ELEMENT_ARRAY_BUFFER),(N||o)&&(o=!1,y(C,O,D,P),I!==null&&i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,e.get(I).buffer))}function l(){return i.createVertexArray()}function c(C){return i.bindVertexArray(C)}function u(C){return i.deleteVertexArray(C)}function h(C,O,D,P){let I=P.wireframe===!0,N=n[O.id];N===void 0&&(N={},n[O.id]=N);let F=C.isInstancedMesh===!0?C.id:0,H=N[F];H===void 0&&(H={},N[F]=H);let B=H[D.id];B===void 0&&(B={},H[D.id]=B);let X=B[I];return X===void 0&&(X=f(l()),B[I]=X),X}function f(C){let O=[],D=[],P=[];for(let I=0;I<t;I++)O[I]=0,D[I]=0,P[I]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:O,enabledAttributes:D,attributeDivisors:P,object:C,attributes:{},index:null}}function d(C,O,D,P){let I=s.attributes,N=O.attributes,F=0,H=D.getAttributes();for(let B in H)if(H[B].location>=0){let V=I[B],re=N[B];if(re===void 0&&(B==="instanceMatrix"&&C.instanceMatrix&&(re=C.instanceMatrix),B==="instanceColor"&&C.instanceColor&&(re=C.instanceColor)),V===void 0||V.attribute!==re||re&&V.data!==re.data)return!0;F++}return s.attributesNum!==F||s.index!==P}function p(C,O,D,P){let I={},N=O.attributes,F=0,H=D.getAttributes();for(let B in H)if(H[B].location>=0){let V=N[B];V===void 0&&(B==="instanceMatrix"&&C.instanceMatrix&&(V=C.instanceMatrix),B==="instanceColor"&&C.instanceColor&&(V=C.instanceColor));let re={};re.attribute=V,V&&V.data&&(re.data=V.data),I[B]=re,F++}s.attributes=I,s.attributesNum=F,s.index=P}function x(){let C=s.newAttributes;for(let O=0,D=C.length;O<D;O++)C[O]=0}function g(C){m(C,0)}function m(C,O){let D=s.newAttributes,P=s.enabledAttributes,I=s.attributeDivisors;D[C]=1,P[C]===0&&(i.enableVertexAttribArray(C),P[C]=1),I[C]!==O&&(i.vertexAttribDivisor(C,O),I[C]=O)}function b(){let C=s.newAttributes,O=s.enabledAttributes;for(let D=0,P=O.length;D<P;D++)O[D]!==C[D]&&(i.disableVertexAttribArray(D),O[D]=0)}function v(C,O,D,P,I,N,F){F===!0?i.vertexAttribIPointer(C,O,D,I,N):i.vertexAttribPointer(C,O,D,P,I,N)}function y(C,O,D,P){x();let I=P.attributes,N=D.getAttributes(),F=O.defaultAttributeValues;for(let H in N){let B=N[H];if(B.location>=0){let X=I[H];if(X===void 0&&(H==="instanceMatrix"&&C.instanceMatrix&&(X=C.instanceMatrix),H==="instanceColor"&&C.instanceColor&&(X=C.instanceColor)),X!==void 0){let V=X.normalized,re=X.itemSize,be=e.get(X);if(be===void 0)continue;let Y=be.buffer,Q=be.type,se=be.bytesPerElement,Se=Q===i.INT||Q===i.UNSIGNED_INT||X.gpuType===Gc;if(X.isInterleavedBufferAttribute){let le=X.data,Ie=le.isInterleavedBuffer===!0?le.stride:le.itemSize,st=X.offset;if(le.isInstancedInterleavedBuffer||le.isInstancedBufferAttribute){for(let Te=0;Te<B.locationSize;Te++)m(B.location+Te,le.meshPerAttribute);C.isInstancedMesh!==!0&&P._maxInstanceCount===void 0&&(P._maxInstanceCount=le.meshPerAttribute*le.count)}else for(let Te=0;Te<B.locationSize;Te++)g(B.location+Te);i.bindBuffer(i.ARRAY_BUFFER,Y);for(let Te=0;Te<B.locationSize;Te++)v(B.location+Te,re/B.locationSize,Q,V,Ie*se,(st+re/B.locationSize*Te)*se,Se)}else{if(X.isInstancedBufferAttribute){for(let le=0;le<B.locationSize;le++)m(B.location+le,X.meshPerAttribute);C.isInstancedMesh!==!0&&P._maxInstanceCount===void 0&&(P._maxInstanceCount=X.meshPerAttribute*X.count)}else for(let le=0;le<B.locationSize;le++)g(B.location+le);i.bindBuffer(i.ARRAY_BUFFER,Y);for(let le=0;le<B.locationSize;le++)v(B.location+le,re/B.locationSize,Q,V,re*se,re/B.locationSize*le*se,Se)}}else if(F!==void 0){let V=F[H];if(V!==void 0)switch(V.length){case 2:i.vertexAttrib2fv(B.location,V);break;case 3:i.vertexAttrib3fv(B.location,V);break;case 4:i.vertexAttrib4fv(B.location,V);break;default:i.vertexAttrib1fv(B.location,V)}}}}b()}function M(){R();for(let C in n){let O=n[C];for(let D in O){let P=O[D];for(let I in P){let N=P[I];for(let F in N)u(N[F].object),delete N[F];delete P[I]}}delete n[C]}}function S(C){if(n[C.id]===void 0)return;let O=n[C.id];for(let D in O){let P=O[D];for(let I in P){let N=P[I];for(let F in N)u(N[F].object),delete N[F];delete P[I]}}delete n[C.id]}function _(C){for(let O in n){let D=n[O];for(let P in D){let I=D[P];if(I[C.id]===void 0)continue;let N=I[C.id];for(let F in N)u(N[F].object),delete N[F];delete I[C.id]}}}function w(C){for(let O in n){let D=n[O],P=C.isInstancedMesh===!0?C.id:0,I=D[P];if(I!==void 0){for(let N in I){let F=I[N];for(let H in F)u(F[H].object),delete F[H];delete I[N]}delete D[P],Object.keys(D).length===0&&delete n[O]}}}function R(){A(),o=!0,s!==r&&(s=r,c(s.object))}function A(){r.geometry=null,r.program=null,r.wireframe=!1}return{setup:a,reset:R,resetDefaultState:A,dispose:M,releaseStatesOfGeometry:S,releaseStatesOfObject:w,releaseStatesOfProgram:_,initAttributes:x,enableAttribute:g,disableUnusedAttributes:b}}function gT(i,e,t){let n;function r(l){n=l}function s(l,c){i.drawArrays(n,l,c),t.update(c,n,1)}function o(l,c,u){u!==0&&(i.drawArraysInstanced(n,l,c,u),t.update(c,n,u))}function a(l,c,u){if(u===0)return;e.get("WEBGL_multi_draw").multiDrawArraysWEBGL(n,l,0,c,0,u);let f=0;for(let d=0;d<u;d++)f+=c[d];t.update(f,n,1)}this.setMode=r,this.render=s,this.renderInstances=o,this.renderMultiDraw=a}function xT(i,e,t,n){let r;function s(){if(r!==void 0)return r;if(e.has("EXT_texture_filter_anisotropic")===!0){let _=e.get("EXT_texture_filter_anisotropic");r=i.getParameter(_.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else r=0;return r}function o(_){return!(_!==Nn&&n.convert(_)!==i.getParameter(i.IMPLEMENTATION_COLOR_READ_FORMAT))}function a(_){let w=_===ai&&(e.has("EXT_color_buffer_half_float")||e.has("EXT_color_buffer_float"));return!(_!==On&&_!==Vn&&!w&&n.convert(_)!==i.getParameter(i.IMPLEMENTATION_COLOR_READ_TYPE))}function l(_){if(_==="highp"){if(i.getShaderPrecisionFormat(i.VERTEX_SHADER,i.HIGH_FLOAT).precision>0&&i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.HIGH_FLOAT).precision>0)return"highp";_="mediump"}return _==="mediump"&&i.getShaderPrecisionFormat(i.VERTEX_SHADER,i.MEDIUM_FLOAT).precision>0&&i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let c=t.precision!==void 0?t.precision:"highp",u=l(c);u!==c&&(Le("WebGLRenderer:",c,"not supported, using",u,"instead."),c=u);let h=t.reversedDepthBuffer===!0&&e.has("EXT_clip_control"),f=t.logarithmicDepthBuffer===!0&&h===!1;t.reversedDepthBuffer===!0&&h===!1&&Le("WebGLRenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer."),t.logarithmicDepthBuffer===!0&&h===!0&&Le("WebGLRenderer: Logarithmic depth buffer is ignored when reversed depth buffer is enabled.");let d=i.getParameter(i.MAX_TEXTURE_IMAGE_UNITS),p=i.getParameter(i.MAX_VERTEX_TEXTURE_IMAGE_UNITS),x=i.getParameter(i.MAX_TEXTURE_SIZE),g=i.getParameter(i.MAX_CUBE_MAP_TEXTURE_SIZE),m=i.getParameter(i.MAX_VERTEX_ATTRIBS),b=i.getParameter(i.MAX_VERTEX_UNIFORM_VECTORS),v=i.getParameter(i.MAX_VARYING_VECTORS),y=i.getParameter(i.MAX_FRAGMENT_UNIFORM_VECTORS),M=i.getParameter(i.MAX_SAMPLES),S=i.getParameter(i.SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:s,getMaxPrecision:l,textureFormatReadable:o,textureTypeReadable:a,precision:c,logarithmicDepthBuffer:f,reversedDepthBuffer:h,maxTextures:d,maxVertexTextures:p,maxTextureSize:x,maxCubemapSize:g,maxAttributes:m,maxVertexUniforms:b,maxVaryings:v,maxFragmentUniforms:y,maxSamples:M,samples:S}}function bT(i){let e=this,t=null,n=0,r=!1,s=!1,o=new si,a=new He,l={value:null,needsUpdate:!1};this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(h,f){let d=h.length!==0||f||n!==0||r;return r=f,n=h.length,d},this.beginShadows=function(){s=!0,u(null)},this.endShadows=function(){s=!1},this.setGlobalState=function(h,f){t=u(h,f,0)},this.setState=function(h,f,d){let p=h.clippingPlanes,x=h.clipIntersection,g=h.clipShadows,m=i.get(h);if(!r||p===null||p.length===0||s&&!g)s?u(null):c();else{let b=s?0:n,v=b*4,y=m.clippingState||null;l.value=y,y=u(p,f,v,d);for(let M=0;M!==v;++M)y[M]=t[M];m.clippingState=y,this.numIntersection=x?this.numPlanes:0,this.numPlanes+=b}};function c(){l.value!==t&&(l.value=t,l.needsUpdate=n>0),e.numPlanes=n,e.numIntersection=0}function u(h,f,d,p){let x=h!==null?h.length:0,g=null;if(x!==0){if(g=l.value,p!==!0||g===null){let m=d+x*4,b=f.matrixWorldInverse;a.getNormalMatrix(b),(g===null||g.length<m)&&(g=new Float32Array(m));for(let v=0,y=d;v!==x;++v,y+=4)o.copy(h[v]).applyMatrix4(b,a),o.normal.toArray(g,y),g[y+3]=o.constant}l.value=g,l.needsUpdate=!0}return e.numPlanes=x,e.numIntersection=0,g}}var Ja=class extends wn{constructor(e=1,t={}){super(e,e,t),this.isWebGLCubeRenderTarget=!0;let n={width:e,height:e,depth:1},r=[n,n,n,n,n,n];this.texture=new va(r),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 <begin_vertex>
|
|
#include <project_vertex>
|
|
|
|
}
|
|
`,fragmentShader:`
|
|
|
|
uniform sampler2D tEquirect;
|
|
|
|
varying vec3 vWorldDirection;
|
|
|
|
#include <common>
|
|
|
|
void main() {
|
|
|
|
vec3 direction = normalize( vWorldDirection );
|
|
|
|
vec2 sampleUV = equirectUv( direction );
|
|
|
|
gl_FragColor = texture2D( tEquirect, sampleUV );
|
|
|
|
}
|
|
`},r=new Fr(5,5,5),s=new Mi({name:"CubemapFromEquirect",uniforms:ys(n.uniforms),vertexShader:n.vertexShader,fragmentShader:n.fragmentShader,side:un,blending:ms});s.uniforms.tEquirect.value=t;let o=new we(r,s),a=t.minFilter;return t.minFilter===Fn&&(t.minFilter=Ht),new xo(1,10,this).update(e,o),t.minFilter=a,o.geometry.dispose(),o.material.dispose(),this}clear(e,t=!0,n=!0,r=!0){let s=e.getRenderTarget();for(let o=0;o<6;o++)e.setRenderTarget(this,o),e.clear(t,n,r);e.setRenderTarget(s)}},Sx=256,yT=3,_T=20,Yx=256,qx=16,vT=3,MT=new U,ST=new W,wo=class i{constructor(e){this._renderer=e,this._cubeSize=0,this._sourceTarget=null,this._cubeCamera=new xo(1,10,null),this._boxMesh=new we(new Fr(5,5,5),null),this._cubemapMaterial=null,this._equirectMaterial=null,this._blurMaterial=null,this._ggxMaterial=null,this._integrationMaterial=null}fromScene(e,t=0,n=.1,r=100,s={}){let{size:o=256,position:a=MT}=s,l=this._renderer;this._setSize(o);let c=this._allocateTarget(),u=this._getSourceTarget(!0);t>0&&(u.texture.mipmapsAutoUpdate=!1);let h=l.autoClear,f=l.autoClearColor,d=l.autoClearDepth,p=l.autoClearStencil,x=e.background;l.autoClear=!0,l.autoClearColor=!0,l.autoClearDepth=!0,l.autoClearStencil=!0,x===null&&(e.background=l.getClearColor(ST));let g=new xo(n,r,u);return g.position.copy(a),g.update(l,e),l.autoClear=h,l.autoClearColor=f,l.autoClearDepth=d,l.autoClearStencil=p,e.background=x,t>0&&(u.texture.mipmapsAutoUpdate=!0,this._blur(c,t)),this._applyPMREM(c),c}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=Ax(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=Tx(),this._compileMaterial(this._equirectMaterial))}dispose(){this._sourceTarget!==null&&this._sourceTarget.dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._blurMaterial!==null&&this._blurMaterial.dispose(),this._ggxMaterial!==null&&this._ggxMaterial.dispose(),this._integrationMaterial!==null&&this._integrationMaterial.dispose(),this._boxMesh.geometry.dispose()}static lodToRoughness(e,t){return t>0?1-Math.sqrt(1-e/t):0}_setSize(e){this._cubeSize=Math.max(Sx,id(e))}_fromTexture(e,t){e.mapping===xs||e.mapping===yo?this._setSize(e.image.length===0?Sx:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4);let n=t||this._allocateTarget();return this._textureToCubemap(e),this._applyPMREM(n),n}_allocateTarget(){let e=this._cubeSize,t=wx(e,!1,!1),n=Math.log2(e)-yT;for(let r=0;r<=n;r++)t.texture.mipmaps.push({width:e>>r,height:e>>r});return t.texture.name="PMREM",t.texture.isPMREMTexture=!0,t}_getSourceTarget(e=!1){let t=this._cubeSize,n=this._sourceTarget;return(n===null||n.width!==t||e&&n.depthBuffer===!1)&&(n!==null&&n.dispose(),this._sourceTarget=wx(t,!0,e)),this._sourceTarget}_compileMaterial(e){this._boxMesh.material=e,this._renderer.compile(this._boxMesh,this._cubeCamera.children[0])}_renderCube(e,t,n){let r=this._boxMesh,s=this._cubeCamera;r.material=n,s.renderTarget=e,s.activeMipmapLevel=t;let o=e.width>>t;e.viewport.set(0,0,o,o),s.update(this._renderer,r),e.viewport.set(0,0,e.width,e.height)}_textureToCubemap(e){let t;e.mapping===xs||e.mapping===yo?(this._cubemapMaterial===null&&(this._cubemapMaterial=Ax()),t=this._cubemapMaterial,t.uniforms.flipEnvMap.value=e.isRenderTargetTexture===!1?-1:1):(this._equirectMaterial===null&&(this._equirectMaterial=Tx()),t=this._equirectMaterial),t.uniforms.envMap.value=e,this._renderCube(this._getSourceTarget(),0,t)}_applyPMREM(e){this._ggxMaterial===null&&(this._ggxMaterial=wT(),this._integrationMaterial=TT());let t=this._cubeSize,n=e.texture.mipmaps.length-1,r=this._ggxMaterial.uniforms;r.envMap.value=this._sourceTarget.texture;let s=this._integrationMaterial.uniforms;s.envMap.value=this._sourceTarget.texture,s.sourceLod.value=Math.log2(t/qx);for(let o=0;o<=n;o++){let a=i.lodToRoughness(o,n);if(o>n-vT)s.roughness.value=a,this._renderCube(e,o,this._integrationMaterial);else{let l=a>0?Math.log2(t)+.5*Math.log2(6/(Yx*Math.pow(a,4)))+.5:0;r.roughness.value=a,r.lodBias.value=l,this._renderCube(e,o,this._ggxMaterial)}}}_blur(e,t){this._blurMaterial===null&&(this._blurMaterial=AT());let n=this._blurMaterial,r=n.uniforms,s=this._sourceTarget;r.sigma.value=Math.min(t,Math.PI)/Math.SQRT2,r.envMap.value=s.texture,this._renderCube(e,0,n),r.envMap.value=e.texture,this._renderCube(s,0,n)}};function wx(i,e,t){return new Ja(i,{minFilter:Fn,generateMipmaps:e,type:ai,colorSpace:Mn,depthBuffer:t})}function ja(i,e,t){return new Mi({name:i,uniforms:e,vertexShader:Qe.cube_vert,fragmentShader:t,side:un,blending:ms,depthTest:!1,depthWrite:!1})}function wT(){return ja("PMREMGGXConvolution",{envMap:{value:null},roughness:{value:0},lodBias:{value:0}},`
|
|
|
|
#define GGX_SAMPLES ${Yx}u
|
|
|
|
varying vec3 vWorldDirection;
|
|
|
|
uniform samplerCube envMap;
|
|
uniform float roughness;
|
|
uniform float lodBias;
|
|
|
|
#include <common>
|
|
|
|
// Van der Corput radical inverse
|
|
float radicalInverse_VdC( uint bits ) {
|
|
|
|
bits = ( bits << 16u ) | ( bits >> 16u );
|
|
bits = ( ( bits & 0x55555555u ) << 1u ) | ( ( bits & 0xAAAAAAAAu ) >> 1u );
|
|
bits = ( ( bits & 0x33333333u ) << 2u ) | ( ( bits & 0xCCCCCCCCu ) >> 2u );
|
|
bits = ( ( bits & 0x0F0F0F0Fu ) << 4u ) | ( ( bits & 0xF0F0F0F0u ) >> 4u );
|
|
bits = ( ( bits & 0x00FF00FFu ) << 8u ) | ( ( bits & 0xFF00FF00u ) >> 8u );
|
|
return float( bits ) * 2.3283064365386963e-10; // / 0x100000000
|
|
|
|
}
|
|
|
|
// Hammersley sequence
|
|
vec2 hammersley( uint i, uint N ) {
|
|
|
|
return vec2( float( i ) / float( N ), radicalInverse_VdC( i ) );
|
|
|
|
}
|
|
|
|
void main() {
|
|
|
|
vec3 N = normalize( vWorldDirection );
|
|
|
|
// For very low roughness, just sample the environment directly
|
|
if ( roughness < 0.001 ) {
|
|
|
|
gl_FragColor = vec4( textureLod( envMap, N, 0.0 ).rgb, 1.0 );
|
|
return;
|
|
|
|
}
|
|
|
|
float alpha = roughness * roughness;
|
|
float alpha2 = alpha * alpha;
|
|
|
|
// Tangent space basis for VNDF sampling
|
|
vec3 up = abs( N.z ) < 0.999 ? vec3( 0.0, 0.0, 1.0 ) : vec3( 1.0, 0.0, 0.0 );
|
|
vec3 tangent = normalize( cross( up, N ) );
|
|
vec3 bitangent = cross( N, tangent );
|
|
|
|
vec3 prefilteredColor = vec3( 0.0 );
|
|
float totalWeight = 0.0;
|
|
|
|
for ( uint i = 0u; i < GGX_SAMPLES; i ++ ) {
|
|
|
|
vec2 Xi = hammersley( i, GGX_SAMPLES );
|
|
|
|
// With V = N, sample the reflected direction directly.
|
|
float invQ = 1.0 / ( 1.0 - Xi.x + alpha2 * Xi.x );
|
|
float NdotL = ( 1.0 - Xi.x - alpha2 * Xi.x ) * invQ;
|
|
|
|
if ( NdotL > 0.0 ) {
|
|
|
|
float phi = 2.0 * PI * Xi.y;
|
|
float sinTheta = 2.0 * alpha * sqrt( Xi.x * ( 1.0 - Xi.x ) ) * invQ;
|
|
vec3 L = N * NdotL + ( tangent * cos( phi ) + bitangent * sin( phi ) ) * sinTheta;
|
|
|
|
// Match the source mip to the sample's solid angle. The terms
|
|
// independent of the sample are precomputed in lodBias.
|
|
float d = alpha2 * invQ;
|
|
float lod = max( log2( d ) + lodBias, 0.0 );
|
|
|
|
// Weight by NdotL for the split-sum approximation
|
|
prefilteredColor += textureLod( envMap, L, lod ).rgb * NdotL;
|
|
totalWeight += NdotL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gl_FragColor = vec4( prefilteredColor / totalWeight, 1.0 );
|
|
|
|
}
|
|
`)}function TT(){return ja("PMREMGGXIntegration",{envMap:{value:null},roughness:{value:0},sourceLod:{value:0},sourceSize:{value:qx}},`
|
|
|
|
varying vec3 vWorldDirection;
|
|
|
|
uniform samplerCube envMap;
|
|
uniform float roughness;
|
|
uniform float sourceLod;
|
|
uniform int sourceSize;
|
|
|
|
void main() {
|
|
|
|
vec3 N = normalize( vWorldDirection );
|
|
|
|
float alpha = roughness * roughness;
|
|
float alpha2 = alpha * alpha;
|
|
|
|
float texelSize = 2.0 / float( sourceSize );
|
|
|
|
vec3 prefilteredColor = vec3( 0.0 );
|
|
float totalWeight = 0.0;
|
|
|
|
// Pair opposite texels: only the one in N's hemisphere contributes.
|
|
for ( int face = 0; face < 3; face ++ ) {
|
|
|
|
for ( int y = 0; y < sourceSize; y ++ ) {
|
|
|
|
for ( int x = 0; x < sourceSize; x ++ ) {
|
|
|
|
vec2 uv = ( vec2( x, y ) + 0.5 ) * texelSize - 1.0;
|
|
vec3 texelDirection = face == 0 ? vec3( 1.0, uv ) : ( face == 1 ? vec3( uv.x, 1.0, uv.y ) : vec3( uv, 1.0 ) );
|
|
|
|
float invDistance = inversesqrt( 1.0 + dot( uv, uv ) );
|
|
float NdotL = dot( N, texelDirection );
|
|
texelDirection *= NdotL < 0.0 ? - 1.0 : 1.0;
|
|
NdotL = abs( NdotL ) * invDistance;
|
|
|
|
// With V = N, NdotH squared is ( 1 + NdotL ) / 2. Common factors
|
|
// in the GGX distribution and texel solid angle cancel when normalized.
|
|
float d = 1.0 + alpha2 + ( alpha2 - 1.0 ) * NdotL;
|
|
float weight = NdotL * invDistance * invDistance * invDistance / ( d * d );
|
|
|
|
prefilteredColor += textureLod( envMap, texelDirection, sourceLod ).rgb * weight;
|
|
totalWeight += weight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gl_FragColor = vec4( prefilteredColor / totalWeight, 1.0 );
|
|
|
|
}
|
|
`)}function AT(){return ja("PMREMSphericalGaussianBlur",{envMap:{value:null},sigma:{value:0}},`
|
|
|
|
#define SAMPLES ${_T}
|
|
#define GOLDEN_ANGLE 2.39996322973
|
|
|
|
varying vec3 vWorldDirection;
|
|
|
|
uniform samplerCube envMap;
|
|
uniform float sigma;
|
|
|
|
#include <common>
|
|
|
|
void main() {
|
|
|
|
vec3 outputDirection = normalize( vWorldDirection );
|
|
|
|
vec3 up = abs( outputDirection.z ) < 0.999 ? vec3( 0.0, 0.0, 1.0 ) : vec3( 1.0, 0.0, 0.0 );
|
|
vec3 tangent = normalize( cross( up, outputDirection ) );
|
|
vec3 bitangent = cross( outputDirection, tangent );
|
|
|
|
// Truncate the kernel at three standard deviations or at the antipode.
|
|
float thetaMax = min( 3.0 * sigma, PI );
|
|
float truncation = 1.0 - exp( - 0.5 * thetaMax * thetaMax / ( sigma * sigma ) );
|
|
|
|
vec3 accumColor = vec3( 0.0 );
|
|
float accumWeight = 0.0;
|
|
|
|
for ( int i = 0; i < SAMPLES; i ++ ) {
|
|
|
|
// Stratified inverse-CDF sampling of the Gaussian, placed on a golden-angle spiral.
|
|
float stratum = ( float( i ) + 0.5 ) / float( SAMPLES );
|
|
float theta = sigma * sqrt( - 2.0 * log( 1.0 - stratum * truncation ) );
|
|
float phi = float( i ) * GOLDEN_ANGLE;
|
|
|
|
vec3 offset = cos( phi ) * tangent + sin( phi ) * bitangent;
|
|
vec3 sampleDirection = cos( theta ) * outputDirection + sin( theta ) * offset;
|
|
|
|
// Correct the planar sample density to solid angle.
|
|
float weight = sin( theta ) / theta;
|
|
|
|
accumColor += weight * textureLod( envMap, sampleDirection, 0.0 ).rgb;
|
|
accumWeight += weight;
|
|
|
|
}
|
|
|
|
gl_FragColor = vec4( accumColor / accumWeight, 1.0 );
|
|
|
|
}
|
|
`)}function Tx(){return ja("PMREMEquirectangularToCubemap",{envMap:{value:null}},`
|
|
|
|
varying vec3 vWorldDirection;
|
|
|
|
uniform sampler2D envMap;
|
|
|
|
#include <common>
|
|
|
|
void main() {
|
|
|
|
// Average four subpixel samples to preserve small, bright features.
|
|
vec3 direction = normalize( vWorldDirection );
|
|
vec3 dx = dFdx( direction ) * 0.25;
|
|
vec3 dy = dFdy( direction ) * 0.25;
|
|
|
|
vec3 color = textureLod( envMap, equirectUv( normalize( direction - dx - dy ) ), 0.0 ).rgb;
|
|
color += textureLod( envMap, equirectUv( normalize( direction + dx - dy ) ), 0.0 ).rgb;
|
|
color += textureLod( envMap, equirectUv( normalize( direction - dx + dy ) ), 0.0 ).rgb;
|
|
color += textureLod( envMap, equirectUv( normalize( direction + dx + dy ) ), 0.0 ).rgb;
|
|
gl_FragColor = vec4( color * 0.25, 1.0 );
|
|
|
|
}
|
|
`)}function Ax(){return ja("PMREMCubemapToCubemap",{envMap:{value:null},flipEnvMap:{value:-1}},`
|
|
|
|
varying vec3 vWorldDirection;
|
|
|
|
uniform samplerCube envMap;
|
|
uniform float flipEnvMap;
|
|
|
|
void main() {
|
|
|
|
gl_FragColor = vec4( textureCube( envMap, vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) ).rgb, 1.0 );
|
|
|
|
}
|
|
`)}function ET(i){let e=new WeakMap,t=new WeakMap,n=null;function r(f,d=!1){return f==null?null:d?o(f):s(f)}function s(f){if(f&&f.isTexture){let d=f.mapping;if(d===zc||d===Vc)if(e.has(f)){let p=e.get(f).texture;return a(p,f.mapping)}else{let p=f.image;if(p&&p.height>0){let x=new Ja(p.height);return x.fromEquirectangularTexture(i,f),e.set(f,x),f.addEventListener("dispose",c),a(x.texture,f.mapping)}else return null}}return f}function o(f){if(f&&f.isTexture&&f.isPMREMTexture!==!0){let d=f.mapping,p=d===zc||d===Vc,x=d===xs||d===yo;if(p||x){let g=t.get(f),m=g!==void 0?g.texture.pmremVersion:0;if(f.isRenderTargetTexture&&f.pmremVersion!==m)return n===null&&(n=new wo(i)),g=p?n.fromEquirectangular(f,g):n.fromCubemap(f,g),g.texture.pmremVersion=f.pmremVersion,t.set(f,g),g.texture;if(g!==void 0)return g.texture;{let b=f.image;return p&&b&&b.height>0||x&&b&&l(b)?(n===null&&(n=new wo(i)),g=p?n.fromEquirectangular(f):n.fromCubemap(f),g.texture.pmremVersion=f.pmremVersion,t.set(f,g),f.addEventListener("dispose",u),g.texture):null}}}return f}function a(f,d){return d===zc?f.mapping=xs:d===Vc&&(f.mapping=yo),f}function l(f){let d=0,p=6;for(let x=0;x<p;x++)f[x]!==void 0&&d++;return d===p}function c(f){let d=f.target;d.removeEventListener("dispose",c);let p=e.get(d);p!==void 0&&(e.delete(d),p.dispose())}function u(f){let d=f.target;d.removeEventListener("dispose",u);let p=t.get(d);p!==void 0&&(t.delete(d),p.dispose())}function h(){e=new WeakMap,t=new WeakMap,n!==null&&(n.dispose(),n=null)}return{get:r,dispose:h}}function RT(i){let e={};function t(n){if(e[n]!==void 0)return e[n];let r=i.getExtension(n);return e[n]=r,r}return{has:function(n){return t(n)!==null},init:function(){t("EXT_color_buffer_float"),t("WEBGL_clip_cull_distance"),t("OES_texture_float_linear"),t("EXT_color_buffer_half_float"),t("WEBGL_multisampled_render_to_texture"),t("WEBGL_render_shared_exponent")},get:function(n){let r=t(n);return r===null&&os("WebGLRenderer: "+n+" extension not supported."),r}}}function CT(i,e,t,n){let r={},s=new WeakMap,o=new FinalizationRegistry(p=>delete r[p]);function a(p){l(p.target)}function l(p){p.index!==null&&e.remove(p.index);for(let g in p.attributes)e.remove(p.attributes[g]);p.removeEventListener("dispose",a),delete r[p.id],o.unregister(p);let x=s.get(p);x&&(e.remove(x),s.delete(p)),n.releaseStatesOfGeometry(p),p.isInstancedBufferGeometry===!0&&delete p._maxInstanceCount,t.memory.geometries--}function c(p,x){return r[x.id]!==void 0||(x.addEventListener("dispose",a),r[x.id]=new WeakRef(x),o.register(x,x.id,x),t.memory.geometries++),x}function u(p){let x=p.attributes;for(let g in x)e.update(x[g],i.ARRAY_BUFFER)}function h(p){let x=p.index,g=p.attributes.position,m=0;if(g===void 0)return;let b=x!==null?x.array.length:g.array.length/3-1,v=g.count>=65535?cs:xa,y=new v(Math.ceil(b/3)*6,1),M=y.array;if(x!==null){let _=x.array;m=x.version;for(let w=0,R=0;w<b;w+=3){let A=_[w+0],C=_[w+1],O=_[w+2];M[R++]=A,M[R++]=C,M[R++]=C,M[R++]=O,M[R++]=O,M[R++]=A}}else{m=g.version;for(let _=0,w=0;_<b;_+=3){let R=_+0,A=_+1,C=_+2;M[w++]=R,M[w++]=A,M[w++]=A,M[w++]=C,M[w++]=C,M[w++]=R}}y.version=m;let S=s.get(p);S&&e.remove(S),s.set(p,y)}function f(p){let x=s.get(p);if(x){let g=p.index;g!==null&&x.version<g.version&&h(p)}else h(p);return s.get(p)}function d(){for(let p in r){let x=r[p].deref();x!==void 0&&l(x)}}return{get:c,update:u,getWireframeAttribute:f,dispose:d}}function PT(i,e,t){let n;function r(h){n=h}let s,o;function a(h){s=h.type,o=h.bytesPerElement}function l(h,f){i.drawElements(n,f,s,h*o),t.update(f,n,1)}function c(h,f,d){d!==0&&(i.drawElementsInstanced(n,f,s,h*o,d),t.update(f,n,d))}function u(h,f,d){if(d===0)return;e.get("WEBGL_multi_draw").multiDrawElementsWEBGL(n,f,0,s,h,0,d);let x=0;for(let g=0;g<d;g++)x+=f[g];t.update(x,n,1)}this.setMode=r,this.setIndex=a,this.render=l,this.renderInstances=c,this.renderMultiDraw=u}function IT(i){let e={geometries:0,textures:0},t={frame:0,calls:0,triangles:0,points:0,lines:0};function n(s,o,a){switch(t.calls++,o){case i.TRIANGLES:t.triangles+=a*(s/3);break;case i.LINES:t.lines+=a*(s/2);break;case i.LINE_STRIP:t.lines+=a*(s-1);break;case i.LINE_LOOP:t.lines+=a*s;break;case i.POINTS:t.points+=a*s;break;default:Ge("WebGLInfo: Unknown draw mode:",o);break}}function r(){t.calls=0,t.triangles=0,t.points=0,t.lines=0}return{memory:e,render:t,programs:null,autoReset:!0,reset:r,update:n}}function LT(i,e,t){let n=new WeakMap,r=new _t;function s(o,a,l){let c=o.morphTargetInfluences,u=a.morphAttributes.position||a.morphAttributes.normal||a.morphAttributes.color,h=u!==void 0?u.length:0,f=n.get(a);if(f===void 0||f.count!==h){let R=function(){_.dispose(),n.delete(a),a.removeEventListener("dispose",R)};f!==void 0&&f.texture.dispose();let d=a.morphAttributes.position!==void 0,p=a.morphAttributes.normal!==void 0,x=a.morphAttributes.color!==void 0,g=a.morphAttributes.position||[],m=a.morphAttributes.normal||[],b=a.morphAttributes.color||[],v=0;d===!0&&(v=1),p===!0&&(v=2),x===!0&&(v=3);let y=a.attributes.position.count*v,M=1;y>e.maxTextureSize&&(M=Math.ceil(y/e.maxTextureSize),y=e.maxTextureSize);let S=new Float32Array(y*M*4*h),_=new ga(S,y,M,h);_.type=Vn,_.needsUpdate=!0;let w=v*4;for(let A=0;A<h;A++){let C=g[A],O=m[A],D=b[A],P=y*M*4*A;for(let I=0;I<C.count;I++){let N=I*w;d===!0&&(r.fromBufferAttribute(C,I),S[P+N+0]=r.x,S[P+N+1]=r.y,S[P+N+2]=r.z,S[P+N+3]=0),p===!0&&(r.fromBufferAttribute(O,I),S[P+N+4]=r.x,S[P+N+5]=r.y,S[P+N+6]=r.z,S[P+N+7]=0),x===!0&&(r.fromBufferAttribute(D,I),S[P+N+8]=r.x,S[P+N+9]=r.y,S[P+N+10]=r.z,S[P+N+11]=D.itemSize===4?r.w:1)}}f={count:h,texture:_,size:new De(y,M)},n.set(a,f),a.addEventListener("dispose",R)}if(o.isInstancedMesh===!0&&o.morphTexture!==null)l.getUniforms().setValue(i,"morphTexture",o.morphTexture,t);else{let d=0;for(let x=0;x<c.length;x++)d+=c[x];let p=a.morphTargetsRelative?1:1-d;l.getUniforms().setValue(i,"morphTargetBaseInfluence",p),l.getUniforms().setValue(i,"morphTargetInfluences",c)}l.getUniforms().setValue(i,"morphTargetsTexture",f.texture,t),l.getUniforms().setValue(i,"morphTargetsTextureSize",f.size)}return{update:s}}function FT(i,e,t,n,r){let s=new WeakMap;function o(c){let u=r.render.frame,h=c.geometry,f=e.get(c,h);if(s.get(f)!==u&&(e.update(f),s.set(f,u)),c.isInstancedMesh&&(c.hasEventListener("dispose",l)===!1&&c.addEventListener("dispose",l),s.get(c)!==u&&(t.update(c.instanceMatrix,i.ARRAY_BUFFER),c.instanceColor!==null&&t.update(c.instanceColor,i.ARRAY_BUFFER),s.set(c,u))),c.isSkinnedMesh){let d=c.skeleton;s.get(d)!==u&&(d.update(),s.set(d,u))}return f}function a(){s=new WeakMap}function l(c){let u=c.target;u.removeEventListener("dispose",l),n.releaseStatesOfObject(u),t.remove(u.instanceMatrix),u.instanceColor!==null&&t.remove(u.instanceColor)}return{update:o,dispose:a}}var OT={[Nf]:"LINEAR_TONE_MAPPING",[Df]:"REINHARD_TONE_MAPPING",[Uf]:"CINEON_TONE_MAPPING",[Bf]:"ACES_FILMIC_TONE_MAPPING",[zf]:"AGX_TONE_MAPPING",[Vf]:"NEUTRAL_TONE_MAPPING",[kf]:"CUSTOM_TONE_MAPPING"};function NT(i,e,t,n,r,s){let o=new wn(e,t,{type:i,depthBuffer:r,stencilBuffer:s,samples:n?4:0,storeMultisampledDepthBuffer:!1,storeMultisampledStencilBuffer:!1,resolveDepthBuffer:!1,resolveStencilBuffer:!1}),a=null,l=null,c=null,u=new Fe;u.setAttribute("position",new ke([-1,3,0,-1,-1,0,3,-1,0],3)),u.setAttribute("uv",new ke([0,2,0,0,2,0],2));let h=new Ec({uniforms:{tDiffuse:{value:null}},vertexShader:`
|
|
precision highp float;
|
|
|
|
uniform mat4 modelViewMatrix;
|
|
uniform mat4 projectionMatrix;
|
|
|
|
attribute vec3 position;
|
|
attribute vec2 uv;
|
|
|
|
varying vec2 vUv;
|
|
|
|
void main() {
|
|
vUv = uv;
|
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
}`,fragmentShader:`
|
|
precision highp float;
|
|
|
|
uniform sampler2D tDiffuse;
|
|
|
|
varying vec2 vUv;
|
|
|
|
#include <tonemapping_pars_fragment>
|
|
#include <colorspace_pars_fragment>
|
|
|
|
void main() {
|
|
gl_FragColor = texture2D( tDiffuse, vUv );
|
|
|
|
#ifdef LINEAR_TONE_MAPPING
|
|
gl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );
|
|
#elif defined( REINHARD_TONE_MAPPING )
|
|
gl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );
|
|
#elif defined( CINEON_TONE_MAPPING )
|
|
gl_FragColor.rgb = CineonToneMapping( gl_FragColor.rgb );
|
|
#elif defined( ACES_FILMIC_TONE_MAPPING )
|
|
gl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );
|
|
#elif defined( AGX_TONE_MAPPING )
|
|
gl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb );
|
|
#elif defined( NEUTRAL_TONE_MAPPING )
|
|
gl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb );
|
|
#elif defined( CUSTOM_TONE_MAPPING )
|
|
gl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb );
|
|
#endif
|
|
|
|
#ifdef SRGB_TRANSFER
|
|
gl_FragColor = sRGBTransferOETF( gl_FragColor );
|
|
#endif
|
|
}`,depthTest:!1,depthWrite:!1}),f=new we(u,h),d=new zn(-1,1,1,-1,0,1),p=null,x=null,g=!1,m,b=null,v=[],y=!1;this.setSize=function(M,S){o.setSize(M,S),a!==null&&a.setSize(M,S),l!==null&&l.setSize(M,S);for(let _=0;_<v.length;_++){let w=v[_];w.setSize&&w.setSize(M,S)}},this.setEffects=function(M){v=M,y=v.length>0&&v[0].isRenderPass===!0;let S=o.width,_=o.height;v.length>0&&a===null&&(a=new wn(S,_,{type:ai,depthBuffer:!1,stencilBuffer:!1}),l=new wn(S,_,{type:ai,depthBuffer:!1,stencilBuffer:!1}));let w=r===!0&&v.some(R=>R.needsDepthTexture===!0);w!==(o.depthTexture!==null)&&(w===!0&&c===null&&(c=new er(S,_),s===!0&&(c.format=lr,c.type=bs)),o.dispose(),o.depthTexture=w?c:null,o.resolveDepthBuffer=w,o.storeMultisampledDepthBuffer=w);for(let R=0;R<v.length;R++){let A=v[R];A.setSize&&A.setSize(S,_),w&&A.needsDepthTexture===!0&&A.setDepthTexture&&A.setDepthTexture(c)}},this.begin=function(M,S){if(g||M.toneMapping===Ei&&v.length===0)return!1;if(b=S,S!==null){let _=S.width,w=S.height;(o.width!==_||o.height!==w)&&this.setSize(_,w)}return y===!1&&M.setRenderTarget(o),m=M.toneMapping,M.toneMapping=Ei,!0},this.hasRenderPass=function(){return y},this.end=function(M,S){M.toneMapping=m,g=!0;let _=o,w=a;for(let R=0;R<v.length;R++){let A=v[R];A.enabled!==!1&&(A.render(M,w,_,S),A.needsSwap!==!1&&(_=w,w=w===a?l:a))}if(p!==M.outputColorSpace||x!==M.toneMapping){p=M.outputColorSpace,x=M.toneMapping,h.defines={},tt.getTransfer(p)===Mt&&(h.defines.SRGB_TRANSFER="");let R=OT[x];R&&(h.defines[R]=""),h.needsUpdate=!0}h.uniforms.tDiffuse.value=_.texture,M.setRenderTarget(b),M.render(f,d),b=null,g=!1},this.isCompositing=function(){return g},this.dispose=function(){o.dispose(),a!==null&&a.dispose(),l!==null&&l.dispose(),u.dispose(),h.dispose()}}var $x=new Kt,Kx=new er(1,1),Zx=new Ma(1),Jx=new ga,jx=new Sc,Qx=new va,Ex=[],Rx=[],Cx=new Float32Array(16),Px=new Float32Array(9),Ix=new Float32Array(4);function To(i,e,t){let n=i[0];if(n<=0||n>0)return i;let r=e*t,s=Ex[r];if(s===void 0&&(s=new Float32Array(r),Ex[r]=s),e!==0){n.toArray(s,0);for(let o=1,a=0;o!==e;++o)a+=t,i[o].toArray(s,a)}return s}function jt(i,e){if(i.length!==e.length)return!1;for(let t=0,n=i.length;t<n;t++)if(i[t]!==e[t])return!1;return!0}function Qt(i,e){for(let t=0,n=e.length;t<n;t++)i[t]=e[t]}function Ru(i,e){let t=Rx[e];t===void 0&&(t=new Int32Array(e),Rx[e]=t);for(let n=0;n!==e;++n)t[n]=i.allocateTextureUnit();return t}function DT(i,e){let t=this.cache;t[0]!==e&&(i.uniform1f(this.addr,e),t[0]=e)}function UT(i,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y)&&(i.uniform2f(this.addr,e.x,e.y),t[0]=e.x,t[1]=e.y);else{if(jt(t,e))return;i.uniform2fv(this.addr,e),Qt(t,e)}}function BT(i,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z)&&(i.uniform3f(this.addr,e.x,e.y,e.z),t[0]=e.x,t[1]=e.y,t[2]=e.z);else if(e.r!==void 0)(t[0]!==e.r||t[1]!==e.g||t[2]!==e.b)&&(i.uniform3f(this.addr,e.r,e.g,e.b),t[0]=e.r,t[1]=e.g,t[2]=e.b);else{if(jt(t,e))return;i.uniform3fv(this.addr,e),Qt(t,e)}}function kT(i,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z||t[3]!==e.w)&&(i.uniform4f(this.addr,e.x,e.y,e.z,e.w),t[0]=e.x,t[1]=e.y,t[2]=e.z,t[3]=e.w);else{if(jt(t,e))return;i.uniform4fv(this.addr,e),Qt(t,e)}}function zT(i,e){let t=this.cache,n=e.elements;if(n===void 0){if(jt(t,e))return;i.uniformMatrix2fv(this.addr,!1,e),Qt(t,e)}else{if(jt(t,n))return;Ix.set(n),i.uniformMatrix2fv(this.addr,!1,Ix),Qt(t,n)}}function VT(i,e){let t=this.cache,n=e.elements;if(n===void 0){if(jt(t,e))return;i.uniformMatrix3fv(this.addr,!1,e),Qt(t,e)}else{if(jt(t,n))return;Px.set(n),i.uniformMatrix3fv(this.addr,!1,Px),Qt(t,n)}}function GT(i,e){let t=this.cache,n=e.elements;if(n===void 0){if(jt(t,e))return;i.uniformMatrix4fv(this.addr,!1,e),Qt(t,e)}else{if(jt(t,n))return;Cx.set(n),i.uniformMatrix4fv(this.addr,!1,Cx),Qt(t,n)}}function HT(i,e){let t=this.cache;t[0]!==e&&(i.uniform1i(this.addr,e),t[0]=e)}function WT(i,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y)&&(i.uniform2i(this.addr,e.x,e.y),t[0]=e.x,t[1]=e.y);else{if(jt(t,e))return;i.uniform2iv(this.addr,e),Qt(t,e)}}function XT(i,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z)&&(i.uniform3i(this.addr,e.x,e.y,e.z),t[0]=e.x,t[1]=e.y,t[2]=e.z);else{if(jt(t,e))return;i.uniform3iv(this.addr,e),Qt(t,e)}}function YT(i,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z||t[3]!==e.w)&&(i.uniform4i(this.addr,e.x,e.y,e.z,e.w),t[0]=e.x,t[1]=e.y,t[2]=e.z,t[3]=e.w);else{if(jt(t,e))return;i.uniform4iv(this.addr,e),Qt(t,e)}}function qT(i,e){let t=this.cache;t[0]!==e&&(i.uniform1ui(this.addr,e),t[0]=e)}function $T(i,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y)&&(i.uniform2ui(this.addr,e.x,e.y),t[0]=e.x,t[1]=e.y);else{if(jt(t,e))return;i.uniform2uiv(this.addr,e),Qt(t,e)}}function KT(i,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z)&&(i.uniform3ui(this.addr,e.x,e.y,e.z),t[0]=e.x,t[1]=e.y,t[2]=e.z);else{if(jt(t,e))return;i.uniform3uiv(this.addr,e),Qt(t,e)}}function ZT(i,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z||t[3]!==e.w)&&(i.uniform4ui(this.addr,e.x,e.y,e.z,e.w),t[0]=e.x,t[1]=e.y,t[2]=e.z,t[3]=e.w);else{if(jt(t,e))return;i.uniform4uiv(this.addr,e),Qt(t,e)}}function Cu(i){return i.version===0&&(i.compareFunction=jf,i.needsUpdate=!0),i}function JT(i,e,t){let n=this.cache,r=t.allocateTextureUnit();n[0]!==r&&(i.uniform1i(this.addr,r),n[0]=r);let s;this.type===i.SAMPLER_2D_SHADOW?s=Cu(Kx):s=$x,t.setTexture2D(e||s,r)}function jT(i,e,t){let n=this.cache,r=t.allocateTextureUnit();n[0]!==r&&(i.uniform1i(this.addr,r),n[0]=r),t.setTexture3D(e||jx,r)}function QT(i,e,t){let n=this.cache,r=t.allocateTextureUnit();n[0]!==r&&(i.uniform1i(this.addr,r),n[0]=r);let s;this.type===i.SAMPLER_CUBE_SHADOW?s=Cu(Zx):s=Qx,t.setTextureCube(e||s,r)}function eA(i,e,t){let n=this.cache,r=t.allocateTextureUnit();n[0]!==r&&(i.uniform1i(this.addr,r),n[0]=r),t.setTexture2DArray(e||Jx,r)}function tA(i){switch(i){case 5126:return DT;case 35664:return UT;case 35665:return BT;case 35666:return kT;case 35674:return zT;case 35675:return VT;case 35676:return GT;case 5124:case 35670:return HT;case 35667:case 35671:return WT;case 35668:case 35672:return XT;case 35669:case 35673:return YT;case 5125:return qT;case 36294:return $T;case 36295:return KT;case 36296:return ZT;case 35678:case 36198:case 36298:case 36306:case 35682:return JT;case 35679:case 36299:case 36307:return jT;case 35680:case 36300:case 36308:case 36293:return QT;case 36289:case 36303:case 36311:case 36292:return eA}}function nA(i,e){i.uniform1fv(this.addr,e)}function iA(i,e){let t=To(e,this.size,2);i.uniform2fv(this.addr,t)}function rA(i,e){let t=To(e,this.size,3);i.uniform3fv(this.addr,t)}function sA(i,e){let t=To(e,this.size,4);i.uniform4fv(this.addr,t)}function oA(i,e){let t=To(e,this.size,4);i.uniformMatrix2fv(this.addr,!1,t)}function aA(i,e){let t=To(e,this.size,9);i.uniformMatrix3fv(this.addr,!1,t)}function lA(i,e){let t=To(e,this.size,16);i.uniformMatrix4fv(this.addr,!1,t)}function cA(i,e){i.uniform1iv(this.addr,e)}function uA(i,e){i.uniform2iv(this.addr,e)}function hA(i,e){i.uniform3iv(this.addr,e)}function fA(i,e){i.uniform4iv(this.addr,e)}function dA(i,e){i.uniform1uiv(this.addr,e)}function pA(i,e){i.uniform2uiv(this.addr,e)}function mA(i,e){i.uniform3uiv(this.addr,e)}function gA(i,e){i.uniform4uiv(this.addr,e)}function xA(i,e,t){let n=this.cache,r=e.length,s=Ru(t,r);jt(n,s)||(i.uniform1iv(this.addr,s),Qt(n,s));let o;this.type===i.SAMPLER_2D_SHADOW?o=Cu(Kx):o=$x;for(let a=0;a!==r;++a)t.setTexture2D(e[a]||o,s[a])}function bA(i,e,t){let n=this.cache,r=e.length,s=Ru(t,r);jt(n,s)||(i.uniform1iv(this.addr,s),Qt(n,s));for(let o=0;o!==r;++o)t.setTexture3D(e[o]||jx,s[o])}function yA(i,e,t){let n=this.cache,r=e.length,s=Ru(t,r);jt(n,s)||(i.uniform1iv(this.addr,s),Qt(n,s));let o;this.type===i.SAMPLER_CUBE_SHADOW?o=Cu(Zx):o=Qx;for(let a=0;a!==r;++a)t.setTextureCube(e[a]||o,s[a])}function _A(i,e,t){let n=this.cache,r=e.length,s=Ru(t,r);jt(n,s)||(i.uniform1iv(this.addr,s),Qt(n,s));for(let o=0;o!==r;++o)t.setTexture2DArray(e[o]||Jx,s[o])}function vA(i){switch(i){case 5126:return nA;case 35664:return iA;case 35665:return rA;case 35666:return sA;case 35674:return oA;case 35675:return aA;case 35676:return lA;case 5124:case 35670:return cA;case 35667:case 35671:return uA;case 35668:case 35672:return hA;case 35669:case 35673:return fA;case 5125:return dA;case 36294:return pA;case 36295:return mA;case 36296:return gA;case 35678:case 36198:case 36298:case 36306:case 35682:return xA;case 35679:case 36299:case 36307:return bA;case 35680:case 36300:case 36308:case 36293:return yA;case 36289:case 36303:case 36311:case 36292:return _A}}var xd=class{constructor(e,t,n){this.id=e,this.addr=n,this.cache=[],this.type=t.type,this.setValue=tA(t.type)}},bd=class{constructor(e,t,n){this.id=e,this.addr=n,this.cache=[],this.type=t.type,this.size=t.size,this.setValue=vA(t.type)}},yd=class{constructor(e){this.id=e,this.seq=[],this.map={}}setValue(e,t,n){let r=this.seq;for(let s=0,o=r.length;s!==o;++s){let a=r[s];a.setValue(e,t[a.id],n)}}},md=/(\w+)(\])?(\[|\.)?/g;function Lx(i,e){i.seq.push(e),i.map[e.id]=e}function MA(i,e,t){let n=i.name,r=n.length;for(md.lastIndex=0;;){let s=md.exec(n),o=md.lastIndex,a=s[1],l=s[2]==="]",c=s[3];if(l&&(a=a|0),c===void 0||c==="["&&o+2===r){Lx(t,c===void 0?new xd(a,i,e):new bd(a,i,e));break}else{let h=t.map[a];h===void 0&&(h=new yd(a),Lx(t,h)),t=h}}}var So=class{constructor(e,t){this.seq=[],this.map={};let n=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let o=0;o<n;++o){let a=e.getActiveUniform(t,o),l=e.getUniformLocation(t,a.name);MA(a,l,this)}let r=[],s=[];for(let o of this.seq)o.type===e.SAMPLER_2D_SHADOW||o.type===e.SAMPLER_CUBE_SHADOW||o.type===e.SAMPLER_2D_ARRAY_SHADOW?r.push(o):s.push(o);r.length>0&&(this.seq=r.concat(s))}setValue(e,t,n,r){let s=this.map[t];s!==void 0&&s.setValue(e,n,r)}setOptional(e,t,n){let r=t[n];r!==void 0&&this.setValue(e,n,r)}static upload(e,t,n,r){for(let s=0,o=t.length;s!==o;++s){let a=t[s],l=n[a.id];l.needsUpdate!==!1&&a.setValue(e,l.value,r)}}static seqWithValue(e,t){let n=[];for(let r=0,s=e.length;r!==s;++r){let o=e[r];o.id in t&&n.push(o)}return n}};function Fx(i,e,t){let n=i.createShader(e);return i.shaderSource(n,t),i.compileShader(n),n}var SA=37297,wA=0;function TA(i,e){let t=i.split(`
|
|
`),n=[],r=Math.max(e-6,0),s=Math.min(e+6,t.length);for(let o=r;o<s;o++){let a=o+1;n.push(`${a===e?">":" "} ${a}: ${t[o]}`)}return n.join(`
|
|
`)}var Ox=new He;function AA(i){tt._getMatrix(Ox,tt.workingColorSpace,i);let e=`mat3( ${Ox.elements.map(t=>t.toFixed(4))} )`;switch(tt.getTransfer(i)){case pa:return[e,"LinearTransferOETF"];case Mt:return[e,"sRGBTransferOETF"];default:return Le("WebGLProgram: Unsupported color space: ",i),[e,"LinearTransferOETF"]}}function Nx(i,e,t){let n=i.getShaderParameter(e,i.COMPILE_STATUS),s=(i.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+`
|
|
|
|
`+TA(i.getShaderSource(e),a)}else return s}function EA(i,e){let t=AA(e);return[`vec4 ${i}( vec4 value ) {`,` return ${t[1]}( vec4( ${t[0]} * value.rgb, value.a ) );`,"}"].join(`
|
|
`)}var RA={[Nf]:"Linear",[Df]:"Reinhard",[Uf]:"Cineon",[Bf]:"ACESFilmic",[zf]:"AgX",[Vf]:"Neutral",[kf]:"Custom"};function CA(i,e){let t=RA[e];return t===void 0?(Le("WebGLProgram: Unsupported toneMapping:",e),"vec3 "+i+"( vec3 color ) { return LinearToneMapping( color ); }"):"vec3 "+i+"( vec3 color ) { return "+t+"ToneMapping( color ); }"}var Eu=new U;function PA(){tt.getLuminanceCoefficients(Eu);let i=Eu.x.toFixed(4),e=Eu.y.toFixed(4),t=Eu.z.toFixed(4);return["float luminance( const in vec3 rgb ) {",` const vec3 weights = vec3( ${i}, ${e}, ${t} );`," return dot( weights, rgb );","}"].join(`
|
|
`)}function IA(i){return[i.extensionClipCullDistance?"#extension GL_ANGLE_clip_cull_distance : require":"",i.extensionMultiDraw?"#extension GL_ANGLE_multi_draw : require":""].filter(Za).join(`
|
|
`)}function LA(i){let e=[];for(let t in i){let n=i[t];n!==!1&&e.push("#define "+t+" "+n)}return e.join(`
|
|
`)}function FA(i,e){let t={},n=i.getProgramParameter(e,i.ACTIVE_ATTRIBUTES);for(let r=0;r<n;r++){let s=i.getActiveAttrib(e,r),o=s.name,a=1;s.type===i.FLOAT_MAT2&&(a=2),s.type===i.FLOAT_MAT3&&(a=3),s.type===i.FLOAT_MAT4&&(a=4),t[o]={type:s.type,location:i.getAttribLocation(e,o),locationSize:a}}return t}function Za(i){return i!==""}function Dx(i,e){let t=e.numSpotLightShadows+e.numSpotLightMaps-e.numSpotLightShadowsWithMaps;return i.replace(/NUM_SUN_LIGHTS/g,e.numSunLights).replace(/NUM_DIR_LIGHTS/g,e.numDirLights).replace(/NUM_SPOT_LIGHTS/g,e.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g,e.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g,t).replace(/NUM_RECT_AREA_LIGHTS/g,e.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,e.numPointLights).replace(/NUM_HEMI_LIGHTS/g,e.numHemiLights).replace(/NUM_SUN_LIGHT_SHADOWS/g,e.numSunLightShadows).replace(/NUM_DIR_LIGHT_SHADOWS/g,e.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g,e.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g,e.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,e.numPointLightShadows).replace(/NUM_LIGHT_PROBE_GRIDS/g,e.numLightProbeGrids)}function Ux(i,e){return i.replace(/NUM_CLIPPING_PLANES/g,e.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,e.numClippingPlanes-e.numClipIntersection)}var OA=/^[ \t]*#include +<([\w\d./]+)>/gm;function _d(i){return i.replace(OA,NA)}function NA(i,e){let t=Qe[e];if(t===void 0)throw new Error("THREE.WebGLProgram: Can not resolve #include <"+e+">");return _d(t)}var DA=/#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 Bx(i){return i.replace(DA,UA)}function UA(i,e,t,n){let r="";for(let s=parseInt(e);s<parseInt(t);s++)r+=n.replace(/\[\s*i\s*\]/g,"[ "+s+" ]").replace(/UNROLLED_LOOP_INDEX/g,s);return r}function kx(i){let e=`precision ${i.precision} float;
|
|
precision ${i.precision} int;
|
|
precision ${i.precision} sampler2D;
|
|
precision ${i.precision} samplerCube;
|
|
precision ${i.precision} sampler3D;
|
|
precision ${i.precision} sampler2DArray;
|
|
precision ${i.precision} sampler2DShadow;
|
|
precision ${i.precision} samplerCubeShadow;
|
|
precision ${i.precision} sampler2DArrayShadow;
|
|
precision ${i.precision} isampler2D;
|
|
precision ${i.precision} isampler3D;
|
|
precision ${i.precision} isamplerCube;
|
|
precision ${i.precision} isampler2DArray;
|
|
precision ${i.precision} usampler2D;
|
|
precision ${i.precision} usampler3D;
|
|
precision ${i.precision} usamplerCube;
|
|
precision ${i.precision} usampler2DArray;
|
|
`;return i.precision==="highp"?e+=`
|
|
#define HIGH_PRECISION`:i.precision==="mediump"?e+=`
|
|
#define MEDIUM_PRECISION`:i.precision==="lowp"&&(e+=`
|
|
#define LOW_PRECISION`),e}var BA={[ka]:"SHADOWMAP_TYPE_PCF",[bo]:"SHADOWMAP_TYPE_VSM"};function kA(i){return BA[i.shadowMapType]||"SHADOWMAP_TYPE_BASIC"}var zA={[yo]:"ENVMAP_MODE_REFRACTION"};function VA(i){return i.envMap===!1?"ENVMAP_MODE_REFLECTION":zA[i.envMapMode]||"ENVMAP_MODE_REFLECTION"}var GA={[kc]:"ENVMAP_BLENDING_MULTIPLY",[jg]:"ENVMAP_BLENDING_MIX",[Qg]:"ENVMAP_BLENDING_ADD"};function HA(i){return i.envMap===!1?"ENVMAP_BLENDING_NONE":GA[i.combine]||"ENVMAP_BLENDING_NONE"}function WA(i,e,t,n){let r=i.getContext(),s=t.defines,o=t.vertexShader,a=t.fragmentShader,l=kA(t),c=t.envMapPMREM===!0?"ENVMAP_TYPE_PMREM":"ENVMAP_TYPE_CUBE",u=VA(t),h=HA(t),f=IA(t),d=LA(s),p=r.createProgram(),x,g,m=t.glslVersion?"#version "+t.glslVersion+`
|
|
`:"";t.isRawShaderMaterial?(x=["#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,d].filter(Za).join(`
|
|
`),x.length>0&&(x+=`
|
|
`),g=["#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,d].filter(Za).join(`
|
|
`),g.length>0&&(g+=`
|
|
`)):(x=[kx(t),"#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,d,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 "+u:"",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.diffuseRoughnessMap?"#define USE_DIFFUSE_ROUGHNESSMAP":"",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.diffuseRoughnessMapUv?"#define DIFFUSE_ROUGHNESSMAP_UV "+t.diffuseRoughnessMapUv:"",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.vertexNormals?"#define HAS_NORMAL":"",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(Za).join(`
|
|
`),g=[kx(t),"#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,d,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 "+u:"",t.envMap?"#define "+h:"",t.envMapPMREM?"#define ENVMAP_MAX_LOD "+t.envMapMaxLod+".0":"",t.envMapPMREM?"#define ENVMAP_SIZE "+t.envMapSize+".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.packedNormalMap?"#define USE_PACKED_NORMALMAP":"",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.diffuseRoughness?"#define USE_DIFFUSE_ROUGHNESS":"",t.diffuseRoughnessMap?"#define USE_DIFFUSE_ROUGHNESSMAP":"",t.dispersion?"#define USE_DISPERSION":"",t.retroreflection?"#define USE_RETROREFLECTION":"",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?"#define USE_COLOR":"",t.vertexAlphas||t.batchingColor?"#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!==Ei?"#define TONE_MAPPING":"",t.toneMapping!==Ei?Qe.tonemapping_pars_fragment:"",t.toneMapping!==Ei?CA("toneMapping",t.toneMapping):"",t.dithering?"#define DITHERING":"",t.opaque?"#define OPAQUE":"",Qe.colorspace_pars_fragment,EA("linearToOutputTexel",t.outputColorSpace),PA(),t.useDepthPacking?"#define DEPTH_PACKING "+t.depthPacking:"",`
|
|
`].filter(Za).join(`
|
|
`)),o=_d(o),o=Dx(o,t),o=Ux(o,t),a=_d(a),a=Dx(a,t),a=Ux(a,t),o=Bx(o),a=Bx(a),t.isRawShaderMaterial!==!0&&(m=`#version 300 es
|
|
`,x=[f,"#define attribute in","#define varying out","#define texture2D texture"].join(`
|
|
`)+`
|
|
`+x,g=["#define varying in",t.glslVersion===td?"":"layout(location = 0) out highp vec4 pc_fragColor;",t.glslVersion===td?"":"#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(`
|
|
`)+`
|
|
`+g);let b=m+x+o,v=m+g+a,y=Fx(r,r.VERTEX_SHADER,b),M=Fx(r,r.FRAGMENT_SHADER,v);r.attachShader(p,y),r.attachShader(p,M),t.index0AttributeName!==void 0?r.bindAttribLocation(p,0,t.index0AttributeName):t.hasPositionAttribute===!0&&r.bindAttribLocation(p,0,"position"),r.linkProgram(p);function S(A){if(i.debug.checkShaderErrors){let C=r.getProgramInfoLog(p)||"",O=r.getShaderInfoLog(y)||"",D=r.getShaderInfoLog(M)||"",P=C.trim(),I=O.trim(),N=D.trim(),F=!0,H=!0;if(r.getProgramParameter(p,r.LINK_STATUS)===!1)if(F=!1,typeof i.debug.onShaderError=="function")i.debug.onShaderError(r,p,y,M);else{let B=Nx(r,y,"vertex"),X=Nx(r,M,"fragment");Ge("WebGLProgram: Shader Error "+r.getError()+" - VALIDATE_STATUS "+r.getProgramParameter(p,r.VALIDATE_STATUS)+`
|
|
|
|
Material Name: `+A.name+`
|
|
Material Type: `+A.type+`
|
|
|
|
Program Info Log: `+P+`
|
|
`+B+`
|
|
`+X)}else P!==""?Le("WebGLProgram: Program Info Log:",P):(I===""||N==="")&&(H=!1);H&&(A.diagnostics={runnable:F,programLog:P,vertexShader:{log:I,prefix:x},fragmentShader:{log:N,prefix:g}})}r.deleteShader(y),r.deleteShader(M),_=new So(r,p),w=FA(r,p)}let _;this.getUniforms=function(){return _===void 0&&S(this),_};let w;this.getAttributes=function(){return w===void 0&&S(this),w};let R=t.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return R===!1&&(R=r.getProgramParameter(p,SA)),R},this.destroy=function(){n.releaseStatesOfProgram(this),r.deleteProgram(p),this.program=void 0},this.type=t.shaderType,this.name=t.shaderName,this.id=wA++,this.cacheKey=e,this.usedTimes=1,this.program=p,this.vertexShader=y,this.fragmentShader=M,this}var XA=0,vd=class{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(e,t,n){let r=this._getShaderCacheForMaterial(e);return r.has(t)===!1&&(r.add(t),t.usedTimes++),r.has(n)===!1&&(r.add(n),n.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}getVertexShaderStage(e){return this._getShaderStage(e.vertexShader)}getFragmentShaderStage(e){return this._getShaderStage(e.fragmentShader)}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 Md(e),t.set(e,n)),n}},Md=class{constructor(e){this.id=XA++,this.code=e,this.usedTimes=0}};function YA(i){return i===Ur||i===Xa||i===Ya}function qA(i,e,t,n,r,s){let o=new co,a=new vd,l=new Set,c=[],u=new Map,h=n.logarithmicDepthBuffer,f={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distance",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 d(_){return l.add(_),_===0?"uv":`uv${_}`}function p(_,w,R,A,C,O){let D=A.fog,P=C.geometry,I=_.isMeshStandardMaterial||_.isMeshLambertMaterial||_.isMeshPhongMaterial?A.environment:null,N=_.isMeshStandardMaterial||_.isMeshLambertMaterial&&!_.envMap||_.isMeshPhongMaterial&&!_.envMap,F=e.get(_.envMap||I,N),H=f[_.type],B=n.precision;_.precision!==null&&(B=n.getMaxPrecision(_.precision),B!==_.precision&&Le("WebGLProgram.getParameters:",_.precision,"not supported, using",B,"instead."));let X=P.morphAttributes.position||P.morphAttributes.normal||P.morphAttributes.color,V=X!==void 0?X.length:0,re=0;P.morphAttributes.position!==void 0&&(re=1),P.morphAttributes.normal!==void 0&&(re=2),P.morphAttributes.color!==void 0&&(re=3);let be,Y,Q,se;if(H){let _e=Pi[H];be=_e.vertexShader,Y=_e.fragmentShader}else{be=_.vertexShader,Y=_.fragmentShader;let _e=a.getVertexShaderStage(_),St=a.getFragmentShaderStage(_);a.update(_,_e,St),Q=_e.id,se=St.id}let Se=i.getRenderTarget(),le=i.state.buffers.depth.getReversed(),Ie=C.isInstancedMesh===!0,st=C.isBatchedMesh===!0,Te=!!_.map,ht=!!_.matcap,bt=!!F,et=bt&&F.isPMREMTexture===!0,Yt=!!_.aoMap,kt=!!_.lightMap,on=!!_.bumpMap&&_.wireframe===!1,Ot=!!_.normalMap,gi=!!_.displacementMap,en=!!_.emissiveMap,Hn=!!_.metalnessMap,Wn=!!_.roughnessMap,Xn=_.anisotropy>0,G=_.clearcoat>0,Yn=_.diffuseRoughness>0,Pt=_.dispersion>0,It=_.retroreflectivity>0,ye=_.iridescence>0,Zt=_.sheen>0,ze=_.transmission>0,We=Xn&&!!_.anisotropyMap,L=G&&!!_.clearcoatMap,T=G&&!!_.clearcoatNormalMap,$=G&&!!_.clearcoatRoughnessMap,oe=Yn&&!!_.diffuseRoughnessMap,ie=ye&&!!_.iridescenceMap,ue=ye&&!!_.iridescenceThicknessMap,ge=Zt&&!!_.sheenColorMap,ee=Zt&&!!_.sheenRoughnessMap,te=!!_.specularMap,fe=!!_.specularColorMap,k=!!_.specularIntensityMap,ne=ze&&!!_.transmissionMap,j=ze&&!!_.thicknessMap,de=!!_.gradientMap,ce=!!_.alphaMap,he=_.alphaTest>0,Oe=!!_.alphaHash,je=!!_.extensions,ae=Ei;_.toneMapped&&(Se===null||Se.isXRRenderTarget===!0)&&(ae=i.toneMapping);let Ne=et?F.isCompressedCubeTexture?F.image[0].mipmaps:F.mipmaps:null,Ze={shaderID:H,shaderType:_.type,shaderName:_.name,vertexShader:be,fragmentShader:Y,defines:_.defines,customVertexShaderID:Q,customFragmentShaderID:se,isRawShaderMaterial:_.isRawShaderMaterial===!0,glslVersion:_.glslVersion,precision:B,batching:st,batchingColor:st&&C._colorsTexture!==null,instancing:Ie,instancingColor:Ie&&C.instanceColor!==null,instancingMorph:Ie&&C.morphTexture!==null,outputColorSpace:Se===null?i.outputColorSpace:Se.isXRRenderTarget===!0?Se.texture.colorSpace:tt.workingColorSpace,alphaToCoverage:!!_.alphaToCoverage,map:Te,matcap:ht,envMap:bt,envMapMode:bt&&F.mapping,envMapPMREM:et,envMapMaxLod:et?Ne.length-1:null,envMapSize:et?Ne[0].width:null,aoMap:Yt,lightMap:kt,bumpMap:on,normalMap:Ot,displacementMap:gi,emissiveMap:en,normalMapObjectSpace:Ot&&_.normalMapType===ix,normalMapTangentSpace:Ot&&_.normalMapType===$a,packedNormalMap:Ot&&_.normalMapType===$a&&YA(_.normalMap.format),metalnessMap:Hn,roughnessMap:Wn,anisotropy:Xn,anisotropyMap:We,clearcoat:G,clearcoatMap:L,clearcoatNormalMap:T,clearcoatRoughnessMap:$,diffuseRoughness:Yn,diffuseRoughnessMap:oe,dispersion:Pt,retroreflection:It,iridescence:ye,iridescenceMap:ie,iridescenceThicknessMap:ue,sheen:Zt,sheenColorMap:ge,sheenRoughnessMap:ee,specularMap:te,specularColorMap:fe,specularIntensityMap:k,transmission:ze,transmissionMap:ne,thicknessMap:j,gradientMap:de,opaque:_.transparent===!1&&_.blending===Ai&&_.alphaToCoverage===!1,alphaMap:ce,alphaTest:he,alphaHash:Oe,combine:_.combine,mapUv:Te&&d(_.map.channel),aoMapUv:Yt&&d(_.aoMap.channel),lightMapUv:kt&&d(_.lightMap.channel),bumpMapUv:on&&d(_.bumpMap.channel),normalMapUv:Ot&&d(_.normalMap.channel),displacementMapUv:gi&&d(_.displacementMap.channel),emissiveMapUv:en&&d(_.emissiveMap.channel),metalnessMapUv:Hn&&d(_.metalnessMap.channel),roughnessMapUv:Wn&&d(_.roughnessMap.channel),anisotropyMapUv:We&&d(_.anisotropyMap.channel),clearcoatMapUv:L&&d(_.clearcoatMap.channel),clearcoatNormalMapUv:T&&d(_.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:$&&d(_.clearcoatRoughnessMap.channel),diffuseRoughnessMapUv:oe&&d(_.diffuseRoughnessMap.channel),iridescenceMapUv:ie&&d(_.iridescenceMap.channel),iridescenceThicknessMapUv:ue&&d(_.iridescenceThicknessMap.channel),sheenColorMapUv:ge&&d(_.sheenColorMap.channel),sheenRoughnessMapUv:ee&&d(_.sheenRoughnessMap.channel),specularMapUv:te&&d(_.specularMap.channel),specularColorMapUv:fe&&d(_.specularColorMap.channel),specularIntensityMapUv:k&&d(_.specularIntensityMap.channel),transmissionMapUv:ne&&d(_.transmissionMap.channel),thicknessMapUv:j&&d(_.thicknessMap.channel),alphaMapUv:ce&&d(_.alphaMap.channel),vertexTangents:!!P.attributes.tangent&&(Ot||Xn),vertexNormals:!!P.attributes.normal,vertexColors:_.vertexColors,vertexAlphas:_.vertexColors===!0&&!!P.attributes.color&&P.attributes.color.itemSize===4,pointsUvs:C.isPoints===!0&&!!P.attributes.uv&&(Te||ce),fog:!!D,useFog:_.fog===!0,fogExp2:!!D&&D.isFogExp2,flatShading:_.wireframe===!1&&(_.flatShading===!0||P.attributes.normal===void 0&&Ot===!1&&(_.isMeshLambertMaterial||_.isMeshPhongMaterial||_.isMeshStandardMaterial||_.isMeshPhysicalMaterial)),sizeAttenuation:_.sizeAttenuation===!0,logarithmicDepthBuffer:h,reversedDepthBuffer:le,skinning:C.isSkinnedMesh===!0,hasPositionAttribute:P.attributes.position!==void 0,morphTargets:P.morphAttributes.position!==void 0,morphNormals:P.morphAttributes.normal!==void 0,morphColors:P.morphAttributes.color!==void 0,morphTargetsCount:V,morphTextureStride:re,numSunLights:w.sun.length,numDirLights:w.directional.length,numPointLights:w.point.length,numSpotLights:w.spot.length,numSpotLightMaps:w.spotLightMap.length,numRectAreaLights:w.rectArea.length,numHemiLights:w.hemi.length,numSunLightShadows:w.sunShadowMap.length,numDirLightShadows:w.directionalShadowMap.length,numPointLightShadows:w.pointShadowMap.length,numSpotLightShadows:w.spotShadowMap.length,numSpotLightShadowsWithMaps:w.numSpotLightShadowsWithMaps,numLightProbes:w.numLightProbes,numLightProbeGrids:O.filter(_e=>_e.texture!==null).length,numClippingPlanes:s.numPlanes,numClipIntersection:s.numIntersection,dithering:_.dithering,shadowMapEnabled:i.shadowMap.enabled&&R.length>0,shadowMapType:i.shadowMap.type,toneMapping:ae,decodeVideoTexture:Te&&_.map.isVideoTexture===!0&&tt.getTransfer(_.map.colorSpace)===Mt,decodeVideoTextureEmissive:en&&_.emissiveMap.isVideoTexture===!0&&tt.getTransfer(_.emissiveMap.colorSpace)===Mt,premultipliedAlpha:_.premultipliedAlpha,doubleSided:_.side===ut,flipSided:_.side===un,useDepthPacking:_.depthPacking>=0,depthPacking:_.depthPacking||0,index0AttributeName:_.index0AttributeName,extensionClipCullDistance:je&&_.extensions.clipCullDistance===!0&&t.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(je&&_.extensions.multiDraw===!0||st)&&t.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:t.has("KHR_parallel_shader_compile"),customProgramCacheKey:_.customProgramCacheKey()};return Ze.vertexUv1s=l.has(1),Ze.vertexUv2s=l.has(2),Ze.vertexUv3s=l.has(3),l.clear(),Ze}function x(_){let w=[];if(_.shaderID?w.push(_.shaderID):(w.push(_.customVertexShaderID),w.push(_.customFragmentShaderID)),_.defines!==void 0)for(let R in _.defines)w.push(R),w.push(_.defines[R]);return _.isRawShaderMaterial===!1&&(g(w,_),m(w,_),w.push(i.outputColorSpace)),w.push(_.customProgramCacheKey),w.join()}function g(_,w){_.push(w.precision),_.push(w.outputColorSpace),_.push(w.envMapMode),_.push(w.envMapPMREM),_.push(w.envMapMaxLod),_.push(w.envMapSize),_.push(w.mapUv),_.push(w.alphaMapUv),_.push(w.lightMapUv),_.push(w.aoMapUv),_.push(w.bumpMapUv),_.push(w.normalMapUv),_.push(w.displacementMapUv),_.push(w.emissiveMapUv),_.push(w.metalnessMapUv),_.push(w.roughnessMapUv),_.push(w.anisotropyMapUv),_.push(w.clearcoatMapUv),_.push(w.clearcoatNormalMapUv),_.push(w.clearcoatRoughnessMapUv),_.push(w.diffuseRoughnessMapUv),_.push(w.iridescenceMapUv),_.push(w.iridescenceThicknessMapUv),_.push(w.sheenColorMapUv),_.push(w.sheenRoughnessMapUv),_.push(w.specularMapUv),_.push(w.specularColorMapUv),_.push(w.specularIntensityMapUv),_.push(w.transmissionMapUv),_.push(w.thicknessMapUv),_.push(w.combine),_.push(w.fogExp2),_.push(w.sizeAttenuation),_.push(w.morphTargetsCount),_.push(w.numSunLights),_.push(w.numDirLights),_.push(w.numPointLights),_.push(w.numSpotLights),_.push(w.numSpotLightMaps),_.push(w.numHemiLights),_.push(w.numRectAreaLights),_.push(w.numSunLightShadows),_.push(w.numDirLightShadows),_.push(w.numPointLightShadows),_.push(w.numSpotLightShadows),_.push(w.numSpotLightShadowsWithMaps),_.push(w.numLightProbes),_.push(w.numLightProbeGrids),_.push(w.shadowMapType),_.push(w.toneMapping),_.push(w.numClippingPlanes),_.push(w.numClipIntersection),_.push(w.depthPacking)}function m(_,w){o.disableAll(),w.instancing&&o.enable(0),w.instancingColor&&o.enable(1),w.instancingMorph&&o.enable(2),w.matcap&&o.enable(3),w.envMap&&o.enable(4),w.normalMapObjectSpace&&o.enable(5),w.normalMapTangentSpace&&o.enable(6),w.clearcoat&&o.enable(7),w.iridescence&&o.enable(8),w.alphaTest&&o.enable(9),w.vertexColors&&o.enable(10),w.vertexAlphas&&o.enable(11),w.vertexUv1s&&o.enable(12),w.vertexUv2s&&o.enable(13),w.vertexUv3s&&o.enable(14),w.vertexTangents&&o.enable(15),w.anisotropy&&o.enable(16),w.alphaHash&&o.enable(17),w.batching&&o.enable(18),w.dispersion&&o.enable(19),w.retroreflection&&o.enable(24),w.diffuseRoughness&&o.enable(25),w.batchingColor&&o.enable(20),w.gradientMap&&o.enable(21),w.packedNormalMap&&o.enable(22),w.vertexNormals&&o.enable(23),_.push(o.mask),o.disableAll(),w.fog&&o.enable(0),w.useFog&&o.enable(1),w.flatShading&&o.enable(2),w.logarithmicDepthBuffer&&o.enable(3),w.reversedDepthBuffer&&o.enable(4),w.skinning&&o.enable(5),w.morphTargets&&o.enable(6),w.morphNormals&&o.enable(7),w.morphColors&&o.enable(8),w.premultipliedAlpha&&o.enable(9),w.shadowMapEnabled&&o.enable(10),w.doubleSided&&o.enable(11),w.flipSided&&o.enable(12),w.useDepthPacking&&o.enable(13),w.dithering&&o.enable(14),w.transmission&&o.enable(15),w.sheen&&o.enable(16),w.opaque&&o.enable(17),w.pointsUvs&&o.enable(18),w.decodeVideoTexture&&o.enable(19),w.decodeVideoTextureEmissive&&o.enable(20),w.alphaToCoverage&&o.enable(21),w.numLightProbeGrids>0&&o.enable(22),w.hasPositionAttribute&&o.enable(23),_.push(o.mask)}function b(_){let w=f[_.type],R;if(w){let A=Pi[w];R=_x.clone(A.uniforms)}else R=_.uniforms;return R}function v(_,w){let R=u.get(w);return R!==void 0?++R.usedTimes:(R=new WA(i,w,_,r),c.push(R),u.set(w,R)),R}function y(_){if(--_.usedTimes===0){let w=c.indexOf(_);c[w]=c[c.length-1],c.pop(),u.delete(_.cacheKey),_.destroy()}}function M(_){a.remove(_)}function S(){a.dispose()}return{getParameters:p,getProgramCacheKey:x,getUniforms:b,acquireProgram:v,releaseProgram:y,releaseShaderCache:M,programs:c,dispose:S}}function $A(){let i=new WeakMap;function e(o){return i.has(o)}function t(o){let a=i.get(o);return a===void 0&&(a={},i.set(o,a)),a}function n(o){i.delete(o)}function r(o,a,l){i.get(o)[a]=l}function s(){i=new WeakMap}return{has:e,get:t,remove:n,update:r,dispose:s}}function KA(i,e){return i.groupOrder!==e.groupOrder?i.groupOrder-e.groupOrder:i.renderOrder!==e.renderOrder?i.renderOrder-e.renderOrder:i.material.id!==e.material.id?i.material.id-e.material.id:i.materialVariant!==e.materialVariant?i.materialVariant-e.materialVariant:i.z!==e.z?i.z-e.z:i.id-e.id}function zx(i,e){return i.groupOrder!==e.groupOrder?i.groupOrder-e.groupOrder:i.renderOrder!==e.renderOrder?i.renderOrder-e.renderOrder:i.z!==e.z?e.z-i.z:i.id-e.id}function Vx(){let i=[],e=0,t=[],n=[],r=[];function s(){e=0,t.length=0,n.length=0,r.length=0}function o(f){let d=0;return f.isInstancedMesh&&(d+=2),f.isSkinnedMesh&&(d+=1),d}function a(f,d,p,x,g,m){let b=i[e];return b===void 0?(b={id:f.id,object:f,geometry:d,material:p,materialVariant:o(f),groupOrder:x,renderOrder:f.renderOrder,z:g,group:m},i[e]=b):(b.id=f.id,b.object=f,b.geometry=d,b.material=p,b.materialVariant=o(f),b.groupOrder=x,b.renderOrder=f.renderOrder,b.z=g,b.group=m),e++,b}function l(f,d,p,x,g,m,b){b.reversedDepth===!0&&(g=-g);let v=a(f,d,p,x,g,m);p.transmission>0?n.push(v):p.transparent===!0?r.push(v):t.push(v)}function c(f,d,p,x,g,m){let b=a(f,d,p,x,g,m);p.transmission>0?n.unshift(b):p.transparent===!0?r.unshift(b):t.unshift(b)}function u(f,d){t.length>1&&t.sort(f||KA),n.length>1&&n.sort(d||zx),r.length>1&&r.sort(d||zx)}function h(){for(let f=e,d=i.length;f<d;f++){let p=i[f];if(p.id===null)break;p.id=null,p.object=null,p.geometry=null,p.material=null,p.group=null}}return{opaque:t,transmissive:n,transparent:r,init:s,push:l,unshift:c,finish:h,sort:u}}function ZA(){let i=new WeakMap;function e(n,r){let s=i.get(n),o;return s===void 0?(o=new Vx,i.set(n,[o])):r>=s.length?(o=new Vx,s.push(o)):o=s[r],o}function t(){i=new WeakMap}return{get:e,dispose:t}}function JA(){let i={};return{get:function(e){if(i[e.id]!==void 0)return i[e.id];let t;switch(e.type){case"SunLight":case"DirectionalLight":t={direction:new U,color:new W};break;case"SpotLight":t={position:new U,direction:new U,color:new W,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":t={position:new U,color:new W,distance:0,decay:0};break;case"HemisphereLight":t={direction:new U,skyColor:new W,groundColor:new W};break;case"RectAreaLight":t={color:new W,position:new U,halfWidth:new U,halfHeight:new U};break}return i[e.id]=t,t}}}function jA(){let i={};return{get:function(e){if(i[e.id]!==void 0)return i[e.id];let t;switch(e.type){case"SunLight":case"DirectionalLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new De};break;case"SpotLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new De};break;case"PointLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new De,shadowCameraNear:1,shadowCameraFar:1e3};break}return i[e.id]=t,t}}}var QA=0;function eE(i,e){return(e.castShadow?2:0)-(i.castShadow?2:0)+(e.map?1:0)-(i.map?1:0)}function tE(i){let e=new JA,t=jA(),n={version:0,hash:{sunLength:-1,directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numSunShadows:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],sun:[],sunShadow:[],sunShadowMap:[],sunShadowMatrix:[],sunShadowCascade:[],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 U);let r=new U,s=new Be,o=new Be;function a(c){let u=0,h=0,f=0;for(let O=0;O<9;O++)n.probe[O].set(0,0,0);let d=0,p=0,x=0,g=0,m=0,b=0,v=0,y=0,M=0,S=0,_=0,w=0,R=0,A=0;c.sort(eE);for(let O=0,D=c.length;O<D;O++){let P=c[O],I=P.color,N=P.intensity,F=P.distance,H=null;if(P.shadow&&P.shadow.map&&(P.shadow.map.texture.format===Ur?H=P.shadow.map.texture:H=P.shadow.map.depthTexture||P.shadow.map.texture),P.isAmbientLight)u+=I.r*N,h+=I.g*N,f+=I.b*N;else if(P.isLightProbe){for(let B=0;B<9;B++)n.probe[B].addScaledVector(P.sh.coefficients[B],N);A++}else if(P.isSunLight){let B=e.get(P);if(B.color.copy(P.color).multiplyScalar(P.intensity),P.castShadow){let X=P.shadow,V=t.get(P);V.shadowIntensity=X.intensity,V.shadowBias=X.bias,V.shadowNormalBias=X.normalBias,V.shadowRadius=X.radius,V.shadowMapSize.copy(X.mapSize).multiply(X.getFrameExtents()),n.sunShadow[p]=V,n.sunShadowMap[p]=H;let re=X.getViewportCount();for(let be=0;be<re;be++)n.sunShadowMatrix[x+be]=X.getMatrix(be),n.sunShadowCascade[x+be]=X._cascadeData[be];x+=re,p++}n.sun[d]=B,d++}else if(P.isDirectionalLight){let B=e.get(P);if(B.color.copy(P.color).multiplyScalar(P.intensity),P.castShadow){let X=P.shadow,V=t.get(P);V.shadowIntensity=X.intensity,V.shadowBias=X.bias,V.shadowNormalBias=X.normalBias,V.shadowRadius=X.radius,V.shadowMapSize=X.mapSize,n.directionalShadow[g]=V,n.directionalShadowMap[g]=H,n.directionalShadowMatrix[g]=P.shadow.matrix,M++}n.directional[g]=B,g++}else if(P.isSpotLight){let B=e.get(P);B.position.setFromMatrixPosition(P.matrixWorld),B.color.copy(I).multiplyScalar(N),B.distance=F,B.coneCos=Math.cos(P.angle),B.penumbraCos=Math.cos(P.angle*(1-P.penumbra)),B.decay=P.decay,n.spot[b]=B;let X=P.shadow;if(P.map&&(n.spotLightMap[w]=P.map,w++,X.updateMatrices(P),P.castShadow&&R++),n.spotLightMatrix[b]=X.matrix,P.castShadow){let V=t.get(P);V.shadowIntensity=X.intensity,V.shadowBias=X.bias,V.shadowNormalBias=X.normalBias,V.shadowRadius=X.radius,V.shadowMapSize=X.mapSize,n.spotShadow[b]=V,n.spotShadowMap[b]=H,_++}b++}else if(P.isRectAreaLight){let B=e.get(P);B.color.copy(I).multiplyScalar(N),B.halfWidth.set(P.width*.5,0,0),B.halfHeight.set(0,P.height*.5,0),n.rectArea[v]=B,v++}else if(P.isPointLight){let B=e.get(P);if(B.color.copy(P.color).multiplyScalar(P.intensity),B.distance=P.distance,B.decay=P.decay,P.castShadow){let X=P.shadow,V=t.get(P);V.shadowIntensity=X.intensity,V.shadowBias=X.bias,V.shadowNormalBias=X.normalBias,V.shadowRadius=X.radius,V.shadowMapSize=X.mapSize,V.shadowCameraNear=X.camera.near,V.shadowCameraFar=X.camera.far,n.pointShadow[m]=V,n.pointShadowMap[m]=H,n.pointShadowMatrix[m]=P.shadow.matrix,S++}n.point[m]=B,m++}else if(P.isHemisphereLight){let B=e.get(P);B.skyColor.copy(P.color).multiplyScalar(N),B.groundColor.copy(P.groundColor).multiplyScalar(N),n.hemi[y]=B,y++}}v>0&&(i.has("OES_texture_float_linear")===!0?(n.rectAreaLTC1=ve.LTC_FLOAT_1,n.rectAreaLTC2=ve.LTC_FLOAT_2):(n.rectAreaLTC1=ve.LTC_HALF_1,n.rectAreaLTC2=ve.LTC_HALF_2)),n.ambient[0]=u,n.ambient[1]=h,n.ambient[2]=f;let C=n.hash;(C.sunLength!==d||C.directionalLength!==g||C.pointLength!==m||C.spotLength!==b||C.rectAreaLength!==v||C.hemiLength!==y||C.numSunShadows!==p||C.numDirectionalShadows!==M||C.numPointShadows!==S||C.numSpotShadows!==_||C.numSpotMaps!==w||C.numLightProbes!==A)&&(n.sun.length=d,n.directional.length=g,n.spot.length=b,n.rectArea.length=v,n.point.length=m,n.hemi.length=y,n.sunShadow.length=p,n.sunShadowMap.length=p,n.sunShadowMatrix.length=x,n.sunShadowCascade.length=x,n.directionalShadow.length=M,n.directionalShadowMap.length=M,n.directionalShadowMatrix.length=M,n.pointShadow.length=S,n.pointShadowMap.length=S,n.pointShadowMatrix.length=S,n.spotShadow.length=_,n.spotShadowMap.length=_,n.spotLightMatrix.length=_+w-R,n.spotLightMap.length=w,n.numSpotLightShadowsWithMaps=R,n.numLightProbes=A,C.sunLength=d,C.directionalLength=g,C.pointLength=m,C.spotLength=b,C.rectAreaLength=v,C.hemiLength=y,C.numSunShadows=p,C.numDirectionalShadows=M,C.numPointShadows=S,C.numSpotShadows=_,C.numSpotMaps=w,C.numLightProbes=A,n.version=QA++)}function l(c,u){let h=0,f=0,d=0,p=0,x=0,g=0,m=u.matrixWorldInverse;for(let b=0,v=c.length;b<v;b++){let y=c[b];if(y.isSunLight){let M=n.sun[h];M.direction.setFromMatrixPosition(y.matrixWorld),M.direction.transformDirection(m),h++}else if(y.isDirectionalLight){let M=n.directional[f];M.direction.setFromMatrixPosition(y.matrixWorld),r.setFromMatrixPosition(y.target.matrixWorld),M.direction.sub(r),M.direction.transformDirection(m),f++}else if(y.isSpotLight){let M=n.spot[p];M.position.setFromMatrixPosition(y.matrixWorld),M.position.applyMatrix4(m),M.direction.setFromMatrixPosition(y.matrixWorld),r.setFromMatrixPosition(y.target.matrixWorld),M.direction.sub(r),M.direction.transformDirection(m),p++}else if(y.isRectAreaLight){let M=n.rectArea[x];M.position.setFromMatrixPosition(y.matrixWorld),M.position.applyMatrix4(m),o.identity(),s.copy(y.matrixWorld),s.premultiply(m),o.extractRotation(s),M.halfWidth.set(y.width*.5,0,0),M.halfHeight.set(0,y.height*.5,0),M.halfWidth.applyMatrix4(o),M.halfHeight.applyMatrix4(o),x++}else if(y.isPointLight){let M=n.point[d];M.position.setFromMatrixPosition(y.matrixWorld),M.position.applyMatrix4(m),d++}else if(y.isHemisphereLight){let M=n.hemi[g];M.direction.setFromMatrixPosition(y.matrixWorld),M.direction.transformDirection(m),g++}}}return{setup:a,setupView:l,state:n}}function Gx(i){let e=new tE(i),t=[],n=[],r=[];function s(h){u.camera=h,t.length=0,n.length=0,r.length=0}function o(h){h.isLightProbeGrid?r.push(h):t.push(h)}function a(h){n.push(h)}function l(){e.setup(t),r.sort((h,f)=>h.priority-f.priority||h.id-f.id)}function c(h){e.setupView(t,h)}let u={lightsArray:t,shadowsArray:n,lightProbeGridArray:r,camera:null,lights:e,transmissionRenderTarget:{},textureUnits:0};return{init:s,state:u,setupLights:l,setupLightsView:c,pushLight:o,pushShadow:a}}function nE(i){let e=new WeakMap;function t(r,s=0){let o=e.get(r),a;return o===void 0?(a=new Gx(i),e.set(r,[a])):s>=o.length?(a=new Gx(i),o.push(a)):a=o[s],a}function n(){e=new WeakMap}return{get:t,dispose:n}}var iE=`void main() {
|
|
gl_Position = vec4( position, 1.0 );
|
|
}`,rE=`uniform sampler2D shadow_pass;
|
|
uniform vec2 resolution;
|
|
uniform float radius;
|
|
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 = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ).rg;
|
|
mean += distribution.x;
|
|
squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;
|
|
#else
|
|
float depth = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ).r;
|
|
mean += depth;
|
|
squared_mean += depth * depth;
|
|
#endif
|
|
}
|
|
mean = mean / samples;
|
|
squared_mean = squared_mean / samples;
|
|
float std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) );
|
|
gl_FragColor = vec4( mean, std_dev, 0.0, 1.0 );
|
|
}`,sE=[new U(1,0,0),new U(-1,0,0),new U(0,1,0),new U(0,-1,0),new U(0,0,1),new U(0,0,-1)],oE=[new U(0,-1,0),new U(0,-1,0),new U(0,0,1),new U(0,0,-1),new U(0,-1,0),new U(0,-1,0)],Hx=new Be,Ka=new U,gd=new U;function aE(i,e,t){let n=new Ir,r=new De,s=new De,o=new _t,a=new Rc,l=new Cc,c={},u=t.maxTextureSize,h={[Ti]:un,[un]:Ti,[ut]:ut},f=new Mi({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new De},radius:{value:4}},vertexShader:iE,fragmentShader:rE}),d=f.clone();d.defines.HORIZONTAL_PASS=1;let p=new Fe;p.setAttribute("position",new wt(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));let x=new we(p,f),g=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=ka;let m=this.type;this.render=function(S,_,w){if(g.enabled===!1||g.autoUpdate===!1&&g.needsUpdate===!1||S.length===0)return;this.type===Fg&&(Le("WebGLShadowMap: PCFSoftShadowMap has been removed. Using PCFShadowMap instead."),this.type=ka);let R=i.getRenderTarget(),A=i.getActiveCubeFace(),C=i.getActiveMipmapLevel(),O=i.state;O.setBlending(ms),O.buffers.depth.getReversed()===!0?O.buffers.color.setClear(0,0,0,0):O.buffers.color.setClear(1,1,1,1),O.buffers.depth.setTest(!0),O.setScissorTest(!1);let D=m!==this.type;D&&_.traverse(function(P){P.material&&(Array.isArray(P.material)?P.material.forEach(I=>I.needsUpdate=!0):P.material.needsUpdate=!0)});for(let P=0,I=S.length;P<I;P++){let N=S[P],F=N.shadow;if(F===void 0){Le("WebGLShadowMap:",N,"has no shadow.");continue}if(F.autoUpdate===!1&&F.needsUpdate===!1)continue;r.copy(F.mapSize);let H=F.getFrameExtents();r.multiply(H),s.copy(F.mapSize),(r.x>u||r.y>u)&&(r.x>u&&(s.x=Math.floor(u/H.x),r.x=s.x*H.x,F.mapSize.x=s.x),r.y>u&&(s.y=Math.floor(u/H.y),r.y=s.y*H.y,F.mapSize.y=s.y));let B=i.state.buffers.depth.getReversed();if(F.camera._reversedDepth=B,F.map===null||D===!0){if(F.map!==null&&(F.map.depthTexture!==null&&(F.map.depthTexture.dispose(),F.map.depthTexture=null),F.map.dispose()),this.type===bo){if(N.isPointLight){Le("WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.");continue}F.map=new wn(r.x,r.y,{format:Ur,type:ai,minFilter:Ht,magFilter:Ht,generateMipmaps:!1}),F.map.texture.name=N.name+".shadowMap",F.map.depthTexture=new er(r.x,r.y,Vn),F.map.depthTexture.name=N.name+".shadowMapDepth",F.map.depthTexture.format=$i,F.map.depthTexture.compareFunction=null,F.map.depthTexture.minFilter=Ut,F.map.depthTexture.magFilter=Ut}else N.isPointLight?(F.map=new Ja(r.x),F.map.depthTexture=new Ma(r.x,oi)):(F.map=new wn(r.x,r.y),F.map.depthTexture=new er(r.x,r.y,oi)),F.map.depthTexture.name=N.name+".shadowMap",F.map.depthTexture.format=$i,this.type===ka?(F.map.depthTexture.compareFunction=B?Jf:Zf,F.map.depthTexture.minFilter=Ht,F.map.depthTexture.magFilter=Ht):(F.map.depthTexture.compareFunction=null,F.map.depthTexture.minFilter=Ut,F.map.depthTexture.magFilter=Ut);F.camera.updateProjectionMatrix()}F.map.isWebGLCubeRenderTarget!==!0&&(F.map.width!==r.x||F.map.height!==r.y)&&F.map.setSize(r.x,r.y);let X=F.map.isWebGLCubeRenderTarget?6:F.getViewportCount();N.isPointLight!==!0&&F.updateMatrices(N,w);let V=(F.camera.layers.mask&4294967294)!==0?F.camera.layers:w.layers;for(let re=0;re<X;re++){let be=F.getCamera(re);if(N.isPointLight){let Y=F.camera,Q=F.matrix,se=N.distance||Y.far;se!==Y.far&&(Y.far=se,Y.updateProjectionMatrix()),Ka.setFromMatrixPosition(N.matrixWorld),Y.position.copy(Ka),gd.copy(Y.position),gd.add(sE[re]),Y.up.copy(oE[re]),Y.lookAt(gd),Y.updateMatrixWorld(),Q.makeTranslation(-Ka.x,-Ka.y,-Ka.z),Hx.multiplyMatrices(Y.projectionMatrix,Y.matrixWorldInverse),F._frustum.setFromProjectionMatrix(Hx,Y.coordinateSystem,Y.reversedDepth)}if(F.map.isWebGLCubeRenderTarget)i.setRenderTarget(F.map,re),i.clear();else{re===0&&(i.setRenderTarget(F.map),i.clear());let Y=F.getViewport(re);o.set(s.x*Y.x,s.y*Y.y,s.x*Y.z,s.y*Y.w),O.viewport(o)}n=F.getFrustum(re),y(_,w,be,N,V,this.type)}F.isPointLightShadow!==!0&&this.type===bo&&b(F,w),F.needsUpdate=!1}m=this.type,g.needsUpdate=!1,i.setRenderTarget(R,A,C)};function b(S,_){let w=e.update(x);f.defines.VSM_SAMPLES!==S.blurSamples&&(f.defines.VSM_SAMPLES=S.blurSamples,d.defines.VSM_SAMPLES=S.blurSamples,f.needsUpdate=!0,d.needsUpdate=!0),S.mapPass===null?S.mapPass=new wn(r.x,r.y,{format:Ur,type:ai}):(S.mapPass.width!==S.map.width||S.mapPass.height!==S.map.height)&&S.mapPass.setSize(S.map.width,S.map.height),f.uniforms.shadow_pass.value=S.map.depthTexture,f.uniforms.resolution.value.set(S.map.width,S.map.height),f.uniforms.radius.value=S.radius,i.setRenderTarget(S.mapPass),i.clear(),i.renderBufferDirect(_,null,w,f,x,null),d.uniforms.shadow_pass.value=S.mapPass.texture,d.uniforms.resolution.value.set(S.map.width,S.map.height),d.uniforms.radius.value=S.radius,i.setRenderTarget(S.map),i.clear(),i.renderBufferDirect(_,null,w,d,x,null)}function v(S,_,w,R){let A=null,C=w.isPointLight===!0?S.customDistanceMaterial:S.customDepthMaterial;if(C!==void 0)A=C;else if(A=w.isPointLight===!0?l:a,i.localClippingEnabled&&_.clipShadows===!0&&Array.isArray(_.clippingPlanes)&&_.clippingPlanes.length!==0||_.displacementMap&&_.displacementScale!==0||_.alphaMap&&_.alphaTest>0||_.map&&_.alphaTest>0||_.alphaToCoverage===!0){let O=A.uuid,D=_.uuid,P=c[O];P===void 0&&(P={},c[O]=P);let I=P[D];I===void 0&&(I=A.clone(),P[D]=I,_.addEventListener("dispose",M)),A=I}if(A.visible=_.visible,A.wireframe=_.wireframe,R===bo?A.side=_.shadowSide!==null?_.shadowSide:_.side:A.side=_.shadowSide!==null?_.shadowSide:h[_.side],A.alphaMap=_.alphaMap,A.alphaTest=_.alphaToCoverage===!0?.5:_.alphaTest,A.map=_.map,A.clipShadows=_.clipShadows,A.clippingPlanes=_.clippingPlanes,A.clipIntersection=_.clipIntersection,A.displacementMap=_.displacementMap,A.displacementScale=_.displacementScale,A.displacementBias=_.displacementBias,A.wireframeLinewidth=_.wireframeLinewidth,A.linewidth=_.linewidth,w.isPointLight===!0&&A.isMeshDistanceMaterial===!0){let O=i.properties.get(A);O.light=w}return A}function y(S,_,w,R,A,C){if(S.visible===!1)return;if(S.layers.test(A)&&(S.isMesh||S.isLine||S.isPoints)&&(S.castShadow||S.receiveShadow&&C===bo)&&(!S.frustumCulled||S.intersectsFrustum(n))){S.modelViewMatrix.multiplyMatrices(w.matrixWorldInverse,S.matrixWorld);let P=e.update(S),I=S.material;if(Array.isArray(I)){let N=P.groups;for(let F=0,H=N.length;F<H;F++){let B=N[F],X=I[B.materialIndex];if(X&&X.visible){let V=v(S,X,R,C);S.onBeforeShadow(i,S,_,w,P,V,B),i.renderBufferDirect(w,null,P,V,S,B),S.onAfterShadow(i,S,_,w,P,V,B)}}}else if(I.visible){let N=v(S,I,R,C);S.onBeforeShadow(i,S,_,w,P,N,null),i.renderBufferDirect(w,null,P,N,S,null),S.onAfterShadow(i,S,_,w,P,N,null)}}let D=S.children;for(let P=0,I=D.length;P<I;P++)y(D[P],_,w,R,A,C)}function M(S){S.target.removeEventListener("dispose",M);for(let w in c){let R=c[w],A=S.target.uuid;A in R&&(R[A].dispose(),delete R[A])}}}function lE(i,e){function t(){let k=!1,ne=new _t,j=null,de=new _t(0,0,0,0);return{setMask:function(ce){j!==ce&&!k&&(i.colorMask(ce,ce,ce,ce),j=ce)},setLocked:function(ce){k=ce},setClear:function(ce,he,Oe,je,ae){ae===!0&&(ce*=je,he*=je,Oe*=je),ne.set(ce,he,Oe,je),de.equals(ne)===!1&&(i.clearColor(ce,he,Oe,je),de.copy(ne))},reset:function(){k=!1,j=null,de.set(-1,0,0,0)}}}function n(){let k=!1,ne=!1,j=null,de=null,ce=null;return{setReversed:function(he){if(ne!==he){let Oe=e.get("EXT_clip_control");he?Oe.clipControlEXT(Oe.LOWER_LEFT_EXT,Oe.ZERO_TO_ONE_EXT):Oe.clipControlEXT(Oe.LOWER_LEFT_EXT,Oe.NEGATIVE_ONE_TO_ONE_EXT),ne=he;let je=ce;ce=null,this.setClear(je)}},getReversed:function(){return ne},setTest:function(he){he?le(i.DEPTH_TEST):Ie(i.DEPTH_TEST)},setMask:function(he){j!==he&&!k&&(i.depthMask(he),j=he)},setFunc:function(he){if(ne&&(he=dx[he]),de!==he){switch(he){case mc:i.depthFunc(i.NEVER);break;case gc:i.depthFunc(i.ALWAYS);break;case xc:i.depthFunc(i.LESS);break;case ro:i.depthFunc(i.LEQUAL);break;case bc:i.depthFunc(i.EQUAL);break;case yc:i.depthFunc(i.GEQUAL);break;case _c:i.depthFunc(i.GREATER);break;case vc:i.depthFunc(i.NOTEQUAL);break;default:i.depthFunc(i.LEQUAL)}de=he}},setLocked:function(he){k=he},setClear:function(he){ce!==he&&(ce=he,ne&&(he=1-he),i.clearDepth(he))},reset:function(){k=!1,j=null,de=null,ce=null,ne=!1}}}function r(){let k=!1,ne=null,j=null,de=null,ce=null,he=null,Oe=null,je=null,ae=null;return{setTest:function(Ne){k||(Ne?le(i.STENCIL_TEST):Ie(i.STENCIL_TEST))},setMask:function(Ne){ne!==Ne&&!k&&(i.stencilMask(Ne),ne=Ne)},setFunc:function(Ne,Ze,_e){(j!==Ne||de!==Ze||ce!==_e)&&(i.stencilFunc(Ne,Ze,_e),j=Ne,de=Ze,ce=_e)},setOp:function(Ne,Ze,_e){(he!==Ne||Oe!==Ze||je!==_e)&&(i.stencilOp(Ne,Ze,_e),he=Ne,Oe=Ze,je=_e)},setLocked:function(Ne){k=Ne},setClear:function(Ne){ae!==Ne&&(i.clearStencil(Ne),ae=Ne)},reset:function(){k=!1,ne=null,j=null,de=null,ce=null,he=null,Oe=null,je=null,ae=null}}}let s=new t,o=new n,a=new r,l={},c=new WeakMap,u={},h={},f={},d=new WeakMap,p=[],x=null,g=!1,m=null,b=null,v=null,y=null,M=null,S=null,_=null,w=new W(0,0,0),R=0,A=!1,C=null,O=null,D=null,P=null,I=null,N=i.getParameter(i.MAX_COMBINED_TEXTURE_IMAGE_UNITS),F=!1,H=0,B=i.getParameter(i.VERSION);B.indexOf("WebGL")!==-1?(H=parseFloat(/^WebGL (\d)/.exec(B)[1]),F=H>=1):B.indexOf("OpenGL ES")!==-1&&(H=parseFloat(/^OpenGL ES (\d)/.exec(B)[1]),F=H>=2);let X=null,V={},re=i.getParameter(i.SCISSOR_BOX),be=i.getParameter(i.VIEWPORT),Y=new _t().fromArray(re),Q=new _t().fromArray(be);function se(k,ne,j,de){let ce=new Uint8Array(4),he=i.createTexture();i.bindTexture(k,he),i.texParameteri(k,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(k,i.TEXTURE_MAG_FILTER,i.NEAREST);for(let Oe=0;Oe<j;Oe++)k===i.TEXTURE_3D||k===i.TEXTURE_2D_ARRAY?i.texImage3D(ne,0,i.RGBA,1,1,de,0,i.RGBA,i.UNSIGNED_BYTE,ce):i.texImage2D(ne+Oe,0,i.RGBA,1,1,0,i.RGBA,i.UNSIGNED_BYTE,ce);return he}let Se={};Se[i.TEXTURE_2D]=se(i.TEXTURE_2D,i.TEXTURE_2D,1),Se[i.TEXTURE_CUBE_MAP]=se(i.TEXTURE_CUBE_MAP,i.TEXTURE_CUBE_MAP_POSITIVE_X,6),Se[i.TEXTURE_2D_ARRAY]=se(i.TEXTURE_2D_ARRAY,i.TEXTURE_2D_ARRAY,1,1),Se[i.TEXTURE_3D]=se(i.TEXTURE_3D,i.TEXTURE_3D,1,1),s.setClear(0,0,0,1),o.setClear(1),a.setClear(0),le(i.DEPTH_TEST),o.setFunc(ro),on(!1),Ot(If),le(i.CULL_FACE),Yt(ms);function le(k){u[k]!==!0&&(i.enable(k),u[k]=!0)}function Ie(k){u[k]!==!1&&(i.disable(k),u[k]=!1)}function st(k,ne){return f[k]!==ne?(i.bindFramebuffer(k,ne),f[k]=ne,k===i.DRAW_FRAMEBUFFER&&(f[i.FRAMEBUFFER]=ne),k===i.FRAMEBUFFER&&(f[i.DRAW_FRAMEBUFFER]=ne),!0):!1}function Te(k,ne){let j=p,de=!1;if(k){j=d.get(ne),j===void 0&&(j=[],d.set(ne,j));let ce=k.textures;if(j.length!==ce.length||j[0]!==i.COLOR_ATTACHMENT0){for(let he=0,Oe=ce.length;he<Oe;he++)j[he]=i.COLOR_ATTACHMENT0+he;j.length=ce.length,de=!0}}else j[0]!==i.BACK&&(j[0]=i.BACK,de=!0);de&&i.drawBuffers(j)}function ht(k){return x!==k?(i.useProgram(k),x=k,!0):!1}let bt={[gs]:i.FUNC_ADD,[Ng]:i.FUNC_SUBTRACT,[Dg]:i.FUNC_REVERSE_SUBTRACT};bt[Ug]=i.MIN,bt[Bg]=i.MAX;let et={[kg]:i.ZERO,[zg]:i.ONE,[Vg]:i.SRC_COLOR,[Ff]:i.SRC_ALPHA,[qg]:i.SRC_ALPHA_SATURATE,[Xg]:i.DST_COLOR,[Hg]:i.DST_ALPHA,[Gg]:i.ONE_MINUS_SRC_COLOR,[Of]:i.ONE_MINUS_SRC_ALPHA,[Yg]:i.ONE_MINUS_DST_COLOR,[Wg]:i.ONE_MINUS_DST_ALPHA,[$g]:i.CONSTANT_COLOR,[Kg]:i.ONE_MINUS_CONSTANT_COLOR,[Zg]:i.CONSTANT_ALPHA,[Jg]:i.ONE_MINUS_CONSTANT_ALPHA};function Yt(k,ne,j,de,ce,he,Oe,je,ae,Ne){if(k===ms){g===!0&&(Ie(i.BLEND),g=!1);return}if(g===!1&&(le(i.BLEND),g=!0),k!==Og){if(k!==m||Ne!==A){if((b!==gs||M!==gs)&&(i.blendEquation(i.FUNC_ADD),b=gs,M=gs),Ne)switch(k){case Ai:i.blendFuncSeparate(i.ONE,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA);break;case Ft:i.blendFunc(i.ONE,i.ONE);break;case Lf:i.blendFuncSeparate(i.ZERO,i.ONE_MINUS_SRC_COLOR,i.ZERO,i.ONE);break;case za:i.blendFuncSeparate(i.DST_COLOR,i.ONE_MINUS_SRC_ALPHA,i.ZERO,i.ONE);break;default:Ge("WebGLState: Invalid blending: ",k);break}else switch(k){case Ai:i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA);break;case Ft:i.blendFuncSeparate(i.SRC_ALPHA,i.ONE,i.ONE,i.ONE);break;case Lf:Ge("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case za:Ge("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:Ge("WebGLState: Invalid blending: ",k);break}v=null,y=null,S=null,_=null,w.set(0,0,0),R=0,m=k,A=Ne}return}ce=ce||ne,he=he||j,Oe=Oe||de,(ne!==b||ce!==M)&&(i.blendEquationSeparate(bt[ne],bt[ce]),b=ne,M=ce),(j!==v||de!==y||he!==S||Oe!==_)&&(i.blendFuncSeparate(et[j],et[de],et[he],et[Oe]),v=j,y=de,S=he,_=Oe),(je.equals(w)===!1||ae!==R)&&(i.blendColor(je.r,je.g,je.b,ae),w.copy(je),R=ae),m=k,A=!1}function kt(k,ne){k.side===ut?Ie(i.CULL_FACE):le(i.CULL_FACE);let j=k.side===un;ne&&(j=!j),on(j),k.blending===Ai&&k.transparent===!1?Yt(ms):Yt(k.blending,k.blendEquation,k.blendSrc,k.blendDst,k.blendEquationAlpha,k.blendSrcAlpha,k.blendDstAlpha,k.blendColor,k.blendAlpha,k.premultipliedAlpha),o.setFunc(k.depthFunc),o.setTest(k.depthTest),o.setMask(k.depthWrite),s.setMask(k.colorWrite);let de=k.stencilWrite;a.setTest(de),de&&(a.setMask(k.stencilWriteMask),a.setFunc(k.stencilFunc,k.stencilRef,k.stencilFuncMask),a.setOp(k.stencilFail,k.stencilZFail,k.stencilZPass)),en(k.polygonOffset,k.polygonOffsetFactor,k.polygonOffsetUnits),k.alphaToCoverage===!0?le(i.SAMPLE_ALPHA_TO_COVERAGE):Ie(i.SAMPLE_ALPHA_TO_COVERAGE)}function on(k){C!==k&&(k?i.frontFace(i.CW):i.frontFace(i.CCW),C=k)}function Ot(k){k!==Ig?(le(i.CULL_FACE),k!==O&&(k===If?i.cullFace(i.BACK):k===Lg?i.cullFace(i.FRONT):i.cullFace(i.FRONT_AND_BACK))):Ie(i.CULL_FACE),O=k}function gi(k){k!==D&&(F&&i.lineWidth(k),D=k)}function en(k,ne,j){k?(le(i.POLYGON_OFFSET_FILL),(P!==ne||I!==j)&&(P=ne,I=j,o.getReversed()&&(ne=-ne,j=-j),i.polygonOffset(ne,j))):Ie(i.POLYGON_OFFSET_FILL)}function Hn(k){k?le(i.SCISSOR_TEST):Ie(i.SCISSOR_TEST)}function Wn(k){k===void 0&&(k=i.TEXTURE0+N-1),X!==k&&(i.activeTexture(k),X=k)}function Xn(k,ne,j){j===void 0&&(X===null?j=i.TEXTURE0+N-1:j=X);let de=V[j];de===void 0&&(de={type:void 0,texture:void 0},V[j]=de),(de.type!==k||de.texture!==ne)&&(X!==j&&(i.activeTexture(j),X=j),i.bindTexture(k,ne||Se[k]),de.type=k,de.texture=ne)}function G(){let k=V[X];k!==void 0&&k.type!==void 0&&(i.bindTexture(k.type,null),k.type=void 0,k.texture=void 0)}function Yn(){try{i.compressedTexImage2D(...arguments)}catch(k){Ge("WebGLState:",k)}}function Pt(){try{i.compressedTexImage3D(...arguments)}catch(k){Ge("WebGLState:",k)}}function It(){try{i.texSubImage2D(...arguments)}catch(k){Ge("WebGLState:",k)}}function ye(){try{i.texSubImage3D(...arguments)}catch(k){Ge("WebGLState:",k)}}function Zt(){try{i.compressedTexSubImage2D(...arguments)}catch(k){Ge("WebGLState:",k)}}function ze(){try{i.compressedTexSubImage3D(...arguments)}catch(k){Ge("WebGLState:",k)}}function We(){try{i.texStorage2D(...arguments)}catch(k){Ge("WebGLState:",k)}}function L(){try{i.texStorage3D(...arguments)}catch(k){Ge("WebGLState:",k)}}function T(){try{i.texImage2D(...arguments)}catch(k){Ge("WebGLState:",k)}}function $(){try{i.texImage3D(...arguments)}catch(k){Ge("WebGLState:",k)}}function oe(k){return h[k]!==void 0?h[k]:i.getParameter(k)}function ie(k,ne){h[k]!==ne&&(i.pixelStorei(k,ne),h[k]=ne)}function ue(k){Y.equals(k)===!1&&(i.scissor(k.x,k.y,k.z,k.w),Y.copy(k))}function ge(k){Q.equals(k)===!1&&(i.viewport(k.x,k.y,k.z,k.w),Q.copy(k))}function ee(k,ne){let j=c.get(ne);j===void 0&&(j=new WeakMap,c.set(ne,j));let de=j.get(k);de===void 0&&(de=i.getUniformBlockIndex(ne,k.name),i.uniformBlockBinding(ne,de,de),j.set(k,de))}function te(k,ne,j){let ce=c.get(ne).get(k);l[ce]!==j&&(i.bindBufferBase(i.UNIFORM_BUFFER,ce,j),l[ce]=j)}function fe(){i.disable(i.BLEND),i.disable(i.CULL_FACE),i.disable(i.DEPTH_TEST),i.disable(i.POLYGON_OFFSET_FILL),i.disable(i.SCISSOR_TEST),i.disable(i.STENCIL_TEST),i.disable(i.SAMPLE_ALPHA_TO_COVERAGE),i.blendEquation(i.FUNC_ADD),i.blendFunc(i.ONE,i.ZERO),i.blendFuncSeparate(i.ONE,i.ZERO,i.ONE,i.ZERO),i.blendColor(0,0,0,0),i.colorMask(!0,!0,!0,!0),i.clearColor(0,0,0,0),i.depthMask(!0),i.depthFunc(i.LESS),o.setReversed(!1),i.clearDepth(1),i.stencilMask(4294967295),i.stencilFunc(i.ALWAYS,0,4294967295),i.stencilOp(i.KEEP,i.KEEP,i.KEEP),i.clearStencil(0),i.cullFace(i.BACK),i.frontFace(i.CCW),i.polygonOffset(0,0),i.activeTexture(i.TEXTURE0),i.bindFramebuffer(i.FRAMEBUFFER,null),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,null),i.bindFramebuffer(i.READ_FRAMEBUFFER,null),i.useProgram(null),i.lineWidth(1),i.scissor(0,0,i.canvas.width,i.canvas.height),i.viewport(0,0,i.canvas.width,i.canvas.height),i.pixelStorei(i.PACK_ALIGNMENT,4),i.pixelStorei(i.UNPACK_ALIGNMENT,4),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!1),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,i.BROWSER_DEFAULT_WEBGL),i.pixelStorei(i.PACK_ROW_LENGTH,0),i.pixelStorei(i.PACK_SKIP_PIXELS,0),i.pixelStorei(i.PACK_SKIP_ROWS,0),i.pixelStorei(i.UNPACK_ROW_LENGTH,0),i.pixelStorei(i.UNPACK_IMAGE_HEIGHT,0),i.pixelStorei(i.UNPACK_SKIP_PIXELS,0),i.pixelStorei(i.UNPACK_SKIP_ROWS,0),i.pixelStorei(i.UNPACK_SKIP_IMAGES,0),u={},h={},X=null,V={},f={},l={},d=new WeakMap,p=[],x=null,g=!1,m=null,b=null,v=null,y=null,M=null,S=null,_=null,w=new W(0,0,0),R=0,A=!1,C=null,O=null,D=null,P=null,I=null,Y.set(0,0,i.canvas.width,i.canvas.height),Q.set(0,0,i.canvas.width,i.canvas.height),s.reset(),o.reset(),a.reset()}return{buffers:{color:s,depth:o,stencil:a},enable:le,disable:Ie,bindFramebuffer:st,drawBuffers:Te,useProgram:ht,setBlending:Yt,setMaterial:kt,setFlipSided:on,setCullFace:Ot,setLineWidth:gi,setPolygonOffset:en,setScissorTest:Hn,activeTexture:Wn,bindTexture:Xn,unbindTexture:G,compressedTexImage2D:Yn,compressedTexImage3D:Pt,texImage2D:T,texImage3D:$,pixelStorei:ie,getParameter:oe,updateUBOMapping:ee,uniformBlockBinding:te,texStorage2D:We,texStorage3D:L,texSubImage2D:It,texSubImage3D:ye,compressedTexSubImage2D:Zt,compressedTexSubImage3D:ze,scissor:ue,viewport:ge,reset:fe}}function cE(i,e,t,n,r,s,o){let a=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):null,l=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),c=new De,u=new WeakMap,h=new Set,f,d=new WeakMap,p=new Set,x=new FinalizationRegistry(L=>p.delete(L)),g=!1;try{g=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function m(L,T){return g?new OffscreenCanvas(L,T):oo("canvas")}function b(L,T,$){let oe=1,ie=We(L);if((ie.width>$||ie.height>$)&&(oe=$/Math.max(ie.width,ie.height)),oe<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 ue=Math.floor(oe*ie.width),ge=Math.floor(oe*ie.height);f===void 0&&(f=m(ue,ge));let ee=T?m(ue,ge):f;return ee.width=ue,ee.height=ge,ee.getContext("2d").drawImage(L,0,0,ue,ge),Le("WebGLRenderer: Texture has been resized from ("+ie.width+"x"+ie.height+") to ("+ue+"x"+ge+")."),ee}else return"data"in L&&Le("WebGLRenderer: Image in DataTexture is too big ("+ie.width+"x"+ie.height+")."),L;return L}function v(L){return L.generateMipmaps}function y(L){i.generateMipmap(L)}function M(L){return L.isWebGLCubeRenderTarget?i.TEXTURE_CUBE_MAP:L.isWebGL3DRenderTarget?i.TEXTURE_3D:L.isWebGLArrayRenderTarget||L.isCompressedArrayTexture?i.TEXTURE_2D_ARRAY:i.TEXTURE_2D}function S(L,T,$,oe,ie,ue=!1){if(L!==null){if(i[L]!==void 0)return i[L];Le("WebGLRenderer: Attempt to use non-existing WebGL internal format '"+L+"'")}let ge;oe&&(ge=e.get("EXT_texture_norm16"),ge||Le("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let ee=T;if(T===i.RED&&($===i.FLOAT&&(ee=i.R32F),$===i.HALF_FLOAT&&(ee=i.R16F),$===i.UNSIGNED_BYTE&&(ee=i.R8),$===i.UNSIGNED_SHORT&&ge&&(ee=ge.R16_EXT),$===i.SHORT&&ge&&(ee=ge.R16_SNORM_EXT)),T===i.RED_INTEGER&&($===i.UNSIGNED_BYTE&&(ee=i.R8UI),$===i.UNSIGNED_SHORT&&(ee=i.R16UI),$===i.UNSIGNED_INT&&(ee=i.R32UI),$===i.BYTE&&(ee=i.R8I),$===i.SHORT&&(ee=i.R16I),$===i.INT&&(ee=i.R32I)),T===i.RG&&($===i.FLOAT&&(ee=i.RG32F),$===i.HALF_FLOAT&&(ee=i.RG16F),$===i.UNSIGNED_BYTE&&(ee=i.RG8),$===i.UNSIGNED_SHORT&&ge&&(ee=ge.RG16_EXT),$===i.SHORT&&ge&&(ee=ge.RG16_SNORM_EXT)),T===i.RG_INTEGER&&($===i.UNSIGNED_BYTE&&(ee=i.RG8UI),$===i.UNSIGNED_SHORT&&(ee=i.RG16UI),$===i.UNSIGNED_INT&&(ee=i.RG32UI),$===i.BYTE&&(ee=i.RG8I),$===i.SHORT&&(ee=i.RG16I),$===i.INT&&(ee=i.RG32I)),T===i.RGB_INTEGER&&($===i.UNSIGNED_BYTE&&(ee=i.RGB8UI),$===i.UNSIGNED_SHORT&&(ee=i.RGB16UI),$===i.UNSIGNED_INT&&(ee=i.RGB32UI),$===i.BYTE&&(ee=i.RGB8I),$===i.SHORT&&(ee=i.RGB16I),$===i.INT&&(ee=i.RGB32I)),T===i.RGBA_INTEGER&&($===i.UNSIGNED_BYTE&&(ee=i.RGBA8UI),$===i.UNSIGNED_SHORT&&(ee=i.RGBA16UI),$===i.UNSIGNED_INT&&(ee=i.RGBA32UI),$===i.BYTE&&(ee=i.RGBA8I),$===i.SHORT&&(ee=i.RGBA16I),$===i.INT&&(ee=i.RGBA32I)),T===i.RGB&&($===i.UNSIGNED_SHORT&&ge&&(ee=ge.RGB16_EXT),$===i.SHORT&&ge&&(ee=ge.RGB16_SNORM_EXT),$===i.UNSIGNED_INT_5_9_9_9_REV&&(ee=i.RGB9_E5),$===i.UNSIGNED_INT_10F_11F_11F_REV&&(ee=i.R11F_G11F_B10F)),T===i.RGBA){let te=ue?pa:tt.getTransfer(ie);$===i.FLOAT&&(ee=i.RGBA32F),$===i.HALF_FLOAT&&(ee=i.RGBA16F),$===i.UNSIGNED_BYTE&&(ee=te===Mt?i.SRGB8_ALPHA8:i.RGBA8),$===i.UNSIGNED_SHORT&&ge&&(ee=ge.RGBA16_EXT),$===i.SHORT&&ge&&(ee=ge.RGBA16_SNORM_EXT),$===i.UNSIGNED_SHORT_4_4_4_4&&(ee=i.RGBA4),$===i.UNSIGNED_SHORT_5_5_5_1&&(ee=i.RGB5_A1)}return(ee===i.R16F||ee===i.R32F||ee===i.RG16F||ee===i.RG32F||ee===i.RGBA16F||ee===i.RGBA32F)&&e.get("EXT_color_buffer_float"),ee}function _(L,T){let $;return L?T===null||T===oi||T===bs?$=i.DEPTH24_STENCIL8:T===Vn?$=i.DEPTH32F_STENCIL8:T===vo&&($=i.DEPTH24_STENCIL8,Le("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):T===null||T===oi||T===bs?$=i.DEPTH_COMPONENT24:T===Vn?$=i.DEPTH_COMPONENT32F:T===vo&&($=i.DEPTH_COMPONENT16),$}function w(L,T){return v(L)===!0||L.isFramebufferTexture&&L.minFilter!==Ut&&L.minFilter!==Ht?Math.log2(Math.max(T.width,T.height))+1:L.mipmaps.length>0?L.mipmaps.length:L.isCompressedTexture&&Array.isArray(L.image)?T.mipmaps.length:1}function R(L){let T=new WeakRef(L);n.get(L).__ref=T,p.add(T),x.register(L,T,T)}function A(L){let T=n.get(L).__ref;T!==void 0&&(p.delete(T),x.unregister(T))}function C(L){D(L.target)}function O(L){P(L.target)}function D(L){L.removeEventListener("dispose",C),A(L),N(L),L.isVideoTexture&&u.delete(L),L.isHTMLTexture&&h.delete(L)}function P(L){L.removeEventListener("dispose",O),A(L),H(L)}function I(){for(let L of p){let T=L.deref();T!==void 0&&(T.isRenderTarget===!0?P(T):D(T))}p.clear(),h.clear()}function N(L){let T=n.get(L);if(T.__webglInit===void 0)return;let $=L.source,oe=d.get($);if(oe){let ie=oe[T.__cacheKey];ie.usedTimes--,ie.usedTimes===0&&F(L),Object.keys(oe).length===0&&d.delete($)}n.remove(L)}function F(L){let T=n.get(L);i.deleteTexture(T.__webglTexture);let $=L.source,oe=d.get($);delete oe[T.__cacheKey],o.memory.textures--}function H(L){let T=n.get(L);T.__depthDisposeCallback&&T.__depthDisposeCallback();let $=L.depthTexture;if($&&$.renderTarget===L&&D($),L.isWebGLCubeRenderTarget)for(let ie=0;ie<6;ie++){if(Array.isArray(T.__webglFramebuffer[ie]))for(let ue=0;ue<T.__webglFramebuffer[ie].length;ue++)i.deleteFramebuffer(T.__webglFramebuffer[ie][ue]);else i.deleteFramebuffer(T.__webglFramebuffer[ie]);T.__webglDepthbuffer&&i.deleteRenderbuffer(T.__webglDepthbuffer[ie])}else{if(Array.isArray(T.__webglFramebuffer))for(let ie=0;ie<T.__webglFramebuffer.length;ie++)i.deleteFramebuffer(T.__webglFramebuffer[ie]);else i.deleteFramebuffer(T.__webglFramebuffer);if(T.__webglDepthbuffer&&i.deleteRenderbuffer(T.__webglDepthbuffer),T.__webglMultisampledFramebuffer&&i.deleteFramebuffer(T.__webglMultisampledFramebuffer),T.__webglColorRenderbuffer)for(let ie=0;ie<T.__webglColorRenderbuffer.length;ie++)T.__webglColorRenderbuffer[ie]&&i.deleteRenderbuffer(T.__webglColorRenderbuffer[ie]);T.__webglDepthRenderbuffer&&i.deleteRenderbuffer(T.__webglDepthRenderbuffer)}let oe=L.textures;for(let ie=0,ue=oe.length;ie<ue;ie++){let ge=n.get(oe[ie]);ge.__webglTexture&&(i.deleteTexture(ge.__webglTexture),o.memory.textures--),n.remove(oe[ie])}n.remove(L)}let B=0;function X(){B=0}function V(){return B}function re(L){B=L}function be(){let L=B;return L>=r.maxTextures&&Le("WebGLTextures: Trying to use "+(L+1)+" texture units while this GPU supports only "+r.maxTextures),B+=1,L}function Y(L){let T=[];return T.push(L.wrapS),T.push(L.wrapT),T.push(L.wrapR||0),T.push(L.magFilter),T.push(L.minFilter),T.push(L.anisotropy),T.push(L.internalFormat),T.push(L.format),T.push(L.type),T.push(L.generateMipmaps),T.push(L.mipmapsAutoUpdate),T.push(L.premultiplyAlpha),T.push(L.flipY),T.push(L.unpackAlignment),T.push(L.colorSpace),T.join()}function Q(L,T){let $=n.get(L);if(L.isVideoTexture&&Zt(L),L.isRenderTargetTexture===!1&&L.isExternalTexture!==!0&&L.version>0&&$.__version!==L.version){let oe=L.image;if(oe===null)Le("WebGLRenderer: Texture marked for update but no image data found.");else if(oe.complete===!1)Le("WebGLRenderer: Texture marked for update but image is incomplete");else{kt($,L,T);return}}else L.isExternalTexture&&($.__webglTexture=L.sourceTexture?L.sourceTexture:null);t.bindTexture(i.TEXTURE_2D,$.__webglTexture,i.TEXTURE0+T)}function se(L,T){let $=n.get(L);if(L.isRenderTargetTexture===!1&&L.version>0&&$.__version!==L.version){kt($,L,T);return}else L.isExternalTexture&&($.__webglTexture=L.sourceTexture?L.sourceTexture:null);t.bindTexture(i.TEXTURE_2D_ARRAY,$.__webglTexture,i.TEXTURE0+T)}function Se(L,T){let $=n.get(L);if(L.isRenderTargetTexture===!1&&L.version>0&&$.__version!==L.version){kt($,L,T);return}t.bindTexture(i.TEXTURE_3D,$.__webglTexture,i.TEXTURE0+T)}function le(L,T){let $=n.get(L);if(L.version>0&&$.__version!==L.version){on($,L,T);return}t.bindTexture(i.TEXTURE_CUBE_MAP,$.__webglTexture,i.TEXTURE0+T)}let Ie={[kn]:i.REPEAT,[ln]:i.CLAMP_TO_EDGE,[Rr]:i.MIRRORED_REPEAT},st={[Ut]:i.NEAREST,[_o]:i.NEAREST_MIPMAP_NEAREST,[ar]:i.NEAREST_MIPMAP_LINEAR,[Ht]:i.LINEAR,[Dr]:i.LINEAR_MIPMAP_NEAREST,[Fn]:i.LINEAR_MIPMAP_LINEAR},Te={[sx]:i.NEVER,[jf]:i.ALWAYS,[ox]:i.LESS,[Zf]:i.LEQUAL,[ax]:i.EQUAL,[Jf]:i.GEQUAL,[lx]:i.GREATER,[cx]:i.NOTEQUAL};function ht(L,T){if(T.type===Vn&&e.has("OES_texture_float_linear")===!1&&(T.magFilter===Ht||T.magFilter===Dr||T.magFilter===ar||T.magFilter===Fn||T.minFilter===Ht||T.minFilter===Dr||T.minFilter===ar||T.minFilter===Fn)&&Le("WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),i.texParameteri(L,i.TEXTURE_WRAP_S,Ie[T.wrapS]),i.texParameteri(L,i.TEXTURE_WRAP_T,Ie[T.wrapT]),(L===i.TEXTURE_3D||L===i.TEXTURE_2D_ARRAY)&&i.texParameteri(L,i.TEXTURE_WRAP_R,Ie[T.wrapR]),i.texParameteri(L,i.TEXTURE_MAG_FILTER,st[T.magFilter]),i.texParameteri(L,i.TEXTURE_MIN_FILTER,st[T.minFilter]),T.compareFunction&&(i.texParameteri(L,i.TEXTURE_COMPARE_MODE,i.COMPARE_REF_TO_TEXTURE),i.texParameteri(L,i.TEXTURE_COMPARE_FUNC,Te[T.compareFunction])),e.has("EXT_texture_filter_anisotropic")===!0){if(T.magFilter===Ut||T.minFilter!==ar&&T.minFilter!==Fn||T.type===Vn&&e.has("OES_texture_float_linear")===!1)return;if(T.anisotropy>1||n.get(T).__currentAnisotropy){let $=e.get("EXT_texture_filter_anisotropic");i.texParameterf(L,$.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(T.anisotropy,r.getMaxAnisotropy())),n.get(T).__currentAnisotropy=T.anisotropy}}}function bt(L,T){let $=!1;L.__webglInit===void 0&&(L.__webglInit=!0,T.addEventListener("dispose",C),R(T));let oe=T.source,ie=d.get(oe);ie===void 0&&(ie={},d.set(oe,ie));let ue=Y(T);if(ue!==L.__cacheKey){ie[ue]===void 0&&(ie[ue]={texture:i.createTexture(),usedTimes:0},o.memory.textures++,$=!0),ie[ue].usedTimes++;let ge=ie[L.__cacheKey];ge!==void 0&&(ie[L.__cacheKey].usedTimes--,ge.usedTimes===0&&F(T)),L.__cacheKey=ue,L.__webglTexture=ie[ue].texture}return $}function et(L,T,$){return Math.floor(Math.floor(L/$)/T)}function Yt(L,T,$,oe){let ue=L.updateRanges;if(ue.length===0)t.texSubImage2D(i.TEXTURE_2D,0,0,0,T.width,T.height,$,oe,T.data);else{ue.sort((k,ne)=>k.start-ne.start);let ge=0;for(let k=1;k<ue.length;k++){let ne=ue[ge],j=ue[k],de=ne.start+ne.count,ce=et(j.start,T.width,4),he=et(ne.start,T.width,4);j.start<=de+1&&ce===he&&et(j.start+j.count-1,T.width,4)===ce?ne.count=Math.max(ne.count,j.start+j.count-ne.start):(++ge,ue[ge]=j)}ue.length=ge+1;let ee=t.getParameter(i.UNPACK_ROW_LENGTH),te=t.getParameter(i.UNPACK_SKIP_PIXELS),fe=t.getParameter(i.UNPACK_SKIP_ROWS);t.pixelStorei(i.UNPACK_ROW_LENGTH,T.width);for(let k=0,ne=ue.length;k<ne;k++){let j=ue[k],de=Math.floor(j.start/4),ce=Math.ceil(j.count/4),he=de%T.width,Oe=Math.floor(de/T.width),je=ce,ae=1;t.pixelStorei(i.UNPACK_SKIP_PIXELS,he),t.pixelStorei(i.UNPACK_SKIP_ROWS,Oe),t.texSubImage2D(i.TEXTURE_2D,0,he,Oe,je,ae,$,oe,T.data)}L.clearUpdateRanges(),t.pixelStorei(i.UNPACK_ROW_LENGTH,ee),t.pixelStorei(i.UNPACK_SKIP_PIXELS,te),t.pixelStorei(i.UNPACK_SKIP_ROWS,fe)}}function kt(L,T,$){let oe=i.TEXTURE_2D;(T.isDataArrayTexture||T.isCompressedArrayTexture)&&(oe=i.TEXTURE_2D_ARRAY),T.isData3DTexture&&(oe=i.TEXTURE_3D);let ie=bt(L,T),ue=T.source;t.bindTexture(oe,L.__webglTexture,i.TEXTURE0+$);let ge=n.get(ue);if(ue.version!==ge.__version||ie===!0){if(t.activeTexture(i.TEXTURE0+$),(typeof ImageBitmap<"u"&&T.image instanceof ImageBitmap)===!1){let ae=tt.getPrimaries(tt.workingColorSpace),Ne=T.colorSpace===li?null:tt.getPrimaries(T.colorSpace),Ze=T.colorSpace===li||ae===Ne?i.NONE:i.BROWSER_DEFAULT_WEBGL;t.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,T.flipY),t.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,T.premultiplyAlpha),t.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,Ze)}t.pixelStorei(i.UNPACK_ALIGNMENT,T.unpackAlignment);let te=b(T.image,!1,r.maxTextureSize);te=ze(T,te);let fe=s.convert(T.format,T.colorSpace),k=s.convert(T.type),ne=S(T.internalFormat,fe,k,T.normalized,T.colorSpace,T.isVideoTexture);ht(oe,T);let j,de=T.mipmaps,ce=T.isVideoTexture!==!0,he=ge.__version===void 0||ie===!0,Oe=ue.dataReady,je=w(T,te);if(T.isDepthTexture)ne=_(T.format===lr,T.type),he&&(ce?t.texStorage2D(i.TEXTURE_2D,1,ne,te.width,te.height):t.texImage2D(i.TEXTURE_2D,0,ne,te.width,te.height,0,fe,k,null));else if(T.isDataTexture)if(de.length>0){ce&&he&&t.texStorage2D(i.TEXTURE_2D,je,ne,de[0].width,de[0].height);for(let ae=0,Ne=de.length;ae<Ne;ae++)j=de[ae],ce?Oe&&t.texSubImage2D(i.TEXTURE_2D,ae,0,0,j.width,j.height,fe,k,j.data):t.texImage2D(i.TEXTURE_2D,ae,ne,j.width,j.height,0,fe,k,j.data);T.generateMipmaps=!1}else ce?(he&&t.texStorage2D(i.TEXTURE_2D,je,ne,te.width,te.height),Oe&&Yt(T,te,fe,k)):t.texImage2D(i.TEXTURE_2D,0,ne,te.width,te.height,0,fe,k,te.data);else if(T.isCompressedTexture)if(T.isCompressedArrayTexture){ce&&he&&t.texStorage3D(i.TEXTURE_2D_ARRAY,je,ne,de[0].width,de[0].height,te.depth);for(let ae=0,Ne=de.length;ae<Ne;ae++)if(j=de[ae],T.format!==Nn)if(fe!==null)if(ce){if(Oe)if(T.layerUpdates.size>0){let Ze=cd(j.width,j.height,T.format,T.type);for(let _e of T.layerUpdates){let St=j.data.subarray(_e*Ze/j.data.BYTES_PER_ELEMENT,(_e+1)*Ze/j.data.BYTES_PER_ELEMENT);t.compressedTexSubImage3D(i.TEXTURE_2D_ARRAY,ae,0,0,_e,j.width,j.height,1,fe,St)}}else t.compressedTexSubImage3D(i.TEXTURE_2D_ARRAY,ae,0,0,0,j.width,j.height,te.depth,fe,j.data)}else t.compressedTexImage3D(i.TEXTURE_2D_ARRAY,ae,ne,j.width,j.height,te.depth,0,j.data,0,0);else Le("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else ce?Oe&&t.texSubImage3D(i.TEXTURE_2D_ARRAY,ae,0,0,0,j.width,j.height,te.depth,fe,k,j.data):t.texImage3D(i.TEXTURE_2D_ARRAY,ae,ne,j.width,j.height,te.depth,0,fe,k,j.data);T.layerUpdates.size>0&&T.clearLayerUpdates()}else{ce&&he&&t.texStorage2D(i.TEXTURE_2D,je,ne,de[0].width,de[0].height);for(let ae=0,Ne=de.length;ae<Ne;ae++)j=de[ae],T.format!==Nn?fe!==null?ce?Oe&&t.compressedTexSubImage2D(i.TEXTURE_2D,ae,0,0,j.width,j.height,fe,j.data):t.compressedTexImage2D(i.TEXTURE_2D,ae,ne,j.width,j.height,0,j.data):Le("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):ce?Oe&&t.texSubImage2D(i.TEXTURE_2D,ae,0,0,j.width,j.height,fe,k,j.data):t.texImage2D(i.TEXTURE_2D,ae,ne,j.width,j.height,0,fe,k,j.data)}else if(T.isDataArrayTexture)if(ce){if(he&&t.texStorage3D(i.TEXTURE_2D_ARRAY,je,ne,te.width,te.height,te.depth),Oe)if(T.layerUpdates.size>0){let ae=cd(te.width,te.height,T.format,T.type);for(let Ne of T.layerUpdates){let Ze=te.data.subarray(Ne*ae/te.data.BYTES_PER_ELEMENT,(Ne+1)*ae/te.data.BYTES_PER_ELEMENT);t.texSubImage3D(i.TEXTURE_2D_ARRAY,0,0,0,Ne,te.width,te.height,1,fe,k,Ze)}T.clearLayerUpdates()}else t.texSubImage3D(i.TEXTURE_2D_ARRAY,0,0,0,0,te.width,te.height,te.depth,fe,k,te.data)}else t.texImage3D(i.TEXTURE_2D_ARRAY,0,ne,te.width,te.height,te.depth,0,fe,k,te.data);else if(T.isData3DTexture)ce?(he&&t.texStorage3D(i.TEXTURE_3D,je,ne,te.width,te.height,te.depth),Oe&&t.texSubImage3D(i.TEXTURE_3D,0,0,0,0,te.width,te.height,te.depth,fe,k,te.data)):t.texImage3D(i.TEXTURE_3D,0,ne,te.width,te.height,te.depth,0,fe,k,te.data);else if(T.isFramebufferTexture){if(he)if(ce)t.texStorage2D(i.TEXTURE_2D,je,ne,te.width,te.height);else{let ae=te.width,Ne=te.height;for(let Ze=0;Ze<je;Ze++)t.texImage2D(i.TEXTURE_2D,Ze,ne,ae,Ne,0,fe,k,null),ae>>=1,Ne>>=1}}else if(T.isHTMLTexture){if("texElementImage2D"in i){let ae=i.canvas;if(ae.hasAttribute("layoutsubtree")||ae.setAttribute("layoutsubtree","true"),te.parentNode!==ae){ae.appendChild(te),h.add(T),ae.onpaint=Ne=>{let Ze=Ne.changedElements;for(let _e of h)Ze.includes(_e.image)&&(_e.needsUpdate=!0)},ae.requestPaint();return}if(i.texElementImage2D.length===3)i.texElementImage2D(i.TEXTURE_2D,i.RGBA8,te);else{let Ze=i.RGBA,_e=i.RGBA,St=i.UNSIGNED_BYTE;i.texElementImage2D(i.TEXTURE_2D,0,Ze,_e,St,te)}i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE)}}else if(de.length>0){if(ce&&he){let ae=We(de[0]);t.texStorage2D(i.TEXTURE_2D,je,ne,ae.width,ae.height)}for(let ae=0,Ne=de.length;ae<Ne;ae++)j=de[ae],ce?Oe&&t.texSubImage2D(i.TEXTURE_2D,ae,0,0,fe,k,j):t.texImage2D(i.TEXTURE_2D,ae,ne,fe,k,j);T.generateMipmaps=!1}else if(ce){if(he){let ae=We(te);t.texStorage2D(i.TEXTURE_2D,je,ne,ae.width,ae.height)}Oe&&t.texSubImage2D(i.TEXTURE_2D,0,0,0,fe,k,te)}else t.texImage2D(i.TEXTURE_2D,0,ne,fe,k,te);v(T)&&T.mipmapsAutoUpdate===!0&&y(oe),ge.__version=ue.version,T.onUpdate&&T.onUpdate(T)}L.__version=T.version}function on(L,T,$){if(T.image.length!==6)return;let oe=bt(L,T),ie=T.source;t.bindTexture(i.TEXTURE_CUBE_MAP,L.__webglTexture,i.TEXTURE0+$);let ue=n.get(ie);if(ie.version!==ue.__version||oe===!0){t.activeTexture(i.TEXTURE0+$);let ge=tt.getPrimaries(tt.workingColorSpace),ee=T.colorSpace===li?null:tt.getPrimaries(T.colorSpace),te=T.colorSpace===li||ge===ee?i.NONE:i.BROWSER_DEFAULT_WEBGL;t.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,T.flipY),t.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,T.premultiplyAlpha),t.pixelStorei(i.UNPACK_ALIGNMENT,T.unpackAlignment),t.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,te);let fe=T.isCompressedTexture||T.image[0].isCompressedTexture,k=T.image[0]&&T.image[0].isDataTexture,ne=[];for(let _e=0;_e<6;_e++)!fe&&!k?ne[_e]=b(T.image[_e],!0,r.maxCubemapSize):ne[_e]=k?T.image[_e].image:T.image[_e],ne[_e]=ze(T,ne[_e]);let j=ne[0],de=s.convert(T.format,T.colorSpace),ce=s.convert(T.type),he=S(T.internalFormat,de,ce,T.normalized,T.colorSpace),Oe=T.isVideoTexture!==!0,je=ue.__version===void 0||oe===!0,ae=ie.dataReady,Ne=w(T,j);ht(i.TEXTURE_CUBE_MAP,T);let Ze;if(T.isDepthTexture){if(he=_(T.format===lr,T.type),je)if(Oe)t.texStorage2D(i.TEXTURE_CUBE_MAP,1,he,j.width,j.height);else for(let _e=0;_e<6;_e++)t.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+_e,0,he,j.width,j.height,0,de,ce,null)}else if(fe){Oe&&je&&t.texStorage2D(i.TEXTURE_CUBE_MAP,Ne,he,j.width,j.height);for(let _e=0;_e<6;_e++){Ze=ne[_e].mipmaps;for(let St=0;St<Ze.length;St++){let tn=Ze[St];T.format!==Nn?de!==null?Oe?ae&&t.compressedTexSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+_e,St,0,0,tn.width,tn.height,de,tn.data):t.compressedTexImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+_e,St,he,tn.width,tn.height,0,tn.data):Le("WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):Oe?ae&&t.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+_e,St,0,0,tn.width,tn.height,de,ce,tn.data):t.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+_e,St,he,tn.width,tn.height,0,de,ce,tn.data)}}}else{if(Ze=T.mipmaps,Oe&&je){Ze.length>0&&Ne++;let _e=We(ne[0]);t.texStorage2D(i.TEXTURE_CUBE_MAP,Ne,he,_e.width,_e.height)}for(let _e=0;_e<6;_e++)if(k){Oe?ae&&t.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+_e,0,0,0,ne[_e].width,ne[_e].height,de,ce,ne[_e].data):t.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+_e,0,he,ne[_e].width,ne[_e].height,0,de,ce,ne[_e].data);for(let St=0;St<Ze.length;St++){let br=Ze[St].image[_e].image;Oe?ae&&t.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+_e,St+1,0,0,br.width,br.height,de,ce,br.data):t.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+_e,St+1,he,br.width,br.height,0,de,ce,br.data)}}else{Oe?ae&&t.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+_e,0,0,0,de,ce,ne[_e]):t.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+_e,0,he,de,ce,ne[_e]);for(let St=0;St<Ze.length;St++){let tn=Ze[St];Oe?ae&&t.texSubImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+_e,St+1,0,0,de,ce,tn.image[_e]):t.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+_e,St+1,he,de,ce,tn.image[_e])}}}v(T)&&T.mipmapsAutoUpdate===!0&&y(i.TEXTURE_CUBE_MAP),ue.__version=ie.version,T.onUpdate&&T.onUpdate(T)}L.__version=T.version}function Ot(L,T,$,oe,ie,ue){let ge=s.convert($.format,$.colorSpace),ee=s.convert($.type),te=S($.internalFormat,ge,ee,$.normalized,$.colorSpace),fe=n.get(T),k=n.get($);if(k.__renderTarget=T,!fe.__hasExternalTextures){let ne=Math.max(1,T.width>>ue),j=Math.max(1,T.height>>ue);ie===i.TEXTURE_3D||ie===i.TEXTURE_2D_ARRAY?t.texImage3D(ie,ue,te,ne,j,T.depth,0,ge,ee,null):t.texImage2D(ie,ue,te,ne,j,0,ge,ee,null)}t.bindFramebuffer(i.FRAMEBUFFER,L),ye(T)?a.framebufferTexture2DMultisampleEXT(i.FRAMEBUFFER,oe,ie,k.__webglTexture,0,It(T)):(ie===i.TEXTURE_2D||ie>=i.TEXTURE_CUBE_MAP_POSITIVE_X&&ie<=i.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&i.framebufferTexture2D(i.FRAMEBUFFER,oe,ie,k.__webglTexture,ue),t.bindFramebuffer(i.FRAMEBUFFER,null)}function gi(L,T,$){if(i.bindRenderbuffer(i.RENDERBUFFER,L),T.depthBuffer){let oe=T.depthTexture,ie=oe&&oe.isDepthTexture?oe.type:null,ue=_(T.stencilBuffer,ie),ge=T.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT;ye(T)?a.renderbufferStorageMultisampleEXT(i.RENDERBUFFER,It(T),ue,T.width,T.height):$?i.renderbufferStorageMultisample(i.RENDERBUFFER,It(T),ue,T.width,T.height):i.renderbufferStorage(i.RENDERBUFFER,ue,T.width,T.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,ge,i.RENDERBUFFER,L)}else{let oe=T.textures;for(let ie=0;ie<oe.length;ie++){let ue=oe[ie],ge=s.convert(ue.format,ue.colorSpace),ee=s.convert(ue.type),te=S(ue.internalFormat,ge,ee,ue.normalized,ue.colorSpace);ye(T)?a.renderbufferStorageMultisampleEXT(i.RENDERBUFFER,It(T),te,T.width,T.height):$?i.renderbufferStorageMultisample(i.RENDERBUFFER,It(T),te,T.width,T.height):i.renderbufferStorage(i.RENDERBUFFER,te,T.width,T.height)}}i.bindRenderbuffer(i.RENDERBUFFER,null)}function en(L,T,$){let oe=T.isWebGLCubeRenderTarget===!0;if(t.bindFramebuffer(i.FRAMEBUFFER,L),!(T.depthTexture&&T.depthTexture.isDepthTexture))throw new Error("THREE.WebGLTextures: renderTarget.depthTexture must be an instance of THREE.DepthTexture.");let ie=n.get(T.depthTexture);ie.__renderTarget=T;let ue=oe?T.depthTexture.image[0]:T.depthTexture.image;(!ie.__webglTexture||ue.width!==T.width||ue.height!==T.height)&&(ue.width=T.width,ue.height=T.height,T.depthTexture.needsUpdate=!0),oe?le(T.depthTexture,0):Q(T.depthTexture,0);let ge=ie.__webglTexture,ee=It(T),te=oe?i.TEXTURE_CUBE_MAP_POSITIVE_X+$:i.TEXTURE_2D,fe=T.depthTexture.format===lr?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT;if(T.depthTexture.format===$i)ye(T)?a.framebufferTexture2DMultisampleEXT(i.FRAMEBUFFER,fe,te,ge,0,ee):i.framebufferTexture2D(i.FRAMEBUFFER,fe,te,ge,0);else if(T.depthTexture.format===lr)ye(T)?a.framebufferTexture2DMultisampleEXT(i.FRAMEBUFFER,fe,te,ge,0,ee):i.framebufferTexture2D(i.FRAMEBUFFER,fe,te,ge,0);else throw new Error("THREE.WebGLTextures: Unknown depthTexture format.")}function Hn(L){let T=n.get(L),$=L.isWebGLCubeRenderTarget===!0;if(T.__boundDepthTexture!==L.depthTexture){let oe=L.depthTexture;if(T.__depthDisposeCallback&&T.__depthDisposeCallback(),oe){let ie=()=>{delete T.__boundDepthTexture,delete T.__depthDisposeCallback,oe.removeEventListener("dispose",ie)};oe.addEventListener("dispose",ie),T.__depthDisposeCallback=ie}T.__boundDepthTexture=oe}if(L.depthTexture&&!T.__autoAllocateDepthBuffer)if($)for(let oe=0;oe<6;oe++)en(T.__webglFramebuffer[oe],L,oe);else L.texture.mipmaps.length>0?en(T.__webglFramebuffer[0],L,0):en(T.__webglFramebuffer,L,0);else if($){T.__webglDepthbuffer=[];for(let oe=0;oe<6;oe++)if(t.bindFramebuffer(i.FRAMEBUFFER,T.__webglFramebuffer[oe]),T.__webglDepthbuffer[oe]===void 0)T.__webglDepthbuffer[oe]=i.createRenderbuffer(),gi(T.__webglDepthbuffer[oe],L,!1);else{let ie=L.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT,ue=T.__webglDepthbuffer[oe];i.bindRenderbuffer(i.RENDERBUFFER,ue),i.framebufferRenderbuffer(i.FRAMEBUFFER,ie,i.RENDERBUFFER,ue)}}else if(L.texture.mipmaps.length>0?t.bindFramebuffer(i.FRAMEBUFFER,T.__webglFramebuffer[0]):t.bindFramebuffer(i.FRAMEBUFFER,T.__webglFramebuffer),T.__webglDepthbuffer===void 0)T.__webglDepthbuffer=i.createRenderbuffer(),gi(T.__webglDepthbuffer,L,!1);else{let ie=L.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT,ue=T.__webglDepthbuffer;i.bindRenderbuffer(i.RENDERBUFFER,ue),i.framebufferRenderbuffer(i.FRAMEBUFFER,ie,i.RENDERBUFFER,ue)}t.bindFramebuffer(i.FRAMEBUFFER,null)}function Wn(L,T,$){let oe=n.get(L);T!==void 0&&Ot(oe.__webglFramebuffer,L,L.texture,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,0),$!==void 0&&Hn(L)}function Xn(L){let T=L.texture,$=n.get(L),oe=n.get(T);L.addEventListener("dispose",O),R(L);let ie=L.textures,ue=L.isWebGLCubeRenderTarget===!0,ge=ie.length>1;if(ge||(oe.__webglTexture===void 0&&(oe.__webglTexture=i.createTexture()),oe.__version=T.version,o.memory.textures++),ue){$.__webglFramebuffer=[];for(let ee=0;ee<6;ee++)if(T.mipmaps.length>0){$.__webglFramebuffer[ee]=[];for(let te=0;te<T.mipmaps.length;te++)$.__webglFramebuffer[ee][te]=i.createFramebuffer()}else $.__webglFramebuffer[ee]=i.createFramebuffer()}else{if(T.mipmaps.length>0){$.__webglFramebuffer=[];for(let ee=0;ee<T.mipmaps.length;ee++)$.__webglFramebuffer[ee]=i.createFramebuffer()}else $.__webglFramebuffer=i.createFramebuffer();if(ge)for(let ee=0,te=ie.length;ee<te;ee++){let fe=n.get(ie[ee]);fe.__webglTexture===void 0&&(fe.__webglTexture=i.createTexture(),o.memory.textures++)}if(L.samples>0&&ye(L)===!1){$.__webglMultisampledFramebuffer=i.createFramebuffer(),$.__webglColorRenderbuffer=[],t.bindFramebuffer(i.FRAMEBUFFER,$.__webglMultisampledFramebuffer);for(let ee=0;ee<ie.length;ee++){let te=ie[ee];$.__webglColorRenderbuffer[ee]=i.createRenderbuffer(),i.bindRenderbuffer(i.RENDERBUFFER,$.__webglColorRenderbuffer[ee]);let fe=s.convert(te.format,te.colorSpace),k=s.convert(te.type),ne=S(te.internalFormat,fe,k,te.normalized,te.colorSpace,L.isXRRenderTarget===!0),j=It(L);i.renderbufferStorageMultisample(i.RENDERBUFFER,j,ne,L.width,L.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+ee,i.RENDERBUFFER,$.__webglColorRenderbuffer[ee])}i.bindRenderbuffer(i.RENDERBUFFER,null),L.depthBuffer&&($.__webglDepthRenderbuffer=i.createRenderbuffer(),gi($.__webglDepthRenderbuffer,L,!0)),t.bindFramebuffer(i.FRAMEBUFFER,null)}}if(ue){t.bindTexture(i.TEXTURE_CUBE_MAP,oe.__webglTexture),ht(i.TEXTURE_CUBE_MAP,T);for(let ee=0;ee<6;ee++)if(T.mipmaps.length>0)for(let te=0;te<T.mipmaps.length;te++)Ot($.__webglFramebuffer[ee][te],L,T,i.COLOR_ATTACHMENT0,i.TEXTURE_CUBE_MAP_POSITIVE_X+ee,te);else Ot($.__webglFramebuffer[ee],L,T,i.COLOR_ATTACHMENT0,i.TEXTURE_CUBE_MAP_POSITIVE_X+ee,0);v(T)?y(i.TEXTURE_CUBE_MAP):T.mipmaps.length>0&&i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_MAX_LEVEL,T.mipmaps.length-1),t.unbindTexture()}else if(ge){for(let ee=0,te=ie.length;ee<te;ee++){let fe=ie[ee],k=n.get(fe),ne=i.TEXTURE_2D;(L.isWebGL3DRenderTarget||L.isWebGLArrayRenderTarget)&&(ne=L.isWebGL3DRenderTarget?i.TEXTURE_3D:i.TEXTURE_2D_ARRAY),t.bindTexture(ne,k.__webglTexture),ht(ne,fe),Ot($.__webglFramebuffer,L,fe,i.COLOR_ATTACHMENT0+ee,ne,0),v(fe)&&y(ne)}t.unbindTexture()}else{let ee=i.TEXTURE_2D;if((L.isWebGL3DRenderTarget||L.isWebGLArrayRenderTarget)&&(ee=L.isWebGL3DRenderTarget?i.TEXTURE_3D:i.TEXTURE_2D_ARRAY),t.bindTexture(ee,oe.__webglTexture),ht(ee,T),T.mipmaps.length>0)for(let te=0;te<T.mipmaps.length;te++)Ot($.__webglFramebuffer[te],L,T,i.COLOR_ATTACHMENT0,ee,te);else Ot($.__webglFramebuffer,L,T,i.COLOR_ATTACHMENT0,ee,0);v(T)?y(ee):T.mipmaps.length>0&&i.texParameteri(ee,i.TEXTURE_MAX_LEVEL,T.mipmaps.length-1),t.unbindTexture()}L.depthBuffer&&Hn(L)}function G(L){let T=L.textures;for(let $=0,oe=T.length;$<oe;$++){let ie=T[$];if(v(ie)&&ie.mipmapsAutoUpdate===!0){let ue=M(L),ge=n.get(ie).__webglTexture;t.bindTexture(ue,ge),y(ue),t.unbindTexture()}}}let Yn=[];function Pt(L){if(L.samples>0){if(ye(L)===!1){let T=L.textures,$=L.width,oe=L.height,ie=i.COLOR_BUFFER_BIT,ue=L.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT,ge=n.get(L),ee=T.length>1;if(ee)for(let fe=0;fe<T.length;fe++)t.bindFramebuffer(i.FRAMEBUFFER,ge.__webglMultisampledFramebuffer),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+fe,i.RENDERBUFFER,null),t.bindFramebuffer(i.FRAMEBUFFER,ge.__webglFramebuffer),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,i.COLOR_ATTACHMENT0+fe,i.TEXTURE_2D,null,0);t.bindFramebuffer(i.READ_FRAMEBUFFER,ge.__webglMultisampledFramebuffer),L.texture.mipmaps.length>0?t.bindFramebuffer(i.DRAW_FRAMEBUFFER,ge.__webglFramebuffer[0]):t.bindFramebuffer(i.DRAW_FRAMEBUFFER,ge.__webglFramebuffer);for(let fe=0;fe<T.length;fe++){if(L.resolveDepthBuffer&&(L.depthBuffer&&(ie|=i.DEPTH_BUFFER_BIT),L.stencilBuffer&&L.resolveStencilBuffer&&(ie|=i.STENCIL_BUFFER_BIT)),ee){i.framebufferRenderbuffer(i.READ_FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.RENDERBUFFER,ge.__webglColorRenderbuffer[fe]);let k=n.get(T[fe]).__webglTexture;i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,k,0)}i.blitFramebuffer(0,0,$,oe,0,0,$,oe,ie,i.NEAREST),l===!0&&(Yn.length=0,Yn.push(i.COLOR_ATTACHMENT0+fe),L.depthBuffer&&L.storeMultisampledDepthBuffer===!1&&Yn.push(ue),i.invalidateFramebuffer(i.READ_FRAMEBUFFER,Yn))}if(t.bindFramebuffer(i.READ_FRAMEBUFFER,null),t.bindFramebuffer(i.DRAW_FRAMEBUFFER,null),ee)for(let fe=0;fe<T.length;fe++){t.bindFramebuffer(i.FRAMEBUFFER,ge.__webglMultisampledFramebuffer),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+fe,i.RENDERBUFFER,ge.__webglColorRenderbuffer[fe]);let k=n.get(T[fe]).__webglTexture;t.bindFramebuffer(i.FRAMEBUFFER,ge.__webglFramebuffer),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,i.COLOR_ATTACHMENT0+fe,i.TEXTURE_2D,k,0)}t.bindFramebuffer(i.DRAW_FRAMEBUFFER,ge.__webglMultisampledFramebuffer)}else if(L.depthBuffer&&L.storeMultisampledDepthBuffer===!1&&l){let T=L.stencilBuffer?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT;i.invalidateFramebuffer(i.DRAW_FRAMEBUFFER,[T])}}}function It(L){return Math.min(r.maxSamples,L.samples)}function ye(L){let T=n.get(L);return L.samples>0&&e.has("WEBGL_multisampled_render_to_texture")===!0&&T.__useRenderToTexture!==!1}function Zt(L){let T=o.render.frame;u.get(L)!==T&&(u.set(L,T),L.update())}function ze(L,T){let $=L.colorSpace,oe=L.format,ie=L.type;return L.isCompressedTexture===!0||L.isVideoTexture===!0||$!==Mn&&$!==li&&(tt.getTransfer($)===Mt?(oe!==Nn||ie!==On)&&Le("WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):Ge("WebGLTextures: Unsupported texture color space:",$)),T}function We(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=be,this.resetTextureUnits=X,this.getTextureUnits=V,this.setTextureUnits=re,this.setTexture2D=Q,this.setTexture2DArray=se,this.setTexture3D=Se,this.setTextureCube=le,this.rebindTextures=Wn,this.setupRenderTarget=Xn,this.updateRenderTargetMipmap=G,this.updateMultisampleRenderTarget=Pt,this.setupDepthRenderbuffer=Hn,this.setupFrameBufferTexture=Ot,this.useMultisampledRTT=ye,this.dispose=I}function uE(i,e){function t(n,r=li){let s,o=tt.getTransfer(r);if(n===On)return i.UNSIGNED_BYTE;if(n===Hc)return i.UNSIGNED_SHORT_4_4_4_4;if(n===Wc)return i.UNSIGNED_SHORT_5_5_5_1;if(n===Xf)return i.UNSIGNED_INT_5_9_9_9_REV;if(n===Yf)return i.UNSIGNED_INT_10F_11F_11F_REV;if(n===Hf)return i.BYTE;if(n===Wf)return i.SHORT;if(n===vo)return i.UNSIGNED_SHORT;if(n===Gc)return i.INT;if(n===oi)return i.UNSIGNED_INT;if(n===Vn)return i.FLOAT;if(n===ai)return i.HALF_FLOAT;if(n===qf)return i.ALPHA;if(n===$f)return i.RGB;if(n===Nn)return i.RGBA;if(n===$i)return i.DEPTH_COMPONENT;if(n===lr)return i.DEPTH_STENCIL;if(n===Xc)return i.RED;if(n===Yc)return i.RED_INTEGER;if(n===Ur)return i.RG;if(n===qc)return i.RG_INTEGER;if(n===$c)return i.RGBA_INTEGER;if(n===Va||n===Ga||n===Ha||n===Wa)if(o===Mt)if(s=e.get("WEBGL_compressed_texture_s3tc_srgb"),s!==null){if(n===Va)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(n===Ga)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(n===Ha)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(n===Wa)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(s=e.get("WEBGL_compressed_texture_s3tc"),s!==null){if(n===Va)return s.COMPRESSED_RGB_S3TC_DXT1_EXT;if(n===Ga)return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(n===Ha)return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(n===Wa)return s.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(n===Kc||n===Zc||n===Jc||n===jc)if(s=e.get("WEBGL_compressed_texture_pvrtc"),s!==null){if(n===Kc)return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(n===Zc)return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(n===Jc)return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(n===jc)return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(n===Qc||n===eu||n===tu||n===nu||n===iu||n===Xa||n===ru)if(s=e.get("WEBGL_compressed_texture_etc"),s!==null){if(n===Qc||n===eu)return o===Mt?s.COMPRESSED_SRGB8_ETC2:s.COMPRESSED_RGB8_ETC2;if(n===tu)return o===Mt?s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:s.COMPRESSED_RGBA8_ETC2_EAC;if(n===nu)return s.COMPRESSED_R11_EAC;if(n===iu)return s.COMPRESSED_SIGNED_R11_EAC;if(n===Xa)return s.COMPRESSED_RG11_EAC;if(n===ru)return s.COMPRESSED_SIGNED_RG11_EAC}else return null;if(n===su||n===ou||n===au||n===lu||n===cu||n===uu||n===hu||n===fu||n===du||n===pu||n===mu||n===gu||n===xu||n===bu)if(s=e.get("WEBGL_compressed_texture_astc"),s!==null){if(n===su)return o===Mt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:s.COMPRESSED_RGBA_ASTC_4x4_KHR;if(n===ou)return o===Mt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:s.COMPRESSED_RGBA_ASTC_5x4_KHR;if(n===au)return o===Mt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:s.COMPRESSED_RGBA_ASTC_5x5_KHR;if(n===lu)return o===Mt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:s.COMPRESSED_RGBA_ASTC_6x5_KHR;if(n===cu)return o===Mt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:s.COMPRESSED_RGBA_ASTC_6x6_KHR;if(n===uu)return o===Mt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:s.COMPRESSED_RGBA_ASTC_8x5_KHR;if(n===hu)return o===Mt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:s.COMPRESSED_RGBA_ASTC_8x6_KHR;if(n===fu)return o===Mt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:s.COMPRESSED_RGBA_ASTC_8x8_KHR;if(n===du)return o===Mt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:s.COMPRESSED_RGBA_ASTC_10x5_KHR;if(n===pu)return o===Mt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:s.COMPRESSED_RGBA_ASTC_10x6_KHR;if(n===mu)return o===Mt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:s.COMPRESSED_RGBA_ASTC_10x8_KHR;if(n===gu)return o===Mt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:s.COMPRESSED_RGBA_ASTC_10x10_KHR;if(n===xu)return o===Mt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:s.COMPRESSED_RGBA_ASTC_12x10_KHR;if(n===bu)return o===Mt?s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:s.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(n===yu||n===_u||n===vu)if(s=e.get("EXT_texture_compression_bptc"),s!==null){if(n===yu)return o===Mt?s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:s.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(n===_u)return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(n===vu)return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(n===Mu||n===Su||n===Ya||n===wu)if(s=e.get("EXT_texture_compression_rgtc"),s!==null){if(n===Mu)return s.COMPRESSED_RED_RGTC1_EXT;if(n===Su)return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(n===Ya)return s.COMPRESSED_RED_GREEN_RGTC2_EXT;if(n===wu)return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return n===bs?i.UNSIGNED_INT_24_8:i[n]!==void 0?i[n]:null}return{convert:t}}var hE=`
|
|
void main() {
|
|
|
|
gl_Position = vec4( position, 1.0 );
|
|
|
|
}`,fE=`
|
|
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;
|
|
|
|
}
|
|
|
|
}`,Sd=class{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t){if(this.texture===null){let n=new Sa(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 Mi({vertexShader:hE,fragmentShader:fE,uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new we(new sn(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}},wd=class extends yi{constructor(e,t){super();let n=this,r=null,s=1,o=null,a="local-floor",l=1,c=null,u=null,h=null,f=null,d=null,p=null,x=typeof XRWebGLBinding<"u",g=new Sd,m={},b=t.getContextAttributes(),v=null,y=null,M=[],S=[],_=new De,w=null,R=null,A=new Jt;A.viewport=new _t;let C=new Jt;C.viewport=new _t;let O=[A,C],D=new Uc,P=null,I=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(Y){let Q=M[Y];return Q===void 0&&(Q=new uo,M[Y]=Q),Q.getTargetRaySpace()},this.getControllerGrip=function(Y){let Q=M[Y];return Q===void 0&&(Q=new uo,M[Y]=Q),Q.getGripSpace()},this.getHand=function(Y){let Q=M[Y];return Q===void 0&&(Q=new uo,M[Y]=Q),Q.getHandSpace()};function N(Y){let Q=S.indexOf(Y.inputSource);if(Q===-1)return;let se=M[Q];se!==void 0&&(se.update(Y.inputSource,Y.frame,c||o),se.dispatchEvent({type:Y.type,data:Y.inputSource}))}function F(){r.removeEventListener("select",N),r.removeEventListener("selectstart",N),r.removeEventListener("selectend",N),r.removeEventListener("squeeze",N),r.removeEventListener("squeezestart",N),r.removeEventListener("squeezeend",N),r.removeEventListener("end",F),r.removeEventListener("inputsourceschange",H);for(let Y=0;Y<M.length;Y++){let Q=S[Y];Q!==null&&(S[Y]=null,M[Y].disconnect(Q))}P=null,I=null,g.reset();for(let Y in m)delete m[Y];if(e.setRenderTarget(v),d=null,f=null,h=null,r=null,y=null,be.stop(),n.isPresenting=!1,e.setPixelRatio(w),e.setSize(_.width,_.height,!1),R!==null){let Y=R.camera;Y.fov=R.fov,Y.zoom=R.zoom,Y.updateProjectionMatrix(),R=null}n.dispatchEvent({type:"sessionend"})}this.setFramebufferScaleFactor=function(Y){s=Y,n.isPresenting===!0&&Le("WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(Y){a=Y,n.isPresenting===!0&&Le("WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return c||o},this.setReferenceSpace=function(Y){c=Y},this.getBaseLayer=function(){return f!==null?f:d},this.getBinding=function(){return h===null&&x&&(h=new XRWebGLBinding(r,t)),h},this.getFrame=function(){return p},this.getSession=function(){return r},this.setSession=async function(Y){if(r=Y,r!==null){if(v=e.getRenderTarget(),r.addEventListener("select",N),r.addEventListener("selectstart",N),r.addEventListener("selectend",N),r.addEventListener("squeeze",N),r.addEventListener("squeezestart",N),r.addEventListener("squeezeend",N),r.addEventListener("end",F),r.addEventListener("inputsourceschange",H),b.xrCompatible!==!0&&await t.makeXRCompatible(),w=e.getPixelRatio(),e.getSize(_),x&&"createProjectionLayer"in XRWebGLBinding.prototype){let se=null,Se=null,le=null;b.depth&&(le=b.stencil?t.DEPTH24_STENCIL8:t.DEPTH_COMPONENT24,se=b.stencil?lr:$i,Se=b.stencil?bs:oi);let Ie={colorFormat:t.RGBA8,depthFormat:le,scaleFactor:s};h=this.getBinding(),f=h.createProjectionLayer(Ie),r.updateRenderState({layers:[f]}),e.setPixelRatio(1),e.setSize(f.textureWidth,f.textureHeight,!1),y=new wn(f.textureWidth,f.textureHeight,{format:Nn,type:On,depthTexture:new er(f.textureWidth,f.textureHeight,Se,void 0,void 0,void 0,void 0,void 0,void 0,se),stencilBuffer:b.stencil,colorSpace:e.outputColorSpace,samples:b.antialias?4:0,resolveDepthBuffer:f.ignoreDepthValues===!1,resolveStencilBuffer:f.ignoreDepthValues===!1,storeMultisampledDepthBuffer:f.ignoreDepthValues===!1,storeMultisampledStencilBuffer:f.ignoreDepthValues===!1})}else{let se={antialias:b.antialias,alpha:!0,depth:b.depth,stencil:b.stencil,framebufferScaleFactor:s};d=new XRWebGLLayer(r,t,se),r.updateRenderState({baseLayer:d}),e.setPixelRatio(1),e.setSize(d.framebufferWidth,d.framebufferHeight,!1),y=new wn(d.framebufferWidth,d.framebufferHeight,{format:Nn,type:On,colorSpace:e.outputColorSpace,stencilBuffer:b.stencil,resolveDepthBuffer:d.ignoreDepthValues===!1,resolveStencilBuffer:d.ignoreDepthValues===!1,storeMultisampledDepthBuffer:d.ignoreDepthValues===!1,storeMultisampledStencilBuffer:d.ignoreDepthValues===!1})}y.isXRRenderTarget=!0,this.setFoveation(l),c=null,o=await r.requestReferenceSpace(a),be.setContext(r),be.start(),n.isPresenting=!0,n.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(r!==null)return r.environmentBlendMode},this.getDepthTexture=function(){return g.getDepthTexture()};function H(Y){for(let Q=0;Q<Y.removed.length;Q++){let se=Y.removed[Q],Se=S.indexOf(se);Se>=0&&(S[Se]=null,M[Se].disconnect(se))}for(let Q=0;Q<Y.added.length;Q++){let se=Y.added[Q],Se=S.indexOf(se);if(Se===-1){for(let Ie=0;Ie<M.length;Ie++)if(Ie>=S.length){S.push(se),Se=Ie;break}else if(S[Ie]===null){S[Ie]=se,Se=Ie;break}if(Se===-1)break}let le=M[Se];le&&le.connect(se)}}function B(Y,Q){Q===null?Y.matrixWorld.copy(Y.matrix):Y.matrixWorld.multiplyMatrices(Q.matrixWorld,Y.matrix),Y.matrixWorldInverse.copy(Y.matrixWorld).invert()}this.updateCamera=function(Y){if(r===null)return;let Q=Y.near,se=Y.far;g.texture!==null&&(g.depthNear>0&&(Q=g.depthNear),g.depthFar>0&&(se=g.depthFar)),D.near=C.near=A.near=Q,D.far=C.far=A.far=se,(P!==D.near||I!==D.far)&&(r.updateRenderState({depthNear:D.near,depthFar:D.far}),P=D.near,I=D.far),D.layers.mask=Y.layers.mask|6,A.layers.mask=D.layers.mask&-5,C.layers.mask=D.layers.mask&-3;let Se=Y.parent,le=D.cameras;B(D,Se);for(let Ie=0;Ie<le.length;Ie++)B(le[Ie],Se);D.projectionMatrix.copy(A.projectionMatrix),D.projectionMatrixInverse.copy(A.projectionMatrixInverse),R===null&&Y.isPerspectiveCamera&&(R={camera:Y,fov:Y.fov,zoom:Y.zoom}),X(Y,D,Se)};function X(Y,Q,se){se===null?Y.matrix.copy(Q.matrixWorld):(Y.matrix.copy(se.matrixWorld),Y.matrix.invert(),Y.matrix.multiply(Q.matrixWorld)),Y.matrix.decompose(Y.position,Y.quaternion,Y.scale),Y.updateMatrixWorld(!0),Y.projectionMatrix.copy(Q.projectionMatrix),Y.projectionMatrixInverse.copy(Q.projectionMatrixInverse),Y.isPerspectiveCamera&&(Y.fov=as*2*Math.atan(1/Y.projectionMatrix.elements[5]),Y.zoom=1)}this.getCamera=function(){return D},this.getFoveation=function(){if(!(f===null&&d===null))return l},this.setFoveation=function(Y){l=Y,f!==null&&(f.fixedFoveation=Y),d!==null&&d.fixedFoveation!==void 0&&(d.fixedFoveation=Y)},this.hasDepthSensing=function(){return g.texture!==null},this.getDepthSensingMesh=function(){return g.getMesh(D)},this.getCameraTexture=function(Y){return m[Y]};let V=null;function re(Y,Q){if(u=Q.getViewerPose(c||o),p=Q,u!==null){let se=u.views;d!==null&&(e.setRenderTargetFramebuffer(y,d.framebuffer),e.setRenderTarget(y));let Se=!1;se.length!==D.cameras.length&&(D.cameras.length=0,Se=!0);for(let Te=0;Te<se.length;Te++){let ht=se[Te],bt=null;if(d!==null)bt=d.getViewport(ht);else{let Yt=h.getViewSubImage(f,ht);bt=Yt.viewport,Te===0&&(e.setRenderTargetTextures(y,Yt.colorTexture,Yt.depthStencilTexture),e.setRenderTarget(y))}let et=O[Te];et===void 0&&(et=new Jt,et.layers.enable(Te),et.viewport=new _t,O[Te]=et),et.matrix.fromArray(ht.transform.matrix),et.matrix.decompose(et.position,et.quaternion,et.scale),et.projectionMatrix.fromArray(ht.projectionMatrix),et.projectionMatrixInverse.copy(et.projectionMatrix).invert(),et.viewport.set(bt.x,bt.y,bt.width,bt.height),Te===0&&(D.matrix.copy(et.matrix),D.matrix.decompose(D.position,D.quaternion,D.scale)),Se===!0&&D.cameras.push(et)}let le=r.enabledFeatures;if(le&&le.includes("depth-sensing")&&r.depthUsage=="gpu-optimized"&&x){h=n.getBinding();let Te=h.getDepthInformation(se[0]);Te&&Te.isValid&&Te.texture&&g.init(Te,r.renderState)}if(le&&le.includes("camera-access")&&x){e.state.unbindTexture(),h=n.getBinding();for(let Te=0;Te<se.length;Te++){let ht=se[Te].camera;if(ht){let bt=m[ht];bt||(bt=new Sa,m[ht]=bt);let et=h.getCameraImage(ht);bt.sourceTexture=et}}}}for(let se=0;se<M.length;se++){let Se=S[se],le=M[se];Se!==null&&le!==void 0&&le.update(Se,Q,c||o)}V&&V(Y,Q),Q.detectedPlanes&&n.dispatchEvent({type:"planesdetected",data:Q}),p=null}let be=new Wx;be.setAnimationLoop(re),this.setAnimationLoop=function(Y){V=Y},this.dispose=function(){}}},dE=new Be,eb=new He;eb.set(-1,0,0,0,1,0,0,0,1);function pE(i,e){function t(g,m){g.matrixAutoUpdate===!0&&g.updateMatrix(),m.value.copy(g.matrix)}function n(g,m){m.color.getRGB(g.fogColor.value,od(i)),m.isFog?(g.fogNear.value=m.near,g.fogFar.value=m.far):m.isFogExp2&&(g.fogDensity.value=m.density)}function r(g,m,b,v,y){m.isNodeMaterial?m.uniformsNeedUpdate=!1:m.isMeshBasicMaterial?s(g,m):m.isMeshLambertMaterial?(s(g,m),m.envMap&&(g.envMapIntensity.value=m.envMapIntensity)):m.isMeshToonMaterial?(s(g,m),h(g,m)):m.isMeshPhongMaterial?(s(g,m),u(g,m),m.envMap&&(g.envMapIntensity.value=m.envMapIntensity)):m.isMeshStandardMaterial?(s(g,m),f(g,m),m.isMeshPhysicalMaterial&&d(g,m,y)):m.isMeshMatcapMaterial?(s(g,m),p(g,m)):m.isMeshDepthMaterial?s(g,m):m.isMeshDistanceMaterial?(s(g,m),x(g,m)):m.isMeshNormalMaterial?s(g,m):m.isLineBasicMaterial?(o(g,m),m.isLineDashedMaterial&&a(g,m)):m.isPointsMaterial?l(g,m,b,v):m.isSpriteMaterial?c(g,m):m.isShadowMaterial?(g.color.value.copy(m.color),g.opacity.value=m.opacity):m.isShaderMaterial&&(m.uniformsNeedUpdate=!1)}function s(g,m){g.opacity.value=m.opacity,m.color&&g.diffuse.value.copy(m.color),m.emissive&&g.emissive.value.copy(m.emissive).multiplyScalar(m.emissiveIntensity),m.map&&(g.map.value=m.map,t(m.map,g.mapTransform)),m.alphaMap&&(g.alphaMap.value=m.alphaMap,t(m.alphaMap,g.alphaMapTransform)),m.bumpMap&&(g.bumpMap.value=m.bumpMap,t(m.bumpMap,g.bumpMapTransform),g.bumpScale.value=m.bumpScale,m.side===un&&(g.bumpScale.value*=-1)),m.normalMap&&(g.normalMap.value=m.normalMap,t(m.normalMap,g.normalMapTransform),g.normalScale.value.copy(m.normalScale),m.side===un&&g.normalScale.value.negate()),m.displacementMap&&(g.displacementMap.value=m.displacementMap,t(m.displacementMap,g.displacementMapTransform),g.displacementScale.value=m.displacementScale,g.displacementBias.value=m.displacementBias),m.emissiveMap&&(g.emissiveMap.value=m.emissiveMap,t(m.emissiveMap,g.emissiveMapTransform)),m.specularMap&&(g.specularMap.value=m.specularMap,t(m.specularMap,g.specularMapTransform)),m.alphaTest>0&&(g.alphaTest.value=m.alphaTest);let b=e.get(m),v=b.envMap,y=b.envMapRotation;v&&(g.envMap.value=v,g.envMapRotation.value.setFromMatrix4(dE.makeRotationFromEuler(y)).transpose(),v.isCubeTexture&&v.isRenderTargetTexture===!1&&g.envMapRotation.value.premultiply(eb),g.reflectivity.value=m.reflectivity,g.ior.value=m.ior,g.refractionRatio.value=m.refractionRatio),m.lightMap&&(g.lightMap.value=m.lightMap,g.lightMapIntensity.value=m.lightMapIntensity,t(m.lightMap,g.lightMapTransform)),m.aoMap&&(g.aoMap.value=m.aoMap,g.aoMapIntensity.value=m.aoMapIntensity,t(m.aoMap,g.aoMapTransform))}function o(g,m){g.diffuse.value.copy(m.color),g.opacity.value=m.opacity,m.map&&(g.map.value=m.map,t(m.map,g.mapTransform))}function a(g,m){g.dashSize.value=m.dashSize,g.totalSize.value=m.dashSize+m.gapSize,g.scale.value=m.scale}function l(g,m,b,v){g.diffuse.value.copy(m.color),g.opacity.value=m.opacity,g.size.value=m.size*b,g.scale.value=v*.5,m.map&&(g.map.value=m.map,t(m.map,g.uvTransform)),m.alphaMap&&(g.alphaMap.value=m.alphaMap,t(m.alphaMap,g.alphaMapTransform)),m.alphaTest>0&&(g.alphaTest.value=m.alphaTest)}function c(g,m){g.diffuse.value.copy(m.color),g.opacity.value=m.opacity,g.rotation.value=m.rotation,m.map&&(g.map.value=m.map,t(m.map,g.mapTransform)),m.alphaMap&&(g.alphaMap.value=m.alphaMap,t(m.alphaMap,g.alphaMapTransform)),m.alphaTest>0&&(g.alphaTest.value=m.alphaTest)}function u(g,m){g.specular.value.copy(m.specular),g.shininess.value=Math.max(m.shininess,1e-4)}function h(g,m){m.gradientMap&&(g.gradientMap.value=m.gradientMap)}function f(g,m){g.metalness.value=m.metalness,m.metalnessMap&&(g.metalnessMap.value=m.metalnessMap,t(m.metalnessMap,g.metalnessMapTransform)),g.roughness.value=m.roughness,m.roughnessMap&&(g.roughnessMap.value=m.roughnessMap,t(m.roughnessMap,g.roughnessMapTransform)),m.envMap&&(g.envMapIntensity.value=m.envMapIntensity)}function d(g,m,b){g.ior.value=m.ior,m.diffuseRoughness>0&&(g.diffuseRoughness.value=m.diffuseRoughness,m.diffuseRoughnessMap&&(g.diffuseRoughnessMap.value=m.diffuseRoughnessMap,t(m.diffuseRoughnessMap,g.diffuseRoughnessMapTransform))),m.sheen>0&&(g.sheenColor.value.copy(m.sheenColor).multiplyScalar(m.sheen),g.sheenRoughness.value=m.sheenRoughness,m.sheenColorMap&&(g.sheenColorMap.value=m.sheenColorMap,t(m.sheenColorMap,g.sheenColorMapTransform)),m.sheenRoughnessMap&&(g.sheenRoughnessMap.value=m.sheenRoughnessMap,t(m.sheenRoughnessMap,g.sheenRoughnessMapTransform))),m.clearcoat>0&&(g.clearcoat.value=m.clearcoat,g.clearcoatRoughness.value=m.clearcoatRoughness,m.clearcoatMap&&(g.clearcoatMap.value=m.clearcoatMap,t(m.clearcoatMap,g.clearcoatMapTransform)),m.clearcoatRoughnessMap&&(g.clearcoatRoughnessMap.value=m.clearcoatRoughnessMap,t(m.clearcoatRoughnessMap,g.clearcoatRoughnessMapTransform)),m.clearcoatNormalMap&&(g.clearcoatNormalMap.value=m.clearcoatNormalMap,t(m.clearcoatNormalMap,g.clearcoatNormalMapTransform),g.clearcoatNormalScale.value.copy(m.clearcoatNormalScale),m.side===un&&g.clearcoatNormalScale.value.negate())),m.dispersion>0&&(g.dispersion.value=m.dispersion),m.retroreflectivity>0&&(g.retroreflectivity.value=m.retroreflectivity),m.iridescence>0&&(g.iridescence.value=m.iridescence,g.iridescenceIOR.value=m.iridescenceIOR,g.iridescenceThicknessMinimum.value=m.iridescenceThicknessMinimum,g.iridescenceThicknessMaximum.value=m.iridescenceThicknessMaximum,m.iridescenceMap&&(g.iridescenceMap.value=m.iridescenceMap,t(m.iridescenceMap,g.iridescenceMapTransform)),m.iridescenceThicknessMap&&(g.iridescenceThicknessMap.value=m.iridescenceThicknessMap,t(m.iridescenceThicknessMap,g.iridescenceThicknessMapTransform))),m.transmission>0&&(g.transmission.value=m.transmission,g.transmissionSamplerMap.value=b.texture,g.transmissionSamplerSize.value.set(b.width,b.height),m.transmissionMap&&(g.transmissionMap.value=m.transmissionMap,t(m.transmissionMap,g.transmissionMapTransform)),g.thickness.value=m.thickness,m.thicknessMap&&(g.thicknessMap.value=m.thicknessMap,t(m.thicknessMap,g.thicknessMapTransform)),g.attenuationDistance.value=m.attenuationDistance,g.attenuationColor.value.copy(m.attenuationColor)),m.anisotropy>0&&(g.anisotropyVector.value.set(m.anisotropy*Math.cos(m.anisotropyRotation),m.anisotropy*Math.sin(m.anisotropyRotation)),m.anisotropyMap&&(g.anisotropyMap.value=m.anisotropyMap,t(m.anisotropyMap,g.anisotropyMapTransform))),g.specularIntensity.value=m.specularIntensity,g.specularColor.value.copy(m.specularColor),m.specularColorMap&&(g.specularColorMap.value=m.specularColorMap,t(m.specularColorMap,g.specularColorMapTransform)),m.specularIntensityMap&&(g.specularIntensityMap.value=m.specularIntensityMap,t(m.specularIntensityMap,g.specularIntensityMapTransform))}function p(g,m){m.matcap&&(g.matcap.value=m.matcap)}function x(g,m){let b=e.get(m).light;g.referencePosition.value.setFromMatrixPosition(b.matrixWorld),g.nearDistance.value=b.shadow.camera.near,g.farDistance.value=b.shadow.camera.far}return{refreshFogUniforms:n,refreshMaterialUniforms:r}}function mE(i,e,t,n){let r={},s={};function o(b,v){let y=v.program;n.uniformBlockBinding(b,y,r[b.id])}function a(b,v){let y=r[b.id];y===void 0&&(p(b),y=l(b),r[b.id]=y,b.addEventListener("dispose",g));let M=v.program;n.updateUBOMapping(b,M);let S=e.render.frame;s[b.id]!==S&&(c(b),s[b.id]=S)}function l(b){let v=i.createBuffer(),y=b.__size,M=b.usage;return i.bindBuffer(i.UNIFORM_BUFFER,v),i.bufferData(i.UNIFORM_BUFFER,y,M),i.bindBuffer(i.UNIFORM_BUFFER,null),v}function c(b){let v=r[b.id],y=b.uniforms,M=b.__cache;i.bindBuffer(i.UNIFORM_BUFFER,v);for(let S=0,_=y.length;S<_;S++){let w=y[S];if(Array.isArray(w))for(let R=0,A=w.length;R<A;R++)u(w[R],S,R,M);else u(w,S,0,M)}i.bindBuffer(i.UNIFORM_BUFFER,null)}function u(b,v,y,M){if(f(b,v,y,M)===!0){let S=b.__offset,_=b.value;if(Array.isArray(_)){let w=0;for(let R=0;R<_.length;R++){let A=_[R],C=x(A,!0);h(A,b.__data,w),w+=C.storage/Float32Array.BYTES_PER_ELEMENT}}else h(_,b.__data,0);i.bufferSubData(i.UNIFORM_BUFFER,S,b.__data)}}function h(b,v,y){typeof b=="number"||typeof b=="boolean"?v[y]=b:b.isMatrix3?(v[y]=b.elements[0],v[y+1]=b.elements[1],v[y+2]=b.elements[2],v[y+3]=0,v[y+4]=b.elements[3],v[y+5]=b.elements[4],v[y+6]=b.elements[5],v[y+7]=0,v[y+8]=b.elements[6],v[y+9]=b.elements[7],v[y+10]=b.elements[8],v[y+11]=0):ArrayBuffer.isView(b)?v.set(b.subarray(0,v.length-y),y):b.toArray(v,y)}function f(b,v,y,M){let S=b.value,_=v+"_"+y;if(Array.isArray(S)){M[_]===void 0&&(M[_]=[]);let w=M[_],R=!1;for(let A=0;A<S.length;A++)d(S[A],w,A)===!0&&(R=!0);return R}return d(S,M,_)}function d(b,v,y){if(v[y]===void 0)return typeof b=="number"||typeof b=="boolean"?v[y]=b:ArrayBuffer.isView(b)?v[y]=b.slice():v[y]=b.clone(),!0;{let M=v[y];if(typeof b=="number"||typeof b=="boolean"){if(M!==b)return v[y]=b,!0}else{if(ArrayBuffer.isView(b))return!0;if(M.equals(b)===!1)return M.copy(b),!0}}return!1}function p(b){let v=b.uniforms,y=0,M=16;for(let _=0,w=v.length;_<w;_++){let R=Array.isArray(v[_])?v[_]:[v[_]];for(let A=0,C=R.length;A<C;A++){let O=R[A],D=Array.isArray(O.value)?O.value:[O.value],P=Array.isArray(v[_])||Array.isArray(O.value),I=y;for(let F=0,H=D.length;F<H;F++){let B=D[F],X=x(B,P),V=y%M,re=V%X.boundary,be=V+re;y+=re,be!==0&&M-be<X.storage&&(y+=M-be),F===0&&(I=y),y+=X.storage}let N=O.type==="int"?Int32Array:O.type==="uint"?Uint32Array:Float32Array;O.__data=new N((y-I)/Float32Array.BYTES_PER_ELEMENT),O.__offset=I}}let S=y%M;return S>0&&(y+=M-S),b.__size=y,b.__cache={},this}function x(b,v){let y={boundary:0,storage:0};return typeof b=="number"||typeof b=="boolean"?(y.boundary=4,y.storage=4):b.isVector2?(y.boundary=8,y.storage=8):b.isVector3||b.isColor?(y.boundary=16,y.storage=12):b.isVector4?(y.boundary=16,y.storage=16):b.isMatrix3?(y.boundary=16,y.storage=48):b.isMatrix4?(y.boundary=16,y.storage=64):b.isTexture?Le("WebGLRenderer: Texture samplers can not be part of an uniforms group."):ArrayBuffer.isView(b)?(y.boundary=16,y.storage=b.byteLength):Le("WebGLRenderer: Unsupported uniform value type.",b),v===!0&&(y.boundary=16,y.storage=Math.ceil(y.storage/16)*16),y}function g(b){let v=b.target;v.removeEventListener("dispose",g),i.deleteBuffer(r[v.id]),delete r[v.id],delete s[v.id]}function m(){for(let b in r)i.deleteBuffer(r[b]);r={},s={}}return{bind:o,update:a,dispose:m}}var gE=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]),Ci=null;function xE(){return Ci===null&&(Ci=new fo(gE,16,16,Ur,ai),Ci.name="DFG_LUT",Ci.minFilter=Ht,Ci.magFilter=Ht,Ci.wrapS=ln,Ci.wrapT=ln,Ci.generateMipmaps=!1,Ci.needsUpdate=!0),Ci}var kr=class{constructor(e={}){let{canvas:t=ux(),context:n=null,depth:r=!0,stencil:s=!1,alpha:o=!1,antialias:a=!1,premultipliedAlpha:l=!0,preserveDrawingBuffer:c=!1,powerPreference:u="default",failIfMajorPerformanceCaveat:h=!1,reversedDepthBuffer:f=!1,outputBufferType:d=On}=e;this.isWebGLRenderer=!0;let p;if(n!==null){if(typeof WebGLRenderingContext<"u"&&n instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");p=n.getContextAttributes().alpha}else p=o;let x=d,g=new Set([$c,qc,Yc]),m=new Set([On,oi,vo,bs,Hc,Wc]),b=new Uint32Array(4),v=new Int32Array(4),y={textures:[],min:[],max:[],resolution:[]},M=null,S=null,_=[],w=[],R=null;this.domElement=t,this.debug={checkShaderErrors:!0,diagnostics:{keywords:!1},onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=Ei,this.toneMappingExposure=1,this.transmissionResolutionScale=1;let A=this,C=!1,O=null,D=null,P=null,I=null;this._outputColorSpace=ft;let N=0,F=0,H=null,B=-1,X=null,V=new _t,re=new _t,be=null,Y=new W(0),Q=0,se=t.width,Se=t.height,le=1,Ie=null,st=null,Te=new _t(0,0,se,Se),ht=new _t(0,0,se,Se),bt=!1,et=new Ir,Yt=new wc,kt=!1,on=!1,Ot=new Be,gi=new U,en=new _t,Hn={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0},Wn=!1;function Xn(){return H===null?le:1}let G=n;function Yn(E,z){return t.getContext(E,z)}let Pt,It,ye,Zt,ze,We,L,T,$,oe,ie,ue,ge,ee,te,fe,k,ne,j,de,ce,he,Oe;try{let E={alpha:!0,depth:r,stencil:s,antialias:a,premultipliedAlpha:l,preserveDrawingBuffer:c,powerPreference:u,failIfMajorPerformanceCaveat:h};if("setAttribute"in t&&t.setAttribute("data-engine",`three.js r${"187"}`),t.addEventListener("webglcontextlost",Ne,!1),t.addEventListener("webglcontextrestored",Ze,!1),t.addEventListener("webglcontextcreationerror",_e,!1),G===null){let z="webgl2";if(G=Yn(z,E),G===null)throw Yn(z)?new Error("THREE.WebGLRenderer: Error creating WebGL context with your selected attributes."):new Error("THREE.WebGLRenderer: Error creating WebGL context.")}je()}catch(E){throw t.removeEventListener("webglcontextlost",Ne,!1),t.removeEventListener("webglcontextrestored",Ze,!1),t.removeEventListener("webglcontextcreationerror",_e,!1),Ge("WebGLRenderer: "+E.message),E}function je(){Pt=new RT(G),Pt.init(),ce=new uE(G,Pt),It=new xT(G,Pt,e,ce),ye=new lE(G,Pt),It.reversedDepthBuffer&&f&&ye.buffers.depth.setReversed(!0),D=G.createFramebuffer(),P=G.createFramebuffer(),I=G.createFramebuffer(),Zt=new IT(G),ze=new $A,We=new cE(G,Pt,ye,ze,It,ce,Zt),L=new ET(A),T=new FS(G),he=new mT(G,T),$=new CT(G,T,Zt,he),oe=new FT(G,$,T,he,Zt),ne=new LT(G,It,We),te=new bT(ze),ie=new qA(A,L,Pt,It,he,te),ue=new pE(A,ze),ge=new ZA,ee=new nE(Pt),k=new pT(A,L,ye,oe,p,l),fe=new aE(A,oe,It),Oe=new mE(G,Zt,It,ye),j=new gT(G,Pt,Zt),de=new PT(G,Pt,Zt),Zt.programs=ie.programs,A.capabilities=It,A.extensions=Pt,A.properties=ze,A.renderLists=ge,A.shadowMap=fe,A.state=ye,A.info=Zt}x!==On&&(R=new NT(x,t.width,t.height,a,r,s));let ae=new wd(A,G);this.xr=ae,this.getContext=function(){return G},this.getContextAttributes=function(){return G.getContextAttributes()},this.forceContextLoss=function(){let E=Pt.get("WEBGL_lose_context");E&&E.loseContext()},this.forceContextRestore=function(){let E=Pt.get("WEBGL_lose_context");E&&E.restoreContext()},this.getPixelRatio=function(){return le},this.setPixelRatio=function(E){E!==void 0&&(le=E,this.setSize(se,Se,!1))},this.getSize=function(E){return E.set(se,Se)},this.setSize=function(E,z,J=!0){if(ae.isPresenting){Le("WebGLRenderer: Can't change size while VR device is presenting.");return}se=E,Se=z,t.width=Math.floor(E*le),t.height=Math.floor(z*le),J===!0&&(t.style.width=E+"px",t.style.height=z+"px"),R!==null&&R.setSize(t.width,t.height),this.setViewport(0,0,E,z)},this.getDrawingBufferSize=function(E){return E.set(se*le,Se*le).floor()},this.setDrawingBufferSize=function(E,z,J){se=E,Se=z,le=J,t.width=Math.floor(E*J),t.height=Math.floor(z*J),this.setViewport(0,0,E,z)},this.setEffects=function(E){if(x===On){Ge("WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.");return}if(E){for(let z=0;z<E.length;z++)if(E[z].isOutputPass===!0){Le("WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.");break}}R.setEffects(E||[])},this.getCurrentViewport=function(E){return E.copy(V)},this.getViewport=function(E){return E.copy(Te)},this.setViewport=function(E,z,J,q){E.isVector4?Te.set(E.x,E.y,E.z,E.w):Te.set(E,z,J,q),ye.viewport(V.copy(Te).multiplyScalar(Xn()).round())},this.getScissor=function(E){return E.copy(ht)},this.setScissor=function(E,z,J,q){E.isVector4?ht.set(E.x,E.y,E.z,E.w):ht.set(E,z,J,q),ye.scissor(re.copy(ht).multiplyScalar(Xn()).round())},this.getScissorTest=function(){return bt},this.setScissorTest=function(E){ye.setScissorTest(bt=E)},this.setOpaqueSort=function(E){Ie=E},this.setTransparentSort=function(E){st=E},this.getClearColor=function(E){return E.copy(k.getClearColor())},this.setClearColor=function(){k.setClearColor(...arguments)},this.getClearAlpha=function(){return k.getClearAlpha()},this.setClearAlpha=function(){k.setClearAlpha(...arguments)},this.clear=function(E=!0,z=!0,J=!0){let q=0;if(E){let K=!1;if(H!==null){let xe=H.texture.format;K=g.has(xe)}if(K){let xe=H.texture.type,Ae=m.has(xe),me=k.getClearColor(),Me=k.getClearAlpha(),Ce=me.r,Ye=me.g,ot=me.b;Ae?(b[0]=Ce,b[1]=Ye,b[2]=ot,b[3]=Me,G.clearBufferuiv(G.COLOR,0,b)):(v[0]=Ce,v[1]=Ye,v[2]=ot,v[3]=Me,G.clearBufferiv(G.COLOR,0,v))}else q|=G.COLOR_BUFFER_BIT}z&&(q|=G.DEPTH_BUFFER_BIT,this.state.buffers.depth.setMask(!0)),J&&(q|=G.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),q!==0&&G.clear(q)},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.setNodesHandler=function(E){E.setRenderer(this),O=E},this.dispose=function(){t.removeEventListener("webglcontextlost",Ne,!1),t.removeEventListener("webglcontextrestored",Ze,!1),t.removeEventListener("webglcontextcreationerror",_e,!1),k.dispose(),ge.dispose(),ee.dispose(),We.dispose(),ze.dispose(),L.dispose(),oe.dispose(),$.dispose(),he.dispose(),Oe.dispose(),ie.dispose(),ae.dispose(),ae.removeEventListener("sessionstart",n0),ae.removeEventListener("sessionend",i0),$r.stop()};function Ne(E){E.preventDefault(),ma("WebGLRenderer: Context Lost."),C=!0}function Ze(){ma("WebGLRenderer: Context Restored."),C=!1;let E=Zt.autoReset,z=fe.enabled,J=fe.autoUpdate,q=fe.needsUpdate,K=fe.type;je(),Zt.autoReset=E,fe.enabled=z,fe.autoUpdate=J,fe.needsUpdate=q,fe.type=K}function _e(E){Ge("WebGLRenderer: A WebGL context could not be created. Reason: ",E.statusMessage)}function St(E){let z=E.target;z.removeEventListener("dispose",St),tn(z)}function tn(E){br(E),ze.remove(E)}function br(E){let z=ze.get(E).programs;z!==void 0&&(z.forEach(function(J){ie.releaseProgram(J)}),E.isShaderMaterial&&ie.releaseShaderCache(E))}this.renderBufferDirect=function(E,z,J,q,K,xe){z===null&&(z=Hn);let Ae=K.isMesh&&K.matrixWorld.determinantAffine()<0,me=jM(E,z,J,q,K);ye.setMaterial(q,Ae);let Me=J.index,Ce=1;if(q.wireframe===!0){if(Me=$.getWireframeAttribute(J),Me===void 0)return;Ce=2}let Ye=J.drawRange,ot=J.attributes.position,Ee=Ye.start*Ce,at=(Ye.start+Ye.count)*Ce;xe!==null&&(Ee=Math.max(Ee,xe.start*Ce),at=Math.min(at,(xe.start+xe.count)*Ce)),Me!==null?(Ee=Math.max(Ee,0),at=Math.min(at,Me.count)):ot!=null&&(Ee=Math.max(Ee,0),at=Math.min(at,ot.count));let qt=at-Ee;if(qt<0||qt===1/0)return;he.setup(K,q,me,J,Me);let Rt,At=j;if(Me!==null&&(Rt=T.get(Me),At=de,At.setIndex(Rt)),K.isMesh)q.wireframe===!0?(ye.setLineWidth(q.wireframeLinewidth*Xn()),At.setMode(G.LINES)):At.setMode(G.TRIANGLES);else if(K.isLine){let hn=q.linewidth;hn===void 0&&(hn=1),ye.setLineWidth(hn*Xn()),K.isLineSegments?At.setMode(G.LINES):K.isLineLoop?At.setMode(G.LINE_LOOP):At.setMode(G.LINE_STRIP)}else K.isPoints?At.setMode(G.POINTS):K.isSprite&&At.setMode(G.TRIANGLES);if(K.isBatchedMesh)if(Pt.get("WEBGL_multi_draw"))At.renderMultiDraw(K._multiDrawStarts,K._multiDrawCounts,K._multiDrawCount);else{let hn=K._multiDrawStarts,Re=K._multiDrawCounts,_n=K._multiDrawCount,yt=Me?T.get(Me).bytesPerElement:1,Kr=ze.get(q).currentProgram.getUniforms();for(let fn=0;fn<_n;fn++)Kr.setValue(G,"_gl_DrawID",fn),At.render(hn[fn]/yt,Re[fn])}else if(K.isInstancedMesh)At.renderInstances(Ee,qt,K.count);else if(J.isInstancedBufferGeometry){let hn=J._maxInstanceCount!==void 0?J._maxInstanceCount:1/0,Re=Math.min(J.instanceCount,hn);At.renderInstances(Ee,qt,Re)}else At.render(Ee,qt)};function t0(E,z,J,q){O!==null&&E.isNodeMaterial&&O.setObject(q,E),kt===!0&&te.setState(E,J,!1),E.transparent===!0&&E.side===ut&&E.forceSinglePass===!1?(E.side=un,E.needsUpdate=!0,$o(E,z,q),E.side=Ti,E.needsUpdate=!0,$o(E,z,q),E.side=ut):$o(E,z,q)}this.compile=function(E,z,J=null){J===null&&(J=E),O!==null&&O.renderStart(E,z,J),S=ee.get(J),S.init(z),w.push(S),J.traverseVisible(function(K){K.isLight&&K.layers.test(z.layers)&&(S.pushLight(K),K.castShadow&&S.pushShadow(K))}),E!==J&&E.traverseVisible(function(K){K.isLight&&K.layers.test(z.layers)&&(S.pushLight(K),K.castShadow&&S.pushShadow(K))}),S.setupLights(),O!==null&&O.updateLights(S.state.lightsArray),on=this.localClippingEnabled,kt=te.init(this.clippingPlanes,on),kt===!0&&te.setGlobalState(this.clippingPlanes,z),O!==null&&fe.render(S.state.shadowsArray,J,z);let q=new Set;return E.traverse(function(K){if(!(K.isMesh||K.isPoints||K.isLine||K.isSprite))return;let xe=K.material;if(xe)if(Array.isArray(xe))for(let Ae=0;Ae<xe.length;Ae++){let me=xe[Ae];t0(me,J,z,K),q.add(me)}else t0(xe,J,z,K),q.add(xe)}),S=w.pop(),O!==null&&O.renderEnd(),q},this.compileAsync=function(E,z,J=null){let q=this.compile(E,z,J);return new Promise(K=>{function xe(){if(q.forEach(function(Ae){let Me=ze.get(Ae).currentProgram;(Me===void 0||Me.isReady())&&q.delete(Ae)}),q.size===0){K(E);return}setTimeout(xe,10)}Pt.get("KHR_parallel_shader_compile")!==null?xe():setTimeout(xe,10)})};let Bh=null;function ZM(E){Bh&&Bh(E)}function n0(){$r.stop()}function i0(){$r.start()}let $r=new Wx;$r.setAnimationLoop(ZM),typeof self<"u"&&$r.setContext(self),this.setAnimationLoop=function(E){Bh=E,ae.setAnimationLoop(E),E===null?$r.stop():$r.start()},ae.addEventListener("sessionstart",n0),ae.addEventListener("sessionend",i0),this.render=function(E,z){if(z!==void 0&&z.isCamera!==!0){Ge("WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(C===!0)return;O!==null&&O.renderStart(E,z);let J=ae.enabled===!0&&ae.isPresenting===!0,q=R!==null&&(H===null||J)&&R.begin(A,H);if(E.matrixWorldAutoUpdate===!0&&E.updateMatrixWorld(),z.parent===null&&z.matrixWorldAutoUpdate===!0&&z.updateMatrixWorld(),ae.enabled===!0&&ae.isPresenting===!0&&(R===null||R.isCompositing()===!1)&&(ae.cameraAutoUpdate===!0&&ae.updateCamera(z),z=ae.getCamera()),E.isScene===!0&&E.onBeforeRender(A,E,z,H),S=ee.get(E,w.length),S.init(z),S.state.textureUnits=We.getTextureUnits(),w.push(S),Ot.multiplyMatrices(z.projectionMatrix,z.matrixWorldInverse),z.isArrayCamera?Yt.setFromArrayCamera(z):et.setFromProjectionMatrix(Ot,$n,z.reversedDepth),on=this.localClippingEnabled,kt=te.init(this.clippingPlanes,on),M=ge.get(E,_.length),M.init(),_.push(M),this.info.render.frame++,ae.enabled===!0&&ae.isPresenting===!0){let Ae=A.xr.getDepthSensingMesh();Ae!==null&&kh(Ae,z,-1/0,A.sortObjects)}kh(E,z,0,A.sortObjects),M.finish(),O!==null&&O.updateLights(S.state.lightsArray),A.sortObjects===!0&&M.sort(Ie,st),Wn=ae.enabled===!1||ae.isPresenting===!1||ae.hasDepthSensing()===!1,Wn&&k.addToRenderList(M,E),this.info.autoReset===!0&&this.info.reset(),kt===!0&&te.beginShadows();let K=S.state.shadowsArray;if(fe.render(K,E,z),kt===!0&&te.endShadows(),(q&&R.hasRenderPass())===!1){let Ae=M.opaque,me=M.transmissive;if(S.setupLights(),z.isArrayCamera){let Me=z.cameras;if(me.length>0)for(let Ce=0,Ye=Me.length;Ce<Ye;Ce++){let ot=Me[Ce];s0(Ae,me,E,ot)}Wn&&k.render(E);for(let Ce=0,Ye=Me.length;Ce<Ye;Ce++){let ot=Me[Ce];r0(M,E,ot,ot.viewport)}}else me.length>0&&s0(Ae,me,E,z),Wn&&k.render(E),r0(M,E,z)}H!==null&&F===0&&(We.updateMultisampleRenderTarget(H),We.updateRenderTargetMipmap(H)),q&&R.end(A),E.isScene===!0&&E.onAfterRender(A,E,z),he.resetDefaultState(),B=-1,X=null,w.pop(),w.length>0?(S=w[w.length-1],We.setTextureUnits(S.state.textureUnits),kt===!0&&te.setGlobalState(A.clippingPlanes,S.state.camera)):S=null,_.pop(),_.length>0?M=_[_.length-1]:M=null,O!==null&&O.renderEnd()};function kh(E,z,J,q){if(E.visible===!1)return;if(E.layers.test(z.layers)){if(E.isGroup)J=E.renderOrder;else if(E.isLOD)E.autoUpdate===!0&&E.update(z);else if(E.isLight)S.pushLight(E),E.castShadow&&S.pushShadow(E);else if(E.isSprite){let Ae=z.isArrayCamera?Yt:et;if(!E.frustumCulled||E.intersectsFrustum(Ae)){q&&en.setFromMatrixPosition(E.matrixWorld).applyMatrix4(Ot);let me=oe.update(E),Me=E.material;Me.visible&&M.push(E,me,Me,J,en.z,null,z)}}else if(E.isMesh||E.isLine||E.isPoints){let Ae=z.isArrayCamera?Yt:et;if(!E.frustumCulled||E.intersectsFrustum(Ae)){let me=oe.update(E),Me=E.material;if(q&&(E.boundingSphere!==void 0?(E.boundingSphere===null&&E.computeBoundingSphere(),en.copy(E.boundingSphere.center)):(me.boundingSphere===null&&me.computeBoundingSphere(),en.copy(me.boundingSphere.center)),en.applyMatrix4(E.matrixWorld).applyMatrix4(Ot)),Array.isArray(Me)){let Ce=me.groups;for(let Ye=0,ot=Ce.length;Ye<ot;Ye++){let Ee=Ce[Ye],at=Me[Ee.materialIndex];at&&at.visible&&M.push(E,me,at,J,en.z,Ee,z)}}else Me.visible&&M.push(E,me,Me,J,en.z,null,z)}}}let xe=E.children;for(let Ae=0,me=xe.length;Ae<me;Ae++)kh(xe[Ae],z,J,q)}function r0(E,z,J,q){let{opaque:K,transmissive:xe,transparent:Ae}=E;S.setupLightsView(J),kt===!0&&te.setGlobalState(A.clippingPlanes,J),q&&ye.viewport(V.copy(q)),K.length>0&&Pl(K,z,J),xe.length>0&&Pl(xe,z,J),Ae.length>0&&Pl(Ae,z,J),ye.buffers.depth.setTest(!0),ye.buffers.depth.setMask(!0),ye.buffers.color.setMask(!0),ye.setPolygonOffset(!1)}function s0(E,z,J,q){if((J.isScene===!0?J.overrideMaterial:null)!==null)return;if(S.state.transmissionRenderTarget[q.id]===void 0){let Ee=Pt.has("EXT_color_buffer_half_float")||Pt.has("EXT_color_buffer_float");S.state.transmissionRenderTarget[q.id]=new wn(1,1,{generateMipmaps:!0,type:Ee?ai:On,minFilter:Fn,samples:Math.max(4,It.samples),stencilBuffer:s,resolveDepthBuffer:!1,resolveStencilBuffer:!1,storeMultisampledDepthBuffer:!1,storeMultisampledStencilBuffer:!1,colorSpace:tt.workingColorSpace})}let xe=S.state.transmissionRenderTarget[q.id],Ae=q.viewport||V;xe.setSize(Ae.z*A.transmissionResolutionScale,Ae.w*A.transmissionResolutionScale);let me=A.getRenderTarget(),Me=A.getActiveCubeFace(),Ce=A.getActiveMipmapLevel();A.setRenderTarget(xe),A.getClearColor(Y),Q=A.getClearAlpha(),Q<1&&A.setClearColor(16777215,.5),A.clear(),Wn&&k.render(J);let Ye=A.toneMapping;A.toneMapping=Ei;let ot=q.viewport;if(q.viewport!==void 0&&(q.viewport=void 0),S.setupLightsView(q),kt===!0&&te.setGlobalState(A.clippingPlanes,q),Pl(E,J,q),We.updateMultisampleRenderTarget(xe),We.updateRenderTargetMipmap(xe),Pt.has("WEBGL_multisampled_render_to_texture")===!1){let Ee=!1;for(let at=0,qt=z.length;at<qt;at++){let Rt=z[at],{object:At,geometry:hn,material:Re,group:_n}=Rt;if(Re.side===ut&&At.layers.test(q.layers)){let yt=Re.side;Re.side=un,Re.needsUpdate=!0,o0(At,J,q,hn,Re,_n),Re.side=yt,Re.needsUpdate=!0,Ee=!0}}Ee===!0&&(We.updateMultisampleRenderTarget(xe),We.updateRenderTargetMipmap(xe))}A.setRenderTarget(me,Me,Ce),A.setClearColor(Y,Q),ot!==void 0&&(q.viewport=ot),A.toneMapping=Ye}function Pl(E,z,J){let q=z.isScene===!0?z.overrideMaterial:null;for(let K=0,xe=E.length;K<xe;K++){let Ae=E[K],{object:me,geometry:Me,group:Ce}=Ae,Ye=Ae.material;Ye.allowOverride===!0&&q!==null&&(Ye=q),me.layers.test(J.layers)&&o0(me,z,J,Me,Ye,Ce)}}function o0(E,z,J,q,K,xe){O!==null&&K.isNodeMaterial&&O.setObject(E,K),E.onBeforeRender(A,z,J,q,K,xe),E.modelViewMatrix.multiplyMatrices(J.matrixWorldInverse,E.matrixWorld),E.normalMatrix.getNormalMatrix(E.modelViewMatrix),K.onBeforeRender(A,z,J,q,E,xe),K.transparent===!0&&K.side===ut&&K.forceSinglePass===!1?(K.side=un,K.needsUpdate=!0,A.renderBufferDirect(J,z,q,K,E,xe),K.side=Ti,K.needsUpdate=!0,A.renderBufferDirect(J,z,q,K,E,xe),K.side=ut):A.renderBufferDirect(J,z,q,K,E,xe),E.onAfterRender(A,z,J,q,K,xe)}function a0(E){let z=0;for(let J of E)J.texture!==null&&z++;return z}function $o(E,z,J){z.isScene!==!0&&(z=Hn);let q=ze.get(E),K=S.state.lights,xe=S.state.shadowsArray,Ae=K.state.version,me=ie.getParameters(E,K.state,xe,z,J,S.state.lightProbeGridArray),Me=ie.getProgramCacheKey(me),Ce=q.programs;q.environment=E.isMeshStandardMaterial||E.isMeshLambertMaterial||E.isMeshPhongMaterial?z.environment:null,q.fog=z.fog;let Ye=E.isMeshStandardMaterial||E.isMeshLambertMaterial&&!E.envMap||E.isMeshPhongMaterial&&!E.envMap;q.envMap=L.get(E.envMap||q.environment,Ye),q.envMapRotation=q.environment!==null&&E.envMap===null?z.environmentRotation:E.envMapRotation,Ce===void 0&&(E.addEventListener("dispose",St),Ce=new Map,q.programs=Ce,q.programVariants=new Map);let ot=Ce.get(Me);if(ot!==void 0){if(q.currentProgram===ot&&q.lightsStateVersion===Ae)return c0(E,me),ot}else me.uniforms=ie.getUniforms(E),O!==null&&E.isNodeMaterial&&O.build(E,J,me),E.onBeforeCompile(me,A),ot=ie.acquireProgram(me,Me),Ce.set(Me,ot),q.uniforms=me.uniforms;let Ee=q.uniforms;return(!E.isShaderMaterial&&!E.isRawShaderMaterial||E.clipping===!0)&&(Ee.clippingPlanes=te.uniform),c0(E,me),q.needsLights=e1(E),q.lightsStateVersion=Ae,q.needsLights&&(Ee.ambientLightColor.value=K.state.ambient,Ee.lightProbe.value=K.state.probe,Ee.sunLights.value=K.state.sun,Ee.sunLightShadows.value=K.state.sunShadow,Ee.directionalLights.value=K.state.directional,Ee.directionalLightShadows.value=K.state.directionalShadow,Ee.spotLights.value=K.state.spot,Ee.spotLightShadows.value=K.state.spotShadow,Ee.rectAreaLights.value=K.state.rectArea,Ee.ltc_1.value=K.state.rectAreaLTC1,Ee.ltc_2.value=K.state.rectAreaLTC2,Ee.pointLights.value=K.state.point,Ee.pointLightShadows.value=K.state.pointShadow,Ee.hemisphereLights.value=K.state.hemi,Ee.sunShadowMatrix.value=K.state.sunShadowMatrix,Ee.sunShadowCascade.value=K.state.sunShadowCascade,Ee.directionalShadowMatrix.value=K.state.directionalShadowMatrix,Ee.spotLightMatrix.value=K.state.spotLightMatrix,Ee.spotLightMap.value=K.state.spotLightMap,Ee.pointShadowMatrix.value=K.state.pointShadowMatrix),q.numLightProbeGrids=a0(S.state.lightProbeGridArray),q.currentProgram=ot,q.uniformsList=null,ot}function JM(E,z,J,q,K){let xe=ze.get(E),Ae=xe.currentProgram.id+","+q+","+K,me=xe.programVariants.get(Ae);return me===void 0?(me=$o(E,z,J),xe.programVariants.set(Ae,me)):(xe.currentProgram=me,xe.uniformsList=null,xe.outputColorSpace=q,xe.toneMapping=K),me}function l0(E){if(E.uniformsList===null){let z=E.currentProgram.getUniforms();E.uniformsList=So.seqWithValue(z.seq,E.uniforms)}return E.uniformsList}function c0(E,z){let J=ze.get(E);J.outputColorSpace=z.outputColorSpace,J.batching=z.batching,J.batchingColor=z.batchingColor,J.instancing=z.instancing,J.instancingColor=z.instancingColor,J.instancingMorph=z.instancingMorph,J.skinning=z.skinning,J.morphTargets=z.morphTargets,J.morphNormals=z.morphNormals,J.morphColors=z.morphColors,J.morphTargetsCount=z.morphTargetsCount,J.numClippingPlanes=z.numClippingPlanes,J.numIntersection=z.numClipIntersection,J.vertexAlphas=z.vertexAlphas,J.vertexTangents=z.vertexTangents,J.toneMapping=z.toneMapping}function jM(E,z,J,q,K){z.isScene!==!0&&(z=Hn),We.resetTextureUnits();let xe=z.fog,Ae=q.isMeshStandardMaterial||q.isMeshLambertMaterial||q.isMeshPhongMaterial?z.environment:null,me=H===null?A.outputColorSpace:H.isXRRenderTarget===!0?H.texture.colorSpace:tt.workingColorSpace,Me=q.isMeshStandardMaterial||q.isMeshLambertMaterial&&!q.envMap||q.isMeshPhongMaterial&&!q.envMap,Ce=L.get(q.envMap||Ae,Me),Ye=q.vertexColors===!0&&!!J.attributes.color&&J.attributes.color.itemSize===4,ot=!!J.attributes.tangent&&(!!q.normalMap||q.anisotropy>0),Ee=!!J.morphAttributes.position,at=!!J.morphAttributes.normal,qt=!!J.morphAttributes.color,Rt=Ei;q.toneMapped&&(H===null||H.isXRRenderTarget===!0)&&(Rt=A.toneMapping);let At=J.morphAttributes.position||J.morphAttributes.normal||J.morphAttributes.color,hn=At!==void 0?At.length:0,Re=ze.get(q),_n=S.state.lights;if(kt===!0&&(on===!0||E!==X)){let Nt=E===X&&q.id===B;te.setState(q,E,Nt)}let yt=!1,Kr=!1;q.version===Re.__version?Re.needsLights&&Re.lightsStateVersion!==_n.state.version||K.isBatchedMesh&&Re.batching===!1||!K.isBatchedMesh&&Re.batching===!0||K.isBatchedMesh&&Re.batchingColor===!0&&K._colorsTexture===null||K.isBatchedMesh&&Re.batchingColor===!1&&K._colorsTexture!==null||K.isInstancedMesh&&Re.instancing===!1||!K.isInstancedMesh&&Re.instancing===!0||K.isSkinnedMesh&&Re.skinning===!1||!K.isSkinnedMesh&&Re.skinning===!0||K.isInstancedMesh&&Re.instancingColor===!0&&K.instanceColor===null||K.isInstancedMesh&&Re.instancingColor===!1&&K.instanceColor!==null||K.isInstancedMesh&&Re.instancingMorph===!0&&K.morphTexture===null||K.isInstancedMesh&&Re.instancingMorph===!1&&K.morphTexture!==null||Re.envMap!==Ce||q.fog===!0&&Re.fog!==xe||Re.numClippingPlanes!==void 0&&(Re.numClippingPlanes!==te.numPlanes||Re.numIntersection!==te.numIntersection)||Re.vertexAlphas!==Ye||Re.vertexTangents!==ot||Re.morphTargets!==Ee||Re.morphNormals!==at||Re.morphColors!==qt||Re.morphTargetsCount!==hn||Re.numLightProbeGrids!==a0(S.state.lightProbeGridArray)?yt=!0:(Re.outputColorSpace!==me||Re.toneMapping!==Rt)&&(Kr=!0):(yt=!0,Re.__version=q.version);let fn=Re.currentProgram;(yt===!0||Kr===!0)&&(fn=Kr===!0?JM(q,z,K,me,Rt):$o(q,z,K),O&&q.isNodeMaterial&&O.onUpdateProgram(q,fn,Re));let Il=!1,yr=!1,Zr=!1,dt=fn.getUniforms(),an=Re.uniforms;if(ye.useProgram(fn.program)&&(Il=!0,yr=!0,Zr=!0),q.id!==B&&(B=q.id,yr=!0),Il||X!==E){ye.buffers.depth.getReversed()&&E.reversedDepth!==!0&&(E._reversedDepth=!0,E.updateProjectionMatrix()),dt.setValue(G,"projectionMatrix",E.projectionMatrix),dt.setValue(G,"viewMatrix",E.matrixWorldInverse);let nn=dt.map.cameraPosition;nn!==void 0&&nn.setValue(G,gi.setFromMatrixPosition(E.matrixWorld)),It.logarithmicDepthBuffer&&dt.setValue(G,"logDepthBufFC",2/(Math.log(E.far+1)/Math.LN2)),(q.isMeshPhongMaterial||q.isMeshToonMaterial||q.isMeshLambertMaterial||q.isMeshBasicMaterial||q.isMeshStandardMaterial||q.isShaderMaterial)&&dt.setValue(G,"isOrthographic",E.isOrthographicCamera===!0),X!==E&&(X=E,yr=!0,Zr=!0)}if(Re.needsLights&&(_n.state.sunShadowMap.length>0&&dt.setValue(G,"sunShadowMap",_n.state.sunShadowMap,We),_n.state.directionalShadowMap.length>0&&dt.setValue(G,"directionalShadowMap",_n.state.directionalShadowMap,We),_n.state.spotShadowMap.length>0&&dt.setValue(G,"spotShadowMap",_n.state.spotShadowMap,We),_n.state.pointShadowMap.length>0&&dt.setValue(G,"pointShadowMap",_n.state.pointShadowMap,We)),K.isSkinnedMesh){dt.setOptional(G,K,"bindMatrix"),dt.setOptional(G,K,"bindMatrixInverse");let Nt=K.skeleton;Nt&&(Nt.boneTexture===null&&Nt.computeBoneTexture(),dt.setValue(G,"boneTexture",Nt.boneTexture,We))}K.isBatchedMesh&&(dt.setOptional(G,K,"batchingTexture"),dt.setValue(G,"batchingTexture",K._matricesTexture,We),dt.setOptional(G,K,"batchingIdTexture"),dt.setValue(G,"batchingIdTexture",K._indirectTexture,We),dt.setOptional(G,K,"batchingColorTexture"),K._colorsTexture!==null&&dt.setValue(G,"batchingColorTexture",K._colorsTexture,We));let ti=J.morphAttributes;if((ti.position!==void 0||ti.normal!==void 0||ti.color!==void 0)&&ne.update(K,J,fn),(yr||Re.receiveShadow!==K.receiveShadow)&&(Re.receiveShadow=K.receiveShadow,dt.setValue(G,"receiveShadow",K.receiveShadow)),(q.isMeshStandardMaterial||q.isMeshLambertMaterial||q.isMeshPhongMaterial)&&q.envMap===null&&z.environment!==null&&(an.envMapIntensity.value=z.environmentIntensity),an.dfgLUT!==void 0&&(an.dfgLUT.value=xE()),yr){if(dt.setValue(G,"toneMappingExposure",A.toneMappingExposure),Re.needsLights&&QM(an,Zr),xe&&q.fog===!0&&ue.refreshFogUniforms(an,xe),ue.refreshMaterialUniforms(an,q,le,Se,S.state.transmissionRenderTarget[E.id]),Re.needsLights&&Re.numLightProbeGrids>0){let Nt=y,nn=0;for(let ki of S.state.lightProbeGridArray)ki.texture!==null&&(Nt.textures[nn]=ki.texture,Nt.min[nn]=ki.boundingBox.min,Nt.max[nn]=ki.boundingBox.max,Nt.resolution[nn]=ki.resolution,nn++);for(let ki in Nt)Nt[ki].length=nn;an.probesSH.value=Nt.textures,an.probesMin.value=Nt.min,an.probesMax.value=Nt.max,an.probesResolution.value=Nt.resolution}So.upload(G,l0(Re),an,We)}if(q.isShaderMaterial&&q.uniformsNeedUpdate===!0&&(So.upload(G,l0(Re),an,We),q.uniformsNeedUpdate=!1),q.isSpriteMaterial&&dt.setValue(G,"center",K.center),dt.setValue(G,"modelViewMatrix",K.modelViewMatrix),dt.setValue(G,"normalMatrix",K.normalMatrix),dt.setValue(G,"modelMatrix",K.matrixWorld),q.uniformsGroups!==void 0){let Nt=q.uniformsGroups;for(let nn=0,ki=Nt.length;nn<ki;nn++){let h0=Nt[nn];Oe.update(h0,fn),Oe.bind(h0,fn)}}return fn}function QM(E,z){E.ambientLightColor.needsUpdate=z,E.lightProbe.needsUpdate=z,E.sunLights.needsUpdate=z,E.sunLightShadows.needsUpdate=z,E.directionalLights.needsUpdate=z,E.directionalLightShadows.needsUpdate=z,E.pointLights.needsUpdate=z,E.pointLightShadows.needsUpdate=z,E.spotLights.needsUpdate=z,E.spotLightShadows.needsUpdate=z,E.rectAreaLights.needsUpdate=z,E.hemisphereLights.needsUpdate=z}function e1(E){return E.isMeshLambertMaterial||E.isMeshToonMaterial||E.isMeshPhongMaterial||E.isMeshStandardMaterial||E.isShadowMaterial||E.isShaderMaterial&&E.lights===!0}this.getActiveCubeFace=function(){return N},this.getActiveMipmapLevel=function(){return F},this.getRenderTarget=function(){return H},this.setRenderTargetTextures=function(E,z,J){let q=ze.get(E);q.__autoAllocateDepthBuffer=E.resolveDepthBuffer===!1,q.__autoAllocateDepthBuffer===!1&&(q.__useRenderToTexture=!1),ze.get(E.texture).__webglTexture=z,ze.get(E.depthTexture).__webglTexture=q.__autoAllocateDepthBuffer?void 0:J,q.__hasExternalTextures=!0},this.setRenderTargetFramebuffer=function(E,z){let J=ze.get(E);J.__webglFramebuffer=z,J.__useDefaultFramebuffer=z===void 0},this.setRenderTarget=function(E,z=0,J=0){H=E,N=z,F=J;let q=null,K=!1,xe=!1;if(E){let me=ze.get(E);if(me.__useDefaultFramebuffer!==void 0){ye.bindFramebuffer(G.FRAMEBUFFER,me.__webglFramebuffer),V.copy(E.viewport),re.copy(E.scissor),be=E.scissorTest,ye.viewport(V),ye.scissor(re),ye.setScissorTest(be),B=-1;return}else if(me.__webglFramebuffer===void 0)We.setupRenderTarget(E);else if(me.__hasExternalTextures)We.rebindTextures(E,ze.get(E.texture).__webglTexture,ze.get(E.depthTexture).__webglTexture);else if(E.depthBuffer){let Ye=E.depthTexture;if(me.__boundDepthTexture!==Ye){if(Ye!==null&&ze.has(Ye)&&(E.width!==Ye.image.width||E.height!==Ye.image.height))throw new Error("THREE.WebGLRenderer: Attached DepthTexture is initialized to the incorrect size.");We.setupDepthRenderbuffer(E)}}let Me=E.texture;(Me.isData3DTexture||Me.isDataArrayTexture||Me.isCompressedArrayTexture)&&(xe=!0);let Ce=ze.get(E).__webglFramebuffer;E.isWebGLCubeRenderTarget?(Array.isArray(Ce[z])?q=Ce[z][J]:q=Ce[z],K=!0):E.samples>0&&We.useMultisampledRTT(E)===!1?q=ze.get(E).__webglMultisampledFramebuffer:Array.isArray(Ce)?q=Ce[J]:q=Ce,V.copy(E.viewport),re.copy(E.scissor),be=E.scissorTest}else V.copy(Te).multiplyScalar(le).floor(),re.copy(ht).multiplyScalar(le).floor(),be=bt;if(J!==0&&(q=D),ye.bindFramebuffer(G.FRAMEBUFFER,q)&&ye.drawBuffers(E,q),ye.viewport(V),ye.scissor(re),ye.setScissorTest(be),K){let me=ze.get(E.texture);G.framebufferTexture2D(G.FRAMEBUFFER,G.COLOR_ATTACHMENT0,G.TEXTURE_CUBE_MAP_POSITIVE_X+z,me.__webglTexture,J)}else if(xe){let me=z;for(let Me=0;Me<E.textures.length;Me++){let Ce=ze.get(E.textures[Me]);G.framebufferTextureLayer(G.FRAMEBUFFER,G.COLOR_ATTACHMENT0+Me,Ce.__webglTexture,J,me)}}else if(E!==null&&J!==0){let me=ze.get(E.texture);G.framebufferTexture2D(G.FRAMEBUFFER,G.COLOR_ATTACHMENT0,G.TEXTURE_2D,me.__webglTexture,J)}B=-1};function u0(E){let z=ze.get(E);return(z.__readFormat!==E.format||z.__readType!==E.type)&&(z.__readFormat=E.format,z.__readType=E.type,z.__formatReadable=It.textureFormatReadable(E.format),z.__typeReadable=It.textureTypeReadable(E.type)),z}this.readRenderTargetPixels=function(E,z,J,q,K,xe,Ae,me=0){if(!(E&&E.isWebGLRenderTarget)){Ge("WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let Me=ze.get(E).__webglFramebuffer;if(E.isWebGLCubeRenderTarget&&Ae!==void 0&&(Me=Me[Ae],Array.isArray(Me)&&(Me=Me[0])),Me){ye.bindFramebuffer(G.FRAMEBUFFER,Me);try{let Ce=E.textures[me],Ye=Ce.format,ot=Ce.type;E.textures.length>1&&G.readBuffer(G.COLOR_ATTACHMENT0+me);let Ee=u0(Ce);if(Ee.__formatReadable===!1){Ge("WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}if(Ee.__typeReadable===!1){Ge("WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");return}z>=0&&z<=E.width-q&&J>=0&&J<=E.height-K&&G.readPixels(z,J,q,K,ce.convert(Ye),ce.convert(ot),xe)}finally{let Ce=H!==null?ze.get(H).__webglFramebuffer:null;ye.bindFramebuffer(G.FRAMEBUFFER,Ce)}}},this.readRenderTargetPixelsAsync=async function(E,z,J,q,K,xe,Ae,me=0){if(!(E&&E.isWebGLRenderTarget))throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let Me=ze.get(E).__webglFramebuffer;if(E.isWebGLCubeRenderTarget&&Ae!==void 0&&(Me=Me[Ae],Array.isArray(Me)&&(Me=Me[0])),Me)if(z>=0&&z<=E.width-q&&J>=0&&J<=E.height-K){ye.bindFramebuffer(G.FRAMEBUFFER,Me);let Ce=E.textures[me],Ye=Ce.format,ot=Ce.type;E.textures.length>1&&G.readBuffer(G.COLOR_ATTACHMENT0+me);let Ee=u0(Ce);if(Ee.__formatReadable===!1)throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(Ee.__typeReadable===!1)throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");let at=G.createBuffer();G.bindBuffer(G.PIXEL_PACK_BUFFER,at),G.bufferData(G.PIXEL_PACK_BUFFER,xe.byteLength,G.STREAM_READ),G.readPixels(z,J,q,K,ce.convert(Ye),ce.convert(ot),0),G.bindBuffer(G.PIXEL_PACK_BUFFER,null);let qt=H!==null?ze.get(H).__webglFramebuffer:null;ye.bindFramebuffer(G.FRAMEBUFFER,qt);let Rt=G.fenceSync(G.SYNC_GPU_COMMANDS_COMPLETE,0);return G.flush(),await fx(G,Rt,4),G.bindBuffer(G.PIXEL_PACK_BUFFER,at),G.getBufferSubData(G.PIXEL_PACK_BUFFER,0,xe),G.bindBuffer(G.PIXEL_PACK_BUFFER,null),G.deleteBuffer(at),G.deleteSync(Rt),xe}else throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")},this.copyFramebufferToTexture=function(E,z=null,J=0){let q=Math.pow(2,-J),K=Math.floor(E.image.width*q),xe=Math.floor(E.image.height*q),Ae=z!==null?z.x:0,me=z!==null?z.y:0;We.setTexture2D(E,0),G.copyTexSubImage2D(G.TEXTURE_2D,J,0,0,Ae,me,K,xe),ye.unbindTexture()},this.copyTextureToTexture=function(E,z,J=null,q=null,K=0,xe=0){let Ae,me,Me,Ce,Ye,ot,Ee,at,qt,Rt=E.isCompressedTexture?E.mipmaps[xe]:E.image;if(J!==null)Ae=J.max.x-J.min.x,me=J.max.y-J.min.y,Me=J.isBox3?J.max.z-J.min.z:1,Ce=J.min.x,Ye=J.min.y,ot=J.isBox3?J.min.z:0;else{let dt=Math.pow(2,-K);Ae=Math.floor(Rt.width*dt),me=Math.floor(Rt.height*dt),E.isDataArrayTexture?Me=Rt.depth:E.isData3DTexture?Me=Math.floor(Rt.depth*dt):Me=1,Ce=0,Ye=0,ot=0}q!==null?(Ee=q.x,at=q.y,qt=q.z):(Ee=0,at=0,qt=0);let At=ce.convert(z.format),hn=ce.convert(z.type),Re;z.isData3DTexture?(We.setTexture3D(z,0),Re=G.TEXTURE_3D):z.isDataArrayTexture||z.isCompressedArrayTexture?(We.setTexture2DArray(z,0),Re=G.TEXTURE_2D_ARRAY):(We.setTexture2D(z,0),Re=G.TEXTURE_2D),ye.activeTexture(G.TEXTURE0),ye.pixelStorei(G.UNPACK_FLIP_Y_WEBGL,z.flipY),ye.pixelStorei(G.UNPACK_PREMULTIPLY_ALPHA_WEBGL,z.premultiplyAlpha),ye.pixelStorei(G.UNPACK_ALIGNMENT,z.unpackAlignment);let _n=ye.getParameter(G.UNPACK_ROW_LENGTH),yt=ye.getParameter(G.UNPACK_IMAGE_HEIGHT),Kr=ye.getParameter(G.UNPACK_SKIP_PIXELS),fn=ye.getParameter(G.UNPACK_SKIP_ROWS),Il=ye.getParameter(G.UNPACK_SKIP_IMAGES);ye.pixelStorei(G.UNPACK_ROW_LENGTH,Rt.width),ye.pixelStorei(G.UNPACK_IMAGE_HEIGHT,Rt.height),ye.pixelStorei(G.UNPACK_SKIP_PIXELS,Ce),ye.pixelStorei(G.UNPACK_SKIP_ROWS,Ye),ye.pixelStorei(G.UNPACK_SKIP_IMAGES,ot);let yr=E.isDataArrayTexture||E.isData3DTexture,Zr=z.isDataArrayTexture||z.isData3DTexture;if(E.isDepthTexture){let dt=ze.get(E),an=ze.get(z),ti=ze.get(dt.__renderTarget),Nt=ze.get(an.__renderTarget);ye.bindFramebuffer(G.READ_FRAMEBUFFER,ti.__webglFramebuffer),ye.bindFramebuffer(G.DRAW_FRAMEBUFFER,Nt.__webglFramebuffer);for(let nn=0;nn<Me;nn++)yr&&(G.framebufferTextureLayer(G.READ_FRAMEBUFFER,G.COLOR_ATTACHMENT0,ze.get(E).__webglTexture,K,ot+nn),G.framebufferTextureLayer(G.DRAW_FRAMEBUFFER,G.COLOR_ATTACHMENT0,ze.get(z).__webglTexture,xe,qt+nn)),G.blitFramebuffer(Ce,Ye,Ce+Ae,Ye+me,Ee,at,Ee+Ae,at+me,G.DEPTH_BUFFER_BIT,G.NEAREST);ye.bindFramebuffer(G.READ_FRAMEBUFFER,null),ye.bindFramebuffer(G.DRAW_FRAMEBUFFER,null)}else if(K!==0||E.isRenderTargetTexture||ze.has(E)){let dt=ze.get(E),an=ze.get(z);ye.bindFramebuffer(G.READ_FRAMEBUFFER,P),ye.bindFramebuffer(G.DRAW_FRAMEBUFFER,I);for(let ti=0;ti<Me;ti++)yr?G.framebufferTextureLayer(G.READ_FRAMEBUFFER,G.COLOR_ATTACHMENT0,dt.__webglTexture,K,ot+ti):G.framebufferTexture2D(G.READ_FRAMEBUFFER,G.COLOR_ATTACHMENT0,G.TEXTURE_2D,dt.__webglTexture,K),Zr?G.framebufferTextureLayer(G.DRAW_FRAMEBUFFER,G.COLOR_ATTACHMENT0,an.__webglTexture,xe,qt+ti):G.framebufferTexture2D(G.DRAW_FRAMEBUFFER,G.COLOR_ATTACHMENT0,G.TEXTURE_2D,an.__webglTexture,xe),K!==0?G.blitFramebuffer(Ce,Ye,Ce+Ae,Ye+me,Ee,at,Ee+Ae,at+me,G.COLOR_BUFFER_BIT,G.NEAREST):Zr?G.copyTexSubImage3D(Re,xe,Ee,at,qt+ti,Ce,Ye,Ae,me):G.copyTexSubImage2D(Re,xe,Ee,at,Ce,Ye,Ae,me);ye.bindFramebuffer(G.READ_FRAMEBUFFER,null),ye.bindFramebuffer(G.DRAW_FRAMEBUFFER,null)}else Zr?E.isDataTexture||E.isData3DTexture?G.texSubImage3D(Re,xe,Ee,at,qt,Ae,me,Me,At,hn,Rt.data):z.isCompressedArrayTexture?G.compressedTexSubImage3D(Re,xe,Ee,at,qt,Ae,me,Me,At,Rt.data):G.texSubImage3D(Re,xe,Ee,at,qt,Ae,me,Me,At,hn,Rt):E.isDataTexture?G.texSubImage2D(G.TEXTURE_2D,xe,Ee,at,Ae,me,At,hn,Rt.data):E.isCompressedTexture?G.compressedTexSubImage2D(G.TEXTURE_2D,xe,Ee,at,Rt.width,Rt.height,At,Rt.data):G.texSubImage2D(G.TEXTURE_2D,xe,Ee,at,Ae,me,At,hn,Rt);ye.pixelStorei(G.UNPACK_ROW_LENGTH,_n),ye.pixelStorei(G.UNPACK_IMAGE_HEIGHT,yt),ye.pixelStorei(G.UNPACK_SKIP_PIXELS,Kr),ye.pixelStorei(G.UNPACK_SKIP_ROWS,fn),ye.pixelStorei(G.UNPACK_SKIP_IMAGES,Il),xe===0&&z.generateMipmaps===!0&&z.mipmapsAutoUpdate===!0&&G.generateMipmap(Re),ye.unbindTexture()},this.initRenderTarget=function(E){ze.get(E).__webglFramebuffer===void 0&&We.setupRenderTarget(E)},this.initTexture=function(E){E.isCubeTexture?We.setTextureCube(E,0):E.isData3DTexture?We.setTexture3D(E,0):E.isDataArrayTexture||E.isCompressedArrayTexture?We.setTexture2DArray(E,0):We.setTexture2D(E,0),ye.unbindTexture()},this.resetState=function(){N=0,F=0,H=null,ye.reset(),he.reset()},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return $n}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(e){this._outputColorSpace=e;let t=this.getContext();t.drawingBufferColorSpace=tt._getDrawingBufferColorSpace(e),t.unpackColorSpace=tt._getUnpackColorSpace()}};var pt=Math.PI/180;function Ue(i,e){let t=new W(i).multiplyScalar(e);return t.setRGB(Math.min(1,t.r),Math.min(1,t.g),Math.min(1,t.b))}var Ii=Ue(3662079,.95),Pu=Ue(3662079,1),ci=Ue(5995775,.34),Ad=Ue(5995775,.22),Qa=[-.55,.83],el=i=>.5+.5*Math.min(1,Math.max(0,i/1.6));function Ed(i,e){let t=Math.hypot(i,e);return .8+.28*((e/t*Qa[0]-i/t*Qa[1]+1)/2)}var Xe=-1,tl=16,cr=32,Rd=48,Iu=64,Cd=128,zr=(i,e)=>new ke(i,e),lt=class{p=[];c=[];f=[];uv;tile;constructor(e=!1,t=!1){this.uv=e?[]:null,this.tile=t?[]:null}tri(e,t,n,r,s=r,o=r,a,l=Xe,c=[0,1]){this.p.push(...e,...t,...n);for(let u of[r,s,o])this.c.push(u.r,u.g,u.b);this.f.push(l,l,l),this.uv?.push(...a??[.5,.5,.5,.5,.5,.5]),this.tile?.push(...c,...c,...c)}get count(){return this.p.length/9}geometry(){let e=new Fe;return e.setAttribute("position",zr(this.p,3)),e.setAttribute("color",zr(this.c,3)),e.setAttribute("fold",zr(this.f,1)),this.uv&&e.setAttribute("uv",zr(this.uv,2)),this.tile&&e.setAttribute("tile",zr(this.tile,2)),e.computeBoundingSphere(),e}},Wt=class{p=[];c=[];f=[];seg(e,t,n=Ii,r=Xe){this.p.push(...e,...t),this.c.push(n.r,n.g,n.b,n.r,n.g,n.b),this.f.push(r,r)}segSplit(e,t,n,r,s){let[o,a]=e[1]<=t[1]?[e,t]:[t,e];if(a[1]<=r+1e-6||s<0)return this.seg(o,a,n,Xe);if(o[1]>=r-1e-6)return this.seg(o,a,n,s);let l=(r-o[1])/(a[1]-o[1]),c=[o[0]+(a[0]-o[0])*l,r,o[2]+(a[2]-o[2])*l];this.seg(o,c,n,Xe),this.seg(c,a,n,s)}geometry(){let e=new Fe;return e.setAttribute("position",zr(this.p,3)),e.setAttribute("color",zr(this.c,3)),e.setAttribute("fold",zr(this.f,1)),e}};var Pd=(i,e,t)=>i.map((n,r)=>n+(e[r]-n)*t);function tb(i,e,t){let n=(t-i.p[1])/(e.p[1]-i.p[1]);return{p:Pd(i.p,e.p,n),c:Pd(i.c,e.c,n),uv:i.uv&&e.uv?Pd(i.uv,e.uv,n):null,tile:i.tile}}function bE(i,e){return{p:i.p.slice(e*3,e*3+3),c:i.c.slice(e*3,e*3+3),uv:i.uv?i.uv.slice(e*2,e*2+2):null,tile:i.tile?i.tile.slice(e*2,e*2+2):null}}function yE(i,e,t,n){t.forEach((r,s)=>{let o=e*3+s;r.p.forEach((a,l)=>i.p[o*3+l]=a),r.c.forEach((a,l)=>i.c[o*3+l]=a),i.uv&&r.uv&&r.uv.forEach((a,l)=>i.uv[o*2+l]=a),i.tile&&r.tile&&r.tile.forEach((a,l)=>i.tile[o*2+l]=a),i.f[o]=n})}function nb(i,e,t){for(let n of e)i.p.push(...n.p),i.c.push(...n.c),i.f.push(t),i.uv?.push(...n.uv??[.5,.5]),i.tile?.push(...n.tile??[0,1])}function Id(i,e,t,n){let r=i.count;for(let s=e;s<r;s++){let o=[0,1,2].map(v=>bE(i,s*3+v)),a=o.map(v=>v.p[1]>t+1e-6),l=o.map(v=>v.p[1]<t-1e-6);if(!a.some(Boolean))continue;if(!l.some(Boolean)){for(let v=0;v<3;v++)i.f[s*3+v]=n;continue}let c=i.f[s*3],u=a.filter(Boolean).length,h=u===1?a.indexOf(!0):a.indexOf(!1),[f,d,p]=[o[h],o[(h+1)%3],o[(h+2)%3]],x=tb(f,d,t),g=tb(p,f,t),[m,b]=u===1?[n,c]:[c,n];yE(i,s,[f,x,g],m),nb(i,[x,d,p],b),nb(i,[x,p,g],b)}}function Ld(i,e,t,n){let r=i.p.length/6;for(let s=e;s<r;s++){let o=i.p.slice(s*6,s*6+3),a=i.p.slice(s*6+3,s*6+6),[l,c]=o[1]<=a[1]?[o,a]:[a,o];if(c[1]<=t+1e-6)continue;if(l[1]>=t-1e-6){i.f[s*2]=n,i.f[s*2+1]=n;continue}let u=(t-l[1])/(c[1]-l[1]),h=[l[0]+(c[0]-l[0])*u,t,l[2]+(c[2]-l[2])*u],f=i.c.slice(s*6,s*6+3);i.p.splice(s*6,6,...l,...h),i.p.push(...h,...c),i.c.push(...f,...f),i.f.push(n,n)}}var _E=i=>i.reduce((e,t,n)=>e+t[0]*i[(n+1)%i.length][1]-i[(n+1)%i.length][0]*t[1],0),ib=([i,e])=>new De(i,e);function Vr(i,e=[]){return Ea.triangulateShape(i.map(ib),e.map(t=>t.map(ib)))}var Ao=(i,e)=>[i[0]-e[0],i[1]-e[1],i[2]-e[2]],rb=(i,e)=>[i[1]*e[2]-i[2]*e[1],i[2]*e[0]-i[0]*e[2],i[0]*e[1]-i[1]*e[0]],sb=(i,e)=>i[0]*e[0]+i[1]*e[1]+i[2]*e[2],ob=i=>{let e=Math.hypot(i[0],i[1],i[2])||1;return[i[0]/e,i[1]/e,i[2]/e]};function Fd(i,e,t,n,r,s,o){let a=new W(o);for(let f=0;f<4;f++){let[d,p]=[e[f],e[(f+1)%4]],[x,g]=[t[f],t[(f+1)%4]],[m,b]=[p[0]-d[0],p[1]-d[1]],v=Math.hypot(m,b);if(v<1e-6)continue;let y=(x[0]+g[0]-d[0]-p[0])/2*(-b/v)+(x[1]+g[1]-d[1]-p[1])/2*(m/v),M=Math.max(0,Math.min(1,y/Math.max(1e-6,Math.hypot(y,r-n)))),S=Ed(m,b),_=Ue(s,el(n)*S).lerp(a,M),w=Ue(s,el(r)*S).lerp(a,M);i.tri([d[0],n,d[1]],[x[0],r,x[1]],[g[0],r,g[1]],_,w,w),i.tri([d[0],n,d[1]],[g[0],r,g[1]],[p[0],n,p[1]],_,w,_)}let[l,c,u,h]=t;Math.hypot(u[0]-l[0],u[1]-l[1])>1e-4&&(i.tri([l[0],r,l[1]],[u[0],r,u[1]],[c[0],r,c[1]],a),i.tri([l[0],r,l[1]],[h[0],r,h[1]],[u[0],r,u[1]],a))}function Od(i,e,t,n){let r=e.length;if(r<2)return;let s=e[0].length,o=new W(n),a=e.map(h=>[0,1,2].map(f=>h.reduce((d,p)=>d+p[f],0)/s)),l=e.map((h,f)=>h.map((d,p)=>{let x=Ao(e[Math.min(r-1,f+1)][p],e[Math.max(0,f-1)][p]),g=Ao(h[(p+1)%s],h[(p+s-1)%s]),m=ob(rb(x,g));return sb(m,Ao(d,a[f]))<0?m.map(b=>-b):m})),c=(h,f)=>{let d=(f[0]*Qa[0]+f[2]*Qa[1]+1)/2;return Ue(t,el(h[1])*(.8+.28*d)).lerp(o,Math.max(0,f[1])*.9)},u=(h,f,d,p,x,g,m)=>{sb(rb(Ao(f,h),Ao(d,h)),p)>=0?i.tri(h,f,d,x,g,m):i.tri(h,d,f,x,m,g)};for(let h=0;h+1<r;h++)for(let f=0;f<s;f++){let d=(f+1)%s,p=[e[h][f],e[h][d],e[h+1][d],e[h+1][f]],x=[l[h][f],l[h][d],l[h+1][d],l[h+1][f]],[g,m,b,v]=p.map((M,S)=>c(M,x[S])),y=[0,1,2].map(M=>x.reduce((S,_)=>S+_[M],0));u(p[0],p[1],p[2],y,g,m,b),u(p[0],p[2],p[3],y,g,b,v)}for(let[h,f]of[[0,-1],[r-1,1]]){let d=e[h],p=Ao(e[h===0?1:r-2][0],d[0]),x=ob(p.map(m=>m*-f)),g=c(a[h],x);for(let m=0;m<s;m++)u(d[m],d[(m+1)%s],a[h],x,g,g,g)}}function Nd(i,e,t,n,r,s,o,a,l,c){let u=new W(l),h=Array.from({length:c},(d,p)=>{let x=p/c*Math.PI*2;return{y:s+Math.cos(x)*o,across:r+Math.sin(x)*o}}),f=(d,p)=>{let{y:x,across:g}=h[p%c],[m,b]=e(d,g);return[m,x,b]};for(let d=0;d<c;d++){let p=Ue(a,.62+.4*Math.max(0,Math.cos((d+.5)/c*Math.PI*2)));i.tri(f(t,d),f(n,d+1),f(n,d),p),i.tri(f(t,d),f(t,d+1),f(n,d+1),p)}for(let d of[t,n]){let[p,x]=e(d,r);for(let g=0;g<c;g++)i.tri([p,s,x],f(d,g),f(d,g+1),u)}}function Tt(i,e,t,n,r,s,o={}){let a=typeof n=="number"?()=>n:x=>Math.max(t+.002,n(x[0],x[1])),l=o.aoFrom??t,c=o.fold??Xe,u=x=>el(x-l),h=(o.holes??[]).map(x=>_E(x)>0?[...x].reverse():x),f=h.length?[...e,...h.flat()]:e,d=o.topFace!==!1,p=!d&&!o.bottom?[]:Vr(e,h);if(d){let x=new W(s);for(let[g,m,b]of p){let[v,y,M]=[f[g],f[m],f[b]];i.tri([v[0],a(v),v[1]],[M[0],a(M),M[1]],[y[0],a(y),y[1]],x,x,x,void 0,o.topFold??c)}}if(o.bottom){let x=Ue(r,.55);for(let[g,m,b]of p){let[v,y,M]=[f[g],f[m],f[b]];i.tri([v[0],t,v[1]],[y[0],t,y[1]],[M[0],t,M[1]],x,x,x,void 0,c)}}for(let x of[e,...h])x.forEach((g,m)=>{let b=x[(m+1)%x.length];if(Math.hypot(b[0]-g[0],b[1]-g[1])<1e-6||o.skipSide?.(g,b))return;let v=Ed(b[0]-g[0],b[1]-g[1]),[y,M]=[a(g),a(b)],S=o.sideColor?o.sideColor(g,b):r,_=Ue(S,u(t)*v),w=Ue(S,u(y)*v),R=Ue(S,u(M)*v);i.tri([g[0],t,g[1]],[g[0],y,g[1]],[b[0],M,b[1]],_,w,R,void 0,c),i.tri([g[0],t,g[1]],[b[0],M,b[1]],[b[0],t,b[1]],_,R,_,void 0,c)})}var _s=i=>{let e=Math.hypot(i[0],i[1])||1;return[i[0]/e,i[1]/e]};function Gr(i){return i.reduce((t,n,r)=>t+n[0]*i[(r+1)%i.length][1]-i[(r+1)%i.length][0]*n[1],0)>=0?i:[...i].reverse()}function ab(i,e){let t=[];return i.forEach((n,r)=>{let s=i[(r+1)%i.length],[o,a]=[e(n),e(s)];if(o>=0&&t.push(n),o>=0!=a>=0){let l=o/(o-a);t.push([n[0]+(s[0]-n[0])*l,n[1]+(s[1]-n[1])*l])}}),t}function Ud(i,e,t,n,r){let s=a=>(a[0]-e[0])*t[0]+(a[1]-e[1])*t[1],o=i;return Number.isFinite(n)&&(o=ab(o,a=>s(a)-n)),Number.isFinite(r)&&(o=ab(o,a=>r-s(a))),o}var lb=i=>Math.round(i*1e3),nl=i=>`${lb(i[0])},${lb(i[1])}`,Dd=(i,e)=>{let[t,n]=[nl(i),nl(e)];return t<n?`${t}|${n}`:`${n}|${t}`};function vE(i,e){let t=[];return i.forEach((n,r)=>{let s=i[(r+1)%i.length],[o,a]=[s[0]-n[0],s[1]-n[1]],l=o*o+a*a;if(l<1e-8)return;let c=e.map(h=>({t:((h[0]-n[0])*o+(h[1]-n[1])*a)/l,off:Math.abs((h[0]-n[0])*a-(h[1]-n[1])*o)/Math.sqrt(l)})).filter(({t:h,off:f})=>h>1e-6&&h<1-1e-6&&f<1e-4).map(({t:h})=>h).sort((h,f)=>h-f),u=n;for(let h of c){let f=[n[0]+o*h,n[1]+a*h];nl(f)!==nl(u)&&t.push([u,f]),u=f}t.push([u,s])}),t}function Bd(i,e){let t=i.map(l=>({wall:l,edges:vE(l.footprint,e)})),n=new Map;for(let{edges:l}of t)for(let[c,u]of l)n.set(Dd(c,u),(n.get(Dd(c,u))??0)+1);let r=[],s=new Map,o=(l,c,u)=>{let h=nl(l);s.has(h)||s.set(h,{p:l,wall:c,d:[]}),s.get(h).d.push(u)};for(let{wall:l,edges:c}of t)for(let[u,h]of c){let f=Math.hypot(h[0]-u[0],h[1]-u[1]);if(n.get(Dd(u,h))!==1||f<1e-4)continue;r.push({a:u,b:h,wall:l});let d=[(h[0]-u[0])/f,(h[1]-u[1])/f];o(u,l,d),o(h,l,d)}let a=[...s.values()].filter(({d:l})=>l.some(c=>l.some(u=>Math.abs(c[0]*u[1]-c[1]*u[0])>.05))).map(({p:l,wall:c})=>({p:l,wall:c}));return{edges:r,corners:a}}function Eo(i,e){if(e.length===0)return[[i.a,i.b]];let t=_s([i.wall.b[0]-i.wall.a[0],i.wall.b[1]-i.wall.a[1]]),n=_s([i.b[0]-i.a[0],i.b[1]-i.a[1]]);if(Math.abs(t[0]*n[0]+t[1]*n[1])<.99)return[[i.a,i.b]];let r=c=>(c[0]-i.wall.a[0])*t[0]+(c[1]-i.wall.a[1])*t[1],[s,o]=[r(i.a),r(i.b)],a=[[Math.min(s,o),Math.max(s,o)]];for(let c of e)a=a.flatMap(([u,h])=>{if(c.s1<=u||c.s0>=h)return[[u,h]];let f=[];return c.s0>u&&f.push([u,c.s0]),c.s1<h&&f.push([c.s1,h]),f});let l=c=>{let u=(c-s)/(o-s||1);return[i.a[0]+(i.b[0]-i.a[0])*u,i.a[1]+(i.b[1]-i.a[1])*u]};return a.filter(([c,u])=>u-c>1e-4).map(([c,u])=>s<=o?[l(c),l(u)]:[l(u),l(c)])}var cb=["body","wood","fabric","white","metal","dark"];var Pe={body:1516088,bodyTop:1911623,fabric:1713732,fabricTop:2241114,cushion:2373217,wood:1647420,woodTop:2108747,white:1911110,whiteTop:2504542,metal:2767456,dark:725279,glass:1849938,plant:1191982,plantTop:1721664,pot:1910336,accent:2854835},mt=(i,e=i)=>({side:i,top:e}),Z={body:mt(Pe.body,Pe.bodyTop),fabric:mt(Pe.fabric,Pe.fabricTop),cushion:mt(Pe.cushion),cushionSoft:mt(Pe.cushion,Pe.fabricTop),wood:mt(Pe.wood,Pe.woodTop),white:mt(Pe.white,Pe.whiteTop),worktop:mt(Pe.whiteTop),metal:mt(Pe.metal),dark:mt(Pe.dark),darkBody:mt(Pe.dark,Pe.body),glass:mt(Pe.glass),accent:mt(Pe.accent),pot:mt(Pe.pot),plant:mt(Pe.plant,Pe.plantTop),bedding:mt(Pe.white,Pe.whiteTop),pillow:mt(Pe.whiteTop)};var pe=Ue(5995775,.3),Je=Ue(5995775,.17),qe=Ue(3662079,.45);var kd={...Pe},ub=Object.fromEntries(Object.entries(Z).map(([i,e])=>[i,{...e}])),hb="",ME=i=>typeof i=="string"&&/^#[0-9a-f]{6}$/i.test(i)?Number.parseInt(i.slice(1),16):null;function fb(i){let e=Object.fromEntries(cb.map(s=>[s,ME(i?.[s])]).filter(([,s])=>s!==null)),t=JSON.stringify(e);if(t===hb)return!1;hb=t,Object.assign(Pe,kd);for(let[s,o]of Object.entries(ub))Object.assign(Z[s],o);let n=s=>Ue(s,1.25).getHex(),r=(s,o,a,l)=>{let c=e[s];if(c===void 0)return;for(let h of o)Pe[h]=c;for(let h of a)Pe[h]=n(c);let u=new Map([...o.map(h=>[kd[h],c]),...a.map(h=>[kd[h],n(c)])]);for(let h of l){let f=ub[h];Z[h].side=u.get(f.side)??Z[h].side,Z[h].top=u.get(f.top)??Z[h].top}};return r("body",["body"],["bodyTop"],["body","darkBody"]),r("wood",["wood"],["woodTop"],["wood"]),r("fabric",["fabric","cushion"],["fabricTop"],["fabric","cushion","cushionSoft"]),r("white",["white"],["whiteTop"],["white","worktop","bedding","pillow"]),r("metal",["metal"],[],["metal"]),r("dark",["dark"],[],["dark","darkBody"]),!0}function db(i){let e=i(0,0),t=i(1,0),n=i(0,1);return(t[0]-e[0])*(n[1]-e[1])-(t[1]-e[1])*(n[0]-e[0])<0}function vs(i,e){let t=(n,r,s)=>{if(n)for(let o=0;o<s;o++){let[a,l]=[r+s+o,r+2*s+o];[n[a],n[l]]=[n[l],n[a]]}};for(let n=e;n<i.p.length;n+=9){let r=n/9;t(i.p,n,3),t(i.c,n,3),t(i.f,r*3,1),t(i.uv,r*6,2),t(i.tile,r*6,2)}}var Li=class i{mirrored;buf;lines;plan;constructor(e,t,n){this.buf=e,this.lines=t,this.plan=n,this.mirrored=db(n)}turned(e,t,n){let[r,s]=[Math.cos(n*pt),Math.sin(n*pt)];return new i(this.buf,this.lines,(o,a)=>this.plan(e+(o-e)*r-(a-t)*s,t+(o-e)*s+(a-t)*r))}seg(e,t,n,r,s,o,a=pe){this.edge(this.plan(e,n),this.plan(r,o),t,s,a)}edge(e,t,n,r,s){this.lines.seg([e[0],n,e[1]],[t[0],r,t[1]],s,Xe)}block({x:[e,t],y:[n,r],z:[s,o]},a,l=null){if(t-e<1e-4||o-s<1e-4||r-n<1e-4)return;let c=[this.plan(e,s),this.plan(e,o),this.plan(t,o),this.plan(t,s)];Tt(this.buf,Gr(c),n,r,a.side,a.top,{aoFrom:0,bottom:n>.05}),l&&c.forEach((u,h)=>{this.edge(u,c[(h+1)%4],r,r,l),this.edge(u,u,n,r,l)})}prism(e,t,n,r,s=null){if(e.length<3||n-t<1e-4)return;let o=e.map(([a,l])=>this.plan(a,l));Tt(this.buf,Gr(o),t,n,r.side,r.top,{aoFrom:Math.min(0,t),bottom:!0}),s&&o.forEach((a,l)=>this.edge(a,o[(l+1)%o.length],n,n,s))}loft(e,t,n,r,s,o=null){if(r-n<1e-4)return;let a=u=>[this.plan(u[0],u[2]),this.plan(u[0],u[3]),this.plan(u[1],u[3]),this.plan(u[1],u[2])],l=a(e),c=a(t);if(l!==Gr(l)&&(l.reverse(),c.reverse()),Fd(this.buf,l,c,n,r,s.side,s.top),o)for(let u=0;u<4;u++)this.edge(c[u],c[(u+1)%4],r,r,o),this.edge(l[u],c[u],n,r,o)}sweep(e,t,n=16,r=2.6,s=null){if(e.length<2)return;let o=e.map(a=>{let[l,c]=[Math.max(.004,(a.y1-a.y0)/2),Math.max(.004,a.hw)],u=(a.y0+a.y1)/2;return Array.from({length:n},(h,f)=>{let d=f/n*Math.PI*2,[p,x]=[Math.cos(d),Math.sin(d)],[g,m]=this.plan(a.x+c*Math.sign(p)*Math.abs(p)**(2/r),a.z);return[g,u+l*Math.sign(x)*Math.abs(x)**(2/r),m]})});if(Od(this.buf,o,t.side,t.top),s){let a=Math.round(n/4);for(let l=0;l+1<o.length;l++)this.lines.seg(o[l][a],o[l+1][a],s,Xe)}}pad(e,t,n=.03,r=null){let{x:[s,o],y:[a,l],z:[c,u]}=e,h=Math.min(n,(o-s)/2-.005,(u-c)/2-.005,(l-a)/2);if(h<.008)return this.block(e,t,r);let f={side:t.side,top:t.side};this.loft([s+h,o-h,c+h,u-h],[s,o,c,u],a,a+h,f),l-a-2*h>.005&&this.block({x:[s,o],y:[a+h,l-h],z:[c,u]},f,r),this.loft([s,o,c,u],[s+h,o-h,c+h,u-h],l-h,l,t)}lyingCylinder(e,t,n,r,s,o,a,l,c=12,u=null){let h=Math.min(a,s-r)/2;if(h<1e-4||o<1e-4)return;let f=(r+s)/2,[d,p]=e==="x"?[t,n]:[n,t],x=(m,b)=>e==="x"?this.plan(m,b):this.plan(b,m),g=this.buf.p.length;if(Nd(this.buf,x,d-o/2,d+o/2,p,f,h,l.side,l.top,c),this.mirrored&&vs(this.buf,g),!!u)for(let m of[d-o/2,d+o/2])for(let b=0;b<c;b++){let[v,y]=[b/c*Math.PI*2,(b+1)/c*Math.PI*2];this.edge(x(m,p+Math.sin(v)*h),x(m,p+Math.sin(y)*h),f+Math.cos(v)*h,f+Math.cos(y)*h,u)}}cylinder(e,t,n,r,s,o,a=10,l=null){let c=Array.from({length:a},(u,h)=>this.plan(e+Math.cos(h/a*Math.PI*2)*n,t+Math.sin(h/a*Math.PI*2)*n));Tt(this.buf,Gr(c),r,s,o.side,o.top,{aoFrom:0,bottom:r>.05}),l&&c.forEach((u,h)=>this.edge(u,c[(h+1)%a],s,s,l))}ring(e,t,n,r,s=20,o=pe){for(let a=0;a<s;a++){let[l,c]=[a/s*Math.PI*2,(a+1)/s*Math.PI*2];this.seg(e+Math.cos(l)*n,t+Math.sin(l)*n,r,e+Math.cos(c)*n,t+Math.sin(c)*n,r,o)}}};function pb(i,e,t,n,r){let s=Math.min(.14,Math.max(.06,Math.min(t,n)*.15)),o=new W(1-r,1-r,1-r),a=new W(1,1,1),l=.003,c=p=>[e(-t/2-p,-n/2-p),e(t/2+p,-n/2-p),e(t/2+p,n/2+p),e(-t/2-p,n/2+p)],[u,h]=[c(0),c(s)],f=p=>[p[0],l,p[1]],d=i.p.length;i.tri(f(u[0]),f(u[1]),f(u[2]),o),i.tri(f(u[0]),f(u[2]),f(u[3]),o);for(let p=0;p<4;p++){let x=(p+1)%4;i.tri(f(u[p]),f(h[p]),f(h[x]),o,a,a),i.tri(f(u[p]),f(h[x]),f(u[x]),o,a,o)}db(e)&&vs(i,d)}function zd(i,e){if(!i)return null;if(i.startsWith("#"))return Number.parseInt(i.slice(1),16);let t=Pe;return(e?t[`${i}Top`]:void 0)??t[i]??null}function Ms(i,e,t,n,r,s,o,a=null,l=null,c=null){let u=e.colors?.length?(e.colors.find(f=>f.id===l)??e.colors[0]).hex:null,h=jo(e,t,n,r);for(let f of c===null?h:L0(h,c)){if(c===null&&f.move||a&&!a(f))continue;let d=a?{...f,glow:!0,w:f.w+.006/t,d:f.d+.006/n,y:Math.max(0,f.y-.002/r),h:f.h+.004/r}:f,p=d.glow&&o!==null,x=!!(d.paint&&u),g=x?u:d.color,m=p?o:zd(g,!1)??Pe.body,b=p?o:zd(x?void 0:d.top,!1)??zd(g,!0)??Ue(m,1.25).getHex(),v=mt(m,b),[y,M]=[s+d.y*r,s+Math.min(r,(d.y+d.h)*r)],S=d.edges==="glow"?Ii:d.edges==="faint"?Je:d.edges?pe:null,_=d.rot?i.turned(d.x*t,d.z*n,d.rot):i,[w,R]=[d.x*t,d.z*n];if(d.shape==="cyl"&&(d.axis==="x"||d.axis==="z"))_.lyingCylinder(d.axis,w,R,y,M,d.axis==="x"?d.w*t:d.d*n,d.axis==="x"?d.d*n:d.w*t,v,14,S);else if(d.shape==="cyl")_.cylinder(w,R,Math.min(d.w*t,d.d*n)/2,y,M,v,14,S);else if(d.shape==="loft"){let[A,C,O,D]=[d.tx??d.x,d.tz??d.z,d.tw??d.w,d.td??d.d];_.loft([(d.x-d.w/2)*t,(d.x+d.w/2)*t,(d.z-d.d/2)*n,(d.z+d.d/2)*n],[(A-O/2)*t,(A+O/2)*t,(C-D/2)*n,(C+D/2)*n],y,M,v,S)}else if(d.shape==="sweep"){let A=(d.stations??[]).map(([C,O,D,P])=>({x:w,z:C*n,y0:s+O*r,y1:s+D*r,hw:P*t/2}));_.sweep(A,v,d.n??16,d.exp??2.6,S)}else _.block({x:[(d.x-d.w/2)*t,(d.x+d.w/2)*t],y:[y,M],z:[(d.z-d.d/2)*n,(d.z+d.d/2)*n]},v,S)}}function Ss(i){let[e,t]=[Math.cos(i.rotation*pt),Math.sin(i.rotation*pt)],n=i.mirror?-1:1;return(r,s)=>[i.x+n*r*e-s*t,i.z+n*r*t+s*e]}var Vd=i=>[Math.max(.05,i.w),Math.max(.05,i.d),Math.max(.005,i.h)];function il(i,e,t,n,r,s=o=>!!o.glow){Ms(new Li(i,new Wt,Ss(t)),e,...Vd(t),n,r,s)}function Gd(i,e,t,n,r){let s=i.p.length;Ms(new Li(i,new Wt,Ss(t)),e,...Vd(t),n,null,null,t.variant??null,r),t.mirror&&vs(i,s)}function rl(i,e,t,n,r){Ms(new Li(i,new Wt,Ss(t)),e,...Vd(t),n,r)}function mb(i){let e=2166136261;for(let t=0;t<i.length;t++)e=Math.imul(e^i.charCodeAt(t),16777619);return()=>(e=Math.imul(e^e>>>15,2246822507),e=Math.imul(e^e>>>13,3266489909),e^=e>>>16,(e>>>0)/4294967296)}var SE=(i,e,t)=>{let[n,r]=[t[0]-e[0],t[1]-e[1]],s=n*n+r*r||1e-9,o=Math.max(0,Math.min(1,((i[0]-e[0])*n+(i[1]-e[1])*r)/s));return Math.hypot(i[0]-e[0]-n*o,i[1]-e[1]-r*o)};function wE(i,e,t=.25){if(!Ve(e,i.points))return!1;let n=i.points;for(let r=0;r<n.length;r++)if(SE(e,n[r],n[(r+1)%n.length])<t)return!1;return!i.obstacles.some(r=>Ve(e,r))}function TE(i,e,t){let n=i.obstacles.filter(s=>!Ve(e,s)),r=Math.max(1,Math.ceil(Math.hypot(t[0]-e[0],t[1]-e[1])/.1));for(let s=1;s<=r;s++){let o=[e[0]+(t[0]-e[0])*s/r,e[1]+(t[1]-e[1])*s/r];if(n.some(a=>Ve(o,a)))return!1}return!0}function AE(i,e,t){let n=i.points.map(c=>c[0]),r=i.points.map(c=>c[1]),[s,o,a,l]=[Math.min(...n),Math.max(...n),Math.min(...r),Math.max(...r)];for(let c=0;c<24;c++){let u=[s+(o-s)*t(),a+(l-a)*t()];if(Math.hypot(u[0]-e[0],u[1]-e[1])>.6&&wE(i,u)&&TE(i,e,u))return u}return null}function EE(i,e,t,n){if(!i.target){if(i.rest-=t,i.rest>0)return!1;if(i.target=AE(e,i.pos,n),!i.target)return i.rest=2,!1}let[r,s]=[i.target[0]-i.pos[0],i.target[1]-i.pos[1]],o=Math.hypot(r,s),l=Math.atan2(r,s)-i.heading;for(;l>Math.PI;)l-=2*Math.PI;for(;l<-Math.PI;)l+=2*Math.PI;i.heading+=Math.max(-4*t,Math.min(4*t,l));let c=e.speed*t*(Math.abs(l)>1.2?.3:1);return o<=c?(i.pos=[i.target[0],i.target[1]],i.target=null,i.rest=2+n()*6,!0):(i.pos=[i.pos[0]+r/o*c,i.pos[1]+s/o*c],!0)}function gb(i,e,t,n){let r=Math.min(.2,Math.max(0,t));return i.target||(i.rest-=Math.max(0,t)-r),EE(i,e,r,n)}function xb(){let e=navigator.deviceMemory??8,t=navigator.hardwareConcurrency||8;return e<=3||t<=4||/Silk|KF[A-Z]{2,4}\b/.test(navigator.userAgent)}var Lu=class{times=[];settle=30;ratio;lastDown=-1/0;slowAtFloor=0;max;min;constructor(e,t=1){this.max=e,this.min=t,this.ratio=e}get pixelRatio(){return this.ratio}frame(e,t){if(this.settle>0)return this.settle--,null;if(e<=0||e>=100||(this.times.push(e),this.times.length<45))return null;let n=[...this.times].sort((s,o)=>s-o);this.times=[];let r=1e3/n[Math.floor(n.length/2)];return r<26&&this.ratio>this.min+1e-6?(this.ratio=Math.max(this.min,Math.round((this.ratio-.25)*100)/100),this.lastDown=t,this.settle=30,{ratio:this.ratio}):r<16&&this.ratio<=this.min+1e-6?++this.slowAtFloor>=2?{low:!0}:null:(this.slowAtFloor=0,r>55&&this.ratio<this.max-1e-6&&t-this.lastDown>3e4?(this.ratio=Math.min(this.max,Math.round((this.ratio+.25)*100)/100),this.settle=30,{ratio:this.ratio}):null)}};function bb(i){let e=i.length/3,t=new Float32Array(e);for(let n=0;n<e;n++){let r=i[n*3+1];i[n*3]===0&&i[n*3+2]===0&&r>0&&(t[n]=r)}return t}function yb(i,e,t,n){for(let r=t.start*3;r<t.end*3;r++){let s=e[r];s<=0||(i[r*3]=Math.min(1,n[0]*s),i[r*3+1]=Math.min(1,n[1]*s),i[r*3+2]=Math.min(1,n[2]*s))}}var Fu=Math.PI/180,ur=i=>Math.tan(Math.min(80,Math.max(0,i))*Fu);function ws(i){return{x0:Math.min(i.x0,i.x1),x1:Math.max(i.x0,i.x1),z0:Math.min(i.z0,i.z1),z1:Math.max(i.z0,i.z1)}}function _b(i){if(!i.rotation)return null;let e=i.rotation*Fu;return{cx:(i.x0+i.x1)/2,cz:(i.z0+i.z1)/2,c:Math.cos(e),sn:Math.sin(e)}}function vb(i,e){let t=_b(i);if(!t)return e;let[n,r]=[e[0]-t.cx,e[1]-t.cz];return[t.cx+n*t.c-r*t.sn,t.cz+n*t.sn+r*t.c]}function Hd(i,e,t){let n=_b(i);if(!n)return[e,t];let[r,s]=[e-n.cx,t-n.cz];return[n.cx+r*n.c+s*n.sn,n.cz-r*n.sn+s*n.c]}function Mb(i,e=0){let{x0:t,x1:n,z0:r,z1:s}=ws(i);return[[t-e,r-e],[n+e,r-e],[n+e,s+e],[t-e,s+e]].map(o=>vb(i,o))}function Dn(i){let{x0:e,x1:t,z0:n,z1:r}=ws(i),s=o=>vb(i,o);return i.axis==="x"?{u0:e,u1:t,w:r-n,at:(o,a)=>s([o,i.flip?r-a:n+a])}:{u0:n,u1:r,w:t-e,at:(o,a)=>s([i.flip?t-a:e+a,o])}}function Fi(i,e,t){let{x0:n,x1:r,z0:s,z1:o}=ws(i),[a,l]=Hd(i,e,t);return i.axis==="x"?[a,i.flip?o-l:l-s]:[l,i.flip?r-a:a-n]}var sl=Math.tan(30*Fu);function ol(i,e,t,n,r){let s=Math.min(i*.3,n>1e-6?2.4/n:i*.3),o=Math.min(i*.3,r>1e-6?2.4/r:i*.3),a=e+s*n,l=t+o*r,c=Math.min(i-o,Math.max(s,(l-a+sl*(i-o+s))/(2*sl))),u=a+(c-s)*sl;return{vla:s,vlb:o,yla:a,ylb:l,vr:c,rh:u,y:f=>f<=s?e+f*n:f<=c?a+(f-s)*sl:f<=i-o?l+(i-o-f)*sl:t+(i-f)*r}}function En(i){let e=Dn(i).w,[t,n]=[i.eave_a,i.eave_b],[r,s]=[ur(i.pitch_a),ur(i.pitch_b)];switch(i.shape){case"flat":case"parapet":return{vr:e/2,rh:t,y:()=>t};case"pent":return{vr:e,rh:t+e*r,y:o=>t+o*r};case"mansard":{let o=ol(e,t,n,r,s);return{vr:o.vr,rh:o.rh,y:o.y}}default:{let o=r+s>1e-6?Math.min(e,Math.max(0,(n-t+e*s)/(r+s))):e/2;return{vr:o,rh:t+o*r,y:a=>a<=o?t+a*r:n+(e-a)*s}}}}var Wd=i=>En(i).rh;var xt=(i,e)=>[i[0]-e[0],i[1]-e[1]],Oi=(i,e)=>[i[0]+e[0],i[1]+e[1]],ui=(i,e)=>[i[0]*e,i[1]*e],yn=(i,e)=>i[0]*e[0]+i[1]*e[1],Rn=(i,e)=>i[0]*e[1]-i[1]*e[0],Kn=i=>Math.hypot(i[0],i[1]),hi=i=>{let e=Kn(i)||1;return[i[0]/e,i[1]/e]},Xd=i=>[-i[1],i[0]],Yd=i=>[i[1],-i[0]];function Sb(i){let e=i.heightEnd!==void 0;return{...i,a:i.b,b:i.a,left:i.right,right:i.left,roomLeft:i.roomRight,roomRight:i.roomLeft,height:e?i.heightEnd:i.height,heightEnd:e?i.height:void 0}}function RE(i,e){let t=i.map(n=>({...n}));for(let n of e){let r=t.find(s=>s.room_id===n.room_id&&s.edge===n.edge&&(Math.abs(s.t1-n.t0)<1e-6||Math.abs(n.t1-s.t0)<1e-6));r?(r.t0=Math.min(r.t0,n.t0),r.t1=Math.max(r.t1,n.t1)):t.push({...n})}return t}function CE(i,e,t){if(i.a===e.b)return!1;let n=hi(xt(t[i.b],t[i.a])),r=hi(xt(t[e.b],t[e.a]));return Math.abs(Rn(n,r))>1e-6||yn(n,r)<=0||i.free||e.free||i.heightEnd!==void 0||e.heightEnd!==void 0?!1:i.height===e.height&&i.exterior===e.exterior&&i.roomLeft===e.roomLeft&&i.roomRight===e.roomRight&&Math.abs(i.left-e.left)<=1e-9&&Math.abs(i.right-e.right)<=1e-9}function wb(i,e,t=new Set){let n=i.slice();for(;;){let r=new Map;n.forEach((o,a)=>{for(let l of[o.a,o.b])r.set(l,[...r.get(l)??[],a])});let s=null;for(let[o,a]of r){if(a.length!==2||t.has(o))continue;let l=n[a[0]].b===o?n[a[0]]:Sb(n[a[0]]),c=n[a[1]].a===o?n[a[1]]:Sb(n[a[1]]);if(!CE(l,c,e))continue;let u={...l,b:c.b,sources:RE(l.sources,c.sources)};s=[...n.filter((h,f)=>f!==a[0]&&f!==a[1]),u];break}if(!s)return n;n=s}}function Tb(i,e){let t=new Map;i.forEach((r,s)=>{let o=hi(xt(e[r.b],e[r.a])),a=[[r.a,{key:`${s}:a`,d:o,left:r.left,right:r.right,angle:Math.atan2(o[1],o[0])}],[r.b,{key:`${s}:b`,d:ui(o,-1),left:r.right,right:r.left,angle:Math.atan2(-o[1],-o[0])}]];for(let[l,c]of a)t.set(l,[...t.get(l)??[],c])});let n=new Map;for(let[r,s]of t){let o=e[r];s.sort((l,c)=>l.angle-c.angle);for(let l of s)n.set(l.key,{left:Oi(o,ui(Xd(l.d),l.left)),right:Oi(o,ui(Yd(l.d),l.right))});if(s.length<2)continue;let a=4*Math.max(...s.map(l=>Math.max(l.left,l.right)))+1e-9;s.forEach((l,c)=>{let u=s[(c+1)%s.length],h=Oi(o,ui(Xd(l.d),l.left)),f=Oi(o,ui(Yd(u.d),u.right)),d=Rn(l.d,u.d);if(Math.abs(d)<1e-4)return;let p=Oi(h,ui(l.d,Rn(xt(f,h),u.d)/d));Kn(xt(p,o))>a||(n.get(l.key).left=p,n.get(u.key).right=p)})}return n}function Ab(i,e){let t=i.filter((n,r)=>Kn(xt(n,i[(r+1)%i.length]))>e);for(;;){if(t.length<=3)return t;let n=t.findIndex((r,s)=>{let o=t[(s+t.length-1)%t.length],a=t[(s+1)%t.length],[l,c]=[xt(r,o),xt(a,r)];return Math.abs(Rn(hi(l),hi(c)))<1e-7&&yn(l,c)>0});if(n===-1)return t;t=t.filter((r,s)=>s!==n)}}function PE(i){let e=[];return{points:e,idOf(t){let n=e.findIndex(r=>Math.abs(r[0]-t[0])<=i&&Math.abs(r[1]-t[1])<=i);return n>=0?n:(e.push([t[0],t[1]]),e.length-1)}}}function IE(i,e){let t=[];for(let n of i){let r=n.points;if(r.length<3||Math.abs(es(r))<1e-6)continue;let s=es(r)>0,o=r.map(a=>e.idOf(a));o.forEach((a,l)=>{let c=o[(l+1)%o.length];a!==c&&t.push(s?{u:a,v:c,room:n.id,edge:l,forward:!0}:{u:c,v:a,room:n.id,edge:l,forward:!1})})}return t}function LE(i,e,t){let n=[];for(let r of i){let[s,o]=[e[r.u],e[r.v]],a=xt(o,s),l=Kn(a),c=ui(a,1/l),u=e.map((f,d)=>({id:d,rel:xt(f,s)})).filter(({id:f,rel:d})=>f!==r.u&&f!==r.v&&yn(d,c)>t&&yn(d,c)<l-t&&Math.abs(Rn(c,d))<=t).map(({id:f,rel:d})=>({t:yn(d,c),id:f})).sort((f,d)=>f.t-d.t),h=[{t:0,id:r.u},...u,{t:l,id:r.v}];for(let f=0;f+1<h.length;f++){let[d,p]=[h[f],h[f+1]];n.push({u:d.id,v:p.id,room:r.room,edge:r.edge,t0:r.forward?d.t:l-p.t,t1:r.forward?p.t:l-d.t,forward:r.forward})}}return n}var Eb=i=>({room_id:i.room,edge:i.edge,t0:i.t0,t1:i.t1});function FE(i,e){let t=new Map(i.map(a=>[a.id,a])),n=new Map;for(let a of e){let l=`${a.room}:${a.edge}`;n.set(l,[...n.get(l)??[],a.t0].sort((c,u)=>c-u))}let r=a=>{let l=t.get(a.room)?.wall_heights?.[a.edge];return Array.isArray(l)?l[(n.get(`${a.room}:${a.edge}`)??[]).indexOf(a.t0)]??null:l},s=a=>{let l=t.get(a.room),[c,u]=[l?.wall_heights?.[a.edge],l?.wall_slopes?.[a.edge]];if(!l||typeof c!="number"||typeof u!="number"||c<=0||u<=0)return null;let[h,f]=[l.points[a.edge],l.points[(a.edge+1)%l.points.length]];return{from:c,to:u,length:Math.hypot(f[0]-h[0],f[1]-h[1])}},o=a=>{let l=s(a);if(!l||l.length<1e-9){let u=r(a);return typeof u=="number"&&u>0?[u,u]:[null,null]}let c=u=>l.from+(l.to-l.from)*u/l.length;return a.forward?[c(a.t0),c(a.t1)]:[c(a.t1),c(a.t0)]};return{heightsOf(a){let[l,c]=[1/0,1/0];for(let h of a){let[f,d]=o(h),[p,x]=h===a[0]?[f,d]:[d,f];p!==null&&(l=Math.min(l,p)),x!==null&&(c=Math.min(c,x))}let u=a.map(h=>t.get(h.room)?.ceiling);if(u.every(h=>typeof h=="number"&&h>0)){let h=Math.max(...u);l===1/0&&(l=h),c===1/0&&(c=h)}return{...l<1/0?{a:l}:{},...c<1/0?{b:c}:{}}},thicknessOf(a){let l=a.map(c=>{let u=t.get(c.room)?.wall_thickness?.[c.edge];return Array.isArray(u)?u[(n.get(`${c.room}:${c.edge}`)??[]).indexOf(c.t0)]:u}).filter(c=>typeof c=="number"&&c>0);return l.length?Math.max(...l):void 0},hasNoWall:a=>a.some(l=>r(l)===0)}}function Rb(i){let e=t=>Math.round(t*1e6)/1e6;return i.a===void 0||i.b===void 0?i.a!==void 0?{height:e(i.a)}:i.b!==void 0?{height:e(i.b)}:{}:Math.abs(i.a-i.b)<1e-6?{height:e(i.a)}:{height:e(i.a),heightEnd:e(i.b)}}function OE(i,e,t,n){let r=FE(e,i),s=new Map;for(let l of i){let c=l.u<l.v?`${l.u}-${l.v}`:`${l.v}-${l.u}`;s.set(c,[...s.get(c)??[],l])}let o=[],a=[];for(let l of s.values()){let c=l[0],u=l.find(f=>f!==c&&f.u===c.v&&f.v===c.u&&f.room!==c.room);for(let f of l)f!==c&&f!==u&&f.room!==c.room&&n.push(`overlap:${c.room}:${f.room}`);let h=u?[c,u]:[c];if(r.hasNoWall(h)){u&&a.push([c.room,u.room]);continue}if(u){let f=r.thicknessOf(h)??t.interior;o.push({a:c.u,b:c.v,left:f/2,right:f/2,exterior:!1,roomLeft:c.room,roomRight:u.room,sources:h.map(Eb),...Rb(r.heightsOf(h))})}else o.push({a:c.u,b:c.v,left:0,right:r.thicknessOf(h)??t.exterior,exterior:!0,roomLeft:c.room,roomRight:null,sources:[Eb(c)],...Rb(r.heightsOf(h))})}return{drafts:o,open:a}}function NE(i,e){let t=s=>hi(xt(e[s.b],e[s.a])),n=i.filter(s=>!s.exterior&&!s.free),r=new Map;for(let s of n){if(r.has(s))continue;let o=[s];r.set(s,o);for(let a=0;a<o.length;a++){let l=o[a];for(let c of n){if(r.has(c))continue;(c.a===l.a||c.a===l.b||c.b===l.a||c.b===l.b)&&Math.abs(Rn(t(l),t(c)))<1e-6&&(o.push(c),r.set(c,o))}}}for(let s of new Set(r.values())){let o=t(s[0]),a=new Map;for(let u of s)for(let h of[u.a,u.b])a.set(h,(a.get(h)??0)+1);let l=new Set;for(let[u,h]of a)if(h===1)for(let f of i){if(!f.exterior||f.free||f.a!==u&&f.b!==u)continue;let d=t(f);Math.abs(Rn(o,d))>1e-6||l.add(yn(o,d)>0?"left":"right")}if(l.size!==1)continue;let c=[...l][0];for(let u of s){let h=u.left+u.right,f=yn(t(u),o)>0,d=c==="left"===f;[u.left,u.right]=d?[0,h]:[h,0]}}}var DE=(i,e)=>{let t=s=>Math.round(s*100),[n,r]=i[0]<e[0]||i[0]===e[0]&&i[1]<=e[1]?[i,e]:[e,i];return`w_${t(n[0])}_${t(n[1])}_${t(r[0])}_${t(r[1])}`};function al(i,e,t=[]){let n=e.eps??.005,r=[],s=PE(n),o=IE(i,s),a=t.filter(m=>Math.hypot(m.b[0]-m.a[0],m.b[1]-m.a[1])>.05),l=a.map(m=>[s.idOf(m.a),s.idOf(m.b)]),c=new Set;for(let m of i){let b=m.points;b.length<3||(m.wall_splits??[]).forEach((v,y)=>{if(!v||y>=b.length)return;let M=b[y],S=xt(b[(y+1)%b.length],M),_=Kn(S);for(let w of v)w>n&&w<_-n&&c.add(s.idOf(Oi(M,ui(S,w/_))))})}let u=LE(o,s.points,n),{drafts:h,open:f}=OE(u,i,e,r);NE(h,s.points);let d=h;a.forEach((m,b)=>{let[v,y]=l[b];if(v===y)return;let M=[(m.a[0]+m.b[0])/2,(m.a[1]+m.b[1])/2],S=i.find(w=>w.points.length>=3&&Ve(M,w.points))?.id??null,_=(m.thickness??e.interior)/2;d.push({free:m.id,a:v,b:y,left:_,right:_,exterior:!1,roomLeft:S,roomRight:S,sources:[],height:typeof m.height=="number"&&m.height>0?m.height:void 0,...typeof m.height=="number"&&m.height>0&&typeof m.height_end=="number"&&m.height_end>0&&Math.abs(m.height_end-m.height)>1e-6?{heightEnd:m.height_end}:{}})});let p=wb(d,s.points,c),x=Tb(p,s.points);return{walls:p.map((m,b)=>{let[v,y]=[s.points[m.a],s.points[m.b]],[M,S]=[x.get(`${b}:a`),x.get(`${b}:b`)],_=Ab([M.right,S.left,y,S.right,M.left,v],1e-6);return{id:DE(v,y),a:[v[0],v[1]],b:[y[0],y[1]],left:m.left,right:m.right,exterior:m.exterior,roomLeft:m.roomLeft,roomRight:m.roomRight,sources:m.sources,footprint:_,...m.free?{free:m.free}:{},...m.height!==void 0?{height:m.height}:{},...m.heightEnd!==void 0?{heightEnd:m.heightEnd}:{}}}),warnings:[...new Set(r)],open:f}}function Cb(i,e,t){let n=i.points[e];return Oi(n,ui(hi(xt(i.points[(e+1)%i.points.length],n)),t))}function Pb(i,e,t){if(i.wall){let r=t.find(a=>a.id===i.wall);if(!r||Math.hypot(r.b[0]-r.a[0],r.b[1]-r.a[1])<.05)return null;let s=hi(xt(r.b,r.a));return{room:{id:i.room_id,name:"",area_id:null,points:[r.a,r.b,Oi(r.a,[-s[1],s[0]])]},edge:0}}let n=e.find(r=>r.id===i.room_id);return n&&i.edge<n.points.length?{room:n,edge:i.edge}:null}var Ib=(i,e)=>yn(xt(e,i.a),hi(xt(i.b,i.a)));function Lb(i,e,t){if(!e.wall)return UE(i,t.room,t.edge,e.offset);let n=i.find(r=>r.free===e.wall);return n?{wall:n,s:Ib(n,Cb(t.room,0,e.offset))}:null}function UE(i,e,t,n){for(let r of i)if(r.sources.some(o=>o.room_id===e.id&&o.edge===t&&n>=o.t0-1e-6&&n<=o.t1+1e-6))return{wall:r,s:Ib(r,Cb(e,t,n))};return null}var Fb=([i,e])=>{let t=Math.hypot(i,e)||1;return[i/t,e/t]};function BE(i){return i.reduce((e,t,n)=>e+(t[0]*i[(n+1)%i.length][1]-i[(n+1)%i.length][0]*t[1]),0)/2}function Ou(i,e){let t=i.length;if(t<3||Math.abs(e)<1e-9)return i.map(([r,s])=>[r,s]);let n=BE(i)>=0?1:-1;return i.map((r,s)=>{let o=i[(s+t-1)%t],a=i[(s+1)%t],[l,c]=Fb([r[0]-o[0],r[1]-o[1]]),[u,h]=Fb([a[0]-r[0],a[1]-r[1]]),f=[c*n,-l*n],d=[h*n,-u*n],p=[f[0]+d[0],f[1]+d[1]],x=Math.hypot(p[0],p[1]);if(x<1e-6)return[r[0]+f[0]*e,r[1]+f[1]*e];let g=(p[0]*f[0]+p[1]*f[1])/x,m=Math.min(4,1/Math.max(.25,g));return[r[0]+p[0]/x*e*m,r[1]+p[1]/x*e*m]})}function qd(i,e){if(i.points&&i.points.length>=3)return Ou(i.points,e);if(i.rotation)return Mb(i,e);let t=Math.min(i.x0,i.x1)-e,n=Math.max(i.x0,i.x1)+e,r=Math.min(i.z0,i.z1)-e,s=Math.max(i.z0,i.z1)+e;return[[t,r],[n,r],[n,s],[t,s]]}function Hr(i,e){let t=Dn(i),n=En(i),r=t.w,[s,o]=[Math.max(0,e.a),Math.max(0,e.b)],a=t.u0-Math.max(0,e.u0),l=t.u1+Math.max(0,e.u1),c=(m,b)=>[m,b,n.y(b)],u=c(a,-s),h=c(l,-s),f=c(l,r+o),d=c(a,r+o),[p,x]=[ur(i.pitch_a),ur(i.pitch_b)],g=m=>[m,n.vr,n.rh];if(i.ends&&(i.shape==="gable"||i.shape==="hip"||i.shape==="halfhip")){let m=(t.u1-t.u0)/2,b=Math.min(m,Math.min(n.vr,r-n.vr)||r/2),v=Math.min(n.y(0),n.y(r)),y=v+(n.rh-v)*Math.min(.9,Math.max(.2,i.halfhip??.55)),M=p>1e-6?Math.min(n.vr,(y-i.eave_a)/p):n.vr,S=x>1e-6?Math.max(n.vr,r-(y-i.eave_b)/x):n.vr,_=Math.min(m-.1,(n.rh-y)/Math.max(.2,p)),w=[[0,n.y(0)],[n.vr,n.rh],[r,n.y(r)]],R=[[0,n.y(0)],[M,y],[S,y],[r,n.y(r)]],A=(F,H,B)=>{if(F==="hip")return{upA:[],upB:[],ridge:g(H===a?t.u0+b*B:t.u1-b*B),profile:null};if(F==="halfhip"){let X=g(H===a?t.u0+_:t.u1-_);return{upA:[[H,M,y]],upB:[[H,S,y]],ridge:X,profile:R}}return{upA:[],upB:[],ridge:g(H),profile:w}},C=A(i.ends[0],a,1),O=A(i.ends[1],l,1),D=[[u,h,...O.upA,O.ridge,C.ridge,...[...C.upA].reverse()],[C.ridge,O.ridge,...[...O.upB].reverse(),f,d,...C.upB]],P=[[C.ridge,O.ridge]];for(let[F,H,B]of[[C,u,d],[O,h,f]])F.profile===null?(D.push(F===C?[d,u,F.ridge]:[h,f,F.ridge]),P.push([H,F.ridge],[B,F.ridge])):F.upA.length&&(D.push(F===C?[F.upB[0],F.upA[0],F.ridge]:[F.upA[0],F.upB[0],F.ridge]),P.push([F.upA[0],F.ridge],[F.upB[0],F.ridge]));let I=F=>F.profile===null?[]:F.upA.length?[F.upA[0],F.upB[0]]:[F.ridge],N=[u,h,...I(O),f,d,...[...I(C)].reverse()];return{faces:D,rim:N,ridges:P,gable:w,endProfiles:[C.profile,O.profile]}}switch(i.shape){case"pent":return{faces:[[u,h,f,d]],rim:[u,h,f,d],ridges:[[f,d]],gable:[[0,n.y(0)],[r,n.y(r)]]};case"hip":case"pyramid":{let m=(t.u1-t.u0)/2,b=i.shape==="pyramid"?m:Math.min(m,Math.min(n.vr,r-n.vr)||r/2),v=g(t.u0+b),y=g(t.u1-b);return i.shape==="pyramid"?{faces:[[u,h,v],[h,f,v],[f,d,v],[d,u,v]],rim:[u,h,f,d],ridges:[[u,v],[d,v],[h,v],[f,v]],gable:null}:{faces:[[u,h,y,v],[v,y,f,d],[d,u,v],[h,f,y]],rim:[u,h,f,d],ridges:[[v,y],[u,v],[d,v],[h,y],[f,y]],gable:null}}case"halfhip":{let m=Math.min(n.y(0),n.y(r)),b=m+(n.rh-m)*Math.min(.9,Math.max(.2,i.halfhip??.55)),v=p>1e-6?Math.min(n.vr,(b-i.eave_a)/p):n.vr,y=x>1e-6?Math.max(n.vr,r-(b-i.eave_b)/x):n.vr,M=Math.min((t.u1-t.u0)/2-.1,(n.rh-b)/Math.max(.2,p)),S=g(t.u0+M),_=g(t.u1-M),w=[a,v,b],R=[a,y,b],A=[l,v,b],C=[l,y,b];return{faces:[[u,h,A,_,S,w],[S,_,C,f,d,R],[R,w,S],[A,C,_]],rim:[u,h,A,C,f,d,R,w],ridges:[[S,_],[w,S],[R,S],[A,_],[C,_]],gable:[[0,n.y(0)],[v,b],[y,b],[r,n.y(r)]]}}case"mansard":{let m=ol(r,i.eave_a,i.eave_b,p,x),b=[a,m.vla,m.yla],v=[l,m.vla,m.yla],y=[a,r-m.vlb,m.ylb],M=[l,r-m.vlb,m.ylb],S=[a,m.vr,m.rh],_=[l,m.vr,m.rh];return{faces:[[u,h,v,b],[b,v,_,S],[S,_,M,y],[y,M,f,d]],rim:[u,h,v,_,M,f,d,y,S,b],ridges:[[S,_],[b,v],[y,M]],gable:[[0,n.y(0)],[m.vla,m.yla],[m.vr,m.rh],[r-m.vlb,m.ylb],[r,n.y(r)]]}}default:{let m=g(a),b=g(l);return{faces:[[u,h,b,m],[m,b,f,d]],rim:[u,h,b,f,d,m],ridges:[[m,b]],gable:[[0,n.y(0)],[n.vr,n.rh],[r,n.y(r)]]}}}}function Ts(i,e,t){let n=null;for(let r of i.faces){if(!Ve([e,t],r.map(([f,d])=>[f,d])))continue;let[s,o]=r,a=r.slice(2).find(f=>Math.abs((o[0]-s[0])*(f[1]-s[1])-(o[1]-s[1])*(f[0]-s[0]))>1e-9);if(!a)continue;let l=[o[0]-s[0],o[2]-s[2],o[1]-s[1]],c=[a[0]-s[0],a[2]-s[2],a[1]-s[1]],u=[l[1]*c[2]-l[2]*c[1],l[2]*c[0]-l[0]*c[2],l[0]*c[1]-l[1]*c[0]];if(Math.abs(u[1])<1e-9)continue;let h=s[2]-(u[0]*(e-s[0])+u[2]*(t-s[1]))/u[1];n=n===null?h:Math.min(n,h)}return n}function Ro(i,e,t,n){let r=o=>n?o[e]<=t+1e-9:o[e]>=t-1e-9,s=[];return i.forEach((o,a)=>{let l=i[(a+1)%i.length];if(r(o)&&s.push(o),r(o)!==r(l)){let c=(t-o[e])/(l[e]-o[e]);s.push([o[0]+(l[0]-o[0])*c,o[1]+(l[1]-o[1])*c,o[2]+(l[2]-o[2])*c])}}),s}function Nu(i,e){let t=Ro(Ro(i,0,e.u0,!1),0,e.u1,!0);return[Ro(i,0,e.u0,!0),Ro(i,0,e.u1,!1),Ro(t,1,e.v0,!0),Ro(t,1,e.v1,!1)].filter(r=>r.length>=3&&Math.abs(vr(r.map(([s,o])=>[s,o])))>1e-6)}function ll(i,e,t){let n=Dn(e),r=i.floors.flatMap(h=>h.rooms.filter(f=>f.points.length>=3&&h.elevation+h.height>e.base+.05)),s=h=>h.some(f=>r.some(d=>Ve(f,d.points))),o=.35,a=[.15,.5,.85].map(h=>n.u0+(n.u1-n.u0)*h),l=[.15,.5,.85].map(h=>n.w*h),c=h=>h?0:t,u=(h,f)=>{let d=e.overhang_sides?.[h];return typeof d=="number"&&Number.isFinite(d)?Math.min(2,Math.max(0,d)):f};return{a:u("a",c(s(a.map(h=>n.at(h,-o))))),b:u("b",c(s(a.map(h=>n.at(h,n.w+o))))),u0:u("u0",c(s(l.map(h=>n.at(n.u0-o,h))))),u1:u("u1",c(s(l.map(h=>n.at(n.u1+o,h)))))}}var Co=i=>Math.abs((i.x1-i.x0)*(i.z1-i.z0)),Du=i=>i.shape==="flat"||i.shape==="parapet";function As(i,e){let[t,n]=[(e.x0+e.x1)/2,(e.z0+e.z1)/2];return i.filter(s=>{if(s===e||s.dormer||s.open||Du(s)||Co(s)<Co(e)*1.5)return!1;let o=ws(s);return t>=o.x0&&t<=o.x1&&n>=o.z0&&n<=o.z1}).reduce((s,o)=>s===null||Co(o)<Co(s)?o:s,null)}function Ob(i,e){let t=Hr(i,{u0:0,u1:0,a:0,b:0}),n=En(i);return r=>{let[s,o]=e.at(r,e.w/2),[a,l]=Fi(i,s,o);return Ts(t,a,l)??n.y(l)}}function cl(i,e){if(Du(e))return e;let t=Dn(e),n=En(e).rh,r=Ob(i,t),s=r(t.u0)<=r(t.u1),[o,a]=s?[t.u0,t.u1]:[t.u1,t.u0],l=s?1:-1,c=a;for(let f=.5;f<Math.abs(a-o);f+=.05)if(r(o+l*f)>=n-.02){c=o+l*f;break}if(Math.abs(c-a)<.05)return e;let u={...e},h=a===t.u1;return e.axis==="x"?u[h?"x1":"x0"]=c:u[h?"z1":"z0"]=c,u}function Uu(i,e){let t=cl(i,e),n=Dn(t),r=En(t),s=Ob(i,n),o=s(n.u0)<=s(n.u1),a=n.u1-n.u0,l=Math.max(1,Math.ceil(a/.15)),c=[];for(let u=0;u<l;u++){let[h,f]=[a*u/l,a*(u+1)/l],[d,p]=o?[n.u0+h,n.u0+f]:[n.u1-h,n.u1-f],x=s(p),g=1/0,m=-1/0;for(let y=0;y<=40;y++){let M=n.w*y/40;r.y(M)>x+.02&&(g=Math.min(g,M),m=Math.max(m,M))}if(!(m-g>.05))continue;let b=Fi(i,...n.at(d,g)),v=Fi(i,...n.at(p,m));c.push({u0:Math.min(b[0],v[0]),u1:Math.max(b[0],v[0]),v0:Math.min(b[1],v[1]),v1:Math.max(b[1],v[1])})}return c}function ul(i,e){if(e.dormer||e.open||Du(e)||As(i,e))return null;let t=ws(e),n=.35;for(let r of i){if(r===e||r.dormer||r.open||Du(r)||r.axis===e.axis||Co(r)<Co(e))continue;let s=ws(r),o=e.axis==="z"?[t.z0,t.z1,s.z0,s.z1]:[t.x0,t.x1,s.x0,s.x1],a=e.axis==="z"?[t.x0,t.x1,s.x0,s.x1]:[t.z0,t.z1,s.z0,s.z1];if(a[0]<a[2]-.05||a[1]>a[3]+.05)continue;let l=(o[2]+o[3])/2,[c,u]=e.axis==="z"?["z0","z1"]:["x0","x1"],h;if(Math.abs(o[0]-o[3])<=n)h=[l,o[1]];else if(Math.abs(o[1]-o[2])<=n)h=[o[0],l];else continue;let f={...e,[c]:h[0],[u]:h[1]};return{parent:r,extended:cl(r,f)}}return null}var Nb=.14,kE=i=>i.shape==="flat"||i.shape==="parapet";function $d(i,e){return!i.open&&Math.min(i.base,i.eave_a,i.eave_b)<e-.05}function Kd(i,e,t){let n=Math.max(0,i.settings.roof.overhang??0),r=1e-6,s=[];for(let o of i.settings.roof.sections??[]){if(o.open)continue;let[a,l,c,u]=[Math.min(o.x0,o.x1),Math.max(o.x0,o.x1),Math.min(o.z0,o.z1),Math.max(o.z0,o.z1)],[h,f]=Hd(o,e,t);if(h<a-r||h>l+r||f<c-r||f>u+r||o.points&&o.points.length>=3&&!Ve([e,t],o.points))continue;let[d,p]=Fi(o,e,t),x=Math.max(0,o.overhang??n),g=kE(o)?null:Ts(Hr(o,{u0:x,u1:x,a:x,b:x}),d,p);s.push((g??En(o).y(p))-Nb)}return s.length?Math.max(...s):null}function Zd(i,e){let t=i.floors.filter(l=>l.rooms.length>0).sort((l,c)=>l.elevation-c.elevation),n=t.filter(l=>l.elevation<e.base-.05),{x0:r,z0:s,x1:o,z1:a}=e;if(r!==void 0&&s!==void 0&&o!==void 0&&a!==void 0){let l=[];for(let u of[.2,.5,.8])for(let h of[.2,.5,.8])l.push([r+(o-r)*u,s+(a-s)*h]);let c=n.findLast(u=>u.rooms.some(h=>h.points.length>=3&&l.some(f=>Ve(f,h.points))));if(c)return c}return n.at(-1)??t[0]}function Jd(i,e,t){let n=i.settings.roof.sections??[],r=n.filter(l=>t.includes(l.id)).map(l=>As(n,l)??l);if(r.length===0)return e.id;let s=Math.max(...r.map(Wd)),o=l=>l.rooms.some(c=>{if(c.points.length<3)return!1;let u=c.points.reduce((f,d)=>f+d[0],0)/c.points.length,h=c.points.reduce((f,d)=>f+d[1],0)/c.points.length;return r.some(f=>u>=Math.min(f.x0,f.x1)&&u<=Math.max(f.x0,f.x1)&&h>=Math.min(f.z0,f.z1)&&h<=Math.max(f.z0,f.z1))});return i.floors.filter(l=>l.elevation>=e.elevation&&l.elevation<s-.3&&o(l)).sort((l,c)=>c.elevation-l.elevation)[0]?.id??e.id}var Po=new U;function Db(i,e,t,n=1.05){return Po.set(e[0],e[1],e[2]).project(i),{x:(Po.x+1)/2*t.w,y:(1-Po.y)/2*t.h,off:Po.z>1||Math.abs(Po.x)>n||Math.abs(Po.y)>n}}var hl=i=>`translate(${i.x}px, ${i.y}px) translate(-50%, -50%)`,Ub=(i,e)=>`translate(${i}px, ${e}px) translate(0, -50%)`,Bu=class{placed=new WeakMap;place(e,t){let n=t===null;e.hidden!==n&&(e.hidden=n),!(t===null||this.placed.get(e)===t)&&(this.placed.set(e,t),e.style.transform=t)}},zE=8;function Bb(i){let e=[...i].sort((t,n)=>n.rank-t.rank).map(t=>({...t}));for(let t=1;t<e.length;t++){let n=e[t-1];e[t].y=Math.max(e[t].y,n.y+(n.height+e[t].height)/2+zE)}return e}function kb(i,e,t){let n=i.reduce((l,c)=>c.x<l.x?c:l),r=i.reduce((l,c)=>c.x>l.x?c:l),s=8+t.inset,[o,a]=[n.x-e-14,n.y];return o<s&&t.inset&&([o,a]=[r.x+14,r.y]),{left:Math.max(s,Math.min(t.width-e-8,o)),y:a}}function jd(i,e){return i.to>=.99&&i.o>=.9&&!e}function zb(i){return i.to>0&&Math.abs(i.o-i.to)<.05}function Vb(i,e,t,n){return e===void 0?{y:t?i*2.4:0,opacity:1}:i>e?{y:5+i,opacity:0}:i===e?{y:0,opacity:1}:n==="stacked"?{y:0,opacity:1}:{y:-.4,opacity:n==="single"?0:.22}}function Gb(i,e){let[t,n]=[i.ty-i.y,i.to-i.o];if(Math.abs(t)<.004&&Math.abs(n)<.004){let r=t!==0||n!==0;return r&&([i.y,i.o]=[i.ty,i.to]),{moving:!1,settled:r}}return i.y+=t*e,i.o+=n*e,{moving:!0,settled:!1}}function Hb(i,e){let t=e>.999;for(let n of[i.floor,i.wall,i.frames,i.blinds,i.lamps])n.transparent===t&&(n.transparent=!t,n.depthWrite=t,n.needsUpdate=!0),n.opacity=e;for(let n of i.ghosts)n.material.opacity=n.base*e;for(let n of[i.pattern,i.glow,i.lines,i.glass,i.glassWall,i.halos,i.cones,i.screens])n.opacity=e}var Qd=i=>1-Math.exp(-i/140);var Xb=["open","open2","tilt","tilt2"],ep=i=>1-Math.exp(-i/160),Wb=(i,e)=>(i??null)===(e??null)||typeof i=="number"&&typeof e=="number"&&Math.abs(i-e)<.003;function tp(i,e){return Xb.every(t=>Wb(e[t]??0,i[t]??0))&&Wb(e.cover,i.cover)&&!!e.sensed==!!i.sensed&&!!e.unlocked==!!i.unlocked&&!!e.assumed==!!i.assumed}function Yb(i,e,t){let n={...i,open2:i.open2??0,tilt2:i.tilt2??0,sensed:e.sensed,unlocked:e.unlocked,assumed:e.assumed},r=!1,s=(o,a)=>Math.abs(a-o)<.003?a:(r=!0,o+(a-o)*t);for(let o of Xb)n[o]=s(i[o]??0,e[o]??0);return n.cover=e.cover===null||i.cover===null?e.cover:s(i.cover,e.cover),{state:n,moving:r}}var Es={ceiling:[.4,.4,.08],downlight:[.1,.1,.02],spot:[.1,.1,.14],panel:[.6,.6,.03],uplight:[.35,.35,1.8],bollard:[.16,.16,.8],garden:[.12,.12,.3],pendant:[.4,.4,.8],fan:[1.32,1.32,.32],floor:[.42,.42,1.7],table:[.26,.26,.45],wall:[.22,.12,.2],strip:[2,.04,.03]},ku=new Set(["ceiling","downlight","spot","panel","pendant","fan","strip"]),VE=1;function qb(i,e,t,n){switch(i){case"ceiling":return[e-.12,"ceiling"];case"downlight":return[e-.03,"spot"];case"spot":return[e-n,"spot"];case"panel":return[e-.05,"ceiling"];case"pendant":return[Math.max(.5,e-n),"pendant"];case"fan":return[Math.max(.5,e-n+.02),"ceiling"];case"floor":return[t+n-.15,"omni"];case"uplight":return[t+n,"up"];case"table":return[t+n-.1,"omni"];case"wall":return[t+.1,"wall"];case"strip":return[t+Math.max(.02,n)-.01,t<VE?"up":"ceiling"];case"bollard":return[t+n-.08,"ceiling"];case"garden":return[t+n,"up"]}}var $b=Math.PI/180;function Io(i,e,t){let n=Math.abs(t??0)*$b;if(!n)return 0;let r=e/2*Math.sin(n);return i!=null?r:-r}function zu(i,e,t,n,r,s,o){let a=(s??0)*$b,l=r*o*Math.cos(a);return[i+Math.cos(n)*l,e+r*o*Math.sin(a),t+Math.sin(n)*l]}var Kb=.015,GE=.45;function Zb(i,e,t,n,r){let[s,o]=[Math.cos(n),Math.sin(n)],a=[t[0]*s-t[1]*o,t[1]*s+t[0]*o],l=r;for(let c of i){let u=[c.b[0]-c.a[0],c.b[1]-c.a[1]],h=a[0]*u[1]-a[1]*u[0];if(Math.abs(h)<1e-9)continue;let f=[c.a[0]-e[0],c.a[1]-e[1]],d=(f[0]*u[1]-f[1]*u[0])/h,p=(f[0]*a[1]-f[1]*a[0])/h;d>GE&&d<l&&p>=0&&p<=1&&(l=d)}return l}function Jb(i,e,t){let n=i.count,r=e.wedge;if(!r)return{start:n,end:n};let s=(e.rotation??0)*pt,o=[-Math.sin(s),Math.cos(s)],a=r.angle*pt/2,l=new W(...r.color.map(d=>d*r.opacity)),c=new W(0,0,0),u=Math.max(4,Math.round(a/.15)),h=[e.x,e.z],f=(d,p)=>[e.x+(o[0]*Math.cos(d)-o[1]*Math.sin(d))*p,Kb,e.z+(o[1]*Math.cos(d)+o[0]*Math.sin(d))*p];for(let d=0;d<u;d++){let[p,x]=[-a+2*a*d/u,-a+2*a*(d+1)/u],[g,m]=r.walls===!1?[r.reach,r.reach]:[Zb(t,h,o,p,r.reach),Zb(t,h,o,x,r.reach)],[b,v]=[Math.min(r.near,g),Math.min(r.near,m)];r.near<=0?i.tri([e.x,Kb,e.z],f(x,m),f(p,g),l,c,c):(i.tri(f(p,b),f(x,m),f(p,g),l,c,c),i.tri(f(p,b),f(x,v),f(x,m),l,l,c))}return{start:n,end:i.count}}function jb(i,e,t,n){switch(i){case"ceiling":return e-.07;case"downlight":return e-.03;case"spot":return e-n;case"panel":return e-.03;case"pendant":return Math.max(.4,e-n)+.08;case"fan":return Math.max(.5,e-n+.03);case"floor":return t+n-.15;case"uplight":return t+n;case"table":return t+n-.09;case"wall":return t+n/2;case"strip":return t+Math.max(.02,n)-.01;case"bollard":return t+n-.08;case"garden":return t+n-.03}}var HE=.7;function Qb(i,e,t,n){let[r,s,o]=e.size??Es[e.lamp],a=e.base??0,l=(e.rotation??0)*pt,c=jb(e.lamp,n,a,o),u=(h,f,d,p)=>{i.positions.push(h,f,d);for(let x of t.color)i.colours.push(x*t.level*HE*p)};if(e.lamp==="strip")for(let h of[-.4,-.13,.13,.4])e.upright?u(e.x,a+r*(.5+h),e.z,.6):u(...zu(e.x,c+Io(e.base,r,e.rise),e.z,l,r,e.rise,h),.6);else e.lamp==="wall"?u(e.x-Math.sin(l)*(s/2+.05),c,e.z+Math.cos(l)*(s/2+.05),1):u(e.x,c,e.z,1)}function ey(i,e,t,n){let[r,,s]=e.size??Es[e.lamp],o=jb(e.lamp,n,e.base??0,s),a=new W(...t.color.map(d=>d*.09*t.level)),l=new W(0,0,0),[c,u]=[Math.max(.03,r/2),.45+.35*t.level],h=16,f=(d,p,x)=>[e.x+Math.cos(d)*p,x,e.z+Math.sin(d)*p];for(let d=0;d<h;d++){let[p,x]=[d/h*Math.PI*2,(d+1)/h*Math.PI*2];i.tri(f(p,c,o),f(p,u,.02),f(x,u,.02),a,l,l),i.tri(f(p,c,o),f(x,u,.02),f(x,c,o),a,l,a)}}var ty=i=>ku.has(i);var ny=7,WE=.25,XE=.3,YE=2,np=[1,.82,.55],qE=.45;function iy(i,e,t,n){return i?`${i.elevation.toFixed(1)},${i.azimuth.toFixed(1)},${e*pt},${t.toFixed(2)},${[...n].map(r=>(r.cover??0).toFixed(2)).join(",")}`:""}var Lo=(i,e)=>[Math.sin((e+i)*pt),-Math.cos((e+i)*pt)],ip=(i,e)=>Math.min(1,i/12)*(1-.8*e),$E=(i,e)=>-i.toRoom[0]*e[0]+-i.toRoom[1]*e[1];function ry({floor:i,openings:e,states:t,sun:n,northDegrees:r,cloud:s}){let o=new lt;if(!n||n.elevation<=YE||s>=.97)return o;let a=ip(n.elevation,s),l=Lo(n.azimuth,r),c=1/Math.tan(n.elevation*pt);for(let u of e){if(u.opening.type!=="window"||!u.exterior)continue;let h=$E(u,l);if(h<.05)continue;let f=u.top-(t.get(u.opening.id)?.cover??0)*(u.top-u.sill);if(f-u.sill<.05)continue;let d=i.rooms.find(M=>M.id===u.opening.room_id);if(!d||d.points.length<3)continue;let p=(M,S)=>{let _=Math.min(ny,S*c);return[u.start[0]+u.axis[0]*M+u.toRoom[0]*u.faceRoom-l[0]*_,.02,u.start[1]+u.axis[1]*M+u.toRoom[1]*u.faceRoom-l[1]*_]},x=.14*a*Math.min(1,h*1.5),g=new W(np[0]*x,np[1]*x,np[2]*x),m=g.clone().multiplyScalar(qE),b=Math.max(1,Math.ceil(Math.min(ny,f*c)/WE)),v=Math.max(1,Math.ceil(u.width/XE)),y=f-u.sill;for(let M=0;M<b;M++){let[S,_]=[u.sill+y*M/b,u.sill+y*(M+1)/b],[w,R]=[g.clone().lerp(m,M/b),g.clone().lerp(m,(M+1)/b)];for(let A=0;A<v;A++){let[C,O]=[u.width*A/v,u.width*(A+1)/v],D=p((C+O)/2,(S+_)/2);if(!Ve([D[0],D[2]],d.points))continue;let[P,I,N,F]=[p(C,S),p(O,S),p(O,_),p(C,_)];o.tri(P,I,N,w,w,R),o.tri(P,N,F,w,R,R)}}}return o}var hr=1e-4;function sy(i){return i.reduce((e,t,n)=>e+Rn(t,i[(n+1)%i.length]),0)/2}var oy=i=>sy(i)>=0?[...i]:[...i].reverse();function ay(i,e,t,n){let r=xt(e,i),s=xt(n,t),o=Rn(r,s);if(Math.abs(o)<1e-12)return null;let a=Rn(xt(t,i),s)/o,l=Rn(xt(t,i),r)/o;return a>hr&&a<1-hr&&l>-hr&&l<1+hr?a:null}function rp(i,e,t){let n=xt(t,e),r=yn(n,n);if(r<1e-12)return null;let s=yn(xt(i,e),n)/r;return s<=hr||s>=1-hr?null:Math.abs(Rn(xt(i,e),n))/Math.sqrt(r)<hr?s:null}var fl=(i,e,t=hr)=>Kn(xt(i,e))<t,dl=i=>i.map((e,t)=>[e,i[(t+1)%i.length]]);function KE(i,e){for(let[t,n]of dl(i))for(let[r,s]of dl(e))if(ay(t,n,r,s)!==null||rp(r,t,n)!==null||rp(t,r,s)!==null||fl(t,r))return!0;return Ve(i[0],e)||Ve(e[0],i)}function ZE(i){let e=i.map(oy),t=[];e.forEach((s,o)=>{for(let[a,l]of dl(s)){let c=[0,1];e.forEach((u,h)=>{if(h!==o)for(let[f,d]of dl(u)){let p=ay(a,l,f,d)??rp(f,a,l);p!==null&&c.push(p)}}),c.sort((u,h)=>u-h);for(let u=1;u<c.length;u++){if(c[u]-c[u-1]<hr)continue;let h=[a[0]+(l[0]-a[0])*c[u-1],a[1]+(l[1]-a[1])*c[u-1]],f=[a[0]+(l[0]-a[0])*c[u],a[1]+(l[1]-a[1])*c[u]],d=Kn(xt(f,h)),p=[(h[0]+f[0])/2+(f[1]-h[1])/d*.001,(h[1]+f[1])/2-(f[0]-h[0])/d*.001];e.some((x,g)=>g!==o&&Ve(p,x))||t.some(([x,g])=>fl(x,h)&&fl(g,f))||t.push([h,f])}}});let n=[],r=new Set;return t.forEach(([s,o],a)=>{if(r.has(a))return;r.add(a);let l=[s],c=o;for(let u=0;u<t.length&&!fl(c,l[0],.001);u++){let h=t.findIndex(([f],d)=>!r.has(d)&&fl(f,c,.001));if(h<0)break;r.add(h),l.push(t[h][0]),c=t[h][1]}l.length>=3&&sy(l)>1e-6&&n.push(l)}),n}function fr(i){let e=i.filter(s=>s.length>=3),t=e.map((s,o)=>o),n=s=>t[s]===s?s:t[s]=n(t[s]);e.forEach((s,o)=>{for(let a=o+1;a<e.length;a++)n(o)!==n(a)&&KE(s,e[a])&&(t[n(a)]=n(o))});let r=new Map;return e.forEach((s,o)=>r.set(n(o),[...r.get(n(o))??[],s])),[...r.values()].flatMap(s=>s.length===1?s:ZE(s))}function JE(i,e,t){let n=xt(t,e),r=yn(n,n),s=r?Math.max(0,Math.min(1,yn(xt(i,e),n)/r)):0;return Kn(xt(i,[e[0]+n[0]*s,e[1]+n[1]*s]))}function ly(i,e,t=.03){return i.every(n=>Ve(n,e)||dl(e).some(([r,s])=>JE(n,r,s)<=t))}function cy(i,e){let t=oy(i),n=(r,s)=>{let o=xt(s,r),a=Kn(o)||1;return[-o[1]/a,o[0]/a]};return t.map((r,s)=>{let o=n(t[(s-1+t.length)%t.length],r),a=n(r,t[(s+1)%t.length]),l=1+yn(o,a);return l<.1?r:[r[0]+(o[0]+a[0])/l*e,r[1]+(o[1]+a[1])/l*e]})}var jE=30,uy=i=>i.reduce((e,t,n)=>e+t[0]*i[(n+1)%i.length][1]-i[(n+1)%i.length][0]*t[1],0)/2;function QE(i,e,t,n){if(!t||t.elevation<=2||e<=0||!i.length)return[];let r=Math.min(jE,e/Math.tan(t.elevation*Math.PI/180)),[s,o]=Lo(t.azimuth,n),a=c=>[c[0]-s*r,c[1]-o*r],l=[];for(let c of i){l.push([...c],c.map(a));let u=Math.sign(uy(c))||1;c.forEach((h,f)=>{let d=c[(f+1)%c.length];if(u*((d[1]-h[1])*-s-(d[0]-h[0])*-o)<=1e-9)return;let x=[h,d,a(d),a(h)];Math.abs(uy(x))>.001&&l.push(x)})}return fr(l)}var Vu=class{mesh;material=new Ke({color:0,side:ut,transparent:!0,opacity:0,depthWrite:!1,polygonOffset:!0,polygonOffsetFactor:-2,polygonOffsetUnits:-2});constructor(){this.mesh=new we(new Fe,this.material),this.mesh.renderOrder=1,this.mesh.visible=!1}update(e,t,n,r,s,o,a){let l=a?[]:QE(e,t,r,s),c=[];for(let h of l){let f=e.filter(p=>Ve([p.reduce((x,g)=>x+g[0],0)/p.length,p.reduce((x,g)=>x+g[1],0)/p.length],h)),d=[...h,...f.flat()];for(let[p,x,g]of Vr(h,f.map(m=>[...m])))for(let m of[d[p],d[x],d[g]])c.push(m[0],n,m[1])}this.mesh.geometry.dispose();let u=new Fe;u.setAttribute("position",new ke(c,3)),this.mesh.geometry=u,this.material.opacity=r?.32*ip(r.elevation,o):0,this.mesh.visible=c.length>0&&this.material.opacity>.02}dispose(){this.mesh.geometry.dispose(),this.material.dispose()}};var pl=i=>es(i)>=0?i:[...i].reverse();function ml(i,[e,t],n,r,s,o,a){Tt(i,pl([[e-n,t-n],[e+n,t-n],[e+n,t+n],[e-n,t+n]]),r,s,o,a)}function Gu(i,e,t,n,r,s,o,a,l=0){let[c,u]=[t[0]-e[0],t[1]-e[1]],h=Math.hypot(c,u);if(h<1e-6)return;let[f,d]=[-u/h*n*.5,c/h*n*.5];if(Math.abs(l)<1e-4){Tt(i,pl([[e[0]+f,e[1]+d],[t[0]+f,t[1]+d],[t[0]-f,t[1]-d],[e[0]-f,e[1]-d]]),r,s,o,a,{aoFrom:r-1});return}let p=(y,M)=>[e[0]+f*M,y,e[1]+d*M],x=(y,M)=>[t[0]+f*M,y+l,t[1]+d*M],g=(y,M)=>{for(let[S,_,w]of[[0,1,2],[0,2,3],[0,2,1],[0,3,2]])i.tri(y[S],y[_],y[w],M,M,M,void 0,Xe)},m=new W(a),b=Ue(o,.9),v=Ue(o,.6);g([p(s,1),x(s,1),x(s,-1),p(s,-1)],m),g([p(r,1),x(r,1),x(r,-1),p(r,-1)],v),g([p(r,1),x(r,1),x(s,1),p(s,1)],b),g([p(r,-1),x(r,-1),x(s,-1),p(s,-1)],b),g([p(r,1),p(r,-1),p(s,-1),p(s,1)],b),g([x(r,1),x(r,-1),x(s,-1),x(s,1)],b)}function hy(i,e,t){let n=(o,a)=>Math.abs(o[0]-a[0])<1e-6&&Math.abs(o[1]-a[1])<1e-6,r=Math.hypot(t[0]-e[0],t[1]-e[1]),s=[];for(let o of i.gates??[]){let a=i.points[o.edge],l=i.points[(o.edge+1)%i.points.length];!a||!l||(n(a,e)&&n(l,t)?s.push({gate:o,offset:o.offset}):n(a,t)&&n(l,e)&&s.push({gate:o,offset:r-o.offset}))}return s.sort((o,a)=>o.offset-a.offset)}function fy(i,e,t,n,r){let s=Math.hypot(e[0]-i[0],e[1]-i[1]);if(s<.3)return null;let o=Math.min(t.width,s-.1);if(o<.3)return null;let a=Math.max(.05,Math.min(s-o-.05,n-o/2)),l=a+o,[c,u]=[(e[0]-i[0])/s,(e[1]-i[1])/s],[h,f]=[-u,c],d=(m,b=0)=>[i[0]+c*m+h*b,i[1]+u*m+f*b],[p,x]=[d(a),d(l)],g=[];if(t.kind==="double"){let m=(a+l)/2;g.push(r?{a:p,b:d(a,o/2)}:{a:p,b:d(m)}),g.push(r?{a:x,b:d(l,o/2)}:{a:x,b:d(m)})}else t.kind==="sliding"?g.push(r?{a:d(l,-.12),b:d(l+o,-.12)}:{a:p,b:x}):g.push(r?{a:p,b:d(a,o)}:{a:p,b:x});return{from:a,to:l,posts:[p,x],leaves:g}}var dy={lawn:{color:927778,side:729115,edge:4121250,edgeAlpha:.16},terrace:{color:1841968,side:1447464,edge:5995775,edgeAlpha:.32},path:{color:1778228,side:1383209,edge:5995775,edgeAlpha:.22},driveway:{color:1514796,side:1185573,edge:5995775,edgeAlpha:.18},pool:{color:736091,side:861497,edge:3662079,edgeAlpha:.6},bed:{color:1775123,side:1380623,edge:4121250,edgeAlpha:.2},wild:{color:1384987,side:1055509,edge:10146383,edgeAlpha:.14},hedge:{color:1524016,side:1126693,edge:4121250,edgeAlpha:.35},fence:{color:1976903,side:1976903,edge:5995775,edgeAlpha:.45},pergola:{color:2827065,side:2104109,edge:5995775,edgeAlpha:.5}};function sp(i,e){return Ko(i)+(e.offset??0)+(Jr(e.type)?.01:Ll[e.type])}function Hu(i,e){let t=i[e];return Jr(t.type)||t.type==="pool"?[]:i.filter((n,r)=>r!==e&&m0(n)&&n.points.length>=3&&n.points.every(s=>Ve(s,t.points))).map(n=>pl(n.points))}var Wu=(i,e)=>i.map((t,n)=>[n,t,i[(n+1)%i.length]]).filter(([t])=>t!==e);function gl(i,e){if(i.area.outline!==!1)for(let[,t,n]of Wu(i.poly,i.openEdge))i.lines.seg([t[0],e(t[0],t[1]),t[1]],[n[0],e(n[0],n[1]),n[1]],i.edge,Xe)}function eR(i){let{buf:e,poly:t,base:n,top:r,look:s}=i,o=new W(s.color);for(let[l,c,u]of Vr(t)){let[h,f,d]=[t[l],t[c],t[u]];e.tri([h[0],n+r,h[1]],[d[0],n+r,d[1]],[f[0],n+r,f[1]],o,o,o,void 0,Xe)}let a=new W(s.side);for(let[,l,c]of Wu(t,-1))e.tri([c[0],n+r,c[1]],[c[0],n+.06,c[1]],[l[0],n+.06,l[1]],a,a,a,void 0,Xe),e.tri([c[0],n+r,c[1]],[l[0],n+.06,l[1]],[l[0],n+r,l[1]],a,a,a,void 0,Xe);gl(i,()=>n+.06),gl(i,()=>n+r+.005)}function tR(i){let{buf:e,lines:t,poly:n,area:r,top:s,look:o,groundAt:a,edge:l,openEdge:c}=i;for(let[u,h,f]of Wu(n,c)){let d=Math.hypot(f[0]-h[0],f[1]-h[1]),p=Math.max(1,Math.round(d/2)),x=hy(r,h,f).map(({gate:M,offset:S})=>({gate:M,layout:fy(h,f,M,S,!!M.open)})).filter(M=>!!M.layout),g=M=>x.some(S=>M>S.layout.from-.15&&M<S.layout.to+.15),m=c>=0&&u===c-1?p:p-1;for(let M=0;M<=m;M++){if(g(d*M/p))continue;let S=h[0]+(f[0]-h[0])*M/p,_=h[1]+(f[1]-h[1])*M/p,w=a(S,_);ml(e,[S,_],.04,w,w+s,o.side,o.color)}let b=[],v=0;for(let M of x)b.push([v,M.layout.from]),v=M.layout.to;b.push([v,d]);let y=M=>[h[0]+(f[0]-h[0])*M/d,h[1]+(f[1]-h[1])*M/d];for(let[M,S]of b){if(S-M<.02)continue;let[_,w]=[y(M),y(S)];for(let R of[.35,.85])t.seg([_[0],a(_[0],_[1])+R*s,_[1]],[w[0],a(w[0],w[1])+R*s,w[1]],l,Xe)}for(let{layout:M}of x){for(let S of M.posts){let _=a(S[0],S[1]);ml(e,S,.07,_,_+s*1.05,o.side,o.color)}for(let S of M.leaves)nR(i,S.a,S.b)}}}function nR(i,e,t){let{buf:n,lines:r,top:s,look:o,groundAt:a,edge:l}=i,c=Math.hypot(t[0]-e[0],t[1]-e[1]);if(c<.05)return;let[u,h]=[a(e[0],e[1]),a(t[0],t[1])],f=h-u;for(let[p,x]of[[.12,.2],[.78,.86]])Gu(n,e,t,.05,u+p*s,u+x*s,o.side,o.color,f);let d=Math.max(2,Math.round(c/.18));for(let p=0;p<=d;p++){let x=p/d,g=e[0]+(t[0]-e[0])*x,m=e[1]+(t[1]-e[1])*x,b=u+f*x;ml(n,[g,m],p===0||p===d?.03:.012,b+.1*s,b+.9*s,o.side,o.color)}r.seg([e[0],u+.2*s,e[1]],[t[0],h+.78*s,t[1]],l,Xe)}function iR(i){let{buf:e,lines:t,poly:n,area:r,top:s,look:o,groundAt:a,edge:l,openEdge:c}=i;for(let u of n){let h=a(u[0],u[1]);ml(e,u,.06,h,h+s,o.side,o.color)}for(let[,u,h]of Wu(n,c)){let[f,d]=[a(u[0],u[1]),a(h[0],h[1])];Gu(e,u,h,.12,f+s-.16,f+s,o.side,o.color,d-f),r.bracing&&(t.seg([u[0],f+.25,u[1]],[h[0],d+s-.25,h[1]],l,Xe),t.seg([h[0],d+.25,h[1]],[u[0],f+s-.25,u[1]],l,Xe))}if(T0(n)){let u=A0(n),h=u.x1-u.x0>=u.z1-u.z0,[f,d]=h?[u.x0,u.x1-u.x0]:[u.z0,u.z1-u.z0],p=Math.max(1,Math.round(d/.6));for(let x=1;x<p;x++){let g=f+d*x/p,m=h?[g,u.z0+.06]:[u.x0+.06,g],b=h?[g,u.z1-.06]:[u.x1-.06,g],v=a(m[0],m[1]);Gu(e,m,b,.06,v+s-.04,v+s+.08,o.side,o.color,a(b[0],b[1])-v)}}gl(i,(u,h)=>a(u,h)+s+.004)}function rR(i,e,t){let{buf:n,lines:r,poly:s,area:o,top:a,look:l,groundAt:c,base:u,edge:h}=i,f=u-(o.slope??0),d=(x,g)=>c(x,g)+a,p=Hu(e,t);if(Tt(n,s,f,o.slope?d:u+a,l.side,l.color,{aoFrom:f,holes:p}),gl(i,(x,g)=>d(x,g)+.004),o.type==="hedge"&&gl(i,(x,g)=>c(x,g)+.004),o.outline!==!1)for(let x of p)x.forEach((g,m)=>{let b=x[(m+1)%x.length];r.seg([g[0],d(g[0],g[1])+.004,g[1]],[b[0],d(b[0],b[1])+.004,b[1]],h,Xe)})}function py(i){let e=i.opacity;return e==null||!(e<1)?1:Math.max(.1,Math.round(e*20)/20)}function op(i,e,t,n,r){let s=Ko(t),o=t.outdoor??[];o.forEach((a,l)=>{if(a.points.length<3)return;let c=s+(a.offset??0),u=dy[a.type],h=pl(a.points),f=py(a),d=i;f<1&&n&&r&&(n.has(f)||n.set(f,r()),d=n.get(f));let p={buf:d,lines:e,area:a,poly:h,base:c,groundAt:(x,g)=>c-zh(a,x,g),top:Jr(a.type)&&a.height?a.height:Ll[a.type],look:u,edge:Ue(u.edge,u.edgeAlpha),openEdge:a.open&&(a.type==="fence"||a.type==="pergola")?h.length-1:-1};a.type==="pool"?eR(p):a.type==="fence"?tR(p):a.type==="pergola"?iR(p):rR(p,o,l)})}var my=.012,sR=.012;function oR(){let i=[],e=[],t=[],n=[];return{add(r,s,o,a,l,c,u){for(let h of[r,s,o,r,o,a])i.push(h[0],h[1],h[2]),e.push(l[0],l[1],l[2]),t.push(c),n.push(u)},finish:r=>({pos:new Float32Array(i),normal:new Float32Array(e),room:Int16Array.from(t),fold:new Float32Array(n),doors:r})}}function by(i,e){let[t,n]=[i.b[0]-i.a[0],i.b[1]-i.a[1]],r=Math.hypot(t,n)||1;return Math.abs((e.start[0]-i.a[0])*n-(e.start[1]-i.a[1])*t)/r<.02&&Math.abs((e.axis[0]*t+e.axis[1]*n)/r)>.99}function aR(i,e,t,n){let r=[];for(let s of n.filter(o=>by(i,o))){let o=(s.start[0]-i.a[0])*e[0]+(s.start[1]-i.a[1])*e[1],a=s.axis[0]*e[0]+s.axis[1]*e[1]>0?o:o-s.width;a>t||a+s.width<0||r.push({s0:a,s1:a+s.width,y0:s.sill-.01,y1:s.top+.01})}return r}function gy(i,e,t){let n=[e,t,...i.filter(r=>r>e+.005&&r<t-.005)].sort((r,s)=>r-s);return n.filter((r,s)=>s===0||r>n[s-1]+.005)}function xy(i,e,t=()=>!1){let n=i.map(u=>u[0]),r=i.map(u=>u[1]),[s,o]=[Math.min(...n),Math.min(...r)],[a,l]=[Math.max(1,Math.ceil((Math.max(...n)-s)/e)),Math.max(1,Math.ceil((Math.max(...r)-o)/e))],c=[];for(let u=0;u<a;u++)for(let h=0;h<l;h++){let[f,d]=[s+(u+.5)*e,o+(h+.5)*e];Ve([f,d],i)&&!t(f,d)&&c.push({a:s+u*e,b:o+h*e})}return c}function ap(i,e,t,n,r,s=[],o){let a=oR(),l=(d,p,x,g)=>a.add([d,x,p],[d,x,p+r],[d+r,x,p+r],[d+r,x,p],[0,1,0],g,-1);i.rooms.forEach((d,p)=>{if(!(d.points.length<3))for(let{a:x,b:g}of xy(d.points,r,(m,b)=>s.some(v=>Ve([m,b],v))))l(x,g,my,p)});let c=i.rooms.length,u=i.outdoor??[];u.forEach((d,p)=>{if(d.points.length<3||Jr(d.type))return;let x=sp(i,d)+my,g=Hu(u,p);for(let{a:m,b}of xy(d.points,r,(v,y)=>g.some(M=>Ve([v,y],M))))l(m,b,x,c)});let h=Math.min(i.cut_height,i.height);e.forEach((d,p)=>{let x=d.heightEnd===void 0?null:[d.height??i.height,d.heightEnd],g=x?Math.max(...x):d.height??i.height,m=Math.min(h,g-.02),[b,v]=[d.b[0]-d.a[0],d.b[1]-d.a[1]],y=Math.hypot(b,v);if(y<.05)return;let M=[b/y,v/y],S=[-M[1],M[0]],_=t[p],w=aR(d,M,y,n),R=gy([m,(m+g)/2,...w.flatMap(C=>[C.y0+.01,C.y1-.01])],.02,g-.02),A=gy(w.flatMap(C=>[C.s0,C.s1]),0,y);for(let C of[1,-1]){let O=C>0?d.roomLeft:d.roomRight,D=O?i.rooms.findIndex(H=>H.id===O):d.exterior?c:-1;if(D<0)continue;let P=(C>0?d.left:d.right)+sR,I=[S[0]*C,S[1]*C],N=(H,B)=>[d.a[0]+M[0]*H+I[0]*P,B,d.a[1]+M[1]*H+I[1]*P],F=H=>{let B=N(H,0),X=o?.(B[0],B[2]),V=x?x[0]+(x[1]-x[0])*H/y-.02:1/0;return Math.min(V,X==null?1/0:X-.02)};for(let H=0;H+1<A.length;H++){let B=A[H+1]-A[H],X=Math.max(1,Math.ceil(B/r));for(let V=0;V<X;V++){let re=A[H]+B/X*V,be=A[H]+B/X*(V+1);for(let Y=0;Y+1<R.length;Y++){let[Q,se]=[R[Y],R[Y+1]];if(se-Q<.01)continue;let[Se,le]=[(re+be)/2,(Q+se)/2];if(w.some(Te=>Se>Te.s0&&Se<Te.s1&&le>Te.y0&&le<Te.y1))continue;let[Ie,st]=[Math.min(se,F(re)),Math.min(se,F(be))];Ie<=Q+.005&&st<=Q+.005||a.add(N(re,Q),N(be,Q),N(be,Math.max(Q,st)),N(re,Math.max(Q,Ie)),[I[0],0,I[1]],D,Q>=h-1e-6?_:cr+_)}}}}});let f=[];for(let d of n.filter(p=>p.opening.type==="door")){let p=e.find(m=>by(m,d));if(!p?.roomLeft||!p.roomRight)continue;let[x,g]=[i.rooms.findIndex(m=>m.id===p.roomLeft),i.rooms.findIndex(m=>m.id===p.roomRight)];x<0||g<0||f.push({id:d.opening.id,a:x,b:g,x:d.start[0]+d.axis[0]*(d.width/2),y:Math.min(1.1,d.top*.55),z:d.start[1]+d.axis[1]*(d.width/2)})}return a.finish(f)}function lR(i,e){let t=Math.max(0,-e),n=Math.max(0,e);switch(i){case"ceiling":return .3+.7*t;case"spot":return .06+.94*t**5;case"pendant":return .25+.85*t**2+.2*n;case"up":return .25+.75*n;case"wall":return .45+.35*Math.abs(e);default:return 1}}function cR(i){return(i.kind==="spot"?2:i.kind==="wall"?1.4:2.4)*(.55+.45*i.level)}function yy(i,e,t){let[n,r,s]=[e[0]-i.x,e[1]-i.y,e[2]-i.z],o=n*n+r*r+s*s,a=Math.sqrt(o)||1e-6,l=cR(i),c=1/(1+o/(l*l)),u=c*Math.sqrt(c),h=Math.max(0,-(n*t[0]+r*t[1]+s*t[2])/a);return i.level*u*(.2+.8*h)*lR(i.kind,r/a)}function uR(i,e,t){let n=[];return i.doors.forEach((r,s)=>{let o=t[s]??.5;if(!(o<=.01))for(let[a,l]of[[r.a,r.b],[r.b,r.a]]){let c=[0,0,0];for(let h of e.filter(f=>f.room===a)){let f=[h.x-r.x,h.y-r.y,h.z-r.z],d=Math.hypot(...f)||1,p=yy(h,[r.x,r.y,r.z],[f[0]/d,f[1]/d,f[2]/d]);for(let x=0;x<3;x++)c[x]+=h.color[x]*p}let u=Math.max(...c);u<.01||n.push({x:r.x,y:r.y,z:r.z,color:[c[0]/u,c[1]/u,c[2]/u],level:Math.min(1,u*.9*(.35+.65*o)),kind:"wall",room:l})}}),n}function lp(i,e,t=.7,n=[]){let r=new Map;for(let c of[...e,...uR(i,e,n)]){let u={...c,color:c.color.map(h=>h**1.5)};r.set(c.room,[...r.get(c.room)??[],u])}let{pos:s,normal:o,room:a}=i,l=new Float32Array(s.length);for(let c=0;c<a.length;c++){let u=r.get(a[c]);if(!u)continue;let h=c*3,f=[0,0,0];for(let d of u){let p=yy(d,[s[h],s[h+1],s[h+2]],[o[h],o[h+1],o[h+2]]);for(let x=0;x<3;x++)f[x]+=d.color[x]*p}for(let d=0;d<3;d++)l[h+d]=1-Math.exp(-f[d]*t*1.6)}return l}function cp(i,e,t){let n=i.rooms.findIndex(r=>r.points.length>=3&&Ve([e,t],r.points));return n<0?i.rooms.length:n}var up=(i,e)=>i&&e>=0&&e<i.length?i[e]:e;var hR=Math.PI/180,fR=[.3,.3,.3],dR=[-1/3,0,1/3],_y=.55;function vy(i,e,t,n){let r=[];for(let s of t){let o=n(s);if(s.floorId!==i.id||!o)continue;let a=up(e,cp(i,s.x,s.z)),[l,,c]=s.size??(s.lamp?Es[s.lamp]:fR),u=s.base??0,[h,f]=s.lamp?qb(s.lamp,s.ceiling??i.height,u,c):[s.y,"omni"],d=s.lightY??h,{color:p,level:x}=o;if(s.lamp!=="strip"){r.push({x:s.x,y:d,z:s.z,color:p,level:x,kind:f,room:a});continue}let g=(s.rotation??0)*hR,m=!!s.upright||Math.abs(s.roll??0)>45,b=d+Io(s.base,l,s.rise);for(let v of dR)if(s.upright)r.push({x:s.x,y:u+l*(.5+v),z:s.z,color:p,level:x*_y,kind:"omni",room:a});else{let[y,M,S]=zu(s.x,b,s.z,g,l,s.rise,v);r.push({x:y,y:M,z:S,color:p,level:x*_y,kind:m?"omni":f,room:a})}}return r}function My(i,e,t="plain"){return i.onBeforeCompile=n=>{n.uniforms.uStanding=e.standing,n.uniforms.uGlass=e.glass,n.uniforms.uSlope=e.slope??{value:{x:0,y:0,z:0,w:0}},n.uniforms.uSlopeY=e.slopeY??{value:{x:0,y:0}},n.uniforms.uGlassAlpha=e.glassAlpha??{value:.2},n.vertexShader=n.vertexShader.replace("#include <common>",`#include <common>
|
|
attribute float fold;
|
|
uniform int uStanding;
|
|
uniform int uGlass;
|
|
uniform vec4 uSlope;
|
|
uniform vec2 uSlopeY;
|
|
varying float vNfPaint;`).replace("#include <begin_vertex>",`#include <begin_vertex>
|
|
vNfPaint = fold > 127.5 ? 1.0 : 0.0;
|
|
if (fold > -0.5 && (uSlope.x != 0.0 || uSlope.y != 0.0) && int(mod(fold, 128.0) + 0.5) / 16 != 4) {
|
|
float nfAlong = clamp((dot(transformed.xz, uSlope.xy) - uSlope.z) / max(uSlope.w - uSlope.z, 0.001), 0.0, 1.0);
|
|
transformed.y = min(transformed.y, mix(uSlopeY.x, uSlopeY.y, nfAlong));
|
|
}`).replace("#include <project_vertex>",`#include <project_vertex>
|
|
{
|
|
bool nfShow = ${t==="glass"?"false":"true"};
|
|
if (fold > -0.5) {
|
|
int nfFold = int(mod(fold, 128.0) + 0.5);
|
|
int nfKind = nfFold / 16;
|
|
int nfBucket = nfFold - nfKind * 16;
|
|
bool nfStanding = ((uStanding >> nfBucket) & 1) == 1;
|
|
bool nfGlass = ((uGlass >> nfBucket) & 1) == 1;
|
|
// kinds: 0 upper part, 1 cut edge, 2 lower part, 3 cap at the cut height, 4 furniture above the cut
|
|
nfShow = nfKind == 0 || nfKind == 4 ? nfStanding : nfKind == 1 || nfKind == 3 ? !nfStanding : true;
|
|
bool nfWall = nfKind == 0 || nfKind == 2;
|
|
${t==="solid"?"if (nfGlass && nfWall) nfShow = false;":""}
|
|
${t==="glass"?"nfShow = nfShow && nfGlass && nfWall;":""}
|
|
}
|
|
if (!nfShow) gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
}`),n.fragmentShader=n.fragmentShader.replace("#include <common>",`#include <common>
|
|
varying float vNfPaint;
|
|
uniform float uGlassAlpha;`),t!=="glass"&&(n.fragmentShader=n.fragmentShader.replace("#include <color_fragment>",`#include <color_fragment>
|
|
#ifdef USE_COLOR
|
|
if (vNfPaint > 0.5) diffuseColor.rgb = vColor.rgb;
|
|
#endif`)),t==="glass"&&(n.fragmentShader=n.fragmentShader.replace("#include <color_fragment>",`#include <color_fragment>
|
|
diffuseColor.rgb = diffuseColor.rgb * 1.7 + vec3(0.015, 0.05, 0.075);
|
|
diffuseColor.a *= uGlassAlpha;`))},i.customProgramCacheKey=()=>`nf-fold-${t}`,i}var hp=["neon","blueprint","day"],eN=["auto",...hp];var Sy=i=>hp.indexOf(i),Xu={value:new U(.22,.88,1)},Yu={value:0};function wy(i){let e=/^#?([0-9a-f]{6})$/i.exec(i?.trim()??"");if(!e)return null;let t=Number.parseInt(e[1],16);return[(t>>16&255)/255,(t>>8&255)/255,(t&255)/255]}var pR=`
|
|
uniform int uTheme;
|
|
uniform vec3 uAccent;
|
|
uniform int uAccentOn;
|
|
vec3 nfThemed(vec3 c, bool isLine) {
|
|
float strongest = max(c.r, max(c.g, c.b));
|
|
float weakest = min(c.r, min(c.g, c.b));
|
|
float saturation = strongest > 0.0 ? (strongest - weakest) / strongest : 0.0;
|
|
if (uTheme == 0) {
|
|
// an own accent: every line and every cyan surface takes it, as bright as it was
|
|
bool cyanish = saturation > 0.35 && c.r < c.g * 0.8 && c.b > c.g * 0.85 && c.g > c.b * 0.6;
|
|
if (uAccentOn == 1 && (isLine || cyanish)) return uAccent * strongest;
|
|
return c;
|
|
}
|
|
// signal colours keep their colour
|
|
if (!isLine && strongest > 0.45 && saturation > 0.45) return c;
|
|
float luma = dot(c, vec3(0.299, 0.587, 0.114));
|
|
if (uTheme == 1) {
|
|
// blueprint: pale lines on shades of blue
|
|
if (isLine) return vec3(0.8, 0.9, 1.0) * min(1.0, strongest * 1.15);
|
|
return mix(vec3(0.04, 0.13, 0.3), vec3(0.2, 0.42, 0.75), clamp(luma * 5.0, 0.0, 1.0));
|
|
}
|
|
// day: light surfaces with a trace of their hue, dark blue lines
|
|
if (isLine) return vec3(0.08, 0.17, 0.38) * clamp(strongest * 1.4, 0.4, 1.0);
|
|
vec3 grey = vec3(clamp(0.66 + luma * 2.6, 0.0, 0.96));
|
|
return mix(grey, grey * (c / max(strongest, 0.001)), 0.1);
|
|
}
|
|
`;function Zn(i,e,t=!1){let n=i.onBeforeCompile.bind(i),r=i.customProgramCacheKey.bind(i);return i.onBeforeCompile=(s,o)=>{n(s,o),Object.assign(s.uniforms,{uTheme:e,uAccent:Xu,uAccentOn:Yu}),s.fragmentShader=s.fragmentShader.replace("#include <common>",`#include <common>
|
|
${pR}`).replace("#include <color_fragment>",`#include <color_fragment>
|
|
diffuseColor.rgb = nfThemed(diffuseColor.rgb, ${t});`)},i.customProgramCacheKey=()=>`${r()}-themed-${t?"l":"s"}`,i}var xl=i=>i==="day"?Ai:Ft;var mR=`#include <common>
|
|
attribute vec2 tile;
|
|
varying vec2 vNfTile;`,gR=`#include <begin_vertex>
|
|
vNfTile = tile;`,xR=`#ifdef USE_MAP
|
|
vec2 nfCell = fract(vMapUv);
|
|
vec2 nfUv = (vNfTile + 0.004 + nfCell * 0.992) / vec2(3.0, 2.0);
|
|
// gradients of the unwrapped coordinates avoid mip seams at the tile borders
|
|
vec4 sampledDiffuseColor = textureGrad(map, nfUv, dFdx(vMapUv) / vec2(3.0, 2.0), dFdy(vMapUv) / vec2(3.0, 2.0));
|
|
diffuseColor *= sampledDiffuseColor;
|
|
#endif`;function bR(i){let e=new Ke({map:i,transparent:!0,blending:Ft,depthWrite:!1,polygonOffset:!0,polygonOffsetFactor:-2});return e.onBeforeCompile=t=>{t.vertexShader=t.vertexShader.replace("#include <common>",mR).replace("#include <begin_vertex>",gR),t.fragmentShader=t.fragmentShader.replace("#include <common>",`#include <common>
|
|
varying vec2 vNfTile;`).replace("#include <map_fragment>",xR)},e.customProgramCacheKey=()=>"nf-pattern",e}var qu=(i={})=>new Ke({vertexColors:!0,transparent:!0,blending:Ft,depthWrite:!1,...i});function Ty({mask:i,look:e,theme:t,textures:n}){let r=(o={})=>new Ke({vertexColors:!0,...o}),s=(o,a)=>My(o,i,a);return{floor:Zn(r(),e),pattern:bR(n.pattern),wall:Zn(s(r(),"solid"),e),glassWall:s(r({transparent:!0,depthWrite:!1}),"glass"),shadow:r({blending:za,premultipliedAlpha:!0,transparent:!0,depthWrite:!1,side:ut,polygonOffset:!0,polygonOffsetFactor:-1}),lines:Zn(s(new Lt({vertexColors:!0,transparent:!0,blending:xl(t),depthWrite:!1})),e,!0),glow:s(qu({side:ut,polygonOffset:!0,polygonOffsetFactor:-3}),"solid"),frames:Zn(s(r({side:ut})),e),glass:s(qu({side:ut})),blinds:Zn(s(r({map:n.blinds,side:ut})),e),lamps:Zn(r(),e),halos:new cn({map:n.halo,size:.9,sizeAttenuation:!0,vertexColors:!0,transparent:!0,blending:Ft,depthWrite:!1}),cones:qu({side:ut}),screens:qu({side:ut}),ghosts:[]}}var $u=i=>Object.assign(document.createElement("span"),{className:i});function Ay(i,e){let t=Object.assign(document.createElement("button"),{className:"nf-dev"});t.dataset.entity=i,t.append($u("nf-dev-icon"),$u("nf-dev-text"),$u("nf-dev-watt"),$u("nf-dev-name"));let n,r=!1,s=a=>{let{x:l,y:c}=e.centre(t);a(i,l,c)},o=()=>clearTimeout(n);t.addEventListener("pointerdown",a=>{if(e.furnishing())return e.pressedWhileFurnishing(i);a.stopPropagation(),r=!1,o(),n=setTimeout(()=>{r=!0,s(e.hold)},500)});for(let a of["pointerleave","pointercancel","pointerup"])t.addEventListener(a,o);return t.addEventListener("contextmenu",a=>a.preventDefault()),t.addEventListener("click",a=>{if(a.stopPropagation(),e.furnishing())return e.selectWhileFurnishing(i);r||s(e.tap)}),t.addEventListener("keydown",a=>{(a.key==="Enter"&&a.shiftKey||a.key==="ContextMenu")&&(a.preventDefault(),s(e.hold))}),t}function Ey(i,e=10,t="NextFloor"){let n=[];for(let{positions:o,lift:a}of i)for(let l=0;l+8<o.length;l+=9){let c=[0,3,6].map(x=>[o[l+x]*e,-o[l+x+2]*e,(o[l+x+1]+a)*e]),[u,h,f]=c,d=[(h[1]-u[1])*(f[2]-u[2])-(h[2]-u[2])*(f[1]-u[1]),(h[2]-u[2])*(f[0]-u[0])-(h[0]-u[0])*(f[2]-u[2]),(h[0]-u[0])*(f[1]-u[1])-(h[1]-u[1])*(f[0]-u[0])],p=Math.hypot(d[0],d[1],d[2]);p<1e-9||n.push([d[0]/p,d[1]/p,d[2]/p,...u,...h,...f])}let r=new Uint8Array(84+n.length*50),s=new DataView(r.buffer);return r.set(new TextEncoder().encode(`${t} STL`.slice(0,79)),0),s.setUint32(80,n.length,!0),n.forEach((o,a)=>{let l=84+a*50;o.forEach((c,u)=>s.setFloat32(l+u*4,c,!0))}),r}var Rs=Math.PI/180;function Ry(i,e,t){let n=i.getTime()/864e5-10957.5,r=(357.529+.98560028*n)*Rs,o=(280.459+.98564736*n+1.915*Math.sin(r)+.02*Math.sin(2*r))*Rs,a=(23.439-36e-8*n)*Rs,l=Math.atan2(Math.cos(a)*Math.sin(o),Math.cos(o)),c=Math.asin(Math.sin(a)*Math.sin(o)),h=(((18.697374558+24.06570982441908*n)%24+24)%24*15+t)*Rs-l,f=e*Rs,d=Math.asin(Math.sin(f)*Math.sin(c)+Math.cos(f)*Math.cos(c)*Math.cos(h)),p=Math.atan2(Math.sin(h),Math.cos(h)*Math.sin(f)-Math.tan(c)*Math.cos(f))/Rs+180;return{elevation:d/Rs,azimuth:(p%360+360)%360}}function fp(i,e){let t=Object.fromEntries(new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric"}).formatToParts(new Date(i)).map(n=>[n.type,Number(n.value)]));return Date.UTC(t.year,t.month-1,t.day,t.hour,t.minute,t.second)}function Cy(i,e,t=new Date){let[n,r]=[Math.floor(i),Math.round(i%1*60)];if(e)try{let o=new Date(fp(t.getTime(),e)),a=Date.UTC(o.getUTCFullYear(),o.getUTCMonth(),o.getUTCDate(),n,r),l=a-(fp(a,e)-a);return l=a-(fp(l,e)-l),new Date(l)}catch{}let s=new Date(t);return s.setHours(n,r,0,0),s}function yR(i,e=new Date){let t=[];for(let n=0;n<=24;n+=.25){let r=Ry(Cy(Math.min(n,23.99),i.zone,e),i.latitude,i.longitude);r.elevation<0||t.push(Py(i,r))}return t}function Py(i,e){let[t,n]=Lo(e.azimuth,i.north),r=Math.max(0,e.elevation)*Math.PI/180;return[i.centre[0]+t*i.radius*Math.cos(r),Math.sin(r)*i.radius*.9,i.centre[1]+n*i.radius*Math.cos(r)]}function _R(i,e){let t=document.createElement("canvas");t.width=t.height=64;let n=t.getContext("2d");n&&(n.font="bold 44px system-ui, sans-serif",n.fillStyle=e,n.textAlign="center",n.textBaseline="middle",n.fillText(i,32,34));let r=new ji(new vi({map:new zt(t),transparent:!0,depthWrite:!1,depthTest:!1}));return r.renderOrder=20,r}var Ku=class{group=new ct;key="";constructor(){this.group.visible=!1,this.group.renderOrder=15}update(e,t,n){let r=e?`${e.centre},${e.radius.toFixed(1)},${e.north},${e.latitude.toFixed(2)},${e.longitude.toFixed(2)},${new Date().toDateString()},${n},${t?`${t.elevation.toFixed(0)},${t.azimuth.toFixed(0)}`:"-"}`:"off";if(r===this.key)return;if(this.key=r,this.clear(),!e){this.group.visible=!1;return}this.group.visible=!0;let s=n+.05,o=[];for(let h=0;h<=96;h++){let f=h/96*Math.PI*2;o.push(e.centre[0]+Math.cos(f)*e.radius,s,e.centre[1]+Math.sin(f)*e.radius)}let a=new Fe;a.setAttribute("position",new ke(o,3)),this.group.add(new Pn(a,new Lt({color:7311304,transparent:!0,opacity:.55,depthWrite:!1})));let l=[];[["N",0],["E",90],["S",180],["W",270]].forEach(([h,f])=>{let[d,p]=Lo(f,e.north);l.push(e.centre[0]+d*e.radius*.94,s,e.centre[1]+p*e.radius*.94,e.centre[0]+d*e.radius*1.04,s,e.centre[1]+p*e.radius*1.04);let x=_R(h,h==="N"?"#ff6b6b":"#9fb4d8");x.position.set(e.centre[0]+d*e.radius*1.12,s+.4,e.centre[1]+p*e.radius*1.12),x.scale.setScalar(Math.max(1.2,e.radius*.12)),this.group.add(x)});let c=new Fe;c.setAttribute("position",new ke(l,3)),this.group.add(new gn(c,new Lt({color:10466520,transparent:!0,opacity:.8,depthWrite:!1})));let u=yR(e).map(([h,f,d])=>[h,n+f,d]);if(u.length>1){let h=new Fe;h.setAttribute("position",new ke(u.flat(),3)),this.group.add(new Pn(h,new Lt({color:16761415,transparent:!0,opacity:.85,depthWrite:!1})))}if(t&&t.elevation>0){let[h,f,d]=Py(e,t),p=new we(new Ca(Math.max(.35,e.radius*.035),12,8),new Ke({color:16765530}));p.position.set(h,n+f,d),this.group.add(p)}}clear(){for(let e of[...this.group.children]){this.group.remove(e);let t=e;t.geometry?.dispose();let n=t.material;n?.map?.dispose(),n?.dispose()}}dispose(){this.clear()}};var vR=["straight","quarter","l","half","u","spiral"],MR=["solid","stringer","mono","cantilever"],SR=["none","left","right","both"],wR=["headroom","full","none"],Zu={shape:"straight",turn:"right",build:"solid",risers:!0,steps:null,run_width:null,down:!1,rail:"none",opening:"headroom",landing_after:null};var Ny=2,Dy=40,TR=2.2,Ju=(i,e)=>typeof e=="string"&&i.includes(e);function dp(i){let e=i.stair??{},t=typeof e.steps=="number"&&Number.isFinite(e.steps)?Math.round(Math.min(Dy,Math.max(Ny,e.steps))):null,n=typeof e.run_width=="number"&&Number.isFinite(e.run_width)&&e.run_width>.2?e.run_width:null;return{shape:Ju(vR,e.shape)?e.shape:Zu.shape,turn:e.turn==="left"?"left":"right",build:Ju(MR,e.build)?e.build:Zu.build,risers:e.risers!==!1,steps:t,run_width:n,down:e.down===!0,rail:Ju(SR,e.rail)?e.rail:Zu.rail,opening:Ju(wR,e.opening)?e.opening:Zu.opening,landing_after:typeof e.landing_after=="number"&&Number.isFinite(e.landing_after)?Math.max(1,Math.round(e.landing_after)):null}}var Qu=i=>i.type==="stairs"&&!!i.stair,yl=(i,e,t)=>[i[0]+(e[0]-i[0])*t,i[1]+(e[1]-i[1])*t],Iy=(i,e)=>Math.abs(i[0]-e[0])<1e-6&&Math.abs(i[1]-e[1])<1e-6;function Uy(i){let e=[];for(let t of i)(!e.length||!Iy(e[e.length-1],t))&&e.push(t);for(;e.length>1&&Iy(e[0],e[e.length-1]);)e.pop();return e}function _l(i,e,t=!1){return{poly:Uy([...i,...[...e].reverse()]),landing:t,left:i,right:e}}function bl(i,e,t,n,r){let s=[];for(let o=0;o<r;o++){let[a,l]=[o/r,(o+1)/r];s.push(_l([yl(i,t,a),yl(i,t,l)],[yl(e,n,a),yl(e,n,l)]))}return s}function Ly(i,e){let t=e;for(let n=0;n+1<i.length;n++){let r=Math.hypot(i[n+1][0]-i[n][0],i[n+1][1]-i[n][1]);if(t<=r||n+2===i.length)return yl(i[n],i[n+1],r?Math.min(1,t/r):0);t-=r}return i[i.length-1]}function AR(i,e,t){let n=[Ly(i,e)],r=0;for(let s=0;s+1<i.length;s++)r+=Math.hypot(i[s+1][0]-i[s][0],i[s+1][1]-i[s][1]),r>e+1e-6&&r<t-1e-6&&n.push(i[s+1]);return n.push(Ly(i,t)),n}var ER=i=>i.reduce((e,t,n)=>n?e+Math.hypot(t[0]-i[n-1][0],t[1]-i[n-1][1]):e,0);function Fy(i,e,t,n,r){let s=ER(i),o=[];for(let a=0;a<r;a++){let l=Uy([...a===0?[e]:[],t,...a===r-1?[n]:[]]);o.push(_l(AR(i,s*a/r,s*(a+1)/r),l.length?l:[t]))}return o}function ju(i,e,t){if(i<=0)return[0,0];if(e<=.001)return[0,i];if(t<=.001)return[i,0];let n=Math.min(i,Math.max(0,Math.round(i*e/(e+t))));return[n,i-n]}function Oy(i,e){if(i.landing_after==null)return null;let t=Math.min(e-1,Math.max(1,Math.round(i.landing_after)))-1;return[t,e-1-t]}function RR(i,e,t,n){let[r,s,o,a]=[-e/2,e/2,-t/2,t/2];switch(i.shape){case"quarter":case"l":{let l=Math.min(i.run_width??Math.min(1,Math.min(e,t)/2),Math.min(e,t)-.05),c=[r+l,o+l],u=[[r,o+l],[r,o],[r+l,o]],h=i.shape==="l"?1:Math.min(n,n>=8?3:2),[f,d]=i.shape==="l"?Oy(i,n)??ju(n-h,t-l,e-l):ju(n-h,t-l,e-l),p=bl([r,a],[r+l,a],[r,o+l],c,f),x=i.shape==="l"?[_l(u,[c],!0)]:Fy(u,c,c,c,h),g=bl([r+l,o],c,[s,o],[s,o+l],d);return{treads:[...p,...x,...g],flight:l,column:0}}case"half":case"u":{let l=Math.min(i.run_width??Math.min(1.1,(e-.1)/2),(e-.02)/2),c=o+l,u=[[r,c],[r,o],[s,o],[s,c]],[h,f]=[[r+l,c],[s-l,c]],d=i.shape==="u"?1:Math.min(n,n>=12?6:n>=8?4:2),[p,x]=i.shape==="u"?Oy(i,n)??ju(n-d,t-l,t-l):ju(n-d,t-l,t-l),g=bl([r,a],[r+l,a],[r,c],h,p),m=i.shape==="u"?[_l(u,[h,f],!0)]:Fy(u,h,[0,c],f,d),b=bl([s,c],f,[s,a],[s-l,a],x);return{treads:[...g,...m,...b],flight:l,column:0}}case"spiral":{let l=Math.min(e,t)/2,c=Math.min(.08,l*.12),u=Math.min(.75,Math.max(.3,.22/(l*.6))),h=(d,p)=>[Math.cos(p)*d,Math.sin(p)*d],f=[];for(let d=0;d<n;d++){let[p,x]=[Math.PI+u*d,Math.PI+u*(d+1)],g=[0,.5,1].map(m=>h(l,p+(x-p)*m));f.push(_l(g,[h(c,p),h(c,x)]))}return{treads:f,flight:l-c,column:c}}default:return{treads:bl([r,a],[s,a],[r,o],[s,o],n),flight:e,column:0}}}var CR=(i,e)=>i.steps??Math.min(Dy,Math.max(Ny,Math.round(Math.abs(e)/.18)));function pp(i,e,t,n){let r=CR(i,n),s=Math.abs(n)/r,o=RR(i,Math.max(.3,e),Math.max(.3,t),r),a=c=>[-c[0],c[1]];return{treads:o.treads.map((c,u)=>{let h=i.down?-s*(u+1):s*(u+1);return i.turn==="right"?{...c,top:h}:{poly:c.poly.map(a).reverse(),top:h,landing:c.landing,left:c.right.map(a),right:c.left.map(a)}}),rise:s,steps:r,column:o.column,flight:o.flight}}function By(i){let e=i.poly.reduce((t,n)=>[t[0]+n[0],t[1]+n[1]],[0,0]);return[e[0]/i.poly.length,e[1]/i.poly.length]}function PR(i,e,t,n="headroom"){if(n==="none")return[];let r=t?0:Math.abs(e),s=n==="full"?i.treads:i.treads.filter((o,a)=>o.top>r-TR||!t&&a===i.treads.length-1||t&&a===0);return fr(s.map(o=>o.poly).filter(o=>o.length>=3))}function mp(i){let e=dp(i),t=PR(pp(e,i.w,i.d,i.h),i.h,e.down,e.opening),n=i.rotation*Math.PI/180,[r,s]=[Math.cos(n),Math.sin(n)],o=i.mirror?-1:1;return t.map(a=>a.map(([l,c])=>[i.x+o*l*r-c*s,i.z+o*l*s+c*r]))}function Ni(i,e,t,n,r,s,o=Pe.metal,a=!1){let[l,c]=[e/2-s-r,t/2-s-r],u=mt(o);for(let h of[-1,1])for(let f of[-1,1]){let[d,p]=[h*l,f*c];a?i.loft([d-r*.3,d+r*.3,p-r*.3,p+r*.3],[d-r/2,d+r/2,p-r/2,p+r/2],0,n,u):i.block({x:[d-r/2,d+r/2],y:[0,n],z:[p-r/2,p+r/2]},u)}}function Cs(i,e,t,n,r,s,o,a=null,l=!1){let c=(t-e)/o;for(let u=1;u<o;u++)i.seg(e+c*u,n,s,e+c*u,r,s,Je);for(let u=0;u<o;u++){let h=e+c*(u+.5),f=a??r-.08;if(l){let d=Math.min(.1,c/4);i.seg(h-d,f,s+.012,h+d,f,s+.012,qe)}else{let d=o>1?h+(u%2?-c/2+.06:c/2-.06):h+c/2-.06;i.seg(d,f-.08,s+.012,d,f+.08,s+.012,qe)}}}function fi(i,e,t,n,r,s=null,o=!1,a=Z.body){i.block({x:[-e/2,e/2],y:[.02,n],z:[-t/2,t/2-.02]},a,pe),i.block({x:[-e/2+.02,e/2-.02],y:[0,.08],z:[-t/2+.02,t/2-.06]},mt(Pe.dark)),Cs(i,-e/2,e/2,.08,n,t/2-.02,r,s,o)}function gp(i,e,t,n,r){let[s,o,a,l]=[-e/2,e/2,-t/2,t/2],c=Math.min(.2,e*.12),u=n*.5,h=Math.min(.24,t*.28);Ni(i,e,t,.07,.05,.05,Pe.wood,!0),i.pad({x:[s,o],y:[.07,u-.08],z:[a+.02,l]},Z.fabric,.04,pe),i.loft([s,o,a,a+h],[s+.01,o-.01,a,a+h*.5],u-.08,n,Z.fabric,pe);for(let[d,p]of[[s,s+c],[o-c,o]])i.pad({x:[d,p],y:[u-.08,n*.72],z:[a+.02,l-.02]},Z.fabric,.04,pe);let f=(o-c-(s+c))/r;for(let d=0;d<r;d++){let p=s+c+f*d+.02,x=p+f-.04;i.pad({x:[p,x],y:[u-.08,u+.05],z:[a+h+.02,l-.06]},Z.cushion,.04),i.loft([p+.01,x-.01,a+h*.55,a+h+.14],[p+.03,x-.03,a+h*.4,a+h*.4+.06],u+.03,n*.93,Z.cushion)}}function ky(i,e,t,n,r){let[s,o,a,l]=[-e/2,e/2,-t/2,t/2],c=n*.5,u=Math.min(.24,t*.2),h=Math.min(.95,t*.55),f=Math.min(.9,e*(r==="u"?.28:.34)),d=.16;Ni(i,e,t,.07,.05,.05,Pe.wood,!0),i.pad({x:[s,o],y:[.07,c-.08],z:[a+.02,a+h]},Z.fabric,.04,pe);let p=r==="u"?[[s,s+f],[o-f,o]]:[[o-f,o]];for(let[v,y]of p)i.pad({x:[v,y],y:[.07,c-.08],z:[a+h-.04,l]},Z.fabric,.04,pe);i.loft([s,o,a,a+u],[s+.01,o-.01,a,a+u*.5],c-.08,n,Z.fabric,pe),r==="l"&&i.pad({x:[s,s+d],y:[c-.08,n*.72],z:[a+.02,a+h-.02]},Z.fabric,.04,pe);for(let[v,y]of p){let M=v<=s+1e-6?[v,v+d]:[y-d,y];i.pad({x:[M[0],M[1]],y:[c-.08,n*.62],z:[a+.02,l-.02]},Z.fabric,.04,pe)}let x=r==="u"?s+f:s+d,g=o-f,m=Math.max(1,Math.round((g-x)/.62)),b=(g-x)/m;for(let v=0;v<m;v++){let y=x+b*v+.02,M=y+b-.04;i.pad({x:[y,M],y:[c-.08,c+.05],z:[a+u+.02,a+h-.06]},Z.cushion,.04),i.loft([y+.01,M-.01,a+u*.55,a+u+.14],[y+.03,M-.03,a+u*.4,a+u*.4+.06],c+.03,n*.93,Z.cushion)}for(let[v,y]of p){let M=v<=s+1e-6?[v+d+.02,y-.02]:[v+.02,y-d-.02];i.pad({x:[M[0],M[1]],y:[c-.08,c+.05],z:[a+u+.02,l-.06]},Z.cushion,.04)}}function zy(i,e,t,n){let[r,s,o,a]=[-e/2,e/2,-t/2,t/2],l=Math.min(.32,n*.36);Ni(i,e,t,.08,.06,.03,Pe.wood,!0),i.block({x:[r,s],y:[.08,l],z:[o+.06,a]},Z.wood,pe),i.pad({x:[r+.03,s-.03],y:[l,l+.2],z:[o+.08,a-.03]},Z.bedding,.03),i.block({x:[r,s],y:[.08,n-.05],z:[o,o+.07]},Z.wood,pe),i.block({x:[r,s],y:[n-.05,n],z:[o,o+.09]},Z.wood,Je);let c=l+.2,u=o+(t-.1)*.36;i.pad({x:[r+.01,s-.01],y:[c-.1,c+.05],z:[u,a-.01]},Z.cushionSoft,.025,Je),i.lyingCylinder("x",0,u+.05,c-.02,c+.09,e-.02,.1,Z.cushionSoft,8);let h=e>1.2?2:1,f=(e-.2)/h;for(let d=0;d<h;d++){let p=r+.1+f*d,x=o+.12,g=Math.min(.42,t*.2),m=.1;i.loft([p+.03+m,p+f-.03-m,x+m*.5,x+g-m*.5],[p+.03,p+f-.03,x,x+g],c,c+.06,Z.pillow),i.loft([p+.03,p+f-.03,x,x+g],[p+.03+m,p+f-.03-m,x+m*.5,x+g-m*.5],c+.06,c+.12,Z.pillow,Je)}}function Vy(i,e,t,n){let r=Math.min(.46,n*.52);Ni(i,e,t,r-.04,.035,.02,Pe.wood,!0),i.block({x:[-e/2,e/2],y:[r-.04,r],z:[-t/2,t/2]},Z.wood,pe),i.pad({x:[-e/2+.02,e/2-.02],y:[r,r+.04],z:[-t/2+.05,t/2-.03]},Z.cushion,.015),i.loft([-e/2,e/2,-t/2+.02,-t/2+.07],[-e/2+.02,e/2-.02,-t/2,-t/2+.03],r,n,Z.wood,pe)}function Gy(i,e,t,n){let r=Math.min(e,t)/2;i.cylinder(0,0,r*.8,0,.02,Z.metal,12),i.cylinder(0,0,.025,.02,n-.05,Z.metal,6),i.cylinder(0,0,r*.75,n*.35,n*.35+.015,Z.metal,12,Je),i.cylinder(0,0,r,n-.05,n,Z.cushionSoft,14,pe)}function Hy(i,e,t,n){let r=Math.min(e,t)/2;i.block({x:[-r,r],y:[.04,.08],z:[-.03,.03]},Z.metal),i.block({x:[-.03,.03],y:[.04,.08],z:[-r,r]},Z.metal),i.cylinder(0,0,.06,.02,.1,Z.dark,8),i.cylinder(0,0,.025,.1,.44,Z.metal,6),i.block({x:[-r*.75,r*.75],y:[.44,.52],z:[-r*.7,r*.75]},mt(Pe.fabric,Pe.cushion),pe),i.block({x:[-r*.7,r*.7],y:[.58,n],z:[-r*.78,-r*.62]},Z.fabric,pe),i.block({x:[-.03,.03],y:[.5,.62],z:[-r*.72,-r*.62]},Z.metal)}function Wy(i,e,t,n){Ni(i,e,t,.08,.04,.05,Pe.wood),i.block({x:[-e/2,e/2],y:[.08,n],z:[-t/2,t/2]},mt(Pe.fabric,Pe.cushion),pe)}function xp(i,e,t,n,r){let o=Math.min(.5,r?t*.4:t),a=.08,l=mt(Pe.cushion);i.block({x:[-e/2,e/2],y:[0,.45-.06],z:[-t/2,-t/2+o]},Z.wood,pe),i.block({x:[-e/2,e/2],y:[0,n],z:[-t/2,-t/2+a]},Z.wood,pe),i.block({x:[-e/2+(r?o:.02),e/2-.02],y:[.45-.06,.45+.02],z:[-t/2+a,-t/2+o]},l,Je),r&&(i.block({x:[-e/2,-e/2+o],y:[0,.45-.06],z:[-t/2+o,t/2]},Z.wood,pe),i.block({x:[-e/2,-e/2+a],y:[0,n],z:[-t/2+a,t/2]},Z.wood,pe),i.block({x:[-e/2+a,-e/2+o],y:[.45-.06,.45+.02],z:[-t/2+a,t/2-.02]},l,Je))}function Xy(i,e,t,n){for(let o of[-1,1])for(let a of[-1,1])i.block({x:[o*(e/2)-(o>0?.05:0),o*(e/2)+(o<0?.05:0)],y:[0,n],z:[a*(t/2)-(a>0?.05:0),a*(t/2)+(a<0?.05:0)]},Z.wood);for(let o of[.25,n-.55])i.block({x:[-e/2,e/2],y:[o,o+.08],z:[-t/2,t/2]},Z.wood,pe),i.block({x:[-e/2+.04,e/2-.04],y:[o+.08,o+.24],z:[-t/2+.05,t/2-.05]},Z.bedding,Je),i.block({x:[-e/2+.05,e/2-.05],y:[o+.24,o+.33],z:[-t/2+.08,-t/2+.4]},Z.pillow);i.block({x:[-e/2,e/2],y:[n-.2,n-.15],z:[t/2-.05,t/2]},Z.wood);let s=e/2-.35;for(let o of[s-.18,s+.18])i.seg(o,0,t/2+.02,o,n-.15,t/2+.02,pe);for(let o=.3;o<n-.2;o+=.28)i.seg(s-.18,o,t/2+.02,s+.18,o,t/2+.02,Je)}var yp=(i,e,t,n)=>i.block({x:[-e/2,e/2],y:[n-.04,n],z:[-t/2,t/2]},Z.worktop,pe);function Yy(i,e,t,n){fi(i,e,t-.02,n-.04,Math.max(1,Math.round(e/.6)),n-.2),yp(i,e,t,n)}function qy(i,e,t,n){i.block({x:[-e/2,e/2],y:[Math.max(0,n-.04),n],z:[-t/2,t/2]},Z.worktop,pe)}function $y(i,e,t,n){i.block({x:[-e/2,e/2],y:[0,n],z:[-t/2,t/2]},Z.white,pe);let r=n*.62;i.seg(-e/2,r,t/2,e/2,r,t/2,Je);let s=e/2-.06;i.seg(s,r+.08,t/2+.015,s,r+.4,t/2+.015,qe),i.seg(s,r-.4,t/2+.015,s,r-.08,t/2+.015,qe)}var _p=.06;function Ky(i,e,t,n){let r=t/2-_p;i.block({x:[-e/2,e/2],y:[.02,n],z:[-t/2,r]},Z.body,pe),i.block({x:[-e/2+.05,e/2-.05],y:[0,.02],z:[-t/2+.05,r-.05]},Z.dark);for(let s of[.35,.7,1.05,1.4])s>n-.15||(i.seg(-e/2+.03,s,r+.001,-.03,s,r+.001,Je),i.seg(.03,s,r+.001,e/2-.03,s,r+.001,Je))}var bp=1.83;function IR(i,e,t,n,r){let[s,o]=[Math.cos(e.rotation*pt),Math.sin(e.rotation*pt)],a=e.mirror?-1:1,l=(b,v)=>[e.x+a*b*s-v*o,e.z+a*b*o+v*s],[c,u]=[t+.05,t+e.h-.02],h=new W(.75,.1,.14),f=new W(Pe.dark),d=new W(Pe.accent),p=e.w/2-.006,x=(b,v,y)=>{let M=y/bp,S=new W(2043212).lerp(h,M),_=new W(Pe.body).lerp(h,M*.8),[w,R]=[Math.cos(y),Math.sin(y)],A=(D,P)=>l(b+v*(D*w-P*R),e.d/2+D*R+P*w),C=(D,P,I,N)=>{let[F,H,B,X]=D;i.tri([F[0],P,F[1]],[H[0],P,H[1]],[B[0],I,B[1]],N),i.tri([F[0],P,F[1]],[B[0],I,B[1]],[X[0],I,X[1]],N)},O=(D,P,I,N,F,H,B,X=B)=>{let V=[A(D,H),A(P,H),A(P,F),A(D,F)];C([V[0],V[1],V[1],V[0]],I,N,X),C([V[3],V[2],V[2],V[3]],I,N,B),C([V[0],V[3],V[3],V[0]],I,N,B),C([V[1],V[2],V[2],V[1]],I,N,B),C([V[0],V[1],V[2],V[3]],N,N,B),C([V[3],V[2],V[1],V[0]],I,I,B)};return O(0,p,c,u,-_p,0,_,S),O(p-.05,p-.03,t+e.h*.45,t+e.h*.75,.005,.025,d),O};x(-e.w/2,1,n*bp)(.12,.3,t+e.h*.5,t+e.h*.68,.001,.005,f),x(e.w/2,-1,r*bp)(.06,p-.06,t+e.h*.52,t+e.h*.86,.001,.005,f)}function vp(i,e,t,n,r){let s=i.p.length;IR(i,e,t,n,r),e.mirror&&vs(i,s)}function Zy(i,e,t,n){fi(i,e,t-.02,n-.04,1,n-.24,!0),i.block({x:[-e/2,e/2],y:[n-.04,n],z:[-t/2,t/2]},Z.dark,pe);let r=[[-.14,-.13,.09],[.14,-.13,.07],[-.14,.13,.07],[.14,.13,.09]];for(let[s,o,a]of r)i.cylinder(s*e/.6,o*t/.62,a,n,n+.004,mt(Pe.dark,1451583),12,qe)}function Jy(i,e,t,n){fi(i,e,t-.02,n-.04,Math.max(1,Math.round(e/.45)),n-.2);let r=Math.min(.5,e-.2),s=(o,a,l,c,u=!1)=>i.block({x:[o,a],y:[n-.04,n],z:[l,c]},Z.worktop,u?pe:null);s(-e/2,-r/2,-t/2,t/2,!0),s(r/2,e/2,-t/2,t/2,!0),s(-r/2,r/2,-t/2,-t/2+.1),s(-r/2,r/2,t/2-.08,t/2),i.block({x:[-r/2,r/2],y:[n-.2,n-.17],z:[-t/2+.1,t/2-.08]},Z.metal,qe),i.cylinder(0,-t/2+.05,.02,n,n+.28,Z.metal,8),i.block({x:[-.015,.015],y:[n+.24,n+.28],z:[-t/2+.05,-t/2+.22]},Z.metal)}function jy(i,e,t,n){i.block({x:[-e/2,e/2],y:[1.45,1.45+n],z:[-t/2,t/2-.02]},Z.body,pe),Cs(i,-e/2,e/2,1.45,1.45+n,t/2-.02,Math.max(1,Math.round(e/.5)),1.45+.08)}function Qy(i,e,t,n){i.block({x:[-e/2,e/2],y:[.02,n],z:[-t/2,t/2-.02]},Z.body,pe),i.block({x:[-e/2+.02,e/2-.02],y:[0,.08],z:[-t/2+.02,t/2-.06]},Z.dark);let r=t/2-.02;i.block({x:[-e/2+.03,e/2-.03],y:[.85,1.45],z:[r,r+.01]},Z.dark,qe),i.seg(-e/2+.08,1.4,r+.02,e/2-.08,1.4,r+.02,qe);for(let s of[.85,1.45])i.seg(-e/2,s,r,e/2,s,r,Je);i.seg(e/2-.06,.5,r+.012,e/2-.06,.7,r+.012,qe),i.seg(e/2-.06,1.6,r+.012,e/2-.06,1.8,r+.012,qe)}function e_(i,e,t,n){let r=t-.3;i.block({x:[-e/2+.05,e/2-.05],y:[.08,n-.04],z:[-t/2+.02,-t/2+r]},Z.body,pe),i.block({x:[-e/2+.07,e/2-.07],y:[0,.08],z:[-t/2+.04,-t/2+r-.04]},Z.dark),Cs(i,-e/2+.05,e/2-.05,.08,n-.04,-t/2+r,Math.max(2,Math.round(e/.6)),n-.2),yp(i,e,t,n)}function t_(i,e,t,n){i.block({x:[-e/2,e/2],y:[.02,n-.04],z:[-t/2,t/2-.02]},Z.body,pe),i.block({x:[-e/2+.02,e/2-.02],y:[0,.08],z:[-t/2+.02,t/2-.06]},Z.dark),i.seg(-e/2+.08,n-.12,t/2-.008,e/2-.08,n-.12,t/2-.008,qe),yp(i,e,t,n)}function Mp(i,e,t,n,r){i.block({x:[-e/2,e/2],y:[0,n],z:[-t/2,t/2-.02]},Z.white,pe);let s=t/2-.012;i.seg(-e/2,n-.14,s,e/2,n-.14,s,Je),i.seg(e/2-.16,n-.07,s,e/2-.08,n-.07,s,qe);let o=(n-.14)/2+.04,a=Math.min(e*.36,(n-.2)*.42),l=20;for(let c=0;c<l;c++){let[u,h]=[c/l*Math.PI*2,(c+1)/l*Math.PI*2],f=(d,p)=>i.seg(Math.cos(u)*a*d,o+Math.sin(u)*a*d,s,Math.cos(h)*a*d,o+Math.sin(h)*a*d,s,p);f(1,qe),r||f(.72,Je)}}function n_(i,e,t,n){i.block({x:[-e/2,e/2],y:[0,n-.02],z:[-t/2,t/2]},Z.white,pe);let s=(o,a,l,c)=>i.block({x:[o,a],y:[n-.02,n],z:[l,c]},Z.worktop);s(-e/2,e/2,-t/2,-t/2+.07),s(-e/2,e/2,t/2-.07,t/2),s(-e/2,-e/2+.07,-t/2+.07,t/2-.07),s(e/2-.07,e/2,-t/2+.07,t/2-.07),i.block({x:[-e/2+.07,e/2-.07],y:[n-.03,n-.02],z:[-t/2+.07,t/2-.07]},Z.glass,qe),i.cylinder(-e/2+.04,0,.02,n,n+.12,Z.metal,8)}function i_(i,e,t,n){i.block({x:[-e/2,e/2],y:[0,.05],z:[-t/2,t/2]},Z.worktop,pe),i.cylinder(0,0,.04,.05,.052,Z.metal,8);for(let[r,s,o,a]of[[-e/2,t/2,e/2,t/2],[e/2,-t/2,e/2,t/2]])i.seg(r,.05,s,o,.05,a,qe),i.seg(r,n,s,o,n,a,qe),i.seg(o,.05,a,o,n,a,qe);i.cylinder(-e/2+.06,-t/2+.06,.015,.05,n-.05,Z.metal,6),i.cylinder(-e/2+.2,-t/2+.2,.1,n-.08,n-.06,Z.metal,12,qe)}function r_(i,e,t,n){let r=Math.min(.18,t*.3);i.block({x:[-e/2,e/2],y:[.45,n],z:[-t/2,-t/2+r]},Z.white,pe),i.block({x:[-e*.3,e*.3],y:[0,.36],z:[-t/2+r-.02,t/2-.12]},Z.white),i.cylinder(0,t/2-.26,Math.min(e/2,.19),.36,.41,Z.white,12,pe),i.block({x:[-e/2+.02,e/2-.02],y:[.41,.43],z:[-t/2+r,-t/2+r+.05]},Z.worktop)}function s_(i,e,t,n){fi(i,e,t-.02,n-.12,e>.8?2:1,n-.3),i.block({x:[-e/2,e/2],y:[n-.12,n],z:[-t/2,t/2]},Z.white,pe),i.block({x:[-e/2+.07,e/2-.07],y:[n-.005,n],z:[-t/2+.12,t/2-.06]},Z.glass,qe),i.cylinder(0,-t/2+.06,.018,n,n+.2,Z.metal,8),i.block({x:[-e/2+.04,e/2-.04],y:[n+.35,n+1],z:[-t/2,-t/2+.02]},Z.glass,qe)}var vl=.12;function o_(i,e,t,n){let r=vl;i.block({x:[-e/2+.05,-e/2+.08],y:[0,r],z:[-t/2,-t/2+.03]},Z.metal),i.block({x:[e/2-.08,e/2-.05],y:[0,r],z:[-t/2,-t/2+.03]},Z.metal),i.block({x:[-e/2,e/2],y:[r,r+n],z:[-t/2+.02,t/2]},Z.white,pe);let s=Math.max(3,Math.round(e/.1));for(let o=1;o<s;o++){let a=-e/2+e/s*o;i.seg(a,r+.03,t/2+.002,a,r+n-.03,t/2+.002,Je)}}function a_(i,e,t,n){Ni(i,e,t,n-.04,.06,.05,Pe.wood,!0),i.block({x:[-e/2,e/2],y:[n-.04,n],z:[-t/2,t/2]},Z.wood,qe),i.block({x:[-e/2+.08,e/2-.08],y:[n-.1,n-.04],z:[-t/2+.08,t/2-.08]},mt(Pe.body))}function l_(i,e,t,n){let r=Math.min(e,t)/2;i.cylinder(0,0,r*.4,0,.03,Z.metal,12),i.cylinder(0,0,.05,.03,n-.04,mt(Pe.wood),8),i.cylinder(0,0,r,n-.04,n,Z.wood,20,pe)}function c_(i,e,t,n){Ni(i,e,t,n-.03,.04,.03,Pe.wood),i.block({x:[-e/2,e/2],y:[n-.03,n],z:[-t/2,t/2]},Z.wood,pe),i.block({x:[-e/2+.05,e/2-.05],y:[.1,.13],z:[-t/2+.05,t/2-.05]},Z.body,Je)}function u_(i,e,t,n){let[r,s]=[-e/2,e/2];i.block({x:[r,s],y:[n-.035,n],z:[-t/2,t/2]},Z.wood,pe),i.block({x:[r,r+.03],y:[0,n-.035],z:[-t/2+.03,t/2-.03]},Z.metal);let o=Math.min(.42,e*.32);i.block({x:[s-o,s],y:[0,n-.035],z:[-t/2+.03,t/2-.02]},Z.body,pe);let a=t/2-.02;for(let l of[n*.35,n*.66])i.seg(s-o,l,a,s,l,a,Je);for(let l of[n*.2,n*.5,n*.82])i.seg(s-o/2-.07,l,a+.012,s-o/2+.07,l,a+.012,qe);i.block({x:[-.3,.3],y:[n+.08,n+.42],z:[-t/2+.08,-t/2+.11]},Z.dark,qe),i.block({x:[-.03,.03],y:[n,n+.1],z:[-t/2+.09,-t/2+.13]},Z.metal)}function h_(i,e,t,n){fi(i,e,t,n,1,n*.72,!0),i.seg(-e/2,n*.5,t/2-.02,e/2,n*.5,t/2-.02,Je)}function f_(i,e,t,n){i.block({x:[-e/2,-e/2+.025],y:[0,n],z:[-t/2,t/2]},Z.wood,pe),i.block({x:[e/2-.025,e/2],y:[0,n],z:[-t/2,t/2]},Z.wood,pe),i.block({x:[-e/2+.025,e/2-.025],y:[0,n],z:[-t/2,-t/2+.015]},mt(Pe.body));let s=Math.max(2,Math.round(n/.38));for(let o=0;o<=s;o++){let a=Math.min(n-.025,n/s*o);if(i.block({x:[-e/2+.025,e/2-.025],y:[a,a+.025],z:[-t/2+.015,t/2]},Z.wood,Je),o===s)continue;let l=-e/2+.025+.04,c=o*3;for(;l<e/2-.025-.12;){let u=.03+c*7%5*.008,h=n/s-.025-.08-c*5%4*.025;c*11%7!==0&&i.block({x:[l,l+u],y:[a+.025,a+.025+h],z:[-t/2+.04,t/2-.05]},c%3?Z.fabric:mt(Pe.cushion,Pe.fabricTop)),l+=u+.006,c++}}}function d_(i,e,t,n){Ni(i,e,t,.12,.03,.04,Pe.metal),i.block({x:[-e/2,e/2],y:[.12,n],z:[-t/2,t/2-.02]},Z.wood,pe),Cs(i,-e/2,e/2,.12,n,t/2-.02,Math.max(2,Math.round(e/.45)),n-.1,!0)}function p_(i,e,t,n){i.block({x:[-e/2,e/2],y:[.06,n],z:[-t/2,t/2-.02]},Z.wood,pe),i.block({x:[-e/2+.02,e/2-.02],y:[0,.06],z:[-t/2+.02,t/2-.06]},Z.dark);let r=Math.max(3,Math.round((n-.06)/.22)),s=t/2-.02,o=(n-.06)/r;for(let a=1;a<r;a++)i.seg(-e/2,.06+o*a,s,e/2,.06+o*a,s,Je);for(let a=0;a<r;a++)i.seg(-.08,.06+o*(a+.5),s+.012,.08,.06+o*(a+.5),s+.012,qe)}function m_(i,e,t,n){i.block({x:[-e/2,e/2],y:[0,.45],z:[-t/2,t/2]},Z.wood,pe),Cs(i,-e/2,e/2,.02,.45,t/2,Math.max(2,Math.round(e/.5)),.38,!0),i.block({x:[-e/2,e/2],y:[.45,n],z:[-t/2,-t/2+.03]},Z.body,pe),i.block({x:[-e/2,e/2],y:[n-.04,n],z:[-t/2,t/2]},Z.wood,pe);let r=Math.max(2,Math.round(e/.25));for(let s=0;s<r;s++){let o=-e/2+e/r*(s+.5);i.block({x:[o-.015,o+.015],y:[n-.32,n-.28],z:[-t/2+.03,-t/2+.1]},Z.metal)}}function g_(i,e,t,n){let r=Math.min(e,t)/2,s=Math.min(.4,n*.34);i.cylinder(0,0,r*.62,0,s,Z.pot,10,pe),i.cylinder(0,0,r*.08,s,n*.55,mt(Pe.wood),6);let o=4;for(let a=0;a<o;a++){let l=r*(.95-.55*(a/(o-1))),c=s+(n-s)*(.18+.2*a);i.cylinder(Math.sin(a*2.1)*.03,Math.cos(a*1.7)*.03,l,c,c+(n-s)*.16,Z.plant,8,a===o-1?Je:null)}}function x_(i,e,t){i.block({x:[-e/2,e/2],y:[0,.012],z:[-t/2,t/2]},Z.fabric);let n=Math.min(.12,Math.min(e,t)*.08),[r,s,o,a]=[-e/2+n,e/2-n,-t/2+n,t/2-n];for(let[l,c,u,h]of[[r,o,s,o],[s,o,s,a],[s,a,r,a],[r,a,r,o]])i.seg(l,.014,c,u,.014,h,pe)}function b_(i,e,t,n){let r=Math.max(3,Math.round(n/.18)),s=n/r,o=t/r;for(let u=0;u<r;u++){let h=t/2-o*u,f=s*(u+1);i.block({x:[-e/2,e/2],y:[0,f],z:[h-o,h]},Z.wood),i.seg(-e/2,f,h,e/2,f,h,pe)}i.seg(-e/2,0,t/2,-e/2,s,t/2,pe);for(let u of[-e/2,e/2])i.seg(u,s,t/2,u,n,-t/2+o,Je);let a=.9,l=e/2-.03,c=Math.max(1,r-4);i.seg(l,s+a,t/2-o/2,l,s*c+a,t/2-o*(c-.5),qe);for(let u=0;u<c;u+=3){let h=t/2-o*(u+.5);i.seg(l,s*(u+1),h,l,s*(u+1)+a,h,Je)}}function y_(i,e,t,n,r=qe){fi(i,e,t,n,Math.max(2,Math.round(e/.6)),n*.55,!0);let s=Math.min(e*.8,1.45);i.block({x:[-.1,.1],y:[n,n+.02],z:[-t/2+.08,-t/2+.24]},Z.metal),i.block({x:[-.02,.02],y:[n+.02,n+.12],z:[-t/2+.14,-t/2+.18]},Z.metal),i.block({x:[-s/2,s/2],y:[n+.1,n+.1+s*.56],z:[-t/2+.12,-t/2+.16]},Z.dark,r)}function __(i,e,t,n,r=qe){let s=1.3-n/2;i.block({x:[-.12,.12],y:[s+n*.3,s+n*.7],z:[-t/2,-t/2+.03]},Z.metal),i.block({x:[-e/2,e/2],y:[s,s+n],z:[-t/2+.03,t/2]},Z.dark,r)}function v_(i,e,t,n,r){let o=t/2,a=l=>i.block({x:[-e/2,e/2],y:[1.1,1.1+n],z:[-t/2,t/2]},l,pe);if(r==="slim"){a(Z.darkBody),i.seg(-e*.25,1.1+n*.15,o+.004,-e*.25,1.1+n*.85,o+.004,qe),i.block({x:[-e*.1,e*.3],y:[1.1+n*.7,1.1+n*.85],z:[o,o+.005]},Z.dark);return}if(a(Z.white),r==="hybrid"){i.ring(0,1.1+n*.66,Math.min(e,n)*.22,o+.004,20,qe),i.seg(-e*.08,1.1+n*.66,o+.005,e*.08,1.1+n*.66,o+.005,qe);for(let l of[-1,1])i.ring(l*e*.22,1.1+n*.2,Math.min(e,n)*.1,-t/2-.002,12,qe);return}i.block({x:[-e*.28,e*.28],y:[1.1+n*.58,1.1+n*.82],z:[t/2,t/2+.006]},Z.dark),i.seg(-e*.3,1.1+n*.45,t/2+.004,e*.3,1.1+n*.45,t/2+.004,qe);for(let l of[-1,1])for(let c=1;c<6;c++)i.seg(l*e/2+l*.002,1.1+n*c/6,-t/2+.03,l*e/2+l*.002,1.1+n*c/6,t/2-.03,Je)}function M_(i,e,t,n){i.block({x:[-e/2,e/2],y:[0,n],z:[-t/2,t/2]},Z.darkBody,pe),i.block({x:[-e/2-.01,e/2+.01],y:[n,n+.03],z:[-t/2-.01,t/2+.01]},Z.darkBody),i.seg(-e/2,n+.032,t/2+.01,e/2,n+.032,t/2+.01,qe),i.seg(-e*.3,n*.55,t/2+.003,e*.3,n*.55,t/2+.003,Je)}function S_(i,e,t,n){i.block({x:[-e/2,e/2],y:[1,1+n],z:[-t/2,t/2]},Z.darkBody,pe),i.ring(0,1+n*.58,Math.min(e,n)*.28,t/2+.003,16,qe),i.block({x:[-.015,.015],y:[1-.35,1],z:[t/2-.03,t/2]},Z.dark),i.block({x:[-.06,.06],y:[1-.42,1-.35],z:[t/2-.05,t/2]},Z.darkBody)}function w_(i,e,t,n){i.block({x:[-e/2,e/2],y:[.4,.4+n],z:[-t/2,t/2]},Z.white,pe),i.seg(-e/2+.025,.4+.025,t/2+.003,-e/2+.025,.4+n-.025,t/2+.003,Je),i.seg(-e/2+.025,.4+n-.025,t/2+.003,e/2-.025,.4+n-.025,t/2+.003,Je),i.block({x:[e/2-.06,e/2-.035],y:[.4+n*.5-.05,.4+n*.5+.05],z:[t/2,t/2+.012]},Z.dark),i.block({x:[-e*.3,e*.3],y:[.4+n*.6,.4+n*.8],z:[t/2,t/2+.005]},Z.dark),i.seg(-e*.22,.4+n*.7,t/2+.008,e*.22,.4+n*.7,t/2+.008,qe)}function T_(i,e,t,n,r){if(r==="wall"){i.block({x:[-e/2,e/2],y:[.5,.5+n],z:[-t/2,t/2]},Z.white,pe),i.seg(-e*.3,.5+n*.9,t/2+.004,e*.3,.5+n*.9,t/2+.004,qe),i.seg(-e*.3,.5+n*.08,t/2+.003,e*.3,.5+n*.08,t/2+.003,Je);return}if(r==="cube"){i.block({x:[-e/2+.01,e/2-.01],y:[0,.03],z:[-t/2+.01,t/2-.01]},Z.dark),i.block({x:[-e/2,e/2],y:[.03,n],z:[-t/2,t/2]},Z.darkBody,pe),i.seg(-e*.35,n*.85,t/2+.004,e*.35,n*.85,t/2+.004,qe),i.block({x:[-e*.15,e*.15],y:[n,n+.025],z:[-.012,.012]},Z.dark);return}i.block({x:[-e/2+.02,e/2-.02],y:[0,.06],z:[-t/2+.02,t/2-.02]},Z.dark);let s=Math.max(2,Math.round((n-.06)/.3)),o=(n-.06)/s;for(let a=0;a<s;a++)i.block({x:[-e/2,e/2],y:[.06+a*o+.004,.06+(a+1)*o],z:[-t/2,t/2]},Z.white,pe);for(let a=0;a<5;a++){let l=.06+n*.18+a*((n-.3)/5);i.seg(-e*.04,l,t/2+.003,e*.04,l,t/2+.003,qe)}}var eh=.9;function A_(i,e,t,n,r,s,o,a=Z.wood){let[l,c]=[t[0]-e[0],t[1]-e[1]],u=Math.hypot(l,c);if(u<.01||s-r<.005)return;let[h,f]=[-c/u,l/u],d=[(e[0]+t[0])/2,(e[1]+t[1])/2];(n[0]-d[0])*h+(n[1]-d[1])*f<0&&([h,f]=[-h,-f]);let p=(x,g)=>[x[0]+h*g,x[1]+f*g];i.prism([e,t,p(t,o),p(e,o)],r,s,a,Je)}var LR=i=>i.slice(1).map((e,t)=>[i[t],e]).filter(([e,t])=>Math.hypot(t[0]-e[0],t[1]-e[1])>.01);function FR(i,e,t,n,r){let s=e.build==="cantilever"?.07:.05;t.forEach((o,a)=>{let l=By(o),c=a===0?0:t[a-1].top;if(e.build==="solid"){i.prism(o.poly,Math.min(r,o.top),o.top,Z.body,pe);return}if(i.prism(o.poly,o.top-s,o.top,Z.wood,pe),e.risers&&!o.landing){let[u,h]=[Math.min(c,o.top),Math.max(c,o.top)-s];A_(i,o.left[0],o.right[0],l,u,h,.02)}if(e.build==="stringer")for(let u of[o.left,o.right])for(let[h,f]of LR(u))A_(i,h,f,l,o.top-n-.2,o.top+.05,.04);else e.build==="mono"&&i.block({x:[l[0]-.07,l[0]+.07],y:[o.top-n-.12,o.top-s],z:[l[1]-.07,l[1]+.07]},Z.metal)})}function OR(i,e,t){let n=e.rail==="both"?["left","right"]:e.rail==="none"?[]:[e.rail];for(let r of n){let s=[];for(let o of t)for(let a of o[r])s.push([a[0],o.top+eh,a[1]]);for(let[o,a]of t.entries()){if(o%2&&o!==t.length-1)continue;let l=a[r][0];i.cylinder(l[0],l[1],.012,a.top,a.top+eh,Z.metal,6)}for(let o=1;o<s.length;o++){let[a,l]=[s[o-1],s[o]];i.seg(a[0],a[1],a[2],l[0],l[1],l[2],qe),i.seg(a[0],a[1]-eh*.55,a[2],l[0],l[1]-eh*.55,l[2],Je)}}}function E_(i,e,t,n,r){let s=dp(e),o=pp(s,t,n,r),a=s.down?-r:0;o.column>0&&i.cylinder(0,0,o.column,Math.min(0,a),s.down?0:r,Z.metal,12,pe),FR(i,s,o.treads,o.rise,a),OR(i,s,o.treads)}function NR(i,e,t,n,r,s){switch(e.type){case"sofa":return e.variant==="l"||e.variant==="u"?ky(i,t,n,r,e.variant):gp(i,t,n,r,Math.max(1,Math.round((t-.4)/.62))),"yes";case"armchair":return gp(i,t,n,r,1),"yes";case"bed":return zy(i,t,n,r),"yes";case"chair":return Vy(i,t,n,r),"yes";case"table":return a_(i,t,n,r),"yes";case"desk":return u_(i,t,n,r),"yes";case"nightstand":return h_(i,t,n,r),"yes";case"wardrobe":return fi(i,t,n,r,Math.max(2,Math.round(t/.5)),r*.5),"yes";case"tall_cabinet":return fi(i,t,n,r,1,r*.5),"yes";case"shelf":return f_(i,t,n,r),"yes";case"kitchen":return Yy(i,t,n,r),"yes";case"fridge":return $y(i,t,n,r),"yes";case"fridge_smart":return Ky(i,t,n,r),"yes";case"stove":return Zy(i,t,n,r),"yes";case"sink":return Jy(i,t,n,r),"yes";case"bathtub":return n_(i,t,n,r),"yes";case"shower":return i_(i,t,n,r),"yes";case"wc":return r_(i,t,n,r),"yes";case"washbasin":return s_(i,t,n,r),"yes";case"tv_board":return y_(i,t,n,r,e.ambilight===0?pe:void 0),"yes";case"plant":return g_(i,t,n,r),"yes";case"rug":return x_(i,t,n),"no";case"stairs":return e.stair?(E_(i,e,t,n,r),e.stair.down?"no":"yes"):(b_(i,t,n,r),"yes");case"stairwell":return"no";case"sideboard":return d_(i,t,n,r),"yes";case"dresser":return p_(i,t,n,r),"yes";case"coat_rack":return m_(i,t,n,r),"yes";case"bench":return xp(i,t,n,r,!1),"yes";case"corner_bench":return xp(i,t,n,r,!0),"yes";case"bar_stool":return Gy(i,t,n,r),"yes";case"office_chair":return Hy(i,t,n,r),"yes";case"stool":return Wy(i,t,n,r),"yes";case"kitchen_wall":return jy(i,t,n,r),"no";case"kitchen_tall":return Qy(i,t,n,r),"yes";case"island":return e_(i,t,n,r),"yes";case"worktop":return qy(i,t,n,r),"no";case"dishwasher":return t_(i,t,n,r),"yes";case"washer":return Mp(i,t,n,r,!1),"yes";case"dryer":return Mp(i,t,n,r,!0),"yes";case"bunk_bed":return Xy(i,t,n,r),"yes";case"table_round":return l_(i,t,n,r),"yes";case"coffee_table":return c_(i,t,n,r),"yes";case"tv_wall":return __(i,t,n,r,e.ambilight===0?pe:void 0),"no";case"parking":{let a=[[-t/2,-n/2],[t/2,-n/2],[t/2,n/2],[-t/2,n/2]];return a.forEach(([l,c],u)=>i.seg(l,.012,c,a[(u+1)%4][0],.012,a[(u+1)%4][1],Je)),i.seg(-t*.15,.012,n/2-.45,0,.012,n/2-.2,pe),i.seg(0,.012,n/2-.2,t*.15,.012,n/2-.45,pe),"no"}case"robot_vacuum":return i.block({x:[-t*.45,t*.45],y:[0,r],z:[-n/2,-n/2+n*.3]},Z.white,pe),i.block({x:[-t*.2,t*.2],y:[r*.5,r*.62],z:[-n/2+n*.3,-n/2+n*.31]},Z.accent),"no";case"radiator":return o_(i,t,n,r),"no";case"inverter":return v_(i,t,n,r,e.variant??null),"no";case"grid_point":return M_(i,t,n,r),"yes";case"wallbox":return S_(i,t,n,r),"no";case"meter":return w_(i,t,n,r),"no";case"home_battery":return T_(i,t,n,r,e.variant??null),e.variant==="wall"?"no":"yes";default:{let o=vt(e.type);return o?o.pet?"no":(Ms(i,o,t,n,r,s,null,null,e.variant??null),s>.05?"no":"yes"):(i.block({x:[-t/2,t/2],y:[0,r],z:[-n/2,n/2]},Z.body,pe),"yes")}}}function R_(i,e,t,n,r){let s=Ss(n),o=new Li(i,e,s),[a,l,c]=[Math.max(.05,n.w),Math.max(.05,n.d),Math.max(.005,n.h)];NR(o,n,a,l,c,r)==="yes"&&pb(t,s,a,l,n.type==="plant"?.35:.5)}function C_(i,e,t){let[n,r]=[Math.cos(t),Math.sin(t)],s=e[0]*i[0]+e[1]*i[1]+e[2]*i[2],o=[e[1]*i[2]-e[2]*i[1],e[2]*i[0]-e[0]*i[2],e[0]*i[1]-e[1]*i[0]];return[i[0]*n+o[0]*r+e[0]*s*(1-n),i[1]*n+o[1]*r+e[1]*s*(1-n),i[2]*n+o[2]*r+e[2]*s*(1-n)]}function DR(i,e,t,n,r){let[s,o]=[n.tilt_x??0,n.tilt_z??0];if(!s&&!o)return;let a=n.rotation*Math.PI/180,l=[Math.cos(a),0,Math.sin(a)],c=[-Math.sin(a),0,Math.cos(a)],u=(h,f)=>{for(let d=f;d+2<h.length;d+=3){let p=[h[d]-n.x,h[d+1]-r,h[d+2]-n.z];s&&(p=C_(p,l,s*Math.PI/180)),o&&(p=C_(p,c,o*Math.PI/180)),h[d]=n.x+p[0],h[d+1]=r+p[1],h[d+2]=n.z+p[2]}};u(i.p,t.vertex),u(e.p,t.line)}function Ml(i,e,t,n,r=0){let s={vertex:i.p.length,line:e.p.length};UR(i,e,t,n,r),DR(i,e,s,n,r)}function UR(i,e,t,n,r=0){let s=vt(n.type)?0:r-jr(n);if(vt(n.type)||Math.abs(s)<.001)return R_(i,e,t,n,r);let[o,a]=[i.p.length,e.p.length];R_(i,e,r<.05?t:new lt,n,0);for(let l=o+1;l<i.p.length;l+=3)i.p[l]+=s;for(let l=a+1;l<e.p.length;l+=3)e.p[l]+=s}function BR(i,e,t,n,r){switch(i.type){case"tv_board":{let s=Math.min(e*.8,1.45);return{x0:-s/2+.02,x1:s/2-.02,y0:n+.12,y1:n+.08+s*.56,z:-t/2+.165}}case"tv_wall":{let s=1.3-n/2;return{x0:-e/2+.02,x1:e/2-.02,y0:s+.02,y1:s+n-.02,z:t/2+.003}}case"desk":return{x0:-.28,x1:.28,y0:n+.1,y1:n+.4,z:-t/2+.115};case"fridge_smart":{let s=r?Gt(r,i):0;return{x0:.06,x1:e/2-.06,y0:s+n*.52+.01,y1:s+n*.86-.01,z:t/2+.006}}case"radiator":return{x0:-e/2+.02,x1:e/2-.02,y0:vl+.02,y1:vl+n-.02,z:t/2+.004};case"washer":case"dryer":{let s=(n-.14)/2+.04,o=Math.min(e*.36,(n-.2)*.42)*.8;return{x0:-o,x1:o,y0:s-o,y1:s+o,z:t/2-.004}}case"dishwasher":return{x0:-e/2+.06,x1:e/2-.06,y0:n-.16,y1:n-.08,z:t/2-.004};default:return null}}function kR(i,e){let[t,n,r]=[Math.max(.05,i.w),Math.max(.05,i.d),Math.max(.005,i.h)],s=vt(i.type),o=s&&jo(s,t,n,r).find(c=>c.screen);if(o){let c=e?Gt(e,i):0,[u,h]=[(o.x-o.w/2)*t,(o.x+o.w/2)*t],f=Math.min(.02,(h-u)*.05);return{x0:u+f,x1:h-f,y0:c+o.y*r+f,y1:c+(o.y+o.h)*r-f,z:(o.z+o.d/2)*n}}let a=e&&i.type!=="fridge_smart"?Gt(e,i)-jr(i):0,l=BR(i,t,n,r,e);return l&&{...l,y0:l.y0+a,y1:l.y1+a}}function th(i,e){let t=kR(i,e);return t&&i.mirror?{...t,x0:-t.x1,x1:-t.x0}:t}function Sp(i,e){let[t,n,r]=[Math.max(.05,i.w),Math.max(.05,i.d),Math.max(.005,i.h)],s=vt(i.type),o=s&&jo(s,t,n,r).find(h=>h.picture);if(!o)return null;let a=e?Gt(e,i):0,[l,c]=[(o.x-o.w/2)*t,(o.x+o.w/2)*t],u={x0:l,x1:c,y0:a+o.y*r,y1:a+(o.y+o.h)*r,z:(o.z+o.d/2)*n};return i.mirror?{...u,x0:-u.x1,x1:-u.x0}:u}function wp(i,e){if(i.type!=="home_battery")return null;let[t,n,r]=[Math.max(.05,i.w),Math.max(.05,i.d),Math.max(.05,i.h)],s=e?Gt(e,i)-jr(i):0,o=n/2+.005;return i.variant==="wall"?{rect:{x0:-t*.3,x1:t*.3,y0:s+.5+r*.84,y1:s+.5+r*.9,z:o},vertical:!1}:i.variant==="cube"?{rect:{x0:-t*.35,x1:t*.35,y0:s+r*.8,y1:s+r*.86,z:o},vertical:!1}:{rect:{x0:-t*.05,x1:t*.05,y0:s+.06+r*.16,y1:s+r-.12,z:o},vertical:!0}}var Jn=Math.PI/180,dr=(i,e)=>[i[0]-e[0],i[1]-e[1],i[2]-e[2]];var Fo=i=>Math.hypot(i[0],i[1],i[2]),Ps=i=>{let e=Fo(i)||1;return[i[0]/e,i[1]/e,i[2]/e]},P_=(i,e)=>[i[1]*e[2]-i[2]*e[1],i[2]*e[0]-i[0]*e[2],i[0]*e[1]-i[1]*e[0]];var L_=.25;function F_(i,e,t,n,r,s,o){let a=r-t>=s-n,l=a?r-t:s-n;return{key:`${i}:top`,section:e,side:"top",flat:!0,o:[t,o,n],eu:a?[1,0,0]:[0,0,1],es:a?[0,0,1]:[1,0,0],n:[0,1,0],lu:l,ls:a?s-n:r-t,pitch:0,span:()=>[0,l],facing:a?[0,1]:[1,0]}}function O_(i,e){let t=Ps(P_(i,e));return t[1]<0?[-t[0],-t[1],-t[2]]:t}var N_=i=>{let e=Ps([-i[0],0,-i[2]]);return[e[0],e[2]]};function pr(i,e,t,n,r,s,o,a){let l=Ps(dr(r,n)),c=Ps(dr(s,n));return{key:i,section:e,side:t,flat:!1,o:n,eu:l,es:c,n:O_(l,c),lu:Fo(dr(r,n)),ls:Fo(dr(s,n)),pitch:o,span:a,facing:N_(c)}}function I_(i,e,t,n,r,s){let o=Fo(dr(r,n));if(o<.3)return null;let a=Ps(dr(r,n)),l=dr(s,n),c=l[0]*a[0]+l[1]*a[1]+l[2]*a[2],u=[l[0]-a[0]*c,l[1]-a[1]*c,l[2]-a[2]*c],h=Fo(u);if(h<.3)return null;let f=Ps(u),d=p=>{let x=Math.min(1,Math.max(0,p/h));return[c*x,o-(o-c)*x]};return{key:i,section:e,side:t,flat:!1,o:n,eu:a,es:f,n:O_(a,f),lu:o,ls:h,pitch:Math.atan2(f[1],Math.hypot(f[0],f[2]))/Jn,span:d,facing:N_(f)}}function zR(i,e){let t=Dn(i),n=En(i),r=(b,v,y)=>{let[M,S]=t.at(b,v);return[M,y,S]},[s,o]=[Math.max(0,e.a),Math.max(0,e.b)],a=t.u0-Math.max(0,e.u0),l=t.u1+Math.max(0,e.u1),c=l-a,u=n.y(-s),h=n.y(t.w+o);if(i.shape==="flat"||i.shape==="parapet"){let[b,v]=[t.at(a,-s),t.at(l,t.w+o)];return[F_(i.id,i.id,Math.min(b[0],v[0]),Math.min(b[1],v[1]),Math.max(b[0],v[0]),Math.max(b[1],v[1]),i.eave_a+L_)]}if(i.shape==="pent")return[pr(`${i.id}:a`,i.id,"a",r(a,-s,u),r(l,-s,u),r(a,t.w+o,h),i.pitch_a,()=>[0,c])];if(i.shape==="mansard")return VR(i,t,a,l,s,o);let f=i.shape==="hip"||i.shape==="pyramid",d=(t.u1-t.u0)/2,p=i.shape==="pyramid"?d:f?Math.min(d,Math.min(n.vr,t.w-n.vr)||t.w/2):0,x=f?t.u0+p-a:0,g=f?l-(t.u1-p):0,m=[];if(n.vr>.3){let b=Math.hypot(n.vr+s,n.rh-u);m.push(pr(`${i.id}:a`,i.id,"a",r(a,-s,u),r(l,-s,u),r(a,n.vr,n.rh),i.pitch_a,v=>[x*(v/b),c-g*(v/b)]))}if(t.w-n.vr>.3){let b=Math.hypot(t.w+o-n.vr,n.rh-h);m.push(pr(`${i.id}:b`,i.id,"b",r(l,t.w+o,h),r(a,t.w+o,h),r(l,n.vr,n.rh),i.pitch_b,v=>[g*(v/b),c-x*(v/b)]))}if(f){let b=I_(`${i.id}:c`,i.id,"c",r(a,t.w+o,h),r(a,-s,u),r(t.u0+p,n.vr,n.rh)),v=I_(`${i.id}:d`,i.id,"d",r(l,-s,u),r(l,t.w+o,h),r(t.u1-p,n.vr,n.rh));m.push(...[b,v].filter(y=>y!==null))}return m}function VR(i,e,t,n,r,s){let o=ol(e.w,i.eave_a,i.eave_b,ur(i.pitch_a),ur(i.pitch_b)),a=(p,x)=>{let[g,m]=e.at(p,x);return[g,o.y(x),m]},l=n-t,c=()=>[0,l],u=(p,x)=>Math.atan2(p,x)/Jn,h=[],[f,d]=[e.w+s,e.w-o.vlb];return o.vla+r>.3&&h.push(pr(`${i.id}:a`,i.id,"a",a(t,-r),a(n,-r),a(t,o.vla),i.pitch_a,c)),o.vr-o.vla>.3&&h.push(pr(`${i.id}:au`,i.id,"a",a(t,o.vla),a(n,o.vla),a(t,o.vr),u(o.rh-o.yla,o.vr-o.vla),c)),o.vlb+s>.3&&h.push(pr(`${i.id}:b`,i.id,"b",a(n,f),a(t,f),a(n,d),i.pitch_b,c)),d-o.vr>.3&&h.push(pr(`${i.id}:bu`,i.id,"b",a(n,d),a(t,d),a(n,o.vr),u(o.rh-o.ylb,d-o.vr),c)),h}function D_(i){return i.floors.filter(t=>t.rooms.some(n=>n.points.length>=3)).sort((t,n)=>n.elevation-t.elevation)[0]??null}function Is(i){let e=i.settings.roof;if(!e||e.type==="none")return[];if(e.type==="custom")return(e.sections??[]).flatMap(v=>zR(v,ll(i,v,v.overhang??e.overhang)));let t=D_(i);if(!t)return[];let n=t.rooms.flatMap(v=>v.points.map(y=>y[0])),r=t.rooms.flatMap(v=>v.points.map(y=>y[1])),s=i.settings.wall_exterior+e.overhang,[o,a]=[Math.min(...n)-s,Math.max(...n)+s],[l,c]=[Math.min(...r)-s,Math.max(...r)+s],u=t.elevation+t.height;if(e.type==="flat")return[F_("main",null,o,l,a,c,u+L_)];let h=a-o>=c-l,f=e.ridge==="short"?!h:h,d=(f?c-l:a-o)/2,p=d*Math.tan(e.pitch*Jn),x=(v,y,M)=>f?[v,u+M,(l+c)/2+y]:[(o+a)/2+y,u+M,v],[g,m]=f?[o,a]:[l,c],b=()=>[0,m-g];return[pr("main:a",null,"a",x(g,-d,0),x(m,-d,0),x(g,0,p),e.pitch,b),pr("main:b",null,"b",x(g,d,0),x(m,d,0),x(g,0,p),e.pitch,b)]}function nh(i,e){let t=[];for(let n of i.floors.filter(r=>!e||r.id===e)){let{walls:r}=al(n.rooms,{exterior:i.settings.wall_exterior,interior:i.settings.wall_interior},n.walls??[]);for(let s of r){if(!s.exterior&&!s.free)continue;let[o,a]=[s.b[0]-s.a[0],s.b[1]-s.a[1]],l=Math.hypot(o,a);if(l<1.2)continue;let[c,u]=[a/l,-o/l],h=Math.min(n.height,s.height??n.height,s.heightEnd??1/0),f=(d,p,x,g)=>t.push({key:d,section:null,side:"top",flat:!1,o:p,eu:x,es:[0,1,0],n:g,lu:l,ls:h,pitch:90,span:()=>[0,l],facing:[g[0],g[2]],wall:{floorId:n.id}});f(`wall:${n.id}:${s.id}`,[s.a[0]+c*s.right,n.elevation,s.a[1]+u*s.right],[o/l,0,a/l],[c,0,u]),s.free&&f(`wall:${n.id}:${s.id}:back`,[s.b[0]-c*s.left,n.elevation,s.b[1]-u*s.left],[-o/l,0,-a/l],[-c,0,-u])}}return t}var Sl="ground";function ih(i){let e=i.floors.filter(t=>t.rooms.some(n=>n.points.length>=3)).sort((t,n)=>t.elevation-n.elevation);return e.find(t=>t.elevation>-.5)??e[0]??i.floors[0]??null}function rh(i,e){let t=(e.rotation??0)*Jn,n=[Math.cos(t),0,Math.sin(t)],r=[-Math.sin(t),0,Math.cos(t)],s=ih(i),o=n[0]*e.u+r[0]*e.v,a=n[2]*e.u+r[2]*e.v,l=s?s.elevation+(e.base!=null?e.base:p0(s,o,a)):e.base??0;return{key:Sl,section:null,side:"top",flat:!0,o:[0,l,0],eu:n,es:r,n:[0,1,0],lu:1e4,ls:1e4,pitch:0,span:()=>[-1e4,1e4],facing:[r[0],r[2]],unbounded:!0}}var Tp=1.13,Ap=1.72,Oo=.025,di=.07;function wl(i){let e=i.module_w||Tp,t=i.module_h||Ap;return i.portrait===!1?[t,e]:[e,t]}function Ep(i){return i.layout?.length?i.layout.map(e=>Math.max(0,Math.min(60,Math.round(e)))):Array.from({length:Math.max(1,i.rows)},()=>Math.max(1,i.cols))}function Rp(i,e){return i.flat?Math.min(45,Math.max(0,e.tilt??15))*Jn:i.wall?Math.min(90,Math.max(0,e.tilt??0))*Jn:Math.min(45,Math.max(0,e.tilt??0))*Jn}function oh(i,e){let[,t]=wl(e),n=Rp(i,e);return i.wall?t*Math.cos(n)+Oo:!i.flat&&n<.001?t+Oo:i.flat&&e.rack==="ew"?t*Math.cos(n)+.08:t*Math.cos(n)+Math.max(.3,2*t*Math.sin(n))}function Cp(i,e){let[t,n]=wl(e),r=Ep(e),s=Math.max(1,...r);return[s*t+(s-1)*Oo,(r.length-1)*oh(i,e)+n*Math.cos(Rp(i,e))]}var GR=i=>i.flat&&!i.unbounded&&!i.wall;function HR(i,e){if(!GR(i)||!e.rotation)return null;let t=e.rotation*Jn,[n,r]=Cp(i,e);return{cos:Math.cos(t),sin:Math.sin(t),u:e.u+n/2,s:e.v+r/2}}function No(i,e,t=!1){let[n,r]=wl(e),s=Rp(i,e),o=r*Math.cos(s),a=oh(i,e),l=Ep(e),c=Math.max(1,...l),u=new Set(e.skip??[]),h=HR(i,e),f=(g,m)=>h?[h.u+(g-h.u)*h.cos-(m-h.s)*h.sin,h.s+(g-h.u)*h.sin+(m-h.s)*h.cos]:[g,m],d=(g,m,b)=>{let[v,y]=f(g,m);return[0,1,2].map(M=>i.o[M]+i.eu[M]*v+i.es[M]*y+i.n[M]*b)},p=(g,m)=>{let[b,v]=f(g,m);if(i.unbounded)return!0;if(v<-1e-6||v>i.ls+1e-6)return!1;let[y,M]=i.span(v);return b>=y-1e-6&&b<=M+1e-6},x=[];return l.forEach((g,m)=>{let b=e.align==="right"?c-g:e.align==="center"?(c-g)/2:0;for(let v=0;v<g;v++){let y=`${m}:${v}`,M=u.has(y);if(M&&!t)continue;let S=e.u+(v+b)*(n+Oo),_=S+n,w=e.v+m*a,R=w+(i.flat||i.wall||s>.001?o:r);if([[S,w],[_,w],[_,R],[S,R]].every(([A,C])=>p(A,C)))if(i.wall&&s>.001){let A=di+r*Math.sin(s),[C,O]=e.flip?[A,di]:[di,A],D=[d(S,w,C),d(_,w,C),d(_,R,O),d(S,R,O)],P=e.flip?w:R;x.push({corners:D,posts:[S+.05,_-.05].map(I=>[d(I,P,0),d(I,P,A)]),cell:y,skipped:M})}else if(!i.flat&&s>.001){let A=di+r*Math.sin(s),C=[d(S,w,di),d(_,w,di),d(_,R,A),d(S,R,A)];x.push({corners:C,posts:[S+.05,_-.05].map(O=>[d(O,R,0),d(O,R,A)]),cell:y,skipped:M})}else if(!i.flat)x.push({corners:[d(S,w,di),d(_,w,di),d(_,R,di),d(S,R,di)],posts:[],cell:y,skipped:M});else{let C=.15+r*Math.sin(s),O=e.rack==="ew"&&m%2===1?!e.flip:!!e.flip,[D,P]=O?[R,w]:[w,R],I=[d(S,D,.15),d(_,D,.15),d(_,P,C),d(S,P,C)],N=[S+.05,_-.05].flatMap(F=>[[d(F,D,0),d(F,D,.15)],[d(F,P,0),d(F,P,C)]]);x.push({corners:I,posts:N,cell:y,skipped:M})}}}),x}var Pp=.78,Ip=1.18,U_=i=>({id:i.id,face:i.face,u:i.u,v:i.v,rows:1,cols:1,portrait:!0,module_w:i.w||Pp,module_h:i.h||Ip});function Tl(i,e){let t=No(i,U_(e))[0];if(!t)return null;let n=r=>[r[0]-i.n[0]*.05,r[1]-i.n[1]*.05,r[2]-i.n[2]*.05];return t.corners.map(n)}var sh={brick:{w:.5,d:.5,h:1},round:{w:.4,d:.4,h:1},wide:{w:1,d:.5,h:1},steel:{w:.2,d:.2,h:1.2}};function ah(i){let e=i.shape??"brick",t=sh[e]??sh.brick;return{shape:e,w:i.w||t.w,d:i.d||t.d,h:i.h||t.h}}function Lp(i,e){let{w:t,d:n}=ah(i),r=e&&!e.flat?Math.cos(e.pitch*Jn):1;return{id:i.id,face:i.face,u:i.u,v:i.v,rows:1,cols:1,portrait:!0,module_w:t,module_h:n/Math.max(.2,r),tilt:0}}function Fp(i,e){let t=Lp(e,i),[n,r]=[t.module_w,t.module_h],s=(u,h)=>[i.o[0]+i.eu[0]*u+i.es[0]*h,i.o[1]+i.eu[1]*u+i.es[1]*h,i.o[2]+i.eu[2]*u+i.es[2]*h],[o,a]=[s(e.u+n/2,e.v),s(e.u+n/2,e.v+r)],l=s(e.u+n/2,e.v+r/2),c=u=>{let h=Math.hypot(u[0],u[2])||1;return[u[0]/h,u[2]/h]};return{center:[l[0],l[2]],along:c(i.eu),across:c(i.es),low:Math.min(o[1],a[1]),high:Math.max(o[1],a[1])}}var Ls=1712952,Fs=2239816,lh=1318193,mr=Ue(3662079,.9),gr=Ue(5995775,.45),Xt=.14,B_=9427199,k_=13226982,z_=14936565,V_={black:{glass:new W(329483),edge:Ue(9082544,.32),cells:Ue(2766160,.22)},blue:{glass:new W(1386842),edge:Ue(10467583,.55),cells:Ue(4025599,.35)}},G_=Ue(13226982,.5),H_=Ue(13226982,.85),W_=Ue(16757575,.95),Op=new W(2845583),Np=new W(3818072),Dp=3812144,Up=4864064,ch=2765896,Do=329483,uh=9148333,hh=11845844,X_=Ue(5995775,.4);var Uo=(i,e,t)=>[i[0]+(e[0]-i[0])*t,i[1]+(e[1]-i[1])*t,i[2]+(e[2]-i[2])*t],fh=(i,e,t)=>[i[0]+e[0]*t,i[1]+e[1]*t,i[2]+e[2]*t],Bp=(i,e)=>e.section?i.find(t=>t.sections?.includes(e.section)):i[0];function Y_(i,e,t){let n=i.settings.roof?.windows??[];if(n.length===0||e.length===0)return;let r=new Map(Is(i).map(s=>[s.key,s]));for(let s of n){let o=r.get(s.face),a=o?Tl(o,s):null,l=o&&a?Bp(e,o):void 0;if(!o||!a||!l)continue;let c=l.floor.elevation+l.base,[u,h,f,d]=a.map(R=>[R[0],R[1]-c,R[2]]),p=t.get(s.id)??{open:0,tilt:0,cover:0},x=(R,A)=>fh(R,o.n,A),g=p.open>.02||p.tilt>.02?W_:H_,m=[u,h,f,d].map(R=>x(R,.06));m.forEach((R,A)=>l.lines.seg(R,m[(A+1)%4],g));let b=(p.open>.02?30*Math.min(1,p.open):p.tilt>.5?12:0)*pt,v=Math.hypot(f[0]-h[0],f[1]-h[1],f[2]-h[2]),y=R=>fh(fh(R,o.es,-v*Math.cos(b)),o.n,v*Math.sin(b)),[M,S]=[x(d,.065),x(f,.065)],[_,w]=[y(M),y(S)];l.solid.tri(_,w,S,Op),l.solid.tri(_,S,M,Op);for(let[R,A]of[[_,w],[w,S],[S,M],[M,_]])l.lines.seg(R,A,g);if(p.cover>.02){let R=Math.min(1,p.cover),[A,C]=[x(Uo(M,_,R),.01),x(Uo(S,w,R),.01)],[O,D]=[x(M,.01),x(S,.01)];l.solid.tri(A,C,D,Np),l.solid.tri(A,D,O,Np)}}}function dh(i,e,t,n,r){let s=c=>[c[0],c[1]-r,c[2]],o=V_[n.look==="blue"?"blue":"black"],[a,l]=n.portrait===!1?[10,6]:[6,10];for(let c of No(t,n)){let[u,h,f,d]=c.corners.map(s);for(let[g,m,b]of[[u,h,f],[u,f,d],[u,f,h],[u,d,f]])i.tri(g,m,b,o.glass);let p=g=>fh(g,t.n,.004),x=[u,h,f,d].map(p);x.forEach((g,m)=>e.seg(g,x[(m+1)%4],o.edge));for(let g=1;g<a;g++)e.seg(p(Uo(u,h,g/a)),p(Uo(d,f,g/a)),o.cells);for(let g=1;g<l;g++)e.seg(p(Uo(u,d,g/l)),p(Uo(h,f,g/l)),o.cells);for(let[g,m]of c.posts)e.seg(s(g),s(m),G_)}}function q_(i,e){let t=i.settings.roof?.solar??[];if(t.length===0||e.length===0)return;let n=new Map(Is(i).map(r=>[r.key,r]));for(let r of t){let s=n.get(r.face),o=s?Bp(e,s):void 0;s&&o&&dh(o.solid,o.lines,s,r,o.floor.elevation+o.base)}}function $_(i,e){let t=i.settings.roof?.chimneys??[];if(t.length===0||e.length===0)return;let n=new Map(Is(i).map(r=>[r.key,r]));for(let r of t){let s=n.get(r.face),o=s?Bp(e,s):void 0;if(!s||!o)continue;let a=o.floor.elevation+o.base,{shape:l,w:c,d:u,h}=ah(r),f=Fp(s,r),[d,p]=[f.low-a-.1,f.high-a+h],x=(_,w)=>{let{center:R,along:A,across:C}=f,O=(D,P)=>[R[0]+A[0]*_*D+C[0]*w*P,R[1]+A[1]*_*D+C[1]*w*P];return[O(-1,-1),O(1,-1),O(1,1),O(-1,1)]},g=(_,w=16)=>Array.from({length:w},(R,A)=>[f.center[0]+Math.cos(A/w*2*Math.PI)*_,f.center[1]+Math.sin(A/w*2*Math.PI)*_]),m=(_,w)=>_.forEach((R,A)=>o.lines.seg([R[0],w,R[1]],[_[(A+1)%_.length][0],w,_[(A+1)%_.length][1]],X_)),b=(_,w,R,A,C)=>Tt(o.solid,YR(_),w,R,A,C);if(l==="steel"){let _=Math.min(c,u)/2;b(g(_,12),d,p,uh,hh),b(g(_*.75,12),p,p+.001,Do,Do),b(g(_*.25,6),p,p+.1,uh,hh);let w=g(_*1.9,12);b(w,p+.1,p+.13,uh,hh),m(w,p+.13);continue}if(l==="round"){let _=Math.min(c,u)/2,w=g(_);b(w,d,p,Dp,Up),b(g(_*.55),p,p+.002,Do,Do),m(w,p);continue}let v=x(c/2,u/2);b(v,d,p,Dp,Up);let y=x(c/2+.04,u/2+.04);b(y,p,p+.06,ch,ch),m(y,p+.06),m(v,p-.25);let M=Math.min(c,u)*.25,S=l==="wide"?[-c/4,c/4]:[0];for(let _ of S){let w=[f.center[0]+f.along[0]*_,f.center[1]+f.along[1]*_],R=[[-1,-1],[1,-1],[1,1],[-1,1]].map(([A,C])=>[w[0]+f.along[0]*M*A+f.across[0]*M*C,w[1]+f.along[1]*M*A+f.across[1]*M*C]);b(R,p+.06,p+.16,ch,Do)}}}function YR(i){let e=0;for(let t=0;t<i.length;t++){let[n,r]=[i[t],i[(t+1)%i.length]];e+=n[0]*r[1]-r[0]*n[1]}return e<0?[...i].reverse():i}var jn=.12,Al=.16;function K_(i,e,t,n,r,s,o){let a=t.w,[l,c,u,h]=[r.a>0,r.b>0,r.u0>0,r.u1>0],f=(p,x,g,m,b,v)=>{let y=[t.at(p,g),t.at(x,g),t.at(x,m),t.at(p,m)],M=(y[1][0]-y[0][0])*(y[2][1]-y[0][1])-(y[2][0]-y[0][0])*(y[1][1]-y[0][1]);Tt(i,M<0?[...y].reverse():y,b-o,v-o,k_,z_,{bottom:!0})};for(let[p,x]of[[0,l],[a,c]]){if(!x)continue;let g=n.y(p)-.03,m=p===0?0:a-jn;f(t.u0,t.u1,m,m+jn,g-Al,g),e.seg(s(t.u0,p,g-Al),s(t.u1,p,g-Al),gr)}for(let[p,x]of[[t.u0,u],[t.u1-jn,h]])if(x)for(let g=0;g<6;g++){let[m,b]=[a*g/6,a*(g+1)/6],v=Math.min(n.y(m),n.y(b))-.03;f(p,p+jn,m,b,v-Al,v)}let d=[];for(let[p,x]of[[0,l],[a-jn,c]]){if(!x)continue;let g=t.u1-t.u0-jn,m=Math.max(1,Math.ceil(g/3.5));for(let b=0;b<=m;b++)b===0&&!u||b===m&&!h||d.push([t.u0+g*b/m,p])}!l&&!c&&(u&&d.push([t.u0,a/2-jn/2]),h&&d.push([t.u1-jn,a/2-jn/2]));for(let[p,x]of d)f(p,p+jn,x,x+jn,o,n.y(x+jn/2)-.03-Al)}function qR(i,e){let t=[];if(i.forEach(([s,o],a)=>{o>=e&&t.push([s,o]);let l=i[a+1];if(l&&(o-e)*(l[1]-e)<0){let c=(e-o)/(l[1]-o);t.push([s+(l[0]-s)*c,e])}}),t.length<2)return[];let[n,r]=[t[0],t[t.length-1]];return r[1]>e&&t.push([r[0],e]),n[1]>e&&t.unshift([n[0],e]),t}var Z_=i=>vr(i)>=0?i:[...i].reverse();function J_(i,e,t,n,r,s=i,o=!1,a=[],l=null){let c=Dn(t),u=En(t),h=typeof n=="number"?{u0:n,u1:n,a:n,b:n}:n,[f,d]=[Math.max(0,h.a),Math.max(0,h.b)],p=c.w,x=c.u0-Math.max(0,h.u0),g=c.u1+Math.max(0,h.u1),m=(I,N,F)=>{let[H,B]=c.at(I,N);return[H,F-r,B]},b=new W(Fs),v=new W(Ls),y=new W(lh),M=(I,N)=>{for(let F=1;F+1<I.length;F++)i.tri(I[0],I[F],I[F+1],N)},S=([I,N,F],H=0)=>m(I,N,F-H),_=[],w=[],R=[],A=null,C=null;if(t.shape==="flat"||t.shape==="parapet"){let I=t.eave_a-r,N=t.shape==="parapet",F=t.points&&t.points.length>=3?qd(t,N?0:Math.max(0,Math.min(h.a,h.b,h.u0,h.u1))):N?[c.at(c.u0,0),c.at(c.u1,0),c.at(c.u1,p),c.at(c.u0,p)]:[c.at(x,-f),c.at(g,-f),c.at(g,p+d),c.at(x,p+d)];if(Tt(i,F,I,I+.25,Ls,Fs,{bottom:!0}),F.forEach((H,B)=>{let X=F[(B+1)%F.length];e.seg([H[0],I+.252,H[1]],[X[0],I+.252,X[1]],mr),e.seg([H[0],I,H[1]],[X[0],I,X[1]],gr)}),N){let H=Z_(F),B=Ou(H,-.2);H.forEach((X,V)=>{let re=(V+1)%H.length;Tt(i,Z_([X,H[re],B[re],B[V]]),I+.25,I+.65,Ls,Fs),e.seg([X[0],I+.652,X[1]],[H[re][0],I+.652,H[re][1]],mr),e.seg([B[V][0],I+.652,B[V][1]],[B[re][0],I+.652,B[re][1]],mr)})}}else{let I=Hr(t,h);_=a.reduce((N,F)=>N.flatMap(H=>Nu(H,F)),I.faces),w=I.rim,R=I.ridges,A=I.gable,C=I.endProfiles??null}let O=!!t.open,D=new W(B_);for(let I of _)if(O)for(let N=1;N+1<I.length;N++)s.tri(S(I[0]),S(I[N]),S(I[N+1]),D);else M(I.map(N=>S(N)),b),M(I.map(N=>S(N,Xt)),v);if(w.forEach((I,N)=>{let F=w[(N+1)%w.length];O||M([S(I),S(F),S(F,Xt),S(I,Xt)],v),e.seg(S(I),S(F),O?mr:gr)}),O){K_(i,e,c,u,h,(I,N,F)=>m(I,N,F),r);return}for(let[I,N]of R)e.seg(S([I[0],I[1],I[2]+.004]),S([N[0],N[1],N[2]+.004]),mr);let P=t.base;if(!o){if(A){let I=l===null?[c.u0,c.u1]:[l===0?c.u0:c.u1];for(let N of I){let F=C?C[N===c.u0?0:1]:A,H=F?qR(F,P-Xt):[];H.length>=3&&M(H.map(([B,X])=>m(N,B,X)),y)}}if(t.shape!=="flat"&&t.shape!=="parapet")for(let I of[0,p]){let N=u.y(I)-Xt;N>P+.02&&M([m(c.u0,I,P),m(c.u1,I,P),m(c.u1,I,N),m(c.u0,I,N)],y)}else if(t.eave_a>P+.02){let I=[[c.u0,0],[c.u1,0],[c.u1,p],[c.u0,p]];I.forEach(([N,F],H)=>{let[B,X]=I[(H+1)%4];M([m(N,F,P),m(B,X,P),m(B,X,t.eave_a),m(N,F,t.eave_a)],y)})}}}function j_(i,e,t){let n=i.floors.filter(o=>o.rooms.length>0).sort((o,a)=>o.elevation-a.elevation);if(n.length===0)return[];let r=new Map,s=new Map(Is(i).map(o=>[o.key,o]));for(let o of e){if(Math.abs(o.x1-o.x0)<.1||Math.abs(o.z1-o.z0)<.1)continue;let a=Zd(i,o)??n[0],l=o.open?`${a.id}:open`:a.id,c=r.get(l);c||r.set(l,c={floor:a,base:0,solid:new lt,lines:new Wt,glass:new lt,sections:[],lift:!o.open}),c.sections.push(o.id);let u=ul(e,o),h=As(e,o)??u?.parent??null,f=a.elevation+a.height>o.base+.05&&!o.dormer&&!h,d=e.filter(g=>g!==o).flatMap(g=>As(e,g)===o?Uu(o,g):ul(e,g)?.parent===o?Uu(o,ul(e,g).extended):[]);for(let g of i.settings.roof.windows??[]){let m=s.get(g.face),b=m&&m.section===o.id?Tl(m,g):null;if(!b)continue;let v=b.map(y=>Fi(o,y[0],y[2]));d.push({u0:Math.min(...v.map(y=>y[0])),u1:Math.max(...v.map(y=>y[0])),v0:Math.min(...v.map(y=>y[1])),v1:Math.max(...v.map(y=>y[1]))})}let p=u?u.extended:h?cl(h,o):o,x=null;if(h){let g=Dn(p),m=Hr(h,{u0:0,u1:0,a:0,b:0}),b=v=>{let[y,M]=g.at(v,g.w/2),[S,_]=Fi(h,y,M);return Ts(m,S,_)??En(h).y(_)};x=b(g.u0)<=b(g.u1)?0:1}J_(c.solid,c.lines,p,ll(i,p,p.overhang??t),a.elevation,c.glass,f,d,x)}return[...r.values()].sort((o,a)=>+(o.lift===!1)-+(a.lift===!1))}function Q_(i){return i.floors.filter(e=>e.rooms.some(t=>t.points.length>=3)).sort((e,t)=>t.elevation-e.elevation)[0]??null}function ev(i){let e=i.settings.roof,t=Q_(i);if(!t||!e||e.type==="none"||e.type==="custom")return null;let n=t.rooms.flatMap(O=>O.points.map(D=>D[0])),r=t.rooms.flatMap(O=>O.points.map(D=>D[1])),s=i.settings.wall_exterior+e.overhang,[o,a]=[Math.min(...n)-s,Math.max(...n)+s],[l,c]=[Math.min(...r)-s,Math.max(...r)+s],u=new lt,h=new Wt,f={floor:t,base:t.height,solid:u,lines:h,glass:new lt};if(e.type==="flat"){let O=[[o,l],[a,l],[a,c],[o,c]];return Tt(u,O,0,.25,Ls,Fs,{bottom:!0}),O.forEach(([D,P],I)=>{let[N,F]=O[(I+1)%4];h.seg([D,.252,P],[N,.252,F],mr),h.seg([D,0,P],[N,0,F],gr)}),f}let d=a-o>=c-l,p=e.ridge==="short"?!d:d,x=(p?c-l:a-o)/2,g=Math.tan(e.pitch*pt),m=x*g,b=(O,D,P)=>p?[O,P,(l+c)/2+D]:[(o+a)/2+D,P,O],[v,y]=p?[o,a]:[l,c],M=new W(Fs),S=new W(Ls),_=(O,D,P,I,N)=>{u.tri(O,D,P,N),u.tri(O,P,I,N)};for(let O of[-1,1]){_(b(v,O*x,0),b(y,O*x,0),b(y,0,m),b(v,0,m),M),_(b(v,O*x,-Xt),b(v,0,m-Xt),b(y,0,m-Xt),b(y,O*x,-Xt),S),_(b(v,O*x,-Xt),b(y,O*x,-Xt),b(y,O*x,0),b(v,O*x,0),S);for(let D of[v,y])_(b(D,O*x,-Xt),b(D,O*x,0),b(D,0,m),b(D,0,m-Xt),S);h.seg(b(v,O*x,0),b(y,O*x,0),gr);for(let D of[v,y])h.seg(b(D,O*x,0),b(D,0,m),gr)}let w=e.overhang,R=new W(lh),A=x-w,C=A*g;for(let O of[v+w,y-w])u.tri(b(O,-A,-Xt),b(O,A,-Xt),b(O,0,C-Xt),R),u.tri(b(O,A,-Xt),b(O,-A,-Xt),b(O,0,C-Xt),R);return h.seg(b(v,0,m+.004),b(y,0,m+.004),mr),f}function kp(i,e=new Map){let t=i.settings.roof,n=t?.type==="custom"?null:ev(i),r=t?.type==="custom"?j_(i,t.sections??[],t.overhang):n?[n]:[];return q_(i,r),Y_(i,r,e),$_(i,r),r}function ph(i){let{start:e,axis:t,width:n}=i.info;return[[e[0],e[1]],[e[0]+t[0]*n,e[1]+t[1]*n]]}var tv=(i,e)=>`${i}|${Math.round(e[0]*50)},${Math.round(e[1]*50)}`;function nv(i,e){let t=[];for(let n of i){let r=n.info.opening.front;if(!r)continue;let[s,o]=ph(n);e.at(r,s)&&t.push(n.s0),e.at(r,o)&&t.push(n.s1)}return t}function iv(i,e){let t=Math.hypot(i.b[0]-i.a[0],i.b[1]-i.a[1])||1;return((e[0]-i.a[0])*(i.b[0]-i.a[0])+(e[1]-i.a[1])*(i.b[1]-i.a[1]))/t}function mh(i){let e=new Map,t=new Map;for(let r of i)for(let s of r){let o=s.info.opening.front;if(o)for(let a of ph(s)){let l=tv(o,a);e.set(l,(e.get(l)??0)+1),t.has(l)||t.set(l,[a[0],a[1]])}}return{points:[...e].filter(([,r])=>r>1).map(([r])=>t.get(r)).filter(r=>!!r),at:(r,s)=>(e.get(tv(r,s))??0)>1}}var Os={floor:923177,slab:659744,wall:1252657,wallTop:1323071,edge:3662079,edgeSoft:5995775},gh={wood:{color:1120814,tile:[0,0]},oak:{color:1252141,tile:[1,0]},tiles:{color:923695,tile:[2,0]},carpet:{color:1053995,tile:[0,1]},stone:{color:988971,tile:[1,1]},concrete:{color:1120295,tile:[2,1]}},pi=.2,Bo=8;var rv=(i,e)=>i.heightEnd===void 0?i.height??e:Math.max(i.height??e,i.heightEnd);function sv(i){let e=new Map,t=[],n=new Map;for(let r of i){let s="interior",o=null;if(r.exterior){let[a,l]=[r.b[0]-r.a[0],r.b[1]-r.a[1]],c=Math.hypot(a,l)||1,u=[l/c,-a/c],h=(Math.round(Math.atan2(u[1],u[0])/(2*Math.PI)*Bo)%Bo+Bo)%Bo;s=`s${h}`;let f=h/Bo*2*Math.PI;o=[Math.cos(f),Math.sin(f)]}e.has(s)||(e.set(s,t.length),t.push(o)),n.set(r,e.get(s))}return{buckets:t,wallBucket:n}}function ov(i){let e=(n,r,s)=>{let o=i?i(n,r):null;return o===null?s:Math.max(.05,Math.min(s,o))};return{topAt:e,lowestTop:(n,r,s,o,a)=>{if(!i)return a;let l=Math.max(2,Math.ceil((o-s)/.25)+1),c=a;for(let u=0;u<l;u++){let h=s+(o-s)*u/(l-1);c=Math.min(c,e(n[0]+r[0]*h,n[1]+r[1]*h,a))}return c}}}function ko(i,e,t){let n=rv(i,e),r=Math.hypot(i.b[0]-i.a[0],i.b[1]-i.a[1]),s=_s([i.b[0]-i.a[0],i.b[1]-i.a[1]]);if(i.heightEnd===void 0)return{H:n,varies:!1,topAt:(h,f)=>t.topAt(h,f,n),lowestTop:(h,f)=>t.lowestTop(i.a,s,h,f,n)};let[o,a]=[i.height??e,i.heightEnd],l=(h,f)=>{let d=r>1e-9?((h-i.a[0])*s[0]+(f-i.a[1])*s[1])/r:0;return o+(a-o)*Math.max(0,Math.min(1,d))},c=(h,f)=>t.topAt(h,f,l(h,f));return{H:n,varies:!0,topAt:c,lowestTop:(h,f)=>{let d=Math.max(2,Math.ceil((f-h)/.25)+1),p=1/0;for(let x=0;x<d;x++){let g=h+(f-h)*x/(d-1);p=Math.min(p,c(i.a[0]+s[0]*g,i.a[1]+s[1]*g))}return p}}}function av(i,e,t,n){let r=new Map,s=[];for(let o of i.openings){let a=Pb(o,i.rooms,i.walls??[]),l=a&&Lb(e,o,a);if(!a||!l)continue;let{wall:c,s:u}=l,h=_s([c.b[0]-c.a[0],c.b[1]-c.a[1]]),f=Math.hypot(c.b[0]-c.a[0],c.b[1]-c.a[1]),d=Math.min(o.width,f),p=Math.max(0,Math.min(f-d,u-d/2)),x=a.room.points,g=c.free?h[0]*(x[1][0]-x[0][0])+h[1]*(x[1][1]-x[0][1])>0:c.roomLeft===o.room_id,m=[-h[1],h[0]],b=g?m:[-m[0],-m[1]],v=Qr(i.rooms.find(R=>R.id===o.room_id)),y=Math.min(ko(c,i.height,n).lowestTop(p,p+d)-.02,v+o.sill+o.height),M=Math.max(Math.min(0,v),Math.min(v+o.sill,y-.1)),S=[b[1],-b[0]],_=h[0]*S[0]+h[1]*S[1]>0,w={opening:o,bucket:t.get(c),start:[c.a[0]+h[0]*p,c.a[1]+h[1]*p],axis:h,width:d,toRoom:b,faceRoom:g?c.left:c.right,faceOut:g?c.right:c.left,sill:M,top:y,hingeAtStart:o.hinge==="left"===_,exterior:c.exterior};s.push(w),r.set(c,[...r.get(c)??[],{s0:p,s1:p+d,sill:M,top:y,info:w}])}return{openings:s,spans:r}}var lv=i=>`${Math.round(i[0]*50)},${Math.round(i[1]*50)}`;function $R(i,e,t,n=!1,r=!1){let{info:s}=e,o=s.bucket,a=(u,h,f)=>[s.start[0]+s.axis[0]*(u-e.s0)+s.toRoom[0]*h,f,s.start[1]+s.axis[1]*(u-e.s0)+s.toRoom[1]*h],l=u=>u>t+1e-6?o:Xe,c=e.sill<0?e.sill+.004:Math.max(e.sill,.004);for(let u of[s.faceRoom,-s.faceOut])n||i.segSplit(a(e.s0,u,c),a(e.s0,u,e.top),ci,t,o),r||i.segSplit(a(e.s1,u,c),a(e.s1,u,e.top),ci,t,o),i.seg(a(e.s0,u,e.top),a(e.s1,u,e.top),ci,l(e.top)),e.sill>.01&&i.seg(a(e.s0,u,e.sill),a(e.s1,u,e.sill),ci,l(e.sill));for(let[u,h]of[[e.s0,n],[e.s1,r]])h||(i.seg(a(u,s.faceRoom,e.top),a(u,-s.faceOut,e.top),ci,l(e.top)),e.sill>.01&&i.seg(a(u,s.faceRoom,e.sill),a(u,-s.faceOut,e.sill),ci,l(e.sill)),e.sill<t&&e.top>t&&i.seg(a(u,s.faceRoom,t),a(u,-s.faceOut,t),Pu,tl+o))}function cv(i,e,t,n,r,s,o){let a=Math.min(e.cut_height,e.height),l=(f,d)=>(r.get(f)??[]).filter(d);for(let f of t.edges){let d=n.get(f.wall);for(let[m,b]of Eo(f,l(f.wall,v=>v.sill<=.005)))i.seg([m[0],.004,m[1]],[b[0],.004,b[1]],Ad);for(let[m,b]of Eo(f,l(f.wall,v=>v.sill<a&&v.top>a)))i.seg([m[0],a,m[1]],[b[0],a,b[1]],Pu,tl+d);let p=ko(f.wall,e.height,s),{H:x,topAt:g}=p;for(let[m,b]of Eo(f,l(f.wall,v=>v.top>=x-.021))){if(!o&&!p.varies){i.seg([m[0],x,m[1]],[b[0],x,b[1]],Ii,x<=a+1e-6?cr+d:d);continue}let v=Math.max(1,Math.ceil(Math.hypot(b[0]-m[0],b[1]-m[1])/.3)),y=M=>[m[0]+(b[0]-m[0])*M/v,m[1]+(b[1]-m[1])*M/v];for(let M=0;M<v;M++){let[S,_]=[y(M),y(M+1)],[w,R]=[g(S[0],S[1]),g(_[0],_[1])];i.seg([S[0],w,S[1]],[_[0],R,_[1]],Ii,Math.max(w,R)<=a+1e-6?cr+d:d)}}}let c=mh(r.values()),u=new Set(c.points.map(lv)),h=new Map;for(let[f,d]of r)h.set(f,nv(d,c));for(let f of t.corners){let d=iv(f.wall,f.p),x=(r.get(f.wall)??[]).some(b=>!!b.info.opening.front&&d>b.s0+.05&&d<b.s1-.05),g=(h.get(f.wall)??[]).some(b=>Math.abs(b-d)<.06);if(x||g||u.has(lv(f.p)))continue;let m=ko(f.wall,e.height,s).topAt(f.p[0],f.p[1]);i.segSplit([f.p[0],.004,f.p[1]],[f.p[0],m,f.p[1]],ci,Math.min(a,m),n.get(f.wall))}for(let f of r.values())for(let d of f){let p=d.info.opening.front,[x,g]=ph(d);$R(i,d,a,p?c.at(p,x):!1,p?c.at(p,g):!1)}}function uv(i,e){let t=new lt(!0,!0),n=[],r=new Wt,s=[],o=new W(Os.slab),a=(l,c=0,u=c-pi)=>{l.forEach((h,f)=>{let d=l[(f+1)%l.length];t.tri([h[0],u,h[1]],[h[0],c,h[1]],[d[0],c,d[1]],o),t.tri([h[0],u,h[1]],[d[0],c,d[1]],[d[0],u,d[1]],o)})};for(let l of i.rooms){if(l.points.length<3)continue;let c=Gr(l.points),u=gh[l.floor_material]??gh.wood,h=new W(u.color),f=e.filter(g=>ly(g,c)).map(g=>cy(g,.003));s.push(...f);let d=[...c,...f.flat()],p=t.count,x=Qr(l);for(let[g,m,b]of Vr(c,f)){let[v,y,M]=[d[g],d[m],d[b]];t.tri([v[0],x,v[1]],[M[0],x,M[1]],[y[0],x,y[1]],h,h,h,[v[0],v[1],M[0],M[1],y[0],y[1]],Xe,u.tile)}n.push({roomId:l.id,start:p,end:t.count,color:u.color}),a(c,x),Math.abs(x)>.005&&(a(c,Math.max(0,x),Math.min(0,x)),a([...c].reverse(),Math.max(0,x),Math.min(0,x)));for(let g of f)a([...Gr(g)].reverse()),g.forEach((m,b)=>{let v=g[(b+1)%g.length];r.seg([m[0],x+.006,m[1]],[v[0],x+.006,v[1]],Ii),r.seg([m[0],x-pi,m[1]],[v[0],x-pi,v[1]],ci)})}return{buffer:t,roomTris:n,holeLines:r,cutHoles:s}}var xh=.42,zp=.42;function hv(i,e,t){let n=new lt,r=new W(zp,zp,zp),s=new W(1,1,1),o=.002;for(let a of i)for(let[l,c]of Eo(a,(t.get(a.wall)??[]).filter(u=>u.sill<=.005))){let[u,h]=[c[0]-l[0],c[1]-l[1]],f=Math.hypot(u,h);if(f<.05)continue;let d=[h/f,-u/f],p=[(l[0]+c[0])/2+d[0]*.05,(l[1]+c[1])/2+d[1]*.05];if(!e.some(m=>m.points.length>=3&&Ve(p,m.points)))continue;let x=[l[0]+d[0]*xh,l[1]+d[1]*xh],g=[c[0]+d[0]*xh,c[1]+d[1]*xh];n.tri([l[0],o,l[1]],[x[0],o,x[1]],[g[0],o,g[1]],r,s,s),n.tri([l[0],o,l[1]],[g[0],o,g[1]],[c[0],o,c[1]],r,s,r)}return n}var Vp=(i,e)=>Number.parseInt(/^#?([0-9a-f]{6})$/i.exec(i?.trim()??"")?.[1]??e.slice(1),16),KR=i=>/^#?[0-9a-f]{6}$/i.test(i?.trim()??"");function Gp(i,e){return{outside:Vp(KR(e.wall_paint_outside)?e.wall_paint_outside:i.wall_paint_outside,g0),inside:Vp(i.wall_paint_inside,Vh),rooms:e.rooms.filter(t=>t.wall_paint&&t.points.length>=3).map(t=>({points:t.points,color:Vp(t.wall_paint,Vh)}))}}var ZR=14276045;function JR(i,e,t,n,r){let s=Math.hypot(t[0]-e[0],t[1]-e[1])||1,o=[(e[0]+t[0])/2,(e[1]+t[1])/2],a=[(t[1]-e[1])/s,-(t[0]-e[0])/s];Ve([o[0]+a[0]*.01,o[1]+a[1]*.01],i)&&(a=[-a[0],-a[1]]);let l=[o[0]+a[0]*.06,o[1]+a[1]*.06],c=n.rooms.find(u=>Ve(l,u.points));return c?c.color:r.some(u=>u.points.length>=3&&Ve(l,u.points))?n.inside:n.outside}function jR(i,e,t=-pi){let n=[-1/0,...new Set(i.flatMap(s=>[s.s0,s.s1])).values(),1/0].sort((s,o)=>s-o),r=[];for(let s=0;s+1<n.length;s++){let[o,a]=[n[s],n[s+1]];if(a-o<1e-6)continue;let l=Number.isFinite(o)&&Number.isFinite(a)?(o+a)/2:Number.isFinite(o)?o+1:a-1,c=i.filter(f=>f.s0<l&&f.s1>l).map(f=>[f.sill,f.top]).sort((f,d)=>f[0]-d[0]),u=[],h=t;for(let[f,d]of c)f>h+1e-4&&u.push([h,f]),h=Math.max(h,d);e>h+1e-4&&u.push([h,e]),r.push({t0:o,t1:a,ranges:u})}return r}function fv(i,e,t,n,r,s,o,a){let l=Math.min(e.cut_height,e.height),c=a?Cd:0,u=a?g=>(m,b)=>JR(g,m,b,a,e.rooms):null,h=a?ZR:Os.wallTop,f=mh(r.values()),d=g=>f.points.some(m=>Math.hypot(m[0]-g[0],m[1]-g[1])<.03),p=g=>g&&g.info.opening.front?[g.sill,g.top]:null,x=(g,m)=>{let b=[];for(let[v,y]of g)m[0]>v+1e-4&&b.push([v,Math.min(y,m[0])]),y>m[1]+1e-4&&b.push([Math.max(v,m[1]),y]);return b};for(let g of t){let m=n.get(g),b=_s([g.b[0]-g.a[0],g.b[1]-g.a[1]]),v=(r.get(g)??[]).sort((I,N)=>I.s0-N.s0),y=ko(g,e.height,s),{H:M,topAt:S}=y,_=Math.min(0,...[g.roomLeft,g.roomRight].map(I=>Qr(e.rooms.find(N=>N.id===I)))),w=jR(v,M,_-pi),R=Math.hypot(g.b[0]-g.a[0],g.b[1]-g.a[1]),A=(o||y.varies)&&y.lowestTop(0,R)<M-.001,C=A?w.flatMap(I=>{let N=Math.max(I.t0,-.5),F=Math.min(I.t1,R+.5),H=Math.max(1,Math.ceil((F-N)/.3));return Array.from({length:H},(B,X)=>({t0:X===0?I.t0:N+(F-N)*X/H,t1:X===H-1?I.t1:N+(F-N)*(X+1)/H,ranges:I.ranges,inner0:X>0,inner1:X<H-1}))}):w.map(I=>({...I,inner0:!1,inner1:!1})),O=I=>(I[0]-g.a[0])*b[0]+(I[1]-g.a[1])*b[1],D=d(g.a)?p(v[0]):null,P=d(g.b)?p(v[v.length-1]):null;for(let I of C){let N=Ud(g.footprint,g.a,b,I.t0,I.t1);if(N.length<3)continue;let F=I.t1<=1e-6&&I.t0<0?D:I.t0>=R-1e-6?P:null,H=F?x(I.ranges,F):I.ranges,B=(Y,Q)=>Math.abs(O(Y)-Q)<1e-4,X=(Y,Q)=>I.inner0&&B(Y,I.t0)&&B(Q,I.t0)||I.inner1&&B(Y,I.t1)&&B(Q,I.t1),V=(Y,Q)=>!f.points.length||Math.hypot(Y[0]-Q[0],Y[1]-Q[1])>.5?!1:f.points.some(se=>Math.min(Math.hypot(se[0]-Y[0],se[1]-Y[1]),Math.hypot(se[0]-Q[0],se[1]-Q[1]))<.05),re=(Y,Q)=>X(Y,Q)||V(Y,Q),be=A?Math.min(...N.map(([Y,Q])=>S(Y,Q))):M;for(let[Y,Q]of H){let se=Math.min(Q,A?Math.max(...N.map(([st,Te])=>S(st,Te))):Q);if(se-Y<1e-4||be-Y<.01)continue;let Se=Y>.01,le=A&&Q>be,Ie=(st,Te)=>Math.min(Q,S(st,Te));if(Y<l-1e-6){let st=se>l+1e-6?Rd+m:cr+m,Te=le&&be<l?(ht,bt)=>Math.min(l,Ie(ht,bt)):Math.min(se,l);Tt(i,N,Y,Te,Os.wall,h,{aoFrom:0,bottom:Se,fold:c+cr+m,topFold:c+st,skipSide:re,sideColor:u?.(N)})}se>l+1e-6&&be>l+1e-6&&Tt(i,N,Math.max(Y,l),le?Ie:se,Os.wall,h,{aoFrom:0,fold:c+m,bottom:Se&&Y>=l,skipSide:re,sideColor:u?.(N)})}}}}function Hp(i,e,t,n=[],r=[],s,o){let{walls:a,open:l}=al(i.rooms,{exterior:e,interior:t},i.walls??[]),c=ov(s),u=!!s,h=uv(i,n),{buckets:f,wallBucket:d}=sv(a),{openings:p,spans:x}=av(i,a,d,c),g=new lt;fv(g,i,a,d,x,c,u,o);let m=Bd(a,a.flatMap(_=>_.footprint)),b=new Wt;b.p.push(...h.holeLines.p),b.c.push(...h.holeLines.c),b.f.push(...h.holeLines.f),cv(b,i,m,d,x,c,u);let v=hv(m.edges,i.rooms,x),y=new Map;op(g,b,i,y,()=>new lt);for(let _ of r)dh(g,b,_.face,_.field,i.elevation);let M=Math.min(i.cut_height,i.height),S=[];for(let _ of i.furniture.filter(w=>!b0(w.type))){let w=g.count,R=b.p.length/6,A=Gt(i,_);Dl(_.type)||Ml(g,b,v,_,A),A+_.h>M+.05&&(Id(g,w,M,Iu),Ld(b,R,M,Iu)),S.push({id:_.id,start:w,end:g.count})}return{floor:h.buffer.geometry(),roomTris:h.roomTris,holes:h.cutHoles,walls:g.geometry(),ghosts:[...y].map(([_,w])=>({opacity:_,geometry:w.geometry()})),lines:b.geometry(),shadow:v.geometry(),buckets:f,openings:p,walls2d:a,openRooms:l,wallBuckets:a.map(_=>d.get(_)),furnitureTris:S,roofUnder:s}}function Wp(i,e){let t=_0(i,e),n=[...e.furniture.filter(a=>a.type==="stairwell").map(ts),...e.furniture.filter(a=>Qu(a)&&a.stair?.down).flatMap(mp)].filter(a=>a.length>=3),r=i.filter(a=>a.elevation<e.elevation).sort((a,l)=>l.elevation-a.elevation)[0];if(!r)return fr([...n,...t]);let o=r.furniture.filter(a=>(a.type==="stairs"||vt(a.type)?.hole)&&!(Qu(a)&&a.stair?.down)&&r.elevation+a.h>=e.elevation-.3).flatMap(a=>Qu(a)?mp(a):[ts(a)]).filter(a=>a.length>=3);return fr([...n,...o,...t])}var dv=.12,pv=1.35,Di=(i,e,t)=>Math.min(t,Math.max(e,i)),QR=i=>i<.5?4*i*i*i:1-(-2*i+2)**3/2,mv=i=>({...i,target:i.target.clone()});function gv({target:i,radius:e,theta:t,phi:n}){return new U(i.x+e*Math.sin(n)*Math.sin(t),i.y+e*Math.cos(n),i.z+e*Math.sin(n)*Math.cos(t))}function xv(i,e,t){let n=QR(t);return{target:new U().lerpVectors(i.target,e.target,n),radius:i.radius+(e.radius-i.radius)*n,theta:i.theta+(e.theta-i.theta)*n,phi:i.phi+(e.phi-i.phi)*n}}function bv(i,e){let t=e.theta??i.theta;for(;t-i.theta>Math.PI;)t-=2*Math.PI;for(;t-i.theta<-Math.PI;)t+=2*Math.PI;return{target:(e.target??i.target).clone(),radius:e.radius??i.radius,theta:t,phi:e.phi??i.phi}}function Xp(i,e,t,n,r){let s=2*i.radius*Math.tan(r*Math.PI/360)/(n||1),o=new U(Math.cos(i.theta),0,-Math.sin(i.theta)),a=new U(-Math.sin(i.theta),0,-Math.cos(i.theta));i.target.addScaledVector(o,-e*s),i.target.addScaledVector(a,t*s/Math.max(.35,Math.cos(i.phi)))}function yv(i,e,t,n){let r=n||1,s={theta:-e/r*3.2,phi:-t/r*2.4};return i.theta+=s.theta,i.phi=Di(i.phi+s.phi,dv,pv),s}function _v(i,e){return Math.abs(e.theta)<=1e-4&&Math.abs(e.phi)<=1e-4?!1:(i.theta+=e.theta,i.phi=Di(i.phi+e.phi,dv,pv),e.theta*=.9,e.phi*=.9,!0)}var eC={KeyW:"w",KeyA:"a",KeyS:"s",KeyD:"d",KeyQ:"q",KeyE:"e"},tC=new Set(["w","a","s","d","q","e","arrowup","arrowdown","arrowleft","arrowright"]);function nC(i){let e=i.code?.startsWith("Key")?eC[i.code]??null:i.key.toLowerCase();return e&&tC.has(e)?e:null}var iC=500,rC=400,sC=320,oC=6,vv=1.5,aC=1.8;function lC(i,e){let t=i.keys,n=(t.has("w")||t.has("arrowup")?1:0)-(t.has("s")||t.has("arrowdown")?1:0)-i.stick[1],r=(t.has("d")?1:0)-(t.has("a")?1:0),s=(t.has("arrowleft")||t.has("q")?1:0)-(t.has("arrowright")||t.has("e")?1:0)-i.stick[0];if(!n&&!r&&!s)return!1;let o=e/1e3;i.yaw+=s*aC*o;let[a,l]=[-Math.sin(i.yaw),-Math.cos(i.yaw)],[c,u]=[Math.cos(i.yaw),-Math.sin(i.yaw)];return i.eye.x=Di(i.eye.x+(a*n+c*r)*vv*o,i.bounds.x0,i.bounds.x1),i.eye.z=Di(i.eye.z+(l*n+u*r)*vv*o,i.bounds.z0,i.bounds.z1),!0}var El=class{view={target:new U,radius:16,theta:-.6,phi:.85};minRadius=2;maxRadius=80;locked=!1;walk=null;pointers=new Map;velocity={theta:0,phi:0};flight=null;press=null;lastTap=0;holdTimer;held=!1;grabbing=!1;swiping=null;pinch=null;listeners=[];el;camera;events;constructor(e,t,n){this.el=e,this.camera=t,this.events=n;let r=(l,c,u)=>{e.addEventListener(l,c,u),this.listeners.push([l,c])};r("pointerdown",l=>this.onDown(l)),r("pointermove",l=>this.onMove(l)),r("pointerup",l=>this.onUp(l)),r("pointercancel",l=>this.onUp(l)),r("wheel",l=>this.onWheel(l),{passive:!1}),r("contextmenu",l=>l.preventDefault());let s=l=>c=>{if(!this.walk||c.target?.closest?.("input, textarea, select"))return;let u=nC(c);u&&(c.preventDefault(),l?this.walk.keys.add(u):this.walk.keys.delete(u),this.events.change())},o=s(!0),a=s(!1);window.addEventListener("keydown",o),window.addEventListener("keyup",a),this.listeners.push(["__window_keydown",o],["__window_keyup",a])}dispose(){clearTimeout(this.holdTimer);for(let[e,t]of this.listeners)e.startsWith("__window_")?window.removeEventListener(e.slice(9),t):this.el.removeEventListener(e,t)}get active(){return this.pointers.size>0||this.flight!==null}get busy(){return this.active}update(e){if(this.walk){let n=this.walk,r=lC(n,n.last?Math.min(100,e-n.last):16);n.last=r?e:0;let s=new U(-Math.sin(n.yaw)*Math.cos(n.pitch),Math.sin(n.pitch),-Math.cos(n.yaw)*Math.cos(n.pitch));return this.view.target.copy(n.eye).add(s),this.camera.position.copy(n.eye),this.camera.lookAt(this.view.target),r}let t=!1;if(this.flight){let{from:n,to:r,start:s,duration:o}=this.flight,a=Math.min(1,(e-s)/o);this.view=xv(n,r,a),a>=1&&(this.flight=null),t=!0}else this.pointers.size===0&&(t=_v(this.view,this.velocity));return this.camera.position.copy(gv(this.view)),this.camera.lookAt(this.view.target),t}flyTo(e,t=700){let n=bv(this.view,e),r=mv(this.view);this.velocity={theta:0,phi:0},t<=0||matchMedia("(prefers-reduced-motion: reduce)").matches?(this.view=n,this.flight=null):this.flight={from:r,to:n,start:performance.now(),duration:t},this.events.change()}local(e){let t=this.el.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]}stopMotion(){this.flight=null,this.velocity={theta:0,phi:0}}onDown(e){this.el.setPointerCapture(e.pointerId);let t=this.pointers.size===0;if(this.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY,button:e.button}),this.stopMotion(),t&&e.button===0&&this.events.grab?.(...this.local(e))){this.grabbing=!0;return}if(clearTimeout(this.holdTimer),this.held=!1,this.pointers.size===1){this.press={x:e.clientX,y:e.clientY,time:performance.now(),moved:!1};let[n,r]=this.local(e);this.holdTimer=setTimeout(()=>{!this.press||this.press.moved||this.pointers.size!==1||(this.held=!0,this.events.hold(n,r))},iC)}else this.press=null,this.pinch=this.pinchState()}onMove(e){let t=this.pointers.get(e.pointerId);if(!t)return;if(this.grabbing)return void this.events.drag?.(...this.local(e));if(this.swiping)return void this.events.swipeMove?.(e.clientY-this.swiping.startY);let[n,r]=[e.clientX-t.x,e.clientY-t.y];if(this.press&&!this.press.moved&&Math.hypot(e.clientX-this.press.x,e.clientY-this.press.y)>oC){this.press.moved=!0,clearTimeout(this.holdTimer);let[s,o]=this.local({clientX:this.press.x,clientY:this.press.y});if(this.pointers.size===1&&t.button===0&&!e.shiftKey&&this.events.swipeStart?.(s,o,e.clientX-this.press.x,e.clientY-this.press.y))return this.swiping={startY:this.press.y},this.velocity={theta:0,phi:0},void this.events.swipeMove?.(e.clientY-this.press.y)}if(this.locked){[t.x,t.y]=[e.clientX,e.clientY];return}if(this.walk){if(!(this.press&&!this.press.moved)&&this.pointers.size===1){let s=this.el.clientHeight||1;this.walk.yaw+=n/s*2.4,this.walk.pitch=Di(this.walk.pitch+r/s*1.8,-1.1,1.1),this.events.change()}[t.x,t.y]=[e.clientX,e.clientY];return}if(this.pointers.size===1)this.press&&!this.press.moved||(t.button===1||t.button===2||e.shiftKey?Xp(this.view,n,r,this.el.clientHeight,this.camera.fov):this.velocity=yv(this.view,n,r,this.el.clientHeight)),[t.x,t.y]=[e.clientX,e.clientY];else{[t.x,t.y]=[e.clientX,e.clientY];let s=this.pinchState();this.pinch&&s&&(this.zoom(this.pinch.dist/Math.max(1,s.dist)),Xp(this.view,s.mid[0]-this.pinch.mid[0],s.mid[1]-this.pinch.mid[1],this.el.clientHeight,this.camera.fov)),this.pinch=s}this.pointers.size===1&&this.press&&!this.press.moved||this.events.change()}onUp(e){if(this.pointers.has(e.pointerId)){if(this.pointers.delete(e.pointerId),this.grabbing)return this.grabbing=!1,void this.events.drop?.();if(this.swiping)return this.swiping=null,this.press=null,void this.events.swipeEnd?.();if(this.pointers.size<2&&(this.pinch=null),clearTimeout(this.holdTimer),this.held)this.held=!1,this.press=null;else if(this.press&&!this.press.moved&&e.type==="pointerup"&&performance.now()-this.press.time<rC){let[t,n]=this.local(e),r=performance.now(),s=r-this.lastTap<sC;this.lastTap=s?0:r,s?this.events.doubleTap(t,n):this.events.tap(t,n)}this.pointers.size===0&&(this.press=null),this.events.change()}}onWheel(e){if(e.preventDefault(),!this.locked){if(this.walk){let t=Di(-e.deltaY*(e.deltaMode===1?.05:.002),-.6,.6),n=this.walk;n.eye.x=Di(n.eye.x-Math.sin(n.yaw)*t,n.bounds.x0,n.bounds.x1),n.eye.z=Di(n.eye.z-Math.cos(n.yaw)*t,n.bounds.z0,n.bounds.z1),this.events.change();return}this.flight=null,this.zoom(Math.exp(e.deltaY*(e.deltaMode===1?.05:.0015))),this.events.change()}}zoom(e){this.view.radius=Di(this.view.radius*e,this.minRadius,this.maxRadius)}pinchState(){let[e,t]=[...this.pointers.values()];return t?{dist:Math.hypot(e.x-t.x,e.y-t.y),mid:[(e.x+t.x)/2,(e.y+t.y)/2]}:null}};function cC(i,e){let t=vt(e);if(!t)return null;let n=i.scale??1,[r,s,o]=t.size.map(a=>a*n);return{id:`${i.id}:vehicle`,type:e,x:i.x,z:i.z,rotation:i.rotation,w:r,d:s,h:o,variant:i.variant??null,entity:null,power:null}}function bh(i,e){let t=[],n=!1;for(let r of i.furniture){t.push(r);let s=r.type==="parking"?e.get(r.id):void 0,o=s?cC(r,s):null;o&&(t.push(o),n=!0)}return n?{...i,furniture:t}:i}var uC="https://tile.openstreetmap.org/{z}/{x}/{y}.png";var hC=40075016686e-3,yh=Math.PI/180,fC=18,dC=.5,pC=160;function mC(i,e,t){let n=2**t,r=(e+180)/360*n,s=(1-Math.log(Math.tan(i*yh)+1/Math.cos(i*yh))/Math.PI)/2*n;return[r,s]}var gC=(i,e)=>hC*Math.cos(i*yh)/2**e;function Mv(i,e,t,n=pC){let[r,s]=mC(i,e,t),o=gC(i,t),a=n/o,l=2**t-1,c=[];for(let u=Math.floor(s-a);u<=Math.floor(s+a);u++)for(let h=Math.floor(r-a);h<=Math.floor(r+a);h++){if(u<0||u>l)continue;let f=(h%(l+1)+l+1)%(l+1);c.push({x:f,y:u,z:t,east:(h-r)*o,north:-(u-s)*o,size:o})}return c}function Sv(i,e){return i.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y)).replace("{s}","abc"[(e.x+e.y)%3])}var wv=i=>i.url&&i.url.startsWith("https://")?i.url:uC;function Tv(i,e,t,n){let r=t*yh;return[n.x+i*Math.cos(r)+e*Math.sin(r),n.z+i*Math.sin(r)-e*Math.cos(r)]}var Av=i=>!!i&&i.on===!0&&Number.isFinite(i.lat)&&Number.isFinite(i.lon),Ev=i=>({x:i.x??0,z:i.z??0,opacity:i.opacity??dC,zoom:i.zoom??fC});var xC="strict-origin-when-cross-origin",Yp=new Map;function Rv(i){let e=Yp.get(i);return e||(e=fetch(i,{referrerPolicy:xC,mode:"cors",credentials:"omit"}).then(async t=>t.ok&&(t.headers.get("content-type")??"").startsWith("image/")?await t.blob():null).catch(()=>null).then(t=>(t||setTimeout(()=>Yp.delete(i),6e4),t)),Yp.set(i,e)),e}var zo=256,bC=Math.PI/180,_h=class{mesh=new we(new sn(1,1),new Ke({transparent:!0,depthWrite:!1,side:ut}));canvas=null;texture=null;key="";generation=0;centre=[0,0];onChange=()=>{};scene;constructor(e){this.scene=e,this.mesh.rotation.order="YXZ",this.mesh.renderOrder=-2,this.mesh.visible=!1,this.mesh.name="live-map",e.add(this.mesh)}set(e,t,n,r=1){if(!Av(e)){this.mesh.visible=!1,this.generation++,this.key="";return}let s=Ev(e),o=wv(e),a=`${e.lat},${e.lon},${s.zoom},${o}`;a!==this.key&&this.load(a,e,s.zoom,o);let[l,c]=this.centre,[u,h]=Tv(l,c,t,s);this.mesh.position.set(u,n,h),this.mesh.rotation.set(-Math.PI/2,-t*bC,0);let f=this.mesh.material;f.opacity=s.opacity,f.color.setScalar(r),this.mesh.visible=this.canvas!==null}load(e,t,n,r){this.key=e;let s=++this.generation,o=Mv(t.lat,t.lon,n);if(!o.length)return;let a=o[0].size,l=Math.min(...o.map(x=>x.east)),c=Math.max(...o.map(x=>x.north)),u=Math.round((Math.max(...o.map(x=>x.east))-l)/a)+1,h=Math.round((c-Math.min(...o.map(x=>x.north)))/a)+1,f=document.createElement("canvas");f.width=u*zo,f.height=h*zo,this.canvas=f,this.texture?.dispose(),this.texture=new zt(f),this.texture.colorSpace=ft,this.texture.anisotropy=4;let d=this.mesh.material;d.map=this.texture,d.needsUpdate=!0,this.mesh.geometry.dispose(),this.mesh.geometry=new sn(u*a,h*a),this.centre=[l+u*a/2,c-h*a/2];let p=f.getContext("2d");if(p)for(let x of o)this.draw(p,x,r,s,Math.round((x.east-l)/a),Math.round((c-x.north)/a))}draw(e,t,n,r,s,o){Rv(Sv(n,t)).then(a=>a?createImageBitmap(a):null).then(a=>{!a||r!==this.generation||(e.drawImage(a,s*zo,o*zo,zo,zo),this.texture&&(this.texture.needsUpdate=!0),this.onChange())})}dispose(){this.generation++,this.scene.remove(this.mesh),this.mesh.geometry.dispose(),this.mesh.material.dispose(),this.texture?.dispose()}};var yC=globalThis,Cv=yC.__nextfloorPluginStore??={plugins:new Map,listeners:new Set},_C=Cv.plugins,XB=Cv.listeners;var vC=5;function MC(i,e){i.errors.length<vC&&i.errors.push(e instanceof Error?e.message:String(e))}function SC(i){for(let{plugin:e,status:t}of _C.values()){let n=e.lightAnimations?.[i];if(n)return{fn:n,status:t}}return null}function Pv(i,e,t){let n=SC(e);if(!n)return i;try{let r=n.fn({color:[...i.color],level:i.level},t);if(!(r&&Array.isArray(r.color)&&r.color.length===3&&r.color.every(a=>Number.isFinite(a))&&Number.isFinite(r.level)))return i;let o=a=>Math.max(0,Math.min(1,a));return{color:[o(r.color[0]),o(r.color[1]),o(r.color[2])],level:o(r.level)}}catch(r){return MC(n.status,r),i}}var Iv={rainbow:(i,e)=>{let t=(e*.08%1+1)%1,n=r=>Math.max(0,Math.min(1,Math.abs((t*6+r)%6-3)-1));return{color:[n(0),n(4),n(2)],level:i.level}},flicker:(i,e)=>({...i,level:i.level*(.75+.15*Math.sin(e*17)+.1*Math.sin(e*31+1))}),pulse:(i,e)=>({...i,level:i.level*(.65+.35*Math.sin(e*Math.PI))})};function Lv(i,e,t){return!i||!e?i:Object.prototype.hasOwnProperty.call(Iv,e)?Iv[e]?.(i,t)??i:Pv(i,e,t)}var Vo=2043986,Wr=2769520,Fv=2242399,vh=1845831,Ov=1450554,mi=16758087,Nv=1846349,Dv=2572395,Uv=1120816,Bv=1845831,kv=3662079,zv=5995775,Vv=9085695,Xr=Ue(3662079,.08),Gv=1.2,Hv=1.5,Wv=.2,Xv=.52;function Mh(i,e,t,n,r,s){let o=(x,g,m)=>e(x,g,m),{x0:a,x1:l,n0:c,n1:u,y0:h,y1:f}=t,d=x=>Ue(n.getHex(),x),p=[[o(a,c,f),o(l,c,f),o(l,u,f),o(a,u,f),r],[o(a,c,h),o(l,c,h),o(l,u,h),o(a,u,h),d(.6)],[o(a,u,h),o(l,u,h),o(l,u,f),o(a,u,f),n],[o(a,c,h),o(l,c,h),o(l,c,f),o(a,c,f),d(.85)],[o(a,c,h),o(a,u,h),o(a,u,f),o(a,c,f),d(.92)],[o(l,c,h),o(l,u,h),o(l,u,f),o(l,c,f),d(.92)]];for(let[x,g,m,b,v]of p)i.tri(x,g,m,v,v,v,void 0,s),i.tri(x,m,b,v,v,v,void 0,s)}function Vt(i,e,t,n,r,{cut:s,bucket:o}){if(t.y1<=s+1e-6)return Mh(i,e,t,n,r,Xe);if(t.y0>=s-1e-6)return Mh(i,e,t,n,r,o);Mh(i,e,{...t,y1:s},n,r,Xe),Mh(i,e,{...t,y0:s},n,r,o)}function Qn(i,e,t,n,r,s,o,a,{cut:l,bucket:c},u=0){let h=(f,d,p)=>{let x=y=>u?(o-y)/u:.5,[g,m,b,v]=[e(t,r,f),e(n,r,f),e(n,r,d),e(t,r,d)];i.tri(g,m,b,a,a,a,[0,x(f),1,x(f),1,x(d)],p),i.tri(g,b,v,a,a,a,[0,x(f),1,x(d),0,x(d)],p)};o<=l+1e-6?h(s,o,Xe):s>=l-1e-6?h(s,o,c):(h(s,l,Xe),h(l,o,c))}function Yv(i,e,t,n,r,s,o,a,l,c){let[u,h,f,d]=[e(t,r,o),e(n,r,o),e(n,s,o),e(t,s,o)],p=(s-r)/c;i.tri(u,h,f,a,a,a,[0,0,1,0,1,p],l),i.tri(u,f,d,a,a,a,[0,0,1,p,0,p],l)}var wC=16777215,TC=13225686,AC=15722456,qv=.08,$v=.085;function Kv(i){let{info:e,state:t,frame:n,fold:r}=i;if(t.cover===null)return;let[s,o,a]=[e.width,e.sill,e.top],l=e.opening.blind??"roller",c=-e.faceOut,u=e.faceRoom;l==="inside"?Vt(i.frames,n,{x0:-.03,x1:s+.03,n0:u,n1:u+.07,y0:a-.02,y1:a+.07},new W(15921906),new W(16250871),r):Vt(i.frames,n,{x0:-.05,x1:s+.05,n0:c-.15,n1:c,y0:a,y1:a+.2},new W(Ov),new W(Wr),r);let h=t.cover2!=null?[[0,s/2,t.cover,t.slats??0],[s/2,s,t.cover2,t.slats2??t.slats??0]]:[[0,s,t.cover,t.slats??0]];for(let[f,d,p,x]of h){let g=Math.min(1,Math.max(0,p));if(g<=.01)continue;let m=a-g*(a-o);l==="inside"?Qn(i.blinds,n,f+.01,d-.01,u+.04,m,a-.02,new W(AC),r):l==="venetian"?EC(i,f,d,c-.07,m,a,x):Qn(i.blinds,n,f,d,c-.07,m,a,new W(wC),r,.045)}}function EC(i,e,t,n,r,s,o){let{frame:a,fold:l}=i,c=new W(TC),u=Math.PI/2*(.12+.88*Math.min(1,Math.max(0,o))),h=Math.sin(u)*$v/2,f=Math.cos(u)*$v/2;for(let d=s-qv/2;d>r;d-=qv){let p=d>=l.cut?l.bucket:Xe,[x,g,m,b]=[a(e,n-h,d+f),a(t,n-h,d+f),a(t,n+h,d-f),a(e,n+h,d-f)];i.blinds.tri(x,g,m,c,c,c,[0,.5,1,.5,1,.5],p),i.blinds.tri(x,m,b,c,c,c,[0,.5,1,.5,0,.5],p)}}function Zv(i){let{info:e,state:t,frame:n,fold:r}=i,[s,o,a]=[e.width,e.top,Math.min(0,e.sill)],l=e.opening.type==="garage"&&(i.markClosed?!!t.sensed&&(t.cover??1)>=.95:(t.cover??1)<.95),c=l?Ue(mi,.8):new W(Vo),u=l?Ue(mi,1):new W(Wr),[h,f]=[-e.faceOut-.012,e.faceRoom+.012],d=(p,x,g)=>Vt(i.frames,n,{x0:p,x1:x,n0:h,n1:f,y0:g,y1:o+.045},c,u,r);d(-.045,.02,a),d(s-.02,s+.045,a),d(.02,s-.02,o-.02)}function Jv(i){let{info:e,state:t,frame:n,fold:r,mid:s}=i,[o,a,l]=[e.width,e.top,Math.min(0,e.sill)],c=a-l,u=_r(e.opening,e.exterior),h=u==="passage",f=w0(u),d=e.opening.swing==="out"?-1:1,p=d>0?e.faceRoom:-e.faceOut,x=e.opening.leaves===2,g=new W(Vo),m=new W(Wr),b=.02,v=o-.02,y=S0(o,u,e.hingeAtStart,e.opening);if(y){for(let[R,A]of y.panels){let C=(O,D,P,I)=>Vt(i.frames,n,{x0:O,x1:D,n0:s-.03,n1:s+.03,y0:P,y1:I},g,m,r);C(R,R+.04,l+.02,a-.02),C(A-.04,A,l+.02,a-.02),C(R,A,l+.02,l+.1),Qn(i.glass,n,R+.04,A-.04,s,l+.1,a-.02,Xr,r)}b=y.x0,v=y.x1}let M=x?(v-b)/2-.004:v-b,S=f?.06:.04;f&&(Vt(i.frames,n,{x0:.02,x1:o-.02,n0:-e.faceOut-.02,n1:e.faceRoom,y0:l,y1:l+.02},new W(vh),m,r),e.exterior&&Vt(i.frames,n,{x0:o/2-.08,x1:o/2+.08,n0:-e.faceOut-.1,n1:-e.faceOut,y0:a+.1,y1:a+.17},Ue(mi,.55),Ue(mi,.85),{cut:r.cut,bucket:Xe}));let _=e.opening.open_angle?Math.min(180,Math.max(5,e.opening.open_angle))*pt:Hv,w=h?[]:[[e.hingeAtStart,t.open]];x&&!h&&w.push([!e.hingeAtStart,t.open2??0]);for(let[R,A]of w){let C=Math.min(1,Math.max(0,A)),O=u==="sliding"?0:C*_,D=u==="sliding"?C*M:0,P=(Q,se,Se)=>{let le=Q*Math.cos(O)-se*Math.sin(O)-D,Ie=p+d*(se*Math.cos(O)+Q*Math.sin(O)+(D?.05:0));return n(R?b+le:v-le,Ie,Se)},I={cut:r.cut,bucket:C>.05?Xe:r.bucket},N=i.markClosed?!!t.sensed&&C<.05:C>.9&&!(R===e.hingeAtStart&&t.assumed),F=N?Ue(mi,.7):new W(f?Uv:Nv),H=N?Ue(mi,.9):new W(f?Bv:Dv),B=(Q,se,Se,le,Ie=-S,st=0)=>Vt(i.frames,P,{x0:Q,x1:se,n0:Ie,n1:st,y0:Se,y1:le},F,H,I);u==="glass"?(B(0,.05,l+.01,a-.01),B(M-.05,M,l+.01,a-.01),B(.05,M-.05,l+.01,l+.12),B(.05,M-.05,a-.08,a-.01),Qn(i.glass,P,.05,M-.05,-S/2,l+.12,a-.08,Xr,I)):B(0,M,l+.01,a-.01),u==="front_glass"?Qn(i.glass,P,.12,M-.12,.001,l+c*.55,a-.18,Xr,I):f&&Qn(i.glass,P,.1,.18,.001,l+.3,a-.3,Xr,I);let X=l+Math.min(1.05,c*.5),V=f?.3:.012,[re,be]=f?[M-.11,M-.08]:[M-.16,M-.05],Y=(Q,se)=>Vt(i.frames,P,{x0:re,x1:be,n0:Q,n1:se,y0:X-V,y1:X+V},new W(zv),new W(Vv),I);if(Y(.004,.05),Y(-S-.05,-S-.004),t.unlocked){let Q=new W(kv);Vt(i.frames,P,{x0:M-.012,x1:M+.004,n0:-S-.004,n1:.004,y0:l+.06,y1:a-.06},Q,Q,{cut:r.cut,bucket:Xe})}}}function jv(i){let{info:e,state:t,frame:n,fold:r}=i,[s,o,a]=[e.width,e.top,Math.min(0,e.sill)],l=Math.min(1,Math.max(0,t.cover??1)),c=new W(13951231),u=e.faceRoom-.03;l>.01&&Qn(i.blinds,n,.02,s-.02,u,a+(o-a)*(1-l),o,c,r,.5);let h=(1-l)*(o-a);h>.01&&Yv(i.blinds,n,.02,s-.02,u,u+h,o+.03,c,r.bucket,.5)}var RC=4936290,CC=7041926,Qv=2764860,eM=9082024;function tM(i,e){let{info:t}=i;return t.opening.type!=="window"||!t.exterior||t.opening.light_well===!1?!1:t.opening.light_well===!0||t.sill<e-.02}function nM(i,e){let{info:t,frame:n}=i,r={cut:i.fold.cut,bucket:Xe},[s,o]=[-.12,t.width+.12],a=-t.faceOut,l=.7,c=Math.min(t.sill-.25,e-.3),u=e,h=new W(RC),f=new W(CC),d=.07,p=(m,b,v,y)=>Vt(i.frames,n,{x0:m,x1:b,n0:v,n1:y,y0:c,y1:u},h,f,r);p(s-d,s,a-l,a),p(o,o+d,a-l,a),p(s-d,o+d,a-l-d,a-l),Vt(i.frames,n,{x0:s,x1:o,n0:a-l,n1:a,y0:c-d,y1:c},h,f,r);let x=(m,b)=>Vt(i.frames,n,{x0:m,x1:b,n0:a-l,n1:a,y0:u-.025,y1:u},new W(Qv),new W(eM),r),g=Math.max(3,Math.round((o-s)/.06));for(let m=0;m<=g;m++){let b=s+(o-s)*m/g;x(b-.008,b+.008)}Vt(i.frames,n,{x0:s,x1:o,n0:a-l-.01,n1:a-l+.02,y0:u-.03,y1:u},new W(Qv),new W(eM),r)}var Ns={open:0,open2:0,tilt:0,tilt2:0,cover:null};function iM(i){let{info:e,frame:t,fold:n,mid:r}=i,[s,o,a]=[e.width,e.sill,e.top],[l,c]=[.04,.025],u=new W(Vo),h=new W(Wr),f=(b,v,y,M)=>Vt(i.frames,t,{x0:b,x1:v,n0:r-c,n1:r+c,y0:y,y1:M},u,h,n);i.first&&f(0,l,o,a),i.last&&f(s-l,s,o,a);let[d,p]=[i.first?l:-i.over[0],i.last?s-l:s+i.over[1]];f(d,p,o,o+.03),f(d,p,a-l,a);let x=e.opening.front?0:e.opening.panes,g=Math.max(1,x==null?Math.max(1,Math.round((p-d)/.9)):Math.round(x)),m=(p-d)/g;for(let b=1;b<g;b++)f(d+b*m-.02,d+b*m+.02,o+.03,a-l);for(let b=0;b<g;b++){let v=d+b*m+(b?.02:0),y=d+(b+1)*m-(b<g-1?.02:0);Qn(i.glass,t,v,y,r,o+.03,a-l,Xr,n)}}function PC(i,e,t,n,r,s){let o=i-2*e,a=.04;if(n===2){let u=o/4+a/2,h=u-a-.02;return[{atStart:!0,x0:e,x1:e+u,open:0,tilt:0,slide:0,track:0},{atStart:!0,x0:e+o/4-a/2,x1:e+o/2,open:t?r:s,tilt:0,slide:-h,track:1},{atStart:!1,x0:e+o/2,x1:i-e-o/4+a/2,open:t?s:r,tilt:0,slide:h,track:1},{atStart:!1,x0:i-e-u,x1:i-e,open:0,tilt:0,slide:0,track:0}]}let l=o/2,c=l-a-.02;return t?[{atStart:!0,x0:e,x1:e+l+a/2,open:r,tilt:0,slide:c,track:1},{atStart:!1,x0:e+l-a/2,x1:i-e,open:0,tilt:0,slide:0,track:0}]:[{atStart:!0,x0:e,x1:e+l+a/2,open:0,tilt:0,slide:0,track:0},{atStart:!1,x0:e+l-a/2,x1:i-e,open:r,tilt:0,slide:-c,track:1}]}function rM(i){let{info:e,state:t,frame:n,fold:r,mid:s}=i,[o,a,l]=[e.width,e.sill,e.top],[c,u]=[.06,.035],h=new W(Vo),f=new W(Wr),d=new W(vh),p=(A,C,O,D)=>Vt(i.frames,n,{x0:A,x1:C,n0:s-u,n1:s+u,y0:O,y1:D},h,f,r),x=a+(a>.05?c:.03);p(0,c,a,l),p(o-c,o,a,l),p(c,o-c,a,x),p(c,o-c,l-c,l);let g=e.opening.sill_boards??"auto";g!=="none"&&(g!=="auto"||a>.3)&&(g!=="outside"&&Vt(i.frames,n,{x0:-.04,x1:o+.04,n0:s+u,n1:e.faceRoom+.07,y0:a-.03,y1:a},d,f,r),e.exterior&&g!=="inside"&&Vt(i.frames,n,{x0:-.03,x1:o+.03,n0:-e.faceOut-.06,n1:s-u,y0:a-.04,y1:a-.02},d,f,r));let m=.055,[b,v]=[x,l-c],[y,M]=[s+u,s+u+.06],S=e.hingeAtStart,_=e.opening.opens??"turn",w=_==="slide"?PC(o,c,S,e.opening.leaves,t.open,t.open2??0):e.opening.leaves===2?[{atStart:S,x0:S?c:o/2,x1:S?o/2:o-c,open:t.open,tilt:t.tilt},{atStart:!S,x0:S?o/2:c,x1:S?o-c:o/2,open:t.open2??0,tilt:t.tilt2??0}]:[{atStart:S,x0:c,x1:o-c,open:t.open,tilt:t.tilt}],R=_r(e.opening,e.exterior);for(let A of w){let C=_==="top"?Math.max(A.open,A.tilt)*Xv:0,D=(_!=="slide"||!!A.slide)&&(A.open>.02||A.tilt>.02),P=i.markClosed?!!t.sensed&&!D:D,I=P?Ue(mi,.75):new W(Fv),N=P?Ue(mi,.95):f,F=A.x1-A.x0,H=_==="turn",B=H?A.open*Gv:0,X=H?A.tilt*Wv:0,V=(A.slide??0)*A.open,re=_==="slide"&&A.track===0?-.065:0,be=(se,Se,le)=>{if(C>0){let[et,Yt]=[Se-y,le-v],[kt,on]=[Math.cos(C),Math.sin(C)];return n(A.atStart?A.x0+se:A.x1-se,y+et*kt+Yt*on,v-et*on+Yt*kt)}let Ie=le-b,st=Se+Ie*Math.sin(X)+re,Te=b+Ie*Math.cos(X),ht=se*Math.cos(B)-(st-y)*Math.sin(B),bt=y+(st-y)*Math.cos(B)+se*Math.sin(B);return n((A.atStart?A.x0+ht:A.x1-ht)+V,bt,Te)},Y={cut:r.cut,bucket:B>.05||C>.05?Xe:r.bucket},Q=(se,Se,le,Ie,st=y,Te=M)=>Vt(i.frames,be,{x0:se,x1:Se,n0:st,n1:Te,y0:le,y1:Ie},I,N,Y);if(Q(0,m,b,v),Q(F-m,F,b,v),Q(m,F-m,b,b+m),Q(m,F-m,v-m,v),Qn(i.glass,be,m,F-m,(y+M)/2,b+m,v-m,P?Ue(mi,.16):Xr,Y),R==="bars"){let[se,Se]=[(b+v)/2,(y+M)/2];Q(m,F-m,se-.012,se+.012,Se-.012,Se+.012),Q(F/2-.012,F/2+.012,b+m,v-m,Se-.012,Se+.012)}}}var qp=i=>i.opening.front??i.opening.id;function $p(i,e,t,n=-1/0){let r=new lt,s=new lt,o=new lt(!0),a=[],l=[],c=[],u=new Map;i.forEach((x,g)=>{let m=qp(x);u.set(m,[...u.get(m)??[],g])});let h=x=>[[x.start[0],x.start[1]],[x.start[0]+x.axis[0]*x.width,x.start[1]+x.axis[1]*x.width]],f=x=>`${Math.round(x[0]*50)},${Math.round(x[1]*50)}`,d=new Map,p=new Map;for(let x of u.values()){let g=new Map,m=new Map;for(let v of x){let[y,M]=h(i[v]);g.set(f(y),[...g.get(f(y))??[],v]),m.set(f(M),[...m.get(f(M))??[],v])}let b=(v,y)=>{if(y==null||y===v)return 0;let M=Math.abs((i[v].faceRoom-i[v].faceOut)/2),[S,_]=[i[v].axis,i[y].axis],w=Math.max(-1,Math.min(1,S[0]*_[0]+S[1]*_[1])),R=Math.acos(w);return R<Math.PI/2?Math.min(M*Math.tan(R/2),M):0};for(let v of x){let[y,M]=h(i[v]),S=(m.get(f(y))??[]).find(w=>w!==v),_=(g.get(f(M))??[]).find(w=>w!==v);d.set(v,[S==null,_==null]),p.set(v,[b(v,S),b(v,_)])}}for(let x=0;x<i.length;x++){let g=i[x],m={frames:r.count,glass:s.count,blinds:o.count},b=g.opening.type,v=_r(g.opening,g.exterior),[y,M]=d.get(x)??[!0,!0],S={info:g,state:e.get(qp(g))??Ns,frame:(w,R,A)=>[g.start[0]+g.axis[0]*w+g.toRoom[0]*R,A,g.start[1]+g.axis[1]*w+g.toRoom[1]*R],mid:(g.faceRoom-g.faceOut)/2,markClosed:g.opening.mark==="closed",fold:{cut:t,bucket:g.bucket},frames:r,glass:s,blinds:o,first:y,last:M,over:p.get(x)??[0,0]};(b==="door"&&v!=="passage"||b==="garage")&&Zv(S),b==="door"?Jv(S):b==="garage"?jv(S):v==="glass_wall"?iM(S):rM(S),tM(S,n)&&nM(S,n),b!=="garage"&&Kv(S);let _=qp(g);a.push({id:_,start:m.frames,end:r.count}),l.push({id:_,start:m.glass,end:s.count}),c.push({id:_,start:m.blinds,end:o.count})}return{frames:r.geometry(),glass:s.geometry(),blinds:o.geometry(),frameTris:a,glassTris:l,blindTris:c}}var Kp=Math.PI/180,Rl=2400,Go=1600,Zp=9,sM=360;function Sh(i,e=64){let t=document.createElement("canvas");t.width=t.height=e;let n=t.getContext("2d"),r=n.createRadialGradient(e/2,e/2,0,e/2,e/2,e/2);for(let[s,o]of i)r.addColorStop(s,o);return n.fillStyle=r,n.fillRect(0,0,e,e),new zt(t)}function IC(i){let t=document.createElement("canvas");t.width=128,t.height=128/2;let n=t.getContext("2d"),r=i*9301+49297,s=()=>(r=(r*9301+49297)%233280)/233280;for(let o=0;o<7;o++){let a=128*(.2+.6*s()),l=128/2*(.45+.25*s()),c=128*(.12+.14*s()),u=n.createRadialGradient(a,l,0,a,l,c);u.addColorStop(0,"rgba(255,255,255,0.9)"),u.addColorStop(.6,"rgba(255,255,255,0.45)"),u.addColorStop(1,"rgba(255,255,255,0)"),n.fillStyle=u,n.fillRect(0,0,128,128/2)}return new zt(t)}var wh=class{group=new ct;scene;bounds={x0:-10,x1:10,z0:-10,z1:10,y0:0,y1:8};view=null;rain;rainVel=new Float32Array(Rl*3);snow;snowPhase=new Float32Array(Go);hail;clouds=[];bolt;disc;halo;stars;cover;last=0;nextBolt=0;boltUntil=0;onFlash=null;constructor(e){this.scene=e,this.group.name="live-weather",this.group.renderOrder=5;let t=new Fe;t.setAttribute("position",new ke(new Float32Array(Rl*6),3)),this.rain=new gn(t,new Lt({color:11128309,transparent:!0,opacity:.5,depthWrite:!1}));let n=Sh([[0,"rgba(255,255,255,1)"],[.5,"rgba(255,255,255,0.6)"],[1,"rgba(255,255,255,0)"]],32),r=new Fe;r.setAttribute("position",new ke(new Float32Array(Go*3),3)),this.snow=new xn(r,new cn({color:16185855,size:.16,map:n,transparent:!0,opacity:.9,depthWrite:!1}));for(let h=0;h<Go;h++)this.snowPhase[h]=Math.random()*Math.PI*2;let s=new Fe;s.setAttribute("position",new ke(new Float32Array(600*3),3)),this.hail=new xn(s,new cn({color:15331839,size:.09,transparent:!0,opacity:.95,depthWrite:!1}));let o=Sh([[0,"rgba(0,0,0,0.55)"],[.7,"rgba(0,0,0,0.25)"],[1,"rgba(0,0,0,0)"]]);for(let h=0;h<Zp;h++){let f=new ji(new vi({map:IC(h+1),transparent:!0,opacity:0,depthWrite:!1,fog:!1})),d=new we(new sn(1,1),new Ke({map:o,transparent:!0,opacity:0,depthWrite:!1,blending:Ai}));d.rotation.x=-Math.PI/2,d.renderOrder=-1,this.clouds.push({sprite:f,shadow:d,angle:0,ring:1,lift:1,scale:1,speed:.6+Math.random()*.8,sx:0,sz:0}),this.group.add(f,d)}let a=new Fe;a.setAttribute("position",new ke(new Float32Array(144),3)),this.bolt=new gn(a,new Lt({color:14674175,transparent:!0,opacity:1,blending:Ft,depthWrite:!1})),this.bolt.visible=!1;let l=Sh([[0,"rgba(255,255,255,1)"],[.25,"rgba(255,255,255,0.9)"],[.32,"rgba(255,255,255,0.35)"],[1,"rgba(255,255,255,0)"]]);this.disc=new ji(new vi({map:l,transparent:!0,depthWrite:!1,blending:Ft,fog:!1})),this.halo=new ji(new vi({map:Sh([[0,"rgba(255,255,255,0.35)"],[1,"rgba(255,255,255,0)"]]),transparent:!0,depthWrite:!1,blending:Ft,fog:!1}));let c=new Float32Array(sM*3);for(let h=0;h<sM;h++){let f=h*2.39996,d=.08+.92*(h*.618034%1),p=Math.sqrt(1-d*d);c.set([Math.cos(f)*p,d,Math.sin(f)*p],h*3)}let u=new Fe;u.setAttribute("position",new ke(c,3)),this.stars=new xn(u,new cn({color:15660031,size:1.6,sizeAttenuation:!1,transparent:!0,opacity:0,depthWrite:!1,fog:!1})),this.cover=new we(new sn(1,1),new Ke({color:16777215,transparent:!0,opacity:0,depthWrite:!1})),this.cover.rotation.x=-Math.PI/2,this.cover.renderOrder=-1;for(let h of[this.rain,this.snow,this.hail,this.bolt,this.disc,this.halo,this.stars,this.cover])h.frustumCulled=!1,this.group.add(h);this.group.visible=!1,e.add(this.group)}get cloud(){return this.view?.weather?.cloud??0}setBounds(e){this.bounds=e,this.seed(),this.placeNight()}placeNight(){let e=this.view,t=e?.weather,n=this.bounds,r=Math.max(n.x1-n.x0,n.z1-n.z0),s=e?.sun&&e.disc?Math.min(1,Math.max(0,(-e.sun.elevation-4)/8)):0,o=this.stars.material;o.opacity=s*(1-(t?.cloud??0))*.9,this.stars.visible=o.opacity>.02,this.stars.position.set((n.x0+n.x1)/2,n.y0,(n.z0+n.z1)/2),this.stars.scale.setScalar(r*3);let a=this.cover.material,l=(t?.snow??0)+(t?.hail??0)*.5,c=t?.rain??0;a.color.setHex(l>.05?16054527:1848656),a.opacity=l>.05?.3+.45*Math.min(1,l):c>.1?.25*Math.min(1,c):0,this.cover.visible=a.opacity>.02,this.cover.position.set((n.x0+n.x1)/2,n.y0-.18,(n.z0+n.z1)/2),this.cover.scale.set(n.x1-n.x0,n.z1-n.z0,1)}set(e){let t=this.view;this.view=e,this.group.visible=!!e;let n=e?.weather??null;if(e&&n&&n.fog>.02&&!e.low){let r=new W(e.sky[0]/255,e.sky[1]/255,e.sky[2]/255);this.scene.fog=new ls(r,.008+.04*n.fog)}else this.scene.fog instanceof ls&&(this.scene.fog=null);(!t||t.low!==e?.low||!!t.weather!=!!n)&&this.seed(),this.placeDisc(),this.placeNight(),n?.lightning||this.endBolt()}windVector(){let e=this.view?.weather;if(!e)return[0,0];let n=((e.windFrom??270)+(this.view?.north??0)+180)*Kp,r=.4+7*e.wind;return[Math.sin(n)*r,-Math.cos(n)*r]}count(e,t){let n=this.view?.low??!1;return Math.round(Math.min(1,e)*t*(n?.3:1))}seed(){let e=this.bounds,t=this.view?.weather,n=()=>e.x0+Math.random()*(e.x1-e.x0),r=()=>e.z0+Math.random()*(e.z1-e.z0),s=()=>e.y0+Math.random()*(e.y1-e.y0),o=this.rain.geometry.getAttribute("position");for(let c=0;c<Rl;c++){let u=n(),h=s(),f=r();o.setXYZ(c*2,u,h,f),o.setXYZ(c*2+1,u,h-.4,f),this.rainVel[c*3+1]=8.5+Math.random()*3}o.needsUpdate=!0;let a=this.snow.geometry.getAttribute("position");for(let c=0;c<Go;c++)a.setXYZ(c,n(),s(),r());a.needsUpdate=!0;let l=this.hail.geometry.getAttribute("position");for(let c=0;c<l.count;c++)l.setXYZ(c,n(),s(),r());l.needsUpdate=!0,this.rain.geometry.setDrawRange(0,this.count(t?.rain??0,Rl)*2),this.snow.geometry.setDrawRange(0,this.count(t?.snow??0,Go)),this.hail.geometry.setDrawRange(0,this.count(t?.hail??0,600)),this.rain.visible=!!t&&t.rain>.01,this.snow.visible=!!t&&t.snow>.01,this.hail.visible=!!t&&t.hail>.01,this.clouds.forEach((c,u)=>{c.angle=u/Zp*Math.PI*2+Math.random()*.5,c.ring=1.7+Math.random()*.9,c.lift=.35+Math.random()*.35,c.scale=.55+Math.random()*.45,c.sx=e.x0+Math.random()*(e.x1-e.x0),c.sz=e.z0+Math.random()*(e.z1-e.z0)}),this.placeClouds(0)}placeClouds(e){let t=this.view,n=t?.weather,r=n?.cloud??0,s=this.bounds,o=(s.x0+s.x1)/2,a=(s.z0+s.z1)/2,l=Math.max(s.x1-s.x0,s.z1-s.z0),[c,u]=this.windVector(),h=Math.round(r*Zp),f=t?.sky??[20,28,44],d=(f[0]+f[1]+f[2])/765,p=n?.rain||n?.lightning?.3:0,x=Math.max(.12,Math.min(1,.28+d*.9-p-.25*Math.max(0,r-.6))),g=Math.hypot(c,u)/Math.max(20,l*4)*e*Math.sign(c||1);this.clouds.forEach((m,b)=>{let v=b<h;m.angle+=g*m.speed;let y=l*m.ring,M=m.sprite.material;M.color.setRGB(x,x*1.02,Math.min(1,x*1.12)),M.opacity=v?.3+.45*r:0,m.sprite.visible=v,m.sprite.position.set(o+Math.cos(m.angle)*y,s.y0+l*m.lift,a+Math.sin(m.angle)*y),m.sprite.scale.set(l*m.scale*1.6,l*m.scale*.6,1),m.sx+=c*.45*m.speed*e,m.sz+=u*.45*m.speed*e;let S=l*.4;m.sx>s.x1+S&&(m.sx=s.x0-S),m.sx<s.x0-S&&(m.sx=s.x1+S),m.sz>s.z1+S&&(m.sz=s.z0-S),m.sz<s.z0-S&&(m.sz=s.z1+S);let _=m.shadow.material;_.opacity=v?.12+.2*r:0,m.shadow.visible=v,m.shadow.position.set(m.sx,s.y0+.03,m.sz),m.shadow.scale.set(l*m.scale*.55,l*m.scale*.35,1)})}placeDisc(){let e=this.view,t=e?.sun,n=e?.weather?.cloud??0,r=!t||t.elevation<-3;if(!e||!t||!e.disc||n>.9||!r&&t.elevation<.5){this.disc.visible=this.halo.visible=!1;return}let s=this.bounds,o=new U((s.x0+s.x1)/2,s.y0,(s.z0+s.z1)/2),a=Math.max(70,Math.max(s.x1-s.x0,s.z1-s.z0)*3.5),l=((r?t.azimuth+180:t.azimuth)+e.north)*Kp,c=Math.max(8,Math.abs(t.elevation))*Kp,u=new U(Math.sin(l)*Math.cos(c),Math.sin(c),-Math.cos(l)*Math.cos(c)),h=o.addScaledVector(u,a),f=a*(r?.07:.1);this.disc.position.copy(h),this.halo.position.copy(h),this.disc.scale.setScalar(f),this.halo.scale.setScalar(f*3.2);let d=this.disc.material,p=this.halo.material,x=r?0:Math.max(0,1-t.elevation/20);d.color.set(r?14016242:new W(1,.9-.25*x,.6-.35*x)),p.color.copy(d.color),d.opacity=(r?.7:.95)*(1-n),p.opacity=(r?.35:.6)*(1-n),this.disc.visible=this.halo.visible=!0}endBolt(){this.bolt.visible&&(this.bolt.visible=!1,this.onFlash?.(!1))}strike(e){let t=this.bounds,r=(Math.random()<.5?-1:1)<0?t.x0-2-Math.random()*6:t.x1+2+Math.random()*6,s=t.z0+Math.random()*(t.z1-t.z0),o=t.y1+4,a=this.bolt.geometry.getAttribute("position"),l=24,c=o;for(let u=0;u<l;u++){let h=o-(u+1)/l*(o-t.y0),f=r+(Math.random()-.5)*1.6,d=s+(Math.random()-.5)*1.6;a.setXYZ(u*2,r,c,s),a.setXYZ(u*2+1,f,h,d),r=f,s=d,c=h}a.needsUpdate=!0,this.bolt.visible=!0,this.boltUntil=e+90+Math.random()*120,this.onFlash?.(!0)}step(e){let t=this.view,n=t?.weather;if(!t||!n)return this.last=0,!1;let r=this.last?Math.min(.1,(e-this.last)/1e3):0;this.last=e;let s=this.bounds,o=s.y1-s.y0,[a,l]=this.windVector();if(this.rain.visible&&r){let c=this.rain.geometry.getAttribute("position"),u=c.array,h=this.count(n.rain,Rl);for(let f=0;f<h;f++){let d=f*6,p=this.rainVel[f*3+1],x=u[d]+a*r,g=u[d+1]-p*r,m=u[d+2]+l*r;g<s.y0&&(g+=o,x=s.x0+Math.random()*(s.x1-s.x0)-a*.4,m=s.z0+Math.random()*(s.z1-s.z0)-l*.4);let b=.05;u[d]=x,u[d+1]=g,u[d+2]=m,u[d+3]=x-a*b,u[d+4]=g+p*b,u[d+5]=m-l*b}c.needsUpdate=!0}if(this.snow.visible&&r){let c=this.snow.geometry.getAttribute("position"),u=c.array,h=this.count(n.snow,Go),f=e/1e3;for(let d=0;d<h;d++){let p=d*3,x=this.snowPhase[d],g=u[p]+(a*.35+Math.sin(f*1.3+x)*.35)*r,m=u[p+1]-(.7+.5*(x*7%1))*r,b=u[p+2]+(l*.35+Math.cos(f*1.1+x)*.35)*r;m<s.y0&&(m+=o,g=s.x0+Math.random()*(s.x1-s.x0),b=s.z0+Math.random()*(s.z1-s.z0)),u[p]=g,u[p+1]=m,u[p+2]=b}c.needsUpdate=!0}if(this.hail.visible&&r){let c=this.hail.geometry.getAttribute("position"),u=c.array,h=this.count(n.hail,600);for(let f=0;f<h;f++){let d=f*3,p=u[d+1]-14*r;p<s.y0&&(p+=o),u[d]+=a*.5*r,u[d+1]=p,u[d+2]+=l*.5*r}c.needsUpdate=!0}return n.cloud>.01&&this.placeClouds(r),n.lightning&&!t.low?(this.nextBolt||(this.nextBolt=e+2500+Math.random()*6e3),e>=this.nextBolt&&(this.strike(e),this.nextBolt=e+3500+Math.random()*9e3),this.bolt.visible&&e>this.boltUntil&&this.endBolt()):this.nextBolt=0,this.rain.visible||this.snow.visible||this.hail.visible||n.cloud>.01||n.lightning}dispose(){this.endBolt(),this.group.traverse(e=>{let t=e;t.geometry?.dispose();let n=t.material;n?.map?.dispose(),n?.dispose()}),this.scene.remove(this.group),this.scene.fog instanceof ls&&(this.scene.fog=null)}};var Th=46,Ah=33,Ds=900;function Jp(){let i=document.createElement("canvas");i.width=i.height=32;let e=i.getContext("2d"),t=e.createRadialGradient(16,16,0,16,16,16);return t.addColorStop(0,"rgba(255,255,255,1)"),t.addColorStop(.35,"rgba(255,255,255,0.7)"),t.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=t,e.fillRect(0,0,32,32),new zt(i)}var Eh=class{group=new ct;scene;lift;tex=Jp();arcs=new Map;sparkFields=[];sparks;sparkBase=new Float32Array(Ds*3);sparkField=new Int16Array(Ds);sparkPhase=new Float32Array(Ds);sparkCount=0;last=0;constructor(e,t){this.scene=e,this.lift=t,this.group.name="live-energy";let n=new Fe;n.setAttribute("position",new ke(new Float32Array(Ds*3),3)),n.setAttribute("color",new ke(new Float32Array(Ds*3),3)),this.sparks=new xn(n,new cn({size:.4,map:this.tex,vertexColors:!0,transparent:!0,depthWrite:!1,blending:Ft})),this.sparks.frustumCulled=!1,this.group.add(this.sparks),e.add(this.group)}get active(){return this.arcs.size>0||this.sparkCount>0}setArcs(e){let t=new Set(e.map(n=>n.key));for(let[n,r]of this.arcs)t.has(n)||(this.group.remove(r.line,r.points),r.line.geometry.dispose(),r.line.material.dispose(),r.points.geometry.dispose(),r.points.material.dispose(),this.arcs.delete(n));for(let n of e){let r=this.arcs.get(n.key);if(!r){let o=new Fe;o.setAttribute("position",new ke(new Float32Array(Ah*3),3));let a=new Pn(o,new Lt({transparent:!0,opacity:.4,depthWrite:!1,blending:Ft})),l=new Fe;l.setAttribute("position",new ke(new Float32Array(Th*3),3));let c=new xn(l,new cn({size:.55,map:this.tex,transparent:!0,depthWrite:!1,blending:Ft}));a.frustumCulled=c.frustumCulled=!1;let u=new Float32Array(Th);for(let h=0;h<Th;h++)u[h]=Math.random();r={arc:n,line:a,points:c,phase:u,count:0,speed:0,a:new U,b:new U,c:new U,path:null,along:[]},this.arcs.set(n.key,r),this.group.add(a,c)}r.arc=n;let s=new W(n.color[0]/255,n.color[1]/255,n.color[2]/255);r.line.material.color.copy(s),r.line.material.opacity=n.via?.length&&n.cable?.9:.4,r.path=n.via?.length?Array.from({length:n.via.length+2},()=>new U):null,r.points.material.color.copy(s),r.count=n.power<=0?0:Math.max(3,Math.min(Th,Math.round(3+Math.sqrt(n.power)/2.2))),r.speed=.18+Math.min(.5,Math.log10(1+n.power)*.1),r.points.geometry.setDrawRange(0,r.count)}this.place()}setSparks(e){this.sparkFields=e;let t=e.reduce((r,s)=>r+s.quads.length*s.level,0),n=0;t>0&&e.forEach((r,s)=>{if(r.level<=0)return;let o=Math.round(Ds*r.quads.length*r.level/Math.max(t,e.reduce((a,l)=>a+l.quads.length,0)));for(let a=0;a<o&&n<Ds;a++,n++){let l=r.quads[Math.floor(Math.random()*r.quads.length)],c=Math.random(),u=Math.random();for(let h=0;h<3;h++){let f=l[0][h]+(l[1][h]-l[0][h])*c,d=l[3][h]+(l[2][h]-l[3][h])*c;this.sparkBase[n*3+h]=f+(d-f)*u+(h===1?.12:0)}this.sparkField[n]=s,this.sparkPhase[n]=Math.random()*Math.PI*2}}),this.sparkCount=n,this.sparks.geometry.setDrawRange(0,n),this.sparks.visible=n>0}world(e,t){let n=this.lift(e.floorId);return t.set(e.x,n.y+e.y,e.z),n.visible}place(){for(let e of this.arcs.values()){if(e.path){this.placeRoute(e,e.path);continue}let t=this.world(e.arc.from,e.a),n=this.world(e.arc.to,e.b),r=e.a.distanceTo(e.b);e.c.copy(e.a).add(e.b).multiplyScalar(.5),e.c.y=Math.max(e.a.y,e.b.y)+.6+r*.22;let s=t&&n;e.line.visible=e.points.visible=s;let o=e.line.geometry.getAttribute("position");for(let a=0;a<Ah;a++){let l=a/(Ah-1);o.setXYZ(a,...this.bezier(e,l))}e.line.geometry.setDrawRange(0,Ah),o.needsUpdate=!0}}placeRoute(e,t){let n=[e.arc.from,...e.arc.via??[],e.arc.to],r=!0;n.forEach((o,a)=>r=this.world(o,t[a])&&r),e.line.visible=e.points.visible=r,e.along=[0];for(let o=1;o<t.length;o++)e.along.push(e.along[o-1]+t[o].distanceTo(t[o-1]));let s=e.line.geometry.getAttribute("position");t.forEach((o,a)=>s.setXYZ(a,o.x,o.y,o.z)),e.line.geometry.setDrawRange(0,t.length),s.needsUpdate=!0}at(e,t){if(!e.path)return this.bezier(e,t);let n=e.along[e.along.length-1]||1,r=t*n,s=1;for(;s<e.along.length-1&&e.along[s]<r;)s++;let[o,a]=[e.path[s-1],e.path[s]],l=e.along[s]-e.along[s-1]||1,c=Math.max(0,Math.min(1,(r-e.along[s-1])/l));return[o.x+(a.x-o.x)*c,o.y+(a.y-o.y)*c,o.z+(a.z-o.z)*c]}bezier(e,t){let n=1-t;return[n*n*e.a.x+2*n*t*e.c.x+t*t*e.b.x,n*n*e.a.y+2*n*t*e.c.y+t*t*e.b.y,n*n*e.a.z+2*n*t*e.c.z+t*t*e.b.z]}step(e){if(!this.active||!this.group.visible)return this.last=0,!1;let t=this.last?Math.min(.1,(e-this.last)/1e3):0;this.last=e,this.place();for(let n of this.arcs.values()){if(!n.points.visible)continue;let r=n.points.geometry.getAttribute("position");for(let s=0;s<n.count;s++)n.phase[s]=(n.phase[s]+n.speed*t)%1,r.setXYZ(s,...this.at(n,n.phase[s]));r.needsUpdate=!0}if(this.sparkCount){let n=this.sparks.geometry.getAttribute("position"),r=this.sparks.geometry.getAttribute("color"),s=e/1e3;for(let o=0;o<this.sparkCount;o++){let a=this.sparkFields[this.sparkField[o]],l=this.lift(a?.floorId??null);n.setXYZ(o,this.sparkBase[o*3],l.visible?this.sparkBase[o*3+1]+l.dy:-1e3,this.sparkBase[o*3+2]);let c=Math.max(0,Math.sin(s*2.4+this.sparkPhase[o]*3))**6,u=l.visible?(.15+.85*c)*(.4+.6*(a?.level??0)):0;r.setXYZ(o,u,u*.86,u*.35)}n.needsUpdate=!0,r.needsUpdate=!0}return!0}setVisible(e){this.group.visible=e}dispose(){this.setArcs([]),this.sparks.geometry.dispose(),this.sparks.material.dispose(),this.tex.dispose(),this.scene.remove(this.group)}};var oM=3,Rh=class{group=new ct;scene;lift;ringGeo=new Ra(.92,1,48);spots=new Map;links=[];constructor(e,t){this.scene=e,this.lift=t,this.group.name="live-sound",e.add(this.group)}get active(){return this.spots.size>0}set(e,t){let n=new Set(e.map(r=>r.id));for(let[r,s]of this.spots)if(!n.has(r)){for(let o of s.rings)this.group.remove(o),o.material.dispose();this.spots.delete(r)}for(let r of e){let s=this.spots.get(r.id);if(!s){let a=Array.from({length:oM},()=>{let l=new we(this.ringGeo,new Ke({transparent:!0,opacity:0,depthWrite:!1,blending:Ft,side:ut}));return l.rotation.x=-Math.PI/2,l.frustumCulled=!1,this.group.add(l),l});s={spot:r,rings:a},this.spots.set(r.id,s)}s.spot=r;let o=new W(r.color[0]/255,r.color[1]/255,r.color[2]/255);for(let a of s.rings)a.material.color.copy(o)}for(let r of this.links)this.group.remove(r.line),r.line.geometry.dispose(),r.line.material.dispose();this.links=t.map(([r,s])=>{let o=new Fe;o.setAttribute("position",new ke(new Float32Array(51),3));let a=new Pn(o,new Lt({color:12616956,transparent:!0,opacity:.55,depthWrite:!1,blending:Ft}));return a.frustumCulled=!1,this.group.add(a),{a:r,b:s,line:a}})}step(e){if(!this.spots.size&&!this.links.length)return!1;let t=e/1e3;for(let n of this.spots.values()){let r=this.lift(n.spot.at.floorId),s=.9+1.6*n.spot.level;n.rings.forEach((o,a)=>{let l=(t*.55+a/oM)%1;o.visible=r.visible,o.position.set(n.spot.at.x,r.y+n.spot.at.y,n.spot.at.z),o.scale.setScalar((.25+l*s)*(n.spot.size??1)),o.material.opacity=(1-l)*(.35+.5*n.spot.level)})}for(let n of this.links){let r=this.lift(n.a.floorId),s=this.lift(n.b.floorId);n.line.visible=r.visible&&s.visible;let o=n.line.geometry.getAttribute("position"),a=r.y+n.a.y,l=s.y+n.b.y,c=Math.hypot(n.a.x-n.b.x,n.a.z-n.b.z);for(let u=0;u<=16;u++){let h=u/16,f=Math.sin(Math.PI*h)*(.3+c*.12)+Math.sin(t*3+h*12)*.03;o.setXYZ(u,n.a.x+(n.b.x-n.a.x)*h,a+(l-a)*h+f,n.a.z+(n.b.z-n.a.z)*h)}o.needsUpdate=!0}return!0}dispose(){this.set([],[]),this.ringGeo.dispose(),this.scene.remove(this.group)}};var Ch=6,lM=24,aM=Ch*lM;function LC(i,e,t){let n=i%Ch,r=Math.floor(i/Ch),s=(r/lM+e*.7)%1,o=n/Ch*Math.PI*2+e*.35+(r*7%5-2)*.012,a=s*t,l=Math.min(1.2,t/3);return[Math.cos(o)*a,4*l*s*(1-s),Math.sin(o)*a]}var Ph=class{group=new ct;scene;lift;tex=Jp();material=new cn({color:11068159,size:.09,map:this.tex,transparent:!0,opacity:.9,depthWrite:!1});sprays=new Map;constructor(e,t){this.scene=e,this.lift=t,this.group.name="live-water",e.add(this.group)}get active(){return this.sprays.size>0}set(e){let t=new Set(e.map(n=>n.id));for(let[n,r]of this.sprays)t.has(n)||(this.group.remove(r.points),r.points.geometry.dispose(),this.sprays.delete(n));for(let n of e){let r=this.sprays.get(n.id);if(r){r.spot=n;continue}let s=new Fe;s.setAttribute("position",new ke(new Float32Array(aM*3),3));let o=new xn(s,this.material);o.frustumCulled=!1,this.group.add(o),this.sprays.set(n.id,{spot:n,points:o})}}step(e){if(!this.sprays.size)return!1;let t=e/1e3;for(let n of this.sprays.values()){let r=this.lift(n.spot.at.floorId);n.points.visible=r.visible,n.points.position.set(n.spot.at.x,r.y+n.spot.at.y,n.spot.at.z);let s=n.points.geometry.getAttribute("position");for(let o=0;o<aM;o++){let[a,l,c]=LC(o,t,n.spot.reach);s.setXYZ(o,a,l,c)}s.needsUpdate=!0}return!0}dispose(){this.set([]),this.material.dispose(),this.tex.dispose(),this.scene.remove(this.group)}};var FC=Math.PI/180;function OC(){let i=document.createElement("canvas");i.width=i.height=64;let e=i.getContext("2d"),t=e.createRadialGradient(32,32,4,32,32,32);return t.addColorStop(0,"rgba(255,255,255,0.9)"),t.addColorStop(.5,"rgba(255,255,255,0.35)"),t.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=t,e.fillRect(0,0,64,64),new zt(i)}var Ih=class{group=new ct;scene;lift;glowTex=OC();views=new Map;onChange=null;constructor(e,t){this.scene=e,this.lift=t,this.group.name="live-screens",e.add(this.group)}get active(){return[...this.views.values()].some(e=>e.s.playing)}set(e){let t=new Set(e.map(n=>n.id));for(let[n,r]of this.views)t.has(n)||this.drop(n,r);for(let n of e){let r=this.views.get(n.id);if(!r){let o=document.createElement("canvas");o.width=512,o.height=288;let a=new zt(o);a.colorSpace=ft;let l=new we(new sn(1,1),new Ke({map:a,transparent:!0,toneMapped:!1}));l.renderOrder=6;let c=new we(new sn(1,1),new Ke({map:this.glowTex,transparent:!0,depthWrite:!1,blending:Ft,side:ut}));c.renderOrder=2,this.group.add(l,c),r={s:n,sig:"",screen:l,glow:c,canvas:o,texture:a,image:null},this.views.set(n.id,r)}r.s=n;let s=[n.title,n.subtitle,n.app,n.picture,n.color.join(","),n.playing].join("|");if(s!==r.sig){let o=r.sig.split("|")[3]!==(n.picture??"");r.sig=s,o&&this.loadPicture(r),this.draw(r)}this.place(r)}}loadPicture(e){e.image=null;let t=e.s.picture;if(!t)return;let n=new Image;n.crossOrigin="anonymous",n.onload=()=>{e.s.picture!==t||!this.views.has(e.s.id)||(e.image=n,this.draw(e),this.onChange?.())},n.src=t}draw(e){let t=e.s,n=e.canvas.getContext("2d"),r=e.canvas.width,s=e.canvas.height,[o,a,l]=t.color,c=n.createLinearGradient(0,0,r,s);c.addColorStop(0,`rgb(${Math.round(o*.35)},${Math.round(a*.35)},${Math.round(l*.35)})`),c.addColorStop(1,"rgb(6,9,18)"),n.fillStyle=c,n.fillRect(0,0,r,s);let u=22,h=u;if(e.image){let f=s-u*2-30;n.save(),n.shadowColor=`rgba(${o},${a},${l},0.7)`,n.shadowBlur=24;let d=e.image.naturalWidth||1,p=e.image.naturalHeight||1,x=Math.max(f/d,f/p),g=f/x,m=f/x;n.drawImage(e.image,(d-g)/2,(p-m)/2,g,m,u,u,f,f),n.restore(),h=u*2+f}n.fillStyle="#ffffff",n.font="600 34px Figtree, Roboto, sans-serif",this.text(n,t.title||t.app||"",h,s/2-18,r-h-u),n.fillStyle="rgba(230,240,255,0.75)",n.font="26px Figtree, Roboto, sans-serif",this.text(n,t.subtitle,h,s/2+22,r-h-u),t.app&&(n.fillStyle=`rgb(${o},${a},${l})`,n.font="700 22px Figtree, Roboto, sans-serif",this.text(n,(t.playing?"\u25B6 ":"\u275A\u275A ")+t.app,h,s-u-14,r-h-u)),n.fillStyle=`rgba(${o},${a},${l},0.9)`,n.fillRect(0,s-6,r*(t.playing?1:.4),6),e.texture.needsUpdate=!0}text(e,t,n,r,s){let o=t;for(;o.length>1&&e.measureText(o).width>s;)o=o.slice(0,-2);e.fillText(o===t?o:`${o}\u2026`,n,r)}place(e){let t=e.s,n=t.rect,r=t.rotation*FC,s=this.lift(t.floorId),o=(n.x0+n.x1)/2,a=(p,x)=>[t.x+p*Math.cos(r)-x*Math.sin(r),t.z+p*Math.sin(r)+x*Math.cos(r)],l=n.x1-n.x0,c=n.y1-n.y0,[u,h]=a(o,n.z+.012);e.screen.position.set(u,s.y+(n.y0+n.y1)/2,h),e.screen.rotation.set(0,-r,0),e.screen.scale.set(l,c,1);let[f,d]=a(o,n.z-.18);e.glow.position.set(f,s.y+(n.y0+n.y1)/2,d),e.glow.rotation.set(0,-r,0),e.glow.scale.set(l*2.4,c*2.6,1),e.glow.material.color=new W(t.color[0]/255,t.color[1]/255,t.color[2]/255),e.screen.visible=s.visible,e.glow.visible=s.visible&&(t.ambilight??1)>0}step(e){let t=!1;for(let n of this.views.values()){this.place(n);let r=n.glow.material;r.opacity=(n.s.playing?.55+.25*Math.sin(e/900+n.s.x):.25)*Math.min(1.5,n.s.ambilight??1),t||=n.s.playing}return t}drop(e,t){this.group.remove(t.screen,t.glow),t.screen.geometry.dispose(),t.screen.material.dispose(),t.texture.dispose(),t.glow.geometry.dispose(),t.glow.material.dispose(),this.views.delete(e)}dispose(){for(let[e,t]of this.views)this.drop(e,t);this.glowTex.dispose(),this.scene.remove(this.group)}};var NC=Math.PI/180,DC="#f4f1ea",Lh=class{group=new ct;scene;lift;views=new Map;onChange=null;constructor(e,t){this.scene=e,this.lift=t,this.group.name="live-pictures",e.add(this.group)}set(e){let t=new Set(e.map(n=>n.id));for(let[n,r]of this.views)t.has(n)||this.drop(n,r);for(let n of e){let r=this.views.get(n.id);if(!r){let c=document.createElement("canvas"),u=new zt(c);u.colorSpace=ft;let h=new we(new sn(1,1),new Ke({map:u,toneMapped:!1}));h.renderOrder=5,this.group.add(h),r={p:n,sig:"",mesh:h,canvas:c,texture:u,image:null},this.views.set(n.id,r)}let s=r.p.url!==n.url||!r.sig;r.p=n;let o=n.rect.x1-n.rect.x0,a=n.rect.y1-n.rect.y0,l=[n.url,n.border,n.fit,o.toFixed(3),a.toFixed(3)].join("|");l!==r.sig&&(r.sig=l,s&&this.load(r),this.draw(r)),this.place(r)}}load(e){e.image=null;let t=e.p.url,n=new Image;n.crossOrigin="anonymous",n.onload=()=>{e.p.url!==t||!this.views.has(e.p.id)||(e.image=n,this.draw(e),this.onChange?.())},n.src=t}draw(e){let t=e.p,n=Math.max(.01,t.rect.x1-t.rect.x0),r=Math.max(.01,t.rect.y1-t.rect.y0),s=600/Math.max(n,r),o=e.canvas.width=Math.max(16,Math.round(n*s)),a=e.canvas.height=Math.max(16,Math.round(r*s)),l=e.canvas.getContext("2d");l.fillStyle=t.border>0?DC:"#20242c",l.fillRect(0,0,o,a);let c=Math.round(Math.min(o,a)*Math.min(40,Math.max(0,t.border))/100),[u,h,f,d]=[c,c,o-2*c,a-2*c];if(e.image&&f>4&&d>4){let p=e.image.naturalWidth||1,x=e.image.naturalHeight||1;if(t.fit==="contain"){let g=Math.min(f/p,d/x);l.drawImage(e.image,u+(f-p*g)/2,h+(d-x*g)/2,p*g,x*g)}else{let g=Math.max(f/p,d/x),m=f/g,b=d/g;l.drawImage(e.image,(p-m)/2,(x-b)/2,m,b,u,h,f,d)}c>0&&(l.strokeStyle="rgba(0,0,0,0.25)",l.lineWidth=Math.max(1,c*.04),l.strokeRect(u,h,f,d))}else f>4&&d>4&&(l.fillStyle="#3a4250",l.fillRect(u,h,f,d));e.texture.needsUpdate=!0}place(e){let t=e.p,n=t.rect,r=t.rotation*NC,s=this.lift(t.floorId),o=(n.x0+n.x1)/2,a=n.z+.004;e.mesh.position.set(t.x+o*Math.cos(r)-a*Math.sin(r),s.y+(n.y0+n.y1)/2,t.z+o*Math.sin(r)+a*Math.cos(r)),e.mesh.rotation.set(0,-r,0),e.mesh.scale.set(n.x1-n.x0,n.y1-n.y0,1),e.mesh.visible=s.visible}step(){for(let e of this.views.values())this.place(e);return!1}drop(e,t){this.group.remove(t.mesh),t.mesh.geometry.dispose(),t.mesh.material.dispose(),t.texture.dispose(),this.views.delete(e)}dispose(){for(let[e,t]of this.views)this.drop(e,t);this.scene.remove(this.group)}};var Fh=class extends Tn{constructor(){super(),this.name="RoomEnvironment",this.position.y=-3.5;let e=new Fr;e.deleteAttribute("uv");let t=new In({side:un}),n=new In,r=new ps(16777215,900,28,2);r.position.set(.418,16.199,.3),this.add(r);let s=new we(e,t);s.position.set(-.757,13.219,.717),s.scale.set(31.713,28.305,28.591),this.add(s);let o=new hs(e,n,6),a=new Et;a.position.set(-10.906,2.009,1.846),a.rotation.set(0,-.195,0),a.scale.set(2.328,7.905,4.651),a.updateMatrix(),o.setMatrixAt(0,a.matrix),a.position.set(-5.607,-.754,-.758),a.rotation.set(0,.994,0),a.scale.set(1.97,1.534,3.955),a.updateMatrix(),o.setMatrixAt(1,a.matrix),a.position.set(6.167,.857,7.803),a.rotation.set(0,.561,0),a.scale.set(3.927,6.285,3.687),a.updateMatrix(),o.setMatrixAt(2,a.matrix),a.position.set(-2.017,.018,6.124),a.rotation.set(0,.333,0),a.scale.set(2.002,4.566,2.064),a.updateMatrix(),o.setMatrixAt(3,a.matrix),a.position.set(2.291,-.756,-2.621),a.rotation.set(0,-.286,0),a.scale.set(1.546,1.552,1.496),a.updateMatrix(),o.setMatrixAt(4,a.matrix),a.position.set(-2.193,-.369,-5.547),a.rotation.set(0,.516,0),a.scale.set(3.875,3.487,2.986),a.updateMatrix(),o.setMatrixAt(5,a.matrix),this.add(o);let l=new we(e,Ho(50));l.position.set(-16.116,14.37,8.208),l.scale.set(.1,2.428,2.739),this.add(l);let c=new we(e,Ho(50));c.position.set(-16.109,18.021,-8.207),c.scale.set(.1,2.425,2.751),this.add(c);let u=new we(e,Ho(17));u.position.set(14.904,12.198,-1.832),u.scale.set(.15,4.265,6.331),this.add(u);let h=new we(e,Ho(43));h.position.set(-.462,8.89,14.52),h.scale.set(4.38,5.441,.088),this.add(h);let f=new we(e,Ho(20));f.position.set(3.235,11.486,-12.541),f.scale.set(2.5,2,.1),this.add(f);let d=new we(e,Ho(100));d.position.set(0,20,0),d.scale.set(1,.1,1),this.add(d)}dispose(){let e=new Set;this.traverse(t=>{t.isMesh&&(e.add(t.geometry),e.add(t.material))});for(let t of e)t.dispose()}};function Ho(i){return new Pa({color:0,emissive:16777215,emissiveIntensity:i})}function jp(i,e){if(e===Kf)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),i;if(e===Mo||e===qa){let t=i.getIndex();if(t===null){let s=[],o=i.getAttribute("position");if(o!==void 0){for(let a=0;a<o.count;a++)s.push(a);i.setIndex(s),t=i.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),i}let n=t.count-2,r=[];if(e===Mo)for(let s=1;s<=n;s++)r.push(t.getX(0)),r.push(t.getX(s)),r.push(t.getX(s+1));else for(let s=0;s<n;s++)s%2===0?(r.push(t.getX(s)),r.push(t.getX(s+1)),r.push(t.getX(s+2))):(r.push(t.getX(s+2)),r.push(t.getX(s+1)),r.push(t.getX(s)));return r.length/3!==n&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles."),i.setIndex(r),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),i}function cM(i,e=Math.PI/3){let t=i.index?i.toNonIndexed():i,n=t.attributes.position,r=n.count,s;if(n.isBufferAttribute===!0&&n.itemSize===3&&n.normalized===!1)s=n.array;else{s=new Float64Array(r*3);for(let y=0;y<r;y++)s[3*y+0]=n.getX(y),s[3*y+1]=n.getY(y),s[3*y+2]=n.getZ(y)}let o=Math.cos(e),a=(1+1e-10)*100,l=r/3,c=new Float64Array(l*3);for(let y=0;y<l;y++){let M=9*y,S=s[M+0],_=s[M+1],w=s[M+2],R=s[M+3],A=s[M+4],C=s[M+5],O=s[M+6],D=s[M+7],P=s[M+8],I=O-R,N=D-A,F=P-C,H=S-R,B=_-A,X=w-C,V=N*X-F*B,re=F*H-I*X,be=I*B-N*H,Y=1/(Math.sqrt(V*V+re*re+be*be)||1);c[3*y+0]=V*Y,c[3*y+1]=re*Y,c[3*y+2]=be*Y}let u=new Int32Array(r),h=new Float64Array(r*3),f=1;for(;f<r*2;)f<<=1;let d=f-1,p=new Int32Array(f),x=0;for(let y=0;y<r;y++){let M=3*y,S=Math.trunc(s[M+0]*a),_=Math.trunc(s[M+1]*a),w=Math.trunc(s[M+2]*a),R=(Math.imul(S,73856093)^Math.imul(_,19349663)^Math.imul(w,83492791))&d;for(;;){let A=p[R];if(A===0){let O=3*x;h[O+0]=S,h[O+1]=_,h[O+2]=w,p[R]=x+1,u[y]=x++;break}let C=3*(A-1);if(h[C+0]===S&&h[C+1]===_&&h[C+2]===w){u[y]=A-1;break}R=R+1&d}}let g=new Int32Array(x+1);for(let y=0;y<r;y++)g[u[y]+1]++;for(let y=0;y<x;y++)g[y+1]+=g[y];let m=new Int32Array(r),b=g.slice(0,x);for(let y=0;y<l;y++){let M=3*y;m[b[u[M+0]]++]=y,m[b[u[M+1]]++]=y,m[b[u[M+2]]++]=y}let v=new Float32Array(r*3);for(let y=0;y<l;y++){let M=3*y,S=c[M+0],_=c[M+1],w=c[M+2];for(let R=0;R<3;R++){let A=M+R,C=u[A],O=0,D=0,P=0;for(let N=g[C],F=g[C+1];N<F;N++){let H=3*m[N],B=c[H+0],X=c[H+1],V=c[H+2];S*B+_*X+w*V>o&&(O+=B,D+=X,P+=V)}let I=1/(Math.sqrt(O*O+D*D+P*P)||1);v[3*A+0]=O*I,v[3*A+1]=D*I,v[3*A+2]=P*I}}return t.setAttribute("normal",new wt(v,3,!1)),t}function uM(i){let e=new Map,t=new Map,n=i.clone();return hM(i,n,function(r,s){e.set(s,r),t.set(r,s)}),n.traverse(function(r){if(!r.isSkinnedMesh)return;let s=r,o=e.get(r),a=o.skeleton.bones;s.skeleton=o.skeleton.clone(),s.bindMatrix.copy(o.bindMatrix),s.skeleton.bones=a.map(function(l){return t.get(l)}),s.bind(s.skeleton,s.bindMatrix)}),n}function hM(i,e,t){t(i,e);for(let n=0;n<i.children.length;n++)hM(i.children[n],e.children[n],t)}var Xo=class extends wi{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new sm(t)}),this.register(function(t){return new om(t)}),this.register(function(t){return new am(t)}),this.register(function(t){return new gm(t)}),this.register(function(t){return new xm(t)}),this.register(function(t){return new bm(t)}),this.register(function(t){return new cm(t)}),this.register(function(t){return new um(t)}),this.register(function(t){return new hm(t)}),this.register(function(t){return new fm(t)}),this.register(function(t){return new rm(t)}),this.register(function(t){return new dm(t)}),this.register(function(t){return new lm(t)}),this.register(function(t){return new mm(t)}),this.register(function(t){return new pm(t)}),this.register(function(t){return new nm(t)}),this.register(function(t){return new Oh(t,nt.EXT_MESHOPT_COMPRESSION)}),this.register(function(t){return new Oh(t,nt.KHR_MESHOPT_COMPRESSION)}),this.register(function(t){return new ym(t)})}load(e,t,n,r){let s=this,o;if(this.resourcePath!=="")o=this.resourcePath;else if(this.path!==""){let c=or.extractUrlBase(e);o=or.resolveURL(c,this.path)}else o=or.extractUrlBase(e);this.manager.itemStart(e);let a=function(c){r?r(c):console.error(c),s.manager.itemError(e),s.manager.itemEnd(e)},l=new mo(this.manager);l.setPriority(this.priority),l.setCache(this.cache),l.setPath(this.path),l.setResponseType("arraybuffer"),l.setRequestHeader(this.requestHeader),l.setWithCredentials(this.withCredentials),l.load(e,function(c){try{s.parse(c,o,function(u){t(u),s.manager.itemEnd(e)},a)}catch(u){a(u)}},n,a)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,r){let s,o={},a={},l=new TextDecoder;if(typeof e=="string")s=JSON.parse(e);else if(e instanceof ArrayBuffer)if(l.decode(new Uint8Array(e,0,4))===gM){try{o[nt.KHR_BINARY_GLTF]=new _m(e)}catch(h){r&&r(h);return}s=JSON.parse(o[nt.KHR_BINARY_GLTF].content)}else s=JSON.parse(l.decode(e));else s=e;if(s.asset===void 0||s.asset.version[0]<2){r&&r(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}let c=new Em(s,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,priority:this.priority,cache:this.cache,withCredentials:this.withCredentials,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let u=0;u<this.pluginCallbacks.length;u++){let h=this.pluginCallbacks[u](c);h.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),a[h.name]=h,o[h.name]=!0}if(s.extensionsUsed)for(let u=0;u<s.extensionsUsed.length;++u){let h=s.extensionsUsed[u],f=s.extensionsRequired||[];switch(h){case nt.KHR_MATERIALS_UNLIT:o[h]=new im;break;case nt.KHR_DRACO_MESH_COMPRESSION:o[h]=new vm(s,this.dracoLoader);break;case nt.KHR_TEXTURE_TRANSFORM:o[h]=new Mm;break;case nt.KHR_MESH_QUANTIZATION:o[h]=new Sm;break;default:f.indexOf(h)>=0&&a[h]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+h+'".')}}c.setExtensions(o),c.setPlugins(a),c.parse(n,r)}parseAsync(e,t){let n=this;return new Promise(function(r,s){n.parse(e,t,r,s)})}};function UC(){let i={};return{get:function(e){return i[e]},add:function(e,t){i[e]=t},remove:function(e){delete i[e]},removeAll:function(){i={}}}}function Bt(i,e,t){let n=i.json.materials[e];return n.extensions&&n.extensions[t]?n.extensions[t]:null}var nt={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DIFFUSE_ROUGHNESS:"KHR_materials_diffuse_roughness",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",KHR_MESHOPT_COMPRESSION:"KHR_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"},nm=class{constructor(e){this.parser=e,this.name=nt.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){let e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n<r;n++){let s=t[n];s.extensions&&s.extensions[this.name]&&s.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,s.extensions[this.name].light)}}_loadLight(e){let t=this.parser,n="light:"+e,r=t.cache.get(n);if(r)return r;let s=t.json,l=((s.extensions&&s.extensions[this.name]||{}).lights||[])[e],c,u=new W(16777215);l.color!==void 0&&u.setRGB(l.color[0],l.color[1],l.color[2],Mn);let h=l.range!==void 0?l.range:0;switch(l.type){case"directional":c=new sr(u),c.target.position.set(0,0,-1),c.add(c.target);break;case"point":c=new ps(u),c.distance=h;break;case"spot":c=new Na(u),c.distance=h,l.spot=l.spot||{},l.spot.innerConeAngle=l.spot.innerConeAngle!==void 0?l.spot.innerConeAngle:0,l.spot.outerConeAngle=l.spot.outerConeAngle!==void 0?l.spot.outerConeAngle:Math.PI/4,c.angle=l.spot.outerConeAngle,c.penumbra=1-l.spot.innerConeAngle/l.spot.outerConeAngle,c.target.position.set(0,0,-1),c.add(c.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+l.type)}return c.position.set(0,0,0),Ui(c,l),l.intensity!==void 0&&(c.intensity=l.intensity),c.name=t.createUniqueName(l.name||"light_"+e),r=Promise.resolve(c),t.cache.add(n,r),r}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){let t=this,n=this.parser,s=n.json.nodes[e],a=(s.extensions&&s.extensions[this.name]||{}).light;return a===void 0?null:this._loadLight(a).then(function(l){return n._getNodeRef(t.cache,a,l)})}},im=class{constructor(){this.name=nt.KHR_MATERIALS_UNLIT}getMaterialType(){return Ke}extendParams(e,t,n){let r=[];e.color=new W(1,1,1),e.opacity=1;let s=t.pbrMetallicRoughness;if(s){if(Array.isArray(s.baseColorFactor)){let o=s.baseColorFactor;e.color.setRGB(o[0],o[1],o[2],Mn),e.opacity=o[3]}s.baseColorTexture!==void 0&&r.push(n.assignTexture(e,"map",s.baseColorTexture,ft))}return Promise.all(r)}},rm=class{constructor(e){this.parser=e,this.name=nt.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){let n=Bt(this.parser,e,this.name);return n===null||n.emissiveStrength!==void 0&&(t.emissiveIntensity=n.emissiveStrength),Promise.resolve()}},sm=class{constructor(e){this.parser=e,this.name=nt.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){return Bt(this.parser,e,this.name)!==null?An:null}extendMaterialParams(e,t){let n=Bt(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];if(n.clearcoatFactor!==void 0&&(t.clearcoat=n.clearcoatFactor),n.clearcoatTexture!==void 0&&r.push(this.parser.assignTexture(t,"clearcoatMap",n.clearcoatTexture)),n.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=n.clearcoatRoughnessFactor),n.clearcoatRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,"clearcoatRoughnessMap",n.clearcoatRoughnessTexture)),n.clearcoatNormalTexture!==void 0&&(r.push(this.parser.assignTexture(t,"clearcoatNormalMap",n.clearcoatNormalTexture)),n.clearcoatNormalTexture.scale!==void 0)){let s=n.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new De(s,s)}return Promise.all(r)}},om=class{constructor(e){this.parser=e,this.name=nt.KHR_MATERIALS_DIFFUSE_ROUGHNESS}getMaterialType(e){return Bt(this.parser,e,this.name)!==null?An:null}extendMaterialParams(e,t){let n=Bt(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return t.diffuseRoughness=n.diffuseRoughnessFactor!==void 0?n.diffuseRoughnessFactor:0,n.diffuseRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,"diffuseRoughnessMap",n.diffuseRoughnessTexture)),Promise.all(r)}},am=class{constructor(e){this.parser=e,this.name=nt.KHR_MATERIALS_DISPERSION}getMaterialType(e){return Bt(this.parser,e,this.name)!==null?An:null}extendMaterialParams(e,t){let n=Bt(this.parser,e,this.name);return n===null||(t.dispersion=n.dispersion!==void 0?n.dispersion:0),Promise.resolve()}},lm=class{constructor(e){this.parser=e,this.name=nt.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){return Bt(this.parser,e,this.name)!==null?An:null}extendMaterialParams(e,t){let n=Bt(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.iridescenceFactor!==void 0&&(t.iridescence=n.iridescenceFactor),n.iridescenceTexture!==void 0&&r.push(this.parser.assignTexture(t,"iridescenceMap",n.iridescenceTexture)),n.iridescenceIor!==void 0&&(t.iridescenceIOR=n.iridescenceIor),n.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessMinimum=n.iridescenceThicknessMinimum),n.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessMaximum=n.iridescenceThicknessMaximum),n.iridescenceThicknessTexture!==void 0&&r.push(this.parser.assignTexture(t,"iridescenceThicknessMap",n.iridescenceThicknessTexture)),Promise.all(r)}},cm=class{constructor(e){this.parser=e,this.name=nt.KHR_MATERIALS_SHEEN}getMaterialType(e){return Bt(this.parser,e,this.name)!==null?An:null}extendMaterialParams(e,t){let n=Bt(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];if(t.sheenColor=new W(0,0,0),t.sheenRoughness=0,t.sheen=1,n.sheenColorFactor!==void 0){let s=n.sheenColorFactor;t.sheenColor.setRGB(s[0],s[1],s[2],Mn)}return n.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=n.sheenRoughnessFactor),n.sheenColorTexture!==void 0&&r.push(this.parser.assignTexture(t,"sheenColorMap",n.sheenColorTexture,ft)),n.sheenRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,"sheenRoughnessMap",n.sheenRoughnessTexture)),Promise.all(r)}},um=class{constructor(e){this.parser=e,this.name=nt.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){return Bt(this.parser,e,this.name)!==null?An:null}extendMaterialParams(e,t){let n=Bt(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.transmissionFactor!==void 0&&(t.transmission=n.transmissionFactor),n.transmissionTexture!==void 0&&r.push(this.parser.assignTexture(t,"transmissionMap",n.transmissionTexture)),Promise.all(r)}},hm=class{constructor(e){this.parser=e,this.name=nt.KHR_MATERIALS_VOLUME}getMaterialType(e){return Bt(this.parser,e,this.name)!==null?An:null}extendMaterialParams(e,t){let n=Bt(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];t.thickness=n.thicknessFactor!==void 0?n.thicknessFactor:0,n.thicknessTexture!==void 0&&r.push(this.parser.assignTexture(t,"thicknessMap",n.thicknessTexture)),t.attenuationDistance=n.attenuationDistance||1/0;let s=n.attenuationColor||[1,1,1];return t.attenuationColor=new W().setRGB(s[0],s[1],s[2],Mn),Promise.all(r)}},fm=class{constructor(e){this.parser=e,this.name=nt.KHR_MATERIALS_IOR}getMaterialType(e){return Bt(this.parser,e,this.name)!==null?An:null}extendMaterialParams(e,t){let n=Bt(this.parser,e,this.name);return n===null||(t.ior=n.ior!==void 0?n.ior:1.5,t.ior===0&&(t.ior=1e3)),Promise.resolve()}},dm=class{constructor(e){this.parser=e,this.name=nt.KHR_MATERIALS_SPECULAR}getMaterialType(e){return Bt(this.parser,e,this.name)!==null?An:null}extendMaterialParams(e,t){let n=Bt(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];t.specularIntensity=n.specularFactor!==void 0?n.specularFactor:1,n.specularTexture!==void 0&&r.push(this.parser.assignTexture(t,"specularIntensityMap",n.specularTexture));let s=n.specularColorFactor||[1,1,1];return t.specularColor=new W().setRGB(s[0],s[1],s[2],Mn),n.specularColorTexture!==void 0&&r.push(this.parser.assignTexture(t,"specularColorMap",n.specularColorTexture,ft)),Promise.all(r)}},pm=class{constructor(e){this.parser=e,this.name=nt.EXT_MATERIALS_BUMP}getMaterialType(e){return Bt(this.parser,e,this.name)!==null?An:null}extendMaterialParams(e,t){let n=Bt(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return t.bumpScale=n.bumpFactor!==void 0?n.bumpFactor:1,n.bumpTexture!==void 0&&r.push(this.parser.assignTexture(t,"bumpMap",n.bumpTexture)),Promise.all(r)}},mm=class{constructor(e){this.parser=e,this.name=nt.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){return Bt(this.parser,e,this.name)!==null?An:null}extendMaterialParams(e,t){let n=Bt(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.anisotropyStrength!==void 0&&(t.anisotropy=n.anisotropyStrength),n.anisotropyRotation!==void 0&&(t.anisotropyRotation=n.anisotropyRotation),n.anisotropyTexture!==void 0&&r.push(this.parser.assignTexture(t,"anisotropyMap",n.anisotropyTexture)),Promise.all(r)}},gm=class{constructor(e){this.parser=e,this.name=nt.KHR_TEXTURE_BASISU}loadTexture(e){let t=this.parser,n=t.json,r=n.textures[e];if(!r.extensions||!r.extensions[this.name])return null;let s=r.extensions[this.name],o=t.options.ktx2Loader;if(!o){if(n.extensionsRequired&&n.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,s.source,o)}},xm=class{constructor(e){this.parser=e,this.name=nt.EXT_TEXTURE_WEBP}loadTexture(e){let t=this.name,n=this.parser,r=n.json,s=r.textures[e];if(!s.extensions||!s.extensions[t])return null;let o=s.extensions[t],a=r.images[o.source],l=n.textureLoader;if(a.uri){let c=n.options.manager.getHandler(a.uri);c!==null&&(l=c)}return n.loadTextureImage(e,o.source,l)}},bm=class{constructor(e){this.parser=e,this.name=nt.EXT_TEXTURE_AVIF}loadTexture(e){let t=this.name,n=this.parser,r=n.json,s=r.textures[e];if(!s.extensions||!s.extensions[t])return null;let o=s.extensions[t],a=r.images[o.source],l=n.textureLoader;if(a.uri){let c=n.options.manager.getHandler(a.uri);c!==null&&(l=c)}return n.loadTextureImage(e,o.source,l)}},Oh=class{constructor(e,t){this.name=t,this.parser=e}loadBufferView(e){let t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){let r=n.extensions[this.name],s=this.parser.getDependency("buffer",r.buffer),o=this.parser.options.meshoptDecoder;if(!o||!o.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return s.then(function(a){let l=r.byteOffset||0,c=r.byteLength||0,u=r.count,h=r.byteStride,f=new Uint8Array(a,l,c);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(u,h,f,r.mode,r.filter).then(function(d){return d.buffer}):o.ready.then(function(){let d=new ArrayBuffer(u*h);return o.decodeGltfBuffer(new Uint8Array(d),u,h,f,r.mode,r.filter),d})})}else return null}},ym=class{constructor(e){this.name=nt.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){let t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||n.mesh===void 0)return null;let r=t.meshes[n.mesh];for(let c of r.primitives)if(c.mode!==ei.TRIANGLES&&c.mode!==ei.TRIANGLE_STRIP&&c.mode!==ei.TRIANGLE_FAN&&c.mode!==void 0)return null;let o=n.extensions[this.name].attributes,a=[],l={};for(let c in o)a.push(this.parser.getDependency("accessor",o[c]).then(u=>(l[c]=u,l[c])));return a.length<1?null:(a.push(this.parser.createNodeMesh(e)),Promise.all(a).then(c=>{let u=c.pop(),h=u.isGroup?u.children:[u],f=c[0].count,d=[];for(let p of h){let x=new Be,g=new U,m=new Sn,b=new U(1,1,1),v=new hs(p.geometry,p.material,f);for(let M=0;M<f;M++)l.TRANSLATION&&g.fromBufferAttribute(l.TRANSLATION,M),l.ROTATION&&m.fromBufferAttribute(l.ROTATION,M),l.SCALE&&b.fromBufferAttribute(l.SCALE,M),v.setMatrixAt(M,x.compose(g,m,b));let y=null;for(let M in l)if(M==="_COLOR_0"){let S=l[M];v.instanceColor=new Qi(S.array,S.itemSize,S.normalized)}else if(M!=="TRANSLATION"&&M!=="ROTATION"&&M!=="SCALE"){if(y===null){let _=v.geometry;y=new Fe,y.name=_.name;for(let w in _.attributes)y.setAttribute(w,_.attributes[w]);for(let w in _.morphAttributes)y.morphAttributes[w]=_.morphAttributes[w];_.index!==null&&y.setIndex(_.index),y.morphTargetsRelative=_.morphTargetsRelative;for(let w of _.groups)y.addGroup(w.start,w.count,w.materialIndex);_.boundingBox!==null&&(y.boundingBox=_.boundingBox.clone()),_.boundingSphere!==null&&(y.boundingSphere=_.boundingSphere.clone()),y.drawRange.start=_.drawRange.start,y.drawRange.count=_.drawRange.count,y.userData=Object.assign({},_.userData),v.geometry=y}let S=l[M];y.setAttribute(M,new Qi(S.array,S.itemSize,S.normalized))}Et.prototype.copy.call(v,p),this.parser.assignFinalMaterial(v),d.push(v)}return u.isGroup?(u.clear(),u.add(...d),u):d[0]}))}},gM="glTF",Cl=12,fM={JSON:1313821514,BIN:5130562},_m=class{constructor(e){this.name=nt.KHR_BINARY_GLTF,this.content=null,this.body=null;let t=new DataView(e,0,Cl),n=new TextDecoder;if(this.header={magic:n.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==gM)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");let r=this.header.length-Cl,s=new DataView(e,Cl),o=0;for(;o<r;){let a=s.getUint32(o,!0);o+=4;let l=s.getUint32(o,!0);if(o+=4,l===fM.JSON){let c=new Uint8Array(e,Cl+o,a);this.content=n.decode(c)}else if(l===fM.BIN){let c=Cl+o;this.body=e.slice(c,c+a)}o+=a}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}},vm=class{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=nt.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){let n=this.json,r=this.dracoLoader,s=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,a={},l={},c={};for(let u in o){let h=Tm[u]||u.toLowerCase();a[h]=o[u]}for(let u in e.attributes){let h=Tm[u]||u.toLowerCase();if(o[u]!==void 0){let f=n.accessors[e.attributes[u]],d=Wo[f.componentType];c[h]=d.name,l[h]=f.normalized===!0}}return t.getDependency("bufferView",s).then(function(u){return new Promise(function(h,f){r.decodeDracoFile(u,function(d){for(let p in d.attributes){let x=d.attributes[p],g=l[p];g!==void 0&&(x.normalized=g)}h(d)},a,c,Mn,f)})})}},Mm=class{constructor(){this.name=nt.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){if((t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0)return e;if(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),t.rotation!==void 0){let n=Math.cos(e.rotation),r=Math.sin(e.rotation);e.matrix.set(e.repeat.x*n,e.repeat.y*r,e.offset.x,-e.repeat.x*r,e.repeat.y*n,e.offset.y,0,0,1),e.matrixAutoUpdate=!1}return e.needsUpdate=!0,e}},Sm=class{constructor(){this.name=nt.KHR_MESH_QUANTIZATION}},Nh=class extends Si{constructor(e,t,n,r){super(e,t,n,r)}copySampleValue_(e){let t=this.resultBuffer,n=this.sampleValues,r=this.valueSize,s=e*r*3+r;for(let o=0;o!==r;o++)t[o]=n[s+o];return t}interpolate_(e,t,n,r){let s=this.resultBuffer,o=this.sampleValues,a=this.valueSize,l=a*2,c=a*3,u=r-t,h=(n-t)/u,f=h*h,d=f*h,p=e*c,x=p-c,g=-2*d+3*f,m=d-f,b=1-g,v=m-f+h;for(let y=0;y!==a;y++){let M=o[x+y+a],S=o[x+y+l]*u,_=o[p+y+a],w=o[p+y]*u;s[y]=b*M+v*S+g*_+m*w}return s}},BC=new Sn,wm=class extends Nh{interpolate_(e,t,n,r){let s=super.interpolate_(e,t,n,r);return BC.fromArray(s).normalize().toArray(s),s}},ei={FLOAT:5126,FLOAT_MAT3:35675,FLOAT_MAT4:35676,FLOAT_VEC2:35664,FLOAT_VEC3:35665,FLOAT_VEC4:35666,LINEAR:9729,REPEAT:10497,SAMPLER_2D:35678,POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,UNSIGNED_BYTE:5121,UNSIGNED_SHORT:5123},Wo={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},dM={9728:Ut,9729:Ht,9984:_o,9985:Dr,9986:ar,9987:Fn},pM={33071:ln,33648:Rr,10497:kn},Qp={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Tm={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},Yr={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},kC={CUBICSPLINE:void 0,LINEAR:Zi,STEP:Ki},em={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function zC(i){return i.DefaultMaterial===void 0&&(i.DefaultMaterial=new In({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:Ti})),i.DefaultMaterial}function Us(i,e,t){for(let n in t.extensions)i[n]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[n]=t.extensions[n])}function Ui(i,e){e.extras!==void 0&&(typeof e.extras=="object"?Object.assign(i.userData,e.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+e.extras))}function VC(i,e,t){let n=!1,r=!1,s=!1;for(let c=0,u=e.length;c<u;c++){let h=e[c];if(h.POSITION!==void 0&&(n=!0),h.NORMAL!==void 0&&(r=!0),h.COLOR_0!==void 0&&(s=!0),n&&r&&s)break}if(!n&&!r&&!s)return Promise.resolve(i);let o=[],a=[],l=[];for(let c=0,u=e.length;c<u;c++){let h=e[c];if(n){let f=h.POSITION!==void 0?t.getDependency("accessor",h.POSITION):i.attributes.position;o.push(f)}if(r){let f=h.NORMAL!==void 0?t.getDependency("accessor",h.NORMAL):i.attributes.normal;a.push(f)}if(s){let f=h.COLOR_0!==void 0?t.getDependency("accessor",h.COLOR_0):i.attributes.color;l.push(f)}}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(l)]).then(function(c){let u=c[0],h=c[1],f=c[2];return n&&(i.morphAttributes.position=u),r&&(i.morphAttributes.normal=h),s&&(i.morphAttributes.color=f),i.morphTargetsRelative=!0,i})}function GC(i,e){if(i.updateMorphTargets(),e.weights!==void 0)for(let t=0,n=e.weights.length;t<n;t++)i.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){let t=e.extras.targetNames;if(i.morphTargetInfluences.length===t.length){i.morphTargetDictionary={};for(let n=0,r=t.length;n<r;n++)i.morphTargetDictionary[t[n]]=n}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function HC(i){let e,t=i.extensions&&i.extensions[nt.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+tm(t.attributes):e=i.indices+":"+tm(i.attributes)+":"+i.mode,i.targets!==void 0)for(let n=0,r=i.targets.length;n<r;n++)e+=":"+tm(i.targets[n]);return e}function tm(i){let e="",t=Object.keys(i).sort();for(let n=0,r=t.length;n<r;n++)e+=t[n]+":"+i[t[n]]+";";return e}function Am(i){switch(i){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}function WC(i){return i.search(/\.jpe?g($|\?)/i)>0||i.search(/^data\:image\/jpeg/)===0?"image/jpeg":i.search(/\.webp($|\?)/i)>0||i.search(/^data\:image\/webp/)===0?"image/webp":i.search(/\.ktx2($|\?)/i)>0||i.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}var XC=new Be,Em=class{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new UC,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let n=!1,r=-1,s=!1,o=-1;if(typeof navigator<"u"&&typeof navigator.userAgent<"u"){let a=navigator.userAgent;n=/^((?!chrome|android).)*safari/i.test(a)===!0;let l=a.match(/Version\/(\d+)/);r=n&&l?parseInt(l[1],10):-1,s=a.indexOf("Firefox")>-1,o=s?a.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||n&&r<17||s&&o<98?(this.textureLoader=new Fa(this.options.manager),this.textureLoader.setPriority(this.options.priority),this.textureLoader.setCache(this.options.cache)):(this.textureLoader=new Ua(this.options.manager),this.textureLoader.setPriority(this.options.priority),this.textureLoader.setCache(this.options.cache)),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setWithCredentials(this.options.withCredentials),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new mo(this.options.manager),this.fileLoader.setPriority(this.options.priority),this.fileLoader.setCache(this.options.cache),this.fileLoader.setResponseType("arraybuffer"),(this.options.withCredentials||this.options.crossOrigin==="use-credentials")&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){let n=this,r=this.json,s=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(o){return o._markDefs&&o._markDefs()}),Promise.all(this._invokeAll(function(o){return o.beforeRoot&&o.beforeRoot()})).then(function(){return Promise.all([n.getDependencies("scene"),n.getDependencies("animation"),n.getDependencies("camera")])}).then(function(o){let a={scene:o[0][r.scene||0],scenes:o[0],animations:o[1],cameras:o[2],asset:r.asset,parser:n,userData:{}};return Us(s,a,r),Ui(a,r),Promise.all(n._invokeAll(function(l){return l.afterRoot&&l.afterRoot(a)})).then(function(){for(let l of a.scenes)l.updateMatrixWorld();e(a)})}).catch(t)}_markDefs(){let e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let r=0,s=t.length;r<s;r++){let o=t[r].joints;for(let a=0,l=o.length;a<l;a++)e[o[a]].isBone=!0}for(let r=0,s=e.length;r<s;r++){let o=e[r];o.mesh!==void 0&&(this._addNodeRef(this.meshCache,o.mesh),o.skin!==void 0&&(n[o.mesh].isSkinnedMesh=!0)),o.camera!==void 0&&this._addNodeRef(this.cameraCache,o.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,n){if(e.refs[t]<=1)return n;let r=n.clone(),s=(o,a)=>{let l=this.associations.get(o);l!=null&&this.associations.set(a,l);for(let[c,u]of o.children.entries())s(u,a.children[c])};return s(n,r),r.name+="_instance_"+e.uses[t]++,r}_invokeOne(e){let t=Object.values(this.plugins);t.push(this);for(let n=0;n<t.length;n++){let r=e(t[n]);if(r)return r}return null}_invokeAll(e){let t=Object.values(this.plugins);t.unshift(this);let n=[];for(let r=0;r<t.length;r++){let s=e(t[r]);s&&n.push(s)}return n}getDependency(e,t){let n=e+":"+t,r=this.cache.get(n);if(!r){switch(e){case"scene":r=this.loadScene(t);break;case"node":r=this._invokeOne(function(s){return s.loadNode&&s.loadNode(t)});break;case"mesh":r=this._invokeOne(function(s){return s.loadMesh&&s.loadMesh(t)});break;case"accessor":r=this.loadAccessor(t);break;case"bufferView":r=this._invokeOne(function(s){return s.loadBufferView&&s.loadBufferView(t)});break;case"buffer":r=this.loadBuffer(t);break;case"material":r=this._invokeOne(function(s){return s.loadMaterial&&s.loadMaterial(t)});break;case"texture":r=this._invokeOne(function(s){return s.loadTexture&&s.loadTexture(t)});break;case"skin":r=this.loadSkin(t);break;case"animation":r=this._invokeOne(function(s){return s.loadAnimation&&s.loadAnimation(t)});break;case"camera":r=this.loadCamera(t);break;default:if(r=this._invokeOne(function(s){return s!=this&&s.getDependency&&s.getDependency(e,t)}),!r)throw new Error("Unknown type: "+e);break}this.cache.add(n,r)}return r}getDependencies(e){let t=this.cache.get(e);if(!t){let n=this,r=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(r.map(function(s,o){return n.getDependency(e,o)})),this.cache.add(e,t)}return t}loadBuffer(e){let t=this.json.buffers[e],n=this.fileLoader;if(t.type&&t.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[nt.KHR_BINARY_GLTF].body);let r=this.options;return new Promise(function(s,o){n.load(or.resolveURL(t.uri,r.path),s,void 0,function(){o(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))})})}loadBufferView(e){let t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(n){let r=t.byteLength||0,s=t.byteOffset||0;return n.slice(s,s+r)})}loadAccessor(e){let t=this,n=this.json,r=this.json.accessors[e];if(r.bufferView===void 0&&r.sparse===void 0){let o=Qp[r.type],a=Wo[r.componentType],l=r.normalized===!0,c=new a(r.count*o);return Promise.resolve(new wt(c,o,l))}let s=[];return r.bufferView!==void 0?s.push(this.getDependency("bufferView",r.bufferView)):s.push(null),r.sparse!==void 0&&(s.push(this.getDependency("bufferView",r.sparse.indices.bufferView)),s.push(this.getDependency("bufferView",r.sparse.values.bufferView))),Promise.all(s).then(function(o){let a=o[0],l=Qp[r.type],c=Wo[r.componentType],u=c.BYTES_PER_ELEMENT,h=u*l,f=r.byteOffset||0,d=r.bufferView!==void 0?n.bufferViews[r.bufferView].byteStride:void 0,p=r.normalized===!0,x,g;if(d&&d!==h){let m=Math.floor(f/d),b="InterleavedBuffer:"+r.bufferView+":"+r.componentType+":"+m+":"+r.count,v=t.cache.get(b);v||(x=new c(a,m*d,r.count*d/u),v=new us(x,d/u),t.cache.add(b,v)),g=new Cr(v,l,f%d/u,p)}else a===null?x=new c(r.count*l):x=new c(a,f,r.count*l),g=new wt(x,l,p);if(r.sparse!==void 0){let m=Qp.SCALAR,b=Wo[r.sparse.indices.componentType],v=r.sparse.indices.byteOffset||0,y=r.sparse.values.byteOffset||0,M=new b(o[1],v,r.sparse.count*m),S=new c(o[2],y,r.sparse.count*l);a!==null&&(g=new wt(g.array.slice(),g.itemSize,g.normalized)),g.normalized=!1;for(let _=0,w=M.length;_<w;_++){let R=M[_];if(g.setX(R,S[_*l]),l>=2&&g.setY(R,S[_*l+1]),l>=3&&g.setZ(R,S[_*l+2]),l>=4&&g.setW(R,S[_*l+3]),l>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}g.normalized=p}return g})}loadTexture(e){let t=this.json,n=this.options,s=t.textures[e].source,o=t.images[s],a=this.textureLoader;if(o.uri){let l=n.manager.getHandler(o.uri);l!==null&&(a=l)}return this.loadTextureImage(e,s,a)}loadTextureImage(e,t,n){let r=this,s=this.json,o=s.textures[e],a=s.images[t],l=(a.uri||a.bufferView)+":"+o.sampler;if(this.textureCache[l])return this.textureCache[l];let c=this.loadImageSource(t,n).then(function(u){u.flipY=!1,u.name=o.name||a.name||"",u.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(u.name=a.uri);let f=(s.samplers||{})[o.sampler]||{};return u.magFilter=dM[f.magFilter]||Ht,u.minFilter=dM[f.minFilter]||Fn,u.wrapS=pM[f.wrapS]||kn,u.wrapT=pM[f.wrapT]||kn,u.generateMipmaps=!u.isCompressedTexture&&u.minFilter!==Ut&&u.minFilter!==Ht,r.associations.set(u,{textures:e}),u}).catch(function(){return null});return this.textureCache[l]=c,c}loadImageSource(e,t){let n=this,r=this.json,s=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(f=>f.clone());let o=r.images[e],a=self.URL||self.webkitURL,l=o.uri||"",c=!1,u;if(t.isKTX2Loader===!0&&o.bufferView!==void 0)u=n.getDependency("bufferView",o.bufferView).then(function(f){return new Promise(function(d,p){t.parse(f,d,p)})});else{if(o.bufferView!==void 0)l=n.getDependency("bufferView",o.bufferView).then(function(f){c=!0;let d=new Blob([f],{type:o.mimeType});return l=a.createObjectURL(d),l});else if(o.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");u=Promise.resolve(l).then(function(f){return new Promise(function(d,p){let x=d;t.isImageBitmapLoader===!0&&(x=function(g){let m=new Kt(g);m.needsUpdate=!0,d(m)}),t.load(or.resolveURL(f,s.path),x,void 0,p)})})}let h=u.then(function(f){return c===!0&&a.revokeObjectURL(l),Ui(f,o),f.userData.mimeType=o.mimeType||WC(o.uri),f}).catch(function(f){throw console.error("THREE.GLTFLoader: Couldn't load texture",l),f});return this.sourceCache[e]=h,h}assignTexture(e,t,n,r){let s=this;return this.getDependency("texture",n.index).then(function(o){if(!o)return null;if(n.texCoord!==void 0&&n.texCoord>0&&(o=o.clone(),o.channel=n.texCoord),s.extensions[nt.KHR_TEXTURE_TRANSFORM]){let a=n.extensions!==void 0?n.extensions[nt.KHR_TEXTURE_TRANSFORM]:void 0;if(a){let l=s.associations.get(o);o=s.extensions[nt.KHR_TEXTURE_TRANSFORM].extendTexture(o,a),s.associations.set(o,l)}}return r!==void 0&&(o.colorSpace=r),e[t]=o,o})}assignFinalMaterial(e){let t=e.geometry,n=e.material,r=t.attributes.tangent===void 0,s=t.attributes.color!==void 0,o=t.attributes.normal===void 0;if(e.isPoints){let a="PointsMaterial:"+n.uuid,l=this.cache.get(a);l||(l=new cn,mn.prototype.copy.call(l,n),l.color.copy(n.color),l.map=n.map,l.sizeAttenuation=!1,this.cache.add(a,l)),n=l}else if(e.isLine){let a="LineBasicMaterial:"+n.uuid,l=this.cache.get(a);l||(l=new Lt,mn.prototype.copy.call(l,n),l.color.copy(n.color),l.map=n.map,this.cache.add(a,l)),n=l}if(r||s||o){let a="ClonedMaterial:"+n.uuid+":";r&&(a+="derivative-tangents:"),s&&(a+="vertex-colors:"),o&&(a+="flat-shading:");let l=this.cache.get(a);l||(l=n.clone(),s&&(l.vertexColors=!0),o&&(l.flatShading=!0),r&&(l.normalScale&&(l.normalScale.y*=-1),l.clearcoatNormalScale&&(l.clearcoatNormalScale.y*=-1)),this.cache.add(a,l),this.associations.set(l,this.associations.get(n))),n=l}e.material=n}getMaterialType(){return In}loadMaterial(e){let t=this,n=this.json,r=this.extensions,s=n.materials[e],o,a={},l=s.extensions||{},c=[];if(l[nt.KHR_MATERIALS_UNLIT]){let h=r[nt.KHR_MATERIALS_UNLIT];o=h.getMaterialType(),c.push(h.extendParams(a,s,t))}else{let h=s.pbrMetallicRoughness||{};if(a.color=new W(1,1,1),a.opacity=1,Array.isArray(h.baseColorFactor)){let f=h.baseColorFactor;a.color.setRGB(f[0],f[1],f[2],Mn),a.opacity=f[3]}h.baseColorTexture!==void 0&&c.push(t.assignTexture(a,"map",h.baseColorTexture,ft)),a.metalness=h.metallicFactor!==void 0?h.metallicFactor:1,a.roughness=h.roughnessFactor!==void 0?h.roughnessFactor:1,h.metallicRoughnessTexture!==void 0&&(c.push(t.assignTexture(a,"metalnessMap",h.metallicRoughnessTexture)),c.push(t.assignTexture(a,"roughnessMap",h.metallicRoughnessTexture))),o=this._invokeOne(function(f){return f.getMaterialType&&f.getMaterialType(e)}),c.push(Promise.all(this._invokeAll(function(f){return f.extendMaterialParams&&f.extendMaterialParams(e,a)})))}s.doubleSided===!0&&(a.side=ut);let u=s.alphaMode||em.OPAQUE;if(u===em.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,u===em.MASK&&(a.alphaTest=s.alphaCutoff!==void 0?s.alphaCutoff:.5)),s.normalTexture!==void 0&&o!==Ke&&(c.push(t.assignTexture(a,"normalMap",s.normalTexture)),a.normalScale=new De(1,1),s.normalTexture.scale!==void 0)){let h=s.normalTexture.scale;a.normalScale.set(h,h)}if(s.occlusionTexture!==void 0&&o!==Ke&&(c.push(t.assignTexture(a,"aoMap",s.occlusionTexture)),s.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=s.occlusionTexture.strength)),s.emissiveFactor!==void 0&&o!==Ke){let h=s.emissiveFactor;a.emissive=new W().setRGB(h[0],h[1],h[2],Mn)}return s.emissiveTexture!==void 0&&o!==Ke&&c.push(t.assignTexture(a,"emissiveMap",s.emissiveTexture,ft)),Promise.all(c).then(function(){let h=new o(a);return s.name&&(h.name=s.name),Ui(h,s),t.associations.set(h,{materials:e}),s.extensions&&Us(r,h,s),h})}createUniqueName(e){let t=gt.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){let t=this,n=this.extensions,r=this.primitiveCache;function s(a){return n[nt.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,t).then(function(l){return mM(l,a,t)})}let o=[];for(let a=0,l=e.length;a<l;a++){let c=e[a],u=HC(c),h=r[u];if(h)o.push(h.promise);else{let f;c.extensions&&c.extensions[nt.KHR_DRACO_MESH_COMPRESSION]?f=s(c):f=mM(new Fe,c,t),c.mode===ei.TRIANGLE_STRIP?f=f.then(d=>jp(d,qa)):c.mode===ei.TRIANGLE_FAN&&(f=f.then(d=>jp(d,Mo))),r[u]={primitive:c,promise:f},o.push(f)}}return Promise.all(o)}loadMesh(e){let t=this,n=this.json,r=this.extensions,s=n.meshes[e],o=s.primitives,a=[];for(let l=0,c=o.length;l<c;l++){let u=o[l].material===void 0?zC(this.cache):this.getDependency("material",o[l].material);a.push(u)}return a.push(t.loadGeometries(o)),Promise.all(a).then(async function(l){let c=l.slice(0,l.length-1),u=l[l.length-1],h=[];for(let d=0,p=u.length;d<p;d++){let x=u[d],g=o[d],m,b=c[d];if(g.mode===ei.TRIANGLES||g.mode===ei.TRIANGLE_STRIP||g.mode===ei.TRIANGLE_FAN||g.mode===void 0){let v=s.isSkinnedMesh===!0,y=x.hasAttribute("skinIndex")&&x.hasAttribute("skinWeight");v&&y===!1&&console.warn("THREE.GLTFLoader: Missing skinIndex or skinWeight attributes. Skinning disabled."),m=v&&y?new ba(x,b):new we(x,b),m.isSkinnedMesh===!0&&m.normalizeSkinWeights()}else if(g.mode===ei.LINES)m=new gn(x,b);else if(g.mode===ei.LINE_STRIP)m=new Pn(x,b);else if(g.mode===ei.LINE_LOOP)m=new _a(x,b);else if(g.mode===ei.POINTS)m=new xn(x,b);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+g.mode);Object.keys(m.geometry.morphAttributes).length>0&&GC(m,s),m.name=t.createUniqueName(s.name||"mesh_"+e),Ui(m,s),g.extensions&&Us(r,m,g),t.assignFinalMaterial(m),h.push(m)}for(let d=0,p=h.length;d<p;d++)t.associations.set(h[d],{meshes:e,primitives:d});if(h.length===1)return s.extensions&&Us(r,h[0],s),h[0];let f=new ct;s.extensions&&Us(r,f,s),t.associations.set(f,{meshes:e});for(let d=0,p=h.length;d<p;d++)f.add(h[d]);return f})}loadCamera(e){let t,n=this.json.cameras[e],r=n[n.type];if(!r){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return n.type==="perspective"?t=new Jt(Br.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):n.type==="orthographic"&&(t=new zn(-r.xmag,r.xmag,r.ymag,-r.ymag,r.znear,r.zfar)),n.name&&(t.name=this.createUniqueName(n.name)),Ui(t,n),Promise.resolve(t)}loadSkin(e){let t=this.json.skins[e],n=[];for(let r=0,s=t.joints.length;r<s;r++)n.push(this._loadNodeShallow(t.joints[r]));return t.inverseBindMatrices!==void 0?n.push(this.getDependency("accessor",t.inverseBindMatrices)):n.push(null),Promise.all(n).then(function(r){let s=r.pop(),o=r,a=[],l=[];for(let c=0,u=o.length;c<u;c++){let h=o[c];if(h){a.push(h);let f=new Be;s!==null&&f.fromArray(s.array,c*16),l.push(f)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[c])}return new ya(a,l)})}loadAnimation(e){let t=this.json,n=this,r=t.animations[e],s=r.name?r.name:"animation_"+e,o=[],a=[],l=[],c=[],u=[];for(let h=0,f=r.channels.length;h<f;h++){let d=r.channels[h],p=r.samplers[d.sampler],x=d.target,g=x.node,m=r.parameters!==void 0?r.parameters[p.input]:p.input,b=r.parameters!==void 0?r.parameters[p.output]:p.output;x.node!==void 0&&(o.push(this.getDependency("node",g)),a.push(this.getDependency("accessor",m)),l.push(this.getDependency("accessor",b)),c.push(p),u.push(x))}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(l),Promise.all(c),Promise.all(u)]).then(function(h){let f=h[0],d=h[1],p=h[2],x=h[3],g=h[4],m=[];for(let v=0,y=f.length;v<y;v++){let M=f[v],S=d[v],_=p[v],w=x[v],R=g[v];if(M===void 0)continue;M.updateMatrix&&M.updateMatrix();let A=n._createAnimationTracks(M,S,_,w,R);if(A)for(let C=0;C<A.length;C++)m.push(A[C])}let b=new La(s,void 0,m);return Ui(b,r),b})}createNodeMesh(e){let t=this.json,n=this,r=t.nodes[e];return r.mesh===void 0?null:n.getDependency("mesh",r.mesh).then(function(s){let o=n._getNodeRef(n.meshCache,r.mesh,s);return r.weights!==void 0&&o.traverse(function(a){if(a.isMesh)for(let l=0,c=r.weights.length;l<c;l++)a.morphTargetInfluences[l]=r.weights[l]}),o})}loadNode(e){let t=this.json,n=this,r=t.nodes[e],s=n._loadNodeShallow(e),o=[],a=r.children||[];for(let c=0,u=a.length;c<u;c++)o.push(n.getDependency("node",a[c]));let l=r.skin===void 0?Promise.resolve(null):n.getDependency("skin",r.skin);return Promise.all([s,Promise.all(o),l]).then(function(c){let u=c[0],h=c[1],f=c[2];f!==null&&u.traverse(function(d){d.isSkinnedMesh&&d.bind(f,XC)});for(let d=0,p=h.length;d<p;d++)u.add(h[d]);if(u.userData.pivot!==void 0&&h.length>0){let d=u.userData.pivot,p=h[0];u.pivot=new U().fromArray(d),u.position.x-=d[0],u.position.y-=d[1],u.position.z-=d[2],p.position.set(0,0,0),delete u.userData.pivot}return u})}_loadNodeShallow(e){let t=this.json,n=this.extensions,r=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];let s=t.nodes[e],o=s.name?r.createUniqueName(s.name):"",a=[],l=r._invokeOne(function(c){return c.createNodeMesh&&c.createNodeMesh(e)});return l&&a.push(l),s.camera!==void 0&&a.push(r.getDependency("camera",s.camera).then(function(c){return r._getNodeRef(r.cameraCache,s.camera,c)})),r._invokeAll(function(c){return c.createNodeAttachment&&c.createNodeAttachment(e)}).forEach(function(c){a.push(c)}),this.nodeCache[e]=Promise.all(a).then(function(c){let u;if(s.isBone===!0?u=new ho:c.length>1?u=new ct:c.length===1?u=c[0]:u=new Et,u!==c[0])for(let h=0,f=c.length;h<f;h++)u.add(c[h]);if(s.name&&(u.userData.name=s.name,u.name=o),Ui(u,s),s.extensions&&Us(n,u,s),s.matrix!==void 0){let h=new Be;h.fromArray(s.matrix),u.applyMatrix4(h)}else s.translation!==void 0&&u.position.fromArray(s.translation),s.rotation!==void 0&&u.quaternion.fromArray(s.rotation),s.scale!==void 0&&u.scale.fromArray(s.scale);if(!r.associations.has(u))r.associations.set(u,{});else if(s.mesh!==void 0&&r.meshCache.refs[s.mesh]>1){let h=r.associations.get(u);r.associations.set(u,{...h})}return r.associations.get(u).nodes=e,u}),this.nodeCache[e]}loadScene(e){let t=this.extensions,n=this.json.scenes[e],r=this,s=new ct;n.name&&(s.name=r.createUniqueName(n.name)),Ui(s,n),n.extensions&&Us(t,s,n);let o=n.nodes||[],a=[];for(let l=0,c=o.length;l<c;l++)a.push(r.getDependency("node",o[l]));return Promise.all(a).then(function(l){for(let u=0,h=l.length;u<h;u++){let f=l[u];f.parent!==null?s.add(uM(f)):s.add(f)}let c=u=>{let h=new Map;for(let[f,d]of r.associations)(f instanceof mn||f instanceof Kt)&&h.set(f,d);return u.traverse(f=>{let d=r.associations.get(f);d!=null&&h.set(f,d)}),h};return r.associations=c(s),s})}_createAnimationTracks(e,t,n,r,s){let o=[],a=e.name?e.name:e.uuid,l=[];function c(d){d.morphTargetInfluences&&l.push(d.name?d.name:d.uuid)}Yr[s.path]===Yr.weights?(c(e),e.isGroup&&e.children.forEach(c)):l.push(a);let u;switch(Yr[s.path]){case Yr.weights:u=nr;break;case Yr.rotation:u=ir;break;case Yr.translation:case Yr.scale:u=Or;break;default:n.itemSize===1?u=nr:u=Or;break}let h=r.interpolation!==void 0?kC[r.interpolation]:Zi,f=this._getArrayFromAccessor(n);for(let d=0,p=l.length;d<p;d++){let x=new u(l[d]+"."+Yr[s.path],t.array,f,h);r.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(x),o.push(x)}return o}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){let n=Am(t.constructor),r=new Float32Array(t.length);for(let s=0,o=t.length;s<o;s++)r[s]=t[s]*n;t=r}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(n){let r=this instanceof ir?wm:Nh;return new r(this.times,this.values,this.getValueSize()/3,n)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}};function YC(i,e,t){let n=e.attributes,r=new Ct;if(n.POSITION!==void 0){let a=t.json.accessors[n.POSITION],l=a.min,c=a.max;if(l!==void 0&&c!==void 0){if(r.set(new U(l[0],l[1],l[2]),new U(c[0],c[1],c[2])),a.normalized){let u=Am(Wo[a.componentType]);r.min.multiplyScalar(u),r.max.multiplyScalar(u)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;let s=e.targets;if(s!==void 0){let a=new U,l=new U;for(let c=0,u=s.length;c<u;c++){let h=s[c];if(h.POSITION!==void 0){let f=t.json.accessors[h.POSITION],d=f.min,p=f.max;if(d!==void 0&&p!==void 0){if(l.setX(Math.max(Math.abs(d[0]),Math.abs(p[0]))),l.setY(Math.max(Math.abs(d[1]),Math.abs(p[1]))),l.setZ(Math.max(Math.abs(d[2]),Math.abs(p[2]))),f.normalized){let x=Am(Wo[f.componentType]);l.multiplyScalar(x)}a.max(l)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}r.expandByVector(a)}i.boundingBox=r;let o=new Cn;r.getCenter(o.center),o.radius=r.min.distanceTo(r.max)/2,i.boundingSphere=o}function mM(i,e,t){let n=e.attributes,r=[];function s(o,a){return t.getDependency("accessor",o).then(function(l){i.setAttribute(a,l)})}for(let o in n){let a=Tm[o]||o.toLowerCase();a in i.attributes||r.push(s(n[o],a))}if(e.indices!==void 0&&!i.index){let o=t.getDependency("accessor",e.indices).then(function(a){i.setIndex(a)});r.push(o)}return tt.workingColorSpace!==Mn&&"COLOR_0"in n&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${tt.workingColorSpace}" not supported.`),Ui(i,e),YC(i,e,t),Promise.all(r).then(function(){return e.targets!==void 0?VC(i,e.targets,t):i})}var xM=new Map,bM=new Map,qC=50*Math.PI/180;function $C(i){i.traverse(e=>{let t=e;if(!t.isMesh)return;let n=t.geometry,r=t.material,s=r.name??"";t.userData.paint=!!r.userData?.paint||/^Paint/.test(s),n.getAttribute("normal")||(t.userData.paint?n.computeVertexNormals():t.geometry=cM(n,qC)),r.flatShading=!1;let o=/glass/i.test(s);r.metalness=t.userData.paint?.55:o?0:Math.min(r.metalness??0,.4),r.roughness=t.userData.paint?.28:o?.05:Math.max(r.roughness??.6,.45),o&&(r.transparent=!0,r.depthWrite=!1,r.opacity=Math.max(r.opacity,.9))})}function yM(i){let e=xM.get(i);if(!e){let t=D0();if(!t)return Promise.resolve(!1);e=t(i).then(n=>n&&new Promise(r=>{new Xo().parse(n,"",s=>{$C(s.scene);let o=new Ct().setFromObject(s.scene),a=[o.max.x-o.min.x,o.max.y-o.min.y,o.max.z-o.min.z];s.scene.position.set(-(o.max.x+o.min.x)/2,-o.min.y,-(o.max.z+o.min.z)/2);let l=new ct;l.add(s.scene),bM.set(i,{root:l,size:a}),U0(i),r({root:l,size:a})},()=>r(null))})).catch(()=>null),xM.set(i,e)}return e.then(t=>!!t)}function _M(i,e){let t=bM.get(i);if(!t)return null;let n=t.root.clone(!0),r=[];n.traverse(o=>{let a=o;if(!a.isMesh)return;let l=a.material.clone();a.userData.paint&&e.paint&&(l.color=new W(e.paint)),a.material=l,r.push(l)});let s=new ct;return s.add(n),s.scale.set((e.mirror?-1:1)*(e.w/t.size[0]),e.h/t.size[1],e.d/t.size[2]),s.position.set(e.x,e.y,e.z),s.rotation.y=-e.rotation*Math.PI/180,s.userData.own=r,s}function Rm(i){for(let e of i.userData.own??[])e.dispose()}function vM(i,e){let t=new wo(e),n=t.fromScene(new Fh,.04).texture;t.dispose();let r=new ds(16777215,9081766,.9),s=new sr(16777215,1.6);return s.position.set(-4,9,6),i.add(r,s),{env:n,dispose:()=>{n.dispose(),r.removeFromParent(),s.removeFromParent()}}}function MM(i,e){for(let t of i.userData.own??[])t.envMap=e,t.envMapIntensity=.9}var KC=.3,SM=2.6,Dh=.05;function ZC(i,e,t,n){let r=n*.7071,s=[i,[i[0]+n,i[1]],[i[0]-n,i[1]],[i[0],i[1]+n],[i[0],i[1]-n]],o=[[i[0]+r,i[1]+r],[i[0]-r,i[1]+r],[i[0]+r,i[1]-r],[i[0]-r,i[1]-r]];return s.every(a=>Ve(a,e))&&!t.some(a=>[...s,...o].some(l=>Ve(l,a)))}function wM(i,e,t){let n=Math.ceil(Math.hypot(e[0]-i[0],e[1]-i[1])/Dh);for(let r=1;r<n;r++)if(!t([i[0]+(e[0]-i[0])*r/n,i[1]+(e[1]-i[1])*r/n]))return!1;return!0}function JC(i,e,t){let n=null,r=null;for(let s=e;s<=t+1e-6;s+=Dh){let o=i(s);if(o&&(r??=s),(!o||s+Dh>t+1e-6)&&r!==null){let a=o?s:s-Dh;(!n||a-r>n[1]-n[0])&&(n=[r,a]),r=null}}return n}function TM(i,e=.32,t=.22,n=[]){let r=i.map(v=>v[0]),s=i.map(v=>v[1]),[o,a,l,c]=[Math.min(...r),Math.max(...r),Math.min(...s),Math.max(...s)],u=c-l>=a-o,h=v=>ZC(v,i,n,t),f=(v,y)=>u?[v,y]:[y,v],[d,p,x,g]=u?[o,a,l,c]:[l,c,o,a],m=[],b=!0;for(let v=d+t;v<=p-t+1e-6;v+=e){let y=JC(w=>h(f(v,w)),x,g);if(!y||y[1]-y[0]<.2)continue;let M=w=>w?[f(v,y[0]),f(v,y[1])]:[f(v,y[1]),f(v,y[0])],S=M(b),_=m[m.length-1];if(_&&n.length>0&&!wM(_,S[0],h)){let w=M(!b);if(!wM(_,w[0],h))continue;S=w,b=!b}m.push(...S),b=!b}return m}function Pm(i,e=.7,t=12){return Array.from({length:t},(n,r)=>[i[0]+Math.cos(r/t*Math.PI*2)*e,i[1]+Math.sin(r/t*Math.PI*2)*e])}var Cm=i=>Math.atan2(Math.sin(i),Math.cos(i));function AM(i,e,t){let n;if(e.mode==="cleaning"){if(i.path.length===0)return!1;n=i.path[i.next%i.path.length]}else if(e.mode==="returning"||e.mode==="docked")n=e.rest;else return!1;let[r,s]=[n[0]-i.pos[0],n[1]-i.pos[1]],o=Math.hypot(r,s);if(o<.02){if(e.mode==="cleaning")return i.next=(i.next+1)%i.path.length,!0;let l=Cm(e.restHeading-i.heading);return Math.abs(l)<.02?!1:(i.heading+=Math.sign(l)*Math.min(Math.abs(l),SM*t),!0)}let a=Cm(Math.atan2(r,s)-i.heading);if(i.heading=Cm(i.heading+Math.sign(a)*Math.min(Math.abs(a),SM*t)),Math.abs(a)<.35){let l=Math.min(o,KC*t);i.pos=[i.pos[0]+r/o*l,i.pos[1]+s/o*l]}return!0}var Uh=600*1e3,jC=3e3;function EM(i,e){if(i==null)return 1;let t=e-i;return t>Uh?Math.max(0,1-(t-Uh)/jC):1}function Im(i,e,t){let n=e/2,r=[],s=(a,l,c)=>r.push(a[0],t,a[1],l[0],t,l[1],c[0],t,c[1]);for(let a of i){for(let c=0;c+1<a.length;c++){let[u,h]=[a[c],a[c+1]],[f,d]=[h[0]-u[0],h[1]-u[1]],p=Math.hypot(f,d);if(p<1e-4)continue;let[x,g]=[-d/p*n,f/p*n],[m,b]=[[u[0]+x,u[1]+g],[u[0]-x,u[1]-g]],[v,y]=[[h[0]+x,h[1]+g],[h[0]-x,h[1]-g]];s(m,b,v),s(b,y,v)}let l=6;for(let c=1;c+1<a.length;c++){let[u,h,f]=[a[c-1],a[c],a[c+1]],[d,p]=[h[0]-u[0],h[1]-u[1]],[x,g]=[f[0]-h[0],f[1]-h[1]],[m,b]=[Math.hypot(d,p),Math.hypot(x,g)];if(m<1e-9||b<1e-9||Math.abs(d*g-p*x)/(m*b)<.2)continue;let[v,y]=a[c];for(let M=0;M<l;M++){let[S,_]=[M/l*Math.PI*2,(M+1)/l*Math.PI*2];s([v,y],[v+Math.cos(S)*n,y+Math.sin(S)*n],[v+Math.cos(_)*n,y+Math.sin(_)*n])}}}let o=new Fe;return o.setAttribute("position",new ke(r,3)),o}function RM(i,e){return i.roomId?i.roomId===e.roomId:i.floorId===e.floorId}var CM={POSITION:["byte","byte normalized","unsigned byte","unsigned byte normalized","short","short normalized","unsigned short","unsigned short normalized"],NORMAL:["byte normalized","short normalized"],TANGENT:["byte normalized","short normalized"],TEXCOORD:["byte","byte normalized","unsigned byte","short","short normalized","unsigned short"]},qr=class{constructor(){this.textureUtils=null,this.pluginCallbacks=[],this.register(function(e){return new Dm(e)}),this.register(function(e){return new Um(e)}),this.register(function(e){return new Vm(e)}),this.register(function(e){return new Gm(e)}),this.register(function(e){return new Hm(e)}),this.register(function(e){return new Wm(e)}),this.register(function(e){return new Bm(e)}),this.register(function(e){return new km(e)}),this.register(function(e){return new zm(e)}),this.register(function(e){return new Xm(e)}),this.register(function(e){return new Ym(e)}),this.register(function(e){return new qm(e)}),this.register(function(e){return new $m(e)}),this.register(function(e){return new Km(e)})}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}setTextureUtils(e){return this.textureUtils=e,this}parse(e,t,n,r){let s=new Nm,o=[];for(let a=0,l=this.pluginCallbacks.length;a<l;a++)o.push(this.pluginCallbacks[a](s));s.setPlugins(o),s.setTextureUtils(this.textureUtils),s.writeAsync(e,t,r).catch(n)}parseAsync(e,t){let n=this;return new Promise(function(r,s){n.parse(e,r,s,t)})}},rt={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,INT:5124,UNSIGNED_INT:5125,FLOAT:5126,ARRAY_BUFFER:34962,ELEMENT_ARRAY_BUFFER:34963,NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987,CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},Lm="KHR_mesh_quantization",Gn={};Gn[Ut]=rt.NEAREST;Gn[_o]=rt.NEAREST_MIPMAP_NEAREST;Gn[ar]=rt.NEAREST_MIPMAP_LINEAR;Gn[Ht]=rt.LINEAR;Gn[Dr]=rt.LINEAR_MIPMAP_NEAREST;Gn[Fn]=rt.LINEAR_MIPMAP_LINEAR;Gn[ln]=rt.CLAMP_TO_EDGE;Gn[kn]=rt.REPEAT;Gn[Rr]=rt.MIRRORED_REPEAT;var PM={scale:"scale",position:"translation",quaternion:"rotation",morphTargetInfluences:"weights"},QC=new W,IM=12,eP=1179937895,tP=2,LM=8,nP=1313821514,iP=5130562;function xr(i,e){return i.length===e.length&&i.every(function(t,n){return t===e[n]})}function rP(i){return new TextEncoder().encode(i).buffer}function sP(i){return xr(i.elements,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function oP(i,e,t){let n={min:new Array(i.itemSize).fill(Number.POSITIVE_INFINITY),max:new Array(i.itemSize).fill(Number.NEGATIVE_INFINITY)};for(let r=e;r<e+t;r++)for(let s=0;s<i.itemSize;s++){let o;i.itemSize>4?o=i.array[r*i.itemSize+s]:(s===0?o=i.getX(r):s===1?o=i.getY(r):s===2?o=i.getZ(r):s===3&&(o=i.getW(r)),i.normalized===!0&&(o=Br.normalize(o,i.array))),n.min[s]=Math.min(n.min[s],o),n.max[s]=Math.max(n.max[s],o)}return n}function FM(i){return Math.ceil(i/4)*4}function Fm(i,e=0){let t=FM(i.byteLength);if(t!==i.byteLength){let n=new Uint8Array(t);if(n.set(new Uint8Array(i)),e!==0)for(let r=i.byteLength;r<t;r++)n[r]=e;return n.buffer}return i}function Om(){return typeof document>"u"&&typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):document.createElement("canvas")}function aP(i,e){if(typeof OffscreenCanvas<"u"&&i instanceof OffscreenCanvas){let t;return e==="image/jpeg"?t=.92:e==="image/webp"&&(t=.8),i.convertToBlob({type:e,quality:t})}else return new Promise(t=>i.toBlob(t,e))}var Nm=class{constructor(){this.plugins=[],this.options={},this.pending=[],this.buffers=[],this.byteOffset=0,this.buffers=[],this.nodeMap=new Map,this.skins=[],this.extensionsUsed={},this.extensionsRequired={},this.uids=new Map,this.uid=0,this.json={asset:{version:"2.0",generator:"THREE.GLTFExporter r187"}},this.cache={meshes:new Map,attributes:new Map,attributesNormalized:new Map,materials:new Map,textures:new Map,images:new Map,normalMaps:new Map},this.textureUtils=null}setPlugins(e){this.plugins=e}setTextureUtils(e){this.textureUtils=e}async writeAsync(e,t,n={}){this.options=Object.assign({binary:!1,trs:!1,onlyVisible:!0,maxTextureSize:1/0,animations:[],includeCustomExtensions:!1,copyright:null},n),this.options.animations.length>0&&(this.options.trs=!0),await this.processInputAsync(e),await Promise.all(this.pending);let r=this,s=r.buffers,o=r.json;n=r.options;let a=r.extensionsUsed,l=r.extensionsRequired,c=new Blob(s,{type:"application/octet-stream"}),u=Object.keys(a),h=Object.keys(l);if(u.length>0&&(o.extensionsUsed=u),h.length>0&&(o.extensionsRequired=h),o.buffers&&o.buffers.length>0&&(o.buffers[0].byteLength=c.size),n.copyright&&(o.asset.copyright=n.copyright),n.binary===!0){let f=new FileReader;f.readAsArrayBuffer(c),f.onloadend=function(){let d=Fm(f.result),p=new DataView(new ArrayBuffer(LM));p.setUint32(0,d.byteLength,!0),p.setUint32(4,iP,!0);let x=Fm(rP(JSON.stringify(o)),32),g=new DataView(new ArrayBuffer(LM));g.setUint32(0,x.byteLength,!0),g.setUint32(4,nP,!0);let m=new ArrayBuffer(IM),b=new DataView(m);b.setUint32(0,eP,!0),b.setUint32(4,tP,!0);let v=IM+g.byteLength+x.byteLength+p.byteLength+d.byteLength;b.setUint32(8,v,!0);let y=new Blob([m,g,x,p,d],{type:"application/octet-stream"}),M=new FileReader;M.readAsArrayBuffer(y),M.onloadend=function(){t(M.result)}}}else if(o.buffers&&o.buffers.length>0){let f=new FileReader;f.readAsDataURL(c),f.onloadend=function(){let d=f.result;o.buffers[0].uri=d,t(o)}}else t(o)}serializeUserData(e,t){if(Object.keys(e.userData).length===0)return;let n=this.options,r=this.extensionsUsed;try{let s=JSON.parse(JSON.stringify(e.userData));if(n.includeCustomExtensions&&s.gltfExtensions){t.extensions===void 0&&(t.extensions={});for(let o in s.gltfExtensions)t.extensions[o]=s.gltfExtensions[o],r[o]=!0;delete s.gltfExtensions}Object.keys(s).length>0&&(t.extras=s)}catch(s){console.warn("THREE.GLTFExporter: userData of '"+e.name+"' won't be serialized because of JSON.stringify error - "+s.message)}}getUID(e,t=!1){if(this.uids.has(e)===!1){let r=new Map;r.set(!0,this.uid++),r.set(!1,this.uid++),this.uids.set(e,r)}return this.uids.get(e).get(t)}isNormalizedNormalAttribute(e){if(this.cache.attributesNormalized.has(e))return!1;let n=new U;for(let r=0,s=e.count;r<s;r++)if(Math.abs(n.fromBufferAttribute(e,r).length()-1)>5e-4)return!1;return!0}createNormalizedNormalAttribute(e){let t=this.cache;if(t.attributesNormalized.has(e))return t.attributesNormalized.get(e);let n=e.clone(),r=new U;for(let s=0,o=n.count;s<o;s++)r.fromBufferAttribute(n,s),r.x===0&&r.y===0&&r.z===0?r.setX(1):r.normalize(),n.setXYZ(s,r.x,r.y,r.z);return t.attributesNormalized.set(e,n),n}applyTextureTransform(e,t){let n=!1,r={};(t.offset.x!==0||t.offset.y!==0)&&(r.offset=t.offset.toArray(),n=!0),t.rotation!==0&&(r.rotation=t.rotation,n=!0),(t.repeat.x!==1||t.repeat.y!==1)&&(r.scale=t.repeat.toArray(),n=!0),n&&(e.extensions=e.extensions||{},e.extensions.KHR_texture_transform=r,this.extensionsUsed.KHR_texture_transform=!0)}async buildMetalRoughTextureAsync(e,t){if(e===t)return e;function n(d){return d.colorSpace===ft?function(x){return x<.04045?x*.0773993808:Math.pow(x*.9478672986+.0521327014,2.4)}:function(x){return x}}e instanceof Lr&&(e=await this.decompressTextureAsync(e)),t instanceof Lr&&(t=await this.decompressTextureAsync(t));let r=e?e.image:null,s=t?t.image:null,o=Math.max(r?r.width:0,s?s.width:0),a=Math.max(r?r.height:0,s?s.height:0),l=Om();l.width=o,l.height=a;let c=l.getContext("2d",{willReadFrequently:!0});c.fillStyle="#00ffff",c.fillRect(0,0,o,a);let u=c.getImageData(0,0,o,a);if(r){c.drawImage(r,0,0,o,a);let d=n(e),p=c.getImageData(0,0,o,a).data;for(let x=2;x<p.length;x+=4)u.data[x]=d(p[x]/256)*256}if(s){c.drawImage(s,0,0,o,a);let d=n(t),p=c.getImageData(0,0,o,a).data;for(let x=1;x<p.length;x+=4)u.data[x]=d(p[x]/256)*256}c.putImageData(u,0,0);let f=(e||t).clone();return f.source=new Ji(l),f.colorSpace=li,f.channel=(e||t).channel,e&&t&&e.channel!==t.channel&&console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match."),console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures."),f}async buildNormalMapTextureAsync(e,t,n){e instanceof Lr&&(e=await this.decompressTextureAsync(e));let r=e.image,s=Om();s.width=r.width,s.height=r.height;let o=s.getContext("2d",{willReadFrequently:!0});o.drawImage(r,0,0,s.width,s.height);let a=o.getImageData(0,0,s.width,s.height),l=a.data;for(let u=0;u<l.length;u+=4)t&&(l[u+0]=255-l[u+0]),n&&(l[u+1]=255-l[u+1]);o.putImageData(a,0,0);let c=e.clone();return c.source=new Ji(s),c}async decompressTextureAsync(e,t=1/0){if(this.textureUtils===null)throw new Error("THREE.GLTFExporter: setTextureUtils() must be called to process compressed textures.");return await this.textureUtils.decompress(e,t)}processBuffer(e){let t=this.json,n=this.buffers;return t.buffers||(t.buffers=[{byteLength:0}]),n.push(e),0}processBufferView(e,t,n,r,s){let o=this.json;o.bufferViews||(o.bufferViews=[]);let a;switch(t){case rt.BYTE:case rt.UNSIGNED_BYTE:a=1;break;case rt.SHORT:case rt.UNSIGNED_SHORT:a=2;break;default:a=4}let l=e.itemSize*a;s===rt.ARRAY_BUFFER&&(l=Math.ceil(l/4)*4);let c=FM(r*l),u=new DataView(new ArrayBuffer(c)),h=0;for(let p=n;p<n+r;p++){for(let x=0;x<e.itemSize;x++){let g;e.itemSize>4?g=e.array[p*e.itemSize+x]:(x===0?g=e.getX(p):x===1?g=e.getY(p):x===2?g=e.getZ(p):x===3&&(g=e.getW(p)),e.normalized===!0&&(g=Br.normalize(g,e.array))),t===rt.FLOAT?u.setFloat32(h,g,!0):t===rt.INT?u.setInt32(h,g,!0):t===rt.UNSIGNED_INT?u.setUint32(h,g,!0):t===rt.SHORT?u.setInt16(h,g,!0):t===rt.UNSIGNED_SHORT?u.setUint16(h,g,!0):t===rt.BYTE?u.setInt8(h,g):t===rt.UNSIGNED_BYTE&&u.setUint8(h,g),h+=a}h%l!==0&&(h+=l-h%l)}let f={buffer:this.processBuffer(u.buffer),byteOffset:this.byteOffset,byteLength:c};return s!==void 0&&(f.target=s),s===rt.ARRAY_BUFFER&&(f.byteStride=l),this.byteOffset+=c,o.bufferViews.push(f),{id:o.bufferViews.length-1,byteLength:0}}processBufferViewImage(e){let t=this,n=t.json;return n.bufferViews||(n.bufferViews=[]),new Promise(function(r){let s=new FileReader;s.readAsArrayBuffer(e),s.onloadend=function(){let o=Fm(s.result),a={buffer:t.processBuffer(o),byteOffset:t.byteOffset,byteLength:o.byteLength};t.byteOffset+=o.byteLength,r(n.bufferViews.push(a)-1)}})}processAccessor(e,t,n,r){let s=this.json,o={1:"SCALAR",2:"VEC2",3:"VEC3",4:"VEC4",9:"MAT3",16:"MAT4"},a;if(e.array.constructor===Float32Array)a=rt.FLOAT;else if(e.array.constructor===Int32Array)a=rt.INT;else if(e.array.constructor===Uint32Array)a=rt.UNSIGNED_INT;else if(e.array.constructor===Int16Array)a=rt.SHORT;else if(e.array.constructor===Uint16Array)a=rt.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)a=rt.BYTE;else if(e.array.constructor===Uint8Array)a=rt.UNSIGNED_BYTE;else throw new Error("THREE.GLTFExporter: Unsupported bufferAttribute component type: "+e.array.constructor.name);if(n===void 0&&(n=0),(r===void 0||r===1/0)&&(r=e.count),r===0)return null;let l=oP(e,n,r),c;t!==void 0&&(c=e===t.index?rt.ELEMENT_ARRAY_BUFFER:rt.ARRAY_BUFFER);let u=this.processBufferView(e,a,n,r,c),h={bufferView:u.id,byteOffset:u.byteOffset,componentType:a,count:r,max:l.max,min:l.min,type:o[e.itemSize]};return e.normalized===!0&&(h.normalized=!0),s.accessors||(s.accessors=[]),s.accessors.push(h)-1}processImage(e,t,n,r="image/png"){if(e!==null){let s=this,o=s.cache,a=s.json,l=s.options,c=s.pending;o.images.has(e)||o.images.set(e,{});let u=o.images.get(e),h=r+":flipY/"+n.toString();if(u[h]!==void 0)return u[h];a.images||(a.images=[]);let f={mimeType:r},d=Om();d.width=Math.min(e.width,l.maxTextureSize),d.height=Math.min(e.height,l.maxTextureSize);let p=d.getContext("2d",{willReadFrequently:!0});if(n===!0&&(p.translate(0,d.height),p.scale(1,-1)),e.data!==void 0){t!==Nn&&console.error("GLTFExporter: Only RGBAFormat is supported.",t),(e.width>l.maxTextureSize||e.height>l.maxTextureSize)&&console.warn("GLTFExporter: Image size is bigger than maxTextureSize",e);let g=new Uint8ClampedArray(e.height*e.width*4);for(let m=0;m<g.length;m+=4)g[m+0]=e.data[m+0],g[m+1]=e.data[m+1],g[m+2]=e.data[m+2],g[m+3]=e.data[m+3];p.putImageData(new ImageData(g,e.width,e.height),0,0)}else if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap||typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas)p.drawImage(e,0,0,d.width,d.height);else throw new Error("THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.");l.binary===!0?c.push(aP(d,r).then(g=>s.processBufferViewImage(g)).then(g=>{f.bufferView=g})):f.uri=lo.getDataURL(d,r);let x=a.images.push(f)-1;return u[h]=x,x}else throw new Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.")}processSampler(e){let t=this.json;t.samplers||(t.samplers=[]);let n={magFilter:Gn[e.magFilter],minFilter:Gn[e.minFilter],wrapS:Gn[e.wrapS],wrapT:Gn[e.wrapT]};return t.samplers.push(n)-1}async processTextureAsync(e){let n=this.options,r=this.cache,s=this.json;if(r.textures.has(e))return r.textures.get(e);s.textures||(s.textures=[]),e instanceof Lr&&(e=await this.decompressTextureAsync(e,n.maxTextureSize));let o=e.userData.mimeType,a=this.processImage(e.image,e.format,e.flipY,o),l={sampler:this.processSampler(e)};o==="image/webp"?(l.extensions=l.extensions||{},l.extensions.EXT_texture_webp={source:a},this.extensionsUsed.EXT_texture_webp=!0,this.extensionsRequired.EXT_texture_webp=!0):l.source=a,e.name&&(l.name=e.name),await this._invokeAllAsync(async function(u){u.writeTexture&&await u.writeTexture(e,l)});let c=s.textures.push(l)-1;return r.textures.set(e,c),c}async processMaterialAsync(e,t){let n=this.cache,r=this.json,s=t!==void 0&&t.hasAttribute("tangent"),o=e.normalMap?e.uuid+":"+s:e.uuid;if(n.materials.has(o))return n.materials.get(o);if(e.isShaderMaterial)return console.warn("GLTFExporter: THREE.ShaderMaterial not supported."),null;r.materials||(r.materials=[]);let a={pbrMetallicRoughness:{}};e.isMeshStandardMaterial!==!0&&e.isMeshBasicMaterial!==!0&&console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");let l=e.color.toArray().concat([e.opacity]);if(xr(l,[1,1,1,1])||(a.pbrMetallicRoughness.baseColorFactor=l),e.isMeshStandardMaterial?(a.pbrMetallicRoughness.metallicFactor=e.metalness,a.pbrMetallicRoughness.roughnessFactor=e.roughness):(a.pbrMetallicRoughness.metallicFactor=0,a.pbrMetallicRoughness.roughnessFactor=1),e.metalnessMap||e.roughnessMap){let u=await this.buildMetalRoughTextureAsync(e.metalnessMap,e.roughnessMap),h={index:await this.processTextureAsync(u),texCoord:u.channel};this.applyTextureTransform(h,u),a.pbrMetallicRoughness.metallicRoughnessTexture=h}if(e.map){let u={index:await this.processTextureAsync(e.map),texCoord:e.map.channel};this.applyTextureTransform(u,e.map),a.pbrMetallicRoughness.baseColorTexture=u}if(e.emissive){let u=e.emissive;if(Math.max(u.r,u.g,u.b)>0&&(a.emissiveFactor=e.emissive.toArray()),e.emissiveMap){let f={index:await this.processTextureAsync(e.emissiveMap),texCoord:e.emissiveMap.channel};this.applyTextureTransform(f,e.emissiveMap),a.emissiveTexture=f}}if(e.normalMap){let u=e.normalScale,h=u.x<0,f=s?u.y<0:u.y>0,d=e.normalMap;if(h||f){n.normalMaps.has(e.normalMap)===!1&&n.normalMaps.set(e.normalMap,{});let x=n.normalMaps.get(e.normalMap),g=`${h}:${f}`;x[g]===void 0&&(x[g]=await this.buildNormalMapTextureAsync(e.normalMap,h,f)),d=x[g]}let p={index:await this.processTextureAsync(d),texCoord:e.normalMap.channel};Math.abs(u.x)!==1&&(p.scale=Math.abs(u.x)),this.applyTextureTransform(p,e.normalMap),a.normalTexture=p}if(e.aoMap){let u={index:await this.processTextureAsync(e.aoMap),texCoord:e.aoMap.channel};e.aoMapIntensity!==1&&(u.strength=e.aoMapIntensity),this.applyTextureTransform(u,e.aoMap),a.occlusionTexture=u}e.transparent?a.alphaMode="BLEND":e.alphaTest>0&&(a.alphaMode="MASK",a.alphaCutoff=e.alphaTest),e.side===ut&&(a.doubleSided=!0),e.name!==""&&(a.name=e.name),this.serializeUserData(e,a),await this._invokeAllAsync(async function(u){u.writeMaterialAsync&&await u.writeMaterialAsync(e,a)});let c=r.materials.push(a)-1;return n.materials.set(o,c),c}async processMeshAsync(e){let t=this.cache,n=this.json,r=[e.geometry.uuid];if(Array.isArray(e.material))for(let y=0,M=e.material.length;y<M;y++)r.push(e.material[y].uuid);else r.push(e.material.uuid);let s=r.join(":");if(t.meshes.has(s))return t.meshes.get(s);let o=e.geometry,a;e.isLineSegments?a=rt.LINES:e.isLineLoop?a=rt.LINE_LOOP:e.isLine?a=rt.LINE_STRIP:e.isPoints?a=rt.POINTS:a=e.material.wireframe?rt.LINES:rt.TRIANGLES;let l={},c={},u=[],h=[],f={uv:"TEXCOORD_0",uv1:"TEXCOORD_1",uv2:"TEXCOORD_2",uv3:"TEXCOORD_3",color:"COLOR_0",skinWeight:"WEIGHTS_0",skinIndex:"JOINTS_0"},d=o.getAttribute("normal");d!==void 0&&!this.isNormalizedNormalAttribute(d)&&(console.warn("THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one."),o.setAttribute("normal",this.createNormalizedNormalAttribute(d)));let p=null;for(let y in o.attributes){if(y.slice(0,5)==="morph")continue;let M=o.attributes[y];if(y=f[y]||y.toUpperCase(),!/^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/.test(y)&&!y.startsWith("_")&&(y="_"+y),t.attributes.has(this.getUID(M))){c[y]=t.attributes.get(this.getUID(M));continue}p=null;let _=M.array;y==="JOINTS_0"&&!(_ instanceof Uint16Array)&&!(_ instanceof Uint8Array)?(console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.'),p=qr.Utils.toTypedBufferAttribute(M,Uint16Array)):(_ instanceof Uint32Array||_ instanceof Int32Array)&&!y.startsWith("_")&&(console.warn(`GLTFExporter: Attribute "${y}" converted to type FLOAT.`),p=qr.Utils.toTypedBufferAttribute(M,Float32Array));let w=this.processAccessor(p||M,o);w!==null&&(y.startsWith("_")||this.detectMeshQuantization(y,M),c[y]=w,t.attributes.set(this.getUID(M),w))}if(d!==void 0&&o.setAttribute("normal",d),Object.keys(c).length===0)return null;if(e.morphTargetInfluences!==void 0&&e.morphTargetInfluences.length>0){let y=[],M=[],S={};if(e.morphTargetDictionary!==void 0)for(let _ in e.morphTargetDictionary)S[e.morphTargetDictionary[_]]=_;for(let _=0;_<e.morphTargetInfluences.length;++_){let w={},R=!1;for(let A in o.morphAttributes){if(A!=="position"&&A!=="normal"){R||(console.warn("GLTFExporter: Only POSITION and NORMAL morph are supported."),R=!0);continue}let C=o.morphAttributes[A][_],O=A.toUpperCase(),D=o.attributes[A];if(t.attributes.has(this.getUID(C,!0))){w[O]=t.attributes.get(this.getUID(C,!0));continue}let P=C.clone();if(!o.morphTargetsRelative)for(let I=0,N=C.count;I<N;I++)for(let F=0;F<C.itemSize;F++)F===0&&P.setX(I,C.getX(I)-D.getX(I)),F===1&&P.setY(I,C.getY(I)-D.getY(I)),F===2&&P.setZ(I,C.getZ(I)-D.getZ(I)),F===3&&P.setW(I,C.getW(I)-D.getW(I));w[O]=this.processAccessor(P,o),t.attributes.set(this.getUID(D,!0),w[O])}h.push(w),y.push(e.morphTargetInfluences[_]),e.morphTargetDictionary!==void 0&&M.push(S[_])}l.weights=y,M.length>0&&(l.extras={},l.extras.targetNames=M)}let x=Array.isArray(e.material);if(x&&o.groups.length===0)return null;let g=!1;if(x&&o.index===null){let y=[];for(let M=0,S=o.attributes.position.count;M<S;M++)y[M]=M;o.setIndex(y),g=!0}let m=x?e.material:[e.material],b=x?o.groups:[{materialIndex:0,start:void 0,count:void 0}];for(let y=0,M=b.length;y<M;y++){let S={mode:a,attributes:c};if(this.serializeUserData(o,S),h.length>0&&(S.targets=h),o.index!==null){let w=this.getUID(o.index);(b[y].start!==void 0||b[y].count!==void 0)&&(w+=":"+b[y].start+":"+b[y].count),t.attributes.has(w)?S.indices=t.attributes.get(w):(S.indices=this.processAccessor(o.index,o,b[y].start,b[y].count),t.attributes.set(w,S.indices)),S.indices===null&&delete S.indices}let _=await this.processMaterialAsync(m[b[y].materialIndex],o);_!==null&&(S.material=_),u.push(S)}g===!0&&o.setIndex(null),l.primitives=u,n.meshes||(n.meshes=[]),await this._invokeAllAsync(function(y){y.writeMesh&&y.writeMesh(e,l)});let v=n.meshes.push(l)-1;return t.meshes.set(s,v),v}detectMeshQuantization(e,t){if(this.extensionsUsed[Lm])return;let n;switch(t.array.constructor){case Int8Array:n="byte";break;case Uint8Array:n="unsigned byte";break;case Int16Array:n="short";break;case Uint16Array:n="unsigned short";break;default:return}t.normalized&&(n+=" normalized");let r=e.split("_",1)[0];CM[r]&&CM[r].includes(n)&&(this.extensionsUsed[Lm]=!0,this.extensionsRequired[Lm]=!0)}processCamera(e){let t=this.json;t.cameras||(t.cameras=[]);let n=e.isOrthographicCamera,r={type:n?"orthographic":"perspective"};return n?r.orthographic={xmag:e.right,ymag:e.top,zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near}:r.perspective={aspectRatio:e.aspect,yfov:Br.degToRad(e.fov),zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near},e.name!==""&&(r.name=e.type),t.cameras.push(r)-1}processAnimation(e,t){let n=this.json,r=this.nodeMap;n.animations||(n.animations=[]),e=qr.Utils.mergeMorphTargetTracks(e.clone(),t);let s=e.tracks,o=[],a=[];for(let c=0;c<s.length;++c){let u=s[c],h=gt.parseTrackName(u.name),f=gt.findNode(t,h.nodeName),d=PM[h.propertyName];if(h.objectName==="bones"&&(f.isSkinnedMesh===!0?f=f.skeleton.getBoneByName(h.objectIndex):f=void 0),!f||!d){console.warn('THREE.GLTFExporter: Could not export animation track "%s".',u.name);continue}let p=1,x=u.values.length/u.times.length;d===PM.morphTargetInfluences&&(x/=f.morphTargetInfluences.length);let g;u.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline===!0?(g="CUBICSPLINE",x/=3):u.getInterpolation()===Ki?g="STEP":g="LINEAR",a.push({input:this.processAccessor(new wt(u.times,p)),output:this.processAccessor(new wt(u.values,x)),interpolation:g}),o.push({sampler:a.length-1,target:{node:r.get(f),path:d}})}let l={name:e.name||"clip_"+n.animations.length,samplers:a,channels:o};return this.serializeUserData(e,l),n.animations.push(l),n.animations.length-1}processSkin(e){let t=this.json,n=this.nodeMap,r=t.nodes[n.get(e)],s=e.skeleton;if(s===void 0)return null;let o=e.skeleton.bones[0];if(o===void 0)return null;let a=[],l=new Float32Array(s.bones.length*16),c=new Be;for(let h=0;h<s.bones.length;++h)a.push(n.get(s.bones[h])),c.copy(s.boneInverses[h]),c.multiply(e.bindMatrix).toArray(l,h*16);return t.skins===void 0&&(t.skins=[]),t.skins.push({inverseBindMatrices:this.processAccessor(new wt(l,16)),joints:a,skeleton:n.get(o)}),r.skin=t.skins.length-1}async processNodeAsync(e){let t=this.json,n=this.options,r=this.nodeMap;if(t.nodes||(t.nodes=[]),e.pivot!==null)return await this._processNodeWithPivotAsync(e);let s={};if(n.trs){let a=e.quaternion.toArray(),l=e.position.toArray(),c=e.scale.toArray();xr(a,[0,0,0,1])||(s.rotation=a),xr(l,[0,0,0])||(s.translation=l),xr(c,[1,1,1])||(s.scale=c)}else e.matrixAutoUpdate&&e.updateMatrix(),sP(e.matrix)===!1&&(s.matrix=e.matrix.elements);if(e.name!==""&&(s.name=String(e.name)),this.serializeUserData(e,s),e.isMesh||e.isLine||e.isPoints){let a=await this.processMeshAsync(e);a!==null&&(s.mesh=a)}else e.isCamera&&(s.camera=this.processCamera(e));e.isSkinnedMesh&&this.skins.push(e);let o=t.nodes.push(s)-1;if(r.set(e,o),e.children.length>0){let a=[];for(let l=0,c=e.children.length;l<c;l++){let u=e.children[l];if(u.visible||n.onlyVisible===!1){let h=await this.processNodeAsync(u);h!==null&&a.push(h)}}a.length>0&&(s.children=a)}return await this._invokeAllAsync(function(a){a.writeNode&&a.writeNode(e,s)}),o}async _processNodeWithPivotAsync(e){let t=this.json,n=this.options,r=this.nodeMap,s=e.pivot,o={},a=e.quaternion.toArray(),l=[e.position.x+s.x,e.position.y+s.y,e.position.z+s.z],c=e.scale.toArray();xr(a,[0,0,0,1])||(o.rotation=a),xr(l,[0,0,0])||(o.translation=l),xr(c,[1,1,1])||(o.scale=c),o.extras={pivot:s.toArray()},e.name!==""&&(o.name=String(e.name)),this.serializeUserData(e,o);let u=t.nodes.push(o)-1;r.set(e,u);let h={},f=[-s.x,-s.y,-s.z];if(xr(f,[0,0,0])||(h.translation=f),e.isMesh||e.isLine||e.isPoints){let x=await this.processMeshAsync(e);x!==null&&(h.mesh=x)}else e.isCamera&&(h.camera=this.processCamera(e));e.isSkinnedMesh&&this.skins.push(e);let p=[t.nodes.push(h)-1];if(e.children.length>0){let x=[];for(let g=0,m=e.children.length;g<m;g++){let b=e.children[g];if(b.visible||n.onlyVisible===!1){let v=await this.processNodeAsync(b);v!==null&&x.push(v)}}x.length>0&&(h.children=x)}return o.children=p,await this._invokeAllAsync(function(x){x.writeNode&&x.writeNode(e,o)}),u}async processSceneAsync(e){let t=this.json,n=this.options;t.scenes||(t.scenes=[],t.scene=0);let r={};e.name!==""&&(r.name=e.name),t.scenes.push(r);let s=[];for(let o=0,a=e.children.length;o<a;o++){let l=e.children[o];if(l.visible||n.onlyVisible===!1){let c=await this.processNodeAsync(l);c!==null&&s.push(c)}}s.length>0&&(r.nodes=s),this.serializeUserData(e,r)}async processObjectsAsync(e){let t=new Tn;t.name="AuxScene";for(let n=0;n<e.length;n++)t.children.push(e[n]);await this.processSceneAsync(t)}async processInputAsync(e){let t=this.options;e=e instanceof Array?e:[e],await this._invokeAllAsync(function(r){r.beforeParse&&r.beforeParse(e)});let n=[];for(let r=0;r<e.length;r++)e[r]instanceof Tn?await this.processSceneAsync(e[r]):n.push(e[r]);n.length>0&&await this.processObjectsAsync(n);for(let r=0;r<this.skins.length;++r)this.processSkin(this.skins[r]);if(e.length===1)for(let r=0;r<t.animations.length;++r)this.processAnimation(t.animations[r],e[0]);else for(let r=0;r<e.length;r++){let s=t.animations[r]||[];for(let o=0;o<s.length;++o)this.processAnimation(s[o],e[r])}await this._invokeAllAsync(function(r){r.afterParse&&r.afterParse(e)})}async _invokeAllAsync(e){for(let t=0,n=this.plugins.length;t<n;t++)await e(this.plugins[t])}},Dm=class{constructor(e){this.writer=e,this.name="KHR_lights_punctual"}writeNode(e,t){if(!e.isLight)return;if(!e.isDirectionalLight&&!e.isPointLight&&!e.isSpotLight){console.warn("THREE.GLTFExporter: Only directional, point, and spot lights are supported.",e);return}let n=this.writer,r=n.json,s=n.extensionsUsed,o={};e.name&&(o.name=e.name),o.color=e.color.toArray(),o.intensity=e.intensity,e.isDirectionalLight?o.type="directional":e.isPointLight?(o.type="point",e.distance>0&&(o.range=e.distance)):e.isSpotLight&&(o.type="spot",e.distance>0&&(o.range=e.distance),o.spot={},o.spot.innerConeAngle=(1-e.penumbra)*e.angle,o.spot.outerConeAngle=e.angle),e.decay!==void 0&&e.decay!==2&&console.warn("THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."),e.target&&(e.target.parent!==e||e.target.position.x!==0||e.target.position.y!==0||e.target.position.z!==-1)&&console.warn("THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1."),s[this.name]||(r.extensions=r.extensions||{},r.extensions[this.name]={lights:[]},s[this.name]=!0);let a=r.extensions[this.name].lights;a.push(o),t.extensions=t.extensions||{},t.extensions[this.name]={light:a.length-1}}},Um=class{constructor(e){this.writer=e,this.name="KHR_materials_unlit"}async writeMaterialAsync(e,t){if(!e.isMeshBasicMaterial)return;let r=this.writer.extensionsUsed;t.extensions=t.extensions||{},t.extensions[this.name]={},r[this.name]=!0,t.pbrMetallicRoughness.metallicFactor=0,t.pbrMetallicRoughness.roughnessFactor=.9}},Bm=class{constructor(e){this.writer=e,this.name="KHR_materials_clearcoat"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.clearcoat===0)return;let n=this.writer,r=n.extensionsUsed,s={};if(s.clearcoatFactor=e.clearcoat,e.clearcoatMap){let o={index:await n.processTextureAsync(e.clearcoatMap),texCoord:e.clearcoatMap.channel};n.applyTextureTransform(o,e.clearcoatMap),s.clearcoatTexture=o}if(s.clearcoatRoughnessFactor=e.clearcoatRoughness,e.clearcoatRoughnessMap){let o={index:await n.processTextureAsync(e.clearcoatRoughnessMap),texCoord:e.clearcoatRoughnessMap.channel};n.applyTextureTransform(o,e.clearcoatRoughnessMap),s.clearcoatRoughnessTexture=o}if(e.clearcoatNormalMap){let o={index:await n.processTextureAsync(e.clearcoatNormalMap),texCoord:e.clearcoatNormalMap.channel};e.clearcoatNormalScale.x!==1&&(o.scale=e.clearcoatNormalScale.x),n.applyTextureTransform(o,e.clearcoatNormalMap),s.clearcoatNormalTexture=o}t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},km=class{constructor(e){this.writer=e,this.name="KHR_materials_dispersion"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.dispersion===0)return;let r=this.writer.extensionsUsed,s={};s.dispersion=e.dispersion,t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},zm=class{constructor(e){this.writer=e,this.name="KHR_materials_iridescence"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.iridescence===0)return;let n=this.writer,r=n.extensionsUsed,s={};if(s.iridescenceFactor=e.iridescence,e.iridescenceMap){let o={index:await n.processTextureAsync(e.iridescenceMap),texCoord:e.iridescenceMap.channel};n.applyTextureTransform(o,e.iridescenceMap),s.iridescenceTexture=o}if(s.iridescenceIor=e.iridescenceIOR,s.iridescenceThicknessMinimum=e.iridescenceThicknessMinimum,s.iridescenceThicknessMaximum=e.iridescenceThicknessMaximum,e.iridescenceThicknessMap){let o={index:await n.processTextureAsync(e.iridescenceThicknessMap),texCoord:e.iridescenceThicknessMap.channel};n.applyTextureTransform(o,e.iridescenceThicknessMap),s.iridescenceThicknessTexture=o}t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Vm=class{constructor(e){this.writer=e,this.name="KHR_materials_transmission"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;let n=this.writer,r=n.extensionsUsed,s={};if(s.transmissionFactor=e.transmission,e.transmissionMap){let o={index:await n.processTextureAsync(e.transmissionMap),texCoord:e.transmissionMap.channel};n.applyTextureTransform(o,e.transmissionMap),s.transmissionTexture=o}t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Gm=class{constructor(e){this.writer=e,this.name="KHR_materials_volume"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;let n=this.writer,r=n.extensionsUsed,s={};if(s.thicknessFactor=e.thickness,e.thicknessMap){let o={index:await n.processTextureAsync(e.thicknessMap),texCoord:e.thicknessMap.channel};n.applyTextureTransform(o,e.thicknessMap),s.thicknessTexture=o}e.attenuationDistance!==1/0&&(s.attenuationDistance=e.attenuationDistance),s.attenuationColor=e.attenuationColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Hm=class{constructor(e){this.writer=e,this.name="KHR_materials_ior"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.ior===1.5)return;let r=this.writer.extensionsUsed,s={};s.ior=e.ior,t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Wm=class{constructor(e){this.writer=e,this.name="KHR_materials_specular"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.specularIntensity===1&&e.specularColor.equals(QC)&&!e.specularIntensityMap&&!e.specularColorMap)return;let n=this.writer,r=n.extensionsUsed,s={};if(e.specularIntensityMap){let o={index:await n.processTextureAsync(e.specularIntensityMap),texCoord:e.specularIntensityMap.channel};n.applyTextureTransform(o,e.specularIntensityMap),s.specularTexture=o}if(e.specularColorMap){let o={index:await n.processTextureAsync(e.specularColorMap),texCoord:e.specularColorMap.channel};n.applyTextureTransform(o,e.specularColorMap),s.specularColorTexture=o}s.specularFactor=e.specularIntensity,s.specularColorFactor=e.specularColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Xm=class{constructor(e){this.writer=e,this.name="KHR_materials_sheen"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.sheen==0)return;let n=this.writer,r=n.extensionsUsed,s={};if(e.sheenRoughnessMap){let o={index:await n.processTextureAsync(e.sheenRoughnessMap),texCoord:e.sheenRoughnessMap.channel};n.applyTextureTransform(o,e.sheenRoughnessMap),s.sheenRoughnessTexture=o}if(e.sheenColorMap){let o={index:await n.processTextureAsync(e.sheenColorMap),texCoord:e.sheenColorMap.channel};n.applyTextureTransform(o,e.sheenColorMap),s.sheenColorTexture=o}s.sheenRoughnessFactor=e.sheenRoughness,s.sheenColorFactor=e.sheenColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Ym=class{constructor(e){this.writer=e,this.name="KHR_materials_anisotropy"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.anisotropy==0)return;let n=this.writer,r=n.extensionsUsed,s={};if(e.anisotropyMap){let o={index:await n.processTextureAsync(e.anisotropyMap)};n.applyTextureTransform(o,e.anisotropyMap),s.anisotropyTexture=o}s.anisotropyStrength=e.anisotropy,s.anisotropyRotation=e.anisotropyRotation,t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},qm=class{constructor(e){this.writer=e,this.name="KHR_materials_emissive_strength"}async writeMaterialAsync(e,t){if(!e.isMeshStandardMaterial||e.emissiveIntensity===1)return;let r=this.writer.extensionsUsed,s={};s.emissiveStrength=e.emissiveIntensity,t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},$m=class{constructor(e){this.writer=e,this.name="EXT_materials_bump"}async writeMaterialAsync(e,t){if(!e.isMeshStandardMaterial||e.bumpScale===1&&!e.bumpMap)return;let n=this.writer,r=n.extensionsUsed,s={};if(e.bumpMap){let o={index:await n.processTextureAsync(e.bumpMap),texCoord:e.bumpMap.channel};n.applyTextureTransform(o,e.bumpMap),s.bumpTexture=o}s.bumpFactor=e.bumpScale,t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Km=class{constructor(e){this.writer=e,this.name="EXT_mesh_gpu_instancing"}writeNode(e,t){if(!e.isInstancedMesh)return;let n=this.writer,r=e,s=new Float32Array(r.count*3),o=new Float32Array(r.count*4),a=new Float32Array(r.count*3),l=new Be,c=new U,u=new Sn,h=new U;for(let d=0;d<r.count;d++)r.getMatrixAt(d,l),l.decompose(c,u,h),c.toArray(s,d*3),u.toArray(o,d*4),h.toArray(a,d*3);let f={TRANSLATION:n.processAccessor(new wt(s,3)),ROTATION:n.processAccessor(new wt(o,4)),SCALE:n.processAccessor(new wt(a,3))};r.instanceColor&&(f._COLOR_0=n.processAccessor(r.instanceColor)),t.extensions=t.extensions||{},t.extensions[this.name]={attributes:f},n.extensionsUsed[this.name]=!0,n.extensionsRequired[this.name]=!0}};qr.Utils={insertKeyframe:function(i,e){let n=i.getValueSize(),r=new i.TimeBufferType(i.times.length+1),s=new i.ValueBufferType(i.values.length+n),o=i.createInterpolant(new i.ValueBufferType(n)),a;if(i.times.length===0){r[0]=e;for(let l=0;l<n;l++)s[l]=0;a=0}else if(e<i.times[0]){if(Math.abs(i.times[0]-e)<.001)return 0;r[0]=e,r.set(i.times,1),s.set(o.evaluate(e),0),s.set(i.values,n),a=0}else if(e>i.times[i.times.length-1]){if(Math.abs(i.times[i.times.length-1]-e)<.001)return i.times.length-1;r[r.length-1]=e,r.set(i.times,0),s.set(i.values,0),s.set(o.evaluate(e),i.values.length),a=r.length-1}else for(let l=0;l<i.times.length;l++){if(Math.abs(i.times[l]-e)<.001)return l;if(i.times[l]<e&&i.times[l+1]>e){r.set(i.times.slice(0,l+1),0),r[l+1]=e,r.set(i.times.slice(l+1),l+2),s.set(i.values.slice(0,(l+1)*n),0),s.set(o.evaluate(e),(l+1)*n),s.set(i.values.slice((l+1)*n),(l+2)*n),a=l+1;break}}return i.times=r,i.values=s,a},mergeMorphTargetTracks:function(i,e){let t=[],n={},r=i.tracks;for(let s=0;s<r.length;++s){let o=r[s],a=gt.parseTrackName(o.name),l=gt.findNode(e,a.nodeName);if(a.propertyName!=="morphTargetInfluences"||a.propertyIndex===void 0){t.push(o);continue}if(o.createInterpolant!==o.InterpolantFactoryMethodDiscrete&&o.createInterpolant!==o.InterpolantFactoryMethodLinear){if(o.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline)throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.");console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead."),o=o.clone(),o.setInterpolation(Zi)}let c=l.morphTargetInfluences.length,u=l.morphTargetDictionary[a.propertyIndex];if(u===void 0)throw new Error("THREE.GLTFExporter: Morph target name not found: "+a.propertyIndex);let h;if(n[l.uuid]===void 0){h=o.clone();let d=new h.ValueBufferType(c*h.times.length);for(let p=0;p<h.times.length;p++)d[p*c+u]=h.values[p];h.name=(a.nodeName||"")+".morphTargetInfluences",h.values=d,n[l.uuid]=h,t.push(h);continue}let f=o.createInterpolant(new o.ValueBufferType(1));h=n[l.uuid];for(let d=0;d<h.times.length;d++)h.values[d*c+u]=f.evaluate(h.times[d]);for(let d=0;d<o.times.length;d++){let p=this.insertKeyframe(h,o.times[d]);h.values[p*c+u]=o.values[d]}}return i.tracks=t,i},toTypedBufferAttribute:function(i,e){let t=new wt(new e(i.count*i.itemSize),i.itemSize,!1);if(!i.normalized&&!i.isInterleavedBufferAttribute)return t.array.set(i.array),t;for(let n=0,r=i.count;n<r;n++)for(let s=0;s<i.itemSize;s++)t.setComponent(n,s,i.getComponent(n,s));return t}};var lP=/^paint|carpaint|body|lack|lacquer|exterior/i;function OM(i){let e=i.filter(r=>lP.test(r.name)).map(r=>r.name);if(e.length>0)return e;let n=[...i.filter(r=>r.opacity>=.9&&r.lightness>.12&&!/glass|window|light|lamp/i.test(r.name))].sort((r,s)=>s.area-r.area)[0];return n?[n.name]:[]}function NM(i,e){let t=i.reduce((r,s)=>r+s,0);if(t<=e)return[...i];let n=e/t;return i.map(r=>Math.max(1,Math.floor(r*n)))}var DM=i=>/^Paint/.test(i)?i:`Paint_${i||"body"}`;var Yo=i=>i.indices.length/3;function cP(i){let e=[1/0,1/0,1/0],t=[-1/0,-1/0,-1/0];for(let n=0;n<i.length;n+=3)for(let r=0;r<3;r++)e[r]=Math.min(e[r],i[n+r]),t[r]=Math.max(t[r],i[n+r]);return{min:e,size:[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}}function UM(i,e,t){let n=i.length/3,r=e.size.map(o=>Math.floor(o/t)+1),s=new Float64Array(n);for(let o=0;o<n;o++){let a=Math.floor((i[o*3]-e.min[0])/t),l=Math.floor((i[o*3+1]-e.min[1])/t),c=Math.floor((i[o*3+2]-e.min[2])/t);s[o]=(a*r[1]+l)*r[2]+c}return s}function uP(i,e){let t=0;for(let n=0;n<i.length;n+=3){let[r,s,o]=[e[i[n]],e[i[n+1]],e[i[n+2]]];r!==s&&s!==o&&r!==o&&t++}return t}function hP(i,e){let t=new Map,n=[],r=[],s=new Uint32Array(e.length);for(let c=0;c<e.length;c++){let u=t.get(e[c]);u===void 0&&(u=r.length,t.set(e[c],u),r.push(0),n.push(0,0,0)),s[c]=u,r[u]++;for(let h=0;h<3;h++)n[u*3+h]+=i.positions[c*3+h]}let o=new Float32Array(r.length*3);for(let c=0;c<r.length;c++)for(let u=0;u<3;u++)o[c*3+u]=n[c*3+u]/r[c];let a=new Set,l=[];for(let c=0;c<i.indices.length;c+=3){let[u,h,f]=[s[i.indices[c]],s[i.indices[c+1]],s[i.indices[c+2]]];if(u===h||h===f||u===f)continue;let d=Math.min(u,h,f),p=d===u?`${u},${h},${f}`:d===h?`${h},${f},${u}`:`${f},${u},${h}`;a.has(p)||(a.add(p),l.push(u,h,f))}return{positions:o,indices:Uint32Array.from(l)}}function BM(i,e){if(Yo(i)<=e||i.positions.length===0)return i;let t=cP(i.positions),n=Math.max(...t.size,1e-9),r=n/4096,s=n,o=UM(i.positions,t,s);for(let a=0;a<14;a++){let l=Math.sqrt(r*s),c=UM(i.positions,t,l);uP(i.indices,c)>e?r=l:(s=l,o=c)}return hP(i,o)}var Bi=class extends Error{reason;constructor(e,t){super(t),this.reason=e}},fP=1179937895;function dP(i){if(i.byteLength<20||new DataView(i).getUint32(0,!0)!==fP)throw new Bi("not_glb","not a binary glTF (.glb) file")}async function Zm(i){return dP(i),new Promise((e,t)=>{new Xo().parse(i,"",n=>e(n.scene),n=>{let r=String(n?.message??n);t(/draco|meshopt|ktx/i.test(r)?new Bi("compressed",r):new Bi("unreadable",r))})})}var pP=i=>i instanceof In?i:Object.assign(new In,{color:i.color?.clone()??new W(8947848),name:i.name,opacity:i.opacity,transparent:i.transparent});function kM(i,e){i.updateMatrixWorld(!0);let t=new Map;return i.traverse(n=>{let r=n;if(!r.isMesh)return;let s=r.geometry,o=s.getAttribute("position");if(!o)return;let a=pP(Array.isArray(r.material)?r.material[0]:r.material),l=t.get(a)??{positions:[],indices:[]};t.set(a,l);let c=new Be().multiplyMatrices(e,r.matrixWorld),u=l.positions.length/3,h=new U;for(let p=0;p<o.count;p++)h.fromBufferAttribute(o,p).applyMatrix4(c),l.positions.push(h.x,h.y,h.z);let f=s.getIndex(),d=f?f.count:o.count;for(let p=0;p<d;p++)l.indices.push(u+(f?f.getX(p):p))}),[...t].map(([n,r])=>({material:n,mesh:{positions:Float32Array.from(r.positions),indices:Uint32Array.from(r.indices)}}))}var mP=i=>{let e=0,[t,n,r]=[new U,new U,new U];for(let s=0;s<i.indices.length;s+=3)t.fromArray(i.positions,i.indices[s]*3),n.fromArray(i.positions,i.indices[s+1]*3),r.fromArray(i.positions,i.indices[s+2]*3),e+=n.sub(t).cross(r.sub(t)).length()/2;return e},gP=i=>.299*i.r+.587*i.g+.114*i.b;async function xP(i){let e=kM(await Zm(i),new Be);if(e.length===0)throw new Bi("empty","the file has no 3D parts");let t=new Ct;for(let s of e)t.union(new Ct().setFromArray(s.mesh.positions));let n=t.getSize(new U),r=e.map(s=>({name:s.material.name||"material",area:mP(s.mesh),opacity:s.material.opacity,lightness:gP(s.material.color)}));return{triangles:e.reduce((s,o)=>s+Yo(o.mesh),0),size:[n.x,n.y,n.z],materials:r,paint:OM(r)}}async function bP(i,e){let t=new Be().makeRotationY(e.turns*Math.PI/2),n=kM(await Zm(i),t);if(n.length===0)throw new Bi("empty","the file has no 3D parts");let r=NM(n.map(l=>Yo(l.mesh)),e.maxTriangles),s=new Tn,o=0;return n.forEach((l,c)=>{let u=BM(l.mesh,r[c]);if(Yo(u)===0)return;o+=Yo(u);let h=new Fe;h.setAttribute("position",new wt(u.positions,3)),h.setIndex(new wt(u.indices,1));let f=l.material.name||"material",d=e.paint.includes(f),p=new In({color:l.material.color.clone(),name:d?DM(f):f,metalness:l.material.metalness,roughness:l.material.roughness,opacity:l.material.opacity,transparent:l.material.opacity<1});d&&(p.userData.paint=!0),s.add(new we(h,p))}),{glb:await new Promise((l,c)=>{new qr().parse(s,u=>u instanceof ArrayBuffer?l(u):c(new Bi("unreadable","export gave no binary")),u=>c(new Bi("unreadable",String(u))),{binary:!0})}),triangles:o}}async function yP(i,e,t=220){let n=await Zm(i),r=new Ct().setFromObject(n),s=r.getCenter(new U),o=r.getSize(new U);n.traverse(d=>{let p=d;if(!p.isMesh)return;let x=p.material;(x.userData?.paint||/^Paint/.test(x.name))&&x.color.set(e),x.metalness=Math.min(x.metalness??0,.5)});let a=new Tn,l=new sr(16777215,1.6);l.position.set(-4,9,6),a.add(n,new Da(16777215,.5),new ds(16777215,6713480,1.1),l);let c=Math.max(o.x,o.y,o.z)*.75,u=new zn(-c,c,c,-c,.01,100);u.position.copy(s).add(new U(.9,.7,1.2).normalize().multiplyScalar(20)),u.lookAt(s);let h=new kr({alpha:!0,antialias:!0,preserveDrawingBuffer:!0});h.setSize(t,t,!1),h.render(a,u);let f=h.domElement.toDataURL("image/png");return h.dispose(),a.traverse(d=>{let p=d;p.isMesh&&p.geometry.dispose()}),f}var qo=null,zM=new Map,VM=16758087;function _P(i,e,t){let n=vt(i.type);if(n?.light)rl(e,n,{x:0,z:0,rotation:0,w:i.w,d:i.d,h:i.h},0,VM);else if(i.lamp)Jm(e,{x:0,z:0,size:[i.w,i.d,i.h],base:0,rotation:0,variant:i.variant??null,lamp:i.lamp},Math.max(i.h+.15,.6),VM);else{let r={id:"preview",type:i.type,x:0,z:0,rotation:0,w:i.w,d:i.d,h:i.h,variant:i.variant??null,entity:null,power:null};Ml(e,t,new lt,r)}}function vP(i){let e=i.getCenter(new U),t=new zn(-1,1,1,-1,.01,100);t.position.copy(e).add(new U(.9,.75,1.3).normalize().multiplyScalar(20)),t.lookAt(e),t.updateMatrixWorld();let n=.05;for(let s of[i.min.x,i.max.x])for(let o of[i.min.y,i.max.y])for(let a of[i.min.z,i.max.z]){let l=new U(s,o,a).applyMatrix4(t.matrixWorldInverse);n=Math.max(n,Math.abs(l.x),Math.abs(l.y))}let r=n*1.12;return Object.assign(t,{left:-r,right:r,top:r,bottom:-r}),t.updateProjectionMatrix(),t}function MP(i,e=180,t,n=1.3){let r=[i.type,i.w,i.d,i.h,i.variant??"",e,n].join("|"),s=zM.get(r);if(s)return s;t&&Nl(t),qo??=new kr({alpha:!0,antialias:!0,preserveDrawingBuffer:!0}),qo.setPixelRatio(Math.min(2,window.devicePixelRatio||1)),qo.setSize(e,e,!1),qo.setClearColor(0,0);let[o,a]=[new lt,new Wt];_P(i,o,a);let l=new we(o.geometry(),new Ke({vertexColors:!0,color:new W(n,n,n)})),c=new gn(a.geometry(),new Lt({vertexColors:!0,color:new W(n*1.8,n*1.8,n*1.8)})),u=new Tn;u.add(l,c),qo.render(u,vP(new Ct().setFromObject(l)));let h=qo.domElement.toDataURL("image/png");for(let f of[l,c])f.geometry.dispose(),f.material.dispose();return zM.set(r,h),h}var HM={cleaning:3662079,returning:16758087,docked:4310123,idle:5995775,error:16726863},SP=1.4,Qm=32,$e=2767456,WM=4873352,wP=1911110,jm=450,XM=125,TP=1.6,YM=3e4,$M=5,KM=360/$M,AP=new W(1714765),qM=.94;var e0=class{host;options;renderer;scene=new Tn;camera=new Jt(38,1,.1,400);controls;labels;root=new ct;patternTexture;blindTexture;openingTargets=new Map;fridges=new Map;covers=new Map;screens=new Map;pickFurniture=new Map;pickOpenings=new Map;pickOpenings2=new Map;flashes=new Map;surfaceGrab=null;surfaceDragging=!1;furnishTypes=null;roofWindows=new Map;roofWindowsKey="";persons=[];personPins=new Map;floorInfo=new Map;roomInfo=new Map;groundTexture=null;devices=[];devicePins=new Map;ground;floors=[];building=null;furnitureColors=null;notePhoto=null;floorId=null;roomId=null;wallMode="auto";painted=!1;explode;frame=0;lastFrame=0;qualityMode="auto";governor=null;disposed=!1;resizeObserver;fpsFrames=0;worstFrame=0;lastStatsFrame=0;lowQuality=!1;highQuality=!1;effectTime=0;effectTick=!1;tintTick=!1;effectTimer;awakeUntil=0;deviceLook="";haloTexture;roof=null;roofO=0;keepRoof=!1;robots=new Map;pets=new Map;petMat=null;petTimer;robotGeo=null;robotTrails=new Map;trailTimers=new Map;robotMat=null;mowerMat=null;robotLedGeo=null;robotLast=0;petLast=0;meshes=[];meshLight=null;meshAsked=new Set;robotTimer;floorStack="dim";floorMap=new Map;labelsDirty=!0;viewKey=new Float64Array(6);pinMode=new WeakMap;size={w:1,h:1};labelInset=0;effectFloors=new Set;deviceFloor=new Map;statsOn=!1;parked=new Map;parkedSig="";plain=!1;rightBack=!1;rightDown=null;gateOpen=new Map;gateSig="";orbitSpeed=0;orbitLast=0;orbitTimer;onScreen=!0;intersection=null;swipe=null;furnish=!1;selectedFurniture=null;selectedDevice=null;pendingDevice=null;labelPlacer=new Bu;pinHooks={furnishing:()=>this.furnish,pressedWhileFurnishing:e=>this.pendingDevice=e,selectWhileFurnishing:e=>{this.selectDevice(e),this.options.onDeviceSelect?.(e)},centre:e=>{let[t,n]=[e.getBoundingClientRect(),this.host.getBoundingClientRect()];return{x:t.left+t.width/2-n.left,y:t.top+t.height/2-n.top}},tap:(e,t,n)=>{let r=this.tapInRoom?this.devices.find(s=>s.id===e):void 0;if(r&&!this.deviceInReach(r.floorId,r.roomId))return this.options.onRoomTap?.(r.floorId,r.roomId);this.options.onDeviceTap?.(e,t,n)},hold:(e,t,n)=>this.options.onDeviceHold?.(e,t,n)};tapInRoom=!1;deviceGrab=null;grab=null;ghost=null;theme="neon";themeUniform={value:0};sun=null;weatherLayer;houseShadow=new Vu;sunArc=new Ku;sunArcLocation=null;shadowKey="";footprint={key:"",rings:[]};mapLayer;mapSettings=null;mapNorth=0;groundY=0;skyView=null;weatherTimer;energyLayer;soundLayer;waterLayer;glassAlpha={value:.2};screenLayer;pictureLayer;liveAnchors=[];liveAnchorCb=null;roomTint=null;houseRadius=20;startView=null;fpsStart=0;constructor(e,t={}){this.host=e,this.options=t,this.explode=t.explode??!0,this.qualityMode=t.quality??"auto",this.renderer=this.makeRenderer(this.qualityMode),this.labels=document.createElement("div"),this.labels.className="nf-labels",e.append(this.labels),this.patternTexture=EP(),this.blindTexture=RP(),this.haloTexture=PP(),this.ground=new we(new sn(1,1),new Ke({transparent:!0,blending:Ft,depthWrite:!1})),this.ground.rotation.x=-Math.PI/2,this.ground.renderOrder=-1,this.scene.add(this.ground,this.root),this.weatherLayer=new wh(this.scene),this.scene.add(this.houseShadow.mesh),this.scene.add(this.sunArc.group),this.mapLayer=new _h(this.scene),this.mapLayer.onChange=()=>this.invalidate(),this.energyLayer=new Eh(this.scene,this.liftOf),this.soundLayer=new Rh(this.scene,this.liftOf),this.waterLayer=new Ph(this.scene,this.liftOf),this.screenLayer=new Ih(this.scene,this.liftOf),this.screenLayer.onChange=()=>this.invalidate(),this.pictureLayer=new Lh(this.scene,this.liftOf),this.pictureLayer.onChange=()=>this.invalidate(),this.weatherLayer.onFlash=n=>this.host.classList.toggle("live-flash",n),this.controls=this.makeControls(),this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(e),document.addEventListener("visibilitychange",this.onVisibility),this.host.addEventListener("pointerdown",this.onTouch,{passive:!0}),this.renderer.domElement.addEventListener("pointerdown",this.onRightDown),this.renderer.domElement.addEventListener("pointerup",this.onRightUp),this.renderer.domElement.addEventListener("contextmenu",this.onContext),this.awakeUntil=performance.now()+YM,typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(n=>{let r=n.some(s=>s.isIntersecting);r!==this.onScreen&&(this.onScreen=r,r||(clearTimeout(this.effectTimer),this.effectTimer=void 0),r&&this.invalidate())}),this.intersection.observe(e)),this.resize()}get low(){return this.lowQuality}setRightBack(e){this.rightBack=e}onRightDown=e=>{this.rightDown=this.rightBack&&e.button===2?{x:e.clientX,y:e.clientY,at:performance.now()}:null};onRightUp=e=>{let t=this.rightDown;this.rightDown=null,!(!this.rightBack||!t||e.button!==2)&&Math.hypot(e.clientX-t.x,e.clientY-t.y)<6&&performance.now()-t.at<400&&this.options.onBack?.()};onContext=e=>{this.rightBack&&e.preventDefault()};setPlain(e){e!==this.plain&&(this.plain=e,this.building&&(this.rebuild(),this.invalidate()))}exportStl(e=10){let t=[];for(let n of this.floors)for(let r of[n.wallMesh,n.floorMesh]){let s=r.geometry.getAttribute("position");s&&t.push({positions:s.array,lift:n.floor.elevation})}return Ey(t,e)}setGateStates(e){let t=[...e].map(([n,r])=>`${n}=${r?1:0}`).sort().join("|");t!==this.gateSig&&(this.gateSig=t,this.gateOpen=e,this.building&&(this.rebuild(),this.invalidate()))}setParked(e){let t=[...e].map(([n,r])=>`${n}=${r}`).sort().join("|");t!==this.parkedSig&&(this.parkedSig=t,this.parked=e,this.building&&(this.rebuild(),this.invalidate()))}setStats(e){this.statsOn=e}setLabelInset(e){this.labelInset!==e&&(this.labelInset=e,this.labelsDirty=!0,this.invalidate())}setAutoOrbit(e){this.orbitSpeed=e,this.orbitLast=0,this.invalidate()}setQuality(e){this.qualityMode=e,this.swapRenderer(e)}dropToLow(){this.disposed||this.lowQuality||this.swapRenderer("low")}swapRenderer(e){let t=this.renderer.domElement,n=this.makeRenderer(e);this.rebuildTier(),this.applyTierFlags(),t.replaceWith(n.domElement),this.renderer.dispose(),this.renderer.forceContextLoss(),this.renderer=n;let{view:r,locked:s}=this.controls;this.controls.dispose(),this.controls=this.makeControls(),this.controls.view=r,this.controls.locked=s,this.resize()}setMeshSource(e){N0(e)}setPacks(e){Nl(e),this.building&&(this.rebuild(),this.invalidate())}setBuilding(e){let t=this.building===null;this.building=e,this.rebuild(),t&&this.fit(0),this.invalidate()}get walking(){return this.controls.walk!==null}startWalk(){let e=this.floors.filter(l=>l.floor.rooms.some(c=>c.points.length>=3)),t=(this.floorId?this.floorMap.get(this.floorId):void 0)??[...e].sort((l,c)=>Math.abs(l.floor.elevation)-Math.abs(c.floor.elevation))[0];if(!t||!t.bbox)return null;let n=t.floor.rooms.filter(l=>l.points.length>=3),r=n.find(l=>l.id===this.roomId)??[...n].sort((l,c)=>vr(c.points)-vr(l.points))[0],[s,o]=r?Bs(r.points):[(t.bbox.x0+t.bbox.x1)/2,(t.bbox.z0+t.bbox.z1)/2];this.floorId!==t.floor.id&&this.setFloor(t.floor.id,!1);let a=.3;return this.controls.walk={eye:new U(s,t.floor.elevation+t.ty+TP,o),yaw:this.controls.view.theta,pitch:-.05,stick:[0,0],keys:new Set,bounds:{x0:t.bbox.x0-a,x1:t.bbox.x1+a,z0:t.bbox.z0-a,z1:t.bbox.z1+a},last:0},this.labelsDirty=!0,this.wake(),t.floor.id}stopWalk(){this.controls.walk&&(this.controls.walk=null,this.labelsDirty=!0,this.fit(700))}setWalkStick(e,t){this.controls.walk&&(this.controls.walk.stick=[e,t],this.wake())}setFloor(e,t=!0){let n=this.keepCamera&&this.floorId!==null&&e!==null&&e!==this.floorId?{theta:this.controls.view.theta,phi:this.controls.view.phi,radius:this.controls.view.radius}:null;this.floorId=e,this.roomId=null,this.labelsDirty=!0,this.applyTargets(!t),this.applyHighlight(),this.fit(t?700:0,n)}setKeepCamera(e){this.keepCamera=e}setZoom(e){let t=Math.min(3,Math.max(.5,e||1));t!==this.zoom&&(this.zoom=t,this.building&&this.fit(400))}setFloorStack(e){e!==this.floorStack&&(this.floorStack=e,this.applyTargets(!1))}setKeepRoof(e){e!==this.keepRoof&&(this.keepRoof=e,this.invalidate())}setExplode(e){e!==this.explode&&(this.explode=e,this.applyTargets(!1),this.floorId===null&&this.fit(700))}selectRoom(e){if(this.roomId=e,this.labelsDirty=!0,this.applyHighlight(),!e){this.fit(700);return}let t=this.floors.find(u=>u.floor.rooms.some(h=>h.id===e)),n=t?.floor.rooms.find(u=>u.id===e);if(!t||!n)return;let r=n.start_view;if(r){let u=t.floor.elevation+t.ty,[h,f]=Bs(n.points),d=r.target??{x:h,y:.3,z:f};this.controls.flyTo({target:new U(d.x,d.y+u,d.z),radius:r.radius,phi:r.phi,theta:r.theta});return}let[s,o]=Bs(n.points),a=n.points.map(u=>u[0]),l=n.points.map(u=>u[1]),c=new U(Math.max(...a)-Math.min(...a),t.floor.cut_height,Math.max(...l)-Math.min(...l));this.controls.flyTo({target:new U(s,t.floor.elevation+t.ty+.3,o),radius:Math.max(4,this.distanceFor(c)*1.05),phi:.72})}get lowered(){return this.wallMode!=="auto"}setPaintedWalls(e){e!==this.painted&&(this.painted=e,this.rebuild(),this.invalidate())}wallPaint(e){return this.painted&&this.building?Gp(this.building.settings,e):void 0}setWallMode(e){this.wallMode=e;for(let t of this.floors)this.buildLamps(t);this.invalidate()}setDevices(e){let t=e.map(r=>`${r.id}:${r.active?1:0}:${r.glow?r.glow.level.toFixed(1):"-"}`).join(";");t!==this.deviceLook&&(this.deviceLook=t,this.wake()),this.devices=e,this.labelsDirty=!0,this.effectFloors=new Set(e.filter(r=>r.effect&&r.glow||(r.spin??0)>0).map(r=>r.floorId)),this.deviceFloor=new Map(e.map(r=>[r.id,r.floorId]));let n=new Set;for(let r of e){n.add(r.id);let s=this.devicePins.get(r.id);s||(s={el:Ay(r.id,this.pinHooks),icon:"",text:"",watt:"",label:"",active:!1,unavailable:!1,glow:"",caption:""},this.devicePins.set(r.id,s),this.labels.append(s.el));let o=s.el;s.icon!==r.icon&&(s.icon=r.icon,o.querySelector(".nf-dev-icon").innerHTML=r.icon),s.text!==r.text&&(s.text=r.text,o.querySelector(".nf-dev-text").textContent=r.text);let a=r.caption??"";s.caption!==a&&(s.caption=a,o.querySelector(".nf-dev-name").textContent=a);let l=r.power!==null&&r.power!==void 0&&r.power>=1?r.powerText??`${Math.round(r.power)} W`:"";s.watt!==l&&(s.watt=l,o.querySelector(".nf-dev-watt").textContent=l);let c=`${r.name}: ${r.text}`;s.label!==c&&(s.label=c,o.title=r.name,o.setAttribute("aria-label",c)),s.active!==r.active&&(s.active=r.active,o.classList.toggle("nf-dev-on",r.active)),s.unavailable!==r.unavailable&&(s.unavailable=r.unavailable,o.classList.toggle("nf-dev-na",r.unavailable));let u=r.glow?`rgb(${r.glow.color.map(h=>Math.round(h*255)).join(", ")})`:"";s.glow!==u&&(s.glow=u,u?o.style.setProperty("--nf-glow",u):o.style.removeProperty("--nf-glow"))}for(let[r,s]of this.devicePins)n.has(r)||(s.el.remove(),this.devicePins.delete(r));for(let r of this.floors)this.buildGlow(r),this.buildLamps(r);this.invalidate()}setRoofWindows(e){let t=JSON.stringify([...e]);t!==this.roofWindowsKey&&(this.roofWindowsKey=t,this.roofWindows=e,this.buildRoofMesh(),this.invalidate())}setPersons(e){this.labelsDirty=!0,this.persons=e;let t=new Set;for(let n of e){t.add(n.id);let r=this.personPins.get(n.id);if(r||(r=document.createElement("div"),r.className="nf-person",r.dataset.entity=n.id,this.personPins.set(n.id,r),this.labels.append(r)),r.title=n.name,r.setAttribute("aria-label",n.name),r.dataset.picture!==(n.picture??"")||r.dataset.initials!==n.initials)if(r.dataset.picture=n.picture??"",r.dataset.initials=n.initials,r.replaceChildren(),n.picture){let s=document.createElement("img");s.src=n.picture,s.alt="",s.addEventListener("error",()=>s.replaceWith(document.createTextNode(n.initials))),r.append(s)}else r.textContent=n.initials}for(let[n,r]of this.personPins)t.has(n)||(r.remove(),this.personPins.delete(n));this.invalidate()}setNavigationLocked(e){this.controls.locked=e}setPickTargets(e,t,n=new Map){this.pickFurniture=e,this.pickOpenings=t,this.pickOpenings2=n}setNotePhotos(e){this.notePhoto=e}setFurnitureColors(e){JSON.stringify(e??{})!==JSON.stringify(this.furnitureColors??{})&&(this.furnitureColors=e,this.building&&(this.rebuild(),this.invalidate()))}setAccent(e){let t=wy(e),n=t?1:0;n===Yu.value&&(!t||Xu.value.equals(new U(...t)))||(Yu.value=n,t&&Xu.value.set(...t),this.invalidate())}setTheme(e){if(e===this.theme)return;this.theme=e,this.placeMap(),this.themeUniform.value=Sy(e);let t=xl(e),n=[...this.floors.map(r=>r.materials.lines),...this.roof?[this.roof.lines]:[]];for(let r of n)r.blending=t,r.needsUpdate=!0;this.placeGround(),this.invalidate()}setFurnishMode(e){this.furnish=e,e||this.selectFurniture(null),this.invalidate()}selectFurniture(e){e&&this.selectedDevice&&this.selectDevice(null),this.selectedFurniture=e,this.updateGhost(),this.invalidate()}setSun(e){this.sun=e;for(let t of this.floors)this.buildSun(t);this.buildHouseShadow(),this.buildSunArc(),this.invalidate()}setLocation(e){this.sunArcLocation=e,this.buildSunArc(),this.invalidate()}buildSunArc(){let e=this.building,t=this.sunArcLocation,n=(e?.floors??[]).flatMap(c=>[...c.rooms.flatMap(u=>u.points),...(c.outdoor??[]).flatMap(u=>u.points)]);if(!e||!e.settings.sun_arc||!t||!n.length)return void this.sunArc.update(null,null,0);let r=n.map(c=>c[0]),s=n.map(c=>c[1]),o=[(Math.min(...r)+Math.max(...r))/2,(Math.min(...s)+Math.max(...s))/2],a=Math.max(6,Math.hypot(Math.max(...r)-Math.min(...r),Math.max(...s)-Math.min(...s))/2+3),l=Math.min(0,...e.floors.map(c=>c.elevation));this.sunArc.update({centre:o,radius:a,north:e.settings.north??0,...t},this.sun,l)}buildHouseShadow(){if(!this.houseShadow)return;let e=this.building,t=(e?.floors??[]).filter(u=>u.elevation>=-.01&&u.rooms.length),n=!e||!t.length||e.settings.sun_patches===!1||this.lowQuality,r=this.weatherLayer?.cloud??0,s=e?.settings.north??0,o=t.map(u=>`${u.elevation}:${u.height}:${JSON.stringify(u.rooms.map(h=>h.points))}`).join("|"),a=n?"off":`${this.sun?.elevation.toFixed(1)},${this.sun?.azimuth.toFixed(1)},${s},${r.toFixed(2)},${o}`;if(a===this.shadowKey)return;if(this.shadowKey=a,n){this.houseShadow.update([],0,0,null,0,0,!0);return}let l=Math.min(...t.map(u=>u.elevation)),c=Math.max(...t.map(u=>u.elevation+u.height));this.footprint.key!==o&&(this.footprint={key:o,rings:fr(t.flatMap(u=>u.rooms.map(h=>h.points)))}),this.houseShadow.update(this.footprint.rings,c-l,l+.03,this.sun,s,r,!1)}liftOf=e=>{if(!e)return{y:0,dy:0,visible:!0};let t=this.floorMap.get(e);return t?{y:t.floor.elevation+t.y,dy:t.y,visible:t.group.visible}:{y:0,dy:0,visible:!1}};setLiveEnergy(e,t){this.energyLayer.setArcs(e),this.energyLayer.setSparks(t),this.invalidate()}setLiveSound(e,t){this.soundLayer.set(e,t),this.invalidate()}setGlassWalls(e){let t=Math.min(1,Math.max(0,e));t!==this.glassAlpha.value&&(this.glassAlpha.value=t,this.invalidate())}setLiveWater(e){this.waterLayer.set(e),this.invalidate()}setLiveScreens(e){let t=[];for(let n of e){let r=this.building?.floors.find(a=>a.id===n.floorId),s=r?.furniture.find(a=>a.id===n.furnitureId),o=s&&r?th(s,r):null;!s||!o||t.push({...n,x:s.x,z:s.z,rotation:s.rotation,rect:o})}this.screenLayer.set(t),this.invalidate()}setPictures(e){let t=[];for(let n of e){let r=this.building?.floors.find(a=>a.id===n.floorId),s=r?.furniture.find(a=>a.id===n.furnitureId),o=s&&r?Sp(s,r):null;!s||!o||t.push({id:n.furnitureId,floorId:n.floorId,url:n.url,border:n.border,fit:n.fit,x:s.x,z:s.z,rotation:s.rotation,rect:o})}this.pictureLayer.set(t),this.invalidate()}setLiveAnchors(e,t){this.liveAnchors=e,this.liveAnchorCb=t,this.invalidate()}placeLhAnchors(){let e=this.liveAnchorCb;if(!e||!this.liveAnchors.length)return;let t=new U;this.liveAnchors.forEach((n,r)=>{let s=this.liftOf(n.floorId);t.set(n.x,s.y+n.y,n.z).project(this.camera);let o=s.visible&&t.z<1&&Math.abs(t.x)<1.15&&Math.abs(t.y)<1.15;e(r,(t.x+1)/2*this.size.w,(1-t.y)/2*this.size.h,o)})}setSky(e){this.skyView=e,this.weatherLayer.set(e?{...e,low:e.low||this.lowQuality}:null),this.buildHouseShadow();for(let t of this.floors)this.buildSun(t);this.invalidate()}setRoomTint(e){let t=!!e!=!!this.roomTint;if(this.roomTint=e,this.tintTick=!0,this.applyHighlight(),t)for(let n of this.floors)n.glowSig="",this.buildGlow(n)}setScreens(e){this.screens=e;for(let t of this.floors)this.buildScreens(t);this.invalidate()}fillRoomPin(e,t,n){if(e.textContent=t||"\u2013",n){let r=document.createElement("small");r.textContent=n,e.append(r),e.classList.add("nf-pin-info")}else e.classList.remove("nf-pin-info")}setRoomInfo(e){if(!(e.size===this.roomInfo.size&&[...e].every(([n,r])=>this.roomInfo.get(n)===r))){this.roomInfo=e;for(let n of this.floors)for(let r of n.roomPins)this.fillRoomPin(r.pin,r.room.name,e.get(r.room.id))}}setFloorInfo(e){this.floorInfo=e;for(let t of this.floors){let n=t.label.querySelector("span"),r=e.get(t.floor.id)??this.options.floorInfo?.(t.floor)??"";n&&n.textContent!==r&&(n.textContent=r,t.labelSize=null,this.labelsDirty=!0)}this.invalidate()}setOpeningStates(e){let t=this.openingTargets;this.openingTargets=e,[...e].some(([n,r])=>!tp(t.get(n)??Ns,r))&&this.wake(),this.invalidate()}wake(){this.awakeUntil=performance.now()+YM,this.invalidate()}get resting(){return this.lowQuality&&performance.now()>this.awakeUntil}setFridgeDoors(e){for(let[t,n]of e){let r=this.fridges.get(t)??{l:n.left?1:0,r:n.right?1:0,tl:0,tr:0};r.tl=n.left?1:0,r.tr=n.right?1:0,this.fridges.set(t,r)}for(let t of[...this.fridges.keys()])e.has(t)||this.fridges.delete(t);this.invalidate()}setCovers(e){let t=!1;for(let[n,r]of e){let s=this.covers.get(n);s?s.t!==r&&(s.t=r,t=!0):(this.covers.set(n,{k:r,t:r}),t=!0)}for(let n of[...this.covers.keys()])e.has(n)||this.covers.delete(n);if(t){for(let n of this.floors)this.buildFridges(n);this.wake()}}stepCovers(e){let t=Math.min(1,e/4e3),n=!1;for(let r of this.covers.values()){if(r.k===r.t)continue;let s=r.t-r.k;r.k=Math.abs(s)<=t?r.t:r.k+Math.sign(s)*t,n=!0}if(n)for(let r of this.floors)this.buildFridges(r);return n}stepFridges(e){let t=ep(e),n=new Set;for(let[r,s]of this.fridges)for(let[o,a]of[["l","tl"],["r","tr"]]){let l=s[a]-s[o];if(Math.abs(l)<.004){l!==0&&(s[o]=s[a],n.add(r));continue}s[o]+=l*t,n.add(r)}if(!n.size)return!1;for(let r of this.floors)r.floor.furniture.some(s=>n.has(s.id))&&this.buildFridges(r);return!0}buildFridges(e){let t=new lt;for(let n of e.floor.furniture){let r=vt(n.type);if(r&&P0(r)){Gd(t,r,n,Gt(e.floor,n),this.covers.get(n.id)?.k??I0(r,null));continue}if(n.type!=="fridge_smart")continue;let s=this.fridges.get(n.id);vp(t,n,Gt(e.floor,n),s?.l??0,s?.r??0)}e.fridgeMesh.geometry.dispose(),e.fridgeMesh.geometry=t.geometry(),e.fridgeMesh.visible=t.count>0}resetView(){this.fit(700)}setStartView(e){this.startView=e}currentView(){let e=this.controls.view,t=this.floorBase(this.floorId);return{theta:e.theta,phi:e.phi,radius:e.radius,target:{x:e.target.x,y:e.target.y-t,z:e.target.z}}}floorBase(e){let t=e===null?void 0:this.floorMap.get(e);return t?t.floor.elevation+t.ty:0}dispose(){this.disposed=!0,cancelAnimationFrame(this.frame),clearTimeout(this.effectTimer),clearTimeout(this.robotTimer),clearTimeout(this.orbitTimer),clearTimeout(this.weatherTimer),this.weatherLayer.dispose(),this.sunArc?.dispose(),this.houseShadow?.dispose(),this.mapLayer.dispose(),this.energyLayer.dispose(),this.soundLayer.dispose(),this.waterLayer.dispose(),this.screenLayer.dispose(),this.pictureLayer.dispose(),this.resizeObserver.disconnect(),this.intersection?.disconnect(),document.removeEventListener("visibilitychange",this.onVisibility),this.host?.removeEventListener("pointerdown",this.onTouch),this.renderer?.domElement?.removeEventListener?.("pointerdown",this.onRightDown),this.renderer?.domElement?.removeEventListener?.("pointerup",this.onRightUp),this.renderer?.domElement?.removeEventListener?.("contextmenu",this.onContext),clearTimeout(this.petTimer),this.controls.dispose(),this.clear(),this.building=null,this.buildRoofMesh(),this.ground.geometry.dispose(),this.ground.material.dispose(),this.patternTexture.dispose(),this.blindTexture.dispose(),this.groundTexture?.dispose(),this.haloTexture.dispose();for(let e of this.robots.values())e.led.dispose();this.robots.clear();for(let e of this.robotTrails.values())e.removeFromParent(),e.geometry.dispose(),e.material.dispose();this.robotTrails.clear();for(let e of this.trailTimers.values())clearTimeout(e);this.trailTimers.clear(),this.robotGeo?.dispose(),this.robotLedGeo?.dispose(),this.robotMat?.dispose(),this.mowerMat?.dispose(),this.meshLight?.dispose(),this.renderer.dispose(),this.renderer.forceContextLoss(),this.renderer.domElement.remove(),this.labels.remove()}invalidate(){this.frame||this.disposed||document.hidden||!this.onScreen||(this.frame=requestAnimationFrame(e=>this.render(e)))}makeRenderer(e){let t=e==="low"||e==="auto"&&xb();this.lowQuality=t,this.weatherLayer&&this.skyView&&this.weatherLayer.set({...this.skyView,low:this.skyView.low||t}),this.weatherLayer&&this.buildHouseShadow(),this.highQuality=e==="high";let n=new kr({antialias:!t,alpha:!0,powerPreference:t?"low-power":"default"}),r=Math.min(window.devicePixelRatio||1,t?1:e==="high"?2.5:2);return n.setPixelRatio(r),this.governor=e==="auto"&&!t?new Lu(r,Math.min(1,r)):null,n.setClearColor(0,0),n.outputColorSpace=ft,n.domElement.className="nf-canvas",this.host.prepend(n.domElement),n}makeControls(){return new El(this.renderer.domElement,this.camera,{change:()=>this.wake(),tap:(e,t)=>this.onTap(e,t),hold:(e,t)=>this.onHold(e,t),swipeStart:(e,t,n,r)=>this.swipeStart(e,t,n,r),swipeMove:e=>this.swipe&&this.options.onDeviceSwipe?.(this.swipe.entity,"move",e,this.swipe.x,this.swipe.y),swipeEnd:()=>{this.swipe&&this.options.onDeviceSwipe?.(this.swipe.entity,"end",0,this.swipe.x,this.swipe.y),this.swipe=null},grab:(e,t)=>this.grabFurniture(e,t),drag:(e,t)=>this.dragFurniture(e,t),drop:()=>this.dropFurniture(),doubleTap:(e,t)=>{let n=this.floorId&&this.options.onRoomDoubleTap?this.pick(e,t):null;n&&!("entity"in n)&&n.roomId?this.options.onRoomDoubleTap(n.floorId,n.roomId):this.options.onBack?.()}})}onTouch=()=>this.wake();onVisibility=()=>{document.hidden&&(clearTimeout(this.effectTimer),this.effectTimer=void 0),document.hidden||this.invalidate()};scheduleEffects(){if(!this.hasVisibleEffects(document.hidden)||this.resting){clearTimeout(this.effectTimer),this.effectTimer=void 0;return}if(this.effectTimer!==void 0)return;let e=this.lowQuality?2*XM:XM;this.effectTimer=setTimeout(()=>{if(this.effectTimer=void 0,!!this.hasVisibleEffects(document.hidden)){this.effectTime=performance.now()/1e3,this.effectTick=!0;for(let t of this.floors)t.o<.02||!this.effectFloors.has(t.floor.id)||(this.buildLamps(t),this.buildGlow(t));this.invalidate()}},e)}hasVisibleEffects(e){return!e&&!this.disposed&&this.onScreen&&this.floors.some(t=>t.o>=.02&&this.effectFloors.has(t.floor.id))}resize(){let e=this.host.clientWidth||1,t=this.host.clientHeight||1;this.size={w:e,h:t},this.labelsDirty=!0,this.renderer.setSize(e,t,!1),this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.invalidate()}clear(){for(let e of this.robots.values())e.group.removeFromParent();for(let e of this.meshes)e.group.removeFromParent(),Rm(e.group);this.meshes=[];for(let e of this.floors){e.group.traverse(t=>{t.geometry?.dispose()});for(let t of Object.values(e.materials))Array.isArray(t)||t.dispose();for(let t of e.materials.ghosts)t.material.dispose();this.root.remove(e.group)}this.floors=[],this.floorMap=new Map;for(let e of[...this.labels.children])e.dataset.entity||e.remove()}buildLightSurface(e){let t=this.lowQuality?.5:.25,n=ap(e.floor,e.geo.walls2d,e.geo.wallBuckets,e.geo.openings,t,e.geo.holes,e.geo.roofUnder),r=CP(e.floor,e.geo.openRooms);if(e.lightZones=r.some((a,l)=>a!==l)?r:null,e.lightZones){for(let a=0;a<n.room.length;a++){let l=n.room[a];l>=0&&l<r.length&&(n.room[a]=r[l])}for(let a of n.doors)a.a>=0&&a.a<r.length&&(a.a=r[a.a]),a.b>=0&&a.b<r.length&&(a.b=r[a.b])}e.lightSurface=n;let s=new Fe;s.setAttribute("position",new ke(n.pos,3)),s.setAttribute("color",new ke(new Float32Array(n.pos.length),3)),s.setAttribute("fold",new ke(n.fold,1));let o=new cs(new Uint32Array(n.pos.length/3),1);o.setUsage(ed),s.setIndex(o),s.setDrawRange(0,0),s.computeBoundingSphere(),e.glowMesh.geometry.dispose(),e.glowMesh.geometry=s,e.glowSig="",this.buildGlow(e)}buildGlow(e){let t=e.lightSurface;if(!t)return;let n=vy(e.floor,e.lightZones,this.devices,h=>this.glowOf(h)),r=t.doors.map(h=>{let f=e.geo.openings.find(p=>p.opening.id===h.id);if(f&&_r(f.opening,f.exterior)==="passage")return 1;let d=e.openings.get(h.id);return d?Math.max(d.open,d.open2??0):.5}),s=n.map(h=>`${h.x.toFixed(2)},${h.y.toFixed(2)},${h.z.toFixed(2)},${h.kind},${h.level.toFixed(3)},${h.color.map(f=>f.toFixed(3)).join("/")}`).join(";")+"|"+r.map(h=>h.toFixed(1)).join(",");if(s===e.glowSig)return;e.glowSig=s;let o=e.glowMesh.geometry,a=o.getAttribute("color");if(!n.length){e.glowMesh.visible=!1,o.setDrawRange(0,0);return}let l=lp(t,n,.42,r);if(this.roomTint){let h=e.floor.rooms.length;for(let f=0;f<t.room.length;f++)if(t.room[f]!==h)for(let d=0;d<3;d++)l[f*3+d]*=.12}a.array.set(l),a.needsUpdate=!0;let c=o.index.array,u=0;for(let h=0;h<l.length/18;h++){let f=!1;for(let d=h*18;d<h*18+18&&!f;d++)f=l[d]>.004;if(f)for(let d=0;d<6;d++)c[u++]=h*6+d}o.index.needsUpdate=!0,o.setDrawRange(0,u),e.glowMesh.visible=u>0}withoutFurniture(e){if(this.gateOpen.size&&(e.outdoor??[]).some(n=>n.gates?.length)&&(e={...e,outdoor:e.outdoor.map(n=>n.gates?.length?{...n,gates:n.gates.map(r=>({...r,open:this.gateOpen.get(r.id)??!1}))}:n)}),!this.plain)return e;let t=n=>n.type==="stairs"||n.type==="stairwell"||!!vt(n.type)?.hole;return{...e,furniture:e.furniture.filter(t)}}rebuild(){let e=new Map(this.floors.map(s=>[s.floor.id,{y:s.y,o:s.o}])),t=new Map(this.floors.map(s=>[s.floor.id,s.openings]));this.clear();let n=this.building;if(!n)return;fb({...n.settings.furniture_colors,...this.furnitureColors});let r=[...n.floors].sort((s,o)=>s.elevation-o.elevation);for(let s of n.floors){let o=n.settings.roof?.solar??[],a=ih(n)?.id===s.id?o.filter(V=>V.face===Sl).map(V=>({field:V,face:rh(n,V)})):[],l=o.filter(V=>V.face.startsWith(`wall:${s.id}:`));if(l.length){let V=new Map(nh(n,s.id).map(re=>[re.key,re]));for(let re of l){let be=V.get(re.face);be&&a.push({field:re,face:be})}}let u=(n.settings.roof.sections??[]).some(V=>$d(V,s.elevation+s.height))?(V,re)=>{let be=Kd(n,V,re);return be===null?null:be-s.elevation}:void 0,h=Hp(this.withoutFurniture(bh(s,this.parked)),n.settings.wall_exterior,n.settings.wall_interior,Wp(n.floors,s),a,u,this.wallPaint(s)),f={standing:{value:65535},glass:{value:0},slope:{value:new _t},slopeY:{value:new De},glassAlpha:this.glassAlpha},d=Ty({mask:f,look:this.themeUniform,theme:this.theme,textures:{pattern:this.patternTexture,blinds:this.blindTexture,halo:this.haloTexture}}),p=new ct,x=new we(h.floor,d.floor),g=new we(h.shadow,d.shadow);g.renderOrder=1;let m=new we(h.floor,d.pattern);m.renderOrder=2;let b=new we(new Fe,d.glow);b.renderOrder=3,b.visible=!1;let v=new we(new Fe,d.frames),y=new we(new Fe,d.blinds),M=new we(new Fe,d.glass);M.renderOrder=4;let S=new we(new Fe,d.lamps);S.visible=!1;let _=new we(new Fe,d.cones);_.visible=!1,_.renderOrder=3;let w=new xn(new Fe,d.halos);w.visible=!1,w.renderOrder=7;let R=new we(new Fe,d.cones);R.visible=!1,R.renderOrder=7;let A=new we(new Fe,d.lamps);A.visible=!1;let C=new we(new Fe,d.screens);C.visible=!1,C.renderOrder=5;for(let V of[v,y,M])V.frustumCulled=!1;let O=new we(h.walls,d.glassWall),D=new we(h.walls,d.wall);O.renderOrder=6,p.add(x,g,m,b,D,new gn(h.lines,d.lines),v,y,M,S,_,w,R,A,C,O);for(let V of h.ghosts){let re=Zn(new Ke({vertexColors:!0,transparent:!0,opacity:V.opacity,depthWrite:!1,side:ut}),this.themeUniform);d.ghosts.push({material:re,base:V.opacity});let be=new we(V.geometry,re);be.renderOrder=2,p.add(be)}this.root.add(p);let P=document.createElement("button");P.className="nf-pin nf-pin-floor",P.dataset.floor=s.id;let I=document.createElement("b");I.textContent=s.name||"\u2013";let N=document.createElement("span");N.textContent=this.floorInfo.get(s.id)??this.options.floorInfo?.(s)??"",P.append(I,N),P.addEventListener("click",()=>this.options.onFloorTap?.(s.id)),this.labels.append(P);let F=e.get(s.id),H=[],B=null;for(let V of s.rooms){let re=document.createElement("button");re.className="nf-pin",re.dataset.room=V.id,re.dataset.floor=s.id,this.fillRoomPin(re,V.name,this.roomInfo.get(V.id)),re.addEventListener("click",()=>this.options.onRoomTap?.(s.id,V.id)),this.labels.append(re);let[be,Y]=Bs(V.points);H.push({pin:re,room:V,cx:be,cz:Y});for(let[Q,se]of V.points)B??={x0:Q,x1:Q,z0:se,z1:se},B.x0=Math.min(B.x0,Q),B.x1=Math.max(B.x1,Q),B.z0=Math.min(B.z0,se),B.z1=Math.max(B.z1,se)}let X=[];for(let V of s.notes??[]){if(!V.text)continue;let re=document.createElement("button");re.className=`nf-pin nf-note-pin${d0(V)?" nf-note-due":""}`,re.title=V.text;let be=V.text.length>28?`${V.text.slice(0,27)}\u2026`:V.text;re.textContent=`${V.photo?"\u{1F4F7} ":"\u270E "}${be}`,re.addEventListener("click",()=>{let Y=re.classList.toggle("nf-note-open");re.textContent=`${V.photo?"\u{1F4F7} ":"\u270E "}${Y?V.text:be}`;let Q=Y&&V.photo?this.notePhoto?.(V.photo):null;if(Q){let se=document.createElement("img");se.className="nf-note-photo",se.alt="",se.src=Q,se.addEventListener("load",()=>{this.labelsDirty=!0,this.invalidate()}),re.append(se)}this.labelsDirty=!0,this.invalidate()}),this.labels.append(re),X.push({pin:re,note:V})}this.floors.push({floor:s,rank:r.indexOf(s),group:p,geo:h,floorMesh:x,shadowMesh:g,patternMesh:m,glowMesh:b,lightSurface:null,lightZones:null,framesMesh:v,glassMesh:M,blindsMesh:y,lampMesh:S,sunMesh:_,sunSig:"",haloMesh:w,coneMesh:R,wedgeTris:[],fridgeMesh:A,lampTris:[],lampFurnTris:[],frameTris:[],glassTris:[],blindTris:[],wallMesh:D,screenMesh:C,screenSig:"",flowLayout:"",glowSig:"",lampShapeSig:"",lampColorSig:"",lampShade:new Float32Array(0),lampRanges:new Map,bbox:B,roomPins:H,notePins:X,labelSize:null,materials:d,mask:f,openings:new Map,y:F?.y??0,o:F?.o??1,ty:0,to:1,appliedO:-1,label:P})}this.floorMap=new Map(this.floors.map(s=>[s.floor.id,s])),this.buildPets();for(let s of this.floors)this.buildFridges(s);this.labelsDirty=!0,this.floorId&&!n.floors.some(s=>s.id===this.floorId)&&(this.floorId=null);for(let s of this.floors){this.buildLamps(s),this.buildScreens(s);let o=t.get(s.floor.id);for(let a of s.geo.openings)s.openings.set(a.opening.id,o?.get(a.opening.id)??this.openingTargets.get(a.opening.id)??Ns);this.buildOpenings(s),this.buildLightSurface(s),this.buildSun(s)}this.applyTargets(e.size===0),this.applyHighlight(),this.applyTierFlags(),this.buildRoofMesh(),this.updateGhost(),this.placeMeshes()}placeMeshes(){for(let e of this.meshes)e.group.removeFromParent(),Rm(e.group);this.meshes=[];for(let e of this.floors)for(let t of bh(e.floor,this.parked).furniture){let n=vt(t.type);if(!n?.mesh)continue;let r=n.mesh;if(!Dl(t.type)){this.meshAsked.has(r)||(this.meshAsked.add(r),yM(r).then(a=>{a&&!this.disposed&&this.rebuild()}));continue}let s=n.colors?.length?(n.colors.find(a=>a.id===t.variant)??n.colors[0]).hex:null,o=_M(r,{x:t.x,z:t.z,y:Gt(e.floor,t),rotation:t.rotation,mirror:t.mirror,w:t.w,d:t.d,h:t.h,paint:s});o&&(this.meshLight||(this.meshLight=vM(this.root,this.renderer)),MM(o,this.meshLight.env),e.group.add(o),this.meshes.push({group:o,furnitureId:t.id}))}this.invalidate()}buildRoofMesh(){this.roof&&(this.roof.group.traverse(a=>a.geometry?.dispose()),this.roof.solid.dispose(),this.roof.lines.dispose(),this.roof.glass.dispose(),this.scene.remove(this.roof.group),this.roof=null);let e=this.building?kp(this.building,this.roofWindows):[];if(!e.length)return;let t=new ct,n=Zn(new Ke({vertexColors:!0,transparent:!0,side:ut}),this.themeUniform),r=Zn(new Lt({vertexColors:!0,transparent:!0,blending:xl(this.theme),depthWrite:!1}),this.themeUniform,!0),s=Zn(new Ke({vertexColors:!0,transparent:!0,side:ut,depthWrite:!1}),this.themeUniform),o=e.map(a=>{let l=new ct;return l.add(new we(a.solid.geometry(),n),new gn(a.lines.geometry(),r)),a.glass.count&&l.add(new we(a.glass.geometry(),s)),l.renderOrder=8,t.add(l),{group:l,floorId:a.floor.id,rideId:Jd(this.building,a.floor,a.sections??[]),base:a.base,lift:a.lift!==!1}});t.renderOrder=8,this.scene.add(t),this.roof={group:t,parts:o,solid:n,lines:r,glass:s},this.placeRoof()}placeRoof(e=1e3){let t=this.roof;if(!t)return!1;let n=this.keepRoof?1:Math.min(1,Math.max(0,(this.controls.view.radius/this.houseRadius-.62)/.3)),s=(this.floorId===null||this.floors.length===1)&&!this.lowered?qM*n:0,o=Qd(e),a=this.roofO;this.roofO+=(s-this.roofO)*o,Math.abs(s-this.roofO)<.004&&(this.roofO=s),t.group.visible=this.roofO>.02;for(let l of t.parts){let c=this.floorMap.get(l.floorId);if(!c)continue;let u=this.floorMap.get(l.rideId)??c,h=u.ty>0?Math.min(1,u.y/u.ty):this.explode&&this.floorId===null?1:0,f=Math.max(0,1-this.roofO/qM);l.group.position.y=c.floor.elevation+u.y+l.base+f*2.2+(l.lift?h*SP:0)}return t.solid.opacity=this.roofO,t.solid.depthWrite=this.roofO>.5,t.lines.opacity=this.roofO,t.glass.opacity=this.roofO*.28,this.roofO!==a&&this.roofO!==s}applyTierFlags(){let e=this.lowQuality;this.ground.visible=!e&&this.theme!=="day"&&this.floors.some(t=>t.floor.rooms.length>0);for(let t of this.floors)t.patternMesh.visible=!e,t.shadowMesh.visible=!e&&t.o>.98;this.invalidate()}rebuildTier(){for(let e of this.floors)e.flowLayout="",this.buildLightSurface(e),e.lampShapeSig="",this.buildLamps(e)}get houseView(){return this.floorId===null&&this.floors.length>1}applyTargets(e){let t=this.floorId?this.floorMap.get(this.floorId):void 0;for(let n of this.floors){let r=Vb(n.rank,t?.rank,this.explode,this.floorStack);[n.ty,n.to]=[r.y,r.opacity],e&&([n.y,n.o]=[r.y,r.opacity]),this.applyFloor(n)}this.invalidate()}applyFloor(e){e.group.position.y=e.floor.elevation+e.y,e.group.visible=e.o>.02,e.shadowMesh.visible=e.o>.98&&!this.lowQuality,!(Math.abs(e.appliedO-e.o)<.001)&&(e.appliedO=e.o,Hb(e.materials,e.o))}stepFloors(e){let t=!1,n=Qd(e);for(let r of this.floors){let s=Gb(r,n);s.settled&&(this.labelsDirty=!0),(s.moving||s.settled)&&this.applyFloor(r),t||=s.moving}return t}stepOpenings(e){let t=!1,n=ep(e);for(let r of this.floors){let s=!1;for(let[o,a]of r.openings){let l=this.openingTargets.get(o)??Ns;if(tp(a,l))continue;let c=Yb(a,l,n);r.openings.set(o,c.state),s=!0,t||=c.moving}s&&(this.buildOpenings(r),this.buildGlow(r),this.buildSun(r))}return t}fanPhase(e){return e.lamp!=="fan"||!e.spin?0:Math.round(this.effectTime*e.spin*360%KM*10)/10}glowOf(e){return Lv(e.glow,e.effect,this.effectTime)}buildLamps(e){let t=performance.now(),n=h=>{let f=this.flashes.get(h);if(!f||f<=t)return 0;let d=f-t,p=d>jm?.5+.5*Math.sin(d/140):d/jm;return Math.round(p*10)/10},r=this.devices.filter(h=>h.floorId===e.floor.id&&h.lamp),s=this.wallMode+(this.lowQuality?"L":this.highQuality?"H":"M")+r.map(h=>`${h.id},${h.lamp},${h.variant},${h.x},${h.z},${h.y},${h.rotation??0},${h.roll??0},${h.upright?1:0},${h.rise??0},${h.size?.join("/")},${h.base??0},${h.pack??""},${h.mirror?1:0},${h.ceiling??""},${this.fanPhase(h)}`).join(";"),o=r.map(h=>this.glowOf(h)),a=this.devices.filter(h=>h.floorId===e.floor.id&&h.wedge),l=r.map((h,f)=>`${n(h.id)},${o[f]?`${o[f].level.toFixed(3)},${o[f].color.map(d=>d.toFixed(3)).join("/")}`:"off"}`).join(";")+"|"+a.map(h=>`${h.id},${h.x},${h.z},${h.rotation??0},${JSON.stringify(h.wedge)}`).join(";");if(s!==e.lampShapeSig||!e.lampMesh.geometry.getAttribute("position")){e.lampShapeSig=s,e.lampColorSig="";let h=new lt,f=[],d=[],p=new Map,x=e.floor.height;for(let g of r){let m=g.lamp==="strip"?(g.base??x)>Math.min(e.floor.cut_height,g.ceiling??x):g.lamp?ku.has(g.lamp):!1;if(!g.lamp||m&&this.lowered)continue;let b=h.count,v=g.pack?vt(g.pack):void 0,[y,M,S]=g.size??[.3,.3,.3];v?rl(h,v,{x:g.x,z:g.z,rotation:g.rotation??0,w:y,d:M,h:S,mirror:g.mirror},g.base??0,65280):Jm(h,{...g,lamp:g.lamp,phase:this.fanPhase(g)},g.ceiling??x,65280),p.set(g.furnitureId??g.id,{start:b,end:h.count}),g.pickable!==!1&&f.push({id:g.id,start:b,end:h.count}),g.furnitureId&&d.push({id:g.furnitureId,start:b,end:h.count})}e.lampTris=f,e.lampFurnTris=d,e.lampRanges=p,e.lampShade=bb(h.c),e.lampMesh.geometry.dispose(),e.lampMesh.geometry=h.geometry(),e.lampMesh.visible=h.count>0}if(l===e.lampColorSig)return;e.lampColorSig=l;let c=e.lampMesh.geometry.getAttribute("color"),u=c.array;r.forEach((h,f)=>{let d=e.lampRanges.get(h.furnitureId??h.id);if(!d)return;let p=o[f],x=p?.55+.45*p.level:0,g=p?new W(...p.color.map(v=>Math.min(1,v*x))):new W(wP),m=n(h.id);m>0&&g.lerp(new W(1,1,1),.7*m);let b=new W(g.getHex());yb(u,e.lampShade,d,[b.r,b.g,b.b])}),c.needsUpdate=!0,this.buildHalos(e)}buildSun(e){let t=this.building?.settings.sun_patches===!1?null:this.sun,n=this.building?.settings.north??0,r=this.weatherLayer?.cloud??0,s=iy(t,n,r,e.openings.values());if(s===e.sunSig)return;e.sunSig=s;let o=ry({floor:e.floor,openings:e.geo.openings,states:e.openings,sun:t,northDegrees:n,cloud:r});e.sunMesh.geometry.dispose(),e.sunMesh.geometry=o.geometry(),e.sunMesh.visible=o.count>0}buildHalos(e){let t={positions:[],colours:[]},n=new lt,r=[];for(let a of this.devices)if(a.floorId===e.floor.id&&a.wedge){let l=Jb(n,a,e.geo.walls2d);a.wedge.through||r.push({id:a.id,...l})}e.wedgeTris=r;let s=this.lowered;for(let a of this.lowQuality?[]:this.devices){let l=this.glowOf(a);if(a.floorId!==e.floor.id||!a.lamp||!l||s&&ty(a.lamp))continue;let c=a;Qb(t,c,l,a.ceiling??e.floor.height),this.highQuality&&(a.lamp==="downlight"||a.lamp==="spot")&&ey(n,c,l,a.ceiling??e.floor.height)}let o=new Fe;o.setAttribute("position",new ke(t.positions,3)),o.setAttribute("color",new ke(t.colours,3)),e.haloMesh.geometry.dispose(),e.haloMesh.geometry=o,e.haloMesh.visible=!this.lowQuality&&t.positions.length>0,e.coneMesh.geometry.dispose(),e.coneMesh.geometry=n.geometry(),e.coneMesh.visible=n.count>0}buildScreens(e){let t=bh(e.floor,this.parked).furniture.filter(s=>this.screens.has(s.id)),n=t.map(s=>`${s.id}:${s.x},${s.z},${s.rotation},${s.w},${s.d},${s.h},${s.mount_y??""},${s.mirror?1:0}:${JSON.stringify(this.screens.get(s.id))}`).join(";");if(n===e.screenSig&&e.screenMesh.geometry.getAttribute("position"))return;e.screenSig=n;let r=new lt;for(let s of t){let o=this.screens.get(s.id),a=s.rotation*pt,l=Math.cos(a),c=Math.sin(a),u=(y,M,S)=>[s.x+y*l-S*c,M,s.z+y*c+S*l];if(o.gangs){let y=vt(s.type);if(!y)continue;for(let M of o.gangs){let S=new W(...M.color.map(_=>Math.min(1,_*(.45+.55*M.level))));il(r,y,s,Gt(e.floor,s),S.getHex(),_=>_.gang===M.gang)}continue}if(o.print!==void 0){let y=Gt(e.floor,s)+s.h*.2,M=Math.min(s.w,s.d)*.16,S=y+s.h*.38*Math.min(1,Math.max(0,o.print)),_=new W(...o.color.map(C=>Math.min(1,C*(.35+.65*o.level)))),w=_.clone().multiplyScalar(.7),R=[u(-M,y,-M),u(M,y,-M),u(M,y,M),u(-M,y,M)],A=[u(-M,S,-M),u(M,S,-M),u(M,S,M),u(-M,S,M)];r.tri(A[0],A[2],A[1],_),r.tri(A[0],A[3],A[2],_);for(let C=0;C<4;C++){let O=(C+1)%4;r.tri(R[C],R[O],A[O],w),r.tri(R[C],A[O],A[C],w)}continue}if(o.fill!==void 0){let y=wp(s,e.floor);if(!y)continue;let M=y.rect,S=Math.min(1,Math.max(0,o.fill)),_=new W(...o.color.map(C=>Math.min(1,C*(.35+.65*o.level)))),w=new W(.08,.1,.13),R=M.z,A=(C,O,D,P,I)=>{r.tri(u(C,D,R),u(O,D,R),u(O,P,R),I),r.tri(u(C,D,R),u(O,P,R),u(C,P,R),I)};if(y.vertical){let C=M.y0+(M.y1-M.y0)*S;S>0&&A(M.x0,M.x1,M.y0,C,_),S<1&&A(M.x0,M.x1,C,M.y1,w)}else{let C=M.x0+(M.x1-M.x0)*S;S>0&&A(M.x0,C,M.y0,M.y1,_),S<1&&A(C,M.x1,M.y0,M.y1,w)}continue}if(o.leds){let y=vt(s.type);if(!y)continue;let M=new W(...o.color.map(S=>Math.min(1,S*(.35+.65*o.level))));il(r,y,s,Gt(e.floor,s),M.getHex(),S=>!!S.glow||!!S.screen);continue}if(o.heat){let y=vt(s.type);if(!y)continue;let M=new W(...o.color.map(S=>Math.min(1,S*(.35+.65*o.level))));il(r,y,s,Gt(e.floor,s),M.getHex(),()=>!0);continue}if(o.faces){let y=Math.max(.05,s.w)*(s.mirror?-1:1),M=Math.max(.05,s.d),S=Math.max(.005,s.h),_=Gt(e.floor,s);for(let w of o.faces){let R=w.part==="right"?.03:-Math.abs(y)/2+.03,A=w.part==="left"?-.03:Math.abs(y)/2-.03,C=_+(w.part==="bottom"?S*.45:S)+.006,O=new W(...w.color.map(B=>Math.min(1,B*(.35+.65*w.level)))),D=new W(0,0,0),P=(B,X,V=C)=>u(B*Math.sign(y),V,X),I=[P(R,-M/2+.03),P(A,-M/2+.03),P(A,M/2-.03),P(R,M/2-.03)];r.tri(I[0],I[2],I[1],O),r.tri(I[0],I[3],I[2],O);let N=.12+.1*w.level,F=O.clone().multiplyScalar(.5),H=[P(R-N,-M/2-N,C+.004),P(A+N,-M/2-N,C+.004),P(A+N,M/2+N,C+.004),P(R-N,M/2+N,C+.004)];for(let B=0;B<4;B++){let X=(B+1)%4;r.tri(I[B],H[X],H[B],F,D,D),r.tri(I[B],I[X],H[X],F,F,D)}}continue}let h=th(s,e.floor);if(!h)continue;let f=new W(...o.color.map(y=>Math.min(1,y*(.35+.65*o.level)))),d=new W(0,0,0),p=h.z+.004;r.tri(u(h.x0,h.y0,p),u(h.x1,h.y0,p),u(h.x1,h.y1,p),f),r.tri(u(h.x0,h.y0,p),u(h.x1,h.y1,p),u(h.x0,h.y1,p),f);let x=Math.min(1.5,o.halo??1);if(x<=0)continue;let g=(.18+.12*o.level)*Math.min(1,x),m=f.clone().multiplyScalar(.5*x),b=[u(h.x0,h.y0,p),u(h.x1,h.y0,p),u(h.x1,h.y1,p),u(h.x0,h.y1,p)],v=[u(h.x0-g,h.y0-g,p+.01),u(h.x1+g,h.y0-g,p+.01),u(h.x1+g,h.y1+g,p+.01),u(h.x0-g,h.y1+g,p+.01)];for(let y=0;y<4;y++){let M=(y+1)%4;r.tri(b[y],v[y],v[M],m,d,d),r.tri(b[y],v[M],b[M],m,d,m)}}e.screenMesh.geometry.dispose(),e.screenMesh.geometry=r.geometry(),e.screenMesh.visible=r.count>0}buildOpenings(e){let t=$p(e.geo.openings,e.openings,Math.min(e.floor.cut_height,e.floor.height),-.2-e.floor.elevation);e.frameTris=t.frameTris,e.glassTris=t.glassTris,e.blindTris=t.blindTris;for(let[n,r]of[[e.framesMesh,t.frames],[e.glassMesh,t.glass],[e.blindsMesh,t.blinds]])n.geometry.dispose(),n.geometry=r,n.visible=r.getAttribute("position").count>0}activeFloors(){return this.floors.filter(e=>e.to>.99)}applyHighlight(){for(let e of this.floors){let t=e.geo.floor.getAttribute("color");for(let n of e.geo.roomTris){let r=new W(n.color),s=this.roomTint?.get(n.roomId);s&&r.lerp(new W(...s).multiplyScalar(.6),.9),n.roomId===this.roomId&&r.lerp(AP,s?.3:.75);for(let o=n.start*3;o<n.end*3;o++)t.setXYZ(o,r.r,r.g,r.b)}t.needsUpdate=!0}for(let e of this.labels.querySelectorAll(".nf-pin"))e.classList.toggle("nf-pin-active",!!e.dataset.room&&e.dataset.room===this.roomId);this.invalidate()}keepCamera=!1;zoom=1;fit(e,t=null){let n=new Ct;for(let f of this.activeFloors()){let d=f.floor.elevation+f.ty;for(let p of f.floor.rooms)for(let[x,g]of p.points)n.expandByPoint(new U(x,d,g)),n.expandByPoint(new U(x,d+f.floor.height,g))}n.isEmpty()&&n.set(new U(-4,0,-4),new U(4,2.5,4)),this.placeGround(),this.buildHouseShadow(),this.weatherLayer.setBounds({x0:n.min.x-8,x1:n.max.x+8,z0:n.min.z-8,z1:n.max.z+8,y0:n.min.y,y1:n.max.y+6});let r=n.getCenter(new U),s=n.getSize(new U),o=Math.max(8,this.distanceFor(s)*(this.camera.aspect<1?1.16:1.02));this.controls.maxRadius=Math.max(40,o*3),r.y=n.min.y+s.y*(this.houseView?.45:.3),(this.floorId===null||this.floors.length===1)&&(this.houseRadius=o);let a=this.floorId===null,l=a?null:this.floorMap.get(this.floorId)?.floor.start_view??null,c=l??this.startView,u=!!c&&(a||!!l);c&&u&&(this.controls.maxRadius=Math.max(this.controls.maxRadius,c.radius*1.5));let h=u?c.target:null;if(h&&r.set(h.x,h.y+(l?this.floorBase(this.floorId):0),h.z),t){this.controls.flyTo({target:r,radius:t.radius,phi:t.phi,theta:t.theta},e);return}this.controls.flyTo({target:r,radius:(u?c.radius:o)/this.zoom,phi:c?c.phi:.85,theta:c?c.theta:-.6},e)}placeGround(){let e=new Ct,t=1/0;for(let o of this.floors){t=Math.min(t,o.floor.elevation+Math.min(0,o.ty));for(let a of o.floor.rooms)for(let[l,c]of a.points)e.expandByPoint(new U(l,0,c));for(let a of o.floor.outdoor??[])for(let[l,c]of a.points)e.expandByPoint(new U(l,0,c))}if(this.ground.visible=!e.isEmpty()&&!this.lowQuality&&this.theme!=="day",e.isEmpty())return;if(this.ground.visible&&!this.groundTexture){this.groundTexture=IP();let o=this.ground.material;o.map=this.groundTexture,o.needsUpdate=!0}let n=e.getCenter(new U),r=e.getSize(new U),s=Qm*Math.ceil((Math.max(r.x,r.z)+16)/Qm);this.ground.scale.set(s,s,1),this.ground.position.set(n.x,t-pi-.02,n.z),this.groundY=t-pi-.04,this.placeMap()}setMap(e,t){this.mapSettings=e??null,this.mapNorth=t,this.placeMap(),this.invalidate()}placeMap(){this.mapLayer.set(this.mapSettings,this.mapNorth,this.groundY,this.theme==="day"?1:.55)}distanceFor(e){let t=this.camera.fov*pt,n=2*Math.atan(Math.tan(t/2)*this.camera.aspect);return e.length()/2/Math.sin(Math.min(t,n)/2)}rayAt(e,t){let n=this.renderer.domElement.getBoundingClientRect(),r=new Ba;return r.setFromCamera(new De(e/n.width*2-1,-(t/n.height)*2+1),this.camera),r}setTapInRoom(e){this.tapInRoom=e}deviceInReach(e,t){return!this.tapInRoom||RM({floorId:e,roomId:t},{floorId:this.floorId,roomId:this.roomId})}pickInReach(e,t){let n=this.pick(e,t);if(!this.tapInRoom||!n||!("entity"in n))return n;let r=this.pick(e,t,!1);return r&&"floorId"in r&&this.deviceInReach(r.floorId,r.roomId)?n:r}pick(e,t,n=!0){let r=this.rayAt(e,t),s=this.activeFloors();if(n&&this.meshes.length){let l=r.intersectObjects(this.meshes.map(c=>c.group),!0)[0];if(l){let c=l.object;for(;c&&!this.meshes.some(h=>h.group===c);)c=c.parent;let u=c?this.pickFurniture.get(this.meshes.find(h=>h.group===c).furnitureId):void 0;if(u)return{entity:u}}}let o=s.flatMap(l=>[l.lampMesh,l.coneMesh,l.framesMesh,l.glassMesh,l.blindsMesh,l.wallMesh,l.floorMesh].filter(c=>c.visible)),a=(l,c)=>l.find(u=>c>=u.start&&c<u.end)?.id;for(let l of r.intersectObjects(o,!1)){if(l.faceIndex==null)continue;let c=l.faceIndex,u=s.find(h=>h.group===l.object.parent);if(!(!n&&(l.object===u.lampMesh||l.object===u.coneMesh||l.object===u.framesMesh||l.object===u.blindsMesh||l.object===u.glassMesh))){if(l.object===u.lampMesh||l.object===u.coneMesh){let h=a(l.object===u.lampMesh?u.lampTris:u.wedgeTris,c);if(h)return{entity:h}}else if(l.object===u.framesMesh||l.object===u.blindsMesh||l.object===u.glassMesh){if(this.lowered&&l.face){let x=l.object.geometry.getAttribute("fold")?.getX(l.face.a)??Xe;if(x!==Xe&&Math.floor(x/16)%8===0)continue}let h=a(l.object===u.framesMesh?u.frameTris:l.object===u.glassMesh?u.glassTris:u.blindTris,c),f=h?this.pickOpenings.get(h):void 0,d=h?this.pickOpenings2.get(h):void 0,p=d?u.geo.openings.find(x=>x.opening.id===h):void 0;if(d&&p&&(l.point.x-p.start[0])*p.axis[0]+(l.point.z-p.start[1])*p.axis[1]>p.width/2&&(f=d),f)return{entity:f}}else if(l.object===u.wallMesh){let h=a(u.geo.furnitureTris,c),f=h&&n?this.pickFurniture.get(h):void 0;if(f)return{entity:f};if(l.face&&!h){let d=u.wallMesh.geometry.getAttribute("fold")?.getX(l.face.a)??32,p=Math.floor(d/16)%8,x=d%16,g=this.lowered&&p===0,m=(u.mask.glass.value&1<<x)!==0;if(!g){let b=r.ray.direction,v=Math.hypot(b.x,b.z)||1,y=[l.point.x-b.x/v*.3,l.point.z-b.z/v*.3],M=u.floor.rooms.find(S=>S.points.length>=3&&Ve(y,S.points))?.id??null;if(this.roomId!==null){if(M===this.roomId)return{floorId:u.floor.id,roomId:M}}else if(!m&&M)return{floorId:u.floor.id,roomId:M}}}}else if(l.object===u.floorMesh)return{floorId:u.floor.id,roomId:a(u.geo.roomTris.map(h=>({id:h.roomId,start:h.start,end:h.end})),c)??null}}}return null}onTap(e,t){let n=this.furnish?this.pick(e,t):this.pickInReach(e,t);if(n&&"entity"in n&&this.furnish){this.selectDevice(n.entity),this.options.onDeviceSelect?.(n.entity);return}if(n&&"entity"in n){this.flashes.set(n.entity,performance.now()+jm),this.invalidate(),this.options.onDeviceTap?.(n.entity,e,t);return}this.options.onRoomTap?.(n?.floorId??this.floorId??"",n?.roomId??null)}furnitureAt(e,t){let n=this.rayAt(e,t),r=this.activeFloors(),s=r.flatMap(o=>[o.lampMesh,o.wallMesh].filter(a=>a.visible));for(let o of n.intersectObjects(s,!1)){if(o.faceIndex==null)continue;let a=r.find(u=>u.group===o.object.parent),c=(o.object===a.lampMesh?a.lampFurnTris:a.geo.furnitureTris).find(u=>o.faceIndex>=u.start&&o.faceIndex<u.end)?.id;if(c)return{fv:a,id:c}}return null}floorPoint(e,t,n){let r=this.rayAt(t,n),s=e.floor.elevation+e.y,o=r.ray.direction;if(Math.abs(o.y)<1e-4)return null;let a=(s-r.ray.origin.y)/o.y;return a<=0?null:[r.ray.origin.x+o.x*a,r.ray.origin.z+o.z*a]}setFurnishTypes(e){this.furnishTypes=e?new Set(e):null}setSurfaceGrab(e){this.surfaceGrab=e}surfaceRay(e,t){let n=this.rayAt(e,t).ray;return{o:[n.origin.x,n.origin.y,n.origin.z],d:[n.direction.x,n.direction.y,n.direction.z]}}grabFurniture(e,t){if(this.surfaceGrab?.start(this.surfaceRay(e,t)))return this.surfaceDragging=!0,!0;if(!this.furnish)return!1;let n=this.pendingDevice;this.pendingDevice=null;let r=this.furnishTypes;if(r){let o=n?this.devices.find(h=>h.id===n)?.furnitureId:void 0,a=o?null:this.furnitureAt(e,t),l=o??a?.id,c=l?this.floors.find(h=>h.floor.furniture.some(f=>f.id===l)):void 0,u=c?.floor.furniture.find(h=>h.id===l)?.type;return!!(c&&l&&u&&r.has(u))&&this.grabItem(c,l,e,t)}if(n){let o=this.devices.find(l=>l.id===n)?.furnitureId,a=o?this.floors.find(l=>l.floor.furniture.some(c=>c.id===o)):void 0;return!o||!a?this.grabDevice(n,e,t):this.grabItem(a,o,e,t)}let s=this.furnitureAt(e,t);if(!s){let o=this.pick(e,t);return o&&"entity"in o?this.grabDevice(o.entity,e,t):(this.selectedFurniture&&(this.selectFurniture(null),this.options.onFurnitureSelect?.(null)),this.selectedDevice&&(this.selectDevice(null),this.options.onDeviceSelect?.(null)),!1)}return this.grabItem(s.fv,s.id,e,t)}grabItem(e,t,n,r){let s=e.floor.furniture.find(a=>a.id===t),o=this.floorPoint(e,n,r);return!s||!o?!1:s.locked?(this.selectFurniture(s.id),this.options.onFurnitureSelect?.(s.id),!1):(this.grab={floorId:e.floor.id,id:s.id,offset:[s.x-o[0],s.z-o[1]],x:s.x,z:s.z,moved:!1},this.selectFurniture(s.id),this.options.onFurnitureSelect?.(s.id),!0)}grabDevice(e,t,n){let r=this.devices.find(a=>a.id===e),s=r&&this.floorMap.get(r.floorId),o=s&&this.floorPoint(s,t,n);return!r||!s||!o?!1:r.fixed?(this.selectDevice(e),this.options.onDeviceSelect?.(e),!1):(this.deviceGrab={id:e,floorId:s.floor.id,offset:[r.x-o[0],r.z-o[1]],x:r.x,z:r.z,moved:!1},this.selectDevice(e),this.options.onDeviceSelect?.(e),!0)}setSelectedDevice(e){e!==this.selectedDevice&&this.selectDevice(e)}selectDevice(e){e&&this.selectedFurniture&&(this.selectFurniture(null),this.options.onFurnitureSelect?.(null)),this.selectedDevice=e;for(let[t,n]of this.devicePins)n.el.classList.toggle("nf-dev-sel",t===e)}dragFurniture(e,t){if(this.surfaceDragging){this.surfaceGrab?.move(this.surfaceRay(e,t));return}let n=this.deviceGrab;if(n){let l=this.floorMap.get(n.floorId),c=this.devices.find(f=>f.id===n.id),u=l&&this.floorPoint(l,e,t);if(!l||!c||!u)return;let h=this.building?.settings.grid??.05;n.x=c.x=Math.round((u[0]+n.offset[0])/h)*h,n.z=c.z=Math.round((u[1]+n.offset[1])/h)*h,n.moved=!0,this.labelsDirty=!0,this.invalidate();return}let r=this.grab,s=r&&this.floorMap.get(r.floorId);if(!r||!s)return;let o=this.floorPoint(s,e,t);if(!o)return;let a=this.building?.settings.grid??.05;r.x=Math.round((o[0]+r.offset[0])/a)*a,r.z=Math.round((o[1]+r.offset[1])/a)*a,r.moved=!0,this.updateGhost(),this.invalidate()}dropFurniture(){if(this.surfaceDragging){this.surfaceDragging=!1,this.surfaceGrab?.end();return}let e=this.deviceGrab;this.deviceGrab=null,e?.moved&&this.options.onDeviceMove?.(e.id,Math.round(e.x*1e3)/1e3,Math.round(e.z*1e3)/1e3);let t=this.grab;this.grab=null,t?.moved&&this.options.onFurnitureMove?.(t.id,Math.round(t.x*1e3)/1e3,Math.round(t.z*1e3)/1e3),this.updateGhost()}updateGhost(){this.ghost&&(this.ghost.geometry.dispose(),this.ghost.material.dispose(),this.scene.remove(this.ghost),this.ghost=null);let e=this.selectedFurniture,t=e?this.floors.find(m=>m.floor.furniture.some(b=>b.id===e)):void 0,n=t?.floor.furniture.find(m=>m.id===e);if(!t||!n)return;let r=this.grab?.id===n.id?this.grab.x:n.x,s=this.grab?.id===n.id?this.grab.z:n.z,o=Ol(t.floor,{...n,x:r,z:s}),a=y0.has(n.type),l=Math.max(.1,n.type==="lamp_pendant"?.3:n.h),c=vt(n.type)||n.type==="lamp_wall"||n.type==="led_strip"?Gt(t.floor,n):a?n.type==="lamp_pendant"||n.type==="ceiling_fan"?o-n.h-.1:o-l:Gt(t.floor,n),u=n.rotation*pt,h=Math.cos(u),f=Math.sin(u),d=(m,b,v)=>[r+m*h-b*f,v,s+m*f+b*h],p=new Wt,x=[[-n.w/2,-n.d/2],[n.w/2,-n.d/2],[n.w/2,n.d/2],[-n.w/2,n.d/2]],g=new W(.25,.9,1);for(let m=0;m<4;m++){let[b,v]=x[m],[y,M]=x[(m+1)%4];p.seg(d(b,v,c+.01),d(y,M,c+.01),g),p.seg(d(b,v,c+l),d(y,M,c+l),g),p.seg(d(b,v,c+.01),d(b,v,c+l),g)}p.seg(d(-n.w/2,n.d/2+.03,c+.02),d(n.w/2,n.d/2+.03,c+.02),new W(1,1,1)),this.ghost=new gn(p.geometry(),new Lt({vertexColors:!0,depthTest:!1,transparent:!0})),this.ghost.position.y=t.floor.elevation+t.y,this.ghost.renderOrder=20,this.scene.add(this.ghost)}onHold(e,t){let n=this.pick(e,t);n&&"entity"in n&&this.options.onDeviceHold?.(n.entity,e,t)}swipeStart(e,t,n,r){if(this.furnish||Math.abs(r)<Math.abs(n)*1.2)return!1;let s=this.pickInReach(e,t);return!s||!("entity"in s)||this.options.onDeviceSwipe?.(s.entity,"start",0,e,t)!==!0?!1:(this.swipe={entity:s.entity,x:e,y:t},!0)}floorThumbnails(e=200,t=150){let n=this.floors.filter(m=>m.floor.rooms.some(b=>b.points.length>=3));if(!n.length)return[];let r=this.lowQuality?1:Math.min(2,window.devicePixelRatio||1),s=Math.round(e*r),o=Math.round(t*r),a=new wn(s,o);a.texture.colorSpace=ft;let l=new zn(-1,1,1,-1,.1,400),c=this.floors.map(m=>({fv:m,visible:m.group.visible,y:m.y,o:m.o,standing:m.mask.standing.value,glass:m.mask.glass.value})),u=this.roof?.group.visible??!1,h=this.ghost?.visible??!1,f=this.renderer.getClearAlpha(),d=new Uint8Array(s*o*4),p=document.createElement("canvas");p.width=s,p.height=o;let x=p.getContext("2d"),g=[];try{this.roof&&(this.roof.group.visible=!1),this.ghost&&(this.ghost.visible=!1),this.renderer.setClearAlpha(0);for(let m of n){for(let D of this.floors)D.group.visible=D===m;m.y=0,m.o=1,this.applyFloor(m),m.group.visible=!0,m.mask.standing.value=0,m.mask.glass.value=0;let b=m.floor.rooms.flatMap(D=>D.points),v=m.floor.elevation,y=new Ct(new U(Math.min(...b.map(D=>D[0]))-.3,v,Math.min(...b.map(D=>D[1]))-.3),new U(Math.max(...b.map(D=>D[0]))+.3,v+Math.min(m.floor.cut_height,m.floor.height),Math.max(...b.map(D=>D[1]))+.3)),M=y.getCenter(new U),S=-.6,_=.8,w=new U(Math.sin(_)*Math.sin(S),Math.cos(_),Math.sin(_)*Math.cos(S));l.position.copy(M).addScaledVector(w,100),l.lookAt(M),l.updateMatrixWorld();let R=.5,A=.5;for(let D of[y.min.x,y.max.x])for(let P of[y.min.y,y.max.y])for(let I of[y.min.z,y.max.z]){let N=new U(D,P,I).applyMatrix4(l.matrixWorldInverse);R=Math.max(R,Math.abs(N.x)),A=Math.max(A,Math.abs(N.y))}let C=s/o;R/A>C?A=R/C:R=A*C,l.left=-R*1.05,l.right=R*1.05,l.top=A*1.05,l.bottom=-A*1.05,l.updateProjectionMatrix(),this.renderer.setRenderTarget(a),this.renderer.clear(),this.renderer.render(this.scene,l),this.renderer.readRenderTargetPixels(a,0,0,s,o,d);let O=x.createImageData(s,o);for(let D=0;D<o;D++)O.data.set(d.subarray((o-1-D)*s*4,(o-D)*s*4),D*s*4);x.putImageData(O,0,0),g.push({floorId:m.floor.id,url:p.toDataURL("image/png")})}}finally{this.renderer.setRenderTarget(null),this.renderer.setClearAlpha(f);for(let m of c)m.fv.y=m.y,m.fv.o=m.o,m.fv.mask.standing.value=m.standing,m.fv.mask.glass.value=m.glass,this.applyFloor(m.fv),m.fv.group.visible=m.visible;this.roof&&(this.roof.group.visible=u),this.ghost&&(this.ghost.visible=h),a.dispose(),this.invalidate()}return g}setRobots(e){let t=new Set;for(let n of e){t.add(n.id);let r=this.robots.get(n.id);r||(r=this.makeRobot(n),this.robots.set(n.id,r));let s=r.info.mode,o=n.mode==="cleaning"&&s==="cleaning"&&((r.info.roomId??null)!==(n.roomId??null)||JSON.stringify(r.info.obstacles??[])!==JSON.stringify(n.obstacles??[]));if(r.info=n,this.setRobotTrail(n),n.pose)r.motion.pos=[n.pose.x,n.pose.z],r.motion.heading=n.pose.heading,r.motion.path=[];else if(n.mode==="cleaning"&&(s!=="cleaning"||o||!r.motion.path.length)){let a=n.room?TM(n.room,void 0,void 0,n.obstacles):Pm(n.rest),l=a.length?a:Pm(n.rest),c=0;l.forEach((u,h)=>{Math.hypot(u[0]-r.motion.pos[0],u[1]-r.motion.pos[1])<Math.hypot(l[c][0]-r.motion.pos[0],l[c][1]-r.motion.pos[1])&&(c=h)}),r.motion.path=l,r.motion.next=c,n.room&&!Ve(r.motion.pos,n.room)&&(r.motion.pos=[l[c][0],l[c][1]])}r.led.color.setHex(HM[n.mode])}for(let[n,r]of this.robots){if(t.has(n))continue;r.group.removeFromParent(),r.led.dispose(),this.robots.delete(n);let s=this.robotTrails.get(n);s?.removeFromParent(),s?.geometry.dispose(),s?.material?.dispose(),this.robotTrails.delete(n);let o=this.trailTimers.get(n);o!==void 0&&(clearTimeout(o),this.trailTimers.delete(n))}this.robotLast=0,this.invalidate()}setRobotTrail(e){let t=e.track??[],n=t.map(o=>o.length?`${o.length}:${o[0].map(a=>a.toFixed(2))}/${o[o.length-1].map(a=>a.toFixed(2))}`:"").join("|"),r=this.robotTrails.get(e.id);if(r&&r.userData.key===n){this.showRobotTrail(e);return}let s=r;if(!s){let o=new Ke({color:3590399,transparent:!0,opacity:.34,depthWrite:!1,side:ut});s=new we(Im([],.16,0),o),s.renderOrder=3,s.name=`robot-trail:${e.id}`,this.robotTrails.set(e.id,s);let a=this.robots.get(e.id)?.group.parent;a&&a.add(s)}s.geometry.dispose(),s.geometry=Im(t,.16,(e.y??0)+.012),s.userData.key=n,this.showRobotTrail(e)}showRobotTrail(e){let t=this.robotTrails.get(e.id);if(!t)return;let n=this.trailTimers.get(e.id);n!==void 0&&(clearTimeout(n),this.trailTimers.delete(e.id));let r=Date.now(),s=EM(e.settledAt,r);if(t.material.opacity=.34*s,t.visible=(e.track?.length??0)>0&&s>.01,s<=0||s>=1&&e.settledAt==null)return;let o=s>=1?Math.max(0,(e.settledAt??r)+Uh-r):250;this.trailTimers.set(e.id,setTimeout(()=>{this.showRobotTrail(e),this.invalidate()},o))}makeRobot(e){if(!this.robotGeo){let s=new lt,o=(l,c,u,h,f)=>{let d=[];for(let p=0;p<20;p++)d.push([Math.cos(p/20*Math.PI*2)*l,Math.sin(p/20*Math.PI*2)*l]);Tt(s,d,c,u,h,f,{aoFrom:0,bottom:!1})};o(.17,.012,.08,2371657,3424863),o(.055,.08,.1,3820138,5070726),this.robotGeo=s.geometry(),this.robotMat=new Ke({vertexColors:!0});let a=new lt;Tt(a,[[-.05,.1],[.05,.1],[.05,.14],[-.05,.14]],.08,.085,16777215,16777215,{aoFrom:0,bottom:!1}),this.robotLedGeo=a.geometry()}let t=new ct,n=new Ke({color:HM[e.mode]}),r=e.mower?this.mowerMat??=new Ke({color:4164170}):this.robotMat;return t.add(new we(this.robotGeo,r),new we(this.robotLedGeo,n)),e.mower&&t.scale.set(1.7,1.6,1.7),{info:e,motion:{pos:[...e.rest],heading:e.restHeading,path:[],next:0},group:t,led:n}}buildPets(){let e=new Map(this.pets);this.pets.clear(),this.petMat??=new Ke({vertexColors:!0});for(let t of this.floors)for(let n of t.floor.furniture){let r=vt(n.type);if(!r?.pet)continue;let s=t.floor.rooms.find(f=>f.points.length>=3&&Ve([n.x,n.z],f.points)),o=e.get(n.id),a=new lt;Ms(new Li(a,new Wt,Ss({x:0,z:0,rotation:0,mirror:n.mirror})),r,Math.max(.05,n.w),Math.max(.05,n.d),Math.max(.05,n.h),0,null,null,n.variant??null),o?.group.removeFromParent();let l=new ct;l.add(new we(a.geometry(),this.petMat));let c=s?t.floor.furniture.filter(f=>f.id!==n.id&&!vt(f.type)?.pet&&f.type!=="rug"&&Gt(t.floor,f)<.5&&Ve([f.x,f.z],s.points)).map(f=>ts(f)):[],u={points:s?.points??[[n.x-.5,n.z-.5],[n.x+.5,n.z-.5],[n.x+.5,n.z+.5],[n.x-.5,n.z+.5]],obstacles:c,speed:n.type.endsWith(":pet_dog")?.7:.45},h=o&&s&&Ve(o.motion.pos,s.points)?o.motion:{pos:[n.x,n.z],heading:n.rotation*Math.PI/180,target:null,rest:1};this.pets.set(n.id,{motion:h,room:u,random:mb(n.id),group:l,floorId:t.floor.id})}for(let[t,n]of e)this.pets.has(t)||n.group.removeFromParent()}setPetRooms(e){for(let[t,n]of this.pets){let r=this.floorMap.get(n.floorId),s=e.get(t);if(!r||s===void 0)continue;let o=s?r.floor.rooms.find(l=>l.id===s&&l.points.length>=3):void 0;if(!o||n.room.points===o.points)continue;let a=r.floor.furniture.filter(l=>!vt(l.type)?.pet&&l.type!=="rug"&&Gt(r.floor,l)<.5&&Ve([l.x,l.z],o.points)).map(l=>ts(l));n.room={...n.room,points:o.points,obstacles:a},Ve(n.motion.pos,o.points)||(n.motion={...n.motion,pos:Bs(o.points),target:null,rest:.5})}this.invalidate()}stepRobots(e){if(!this.robots.size&&!this.pets.size)return!1;let t=this.robotLast?Math.min(.2,(e-this.robotLast)/1e3):0;this.robotLast=e;let n=!1,r=1/0,s=this.petLast?(e-this.petLast)/1e3:0;this.petLast=e;for(let o of this.pets.values()){let a=this.floorMap.get(o.floorId);if(!a)continue;o.group.parent!==a.group&&a.group.add(o.group),gb(o.motion,o.room,s,o.random)||!!o.motion.target?n=!0:r=Math.min(r,Math.max(0,o.motion.rest)),o.group.position.set(o.motion.pos[0],0,o.motion.pos[1]),o.group.rotation.y=o.motion.heading}clearTimeout(this.petTimer),!n&&Number.isFinite(r)&&(this.petTimer=setTimeout(()=>this.invalidate(),r*1e3+50));for(let o of this.robots.values()){let a=this.floorMap.get(o.info.floorId);if(!a)continue;o.group.parent!==a.group&&a.group.add(o.group);let l=this.robotTrails.get(o.info.id);l&&l.parent!==a.group&&a.group.add(l),t>0?n=AM(o.motion,o.info,t)||n:n||=o.info.mode==="cleaning"||o.info.mode==="returning",o.group.position.set(o.motion.pos[0],o.info.y??0,o.motion.pos[1]),o.group.rotation.y=o.motion.heading}return n||(this.robotLast=0),n}getView(){return{...this.controls.view,target:this.controls.view.target.clone()}}showView(e,t=900){let n=e.target??{x:0,y:0,z:0};this.controls.maxRadius=Math.max(this.controls.maxRadius,e.radius*1.5),this.controls.flyTo({target:new U(n.x,n.y,n.z),radius:e.radius,phi:e.phi,theta:e.theta},t)}flyTo(e,t=900){this.controls.flyTo(e,t)}focus(e,t,n,r,s){let o=this.floorMap.get(e);if(o){if(this.controls.flyTo({target:new U(t,o.floor.elevation+o.ty+r,n),radius:5.5,phi:.78},900),s){this.flashes.set(s,performance.now()+2400);let a=this.host.querySelector(`.nf-dev[data-entity="${CSS.escape(s)}"]`);a?.classList.add("nf-dev-found"),setTimeout(()=>a?.classList.remove("nf-dev-found"),2600)}this.invalidate()}}render(e){if(this.frame=0,this.disposed)return;let t=this.lastFrame?Math.min(100,e-this.lastFrame):16,n=!1;this.orbitSpeed&&!this.controls.active?(this.orbitLast&&(this.controls.view.theta+=this.orbitSpeed*Math.min(100,e-this.orbitLast)/1e3),this.orbitLast=e,n=!0):this.orbitLast=0;let r=this.controls.update(e),s=this.stepFloors(t),a=[this.stepOpenings(t),this.stepFridges(t),this.stepCovers(t)].some(Boolean),l=!1;if(this.flashes.size){let g=new Set;for(let[m,b]of this.flashes){let v=this.deviceFloor.get(m);v&&g.add(v),b<=e&&this.flashes.delete(m)}l=this.flashes.size>0;for(let m of this.floors)g.has(m.floor.id)&&this.buildLamps(m)}let c=this.placeRoof(t),u=this.stepRobots(e);this.pictureLayer.step();let f=[this.weatherLayer,this.energyLayer,this.soundLayer,this.screenLayer,this.waterLayer].map(g=>g.step(e)).some(Boolean),d=r||s||a||l||c,p=[];if(r&&p.push("camera"),s&&p.push("floors"),a&&p.push("openings"),l&&p.push("flash"),c&&p.push("roof"),this.effectTick&&p.push("effect"),u&&p.push("robot"),n&&p.push("orbit"),this.tintTick&&p.push("tint"),this.effectTick=this.tintTick=!1,this.lastFrame=d?e:0,d&&this.governor){let g=this.governor.frame(t,e);g&&"ratio"in g?(this.renderer.setPixelRatio(g.ratio),this.resize()):g&&setTimeout(()=>this.dropToLow(),0)}this.updateWalls(),this.renderer.render(this.scene,this.camera),this.placeLhAnchors(),(this.viewChanged()||s||this.labelsDirty)&&(this.labelsDirty=!1,this.updateLabels()),this.reportStats(e,p),d&&this.invalidate(),this.scheduleEffects(),!d&&n&&!this.orbitTimer&&(this.orbitTimer=setTimeout(()=>{this.orbitTimer=void 0,this.invalidate()},this.lowQuality?66:33));let x=this.resting;!d&&f&&!this.weatherTimer&&!x&&(this.weatherTimer=setTimeout(()=>{this.weatherTimer=void 0,this.invalidate()},33)),!d&&u&&!this.robotTimer&&!x&&(this.robotTimer=setTimeout(()=>{this.robotTimer=void 0,this.invalidate()},this.lowQuality?66:33))}updateWalls(){if(this.controls.walk){for(let o of this.floors)o.mask.standing.value=65535,o.mask.glass.value=0,o.mask.slope?.value.set(0,0,0,0);return}let e=this.camera.position,t=this.controls.view.target,n=e.x-t.x,r=e.z-t.z,s=Math.hypot(n,r)||1;for(let o of this.floors){let a=this.roomId!==null&&o.floor.rooms.some(h=>h.id===this.roomId),l=this.wallMode==="cut",c=0,u=0;o.geo.buckets.forEach((h,f)=>{let d=h?h[0]*n/s+h[1]*r/s>=.25:a;this.wallMode!=="auto"||!d||(this.painted?a&&(u|=1<<f):c|=1<<f)}),o.mask.standing.value=l?0:65535&~u,o.mask.glass.value=c,this.slopeWalls(o,-n/s,-r/s)}}slopeWalls(e,t,n){let r=e.mask.slope.value;if(this.wallMode!=="slope"||!e.bbox||this.controls.walk){r.set(0,0,0,0);return}let{x0:s,x1:o,z0:a,z1:l}=e.bbox,c=[s*t+a*n,o*t+a*n,s*t+l*n,o*t+l*n],[u,h]=[Math.min(...c),Math.max(...c)],f=(h-u)*.08;r.set(t,n,u+f,h-f),e.mask.slopeY.value.set(Math.min(e.floor.cut_height,e.floor.height),e.floor.height)}viewChanged(){let e=this.controls.view,t=this.viewKey;return t[0]===e.target.x&&t[1]===e.target.y&&t[2]===e.target.z&&t[3]===e.radius&&t[4]===e.theta&&t[5]===e.phi?!1:(t[0]=e.target.x,t[1]=e.target.y,t[2]=e.target.z,t[3]=e.radius,t[4]=e.theta,t[5]=e.phi,!0)}screenPoint(e,t=1.05){return Db(this.camera,e,this.size,t)}updateLabels(){let e=this.houseView,t=[];for(let n of this.floors){let r=n.bbox;if(!(e&&n.o>.5&&r)){this.labelPlacer.place(n.label,null);continue}let s=n.floor.elevation+n.y+n.floor.cut_height*.5,o=[r.x0,r.x1].flatMap(l=>[r.z0,r.z1].map(c=>this.screenPoint([l,s,c],1/0)));n.label.hidden&&(n.label.hidden=!1),n.labelSize??={w:n.label.offsetWidth,h:n.label.offsetHeight};let a=kb(o,n.labelSize.w,{width:this.size.w,inset:this.labelInset});t.push({fv:n,rank:n.rank,left:a.left,y:a.y,height:n.labelSize.h})}for(let n of Bb(t))this.labelPlacer.place(n.fv.label,Ub(n.left,n.y));this.updateDevicePins();for(let n of this.floors){let r=n.to<.99||n.o<.9||e||this.roomId!==null||this.otherFloor(n),s=n.floor.elevation+n.y+.05;for(let a of n.roomPins){let l=r?null:this.screenPoint([a.cx,s,a.cz],1.1);this.labelPlacer.place(a.pin,l&&!l.off?hl(l):null)}let o=e||n.o<.9||this.otherFloor(n);for(let{pin:a,note:l}of n.notePins){let c=o?null:this.screenPoint([l.x,n.floor.elevation+n.y+(l.y??f0),l.z]);this.labelPlacer.place(a,c&&!c.off?hl(c):null)}}}otherFloor(e){return this.floorId!==null&&e.floor.id!==this.floorId}updateDevicePins(){let e=this.houseView;for(let t of this.persons){let n=this.personPins.get(t.id),r=this.floorMap.get(t.floorId);if(!n)continue;let s=r&&!e&&jd(r,this.otherFloor(r))?this.screenPoint([t.x,r.floor.elevation+r.y+.9,t.z]):null;this.labelPlacer.place(n,s&&!s.off?hl(s):null)}for(let t of this.devices){let n=this.devicePins.get(t.id)?.el;if(!n)continue;let r=this.floorMap.get(t.floorId),s=t.id.startsWith("detect:"),o=!!t.full&&t.roomId===null,a=!!r&&(o?zb(r):(!e||s)&&jd(r,this.otherFloor(r))),c=!!r&&a&&t.pin!==!1?this.screenPoint([t.x,r.floor.elevation+r.y+t.y,t.z]):null;if(!c||c.off){this.labelPlacer.place(n,null);continue}let u=this.roomId===null?t.full?"full":"":t.roomId===this.roomId?"full":"dim";this.pinMode.get(n)!==u&&(this.pinMode.set(n,u),n.classList.toggle("nf-dev-full",u==="full"),n.classList.toggle("nf-dev-dim",u==="dim")),this.labelPlacer.place(n,hl(c))}}reportStats(e,t){if(!this.statsOn||!this.options.onStats)return;let n=t.length>0;this.fpsStart||(this.fpsStart=e),this.lastStatsFrame&&n&&(this.worstFrame=Math.max(this.worstFrame,e-this.lastStatsFrame)),this.lastStatsFrame=n?e:0,this.fpsFrames++;let r=e-this.fpsStart;if(r>500||!n){let s=this.renderer.info.render;this.options.onStats({fps:n?Math.round(this.fpsFrames*1e3/r):0,busy:t,worstMs:Math.round(this.worstFrame),calls:s.calls,triangles:s.triangles,low:this.lowQuality,pixelRatio:this.renderer.getPixelRatio()}),this.fpsFrames=0,this.fpsStart=e,this.worstFrame=0}}};function EP(){let e=document.createElement("canvas");e.width=256*3,e.height=256*2;let t=e.getContext("2d"),n=(o,a,l,c,u)=>{t.strokeStyle=`rgba(55,224,255,${u})`,t.beginPath(),t.moveTo(o,a),t.lineTo(l,c),t.stroke()};t.lineWidth=1.5;let r=(o,a,l)=>{t.save(),t.beginPath(),t.rect(o*256,a*256,256,256),t.clip(),l(o*256,a*256),t.restore()};r(0,0,(o,a)=>{for(let l=0;l<5;l++){let c=a+l*256/5+.75;n(o,c,o+256,c,.09);let u=o+l*.37%1*256;n(u,c,u,c+256/5,.07)}}),r(1,0,(o,a)=>{for(let l=0;l<7;l++){let c=o+l*256/7+.75;n(c,a,c,a+256,.08);let u=a+l*.53%1*256;n(c,u,c+256/7,u,.06)}}),r(2,0,(o,a)=>{for(let l=0;l<4;l++){let c=l*256/4+.75;n(o+c,a,o+c,a+256,.1),n(o,a+c,o+256,a+c,.1)}}),r(1,1,(o,a)=>{for(let l=0;l<2;l++){let c=a+l*256/2+.75;n(o,c,o+256,c,.09);let u=l?256/4:0;for(let h of[u,u+256/2])n(o+h+.75,c,o+h+.75,c+256/2,.09)}}),r(2,1,(o,a)=>{n(o+.75,a,o+.75,a+256,.08),n(o,a+.75,o+256,a+.75,.08),t.fillStyle="rgba(55,224,255,0.05)";for(let l=0;l<90;l++)t.fillRect(o+l*97%256,a+(l*61+l*l%37)%256,2,2)});let s=new zt(e);return s.flipY=!1,s.wrapS=ln,s.wrapT=ln,s.anisotropy=4,s.colorSpace=ft,s}function RP(){let i=document.createElement("canvas");i.width=8,i.height=32;let e=i.getContext("2d");e.fillStyle="#1a2742",e.fillRect(0,0,8,32),e.fillStyle="#223556",e.fillRect(0,4,8,14),e.fillStyle="rgba(55,224,255,0.45)",e.fillRect(0,29,8,2);let t=new zt(i);return t.wrapS=kn,t.wrapT=kn,t.colorSpace=ft,t}function CP(i,e){let t=i.rooms.map((r,s)=>s),n=r=>t[r]===r?r:t[r]=n(t[r]);for(let[r,s]of e){let o=i.rooms.findIndex(u=>u.id===r),a=i.rooms.findIndex(u=>u.id===s);if(o<0||a<0)continue;let l=n(o),c=n(a);l!==c&&(t[Math.max(l,c)]=Math.min(l,c))}return t.map((r,s)=>n(s))}function PP(){let e=document.createElement("canvas");e.width=64,e.height=64;let t=e.getContext("2d"),n=t.createRadialGradient(64/2,64/2,0,64/2,64/2,64/2);n.addColorStop(0,"rgba(255,255,255,0.9)"),n.addColorStop(.2,"rgba(255,255,255,0.45)"),n.addColorStop(.55,"rgba(255,255,255,0.1)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,64,64);let r=new zt(e);return r.colorSpace=ft,r}function IP(){let e=Qm,t=document.createElement("canvas");t.width=1024,t.height=1024;let n=t.getContext("2d");n.strokeStyle="rgba(91,124,255,0.16)",n.lineWidth=1;for(let o=0;o<=e;o++){let a=Math.round(o/e*1024)+.5;n.beginPath(),n.moveTo(a,0),n.lineTo(a,1024),n.moveTo(0,a),n.lineTo(1024,a),n.stroke()}n.globalCompositeOperation="destination-in";let r=n.createRadialGradient(1024/2,1024/2,1024*.12,1024/2,1024/2,1024/2);r.addColorStop(0,"rgba(0,0,0,1)"),r.addColorStop(1,"rgba(0,0,0,0)"),n.fillStyle=r,n.fillRect(0,0,1024,1024);let s=new zt(t);return s.anisotropy=4,s.colorSpace=ft,s}function w5(i,e){return new e0(i,e)}function Jm(i,e,t,n){let[r,s,o]=e.size??Es[e.lamp],a=e.base??0,l=(e.rotation??0)*pt,c=Math.cos(l),u=Math.sin(l),h=(x,g)=>[e.x+x*c-g*u,e.z+x*u+g*c],f=(x,g,m,b,v,y=14)=>{let M=[];for(let S=0;S<y;S++){let _=S/y*Math.PI*2;M.push([e.x+Math.cos(_)*x,e.z+Math.sin(_)*x])}Tt(i,M,g,m,b,v,{aoFrom:0,bottom:!0})},d=(x,g,m,b,v,y,M,S=M)=>Tt(i,[h(x,m),h(g,m),h(g,b),h(x,b)],v,y,M,S,{aoFrom:0,bottom:!0}),p=Math.max(.05,Math.min(r,s)/2);switch(e.lamp){case"ceiling":f(p*.25,t-.04,t,$e,$e,8),f(p,t-Math.max(.04,o)-.035,t-.04,n,n);break;case"pendant":{let x=Math.max(.4,t-o);f(.06,t-.02,t,$e,$e,8);let g=e.variant==="globe"?x+2*p:e.variant==="drum"?x+.24:x+.2;if(f(.008,g,t-.02,$e,$e,5),e.variant==="globe")for(let b=0;b<7;b++){let v=Math.PI*(b/7),y=Math.PI*((b+1)/7);f(p*Math.max(.2,Math.sin((v+y)/2)),x+p-p*Math.cos(v),x+p-p*Math.cos(y),n,n,14)}else if(e.variant==="cone")for(let b=0;b<4;b++)f(p*(.25+.75*(4-b)/4),x+.06*b,x+.06*(b+1),n,n,16);else e.variant==="drum"?f(p,x,x+.24,n,n,18):(f(p*.35,x+.14,x+.2,n,n,12),f(p,x,x+.14,n,n,16));break}case"fan":{let x=Math.max(.05,t-Math.max(.22,o)),g=x+.16;f(.07,t-.05,t,$e,$e,10),g<t-.05&&f(.014,g,t-.05,$e,$e,6),f(.11,x+.06,g,$e,$e,14),f(.1,x,x+.06,n,n,14);let m=Math.max(.2,Math.min(r,s)/2),b=x+.1;for(let v=0;v<$M;v++){let y=((e.phase??0)+v*KM)*pt,[M,S]=[Math.cos(y),Math.sin(y)],_=(w,R)=>[e.x+w*M-R*S,e.z+w*S+R*M];Tt(i,[_(.1,-.035),_(m,-.075),_(m,.075),_(.1,.035)],b,b+.012,WM,WM,{aoFrom:0,bottom:!0})}break}case"downlight":f(p,t-.012,t,$e,$e,12),f(p*.7,t-.02,t-.012,n,n,12);break;case"spot":f(p*.6,t-.02,t,$e,$e,10),f(p,t-Math.max(.06,o),t-.02,$e,$e,12),f(p*.8,t-Math.max(.06,o)-.008,t-Math.max(.06,o),n,n,12);break;case"panel":d(-r/2,r/2,-s/2,s/2,t-Math.max(.015,o),t,$e,$e),d(-r/2+.02,r/2-.02,-s/2+.02,s/2-.02,t-Math.max(.015,o)-.004,t-Math.max(.015,o),n);break;case"uplight":f(Math.max(.1,p*.6),a,a+.03,$e,$e),f(.014,a+.03,a+o-.12,$e,$e,6),f(p,a+o-.14,a+o-.02,$e,$e),f(p*.92,a+o-.02,a+o,n,n);break;case"bollard":f(p,a,a+o-.14,$e,$e,10),f(p*.9,a+o-.14,a+o-.03,n,n,10),f(p*1.1,a+o-.03,a+o,$e,$e,10);break;case"garden":f(.012,a,a+o-.08,$e,$e,5),f(p,a+o-.08,a+o-.01,$e,$e,10),f(p*.8,a+o-.01,a+o,n,n,10);break;case"floor":f(Math.max(.1,p*.7),a,a+.03,$e,$e),f(.014,a+.03,a+o-.28,$e,$e,6),f(p,a+o-.3,a+o,n,n);break;case"table":f(Math.max(.05,p*.55),a,a+.03,$e,$e),f(.012,a+.03,a+o-.16,$e,$e,6),f(p,a+o-.18,a+o,n,n);break;case"wall":{let x=e.base??Fl;d(-r/2+.03,r/2-.03,-s/2,-s/2+.02,x,x+o,$e),d(-r/2,r/2,-s/2+.02,s/2,x+o*.15,x+o*.85,n);break}case"strip":{let x=Math.max(.02,o),g=e.base!=null?e.base+x:t-.04,m=e.upright?0:(e.rise??0)*pt;if(!e.roll&&!e.upright&&!m){d(-r/2,r/2,-s/2,s/2,g-x,g,n);break}let b=(e.roll??0)*pt,v=Math.cos(b),y=Math.sin(b),[M,S]=[Math.cos(m),Math.sin(m)],_=e.upright?a+r/2:g-x/2+Io(e.base,r,e.rise),w=(D,P,I)=>{let N=D,F=P*v-I*y,H=P*y+I*v;return e.upright?[N,F]=[-F,N]:m&&([N,F]=[N*M-F*S,N*S+F*M]),[e.x+N*c-H*u,_+F,e.z+N*u+H*c]},R=[w(-r/2,-x/2,-s/2),w(r/2,-x/2,-s/2),w(r/2,-x/2,s/2),w(-r/2,-x/2,s/2),w(-r/2,x/2,-s/2),w(r/2,x/2,-s/2),w(r/2,x/2,s/2),w(-r/2,x/2,s/2)],A=new W(n),C=[e.x,_,e.z],O=(D,P,I,N)=>{let[F,H,B]=[R[D],R[P],R[I]],X=[(H[1]-F[1])*(B[2]-F[2])-(H[2]-F[2])*(B[1]-F[1]),(H[2]-F[2])*(B[0]-F[0])-(H[0]-F[0])*(B[2]-F[2]),(H[0]-F[0])*(B[1]-F[1])-(H[1]-F[1])*(B[0]-F[0])],V=[F[0]-C[0],F[1]-C[1],F[2]-C[2]],re=X[0]*V[0]+X[1]*V[1]+X[2]*V[2]<0,[be,Y,Q,se]=re?[R[N],R[I],R[P],R[D]]:[R[D],R[P],R[I],R[N]];i.tri(be,Y,Q,A,A,A),i.tri(be,Q,se,A,A,A)};O(0,1,2,3),O(4,5,6,7),O(0,1,5,4),O(1,2,6,5),O(2,3,7,6),O(3,0,4,7);break}}}export{Bi as ModelError,e0 as NextFloorViewer,w5 as createViewer,MP as furniturePreview,xP as inspectModel,xb as isLowEnd,bP as prepareModel,yP as previewModel,Jm as pushLampModel};
|
|
/*! Bundled license information:
|
|
|
|
three/build/three.core.js:
|
|
three/build/three.module.js:
|
|
(**
|
|
* @license
|
|
* Copyright 2010-2026 Three.js Authors
|
|
* SPDX-License-Identifier: MIT
|
|
*)
|
|
*/
|