@deck.gl/mesh-layers
Version:
deck.gl layers that loads 3D meshes or scene graphs
582 lines (495 loc) • 197 kB
JavaScript
(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 Ri=Object.create;var et=Object.defineProperty;var Ii=Object.getOwnPropertyDescriptor;var Si=Object.getOwnPropertyNames;var Li=Object.getPrototypeOf,Fi=Object.prototype.hasOwnProperty;var Ut=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),N=(t,e)=>{for(var n in e)et(t,n,{get:e[n],enumerable:!0})},$e=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Si(e))!Fi.call(t,o)&&o!==n&&et(t,o,{get:()=>e[o],enumerable:!(r=Ii(e,o))||r.enumerable});return t},$=(t,e,n)=>($e(t,e,"default"),n&&$e(n,e,"default")),F=(t,e,n)=>(n=t!=null?Ri(Li(t)):{},$e(e||!t||!t.__esModule?et(n,"default",{value:t,enumerable:!0}):n,t)),Di=t=>$e(et({},"__esModule",{value:!0}),t);var pe=Ut((Zl,rr)=>{rr.exports=globalThis.deck});var oe=Ut((eh,sr)=>{sr.exports=globalThis.luma});var Fe=Ut((th,ir)=>{ir.exports=globalThis.luma});var Ze={};N(Ze,{ScenegraphLayer:()=>Ti,SimpleMeshLayer:()=>Io});var X={},or=F(pe(),1);$(X,F(pe(),1));if(!or.Layer)throw new Error("@deck.gl/core is not found");$(Ze,X);var te=F(pe(),1),Ro=F(oe(),1),ge=F(Fe(),1);var nh=1/Math.PI*180,rh=1/180*Math.PI,vi={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...vi}};var R=globalThis.mathgl.config;function ar(t,{precision:e=R.precision}={}){return t=Gi(t),`${parseFloat(t.toPrecision(e))}`}function me(t){return Array.isArray(t)||ArrayBuffer.isView(t)&&!(t instanceof DataView)}function Ht(t,e,n){let r=R.EPSILON;n&&(R.EPSILON=n);try{if(t===e)return!0;if(me(t)&&me(e)){if(t.length!==e.length)return!1;for(let o=0;o<t.length;++o)if(!Ht(t[o],e[o]))return!1;return!0}return t&&t.equals?t.equals(e):e&&e.equals?e.equals(t):typeof t=="number"&&typeof e=="number"?Math.abs(t-e)<=R.EPSILON*Math.max(1,Math.abs(t),Math.abs(e)):!1}finally{R.EPSILON=r}}function Gi(t){return Math.round(t/R.EPSILON)*R.EPSILON}var ee=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(e,n=0){for(let r=0;r<this.ELEMENTS;++r)this[r]=e[r+n];return this.check()}toArray(e=[],n=0){for(let r=0;r<this.ELEMENTS;++r)e[n+r]=this[r];return e}toObject(e){return e}from(e){return Array.isArray(e)?this.copy(e):this.fromObject(e)}to(e){return e===this?this:me(e)?this.toArray(e):this.toObject(e)}toTarget(e){return e?this.to(e):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(R)}formatString(e){let n="";for(let r=0;r<this.ELEMENTS;++r)n+=(r>0?", ":"")+ar(this[r],e);return`${e.printTypes?this.constructor.name:""}[${n}]`}equals(e){if(!e||this.length!==e.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(!Ht(this[n],e[n]))return!1;return!0}exactEquals(e){if(!e||this.length!==e.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(this[n]!==e[n])return!1;return!0}negate(){for(let e=0;e<this.ELEMENTS;++e)this[e]=-this[e];return this.check()}lerp(e,n,r){if(r===void 0)return this.lerp(this,e,n);for(let o=0;o<this.ELEMENTS;++o){let s=e[o],i=typeof n=="number"?n:n[o];this[o]=s+r*(i-s)}return this.check()}min(e){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(e[n],this[n]);return this.check()}max(e){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.max(e[n],this[n]);return this.check()}clamp(e,n){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],e[r]),n[r]);return this.check()}add(...e){for(let n of e)for(let r=0;r<this.ELEMENTS;++r)this[r]+=n[r];return this.check()}subtract(...e){for(let n of e)for(let r=0;r<this.ELEMENTS;++r)this[r]-=n[r];return this.check()}scale(e){if(typeof e=="number")for(let n=0;n<this.ELEMENTS;++n)this[n]*=e;else for(let n=0;n<this.ELEMENTS&&n<e.length;++n)this[n]*=e[n];return this.check()}multiplyByScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]*=e;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 e=this.length===this.ELEMENTS;for(let n=0;n<this.ELEMENTS;++n)e=e&&Number.isFinite(this[n]);return e}sub(e){return this.subtract(e)}setScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]=e;return this.check()}addScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]+=e;return this.check()}subScalar(e){return this.addScalar(-e)}multiplyScalar(e){for(let n=0;n<this.ELEMENTS;++n)this[n]*=e;return this.check()}divideScalar(e){return this.multiplyByScalar(1/e)}clampScalar(e,n){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],e),n);return this.check()}get elements(){return this}};function Oi(t,e){if(t.length!==e)return!1;for(let n=0;n<t.length;++n)if(!Number.isFinite(t[n]))return!1;return!0}function y(t){if(!Number.isFinite(t))throw new Error(`Invalid number ${JSON.stringify(t)}`);return t}function Ae(t,e,n=""){if(R.debug&&!Oi(t,e))throw new Error(`math.gl: ${n} some fields set to invalid numbers'`);return t}function Jt(t,e){if(!t)throw new Error(`math.gl assertion ${e}`)}var tt=class extends ee{get x(){return this[0]}set x(e){this[0]=y(e)}get y(){return this[1]}set y(e){this[1]=y(e)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let e=0;for(let n=0;n<this.ELEMENTS;++n)e+=this[n]*this[n];return e}magnitudeSquared(){return this.lengthSquared()}distance(e){return Math.sqrt(this.distanceSquared(e))}distanceSquared(e){let n=0;for(let r=0;r<this.ELEMENTS;++r){let o=this[r]-e[r];n+=o*o}return y(n)}dot(e){let n=0;for(let r=0;r<this.ELEMENTS;++r)n+=this[r]*e[r];return y(n)}normalize(){let e=this.magnitude();if(e!==0)for(let n=0;n<this.ELEMENTS;++n)this[n]/=e;return this.check()}multiply(...e){for(let n of e)for(let r=0;r<this.ELEMENTS;++r)this[r]*=n[r];return this.check()}divide(...e){for(let n of e)for(let r=0;r<this.ELEMENTS;++r)this[r]/=n[r];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(e){return this.distance(e)}distanceToSquared(e){return this.distanceSquared(e)}getComponent(e){return Jt(e>=0&&e<this.ELEMENTS,"index is out of range"),y(this[e])}setComponent(e,n){return Jt(e>=0&&e<this.ELEMENTS,"index is out of range"),this[e]=n,this.check()}addVectors(e,n){return this.copy(e).add(n)}subVectors(e,n){return this.copy(e).subtract(n)}multiplyVectors(e,n){return this.copy(e).multiply(n)}addScaledVector(e,n){return this.add(new this.constructor(e).multiplyScalar(n))}};var S=typeof Float32Array<"u"?Float32Array:Array;var Ah=Math.PI/180;function Pi(){let t=new S(2);return S!=Float32Array&&(t[0]=0,t[1]=0),t}function lr(t,e,n){let r=e[0],o=e[1];return t[0]=n[0]*r+n[4]*o+n[12],t[1]=n[1]*r+n[5]*o+n[13],t}var uh=function(){let t=Pi();return function(e,n,r,o,s,i){let a,c;for(n||(n=2),r||(r=0),o?c=Math.min(o*n+r,e.length):c=e.length,a=r;a<c;a+=n)t[0]=e[a],t[1]=e[a+1],s(t,t,i),e[a]=t[0],e[a+1]=t[1];return e}}();function hr(t,e,n){let r=e[0],o=e[1],s=n[3]*r+n[7]*o||1;return t[0]=(n[0]*r+n[4]*o)/s,t[1]=(n[1]*r+n[5]*o)/s,t}function pr(t,e,n){let r=e[0],o=e[1],s=e[2],i=n[3]*r+n[7]*o+n[11]*s||1;return t[0]=(n[0]*r+n[4]*o+n[8]*s)/i,t[1]=(n[1]*r+n[5]*o+n[9]*s)/i,t[2]=(n[2]*r+n[6]*o+n[10]*s)/i,t}function mr(t,e,n){let r=e[0],o=e[1];return t[0]=n[0]*r+n[2]*o,t[1]=n[1]*r+n[3]*o,t[2]=e[2],t[3]=e[3],t}function Ar(t,e,n){let r=e[0],o=e[1],s=e[2];return t[0]=n[0]*r+n[3]*o+n[6]*s,t[1]=n[1]*r+n[4]*o+n[7]*s,t[2]=n[2]*r+n[5]*o+n[8]*s,t[3]=e[3],t}function Kt(){let t=new S(3);return S!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function wi(t){let e=t[0],n=t[1],r=t[2];return Math.sqrt(e*e+n*n+r*r)}function Vt(t,e,n){let r=new S(3);return r[0]=t,r[1]=e,r[2]=n,r}function ur(t,e){let n=e[0],r=e[1],o=e[2],s=n*n+r*r+o*o;return s>0&&(s=1/Math.sqrt(s)),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t}function dr(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function nt(t,e,n){let r=e[0],o=e[1],s=e[2],i=n[0],a=n[1],c=n[2];return t[0]=o*c-s*a,t[1]=s*i-r*c,t[2]=r*a-o*i,t}function rt(t,e,n){let r=e[0],o=e[1],s=e[2],i=n[3]*r+n[7]*o+n[11]*s+n[15];return i=i||1,t[0]=(n[0]*r+n[4]*o+n[8]*s+n[12])/i,t[1]=(n[1]*r+n[5]*o+n[9]*s+n[13])/i,t[2]=(n[2]*r+n[6]*o+n[10]*s+n[14])/i,t}function gr(t,e,n){let r=n[0],o=n[1],s=n[2],i=n[3],a=e[0],c=e[1],f=e[2],l=o*f-s*c,h=s*a-r*f,p=r*c-o*a,m=o*p-s*h,A=s*l-r*p,u=r*h-o*l,d=i*2;return l*=d,h*=d,p*=d,m*=2,A*=2,u*=2,t[0]=a+l+m,t[1]=c+h+A,t[2]=f+p+u,t}var Br=wi;var Bh=function(){let t=Kt();return function(e,n,r,o,s,i){let a,c;for(n||(n=3),r||(r=0),o?c=Math.min(o*n+r,e.length):c=e.length,a=r;a<c;a+=n)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],s(t,t,i),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2];return e}}();var ot,ue=class extends tt{static get ZERO(){return ot||(ot=new ue(0,0,0,0),Object.freeze(ot)),ot}constructor(e=0,n=0,r=0,o=0){super(-0,-0,-0,-0),me(e)&&arguments.length===1?this.copy(e):(R.debug&&(y(e),y(n),y(r),y(o)),this[0]=e,this[1]=n,this[2]=r,this[3]=o)}set(e,n,r,o){return this[0]=e,this[1]=n,this[2]=r,this[3]=o,this.check()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this.check()}fromObject(e){return R.debug&&(y(e.x),y(e.y),y(e.z),y(e.w)),this[0]=e.x,this[1]=e.y,this[2]=e.z,this[3]=e.w,this}toObject(e){return e.x=this[0],e.y=this[1],e.z=this[2],e.w=this[3],e}get ELEMENTS(){return 4}get z(){return this[2]}set z(e){this[2]=y(e)}get w(){return this[3]}set w(e){this[3]=y(e)}transform(e){return rt(this,this,e),this.check()}transformByMatrix3(e){return Ar(this,this,e),this.check()}transformByMatrix2(e){return mr(this,this,e),this.check()}transformByQuaternion(e){return gr(this,this,e),this.check()}applyMatrix4(e){return e.transform(this,this),this}};var st=class extends ee{toString(){let e="[";if(R.printRowMajor){e+="row-major:";for(let n=0;n<this.RANK;++n)for(let r=0;r<this.RANK;++r)e+=` ${this[r*this.RANK+n]}`}else{e+="column-major:";for(let n=0;n<this.ELEMENTS;++n)e+=` ${this[n]}`}return e+="]",e}getElementIndex(e,n){return n*this.RANK+e}getElement(e,n){return this[n*this.RANK+e]}setElement(e,n,r){return this[n*this.RANK+e]=y(r),this}getColumn(e,n=new Array(this.RANK).fill(-0)){let r=e*this.RANK;for(let o=0;o<this.RANK;++o)n[o]=this[r+o];return n}setColumn(e,n){let r=e*this.RANK;for(let o=0;o<this.RANK;++o)this[r+o]=n[o];return this}};function xr(){let t=new S(9);return S!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[5]=0,t[6]=0,t[7]=0),t[0]=1,t[4]=1,t[8]=1,t}function Hi(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Mr(t,e){if(t===e){let n=e[1],r=e[2],o=e[3],s=e[6],i=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=n,t[6]=e[9],t[7]=e[13],t[8]=r,t[9]=s,t[11]=e[14],t[12]=o,t[13]=i,t[14]=a}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function Cr(t,e){let n=e[0],r=e[1],o=e[2],s=e[3],i=e[4],a=e[5],c=e[6],f=e[7],l=e[8],h=e[9],p=e[10],m=e[11],A=e[12],u=e[13],d=e[14],B=e[15],E=n*a-r*i,g=n*c-o*i,x=n*f-s*i,M=r*c-o*a,C=r*f-s*a,v=o*f-s*c,G=l*u-h*A,O=l*d-p*A,P=l*B-m*A,J=h*d-p*u,K=h*B-m*u,V=p*B-m*d,_=E*V-g*K+x*J+M*P-C*O+v*G;return _?(_=1/_,t[0]=(a*V-c*K+f*J)*_,t[1]=(o*K-r*V-s*J)*_,t[2]=(u*v-d*C+B*M)*_,t[3]=(p*C-h*v-m*M)*_,t[4]=(c*P-i*V-f*O)*_,t[5]=(n*V-o*P+s*O)*_,t[6]=(d*x-A*v-B*g)*_,t[7]=(l*v-p*x+m*g)*_,t[8]=(i*K-a*P+f*G)*_,t[9]=(r*P-n*K-s*G)*_,t[10]=(A*C-u*x+B*E)*_,t[11]=(h*x-l*C-m*E)*_,t[12]=(a*O-i*J-c*G)*_,t[13]=(n*J-r*O+o*G)*_,t[14]=(u*g-A*M-d*E)*_,t[15]=(l*M-h*g+p*E)*_,t):null}function Er(t){let e=t[0],n=t[1],r=t[2],o=t[3],s=t[4],i=t[5],a=t[6],c=t[7],f=t[8],l=t[9],h=t[10],p=t[11],m=t[12],A=t[13],u=t[14],d=t[15],B=e*i-n*s,E=e*a-r*s,g=n*a-r*i,x=f*A-l*m,M=f*u-h*m,C=l*u-h*A,v=e*C-n*M+r*x,G=s*C-i*M+a*x,O=f*g-l*E+h*B,P=m*g-A*E+u*B;return c*v-o*G+d*O-p*P}function Xt(t,e,n){let r=e[0],o=e[1],s=e[2],i=e[3],a=e[4],c=e[5],f=e[6],l=e[7],h=e[8],p=e[9],m=e[10],A=e[11],u=e[12],d=e[13],B=e[14],E=e[15],g=n[0],x=n[1],M=n[2],C=n[3];return t[0]=g*r+x*a+M*h+C*u,t[1]=g*o+x*c+M*p+C*d,t[2]=g*s+x*f+M*m+C*B,t[3]=g*i+x*l+M*A+C*E,g=n[4],x=n[5],M=n[6],C=n[7],t[4]=g*r+x*a+M*h+C*u,t[5]=g*o+x*c+M*p+C*d,t[6]=g*s+x*f+M*m+C*B,t[7]=g*i+x*l+M*A+C*E,g=n[8],x=n[9],M=n[10],C=n[11],t[8]=g*r+x*a+M*h+C*u,t[9]=g*o+x*c+M*p+C*d,t[10]=g*s+x*f+M*m+C*B,t[11]=g*i+x*l+M*A+C*E,g=n[12],x=n[13],M=n[14],C=n[15],t[12]=g*r+x*a+M*h+C*u,t[13]=g*o+x*c+M*p+C*d,t[14]=g*s+x*f+M*m+C*B,t[15]=g*i+x*l+M*A+C*E,t}function br(t,e,n){let r=n[0],o=n[1],s=n[2],i,a,c,f,l,h,p,m,A,u,d,B;return e===t?(t[12]=e[0]*r+e[4]*o+e[8]*s+e[12],t[13]=e[1]*r+e[5]*o+e[9]*s+e[13],t[14]=e[2]*r+e[6]*o+e[10]*s+e[14],t[15]=e[3]*r+e[7]*o+e[11]*s+e[15]):(i=e[0],a=e[1],c=e[2],f=e[3],l=e[4],h=e[5],p=e[6],m=e[7],A=e[8],u=e[9],d=e[10],B=e[11],t[0]=i,t[1]=a,t[2]=c,t[3]=f,t[4]=l,t[5]=h,t[6]=p,t[7]=m,t[8]=A,t[9]=u,t[10]=d,t[11]=B,t[12]=i*r+l*o+A*s+e[12],t[13]=a*r+h*o+u*s+e[13],t[14]=c*r+p*o+d*s+e[14],t[15]=f*r+m*o+B*s+e[15]),t}function _r(t,e,n){let r=n[0],o=n[1],s=n[2];return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*o,t[5]=e[5]*o,t[6]=e[6]*o,t[7]=e[7]*o,t[8]=e[8]*s,t[9]=e[9]*s,t[10]=e[10]*s,t[11]=e[11]*s,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function yr(t,e,n,r){let o=r[0],s=r[1],i=r[2],a=Math.sqrt(o*o+s*s+i*i),c,f,l,h,p,m,A,u,d,B,E,g,x,M,C,v,G,O,P,J,K,V,_,Le;return a<1e-6?null:(a=1/a,o*=a,s*=a,i*=a,f=Math.sin(n),c=Math.cos(n),l=1-c,h=e[0],p=e[1],m=e[2],A=e[3],u=e[4],d=e[5],B=e[6],E=e[7],g=e[8],x=e[9],M=e[10],C=e[11],v=o*o*l+c,G=s*o*l+i*f,O=i*o*l-s*f,P=o*s*l-i*f,J=s*s*l+c,K=i*s*l+o*f,V=o*i*l+s*f,_=s*i*l-o*f,Le=i*i*l+c,t[0]=h*v+u*G+g*O,t[1]=p*v+d*G+x*O,t[2]=m*v+B*G+M*O,t[3]=A*v+E*G+C*O,t[4]=h*P+u*J+g*K,t[5]=p*P+d*J+x*K,t[6]=m*P+B*J+M*K,t[7]=A*P+E*J+C*K,t[8]=h*V+u*_+g*Le,t[9]=p*V+d*_+x*Le,t[10]=m*V+B*_+M*Le,t[11]=A*V+E*_+C*Le,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function Tr(t,e,n){let r=Math.sin(n),o=Math.cos(n),s=e[4],i=e[5],a=e[6],c=e[7],f=e[8],l=e[9],h=e[10],p=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=s*o+f*r,t[5]=i*o+l*r,t[6]=a*o+h*r,t[7]=c*o+p*r,t[8]=f*o-s*r,t[9]=l*o-i*r,t[10]=h*o-a*r,t[11]=p*o-c*r,t}function Rr(t,e,n){let r=Math.sin(n),o=Math.cos(n),s=e[0],i=e[1],a=e[2],c=e[3],f=e[8],l=e[9],h=e[10],p=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=s*o-f*r,t[1]=i*o-l*r,t[2]=a*o-h*r,t[3]=c*o-p*r,t[8]=s*r+f*o,t[9]=i*r+l*o,t[10]=a*r+h*o,t[11]=c*r+p*o,t}function Ir(t,e,n){let r=Math.sin(n),o=Math.cos(n),s=e[0],i=e[1],a=e[2],c=e[3],f=e[4],l=e[5],h=e[6],p=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=s*o+f*r,t[1]=i*o+l*r,t[2]=a*o+h*r,t[3]=c*o+p*r,t[4]=f*o-s*r,t[5]=l*o-i*r,t[6]=h*o-a*r,t[7]=p*o-c*r,t}function Sr(t,e){let n=e[0],r=e[1],o=e[2],s=e[3],i=n+n,a=r+r,c=o+o,f=n*i,l=r*i,h=r*a,p=o*i,m=o*a,A=o*c,u=s*i,d=s*a,B=s*c;return t[0]=1-h-A,t[1]=l+B,t[2]=p-d,t[3]=0,t[4]=l-B,t[5]=1-f-A,t[6]=m+u,t[7]=0,t[8]=p+d,t[9]=m-u,t[10]=1-f-h,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Lr(t,e,n,r,o,s,i){let a=1/(n-e),c=1/(o-r),f=1/(s-i);return t[0]=s*2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=s*2*c,t[6]=0,t[7]=0,t[8]=(n+e)*a,t[9]=(o+r)*c,t[10]=(i+s)*f,t[11]=-1,t[12]=0,t[13]=0,t[14]=i*s*2*f,t[15]=0,t}function Ji(t,e,n,r,o){let s=1/Math.tan(e/2);if(t[0]=s/n,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=s,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,o!=null&&o!==1/0){let i=1/(r-o);t[10]=(o+r)*i,t[14]=2*o*r*i}else t[10]=-1,t[14]=-2*r;return t}var Fr=Ji;function Ki(t,e,n,r,o,s,i){let a=1/(e-n),c=1/(r-o),f=1/(s-i);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*f,t[11]=0,t[12]=(e+n)*a,t[13]=(o+r)*c,t[14]=(i+s)*f,t[15]=1,t}var Dr=Ki;function vr(t,e,n,r){let o,s,i,a,c,f,l,h,p,m,A=e[0],u=e[1],d=e[2],B=r[0],E=r[1],g=r[2],x=n[0],M=n[1],C=n[2];return Math.abs(A-x)<1e-6&&Math.abs(u-M)<1e-6&&Math.abs(d-C)<1e-6?Hi(t):(h=A-x,p=u-M,m=d-C,o=1/Math.sqrt(h*h+p*p+m*m),h*=o,p*=o,m*=o,s=E*m-g*p,i=g*h-B*m,a=B*p-E*h,o=Math.sqrt(s*s+i*i+a*a),o?(o=1/o,s*=o,i*=o,a*=o):(s=0,i=0,a=0),c=p*a-m*i,f=m*s-h*a,l=h*i-p*s,o=Math.sqrt(c*c+f*f+l*l),o?(o=1/o,c*=o,f*=o,l*=o):(c=0,f=0,l=0),t[0]=s,t[1]=c,t[2]=h,t[3]=0,t[4]=i,t[5]=f,t[6]=p,t[7]=0,t[8]=a,t[9]=l,t[10]=m,t[11]=0,t[12]=-(s*A+i*u+a*d),t[13]=-(c*A+f*u+l*d),t[14]=-(h*A+p*u+m*d),t[15]=1,t)}function Vi(){let t=new S(4);return S!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t}function Gr(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t[3]=e[3]+n[3],t}function Or(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t}function Pr(t){let e=t[0],n=t[1],r=t[2],o=t[3];return Math.sqrt(e*e+n*n+r*r+o*o)}function wr(t){let e=t[0],n=t[1],r=t[2],o=t[3];return e*e+n*n+r*r+o*o}function Nr(t,e){let n=e[0],r=e[1],o=e[2],s=e[3],i=n*n+r*r+o*o+s*s;return i>0&&(i=1/Math.sqrt(i)),t[0]=n*i,t[1]=r*i,t[2]=o*i,t[3]=s*i,t}function Ur(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function Hr(t,e,n,r){let o=e[0],s=e[1],i=e[2],a=e[3];return t[0]=o+r*(n[0]-o),t[1]=s+r*(n[1]-s),t[2]=i+r*(n[2]-i),t[3]=a+r*(n[3]-a),t}function Jr(t,e,n){let r=e[0],o=e[1],s=e[2],i=e[3];return t[0]=n[0]*r+n[4]*o+n[8]*s+n[12]*i,t[1]=n[1]*r+n[5]*o+n[9]*s+n[13]*i,t[2]=n[2]*r+n[6]*o+n[10]*s+n[14]*i,t[3]=n[3]*r+n[7]*o+n[11]*s+n[15]*i,t}function Kr(t,e,n){let r=e[0],o=e[1],s=e[2],i=n[0],a=n[1],c=n[2],f=n[3],l=f*r+a*s-c*o,h=f*o+c*r-i*s,p=f*s+i*o-a*r,m=-i*r-a*o-c*s;return t[0]=l*f+m*-i+h*-c-p*-a,t[1]=h*f+m*-a+p*-i-l*-c,t[2]=p*f+m*-c+l*-a-h*-i,t[3]=e[3],t}var Lh=function(){let t=Vi();return function(e,n,r,o,s,i){let a,c;for(n||(n=4),r||(r=0),o?c=Math.min(o*n+r,e.length):c=e.length,a=r;a<c;a+=n)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],t[3]=e[a+3],s(t,t,i),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2],e[a+3]=t[3];return e}}();var zt;(function(t){t[t.COL0ROW0=0]="COL0ROW0",t[t.COL0ROW1=1]="COL0ROW1",t[t.COL0ROW2=2]="COL0ROW2",t[t.COL0ROW3=3]="COL0ROW3",t[t.COL1ROW0=4]="COL1ROW0",t[t.COL1ROW1=5]="COL1ROW1",t[t.COL1ROW2=6]="COL1ROW2",t[t.COL1ROW3=7]="COL1ROW3",t[t.COL2ROW0=8]="COL2ROW0",t[t.COL2ROW1=9]="COL2ROW1",t[t.COL2ROW2=10]="COL2ROW2",t[t.COL2ROW3=11]="COL2ROW3",t[t.COL3ROW0=12]="COL3ROW0",t[t.COL3ROW1=13]="COL3ROW1",t[t.COL3ROW2=14]="COL3ROW2",t[t.COL3ROW3=15]="COL3ROW3"})(zt||(zt={}));var ji=45*Math.PI/180,ki=1,jt=.1,kt=500,zi=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),q=class extends st{static get IDENTITY(){return Qi()}static get ZERO(){return Yi()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return zt}constructor(e){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(e)?this.copy(e):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this[9]=e[9],this[10]=e[10],this[11]=e[11],this[12]=e[12],this[13]=e[13],this[14]=e[14],this[15]=e[15],this.check()}set(e,n,r,o,s,i,a,c,f,l,h,p,m,A,u,d){return this[0]=e,this[1]=n,this[2]=r,this[3]=o,this[4]=s,this[5]=i,this[6]=a,this[7]=c,this[8]=f,this[9]=l,this[10]=h,this[11]=p,this[12]=m,this[13]=A,this[14]=u,this[15]=d,this.check()}setRowMajor(e,n,r,o,s,i,a,c,f,l,h,p,m,A,u,d){return this[0]=e,this[1]=s,this[2]=f,this[3]=m,this[4]=n,this[5]=i,this[6]=l,this[7]=A,this[8]=r,this[9]=a,this[10]=h,this[11]=u,this[12]=o,this[13]=c,this[14]=p,this[15]=d,this.check()}toRowMajor(e){return e[0]=this[0],e[1]=this[4],e[2]=this[8],e[3]=this[12],e[4]=this[1],e[5]=this[5],e[6]=this[9],e[7]=this[13],e[8]=this[2],e[9]=this[6],e[10]=this[10],e[11]=this[14],e[12]=this[3],e[13]=this[7],e[14]=this[11],e[15]=this[15],e}identity(){return this.copy(zi)}fromObject(e){return this.check()}fromQuaternion(e){return Sr(this,e),this.check()}frustum(e){let{left:n,right:r,bottom:o,top:s,near:i=jt,far:a=kt}=e;return a===1/0?Wi(this,n,r,o,s,i):Lr(this,n,r,o,s,i,a),this.check()}lookAt(e){let{eye:n,center:r=[0,0,0],up:o=[0,1,0]}=e;return vr(this,n,r,o),this.check()}ortho(e){let{left:n,right:r,bottom:o,top:s,near:i=jt,far:a=kt}=e;return Dr(this,n,r,o,s,i,a),this.check()}orthographic(e){let{fovy:n=ji,aspect:r=ki,focalDistance:o=1,near:s=jt,far:i=kt}=e;Vr(n);let a=n/2,c=o*Math.tan(a),f=c*r;return this.ortho({left:-f,right:f,bottom:-c,top:c,near:s,far:i})}perspective(e){let{fovy:n=45*Math.PI/180,aspect:r=1,near:o=.1,far:s=500}=e;return Vr(n),Fr(this,n,r,o,s),this.check()}determinant(){return Er(this)}getScale(e=[-0,-0,-0]){return e[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),e[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),e[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),e}getTranslation(e=[-0,-0,-0]){return e[0]=this[12],e[1]=this[13],e[2]=this[14],e}getRotation(e,n){e=e||[-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),o=1/r[0],s=1/r[1],i=1/r[2];return e[0]=this[0]*o,e[1]=this[1]*s,e[2]=this[2]*i,e[3]=0,e[4]=this[4]*o,e[5]=this[5]*s,e[6]=this[6]*i,e[7]=0,e[8]=this[8]*o,e[9]=this[9]*s,e[10]=this[10]*i,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}getRotationMatrix3(e,n){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let r=this.getScale(n),o=1/r[0],s=1/r[1],i=1/r[2];return e[0]=this[0]*o,e[1]=this[1]*s,e[2]=this[2]*i,e[3]=this[4]*o,e[4]=this[5]*s,e[5]=this[6]*i,e[6]=this[8]*o,e[7]=this[9]*s,e[8]=this[10]*i,e}transpose(){return Mr(this,this),this.check()}invert(){return Cr(this,this),this.check()}multiplyLeft(e){return Xt(this,e,this),this.check()}multiplyRight(e){return Xt(this,this,e),this.check()}rotateX(e){return Tr(this,this,e),this.check()}rotateY(e){return Rr(this,this,e),this.check()}rotateZ(e){return Ir(this,this,e),this.check()}rotateXYZ(e){return this.rotateX(e[0]).rotateY(e[1]).rotateZ(e[2])}rotateAxis(e,n){return yr(this,this,e,n),this.check()}scale(e){return _r(this,this,Array.isArray(e)?e:[e,e,e]),this.check()}translate(e){return br(this,this,e),this.check()}transform(e,n){return e.length===4?(n=Jr(n||[-0,-0,-0,-0],e,this),Ae(n,4),n):this.transformAsPoint(e,n)}transformAsPoint(e,n){let{length:r}=e,o;switch(r){case 2:o=lr(n||[-0,-0],e,this);break;case 3:o=rt(n||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Ae(o,e.length),o}transformAsVector(e,n){let r;switch(e.length){case 2:r=hr(n||[-0,-0],e,this);break;case 3:r=pr(n||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Ae(r,e.length),r}transformPoint(e,n){return this.transformAsPoint(e,n)}transformVector(e,n){return this.transformAsPoint(e,n)}transformDirection(e,n){return this.transformAsVector(e,n)}makeRotationX(e){return this.identity().rotateX(e)}makeTranslation(e,n,r){return this.identity().translate([e,n,r])}},it,at;function Yi(){return it||(it=new q([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(it)),it}function Qi(){return at||(at=new q,Object.freeze(at)),at}function Vr(t){if(t>Math.PI*2)throw Error("expected radians")}function Wi(t,e,n,r,o,s){let i=2*s/(n-e),a=2*s/(o-r),c=(n+e)/(n-e),f=(o+r)/(o-r),l=-1,h=-1,p=-2*s;return t[0]=i,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=a,t[6]=0,t[7]=0,t[8]=c,t[9]=f,t[10]=l,t[11]=h,t[12]=0,t[13]=0,t[14]=p,t[15]=0,t}function Xr(){let t=new S(4);return S!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function jr(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function Yt(t,e,n){n=n*.5;let r=Math.sin(n);return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=Math.cos(n),t}function Qt(t,e,n){let r=e[0],o=e[1],s=e[2],i=e[3],a=n[0],c=n[1],f=n[2],l=n[3];return t[0]=r*l+i*a+o*f-s*c,t[1]=o*l+i*c+s*a-r*f,t[2]=s*l+i*f+r*c-o*a,t[3]=i*l-r*a-o*c-s*f,t}function kr(t,e,n){n*=.5;let r=e[0],o=e[1],s=e[2],i=e[3],a=Math.sin(n),c=Math.cos(n);return t[0]=r*c+i*a,t[1]=o*c+s*a,t[2]=s*c-o*a,t[3]=i*c-r*a,t}function zr(t,e,n){n*=.5;let r=e[0],o=e[1],s=e[2],i=e[3],a=Math.sin(n),c=Math.cos(n);return t[0]=r*c-s*a,t[1]=o*c+i*a,t[2]=s*c+r*a,t[3]=i*c-o*a,t}function Yr(t,e,n){n*=.5;let r=e[0],o=e[1],s=e[2],i=e[3],a=Math.sin(n),c=Math.cos(n);return t[0]=r*c+o*a,t[1]=o*c-r*a,t[2]=s*c+i*a,t[3]=i*c-s*a,t}function Qr(t,e){let n=e[0],r=e[1],o=e[2];return t[0]=n,t[1]=r,t[2]=o,t[3]=Math.sqrt(Math.abs(1-n*n-r*r-o*o)),t}function ve(t,e,n,r){let o=e[0],s=e[1],i=e[2],a=e[3],c=n[0],f=n[1],l=n[2],h=n[3],p,m,A,u,d;return p=o*c+s*f+i*l+a*h,p<0&&(p=-p,c=-c,f=-f,l=-l,h=-h),1-p>1e-6?(m=Math.acos(p),d=Math.sin(m),A=Math.sin((1-r)*m)/d,u=Math.sin(r*m)/d):(A=1-r,u=r),t[0]=A*o+u*c,t[1]=A*s+u*f,t[2]=A*i+u*l,t[3]=A*a+u*h,t}function Wr(t,e){let n=e[0],r=e[1],o=e[2],s=e[3],i=n*n+r*r+o*o+s*s,a=i?1/i:0;return t[0]=-n*a,t[1]=-r*a,t[2]=-o*a,t[3]=s*a,t}function qr(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t}function Wt(t,e){let n=e[0]+e[4]+e[8],r;if(n>0)r=Math.sqrt(n+1),t[3]=.5*r,r=.5/r,t[0]=(e[5]-e[7])*r,t[1]=(e[6]-e[2])*r,t[2]=(e[1]-e[3])*r;else{let o=0;e[4]>e[0]&&(o=1),e[8]>e[o*3+o]&&(o=2);let s=(o+1)%3,i=(o+2)%3;r=Math.sqrt(e[o*3+o]-e[s*3+s]-e[i*3+i]+1),t[o]=.5*r,r=.5/r,t[3]=(e[s*3+i]-e[i*3+s])*r,t[s]=(e[s*3+o]+e[o*3+s])*r,t[i]=(e[i*3+o]+e[o*3+i])*r}return t}var Zr=Gr;var $r=Or,eo=Ur,to=Hr,no=Pr;var ro=wr;var oo=Nr;var so=function(){let t=Kt(),e=Vt(1,0,0),n=Vt(0,1,0);return function(r,o,s){let i=dr(o,s);return i<-.999999?(nt(t,e,o),Br(t)<1e-6&&nt(t,n,o),ur(t,t),Yt(r,t,Math.PI),r):i>.999999?(r[0]=0,r[1]=0,r[2]=0,r[3]=1,r):(nt(t,o,s),r[0]=t[0],r[1]=t[1],r[2]=t[2],r[3]=1+i,oo(r,r))}}(),Xh=function(){let t=Xr(),e=Xr();return function(n,r,o,s,i,a){return ve(t,r,i,a),ve(e,o,s,a),ve(n,t,e,2*a*(1-a)),n}}(),jh=function(){let t=xr();return function(e,n,r,o){return t[0]=r[0],t[3]=r[1],t[6]=r[2],t[1]=o[0],t[4]=o[1],t[7]=o[2],t[2]=-n[0],t[5]=-n[1],t[8]=-n[2],oo(e,Wt(e,t))}}();var qi=[0,0,0,1],Ge=class extends ee{constructor(e=0,n=0,r=0,o=1){super(-0,-0,-0,-0),Array.isArray(e)&&arguments.length===1?this.copy(e):this.set(e,n,r,o)}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this.check()}set(e,n,r,o){return this[0]=e,this[1]=n,this[2]=r,this[3]=o,this.check()}fromObject(e){return this[0]=e.x,this[1]=e.y,this[2]=e.z,this[3]=e.w,this.check()}fromMatrix3(e){return Wt(this,e),this.check()}fromAxisRotation(e,n){return Yt(this,e,n),this.check()}identity(){return jr(this),this.check()}setAxisAngle(e,n){return this.fromAxisRotation(e,n)}get ELEMENTS(){return 4}get x(){return this[0]}set x(e){this[0]=y(e)}get y(){return this[1]}set y(e){this[1]=y(e)}get z(){return this[2]}set z(e){this[2]=y(e)}get w(){return this[3]}set w(e){this[3]=y(e)}len(){return no(this)}lengthSquared(){return ro(this)}dot(e){return eo(this,e)}rotationTo(e,n){return so(this,e,n),this.check()}add(e){return Zr(this,this,e),this.check()}calculateW(){return Qr(this,this),this.check()}conjugate(){return qr(this,this),this.check()}invert(){return Wr(this,this),this.check()}lerp(e,n,r){return r===void 0?this.lerp(this,e,n):(to(this,e,n,r),this.check())}multiplyRight(e){return Qt(this,this,e),this.check()}multiplyLeft(e){return Qt(this,e,this),this.check()}normalize(){let e=this.len(),n=e>0?1/e:0;return this[0]=this[0]*n,this[1]=this[1]*n,this[2]=this[2]*n,this[3]=this[3]*n,e===0&&(this[3]=1),this.check()}rotateX(e){return kr(this,this,e),this.check()}rotateY(e){return zr(this,this,e),this.check()}rotateZ(e){return Yr(this,this,e),this.check()}scale(e){return $r(this,this,e),this.check()}slerp(e,n,r){let o,s,i;switch(arguments.length){case 1:({start:o=qi,target:s,ratio:i}=e);break;case 2:o=this,s=e,i=n;break;default:o=e,s=n,i=r}return ve(this,o,s,i),this.check()}transformVector4(e,n=new ue){return Kr(n,e,this),Ae(n,4)}lengthSq(){return this.lengthSquared()}setFromAxisAngle(e,n){return this.setAxisAngle(e,n)}premultiply(e){return this.multiplyLeft(e)}multiply(e){return this.multiplyRight(e)}};var ao=F(oe(),1);var qt=`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 io=`// #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 Zi=5,$i=255,Oe;(function(t){t[t.POINT=0]="POINT",t[t.DIRECTIONAL=1]="DIRECTIONAL"})(Oe||(Oe={}));var se={props:{},uniforms:{},name:"lighting",defines:{},uniformTypes:{enabled:"i32",lightType:"i32",directionalLightCount:"i32",pointLightCount:"i32",ambientColor:"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:Oe.POINT,directionalLightCount:0,pointLightCount:0,ambientColor:[.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:io,vs:qt,fs:qt,getUniforms:ea};function ea(t,e={}){if(t=t&&{...t},!t)return{...se.defaultUniforms};t.lights&&(t={...t,...na(t.lights),lights:void 0});let{ambientLight:n,pointLights:r,directionalLights:o}=t||{};if(!(n||r&&r.length>0||o&&o.length>0))return{...se.defaultUniforms,enabled:0};let i={...se.defaultUniforms,...e,...ta({ambientLight:n,pointLights:r,directionalLights:o})};return t.enabled!==void 0&&(i.enabled=t.enabled?1:0),i}function ta({ambientLight:t,pointLights:e=[],directionalLights:n=[]}){let r={};r.ambientColor=Zt(t);let o=0;for(let s of e){r.lightType=Oe.POINT;let i=o;r[`lightColor${i}`]=Zt(s),r[`lightPosition${i}`]=s.position,r[`lightAttenuation${i}`]=s.attenuation||[1,0,0],o++}for(let s of n){r.lightType=Oe.DIRECTIONAL;let i=o;r[`lightColor${i}`]=Zt(s),r[`lightDirection${i}`]=s.direction,o++}return o>Zi&&ao.log.warn("MAX_LIGHTS exceeded")(),r.directionalLightCount=n.length,r.pointLightCount=e.length,r}function na(t){let e={pointLights:[],directionalLights:[]};for(let n of t||[])switch(n.type){case"ambient":e.ambientLight=n;break;case"directional":e.directionalLights?.push(n);break;case"point":e.pointLights?.push(n);break;default:}return e}function Zt(t={}){let{color:e=[0,0,0],intensity:n=1}=t;return e.map(r=>r*n/$i)}var co=`uniform phongMaterialUniforms {
uniform float ambient;
uniform float diffuse;
uniform float shininess;
uniform vec3 specularColor;
} material;
`,fo=`#define MAX_LIGHTS 3
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 lo=`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 ct={name:"phongMaterial",dependencies:[se],source:lo,vs:co,fs:fo,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15]},getUniforms(t){let e={...t};return e.specularColor&&(e.specularColor=e.specularColor.map(n=>n/255)),{...ct.defaultUniforms,...e}}};var ho=`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
}
`,po=`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
// In glT