UNPKG

@deck.gl/mesh-layers

Version:

deck.gl layers that loads 3D meshes or scene graphs

580 lines (493 loc) 181 kB
(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['deck'] = factory(); else root['deck'] = factory();})(globalThis, function () { "use strict";var __exports__=(()=>{var Mi=Object.create;var ee=Object.defineProperty;var Ci=Object.getOwnPropertyDescriptor;var Ei=Object.getOwnPropertyNames;var _i=Object.getPrototypeOf,Ti=Object.prototype.hasOwnProperty;var He=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),N=(e,t)=>{for(var n in t)ee(e,n,{get:t[n],enumerable:!0})},te=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ei(t))!Ti.call(e,s)&&s!==n&&ee(e,s,{get:()=>t[s],enumerable:!(r=Ci(t,s))||r.enumerable});return e},tt=(e,t,n)=>(te(e,t,"default"),n&&te(n,t,"default")),F=(e,t,n)=>(n=e!=null?Mi(_i(e)):{},te(t||!e||!e.__esModule?ee(n,"default",{value:e,enumerable:!0}):n,e)),yi=e=>te(ee({},"__esModule",{value:!0}),e);var At=He((Ul,or)=>{or.exports=globalThis.deck});var pt=He((Jl,cr)=>{cr.exports=globalThis.luma});var Dt=He((Kl,ar)=>{ar.exports=globalThis.luma});var $t={};N($t,{ScenegraphLayer:()=>xi,SimpleMeshLayer:()=>Ss});var j={},ir=F(At(),1);tt(j,F(At(),1));if(!ir.Layer)throw new Error("@deck.gl/core is not found");tt($t,j);var nt=F(At(),1),Is=F(pt(),1),Bt=F(Dt(),1);var Xl=1/Math.PI*180,Vl=1/180*Math.PI,bi={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...bi}};var R=globalThis.mathgl.config;function fr(e,{precision:t=R.precision}={}){return e=Ri(e),`${parseFloat(e.toPrecision(t))}`}function mt(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Je(e,t,n){let r=R.EPSILON;n&&(R.EPSILON=n);try{if(e===t)return!0;if(mt(e)&&mt(t)){if(e.length!==t.length)return!1;for(let s=0;s<e.length;++s)if(!Je(e[s],t[s]))return!1;return!0}return e&&e.equals?e.equals(t):t&&t.equals?t.equals(e):typeof e=="number"&&typeof t=="number"?Math.abs(e-t)<=R.EPSILON*Math.max(1,Math.abs(e),Math.abs(t)):!1}finally{R.EPSILON=r}}function Ri(e){return Math.round(e/R.EPSILON)*R.EPSILON}var et=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,n=0){for(let r=0;r<this.ELEMENTS;++r)this[r]=t[r+n];return this.check()}toArray(t=[],n=0){for(let r=0;r<this.ELEMENTS;++r)t[n+r]=this[r];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:mt(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(R)}formatString(t){let n="";for(let r=0;r<this.ELEMENTS;++r)n+=(r>0?", ":"")+fr(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<this.ELEMENTS;++n)if(!Je(this[n],t[n]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(this[n]!==t[n])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,n,r){if(r===void 0)return this.lerp(this,t,n);for(let s=0;s<this.ELEMENTS;++s){let o=t[s],i=typeof n=="number"?n:n[s];this[s]=o+r*(i-o)}return this.check()}min(t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(t[n],this[n]);return this.check()}max(t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.max(t[n],this[n]);return this.check()}clamp(t,n){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],t[r]),n[r]);return this.check()}add(...t){for(let n of t)for(let r=0;r<this.ELEMENTS;++r)this[r]+=n[r];return this.check()}subtract(...t){for(let n of t)for(let r=0;r<this.ELEMENTS;++r)this[r]-=n[r];return this.check()}scale(t){if(typeof t=="number")for(let n=0;n<this.ELEMENTS;++n)this[n]*=t;else for(let n=0;n<this.ELEMENTS&&n<t.length;++n)this[n]*=t[n];return this.check()}multiplyByScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]*=t;return this.check()}check(){if(R.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let n=0;n<this.ELEMENTS;++n)t=t&&Number.isFinite(this[n]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]=t;return this.check()}addScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,n){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],t),n);return this.check()}get elements(){return this}};function Ii(e,t){if(e.length!==t)return!1;for(let n=0;n<e.length;++n)if(!Number.isFinite(e[n]))return!1;return!0}function y(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function dt(e,t,n=""){if(R.debug&&!Ii(e,t))throw new Error(`math.gl: ${n} some fields set to invalid numbers'`);return e}function Ke(e,t){if(!e)throw new Error(`math.gl assertion ${t}`)}var ne=class extends et{get x(){return this[0]}set x(t){this[0]=y(t)}get y(){return this[1]}set y(t){this[1]=y(t)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let t=0;for(let n=0;n<this.ELEMENTS;++n)t+=this[n]*this[n];return t}magnitudeSquared(){return this.lengthSquared()}distance(t){return Math.sqrt(this.distanceSquared(t))}distanceSquared(t){let n=0;for(let r=0;r<this.ELEMENTS;++r){let s=this[r]-t[r];n+=s*s}return y(n)}dot(t){let n=0;for(let r=0;r<this.ELEMENTS;++r)n+=this[r]*t[r];return y(n)}normalize(){let t=this.magnitude();if(t!==0)for(let n=0;n<this.ELEMENTS;++n)this[n]/=t;return this.check()}multiply(...t){for(let n of t)for(let r=0;r<this.ELEMENTS;++r)this[r]*=n[r];return this.check()}divide(...t){for(let n of t)for(let r=0;r<this.ELEMENTS;++r)this[r]/=n[r];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(t){return this.distance(t)}distanceToSquared(t){return this.distanceSquared(t)}getComponent(t){return Ke(t>=0&&t<this.ELEMENTS,"index is out of range"),y(this[t])}setComponent(t,n){return Ke(t>=0&&t<this.ELEMENTS,"index is out of range"),this[t]=n,this.check()}addVectors(t,n){return this.copy(t).add(n)}subVectors(t,n){return this.copy(t).subtract(n)}multiplyVectors(t,n){return this.copy(t).multiply(n)}addScaledVector(t,n){return this.add(new this.constructor(t).multiplyScalar(n))}};var S=typeof Float32Array<"u"?Float32Array:Array;var eh=Math.PI/180;function Si(){let e=new S(2);return S!=Float32Array&&(e[0]=0,e[1]=0),e}function Ar(e,t,n){let r=t[0],s=t[1];return e[0]=n[0]*r+n[4]*s+n[12],e[1]=n[1]*r+n[5]*s+n[13],e}var nh=function(){let e=Si();return function(t,n,r,s,o,i){let c,a;for(n||(n=2),r||(r=0),s?a=Math.min(s*n+r,t.length):a=t.length,c=r;c<a;c+=n)e[0]=t[c],e[1]=t[c+1],o(e,e,i),t[c]=e[0],t[c+1]=e[1];return t}}();function pr(e,t,n){let r=t[0],s=t[1],o=n[3]*r+n[7]*s||1;return e[0]=(n[0]*r+n[4]*s)/o,e[1]=(n[1]*r+n[5]*s)/o,e}function mr(e,t,n){let r=t[0],s=t[1],o=t[2],i=n[3]*r+n[7]*s+n[11]*o||1;return e[0]=(n[0]*r+n[4]*s+n[8]*o)/i,e[1]=(n[1]*r+n[5]*s+n[9]*o)/i,e[2]=(n[2]*r+n[6]*s+n[10]*o)/i,e}function dr(e,t,n){let r=t[0],s=t[1];return e[0]=n[0]*r+n[2]*s,e[1]=n[1]*r+n[3]*s,e[2]=t[2],e[3]=t[3],e}function ur(e,t,n){let r=t[0],s=t[1],o=t[2];return e[0]=n[0]*r+n[3]*s+n[6]*o,e[1]=n[1]*r+n[4]*s+n[7]*o,e[2]=n[2]*r+n[5]*s+n[8]*o,e[3]=t[3],e}function Xe(){let e=new S(3);return S!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function Li(e){let t=e[0],n=e[1],r=e[2];return Math.sqrt(t*t+n*n+r*r)}function Ve(e,t,n){let r=new S(3);return r[0]=e,r[1]=t,r[2]=n,r}function gr(e,t){let n=t[0],r=t[1],s=t[2],o=n*n+r*r+s*s;return o>0&&(o=1/Math.sqrt(o)),e[0]=t[0]*o,e[1]=t[1]*o,e[2]=t[2]*o,e}function Br(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function re(e,t,n){let r=t[0],s=t[1],o=t[2],i=n[0],c=n[1],a=n[2];return e[0]=s*a-o*c,e[1]=o*i-r*a,e[2]=r*c-s*i,e}function se(e,t,n){let r=t[0],s=t[1],o=t[2],i=n[3]*r+n[7]*s+n[11]*o+n[15];return i=i||1,e[0]=(n[0]*r+n[4]*s+n[8]*o+n[12])/i,e[1]=(n[1]*r+n[5]*s+n[9]*o+n[13])/i,e[2]=(n[2]*r+n[6]*s+n[10]*o+n[14])/i,e}function xr(e,t,n){let r=n[0],s=n[1],o=n[2],i=n[3],c=t[0],a=t[1],f=t[2],l=s*f-o*a,h=o*c-r*f,A=r*a-s*c,p=s*A-o*h,m=o*l-r*A,d=r*h-s*l,u=i*2;return l*=u,h*=u,A*=u,p*=2,m*=2,d*=2,e[0]=c+l+p,e[1]=a+h+m,e[2]=f+A+d,e}var Mr=Li;var oh=function(){let e=Xe();return function(t,n,r,s,o,i){let c,a;for(n||(n=3),r||(r=0),s?a=Math.min(s*n+r,t.length):a=t.length,c=r;c<a;c+=n)e[0]=t[c],e[1]=t[c+1],e[2]=t[c+2],o(e,e,i),t[c]=e[0],t[c+1]=e[1],t[c+2]=e[2];return t}}();var oe,ut=class extends ne{static get ZERO(){return oe||(oe=new ut(0,0,0,0),Object.freeze(oe)),oe}constructor(t=0,n=0,r=0,s=0){super(-0,-0,-0,-0),mt(t)&&arguments.length===1?this.copy(t):(R.debug&&(y(t),y(n),y(r),y(s)),this[0]=t,this[1]=n,this[2]=r,this[3]=s)}set(t,n,r,s){return this[0]=t,this[1]=n,this[2]=r,this[3]=s,this.check()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this.check()}fromObject(t){return R.debug&&(y(t.x),y(t.y),y(t.z),y(t.w)),this[0]=t.x,this[1]=t.y,this[2]=t.z,this[3]=t.w,this}toObject(t){return t.x=this[0],t.y=this[1],t.z=this[2],t.w=this[3],t}get ELEMENTS(){return 4}get z(){return this[2]}set z(t){this[2]=y(t)}get w(){return this[3]}set w(t){this[3]=y(t)}transform(t){return se(this,this,t),this.check()}transformByMatrix3(t){return ur(this,this,t),this.check()}transformByMatrix2(t){return dr(this,this,t),this.check()}transformByQuaternion(t){return xr(this,this,t),this.check()}applyMatrix4(t){return t.transform(this,this),this}};var ie=class extends et{toString(){let t="[";if(R.printRowMajor){t+="row-major:";for(let n=0;n<this.RANK;++n)for(let r=0;r<this.RANK;++r)t+=` ${this[r*this.RANK+n]}`}else{t+="column-major:";for(let n=0;n<this.ELEMENTS;++n)t+=` ${this[n]}`}return t+="]",t}getElementIndex(t,n){return n*this.RANK+t}getElement(t,n){return this[n*this.RANK+t]}setElement(t,n,r){return this[n*this.RANK+t]=y(r),this}getColumn(t,n=new Array(this.RANK).fill(-0)){let r=t*this.RANK;for(let s=0;s<this.RANK;++s)n[s]=this[r+s];return n}setColumn(t,n){let r=t*this.RANK;for(let s=0;s<this.RANK;++s)this[r+s]=n[s];return this}};function Cr(){let e=new S(9);return S!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[5]=0,e[6]=0,e[7]=0),e[0]=1,e[4]=1,e[8]=1,e}function Oi(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Er(e,t){if(e===t){let n=t[1],r=t[2],s=t[3],o=t[6],i=t[7],c=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=n,e[6]=t[9],e[7]=t[13],e[8]=r,e[9]=o,e[11]=t[14],e[12]=s,e[13]=i,e[14]=c}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e}function _r(e,t){let n=t[0],r=t[1],s=t[2],o=t[3],i=t[4],c=t[5],a=t[6],f=t[7],l=t[8],h=t[9],A=t[10],p=t[11],m=t[12],d=t[13],u=t[14],B=t[15],E=n*c-r*i,g=n*a-s*i,x=n*f-o*i,M=r*a-s*c,C=r*f-o*c,O=s*f-o*a,G=l*d-h*m,v=l*u-A*m,P=l*B-p*m,J=h*u-A*d,K=h*B-p*d,X=A*B-p*u,T=E*X-g*K+x*J+M*P-C*v+O*G;return T?(T=1/T,e[0]=(c*X-a*K+f*J)*T,e[1]=(s*K-r*X-o*J)*T,e[2]=(d*O-u*C+B*M)*T,e[3]=(A*C-h*O-p*M)*T,e[4]=(a*P-i*X-f*v)*T,e[5]=(n*X-s*P+o*v)*T,e[6]=(u*x-m*O-B*g)*T,e[7]=(l*O-A*x+p*g)*T,e[8]=(i*K-c*P+f*G)*T,e[9]=(r*P-n*K-o*G)*T,e[10]=(m*C-d*x+B*E)*T,e[11]=(h*x-l*C-p*E)*T,e[12]=(c*v-i*J-a*G)*T,e[13]=(n*J-r*v+s*G)*T,e[14]=(d*g-m*M-u*E)*T,e[15]=(l*M-h*g+A*E)*T,e):null}function Tr(e){let t=e[0],n=e[1],r=e[2],s=e[3],o=e[4],i=e[5],c=e[6],a=e[7],f=e[8],l=e[9],h=e[10],A=e[11],p=e[12],m=e[13],d=e[14],u=e[15],B=t*i-n*o,E=t*c-r*o,g=n*c-r*i,x=f*m-l*p,M=f*d-h*p,C=l*d-h*m,O=t*C-n*M+r*x,G=o*C-i*M+c*x,v=f*g-l*E+h*B,P=p*g-m*E+d*B;return a*O-s*G+u*v-A*P}function je(e,t,n){let r=t[0],s=t[1],o=t[2],i=t[3],c=t[4],a=t[5],f=t[6],l=t[7],h=t[8],A=t[9],p=t[10],m=t[11],d=t[12],u=t[13],B=t[14],E=t[15],g=n[0],x=n[1],M=n[2],C=n[3];return e[0]=g*r+x*c+M*h+C*d,e[1]=g*s+x*a+M*A+C*u,e[2]=g*o+x*f+M*p+C*B,e[3]=g*i+x*l+M*m+C*E,g=n[4],x=n[5],M=n[6],C=n[7],e[4]=g*r+x*c+M*h+C*d,e[5]=g*s+x*a+M*A+C*u,e[6]=g*o+x*f+M*p+C*B,e[7]=g*i+x*l+M*m+C*E,g=n[8],x=n[9],M=n[10],C=n[11],e[8]=g*r+x*c+M*h+C*d,e[9]=g*s+x*a+M*A+C*u,e[10]=g*o+x*f+M*p+C*B,e[11]=g*i+x*l+M*m+C*E,g=n[12],x=n[13],M=n[14],C=n[15],e[12]=g*r+x*c+M*h+C*d,e[13]=g*s+x*a+M*A+C*u,e[14]=g*o+x*f+M*p+C*B,e[15]=g*i+x*l+M*m+C*E,e}function yr(e,t,n){let r=n[0],s=n[1],o=n[2],i,c,a,f,l,h,A,p,m,d,u,B;return t===e?(e[12]=t[0]*r+t[4]*s+t[8]*o+t[12],e[13]=t[1]*r+t[5]*s+t[9]*o+t[13],e[14]=t[2]*r+t[6]*s+t[10]*o+t[14],e[15]=t[3]*r+t[7]*s+t[11]*o+t[15]):(i=t[0],c=t[1],a=t[2],f=t[3],l=t[4],h=t[5],A=t[6],p=t[7],m=t[8],d=t[9],u=t[10],B=t[11],e[0]=i,e[1]=c,e[2]=a,e[3]=f,e[4]=l,e[5]=h,e[6]=A,e[7]=p,e[8]=m,e[9]=d,e[10]=u,e[11]=B,e[12]=i*r+l*s+m*o+t[12],e[13]=c*r+h*s+d*o+t[13],e[14]=a*r+A*s+u*o+t[14],e[15]=f*r+p*s+B*o+t[15]),e}function br(e,t,n){let r=n[0],s=n[1],o=n[2];return e[0]=t[0]*r,e[1]=t[1]*r,e[2]=t[2]*r,e[3]=t[3]*r,e[4]=t[4]*s,e[5]=t[5]*s,e[6]=t[6]*s,e[7]=t[7]*s,e[8]=t[8]*o,e[9]=t[9]*o,e[10]=t[10]*o,e[11]=t[11]*o,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function Rr(e,t,n,r){let s=r[0],o=r[1],i=r[2],c=Math.sqrt(s*s+o*o+i*i),a,f,l,h,A,p,m,d,u,B,E,g,x,M,C,O,G,v,P,J,K,X,T,Ft;return c<1e-6?null:(c=1/c,s*=c,o*=c,i*=c,f=Math.sin(n),a=Math.cos(n),l=1-a,h=t[0],A=t[1],p=t[2],m=t[3],d=t[4],u=t[5],B=t[6],E=t[7],g=t[8],x=t[9],M=t[10],C=t[11],O=s*s*l+a,G=o*s*l+i*f,v=i*s*l-o*f,P=s*o*l-i*f,J=o*o*l+a,K=i*o*l+s*f,X=s*i*l+o*f,T=o*i*l-s*f,Ft=i*i*l+a,e[0]=h*O+d*G+g*v,e[1]=A*O+u*G+x*v,e[2]=p*O+B*G+M*v,e[3]=m*O+E*G+C*v,e[4]=h*P+d*J+g*K,e[5]=A*P+u*J+x*K,e[6]=p*P+B*J+M*K,e[7]=m*P+E*J+C*K,e[8]=h*X+d*T+g*Ft,e[9]=A*X+u*T+x*Ft,e[10]=p*X+B*T+M*Ft,e[11]=m*X+E*T+C*Ft,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function Ir(e,t,n){let r=Math.sin(n),s=Math.cos(n),o=t[4],i=t[5],c=t[6],a=t[7],f=t[8],l=t[9],h=t[10],A=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=o*s+f*r,e[5]=i*s+l*r,e[6]=c*s+h*r,e[7]=a*s+A*r,e[8]=f*s-o*r,e[9]=l*s-i*r,e[10]=h*s-c*r,e[11]=A*s-a*r,e}function Sr(e,t,n){let r=Math.sin(n),s=Math.cos(n),o=t[0],i=t[1],c=t[2],a=t[3],f=t[8],l=t[9],h=t[10],A=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=o*s-f*r,e[1]=i*s-l*r,e[2]=c*s-h*r,e[3]=a*s-A*r,e[8]=o*r+f*s,e[9]=i*r+l*s,e[10]=c*r+h*s,e[11]=a*r+A*s,e}function Lr(e,t,n){let r=Math.sin(n),s=Math.cos(n),o=t[0],i=t[1],c=t[2],a=t[3],f=t[4],l=t[5],h=t[6],A=t[7];return t!==e&&(e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=o*s+f*r,e[1]=i*s+l*r,e[2]=c*s+h*r,e[3]=a*s+A*r,e[4]=f*s-o*r,e[5]=l*s-i*r,e[6]=h*s-c*r,e[7]=A*s-a*r,e}function Fr(e,t){let n=t[0],r=t[1],s=t[2],o=t[3],i=n+n,c=r+r,a=s+s,f=n*i,l=r*i,h=r*c,A=s*i,p=s*c,m=s*a,d=o*i,u=o*c,B=o*a;return e[0]=1-h-m,e[1]=l+B,e[2]=A-u,e[3]=0,e[4]=l-B,e[5]=1-f-m,e[6]=p+d,e[7]=0,e[8]=A+u,e[9]=p-d,e[10]=1-f-h,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Dr(e,t,n,r,s,o,i){let c=1/(n-t),a=1/(s-r),f=1/(o-i);return e[0]=o*2*c,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=o*2*a,e[6]=0,e[7]=0,e[8]=(n+t)*c,e[9]=(s+r)*a,e[10]=(i+o)*f,e[11]=-1,e[12]=0,e[13]=0,e[14]=i*o*2*f,e[15]=0,e}function Gi(e,t,n,r,s){let o=1/Math.tan(t/2);if(e[0]=o/n,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=o,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,s!=null&&s!==1/0){let i=1/(r-s);e[10]=(s+r)*i,e[14]=2*s*r*i}else e[10]=-1,e[14]=-2*r;return e}var Or=Gi;function vi(e,t,n,r,s,o,i){let c=1/(t-n),a=1/(r-s),f=1/(o-i);return e[0]=-2*c,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*a,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*f,e[11]=0,e[12]=(t+n)*c,e[13]=(s+r)*a,e[14]=(i+o)*f,e[15]=1,e}var Gr=vi;function vr(e,t,n,r){let s,o,i,c,a,f,l,h,A,p,m=t[0],d=t[1],u=t[2],B=r[0],E=r[1],g=r[2],x=n[0],M=n[1],C=n[2];return Math.abs(m-x)<1e-6&&Math.abs(d-M)<1e-6&&Math.abs(u-C)<1e-6?Oi(e):(h=m-x,A=d-M,p=u-C,s=1/Math.sqrt(h*h+A*A+p*p),h*=s,A*=s,p*=s,o=E*p-g*A,i=g*h-B*p,c=B*A-E*h,s=Math.sqrt(o*o+i*i+c*c),s?(s=1/s,o*=s,i*=s,c*=s):(o=0,i=0,c=0),a=A*c-p*i,f=p*o-h*c,l=h*i-A*o,s=Math.sqrt(a*a+f*f+l*l),s?(s=1/s,a*=s,f*=s,l*=s):(a=0,f=0,l=0),e[0]=o,e[1]=a,e[2]=h,e[3]=0,e[4]=i,e[5]=f,e[6]=A,e[7]=0,e[8]=c,e[9]=l,e[10]=p,e[11]=0,e[12]=-(o*m+i*d+c*u),e[13]=-(a*m+f*d+l*u),e[14]=-(h*m+A*d+p*u),e[15]=1,e)}function Pi(){let e=new S(4);return S!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function Pr(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e[3]=t[3]+n[3],e}function wr(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e}function Nr(e){let t=e[0],n=e[1],r=e[2],s=e[3];return Math.sqrt(t*t+n*n+r*r+s*s)}function Ur(e){let t=e[0],n=e[1],r=e[2],s=e[3];return t*t+n*n+r*r+s*s}function Hr(e,t){let n=t[0],r=t[1],s=t[2],o=t[3],i=n*n+r*r+s*s+o*o;return i>0&&(i=1/Math.sqrt(i)),e[0]=n*i,e[1]=r*i,e[2]=s*i,e[3]=o*i,e}function Jr(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]}function Kr(e,t,n,r){let s=t[0],o=t[1],i=t[2],c=t[3];return e[0]=s+r*(n[0]-s),e[1]=o+r*(n[1]-o),e[2]=i+r*(n[2]-i),e[3]=c+r*(n[3]-c),e}function Xr(e,t,n){let r=t[0],s=t[1],o=t[2],i=t[3];return e[0]=n[0]*r+n[4]*s+n[8]*o+n[12]*i,e[1]=n[1]*r+n[5]*s+n[9]*o+n[13]*i,e[2]=n[2]*r+n[6]*s+n[10]*o+n[14]*i,e[3]=n[3]*r+n[7]*s+n[11]*o+n[15]*i,e}function Vr(e,t,n){let r=t[0],s=t[1],o=t[2],i=n[0],c=n[1],a=n[2],f=n[3],l=f*r+c*o-a*s,h=f*s+a*r-i*o,A=f*o+i*s-c*r,p=-i*r-c*s-a*o;return e[0]=l*f+p*-i+h*-a-A*-c,e[1]=h*f+p*-c+A*-i-l*-a,e[2]=A*f+p*-a+l*-c-h*-i,e[3]=t[3],e}var gh=function(){let e=Pi();return function(t,n,r,s,o,i){let c,a;for(n||(n=4),r||(r=0),s?a=Math.min(s*n+r,t.length):a=t.length,c=r;c<a;c+=n)e[0]=t[c],e[1]=t[c+1],e[2]=t[c+2],e[3]=t[c+3],o(e,e,i),t[c]=e[0],t[c+1]=e[1],t[c+2]=e[2],t[c+3]=e[3];return t}}();var ze;(function(e){e[e.COL0ROW0=0]="COL0ROW0",e[e.COL0ROW1=1]="COL0ROW1",e[e.COL0ROW2=2]="COL0ROW2",e[e.COL0ROW3=3]="COL0ROW3",e[e.COL1ROW0=4]="COL1ROW0",e[e.COL1ROW1=5]="COL1ROW1",e[e.COL1ROW2=6]="COL1ROW2",e[e.COL1ROW3=7]="COL1ROW3",e[e.COL2ROW0=8]="COL2ROW0",e[e.COL2ROW1=9]="COL2ROW1",e[e.COL2ROW2=10]="COL2ROW2",e[e.COL2ROW3=11]="COL2ROW3",e[e.COL3ROW0=12]="COL3ROW0",e[e.COL3ROW1=13]="COL3ROW1",e[e.COL3ROW2=14]="COL3ROW2",e[e.COL3ROW3=15]="COL3ROW3"})(ze||(ze={}));var Ni=45*Math.PI/180,Ui=1,ke=.1,Ye=500,Hi=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),Z=class extends ie{static get IDENTITY(){return Ki()}static get ZERO(){return Ji()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return ze}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,n,r,s,o,i,c,a,f,l,h,A,p,m,d,u){return this[0]=t,this[1]=n,this[2]=r,this[3]=s,this[4]=o,this[5]=i,this[6]=c,this[7]=a,this[8]=f,this[9]=l,this[10]=h,this[11]=A,this[12]=p,this[13]=m,this[14]=d,this[15]=u,this.check()}setRowMajor(t,n,r,s,o,i,c,a,f,l,h,A,p,m,d,u){return this[0]=t,this[1]=o,this[2]=f,this[3]=p,this[4]=n,this[5]=i,this[6]=l,this[7]=m,this[8]=r,this[9]=c,this[10]=h,this[11]=d,this[12]=s,this[13]=a,this[14]=A,this[15]=u,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(Hi)}fromObject(t){return this.check()}fromQuaternion(t){return Fr(this,t),this.check()}frustum(t){let{left:n,right:r,bottom:s,top:o,near:i=ke,far:c=Ye}=t;return c===1/0?Xi(this,n,r,s,o,i):Dr(this,n,r,s,o,i,c),this.check()}lookAt(t){let{eye:n,center:r=[0,0,0],up:s=[0,1,0]}=t;return vr(this,n,r,s),this.check()}ortho(t){let{left:n,right:r,bottom:s,top:o,near:i=ke,far:c=Ye}=t;return Gr(this,n,r,s,o,i,c),this.check()}orthographic(t){let{fovy:n=Ni,aspect:r=Ui,focalDistance:s=1,near:o=ke,far:i=Ye}=t;jr(n);let c=n/2,a=s*Math.tan(c),f=a*r;return this.ortho({left:-f,right:f,bottom:-a,top:a,near:o,far:i})}perspective(t){let{fovy:n=45*Math.PI/180,aspect:r=1,near:s=.1,far:o=500}=t;return jr(n),Or(this,n,r,s,o),this.check()}determinant(){return Tr(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,n){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let r=this.getScale(n),s=1/r[0],o=1/r[1],i=1/r[2];return t[0]=this[0]*s,t[1]=this[1]*o,t[2]=this[2]*i,t[3]=0,t[4]=this[4]*s,t[5]=this[5]*o,t[6]=this[6]*i,t[7]=0,t[8]=this[8]*s,t[9]=this[9]*o,t[10]=this[10]*i,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,n){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let r=this.getScale(n),s=1/r[0],o=1/r[1],i=1/r[2];return t[0]=this[0]*s,t[1]=this[1]*o,t[2]=this[2]*i,t[3]=this[4]*s,t[4]=this[5]*o,t[5]=this[6]*i,t[6]=this[8]*s,t[7]=this[9]*o,t[8]=this[10]*i,t}transpose(){return Er(this,this),this.check()}invert(){return _r(this,this),this.check()}multiplyLeft(t){return je(this,t,this),this.check()}multiplyRight(t){return je(this,this,t),this.check()}rotateX(t){return Ir(this,this,t),this.check()}rotateY(t){return Sr(this,this,t),this.check()}rotateZ(t){return Lr(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,n){return Rr(this,this,t,n),this.check()}scale(t){return br(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return yr(this,this,t),this.check()}transform(t,n){return t.length===4?(n=Xr(n||[-0,-0,-0,-0],t,this),dt(n,4),n):this.transformAsPoint(t,n)}transformAsPoint(t,n){let{length:r}=t,s;switch(r){case 2:s=Ar(n||[-0,-0],t,this);break;case 3:s=se(n||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return dt(s,t.length),s}transformAsVector(t,n){let r;switch(t.length){case 2:r=pr(n||[-0,-0],t,this);break;case 3:r=mr(n||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return dt(r,t.length),r}transformPoint(t,n){return this.transformAsPoint(t,n)}transformVector(t,n){return this.transformAsPoint(t,n)}transformDirection(t,n){return this.transformAsVector(t,n)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,n,r){return this.identity().translate([t,n,r])}},ce,ae;function Ji(){return ce||(ce=new Z([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(ce)),ce}function Ki(){return ae||(ae=new Z,Object.freeze(ae)),ae}function jr(e){if(e>Math.PI*2)throw Error("expected radians")}function Xi(e,t,n,r,s,o){let i=2*o/(n-t),c=2*o/(s-r),a=(n+t)/(n-t),f=(s+r)/(s-r),l=-1,h=-1,A=-2*o;return e[0]=i,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]=A,e[15]=0,e}function kr(){let e=new S(4);return S!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}function Yr(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e}function Qe(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 We(e,t,n){let r=t[0],s=t[1],o=t[2],i=t[3],c=n[0],a=n[1],f=n[2],l=n[3];return e[0]=r*l+i*c+s*f-o*a,e[1]=s*l+i*a+o*c-r*f,e[2]=o*l+i*f+r*a-s*c,e[3]=i*l-r*c-s*a-o*f,e}function zr(e,t,n){n*=.5;let r=t[0],s=t[1],o=t[2],i=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]=o*a-s*c,e[3]=i*a-r*c,e}function Qr(e,t,n){n*=.5;let r=t[0],s=t[1],o=t[2],i=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]=o*a+r*c,e[3]=i*a-s*c,e}function Wr(e,t,n){n*=.5;let r=t[0],s=t[1],o=t[2],i=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]=o*a+i*c,e[3]=i*a-o*c,e}function qr(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 Gt(e,t,n,r){let s=t[0],o=t[1],i=t[2],c=t[3],a=n[0],f=n[1],l=n[2],h=n[3],A,p,m,d,u;return A=s*a+o*f+i*l+c*h,A<0&&(A=-A,a=-a,f=-f,l=-l,h=-h),1-A>1e-6?(p=Math.acos(A),u=Math.sin(p),m=Math.sin((1-r)*p)/u,d=Math.sin(r*p)/u):(m=1-r,d=r),e[0]=m*s+d*a,e[1]=m*o+d*f,e[2]=m*i+d*l,e[3]=m*c+d*h,e}function Zr(e,t){let n=t[0],r=t[1],s=t[2],o=t[3],i=n*n+r*r+s*s+o*o,c=i?1/i:0;return e[0]=-n*c,e[1]=-r*c,e[2]=-s*c,e[3]=o*c,e}function $r(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e}function qe(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 o=(s+1)%3,i=(s+2)%3;r=Math.sqrt(t[s*3+s]-t[o*3+o]-t[i*3+i]+1),e[s]=.5*r,r=.5/r,e[3]=(t[o*3+i]-t[i*3+o])*r,e[o]=(t[o*3+s]+t[s*3+o])*r,e[i]=(t[i*3+s]+t[s*3+i])*r}return e}var ts=Pr;var es=wr,ns=Jr,rs=Kr,ss=Nr;var os=Ur;var is=Hr;var cs=function(){let e=Xe(),t=Ve(1,0,0),n=Ve(0,1,0);return function(r,s,o){let i=Br(s,o);return i<-.999999?(re(e,t,s),Mr(e)<1e-6&&re(e,n,s),gr(e,e),Qe(r,e,Math.PI),r):i>.999999?(r[0]=0,r[1]=0,r[2]=0,r[3]=1,r):(re(e,s,o),r[0]=e[0],r[1]=e[1],r[2]=e[2],r[3]=1+i,is(r,r))}}(),Fh=function(){let e=kr(),t=kr();return function(n,r,s,o,i,c){return Gt(e,r,i,c),Gt(t,s,o,c),Gt(n,e,t,2*c*(1-c)),n}}(),Dh=function(){let e=Cr();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],is(t,qe(t,e))}}();var Vi=[0,0,0,1],vt=class extends et{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 qe(this,t),this.check()}fromAxisRotation(t,n){return Qe(this,t,n),this.check()}identity(){return Yr(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 ss(this)}lengthSquared(){return os(this)}dot(t){return ns(this,t)}rotationTo(t,n){return cs(this,t,n),this.check()}add(t){return ts(this,this,t),this.check()}calculateW(){return qr(this,this),this.check()}conjugate(){return $r(this,this),this.check()}invert(){return Zr(this,this),this.check()}lerp(t,n,r){return r===void 0?this.lerp(this,t,n):(rs(this,t,n,r),this.check())}multiplyRight(t){return We(this,this,t),this.check()}multiplyLeft(t){return We(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 zr(this,this,t),this.check()}rotateY(t){return Qr(this,this,t),this.check()}rotateZ(t){return Wr(this,this,t),this.check()}scale(t){return es(this,this,t),this.check()}slerp(t,n,r){let s,o,i;switch(arguments.length){case 1:({start:s=Vi,target:o,ratio:i}=t);break;case 2:s=this,o=t,i=n;break;default:s=t,o=n,i=r}return Gt(this,s,o,i),this.check()}transformVector4(t,n=new ut){return Vr(n,t,this),dt(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 fs=F(pt(),1);var Ze=`precision highp int; // #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; // 2nd order x:Constant-y:Linear-z:Exponential }; struct DirectionalLight { vec3 color; vec3 direction; }; uniform lightingUniforms { int enabled; int lightType; int directionalLightCount; int pointLightCount; vec3 ambientColor; vec3 lightColor0; vec3 lightPosition0; vec3 lightDirection0; vec3 lightAttenuation0; vec3 lightColor1; vec3 lightPosition1; vec3 lightDirection1; vec3 lightAttenuation1; vec3 lightColor2; vec3 lightPosition2; vec3 lightDirection2; vec3 lightAttenuation2; } lighting; PointLight lighting_getPointLight(int index) { switch (index) { case 0: return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0); case 1: return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1); case 2: default: return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2); } } DirectionalLight lighting_getDirectionalLight(int index) { switch (index) { case 0: return DirectionalLight(lighting.lightColor0, lighting.lightDirection0); case 1: return DirectionalLight(lighting.lightColor1, lighting.lightDirection1); case 2: default: return DirectionalLight(lighting.lightColor2, lighting.lightDirection2); } } float getPointLightAttenuation(PointLight pointLight, float distance) { return pointLight.attenuation.x + pointLight.attenuation.y * distance + pointLight.attenuation.z * distance * distance; } // #endif `;var as=`// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX)) struct AmbientLight { color: vec3<f32>, }; struct PointLight { color: vec3<f32>, position: vec3<f32>, attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential }; struct DirectionalLight { color: vec3<f32>, direction: vec3<f32>, }; struct lightingUniforms { enabled: i32, pointLightCount: i32, directionalLightCount: i32, ambientColor: vec3<f32>, // TODO - support multiple lights by uncommenting arrays below lightType: i32, lightColor: vec3<f32>, lightDirection: vec3<f32>, lightPosition: vec3<f32>, lightAttenuation: vec3<f32>, // AmbientLight ambientLight; // PointLight pointLight[MAX_LIGHTS]; // DirectionalLight directionalLight[MAX_LIGHTS]; }; // Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls) @binding(1) @group(0) var<uniform> lighting : lightingUniforms; fn lighting_getPointLight(index: i32) -> PointLight { return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation); } fn lighting_getDirectionalLight(index: i32) -> DirectionalLight { return DirectionalLight(lighting.lightColor, lighting.lightDirection); } fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 { return pointLight.attenuation.x + pointLight.attenuation.y * distance + pointLight.attenuation.z * distance * distance; } `;var ls=3,ji=255,Pt;(function(e){e[e.POINT=0]="POINT",e[e.DIRECTIONAL=1]="DIRECTIONAL"})(Pt||(Pt={}));var ot={props:{},uniforms:{},name:"lighting",defines:{MAX_LIGHTS:ls},uniformTypes:{enabled:"i32",lightType:"i32",directionalLightCount:"i32",pointLightCount:"i32",ambientLightColor:"vec3<f32>",lightColor0:"vec3<f32>",lightPosition0:"vec3<f32>",lightDirection0:"vec3<f32>",lightAttenuation0:"vec3<f32>",lightColor1:"vec3<f32>",lightPosition1:"vec3<f32>",lightDirection1:"vec3<f32>",lightAttenuation1:"vec3<f32>",lightColor2:"vec3<f32>",lightPosition2:"vec3<f32>",lightDirection2:"vec3<f32>",lightAttenuation2:"vec3<f32>"},defaultUniforms:{enabled:1,lightType:Pt.POINT,directionalLightCount:0,pointLightCount:0,ambientLightColor:[.1,.1,.1],lightColor0:[1,1,1],lightPosition0:[1,1,2],lightDirection0:[1,1,1],lightAttenuation0:[1,0,0],lightColor1:[1,1,1],lightPosition1:[1,1,2],lightDirection1:[1,1,1],lightAttenuation1:[1,0,0],lightColor2:[1,1,1],lightPosition2:[1,1,2],lightDirection2:[1,1,1],lightAttenuation2:[1,0,0]},source:as,vs:Ze,fs:Ze,getUniforms:ki};function ki(e,t={}){if(e=e&&{...e},!e)return{...ot.defaultUniforms};e.lights&&(e={...e,...zi(e.lights),lights:void 0});let{ambientLight:n,pointLights:r,directionalLights:s}=e||{};if(!(n||r&&r.length>0||s&&s.length>0))return{...ot.defaultUniforms,enabled:0};let i={...ot.defaultUniforms,...t,...Yi({ambientLight:n,pointLights:r,directionalLights:s})};return e.enabled!==void 0&&(i.enabled=e.enabled?1:0),i}function Yi({ambientLight:e,pointLights:t=[],directionalLights:n=[]}){let r={};r.ambientLightColor=$e(e);let s=0;for(let o of t){r.lightType=Pt.POINT;let i=s;r[`lightColor${i}`]=$e(o),r[`lightPosition${i}`]=o.position,r[`lightAttenuation${i}`]=o.attenuation||[1,0,0],s++}for(let o of n){r.lightType=Pt.DIRECTIONAL;let i=s;r[`lightColor${i}`]=$e(o),r[`lightDirection${i}`]=o.direction,s++}return s>ls&&fs.log.warn("MAX_LIGHTS exceeded")(),r.directionalLightCount=n.length,r.pointLightCount=t.length,r}function zi(e){let t={pointLights:[],directionalLights:[]};for(let n of e||[])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 t}function $e(e={}){let{color:t=[0,0,0],intensity:n=1}=e;return t.map(r=>r*n/ji)}var hs=`uniform phongMaterialUniforms { uniform float ambient; uniform float diffuse; uniform float shininess; uniform vec3 specularColor; } material; `,As=`uniform phongMaterialUniforms { uniform float ambient; uniform float diffuse; uniform float shininess; uniform vec3 specularColor; } material; vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) { vec3 halfway_direction = normalize(light_direction + view_direction); float lambertian = dot(light_direction, normal_worldspace); float specular = 0.0; if (lambertian > 0.0) { float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0); specular = pow(specular_angle, material.shininess); } lambertian = max(lambertian, 0.0); return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color; } vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) { vec3 lightColor = surfaceColor; if (lighting.enabled == 0) { return lightColor; } vec3 view_direction = normalize(cameraPosition - position_worldspace); lightColor = material.ambient * surfaceColor * lighting.ambientColor; for (int i = 0; i < lighting.pointLightCount; i++) { PointLight pointLight = lighting_getPointLight(i); vec3 light_position_worldspace = pointLight.position; vec3 light_direction = normalize(light_position_worldspace - position_worldspace); float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace)); lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation); } int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount); for (int i = lighting.pointLightCount; i < totalLights; i++) { DirectionalLight directionalLight = lighting_getDirectionalLight(i); lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); } return lightColor; } `;var ps=`struct phongMaterialUniforms { ambient: f32, diffuse: f32, shininess: f32, specularColor: vec3<f32>, }; @binding(2) @group(0) var<uniform> phongMaterial : phongMaterialUniforms; fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, view_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> { let halfway_direction: vec3<f32> = normalize(light_direction + view_direction); var lambertian: f32 = dot(light_direction, normal_worldspace); var specular: f32 = 0.0; if (lambertian > 0.0) { let specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0); specular = pow(specular_angle, phongMaterial.shininess); } lambertian = max(lambertian, 0.0); return (lambertian * phongMaterial.diffuse * surfaceColor + specular * phongMaterial.specularColor) * color; } fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> { var lightColor: vec3<f32> = surfaceColor; if (lighting.enabled == 0) { return lightColor; } let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace); lightColor = phongMaterial.ambient * surfaceColor * lighting.ambientColor; if (lighting.lightType == 0) { let pointLight: PointLight = lighting_getPointLight(0); let light_position_worldspace: vec3<f32> = pointLight.position; let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace); lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color); } else if (lighting.lightType == 1) { var directionalLight: DirectionalLight = lighting_getDirectionalLight(0); lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); } return lightColor; /* for (int i = 0; i < MAX_LIGHTS; i++) { if (i >= lighting.pointLightCount) { break; } PointLight pointLight = lighting.pointLight[i]; vec3 light_position_worldspace = pointLight.position; vec3 light_direction = normalize(light_position_worldspace - position_worldspace); lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color); } for (int i = 0; i < MAX_LIGHTS; i++) { if (i >= lighting.directionalLightCount) { break; } DirectionalLight directionalLight = lighting.directionalLight[i]; lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); } */ } fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32>{ var lightColor = vec3<f32>(0, 0, 0); let surfaceColor = vec3<f32>(0, 0, 0); if (lighting.enabled == 0) { let view_direction = normalize(cameraPosition - position_worldspace); switch (lighting.lightType) { case 0, default: { let pointLight: PointLight = lighting_getPointLight(0); let light_position_worldspace: vec3<f32> = pointLight.position; let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace); lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color); } case 1: { let directionalLight: DirectionalLight = lighting_getDirectionalLight(0); lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color); } } } return lightColor; } `;var fe={name:"phongMaterial",dependencies:[ot],source:ps,vs:hs,fs:As,defines:{LIGHTING_FRAGMENT:1},uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(e){let t={...e};return t.specularColor&&(t.specularColor=t.specularColor.map(n=>n/255)),{...fe.defaultUniforms,...t}}};var ms=`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 = pbrProjection.modelMatrix * position; pbr_vPosition = vec3(pos.xyz) / pos.w; #ifdef HAS_NORMALS #ifdef HAS_TANGENTS vec3 normalW = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0))); vec3 tangentW = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0))); vec3 bitangentW = cross(normalW, tangentW) * tangent.w; pbr_vTBN = mat3(tangentW, bitangentW, normalW); #else // HAS_TANGENTS != 1 pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0))); #endif #endif #ifdef HAS_UV pbr_vUV = uv; #else pbr_vUV = vec2(0.,0.); #endif } `;var ds=`precision highp float; uniform pbrMaterialUniforms { // Material is unlit bool unlit; // Base color map bool baseColorMapEnabled; vec4 baseColorFactor; bool normalMapEnabled; float normalScale; // #ifdef HAS_NORMALMAP bool emissiveMapEnabled; vec3 emissiveFactor; // #ifdef HAS_EMISSIVEMAP vec2 metallicRoughnessValues; bool metallicRoughnessMapEnabled; bool occlusionMapEnabled; float occlusionStrength; // #ifdef HAS_OCCLUSIONMAP bool alphaCutoffEnabled; float alphaCutoff; // #ifdef ALPHA_CUTOFF // IBL bool IBLenabled; vec2 scaleIBLAmbient; // #ifdef USE_IBL // debugging flags used for shader output of intermediate PBR variables // #ifdef PBR_DEBUG vec4 scaleDiffBaseMR; vec4 scaleFGDSpec; // #endif } pbrMaterial; // Samplers #ifdef HAS_BASECOLORMAP uniform sampler2D pbr_baseColorSampler; #endif #ifdef HAS_NORMALMAP uniform sampler2D pbr_normalSampler; #endif #ifdef HAS_EMISSIVEMAP uniform sampler2D pbr_emissiveSampler; #endif #ifdef HAS_METALROUGHNESSMAP uniform sampler2D pbr_metallicRoughnessSampler; #endif #ifdef HAS_OCCLUSIONMAP uniform sampler2D pbr_occlusionSampler; #endif #ifdef USE_IBL uniform samplerCube pbr_diffuseEnvSampler; uniform samplerCube pbr_specularEnvSampler; uniform sampler2D pbr_brdfLUT; #endif // Inputs from vertex shader 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 // Encapsulate the various inputs used by the various functions in the shading equation // We store values in this struct to simplify the integration of alternative implementations // of the shading terms, outlined in the Readme.MD Appendix. struct PBRInfo { float NdotL; // cos angle between normal and light direction float NdotV; // cos angle between normal and view direction float NdotH; // cos angle between normal and half vector float LdotH; // cos angle between light direction and half vector float VdotH; // cos angle between view direction and half vector float perceptualRoughness; // roughness value, as authored by the model creator (input to shader) float metalness; // metallic value at the surface vec3 reflectance0; // full reflectance color (normal incidence angle) vec3 reflectance90; // reflectance color at grazing angle float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2]) vec3 diffuseColor; // color contribution from diffuse lighting vec3 specularColor; // color contribution from specular lighting vec3 n; // normal at surface point vec3 v; // vector from surface point to camera }; 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 // SRGB_FAST_APPROXIMATION 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 //SRGB_FAST_APPROXIMATION return vec4(linOut,srgbIn.w);; #else //MANUAL_SRGB return srgbIn; #endif //MANUAL_SRGB } // Find the normal for this fragment, pulling either from a predefined normal map // or from the interpolated mesh normal and tangent attributes. vec3 getNormal() { // Retrieve the tangent space matrix #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 // HAS_TANGENTS mat3 tbn = pbr_vTBN; #endif #ifdef HAS_NORMALMAP vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb; n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0))); #else // The tbn matrix is linearly interpolated, so we need to re-normalize vec3 n = normalize(tbn[2].xyz); #endif return n; } // Calculation of the lighting contribution from an optional Image Based Light source. // Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1]. // See our README.md on Environment Maps [3] for additional discussion. #ifdef USE_IBL vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection) { float mipCount = 9.0; // resolution of 512x512 float lod = (pbrInfo.perceptualRoughness * mipCount); // retrieve a scale and bias to F0. See [1], Figure 3 vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT, vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb; vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb; #ifdef USE_TEX_LOD vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb; #else vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb; #endif vec3 diffuse = diffuseLight * pbrInfo.diffuseColor; vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y); // For presentation, this allows us to disable IBL terms diffuse *= pbrMaterial.scaleIBLAmbient.x; specular *= pbrMaterial.scaleIBLAmbient.y; return diffuse + specular; } #endif // Basic Lambertian diffuse // Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog // See also [1], Equation 1 vec3 diffuse(PBRInfo pbrInfo) { return pbrInfo.diffuseColor / M_PI; } // The following equation models the Fresnel reflectance term of the spec equation (aka F()) // Implementation of fresnel from [4], Equation 15 vec3 specularReflection(PBRInfo pbrInfo) { return pbrInfo.reflectance0 + (pbrInfo.reflectance90 - pbrInfo.reflectance0) * pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0); } // This calculates the specular geometric attenuation (aka G()), // where rougher material will reflect less light back to the viewer. // This implementation is based on [1] Equation 4, and we adopt their modifications to // alphaRoughness as input as originally proposed in [2]. float geometricOcclusion(PBRInfo pbrInfo) { float NdotL = pbrInfo.NdotL; float NdotV = pbrInfo.NdotV; float r = pbrInfo.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; } // The following equation(s) model the distribution of microfacet normals across // the area being drawn (aka D()) // Implementation from "Average Irregularity Representation of a Roughened Surface // for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz // Follows the distribution function recommended in the SIGGRAPH 2013 course notes // from EPIC Games [1], Equation 3. float microfacetDistribution(PBRInfo pbrInfo) { float roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness; float f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0; return roughnessSq / (M_PI * f * f); } void PBRInfo_setAmbientLight(inout PBRInfo pbrInfo) { pbrInfo.NdotL = 1.0; pbrInfo.NdotH = 0.0; pbrInfo.LdotH = 0.0; pbrInfo.VdotH = 1.0; } void PBRInfo_setDirectionalLight(inout PBRInfo pbrInfo, vec3 lightDirection) { vec3 n = pbrInfo.n; vec3 v = pbrInfo.v; vec3 l = normalize(lightDirection); // Vector from surface point to light vec3 h = normalize(l+v); // Half vector between both l and v pbrInfo.NdotL = clamp(dot(n, l), 0.001, 1.0); pbrInfo.NdotH = clamp(dot(n, h), 0.0, 1.0); pbrInfo.LdotH = clamp(dot(l, h), 0.0, 1.0); pbrInfo.VdotH = clamp(dot(v, h), 0.0, 1.0); } void PBRInfo_setPointLight(inout PBRInfo pbrInfo, PointLight pointLight) { vec3 light_direction = normalize(pointLight.position - pbr_vPosition); PBRInfo_setDirectionalLight(pbrInfo, light_direction); } vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) { // Calculate the shading terms for the microfacet specular shading model vec3 F = specularReflection(pbrInfo); float G = geometricOcclusion(pbrInfo); float D = microfacetDistribution(pbrInfo); // Calculation of analytical lighting contribution vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInfo); vec3 specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV); // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law) return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib); } vec4 pbr_filterColor(vec4 colorUnused) { // The albedo may be defined from a base texture or a flat color #ifdef HAS_BASECOLORMAP vec4 baseColor = SRGBtoLINEAR(texture(pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor; #else vec4 baseColor = pbrMaterial.baseColorFactor; #endif #ifdef ALPHA_CUTOFF if (baseColor.a < pbrMaterial.alphaCutoff) { discard; } #endif vec3 color = vec3(0, 0, 0); if(pbrMaterial.unlit){ color.rgb = baseColor.rgb; } else{ // Metallic and Roughness material properties are packed together