1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2904],{27135:(e,t,i)=>{let r;i.d(t,{G:()=>em,R:()=>eh,S:()=>k,T:()=>ev,a:()=>V,b:()=>O,c:()=>U,d:()=>N,e:()=>$,f:()=>eT,g:()=>K,h:()=>Y,i:()=>A,j:()=>W,k:()=>X,l:()=>ef,m:()=>ep,n:()=>J,o:()=>Z,p:()=>ed,q:()=>q,r:()=>el,s:()=>B,t:()=>e_,u:()=>G,v:()=>H,w:()=>j,x:()=>Q,y:()=>eS,z:()=>eg});var s=i(68316),n=i(76022),a=i(9787),o=i(32587);i(5913);var h=i(6830),l=i(53944),u=i(47766),c=i(57143),d=i(78297),f=i(66848),p=i(30778),m=i(93332),g=i(89848),v=i(4208),x=i(11212),_=i(46495),y=i(33584);i(36312);var b=i(51254),w=i(42227),C=i(5718),M=i(2214),T=i(84993),S=i(85973),E=i(35255),F=i(27812),L=i(97141),I=i(68104),D=i(11441);function A(e,t){t.createImage=function(t,i){return new e.Image(t,i)},t.saveCanvas=function(...e){let i,r,s,n,o;if(e[0]instanceof HTMLCanvasElement)i=e[0],e.shift();else if(e[0]instanceof a.H)i=e[0].elt,e.shift();else if(e[0]instanceof eM){let t=e[0];(n=this.createGraphics(t.width,t.height)).pixelDensity(t.pixelDensity()),t.loadPixels(),n.loadPixels(),n.pixels.set(t.pixels),n.updatePixels(),i=n._renderer.canvas,e.shift()}else i=this._curElement&&this._curElement.elt;switch(e.length>=1&&(r=e[0]),e.length>=2&&(s=e[1]),s=s||t._checkFileExtension(r,s)[1]||"png"){default:o="image/png";break;case"webp":o="image/webp";break;case"jpeg":case"jpg":o="image/jpeg"}i.toBlob(e=>{t.downloadFile(e,r,s),n&&n.remove()},o)},t.encodeAndDownloadGif=function(e,i){let r=e.gifProperties,s=r.loopLimit;1===s?s=null:null===s&&(s=0);let n=new Uint8Array(e.width*e.height*r.numFrames),a=[],o={};for(let t=0;t<r.numFrames;t++){let i=new Set,s=r.frames[t].image.data,n=s.length,h=new Uint32Array(e.width*e.height);for(let e=0,t=0;e<n;e+=4,t++){let r=s[e+0],n=r<<16|s[e+1]<<8|(0|s[e+2]);i.add(n),h[t]=n}let l=[...i].sort().toString();void 0===o[l]?o[l]={freq:1,frames:[t]}:(o[l].freq+=1,o[l].frames.push(t)),a.push(h)}let h=[],l=Object.keys(o).sort(function(e,t){return o[t].freq-o[e].freq}),u=l[0].split(",").map(e=>parseInt(e));h=h.concat(o[u].frames);let c=new Set(u);for(let e=1;e<l.length;e++){let t=l[e].split(",").map(e=>parseInt(e)).filter(e=>!c.has(e));if(u.length+t.length<=256){for(let e=0;e<t.length;e++)u.push(t[e]),c.add(t[e]);h=h.concat(o[l[e]].frames)}}h=new Set(h);let d={};for(let e=0;e<u.length;e++)d[u[e]]||(d[u[e]]=e);let p=1;for(;p<u.length;)p<<=1;u.length=p;let m={loop:s,palette:new Uint32Array(u)},g=new f.e(n,e.width,e.height,m),v={};for(let t=0;t<r.numFrames;t++){let i=!h.has(t),s=i?[]:u,n=new Uint8Array(e.width*e.height),o={},l=new Set;a[t].forEach((e,r)=>{i?(void 0===o[e]&&(o[e]=s.length,s.push(e)),n[r]=o[e]):n[r]=d[e],t>0&&a[t-1][r]!==e&&l.add(e)});let c={},f=s.filter(e=>!l.has(e));if(f.length>0){let e=f[0],r=i?o[e]:d[e];if(t>0){for(let e=0;e<a[t].length;e++)a[t-1][e]===a[t][e]&&(n[e]=r);c.transparent=r,v.frameOpts.disposal=1}}if(c.delay=r.frames[t].delay/10,i){let e=1;for(;e<s.length;)e<<=1;s.length=e,c.palette=new Uint32Array(s)}t>0&&g.addFrame(0,0,e.width,e.height,v.pixelPaletteIndex,v.frameOpts),v={pixelPaletteIndex:n,frameOpts:c}}v.frameOpts.disposal=1,g.addFrame(0,0,e.width,e.height,v.pixelPaletteIndex,v.frameOpts);let x=new Blob([n.slice(0,g.end())],{type:"image/gif"});t.downloadFile(x,i,"gif")},t.saveFrames=function(e,i,r,s,n){let a=r||3;a=1e3*Math.max(Math.min(a,15),0);let o=s||15;o=Math.max(Math.min(o,22),0);let h=0,l=t._makeFrame,u=this._curElement.elt,c=[],d=setInterval(()=>{c.push(l(e+h,i,u)),h++},1e3/o);setTimeout(()=>{if(clearInterval(d),n)n(c);else for(let e of c)t.downloadFile(e.imageData,e.filename,e.ext);c=[]},a+.01)},t._makeFrame=function(e,t,i){let r,s;if(r=this?this._curElement.elt:i,t)switch(t.toLowerCase()){case"png":default:s="image/png";break;case"jpeg":case"jpg":s="image/jpeg"}else t="png",s="image/png";let n=r.toDataURL(s);n=n.replace(s,"image/octet-stream");let a={};return a.imageData=n,a.filename=e,a.ext=t,a}}"undefined"!=typeof p5&&A(p5,p5.prototype);class P extends Error{status;response;ok}async function V(e,t){try{let i=await fetch(e);if(i.ok){let e;switch(t){case"json":e=await i.json();break;case"text":e=await i.text();break;case"arrayBuffer":e=await i.arrayBuffer();break;case"blob":e=await i.blob();break;
1case"bytes":if(i.bytes)e=await i.bytes();else{let t=await i.arrayBuffer();e=new Uint8Array(t)}break;default:throw Error("Unsupported response type")}return{data:e,headers:i.headers}}{let e=new P(i.statusText);throw e.status=i.status,e.response=i,e.ok=!1,e}}catch(e){throw e instanceof TypeError?console.log("You may have encountered a CORS error"):e instanceof P?console.log("You have encountered a HTTP error"):e instanceof SyntaxError&&console.log("There is an error parsing the response to requested data structure"),e}}function N(e,t){function i(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}t.loadJSON=async function(t,i,r){try{let{data:e}=await V(t,"json");if(i)return i(e);return e}catch(i){if(e._friendlyFileLoadError(5,t),r)return r(i);throw i}},t.loadStrings=async function(t,i,r){try{let{data:e}=await V(t,"text");if(e=e.split(/\r?\n/),i)return i(e);return e}catch(i){if(e._friendlyFileLoadError(3,t),r)return r(i);throw i}},t.loadTable=async function(t,i,r,s,n){"function"==typeof arguments[arguments.length-1]&&("function"==typeof arguments[arguments.length-2]?(s=arguments[arguments.length-2],n=arguments[arguments.length-1]):s=arguments[arguments.length-1]),"string"!=typeof i&&(i=","),"function"==typeof r&&(r=!1);try{let{data:n}=await V(t,"text"),a=new e.Table;if(n=(0,m.q)(n,{separator:i}),r?a.columns=n.shift():a.columns=Array(n[0].length).fill(null),n.forEach(t=>{let i=new e.TableRow(t);a.addRow(i)}),s)return s(a);return a}catch(i){if(e._friendlyFileLoadError(2,t),n)return n(i);throw i}},t.loadXML=async function(t,i,r){try{let r=new DOMParser,{data:s}=await V(t,"text"),n=r.parseFromString(s,"application/xml");if(s=new e.XML(n),i)return i(s);return s}catch(i){if(e._friendlyFileLoadError(1,t),r)return r(i);throw i}},t.loadBytes=async function(t,i,r){try{let{data:e}=await V(t,"arrayBuffer");if(e=new Uint8Array(e),i)return i(e);return e}catch(i){if(e._friendlyFileLoadError(6,t),r)return r(i);throw i}},t.loadBlob=async function(e,t,i){try{let{data:i}=await V(e,"blob");if(t)return t(i);return i}catch(e){if(i)return i(e);throw e}},t.httpGet=async function(e,t="text",i,r){return"function"==typeof t&&(r=i,i=t,t="text"),this.httpDo(e,"GET",t,i,r)},t.httpPost=async function(t,i,r="text",s,n){"function"==typeof i?(s=i,n=r,i=void 0,r="text"):"function"==typeof r&&(n=s,s=r,r="text");let a=i,o="text/plain";i instanceof e.XML?(a=i.serialize(),o="application/xml"):i instanceof e.Image?(a=await i.toBlob(),o="image/png"):"object"==typeof i&&(a=JSON.stringify(i),o="application/json");let h={method:"POST",body:a,headers:{"Content-Type":o}};a&&(h.body=a);let l=new Request(t,h);return this.httpDo(l,"POST",r,s,n)},t.httpDo=async function(e,t,i,r,s){if("function"==typeof i&&(s=r,r=i,i=void 0),!i)switch("string"==typeof e?e.split(".").pop():e.url.split(".").pop()){case"json":i="json";break;case"jpg":case"jpeg":case"png":case"webp":case"gif":i="blob";break;default:i="text"}let n=new Request(e,{method:t});try{let{data:e}=await V(n,i);if(r)return r(e);return e}catch(e){if(s)return s(e);throw e}},t._pWriters=[],t.createWriter=function(i,r){let s;for(let n in t._pWriters)if(t._pWriters[n].name===i)return s=new e.PrintWriter(i+this.millis(),r),t._pWriters.push(s),s;return s=new e.PrintWriter(i,r),t._pWriters.push(s),s},e.PrintWriter=function(e,i){let r=this;this.name=e,this.content="",this.write=function(e){this.content+=e},this.print=function(e){this.content+=`${e} 2`},this.clear=function(){this.content=""},this.close=function(){let s=[];for(let r in s.push(this.content),t.writeFile(s,e,i),t._pWriters)t._pWriters[r].name===this.name&&t._pWriters.splice(r,1);r.clear(),r={}}},t.save=function(i,r,s){let n=arguments,a=this._curElement?this._curElement.elt:this.elt;if(0===n.length)return void t.saveCanvas(a);if(n[0]instanceof o.R||n[0]instanceof em)return void t.saveCanvas(n[0].canvas,n[1],n[2]);if(1===n.length&&"string"==typeof n[0])t.saveCanvas(a,n[0]);else switch((0,g.N)(n[1],n[2])[1]){case"json":t.saveJSON(n[0],n[1],n[2]);return;case"txt":t.saveStrings(n[0],n[1],n[2]);return;default:n[0]instanceof Array?t.saveStrings(n[0],n[1],n[2]):n[0]instanceof e.Table?t.saveTable(n[0],n[1],n[2]):n[0]instanceof e.Image?t.saveCanvas(n[0].canvas,n[1]):n[0]instanceof e.SoundFile&&t.saveSound(n[0],n[1],n[2],n[3])}},t.saveJSON=function(e,t,i){let r;r=i?JSON.stringify(e):JSON.stringify(e,void 0,2),this.saveStrings(r.split("\n"),t,"json")},t.saveStrings=function(t,i,r,s){let n=new e.PrintWriter(i,r||"txt");for(let e of t)s?n.write(e+"\r\n"):n.write(e+"\n");n.close(),n.clear()},t.saveTable=function(e,t,r){let s;void 0===r?(s=t.substring(t.lastIndexOf(".")+1,t.length))===t&&(s="csv"):s=r;let n=this.createWriter(t,s),a=e.columns,o=",";if("tsv"===s&&(o=" "),"html"!==s){let t=e.toString(o);n.write(t)}else{n.print("<html>"),n.print("<head>");let t=' <meta http-equiv="content-type" content';if(t+='="text/html;charset=utf-8" />',n.print(t),n.print("</head>"),n.print("<body>"),n.print(" <table>"),"0"!==a[0]){n.print(" <tr>");for(let e=0;e<a.length;e++){let t=i(a[e]);n.print(` <td>${t}`),n.print(" </td>")}n.print(" </tr>")}for(let t=0;t<e.rows.length;t++){n.print(" <tr>");for(let r=0;r<e.columns.length;r++){let s=i(e.rows[t].getString(r));n.print(` <td>${s}`),n.print(" </td>")}n.print(" </tr>")}n.print(" </table>"),n.print("</body>"),n.print("</html>")}n.close(),n.clear()},t.writeFile=function(e,i,r){let s="application/octet-stream";t._isSafari()&&(s="text/plain");let n=new Blob(e,{type:s});t.downloadFile(n,i,r)},t.downloadFile=g.P,t._checkFileExtension=g.N,t._isSafari=function(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}}function O(e,t){async function i(t,i){let r=new f.u(t);i.width=i.canvas.width=r.width,i.height=i.canvas.height=r.height;let s=[],n=r.numFrames(),a=new Uint8ClampedArray(i.width*i.height*4),o=(t,r)=>{try{r.decodeAndBlitFrameRGBA(t,a)}catch(t){throw e._friendlyFileLoadError(8,i.src),t}}
2;for(let e=0;e<n;e++){let t=r.frameInfo(e),n=i.drawingContext.getImageData(0,0,i.width,i.height);a=n.data.slice(),o(e,r);let h=new ImageData(a,i.width,i.height);i.drawingContext.putImageData(h,0,0);let l=t.delay;0===l&&(l=10),s.push({image:i.drawingContext.getImageData(0,0,i.width,i.height),delay:10*l}),2===t.disposal?i.drawingContext.clearRect(t.x,t.y,t.width,t.height):3===t.disposal&&i.drawingContext.putImageData(n,0,0,t.x,t.y,t.width,t.height)}let h=r.loopCount();return null===h?h=1:0===h&&(h=null),i.drawingContext.putImageData(s[0].image,0,0),s.length>1&&(i.gifProperties={displayIndex:0,loopLimit:h,loopCount:0,frames:s,numFrames:n,playing:!0,timeDisplayed:0,lastChangeTime:0}),i}function r(e,t){return e>0&&e<t?e:t}t.loadImage=async function(t,r,s){try{let s=new e.Image(1,1,this),n=new Request(t,{method:"GET",mode:"cors"}),{data:a,headers:o}=await V(n,"bytes"),h=o.get("content-type");if(null===h&&console.warn("The image you loaded does not have a Content-Type header. If you are using the online editor consider reuploading the asset."),h&&h.includes("image/gif"))await i(a,s);else{let e=new Blob([a]),t=await createImageBitmap(e);s.width=s.canvas.width=t.width,s.height=s.canvas.height=t.height,s.drawingContext.drawImage(t,0,0)}if(s.modified=!0,r)return r(s);return s}catch(i){if(e._friendlyFileLoadError(0,t),"function"==typeof s)return s(i);throw i}},t.saveGif=async function(i,r,s={delay:0,units:"seconds",silent:!1,notificationDuration:0,notificationID:"progressBar",reset:!0}){let n,a,o,h,l;if("string"!=typeof i)throw TypeError("fileName parameter must be a string");if("number"!=typeof r)throw TypeError("Duration parameter must be a number");let u=s&&s.delay||0,c=s&&s.units||"seconds",d=s&&s.silent||!1,f=s&&s.notificationDuration||0,p=s&&s.notificationID||"progressBar",m=!s||void 0===s.reset||s.reset;if("number"!=typeof u)throw TypeError("Delay parameter must be a number");if("seconds"!==c&&"frames"!==c)throw TypeError('Units parameter must be either "frames" or "seconds"');if("boolean"!=typeof d)throw TypeError("Silent parameter must be a boolean");if("number"!=typeof f)throw TypeError("Notification duration parameter must be a number");if("string"!=typeof p)throw TypeError("Notification ID parameter must be a string");this._recording=!0;let g=this._targetFrameRate;(g===1/0||void 0===g||0===g)&&(g=60);let x=1/g*1e3;x=x<20?20:x;let _="seconds"===c?r*g:r,y="seconds"===c?u*g:u;m?(n=y,this.frameCount=n,a=_+y):a=(n=this.frameCount+y)+_;let b=this._renderer._pixelDensity;this.pixelDensity(1);let w=[];for(null!==document.getElementById(p)&&document.getElementById(p).remove(),d||((o=this.createP("")).id(p),o.style("font-size","16px"),o.style("font-family","Montserrat"),o.style("background-color","#ffffffa0"),o.style("padding","8px"),o.style("border-radius","10px"),o.position(0,0)),this._renderer instanceof e.RendererGL&&(h=new Uint8Array((l=this.drawingContext).drawingBufferWidth*l.drawingBufferHeight*4)),this.noLoop(),await new Promise(requestAnimationFrame);n<a;){let t;this.redraw(),await new Promise(requestAnimationFrame),this._renderer instanceof e.RendererGL?(h=new Uint8Array(l.drawingBufferWidth*l.drawingBufferHeight*4),l.readPixels(0,0,l.drawingBufferWidth,l.drawingBufferHeight,l.RGBA,l.UNSIGNED_BYTE,h),t=function(e,t,i){let r=parseInt(i/2),s=4*t,n=new Uint8Array(4*t);for(let t=0;t<r;++t){let r=t*s,a=(i-t-1)*s;n.set(e.subarray(r,r+s)),e.copyWithin(r,a,a+s),e.set(n,a)}return e}(h,this.width,this.height)):t=this.drawingContext.getImageData(0,0,this.width,this.height).data,w.push(t),n++,d||o.html("Saved frame <b>"+w.length.toString()+"</b> out of "+_.toString()),await new Promise(e=>setTimeout(e,0))}d||o.html("Frames processed, generating color palette..."),this.loop(),this.pixelDensity(b);let C=(0,v.GIFEncoder)(),M=function(e){let t=new Uint8Array(e.length*e[0].length);for(let i=0;i<e.length;i++)t.set(e[i],i*e[0].length);let i=(0,v.quantize)(t,256,{format:"rgba4444",oneBitAlpha:!0});return 256===i.length?i[i.length-1]=[255*Math.random(),255*Math.random(),255*Math.random(),0]:i.push([255*Math.random(),255*Math.random(),255*Math.random(),0]),i}(w),T={},S=e=>{let t=e.length/4,i=new Uint8Array(t);for(let r=0;r<t;r++){let t=e[4*r]<<24|e[4*r+1]<<16|e[4*r+2]<<8|e[4*r+3];void 0===T[t]&&(T[t]=(0,v.nearestColorIndex)(M,e.slice(4*r,(r+1)*4))),i[r]=T[t]}return i},E=M.length-1,F=[];for(let e=0;e<w.length;e++){let t=S(w[e]),i=t.slice();if(0===e)C.writeFrame(t,this.width,this.height,{palette:M,delay:x,dispose:1});else{for(let e=0;e<t.length;e++)t[e]===F[e]&&(t[e]=E);C.writeFrame(t,this.width,this.height,{delay:x,transparent:!0,transparentIndex:E,dispose:1})}F=i,d||o.html("Rendered frame <b>"+e.toString()+"</b> out of "+_.toString()),await new Promise(e=>setTimeout(e,0))}C.finish();let L=new Blob([C.bytesView()],{type:"image/gif"});w=[],this._recording=!1,this.loop(),!d&&(o.html("Done. Downloading your gif!\uD83C\uDF38"),f>0&&setTimeout(()=>
2o.remove(),1e3*f)),t.downloadFile(L,i,"gif")},t.image=function(e,t,i,n,a,o,h,l,u,c,d,f){let m=e.width,g=e.height;f=f||s.C,d=d||s.C,e.elt&&(m=void 0!==m?m:e.elt.width,g=void 0!==g?g:e.elt.height),e.elt&&e.elt.videoWidth&&!e.canvas&&(m=void 0!==m?m:e.elt.videoWidth,g=void 0!==g?g:e.elt.videoHeight);let v=n||m,x=a||g,_=o||0,y=h||0,b=void 0!==l?l:m,w=void 0!==u?u:g;b=r(b,m),w=r(w,g);let C=1;e.elt&&!e.canvas&&e.elt.style.width&&(C=(e.elt.videoWidth&&!n?e.elt.videoWidth:e.elt.width)/parseInt(e.elt.style.width,10)),_*=C,y*=C,w*=C,b*=C;let M=p.A.modeAdjust(t,i,v,x,this._renderer.states.imageMode);M=function(e,t,i,r,n,a,o,h,l,u,c){if(e===s.ap){let{x:e,y:r,w:n,h:d}=function(e,t,i,r,n,a,o,h){let l=Math.max(i/o,r/h),[u,c]=[i/l,r/l],d=n,f=a;return e===s.C?d+=(o-u)/2:e===s.R&&(d+=o-u),t===s.C?f+=(h-c)/2:t===s.ar&&(f+=h-c),{x:d,y:f,w:u,h:c}}(t,i,a,o,h,l,u,c);h=e,l=r,u=n,c=d}if(e===s.aq){let{x:e,y:h,w:l,h:d}=function(e,t,i,r,n,a,o,h){let l=Math.max(o/n,h/a),[u,c]=[o/l,h/l],d=i,f=r;return e===s.C?d+=(n-u)/2:e===s.R&&(d+=n-u),t===s.C?f+=(a-c)/2:t===s.ar&&(f+=a-c),{x:d,y:f,w:u,h:c}}(t,i,r,n,a,o,u,c);r=e,n=h,a=l,o=d}return{sx:h,sy:l,sw:u,sh:c,dx:r,dy:n,dw:a,dh:o}}(c,d,f,M.x,M.y,M.w,M.h,_,y,b,w),this._renderer.image(e,M.sx,M.sy,M.sw,M.sh,M.dx,M.dy,M.dw,M.dh)},t.tint=function(...e){let t=this.color(...e);this._renderer.states.setValue("tint",t._getRGBA([255,255,255,255]))},t.noTint=function(){this._renderer.states.setValue("tint",null)},t.imageMode=function(e){(e===s.e||e===s.i||e===s.C)&&this._renderer.states.setValue("imageMode",e)}}"undefined"!=typeof p5&&N(p5,p5.prototype),"undefined"!=typeof p5&&O(p5,p5.prototype);class R{constructor(e){this._renderer=e,this.cameraType="default",this.useLinePerspective=!0,this.cameraMatrix=new C.uq(4),this.projMatrix=new C.uq(4),this.yScale=1}perspective(e,t,i,r){this.cameraType=arguments.length>0?"custom":"default",void 0===e?(e=this.defaultCameraFOV,this.cameraFOV=e):this.cameraFOV=this._renderer._pInst._toRadians(e),void 0===t&&(t=this.defaultAspectRatio),void 0===i&&(i=this.defaultCameraNear),void 0===r&&(r=this.defaultCameraFar),i<=1e-4&&(i=.01,console.log("Avoid perspective near plane values close to or below 0. Setting value to 0.01.")),r<i&&console.log("Perspective far plane value is less than near plane value. Nothing will be shown."),this.aspectRatio=t,this.cameraNear=i,this.cameraFar=r,this.projMatrix=new C.uq(4);let s=1/Math.tan(this.cameraFOV/2),n=1/(this.cameraNear-this.cameraFar);this.projMatrix.set(s/t,0,0,0,0,-s*this.yScale,0,0,0,0,(r+i)*n,-1,0,0,2*r*i*n,0),this._isActive()&&(this._renderer.states.setValue("uPMatrix",this._renderer.states.uPMatrix.clone()),this._renderer.states.uPMatrix.set(this.projMatrix))}ortho(e,t,i,r,s,n){let a=this.fbo||this._renderer;void 0===e&&(e=-a.width/2),void 0===t&&(t=a.width/2),void 0===i&&(i=-a.height/2),void 0===r&&(r=a.height/2),void 0===s&&(s=0),void 0===n&&(n=Math.max(a.width,a.height)+800),this.cameraNear=s,this.cameraFar=n;let o=t-e,h=r-i,l=n-s,u=2/h*this.yScale,c=-(t+e)/o,d=-(r+i)/h,f=-(n+s)/l;this.projMatrix=new C.uq(4),this.projMatrix.set(2/o,0,0,0,0,-u,0,0,0,0,-2/l,0,c,d,f,1),this._isActive()&&(this._renderer.states.setValue("uPMatrix",this._renderer.states.uPMatrix.clone()),this._renderer.states.uPMatrix.set(this.projMatrix)),this.cameraType="custom"}frustum(e,t,i,r,s,n){void 0===e&&(e=-(.05*this._renderer.width)),void 0===t&&(t=.05*this._renderer.width),void 0===i&&(i=.05*this._renderer.height),void 0===r&&(r=-(.05*this._renderer.height)),void 0===s&&(s=this.defaultCameraNear),void 0===n&&(n=this.defaultCameraFar),this.cameraNear=s,this.cameraFar=n;let a=t-e,o=r-i,h=n-s,l=2*s/a,u=2*s/o*this.yScale,c=-(2*n*s)/h,d=(t+e)/a,f=(r+i)/o,p=-(n+s)/h;this.projMatrix=new C.uq(4),this.projMatrix.set(l,0,0,0,0,-u,0,0,d,f,p,-1,0,0,c,0),this._isActive()&&(this._renderer.states.setValue("uPMatrix",this._renderer.states.uPMatrix.clone()),this._renderer.states.uPMatrix.set(this.projMatrix)),this.cameraType="custom"}_rotateView(e,t,i,r){let s=this.centerX,n=this.centerY,a=this.centerZ;s-=this.eyeX,n-=this.eyeY,a-=this.eyeZ;let o=new C.uq(4);o.rotate4x4(this._renderer._pInst._toRadians(e),t,i,r);let h=[s*o.mat4[0]+n*o.mat4[4]+a*o.mat4[8],s*o.mat4[1]+n*o.mat4[5]+a*o.mat4[9],s*o.mat4[2]+n*o.mat4[6]+a*o.mat4[10]];h[0]+=this.eyeX,h[1]+=this.eyeY,h[2]+=this.eyeZ,this.camera(this.eyeX,this.eyeY,this.eyeZ,h[0],h[1],h[2],this.upX,this.upY,this.upZ)}roll(e){let t=this._getLocalAxes(),i=w.k.fromAxisAngle(this._renderer._pInst._toRadians(e),t.z[0],t.z[1],t.z[2]).rotateVector(new b.M(this.upX,this.upY,this.upZ));this.camera(this.eyeX,this.eyeY,this.eyeZ,this.centerX,this.centerY,this.centerZ,i.x,i.y,i.z)}pan(e){let t=this._getLocalAxes();this._rotateView(e,t.y[0],t.y[1],t.y[2])}tilt(e){let t=this._getLocalAxes();this._rotateView(e,t.x[0],t.x[1],t.x[2])}lookAt(e,t,i){this.camera(this.eyeX,this.eyeY,this.eyeZ,e,t,i,this.upX,this.upY,this.upZ)}camera(e,t,i,r,s,n,a,o,h){void 0===e&&(e=this.defaultEyeX,t=this.defaultEyeY,i=this.defaultEyeZ,r=e,s=t,n=0,a=0,o=1,h=0),this.eyeX=e,this.eyeY=t,this.eyeZ=i,void 0!==r&&(this.centerX=r,this.centerY=s,this.centerZ=n),void 0!==a&&(this.upX=a,this.upY=o,this.upZ=h);let l=this._getLocalAxes();this.cameraMatrix.set(l.x[0],l.y[0],l.z[0],0,l.x[1],l.y[1],l.z[1],0,l.x[2],l.y[2],l.z[2],0,0,0,0,1);let u=-e,c=-t,d=-i;return this.cameraMatrix.translate([u,c,d]),this._isActive()&&(this._renderer.states.setValue("uViewMatrix",this._renderer.states.uViewM
2atrix.clone()),this._renderer.states.uViewMatrix.set(this.cameraMatrix)),this}move(e,t,i){let r=this._getLocalAxes(),s=[r.x[0]*e,r.x[1]*e,r.x[2]*e],n=[r.y[0]*t,r.y[1]*t,r.y[2]*t],a=[r.z[0]*i,r.z[1]*i,r.z[2]*i];this.camera(this.eyeX+s[0]+n[0]+a[0],this.eyeY+s[1]+n[1]+a[1],this.eyeZ+s[2]+n[2]+a[2],this.centerX+s[0]+n[0]+a[0],this.centerY+s[1]+n[1]+a[1],this.centerZ+s[2]+n[2]+a[2],this.upX,this.upY,this.upZ)}setPosition(e,t,i){let r=e-this.eyeX,s=t-this.eyeY,n=i-this.eyeZ;this.camera(e,t,i,this.centerX+r,this.centerY+s,this.centerZ+n,this.upX,this.upY,this.upZ)}set(e){for(let t of["eyeX","eyeY","eyeZ","centerX","centerY","centerZ","upX","upY","upZ","cameraFOV","aspectRatio","cameraNear","cameraFar","cameraType","yScale","useLinePerspective"])this[t]=e[t];this.cameraMatrix=e.cameraMatrix.copy(),this.projMatrix=e.projMatrix.copy(),this._isActive()&&(this._renderer.states.setValue("uModelMatrix",this._renderer.states.uModelMatrix.clone()),this._renderer.states.setValue("uViewMatrix",this._renderer.states.uViewMatrix.clone()),this._renderer.states.setValue("uPMatrix",this._renderer.states.uPMatrix.clone()),this._renderer.states.uModelMatrix.reset(),this._renderer.states.uViewMatrix.set(this.cameraMatrix),this._renderer.states.uPMatrix.set(this.projMatrix))}slerp(e,t,i){let r,s,n,a;if(0===i)return void this.set(e);if(1===i)return void this.set(t);0!==this.projMatrix.mat4[15]&&(this.projMatrix.setElement(0,e.projMatrix.mat4[0]*Math.pow(t.projMatrix.mat4[0]/e.projMatrix.mat4[0],i)),this.projMatrix.setElement(5,e.projMatrix.mat4[5]*Math.pow(t.projMatrix.mat4[5]/e.projMatrix.mat4[5],i)),this._isActive()&&(this._renderer.states.setValue("uPMatrix",this._renderer.states.uPMatrix.clone()),this._renderer.states.uPMatrix.mat4=this.projMatrix.mat4.slice()));let o=new b.M(e.eyeX,e.eyeY,e.eyeZ),h=new b.M(t.eyeX,t.eyeY,t.eyeZ),l=new b.M(e.centerX,e.centerY,e.centerZ),u=new b.M(t.centerX,t.centerY,t.centerZ),c=b.M.dist(o,l),d=c*Math.pow(b.M.dist(h,u)/c,i),f=b.M.sub(o,h),p=o.copy().sub(h).sub(l).add(u),m=p.magSq(),g=1;m>1e-6&&(g=Math.max(0,Math.min(g=b.M.dot(f,p)/m,1)));let v=b.M.lerp(b.M.lerp(o,l,g),b.M.lerp(h,u,g),i),x=e.cameraMatrix.createSubMatrix3x3(),_=t.cameraMatrix.createSubMatrix3x3(),y=x.row(2),w=_.row(2),M=x.row(1),T=_.row(1),S=new b.M,E=new b.M,F=new b.M,L=new b.M,I=_.mult(x.copy().transpose()),D=I.diagonal(),A=.5*(D[0]+D[1]+D[2]-1);if(1-A<1e-7){S.set(b.M.lerp(y,w,i)).normalize(),F.set(S).mult(g*d).add(v),L.set(S).mult((g-1)*d).add(v),E.set(b.M.lerp(M,T,i)).normalize(),this.camera(F.x,F.y,F.z,L.x,L.y,L.z,E.x,E.y,E.z);return}let P=1/(1-A),V=Math.max(D[0],D[1],D[2]),N=I.mat3[1]+I.mat3[3],O=I.mat3[2]+I.mat3[6],R=I.mat3[5]+I.mat3[7];V===D[0]?(r=Math.sqrt((D[0]-A)*P),P/=r,s=.5*N*P,n=.5*O*P,a=.5*(I.mat3[7]-I.mat3[5])/r):V===D[1]?(s=Math.sqrt((D[1]-A)*P),P/=s,n=.5*R*P,r=.5*N*P,a=.5*(I.mat3[2]-I.mat3[6])/s):(n=Math.sqrt((D[2]-A)*P),P/=n,r=.5*O*P,s=.5*R*P,a=.5*(I.mat3[3]-I.mat3[1])/n);let U=i*Math.atan2(a,A),k=Math.cos(U),B=Math.sin(U),G=1-k,z=r*s,j=s*n,H=n*r,W=new C.uq([k+G*r*r,G*z+B*n,G*H-B*s,G*z-B*n,k+G*s*s,G*j+B*r,G*H+B*s,G*j-B*r,k+G*n*n]);W.multiplyVec(y,S),F.set(S).mult(g*d).add(v),L.set(S).mult((g-1)*d).add(v),W.multiplyVec(M,E),this.camera(F.x,F.y,F.z,L.x,L.y,L.z,E.x,E.y,E.z)}_computeCameraDefaultSettings(){this.defaultAspectRatio=this._renderer.width/this._renderer.height,this.defaultEyeX=0,this.defaultEyeY=0,this.defaultEyeZ=800,this.defaultCameraFOV=2*Math.atan(this._renderer.height/2/this.defaultEyeZ),this.defaultCenterX=0,this.defaultCenterY=0,this.defaultCenterZ=0,this.defaultCameraNear=.1*this.defaultEyeZ,this.defaultCameraFar=10*this.defaultEyeZ}_setDefaultCamera(){this.cameraFOV=this.defaultCameraFOV,this.aspectRatio=this.defaultAspectRatio,this.eyeX=this.defaultEyeX,this.eyeY=this.defaultEyeY,this.eyeZ=this.defaultEyeZ,this.centerX=this.defaultCenterX,this.centerY=this.defaultCenterY,this.centerZ=this.defaultCenterZ,this.upX=0,this.upY=1,this.upZ=0,this.cameraNear=this.defaultCameraNear,this.cameraFar=this.defaultCameraFar,this.perspective(),this.camera(),this.cameraType="default"}_resize(){"default"===this.cameraType&&(this._computeCameraDefaultSettings(),this.cameraFOV=this.defaultCameraFOV,this.aspectRatio=this.defaultAspectRatio,this.perspective())}copy(){let e=new R(this._renderer);return e.cameraFOV=this.cameraFOV,e.aspectRatio=this.aspectRatio,e.eyeX=this.eyeX,e.eyeY=this.eyeY,e.eyeZ=this.eyeZ,e.centerX=this.centerX,e.centerY=this.centerY,e.centerZ=this.centerZ,e.upX=this.upX,e.upY=this.upY,e.upZ=this.upZ,e.cameraNear=this.cameraNear,e.cameraFar=this.cameraFar,e.cameraType=this.cameraType,e.useLinePerspective=this.useLinePerspective,e.cameraMatrix=this.cameraMatrix.copy(),e.projMatrix=this.projMatrix.copy(),e.yScale=this.yScale,e.cameraType=this.cameraType,e}clone(){return this.copy()}_getLocalAxes(){let e=this.eyeX-this.centerX,t=this.eyeY-this.centerY,i=this.eyeZ-this.centerZ,r=Math.sqrt(e*e+t*t+i*i);0!==r&&(e/=r,t/=r,i/=r);let s=this.upX,n=this.upY,a=this.upZ,o=n*i-a*t,h=-s*i+a*e,l=s*t-n*e;s=t*l-i*h,n=-e*l+i*o,a=e*h-t*o;let u=Math.sqrt(o*o+h*h+l*l);0!==u&&(o/=u,h/=u,l/=u);let c=Math.sqrt(s*s+n*n+a*a);return 0!==c&&(s/=c,n/=c,a/=c),{x:[o,h,l],y:[s,n,a],z:[e,t,i]}}_orbit(e,t,i){let r=this.eyeX-this.centerX,s=this.eyeY-this.centerY,n=this.eyeZ-this.centerZ,a=Math.hypot(r,s,n),o=new b.M(r,s,n).normalize(),h=new b.M(this.upX,this.upY,this.upZ).normalize(),l=b.M.
2cross(h,o).normalize(),u=b.M.cross(l,h);(a*=Math.pow(10,i))<this.cameraNear&&(a=this.cameraNear),a>this.cameraFar&&(a=this.cameraFar);let c=Math.acos(Math.max(-1,Math.min(1,b.M.dot(o,h))))+t;(c<=0||c>=Math.PI)&&(this.upX*=-1,this.upY*=-1,this.upZ*=-1),h.mult(Math.cos(c)),u.mult(Math.cos(e)*Math.sin(c)),l.mult(Math.sin(e)*Math.sin(c)),o.set(h).add(u).add(l),this.eyeX=a*o.x+this.centerX,this.eyeY=a*o.y+this.centerY,this.eyeZ=a*o.z+this.centerZ,this.camera(this.eyeX,this.eyeY,this.eyeZ,this.centerX,this.centerY,this.centerZ,this.upX,this.upY,this.upZ)}_orbitFree(e,t,i){let r=this.eyeX-this.centerX,s=this.eyeY-this.centerY,n=this.eyeZ-this.centerZ,a=Math.hypot(r,s,n),o=new b.M(r,s,n).normalize(),h=new b.M(this.upX,this.upY,this.upZ),l=b.M.cross(h,o).normalize(),u=b.M.cross(o,l),c=Math.atan2(t,e);u.mult(Math.sin(c)),l.mult(Math.cos(c)).add(u);let d=Math.sqrt(e*e+t*t),f=b.M.cross(o,l);(a*=Math.pow(10,i))<this.cameraNear&&(a=this.cameraNear),a>this.cameraFar&&(a=this.cameraFar);let p=Math.cos(d),m=Math.sin(d),g=h.dot(o),v=h.dot(l),x=g*p+v*m,_=-g*m+v*p,y=h.dot(f);h.x=x*o.x+_*l.x+y*f.x,h.y=x*o.y+_*l.y+y*f.y,h.z=x*o.z+_*l.z+y*f.z,l.mult(-m),o.mult(p).add(l).mult(a),this.camera(o.x+this.centerX,o.y+this.centerY,o.z+this.centerZ,this.centerX,this.centerY,this.centerZ,h.x,h.y,h.z)}_isActive(){return this===this._renderer.states.curCamera}}function U(e,t){t.camera=function(...e){return this._assert3d("camera"),this._renderer.camera(...e),this},t.perspective=function(...e){return this._assert3d("perspective"),this._renderer.perspective(...e),this},t.linePerspective=function(e){if(!(this._renderer instanceof eh))throw Error("linePerspective() must be called in WebGL mode.");return this._renderer.linePerspective(e)},t.ortho=function(...e){return this._assert3d("ortho"),this._renderer.ortho(...e),this},t.frustum=function(...e){return this._assert3d("frustum"),this._renderer.frustum(...e),this},t.createCamera=function(){return this._assert3d("createCamera"),this._renderer.createCamera()},t.setCamera=function(e){this._renderer.setCamera(e)},e.Camera=R,eh.prototype.camera=function(...e){this.states.setValue("curCamera",this.states.curCamera.clone()),this.states.curCamera.camera(...e)},eh.prototype.perspective=function(...e){this.states.setValue("curCamera",this.states.curCamera.clone()),this.states.curCamera.perspective(...e)},eh.prototype.linePerspective=function(e){if(void 0===e)return this.states.curCamera.useLinePerspective;this.states.setValue("curCamera",this.states.curCamera.clone()),this.states.curCamera.useLinePerspective=e},eh.prototype.ortho=function(...e){this.states.setValue("curCamera",this.states.curCamera.clone()),this.states.curCamera.ortho(...e)},eh.prototype.frustum=function(...e){this.states.setValue("curCamera",this.states.curCamera.clone()),this.states.curCamera.frustum(...e)},eh.prototype.createCamera=function(){let e=new R(this);return e._computeCameraDefaultSettings(),e._setDefaultCamera(),e},eh.prototype.setCamera=function(e){this.states.setValue("curCamera",e),this.states.setValue("uPMatrix",this.states.uPMatrix.clone()),this.states.uPMatrix.set(e.projMatrix),this.states.setValue("uViewMatrix",this.states.uViewMatrix.clone()),this.states.uViewMatrix.set(e.cameraMatrix)}}"undefined"!=typeof p5&&U(p5,p5.prototype);class k{constructor(e,t,i,r={}){this._renderer=e,this._vertSrc=t,this._fragSrc=i,this._vertShader=-1,this._fragShader=-1,this._glProgram=0,this._loadedAttributes=!1,this.attributes={},this._loadedUniforms=!1,this.uniforms={},this._bound=!1,this.samplers=[],this.hooks={uniforms:r.uniforms||{},declarations:r.declarations,helpers:r.helpers||{},vertex:r.vertex||{},fragment:r.fragment||{},modified:{vertex:r.modified&&r.modified.vertex||{},fragment:r.modified&&r.modified.fragment||{}}}}hookTypes(e){let t=this._vertSrc,i=this.hooks.vertex[e];if(i||(i=this.hooks.fragment[e],t=this._fragSrc),!i)throw Error(`Can't find hook ${e}!`);let r=e.split(/\s+/g),s=r.pop(),n=r.pop(),a=[...r],o=/\(([^\)]*)\)/.exec(i);if(!o)throw Error(`Couldn't find function parameters in hook body: 3${i}`);let h=e=>{let i=RegExp(`struct\\s+${e}\\s*{([^}]*)}`).exec(t);if(!i)return;let r=[];for(let e of i[1].split(";")){let t=e.trim().split(/\s+|,/g),i=t.shift(),s=[...t],n=h(i);for(let e of s)r.push({name:e,type:{typeName:i,qualifiers:[],properties:n}})}return r}
3,l=o[1].split(",").map(e=>{let t=e.trim().split(/\s+/g),i=t.pop(),r=t.pop(),s=[...t],n=h(r);return{name:i,type:{typeName:r,qualifiers:s,properties:n}}});return{name:s,returnType:{typeName:n,qualifiers:a,properties:h(n)},parameters:l}}shaderSrc(e,t){let i="void main",[r,s]=e.split(i),n="",a="";for(let e in this.hooks.uniforms)n+=`uniform ${e}; 4`;for(let e in this.hooks.declarations&&(n+=this.hooks.declarations+"\n"),this.hooks[t].declarations&&(n+=this.hooks[t].declarations+"\n"),this.hooks.helpers)n+=`${e}${this.hooks.helpers[e]} 5`;for(let e in this.hooks[t]){if("declarations"===e)continue;let[i,r]=e.split(" ");this.hooks.modified[t][e]&&(a+="#define AUGMENTED_HOOK_"+r+"\n"),n+=i+" HOOK_"+r+this.hooks[t][e]+"\n"}return -1!==r.indexOf("#define HOOK_DEFINES")&&(r=r.replace("#define HOOK_DEFINES","\n"+a+"\n"),a=""),r+"\n"+a+n+i+s}version(){let e=/#version (.+)$/.exec(this.vertSrc());return e?e[1]:"100 es"}vertSrc(){return this.shaderSrc(this._vertSrc,"vertex")}fragSrc(){return this.shaderSrc(this._fragSrc,"fragment")}inspectHooks(){for(let e in console.log("==== Vertex shader hooks: ===="),this.hooks.vertex)console.log((this.hooks.modified.vertex[e]?"[MODIFIED] ":"")+e+this.hooks.vertex[e]);for(let e in console.log(""),console.log("==== Fragment shader hooks: ===="),this.hooks.fragment)console.log((this.hooks.modified.fragment[e]?"[MODIFIED] ":"")+e+this.hooks.fragment[e]);for(let e in console.log(""),console.log("==== Helper functions: ===="),this.hooks.helpers)console.log(e+this.hooks.helpers[e])}modify(e){let t={},i={},r={};for(let s in e)"declarations"!==s&&"uniforms"!==s&&("vertexDeclarations"===s?t.declarations=(t.declarations||"")+"\n"+e[s]:"fragmentDeclarations"===s?i.declarations=(i.declarations||"")+"\n"+e[s]:this.hooks.vertex[s]?t[s]=e[s]:this.hooks.fragment[s]?i[s]=e[s]:r[s]=e[s]);let s=Object.assign({},this.hooks.modified.vertex),n=Object.assign({},this.hooks.modified.fragment);for(let e in t||{})"declarations"!==e&&(s[e]=!0);for(let e in i||{})"declarations"!==e&&(n[e]=!0);return new k(this._renderer,this._vertSrc,this._fragSrc,{declarations:(this.hooks.declarations||"")+"\n"+(e.declarations||""),uniforms:Object.assign({},this.hooks.uniforms,e.uniforms||{}),fragment:Object.assign({},this.hooks.fragment,i||{}),vertex:Object.assign({},this.hooks.vertex,t||{}),helpers:Object.assign({},this.hooks.helpers,r||{}),modified:{vertex:s,fragment:n}})}init(){if(0===this._glProgram){let e=this._renderer.GL;if(this._vertShader=e.createShader(e.VERTEX_SHADER),e.shaderSource(this._vertShader,this.vertSrc()),e.compileShader(this._vertShader),!e.getShaderParameter(this._vertShader,e.COMPILE_STATUS)){let t=e.getShaderInfoLog(this._vertShader);if("undefined"!=typeof IS_MINIFIED||"undefined"==typeof p5)console.error(t);else throw p5._friendlyError(`Yikes! An error occurred compiling the vertex shader:${t}`),t;return null}if(this._fragShader=e.createShader(e.FRAGMENT_SHADER),e.shaderSource(this._fragShader,this.fragSrc()),e.compileShader(this._fragShader),!e.getShaderParameter(this._fragShader,e.COMPILE_STATUS)){let t=e.getShaderInfoLog(this._fragShader);if("undefined"!=typeof IS_MINIFIED||"undefined"==typeof p5)console.error(t);else throw p5._friendlyError(`Darn! An error occurred compiling the fragment shader:${t}`),t;return null}this._glProgram=e.createProgram(),e.attachShader(this._glProgram,this._vertShader),e.attachShader(this._glProgram,this._fragShader),e.linkProgram(this._glProgram),e.getProgramParameter(this._glProgram,e.LINK_STATUS)||p5._friendlyError(`Snap! Error linking shader program: ${e.getProgramInfoLog(this._glProgram)}`),this._loadAttributes(),this._loadUniforms()}return this}setDefaultUniforms(){for(let e in this.hooks.uniforms){let t,[,i]=e.split(" "),r=this.hooks.uniforms[e];null!=(t=r instanceof Function?r():r)&&this.setUniform(i,t)}}copyToContext(e){let t=new k(e._renderer,this._vertSrc,this._fragSrc);return t.ensureCompiledOnContext(e._renderer),t}ensureCompiledOnContext(e){if(0!==this._glProgram&&this._renderer!==e)throw Error("The shader being run is attached to a different context. Do you need to copy it to this context first with .copyToContext()?");0===this._glProgram&&(this._renderer=e?._renderer?.filterRenderer?._renderer||e,this.init())}_loadAttributes(){if(this._loadedAttributes)return;this.attributes={};let e=this._renderer.GL,t=e.getProgramParameter(this._glProgram,e.ACTIVE_ATTRIBUTES);for(let i=0;i<t;++i){let t=e.getActiveAttrib(this._glProgram,i),r=t.name,s=e.getAttribLocation(this._glProgram,r),n={};n.name=r,n.location=s,n.index=i,n.type=t.type,n.size=t.size,this.attributes[r]=n}this._loadedAttributes=!0}_loadUniforms(){if(this._loadedUniforms)return;let e=this._renderer.GL,t=e.getProgramParameter(this._glProgram,e.ACTIVE_UNIFORMS),i=0;for(let r=0;r<t;++r){let t=e.getActiveUniform(this._glProgram,r),s={};s.location=e.getUniformLocation(this._glProgram,t.name),s.size=t.size;let n=t.name;t.size>1&&(n=n.substring(0,n.indexOf("[0]"))),s.name=n,s.type=t.type,s._cachedData=void 0,s.type===e.SAMPLER_2D&&(s.samplerIndex=i,i++,this.samplers.push(s)),s.isArray=t.size>1||s.type===e.FLOAT_MAT3||s.type===e.FLOAT_MAT4||s.type===e.FLOAT_VEC2||s.type===e.FLOAT_VEC3||s.type===e.FLOAT_VEC4||s.type===e.INT_VEC2||s.type===e.INT_VEC4||s.type===e.INT_VEC3,this.uniforms[n]=s}this._loadedUniforms=!0}compile(){}
5bindShader(){this.init(),this._bound||(this.useProgram(),this._bound=!0)}unbindShader(){return this._bound&&(this.unbindTextures(),this._bound=!1),this}bindTextures(){let e=this._renderer.GL,t=this._renderer._getEmptyTexture();for(let i of this.samplers){let r=i.texture;void 0===r&&(i.texture=r=t),e.activeTexture(e.TEXTURE0+i.samplerIndex),r.bindTexture(),r.update(),e.uniform1i(i.location,i.samplerIndex)}}updateTextures(){for(let e of this.samplers){let t=e.texture;t&&t.update()}}unbindTextures(){let e=this._renderer.GL,t=this._renderer._getEmptyTexture();for(let i of this.samplers)i.texture?.isFramebufferTexture&&(e.activeTexture(e.TEXTURE0+i.samplerIndex),t.bindTexture(),e.uniform1i(i.location,i.samplerIndex))}useProgram(){let e=this._renderer.GL;return this._renderer._curShader!==this&&(e.useProgram(this._glProgram),this._renderer._curShader=this),this}setUniform(e,t){this.init();let i=this.uniforms[e];if(!i)return;let r=this._renderer.GL;if(i.isArray)if(i._cachedData&&this._renderer._arraysEqual(i._cachedData,t))return;else i._cachedData=t.slice(0);else{if(i._cachedData&&i._cachedData===t)return;Array.isArray(t)?i._cachedData=t.slice(0):i._cachedData=t}let s=i.location;switch(this.useProgram(),i.type){case r.BOOL:!0===t?r.uniform1i(s,1):r.uniform1i(s,0);break;case r.INT:i.size>1?t.length&&r.uniform1iv(s,t):r.uniform1i(s,t);break;case r.FLOAT:i.size>1?t.length&&r.uniform1fv(s,t):r.uniform1f(s,t);break;case r.FLOAT_MAT3:r.uniformMatrix3fv(s,!1,t);break;case r.FLOAT_MAT4:r.uniformMatrix4fv(s,!1,t);break;case r.FLOAT_VEC2:i.size>1?t.length&&r.uniform2fv(s,t):r.uniform2f(s,t[0],t[1]);break;case r.FLOAT_VEC3:i.size>1?t.length&&r.uniform3fv(s,t):r.uniform3f(s,t[0],t[1],t[2]);break;case r.FLOAT_VEC4:i.size>1?t.length&&r.uniform4fv(s,t):r.uniform4f(s,t[0],t[1],t[2],t[3]);break;case r.INT_VEC2:i.size>1?t.length&&r.uniform2iv(s,t):r.uniform2i(s,t[0],t[1]);break;case r.INT_VEC3:i.size>1?t.length&&r.uniform3iv(s,t):r.uniform3i(s,t[0],t[1],t[2]);break;case r.INT_VEC4:i.size>1?t.length&&r.uniform4iv(s,t):r.uniform4i(s,t[0],t[1],t[2],t[3]);break;case r.SAMPLER_2D:if("number"==typeof t){if(t<r.TEXTURE0||t>r.TEXTURE31||t!==Math.ceil(t))return console.log("\uD83C\uDF38 p5.js says: You're trying to use a number as the data for a texture.Please use a texture."),this;r.activeTexture(t),r.uniform1i(s,t)}else r.activeTexture(r.TEXTURE0+i.samplerIndex),i.texture=t instanceof ev?t:this._renderer.getTexture(t),r.uniform1i(s,i.samplerIndex),i.texture.src.gifProperties&&i.texture.src._animateGif(this._renderer._pInst);break;case r.SAMPLER_CUBE:case r.SAMPLER_3D:case r.SAMPLER_2D_SHADOW:case r.SAMPLER_2D_ARRAY:case r.SAMPLER_2D_ARRAY_SHADOW:case r.SAMPLER_CUBE_SHADOW:case r.INT_SAMPLER_2D:case r.INT_SAMPLER_3D:case r.INT_SAMPLER_CUBE:case r.INT_SAMPLER_2D_ARRAY:case r.UNSIGNED_INT_SAMPLER_2D:case r.UNSIGNED_INT_SAMPLER_3D:case r.UNSIGNED_INT_SAMPLER_CUBE:case r.UNSIGNED_INT_SAMPLER_2D_ARRAY:if("number"!=typeof t)break;if(t<r.TEXTURE0||t>r.TEXTURE31||t!==Math.ceil(t)){console.log("\uD83C\uDF38 p5.js says: You're trying to use a number as the data for a texture.Please use a texture.");break}r.activeTexture(t),r.uniform1i(s,t)}return this}enableAttrib(e,t,i,r,s,n){if(e){"undefined"==typeof IS_MINIFIED&&this.attributes[e.name]!==e&&console.warn(`The attribute "${e.name}"passed to enableAttrib does not belong to this shader.`);let a=e.location;if(-1!==a){let e=this._renderer.GL;this._renderer.registerEnabled.has(a)||(e.enableVertexAttribArray(a),this._renderer.registerEnabled.add(a)),this._renderer.GL.vertexAttribPointer(a,t,i||e.FLOAT,r||!1,s||0,n||0)}}return this}disableRemainingAttributes(){for(let e of this._renderer.registerEnabled.values())Object.keys(this.attributes).some(t=>this.attributes[t].location===e)||(this._renderer.GL.disableVertexAttribArray(e),this._renderer.registerEnabled.delete(e))}}function B(e,t){e.Shader=k}"undefined"!=typeof p5&&B(p5,p5.prototype);var G="precision highp int;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nIN vec3 aPosition;\nIN vec2 aTexCoord;\nOUT vec2 vTexCoord;\n\nvoid main() {\n // transferring texcoords for the frag shader\n vTexCoord = aTexCoord;\n\n // copy position with a fourth coordinate for projection (1.0 is normal)\n vec4 positionVec4 = vec4(aPosition, 1.0
5);\n\n // project to 3D space\n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n}\n",z='#define PI 3.141592\n\nprecision highp float;\nprecision highp int;\n\nuniform mat4 uViewMatrix;\n\nuniform bool uUseLighting;\n\nuniform int uAmbientLightCount;\nuniform vec3 uAmbientColor[5];\nuniform mat3 uCameraRotation;\nuniform int uDirectionalLightCount;\nuniform vec3 uLightingDirection[5];\nuniform vec3 uDirectionalDiffuseColors[5];\nuniform vec3 uDirectionalSpecularColors[5];\n\nuniform int uPointLightCount;\nuniform vec3 uPointLightLocation[5];\nuniform vec3 uPointLightDiffuseColors[5]; \nuniform vec3 uPointLightSpecularColors[5];\n\nuniform int uSpotLightCount;\nuniform float uSpotLightAngle[5];\nuniform float uSpotLightConc[5];\nuniform vec3 uSpotLightDiffuseColors[5];\nuniform vec3 uSpotLightSpecularColors[5];\nuniform vec3 uSpotLightLocation[5];\nuniform vec3 uSpotLightDirection[5];\n\nuniform bool uSpecular;\nuniform float uShininess;\nuniform float uMetallic;\n\nuniform float uConstantAttenuation;\nuniform float uLinearAttenuation;\nuniform float uQuadraticAttenuation;\n\n// setting from _setImageLightUniforms()\n// boolean to initiate the calculateImageDiffuse and calculateImageSpecular\nuniform bool uUseImageLight;\n// texture for use in calculateImageDiffuse\nuniform sampler2D environmentMapDiffused;\n// texture for use in calculateImageSpecular\nuniform sampler2D environmentMapSpecular;\n\nconst float specularFactor = 2.0;\nconst float diffuseFactor = 0.73;\n\nstruct LightResult {\n float specular;\n float diffuse;\n};\n\nfloat _phongSpecular(\n vec3 lightDirection,\n vec3 viewDirection,\n vec3 surfaceNormal,\n float shininess) {\n\n vec3 R = reflect(lightDirection, surfaceNormal);\n return pow(max(0.0, dot(R, viewDirection)), shininess);\n}\n\nfloat _lambertDiffuse(vec3 lightDirection, vec3 surfaceNormal) {\n return max(0.0, dot(-lightDirection, surfaceNormal));\n}\n\nLightResult _light(vec3 viewDirection, vec3 normal, vec3 lightVector, float shininess, float metallic) {\n\n vec3 lightDir = normalize(lightVector);\n\n //compute our diffuse & specular terms\n LightResult lr;\n float specularIntensity = mix(1.0, 0.4, metallic);\n float diffuseIntensity = mix(1.0, 0.1, metallic);\n if (uSpecular)\n lr.specular = (_phongSpecular(lightDir, viewDirection, normal, shininess)) * specularIntensity;\n lr.diffuse = _lambertDiffuse(lightDir, normal) * diffuseIntensity;\n return lr;\n}\n\n// converts the range of "value" from [min1 to max1] to [min2 to max2]\nfloat map(float value, float min1, float max1, float min2, float max2) {\n return min2 + (value - min1) * (max2 - min2) / (max1 - min1);\n}\n\nvec2 mapTextureToNormal( vec3 v ){\n // x = r sin(phi) cos(theta) \n // y = r cos(phi) \n // z = r sin(phi) sin(theta)\n float phi = acos( v.y );\n // if phi is 0, then there are no x, z components\n float theta = 0.0;\n // else \n theta = acos(v.x / sin(phi));\n float sinTheta = v.z / sin(phi);\n if (sinTheta < 0.0) {\n // Turn it into -theta, but in the 0-2PI range\n theta = 2.0 * PI - theta;\n }\n theta = theta / (2.0 * 3.14159);\n phi = phi / 3.14159 ;\n \n vec2 angles = vec2( fract(theta + 0.25), 1.0 - phi );\n return angles;\n}\n\n\nvec3 calculateImageDiffuse(vec3 vNormal, vec3 vViewPosition, float metallic){\n // make 2 seperate builds \n vec3 worldCameraPosition = vec3(0.0, 0.0, 0.0); // hardcoded world camera position\n vec3 worldNormal = normalize(vNormal * uCameraRotation);\n vec2 newTexCoor = mapTextureToNormal( worldNormal );\n vec4 texture = TEXTURE( environmentMapDiffused, newTexCoor );\n // this is to make the darker sections more dark\n // png and jpg usually flatten the brightness so it is to reverse that\n return mix(smoothstep(vec3(0.0), vec3(1.0), texture.xyz), vec3(0.0), metallic);\n}\n\nvec3 calculateImageSpecular(vec3 vNormal, vec3 vViewPosition, float shininess, float metallic){\n vec3 worldCameraPosition = vec3(0.0, 0.0, 0.0);\n vec3 worldNormal = normalize(vNormal);\n vec3 lightDirection = normalize( vViewPosition - worldCameraPosition );\n vec3 R = reflect(lightDirection, worldNormal) * uCameraRotation;\n vec2 newTexCoor = mapTextureToNormal( R );\n#ifdef WEBGL2\n // In p5js the range of shininess is >= 1,\n // Therefore roughness range will be ([0,1]*8)*20 or [0, 160]\n // The factor of 8 is because currently the getSpecularTexture\n // only calculated 8 different levels of roughness\n // The factor of 20 is just to spread up this range so that,\n // [1, max] of shininess is converted to [0,160] of roughness\n float roughness = 20. / shininess;\n vec4 outColor = textureLod(environmentMapSpecular, newTexCoor, roughness * 8.);\n#else\n vec4 outColor = TEXTURE(environmentMapSpecular, newTexCoor);\n#endif\n // this is to make the darker sections more dark\n // png and jpg usually flatten the brightness so it is to reverse that\n return mix(\n pow(outColor.xyz, vec3(10)),\n pow(outColor.xyz, vec3(1.2)),\n metallic \n );\n}\n\nvoid totalLight(\n vec3 modelPosition,\n vec3 normal,\n float shininess,\n float metallic,\n out vec3 totalDiffuse,\n out vec3 totalSpecular\n) {\n\n totalSpecular = vec3(0.0);\n\n if (!uUseLighting) {\n totalDiffuse = vec3(1.0);\n return;\n }\n\n totalDiffuse = vec3(0.0);\n\n vec3 viewDirection = normalize(-modelPosition);\n\n for (int j = 0; j < 5;
5 j++) {\n if (j < uDirectionalLightCount) {\n vec3 lightVector = (uViewMatrix * vec4(uLightingDirection[j], 0.0)).xyz;\n vec3 lightColor = uDirectionalDiffuseColors[j];\n vec3 specularColor = uDirectionalSpecularColors[j];\n LightResult result = _light(viewDirection, normal, lightVector, shininess, metallic);\n totalDiffuse += result.diffuse * lightColor;\n totalSpecular += result.specular * lightColor * specularColor;\n }\n\n if (j < uPointLightCount) {\n vec3 lightPosition = (uViewMatrix * vec4(uPointLightLocation[j], 1.0)).xyz;\n vec3 lightVector = modelPosition - lightPosition;\n //calculate attenuation\n float lightDistance = length(lightVector);\n float lightFalloff = 1.0 / (uConstantAttenuation + lightDistance * uLinearAttenuation + (lightDistance * lightDistance) * uQuadraticAttenuation);\n vec3 lightColor = lightFalloff * uPointLightDiffuseColors[j];\n vec3 specularColor = lightFalloff * uPointLightSpecularColors[j];\n\n LightResult result = _light(viewDirection, normal, lightVector, shininess, metallic);\n totalDiffuse += result.diffuse * lightColor;\n totalSpecular += result.specular * lightColor * specularColor;\n }\n\n if(j < uSpotLightCount) {\n vec3 lightPosition = (uViewMatrix * vec4(uSpotLightLocation[j], 1.0)).xyz;\n vec3 lightVector = modelPosition - lightPosition;\n \n float lightDistance = length(lightVector);\n float lightFalloff = 1.0 / (uConstantAttenuation + lightDistance * uLinearAttenuation + (lightDistance * lightDistance) * uQuadraticAttenuation);\n\n vec3 lightDirection = (uViewMatrix * vec4(uSpotLightDirection[j], 0.0)).xyz;\n float spotDot = dot(normalize(lightVector), normalize(lightDirection));\n float spotFalloff;\n if(spotDot < uSpotLightAngle[j]) {\n spotFalloff = 0.0;\n }\n else {\n spotFalloff = pow(spotDot, uSpotLightConc[j]);\n }\n lightFalloff *= spotFalloff;\n\n vec3 lightColor = uSpotLightDiffuseColors[j];\n vec3 specularColor = uSpotLightSpecularColors[j];\n \n LightResult result = _light(viewDirection, normal, lightVector, shininess, metallic);\n \n totalDiffuse += result.diffuse * lightColor * lightFalloff;\n totalSpecular += result.specular * lightColor * specularColor * lightFalloff;\n }\n }\n\n if( uUseImageLight ){\n totalDiffuse += calculateImageDiffuse(normal, modelPosition, metallic);\n totalSpecular += calculateImageSpecular(normal, modelPosition, shininess, metallic);\n }\n\n totalDiffuse *= diffuseFactor;\n totalSpecular *= specularFactor;\n}\n',j="#ifdef WEBGL2\n\n#define IN in\n#define OUT out\n\n#ifdef FRAGMENT_SHADER\nout vec4 outColor;\n#define OUT_COLOR outColor\n#endif\n#define TEXTURE texture\n\n#else\n\n#ifdef FRAGMENT_SHADER\n#define IN varying\n#else\n#define IN attribute\n#endif\n#define OUT varying\n#define TEXTURE texture2D\n\n#ifdef FRAGMENT_SHADER\n#define OUT_COLOR gl_FragColor\n#endif\n\n#endif\n\n#ifdef FRAGMENT_SHADER\nvec4 getTexture(in sampler2D content, vec2 coord) {\n vec4 color = TEXTURE(content, coord);\n color.rgb /= color.a;\n return color;\n}\n#endif\n",H="precision highp float;\n\nuniform sampler2D tex0;\nuniform vec2 canvasSize;\nuniform vec2 texelSize;\n\nIN vec2 vTexCoord;\n\nstruct FilterInputs {\n vec2 texCoord;\n vec2 canvasSize;\n vec2 texelSize;\n};\n\nvoid main(void) {\n FilterInputs inputs;\n inputs.texCoord = vTexCoord;\n inputs.canvasSize = canvasSize;\n inputs.texelSize = texelSize;\n OUT_COLOR = HOOK_getColor(inputs, tex0);\n OUT_COLOR.rgb *= outColor.a;\n}\n",W="precision highp float;\n\nvarying vec2 vTexCoord;\n\nuniform sampler2D tex0;\n\nfloat luma(vec3 color) {\n // weighted grayscale with luminance values\n return dot(color, vec3(0.2126, 0.7152, 0.0722));\n}\n\nvoid main() {\n vec4 tex = texture2D(tex0, vTexCoord);\n float gray = luma(tex.rgb);\n gl_FragColor = vec4(gray, gray, gray, tex.a);\n}\n",X="// Reduces the bright areas in an image\n\nprecision highp float;\n\nvarying vec2 vTexCoord;\n\nuniform sampler2D tex0;\nuniform vec2 texelSize;\n\nfloat luma(vec3 color) {\n // weighted grayscale with luminance values\n // weights 77, 151, 28 taken from src/image/filters.js\n return dot(color, vec3(0.300781, 0.589844, 0.109375));\n}\n\nvoid main() {\n vec4 color = texture2D(tex0, vTexCoord);\n float lum = luma(color.rgb);\n\n // set current color as the darkest neighbor color\n\n vec4 neighbors[4];\n neighbors[0] = texture2D(tex0, vTexCoord + vec2( texelSize.x, 0.0
5));\n neighbors[1] = texture2D(tex0, vTexCoord + vec2(-texelSize.x, 0.0));\n neighbors[2] = texture2D(tex0, vTexCoord + vec2(0.0, texelSize.y));\n neighbors[3] = texture2D(tex0, vTexCoord + vec2(0.0, -texelSize.y));\n\n for (int i = 0; i < 4; i++) {\n vec4 neighborColor = neighbors[i];\n float neighborLum = luma(neighborColor.rgb);\n\n if (neighborLum < lum) {\n color = neighborColor;\n lum = neighborLum;\n }\n }\n\n gl_FragColor = color;\n}\n",Y="// Increase the bright areas in an image\n\nprecision highp float;\n\nvarying vec2 vTexCoord;\n\nuniform sampler2D tex0;\nuniform vec2 texelSize;\n\nfloat luma(vec3 color) {\n // weighted grayscale with luminance values\n // weights 77, 151, 28 taken from src/image/filters.js\n return dot(color, vec3(0.300781, 0.589844, 0.109375));\n}\n\nvoid main() {\n vec4 color = texture2D(tex0, vTexCoord);\n float lum = luma(color.rgb);\n\n // set current color as the brightest neighbor color\n\n vec4 neighbors[4];\n neighbors[0] = texture2D(tex0, vTexCoord + vec2( texelSize.x, 0.0));\n neighbors[1] = texture2D(tex0, vTexCoord + vec2(-texelSize.x, 0.0));\n neighbors[2] = texture2D(tex0, vTexCoord + vec2(0.0, texelSize.y));\n neighbors[3] = texture2D(tex0, vTexCoord + vec2(0.0, -texelSize.y));\n\n for (int i = 0; i < 4; i++) {\n vec4 neighborColor = neighbors[i];\n float neighborLum = luma(neighborColor.rgb);\n\n if (neighborLum > lum) {\n color = neighborColor;\n lum = neighborLum;\n }\n }\n\n gl_FragColor = color;\n}\n",q="precision highp float;\n\n// Two-pass blur filter, unweighted kernel.\n// See also a similar blur at Adam Ferriss' repo of shader examples:\n// https://github.com/aferriss/p5jsShaderExamples/blob/gh-pages/4_image-effects/4-9_single-pass-blur/effect.frag\n\n\nuniform sampler2D tex0;\nvarying vec2 vTexCoord;\nuniform vec2 direction;\nuniform vec2 canvasSize;\nuniform float radius;\n\nfloat random(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * .1031);\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n}\n\n// This isn't a real Gaussian weight, it's a quadratic weight. It's what the\n// CPU mode's blur uses though, so we also use it here to match.\nfloat quadWeight(float x, float e) {\n return pow(e-abs(x), 2.);\n}\n\nvoid main(){\n vec2 uv = vTexCoord;\n\n // A reasonable maximum number of samples\n const float maxSamples = 64.0;\n\n float numSamples = floor(7. * radius);\n if (fract(numSamples / 2.) == 0.) {\n numSamples++;\n }\n vec4 avg = vec4(0.0);\n float total = 0.0;\n\n // Calculate the spacing to avoid skewing if numSamples > maxSamples\n float spacing = 1.0;\n if (numSamples > maxSamples) {\n spacing = numSamples / maxSamples;\n numSamples = maxSamples;\n }\n\n float randomOffset = (spacing - 1.0) * mix(-0.5, 0.5, random(gl_FragCoord.xy));\n for (float i = 0.0; i < maxSamples; i++) {\n if (i >= numSamples) break;\n\n float sample = i * spacing - (numSamples - 1.0) * 0.5 * spacing + randomOffset;\n vec2 sampleCoord = uv + vec2(sample, sample) / canvasSize * direction;\n float weight = quadWeight(sample, (numSamples - 1.0) * 0.5 * spacing);\n\n avg += weight * texture2D(tex0, sampleCoord);\n total += weight;\n }\n\n avg /= total;\n gl_FragColor = avg;\n}\n",K="// Limit color space for a stylized cartoon / poster effect\n\nprecision highp float;\n\nvarying vec2 vTexCoord;\n\nuniform sampler2D tex0;\nuniform float filterParameter;\n\nvec3 quantize(vec3 color, float n) {\n // restrict values to N options/bins\n // and floor each channel to nearest value\n //\n // eg. when N = 5, values = 0.0, 0.25, 0.50, 0.75, 1.0\n // then quantize (0.1, 0.7, 0.9) -> (0.0, 0.5, 1.0)\n\n color = color * n;\n color = floor(color);\n color = color / (n - 1.0);\n return color;\n}\n\nvoid main() {\n vec4 color = texture2D(tex0, vTexCoord);\n\n vec3 restrictedColor = quantize(color.rgb / color.a, filterParameter);\n\n gl_FragColor = vec4(restrictedColor.rgb * color.a, color.a);\n}\n",$="// Set alpha channel to entirely opaque\n\nprecision highp float;\n\nvarying vec2 vTexCoord;\n\nuniform sampler2D tex0;\n\nvoid main() {\n vec4 color = texture2D(tex0, vTexCoord);\n gl_FragColor = vec4(color.rgb / color.a, 1.0);\n}\n",Z="// Set each pixel to inverse value\n// Note that original INVERT does not change the opacity, so this follows suit\n\nprecision highp float;\n\nvarying vec2 vTexCoord;\n\nuniform sampler2D tex0;\n\nvoid main() {\nvec4 color = texture2D(tex0, vTexCoord);
5\nvec3 origColor = color.rgb / color.a;\nvec3 invertedColor = vec3(1.0) - origColor;\ngl_FragColor = vec4(invertedColor * color.a, color.a);\n}\n",J="// Convert pixels to either white or black, \n// depending on if their luma is above or below filterParameter\n\nprecision highp float;\n\nvarying vec2 vTexCoord;\n\nuniform sampler2D tex0;\nuniform float filterParameter;\n\nfloat luma(vec3 color) {\n // weighted grayscale with luminance values\n return dot(color, vec3(0.2126, 0.7152, 0.0722));\n}\n\nvoid main() {\n vec4 color = texture2D(tex0, vTexCoord);\n float gray = luma(color.rgb / color.a);\n // floor() used to match src/image/filters.js\n float threshold = floor(filterParameter * 255.0) / 255.0;\n float blackOrWhite = step(threshold, gray);\n gl_FragColor = vec4(vec3(blackOrWhite) * color.a, color.a);\n}\n",Q="uniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nattribute vec3 aPosition;\n// texcoords only come from p5 to vertex shader\n// so pass texcoords on to the fragment shader in a varying variable\nattribute vec2 aTexCoord;\nvarying vec2 vTexCoord;\n\nvoid main() {\n // transferring texcoords for the frag shader\n vTexCoord = aTexCoord;\n\n // copy position with a fourth coordinate for projection (1.0 is normal)\n vec4 positionVec4 = vec4(aPosition, 1.0
5);\n\n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n}\n";let ee={},et={},ei="",er=function(e,t){ei+=`#define STROKE_CAP_${e} ${t} 6`,ee[s.v[e]]=t},es=function(e,t){ei+=`#define STROKE_JOIN_${e} ${t} 7`,et[s.v[e]]=t};er("ROUND",0),er("PROJECT",1),er("SQUARE",2),es("ROUND",0),es("MITER",1),es("BEVEL",2);let en={normalVert:"IN vec3 aPosition;\nIN vec3 aNormal;\nIN vec2 aTexCoord;\nIN vec4 aVertexColor;\n\n#define HOOK_DEFINES\n\n#ifdef AUGMENTED_HOOK_getWorldInputs\nuniform mat4 uModelMatrix;\nuniform mat4 uViewMatrix;\nuniform mat3 uModelNormalMatrix;\nuniform mat3 uCameraNormalMatrix;\n#else\nuniform mat4 uModelViewMatrix;\nuniform mat3 uNormalMatrix;\n#endif\nuniform mat4 uProjectionMatrix;\n\nuniform vec4 uMaterialColor;\nuniform bool uUseVertexColor;\n\nOUT vec3 vVertexNormal;\nOUT highp vec2 vVertTexCoord;\nOUT vec4 vColor;\n\nstruct Vertex {\n vec3 position;\n vec3 normal;\n vec2 texCoord;\n vec4 color;\n};\n\nvoid main(void) {\n HOOK_beforeVertex();\n\n Vertex inputs;\n inputs.position = aPosition;\n inputs.normal = aNormal;\n inputs.texCoord = aTexCoord;\n inputs.color = (uUseVertexColor && aVertexColor.x >= 0.0) ? aVertexColor : uMaterialColor;\n#ifdef AUGMENTED_HOOK_getObjectInputs\n inputs = HOOK_getObjectInputs(inputs);\n#endif\n\n#ifdef AUGMENTED_HOOK_getWorldInputs\n inputs.position = (uModelMatrix * vec4(inputs.position, 1.)).xyz;\n inputs.normal = uModelNormalMatrix * inputs.normal;\n inputs = HOOK_getWorldInputs(inputs);\n#endif\n\n#ifdef AUGMENTED_HOOK_getWorldInputs\n // Already multiplied by the model matrix, just apply view\n inputs.position = (uViewMatrix * vec4(inputs.position, 1.)).xyz;\n inputs.normal = uCameraNormalMatrix * inputs.normal;\n#else\n // Apply both at once\n inputs.position = (uModelViewMatrix * vec4(inputs.position, 1.)).xyz;\n inputs.normal = uNormalMatrix * inputs.normal;\n#endif\n#ifdef AUGMENTED_HOOK_getCameraInputs\n inputs = HOOK_getCameraInputs(inputs);\n#endif\n\n // Pass varyings to fragment shader\n vVertTexCoord = inputs.texCoord;\n vVertexNormal = normalize(inputs.normal);\n vColor = inputs.color;\n\n gl_Position = uProjectionMatrix * vec4(inputs.position, 1.);\n\n HOOK_afterVertex();\n}\n",normalFrag:"IN vec3 vVertexNormal;\nvoid main(void) {\n HOOK_beforeFragment();\n OUT_COLOR = HOOK_getFinalColor(vec4(vVertexNormal, 1.0));\n HOOK_afterFragment();\n}\n",basicFrag:"IN vec4 vColor;\nvoid main(void) {\n HOOK_beforeFragment();\n OUT_COLOR = HOOK_getFinalColor(vec4(vColor.rgb, 1.) * vColor.a);\n HOOK_afterFragment();\n}\n",sphereMappingFrag:"#define PI 3.141592\n\nprecision highp float;\n \nuniform sampler2D uEnvMap;\nuniform mat3 uNewNormalMatrix;\nuniform float uFovY;\nuniform float uAspect;\n\nvarying vec2 vTexCoord;\n \nvoid main() {\n float uFovX = uFovY * uAspect; \n float angleY = mix(uFovY/2.0, -uFovY/2.0, vTexCoord.y);\n float angleX = mix(uFovX/2.0, -uFovX/2.0, vTexCoord.x);\n vec3 rotatedNormal = vec3( angleX, angleY, 1.0 );\n rotatedNormal = uNewNormalMatrix * normalize(rotatedNormal);\n float temp = rotatedNormal.z;\n rotatedNormal.z = rotatedNormal.x;\n rotatedNormal.x = -temp;\n vec2 suv;\n suv.y = 0.5 + 0.5 * (-rotatedNormal.y);\n suv.x = atan(rotatedNormal.z, rotatedNormal.x) / (2.0 * PI) + 0.5;\n vec4 newTexColor = texture2D(uEnvMap, suv.xy);\n gl_FragColor = newTexColor;\n}\n",lightVert:z+"// include lighting.glgl\n\nIN vec3 aPosition;\nIN vec3 aNormal;\nIN vec2 aTexCoord;\nIN vec4 aVertexColor;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform mat3 uNormalMatrix;\n\nuniform bool uUseVertexColor;\nuniform vec4 uMaterialColor;\n\nOUT highp vec2 vVertTexCoord;\nOUT vec3 vDiffuseColor;\nOUT vec3 vSpecularColor;\nOUT vec4 vColor;\n\nvoid main(void) {\n\n vec4 viewModelPosition = uModelViewMatrix * vec4(aPosition, 1.0
7);\n gl_Position = uProjectionMatrix * viewModelPosition;\n\n vec3 vertexNormal = normalize(uNormalMatrix * aNormal);\n vVertTexCoord = aTexCoord;\n\n totalLight(viewModelPosition.xyz, vertexNormal, vDiffuseColor, vSpecularColor);\n\n for (int i = 0; i < 8; i++) {\n if (i < uAmbientLightCount) {\n vDiffuseColor += uAmbientColor[i];\n }\n }\n \n vColor = ((uUseVertexColor && aVertexColor.x >= 0.0) ? aVertexColor : uMaterialColor);\n}\n",lightTextureFrag:"uniform vec4 uTint;\nuniform sampler2D uSampler;\nuniform bool isTexture;\nuniform bool uEmissive;\n\nIN highp vec2 vVertTexCoord;\nIN vec3 vDiffuseColor;\nIN vec3 vSpecularColor;\nIN vec4 vColor;\n\nvoid main(void) {\n if(uEmissive && !isTexture) {\n OUT_COLOR = vColor;\n }\n else {\n vec4 baseColor = isTexture\n // Textures come in with premultiplied alpha. To apply tint and still have\n // premultiplied alpha output, we need to multiply the RGB channels by the\n // tint RGB, and all channels by the tint alpha.\n ? TEXTURE(uSampler, vVertTexCoord) * vec4(uTint.rgb/255., 1.) * (uTint.a/255.)\n // Colors come in with unmultiplied alpha, so we need to multiply the RGB\n // channels by alpha to convert it to premultiplied alpha.\n : vec4(vColor.rgb * vColor.a, vColor.a);\n OUT_COLOR = vec4(baseColor.rgb * vDiffuseColor + vSpecularColor, baseColor.a);\n }\n}\n",phongVert:"precision highp int;\n\n#define HOOK_DEFINES\n\nIN vec3 aPosition;\nIN vec3 aNormal;\nIN vec2 aTexCoord;\nIN vec4 aVertexColor;\n\nuniform vec3 uAmbientColor[5];\n\n#ifdef AUGMENTED_HOOK_getWorldInputs\nuniform mat4 uModelMatrix;\nuniform mat4 uViewMatrix;\nuniform mat3 uModelNormalMatrix;\nuniform mat3 uCameraNormalMatrix;\n#else\nuniform mat4 uModelViewMatrix;\nuniform mat3 uNormalMatrix;\n#endif\nuniform mat4 uProjectionMatrix;\nuniform int uAmbientLightCount;\n\nuniform bool uUseVertexColor;\nuniform vec4 uMaterialColor;\n\nOUT vec3 vNormal;\nOUT vec2 vTexCoord;\nOUT vec3 vViewPosition;\nOUT vec3 vAmbientColor;\nOUT vec4 vColor;\n\nstruct Vertex {\n vec3 position;\n vec3 normal;\n vec2 texCoord;\n vec4 color;\n};\n\nvoid main(void) {\n HOOK_beforeVertex();\n\n Vertex inputs;\n inputs.position = aPosition;\n inputs.normal = aNormal;\n inputs.texCoord = aTexCoord;\n inputs.color = (uUseVertexColor && aVertexColor.x >= 0.0) ? aVertexColor : uMaterialColor;\n#ifdef AUGMENTED_HOOK_getObjectInputs\n inputs = HOOK_getObjectInputs(inputs);\n#endif\n\n#ifdef AUGMENTED_HOOK_getWorldInputs\n inputs.position = (uModelMatrix * vec4(inputs.position, 1.)).xyz;\n inputs.normal = uModelNormalMatrix * inputs.normal;\n inputs = HOOK_getWorldInputs(inputs);\n#endif\n\n#ifdef AUGMENTED_HOOK_getWorldInputs\n // Already multiplied by the model matrix, just apply view\n inputs.position = (uViewMatrix * vec4(inputs.position, 1.)).xyz;\n inputs.normal = uCameraNormalMatrix * inputs.normal;\n#else\n // Apply both at once\n inputs.position = (uModelViewMatrix * vec4(inputs.position, 1.)).xyz;\n inputs.normal = uNormalMatrix * inputs.normal;\n#endif\n#ifdef AUGMENTED_HOOK_getCameraInputs\n inputs = HOOK_getCameraInputs(inputs);\n#endif\n\n // Pass varyings to fragment shader\n vViewPosition = inputs.position;\n vTexCoord = inputs.texCoord;\n vNormal = inputs.normal;\n vColor = inputs.color;\n\n // TODO: this should be a uniform\n vAmbientColor = vec3(0.0);\n for (int i = 0; i < 5; i++) {\n if (i < uAmbientLightCount) {\n vAmbientColor += uAmbientColor[i];\n }\n }\n\n gl_Position = uProjectionMatrix * vec4(inputs.position, 1.);\n HOOK_afterVertex();\n}\n",phongFrag:z+"// include lighting.glsl\nprecision highp int;\n\nuniform bool uHasSetAmbient;\nuniform vec4 uSpecularMatColor;\nuniform vec4 uAmbientMatColor;\nuniform vec4 uEmissiveMatColor;\n\nuniform vec4 uTint;\nuniform sampler2D uSampler;\nuniform bool isTexture;\n\nIN vec3 vNormal;\nIN vec2 vTexCoord;\nIN vec3 vViewPosition;\nIN vec3 vAmbientColor;\nIN vec4 vColor;\n\nstruct ColorComponents {\n vec3 baseColor;\n float opacity;\n vec3 ambientColor;\n vec3 specularColor;\n vec3 diffuse;\n vec3 ambient;\n vec3 specular;\n vec3 emissive;\n};\n\nstruct Inputs {\n vec3 normal;\n vec2 texCoord;\n vec3 ambientLight;\n vec3 ambientMaterial;\n vec3 specularMaterial;\n vec3 emissiveMaterial;\n vec4 color;\n float shininess;\n float metalness;\n};\n\nvoid main(void) {\n HOOK_beforeFragment();
7\n\n Inputs inputs;\n inputs.normal = normalize(vNormal);\n inputs.texCoord = vTexCoord;\n inputs.ambientLight = vAmbientColor;\n inputs.color = isTexture\n ? TEXTURE(uSampler, vTexCoord) * (vec4(uTint.rgb/255., 1.) * uTint.a/255.)\n : vColor;\n if (isTexture && inputs.color.a > 0.0) {\n // Textures come in with premultiplied alpha. Temporarily unpremultiply it\n // so hooks users don't have to think about premultiplied alpha.\n inputs.color.rgb /= inputs.color.a;\n }\n inputs.shininess = uShininess;\n inputs.metalness = uMetallic;\n inputs.ambientMaterial = uHasSetAmbient ? uAmbientMatColor.rgb : inputs.color.rgb;\n inputs.specularMaterial = uSpecularMatColor.rgb;\n inputs.emissiveMaterial = uEmissiveMatColor.rgb;\n inputs = HOOK_getPixelInputs(inputs);\n\n vec3 diffuse;\n vec3 specular;\n totalLight(vViewPosition, inputs.normal, inputs.shininess, inputs.metalness, diffuse, specular);\n\n // Calculating final color as result of all lights (plus emissive term).\n\n vec2 texCoord = inputs.texCoord;\n vec4 baseColor = inputs.color;\n ColorComponents c;\n c.opacity = baseColor.a;\n c.baseColor = baseColor.rgb;\n c.ambientColor = inputs.ambientMaterial;\n c.specularColor = inputs.specularMaterial;\n c.diffuse = diffuse;\n c.ambient = inputs.ambientLight;\n c.specular = specular;\n c.emissive = inputs.emissiveMaterial;\n OUT_COLOR = HOOK_getFinalColor(HOOK_combineColors(c));\n OUT_COLOR.rgb *= OUT_COLOR.a; // Premultiply alpha before rendering\n HOOK_afterFragment();\n}\n",fontVert:"IN vec3 aPosition;\nIN vec2 aTexCoord;\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nuniform vec4 uGlyphRect;\nuniform float uGlyphOffset;\n\nOUT vec2 vTexCoord;\nOUT float w;
7\n\nvoid main() {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n\n // scale by the size of the glyph's rectangle\n positionVec4.xy *= uGlyphRect.zw - uGlyphRect.xy;\n\n // Expand glyph bounding boxes by 1px on each side to give a bit of room\n // for antialiasing\n vec3 newOrigin = (uModelViewMatrix * vec4(0., 0., 0., 1.)).xyz;\n vec3 newDX = (uModelViewMatrix * vec4(1., 0., 0., 1.)).xyz;\n vec3 newDY = (uModelViewMatrix * vec4(0., 1., 0., 1.)).xyz;\n vec2 pixelScale = vec2(\n 1. / length(newOrigin - newDX),\n 1. / length(newOrigin - newDY)\n );\n vec2 offset = pixelScale * normalize(aTexCoord - vec2(0.5, 0.5));\n vec2 textureOffset = offset * (1. / vec2(\n uGlyphRect.z - uGlyphRect.x,\n uGlyphRect.w - uGlyphRect.y\n ));\n\n // move to the corner of the glyph\n positionVec4.xy += uGlyphRect.xy;\n\n // move to the letter's line offset\n positionVec4.x += uGlyphOffset;\n\n positionVec4.xy += offset;\n \n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vTexCoord = aTexCoord + textureOffset;\n w = gl_Position.w;\n}\n",fontFrag:"#ifndef WEBGL2\n#extension GL_OES_standard_derivatives : enable\n#endif\n\n#if 0\n // simulate integer math using floats\n #define int float\n #define ivec2 vec2\n #define INT(x) float(x)\n\n int ifloor(float v) { return floor(v); }\n ivec2 ifloor(vec2 v) { return floor(v); }\n\n#else\n // use native integer math\n precision highp int;\n #define INT(x) x\n\n int ifloor(float v) { return int(v); }\n int ifloor(int v) { return v; }\n ivec2 ifloor(vec2 v) { return ivec2(v); }\n\n#endif\n\nuniform sampler2D uSamplerStrokes;\nuniform sampler2D uSamplerRowStrokes;\nuniform sampler2D uSamplerRows;\nuniform sampler2D uSamplerColStrokes;\nuniform sampler2D uSamplerCols;\n\nuniform ivec2 uStrokeImageSize;\nuniform ivec2 uCellsImageSize;\nuniform ivec2 uGridImageSize;\n\nuniform ivec2 uGridOffset;\nuniform ivec2 uGridSize;\nuniform vec4 uMaterialColor;\n\nIN vec2 vTexCoord;\n\n// some helper functions\nint ROUND(float v) { return ifloor(v + 0.5); }\nivec2 ROUND(vec2 v) { return ifloor(v + 0.5); }\nfloat saturate(float v) { return clamp(v, 0.0, 1.0); }\nvec2 saturate(vec2 v) { return clamp(v, 0.0, 1.0); }\n\nint mul(float v1, int v2) {\n return ifloor(v1 * float(v2));\n}\n\nivec2 mul(vec2 v1, ivec2 v2) {\n return ifloor(v1 * vec2(v2) + 0.5);\n}\n\n// unpack a 16-bit integer from a float vec2\nint getInt16(vec2 v) {\n ivec2 iv = ROUND(v * 255.0);\n return iv.x * INT(128) + iv.y;\n}\n\nvec2 pixelScale;\nvec2 coverage = vec2(0.0);\nvec2 weight = vec2(0.5);\nconst float minDistance = 1.0/8192.0;\nconst float hardness = 1.05; // amount of antialias\n\n// the maximum number of curves in a glyph\nconst int N = INT(250);\n\n// retrieves an indexed pixel from a sampler\nvec4 getTexel(sampler2D sampler, int pos, ivec2 size) {\n int width = size.x;\n int y = ifloor(pos / width);\n int x = pos - y * width; // pos % width\n\n return TEXTURE(sampler, (vec2(x, y) + 0.5) / vec2(size));\n}\n\nvoid calulateCrossings(vec2 p0, vec2 p1, vec2 p2, out vec2 C1, out vec2 C2) {\n\n // get the coefficients of the quadratic in t\n vec2 a = p0 - p1 * 2.0 + p2;\n vec2 b = p0 - p1;\n vec2 c = p0 - vTexCoord;\n\n // found out which values of 't' it crosses the axes\n vec2 surd = sqrt(max(vec2(0.0), b * b - a * c));\n vec2 t1 = ((b - surd) / a).yx;\n vec2 t2 = ((b + surd) / a).yx;\n\n // approximate straight lines to avoid rounding errors\n if (abs(a.y) < 0.001)\n t1.x = t2.x = c.y / (2.0 * b.y);\n\n if (abs(a.x) < 0.001)\n t1.y = t2.y = c.x / (2.0 * b.x);\n\n // plug into quadratic formula to find the corrdinates of the crossings\n C1 = ((a * t1 - b * 2.0) * t1 + c) * pixelScale;\n C2 = ((a * t2 - b * 2.0) * t2 + c) * pixelScale;\n}\n\nvoid coverageX(vec2 p0, vec2 p1, vec2 p2) {\n\n vec2 C1, C2;\n calulateCrossings(p0, p1, p2, C1, C2);\n\n // determine on which side of the x-axis the points lie\n bool y0 = p0.y > vTexCoord.y;\n bool y1 = p1.y > vTexCoord.y;\n bool y2 = p2.y > vTexCoord.y;\n\n // could web be under the curve (after t1)?\n if (y1 ? !y2 : y0) {\n // add the coverage for t1\n coverage.x += saturate(C1.x + 0.5);
7\n // calculate the anti-aliasing for t1\n weight.x = min(weight.x, abs(C1.x));\n }\n\n // are we outside the curve (after t2)?\n if (y1 ? !y0 : y2) {\n // subtract the coverage for t2\n coverage.x -= saturate(C2.x + 0.5);\n // calculate the anti-aliasing for t2\n weight.x = min(weight.x, abs(C2.x));\n }\n}\n\n// this is essentially the same as coverageX, but with the axes swapped\nvoid coverageY(vec2 p0, vec2 p1, vec2 p2) {\n\n vec2 C1, C2;\n calulateCrossings(p0, p1, p2, C1, C2);\n\n bool x0 = p0.x > vTexCoord.x;\n bool x1 = p1.x > vTexCoord.x;\n bool x2 = p2.x > vTexCoord.x;\n\n if (x1 ? !x2 : x0) {\n coverage.y -= saturate(C1.y + 0.5);\n weight.y = min(weight.y, abs(C1.y));\n }\n\n if (x1 ? !x0 : x2) {\n coverage.y += saturate(C2.y + 0.5);\n weight.y = min(weight.y, abs(C2.y));\n }\n}\n\nvoid main() {\n\n // calculate the pixel scale based on screen-coordinates\n pixelScale = hardness / fwidth(vTexCoord);\n\n // which grid cell is this pixel in?\n ivec2 gridCoord = ifloor(vTexCoord * vec2(uGridSize));\n\n // intersect curves in this row\n {\n // the index into the row info bitmap\n int rowIndex = gridCoord.y + uGridOffset.y;\n // fetch the info texel\n vec4 rowInfo = getTexel(uSamplerRows, rowIndex, uGridImageSize);\n // unpack the rowInfo\n int rowStrokeIndex = getInt16(rowInfo.xy);\n int rowStrokeCount = getInt16(rowInfo.zw);\n\n for (int iRowStroke = INT(0); iRowStroke < N; iRowStroke++) {\n if (iRowStroke >= rowStrokeCount)\n break;\n\n // each stroke is made up of 3 points: the start and control point\n // and the start of the next curve.\n // fetch the indices of this pair of strokes:\n vec4 strokeIndices = getTexel(uSamplerRowStrokes, rowStrokeIndex++, uCellsImageSize);\n\n // unpack the stroke index\n int strokePos = getInt16(strokeIndices.xy);\n\n // fetch the two strokes\n vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);\n vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);\n\n // calculate the coverage\n coverageX(stroke0.xy, stroke0.zw, stroke1.xy);\n }\n }\n\n // intersect curves in this column\n {\n int colIndex = gridCoord.x + uGridOffset.x;\n vec4 colInfo = getTexel(uSamplerCols, colIndex, uGridImageSize);\n int colStrokeIndex = getInt16(colInfo.xy);\n int colStrokeCount = getInt16(colInfo.zw);\n \n for (int iColStroke = INT(0); iColStroke < N; iColStroke++) {\n if (iColStroke >= colStrokeCount)\n break;\n\n vec4 strokeIndices = getTexel(uSamplerColStrokes, colStrokeIndex++, uCellsImageSize);\n\n int strokePos = getInt16(strokeIndices.xy);\n vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);\n vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);\n coverageY(stroke0.xy, stroke0.zw, stroke1.xy);\n }\n }\n\n weight = saturate(1.0 - weight * 2.0);\n float distance = max(weight.x + weight.y, minDistance); // manhattan approx.\n float antialias = abs(dot(coverage, weight) / distance);\n float cover = min(abs(coverage.x), abs(coverage.y));\n OUT_COLOR = vec4(uMaterialColor.rgb, 1.) * uMaterialColor.a;\n OUT_COLOR *= saturate(max(antialias, cover));\n}\n",lineVert:ei+"/*\n Part of the Processing project - http://processing.org\n Copyright (c) 2012-15 The Processing Foundation\n Copyright (c) 2004-12 Ben Fry and Casey Reas\n Copyright (c) 2001-04 Massachusetts Institute of Technology\n This library is free software; you can redistribute it and/or\n modify it under the terms of the GNU Lesser General Public\n License as published by the Free Software Foundation, version 2.1.\n This library is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n Lesser General Public License for more details.\n You should have received a copy of the GNU Lesser General\n Public License along with this library;
7 if not, write to the\n Free Software Foundation, Inc., 59 Temple Place, Suite 330,\n Boston, MA 02111-1307 USA\n*/\n\n#define PROCESSING_LINE_SHADER\n\n#define HOOK_DEFINES\n\nprecision highp int;\nprecision highp float;\n\n#ifdef AUGMENTED_HOOK_getWorldInputs\nuniform mat4 uModelMatrix;\nuniform mat4 uViewMatrix;\n#else\nuniform mat4 uModelViewMatrix;\n#endif\n\nuniform mat4 uProjectionMatrix;\nuniform float uStrokeWeight;\n\nuniform bool uUseLineColor;\nuniform bool uSimpleLines;\nuniform vec4 uMaterialColor;\n\nuniform vec4 uViewport;\nuniform int uPerspective;\nuniform int uStrokeJoin;\n\nIN vec3 aPosition;\nIN vec3 aTangentIn;\nIN vec3 aTangentOut;\nIN float aSide;\nIN vec4 aVertexColor;\n\nOUT vec4 vColor;\nOUT vec2 vTangent;\nOUT vec2 vCenter;\nOUT vec2 vPosition;\nOUT float vMaxDist;\nOUT float vCap;\nOUT float vJoin;\nOUT float vStrokeWeight;\n\nvec2 lineIntersection(vec2 aPoint, vec2 aDir, vec2 bPoint, vec2 bDir) {\n // Rotate and translate so a starts at the origin and goes out to the right\n bPoint -= aPoint;\n vec2 rotatedBFrom = vec2(\n bPoint.x*aDir.x + bPoint.y*aDir.y,\n bPoint.y*aDir.x - bPoint.x*aDir.y\n );\n vec2 bTo = bPoint + bDir;\n vec2 rotatedBTo = vec2(\n bTo.x*aDir.x + bTo.y*aDir.y,\n bTo.y*aDir.x - bTo.x*aDir.y\n );\n float intersectionDistance =\n rotatedBTo.x + (rotatedBFrom.x - rotatedBTo.x) * rotatedBTo.y /\n (rotatedBTo.y - rotatedBFrom.y);\n return aPoint + aDir * intersectionDistance;\n}\n\nstruct StrokeVertex {\n vec3 position;\n vec3 tangentIn;\n vec3 tangentOut;\n vec4 color;\n float weight;\n};\n\nvoid main() {\n HOOK_beforeVertex();\n\n if (!uSimpleLines) {\n // Caps have one of either the in or out tangent set to 0\n vCap = (aTangentIn == vec3(0.)) != (aTangentOut == vec3(0.)) ? 1. : 0.;\n\n // Joins have two unique, defined tangents\n vJoin = (\n aTangentIn != vec3(0.) &&\n aTangentOut != vec3(0.) &&\n aTangentIn != aTangentOut\n ) ? 1. : 0.;\n }\n\n StrokeVertex inputs;\n inputs.position = aPosition.xyz;\n inputs.color = uUseLineColor ? aVertexColor : uMaterialColor;\n inputs.weight = uStrokeWeight;\n inputs.tangentIn = aTangentIn;\n inputs.tangentOut = aTangentOut;\n\n#ifdef AUGMENTED_HOOK_getObjectInputs\n inputs = HOOK_getObjectInputs(inputs);\n#endif\n\n#ifdef AUGMENTED_HOOK_getWorldInputs\n inputs.position = (uModelMatrix * vec4(inputs.position, 1.)).xyz;\n inputs.tangentIn = (uModelMatrix * vec4(aTangentIn, 0.)).xyz;\n inputs.tangentOut = (uModelMatrix * vec4(aTangentOut, 0.)).xyz;\n inputs = HOOK_getWorldInputs(inputs);\n#endif\n\n#ifdef AUGMENTED_HOOK_getWorldInputs\n // Already multiplied by the model matrix, just apply view\n inputs.position = (uViewMatrix * vec4(inputs.position, 1.)).xyz;\n inputs.tangentIn = (uViewMatrix * vec4(aTangentIn, 0.)).xyz;\n inputs.tangentOut = (uViewMatrix * vec4(aTangentOut, 0.)).xyz;\n#else\n // Apply both at once\n inputs.position = (uModelViewMatrix * vec4(inputs.position, 1.)).xyz;\n inputs.tangentIn = (uModelViewMatrix * vec4(aTangentIn, 0.)).xyz;\n inputs.tangentOut = (uModelViewMatrix * vec4(aTangentOut, 0.)).xyz;\n#endif\n#ifdef AUGMENTED_HOOK_getCameraInputs\n inputs = hook_getCameraInputs(inputs);\n#endif\n\n vec4 posp = vec4(inputs.position, 1.);\n vec4 posqIn = vec4(inputs.position + inputs.tangentIn, 1.);\n vec4 posqOut = vec4(inputs.position + inputs.tangentOut, 1.);\n vStrokeWeight = inputs.weight;\n\n float facingCamera = pow(\n // The word space tangent's z value is 0 if it's facing the camera\n abs(normalize(posqIn-posp).z),\n\n // Using pow() here to ramp `facingCamera` up from 0 to 1 really quickly\n // so most lines get scaled and don't get clipped\n 0.25\n );\n\n // Moving vertices slightly toward the camera\n // to avoid depth-fighting with the fill triangles.\n // A mix of scaling and offsetting is used based on distance\n // Discussion here:\n // https://github.com/processing/p5.js/issues/7200 \n\n // using a scale <1 moves the lines towards nearby camera\n // in order to prevent popping effects due to half of\n // the line disappearing behind the geometry faces.\n float zDistance = -posp.z; \n float distanceFactor = smoothstep(0.0, 800.0, zDistance); \n \n // Discussed here:\n // http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=252848 \n float scale = mix(1., 0.995, facingCamera);\n float dynamicScale = mix(scale, 1.0, distanceFactor); // Closer = more scale, farther = less\n\n posp.xyz = posp.xyz * dynamicScale;\n posqIn.xyz = posqIn.xyz * dynamicScale;\n posqOut.xyz = posqOut.xyz * dynamicScale;\n\n // Moving vertices slightly toward camera when far away \n // https://github.com/processing/p5.js/issues/6956 \n float zOffset = mix(0., -1., facingCamera);\n float dynamicZAdjustment = mix(0.0, zOffset, distanceFactor); // Closer = less zAdjustment, farther = more\n\n posp.z -= dynamicZAdjustment;\n posqIn.z -= dynamicZAdjustment;\n posqOut.z -= dynamicZAdjustment;\n \n vec4 p = uProjectionMatrix * posp;\n vec4 qIn = uProjectionMatrix * posqIn;\n vec4 qOut = uProjectionMatrix * posqOut;\n\n // formula to convert from clip space (range -1..1) to screen space (range 0..[width or height])\n // screen_p = (p.xy/p.w + <1,1>) * 0.5 * uViewport.zw\n\n // prevent division by W by transforming the tangent formula (div by 0 causes\n // the line to disappear, see https://github.com/processing/processing/issues/5183)\n // t = screen_q - screen_p\n //\n // tangent is normalized and we don't care which aDirection it points to (+-)\n // t = +- normalize( screen_q - screen_p )\n // t = +- normalize( (q.xy/q.w+<1,1>)*0.5*uViewport.zw - (p.xy/p.w+<1,1>)*0.5*uViewport.zw )\n //\n // extract common factor, <1,1> - <1,1> cancels out\n // t = +- normalize( (q.xy/q.w - p.xy/p.w) * 0.5 * uViewport.zw )\n //\n // convert to common divisor\n // t = +- normalize( ((q.xy*p.w - p.xy*q.w) / (p.w*q.w)) * 0.5 * uViewport.zw )\n //\n // remove the common scalar divisor/factor, not needed due to normalize and +-\n // (keep uViewport - can't remove because it has different c
7omponents for x and y\n // and corrects for aspect ratio, see https://github.com/processing/processing/issues/5181)\n // t = +- normalize( (q.xy*p.w - p.xy*q.w) * uViewport.zw )\n\n vec2 tangentIn = normalize((qIn.xy*p.w - p.xy*qIn.w) * uViewport.zw);\n vec2 tangentOut = normalize((qOut.xy*p.w - p.xy*qOut.w) * uViewport.zw);\n\n vec2 curPerspScale;\n if(uPerspective == 1) {\n // Perspective ---\n // convert from world to clip by multiplying with projection scaling factor\n // to get the right thickness (see https://github.com/processing/processing/issues/5182)\n\n // The y value of the projection matrix may be flipped if rendering to a Framebuffer.\n // Multiplying again by its sign here negates the flip to get just the scale.\n curPerspScale = (uProjectionMatrix * vec4(1, sign(uProjectionMatrix[1][1]), 0, 0)).xy;\n } else {\n // No Perspective ---\n // multiply by W (to cancel out division by W later in the pipeline) and\n // convert from screen to clip (derived from clip to screen above)\n curPerspScale = p.w / (0.5 * uViewport.zw);\n }\n\n vec2 offset;\n if (vJoin == 1. && !uSimpleLines) {\n vTangent = normalize(tangentIn + tangentOut);\n vec2 normalIn = vec2(-tangentIn.y, tangentIn.x);\n vec2 normalOut = vec2(-tangentOut.y, tangentOut.x);\n float side = sign(aSide);\n float sideEnum = abs(aSide);\n\n // We generate vertices for joins on either side of the centerline, but\n // the \"elbow\" side is the only one needing a join. By not setting the\n // offset for the other side, all its vertices will end up in the same\n // spot and not render, effectively discarding it.\n if (sign(dot(tangentOut, vec2(-tangentIn.y, tangentIn.x))) != side) {\n // Side enums:\n // 1: the side going into the join\n // 2: the middle of the join\n // 3: the side going out of the join\n if (sideEnum == 2.) {\n // Calculate the position + tangent on either side of the join, and\n // find where the lines intersect to find the elbow of the join\n vec2 c = (posp.xy/posp.w + vec2(1.,1.)) * 0.5 * uViewport.zw;\n vec2 intersection = lineIntersection(\n c + (side * normalIn * inputs.weight / 2.),\n tangentIn,\n c + (side * normalOut * inputs.weight / 2.),\n tangentOut\n );\n offset = (intersection - c);\n\n // When lines are thick and the angle of the join approaches 180, the\n // elbow might be really far from the center. We'll apply a limit to\n // the magnitude to avoid lines going across the whole screen when this\n // happens.\n float mag = length(offset);\n float maxMag = 3. * inputs.weight;\n if (mag > maxMag) {\n offset *= maxMag / mag;\n }\n } else if (sideEnum == 1.) {\n offset = side * normalIn * inputs.weight / 2.;\n } else if (sideEnum == 3.) {\n offset = side * normalOut * inputs.weight / 2.;\n }\n }\n if (uStrokeJoin == STROKE_JOIN_BEVEL) {\n vec2 avgNormal = vec2(-vTangent.y, vTangent.x);\n vMaxDist = abs(dot(avgNormal, normalIn * inputs.weight / 2.));\n } else {\n vMaxDist = inputs.weight / 2.;\n }\n } else {\n vec2 tangent = aTangentIn == vec3(0.) ? tangentOut : tangentIn;\n vTangent = tangent;\n vec2 normal = vec2(-tangent.y, tangent.x);\n\n float normalOffset = sign(aSide);\n // Caps will have side values of -2 or 2 on the edge of the cap that\n // extends out from the line\n float tangentOffset = abs(aSide) - 1.;\n offset = (normal * normalOffset + tangent * tangentOffset) *\n inputs.weight * 0.5;\n vMaxDist = inputs.weight / 2.;\n }\n\n vCenter = p.xy;\n vPosition = vCenter + offset;\n vColor = inputs.color;\n\n gl_Position.xy = p.xy + offset.xy * curPerspScale;\n gl_Position.zw = p.zw;\n \n HOOK_afterVertex();\n}\n",lineFrag:ei+"precision highp int;\nprecision highp float;\n\nuniform vec4 uMaterialColor;\nuniform int uStrokeCap;\nuniform int uStrokeJoin;\n\nIN vec4 vColor;\nIN vec2 vTangent;\nIN vec2 vCenter;\nIN vec2 vPosition;\nIN float vStrokeWeight;\nIN float vMaxDist;\nIN float vCap;\nIN float vJoin;\n\nfloat distSquared(vec2 a, vec2 b) {\n vec2 aToB = b - a;\n return dot(aToB, aToB);\n}\n\nstruct Inputs {\n vec4 color;\n vec2 tangent;\n vec2 center;\n vec2 position;\n float strokeWeight;\n};\n\nvoid main() {\n HOOK_beforeFragment();
7\n\n Inputs inputs;\n inputs.color = vColor;\n inputs.tangent = vTangent;\n inputs.center = vCenter;\n inputs.position = vPosition;\n inputs.strokeWeight = vStrokeWeight;\n inputs = HOOK_getPixelInputs(inputs);\n\n if (vCap > 0.) {\n if (\n uStrokeCap == STROKE_CAP_ROUND &&\n HOOK_shouldDiscard(distSquared(inputs.position, inputs.center) > inputs.strokeWeight * inputs.strokeWeight * 0.25)\n ) {\n discard;\n } else if (\n uStrokeCap == STROKE_CAP_SQUARE &&\n HOOK_shouldDiscard(dot(inputs.position - inputs.center, inputs.tangent) > 0.)\n ) {\n discard;\n // Use full area for PROJECT\n } else if (HOOK_shouldDiscard(false)) {\n discard;\n }\n } else if (vJoin > 0.) {\n if (\n uStrokeJoin == STROKE_JOIN_ROUND &&\n HOOK_shouldDiscard(distSquared(inputs.position, inputs.center) > inputs.strokeWeight * inputs.strokeWeight * 0.25)\n ) {\n discard;\n } else if (uStrokeJoin == STROKE_JOIN_BEVEL) {\n vec2 normal = vec2(-inputs.tangent.y, inputs.tangent.x);\n if (HOOK_shouldDiscard(abs(dot(inputs.position - inputs.center, normal)) > vMaxDist)) {\n discard;\n }\n // Use full area for MITER\n } else if (HOOK_shouldDiscard(false)) {\n discard;\n }\n }\n OUT_COLOR = HOOK_getFinalColor(vec4(inputs.color.rgb, 1.) * inputs.color.a);\n HOOK_afterFragment();\n}\n",pointVert:"IN vec3 aPosition;\nuniform float uPointSize;\nOUT float vStrokeWeight;\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nvoid main() {\n HOOK_beforeVertex();\n vec4 viewModelPosition = vec4(HOOK_getWorldPosition(\n (uModelViewMatrix * vec4(HOOK_getLocalPosition(aPosition), 1.0)).xyz\n ), 1.);\n gl_Position = uProjectionMatrix * viewModelPosition; \n\n float pointSize = HOOK_getPointSize(uPointSize);\n\n gl_PointSize = pointSize;\n vStrokeWeight = pointSize;\n HOOK_afterVertex();\n}\n",pointFrag:"precision mediump int;\nuniform vec4 uMaterialColor;\nIN float vStrokeWeight;\n\nvoid main(){\n HOOK_beforeFragment();\n float mask = 0.0;\n\n // make a circular mask using the gl_PointCoord (goes from 0 - 1 on a point)\n // might be able to get a nicer edge on big strokeweights with smoothstep but slightly less performant\n\n mask = step(0.98, length(gl_PointCoord * 2.0 - 1.0));\n\n // if strokeWeight is 1 or less lets just draw a square\n // this prevents weird artifacting from carving circles when our points are really small\n // if strokeWeight is larger than 1, we just use it as is\n\n mask = mix(0.0, mask, clamp(floor(vStrokeWeight - 0.5),0.0,1.0));\n\n // throw away the borders of the mask\n // otherwise we get weird alpha blending issues\n\n if(HOOK_shouldDiscard(mask > 0.98)){\n discard;\n }\n\n OUT_COLOR = HOOK_getFinalColor(vec4(uMaterialColor.rgb, 1.) * uMaterialColor.a);\n HOOK_afterFragment();\n}\n",imageLightVert:"precision highp float;\nattribute vec3 aPosition;\nattribute vec3 aNormal;\nattribute vec2 aTexCoord;\n\nvarying vec3 localPos;\nvarying vec3 vWorldNormal;\nvarying vec3 vWorldPosition;\nvarying vec2 vTexCoord;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform mat3 uNormalMatrix;\n\nvoid main() {\n // Multiply the position by the matrix.\n vec4 viewModelPosition = uModelViewMatrix * vec4(aPosition, 1.0
7);\n gl_Position = uProjectionMatrix * viewModelPosition; \n \n // orient the normals and pass to the fragment shader\n vWorldNormal = uNormalMatrix * aNormal;\n \n // send the view position to the fragment shader\n vWorldPosition = (uModelViewMatrix * vec4(aPosition, 1.0)).xyz;\n \n localPos = vWorldPosition;\n vTexCoord = aTexCoord;\n}\n\n\n/*\nin the vertex shader we'll compute the world position and world oriented normal of the vertices and pass those to the fragment shader as varyings.\n*/\n",imageLightDiffusedFrag:"precision highp float;\nvarying vec3 localPos;\n\n// the HDR cubemap converted (can be from an equirectangular environment map.)\nuniform sampler2D environmentMap;\nvarying vec2 vTexCoord;\n\nconst float PI = 3.14159265359;\n\nvec2 nTOE( vec3 v ){\n // x = r sin(phi) cos(theta) \n // y = r cos(phi) \n // z = r sin(phi) sin(theta)\n float phi = acos( v.y );\n // if phi is 0, then there are no x, z components\n float theta = 0.0;\n // else \n theta = acos(v.x / sin(phi));\n float sinTheta = v.z / sin(phi);\n if (sinTheta < 0.0) {\n // Turn it into -theta, but in the 0-2PI range\n theta = 2.0 * PI - theta;\n }\n theta = theta / (2.0 * 3.14159);\n phi = phi / 3.14159 ;\n \n vec2 angles = vec2( phi, theta );\n return angles;\n}\n\nfloat random(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * .1031);\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n}\n\nvoid main()\n{ \n // the sample direction equals the hemisphere's orientation\n float phi = vTexCoord.x * 2.0 * PI;\n float theta = vTexCoord.y * PI;\n float x = sin(theta) * cos(phi);\n float y = sin(theta) * sin(phi);\n float z = cos(theta);\n vec3 normal = vec3( x, y, z);\n\n // Discretely sampling the hemisphere given the integral's\n // spherical coordinates translates to the following fragment code:\n vec3 irradiance = vec3(0.0); \n vec3 up = vec3(0.0, 1.0, 0.0);\n vec3 right = normalize(cross(up, normal));\n up = normalize(cross(normal, right));\n\n // We specify a fixed sampleDelta delta value to traverse\n // the hemisphere; decreasing or increasing the sample delta\n // will increase or decrease the accuracy respectively.\n const float sampleDelta = 0.100;\n float nrSamples = 0.0;\n float randomOffset = random(gl_FragCoord.xy) * sampleDelta;\n for(float rawPhi = 0.0; rawPhi < 2.0 * PI; rawPhi += sampleDelta)\n {\n float phi = rawPhi + randomOffset;\n for(float rawTheta = 0.0; rawTheta < ( 0.5 ) * PI; rawTheta += sampleDelta)\n {\n float theta = rawTheta + randomOffset;\n // spherical to cartesian (in tangent space) // tangent space to world // add each sample result to irradiance\n float x = sin(theta) * cos(phi);\n float y = sin(theta) * sin(phi);\n float z = cos(theta);\n vec3 tangentSample = vec3( x, y, z);\n \n vec3 sampleVec = tangentSample.x * right + tangentSample.y * up + tangentSample.z * normal;\n irradiance += (texture2D(environmentMap, nTOE(sampleVec)).xyz) * cos(theta) * sin(theta);\n nrSamples++;\n }\n }\n // divide by the total number of samples taken, giving us the average sampled irradiance.\n irradiance = PI * irradiance * (1.0 / float(nrSamples )) ;\n \n \n gl_FragColor = vec4(irradiance, 1.0);\n}",imageLightSpecularFrag:"precision highp float;\r\nvarying vec3 localPos;\r\nvarying vec2 vTexCoord;\r\n\r\n// our texture\r\nuniform sampler2D environmentMap;\r\nuniform float roughness;\r\n\r\nconst float PI = 3.14159265359;\r\n\r\nfloat VanDerCorput(int bits);\r\nvec2 HammersleyNoBitOps(int i, int N);\r\nvec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness);\r\n\r\n\r\nvec2 nTOE( vec3 v ){\r\n // x = r sin(phi) cos(theta) \r\n // y = r cos(phi) \r\n // z = r sin(phi) sin(theta)\r\n float phi = acos( v.y );\r\n // if phi is 0, then there are no x, z components\r\n float theta = 0.0;\r\n // else \r\n theta = acos(v.x / sin(phi));\r\n float sinTheta = v.z / sin(phi);\r\n if (sinTheta < 0.0) {\r\n // Turn it into -theta, but in the 0-2PI range\r\n theta = 2.0 * PI - theta;\r\n }\r\n theta = theta / (2.0 * 3.14159);\r\n phi = phi / 3.14159 ;\r\n \r\n vec2 angles = vec2( phi, theta );\r\n return angles;\r\n}\r\n\r\n\r\nvoid main(){\r\n const int SAMPLE_COUNT = 400; // 4096\r\n int lowRoughnessLimit = int(pow(2.0,(roughness+0.1)*20.0));\r\n float totalWeight = 0.0;\r\n vec3 prefilteredColor = vec3(0.0);\r\n float phi = vTexCoord.x * 2.0 * PI;\r\n float theta = vTexCoord.y * PI;\r\n float x = sin(theta) * cos(phi);\r\n float y = sin(theta) * sin(phi);\r\n float z = cos(theta);\r\n vec3 N = vec3(x,y,z);\r\n vec3 V = N;\r\n for (int i = 0; i < SAMPLE_COUNT; ++i)\r\n {\r\n // break at smaller sample numbers for low roughness levels\r\n if(i == lowRoughnessLimit)\r\n {\r\n break;\r\n }\r\n vec2 Xi = HammersleyNoBitOps(i, SAMPLE_COUNT);\r\n vec3 H = ImportanceSampleGGX(Xi, N, roughness);\r\n vec3 L = normalize(2.0 * dot(V, H) * H - V);\r\n\r\n float NdotL = max(dot(N, L), 0.0);\r\n if (NdotL > 0.0)\r\n {\r\n prefilteredColor += texture2D(environmentMap, nTOE(L)).xyz * NdotL;\r\n totalWeight += NdotL;\r\n }\r\n }\r\n prefilteredColor = prefilteredColor / totalWeight;\r\n\r\n gl_FragColor = vec4(prefilteredColor, 1.0);\r\n}\r\n\r\nvec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness){\r\n float a = roughness * roughness;\r\n\r\n float phi = 2.0 * PI * Xi.x;\r\n float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (a * a - 1.0) * Xi.y));\r\n float sinTheta = sqrt(1.0 - cosTheta * cosTheta);\r\n // from spherical coordinates to cartesian coordinates\r\n vec3 H;\r\n H.x = cos(phi) * sinTheta;\r\n H.y = sin(phi) * sinTheta;\r\n H.z = cosTheta;\r\n\r\n // from tangent-space vector to world-space sample vector\r\n vec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);\r\n vec3 tangent = normalize(cross(up, N));\r\n vec3 bitangent = cross(N, tangent);\r\n\r\n vec3 sampleVec = tangent * H.x + bitangent * H.y + N * H.z;\r\n return normalize(sampleVec);\r\n}\r\n\r\n\r\nfloat VanDerCorput(int n, int base)\r\n{\r\n#ifdef WEBGL2\r\n\r\n uint bits = uint(n);\r\n bits = (bits << 16u) | (bits >> 16u);\r\n bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);\r\n bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);\r\n bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);\r\n bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);\r\n return float(bits) * 2.3283064365386963e-10; // / 0x100000000\r\n\r\n#else\r\n\r\n float invBase = 1.0 / float(base);\r\n float denom = 1.0;\r\n float result = 0.0;\r\n\r\n\r\n for (int i = 0; i < 32; ++i)\r\n {\r\n if (n > 0)\r\n {\r\n denom = mod(float(n), 2.0);
7\r\n result += denom * invBase;\r\n invBase = invBase / 2.0;\r\n n = int(float(n) / 2.0);\r\n }\r\n }\r\n\r\n\r\n return result;\r\n\r\n#endif\r\n}\r\n\r\nvec2 HammersleyNoBitOps(int i, int N)\r\n{\r\n return vec2(float(i) / float(N), VanDerCorput(i, 2));\r\n}\r\n",filterBaseVert:G,filterBaseFrag:H},ea=en.sphereMappingFrag;for(let e in en)en[e]=j+en[e];let eo={[s.X]:W,[s.Y]:X,[s.V]:Y,[s.$]:q,[s.U]:K,[s.K]:$,[s._]:Z,[s.Z]:J};class eh extends o.R{constructor(e,t,i,r,n,o){for(let s of(super(e,t,i,r),this.canvas=this.elt=n||document.createElement("canvas"),this._setAttributeDefaults(e),this._initContext(),this.GL=this.drawingContext,this._isMainCanvas?(this._pInst._curElement=this,this._pInst.canvas=this.canvas):this.canvas.style.display="none",this.elt.id="defaultCanvas0",this.elt.classList.add("p5Canvas"),this.wrappedElt=new a.H(this.elt,this._pInst),Object.getOwnPropertyNames(a.H.prototype)))"constructor"!==s&&"_"!==s[0]&&Object.defineProperty(this,s,{get(){return this.wrappedElt[s]}});let h=this._adjustDimensions(t,i);if(t=h.adjustedWidth,i=h.adjustedHeight,this.width=t,this.height=i,this.elt.width=t*this._pixelDensity,this.elt.height=i*this._pixelDensity,this.elt.style.width=`${t}px`,this.elt.style.height=`${i}px`,this._origViewport={width:this.GL.drawingBufferWidth,height:this.GL.drawingBufferHeight},this.viewport(this._origViewport.width,this._origViewport.height),this._pInst._userNode)this._pInst._userNode.appendChild(this.elt);else{if(0===document.getElementsByTagName("main").length){let e=document.createElement("main");document.body.appendChild(e)}document.getElementsByTagName("main")[0].appendChild(this.elt)}this.isP3D=!0,this.geometryBuilder=void 0,this.states.uModelMatrix=new C.uq(4),this.states.uViewMatrix=new C.uq(4),this.states.uPMatrix=new C.uq(4),this.states.curCamera=new R(this),this.states.uPMatrix.set(this.states.curCamera.projMatrix),this.states.uViewMatrix.set(this.states.curCamera.cameraMatrix),this.states.enableLighting=!1,this.states.ambientLightColors=[],this.states.specularColors=[1,1,1],this.states.directionalLightDirections=[],this.states.directionalLightDiffuseColors=[],this.states.directionalLightSpecularColors=[],this.states.pointLightPositions=[],this.states.pointLightDiffuseColors=[],this.states.pointLightSpecularColors=[],this.states.spotLightPositions=[],this.states.spotLightDirections=[],this.states.spotLightDiffuseColors=[],this.states.spotLightSpecularColors=[],this.states.spotLightAngle=[],this.states.spotLightConc=[],this.states.activeImageLight=null,this.states.curFillColor=[1,1,1,1],this.states.curAmbientColor=[1,1,1,1],this.states.curSpecularColor=[0,0,0,0],this.states.curEmissiveColor=[0,0,0,0],this.states.curStrokeColor=[0,0,0,1],this.states.curBlendMode=s.u,this.states._hasSetAmbient=!1,this.states._useSpecularMaterial=!1,this.states._useEmissiveMaterial=!1,this.states._useNormalMaterial=!1,this.states._useShininess=1,this.states._useMetalness=0,this.states.tint=[255,255,255,255],this.states.constantAttenuation=1,this.states.linearAttenuation=0,this.states.quadraticAttenuation=0,this.states._currentNormal=new b.M(0,0,1),this.states.drawMode=s.as,this.states._tex=null,this.states.textureMode=s.a1,this.states.textureWrapX=s.at,this.states.textureWrapY=s.at,this._isErasing=!1,this._simpleLines=!1,this._clipDepths=[],this._isCl
7ipApplied=!1,this._stencilTestOn=!1,this.mixedAmbientLight=[],this.mixedSpecularColor=[],this.diffusedTextures=new Map,this.specularTextures=new Map,this.preEraseBlend=void 0,this._cachedBlendMode=void 0,this._cachedFillStyle=[1,1,1,1],this._cachedStrokeStyle=[0,0,0,1],this.webglVersion===s.z?this.blendExt=this.GL:this.blendExt=this.GL.getExtension("EXT_blend_minmax"),this._isBlending=!1,this._useLineColor=!1,this._useVertexColor=!1,this.registerEnabled=new Set,this.states.curCamera._computeCameraDefaultSettings(),this.states.curCamera._setDefaultCamera(),this.filterCamera=new R(this),this.filterCamera._computeCameraDefaultSettings(),this.filterCamera._setDefaultCamera(),this.prevTouches=[],this.zoomVelocity=0,this.rotateVelocity=new b.M(0,0),this.moveVelocity=new b.M(0,0),this.executeZoom=!1,this.executeRotateAndMove=!1,this._drawingFilter=!1,this._drawingImage=!1,this.specularShader=void 0,this.sphereMapping=void 0,this.diffusedShader=void 0,this._baseFilterShader=void 0,this._defaultLightShader=void 0,this._defaultImmediateModeShader=void 0,this._defaultNormalShader=void 0,this._defaultColorShader=void 0,this._defaultPointShader=void 0,this.states.userFillShader=void 0,this.states.userStrokeShader=void 0,this.states.userPointShader=void 0,this.states.userImageShader=void 0,this.states.curveDetail=1/4,this.shapeBuilder=new S.V(this),this.buffers={fill:[new M.f(3,"vertices","vertexBuffer","aPosition",this,this._vToNArray),new M.f(3,"vertexNormals","normalBuffer","aNormal",this,this._vToNArray),new M.f(4,"vertexColors","colorBuffer","aVertexColor",this),new M.f(3,"vertexAmbients","ambientBuffer","aAmbientColor",this),new M.f(2,"uvs","uvBuffer","aTexCoord",this,e=>e.flat())],stroke:[new M.f(4,"lineVertexColors","lineColorBuffer","aVertexColor",this),new M.f(3,"lineVertices","lineVerticesBuffer","aPosition",this),new M.f(3,"lineTangentsIn","lineTangentsInBuffer","aTangentIn",this),new M.f(3,"lineTangentsOut","lineTangentsOutBuffer","aTangentOut",this),new M.f(1,"lineSides","lineSidesBuffer","aSide",this)],text:[new M.f(3,"vertices","vertexBuffer","aPosition",this,this._vToNArray),new M.f(2,"uvs","uvBuffer","aTexCoord",this,e=>e.flat())],point:this.GL.createBuffer(),user:[]},this.geometryBufferCache=new E.T(this),this.curStrokeCap=s.j,this.curStrokeJoin=s.j,this.textures=new Map,this.framebuffers=new Set,this.activeFramebuffers=[],this.states.filterShader=void 0,this.filterLayer=void 0,this.filterLayerTemp=void 0,this.defaultFilterShaders={},this.fontInfos={},this._curShader=void 0,this.drawShapeCount=1,this.scratchMat3=new C.uq(3),this._userEnabledStencil=!1,this._internalEnable=this.drawingContext.enable,this._internalDisable=this.drawingContext.disable,this.drawingContext.enable=e=>(e!==this.drawingContext.STENCIL_TEST||this._clipping||(this._userEnabledStencil=!0),this._internalEnable.call(this.drawingContext,e)),this.drawingContext.disable=e=>(e===this.drawingContext.STENCIL_TEST&&(this._userEnabledStencil=!1),this._internalDisable.call(this.drawingContext,e)),this._validateFaces=!1}remove(){this.wrappedElt.remove(),this.wrappedElt=null,this.canvas=null,this.elt=null}beginGeometry(){if(this.geometryBuilder)throw Error("It looks like `beginGeometry()` is being called while another p5.Geometry is already being build.");this.geometryBuilder=new y.A(this),this.geometryBuilder.prevFillColor=this.states.fillColor,this.fill(new n.C([-1,-1,-1,-1]))}endGeometry(){if(!this.geometryBuilder)throw Error("Make sure you call beginGeometry() before endGeometry()!");let e=this.geometryBuilder.finish();return this.geometryBuilder.prevFillColor?this.fill(this.geometryBuilder.prevFillColor):this.noFill(),this.geometryBuilder=void 0,e}buildGeometry(e){return this.beginGeometry(),e(),this.endGeometry()}beginShape(...e){super.beginShape(...e)}curveDetail(e){if(void 0===e)return this.states.curveDetail;this.states.setValue("curveDetail",e)}drawShape(e){let t=new L.Om({curveDetail:this.states.curveDetail});e.accept(t),this.shapeBuilder.constructFromContours(e,t.contours),this.geometryBuilder?this.geometryBuilder.addImmediate(this.shapeBuilder.geometry,this.shapeBuilder.shapeMode,{validateFaces:this._val
7idateFaces}):(this.states.fillColor||this.states.strokeColor)&&(this.shapeBuilder.shapeMode===s.o?this._drawPoints(this.shapeBuilder.geometry.vertices,this.buffers.point):this._drawGeometry(this.shapeBuilder.geometry,{mode:this.shapeBuilder.shapeMode,count:this.drawShapeCount})),this.drawShapeCount=1}endShape(e,t){this.drawShapeCount=t,super.endShape(e,t)}vertexProperty(...e){this.currentShape.vertexProperty(...e)}normal(e,t,i){e instanceof b.M?this.states.setValue("_currentNormal",e):this.states.setValue("_currentNormal",new b.M(e,t,i)),this.updateShapeVertexProperties()}model(e,t=1){e.vertices.length>0&&(this.geometryBuilder?this.geometryBuilder.addRetained(e):(this.geometryInHash(e.gid)||(e._edgesToVertices(),this._getOrMakeCachedBuffers(e)),this._drawGeometry(e,{count:t})))}_drawGeometry(e,{mode:t=s.p,count:i=1}={}){for(let t in e.userVertexProperties){let i=e.userVertexProperties[t];this.buffers.user.push(new M.f(i.getDataSize(),i.getSrcName(),i.getDstName(),i.getName(),this))}this.states.fillColor&&e.vertices.length>=3&&![s.L,s.o].includes(t)&&this._drawFills(e,{mode:t,count:i}),this.states.strokeColor&&e.lineVertices.length>=1&&this._drawStrokes(e,{count:i}),this.buffers.user=[]}_drawGeometryScaled(e,t,i,r){let s=this.states.uModelMatrix;this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone());try{this.states.uModelMatrix.scale(t,i,r),this.geometryBuilder?this.geometryBuilder.addRetained(e):this._drawGeometry(e)}finally{this.states.setValue("uModelMatrix",s)}}_drawFills(e,{count:t,mode:i}={}){this._useVertexColor=e.vertexColors.length>0;let r=!this._drawingFilter&&this.states.userFillShader?this.states.userFillShader:this._getFillShader();for(let t of(r.bindShader(),this._setGlobalUniforms(r),this._setFillUniforms(r),r.bindTextures(),this.buffers.fill))t._prepareBuffer(e,r);this._prepareUserAttributes(e,r),r.disableRemainingAttributes(),this._applyColorBlend(this.states.curFillColor,e.hasFillTransparency()),this._drawBuffers(e,{mode:i,count:t}),r.unbindShader()}_drawStrokes(e,{count:t}={}){let i=this.GL;this._useLineColor=e.vertexStrokeColors.length>0;let r=this._getStrokeShader();for(let t of(r.bindShader(),this._setGlobalUniforms(r),this._setStrokeUniforms(r),r.bindTextures(),this.buffers.stroke))t._prepareBuffer(e,r);if(this._prepareUserAttributes(e,r),r.disableRemainingAttributes(),this._applyColorBlend(this.states.curStrokeColor,e.hasStrokeTransparency()),1===t)i.drawArrays(i.TRIANGLES,0,e.lineVertices.length/3);else try{i.drawArraysInstanced(i.TRIANGLES,0,e.lineVertices.length/3,t)}catch(e){console.log("\uD83C\uDF38 p5.js says: Instancing is only supported in WebGL2 mode")}r.unbindShader()}_drawPoints(e,t){let i=this.GL,r=this._getPointShader();r.bindShader(),this._setGlobalUniforms(r),this._setPointUniforms(r),r.bindTextures(),this._bindBuffer(t,i.ARRAY_BUFFER,this._vToNArray(e),Float32Array,i.STATIC_DRAW),r.enableAttrib(r.attributes.aPosition,3),this._applyColorBlend(this.states.curStrokeColor),i.drawArrays(i.Points,0,e.length),r.unbindShader()}_prepareUserAttributes(e,t){for(let i of this.buffers.user){if(!this._pInst.constructor.disableFriendlyErrors){let t=e.userVertexProperties[i.attr];if(t){let i=t.getSrcArray().length/t.getDataSize();i>e.vertices.length?this._pInst.constructor._friendlyError(`One of the geometries has a custom vertex property '${t.getName()}' with more values than vertices. This is probably caused by directly using the Geometry.vertexProperty() method.`,"vertexProperty()"):i<e.vertices.length&&this._pInst.constructor._friendlyError(`One of the geometries has a custom vertex property '${t.getName()}' with fewer values than vertices. This is probably caused by directly using the Geometry.vertexProperty() method.`,"vertexProperty()")}}i._prepareBuffer(e,t)}}_drawBuffers(e,{mode:t=this.GL.TRIANGLES,count:i}){let r=this.GL,n=this.geometryBufferCache.getCached(e);if(n)if(n.indexBuffer){if(this._bindBuffer(n.indexBuffer,r.ELEMENT_ARRAY_BUFFER),this._pInst.webglVersion!==s.z&&n.indexBufferType===r.UNSIGNED_INT&&!r.getExtension("OES_element_index_uint"))throw Error("Unable to render a 3d model with > 65535 triangles. Your web browser does not support the WebGL Extension OES_element_index_uint.");if(1===i)r.drawElements(r.TRIANGLES,3*e.faces.length,n.indexBufferType,0);else try{r.drawElementsInstanced(r.TRIANGLES,3*e.faces.length,n.indexBufferType,0,i)}catch(e){console.log("\uD83C\uDF38 p5.js says: Instancing is only supported in WebGL2 mode")}}else if(1===i)r.drawArrays(t,0,e.vertices.length);else try{r.drawArraysInstanced(t,0,e.vertices.length,i)}catch(e){console.log("\uD83C\uDF38 p5.js says: Instancing is only supported in WebGL2 mode")}}_getOrMakeCachedBuffers(e){return this.geometryBufferCache.ensureCached(e)}_setAttributeDefaults(e){let t={alpha:!0,depth:!0,stencil:!0,antialias:navigator.userAgent.toLowerCase().includes("safari"),premultipliedAlpha:!0,preserveDrawingBuffer:!0,perPixelLighting:!0,version:2};null===e._glAttributes?e._glAttributes=t:e._glAttributes=Object.assign(t,e._glAttributes)}_initContext(){if(this._pInst._glAttributes?.version!==1&&(this.drawingContext=this.canvas.getContext("webgl2",this._pInst._glAttributes)),this.webglVersion=this.drawingContext?s.z:s.a0,this._pInst.webglVersion=this.webglVersion,this.drawingContext||(this.drawingContext=this.canvas.getContext("webgl",this._pInst._glAttributes)||this.canvas.getContext("experimental-webgl",this._pInst._glAttributes)),null===this.drawingContext)throw Error("Error creating webgl context");{let e=this.drawingContext;e.enable(e.DEPTH_TEST),e.depthFunc(e.LEQUAL),e.viewport(0,0,e.drawingBufferWidth,e.drawingBufferHeight),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),this._viewport=this.drawingContext.getParameter(this.drawingContext.VIEWPORT)}}_getMaxTextureSize(){let e=this.drawingContext;return e.getParameter(e.MAX_TEXTURE_SIZE)}_adjustDimensions(e,t){this._maxTextureSize||(this._maxTextureSize=this._getMaxTextureSize());let i=Math.floor(this._maxTextureSize/this._pixelDensity),r=Math.min(e,i),s=Math.min(t,i);return(r!==e||s!==t)&&console.warn(`Warning: The requested width/height exceeds hardware limits. Adjusting dimensions to width: ${r}, height: ${s}.`),{adjustedWidth:r,adjustedHeight:s}}_resetContext(e,t){let i=this.width,r=this.height,s=this.canvas.id,n=this._pInst instanceof em,o={position:this.canvas.style.position,top:this.canvas.style.top,left
7:this.canvas.style.left};if(n){let e=this._pInst;e.canvas.parentNode.removeChild(e.canvas),e.canvas=document.createElement("canvas"),(e._pInst._userNode||document.body).appendChild(e.canvas),a.H.call(e,e.canvas,e._pInst),e.width=i,e.height=r}else{let e=this.canvas;e&&e.parentNode.removeChild(e),(e=document.createElement("canvas")).id=s,this._pInst._userNode?this._pInst._userNode.appendChild(e):document.body.appendChild(e),this._pInst.canvas=e,this.canvas=e,this.canvas.style.position=o.position,this.canvas.style.top=o.top,this.canvas.style.left=o.left}let h=new eh(this._pInst,i,r,!n,this._pInst.canvas);this._pInst._renderer=h,h._applyDefaults(),"function"==typeof t&&setTimeout(()=>{t.apply(window._renderer,e)},0)}_update(){this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone()),this.states.uModelMatrix.reset(),this.states.setValue("uViewMatrix",this.states.uViewMatrix.clone()),this.states.uViewMatrix.set(this.states.curCamera.cameraMatrix),this.states.setValue("ambientLightColors",[]),this.states.setValue("specularColors",[1,1,1]),this.states.setValue("directionalLightDirections",[]),this.states.setValue("directionalLightDiffuseColors",[]),this.states.setValue("directionalLightSpecularColors",[]),this.states.setValue("pointLightPositions",[]),this.states.setValue("pointLightDiffuseColors",[]),this.states.setValue("pointLightSpecularColors",[]),this.states.setValue("spotLightPositions",[]),this.states.setValue("spotLightDirections",[]),this.states.setValue("spotLightDiffuseColors",[]),this.states.setValue("spotLightSpecularColors",[]),this.states.setValue("spotLightAngle",[]),this.states.setValue("spotLightConc",[]),this.states.setValue("enableLighting",!1),this.states.setValue("tint",[255,255,255,255]),this.GL.clearStencil(0),this.GL.clear(this.GL.DEPTH_BUFFER_BIT|this.GL.STENCIL_BUFFER_BIT),this._userEnabledStencil||this._internalDisable.call(this.GL,this.GL.STENCIL_TEST)}background(...e){let t=this._pInst.color(...e);this.clear(...t._getRGBA())}get uModelMatrix(){return this.states.uModelMatrix}get uViewMatrix(){return this.states.uViewMatrix}get uPMatrix(){return this.states.uPMatrix}get uMVMatrix(){let e=this.uModelMatrix.copy();return e.mult(this.uViewMatrix),e}getWorldToScreenMatrix(){let e=this.states.uModelMatrix,t=this.states.uViewMatrix,i=this.states.uPMatrix,r=new C.uq(4);return r.scale(this.width,this.height,1),r.translate([.5,.5,.5]),r.scale(.5,-.5,.5),e.copy().mult(t).mult(i).mult(r)}fill(...e){super.fill(...e);let t=this.states.fillColor;this.states.setValue("curFillColor",t._array),this.states.setValue("drawMode",s.as),this.states.setValue("_useNormalMaterial",!1),this.states.setValue("_tex",null)}stroke(...e){super.stroke(...e),this.states.setValue("curStrokeColor",this.states.strokeColor._array)}getCommonVertexProperties(){return{...super.getCommonVertexProperties(),stroke:this.states.strokeColor,fill:this.states.fillColor,normal:this.states._currentNormal}}getSupportedIndividualVertexProperties(){return{textureCoordinates:!0}}strokeCap(e){this.curStrokeCap=e}strokeJoin(e){this.curStrokeJoin=e}getFilterLayer(){return this.filterLayer||(this.filterLayer=new eM(this)),this.filterLayer}getFilterLayerTemp(){return this.filterLayerTemp||(this.filterLayerTemp=new eM(this)),this.filterLayerTemp}matchSize(e,t){(e.width!==t.width||e.height!==t.height)&&e.resize(t.width,t.height),e.pixelDensity()!==t.pixelDensity()&&e.pixelDensity(t.pixelDensity())}filter(...e){let t,i,r=this.getFilterLayer();"string"==typeof e[0]?(t=(i=e[0])in F.k&&void 0===e[1]?F.k[i]:e[1],i in this.defaultFilterShaders||(this.defaultFilterShaders[i]=new k(r.renderer,Q,eo[i])),this.states.setValue("filterShader",this.defaultFilterShaders[i])):this.states.setValue("filterShader",e[0]);let n=this.activeFramebuffer()||this;this.matchSize(r,n),r.draw(()=>this.clear());let a=[1/(n.width*n.pixelDensity()),1/(n.height*n.pixelDensity())];if(i===s.$){let e=this.getFilterLayerTemp();this.matchSize(e,n),this.push(),this.states.setValue("strokeColor",null),this.blendMode(s.u),this.shader(this.states.filterShader),this.states.filterShader.setUniform("texelSize",a),this.states.filterShader.setUniform("canvasSize",[n.width,n.height]),this.states.filterShader.setUniform("radius",Math.max(1,t)),e.draw(()=>{this.states.filterShader.setUniform("direction",[1,0]),this.states.filterShader.setUniform("tex0",n),this.clear(),this.shader(this.states.filterShader),this.noLights(),this.plane(n.width,n.height)}),r.draw(()=>{this.states.filterShader.setUniform("direction",[0,1]),this.states.filterShader.setUniform("tex0",e),this.clear(),this.shader(this.states.filterShader),this.noLights(),this.plane(n.width,n.height)}),this.pop()}else r.draw(()=>{this.states.setValue("strokeColor",null),this.blendMode(s.u),this.shader(this.states.filterShader),this.states.filterShader.setUniform("tex0",n),this.states.filterShader.setUniform("texelSize",a),this.states.filterShader.setUniform("canvasSize",[n.width,n.height]),this.states.filterShader.setUniform("filterParameter",t),this.noLights(),this.plane(n.width,n.height)});this.push(),this.states.setValue("strokeColor",null),this.clear(),this.push(),this.states.setValue("imageMode",s.e),this.blendMode(s.u),n.filterCamera._resize(),this.setCamera(n.filterCamera),this.resetMatrix(),this._drawingFilter=!0,this.image(r,0,0,r.width,r.height,-n.width/2,-n.height/2,n.width,n.height),this._drawingFilter=!1,this.clearDepth(),this.pop(),this.pop()}pixelDensity(e){return e?this._pInst.pixelDensity(e):this._pInst.pixelDensity()}blendMode(e){e===s.a6||e===s.a7||e===s.ai||e===s.u||e===s.a5||e===s.ab||e===s.aa||e===s.ac||e===s.a9||e===s.a4?this.states.setValue("curBlendM
7ode",e):(e===s.ah||e===s.ad||e===s.ae||e===s.af||e===s.ag)&&console.warn("BURN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, and DODGE only work for blendMode in 2D mode.")}erase(e,t){this._isErasing||(this.preEraseBlend=this.states.curBlendMode,this._isErasing=!0,this.blendMode(s.a4),this._cachedFillStyle=this.states.curFillColor.slice(),this.states.setValue("curFillColor",[1,1,1,e/255]),this._cachedStrokeStyle=this.states.curStrokeColor.slice(),this.states.setValue("curStrokeColor",[1,1,1,t/255]))}noErase(){this._isErasing&&(this.states.setValue("curFillColor",this._cachedFillStyle.slice()),this.states.setValue("curStrokeColor",this._cachedStrokeStyle.slice()),this.states.setValue("curBlendMode",this.preEraseBlend),this.blendMode(this.preEraseBlend),this._isErasing=!1,this._applyBlendMode())}drawTarget(){return this.activeFramebuffers[this.activeFramebuffers.length-1]||this}beginClip(e={}){super.beginClip(e),this.drawTarget()._isClipApplied=!0;let t=this.GL;t.clearStencil(0),t.clear(t.STENCIL_BUFFER_BIT),this._internalEnable.call(t,t.STENCIL_TEST),this._stencilTestOn=!0,t.stencilFunc(t.ALWAYS,1,255),t.stencilOp(t.KEEP,t.KEEP,t.REPLACE),t.disable(t.DEPTH_TEST),this.push(),this.resetShader(),this.states.fillColor&&this.fill(0,0),this.states.strokeColor&&this.stroke(0,0)}endClip(){this.pop();let e=this.GL;e.stencilOp(e.KEEP,e.KEEP,e.KEEP),e.stencilFunc(this._clipInvert?e.EQUAL:e.NOTEQUAL,0,255),e.enable(e.DEPTH_TEST),this._clipDepths.push(this._pushPopDepth),super.endClip()}_clearClip(){this.GL.clearStencil(1),this.GL.clear(this.GL.STENCIL_BUFFER_BIT),this._clipDepths.length>0&&this._clipDepths.pop(),this.drawTarget()._isClipApplied=!1}_getPixel(e,t){let i=this.GL;return ec(i,null,e,t,i.RGBA,i.UNSIGNED_BYTE,this._pInst.height*this._pInst.pixelDensity())}loadPixels(){if(!0!==this._pInst._glAttributes.preserveDrawingBuffer)return void console.log("loadPixels only works in WebGL when preserveDrawingBuffer is true.");let e=this._pixelDensity,t=this.GL;this.pixels=eu(this.pixels,t,null,0,0,this.width*e,this.height*e,t.RGBA,t.UNSIGNED_BYTE,this.height*e)}updatePixels(){let e=this._getTempFramebuffer();e.pixels=this.pixels,e.updatePixels(),this.push(),this.resetMatrix(),this.clear(),this.states.setValue("imageMode",s.e),this.image(e,0,0,e.width,e.height,-e.width/2,-e.height/2,e.width,e.height),this.pop(),this.GL.clearDepth(1),this.GL.clear(this.GL.DEPTH_BUFFER_BIT)}_getTempFramebuffer(){return this._tempFramebuffer||(this._tempFramebuffer=new eM(this,{format:s.av,useDepth:this._pInst._glAttributes.depth,depthFormat:s.au,antialias:this._pInst._glAttributes.antialias})),this._tempFramebuffer}geometryInHash(e){return this.geometryBufferCache.isCached(e)}viewport(e,t){this._viewport=[0,0,e,t],this.GL.viewport(0,0,e,t)}resize(e,t){super.resize(e,t);let i={};for(let e in this.drawingContext){let t=this.drawingContext[e];"object"!=typeof t&&"function"!=typeof t&&(i[e]=t)}let r=this._adjustDimensions(e,t);for(let i of(e=r.adjustedWidth,t=r.adjustedHeight,this.width=e,this.height=t,this.canvas.width=e*this._pixelDensity,this.canvas.height=t*this._pixelDensity,this.canvas.style.width=`${e}px`,this.canvas.style.height=`${t}px`,this._origViewport={width:this.GL.drawingBufferWidth,height:this.GL.drawingBufferHeight},this.viewport(this._origViewport.width,this._origViewport.height),this.states.curCamera._resize(),void 0!==this.pixels&&(this.pixels=new Uint8Array(this.GL.drawingBufferWidth*this.GL.drawingBufferHeight*4)),this.framebuffers))i._canvasSizeChanged();for(let e in i)try{this.drawingContext[e]=i[e]}catch(e){}}clear(...e){let t=e[0]||0,i=e[1]||0,r=e[2]||0,n=e[3]||0,a=this.activeFramebuffer();a&&a.format===s.av&&!a.antialias&&0===n&&(n=1e-10),this.GL.clearColor(t*n,i*n,r*n,n),this.GL.clearDepth(1),this.GL.clear(this.GL.COLOR_BUFFER_BIT|this.GL.DEPTH_BUFFER_BIT)}clearDepth(e=1){this.GL.clearDepth(e),this.GL.clear(this.GL.DEPTH_BUFFER_BIT)}applyMatrix(e,t,i,r,s,n){this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone()),16==arguments.length?C.uq.prototype.apply.apply(this.states.uModelMatrix,arguments):this.states.uModelMatrix.apply([e,t,0,0,i,r,0,0,0,0,1,0,s,n,0,1])}translate(e,t,i){return e instanceof b.M&&(i=e.z,t=e.y,e=e.x),this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone()),this.states.uModelMatrix.translate([e,t,i]),this}scale(e,t,i){return this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone()),this.states.uModelMatrix.scale(e,t,i),this}rotate(e,t){return void 0===t?this.rotateZ(e):(this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone()),C.uq.prototype.rotate4x4.apply(this.states.uModelMatrix,arguments),this)}rotateX(e){return this.rotate(e,1,0,0),this}rotateY(e){return this.rotate(e,0,1,0),this}rotateZ(e){return this.rotate(e,0,0,1),this}pop(...e){this._clipDepths.length>0&&this._pushPopDepth===this._clipDepths[this._clipDepths.length-1]&&(this._clearClip(),this._userEnabledStencil||this._internalDisable.call(this.GL,this.GL.STENCIL_TEST)),super.pop(...e),this._applyStencilTestIfClipping()}_applyStencilTestIfClipping(){let e=this.drawTarget();e._isClipApplied!==this._stencilTestOn&&(e._isClipApplied?(this._internalEnable.call(this.GL,this.GL.STENCIL_TEST),this._stencilTestOn=!0):(this._userEnabledStencil||this._internalDisable.call(this.GL,this.GL.STENCIL_TEST),this._stencilTestOn=!1))}resetMatrix(){return this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone()),this.states.uModelMatrix.reset(),this.states.setValue("uViewMatrix",this.states.uViewM
7atrix.clone()),this.states.uViewMatrix.set(this.states.curCamera.cameraMatrix),this}_getStrokeShader(){let e=this.states.userStrokeShader;return e||this._getLineShader()}_getSphereMapping(e){return this.sphereMapping||(this.sphereMapping=this._pInst.createFilterShader(ea)),this.scratchMat3.inverseTranspose4x4(this.states.uViewMatrix),this.scratchMat3.invert(this.scratchMat3),this.sphereMapping.setUniform("uFovY",this.states.curCamera.cameraFOV),this.sphereMapping.setUniform("uAspect",this.states.curCamera.aspectRatio),this.sphereMapping.setUniform("uNewNormalMatrix",this.scratchMat3.mat3),this.sphereMapping.setUniform("uEnvMap",e),this.sphereMapping}_getFillShader(){if(this._drawingImage)if(this.states.userImageShader&&!this._drawingFilter)return this.states.userImageShader;else return this._getLightShader();return this.states.userFillShader?this.states.userFillShader:this.states._useNormalMaterial?this._getNormalShader():this.states.enableLighting||this.states._tex?this._getLightShader():this._getColorShader()}_getPointShader(){let e=this.states.userPointShader;return e&&e.isPointShader()?e:this._getPointShader()}baseMaterialShader(){if(!this._pInst._glAttributes.perPixelLighting)throw Error("The material shader does not support hooks without perPixelLighting. Try turning it back on.");return this._getLightShader()}_getLightShader(){return this._defaultLightShader||(this._pInst._glAttributes.perPixelLighting?this._defaultLightShader=new k(this,this._webGL2CompatibilityPrefix("vert","highp")+en.phongVert,this._webGL2CompatibilityPrefix("frag","highp")+en.phongFrag,{vertex:{"void beforeVertex":"() {}","Vertex getObjectInputs":"(Vertex inputs) { return inputs; }","Vertex getWorldInputs":"(Vertex inputs) { return inputs; }","Vertex getCameraInputs":"(Vertex inputs) { return inputs; }","void afterVertex":"() {}"},fragment:{"void beforeFragment":"() {}","Inputs getPixelInputs":"(Inputs inputs) { return inputs; }","vec4 combineColors":`(ColorComponents components) { 8 vec4 color = vec4(0.); 9 color.rgb += components.diffuse * components.baseColor; 10 color.rgb += components.ambient * components.ambientColor; 11 color.rgb += components.specular * components.specularColor; 12 color.rgb += components.emissive; 13 color.a = components.opacity; 14 return color; 15 }`,"vec4 getFinalColor":"(vec4 color) { return color; }","void afterFragment":"() {}"}}):this._defaultLightShader=new k(this,this._webGL2CompatibilityPrefix("vert","highp")+en.lightVert,this._webGL2CompatibilityPrefix("frag","highp")+en.lightTextureFrag)),this._defaultLightShader}baseNormalShader(){return this._getNormalShader()}_getNormalShader(){return this._defaultNormalShader||(this._defaultNormalShader=new k(this,this._webGL2CompatibilityPrefix("vert","mediump")+en.normalVert,this._webGL2CompatibilityPrefix("frag","mediump")+en.normalFrag,{vertex:{"void beforeVertex":"() {}","Vertex getObjectInputs":"(Vertex inputs) { return inputs; }","Vertex getWorldInputs":"(Vertex inputs) { return inputs; }","Vertex getCameraInputs":"(Vertex inputs) { return inputs; }","void afterVertex":"() {}"},fragment:{"void beforeFragment":"() {}","vec4 getFinalColor":"(vec4 color) { return color; }","void afterFragment":"() {}"}})),this._defaultNormalShader}baseColorShader(){return this._getColorShader()}_getColorShader(){return this._defaultColorShader||(this._defaultColorShader=new k(this,this._webGL2CompatibilityPrefix("vert","mediump")+en.normalVert,this._webGL2CompatibilityPrefix("frag","mediump")+en.basicFrag,{vertex:{"void beforeVertex":"() {}","Vertex getObjectInputs":"(Vertex inputs) { return inputs; }","Vertex getWorldInputs":"(Vertex inputs) { return inputs; }","Vertex getCameraInputs":"(Vertex inputs) { return inputs; }","void afterVertex":"() {}"},fragment:{"void beforeFragment":"() {}","vec4 getFinalColor":"(vec4 color) { return color; }","void afterFragment":"() {}"}})),this._defaultColorShader}pointShader(){return this._getPointShader()}_getPointShader(){return this._defaultPointShader||(this._defaultPointShader=new k(this,this._webGL2CompatibilityPrefix("vert","mediump")+en.pointVert,this._webGL2CompatibilityPrefix("frag","mediump")+en.pointFrag,{vertex:{"void beforeVertex":"() {}","vec3 getLocalPosition":"(vec3 position) { return position; }","vec3 getWorldPosition":"(vec3 position) { return position; }","float getPointSize":"(float size) { return size; }","void afterVertex":"() {}"},fragment:{"void beforeFragment":"() {}","vec4 getFinalColor":"(vec4 color) { return color; }","bool shouldDiscard":"(bool outside) { return outside; }","void afterFragment":"() {}"}})),this._defaultPointShader}baseStrokeShader(){return this._getLineShader()}_getLineShader(){return this._defaultLineShader||(this._defaultLineShader=new k(this,this._webGL2CompatibilityPrefix("vert","mediump")+en.lineVert,this._webGL2CompatibilityPrefix("frag","mediump")+en.lineFrag,{vertex:{"void beforeVertex":"() {}
15","StrokeVertex getObjectInputs":"(StrokeVertex inputs) { return inputs; }","StrokeVertex getWorldInputs":"(StrokeVertex inputs) { return inputs; }","StrokeVertex getCameraInputs":"(StrokeVertex inputs) { return inputs; }","void afterVertex":"() {}"},fragment:{"void beforeFragment":"() {}","Inputs getPixelInputs":"(Inputs inputs) { return inputs; }","vec4 getFinalColor":"(vec4 color) { return color; }","bool shouldDiscard":"(bool outside) { return outside; }","void afterFragment":"() {}"}})),this._defaultLineShader}_getFontShader(){return this._defaultFontShader||(this.webglVersion===s.a0&&this.GL.getExtension("OES_standard_derivatives"),this._defaultFontShader=new k(this,this._webGL2CompatibilityPrefix("vert","highp")+en.fontVert,this._webGL2CompatibilityPrefix("frag","highp")+en.fontFrag)),this._defaultFontShader}baseFilterShader(){return this._baseFilterShader||(this._baseFilterShader=new k(this,this._webGL2CompatibilityPrefix("vert","highp")+en.filterBaseVert,this._webGL2CompatibilityPrefix("frag","highp")+en.filterBaseFrag,{vertex:{},fragment:{"vec4 getColor":`(FilterInputs inputs, in sampler2D canvasContent) { 16 return getTexture(canvasContent, inputs.texCoord); 17 }`}})),this._baseFilterShader}_webGL2CompatibilityPrefix(e,t){let i="";return this.webglVersion===s.z&&(i+="#version 300 es\n#define WEBGL2\n"),"vert"===e?i+="#define VERTEX_SHADER\n":"frag"===e&&(i+="#define FRAGMENT_SHADER\n"),t&&(i+=`precision ${t} float; 18`),i}_getEmptyTexture(){if(!this._emptyTexture){let e=new o.I(1,1);e.set(0,0,255),this._emptyTexture=new ev(this,e)}return this._emptyTexture}getTexture(e){let t=e;t instanceof eM&&(t=t.color);let i=this.textures.get(t);if(i)return i;let r=new ev(this,t);return this.textures.set(t,r),r}getDiffusedTexture(e){let t;if(null!=this.diffusedTextures.get(e))return this.diffusedTextures.get(e);let i=Math.floor(200*(e.height/e.width));return t=new eM(this,{width:200,height:i,density:1}),this.diffusedShader||(this.diffusedShader=this._pInst.createShader(en.imageLightVert,en.imageLightDiffusedFrag)),t.draw(()=>{this.shader(this.diffusedShader),this.diffusedShader.setUniform("environmentMap",e),this.states.setValue("strokeColor",null),this.noLights(),this.plane(200,i)}),this.diffusedTextures.set(e,t),t}getSpecularTexture(e){let t;if(null!=this.specularTextures.get(e))return this.specularTextures.get(e);let i=[],r=new eM(this,{width:512,height:512,density:1}),s=Math.log(512)/Math.log(2);this.specularShader||(this.specularShader=this._pInst.createShader(en.imageLightVert,en.imageLightSpecularFrag));for(let t=512;t>=1;t/=2){r.resize(t,t);let n=1-Math.log(t)/Math.log(2)/s;r.draw(()=>{this.shader(this.specularShader),this.clear(),this.specularShader.setUniform("environmentMap",e),this.specularShader.setUniform("roughness",n),this.states.setValue("strokeColor",null),this.noLights(),this.plane(t,t)}),i.push(r.get().drawingContext.getImageData(0,0,t,t))}return r.remove(),t=new ex(this,i,{}),this.specularTextures.set(e,t),t}activeFramebuffer(){return this.activeFramebuffers[this.activeFramebuffers.length-1]||null}createFramebuffer(e){return new eM(this,e)}_setGlobalUniforms(e){let t=this.states.uModelMatrix,i=this.states.uViewMatrix,r=this.states.uPMatrix,s=t.copy().mult(i);if(e.setUniform("uPerspective",+!!this.states.curCamera.useLinePerspective),e.setUniform("uViewMatrix",i.mat4),e.setUniform("uProjectionMatrix",r.mat4),e.setUniform("uModelMatrix",t.mat4),e.setUniform("uModelViewMatrix",s.mat4),e.uniforms.uModelViewProjectionMatrix){let t=s.copy();t.mult(r),e.setUniform("uModelViewProjectionMatrix",t.mat4)}e.uniforms.uNormalMatrix&&(this.scratchMat3.inverseTranspose4x4(s),e.setUniform("uNormalMatrix",this.scratchMat3.mat3)),e.uniforms.uModelNormalMatrix&&(this.scratchMat3.inverseTranspose4x4(this.states.uModelMatrix),e.setUniform("uModelNormalMatrix",this.scratchMat3.mat3)),e.uniforms.uCameraNormalMatrix&&(this.scratchMat3.inverseTranspose4x4(this.states.uViewMatrix),e.setUniform("uCameraNormalMatrix",this.scratchMat3.mat3)),e.uniforms.uCameraRotation&&(this.scratchMat3.inverseTranspose4x4(this.states.uViewM
18atrix),e.setUniform("uCameraRotation",this.scratchMat3.mat3)),e.setUniform("uViewport",this._viewport)}_setStrokeUniforms(e){e.setUniform("uSimpleLines",this._simpleLines),e.setUniform("uUseLineColor",this._useLineColor),e.setUniform("uMaterialColor",this.states.curStrokeColor),e.setUniform("uStrokeWeight",this.states.strokeWeight),e.setUniform("uStrokeCap",ee[this.curStrokeCap]),e.setUniform("uStrokeJoin",et[this.curStrokeJoin])}_setFillUniforms(e){this.mixedSpecularColor=[...this.states.curSpecularColor];let t=this._getEmptyTexture();this.states._useMetalness>0&&(this.mixedSpecularColor=this.mixedSpecularColor.map((e,t)=>this.states.curFillColor[t]*this.states._useMetalness+e*(1-this.states._useMetalness))),e.setUniform("uUseVertexColor",this._useVertexColor),e.setUniform("uMaterialColor",this.states.curFillColor),e.setUniform("isTexture",!!this.states._tex),e.setUniform("uSampler",this.states._tex||t),e.setUniform("uTint",this.states.tint),e.setUniform("uHasSetAmbient",this.states._hasSetAmbient),e.setUniform("uAmbientMatColor",this.states.curAmbientColor),e.setUniform("uSpecularMatColor",this.mixedSpecularColor),e.setUniform("uEmissiveMatColor",this.states.curEmissiveColor),e.setUniform("uSpecular",this.states._useSpecularMaterial),e.setUniform("uEmissive",this.states._useEmissiveMaterial),e.setUniform("uShininess",this.states._useShininess),e.setUniform("uMetallic",this.states._useMetalness),this._setImageLightUniforms(e),e.setUniform("uUseLighting",this.states.enableLighting);let i=this.states.pointLightDiffuseColors.length/3;e.setUniform("uPointLightCount",i),e.setUniform("uPointLightLocation",this.states.pointLightPositions),e.setUniform("uPointLightDiffuseColors",this.states.pointLightDiffuseColors),e.setUniform("uPointLightSpecularColors",this.states.pointLightSpecularColors);let r=this.states.directionalLightDiffuseColors.length/3;e.setUniform("uDirectionalLightCount",r),e.setUniform("uLightingDirection",this.states.directionalLightDirections),e.setUniform("uDirectionalDiffuseColors",this.states.directionalLightDiffuseColors),e.setUniform("uDirectionalSpecularColors",this.states.directionalLightSpecularColors);let s=this.states.ambientLightColors.length/3;this.mixedAmbientLight=[...this.states.ambientLightColors],this.states._useMetalness>0&&(this.mixedAmbientLight=this.mixedAmbientLight.map(e=>Math.max(0,e-this.states._useMetalness))),e.setUniform("uAmbientLightCount",s),e.setUniform("uAmbientColor",this.mixedAmbientLight);let n=this.states.spotLightDiffuseColors.length/3;e.setUniform("uSpotLightCount",n),e.setUniform("uSpotLightAngle",this.states.spotLightAngle),e.setUniform("uSpotLightConc",this.states.spotLightConc),e.setUniform("uSpotLightDiffuseColors",this.states.spotLightDiffuseColors),e.setUniform("uSpotLightSpecularColors",this.states.spotLightSpecularColors),e.setUniform("uSpotLightLocation",this.states.spotLightPositions),e.setUniform("uSpotLightDirection",this.states.spotLightDirections),e.setUniform("uConstantAttenuation",this.states.constantAttenuation),e.setUniform("uLinearAttenuation",this.states.linearAttenuation),e.setUniform("uQuadraticAttenuation",this.states.quadraticAttenuation)}_setImageLightUniforms(e){if(e.setUniform("uUseImageLight",null!=this.states.activeImageLight),this.states.activeImageLight){let t=this.getDiffusedTexture(this.states.activeImageLight);e.setUniform("environmentMapDiffused",t);let i=this.getSpecularTexture(this.states.activeImageLight);e.setUniform("environmentMapSpecular",i)}}_setPointUniforms(e){e.setUniform("uMaterialColor",this.states.curStrokeColor),e.setUniform("uPointSize",this.states.strokeWeight*this._pixelDensity)}_bindBuffer(e,t,i,r,s){if(t||(t=this.GL.ARRAY_BUFFER),this.GL.bindBuffer(t,e),void 0!==i){let e=i;i instanceof T.U?e=i.dataArray():e instanceof(r||Float32Array)||(e=new(r||Float32Array)(e)),this.GL.bufferData(t,e,s||this.GL.STATIC_DRAW)}}_arraysEqual(e,t){return e.length===t.length&&e.every((e,i)=>e===t[i])}_isTypedArray(e){return[Float32Array,Float64Array,Int16Array,Uint16Array,Uint32Array].some(t=>e instanceof t)}_vToNArray(e){return e.flatMap(e=>[e.x,e.y,e.z])}}function el(e,t){e.RendererGL=eh,t.setAttributes=function(t,i){if(void 0===this._glAttributes)return void console.log("You are trying to use setAttributes on a p5.Graphics object that does not use a WEBGL renderer.");let r=!0;if(void 0!==i?(null===this._glAttributes&&(this._glAttributes={}),this._glAttributes[t]!==i&&(this._glAttributes[t]=i,r=!1)):t instanceof Object&&this._glAttributes!==t&&(this._glAttributes=t,r=!1),this._renderer.isP3D&&!r){if(!this._setupDone&&this._renderer.geometryBufferCache.numCached()>0)return void e._friendlyError("Sorry, Could not set the attributes, you need to call setAttributes() before calling the other drawing methods in setup()");this._renderer._resetContext(),this._renderer.states.curCamera&&(this._renderer.states.curCamera._renderer=this._renderer)}},t._assert3d=function(e){if(!this._renderer.isP3D)throw Error(`${e}() is only supported in WEBGL mode. If you'd like to use 3D graphics and WebGL, see https://p5js.org/examples/form-3d-primitives.html for more information.`)},e.renderers[s.a0]=e.RendererGL,e.renderers[s.z]=e.RendererGL}function eu(e,t,i,r,s,n,a,o,h,l){let u=t.getParameter(t.FRAMEBUFFER_BINDING);t.bindFramebuffer(t.FRAMEBUFFER,i);let c=o===t.RGBA?4:3,d=n*a*c,f=h===t.UNSIGNED_BYTE?Uint8Array:Float32Array;
18if(e instanceof f&&e.length===d||(e=new f(d)),t.readPixels(r,l?l-s-a:s,n,a,o,h,e),t.bindFramebuffer(t.FRAMEBUFFER,u),l){let t=Math.floor(a/2),i=new f(n*c);for(let r=0;r<t;r++){let t=r*n*4,s=(a-r-1)*n*4;i.set(e.subarray(t,t+4*n)),e.copyWithin(t,s,s+4*n),e.set(i,s)}}return e}function ec(e,t,i,r,s,n,a){let o=e.getParameter(e.FRAMEBUFFER_BINDING);e.bindFramebuffer(e.FRAMEBUFFER,t);let h=s===e.RGBA?4:3,l=new(n===e.UNSIGNED_BYTE?Uint8Array:Float32Array)(h);return e.readPixels(i,a?a-r-1:r,1,1,s,n,l),e.bindFramebuffer(e.FRAMEBUFFER,o),Array.from(l)}function ed(e,t){t.strokeMode=function(e){if(void 0===e)return this._renderer._simpleLines?s.aw:s.ax;if(e===s.aw)this._renderer._simpleLines=!0;else if(e===s.ax)this._renderer._simpleLines=!1;else throw Error("no such parameter")},t.buildGeometry=function(e){return this._renderer.buildGeometry(e)},t.freeGeometry=function(e){this._renderer.geometryBufferCache.freeBuffers(e.gid)},t.plane=function(e=50,t=e,i=1,r=1){return this._assert3d("plane"),this._renderer.plane(e,t,i,r),this},t.box=function(e,t,i,r,s){return this._assert3d("box"),this._renderer.box(e,t,i,r,s),this},t.sphere=function(e=50,t=24,i=16){return this._assert3d("sphere"),this._renderer.sphere(e,t,i),this},t.cylinder=function(e=50,t=e,i=24,r=1,s=!0,n=!0){return this._assert3d("cylinder"),this._renderer.cylinder(e,t,i,r,s,n),this},t.cone=function(e=50,t=e,i=24,r=1,s=!0){return this._assert3d("cone"),this._renderer.cone(e,t,i,r,s),this},t.ellipsoid=function(e=50,t=e,i=e,r=24,s=16){return this._assert3d("ellipsoid"),this._renderer.ellipsoid(e,t,i,r,s),this},t.torus=function(e,t,i,r){return this._assert3d("torus"),this._renderer.torus(e,t,i,r),this},eh.prototype.point=function(e,t,i=0){let r=[];return r.push(new b.M(e,t,i)),this._drawPoints(r,this.buffers.point),this},eh.prototype.triangle=function(e){let t=e[0],i=e[1],r=e[2],s=e[3],n=e[4],a=e[5];if(!this.geometryInHash("tri")){let e=new I.V(1,1,function(){let e=[];e.push(new b.M(0,0,0)),e.push(new b.M(1,0,0)),e.push(new b.M(0,1,0)),this.edges=[[0,1],[1,2],[2,0]],this.vertices=e,this.faces=[[0,1,2]],this.uvs=[0,0,1,0,1,1]},this);e._edgesToVertices(),e.computeNormals(),e.gid="tri",this.geometryBufferCache.ensureCached(e)}let o=this.states.uModelMatrix.copy();try{let e=Math.sign(t*s-r*i+r*a-n*s+n*i-t*a),o=new C.uq([r-t,s-i,0,0,n-t,a-i,0,0,0,0,e,0,t,i,0,1]).mult(this.states.uModelMatrix);this.states.setValue("uModelMatrix",o),this.model(this.geometryBufferCache.getGeometryByID("tri"))}finally{this.states.setValue("uModelMatrix",o)}return this},eh.prototype.ellipse=function(e){this.arc(e[0],e[1],e[2],e[3],0,s.f,s.O,e[4])},eh.prototype.arc=function(...e){let t,i,r=e[0],n=e[1],a=e[2],o=e[3],h=e[4],l=e[5],u=e[6],c=e[7]||25;if(Math.abs(l-h)>=s.f?(t="ellipse",i=`${t}|${c}|`):(t="arc",i=`${t}|${h}|${l}|${u}|${c}|`),!this.geometryInHash(i)){let e=new I.V(c,1,function(){if(h.toFixed(10)!==l.toFixed(10)){(u===s.aj||void 0===u)&&(this.vertices.push(new b.M(.5,.5,0)),this.uvs.push([.5,.5]));for(let e=0;e<=c;e++){let t=e/c*(l-h)+h,i=.5+Math.cos(t)/2,r=.5+Math.sin(t)/2;this.vertices.push(new b.M(i,r,0)),this.uvs.push([i,r]),e<c-1&&(this.faces.push([0,e+1,e+2]),this.edges.push([e+1,e+2]))}switch(u){case s.aj:this.faces.push([0,this.vertices.length-2,this.vertices.length-1]),this.edges.push([0,1]),this.edges.push([this.vertices.length-2,this.vertices.length-1]),this.edges.push([0,this.vertices.length-1]);break;case s.ak:this.edges.push([0,1]),this.edges.push([0,this.vertices.length-1]);break;case s.O:this.edges.push([0,1]);break;default:this.faces.push([0,this.vertices.length-2,this.vertices.length-1]),this.edges.push([this.vertices.length-2,this.vertices.length-1])}}},this);e.computeNormals(),c<=50?e._edgesToVertices(e):this.states.strokeColor&&console.log(`Cannot apply a stroke to an ${t} with more than 50 detail`),e.gid=i,this.geometryBufferCache.ensureCached(e)}let d=this.states.uModelMatrix;this.states.setValue("uModelMatrix",this.states.uModelMatrix.clone());try{this.states.uModelMatrix.translate([r,n,0]),this.states.uModelMatrix.scale(a,o,1),this.model(this.geometryBufferCache.getGeometryByID(i))}finally{this.states.setValue("uModelMatrix",d)}return this},eh.prototype.rect=function(e){let t=e[0],i=e[1],r=e[2],n=e[3];
18if(void 0===e[4]){let s=this._pInst._glAttributes.perPixelLighting,a=e[4]||(s?1:24),o=e[5]||(s?1:16),h=`rect|${a}|${o}`;if(!this.geometryInHash(h)){let e=new I.V(a,o,function(){for(let e=0;e<=this.detailY;e++){let t=e/this.detailY;for(let e=0;e<=this.detailX;e++){let i=e/this.detailX,r=new b.M(i,t,0);this.vertices.push(r),this.uvs.push(i,t)}}a>0&&o>0&&(this.edges=[[0,a],[a,(a+1)*(o+1)-1],[(a+1)*(o+1)-1,(a+1)*o],[(a+1)*o,0]])},this);e.computeFaces().computeNormals()._edgesToVertices(),e.gid=h,this.geometryBufferCache.ensureCached(e)}let l=this.states.uModelMatrix;this.states.setValue("uModelMatrix",this.states.uModelMatrix.copy());try{this.states.uModelMatrix.translate([t,i,0]),this.states.uModelMatrix.scale(r,n,1),this.model(this.geometryBufferCache.getGeometryByID(h))}finally{this.states.setValue("uModelMatrix",l)}}else{let a=e[4],o=void 0===e[5]?a:e[5],h=void 0===e[6]?o:e[6],l=void 0===e[7]?h:e[7],u=t,c=i,d=r,f=n;if(d+=u,f+=c,u>d){let e=u;u=d,d=e}if(c>f){let e=c;c=f,f=e}let p=Math.min((d-u)/2,(f-c)/2);a>p&&(a=p),o>p&&(o=p),h>p&&(h=p),l>p&&(l=p);let m=u,g=c,v=d,x=f,_=this.states.textureMode;this.states.setValue("textureMode",s.N);let y=this.bezierOrder();this.bezierOrder(2),this.beginShape();let b=(e,t)=>[e,t,0,(e-m)/r,(t-g)/n];0!==o?(this.vertex(...b(v-o,g)),this.bezierVertex(...b(v,g)),this.bezierVertex(...b(v,g+o))):this.vertex(...b(v,g)),0!==h?(this.vertex(...b(v,x-h)),this.bezierVertex(...b(v,x)),this.bezierVertex(...b(v-h,x))):this.vertex(...b(v,x)),0!==l?(this.vertex(...b(m+l,x)),this.bezierVertex(...b(m,x)),this.bezierVertex(...b(m,x-l))):this.vertex(...b(m,x)),0!==a?(this.vertex(...b(m,g+a)),this.bezierVertex(...b(m,g)),this.bezierVertex(...b(m+a,g))):this.vertex(...b(m,g)),this.endShape(s.n),this.states.setValue("textureMode",_),this.bezierOrder(y)}return this},eh.prototype.quad=function(e,t,i,r,s,n,a,o,h,l,u,c,d=2,f=2){let p=`quad|${e}|${t}|${i}|${r}|${s}|${n}|${a}|${o}|${h}|${l}|${u}|${c}|${d}|${f}`;if(!this.geometryInHash(p)){let m=new I.V(d,f,function(){let d=1/(this.detailX-1),f=1/(this.detailY-1);for(let p=0;p<this.detailY;p++)for(let m=0;m<this.detailX;m++){let g=m*d,v=p*f,x=(1-v)*e+v*l,_=(1-v)*t+v*u,y=(1-v)*i+v*c,w=(1-g)*x+g*((1-v)*r+v*a),C=(1-g)*_+g*((1-v)*s+v*o),M=(1-g)*y+g*((1-v)*n+v*h);this.vertices.push(new b.M(w,C,M)),this.uvs.push([g,v])}},this);m.faces=[];for(let e=0;e<f-1;e++)for(let t=0;t<d-1;t++){let i=t+e*d,r=t+1+e*d,s=t+1+(e+1)*d,n=t+(e+1)*d;m.faces.push([i,r,s]),m.faces.push([i,s,n])}m.computeNormals(),m.edges.length=0;let g=[0,2,3,1];for(let e=0;e<g.length;e++){let t=g[e],i=g[(e+1)%g.length];m.edges.push([t,i])}m._edgesToVertices(),m.gid=p,this.geometryBufferCache.ensureCached(m)}return this.model(this.geometryBufferCache.getGeometryByID(p)),this},eh.prototype.bezier=function(e,t,i,r,s,n,a,o,h,l,u,c){8==arguments.length&&(u=o,l=a,o=n,a=s,s=r,r=i,i=n=h=c=0),this.bezierOrder(),this.bezierOrder(3),this.beginShape(),this.vertex(e,t,i),this.bezierVertex(r,s,n),this.bezierVertex(a,o,h),this.bezierVertex(l,u,c),this.endShape()},eh.prototype.curve=function(e,t,i,r,s,n,a,o,h,l,u,c){8==arguments.length&&(l=a,u=o,a=s,o=r,s=r=i,i=n=h=c=0),this.beginShape(),this.splineVertex(e,t,i),this.splineVertex(r,s,n),this.splineVertex(a,o,h),this.splineVertex(l,u,c),this.endShape()},eh.prototype.line=function(...e){return 6===e.length?(this.beginShape(s.L),this.vertex(e[0],e[1],e[2]),this.vertex(e[3],e[4],e[5]),this.endShape()):4===e.length&&(this.beginShape(s.L),this.vertex(e[0],e[1],0),this.vertex(e[2],e[3],0),this.endShape()),this},eh.prototype.image=function(e,t,i,r,n,a,o,h,l){this._isErasing&&this.blendMode(this._cachedBlendMode),this.push(),this.noLights(),this.states.setValue("strokeColor",null),this.texture(e),this.states.setValue("textureMode",s.N);let u=0;t<=e.width&&(u=t/e.width);let c=1;t+r<=e.width&&(c=(t+r)/e.width);let d=0;i<=e.height&&(d=i/e.height);let f=1;i+n<=e.height&&(f=(i+n)/e.height),this._drawingImage=!0,this.beginShape(),this.vertex(a,o,0,u,d),this.vertex(a+h,o,0,c,d),this.vertex(a+h,o+l,0,c,f),this.vertex(a,o+l,0,u,f),this.endShape(s.n),this._drawingImage=!1,this.pop(),this._isErasing&&this.blendMode(s.a4)};let i=function(e,t,i,r,s,n,a){let o,h,l;e=e<=0?1:e,t=t<0?0:t,i=i<=0?e:i,r=r<3?3:r;let u=(n=void 0===n||n)?-2:0,c=(s=s<1?1:s)+2*!!(a=void 0===a?0!==t:a),d=Math.atan2(e-t,i),f=Math.sin(d),p=Math.cos(d);for(o=u;o<=c;++o){let n,a=o/s,l=i*a;for(o<0?(l=0,a=0,n=e):o>s?(l=i,a=1,n=t):n=e+(t-e)*a,(-2===o||o===s+2)&&(n=0),l-=i/2,h=0;h<r;++h){let e,i=h/(r-1),u=2*Math.PI*i,c=Math.sin(u),d=Math.cos(u);this.vertices.push(new b.M(c*n,l,d*n)),e=o<0?new b.M(0,-1,0):o>s&&t?new b.M(0,1,0):new b.M(c*p,f,d*p),this.vertexNormals.push(e),this.uvs.push(i,a)}}let m=0;if(n){for(l=0;l<r;++l){let e=(l+1)%r;this.faces.push([m+l,m+r+e,m+r+l])}m+=2*r}for(o=0;o<s;++o){for(h=0;h<r;++h){let e=(h+1)%r;this.faces.push([m+h,m+e,m+r+e]),this.faces.push([m+h,m+r+e,m+r+h])}m+=r}if(a)for(m+=r,h=0;h<r;++h)this.faces.push([m+h,m+(h+1)%r,m+r])};
18eh.prototype.plane=function(e=50,t=e,i=1,r=1){let s=`plane|${i}|${r}`;if(!this.geometryInHash(s)){let e=new I.V(i,r,function(){let e,t,i;for(let r=0;r<=this.detailY;r++){t=r/this.detailY;for(let r=0;r<=this.detailX;r++)e=r/this.detailX,i=new b.M(e-.5,t-.5,0),this.vertices.push(i),this.uvs.push(e,t)}},this);e.computeFaces().computeNormals(),i<=1&&r<=1?e._makeTriangleEdges()._edgesToVertices():this.states.strokeColor&&console.log("Cannot draw stroke on plane objects with more than 1 detailX or 1 detailY"),e.gid=s,this.geometryBufferCache.ensureCached(e)}this._drawGeometryScaled(this.geometryBufferCache.getGeometryByID(s),e,t,1)},eh.prototype.box=function(e=50,t=e,i=t,r,s){let n=this.attributes&&this.attributes.perPixelLighting;void 0===r&&(r=n?1:4),void 0===s&&(s=n?1:4);let a=`box|${r}|${s}`;if(!this.geometryInHash(a)){let e=new I.V(r,s,function(){this.edges=[[0,1],[1,3],[3,2],[6,7],[8,9],[9,11],[14,15],[16,17],[17,19],[18,19],[20,21],[22,23]],[[0,4,2,6],[1,3,5,7],[0,1,4,5],[2,6,3,7],[0,2,1,3],[4,5,6,7]].forEach((e,t)=>{let i=4*t;for(let t=0;t<4;t++){let i=e[t],r=new b.M(((1&i)*2-1)/2,((2&i)-1)/2,((4&i)/2-1)/2);this.vertices.push(r),this.uvs.push(1&t,(2&t)/2)}this.faces.push([i,i+1,i+2]),this.faces.push([i+2,i+1,i+3])})},this);e.computeNormals(),r<=4&&s<=4?e._edgesToVertices():this.states.strokeColor&&console.log("Cannot draw stroke on box objects with more than 4 detailX or 4 detailY"),e.gid=a,this.geometryBufferCache.ensureCached(e)}this._drawGeometryScaled(this.geometryBufferCache.getGeometryByID(a),e,t,i)},eh.prototype.sphere=function(e=50,t=24,i=16){this.ellipsoid(e,e,e,t,i)},eh.prototype.ellipsoid=function(t=50,i=t,r=t,s=24,n=16){let a=`ellipsoid|${s}|${n}`;if(!this.geometryInHash(a)){let t=new I.V(s,n,function(){for(let t=0;t<=this.detailY;t++){let i=t/this.detailY,r=Math.PI*i-Math.PI/2,s=Math.cos(r),n=Math.sin(r);for(let t=0;t<=this.detailX;t++){let r=t/this.detailX,a=2*Math.PI*r,o=Math.cos(a),h=Math.sin(a),l=new e.Vector(s*h,n,s*o);this.vertices.push(l),this.vertexNormals.push(l),this.uvs.push(r,i)}}},this);t.computeFaces(),s<=24&&n<=24?t._makeTriangleEdges()._edgesToVertices():this.states.strokeColor&&console.log("Cannot draw stroke on ellipsoids with more than 24 detailX or 24 detailY"),t.gid=a,this.geometryBufferCache.ensureCached(t)}this._drawGeometryScaled(this.geometryBufferCache.getGeometryByID(a),t,i,r)},eh.prototype.cylinder=function(t=50,r=t,s=24,n=1,a=!0,o=!0){let h=`cylinder|${s}|${n}|${a}|${o}`;if(!this.geometryInHash(h)){let t=new e.Geometry(s,n,function(){i.call(this,1,1,1,s,n,a,o)},this);s<=24&&n<=16?t._makeTriangleEdges()._edgesToVertices():this.states.strokeColor&&console.log("Cannot draw stroke on cylinder objects with more than 24 detailX or 16 detailY"),t.gid=h,this.geometryBufferCache.ensureCached(t)}this._drawGeometryScaled(this.geometryBufferCache.getGeometryByID(h),t,r,t)},eh.prototype.cone=function(e=50,t=e,r=24,s=1,n=!0){let a=`cone|${r}|${s}|${n}`;if(!this.geometryInHash(a)){let e=new I.V(r,s,function(){i.call(this,1,0,1,r,s,n,!1)},this);r<=24&&s<=16?e._makeTriangleEdges()._edgesToVertices():this.states.strokeColor&&console.log("Cannot draw stroke on cone objects with more than 24 detailX or 16 detailY"),e.gid=a,this.geometryBufferCache.ensureCached(e)}this._drawGeometryScaled(this.geometryBufferCache.getGeometryByID(a),e,t,e)},eh.prototype.torus=function(e=50,t=10,i=24,r=16){if(0===e||0===t)return;let s=(t/e).toPrecision(4),n=`torus|${s}|${i}|${r}`;if(!this.geometryInHash(n)){let e=new I.V(i,r,function(){for(let e=0;e<=this.detailY;e++){let t=e/this.detailY,i=2*Math.PI*t,r=Math.cos(i),n=Math.sin(i),a=1+s*r;for(let e=0;e<=this.detailX;e++){let i=e/this.detailX,o=2*Math.PI*i,h=Math.cos(o),l=Math.sin(o),u=new b.M(a*h,a*l,s*n),c=new b.M(r*h,r*l,n);this.vertices.push(u),this.vertexNormals.push(c),this.uvs.push(i,t)}}},this);e.computeFaces(),i<=24&&r<=16?e._makeTriangleEdges()._edgesToVertices():this.states.strokeColor&&console.log("Cannot draw strokes on torus object with more than 24 detailX or 16 detailY"),e.gid=n,this.geometryBufferCache.ensureCached(e)}this._drawGeometryScaled(this.geometryBufferCache.getGeometryByID(n),e,e,e)},t.curveDetail=function(e){if(!(this._renderer instanceof eh))throw Error("curveDetail() only w
18orks in WebGL mode. Did you mean to call createCanvas(width, height, WEBGL)?");return this._renderer.curveDetail(e)}}function ef(e,t){t.ambientLight=function(e,t,i,r){return this._assert3d("ambientLight"),this._renderer.ambientLight(...arguments),this},t.specularColor=function(e,t,i){return this._assert3d("specularColor"),this._renderer.specularColor(...arguments),this},t.directionalLight=function(e,t,i,r,s,n){return this._assert3d("directionalLight"),this._renderer.directionalLight(...arguments),this},t.pointLight=function(e,t,i,r,s,n){return this._assert3d("pointLight"),this._renderer.pointLight(...arguments),this},t.imageLight=function(e){this._renderer.imageLight(e)},t.panorama=function(e){this.filter(this._renderer._getSphereMapping(e))},t.lights=function(){return this._assert3d("lights"),this._renderer.lights(),this},t.lightFalloff=function(e,t,i){return this._assert3d("lightFalloff"),this._renderer.lightFalloff(e,t,i),this},t.spotLight=function(e,t,i,r,s,n,a,o,h,l,u){return this._assert3d("spotLight"),this._renderer.spotLight(...arguments),this},t.noLights=function(){return this._assert3d("noLights"),this._renderer.noLights(),this},eh.prototype.ambientLight=function(e,t,i,r){let s=this._pInst.color(...arguments);this.states.setValue("ambientLightColors",[...this.states.ambientLightColors]),this.states.ambientLightColors.push(s._array[0],s._array[1],s._array[2]),this.states.setValue("enableLighting",!0)},eh.prototype.specularColor=function(e,t,i){let r=this._pInst.color(...arguments);this.states.setValue("specularColors",[r._array[0],r._array[1],r._array[2]])},eh.prototype.directionalLight=function(e,t,i,r,s,a){let o,h,l,u;o=e instanceof n.C?e:this._pInst.color(e,t,i);let c=arguments[arguments.length-1];"number"==typeof c?(h=arguments[arguments.length-3],l=arguments[arguments.length-2],u=arguments[arguments.length-1]):(h=c.x,l=c.y,u=c.z);let d=Math.sqrt(h*h+l*l+u*u);this.states.setValue("directionalLightDirections",[...this.states.directionalLightDirections]),this.states.directionalLightDirections.push(h/d,l/d,u/d),this.states.setValue("directionalLightDiffuseColors",[...this.states.directionalLightDiffuseColors]),this.states.directionalLightDiffuseColors.push(o._array[0],o._array[1],o._array[2]),this.states.setValue("directionalLightSpecularColors",[...this.states.directionalLightSpecularColors]),Array.prototype.push.apply(this.states.directionalLightSpecularColors,this.states.specularColors),this.states.setValue("enableLighting",!0)},eh.prototype.pointLight=function(e,t,i,r,s,a){let o,h,l,u;o=e instanceof n.C?e:this._pInst.color(e,t,i);let c=arguments[arguments.length-1];"number"==typeof c?(h=arguments[arguments.length-3],l=arguments[arguments.length-2],u=arguments[arguments.length-1]):(h=c.x,l=c.y,u=c.z),this.states.setValue("pointLightPositions",[...this.states.pointLightPositions]),this.states.pointLightPositions.push(h,l,u),this.states.setValue("pointLightDiffuseColors",[...this.states.pointLightDiffuseColors]),this.states.pointLightDiffuseColors.push(o._array[0],o._array[1],o._array[2]),this.states.setValue("pointLightSpecularColors",[...this.states.pointLightSpecularColors]),Array.prototype.push.apply(this.states.pointLightSpecularColors,this.states.specularColors),this.states.setValue("enableLighting",!0)},eh.prototype.imageLight=function(e){this.states.setValue("activeImageLight",e),this.states.setValue("enableLighting",!0)},eh.prototype.lights=function(){let e=this._pInst.color("rgb(128,128,128)");this.ambientLight(e),this.directionalLight(e,0,0,-1)},eh.prototype.lightFalloff=function(e,t,i){e<0&&(e=0,console.warn("Value of constant argument in lightFalloff() should be never be negative. Set to 0.")),t<0&&(t=0,console.warn("Value of linear argument in lightFalloff() should be never be negative. Set to 0.")),i<0&&(i=0,console.warn("Value of quadratic argument in lightFalloff() should be never be negative. Set to 0.")),0===e&&0===t&&0===i&&(e=1,console.warn("Either one of the three arguments in lightFalloff() should be greater than zero. Set constant argument to 1.")),this.states.setValue("constantAttenuation",e),this.states.setValue("linearAttenuation",t),this.states.setValue("quadraticAttenuation",i)},eh.prototype.spotLight=function(e,t,i,r,s,a,o,h,l,u,c){let d,f,p,m=arguments.length;switch(m){case 11:case 10:d=this._pInst.color(e,t,i),f=new b.M(r,s,a),p=new b.M(o,h,l);break;case 9:e instanceof n.C?(d=e,f=new b.M(t,i,r),p=new b.M(s,a,o),u=h,c=l):r instanceof b.M?(d=this._pInst.color(e,t,i),f=r,p=new b.M(s,a,o),u=h,c=l):o instanceof b.M?(d=this._pInst.color(e,t,i),f=new b.M(r,s,a),p=o,u=h,c=l):(d=this._pInst.color(e,t,i),f=new b.M(r,s,a),p=new b.M(o,h,l));break;case 8:e instanceof n.C?(d=e,f=new b.M(t,i,r),p=new b.M(s,a,o)):r instanceof b.M?(d=this._pInst.color(e,t,i),f=r,p=new b.M(s,a,o)):(d=this._pInst.color(e,t,i),f=new b.M(r,s,a),p=o),u=h;break;case 7:e instanceof n.C&&t instanceof b.M?(d=e,f=t,p=new b.M(i,r,s),u=a,c=o):e instanceof n.C&&s instanceof b.M?(d=e,f=new b.M(t,i,r),p=s,u=a,c=o):r instanceof b.M&&s instanceof b.M?(d=this._pInst.color(e,t,i),f=r,p=s,u=a,c=o):e instanceof n.C?(d=e,f=new b.M(t,i,r),p=new b.M(s,a,o)):r instanceof b.M?(d=this._pInst.color(e,t,i),f=r,p=new b.M(s,a,o)):(d=this._pInst.color(e,t,i),f=new b.M(r,s,a),p=o);break;case 6:r instanceof b.M&&s instanceof b.M?(d=this._pInst.color(e,t,i),f=r,p=s,u=a):e instanceof n.C&&s instanceof b.M?(d=e,f=new b.M(t,i,r),p=s,u=a
18):e instanceof n.C&&t instanceof b.M&&(d=e,f=t,p=new b.M(i,r,s),u=a);break;case 5:e instanceof n.C&&t instanceof b.M&&i instanceof b.M?(d=e,f=t,p=i,u=r,c=s):r instanceof b.M&&s instanceof b.M?(d=this._pInst.color(e,t,i),f=r,p=s):e instanceof n.C&&s instanceof b.M?(d=e,f=new b.M(t,i,r),p=s):e instanceof n.C&&t instanceof b.M&&(d=e,f=t,p=new b.M(i,r,s));break;case 4:d=e,f=t,p=i,u=r;break;case 3:d=e,f=t,p=i;break;default:console.warn(`Sorry, input for spotlight() is not in prescribed format. Too ${m<3?"few":"many"} arguments were provided`);return}this.states.setValue("spotLightDiffuseColors",[d._array[0],d._array[1],d._array[2]]),this.states.setValue("spotLightSpecularColors",[...this.states.specularColors]),this.states.setValue("spotLightPositions",[f.x,f.y,f.z]),p.normalize(),this.states.setValue("spotLightDirections",[p.x,p.y,p.z]),void 0===u&&(u=Math.PI/3),void 0!==c&&c<1?(c=1,console.warn("Value of concentration needs to be greater than 1. Setting it to 1")):void 0===c&&(c=100),u=this._pInst._toRadians(u),this.states.setValue("spotLightAngle",[Math.cos(u)]),this.states.setValue("spotLightConc",[c]),this.states.setValue("enableLighting",!0)},eh.prototype.noLights=function(){this.states.setValue("activeImageLight",null),this.states.setValue("enableLighting",!1),this.states.setValue("ambientLightColors",[]),this.states.setValue("specularColors",[1,1,1]),this.states.setValue("directionalLightDirections",[]),this.states.setValue("directionalLightDiffuseColors",[]),this.states.setValue("directionalLightSpecularColors",[]),this.states.setValue("pointLightPositions",[]),this.states.setValue("pointLightDiffuseColors",[]),this.states.setValue("pointLightSpecularColors",[]),this.states.setValue("spotLightPositions",[]),this.states.setValue("spotLightDirections",[]),this.states.setValue("spotLightDiffuseColors",[]),this.states.setValue("spotLightSpecularColors",[]),this.states.setValue("spotLightAngle",[]),this.states.setValue("spotLightConc",[]),this.states.setValue("constantAttenuation",1),this.states.setValue("linearAttenuation",0),this.states.setValue("quadraticAttenuation",0),this.states.setValue("_useShininess",1),this.states.setValue("_useMetalness",0)}}function ep(e,t){t.loadShader=async function(e,t,i,r){let s=new k;try{if(s._vertSrc=(await V(e,"text")).data,s._fragSrc=(await V(t,"text")).data,i)return i(s);return s}catch(e){if(r)return r(e);throw e}},t.createShader=function(e,t,i){return new k(this._renderer,e,t,i)},t.loadFilterShader=async function(e,t,i){try{let i=await this.loadStrings(e),r=await i.join("\n"),s=this.createFilterShader(r,!0);return t&&t(s),s}catch(e){i?i(e):console.error(e)}},t.createFilterShader=function(e,t=!1){let i=` 19 uniform mat4 uModelViewMatrix; 20 uniform mat4 uProjectionMatrix; 21 22 attribute vec3 aPosition; 23 // texcoords only come from p5 to vertex shader 24 // so pass texcoords on to the fragment shader in a varying variable 25 attribute vec2 aTexCoord; 26 varying vec2 vTexCoord; 27 28 void main() { 29 // transferring texcoords for the frag shader 30 vTexCoord = aTexCoord; 31 32 // copy position with a fourth coordinate for projection (1.0 is normal)
33 vec4 positionVec4 = vec4(aPosition, 1.0); 34 35 // project to 3D space 36 gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4; 37 } 38 `,r=`#version 300 es 39 uniform mat4 uModelViewMatrix; 40 uniform mat4 uProjectionMatrix; 41 42 in vec3 aPosition; 43 in vec2 aTexCoord; 44 out vec2 vTexCoord; 45 46 void main() { 47 // transferring texcoords for the frag shader 48 vTexCoord = aTexCoord; 49 50 // copy position with a fourth coordinate for projection (1.0 is normal) 51 vec4 positionVec4 = vec4(aPosition, 1.0); 52 53 // project to 3D space 54 gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4; 55 } 56 `,s=e.includes("#version 300 es")?r:i,n=new k(this._renderer,s,e);return t||(this._renderer.GL?n.ensureCompiledOnContext(this._renderer):n.ensureCompiledOnContext(this)),n},t.shader=function(e){return this._assert3d("shader"),this._renderer.shader(e),this},t.strokeShader=function(e){return this._assert3d("strokeShader"),this._renderer.strokeShader(e),this},t.imageShader=function(e){return this._assert3d("imageShader"),this._renderer.imageShader(e),this},t.baseMaterialShader=function(){return this._assert3d("baseMaterialShader"),this._renderer.baseMaterialShader()},t.baseFilterShader=function(){return(this._renderer.filterRenderer||this._renderer).baseFilterShader()},t.baseNormalShader=function(){return this._assert3d("baseNormalShader"),this._renderer.baseNormalShader()},t.baseColorShader=function(){return this._assert3d("baseColorShader"),this._renderer.baseColorShader()},t.baseStrokeShader=function(){return this._assert3d("baseStrokeShader"),this._renderer.baseStrokeShader()},t.resetShader=function(){return this._renderer.resetShader(),this},t.texture=function(e){return this._assert3d("texture"),e.gifProperties&&e._animateGif(this),this._renderer.texture(e),this},t.textureMode=function(e){e!==s.a1&&e!==s.N?console.warn(`You tried to set ${e} textureMode only supports IMAGE & NORMAL `):this._renderer.states.setValue("textureMode",e)},t.textureWrap=function(e,t=e){for(let i of(this._renderer.states.setValue("textureWrapX",e),this._renderer.states.setValue("textureWrapY",t),this._renderer.textures.values()))i.setWrapMode(e,t)},t.normalMaterial=function(...e){return this._assert3d("normalMaterial"),this._renderer.normalMaterial(...e),this},t.ambientMaterial=function(e,i,r){this._assert3d("ambientMaterial");let s=t.color.apply(this,arguments);return this._renderer.states.setValue("_hasSetAmbient",!0),this._renderer.states.setValue("curAmbientColor",s._array),this._renderer.states.setValue("_useNormalMaterial",!1),this._renderer.states.setValue("enableLighting",!0),this._renderer.states.fillColor||this._renderer.states.setValue("fillColor",new n.C([1,1,1])),this},t.emissiveMaterial=function(e,i,r,s){this._assert3d("emissiveMaterial");let n=t.color.apply(this,arguments);return this._renderer.states.setValue("curEmissiveColor",n._array),this._renderer.states.setValue("_useEmissiveMaterial",!0),this._renderer.states.setValue("_useNormalMaterial",!1),this._renderer.states.setValue("enableLighting",!0),this},t.specularMaterial=function(e,i,r,s){this._assert3d("specularMaterial");let n=t.color.apply(this,arguments);return this._renderer.states.setValue("curSpecularColor",n._array),this._renderer.states.setValue("_useSpecularMaterial",!0),this._renderer.states.setValue("_useNormalMaterial",!1),this._renderer.states.setValue("enableLighting",!0),this},t.shininess=function(e){return this._assert3d("shininess"),this._renderer.shininess(e),this},t.metalness=function(e){return this._assert3d("metalness"),this._renderer.metalness(e),this},eh.prototype._applyColorBlend=function(e,t){let i=this.GL,r=this.states.drawMode===s.T,n=t||this.states.userFillShader||this.states.userStrokeShader||this.states.userPointShader||r||this.states.curBlendMode!==s.u||e[e.length-1]<1||this._isErasing;return n!==this._isBlending&&(n||this.states.curBlendMode!==s.u&&this.states.curBlendMode!==s.ai?i.enable(i.BLEND):i.disable(i.BLEND),i.depthMask(!0),this._isBlending=n),this._applyBlendMode(),e},eh.prototype._applyBlendMode=function(){if(this._cachedBlendMode===this.states.curBlendM
56ode)return;let e=this.GL;switch(this.states.curBlendMode){case s.u:e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case s.ai:e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ONE);break;case s.a4:e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ZERO,e.ONE_MINUS_SRC_ALPHA);break;case s.a9:e.blendEquation(e.FUNC_ADD),e.blendFunc(e.DST_COLOR,e.ONE_MINUS_SRC_ALPHA);break;case s.ab:e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_COLOR);break;case s.aa:e.blendEquationSeparate(e.FUNC_ADD,e.FUNC_ADD),e.blendFuncSeparate(e.ONE_MINUS_DST_COLOR,e.ONE_MINUS_SRC_COLOR,e.ONE,e.ONE);break;case s.ac:e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ZERO);break;case s.a5:e.blendEquationSeparate(e.FUNC_REVERSE_SUBTRACT,e.FUNC_ADD),e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case s.a6:this.blendExt?(e.blendEquationSeparate(this.blendExt.MIN||this.blendExt.MIN_EXT,e.FUNC_ADD),e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,e.ONE)):console.warn("blendMode(DARKEST) does not work in your browser in WEBGL mode.");break;case s.a7:this.blendExt?(e.blendEquationSeparate(this.blendExt.MAX||this.blendExt.MAX_EXT,e.FUNC_ADD),e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,e.ONE)):console.warn("blendMode(LIGHTEST) does not work in your browser in WEBGL mode.");break;default:console.error("Oops! Somehow RendererGL set curBlendMode to an unsupported mode.")}this._cachedBlendMode=this.states.curBlendMode},eh.prototype.shader=function(e){this.states.setValue("userFillShader",e),this.states.setValue("_useNormalMaterial",!1),e.ensureCompiledOnContext(this),e.setDefaultUniforms()},eh.prototype.strokeShader=function(e){this.states.setValue("userStrokeShader",e),e.ensureCompiledOnContext(this),e.setDefaultUniforms()},eh.prototype.imageShader=function(e){this.states.setValue("userImageShader",e),e.ensureCompiledOnContext(this),e.setDefaultUniforms()},eh.prototype.resetShader=function(){this.states.setValue("userFillShader",null),this.states.setValue("userStrokeShader",null),this.states.setValue("userImageShader",null)},eh.prototype.texture=function(e){this.states.setValue("drawMode",s.T),this.states.setValue("_useNormalMaterial",!1),this.states.setValue("_tex",e),this.states.setValue("fillColor",new n.C([1,1,1]))},eh.prototype.normalMaterial=function(){this.states.setValue("drawMode",s.as),this.states.setValue("_useSpecularMaterial",!1),this.states.setValue("_useEmissiveMaterial",!1),this.states.setValue("_useNormalMaterial",!0),this.states.setValue("curFillColor",[1,1,1,1]),this.states.setValue("fillColor",new n.C([1,1,1])),this.states.setValue("strokeColor",null)},eh.prototype.shininess=function(e){e<1&&(e=1),this.states.setValue("_useShininess",e)},eh.prototype.metalness=function(e){let t=1-Math.exp(-e/100);this.states.setValue("_useMetalness",t)}}"undefined"!=typeof p5&&el(p5,p5.prototype),"undefined"!=typeof p5&&ed(p5,p5.prototype),"undefined"!=typeof p5&&ef(p5,p5.prototype),"undefined"!=typeof p5&&loading(p5,p5.prototype);class em{constructor(e,t,i,n,a){let o=i||s.P;return this._pInst=n,this._renderer=new r[o](this,e,t,!1,a),this._initializeInstanceVariables(this),this._renderer._applyDefaults(),this}get elt(){return this.canvas}get deltaTime(){return this._pInst.deltaTime}get canvas(){return this._renderer?.canvas}get drawingContext(){return this._renderer.drawingContext}get width(){return this._renderer?.width}get height(){return this._renderer?.height}get pixels(){return this._renderer?.pixels}pixelDensity(e){let t;return"number"==typeof e?(e!==this._renderer._pixelDensity&&(this._renderer._pixelDensity=e),t=this,this.resizeCanvas(this.width,this.height,!0)):t=this._renderer._pixelDensity,t}resizeCanvas(e,t){this._renderer.resize(e,t)}reset(){this._renderer.resetMatrix(),this._renderer.isP3D&&this._renderer._update()}remove(){this._renderer.remove(),this._renderer=void 0}createFramebuffer(e){return new eM(this._renderer,e)}_assert3d(e){if(!this._renderer.isP3D)throw Error(`${e}() is only supported in WEBGL mode. If you'd like to use 3D graphics and WebGL, see https://p5js.org/examples/form-3d-primitives.html for more information.`)}_initializeInstanceVariables(){this._accessibleOutputs={text:!1,grid:!1,textLabel:!1,gridLabel:!1},this._styles=[],this._downKeys={}}}function eg(e,t){e.Graphics=em,(0,h.A)(e,e.Graphics.prototype),(0,l.A)(e,e.Graphics.prototype),(0,u.A)(e,e.Graphics.prototype),(0,c.A)(e,e.Graphics.prototype),(0,L.Ay)(e,e.Graphics.prototype),(0,d.A)(e,e.Graphics.prototype),O(e,e.Graphics.prototype),A(e,e.Graphics.prototype),(0,x.A)(e,e.Graphics.prototype),(0,_.A)(e,e.Graphics.prototype),ed(e,e.Graphics.prototype),ef(e,e.Graphics.prototype),ep(e,e.Graphics.prototype),(0,n.c)(e,e.Graphics.prototype),(0,D.A)(e,e.Graphics.prototype)}class ev{constructor(e,t,i){this._renderer=e;let r=this._renderer.GL;i=i||{},this.src=t,this.glTex=void 0,this.glTarget=r.TEXTURE_2D,this.glFormat=i.format||r.RGBA,this.mipmaps=!1,this.glMinFilter=i.minFilter||r.LINEAR,this.glMagFilter=i.magFilter||r.LINEAR,this.glWrapS=i.wrapS||r.CLAMP_TO_EDGE,this.glWrapT=i.wrapT||r.CLAMP_TO_EDGE,this.glDataType=i.dataType||r.UNSIGNED_BYTE;let s=ey(e);this.glFormat!==r.HALF_FLOAT||s.halfFloat||(console.log("This device does not support dataType HALF_FLOAT. Falling back to FLOAT."),this.glDataType=r.FLOAT),this.glFormat!==r.HALF_FLOAT||this.glMinFilter!==r.LINEAR&&this.glMagFilter!==r.LINEAR||s.halfFloatLinear||(console.log("This device does not support linear filtering for dataType FLOAT. Falling back to NEAREST."),this.glMinFilter===r.LINEAR&&(this.glMinFilter=r.NEAREST),this.glMagFilter===r.LINEAR&&(this.glMagFilter=r.NEAREST)),this.glFormat!==r.FLOAT||s.float||(console.log("This device does not support dataType FLOAT. Falling back to UNSIGNED_BYTE."),this.glDataType=r.UNSIGNED_BYTE),this.glFormat!==r.FLOAT||this.glMinFilter!==r.LINEAR&&this.glMagFilter!==r.LINEAR||s.floatLinear||(console.log("This device does not support linear filtering for dataType FLOAT. Falling back to NEAREST."),this.glMinFilter===r.LINEAR&&(this.glMinFilter=r.NEAREST),this.glMagFilter===r.LINEAR&&(this.glMagFilter=r.NEAREST)),this.isSrcMediaElement=!1,this._videoPrevUpdateTime=0,this.isSrcHTMLElement=void 0!==a.H&&t instanceof a.H&&!(t instanceof em)&&!(t instanceof o.R),this.isSrcP5Image=t instanceof o.I,this.isSrcP5Graphics=t instanceof em,this.isSrcP5Renderer=t instanceof o.R,this.isImageData="undefined"!=typeof ImageData&&t instanceof ImageData,this.isFramebufferTexture=t instanceof eC;let n=this._getTextureDataFromSource();return this.width=n.width,this.height=n.height,this.init(n),this}remove(){this.glTex&&(this._renderer.GL.deleteTexture(this.glTex),this.glTex=void 0)}_getTextureDataFromSource(){let e;return this.isFramebufferTexture?e=this.src.rawTexture():this.isSrcP5Image?e=this.src.canvas:this.isSrcMediaElement||this.isSrcHTMLElement?(this.src._ensureCanvas&&this.src._ensureCanvas(),e=this.src.elt):this.isSrcP5Graphics||this.isSrcP5Renderer?e=this.src.canvas:this.isImageData&&(e=this.src),e}init(e){let t=this._renderer.GL;if(this.isFramebufferTexture||(this.glTex=t.createTexture()),this.glWrapS=this._renderer.states.textureWrapX,this.glWrapT=this._renderer.states.textureWrapY,this.setWrapMode(this.glWrapS,this.glWrapT),this.bindTexture(),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,this.glMagFilter),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,this.glMinFilter),this.isFramebufferTexture);else if(0===this.width||0===this.height||this.isSrcMediaElement&&!this.src.loadedmetadata){let e=new Uint8Array([1,1,1,1]);t.texImage2D(this.glTarget,0,t.RGBA,1,1,0,this.glFormat,this.glDataType,e)}else t.texImage2D(this.glTarget,0,this.glFormat,this.glFormat,this.glDataType,e)}update(){let e=this.src;if(0===e.width||0===e.height)return!1;if(this.isFramebufferTexture)return this.src.update(),!1;let t=this._getTextureDataFromSource(),i=!1,r=this._renderer.GL;return t.width!==this.width||t.height!==this.height?(i=!0,this.width=t.width||e.width,this.height=t.height||e.height,this.isSrcP5Image?e.setModified(!1):(this.isSrcMediaElement||this.isSrcHTMLElement)&&e.setModified&&e.setModified(!0)):this.isSrcP5Image?e.isModified()&&(i=!0,e.setModified(!1)):this.isSrcMediaElement?e.
56isModified()?(i=!0,e.setModified(!1)):e.loadedmetadata&&this._videoPrevUpdateTime!==e.time()&&(this._videoPrevUpdateTime=e.time(),i=!0):this.isImageData?e._dirty&&(e._dirty=!1,i=!0):i=!0,i&&(this.bindTexture(),r.texImage2D(this.glTarget,0,this.glFormat,this.glFormat,this.glDataType,t)),i}bindTexture(){return this._renderer.GL.bindTexture(this.glTarget,this.getTexture()),this}unbindTexture(){this._renderer.GL.bindTexture(this.glTarget,null)}getTexture(){return this.isFramebufferTexture?this.src.rawTexture():this.glTex}setInterpolation(e,t){let i=this._renderer.GL;this.glMinFilter=this.glFilter(e),this.glMagFilter=this.glFilter(t),this.bindTexture(),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,this.glMinFilter),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,this.glMagFilter),this.unbindTexture()}glFilter(e){let t=this._renderer.GL;return e===s.ay?t.NEAREST:t.LINEAR}setWrapMode(e,t){let i,r,n=this._renderer.GL,a=e=>(e&e-1)==0,o=this._getTextureDataFromSource();o.naturalWidth&&o.naturalHeight?(i=o.naturalWidth,r=o.naturalHeight):(i=this.width,r=this.height);let h=a(i),l=a(r);e===s.az?this._renderer.webglVersion===s.z||h&&l?this.glWrapS=n.REPEAT:(console.warn("You tried to set the wrap mode to REPEAT but the texture size is not a power of two. Setting to CLAMP instead"),this.glWrapS=n.CLAMP_TO_EDGE):e===s.aA?this._renderer.webglVersion===s.z||h&&l?this.glWrapS=n.MIRRORED_REPEAT:(console.warn("You tried to set the wrap mode to MIRROR but the texture size is not a power of two. Setting to CLAMP instead"),this.glWrapS=n.CLAMP_TO_EDGE):this.glWrapS=n.CLAMP_TO_EDGE,t===s.az?this._renderer.webglVersion===s.z||h&&l?this.glWrapT=n.REPEAT:(console.warn("You tried to set the wrap mode to REPEAT but the texture size is not a power of two. Setting to CLAMP instead"),this.glWrapT=n.CLAMP_TO_EDGE):t===s.aA?this._renderer.webglVersion===s.z||h&&l?this.glWrapT=n.MIRRORED_REPEAT:(console.warn("You tried to set the wrap mode to MIRROR but the texture size is not a power of two. Setting to CLAMP instead"),this.glWrapT=n.CLAMP_TO_EDGE):this.glWrapT=n.CLAMP_TO_EDGE,this.bindTexture(),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,this.glWrapS),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,this.glWrapT),this.unbindTexture()}}class ex extends ev{constructor(e,t,i){super(e,t,i);let r=this._renderer.GL;this.glMinFilter===r.LINEAR&&(this.glMinFilter=r.LINEAR_MIPMAP_LINEAR)}glFilter(e){return this._renderer.GL.LINEAR_MIPMAP_LINEAR}_getTextureDataFromSource(){return this.src}init(e){let t=this._renderer.GL;this.glTex=t.createTexture(),this.bindTexture();for(let i=0;i<e.length;i++)t.texImage2D(this.glTarget,i,this.glFormat,this.glFormat,this.glDataType,e[i]);this.glMinFilter=t.LINEAR_MIPMAP_LINEAR,t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,this.glMagFilter),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,this.glMinFilter),this.unbindTexture()}update(){}}function e_(e,t){e.Texture=ev,e.MipmapTexture=ex}function ey({GL:e,webglVersion:t}){let i=t===s.z?e.getExtension("EXT_color_buffer_float")&&e.getExtension("EXT_float_blend"):e.getExtension("OES_texture_float"),r=i&&e.getExtension("OES_texture_float_linear"),n=t===s.z?e.getExtension("EXT_color_buffer_float"):e.getExtension("OES_texture_half_float"),a=n&&e.getExtension("OES_texture_half_float_linear");return{float:i,floatLinear:r,halfFloat:n,halfFloatLinear:a}}"undefined"!=typeof p5&&e_(p5,p5.prototype);let eb=(e,t,i)=>Math.max(Math.min(e,i),t);class ew extends R{constructor(e){super(e.renderer),this.fbo=e,this.yScale=-1}_computeCameraDefaultSettings(){super._computeCameraDefaultSettings(),this.defaultAspectRatio=this.fbo.width/this.fbo.height,this.defaultCameraFOV=2*Math.atan(this.fbo.height/2/this.defaultEyeZ)}copy(){let e=super.copy();return e.fbo=this.fbo,e}}class eC{constructor(e,t){this.framebuffer=e,this.property=t}get width(){return this.framebuffer.width*this.framebuffer.density}get height(){return this.framebuffer.height*this.framebuffer.density}update(){this.framebuffer._update(this.property)}rawTexture(){return this.framebuffer[this.property]}}class eM{constructor(e,t={}){this.renderer=e,this.renderer.framebuffers.add(this),this._isCl
56ipApplied=!1,this.dirty={colorTexture:!1,depthTexture:!1},this.pixels=[],this.format=t.format||s.av,this.channels=t.channels||(this.renderer._pInst._glAttributes.alpha?n.h:n.R),this.useDepth=void 0===t.depth||t.depth,this.depthFormat=t.depthFormat||s.aB,this.textureFiltering=t.textureFiltering||s.aC,void 0===t.antialias?this.antialiasSamples=2*!!this.renderer._pInst._glAttributes.antialias:"number"==typeof t.antialias?this.antialiasSamples=t.antialias:this.antialiasSamples=2*!!t.antialias,this.antialias=this.antialiasSamples>0,this.antialias&&this.renderer.webglVersion!==s.z&&(console.warn("Antialiasing is unsupported in a WebGL 1 context"),this.antialias=!1),this.density=t.density||this.renderer._pixelDensity;let i=this.renderer.GL;if(this.gl=i,t.width&&t.height){let e=this.renderer._adjustDimensions(t.width,t.height);this.width=e.adjustedWidth,this.height=e.adjustedHeight,this._autoSized=!1}else void 0===t.width!=(void 0===t.height)&&console.warn("Please supply both width and height for a framebuffer to give it a size. Only one was given, so the framebuffer will match the size of its canvas."),this.width=this.renderer.width,this.height=this.renderer.height,this._autoSized=!0;if(this._checkIfFormatsAvailable(),t.stencil&&!this.useDepth&&console.warn("A stencil buffer can only be used if also using depth. Since the framebuffer has no depth buffer, the stencil buffer will be ignored."),this.useStencil=this.useDepth&&(void 0===t.stencil||t.stencil),this.framebuffer=i.createFramebuffer(),!this.framebuffer)throw Error("Unable to create a framebuffer");if(this.antialias&&(this.aaFramebuffer=i.createFramebuffer(),!this.aaFramebuffer))throw Error("Unable to create a framebuffer for antialiasing");this._recreateTextures();let r=this.renderer.states.curCamera;this.defaultCamera=this.createCamera(),this.filterCamera=this.createCamera(),this.renderer.states.setValue("curCamera",r),this.draw(()=>this.renderer.clear())}resize(e,t){this._autoSized=!1;let i=this.renderer._adjustDimensions(e,t);e=i.adjustedWidth,t=i.adjustedHeight,this.width=e,this.height=t,this._handleResize()}pixelDensity(e){if(!e)return this.density;this._autoSized=!1,this.density=e,this._handleResize()}autoSized(e){if(void 0===e)return this._autoSized;this._autoSized=e,this._handleResize()}_checkIfFormatsAvailable(){let e=this.gl;this.useDepth&&this.renderer.webglVersion===s.a0&&!e.getExtension("WEBGL_depth_texture")&&(console.warn("Unable to create depth textures in this environment. Falling back to a framebuffer without depth."),this.useDepth=!1),this.useDepth&&this.renderer.webglVersion===s.a0&&this.depthFormat===s.aB&&(console.warn("FLOAT depth format is unavailable in WebGL 1. Defaulting to UNSIGNED_INT."),this.depthFormat=s.au),[s.av,s.aB,s.aD].includes(this.format)||(console.warn("Unknown Framebuffer format. Please use UNSIGNED_BYTE, FLOAT, or HALF_FLOAT. Defaulting to UNSIGNED_BYTE."),this.format=s.av),this.useDepth&&![s.au,s.aB].includes(this.depthFormat)&&(console.warn("Unknown Framebuffer depth format. Please use UNSIGNED_INT or FLOAT. Defaulting to FLOAT."),this.depthFormat=s.aB);let t=ey(this.renderer);t.float||this.format!==s.aB||(console.warn("This environment does not support FLOAT textures. Falling back to UNSIGNED_BYTE."),this.format=s.av),this.useDepth&&!t.float&&this.depthFormat===s.aB&&(console.warn("This environment does not support FLOAT depth textures. Falling back to UNSIGNED_INT."),this.depthFormat=s.au),t.halfFloat||this.format!==s.aD||(console.warn("This environment does not support HALF_FLOAT textures. Falling back to UNSIGNED_BYTE."),this.format=s.av),this.channels===n.R&&[s.aB,s.aD].includes(this.format)&&(console.warn("FLOAT and HALF_FLOAT formats do not work cross-platform with only RGB channels. Falling back to RGBA."),this.channels=n.h)}_recreateTextures(){let e=this.gl;this._updateSize();let t=e.getParameter(e.TEXTURE_BINDING_2D),i=e.getParameter(e.FRAMEBUFFER_BINDING),r=e.createTexture();if(!r)throw Error("Unable to create color texture");e.bindTexture(e.TEXTURE_2D,r);let n=this._glColorFormat();if(e.texImage2D(e.TEXTURE_2D,0,n.internalFormat,this.width*this.density,this.height*this.density,0,n.format,n.type,null),this.colorTexture=r,e.bindFramebuffer(e.FRAMEBUFFER,this.framebuffer),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,r,0),this.useDepth){let t=e.createTexture();if(!t)throw Error("Unable to create depth texture");let i=this._glDepthFormat();e.bindTexture(e.TEXTURE_2D,t),e.texImage2D(e.TEXTURE_2D,0,i.internalFormat,this.width*this.density,this.height*this.density,0,i.format,i.type,null),e.framebufferTexture2D(e.FRAMEBUFFER,this.useStencil?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT,e.TEXTURE_2D,t,0),this.depthTexture=t}
56if(this.antialias){if(this.colorRenderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,this.colorRenderbuffer),e.renderbufferStorageMultisample(e.RENDERBUFFER,Math.max(0,Math.min(this.antialiasSamples,e.getParameter(e.MAX_SAMPLES))),n.internalFormat,this.width*this.density,this.height*this.density),this.useDepth){let t=this._glDepthFormat();this.depthRenderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,this.depthRenderbuffer),e.renderbufferStorageMultisample(e.RENDERBUFFER,Math.max(0,Math.min(this.antialiasSamples,e.getParameter(e.MAX_SAMPLES))),t.internalFormat,this.width*this.density,this.height*this.density)}e.bindFramebuffer(e.FRAMEBUFFER,this.aaFramebuffer),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.RENDERBUFFER,this.colorRenderbuffer),this.useDepth&&e.framebufferRenderbuffer(e.FRAMEBUFFER,this.useStencil?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT,e.RENDERBUFFER,this.depthRenderbuffer)}if(this.useDepth){this.depth=new eC(this,"depthTexture");let t=e.NEAREST;this.depthP5Texture=new ev(this.renderer,this.depth,{minFilter:t,magFilter:t}),this.renderer.textures.set(this.depth,this.depthP5Texture)}this.color=new eC(this,"colorTexture");let a=this.textureFiltering===s.aC?e.LINEAR:e.NEAREST;this.colorP5Texture=new ev(this.renderer,this.color,{minFilter:a,magFilter:a}),this.renderer.textures.set(this.color,this.colorP5Texture),e.bindTexture(e.TEXTURE_2D,t),e.bindFramebuffer(e.FRAMEBUFFER,i)}_glColorFormat(){let e,t,i=this.gl;return e=this.format===s.aB?i.FLOAT:this.format===s.aD?this.renderer.webglVersion===s.z?i.HALF_FLOAT:i.getExtension("OES_texture_half_float").HALF_FLOAT_OES:i.UNSIGNED_BYTE,t=this.channels===n.h?i.RGBA:i.RGB,{internalFormat:this.renderer.webglVersion===s.z?({[i.FLOAT]:{[i.RGBA]:i.RGBA32F},[i.HALF_FLOAT]:{[i.RGBA]:i.RGBA16F},[i.UNSIGNED_BYTE]:{[i.RGBA]:i.RGBA8,[i.RGB]:i.RGB8}})[e][t]:this.format===s.aD?i.RGBA:t,format:t,type:e}}_glDepthFormat(){let e,t,i=this.gl;return e=this.useStencil?this.depthFormat===s.aB?i.FLOAT_32_UNSIGNED_INT_24_8_REV:this.renderer.webglVersion===s.z?i.UNSIGNED_INT_24_8:i.getExtension("WEBGL_depth_texture").UNSIGNED_INT_24_8_WEBGL:this.depthFormat===s.aB?i.FLOAT:i.UNSIGNED_INT,t=this.useStencil?i.DEPTH_STENCIL:i.DEPTH_COMPONENT,{internalFormat:this.useStencil?this.depthFormat===s.aB?i.DEPTH32F_STENCIL8:this.renderer.webglVersion===s.z?i.DEPTH24_STENCIL8:i.DEPTH_STENCIL:this.renderer.webglVersion===s.z?this.depthFormat===s.aB?i.DEPTH_COMPONENT32F:i.DEPTH_COMPONENT24:i.DEPTH_COMPONENT,format:t,type:e}}_updateSize(){this._autoSized&&(this.width=this.renderer.width,this.height=this.renderer.height,this.density=this.renderer._pixelDensity)}_canvasSizeChanged(){this._autoSized&&this._handleResize()}_handleResize(){let e=this.color,t=this.depth,i=this.colorRenderbuffer,r=this.depthRenderbuffer;this._deleteTexture(e),t&&this._deleteTexture(t);let s=this.gl;i&&s.deleteRenderbuffer(i),r&&s.deleteRenderbuffer(r),this._recreateTextures(),this.defaultCamera._resize()}createCamera(){let e=new ew(this);return e._computeCameraDefaultSettings(),e._setDefaultCamera(),e}_deleteTexture(e){this.gl.deleteTexture(e.rawTexture()),this.renderer.textures.delete(e)}remove(){let e=this.gl;this._deleteTexture(this.color),this.depth&&this._deleteTexture(this.depth),e.deleteFramebuffer(this.framebuffer),this.aaFramebuffer&&e.deleteFramebuffer(this.aaFramebuffer),this.depthRenderbuffer&&e.deleteRenderbuffer(this.depthRenderbuffer),this.colorRenderbuffer&&e.deleteRenderbuffer(this.colorRenderbuffer),this.renderer.framebuffers.delete(this)}begin(){this.prevFramebuffer=this.renderer.activeFramebuffer(),this.prevFramebuffer&&this.prevFramebuffer._beforeEnd(),this.renderer.activeFramebuffers.push(this),this._beforeBegin(),this.renderer.push(),this.renderer.states.setValue("curCamera",this.defaultCamera),this.renderer.states.setValue("uPMatrix",this.renderer.states.uPMatrix.clone()),this.renderer.states.uPMatrix.set(this.defaultCamera.projMatrix),this.renderer.states.setValue("uViewMatrix",this.renderer.states.uViewMatrix.clone()),this.renderer.states.uViewMatrix.set(this.defaultCamera.cameraMatrix),this.renderer.resetMatrix(),this.renderer.states.uViewM
56atrix.set(this.renderer.states.curCamera.cameraMatrix),this.renderer.states.uModelMatrix.reset(),this.renderer._applyStencilTestIfClipping()}_framebufferToBind(){return this.antialias?this.aaFramebuffer:this.framebuffer}_update(e){if(this.dirty[e]&&this.antialias){let t=this.gl;t.bindFramebuffer(t.READ_FRAMEBUFFER,this.aaFramebuffer),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,this.framebuffer);let i={colorTexture:[t.COLOR_BUFFER_BIT,this.colorP5Texture.glMagFilter]};this.useDepth&&(i.depthTexture=[t.DEPTH_BUFFER_BIT,this.depthP5Texture.glMagFilter]);let[r,s]=i[e];t.blitFramebuffer(0,0,this.width*this.density,this.height*this.density,0,0,this.width*this.density,this.height*this.density,r,s),this.dirty[e]=!1;let n=this.renderer.activeFramebuffer();n?t.bindFramebuffer(t.FRAMEBUFFER,n._framebufferToBind()):t.bindFramebuffer(t.FRAMEBUFFER,null)}}_beforeBegin(){let e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this._framebufferToBind()),this.renderer.viewport(this.width*this.density,this.height*this.density)}_beforeEnd(){this.antialias&&(this.dirty={colorTexture:!0,depthTexture:!0})}end(){let e=this.gl;if(this.renderer.pop(),this.renderer.activeFramebuffers.pop()!==this)throw Error("It looks like you've called end() while another Framebuffer is active.");this._beforeEnd(),this.prevFramebuffer?this.prevFramebuffer._beforeBegin():(e.bindFramebuffer(e.FRAMEBUFFER,null),this.renderer.viewport(this.renderer._origViewport.width,this.renderer._origViewport.height)),this.renderer._applyStencilTestIfClipping()}draw(e){this.begin(),e(),this.end()}loadPixels(){this._update("colorTexture");let e=this.gl,t=this.renderer.activeFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,this.framebuffer);let i=this._glColorFormat();this.pixels=eu(this.pixels,e,this.framebuffer,0,0,this.width*this.density,this.height*this.density,i.format,i.type),t?e.bindFramebuffer(e.FRAMEBUFFER,t._framebufferToBind()):e.bindFramebuffer(e.FRAMEBUFFER,null)}get(e,t,i,r){this._update("colorTexture");let s=this._glColorFormat();if(void 0===e&&void 0===t)e=0,t=0,i=this.width,r=this.height;else if(void 0===i&&void 0===r)return(e<0||t<0||e>=this.width||t>=this.height)&&(console.warn("The x and y values passed to p5.Framebuffer.get are outside of its range and will be clamped."),e=eb(e,0,this.width-1),t=eb(t,0,this.height-1)),ec(this.gl,this.framebuffer,e*this.density,t*this.density,s.format,s.type);e=eb(e,0,this.width-1),t=eb(t,0,this.height-1),i=eb(i,1,this.width-e),r=eb(r,1,this.height-t);let n=eu(void 0,this.gl,this.framebuffer,e*this.density,t*this.density,i*this.density,r*this.density,s.format,s.type),a=new Uint8ClampedArray(i*r*this.density*this.density*4);a.fill(255);let h=s.type===this.gl.RGB?3:4;for(let e=0;e<r*this.density;e++)for(let t=0;t<i*this.density;t++)for(let r=0;r<4;r++){let s=(e*i*this.density+t)*4+r;if(r<h){let o=4===h?s:(e*i*this.density+t)*h+r;a[s]=n[o]}}let l=new o.I(i*this.density,r*this.density);return l.imageData=l.canvas.getContext("2d").createImageData(l.width,l.height),l.imageData.data.set(a),l.pixels=l.imageData.data,l.updatePixels(),1!==this.density&&l.resize(i,r),l}updatePixels(){let e=this.gl;this.colorP5Texture.bindTexture();let t=this._glColorFormat(),i=t.format===e.RGBA?4:3,r=this.width*this.height*this.density*this.density*i,n=t.type===e.UNSIGNED_BYTE?Uint8Array:Float32Array;if(!(this.pixels instanceof n)||this.pixels.length!==r)throw Error("The pixels array has not been set correctly. Please call loadPixels() before updatePixels().");e.texImage2D(e.TEXTURE_2D,0,t.internalFormat,this.width*this.density,this.height*this.density,0,t.format,t.type,this.pixels),this.colorP5Texture.unbindTexture(),this.dirty.colorTexture=!1;let a=this.renderer.activeFramebuffer();this.antialias?(this.begin(),this.renderer.push(),this.renderer.states.setValue("imageMode",s.e),this.renderer.setCamera(this.filterCamera),this.renderer.resetMatrix(),this.renderer.states.setValue("strokeColor",null),this.renderer.clear(),this.renderer._drawingFilter=!0,this.renderer.image(this,0,0,this.width,this.height,-this.renderer.width/2,-this.renderer.height/2,this.renderer.width,this.renderer.height),this.renderer._drawingFilter=!1,this.renderer.pop(),this.useDepth&&(e.clearDepth(1),e.clear(e.DEPTH_BUFFER_BIT)),this.end()):(e.bindFramebuffer(e.FRAMEBUFFER,this.framebuffer),this.useDepth&&(e.clearDepth(1),e.clear(e.DEPTH_BUFFER_BIT)),a?e.bindFramebuffer(e.FRAMEBUFFER,a._framebufferToBind()):e.bindFramebuffer(e.FRAMEBUFFER,null))}}function eT(e,t){e.FramebufferCamera=ew,e.FramebufferTexture=eC,e.Framebuffer=eM}function eS(e,t){r=e.renderers={},t.createCanvas=function(e,t,i,...n){let a=s.P;return Reflect.ownKeys(r).includes(i)?a=i:n.unshift(i),this._renderer&&this._renderer.remove(),this._renderer=new r[a](this,e,t,!0,...n),this._defaultGraphicsCreated=!0,this._elements.push(this._renderer),this._renderer._applyDefaults(),Object.hasOwn(this,"pixels")||Object.defineProperty(this,"pixels",{get(){return this._renderer?.pixels}}),this._renderer},t.resizeCanvas=function(e,t,i){this._renderer&&(this._renderer.resize(e,t),i||this.redraw()),this._addAccsOutput()&&this._updateAccsOutput()},t.noCanvas=function(){this.canvas&&this.canvas.parentNode.removeChild(this.canvas)},t.createGraphics=function(t,i,...r){return r[0]instanceof HTMLCanvasElement&&(r[1]=r[0],r[0]=s.P),new e.Graphics(t,i,r[0],this,r[1])},t.createFramebuffer=function(e){return new eM(this._renderer,e)},t.clearDepth=function(e){this._assert3d("clearDepth"),this._renderer.clearDepth(e)}}"undefined"!=typeof p5&&eT(p5,p5.prototype),"undefined"!=typeof p5&&eS(p5,p5.prototype)}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.