(function webpackUniversalModuleDefinition(root, factory) { if (typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if (typeof define === 'function' && define.amd) define([], factory); else if (typeof exports === 'object') exports['luma'] = factory(); else root['luma'] = factory();})(globalThis, function () { var __exports__=(()=>{var Ln=Object.create;var ot=Object.defineProperty;var Rn=Object.getOwnPropertyDescriptor;var In=Object.getOwnPropertyNames;var vn=Object.getPrototypeOf,Nn=Object.prototype.hasOwnProperty;var Kt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),wn=(e,t)=>{for(var n in t)ot(e,n,{get:t[n],enumerable:!0})},it=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of In(t))!Nn.call(e,s)&&s!==n&&ot(e,s,{get:()=>t[s],enumerable:!(r=Rn(t,s))||r.enumerable});return e},ct=(e,t,n)=>(it(e,t,"default"),n&&it(n,t,"default")),D=(e,t,n)=>(n=e!=null?Ln(vn(e)):{},it(t||!e||!e.__esModule?ot(n,"default",{value:e,enumerable:!0}):n,e)),bn=e=>it(ot({},"__esModule",{value:!0}),e);var j=Kt((Kr,Qt)=>{Qt.exports=globalThis.luma});var Pt=Kt((Js,ge)=>{ge.exports=globalThis.luma});var st={};wn(st,{GLTFAnimator:()=>W,createScenegraphsFromGLTF:()=>Tn,loadPBREnvironment:()=>xe,parsePBRMaterial:()=>at});ct(st,D(j(),1));var Zt=D(j(),1),C;(function(e){e[e.FUNC_ADD=32774]="FUNC_ADD",e[e.ONE=1]="ONE",e[e.SRC_ALPHA=770]="SRC_ALPHA",e[e.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",e[e.TEXTURE_MIN_FILTER=10241]="TEXTURE_MIN_FILTER",e[e.LINEAR=9729]="LINEAR",e[e.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",e[e.UNPACK_FLIP_Y_WEBGL=37440]="UNPACK_FLIP_Y_WEBGL"})(C||(C={}));function at(e,t,n,r){let s={defines:{MANUAL_SRGB:1,SRGB_FAST_APPROXIMATION:1},bindings:{},uniforms:{u_Camera:[0,0,0],u_MetallicRoughnessValues:[1,1]},parameters:{},glParameters:{},generatedTextures:[]};s.defines.USE_TEX_LOD=1;let{imageBasedLightingEnvironment:i}=r;return i&&(s.bindings.u_DiffuseEnvSampler=i.diffuseEnvSampler,s.bindings.u_SpecularEnvSampler=i.specularEnvSampler,s.bindings.u_brdfLUT=i.brdfLutTexture,s.uniforms.u_ScaleIBLAmbient=[1,1]),r?.pbrDebug&&(s.defines.PBR_DEBUG=1,s.uniforms.u_ScaleDiffBaseMR=[0,0,0,0],s.uniforms.u_ScaleFGDSpec=[0,0,0,0]),n.NORMAL&&(s.defines.HAS_NORMALS=1),n.TANGENT&&r?.useTangents&&(s.defines.HAS_TANGENTS=1),n.TEXCOORD_0&&(s.defines.HAS_UV=1),r?.imageBasedLightingEnvironment&&(s.defines.USE_IBL=1),r?.lights&&(s.defines.USE_LIGHTS=1),t&&On(e,t,s),s}function On(e,t,n){if(n.uniforms.pbr_uUnlit=Boolean(t.unlit),t.pbrMetallicRoughness&&Pn(e,t.pbrMetallicRoughness,n),t.normalTexture){K(e,t.normalTexture,"u_NormalSampler","HAS_NORMALMAP",n);let{scale:r=1}=t.normalTexture;n.uniforms.u_NormalScale=r}if(t.occlusionTexture){K(e,t.occlusionTexture,"u_OcclusionSampler","HAS_OCCLUSIONMAP",n);let{strength:r=1}=t.occlusionTexture;n.uniforms.u_OcclusionStrength=r}switch(t.emissiveTexture&&(K(e,t.emissiveTexture,"u_EmissiveSampler","HAS_EMISSIVEMAP",n),n.uniforms.u_EmissiveFactor=t.emissiveFactor||[0,0,0]),t.alphaMode){case"MASK":let{alphaCutoff:r=.5}=t;n.defines.ALPHA_CUTOFF=1,n.uniforms.u_AlphaCutoff=r;break;case"BLEND":Zt.log.warn("glTF BLEND alphaMode might not work well because it requires mesh sorting")(),n.parameters.blendColorOperation="add",n.parameters.blendColorSrcFactor="src-alpha",n.parameters.blendColorDstFactor="one-minus-src-alpha",n.parameters.blendAlphaOperation="add",n.parameters.blendAlphaSrcFactor="one",n.parameters.blendAlphaDstFactor="one-minus-src-alpha",n.glParameters.blend=!0,n.glParameters.blendEquation=C.FUNC_ADD,n.glParameters.blendFunc=[C.SRC_ALPHA,C.ONE_MINUS_SRC_ALPHA,C.ONE,C.ONE_MINUS_SRC_ALPHA];break}}function Pn(e,t,n){t.baseColorTexture&&K(e,t.baseColorTexture,"u_BaseColorSampler","HAS_BASECOLORMAP",n),n.uniforms.u_BaseColorFactor=t.baseColorFactor||[1,1,1,1],t.metallicRoughnessTexture&&K(e,t.metallicRoughnessTexture,"u_MetallicRoughnessSampler","HAS_METALROUGHNESSMAP",n);let{metallicFactor:r=1,roughnessFactor:s=1}=t;n.uniforms.u_MetallicRoughnessValues=[r,s]}function K(e,t,n,r=null,s){let i=t?.texture?.sampler?.parameters||{},o=t.texture.source.image,c,a={};o.compressed?(c=o,a={[C.TEXTURE_MIN_FILTER]:o.data.length>1?C.LINEAR_MIPMAP_NEAREST:C.LINEAR}):c={data:o};let f=e.createTexture({id:t.uniformName||t.id,parameters:{...i,...a},pixelStore:{[C.UNPACK_FLIP_Y_WEBGL]:!1},...c});s.bindings[n]=f,r&&(s.defines[r]=1),s.generatedTextures.push(f)}function q(e,t){if(!e)throw new Error(t||"loader assertion failed.")}var B={self:typeof self<"u"&&self,window:typeof window<"u"&&window,global:typeof global<"u"&&global,document:typeof document<"u"&&document},Cn=B.self||B.window||B.global||{},Bn=B.window||B.self||B.global||{},zn=B.global||B.self||B.window||{},kn=B.document||{};var Tt=Boolean(typeof process!="object"||String(process)!=="[object process]"||process.browser);var Jt=typeof process<"u"&&process.version&&/v([0-9]*)/.exec(process.version),Fn=Jt&&parseFloat(Jt[1])||0;var Un="",te={};function Lt(e){for(let t in te)if(e.startsWith(t)){let n=te[t];e=e.replace(t,n)}return!e.startsWith("http://")&&!e.startsWith("https://")&&(e=`${Un}${e}`),e}var ee="4.2.1";var Vn=globalThis.loaders?.parseImageNode,Rt=typeof Image<"u",It=typeof ImageBitmap<"u",qn=Boolean(Vn),vt=Tt?!0:qn;function ne(e){switch(e){case"auto":return It||Rt||vt;case"imagebitmap":return It;case"image":return Rt;case"data":return vt;default:throw new Error(`@loaders.gl/images: image ${e} not supported in this environment`)}}function re(){if(It)return"imagebitmap";if(Rt)return"image";if(vt)return"data";throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js")}function se(e){let t=Dn(e);if(!t)throw new Error("Not an image");return t}function Nt(e){return ft(e)}function ft(e){switch(se(e)){case"data":return e;case"image":case"imagebitmap":let t=document.createElement("canvas"),n=t.getContext("2d");if(!n)throw new Error("getImageData");return t.width=e.width,t.height=e.height,n.drawImage(e,0,0),n.getImageData(0,0,e.width,e.height);default:throw new Error("getImageData")}}function Dn(e){return typeof ImageBitmap<"u"&&e instanceof ImageBitmap?"imagebitmap":typeof Image<"u"&&e instanceof Image?"image":e&&typeof e=="object"&&e.data&&e.width&&e.height?"data":null}var Yn=/^data:image\/svg\+xml/,Hn=/\.svg((\?|#).*)?$/;function lt(e){return e&&(Yn.test(e)||Hn.test(e))}function ie(e,t){if(lt(t)){let r=new TextDecoder().decode(e);try{typeof unescape=="function"&&typeof encodeURIComponent=="function"&&(r=unescape(encodeURIComponent(r)))}catch(i){throw new Error(i.message)}return`data:image/svg+xml;base64,${btoa(r)}`}return wt(e,t)}function wt(e,t){if(lt(t))throw new Error("SVG cannot be parsed directly to imagebitmap");return new Blob([new Uint8Array(e)])}async function ht(e,t,n){let r=ie(e,n),s=self.URL||self.webkitURL,i=typeof r!="string"&&s.createObjectURL(r);try{return await Gn(i||r,t)}finally{i&&s.revokeObjectURL(i)}}async function Gn(e,t){let n=new Image;return n.src=e,t.image&&t.image.decode&&n.decode?(await n.decode(),n):await new Promise((r,s)=>{try{n.onload=()=>r(n),n.onerror=i=>{let o=i instanceof Error?i.message:"error";s(new Error(o))}}catch(i){s(i)}})}var Wn={},oe=!0;async function ce(e,t,n){let r;lt(n)?r=await ht(e,t,n):r=wt(e,n);let s=t&&t.imagebitmap;return await $n(r,s)}async function $n(e,t=null){if((Xn(t)||!oe)&&(t=null),t)try{return await createImageBitmap(e,t)}catch(n){console.warn(n),oe=!1}return await createImageBitmap(e)}function Xn(e){for(let t in e||Wn)return!1;return!0}function ae(e){return!Zn(e,"ftyp",4)||!(e[8]&96)?null:jn(e)}function jn(e){switch(Kn(e,8,12).replace("\0"," ").trim()){case"avif":case"avis":return{extension:"avif",mimeType:"image/avif"};default:return null}}function Kn(e,t,n){return String.fromCharCode(...e.slice(t,n))}function Qn(e){return[...e].map(t=>t.charCodeAt(0))}function Zn(e,t,n=0){let r=Qn(t);for(let s=0;s=24&&t.getUint32(0,z)===2303741511?{mimeType:"image/png",width:t.getUint32(16,z),height:t.getUint32(20,z)}:null}function er(e){let t=Z(e);return t.byteLength>=10&&t.getUint32(0,z)===1195984440?{mimeType:"image/gif",width:t.getUint16(6,Q),height:t.getUint16(8,Q)}:null}function nr(e){let t=Z(e);return t.byteLength>=14&&t.getUint16(0,z)===16973&&t.getUint32(2,Q)===t.byteLength?{mimeType:"image/bmp",width:t.getUint32(18,Q),height:t.getUint32(22,Q)}:null}function rr(e){let t=Z(e);if(!(t.byteLength>=3&&t.getUint16(0,z)===65496&&t.getUint8(2)===255))return null;let{tableMarkers:r,sofMarkers:s}=sr(),i=2;for(;i+9Boolean(pt(new DataView(e)))],options:ar};function xt(e,t,n){let r=typeof e=="function"?e({...t,...n}):e,s=t.baseUrl;return s&&(r=s[s.length-1]==="/"?`${s}${r}`:`${s}/${r}`),Lt(r)}var fr=e=>e&&typeof e=="object";async function he(e,t,n={}){return await bt(e,t,n)}async function bt(e,t,n){return Array.isArray(e)?await hr(e,t,n):fr(e)?await lr(e,t,n):await t(e,n)}async function lr(e,t,n){let r=[],s={};for(let i in e){let o=e[i],c=bt(o,t,n).then(a=>{s[i]=a});r.push(c)}return await Promise.all(r),s}async function hr(e,t,n={}){let r=e.map(s=>bt(s,t,n));return await Promise.all(r)}async function pe(e,t,n){return await he(e,r=>Ot(r,t,n))}async function Ot(e,t,n){let s=await(await fetch(e,n.fetch)).arrayBuffer();return await t(s,n)}async function J(e,t={}){let n=await pr(e,t);return await pe(n,mt.parse,t)}async function pr(e,t,n={}){let r=t&&t.image&&t.image.mipLevels||0;return r!==0?await mr(e,r,t,n):xt(e,t,n)}async function mr(e,t,n,r){let s=[];if(t==="auto"){let i=xt(e,n,{...r,lod:0}),o=await Ot(i,mt.parse,n),{width:c,height:a}=Nt(o);t=xr({width:c,height:a}),s.push(i)}q(t>0);for(let i=s.length;iJ(t.getTexUrl("diffuse",i,0)),sampler:{wrapS:"clamp-to-edge",wrapT:"clamp-to-edge",minFilter:"linear",maxFilter:"linear"}}),s=me(e,{id:"SpecularEnvSampler",getTextureForFace:i=>{let o=[];for(let c=0;c<=t.specularMipLevels-1;c++)o.push(J(t.getTexUrl("specular",i,c)));return o},sampler:{wrapS:"clamp-to-edge",wrapT:"clamp-to-edge",minFilter:"linear",maxFilter:"linear"}});return{brdfLutTexture:n,diffuseEnvSampler:r,specularEnvSampler:s}}var gr=[0,1,2,3,4,5];function me(e,{id:t,getTextureForFace:n,sampler:r}){let s={};return gr.forEach(i=>{s[String(i)]=n(i)}),e.createTexture({id:t,dimension:"cube",mipmaps:!1,sampler:r,data:s})}var $=D(Pt(),1);var ti=1/Math.PI*180,ei=1/180*Math.PI,dr={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...dr}};var L=globalThis.mathgl.config;function de(e,{precision:t=L.precision}={}){return e=Mr(e),`${parseFloat(e.toPrecision(t))}`}function Y(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Ct(e,t,n){let r=L.EPSILON;n&&(L.EPSILON=n);try{if(e===t)return!0;if(Y(e)&&Y(t)){if(e.length!==t.length)return!1;for(let s=0;s0?", ":"")+de(this[r],t);return`${t.printTypes?this.constructor.name:""}[${n}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let n=0;n=0&&t=0&&t0&&(i=1/Math.sqrt(i)),e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e}function Le(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function dt(e,t,n){let r=t[0],s=t[1],i=t[2],o=n[0],c=n[1],a=n[2];return e[0]=s*a-i*c,e[1]=i*o-r*a,e[2]=r*c-s*o,e}function Mt(e,t,n){let r=t[0],s=t[1],i=t[2],o=n[3]*r+n[7]*s+n[11]*i+n[15];return o=o||1,e[0]=(n[0]*r+n[4]*s+n[8]*i+n[12])/o,e[1]=(n[1]*r+n[5]*s+n[9]*i+n[13])/o,e[2]=(n[2]*r+n[6]*s+n[10]*i+n[14])/o,e}function Re(e,t,n){let r=n[0],s=n[1],i=n[2],o=n[3],c=t[0],a=t[1],f=t[2],l=s*f-i*a,h=i*c-r*f,p=r*a-s*c,m=s*p-i*h,x=i*l-r*p,g=r*h-s*l,d=o*2;return l*=d,h*=d,p*=d,m*=2,x*=2,g*=2,e[0]=c+l+m,e[1]=a+h+x,e[2]=f+p+g,e}var Ie=Ar;var di=function(){let e=zt();return function(t,n,r,s,i,o){let c,a;for(n||(n=3),r||(r=0),s?a=Math.min(s*n+r,t.length):a=t.length,c=r;c0&&(o=1/Math.sqrt(o)),e[0]=n*o,e[1]=r*o,e[2]=s*o,e[3]=i*o,e}function Xe(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]}function je(e,t,n,r){let s=t[0],i=t[1],o=t[2],c=t[3];return e[0]=s+r*(n[0]-s),e[1]=i+r*(n[1]-i),e[2]=o+r*(n[2]-o),e[3]=c+r*(n[3]-c),e}function Ke(e,t,n){let r=t[0],s=t[1],i=t[2],o=t[3];return e[0]=n[0]*r+n[4]*s+n[8]*i+n[12]*o,e[1]=n[1]*r+n[5]*s+n[9]*i+n[13]*o,e[2]=n[2]*r+n[6]*s+n[10]*i+n[14]*o,e[3]=n[3]*r+n[7]*s+n[11]*i+n[15]*o,e}function Qe(e,t,n){let r=t[0],s=t[1],i=t[2],o=n[0],c=n[1],a=n[2],f=n[3],l=f*r+c*i-a*s,h=f*s+a*r-o*i,p=f*i+o*s-c*r,m=-o*r-c*s-a*i;return e[0]=l*f+m*-o+h*-a-p*-c,e[1]=h*f+m*-c+p*-o-l*-a,e[2]=p*f+m*-a+l*-c-h*-o,e[3]=t[3],e}var vi=function(){let e=Rr();return function(t,n,r,s,i,o){let c,a;for(n||(n=4),r||(r=0),s?a=Math.min(s*n+r,t.length):a=t.length,c=r;cMath.PI*2)throw Error("expected radians")}function Pr(e,t,n,r,s,i){let o=2*i/(n-t),c=2*i/(s-r),a=(n+t)/(n-t),f=(s+r)/(s-r),l=-1,h=-1,p=-2*i;return e[0]=o,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=c,e[6]=0,e[7]=0,e[8]=a,e[9]=f,e[10]=l,e[11]=h,e[12]=0,e[13]=0,e[14]=p,e[15]=0,e}function Je(){let e=new R(4);return R!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}function tn(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e}function Dt(e,t,n){n=n*.5;let r=Math.sin(n);return e[0]=r*t[0],e[1]=r*t[1],e[2]=r*t[2],e[3]=Math.cos(n),e}function Yt(e,t,n){let r=t[0],s=t[1],i=t[2],o=t[3],c=n[0],a=n[1],f=n[2],l=n[3];return e[0]=r*l+o*c+s*f-i*a,e[1]=s*l+o*a+i*c-r*f,e[2]=i*l+o*f+r*a-s*c,e[3]=o*l-r*c-s*a-i*f,e}function en(e,t,n){n*=.5;let r=t[0],s=t[1],i=t[2],o=t[3],c=Math.sin(n),a=Math.cos(n);return e[0]=r*a+o*c,e[1]=s*a+i*c,e[2]=i*a-s*c,e[3]=o*a-r*c,e}function nn(e,t,n){n*=.5;let r=t[0],s=t[1],i=t[2],o=t[3],c=Math.sin(n),a=Math.cos(n);return e[0]=r*a-i*c,e[1]=s*a+o*c,e[2]=i*a+r*c,e[3]=o*a-s*c,e}function rn(e,t,n){n*=.5;let r=t[0],s=t[1],i=t[2],o=t[3],c=Math.sin(n),a=Math.cos(n);return e[0]=r*a+s*c,e[1]=s*a-r*c,e[2]=i*a+o*c,e[3]=o*a-i*c,e}function sn(e,t){let n=t[0],r=t[1],s=t[2];return e[0]=n,e[1]=r,e[2]=s,e[3]=Math.sqrt(Math.abs(1-n*n-r*r-s*s)),e}function et(e,t,n,r){let s=t[0],i=t[1],o=t[2],c=t[3],a=n[0],f=n[1],l=n[2],h=n[3],p,m,x,g,d;return p=s*a+i*f+o*l+c*h,p<0&&(p=-p,a=-a,f=-f,l=-l,h=-h),1-p>1e-6?(m=Math.acos(p),d=Math.sin(m),x=Math.sin((1-r)*m)/d,g=Math.sin(r*m)/d):(x=1-r,g=r),e[0]=x*s+g*a,e[1]=x*i+g*f,e[2]=x*o+g*l,e[3]=x*c+g*h,e}function on(e,t){let n=t[0],r=t[1],s=t[2],i=t[3],o=n*n+r*r+s*s+i*i,c=o?1/o:0;return e[0]=-n*c,e[1]=-r*c,e[2]=-s*c,e[3]=i*c,e}function cn(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e}function Ht(e,t){let n=t[0]+t[4]+t[8],r;if(n>0)r=Math.sqrt(n+1),e[3]=.5*r,r=.5/r,e[0]=(t[5]-t[7])*r,e[1]=(t[6]-t[2])*r,e[2]=(t[1]-t[3])*r;else{let s=0;t[4]>t[0]&&(s=1),t[8]>t[s*3+s]&&(s=2);let i=(s+1)%3,o=(s+2)%3;r=Math.sqrt(t[s*3+s]-t[i*3+i]-t[o*3+o]+1),e[s]=.5*r,r=.5/r,e[3]=(t[i*3+o]-t[o*3+i])*r,e[i]=(t[i*3+s]+t[s*3+i])*r,e[o]=(t[o*3+s]+t[s*3+o])*r}return e}var an=Ye;var fn=He,ln=Xe,hn=je,pn=Ge;var mn=We;var xn=$e;var gn=function(){let e=zt(),t=kt(1,0,0),n=kt(0,1,0);return function(r,s,i){let o=Le(s,i);return o<-.999999?(dt(e,t,s),Ie(e)<1e-6&&dt(e,n,s),Te(e,e),Dt(r,e,Math.PI),r):o>.999999?(r[0]=0,r[1]=0,r[2]=0,r[3]=1,r):(dt(e,s,i),r[0]=e[0],r[1]=e[1],r[2]=e[2],r[3]=1+o,xn(r,r))}}(),Di=function(){let e=Je(),t=Je();return function(n,r,s,i,o,c){return et(e,r,o,c),et(t,s,i,c),et(n,e,t,2*c*(1-c)),n}}(),Yi=function(){let e=ve();return function(t,n,r,s){return e[0]=r[0],e[3]=r[1],e[6]=r[2],e[1]=s[0],e[4]=s[1],e[7]=s[2],e[2]=-n[0],e[5]=-n[1],e[8]=-n[2],xn(t,Ht(t,e))}}();var Cr=[0,0,0,1],nt=class extends V{constructor(t=0,n=0,r=0,s=1){super(-0,-0,-0,-0),Array.isArray(t)&&arguments.length===1?this.copy(t):this.set(t,n,r,s)}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this.check()}set(t,n,r,s){return this[0]=t,this[1]=n,this[2]=r,this[3]=s,this.check()}fromObject(t){return this[0]=t.x,this[1]=t.y,this[2]=t.z,this[3]=t.w,this.check()}fromMatrix3(t){return Ht(this,t),this.check()}fromAxisRotation(t,n){return Dt(this,t,n),this.check()}identity(){return tn(this),this.check()}setAxisAngle(t,n){return this.fromAxisRotation(t,n)}get ELEMENTS(){return 4}get x(){return this[0]}set x(t){this[0]=y(t)}get y(){return this[1]}set y(t){this[1]=y(t)}get z(){return this[2]}set z(t){this[2]=y(t)}get w(){return this[3]}set w(t){this[3]=y(t)}len(){return pn(this)}lengthSquared(){return mn(this)}dot(t){return ln(this,t)}rotationTo(t,n){return gn(this,t,n),this.check()}add(t){return an(this,this,t),this.check()}calculateW(){return sn(this,this),this.check()}conjugate(){return cn(this,this),this.check()}invert(){return on(this,this),this.check()}lerp(t,n,r){return r===void 0?this.lerp(this,t,n):(hn(this,t,n,r),this.check())}multiplyRight(t){return Yt(this,this,t),this.check()}multiplyLeft(t){return Yt(this,t,this),this.check()}normalize(){let t=this.len(),n=t>0?1/t:0;return this[0]=this[0]*n,this[1]=this[1]*n,this[2]=this[2]*n,this[3]=this[3]*n,t===0&&(this[3]=1),this.check()}rotateX(t){return en(this,this,t),this.check()}rotateY(t){return nn(this,this,t),this.check()}rotateZ(t){return rn(this,this,t),this.check()}scale(t){return fn(this,this,t),this.check()}slerp(t,n,r){let s,i,o;switch(arguments.length){case 1:({start:s=Cr,target:i,ratio:o}=t);break;case 2:s=this,i=t,o=n;break;default:s=t,i=n,o=r}return et(this,s,i,o),this.check()}transformVector4(t,n=new G){return Qe(n,t,this),H(n,4)}lengthSq(){return this.lengthSquared()}setFromAxisAngle(t,n){return this.setAxisAngle(t,n)}premultiply(t){return this.multiplyLeft(t)}multiply(t){return this.multiplyRight(t)}};var rt=D(j(),1);var Br={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},zr={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Wt=class{name;startTime=0;playing=!0;speed=1;channels=[];constructor(t){Object.assign(this,t)}animate(t){if(!this.playing)return;let r=(t/1e3-this.startTime)*this.speed;this.channels.forEach(({sampler:s,target:i,path:o})=>{Dr(r,s,i,o),Fr(i,i._node)})}},W=class{animations;constructor(t){this.animations=t.animations.map((n,r)=>{let s=n.name||`Animation-${r}`,i=n.samplers.map(({input:c,interpolation:a="LINEAR",output:f})=>({input:dn(t.accessors[c]),interpolation:a,output:dn(t.accessors[f])})),o=n.channels.map(({sampler:c,target:a})=>({sampler:i[c],target:t.nodes[a.node],path:a.path}));return new Wt({name:s,channels:o})})}animate(t){this.setTime(t)}setTime(t){this.animations.forEach(n=>n.animate(t))}getAnimations(){return this.animations}};function dn(e){if(!e._animation){let t=zr[e.componentType],n=Br[e.type],r=n*e.count,{buffer:s,byteOffset:i}=e.bufferView.data,o=new t(s,i+(e.byteOffset||0),r);if(n===1)e._animation=Array.from(o);else{let c=[];for(let a=0;ap>=c),f=Math.max(0,a-1);if(!Array.isArray(s[i]))switch(i){case"translation":s[i]=[0,0,0];break;case"rotation":s[i]=[0,0,0,1];break;case"scale":s[i]=[1,1,1];break;default:rt.log.warn(`Bad animation path ${i}`)()}(0,rt.assert)(s[i].length===r[f].length);let l=t[f],h=t[a];switch(n){case"STEP":qr(s,i,r[f]);break;case"LINEAR":if(h>l){let p=(c-l)/(h-l);Ur(s,i,r[f],r[a],p)}break;case"CUBICSPLINE":if(h>l){let p=(c-l)/(h-l),m=h-l,x=r[3*f+1],g=r[3*f+2],d=r[3*a+0],S=r[3*a+1];Vr(s,i,{p0:x,outTangent0:g,inTangent1:d,p1:S,tDiff:m,ratio:p})}break;default:rt.log.warn(`Interpolation ${n} not supported`)();break}}var En=D(j(),1);var $t=`#if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX)) struct AmbientLight { vec3 color; }; struct PointLight { vec3 color; vec3 position; vec3 attenuation; }; struct DirectionalLight { vec3 color; vec3 direction; }; uniform AmbientLight lighting_uAmbientLight; uniform PointLight lighting_uPointLight[MAX_LIGHTS]; uniform DirectionalLight lighting_uDirectionalLight[MAX_LIGHTS]; uniform int lighting_uPointLightCount; uniform int lighting_uDirectionalLightCount; uniform bool lighting_uEnabled; float getPointLightAttenuation(PointLight pointLight, float distance) { return pointLight.attenuation.x + pointLight.attenuation.y * distance + pointLight.attenuation.z * distance * distance; } #endif `;var Yr={lightSources:{}};function Xt(e={}){let{color:t=[0,0,0],intensity:n=1}=e;return t.map(r=>r*n/255)}function Hr({ambientLight:e,pointLights:t=[],directionalLights:n=[]}){let r={};return e?r["lighting_uAmbientLight.color"]=Xt(e):r["lighting_uAmbientLight.color"]=[0,0,0],t.forEach((s,i)=>{r[`lighting_uPointLight[${i}].color`]=Xt(s),r[`lighting_uPointLight[${i}].position`]=s.position,r[`lighting_uPointLight[${i}].attenuation`]=s.attenuation||[1,0,0]}),r.lighting_uPointLightCount=t.length,n.forEach((s,i)=>{r[`lighting_uDirectionalLight[${i}].color`]=Xt(s),r[`lighting_uDirectionalLight[${i}].direction`]=s.direction}),r.lighting_uDirectionalLightCount=n.length,r}function Mn(e=Yr){if("lightSources"in e){let{ambientLight:t,pointLights:n,directionalLights:r}=e.lightSources||{};return t||n&&n.length>0||r&&r.length>0?Object.assign({},Hr({ambientLight:t,pointLights:n,directionalLights:r}),{lighting_uEnabled:!0}):{lighting_uEnabled:!1}}if("lights"in e){let t={pointLights:[],directionalLights:[]};for(let n of e.lights||[])switch(n.type){case"ambient":t.ambientLight=n;break;case"directional":t.directionalLights?.push(n);break;case"point":t.pointLights?.push(n);break;default:}return Mn({lightSources:t})}return{}}var un={name:"lights",vs:$t,fs:$t,getUniforms:Mn,defines:{MAX_LIGHTS:3}};var _n=`uniform mat4 u_MVPMatrix; uniform mat4 u_ModelMatrix; uniform mat4 u_NormalMatrix; out vec3 pbr_vPosition; out vec2 pbr_vUV; #ifdef HAS_NORMALS # ifdef HAS_TANGENTS out mat3 pbr_vTBN; # else out vec3 pbr_vNormal; # endif #endif void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv) { vec4 pos = u_ModelMatrix * position; pbr_vPosition = vec3(pos.xyz) / pos.w; #ifdef HAS_NORMALS #ifdef HAS_TANGENTS vec3 normalW = normalize(vec3(u_NormalMatrix * vec4(normal.xyz, 0.0))); vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(tangent.xyz, 0.0))); vec3 bitangentW = cross(normalW, tangentW) * tangent.w; pbr_vTBN = mat3(tangentW, bitangentW, normalW); #else pbr_vNormal = normalize(vec3(u_ModelMatrix * vec4(normal.xyz, 0.0))); #endif #endif #ifdef HAS_UV pbr_vUV = uv; #else pbr_vUV = vec2(0.,0.); #endif } `;var An=`precision highp float; uniform bool pbr_uUnlit; #ifdef USE_IBL uniform samplerCube u_DiffuseEnvSampler; uniform samplerCube u_SpecularEnvSampler; uniform sampler2D u_brdfLUT; uniform vec2 u_ScaleIBLAmbient; #endif #ifdef HAS_BASECOLORMAP uniform sampler2D u_BaseColorSampler; #endif #ifdef HAS_NORMALMAP uniform sampler2D u_NormalSampler; uniform float u_NormalScale; #endif #ifdef HAS_EMISSIVEMAP uniform sampler2D u_EmissiveSampler; uniform vec3 u_EmissiveFactor; #endif #ifdef HAS_METALROUGHNESSMAP uniform sampler2D u_MetallicRoughnessSampler; #endif #ifdef HAS_OCCLUSIONMAP uniform sampler2D u_OcclusionSampler; uniform float u_OcclusionStrength; #endif #ifdef ALPHA_CUTOFF uniform float u_AlphaCutoff; #endif uniform vec2 u_MetallicRoughnessValues; uniform vec4 u_BaseColorFactor; uniform vec3 u_Camera; #ifdef PBR_DEBUG uniform vec4 u_ScaleDiffBaseMR; uniform vec4 u_ScaleFGDSpec; #endif in vec3 pbr_vPosition; in vec2 pbr_vUV; #ifdef HAS_NORMALS #ifdef HAS_TANGENTS in mat3 pbr_vTBN; #else in vec3 pbr_vNormal; #endif #endif struct PBRInfo { float NdotL; float NdotV; float NdotH; float LdotH; float VdotH; float perceptualRoughness; float metalness; vec3 reflectance0; vec3 reflectance90; float alphaRoughness; vec3 diffuseColor; vec3 specularColor; vec3 n; vec3 v; }; const float M_PI = 3.141592653589793; const float c_MinRoughness = 0.04; vec4 SRGBtoLINEAR(vec4 srgbIn) { #ifdef MANUAL_SRGB #ifdef SRGB_FAST_APPROXIMATION vec3 linOut = pow(srgbIn.xyz,vec3(2.2)); #else vec3 bLess = step(vec3(0.04045),srgbIn.xyz); vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess ); #endif return vec4(linOut,srgbIn.w);; #else return srgbIn; #endif } vec3 getNormal() { #ifndef HAS_TANGENTS vec3 pos_dx = dFdx(pbr_vPosition); vec3 pos_dy = dFdy(pbr_vPosition); vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0)); vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0)); vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t); #ifdef HAS_NORMALS vec3 ng = normalize(pbr_vNormal); #else vec3 ng = cross(pos_dx, pos_dy); #endif t = normalize(t - ng * dot(ng, t)); vec3 b = normalize(cross(ng, t)); mat3 tbn = mat3(t, b, ng); #else mat3 tbn = pbr_vTBN; #endif #ifdef HAS_NORMALMAP vec3 n = texture(u_NormalSampler, pbr_vUV).rgb; n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0))); #else vec3 n = normalize(tbn[2].xyz); #endif return n; } #ifdef USE_IBL vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection) { float mipCount = 9.0; float lod = (pbrInputs.perceptualRoughness * mipCount); vec3 brdf = SRGBtoLINEAR(texture(u_brdfLUT, vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb; vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb; #ifdef USE_TEX_LOD vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb; #else vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb; #endif vec3 diffuse = diffuseLight * pbrInputs.diffuseColor; vec3 specular = specularLight * (pbrInputs.specularColor * brdf.x + brdf.y); diffuse *= u_ScaleIBLAmbient.x; specular *= u_ScaleIBLAmbient.y; return diffuse + specular; } #endif vec3 diffuse(PBRInfo pbrInputs) { return pbrInputs.diffuseColor / M_PI; } vec3 specularReflection(PBRInfo pbrInputs) { return pbrInputs.reflectance0 + (pbrInputs.reflectance90 - pbrInputs.reflectance0) * pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0); } float geometricOcclusion(PBRInfo pbrInputs) { float NdotL = pbrInputs.NdotL; float NdotV = pbrInputs.NdotV; float r = pbrInputs.alphaRoughness; float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL))); float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV))); return attenuationL * attenuationV; } float microfacetDistribution(PBRInfo pbrInputs) { float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness; float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0; return roughnessSq / (M_PI * f * f); } void PBRInfo_setAmbientLight(inout PBRInfo pbrInputs) { pbrInputs.NdotL = 1.0; pbrInputs.NdotH = 0.0; pbrInputs.LdotH = 0.0; pbrInputs.VdotH = 1.0; } void PBRInfo_setDirectionalLight(inout PBRInfo pbrInputs, vec3 lightDirection) { vec3 n = pbrInputs.n; vec3 v = pbrInputs.v; vec3 l = normalize(lightDirection); vec3 h = normalize(l+v); pbrInputs.NdotL = clamp(dot(n, l), 0.001, 1.0); pbrInputs.NdotH = clamp(dot(n, h), 0.0, 1.0); pbrInputs.LdotH = clamp(dot(l, h), 0.0, 1.0); pbrInputs.VdotH = clamp(dot(v, h), 0.0, 1.0); } void PBRInfo_setPointLight(inout PBRInfo pbrInputs, PointLight pointLight) { vec3 light_direction = normalize(pointLight.position - pbr_vPosition); PBRInfo_setDirectionalLight(pbrInputs, light_direction); } vec3 calculateFinalColor(PBRInfo pbrInputs, vec3 lightColor) { vec3 F = specularReflection(pbrInputs); float G = geometricOcclusion(pbrInputs); float D = microfacetDistribution(pbrInputs); vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs); vec3 specContrib = F * G * D / (4.0 * pbrInputs.NdotL * pbrInputs.NdotV); return pbrInputs.NdotL * lightColor * (diffuseContrib + specContrib); } vec4 pbr_filterColor(vec4 colorUnused) { #ifdef HAS_BASECOLORMAP vec4 baseColor = SRGBtoLINEAR(texture(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor; #else vec4 baseColor = u_BaseColorFactor; #endif #ifdef ALPHA_CUTOFF if (baseColor.a < u_AlphaCutoff) { discard; } #endif vec3 color = vec3(0, 0, 0); if(pbr_uUnlit){ color.rgb = baseColor.rgb; } else{ float perceptualRoughness = u_MetallicRoughnessValues.y; float metallic = u_MetallicRoughnessValues.x; #ifdef HAS_METALROUGHNESSMAP vec4 mrSample = texture(u_MetallicRoughnessSampler, pbr_vUV); perceptualRoughness = mrSample.g * perceptualRoughness; metallic = mrSample.b * metallic; #endif perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0); metallic = clamp(metallic, 0.0, 1.0); float alphaRoughness = perceptualRoughness * perceptualRoughness; vec3 f0 = vec3(0.04); vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0); diffuseColor *= 1.0 - metallic; vec3 specularColor = mix(f0, baseColor.rgb, metallic); float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b); float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0); vec3 specularEnvironmentR0 = specularColor.rgb; vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90; vec3 n = getNormal(); vec3 v = normalize(u_Camera - pbr_vPosition); float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0); vec3 reflection = -normalize(reflect(v, n)); PBRInfo pbrInputs = PBRInfo( 0.0, NdotV, 0.0, 0.0, 0.0, perceptualRoughness, metallic, specularEnvironmentR0, specularEnvironmentR90, alphaRoughness, diffuseColor, specularColor, n, v ); #ifdef USE_LIGHTS PBRInfo_setAmbientLight(pbrInputs); color += calculateFinalColor(pbrInputs, lighting_uAmbientLight.color); for(int i = 0; i < lighting_uDirectionalLightCount; i++) { if (i < lighting_uDirectionalLightCount) { PBRInfo_setDirectionalLight(pbrInputs, lighting_uDirectionalLight[i].direction); color += calculateFinalColor(pbrInputs, lighting_uDirectionalLight[i].color); } } for(int i = 0; i < lighting_uPointLightCount; i++) { if (i < lighting_uPointLightCount) { PBRInfo_setPointLight(pbrInputs, lighting_uPointLight[i]); float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition)); color += calculateFinalColor(pbrInputs, lighting_uPointLight[i].color / attenuation); } } #endif #ifdef USE_IBL color += getIBLContribution(pbrInputs, n, reflection); #endif #ifdef HAS_OCCLUSIONMAP float ao = texture(u_OcclusionSampler, pbr_vUV).r; color = mix(color, color * ao, u_OcclusionStrength); #endif #ifdef HAS_EMISSIVEMAP vec3 emissive = SRGBtoLINEAR(texture(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor; color += emissive; #endif #ifdef PBR_DEBUG color = mix(color, baseColor.rgb, u_ScaleDiffBaseMR.y); color = mix(color, vec3(metallic), u_ScaleDiffBaseMR.z); color = mix(color, vec3(perceptualRoughness), u_ScaleDiffBaseMR.w); #endif } return vec4(pow(color,vec3(1.0/2.2)), baseColor.a); } `;var jt={name:"pbr",vs:_n,fs:An,defines:{LIGHTING_FRAGMENT:1},dependencies:[un]};var Et=D(Pt(),1);var Gr=` #pragma vscode_glsllint_stage: vert #if (__VERSION__ < 300) #define _attr attribute #else #define _attr in #endif // _attr vec4 POSITION; _attr vec4 positions; #ifdef HAS_NORMALS // _attr vec4 NORMAL; _attr vec4 normals; #endif #ifdef HAS_TANGENTS _attr vec4 TANGENT; #endif #ifdef HAS_UV // _attr vec2 TEXCOORD_0; _attr vec2 texCoords; #endif void main(void) { vec4 _NORMAL = vec4(0.); vec4 _TANGENT = vec4(0.); vec2 _TEXCOORD_0 = vec2(0.); #ifdef HAS_NORMALS _NORMAL = normals; #endif #ifdef HAS_TANGENTS _TANGENT = TANGENT; #endif #ifdef HAS_UV _TEXCOORD_0 = texCoords; #endif pbr_setPositionNormalTangentUV(positions, _NORMAL, _TANGENT, _TEXCOORD_0); gl_Position = u_MVPMatrix * positions; } `,Wr=` #pragma vscode_glsllint_stage: frag #if (__VERSION__ < 300) #define fragmentColor gl_FragColor #else out vec4 fragmentColor; #endif void main(void) { vec3 pos = pbr_vPosition; fragmentColor = pbr_filterColor(vec4(1.0)); } `;function yn(e,t){let{id:n,geometry:r,material:s,vertexCount:i,materialOptions:o,modelOptions:c}=t,a=at(e,s,r.attributes,o);En.log.info(4,"createGLTFModel defines: ",a.defines)();let f=[],l={depthWriteEnabled:!0,depthCompare:"less",depthFormat:"depth24plus",cullMode:"back"},h={id:n,geometry:r,topology:r.topology,vertexCount:i,modules:[jt],vs:Sn(e,Gr),fs:Sn(e,Wr),...c,bindings:{...a.bindings,...c.bindings},defines:{...a.defines,...c.defines},parameters:{...l,...a.parameters,...c.parameters},uniforms:{...a.uniforms,...c.uniforms}},p=new Et.Model(e,h);return new Et.ModelNode({managedResources:f,model:p})}function Sn(e,t){return`#version 300 es ${t}`}var $r={modelOptions:{},pbrDebug:!1,imageBasedLightingEnvironment:null,lights:!0,useTangents:!1},yt=class{device;options;gltf;constructor(t,n={}){this.device=t,this.options={...$r,...n}}instantiate(t){return this.gltf=t,(t.scenes||[]).map(r=>this.createScene(r))}createAnimator(){return Array.isArray(this.gltf.animations)?new W(this.gltf):null}createScene(t){let r=(t.nodes||[]).map(i=>this.createNode(i));return new $.GroupNode({id:t.name||t.id,children:r})}createNode(t){if(!t._node){let r=(t.children||[]).map(i=>this.createNode(i));t.mesh&&r.push(this.createMesh(t.mesh));let s=new $.GroupNode({id:t.name||t.id,children:r});if(t.matrix)s.setMatrix(t.matrix);else{if(s.matrix.identity(),t.translation&&s.matrix.translate(t.translation),t.rotation){let i=new F().fromQuaternion(t.rotation);s.matrix.multiplyRight(i)}t.scale&&s.matrix.scale(t.scale)}t._node=s}return t._node}createMesh(t){if(!t._mesh){let r=(t.primitives||[]).map((i,o)=>this.createPrimitive(i,o,t)),s=new $.GroupNode({id:t.name||t.id,children:r});t._mesh=s}return t._mesh}createPrimitive(t,n,r){let s=t.name||`${r.name||r.id}-primitive-${n}`,i=Xr(t.mode||4),o=t.indices?t.indices.count:this.getVertexCount(t.attributes),c=yn(this.device,{id:s,geometry:this.createGeometry(s,t,i),material:t.material,materialOptions:this.options,modelOptions:this.options.modelOptions,vertexCount:o});return c.bounds=[t.attributes.POSITION.min,t.attributes.POSITION.max],c}getVertexCount(t){throw new Error("getVertexCount not implemented")}createGeometry(t,n,r){let s={};for(let[i,o]of Object.entries(n.attributes)){let{components:c,size:a,value:f}=o;s[i]={size:a??c,value:f}}return new $.Geometry({id:t,topology:r,indices:n.indices.value,attributes:s})}createBuffer(t,n){t.bufferView||(t.bufferView={});let{bufferView:r}=t;return r.lumaBuffers||(r.lumaBuffers={}),r.lumaBuffers[n]||(r.lumaBuffers[n]=this.device.createBuffer({id:`from-${r.id}`,data:r.data||t.value})),r.lumaBuffers[n]}createSampler(t){return t}needsPOT(){return!1}},U;(function(e){e[e.POINTS=0]="POINTS",e[e.LINES=1]="LINES",e[e.LINE_LOOP=2]="LINE_LOOP",e[e.LINE_STRIP=3]="LINE_STRIP",e[e.TRIANGLES=4]="TRIANGLES",e[e.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",e[e.TRIANGLE_FAN=6]="TRIANGLE_FAN"})(U||(U={}));function Xr(e){switch(e){case U.POINTS:return"point-list";case U.LINES:return"line-list";case U.LINE_STRIP:return"line-strip";case U.LINE_LOOP:return"line-loop-webgl";case U.TRIANGLES:return"triangle-list";case U.TRIANGLE_STRIP:return"triangle-strip";case U.TRIANGLE_FAN:return"triangle-fan-webgl";default:throw new Error(e)}}function Tn(e,t,n){let r=new yt(e,n),s=r.instantiate(t),i=r.createAnimator();return{scenes:s,animator:i}}return bn(st);})(); return __exports__; });