@luma.gl/engine 9.1.0-alpha.9 → 9.1.0-beta.11
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/animation/key-frames.js +1 -0
- package/dist/animation/key-frames.js.map +1 -0
- package/dist/animation/timeline.js +1 -0
- package/dist/animation/timeline.js.map +1 -0
- package/dist/animation-loop/animation-loop-template.js +1 -0
- package/dist/animation-loop/animation-loop-template.js.map +1 -0
- package/dist/animation-loop/animation-loop.d.ts +2 -0
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +24 -6
- package/dist/animation-loop/animation-loop.js.map +1 -0
- package/dist/animation-loop/animation-props.js +1 -0
- package/dist/animation-loop/animation-props.js.map +1 -0
- package/dist/animation-loop/make-animation-loop.d.ts +5 -1
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +3 -1
- package/dist/animation-loop/make-animation-loop.js.map +1 -0
- package/dist/animation-loop/request-animation-frame.d.ts +4 -2
- package/dist/animation-loop/request-animation-frame.d.ts.map +1 -1
- package/dist/animation-loop/request-animation-frame.js +5 -3
- package/dist/animation-loop/request-animation-frame.js.map +1 -0
- package/dist/application-utils/load-file.d.ts +1 -1
- package/dist/application-utils/load-file.d.ts.map +1 -1
- package/dist/application-utils/load-file.js +2 -2
- package/dist/application-utils/load-file.js.map +1 -0
- package/dist/application-utils/random.js +1 -0
- package/dist/application-utils/random.js.map +1 -0
- package/dist/async-texture/async-texture.d.ts +14 -2
- package/dist/async-texture/async-texture.d.ts.map +1 -1
- package/dist/async-texture/async-texture.js +31 -0
- package/dist/async-texture/async-texture.js.map +1 -0
- package/dist/compute/buffer-transform.d.ts +41 -0
- package/dist/compute/buffer-transform.d.ts.map +1 -0
- package/dist/{transform → compute}/buffer-transform.js +19 -12
- package/dist/compute/buffer-transform.js.map +1 -0
- package/dist/{computation.d.ts → compute/computation.d.ts} +3 -3
- package/dist/compute/computation.d.ts.map +1 -0
- package/dist/{computation.js → compute/computation.js} +7 -8
- package/dist/compute/computation.js.map +1 -0
- package/dist/compute/swap.d.ts +48 -0
- package/dist/compute/swap.d.ts.map +1 -0
- package/dist/compute/swap.js +91 -0
- package/dist/compute/swap.js.map +1 -0
- package/dist/{transform → compute}/texture-transform.d.ts +0 -6
- package/dist/compute/texture-transform.d.ts.map +1 -0
- package/dist/{transform → compute}/texture-transform.js +7 -13
- package/dist/compute/texture-transform.js.map +1 -0
- package/dist/debug/copy-texture-to-image.js +1 -0
- package/dist/debug/copy-texture-to-image.js.map +1 -0
- package/dist/debug/debug-framebuffer.js +2 -1
- package/dist/debug/debug-framebuffer.js.map +1 -0
- package/dist/debug/debug-shader-layout.js +2 -1
- package/dist/debug/debug-shader-layout.js.map +1 -0
- package/dist/debug/pixel-data-utils.js +1 -0
- package/dist/debug/pixel-data-utils.js.map +1 -0
- package/dist/dist.dev.js +2588 -5862
- package/dist/dist.min.js +420 -103
- package/dist/factories/pipeline-factory.d.ts.map +1 -0
- package/dist/{lib → factories}/pipeline-factory.js +1 -0
- package/dist/factories/pipeline-factory.js.map +1 -0
- package/dist/factories/shader-factory.d.ts.map +1 -0
- package/dist/{lib → factories}/shader-factory.js +1 -0
- package/dist/factories/shader-factory.js.map +1 -0
- package/dist/geometries/cone-geometry.js +1 -0
- package/dist/geometries/cone-geometry.js.map +1 -0
- package/dist/geometries/cube-geometry.js +1 -0
- package/dist/geometries/cube-geometry.js.map +1 -0
- package/dist/geometries/cylinder-geometry.js +1 -0
- package/dist/geometries/cylinder-geometry.js.map +1 -0
- package/dist/geometries/ico-sphere-geometry.js +1 -0
- package/dist/geometries/ico-sphere-geometry.js.map +1 -0
- package/dist/geometries/plane-geometry.js +1 -0
- package/dist/geometries/plane-geometry.js.map +1 -0
- package/dist/geometries/sphere-geometry.js +1 -0
- package/dist/geometries/sphere-geometry.js.map +1 -0
- package/dist/geometries/truncated-cone-geometry.js +1 -0
- package/dist/geometries/truncated-cone-geometry.js.map +1 -0
- package/dist/geometry/geometry-table.js +1 -0
- package/dist/geometry/geometry-table.js.map +1 -0
- package/dist/geometry/geometry-utils.js +1 -0
- package/dist/geometry/geometry-utils.js.map +1 -0
- package/dist/geometry/geometry.js +1 -0
- package/dist/geometry/geometry.js.map +1 -0
- package/dist/geometry/gpu-geometry.js +1 -0
- package/dist/geometry/gpu-geometry.js.map +1 -0
- package/dist/geometry/gpu-table.js +1 -0
- package/dist/geometry/gpu-table.js.map +1 -0
- package/dist/index.cjs +1268 -173
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +23 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -9
- package/dist/index.js.map +1 -0
- package/dist/model/model.d.ts +11 -10
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +77 -58
- package/dist/model/model.js.map +1 -0
- package/dist/model/split-uniforms-and-bindings.d.ts +1 -1
- package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
- package/dist/model/split-uniforms-and-bindings.js +2 -1
- package/dist/model/split-uniforms-and-bindings.js.map +1 -0
- package/dist/models/billboard-texture-model.d.ts +23 -0
- package/dist/models/billboard-texture-model.d.ts.map +1 -0
- package/dist/models/billboard-texture-model.js +78 -0
- package/dist/models/billboard-texture-model.js.map +1 -0
- package/dist/models/billboard-texture-module.d.ts +10 -0
- package/dist/models/billboard-texture-module.d.ts.map +1 -0
- package/dist/models/billboard-texture-module.js +37 -0
- package/dist/models/billboard-texture-module.js.map +1 -0
- package/dist/{lib → models}/clip-space.d.ts +3 -1
- package/dist/models/clip-space.d.ts.map +1 -0
- package/dist/models/clip-space.js +77 -0
- package/dist/models/clip-space.js.map +1 -0
- package/dist/modules/picking/color-picking.d.ts +28 -0
- package/dist/modules/picking/color-picking.d.ts.map +1 -0
- package/dist/modules/picking/color-picking.js +177 -0
- package/dist/modules/picking/color-picking.js.map +1 -0
- package/dist/modules/picking/index-picking.d.ts +32 -0
- package/dist/modules/picking/index-picking.d.ts.map +1 -0
- package/dist/modules/picking/index-picking.js +148 -0
- package/dist/modules/picking/index-picking.js.map +1 -0
- package/dist/modules/picking/legacy-picking-manager.d.ts +27 -0
- package/dist/modules/picking/legacy-picking-manager.d.ts.map +1 -0
- package/dist/modules/picking/legacy-picking-manager.js +76 -0
- package/dist/modules/picking/legacy-picking-manager.js.map +1 -0
- package/dist/modules/picking/picking-manager.d.ts +45 -0
- package/dist/modules/picking/picking-manager.d.ts.map +1 -0
- package/dist/modules/picking/picking-manager.js +101 -0
- package/dist/modules/picking/picking-manager.js.map +1 -0
- package/dist/modules/picking/picking-uniforms.d.ts +79 -0
- package/dist/modules/picking/picking-uniforms.d.ts.map +1 -0
- package/dist/modules/picking/picking-uniforms.js +109 -0
- package/dist/modules/picking/picking-uniforms.js.map +1 -0
- package/dist/passes/get-fragment-shader.d.ts +12 -0
- package/dist/passes/get-fragment-shader.d.ts.map +1 -0
- package/dist/passes/get-fragment-shader.js +117 -0
- package/dist/passes/get-fragment-shader.js.map +1 -0
- package/dist/passes/shader-pass-renderer.d.ts +63 -0
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -0
- package/dist/passes/shader-pass-renderer.js +197 -0
- package/dist/passes/shader-pass-renderer.js.map +1 -0
- package/dist/scenegraph/group-node.js +1 -0
- package/dist/scenegraph/group-node.js.map +1 -0
- package/dist/scenegraph/model-node.js +1 -0
- package/dist/scenegraph/model-node.js.map +1 -0
- package/dist/scenegraph/scenegraph-node.js +1 -0
- package/dist/scenegraph/scenegraph-node.js.map +1 -0
- package/dist/shader-inputs.d.ts +8 -21
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +15 -11
- package/dist/shader-inputs.js.map +1 -0
- package/dist/utils/deep-equal.js +1 -0
- package/dist/utils/deep-equal.js.map +1 -0
- package/dist/utils/uid.js +1 -0
- package/dist/utils/uid.js.map +1 -0
- package/package.json +6 -6
- package/src/animation-loop/animation-loop.ts +27 -6
- package/src/animation-loop/make-animation-loop.ts +8 -3
- package/src/animation-loop/request-animation-frame.ts +4 -3
- package/src/application-utils/load-file.ts +2 -4
- package/src/async-texture/async-texture.ts +39 -7
- package/src/{transform → compute}/buffer-transform.ts +30 -14
- package/src/{computation.ts → compute/computation.ts} +14 -8
- package/src/compute/swap.ts +116 -0
- package/src/{transform → compute}/texture-transform.ts +6 -16
- package/src/debug/debug-framebuffer.ts +1 -1
- package/src/debug/debug-shader-layout.ts +1 -1
- package/src/index.ts +35 -16
- package/src/model/model.ts +116 -66
- package/src/model/split-uniforms-and-bindings.ts +4 -4
- package/src/models/billboard-texture-model.ts +98 -0
- package/src/models/billboard-texture-module.ts +49 -0
- package/src/models/clip-space.ts +88 -0
- package/src/modules/picking/README.md +88 -0
- package/src/modules/picking/color-picking.ts +190 -0
- package/src/modules/picking/index-picking.ts +156 -0
- package/src/modules/picking/legacy-picking-manager.ts +99 -0
- package/src/modules/picking/picking-manager.ts +137 -0
- package/src/modules/picking/picking-uniforms.ts +179 -0
- package/src/passes/get-fragment-shader.ts +129 -0
- package/src/passes/shader-pass-renderer.ts +252 -0
- package/src/shader-inputs.ts +27 -48
- package/dist/computation.d.ts.map +0 -1
- package/dist/lib/clip-space.d.ts.map +0 -1
- package/dist/lib/clip-space.js +0 -46
- package/dist/lib/pipeline-factory.d.ts.map +0 -1
- package/dist/lib/shader-factory.d.ts.map +0 -1
- package/dist/transform/buffer-transform.d.ts +0 -35
- package/dist/transform/buffer-transform.d.ts.map +0 -1
- package/dist/transform/texture-transform.d.ts.map +0 -1
- package/src/lib/clip-space.ts +0 -53
- /package/dist/{lib → factories}/pipeline-factory.d.ts +0 -0
- /package/dist/{lib → factories}/shader-factory.d.ts +0 -0
- /package/src/{lib → factories}/pipeline-factory.ts +0 -0
- /package/src/{lib → factories}/shader-factory.ts +0 -0
package/dist/dist.min.js
CHANGED
|
@@ -4,115 +4,432 @@
|
|
|
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 Or=Object.create;var $t=Object.defineProperty;var Pr=Object.getOwnPropertyDescriptor;var Ir=Object.getOwnPropertyNames;var Lr=Object.getPrototypeOf,Nr=Object.prototype.hasOwnProperty;var Rr=(s,t,e)=>t in s?$t(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var zr=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports),Cr=(s,t)=>{for(var e in t)$t(s,e,{get:t[e],enumerable:!0})},oe=(s,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ir(t))!Nr.call(s,r)&&r!==e&&$t(s,r,{get:()=>t[r],enumerable:!(n=Pr(t,r))||n.enumerable});return s},ae=(s,t,e)=>(oe(s,t,"default"),e&&oe(e,t,"default")),$=(s,t,e)=>(e=s!=null?Or(Lr(s)):{},oe(t||!s||!s.__esModule?$t(e,"default",{value:s,enumerable:!0}):e,s)),Fr=s=>oe($t({},"__esModule",{value:!0}),s);var et=(s,t,e)=>(Rr(s,typeof t!="symbol"?t+"":t,e),e);var D=zr((Ki,on)=>{on.exports=globalThis.luma});var ee={};Cr(ee,{AnimationLoop:()=>vt,AnimationLoopTemplate:()=>le,AsyncTexture:()=>wt,BufferTransform:()=>Dt,ClipSpace:()=>Ge,Computation:()=>te,ConeGeometry:()=>He,CubeGeometry:()=>Ye,CylinderGeometry:()=>Xe,GPUGeometry:()=>zt,Geometry:()=>G,GroupNode:()=>Ut,IcoSphereGeometry:()=>Ke,KeyFrames:()=>he,Model:()=>Z,ModelNode:()=>We,PipelineFactory:()=>at,PlaneGeometry:()=>Ze,ScenegraphNode:()=>lt,ShaderFactory:()=>ct,SphereGeometry:()=>Je,TextureTransform:()=>je,Timeline:()=>ce,TruncatedConeGeometry:()=>_t,_ShaderInputs:()=>pt,cancelAnimationFrame:()=>fe,loadImage:()=>mr,loadImageBitmap:()=>$e,makeAnimationLoop:()=>hn,makeRandomGenerator:()=>br,requestAnimationFrame:()=>ue,setPathPrefix:()=>dr});ae(ee,$(D(),1));var Dr=1,Ur=1,ce=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=Dr++,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=Ur++;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 he=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 le=class{constructor(t){}async onInitialize(t){return null}};var an=$(D(),1);function ue(s){return typeof window<"u"&&window.requestAnimationFrame?window.requestAnimationFrame(s):setTimeout(s,1e3/60)}function fe(s){return typeof window<"u"&&window.cancelAnimationFrame?window.cancelAnimationFrame(s):clearTimeout(s)}function Bt(){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 xt=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=Bt(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(Bt()-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 kt=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 xt?r=t:r=new xt(e,n),this.stats[e]=r),r}};var qr=0,$r={device:null,onAddHTML:()=>"",onInitialize:async()=>null,onRender:()=>{},onFinalize:()=>{},onError:s=>console.error(s),stats:an.luma.stats.get(`animation-loop-${qr++}`),useDevicePixels:!0,autoResizeViewport:!1,autoResizeDrawingBuffer:!1},vt=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={...$r,...t},t=this.props,!t.device)throw new Error("No device provided");let{useDevicePixels:e=!0}=this.props;this.stats=t.stats||new kt({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=ue(this._animationFrame.bind(this)))}_cancelAnimationFrame(){this._animationFrameId!==null&&(fe(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(){let t=this.device?.canvasContext?.canvas;if(!this.device||!t)throw new Error("loop");this.animationProps={animationLoop:this,device:this.device,canvas:t,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 cn=$(D(),1);function hn(s,t){let e=null,n=t?.device||cn.luma.createDevice({id:"animation-loop"}),r=new vt({...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 ht=$(D(),1),Be=$(D(),1),j=$(D(),1),Ve=$(D(),1);function de(s,t){if(!s)throw new Error(t||"shadertools: assertion failed.")}var Qe={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 un(s){let t={};for(let[e,n]of Object.entries(s))t[e]=Br(n);return t}function Br(s){let t=ln(s);if(t!=="object")return{value:s,...Qe[t],type:t};if(typeof s=="object")return s?s.type!==void 0?{...s,...Qe[s.type],type:s.type}:s.value===void 0?{type:"object",value:s}:(t=ln(s.value),{...s,...Qe[t],type:t}):{type:"object",value:null};throw new Error("props")}function ln(s){return Array.isArray(s)||ArrayBuffer.isView(s)?"array":typeof s}var fn=`#ifdef MODULE_LOGDEPTH
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// Apple optimizes away the calculation necessary for emulated fp64
|
|
34
|
-
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
35
|
-
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
36
|
-
// Intel GPU doesn't have full 32 bits precision in same cases, causes overflow
|
|
37
|
-
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
|
|
38
|
-
`;case"nvidia":return`#define NVIDIA_GPU
|
|
39
|
-
// Nvidia optimizes away the calculation necessary for emulated fp64
|
|
40
|
-
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
41
|
-
`;case"intel":return`#define INTEL_GPU
|
|
42
|
-
// Intel optimizes away the calculation necessary for emulated fp64
|
|
43
|
-
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
44
|
-
// Intel's built-in 'tan' function doesn't have acceptable precision
|
|
45
|
-
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
46
|
-
// Intel GPU doesn't have full 32 bits precision in same cases, causes overflow
|
|
47
|
-
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
|
|
48
|
-
`;case"amd":return`#define AMD_GPU
|
|
49
|
-
`;default:return`#define DEFAULT_GPU
|
|
50
|
-
// Prevent driver from optimizing away the calculation necessary for emulated fp64
|
|
51
|
-
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
52
|
-
// Headless Chrome's software shader 'tan' function doesn't have acceptable precision
|
|
53
|
-
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
54
|
-
// If the GPU doesn't have full 32 bits precision, will causes overflow
|
|
55
|
-
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
|
|
56
|
-
`}}function wn(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=yn(s,Hr),s;case"fragment":return s=yn(s,Yr),s;default:throw new Error(t)}}var kn=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
|
|
57
|
-
`],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],Hr=[...kn,[ss("attribute"),"in $1"],[ss("varying"),"out $1"]],Yr=[...kn,[ss("varying"),"in $1"]];function yn(s,t){for(let[e,n]of t)s=s.replace(e,n);return s}function ss(s){return new RegExp(`\\b${s}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function ns(s,t){let e="";for(let n in s){let r=s[n];if(e+=`void ${r.signature} {
|
|
58
|
-
`,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}
|
|
59
|
-
`}r.footer&&(e+=` ${r.footer}`),e+=`}
|
|
60
|
-
`}return e}function rs(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 vn(s,t){return{name:Xr(s,t),language:"glsl",version:Kr(s)}}function Xr(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 Kr(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 Mn=`
|
|
61
|
-
|
|
62
|
-
${Vt}
|
|
63
|
-
`,Zr=`precision highp float;
|
|
64
|
-
`;function Sn(s){let t=Mt(s.modules||[]);return{source:Jr(s.platformInfo,{...s,source:s.source,stage:"vertex",modules:t}),getUniforms:En(t)}}function An(s){let{vs:t,fs:e}=s,n=Mt(s.modules||[]);return{vs:bn(s.platformInfo,{...s,source:t,stage:"vertex",modules:n}),fs:bn(s.platformInfo,{...s,source:e,stage:"fragment",modules:n}),getUniforms:En(n)}}function Jr(s,t){let{source:e,stage:n,modules:r,hookFunctions:i=[],inject:o={},log:c}=t;de(typeof e=="string","shader source must be a string");let h=e,f="",m=rs(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&&es(g,h,c);let w=Tn(g,n);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+=Mn,f=jt(f,n,_),f+=ns(m[n],p),f+=h,f=jt(f,n,y),f}function bn(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;de(typeof n=="string","shader source must be a string");let _=i==="glsl"?vn(n).version:-1,y=s.shaderLanguageVersion,S=_===100?"#version 100":"#version 300 es",w=n.split(`
|
|
65
|
-
`).slice(1).join(`
|
|
66
|
-
`),M={};o.forEach(T=>{Object.assign(M,T.defines)}),Object.assign(M,c);let b="";switch(i){case"wgsl":break;case"glsl":b=m?`${S}
|
|
67
|
-
|
|
68
|
-
// ----- PROLOGUE -------------------------
|
|
69
|
-
${Qr({id:e,source:n,stage:r})}
|
|
70
|
-
${`#define SHADER_TYPE_${r.toUpperCase()}`}
|
|
71
|
-
|
|
72
|
-
${xn(s)}
|
|
73
|
-
${r==="fragment"?Zr:""}
|
|
74
|
-
|
|
75
|
-
// ----- APPLICATION DEFINES -------------------------
|
|
76
|
-
|
|
77
|
-
${ti(M)}
|
|
78
|
-
|
|
79
|
-
`:`${S}
|
|
80
|
-
`;break}let x=rs(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 L=O[2],E=O[3];L?E==="decl"?v[T]=[R]:A[T]=[R]:k[T]=[R]}else A[T]=[R]}for(let T of o){p&&es(T,w,p);let R=Tn(T,r);b+=R;let O=T.instance?.normalizedInjections[r]||{};for(let L in O){let E=/^(v|f)s:#([\w-]+)$/.exec(L);if(E){let N=E[2]==="decl"?v:A;N[L]=N[L]||[],N[L].push(O[L])}else k[L]=k[L]||[],k[L].push(O[L])}}return b+="// ----- MAIN SHADER SOURCE -------------------------",b+=Mn,b=jt(b,r,v),b+=ns(x[r],k),b+=w,b=jt(b,r,A),i==="glsl"&&_!==y&&(b=wn(b,r)),b.trim()}function En(s){return function(e){let n={};for(let r of s){let i=r.getUniforms?.(e,n);Object.assign(n,i)}return n}}function Qr(s){let{id:t,source:e,stage:n}=s;return t&&e.indexOf("SHADER_NAME")===-1?`
|
|
81
|
-
#define SHADER_NAME ${t}_${n}`:""}function ti(s={}){let t="";for(let e in s){let n=s[e];(n||Number.isFinite(n))&&(t+=`#define ${e.toUpperCase()} ${s[e]}
|
|
82
|
-
`)}return t}function Tn(s,t){let e;switch(t){case"vertex":e=s.vs||"";break;case"fragment":e=s.fs||"";break;case"wgsl":e=s.source||"";break;default:de(!1)}if(!s.name)throw new Error("Shader module must have a name");let n=s.name.toUpperCase().replace(/[^0-9a-z]/gi,"_");return`// ----- MODULE ${s.name} ---------------
|
|
83
|
-
|
|
84
|
-
#define MODULE_${n}
|
|
85
|
-
${e}
|
|
86
|
-
|
|
87
|
-
`}var ei=/^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/,si=/^\s*\#\s*endif\s*$/;function On(s,t){let e=s.split(`
|
|
88
|
-
`),n=[],r=!0,i=null;for(let o of e){let c=o.match(ei),h=o.match(si);c?(i=c[1],r=Boolean(t?.defines?.[i])):h?r=!0:r&&n.push(o)}return n.join(`
|
|
89
|
-
`)}var St=class{_hookFunctions=[];_defaultModules=[];static getDefaultShaderAssembler(){return St.defaultShaderAssembler=St.defaultShaderAssembler||new St,St.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)}assembleWGSLShader(t){let e=this._getModuleList(t.modules),n=this._hookFunctions,{source:r,getUniforms:i}=Sn({...t,source:t.source,modules:e,hookFunctions:n});return{source:t.platformInfo.shaderLanguage==="wgsl"?On(r):r,getUniforms:i,modules:e}}assembleGLSLShaderPair(t){let e=this._getModuleList(t.modules),n=this._hookFunctions;return{...An({...t,vs:t.vs,fs:t.fs,modules:e,hookFunctions:n}),modules:e}}_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,bt(e),e}},ut=St;et(ut,"defaultShaderAssembler");var ni=`out vec4 transform_output;
|
|
90
|
-
void main() {
|
|
91
|
-
transform_output = vec4(0);
|
|
92
|
-
}`,ri=`#version 300 es
|
|
93
|
-
${ni}`;function Gt(s){let{input:t,inputChannels:e,output:n}=s||{};if(!t)return ri;if(!e)throw new Error("inputChannels");let r=ii(e),i=Pn(t,e);return`#version 300 es
|
|
94
|
-
in ${r} ${t};
|
|
95
|
-
out vec4 ${n};
|
|
96
|
-
void main() {
|
|
97
|
-
${n} = ${i};
|
|
98
|
-
}`}function ii(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 Pn(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 Ln=$(D(),1);var is=class{constructor(){this.constants=new Map,this.aliases=new Map,this.structs=new Map}},Q=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(Ot.instance);for(let n of t)n instanceof Array?this.searchBlock(n,e):n.search(e);e(Pt.instance)}}},Ot=class extends Q{};Ot.instance=new Ot;var Pt=class extends Q{};Pt.instance=new Pt;var z=class extends Q{constructor(){super()}},Ht=class extends z{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)}},os=class extends z{constructor(t){super(),this.expression=t}get astNodeType(){return"staticAssert"}search(t){this.expression.search(t)}},as=class extends z{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)}},cs=class extends z{constructor(t){super(),this.body=t}get astNodeType(){return"continuing"}search(t){this.searchBlock(this.body,t)}},hs=class extends z{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)}},rt=class extends z{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)}},me=class extends z{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)}},Yt=class extends z{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)}},pe=class extends z{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)}},It;(function(s){s.increment="++",s.decrement="--"})(It||(It={}));(function(s){function t(e){let n=e;if(n=="parse")throw new Error("Invalid value for IncrementOperator");return s[n]}s.parse=t})(It||(It={}));var ls=class extends z{constructor(t,e){super(),this.operator=t,this.variable=e}get astNodeType(){return"increment"}search(t){this.variable.search(t)}},Xt;(function(s){s.assign="=",s.addAssign="+=",s.subtractAssin="-=",s.multiplyAssign="*=",s.divideAssign="/=",s.moduloAssign="%=",s.andAssign="&=",s.orAssign="|=",s.xorAssign="^=",s.shiftLeftAssign="<<=",s.shiftRightAssign=">>="})(Xt||(Xt={}));(function(s){function t(e){let n=e;if(n=="parse")throw new Error("Invalid value for AssignOperator");return n}s.parse=t})(Xt||(Xt={}));var us=class extends z{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)}},_e=class extends z{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)}},fs=class extends z{constructor(t,e){super(),this.body=t,this.continuing=e}get astNodeType(){return"loop"}},ds=class extends z{constructor(t,e){super(),this.condition=t,this.body=e}get astNodeType(){return"body"}},ms=class extends z{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)}},ps=class extends z{constructor(t){super(),this.value=t}get astNodeType(){return"return"}search(t){var e;(e=this.value)===null||e===void 0||e.search(t)}},_s=class extends z{constructor(t){super(),this.name=t}get astNodeType(){return"enable"}},gs=class extends z{constructor(t){super(),this.extensions=t}get astNodeType(){return"requires"}},xs=class extends z{constructor(t,e){super(),this.severity=t,this.rule=e}get astNodeType(){return"diagnostic"}},ge=class extends z{constructor(t,e){super(),this.name=t,this.type=e}get astNodeType(){return"alias"}},ys=class extends z{constructor(){super()}get astNodeType(){return"discard"}},ws=class extends z{constructor(){super()}get astNodeType(){return"break"}},ks=class extends z{constructor(){super()}get astNodeType(){return"continue"}},it=class extends z{constructor(t){super(),this.name=t}get astNodeType(){return"type"}get isStruct(){return!1}get isArray(){return!1}},nt=class extends it{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}},xe=class extends it{constructor(t,e,n){super(t),this.format=e,this.access=n}get astNodeType(){return"template"}},vs=class extends it{constructor(t,e,n,r){super(t),this.storage=e,this.type=n,this.access=r}get astNodeType(){return"pointer"}},ye=class extends it{constructor(t,e,n,r){super(t),this.attributes=e,this.format=n,this.count=r}get astNodeType(){return"array"}get isArray(){return!0}},yt=class extends it{constructor(t,e,n){super(t),this.format=e,this.access=n}get astNodeType(){return"sampler"}},H=class extends Q{constructor(){super()}},we=class extends H{constructor(t){super(),this.value=t}get astNodeType(){return"stringExpr"}toString(){return this.value}evaluateString(){return this.value}},dt=class extends H{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)}},ke=class extends H{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)}},Kt=class extends H{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)}},ve=class extends H{constructor(t,e){super(),this.name=t,this.initializer=e}get astNodeType(){return"constExpr"}evaluate(t){var e,n;if(this.initializer instanceof dt){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)}},be=class extends H{constructor(t){super(),this.value=t}get astNodeType(){return"literalExpr"}evaluate(){return this.value}},bs=class extends H{constructor(t,e){super(),this.type=t,this.value=e}get astNodeType(){return"bitcastExpr"}search(t){this.value.search(t)}},Ms=class extends H{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)}},Me=class extends H{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)}},Ss=class extends H{constructor(t){super(),this.index=t}search(t){this.index.search(t)}},Se=class extends H{constructor(){super()}},As=class extends Se{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)}},X=class extends Se{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)}},Ae=class extends Q{constructor(){super()}},Es=class extends Ae{constructor(t,e){super(),this.selector=t,this.body=e}get astNodeType(){return"case"}search(t){this.searchBlock(this.body,t)}},Ts=class extends Ae{constructor(t){super(),this.body=t}get astNodeType(){return"default"}search(t){this.searchBlock(this.body,t)}},Os=class extends Q{constructor(t,e,n){super(),this.name=t,this.type=e,this.attributes=n}get astNodeType(){return"argument"}},Ps=class extends Q{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)}},Is=class extends Q{constructor(t,e,n){super(),this.name=t,this.type=e,this.attributes=n}get astNodeType(){return"member"}},Ls=class extends Q{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 Ee=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 Ee(a.eof,"",this._line)),this._tokens}scanToken(){let t=this._advance();if(t==`
|
|
99
|
-
`)return this._line++,!0;if(this._isWhitespace(t))return!0;if(t=="/"){if(this._peekAhead()=="/"){for(;t!=`
|
|
100
|
-
`;){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==`
|
|
101
|
-
`)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 Ee(t,e,this._line))}},Rs=class{constructor(){this._tokens=[],this._current=0,this._currentLine=0,this._context=new is,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 Kt){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 Os(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 Ht(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 ys:this._match(a.keywords.break)?t=new ws:this._match(a.keywords.continue)?t=new ks: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 os(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 as(t,e)}_continuing_statement(){if(!this._match(a.keywords.continuing))return null;let t=this._compound_statement();return new cs(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 hs(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 rt(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 Yt(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 pe(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 ls(n.type===a.tokens.plus_plus?It.increment:It.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 us(Xt.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 _e(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 fs(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 ds(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 Es(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 Ts(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 ms(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 Ps(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 ps(t)}_short_circuit_or_expression(){let t=this._short_circuit_and_expr();for(;this._match(a.tokens.or_or);)t=new X(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 X(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 X(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 X(this._previous().toString(),t,this._and_expression());return t}_and_expression(){let t=this._equality_expression();for(;this._match(a.tokens.and);)t=new X(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 X(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 X(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 X(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 X(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 X(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 As(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 Ss(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 we(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 dt(i,r):new ke(n,r)}if(this._context.constants.has(n)){let r=this._context.constants.get(n);return new ve(n,r.value)}return new Kt(n)}if(this._match(a.const_literal))return new be(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 bs(n,r)}let t=this._type_decl(),e=this._argument_expression_list();return new Ms(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 Me([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 Me([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 Is(c,f,o))}this._consume(a.tokens.brace_right,"Expected '}' after struct body.");let r=this._currentLine,i=new nt(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 dt)n=i;else if(i instanceof ve&&i.initializer instanceof dt)n=i.initializer;else try{let o=i.evaluate(this._context);n=new be(o)}catch{n=i}}let r=new pe(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 Yt(t.toString(),e,"","",n)}_const_expression(){if(this._match(a.const_literal))return new we(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 dt(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 rt(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 me(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 xs(t.toString(),e.toString())}_enable_directive(){let t=this._consume(a.tokens.ident,"identity expected.");return new _s(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 gs(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 ge(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 it(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 xe(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 vs(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 ye(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 yt(this._previous().toString(),null,null);if(this._match(a.depth_texture_type))return new yt(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 yt(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 yt(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 Ls(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}},mt=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}},Te=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 mt{constructor(t,e){super(t,e),this.members=[],this.align=0,this.startLine=-1,this.endLine=-1,this.inUse=!1}get isStruct(){return!0}},Wt=class extends mt{constructor(t,e){super(t,e),this.count=0,this.stride=0}get isArray(){return!0}},Oe=class extends mt{constructor(t,e,n,r){super(t,n),this.format=e,this.access=r}get isTemplate(){return!0}},ft;(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"})(ft||(ft={}));var Et=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}},zs=class{constructor(t,e){this.name=t,this.type=e}},Tt=class{constructor(t,e){this.align=t,this.size=e}},Cs=class{constructor(t,e,n,r){this.name=t,this.type=e,this.locationType=n,this.location=r,this.interpolation=null}},Pe=class{constructor(t,e,n,r){this.name=t,this.type=e,this.locationType=n,this.location=r}},Fs=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}},Ds=class{constructor(){this.vertex=[],this.fragment=[],this.compute=[]}},Us=class{constructor(t,e,n,r){this.name=t,this.type=e,this.attributes=n,this.id=r}},qs=class{constructor(t){this.resources=null,this.inUse=!1,this.info=null,this.node=t}},K=class{constructor(t){this.uniforms=[],this.storage=[],this.textures=[],this.samplers=[],this.aliases=[],this.overrides=[],this.structs=[],this.entry=new Ds,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 Rs().parse(t);for(let r of n)r instanceof Ht&&this._functions.set(r.name,new qs(r));for(let r of n)if(r instanceof nt){let i=this._getTypeInfo(r,null);i instanceof At&&this.structs.push(i)}for(let r of n){if(r instanceof ge){this.aliases.push(this._getAliasInfo(r));continue}if(r instanceof me){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 Us(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 Et(i.name,h,o,c,i.attributes,ft.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 Et(i.name,h,o,c,i.attributes,f?ft.StorageTexture:ft.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 Et(i.name,h,o,c,i.attributes,f?ft.StorageTexture:ft.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 Et(i.name,h,o,c,i.attributes,ft.Sampler,i.access);this.samplers.push(f);continue}if(r instanceof Ht){let i=this._getAttribute(r,"vertex"),o=this._getAttribute(r,"fragment"),c=this._getAttribute(r,"compute"),h=i||o||c,f=new Fs(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 Ot)i.push({});else if(o instanceof Pt)i.pop();else if(o instanceof rt){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 dt){let c=o;e&&c.type!==null&&this._markStructsFromAST(c.type)}else if(o instanceof Yt){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 Kt){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 ke){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 _e){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 nt)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 nt)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 Pe(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 Pe("",n,e.name,r)}return null}_getInputs(t,e=void 0){e===void 0&&(e=[]);for(let n of t)if(n.type instanceof nt)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 nt)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 Cs(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 zs(t.name,this._getTypeInfo(t.type,null))}_getTypeInfo(t,e){if(this._types.has(t))return this._types.get(t);if(t instanceof ye){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 nt){let r=t,i=new At(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 Te(o.name,c,o.attributes))}return this._types.set(t,i),this._updateTypeInfo(i),i}if(t instanceof yt){let r=t,i=r.format instanceof it,o=r.format?i?this._getTypeInfo(r.format,null):new mt(r.format,null):null,c=new Oe(r.name,o,e,r.access);return this._types.set(t,c),this._updateTypeInfo(c),c}if(t instanceof xe){let r=t,i=r.format?this._getTypeInfo(r.format,null):null,o=new Oe(r.name,i,e,r.access);return this._types.set(t,o),this._updateTypeInfo(o),o}let n=new mt(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 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 Te&&(t=t.type),t instanceof mt){let i=this._getAlias(t.name);i!==null&&(t=i)}{let i=K._typeInfo[t.name];if(i!==void 0){let o=t.format==="f16"?2:1;return new Tt(Math.max(r,i.align/o),Math.max(n,i.size/o))}}{let i=K._typeInfo[t.name.substring(0,t.name.length-1)];if(i){let o=t.name[t.name.length-1]==="h"?2:1;return new Tt(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 Tt(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 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 Tt(Math.max(r,i),Math.max(n,o))}return null}_isUniformVar(t){return t instanceof rt&&t.storage=="uniform"}_isStorageVar(t){return t instanceof rt&&t.storage=="storage"}_isTextureVar(t){return t instanceof rt&&t.type!==null&&K._textureTypes.indexOf(t.type.name)!=-1}_isSamplerVar(t){return t instanceof rt&&t.type!==null&&K._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}};K._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}};K._textureTypes=a.any_texture_type.map(s=>s.name);K._samplerTypes=a.sampler_type.map(s=>s.name);function Zt(s){let t={attributes:[],bindings:[]},e;try{e=oi(s)}catch(i){return Ln.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:In(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=In(o.type);t.attributes.push({name:o.name,location:Number(o.location),type:c})}}return t}function In(s){return s.format?`${s.name}<${s.format.name}>`:s.name}function oi(s){try{return new K(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 Ko=1/Math.PI*180,Zo=1/180*Math.PI,ai={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...ai}};var B=globalThis.mathgl.config;function Nn(s,{precision:t=B.precision}={}){return s=ci(s),`${parseFloat(s.toPrecision(t))}`}function Lt(s){return Array.isArray(s)||ArrayBuffer.isView(s)&&!(s instanceof DataView)}function $s(s,t,e){let n=B.EPSILON;e&&(B.EPSILON=e);try{if(s===t)return!0;if(Lt(s)&&Lt(t)){if(s.length!==t.length)return!1;for(let r=0;r<s.length;++r)if(!$s(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 ci(s){return Math.round(s/B.EPSILON)*B.EPSILON}var Nt=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:Lt(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?", ":"")+Nn(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(!$s(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 hi(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 Ie(s,t,e=""){if(B.debug&&!hi(s,t))throw new Error(`math.gl: ${e} some fields set to invalid numbers'`);return s}function Bs(s,t){if(!s)throw new Error(`math.gl assertion ${t}`)}var Le=class extends Nt{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 Bs(t>=0&&t<this.ELEMENTS,"index is out of range"),V(this[t])}setComponent(t,e){return Bs(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 ot=typeof Float32Array<"u"?Float32Array:Array;var ca=Math.PI/180;function li(){let s=new ot(2);return ot!=Float32Array&&(s[0]=0,s[1]=0),s}function Cn(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 ha=function(){let s=li();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 Fn(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 Dn(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 ui(){let s=new ot(3);return ot!=Float32Array&&(s[0]=0,s[1]=0,s[2]=0),s}function fi(s,t){return s[0]*t[0]+s[1]*t[1]+s[2]*t[2]}function Un(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 Re(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 qn(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 $n(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 Bn(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 Vn(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 jn(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 Gn(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&&fi(s,t)/h;return Math.acos(Math.min(Math.max(f,-1),1))}var fa=function(){let s=ui();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 js=[0,0,0],ze,W=class extends Le{static get ZERO(){return ze||(ze=new W(0,0,0),Object.freeze(ze)),ze}constructor(t=0,e=0,n=0){super(-0,-0,-0),arguments.length===1&&Lt(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 Gn(this,t)}cross(t){return Un(this,this,t),this.check()}rotateX({radians:t,origin:e=js}){return Bn(this,this,e,t),this.check()}rotateY({radians:t,origin:e=js}){return Vn(this,this,e,t),this.check()}rotateZ({radians:t,origin:e=js}){return jn(this,this,e,t),this.check()}transform(t){return this.transformAsPoint(t)}transformAsPoint(t){return Re(this,this,t),this.check()}transformAsVector(t){return Ne(this,this,t),this.check()}transformByMatrix3(t){return qn(this,this,t),this.check()}transformByMatrix2(t){return Dn(this,this,t),this.check()}transformByQuaternion(t){return $n(this,this,t),this.check()}};var Ce=class extends Nt{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 di(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 Wn(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 Hn(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,L=m*M-y*S,E=p*w-_*g,I=p*M-y*g,N=_*M-y*w,P=b*N-x*I+k*E+v*L-A*O+T*R;return P?(P=1/P,s[0]=(c*N-h*I+f*E)*P,s[1]=(r*I-n*N-i*E)*P,s[2]=(g*T-w*A+M*v)*P,s[3]=(_*A-p*T-y*v)*P,s[4]=(h*L-o*N-f*O)*P,s[5]=(e*N-r*L+i*O)*P,s[6]=(w*k-S*T-M*x)*P,s[7]=(m*T-_*k+y*x)*P,s[8]=(o*I-c*L+f*R)*P,s[9]=(n*L-e*I-i*R)*P,s[10]=(S*A-g*k+M*b)*P,s[11]=(p*k-m*A-y*b)*P,s[12]=(c*O-o*E-h*R)*P,s[13]=(e*E-n*O+r*R)*P,s[14]=(g*x-S*v-w*b)*P,s[15]=(m*v-p*x+_*b)*P,s):null}function Yn(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,L=y*x-S*b+g*M;return h*T-r*R+w*O-_*L}function Gs(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 Xn(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 Kn(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 Zn(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,L,E,I,N,P,q;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,L=r*i*m-o*f,E=i*i*m+h,I=o*i*m+r*f,N=r*o*m+i*f,P=i*o*m-r*f,q=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*L+g*E+x*I,s[5]=_*L+w*E+k*I,s[6]=y*L+M*E+v*I,s[7]=S*L+b*E+A*I,s[8]=p*N+g*P+x*q,s[9]=_*N+w*P+k*q,s[10]=y*N+M*P+v*q,s[11]=S*N+b*P+A*q,t!==s&&(s[12]=t[12],s[13]=t[13],s[14]=t[14],s[15]=t[15]),s)}function Jn(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 Qn(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 tr(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 er(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 sr(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 mi(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 nr=mi;function pi(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 rr=pi;function ir(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?di(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 _i(){let s=new ot(4);return ot!=Float32Array&&(s[0]=0,s[1]=0,s[2]=0,s[3]=0),s}function or(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 Sa=function(){let s=_i();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 Ys;(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"})(Ys||(Ys={}));var gi=45*Math.PI/180,xi=1,Ws=.1,Hs=500,yi=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),tt=class extends Ce{static get IDENTITY(){return ki()}static get ZERO(){return wi()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Ys}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(yi)}fromObject(t){return this.check()}fromQuaternion(t){return er(this,t),this.check()}frustum(t){let{left:e,right:n,bottom:r,top:i,near:o=Ws,far:c=Hs}=t;return c===1/0?vi(this,e,n,r,i,o):sr(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 ir(this,e,n,r),this.check()}ortho(t){let{left:e,right:n,bottom:r,top:i,near:o=Ws,far:c=Hs}=t;return rr(this,e,n,r,i,o,c),this.check()}orthographic(t){let{fovy:e=gi,aspect:n=xi,focalDistance:r=1,near:i=Ws,far:o=Hs}=t;ar(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 ar(e),nr(this,e,n,r,i),this.check()}determinant(){return Yn(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 Wn(this,this),this.check()}invert(){return Hn(this,this),this.check()}multiplyLeft(t){return Gs(this,t,this),this.check()}multiplyRight(t){return Gs(this,this,t),this.check()}rotateX(t){return Jn(this,this,t),this.check()}rotateY(t){return Qn(this,this,t),this.check()}rotateZ(t){return tr(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,e){return Zn(this,this,t,e),this.check()}scale(t){return Kn(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return Xn(this,this,t),this.check()}transform(t,e){return t.length===4?(e=or(e||[-0,-0,-0,-0],t,this),Ie(e,4),e):this.transformAsPoint(t,e)}transformAsPoint(t,e){let{length:n}=t,r;switch(n){case 2:r=Cn(e||[-0,-0],t,this);break;case 3:r=Re(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Ie(r,t.length),r}transformAsVector(t,e){let n;switch(t.length){case 2:n=Fn(e||[-0,-0],t,this);break;case 3:n=Ne(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Ie(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])}},Fe,De;function wi(){return Fe||(Fe=new tt([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Fe)),Fe}function ki(){return De||(De=new tt,Object.freeze(De)),De}function ar(s){if(s>Math.PI*2)throw Error("expected radians")}function vi(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 Jt=$(D(),1);var Xs={};function C(s="id"){Xs[s]=Xs[s]||1;let t=Xs[s]++;return`${s}-${t}`}var zt=class{id;userData={};topology;bufferLayout=[];vertexCount;indices;attributes;constructor(t){if(this.id=t.id||C("geometry"),this.topology=t.topology,this.indices=t.indices||null,this.attributes=t.attributes,this.vertexCount=t.vertexCount,this.bufferLayout=t.bufferLayout||[],this.indices&&!(this.indices.usage&Jt.Buffer.INDEX))throw new Error("Index buffer must have INDEX usage")}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||null}_calculateVertexCount(t){return t.byteLength/12}};function cr(s,t){if(t instanceof zt)return t;let e=bi(s,t),{attributes:n,bufferLayout:r}=Mi(s,t);return new zt({topology:t.topology||"triangle-list",bufferLayout:r,vertexCount:t.vertexCount,indices:e,attributes:n})}function bi(s,t){if(!t.indices)return;let e=t.indices.value;return s.createBuffer({usage:Jt.Buffer.INDEX,data:e})}function Mi(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}if(o){n[c]=s.createBuffer({data:o.value,id:`${i}-buffer`});let{value:h,size:f,normalized:m}=o;e.push({name:c,format:(0,Jt.getVertexFormatFromAttribute)(h,f,m)})}}let r=t._calculateVertexCount(t.attributes,t.indices);return{attributes:n,bufferLayout:e,vertexCount:r}}var Ct=$(D(),1);var Ks=class{static getDefaultPipelineFactory(t){return t._lumaData.defaultPipelineFactory=t._lumaData.defaultPipelineFactory||new Ks(t),t._lumaData.defaultPipelineFactory}device;destroyPolicy;_hashCounter=0;_hashes={};_renderPipelineCache={};_computePipelineCache={};constructor(t){this.device=t,this.destroyPolicy=t.props._factoryDestroyPolicy}createRenderPipeline(t){let e={...Ct.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={...Ct.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 Ct.ComputePipeline?this._computePipelineCache:this._renderPipelineCache;n[e].useCount--,n[e].useCount===0&&this.destroyPolicy==="unused"&&(n[e].pipeline.destroy(),delete n[e])}_hashComputePipeline(t){return`${this._getHash(t.shader.source)}`}_hashRenderPipeline(t){let e=t.vs?this._getHash(t.vs.source):0,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]}},at=Ks;et(at,"defaultProps",{...Ct.RenderPipeline.defaultProps});var hr=$(D(),1);var Zs=class{static getDefaultShaderFactory(t){return t._lumaData.defaultShaderFactory||=new Zs(t),t._lumaData.defaultShaderFactory}device;destroyPolicy;_cache={};constructor(t){this.device=t,this.destroyPolicy=t.props._factoryDestroyPolicy}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&&this.destroyPolicy==="unused"&&(delete this._cache[e],n.shader.destroy()))}_hashShader(t){return`${t.stage}:${t.source}`}},ct=Zs;et(ct,"defaultProps",{...hr.Shader.defaultProps});function lr(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 U=null,Js=null;function ur(s,{id:t,minimap:e,opaque:n,top:r="0",left:i="0",rgbaScale:o=1}){U||(U=document.createElement("canvas"),U.id=t,U.title=t,U.style.zIndex="100",U.style.position="absolute",U.style.top=r,U.style.left=i,U.style.border="blue 1px solid",U.style.transform="scaleY(-1)",document.body.appendChild(U),Js=U.getContext("2d")),(U.width!==s.width||U.height!==s.height)&&(U.width=s.width/2,U.height=s.height/2,U.style.width="400px",U.style.height="400px");let c=s.device.readPixelsToArrayWebGL(s),h=Js?.createImageData(s.width,s.height);if(h){for(let m=0;m<c.length;m+=4)h.data[0+m+0]=c[m+0]*o,h.data[0+m+1]=c[m+1]*o,h.data[0+m+2]=c[m+2]*o,h.data[0+m+3]=n?255:c[m+3]*o;Js?.putImageData(h,0,0)}}function Ue(s,t,e){if(s===t)return!0;if(!e||!s||!t)return!1;if(Array.isArray(s)){if(!Array.isArray(t)||s.length!==t.length)return!1;for(let n=0;n<s.length;n++)if(!Ue(s[n],t[n],e-1))return!1;return!0}if(Array.isArray(t))return!1;if(typeof s=="object"&&typeof t=="object"){let n=Object.keys(s),r=Object.keys(t);if(n.length!==r.length)return!1;for(let i of n)if(!t.hasOwnProperty(i)||!Ue(s[i],t[i],e-1))return!1;return!0}return!1}function fr(s){return ArrayBuffer.isView(s)&&!(s instanceof DataView)?s:null}function Qt(s){return Array.isArray(s)?s.length===0||typeof s[0]=="number"?s:null:fr(s)}function Si(s){return Qt(s)!==null||typeof s=="number"||typeof s=="boolean"}function qe(s){let t={bindings:{},uniforms:{}};return Object.keys(s).forEach(e=>{let n=s[e];Si(n)?t.uniforms[e]=n:t.bindings[e]=n}),t}var Qs=$(D(),1);var pt=class{modules;moduleUniforms;moduleBindings;constructor(t){let e=Mt(Object.values(t).filter(n=>n.dependencies));for(let n of e)t[n.name]=n;Qs.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){Qs.log.warn(`Module ${e} not found`)();continue}let o=this.moduleUniforms[n],c=this.moduleBindings[n],h=i.getUniforms?.(r,this.moduleUniforms[n]);h||={...this.moduleUniforms[n],...r};let{uniforms:f,bindings:m}=qe(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 tn="";function dr(s){tn=s}async function $e(s,t){let e=new Image;return e.crossOrigin=t?.crossOrigin||"anonymous",e.src=s.startsWith("http")?s:tn+s,await e.decode(),await createImageBitmap(e)}async function mr(s,t){return await new Promise((e,n)=>{try{let r=new Image;r.onload=()=>e(r),r.onerror=()=>n(new Error(`Could not load image ${s}.`)),r.crossOrigin=t?.crossOrigin||"anonymous",r.src=s.startsWith("http")?s:tn+s}catch(r){n(r)}})}var wt=class{device;texture;sampler;view;ready;isReady=!1;destroyed=!1;resolveReady=()=>{};rejectReady=()=>{};constructor(t,e){this.device=t,typeof e?.data=="string"&&e.dimension==="2d"&&(e={...e,data:$e(e.data)}),this.ready=new Promise((n,r)=>{this.resolveReady=()=>{this.isReady=!0,n()},this.rejectReady=r}),this.initAsync(e)}async initAsync(t){let e,n,r=t.data,i=await pr(r).then(e,n);if(this.destroyed)return;let o={...t,data:i};this.texture=this.device.createTexture(o),this.sampler=this.texture.sampler,this.view=this.texture.view,this.isReady=!0}destroy(){this.texture&&(this.texture.destroy(),this.texture=null),this.destroyed=!0}};async function pr(s){if(s=await s,Array.isArray(s))return await Promise.all(s.map(pr));if(s&&typeof s=="object"&&s.constructor===Object){let t=s,e=await Promise.all(Object.values(t)),n=Object.keys(t),r={};for(let i=0;i<n.length;i++)r[n[i]]=e[i];return r}return s}var Ft=2,Ai=1e4,en=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={...en.defaultProps,...e},e=this.props,this.id=e.id||C("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 pt(n));let r=Ei(t),i=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];if(this.device.type==="webgpu"&&this.props.source){this.props.shaderLayout||=Zt(this.props.source);let{source:c,getUniforms:h}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:r,...this.props,modules:i});this.source=c,this._getModuleUniforms=h}else{let{vs:c,fs:h,getUniforms:f}=this.props.shaderAssembler.assembleGLSLShaderPair({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||at.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||ct.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();let n=this._getBindings();this.pipeline.setBindings(n,{disableWarnings:this.props.disableWarnings}),xr(this.uniforms)||this.pipeline.setUniformsWebGL(this.uniforms);let{indexBuffer:r}=this.vertexArray,i=r?r.byteLength/(r.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:i,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&&cr(this.device,t);e&&(this.setTopology(e.topology||"triangle-list"),this.bufferLayout=_r(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?_r(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){Ue(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 Be.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&&j.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=>gr(h).includes(n));if(!i){j.log.warn(`Model(${this.id}): Missing layout for buffer "${n}".`)();continue}let o=gr(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)&&j.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)||j.log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${n}"`)()}this.setNeedsRedraw("constants")}setUniforms(t){xr(t)||(this.pipeline.setUniformsWebGL(t),Object.assign(this.uniforms,t)),this.setNeedsRedraw("uniforms")}updateModuleSettings(t){let{bindings:e,uniforms:n}=qe(this._getModuleUniforms(t));Object.assign(this.bindings,e),Object.assign(this.uniforms,n),this.setNeedsRedraw("moduleSettings")}_getBindings(){return Object.entries(this.bindings).reduce((t,[e,n])=>(n instanceof wt?n.isReady&&(t[e]=n.texture):t[e]=n,t),{})}_getBindingsUpdateTimestamp(){let t=0;for(let e of Object.values(this.bindings))e instanceof ht.TextureView?t=Math.max(t,e.texture.updateTimestamp):e instanceof ht.Buffer||e instanceof ht.Texture?t=Math.max(t,e.updateTimestamp):e instanceof wt?t=e.texture?Math.max(t,e.texture.updateTimestamp):1/0:e instanceof ht.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&&(j.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,bindings:this._getBindings(),vs:n,fs:r}),this._attributeInfos=(0,Ve.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=j.log.level>3?0:Ai;j.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,j.log.group(Ft,`>>> DRAWING MODEL ${this.id}`,{collapsed:j.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=lr(this.pipeline.shaderLayout,this.id);j.log.table(Ft,t)();let e=this.shaderInputs.getDebugTable();for(let[r,i]of Object.entries(this.uniforms))e[r]={value:i};j.log.table(Ft,e)();let n=this._getAttributeDebugTable();j.log.table(Ft,this._attributeInfos)(),j.log.table(Ft,n)(),j.log.groupEnd(Ft)(),this._logOpen=!1}}_drawCount=0;_logFramebuffer(t){let e=j.log.get("framebuffer");if(this._drawCount++,!e||this._drawCount++>3&&this._drawCount%60)return;let n=t.props.framebuffer;n&&ur(n,{id:n.id,minimap:!0})}_getAttributeDebugTable(){let t={};for(let[e,n]of Object.entries(this._attributeInfos)){let r=this.vertexArray.attributes[n.location];t[n.location]={name:e,type:n.shaderType,values:r?this._getBufferOrConstantValues(r,n.bufferDataType):"null"}}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,Ve.getTypedArrayFromDataType)(e);return(t instanceof ht.Buffer?new n(t.debugData):t).toString()}},Z=en;et(Z,"defaultProps",{...Be.RenderPipeline.defaultProps,source:void 0,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:ut.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0});function _r(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 Ei(s){return{type:s.type,shaderLanguage:s.info.shadingLanguage,shaderLanguageVersion:s.info.shadingLanguageVersion,gpu:s.info.gpu,features:s.features}}function gr(s){return s.attributes?s.attributes?.map(t=>t.attribute):[s.name]}function xr(s){let t=!0;for(let e in s){t=!1;break}return t}var yr=$(D(),1);var Dt=class{device;model;transformFeedback;static isSupported(t){return t?.info?.type==="webgl"}constructor(t,e=Z.defaultProps){if(!Dt.isSupported(t))throw new Error("BufferTransform not yet implemented on WebGPU");this.device=t,this.model=new Z(this.device,{id:e.id||"buffer-transform-model",fs:e.fs||Gt(),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)throw new Error("BufferTransform#getBuffer");if(e instanceof yr.Buffer)return e.readAsync();let{buffer:n,byteOffset:r=0,byteLength:i=n.byteLength}=e;return n.readAsync(r,i)}};var Ti="transform_output",je=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 Z(this.device,{id:e.id||"texture-transform-model",fs:e.fs||Gt({input:e.targetTextureVarying,inputChannels:e.targetTextureChannels,output:Ti}),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 G=class{id;topology;vertexCount;indices;attributes;userData={};constructor(t){let{attributes:e={},indices:n=null,vertexCount:r=null}=t;this.id=t.id||C("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;if(!ArrayBuffer.isView(c.value))throw new Error(`${this._print(i)}: must be typed array or object with value as typed array`);if((i==="POSITION"||i==="positions")&&!c.size&&(c.size=3),i==="indices"){if(this.indices)throw new Error("Multiple indices detected");this.indices=c}else 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!==void 0&&o>=1&&(n=Math.min(n,i.length/o))}return n}};var Oi=`#version 300 es
|
|
102
|
-
in vec2 aClipSpacePosition;
|
|
103
|
-
in vec2 aTexCoord;
|
|
104
|
-
in vec2 aCoordinate;
|
|
7
|
+
"use strict";var __exports__=(()=>{var Ui=Object.create;var bt=Object.defineProperty;var $i=Object.getOwnPropertyDescriptor;var ji=Object.getOwnPropertyNames;var Gi=Object.getPrototypeOf,Vi=Object.prototype.hasOwnProperty;var qi=(i,t,e)=>t in i?bt(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var Le=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),Wi=(i,t)=>{for(var e in t)bt(i,e,{get:t[e],enumerable:!0})},Et=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ji(t))!Vi.call(i,n)&&n!==e&&bt(i,n,{get:()=>t[n],enumerable:!(s=$i(t,n))||s.enumerable});return i},kt=(i,t,e)=>(Et(i,t,"default"),e&&Et(e,t,"default")),L=(i,t,e)=>(e=i!=null?Ui(Gi(i)):{},Et(t||!i||!i.__esModule?bt(e,"default",{value:i,enumerable:!0}):e,i)),Hi=i=>Et(bt({},"__esModule",{value:!0}),i);var V=(i,t,e)=>(qi(i,typeof t!="symbol"?t+"":t,e),e);var j=Le((rn,Ne)=>{Ne.exports=globalThis.luma});var rt=Le((wn,Be)=>{Be.exports=globalThis.luma});var St={};Wi(St,{AnimationLoop:()=>ht,AnimationLoopTemplate:()=>Ft,AsyncTexture:()=>it,BackgroundTextureModel:()=>at,BufferTransform:()=>At,ClipSpace:()=>J,Computation:()=>Pt,ConeGeometry:()=>ee,CubeGeometry:()=>ie,CylinderGeometry:()=>se,GPUGeometry:()=>lt,Geometry:()=>D,GroupNode:()=>mt,IcoSphereGeometry:()=>ne,KeyFrames:()=>Nt,LegacyPickingManager:()=>de,Model:()=>q,ModelNode:()=>te,PickingManager:()=>It,PipelineFactory:()=>Z,PlaneGeometry:()=>re,ScenegraphNode:()=>et,ShaderFactory:()=>Q,ShaderInputs:()=>Y,ShaderPassRenderer:()=>ce,SphereGeometry:()=>oe,Swap:()=>gt,SwapBuffers:()=>ae,SwapFramebuffers:()=>xt,TextureTransform:()=>qt,Timeline:()=>Lt,TruncatedConeGeometry:()=>st,cancelAnimationFramePolyfill:()=>Dt,colorPicking:()=>Ni,indexPicking:()=>Li,loadImage:()=>Ye,loadImageBitmap:()=>jt,makeAnimationLoop:()=>De,makeRandomGenerator:()=>Ri,requestAnimationFramePolyfill:()=>zt,setPathPrefix:()=>He});kt(St,L(j(),1));var Yi=1,Xi=1,Lt=class{time=0;channels=new Map;animations=new Map;playing=!1;lastEngineTime=-1;constructor(){}addChannel(t){let{delay:e=0,duration:s=Number.POSITIVE_INFINITY,rate:n=1,repeat:r=1}=t,o=Yi++,a={time:0,delay:e,duration:s,rate:n,repeat:r};return this._setChannelTime(a,this.time),this.channels.set(o,a),o}removeChannel(t){this.channels.delete(t);for(let[e,s]of this.animations)s.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 n of e)this._setChannelTime(n,this.time);let s=this.animations.values();for(let n of s){let{animation:r,channel:o}=n;r.setTime(this.getTime(o))}}play(){this.playing=!0}pause(){this.playing=!1,this.lastEngineTime=-1}reset(){this.setTime(0)}attachAnimation(t,e){let s=Xi++;return this.animations.set(s,{animation:t,channel:e}),t.setTime(this.getTime(e)),s}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 s=e-t.delay,n=t.duration*t.repeat;s>=n?t.time=t.duration*t.rate:(t.time=Math.max(0,s)%t.duration,t.time*=t.rate)}};var Nt=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 s=0;s<e;++s)this.times[s]=t[s][0],this.values[s]=t[s][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,s=this.times.length;for(e=0;e<s-2&&!(this.times[e+1]>t);++e);this.startIndex=e,this.endIndex=e+1;let n=this.times[this.startIndex],r=this.times[this.endIndex];this.factor=Math.min(Math.max(0,(t-n)/(r-n)),1)}};var Ft=class{constructor(t){}async onInitialize(t){return null}};var Fe=L(j(),1);function zt(i){return typeof window<"u"&&window.requestAnimationFrame?window.requestAnimationFrame(i):setTimeout(i,1e3/60)}function Dt(i){return typeof window<"u"&&window.cancelAnimationFrame?window.cancelAnimationFrame(i):clearTimeout(i)}function Mt(){let i;if(typeof window<"u"&&window.performance)i=window.performance.now();else if(typeof process<"u"&&process.hrtime){let t=process.hrtime();i=t[0]*1e3+t[1]/1e6}else i=Date.now();return i}var nt=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=Mt(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(Mt()-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 ct=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:s}=t,n=this.stats[e];return n||(t instanceof nt?n=t:n=new nt(e,s),this.stats[e]=n),n}};var Ki=0,Zi={device:null,onAddHTML:()=>"",onInitialize:async()=>null,onRender:()=>{},onFinalize:()=>{},onError:i=>console.error(i),stats:Fe.luma.stats.get(`animation-loop-${Ki++}`),useDevicePixels:!0,autoResizeViewport:!1,autoResizeDrawingBuffer:!1},ht=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;_error=null;constructor(t){if(this.props={...Zi,...t},t=this.props,!t.device)throw new Error("No device provided");let{useDevicePixels:e=!0}=this.props;this.stats=t.stats||new ct({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()}setError(t){if(this.props.onError(t),this._error=Error(),this.device?.canvasContext?.canvas instanceof HTMLCanvasElement){let s=document.createElement("h1");s.innerHTML=t.message,s.style.position="absolute",s.style.top="20%",s.style.left="10px",s.style.color="black",s.style.backgroundColor="red",document.body.appendChild(s)}}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._error&&this.props.onFinalize(this.animationProps),this._cancelAnimationFrame(),this._nextFramePromise=null,this._resolveNextFrame=null,this._running=!1),this}redraw(){return this.device?.isLost||this._error?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=zt(this._animationFrame.bind(this)))}_cancelAnimationFrame(){this._animationFrameId!==null&&(Dt(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(){let t=this.device?.canvasContext?.canvas;if(!this.device||!t)throw new Error("loop");this.animationProps={animationLoop:this,device:this.device,canvas:t,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:s}=this._getSizeAndAspect();(t!==this.animationProps.width||e!==this.animationProps.height)&&this.setNeedsRedraw("drawing buffer resized"),s!==this.animationProps.aspect&&this.setNeedsRedraw("drawing buffer aspect changed"),this.animationProps.width=t,this.animationProps.height=e,this.animationProps.aspect=s,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 s=this.props.onAddHTML(e);s&&(e.innerHTML=s)}}_getSizeAndAspect(){if(!this.device)return{width:1,height:1,aspect:1};let[t,e]=this.device?.canvasContext?.getPixelSize()||[1,1],s=1,n=this.device?.canvasContext?.canvas;return n&&n.clientHeight?s=n.clientWidth/n.clientHeight:t>0&&e>0&&(s=t/e),{width:t,height:e,aspect:s}}_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 ze=L(j(),1);function De(i,t){let e=null,s=t?.device||ze.luma.createDevice({id:"animation-loop",adapters:t?.adapters,createCanvasContext:!0}),n=new ht({...t,device:s,async onInitialize(r){return e=new i(r),await e?.onInitialize(r)},onRender:r=>e?.onRender(r),onFinalize:r=>e?.onFinalize(r)});return n.getInfo=()=>this.AnimationLoopTemplateCtor.info,n}var P=L(j(),1),Gt=L(rt(),1);var vt=L(j(),1);var ue={};function O(i="id"){ue[i]=ue[i]||1;let t=ue[i]++;return`${i}-${t}`}var lt=class{id;userData={};topology;bufferLayout=[];vertexCount;indices;attributes;constructor(t){if(this.id=t.id||O("geometry"),this.topology=t.topology,this.indices=t.indices||null,this.attributes=t.attributes,this.vertexCount=t.vertexCount,this.bufferLayout=t.bufferLayout||[],this.indices&&!(this.indices.usage&vt.Buffer.INDEX))throw new Error("Index buffer must have INDEX usage")}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||null}_calculateVertexCount(t){return t.byteLength/12}};function Ue(i,t){if(t instanceof lt)return t;let e=Qi(i,t),{attributes:s,bufferLayout:n}=Ji(i,t);return new lt({topology:t.topology||"triangle-list",bufferLayout:n,vertexCount:t.vertexCount,indices:e,attributes:s})}function Qi(i,t){if(!t.indices)return;let e=t.indices.value;return i.createBuffer({usage:vt.Buffer.INDEX,data:e})}function Ji(i,t){let e=[],s={};for(let[r,o]of Object.entries(t.attributes)){let a=r;switch(r){case"POSITION":a="positions";break;case"NORMAL":a="normals";break;case"TEXCOORD_0":a="texCoords";break;case"COLOR_0":a="colors";break}if(o){s[a]=i.createBuffer({data:o.value,id:`${r}-buffer`});let{value:c,size:h,normalized:l}=o;e.push({name:a,format:(0,vt.getVertexFormatFromAttribute)(c,h,l)})}}let n=t._calculateVertexCount(t.attributes,t.indices);return{attributes:s,bufferLayout:e,vertexCount:n}}var ft=L(j(),1);var pe=class{static getDefaultPipelineFactory(t){return t._lumaData.defaultPipelineFactory=t._lumaData.defaultPipelineFactory||new pe(t),t._lumaData.defaultPipelineFactory}device;destroyPolicy;_hashCounter=0;_hashes={};_renderPipelineCache={};_computePipelineCache={};constructor(t){this.device=t,this.destroyPolicy=t.props._factoryDestroyPolicy}createRenderPipeline(t){let e={...ft.RenderPipeline.defaultProps,...t},s=this._hashRenderPipeline(e);if(!this._renderPipelineCache[s]){let n=this.device.createRenderPipeline({...e,id:e.id?`${e.id}-cached`:void 0});n.hash=s,this._renderPipelineCache[s]={pipeline:n,useCount:0}}return this._renderPipelineCache[s].useCount++,this._renderPipelineCache[s].pipeline}createComputePipeline(t){let e={...ft.ComputePipeline.defaultProps,...t},s=this._hashComputePipeline(e);if(!this._computePipelineCache[s]){let n=this.device.createComputePipeline({...e,id:e.id?`${e.id}-cached`:void 0});n.hash=s,this._computePipelineCache[s]={pipeline:n,useCount:0}}return this._computePipelineCache[s].useCount++,this._computePipelineCache[s].pipeline}release(t){let e=t.hash,s=t instanceof ft.ComputePipeline?this._computePipelineCache:this._renderPipelineCache;s[e].useCount--,s[e].useCount===0&&this.destroyPolicy==="unused"&&(s[e].pipeline.destroy(),delete s[e])}_hashComputePipeline(t){return`${this._getHash(t.shader.source)}`}_hashRenderPipeline(t){let e=t.vs?this._getHash(t.vs.source):0,s=t.fs?this._getHash(t.fs.source):0,n="-",r=this._getHash(JSON.stringify(t.bufferLayout));switch(this.device.type){case"webgl":return`${e}/${s}V${n}BL${r}`;default:let o=this._getHash(JSON.stringify(t.parameters));return`${e}/${s}V${n}T${t.topology}P${o}BL${r}`}}_getHash(t){return this._hashes[t]===void 0&&(this._hashes[t]=this._hashCounter++),this._hashes[t]}},Z=pe;V(Z,"defaultProps",{...ft.RenderPipeline.defaultProps});var $e=L(j(),1);var me=class{static getDefaultShaderFactory(t){return t._lumaData.defaultShaderFactory||=new me(t),t._lumaData.defaultShaderFactory}device;destroyPolicy;_cache={};constructor(t){this.device=t,this.destroyPolicy=t.props._factoryDestroyPolicy}createShader(t){let e=this._hashShader(t),s=this._cache[e];if(!s){let n=this.device.createShader({...t,id:t.id?`${t.id}-cached`:void 0});this._cache[e]=s={shader:n,useCount:0}}return s.useCount++,s.shader}release(t){let e=this._hashShader(t),s=this._cache[e];s&&(s.useCount--,s.useCount===0&&this.destroyPolicy==="unused"&&(delete this._cache[e],s.shader.destroy()))}_hashShader(t){return`${t.stage}:${t.source}`}},Q=me;V(Q,"defaultProps",{...$e.Shader.defaultProps});function je(i,t){let e={},s="Values";if(i.attributes.length===0&&!i.varyings?.length)return{"No attributes or varyings":{[s]:"N/A"}};for(let n of i.attributes)if(n){let r=`${n.location} ${n.name}: ${n.type}`;e[`in ${r}`]={[s]:n.stepMode||"vertex"}}for(let n of i.varyings||[]){let r=`${n.location} ${n.name}`;e[`out ${r}`]={[s]:JSON.stringify(n)}}return e}var N=null,ge=null;function Ge(i,{id:t,minimap:e,opaque:s,top:n="0",left:r="0",rgbaScale:o=1}){N||(N=document.createElement("canvas"),N.id=t,N.title=t,N.style.zIndex="100",N.style.position="absolute",N.style.top=n,N.style.left=r,N.style.border="blue 5px solid",N.style.transform="scaleY(-1)",document.body.appendChild(N),ge=N.getContext("2d")),(N.width!==i.width||N.height!==i.height)&&(N.width=i.width/2,N.height=i.height/2,N.style.width="400px",N.style.height="400px");let a=i.device.readPixelsToArrayWebGL(i),c=ge?.createImageData(i.width,i.height);if(c){for(let l=0;l<a.length;l+=4)c.data[0+l+0]=a[l+0]*o,c.data[0+l+1]=a[l+1]*o,c.data[0+l+2]=a[l+2]*o,c.data[0+l+3]=s?255:a[l+3]*o;ge?.putImageData(c,0,0)}}function Bt(i,t,e){if(i===t)return!0;if(!e||!i||!t)return!1;if(Array.isArray(i)){if(!Array.isArray(t)||i.length!==t.length)return!1;for(let s=0;s<i.length;s++)if(!Bt(i[s],t[s],e-1))return!1;return!0}if(Array.isArray(t))return!1;if(typeof i=="object"&&typeof t=="object"){let s=Object.keys(i),n=Object.keys(t);if(s.length!==n.length)return!1;for(let r of s)if(!t.hasOwnProperty(r)||!Bt(i[r],t[r],e-1))return!1;return!0}return!1}var $t=L(j(),1),We=L(rt(),1);function Ve(i){return ArrayBuffer.isView(i)&&!(i instanceof DataView)}function qe(i){return Array.isArray(i)?i.length===0||typeof i[0]=="number":!1}function _t(i){return Ve(i)||qe(i)}function ts(i){return _t(i)||typeof i=="number"||typeof i=="boolean"}function Ut(i){let t={bindings:{},uniforms:{}};return Object.keys(i).forEach(e=>{let s=i[e];ts(s)?t.uniforms[e]=s:t.bindings[e]=s}),t}var Y=class{modules;moduleUniforms;moduleBindings;constructor(t){let e=(0,We.getShaderModuleDependencies)(Object.values(t).filter(s=>s.dependencies));for(let s of e)t[s.name]=s;$t.log.log(1,"Creating ShaderInputs with modules",Object.keys(t))(),this.modules=t,this.moduleUniforms={},this.moduleBindings={};for(let[s,n]of Object.entries(t))this._addModule(n),n.name&&s!==n.name&&$t.log.warn(`Module name: ${s} vs ${n.name}`)()}destroy(){}setProps(t){for(let e of Object.keys(t)){let s=e,n=t[s]||{},r=this.modules[s];if(!r){$t.log.warn(`Module ${e} not found`)();continue}let o=this.moduleUniforms[s],a=this.moduleBindings[s],c=r.getUniforms?.(n,o)||n,{uniforms:h,bindings:l}=Ut(c);this.moduleUniforms[s]={...o,...h},this.moduleBindings[s]={...a,...l}}}getModules(){return Object.values(this.modules)}getUniformValues(){return this.moduleUniforms}getBindingValues(){let t={};for(let e of Object.values(this.moduleBindings))Object.assign(t,e);return t}getDebugTable(){let t={};for(let[e,s]of Object.entries(this.moduleUniforms))for(let[n,r]of Object.entries(s))t[`${e}.${n}`]={type:this.modules[e].uniformTypes?.[n],value:String(r)};return t}_addModule(t){let e=t.name;this.moduleUniforms[e]=t.defaultUniforms||{},this.moduleBindings[e]={}}};var xe="";function He(i){xe=i}async function jt(i,t){let e=new Image;return e.crossOrigin=t?.crossOrigin||"anonymous",e.src=i.startsWith("http")?i:xe+i,await e.decode(),t?await createImageBitmap(e,t):await createImageBitmap(e)}async function Ye(i,t){return await new Promise((e,s)=>{try{let n=new Image;n.onload=()=>e(n),n.onerror=()=>s(new Error(`Could not load image ${i}.`)),n.crossOrigin=t?.crossOrigin||"anonymous",n.src=i.startsWith("http")?i:xe+i}catch(n){s(n)}})}var it=class{device;id;texture;sampler;view;ready;isReady=!1;destroyed=!1;resolveReady=()=>{};rejectReady=()=>{};get[Symbol.toStringTag](){return"AsyncTexture"}toString(){return`AsyncTexture:"${this.id}"(${this.isReady?"ready":"loading"})`}constructor(t,e){this.device=t,this.id=e.id||O("async-texture"),typeof e?.data=="string"&&e.dimension==="2d"&&(e={...e,data:jt(e.data)}),this.ready=new Promise((s,n)=>{this.resolveReady=()=>{this.isReady=!0,s()},this.rejectReady=n}),this.initAsync(e)}async initAsync(t){let e,s,n=t.data,r=await Xe(n).then(e,s);if(this.destroyed)return;let o={...t,data:r};this.texture=this.device.createTexture(o),this.sampler=this.texture.sampler,this.view=this.texture.view,this.isReady=!0}destroy(){this.texture&&(this.texture.destroy(),this.texture=null),this.destroyed=!0}resize(t){if(!this.isReady)throw new Error("Cannot resize texture before it is ready");if(t.width===this.texture.width&&t.height===this.texture.height)return!1;if(this.texture){let e=this.texture;this.texture=e.clone(t),e.destroy()}return!0}};async function Xe(i){if(i=await i,Array.isArray(i))return await Promise.all(i.map(Xe));if(i&&typeof i=="object"&&i.constructor===Object){let t=i,e=await Promise.all(Object.values(t)),s=Object.keys(t),n={};for(let r=0;r<s.length;r++)n[s[r]]=e[r];return n}return i}var ot=2,es=1e4,be=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;get[Symbol.toStringTag](){return"Model"}toString(){return`Model(${this.id})`}constructor(t,e){this.props={...be.defaultProps,...e},e=this.props,this.id=e.id||O("model"),this.device=t,Object.assign(this.userData,e.userData);let s=Object.fromEntries(this.props.modules?.map(a=>[a.name,a])||[]);this.setShaderInputs(e.shaderInputs||new Y(s));let n=ss(t),r=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];if(this.device.type==="webgpu"&&this.props.source){this.props.shaderLayout||=(0,Gt.getShaderLayoutFromWGSL)(this.props.source);let{source:a,getUniforms:c}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:n,...this.props,modules:r});this.source=a,this._getModuleUniforms=c}else{let{vs:a,fs:c,getUniforms:h}=this.props.shaderAssembler.assembleGLSLShaderPair({platformInfo:n,...this.props,modules:r});this.vs=a,this.fs=c,this._getModuleUniforms=h}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||Z.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||Q.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.setUniformsWebGL(e.uniforms),e.moduleSettings&&this.updateModuleSettingsWebGL(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){let e=this._areBindingsLoading();if(e)return P.log.info(ot,`>>> DRAWING ABORTED ${this.id}: ${e} not loaded`)(),!1;try{t.pushDebugGroup(`${this}.predraw(${t})`),this.predraw()}finally{t.popDebugGroup()}let s;try{t.pushDebugGroup(`${this}.draw(${t})`),this._logDrawCallStart(),this.pipeline=this._updatePipeline();let n=this._getBindings();this.pipeline.setBindings(n,{disableWarnings:this.props.disableWarnings}),ye(this.uniforms)||this.pipeline.setUniformsWebGL(this.uniforms);let{indexBuffer:r}=this.vertexArray,o=r?r.byteLength/(r.indexType==="uint32"?4:2):void 0;s=this.pipeline.draw({renderPass:t,vertexArray:this.vertexArray,isInstanced:this.isInstanced,vertexCount:this.vertexCount,instanceCount:this.instanceCount,indexCount:o,transformFeedback:this.transformFeedback||void 0,parameters:this.parameters,topology:this.topology})}finally{t.popDebugGroup(),this._logDrawCallEnd()}return this._logFramebuffer(t),s?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):this._needsRedraw="waiting for resource initialization",s}setGeometry(t){this._gpuGeometry?.destroy();let e=t&&Ue(this.device,t);if(e){this.setTopology(e.topology||"triangle-list");let s=new P._BufferLayoutHelper(this.bufferLayout);this.bufferLayout=s.mergeBufferLayouts(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){let e=new P._BufferLayoutHelper(this.bufferLayout);this.bufferLayout=this._gpuGeometry?e.mergeBufferLayouts(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){Bt(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 P.UniformStore(this.shaderInputs.modules);for(let[e,s]of Object.entries(this.shaderInputs.modules))if(is(s)){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.getBindingValues()),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){let s=e?.disableWarnings??this.props.disableWarnings;t.indices&&P.log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)();let n=new P._BufferLayoutHelper(this.bufferLayout);for(let[r,o]of Object.entries(t)){let a=n.getBufferLayout(r);if(!a){s||P.log.warn(`Model(${this.id}): Missing layout for buffer "${r}".`)();continue}let c=n.getAttributeNamesForBuffer(a),h=!1;for(let l of c){let f=this._attributeInfos[l];f&&(this.vertexArray.setBuffer(f.location,o),h=!0)}!h&&!s&&P.log.warn(`Model(${this.id}): Ignoring buffer "${o.id}" for unknown attribute "${r}"`)()}this.setNeedsRedraw("attributes")}setConstantAttributes(t,e){for(let[s,n]of Object.entries(t)){let r=this._attributeInfos[s];r?this.vertexArray.setConstantWebGL(r.location,n):(e?.disableWarnings??this.props.disableWarnings)||P.log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${s}"`)()}this.setNeedsRedraw("constants")}setUniformsWebGL(t){ye(t)||(this.pipeline.setUniformsWebGL(t),Object.assign(this.uniforms,t)),this.setNeedsRedraw("uniforms")}updateModuleSettingsWebGL(t){let{bindings:e,uniforms:s}=Ut(this._getModuleUniforms(t));Object.assign(this.bindings,e),Object.assign(this.uniforms,s),this.setNeedsRedraw("moduleSettings")}_areBindingsLoading(){for(let t of Object.values(this.bindings))if(t instanceof it&&!t.isReady)return t.id;return!1}_getBindings(){let t={};for(let[e,s]of Object.entries(this.bindings))s instanceof it?s.isReady&&(t[e]=s.texture):t[e]=s;return t}_getBindingsUpdateTimestamp(){let t=0;for(let e of Object.values(this.bindings))e instanceof P.TextureView?t=Math.max(t,e.texture.updateTimestamp):e instanceof P.Buffer||e instanceof P.Texture?t=Math.max(t,e.updateTimestamp):e instanceof it?t=e.texture?Math.max(t,e.texture.updateTimestamp):1/0:e instanceof P.Sampler||(t=Math.max(t,e.buffer.updateTimestamp));return t}_setGeometryAttributes(t){let e={...t.attributes};for(let[s]of Object.entries(e))!this.pipeline.shaderLayout.attributes.find(n=>n.name===s)&&s!=="positions"&&delete e[s];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&&(P.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),t=this.pipeline.vs,e=this.pipeline.fs),this._pipelineNeedsUpdate=!1;let s=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:"vertex",source:this.source||this.vs,debugShaders:this.props.debugShaders}),n=null;this.source?n=s:this.fs&&(n=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"fragment",source:this.source||this.fs,debugShaders:this.props.debugShaders})),this.pipeline=this.pipelineFactory.createRenderPipeline({...this.props,bufferLayout:this.bufferLayout,topology:this.topology,parameters:this.parameters,bindings:this._getBindings(),vs:s,fs:n}),this._attributeInfos=(0,P.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=P.log.level>3?0:es;P.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,P.log.group(ot,`>>> DRAWING MODEL ${this.id}`,{collapsed:P.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=je(this.pipeline.shaderLayout,this.id);P.log.table(ot,t)();let e=this.shaderInputs.getDebugTable();for(let[n,r]of Object.entries(this.uniforms))e[n]={value:r};P.log.table(ot,e)();let s=this._getAttributeDebugTable();P.log.table(ot,this._attributeInfos)(),P.log.table(ot,s)(),P.log.groupEnd(ot)(),this._logOpen=!1}}_drawCount=0;_logFramebuffer(t){let e=this.device.props.debugFramebuffers;if(this._drawCount++,!e)return;let s=t.props.framebuffer;s&&Ge(s,{id:s.id,minimap:!0})}_getAttributeDebugTable(){let t={};for(let[e,s]of Object.entries(this._attributeInfos)){let n=this.vertexArray.attributes[s.location];t[s.location]={name:e,type:s.shaderType,values:n?this._getBufferOrConstantValues(n,s.bufferDataType):"null"}}if(this.vertexArray.indexBuffer){let{indexBuffer:e}=this.vertexArray,s=e.indexType==="uint32"?new Uint32Array(e.debugData):new Uint16Array(e.debugData);t.indices={name:"indices",type:e.indexType,values:s.toString()}}return t}_getBufferOrConstantValues(t,e){let s=(0,P.getTypedArrayFromDataType)(e);return(t instanceof P.Buffer?new s(t.debugData):t).toString()}},q=be;V(q,"defaultProps",{...P.RenderPipeline.defaultProps,source:void 0,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:Gt.ShaderAssembler.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0});function is(i){return Boolean(i.uniformTypes&&!ye(i.uniformTypes))}function ss(i){return{type:i.type,shaderLanguage:i.info.shadingLanguage,shaderLanguageVersion:i.info.shadingLanguageVersion,gpu:i.info.gpu,features:i.features}}function ye(i){for(let t in i)return!1;return!0}var Ke=L(j(),1),Ze=L(rt(),1);var Vt=class{device;model;transformFeedback;static isSupported(t){return t?.info?.type==="webgl"}constructor(t,e=Vt.defaultProps){if(!Vt.isSupported(t))throw new Error("BufferTransform not yet implemented on WebGPU");this.device=t,this.model=new q(this.device,{id:e.id||"buffer-transform-model",fs:e.fs||(0,Ze.getPassthroughFS)(),topology:e.topology||"point-list",varyings:e.outputs||e.varyings,...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){t?.inputBuffers&&this.model.setAttributes(t.inputBuffers),t?.outputBuffers&&this.transformFeedback.setBuffers(t.outputBuffers);let e=this.device.beginRenderPass(t);this.model.draw(e),e.end()}getBuffer(t){return this.transformFeedback.getBuffer(t)}readAsync(t){let e=this.getBuffer(t);if(!e)throw new Error("BufferTransform#getBuffer");if(e instanceof Ke.Buffer)return e.readAsync();let{buffer:s,byteOffset:n=0,byteLength:r=s.byteLength}=e;return s.readAsync(n,r)}},At=Vt;V(At,"defaultProps",{...q.defaultProps,outputs:void 0,feedbackBuffers:void 0});var Qe=L(rt(),1),ns="transform_output",qt=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 q(this.device,{id:e.id||"texture-transform-model",fs:e.fs||(0,Qe.getPassthroughFS)({input:e.targetTextureVarying,inputChannels:e.targetTextureChannels,output:ns}),vertexCount:e.vertexCount,...e}),this._initialize(e),Object.seal(this)}destroy(){this.model.destroy();for(let t of this.bindings)t.framebuffer?.destroy()}delete(){this.destroy()}run(t){let{framebuffer:e}=this.bindings[this.currentIndex],s=this.device.beginRenderPass({framebuffer:e,...t});this.model.draw(s),s.end()}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:s,targetTexture:n}){if(t||(t={sourceBuffers:{},sourceTextures:{},targetTexture:null}),Object.assign(t.sourceTextures,s),Object.assign(t.sourceBuffers,e),n){t.targetTexture=n;let{width:r,height:o}=n;t.framebuffer&&t.framebuffer.destroy(),t.framebuffer=this.device.createFramebuffer({id:"transform-framebuffer",width:r,height:o,colorAttachments:[n]}),t.framebuffer.resize({width:r,height:o})}return t}_setSourceTextureParameters(){let t=this.currentIndex,{sourceTextures:e}=this.bindings[t];for(let s in e)e[s].sampler=this.sampler}};var D=class{id;topology;vertexCount;indices;attributes;userData={};constructor(t){let{attributes:e={},indices:s=null,vertexCount:n=null}=t;this.id=t.id||O("geometry"),this.topology=t.topology,s&&(this.indices=ArrayBuffer.isView(s)?{value:s,size:1}:s),this.attributes={};for(let[r,o]of Object.entries(e)){let a=ArrayBuffer.isView(o)?{value:o}:o;if(!ArrayBuffer.isView(a.value))throw new Error(`${this._print(r)}: must be typed array or object with value as typed array`);if((r==="POSITION"||r==="positions")&&!a.size&&(a.size=3),r==="indices"){if(this.indices)throw new Error("Multiple indices detected");this.indices=a}else this.attributes[r]=a}this.indices&&this.indices.isIndexed!==void 0&&(this.indices=Object.assign({},this.indices),delete this.indices.isIndexed),this.vertexCount=n||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 s=1/0;for(let n of Object.values(t)){let{value:r,size:o,constant:a}=n;!a&&r&&o!==void 0&&o>=1&&(s=Math.min(s,r.length/o))}return s}};var rs=`struct VertexInputs {
|
|
8
|
+
@location(0) clipSpacePosition: vec2<f32>,
|
|
9
|
+
@location(1) texCoord: vec2<f32>,
|
|
10
|
+
@location(2) coordinate: vec2<f32>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
struct FragmentInputs {
|
|
14
|
+
@builtin(position) Position : vec4<f32>,
|
|
15
|
+
@location(0) position : vec2<f32>,
|
|
16
|
+
@location(1) coordinate : vec2<f32>,
|
|
17
|
+
@location(2) uv : vec2<f32>
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
@vertex
|
|
21
|
+
fn vertexMain(inputs: VertexInputs) -> FragmentInputs {
|
|
22
|
+
var outputs: FragmentInputs;
|
|
23
|
+
outputs.Position = vec4(inputs.clipSpacePosition, 0., 1.);
|
|
24
|
+
outputs.position = inputs.clipSpacePosition;
|
|
25
|
+
outputs.coordinate = inputs.coordinate;
|
|
26
|
+
outputs.uv = inputs.texCoord;
|
|
27
|
+
return outputs;
|
|
28
|
+
}
|
|
29
|
+
`,os=`#version 300 es
|
|
30
|
+
in vec2 clipSpacePositions;
|
|
31
|
+
in vec2 texCoords;
|
|
32
|
+
in vec2 coordinates;
|
|
105
33
|
|
|
106
34
|
out vec2 position;
|
|
107
35
|
out vec2 coordinate;
|
|
108
36
|
out vec2 uv;
|
|
109
37
|
|
|
110
38
|
void main(void) {
|
|
111
|
-
gl_Position = vec4(
|
|
112
|
-
position =
|
|
113
|
-
coordinate =
|
|
114
|
-
uv =
|
|
39
|
+
gl_Position = vec4(clipSpacePositions, 0., 1.);
|
|
40
|
+
position = clipSpacePositions;
|
|
41
|
+
coordinate = coordinates;
|
|
42
|
+
uv = texCoords;
|
|
43
|
+
}
|
|
44
|
+
`,Je=[-1,-1,1,-1,-1,1,1,1],J=class extends q{constructor(t,e){let s=Je.map(n=>n===-1?0:n);e.source&&(e={...e,source:`${rs}
|
|
45
|
+
${e.source}`}),super(t,{id:e.id||O("clip-space"),...e,vs:os,vertexCount:4,geometry:new D({topology:"triangle-strip",vertexCount:4,attributes:{clipSpacePositions:{size:2,value:new Float32Array(Je)},texCoords:{size:2,value:new Float32Array(s)},coordinates:{size:2,value:new Float32Array(s)}}})})}};var as=`@group(0) @binding(0) var backgroundTexture: texture_2d<f32>;
|
|
46
|
+
@group(0) @binding(1) var backgroundTextureSampler: sampler;
|
|
47
|
+
|
|
48
|
+
fn billboardTexture_getTextureUV(coordinates: vec2<f32>) -> vec2<f32> {
|
|
49
|
+
let iTexSize: vec2<u32> = textureDimensions(backgroundTexture, 0) * 2;
|
|
50
|
+
let texSize: vec2<f32> = vec2<f32>(f32(iTexSize.x), f32(iTexSize.y));
|
|
51
|
+
var position: vec2<f32> = coordinates.xy / texSize;
|
|
52
|
+
return position;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@fragment
|
|
56
|
+
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {
|
|
57
|
+
let position: vec2<f32> = billboardTexture_getTextureUV(inputs.coordinate);
|
|
58
|
+
return textureSample(backgroundTexture, backgroundTextureSampler, position);
|
|
59
|
+
}
|
|
60
|
+
`,cs=`#version 300 es
|
|
61
|
+
precision highp float;
|
|
62
|
+
|
|
63
|
+
uniform sampler2D backgroundTexture;
|
|
64
|
+
out vec4 fragColor;
|
|
65
|
+
|
|
66
|
+
vec2 billboardTexture_getTextureUV() {
|
|
67
|
+
ivec2 iTexSize = textureDimensions(backgroundTexture, 0) * 2;
|
|
68
|
+
vec2 texSize = vec2(float(iTexSize.x), float(iTexSize.y));
|
|
69
|
+
vec2 position = gl_FragCoord.xy / texSize;
|
|
70
|
+
return position;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
void main(void) {
|
|
74
|
+
vec2 position = billboardTexture_getTextureUV();
|
|
75
|
+
fragColor = texture(backgroundTexture, position);
|
|
76
|
+
}
|
|
77
|
+
`,at=class extends J{constructor(t,e){super(t,{id:e.id||"background-texture-model",source:as,fs:cs,parameters:{depthWriteEnabled:!1,depthCompare:"always",...e.blend?{blend:!0,blendColorOperation:"add",blendAlphaOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one-minus-src-color",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one-minus-src-alpha"}:{}}}),this.setTexture(e.backgroundTexture)}setTexture(t){this.setBindings({backgroundTexture:t})}predraw(){this.shaderInputs.setProps({}),super.predraw()}};var xr=1/Math.PI*180,yr=1/180*Math.PI,hs={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...hs}};var z=globalThis.mathgl.config;function ti(i,{precision:t=z.precision}={}){return i=ls(i),`${parseFloat(i.toPrecision(t))}`}function dt(i){return Array.isArray(i)||ArrayBuffer.isView(i)&&!(i instanceof DataView)}function Me(i,t,e){let s=z.EPSILON;e&&(z.EPSILON=e);try{if(i===t)return!0;if(dt(i)&&dt(t)){if(i.length!==t.length)return!1;for(let n=0;n<i.length;++n)if(!Me(i[n],t[n]))return!1;return!0}return i&&i.equals?i.equals(t):t&&t.equals?t.equals(i):typeof i=="number"&&typeof t=="number"?Math.abs(i-t)<=z.EPSILON*Math.max(1,Math.abs(i),Math.abs(t)):!1}finally{z.EPSILON=s}}function ls(i){return Math.round(i/z.EPSILON)*z.EPSILON}var ut=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,e=0){for(let s=0;s<this.ELEMENTS;++s)this[s]=t[s+e];return this.check()}toArray(t=[],e=0){for(let s=0;s<this.ELEMENTS;++s)t[e+s]=this[s];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:dt(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(z)}formatString(t){let e="";for(let s=0;s<this.ELEMENTS;++s)e+=(s>0?", ":"")+ti(this[s],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(!Me(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,s){if(s===void 0)return this.lerp(this,t,e);for(let n=0;n<this.ELEMENTS;++n){let r=t[n],o=typeof e=="number"?e:e[n];this[n]=r+s*(o-r)}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 s=0;s<this.ELEMENTS;++s)this[s]=Math.min(Math.max(this[s],t[s]),e[s]);return this.check()}add(...t){for(let e of t)for(let s=0;s<this.ELEMENTS;++s)this[s]+=e[s];return this.check()}subtract(...t){for(let e of t)for(let s=0;s<this.ELEMENTS;++s)this[s]-=e[s];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(z.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 s=0;s<this.ELEMENTS;++s)this[s]=Math.min(Math.max(this[s],t),e);return this.check()}get elements(){return this}};function fs(i,t){if(i.length!==t)return!1;for(let e=0;e<i.length;++e)if(!Number.isFinite(i[e]))return!1;return!0}function B(i){if(!Number.isFinite(i))throw new Error(`Invalid number ${JSON.stringify(i)}`);return i}function Wt(i,t,e=""){if(z.debug&&!fs(i,t))throw new Error(`math.gl: ${e} some fields set to invalid numbers'`);return i}function ve(i,t){if(!i)throw new Error(`math.gl assertion ${t}`)}var Ht=class extends ut{get x(){return this[0]}set x(t){this[0]=B(t)}get y(){return this[1]}set y(t){this[1]=B(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 s=0;s<this.ELEMENTS;++s){let n=this[s]-t[s];e+=n*n}return B(e)}dot(t){let e=0;for(let s=0;s<this.ELEMENTS;++s)e+=this[s]*t[s];return B(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 s=0;s<this.ELEMENTS;++s)this[s]*=e[s];return this.check()}divide(...t){for(let e of t)for(let s=0;s<this.ELEMENTS;++s)this[s]/=e[s];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(t){return this.distance(t)}distanceToSquared(t){return this.distanceSquared(t)}getComponent(t){return ve(t>=0&&t<this.ELEMENTS,"index is out of range"),B(this[t])}setComponent(t,e){return ve(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 tt=typeof Float32Array<"u"?Float32Array:Array;var Cr=Math.PI/180;function ds(){let i=new tt(2);return tt!=Float32Array&&(i[0]=0,i[1]=0),i}function si(i,t,e){let s=t[0],n=t[1];return i[0]=e[0]*s+e[4]*n+e[12],i[1]=e[1]*s+e[5]*n+e[13],i}var Or=function(){let i=ds();return function(t,e,s,n,r,o){let a,c;for(e||(e=2),s||(s=0),n?c=Math.min(n*e+s,t.length):c=t.length,a=s;a<c;a+=e)i[0]=t[a],i[1]=t[a+1],r(i,i,o),t[a]=i[0],t[a+1]=i[1];return t}}();function ni(i,t,e){let s=t[0],n=t[1],r=e[3]*s+e[7]*n||1;return i[0]=(e[0]*s+e[4]*n)/r,i[1]=(e[1]*s+e[5]*n)/r,i}function Yt(i,t,e){let s=t[0],n=t[1],r=t[2],o=e[3]*s+e[7]*n+e[11]*r||1;return i[0]=(e[0]*s+e[4]*n+e[8]*r)/o,i[1]=(e[1]*s+e[5]*n+e[9]*r)/o,i[2]=(e[2]*s+e[6]*n+e[10]*r)/o,i}function ri(i,t,e){let s=t[0],n=t[1];return i[0]=e[0]*s+e[2]*n,i[1]=e[1]*s+e[3]*n,i[2]=t[2],i}function us(){let i=new tt(3);return tt!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0),i}function ps(i,t){return i[0]*t[0]+i[1]*t[1]+i[2]*t[2]}function oi(i,t,e){let s=t[0],n=t[1],r=t[2],o=e[0],a=e[1],c=e[2];return i[0]=n*c-r*a,i[1]=r*o-s*c,i[2]=s*a-n*o,i}function Xt(i,t,e){let s=t[0],n=t[1],r=t[2],o=e[3]*s+e[7]*n+e[11]*r+e[15];return o=o||1,i[0]=(e[0]*s+e[4]*n+e[8]*r+e[12])/o,i[1]=(e[1]*s+e[5]*n+e[9]*r+e[13])/o,i[2]=(e[2]*s+e[6]*n+e[10]*r+e[14])/o,i}function ai(i,t,e){let s=t[0],n=t[1],r=t[2];return i[0]=s*e[0]+n*e[3]+r*e[6],i[1]=s*e[1]+n*e[4]+r*e[7],i[2]=s*e[2]+n*e[5]+r*e[8],i}function ci(i,t,e){let s=e[0],n=e[1],r=e[2],o=e[3],a=t[0],c=t[1],h=t[2],l=n*h-r*c,f=r*a-s*h,d=s*c-n*a,m=n*d-r*f,b=r*l-s*d,u=s*f-n*l,x=o*2;return l*=x,f*=x,d*=x,m*=2,b*=2,u*=2,i[0]=a+l+m,i[1]=c+f+b,i[2]=h+d+u,i}function hi(i,t,e,s){let n=[],r=[];return n[0]=t[0]-e[0],n[1]=t[1]-e[1],n[2]=t[2]-e[2],r[0]=n[0],r[1]=n[1]*Math.cos(s)-n[2]*Math.sin(s),r[2]=n[1]*Math.sin(s)+n[2]*Math.cos(s),i[0]=r[0]+e[0],i[1]=r[1]+e[1],i[2]=r[2]+e[2],i}function li(i,t,e,s){let n=[],r=[];return n[0]=t[0]-e[0],n[1]=t[1]-e[1],n[2]=t[2]-e[2],r[0]=n[2]*Math.sin(s)+n[0]*Math.cos(s),r[1]=n[1],r[2]=n[2]*Math.cos(s)-n[0]*Math.sin(s),i[0]=r[0]+e[0],i[1]=r[1]+e[1],i[2]=r[2]+e[2],i}function fi(i,t,e,s){let n=[],r=[];return n[0]=t[0]-e[0],n[1]=t[1]-e[1],n[2]=t[2]-e[2],r[0]=n[0]*Math.cos(s)-n[1]*Math.sin(s),r[1]=n[0]*Math.sin(s)+n[1]*Math.cos(s),r[2]=n[2],i[0]=r[0]+e[0],i[1]=r[1]+e[1],i[2]=r[2]+e[2],i}function di(i,t){let e=i[0],s=i[1],n=i[2],r=t[0],o=t[1],a=t[2],c=Math.sqrt((e*e+s*s+n*n)*(r*r+o*o+a*a)),h=c&&ps(i,t)/c;return Math.acos(Math.min(Math.max(h,-1),1))}var kr=function(){let i=us();return function(t,e,s,n,r,o){let a,c;for(e||(e=3),s||(s=0),n?c=Math.min(n*e+s,t.length):c=t.length,a=s;a<c;a+=e)i[0]=t[a],i[1]=t[a+1],i[2]=t[a+2],r(i,i,o),t[a]=i[0],t[a+1]=i[1],t[a+2]=i[2];return t}}();var Ae=[0,0,0],Kt,$=class extends Ht{static get ZERO(){return Kt||(Kt=new $(0,0,0),Object.freeze(Kt)),Kt}constructor(t=0,e=0,s=0){super(-0,-0,-0),arguments.length===1&&dt(t)?this.copy(t):(z.debug&&(B(t),B(e),B(s)),this[0]=t,this[1]=e,this[2]=s)}set(t,e,s){return this[0]=t,this[1]=e,this[2]=s,this.check()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this.check()}fromObject(t){return z.debug&&(B(t.x),B(t.y),B(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]=B(t)}angle(t){return di(this,t)}cross(t){return oi(this,this,t),this.check()}rotateX({radians:t,origin:e=Ae}){return hi(this,this,e,t),this.check()}rotateY({radians:t,origin:e=Ae}){return li(this,this,e,t),this.check()}rotateZ({radians:t,origin:e=Ae}){return fi(this,this,e,t),this.check()}transform(t){return this.transformAsPoint(t)}transformAsPoint(t){return Xt(this,this,t),this.check()}transformAsVector(t){return Yt(this,this,t),this.check()}transformByMatrix3(t){return ai(this,this,t),this.check()}transformByMatrix2(t){return ri(this,this,t),this.check()}transformByQuaternion(t){return ci(this,this,t),this.check()}};var Zt=class extends ut{toString(){let t="[";if(z.printRowMajor){t+="row-major:";for(let e=0;e<this.RANK;++e)for(let s=0;s<this.RANK;++s)t+=` ${this[s*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,s){return this[e*this.RANK+t]=B(s),this}getColumn(t,e=new Array(this.RANK).fill(-0)){let s=t*this.RANK;for(let n=0;n<this.RANK;++n)e[n]=this[s+n];return e}setColumn(t,e){let s=t*this.RANK;for(let n=0;n<this.RANK;++n)this[s+n]=e[n];return this}};function ms(i){return i[0]=1,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=1,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[10]=1,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i}function ui(i,t){if(i===t){let e=t[1],s=t[2],n=t[3],r=t[6],o=t[7],a=t[11];i[1]=t[4],i[2]=t[8],i[3]=t[12],i[4]=e,i[6]=t[9],i[7]=t[13],i[8]=s,i[9]=r,i[11]=t[14],i[12]=n,i[13]=o,i[14]=a}else i[0]=t[0],i[1]=t[4],i[2]=t[8],i[3]=t[12],i[4]=t[1],i[5]=t[5],i[6]=t[9],i[7]=t[13],i[8]=t[2],i[9]=t[6],i[10]=t[10],i[11]=t[14],i[12]=t[3],i[13]=t[7],i[14]=t[11],i[15]=t[15];return i}function pi(i,t){let e=t[0],s=t[1],n=t[2],r=t[3],o=t[4],a=t[5],c=t[6],h=t[7],l=t[8],f=t[9],d=t[10],m=t[11],b=t[12],u=t[13],x=t[14],M=t[15],_=e*a-s*o,p=e*c-n*o,g=e*h-r*o,y=s*c-n*a,v=s*h-r*a,S=n*h-r*c,R=l*u-f*b,T=l*x-d*b,E=l*M-m*b,A=f*x-d*u,I=f*M-m*u,C=d*M-m*x,w=_*C-p*I+g*A+y*E-v*T+S*R;return w?(w=1/w,i[0]=(a*C-c*I+h*A)*w,i[1]=(n*I-s*C-r*A)*w,i[2]=(u*S-x*v+M*y)*w,i[3]=(d*v-f*S-m*y)*w,i[4]=(c*E-o*C-h*T)*w,i[5]=(e*C-n*E+r*T)*w,i[6]=(x*g-b*S-M*p)*w,i[7]=(l*S-d*g+m*p)*w,i[8]=(o*I-a*E+h*R)*w,i[9]=(s*E-e*I-r*R)*w,i[10]=(b*v-u*g+M*_)*w,i[11]=(f*g-l*v-m*_)*w,i[12]=(a*T-o*A-c*R)*w,i[13]=(e*A-s*T+n*R)*w,i[14]=(u*p-b*y-x*_)*w,i[15]=(l*y-f*p+d*_)*w,i):null}function mi(i){let t=i[0],e=i[1],s=i[2],n=i[3],r=i[4],o=i[5],a=i[6],c=i[7],h=i[8],l=i[9],f=i[10],d=i[11],m=i[12],b=i[13],u=i[14],x=i[15],M=t*o-e*r,_=t*a-s*r,p=e*a-s*o,g=h*b-l*m,y=h*u-f*m,v=l*u-f*b,S=t*v-e*y+s*g,R=r*v-o*y+a*g,T=h*p-l*_+f*M,E=m*p-b*_+u*M;return c*S-n*R+x*T-d*E}function we(i,t,e){let s=t[0],n=t[1],r=t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],f=t[8],d=t[9],m=t[10],b=t[11],u=t[12],x=t[13],M=t[14],_=t[15],p=e[0],g=e[1],y=e[2],v=e[3];return i[0]=p*s+g*a+y*f+v*u,i[1]=p*n+g*c+y*d+v*x,i[2]=p*r+g*h+y*m+v*M,i[3]=p*o+g*l+y*b+v*_,p=e[4],g=e[5],y=e[6],v=e[7],i[4]=p*s+g*a+y*f+v*u,i[5]=p*n+g*c+y*d+v*x,i[6]=p*r+g*h+y*m+v*M,i[7]=p*o+g*l+y*b+v*_,p=e[8],g=e[9],y=e[10],v=e[11],i[8]=p*s+g*a+y*f+v*u,i[9]=p*n+g*c+y*d+v*x,i[10]=p*r+g*h+y*m+v*M,i[11]=p*o+g*l+y*b+v*_,p=e[12],g=e[13],y=e[14],v=e[15],i[12]=p*s+g*a+y*f+v*u,i[13]=p*n+g*c+y*d+v*x,i[14]=p*r+g*h+y*m+v*M,i[15]=p*o+g*l+y*b+v*_,i}function gi(i,t,e){let s=e[0],n=e[1],r=e[2],o,a,c,h,l,f,d,m,b,u,x,M;return t===i?(i[12]=t[0]*s+t[4]*n+t[8]*r+t[12],i[13]=t[1]*s+t[5]*n+t[9]*r+t[13],i[14]=t[2]*s+t[6]*n+t[10]*r+t[14],i[15]=t[3]*s+t[7]*n+t[11]*r+t[15]):(o=t[0],a=t[1],c=t[2],h=t[3],l=t[4],f=t[5],d=t[6],m=t[7],b=t[8],u=t[9],x=t[10],M=t[11],i[0]=o,i[1]=a,i[2]=c,i[3]=h,i[4]=l,i[5]=f,i[6]=d,i[7]=m,i[8]=b,i[9]=u,i[10]=x,i[11]=M,i[12]=o*s+l*n+b*r+t[12],i[13]=a*s+f*n+u*r+t[13],i[14]=c*s+d*n+x*r+t[14],i[15]=h*s+m*n+M*r+t[15]),i}function xi(i,t,e){let s=e[0],n=e[1],r=e[2];return i[0]=t[0]*s,i[1]=t[1]*s,i[2]=t[2]*s,i[3]=t[3]*s,i[4]=t[4]*n,i[5]=t[5]*n,i[6]=t[6]*n,i[7]=t[7]*n,i[8]=t[8]*r,i[9]=t[9]*r,i[10]=t[10]*r,i[11]=t[11]*r,i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15],i}function yi(i,t,e,s){let n=s[0],r=s[1],o=s[2],a=Math.sqrt(n*n+r*r+o*o),c,h,l,f,d,m,b,u,x,M,_,p,g,y,v,S,R,T,E,A,I,C,w,F;return a<1e-6?null:(a=1/a,n*=a,r*=a,o*=a,h=Math.sin(e),c=Math.cos(e),l=1-c,f=t[0],d=t[1],m=t[2],b=t[3],u=t[4],x=t[5],M=t[6],_=t[7],p=t[8],g=t[9],y=t[10],v=t[11],S=n*n*l+c,R=r*n*l+o*h,T=o*n*l-r*h,E=n*r*l-o*h,A=r*r*l+c,I=o*r*l+n*h,C=n*o*l+r*h,w=r*o*l-n*h,F=o*o*l+c,i[0]=f*S+u*R+p*T,i[1]=d*S+x*R+g*T,i[2]=m*S+M*R+y*T,i[3]=b*S+_*R+v*T,i[4]=f*E+u*A+p*I,i[5]=d*E+x*A+g*I,i[6]=m*E+M*A+y*I,i[7]=b*E+_*A+v*I,i[8]=f*C+u*w+p*F,i[9]=d*C+x*w+g*F,i[10]=m*C+M*w+y*F,i[11]=b*C+_*w+v*F,t!==i&&(i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i)}function bi(i,t,e){let s=Math.sin(e),n=Math.cos(e),r=t[4],o=t[5],a=t[6],c=t[7],h=t[8],l=t[9],f=t[10],d=t[11];return t!==i&&(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i[4]=r*n+h*s,i[5]=o*n+l*s,i[6]=a*n+f*s,i[7]=c*n+d*s,i[8]=h*n-r*s,i[9]=l*n-o*s,i[10]=f*n-a*s,i[11]=d*n-c*s,i}function Mi(i,t,e){let s=Math.sin(e),n=Math.cos(e),r=t[0],o=t[1],a=t[2],c=t[3],h=t[8],l=t[9],f=t[10],d=t[11];return t!==i&&(i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i[0]=r*n-h*s,i[1]=o*n-l*s,i[2]=a*n-f*s,i[3]=c*n-d*s,i[8]=r*s+h*n,i[9]=o*s+l*n,i[10]=a*s+f*n,i[11]=c*s+d*n,i}function vi(i,t,e){let s=Math.sin(e),n=Math.cos(e),r=t[0],o=t[1],a=t[2],c=t[3],h=t[4],l=t[5],f=t[6],d=t[7];return t!==i&&(i[8]=t[8],i[9]=t[9],i[10]=t[10],i[11]=t[11],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i[0]=r*n+h*s,i[1]=o*n+l*s,i[2]=a*n+f*s,i[3]=c*n+d*s,i[4]=h*n-r*s,i[5]=l*n-o*s,i[6]=f*n-a*s,i[7]=d*n-c*s,i}function _i(i,t){let e=t[0],s=t[1],n=t[2],r=t[3],o=e+e,a=s+s,c=n+n,h=e*o,l=s*o,f=s*a,d=n*o,m=n*a,b=n*c,u=r*o,x=r*a,M=r*c;return i[0]=1-f-b,i[1]=l+M,i[2]=d-x,i[3]=0,i[4]=l-M,i[5]=1-h-b,i[6]=m+u,i[7]=0,i[8]=d+x,i[9]=m-u,i[10]=1-h-f,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i}function Ai(i,t,e,s,n,r,o){let a=1/(e-t),c=1/(n-s),h=1/(r-o);return i[0]=r*2*a,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=r*2*c,i[6]=0,i[7]=0,i[8]=(e+t)*a,i[9]=(n+s)*c,i[10]=(o+r)*h,i[11]=-1,i[12]=0,i[13]=0,i[14]=o*r*2*h,i[15]=0,i}function gs(i,t,e,s,n){let r=1/Math.tan(t/2);if(i[0]=r/e,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=r,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[11]=-1,i[12]=0,i[13]=0,i[15]=0,n!=null&&n!==1/0){let o=1/(s-n);i[10]=(n+s)*o,i[14]=2*n*s*o}else i[10]=-1,i[14]=-2*s;return i}var wi=gs;function xs(i,t,e,s,n,r,o){let a=1/(t-e),c=1/(s-n),h=1/(r-o);return i[0]=-2*a,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=-2*c,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[10]=2*h,i[11]=0,i[12]=(t+e)*a,i[13]=(n+s)*c,i[14]=(o+r)*h,i[15]=1,i}var Pi=xs;function Ii(i,t,e,s){let n,r,o,a,c,h,l,f,d,m,b=t[0],u=t[1],x=t[2],M=s[0],_=s[1],p=s[2],g=e[0],y=e[1],v=e[2];return Math.abs(b-g)<1e-6&&Math.abs(u-y)<1e-6&&Math.abs(x-v)<1e-6?ms(i):(f=b-g,d=u-y,m=x-v,n=1/Math.sqrt(f*f+d*d+m*m),f*=n,d*=n,m*=n,r=_*m-p*d,o=p*f-M*m,a=M*d-_*f,n=Math.sqrt(r*r+o*o+a*a),n?(n=1/n,r*=n,o*=n,a*=n):(r=0,o=0,a=0),c=d*a-m*o,h=m*r-f*a,l=f*o-d*r,n=Math.sqrt(c*c+h*h+l*l),n?(n=1/n,c*=n,h*=n,l*=n):(c=0,h=0,l=0),i[0]=r,i[1]=c,i[2]=f,i[3]=0,i[4]=o,i[5]=h,i[6]=d,i[7]=0,i[8]=a,i[9]=l,i[10]=m,i[11]=0,i[12]=-(r*b+o*u+a*x),i[13]=-(c*b+h*u+l*x),i[14]=-(f*b+d*u+m*x),i[15]=1,i)}function ys(){let i=new tt(4);return tt!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0,i[3]=0),i}function Si(i,t,e){let s=t[0],n=t[1],r=t[2],o=t[3];return i[0]=e[0]*s+e[4]*n+e[8]*r+e[12]*o,i[1]=e[1]*s+e[5]*n+e[9]*r+e[13]*o,i[2]=e[2]*s+e[6]*n+e[10]*r+e[14]*o,i[3]=e[3]*s+e[7]*n+e[11]*r+e[15]*o,i}var Wr=function(){let i=ys();return function(t,e,s,n,r,o){let a,c;for(e||(e=4),s||(s=0),n?c=Math.min(n*e+s,t.length):c=t.length,a=s;a<c;a+=e)i[0]=t[a],i[1]=t[a+1],i[2]=t[a+2],i[3]=t[a+3],r(i,i,o),t[a]=i[0],t[a+1]=i[1],t[a+2]=i[2],t[a+3]=i[3];return t}}();var Se;(function(i){i[i.COL0ROW0=0]="COL0ROW0",i[i.COL0ROW1=1]="COL0ROW1",i[i.COL0ROW2=2]="COL0ROW2",i[i.COL0ROW3=3]="COL0ROW3",i[i.COL1ROW0=4]="COL1ROW0",i[i.COL1ROW1=5]="COL1ROW1",i[i.COL1ROW2=6]="COL1ROW2",i[i.COL1ROW3=7]="COL1ROW3",i[i.COL2ROW0=8]="COL2ROW0",i[i.COL2ROW1=9]="COL2ROW1",i[i.COL2ROW2=10]="COL2ROW2",i[i.COL2ROW3=11]="COL2ROW3",i[i.COL3ROW0=12]="COL3ROW0",i[i.COL3ROW1=13]="COL3ROW1",i[i.COL3ROW2=14]="COL3ROW2",i[i.COL3ROW3=15]="COL3ROW3"})(Se||(Se={}));var bs=45*Math.PI/180,Ms=1,Pe=.1,Ie=500,vs=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),H=class extends Zt{static get IDENTITY(){return As()}static get ZERO(){return _s()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Se}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,s,n,r,o,a,c,h,l,f,d,m,b,u,x){return this[0]=t,this[1]=e,this[2]=s,this[3]=n,this[4]=r,this[5]=o,this[6]=a,this[7]=c,this[8]=h,this[9]=l,this[10]=f,this[11]=d,this[12]=m,this[13]=b,this[14]=u,this[15]=x,this.check()}setRowMajor(t,e,s,n,r,o,a,c,h,l,f,d,m,b,u,x){return this[0]=t,this[1]=r,this[2]=h,this[3]=m,this[4]=e,this[5]=o,this[6]=l,this[7]=b,this[8]=s,this[9]=a,this[10]=f,this[11]=u,this[12]=n,this[13]=c,this[14]=d,this[15]=x,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(vs)}fromObject(t){return this.check()}fromQuaternion(t){return _i(this,t),this.check()}frustum(t){let{left:e,right:s,bottom:n,top:r,near:o=Pe,far:a=Ie}=t;return a===1/0?ws(this,e,s,n,r,o):Ai(this,e,s,n,r,o,a),this.check()}lookAt(t){let{eye:e,center:s=[0,0,0],up:n=[0,1,0]}=t;return Ii(this,e,s,n),this.check()}ortho(t){let{left:e,right:s,bottom:n,top:r,near:o=Pe,far:a=Ie}=t;return Pi(this,e,s,n,r,o,a),this.check()}orthographic(t){let{fovy:e=bs,aspect:s=Ms,focalDistance:n=1,near:r=Pe,far:o=Ie}=t;Ti(e);let a=e/2,c=n*Math.tan(a),h=c*s;return this.ortho({left:-h,right:h,bottom:-c,top:c,near:r,far:o})}perspective(t){let{fovy:e=45*Math.PI/180,aspect:s=1,near:n=.1,far:r=500}=t;return Ti(e),wi(this,e,s,n,r),this.check()}determinant(){return mi(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 s=this.getScale(e),n=1/s[0],r=1/s[1],o=1/s[2];return t[0]=this[0]*n,t[1]=this[1]*r,t[2]=this[2]*o,t[3]=0,t[4]=this[4]*n,t[5]=this[5]*r,t[6]=this[6]*o,t[7]=0,t[8]=this[8]*n,t[9]=this[9]*r,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 s=this.getScale(e),n=1/s[0],r=1/s[1],o=1/s[2];return t[0]=this[0]*n,t[1]=this[1]*r,t[2]=this[2]*o,t[3]=this[4]*n,t[4]=this[5]*r,t[5]=this[6]*o,t[6]=this[8]*n,t[7]=this[9]*r,t[8]=this[10]*o,t}transpose(){return ui(this,this),this.check()}invert(){return pi(this,this),this.check()}multiplyLeft(t){return we(this,t,this),this.check()}multiplyRight(t){return we(this,this,t),this.check()}rotateX(t){return bi(this,this,t),this.check()}rotateY(t){return Mi(this,this,t),this.check()}rotateZ(t){return vi(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,e){return yi(this,this,t,e),this.check()}scale(t){return xi(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return gi(this,this,t),this.check()}transform(t,e){return t.length===4?(e=Si(e||[-0,-0,-0,-0],t,this),Wt(e,4),e):this.transformAsPoint(t,e)}transformAsPoint(t,e){let{length:s}=t,n;switch(s){case 2:n=si(e||[-0,-0],t,this);break;case 3:n=Xt(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Wt(n,t.length),n}transformAsVector(t,e){let s;switch(t.length){case 2:s=ni(e||[-0,-0],t,this);break;case 3:s=Yt(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Wt(s,t.length),s}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,s){return this.identity().translate([t,e,s])}},Qt,Jt;function _s(){return Qt||(Qt=new H([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Qt)),Qt}function As(){return Jt||(Jt=new H,Object.freeze(Jt)),Jt}function Ti(i){if(i>Math.PI*2)throw Error("expected radians")}function ws(i,t,e,s,n,r){let o=2*r/(e-t),a=2*r/(n-s),c=(e+t)/(e-t),h=(n+s)/(n-s),l=-1,f=-1,d=-2*r;return i[0]=o,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=a,i[6]=0,i[7]=0,i[8]=c,i[9]=h,i[10]=l,i[11]=f,i[12]=0,i[13]=0,i[14]=d,i[15]=0,i}var et=class{id;matrix=new H;display=!0;position=new $;rotation=new $;scale=new $(1,1,1);userData={};props={};constructor(t={}){let{id:e}=t;this.id=e||O(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 this.position=t,this}setRotation(t){return this.rotation=t,this}setScale(t){return this.scale=t,this}setMatrix(t,e=!0){e?this.matrix.copy(t):this.matrix=t}setMatrixComponents(t){let{position:e,rotation:s,scale:n,update:r=!0}=t;return e&&this.setPosition(e),s&&this.setRotation(s),n&&this.setScale(n),r&&this.updateMatrix(),this}updateMatrix(){let t=this.position,e=this.rotation,s=this.scale;return this.matrix.identity(),this.matrix.translate(t),this.matrix.rotateXYZ(e),this.matrix.scale(s),this}update(t={}){let{position:e,rotation:s,scale:n}=t;return e&&this.setPosition(e),s&&this.setRotation(s),n&&this.setScale(n),this.updateMatrix(),this}getCoordinateUniforms(t,e){e=e||this.matrix;let s=new H(t).multiplyRight(e),n=s.invert(),r=n.transpose();return{viewMatrix:t,modelMatrix:e,objectMatrix:e,worldMatrix:s,worldInverseMatrix:n,worldInverseTransposeMatrix:r}}_setScenegraphNodeProps(t){"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 Ci=L(j(),1);var mt=class extends et{children;constructor(t={}){t=Array.isArray(t)?{children:t}:t;let{children:e=[]}=t;Ci.log.assert(e.every(s=>s instanceof et),"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:s})=>{let n=e.getBounds();if(!n)return;let[r,o]=n,a=new $(r).add(o).divide([2,2,2]);s.transformAsPoint(a,a);let c=new $(o).subtract(r).divide([2,2,2]);s.transformAsVector(c,c);for(let h=0;h<8;h++){let l=new $(h&1?-1:1,h&2?-1:1,h&4?-1:1).multiply(c).add(a);for(let f=0;f<3;f++)t[0][f]=Math.min(t[0][f],l[f]),t[1][f]=Math.max(t[1][f],l[f])}}),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,s=e.indexOf(t);return s>-1&&e.splice(s,1),this}removeAll(){return this.children=[],this}traverse(t,{worldMatrix:e=new H}={}){let s=new H(e).multiplyRight(this.matrix);for(let n of this.children)n instanceof mt?n.traverse(t,{worldMatrix:s}):t(n,{worldMatrix:s})}};var te=class extends et{model;bounds=null;managedResources;constructor(t){super(t),this.model=t.model,this.managedResources=t.managedResources||[],this.bounds=t.bounds||null,this.setProps(t)}destroy(){this.model&&(this.model.destroy(),this.model=null),this.managedResources.forEach(t=>t.destroy()),this.managedResources=[]}getBounds(){return this.bounds}draw(t){return this.model.draw(t)}};var Ps={x:[2,0,1],y:[0,1,2],z:[1,2,0]},st=class extends D{constructor(t={}){let{id:e=O("truncated-code-geometry")}=t,{indices:s,attributes:n}=Is(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{POSITION:{size:3,value:n.POSITION},NORMAL:{size:3,value:n.NORMAL},TEXCOORD_0:{size:2,value:n.TEXCOORD_0},...t.attributes}})}};function Is(i={}){let{bottomRadius:t=0,topRadius:e=0,height:s=1,nradial:n=10,nvertical:r=10,verticalAxis:o="y",topCap:a=!1,bottomCap:c=!1}=i,h=(a?2:0)+(c?2:0),l=(n+1)*(r+1+h),f=Math.atan2(t-e,s),d=Math.sin,m=Math.cos,b=Math.PI,u=m(f),x=d(f),M=a?-2:0,_=r+(c?2:0),p=n+1,g=new Uint16Array(n*(r+h)*6),y=Ps[o],v=new Float32Array(l*3),S=new Float32Array(l*3),R=new Float32Array(l*2),T=0,E=0;for(let A=M;A<=_;A++){let I=A/r,C=s*I,w;A<0?(C=0,I=1,w=t):A>r?(C=s,I=1,w=e):w=t+(e-t)*(A/r),(A===-2||A===r+2)&&(w=0,I=0),C-=s/2;for(let F=0;F<p;F++){let K=d(F*b*2/n),W=m(F*b*2/n);v[T+y[0]]=K*w,v[T+y[1]]=C,v[T+y[2]]=W*w,S[T+y[0]]=A<0||A>r?0:K*u,S[T+y[1]]=A<0?-1:A>r?1:x,S[T+y[2]]=A<0||A>r?0:W*u,R[E+0]=F/n,R[E+1]=I,E+=2,T+=3}}for(let A=0;A<r+h;A++)for(let I=0;I<n;I++){let C=(A*n+I)*6;g[C+0]=p*(A+0)+0+I,g[C+1]=p*(A+0)+1+I,g[C+2]=p*(A+1)+1+I,g[C+3]=p*(A+0)+0+I,g[C+4]=p*(A+1)+1+I,g[C+5]=p*(A+1)+0+I}return{indices:g,attributes:{POSITION:v,NORMAL:S,TEXCOORD_0:R}}}var ee=class extends st{constructor(t={}){let{id:e=O("cone-geometry"),radius:s=1,cap:n=!0}=t;super({...t,id:e,topRadius:0,topCap:Boolean(n),bottomCap:Boolean(n),bottomRadius:s})}};var ie=class extends D{constructor(t={}){let{id:e=O("cube-geometry"),indices:s=!0}=t;super(s?{...t,id:e,topology:"triangle-list",indices:{size:1,value:Ss},attributes:{...Ls,...t.attributes}}:{...t,id:e,topology:"triangle-list",indices:void 0,attributes:{...Ns,...t.attributes}})}},Ss=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]),Ts=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]),Cs=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]),Os=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]),Rs=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]),Es=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]),ks=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]),Ls={POSITION:{size:3,value:Ts},NORMAL:{size:3,value:Cs},TEXCOORD_0:{size:2,value:Os}},Ns={POSITION:{size:3,value:Rs},TEXCOORD_0:{size:2,value:Es},COLOR_0:{size:3,value:ks}};var se=class extends st{constructor(t={}){let{id:e=O("cylinder-geometry"),radius:s=1}=t;super({...t,id:e,bottomRadius:s,topRadius:s})}};var Fs=[-1,0,0,0,1,0,0,0,-1,0,0,1,0,-1,0,1,0,0],zs=[3,4,5,3,5,1,3,1,0,3,0,4,4,0,2,4,2,5,2,0,1,5,2,1],ne=class extends D{constructor(t={}){let{id:e=O("ico-sphere-geometry")}=t,{indices:s,attributes:n}=Ds(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{...n,...t.attributes}})}};function Ds(i){let{iterations:t=0}=i,e=Math.PI,s=e*2,n=[...Fs],r=[...zs];n.push(),r.push();let o=(()=>{let l={};return(f,d)=>{f*=3,d*=3;let m=f<d?f:d,b=f>d?f:d,u=`${m}|${b}`;if(u in l)return l[u];let x=n[f],M=n[f+1],_=n[f+2],p=n[d],g=n[d+1],y=n[d+2],v=(x+p)/2,S=(M+g)/2,R=(_+y)/2,T=Math.sqrt(v*v+S*S+R*R);return v/=T,S/=T,R/=T,n.push(v,S,R),l[u]=n.length/3-1}})();for(let l=0;l<t;l++){let f=[];for(let d=0;d<r.length;d+=3){let m=o(r[d+0],r[d+1]),b=o(r[d+1],r[d+2]),u=o(r[d+2],r[d+0]);f.push(u,r[d+0],m,m,r[d+1],b,b,r[d+2],u,m,b,u)}r=f}let a=new Array(n.length),c=new Array(n.length/3*2),h=r.length;for(let l=h-3;l>=0;l-=3){let f=r[l+0],d=r[l+1],m=r[l+2],b=f*3,u=d*3,x=m*3,M=f*2,_=d*2,p=m*2,g=n[b+0],y=n[b+1],v=n[b+2],S=Math.acos(v/Math.sqrt(g*g+y*y+v*v)),R=Math.atan2(y,g)+e,T=S/e,E=1-R/s,A=n[u+0],I=n[u+1],C=n[u+2],w=Math.acos(C/Math.sqrt(A*A+I*I+C*C)),F=Math.atan2(I,A)+e,K=w/e,W=1-F/s,Tt=n[x+0],Ct=n[x+1],Ot=n[x+2],Fi=Math.acos(Ot/Math.sqrt(Tt*Tt+Ct*Ct+Ot*Ot)),zi=Math.atan2(Ct,Tt)+e,ke=Fi/e,Rt=1-zi/s,Di=[Tt-A,Ct-I,Ot-C],Bi=[g-A,y-I,v-C],G=new $(Di).cross(Bi).normalize(),k;(E===0||W===0||Rt===0)&&(E===0||E>.5)&&(W===0||W>.5)&&(Rt===0||Rt>.5)&&(n.push(n[b+0],n[b+1],n[b+2]),k=n.length/3-1,r.push(k),c[k*2+0]=1,c[k*2+1]=T,a[k*3+0]=G.x,a[k*3+1]=G.y,a[k*3+2]=G.z,n.push(n[u+0],n[u+1],n[u+2]),k=n.length/3-1,r.push(k),c[k*2+0]=1,c[k*2+1]=K,a[k*3+0]=G.x,a[k*3+1]=G.y,a[k*3+2]=G.z,n.push(n[x+0],n[x+1],n[x+2]),k=n.length/3-1,r.push(k),c[k*2+0]=1,c[k*2+1]=ke,a[k*3+0]=G.x,a[k*3+1]=G.y,a[k*3+2]=G.z),a[b+0]=a[u+0]=a[x+0]=G.x,a[b+1]=a[u+1]=a[x+1]=G.y,a[b+2]=a[u+2]=a[x+2]=G.z,c[M+0]=E,c[M+1]=T,c[_+0]=W,c[_+1]=K,c[p+0]=Rt,c[p+1]=ke}return{indices:{size:1,value:new Uint16Array(r)},attributes:{POSITION:{size:3,value:new Float32Array(n)},NORMAL:{size:3,value:new Float32Array(a)},TEXCOORD_0:{size:2,value:new Float32Array(c)}}}}function Oi(i){let{indices:t,attributes:e}=i;if(!t)return i;let s=t.value.length,n={};for(let r in e){let o=e[r],{constant:a,value:c,size:h}=o;if(a||!h)continue;let l=new c.constructor(s*h);for(let f=0;f<s;++f){let d=t.value[f];for(let m=0;m<h;m++)l[f*h+m]=c[d*h+m]}n[r]={size:h,value:l}}return{attributes:Object.assign({},e,n)}}var re=class extends D{constructor(t={}){let{id:e=O("plane-geometry")}=t,{indices:s,attributes:n}=Bs(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{...n,...t.attributes}})}};function Bs(i){let{type:t="x,y",offset:e=0,flipCull:s=!1,unpack:n=!1}=i,r=t.split(","),o=i[`${r[0]}len`]||1,a=i[`${r[1]}len`]||1,c=i[`n${r[0]}`]||1,h=i[`n${r[1]}`]||1,l=(c+1)*(h+1),f=new Float32Array(l*3),d=new Float32Array(l*3),m=new Float32Array(l*2);s&&(o=-o);let b=0,u=0;for(let p=0;p<=h;p++)for(let g=0;g<=c;g++){let y=g/c,v=p/h;switch(m[b+0]=s?1-y:y,m[b+1]=v,t){case"x,y":f[u+0]=o*y-o*.5,f[u+1]=a*v-a*.5,f[u+2]=e,d[u+0]=0,d[u+1]=0,d[u+2]=s?1:-1;break;case"x,z":f[u+0]=o*y-o*.5,f[u+1]=e,f[u+2]=a*v-a*.5,d[u+0]=0,d[u+1]=s?1:-1,d[u+2]=0;break;case"y,z":f[u+0]=e,f[u+1]=o*y-o*.5,f[u+2]=a*v-a*.5,d[u+0]=s?1:-1,d[u+1]=0,d[u+2]=0;break;default:throw new Error("PlaneGeometry: unknown type")}b+=2,u+=3}let x=c+1,M=new Uint16Array(c*h*6);for(let p=0;p<h;p++)for(let g=0;g<c;g++){let y=(p*c+g)*6;M[y+0]=(p+0)*x+g,M[y+1]=(p+1)*x+g,M[y+2]=(p+0)*x+g+1,M[y+3]=(p+1)*x+g,M[y+4]=(p+1)*x+g+1,M[y+5]=(p+0)*x+g+1}let _={indices:{size:1,value:M},attributes:{POSITION:{size:3,value:f},NORMAL:{size:3,value:d},TEXCOORD_0:{size:2,value:m}}};return n?Oi(_):_}var oe=class extends D{constructor(t={}){let{id:e=O("sphere-geometry")}=t,{indices:s,attributes:n}=Us(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{...n,...t.attributes}})}};function Us(i){let{nlat:t=10,nlong:e=10}=i,r=Math.PI-0,o=0,c=2*Math.PI-o,h=(t+1)*(e+1),l=(M,_,p,g,y)=>i.radius||1,f=new Float32Array(h*3),d=new Float32Array(h*3),m=new Float32Array(h*2),b=h>65535?Uint32Array:Uint16Array,u=new b(t*e*6);for(let M=0;M<=t;M++)for(let _=0;_<=e;_++){let p=_/e,g=M/t,y=_+M*(e+1),v=y*2,S=y*3,R=c*p,T=r*g,E=Math.sin(R),A=Math.cos(R),I=Math.sin(T),C=Math.cos(T),w=A*I,F=C,K=E*I,W=l(w,F,K,p,g);f[S+0]=W*w,f[S+1]=W*F,f[S+2]=W*K,d[S+0]=w,d[S+1]=F,d[S+2]=K,m[v+0]=p,m[v+1]=1-g}let x=e+1;for(let M=0;M<e;M++)for(let _=0;_<t;_++){let p=(M*t+_)*6;u[p+0]=_*x+M,u[p+1]=_*x+M+1,u[p+2]=(_+1)*x+M,u[p+3]=(_+1)*x+M,u[p+4]=_*x+M+1,u[p+5]=(_+1)*x+M+1}return{indices:{size:1,value:u},attributes:{POSITION:{size:3,value:f},NORMAL:{size:3,value:d},TEXCOORD_0:{size:2,value:m}}}}function Ri(){let i=1,t=1;return()=>(i=Math.sin(t*17.23),t=Math.cos(i*27.92),$s(Math.abs(i*t)*1432.71))}function $s(i){return i-Math.floor(i)}var ki=L(rt(),1);var wt=L(j(),1),gt=class{current;next;constructor(t){this.current=t.current,this.next=t.next}destroy(){this.current?.destroy(),this.next?.destroy()}swap(){let t=this.current;this.current=this.next,this.next=t}},xt=class extends gt{constructor(t,e){e={...e};let s=e.colorAttachments?.map(o=>typeof o!="string"?o:t.createTexture({format:o,usage:wt.Texture.COPY_DST|wt.Texture.RENDER_ATTACHMENT})),n=t.createFramebuffer({...e,colorAttachments:s});s=e.colorAttachments?.map(o=>typeof o!="string"?o:t.createTexture({format:o,usage:wt.Texture.COPY_DST|wt.Texture.RENDER_ATTACHMENT}));let r=t.createFramebuffer({...e,colorAttachments:s});super({current:n,next:r})}resize(t){if(t.width===this.current.width&&t.height===this.current.height)return!1;let{current:e,next:s}=this;return this.current=e.clone(t),e.destroy(),this.next=s.clone(t),s.destroy(),!0}},ae=class extends gt{constructor(t,e){super({current:t.createBuffer(e),next:t.createBuffer(e)})}resize(t){if(t.byteLength===this.current.byteLength)return!1;let{current:e,next:s}=this;return this.current=e.clone(t),e.destroy(),this.next=s.clone(t),s.destroy(),!0}};function Ei(i){let{shaderPass:t,action:e,shadingLanguage:s}=i;switch(e){case"filter":let n=`${t.name}_filterColor_ext`;return s==="wgsl"?js(n):Vs(n);case"sample":let r=`${t.name}_sampleColor`;return s==="wgsl"?Gs(r):qs(r);default:throw new Error(`${t.name} no fragment shader generated for shader pass`)}}function js(i){return`// Binding 0:1 is reserved for shader passes
|
|
78
|
+
@group(0) @binding(0) var<uniform> brightnessContrast : brightnessContrastUniforms;
|
|
79
|
+
@group(0) @binding(1) var texture: texture_2d<f32>;
|
|
80
|
+
@group(0) @binding(2) var sampler: sampler;
|
|
81
|
+
|
|
82
|
+
struct FragmentInputs = {
|
|
83
|
+
@location(0) fragUV: vec2f,
|
|
84
|
+
@location(1) fragPosition: vec4f,
|
|
85
|
+
@location(2) fragCoordinate: vec4f
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
@fragment
|
|
89
|
+
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
|
|
90
|
+
let texSize = textureDimensions(texture, 0);
|
|
91
|
+
var fragColor = textureSample(texture, sampler, fragUV);
|
|
92
|
+
fragColor = ${i}(gl_FragColor, texSize, texCoord);
|
|
93
|
+
return fragColor;
|
|
94
|
+
}
|
|
95
|
+
`}function Gs(i){return`// Binding 0:1 is reserved for shader passes
|
|
96
|
+
@group(0) @binding(0) var<uniform> brightnessContrast : brightnessContrastUniforms;
|
|
97
|
+
@group(0) @binding(1) var texture: texture_2d<f32>;
|
|
98
|
+
@group(0) @binding(2) var sampler: sampler;
|
|
99
|
+
|
|
100
|
+
struct FragmentInputs = {
|
|
101
|
+
@location(0) fragUV: vec2f,
|
|
102
|
+
@location(1) fragPosition: vec4f,
|
|
103
|
+
@location(2) fragCoordinate: vec4f
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
@fragment
|
|
107
|
+
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
|
|
108
|
+
let texSize = textureDimensions(texture, 0);
|
|
109
|
+
var fragColor = textureSample(texture, sampler, fragUV);
|
|
110
|
+
fragColor = ${i}(gl_FragColor, texSize, texCoord);
|
|
111
|
+
return fragColor;
|
|
112
|
+
}
|
|
113
|
+
`}function Vs(i){return`#version 300 es
|
|
114
|
+
|
|
115
|
+
uniform sampler2D sourceTexture;
|
|
116
|
+
|
|
117
|
+
in vec2 position;
|
|
118
|
+
in vec2 coordinate;
|
|
119
|
+
in vec2 uv;
|
|
120
|
+
|
|
121
|
+
out vec4 fragColor;
|
|
122
|
+
|
|
123
|
+
void main() {
|
|
124
|
+
vec2 texCoord = coordinate;
|
|
125
|
+
ivec2 iTexSize = textureSize(sourceTexture, 0);
|
|
126
|
+
vec2 texSize = vec2(float(iTexSize.x), float(iTexSize.y));
|
|
127
|
+
|
|
128
|
+
fragColor = texture(sourceTexture, texCoord);
|
|
129
|
+
fragColor = ${i}(fragColor, texSize, texCoord);
|
|
130
|
+
}
|
|
131
|
+
`}function qs(i){return`#version 300 es
|
|
132
|
+
|
|
133
|
+
uniform sampler2D sourceTexture;
|
|
134
|
+
|
|
135
|
+
in vec2 position;
|
|
136
|
+
in vec2 coordinate;
|
|
137
|
+
in vec2 uv;
|
|
138
|
+
|
|
139
|
+
out vec4 fragColor;
|
|
140
|
+
|
|
141
|
+
void main() {
|
|
142
|
+
vec2 texCoord = coordinate;
|
|
143
|
+
ivec2 iTexSize = textureSize(sourceTexture, 0);
|
|
144
|
+
vec2 texSize = vec2(float(iTexSize.x), float(iTexSize.y));
|
|
145
|
+
|
|
146
|
+
fragColor = ${i}(sourceTexture, texSize, texCoord);
|
|
147
|
+
}
|
|
148
|
+
`}var ce=class{device;shaderInputs;passRenderers;swapFramebuffers;clipSpace;textureModel;constructor(t,e){this.device=t,e.shaderPasses.map(r=>(0,ki.initializeShaderModule)(r));let s=e.shaderPasses.reduce((r,o)=>({...r,[o.name]:o}),{});this.shaderInputs=e.shaderInputs||new Y(s);let n=t.getCanvasContext().getPixelSize();this.swapFramebuffers=new xt(t,{colorAttachments:["rgba8unorm"],width:n[0],height:n[1]}),this.textureModel=new at(t,{backgroundTexture:this.swapFramebuffers.current.colorAttachments[0].texture}),this.clipSpace=new J(t,{source:` @group(0) @binding(0) var sourceTexture: texture_2d<f32>;
|
|
149
|
+
@group(0) @binding(1) var sourceTextureSampler: sampler;
|
|
150
|
+
|
|
151
|
+
@fragment
|
|
152
|
+
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {
|
|
153
|
+
let texCoord: vec2<f32> = inputs.coordinate;
|
|
154
|
+
return textureSample(sourceTexture, sourceTextureSampler, texCoord);
|
|
155
|
+
}
|
|
156
|
+
`,fs:`#version 300 es
|
|
157
|
+
|
|
158
|
+
uniform sampler2D sourceTexture;
|
|
159
|
+
in vec2 uv;
|
|
160
|
+
in vec2 coordinate;
|
|
161
|
+
out vec4 fragColor;
|
|
162
|
+
|
|
163
|
+
void main() {
|
|
164
|
+
vec2 texCoord = coordinate;
|
|
165
|
+
fragColor = texture(sourceTexture, coordinate);
|
|
166
|
+
}
|
|
167
|
+
`}),this.passRenderers=e.shaderPasses.map(r=>new Te(t,r))}destroy(){for(let t of this.passRenderers)t.destroy();this.swapFramebuffers.destroy(),this.clipSpace.destroy()}resize(t,e){this.swapFramebuffers.resize({width:t,height:e})}renderToScreen(t){let e=this.renderToTexture(t);if(!e)return!1;let s=this.device.beginRenderPass({clearColor:[0,0,0,1],clearDepth:1});return this.clipSpace.setBindings({sourceTexture:e}),this.clipSpace.draw(s),s.end(),!0}renderToTexture(t){let{sourceTexture:e}=t;if(!e.isReady)return null;this.textureModel.destroy(),this.textureModel=new at(this.device,{backgroundTexture:e});let s=this.device.beginRenderPass({framebuffer:this.swapFramebuffers.current,clearColor:[0,0,0,1]});this.textureModel.draw(s),s.end();let n=!0;for(let o of this.passRenderers)for(let a of o.subPassRenderers){n||this.swapFramebuffers.swap(),n=!1;let h={sourceTexture:this.swapFramebuffers.current.colorAttachments[0].texture},l=this.device.beginRenderPass({framebuffer:this.swapFramebuffers.next,clearColor:[0,0,0,1],clearDepth:1});a.render({renderPass:l,bindings:h}),l.end()}return this.swapFramebuffers.swap(),this.swapFramebuffers.current.colorAttachments[0].texture}},Te=class{shaderPass;subPassRenderers;constructor(t,e,s={}){this.shaderPass=e;let n=e.passes||[];this.subPassRenderers=n.map(r=>new Ce(t,e,r))}destroy(){for(let t of this.subPassRenderers)t.destroy()}},Ce=class{model;shaderPass;subPass;constructor(t,e,s){this.shaderPass=e,this.subPass=s;let n=s.action||s.filter&&"filter"||s.sampler&&"sample"||"filter",r=Ei({shaderPass:e,action:n,shadingLanguage:t.info.shadingLanguage});this.model=new J(t,{id:`${e.name}-subpass`,source:r,fs:r,modules:[e],parameters:{depthWriteEnabled:!1,depthCompare:"always"}})}destroy(){this.model.destroy()}render(t){let{renderPass:e,bindings:s}=t;this.model.shaderInputs.setProps({[this.shaderPass.name]:this.shaderPass.uniforms||{}}),this.model.shaderInputs.setProps({[this.shaderPass.name]:this.subPass.uniforms||{}}),this.model.setBindings(s||{}),this.model.draw(e)}};var U=L(j(),1),he=L(rt(),1);var Oe=2,Ws=1e4,Re=class{device;id;pipelineFactory;shaderFactory;userData={};bindings={};pipeline;source;shader;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={...Re.defaultProps,...e},e=this.props,this.id=e.id||O("model"),this.device=t,Object.assign(this.userData,e.userData);let s=Object.fromEntries(this.props.modules?.map(c=>[c.name,c])||[]);this.shaderInputs=e.shaderInputs||new Y(s),this.setShaderInputs(this.shaderInputs),this.props.shaderLayout||=(0,he.getShaderLayoutFromWGSL)(this.props.source);let n=Hs(t),r=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];this.pipelineFactory=e.pipelineFactory||Z.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||Q.getDefaultShaderFactory(this.device);let{source:o,getUniforms:a}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:n,...this.props,modules:r});this.source=o,this._getModuleUniforms=a,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,s,n){try{this._logDrawCallStart(),this.pipeline=this._updatePipeline(),this.pipeline.setBindings(this.bindings),t.setPipeline(this.pipeline),t.setBindings([]),t.dispatch(e,s,n)}finally{this._logDrawCallEnd()}}setVertexCount(t){}setInstanceCount(t){}setShaderInputs(t){this.shaderInputs=t,this._uniformStore=new U.UniformStore(this.shaderInputs.modules);for(let e of Object.keys(this.shaderInputs.modules)){let s=this._uniformStore.getManagedUniformBuffer(this.device,e);this.bindings[`${e}Uniforms`]=s}}setShaderModuleProps(t){let e=this._getModuleUniforms(t),s=Object.keys(e).filter(r=>{let o=e[r];return!_t(o)&&typeof o!="number"&&typeof o!="boolean"}),n={};for(let r of s)n[r]=e[r],delete e[r]}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&&(U.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,debugShaders: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=U.log.level>3?0:Ws;U.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,U.log.group(Oe,`>>> DRAWING MODEL ${this.id}`,{collapsed:U.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=this.shaderInputs.getDebugTable();U.log.table(Oe,t)(),U.log.groupEnd(Oe)(),this._logOpen=!1}}_drawCount=0;_getBufferOrConstantValues(t,e){let s=(0,U.getTypedArrayFromDataType)(e);return(t instanceof U.Buffer?new s(t.debugData):t).toString()}},Pt=Re;V(Pt,"defaultProps",{...U.ComputePipeline.defaultProps,id:"unnamed",handle:void 0,userData:{},source:"",modules:[],defines:{},bindings:void 0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,shaderAssembler:he.ShaderAssembler.getDefaultShaderAssembler(),debugShaders:void 0});function Hs(i){return{type:i.type,shaderLanguage:i.info.shadingLanguage,shaderLanguageVersion:i.info.shadingLanguageVersion,gpu:i.info.gpu,features:i.features}}var Ys=[0,1,1,1],X=-1,Xs={isActive:"i32",indexMode:"i32",batchIndex:"i32",isHighlightActive:"i32",highlightedBatchIndex:"i32",highlightedObjectIndex:"i32",highlightColor:"vec4<f32>"},yt=`precision highp float;
|
|
168
|
+
precision highp int;
|
|
169
|
+
|
|
170
|
+
uniform pickingUniforms {
|
|
171
|
+
int isActive;
|
|
172
|
+
int indexMode;
|
|
173
|
+
int batchIndex;
|
|
174
|
+
|
|
175
|
+
int isHighlightActive;
|
|
176
|
+
int highlightedBatchIndex;
|
|
177
|
+
int highlightedObjectIndex;
|
|
178
|
+
vec4 highlightColor;
|
|
179
|
+
} picking;
|
|
180
|
+
`,le=`struct pickingUniforms {
|
|
181
|
+
isActive: int32;
|
|
182
|
+
indexMode: int32;
|
|
183
|
+
batchIndex: int32;
|
|
184
|
+
|
|
185
|
+
isHighlightActive: int32;
|
|
186
|
+
highlightedBatchIndex: int32;
|
|
187
|
+
highlightedObjectIndex: int32;
|
|
188
|
+
highlightColor: vec4<f32>;
|
|
189
|
+
} picking;
|
|
190
|
+
`;function Ks(i={},t){let e={...t};switch(i.isActive!==void 0&&(e.isActive=Boolean(i.isActive)),i.indexMode){case"instance":e.indexMode=0;break;case"custom":e.indexMode=1;break;case void 0:break}switch(i.highlightedObjectIndex){case void 0:break;case null:e.isHighlightActive=!1,e.highlightedObjectIndex=X;break;default:e.isHighlightActive=!0,e.highlightedObjectIndex=i.highlightedObjectIndex}return typeof i.highlightedBatchIndex=="number"&&(e.highlightedBatchIndex=i.highlightedBatchIndex),i.highlightColor&&(e.highlightColor=i.highlightColor),e}var fe={props:{},uniforms:{},name:"picking",uniformTypes:Xs,defaultUniforms:{isActive:!1,indexMode:0,batchIndex:0,isHighlightActive:!0,highlightedBatchIndex:X,highlightedObjectIndex:X,highlightColor:Ys},getUniforms:Ks};var Ee=class{device;props;pickInfo={batchIndex:null,objectIndex:null};framebuffer=null;constructor(t,e){this.device=t,this.props={...Ee.defaultProps,...e}}destroy(){this.framebuffer?.destroy()}getFramebuffer(){return this.framebuffer||(this.framebuffer=this.device.createFramebuffer({colorAttachments:["rgba8unorm","rg32sint"],depthStencilAttachment:"depth24plus"})),this.framebuffer}clearPickState(){this.props.shaderInputs.setProps({picking:{highlightedObjectIndex:null}})}beginRenderPass(){let t=this.getFramebuffer();return t.resize(this.device.getDefaultCanvasContext().getPixelSize()),this.props.shaderInputs?.setProps({picking:{isActive:!0}}),this.device.beginRenderPass({framebuffer:t,clearColors:[new Float32Array([0,0,0,0]),new Int32Array([-1,-1,0,0])],clearDepth:1})}getPickInfo(t){let e=this.getFramebuffer(),[s,n]=this.getPickPosition(t),r=this.device.readPixelsToArrayWebGL(e,{sourceX:s,sourceY:n,sourceWidth:1,sourceHeight:1,sourceAttachment:1});if(!r)return null;let o={objectIndex:r[0]===X?null:r[0],batchIndex:r[1]===X?null:r[1]};return(o.objectIndex!==this.pickInfo.objectIndex||o.batchIndex!==this.pickInfo.batchIndex)&&(this.pickInfo=o,this.props.onObjectPicked(o)),this.props.shaderInputs?.setProps({picking:{isActive:!1,highlightedBatchIndex:o.batchIndex,highlightedObjectIndex:o.objectIndex}}),this.pickInfo}getPickPosition(t){let e=this.device.getDefaultCanvasContext().cssToDevicePixels(t),s=e.x+Math.floor(e.width/2),n=e.y+Math.floor(e.height/2);return[s,n]}},It=Ee;V(It,"defaultProps",{shaderInputs:void 0,onObjectPicked:()=>{}});var Zs=`${le}
|
|
191
|
+
|
|
192
|
+
const INDEX_PICKING_MODE_INSTANCE = 0;
|
|
193
|
+
const INDEX_PICKING_MODE_CUSTOM = 1;
|
|
194
|
+
const INDEX_PICKING_INVALID_INDEX = ${X}; // 2^32 - 1
|
|
195
|
+
|
|
196
|
+
struct indexPickingFragmentInputs = {
|
|
197
|
+
objectIndex: int32;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
let indexPickingFragmentInputs: indexPickingFragmentInputs;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Vertex shaders should call this function to set the object index.
|
|
204
|
+
* If using instance or vertex mode, argument will be ignored, 0 can be supplied.
|
|
205
|
+
*/
|
|
206
|
+
fn picking_setObjectIndex(objectIndex: int32) {
|
|
207
|
+
switch (picking.indexMode) {
|
|
208
|
+
case INDEX_PICKING_MODE_INSTANCE, default: {
|
|
209
|
+
picking_objectIndex = instance_index;
|
|
210
|
+
};
|
|
211
|
+
case INDEX_PICKING_MODE_CUSTOM: {
|
|
212
|
+
picking_objectIndex = objectIndex;
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
`,Qs=`${yt}
|
|
218
|
+
|
|
219
|
+
const int INDEX_PICKING_MODE_INSTANCE = 0;
|
|
220
|
+
const int INDEX_PICKING_MODE_CUSTOM = 1;
|
|
221
|
+
|
|
222
|
+
const int INDEX_PICKING_INVALID_INDEX = ${X}; // 2^32 - 1
|
|
223
|
+
|
|
224
|
+
flat out int picking_objectIndex;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Vertex shaders should call this function to set the object index.
|
|
228
|
+
* If using instance or vertex mode, argument will be ignored, 0 can be supplied.
|
|
229
|
+
*/
|
|
230
|
+
void picking_setObjectIndex(int objectIndex) {
|
|
231
|
+
switch (picking.indexMode) {
|
|
232
|
+
case INDEX_PICKING_MODE_INSTANCE:
|
|
233
|
+
picking_objectIndex = gl_InstanceID;
|
|
234
|
+
break;
|
|
235
|
+
case INDEX_PICKING_MODE_CUSTOM:
|
|
236
|
+
picking_objectIndex = objectIndex;
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
`,Js=`${yt}
|
|
241
|
+
|
|
242
|
+
const int INDEX_PICKING_INVALID_INDEX = ${X}; // 2^32 - 1
|
|
243
|
+
|
|
244
|
+
flat in int picking_objectIndex;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Check if this vertex is highlighted (part of the selected batch and object)
|
|
248
|
+
*/
|
|
249
|
+
bool picking_isFragmentHighlighted() {
|
|
250
|
+
return
|
|
251
|
+
bool(picking.isHighlightActive) &&
|
|
252
|
+
picking.highlightedBatchIndex == picking.batchIndex &&
|
|
253
|
+
picking.highlightedObjectIndex == picking_objectIndex
|
|
254
|
+
;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Returns highlight color if this item is selected.
|
|
259
|
+
*/
|
|
260
|
+
vec4 picking_filterHighlightColor(vec4 color) {
|
|
261
|
+
// If we are still picking, we don't highlight
|
|
262
|
+
if (bool(picking.isActive)) {
|
|
263
|
+
return color;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// If we are not highlighted, return color as is
|
|
267
|
+
if (!picking_isFragmentHighlighted()) {
|
|
268
|
+
return color;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Blend in highlight color based on its alpha value
|
|
272
|
+
float highLightAlpha = picking.highlightColor.a;
|
|
273
|
+
float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
|
|
274
|
+
float highLightRatio = highLightAlpha / blendedAlpha;
|
|
275
|
+
|
|
276
|
+
vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);
|
|
277
|
+
return vec4(blendedRGB, blendedAlpha);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/*
|
|
281
|
+
* Returns picking color if picking enabled else unmodified argument.
|
|
282
|
+
*/
|
|
283
|
+
ivec4 picking_getPickingColor() {
|
|
284
|
+
// Assumes that colorAttachment0 is rg32int
|
|
285
|
+
// TODO? - we could render indices into a second color attachment and not mess with fragColor
|
|
286
|
+
return ivec4(picking_objectIndex, picking.batchIndex, 0u, 0u);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
vec4 picking_filterPickingColor(vec4 color) {
|
|
290
|
+
if (bool(picking.isActive)) {
|
|
291
|
+
if (picking_objectIndex == INDEX_PICKING_INVALID_INDEX) {
|
|
292
|
+
discard;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return color;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/*
|
|
299
|
+
* Returns picking color if picking is enabled if not
|
|
300
|
+
* highlight color if this item is selected, otherwise unmodified argument.
|
|
301
|
+
*/
|
|
302
|
+
vec4 picking_filterColor(vec4 color) {
|
|
303
|
+
vec4 outColor = color;
|
|
304
|
+
outColor = picking_filterHighlightColor(outColor);
|
|
305
|
+
outColor = picking_filterPickingColor(outColor);
|
|
306
|
+
return outColor;
|
|
307
|
+
}
|
|
308
|
+
`,Li={...fe,name:"picking",source:Zs,vs:Qs,fs:Js};var tn=`${le}
|
|
309
|
+
`,en=`${yt}
|
|
310
|
+
out vec4 picking_vRGBcolor_Avalid;
|
|
311
|
+
|
|
312
|
+
// Normalize unsigned byte color to 0-1 range
|
|
313
|
+
vec3 picking_normalizeColor(vec3 color) {
|
|
314
|
+
return picking.useFloatColors > 0.5 ? color : color / 255.0;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Normalize unsigned byte color to 0-1 range
|
|
318
|
+
vec4 picking_normalizeColor(vec4 color) {
|
|
319
|
+
return picking.useFloatColors > 0.5 ? color : color / 255.0;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
bool picking_isColorZero(vec3 color) {
|
|
323
|
+
return dot(color, vec3(1.0)) < 0.00001;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
bool picking_isColorValid(vec3 color) {
|
|
327
|
+
return dot(color, vec3(1.0)) > 0.00001;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// Check if this vertex is highlighted
|
|
331
|
+
bool isVertexHighlighted(vec3 vertexColor) {
|
|
332
|
+
vec3 highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);
|
|
333
|
+
return
|
|
334
|
+
bool(picking.isHighlightActive) && picking_isColorZero(abs(vertexColor - highlightedObjectColor));
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Set the current picking color
|
|
338
|
+
void picking_setPickingColor(vec3 pickingColor) {
|
|
339
|
+
pickingColor = picking_normalizeColor(pickingColor);
|
|
340
|
+
|
|
341
|
+
if (bool(picking.isActive)) {
|
|
342
|
+
// Use alpha as the validity flag. If pickingColor is [0, 0, 0] fragment is non-pickable
|
|
343
|
+
picking_vRGBcolor_Avalid.a = float(picking_isColorValid(pickingColor));
|
|
344
|
+
|
|
345
|
+
if (!bool(picking.isAttribute)) {
|
|
346
|
+
// Stores the picking color so that the fragment shader can render it during picking
|
|
347
|
+
picking_vRGBcolor_Avalid.rgb = pickingColor;
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
// Do the comparison with selected item color in vertex shader as it should mean fewer compares
|
|
351
|
+
picking_vRGBcolor_Avalid.a = float(isVertexHighlighted(pickingColor));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
void picking_setObjectIndex(uint objectIndex) {
|
|
356
|
+
if (bool(picking.isActive)) {
|
|
357
|
+
uint index = objectIndex;
|
|
358
|
+
if (picking.indexMode == PICKING_INDEX_MODE_INSTANCE) {
|
|
359
|
+
index = uint(gl_InstanceID);
|
|
360
|
+
}
|
|
361
|
+
picking_vRGBcolor_Avalid.r = float(index % 255) / 255.0;
|
|
362
|
+
picking_vRGBcolor_Avalid.g = float((index / 255) % 255) / 255.0;
|
|
363
|
+
picking_vRGBcolor_Avalid.b = float((index / 255 / 255) %255) / 255.0;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
void picking_setPickingAttribute(float value) {
|
|
368
|
+
if (bool(picking.isAttribute)) {
|
|
369
|
+
picking_vRGBcolor_Avalid.r = value;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
void picking_setPickingAttribute(vec2 value) {
|
|
374
|
+
if (bool(picking.isAttribute)) {
|
|
375
|
+
picking_vRGBcolor_Avalid.rg = value;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
void picking_setPickingAttribute(vec3 value) {
|
|
380
|
+
if (bool(picking.isAttribute)) {
|
|
381
|
+
picking_vRGBcolor_Avalid.rgb = value;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
`,sn=`${yt}
|
|
385
|
+
|
|
386
|
+
in vec4 picking_vRGBcolor_Avalid;
|
|
387
|
+
|
|
388
|
+
/*
|
|
389
|
+
* Returns highlight color if this item is selected.
|
|
390
|
+
*/
|
|
391
|
+
vec4 picking_filterHighlightColor(vec4 color) {
|
|
392
|
+
// If we are still picking, we don't highlight
|
|
393
|
+
if (picking.isActive > 0.5) {
|
|
394
|
+
return color;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
bool selected = bool(picking_vRGBcolor_Avalid.a);
|
|
398
|
+
|
|
399
|
+
if (selected) {
|
|
400
|
+
// Blend in highlight color based on its alpha value
|
|
401
|
+
float highLightAlpha = picking.highlightColor.a;
|
|
402
|
+
float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
|
|
403
|
+
float highLightRatio = highLightAlpha / blendedAlpha;
|
|
404
|
+
|
|
405
|
+
vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);
|
|
406
|
+
return vec4(blendedRGB, blendedAlpha);
|
|
407
|
+
} else {
|
|
408
|
+
return color;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/*
|
|
413
|
+
* Returns picking color if picking enabled else unmodified argument.
|
|
414
|
+
*/
|
|
415
|
+
vec4 picking_filterPickingColor(vec4 color) {
|
|
416
|
+
if (bool(picking.isActive)) {
|
|
417
|
+
if (picking_vRGBcolor_Avalid.a == 0.0) {
|
|
418
|
+
discard;
|
|
419
|
+
}
|
|
420
|
+
return picking_vRGBcolor_Avalid;
|
|
421
|
+
}
|
|
422
|
+
return color;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/*
|
|
426
|
+
* Returns picking color if picking is enabled if not
|
|
427
|
+
* highlight color if this item is selected, otherwise unmodified argument.
|
|
428
|
+
*/
|
|
429
|
+
vec4 picking_filterColor(vec4 color) {
|
|
430
|
+
vec4 highlightColor = picking_filterHighlightColor(color);
|
|
431
|
+
return picking_filterPickingColor(highlightColor);
|
|
115
432
|
}
|
|
116
|
-
`,wr=[-1,-1,1,-1,-1,1,1,1],Ge=class extends Z{constructor(t,e){let n=wr.map(r=>r===-1?0:r);super(t,{...e,vs:Oi,vertexCount:4,geometry:new G({topology:"triangle-strip",vertexCount:4,attributes:{aClipSpacePosition:{size:2,value:new Float32Array(wr)},aTexCoord:{size:2,value:new Float32Array(n)},aCoordinate:{size:2,value:new Float32Array(n)}}})})}};var lt=class{id;matrix=new tt;display=!0;position=new W;rotation=new W;scale=new W(1,1,1);userData={};props={};constructor(t={}){let{id:e}=t;this.id=e||C(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 this.position=t,this}setRotation(t){return this.rotation=t,this}setScale(t){return 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){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){"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 kr=$(D(),1);var Ut=class extends lt{children;constructor(t={}){t=Array.isArray(t)?{children:t}:t;let{children:e=[]}=t;kr.log.assert(e.every(n=>n instanceof lt),"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 W(i).add(o).divide([2,2,2]);n.transformAsPoint(c,c);let h=new W(o).subtract(i).divide([2,2,2]);n.transformAsVector(h,h);for(let f=0;f<8;f++){let m=new W(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 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 We=class extends lt{model;bounds=null;managedResources;constructor(t){super(t),this.model=t.model,this.managedResources=t.managedResources||[],this.bounds=t.bounds||null,this.setProps(t)}destroy(){this.model&&(this.model.destroy(),this.model=null),this.managedResources.forEach(t=>t.destroy()),this.managedResources=[]}getBounds(){return this.bounds}draw(t){return this.model.draw(t)}};var Pi={x:[2,0,1],y:[0,1,2],z:[1,2,0]},_t=class extends G{constructor(t={}){let{id:e=C("truncated-code-geometry")}=t,{indices:n,attributes:r}=Ii(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 Ii(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=Pi[o],A=new Float32Array(m*3),T=new Float32Array(m*3),R=new Float32Array(m*2),O=0,L=0;for(let E=M;E<=b;E++){let I=E/i,N=n*I,P;E<0?(N=0,I=1,P=t):E>i?(N=n,I=1,P=e):P=t+(e-t)*(E/i),(E===-2||E===i+2)&&(P=0,I=0),N-=n/2;for(let q=0;q<x;q++){let st=_(q*S*2/r),J=y(q*S*2/r);A[O+v[0]]=st*P,A[O+v[1]]=N,A[O+v[2]]=J*P,T[O+v[0]]=E<0||E>i?0:st*g,T[O+v[1]]=E<0?-1:E>i?1:w,T[O+v[2]]=E<0||E>i?0:J*g,R[L+0]=q/r,R[L+1]=I,L+=2,O+=3}}for(let E=0;E<i+f;E++)for(let I=0;I<r;I++){let N=(E*r+I)*6;k[N+0]=x*(E+0)+0+I,k[N+1]=x*(E+0)+1+I,k[N+2]=x*(E+1)+1+I,k[N+3]=x*(E+0)+0+I,k[N+4]=x*(E+1)+1+I,k[N+5]=x*(E+1)+0+I}return{indices:k,attributes:{POSITION:A,NORMAL:T,TEXCOORD_0:R}}}var He=class extends _t{constructor(t={}){let{id:e=C("cone-geometry"),radius:n=1,cap:r=!0}=t;super({...t,id:e,topRadius:0,topCap:Boolean(r),bottomCap:Boolean(r),bottomRadius:n})}};var Ye=class extends G{constructor(t={}){let{id:e=C("cube-geometry"),indices:n=!0}=t;super(n?{...t,id:e,topology:"triangle-list",indices:{size:1,value:Li},attributes:{...Ui,...t.attributes}}:{...t,id:e,topology:"triangle-list",indices:void 0,attributes:{...qi,...t.attributes}})}},Li=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]),Ni=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]),Ri=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]),zi=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]),Ci=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]),Fi=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]),Di=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]),Ui={POSITION:{size:3,value:Ni},NORMAL:{size:3,value:Ri},TEXCOORD_0:{size:2,value:zi}},qi={POSITION:{size:3,value:Ci},TEXCOORD_0:{size:2,value:Fi},COLOR_0:{size:3,value:Di}};var Xe=class extends _t{constructor(t={}){let{id:e=C("cylinder-geometry"),radius:n=1}=t;super({...t,id:e,bottomRadius:n,topRadius:n})}};var $i=[-1,0,0,0,1,0,0,0,-1,0,0,1,0,-1,0,1,0,0],Bi=[3,4,5,3,5,1,3,1,0,3,0,4,4,0,2,4,2,5,2,0,1,5,2,1],Ke=class extends G{constructor(t={}){let{id:e=C("ico-sphere-geometry")}=t,{indices:n,attributes:r}=Vi(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{...r,...t.attributes}})}};function Vi(s){let{iterations:t=0}=s,e=Math.PI,n=e*2,r=[...$i],i=[...Bi];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,L=1-R/n,E=r[g+0],I=r[g+1],N=r[g+2],P=Math.acos(N/Math.sqrt(E*E+I*I+N*N)),q=Math.atan2(I,E)+e,st=P/e,J=1-q/n,se=r[w+0],ne=r[w+1],re=r[w+2],Sr=Math.acos(re/Math.sqrt(se*se+ne*ne+re*re)),Ar=Math.atan2(ne,se)+e,rn=Sr/e,ie=1-Ar/n,Er=[se-E,ne-I,re-N],Tr=[k-E,v-I,A-N],Y=new W(Er).cross(Tr).normalize(),F;(L===0||J===0||ie===0)&&(L===0||L>.5)&&(J===0||J>.5)&&(ie===0||ie>.5)&&(r.push(r[S+0],r[S+1],r[S+2]),F=r.length/3-1,i.push(F),h[F*2+0]=1,h[F*2+1]=O,c[F*3+0]=Y.x,c[F*3+1]=Y.y,c[F*3+2]=Y.z,r.push(r[g+0],r[g+1],r[g+2]),F=r.length/3-1,i.push(F),h[F*2+0]=1,h[F*2+1]=st,c[F*3+0]=Y.x,c[F*3+1]=Y.y,c[F*3+2]=Y.z,r.push(r[w+0],r[w+1],r[w+2]),F=r.length/3-1,i.push(F),h[F*2+0]=1,h[F*2+1]=rn,c[F*3+0]=Y.x,c[F*3+1]=Y.y,c[F*3+2]=Y.z),c[S+0]=c[g+0]=c[w+0]=Y.x,c[S+1]=c[g+1]=c[w+1]=Y.y,c[S+2]=c[g+2]=c[w+2]=Y.z,h[M+0]=L,h[M+1]=O,h[b+0]=J,h[b+1]=st,h[x+0]=ie,h[x+1]=rn}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)}}}}function vr(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 Ze=class extends G{constructor(t={}){let{id:e=C("plane-geometry")}=t,{indices:n,attributes:r}=ji(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{...r,...t.attributes}})}};function ji(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?vr(b):b}var Je=class extends G{constructor(t={}){let{id:e=C("sphere-geometry")}=t,{indices:n,attributes:r}=Gi(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{...r,...t.attributes}})}};function Gi(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,L=Math.sin(R),E=Math.cos(R),I=Math.sin(O),N=Math.cos(O),P=E*I,q=N,st=L*I,J=m(P,q,st,x,k);p[T+0]=J*P,p[T+1]=J*q,p[T+2]=J*st,_[T+0]=P,_[T+1]=q,_[T+2]=st,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}}}}function br(){let s=1,t=1;return()=>(s=Math.sin(t*17.23),t=Math.cos(s*27.92),Wi(Math.abs(s*t)*1432.71))}function Wi(s){return s-Math.floor(s)}var qt=$(D(),1),gt=$(D(),1),Mr=$(D(),1);var sn=2,Hi=1e4,nn=class{device;id;pipelineFactory;shaderFactory;userData={};bindings={};pipeline;source;shader;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={...nn.defaultProps,...e},e=this.props,this.id=e.id||C("model"),this.device=t,Object.assign(this.userData,e.userData);let n=Object.fromEntries(this.props.modules?.map(h=>[h.name,h])||[]);this.shaderInputs=e.shaderInputs||new pt(n),this.setShaderInputs(this.shaderInputs),this.props.shaderLayout||=Zt(this.props.source);let r=Yi(t),i=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];this.pipelineFactory=e.pipelineFactory||at.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||ct.getDefaultShaderFactory(this.device);let{source:o,getUniforms:c}=this.props.shaderAssembler.assembleWGSLShader({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!Qt(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&&(gt.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=gt.log.level>3?0:Hi;gt.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,gt.log.group(sn,`>>> DRAWING MODEL ${this.id}`,{collapsed:gt.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=this.shaderInputs.getDebugTable();gt.log.table(sn,t)(),gt.log.groupEnd(sn)(),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()}},te=nn;et(te,"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:ut.getDefaultShaderAssembler(),debugShaders:void 0});function Yi(s){return{type:s.type,shaderLanguage:s.info.shadingLanguage,shaderLanguageVersion:s.info.shadingLanguageVersion,gpu:s.info.gpu,features:s.features}}return Fr(ee);})();
|
|
433
|
+
`,Ni={...fe,name:"picking",source:tn,vs:en,fs:sn};var de=class{device;framebuffer=null;shaderInputs;constructor(t,e){this.device=t,this.shaderInputs=e}destroy(){this.framebuffer?.destroy()}getFramebuffer(){return this.framebuffer||(this.framebuffer=this.device.createFramebuffer({colorAttachments:["rgba8unorm"],depthStencilAttachment:"depth24plus"})),this.framebuffer}clearPickState(){this.shaderInputs.setProps({picking:{highlightedObjectColor:null}})}beginRenderPass(){let t=this.getFramebuffer();return t.resize(this.device.getCanvasContext().getPixelSize()),this.shaderInputs.setProps({picking:{isActive:!0}}),this.device.beginRenderPass({framebuffer:t,clearColor:[0,0,0,0],clearDepth:1})}updatePickState(t){let e=this.getFramebuffer(),[s,n]=this.getPickPosition(t),o=[...this.device.readPixelsToArrayWebGL(e,{sourceX:s,sourceY:n,sourceWidth:1,sourceHeight:1})].map(c=>c/255);o[0]+o[1]+o[2]>0||(o=null),this.shaderInputs.setProps({picking:{isActive:!1,highlightedObjectColor:o}})}getPickPosition(t){let e=this.device.getCanvasContext().cssToDevicePixels(t),s=e.x+Math.floor(e.width/2),n=e.y+Math.floor(e.height/2);return[s,n]}};return Hi(St);})();
|
|
117
434
|
return __exports__;
|
|
118
435
|
});
|