@luma.gl/engine 9.0.14 → 9.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dist.min.js CHANGED
@@ -4,10 +4,10 @@
4
4
  else if (typeof define === 'function' && define.amd) define([], factory);
5
5
  else if (typeof exports === 'object') exports['luma'] = factory();
6
6
  else root['luma'] = factory();})(globalThis, function () {
7
- "use strict";var __exports__=(()=>{var yr=Object.create;var Vt=Object.defineProperty;var wr=Object.getOwnPropertyDescriptor;var vr=Object.getOwnPropertyNames;var br=Object.getPrototypeOf,kr=Object.prototype.hasOwnProperty;var Mr=(s,t,e)=>t in s?Vt(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var Sr=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports),Er=(s,t)=>{for(var e in t)Vt(s,e,{get:t[e],enumerable:!0})},ee=(s,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of vr(t))!kr.call(s,r)&&r!==e&&Vt(s,r,{get:()=>t[r],enumerable:!(n=wr(t,r))||n.enumerable});return s},se=(s,t,e)=>(ee(s,t,"default"),e&&ee(e,t,"default")),C=(s,t,e)=>(e=s!=null?yr(br(s)):{},ee(t||!s||!s.__esModule?Vt(e,"default",{value:s,enumerable:!0}):e,s)),Ar=s=>ee(Vt({},"__esModule",{value:!0}),s);var et=(s,t,e)=>(Mr(s,typeof t!="symbol"?t+"":t,e),e);var z=Sr((Ci,Xs)=>{Xs.exports=globalThis.luma});var Kt={};Er(Kt,{AnimationLoop:()=>St,AnimationLoopTemplate:()=>ie,BufferTransform:()=>Ft,ClipSpace:()=>Fe,Computation:()=>Xt,ConeGeometry:()=>Ue,CubeGeometry:()=>qe,CylinderGeometry:()=>Ve,GPUGeometry:()=>Rt,Geometry:()=>G,GroupNode:()=>Ut,IcoSphereGeometry:()=>$e,KeyFrames:()=>re,Model:()=>K,ModelNode:()=>De,PipelineFactory:()=>ht,PlaneGeometry:()=>je,ScenegraphNode:()=>ft,ShaderFactory:()=>lt,SphereGeometry:()=>Ge,TextureTransform:()=>Ce,Timeline:()=>ne,TruncatedConeGeometry:()=>xt,_ShaderInputs:()=>gt,makeAnimationLoop:()=>Js});se(Kt,C(z(),1));var Tr=1,Or=1,ne=class{time=0;channels=new Map;animations=new Map;playing=!1;lastEngineTime=-1;constructor(){}addChannel(t){let{delay:e=0,duration:n=Number.POSITIVE_INFINITY,rate:r=1,repeat:i=1}=t,o=Tr++,c={time:0,delay:e,duration:n,rate:r,repeat:i};return this._setChannelTime(c,this.time),this.channels.set(o,c),o}removeChannel(t){this.channels.delete(t);for(let[e,n]of this.animations)n.channel===t&&this.detachAnimation(e)}isFinished(t){let e=this.channels.get(t);return e===void 0?!1:this.time>=e.delay+e.duration*e.repeat}getTime(t){if(t===void 0)return this.time;let e=this.channels.get(t);return e===void 0?-1:e.time}setTime(t){this.time=Math.max(0,t);let e=this.channels.values();for(let r of e)this._setChannelTime(r,this.time);let n=this.animations.values();for(let r of n){let{animation:i,channel:o}=r;i.setTime(this.getTime(o))}}play(){this.playing=!0}pause(){this.playing=!1,this.lastEngineTime=-1}reset(){this.setTime(0)}attachAnimation(t,e){let n=Or++;return this.animations.set(n,{animation:t,channel:e}),t.setTime(this.getTime(e)),n}detachAnimation(t){this.animations.delete(t)}update(t){this.playing&&(this.lastEngineTime===-1&&(this.lastEngineTime=t),this.setTime(this.time+(t-this.lastEngineTime)),this.lastEngineTime=t)}_setChannelTime(t,e){let n=e-t.delay,r=t.duration*t.repeat;n>=r?t.time=t.duration*t.rate:(t.time=Math.max(0,n)%t.duration,t.time*=t.rate)}};var re=class{startIndex=-1;endIndex=-1;factor=0;times=[];values=[];_lastTime=-1;constructor(t){this.setKeyFrames(t),this.setTime(0)}setKeyFrames(t){let e=t.length;this.times.length=e,this.values.length=e;for(let n=0;n<e;++n)this.times[n]=t[n][0],this.values[n]=t[n][1];this._calculateKeys(this._lastTime)}setTime(t){t=Math.max(0,t),t!==this._lastTime&&(this._calculateKeys(t),this._lastTime=t)}getStartTime(){return this.times[this.startIndex]}getEndTime(){return this.times[this.endIndex]}getStartData(){return this.values[this.startIndex]}getEndData(){return this.values[this.endIndex]}_calculateKeys(t){let e=0,n=this.times.length;for(e=0;e<n-2&&!(this.times[e+1]>t);++e);this.startIndex=e,this.endIndex=e+1;let r=this.times[this.startIndex],i=this.times[this.endIndex];this.factor=Math.min(Math.max(0,(t-r)/(i-r)),1)}};var ie=class{constructor(t){}async onInitialize(t){return null}};var Ks=C(z(),1),oe=C(z(),1);function $t(){let s;if(typeof window<"u"&&window.performance)s=window.performance.now();else if(typeof process<"u"&&process.hrtime){let t=process.hrtime();s=t[0]*1e3+t[1]/1e6}else s=Date.now();return s}var yt=class{constructor(t,e){this.name=void 0,this.type=void 0,this.sampleSize=1,this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this.name=t,this.type=e,this.reset()}reset(){return this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this}setSampleSize(t){return this.sampleSize=t,this}incrementCount(){return this.addCount(1),this}decrementCount(){return this.subtractCount(1),this}addCount(t){return this._count+=t,this._samples++,this._checkSampling(),this}subtractCount(t){return this._count-=t,this._samples++,this._checkSampling(),this}addTime(t){return this._time+=t,this.lastTiming=t,this._samples++,this._checkSampling(),this}timeStart(){return this._startTime=$t(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime($t()-this._startTime),this._timerPending=!1,this._checkSampling(),this):this}getSampleAverageCount(){return this.sampleSize>0?this.lastSampleCount/this.sampleSize:0}getSampleAverageTime(){return this.sampleSize>0?this.lastSampleTime/this.sampleSize:0}getSampleHz(){return this.lastSampleTime>0?this.sampleSize/(this.lastSampleTime/1e3):0}getAverageCount(){return this.samples>0?this.count/this.samples:0}getAverageTime(){return this.samples>0?this.time/this.samples:0}getHz(){return this.time>0?this.samples/(this.time/1e3):0}_checkSampling(){this._samples===this.sampleSize&&(this.lastSampleTime=this._time,this.lastSampleCount=this._count,this.count+=this._count,this.time+=this._time,this.samples+=this._samples,this._time=0,this._count=0,this._samples=0)}};var Mt=class{constructor(t){this.id=void 0,this.stats={},this.id=t.id,this.stats={},this._initializeStats(t.stats),Object.seal(this)}get(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"count";return this._getOrCreate({name:t,type:e})}get size(){return Object.keys(this.stats).length}reset(){for(let t of Object.values(this.stats))t.reset();return this}forEach(t){for(let e of Object.values(this.stats))t(e)}getTable(){let t={};return this.forEach(e=>{t[e.name]={time:e.time||0,count:e.count||0,average:e.getAverageTime()||0,hz:e.getHz()||0}}),t}_initializeStats(){(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).forEach(e=>this._getOrCreate(e))}_getOrCreate(t){let{name:e,type:n}=t,r=this.stats[e];return r||(t instanceof yt?r=t:r=new yt(e,n),this.stats[e]=r),r}};var Pr=0,Nr={device:null,onAddHTML:()=>"",onInitialize:async()=>null,onRender:()=>{},onFinalize:()=>{},onError:s=>console.error(s),stats:Ks.luma.stats.get(`animation-loop-${Pr++}`),useDevicePixels:!0,autoResizeViewport:!1,autoResizeDrawingBuffer:!1},St=class{device=null;canvas=null;props;animationProps=null;timeline=null;stats;cpuTime;gpuTime;frameRate;display;needsRedraw="initialized";_initialized=!1;_running=!1;_animationFrameId=null;_nextFramePromise=null;_resolveNextFrame=null;_cpuStartTime=0;constructor(t){if(this.props={...Nr,...t},t=this.props,!t.device)throw new Error("No device provided");let{useDevicePixels:e=!0}=this.props;this.stats=t.stats||new Mt({id:"animation-loop-stats"}),this.cpuTime=this.stats.get("CPU Time"),this.gpuTime=this.stats.get("GPU Time"),this.frameRate=this.stats.get("Frame Rate"),this.setProps({autoResizeViewport:t.autoResizeViewport,autoResizeDrawingBuffer:t.autoResizeDrawingBuffer,useDevicePixels:e}),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this._onMousemove=this._onMousemove.bind(this),this._onMouseleave=this._onMouseleave.bind(this)}destroy(){this.stop(),this._setDisplay(null)}delete(){this.destroy()}setNeedsRedraw(t){return this.needsRedraw=this.needsRedraw||t,this}setProps(t){return"autoResizeViewport"in t&&(this.props.autoResizeViewport=t.autoResizeViewport||!1),"autoResizeDrawingBuffer"in t&&(this.props.autoResizeDrawingBuffer=t.autoResizeDrawingBuffer||!1),"useDevicePixels"in t&&(this.props.useDevicePixels=t.useDevicePixels||!1),this}async start(){if(this._running)return this;this._running=!0;try{let t;return this._initialized||(this._initialized=!0,await this._initDevice(),this._initialize(),await this.props.onInitialize(this._getAnimationProps())),this._running?(t!==!1&&(this._cancelAnimationFrame(),this._requestAnimationFrame()),this):null}catch(t){let e=t instanceof Error?t:new Error("Unknown error");throw this.props.onError(e),e}}stop(){return this._running&&(this.animationProps&&this.props.onFinalize(this.animationProps),this._cancelAnimationFrame(),this._nextFramePromise=null,this._resolveNextFrame=null,this._running=!1),this}redraw(){return this.device?.isLost?this:(this._beginFrameTimers(),this._setupFrame(),this._updateAnimationProps(),this._renderFrame(this._getAnimationProps()),this._clearNeedsRedraw(),this._resolveNextFrame&&(this._resolveNextFrame(this),this._nextFramePromise=null,this._resolveNextFrame=null),this._endFrameTimers(),this)}attachTimeline(t){return this.timeline=t,this.timeline}detachTimeline(){this.timeline=null}waitForRender(){return this.setNeedsRedraw("waitForRender"),this._nextFramePromise||(this._nextFramePromise=new Promise(t=>{this._resolveNextFrame=t})),this._nextFramePromise}async toDataURL(){if(this.setNeedsRedraw("toDataURL"),await this.waitForRender(),this.canvas instanceof HTMLCanvasElement)return this.canvas.toDataURL();throw new Error("OffscreenCanvas")}_initialize(){this._startEventHandling(),this._initializeAnimationProps(),this._updateAnimationProps(),this._resizeCanvasDrawingBuffer(),this._resizeViewport()}_setDisplay(t){this.display&&(this.display.destroy(),this.display.animationLoop=null),t&&(t.animationLoop=this),this.display=t}_requestAnimationFrame(){this._running&&(this._animationFrameId=(0,oe.requestAnimationFrame)(this._animationFrame.bind(this)))}_cancelAnimationFrame(){this._animationFrameId!==null&&((0,oe.cancelAnimationFrame)(this._animationFrameId),this._animationFrameId=null)}_animationFrame(){this._running&&(this.redraw(),this._requestAnimationFrame())}_renderFrame(t){if(this.display){this.display._renderFrame(t);return}this.props.onRender(this._getAnimationProps()),this.device.submit()}_clearNeedsRedraw(){this.needsRedraw=!1}_setupFrame(){this._resizeCanvasDrawingBuffer(),this._resizeViewport()}_initializeAnimationProps(){if(!this.device)throw new Error("loop");this.animationProps={animationLoop:this,device:this.device,canvas:this.device?.canvasContext?.canvas,timeline:this.timeline,useDevicePixels:this.props.useDevicePixels,needsRedraw:!1,width:1,height:1,aspect:1,time:0,startTime:Date.now(),engineTime:0,tick:0,tock:0,_mousePosition:null}}_getAnimationProps(){if(!this.animationProps)throw new Error("animationProps");return this.animationProps}_updateAnimationProps(){if(!this.animationProps)return;let{width:t,height:e,aspect:n}=this._getSizeAndAspect();(t!==this.animationProps.width||e!==this.animationProps.height)&&this.setNeedsRedraw("drawing buffer resized"),n!==this.animationProps.aspect&&this.setNeedsRedraw("drawing buffer aspect changed"),this.animationProps.width=t,this.animationProps.height=e,this.animationProps.aspect=n,this.animationProps.needsRedraw=this.needsRedraw,this.animationProps.engineTime=Date.now()-this.animationProps.startTime,this.timeline&&this.timeline.update(this.animationProps.engineTime),this.animationProps.tick=Math.floor(this.animationProps.time/1e3*60),this.animationProps.tock++,this.animationProps.time=this.timeline?this.timeline.getTime():this.animationProps.engineTime}async _initDevice(){if(this.device=await this.props.device,!this.device)throw new Error("No device provided");this.canvas=this.device.canvasContext?.canvas||null}_createInfoDiv(){if(this.canvas&&this.props.onAddHTML){let t=document.createElement("div");document.body.appendChild(t),t.style.position="relative";let e=document.createElement("div");e.style.position="absolute",e.style.left="10px",e.style.bottom="10px",e.style.width="300px",e.style.background="white",this.canvas instanceof HTMLCanvasElement&&t.appendChild(this.canvas),t.appendChild(e);let n=this.props.onAddHTML(e);n&&(e.innerHTML=n)}}_getSizeAndAspect(){if(!this.device)return{width:1,height:1,aspect:1};let[t,e]=this.device?.canvasContext?.getPixelSize()||[1,1],n=1,r=this.device?.canvasContext?.canvas;return r&&r.clientHeight?n=r.clientWidth/r.clientHeight:t>0&&e>0&&(n=t/e),{width:t,height:e,aspect:n}}_resizeViewport(){this.props.autoResizeViewport&&this.device.gl&&this.device.gl.viewport(0,0,this.device.gl.drawingBufferWidth,this.device.gl.drawingBufferHeight)}_resizeCanvasDrawingBuffer(){this.props.autoResizeDrawingBuffer&&this.device?.canvasContext?.resize({useDevicePixels:this.props.useDevicePixels})}_beginFrameTimers(){this.frameRate.timeEnd(),this.frameRate.timeStart(),this.cpuTime.timeStart()}_endFrameTimers(){this.cpuTime.timeEnd()}_startEventHandling(){this.canvas&&(this.canvas.addEventListener("mousemove",this._onMousemove.bind(this)),this.canvas.addEventListener("mouseleave",this._onMouseleave.bind(this)))}_onMousemove(t){t instanceof MouseEvent&&(this._getAnimationProps()._mousePosition=[t.offsetX,t.offsetY])}_onMouseleave(t){this._getAnimationProps()._mousePosition=null}};var Zs=C(z(),1);function Js(s,t){let e=null,n=t?.device||Zs.luma.createDevice(),r=new St({...t,device:n,async onInitialize(i){return e=new s(i),await e?.onInitialize(i)},onRender:i=>e?.onRender(i),onFinalize:i=>e?.onFinalize(i)});return r.getInfo=()=>this.AnimationLoopTemplateCtor.info,r}var ut=C(z(),1),Le=C(z(),1),F=C(z(),1),Re=C(z(),1);function st(s,t){if(!s)throw new Error(t||"shadertools: assertion failed.")}var Be={number:{type:"number",validate(s,t){return Number.isFinite(s)&&typeof t=="object"&&(t.max===void 0||s<=t.max)&&(t.min===void 0||s>=t.min)}},array:{type:"array",validate(s,t){return Array.isArray(s)||ArrayBuffer.isView(s)}}};function tn(s){let t={};for(let[e,n]of Object.entries(s))t[e]=Ir(n);return t}function en(s,t,e){let n={};for(let[r,i]of Object.entries(t))s&&r in s&&!i.private?(i.validate&&st(i.validate(s[r],i),`${e}: invalid ${r}`),n[r]=s[r]):n[r]=i.value;return n}function Ir(s){let t=Qs(s);if(t!=="object")return{value:s,...Be[t],type:t};if(typeof s=="object")return s?s.type!==void 0?{...s,...Be[s.type],type:s.type}:s.value===void 0?{type:"object",value:s}:(t=Qs(s.value),{...s,...Be[t],type:t}):{type:"object",value:null};throw new Error("props")}function Qs(s){return Array.isArray(s)||ArrayBuffer.isView(s)?"array":typeof s}var sn=`#ifdef MODULE_LOGDEPTH
7
+ "use strict";var __exports__=(()=>{var Sr=Object.create;var Vt=Object.defineProperty;var Ar=Object.getOwnPropertyDescriptor;var Er=Object.getOwnPropertyNames;var Tr=Object.getPrototypeOf,Or=Object.prototype.hasOwnProperty;var Lr=(s,t,e)=>t in s?Vt(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var Ir=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports),Nr=(s,t)=>{for(var e in t)Vt(s,e,{get:t[e],enumerable:!0})},ae=(s,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Er(t))!Or.call(s,r)&&r!==e&&Vt(s,r,{get:()=>t[r],enumerable:!(n=Ar(t,r))||n.enumerable});return s},ce=(s,t,e)=>(ae(s,t,"default"),e&&ae(e,t,"default")),C=(s,t,e)=>(e=s!=null?Sr(Tr(s)):{},ae(t||!s||!s.__esModule?Vt(e,"default",{value:s,enumerable:!0}):e,s)),Pr=s=>ae(Vt({},"__esModule",{value:!0}),s);var st=(s,t,e)=>(Lr(s,typeof t!="symbol"?t+"":t,e),e);var z=Ir(($i,en)=>{en.exports=globalThis.luma});var se={};Nr(se,{AnimationLoop:()=>St,AnimationLoopTemplate:()=>ue,BufferTransform:()=>Ut,ClipSpace:()=>Be,Computation:()=>ee,ConeGeometry:()=>je,CubeGeometry:()=>Ge,CylinderGeometry:()=>We,GPUGeometry:()=>Ct,Geometry:()=>j,GroupNode:()=>$t,IcoSphereGeometry:()=>He,KeyFrames:()=>le,Model:()=>K,ModelNode:()=>Ve,PipelineFactory:()=>lt,PlaneGeometry:()=>Ye,ScenegraphNode:()=>dt,ShaderFactory:()=>ut,SphereGeometry:()=>Xe,TextureTransform:()=>$e,Timeline:()=>he,TruncatedConeGeometry:()=>yt,_ShaderInputs:()=>xt,makeAnimationLoop:()=>rn});ce(se,C(z(),1));var Rr=1,zr=1,he=class{time=0;channels=new Map;animations=new Map;playing=!1;lastEngineTime=-1;constructor(){}addChannel(t){let{delay:e=0,duration:n=Number.POSITIVE_INFINITY,rate:r=1,repeat:i=1}=t,o=Rr++,c={time:0,delay:e,duration:n,rate:r,repeat:i};return this._setChannelTime(c,this.time),this.channels.set(o,c),o}removeChannel(t){this.channels.delete(t);for(let[e,n]of this.animations)n.channel===t&&this.detachAnimation(e)}isFinished(t){let e=this.channels.get(t);return e===void 0?!1:this.time>=e.delay+e.duration*e.repeat}getTime(t){if(t===void 0)return this.time;let e=this.channels.get(t);return e===void 0?-1:e.time}setTime(t){this.time=Math.max(0,t);let e=this.channels.values();for(let r of e)this._setChannelTime(r,this.time);let n=this.animations.values();for(let r of n){let{animation:i,channel:o}=r;i.setTime(this.getTime(o))}}play(){this.playing=!0}pause(){this.playing=!1,this.lastEngineTime=-1}reset(){this.setTime(0)}attachAnimation(t,e){let n=zr++;return this.animations.set(n,{animation:t,channel:e}),t.setTime(this.getTime(e)),n}detachAnimation(t){this.animations.delete(t)}update(t){this.playing&&(this.lastEngineTime===-1&&(this.lastEngineTime=t),this.setTime(this.time+(t-this.lastEngineTime)),this.lastEngineTime=t)}_setChannelTime(t,e){let n=e-t.delay,r=t.duration*t.repeat;n>=r?t.time=t.duration*t.rate:(t.time=Math.max(0,n)%t.duration,t.time*=t.rate)}};var le=class{startIndex=-1;endIndex=-1;factor=0;times=[];values=[];_lastTime=-1;constructor(t){this.setKeyFrames(t),this.setTime(0)}setKeyFrames(t){let e=t.length;this.times.length=e,this.values.length=e;for(let n=0;n<e;++n)this.times[n]=t[n][0],this.values[n]=t[n][1];this._calculateKeys(this._lastTime)}setTime(t){t=Math.max(0,t),t!==this._lastTime&&(this._calculateKeys(t),this._lastTime=t)}getStartTime(){return this.times[this.startIndex]}getEndTime(){return this.times[this.endIndex]}getStartData(){return this.values[this.startIndex]}getEndData(){return this.values[this.endIndex]}_calculateKeys(t){let e=0,n=this.times.length;for(e=0;e<n-2&&!(this.times[e+1]>t);++e);this.startIndex=e,this.endIndex=e+1;let r=this.times[this.startIndex],i=this.times[this.endIndex];this.factor=Math.min(Math.max(0,(t-r)/(i-r)),1)}};var ue=class{constructor(t){}async onInitialize(t){return null}};var sn=C(z(),1),fe=C(z(),1);function jt(){let s;if(typeof window<"u"&&window.performance)s=window.performance.now();else if(typeof process<"u"&&process.hrtime){let t=process.hrtime();s=t[0]*1e3+t[1]/1e6}else s=Date.now();return s}var wt=class{constructor(t,e){this.sampleSize=1,this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this.name=t,this.type=e,this.reset()}reset(){return this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this}setSampleSize(t){return this.sampleSize=t,this}incrementCount(){return this.addCount(1),this}decrementCount(){return this.subtractCount(1),this}addCount(t){return this._count+=t,this._samples++,this._checkSampling(),this}subtractCount(t){return this._count-=t,this._samples++,this._checkSampling(),this}addTime(t){return this._time+=t,this.lastTiming=t,this._samples++,this._checkSampling(),this}timeStart(){return this._startTime=jt(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(jt()-this._startTime),this._timerPending=!1,this._checkSampling(),this):this}getSampleAverageCount(){return this.sampleSize>0?this.lastSampleCount/this.sampleSize:0}getSampleAverageTime(){return this.sampleSize>0?this.lastSampleTime/this.sampleSize:0}getSampleHz(){return this.lastSampleTime>0?this.sampleSize/(this.lastSampleTime/1e3):0}getAverageCount(){return this.samples>0?this.count/this.samples:0}getAverageTime(){return this.samples>0?this.time/this.samples:0}getHz(){return this.time>0?this.samples/(this.time/1e3):0}_checkSampling(){this._samples===this.sampleSize&&(this.lastSampleTime=this._time,this.lastSampleCount=this._count,this.count+=this._count,this.time+=this._time,this.samples+=this._samples,this._time=0,this._count=0,this._samples=0)}};var Mt=class{constructor(t){this.stats={},this.id=t.id,this.stats={},this._initializeStats(t.stats),Object.seal(this)}get(t,e="count"){return this._getOrCreate({name:t,type:e})}get size(){return Object.keys(this.stats).length}reset(){for(let t of Object.values(this.stats))t.reset();return this}forEach(t){for(let e of Object.values(this.stats))t(e)}getTable(){let t={};return this.forEach(e=>{t[e.name]={time:e.time||0,count:e.count||0,average:e.getAverageTime()||0,hz:e.getHz()||0}}),t}_initializeStats(t=[]){t.forEach(e=>this._getOrCreate(e))}_getOrCreate(t){let{name:e,type:n}=t,r=this.stats[e];return r||(t instanceof wt?r=t:r=new wt(e,n),this.stats[e]=r),r}};var Cr=0,Fr={device:null,onAddHTML:()=>"",onInitialize:async()=>null,onRender:()=>{},onFinalize:()=>{},onError:s=>console.error(s),stats:sn.luma.stats.get(`animation-loop-${Cr++}`),useDevicePixels:!0,autoResizeViewport:!1,autoResizeDrawingBuffer:!1},St=class{device=null;canvas=null;props;animationProps=null;timeline=null;stats;cpuTime;gpuTime;frameRate;display;needsRedraw="initialized";_initialized=!1;_running=!1;_animationFrameId=null;_nextFramePromise=null;_resolveNextFrame=null;_cpuStartTime=0;constructor(t){if(this.props={...Fr,...t},t=this.props,!t.device)throw new Error("No device provided");let{useDevicePixels:e=!0}=this.props;this.stats=t.stats||new Mt({id:"animation-loop-stats"}),this.cpuTime=this.stats.get("CPU Time"),this.gpuTime=this.stats.get("GPU Time"),this.frameRate=this.stats.get("Frame Rate"),this.setProps({autoResizeViewport:t.autoResizeViewport,autoResizeDrawingBuffer:t.autoResizeDrawingBuffer,useDevicePixels:e}),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this._onMousemove=this._onMousemove.bind(this),this._onMouseleave=this._onMouseleave.bind(this)}destroy(){this.stop(),this._setDisplay(null)}delete(){this.destroy()}setNeedsRedraw(t){return this.needsRedraw=this.needsRedraw||t,this}setProps(t){return"autoResizeViewport"in t&&(this.props.autoResizeViewport=t.autoResizeViewport||!1),"autoResizeDrawingBuffer"in t&&(this.props.autoResizeDrawingBuffer=t.autoResizeDrawingBuffer||!1),"useDevicePixels"in t&&(this.props.useDevicePixels=t.useDevicePixels||!1),this}async start(){if(this._running)return this;this._running=!0;try{let t;return this._initialized||(this._initialized=!0,await this._initDevice(),this._initialize(),await this.props.onInitialize(this._getAnimationProps())),this._running?(t!==!1&&(this._cancelAnimationFrame(),this._requestAnimationFrame()),this):null}catch(t){let e=t instanceof Error?t:new Error("Unknown error");throw this.props.onError(e),e}}stop(){return this._running&&(this.animationProps&&this.props.onFinalize(this.animationProps),this._cancelAnimationFrame(),this._nextFramePromise=null,this._resolveNextFrame=null,this._running=!1),this}redraw(){return this.device?.isLost?this:(this._beginFrameTimers(),this._setupFrame(),this._updateAnimationProps(),this._renderFrame(this._getAnimationProps()),this._clearNeedsRedraw(),this._resolveNextFrame&&(this._resolveNextFrame(this),this._nextFramePromise=null,this._resolveNextFrame=null),this._endFrameTimers(),this)}attachTimeline(t){return this.timeline=t,this.timeline}detachTimeline(){this.timeline=null}waitForRender(){return this.setNeedsRedraw("waitForRender"),this._nextFramePromise||(this._nextFramePromise=new Promise(t=>{this._resolveNextFrame=t})),this._nextFramePromise}async toDataURL(){if(this.setNeedsRedraw("toDataURL"),await this.waitForRender(),this.canvas instanceof HTMLCanvasElement)return this.canvas.toDataURL();throw new Error("OffscreenCanvas")}_initialize(){this._startEventHandling(),this._initializeAnimationProps(),this._updateAnimationProps(),this._resizeCanvasDrawingBuffer(),this._resizeViewport()}_setDisplay(t){this.display&&(this.display.destroy(),this.display.animationLoop=null),t&&(t.animationLoop=this),this.display=t}_requestAnimationFrame(){this._running&&(this._animationFrameId=(0,fe.requestAnimationFrame)(this._animationFrame.bind(this)))}_cancelAnimationFrame(){this._animationFrameId!==null&&((0,fe.cancelAnimationFrame)(this._animationFrameId),this._animationFrameId=null)}_animationFrame(){this._running&&(this.redraw(),this._requestAnimationFrame())}_renderFrame(t){if(this.display){this.display._renderFrame(t);return}this.props.onRender(this._getAnimationProps()),this.device.submit()}_clearNeedsRedraw(){this.needsRedraw=!1}_setupFrame(){this._resizeCanvasDrawingBuffer(),this._resizeViewport()}_initializeAnimationProps(){if(!this.device)throw new Error("loop");this.animationProps={animationLoop:this,device:this.device,canvas:this.device?.canvasContext?.canvas,timeline:this.timeline,useDevicePixels:this.props.useDevicePixels,needsRedraw:!1,width:1,height:1,aspect:1,time:0,startTime:Date.now(),engineTime:0,tick:0,tock:0,_mousePosition:null}}_getAnimationProps(){if(!this.animationProps)throw new Error("animationProps");return this.animationProps}_updateAnimationProps(){if(!this.animationProps)return;let{width:t,height:e,aspect:n}=this._getSizeAndAspect();(t!==this.animationProps.width||e!==this.animationProps.height)&&this.setNeedsRedraw("drawing buffer resized"),n!==this.animationProps.aspect&&this.setNeedsRedraw("drawing buffer aspect changed"),this.animationProps.width=t,this.animationProps.height=e,this.animationProps.aspect=n,this.animationProps.needsRedraw=this.needsRedraw,this.animationProps.engineTime=Date.now()-this.animationProps.startTime,this.timeline&&this.timeline.update(this.animationProps.engineTime),this.animationProps.tick=Math.floor(this.animationProps.time/1e3*60),this.animationProps.tock++,this.animationProps.time=this.timeline?this.timeline.getTime():this.animationProps.engineTime}async _initDevice(){if(this.device=await this.props.device,!this.device)throw new Error("No device provided");this.canvas=this.device.canvasContext?.canvas||null}_createInfoDiv(){if(this.canvas&&this.props.onAddHTML){let t=document.createElement("div");document.body.appendChild(t),t.style.position="relative";let e=document.createElement("div");e.style.position="absolute",e.style.left="10px",e.style.bottom="10px",e.style.width="300px",e.style.background="white",this.canvas instanceof HTMLCanvasElement&&t.appendChild(this.canvas),t.appendChild(e);let n=this.props.onAddHTML(e);n&&(e.innerHTML=n)}}_getSizeAndAspect(){if(!this.device)return{width:1,height:1,aspect:1};let[t,e]=this.device?.canvasContext?.getPixelSize()||[1,1],n=1,r=this.device?.canvasContext?.canvas;return r&&r.clientHeight?n=r.clientWidth/r.clientHeight:t>0&&e>0&&(n=t/e),{width:t,height:e,aspect:n}}_resizeViewport(){this.props.autoResizeViewport&&this.device.gl&&this.device.gl.viewport(0,0,this.device.gl.drawingBufferWidth,this.device.gl.drawingBufferHeight)}_resizeCanvasDrawingBuffer(){this.props.autoResizeDrawingBuffer&&this.device?.canvasContext?.resize({useDevicePixels:this.props.useDevicePixels})}_beginFrameTimers(){this.frameRate.timeEnd(),this.frameRate.timeStart(),this.cpuTime.timeStart()}_endFrameTimers(){this.cpuTime.timeEnd()}_startEventHandling(){this.canvas&&(this.canvas.addEventListener("mousemove",this._onMousemove.bind(this)),this.canvas.addEventListener("mouseleave",this._onMouseleave.bind(this)))}_onMousemove(t){t instanceof MouseEvent&&(this._getAnimationProps()._mousePosition=[t.offsetX,t.offsetY])}_onMouseleave(t){this._getAnimationProps()._mousePosition=null}};var nn=C(z(),1);function rn(s,t){let e=null,n=t?.device||nn.luma.createDevice(),r=new St({...t,device:n,async onInitialize(i){return e=new s(i),await e?.onInitialize(i)},onRender:i=>e?.onRender(i),onFinalize:i=>e?.onFinalize(i)});return r.getInfo=()=>this.AnimationLoopTemplateCtor.info,r}var ft=C(z(),1),De=C(z(),1),D=C(z(),1),Ue=C(z(),1);function nt(s,t){if(!s)throw new Error(t||"shadertools: assertion failed.")}var Ke={number:{type:"number",validate(s,t){return Number.isFinite(s)&&typeof t=="object"&&(t.max===void 0||s<=t.max)&&(t.min===void 0||s>=t.min)}},array:{type:"array",validate(s,t){return Array.isArray(s)||ArrayBuffer.isView(s)}}};function an(s){let t={};for(let[e,n]of Object.entries(s))t[e]=Dr(n);return t}function cn(s,t,e){let n={};for(let[r,i]of Object.entries(t))s&&r in s&&!i.private?(i.validate&&nt(i.validate(s[r],i),`${e}: invalid ${r}`),n[r]=s[r]):n[r]=i.value;return n}function Dr(s){let t=on(s);if(t!=="object")return{value:s,...Ke[t],type:t};if(typeof s=="object")return s?s.type!==void 0?{...s,...Ke[s.type],type:s.type}:s.value===void 0?{type:"object",value:s}:(t=on(s.value),{...s,...Ke[t],type:t}):{type:"object",value:null};throw new Error("props")}function on(s){return Array.isArray(s)||ArrayBuffer.isView(s)?"array":typeof s}var hn=`#ifdef MODULE_LOGDEPTH
8
8
  logdepth_adjustPosition(gl_Position);
9
9
  #endif
10
- `,nn=`#ifdef MODULE_MATERIAL
10
+ `,ln=`#ifdef MODULE_MATERIAL
11
11
  gl_FragColor = material_filterColor(gl_FragColor);
12
12
  #endif
13
13
  #ifdef MODULE_LIGHTING
@@ -23,14 +23,14 @@ gl_FragColor = picking_filterPickingColor(gl_FragColor);
23
23
  #ifdef MODULE_LOGDEPTH
24
24
  logdepth_setFragDepth();
25
25
  #endif
26
- `;var Lr={vertex:sn,fragment:nn},rn=/void\s+main\s*\([^)]*\)\s*\{\n?/,on=/}\n?[^{}]*$/,We=[],jt="__LUMA_INJECT_DECLARATIONS__";function an(s){let t={vertex:{},fragment:{}};for(let e in s){let n=s[e],r=Rr(e);typeof n=="string"&&(n={order:0,injection:n}),t[r][e]=n}return t}function Rr(s){let t=s.slice(0,2);switch(t){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(t)}}function Gt(s,t,e,n=!1){let r=t==="vertex";for(let i in e){let o=e[i];o.sort((h,f)=>h.order-f.order),We.length=o.length;for(let h=0,f=o.length;h<f;++h)We[h]=o[h].injection;let c=`${We.join(`
26
+ `;var Ur={vertex:hn,fragment:ln},un=/void\s+main\s*\([^)]*\)\s*\{\n?/,fn=/}\n?[^{}]*$/,Ze=[],Gt="__LUMA_INJECT_DECLARATIONS__";function dn(s){let t={vertex:{},fragment:{}};for(let e in s){let n=s[e],r=qr(e);typeof n=="string"&&(n={order:0,injection:n}),t[r][e]=n}return t}function qr(s){let t=s.slice(0,2);switch(t){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(t)}}function Wt(s,t,e,n=!1){let r=t==="vertex";for(let i in e){let o=e[i];o.sort((h,f)=>h.order-f.order),Ze.length=o.length;for(let h=0,f=o.length;h<f;++h)Ze[h]=o[h].injection;let c=`${Ze.join(`
27
27
  `)}
28
- `;switch(i){case"vs:#decl":r&&(s=s.replace(jt,c));break;case"vs:#main-start":r&&(s=s.replace(rn,h=>h+c));break;case"vs:#main-end":r&&(s=s.replace(on,h=>c+h));break;case"fs:#decl":r||(s=s.replace(jt,c));break;case"fs:#main-start":r||(s=s.replace(rn,h=>h+c));break;case"fs:#main-end":r||(s=s.replace(on,h=>c+h));break;default:s=s.replace(i,h=>h+c)}}return s=s.replace(jt,""),n&&(s=s.replace(/\}\s*$/,i=>i+Lr[t])),s}var zr=1,Q=class{name;vs;fs;getModuleUniforms;dependencies;deprecations;defines;injections;uniforms={};uniformTypes={};static instantiateModules(t){return t.map(e=>{if(e instanceof Q)return e;st(typeof e!="string",`Shader module use by name is deprecated. Import shader module '${JSON.stringify(e)}' and use it directly.`),e.name||(console.warn("shader module has no name"),e.name=`shader-module-${zr++}`);let n=new Q(e);return n.dependencies=Q.instantiateModules(e.dependencies||[]),n})}constructor(t){let{name:e,vs:n,fs:r,dependencies:i=[],uniformTypes:o={},uniformPropTypes:c={},getUniforms:h,deprecations:f=[],defines:m={},inject:d={}}=t;st(typeof e=="string"),this.name=e,this.vs=n,this.fs=r,this.getModuleUniforms=h,this.dependencies=Q.instantiateModules(i),this.deprecations=this._parseDeprecationDefinitions(f),this.defines=m,this.injections=an(d),this.uniformTypes=o,c&&(this.uniforms=tn(c))}getModuleSource(t){let e;switch(t){case"vertex":e=this.vs||"";break;case"fragment":e=this.fs||"";break;default:st(!1)}let n=this.name.toUpperCase().replace(/[^0-9a-z]/gi,"_");return`// ----- MODULE ${this.name} ---------------
28
+ `;switch(i){case"vs:#decl":r&&(s=s.replace(Gt,c));break;case"vs:#main-start":r&&(s=s.replace(un,h=>h+c));break;case"vs:#main-end":r&&(s=s.replace(fn,h=>c+h));break;case"fs:#decl":r||(s=s.replace(Gt,c));break;case"fs:#main-start":r||(s=s.replace(un,h=>h+c));break;case"fs:#main-end":r||(s=s.replace(fn,h=>c+h));break;default:s=s.replace(i,h=>h+c)}}return s=s.replace(Gt,""),n&&(s=s.replace(/\}\s*$/,i=>i+Ur[t])),s}var $r=1,Q=class{name;vs;fs;getModuleUniforms;dependencies;deprecations;defines;injections;uniforms={};uniformTypes={};static instantiateModules(t){return t.map(e=>{if(e instanceof Q)return e;nt(typeof e!="string",`Shader module use by name is deprecated. Import shader module '${JSON.stringify(e)}' and use it directly.`),e.name||(console.warn("shader module has no name"),e.name=`shader-module-${$r++}`);let n=new Q(e);return n.dependencies=Q.instantiateModules(e.dependencies||[]),n})}constructor(t){let{name:e,vs:n,fs:r,dependencies:i=[],uniformTypes:o={},uniformPropTypes:c={},getUniforms:h,deprecations:f=[],defines:m={},inject:p={}}=t;nt(typeof e=="string"),this.name=e,this.vs=n,this.fs=r,this.getModuleUniforms=h,this.dependencies=Q.instantiateModules(i),this.deprecations=this._parseDeprecationDefinitions(f),this.defines=m,this.injections=dn(p),this.uniformTypes=o,c&&(this.uniforms=an(c))}getModuleSource(t){let e;switch(t){case"vertex":e=this.vs||"";break;case"fragment":e=this.fs||"";break;default:nt(!1)}let n=this.name.toUpperCase().replace(/[^0-9a-z]/gi,"_");return`// ----- MODULE ${this.name} ---------------
29
29
 
30
30
  #define MODULE_${n}
31
31
  ${e}
32
32
 
33
- `}getUniforms(t,e){return this.getModuleUniforms?this.getModuleUniforms(t,e):en(t,this.uniforms,this.name)}getDefines(){return this.defines}checkDeprecations(t,e){this.deprecations.forEach(n=>{n.regex?.test(t)&&(n.deprecated?e.deprecated(n.old,n.new)():e.removed(n.old,n.new)())})}_parseDeprecationDefinitions(t){return t.forEach(e=>{switch(e.type){case"function":e.regex=new RegExp(`\\b${e.old}\\(`);break;default:e.regex=new RegExp(`${e.type} ${e.old};`)}}),t}_defaultGetUniforms(t={}){let e={},n=this.uniforms;for(let r in n){let i=n[r];r in t&&!i.private?(i.validate&&st(i.validate(t[r],i),`${this.name}: invalid ${r}`),e[r]=t[r]):e[r]=i.value}return e}};function He(s){if(s.source&&s.platformInfo.type==="webgpu")return{...s,vs:void 0,fs:void 0};if(!s.vs)throw new Error("no vertex shader");let t=cn(s.platformInfo,s.vs),e;return s.fs&&(e=cn(s.platformInfo,s.fs)),{...s,vs:t,fs:e}}function cn(s,t){if(typeof t=="string")return t;switch(s.type){case"webgpu":if(t?.wgsl)return t.wgsl;throw new Error("WebGPU does not support GLSL shaders");default:if(t?.glsl)return t.glsl;throw new Error("WebGL does not support WGSL shaders")}}function wt(s){let t=Q.instantiateModules(s);return Cr(t)}function Cr(s){let t={},e={};return hn({modules:s,level:0,moduleMap:t,moduleDepth:e}),Object.keys(e).sort((n,r)=>e[r]-e[n]).map(n=>t[n])}function hn(s){let{modules:t,level:e,moduleMap:n,moduleDepth:r}=s;if(e>=5)throw new Error("Possible loop in shader dependency graph");for(let i of t)n[i.name]=i,(r[i.name]===void 0||r[i.name]<e)&&(r[i.name]=e);for(let i of t)i.dependencies&&hn({modules:i.dependencies,level:e+1,moduleMap:n,moduleDepth:r})}function ln(s){switch(s?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
33
+ `}getUniforms(t,e){return this.getModuleUniforms?this.getModuleUniforms(t,e):cn(t,this.uniforms,this.name)}getDefines(){return this.defines}checkDeprecations(t,e){this.deprecations.forEach(n=>{n.regex?.test(t)&&(n.deprecated?e.deprecated(n.old,n.new)():e.removed(n.old,n.new)())})}_parseDeprecationDefinitions(t){return t.forEach(e=>{switch(e.type){case"function":e.regex=new RegExp(`\\b${e.old}\\(`);break;default:e.regex=new RegExp(`${e.type} ${e.old};`)}}),t}_defaultGetUniforms(t={}){let e={},n=this.uniforms;for(let r in n){let i=n[r];r in t&&!i.private?(i.validate&&nt(i.validate(t[r],i),`${this.name}: invalid ${r}`),e[r]=t[r]):e[r]=i.value}return e}};function Je(s){if(s.source&&s.platformInfo.type==="webgpu")return{...s,vs:void 0,fs:void 0};if(!s.vs)throw new Error("no vertex shader");let t=mn(s.platformInfo,s.vs),e;return s.fs&&(e=mn(s.platformInfo,s.fs)),{...s,vs:t,fs:e}}function mn(s,t){if(typeof t=="string")return t;switch(s.type){case"webgpu":if(t?.wgsl)return t.wgsl;throw new Error("WebGPU does not support GLSL shaders");default:if(t?.glsl)return t.glsl;throw new Error("WebGL does not support WGSL shaders")}}function kt(s){let t=Q.instantiateModules(s);return Br(t)}function Br(s){let t={},e={};return pn({modules:s,level:0,moduleMap:t,moduleDepth:e}),Object.keys(e).sort((n,r)=>e[r]-e[n]).map(n=>t[n])}function pn(s){let{modules:t,level:e,moduleMap:n,moduleDepth:r}=s;if(e>=5)throw new Error("Possible loop in shader dependency graph");for(let i of t)n[i.name]=i,(r[i.name]===void 0||r[i.name]<e)&&(r[i.name]=e);for(let i of t)i.dependencies&&pn({modules:i.dependencies,level:e+1,moduleMap:n,moduleDepth:r})}function _n(s){switch(s?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
34
34
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
35
35
  #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
36
36
  #define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
@@ -45,46 +45,46 @@ ${e}
45
45
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
46
46
  #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
47
47
  #define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
48
- `}}function fn(s,t){if(Number(s.match(/^#version[ \t]+(\d+)/m)?.[1]||100)!==300)throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");switch(t){case"vertex":return s=un(s,Fr),s;case"fragment":return s=un(s,Dr),s;default:throw new Error(t)}}var dn=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
49
- `],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],Fr=[...dn,[Ye("attribute"),"in $1"],[Ye("varying"),"out $1"]],Dr=[...dn,[Ye("varying"),"in $1"]];function un(s,t){for(let[e,n]of t)s=s.replace(e,n);return s}function Ye(s){return new RegExp(`\\b${s}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function Xe(s,t){let e="";for(let n in s){let r=s[n];if(e+=`void ${r.signature} {
48
+ `}}function xn(s,t){if(Number(s.match(/^#version[ \t]+(\d+)/m)?.[1]||100)!==300)throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");switch(t){case"vertex":return s=gn(s,Vr),s;case"fragment":return s=gn(s,jr),s;default:throw new Error(t)}}var yn=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
49
+ `],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],Vr=[...yn,[Qe("attribute"),"in $1"],[Qe("varying"),"out $1"]],jr=[...yn,[Qe("varying"),"in $1"]];function gn(s,t){for(let[e,n]of t)s=s.replace(e,n);return s}function Qe(s){return new RegExp(`\\b${s}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function ts(s,t){let e="";for(let n in s){let r=s[n];if(e+=`void ${r.signature} {
50
50
  `,r.header&&(e+=` ${r.header}`),t[n]){let i=t[n];i.sort((o,c)=>o.order-c.order);for(let o of i)e+=` ${o.injection}
51
51
  `}r.footer&&(e+=` ${r.footer}`),e+=`}
52
- `}return e}function Ke(s){let t={vertex:{},fragment:{}};for(let e of s){let n,r;typeof e!="string"?(n=e,r=n.hook):(n={},r=e),r=r.trim();let[i,o]=r.split(":"),c=r.replace(/\(.+/,""),h=Object.assign(n,{signature:o});switch(i){case"vs":t.vertex[c]=h;break;case"fs":t.fragment[c]=h;break;default:throw new Error(i)}}return t}function mn(s,t){return{name:Ur(s,t),language:"glsl",version:qr(s)}}function Ur(s,t="unnamed"){let n=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(s);return n?n[1]:t}function qr(s){let t=100,e=s.match(/[^\s]+/g);if(e&&e.length>=2&&e[0]==="#version"){let n=parseInt(e[1],10);Number.isFinite(n)&&(t=n)}if(t!==100&&t!==300)throw new Error(`Invalid GLSL version ${t}`);return t}var _n=`
52
+ `}return e}function es(s){let t={vertex:{},fragment:{}};for(let e of s){let n,r;typeof e!="string"?(n=e,r=n.hook):(n={},r=e),r=r.trim();let[i,o]=r.split(":"),c=r.replace(/\(.+/,""),h=Object.assign(n,{signature:o});switch(i){case"vs":t.vertex[c]=h;break;case"fs":t.fragment[c]=h;break;default:throw new Error(i)}}return t}function wn(s,t){return{name:Gr(s,t),language:"glsl",version:Wr(s)}}function Gr(s,t="unnamed"){let n=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(s);return n?n[1]:t}function Wr(s){let t=100,e=s.match(/[^\s]+/g);if(e&&e.length>=2&&e[0]==="#version"){let n=parseInt(e[1],10);Number.isFinite(n)&&(t=n)}if(t!==100&&t!==300)throw new Error(`Invalid GLSL version ${t}`);return t}var vn=`
53
53
 
54
- ${jt}
55
- `,Vr=`precision highp float;
56
- `;function gn(s){let t=wt(s.modules||[]);return{source:Ze(s.platformInfo,{...s,source:s.source,stage:"vertex",modules:t}),getUniforms:Je(t)}}function xn(s){let t=wt(s.modules||[]);return{vs:Ze(s.platformInfo,{...s,source:s.vs,stage:"vertex",modules:t}),fs:Ze(s.platformInfo,{...s,source:s.fs,stage:"fragment",modules:t}),getUniforms:Je(t)}}function yn(s){let{vs:t,fs:e}=s,n=wt(s.modules||[]);return{vs:pn(s.platformInfo,{...s,source:t,stage:"vertex",modules:n}),fs:pn(s.platformInfo,{...s,source:e,stage:"fragment",modules:n}),getUniforms:Je(n)}}function Ze(s,t){let{source:e,stage:n,modules:r,hookFunctions:i=[],inject:o={},log:c}=t;st(typeof e=="string","shader source must be a string");let h=e,f="",m=Ke(i),d={},_={},y={};for(let g in o){let w=typeof o[g]=="string"?{injection:o[g],order:0}:o[g],M=/^(v|f)s:(#)?([\w-]+)$/.exec(g);if(M){let k=M[2],x=M[3];k?x==="decl"?_[g]=[w]:y[g]=[w]:d[g]=[w]}else y[g]=[w]}let S=s.type!=="webgpu"?r:[];for(let g of S){c&&g.checkDeprecations(h,c);let w=g.getModuleSource(n,"wgsl");f+=w;let M=g.injections[n];for(let k in M){let x=/^(v|f)s:#([\w-]+)$/.exec(k);if(x){let b=x[2]==="decl"?_:y;b[k]=b[k]||[],b[k].push(M[k])}else d[k]=d[k]||[],d[k].push(M[k])}}return f+=_n,f=Gt(f,n,_),f+=Xe(m[n],d),f+=h,f=Gt(f,n,y),f}function pn(s,t){let{id:e,source:n,stage:r,language:i="glsl",modules:o,defines:c={},hookFunctions:h=[],inject:f={},prologue:m=!0,log:d}=t;st(typeof n=="string","shader source must be a string");let _=i==="glsl"?mn(n).version:-1,y=s.shaderLanguageVersion,S=_===100?"#version 100":"#version 300 es",w=n.split(`
54
+ ${Gt}
55
+ `,Hr=`precision highp float;
56
+ `;function bn(s){let t=kt(s.modules||[]);return{source:ss(s.platformInfo,{...s,source:s.source,stage:"vertex",modules:t}),getUniforms:ns(t)}}function Mn(s){let t=kt(s.modules||[]);return{vs:ss(s.platformInfo,{...s,source:s.vs,stage:"vertex",modules:t}),fs:ss(s.platformInfo,{...s,source:s.fs,stage:"fragment",modules:t}),getUniforms:ns(t)}}function Sn(s){let{vs:t,fs:e}=s,n=kt(s.modules||[]);return{vs:kn(s.platformInfo,{...s,source:t,stage:"vertex",modules:n}),fs:kn(s.platformInfo,{...s,source:e,stage:"fragment",modules:n}),getUniforms:ns(n)}}function ss(s,t){let{source:e,stage:n,modules:r,hookFunctions:i=[],inject:o={},log:c}=t;nt(typeof e=="string","shader source must be a string");let h=e,f="",m=es(i),p={},_={},y={};for(let g in o){let w=typeof o[g]=="string"?{injection:o[g],order:0}:o[g],M=/^(v|f)s:(#)?([\w-]+)$/.exec(g);if(M){let b=M[2],x=M[3];b?x==="decl"?_[g]=[w]:y[g]=[w]:p[g]=[w]}else y[g]=[w]}let S=s.type!=="webgpu"?r:[];for(let g of S){c&&g.checkDeprecations(h,c);let w=g.getModuleSource(n,"wgsl");f+=w;let M=g.injections[n];for(let b in M){let x=/^(v|f)s:#([\w-]+)$/.exec(b);if(x){let v=x[2]==="decl"?_:y;v[b]=v[b]||[],v[b].push(M[b])}else p[b]=p[b]||[],p[b].push(M[b])}}return f+=vn,f=Wt(f,n,_),f+=ts(m[n],p),f+=h,f=Wt(f,n,y),f}function kn(s,t){let{id:e,source:n,stage:r,language:i="glsl",modules:o,defines:c={},hookFunctions:h=[],inject:f={},prologue:m=!0,log:p}=t;nt(typeof n=="string","shader source must be a string");let _=i==="glsl"?wn(n).version:-1,y=s.shaderLanguageVersion,S=_===100?"#version 100":"#version 300 es",w=n.split(`
57
57
  `).slice(1).join(`
58
- `),M={};o.forEach(T=>{Object.assign(M,T.getDefines())}),Object.assign(M,c);let k="";switch(i){case"wgsl":break;case"glsl":k=m?`${S}
58
+ `),M={};o.forEach(T=>{Object.assign(M,T.getDefines())}),Object.assign(M,c);let b="";switch(i){case"wgsl":break;case"glsl":b=m?`${S}
59
59
 
60
60
  // ----- PROLOGUE -------------------------
61
- ${$r({id:e,source:n,stage:r})}
61
+ ${Yr({id:e,source:n,stage:r})}
62
62
  ${`#define SHADER_TYPE_${r.toUpperCase()}`}
63
- ${ln(s)}
64
- ${r==="fragment"?Vr:""}
63
+ ${_n(s)}
64
+ ${r==="fragment"?Hr:""}
65
65
 
66
66
  // ----- APPLICATION DEFINES -------------------------
67
67
 
68
- ${jr(M)}
68
+ ${Xr(M)}
69
69
 
70
70
  `:`${S}
71
- `;break}let x=Ke(h),v={},b={},E={};for(let T in f){let R=typeof f[T]=="string"?{injection:f[T],order:0}:f[T],O=/^(v|f)s:(#)?([\w-]+)$/.exec(T);if(O){let I=O[2],A=O[3];I?A==="decl"?b[T]=[R]:E[T]=[R]:v[T]=[R]}else E[T]=[R]}for(let T of o){d&&T.checkDeprecations(w,d);let R=T.getModuleSource(r);k+=R;let O=T.injections[r];for(let I in O){let A=/^(v|f)s:#([\w-]+)$/.exec(I);if(A){let L=A[2]==="decl"?b:E;L[I]=L[I]||[],L[I].push(O[I])}else v[I]=v[I]||[],v[I].push(O[I])}}return k+="// ----- MAIN SHADER SOURCE -------------------------",k+=_n,k=Gt(k,r,b),k+=Xe(x[r],v),k+=w,k=Gt(k,r,E),i==="glsl"&&_!==y&&(k=fn(k,r)),k.trim()}function Je(s){return function(e){let n={};for(let r of s){let i=r.getUniforms(e,n);Object.assign(n,i)}return n}}function $r(s){let{id:t,source:e,stage:n}=s;return t&&e.indexOf("SHADER_NAME")===-1?`
71
+ `;break}let x=es(h),k={},v={},A={};for(let T in f){let R=typeof f[T]=="string"?{injection:f[T],order:0}:f[T],O=/^(v|f)s:(#)?([\w-]+)$/.exec(T);if(O){let N=O[2],E=O[3];N?E==="decl"?v[T]=[R]:A[T]=[R]:k[T]=[R]}else A[T]=[R]}for(let T of o){p&&T.checkDeprecations(w,p);let R=T.getModuleSource(r);b+=R;let O=T.injections[r];for(let N in O){let E=/^(v|f)s:#([\w-]+)$/.exec(N);if(E){let P=E[2]==="decl"?v:A;P[N]=P[N]||[],P[N].push(O[N])}else k[N]=k[N]||[],k[N].push(O[N])}}return b+="// ----- MAIN SHADER SOURCE -------------------------",b+=vn,b=Wt(b,r,v),b+=ts(x[r],k),b+=w,b=Wt(b,r,A),i==="glsl"&&_!==y&&(b=xn(b,r)),b.trim()}function ns(s){return function(e){let n={};for(let r of s){let i=r.getUniforms(e,n);Object.assign(n,i)}return n}}function Yr(s){let{id:t,source:e,stage:n}=s;return t&&e.indexOf("SHADER_NAME")===-1?`
72
72
  #define SHADER_NAME ${t}_${n}
73
73
 
74
- `:""}function jr(s={}){let t="";for(let e in s){let n=s[e];(n||Number.isFinite(n))&&(t+=`#define ${e.toUpperCase()} ${s[e]}
75
- `)}return t}var Et=class{_hookFunctions=[];_defaultModules=[];static getDefaultShaderAssembler(){return Et.defaultShaderAssembler=Et.defaultShaderAssembler||new Et,Et.defaultShaderAssembler}addDefaultModule(t){this._defaultModules.find(e=>e.name===(typeof t=="string"?t:t.name))||this._defaultModules.push(t)}removeDefaultModule(t){let e=typeof t=="string"?t:t.name;this._defaultModules=this._defaultModules.filter(n=>n.name!==e)}addShaderHook(t,e){e&&(t=Object.assign(e,{hook:t})),this._hookFunctions.push(t)}assembleShader(t){let e=this._getModuleList(t.modules),n=this._hookFunctions,r=He(t);return{...gn({platformInfo:t.platformInfo,...r,modules:e,hookFunctions:n}),modules:e}}assembleShaderPair(t){let e=He(t),n=this._getModuleList(t.modules),r=this._hookFunctions,{platformInfo:i}=t;return{...t.platformInfo.shaderLanguage==="wgsl"?xn({platformInfo:i,...e,modules:n,hookFunctions:r}):yn({platformInfo:i,...e,modules:n,hookFunctions:r}),modules:n}}_getModuleList(t=[]){let e=new Array(this._defaultModules.length+t.length),n={},r=0;for(let i=0,o=this._defaultModules.length;i<o;++i){let c=this._defaultModules[i],h=c.name;e[r++]=c,n[h]=!0}for(let i=0,o=t.length;i<o;++i){let c=t[i],h=c.name;n[h]||(e[r++]=c,n[h]=!0)}return e.length=r,Q.instantiateModules(e)}},dt=Et;et(dt,"defaultShaderAssembler");var Gr=`out vec4 transform_output;
74
+ `:""}function Xr(s={}){let t="";for(let e in s){let n=s[e];(n||Number.isFinite(n))&&(t+=`#define ${e.toUpperCase()} ${s[e]}
75
+ `)}return t}var At=class{_hookFunctions=[];_defaultModules=[];static getDefaultShaderAssembler(){return At.defaultShaderAssembler=At.defaultShaderAssembler||new At,At.defaultShaderAssembler}addDefaultModule(t){this._defaultModules.find(e=>e.name===(typeof t=="string"?t:t.name))||this._defaultModules.push(t)}removeDefaultModule(t){let e=typeof t=="string"?t:t.name;this._defaultModules=this._defaultModules.filter(n=>n.name!==e)}addShaderHook(t,e){e&&(t=Object.assign(e,{hook:t})),this._hookFunctions.push(t)}assembleShader(t){let e=this._getModuleList(t.modules),n=this._hookFunctions,r=Je(t);return{...bn({platformInfo:t.platformInfo,...r,modules:e,hookFunctions:n}),modules:e}}assembleShaderPair(t){let e=Je(t),n=this._getModuleList(t.modules),r=this._hookFunctions,{platformInfo:i}=t;return{...t.platformInfo.shaderLanguage==="wgsl"?Mn({platformInfo:i,...e,modules:n,hookFunctions:r}):Sn({platformInfo:i,...e,modules:n,hookFunctions:r}),modules:n}}_getModuleList(t=[]){let e=new Array(this._defaultModules.length+t.length),n={},r=0;for(let i=0,o=this._defaultModules.length;i<o;++i){let c=this._defaultModules[i],h=c.name;e[r++]=c,n[h]=!0}for(let i=0,o=t.length;i<o;++i){let c=t[i],h=c.name;n[h]||(e[r++]=c,n[h]=!0)}return e.length=r,Q.instantiateModules(e)}},mt=At;st(mt,"defaultShaderAssembler");var Kr=`out vec4 transform_output;
76
76
  void main() {
77
77
  transform_output = vec4(0);
78
- }`,Br=`#version 300 es
79
- ${Gr}`;function Bt(s){let{input:t,inputChannels:e,output:n}=s||{};if(!t)return Br;if(!e)throw new Error("inputChannels");let r=Wr(e),i=wn(t,e);return`#version 300 es
78
+ }`,Zr=`#version 300 es
79
+ ${Kr}`;function Ht(s){let{input:t,inputChannels:e,output:n}=s||{};if(!t)return Zr;if(!e)throw new Error("inputChannels");let r=Jr(e),i=An(t,e);return`#version 300 es
80
80
  in ${r} ${t};
81
81
  out vec4 ${n};
82
82
  void main() {
83
83
  ${n} = ${i};
84
- }`}function Wr(s){switch(s){case 1:return"float";case 2:return"vec2";case 3:return"vec3";case 4:return"vec4";default:throw new Error(`invalid channels: ${s}`)}}function wn(s,t){switch(t){case 1:return`vec4(${s}, 0.0, 0.0, 1.0)`;case 2:return`vec4(${s}, 0.0, 1.0)`;case 3:return`vec4(${s}, 1.0)`;case 4:return s;default:throw new Error(`invalid channels: ${t}`)}}var bn=C(z(),1);var Qe=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},it=class{constructor(){}get isAstNode(){return!0}get astNodeType(){return""}evaluate(t){throw new Error("Cannot evaluate node")}evaluateString(t){return this.evaluate(t).toString()}},D=class extends it{constructor(){super()}},ae=class extends D{constructor(t,e,n,r){super(),this.name=t,this.args=e,this.returnType=n,this.body=r}get astNodeType(){return"function"}},ts=class extends D{constructor(t){super(),this.expression=t}get astNodeType(){return"staticAssert"}},es=class extends D{constructor(t,e){super(),this.condition=t,this.body=e}get astNodeType(){return"while"}},ss=class extends D{constructor(t){super(),this.body=t}get astNodeType(){return"continuing"}},ns=class extends D{constructor(t,e,n,r){super(),this.init=t,this.condition=e,this.increment=n,this.body=r}get astNodeType(){return"for"}},pt=class extends D{constructor(t,e,n,r,i){super(),this.name=t,this.type=e,this.storage=n,this.access=r,this.value=i}get astNodeType(){return"var"}},ce=class extends D{constructor(t,e,n){super(),this.name=t,this.type=e,this.value=n}get astNodeType(){return"override"}},he=class extends D{constructor(t,e,n,r,i){super(),this.name=t,this.type=e,this.storage=n,this.access=r,this.value=i}get astNodeType(){return"let"}},le=class extends D{constructor(t,e,n,r,i){super(),this.name=t,this.type=e,this.storage=n,this.access=r,this.value=i}get astNodeType(){return"const"}evaluate(t){return this.value.evaluate(t)}},Pt;(function(s){s.increment="++",s.decrement="--"})(Pt||(Pt={}));(function(s){function t(e){let n=e;if(n=="parse")throw new Error("Invalid value for IncrementOperator");return s[n]}s.parse=t})(Pt||(Pt={}));var rs=class extends D{constructor(t,e){super(),this.operator=t,this.variable=e}get astNodeType(){return"increment"}},Ht;(function(s){s.assign="=",s.addAssign="+=",s.subtractAssin="-=",s.multiplyAssign="*=",s.divideAssign="/=",s.moduloAssign="%=",s.andAssign="&=",s.orAssign="|=",s.xorAssign="^=",s.shiftLeftAssign="<<=",s.shiftRightAssign=">>="})(Ht||(Ht={}));(function(s){function t(e){let n=e;if(n=="parse")throw new Error("Invalid value for AssignOperator");return s[n]}s.parse=t})(Ht||(Ht={}));var is=class extends D{constructor(t,e,n){super(),this.operator=t,this.variable=e,this.value=n}get astNodeType(){return"assign"}},os=class extends D{constructor(t,e){super(),this.name=t,this.args=e}get astNodeType(){return"call"}},as=class extends D{constructor(t,e){super(),this.body=t,this.continuing=e}get astNodeType(){return"loop"}},cs=class extends D{constructor(t,e){super(),this.condition=t,this.body=e}get astNodeType(){return"body"}},hs=class extends D{constructor(t,e,n,r){super(),this.condition=t,this.body=e,this.elseif=n,this.else=r}get astNodeType(){return"if"}},ls=class extends D{constructor(t){super(),this.value=t}get astNodeType(){return"return"}},us=class extends D{constructor(t){super(),this.name=t}get astNodeType(){return"enable"}},ue=class extends D{constructor(t,e){super(),this.name=t,this.type=e}get astNodeType(){return"alias"}},fs=class extends D{constructor(){super()}get astNodeType(){return"discard"}},ds=class extends D{constructor(){super()}get astNodeType(){return"break"}},ms=class extends D{constructor(){super()}get astNodeType(){return"continue"}},ot=class extends D{constructor(t){super(),this.name=t}get astNodeType(){return"type"}get isStruct(){return!1}get isArray(){return!1}},rt=class extends ot{constructor(t,e){super(t),this.members=e}get astNodeType(){return"struct"}get isStruct(){return!0}getMemberIndex(t){for(let e=0;e<this.members.length;e++)if(this.members[e].name==t)return e;return-1}},fe=class extends ot{constructor(t,e,n){super(t),this.format=e,this.access=n}get astNodeType(){return"template"}},ps=class extends ot{constructor(t,e,n,r){super(t),this.storage=e,this.type=n,this.access=r}get astNodeType(){return"pointer"}},de=class extends ot{constructor(t,e,n,r){super(t),this.attributes=e,this.format=n,this.count=r}get astNodeType(){return"array"}get isArray(){return!0}},vt=class extends ot{constructor(t,e,n){super(t),this.format=e,this.access=n}get astNodeType(){return"sampler"}},X=class extends it{constructor(){super()}},me=class extends X{constructor(t){super(),this.value=t}get astNodeType(){return"stringExpr"}toString(){return this.value}evaluateString(){return this.value}},bt=class extends X{constructor(t,e){super(),this.type=t,this.args=e}get astNodeType(){return"createExpr"}},_s=class extends X{constructor(t,e){super(),this.name=t,this.args=e}get astNodeType(){return"callExpr"}evaluate(t){switch(this.name){case"abs":return Math.abs(this.args[0].evaluate(t));case"acos":return Math.acos(this.args[0].evaluate(t));case"acosh":return Math.acosh(this.args[0].evaluate(t));case"asin":return Math.asin(this.args[0].evaluate(t));case"asinh":return Math.asinh(this.args[0].evaluate(t));case"atan":return Math.atan(this.args[0].evaluate(t));case"atan2":return Math.atan2(this.args[0].evaluate(t),this.args[1].evaluate(t));case"atanh":return Math.atanh(this.args[0].evaluate(t));case"ceil":return Math.ceil(this.args[0].evaluate(t));case"clamp":return Math.min(Math.max(this.args[0].evaluate(t),this.args[1].evaluate(t)),this.args[2].evaluate(t));case"cos":return Math.cos(this.args[0].evaluate(t));case"degrees":return this.args[0].evaluate(t)*180/Math.PI;case"distance":return Math.sqrt(Math.pow(this.args[0].evaluate(t)-this.args[1].evaluate(t),2));case"dot":case"exp":return Math.exp(this.args[0].evaluate(t));case"exp2":return Math.pow(2,this.args[0].evaluate(t));case"floor":return Math.floor(this.args[0].evaluate(t));case"fma":return this.args[0].evaluate(t)*this.args[1].evaluate(t)+this.args[2].evaluate(t);case"fract":return this.args[0].evaluate(t)-Math.floor(this.args[0].evaluate(t));case"inverseSqrt":return 1/Math.sqrt(this.args[0].evaluate(t));case"log":return Math.log(this.args[0].evaluate(t));case"log2":return Math.log2(this.args[0].evaluate(t));case"max":return Math.max(this.args[0].evaluate(t),this.args[1].evaluate(t));case"min":return Math.min(this.args[0].evaluate(t),this.args[1].evaluate(t));case"mix":return this.args[0].evaluate(t)*(1-this.args[2].evaluate(t))+this.args[1].evaluate(t)*this.args[2].evaluate(t);case"modf":return this.args[0].evaluate(t)-Math.floor(this.args[0].evaluate(t));case"pow":return Math.pow(this.args[0].evaluate(t),this.args[1].evaluate(t));case"radians":return this.args[0].evaluate(t)*Math.PI/180;case"round":return Math.round(this.args[0].evaluate(t));case"sign":return Math.sign(this.args[0].evaluate(t));case"sin":return Math.sin(this.args[0].evaluate(t));case"sinh":return Math.sinh(this.args[0].evaluate(t));case"saturate":return Math.min(Math.max(this.args[0].evaluate(t),0),1);case"smoothstep":return this.args[0].evaluate(t)*this.args[0].evaluate(t)*(3-2*this.args[0].evaluate(t));case"sqrt":return Math.sqrt(this.args[0].evaluate(t));case"step":return this.args[0].evaluate(t)<this.args[1].evaluate(t)?0:1;case"tan":return Math.tan(this.args[0].evaluate(t));case"tanh":return Math.tanh(this.args[0].evaluate(t));case"trunc":return Math.trunc(this.args[0].evaluate(t));default:throw new Error("Non const function: "+this.name)}}},gs=class extends X{constructor(t){super(),this.name=t}get astNodeType(){return"varExpr"}},pe=class extends X{constructor(t,e){super(),this.name=t,this.initializer=e}get astNodeType(){return"constExpr"}evaluate(t){var e,n;if(this.initializer instanceof bt){let r=(e=this.postfix)===null||e===void 0?void 0:e.evaluateString(t),i=(n=this.initializer.type)===null||n===void 0?void 0:n.name,o=t.structs.get(i),c=o?.getMemberIndex(r);if(c!=-1)return this.initializer.args[c].evaluate(t);console.log(c)}return this.initializer.evaluate(t)}},_e=class extends X{constructor(t){super(),this.value=t}get astNodeType(){return"literalExpr"}evaluate(){return this.value}},xs=class extends X{constructor(t,e){super(),this.type=t,this.value=e}get astNodeType(){return"bitcastExpr"}},ys=class extends X{constructor(t,e){super(),this.type=t,this.args=e}get astNodeType(){return"typecastExpr"}evaluate(t){return this.args[0].evaluate(t)}},ge=class extends X{constructor(t){super(),this.contents=t}get astNodeType(){return"groupExpr"}evaluate(t){return this.contents[0].evaluate(t)}},xe=class extends X{constructor(){super()}},ws=class extends xe{constructor(t,e){super(),this.operator=t,this.right=e}get astNodeType(){return"unaryOp"}evaluate(t){switch(this.operator){case"+":return this.right.evaluate(t);case"-":return-this.right.evaluate(t);case"!":return this.right.evaluate(t)?0:1;case"~":return~this.right.evaluate(t);default:throw new Error("Unknown unary operator: "+this.operator)}}},H=class extends xe{constructor(t,e,n){super(),this.operator=t,this.left=e,this.right=n}get astNodeType(){return"binaryOp"}evaluate(t){switch(this.operator){case"+":return this.left.evaluate(t)+this.right.evaluate(t);case"-":return this.left.evaluate(t)-this.right.evaluate(t);case"*":return this.left.evaluate(t)*this.right.evaluate(t);case"/":return this.left.evaluate(t)/this.right.evaluate(t);case"%":return this.left.evaluate(t)%this.right.evaluate(t);case"==":return this.left.evaluate(t)==this.right.evaluate(t)?1:0;case"!=":return this.left.evaluate(t)!=this.right.evaluate(t)?1:0;case"<":return this.left.evaluate(t)<this.right.evaluate(t)?1:0;case">":return this.left.evaluate(t)>this.right.evaluate(t)?1:0;case"<=":return this.left.evaluate(t)<=this.right.evaluate(t)?1:0;case">=":return this.left.evaluate(t)>=this.right.evaluate(t)?1:0;case"&&":return this.left.evaluate(t)&&this.right.evaluate(t)?1:0;case"||":return this.left.evaluate(t)||this.right.evaluate(t)?1:0;default:throw new Error(`Unknown operator ${this.operator}`)}}},ye=class extends it{constructor(){super()}},vs=class extends ye{constructor(t,e){super(),this.selector=t,this.body=e}get astNodeType(){return"case"}},bs=class extends ye{constructor(t){super(),this.body=t}get astNodeType(){return"default"}},ks=class extends it{constructor(t,e,n){super(),this.name=t,this.type=e,this.attributes=n}get astNodeType(){return"argument"}},Ms=class extends it{constructor(t,e){super(),this.condition=t,this.body=e}get astNodeType(){return"elseif"}},Ss=class extends it{constructor(t,e,n){super(),this.name=t,this.type=e,this.attributes=n}get astNodeType(){return"member"}},we=class extends it{constructor(t,e){super(),this.name=t,this.value=e}get astNodeType(){return"attribute"}},p,u;(function(s){s[s.token=0]="token",s[s.keyword=1]="keyword",s[s.reserved=2]="reserved"})(u||(u={}));var l=class{constructor(t,e,n){this.name=t,this.type=e,this.rule=n}toString(){return this.name}},a=class{};p=a;a.none=new l("",u.reserved,"");a.eof=new l("EOF",u.token,"");a.reserved={asm:new l("asm",u.reserved,"asm"),bf16:new l("bf16",u.reserved,"bf16"),do:new l("do",u.reserved,"do"),enum:new l("enum",u.reserved,"enum"),f16:new l("f16",u.reserved,"f16"),f64:new l("f64",u.reserved,"f64"),handle:new l("handle",u.reserved,"handle"),i8:new l("i8",u.reserved,"i8"),i16:new l("i16",u.reserved,"i16"),i64:new l("i64",u.reserved,"i64"),mat:new l("mat",u.reserved,"mat"),premerge:new l("premerge",u.reserved,"premerge"),regardless:new l("regardless",u.reserved,"regardless"),typedef:new l("typedef",u.reserved,"typedef"),u8:new l("u8",u.reserved,"u8"),u16:new l("u16",u.reserved,"u16"),u64:new l("u64",u.reserved,"u64"),unless:new l("unless",u.reserved,"unless"),using:new l("using",u.reserved,"using"),vec:new l("vec",u.reserved,"vec"),void:new l("void",u.reserved,"void")};a.keywords={array:new l("array",u.keyword,"array"),atomic:new l("atomic",u.keyword,"atomic"),bool:new l("bool",u.keyword,"bool"),f32:new l("f32",u.keyword,"f32"),i32:new l("i32",u.keyword,"i32"),mat2x2:new l("mat2x2",u.keyword,"mat2x2"),mat2x3:new l("mat2x3",u.keyword,"mat2x3"),mat2x4:new l("mat2x4",u.keyword,"mat2x4"),mat3x2:new l("mat3x2",u.keyword,"mat3x2"),mat3x3:new l("mat3x3",u.keyword,"mat3x3"),mat3x4:new l("mat3x4",u.keyword,"mat3x4"),mat4x2:new l("mat4x2",u.keyword,"mat4x2"),mat4x3:new l("mat4x3",u.keyword,"mat4x3"),mat4x4:new l("mat4x4",u.keyword,"mat4x4"),ptr:new l("ptr",u.keyword,"ptr"),sampler:new l("sampler",u.keyword,"sampler"),sampler_comparison:new l("sampler_comparison",u.keyword,"sampler_comparison"),struct:new l("struct",u.keyword,"struct"),texture_1d:new l("texture_1d",u.keyword,"texture_1d"),texture_2d:new l("texture_2d",u.keyword,"texture_2d"),texture_2d_array:new l("texture_2d_array",u.keyword,"texture_2d_array"),texture_3d:new l("texture_3d",u.keyword,"texture_3d"),texture_cube:new l("texture_cube",u.keyword,"texture_cube"),texture_cube_array:new l("texture_cube_array",u.keyword,"texture_cube_array"),texture_multisampled_2d:new l("texture_multisampled_2d",u.keyword,"texture_multisampled_2d"),texture_storage_1d:new l("texture_storage_1d",u.keyword,"texture_storage_1d"),texture_storage_2d:new l("texture_storage_2d",u.keyword,"texture_storage_2d"),texture_storage_2d_array:new l("texture_storage_2d_array",u.keyword,"texture_storage_2d_array"),texture_storage_3d:new l("texture_storage_3d",u.keyword,"texture_storage_3d"),texture_depth_2d:new l("texture_depth_2d",u.keyword,"texture_depth_2d"),texture_depth_2d_array:new l("texture_depth_2d_array",u.keyword,"texture_depth_2d_array"),texture_depth_cube:new l("texture_depth_cube",u.keyword,"texture_depth_cube"),texture_depth_cube_array:new l("texture_depth_cube_array",u.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new l("texture_depth_multisampled_2d",u.keyword,"texture_depth_multisampled_2d"),texture_external:new l("texture_external",u.keyword,"texture_external"),u32:new l("u32",u.keyword,"u32"),vec2:new l("vec2",u.keyword,"vec2"),vec3:new l("vec3",u.keyword,"vec3"),vec4:new l("vec4",u.keyword,"vec4"),bitcast:new l("bitcast",u.keyword,"bitcast"),block:new l("block",u.keyword,"block"),break:new l("break",u.keyword,"break"),case:new l("case",u.keyword,"case"),continue:new l("continue",u.keyword,"continue"),continuing:new l("continuing",u.keyword,"continuing"),default:new l("default",u.keyword,"default"),discard:new l("discard",u.keyword,"discard"),else:new l("else",u.keyword,"else"),enable:new l("enable",u.keyword,"enable"),fallthrough:new l("fallthrough",u.keyword,"fallthrough"),false:new l("false",u.keyword,"false"),fn:new l("fn",u.keyword,"fn"),for:new l("for",u.keyword,"for"),function:new l("function",u.keyword,"function"),if:new l("if",u.keyword,"if"),let:new l("let",u.keyword,"let"),const:new l("const",u.keyword,"const"),loop:new l("loop",u.keyword,"loop"),while:new l("while",u.keyword,"while"),private:new l("private",u.keyword,"private"),read:new l("read",u.keyword,"read"),read_write:new l("read_write",u.keyword,"read_write"),return:new l("return",u.keyword,"return"),storage:new l("storage",u.keyword,"storage"),switch:new l("switch",u.keyword,"switch"),true:new l("true",u.keyword,"true"),alias:new l("alias",u.keyword,"alias"),type:new l("type",u.keyword,"type"),uniform:new l("uniform",u.keyword,"uniform"),var:new l("var",u.keyword,"var"),override:new l("override",u.keyword,"override"),workgroup:new l("workgroup",u.keyword,"workgroup"),write:new l("write",u.keyword,"write"),r8unorm:new l("r8unorm",u.keyword,"r8unorm"),r8snorm:new l("r8snorm",u.keyword,"r8snorm"),r8uint:new l("r8uint",u.keyword,"r8uint"),r8sint:new l("r8sint",u.keyword,"r8sint"),r16uint:new l("r16uint",u.keyword,"r16uint"),r16sint:new l("r16sint",u.keyword,"r16sint"),r16float:new l("r16float",u.keyword,"r16float"),rg8unorm:new l("rg8unorm",u.keyword,"rg8unorm"),rg8snorm:new l("rg8snorm",u.keyword,"rg8snorm"),rg8uint:new l("rg8uint",u.keyword,"rg8uint"),rg8sint:new l("rg8sint",u.keyword,"rg8sint"),r32uint:new l("r32uint",u.keyword,"r32uint"),r32sint:new l("r32sint",u.keyword,"r32sint"),r32float:new l("r32float",u.keyword,"r32float"),rg16uint:new l("rg16uint",u.keyword,"rg16uint"),rg16sint:new l("rg16sint",u.keyword,"rg16sint"),rg16float:new l("rg16float",u.keyword,"rg16float"),rgba8unorm:new l("rgba8unorm",u.keyword,"rgba8unorm"),rgba8unorm_srgb:new l("rgba8unorm_srgb",u.keyword,"rgba8unorm_srgb"),rgba8snorm:new l("rgba8snorm",u.keyword,"rgba8snorm"),rgba8uint:new l("rgba8uint",u.keyword,"rgba8uint"),rgba8sint:new l("rgba8sint",u.keyword,"rgba8sint"),bgra8unorm:new l("bgra8unorm",u.keyword,"bgra8unorm"),bgra8unorm_srgb:new l("bgra8unorm_srgb",u.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new l("rgb10a2unorm",u.keyword,"rgb10a2unorm"),rg11b10float:new l("rg11b10float",u.keyword,"rg11b10float"),rg32uint:new l("rg32uint",u.keyword,"rg32uint"),rg32sint:new l("rg32sint",u.keyword,"rg32sint"),rg32float:new l("rg32float",u.keyword,"rg32float"),rgba16uint:new l("rgba16uint",u.keyword,"rgba16uint"),rgba16sint:new l("rgba16sint",u.keyword,"rgba16sint"),rgba16float:new l("rgba16float",u.keyword,"rgba16float"),rgba32uint:new l("rgba32uint",u.keyword,"rgba32uint"),rgba32sint:new l("rgba32sint",u.keyword,"rgba32sint"),rgba32float:new l("rgba32float",u.keyword,"rgba32float"),static_assert:new l("static_assert",u.keyword,"static_assert")};a.tokens={decimal_float_literal:new l("decimal_float_literal",u.token,/((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?f?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+f?)|([0-9]+f)/),hex_float_literal:new l("hex_float_literal",u.token,/-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+f?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+f?))/),int_literal:new l("int_literal",u.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new l("uint_literal",u.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),ident:new l("ident",u.token,/[a-zA-Z][0-9a-zA-Z_]*/),and:new l("and",u.token,"&"),and_and:new l("and_and",u.token,"&&"),arrow:new l("arrow ",u.token,"->"),attr:new l("attr",u.token,"@"),attr_left:new l("attr_left",u.token,"[["),attr_right:new l("attr_right",u.token,"]]"),forward_slash:new l("forward_slash",u.token,"/"),bang:new l("bang",u.token,"!"),bracket_left:new l("bracket_left",u.token,"["),bracket_right:new l("bracket_right",u.token,"]"),brace_left:new l("brace_left",u.token,"{"),brace_right:new l("brace_right",u.token,"}"),colon:new l("colon",u.token,":"),comma:new l("comma",u.token,","),equal:new l("equal",u.token,"="),equal_equal:new l("equal_equal",u.token,"=="),not_equal:new l("not_equal",u.token,"!="),greater_than:new l("greater_than",u.token,">"),greater_than_equal:new l("greater_than_equal",u.token,">="),shift_right:new l("shift_right",u.token,">>"),less_than:new l("less_than",u.token,"<"),less_than_equal:new l("less_than_equal",u.token,"<="),shift_left:new l("shift_left",u.token,"<<"),modulo:new l("modulo",u.token,"%"),minus:new l("minus",u.token,"-"),minus_minus:new l("minus_minus",u.token,"--"),period:new l("period",u.token,"."),plus:new l("plus",u.token,"+"),plus_plus:new l("plus_plus",u.token,"++"),or:new l("or",u.token,"|"),or_or:new l("or_or",u.token,"||"),paren_left:new l("paren_left",u.token,"("),paren_right:new l("paren_right",u.token,")"),semicolon:new l("semicolon",u.token,";"),star:new l("star",u.token,"*"),tilde:new l("tilde",u.token,"~"),underscore:new l("underscore",u.token,"_"),xor:new l("xor",u.token,"^"),plus_equal:new l("plus_equal",u.token,"+="),minus_equal:new l("minus_equal",u.token,"-="),times_equal:new l("times_equal",u.token,"*="),division_equal:new l("division_equal",u.token,"/="),modulo_equal:new l("modulo_equal",u.token,"%="),and_equal:new l("and_equal",u.token,"&="),or_equal:new l("or_equal",u.token,"|="),xor_equal:new l("xor_equal",u.token,"^="),shift_right_equal:new l("shift_right_equal",u.token,">>="),shift_left_equal:new l("shift_left_equal",u.token,"<<=")};a.storage_class=[p.keywords.function,p.keywords.private,p.keywords.workgroup,p.keywords.uniform,p.keywords.storage];a.access_mode=[p.keywords.read,p.keywords.write,p.keywords.read_write];a.sampler_type=[p.keywords.sampler,p.keywords.sampler_comparison];a.sampled_texture_type=[p.keywords.texture_1d,p.keywords.texture_2d,p.keywords.texture_2d_array,p.keywords.texture_3d,p.keywords.texture_cube,p.keywords.texture_cube_array];a.multisampled_texture_type=[p.keywords.texture_multisampled_2d];a.storage_texture_type=[p.keywords.texture_storage_1d,p.keywords.texture_storage_2d,p.keywords.texture_storage_2d_array,p.keywords.texture_storage_3d];a.depth_texture_type=[p.keywords.texture_depth_2d,p.keywords.texture_depth_2d_array,p.keywords.texture_depth_cube,p.keywords.texture_depth_cube_array,p.keywords.texture_depth_multisampled_2d];a.texture_external_type=[p.keywords.texture_external];a.any_texture_type=[...p.sampled_texture_type,...p.multisampled_texture_type,...p.storage_texture_type,...p.depth_texture_type,...p.texture_external_type];a.texel_format=[p.keywords.r8unorm,p.keywords.r8snorm,p.keywords.r8uint,p.keywords.r8sint,p.keywords.r16uint,p.keywords.r16sint,p.keywords.r16float,p.keywords.rg8unorm,p.keywords.rg8snorm,p.keywords.rg8uint,p.keywords.rg8sint,p.keywords.r32uint,p.keywords.r32sint,p.keywords.r32float,p.keywords.rg16uint,p.keywords.rg16sint,p.keywords.rg16float,p.keywords.rgba8unorm,p.keywords.rgba8unorm_srgb,p.keywords.rgba8snorm,p.keywords.rgba8uint,p.keywords.rgba8sint,p.keywords.bgra8unorm,p.keywords.bgra8unorm_srgb,p.keywords.rgb10a2unorm,p.keywords.rg11b10float,p.keywords.rg32uint,p.keywords.rg32sint,p.keywords.rg32float,p.keywords.rgba16uint,p.keywords.rgba16sint,p.keywords.rgba16float,p.keywords.rgba32uint,p.keywords.rgba32sint,p.keywords.rgba32float];a.const_literal=[p.tokens.int_literal,p.tokens.uint_literal,p.tokens.decimal_float_literal,p.tokens.hex_float_literal,p.keywords.true,p.keywords.false];a.literal_or_ident=[p.tokens.ident,p.tokens.int_literal,p.tokens.uint_literal,p.tokens.decimal_float_literal,p.tokens.hex_float_literal];a.element_count_expression=[p.tokens.int_literal,p.tokens.uint_literal,p.tokens.ident];a.template_types=[p.keywords.vec2,p.keywords.vec3,p.keywords.vec4,p.keywords.mat2x2,p.keywords.mat2x3,p.keywords.mat2x4,p.keywords.mat3x2,p.keywords.mat3x3,p.keywords.mat3x4,p.keywords.mat4x2,p.keywords.mat4x3,p.keywords.mat4x4,p.keywords.atomic,p.keywords.bitcast,...p.any_texture_type];a.attribute_name=[p.tokens.ident,p.keywords.block];a.assignment_operators=[p.tokens.equal,p.tokens.plus_equal,p.tokens.minus_equal,p.tokens.times_equal,p.tokens.division_equal,p.tokens.modulo_equal,p.tokens.and_equal,p.tokens.or_equal,p.tokens.xor_equal,p.tokens.shift_right_equal,p.tokens.shift_left_equal];a.increment_operators=[p.tokens.plus_plus,p.tokens.minus_minus];var ve=class{constructor(t,e,n){this.type=t,this.lexeme=e,this.line=n}toString(){return this.lexeme}isTemplateType(){return a.template_types.indexOf(this.type)!=-1}isArrayType(){return this.type==a.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}},Es=class{constructor(t){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=t??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new ve(a.eof,"",this._line)),this._tokens}scanToken(){let t=this._advance();if(t==`
84
+ }`}function Jr(s){switch(s){case 1:return"float";case 2:return"vec2";case 3:return"vec3";case 4:return"vec4";default:throw new Error(`invalid channels: ${s}`)}}function An(s,t){switch(t){case 1:return`vec4(${s}, 0.0, 0.0, 1.0)`;case 2:return`vec4(${s}, 0.0, 1.0)`;case 3:return`vec4(${s}, 1.0)`;case 4:return s;default:throw new Error(`invalid channels: ${t}`)}}var Tn=C(z(),1);var rs=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},tt=class{constructor(){}get isAstNode(){return!0}get astNodeType(){return""}evaluate(t){throw new Error("Cannot evaluate node")}evaluateString(t){return this.evaluate(t).toString()}search(t){}searchBlock(t,e){if(t){e(Lt.instance);for(let n of t)n instanceof Array?this.searchBlock(n,e):n.search(e);e(It.instance)}}},Lt=class extends tt{};Lt.instance=new Lt;var It=class extends tt{};It.instance=new It;var F=class extends tt{constructor(){super()}},Xt=class extends F{constructor(t,e,n,r,i,o){super(),this.calls=new Set,this.name=t,this.args=e,this.returnType=n,this.body=r,this.startLine=i,this.endLine=o}get astNodeType(){return"function"}search(t){this.searchBlock(this.body,t)}},is=class extends F{constructor(t){super(),this.expression=t}get astNodeType(){return"staticAssert"}search(t){this.expression.search(t)}},os=class extends F{constructor(t,e){super(),this.condition=t,this.body=e}get astNodeType(){return"while"}search(t){this.condition.search(t),this.searchBlock(this.body,t)}},as=class extends F{constructor(t){super(),this.body=t}get astNodeType(){return"continuing"}search(t){this.searchBlock(this.body,t)}},cs=class extends F{constructor(t,e,n,r){super(),this.init=t,this.condition=e,this.increment=n,this.body=r}get astNodeType(){return"for"}search(t){var e,n,r;(e=this.init)===null||e===void 0||e.search(t),(n=this.condition)===null||n===void 0||n.search(t),(r=this.increment)===null||r===void 0||r.search(t),this.searchBlock(this.body,t)}},ot=class extends F{constructor(t,e,n,r,i){super(),this.name=t,this.type=e,this.storage=n,this.access=r,this.value=i}get astNodeType(){return"var"}search(t){var e;t(this),(e=this.value)===null||e===void 0||e.search(t)}},de=class extends F{constructor(t,e,n){super(),this.name=t,this.type=e,this.value=n}get astNodeType(){return"override"}search(t){var e;(e=this.value)===null||e===void 0||e.search(t)}},Kt=class extends F{constructor(t,e,n,r,i){super(),this.name=t,this.type=e,this.storage=n,this.access=r,this.value=i}get astNodeType(){return"let"}search(t){var e;t(this),(e=this.value)===null||e===void 0||e.search(t)}},me=class extends F{constructor(t,e,n,r,i){super(),this.name=t,this.type=e,this.storage=n,this.access=r,this.value=i}get astNodeType(){return"const"}evaluate(t){return this.value.evaluate(t)}search(t){var e;t(this),(e=this.value)===null||e===void 0||e.search(t)}},Nt;(function(s){s.increment="++",s.decrement="--"})(Nt||(Nt={}));(function(s){function t(e){let n=e;if(n=="parse")throw new Error("Invalid value for IncrementOperator");return s[n]}s.parse=t})(Nt||(Nt={}));var hs=class extends F{constructor(t,e){super(),this.operator=t,this.variable=e}get astNodeType(){return"increment"}search(t){this.variable.search(t)}},Zt;(function(s){s.assign="=",s.addAssign="+=",s.subtractAssin="-=",s.multiplyAssign="*=",s.divideAssign="/=",s.moduloAssign="%=",s.andAssign="&=",s.orAssign="|=",s.xorAssign="^=",s.shiftLeftAssign="<<=",s.shiftRightAssign=">>="})(Zt||(Zt={}));(function(s){function t(e){let n=e;if(n=="parse")throw new Error("Invalid value for AssignOperator");return n}s.parse=t})(Zt||(Zt={}));var ls=class extends F{constructor(t,e,n){super(),this.operator=t,this.variable=e,this.value=n}get astNodeType(){return"assign"}search(t){this.variable.search(t),this.value.search(t)}},pe=class extends F{constructor(t,e){super(),this.name=t,this.args=e}get astNodeType(){return"call"}search(t){for(let e of this.args)e.search(t);t(this)}},us=class extends F{constructor(t,e){super(),this.body=t,this.continuing=e}get astNodeType(){return"loop"}},fs=class extends F{constructor(t,e){super(),this.condition=t,this.body=e}get astNodeType(){return"body"}},ds=class extends F{constructor(t,e,n,r){super(),this.condition=t,this.body=e,this.elseif=n,this.else=r}get astNodeType(){return"if"}search(t){this.condition.search(t),this.searchBlock(this.body,t),this.searchBlock(this.elseif,t),this.searchBlock(this.else,t)}},ms=class extends F{constructor(t){super(),this.value=t}get astNodeType(){return"return"}search(t){var e;(e=this.value)===null||e===void 0||e.search(t)}},ps=class extends F{constructor(t){super(),this.name=t}get astNodeType(){return"enable"}},_s=class extends F{constructor(t){super(),this.extensions=t}get astNodeType(){return"requires"}},gs=class extends F{constructor(t,e){super(),this.severity=t,this.rule=e}get astNodeType(){return"diagnostic"}},_e=class extends F{constructor(t,e){super(),this.name=t,this.type=e}get astNodeType(){return"alias"}},xs=class extends F{constructor(){super()}get astNodeType(){return"discard"}},ys=class extends F{constructor(){super()}get astNodeType(){return"break"}},ws=class extends F{constructor(){super()}get astNodeType(){return"continue"}},at=class extends F{constructor(t){super(),this.name=t}get astNodeType(){return"type"}get isStruct(){return!1}get isArray(){return!1}},it=class extends at{constructor(t,e,n,r){super(t),this.members=e,this.startLine=n,this.endLine=r}get astNodeType(){return"struct"}get isStruct(){return!0}getMemberIndex(t){for(let e=0;e<this.members.length;e++)if(this.members[e].name==t)return e;return-1}},ge=class extends at{constructor(t,e,n){super(t),this.format=e,this.access=n}get astNodeType(){return"template"}},ks=class extends at{constructor(t,e,n,r){super(t),this.storage=e,this.type=n,this.access=r}get astNodeType(){return"pointer"}},xe=class extends at{constructor(t,e,n,r){super(t),this.attributes=e,this.format=n,this.count=r}get astNodeType(){return"array"}get isArray(){return!0}},vt=class extends at{constructor(t,e,n){super(t),this.format=e,this.access=n}get astNodeType(){return"sampler"}},W=class extends tt{constructor(){super()}},ye=class extends W{constructor(t){super(),this.value=t}get astNodeType(){return"stringExpr"}toString(){return this.value}evaluateString(){return this.value}},_t=class extends W{constructor(t,e){super(),this.type=t,this.args=e}get astNodeType(){return"createExpr"}search(t){t(this);for(let e of this.args)e.search(t)}},we=class extends W{constructor(t,e){super(),this.name=t,this.args=e}get astNodeType(){return"callExpr"}evaluate(t){switch(this.name){case"abs":return Math.abs(this.args[0].evaluate(t));case"acos":return Math.acos(this.args[0].evaluate(t));case"acosh":return Math.acosh(this.args[0].evaluate(t));case"asin":return Math.asin(this.args[0].evaluate(t));case"asinh":return Math.asinh(this.args[0].evaluate(t));case"atan":return Math.atan(this.args[0].evaluate(t));case"atan2":return Math.atan2(this.args[0].evaluate(t),this.args[1].evaluate(t));case"atanh":return Math.atanh(this.args[0].evaluate(t));case"ceil":return Math.ceil(this.args[0].evaluate(t));case"clamp":return Math.min(Math.max(this.args[0].evaluate(t),this.args[1].evaluate(t)),this.args[2].evaluate(t));case"cos":return Math.cos(this.args[0].evaluate(t));case"degrees":return this.args[0].evaluate(t)*180/Math.PI;case"distance":return Math.sqrt(Math.pow(this.args[0].evaluate(t)-this.args[1].evaluate(t),2));case"dot":case"exp":return Math.exp(this.args[0].evaluate(t));case"exp2":return Math.pow(2,this.args[0].evaluate(t));case"floor":return Math.floor(this.args[0].evaluate(t));case"fma":return this.args[0].evaluate(t)*this.args[1].evaluate(t)+this.args[2].evaluate(t);case"fract":return this.args[0].evaluate(t)-Math.floor(this.args[0].evaluate(t));case"inverseSqrt":return 1/Math.sqrt(this.args[0].evaluate(t));case"log":return Math.log(this.args[0].evaluate(t));case"log2":return Math.log2(this.args[0].evaluate(t));case"max":return Math.max(this.args[0].evaluate(t),this.args[1].evaluate(t));case"min":return Math.min(this.args[0].evaluate(t),this.args[1].evaluate(t));case"mix":return this.args[0].evaluate(t)*(1-this.args[2].evaluate(t))+this.args[1].evaluate(t)*this.args[2].evaluate(t);case"modf":return this.args[0].evaluate(t)-Math.floor(this.args[0].evaluate(t));case"pow":return Math.pow(this.args[0].evaluate(t),this.args[1].evaluate(t));case"radians":return this.args[0].evaluate(t)*Math.PI/180;case"round":return Math.round(this.args[0].evaluate(t));case"sign":return Math.sign(this.args[0].evaluate(t));case"sin":return Math.sin(this.args[0].evaluate(t));case"sinh":return Math.sinh(this.args[0].evaluate(t));case"saturate":return Math.min(Math.max(this.args[0].evaluate(t),0),1);case"smoothstep":return this.args[0].evaluate(t)*this.args[0].evaluate(t)*(3-2*this.args[0].evaluate(t));case"sqrt":return Math.sqrt(this.args[0].evaluate(t));case"step":return this.args[0].evaluate(t)<this.args[1].evaluate(t)?0:1;case"tan":return Math.tan(this.args[0].evaluate(t));case"tanh":return Math.tanh(this.args[0].evaluate(t));case"trunc":return Math.trunc(this.args[0].evaluate(t));default:throw new Error("Non const function: "+this.name)}}search(t){for(let e of this.args)e.search(t);t(this)}},Jt=class extends W{constructor(t){super(),this.name=t}get astNodeType(){return"varExpr"}search(t){t(this),this.postfix&&this.postfix.search(t)}evaluate(t){let e=t.constants.get(this.name);if(!e)throw new Error("Cannot evaluate node");return e.evaluate(t)}},ke=class extends W{constructor(t,e){super(),this.name=t,this.initializer=e}get astNodeType(){return"constExpr"}evaluate(t){var e,n;if(this.initializer instanceof _t){let r=(e=this.postfix)===null||e===void 0?void 0:e.evaluateString(t),i=(n=this.initializer.type)===null||n===void 0?void 0:n.name,o=t.structs.get(i),c=o?.getMemberIndex(r);if(c!=-1)return this.initializer.args[c].evaluate(t);console.log(c)}return this.initializer.evaluate(t)}search(t){this.initializer.search(t)}},ve=class extends W{constructor(t){super(),this.value=t}get astNodeType(){return"literalExpr"}evaluate(){return this.value}},vs=class extends W{constructor(t,e){super(),this.type=t,this.value=e}get astNodeType(){return"bitcastExpr"}search(t){this.value.search(t)}},bs=class extends W{constructor(t,e){super(),this.type=t,this.args=e}get astNodeType(){return"typecastExpr"}evaluate(t){return this.args[0].evaluate(t)}search(t){this.searchBlock(this.args,t)}},be=class extends W{constructor(t){super(),this.contents=t}get astNodeType(){return"groupExpr"}evaluate(t){return this.contents[0].evaluate(t)}search(t){this.searchBlock(this.contents,t)}},Ms=class extends W{constructor(t){super(),this.index=t}search(t){this.index.search(t)}},Me=class extends W{constructor(){super()}},Ss=class extends Me{constructor(t,e){super(),this.operator=t,this.right=e}get astNodeType(){return"unaryOp"}evaluate(t){switch(this.operator){case"+":return this.right.evaluate(t);case"-":return-this.right.evaluate(t);case"!":return this.right.evaluate(t)?0:1;case"~":return~this.right.evaluate(t);default:throw new Error("Unknown unary operator: "+this.operator)}}search(t){this.right.search(t)}},Y=class extends Me{constructor(t,e,n){super(),this.operator=t,this.left=e,this.right=n}get astNodeType(){return"binaryOp"}evaluate(t){switch(this.operator){case"+":return this.left.evaluate(t)+this.right.evaluate(t);case"-":return this.left.evaluate(t)-this.right.evaluate(t);case"*":return this.left.evaluate(t)*this.right.evaluate(t);case"/":return this.left.evaluate(t)/this.right.evaluate(t);case"%":return this.left.evaluate(t)%this.right.evaluate(t);case"==":return this.left.evaluate(t)==this.right.evaluate(t)?1:0;case"!=":return this.left.evaluate(t)!=this.right.evaluate(t)?1:0;case"<":return this.left.evaluate(t)<this.right.evaluate(t)?1:0;case">":return this.left.evaluate(t)>this.right.evaluate(t)?1:0;case"<=":return this.left.evaluate(t)<=this.right.evaluate(t)?1:0;case">=":return this.left.evaluate(t)>=this.right.evaluate(t)?1:0;case"&&":return this.left.evaluate(t)&&this.right.evaluate(t)?1:0;case"||":return this.left.evaluate(t)||this.right.evaluate(t)?1:0;default:throw new Error(`Unknown operator ${this.operator}`)}}search(t){this.left.search(t),this.right.search(t)}},Se=class extends tt{constructor(){super()}},As=class extends Se{constructor(t,e){super(),this.selector=t,this.body=e}get astNodeType(){return"case"}search(t){this.searchBlock(this.body,t)}},Es=class extends Se{constructor(t){super(),this.body=t}get astNodeType(){return"default"}search(t){this.searchBlock(this.body,t)}},Ts=class extends tt{constructor(t,e,n){super(),this.name=t,this.type=e,this.attributes=n}get astNodeType(){return"argument"}},Os=class extends tt{constructor(t,e){super(),this.condition=t,this.body=e}get astNodeType(){return"elseif"}search(t){this.condition.search(t),this.searchBlock(this.body,t)}},Ls=class extends tt{constructor(t,e,n){super(),this.name=t,this.type=e,this.attributes=n}get astNodeType(){return"member"}},Is=class extends tt{constructor(t,e){super(),this.name=t,this.value=e}get astNodeType(){return"attribute"}},d,u;(function(s){s[s.token=0]="token",s[s.keyword=1]="keyword",s[s.reserved=2]="reserved"})(u||(u={}));var l=class{constructor(t,e,n){this.name=t,this.type=e,this.rule=n}toString(){return this.name}},a=class{};d=a;a.none=new l("",u.reserved,"");a.eof=new l("EOF",u.token,"");a.reserved={asm:new l("asm",u.reserved,"asm"),bf16:new l("bf16",u.reserved,"bf16"),do:new l("do",u.reserved,"do"),enum:new l("enum",u.reserved,"enum"),f16:new l("f16",u.reserved,"f16"),f64:new l("f64",u.reserved,"f64"),handle:new l("handle",u.reserved,"handle"),i8:new l("i8",u.reserved,"i8"),i16:new l("i16",u.reserved,"i16"),i64:new l("i64",u.reserved,"i64"),mat:new l("mat",u.reserved,"mat"),premerge:new l("premerge",u.reserved,"premerge"),regardless:new l("regardless",u.reserved,"regardless"),typedef:new l("typedef",u.reserved,"typedef"),u8:new l("u8",u.reserved,"u8"),u16:new l("u16",u.reserved,"u16"),u64:new l("u64",u.reserved,"u64"),unless:new l("unless",u.reserved,"unless"),using:new l("using",u.reserved,"using"),vec:new l("vec",u.reserved,"vec"),void:new l("void",u.reserved,"void")};a.keywords={array:new l("array",u.keyword,"array"),atomic:new l("atomic",u.keyword,"atomic"),bool:new l("bool",u.keyword,"bool"),f32:new l("f32",u.keyword,"f32"),i32:new l("i32",u.keyword,"i32"),mat2x2:new l("mat2x2",u.keyword,"mat2x2"),mat2x3:new l("mat2x3",u.keyword,"mat2x3"),mat2x4:new l("mat2x4",u.keyword,"mat2x4"),mat3x2:new l("mat3x2",u.keyword,"mat3x2"),mat3x3:new l("mat3x3",u.keyword,"mat3x3"),mat3x4:new l("mat3x4",u.keyword,"mat3x4"),mat4x2:new l("mat4x2",u.keyword,"mat4x2"),mat4x3:new l("mat4x3",u.keyword,"mat4x3"),mat4x4:new l("mat4x4",u.keyword,"mat4x4"),ptr:new l("ptr",u.keyword,"ptr"),sampler:new l("sampler",u.keyword,"sampler"),sampler_comparison:new l("sampler_comparison",u.keyword,"sampler_comparison"),struct:new l("struct",u.keyword,"struct"),texture_1d:new l("texture_1d",u.keyword,"texture_1d"),texture_2d:new l("texture_2d",u.keyword,"texture_2d"),texture_2d_array:new l("texture_2d_array",u.keyword,"texture_2d_array"),texture_3d:new l("texture_3d",u.keyword,"texture_3d"),texture_cube:new l("texture_cube",u.keyword,"texture_cube"),texture_cube_array:new l("texture_cube_array",u.keyword,"texture_cube_array"),texture_multisampled_2d:new l("texture_multisampled_2d",u.keyword,"texture_multisampled_2d"),texture_storage_1d:new l("texture_storage_1d",u.keyword,"texture_storage_1d"),texture_storage_2d:new l("texture_storage_2d",u.keyword,"texture_storage_2d"),texture_storage_2d_array:new l("texture_storage_2d_array",u.keyword,"texture_storage_2d_array"),texture_storage_3d:new l("texture_storage_3d",u.keyword,"texture_storage_3d"),texture_depth_2d:new l("texture_depth_2d",u.keyword,"texture_depth_2d"),texture_depth_2d_array:new l("texture_depth_2d_array",u.keyword,"texture_depth_2d_array"),texture_depth_cube:new l("texture_depth_cube",u.keyword,"texture_depth_cube"),texture_depth_cube_array:new l("texture_depth_cube_array",u.keyword,"texture_depth_cube_array"),texture_depth_multisampled_2d:new l("texture_depth_multisampled_2d",u.keyword,"texture_depth_multisampled_2d"),texture_external:new l("texture_external",u.keyword,"texture_external"),u32:new l("u32",u.keyword,"u32"),vec2:new l("vec2",u.keyword,"vec2"),vec3:new l("vec3",u.keyword,"vec3"),vec4:new l("vec4",u.keyword,"vec4"),bitcast:new l("bitcast",u.keyword,"bitcast"),block:new l("block",u.keyword,"block"),break:new l("break",u.keyword,"break"),case:new l("case",u.keyword,"case"),continue:new l("continue",u.keyword,"continue"),continuing:new l("continuing",u.keyword,"continuing"),default:new l("default",u.keyword,"default"),diagnostic:new l("diagnostic",u.keyword,"diagnostic"),discard:new l("discard",u.keyword,"discard"),else:new l("else",u.keyword,"else"),enable:new l("enable",u.keyword,"enable"),fallthrough:new l("fallthrough",u.keyword,"fallthrough"),false:new l("false",u.keyword,"false"),fn:new l("fn",u.keyword,"fn"),for:new l("for",u.keyword,"for"),function:new l("function",u.keyword,"function"),if:new l("if",u.keyword,"if"),let:new l("let",u.keyword,"let"),const:new l("const",u.keyword,"const"),loop:new l("loop",u.keyword,"loop"),while:new l("while",u.keyword,"while"),private:new l("private",u.keyword,"private"),read:new l("read",u.keyword,"read"),read_write:new l("read_write",u.keyword,"read_write"),return:new l("return",u.keyword,"return"),requires:new l("requires",u.keyword,"requires"),storage:new l("storage",u.keyword,"storage"),switch:new l("switch",u.keyword,"switch"),true:new l("true",u.keyword,"true"),alias:new l("alias",u.keyword,"alias"),type:new l("type",u.keyword,"type"),uniform:new l("uniform",u.keyword,"uniform"),var:new l("var",u.keyword,"var"),override:new l("override",u.keyword,"override"),workgroup:new l("workgroup",u.keyword,"workgroup"),write:new l("write",u.keyword,"write"),r8unorm:new l("r8unorm",u.keyword,"r8unorm"),r8snorm:new l("r8snorm",u.keyword,"r8snorm"),r8uint:new l("r8uint",u.keyword,"r8uint"),r8sint:new l("r8sint",u.keyword,"r8sint"),r16uint:new l("r16uint",u.keyword,"r16uint"),r16sint:new l("r16sint",u.keyword,"r16sint"),r16float:new l("r16float",u.keyword,"r16float"),rg8unorm:new l("rg8unorm",u.keyword,"rg8unorm"),rg8snorm:new l("rg8snorm",u.keyword,"rg8snorm"),rg8uint:new l("rg8uint",u.keyword,"rg8uint"),rg8sint:new l("rg8sint",u.keyword,"rg8sint"),r32uint:new l("r32uint",u.keyword,"r32uint"),r32sint:new l("r32sint",u.keyword,"r32sint"),r32float:new l("r32float",u.keyword,"r32float"),rg16uint:new l("rg16uint",u.keyword,"rg16uint"),rg16sint:new l("rg16sint",u.keyword,"rg16sint"),rg16float:new l("rg16float",u.keyword,"rg16float"),rgba8unorm:new l("rgba8unorm",u.keyword,"rgba8unorm"),rgba8unorm_srgb:new l("rgba8unorm_srgb",u.keyword,"rgba8unorm_srgb"),rgba8snorm:new l("rgba8snorm",u.keyword,"rgba8snorm"),rgba8uint:new l("rgba8uint",u.keyword,"rgba8uint"),rgba8sint:new l("rgba8sint",u.keyword,"rgba8sint"),bgra8unorm:new l("bgra8unorm",u.keyword,"bgra8unorm"),bgra8unorm_srgb:new l("bgra8unorm_srgb",u.keyword,"bgra8unorm_srgb"),rgb10a2unorm:new l("rgb10a2unorm",u.keyword,"rgb10a2unorm"),rg11b10float:new l("rg11b10float",u.keyword,"rg11b10float"),rg32uint:new l("rg32uint",u.keyword,"rg32uint"),rg32sint:new l("rg32sint",u.keyword,"rg32sint"),rg32float:new l("rg32float",u.keyword,"rg32float"),rgba16uint:new l("rgba16uint",u.keyword,"rgba16uint"),rgba16sint:new l("rgba16sint",u.keyword,"rgba16sint"),rgba16float:new l("rgba16float",u.keyword,"rgba16float"),rgba32uint:new l("rgba32uint",u.keyword,"rgba32uint"),rgba32sint:new l("rgba32sint",u.keyword,"rgba32sint"),rgba32float:new l("rgba32float",u.keyword,"rgba32float"),static_assert:new l("static_assert",u.keyword,"static_assert")};a.tokens={decimal_float_literal:new l("decimal_float_literal",u.token,/((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?f?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+f?)|([0-9]+f)/),hex_float_literal:new l("hex_float_literal",u.token,/-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+f?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+f?))/),int_literal:new l("int_literal",u.token,/-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),uint_literal:new l("uint_literal",u.token,/0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),ident:new l("ident",u.token,/[_a-zA-Z][0-9a-zA-Z_]*/),and:new l("and",u.token,"&"),and_and:new l("and_and",u.token,"&&"),arrow:new l("arrow ",u.token,"->"),attr:new l("attr",u.token,"@"),forward_slash:new l("forward_slash",u.token,"/"),bang:new l("bang",u.token,"!"),bracket_left:new l("bracket_left",u.token,"["),bracket_right:new l("bracket_right",u.token,"]"),brace_left:new l("brace_left",u.token,"{"),brace_right:new l("brace_right",u.token,"}"),colon:new l("colon",u.token,":"),comma:new l("comma",u.token,","),equal:new l("equal",u.token,"="),equal_equal:new l("equal_equal",u.token,"=="),not_equal:new l("not_equal",u.token,"!="),greater_than:new l("greater_than",u.token,">"),greater_than_equal:new l("greater_than_equal",u.token,">="),shift_right:new l("shift_right",u.token,">>"),less_than:new l("less_than",u.token,"<"),less_than_equal:new l("less_than_equal",u.token,"<="),shift_left:new l("shift_left",u.token,"<<"),modulo:new l("modulo",u.token,"%"),minus:new l("minus",u.token,"-"),minus_minus:new l("minus_minus",u.token,"--"),period:new l("period",u.token,"."),plus:new l("plus",u.token,"+"),plus_plus:new l("plus_plus",u.token,"++"),or:new l("or",u.token,"|"),or_or:new l("or_or",u.token,"||"),paren_left:new l("paren_left",u.token,"("),paren_right:new l("paren_right",u.token,")"),semicolon:new l("semicolon",u.token,";"),star:new l("star",u.token,"*"),tilde:new l("tilde",u.token,"~"),underscore:new l("underscore",u.token,"_"),xor:new l("xor",u.token,"^"),plus_equal:new l("plus_equal",u.token,"+="),minus_equal:new l("minus_equal",u.token,"-="),times_equal:new l("times_equal",u.token,"*="),division_equal:new l("division_equal",u.token,"/="),modulo_equal:new l("modulo_equal",u.token,"%="),and_equal:new l("and_equal",u.token,"&="),or_equal:new l("or_equal",u.token,"|="),xor_equal:new l("xor_equal",u.token,"^="),shift_right_equal:new l("shift_right_equal",u.token,">>="),shift_left_equal:new l("shift_left_equal",u.token,"<<=")};a.simpleTokens={"@":d.tokens.attr,"{":d.tokens.brace_left,"}":d.tokens.brace_right,":":d.tokens.colon,",":d.tokens.comma,"(":d.tokens.paren_left,")":d.tokens.paren_right,";":d.tokens.semicolon};a.literalTokens={"&":d.tokens.and,"&&":d.tokens.and_and,"->":d.tokens.arrow,"/":d.tokens.forward_slash,"!":d.tokens.bang,"[":d.tokens.bracket_left,"]":d.tokens.bracket_right,"=":d.tokens.equal,"==":d.tokens.equal_equal,"!=":d.tokens.not_equal,">":d.tokens.greater_than,">=":d.tokens.greater_than_equal,">>":d.tokens.shift_right,"<":d.tokens.less_than,"<=":d.tokens.less_than_equal,"<<":d.tokens.shift_left,"%":d.tokens.modulo,"-":d.tokens.minus,"--":d.tokens.minus_minus,".":d.tokens.period,"+":d.tokens.plus,"++":d.tokens.plus_plus,"|":d.tokens.or,"||":d.tokens.or_or,"*":d.tokens.star,"~":d.tokens.tilde,_:d.tokens.underscore,"^":d.tokens.xor,"+=":d.tokens.plus_equal,"-=":d.tokens.minus_equal,"*=":d.tokens.times_equal,"/=":d.tokens.division_equal,"%=":d.tokens.modulo_equal,"&=":d.tokens.and_equal,"|=":d.tokens.or_equal,"^=":d.tokens.xor_equal,">>=":d.tokens.shift_right_equal,"<<=":d.tokens.shift_left_equal};a.regexTokens={decimal_float_literal:d.tokens.decimal_float_literal,hex_float_literal:d.tokens.hex_float_literal,int_literal:d.tokens.int_literal,uint_literal:d.tokens.uint_literal,ident:d.tokens.ident};a.storage_class=[d.keywords.function,d.keywords.private,d.keywords.workgroup,d.keywords.uniform,d.keywords.storage];a.access_mode=[d.keywords.read,d.keywords.write,d.keywords.read_write];a.sampler_type=[d.keywords.sampler,d.keywords.sampler_comparison];a.sampled_texture_type=[d.keywords.texture_1d,d.keywords.texture_2d,d.keywords.texture_2d_array,d.keywords.texture_3d,d.keywords.texture_cube,d.keywords.texture_cube_array];a.multisampled_texture_type=[d.keywords.texture_multisampled_2d];a.storage_texture_type=[d.keywords.texture_storage_1d,d.keywords.texture_storage_2d,d.keywords.texture_storage_2d_array,d.keywords.texture_storage_3d];a.depth_texture_type=[d.keywords.texture_depth_2d,d.keywords.texture_depth_2d_array,d.keywords.texture_depth_cube,d.keywords.texture_depth_cube_array,d.keywords.texture_depth_multisampled_2d];a.texture_external_type=[d.keywords.texture_external];a.any_texture_type=[...d.sampled_texture_type,...d.multisampled_texture_type,...d.storage_texture_type,...d.depth_texture_type,...d.texture_external_type];a.texel_format=[d.keywords.r8unorm,d.keywords.r8snorm,d.keywords.r8uint,d.keywords.r8sint,d.keywords.r16uint,d.keywords.r16sint,d.keywords.r16float,d.keywords.rg8unorm,d.keywords.rg8snorm,d.keywords.rg8uint,d.keywords.rg8sint,d.keywords.r32uint,d.keywords.r32sint,d.keywords.r32float,d.keywords.rg16uint,d.keywords.rg16sint,d.keywords.rg16float,d.keywords.rgba8unorm,d.keywords.rgba8unorm_srgb,d.keywords.rgba8snorm,d.keywords.rgba8uint,d.keywords.rgba8sint,d.keywords.bgra8unorm,d.keywords.bgra8unorm_srgb,d.keywords.rgb10a2unorm,d.keywords.rg11b10float,d.keywords.rg32uint,d.keywords.rg32sint,d.keywords.rg32float,d.keywords.rgba16uint,d.keywords.rgba16sint,d.keywords.rgba16float,d.keywords.rgba32uint,d.keywords.rgba32sint,d.keywords.rgba32float];a.const_literal=[d.tokens.int_literal,d.tokens.uint_literal,d.tokens.decimal_float_literal,d.tokens.hex_float_literal,d.keywords.true,d.keywords.false];a.literal_or_ident=[d.tokens.ident,d.tokens.int_literal,d.tokens.uint_literal,d.tokens.decimal_float_literal,d.tokens.hex_float_literal];a.element_count_expression=[d.tokens.int_literal,d.tokens.uint_literal,d.tokens.ident];a.template_types=[d.keywords.vec2,d.keywords.vec3,d.keywords.vec4,d.keywords.mat2x2,d.keywords.mat2x3,d.keywords.mat2x4,d.keywords.mat3x2,d.keywords.mat3x3,d.keywords.mat3x4,d.keywords.mat4x2,d.keywords.mat4x3,d.keywords.mat4x4,d.keywords.atomic,d.keywords.bitcast,...d.any_texture_type];a.attribute_name=[d.tokens.ident,d.keywords.block,d.keywords.diagnostic];a.assignment_operators=[d.tokens.equal,d.tokens.plus_equal,d.tokens.minus_equal,d.tokens.times_equal,d.tokens.division_equal,d.tokens.modulo_equal,d.tokens.and_equal,d.tokens.or_equal,d.tokens.xor_equal,d.tokens.shift_right_equal,d.tokens.shift_left_equal];a.increment_operators=[d.tokens.plus_plus,d.tokens.minus_minus];var Ae=class{constructor(t,e,n){this.type=t,this.lexeme=e,this.line=n}toString(){return this.lexeme}isTemplateType(){return a.template_types.indexOf(this.type)!=-1}isArrayType(){return this.type==a.keywords.array}isArrayOrTemplateType(){return this.isArrayType()||this.isTemplateType()}},Ns=class{constructor(t){this._tokens=[],this._start=0,this._current=0,this._line=1,this._source=t??""}scanTokens(){for(;!this._isAtEnd();)if(this._start=this._current,!this.scanToken())throw`Invalid syntax at line ${this._line}`;return this._tokens.push(new Ae(a.eof,"",this._line)),this._tokens}scanToken(){let t=this._advance();if(t==`
85
85
  `)return this._line++,!0;if(this._isWhitespace(t))return!0;if(t=="/"){if(this._peekAhead()=="/"){for(;t!=`
86
- `;){if(this._isAtEnd())return!0;t=this._advance()}return this._line++,!0}else if(this._peekAhead()=="*"){this._advance();let n=1;for(;n>0;){if(this._isAtEnd())return!0;if(t=this._advance(),t==`
87
- `)this._line++;else if(t=="*"){if(this._peekAhead()=="/"&&(this._advance(),n--,n==0))return!0}else t=="/"&&this._peekAhead()=="*"&&(this._advance(),n++)}return!0}}let e=a.none;for(;;){let n=this._findType(t),r=this._peekAhead();if(t==">"&&(r==">"||r=="=")){let i=!1,o=this._tokens.length-1;for(let c=0;c<5&&o>=0;++c,--o)if(this._tokens[o].type===a.tokens.less_than){o>0&&this._tokens[o-1].isArrayOrTemplateType()&&(i=!0);break}if(i)return this._addToken(n),!0}if(n===a.none){let i=t,o=0,c=2;for(let h=0;h<c;++h)if(i+=this._peekAhead(h),n=this._findType(i),n!==a.none){o=h;break}if(n===a.none)return e===a.none?!1:(this._current--,this._addToken(e),!0);t=i,this._current+=o+1}if(e=n,this._isAtEnd())break;t+=this._advance()}return e===a.none?!1:(this._addToken(e),!0)}_findType(t){for(let e in a.keywords){let n=a.keywords[e];if(this._match(t,n.rule))return n}for(let e in a.tokens){let n=a.tokens[e];if(this._match(t,n.rule))return n}return a.none}_match(t,e){if(typeof e=="string"){if(e==t)return!0}else{let n=e.exec(t);if(n&&n.index==0&&n[0]==t)return!0}return!1}_isAtEnd(){return this._current>=this._source.length}_isWhitespace(t){return t==" "||t==" "||t=="\r"}_advance(t=0){let e=this._source[this._current];return t=t||0,t++,this._current+=t,e}_peekAhead(t=0){return t=t||0,this._current+t>=this._source.length?"\0":this._source[this._current+t]}_addToken(t){let e=this._source.substring(this._start,this._current);this._tokens.push(new ve(t,e,this._line))}},As=class{constructor(){this._tokens=[],this._current=0,this._context=new Qe}parse(t){this._initialize(t);let e=[];for(;!this._isAtEnd();){let n=this._global_decl_or_directive();if(!n)break;e.push(n)}return e}_initialize(t){if(t)if(typeof t=="string"){let e=new Es(t);this._tokens=e.scanTokens()}else this._tokens=t;else this._tokens=[];this._current=0}_error(t,e){return console.error(t,e),{token:t,message:e,toString:function(){return`${e}`}}}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type==a.eof}_match(t){if(t instanceof l)return this._check(t)?(this._advance(),!0):!1;for(let e=0,n=t.length;e<n;++e){let r=t[e];if(this._check(r))return this._advance(),!0}return!1}_consume(t,e){if(this._check(t))return this._advance();throw this._error(this._peek(),e)}_check(t){if(this._isAtEnd())return!1;let e=this._peek();if(t instanceof Array){let n=e.type;return t.indexOf(n)!=-1}return e.type==t}_advance(){return this._isAtEnd()||this._current++,this._previous()}_peek(){return this._tokens[this._current]}_previous(){return this._tokens[this._current-1]}_global_decl_or_directive(){for(;this._match(a.tokens.semicolon)&&!this._isAtEnd(););if(this._match(a.keywords.alias)){let e=this._type_alias();return this._consume(a.tokens.semicolon,"Expected ';'"),e}if(this._match(a.keywords.enable)){let e=this._enable_directive();return this._consume(a.tokens.semicolon,"Expected ';'"),e}let t=this._attribute();if(this._check(a.keywords.var)){let e=this._global_variable_decl();return e!=null&&(e.attributes=t),this._consume(a.tokens.semicolon,"Expected ';'."),e}if(this._check(a.keywords.override)){let e=this._override_variable_decl();return e!=null&&(e.attributes=t),this._consume(a.tokens.semicolon,"Expected ';'."),e}if(this._check(a.keywords.let)){let e=this._global_let_decl();return e!=null&&(e.attributes=t),this._consume(a.tokens.semicolon,"Expected ';'."),e}if(this._check(a.keywords.const)){let e=this._global_const_decl();return e!=null&&(e.attributes=t),this._consume(a.tokens.semicolon,"Expected ';'."),e}if(this._check(a.keywords.struct)){let e=this._struct_decl();return e!=null&&(e.attributes=t),e}if(this._check(a.keywords.fn)){let e=this._function_decl();return e!=null&&(e.attributes=t),e}return null}_function_decl(){if(!this._match(a.keywords.fn))return null;let t=this._consume(a.tokens.ident,"Expected function name.").toString();this._consume(a.tokens.paren_left,"Expected '(' for function arguments.");let e=[];if(!this._check(a.tokens.paren_right))do{if(this._check(a.tokens.paren_right))break;let i=this._attribute(),o=this._consume(a.tokens.ident,"Expected argument name.").toString();this._consume(a.tokens.colon,"Expected ':' for argument type.");let c=this._attribute(),h=this._type_decl();h!=null&&(h.attributes=c,e.push(new ks(o,h,i)))}while(this._match(a.tokens.comma));this._consume(a.tokens.paren_right,"Expected ')' after function arguments.");let n=null;if(this._match(a.tokens.arrow)){let i=this._attribute();n=this._type_decl(),n!=null&&(n.attributes=i)}let r=this._compound_statement();return new ae(t,e,n,r)}_compound_statement(){let t=[];for(this._consume(a.tokens.brace_left,"Expected '{' for block.");!this._check(a.tokens.brace_right);){let e=this._statement();e!==null&&t.push(e)}return this._consume(a.tokens.brace_right,"Expected '}' for block."),t}_statement(){for(;this._match(a.tokens.semicolon)&&!this._isAtEnd(););if(this._check(a.keywords.if))return this._if_statement();if(this._check(a.keywords.switch))return this._switch_statement();if(this._check(a.keywords.loop))return this._loop_statement();if(this._check(a.keywords.for))return this._for_statement();if(this._check(a.keywords.while))return this._while_statement();if(this._check(a.keywords.continuing))return this._continuing_statement();if(this._check(a.keywords.static_assert))return this._static_assert_statement();if(this._check(a.tokens.brace_left))return this._compound_statement();let t=null;return this._check(a.keywords.return)?t=this._return_statement():this._check([a.keywords.var,a.keywords.let,a.keywords.const])?t=this._variable_statement():this._match(a.keywords.discard)?t=new fs:this._match(a.keywords.break)?t=new ds:this._match(a.keywords.continue)?t=new ms:t=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement(),t!=null&&this._consume(a.tokens.semicolon,"Expected ';' after statement."),t}_static_assert_statement(){if(!this._match(a.keywords.static_assert))return null;let t=this._optional_paren_expression();return new ts(t)}_while_statement(){if(!this._match(a.keywords.while))return null;let t=this._optional_paren_expression(),e=this._compound_statement();return new es(t,e)}_continuing_statement(){if(!this._match(a.keywords.continuing))return null;let t=this._compound_statement();return new ss(t)}_for_statement(){if(!this._match(a.keywords.for))return null;this._consume(a.tokens.paren_left,"Expected '('.");let t=this._check(a.tokens.semicolon)?null:this._for_init();this._consume(a.tokens.semicolon,"Expected ';'.");let e=this._check(a.tokens.semicolon)?null:this._short_circuit_or_expression();this._consume(a.tokens.semicolon,"Expected ';'.");let n=this._check(a.tokens.paren_right)?null:this._for_increment();this._consume(a.tokens.paren_right,"Expected ')'.");let r=this._compound_statement();return new ns(t,e,n,r)}_for_init(){return this._variable_statement()||this._func_call_statement()||this._assignment_statement()}_for_increment(){return this._func_call_statement()||this._increment_decrement_statement()||this._assignment_statement()}_variable_statement(){if(this._check(a.keywords.var)){let t=this._variable_decl();if(t===null)throw this._error(this._peek(),"Variable declaration expected.");let e=null;return this._match(a.tokens.equal)&&(e=this._short_circuit_or_expression()),new pt(t.name,t.type,t.storage,t.access,e)}if(this._match(a.keywords.let)){let t=this._consume(a.tokens.ident,"Expected name for let.").toString(),e=null;if(this._match(a.tokens.colon)){let r=this._attribute();e=this._type_decl(),e!=null&&(e.attributes=r)}this._consume(a.tokens.equal,"Expected '=' for let.");let n=this._short_circuit_or_expression();return new he(t,e,null,null,n)}if(this._match(a.keywords.const)){let t=this._consume(a.tokens.ident,"Expected name for const.").toString(),e=null;if(this._match(a.tokens.colon)){let r=this._attribute();e=this._type_decl(),e!=null&&(e.attributes=r)}this._consume(a.tokens.equal,"Expected '=' for const.");let n=this._short_circuit_or_expression();return new le(t,e,null,null,n)}return null}_increment_decrement_statement(){let t=this._current,e=this._unary_expression();if(e==null)return null;if(!this._check(a.increment_operators))return this._current=t,null;let n=this._consume(a.increment_operators,"Expected increment operator");return new rs(n.type===a.tokens.plus_plus?Pt.increment:Pt.decrement,e)}_assignment_statement(){let t=null;if(this._check(a.tokens.brace_right))return null;let e=this._match(a.tokens.underscore);if(e||(t=this._unary_expression()),!e&&t==null)return null;let n=this._consume(a.assignment_operators,"Expected assignment operator."),r=this._short_circuit_or_expression();return new is(Ht.parse(n.lexeme),t,r)}_func_call_statement(){if(!this._check(a.tokens.ident))return null;let t=this._current,e=this._consume(a.tokens.ident,"Expected function name."),n=this._argument_expression_list();return n===null?(this._current=t,null):new os(e.lexeme,n)}_loop_statement(){if(!this._match(a.keywords.loop))return null;this._consume(a.tokens.brace_left,"Expected '{' for loop.");let t=[],e=this._statement();for(;e!==null;){if(Array.isArray(e))for(let r of e)t.push(r);else t.push(e);e=this._statement()}let n=null;return this._match(a.keywords.continuing)&&(n=this._compound_statement()),this._consume(a.tokens.brace_right,"Expected '}' for loop."),new as(t,n)}_switch_statement(){if(!this._match(a.keywords.switch))return null;let t=this._optional_paren_expression();this._consume(a.tokens.brace_left,"Expected '{' for switch.");let e=this._switch_body();if(e==null||e.length==0)throw this._error(this._previous(),"Expected 'case' or 'default'.");return this._consume(a.tokens.brace_right,"Expected '}' for switch."),new cs(t,e)}_switch_body(){let t=[];if(this._match(a.keywords.case)){let e=this._case_selectors();this._match(a.tokens.colon),this._consume(a.tokens.brace_left,"Exected '{' for switch case.");let n=this._case_body();this._consume(a.tokens.brace_right,"Exected '}' for switch case."),t.push(new vs(e,n))}if(this._match(a.keywords.default)){this._match(a.tokens.colon),this._consume(a.tokens.brace_left,"Exected '{' for switch default.");let e=this._case_body();this._consume(a.tokens.brace_right,"Exected '}' for switch default."),t.push(new bs(e))}if(this._check([a.keywords.default,a.keywords.case])){let e=this._switch_body();t.push(e[0])}return t}_case_selectors(){var t,e,n,r;let i=[(e=(t=this._shift_expression())===null||t===void 0?void 0:t.evaluate(this._context).toString())!==null&&e!==void 0?e:""];for(;this._match(a.tokens.comma);)i.push((r=(n=this._shift_expression())===null||n===void 0?void 0:n.evaluate(this._context).toString())!==null&&r!==void 0?r:"");return i}_case_body(){if(this._match(a.keywords.fallthrough))return this._consume(a.tokens.semicolon,"Expected ';'"),[];let t=this._statement();if(t==null)return[];t instanceof Array||(t=[t]);let e=this._case_body();return e.length==0?t:[...t,e[0]]}_if_statement(){if(!this._match(a.keywords.if))return null;let t=this._optional_paren_expression(),e=this._compound_statement(),n=[];this._match_elseif()&&(n=this._elseif_statement(n));let r=null;return this._match(a.keywords.else)&&(r=this._compound_statement()),new hs(t,e,n,r)}_match_elseif(){return this._tokens[this._current].type===a.keywords.else&&this._tokens[this._current+1].type===a.keywords.if?(this._advance(),this._advance(),!0):!1}_elseif_statement(t=[]){let e=this._optional_paren_expression(),n=this._compound_statement();return t.push(new Ms(e,n)),this._match_elseif()&&this._elseif_statement(t),t}_return_statement(){if(!this._match(a.keywords.return))return null;let t=this._short_circuit_or_expression();return new ls(t)}_short_circuit_or_expression(){let t=this._short_circuit_and_expr();for(;this._match(a.tokens.or_or);)t=new H(this._previous().toString(),t,this._short_circuit_and_expr());return t}_short_circuit_and_expr(){let t=this._inclusive_or_expression();for(;this._match(a.tokens.and_and);)t=new H(this._previous().toString(),t,this._inclusive_or_expression());return t}_inclusive_or_expression(){let t=this._exclusive_or_expression();for(;this._match(a.tokens.or);)t=new H(this._previous().toString(),t,this._exclusive_or_expression());return t}_exclusive_or_expression(){let t=this._and_expression();for(;this._match(a.tokens.xor);)t=new H(this._previous().toString(),t,this._and_expression());return t}_and_expression(){let t=this._equality_expression();for(;this._match(a.tokens.and);)t=new H(this._previous().toString(),t,this._equality_expression());return t}_equality_expression(){let t=this._relational_expression();return this._match([a.tokens.equal_equal,a.tokens.not_equal])?new H(this._previous().toString(),t,this._relational_expression()):t}_relational_expression(){let t=this._shift_expression();for(;this._match([a.tokens.less_than,a.tokens.greater_than,a.tokens.less_than_equal,a.tokens.greater_than_equal]);)t=new H(this._previous().toString(),t,this._shift_expression());return t}_shift_expression(){let t=this._additive_expression();for(;this._match([a.tokens.shift_left,a.tokens.shift_right]);)t=new H(this._previous().toString(),t,this._additive_expression());return t}_additive_expression(){let t=this._multiplicative_expression();for(;this._match([a.tokens.plus,a.tokens.minus]);)t=new H(this._previous().toString(),t,this._multiplicative_expression());return t}_multiplicative_expression(){let t=this._unary_expression();for(;this._match([a.tokens.star,a.tokens.forward_slash,a.tokens.modulo]);)t=new H(this._previous().toString(),t,this._unary_expression());return t}_unary_expression(){return this._match([a.tokens.minus,a.tokens.bang,a.tokens.tilde,a.tokens.star,a.tokens.and])?new ws(this._previous().toString(),this._unary_expression()):this._singular_expression()}_singular_expression(){let t=this._primary_expression(),e=this._postfix_expression();return e&&(t.postfix=e),t}_postfix_expression(){if(this._match(a.tokens.bracket_left)){let t=this._short_circuit_or_expression();this._consume(a.tokens.bracket_right,"Expected ']'.");let e=this._postfix_expression();return e&&(t.postfix=e),t}if(this._match(a.tokens.period)){let t=this._consume(a.tokens.ident,"Expected member name."),e=this._postfix_expression(),n=new me(t.lexeme);return e&&(n.postfix=e),n}return null}_getStruct(t){return this._context.aliases.has(t)?this._context.aliases.get(t).type:this._context.structs.has(t)?this._context.structs.get(t):null}_primary_expression(){if(this._match(a.tokens.ident)){let n=this._previous().toString();if(this._check(a.tokens.paren_left)){let r=this._argument_expression_list(),i=this._getStruct(n);return i!=null?new bt(i,r):new _s(n,r)}if(this._context.constants.has(n)){let r=this._context.constants.get(n);return new pe(n,r.value)}return new gs(n)}if(this._match(a.const_literal))return new _e(parseFloat(this._previous().toString()));if(this._check(a.tokens.paren_left))return this._paren_expression();if(this._match(a.keywords.bitcast)){this._consume(a.tokens.less_than,"Expected '<'.");let n=this._type_decl();this._consume(a.tokens.greater_than,"Expected '>'.");let r=this._paren_expression();return new xs(n,r)}let t=this._type_decl(),e=this._argument_expression_list();return new ys(t,e)}_argument_expression_list(){if(!this._match(a.tokens.paren_left))return null;let t=[];do{if(this._check(a.tokens.paren_right))break;let e=this._short_circuit_or_expression();t.push(e)}while(this._match(a.tokens.comma));return this._consume(a.tokens.paren_right,"Expected ')' for agument list"),t}_optional_paren_expression(){this._match(a.tokens.paren_left);let t=this._short_circuit_or_expression();return this._match(a.tokens.paren_right),new ge([t])}_paren_expression(){this._consume(a.tokens.paren_left,"Expected '('.");let t=this._short_circuit_or_expression();return this._consume(a.tokens.paren_right,"Expected ')'."),new ge([t])}_struct_decl(){if(!this._match(a.keywords.struct))return null;let t=this._consume(a.tokens.ident,"Expected name for struct.").toString();this._consume(a.tokens.brace_left,"Expected '{' for struct body.");let e=[];for(;!this._check(a.tokens.brace_right);){let r=this._attribute(),i=this._consume(a.tokens.ident,"Expected variable name.").toString();this._consume(a.tokens.colon,"Expected ':' for struct member type.");let o=this._attribute(),c=this._type_decl();c!=null&&(c.attributes=o),this._check(a.tokens.brace_right)?this._match(a.tokens.comma):this._consume(a.tokens.comma,"Expected ',' for struct member."),e.push(new Ss(i,c,r))}this._consume(a.tokens.brace_right,"Expected '}' after struct body.");let n=new rt(t,e);return this._context.structs.set(t,n),n}_global_variable_decl(){let t=this._variable_decl();return t&&this._match(a.tokens.equal)&&(t.value=this._const_expression()),t}_override_variable_decl(){let t=this._override_decl();return t&&this._match(a.tokens.equal)&&(t.value=this._const_expression()),t}_global_const_decl(){if(!this._match(a.keywords.const))return null;let t=this._consume(a.tokens.ident,"Expected variable name"),e=null;if(this._match(a.tokens.colon)){let i=this._attribute();e=this._type_decl(),e!=null&&(e.attributes=i)}let n=null;if(this._match(a.tokens.equal)){let i=this._short_circuit_or_expression();if(i instanceof bt)n=i;else if(i instanceof pe&&i.initializer instanceof bt)n=i.initializer;else try{let o=i.evaluate(this._context);n=new _e(o)}catch{n=i}}let r=new le(t.toString(),e,"","",n);return this._context.constants.set(r.name,r),r}_global_let_decl(){if(!this._match(a.keywords.let))return null;let t=this._consume(a.tokens.ident,"Expected variable name"),e=null;if(this._match(a.tokens.colon)){let r=this._attribute();e=this._type_decl(),e!=null&&(e.attributes=r)}let n=null;return this._match(a.tokens.equal)&&(n=this._const_expression()),new he(t.toString(),e,"","",n)}_const_expression(){if(this._match(a.const_literal))return new me(this._previous().toString());let t=this._type_decl();this._consume(a.tokens.paren_left,"Expected '('.");let e=[];for(;!this._check(a.tokens.paren_right)&&(e.push(this._const_expression()),!!this._check(a.tokens.comma));)this._advance();return this._consume(a.tokens.paren_right,"Expected ')'."),new bt(t,e)}_variable_decl(){if(!this._match(a.keywords.var))return null;let t="",e="";this._match(a.tokens.less_than)&&(t=this._consume(a.storage_class,"Expected storage_class.").toString(),this._match(a.tokens.comma)&&(e=this._consume(a.access_mode,"Expected access_mode.").toString()),this._consume(a.tokens.greater_than,"Expected '>'."));let n=this._consume(a.tokens.ident,"Expected variable name"),r=null;if(this._match(a.tokens.colon)){let i=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=i)}return new pt(n.toString(),r,t,e,null)}_override_decl(){if(!this._match(a.keywords.override))return null;let t=this._consume(a.tokens.ident,"Expected variable name"),e=null;if(this._match(a.tokens.colon)){let n=this._attribute();e=this._type_decl(),e!=null&&(e.attributes=n)}return new ce(t.toString(),e,null)}_enable_directive(){let t=this._consume(a.tokens.ident,"identity expected.");return new us(t.toString())}_type_alias(){let t=this._consume(a.tokens.ident,"identity expected.");this._consume(a.tokens.equal,"Expected '=' for type alias.");let e=this._type_decl();if(e===null)throw this._error(this._peek(),"Expected Type for Alias.");this._context.aliases.has(e.name)&&(e=this._context.aliases.get(e.name).type);let n=new ue(t.toString(),e);return this._context.aliases.set(n.name,n),n}_type_decl(){if(this._check([a.tokens.ident,...a.texel_format,a.keywords.bool,a.keywords.f32,a.keywords.i32,a.keywords.u32])){let n=this._advance(),r=n.toString();return this._context.structs.has(r)?this._context.structs.get(r):this._context.aliases.has(r)?this._context.aliases.get(r).type:new ot(n.toString())}let t=this._texture_sampler_types();if(t)return t;if(this._check(a.template_types)){let n=this._advance().toString(),r=null,i=null;return this._match(a.tokens.less_than)&&(r=this._type_decl(),i=null,this._match(a.tokens.comma)&&(i=this._consume(a.access_mode,"Expected access_mode for pointer").toString()),this._consume(a.tokens.greater_than,"Expected '>' for type.")),new fe(n,r,i)}if(this._match(a.keywords.ptr)){let n=this._previous().toString();this._consume(a.tokens.less_than,"Expected '<' for pointer.");let r=this._consume(a.storage_class,"Expected storage_class for pointer");this._consume(a.tokens.comma,"Expected ',' for pointer.");let i=this._type_decl(),o=null;return this._match(a.tokens.comma)&&(o=this._consume(a.access_mode,"Expected access_mode for pointer").toString()),this._consume(a.tokens.greater_than,"Expected '>' for pointer."),new ps(n,r.toString(),i,o)}let e=this._attribute();if(this._match(a.keywords.array)){let n=null,r=-1,i=this._previous();if(this._match(a.tokens.less_than)){n=this._type_decl(),this._context.aliases.has(n.name)&&(n=this._context.aliases.get(n.name).type);let o="";this._match(a.tokens.comma)&&(o=this._shift_expression().evaluate(this._context).toString()),this._consume(a.tokens.greater_than,"Expected '>' for array."),r=o?parseInt(o):0}return new de(i.toString(),e,n,r)}return null}_texture_sampler_types(){if(this._match(a.sampler_type))return new vt(this._previous().toString(),null,null);if(this._match(a.depth_texture_type))return new vt(this._previous().toString(),null,null);if(this._match(a.sampled_texture_type)||this._match(a.multisampled_texture_type)){let t=this._previous();this._consume(a.tokens.less_than,"Expected '<' for sampler type.");let e=this._type_decl();return this._consume(a.tokens.greater_than,"Expected '>' for sampler type."),new vt(t.toString(),e,null)}if(this._match(a.storage_texture_type)){let t=this._previous();this._consume(a.tokens.less_than,"Expected '<' for sampler type.");let e=this._consume(a.texel_format,"Invalid texel format.").toString();this._consume(a.tokens.comma,"Expected ',' after texel format.");let n=this._consume(a.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(a.tokens.greater_than,"Expected '>' for sampler type."),new vt(t.toString(),e,n)}return null}_attribute(){let t=[];for(;this._match(a.tokens.attr);){let e=this._consume(a.attribute_name,"Expected attribute name"),n=new we(e.toString(),null);if(this._match(a.tokens.paren_left)){if(n.value=this._consume(a.literal_or_ident,"Expected attribute value").toString(),this._check(a.tokens.comma)){this._advance();do{let r=this._consume(a.literal_or_ident,"Expected attribute value").toString();n.value instanceof Array||(n.value=[n.value]),n.value.push(r)}while(this._match(a.tokens.comma))}this._consume(a.tokens.paren_right,"Expected ')'")}t.push(n)}for(;this._match(a.tokens.attr_left);){if(!this._check(a.tokens.attr_right))do{let e=this._consume(a.attribute_name,"Expected attribute name"),n=new we(e.toString(),null);if(this._match(a.tokens.paren_left)){if(n.value=[this._consume(a.literal_or_ident,"Expected attribute value").toString()],this._check(a.tokens.comma)){this._advance();do{let r=this._consume(a.literal_or_ident,"Expected attribute value").toString();n.value.push(r)}while(this._match(a.tokens.comma))}this._consume(a.tokens.paren_right,"Expected ')'")}t.push(n)}while(this._match(a.tokens.comma));this._consume(a.tokens.attr_right,"Expected ']]' after attribute declarations")}return t.length==0?null:t}},_t=class{constructor(t,e){this.name=t,this.attributes=e,this.size=0}get isArray(){return!1}get isStruct(){return!1}get isTemplate(){return!1}},be=class{constructor(t,e,n){this.name=t,this.type=e,this.attributes=n,this.offset=0,this.size=0}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray?this.type.format:this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},At=class extends _t{constructor(t,e){super(t,e),this.members=[],this.align=0}get isStruct(){return!0}},Wt=class extends _t{constructor(t,e){super(t,e),this.count=0,this.stride=0}get isArray(){return!0}},ke=class extends _t{constructor(t,e,n,r){super(t,n),this.format=e,this.access=r}get isTemplate(){return!0}},mt;(function(s){s[s.Uniform=0]="Uniform",s[s.Storage=1]="Storage",s[s.Texture=2]="Texture",s[s.Sampler=3]="Sampler",s[s.StorageTexture=4]="StorageTexture"})(mt||(mt={}));var Tt=class{constructor(t,e,n,r,i,o,c){this.name=t,this.type=e,this.group=n,this.binding=r,this.attributes=i,this.resourceType=o,this.access=c}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get size(){return this.type.size}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray?this.type.format:this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},Ts=class{constructor(t,e){this.name=t,this.type=e}},Ot=class{constructor(t,e){this.align=t,this.size=e}},Os=class{constructor(t,e,n,r){this.name=t,this.type=e,this.locationType=n,this.location=r,this.interpolation=null}},Me=class{constructor(t,e,n,r){this.name=t,this.type=e,this.locationType=n,this.location=r}},Ps=class{constructor(t,e=null){this.stage=null,this.inputs=[],this.outputs=[],this.name=t,this.stage=e}},Ns=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}},Is=class{constructor(t,e,n,r){this.name=t,this.type=e,this.attributes=n,this.id=r}},Y=class{constructor(t){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new Ns,this._types=new Map,t&&this.update(t)}_isStorageTexture(t){return t.name=="texture_storage_1d"||t.name=="texture_storage_2d"||t.name=="texture_storage_2d_array"||t.name=="texture_storage_3d"}update(t){let n=new As().parse(t);for(let r of n){if(r instanceof rt){let i=this._getTypeInfo(r,null);i instanceof At&&this.structs.push(i);continue}if(r instanceof ue){this.aliases.push(this._getAliasInfo(r));continue}if(r instanceof ce){let i=r,o=this._getAttributeNum(i.attributes,"id",0),c=i.type!=null?this._getTypeInfo(i.type,i.attributes):null;this.overrides.push(new Is(i.name,c,i.attributes,o));continue}if(this._isUniformVar(r)){let i=r,o=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),h=this._getTypeInfo(i.type,i.attributes),f=new Tt(i.name,h,o,c,i.attributes,mt.Uniform,i.access);this.uniforms.push(f);continue}if(this._isStorageVar(r)){let i=r,o=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),h=this._getTypeInfo(i.type,i.attributes),f=this._isStorageTexture(h),m=new Tt(i.name,h,o,c,i.attributes,f?mt.StorageTexture:mt.Storage,i.access);this.storage.push(m);continue}if(this._isTextureVar(r)){let i=r,o=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),h=this._getTypeInfo(i.type,i.attributes),f=this._isStorageTexture(h),m=new Tt(i.name,h,o,c,i.attributes,f?mt.StorageTexture:mt.Texture,i.access);f?this.storage.push(m):this.textures.push(m);continue}if(this._isSamplerVar(r)){let i=r,o=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),h=this._getTypeInfo(i.type,i.attributes),f=new Tt(i.name,h,o,c,i.attributes,mt.Sampler,i.access);this.samplers.push(f);continue}if(r instanceof ae){let i=this._getAttribute(r,"vertex"),o=this._getAttribute(r,"fragment"),c=this._getAttribute(r,"compute"),h=i||o||c;if(h){let f=new Ps(r.name,h.name);f.inputs=this._getInputs(r.args),f.outputs=this._getOutputs(r.returnType),this.entry[h.name].push(f)}continue}}}getBindGroups(){let t=[];function e(n,r){n>=t.length&&(t.length=n+1),t[n]===void 0&&(t[n]=[]),r>=t[n].length&&(t[n].length=r+1)}for(let n of this.uniforms){e(n.group,n.binding);let r=t[n.group];r[n.binding]=n}for(let n of this.storage){e(n.group,n.binding);let r=t[n.group];r[n.binding]=n}for(let n of this.textures){e(n.group,n.binding);let r=t[n.group];r[n.binding]=n}for(let n of this.samplers){e(n.group,n.binding);let r=t[n.group];r[n.binding]=n}return t}_getOutputs(t,e=void 0){if(e===void 0&&(e=[]),t instanceof rt)this._getStructOutputs(t,e);else{let n=this._getOutputInfo(t);n!==null&&e.push(n)}return e}_getStructOutputs(t,e){for(let n of t.members)if(n.type instanceof rt)this._getStructOutputs(n.type,e);else{let r=this._getAttribute(n,"location")||this._getAttribute(n,"builtin");if(r!==null){let i=this._getTypeInfo(n.type,n.type.attributes),o=this._parseInt(r.value),c=new Me(n.name,i,r.name,o);e.push(c)}}}_getOutputInfo(t){let e=this._getAttribute(t,"location")||this._getAttribute(t,"builtin");if(e!==null){let n=this._getTypeInfo(t,t.attributes),r=this._parseInt(e.value);return new Me("",n,e.name,r)}return null}_getInputs(t,e=void 0){e===void 0&&(e=[]);for(let n of t)if(n.type instanceof rt)this._getStructInputs(n.type,e);else{let r=this._getInputInfo(n);r!==null&&e.push(r)}return e}_getStructInputs(t,e){for(let n of t.members)if(n.type instanceof rt)this._getStructInputs(n.type,e);else{let r=this._getInputInfo(n);r!==null&&e.push(r)}}_getInputInfo(t){let e=this._getAttribute(t,"location")||this._getAttribute(t,"builtin");if(e!==null){let n=this._getAttribute(t,"interpolation"),r=this._getTypeInfo(t.type,t.attributes),i=this._parseInt(e.value),o=new Os(t.name,r,e.name,i);return n!==null&&(o.interpolation=this._parseString(n.value)),o}return null}_parseString(t){return t instanceof Array&&(t=t[0]),t}_parseInt(t){t instanceof Array&&(t=t[0]);let e=parseInt(t);return isNaN(e)?t:e}_getAlias(t){for(let e of this.aliases)if(e.name==t)return e.type;return null}_getAliasInfo(t){return new Ts(t.name,this._getTypeInfo(t.type,null))}_getTypeInfo(t,e){if(this._types.has(t))return this._types.get(t);if(t instanceof de){let r=t,i=this._getTypeInfo(r.format,r.attributes),o=new Wt(r.name,e);return o.format=i,o.count=r.count,this._types.set(t,o),this._updateTypeInfo(o),o}if(t instanceof rt){let r=t,i=new At(r.name,e);for(let o of r.members){let c=this._getTypeInfo(o.type,o.attributes);i.members.push(new be(o.name,c,o.attributes))}return this._types.set(t,i),this._updateTypeInfo(i),i}if(t instanceof vt){let r=t,i=r.format instanceof ot,o=r.format?i?this._getTypeInfo(r.format,null):new _t(r.format,null):null,c=new ke(r.name,o,e,r.access);return this._types.set(t,c),this._updateTypeInfo(c),c}if(t instanceof fe){let r=t,i=r.format?this._getTypeInfo(r.format,null):null,o=new ke(r.name,i,e,r.access);return this._types.set(t,o),this._updateTypeInfo(o),o}let n=new _t(t.name,e);return this._types.set(t,n),this._updateTypeInfo(n),n}_updateTypeInfo(t){var e,n;let r=this._getTypeSize(t);if(t.size=(e=r?.size)!==null&&e!==void 0?e:0,t instanceof Wt){let i=this._getTypeSize(t.format);t.stride=(n=i?.size)!==null&&n!==void 0?n:0,this._updateTypeInfo(t.format)}t instanceof At&&this._updateStructInfo(t)}_updateStructInfo(t){var e;let n=0,r=0,i=0,o=0;for(let c=0,h=t.members.length;c<h;++c){let f=t.members[c],m=this._getTypeSize(f);if(!m)continue;(e=this._getAlias(f.type.name))!==null&&e!==void 0||f.type;let d=m.align,_=m.size;n=this._roundUp(d,n+r),r=_,i=n,o=Math.max(o,d),f.offset=n,f.size=_,this._updateTypeInfo(f.type)}t.size=this._roundUp(o,i+r),t.align=o}_getTypeSize(t){var e;if(t==null)return null;let n=this._getAttributeNum(t.attributes,"size",0),r=this._getAttributeNum(t.attributes,"align",0);if(t instanceof be&&(t=t.type),t instanceof _t){let i=this._getAlias(t.name);i!==null&&(t=i)}{let i=Y._typeInfo[t.name];if(i!==void 0){let o=t.format==="f16"?2:1;return new Ot(Math.max(r,i.align/o),Math.max(n,i.size/o))}}{let i=Y._typeInfo[t.name.substring(0,t.name.length-1)];if(i){let o=t.name[t.name.length-1]==="h"?2:1;return new Ot(Math.max(r,i.align/o),Math.max(n,i.size/o))}}if(t instanceof Wt){let i=t,o=8,c=8,h=this._getTypeSize(i.format);h!==null&&(c=h.size,o=h.align);let f=i.count,m=this._getAttributeNum((e=t?.attributes)!==null&&e!==void 0?e:null,"stride",this._roundUp(o,c));return c=f*m,n&&(c=n),new Ot(Math.max(r,o),Math.max(n,c))}if(t instanceof At){let i=0,o=0,c=0,h=0,f=0;for(let m of t.members){let d=this._getTypeSize(m.type);d!==null&&(i=Math.max(d.align,i),c=this._roundUp(d.align,c+h),h=d.size,f=c)}return o=this._roundUp(i,f+h),new Ot(Math.max(r,i),Math.max(n,o))}return null}_isUniformVar(t){return t instanceof pt&&t.storage=="uniform"}_isStorageVar(t){return t instanceof pt&&t.storage=="storage"}_isTextureVar(t){return t instanceof pt&&t.type!==null&&Y._textureTypes.indexOf(t.type.name)!=-1}_isSamplerVar(t){return t instanceof pt&&t.type!==null&&Y._samplerTypes.indexOf(t.type.name)!=-1}_getAttribute(t,e){let n=t;if(!n||!n.attributes)return null;let r=n.attributes;for(let i of r)if(i.name==e)return i;return null}_getAttributeNum(t,e,n){if(t===null)return n;for(let r of t)if(r.name==e){let i=r!==null&&r.value!==null?r.value:n;return i instanceof Array&&(i=i[0]),typeof i=="number"?i:typeof i=="string"?parseInt(i):n}return n}_roundUp(t,e){return Math.ceil(e/t)*t}};Y._typeInfo={f16:{align:2,size:2},i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},atomic:{align:4,size:4},vec2:{align:8,size:8},vec3:{align:16,size:12},vec4:{align:16,size:16},mat2x2:{align:8,size:16},mat3x2:{align:8,size:24},mat4x2:{align:8,size:32},mat2x3:{align:16,size:32},mat3x3:{align:16,size:48},mat4x3:{align:16,size:64},mat2x4:{align:16,size:32},mat3x4:{align:16,size:48},mat4x4:{align:16,size:64}};Y._textureTypes=a.any_texture_type.map(s=>s.name);Y._samplerTypes=a.sampler_type.map(s=>s.name);function Yt(s){let t={attributes:[],bindings:[]},e;try{e=Hr(s)}catch(i){return bn.log.error(i.message)(),t}for(let i of e.uniforms){let o=[];for(let c of i.type.members)o.push({name:c.name,type:vn(c.type)});t.bindings.push({type:"uniform",name:i.name,location:i.binding,group:i.group,members:o})}let n=e.entry.vertex[0],r=n?.inputs.length||0;for(let i=0;i<r;i++){let o=n.inputs[i];if(o.locationType==="location"){let c=vn(o.type);t.attributes.push({name:o.name,location:o.location,type:c})}}return t}function vn(s){return s.format?`${s.name}<${s.format.name}>`:s.name}function Hr(s){try{return new Y(s)}catch(t){if(t instanceof Error)throw t;let e="WGSL parse error";throw typeof t=="object"&&t?.message&&(e+=`: ${t.message} `),typeof t=="object"&&t?.token&&(e+=t.token.line||""),new Error(e,{cause:t})}}var Ro=1/Math.PI*180,zo=1/180*Math.PI,Yr={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Yr}};var $=globalThis.mathgl.config;function kn(s,{precision:t=$.precision}={}){return s=Xr(s),"".concat(parseFloat(s.toPrecision(t)))}function Nt(s){return Array.isArray(s)||ArrayBuffer.isView(s)&&!(s instanceof DataView)}function Ls(s,t,e){let n=$.EPSILON;e&&($.EPSILON=e);try{if(s===t)return!0;if(Nt(s)&&Nt(t)){if(s.length!==t.length)return!1;for(let r=0;r<s.length;++r)if(!Ls(s[r],t[r]))return!1;return!0}return s&&s.equals?s.equals(t):t&&t.equals?t.equals(s):typeof s=="number"&&typeof t=="number"?Math.abs(s-t)<=$.EPSILON*Math.max(1,Math.abs(s),Math.abs(t)):!1}finally{$.EPSILON=n}}function Xr(s){return Math.round(s/$.EPSILON)*$.EPSILON}function Kr(s){function t(){var e=Reflect.construct(s,Array.from(arguments));return Object.setPrototypeOf(e,Object.getPrototypeOf(this)),e}return t.prototype=Object.create(s.prototype,{constructor:{value:s,enumerable:!1,writable:!0,configurable:!0}}),Object.setPrototypeOf?Object.setPrototypeOf(t,s):t.__proto__=s,t}var It=class extends Kr(Array){clone(){return new this.constructor().copy(this)}fromArray(t,e=0){for(let n=0;n<this.ELEMENTS;++n)this[n]=t[n+e];return this.check()}toArray(t=[],e=0){for(let n=0;n<this.ELEMENTS;++n)t[e+n]=this[n];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:Nt(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString($)}formatString(t){let e="";for(let n=0;n<this.ELEMENTS;++n)e+=(n>0?", ":"")+kn(this[n],t);return"".concat(t.printTypes?this.constructor.name:"","[").concat(e,"]")}equals(t){if(!t||this.length!==t.length)return!1;for(let e=0;e<this.ELEMENTS;++e)if(!Ls(this[e],t[e]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let e=0;e<this.ELEMENTS;++e)if(this[e]!==t[e])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,e,n){if(n===void 0)return this.lerp(this,t,e);for(let r=0;r<this.ELEMENTS;++r){let i=t[r],o=typeof e=="number"?e:e[r];this[r]=i+n*(o-i)}return this.check()}min(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=Math.min(t[e],this[e]);return this.check()}max(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=Math.max(t[e],this[e]);return this.check()}clamp(t,e){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t[n]),e[n]);return this.check()}add(...t){for(let e of t)for(let n=0;n<this.ELEMENTS;++n)this[n]+=e[n];return this.check()}subtract(...t){for(let e of t)for(let n=0;n<this.ELEMENTS;++n)this[n]-=e[n];return this.check()}scale(t){if(typeof t=="number")for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;else for(let e=0;e<this.ELEMENTS&&e<t.length;++e)this[e]*=t[e];return this.check()}multiplyByScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;return this.check()}check(){if($.debug&&!this.validate())throw new Error("math.gl: ".concat(this.constructor.name," some fields set to invalid numbers'"));return this}validate(){let t=this.length===this.ELEMENTS;for(let e=0;e<this.ELEMENTS;++e)t=t&&Number.isFinite(this[e]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=t;return this.check()}addScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,e){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t),e);return this.check()}get elements(){return this}};function Zr(s,t){if(s.length!==t)return!1;for(let e=0;e<s.length;++e)if(!Number.isFinite(s[e]))return!1;return!0}function j(s){if(!Number.isFinite(s))throw new Error("Invalid number ".concat(JSON.stringify(s)));return s}function Se(s,t,e=""){if($.debug&&!Zr(s,t))throw new Error("math.gl: ".concat(e," some fields set to invalid numbers'"));return s}function Rs(s,t){if(!s)throw new Error("math.gl assertion ".concat(t))}var Ee=class extends It{get x(){return this[0]}set x(t){this[0]=j(t)}get y(){return this[1]}set y(t){this[1]=j(t)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let t=0;for(let e=0;e<this.ELEMENTS;++e)t+=this[e]*this[e];return t}magnitudeSquared(){return this.lengthSquared()}distance(t){return Math.sqrt(this.distanceSquared(t))}distanceSquared(t){let e=0;for(let n=0;n<this.ELEMENTS;++n){let r=this[n]-t[n];e+=r*r}return j(e)}dot(t){let e=0;for(let n=0;n<this.ELEMENTS;++n)e+=this[n]*t[n];return j(e)}normalize(){let t=this.magnitude();if(t!==0)for(let e=0;e<this.ELEMENTS;++e)this[e]/=t;return this.check()}multiply(...t){for(let e of t)for(let n=0;n<this.ELEMENTS;++n)this[n]*=e[n];return this.check()}divide(...t){for(let e of t)for(let n=0;n<this.ELEMENTS;++n)this[n]/=e[n];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(t){return this.distance(t)}distanceToSquared(t){return this.distanceSquared(t)}getComponent(t){return Rs(t>=0&&t<this.ELEMENTS,"index is out of range"),j(this[t])}setComponent(t,e){return Rs(t>=0&&t<this.ELEMENTS,"index is out of range"),this[t]=e,this.check()}addVectors(t,e){return this.copy(t).add(e)}subVectors(t,e){return this.copy(t).subtract(e)}multiplyVectors(t,e){return this.copy(t).multiply(e)}addScaledVector(t,e){return this.add(new this.constructor(t).multiplyScalar(e))}};var at=typeof Float32Array<"u"?Float32Array:Array;var Wo=Math.PI/180;function Jr(){let s=new at(2);return at!=Float32Array&&(s[0]=0,s[1]=0),s}function En(s,t,e){let n=t[0],r=t[1];return s[0]=e[0]*n+e[4]*r+e[12],s[1]=e[1]*n+e[5]*r+e[13],s}var Ho=function(){let s=Jr();return function(t,e,n,r,i,o){let c,h;for(e||(e=2),n||(n=0),r?h=Math.min(r*e+n,t.length):h=t.length,c=n;c<h;c+=e)s[0]=t[c],s[1]=t[c+1],i(s,s,o),t[c]=s[0],t[c+1]=s[1];return t}}();function An(s,t,e){let n=t[0],r=t[1],i=e[3]*n+e[7]*r||1;return s[0]=(e[0]*n+e[4]*r)/i,s[1]=(e[1]*n+e[5]*r)/i,s}function Ae(s,t,e){let n=t[0],r=t[1],i=t[2],o=e[3]*n+e[7]*r+e[11]*i||1;return s[0]=(e[0]*n+e[4]*r+e[8]*i)/o,s[1]=(e[1]*n+e[5]*r+e[9]*i)/o,s[2]=(e[2]*n+e[6]*r+e[10]*i)/o,s}function Tn(s,t,e){let n=t[0],r=t[1];return s[0]=e[0]*n+e[2]*r,s[1]=e[1]*n+e[3]*r,s[2]=t[2],s}function Qr(){let s=new at(3);return at!=Float32Array&&(s[0]=0,s[1]=0,s[2]=0),s}function ti(s,t){return s[0]*t[0]+s[1]*t[1]+s[2]*t[2]}function On(s,t,e){let n=t[0],r=t[1],i=t[2],o=e[0],c=e[1],h=e[2];return s[0]=r*h-i*c,s[1]=i*o-n*h,s[2]=n*c-r*o,s}function Te(s,t,e){let n=t[0],r=t[1],i=t[2],o=e[3]*n+e[7]*r+e[11]*i+e[15];return o=o||1,s[0]=(e[0]*n+e[4]*r+e[8]*i+e[12])/o,s[1]=(e[1]*n+e[5]*r+e[9]*i+e[13])/o,s[2]=(e[2]*n+e[6]*r+e[10]*i+e[14])/o,s}function Pn(s,t,e){let n=t[0],r=t[1],i=t[2];return s[0]=n*e[0]+r*e[3]+i*e[6],s[1]=n*e[1]+r*e[4]+i*e[7],s[2]=n*e[2]+r*e[5]+i*e[8],s}function Nn(s,t,e){let n=e[0],r=e[1],i=e[2],o=e[3],c=t[0],h=t[1],f=t[2],m=r*f-i*h,d=i*c-n*f,_=n*h-r*c,y=r*_-i*d,S=i*m-n*_,g=n*d-r*m,w=o*2;return m*=w,d*=w,_*=w,y*=2,S*=2,g*=2,s[0]=c+m+y,s[1]=h+d+S,s[2]=f+_+g,s}function In(s,t,e,n){let r=[],i=[];return r[0]=t[0]-e[0],r[1]=t[1]-e[1],r[2]=t[2]-e[2],i[0]=r[0],i[1]=r[1]*Math.cos(n)-r[2]*Math.sin(n),i[2]=r[1]*Math.sin(n)+r[2]*Math.cos(n),s[0]=i[0]+e[0],s[1]=i[1]+e[1],s[2]=i[2]+e[2],s}function Ln(s,t,e,n){let r=[],i=[];return r[0]=t[0]-e[0],r[1]=t[1]-e[1],r[2]=t[2]-e[2],i[0]=r[2]*Math.sin(n)+r[0]*Math.cos(n),i[1]=r[1],i[2]=r[2]*Math.cos(n)-r[0]*Math.sin(n),s[0]=i[0]+e[0],s[1]=i[1]+e[1],s[2]=i[2]+e[2],s}function Rn(s,t,e,n){let r=[],i=[];return r[0]=t[0]-e[0],r[1]=t[1]-e[1],r[2]=t[2]-e[2],i[0]=r[0]*Math.cos(n)-r[1]*Math.sin(n),i[1]=r[0]*Math.sin(n)+r[1]*Math.cos(n),i[2]=r[2],s[0]=i[0]+e[0],s[1]=i[1]+e[1],s[2]=i[2]+e[2],s}function zn(s,t){let e=s[0],n=s[1],r=s[2],i=t[0],o=t[1],c=t[2],h=Math.sqrt((e*e+n*n+r*r)*(i*i+o*o+c*c)),f=h&&ti(s,t)/h;return Math.acos(Math.min(Math.max(f,-1),1))}var Ko=function(){let s=Qr();return function(t,e,n,r,i,o){let c,h;for(e||(e=3),n||(n=0),r?h=Math.min(r*e+n,t.length):h=t.length,c=n;c<h;c+=e)s[0]=t[c],s[1]=t[c+1],s[2]=t[c+2],i(s,s,o),t[c]=s[0],t[c+1]=s[1],t[c+2]=s[2];return t}}();var Cs=[0,0,0],Oe,B=class extends Ee{static get ZERO(){return Oe||(Oe=new B(0,0,0),Object.freeze(Oe)),Oe}constructor(t=0,e=0,n=0){super(-0,-0,-0),arguments.length===1&&Nt(t)?this.copy(t):($.debug&&(j(t),j(e),j(n)),this[0]=t,this[1]=e,this[2]=n)}set(t,e,n){return this[0]=t,this[1]=e,this[2]=n,this.check()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this.check()}fromObject(t){return $.debug&&(j(t.x),j(t.y),j(t.z)),this[0]=t.x,this[1]=t.y,this[2]=t.z,this.check()}toObject(t){return t.x=this[0],t.y=this[1],t.z=this[2],t}get ELEMENTS(){return 3}get z(){return this[2]}set z(t){this[2]=j(t)}angle(t){return zn(this,t)}cross(t){return On(this,this,t),this.check()}rotateX({radians:t,origin:e=Cs}){return In(this,this,e,t),this.check()}rotateY({radians:t,origin:e=Cs}){return Ln(this,this,e,t),this.check()}rotateZ({radians:t,origin:e=Cs}){return Rn(this,this,e,t),this.check()}transform(t){return this.transformAsPoint(t)}transformAsPoint(t){return Te(this,this,t),this.check()}transformAsVector(t){return Ae(this,this,t),this.check()}transformByMatrix3(t){return Pn(this,this,t),this.check()}transformByMatrix2(t){return Tn(this,this,t),this.check()}transformByQuaternion(t){return Nn(this,this,t),this.check()}};var Pe=class extends It{toString(){let t="[";if($.printRowMajor){t+="row-major:";for(let e=0;e<this.RANK;++e)for(let n=0;n<this.RANK;++n)t+=" ".concat(this[n*this.RANK+e])}else{t+="column-major:";for(let e=0;e<this.ELEMENTS;++e)t+=" ".concat(this[e])}return t+="]",t}getElementIndex(t,e){return e*this.RANK+t}getElement(t,e){return this[e*this.RANK+t]}setElement(t,e,n){return this[e*this.RANK+t]=j(n),this}getColumn(t,e=new Array(this.RANK).fill(-0)){let n=t*this.RANK;for(let r=0;r<this.RANK;++r)e[r]=this[n+r];return e}setColumn(t,e){let n=t*this.RANK;for(let r=0;r<this.RANK;++r)this[n+r]=e[r];return this}};function ei(s){return s[0]=1,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=1,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s}function Cn(s,t){if(s===t){let e=t[1],n=t[2],r=t[3],i=t[6],o=t[7],c=t[11];s[1]=t[4],s[2]=t[8],s[3]=t[12],s[4]=e,s[6]=t[9],s[7]=t[13],s[8]=n,s[9]=i,s[11]=t[14],s[12]=r,s[13]=o,s[14]=c}else s[0]=t[0],s[1]=t[4],s[2]=t[8],s[3]=t[12],s[4]=t[1],s[5]=t[5],s[6]=t[9],s[7]=t[13],s[8]=t[2],s[9]=t[6],s[10]=t[10],s[11]=t[14],s[12]=t[3],s[13]=t[7],s[14]=t[11],s[15]=t[15];return s}function Fn(s,t){let e=t[0],n=t[1],r=t[2],i=t[3],o=t[4],c=t[5],h=t[6],f=t[7],m=t[8],d=t[9],_=t[10],y=t[11],S=t[12],g=t[13],w=t[14],M=t[15],k=e*c-n*o,x=e*h-r*o,v=e*f-i*o,b=n*h-r*c,E=n*f-i*c,T=r*f-i*h,R=m*g-d*S,O=m*w-_*S,I=m*M-y*S,A=d*w-_*g,N=d*M-y*g,L=_*M-y*w,P=k*L-x*N+v*A+b*I-E*O+T*R;return P?(P=1/P,s[0]=(c*L-h*N+f*A)*P,s[1]=(r*N-n*L-i*A)*P,s[2]=(g*T-w*E+M*b)*P,s[3]=(_*E-d*T-y*b)*P,s[4]=(h*I-o*L-f*O)*P,s[5]=(e*L-r*I+i*O)*P,s[6]=(w*v-S*T-M*x)*P,s[7]=(m*T-_*v+y*x)*P,s[8]=(o*N-c*I+f*R)*P,s[9]=(n*I-e*N-i*R)*P,s[10]=(S*E-g*v+M*k)*P,s[11]=(d*v-m*E-y*k)*P,s[12]=(c*O-o*A-h*R)*P,s[13]=(e*A-n*O+r*R)*P,s[14]=(g*x-S*b-w*k)*P,s[15]=(m*b-d*x+_*k)*P,s):null}function Dn(s){let t=s[0],e=s[1],n=s[2],r=s[3],i=s[4],o=s[5],c=s[6],h=s[7],f=s[8],m=s[9],d=s[10],_=s[11],y=s[12],S=s[13],g=s[14],w=s[15],M=t*o-e*i,k=t*c-n*i,x=e*c-n*o,v=f*S-m*y,b=f*g-d*y,E=m*g-d*S,T=t*E-e*b+n*v,R=i*E-o*b+c*v,O=f*x-m*k+d*M,I=y*x-S*k+g*M;return h*T-r*R+w*O-_*I}function Fs(s,t,e){let n=t[0],r=t[1],i=t[2],o=t[3],c=t[4],h=t[5],f=t[6],m=t[7],d=t[8],_=t[9],y=t[10],S=t[11],g=t[12],w=t[13],M=t[14],k=t[15],x=e[0],v=e[1],b=e[2],E=e[3];return s[0]=x*n+v*c+b*d+E*g,s[1]=x*r+v*h+b*_+E*w,s[2]=x*i+v*f+b*y+E*M,s[3]=x*o+v*m+b*S+E*k,x=e[4],v=e[5],b=e[6],E=e[7],s[4]=x*n+v*c+b*d+E*g,s[5]=x*r+v*h+b*_+E*w,s[6]=x*i+v*f+b*y+E*M,s[7]=x*o+v*m+b*S+E*k,x=e[8],v=e[9],b=e[10],E=e[11],s[8]=x*n+v*c+b*d+E*g,s[9]=x*r+v*h+b*_+E*w,s[10]=x*i+v*f+b*y+E*M,s[11]=x*o+v*m+b*S+E*k,x=e[12],v=e[13],b=e[14],E=e[15],s[12]=x*n+v*c+b*d+E*g,s[13]=x*r+v*h+b*_+E*w,s[14]=x*i+v*f+b*y+E*M,s[15]=x*o+v*m+b*S+E*k,s}function Un(s,t,e){let n=e[0],r=e[1],i=e[2],o,c,h,f,m,d,_,y,S,g,w,M;return t===s?(s[12]=t[0]*n+t[4]*r+t[8]*i+t[12],s[13]=t[1]*n+t[5]*r+t[9]*i+t[13],s[14]=t[2]*n+t[6]*r+t[10]*i+t[14],s[15]=t[3]*n+t[7]*r+t[11]*i+t[15]):(o=t[0],c=t[1],h=t[2],f=t[3],m=t[4],d=t[5],_=t[6],y=t[7],S=t[8],g=t[9],w=t[10],M=t[11],s[0]=o,s[1]=c,s[2]=h,s[3]=f,s[4]=m,s[5]=d,s[6]=_,s[7]=y,s[8]=S,s[9]=g,s[10]=w,s[11]=M,s[12]=o*n+m*r+S*i+t[12],s[13]=c*n+d*r+g*i+t[13],s[14]=h*n+_*r+w*i+t[14],s[15]=f*n+y*r+M*i+t[15]),s}function qn(s,t,e){let n=e[0],r=e[1],i=e[2];return s[0]=t[0]*n,s[1]=t[1]*n,s[2]=t[2]*n,s[3]=t[3]*n,s[4]=t[4]*r,s[5]=t[5]*r,s[6]=t[6]*r,s[7]=t[7]*r,s[8]=t[8]*i,s[9]=t[9]*i,s[10]=t[10]*i,s[11]=t[11]*i,s[12]=t[12],s[13]=t[13],s[14]=t[14],s[15]=t[15],s}function Vn(s,t,e,n){let r=n[0],i=n[1],o=n[2],c=Math.sqrt(r*r+i*i+o*o),h,f,m,d,_,y,S,g,w,M,k,x,v,b,E,T,R,O,I,A,N,L,P,V;return c<1e-6?null:(c=1/c,r*=c,i*=c,o*=c,f=Math.sin(e),h=Math.cos(e),m=1-h,d=t[0],_=t[1],y=t[2],S=t[3],g=t[4],w=t[5],M=t[6],k=t[7],x=t[8],v=t[9],b=t[10],E=t[11],T=r*r*m+h,R=i*r*m+o*f,O=o*r*m-i*f,I=r*i*m-o*f,A=i*i*m+h,N=o*i*m+r*f,L=r*o*m+i*f,P=i*o*m-r*f,V=o*o*m+h,s[0]=d*T+g*R+x*O,s[1]=_*T+w*R+v*O,s[2]=y*T+M*R+b*O,s[3]=S*T+k*R+E*O,s[4]=d*I+g*A+x*N,s[5]=_*I+w*A+v*N,s[6]=y*I+M*A+b*N,s[7]=S*I+k*A+E*N,s[8]=d*L+g*P+x*V,s[9]=_*L+w*P+v*V,s[10]=y*L+M*P+b*V,s[11]=S*L+k*P+E*V,t!==s&&(s[12]=t[12],s[13]=t[13],s[14]=t[14],s[15]=t[15]),s)}function $n(s,t,e){let n=Math.sin(e),r=Math.cos(e),i=t[4],o=t[5],c=t[6],h=t[7],f=t[8],m=t[9],d=t[10],_=t[11];return t!==s&&(s[0]=t[0],s[1]=t[1],s[2]=t[2],s[3]=t[3],s[12]=t[12],s[13]=t[13],s[14]=t[14],s[15]=t[15]),s[4]=i*r+f*n,s[5]=o*r+m*n,s[6]=c*r+d*n,s[7]=h*r+_*n,s[8]=f*r-i*n,s[9]=m*r-o*n,s[10]=d*r-c*n,s[11]=_*r-h*n,s}function jn(s,t,e){let n=Math.sin(e),r=Math.cos(e),i=t[0],o=t[1],c=t[2],h=t[3],f=t[8],m=t[9],d=t[10],_=t[11];return t!==s&&(s[4]=t[4],s[5]=t[5],s[6]=t[6],s[7]=t[7],s[12]=t[12],s[13]=t[13],s[14]=t[14],s[15]=t[15]),s[0]=i*r-f*n,s[1]=o*r-m*n,s[2]=c*r-d*n,s[3]=h*r-_*n,s[8]=i*n+f*r,s[9]=o*n+m*r,s[10]=c*n+d*r,s[11]=h*n+_*r,s}function Gn(s,t,e){let n=Math.sin(e),r=Math.cos(e),i=t[0],o=t[1],c=t[2],h=t[3],f=t[4],m=t[5],d=t[6],_=t[7];return t!==s&&(s[8]=t[8],s[9]=t[9],s[10]=t[10],s[11]=t[11],s[12]=t[12],s[13]=t[13],s[14]=t[14],s[15]=t[15]),s[0]=i*r+f*n,s[1]=o*r+m*n,s[2]=c*r+d*n,s[3]=h*r+_*n,s[4]=f*r-i*n,s[5]=m*r-o*n,s[6]=d*r-c*n,s[7]=_*r-h*n,s}function Bn(s,t){let e=t[0],n=t[1],r=t[2],i=t[3],o=e+e,c=n+n,h=r+r,f=e*o,m=n*o,d=n*c,_=r*o,y=r*c,S=r*h,g=i*o,w=i*c,M=i*h;return s[0]=1-d-S,s[1]=m+M,s[2]=_-w,s[3]=0,s[4]=m-M,s[5]=1-f-S,s[6]=y+g,s[7]=0,s[8]=_+w,s[9]=y-g,s[10]=1-f-d,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s}function Wn(s,t,e,n,r,i,o){let c=1/(e-t),h=1/(r-n),f=1/(i-o);return s[0]=i*2*c,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=i*2*h,s[6]=0,s[7]=0,s[8]=(e+t)*c,s[9]=(r+n)*h,s[10]=(o+i)*f,s[11]=-1,s[12]=0,s[13]=0,s[14]=o*i*2*f,s[15]=0,s}function si(s,t,e,n,r){let i=1/Math.tan(t/2);if(s[0]=i/e,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=i,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[11]=-1,s[12]=0,s[13]=0,s[15]=0,r!=null&&r!==1/0){let o=1/(n-r);s[10]=(r+n)*o,s[14]=2*r*n*o}else s[10]=-1,s[14]=-2*n;return s}var Hn=si;function ni(s,t,e,n,r,i,o){let c=1/(t-e),h=1/(n-r),f=1/(i-o);return s[0]=-2*c,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=-2*h,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=2*f,s[11]=0,s[12]=(t+e)*c,s[13]=(r+n)*h,s[14]=(o+i)*f,s[15]=1,s}var Yn=ni;function Xn(s,t,e,n){let r,i,o,c,h,f,m,d,_,y,S=t[0],g=t[1],w=t[2],M=n[0],k=n[1],x=n[2],v=e[0],b=e[1],E=e[2];return Math.abs(S-v)<1e-6&&Math.abs(g-b)<1e-6&&Math.abs(w-E)<1e-6?ei(s):(d=S-v,_=g-b,y=w-E,r=1/Math.sqrt(d*d+_*_+y*y),d*=r,_*=r,y*=r,i=k*y-x*_,o=x*d-M*y,c=M*_-k*d,r=Math.sqrt(i*i+o*o+c*c),r?(r=1/r,i*=r,o*=r,c*=r):(i=0,o=0,c=0),h=_*c-y*o,f=y*i-d*c,m=d*o-_*i,r=Math.sqrt(h*h+f*f+m*m),r?(r=1/r,h*=r,f*=r,m*=r):(h=0,f=0,m=0),s[0]=i,s[1]=h,s[2]=d,s[3]=0,s[4]=o,s[5]=f,s[6]=_,s[7]=0,s[8]=c,s[9]=m,s[10]=y,s[11]=0,s[12]=-(i*S+o*g+c*w),s[13]=-(h*S+f*g+m*w),s[14]=-(d*S+_*g+y*w),s[15]=1,s)}function ri(){let s=new at(4);return at!=Float32Array&&(s[0]=0,s[1]=0,s[2]=0,s[3]=0),s}function Kn(s,t,e){let n=t[0],r=t[1],i=t[2],o=t[3];return s[0]=e[0]*n+e[4]*r+e[8]*i+e[12]*o,s[1]=e[1]*n+e[5]*r+e[9]*i+e[13]*o,s[2]=e[2]*n+e[6]*r+e[10]*i+e[14]*o,s[3]=e[3]*n+e[7]*r+e[11]*i+e[15]*o,s}var ha=function(){let s=ri();return function(t,e,n,r,i,o){let c,h;for(e||(e=4),n||(n=0),r?h=Math.min(r*e+n,t.length):h=t.length,c=n;c<h;c+=e)s[0]=t[c],s[1]=t[c+1],s[2]=t[c+2],s[3]=t[c+3],i(s,s,o),t[c]=s[0],t[c+1]=s[1],t[c+2]=s[2],t[c+3]=s[3];return t}}();var qs;(function(s){s[s.COL0ROW0=0]="COL0ROW0",s[s.COL0ROW1=1]="COL0ROW1",s[s.COL0ROW2=2]="COL0ROW2",s[s.COL0ROW3=3]="COL0ROW3",s[s.COL1ROW0=4]="COL1ROW0",s[s.COL1ROW1=5]="COL1ROW1",s[s.COL1ROW2=6]="COL1ROW2",s[s.COL1ROW3=7]="COL1ROW3",s[s.COL2ROW0=8]="COL2ROW0",s[s.COL2ROW1=9]="COL2ROW1",s[s.COL2ROW2=10]="COL2ROW2",s[s.COL2ROW3=11]="COL2ROW3",s[s.COL3ROW0=12]="COL3ROW0",s[s.COL3ROW1=13]="COL3ROW1",s[s.COL3ROW2=14]="COL3ROW2",s[s.COL3ROW3=15]="COL3ROW3"})(qs||(qs={}));var ii=45*Math.PI/180,oi=1,Ds=.1,Us=500,ai=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),tt=class extends Pe{static get IDENTITY(){return hi()}static get ZERO(){return ci()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return qs}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,e,n,r,i,o,c,h,f,m,d,_,y,S,g,w){return this[0]=t,this[1]=e,this[2]=n,this[3]=r,this[4]=i,this[5]=o,this[6]=c,this[7]=h,this[8]=f,this[9]=m,this[10]=d,this[11]=_,this[12]=y,this[13]=S,this[14]=g,this[15]=w,this.check()}setRowMajor(t,e,n,r,i,o,c,h,f,m,d,_,y,S,g,w){return this[0]=t,this[1]=i,this[2]=f,this[3]=y,this[4]=e,this[5]=o,this[6]=m,this[7]=S,this[8]=n,this[9]=c,this[10]=d,this[11]=g,this[12]=r,this[13]=h,this[14]=_,this[15]=w,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(ai)}fromObject(t){return this.check()}fromQuaternion(t){return Bn(this,t),this.check()}frustum(t){let{left:e,right:n,bottom:r,top:i,near:o=Ds,far:c=Us}=t;return c===1/0?li(this,e,n,r,i,o):Wn(this,e,n,r,i,o,c),this.check()}lookAt(t){let{eye:e,center:n=[0,0,0],up:r=[0,1,0]}=t;return Xn(this,e,n,r),this.check()}ortho(t){let{left:e,right:n,bottom:r,top:i,near:o=Ds,far:c=Us}=t;return Yn(this,e,n,r,i,o,c),this.check()}orthographic(t){let{fovy:e=ii,aspect:n=oi,focalDistance:r=1,near:i=Ds,far:o=Us}=t;Zn(e);let c=e/2,h=r*Math.tan(c),f=h*n;return this.ortho({left:-f,right:f,bottom:-h,top:h,near:i,far:o})}perspective(t){let{fovy:e=45*Math.PI/180,aspect:n=1,near:r=.1,far:i=500}=t;return Zn(e),Hn(this,e,n,r,i),this.check()}determinant(){return Dn(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,e){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],e=e||[-0,-0,-0];let n=this.getScale(e),r=1/n[0],i=1/n[1],o=1/n[2];return t[0]=this[0]*r,t[1]=this[1]*i,t[2]=this[2]*o,t[3]=0,t[4]=this[4]*r,t[5]=this[5]*i,t[6]=this[6]*o,t[7]=0,t[8]=this[8]*r,t[9]=this[9]*i,t[10]=this[10]*o,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,e){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],e=e||[-0,-0,-0];let n=this.getScale(e),r=1/n[0],i=1/n[1],o=1/n[2];return t[0]=this[0]*r,t[1]=this[1]*i,t[2]=this[2]*o,t[3]=this[4]*r,t[4]=this[5]*i,t[5]=this[6]*o,t[6]=this[8]*r,t[7]=this[9]*i,t[8]=this[10]*o,t}transpose(){return Cn(this,this),this.check()}invert(){return Fn(this,this),this.check()}multiplyLeft(t){return Fs(this,t,this),this.check()}multiplyRight(t){return Fs(this,this,t),this.check()}rotateX(t){return $n(this,this,t),this.check()}rotateY(t){return jn(this,this,t),this.check()}rotateZ(t){return Gn(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,e){return Vn(this,this,t,e),this.check()}scale(t){return qn(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return Un(this,this,t),this.check()}transform(t,e){return t.length===4?(e=Kn(e||[-0,-0,-0,-0],t,this),Se(e,4),e):this.transformAsPoint(t,e)}transformAsPoint(t,e){let{length:n}=t,r;switch(n){case 2:r=En(e||[-0,-0],t,this);break;case 3:r=Te(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Se(r,t.length),r}transformAsVector(t,e){let n;switch(t.length){case 2:n=An(e||[-0,-0],t,this);break;case 3:n=Ae(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Se(n,t.length),n}transformPoint(t,e){return this.transformAsPoint(t,e)}transformVector(t,e){return this.transformAsPoint(t,e)}transformDirection(t,e){return this.transformAsVector(t,e)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,e,n){return this.identity().translate([t,e,n])}},Ne,Ie;function ci(){return Ne||(Ne=new tt([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Ne)),Ne}function hi(){return Ie||(Ie=new tt,Object.freeze(Ie)),Ie}function Zn(s){if(s>Math.PI*2)throw Error("expected radians")}function li(s,t,e,n,r,i){let o=2*i/(e-t),c=2*i/(r-n),h=(e+t)/(e-t),f=(r+n)/(r-n),m=-1,d=-1,_=-2*i;return s[0]=o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=c,s[6]=0,s[7]=0,s[8]=h,s[9]=f,s[10]=m,s[11]=d,s[12]=0,s[13]=0,s[14]=_,s[15]=0,s}var ct=C(z(),1),Rt=class{id;userData={};topology;bufferLayout=[];vertexCount;indices;attributes;constructor(t){this.id=t.id||(0,ct.uid)("geometry"),this.topology=t.topology,this.indices=t.indices||null,this.attributes=t.attributes,this.vertexCount=t.vertexCount,this.bufferLayout=t.bufferLayout||[],this.indices&&(0,ct.assert)(this.indices.usage===ct.Buffer.INDEX)}destroy(){this.indices?.destroy();for(let t of Object.values(this.attributes))t.destroy()}getVertexCount(){return this.vertexCount}getAttributes(){return this.attributes}getIndexes(){return this.indices}_calculateVertexCount(t){return t.byteLength/12}};function Jn(s,t){if(t instanceof Rt)return t;let e=ui(s,t),{attributes:n,bufferLayout:r}=fi(s,t);return new Rt({topology:t.topology||"triangle-list",bufferLayout:r,vertexCount:t.vertexCount,indices:e,attributes:n})}function ui(s,t){if(!t.indices)return;let e=t.indices.value;return s.createBuffer({usage:ct.Buffer.INDEX,data:e})}function fi(s,t){let e=[],n={};for(let[i,o]of Object.entries(t.attributes)){let c=i;switch(i){case"POSITION":c="positions";break;case"NORMAL":c="normals";break;case"TEXCOORD_0":c="texCoords";break;case"COLOR_0":c="colors";break}n[c]=s.createBuffer({data:o.value,id:`${i}-buffer`});let{value:h,size:f,normalized:m}=o;e.push({name:c,format:(0,ct.getVertexFormatFromAttribute)(h,f,m)})}let r=t._calculateVertexCount(t.attributes,t.indices);return{attributes:n,bufferLayout:e,vertexCount:r}}var Vs=C(z(),1);var gt=class{modules;moduleUniforms;moduleBindings;moduleUniformsChanged;constructor(t){let e=wt(Object.values(t).filter(n=>n.dependencies));for(let n of e)t[n.name]=n;Vs.log.log(1,"Creating ShaderInputs with modules",Object.keys(t))(),this.modules=t,this.moduleUniforms={},this.moduleBindings={};for(let[n,r]of Object.entries(t)){let i=n;this.moduleUniforms[i]=r.defaultUniforms||{},this.moduleBindings[i]={}}}destroy(){}setProps(t){for(let e of Object.keys(t)){let n=e,r=t[n],i=this.modules[n];if(!i){Vs.log.warn(`Module ${e} not found`)();continue}let o=this.moduleUniforms[n],c=i.getUniforms?.(r,this.moduleUniforms[n])||r;this.moduleUniforms[n]={...o,...c}}}getModules(){return Object.values(this.modules)}getUniformValues(){return this.moduleUniforms}getBindings(){let t={};for(let e of Object.values(this.moduleBindings))Object.assign(t,e);return t}getDebugTable(){let t={};for(let[e,n]of Object.entries(this.moduleUniforms))for(let[r,i]of Object.entries(n))t[`${e}.${r}`]={type:this.modules[e].uniformTypes?.[r],value:String(i)};return t}};var zt=C(z(),1);var $s=class{device;_hashCounter=0;_hashes={};_renderPipelineCache={};_computePipelineCache={};static getDefaultPipelineFactory(t){return t._lumaData.defaultPipelineFactory=t._lumaData.defaultPipelineFactory||new $s(t),t._lumaData.defaultPipelineFactory}constructor(t){this.device=t}createRenderPipeline(t){let e={...zt.RenderPipeline.defaultProps,...t},n=this._hashRenderPipeline(e);if(!this._renderPipelineCache[n]){let r=this.device.createRenderPipeline({...e,id:e.id?`${e.id}-cached`:void 0});r.hash=n,this._renderPipelineCache[n]={pipeline:r,useCount:0}}return this._renderPipelineCache[n].useCount++,this._renderPipelineCache[n].pipeline}createComputePipeline(t){let e={...zt.ComputePipeline.defaultProps,...t},n=this._hashComputePipeline(e);if(!this._computePipelineCache[n]){let r=this.device.createComputePipeline({...e,id:e.id?`${e.id}-cached`:void 0});r.hash=n,this._computePipelineCache[n]={pipeline:r,useCount:0}}return this._computePipelineCache[n].useCount++,this._computePipelineCache[n].pipeline}release(t){let e=t.hash,n=t instanceof zt.ComputePipeline?this._computePipelineCache:this._renderPipelineCache;n[e].useCount--,n[e].useCount===0&&(n[e].pipeline.destroy(),delete n[e])}_hashComputePipeline(t){return`${this._getHash(t.shader.source)}`}_hashRenderPipeline(t){let e=this._getHash(t.vs.source),n=t.fs?this._getHash(t.fs.source):0,r="-",i=this._getHash(JSON.stringify(t.bufferLayout));switch(this.device.type){case"webgl":return`${e}/${n}V${r}BL${i}`;default:let o=this._getHash(JSON.stringify(t.parameters));return`${e}/${n}V${r}T${t.topology}P${o}BL${i}`}}_getHash(t){return this._hashes[t]===void 0&&(this._hashes[t]=this._hashCounter++),this._hashes[t]}},ht=$s;et(ht,"defaultProps",{...zt.RenderPipeline.defaultProps});var Qn=C(z(),1);var js=class{device;_cache={};static getDefaultShaderFactory(t){return t._lumaData.defaultShaderFactory||=new js(t),t._lumaData.defaultShaderFactory}constructor(t){this.device=t}createShader(t){let e=this._hashShader(t),n=this._cache[e];if(!n){let r=this.device.createShader({...t,id:t.id?`${t.id}-cached`:void 0});this._cache[e]=n={shader:r,useCount:0}}return n.useCount++,n.shader}release(t){let e=this._hashShader(t),n=this._cache[e];n&&(n.useCount--,n.useCount===0&&(delete this._cache[e],n.shader.destroy()))}_hashShader(t){return`${t.stage}:${t.source}`}},lt=js;et(lt,"defaultProps",{...Qn.Shader.defaultProps});function tr(s,t){let e={},n="Values";if(s.attributes.length===0&&!s.varyings?.length)return{"No attributes or varyings":{[n]:"N/A"}};for(let r of s.attributes)if(r){let i=`${r.location} ${r.name}: ${r.type}`;e[`in ${i}`]={[n]:r.stepMode||"vertex"}}for(let r of s.varyings||[]){let i=`${r.location} ${r.name}`;e[`out ${i}`]={[n]:JSON.stringify(r.accessor)}}return e}var q=null,Gs=null;function er(s,{id:t,minimap:e,opaque:n,top:r="0",left:i="0",rgbaScale:o=1}){q||(q=document.createElement("canvas"),q.id=t,q.title=t,q.style.zIndex="100",q.style.position="absolute",q.style.top=r,q.style.left=i,q.style.border="blue 1px solid",q.style.transform="scaleY(-1)",document.body.appendChild(q),Gs=q.getContext("2d")),(q.width!==s.width||q.height!==s.height)&&(q.width=s.width/2,q.height=s.height/2,q.style.width="400px",q.style.height="400px");let c=s.device.readPixelsToArrayWebGL(s),h=Gs.createImageData(s.width,s.height),f=0;for(let m=0;m<c.length;m+=4)h.data[f+m+0]=c[m+0]*o,h.data[f+m+1]=c[m+1]*o,h.data[f+m+2]=c[m+2]*o,h.data[f+m+3]=n?255:c[m+3]*o;Gs.putImageData(h,0,0)}var Ct=2,di=1e4,Bs=class{device;id;source;vs;fs;pipelineFactory;shaderFactory;userData={};parameters;topology;bufferLayout;isInstanced=void 0;instanceCount=0;vertexCount;indexBuffer=null;bufferAttributes={};constantAttributes={};bindings={};uniforms={};vertexArray;transformFeedback=null;pipeline;shaderInputs;_uniformStore;_attributeInfos={};_gpuGeometry=null;_getModuleUniforms;props;_pipelineNeedsUpdate="newly created";_needsRedraw="initializing";_destroyed=!1;_lastDrawTimestamp=-1;constructor(t,e){this.props={...Bs.defaultProps,...e},e=this.props,this.id=e.id||(0,F.uid)("model"),this.device=t,Object.assign(this.userData,e.userData);let n=Object.fromEntries(this.props.modules?.map(c=>[c.name,c])||[]);this.setShaderInputs(e.shaderInputs||new gt(n));let r=mi(t),i=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];if(this.device.type==="webgpu"&&this.props.source){this.props.shaderLayout||=Yt(this.props.source);let{source:c,getUniforms:h}=this.props.shaderAssembler.assembleShader({platformInfo:r,...this.props,modules:i});this.source=c,this._getModuleUniforms=h}else{let{vs:c,fs:h,getUniforms:f}=this.props.shaderAssembler.assembleShaderPair({platformInfo:r,...this.props,modules:i});this.vs=c,this.fs=h,this._getModuleUniforms=f}this.vertexCount=this.props.vertexCount,this.instanceCount=this.props.instanceCount,this.topology=this.props.topology,this.bufferLayout=this.props.bufferLayout,this.parameters=this.props.parameters,e.geometry&&this.setGeometry(e.geometry),this.pipelineFactory=e.pipelineFactory||ht.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||lt.getDefaultShaderFactory(this.device),this.pipeline=this._updatePipeline(),this.vertexArray=t.createVertexArray({renderPipeline:this.pipeline}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry),"isInstanced"in e&&(this.isInstanced=e.isInstanced),e.instanceCount&&this.setInstanceCount(e.instanceCount),e.vertexCount&&this.setVertexCount(e.vertexCount),e.indexBuffer&&this.setIndexBuffer(e.indexBuffer),e.attributes&&this.setAttributes(e.attributes),e.constantAttributes&&this.setConstantAttributes(e.constantAttributes),e.bindings&&this.setBindings(e.bindings),e.uniforms&&this.setUniforms(e.uniforms),e.moduleSettings&&this.updateModuleSettings(e.moduleSettings),e.transformFeedback&&(this.transformFeedback=e.transformFeedback),Object.seal(this)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.pipeline.vs),this.pipeline.fs&&this.shaderFactory.release(this.pipeline.fs),this._uniformStore.destroy(),this._gpuGeometry?.destroy(),this._destroyed=!0)}needsRedraw(){this._getBindingsUpdateTimestamp()>this._lastDrawTimestamp&&this.setNeedsRedraw("contents of bound textures or buffers updated");let t=this._needsRedraw;return this._needsRedraw=!1,t}setNeedsRedraw(t){this._needsRedraw||=t}predraw(){this.updateShaderInputs(),this.pipeline=this._updatePipeline()}draw(t){this.predraw();let e;try{this._logDrawCallStart(),this.pipeline=this._updatePipeline(),this.pipeline.setBindings(this.bindings,{disableWarnings:this.props.disableWarnings}),(0,F.isObjectEmpty)(this.uniforms)||this.pipeline.setUniformsWebGL(this.uniforms);let{indexBuffer:n}=this.vertexArray,r=n?n.byteLength/(n.indexType==="uint32"?4:2):void 0;e=this.pipeline.draw({renderPass:t,vertexArray:this.vertexArray,isInstanced:this.isInstanced,vertexCount:this.vertexCount,instanceCount:this.instanceCount,indexCount:r,transformFeedback:this.transformFeedback||void 0,parameters:this.parameters,topology:this.topology})}finally{this._logDrawCallEnd()}return this._logFramebuffer(t),e?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):this._needsRedraw="waiting for resource initialization",e}setGeometry(t){this._gpuGeometry?.destroy();let e=t&&Jn(this.device,t);e&&(this.setTopology(e.topology||"triangle-list"),this.bufferLayout=sr(e.bufferLayout,this.bufferLayout),this.vertexArray&&this._setGeometryAttributes(e)),this._gpuGeometry=e}setTopology(t){t!==this.topology&&(this.topology=t,this._setPipelineNeedsUpdate("topology"))}setBufferLayout(t){this.bufferLayout=this._gpuGeometry?sr(t,this._gpuGeometry.bufferLayout):t,this._setPipelineNeedsUpdate("bufferLayout"),this.pipeline=this._updatePipeline(),this.vertexArray=this.device.createVertexArray({renderPipeline:this.pipeline}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry)}setParameters(t){(0,F.deepEqual)(t,this.parameters,2)||(this.parameters=t,this._setPipelineNeedsUpdate("parameters"))}setInstanceCount(t){this.instanceCount=t,this.isInstanced===void 0&&t>0&&(this.isInstanced=!0),this.setNeedsRedraw("instanceCount")}setVertexCount(t){this.vertexCount=t,this.setNeedsRedraw("vertexCount")}setShaderInputs(t){this.shaderInputs=t,this._uniformStore=new Le.UniformStore(this.shaderInputs.modules);for(let e of Object.keys(this.shaderInputs.modules)){let n=this._uniformStore.getManagedUniformBuffer(this.device,e);this.bindings[`${e}Uniforms`]=n}this.setNeedsRedraw("shaderInputs")}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues()),this.setNeedsRedraw("shaderInputs")}setBindings(t){Object.assign(this.bindings,t),this.setNeedsRedraw("bindings")}setTransformFeedback(t){this.transformFeedback=t,this.setNeedsRedraw("transformFeedback")}setIndexBuffer(t){this.vertexArray.setIndexBuffer(t),this.setNeedsRedraw("indexBuffer")}setAttributes(t,e){t.indices&&F.log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)();for(let[n,r]of Object.entries(t)){let i=this.bufferLayout.find(h=>nr(h).includes(n));if(!i){F.log.warn(`Model(${this.id}): Missing layout for buffer "${n}".`)();continue}let o=nr(i),c=!1;for(let h of o){let f=this._attributeInfos[h];f&&(this.vertexArray.setBuffer(f.location,r),c=!0)}!c&&!(e?.disableWarnings??this.props.disableWarnings)&&F.log.warn(`Model(${this.id}): Ignoring buffer "${r.id}" for unknown attribute "${n}"`)()}this.setNeedsRedraw("attributes")}setConstantAttributes(t,e){for(let[n,r]of Object.entries(t)){let i=this._attributeInfos[n];i?this.vertexArray.setConstantWebGL(i.location,r):(e?.disableWarnings??this.props.disableWarnings)||F.log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${n}"`)()}this.setNeedsRedraw("constants")}setUniforms(t){(0,F.isObjectEmpty)(t)||(this.pipeline.setUniformsWebGL(t),Object.assign(this.uniforms,t)),this.setNeedsRedraw("uniforms")}updateModuleSettings(t){let{bindings:e,uniforms:n}=(0,F.splitUniformsAndBindings)(this._getModuleUniforms(t));Object.assign(this.bindings,e),Object.assign(this.uniforms,n),this.setNeedsRedraw("moduleSettings")}_getBindingsUpdateTimestamp(){let t=0;for(let e of Object.values(this.bindings))e instanceof ut.TextureView?t=Math.max(t,e.texture.updateTimestamp):e instanceof ut.Buffer||e instanceof ut.Texture?t=Math.max(t,e.updateTimestamp):e instanceof ut.Sampler||(t=Math.max(t,e.buffer.updateTimestamp));return t}_setGeometryAttributes(t){let e={...t.attributes};for(let[n]of Object.entries(e))!this.pipeline.shaderLayout.attributes.find(r=>r.name===n)&&n!=="positions"&&delete e[n];this.vertexCount=t.vertexCount,this.setIndexBuffer(t.indices||null),this.setAttributes(t.attributes,{disableWarnings:!0}),this.setAttributes(e,{disableWarnings:this.props.disableWarnings}),this.setNeedsRedraw("geometry attributes")}_setPipelineNeedsUpdate(t){this._pipelineNeedsUpdate||=t,this.setNeedsRedraw(t)}_updatePipeline(){if(this._pipelineNeedsUpdate){let t=null,e=null;this.pipeline&&(F.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),t=this.pipeline.vs,e=this.pipeline.fs),this._pipelineNeedsUpdate=!1;let n=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:"vertex",source:this.source||this.vs,debug:this.props.debugShaders}),r=null;this.source?r=n:this.fs&&(r=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"fragment",source:this.source||this.fs,debug:this.props.debugShaders})),this.pipeline=this.pipelineFactory.createRenderPipeline({...this.props,bufferLayout:this.bufferLayout,topology:this.topology,parameters:this.parameters,vs:n,fs:r}),this._attributeInfos=(0,Re.getAttributeInfosFromLayouts)(this.pipeline.shaderLayout,this.bufferLayout),t&&this.shaderFactory.release(t),e&&this.shaderFactory.release(e)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let t=F.log.level>3?0:di;F.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,F.log.group(Ct,`>>> DRAWING MODEL ${this.id}`,{collapsed:F.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=tr(this.pipeline.shaderLayout,this.id);F.log.table(Ct,t)();let e=this.shaderInputs.getDebugTable();for(let[r,i]of Object.entries(this.uniforms))e[r]={value:i};F.log.table(Ct,e)();let n=this._getAttributeDebugTable();F.log.table(Ct,this._attributeInfos)(),F.log.table(Ct,n)(),F.log.groupEnd(Ct)(),this._logOpen=!1}}_drawCount=0;_logFramebuffer(t){let e=F.log.get("framebuffer");if(this._drawCount++,!e||this._drawCount++>3&&this._drawCount%60)return;let n=t.props.framebuffer;n&&er(n,{id:n.id,minimap:!0})}_getAttributeDebugTable(){let t={};for(let[e,n]of Object.entries(this._attributeInfos))t[n.location]={name:e,type:n.shaderType,values:this._getBufferOrConstantValues(this.vertexArray.attributes[n.location],n.bufferDataType)};if(this.vertexArray.indexBuffer){let{indexBuffer:e}=this.vertexArray,n=e.indexType==="uint32"?new Uint32Array(e.debugData):new Uint16Array(e.debugData);t.indices={name:"indices",type:e.indexType,values:n.toString()}}return t}_getBufferOrConstantValues(t,e){let n=(0,Re.getTypedArrayFromDataType)(e);return(t instanceof ut.Buffer?new n(t.debugData):t).toString()}},K=Bs;et(K,"defaultProps",{...Le.RenderPipeline.defaultProps,source:null,vs:null,fs:null,id:"unnamed",handle:void 0,userData:{},defines:{},modules:[],moduleSettings:void 0,geometry:null,indexBuffer:null,attributes:{},constantAttributes:{},varyings:[],isInstanced:void 0,instanceCount:0,vertexCount:0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,transformFeedback:void 0,shaderAssembler:dt.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0});function sr(s,t){let e=[...s];for(let n of t){let r=e.findIndex(i=>i.name===n.name);r<0?e.push(n):e[r]=n}return e}function mi(s){return{type:s.type,shaderLanguage:s.info.shadingLanguage,shaderLanguageVersion:s.info.shadingLanguageVersion,gpu:s.info.gpu,features:s.features}}function nr(s){return s.attributes?s.attributes?.map(t=>t.attribute):[s.name]}var ze=C(z(),1);var Ft=class{device;model;transformFeedback;static isSupported(t){return t?.info?.type==="webgl"}constructor(t,e=K.defaultProps){(0,ze.assert)(Ft.isSupported(t),"BufferTransform not yet implemented on WebGPU"),this.device=t,this.model=new K(this.device,{id:e.id||"buffer-transform-model",fs:e.fs||Bt(),topology:e.topology||"point-list",...e}),this.transformFeedback=this.device.createTransformFeedback({layout:this.model.pipeline.shaderLayout,buffers:e.feedbackBuffers}),this.model.setTransformFeedback(this.transformFeedback),Object.seal(this)}destroy(){this.model&&this.model.destroy()}delete(){this.destroy()}run(t){let e=this.device.beginRenderPass(t);this.model.draw(e),e.end()}update(...t){console.warn("TextureTransform#update() not implemented")}getBuffer(t){return this.transformFeedback.getBuffer(t)}readAsync(t){let e=this.getBuffer(t);if(e instanceof ze.Buffer)return e.readAsync();let{buffer:n,byteOffset:r=0,byteLength:i=n.byteLength}=e;return n.readAsync(r,i)}};var pi="transform_output",Ce=class{device;model;sampler;currentIndex=0;samplerTextureMap=null;bindings=[];resources={};constructor(t,e){this.device=t,this.sampler=t.createSampler({addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",minFilter:"nearest",magFilter:"nearest",mipmapFilter:"nearest"}),this.model=new K(this.device,{id:e.id||"texture-transform-model",fs:e.fs||Bt({input:e.targetTextureVarying,inputChannels:e.targetTextureChannels,output:pi}),vertexCount:e.vertexCount,...e}),this._initialize(e),Object.seal(this)}destroy(){}delete(){this.destroy()}run(t){let{framebuffer:e}=this.bindings[this.currentIndex],n=this.device.beginRenderPass({framebuffer:e,...t});this.model.draw(n),n.end()}update(...t){console.warn("TextureTransform#update() not implemented")}getData({packed:t=!1}={}){throw new Error("getData() not implemented")}getTargetTexture(){let{targetTexture:t}=this.bindings[this.currentIndex];return t}getFramebuffer(){return this.bindings[this.currentIndex].framebuffer}_initialize(t){this._updateBindings(t)}_updateBindings(t){this.bindings[this.currentIndex]=this._updateBinding(this.bindings[this.currentIndex],t)}_updateBinding(t,{sourceBuffers:e,sourceTextures:n,targetTexture:r}){if(t||(t={sourceBuffers:{},sourceTextures:{},targetTexture:null}),Object.assign(t.sourceTextures,n),Object.assign(t.sourceBuffers,e),r){t.targetTexture=r;let{width:i,height:o}=r;t.framebuffer&&t.framebuffer.destroy(),t.framebuffer=this.device.createFramebuffer({id:"transform-framebuffer",width:i,height:o,colorAttachments:[r]}),t.framebuffer.resize({width:i,height:o})}return t}_setSourceTextureParameters(){let t=this.currentIndex,{sourceTextures:e}=this.bindings[t];for(let n in e)e[n].sampler=this.sampler}};var ec=C(z(),1);var Dt=C(z(),1),G=class{id;topology;vertexCount;indices;attributes;userData={};constructor(t){let{attributes:e={},indices:n=null,vertexCount:r=null}=t;this.id=t.id||(0,Dt.uid)("geometry"),this.topology=t.topology,n&&(this.indices=ArrayBuffer.isView(n)?{value:n,size:1}:n),this.attributes={};for(let[i,o]of Object.entries(e)){let c=ArrayBuffer.isView(o)?{value:o}:o;(0,Dt.assert)(ArrayBuffer.isView(c.value),`${this._print(i)}: must be typed array or object with value as typed array`),(i==="POSITION"||i==="positions")&&!c.size&&(c.size=3),i==="indices"?((0,Dt.assert)(!this.indices),this.indices=c):this.attributes[i]=c}this.indices&&this.indices.isIndexed!==void 0&&(this.indices=Object.assign({},this.indices),delete this.indices.isIndexed),this.vertexCount=r||this._calculateVertexCount(this.attributes,this.indices)}getVertexCount(){return this.vertexCount}getAttributes(){return this.indices?{indices:this.indices,...this.attributes}:this.attributes}_print(t){return`Geometry ${this.id} attribute ${t}`}_setAttributes(t,e){return this}_calculateVertexCount(t,e){if(e)return e.value.length;let n=1/0;for(let r of Object.values(t)){let{value:i,size:o,constant:c}=r;!c&&i&&o>=1&&(n=Math.min(n,i.length/o))}return(0,Dt.assert)(Number.isFinite(n)),n}};var _i=`#version 300 es
86
+ `;){if(this._isAtEnd())return!0;t=this._advance()}return this._line++,!0}else if(this._peekAhead()=="*"){this._advance();let o=1;for(;o>0;){if(this._isAtEnd())return!0;if(t=this._advance(),t==`
87
+ `)this._line++;else if(t=="*"){if(this._peekAhead()=="/"&&(this._advance(),o--,o==0))return!0}else t=="/"&&this._peekAhead()=="*"&&(this._advance(),o++)}return!0}}let e=a.simpleTokens[t];if(e)return this._addToken(e),!0;let n=a.none,r=this._isAlpha(t),i=t==="_";if(this._isAlphaNumeric(t)){let o=this._peekAhead();for(;this._isAlphaNumeric(o);)t+=this._advance(),o=this._peekAhead()}if(r){let o=a.keywords[t];if(o)return this._addToken(o),!0}if(r||i)return this._addToken(a.tokens.ident),!0;for(;;){let o=this._findType(t),c=this._peekAhead();if(t==">"&&(c==">"||c=="=")){let h=!1,f=this._tokens.length-1;for(let m=0;m<5&&f>=0;++m,--f)if(this._tokens[f].type===a.tokens.less_than){f>0&&this._tokens[f-1].isArrayOrTemplateType()&&(h=!0);break}if(h)return this._addToken(o),!0}if(o===a.none){let h=t,f=0,m=2;for(let p=0;p<m;++p)if(h+=this._peekAhead(p),o=this._findType(h),o!==a.none){f=p;break}if(o===a.none)return n===a.none?!1:(this._current--,this._addToken(n),!0);t=h,this._current+=f+1}if(n=o,this._isAtEnd())break;t+=this._advance()}return n===a.none?!1:(this._addToken(n),!0)}_findType(t){for(let n in a.regexTokens){let r=a.regexTokens[n];if(this._match(t,r.rule))return r}let e=a.literalTokens[t];return e||a.none}_match(t,e){let n=e.exec(t);return n&&n.index==0&&n[0]==t}_isAtEnd(){return this._current>=this._source.length}_isAlpha(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"}_isAlphaNumeric(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"||t=="_"||t>="0"&&t<="9"}_isWhitespace(t){return t==" "||t==" "||t=="\r"}_advance(t=0){let e=this._source[this._current];return t=t||0,t++,this._current+=t,e}_peekAhead(t=0){return t=t||0,this._current+t>=this._source.length?"\0":this._source[this._current+t]}_addToken(t){let e=this._source.substring(this._start,this._current);this._tokens.push(new Ae(t,e,this._line))}},Ps=class{constructor(){this._tokens=[],this._current=0,this._currentLine=0,this._context=new rs,this._deferArrayCountEval=[]}parse(t){this._initialize(t),this._deferArrayCountEval.length=0;let e=[];for(;!this._isAtEnd();){let n=this._global_decl_or_directive();if(!n)break;e.push(n)}if(this._deferArrayCountEval.length>0){for(let n of this._deferArrayCountEval){let r=n.arrayType,i=n.countNode;if(i instanceof Jt){let c=i.name,h=this._context.constants.get(c);if(h)try{let f=h.evaluate(this._context);r.count=f}catch{}}}this._deferArrayCountEval.length=0}return e}_initialize(t){if(t)if(typeof t=="string"){let e=new Ns(t);this._tokens=e.scanTokens()}else this._tokens=t;else this._tokens=[];this._current=0}_error(t,e){return{token:t,message:e,toString:function(){return`${e}`}}}_isAtEnd(){return this._current>=this._tokens.length||this._peek().type==a.eof}_match(t){if(t instanceof l)return this._check(t)?(this._advance(),!0):!1;for(let e=0,n=t.length;e<n;++e){let r=t[e];if(this._check(r))return this._advance(),!0}return!1}_consume(t,e){if(this._check(t))return this._advance();throw this._error(this._peek(),e)}_check(t){if(this._isAtEnd())return!1;let e=this._peek();if(t instanceof Array){let n=e.type;return t.indexOf(n)!=-1}return e.type==t}_advance(){var t,e;return this._currentLine=(e=(t=this._peek())===null||t===void 0?void 0:t.line)!==null&&e!==void 0?e:-1,this._isAtEnd()||this._current++,this._previous()}_peek(){return this._tokens[this._current]}_previous(){return this._tokens[this._current-1]}_global_decl_or_directive(){for(;this._match(a.tokens.semicolon)&&!this._isAtEnd(););if(this._match(a.keywords.alias)){let e=this._type_alias();return this._consume(a.tokens.semicolon,"Expected ';'"),e}if(this._match(a.keywords.diagnostic)){let e=this._diagnostic();return this._consume(a.tokens.semicolon,"Expected ';'"),e}if(this._match(a.keywords.requires)){let e=this._requires_directive();return this._consume(a.tokens.semicolon,"Expected ';'"),e}if(this._match(a.keywords.enable)){let e=this._enable_directive();return this._consume(a.tokens.semicolon,"Expected ';'"),e}let t=this._attribute();if(this._check(a.keywords.var)){let e=this._global_variable_decl();return e!=null&&(e.attributes=t),this._consume(a.tokens.semicolon,"Expected ';'."),e}if(this._check(a.keywords.override)){let e=this._override_variable_decl();return e!=null&&(e.attributes=t),this._consume(a.tokens.semicolon,"Expected ';'."),e}if(this._check(a.keywords.let)){let e=this._global_let_decl();return e!=null&&(e.attributes=t),this._consume(a.tokens.semicolon,"Expected ';'."),e}if(this._check(a.keywords.const)){let e=this._global_const_decl();return e!=null&&(e.attributes=t),this._consume(a.tokens.semicolon,"Expected ';'."),e}if(this._check(a.keywords.struct)){let e=this._struct_decl();return e!=null&&(e.attributes=t),e}if(this._check(a.keywords.fn)){let e=this._function_decl();return e!=null&&(e.attributes=t),e}return null}_function_decl(){if(!this._match(a.keywords.fn))return null;let t=this._currentLine,e=this._consume(a.tokens.ident,"Expected function name.").toString();this._consume(a.tokens.paren_left,"Expected '(' for function arguments.");let n=[];if(!this._check(a.tokens.paren_right))do{if(this._check(a.tokens.paren_right))break;let c=this._attribute(),h=this._consume(a.tokens.ident,"Expected argument name.").toString();this._consume(a.tokens.colon,"Expected ':' for argument type.");let f=this._attribute(),m=this._type_decl();m!=null&&(m.attributes=f,n.push(new Ts(h,m,c)))}while(this._match(a.tokens.comma));this._consume(a.tokens.paren_right,"Expected ')' after function arguments.");let r=null;if(this._match(a.tokens.arrow)){let c=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=c)}let i=this._compound_statement(),o=this._currentLine;return new Xt(e,n,r,i,t,o)}_compound_statement(){let t=[];for(this._consume(a.tokens.brace_left,"Expected '{' for block.");!this._check(a.tokens.brace_right);){let e=this._statement();e!==null&&t.push(e)}return this._consume(a.tokens.brace_right,"Expected '}' for block."),t}_statement(){for(;this._match(a.tokens.semicolon)&&!this._isAtEnd(););if(this._check(a.tokens.attr)&&this._attribute(),this._check(a.keywords.if))return this._if_statement();if(this._check(a.keywords.switch))return this._switch_statement();if(this._check(a.keywords.loop))return this._loop_statement();if(this._check(a.keywords.for))return this._for_statement();if(this._check(a.keywords.while))return this._while_statement();if(this._check(a.keywords.continuing))return this._continuing_statement();if(this._check(a.keywords.static_assert))return this._static_assert_statement();if(this._check(a.tokens.brace_left))return this._compound_statement();let t=null;return this._check(a.keywords.return)?t=this._return_statement():this._check([a.keywords.var,a.keywords.let,a.keywords.const])?t=this._variable_statement():this._match(a.keywords.discard)?t=new xs:this._match(a.keywords.break)?t=new ys:this._match(a.keywords.continue)?t=new ws:t=this._increment_decrement_statement()||this._func_call_statement()||this._assignment_statement(),t!=null&&this._consume(a.tokens.semicolon,"Expected ';' after statement."),t}_static_assert_statement(){if(!this._match(a.keywords.static_assert))return null;let t=this._optional_paren_expression();return new is(t)}_while_statement(){if(!this._match(a.keywords.while))return null;let t=this._optional_paren_expression();this._check(a.tokens.attr)&&this._attribute();let e=this._compound_statement();return new os(t,e)}_continuing_statement(){if(!this._match(a.keywords.continuing))return null;let t=this._compound_statement();return new as(t)}_for_statement(){if(!this._match(a.keywords.for))return null;this._consume(a.tokens.paren_left,"Expected '('.");let t=this._check(a.tokens.semicolon)?null:this._for_init();this._consume(a.tokens.semicolon,"Expected ';'.");let e=this._check(a.tokens.semicolon)?null:this._short_circuit_or_expression();this._consume(a.tokens.semicolon,"Expected ';'.");let n=this._check(a.tokens.paren_right)?null:this._for_increment();this._consume(a.tokens.paren_right,"Expected ')'."),this._check(a.tokens.attr)&&this._attribute();let r=this._compound_statement();return new cs(t,e,n,r)}_for_init(){return this._variable_statement()||this._func_call_statement()||this._assignment_statement()}_for_increment(){return this._func_call_statement()||this._increment_decrement_statement()||this._assignment_statement()}_variable_statement(){if(this._check(a.keywords.var)){let t=this._variable_decl();if(t===null)throw this._error(this._peek(),"Variable declaration expected.");let e=null;return this._match(a.tokens.equal)&&(e=this._short_circuit_or_expression()),new ot(t.name,t.type,t.storage,t.access,e)}if(this._match(a.keywords.let)){let t=this._consume(a.tokens.ident,"Expected name for let.").toString(),e=null;if(this._match(a.tokens.colon)){let r=this._attribute();e=this._type_decl(),e!=null&&(e.attributes=r)}this._consume(a.tokens.equal,"Expected '=' for let.");let n=this._short_circuit_or_expression();return new Kt(t,e,null,null,n)}if(this._match(a.keywords.const)){let t=this._consume(a.tokens.ident,"Expected name for const.").toString(),e=null;if(this._match(a.tokens.colon)){let r=this._attribute();e=this._type_decl(),e!=null&&(e.attributes=r)}this._consume(a.tokens.equal,"Expected '=' for const.");let n=this._short_circuit_or_expression();return new me(t,e,null,null,n)}return null}_increment_decrement_statement(){let t=this._current,e=this._unary_expression();if(e==null)return null;if(!this._check(a.increment_operators))return this._current=t,null;let n=this._consume(a.increment_operators,"Expected increment operator");return new hs(n.type===a.tokens.plus_plus?Nt.increment:Nt.decrement,e)}_assignment_statement(){let t=null;if(this._check(a.tokens.brace_right))return null;let e=this._match(a.tokens.underscore);if(e||(t=this._unary_expression()),!e&&t==null)return null;let n=this._consume(a.assignment_operators,"Expected assignment operator."),r=this._short_circuit_or_expression();return new ls(Zt.parse(n.lexeme),t,r)}_func_call_statement(){if(!this._check(a.tokens.ident))return null;let t=this._current,e=this._consume(a.tokens.ident,"Expected function name."),n=this._argument_expression_list();return n===null?(this._current=t,null):new pe(e.lexeme,n)}_loop_statement(){if(!this._match(a.keywords.loop))return null;this._check(a.tokens.attr)&&this._attribute(),this._consume(a.tokens.brace_left,"Expected '{' for loop.");let t=[],e=this._statement();for(;e!==null;){if(Array.isArray(e))for(let r of e)t.push(r);else t.push(e);e=this._statement()}let n=null;return this._match(a.keywords.continuing)&&(n=this._compound_statement()),this._consume(a.tokens.brace_right,"Expected '}' for loop."),new us(t,n)}_switch_statement(){if(!this._match(a.keywords.switch))return null;let t=this._optional_paren_expression();this._check(a.tokens.attr)&&this._attribute(),this._consume(a.tokens.brace_left,"Expected '{' for switch.");let e=this._switch_body();if(e==null||e.length==0)throw this._error(this._previous(),"Expected 'case' or 'default'.");return this._consume(a.tokens.brace_right,"Expected '}' for switch."),new fs(t,e)}_switch_body(){let t=[];if(this._match(a.keywords.case)){let e=this._case_selectors();this._match(a.tokens.colon),this._check(a.tokens.attr)&&this._attribute(),this._consume(a.tokens.brace_left,"Exected '{' for switch case.");let n=this._case_body();this._consume(a.tokens.brace_right,"Exected '}' for switch case."),t.push(new As(e,n))}if(this._match(a.keywords.default)){this._match(a.tokens.colon),this._check(a.tokens.attr)&&this._attribute(),this._consume(a.tokens.brace_left,"Exected '{' for switch default.");let e=this._case_body();this._consume(a.tokens.brace_right,"Exected '}' for switch default."),t.push(new Es(e))}if(this._check([a.keywords.default,a.keywords.case])){let e=this._switch_body();t.push(e[0])}return t}_case_selectors(){let t=[this._shift_expression()];for(;this._match(a.tokens.comma);)t.push(this._shift_expression());return t}_case_body(){if(this._match(a.keywords.fallthrough))return this._consume(a.tokens.semicolon,"Expected ';'"),[];let t=this._statement();if(t==null)return[];t instanceof Array||(t=[t]);let e=this._case_body();return e.length==0?t:[...t,e[0]]}_if_statement(){if(!this._match(a.keywords.if))return null;let t=this._optional_paren_expression();this._check(a.tokens.attr)&&this._attribute();let e=this._compound_statement(),n=[];this._match_elseif()&&(this._check(a.tokens.attr)&&this._attribute(),n=this._elseif_statement(n));let r=null;return this._match(a.keywords.else)&&(this._check(a.tokens.attr)&&this._attribute(),r=this._compound_statement()),new ds(t,e,n,r)}_match_elseif(){return this._tokens[this._current].type===a.keywords.else&&this._tokens[this._current+1].type===a.keywords.if?(this._advance(),this._advance(),!0):!1}_elseif_statement(t=[]){let e=this._optional_paren_expression(),n=this._compound_statement();return t.push(new Os(e,n)),this._match_elseif()&&(this._check(a.tokens.attr)&&this._attribute(),this._elseif_statement(t)),t}_return_statement(){if(!this._match(a.keywords.return))return null;let t=this._short_circuit_or_expression();return new ms(t)}_short_circuit_or_expression(){let t=this._short_circuit_and_expr();for(;this._match(a.tokens.or_or);)t=new Y(this._previous().toString(),t,this._short_circuit_and_expr());return t}_short_circuit_and_expr(){let t=this._inclusive_or_expression();for(;this._match(a.tokens.and_and);)t=new Y(this._previous().toString(),t,this._inclusive_or_expression());return t}_inclusive_or_expression(){let t=this._exclusive_or_expression();for(;this._match(a.tokens.or);)t=new Y(this._previous().toString(),t,this._exclusive_or_expression());return t}_exclusive_or_expression(){let t=this._and_expression();for(;this._match(a.tokens.xor);)t=new Y(this._previous().toString(),t,this._and_expression());return t}_and_expression(){let t=this._equality_expression();for(;this._match(a.tokens.and);)t=new Y(this._previous().toString(),t,this._equality_expression());return t}_equality_expression(){let t=this._relational_expression();return this._match([a.tokens.equal_equal,a.tokens.not_equal])?new Y(this._previous().toString(),t,this._relational_expression()):t}_relational_expression(){let t=this._shift_expression();for(;this._match([a.tokens.less_than,a.tokens.greater_than,a.tokens.less_than_equal,a.tokens.greater_than_equal]);)t=new Y(this._previous().toString(),t,this._shift_expression());return t}_shift_expression(){let t=this._additive_expression();for(;this._match([a.tokens.shift_left,a.tokens.shift_right]);)t=new Y(this._previous().toString(),t,this._additive_expression());return t}_additive_expression(){let t=this._multiplicative_expression();for(;this._match([a.tokens.plus,a.tokens.minus]);)t=new Y(this._previous().toString(),t,this._multiplicative_expression());return t}_multiplicative_expression(){let t=this._unary_expression();for(;this._match([a.tokens.star,a.tokens.forward_slash,a.tokens.modulo]);)t=new Y(this._previous().toString(),t,this._unary_expression());return t}_unary_expression(){return this._match([a.tokens.minus,a.tokens.bang,a.tokens.tilde,a.tokens.star,a.tokens.and])?new Ss(this._previous().toString(),this._unary_expression()):this._singular_expression()}_singular_expression(){let t=this._primary_expression(),e=this._postfix_expression();return e&&(t.postfix=e),t}_postfix_expression(){if(this._match(a.tokens.bracket_left)){let t=this._short_circuit_or_expression();this._consume(a.tokens.bracket_right,"Expected ']'.");let e=new Ms(t),n=this._postfix_expression();return n&&(e.postfix=n),e}if(this._match(a.tokens.period)){let t=this._consume(a.tokens.ident,"Expected member name."),e=this._postfix_expression(),n=new ye(t.lexeme);return e&&(n.postfix=e),n}return null}_getStruct(t){return this._context.aliases.has(t)?this._context.aliases.get(t).type:this._context.structs.has(t)?this._context.structs.get(t):null}_primary_expression(){if(this._match(a.tokens.ident)){let n=this._previous().toString();if(this._check(a.tokens.paren_left)){let r=this._argument_expression_list(),i=this._getStruct(n);return i!=null?new _t(i,r):new we(n,r)}if(this._context.constants.has(n)){let r=this._context.constants.get(n);return new ke(n,r.value)}return new Jt(n)}if(this._match(a.const_literal))return new ve(parseFloat(this._previous().toString()));if(this._check(a.tokens.paren_left))return this._paren_expression();if(this._match(a.keywords.bitcast)){this._consume(a.tokens.less_than,"Expected '<'.");let n=this._type_decl();this._consume(a.tokens.greater_than,"Expected '>'.");let r=this._paren_expression();return new vs(n,r)}let t=this._type_decl(),e=this._argument_expression_list();return new bs(t,e)}_argument_expression_list(){if(!this._match(a.tokens.paren_left))return null;let t=[];do{if(this._check(a.tokens.paren_right))break;let e=this._short_circuit_or_expression();t.push(e)}while(this._match(a.tokens.comma));return this._consume(a.tokens.paren_right,"Expected ')' for agument list"),t}_optional_paren_expression(){this._match(a.tokens.paren_left);let t=this._short_circuit_or_expression();return this._match(a.tokens.paren_right),new be([t])}_paren_expression(){this._consume(a.tokens.paren_left,"Expected '('.");let t=this._short_circuit_or_expression();return this._consume(a.tokens.paren_right,"Expected ')'."),new be([t])}_struct_decl(){if(!this._match(a.keywords.struct))return null;let t=this._currentLine,e=this._consume(a.tokens.ident,"Expected name for struct.").toString();this._consume(a.tokens.brace_left,"Expected '{' for struct body.");let n=[];for(;!this._check(a.tokens.brace_right);){let o=this._attribute(),c=this._consume(a.tokens.ident,"Expected variable name.").toString();this._consume(a.tokens.colon,"Expected ':' for struct member type.");let h=this._attribute(),f=this._type_decl();f!=null&&(f.attributes=h),this._check(a.tokens.brace_right)?this._match(a.tokens.comma):this._consume(a.tokens.comma,"Expected ',' for struct member."),n.push(new Ls(c,f,o))}this._consume(a.tokens.brace_right,"Expected '}' after struct body.");let r=this._currentLine,i=new it(e,n,t,r);return this._context.structs.set(e,i),i}_global_variable_decl(){let t=this._variable_decl();return t&&this._match(a.tokens.equal)&&(t.value=this._const_expression()),t}_override_variable_decl(){let t=this._override_decl();return t&&this._match(a.tokens.equal)&&(t.value=this._const_expression()),t}_global_const_decl(){if(!this._match(a.keywords.const))return null;let t=this._consume(a.tokens.ident,"Expected variable name"),e=null;if(this._match(a.tokens.colon)){let i=this._attribute();e=this._type_decl(),e!=null&&(e.attributes=i)}let n=null;if(this._match(a.tokens.equal)){let i=this._short_circuit_or_expression();if(i instanceof _t)n=i;else if(i instanceof ke&&i.initializer instanceof _t)n=i.initializer;else try{let o=i.evaluate(this._context);n=new ve(o)}catch{n=i}}let r=new me(t.toString(),e,"","",n);return this._context.constants.set(r.name,r),r}_global_let_decl(){if(!this._match(a.keywords.let))return null;let t=this._consume(a.tokens.ident,"Expected variable name"),e=null;if(this._match(a.tokens.colon)){let r=this._attribute();e=this._type_decl(),e!=null&&(e.attributes=r)}let n=null;return this._match(a.tokens.equal)&&(n=this._const_expression()),new Kt(t.toString(),e,"","",n)}_const_expression(){if(this._match(a.const_literal))return new ye(this._previous().toString());let t=this._type_decl();this._consume(a.tokens.paren_left,"Expected '('.");let e=[];for(;!this._check(a.tokens.paren_right)&&(e.push(this._const_expression()),!!this._check(a.tokens.comma));)this._advance();return this._consume(a.tokens.paren_right,"Expected ')'."),new _t(t,e)}_variable_decl(){if(!this._match(a.keywords.var))return null;let t="",e="";this._match(a.tokens.less_than)&&(t=this._consume(a.storage_class,"Expected storage_class.").toString(),this._match(a.tokens.comma)&&(e=this._consume(a.access_mode,"Expected access_mode.").toString()),this._consume(a.tokens.greater_than,"Expected '>'."));let n=this._consume(a.tokens.ident,"Expected variable name"),r=null;if(this._match(a.tokens.colon)){let i=this._attribute();r=this._type_decl(),r!=null&&(r.attributes=i)}return new ot(n.toString(),r,t,e,null)}_override_decl(){if(!this._match(a.keywords.override))return null;let t=this._consume(a.tokens.ident,"Expected variable name"),e=null;if(this._match(a.tokens.colon)){let n=this._attribute();e=this._type_decl(),e!=null&&(e.attributes=n)}return new de(t.toString(),e,null)}_diagnostic(){this._consume(a.tokens.paren_left,"Expected '('");let t=this._consume(a.tokens.ident,"Expected severity control name.");this._consume(a.tokens.comma,"Expected ','");let e=this._consume(a.tokens.ident,"Expected diagnostic rule name.");return this._consume(a.tokens.paren_right,"Expected ')'"),new gs(t.toString(),e.toString())}_enable_directive(){let t=this._consume(a.tokens.ident,"identity expected.");return new ps(t.toString())}_requires_directive(){let t=[this._consume(a.tokens.ident,"identity expected.").toString()];for(;this._match(a.tokens.comma);){let e=this._consume(a.tokens.ident,"identity expected.");t.push(e.toString())}return new _s(t)}_type_alias(){let t=this._consume(a.tokens.ident,"identity expected.");this._consume(a.tokens.equal,"Expected '=' for type alias.");let e=this._type_decl();if(e===null)throw this._error(this._peek(),"Expected Type for Alias.");this._context.aliases.has(e.name)&&(e=this._context.aliases.get(e.name).type);let n=new _e(t.toString(),e);return this._context.aliases.set(n.name,n),n}_type_decl(){if(this._check([a.tokens.ident,...a.texel_format,a.keywords.bool,a.keywords.f32,a.keywords.i32,a.keywords.u32])){let n=this._advance(),r=n.toString();return this._context.structs.has(r)?this._context.structs.get(r):this._context.aliases.has(r)?this._context.aliases.get(r).type:new at(n.toString())}let t=this._texture_sampler_types();if(t)return t;if(this._check(a.template_types)){let n=this._advance().toString(),r=null,i=null;return this._match(a.tokens.less_than)&&(r=this._type_decl(),i=null,this._match(a.tokens.comma)&&(i=this._consume(a.access_mode,"Expected access_mode for pointer").toString()),this._consume(a.tokens.greater_than,"Expected '>' for type.")),new ge(n,r,i)}if(this._match(a.keywords.ptr)){let n=this._previous().toString();this._consume(a.tokens.less_than,"Expected '<' for pointer.");let r=this._consume(a.storage_class,"Expected storage_class for pointer");this._consume(a.tokens.comma,"Expected ',' for pointer.");let i=this._type_decl(),o=null;return this._match(a.tokens.comma)&&(o=this._consume(a.access_mode,"Expected access_mode for pointer").toString()),this._consume(a.tokens.greater_than,"Expected '>' for pointer."),new ks(n,r.toString(),i,o)}let e=this._attribute();if(this._match(a.keywords.array)){let n=null,r=-1,i=this._previous(),o=null;if(this._match(a.tokens.less_than)){n=this._type_decl(),this._context.aliases.has(n.name)&&(n=this._context.aliases.get(n.name).type);let h="";if(this._match(a.tokens.comma)){o=this._shift_expression();try{h=o.evaluate(this._context).toString(),o=null}catch{h="1"}}this._consume(a.tokens.greater_than,"Expected '>' for array."),r=h?parseInt(h):0}let c=new xe(i.toString(),e,n,r);return o&&this._deferArrayCountEval.push({arrayType:c,countNode:o}),c}return null}_texture_sampler_types(){if(this._match(a.sampler_type))return new vt(this._previous().toString(),null,null);if(this._match(a.depth_texture_type))return new vt(this._previous().toString(),null,null);if(this._match(a.sampled_texture_type)||this._match(a.multisampled_texture_type)){let t=this._previous();this._consume(a.tokens.less_than,"Expected '<' for sampler type.");let e=this._type_decl();return this._consume(a.tokens.greater_than,"Expected '>' for sampler type."),new vt(t.toString(),e,null)}if(this._match(a.storage_texture_type)){let t=this._previous();this._consume(a.tokens.less_than,"Expected '<' for sampler type.");let e=this._consume(a.texel_format,"Invalid texel format.").toString();this._consume(a.tokens.comma,"Expected ',' after texel format.");let n=this._consume(a.access_mode,"Expected access mode for storage texture type.").toString();return this._consume(a.tokens.greater_than,"Expected '>' for sampler type."),new vt(t.toString(),e,n)}return null}_attribute(){let t=[];for(;this._match(a.tokens.attr);){let e=this._consume(a.attribute_name,"Expected attribute name"),n=new Is(e.toString(),null);if(this._match(a.tokens.paren_left)){if(n.value=this._consume(a.literal_or_ident,"Expected attribute value").toString(),this._check(a.tokens.comma)){this._advance();do{let r=this._consume(a.literal_or_ident,"Expected attribute value").toString();n.value instanceof Array||(n.value=[n.value]),n.value.push(r)}while(this._match(a.tokens.comma))}this._consume(a.tokens.paren_right,"Expected ')'")}t.push(n)}return t.length==0?null:t}},gt=class{constructor(t,e){this.name=t,this.attributes=e,this.size=0}get isArray(){return!1}get isStruct(){return!1}get isTemplate(){return!1}},Ee=class{constructor(t,e,n){this.name=t,this.type=e,this.attributes=n,this.offset=0,this.size=0}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray?this.type.format:this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},Et=class extends gt{constructor(t,e){super(t,e),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1}get isStruct(){return!0}},Yt=class extends gt{constructor(t,e){super(t,e),this.count=0,this.stride=0}get isArray(){return!0}},Te=class extends gt{constructor(t,e,n,r){super(t,n),this.format=e,this.access=r}get isTemplate(){return!0}},pt;(function(s){s[s.Uniform=0]="Uniform",s[s.Storage=1]="Storage",s[s.Texture=2]="Texture",s[s.Sampler=3]="Sampler",s[s.StorageTexture=4]="StorageTexture"})(pt||(pt={}));var Tt=class{constructor(t,e,n,r,i,o,c){this.name=t,this.type=e,this.group=n,this.binding=r,this.attributes=i,this.resourceType=o,this.access=c}get isArray(){return this.type.isArray}get isStruct(){return this.type.isStruct}get isTemplate(){return this.type.isTemplate}get size(){return this.type.size}get align(){return this.type.isStruct?this.type.align:0}get members(){return this.type.isStruct?this.type.members:null}get format(){return this.type.isArray?this.type.format:this.type.isTemplate?this.type.format:null}get count(){return this.type.isArray?this.type.count:0}get stride(){return this.type.isArray?this.type.stride:this.size}},Rs=class{constructor(t,e){this.name=t,this.type=e}},Ot=class{constructor(t,e){this.align=t,this.size=e}},zs=class{constructor(t,e,n,r){this.name=t,this.type=e,this.locationType=n,this.location=r,this.interpolation=null}},Oe=class{constructor(t,e,n,r){this.name=t,this.type=e,this.locationType=n,this.location=r}},Cs=class{constructor(t,e=null){this.stage=null,this.inputs=[],this.outputs=[],this.resources=[],this.startLine=-1,this.endLine=-1,this.inUse=!1,this.calls=new Set,this.name=t,this.stage=e}},Fs=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}},Ds=class{constructor(t,e,n,r){this.name=t,this.type=e,this.attributes=n,this.id=r}},Us=class{constructor(t){this.resources=null,this.inUse=!1,this.info=null,this.node=t}},X=class{constructor(t){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new Fs,this.functions=[],this._types=new Map,this._functions=new Map,t&&this.update(t)}_isStorageTexture(t){return t.name=="texture_storage_1d"||t.name=="texture_storage_2d"||t.name=="texture_storage_2d_array"||t.name=="texture_storage_3d"}update(t){let n=new Ps().parse(t);for(let r of n)r instanceof Xt&&this._functions.set(r.name,new Us(r));for(let r of n)if(r instanceof it){let i=this._getTypeInfo(r,null);i instanceof Et&&this.structs.push(i)}for(let r of n){if(r instanceof _e){this.aliases.push(this._getAliasInfo(r));continue}if(r instanceof de){let i=r,o=this._getAttributeNum(i.attributes,"id",0),c=i.type!=null?this._getTypeInfo(i.type,i.attributes):null;this.overrides.push(new Ds(i.name,c,i.attributes,o));continue}if(this._isUniformVar(r)){let i=r,o=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),h=this._getTypeInfo(i.type,i.attributes),f=new Tt(i.name,h,o,c,i.attributes,pt.Uniform,i.access);this.uniforms.push(f);continue}if(this._isStorageVar(r)){let i=r,o=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),h=this._getTypeInfo(i.type,i.attributes),f=this._isStorageTexture(h),m=new Tt(i.name,h,o,c,i.attributes,f?pt.StorageTexture:pt.Storage,i.access);this.storage.push(m);continue}if(this._isTextureVar(r)){let i=r,o=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),h=this._getTypeInfo(i.type,i.attributes),f=this._isStorageTexture(h),m=new Tt(i.name,h,o,c,i.attributes,f?pt.StorageTexture:pt.Texture,i.access);f?this.storage.push(m):this.textures.push(m);continue}if(this._isSamplerVar(r)){let i=r,o=this._getAttributeNum(i.attributes,"group",0),c=this._getAttributeNum(i.attributes,"binding",0),h=this._getTypeInfo(i.type,i.attributes),f=new Tt(i.name,h,o,c,i.attributes,pt.Sampler,i.access);this.samplers.push(f);continue}if(r instanceof Xt){let i=this._getAttribute(r,"vertex"),o=this._getAttribute(r,"fragment"),c=this._getAttribute(r,"compute"),h=i||o||c,f=new Cs(r.name,h?.name);f.startLine=r.startLine,f.endLine=r.endLine,this.functions.push(f),this._functions.get(r.name).info=f,h&&(this._functions.get(r.name).inUse=!0,f.inUse=!0,f.resources=this._findResources(r,!!h),f.inputs=this._getInputs(r.args),f.outputs=this._getOutputs(r.returnType),this.entry[h.name].push(f));continue}}for(let r of this._functions.values())r.info&&(r.info.inUse=r.inUse,this._addCalls(r.node,r.info.calls));for(let r of this.uniforms)this._markStructsInUse(r.type);for(let r of this.storage)this._markStructsInUse(r.type)}_markStructsInUse(t){if(t.isStruct){t.inUse=!0;for(let e of t.members)this._markStructsInUse(e.type)}else if(t.isArray)this._markStructsInUse(t.format);else if(t.isTemplate)this._markStructsInUse(t.format);else{let e=this._getAlias(t.name);e&&this._markStructsInUse(e)}}_addCalls(t,e){var n;for(let r of t.calls){let i=(n=this._functions.get(r.name))===null||n===void 0?void 0:n.info;i&&e.add(i)}}findResource(t,e){for(let n of this.uniforms)if(n.group==t&&n.binding==e)return n;for(let n of this.storage)if(n.group==t&&n.binding==e)return n;for(let n of this.textures)if(n.group==t&&n.binding==e)return n;for(let n of this.samplers)if(n.group==t&&n.binding==e)return n;return null}_findResource(t){for(let e of this.uniforms)if(e.name==t)return e;for(let e of this.storage)if(e.name==t)return e;for(let e of this.textures)if(e.name==t)return e;for(let e of this.samplers)if(e.name==t)return e;return null}_markStructsFromAST(t){let e=this._getTypeInfo(t,null);this._markStructsInUse(e)}_findResources(t,e){let n=[],r=this,i=[];return t.search(o=>{if(o instanceof Lt)i.push({});else if(o instanceof It)i.pop();else if(o instanceof ot){let c=o;e&&c.type!==null&&this._markStructsFromAST(c.type),i.length>0&&(i[i.length-1][c.name]=c)}else if(o instanceof _t){let c=o;e&&c.type!==null&&this._markStructsFromAST(c.type)}else if(o instanceof Kt){let c=o;e&&c.type!==null&&this._markStructsFromAST(c.type),i.length>0&&(i[i.length-1][c.name]=c)}else if(o instanceof Jt){let c=o;if(i.length>0&&i[i.length-1][c.name])return;let h=r._findResource(c.name);h&&n.push(h)}else if(o instanceof we){let c=o,h=r._functions.get(c.name);h&&(e&&(h.inUse=!0),t.calls.add(h.node),h.resources===null&&(h.resources=r._findResources(h.node,e)),n.push(...h.resources))}else if(o instanceof pe){let c=o,h=r._functions.get(c.name);h&&(e&&(h.inUse=!0),t.calls.add(h.node),h.resources===null&&(h.resources=r._findResources(h.node,e)),n.push(...h.resources))}}),[...new Map(n.map(o=>[o.name,o])).values()]}getBindGroups(){let t=[];function e(n,r){n>=t.length&&(t.length=n+1),t[n]===void 0&&(t[n]=[]),r>=t[n].length&&(t[n].length=r+1)}for(let n of this.uniforms){e(n.group,n.binding);let r=t[n.group];r[n.binding]=n}for(let n of this.storage){e(n.group,n.binding);let r=t[n.group];r[n.binding]=n}for(let n of this.textures){e(n.group,n.binding);let r=t[n.group];r[n.binding]=n}for(let n of this.samplers){e(n.group,n.binding);let r=t[n.group];r[n.binding]=n}return t}_getOutputs(t,e=void 0){if(e===void 0&&(e=[]),t instanceof it)this._getStructOutputs(t,e);else{let n=this._getOutputInfo(t);n!==null&&e.push(n)}return e}_getStructOutputs(t,e){for(let n of t.members)if(n.type instanceof it)this._getStructOutputs(n.type,e);else{let r=this._getAttribute(n,"location")||this._getAttribute(n,"builtin");if(r!==null){let i=this._getTypeInfo(n.type,n.type.attributes),o=this._parseInt(r.value),c=new Oe(n.name,i,r.name,o);e.push(c)}}}_getOutputInfo(t){let e=this._getAttribute(t,"location")||this._getAttribute(t,"builtin");if(e!==null){let n=this._getTypeInfo(t,t.attributes),r=this._parseInt(e.value);return new Oe("",n,e.name,r)}return null}_getInputs(t,e=void 0){e===void 0&&(e=[]);for(let n of t)if(n.type instanceof it)this._getStructInputs(n.type,e);else{let r=this._getInputInfo(n);r!==null&&e.push(r)}return e}_getStructInputs(t,e){for(let n of t.members)if(n.type instanceof it)this._getStructInputs(n.type,e);else{let r=this._getInputInfo(n);r!==null&&e.push(r)}}_getInputInfo(t){let e=this._getAttribute(t,"location")||this._getAttribute(t,"builtin");if(e!==null){let n=this._getAttribute(t,"interpolation"),r=this._getTypeInfo(t.type,t.attributes),i=this._parseInt(e.value),o=new zs(t.name,r,e.name,i);return n!==null&&(o.interpolation=this._parseString(n.value)),o}return null}_parseString(t){return t instanceof Array&&(t=t[0]),t}_parseInt(t){t instanceof Array&&(t=t[0]);let e=parseInt(t);return isNaN(e)?t:e}_getAlias(t){for(let e of this.aliases)if(e.name==t)return e.type;return null}_getAliasInfo(t){return new Rs(t.name,this._getTypeInfo(t.type,null))}_getTypeInfo(t,e){if(this._types.has(t))return this._types.get(t);if(t instanceof xe){let r=t,i=this._getTypeInfo(r.format,r.attributes),o=new Yt(r.name,e);return o.format=i,o.count=r.count,this._types.set(t,o),this._updateTypeInfo(o),o}if(t instanceof it){let r=t,i=new Et(r.name,e);i.startLine=r.startLine,i.endLine=r.endLine;for(let o of r.members){let c=this._getTypeInfo(o.type,o.attributes);i.members.push(new Ee(o.name,c,o.attributes))}return this._types.set(t,i),this._updateTypeInfo(i),i}if(t instanceof vt){let r=t,i=r.format instanceof at,o=r.format?i?this._getTypeInfo(r.format,null):new gt(r.format,null):null,c=new Te(r.name,o,e,r.access);return this._types.set(t,c),this._updateTypeInfo(c),c}if(t instanceof ge){let r=t,i=r.format?this._getTypeInfo(r.format,null):null,o=new Te(r.name,i,e,r.access);return this._types.set(t,o),this._updateTypeInfo(o),o}let n=new gt(t.name,e);return this._types.set(t,n),this._updateTypeInfo(n),n}_updateTypeInfo(t){var e,n;let r=this._getTypeSize(t);if(t.size=(e=r?.size)!==null&&e!==void 0?e:0,t instanceof Yt){let i=this._getTypeSize(t.format);t.stride=(n=i?.size)!==null&&n!==void 0?n:0,this._updateTypeInfo(t.format)}t instanceof Et&&this._updateStructInfo(t)}_updateStructInfo(t){var e;let n=0,r=0,i=0,o=0;for(let c=0,h=t.members.length;c<h;++c){let f=t.members[c],m=this._getTypeSize(f);if(!m)continue;(e=this._getAlias(f.type.name))!==null&&e!==void 0||f.type;let p=m.align,_=m.size;n=this._roundUp(p,n+r),r=_,i=n,o=Math.max(o,p),f.offset=n,f.size=_,this._updateTypeInfo(f.type)}t.size=this._roundUp(o,i+r),t.align=o}_getTypeSize(t){var e;if(t==null)return null;let n=this._getAttributeNum(t.attributes,"size",0),r=this._getAttributeNum(t.attributes,"align",0);if(t instanceof Ee&&(t=t.type),t instanceof gt){let i=this._getAlias(t.name);i!==null&&(t=i)}{let i=X._typeInfo[t.name];if(i!==void 0){let o=t.format==="f16"?2:1;return new Ot(Math.max(r,i.align/o),Math.max(n,i.size/o))}}{let i=X._typeInfo[t.name.substring(0,t.name.length-1)];if(i){let o=t.name[t.name.length-1]==="h"?2:1;return new Ot(Math.max(r,i.align/o),Math.max(n,i.size/o))}}if(t instanceof Yt){let i=t,o=8,c=8,h=this._getTypeSize(i.format);h!==null&&(c=h.size,o=h.align);let f=i.count,m=this._getAttributeNum((e=t?.attributes)!==null&&e!==void 0?e:null,"stride",this._roundUp(o,c));return c=f*m,n&&(c=n),new Ot(Math.max(r,o),Math.max(n,c))}if(t instanceof Et){let i=0,o=0,c=0,h=0,f=0;for(let m of t.members){let p=this._getTypeSize(m.type);p!==null&&(i=Math.max(p.align,i),c=this._roundUp(p.align,c+h),h=p.size,f=c)}return o=this._roundUp(i,f+h),new Ot(Math.max(r,i),Math.max(n,o))}return null}_isUniformVar(t){return t instanceof ot&&t.storage=="uniform"}_isStorageVar(t){return t instanceof ot&&t.storage=="storage"}_isTextureVar(t){return t instanceof ot&&t.type!==null&&X._textureTypes.indexOf(t.type.name)!=-1}_isSamplerVar(t){return t instanceof ot&&t.type!==null&&X._samplerTypes.indexOf(t.type.name)!=-1}_getAttribute(t,e){let n=t;if(!n||!n.attributes)return null;let r=n.attributes;for(let i of r)if(i.name==e)return i;return null}_getAttributeNum(t,e,n){if(t===null)return n;for(let r of t)if(r.name==e){let i=r!==null&&r.value!==null?r.value:n;return i instanceof Array&&(i=i[0]),typeof i=="number"?i:typeof i=="string"?parseInt(i):n}return n}_roundUp(t,e){return Math.ceil(e/t)*t}};X._typeInfo={f16:{align:2,size:2},i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},atomic:{align:4,size:4},vec2:{align:8,size:8},vec3:{align:16,size:12},vec4:{align:16,size:16},mat2x2:{align:8,size:16},mat3x2:{align:8,size:24},mat4x2:{align:8,size:32},mat2x3:{align:16,size:32},mat3x3:{align:16,size:48},mat4x3:{align:16,size:64},mat2x4:{align:16,size:32},mat3x4:{align:16,size:48},mat4x4:{align:16,size:64}};X._textureTypes=a.any_texture_type.map(s=>s.name);X._samplerTypes=a.sampler_type.map(s=>s.name);function Qt(s){let t={attributes:[],bindings:[]},e;try{e=Qr(s)}catch(i){return Tn.log.error(i.message)(),t}for(let i of e.uniforms){let o=[];for(let c of i.type?.members||[])o.push({name:c.name,type:En(c.type)});t.bindings.push({type:"uniform",name:i.name,location:i.binding,group:i.group,members:o})}let n=e.entry.vertex[0],r=n?.inputs.length||0;for(let i=0;i<r;i++){let o=n.inputs[i];if(o.locationType==="location"){let c=En(o.type);t.attributes.push({name:o.name,location:Number(o.location),type:c})}}return t}function En(s){return s.format?`${s.name}<${s.format.name}>`:s.name}function Qr(s){try{return new X(s)}catch(t){if(t instanceof Error)throw t;let e="WGSL parse error";throw typeof t=="object"&&t?.message&&(e+=`: ${t.message} `),typeof t=="object"&&t?.token&&(e+=t.token.line||""),new Error(e,{cause:t})}}var Uo=1/Math.PI*180,qo=1/180*Math.PI,ti={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...ti}};var B=globalThis.mathgl.config;function On(s,{precision:t=B.precision}={}){return s=ei(s),`${parseFloat(s.toPrecision(t))}`}function Pt(s){return Array.isArray(s)||ArrayBuffer.isView(s)&&!(s instanceof DataView)}function qs(s,t,e){let n=B.EPSILON;e&&(B.EPSILON=e);try{if(s===t)return!0;if(Pt(s)&&Pt(t)){if(s.length!==t.length)return!1;for(let r=0;r<s.length;++r)if(!qs(s[r],t[r]))return!1;return!0}return s&&s.equals?s.equals(t):t&&t.equals?t.equals(s):typeof s=="number"&&typeof t=="number"?Math.abs(s-t)<=B.EPSILON*Math.max(1,Math.abs(s),Math.abs(t)):!1}finally{B.EPSILON=n}}function ei(s){return Math.round(s/B.EPSILON)*B.EPSILON}var Rt=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,e=0){for(let n=0;n<this.ELEMENTS;++n)this[n]=t[n+e];return this.check()}toArray(t=[],e=0){for(let n=0;n<this.ELEMENTS;++n)t[e+n]=this[n];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:Pt(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(B)}formatString(t){let e="";for(let n=0;n<this.ELEMENTS;++n)e+=(n>0?", ":"")+On(this[n],t);return`${t.printTypes?this.constructor.name:""}[${e}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let e=0;e<this.ELEMENTS;++e)if(!qs(this[e],t[e]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let e=0;e<this.ELEMENTS;++e)if(this[e]!==t[e])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,e,n){if(n===void 0)return this.lerp(this,t,e);for(let r=0;r<this.ELEMENTS;++r){let i=t[r],o=typeof e=="number"?e:e[r];this[r]=i+n*(o-i)}return this.check()}min(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=Math.min(t[e],this[e]);return this.check()}max(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=Math.max(t[e],this[e]);return this.check()}clamp(t,e){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t[n]),e[n]);return this.check()}add(...t){for(let e of t)for(let n=0;n<this.ELEMENTS;++n)this[n]+=e[n];return this.check()}subtract(...t){for(let e of t)for(let n=0;n<this.ELEMENTS;++n)this[n]-=e[n];return this.check()}scale(t){if(typeof t=="number")for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;else for(let e=0;e<this.ELEMENTS&&e<t.length;++e)this[e]*=t[e];return this.check()}multiplyByScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;return this.check()}check(){if(B.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let e=0;e<this.ELEMENTS;++e)t=t&&Number.isFinite(this[e]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=t;return this.check()}addScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,e){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t),e);return this.check()}get elements(){return this}};function si(s,t){if(s.length!==t)return!1;for(let e=0;e<s.length;++e)if(!Number.isFinite(s[e]))return!1;return!0}function V(s){if(!Number.isFinite(s))throw new Error(`Invalid number ${JSON.stringify(s)}`);return s}function Le(s,t,e=""){if(B.debug&&!si(s,t))throw new Error(`math.gl: ${e} some fields set to invalid numbers'`);return s}function $s(s,t){if(!s)throw new Error(`math.gl assertion ${t}`)}var Ie=class extends Rt{get x(){return this[0]}set x(t){this[0]=V(t)}get y(){return this[1]}set y(t){this[1]=V(t)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let t=0;for(let e=0;e<this.ELEMENTS;++e)t+=this[e]*this[e];return t}magnitudeSquared(){return this.lengthSquared()}distance(t){return Math.sqrt(this.distanceSquared(t))}distanceSquared(t){let e=0;for(let n=0;n<this.ELEMENTS;++n){let r=this[n]-t[n];e+=r*r}return V(e)}dot(t){let e=0;for(let n=0;n<this.ELEMENTS;++n)e+=this[n]*t[n];return V(e)}normalize(){let t=this.magnitude();if(t!==0)for(let e=0;e<this.ELEMENTS;++e)this[e]/=t;return this.check()}multiply(...t){for(let e of t)for(let n=0;n<this.ELEMENTS;++n)this[n]*=e[n];return this.check()}divide(...t){for(let e of t)for(let n=0;n<this.ELEMENTS;++n)this[n]/=e[n];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(t){return this.distance(t)}distanceToSquared(t){return this.distanceSquared(t)}getComponent(t){return $s(t>=0&&t<this.ELEMENTS,"index is out of range"),V(this[t])}setComponent(t,e){return $s(t>=0&&t<this.ELEMENTS,"index is out of range"),this[t]=e,this.check()}addVectors(t,e){return this.copy(t).add(e)}subVectors(t,e){return this.copy(t).subtract(e)}multiplyVectors(t,e){return this.copy(t).multiply(e)}addScaledVector(t,e){return this.add(new this.constructor(t).multiplyScalar(e))}};var ct=typeof Float32Array<"u"?Float32Array:Array;var Zo=Math.PI/180;function ni(){let s=new ct(2);return ct!=Float32Array&&(s[0]=0,s[1]=0),s}function Nn(s,t,e){let n=t[0],r=t[1];return s[0]=e[0]*n+e[4]*r+e[12],s[1]=e[1]*n+e[5]*r+e[13],s}var Jo=function(){let s=ni();return function(t,e,n,r,i,o){let c,h;for(e||(e=2),n||(n=0),r?h=Math.min(r*e+n,t.length):h=t.length,c=n;c<h;c+=e)s[0]=t[c],s[1]=t[c+1],i(s,s,o),t[c]=s[0],t[c+1]=s[1];return t}}();function Pn(s,t,e){let n=t[0],r=t[1],i=e[3]*n+e[7]*r||1;return s[0]=(e[0]*n+e[4]*r)/i,s[1]=(e[1]*n+e[5]*r)/i,s}function Ne(s,t,e){let n=t[0],r=t[1],i=t[2],o=e[3]*n+e[7]*r+e[11]*i||1;return s[0]=(e[0]*n+e[4]*r+e[8]*i)/o,s[1]=(e[1]*n+e[5]*r+e[9]*i)/o,s[2]=(e[2]*n+e[6]*r+e[10]*i)/o,s}function Rn(s,t,e){let n=t[0],r=t[1];return s[0]=e[0]*n+e[2]*r,s[1]=e[1]*n+e[3]*r,s[2]=t[2],s}function ri(){let s=new ct(3);return ct!=Float32Array&&(s[0]=0,s[1]=0,s[2]=0),s}function ii(s,t){return s[0]*t[0]+s[1]*t[1]+s[2]*t[2]}function zn(s,t,e){let n=t[0],r=t[1],i=t[2],o=e[0],c=e[1],h=e[2];return s[0]=r*h-i*c,s[1]=i*o-n*h,s[2]=n*c-r*o,s}function Pe(s,t,e){let n=t[0],r=t[1],i=t[2],o=e[3]*n+e[7]*r+e[11]*i+e[15];return o=o||1,s[0]=(e[0]*n+e[4]*r+e[8]*i+e[12])/o,s[1]=(e[1]*n+e[5]*r+e[9]*i+e[13])/o,s[2]=(e[2]*n+e[6]*r+e[10]*i+e[14])/o,s}function Cn(s,t,e){let n=t[0],r=t[1],i=t[2];return s[0]=n*e[0]+r*e[3]+i*e[6],s[1]=n*e[1]+r*e[4]+i*e[7],s[2]=n*e[2]+r*e[5]+i*e[8],s}function Fn(s,t,e){let n=e[0],r=e[1],i=e[2],o=e[3],c=t[0],h=t[1],f=t[2],m=r*f-i*h,p=i*c-n*f,_=n*h-r*c,y=r*_-i*p,S=i*m-n*_,g=n*p-r*m,w=o*2;return m*=w,p*=w,_*=w,y*=2,S*=2,g*=2,s[0]=c+m+y,s[1]=h+p+S,s[2]=f+_+g,s}function Dn(s,t,e,n){let r=[],i=[];return r[0]=t[0]-e[0],r[1]=t[1]-e[1],r[2]=t[2]-e[2],i[0]=r[0],i[1]=r[1]*Math.cos(n)-r[2]*Math.sin(n),i[2]=r[1]*Math.sin(n)+r[2]*Math.cos(n),s[0]=i[0]+e[0],s[1]=i[1]+e[1],s[2]=i[2]+e[2],s}function Un(s,t,e,n){let r=[],i=[];return r[0]=t[0]-e[0],r[1]=t[1]-e[1],r[2]=t[2]-e[2],i[0]=r[2]*Math.sin(n)+r[0]*Math.cos(n),i[1]=r[1],i[2]=r[2]*Math.cos(n)-r[0]*Math.sin(n),s[0]=i[0]+e[0],s[1]=i[1]+e[1],s[2]=i[2]+e[2],s}function qn(s,t,e,n){let r=[],i=[];return r[0]=t[0]-e[0],r[1]=t[1]-e[1],r[2]=t[2]-e[2],i[0]=r[0]*Math.cos(n)-r[1]*Math.sin(n),i[1]=r[0]*Math.sin(n)+r[1]*Math.cos(n),i[2]=r[2],s[0]=i[0]+e[0],s[1]=i[1]+e[1],s[2]=i[2]+e[2],s}function $n(s,t){let e=s[0],n=s[1],r=s[2],i=t[0],o=t[1],c=t[2],h=Math.sqrt((e*e+n*n+r*r)*(i*i+o*o+c*c)),f=h&&ii(s,t)/h;return Math.acos(Math.min(Math.max(f,-1),1))}var ea=function(){let s=ri();return function(t,e,n,r,i,o){let c,h;for(e||(e=3),n||(n=0),r?h=Math.min(r*e+n,t.length):h=t.length,c=n;c<h;c+=e)s[0]=t[c],s[1]=t[c+1],s[2]=t[c+2],i(s,s,o),t[c]=s[0],t[c+1]=s[1],t[c+2]=s[2];return t}}();var Vs=[0,0,0],Re,G=class extends Ie{static get ZERO(){return Re||(Re=new G(0,0,0),Object.freeze(Re)),Re}constructor(t=0,e=0,n=0){super(-0,-0,-0),arguments.length===1&&Pt(t)?this.copy(t):(B.debug&&(V(t),V(e),V(n)),this[0]=t,this[1]=e,this[2]=n)}set(t,e,n){return this[0]=t,this[1]=e,this[2]=n,this.check()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this.check()}fromObject(t){return B.debug&&(V(t.x),V(t.y),V(t.z)),this[0]=t.x,this[1]=t.y,this[2]=t.z,this.check()}toObject(t){return t.x=this[0],t.y=this[1],t.z=this[2],t}get ELEMENTS(){return 3}get z(){return this[2]}set z(t){this[2]=V(t)}angle(t){return $n(this,t)}cross(t){return zn(this,this,t),this.check()}rotateX({radians:t,origin:e=Vs}){return Dn(this,this,e,t),this.check()}rotateY({radians:t,origin:e=Vs}){return Un(this,this,e,t),this.check()}rotateZ({radians:t,origin:e=Vs}){return qn(this,this,e,t),this.check()}transform(t){return this.transformAsPoint(t)}transformAsPoint(t){return Pe(this,this,t),this.check()}transformAsVector(t){return Ne(this,this,t),this.check()}transformByMatrix3(t){return Cn(this,this,t),this.check()}transformByMatrix2(t){return Rn(this,this,t),this.check()}transformByQuaternion(t){return Fn(this,this,t),this.check()}};var ze=class extends Rt{toString(){let t="[";if(B.printRowMajor){t+="row-major:";for(let e=0;e<this.RANK;++e)for(let n=0;n<this.RANK;++n)t+=` ${this[n*this.RANK+e]}`}else{t+="column-major:";for(let e=0;e<this.ELEMENTS;++e)t+=` ${this[e]}`}return t+="]",t}getElementIndex(t,e){return e*this.RANK+t}getElement(t,e){return this[e*this.RANK+t]}setElement(t,e,n){return this[e*this.RANK+t]=V(n),this}getColumn(t,e=new Array(this.RANK).fill(-0)){let n=t*this.RANK;for(let r=0;r<this.RANK;++r)e[r]=this[n+r];return e}setColumn(t,e){let n=t*this.RANK;for(let r=0;r<this.RANK;++r)this[n+r]=e[r];return this}};function oi(s){return s[0]=1,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=1,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s}function Bn(s,t){if(s===t){let e=t[1],n=t[2],r=t[3],i=t[6],o=t[7],c=t[11];s[1]=t[4],s[2]=t[8],s[3]=t[12],s[4]=e,s[6]=t[9],s[7]=t[13],s[8]=n,s[9]=i,s[11]=t[14],s[12]=r,s[13]=o,s[14]=c}else s[0]=t[0],s[1]=t[4],s[2]=t[8],s[3]=t[12],s[4]=t[1],s[5]=t[5],s[6]=t[9],s[7]=t[13],s[8]=t[2],s[9]=t[6],s[10]=t[10],s[11]=t[14],s[12]=t[3],s[13]=t[7],s[14]=t[11],s[15]=t[15];return s}function Vn(s,t){let e=t[0],n=t[1],r=t[2],i=t[3],o=t[4],c=t[5],h=t[6],f=t[7],m=t[8],p=t[9],_=t[10],y=t[11],S=t[12],g=t[13],w=t[14],M=t[15],b=e*c-n*o,x=e*h-r*o,k=e*f-i*o,v=n*h-r*c,A=n*f-i*c,T=r*f-i*h,R=m*g-p*S,O=m*w-_*S,N=m*M-y*S,E=p*w-_*g,I=p*M-y*g,P=_*M-y*w,L=b*P-x*I+k*E+v*N-A*O+T*R;return L?(L=1/L,s[0]=(c*P-h*I+f*E)*L,s[1]=(r*I-n*P-i*E)*L,s[2]=(g*T-w*A+M*v)*L,s[3]=(_*A-p*T-y*v)*L,s[4]=(h*N-o*P-f*O)*L,s[5]=(e*P-r*N+i*O)*L,s[6]=(w*k-S*T-M*x)*L,s[7]=(m*T-_*k+y*x)*L,s[8]=(o*I-c*N+f*R)*L,s[9]=(n*N-e*I-i*R)*L,s[10]=(S*A-g*k+M*b)*L,s[11]=(p*k-m*A-y*b)*L,s[12]=(c*O-o*E-h*R)*L,s[13]=(e*E-n*O+r*R)*L,s[14]=(g*x-S*v-w*b)*L,s[15]=(m*v-p*x+_*b)*L,s):null}function jn(s){let t=s[0],e=s[1],n=s[2],r=s[3],i=s[4],o=s[5],c=s[6],h=s[7],f=s[8],m=s[9],p=s[10],_=s[11],y=s[12],S=s[13],g=s[14],w=s[15],M=t*o-e*i,b=t*c-n*i,x=e*c-n*o,k=f*S-m*y,v=f*g-p*y,A=m*g-p*S,T=t*A-e*v+n*k,R=i*A-o*v+c*k,O=f*x-m*b+p*M,N=y*x-S*b+g*M;return h*T-r*R+w*O-_*N}function js(s,t,e){let n=t[0],r=t[1],i=t[2],o=t[3],c=t[4],h=t[5],f=t[6],m=t[7],p=t[8],_=t[9],y=t[10],S=t[11],g=t[12],w=t[13],M=t[14],b=t[15],x=e[0],k=e[1],v=e[2],A=e[3];return s[0]=x*n+k*c+v*p+A*g,s[1]=x*r+k*h+v*_+A*w,s[2]=x*i+k*f+v*y+A*M,s[3]=x*o+k*m+v*S+A*b,x=e[4],k=e[5],v=e[6],A=e[7],s[4]=x*n+k*c+v*p+A*g,s[5]=x*r+k*h+v*_+A*w,s[6]=x*i+k*f+v*y+A*M,s[7]=x*o+k*m+v*S+A*b,x=e[8],k=e[9],v=e[10],A=e[11],s[8]=x*n+k*c+v*p+A*g,s[9]=x*r+k*h+v*_+A*w,s[10]=x*i+k*f+v*y+A*M,s[11]=x*o+k*m+v*S+A*b,x=e[12],k=e[13],v=e[14],A=e[15],s[12]=x*n+k*c+v*p+A*g,s[13]=x*r+k*h+v*_+A*w,s[14]=x*i+k*f+v*y+A*M,s[15]=x*o+k*m+v*S+A*b,s}function Gn(s,t,e){let n=e[0],r=e[1],i=e[2],o,c,h,f,m,p,_,y,S,g,w,M;return t===s?(s[12]=t[0]*n+t[4]*r+t[8]*i+t[12],s[13]=t[1]*n+t[5]*r+t[9]*i+t[13],s[14]=t[2]*n+t[6]*r+t[10]*i+t[14],s[15]=t[3]*n+t[7]*r+t[11]*i+t[15]):(o=t[0],c=t[1],h=t[2],f=t[3],m=t[4],p=t[5],_=t[6],y=t[7],S=t[8],g=t[9],w=t[10],M=t[11],s[0]=o,s[1]=c,s[2]=h,s[3]=f,s[4]=m,s[5]=p,s[6]=_,s[7]=y,s[8]=S,s[9]=g,s[10]=w,s[11]=M,s[12]=o*n+m*r+S*i+t[12],s[13]=c*n+p*r+g*i+t[13],s[14]=h*n+_*r+w*i+t[14],s[15]=f*n+y*r+M*i+t[15]),s}function Wn(s,t,e){let n=e[0],r=e[1],i=e[2];return s[0]=t[0]*n,s[1]=t[1]*n,s[2]=t[2]*n,s[3]=t[3]*n,s[4]=t[4]*r,s[5]=t[5]*r,s[6]=t[6]*r,s[7]=t[7]*r,s[8]=t[8]*i,s[9]=t[9]*i,s[10]=t[10]*i,s[11]=t[11]*i,s[12]=t[12],s[13]=t[13],s[14]=t[14],s[15]=t[15],s}function Hn(s,t,e,n){let r=n[0],i=n[1],o=n[2],c=Math.sqrt(r*r+i*i+o*o),h,f,m,p,_,y,S,g,w,M,b,x,k,v,A,T,R,O,N,E,I,P,L,$;return c<1e-6?null:(c=1/c,r*=c,i*=c,o*=c,f=Math.sin(e),h=Math.cos(e),m=1-h,p=t[0],_=t[1],y=t[2],S=t[3],g=t[4],w=t[5],M=t[6],b=t[7],x=t[8],k=t[9],v=t[10],A=t[11],T=r*r*m+h,R=i*r*m+o*f,O=o*r*m-i*f,N=r*i*m-o*f,E=i*i*m+h,I=o*i*m+r*f,P=r*o*m+i*f,L=i*o*m-r*f,$=o*o*m+h,s[0]=p*T+g*R+x*O,s[1]=_*T+w*R+k*O,s[2]=y*T+M*R+v*O,s[3]=S*T+b*R+A*O,s[4]=p*N+g*E+x*I,s[5]=_*N+w*E+k*I,s[6]=y*N+M*E+v*I,s[7]=S*N+b*E+A*I,s[8]=p*P+g*L+x*$,s[9]=_*P+w*L+k*$,s[10]=y*P+M*L+v*$,s[11]=S*P+b*L+A*$,t!==s&&(s[12]=t[12],s[13]=t[13],s[14]=t[14],s[15]=t[15]),s)}function Yn(s,t,e){let n=Math.sin(e),r=Math.cos(e),i=t[4],o=t[5],c=t[6],h=t[7],f=t[8],m=t[9],p=t[10],_=t[11];return t!==s&&(s[0]=t[0],s[1]=t[1],s[2]=t[2],s[3]=t[3],s[12]=t[12],s[13]=t[13],s[14]=t[14],s[15]=t[15]),s[4]=i*r+f*n,s[5]=o*r+m*n,s[6]=c*r+p*n,s[7]=h*r+_*n,s[8]=f*r-i*n,s[9]=m*r-o*n,s[10]=p*r-c*n,s[11]=_*r-h*n,s}function Xn(s,t,e){let n=Math.sin(e),r=Math.cos(e),i=t[0],o=t[1],c=t[2],h=t[3],f=t[8],m=t[9],p=t[10],_=t[11];return t!==s&&(s[4]=t[4],s[5]=t[5],s[6]=t[6],s[7]=t[7],s[12]=t[12],s[13]=t[13],s[14]=t[14],s[15]=t[15]),s[0]=i*r-f*n,s[1]=o*r-m*n,s[2]=c*r-p*n,s[3]=h*r-_*n,s[8]=i*n+f*r,s[9]=o*n+m*r,s[10]=c*n+p*r,s[11]=h*n+_*r,s}function Kn(s,t,e){let n=Math.sin(e),r=Math.cos(e),i=t[0],o=t[1],c=t[2],h=t[3],f=t[4],m=t[5],p=t[6],_=t[7];return t!==s&&(s[8]=t[8],s[9]=t[9],s[10]=t[10],s[11]=t[11],s[12]=t[12],s[13]=t[13],s[14]=t[14],s[15]=t[15]),s[0]=i*r+f*n,s[1]=o*r+m*n,s[2]=c*r+p*n,s[3]=h*r+_*n,s[4]=f*r-i*n,s[5]=m*r-o*n,s[6]=p*r-c*n,s[7]=_*r-h*n,s}function Zn(s,t){let e=t[0],n=t[1],r=t[2],i=t[3],o=e+e,c=n+n,h=r+r,f=e*o,m=n*o,p=n*c,_=r*o,y=r*c,S=r*h,g=i*o,w=i*c,M=i*h;return s[0]=1-p-S,s[1]=m+M,s[2]=_-w,s[3]=0,s[4]=m-M,s[5]=1-f-S,s[6]=y+g,s[7]=0,s[8]=_+w,s[9]=y-g,s[10]=1-f-p,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s}function Jn(s,t,e,n,r,i,o){let c=1/(e-t),h=1/(r-n),f=1/(i-o);return s[0]=i*2*c,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=i*2*h,s[6]=0,s[7]=0,s[8]=(e+t)*c,s[9]=(r+n)*h,s[10]=(o+i)*f,s[11]=-1,s[12]=0,s[13]=0,s[14]=o*i*2*f,s[15]=0,s}function ai(s,t,e,n,r){let i=1/Math.tan(t/2);if(s[0]=i/e,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=i,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[11]=-1,s[12]=0,s[13]=0,s[15]=0,r!=null&&r!==1/0){let o=1/(n-r);s[10]=(r+n)*o,s[14]=2*r*n*o}else s[10]=-1,s[14]=-2*n;return s}var Qn=ai;function ci(s,t,e,n,r,i,o){let c=1/(t-e),h=1/(n-r),f=1/(i-o);return s[0]=-2*c,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=-2*h,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=2*f,s[11]=0,s[12]=(t+e)*c,s[13]=(r+n)*h,s[14]=(o+i)*f,s[15]=1,s}var tr=ci;function er(s,t,e,n){let r,i,o,c,h,f,m,p,_,y,S=t[0],g=t[1],w=t[2],M=n[0],b=n[1],x=n[2],k=e[0],v=e[1],A=e[2];return Math.abs(S-k)<1e-6&&Math.abs(g-v)<1e-6&&Math.abs(w-A)<1e-6?oi(s):(p=S-k,_=g-v,y=w-A,r=1/Math.sqrt(p*p+_*_+y*y),p*=r,_*=r,y*=r,i=b*y-x*_,o=x*p-M*y,c=M*_-b*p,r=Math.sqrt(i*i+o*o+c*c),r?(r=1/r,i*=r,o*=r,c*=r):(i=0,o=0,c=0),h=_*c-y*o,f=y*i-p*c,m=p*o-_*i,r=Math.sqrt(h*h+f*f+m*m),r?(r=1/r,h*=r,f*=r,m*=r):(h=0,f=0,m=0),s[0]=i,s[1]=h,s[2]=p,s[3]=0,s[4]=o,s[5]=f,s[6]=_,s[7]=0,s[8]=c,s[9]=m,s[10]=y,s[11]=0,s[12]=-(i*S+o*g+c*w),s[13]=-(h*S+f*g+m*w),s[14]=-(p*S+_*g+y*w),s[15]=1,s)}function hi(){let s=new ct(4);return ct!=Float32Array&&(s[0]=0,s[1]=0,s[2]=0,s[3]=0),s}function sr(s,t,e){let n=t[0],r=t[1],i=t[2],o=t[3];return s[0]=e[0]*n+e[4]*r+e[8]*i+e[12]*o,s[1]=e[1]*n+e[5]*r+e[9]*i+e[13]*o,s[2]=e[2]*n+e[6]*r+e[10]*i+e[14]*o,s[3]=e[3]*n+e[7]*r+e[11]*i+e[15]*o,s}var ma=function(){let s=hi();return function(t,e,n,r,i,o){let c,h;for(e||(e=4),n||(n=0),r?h=Math.min(r*e+n,t.length):h=t.length,c=n;c<h;c+=e)s[0]=t[c],s[1]=t[c+1],s[2]=t[c+2],s[3]=t[c+3],i(s,s,o),t[c]=s[0],t[c+1]=s[1],t[c+2]=s[2],t[c+3]=s[3];return t}}();var Hs;(function(s){s[s.COL0ROW0=0]="COL0ROW0",s[s.COL0ROW1=1]="COL0ROW1",s[s.COL0ROW2=2]="COL0ROW2",s[s.COL0ROW3=3]="COL0ROW3",s[s.COL1ROW0=4]="COL1ROW0",s[s.COL1ROW1=5]="COL1ROW1",s[s.COL1ROW2=6]="COL1ROW2",s[s.COL1ROW3=7]="COL1ROW3",s[s.COL2ROW0=8]="COL2ROW0",s[s.COL2ROW1=9]="COL2ROW1",s[s.COL2ROW2=10]="COL2ROW2",s[s.COL2ROW3=11]="COL2ROW3",s[s.COL3ROW0=12]="COL3ROW0",s[s.COL3ROW1=13]="COL3ROW1",s[s.COL3ROW2=14]="COL3ROW2",s[s.COL3ROW3=15]="COL3ROW3"})(Hs||(Hs={}));var li=45*Math.PI/180,ui=1,Gs=.1,Ws=500,fi=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),et=class extends ze{static get IDENTITY(){return mi()}static get ZERO(){return di()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Hs}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,e,n,r,i,o,c,h,f,m,p,_,y,S,g,w){return this[0]=t,this[1]=e,this[2]=n,this[3]=r,this[4]=i,this[5]=o,this[6]=c,this[7]=h,this[8]=f,this[9]=m,this[10]=p,this[11]=_,this[12]=y,this[13]=S,this[14]=g,this[15]=w,this.check()}setRowMajor(t,e,n,r,i,o,c,h,f,m,p,_,y,S,g,w){return this[0]=t,this[1]=i,this[2]=f,this[3]=y,this[4]=e,this[5]=o,this[6]=m,this[7]=S,this[8]=n,this[9]=c,this[10]=p,this[11]=g,this[12]=r,this[13]=h,this[14]=_,this[15]=w,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(fi)}fromObject(t){return this.check()}fromQuaternion(t){return Zn(this,t),this.check()}frustum(t){let{left:e,right:n,bottom:r,top:i,near:o=Gs,far:c=Ws}=t;return c===1/0?pi(this,e,n,r,i,o):Jn(this,e,n,r,i,o,c),this.check()}lookAt(t){let{eye:e,center:n=[0,0,0],up:r=[0,1,0]}=t;return er(this,e,n,r),this.check()}ortho(t){let{left:e,right:n,bottom:r,top:i,near:o=Gs,far:c=Ws}=t;return tr(this,e,n,r,i,o,c),this.check()}orthographic(t){let{fovy:e=li,aspect:n=ui,focalDistance:r=1,near:i=Gs,far:o=Ws}=t;nr(e);let c=e/2,h=r*Math.tan(c),f=h*n;return this.ortho({left:-f,right:f,bottom:-h,top:h,near:i,far:o})}perspective(t){let{fovy:e=45*Math.PI/180,aspect:n=1,near:r=.1,far:i=500}=t;return nr(e),Qn(this,e,n,r,i),this.check()}determinant(){return jn(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,e){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],e=e||[-0,-0,-0];let n=this.getScale(e),r=1/n[0],i=1/n[1],o=1/n[2];return t[0]=this[0]*r,t[1]=this[1]*i,t[2]=this[2]*o,t[3]=0,t[4]=this[4]*r,t[5]=this[5]*i,t[6]=this[6]*o,t[7]=0,t[8]=this[8]*r,t[9]=this[9]*i,t[10]=this[10]*o,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,e){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],e=e||[-0,-0,-0];let n=this.getScale(e),r=1/n[0],i=1/n[1],o=1/n[2];return t[0]=this[0]*r,t[1]=this[1]*i,t[2]=this[2]*o,t[3]=this[4]*r,t[4]=this[5]*i,t[5]=this[6]*o,t[6]=this[8]*r,t[7]=this[9]*i,t[8]=this[10]*o,t}transpose(){return Bn(this,this),this.check()}invert(){return Vn(this,this),this.check()}multiplyLeft(t){return js(this,t,this),this.check()}multiplyRight(t){return js(this,this,t),this.check()}rotateX(t){return Yn(this,this,t),this.check()}rotateY(t){return Xn(this,this,t),this.check()}rotateZ(t){return Kn(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,e){return Hn(this,this,t,e),this.check()}scale(t){return Wn(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return Gn(this,this,t),this.check()}transform(t,e){return t.length===4?(e=sr(e||[-0,-0,-0,-0],t,this),Le(e,4),e):this.transformAsPoint(t,e)}transformAsPoint(t,e){let{length:n}=t,r;switch(n){case 2:r=Nn(e||[-0,-0],t,this);break;case 3:r=Pe(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Le(r,t.length),r}transformAsVector(t,e){let n;switch(t.length){case 2:n=Pn(e||[-0,-0],t,this);break;case 3:n=Ne(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Le(n,t.length),n}transformPoint(t,e){return this.transformAsPoint(t,e)}transformVector(t,e){return this.transformAsPoint(t,e)}transformDirection(t,e){return this.transformAsVector(t,e)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,e,n){return this.identity().translate([t,e,n])}},Ce,Fe;function di(){return Ce||(Ce=new et([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Ce)),Ce}function mi(){return Fe||(Fe=new et,Object.freeze(Fe)),Fe}function nr(s){if(s>Math.PI*2)throw Error("expected radians")}function pi(s,t,e,n,r,i){let o=2*i/(e-t),c=2*i/(r-n),h=(e+t)/(e-t),f=(r+n)/(r-n),m=-1,p=-1,_=-2*i;return s[0]=o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=c,s[6]=0,s[7]=0,s[8]=h,s[9]=f,s[10]=m,s[11]=p,s[12]=0,s[13]=0,s[14]=_,s[15]=0,s}var ht=C(z(),1),Ct=class{id;userData={};topology;bufferLayout=[];vertexCount;indices;attributes;constructor(t){this.id=t.id||(0,ht.uid)("geometry"),this.topology=t.topology,this.indices=t.indices||null,this.attributes=t.attributes,this.vertexCount=t.vertexCount,this.bufferLayout=t.bufferLayout||[],this.indices&&(0,ht.assert)(this.indices.usage===ht.Buffer.INDEX)}destroy(){this.indices?.destroy();for(let t of Object.values(this.attributes))t.destroy()}getVertexCount(){return this.vertexCount}getAttributes(){return this.attributes}getIndexes(){return this.indices}_calculateVertexCount(t){return t.byteLength/12}};function rr(s,t){if(t instanceof Ct)return t;let e=_i(s,t),{attributes:n,bufferLayout:r}=gi(s,t);return new Ct({topology:t.topology||"triangle-list",bufferLayout:r,vertexCount:t.vertexCount,indices:e,attributes:n})}function _i(s,t){if(!t.indices)return;let e=t.indices.value;return s.createBuffer({usage:ht.Buffer.INDEX,data:e})}function gi(s,t){let e=[],n={};for(let[i,o]of Object.entries(t.attributes)){let c=i;switch(i){case"POSITION":c="positions";break;case"NORMAL":c="normals";break;case"TEXCOORD_0":c="texCoords";break;case"COLOR_0":c="colors";break}n[c]=s.createBuffer({data:o.value,id:`${i}-buffer`});let{value:h,size:f,normalized:m}=o;e.push({name:c,format:(0,ht.getVertexFormatFromAttribute)(h,f,m)})}let r=t._calculateVertexCount(t.attributes,t.indices);return{attributes:n,bufferLayout:e,vertexCount:r}}var te=C(z(),1);var xt=class{modules;moduleUniforms;moduleBindings;moduleUniformsChanged;constructor(t){let e=kt(Object.values(t).filter(n=>n.dependencies));for(let n of e)t[n.name]=n;te.log.log(1,"Creating ShaderInputs with modules",Object.keys(t))(),this.modules=t,this.moduleUniforms={},this.moduleBindings={};for(let[n,r]of Object.entries(t)){let i=n;this.moduleUniforms[i]=r.defaultUniforms||{},this.moduleBindings[i]={}}}destroy(){}setProps(t){for(let e of Object.keys(t)){let n=e,r=t[n],i=this.modules[n];if(!i){te.log.warn(`Module ${e} not found`)();continue}let o=this.moduleUniforms[n],c=this.moduleBindings[n],h=i.getUniforms?.(r,this.moduleUniforms[n])||r,{uniforms:f,bindings:m}=(0,te.splitUniformsAndBindings)(h);this.moduleUniforms[n]={...o,...f},this.moduleBindings[n]={...c,...m}}}getModules(){return Object.values(this.modules)}getUniformValues(){return this.moduleUniforms}getBindings(){let t={};for(let e of Object.values(this.moduleBindings))Object.assign(t,e);return t}getDebugTable(){let t={};for(let[e,n]of Object.entries(this.moduleUniforms))for(let[r,i]of Object.entries(n))t[`${e}.${r}`]={type:this.modules[e].uniformTypes?.[r],value:String(i)};return t}};var Ft=C(z(),1);var Ys=class{device;_hashCounter=0;_hashes={};_renderPipelineCache={};_computePipelineCache={};static getDefaultPipelineFactory(t){return t._lumaData.defaultPipelineFactory=t._lumaData.defaultPipelineFactory||new Ys(t),t._lumaData.defaultPipelineFactory}constructor(t){this.device=t}createRenderPipeline(t){let e={...Ft.RenderPipeline.defaultProps,...t},n=this._hashRenderPipeline(e);if(!this._renderPipelineCache[n]){let r=this.device.createRenderPipeline({...e,id:e.id?`${e.id}-cached`:void 0});r.hash=n,this._renderPipelineCache[n]={pipeline:r,useCount:0}}return this._renderPipelineCache[n].useCount++,this._renderPipelineCache[n].pipeline}createComputePipeline(t){let e={...Ft.ComputePipeline.defaultProps,...t},n=this._hashComputePipeline(e);if(!this._computePipelineCache[n]){let r=this.device.createComputePipeline({...e,id:e.id?`${e.id}-cached`:void 0});r.hash=n,this._computePipelineCache[n]={pipeline:r,useCount:0}}return this._computePipelineCache[n].useCount++,this._computePipelineCache[n].pipeline}release(t){let e=t.hash,n=t instanceof Ft.ComputePipeline?this._computePipelineCache:this._renderPipelineCache;n[e].useCount--,n[e].useCount===0&&(n[e].pipeline.destroy(),delete n[e])}_hashComputePipeline(t){return`${this._getHash(t.shader.source)}`}_hashRenderPipeline(t){let e=this._getHash(t.vs.source),n=t.fs?this._getHash(t.fs.source):0,r="-",i=this._getHash(JSON.stringify(t.bufferLayout));switch(this.device.type){case"webgl":return`${e}/${n}V${r}BL${i}`;default:let o=this._getHash(JSON.stringify(t.parameters));return`${e}/${n}V${r}T${t.topology}P${o}BL${i}`}}_getHash(t){return this._hashes[t]===void 0&&(this._hashes[t]=this._hashCounter++),this._hashes[t]}},lt=Ys;st(lt,"defaultProps",{...Ft.RenderPipeline.defaultProps});var ir=C(z(),1);var Xs=class{device;_cache={};static getDefaultShaderFactory(t){return t._lumaData.defaultShaderFactory||=new Xs(t),t._lumaData.defaultShaderFactory}constructor(t){this.device=t}createShader(t){let e=this._hashShader(t),n=this._cache[e];if(!n){let r=this.device.createShader({...t,id:t.id?`${t.id}-cached`:void 0});this._cache[e]=n={shader:r,useCount:0}}return n.useCount++,n.shader}release(t){let e=this._hashShader(t),n=this._cache[e];n&&(n.useCount--,n.useCount===0&&(delete this._cache[e],n.shader.destroy()))}_hashShader(t){return`${t.stage}:${t.source}`}},ut=Xs;st(ut,"defaultProps",{...ir.Shader.defaultProps});function or(s,t){let e={},n="Values";if(s.attributes.length===0&&!s.varyings?.length)return{"No attributes or varyings":{[n]:"N/A"}};for(let r of s.attributes)if(r){let i=`${r.location} ${r.name}: ${r.type}`;e[`in ${i}`]={[n]:r.stepMode||"vertex"}}for(let r of s.varyings||[]){let i=`${r.location} ${r.name}`;e[`out ${i}`]={[n]:JSON.stringify(r.accessor)}}return e}var q=null,Ks=null;function ar(s,{id:t,minimap:e,opaque:n,top:r="0",left:i="0",rgbaScale:o=1}){q||(q=document.createElement("canvas"),q.id=t,q.title=t,q.style.zIndex="100",q.style.position="absolute",q.style.top=r,q.style.left=i,q.style.border="blue 1px solid",q.style.transform="scaleY(-1)",document.body.appendChild(q),Ks=q.getContext("2d")),(q.width!==s.width||q.height!==s.height)&&(q.width=s.width/2,q.height=s.height/2,q.style.width="400px",q.style.height="400px");let c=s.device.readPixelsToArrayWebGL(s),h=Ks.createImageData(s.width,s.height),f=0;for(let m=0;m<c.length;m+=4)h.data[f+m+0]=c[m+0]*o,h.data[f+m+1]=c[m+1]*o,h.data[f+m+2]=c[m+2]*o,h.data[f+m+3]=n?255:c[m+3]*o;Ks.putImageData(h,0,0)}var Dt=2,xi=1e4,Zs=class{device;id;source;vs;fs;pipelineFactory;shaderFactory;userData={};parameters;topology;bufferLayout;isInstanced=void 0;instanceCount=0;vertexCount;indexBuffer=null;bufferAttributes={};constantAttributes={};bindings={};uniforms={};vertexArray;transformFeedback=null;pipeline;shaderInputs;_uniformStore;_attributeInfos={};_gpuGeometry=null;_getModuleUniforms;props;_pipelineNeedsUpdate="newly created";_needsRedraw="initializing";_destroyed=!1;_lastDrawTimestamp=-1;constructor(t,e){this.props={...Zs.defaultProps,...e},e=this.props,this.id=e.id||(0,D.uid)("model"),this.device=t,Object.assign(this.userData,e.userData);let n=Object.fromEntries(this.props.modules?.map(c=>[c.name,c])||[]);this.setShaderInputs(e.shaderInputs||new xt(n));let r=yi(t),i=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];if(this.device.type==="webgpu"&&this.props.source){this.props.shaderLayout||=Qt(this.props.source);let{source:c,getUniforms:h}=this.props.shaderAssembler.assembleShader({platformInfo:r,...this.props,modules:i});this.source=c,this._getModuleUniforms=h}else{let{vs:c,fs:h,getUniforms:f}=this.props.shaderAssembler.assembleShaderPair({platformInfo:r,...this.props,modules:i});this.vs=c,this.fs=h,this._getModuleUniforms=f}this.vertexCount=this.props.vertexCount,this.instanceCount=this.props.instanceCount,this.topology=this.props.topology,this.bufferLayout=this.props.bufferLayout,this.parameters=this.props.parameters,e.geometry&&this.setGeometry(e.geometry),this.pipelineFactory=e.pipelineFactory||lt.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||ut.getDefaultShaderFactory(this.device),this.pipeline=this._updatePipeline(),this.vertexArray=t.createVertexArray({renderPipeline:this.pipeline}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry),"isInstanced"in e&&(this.isInstanced=e.isInstanced),e.instanceCount&&this.setInstanceCount(e.instanceCount),e.vertexCount&&this.setVertexCount(e.vertexCount),e.indexBuffer&&this.setIndexBuffer(e.indexBuffer),e.attributes&&this.setAttributes(e.attributes),e.constantAttributes&&this.setConstantAttributes(e.constantAttributes),e.bindings&&this.setBindings(e.bindings),e.uniforms&&this.setUniforms(e.uniforms),e.moduleSettings&&this.updateModuleSettings(e.moduleSettings),e.transformFeedback&&(this.transformFeedback=e.transformFeedback),Object.seal(this)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.pipeline.vs),this.pipeline.fs&&this.shaderFactory.release(this.pipeline.fs),this._uniformStore.destroy(),this._gpuGeometry?.destroy(),this._destroyed=!0)}needsRedraw(){this._getBindingsUpdateTimestamp()>this._lastDrawTimestamp&&this.setNeedsRedraw("contents of bound textures or buffers updated");let t=this._needsRedraw;return this._needsRedraw=!1,t}setNeedsRedraw(t){this._needsRedraw||=t}predraw(){this.updateShaderInputs(),this.pipeline=this._updatePipeline()}draw(t){this.predraw();let e;try{this._logDrawCallStart(),this.pipeline=this._updatePipeline(),this.pipeline.setBindings(this.bindings,{disableWarnings:this.props.disableWarnings}),(0,D.isObjectEmpty)(this.uniforms)||this.pipeline.setUniformsWebGL(this.uniforms);let{indexBuffer:n}=this.vertexArray,r=n?n.byteLength/(n.indexType==="uint32"?4:2):void 0;e=this.pipeline.draw({renderPass:t,vertexArray:this.vertexArray,isInstanced:this.isInstanced,vertexCount:this.vertexCount,instanceCount:this.instanceCount,indexCount:r,transformFeedback:this.transformFeedback||void 0,parameters:this.parameters,topology:this.topology})}finally{this._logDrawCallEnd()}return this._logFramebuffer(t),e?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):this._needsRedraw="waiting for resource initialization",e}setGeometry(t){this._gpuGeometry?.destroy();let e=t&&rr(this.device,t);e&&(this.setTopology(e.topology||"triangle-list"),this.bufferLayout=cr(e.bufferLayout,this.bufferLayout),this.vertexArray&&this._setGeometryAttributes(e)),this._gpuGeometry=e}setTopology(t){t!==this.topology&&(this.topology=t,this._setPipelineNeedsUpdate("topology"))}setBufferLayout(t){this.bufferLayout=this._gpuGeometry?cr(t,this._gpuGeometry.bufferLayout):t,this._setPipelineNeedsUpdate("bufferLayout"),this.pipeline=this._updatePipeline(),this.vertexArray=this.device.createVertexArray({renderPipeline:this.pipeline}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry)}setParameters(t){(0,D.deepEqual)(t,this.parameters,2)||(this.parameters=t,this._setPipelineNeedsUpdate("parameters"))}setInstanceCount(t){this.instanceCount=t,this.isInstanced===void 0&&t>0&&(this.isInstanced=!0),this.setNeedsRedraw("instanceCount")}setVertexCount(t){this.vertexCount=t,this.setNeedsRedraw("vertexCount")}setShaderInputs(t){this.shaderInputs=t,this._uniformStore=new De.UniformStore(this.shaderInputs.modules);for(let e of Object.keys(this.shaderInputs.modules)){let n=this._uniformStore.getManagedUniformBuffer(this.device,e);this.bindings[`${e}Uniforms`]=n}this.setNeedsRedraw("shaderInputs")}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues()),this.setBindings(this.shaderInputs.getBindings()),this.setNeedsRedraw("shaderInputs")}setBindings(t){Object.assign(this.bindings,t),this.setNeedsRedraw("bindings")}setTransformFeedback(t){this.transformFeedback=t,this.setNeedsRedraw("transformFeedback")}setIndexBuffer(t){this.vertexArray.setIndexBuffer(t),this.setNeedsRedraw("indexBuffer")}setAttributes(t,e){t.indices&&D.log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)();for(let[n,r]of Object.entries(t)){let i=this.bufferLayout.find(h=>hr(h).includes(n));if(!i){D.log.warn(`Model(${this.id}): Missing layout for buffer "${n}".`)();continue}let o=hr(i),c=!1;for(let h of o){let f=this._attributeInfos[h];f&&(this.vertexArray.setBuffer(f.location,r),c=!0)}!c&&!(e?.disableWarnings??this.props.disableWarnings)&&D.log.warn(`Model(${this.id}): Ignoring buffer "${r.id}" for unknown attribute "${n}"`)()}this.setNeedsRedraw("attributes")}setConstantAttributes(t,e){for(let[n,r]of Object.entries(t)){let i=this._attributeInfos[n];i?this.vertexArray.setConstantWebGL(i.location,r):(e?.disableWarnings??this.props.disableWarnings)||D.log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${n}"`)()}this.setNeedsRedraw("constants")}setUniforms(t){(0,D.isObjectEmpty)(t)||(this.pipeline.setUniformsWebGL(t),Object.assign(this.uniforms,t)),this.setNeedsRedraw("uniforms")}updateModuleSettings(t){let{bindings:e,uniforms:n}=(0,D.splitUniformsAndBindings)(this._getModuleUniforms(t));Object.assign(this.bindings,e),Object.assign(this.uniforms,n),this.setNeedsRedraw("moduleSettings")}_getBindingsUpdateTimestamp(){let t=0;for(let e of Object.values(this.bindings))e instanceof ft.TextureView?t=Math.max(t,e.texture.updateTimestamp):e instanceof ft.Buffer||e instanceof ft.Texture?t=Math.max(t,e.updateTimestamp):e instanceof ft.Sampler||(t=Math.max(t,e.buffer.updateTimestamp));return t}_setGeometryAttributes(t){let e={...t.attributes};for(let[n]of Object.entries(e))!this.pipeline.shaderLayout.attributes.find(r=>r.name===n)&&n!=="positions"&&delete e[n];this.vertexCount=t.vertexCount,this.setIndexBuffer(t.indices||null),this.setAttributes(t.attributes,{disableWarnings:!0}),this.setAttributes(e,{disableWarnings:this.props.disableWarnings}),this.setNeedsRedraw("geometry attributes")}_setPipelineNeedsUpdate(t){this._pipelineNeedsUpdate||=t,this.setNeedsRedraw(t)}_updatePipeline(){if(this._pipelineNeedsUpdate){let t=null,e=null;this.pipeline&&(D.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),t=this.pipeline.vs,e=this.pipeline.fs),this._pipelineNeedsUpdate=!1;let n=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:"vertex",source:this.source||this.vs,debug:this.props.debugShaders}),r=null;this.source?r=n:this.fs&&(r=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"fragment",source:this.source||this.fs,debug:this.props.debugShaders})),this.pipeline=this.pipelineFactory.createRenderPipeline({...this.props,bufferLayout:this.bufferLayout,topology:this.topology,parameters:this.parameters,vs:n,fs:r}),this._attributeInfos=(0,Ue.getAttributeInfosFromLayouts)(this.pipeline.shaderLayout,this.bufferLayout),t&&this.shaderFactory.release(t),e&&this.shaderFactory.release(e)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let t=D.log.level>3?0:xi;D.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,D.log.group(Dt,`>>> DRAWING MODEL ${this.id}`,{collapsed:D.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=or(this.pipeline.shaderLayout,this.id);D.log.table(Dt,t)();let e=this.shaderInputs.getDebugTable();for(let[r,i]of Object.entries(this.uniforms))e[r]={value:i};D.log.table(Dt,e)();let n=this._getAttributeDebugTable();D.log.table(Dt,this._attributeInfos)(),D.log.table(Dt,n)(),D.log.groupEnd(Dt)(),this._logOpen=!1}}_drawCount=0;_logFramebuffer(t){let e=D.log.get("framebuffer");if(this._drawCount++,!e||this._drawCount++>3&&this._drawCount%60)return;let n=t.props.framebuffer;n&&ar(n,{id:n.id,minimap:!0})}_getAttributeDebugTable(){let t={};for(let[e,n]of Object.entries(this._attributeInfos))t[n.location]={name:e,type:n.shaderType,values:this._getBufferOrConstantValues(this.vertexArray.attributes[n.location],n.bufferDataType)};if(this.vertexArray.indexBuffer){let{indexBuffer:e}=this.vertexArray,n=e.indexType==="uint32"?new Uint32Array(e.debugData):new Uint16Array(e.debugData);t.indices={name:"indices",type:e.indexType,values:n.toString()}}return t}_getBufferOrConstantValues(t,e){let n=(0,Ue.getTypedArrayFromDataType)(e);return(t instanceof ft.Buffer?new n(t.debugData):t).toString()}},K=Zs;st(K,"defaultProps",{...De.RenderPipeline.defaultProps,source:null,vs:null,fs:null,id:"unnamed",handle:void 0,userData:{},defines:{},modules:[],moduleSettings:void 0,geometry:null,indexBuffer:null,attributes:{},constantAttributes:{},varyings:[],isInstanced:void 0,instanceCount:0,vertexCount:0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,transformFeedback:void 0,shaderAssembler:mt.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0});function cr(s,t){let e=[...s];for(let n of t){let r=e.findIndex(i=>i.name===n.name);r<0?e.push(n):e[r]=n}return e}function yi(s){return{type:s.type,shaderLanguage:s.info.shadingLanguage,shaderLanguageVersion:s.info.shadingLanguageVersion,gpu:s.info.gpu,features:s.features}}function hr(s){return s.attributes?s.attributes?.map(t=>t.attribute):[s.name]}var qe=C(z(),1);var Ut=class{device;model;transformFeedback;static isSupported(t){return t?.info?.type==="webgl"}constructor(t,e=K.defaultProps){(0,qe.assert)(Ut.isSupported(t),"BufferTransform not yet implemented on WebGPU"),this.device=t,this.model=new K(this.device,{id:e.id||"buffer-transform-model",fs:e.fs||Ht(),topology:e.topology||"point-list",...e}),this.transformFeedback=this.device.createTransformFeedback({layout:this.model.pipeline.shaderLayout,buffers:e.feedbackBuffers}),this.model.setTransformFeedback(this.transformFeedback),Object.seal(this)}destroy(){this.model&&this.model.destroy()}delete(){this.destroy()}run(t){let e=this.device.beginRenderPass(t);this.model.draw(e),e.end()}update(...t){console.warn("TextureTransform#update() not implemented")}getBuffer(t){return this.transformFeedback.getBuffer(t)}readAsync(t){let e=this.getBuffer(t);if(e instanceof qe.Buffer)return e.readAsync();let{buffer:n,byteOffset:r=0,byteLength:i=n.byteLength}=e;return n.readAsync(r,i)}};var wi="transform_output",$e=class{device;model;sampler;currentIndex=0;samplerTextureMap=null;bindings=[];resources={};constructor(t,e){this.device=t,this.sampler=t.createSampler({addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",minFilter:"nearest",magFilter:"nearest",mipmapFilter:"nearest"}),this.model=new K(this.device,{id:e.id||"texture-transform-model",fs:e.fs||Ht({input:e.targetTextureVarying,inputChannels:e.targetTextureChannels,output:wi}),vertexCount:e.vertexCount,...e}),this._initialize(e),Object.seal(this)}destroy(){}delete(){this.destroy()}run(t){let{framebuffer:e}=this.bindings[this.currentIndex],n=this.device.beginRenderPass({framebuffer:e,...t});this.model.draw(n),n.end()}update(...t){console.warn("TextureTransform#update() not implemented")}getData({packed:t=!1}={}){throw new Error("getData() not implemented")}getTargetTexture(){let{targetTexture:t}=this.bindings[this.currentIndex];return t}getFramebuffer(){return this.bindings[this.currentIndex].framebuffer}_initialize(t){this._updateBindings(t)}_updateBindings(t){this.bindings[this.currentIndex]=this._updateBinding(this.bindings[this.currentIndex],t)}_updateBinding(t,{sourceBuffers:e,sourceTextures:n,targetTexture:r}){if(t||(t={sourceBuffers:{},sourceTextures:{},targetTexture:null}),Object.assign(t.sourceTextures,n),Object.assign(t.sourceBuffers,e),r){t.targetTexture=r;let{width:i,height:o}=r;t.framebuffer&&t.framebuffer.destroy(),t.framebuffer=this.device.createFramebuffer({id:"transform-framebuffer",width:i,height:o,colorAttachments:[r]}),t.framebuffer.resize({width:i,height:o})}return t}_setSourceTextureParameters(){let t=this.currentIndex,{sourceTextures:e}=this.bindings[t];for(let n in e)e[n].sampler=this.sampler}};var oc=C(z(),1);var qt=C(z(),1),j=class{id;topology;vertexCount;indices;attributes;userData={};constructor(t){let{attributes:e={},indices:n=null,vertexCount:r=null}=t;this.id=t.id||(0,qt.uid)("geometry"),this.topology=t.topology,n&&(this.indices=ArrayBuffer.isView(n)?{value:n,size:1}:n),this.attributes={};for(let[i,o]of Object.entries(e)){let c=ArrayBuffer.isView(o)?{value:o}:o;(0,qt.assert)(ArrayBuffer.isView(c.value),`${this._print(i)}: must be typed array or object with value as typed array`),(i==="POSITION"||i==="positions")&&!c.size&&(c.size=3),i==="indices"?((0,qt.assert)(!this.indices),this.indices=c):this.attributes[i]=c}this.indices&&this.indices.isIndexed!==void 0&&(this.indices=Object.assign({},this.indices),delete this.indices.isIndexed),this.vertexCount=r||this._calculateVertexCount(this.attributes,this.indices)}getVertexCount(){return this.vertexCount}getAttributes(){return this.indices?{indices:this.indices,...this.attributes}:this.attributes}_print(t){return`Geometry ${this.id} attribute ${t}`}_setAttributes(t,e){return this}_calculateVertexCount(t,e){if(e)return e.value.length;let n=1/0;for(let r of Object.values(t)){let{value:i,size:o,constant:c}=r;!c&&i&&o>=1&&(n=Math.min(n,i.length/o))}return(0,qt.assert)(Number.isFinite(n)),n}};var ki=`#version 300 es
88
88
  in vec2 aClipSpacePosition;
89
89
  in vec2 aTexCoord;
90
90
  in vec2 aCoordinate;
@@ -97,6 +97,6 @@ position = aClipSpacePosition;
97
97
  coordinate = aCoordinate;
98
98
  uv = aTexCoord;
99
99
  }
100
- `,rr=[-1,-1,1,-1,-1,1,1,1],Fe=class extends K{constructor(t,e){let n=rr.map(r=>r===-1?0:r);super(t,{...e,vs:_i,vertexCount:4,geometry:new G({topology:"triangle-strip",vertexCount:4,attributes:{aClipSpacePosition:{size:2,value:new Float32Array(rr)},aTexCoord:{size:2,value:new Float32Array(n)},aCoordinate:{size:2,value:new Float32Array(n)}}})})}};var kt=C(z(),1);var ft=class{id;matrix=new tt;display=!0;position=new B;rotation=new B;scale=new B(1,1,1);userData={};props={};constructor(t={}){let{id:e}=t;this.id=e||(0,kt.uid)(this.constructor.name),this._setScenegraphNodeProps(t)}getBounds(){return null}destroy(){}delete(){this.destroy()}setProps(t){return this._setScenegraphNodeProps(t),this}toString(){return`{type: ScenegraphNode, id: ${this.id})}`}setPosition(t){return(0,kt.assert)(t.length===3,"setPosition requires vector argument"),this.position=t,this}setRotation(t){return(0,kt.assert)(t.length===3,"setRotation requires vector argument"),this.rotation=t,this}setScale(t){return(0,kt.assert)(t.length===3,"setScale requires vector argument"),this.scale=t,this}setMatrix(t,e=!0){e?this.matrix.copy(t):this.matrix=t}setMatrixComponents(t){let{position:e,rotation:n,scale:r,update:i=!0}=t;return e&&this.setPosition(e),n&&this.setRotation(n),r&&this.setScale(r),i&&this.updateMatrix(),this}updateMatrix(){let t=this.position,e=this.rotation,n=this.scale;return this.matrix.identity(),this.matrix.translate(t),this.matrix.rotateXYZ(e),this.matrix.scale(n),this}update(t={}){let{position:e,rotation:n,scale:r}=t;return e&&this.setPosition(e),n&&this.setRotation(n),r&&this.setScale(r),this.updateMatrix(),this}getCoordinateUniforms(t,e){(0,kt.assert)(t),e=e||this.matrix;let n=new tt(t).multiplyRight(e),r=n.invert(),i=r.transpose();return{viewMatrix:t,modelMatrix:e,objectMatrix:e,worldMatrix:n,worldInverseMatrix:r,worldInverseTransposeMatrix:i}}_setScenegraphNodeProps(t){"display"in t&&(this.display=t.display),"position"in t&&this.setPosition(t.position),"rotation"in t&&this.setRotation(t.rotation),"scale"in t&&this.setScale(t.scale),"matrix"in t&&this.setMatrix(t.matrix),Object.assign(this.props,t)}};var ir=C(z(),1);var Ut=class extends ft{children;constructor(t={}){t=Array.isArray(t)?{children:t}:t;let{children:e=[]}=t;ir.log.assert(e.every(n=>n instanceof ft),"every child must an instance of ScenegraphNode"),super(t),this.children=e}getBounds(){let t=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]];return this.traverse((e,{worldMatrix:n})=>{let r=e.getBounds();if(!r)return;let[i,o]=r,c=new B(i).add(o).divide([2,2,2]);n.transformAsPoint(c,c);let h=new B(o).subtract(i).divide([2,2,2]);n.transformAsVector(h,h);for(let f=0;f<8;f++){let m=new B(f&1?-1:1,f&2?-1:1,f&4?-1:1).multiply(h).add(c);for(let d=0;d<3;d++)t[0][d]=Math.min(t[0][d],m[d]),t[1][d]=Math.max(t[1][d],m[d])}}),Number.isFinite(t[0][0])?t:null}destroy(){this.children.forEach(t=>t.destroy()),this.removeAll(),super.destroy()}add(...t){for(let e of t)Array.isArray(e)?this.add(...e):this.children.push(e);return this}remove(t){let e=this.children,n=e.indexOf(t);return n>-1&&e.splice(n,1),this}removeAll(){return this.children=[],this}traverse(t,{worldMatrix:e=new tt}={}){let n=new tt(e).multiplyRight(this.matrix);for(let r of this.children)r instanceof Ut?r.traverse(t,{worldMatrix:n}):t(r,{worldMatrix:n})}};var De=class extends ft{model;bounds=null;managedResources;constructor(t){super(t),this.model=t.model,this.managedResources=t.managedResources||[],this.bounds=t.bounds||null,this.setProps(t)}getBounds(){return this.bounds}destroy(){this.model&&(this.model.destroy(),this.model=null),this.managedResources.forEach(t=>t.destroy()),this.managedResources=[]}draw(t){return this.model.draw(t)}};var ar=C(z(),1);var or=C(z(),1);var gi={x:[2,0,1],y:[0,1,2],z:[1,2,0]},xt=class extends G{constructor(t={}){let{id:e=(0,or.uid)("truncated-code-geometry")}=t,{indices:n,attributes:r}=xi(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{POSITION:{size:3,value:r.POSITION},NORMAL:{size:3,value:r.NORMAL},TEXCOORD_0:{size:2,value:r.TEXCOORD_0},...t.attributes}})}};function xi(s={}){let{bottomRadius:t=0,topRadius:e=0,height:n=1,nradial:r=10,nvertical:i=10,verticalAxis:o="y",topCap:c=!1,bottomCap:h=!1}=s,f=(c?2:0)+(h?2:0),m=(r+1)*(i+1+f),d=Math.atan2(t-e,n),_=Math.sin,y=Math.cos,S=Math.PI,g=y(d),w=_(d),M=c?-2:0,k=i+(h?2:0),x=r+1,v=new Uint16Array(r*(i+f)*6),b=gi[o],E=new Float32Array(m*3),T=new Float32Array(m*3),R=new Float32Array(m*2),O=0,I=0;for(let A=M;A<=k;A++){let N=A/i,L=n*N,P;A<0?(L=0,N=1,P=t):A>i?(L=n,N=1,P=e):P=t+(e-t)*(A/i),(A===-2||A===i+2)&&(P=0,N=0),L-=n/2;for(let V=0;V<x;V++){let nt=_(V*S*2/r),J=y(V*S*2/r);E[O+b[0]]=nt*P,E[O+b[1]]=L,E[O+b[2]]=J*P,T[O+b[0]]=A<0||A>i?0:nt*g,T[O+b[1]]=A<0?-1:A>i?1:w,T[O+b[2]]=A<0||A>i?0:J*g,R[I+0]=V/r,R[I+1]=N,I+=2,O+=3}}for(let A=0;A<i+f;A++)for(let N=0;N<r;N++){let L=(A*r+N)*6;v[L+0]=x*(A+0)+0+N,v[L+1]=x*(A+0)+1+N,v[L+2]=x*(A+1)+1+N,v[L+3]=x*(A+0)+0+N,v[L+4]=x*(A+1)+1+N,v[L+5]=x*(A+1)+0+N}return{indices:v,attributes:{POSITION:E,NORMAL:T,TEXCOORD_0:R}}}var Ue=class extends xt{constructor(t={}){let{id:e=(0,ar.uid)("cone-geometry"),radius:n=1,cap:r=!0}=t;super({...t,id:e,topRadius:0,topCap:Boolean(r),bottomCap:Boolean(r),bottomRadius:n})}};var cr=C(z(),1);var qe=class extends G{constructor(t={}){let{id:e=(0,cr.uid)("cube-geometry"),indices:n=!0}=t;super(n?{...t,id:e,topology:"triangle-list",indices:{size:1,value:yi},attributes:{...Ei,...t.attributes}}:{...t,id:e,topology:"triangle-list",indices:void 0,attributes:{...Ai,...t.attributes}})}},yi=new Uint16Array([0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]),wi=new Float32Array([-1,-1,1,1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,1,1,1,1,1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1]),vi=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0]),bi=new Float32Array([0,0,1,0,1,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,0,1,1,0,1,0,0,0,0,1,0,1,1,0,1]),ki=new Float32Array([1,-1,1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,1,1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,1,-1,1,1,1,-1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1]),Mi=new Float32Array([1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,1,0,0]),Si=new Float32Array([1,0,1,1,0,0,1,1,0,0,0,1,1,0,0,1,1,0,1,1,0,0,0,1,1,1,1,1,1,0,1,1,1,0,0,1,1,1,0,1,1,1,1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,0,1,1,0,1,1,1,0,1,0,1,0,0,0,1,0,0,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0,0,1,1,0,0,1,1,1,0,1,1,1,1,1,1,1,0,0,1,0,0,0,1,0,1,0,1,1,1,0,1,1,0,0,1,0,1,0,1]),Ei={POSITION:{size:3,value:wi},NORMAL:{size:3,value:vi},TEXCOORD_0:{size:2,value:bi}},Ai={POSITION:{size:3,value:ki},TEXCOORD_0:{size:2,value:Mi},COLOR_0:{size:3,value:Si}};var hr=C(z(),1);var Ve=class extends xt{constructor(t={}){let{id:e=(0,hr.uid)("cylinder-geometry"),radius:n=1}=t;super({...t,id:e,bottomRadius:n,topRadius:n})}};var lr=C(z(),1);var Ti=[-1,0,0,0,1,0,0,0,-1,0,0,1,0,-1,0,1,0,0],Oi=[3,4,5,3,5,1,3,1,0,3,0,4,4,0,2,4,2,5,2,0,1,5,2,1],$e=class extends G{constructor(t={}){let{id:e=(0,lr.uid)("ico-sphere-geometry")}=t,{indices:n,attributes:r}=Pi(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{...r,...t.attributes}})}};function Pi(s){let{iterations:t=0}=s,e=Math.PI,n=e*2,r=[...Ti],i=[...Oi];r.push(),i.push();let o=(()=>{let m={};return(d,_)=>{d*=3,_*=3;let y=d<_?d:_,S=d>_?d:_,g=`${y}|${S}`;if(g in m)return m[g];let w=r[d],M=r[d+1],k=r[d+2],x=r[_],v=r[_+1],b=r[_+2],E=(w+x)/2,T=(M+v)/2,R=(k+b)/2,O=Math.sqrt(E*E+T*T+R*R);return E/=O,T/=O,R/=O,r.push(E,T,R),m[g]=r.length/3-1}})();for(let m=0;m<t;m++){let d=[];for(let _=0;_<i.length;_+=3){let y=o(i[_+0],i[_+1]),S=o(i[_+1],i[_+2]),g=o(i[_+2],i[_+0]);d.push(g,i[_+0],y,y,i[_+1],S,S,i[_+2],g,y,S,g)}i=d}let c=new Array(r.length),h=new Array(r.length/3*2),f=i.length;for(let m=f-3;m>=0;m-=3){let d=i[m+0],_=i[m+1],y=i[m+2],S=d*3,g=_*3,w=y*3,M=d*2,k=_*2,x=y*2,v=r[S+0],b=r[S+1],E=r[S+2],T=Math.acos(E/Math.sqrt(v*v+b*b+E*E)),R=Math.atan2(b,v)+e,O=T/e,I=1-R/n,A=r[g+0],N=r[g+1],L=r[g+2],P=Math.acos(L/Math.sqrt(A*A+N*N+L*L)),V=Math.atan2(N,A)+e,nt=P/e,J=1-V/n,Zt=r[w+0],Jt=r[w+1],Qt=r[w+2],pr=Math.acos(Qt/Math.sqrt(Zt*Zt+Jt*Jt+Qt*Qt)),_r=Math.atan2(Jt,Zt)+e,Ys=pr/e,te=1-_r/n,gr=[Zt-A,Jt-N,Qt-L],xr=[v-A,b-N,E-L],W=new B(gr).cross(xr).normalize(),U;(I===0||J===0||te===0)&&(I===0||I>.5)&&(J===0||J>.5)&&(te===0||te>.5)&&(r.push(r[S+0],r[S+1],r[S+2]),U=r.length/3-1,i.push(U),h[U*2+0]=1,h[U*2+1]=O,c[U*3+0]=W.x,c[U*3+1]=W.y,c[U*3+2]=W.z,r.push(r[g+0],r[g+1],r[g+2]),U=r.length/3-1,i.push(U),h[U*2+0]=1,h[U*2+1]=nt,c[U*3+0]=W.x,c[U*3+1]=W.y,c[U*3+2]=W.z,r.push(r[w+0],r[w+1],r[w+2]),U=r.length/3-1,i.push(U),h[U*2+0]=1,h[U*2+1]=Ys,c[U*3+0]=W.x,c[U*3+1]=W.y,c[U*3+2]=W.z),c[S+0]=c[g+0]=c[w+0]=W.x,c[S+1]=c[g+1]=c[w+1]=W.y,c[S+2]=c[g+2]=c[w+2]=W.z,h[M+0]=I,h[M+1]=O,h[k+0]=J,h[k+1]=nt,h[x+0]=te,h[x+1]=Ys}return{indices:{size:1,value:new Uint16Array(i)},attributes:{POSITION:{size:3,value:new Float32Array(r)},NORMAL:{size:3,value:new Float32Array(c)},TEXCOORD_0:{size:2,value:new Float32Array(h)}}}}var fr=C(z(),1);function ur(s){let{indices:t,attributes:e}=s;if(!t)return s;let n=t.value.length,r={};for(let i in e){let o=e[i],{constant:c,value:h,size:f}=o;if(c||!f)continue;let m=new h.constructor(n*f);for(let d=0;d<n;++d){let _=t.value[d];for(let y=0;y<f;y++)m[d*f+y]=h[_*f+y]}r[i]={size:f,value:m}}return{attributes:Object.assign({},e,r)}}var je=class extends G{constructor(t={}){let{id:e=(0,fr.uid)("plane-geometry")}=t,{indices:n,attributes:r}=Ni(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{...r,...t.attributes}})}};function Ni(s){let{type:t="x,y",offset:e=0,flipCull:n=!1,unpack:r=!1}=s,i=t.split(","),o=s[`${i[0]}len`]||1,c=s[`${i[1]}len`]||1,h=s[`n${i[0]}`]||1,f=s[`n${i[1]}`]||1,m=(h+1)*(f+1),d=new Float32Array(m*3),_=new Float32Array(m*3),y=new Float32Array(m*2);n&&(o=-o);let S=0,g=0;for(let x=0;x<=f;x++)for(let v=0;v<=h;v++){let b=v/h,E=x/f;switch(y[S+0]=n?1-b:b,y[S+1]=E,t){case"x,y":d[g+0]=o*b-o*.5,d[g+1]=c*E-c*.5,d[g+2]=e,_[g+0]=0,_[g+1]=0,_[g+2]=n?1:-1;break;case"x,z":d[g+0]=o*b-o*.5,d[g+1]=e,d[g+2]=c*E-c*.5,_[g+0]=0,_[g+1]=n?1:-1,_[g+2]=0;break;case"y,z":d[g+0]=e,d[g+1]=o*b-o*.5,d[g+2]=c*E-c*.5,_[g+0]=n?1:-1,_[g+1]=0,_[g+2]=0;break;default:throw new Error("PlaneGeometry: unknown type")}S+=2,g+=3}let w=h+1,M=new Uint16Array(h*f*6);for(let x=0;x<f;x++)for(let v=0;v<h;v++){let b=(x*h+v)*6;M[b+0]=(x+0)*w+v,M[b+1]=(x+1)*w+v,M[b+2]=(x+0)*w+v+1,M[b+3]=(x+1)*w+v,M[b+4]=(x+1)*w+v+1,M[b+5]=(x+0)*w+v+1}let k={indices:{size:1,value:M},attributes:{POSITION:{size:3,value:d},NORMAL:{size:3,value:_},TEXCOORD_0:{size:2,value:y}}};return r?ur(k):k}var dr=C(z(),1);var Ge=class extends G{constructor(t={}){let{id:e=(0,dr.uid)("sphere-geometry")}=t,{indices:n,attributes:r}=Ii(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{...r,...t.attributes}})}};function Ii(s){let{nlat:t=10,nlong:e=10}=s,i=Math.PI-0,o=0,h=2*Math.PI-o,f=(t+1)*(e+1),m=(M,k,x,v,b)=>s.radius||1,d=new Float32Array(f*3),_=new Float32Array(f*3),y=new Float32Array(f*2),S=f>65535?Uint32Array:Uint16Array,g=new S(t*e*6);for(let M=0;M<=t;M++)for(let k=0;k<=e;k++){let x=k/e,v=M/t,b=k+M*(e+1),E=b*2,T=b*3,R=h*x,O=i*v,I=Math.sin(R),A=Math.cos(R),N=Math.sin(O),L=Math.cos(O),P=A*N,V=L,nt=I*N,J=m(P,V,nt,x,v);d[T+0]=J*P,d[T+1]=J*V,d[T+2]=J*nt,_[T+0]=P,_[T+1]=V,_[T+2]=nt,y[E+0]=x,y[E+1]=1-v}let w=e+1;for(let M=0;M<e;M++)for(let k=0;k<t;k++){let x=(M*t+k)*6;g[x+0]=k*w+M,g[x+1]=k*w+M+1,g[x+2]=(k+1)*w+M,g[x+3]=(k+1)*w+M,g[x+4]=k*w+M+1,g[x+5]=(k+1)*w+M+1}return{indices:{size:1,value:g},attributes:{POSITION:{size:3,value:d},NORMAL:{size:3,value:_},TEXCOORD_0:{size:2,value:y}}}}var qt=C(z(),1),Z=C(z(),1),mr=C(z(),1);var Ws=2,Li=1e4,Hs=class{device;id;pipelineFactory;shaderFactory;userData={};bindings={};pipeline;shader;source;shaderInputs;_uniformStore;_pipelineNeedsUpdate="newly created";_getModuleUniforms;props;_destroyed=!1;constructor(t,e){if(t.type!=="webgpu")throw new Error("Computation is only supported in WebGPU");this.props={...Hs.defaultProps,...e},e=this.props,this.id=e.id||(0,Z.uid)("model"),this.device=t,Object.assign(this.userData,e.userData);let n=Object.fromEntries(this.props.modules?.map(h=>[h.name,h])||[]);this.setShaderInputs(e.shaderInputs||new gt(n)),this.props.shaderLayout||=Yt(this.props.source);let r=Ri(t),i=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];this.pipelineFactory=e.pipelineFactory||ht.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||lt.getDefaultShaderFactory(this.device);let{source:o,getUniforms:c}=this.props.shaderAssembler.assembleShader({platformInfo:r,...this.props,modules:i});this.source=o,this._getModuleUniforms=c,this.pipeline=this._updatePipeline(),e.bindings&&this.setBindings(e.bindings),Object.seal(this)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.shader),this._uniformStore.destroy(),this._destroyed=!0)}predraw(){this.updateShaderInputs()}dispatch(t,e,n,r){try{this._logDrawCallStart(),this.pipeline=this._updatePipeline(),this.pipeline.setBindings(this.bindings),t.setPipeline(this.pipeline),t.setBindings([]),t.dispatch(e,n,r)}finally{this._logDrawCallEnd()}}setVertexCount(t){}setInstanceCount(t){}setShaderInputs(t){this.shaderInputs=t,this._uniformStore=new qt.UniformStore(this.shaderInputs.modules);for(let e of Object.keys(this.shaderInputs.modules)){let n=this._uniformStore.getManagedUniformBuffer(this.device,e);this.bindings[`${e}Uniforms`]=n}}setShaderModuleProps(t){let e=this._getModuleUniforms(t),n=Object.keys(e).filter(i=>{let o=e[i];return!(0,Z.isNumberArray)(o)&&typeof o!="number"&&typeof o!="boolean"}),r={};for(let i of n)r[i]=e[i],delete e[i]}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues())}setBindings(t){Object.assign(this.bindings,t)}_setPipelineNeedsUpdate(t){this._pipelineNeedsUpdate=this._pipelineNeedsUpdate||t}_updatePipeline(){if(this._pipelineNeedsUpdate){let t=null;this.pipeline&&(Z.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),t=this.shader),this._pipelineNeedsUpdate=!1,this.shader=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"compute",source:this.source,debug:this.props.debugShaders}),this.pipeline=this.pipelineFactory.createComputePipeline({...this.props,shader:this.shader}),t&&this.shaderFactory.release(t)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let t=Z.log.level>3?0:Li;Z.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,Z.log.group(Ws,`>>> DRAWING MODEL ${this.id}`,{collapsed:Z.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=this.shaderInputs.getDebugTable();Z.log.table(Ws,t)(),Z.log.groupEnd(Ws)(),this._logOpen=!1}}_drawCount=0;_getBufferOrConstantValues(t,e){let n=(0,mr.getTypedArrayFromDataType)(e);return(t instanceof qt.Buffer?new n(t.debugData):t).toString()}},Xt=Hs;et(Xt,"defaultProps",{...qt.ComputePipeline.defaultProps,id:"unnamed",handle:void 0,userData:{},source:"",modules:[],defines:{},bindings:void 0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,shaderAssembler:dt.getDefaultShaderAssembler(),debugShaders:void 0});function Ri(s){return{type:s.type,shaderLanguage:s.info.shadingLanguage,shaderLanguageVersion:s.info.shadingLanguageVersion,gpu:s.info.gpu,features:s.features}}return Ar(Kt);})();
100
+ `,lr=[-1,-1,1,-1,-1,1,1,1],Be=class extends K{constructor(t,e){let n=lr.map(r=>r===-1?0:r);super(t,{...e,vs:ki,vertexCount:4,geometry:new j({topology:"triangle-strip",vertexCount:4,attributes:{aClipSpacePosition:{size:2,value:new Float32Array(lr)},aTexCoord:{size:2,value:new Float32Array(n)},aCoordinate:{size:2,value:new Float32Array(n)}}})})}};var bt=C(z(),1);var dt=class{id;matrix=new et;display=!0;position=new G;rotation=new G;scale=new G(1,1,1);userData={};props={};constructor(t={}){let{id:e}=t;this.id=e||(0,bt.uid)(this.constructor.name),this._setScenegraphNodeProps(t)}getBounds(){return null}destroy(){}delete(){this.destroy()}setProps(t){return this._setScenegraphNodeProps(t),this}toString(){return`{type: ScenegraphNode, id: ${this.id})}`}setPosition(t){return(0,bt.assert)(t.length===3,"setPosition requires vector argument"),this.position=t,this}setRotation(t){return(0,bt.assert)(t.length===3,"setRotation requires vector argument"),this.rotation=t,this}setScale(t){return(0,bt.assert)(t.length===3,"setScale requires vector argument"),this.scale=t,this}setMatrix(t,e=!0){e?this.matrix.copy(t):this.matrix=t}setMatrixComponents(t){let{position:e,rotation:n,scale:r,update:i=!0}=t;return e&&this.setPosition(e),n&&this.setRotation(n),r&&this.setScale(r),i&&this.updateMatrix(),this}updateMatrix(){let t=this.position,e=this.rotation,n=this.scale;return this.matrix.identity(),this.matrix.translate(t),this.matrix.rotateXYZ(e),this.matrix.scale(n),this}update(t={}){let{position:e,rotation:n,scale:r}=t;return e&&this.setPosition(e),n&&this.setRotation(n),r&&this.setScale(r),this.updateMatrix(),this}getCoordinateUniforms(t,e){(0,bt.assert)(t),e=e||this.matrix;let n=new et(t).multiplyRight(e),r=n.invert(),i=r.transpose();return{viewMatrix:t,modelMatrix:e,objectMatrix:e,worldMatrix:n,worldInverseMatrix:r,worldInverseTransposeMatrix:i}}_setScenegraphNodeProps(t){"display"in t&&(this.display=t.display),"position"in t&&this.setPosition(t.position),"rotation"in t&&this.setRotation(t.rotation),"scale"in t&&this.setScale(t.scale),"matrix"in t&&this.setMatrix(t.matrix),Object.assign(this.props,t)}};var ur=C(z(),1);var $t=class extends dt{children;constructor(t={}){t=Array.isArray(t)?{children:t}:t;let{children:e=[]}=t;ur.log.assert(e.every(n=>n instanceof dt),"every child must an instance of ScenegraphNode"),super(t),this.children=e}getBounds(){let t=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]];return this.traverse((e,{worldMatrix:n})=>{let r=e.getBounds();if(!r)return;let[i,o]=r,c=new G(i).add(o).divide([2,2,2]);n.transformAsPoint(c,c);let h=new G(o).subtract(i).divide([2,2,2]);n.transformAsVector(h,h);for(let f=0;f<8;f++){let m=new G(f&1?-1:1,f&2?-1:1,f&4?-1:1).multiply(h).add(c);for(let p=0;p<3;p++)t[0][p]=Math.min(t[0][p],m[p]),t[1][p]=Math.max(t[1][p],m[p])}}),Number.isFinite(t[0][0])?t:null}destroy(){this.children.forEach(t=>t.destroy()),this.removeAll(),super.destroy()}add(...t){for(let e of t)Array.isArray(e)?this.add(...e):this.children.push(e);return this}remove(t){let e=this.children,n=e.indexOf(t);return n>-1&&e.splice(n,1),this}removeAll(){return this.children=[],this}traverse(t,{worldMatrix:e=new et}={}){let n=new et(e).multiplyRight(this.matrix);for(let r of this.children)r instanceof $t?r.traverse(t,{worldMatrix:n}):t(r,{worldMatrix:n})}};var Ve=class extends dt{model;bounds=null;managedResources;constructor(t){super(t),this.model=t.model,this.managedResources=t.managedResources||[],this.bounds=t.bounds||null,this.setProps(t)}getBounds(){return this.bounds}destroy(){this.model&&(this.model.destroy(),this.model=null),this.managedResources.forEach(t=>t.destroy()),this.managedResources=[]}draw(t){return this.model.draw(t)}};var dr=C(z(),1);var fr=C(z(),1);var vi={x:[2,0,1],y:[0,1,2],z:[1,2,0]},yt=class extends j{constructor(t={}){let{id:e=(0,fr.uid)("truncated-code-geometry")}=t,{indices:n,attributes:r}=bi(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{POSITION:{size:3,value:r.POSITION},NORMAL:{size:3,value:r.NORMAL},TEXCOORD_0:{size:2,value:r.TEXCOORD_0},...t.attributes}})}};function bi(s={}){let{bottomRadius:t=0,topRadius:e=0,height:n=1,nradial:r=10,nvertical:i=10,verticalAxis:o="y",topCap:c=!1,bottomCap:h=!1}=s,f=(c?2:0)+(h?2:0),m=(r+1)*(i+1+f),p=Math.atan2(t-e,n),_=Math.sin,y=Math.cos,S=Math.PI,g=y(p),w=_(p),M=c?-2:0,b=i+(h?2:0),x=r+1,k=new Uint16Array(r*(i+f)*6),v=vi[o],A=new Float32Array(m*3),T=new Float32Array(m*3),R=new Float32Array(m*2),O=0,N=0;for(let E=M;E<=b;E++){let I=E/i,P=n*I,L;E<0?(P=0,I=1,L=t):E>i?(P=n,I=1,L=e):L=t+(e-t)*(E/i),(E===-2||E===i+2)&&(L=0,I=0),P-=n/2;for(let $=0;$<x;$++){let rt=_($*S*2/r),J=y($*S*2/r);A[O+v[0]]=rt*L,A[O+v[1]]=P,A[O+v[2]]=J*L,T[O+v[0]]=E<0||E>i?0:rt*g,T[O+v[1]]=E<0?-1:E>i?1:w,T[O+v[2]]=E<0||E>i?0:J*g,R[N+0]=$/r,R[N+1]=I,N+=2,O+=3}}for(let E=0;E<i+f;E++)for(let I=0;I<r;I++){let P=(E*r+I)*6;k[P+0]=x*(E+0)+0+I,k[P+1]=x*(E+0)+1+I,k[P+2]=x*(E+1)+1+I,k[P+3]=x*(E+0)+0+I,k[P+4]=x*(E+1)+1+I,k[P+5]=x*(E+1)+0+I}return{indices:k,attributes:{POSITION:A,NORMAL:T,TEXCOORD_0:R}}}var je=class extends yt{constructor(t={}){let{id:e=(0,dr.uid)("cone-geometry"),radius:n=1,cap:r=!0}=t;super({...t,id:e,topRadius:0,topCap:Boolean(r),bottomCap:Boolean(r),bottomRadius:n})}};var mr=C(z(),1);var Ge=class extends j{constructor(t={}){let{id:e=(0,mr.uid)("cube-geometry"),indices:n=!0}=t;super(n?{...t,id:e,topology:"triangle-list",indices:{size:1,value:Mi},attributes:{...Ii,...t.attributes}}:{...t,id:e,topology:"triangle-list",indices:void 0,attributes:{...Ni,...t.attributes}})}},Mi=new Uint16Array([0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]),Si=new Float32Array([-1,-1,1,1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,1,1,1,1,1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1]),Ai=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0]),Ei=new Float32Array([0,0,1,0,1,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,0,1,1,0,1,0,0,0,0,1,0,1,1,0,1]),Ti=new Float32Array([1,-1,1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,1,1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,1,-1,1,1,1,-1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1]),Oi=new Float32Array([1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,1,0,0]),Li=new Float32Array([1,0,1,1,0,0,1,1,0,0,0,1,1,0,0,1,1,0,1,1,0,0,0,1,1,1,1,1,1,0,1,1,1,0,0,1,1,1,0,1,1,1,1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,0,1,1,0,1,1,1,0,1,0,1,0,0,0,1,0,0,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0,0,1,1,0,0,1,1,1,0,1,1,1,1,1,1,1,0,0,1,0,0,0,1,0,1,0,1,1,1,0,1,1,0,0,1,0,1,0,1]),Ii={POSITION:{size:3,value:Si},NORMAL:{size:3,value:Ai},TEXCOORD_0:{size:2,value:Ei}},Ni={POSITION:{size:3,value:Ti},TEXCOORD_0:{size:2,value:Oi},COLOR_0:{size:3,value:Li}};var pr=C(z(),1);var We=class extends yt{constructor(t={}){let{id:e=(0,pr.uid)("cylinder-geometry"),radius:n=1}=t;super({...t,id:e,bottomRadius:n,topRadius:n})}};var _r=C(z(),1);var Pi=[-1,0,0,0,1,0,0,0,-1,0,0,1,0,-1,0,1,0,0],Ri=[3,4,5,3,5,1,3,1,0,3,0,4,4,0,2,4,2,5,2,0,1,5,2,1],He=class extends j{constructor(t={}){let{id:e=(0,_r.uid)("ico-sphere-geometry")}=t,{indices:n,attributes:r}=zi(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{...r,...t.attributes}})}};function zi(s){let{iterations:t=0}=s,e=Math.PI,n=e*2,r=[...Pi],i=[...Ri];r.push(),i.push();let o=(()=>{let m={};return(p,_)=>{p*=3,_*=3;let y=p<_?p:_,S=p>_?p:_,g=`${y}|${S}`;if(g in m)return m[g];let w=r[p],M=r[p+1],b=r[p+2],x=r[_],k=r[_+1],v=r[_+2],A=(w+x)/2,T=(M+k)/2,R=(b+v)/2,O=Math.sqrt(A*A+T*T+R*R);return A/=O,T/=O,R/=O,r.push(A,T,R),m[g]=r.length/3-1}})();for(let m=0;m<t;m++){let p=[];for(let _=0;_<i.length;_+=3){let y=o(i[_+0],i[_+1]),S=o(i[_+1],i[_+2]),g=o(i[_+2],i[_+0]);p.push(g,i[_+0],y,y,i[_+1],S,S,i[_+2],g,y,S,g)}i=p}let c=new Array(r.length),h=new Array(r.length/3*2),f=i.length;for(let m=f-3;m>=0;m-=3){let p=i[m+0],_=i[m+1],y=i[m+2],S=p*3,g=_*3,w=y*3,M=p*2,b=_*2,x=y*2,k=r[S+0],v=r[S+1],A=r[S+2],T=Math.acos(A/Math.sqrt(k*k+v*v+A*A)),R=Math.atan2(v,k)+e,O=T/e,N=1-R/n,E=r[g+0],I=r[g+1],P=r[g+2],L=Math.acos(P/Math.sqrt(E*E+I*I+P*P)),$=Math.atan2(I,E)+e,rt=L/e,J=1-$/n,ne=r[w+0],re=r[w+1],ie=r[w+2],kr=Math.acos(ie/Math.sqrt(ne*ne+re*re+ie*ie)),vr=Math.atan2(re,ne)+e,tn=kr/e,oe=1-vr/n,br=[ne-E,re-I,ie-P],Mr=[k-E,v-I,A-P],H=new G(br).cross(Mr).normalize(),U;(N===0||J===0||oe===0)&&(N===0||N>.5)&&(J===0||J>.5)&&(oe===0||oe>.5)&&(r.push(r[S+0],r[S+1],r[S+2]),U=r.length/3-1,i.push(U),h[U*2+0]=1,h[U*2+1]=O,c[U*3+0]=H.x,c[U*3+1]=H.y,c[U*3+2]=H.z,r.push(r[g+0],r[g+1],r[g+2]),U=r.length/3-1,i.push(U),h[U*2+0]=1,h[U*2+1]=rt,c[U*3+0]=H.x,c[U*3+1]=H.y,c[U*3+2]=H.z,r.push(r[w+0],r[w+1],r[w+2]),U=r.length/3-1,i.push(U),h[U*2+0]=1,h[U*2+1]=tn,c[U*3+0]=H.x,c[U*3+1]=H.y,c[U*3+2]=H.z),c[S+0]=c[g+0]=c[w+0]=H.x,c[S+1]=c[g+1]=c[w+1]=H.y,c[S+2]=c[g+2]=c[w+2]=H.z,h[M+0]=N,h[M+1]=O,h[b+0]=J,h[b+1]=rt,h[x+0]=oe,h[x+1]=tn}return{indices:{size:1,value:new Uint16Array(i)},attributes:{POSITION:{size:3,value:new Float32Array(r)},NORMAL:{size:3,value:new Float32Array(c)},TEXCOORD_0:{size:2,value:new Float32Array(h)}}}}var xr=C(z(),1);function gr(s){let{indices:t,attributes:e}=s;if(!t)return s;let n=t.value.length,r={};for(let i in e){let o=e[i],{constant:c,value:h,size:f}=o;if(c||!f)continue;let m=new h.constructor(n*f);for(let p=0;p<n;++p){let _=t.value[p];for(let y=0;y<f;y++)m[p*f+y]=h[_*f+y]}r[i]={size:f,value:m}}return{attributes:Object.assign({},e,r)}}var Ye=class extends j{constructor(t={}){let{id:e=(0,xr.uid)("plane-geometry")}=t,{indices:n,attributes:r}=Ci(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{...r,...t.attributes}})}};function Ci(s){let{type:t="x,y",offset:e=0,flipCull:n=!1,unpack:r=!1}=s,i=t.split(","),o=s[`${i[0]}len`]||1,c=s[`${i[1]}len`]||1,h=s[`n${i[0]}`]||1,f=s[`n${i[1]}`]||1,m=(h+1)*(f+1),p=new Float32Array(m*3),_=new Float32Array(m*3),y=new Float32Array(m*2);n&&(o=-o);let S=0,g=0;for(let x=0;x<=f;x++)for(let k=0;k<=h;k++){let v=k/h,A=x/f;switch(y[S+0]=n?1-v:v,y[S+1]=A,t){case"x,y":p[g+0]=o*v-o*.5,p[g+1]=c*A-c*.5,p[g+2]=e,_[g+0]=0,_[g+1]=0,_[g+2]=n?1:-1;break;case"x,z":p[g+0]=o*v-o*.5,p[g+1]=e,p[g+2]=c*A-c*.5,_[g+0]=0,_[g+1]=n?1:-1,_[g+2]=0;break;case"y,z":p[g+0]=e,p[g+1]=o*v-o*.5,p[g+2]=c*A-c*.5,_[g+0]=n?1:-1,_[g+1]=0,_[g+2]=0;break;default:throw new Error("PlaneGeometry: unknown type")}S+=2,g+=3}let w=h+1,M=new Uint16Array(h*f*6);for(let x=0;x<f;x++)for(let k=0;k<h;k++){let v=(x*h+k)*6;M[v+0]=(x+0)*w+k,M[v+1]=(x+1)*w+k,M[v+2]=(x+0)*w+k+1,M[v+3]=(x+1)*w+k,M[v+4]=(x+1)*w+k+1,M[v+5]=(x+0)*w+k+1}let b={indices:{size:1,value:M},attributes:{POSITION:{size:3,value:p},NORMAL:{size:3,value:_},TEXCOORD_0:{size:2,value:y}}};return r?gr(b):b}var yr=C(z(),1);var Xe=class extends j{constructor(t={}){let{id:e=(0,yr.uid)("sphere-geometry")}=t,{indices:n,attributes:r}=Fi(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{...r,...t.attributes}})}};function Fi(s){let{nlat:t=10,nlong:e=10}=s,i=Math.PI-0,o=0,h=2*Math.PI-o,f=(t+1)*(e+1),m=(M,b,x,k,v)=>s.radius||1,p=new Float32Array(f*3),_=new Float32Array(f*3),y=new Float32Array(f*2),S=f>65535?Uint32Array:Uint16Array,g=new S(t*e*6);for(let M=0;M<=t;M++)for(let b=0;b<=e;b++){let x=b/e,k=M/t,v=b+M*(e+1),A=v*2,T=v*3,R=h*x,O=i*k,N=Math.sin(R),E=Math.cos(R),I=Math.sin(O),P=Math.cos(O),L=E*I,$=P,rt=N*I,J=m(L,$,rt,x,k);p[T+0]=J*L,p[T+1]=J*$,p[T+2]=J*rt,_[T+0]=L,_[T+1]=$,_[T+2]=rt,y[A+0]=x,y[A+1]=1-k}let w=e+1;for(let M=0;M<e;M++)for(let b=0;b<t;b++){let x=(M*t+b)*6;g[x+0]=b*w+M,g[x+1]=b*w+M+1,g[x+2]=(b+1)*w+M,g[x+3]=(b+1)*w+M,g[x+4]=b*w+M+1,g[x+5]=(b+1)*w+M+1}return{indices:{size:1,value:g},attributes:{POSITION:{size:3,value:p},NORMAL:{size:3,value:_},TEXCOORD_0:{size:2,value:y}}}}var Bt=C(z(),1),Z=C(z(),1),wr=C(z(),1);var Js=2,Di=1e4,Qs=class{device;id;pipelineFactory;shaderFactory;userData={};bindings={};pipeline;shader;source;shaderInputs;_uniformStore;_pipelineNeedsUpdate="newly created";_getModuleUniforms;props;_destroyed=!1;constructor(t,e){if(t.type!=="webgpu")throw new Error("Computation is only supported in WebGPU");this.props={...Qs.defaultProps,...e},e=this.props,this.id=e.id||(0,Z.uid)("model"),this.device=t,Object.assign(this.userData,e.userData);let n=Object.fromEntries(this.props.modules?.map(h=>[h.name,h])||[]);this.setShaderInputs(e.shaderInputs||new xt(n)),this.props.shaderLayout||=Qt(this.props.source);let r=Ui(t),i=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];this.pipelineFactory=e.pipelineFactory||lt.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||ut.getDefaultShaderFactory(this.device);let{source:o,getUniforms:c}=this.props.shaderAssembler.assembleShader({platformInfo:r,...this.props,modules:i});this.source=o,this._getModuleUniforms=c,this.pipeline=this._updatePipeline(),e.bindings&&this.setBindings(e.bindings),Object.seal(this)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.shader),this._uniformStore.destroy(),this._destroyed=!0)}predraw(){this.updateShaderInputs()}dispatch(t,e,n,r){try{this._logDrawCallStart(),this.pipeline=this._updatePipeline(),this.pipeline.setBindings(this.bindings),t.setPipeline(this.pipeline),t.setBindings([]),t.dispatch(e,n,r)}finally{this._logDrawCallEnd()}}setVertexCount(t){}setInstanceCount(t){}setShaderInputs(t){this.shaderInputs=t,this._uniformStore=new Bt.UniformStore(this.shaderInputs.modules);for(let e of Object.keys(this.shaderInputs.modules)){let n=this._uniformStore.getManagedUniformBuffer(this.device,e);this.bindings[`${e}Uniforms`]=n}}setShaderModuleProps(t){let e=this._getModuleUniforms(t),n=Object.keys(e).filter(i=>{let o=e[i];return!(0,Z.isNumberArray)(o)&&typeof o!="number"&&typeof o!="boolean"}),r={};for(let i of n)r[i]=e[i],delete e[i]}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues())}setBindings(t){Object.assign(this.bindings,t)}_setPipelineNeedsUpdate(t){this._pipelineNeedsUpdate=this._pipelineNeedsUpdate||t}_updatePipeline(){if(this._pipelineNeedsUpdate){let t=null;this.pipeline&&(Z.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),t=this.shader),this._pipelineNeedsUpdate=!1,this.shader=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"compute",source:this.source,debug:this.props.debugShaders}),this.pipeline=this.pipelineFactory.createComputePipeline({...this.props,shader:this.shader}),t&&this.shaderFactory.release(t)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let t=Z.log.level>3?0:Di;Z.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,Z.log.group(Js,`>>> DRAWING MODEL ${this.id}`,{collapsed:Z.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=this.shaderInputs.getDebugTable();Z.log.table(Js,t)(),Z.log.groupEnd(Js)(),this._logOpen=!1}}_drawCount=0;_getBufferOrConstantValues(t,e){let n=(0,wr.getTypedArrayFromDataType)(e);return(t instanceof Bt.Buffer?new n(t.debugData):t).toString()}},ee=Qs;st(ee,"defaultProps",{...Bt.ComputePipeline.defaultProps,id:"unnamed",handle:void 0,userData:{},source:"",modules:[],defines:{},bindings:void 0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,shaderAssembler:mt.getDefaultShaderAssembler(),debugShaders:void 0});function Ui(s){return{type:s.type,shaderLanguage:s.info.shadingLanguage,shaderLanguageVersion:s.info.shadingLanguageVersion,gpu:s.info.gpu,features:s.features}}return Pr(se);})();
101
101
  return __exports__;
102
102
  });