3d/html/002-webgpu-instead/main.js

1 line
24 KiB
JavaScript

import{a as S0,b as Z0} from"../chunk-818093f0cbbefec3.js";class H0{G;canvas;_adapter;_device;_context;telemetry;jobsToSubmitThisFrame=[];renderOK=!1;registry={onBeforeUpdate:[],onAfterUpdate:[],onUpdate:[],onStart:[]};constructor(G={}){this.config=G;if(this.config={fov:45,...G},this.canvas=document.querySelector("canvas"),this.canvas.width=window.innerWidth,this.canvas.height=window.innerHeight,location.search.includes("telemetry"))this.telemetry=new Z0(this);this.init().catch((H)=>{const J=document.querySelector("main");if(J)J.innerHTML="<div><i>your browser didn't let me set up webgpu. firefox nightly or enable <code>dom.webgpu.enable</code>.</i></div>";throw new Error("Unable to initialize WebGPU. Your browser or machine may not support it.",H)})}async init(){if(!navigator.gpu)throw new Error("WebGPU not supported");if(this._adapter=await navigator.gpu.requestAdapter(),!this._adapter)throw new Error("No GPU adapter found");if(this._device=await this.adapter.requestDevice(),!this._device)throw new Error("No GPU device found");this._context=this.canvas.getContext("webgpu"),this.context.configure({device:this.device,format:"bgra8unorm",alphaMode:"premultiplied",...this.config.context}),this.renderOK=!0}awaitRendererReady(G=5000){const H=Date.now();return new Promise((J,K)=>{const W=setInterval(()=>{if(this.renderOK)return J(!0);if(Date.now()-H>G)return K(`Renderer was not OK within ${G}ms`)},10)})}get context(){if(!this._context)throw new Error("WebGPU context not initialized");return this._context}get adapter(){if(!this._adapter)throw new Error("WebGPU adapter not initialized");return this._adapter}get device(){if(!this._device)throw new Error("WebGPU device not initialized");return this._device}onBeforeUpdate(G){this.registry.onBeforeUpdate.push(G)}onAfterUpdate(G){this.registry.onAfterUpdate.push(G)}onUpdate(G){this.registry.onUpdate.push(G)}onStart(G){this.registry.onStart.push(G)}doUpdate(G){if(this.jobsToSubmitThisFrame=[],this.registry.onBeforeUpdate.forEach((H)=>H(G,this)),this.registry.onUpdate.forEach((H)=>H(G,this)),this.registry.onAfterUpdate.forEach((H)=>H(G,this)),this.jobsToSubmitThisFrame.length!==0)this.device.queue.submit(this.jobsToSubmitThisFrame)}doStart(G=0){this.registry.onStart.forEach((H)=>H(G,this))}async oneShot(G=0){await this.awaitRendererReady(),this.doStart(G),this.doUpdate(G)}async start(){await this.awaitRendererReady(),this.doStart();const G=(H)=>{this.doUpdate(H),requestAnimationFrame(G)};requestAnimationFrame(G)}commit(G){this.jobsToSubmitThisFrame.push(G)}}var T0=function(G){const H=Q;return Q=G,H},i=function(G,H,J){const K=new Q(3);if(G!==void 0){if(K[0]=G,H!==void 0){if(K[1]=H,J!==void 0)K[2]=J}}return K},g0=function(G,H,J,K){return K=K||new Q(3),K[0]=G,K[1]=H,K[2]=J,K},o0=function(G,H){return H=H||new Q(3),H[0]=Math.ceil(G[0]),H[1]=Math.ceil(G[1]),H[2]=Math.ceil(G[2]),H},r0=function(G,H){return H=H||new Q(3),H[0]=Math.floor(G[0]),H[1]=Math.floor(G[1]),H[2]=Math.floor(G[2]),H},z0=function(G,H){return H=H||new Q(3),H[0]=Math.round(G[0]),H[1]=Math.round(G[1]),H[2]=Math.round(G[2]),H},$0=function(G,H=0,J=1,K){return K=K||new Q(3),K[0]=Math.min(J,Math.max(H,G[0])),K[1]=Math.min(J,Math.max(H,G[1])),K[2]=Math.min(J,Math.max(H,G[2])),K},l0=function(G,H,J){return J=J||new Q(3),J[0]=G[0]+H[0],J[1]=G[1]+H[1],J[2]=G[2]+H[2],J},i0=function(G,H,J,K){return K=K||new Q(3),K[0]=G[0]+H[0]*J,K[1]=G[1]+H[1]*J,K[2]=G[2]+H[2]*J,K},c0=function(G,H){const J=G[0],K=G[1],W=G[2],C=G[0],F=G[1],j=G[2],_=Math.sqrt(J*J+K*K+W*W),U=Math.sqrt(C*C+F*F+j*j),Y=_*U,B=Y&&_0(G,H)/Y;return Math.acos(B)},v=function(G,H,J){return J=J||new Q(3),J[0]=G[0]-H[0],J[1]=G[1]-H[1],J[2]=G[2]-H[2],J},p0=function(G,H){return Math.abs(G[0]-H[0])<w&&Math.abs(G[1]-H[1])<w&&Math.abs(G[2]-H[2])<w},x0=function(G,H){return G[0]===H[0]&&G[1]===H[1]&&G[2]===H[2]},y0=function(G,H,J,K){return K=K||new Q(3),K[0]=G[0]+J*(H[0]-G[0]),K[1]=G[1]+J*(H[1]-G[1]),K[2]=G[2]+J*(H[2]-G[2]),K},v0=function(G,H,J,K){return K=K||new Q(3),K[0]=G[0]+J[0]*(H[0]-G[0]),K[1]=G[1]+J[1]*(H[1]-G[1]),K[2]=G[2]+J[2]*(H[2]-G[2]),K},b0=function(G,H,J){return J=J||new Q(3),J[0]=Math.max(G[0],H[0]),J[1]=Math.max(G[1],H[1]),J[2]=Math.max(G[2],H[2]),J},e0=function(G,H,J){return J=J||new Q(3),J[0]=Math.min(G[0],H[0]),J[1]=Math.min(G[1],H[1]),J[2]=Math.min(G[2],H[2]),J},Y0=function(G,H,J){return J=J||new Q(3),J[0]=G[0]*H,J[1]=G[1]*H,J[2]=G[2]*H,J},m0=function(G,H,J){return J=J||new Q(3),J[0]=G[0]/H,J[1]=G[1]/H,J[2]=G[2]/H,J},j0=function(G,H){return H=H||new Q(3),H[0]=1/G[0],H[1]=1/G[1],H[2]=1/G[2],H},x=function(G,H,J){J=J||new Q(3);const K=G[2]*H[0]-G[0]*H[2],W=G[0]*H[1]-G[1]*H[0];return J[0]=G[1]*H[2]-G[2]*H[1],J[1]=K,J[2]=W,J},_0=function(G,H){return G[0]*H[0]+G[1]*H[1]+G[2]*H[2]},U0=function(G){const H=G[0],J=G[1],K=G[2];return Math.sqrt(H*H+J*J+K*K)},h0=function(G){const H=G[0],J=G[1],K=G[2];return H*H+J*J+K*K},D0=function(G,H){const J=G[0]-H[0],K=G[1]-H[1],W=G[2]-H[2];return Math.sqrt(J*J+K*K+W*W)},P0=function(G,H){const J=G[0]-H[0],K=G[1]-H[1],W=G[2]-H[2];return J*J+K*K+W*W},p=function(G,H){H=H||new Q(3);const J=G[0],K=G[1],W=G[2],C=Math.sqrt(J*J+K*K+W*W);if(C>0.00001)H[0]=J/C,H[1]=K/C,H[2]=W/C;else H[0]=0,H[1]=0,H[2]=0;return H},JG=function(G,H){return H=H||new Q(3),H[0]=-G[0],H[1]=-G[1],H[2]=-G[2],H},Q0=function(G,H){return H=H||new Q(3),H[0]=G[0],H[1]=G[1],H[2]=G[2],H},E0=function(G,H,J){return J=J||new Q(3),J[0]=G[0]*H[0],J[1]=G[1]*H[1],J[2]=G[2]*H[2],J},O0=function(G,H,J){return J=J||new Q(3),J[0]=G[0]/H[0],J[1]=G[1]/H[1],J[2]=G[2]/H[2],J},CG=function(G=1,H){H=H||new Q(3);const J=Math.random()*2*Math.PI,K=Math.random()*2-1,W=Math.sqrt(1-K*K)*G;return H[0]=Math.cos(J)*W,H[1]=Math.sin(J)*W,H[2]=K*G,H},BG=function(G){return G=G||new Q(3),G[0]=0,G[1]=0,G[2]=0,G},XG=function(G,H,J){J=J||new Q(3);const K=G[0],W=G[1],C=G[2],F=H[3]*K+H[7]*W+H[11]*C+H[15]||1;return J[0]=(H[0]*K+H[4]*W+H[8]*C+H[12])/F,J[1]=(H[1]*K+H[5]*W+H[9]*C+H[13])/F,J[2]=(H[2]*K+H[6]*W+H[10]*C+H[14])/F,J},ZG=function(G,H,J){J=J||new Q(3);const K=G[0],W=G[1],C=G[2];return J[0]=K*H[0]+W*H[4]+C*H[8],J[1]=K*H[1]+W*H[5]+C*H[9],J[2]=K*H[2]+W*H[6]+C*H[10],J},YG=function(G,H,J){J=J||new Q(3);const K=G[0],W=G[1],C=G[2];return J[0]=K*H[0]+W*H[4]+C*H[8],J[1]=K*H[1]+W*H[5]+C*H[9],J[2]=K*H[2]+W*H[6]+C*H[10],J},jG=function(G,H,J){J=J||new Q(3);const K=H[0],W=H[1],C=H[2],F=H[3]*2,j=G[0],_=G[1],U=G[2],Y=W*U-C*_,B=C*j-K*U,X=K*_-W*j;return J[0]=j+Y*F+(W*X-C*B)*2,J[1]=_+B*F+(C*Y-K*X)*2,J[2]=U+X*F+(K*B-W*Y)*2,J},_G=function(G,H){return H=H||new Q(3),H[0]=G[12],H[1]=G[13],H[2]=G[14],H},UG=function(G,H,J){J=J||new Q(3);const K=H*4;return J[0]=G[K+0],J[1]=G[K+1],J[2]=G[K+2],J},hG=function(G,H){H=H||new Q(3);const J=G[0],K=G[1],W=G[2],C=G[4],F=G[5],j=G[6],_=G[8],U=G[9],Y=G[10];return H[0]=Math.sqrt(J*J+K*K+W*W),H[1]=Math.sqrt(C*C+F*F+j*j),H[2]=Math.sqrt(_*_+U*U+Y*Y),H},DG=function(G){const H=O;return O=G,H},PG=function(G,H,J,K,W,C,F,j,_,U,Y,B,X,D,h,P){const Z=new O(16);if(G!==void 0){if(Z[0]=G,H!==void 0){if(Z[1]=H,J!==void 0){if(Z[2]=J,K!==void 0){if(Z[3]=K,W!==void 0){if(Z[4]=W,C!==void 0){if(Z[5]=C,F!==void 0){if(Z[6]=F,j!==void 0){if(Z[7]=j,_!==void 0){if(Z[8]=_,U!==void 0){if(Z[9]=U,Y!==void 0){if(Z[10]=Y,B!==void 0){if(Z[11]=B,X!==void 0){if(Z[12]=X,D!==void 0){if(Z[13]=D,h!==void 0){if(Z[14]=h,P!==void 0)Z[15]=P}}}}}}}}}}}}}}}return Z},QG=function(G,H,J,K,W,C,F,j,_,U,Y,B,X,D,h,P,Z){return Z=Z||new O(16),Z[0]=G,Z[1]=H,Z[2]=J,Z[3]=K,Z[4]=W,Z[5]=C,Z[6]=F,Z[7]=j,Z[8]=_,Z[9]=U,Z[10]=Y,Z[11]=B,Z[12]=X,Z[13]=D,Z[14]=h,Z[15]=P,Z},EG=function(G,H){return H=H||new O(16),H[0]=G[0],H[1]=G[1],H[2]=G[2],H[3]=0,H[4]=G[4],H[5]=G[5],H[6]=G[6],H[7]=0,H[8]=G[8],H[9]=G[9],H[10]=G[10],H[11]=0,H[12]=0,H[13]=0,H[14]=0,H[15]=1,H},OG=function(G,H){H=H||new O(16);const J=G[0],K=G[1],W=G[2],C=G[3],F=J+J,j=K+K,_=W+W,U=J*F,Y=K*F,B=K*j,X=W*F,D=W*j,h=W*_,P=C*F,Z=C*j,N=C*_;return H[0]=1-B-h,H[1]=Y+N,H[2]=X-Z,H[3]=0,H[4]=Y-N,H[5]=1-U-h,H[6]=D+P,H[7]=0,H[8]=X+Z,H[9]=D-P,H[10]=1-U-B,H[11]=0,H[12]=0,H[13]=0,H[14]=0,H[15]=1,H},NG=function(G,H){return H=H||new O(16),H[0]=-G[0],H[1]=-G[1],H[2]=-G[2],H[3]=-G[3],H[4]=-G[4],H[5]=-G[5],H[6]=-G[6],H[7]=-G[7],H[8]=-G[8],H[9]=-G[9],H[10]=-G[10],H[11]=-G[11],H[12]=-G[12],H[13]=-G[13],H[14]=-G[14],H[15]=-G[15],H},J0=function(G,H){return H=H||new O(16),H[0]=G[0],H[1]=G[1],H[2]=G[2],H[3]=G[3],H[4]=G[4],H[5]=G[5],H[6]=G[6],H[7]=G[7],H[8]=G[8],H[9]=G[9],H[10]=G[10],H[11]=G[11],H[12]=G[12],H[13]=G[13],H[14]=G[14],H[15]=G[15],H},RG=function(G,H){return Math.abs(G[0]-H[0])<w&&Math.abs(G[1]-H[1])<w&&Math.abs(G[2]-H[2])<w&&Math.abs(G[3]-H[3])<w&&Math.abs(G[4]-H[4])<w&&Math.abs(G[5]-H[5])<w&&Math.abs(G[6]-H[6])<w&&Math.abs(G[7]-H[7])<w&&Math.abs(G[8]-H[8])<w&&Math.abs(G[9]-H[9])<w&&Math.abs(G[10]-H[10])<w&&Math.abs(G[11]-H[11])<w&&Math.abs(G[12]-H[12])<w&&Math.abs(G[13]-H[13])<w&&Math.abs(G[14]-H[14])<w&&Math.abs(G[15]-H[15])<w},kG=function(G,H){return G[0]===H[0]&&G[1]===H[1]&&G[2]===H[2]&&G[3]===H[3]&&G[4]===H[4]&&G[5]===H[5]&&G[6]===H[6]&&G[7]===H[7]&&G[8]===H[8]&&G[9]===H[9]&&G[10]===H[10]&&G[11]===H[11]&&G[12]===H[12]&&G[13]===H[13]&&G[14]===H[14]&&G[15]===H[15]},L0=function(G){return G=G||new O(16),G[0]=1,G[1]=0,G[2]=0,G[3]=0,G[4]=0,G[5]=1,G[6]=0,G[7]=0,G[8]=0,G[9]=0,G[10]=1,G[11]=0,G[12]=0,G[13]=0,G[14]=0,G[15]=1,G},fG=function(G,H){if(H=H||new O(16),H===G){let E;return E=G[1],G[1]=G[4],G[4]=E,E=G[2],G[2]=G[8],G[8]=E,E=G[3],G[3]=G[12],G[12]=E,E=G[6],G[6]=G[9],G[9]=E,E=G[7],G[7]=G[13],G[13]=E,E=G[11],G[11]=G[14],G[14]=E,H}const J=G[0],K=G[1],W=G[2],C=G[3],F=G[4],j=G[5],_=G[6],U=G[7],Y=G[8],B=G[9],X=G[10],D=G[11],h=G[12],P=G[13],Z=G[14],N=G[15];return H[0]=J,H[1]=F,H[2]=Y,H[3]=h,H[4]=K,H[5]=j,H[6]=B,H[7]=P,H[8]=W,H[9]=_,H[10]=X,H[11]=Z,H[12]=C,H[13]=U,H[14]=D,H[15]=N,H},R0=function(G,H){H=H||new O(16);const J=G[0],K=G[1],W=G[2],C=G[3],F=G[4],j=G[5],_=G[6],U=G[7],Y=G[8],B=G[9],X=G[10],D=G[11],h=G[12],P=G[13],Z=G[14],N=G[15],E=X*N,f=Z*D,M=_*N,S=Z*U,I=_*D,A=X*U,u=W*N,V=Z*C,T=W*D,q=X*C,g=W*U,r=_*C,z=Y*P,$=h*B,l=F*P,c=h*j,n=F*B,b=Y*j,e=J*P,a=h*K,m=J*B,d=Y*K,s=J*j,t=F*K,F0=E*j+S*B+I*P-(f*j+M*B+A*P),C0=f*K+u*B+q*P-(E*K+V*B+T*P),B0=M*K+V*j+g*P-(S*K+u*j+r*P),X0=A*K+T*j+r*B-(I*K+q*j+g*B),o=1/(J*F0+F*C0+Y*B0+h*X0);return H[0]=o*F0,H[1]=o*C0,H[2]=o*B0,H[3]=o*X0,H[4]=o*(f*F+M*Y+A*h-(E*F+S*Y+I*h)),H[5]=o*(E*J+V*Y+T*h-(f*J+u*Y+q*h)),H[6]=o*(S*J+u*F+r*h-(M*J+V*F+g*h)),H[7]=o*(I*J+q*F+g*Y-(A*J+T*F+r*Y)),H[8]=o*(z*U+c*D+n*N-($*U+l*D+b*N)),H[9]=o*($*C+e*D+d*N-(z*C+a*D+m*N)),H[10]=o*(l*C+a*U+s*N-(c*C+e*U+t*N)),H[11]=o*(b*C+m*U+t*D-(n*C+d*U+s*D)),H[12]=o*(l*X+b*Z+$*_-(n*Z+z*_+c*X)),H[13]=o*(m*Z+z*W+a*X-(e*X+d*Z+$*W)),H[14]=o*(e*_+t*Z+c*W-(s*Z+l*W+a*_)),H[15]=o*(s*X+n*W+d*_-(m*_+t*X+b*W)),H},MG=function(G){const H=G[0],J=G[1],K=G[2],W=G[3],C=G[4],F=G[5],j=G[6],_=G[7],U=G[8],Y=G[9],B=G[10],X=G[11],D=G[12],h=G[13],P=G[14],Z=G[15],N=B*Z,E=P*X,f=j*Z,M=P*_,S=j*X,I=B*_,A=K*Z,u=P*W,V=K*X,T=B*W,q=K*_,g=j*W,r=N*F+M*Y+S*h-(E*F+f*Y+I*h),z=E*J+A*Y+T*h-(N*J+u*Y+V*h),$=f*J+u*F+q*h-(M*J+A*F+g*h),l=I*J+V*F+g*Y-(S*J+T*F+q*Y);return H*r+C*z+U*$+D*l},k0=function(G,H,J){J=J||new O(16);const K=G[0],W=G[1],C=G[2],F=G[3],j=G[4],_=G[5],U=G[6],Y=G[7],B=G[8],X=G[9],D=G[10],h=G[11],P=G[12],Z=G[13],N=G[14],E=G[15],f=H[0],M=H[1],S=H[2],I=H[3],A=H[4],u=H[5],V=H[6],T=H[7],q=H[8],g=H[9],r=H[10],z=H[11],$=H[12],l=H[13],c=H[14],n=H[15];return J[0]=K*f+j*M+B*S+P*I,J[1]=W*f+_*M+X*S+Z*I,J[2]=C*f+U*M+D*S+N*I,J[3]=F*f+Y*M+h*S+E*I,J[4]=K*A+j*u+B*V+P*T,J[5]=W*A+_*u+X*V+Z*T,J[6]=C*A+U*u+D*V+N*T,J[7]=F*A+Y*u+h*V+E*T,J[8]=K*q+j*g+B*r+P*z,J[9]=W*q+_*g+X*r+Z*z,J[10]=C*q+U*g+D*r+N*z,J[11]=F*q+Y*g+h*r+E*z,J[12]=K*$+j*l+B*c+P*n,J[13]=W*$+_*l+X*c+Z*n,J[14]=C*$+U*l+D*c+N*n,J[15]=F*$+Y*l+h*c+E*n,J},IG=function(G,H,J){if(J=J||L0(),G!==J)J[0]=G[0],J[1]=G[1],J[2]=G[2],J[3]=G[3],J[4]=G[4],J[5]=G[5],J[6]=G[6],J[7]=G[7],J[8]=G[8],J[9]=G[9],J[10]=G[10],J[11]=G[11];return J[12]=H[0],J[13]=H[1],J[14]=H[2],J[15]=1,J},AG=function(G,H){return H=H||i(),H[0]=G[12],H[1]=G[13],H[2]=G[14],H},uG=function(G,H,J){J=J||i();const K=H*4;return J[0]=G[K+0],J[1]=G[K+1],J[2]=G[K+2],J},VG=function(G,H,J,K){if(K!==G)K=J0(G,K);const W=J*4;return K[W+0]=H[0],K[W+1]=H[1],K[W+2]=H[2],K},TG=function(G,H){H=H||i();const J=G[0],K=G[1],W=G[2],C=G[4],F=G[5],j=G[6],_=G[8],U=G[9],Y=G[10];return H[0]=Math.sqrt(J*J+K*K+W*W),H[1]=Math.sqrt(C*C+F*F+j*j),H[2]=Math.sqrt(_*_+U*U+Y*Y),H},qG=function(G,H,J,K,W){W=W||new O(16);const C=Math.tan(Math.PI*0.5-0.5*G);if(W[0]=C/H,W[1]=0,W[2]=0,W[3]=0,W[4]=0,W[5]=C,W[6]=0,W[7]=0,W[8]=0,W[9]=0,W[11]=-1,W[12]=0,W[13]=0,W[15]=0,K===Infinity)W[10]=-1,W[14]=-J;else{const F=1/(J-K);W[10]=K*F,W[14]=K*J*F}return W},gG=function(G,H,J,K,W,C,F){return F=F||new O(16),F[0]=2/(H-G),F[1]=0,F[2]=0,F[3]=0,F[4]=0,F[5]=2/(K-J),F[6]=0,F[7]=0,F[8]=0,F[9]=0,F[10]=1/(W-C),F[11]=0,F[12]=(H+G)/(G-H),F[13]=(K+J)/(J-K),F[14]=W/(W-C),F[15]=1,F},oG=function(G,H,J,K,W,C,F){F=F||new O(16);const j=H-G,_=K-J,U=W-C;return F[0]=2*W/j,F[1]=0,F[2]=0,F[3]=0,F[4]=0,F[5]=2*W/_,F[6]=0,F[7]=0,F[8]=(G+H)/j,F[9]=(K+J)/_,F[10]=C/U,F[11]=-1,F[12]=0,F[13]=0,F[14]=W*C/U,F[15]=0,F},rG=function(G,H,J,K){return K=K||new O(16),R=R||i(),k=k||i(),L=L||i(),p(v(H,G,L),L),p(x(J,L,R),R),p(x(L,R,k),k),K[0]=R[0],K[1]=R[1],K[2]=R[2],K[3]=0,K[4]=k[0],K[5]=k[1],K[6]=k[2],K[7]=0,K[8]=L[0],K[9]=L[1],K[10]=L[2],K[11]=0,K[12]=G[0],K[13]=G[1],K[14]=G[2],K[15]=1,K},zG=function(G,H,J,K){return K=K||new O(16),R=R||i(),k=k||i(),L=L||i(),p(v(G,H,L),L),p(x(J,L,R),R),p(x(L,R,k),k),K[0]=R[0],K[1]=R[1],K[2]=R[2],K[3]=0,K[4]=k[0],K[5]=k[1],K[6]=k[2],K[7]=0,K[8]=L[0],K[9]=L[1],K[10]=L[2],K[11]=0,K[12]=G[0],K[13]=G[1],K[14]=G[2],K[15]=1,K},$G=function(G,H,J,K){return K=K||new O(16),R=R||i(),k=k||i(),L=L||i(),p(v(G,H,L),L),p(x(J,L,R),R),p(x(L,R,k),k),K[0]=R[0],K[1]=k[0],K[2]=L[0],K[3]=0,K[4]=R[1],K[5]=k[1],K[6]=L[1],K[7]=0,K[8]=R[2],K[9]=k[2],K[10]=L[2],K[11]=0,K[12]=-(R[0]*G[0]+R[1]*G[1]+R[2]*G[2]),K[13]=-(k[0]*G[0]+k[1]*G[1]+k[2]*G[2]),K[14]=-(L[0]*G[0]+L[1]*G[1]+L[2]*G[2]),K[15]=1,K},lG=function(G,H){return H=H||new O(16),H[0]=1,H[1]=0,H[2]=0,H[3]=0,H[4]=0,H[5]=1,H[6]=0,H[7]=0,H[8]=0,H[9]=0,H[10]=1,H[11]=0,H[12]=G[0],H[13]=G[1],H[14]=G[2],H[15]=1,H},iG=function(G,H,J){J=J||new O(16);const K=H[0],W=H[1],C=H[2],F=G[0],j=G[1],_=G[2],U=G[3],Y=G[4],B=G[5],X=G[6],D=G[7],h=G[8],P=G[9],Z=G[10],N=G[11],E=G[12],f=G[13],M=G[14],S=G[15];if(G!==J)J[0]=F,J[1]=j,J[2]=_,J[3]=U,J[4]=Y,J[5]=B,J[6]=X,J[7]=D,J[8]=h,J[9]=P,J[10]=Z,J[11]=N;return J[12]=F*K+Y*W+h*C+E,J[13]=j*K+B*W+P*C+f,J[14]=_*K+X*W+Z*C+M,J[15]=U*K+D*W+N*C+S,J},cG=function(G,H){H=H||new O(16);const J=Math.cos(G),K=Math.sin(G);return H[0]=1,H[1]=0,H[2]=0,H[3]=0,H[4]=0,H[5]=J,H[6]=K,H[7]=0,H[8]=0,H[9]=-K,H[10]=J,H[11]=0,H[12]=0,H[13]=0,H[14]=0,H[15]=1,H},nG=function(G,H,J){J=J||new O(16);const K=G[4],W=G[5],C=G[6],F=G[7],j=G[8],_=G[9],U=G[10],Y=G[11],B=Math.cos(H),X=Math.sin(H);if(J[4]=B*K+X*j,J[5]=B*W+X*_,J[6]=B*C+X*U,J[7]=B*F+X*Y,J[8]=B*j-X*K,J[9]=B*_-X*W,J[10]=B*U-X*C,J[11]=B*Y-X*F,G!==J)J[0]=G[0],J[1]=G[1],J[2]=G[2],J[3]=G[3],J[12]=G[12],J[13]=G[13],J[14]=G[14],J[15]=G[15];return J},pG=function(G,H){H=H||new O(16);const J=Math.cos(G),K=Math.sin(G);return H[0]=J,H[1]=0,H[2]=-K,H[3]=0,H[4]=0,H[5]=1,H[6]=0,H[7]=0,H[8]=K,H[9]=0,H[10]=J,H[11]=0,H[12]=0,H[13]=0,H[14]=0,H[15]=1,H},xG=function(G,H,J){J=J||new O(16);const K=G[0],W=G[1],C=G[2],F=G[3],j=G[8],_=G[9],U=G[10],Y=G[11],B=Math.cos(H),X=Math.sin(H);if(J[0]=B*K-X*j,J[1]=B*W-X*_,J[2]=B*C-X*U,J[3]=B*F-X*Y,J[8]=B*j+X*K,J[9]=B*_+X*W,J[10]=B*U+X*C,J[11]=B*Y+X*F,G!==J)J[4]=G[4],J[5]=G[5],J[6]=G[6],J[7]=G[7],J[12]=G[12],J[13]=G[13],J[14]=G[14],J[15]=G[15];return J},yG=function(G,H){H=H||new O(16);const J=Math.cos(G),K=Math.sin(G);return H[0]=J,H[1]=K,H[2]=0,H[3]=0,H[4]=-K,H[5]=J,H[6]=0,H[7]=0,H[8]=0,H[9]=0,H[10]=1,H[11]=0,H[12]=0,H[13]=0,H[14]=0,H[15]=1,H},vG=function(G,H,J){J=J||new O(16);const K=G[0],W=G[1],C=G[2],F=G[3],j=G[4],_=G[5],U=G[6],Y=G[7],B=Math.cos(H),X=Math.sin(H);if(J[0]=B*K+X*j,J[1]=B*W+X*_,J[2]=B*C+X*U,J[3]=B*F+X*Y,J[4]=B*j-X*K,J[5]=B*_-X*W,J[6]=B*U-X*C,J[7]=B*Y-X*F,G!==J)J[8]=G[8],J[9]=G[9],J[10]=G[10],J[11]=G[11],J[12]=G[12],J[13]=G[13],J[14]=G[14],J[15]=G[15];return J},f0=function(G,H,J){J=J||new O(16);let K=G[0],W=G[1],C=G[2];const F=Math.sqrt(K*K+W*W+C*C);K/=F,W/=F,C/=F;const j=K*K,_=W*W,U=C*C,Y=Math.cos(H),B=Math.sin(H),X=1-Y;return J[0]=j+(1-j)*Y,J[1]=K*W*X+C*B,J[2]=K*C*X-W*B,J[3]=0,J[4]=K*W*X-C*B,J[5]=_+(1-_)*Y,J[6]=W*C*X+K*B,J[7]=0,J[8]=K*C*X+W*B,J[9]=W*C*X-K*B,J[10]=U+(1-U)*Y,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J},M0=function(G,H,J,K){K=K||new O(16);let W=H[0],C=H[1],F=H[2];const j=Math.sqrt(W*W+C*C+F*F);W/=j,C/=j,F/=j;const _=W*W,U=C*C,Y=F*F,B=Math.cos(J),X=Math.sin(J),D=1-B,h=_+(1-_)*B,P=W*C*D+F*X,Z=W*F*D-C*X,N=W*C*D-F*X,E=U+(1-U)*B,f=C*F*D+W*X,M=W*F*D+C*X,S=C*F*D-W*X,I=Y+(1-Y)*B,A=G[0],u=G[1],V=G[2],T=G[3],q=G[4],g=G[5],r=G[6],z=G[7],$=G[8],l=G[9],c=G[10],n=G[11];if(K[0]=h*A+P*q+Z*$,K[1]=h*u+P*g+Z*l,K[2]=h*V+P*r+Z*c,K[3]=h*T+P*z+Z*n,K[4]=N*A+E*q+f*$,K[5]=N*u+E*g+f*l,K[6]=N*V+E*r+f*c,K[7]=N*T+E*z+f*n,K[8]=M*A+S*q+I*$,K[9]=M*u+S*g+I*l,K[10]=M*V+S*r+I*c,K[11]=M*T+S*z+I*n,G!==K)K[12]=G[12],K[13]=G[13],K[14]=G[14],K[15]=G[15];return K},aG=function(G,H){return H=H||new O(16),H[0]=G[0],H[1]=0,H[2]=0,H[3]=0,H[4]=0,H[5]=G[1],H[6]=0,H[7]=0,H[8]=0,H[9]=0,H[10]=G[2],H[11]=0,H[12]=0,H[13]=0,H[14]=0,H[15]=1,H},mG=function(G,H,J){J=J||new O(16);const K=H[0],W=H[1],C=H[2];if(J[0]=K*G[0],J[1]=K*G[1],J[2]=K*G[2],J[3]=K*G[3],J[4]=W*G[4],J[5]=W*G[5],J[6]=W*G[6],J[7]=W*G[7],J[8]=C*G[8],J[9]=C*G[9],J[10]=C*G[10],J[11]=C*G[11],G!==J)J[12]=G[12],J[13]=G[13],J[14]=G[14],J[15]=G[15];return J},dG=function(G,H){return H=H||new O(16),H[0]=G,H[1]=0,H[2]=0,H[3]=0,H[4]=0,H[5]=G,H[6]=0,H[7]=0,H[8]=0,H[9]=0,H[10]=G,H[11]=0,H[12]=0,H[13]=0,H[14]=0,H[15]=1,H},sG=function(G,H,J){if(J=J||new O(16),J[0]=H*G[0],J[1]=H*G[1],J[2]=H*G[2],J[3]=H*G[3],J[4]=H*G[4],J[5]=H*G[5],J[6]=H*G[6],J[7]=H*G[7],J[8]=H*G[8],J[9]=H*G[9],J[10]=H*G[10],J[11]=H*G[11],G!==J)J[12]=G[12],J[13]=G[13],J[14]=G[14],J[15]=G[15];return J};var w=0.000001;var V0=new Map([[Float32Array,()=>new Float32Array(12)],[Float64Array,()=>new Float64Array(12)],[Array,()=>new Array(12).fill(0)]]),CH=V0.get(Float32Array);var Q=Float32Array,q0=i,n0=v,a0=Y0,d0=j0,s0=U0,t0=h0,GG=D0,HG=P0,KG=Q0,WG=E0,FG=O0,N0=Object.freeze({__proto__:null,create:i,setDefaultType:T0,fromValues:q0,set:g0,ceil:o0,floor:r0,round:z0,clamp:$0,add:l0,addScaled:i0,angle:c0,subtract:v,sub:n0,equalsApproximately:p0,equals:x0,lerp:y0,lerpV:v0,max:b0,min:e0,mulScalar:Y0,scale:a0,divScalar:m0,inverse:j0,invert:d0,cross:x,dot:_0,length:U0,len:s0,lengthSq:h0,lenSq:t0,distance:D0,dist:GG,distanceSq:P0,distSq:HG,normalize:p,negate:JG,copy:Q0,clone:KG,multiply:E0,mul:WG,divide:O0,div:FG,random:CG,zero:BG,transformMat4:XG,transformMat4Upper3x3:ZG,transformMat3:YG,transformQuat:jG,getTranslation:_G,getAxis:UG,getScaling:hG}),O=Float32Array,LG=J0,SG=R0,wG=k0,R,k,L,bG=f0,eG=M0,y=Object.freeze({__proto__:null,setDefaultType:DG,create:PG,set:QG,fromMat3:EG,fromQuat:OG,negate:NG,copy:J0,clone:LG,equalsApproximately:RG,equals:kG,identity:L0,transpose:fG,inverse:R0,determinant:MG,invert:SG,multiply:k0,mul:wG,setTranslation:IG,getTranslation:AG,getAxis:uG,setAxis:VG,getScaling:TG,perspective:qG,ortho:gG,frustum:oG,aim:rG,cameraAim:zG,lookAt:$G,translation:lG,translate:iG,rotationX:cG,rotateX:nG,rotationY:pG,rotateY:xG,rotationZ:yG,rotateZ:vG,axisRotation:f0,rotation:bG,axisRotate:M0,rotate:eG,scaling:aG,scale:mG,uniformScaling:dG,uniformScale:sG});class K0 extends S0{G;H;J;K;depthTexture;uniformBuffer;vertexBuffer;texture;sampler;uniformBindGroup;renderPassDescriptor;pipeline;viewMatrix=y.translate(y.identity(),N0.fromValues(0,0,-4));projectionMatrix=y.perspective(2*Math.PI*0.2,1.7777777777777777,1,100);constructor(G,H,J,K){super(G);this.app=G;this.mesh=H;this.shader=J;this.textures=K}onStart(){this.projectionMatrix=y.perspective(2*Math.PI*0.2,this.app.canvas.width/this.app.canvas.height,1,100),this.depthTexture=this.app.device.createTexture({size:[this.app.canvas.width,this.app.canvas.height],format:"depth24plus",usage:GPUTextureUsage.RENDER_ATTACHMENT}),this.uniformBuffer=this.app.device.createBuffer({size:68,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.pipeline=this.mesh.pipeline(this.app,this.shader,{}),this.uniformBindGroup=this.app.device.createBindGroup({layout:this.pipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.uniformBuffer}}]}),this.renderPassDescriptor={colorAttachments:[],depthStencilAttachment:{view:this.depthTexture.createView(),depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store"}},this.vertexBuffer=this.mesh.buffer(this.app)}writeUniforms(G,H){if(!this.uniformBuffer)return;const{device:{queue:J}}=this.app,K=G;J.writeBuffer(this.uniformBuffer,0,K.buffer,K.byteOffset,K.length);const W=new Float32Array([H]);J.writeBuffer(this.uniformBuffer,K.length+1,W.buffer,W.byteOffset,W.byteLength)}onUpdate(G){if(!this.renderPassDescriptor||!this.pipeline||!this.uniformBindGroup||!this.vertexBuffer)return;const H=y.multiply(this.projectionMatrix,this.viewMatrix);this.writeUniforms(H,G);const{device:J}=this.app,K=J.createCommandEncoder(),W=K.beginRenderPass(this.renderPassDescriptor);W.setPipeline(this.pipeline),W.setBindGroup(0,this.uniformBindGroup),W.setVertexBuffer(0,this.vertexBuffer),W.draw(this.mesh.config.vertexCount),W.end(),this.app.commit(K.finish())}}class W0{G;constructor(G){this.config=G}buffer(G){const H=G.device.createBuffer({size:this.config.mesh.byteLength,usage:GPUBufferUsage.VERTEX,mappedAtCreation:!0});return new Float32Array(H.getMappedRange()).set(this.config.mesh),H.unmap(),H}pipeline(G,H,J){const K=H.module(G);return G.device.createRenderPipeline({layout:"auto",vertex:{module:K,entryPoint:"main",buffers:[{arrayStride:4,attributes:[{shaderLocation:0,offset:0,format:"float32x4"},{shaderLocation:2,offset:this.config.positionSize,format:"float32x4"},{shaderLocation:1,offset:this.config.positionSize+this.config.colorSize,format:"float32x4"}]}]},fragment:{module:K,entryPoint:"main",targets:[{format:"rgba8unorm"}]},primitive:{topology:"triangle-list",cullMode:J.cullMode??"back"},depthStencil:J.stencil&&{depthWriteEnabled:!0,depthCompare:"less",format:"depth24plus"}})}}var tG=new Float32Array([-1,-1,0,1,1,1,1,1,0,0,1,-1,0,1,1,1,1,1,1,0,-1,1,0,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1]),w0=new W0({mesh:tG,positionSize:16,colorSize:16,uvSize:8});var I0="fn rgb2hsv(vec3f c)->vec3f{vec4f K=vec4f(0.0,-1.0/3.0,2.0/3.0,-1.0);vec4f p=mix(vec4f(c.bg,K.wz),vec4f(c.gb,K.xy),step(c.b,c.g));vec4f q=mix(vec4f(p.xyw,c.r),vec4f(c.r,p.yzx),step(p.x,c.r));f32 d=q.x-min(q.w,q.y);f32 e=1.0e-10;return vec3f(abs(q.z+(q.w-q.y)/(6.0*d+e)),d/(q.x+e),q.x);}fn hsv2rgb(vec3f c)->vec3f{vec4f K=vec4f(1.0,2.0/3.0,1.0/3.0,3.0);vec3f p=abs(fract(c.xxx+K.xyz)*6.0-K.www);return c.z*mix(K.xxx,clamp(p-K.xxx,0.0,1.0),c.y);}struct Uniforms{modelViewProjectionMatrix:mat4x4<f32>,time:f32,}@group(0)@binding(0)var<uniform> uniforms:Uniforms;struct v2f{@builtin(position)position:vec4f,@location(0)color:vec4f,@location(1)uv:vec2f,}@vertex fn main(@builtin(position)position:vec4f,@location(0)color:vec4f,@location(1)uv:vec2f,)->v2f{return v2f(uniforms.modelViewProjectionMatrix*position,color,uv);}@fragment fn main(@location(0)uv:vec2f,)->@location(0)vec4f{f32 z=sin(uniforms.time)*0.001*0.5+0.5;vec3f hsv=vec3f(uv.x,uv.y,z);hsv.x+=uniforms.time*0.0001;hsv.y=1.0;hsv.z=1.0;vec3f rgb=hsv2rgb(hsv);return saturate(vec4f(rgb,1.0));}";var A0="struct Uniforms{modelViewProjectionMatrix:mat4x4<f32>,time:f32,}@group(0)@binding(0)var<uniform> uniforms:Uniforms;struct v2f{@builtin(position)position:vec4f,@location(0)uv:vec2f,}@vertex fn vertex_main(@builtin(position)position:vec4f,@location(0)uv:vec2f,)->v2f{return v2f(uniforms.modelViewProjectionMatrix*position,uv);}@fragment fn fragment_main(@location(0)uv:vec2f,)->vec4f{return vec4f(1.0,0.0,1.0,1.0);}";var JH=new RegExp("#pragma ([a-z]+) ([a-zA-Z_0-9]+)","g");class G0{_module=null;vertexMain="main";fragmentMain="main";code;constructor(...G){this.code=G.join("\n");const H=this.code.matchAll(JH);for(let J of H||[])switch(J[1]){case"fragment":this.fragmentMain=J[2];break;case"vertex":this.vertexMain=J[2];break}}module(G){return this._module=this._module||(this._module=G.device.createShaderModule({code:this.code}))}}var EH=new G0(A0);var u0=new H0({fov:20}),KH=new G0(I0),MH=new K0(u0,w0,KH);u0.start();