@luma.gl/engine 9.3.0-alpha.2 → 9.3.0-alpha.6

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.
Files changed (87) hide show
  1. package/dist/animation-loop/animation-loop.d.ts +8 -4
  2. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  3. package/dist/animation-loop/animation-loop.js +70 -43
  4. package/dist/animation-loop/animation-loop.js.map +1 -1
  5. package/dist/animation-loop/make-animation-loop.js +7 -1
  6. package/dist/animation-loop/make-animation-loop.js.map +1 -1
  7. package/dist/animation-loop/request-animation-frame.d.ts.map +1 -1
  8. package/dist/animation-loop/request-animation-frame.js +23 -6
  9. package/dist/animation-loop/request-animation-frame.js.map +1 -1
  10. package/dist/dist.dev.js +442 -209
  11. package/dist/dist.min.js +37 -79
  12. package/dist/dynamic-texture/dynamic-texture.d.ts +3 -3
  13. package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
  14. package/dist/dynamic-texture/dynamic-texture.js +187 -36
  15. package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
  16. package/dist/dynamic-texture/texture-data.d.ts +4 -0
  17. package/dist/dynamic-texture/texture-data.d.ts.map +1 -1
  18. package/dist/dynamic-texture/texture-data.js +9 -1
  19. package/dist/dynamic-texture/texture-data.js.map +1 -1
  20. package/dist/factories/pipeline-factory.d.ts +7 -5
  21. package/dist/factories/pipeline-factory.d.ts.map +1 -1
  22. package/dist/factories/pipeline-factory.js +71 -36
  23. package/dist/factories/pipeline-factory.js.map +1 -1
  24. package/dist/factories/shader-factory.d.ts +0 -3
  25. package/dist/factories/shader-factory.d.ts.map +1 -1
  26. package/dist/factories/shader-factory.js +13 -19
  27. package/dist/factories/shader-factory.js.map +1 -1
  28. package/dist/geometries/cone-geometry.d.ts +3 -1
  29. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  30. package/dist/geometries/cone-geometry.js.map +1 -1
  31. package/dist/geometries/cylinder-geometry.d.ts +2 -1
  32. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  33. package/dist/geometries/cylinder-geometry.js.map +1 -1
  34. package/dist/index.cjs +433 -208
  35. package/dist/index.cjs.map +2 -2
  36. package/dist/model/model.d.ts +3 -1
  37. package/dist/model/model.d.ts.map +1 -1
  38. package/dist/model/model.js +11 -9
  39. package/dist/model/model.js.map +1 -1
  40. package/dist/models/billboard-texture-model.d.ts.map +1 -1
  41. package/dist/models/billboard-texture-model.js +10 -8
  42. package/dist/models/billboard-texture-model.js.map +1 -1
  43. package/dist/models/clip-space.js +7 -7
  44. package/dist/modules/picking/index-picking.d.ts +1 -1
  45. package/dist/modules/picking/index-picking.d.ts.map +1 -1
  46. package/dist/modules/picking/index-picking.js +0 -6
  47. package/dist/modules/picking/index-picking.js.map +1 -1
  48. package/dist/passes/get-fragment-shader.js +11 -30
  49. package/dist/passes/get-fragment-shader.js.map +1 -1
  50. package/dist/passes/shader-pass-renderer.d.ts +0 -2
  51. package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
  52. package/dist/passes/shader-pass-renderer.js +4 -31
  53. package/dist/passes/shader-pass-renderer.js.map +1 -1
  54. package/dist/scenegraph/group-node.d.ts +5 -0
  55. package/dist/scenegraph/group-node.d.ts.map +1 -1
  56. package/dist/scenegraph/group-node.js +12 -0
  57. package/dist/scenegraph/group-node.js.map +1 -1
  58. package/dist/scenegraph/model-node.d.ts +2 -2
  59. package/dist/scenegraph/model-node.d.ts.map +1 -1
  60. package/dist/scenegraph/model-node.js.map +1 -1
  61. package/dist/scenegraph/scenegraph-node.d.ts +1 -1
  62. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
  63. package/dist/scenegraph/scenegraph-node.js +23 -15
  64. package/dist/scenegraph/scenegraph-node.js.map +1 -1
  65. package/dist/utils/buffer-layout-order.d.ts.map +1 -1
  66. package/dist/utils/buffer-layout-order.js +12 -2
  67. package/dist/utils/buffer-layout-order.js.map +1 -1
  68. package/package.json +4 -4
  69. package/src/animation-loop/animation-loop.ts +75 -46
  70. package/src/animation-loop/make-animation-loop.ts +13 -5
  71. package/src/animation-loop/request-animation-frame.ts +32 -6
  72. package/src/dynamic-texture/dynamic-texture.ts +248 -39
  73. package/src/dynamic-texture/texture-data.ts +15 -1
  74. package/src/factories/pipeline-factory.ts +87 -46
  75. package/src/factories/shader-factory.ts +16 -20
  76. package/src/geometries/cone-geometry.ts +6 -1
  77. package/src/geometries/cylinder-geometry.ts +5 -1
  78. package/src/model/model.ts +14 -10
  79. package/src/models/billboard-texture-model.ts +10 -8
  80. package/src/models/clip-space.ts +7 -7
  81. package/src/modules/picking/index-picking.ts +0 -6
  82. package/src/passes/get-fragment-shader.ts +11 -30
  83. package/src/passes/shader-pass-renderer.ts +4 -33
  84. package/src/scenegraph/group-node.ts +16 -0
  85. package/src/scenegraph/model-node.ts +2 -2
  86. package/src/scenegraph/scenegraph-node.ts +27 -16
  87. package/src/utils/buffer-layout-order.ts +18 -2
package/dist/dist.min.js CHANGED
@@ -4,10 +4,10 @@
4
4
  else if (typeof define === 'function' && define.amd) define([], factory);
5
5
  else if (typeof exports === 'object') exports['luma'] = factory();
6
6
  else root['luma'] = factory();})(globalThis, function () {
7
- "use strict";var __exports__=(()=>{var ii=Object.create;var At=Object.defineProperty;var ri=Object.getOwnPropertyDescriptor;var ni=Object.getOwnPropertyNames;var oi=Object.getPrototypeOf,ai=Object.prototype.hasOwnProperty;var ci=(s,t,e)=>t in s?At(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var Be=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports),hi=(s,t)=>{for(var e in t)At(s,e,{get:t[e],enumerable:!0})},Bt=(s,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ni(t))!ai.call(s,r)&&r!==e&&At(s,r,{get:()=>t[r],enumerable:!(i=ri(t,r))||i.enumerable});return s},$t=(s,t,e)=>(Bt(s,t,"default"),e&&Bt(e,t,"default")),L=(s,t,e)=>(e=s!=null?ii(oi(s)):{},Bt(t||!s||!s.__esModule?At(e,"default",{value:s,enumerable:!0}):e,s)),li=s=>Bt(At({},"__esModule",{value:!0}),s);var z=(s,t,e)=>(ci(s,typeof t!="symbol"?t+"":t,e),e);var B=Be((Cr,$e)=>{$e.exports=globalThis.luma});var ht=Be((Xr,Ge)=>{Ge.exports=globalThis.luma});var Lt={};hi(Lt,{AnimationLoop:()=>ct,AnimationLoopTemplate:()=>Vt,AsyncTexture:()=>Tr,BackgroundTextureModel:()=>gt,BufferTransform:()=>Rt,ClipSpace:()=>st,Computation:()=>Ot,ConeGeometry:()=>ne,CubeGeometry:()=>oe,CylinderGeometry:()=>ae,DynamicTexture:()=>q,GPUGeometry:()=>ut,Geometry:()=>$,GroupNode:()=>vt,IcoSphereGeometry:()=>ce,KeyFrames:()=>jt,LegacyPickingManager:()=>me,Model:()=>Y,ModelNode:()=>re,PickingManager:()=>kt,PipelineFactory:()=>tt,PlaneGeometry:()=>he,ScenegraphNode:()=>rt,ShaderFactory:()=>et,ShaderInputs:()=>K,ShaderPassRenderer:()=>fe,SphereGeometry:()=>le,Swap:()=>Mt,SwapBuffers:()=>de,SwapFramebuffers:()=>_t,TextureTransform:()=>Ht,Timeline:()=>Ut,TruncatedConeGeometry:()=>ot,cancelAnimationFramePolyfill:()=>qt,colorPicking:()=>Qs,indexPicking:()=>Zs,loadImage:()=>Ys,loadImageBitmap:()=>Ws,makeAnimationLoop:()=>Ve,makeRandomGenerator:()=>Gs,requestAnimationFramePolyfill:()=>Gt,setPathPrefix:()=>qs});$t(Lt,L(B(),1));var di=1,fi=1,Ut=class{time=0;channels=new Map;animations=new Map;playing=!1;lastEngineTime=-1;constructor(){}addChannel(t){let{delay:e=0,duration:i=Number.POSITIVE_INFINITY,rate:r=1,repeat:n=1}=t,o=di++,a={time:0,delay:e,duration:i,rate:r,repeat:n};return this._setChannelTime(a,this.time),this.channels.set(o,a),o}removeChannel(t){this.channels.delete(t);for(let[e,i]of this.animations)i.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 i=this.animations.values();for(let r of i){let{animation:n,channel:o}=r;n.setTime(this.getTime(o))}}play(){this.playing=!0}pause(){this.playing=!1,this.lastEngineTime=-1}reset(){this.setTime(0)}attachAnimation(t,e){let i=fi++;return this.animations.set(i,{animation:t,channel:e}),t.setTime(this.getTime(e)),i}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 i=e-t.delay,r=t.duration*t.repeat;i>=r?t.time=t.duration*t.rate:(t.time=Math.max(0,i)%t.duration,t.time*=t.rate)}};var jt=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 i=0;i<e;++i)this.times[i]=t[i][0],this.values[i]=t[i][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,i=this.times.length;for(e=0;e<i-2&&!(this.times[e+1]>t);++e);this.startIndex=e,this.endIndex=e+1;let r=this.times[this.startIndex],n=this.times[this.endIndex];this.factor=Math.min(Math.max(0,(t-r)/(n-r)),1)}};var Vt=class{constructor(t){}async onInitialize(t){return null}};var Ue=L(B(),1);function Gt(s){return typeof window<"u"&&window.requestAnimationFrame?window.requestAnimationFrame(s):setTimeout(s,1e3/60)}function qt(s){return typeof window<"u"&&window.cancelAnimationFrame?window.cancelAnimationFrame(s):clearTimeout(s)}function St(){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 at=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=St(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(St()-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 ft=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:i}=t,r=this.stats[e];return r||(t instanceof at?r=t:r=new at(e,i),this.stats[e]=r),r}};var ui=0,ge=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={...ge.defaultAnimationLoopProps,...t},t=this.props,!t.device)throw new Error("No device provided");this.stats=t.stats||new ft({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}),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()}reportError(t){this.props.onError(t),this._error=t}setNeedsRedraw(t){return this._needsRedraw=this._needsRedraw||t,this}needsRedraw(){let t=this._needsRedraw;return this._needsRedraw=!1,t}setProps(t){return"autoResizeViewport"in t&&(this.props.autoResizeViewport=t.autoResizeViewport||!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._resizeViewport()}_setDisplay(t){this.display&&(this.display.destroy(),this.display.animationLoop=null),t&&(t.animationLoop=this),this.display=t}_requestAnimationFrame(){this._running&&(this._animationFrameId=Gt(this._animationFrame.bind(this)))}_cancelAnimationFrame(){this._animationFrameId!==null&&(qt(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._resizeViewport()}_initializeAnimationProps(){let t=this.device?.getDefaultCanvasContext();if(!this.device||!t)throw new Error("loop");let e=t?.canvas,i=t.props.useDevicePixels;this.animationProps={animationLoop:this,device:this.device,canvasContext:t,canvas:e,useDevicePixels:i,timeline:this.timeline,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:i}=this._getSizeAndAspect();(t!==this.animationProps.width||e!==this.animationProps.height)&&this.setNeedsRedraw("drawing buffer resized"),i!==this.animationProps.aspect&&this.setNeedsRedraw("drawing buffer aspect changed"),this.animationProps.width=t,this.animationProps.height=e,this.animationProps.aspect=i,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.getDefaultCanvasContext().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 i=this.props.onAddHTML(e);i&&(e.innerHTML=i)}}_getSizeAndAspect(){if(!this.device)return{width:1,height:1,aspect:1};let[t,e]=this.device?.getDefaultCanvasContext().getDevicePixelSize()||[1,1],i=1,r=this.device?.getDefaultCanvasContext().canvas;return r&&r.clientHeight?i=r.clientWidth/r.clientHeight:t>0&&e>0&&(i=t/e),{width:t,height:e,aspect:i}}_resizeViewport(){this.props.autoResizeViewport&&this.device.gl&&this.device.gl.viewport(0,0,this.device.gl.drawingBufferWidth,this.device.gl.drawingBufferHeight)}_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}},ct=ge;z(ct,"defaultAnimationLoopProps",{device:null,onAddHTML:()=>"",onInitialize:async()=>null,onRender:()=>{},onFinalize:()=>{},onError:t=>console.error(t),stats:Ue.luma.stats.get(`animation-loop-${ui++}`),autoResizeViewport:!1});var je=L(B(),1);function Ve(s,t){let e=null,i=t?.device||je.luma.createDevice({id:"animation-loop",adapters:t?.adapters,createCanvasContext:!0}),r=new ct({...t,device:i,async onInitialize(n){mi(n.animationLoop.device);try{return e=new s(n),await e?.onInitialize(n)}catch(o){return pi(n.animationLoop.device,o),null}},onRender:n=>e?.onRender(n),onFinalize:n=>e?.onFinalize(n)});return r.getInfo=()=>this.AnimationLoopTemplateCtor.info,r}function pi(s,t){let e=s?.getDefaultCanvasContext().canvas;if(e instanceof HTMLCanvasElement){e.style.overflow="visible";let i=document.getElementById("animation-loop-error");i?.remove(),i=document.createElement("h1"),i.id="animation-loop-error",i.innerHTML=t.message,i.style.position="absolute",i.style.top="10px",i.style.left="10px",i.style.color="black",i.style.backgroundColor="red",e.parentElement?.appendChild(i)}}function mi(s){let t=document.getElementById("animation-loop-error");t&&t.remove()}var T=L(B(),1),cs=L(ht(),1);var Tt=L(B(),1);var xe={};function C(s="id"){xe[s]=xe[s]||1;let t=xe[s]++;return`${s}-${t}`}var ut=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&Tt.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 qe(s,t){if(t instanceof ut)return t;let e=gi(s,t),{attributes:i,bufferLayout:r}=xi(s,t);return new ut({topology:t.topology||"triangle-list",bufferLayout:r,vertexCount:t.vertexCount,indices:e,attributes:i})}function gi(s,t){if(!t.indices)return;let e=t.indices.value;return s.createBuffer({usage:Tt.Buffer.INDEX,data:e})}function xi(s,t){let e=[],i={};for(let[n,o]of Object.entries(t.attributes)){let a=n;switch(n){case"POSITION":a="positions";break;case"NORMAL":a="normals";break;case"TEXCOORD_0":a="texCoords";break;case"COLOR_0":a="colors";break}if(o){i[a]=s.createBuffer({data:o.value,id:`${n}-buffer`});let{value:c,size:h,normalized:l}=o;e.push({name:a,format:(0,Tt.getVertexFormatFromAttribute)(c,h,l)})}}let r=t._calculateVertexCount(t.attributes,t.indices);return{attributes:i,bufferLayout:e,vertexCount:r}}var V=L(B(),1);var ye=class{static getDefaultPipelineFactory(t){let e=t.getModuleData("@luma.gl/engine");return e.defaultPipelineFactory||=new ye(t),e.defaultPipelineFactory}device;cachingEnabled;destroyPolicy;debug;_hashCounter=0;_hashes={};_renderPipelineCache={};_computePipelineCache={};get[Symbol.toStringTag](){return"PipelineFactory"}toString(){return`PipelineFactory(${this.device.id})`}constructor(t){this.device=t,this.cachingEnabled=t.props._cachePipelines,this.destroyPolicy=t.props._cacheDestroyPolicy,this.debug=t.props.debugFactories}createRenderPipeline(t){if(!this.cachingEnabled)return this.device.createRenderPipeline(t);let e={...V.RenderPipeline.defaultProps,...t},i=this._renderPipelineCache,r=this._hashRenderPipeline(e),n=i[r]?.pipeline;return n?(i[r].useCount++,this.debug&&V.log.log(3,`${this}: ${i[r].pipeline} reused, count=${i[r].useCount}, (id=${t.id})`)()):(n=this.device.createRenderPipeline({...e,id:e.id?`${e.id}-cached`:C("unnamed-cached")}),n.hash=r,i[r]={pipeline:n,useCount:1},this.debug&&V.log.log(3,`${this}: ${n} created, count=${i[r].useCount}`)()),n}createComputePipeline(t){if(!this.cachingEnabled)return this.device.createComputePipeline(t);let e={...V.ComputePipeline.defaultProps,...t},i=this._computePipelineCache,r=this._hashComputePipeline(e),n=i[r]?.pipeline;return n?(i[r].useCount++,this.debug&&V.log.log(3,`${this}: ${i[r].pipeline} reused, count=${i[r].useCount}, (id=${t.id})`)()):(n=this.device.createComputePipeline({...e,id:e.id?`${e.id}-cached`:void 0}),n.hash=r,i[r]={pipeline:n,useCount:1},this.debug&&V.log.log(3,`${this}: ${n} created, count=${i[r].useCount}`)()),n}release(t){if(!this.cachingEnabled){t.destroy();return}let e=this._getCache(t),i=t.hash;e[i].useCount--,e[i].useCount===0?(this._destroyPipeline(t),this.debug&&V.log.log(3,`${this}: ${t} released and destroyed`)()):e[i].useCount<0?(V.log.error(`${this}: ${t} released, useCount < 0, resetting`)(),e[i].useCount=0):this.debug&&V.log.log(3,`${this}: ${t} released, count=${e[i].useCount}`)()}_destroyPipeline(t){let e=this._getCache(t);switch(this.destroyPolicy){case"never":return!1;case"unused":return delete e[t.hash],t.destroy(),!0}}_getCache(t){let e;if(t instanceof V.ComputePipeline&&(e=this._computePipelineCache),t instanceof V.RenderPipeline&&(e=this._renderPipelineCache),!e)throw new Error(`${this}`);if(!e[t.hash])throw new Error(`${this}: ${t} matched incorrect entry`);return e}_hashComputePipeline(t){let{type:e}=this.device,i=this._getHash(t.shader.source);return`${e}/C/${i}`}_hashRenderPipeline(t){let e=t.vs?this._getHash(t.vs.source):0,i=t.fs?this._getHash(t.fs.source):0,r="-",n=this._getHash(JSON.stringify(t.bufferLayout)),{type:o}=this.device;switch(o){case"webgl":return`${o}/R/${e}/${i}V${r}BL${n}`;case"webgpu":default:let a=this._getHash(JSON.stringify(t.parameters));return`${o}/R/${e}/${i}V${r}T${t.topology}P${a}BL${n}`}}_getHash(t){return this._hashes[t]===void 0&&(this._hashes[t]=this._hashCounter++),this._hashes[t]}},tt=ye;z(tt,"defaultProps",{...V.RenderPipeline.defaultProps});var lt=L(B(),1);var be=class{static getDefaultShaderFactory(t){let e=t.getModuleData("@luma.gl/engine");return e.defaultShaderFactory||=new be(t),e.defaultShaderFactory}device;cachingEnabled;destroyPolicy;debug;_cache={};get[Symbol.toStringTag](){return"ShaderFactory"}toString(){return`${this[Symbol.toStringTag]}(${this.device.id})`}constructor(t){this.device=t,this.cachingEnabled=t.props._cacheShaders,this.destroyPolicy=t.props._cacheDestroyPolicy,this.debug=!0}createShader(t){if(!this.cachingEnabled)return this.device.createShader(t);let e=this._hashShader(t),i=this._cache[e];if(i)i.useCount++,this.debug&&lt.log.log(3,`${this}: Reusing shader ${i.shader.id} count=${i.useCount}`)();else{let r=this.device.createShader({...t,id:t.id?`${t.id}-cached`:void 0});this._cache[e]=i={shader:r,useCount:1},this.debug&&lt.log.log(3,`${this}: Created new shader ${r.id}`)()}return i.shader}release(t){if(!this.cachingEnabled){t.destroy();return}let e=this._hashShader(t),i=this._cache[e];if(i)if(i.useCount--,i.useCount===0)this.destroyPolicy==="unused"&&(delete this._cache[e],i.shader.destroy(),this.debug&&lt.log.log(3,`${this}: Releasing shader ${t.id}, destroyed`)());else{if(i.useCount<0)throw new Error(`ShaderFactory: Shader ${t.id} released too many times`);this.debug&&lt.log.log(3,`${this}: Releasing shader ${t.id} count=${i.useCount}`)()}}_hashShader(t){return`${t.stage}:${t.source}`}},et=be;z(et,"defaultProps",{...lt.Shader.defaultProps});function We(s,t){let e={},i="Values";if(s.attributes.length===0&&!s.varyings?.length)return{"No attributes or varyings":{[i]:"N/A"}};for(let r of s.attributes)if(r){let n=`${r.location} ${r.name}: ${r.type}`;e[`in ${n}`]={[i]:r.stepMode||"vertex"}}for(let r of s.varyings||[]){let n=`${r.location} ${r.name}`;e[`out ${n}`]={[i]:JSON.stringify(r)}}return e}var N=null,ve=null;function Ye(s,{id:t,minimap:e,opaque:i,top:r="0",left:n="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=r,N.style.left=n,N.style.border="blue 5px solid",N.style.transform="scaleY(-1)",document.body.appendChild(N),ve=N.getContext("2d")),(N.width!==s.width||N.height!==s.height)&&(N.width=s.width/2,N.height=s.height/2,N.style.width="400px",N.style.height="400px");let a=s.device.readPixelsToArrayWebGL(s),c=ve?.createImageData(s.width,s.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]=i?255:a[l+3]*o;ve?.putImageData(c,0,0)}}function Wt(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 i=0;i<s.length;i++)if(!Wt(s[i],t[i],e-1))return!1;return!0}if(Array.isArray(t))return!1;if(typeof s=="object"&&typeof t=="object"){let i=Object.keys(s),r=Object.keys(t);if(i.length!==r.length)return!1;for(let n of i)if(!t.hasOwnProperty(n)||!Wt(s[n],t[n],e-1))return!1;return!0}return!1}var Xe=L(B(),1),pt=class{bufferLayouts;constructor(t){this.bufferLayouts=t}getBufferLayout(t){return this.bufferLayouts.find(e=>e.name===t)||null}getAttributeNamesForBuffer(t){return t.attributes?t.attributes?.map(e=>e.attribute):[t.name]}mergeBufferLayouts(t,e){let i=[...t];for(let r of e){let n=i.findIndex(o=>o.name===r.name);n<0?i.push(r):i[n]=r}return i}getBufferIndex(t){let e=this.bufferLayouts.findIndex(i=>i.name===t);return e===-1&&Xe.log.warn(`BufferLayout: Missing buffer for "${t}".`)(),e}};function He(s,t){let e=Object.fromEntries(s.attributes.map(r=>[r.name,r.location])),i=t.slice();return i.sort((r,n)=>{let o=r.attributes?r.attributes.map(l=>l.attribute):[r.name],a=n.attributes?n.attributes.map(l=>l.attribute):[n.name],c=Math.min(...o.map(l=>e[l])),h=Math.min(...a.map(l=>e[l]));return c-h}),i}var Yt=L(B(),1),Je=L(ht(),1);function Ke(s){return ArrayBuffer.isView(s)&&!(s instanceof DataView)}function Ze(s){return Array.isArray(s)?s.length===0||typeof s[0]=="number":!1}function It(s){return Ke(s)||Ze(s)}function yi(s){return It(s)||typeof s=="number"||typeof s=="boolean"}function Qe(s){let t={bindings:{},uniforms:{}};return Object.keys(s).forEach(e=>{let i=s[e];yi(i)?t.uniforms[e]=i:t.bindings[e]=i}),t}var K=class{options={disableWarnings:!1};modules;moduleUniforms;moduleBindings;constructor(t,e){Object.assign(this.options,e);let i=(0,Je.getShaderModuleDependencies)(Object.values(t).filter(r=>r.dependencies));for(let r of i)t[r.name]=r;Yt.log.log(1,"Creating ShaderInputs with modules",Object.keys(t))(),this.modules=t,this.moduleUniforms={},this.moduleBindings={};for(let[r,n]of Object.entries(t))this._addModule(n),n.name&&r!==n.name&&!this.options.disableWarnings&&Yt.log.warn(`Module name: ${r} vs ${n.name}`)()}destroy(){}setProps(t){for(let e of Object.keys(t)){let i=e,r=t[i]||{},n=this.modules[i];if(!n){this.options.disableWarnings||Yt.log.warn(`Module ${e} not found`)();continue}let o=this.moduleUniforms[i],a=this.moduleBindings[i],c=n.getUniforms?.(r,o)||r,{uniforms:h,bindings:l}=Qe(c);this.moduleUniforms[i]={...o,...h},this.moduleBindings[i]={...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,i]of Object.entries(this.moduleUniforms))for(let[r,n]of Object.entries(i))t[`${e}.${r}`]={type:this.modules[e].uniformTypes?.[r],value:String(n)};return t}_addModule(t){let e=t.name;this.moduleUniforms[e]=t.defaultUniforms||{},this.moduleBindings[e]={}}};var Z=L(B(),1);var Et=L(B(),1);var Me={"+X":0,"-X":1,"+Y":2,"-Y":3,"+Z":4,"-Z":5};function Ct(s){return s?Array.isArray(s)?s[0]??null:s:null}function ts(s){let{dimension:t,data:e}=s;if(!e)return null;switch(t){case"1d":{let i=Ct(e);if(!i)return null;let{width:r}=Pt(i);return{width:r,height:1}}case"2d":{let i=Ct(e);return i?Pt(i):null}case"3d":case"2d-array":{if(!Array.isArray(e)||e.length===0)return null;let i=Ct(e[0]);return i?Pt(i):null}case"cube":{let i=Object.keys(e)[0]??null;if(!i)return null;let r=e[i],n=Ct(r);return n?Pt(n):null}case"cube-array":{if(!Array.isArray(e)||e.length===0)return null;let i=e[0],r=Object.keys(i)[0]??null;if(!r)return null;let n=Ct(i[r]);return n?Pt(n):null}default:return null}}function Pt(s){if((0,Et.isExternalImage)(s))return(0,Et.getExternalImageSize)(s);if(typeof s=="object"&&"width"in s&&"height"in s)return{width:s.width,height:s.height};throw new Error("Unsupported mip-level data")}function bi(s){return typeof s=="object"&&s!==null&&"data"in s&&"width"in s&&"height"in s}function es(s){let t=Me[s];if(t===void 0)throw new Error(`Invalid cube face: ${s}`);return t}function vi(s,t){return 6*s+es(t)}function ss(s){throw new Error("setTexture1DData not supported in WebGL.")}function Mi(s){return Array.isArray(s)?s:[s]}function mt(s,t){let e=Mi(t),i=s,r=[];for(let n=0;n<e.length;n++){let o=e[n];if((0,Et.isExternalImage)(o))r.push({type:"external-image",image:o,z:i,mipLevel:n});else if(bi(o))r.push({type:"texture-data",data:o,z:i,mipLevel:n});else throw new Error("Unsupported 2D mip-level payload")}return r}function is(s){let t=[];for(let e=0;e<s.length;e++)t.push(...mt(e,s[e]));return t}function rs(s){let t=[];for(let e=0;e<s.length;e++)t.push(...mt(e,s[e]));return t}function ns(s){let t=[];for(let[e,i]of Object.entries(s)){let r=es(e);t.push(...mt(r,i))}return t}function os(s){let t=[];return s.forEach((e,i)=>{for(let[r,n]of Object.entries(e)){let o=vi(i,r);mt(o,n)}}),t}var _e=class{device;id;props;_texture=null;_sampler=null;_view=null;ready;isReady=!1;destroyed=!1;resolveReady=()=>{};rejectReady=()=>{};get texture(){if(!this._texture)throw new Error("Texture not initialized yet");return this._texture}get sampler(){if(!this._sampler)throw new Error("Sampler not initialized yet");return this._sampler}get view(){if(!this._view)throw new Error("View not initialized yet");return this._view}get[Symbol.toStringTag](){return"DynamicTexture"}toString(){return`DynamicTexture:"${this.id}":${this.texture.width}x${this.texture.height}px:(${this.isReady?"ready":"loading..."})`}constructor(t,e){this.device=t;let i=C("dynamic-texture"),r=e;this.props={..._e.defaultProps,id:i,...e,data:null},this.id=this.props.id,this.ready=new Promise((n,o)=>{this.resolveReady=n,this.rejectReady=o}),this.initAsync(r)}async initAsync(t){try{let e=await this._loadAllData(t);this._checkNotDestroyed();let r=(()=>{if(this.props.width&&this.props.height)return{width:this.props.width,height:this.props.height};let h=ts(e);return h||{width:this.props.width||1,height:this.props.height||1}})();if(!r||r.width<=0||r.height<=0)throw new Error(`${this} size could not be determined or was zero`);let n={...this.props,...r,mipLevels:1,data:void 0},o=this.device.getMipLevelCount(n.width,n.height),a=this.props.mipLevels==="auto"?o:Math.max(1,Math.min(o,this.props.mipLevels??1)),c={...n,mipLevels:a};if(this._texture=this.device.createTexture(c),this._sampler=this.texture.sampler,this._view=this.texture.view,e.data)switch(e.dimension){case"1d":this.setTexture1DData(e.data);break;case"2d":this.setTexture2DData(e.data);break;case"3d":this.setTexture3DData(e.data);break;case"2d-array":this.setTextureArrayData(e.data);break;case"cube":this.setTextureCubeData(e.data);break;case"cube-array":this.setTextureCubeArrayData(e.data);break;default:throw new Error(`Unhandled dimension ${e.dimension}`)}this.props.mipmaps&&this.generateMipmaps(),this.isReady=!0,this.resolveReady(this.texture),Z.log.info(0,`${this} created`)()}catch(e){let i=e instanceof Error?e:new Error(String(e));throw this.rejectReady(i),i}}destroy(){this._texture&&(this._texture.destroy(),this._texture=null,this._sampler=null,this._view=null),this.destroyed=!0}generateMipmaps(){this.device.type==="webgl"?this.texture.generateMipmapsWebGL():Z.log.warn("Mipmap generation not yet implemented on WebGPU: your texture data will not be correctly initialized")}setSampler(t={}){this._checkReady();let e=t instanceof Z.Sampler?t:this.device.createSampler(t);this.texture.setSampler(e),this._sampler=e}resize(t){if(this._checkReady(),t.width===this.texture.width&&t.height===this.texture.height)return!1;let e=this.texture;return this._texture=e.clone(t),this._sampler=this.texture.sampler,this._view=this.texture.view,e.destroy(),Z.log.info(`${this} resized`),!0}getCubeFaceIndex(t){let e=Me[t];if(e===void 0)throw new Error(`Invalid cube face: ${t}`);return e}getCubeArrayFaceIndex(t,e){return 6*t+this.getCubeFaceIndex(e)}setTexture1DData(t){if(this._checkReady(),this.texture.props.dimension!=="1d")throw new Error(`${this} is not 1d`);let e=ss(t);this._setTextureSubresources(e)}setTexture2DData(t,e=0){if(this._checkReady(),this.texture.props.dimension!=="2d")throw new Error(`${this} is not 2d`);let i=mt(e,t);this._setTextureSubresources(i)}setTexture3DData(t){if(this.texture.props.dimension!=="3d")throw new Error(`${this} is not 3d`);let e=is(t);this._setTextureSubresources(e)}setTextureArrayData(t){if(this.texture.props.dimension!=="2d-array")throw new Error(`${this} is not 2d-array`);let e=rs(t);this._setTextureSubresources(e)}setTextureCubeData(t){if(this.texture.props.dimension!=="cube")throw new Error(`${this} is not cube`);let e=ns(t);this._setTextureSubresources(e)}setTextureCubeArrayData(t){if(this.texture.props.dimension!=="cube-array")throw new Error(`${this} is not cube-array`);let e=os(t);this._setTextureSubresources(e)}_setTextureSubresources(t){for(let e of t){let{z:i,mipLevel:r}=e;switch(e.type){case"external-image":let{image:n,flipY:o}=e;this.texture.copyExternalImage({image:n,z:i,mipLevel:r,flipY:o});break;case"texture-data":let{data:a}=e;this.texture.copyImageData({data:a.data,z:i,mipLevel:r});break;default:throw new Error("Unsupported 2D mip-level payload")}}}async _loadAllData(t){let e=await as(t.data);return{dimension:t.dimension??"2d",data:e??null}}_checkNotDestroyed(){this.destroyed&&Z.log.warn(`${this} already destroyed`)}_checkReady(){this.isReady||Z.log.warn(`${this} Cannot perform this operation before ready`)}},q=_e;z(q,"defaultProps",{...Z.Texture.defaultProps,dimension:"2d",data:null,mipmaps:!1});async function as(s){if(s=await s,Array.isArray(s))return await Promise.all(s.map(as));if(s&&typeof s=="object"&&s.constructor===Object){let t=s,e=await Promise.all(Object.values(t)),i=Object.keys(t),r={};for(let n=0;n<i.length;n++)r[i[n]]=e[n];return r}return s}var dt=2,_i=1e4,we=class{device;id;source;vs;fs;pipelineFactory;shaderFactory;userData={};parameters;topology;bufferLayout;isInstanced=void 0;instanceCount=0;vertexCount;indexBuffer=null;bufferAttributes={};constantAttributes={};bindings={};vertexArray;transformFeedback=null;pipeline;shaderInputs;_uniformStore;_attributeInfos={};_gpuGeometry=null;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={...we.defaultProps,...e},e=this.props,this.id=e.id||C("model"),this.device=t,Object.assign(this.userData,e.userData);let i=Object.fromEntries(this.props.modules?.map(c=>[c.name,c])||[]),r=e.shaderInputs||new K(i,{disableWarnings:this.props.disableWarnings});this.setShaderInputs(r);let n=Ai(t),o=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];if(this.device.type==="webgpu"&&this.props.source){let{source:c,getUniforms:h}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:n,...this.props,modules:o});this.source=c,this._getModuleUniforms=h,this.props.shaderLayout||=t.getShaderLayout(this.source)}else{let{vs:c,fs:h,getUniforms:l}=this.props.shaderAssembler.assembleGLSLShaderPair({platformInfo:n,...this.props,modules:o});this.vs=c,this.fs=h,this._getModuleUniforms=l}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||tt.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||et.getDefaultShaderFactory(this.device),this.pipeline=this._updatePipeline(),this.vertexArray=t.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),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.transformFeedback&&(this.transformFeedback=e.transformFeedback)}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 T.log.info(dt,`>>> DRAWING ABORTED ${this.id}: ${e} not loaded`)(),!1;try{t.pushDebugGroup(`${this}.predraw(${t})`),this.predraw()}finally{t.popDebugGroup()}let i;try{t.pushDebugGroup(`${this}.draw(${t})`),this._logDrawCallStart(),this.pipeline=this._updatePipeline();let r=this._getBindings();this.pipeline.setBindings(r,{disableWarnings:this.props.disableWarnings});let{indexBuffer:n}=this.vertexArray,o=n?n.byteLength/(n.indexType==="uint32"?4:2):void 0;i=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),i?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):this._needsRedraw="waiting for resource initialization",i}setGeometry(t){this._gpuGeometry?.destroy();let e=t&&qe(this.device,t);if(e){this.setTopology(e.topology||"triangle-list");let i=new pt(this.bufferLayout);this.bufferLayout=i.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 pt(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({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry)}setParameters(t){Wt(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 T.UniformStore(this.shaderInputs.modules);for(let[e,i]of Object.entries(this.shaderInputs.modules))if(wi(i)){let r=this._uniformStore.getManagedUniformBuffer(this.device,e);this.bindings[`${e}Uniforms`]=r}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 i=e?.disableWarnings??this.props.disableWarnings;t.indices&&T.log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)(),this.bufferLayout=He(this.pipeline.shaderLayout,this.bufferLayout);let r=new pt(this.bufferLayout);for(let[n,o]of Object.entries(t)){let a=r.getBufferLayout(n);if(!a){i||T.log.warn(`Model(${this.id}): Missing layout for buffer "${n}".`)();continue}let c=r.getAttributeNamesForBuffer(a),h=!1;for(let l of c){let d=this._attributeInfos[l];if(d){let f=this.device.type==="webgpu"?r.getBufferIndex(d.bufferName):d.location;this.vertexArray.setBuffer(f,o),h=!0}}!h&&!i&&T.log.warn(`Model(${this.id}): Ignoring buffer "${o.id}" for unknown attribute "${n}"`)()}this.setNeedsRedraw("attributes")}setConstantAttributes(t,e){for(let[i,r]of Object.entries(t)){let n=this._attributeInfos[i];n?this.vertexArray.setConstantWebGL(n.location,r):(e?.disableWarnings??this.props.disableWarnings)||T.log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${i}"`)()}this.setNeedsRedraw("constants")}_areBindingsLoading(){for(let t of Object.values(this.bindings))if(t instanceof q&&!t.isReady)return t.id;return!1}_getBindings(){let t={};for(let[e,i]of Object.entries(this.bindings))i instanceof q?i.isReady&&(t[e]=i.texture):t[e]=i;return t}_getBindingsUpdateTimestamp(){let t=0;for(let e of Object.values(this.bindings))e instanceof T.TextureView?t=Math.max(t,e.texture.updateTimestamp):e instanceof T.Buffer||e instanceof T.Texture?t=Math.max(t,e.updateTimestamp):e instanceof q?t=e.texture?Math.max(t,e.texture.updateTimestamp):1/0:e instanceof T.Sampler||(t=Math.max(t,e.buffer.updateTimestamp));return t}_setGeometryAttributes(t){let e={...t.attributes};for(let[i]of Object.entries(e))!this.pipeline.shaderLayout.attributes.find(r=>r.name===i)&&i!=="positions"&&delete e[i];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&&(T.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),t=this.pipeline.vs,e=this.pipeline.fs),this._pipelineNeedsUpdate=!1;let i=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:"vertex",source:this.source||this.vs,debugShaders:this.props.debugShaders}),r=null;this.source?r=i:this.fs&&(r=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:i,fs:r}),this._attributeInfos=(0,T.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=T.log.level>3?0:_i;T.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,T.log.group(dt,`>>> DRAWING MODEL ${this.id}`,{collapsed:T.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=We(this.pipeline.shaderLayout,this.id);T.log.table(dt,t)();let e=this.shaderInputs.getDebugTable();T.log.table(dt,e)();let i=this._getAttributeDebugTable();T.log.table(dt,this._attributeInfos)(),T.log.table(dt,i)(),T.log.groupEnd(dt)(),this._logOpen=!1}}_drawCount=0;_logFramebuffer(t){let e=this.device.props.debugFramebuffers;if(this._drawCount++,!e)return;let i=t.props.framebuffer;i&&Ye(i,{id:i.id,minimap:!0})}_getAttributeDebugTable(){let t={};for(let[e,i]of Object.entries(this._attributeInfos)){let r=this.vertexArray.attributes[i.location];t[i.location]={name:e,type:i.shaderType,values:r?this._getBufferOrConstantValues(r,i.bufferDataType):"null"}}if(this.vertexArray.indexBuffer){let{indexBuffer:e}=this.vertexArray,i=e.indexType==="uint32"?new Uint32Array(e.debugData):new Uint16Array(e.debugData);t.indices={name:"indices",type:e.indexType,values:i.toString()}}return t}_getBufferOrConstantValues(t,e){let i=(0,T.getTypedArrayConstructor)(e);return(t instanceof T.Buffer?new i(t.debugData):t).toString()}},Y=we;z(Y,"defaultProps",{...T.RenderPipeline.defaultProps,source:void 0,vs:null,fs:null,id:"unnamed",handle:void 0,userData:{},defines:{},modules:[],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:cs.ShaderAssembler.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0});function wi(s){return Boolean(s.uniformTypes&&!Si(s.uniformTypes))}function Ai(s){return{type:s.type,shaderLanguage:s.info.shadingLanguage,shaderLanguageVersion:s.info.shadingLanguageVersion,gpu:s.info.gpu,features:s.features}}function Si(s){for(let t in s)return!1;return!0}var hs=L(B(),1),ls=L(ht(),1);var Xt=class{device;model;transformFeedback;static isSupported(t){return t?.info?.type==="webgl"}constructor(t,e=Xt.defaultProps){if(!Xt.isSupported(t))throw new Error("BufferTransform not yet implemented on WebGPU");this.device=t,this.model=new Y(this.device,{id:e.id||"buffer-transform-model",fs:e.fs||(0,ls.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 hs.Buffer)return e.readAsync();let{buffer:i,byteOffset:r=0,byteLength:n=i.byteLength}=e;return i.readAsync(r,n)}},Rt=Xt;z(Rt,"defaultProps",{...Y.defaultProps,outputs:void 0,feedbackBuffers:void 0});var ds=L(ht(),1);var Ti="transform_output",Ht=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 Y(this.device,{id:e.id||C("texture-transform-model"),fs:e.fs||(0,ds.getPassthroughFS)({input:e.targetTextureVarying,inputChannels:e.targetTextureChannels,output:Ti}),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],i=this.device.beginRenderPass({framebuffer:e,...t});this.model.draw(i),i.end(),this.device.submit()}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:i,targetTexture:r}){if(t||(t={sourceBuffers:{},sourceTextures:{},targetTexture:null}),Object.assign(t.sourceTextures,i),Object.assign(t.sourceBuffers,e),r){t.targetTexture=r;let{width:n,height:o}=r;t.framebuffer&&t.framebuffer.destroy(),t.framebuffer=this.device.createFramebuffer({id:"transform-framebuffer",width:n,height:o,colorAttachments:[r]}),t.framebuffer.resize({width:n,height:o})}return t}_setSourceTextureParameters(){let t=this.currentIndex,{sourceTextures:e}=this.bindings[t];for(let i in e)e[i].sampler=this.sampler}};var $=class{id;topology;vertexCount;indices;attributes;userData={};constructor(t){let{attributes:e={},indices:i=null,vertexCount:r=null}=t;this.id=t.id||C("geometry"),this.topology=t.topology,i&&(this.indices=ArrayBuffer.isView(i)?{value:i,size:1}:i),this.attributes={};for(let[n,o]of Object.entries(e)){let a=ArrayBuffer.isView(o)?{value:o}:o;if(!ArrayBuffer.isView(a.value))throw new Error(`${this._print(n)}: must be typed array or object with value as typed array`);if((n==="POSITION"||n==="positions")&&!a.size&&(a.size=3),n==="indices"){if(this.indices)throw new Error("Multiple indices detected");this.indices=a}else this.attributes[n]=a}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 i=1/0;for(let r of Object.values(t)){let{value:n,size:o,constant:a}=r;!a&&n&&o!==void 0&&o>=1&&(i=Math.min(i,n.length/o))}return i}};var Ii=`struct VertexInputs {
8
- @location(0) clipSpacePosition: vec2<f32>,
9
- @location(1) texCoord: vec2<f32>,
10
- @location(2) coordinate: vec2<f32>
7
+ "use strict";var __exports__=(()=>{var ci=Object.create;var Te=Object.defineProperty;var hi=Object.getOwnPropertyDescriptor;var li=Object.getOwnPropertyNames;var di=Object.getPrototypeOf,ui=Object.prototype.hasOwnProperty;var fi=(s,e,t)=>e in s?Te(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var Wt=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),pi=(s,e)=>{for(var t in e)Te(s,t,{get:e[t],enumerable:!0})},$e=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of li(e))!ui.call(s,r)&&r!==t&&Te(s,r,{get:()=>e[r],enumerable:!(i=hi(e,r))||i.enumerable});return s},Be=(s,e,t)=>($e(s,e,"default"),t&&$e(t,e,"default")),k=(s,e,t)=>(t=s!=null?ci(di(s)):{},$e(e||!s||!s.__esModule?Te(t,"default",{value:s,enumerable:!0}):t,s)),mi=s=>$e(Te({},"__esModule",{value:!0}),s);var $=(s,e,t)=>(fi(s,typeof e!="symbol"?e+"":e,t),t);var B=Wt((Dr,Ht)=>{Ht.exports=globalThis.luma});var he=Wt((rn,Zt)=>{Zt.exports=globalThis.luma});var ke={};pi(ke,{AnimationLoop:()=>ce,AnimationLoopTemplate:()=>je,AsyncTexture:()=>Fr,BackgroundTextureModel:()=>xe,BufferTransform:()=>Re,ClipSpace:()=>ne,Computation:()=>Oe,ConeGeometry:()=>nt,CubeGeometry:()=>ot,CylinderGeometry:()=>at,DynamicTexture:()=>H,GPUGeometry:()=>me,Geometry:()=>G,GroupNode:()=>fe,IcoSphereGeometry:()=>ct,KeyFrames:()=>Ge,LegacyPickingManager:()=>mt,Model:()=>X,ModelNode:()=>rt,PickingManager:()=>Le,PipelineFactory:()=>ee,PlaneGeometry:()=>ht,ScenegraphNode:()=>ie,ShaderFactory:()=>te,ShaderInputs:()=>Z,ShaderPassRenderer:()=>ut,SphereGeometry:()=>lt,Swap:()=>Me,SwapBuffers:()=>dt,SwapFramebuffers:()=>_e,TextureTransform:()=>Xe,Timeline:()=>Ue,TruncatedConeGeometry:()=>oe,cancelAnimationFramePolyfill:()=>qe,colorPicking:()=>ii,indexPicking:()=>si,loadImage:()=>Qs,loadImageBitmap:()=>Zs,makeAnimationLoop:()=>Kt,makeRandomGenerator:()=>Xs,requestAnimationFramePolyfill:()=>Ve,setPathPrefix:()=>Ks});Be(ke,k(B(),1));var gi=1,xi=1,Ue=class{time=0;channels=new Map;animations=new Map;playing=!1;lastEngineTime=-1;constructor(){}addChannel(e){let{delay:t=0,duration:i=Number.POSITIVE_INFINITY,rate:r=1,repeat:n=1}=e,o=gi++,a={time:0,delay:t,duration:i,rate:r,repeat:n};return this._setChannelTime(a,this.time),this.channels.set(o,a),o}removeChannel(e){this.channels.delete(e);for(let[t,i]of this.animations)i.channel===e&&this.detachAnimation(t)}isFinished(e){let t=this.channels.get(e);return t===void 0?!1:this.time>=t.delay+t.duration*t.repeat}getTime(e){if(e===void 0)return this.time;let t=this.channels.get(e);return t===void 0?-1:t.time}setTime(e){this.time=Math.max(0,e);let t=this.channels.values();for(let r of t)this._setChannelTime(r,this.time);let i=this.animations.values();for(let r of i){let{animation:n,channel:o}=r;n.setTime(this.getTime(o))}}play(){this.playing=!0}pause(){this.playing=!1,this.lastEngineTime=-1}reset(){this.setTime(0)}attachAnimation(e,t){let i=xi++;return this.animations.set(i,{animation:e,channel:t}),e.setTime(this.getTime(t)),i}detachAnimation(e){this.animations.delete(e)}update(e){this.playing&&(this.lastEngineTime===-1&&(this.lastEngineTime=e),this.setTime(this.time+(e-this.lastEngineTime)),this.lastEngineTime=e)}_setChannelTime(e,t){let i=t-e.delay,r=e.duration*e.repeat;i>=r?e.time=e.duration*e.rate:(e.time=Math.max(0,i)%e.duration,e.time*=e.rate)}};var Ge=class{startIndex=-1;endIndex=-1;factor=0;times=[];values=[];_lastTime=-1;constructor(e){this.setKeyFrames(e),this.setTime(0)}setKeyFrames(e){let t=e.length;this.times.length=t,this.values.length=t;for(let i=0;i<t;++i)this.times[i]=e[i][0],this.values[i]=e[i][1];this._calculateKeys(this._lastTime)}setTime(e){e=Math.max(0,e),e!==this._lastTime&&(this._calculateKeys(e),this._lastTime=e)}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(e){let t=0,i=this.times.length;for(t=0;t<i-2&&!(this.times[t+1]>e);++t);this.startIndex=t,this.endIndex=t+1;let r=this.times[this.startIndex],n=this.times[this.endIndex];this.factor=Math.min(Math.max(0,(e-r)/(n-r)),1)}};var je=class{constructor(e){}async onInitialize(e){return null}};var Yt=k(B(),1);function Ve(s){let e=typeof window<"u"?window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame:null;return e?e.call(window,s):setTimeout(()=>s(typeof performance<"u"?performance.now():Date.now()),1e3/60)}function qe(s){let e=typeof window<"u"?window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame:null;if(e){e.call(window,s);return}clearTimeout(s)}function Ae(){let s;if(typeof window<"u"&&window.performance)s=window.performance.now();else if(typeof process<"u"&&process.hrtime){let e=process.hrtime();s=e[0]*1e3+e[1]/1e6}else s=Date.now();return s}var ae=class{constructor(e,t){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=e,this.type=t,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(e){return this.sampleSize=e,this}incrementCount(){return this.addCount(1),this}decrementCount(){return this.subtractCount(1),this}addCount(e){return this._count+=e,this._samples++,this._checkSampling(),this}subtractCount(e){return this._count-=e,this._samples++,this._checkSampling(),this}addTime(e){return this._time+=e,this.lastTiming=e,this._samples++,this._checkSampling(),this}timeStart(){return this._startTime=Ae(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(Ae()-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 pe=class{constructor(e){this.stats={},this.id=e.id,this.stats={},this._initializeStats(e.stats),Object.seal(this)}get(e,t="count"){return this._getOrCreate({name:e,type:t})}get size(){return Object.keys(this.stats).length}reset(){for(let e of Object.values(this.stats))e.reset();return this}forEach(e){for(let t of Object.values(this.stats))e(t)}getTable(){let e={};return this.forEach(t=>{e[t.name]={time:t.time||0,count:t.count||0,average:t.getAverageTime()||0,hz:t.getHz()||0}}),e}_initializeStats(e=[]){e.forEach(t=>this._getOrCreate(t))}_getOrCreate(e){let{name:t,type:i}=e,r=this.stats[t];return r||(e instanceof ae?r=e:r=new ae(t,i),this.stats[t]=r),r}};var yi=0,bi="Animation Loop",gt=class{device=null;canvas=null;props;animationProps=null;timeline=null;stats;sharedStats;cpuTime;gpuTime;frameRate;display;_needsRedraw="initialized";_initialized=!1;_running=!1;_animationFrameId=null;_nextFramePromise=null;_resolveNextFrame=null;_cpuStartTime=0;_error=null;_lastFrameTime=0;constructor(e){if(this.props={...gt.defaultAnimationLoopProps,...e},e=this.props,!e.device)throw new Error("No device provided");this.stats=e.stats||new pe({id:`animation-loop-${yi++}`}),this.sharedStats=Yt.luma.stats.get(bi),this.frameRate=this.stats.get("Frame Rate"),this.frameRate.setSampleSize(1),this.cpuTime=this.stats.get("CPU Time"),this.gpuTime=this.stats.get("GPU Time"),this.setProps({autoResizeViewport:e.autoResizeViewport}),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),this.device?._disableDebugGPUTime()}delete(){this.destroy()}reportError(e){this.props.onError(e),this._error=e}setNeedsRedraw(e){return this._needsRedraw=this._needsRedraw||e,this}needsRedraw(){let e=this._needsRedraw;return this._needsRedraw=!1,e}setProps(e){return"autoResizeViewport"in e&&(this.props.autoResizeViewport=e.autoResizeViewport||!1),this}async start(){if(this._running)return this;this._running=!0;try{let e;return this._initialized||(this._initialized=!0,await this._initDevice(),this._initialize(),await this.props.onInitialize(this._getAnimationProps())),this._running?(e!==!1&&(this._cancelAnimationFrame(),this._requestAnimationFrame()),this):null}catch(e){let t=e instanceof Error?e:new Error("Unknown error");throw this.props.onError(t),t}}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._lastFrameTime=0),this}redraw(e){return this.device?.isLost||this._error?this:(this._beginFrameTimers(e),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(e){return this.timeline=e,this.timeline}detachTimeline(){this.timeline=null}waitForRender(){return this.setNeedsRedraw("waitForRender"),this._nextFramePromise||(this._nextFramePromise=new Promise(e=>{this._resolveNextFrame=e})),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._resizeViewport(),this.device?._enableDebugGPUTime()}_setDisplay(e){this.display&&(this.display.destroy(),this.display.animationLoop=null),e&&(e.animationLoop=this),this.display=e}_requestAnimationFrame(){this._running&&(this._animationFrameId=Ve(this._animationFrame.bind(this)))}_cancelAnimationFrame(){this._animationFrameId!==null&&(qe(this._animationFrameId),this._animationFrameId=null)}_animationFrame(e){this._running&&(this.redraw(e),this._requestAnimationFrame())}_renderFrame(e){if(this.display){this.display._renderFrame(e);return}this.props.onRender(this._getAnimationProps()),this.device?.submit()}_clearNeedsRedraw(){this._needsRedraw=!1}_setupFrame(){this._resizeViewport()}_initializeAnimationProps(){let e=this.device?.getDefaultCanvasContext();if(!this.device||!e)throw new Error("loop");let t=e?.canvas,i=e.props.useDevicePixels;this.animationProps={animationLoop:this,device:this.device,canvasContext:e,canvas:t,useDevicePixels:i,timeline:this.timeline,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:e,height:t,aspect:i}=this._getSizeAndAspect();(e!==this.animationProps.width||t!==this.animationProps.height)&&this.setNeedsRedraw("drawing buffer resized"),i!==this.animationProps.aspect&&this.setNeedsRedraw("drawing buffer aspect changed"),this.animationProps.width=e,this.animationProps.height=t,this.animationProps.aspect=i,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.getDefaultCanvasContext().canvas||null}_createInfoDiv(){if(this.canvas&&this.props.onAddHTML){let e=document.createElement("div");document.body.appendChild(e),e.style.position="relative";let t=document.createElement("div");t.style.position="absolute",t.style.left="10px",t.style.bottom="10px",t.style.width="300px",t.style.background="white",this.canvas instanceof HTMLCanvasElement&&e.appendChild(this.canvas),e.appendChild(t);let i=this.props.onAddHTML(t);i&&(t.innerHTML=i)}}_getSizeAndAspect(){if(!this.device)return{width:1,height:1,aspect:1};let[e,t]=this.device.getDefaultCanvasContext().getDrawingBufferSize(),i=e>0&&t>0?e/t:1;return{width:e,height:t,aspect:i}}_resizeViewport(){this.props.autoResizeViewport&&this.device.gl&&this.device.gl.viewport(0,0,this.device.gl.drawingBufferWidth,this.device.gl.drawingBufferHeight)}_beginFrameTimers(e){let t=e??(typeof performance<"u"?performance.now():Date.now());if(this._lastFrameTime){let i=t-this._lastFrameTime;i>0&&this.frameRate.addTime(i)}this._lastFrameTime=t,this.device?._isDebugGPUTimeEnabled()&&this._consumeEncodedGpuTime(),this.cpuTime.timeStart()}_endFrameTimers(){this.device?._isDebugGPUTimeEnabled()&&this._consumeEncodedGpuTime(),this.cpuTime.timeEnd(),this._updateSharedStats()}_consumeEncodedGpuTime(){if(!this.device)return;let e=this.device.commandEncoder._gpuTimeMs;e!==void 0&&(this.gpuTime.addTime(e),this.device.commandEncoder._gpuTimeMs=void 0)}_updateSharedStats(){if(this.stats!==this.sharedStats){for(let e of Object.keys(this.sharedStats.stats))this.stats.stats[e]||delete this.sharedStats.stats[e];this.stats.forEach(e=>{let t=this.sharedStats.get(e.name,e.type);t.sampleSize=e.sampleSize,t.time=e.time,t.count=e.count,t.samples=e.samples,t.lastTiming=e.lastTiming,t.lastSampleTime=e.lastSampleTime,t.lastSampleCount=e.lastSampleCount,t._count=e._count,t._time=e._time,t._samples=e._samples,t._startTime=e._startTime,t._timerPending=e._timerPending})}}_startEventHandling(){this.canvas&&(this.canvas.addEventListener("mousemove",this._onMousemove.bind(this)),this.canvas.addEventListener("mouseleave",this._onMouseleave.bind(this)))}_onMousemove(e){e instanceof MouseEvent&&(this._getAnimationProps()._mousePosition=[e.offsetX,e.offsetY])}_onMouseleave(e){this._getAnimationProps()._mousePosition=null}},ce=gt;$(ce,"defaultAnimationLoopProps",{device:null,onAddHTML:()=>"",onInitialize:async()=>null,onRender:()=>{},onFinalize:()=>{},onError:e=>console.error(e),stats:void 0,autoResizeViewport:!1});var Xt=k(B(),1);function Kt(s,e){let t=null,i=e?.device||Xt.luma.createDevice({id:"animation-loop",adapters:e?.adapters,createCanvasContext:!0}),r=new ce({...e,device:i,async onInitialize(n){Mi(n.animationLoop.device);try{return t=new s(n),await t?.onInitialize(n)}catch(o){return vi(n.animationLoop.device,o),null}},onRender:n=>t?.onRender(n),onFinalize:n=>t?.onFinalize(n)});return r.getInfo=()=>this.AnimationLoopTemplateCtor.info,r}function vi(s,e){if(!s)return;let t=s.getDefaultCanvasContext().canvas;if(t instanceof HTMLCanvasElement){t.style.overflow="visible";let i=document.getElementById("animation-loop-error");i?.remove(),i=document.createElement("h1"),i.id="animation-loop-error",i.innerHTML=e.message,i.style.position="absolute",i.style.top="10px",i.style.left="10px",i.style.color="black",i.style.backgroundColor="red",t.parentElement?.appendChild(i)}}function Mi(s){if(!s)return;let e=document.getElementById("animation-loop-error");e&&e.remove()}var P=k(B(),1),fs=k(he(),1);var Se=k(B(),1);var xt={};function C(s="id"){xt[s]=xt[s]||1;let e=xt[s]++;return`${s}-${e}`}var me=class{id;userData={};topology;bufferLayout=[];vertexCount;indices;attributes;constructor(e){if(this.id=e.id||C("geometry"),this.topology=e.topology,this.indices=e.indices||null,this.attributes=e.attributes,this.vertexCount=e.vertexCount,this.bufferLayout=e.bufferLayout||[],this.indices&&!(this.indices.usage&Se.Buffer.INDEX))throw new Error("Index buffer must have INDEX usage")}destroy(){this.indices?.destroy();for(let e of Object.values(this.attributes))e.destroy()}getVertexCount(){return this.vertexCount}getAttributes(){return this.attributes}getIndexes(){return this.indices||null}_calculateVertexCount(e){return e.byteLength/12}};function Qt(s,e){if(e instanceof me)return e;let t=_i(s,e),{attributes:i,bufferLayout:r}=wi(s,e);return new me({topology:e.topology||"triangle-list",bufferLayout:r,vertexCount:e.vertexCount,indices:t,attributes:i})}function _i(s,e){if(!e.indices)return;let t=e.indices.value;return s.createBuffer({usage:Se.Buffer.INDEX,data:t})}function wi(s,e){let t=[],i={};for(let[n,o]of Object.entries(e.attributes)){let a=n;switch(n){case"POSITION":a="positions";break;case"NORMAL":a="normals";break;case"TEXCOORD_0":a="texCoords";break;case"COLOR_0":a="colors";break}if(o){i[a]=s.createBuffer({data:o.value,id:`${n}-buffer`});let{value:c,size:l,normalized:h}=o;t.push({name:a,format:(0,Se.getVertexFormatFromAttribute)(c,l,h)})}}let r=e._calculateVertexCount(e.attributes,e.indices);return{attributes:i,bufferLayout:t,vertexCount:r}}var U=k(B(),1);var yt=class{static getDefaultPipelineFactory(e){let t=e.getModuleData("@luma.gl/engine");return t.defaultPipelineFactory||=new yt(e),t.defaultPipelineFactory}device;_hashCounter=0;_hashes={};_renderPipelineCache={};_computePipelineCache={};_sharedRenderPipelineCache={};get[Symbol.toStringTag](){return"PipelineFactory"}toString(){return`PipelineFactory(${this.device.id})`}constructor(e){this.device=e}createRenderPipeline(e){if(!this.device.props._cachePipelines)return this.device.createRenderPipeline(e);let t={...U.RenderPipeline.defaultProps,...e},i=this._renderPipelineCache,r=this._hashRenderPipeline(t),n=i[r]?.resource;if(n)i[r].useCount++,this.device.props.debugFactories&&U.log.log(3,`${this}: ${i[r].resource} reused, count=${i[r].useCount}, (id=${e.id})`)();else{let o=this.device.type==="webgl"&&this.device.props._sharePipelines?this.createSharedRenderPipeline(t):void 0;n=this.device.createRenderPipeline({...t,id:t.id?`${t.id}-cached`:C("unnamed-cached"),_sharedRenderPipeline:o}),n.hash=r,i[r]={resource:n,useCount:1},this.device.props.debugFactories&&U.log.log(3,`${this}: ${n} created, count=${i[r].useCount}`)()}return n}createComputePipeline(e){if(!this.device.props._cachePipelines)return this.device.createComputePipeline(e);let t={...U.ComputePipeline.defaultProps,...e},i=this._computePipelineCache,r=this._hashComputePipeline(t),n=i[r]?.resource;return n?(i[r].useCount++,this.device.props.debugFactories&&U.log.log(3,`${this}: ${i[r].resource} reused, count=${i[r].useCount}, (id=${e.id})`)()):(n=this.device.createComputePipeline({...t,id:t.id?`${t.id}-cached`:void 0}),n.hash=r,i[r]={resource:n,useCount:1},this.device.props.debugFactories&&U.log.log(3,`${this}: ${n} created, count=${i[r].useCount}`)()),n}release(e){if(!this.device.props._cachePipelines){e.destroy();return}let t=this._getCache(e),i=e.hash;t[i].useCount--,t[i].useCount===0?(this._destroyPipeline(e),this.device.props.debugFactories&&U.log.log(3,`${this}: ${e} released and destroyed`)()):t[i].useCount<0?(U.log.error(`${this}: ${e} released, useCount < 0, resetting`)(),t[i].useCount=0):this.device.props.debugFactories&&U.log.log(3,`${this}: ${e} released, count=${t[i].useCount}`)()}createSharedRenderPipeline(e){let t=this._hashSharedRenderPipeline(e),i=this._sharedRenderPipelineCache[t];return i||(i={resource:this.device._createSharedRenderPipelineWebGL(e),useCount:0},this._sharedRenderPipelineCache[t]=i),i.useCount++,i.resource}releaseSharedRenderPipeline(e){if(!e.sharedRenderPipeline)return;let t=this._hashSharedRenderPipeline(e.sharedRenderPipeline.props),i=this._sharedRenderPipelineCache[t];i&&(i.useCount--,i.useCount===0&&(i.resource.destroy(),delete this._sharedRenderPipelineCache[t]))}_destroyPipeline(e){let t=this._getCache(e);return this.device.props._destroyPipelines?(delete t[e.hash],e.destroy(),e instanceof U.RenderPipeline&&this.releaseSharedRenderPipeline(e),!0):!1}_getCache(e){let t;if(e instanceof U.ComputePipeline&&(t=this._computePipelineCache),e instanceof U.RenderPipeline&&(t=this._renderPipelineCache),!t)throw new Error(`${this}`);if(!t[e.hash])throw new Error(`${this}: ${e} matched incorrect entry`);return t}_hashComputePipeline(e){let{type:t}=this.device,i=this._getHash(e.shader.source);return`${t}/C/${i}`}_hashRenderPipeline(e){let t=e.vs?this._getHash(e.vs.source):0,i=e.fs?this._getHash(e.fs.source):0,r=this._getWebGLVaryingHash(e),n=this._getHash(JSON.stringify(e.bufferLayout)),{type:o}=this.device;switch(o){case"webgl":let a=this._getHash(JSON.stringify(e.parameters));return`${o}/R/${t}/${i}V${r}T${e.topology}P${a}BL${n}`;case"webgpu":default:let c=this._getHash(JSON.stringify(e.parameters));return`${o}/R/${t}/${i}V${r}T${e.topology}P${c}BL${n}`}}_hashSharedRenderPipeline(e){let t=e.vs?this._getHash(e.vs.source):0,i=e.fs?this._getHash(e.fs.source):0,r=this._getWebGLVaryingHash(e);return`webgl/S/${t}/${i}V${r}`}_getHash(e){return this._hashes[e]===void 0&&(this._hashes[e]=this._hashCounter++),this._hashes[e]}_getWebGLVaryingHash(e){let{varyings:t=[],bufferMode:i=null}=e;return this._getHash(JSON.stringify({varyings:t,bufferMode:i}))}},ee=yt;$(ee,"defaultProps",{...U.RenderPipeline.defaultProps});var le=k(B(),1);var bt=class{static getDefaultShaderFactory(e){let t=e.getModuleData("@luma.gl/engine");return t.defaultShaderFactory||=new bt(e),t.defaultShaderFactory}device;_cache={};get[Symbol.toStringTag](){return"ShaderFactory"}toString(){return`${this[Symbol.toStringTag]}(${this.device.id})`}constructor(e){this.device=e}createShader(e){if(!this.device.props._cacheShaders)return this.device.createShader(e);let t=this._hashShader(e),i=this._cache[t];if(i)i.useCount++,this.device.props.debugFactories&&le.log.log(3,`${this}: Reusing shader ${i.resource.id} count=${i.useCount}`)();else{let r=this.device.createShader({...e,id:e.id?`${e.id}-cached`:void 0});this._cache[t]=i={resource:r,useCount:1},this.device.props.debugFactories&&le.log.log(3,`${this}: Created new shader ${r.id}`)()}return i.resource}release(e){if(!this.device.props._cacheShaders){e.destroy();return}let t=this._hashShader(e),i=this._cache[t];if(i)if(i.useCount--,i.useCount===0)this.device.props._destroyShaders&&(delete this._cache[t],i.resource.destroy(),this.device.props.debugFactories&&le.log.log(3,`${this}: Releasing shader ${e.id}, destroyed`)());else{if(i.useCount<0)throw new Error(`ShaderFactory: Shader ${e.id} released too many times`);this.device.props.debugFactories&&le.log.log(3,`${this}: Releasing shader ${e.id} count=${i.useCount}`)()}}_hashShader(e){return`${e.stage}:${e.source}`}},te=bt;$(te,"defaultProps",{...le.Shader.defaultProps});function Jt(s,e){let t={},i="Values";if(s.attributes.length===0&&!s.varyings?.length)return{"No attributes or varyings":{[i]:"N/A"}};for(let r of s.attributes)if(r){let n=`${r.location} ${r.name}: ${r.type}`;t[`in ${n}`]={[i]:r.stepMode||"vertex"}}for(let r of s.varyings||[]){let n=`${r.location} ${r.name}`;t[`out ${n}`]={[i]:JSON.stringify(r)}}return t}var N=null,vt=null;function es(s,{id:e,minimap:t,opaque:i,top:r="0",left:n="0",rgbaScale:o=1}){N||(N=document.createElement("canvas"),N.id=e,N.title=e,N.style.zIndex="100",N.style.position="absolute",N.style.top=r,N.style.left=n,N.style.border="blue 5px solid",N.style.transform="scaleY(-1)",document.body.appendChild(N),vt=N.getContext("2d")),(N.width!==s.width||N.height!==s.height)&&(N.width=s.width/2,N.height=s.height/2,N.style.width="400px",N.style.height="400px");let a=s.device.readPixelsToArrayWebGL(s),c=vt?.createImageData(s.width,s.height);if(c){for(let h=0;h<a.length;h+=4)c.data[0+h+0]=a[h+0]*o,c.data[0+h+1]=a[h+1]*o,c.data[0+h+2]=a[h+2]*o,c.data[0+h+3]=i?255:a[h+3]*o;vt?.putImageData(c,0,0)}}function We(s,e,t){if(s===e)return!0;if(!t||!s||!e)return!1;if(Array.isArray(s)){if(!Array.isArray(e)||s.length!==e.length)return!1;for(let i=0;i<s.length;i++)if(!We(s[i],e[i],t-1))return!1;return!0}if(Array.isArray(e))return!1;if(typeof s=="object"&&typeof e=="object"){let i=Object.keys(s),r=Object.keys(e);if(i.length!==r.length)return!1;for(let n of i)if(!e.hasOwnProperty(n)||!We(s[n],e[n],t-1))return!1;return!0}return!1}var ts=k(B(),1),ge=class{bufferLayouts;constructor(e){this.bufferLayouts=e}getBufferLayout(e){return this.bufferLayouts.find(t=>t.name===e)||null}getAttributeNamesForBuffer(e){return e.attributes?e.attributes?.map(t=>t.attribute):[e.name]}mergeBufferLayouts(e,t){let i=[...e];for(let r of t){let n=i.findIndex(o=>o.name===r.name);n<0?i.push(r):i[n]=r}return i}getBufferIndex(e){let t=this.bufferLayouts.findIndex(i=>i.name===e);return t===-1&&ts.log.warn(`BufferLayout: Missing buffer for "${e}".`)(),t}};function ss(s,e){let t=1/0;for(let i of s){let r=e[i];r!==void 0&&(t=Math.min(t,r))}return t}function is(s,e){let t=Object.fromEntries(s.attributes.map(r=>[r.name,r.location])),i=e.slice();return i.sort((r,n)=>{let o=r.attributes?r.attributes.map(h=>h.attribute):[r.name],a=n.attributes?n.attributes.map(h=>h.attribute):[n.name],c=ss(o,t),l=ss(a,t);return c-l}),i}var He=k(B(),1),as=k(he(),1);function rs(s){return ArrayBuffer.isView(s)&&!(s instanceof DataView)}function ns(s){return Array.isArray(s)?s.length===0||typeof s[0]=="number":!1}function Pe(s){return rs(s)||ns(s)}function Ti(s){return Pe(s)||typeof s=="number"||typeof s=="boolean"}function os(s){let e={bindings:{},uniforms:{}};return Object.keys(s).forEach(t=>{let i=s[t];Ti(i)?e.uniforms[t]=i:e.bindings[t]=i}),e}var Z=class{options={disableWarnings:!1};modules;moduleUniforms;moduleBindings;constructor(e,t){Object.assign(this.options,t);let i=(0,as.getShaderModuleDependencies)(Object.values(e).filter(r=>r.dependencies));for(let r of i)e[r.name]=r;He.log.log(1,"Creating ShaderInputs with modules",Object.keys(e))(),this.modules=e,this.moduleUniforms={},this.moduleBindings={};for(let[r,n]of Object.entries(e))this._addModule(n),n.name&&r!==n.name&&!this.options.disableWarnings&&He.log.warn(`Module name: ${r} vs ${n.name}`)()}destroy(){}setProps(e){for(let t of Object.keys(e)){let i=t,r=e[i]||{},n=this.modules[i];if(!n){this.options.disableWarnings||He.log.warn(`Module ${t} not found`)();continue}let o=this.moduleUniforms[i],a=this.moduleBindings[i],c=n.getUniforms?.(r,o)||r,{uniforms:l,bindings:h}=os(c);this.moduleUniforms[i]={...o,...l},this.moduleBindings[i]={...a,...h}}}getModules(){return Object.values(this.modules)}getUniformValues(){return this.moduleUniforms}getBindingValues(){let e={};for(let t of Object.values(this.moduleBindings))Object.assign(e,t);return e}getDebugTable(){let e={};for(let[t,i]of Object.entries(this.moduleUniforms))for(let[r,n]of Object.entries(i))e[`${t}.${r}`]={type:this.modules[t].uniformTypes?.[r],value:String(n)};return e}_addModule(e){let t=e.name;this.moduleUniforms[t]=e.defaultUniforms||{},this.moduleBindings[t]={}}};var F=k(B(),1);var Ee=k(B(),1);var Mt={"+X":0,"-X":1,"+Y":2,"-Y":3,"+Z":4,"-Z":5};function Ce(s){return s?Array.isArray(s)?s[0]??null:s:null}function cs(s){let{dimension:e,data:t}=s;if(!t)return null;switch(e){case"1d":{let i=Ce(t);if(!i)return null;let{width:r}=Ie(i);return{width:r,height:1}}case"2d":{let i=Ce(t);return i?Ie(i):null}case"3d":case"2d-array":{if(!Array.isArray(t)||t.length===0)return null;let i=Ce(t[0]);return i?Ie(i):null}case"cube":{let i=Object.keys(t)[0]??null;if(!i)return null;let r=t[i],n=Ce(r);return n?Ie(n):null}case"cube-array":{if(!Array.isArray(t)||t.length===0)return null;let i=t[0],r=Object.keys(i)[0]??null;if(!r)return null;let n=Ce(i[r]);return n?Ie(n):null}default:return null}}function Ie(s){if((0,Ee.isExternalImage)(s))return(0,Ee.getExternalImageSize)(s);if(typeof s=="object"&&"width"in s&&"height"in s)return{width:s.width,height:s.height};throw new Error("Unsupported mip-level data")}function Ai(s){return typeof s=="object"&&s!==null&&"data"in s&&"width"in s&&"height"in s}function _t(s){let{textureFormat:e,format:t}=s;if(e&&t&&e!==t)throw new Error(`Conflicting texture formats "${e}" and "${t}" provided for the same mip level`);return e??t}function hs(s){let e=Mt[s];if(e===void 0)throw new Error(`Invalid cube face: ${s}`);return e}function Si(s,e){return 6*s+hs(e)}function wt(s){throw new Error("setTexture1DData not supported in WebGL.")}function Pi(s){return Array.isArray(s)?s:[s]}function de(s,e){let t=Pi(e),i=s,r=[];for(let n=0;n<t.length;n++){let o=t[n];if((0,Ee.isExternalImage)(o))r.push({type:"external-image",image:o,z:i,mipLevel:n});else if(Ai(o))r.push({type:"texture-data",data:o,textureFormat:_t(o),z:i,mipLevel:n});else throw new Error("Unsupported 2D mip-level payload")}return r}function Tt(s){let e=[];for(let t=0;t<s.length;t++)e.push(...de(t,s[t]));return e}function At(s){let e=[];for(let t=0;t<s.length;t++)e.push(...de(t,s[t]));return e}function St(s){let e=[];for(let[t,i]of Object.entries(s)){let r=hs(t);e.push(...de(r,i))}return e}function Pt(s){let e=[];return s.forEach((t,i)=>{for(let[r,n]of Object.entries(t)){let o=Si(i,r);e.push(...de(o,n))}}),e}var Ct=class{device;id;props;_texture=null;_sampler=null;_view=null;ready;isReady=!1;destroyed=!1;resolveReady=()=>{};rejectReady=()=>{};get texture(){if(!this._texture)throw new Error("Texture not initialized yet");return this._texture}get sampler(){if(!this._sampler)throw new Error("Sampler not initialized yet");return this._sampler}get view(){if(!this._view)throw new Error("View not initialized yet");return this._view}get[Symbol.toStringTag](){return"DynamicTexture"}toString(){return`DynamicTexture:"${this.id}":${this.texture.width}x${this.texture.height}px:(${this.isReady?"ready":"loading..."})`}constructor(e,t){this.device=e;let i=C("dynamic-texture"),r=t;this.props={...Ct.defaultProps,id:i,...t,data:null},this.id=this.props.id,this.ready=new Promise((n,o)=>{this.resolveReady=n,this.rejectReady=o}),this.initAsync(r)}async initAsync(e){try{let t=await this._loadAllData(e);this._checkNotDestroyed();let i=t.data?Ci(t):[],r="format"in e&&e.format!==void 0,n="usage"in e&&e.usage!==void 0,a=(()=>{if(this.props.width&&this.props.height)return{width:this.props.width,height:this.props.height};let f=cs(t);return f||{width:this.props.width||1,height:this.props.height||1}})();if(!a||a.width<=0||a.height<=0)throw new Error(`${this} size could not be determined or was zero`);let c=Ii(this.device,i,a,{format:r?e.format:void 0}),l=c.format??this.props.format,h={...this.props,...a,format:l,mipLevels:1,data:void 0};this.device.isTextureFormatCompressed(l)&&!n&&(h.usage=F.Texture.SAMPLE|F.Texture.COPY_DST);let d=this.props.mipmaps&&!c.hasExplicitMipChain&&!this.device.isTextureFormatCompressed(l);if(this.device.type==="webgpu"&&d){let f=this.props.dimension==="3d"?F.Texture.SAMPLE|F.Texture.STORAGE|F.Texture.COPY_DST|F.Texture.COPY_SRC:F.Texture.SAMPLE|F.Texture.RENDER|F.Texture.COPY_DST|F.Texture.COPY_SRC;h.usage|=f}let u=this.device.getMipLevelCount(h.width,h.height),g=c.hasExplicitMipChain?c.mipLevels:this.props.mipLevels==="auto"?u:Math.max(1,Math.min(u,this.props.mipLevels??1)),m={...h,mipLevels:g};this._texture=this.device.createTexture(m),this._sampler=this.texture.sampler,this._view=this.texture.view,c.subresources.length&&this._setTextureSubresources(c.subresources),this.props.mipmaps&&!c.hasExplicitMipChain&&!d&&F.log.warn(`${this} skipping auto-generated mipmaps for compressed texture format`)(),d&&this.generateMipmaps(),this.isReady=!0,this.resolveReady(this.texture),F.log.info(0,`${this} created`)()}catch(t){let i=t instanceof Error?t:new Error(String(t));throw this.rejectReady(i),i}}destroy(){this._texture&&(this._texture.destroy(),this._texture=null,this._sampler=null,this._view=null),this.destroyed=!0}generateMipmaps(){this.device.type==="webgl"?this.texture.generateMipmapsWebGL():this.device.type==="webgpu"?this.device.generateMipmapsWebGPU(this.texture):F.log.warn(`${this} mipmaps not supported on ${this.device.type}`)}setSampler(e={}){this._checkReady();let t=e instanceof F.Sampler?e:this.device.createSampler(e);this.texture.setSampler(t),this._sampler=t}resize(e){if(this._checkReady(),e.width===this.texture.width&&e.height===this.texture.height)return!1;let t=this.texture;return this._texture=t.clone(e),this._sampler=this.texture.sampler,this._view=this.texture.view,t.destroy(),F.log.info(`${this} resized`),!0}getCubeFaceIndex(e){let t=Mt[e];if(t===void 0)throw new Error(`Invalid cube face: ${e}`);return t}getCubeArrayFaceIndex(e,t){return 6*e+this.getCubeFaceIndex(t)}setTexture1DData(e){if(this._checkReady(),this.texture.props.dimension!=="1d")throw new Error(`${this} is not 1d`);let t=wt(e);this._setTextureSubresources(t)}setTexture2DData(e,t=0){if(this._checkReady(),this.texture.props.dimension!=="2d")throw new Error(`${this} is not 2d`);let i=de(t,e);this._setTextureSubresources(i)}setTexture3DData(e){if(this.texture.props.dimension!=="3d")throw new Error(`${this} is not 3d`);let t=Tt(e);this._setTextureSubresources(t)}setTextureArrayData(e){if(this.texture.props.dimension!=="2d-array")throw new Error(`${this} is not 2d-array`);let t=At(e);this._setTextureSubresources(t)}setTextureCubeData(e){if(this.texture.props.dimension!=="cube")throw new Error(`${this} is not cube`);let t=St(e);this._setTextureSubresources(t)}setTextureCubeArrayData(e){if(this.texture.props.dimension!=="cube-array")throw new Error(`${this} is not cube-array`);let t=Pt(e);this._setTextureSubresources(t)}_setTextureSubresources(e){for(let t of e){let{z:i,mipLevel:r}=t;switch(t.type){case"external-image":let{image:n,flipY:o}=t;this.texture.copyExternalImage({image:n,z:i,mipLevel:r,flipY:o});break;case"texture-data":let{data:a,textureFormat:c}=t;if(c&&c!==this.texture.format)throw new Error(`${this} mip level ${r} uses format "${c}" but texture format is "${this.texture.format}"`);this.texture.writeData(a.data,{x:0,y:0,z:i,width:a.width,height:a.height,depthOrArrayLayers:1,mipLevel:r});break;default:throw new Error("Unsupported 2D mip-level payload")}}}async _loadAllData(e){let t=await us(e.data);return{dimension:e.dimension??"2d",data:t??null}}_checkNotDestroyed(){this.destroyed&&F.log.warn(`${this} already destroyed`)}_checkReady(){this.isReady||F.log.warn(`${this} Cannot perform this operation before ready`)}},H=Ct;$(H,"defaultProps",{...F.Texture.defaultProps,dimension:"2d",data:null,mipmaps:!1});function Ci(s){if(!s.data)return[];switch(s.dimension){case"1d":return wt(s.data);case"2d":return de(0,s.data);case"3d":return Tt(s.data);case"2d-array":return At(s.data);case"cube":return St(s.data);case"cube-array":return Pt(s.data);default:throw new Error(`Unhandled dimension ${s.dimension}`)}}function Ii(s,e,t,i){if(e.length===0)return{subresources:e,mipLevels:1,format:i.format,hasExplicitMipChain:!1};let r=new Map;for(let h of e){let d=r.get(h.z)??[];d.push(h),r.set(h.z,d)}let n=e.some(h=>h.mipLevel>0),o=i.format,a=Number.POSITIVE_INFINITY,c=[];for(let[h,d]of r){let u=[...d].sort((_,p)=>_.mipLevel-p.mipLevel),g=u[0];if(!g||g.mipLevel!==0)throw new Error(`DynamicTexture: slice ${h} is missing mip level 0`);let m=ds(s,g);if(m.width!==t.width||m.height!==t.height)throw new Error(`DynamicTexture: slice ${h} base level dimensions ${m.width}x${m.height} do not match expected ${t.width}x${t.height}`);let f=ls(g);if(f){if(o&&o!==f)throw new Error(`DynamicTexture: slice ${h} base level format "${f}" does not match texture format "${o}"`);o=f}let y=o&&s.isTextureFormatCompressed(o)?Ei(s,m.width,m.height,o):s.getMipLevelCount(m.width,m.height),v=0;for(let _=0;_<u.length;_++){let p=u[_];if(!p||p.mipLevel!==_||_>=y)break;let x=ds(s,p),b=Math.max(1,m.width>>_),M=Math.max(1,m.height>>_);if(x.width!==b||x.height!==M)break;let A=ls(p);if(A&&(o||(o=A),A!==o))break;v++,c.push(p)}a=Math.min(a,v)}let l=Number.isFinite(a)?Math.max(1,a):1;return{subresources:c.filter(h=>h.mipLevel<l),mipLevels:l,format:o,hasExplicitMipChain:n}}function ls(s){if(s.type==="texture-data")return s.textureFormat??_t(s.data)}function ds(s,e){switch(e.type){case"external-image":return s.getExternalImageSize(e.image);case"texture-data":return{width:e.data.width,height:e.data.height};default:throw new Error("Unsupported texture subresource")}}function Ei(s,e,t,i){let{blockWidth:r=1,blockHeight:n=1}=s.getTextureFormatInfo(i),o=1;for(let a=1;;a++){let c=Math.max(1,e>>a),l=Math.max(1,t>>a);if(c<r||l<n)break;o++}return o}async function us(s){if(s=await s,Array.isArray(s))return await Promise.all(s.map(us));if(s&&typeof s=="object"&&s.constructor===Object){let e=s,t=await Promise.all(Object.values(e)),i=Object.keys(e),r={};for(let n=0;n<i.length;n++)r[i[n]]=t[n];return r}return s}var ue=2,Ri=1e4,It=class{device;id;source;vs;fs;pipelineFactory;shaderFactory;userData={};parameters;topology;bufferLayout;isInstanced=void 0;instanceCount=0;vertexCount;indexBuffer=null;bufferAttributes={};constantAttributes={};bindings={};vertexArray;transformFeedback=null;pipeline;shaderInputs;_uniformStore;_attributeInfos={};_gpuGeometry=null;props;_pipelineNeedsUpdate="newly created";_needsRedraw="initializing";_destroyed=!1;_lastDrawTimestamp=-1;get[Symbol.toStringTag](){return"Model"}toString(){return`Model(${this.id})`}constructor(e,t){this.props={...It.defaultProps,...t},t=this.props,this.id=t.id||C("model"),this.device=e,Object.assign(this.userData,t.userData);let i=Object.fromEntries(this.props.modules?.map(c=>[c.name,c])||[]),r=t.shaderInputs||new Z(i,{disableWarnings:this.props.disableWarnings});this.setShaderInputs(r);let n=Li(e),o=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];if(this.device.type==="webgpu"&&this.props.source){let{source:c,getUniforms:l}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:n,...this.props,modules:o});this.source=c,this._getModuleUniforms=l,this.props.shaderLayout||=e.getShaderLayout(this.source)}else{let{vs:c,fs:l,getUniforms:h}=this.props.shaderAssembler.assembleGLSLShaderPair({platformInfo:n,...this.props,modules:o});this.vs=c,this.fs=l,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,t.geometry&&this.setGeometry(t.geometry),this.pipelineFactory=t.pipelineFactory||ee.getDefaultPipelineFactory(this.device),this.shaderFactory=t.shaderFactory||te.getDefaultShaderFactory(this.device),this.pipeline=this._updatePipeline(),this.vertexArray=e.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry),"isInstanced"in t&&(this.isInstanced=t.isInstanced),t.instanceCount&&this.setInstanceCount(t.instanceCount),t.vertexCount&&this.setVertexCount(t.vertexCount),t.indexBuffer&&this.setIndexBuffer(t.indexBuffer),t.attributes&&this.setAttributes(t.attributes),t.constantAttributes&&this.setConstantAttributes(t.constantAttributes),t.bindings&&this.setBindings(t.bindings),t.transformFeedback&&(this.transformFeedback=t.transformFeedback)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.pipeline.vs),this.pipeline.fs&&this.pipeline.fs!==this.pipeline.vs&&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 e=this._needsRedraw;return this._needsRedraw=!1,e}setNeedsRedraw(e){this._needsRedraw||=e}predraw(){this.updateShaderInputs(),this.pipeline=this._updatePipeline()}draw(e){let t=this._areBindingsLoading();if(t)return P.log.info(ue,`>>> DRAWING ABORTED ${this.id}: ${t} not loaded`)(),!1;try{e.pushDebugGroup(`${this}.predraw(${e})`),this.predraw()}finally{e.popDebugGroup()}let i;try{e.pushDebugGroup(`${this}.draw(${e})`),this._logDrawCallStart(),this.pipeline=this._updatePipeline();let r=this._getBindings(),{indexBuffer:n}=this.vertexArray,o=n?n.byteLength/(n.indexType==="uint32"?4:2):void 0;i=this.pipeline.draw({renderPass:e,vertexArray:this.vertexArray,isInstanced:this.isInstanced,vertexCount:this.vertexCount,instanceCount:this.instanceCount,indexCount:o,transformFeedback:this.transformFeedback||void 0,bindings:r,uniforms:this.props.uniforms,parameters:this.parameters,topology:this.topology})}finally{e.popDebugGroup(),this._logDrawCallEnd()}return this._logFramebuffer(e),i?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):this._needsRedraw="waiting for resource initialization",i}setGeometry(e){this._gpuGeometry?.destroy();let t=e&&Qt(this.device,e);if(t){this.setTopology(t.topology||"triangle-list");let i=new ge(this.bufferLayout);this.bufferLayout=i.mergeBufferLayouts(t.bufferLayout,this.bufferLayout),this.vertexArray&&this._setGeometryAttributes(t)}this._gpuGeometry=t}setTopology(e){e!==this.topology&&(this.topology=e,this._setPipelineNeedsUpdate("topology"))}setBufferLayout(e){let t=new ge(this.bufferLayout);this.bufferLayout=this._gpuGeometry?t.mergeBufferLayouts(e,this._gpuGeometry.bufferLayout):e,this._setPipelineNeedsUpdate("bufferLayout"),this.pipeline=this._updatePipeline(),this.vertexArray=this.device.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry)}setParameters(e){We(e,this.parameters,2)||(this.parameters=e,this._setPipelineNeedsUpdate("parameters"))}setInstanceCount(e){this.instanceCount=e,this.isInstanced===void 0&&e>0&&(this.isInstanced=!0),this.setNeedsRedraw("instanceCount")}setVertexCount(e){this.vertexCount=e,this.setNeedsRedraw("vertexCount")}setShaderInputs(e){this.shaderInputs=e,this._uniformStore=new P.UniformStore(this.shaderInputs.modules);for(let[t,i]of Object.entries(this.shaderInputs.modules))if(Oi(i)){let r=this._uniformStore.getManagedUniformBuffer(this.device,t);this.bindings[`${t}Uniforms`]=r}this.setNeedsRedraw("shaderInputs")}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues()),this.setBindings(this.shaderInputs.getBindingValues()),this.setNeedsRedraw("shaderInputs")}setBindings(e){Object.assign(this.bindings,e),this.setNeedsRedraw("bindings")}setTransformFeedback(e){this.transformFeedback=e,this.setNeedsRedraw("transformFeedback")}setIndexBuffer(e){this.vertexArray.setIndexBuffer(e),this.setNeedsRedraw("indexBuffer")}setAttributes(e,t){let i=t?.disableWarnings??this.props.disableWarnings;e.indices&&P.log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)(),this.bufferLayout=is(this.pipeline.shaderLayout,this.bufferLayout);let r=new ge(this.bufferLayout);for(let[n,o]of Object.entries(e)){let a=r.getBufferLayout(n);if(!a){i||P.log.warn(`Model(${this.id}): Missing layout for buffer "${n}".`)();continue}let c=r.getAttributeNamesForBuffer(a),l=!1;for(let h of c){let d=this._attributeInfos[h];if(d){let u=this.device.type==="webgpu"?r.getBufferIndex(d.bufferName):d.location;this.vertexArray.setBuffer(u,o),l=!0}}!l&&!i&&P.log.warn(`Model(${this.id}): Ignoring buffer "${o.id}" for unknown attribute "${n}"`)()}this.setNeedsRedraw("attributes")}setConstantAttributes(e,t){for(let[i,r]of Object.entries(e)){let n=this._attributeInfos[i];n?this.vertexArray.setConstantWebGL(n.location,r):(t?.disableWarnings??this.props.disableWarnings)||P.log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${i}"`)()}this.setNeedsRedraw("constants")}_areBindingsLoading(){for(let e of Object.values(this.bindings))if(e instanceof H&&!e.isReady)return e.id;return!1}_getBindings(){let e={};for(let[t,i]of Object.entries(this.bindings))i instanceof H?i.isReady&&(e[t]=i.texture):e[t]=i;return e}_getBindingsUpdateTimestamp(){let e=0;for(let t of Object.values(this.bindings))t instanceof P.TextureView?e=Math.max(e,t.texture.updateTimestamp):t instanceof P.Buffer||t instanceof P.Texture?e=Math.max(e,t.updateTimestamp):t instanceof H?e=t.texture?Math.max(e,t.texture.updateTimestamp):1/0:t instanceof P.Sampler||(e=Math.max(e,t.buffer.updateTimestamp));return e}_setGeometryAttributes(e){let t={...e.attributes};for(let[i]of Object.entries(t))!this.pipeline.shaderLayout.attributes.find(r=>r.name===i)&&i!=="positions"&&delete t[i];this.vertexCount=e.vertexCount,this.setIndexBuffer(e.indices||null),this.setAttributes(e.attributes,{disableWarnings:!0}),this.setAttributes(t,{disableWarnings:this.props.disableWarnings}),this.setNeedsRedraw("geometry attributes")}_setPipelineNeedsUpdate(e){this._pipelineNeedsUpdate||=e,this.setNeedsRedraw(e)}_updatePipeline(){if(this._pipelineNeedsUpdate){let e=null,t=null;this.pipeline&&(P.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),e=this.pipeline.vs,t=this.pipeline.fs),this._pipelineNeedsUpdate=!1;let i=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:"vertex",source:this.source||this.vs,debugShaders:this.props.debugShaders}),r=null;this.source?r=i:this.fs&&(r=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:i,fs:r}),this._attributeInfos=(0,P.getAttributeInfosFromLayouts)(this.pipeline.shaderLayout,this.bufferLayout),e&&this.shaderFactory.release(e),t&&t!==e&&this.shaderFactory.release(t)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let e=P.log.level>3?0:Ri;P.log.level<2||Date.now()-this._lastLogTime<e||(this._lastLogTime=Date.now(),this._logOpen=!0,P.log.group(ue,`>>> DRAWING MODEL ${this.id}`,{collapsed:P.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let e=Jt(this.pipeline.shaderLayout,this.id);P.log.table(ue,e)();let t=this.shaderInputs.getDebugTable();P.log.table(ue,t)();let i=this._getAttributeDebugTable();P.log.table(ue,this._attributeInfos)(),P.log.table(ue,i)(),P.log.groupEnd(ue)(),this._logOpen=!1}}_drawCount=0;_logFramebuffer(e){let t=this.device.props.debugFramebuffers;if(this._drawCount++,!t)return;let i=e.props.framebuffer;i&&es(i,{id:i.id,minimap:!0})}_getAttributeDebugTable(){let e={};for(let[t,i]of Object.entries(this._attributeInfos)){let r=this.vertexArray.attributes[i.location];e[i.location]={name:t,type:i.shaderType,values:r?this._getBufferOrConstantValues(r,i.bufferDataType):"null"}}if(this.vertexArray.indexBuffer){let{indexBuffer:t}=this.vertexArray,i=t.indexType==="uint32"?new Uint32Array(t.debugData):new Uint16Array(t.debugData);e.indices={name:"indices",type:t.indexType,values:i.toString()}}return e}_getBufferOrConstantValues(e,t){let i=(0,P.getTypedArrayConstructor)(t);return(e instanceof P.Buffer?new i(e.debugData):e).toString()}},X=It;$(X,"defaultProps",{...P.RenderPipeline.defaultProps,source:void 0,vs:null,fs:null,id:"unnamed",handle:void 0,userData:{},defines:{},modules:[],geometry:null,indexBuffer:null,attributes:{},constantAttributes:{},bindings:{},uniforms:{},varyings:[],isInstanced:void 0,instanceCount:0,vertexCount:0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,transformFeedback:void 0,shaderAssembler:fs.ShaderAssembler.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0});function Oi(s){return Boolean(s.uniformTypes&&!ki(s.uniformTypes))}function Li(s){return{type:s.type,shaderLanguage:s.info.shadingLanguage,shaderLanguageVersion:s.info.shadingLanguageVersion,gpu:s.info.gpu,features:s.features}}function ki(s){for(let e in s)return!1;return!0}var ps=k(B(),1),ms=k(he(),1);var Ye=class{device;model;transformFeedback;static isSupported(e){return e?.info?.type==="webgl"}constructor(e,t=Ye.defaultProps){if(!Ye.isSupported(e))throw new Error("BufferTransform not yet implemented on WebGPU");this.device=e,this.model=new X(this.device,{id:t.id||"buffer-transform-model",fs:t.fs||(0,ms.getPassthroughFS)(),topology:t.topology||"point-list",varyings:t.outputs||t.varyings,...t}),this.transformFeedback=this.device.createTransformFeedback({layout:this.model.pipeline.shaderLayout,buffers:t.feedbackBuffers}),this.model.setTransformFeedback(this.transformFeedback),Object.seal(this)}destroy(){this.model&&this.model.destroy()}delete(){this.destroy()}run(e){e?.inputBuffers&&this.model.setAttributes(e.inputBuffers),e?.outputBuffers&&this.transformFeedback.setBuffers(e.outputBuffers);let t=this.device.beginRenderPass(e);this.model.draw(t),t.end()}getBuffer(e){return this.transformFeedback.getBuffer(e)}readAsync(e){let t=this.getBuffer(e);if(!t)throw new Error("BufferTransform#getBuffer");if(t instanceof ps.Buffer)return t.readAsync();let{buffer:i,byteOffset:r=0,byteLength:n=i.byteLength}=t;return i.readAsync(r,n)}},Re=Ye;$(Re,"defaultProps",{...X.defaultProps,outputs:void 0,feedbackBuffers:void 0});var gs=k(he(),1);var Fi="transform_output",Xe=class{device;model;sampler;currentIndex=0;samplerTextureMap=null;bindings=[];resources={};constructor(e,t){this.device=e,this.sampler=e.createSampler({addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",minFilter:"nearest",magFilter:"nearest",mipmapFilter:"nearest"}),this.model=new X(this.device,{id:t.id||C("texture-transform-model"),fs:t.fs||(0,gs.getPassthroughFS)({input:t.targetTextureVarying,inputChannels:t.targetTextureChannels,output:Fi}),vertexCount:t.vertexCount,...t}),this._initialize(t),Object.seal(this)}destroy(){this.model.destroy();for(let e of this.bindings)e.framebuffer?.destroy()}delete(){this.destroy()}run(e){let{framebuffer:t}=this.bindings[this.currentIndex],i=this.device.beginRenderPass({framebuffer:t,...e});this.model.draw(i),i.end(),this.device.submit()}getTargetTexture(){let{targetTexture:e}=this.bindings[this.currentIndex];return e}getFramebuffer(){return this.bindings[this.currentIndex].framebuffer}_initialize(e){this._updateBindings(e)}_updateBindings(e){this.bindings[this.currentIndex]=this._updateBinding(this.bindings[this.currentIndex],e)}_updateBinding(e,{sourceBuffers:t,sourceTextures:i,targetTexture:r}){if(e||(e={sourceBuffers:{},sourceTextures:{},targetTexture:null}),Object.assign(e.sourceTextures,i),Object.assign(e.sourceBuffers,t),r){e.targetTexture=r;let{width:n,height:o}=r;e.framebuffer&&e.framebuffer.destroy(),e.framebuffer=this.device.createFramebuffer({id:"transform-framebuffer",width:n,height:o,colorAttachments:[r]}),e.framebuffer.resize({width:n,height:o})}return e}_setSourceTextureParameters(){let e=this.currentIndex,{sourceTextures:t}=this.bindings[e];for(let i in t)t[i].sampler=this.sampler}};var G=class{id;topology;vertexCount;indices;attributes;userData={};constructor(e){let{attributes:t={},indices:i=null,vertexCount:r=null}=e;this.id=e.id||C("geometry"),this.topology=e.topology,i&&(this.indices=ArrayBuffer.isView(i)?{value:i,size:1}:i),this.attributes={};for(let[n,o]of Object.entries(t)){let a=ArrayBuffer.isView(o)?{value:o}:o;if(!ArrayBuffer.isView(a.value))throw new Error(`${this._print(n)}: must be typed array or object with value as typed array`);if((n==="POSITION"||n==="positions")&&!a.size&&(a.size=3),n==="indices"){if(this.indices)throw new Error("Multiple indices detected");this.indices=a}else this.attributes[n]=a}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(e){return`Geometry ${this.id} attribute ${e}`}_setAttributes(e,t){return this}_calculateVertexCount(e,t){if(t)return t.value.length;let i=1/0;for(let r of Object.values(e)){let{value:n,size:o,constant:a}=r;!a&&n&&o!==void 0&&o>=1&&(i=Math.min(i,n.length/o))}return i}};var Ni=`struct VertexInputs {
8
+ @location(0) clipSpacePositions: vec2<f32>,
9
+ @location(1) texCoords: vec2<f32>,
10
+ @location(2) coordinates: vec2<f32>
11
11
  }
12
12
 
13
13
  struct FragmentInputs {
@@ -20,13 +20,13 @@ struct FragmentInputs {
20
20
  @vertex
21
21
  fn vertexMain(inputs: VertexInputs) -> FragmentInputs {
22
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;
23
+ outputs.Position = vec4(inputs.clipSpacePositions, 0., 1.);
24
+ outputs.position = inputs.clipSpacePositions;
25
+ outputs.coordinate = inputs.coordinates;
26
+ outputs.uv = inputs.texCoords;
27
27
  return outputs;
28
28
  }
29
- `,Ci=`#version 300 es
29
+ `,Di=`#version 300 es
30
30
  in vec2 clipSpacePositions;
31
31
  in vec2 texCoords;
32
32
  in vec2 coordinates;
@@ -41,26 +41,26 @@ void main(void) {
41
41
  coordinate = coordinates;
42
42
  uv = texCoords;
43
43
  }
44
- `,fs=[-1,-1,1,-1,-1,1,1,1],st=class extends Y{constructor(t,e){let i=fs.map(r=>r===-1?0:r);e.source&&(e={...e,source:`${Ii}
45
- ${e.source}`}),super(t,{id:e.id||C("clip-space"),...e,vs:Ci,vertexCount:4,geometry:new $({topology:"triangle-strip",vertexCount:4,attributes:{clipSpacePositions:{size:2,value:new Float32Array(fs)},texCoords:{size:2,value:new Float32Array(i)},coordinates:{size:2,value:new Float32Array(i)}}})})}};var Pi={name:"background",uniformTypes:{scale:"vec2<f32>"}},Ei=`@group(0) @binding(0) var backgroundTexture: texture_2d<f32>;
44
+ `,xs=[-1,-1,1,-1,-1,1,1,1],ne=class extends X{constructor(e,t){let i=xs.map(r=>r===-1?0:r);t.source&&(t={...t,source:`${Ni}
45
+ ${t.source}`}),super(e,{id:t.id||C("clip-space"),...t,vs:Di,vertexCount:4,geometry:new G({topology:"triangle-strip",vertexCount:4,attributes:{clipSpacePositions:{size:2,value:new Float32Array(xs)},texCoords:{size:2,value:new Float32Array(i)},coordinates:{size:2,value:new Float32Array(i)}}})})}};var zi={name:"background",uniformTypes:{scale:"vec2<f32>"}},$i=`@group(0) @binding(0) var backgroundTexture: texture_2d<f32>;
46
46
  @group(0) @binding(1) var backgroundTextureSampler: sampler;
47
47
  struct backgroundUniforms {
48
48
  scale: vec2<f32>,
49
49
  };
50
50
  @group(0) @binding(2) var<uniform> background: backgroundUniforms;
51
51
 
52
- fn billboardTexture_getTextureUV(coordinates: vec2<f32>) -> vec2<f32> {
52
+ fn billboardTexture_getTextureUV(uv: vec2<f32>) -> vec2<f32> {
53
53
  let scale: vec2<f32> = background.scale;
54
- var position: vec2<f32> = (coordinates - vec2<f32>(0.5, 0.5)) / scale + vec2<f32>(0.5, 0.5);
54
+ var position: vec2<f32> = (uv - vec2<f32>(0.5, 0.5)) / scale + vec2<f32>(0.5, 0.5);
55
55
  return position;
56
56
  }
57
57
 
58
58
  @fragment
59
59
  fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {
60
- let position: vec2<f32> = billboardTexture_getTextureUV(inputs.coordinate);
60
+ let position: vec2<f32> = billboardTexture_getTextureUV(inputs.uv);
61
61
  return textureSample(backgroundTexture, backgroundTextureSampler, position);
62
62
  }
63
- `,Ri=`#version 300 es
63
+ `,Bi=`#version 300 es
64
64
  precision highp float;
65
65
 
66
66
  uniform sampler2D backgroundTexture;
@@ -81,47 +81,28 @@ void main(void) {
81
81
  vec2 position = billboardTexture_getTextureUV(coordinate);
82
82
  fragColor = texture(backgroundTexture, position);
83
83
  }
84
- `,gt=class extends st{backgroundTexture=null;constructor(t,e){if(super(t,{id:e.id||"background-texture-model",source:Ei,fs:Ri,modules:[Pi],parameters:{depthWriteEnabled:!1,...e.blend?{blend:!0,blendColorOperation:"add",blendAlphaOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one-minus-src",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one-minus-src-alpha"}:{}}}),!e.backgroundTexture)throw new Error("BackgroundTextureModel requires a backgroundTexture prop");this.setProps(e)}setProps(t){let{backgroundTexture:e}=t;if(e)if(this.setBindings({backgroundTexture:e}),e.isReady){let i=e instanceof q?e.texture:e;this.backgroundTexture=i,this.updateScale(i)}else e.ready.then(i=>{this.backgroundTexture=i,this.updateScale(i)})}predraw(){super.predraw()}updateScale(t){if(!t){this.shaderInputs.setProps({background:{scale:[1,1]}});return}let[e,i]=this.device.getCanvasContext().getDrawingBufferSize(),r=t.width,n=t.height,o=e/i,a=r/n,c=1,h=1;o>a?h=o/a:c=a/o,this.shaderInputs.setProps({background:{scale:[c,h]}})}};var Hn=1/Math.PI*180,Kn=1/180*Math.PI,Oi={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Oi}};var F=globalThis.mathgl.config;function us(s,{precision:t=F.precision}={}){return s=ki(s),`${parseFloat(s.toPrecision(t))}`}function xt(s){return Array.isArray(s)||ArrayBuffer.isView(s)&&!(s instanceof DataView)}function Ae(s,t,e){let i=F.EPSILON;e&&(F.EPSILON=e);try{if(s===t)return!0;if(xt(s)&&xt(t)){if(s.length!==t.length)return!1;for(let r=0;r<s.length;++r)if(!Ae(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)<=F.EPSILON*Math.max(1,Math.abs(s),Math.abs(t)):!1}finally{F.EPSILON=i}}function ki(s){return Math.round(s/F.EPSILON)*F.EPSILON}var yt=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,e=0){for(let i=0;i<this.ELEMENTS;++i)this[i]=t[i+e];return this.check()}toArray(t=[],e=0){for(let i=0;i<this.ELEMENTS;++i)t[e+i]=this[i];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:xt(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(F)}formatString(t){let e="";for(let i=0;i<this.ELEMENTS;++i)e+=(i>0?", ":"")+us(this[i],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(!Ae(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,i){if(i===void 0)return this.lerp(this,t,e);for(let r=0;r<this.ELEMENTS;++r){let n=t[r],o=typeof e=="number"?e:e[r];this[r]=n+i*(o-n)}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 i=0;i<this.ELEMENTS;++i)this[i]=Math.min(Math.max(this[i],t[i]),e[i]);return this.check()}add(...t){for(let e of t)for(let i=0;i<this.ELEMENTS;++i)this[i]+=e[i];return this.check()}subtract(...t){for(let e of t)for(let i=0;i<this.ELEMENTS;++i)this[i]-=e[i];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(F.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 i=0;i<this.ELEMENTS;++i)this[i]=Math.min(Math.max(this[i],t),e);return this.check()}get elements(){return this}};function Li(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 U(s){if(!Number.isFinite(s))throw new Error(`Invalid number ${JSON.stringify(s)}`);return s}function Kt(s,t,e=""){if(F.debug&&!Li(s,t))throw new Error(`math.gl: ${e} some fields set to invalid numbers'`);return s}function Se(s,t){if(!s)throw new Error(`math.gl assertion ${t}`)}var Zt=class extends yt{get x(){return this[0]}set x(t){this[0]=U(t)}get y(){return this[1]}set y(t){this[1]=U(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 i=0;i<this.ELEMENTS;++i){let r=this[i]-t[i];e+=r*r}return U(e)}dot(t){let e=0;for(let i=0;i<this.ELEMENTS;++i)e+=this[i]*t[i];return U(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 i=0;i<this.ELEMENTS;++i)this[i]*=e[i];return this.check()}divide(...t){for(let e of t)for(let i=0;i<this.ELEMENTS;++i)this[i]/=e[i];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(t){return this.distance(t)}distanceToSquared(t){return this.distanceSquared(t)}getComponent(t){return Se(t>=0&&t<this.ELEMENTS,"index is out of range"),U(this[t])}setComponent(t,e){return Se(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 it=typeof Float32Array<"u"?Float32Array:Array;var ao=Math.PI/180;function Ni(){let s=new it(2);return it!=Float32Array&&(s[0]=0,s[1]=0),s}function gs(s,t,e){let i=t[0],r=t[1];return s[0]=e[0]*i+e[4]*r+e[12],s[1]=e[1]*i+e[5]*r+e[13],s}var co=function(){let s=Ni();return function(t,e,i,r,n,o){let a,c;for(e||(e=2),i||(i=0),r?c=Math.min(r*e+i,t.length):c=t.length,a=i;a<c;a+=e)s[0]=t[a],s[1]=t[a+1],n(s,s,o),t[a]=s[0],t[a+1]=s[1];return t}}();function xs(s,t,e){let i=t[0],r=t[1],n=e[3]*i+e[7]*r||1;return s[0]=(e[0]*i+e[4]*r)/n,s[1]=(e[1]*i+e[5]*r)/n,s}function Qt(s,t,e){let i=t[0],r=t[1],n=t[2],o=e[3]*i+e[7]*r+e[11]*n||1;return s[0]=(e[0]*i+e[4]*r+e[8]*n)/o,s[1]=(e[1]*i+e[5]*r+e[9]*n)/o,s[2]=(e[2]*i+e[6]*r+e[10]*n)/o,s}function ys(s,t,e){let i=t[0],r=t[1];return s[0]=e[0]*i+e[2]*r,s[1]=e[1]*i+e[3]*r,s[2]=t[2],s}function Di(){let s=new it(3);return it!=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 bs(s,t,e){let i=t[0],r=t[1],n=t[2],o=e[0],a=e[1],c=e[2];return s[0]=r*c-n*a,s[1]=n*o-i*c,s[2]=i*a-r*o,s}function Jt(s,t,e){let i=t[0],r=t[1],n=t[2],o=e[3]*i+e[7]*r+e[11]*n+e[15];return o=o||1,s[0]=(e[0]*i+e[4]*r+e[8]*n+e[12])/o,s[1]=(e[1]*i+e[5]*r+e[9]*n+e[13])/o,s[2]=(e[2]*i+e[6]*r+e[10]*n+e[14])/o,s}function vs(s,t,e){let i=t[0],r=t[1],n=t[2];return s[0]=i*e[0]+r*e[3]+n*e[6],s[1]=i*e[1]+r*e[4]+n*e[7],s[2]=i*e[2]+r*e[5]+n*e[8],s}function Ms(s,t,e){let i=e[0],r=e[1],n=e[2],o=e[3],a=t[0],c=t[1],h=t[2],l=r*h-n*c,d=n*a-i*h,f=i*c-r*a,m=r*f-n*d,b=n*l-i*f,u=i*d-r*l,x=o*2;return l*=x,d*=x,f*=x,m*=2,b*=2,u*=2,s[0]=a+l+m,s[1]=c+d+b,s[2]=h+f+u,s}function _s(s,t,e,i){let r=[],n=[];return r[0]=t[0]-e[0],r[1]=t[1]-e[1],r[2]=t[2]-e[2],n[0]=r[0],n[1]=r[1]*Math.cos(i)-r[2]*Math.sin(i),n[2]=r[1]*Math.sin(i)+r[2]*Math.cos(i),s[0]=n[0]+e[0],s[1]=n[1]+e[1],s[2]=n[2]+e[2],s}function ws(s,t,e,i){let r=[],n=[];return r[0]=t[0]-e[0],r[1]=t[1]-e[1],r[2]=t[2]-e[2],n[0]=r[2]*Math.sin(i)+r[0]*Math.cos(i),n[1]=r[1],n[2]=r[2]*Math.cos(i)-r[0]*Math.sin(i),s[0]=n[0]+e[0],s[1]=n[1]+e[1],s[2]=n[2]+e[2],s}function As(s,t,e,i){let r=[],n=[];return r[0]=t[0]-e[0],r[1]=t[1]-e[1],r[2]=t[2]-e[2],n[0]=r[0]*Math.cos(i)-r[1]*Math.sin(i),n[1]=r[0]*Math.sin(i)+r[1]*Math.cos(i),n[2]=r[2],s[0]=n[0]+e[0],s[1]=n[1]+e[1],s[2]=n[2]+e[2],s}function Ss(s,t){let e=s[0],i=s[1],r=s[2],n=t[0],o=t[1],a=t[2],c=Math.sqrt((e*e+i*i+r*r)*(n*n+o*o+a*a)),h=c&&Fi(s,t)/c;return Math.acos(Math.min(Math.max(h,-1),1))}var fo=function(){let s=Di();return function(t,e,i,r,n,o){let a,c;for(e||(e=3),i||(i=0),r?c=Math.min(r*e+i,t.length):c=t.length,a=i;a<c;a+=e)s[0]=t[a],s[1]=t[a+1],s[2]=t[a+2],n(s,s,o),t[a]=s[0],t[a+1]=s[1],t[a+2]=s[2];return t}}();var Ie=[0,0,0],te,G=class extends Zt{static get ZERO(){return te||(te=new G(0,0,0),Object.freeze(te)),te}constructor(t=0,e=0,i=0){super(-0,-0,-0),arguments.length===1&&xt(t)?this.copy(t):(F.debug&&(U(t),U(e),U(i)),this[0]=t,this[1]=e,this[2]=i)}set(t,e,i){return this[0]=t,this[1]=e,this[2]=i,this.check()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this.check()}fromObject(t){return F.debug&&(U(t.x),U(t.y),U(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]=U(t)}angle(t){return Ss(this,t)}cross(t){return bs(this,this,t),this.check()}rotateX({radians:t,origin:e=Ie}){return _s(this,this,e,t),this.check()}rotateY({radians:t,origin:e=Ie}){return ws(this,this,e,t),this.check()}rotateZ({radians:t,origin:e=Ie}){return As(this,this,e,t),this.check()}transform(t){return this.transformAsPoint(t)}transformAsPoint(t){return Jt(this,this,t),this.check()}transformAsVector(t){return Qt(this,this,t),this.check()}transformByMatrix3(t){return vs(this,this,t),this.check()}transformByMatrix2(t){return ys(this,this,t),this.check()}transformByQuaternion(t){return Ms(this,this,t),this.check()}};var ee=class extends yt{toString(){let t="[";if(F.printRowMajor){t+="row-major:";for(let e=0;e<this.RANK;++e)for(let i=0;i<this.RANK;++i)t+=` ${this[i*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,i){return this[e*this.RANK+t]=U(i),this}getColumn(t,e=new Array(this.RANK).fill(-0)){let i=t*this.RANK;for(let r=0;r<this.RANK;++r)e[r]=this[i+r];return e}setColumn(t,e){let i=t*this.RANK;for(let r=0;r<this.RANK;++r)this[i+r]=e[r];return this}};function zi(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 Ts(s,t){if(s===t){let e=t[1],i=t[2],r=t[3],n=t[6],o=t[7],a=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]=i,s[9]=n,s[11]=t[14],s[12]=r,s[13]=o,s[14]=a}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 Is(s,t){let e=t[0],i=t[1],r=t[2],n=t[3],o=t[4],a=t[5],c=t[6],h=t[7],l=t[8],d=t[9],f=t[10],m=t[11],b=t[12],u=t[13],x=t[14],v=t[15],_=e*a-i*o,p=e*c-r*o,g=e*h-n*o,y=i*c-r*a,M=i*h-n*a,I=r*h-n*c,R=l*u-d*b,P=l*x-f*b,O=l*v-m*b,w=d*x-f*u,S=d*v-m*u,E=f*v-m*x,A=_*E-p*S+g*w+y*O-M*P+I*R;return A?(A=1/A,s[0]=(a*E-c*S+h*w)*A,s[1]=(r*S-i*E-n*w)*A,s[2]=(u*I-x*M+v*y)*A,s[3]=(f*M-d*I-m*y)*A,s[4]=(c*O-o*E-h*P)*A,s[5]=(e*E-r*O+n*P)*A,s[6]=(x*g-b*I-v*p)*A,s[7]=(l*I-f*g+m*p)*A,s[8]=(o*S-a*O+h*R)*A,s[9]=(i*O-e*S-n*R)*A,s[10]=(b*M-u*g+v*_)*A,s[11]=(d*g-l*M-m*_)*A,s[12]=(a*P-o*w-c*R)*A,s[13]=(e*w-i*P+r*R)*A,s[14]=(u*p-b*y-x*_)*A,s[15]=(l*y-d*p+f*_)*A,s):null}function Cs(s){let t=s[0],e=s[1],i=s[2],r=s[3],n=s[4],o=s[5],a=s[6],c=s[7],h=s[8],l=s[9],d=s[10],f=s[11],m=s[12],b=s[13],u=s[14],x=s[15],v=t*o-e*n,_=t*a-i*n,p=e*a-i*o,g=h*b-l*m,y=h*u-d*m,M=l*u-d*b,I=t*M-e*y+i*g,R=n*M-o*y+a*g,P=h*p-l*_+d*v,O=m*p-b*_+u*v;return c*I-r*R+x*P-f*O}function Ce(s,t,e){let i=t[0],r=t[1],n=t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],d=t[8],f=t[9],m=t[10],b=t[11],u=t[12],x=t[13],v=t[14],_=t[15],p=e[0],g=e[1],y=e[2],M=e[3];return s[0]=p*i+g*a+y*d+M*u,s[1]=p*r+g*c+y*f+M*x,s[2]=p*n+g*h+y*m+M*v,s[3]=p*o+g*l+y*b+M*_,p=e[4],g=e[5],y=e[6],M=e[7],s[4]=p*i+g*a+y*d+M*u,s[5]=p*r+g*c+y*f+M*x,s[6]=p*n+g*h+y*m+M*v,s[7]=p*o+g*l+y*b+M*_,p=e[8],g=e[9],y=e[10],M=e[11],s[8]=p*i+g*a+y*d+M*u,s[9]=p*r+g*c+y*f+M*x,s[10]=p*n+g*h+y*m+M*v,s[11]=p*o+g*l+y*b+M*_,p=e[12],g=e[13],y=e[14],M=e[15],s[12]=p*i+g*a+y*d+M*u,s[13]=p*r+g*c+y*f+M*x,s[14]=p*n+g*h+y*m+M*v,s[15]=p*o+g*l+y*b+M*_,s}function Ps(s,t,e){let i=e[0],r=e[1],n=e[2],o,a,c,h,l,d,f,m,b,u,x,v;return t===s?(s[12]=t[0]*i+t[4]*r+t[8]*n+t[12],s[13]=t[1]*i+t[5]*r+t[9]*n+t[13],s[14]=t[2]*i+t[6]*r+t[10]*n+t[14],s[15]=t[3]*i+t[7]*r+t[11]*n+t[15]):(o=t[0],a=t[1],c=t[2],h=t[3],l=t[4],d=t[5],f=t[6],m=t[7],b=t[8],u=t[9],x=t[10],v=t[11],s[0]=o,s[1]=a,s[2]=c,s[3]=h,s[4]=l,s[5]=d,s[6]=f,s[7]=m,s[8]=b,s[9]=u,s[10]=x,s[11]=v,s[12]=o*i+l*r+b*n+t[12],s[13]=a*i+d*r+u*n+t[13],s[14]=c*i+f*r+x*n+t[14],s[15]=h*i+m*r+v*n+t[15]),s}function Es(s,t,e){let i=e[0],r=e[1],n=e[2];return s[0]=t[0]*i,s[1]=t[1]*i,s[2]=t[2]*i,s[3]=t[3]*i,s[4]=t[4]*r,s[5]=t[5]*r,s[6]=t[6]*r,s[7]=t[7]*r,s[8]=t[8]*n,s[9]=t[9]*n,s[10]=t[10]*n,s[11]=t[11]*n,s[12]=t[12],s[13]=t[13],s[14]=t[14],s[15]=t[15],s}function Rs(s,t,e,i){let r=i[0],n=i[1],o=i[2],a=Math.sqrt(r*r+n*n+o*o),c,h,l,d,f,m,b,u,x,v,_,p,g,y,M,I,R,P,O,w,S,E,A,D;return a<1e-6?null:(a=1/a,r*=a,n*=a,o*=a,h=Math.sin(e),c=Math.cos(e),l=1-c,d=t[0],f=t[1],m=t[2],b=t[3],u=t[4],x=t[5],v=t[6],_=t[7],p=t[8],g=t[9],y=t[10],M=t[11],I=r*r*l+c,R=n*r*l+o*h,P=o*r*l-n*h,O=r*n*l-o*h,w=n*n*l+c,S=o*n*l+r*h,E=r*o*l+n*h,A=n*o*l-r*h,D=o*o*l+c,s[0]=d*I+u*R+p*P,s[1]=f*I+x*R+g*P,s[2]=m*I+v*R+y*P,s[3]=b*I+_*R+M*P,s[4]=d*O+u*w+p*S,s[5]=f*O+x*w+g*S,s[6]=m*O+v*w+y*S,s[7]=b*O+_*w+M*S,s[8]=d*E+u*A+p*D,s[9]=f*E+x*A+g*D,s[10]=m*E+v*A+y*D,s[11]=b*E+_*A+M*D,t!==s&&(s[12]=t[12],s[13]=t[13],s[14]=t[14],s[15]=t[15]),s)}function Os(s,t,e){let i=Math.sin(e),r=Math.cos(e),n=t[4],o=t[5],a=t[6],c=t[7],h=t[8],l=t[9],d=t[10],f=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]=n*r+h*i,s[5]=o*r+l*i,s[6]=a*r+d*i,s[7]=c*r+f*i,s[8]=h*r-n*i,s[9]=l*r-o*i,s[10]=d*r-a*i,s[11]=f*r-c*i,s}function ks(s,t,e){let i=Math.sin(e),r=Math.cos(e),n=t[0],o=t[1],a=t[2],c=t[3],h=t[8],l=t[9],d=t[10],f=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]=n*r-h*i,s[1]=o*r-l*i,s[2]=a*r-d*i,s[3]=c*r-f*i,s[8]=n*i+h*r,s[9]=o*i+l*r,s[10]=a*i+d*r,s[11]=c*i+f*r,s}function Ls(s,t,e){let i=Math.sin(e),r=Math.cos(e),n=t[0],o=t[1],a=t[2],c=t[3],h=t[4],l=t[5],d=t[6],f=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]=n*r+h*i,s[1]=o*r+l*i,s[2]=a*r+d*i,s[3]=c*r+f*i,s[4]=h*r-n*i,s[5]=l*r-o*i,s[6]=d*r-a*i,s[7]=f*r-c*i,s}function Ns(s,t){let e=t[0],i=t[1],r=t[2],n=t[3],o=e+e,a=i+i,c=r+r,h=e*o,l=i*o,d=i*a,f=r*o,m=r*a,b=r*c,u=n*o,x=n*a,v=n*c;return s[0]=1-d-b,s[1]=l+v,s[2]=f-x,s[3]=0,s[4]=l-v,s[5]=1-h-b,s[6]=m+u,s[7]=0,s[8]=f+x,s[9]=m-u,s[10]=1-h-d,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s}function Ds(s,t,e,i,r,n,o){let a=1/(e-t),c=1/(r-i),h=1/(n-o);return s[0]=n*2*a,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=n*2*c,s[6]=0,s[7]=0,s[8]=(e+t)*a,s[9]=(r+i)*c,s[10]=(o+n)*h,s[11]=-1,s[12]=0,s[13]=0,s[14]=o*n*2*h,s[15]=0,s}function Bi(s,t,e,i,r){let n=1/Math.tan(t/2);if(s[0]=n/e,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=n,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/(i-r);s[10]=(r+i)*o,s[14]=2*r*i*o}else s[10]=-1,s[14]=-2*i;return s}var Fs=Bi;function $i(s,t,e,i,r,n,o){let a=1/(t-e),c=1/(i-r),h=1/(n-o);return s[0]=-2*a,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=-2*c,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=2*h,s[11]=0,s[12]=(t+e)*a,s[13]=(r+i)*c,s[14]=(o+n)*h,s[15]=1,s}var zs=$i;function Bs(s,t,e,i){let r,n,o,a,c,h,l,d,f,m,b=t[0],u=t[1],x=t[2],v=i[0],_=i[1],p=i[2],g=e[0],y=e[1],M=e[2];return Math.abs(b-g)<1e-6&&Math.abs(u-y)<1e-6&&Math.abs(x-M)<1e-6?zi(s):(d=b-g,f=u-y,m=x-M,r=1/Math.sqrt(d*d+f*f+m*m),d*=r,f*=r,m*=r,n=_*m-p*f,o=p*d-v*m,a=v*f-_*d,r=Math.sqrt(n*n+o*o+a*a),r?(r=1/r,n*=r,o*=r,a*=r):(n=0,o=0,a=0),c=f*a-m*o,h=m*n-d*a,l=d*o-f*n,r=Math.sqrt(c*c+h*h+l*l),r?(r=1/r,c*=r,h*=r,l*=r):(c=0,h=0,l=0),s[0]=n,s[1]=c,s[2]=d,s[3]=0,s[4]=o,s[5]=h,s[6]=f,s[7]=0,s[8]=a,s[9]=l,s[10]=m,s[11]=0,s[12]=-(n*b+o*u+a*x),s[13]=-(c*b+h*u+l*x),s[14]=-(d*b+f*u+m*x),s[15]=1,s)}function Ui(){let s=new it(4);return it!=Float32Array&&(s[0]=0,s[1]=0,s[2]=0,s[3]=0),s}function $s(s,t,e){let i=t[0],r=t[1],n=t[2],o=t[3];return s[0]=e[0]*i+e[4]*r+e[8]*n+e[12]*o,s[1]=e[1]*i+e[5]*r+e[9]*n+e[13]*o,s[2]=e[2]*i+e[6]*r+e[10]*n+e[14]*o,s[3]=e[3]*i+e[7]*r+e[11]*n+e[15]*o,s}var So=function(){let s=Ui();return function(t,e,i,r,n,o){let a,c;for(e||(e=4),i||(i=0),r?c=Math.min(r*e+i,t.length):c=t.length,a=i;a<c;a+=e)s[0]=t[a],s[1]=t[a+1],s[2]=t[a+2],s[3]=t[a+3],n(s,s,o),t[a]=s[0],t[a+1]=s[1],t[a+2]=s[2],t[a+3]=s[3];return t}}();var Re;(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"})(Re||(Re={}));var ji=45*Math.PI/180,Vi=1,Pe=.1,Ee=500,Gi=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),H=class extends ee{static get IDENTITY(){return Wi()}static get ZERO(){return qi()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Re}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,i,r,n,o,a,c,h,l,d,f,m,b,u,x){return this[0]=t,this[1]=e,this[2]=i,this[3]=r,this[4]=n,this[5]=o,this[6]=a,this[7]=c,this[8]=h,this[9]=l,this[10]=d,this[11]=f,this[12]=m,this[13]=b,this[14]=u,this[15]=x,this.check()}setRowMajor(t,e,i,r,n,o,a,c,h,l,d,f,m,b,u,x){return this[0]=t,this[1]=n,this[2]=h,this[3]=m,this[4]=e,this[5]=o,this[6]=l,this[7]=b,this[8]=i,this[9]=a,this[10]=d,this[11]=u,this[12]=r,this[13]=c,this[14]=f,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(Gi)}fromObject(t){return this.check()}fromQuaternion(t){return Ns(this,t),this.check()}frustum(t){let{left:e,right:i,bottom:r,top:n,near:o=Pe,far:a=Ee}=t;return a===1/0?Yi(this,e,i,r,n,o):Ds(this,e,i,r,n,o,a),this.check()}lookAt(t){let{eye:e,center:i=[0,0,0],up:r=[0,1,0]}=t;return Bs(this,e,i,r),this.check()}ortho(t){let{left:e,right:i,bottom:r,top:n,near:o=Pe,far:a=Ee}=t;return zs(this,e,i,r,n,o,a),this.check()}orthographic(t){let{fovy:e=ji,aspect:i=Vi,focalDistance:r=1,near:n=Pe,far:o=Ee}=t;Us(e);let a=e/2,c=r*Math.tan(a),h=c*i;return this.ortho({left:-h,right:h,bottom:-c,top:c,near:n,far:o})}perspective(t){let{fovy:e=45*Math.PI/180,aspect:i=1,near:r=.1,far:n=500}=t;return Us(e),Fs(this,e,i,r,n),this.check()}determinant(){return Cs(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 i=this.getScale(e),r=1/i[0],n=1/i[1],o=1/i[2];return t[0]=this[0]*r,t[1]=this[1]*n,t[2]=this[2]*o,t[3]=0,t[4]=this[4]*r,t[5]=this[5]*n,t[6]=this[6]*o,t[7]=0,t[8]=this[8]*r,t[9]=this[9]*n,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 i=this.getScale(e),r=1/i[0],n=1/i[1],o=1/i[2];return t[0]=this[0]*r,t[1]=this[1]*n,t[2]=this[2]*o,t[3]=this[4]*r,t[4]=this[5]*n,t[5]=this[6]*o,t[6]=this[8]*r,t[7]=this[9]*n,t[8]=this[10]*o,t}transpose(){return Ts(this,this),this.check()}invert(){return Is(this,this),this.check()}multiplyLeft(t){return Ce(this,t,this),this.check()}multiplyRight(t){return Ce(this,this,t),this.check()}rotateX(t){return Os(this,this,t),this.check()}rotateY(t){return ks(this,this,t),this.check()}rotateZ(t){return Ls(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,e){return Rs(this,this,t,e),this.check()}scale(t){return Es(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return Ps(this,this,t),this.check()}transform(t,e){return t.length===4?(e=$s(e||[-0,-0,-0,-0],t,this),Kt(e,4),e):this.transformAsPoint(t,e)}transformAsPoint(t,e){let{length:i}=t,r;switch(i){case 2:r=gs(e||[-0,-0],t,this);break;case 3:r=Jt(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Kt(r,t.length),r}transformAsVector(t,e){let i;switch(t.length){case 2:i=xs(e||[-0,-0],t,this);break;case 3:i=Qt(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Kt(i,t.length),i}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,i){return this.identity().translate([t,e,i])}},se,ie;function qi(){return se||(se=new H([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(se)),se}function Wi(){return ie||(ie=new H,Object.freeze(ie)),ie}function Us(s){if(s>Math.PI*2)throw Error("expected radians")}function Yi(s,t,e,i,r,n){let o=2*n/(e-t),a=2*n/(r-i),c=(e+t)/(e-t),h=(r+i)/(r-i),l=-1,d=-1,f=-2*n;return s[0]=o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a,s[6]=0,s[7]=0,s[8]=c,s[9]=h,s[10]=l,s[11]=d,s[12]=0,s[13]=0,s[14]=f,s[15]=0,s}var rt=class{id;matrix=new H;display=!0;position=new G;rotation=new G;scale=new G(1,1,1);userData={};props={};constructor(t={}){let{id:e}=t;this.id=e||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:i,scale:r,update:n=!0}=t;return e&&this.setPosition(e),i&&this.setRotation(i),r&&this.setScale(r),n&&this.updateMatrix(),this}updateMatrix(){let t=this.position,e=this.rotation,i=this.scale;return this.matrix.identity(),this.matrix.translate(t),this.matrix.rotateXYZ(e),this.matrix.scale(i),this}update(t={}){let{position:e,rotation:i,scale:r}=t;return e&&this.setPosition(e),i&&this.setRotation(i),r&&this.setScale(r),this.updateMatrix(),this}getCoordinateUniforms(t,e){e=e||this.matrix;let i=new H(t).multiplyRight(e),r=i.invert(),n=r.transpose();return{viewMatrix:t,modelMatrix:e,objectMatrix:e,worldMatrix:i,worldInverseMatrix:r,worldInverseTransposeMatrix:n}}_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 js=L(B(),1);var vt=class extends rt{children;constructor(t={}){t=Array.isArray(t)?{children:t}:t;let{children:e=[]}=t;js.log.assert(e.every(i=>i instanceof rt),"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:i})=>{let r=e.getBounds();if(!r)return;let[n,o]=r,a=new G(n).add(o).divide([2,2,2]);i.transformAsPoint(a,a);let c=new G(o).subtract(n).divide([2,2,2]);i.transformAsVector(c,c);for(let h=0;h<8;h++){let l=new G(h&1?-1:1,h&2?-1:1,h&4?-1:1).multiply(c).add(a);for(let d=0;d<3;d++)t[0][d]=Math.min(t[0][d],l[d]),t[1][d]=Math.max(t[1][d],l[d])}}),Number.isFinite(t[0][0])?t:null}destroy(){this.children.forEach(t=>t.destroy()),this.removeAll(),super.destroy()}add(...t){for(let e of t)Array.isArray(e)?this.add(...e):this.children.push(e);return this}remove(t){let e=this.children,i=e.indexOf(t);return i>-1&&e.splice(i,1),this}removeAll(){return this.children=[],this}traverse(t,{worldMatrix:e=new H}={}){let i=new H(e).multiplyRight(this.matrix);for(let r of this.children)r instanceof vt?r.traverse(t,{worldMatrix:i}):t(r,{worldMatrix:i})}};var re=class extends rt{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 Xi={x:[2,0,1],y:[0,1,2],z:[1,2,0]},ot=class extends ${constructor(t={}){let{id:e=C("truncated-code-geometry")}=t,{indices:i,attributes:r}=Hi(t);super({...t,id:e,topology:"triangle-list",indices:i,attributes:{POSITION:{size:3,value:r.POSITION},NORMAL:{size:3,value:r.NORMAL},TEXCOORD_0:{size:2,value:r.TEXCOORD_0},...t.attributes}})}};function Hi(s={}){let{bottomRadius:t=0,topRadius:e=0,height:i=1,nradial:r=10,nvertical:n=10,verticalAxis:o="y",topCap:a=!1,bottomCap:c=!1}=s,h=(a?2:0)+(c?2:0),l=(r+1)*(n+1+h),d=Math.atan2(t-e,i),f=Math.sin,m=Math.cos,b=Math.PI,u=m(d),x=f(d),v=a?-2:0,_=n+(c?2:0),p=r+1,g=new Uint16Array(r*(n+h)*6),y=Xi[o],M=new Float32Array(l*3),I=new Float32Array(l*3),R=new Float32Array(l*2),P=0,O=0;for(let w=v;w<=_;w++){let S=w/n,E=i*S,A;w<0?(E=0,S=1,A=t):w>n?(E=i,S=1,A=e):A=t+(e-t)*(w/n),(w===-2||w===n+2)&&(A=0,S=0),E-=i/2;for(let D=0;D<p;D++){let J=f(D*b*2/r),X=m(D*b*2/r);M[P+y[0]]=J*A,M[P+y[1]]=E,M[P+y[2]]=X*A,I[P+y[0]]=w<0||w>n?0:J*u,I[P+y[1]]=w<0?-1:w>n?1:x,I[P+y[2]]=w<0||w>n?0:X*u,R[O+0]=D/r,R[O+1]=S,O+=2,P+=3}}for(let w=0;w<n+h;w++)for(let S=0;S<r;S++){let E=(w*r+S)*6;g[E+0]=p*(w+0)+0+S,g[E+1]=p*(w+0)+1+S,g[E+2]=p*(w+1)+1+S,g[E+3]=p*(w+0)+0+S,g[E+4]=p*(w+1)+1+S,g[E+5]=p*(w+1)+0+S}return{indices:g,attributes:{POSITION:M,NORMAL:I,TEXCOORD_0:R}}}var ne=class extends ot{constructor(t={}){let{id:e=C("cone-geometry"),radius:i=1,cap:r=!0}=t;super({...t,id:e,topRadius:0,topCap:Boolean(r),bottomCap:Boolean(r),bottomRadius:i})}};var oe=class extends ${constructor(t={}){let{id:e=C("cube-geometry"),indices:i=!0}=t;super(i?{...t,id:e,topology:"triangle-list",indices:{size:1,value:Ki},attributes:{...ir,...t.attributes}}:{...t,id:e,topology:"triangle-list",indices:void 0,attributes:{...rr,...t.attributes}})}},Ki=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]),Zi=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]),Qi=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]),Ji=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]),tr=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]),er=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]),sr=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]),ir={POSITION:{size:3,value:Zi},NORMAL:{size:3,value:Qi},TEXCOORD_0:{size:2,value:Ji}},rr={POSITION:{size:3,value:tr},TEXCOORD_0:{size:2,value:er},COLOR_0:{size:3,value:sr}};var ae=class extends ot{constructor(t={}){let{id:e=C("cylinder-geometry"),radius:i=1}=t;super({...t,id:e,bottomRadius:i,topRadius:i})}};var nr=[-1,0,0,0,1,0,0,0,-1,0,0,1,0,-1,0,1,0,0],or=[3,4,5,3,5,1,3,1,0,3,0,4,4,0,2,4,2,5,2,0,1,5,2,1],ce=class extends ${constructor(t={}){let{id:e=C("ico-sphere-geometry")}=t,{indices:i,attributes:r}=ar(t);super({...t,id:e,topology:"triangle-list",indices:i,attributes:{...r,...t.attributes}})}};function ar(s){let{iterations:t=0}=s,e=Math.PI,i=e*2,r=[...nr],n=[...or];r.push(),n.push();let o=(()=>{let l={};return(d,f)=>{d*=3,f*=3;let m=d<f?d:f,b=d>f?d:f,u=`${m}|${b}`;if(u in l)return l[u];let x=r[d],v=r[d+1],_=r[d+2],p=r[f],g=r[f+1],y=r[f+2],M=(x+p)/2,I=(v+g)/2,R=(_+y)/2,P=Math.sqrt(M*M+I*I+R*R);return M/=P,I/=P,R/=P,r.push(M,I,R),l[u]=r.length/3-1}})();for(let l=0;l<t;l++){let d=[];for(let f=0;f<n.length;f+=3){let m=o(n[f+0],n[f+1]),b=o(n[f+1],n[f+2]),u=o(n[f+2],n[f+0]);d.push(u,n[f+0],m,m,n[f+1],b,b,n[f+2],u,m,b,u)}n=d}let a=new Array(r.length),c=new Array(r.length/3*2),h=n.length;for(let l=h-3;l>=0;l-=3){let d=n[l+0],f=n[l+1],m=n[l+2],b=d*3,u=f*3,x=m*3,v=d*2,_=f*2,p=m*2,g=r[b+0],y=r[b+1],M=r[b+2],I=Math.acos(M/Math.sqrt(g*g+y*y+M*M)),R=Math.atan2(y,g)+e,P=I/e,O=1-R/i,w=r[u+0],S=r[u+1],E=r[u+2],A=Math.acos(E/Math.sqrt(w*w+S*S+E*E)),D=Math.atan2(S,w)+e,J=A/e,X=1-D/i,Nt=r[x+0],Dt=r[x+1],Ft=r[x+2],Js=Math.acos(Ft/Math.sqrt(Nt*Nt+Dt*Dt+Ft*Ft)),ti=Math.atan2(Dt,Nt)+e,ze=Js/e,zt=1-ti/i,ei=[Nt-w,Dt-S,Ft-E],si=[g-w,y-S,M-E],W=new G(ei).cross(si).normalize(),k;(O===0||X===0||zt===0)&&(O===0||O>.5)&&(X===0||X>.5)&&(zt===0||zt>.5)&&(r.push(r[b+0],r[b+1],r[b+2]),k=r.length/3-1,n.push(k),c[k*2+0]=1,c[k*2+1]=P,a[k*3+0]=W.x,a[k*3+1]=W.y,a[k*3+2]=W.z,r.push(r[u+0],r[u+1],r[u+2]),k=r.length/3-1,n.push(k),c[k*2+0]=1,c[k*2+1]=J,a[k*3+0]=W.x,a[k*3+1]=W.y,a[k*3+2]=W.z,r.push(r[x+0],r[x+1],r[x+2]),k=r.length/3-1,n.push(k),c[k*2+0]=1,c[k*2+1]=ze,a[k*3+0]=W.x,a[k*3+1]=W.y,a[k*3+2]=W.z),a[b+0]=a[u+0]=a[x+0]=W.x,a[b+1]=a[u+1]=a[x+1]=W.y,a[b+2]=a[u+2]=a[x+2]=W.z,c[v+0]=O,c[v+1]=P,c[_+0]=X,c[_+1]=J,c[p+0]=zt,c[p+1]=ze}return{indices:{size:1,value:new Uint16Array(n)},attributes:{POSITION:{size:3,value:new Float32Array(r)},NORMAL:{size:3,value:new Float32Array(a)},TEXCOORD_0:{size:2,value:new Float32Array(c)}}}}function Vs(s){let{indices:t,attributes:e}=s;if(!t)return s;let i=t.value.length,r={};for(let n in e){let o=e[n],{constant:a,value:c,size:h}=o;if(a||!h)continue;let l=new c.constructor(i*h);for(let d=0;d<i;++d){let f=t.value[d];for(let m=0;m<h;m++)l[d*h+m]=c[f*h+m]}r[n]={size:h,value:l}}return{attributes:Object.assign({},e,r)}}var he=class extends ${constructor(t={}){let{id:e=C("plane-geometry")}=t,{indices:i,attributes:r}=cr(t);super({...t,id:e,topology:"triangle-list",indices:i,attributes:{...r,...t.attributes}})}};function cr(s){let{type:t="x,y",offset:e=0,flipCull:i=!1,unpack:r=!1}=s,n=t.split(","),o=s[`${n[0]}len`]||1,a=s[`${n[1]}len`]||1,c=s[`n${n[0]}`]||1,h=s[`n${n[1]}`]||1,l=(c+1)*(h+1),d=new Float32Array(l*3),f=new Float32Array(l*3),m=new Float32Array(l*2);i&&(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,M=p/h;switch(m[b+0]=i?1-y:y,m[b+1]=M,t){case"x,y":d[u+0]=o*y-o*.5,d[u+1]=a*M-a*.5,d[u+2]=e,f[u+0]=0,f[u+1]=0,f[u+2]=i?1:-1;break;case"x,z":d[u+0]=o*y-o*.5,d[u+1]=e,d[u+2]=a*M-a*.5,f[u+0]=0,f[u+1]=i?1:-1,f[u+2]=0;break;case"y,z":d[u+0]=e,d[u+1]=o*y-o*.5,d[u+2]=a*M-a*.5,f[u+0]=i?1:-1,f[u+1]=0,f[u+2]=0;break;default:throw new Error("PlaneGeometry: unknown type")}b+=2,u+=3}let x=c+1,v=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;v[y+0]=(p+0)*x+g,v[y+1]=(p+1)*x+g,v[y+2]=(p+0)*x+g+1,v[y+3]=(p+1)*x+g,v[y+4]=(p+1)*x+g+1,v[y+5]=(p+0)*x+g+1}let _={indices:{size:1,value:v},attributes:{POSITION:{size:3,value:d},NORMAL:{size:3,value:f},TEXCOORD_0:{size:2,value:m}}};return r?Vs(_):_}var le=class extends ${constructor(t={}){let{id:e=C("sphere-geometry")}=t,{indices:i,attributes:r}=hr(t);super({...t,id:e,topology:"triangle-list",indices:i,attributes:{...r,...t.attributes}})}};function hr(s){let{nlat:t=10,nlong:e=10}=s,n=Math.PI-0,o=0,c=2*Math.PI-o,h=(t+1)*(e+1),l=(v,_,p,g,y)=>s.radius||1,d=new Float32Array(h*3),f=new Float32Array(h*3),m=new Float32Array(h*2),b=h>65535?Uint32Array:Uint16Array,u=new b(t*e*6);for(let v=0;v<=t;v++)for(let _=0;_<=e;_++){let p=_/e,g=v/t,y=_+v*(e+1),M=y*2,I=y*3,R=c*p,P=n*g,O=Math.sin(R),w=Math.cos(R),S=Math.sin(P),E=Math.cos(P),A=w*S,D=E,J=O*S,X=l(A,D,J,p,g);d[I+0]=X*A,d[I+1]=X*D,d[I+2]=X*J,f[I+0]=A,f[I+1]=D,f[I+2]=J,m[M+0]=p,m[M+1]=1-g}let x=e+1;for(let v=0;v<e;v++)for(let _=0;_<t;_++){let p=(v*t+_)*6;u[p+0]=_*x+v,u[p+1]=_*x+v+1,u[p+2]=(_+1)*x+v,u[p+3]=(_+1)*x+v,u[p+4]=_*x+v+1,u[p+5]=(_+1)*x+v+1}return{indices:{size:1,value:u},attributes:{POSITION:{size:3,value:d},NORMAL:{size:3,value:f},TEXCOORD_0:{size:2,value:m}}}}function Gs(){let s=1,t=1;return()=>(s=Math.sin(t*17.23),t=Math.cos(s*27.92),lr(Math.abs(s*t)*1432.71))}function lr(s){return s-Math.floor(s)}var Oe="";function qs(s){Oe=s}async function Ws(s,t){let e=new Image;return e.crossOrigin=t?.crossOrigin||"anonymous",e.src=s.startsWith("http")?s:Oe+s,await e.decode(),t?await createImageBitmap(e,t):await createImageBitmap(e)}async function Ys(s,t){return await new Promise((e,i)=>{try{let r=new Image;r.onload=()=>e(r),r.onerror=()=>i(new Error(`Could not load image ${s}.`)),r.crossOrigin=t?.crossOrigin||"anonymous",r.src=s.startsWith("http")?s:Oe+s}catch(r){i(r)}})}var Hs=L(ht(),1);var nt=L(B(),1),Mt=class{id;current;next;constructor(t){this.id=t.id||"swap",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}},_t=class extends Mt{constructor(t,e){e={...e};let{width:i=1,height:r=1}=e,n=e.colorAttachments?.map(c=>typeof c!="string"?c:t.createTexture({id:`${e.id}-texture-0`,format:c,usage:nt.Texture.SAMPLE|nt.Texture.RENDER|nt.Texture.COPY_SRC|nt.Texture.COPY_DST,width:i,height:r})),o=t.createFramebuffer({...e,colorAttachments:n});n=e.colorAttachments?.map(c=>typeof c!="string"?c:t.createTexture({id:`${e.id}-texture-1`,format:c,usage:nt.Texture.SAMPLE|nt.Texture.RENDER|nt.Texture.COPY_SRC|nt.Texture.COPY_DST,width:i,height:r}));let a=t.createFramebuffer({...e,colorAttachments:n});super({current:o,next:a})}resize(t){if(t.width===this.current.width&&t.height===this.current.height)return!1;let{current:e,next:i}=this;return this.current=e.clone(t),e.destroy(),this.next=i.clone(t),i.destroy(),!0}},de=class extends Mt{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:i}=this;return this.current=e.clone(t),e.destroy(),this.next=i.clone(t),i.destroy(),!0}};function Xs(s){let{shaderPass:t,action:e,shadingLanguage:i}=s;switch(e){case"filter":let r=`${t.name}_filterColor_ext`;return i==="wgsl"?dr(r):ur(r);case"sample":let n=`${t.name}_sampleColor`;return i==="wgsl"?fr(n):pr(n);default:throw new Error(`${t.name} no fragment shader generated for shader pass`)}}function dr(s){return`// Binding 0:1 is reserved for shader passes
85
- // @group(0) @binding(0) var<uniform> brightnessContrast : brightnessContrastUniforms;
86
- @group(0) @binding(1) var texture: texture_2d<f32>;
87
- @group(0) @binding(2) var textureSampler: sampler;
88
-
89
- // This needs to be aligned with
90
- // struct FragmentInputs {
91
- // @location(0) fragUV: vec2f,
92
- // @location(1) fragPosition: vec4f,
93
- // @location(2) fragCoordinate: vec4f
94
- // };
84
+ `,xe=class extends ne{backgroundTexture=null;constructor(e,t){if(super(e,{...t,id:t.id||"background-texture-model",source:$i,fs:Bi,modules:[...t.modules||[],zi],parameters:{depthWriteEnabled:!1,...t.parameters||{},...t.blend?{blend:!0,blendColorOperation:"add",blendAlphaOperation:"add",blendColorSrcFactor:"one-minus-dst-alpha",blendColorDstFactor:"one",blendAlphaSrcFactor:"one-minus-dst-alpha",blendAlphaDstFactor:"one"}:{}}}),!t.backgroundTexture)throw new Error("BackgroundTextureModel requires a backgroundTexture prop");this.setProps(t)}setProps(e){let{backgroundTexture:t}=e;if(t)if(this.setBindings({backgroundTexture:t}),t.isReady){let i=t instanceof H?t.texture:t;this.backgroundTexture=i,this.updateScale(i)}else t.ready.then(i=>{this.backgroundTexture=i,this.updateScale(i)})}predraw(){super.predraw()}updateScale(e){if(!e){this.shaderInputs.setProps({background:{scale:[1,1]}});return}let[t,i]=this.device.getCanvasContext().getDrawingBufferSize(),r=e.width,n=e.height,o=t/i,a=r/n,c=1,l=1;o>a?l=o/a:c=a/o,this.shaderInputs.setProps({background:{scale:[c,l]}})}};var ro=1/Math.PI*180,no=1/180*Math.PI,Ui={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Ui}};var z=globalThis.mathgl.config;function ys(s,{precision:e=z.precision}={}){return s=Gi(s),`${parseFloat(s.toPrecision(e))}`}function ye(s){return Array.isArray(s)||ArrayBuffer.isView(s)&&!(s instanceof DataView)}function Et(s,e,t){let i=z.EPSILON;t&&(z.EPSILON=t);try{if(s===e)return!0;if(ye(s)&&ye(e)){if(s.length!==e.length)return!1;for(let r=0;r<s.length;++r)if(!Et(s[r],e[r]))return!1;return!0}return s&&s.equals?s.equals(e):e&&e.equals?e.equals(s):typeof s=="number"&&typeof e=="number"?Math.abs(s-e)<=z.EPSILON*Math.max(1,Math.abs(s),Math.abs(e)):!1}finally{z.EPSILON=i}}function Gi(s){return Math.round(s/z.EPSILON)*z.EPSILON}var be=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(e,t=0){for(let i=0;i<this.ELEMENTS;++i)this[i]=e[i+t];return this.check()}toArray(e=[],t=0){for(let i=0;i<this.ELEMENTS;++i)e[t+i]=this[i];return e}toObject(e){return e}from(e){return Array.isArray(e)?this.copy(e):this.fromObject(e)}to(e){return e===this?this:ye(e)?this.toArray(e):this.toObject(e)}toTarget(e){return e?this.to(e):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(z)}formatString(e){let t="";for(let i=0;i<this.ELEMENTS;++i)t+=(i>0?", ":"")+ys(this[i],e);return`${e.printTypes?this.constructor.name:""}[${t}]`}equals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(!Et(this[t],e[t]))return!1;return!0}exactEquals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(this[t]!==e[t])return!1;return!0}negate(){for(let e=0;e<this.ELEMENTS;++e)this[e]=-this[e];return this.check()}lerp(e,t,i){if(i===void 0)return this.lerp(this,e,t);for(let r=0;r<this.ELEMENTS;++r){let n=e[r],o=typeof t=="number"?t:t[r];this[r]=n+i*(o-n)}return this.check()}min(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.min(e[t],this[t]);return this.check()}max(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.max(e[t],this[t]);return this.check()}clamp(e,t){for(let i=0;i<this.ELEMENTS;++i)this[i]=Math.min(Math.max(this[i],e[i]),t[i]);return this.check()}add(...e){for(let t of e)for(let i=0;i<this.ELEMENTS;++i)this[i]+=t[i];return this.check()}subtract(...e){for(let t of e)for(let i=0;i<this.ELEMENTS;++i)this[i]-=t[i];return this.check()}scale(e){if(typeof e=="number")for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;else for(let t=0;t<this.ELEMENTS&&t<e.length;++t)this[t]*=e[t];return this.check()}multiplyByScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;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 e=this.length===this.ELEMENTS;for(let t=0;t<this.ELEMENTS;++t)e=e&&Number.isFinite(this[t]);return e}sub(e){return this.subtract(e)}setScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=e;return this.check()}addScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]+=e;return this.check()}subScalar(e){return this.addScalar(-e)}multiplyScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;return this.check()}divideScalar(e){return this.multiplyByScalar(1/e)}clampScalar(e,t){for(let i=0;i<this.ELEMENTS;++i)this[i]=Math.min(Math.max(this[i],e),t);return this.check()}get elements(){return this}};function ji(s,e){if(s.length!==e)return!1;for(let t=0;t<s.length;++t)if(!Number.isFinite(s[t]))return!1;return!0}function j(s){if(!Number.isFinite(s))throw new Error(`Invalid number ${JSON.stringify(s)}`);return s}function Ke(s,e,t=""){if(z.debug&&!ji(s,e))throw new Error(`math.gl: ${t} some fields set to invalid numbers'`);return s}function Rt(s,e){if(!s)throw new Error(`math.gl assertion ${e}`)}var Ze=class extends be{get x(){return this[0]}set x(e){this[0]=j(e)}get y(){return this[1]}set y(e){this[1]=j(e)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let e=0;for(let t=0;t<this.ELEMENTS;++t)e+=this[t]*this[t];return e}magnitudeSquared(){return this.lengthSquared()}distance(e){return Math.sqrt(this.distanceSquared(e))}distanceSquared(e){let t=0;for(let i=0;i<this.ELEMENTS;++i){let r=this[i]-e[i];t+=r*r}return j(t)}dot(e){let t=0;for(let i=0;i<this.ELEMENTS;++i)t+=this[i]*e[i];return j(t)}normalize(){let e=this.magnitude();if(e!==0)for(let t=0;t<this.ELEMENTS;++t)this[t]/=e;return this.check()}multiply(...e){for(let t of e)for(let i=0;i<this.ELEMENTS;++i)this[i]*=t[i];return this.check()}divide(...e){for(let t of e)for(let i=0;i<this.ELEMENTS;++i)this[i]/=t[i];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(e){return this.distance(e)}distanceToSquared(e){return this.distanceSquared(e)}getComponent(e){return Rt(e>=0&&e<this.ELEMENTS,"index is out of range"),j(this[e])}setComponent(e,t){return Rt(e>=0&&e<this.ELEMENTS,"index is out of range"),this[e]=t,this.check()}addVectors(e,t){return this.copy(e).add(t)}subVectors(e,t){return this.copy(e).subtract(t)}multiplyVectors(e,t){return this.copy(e).multiply(t)}addScaledVector(e,t){return this.add(new this.constructor(e).multiplyScalar(t))}};var se=typeof Float32Array<"u"?Float32Array:Array;var xo=Math.PI/180;function Vi(){let s=new se(2);return se!=Float32Array&&(s[0]=0,s[1]=0),s}function Ms(s,e,t){let i=e[0],r=e[1];return s[0]=t[0]*i+t[4]*r+t[12],s[1]=t[1]*i+t[5]*r+t[13],s}var yo=function(){let s=Vi();return function(e,t,i,r,n,o){let a,c;for(t||(t=2),i||(i=0),r?c=Math.min(r*t+i,e.length):c=e.length,a=i;a<c;a+=t)s[0]=e[a],s[1]=e[a+1],n(s,s,o),e[a]=s[0],e[a+1]=s[1];return e}}();function _s(s,e,t){let i=e[0],r=e[1],n=t[3]*i+t[7]*r||1;return s[0]=(t[0]*i+t[4]*r)/n,s[1]=(t[1]*i+t[5]*r)/n,s}function Qe(s,e,t){let i=e[0],r=e[1],n=e[2],o=t[3]*i+t[7]*r+t[11]*n||1;return s[0]=(t[0]*i+t[4]*r+t[8]*n)/o,s[1]=(t[1]*i+t[5]*r+t[9]*n)/o,s[2]=(t[2]*i+t[6]*r+t[10]*n)/o,s}function ws(s,e,t){let i=e[0],r=e[1];return s[0]=t[0]*i+t[2]*r,s[1]=t[1]*i+t[3]*r,s[2]=e[2],s}function qi(){let s=new se(3);return se!=Float32Array&&(s[0]=0,s[1]=0,s[2]=0),s}function Wi(s,e){return s[0]*e[0]+s[1]*e[1]+s[2]*e[2]}function Ts(s,e,t){let i=e[0],r=e[1],n=e[2],o=t[0],a=t[1],c=t[2];return s[0]=r*c-n*a,s[1]=n*o-i*c,s[2]=i*a-r*o,s}function Je(s,e,t){let i=e[0],r=e[1],n=e[2],o=t[3]*i+t[7]*r+t[11]*n+t[15];return o=o||1,s[0]=(t[0]*i+t[4]*r+t[8]*n+t[12])/o,s[1]=(t[1]*i+t[5]*r+t[9]*n+t[13])/o,s[2]=(t[2]*i+t[6]*r+t[10]*n+t[14])/o,s}function As(s,e,t){let i=e[0],r=e[1],n=e[2];return s[0]=i*t[0]+r*t[3]+n*t[6],s[1]=i*t[1]+r*t[4]+n*t[7],s[2]=i*t[2]+r*t[5]+n*t[8],s}function Ss(s,e,t){let i=t[0],r=t[1],n=t[2],o=t[3],a=e[0],c=e[1],l=e[2],h=r*l-n*c,d=n*a-i*l,u=i*c-r*a,g=r*u-n*d,m=n*h-i*u,f=i*d-r*h,y=o*2;return h*=y,d*=y,u*=y,g*=2,m*=2,f*=2,s[0]=a+h+g,s[1]=c+d+m,s[2]=l+u+f,s}function Ps(s,e,t,i){let r=[],n=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],n[0]=r[0],n[1]=r[1]*Math.cos(i)-r[2]*Math.sin(i),n[2]=r[1]*Math.sin(i)+r[2]*Math.cos(i),s[0]=n[0]+t[0],s[1]=n[1]+t[1],s[2]=n[2]+t[2],s}function Cs(s,e,t,i){let r=[],n=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],n[0]=r[2]*Math.sin(i)+r[0]*Math.cos(i),n[1]=r[1],n[2]=r[2]*Math.cos(i)-r[0]*Math.sin(i),s[0]=n[0]+t[0],s[1]=n[1]+t[1],s[2]=n[2]+t[2],s}function Is(s,e,t,i){let r=[],n=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],n[0]=r[0]*Math.cos(i)-r[1]*Math.sin(i),n[1]=r[0]*Math.sin(i)+r[1]*Math.cos(i),n[2]=r[2],s[0]=n[0]+t[0],s[1]=n[1]+t[1],s[2]=n[2]+t[2],s}function Es(s,e){let t=s[0],i=s[1],r=s[2],n=e[0],o=e[1],a=e[2],c=Math.sqrt((t*t+i*i+r*r)*(n*n+o*o+a*a)),l=c&&Wi(s,e)/c;return Math.acos(Math.min(Math.max(l,-1),1))}var Mo=function(){let s=qi();return function(e,t,i,r,n,o){let a,c;for(t||(t=3),i||(i=0),r?c=Math.min(r*t+i,e.length):c=e.length,a=i;a<c;a+=t)s[0]=e[a],s[1]=e[a+1],s[2]=e[a+2],n(s,s,o),e[a]=s[0],e[a+1]=s[1],e[a+2]=s[2];return e}}();var Lt=[0,0,0],et,q=class extends Ze{static get ZERO(){return et||(et=new q(0,0,0),Object.freeze(et)),et}constructor(e=0,t=0,i=0){super(-0,-0,-0),arguments.length===1&&ye(e)?this.copy(e):(z.debug&&(j(e),j(t),j(i)),this[0]=e,this[1]=t,this[2]=i)}set(e,t,i){return this[0]=e,this[1]=t,this[2]=i,this.check()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this.check()}fromObject(e){return z.debug&&(j(e.x),j(e.y),j(e.z)),this[0]=e.x,this[1]=e.y,this[2]=e.z,this.check()}toObject(e){return e.x=this[0],e.y=this[1],e.z=this[2],e}get ELEMENTS(){return 3}get z(){return this[2]}set z(e){this[2]=j(e)}angle(e){return Es(this,e)}cross(e){return Ts(this,this,e),this.check()}rotateX({radians:e,origin:t=Lt}){return Ps(this,this,t,e),this.check()}rotateY({radians:e,origin:t=Lt}){return Cs(this,this,t,e),this.check()}rotateZ({radians:e,origin:t=Lt}){return Is(this,this,t,e),this.check()}transform(e){return this.transformAsPoint(e)}transformAsPoint(e){return Je(this,this,e),this.check()}transformAsVector(e){return Qe(this,this,e),this.check()}transformByMatrix3(e){return As(this,this,e),this.check()}transformByMatrix2(e){return ws(this,this,e),this.check()}transformByQuaternion(e){return Ss(this,this,e),this.check()}};var tt=class extends be{toString(){let e="[";if(z.printRowMajor){e+="row-major:";for(let t=0;t<this.RANK;++t)for(let i=0;i<this.RANK;++i)e+=` ${this[i*this.RANK+t]}`}else{e+="column-major:";for(let t=0;t<this.ELEMENTS;++t)e+=` ${this[t]}`}return e+="]",e}getElementIndex(e,t){return t*this.RANK+e}getElement(e,t){return this[t*this.RANK+e]}setElement(e,t,i){return this[t*this.RANK+e]=j(i),this}getColumn(e,t=new Array(this.RANK).fill(-0)){let i=e*this.RANK;for(let r=0;r<this.RANK;++r)t[r]=this[i+r];return t}setColumn(e,t){let i=e*this.RANK;for(let r=0;r<this.RANK;++r)this[i+r]=t[r];return this}};function Hi(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 Rs(s,e){if(s===e){let t=e[1],i=e[2],r=e[3],n=e[6],o=e[7],a=e[11];s[1]=e[4],s[2]=e[8],s[3]=e[12],s[4]=t,s[6]=e[9],s[7]=e[13],s[8]=i,s[9]=n,s[11]=e[14],s[12]=r,s[13]=o,s[14]=a}else s[0]=e[0],s[1]=e[4],s[2]=e[8],s[3]=e[12],s[4]=e[1],s[5]=e[5],s[6]=e[9],s[7]=e[13],s[8]=e[2],s[9]=e[6],s[10]=e[10],s[11]=e[14],s[12]=e[3],s[13]=e[7],s[14]=e[11],s[15]=e[15];return s}function Os(s,e){let t=e[0],i=e[1],r=e[2],n=e[3],o=e[4],a=e[5],c=e[6],l=e[7],h=e[8],d=e[9],u=e[10],g=e[11],m=e[12],f=e[13],y=e[14],v=e[15],_=t*a-i*o,p=t*c-r*o,x=t*l-n*o,b=i*c-r*a,M=i*l-n*a,A=r*l-n*c,R=h*f-d*m,I=h*y-u*m,O=h*v-g*m,w=d*y-u*f,S=d*v-g*f,E=u*v-g*y,T=_*E-p*S+x*w+b*O-M*I+A*R;return T?(T=1/T,s[0]=(a*E-c*S+l*w)*T,s[1]=(r*S-i*E-n*w)*T,s[2]=(f*A-y*M+v*b)*T,s[3]=(u*M-d*A-g*b)*T,s[4]=(c*O-o*E-l*I)*T,s[5]=(t*E-r*O+n*I)*T,s[6]=(y*x-m*A-v*p)*T,s[7]=(h*A-u*x+g*p)*T,s[8]=(o*S-a*O+l*R)*T,s[9]=(i*O-t*S-n*R)*T,s[10]=(m*M-f*x+v*_)*T,s[11]=(d*x-h*M-g*_)*T,s[12]=(a*I-o*w-c*R)*T,s[13]=(t*w-i*I+r*R)*T,s[14]=(f*p-m*b-y*_)*T,s[15]=(h*b-d*p+u*_)*T,s):null}function Ls(s){let e=s[0],t=s[1],i=s[2],r=s[3],n=s[4],o=s[5],a=s[6],c=s[7],l=s[8],h=s[9],d=s[10],u=s[11],g=s[12],m=s[13],f=s[14],y=s[15],v=e*o-t*n,_=e*a-i*n,p=t*a-i*o,x=l*m-h*g,b=l*f-d*g,M=h*f-d*m,A=e*M-t*b+i*x,R=n*M-o*b+a*x,I=l*p-h*_+d*v,O=g*p-m*_+f*v;return c*A-r*R+y*I-u*O}function kt(s,e,t){let i=e[0],r=e[1],n=e[2],o=e[3],a=e[4],c=e[5],l=e[6],h=e[7],d=e[8],u=e[9],g=e[10],m=e[11],f=e[12],y=e[13],v=e[14],_=e[15],p=t[0],x=t[1],b=t[2],M=t[3];return s[0]=p*i+x*a+b*d+M*f,s[1]=p*r+x*c+b*u+M*y,s[2]=p*n+x*l+b*g+M*v,s[3]=p*o+x*h+b*m+M*_,p=t[4],x=t[5],b=t[6],M=t[7],s[4]=p*i+x*a+b*d+M*f,s[5]=p*r+x*c+b*u+M*y,s[6]=p*n+x*l+b*g+M*v,s[7]=p*o+x*h+b*m+M*_,p=t[8],x=t[9],b=t[10],M=t[11],s[8]=p*i+x*a+b*d+M*f,s[9]=p*r+x*c+b*u+M*y,s[10]=p*n+x*l+b*g+M*v,s[11]=p*o+x*h+b*m+M*_,p=t[12],x=t[13],b=t[14],M=t[15],s[12]=p*i+x*a+b*d+M*f,s[13]=p*r+x*c+b*u+M*y,s[14]=p*n+x*l+b*g+M*v,s[15]=p*o+x*h+b*m+M*_,s}function ks(s,e,t){let i=t[0],r=t[1],n=t[2],o,a,c,l,h,d,u,g,m,f,y,v;return e===s?(s[12]=e[0]*i+e[4]*r+e[8]*n+e[12],s[13]=e[1]*i+e[5]*r+e[9]*n+e[13],s[14]=e[2]*i+e[6]*r+e[10]*n+e[14],s[15]=e[3]*i+e[7]*r+e[11]*n+e[15]):(o=e[0],a=e[1],c=e[2],l=e[3],h=e[4],d=e[5],u=e[6],g=e[7],m=e[8],f=e[9],y=e[10],v=e[11],s[0]=o,s[1]=a,s[2]=c,s[3]=l,s[4]=h,s[5]=d,s[6]=u,s[7]=g,s[8]=m,s[9]=f,s[10]=y,s[11]=v,s[12]=o*i+h*r+m*n+e[12],s[13]=a*i+d*r+f*n+e[13],s[14]=c*i+u*r+y*n+e[14],s[15]=l*i+g*r+v*n+e[15]),s}function Fs(s,e,t){let i=t[0],r=t[1],n=t[2];return s[0]=e[0]*i,s[1]=e[1]*i,s[2]=e[2]*i,s[3]=e[3]*i,s[4]=e[4]*r,s[5]=e[5]*r,s[6]=e[6]*r,s[7]=e[7]*r,s[8]=e[8]*n,s[9]=e[9]*n,s[10]=e[10]*n,s[11]=e[11]*n,s[12]=e[12],s[13]=e[13],s[14]=e[14],s[15]=e[15],s}function Ns(s,e,t,i){let r=i[0],n=i[1],o=i[2],a=Math.sqrt(r*r+n*n+o*o),c,l,h,d,u,g,m,f,y,v,_,p,x,b,M,A,R,I,O,w,S,E,T,D;return a<1e-6?null:(a=1/a,r*=a,n*=a,o*=a,l=Math.sin(t),c=Math.cos(t),h=1-c,d=e[0],u=e[1],g=e[2],m=e[3],f=e[4],y=e[5],v=e[6],_=e[7],p=e[8],x=e[9],b=e[10],M=e[11],A=r*r*h+c,R=n*r*h+o*l,I=o*r*h-n*l,O=r*n*h-o*l,w=n*n*h+c,S=o*n*h+r*l,E=r*o*h+n*l,T=n*o*h-r*l,D=o*o*h+c,s[0]=d*A+f*R+p*I,s[1]=u*A+y*R+x*I,s[2]=g*A+v*R+b*I,s[3]=m*A+_*R+M*I,s[4]=d*O+f*w+p*S,s[5]=u*O+y*w+x*S,s[6]=g*O+v*w+b*S,s[7]=m*O+_*w+M*S,s[8]=d*E+f*T+p*D,s[9]=u*E+y*T+x*D,s[10]=g*E+v*T+b*D,s[11]=m*E+_*T+M*D,e!==s&&(s[12]=e[12],s[13]=e[13],s[14]=e[14],s[15]=e[15]),s)}function Ds(s,e,t){let i=Math.sin(t),r=Math.cos(t),n=e[4],o=e[5],a=e[6],c=e[7],l=e[8],h=e[9],d=e[10],u=e[11];return e!==s&&(s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=e[3],s[12]=e[12],s[13]=e[13],s[14]=e[14],s[15]=e[15]),s[4]=n*r+l*i,s[5]=o*r+h*i,s[6]=a*r+d*i,s[7]=c*r+u*i,s[8]=l*r-n*i,s[9]=h*r-o*i,s[10]=d*r-a*i,s[11]=u*r-c*i,s}function zs(s,e,t){let i=Math.sin(t),r=Math.cos(t),n=e[0],o=e[1],a=e[2],c=e[3],l=e[8],h=e[9],d=e[10],u=e[11];return e!==s&&(s[4]=e[4],s[5]=e[5],s[6]=e[6],s[7]=e[7],s[12]=e[12],s[13]=e[13],s[14]=e[14],s[15]=e[15]),s[0]=n*r-l*i,s[1]=o*r-h*i,s[2]=a*r-d*i,s[3]=c*r-u*i,s[8]=n*i+l*r,s[9]=o*i+h*r,s[10]=a*i+d*r,s[11]=c*i+u*r,s}function $s(s,e,t){let i=Math.sin(t),r=Math.cos(t),n=e[0],o=e[1],a=e[2],c=e[3],l=e[4],h=e[5],d=e[6],u=e[7];return e!==s&&(s[8]=e[8],s[9]=e[9],s[10]=e[10],s[11]=e[11],s[12]=e[12],s[13]=e[13],s[14]=e[14],s[15]=e[15]),s[0]=n*r+l*i,s[1]=o*r+h*i,s[2]=a*r+d*i,s[3]=c*r+u*i,s[4]=l*r-n*i,s[5]=h*r-o*i,s[6]=d*r-a*i,s[7]=u*r-c*i,s}function Bs(s,e){let t=e[0],i=e[1],r=e[2],n=e[3],o=t+t,a=i+i,c=r+r,l=t*o,h=i*o,d=i*a,u=r*o,g=r*a,m=r*c,f=n*o,y=n*a,v=n*c;return s[0]=1-d-m,s[1]=h+v,s[2]=u-y,s[3]=0,s[4]=h-v,s[5]=1-l-m,s[6]=g+f,s[7]=0,s[8]=u+y,s[9]=g-f,s[10]=1-l-d,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s}function Us(s,e,t,i,r,n,o){let a=1/(t-e),c=1/(r-i),l=1/(n-o);return s[0]=n*2*a,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=n*2*c,s[6]=0,s[7]=0,s[8]=(t+e)*a,s[9]=(r+i)*c,s[10]=(o+n)*l,s[11]=-1,s[12]=0,s[13]=0,s[14]=o*n*2*l,s[15]=0,s}function Yi(s,e,t,i,r){let n=1/Math.tan(e/2);if(s[0]=n/t,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=n,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/(i-r);s[10]=(r+i)*o,s[14]=2*r*i*o}else s[10]=-1,s[14]=-2*i;return s}var Gs=Yi;function Xi(s,e,t,i,r,n,o){let a=1/(e-t),c=1/(i-r),l=1/(n-o);return s[0]=-2*a,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=-2*c,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=2*l,s[11]=0,s[12]=(e+t)*a,s[13]=(r+i)*c,s[14]=(o+n)*l,s[15]=1,s}var js=Xi;function Vs(s,e,t,i){let r,n,o,a,c,l,h,d,u,g,m=e[0],f=e[1],y=e[2],v=i[0],_=i[1],p=i[2],x=t[0],b=t[1],M=t[2];return Math.abs(m-x)<1e-6&&Math.abs(f-b)<1e-6&&Math.abs(y-M)<1e-6?Hi(s):(d=m-x,u=f-b,g=y-M,r=1/Math.sqrt(d*d+u*u+g*g),d*=r,u*=r,g*=r,n=_*g-p*u,o=p*d-v*g,a=v*u-_*d,r=Math.sqrt(n*n+o*o+a*a),r?(r=1/r,n*=r,o*=r,a*=r):(n=0,o=0,a=0),c=u*a-g*o,l=g*n-d*a,h=d*o-u*n,r=Math.sqrt(c*c+l*l+h*h),r?(r=1/r,c*=r,l*=r,h*=r):(c=0,l=0,h=0),s[0]=n,s[1]=c,s[2]=d,s[3]=0,s[4]=o,s[5]=l,s[6]=u,s[7]=0,s[8]=a,s[9]=h,s[10]=g,s[11]=0,s[12]=-(n*m+o*f+a*y),s[13]=-(c*m+l*f+h*y),s[14]=-(d*m+u*f+g*y),s[15]=1,s)}function Ki(){let s=new se(4);return se!=Float32Array&&(s[0]=0,s[1]=0,s[2]=0,s[3]=0),s}function qs(s,e,t){let i=e[0],r=e[1],n=e[2],o=e[3];return s[0]=t[0]*i+t[4]*r+t[8]*n+t[12]*o,s[1]=t[1]*i+t[5]*r+t[9]*n+t[13]*o,s[2]=t[2]*i+t[6]*r+t[10]*n+t[14]*o,s[3]=t[3]*i+t[7]*r+t[11]*n+t[15]*o,s}var ko=function(){let s=Ki();return function(e,t,i,r,n,o){let a,c;for(t||(t=4),i||(i=0),r?c=Math.min(r*t+i,e.length):c=e.length,a=i;a<c;a+=t)s[0]=e[a],s[1]=e[a+1],s[2]=e[a+2],s[3]=e[a+3],n(s,s,o),e[a]=s[0],e[a+1]=s[1],e[a+2]=s[2],e[a+3]=s[3];return e}}();var Dt;(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"})(Dt||(Dt={}));var Zi=45*Math.PI/180,Qi=1,Ft=.1,Nt=500,Ji=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),W=class extends tt{static get IDENTITY(){return tr()}static get ZERO(){return er()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Dt}constructor(e){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(e)?this.copy(e):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this[9]=e[9],this[10]=e[10],this[11]=e[11],this[12]=e[12],this[13]=e[13],this[14]=e[14],this[15]=e[15],this.check()}set(e,t,i,r,n,o,a,c,l,h,d,u,g,m,f,y){return this[0]=e,this[1]=t,this[2]=i,this[3]=r,this[4]=n,this[5]=o,this[6]=a,this[7]=c,this[8]=l,this[9]=h,this[10]=d,this[11]=u,this[12]=g,this[13]=m,this[14]=f,this[15]=y,this.check()}setRowMajor(e,t,i,r,n,o,a,c,l,h,d,u,g,m,f,y){return this[0]=e,this[1]=n,this[2]=l,this[3]=g,this[4]=t,this[5]=o,this[6]=h,this[7]=m,this[8]=i,this[9]=a,this[10]=d,this[11]=f,this[12]=r,this[13]=c,this[14]=u,this[15]=y,this.check()}toRowMajor(e){return e[0]=this[0],e[1]=this[4],e[2]=this[8],e[3]=this[12],e[4]=this[1],e[5]=this[5],e[6]=this[9],e[7]=this[13],e[8]=this[2],e[9]=this[6],e[10]=this[10],e[11]=this[14],e[12]=this[3],e[13]=this[7],e[14]=this[11],e[15]=this[15],e}identity(){return this.copy(Ji)}fromObject(e){return this.check()}fromQuaternion(e){return Bs(this,e),this.check()}frustum(e){let{left:t,right:i,bottom:r,top:n,near:o=Ft,far:a=Nt}=e;return a===1/0?sr(this,t,i,r,n,o):Us(this,t,i,r,n,o,a),this.check()}lookAt(e){let{eye:t,center:i=[0,0,0],up:r=[0,1,0]}=e;return Vs(this,t,i,r),this.check()}ortho(e){let{left:t,right:i,bottom:r,top:n,near:o=Ft,far:a=Nt}=e;return js(this,t,i,r,n,o,a),this.check()}orthographic(e){let{fovy:t=Zi,aspect:i=Qi,focalDistance:r=1,near:n=Ft,far:o=Nt}=e;Ws(t);let a=t/2,c=r*Math.tan(a),l=c*i;return this.ortho({left:-l,right:l,bottom:-c,top:c,near:n,far:o})}perspective(e){let{fovy:t=45*Math.PI/180,aspect:i=1,near:r=.1,far:n=500}=e;return Ws(t),Gs(this,t,i,r,n),this.check()}determinant(){return Ls(this)}getScale(e=[-0,-0,-0]){return e[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),e[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),e[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),e}getTranslation(e=[-0,-0,-0]){return e[0]=this[12],e[1]=this[13],e[2]=this[14],e}getRotation(e,t){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],t=t||[-0,-0,-0];let i=this.getScale(t),r=1/i[0],n=1/i[1],o=1/i[2];return e[0]=this[0]*r,e[1]=this[1]*n,e[2]=this[2]*o,e[3]=0,e[4]=this[4]*r,e[5]=this[5]*n,e[6]=this[6]*o,e[7]=0,e[8]=this[8]*r,e[9]=this[9]*n,e[10]=this[10]*o,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}getRotationMatrix3(e,t){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0],t=t||[-0,-0,-0];let i=this.getScale(t),r=1/i[0],n=1/i[1],o=1/i[2];return e[0]=this[0]*r,e[1]=this[1]*n,e[2]=this[2]*o,e[3]=this[4]*r,e[4]=this[5]*n,e[5]=this[6]*o,e[6]=this[8]*r,e[7]=this[9]*n,e[8]=this[10]*o,e}transpose(){return Rs(this,this),this.check()}invert(){return Os(this,this),this.check()}multiplyLeft(e){return kt(this,e,this),this.check()}multiplyRight(e){return kt(this,this,e),this.check()}rotateX(e){return Ds(this,this,e),this.check()}rotateY(e){return zs(this,this,e),this.check()}rotateZ(e){return $s(this,this,e),this.check()}rotateXYZ(e){return this.rotateX(e[0]).rotateY(e[1]).rotateZ(e[2])}rotateAxis(e,t){return Ns(this,this,e,t),this.check()}scale(e){return Fs(this,this,Array.isArray(e)?e:[e,e,e]),this.check()}translate(e){return ks(this,this,e),this.check()}transform(e,t){return e.length===4?(t=qs(t||[-0,-0,-0,-0],e,this),Ke(t,4),t):this.transformAsPoint(e,t)}transformAsPoint(e,t){let{length:i}=e,r;switch(i){case 2:r=Ms(t||[-0,-0],e,this);break;case 3:r=Je(t||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Ke(r,e.length),r}transformAsVector(e,t){let i;switch(e.length){case 2:i=_s(t||[-0,-0],e,this);break;case 3:i=Qe(t||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Ke(i,e.length),i}transformPoint(e,t){return this.transformAsPoint(e,t)}transformVector(e,t){return this.transformAsPoint(e,t)}transformDirection(e,t){return this.transformAsVector(e,t)}makeRotationX(e){return this.identity().rotateX(e)}makeTranslation(e,t,i){return this.identity().translate([e,t,i])}},st,it;function er(){return st||(st=new W([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(st)),st}function tr(){return it||(it=new W,Object.freeze(it)),it}function Ws(s){if(s>Math.PI*2)throw Error("expected radians")}function sr(s,e,t,i,r,n){let o=2*n/(t-e),a=2*n/(r-i),c=(t+e)/(t-e),l=(r+i)/(r-i),h=-1,d=-1,u=-2*n;return s[0]=o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a,s[6]=0,s[7]=0,s[8]=c,s[9]=l,s[10]=h,s[11]=d,s[12]=0,s[13]=0,s[14]=u,s[15]=0,s}function zt(s,e){if(!s)throw new Error(e)}var ie=class{id;matrix=new W;display=!0;position=new q;rotation=new q;scale=new q(1,1,1);userData={};props={};constructor(e={}){let{id:t}=e;this.id=t||C(this.constructor.name),this._setScenegraphNodeProps(e)}getBounds(){return null}destroy(){}delete(){this.destroy()}setProps(e){return this._setScenegraphNodeProps(e),this}toString(){return`{type: ScenegraphNode, id: ${this.id})}`}setPosition(e){return zt(e.length===3,"setPosition requires vector argument"),this.position=e,this}setRotation(e){return zt(e.length===3||e.length===4,"setRotation requires vector argument"),this.rotation=e,this}setScale(e){return zt(e.length===3,"setScale requires vector argument"),this.scale=e,this}setMatrix(e,t=!0){t?this.matrix.copy(e):this.matrix=e}setMatrixComponents(e){let{position:t,rotation:i,scale:r,update:n=!0}=e;return t&&this.setPosition(t),i&&this.setRotation(i),r&&this.setScale(r),n&&this.updateMatrix(),this}updateMatrix(){if(this.matrix.identity(),this.matrix.translate(this.position),this.rotation.length===4){let e=new W().fromQuaternion(this.rotation);this.matrix.multiplyRight(e)}else this.matrix.rotateXYZ(this.rotation);return this.matrix.scale(this.scale),this}update({position:e,rotation:t,scale:i}={}){return e&&this.setPosition(e),t&&this.setRotation(t),i&&this.setScale(i),this.updateMatrix(),this}getCoordinateUniforms(e,t){t=t||this.matrix;let i=new W(e).multiplyRight(t),r=i.invert(),n=r.transpose();return{viewMatrix:e,modelMatrix:t,objectMatrix:t,worldMatrix:i,worldInverseMatrix:r,worldInverseTransposeMatrix:n}}_setScenegraphNodeProps(e){e?.position&&this.setPosition(e.position),e?.rotation&&this.setRotation(e.rotation),e?.scale&&this.setScale(e.scale),this.updateMatrix(),e?.matrix&&this.setMatrix(e.matrix),Object.assign(this.props,e)}};var Hs=k(B(),1);var fe=class extends ie{children;constructor(e={}){e=Array.isArray(e)?{children:e}:e;let{children:t=[]}=e;Hs.log.assert(t.every(i=>i instanceof ie),"every child must an instance of ScenegraphNode"),super(e),this.children=t}getBounds(){let e=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]];return this.traverse((t,{worldMatrix:i})=>{let r=t.getBounds();if(!r)return;let[n,o]=r,a=new q(n).add(o).divide([2,2,2]);i.transformAsPoint(a,a);let c=new q(o).subtract(n).divide([2,2,2]);i.transformAsVector(c,c);for(let l=0;l<8;l++){let h=new q(l&1?-1:1,l&2?-1:1,l&4?-1:1).multiply(c).add(a);for(let d=0;d<3;d++)e[0][d]=Math.min(e[0][d],h[d]),e[1][d]=Math.max(e[1][d],h[d])}}),Number.isFinite(e[0][0])?e:null}destroy(){this.children.forEach(e=>e.destroy()),this.removeAll(),super.destroy()}add(...e){for(let t of e)Array.isArray(t)?this.add(...t):this.children.push(t);return this}remove(e){let t=this.children,i=t.indexOf(e);return i>-1&&t.splice(i,1),this}removeAll(){return this.children=[],this}traverse(e,{worldMatrix:t=new W}={}){let i=new W(t).multiplyRight(this.matrix);for(let r of this.children)r instanceof fe?r.traverse(e,{worldMatrix:i}):e(r,{worldMatrix:i})}preorderTraversal(e,{worldMatrix:t=new W}={}){let i=new W(t).multiplyRight(this.matrix);e(this,{worldMatrix:i});for(let r of this.children)r instanceof fe?r.preorderTraversal(e,{worldMatrix:i}):e(r,{worldMatrix:i})}};var rt=class extends ie{model;bounds=null;managedResources;constructor(e){super(e),this.model=e.model,this.managedResources=e.managedResources||[],this.bounds=e.bounds||null,this.setProps(e)}destroy(){this.model&&(this.model.destroy(),this.model=null),this.managedResources.forEach(e=>e.destroy()),this.managedResources=[]}getBounds(){return this.bounds}draw(e){return this.model.draw(e)}};var ir={x:[2,0,1],y:[0,1,2],z:[1,2,0]},oe=class extends G{constructor(e={}){let{id:t=C("truncated-code-geometry")}=e,{indices:i,attributes:r}=rr(e);super({...e,id:t,topology:"triangle-list",indices:i,attributes:{POSITION:{size:3,value:r.POSITION},NORMAL:{size:3,value:r.NORMAL},TEXCOORD_0:{size:2,value:r.TEXCOORD_0},...e.attributes}})}};function rr(s={}){let{bottomRadius:e=0,topRadius:t=0,height:i=1,nradial:r=10,nvertical:n=10,verticalAxis:o="y",topCap:a=!1,bottomCap:c=!1}=s,l=(a?2:0)+(c?2:0),h=(r+1)*(n+1+l),d=Math.atan2(e-t,i),u=Math.sin,g=Math.cos,m=Math.PI,f=g(d),y=u(d),v=a?-2:0,_=n+(c?2:0),p=r+1,x=new Uint16Array(r*(n+l)*6),b=ir[o],M=new Float32Array(h*3),A=new Float32Array(h*3),R=new Float32Array(h*2),I=0,O=0;for(let w=v;w<=_;w++){let S=w/n,E=i*S,T;w<0?(E=0,S=1,T=e):w>n?(E=i,S=1,T=t):T=e+(t-e)*(w/n),(w===-2||w===n+2)&&(T=0,S=0),E-=i/2;for(let D=0;D<p;D++){let J=u(D*m*2/r),K=g(D*m*2/r);M[I+b[0]]=J*T,M[I+b[1]]=E,M[I+b[2]]=K*T,A[I+b[0]]=w<0||w>n?0:J*f,A[I+b[1]]=w<0?-1:w>n?1:y,A[I+b[2]]=w<0||w>n?0:K*f,R[O+0]=D/r,R[O+1]=S,O+=2,I+=3}}for(let w=0;w<n+l;w++)for(let S=0;S<r;S++){let E=(w*r+S)*6;x[E+0]=p*(w+0)+0+S,x[E+1]=p*(w+0)+1+S,x[E+2]=p*(w+1)+1+S,x[E+3]=p*(w+0)+0+S,x[E+4]=p*(w+1)+1+S,x[E+5]=p*(w+1)+0+S}return{indices:x,attributes:{POSITION:M,NORMAL:A,TEXCOORD_0:R}}}var nt=class extends oe{constructor(e={}){let{id:t=C("cone-geometry"),radius:i=1,cap:r=!0}=e;super({...e,id:t,topRadius:0,topCap:Boolean(r),bottomCap:Boolean(r),bottomRadius:i})}};var ot=class extends G{constructor(e={}){let{id:t=C("cube-geometry"),indices:i=!0}=e;super(i?{...e,id:t,topology:"triangle-list",indices:{size:1,value:nr},attributes:{...ur,...e.attributes}}:{...e,id:t,topology:"triangle-list",indices:void 0,attributes:{...fr,...e.attributes}})}},nr=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]),or=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]),ar=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]),cr=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]),hr=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]),lr=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]),dr=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]),ur={POSITION:{size:3,value:or},NORMAL:{size:3,value:ar},TEXCOORD_0:{size:2,value:cr}},fr={POSITION:{size:3,value:hr},TEXCOORD_0:{size:2,value:lr},COLOR_0:{size:3,value:dr}};var at=class extends oe{constructor(e={}){let{id:t=C("cylinder-geometry"),radius:i=1}=e;super({...e,id:t,bottomRadius:i,topRadius:i})}};var pr=[-1,0,0,0,1,0,0,0,-1,0,0,1,0,-1,0,1,0,0],mr=[3,4,5,3,5,1,3,1,0,3,0,4,4,0,2,4,2,5,2,0,1,5,2,1],ct=class extends G{constructor(e={}){let{id:t=C("ico-sphere-geometry")}=e,{indices:i,attributes:r}=gr(e);super({...e,id:t,topology:"triangle-list",indices:i,attributes:{...r,...e.attributes}})}};function gr(s){let{iterations:e=0}=s,t=Math.PI,i=t*2,r=[...pr],n=[...mr];r.push(),n.push();let o=(()=>{let h={};return(d,u)=>{d*=3,u*=3;let g=d<u?d:u,m=d>u?d:u,f=`${g}|${m}`;if(f in h)return h[f];let y=r[d],v=r[d+1],_=r[d+2],p=r[u],x=r[u+1],b=r[u+2],M=(y+p)/2,A=(v+x)/2,R=(_+b)/2,I=Math.sqrt(M*M+A*A+R*R);return M/=I,A/=I,R/=I,r.push(M,A,R),h[f]=r.length/3-1}})();for(let h=0;h<e;h++){let d=[];for(let u=0;u<n.length;u+=3){let g=o(n[u+0],n[u+1]),m=o(n[u+1],n[u+2]),f=o(n[u+2],n[u+0]);d.push(f,n[u+0],g,g,n[u+1],m,m,n[u+2],f,g,m,f)}n=d}let a=new Array(r.length),c=new Array(r.length/3*2),l=n.length;for(let h=l-3;h>=0;h-=3){let d=n[h+0],u=n[h+1],g=n[h+2],m=d*3,f=u*3,y=g*3,v=d*2,_=u*2,p=g*2,x=r[m+0],b=r[m+1],M=r[m+2],A=Math.acos(M/Math.sqrt(x*x+b*b+M*M)),R=Math.atan2(b,x)+t,I=A/t,O=1-R/i,w=r[f+0],S=r[f+1],E=r[f+2],T=Math.acos(E/Math.sqrt(w*w+S*S+E*E)),D=Math.atan2(S,w)+t,J=T/t,K=1-D/i,Fe=r[y+0],Ne=r[y+1],De=r[y+2],ri=Math.acos(De/Math.sqrt(Fe*Fe+Ne*Ne+De*De)),ni=Math.atan2(Ne,Fe)+t,qt=ri/t,ze=1-ni/i,oi=[Fe-w,Ne-S,De-E],ai=[x-w,b-S,M-E],Y=new q(oi).cross(ai).normalize(),L;(O===0||K===0||ze===0)&&(O===0||O>.5)&&(K===0||K>.5)&&(ze===0||ze>.5)&&(r.push(r[m+0],r[m+1],r[m+2]),L=r.length/3-1,n.push(L),c[L*2+0]=1,c[L*2+1]=I,a[L*3+0]=Y.x,a[L*3+1]=Y.y,a[L*3+2]=Y.z,r.push(r[f+0],r[f+1],r[f+2]),L=r.length/3-1,n.push(L),c[L*2+0]=1,c[L*2+1]=J,a[L*3+0]=Y.x,a[L*3+1]=Y.y,a[L*3+2]=Y.z,r.push(r[y+0],r[y+1],r[y+2]),L=r.length/3-1,n.push(L),c[L*2+0]=1,c[L*2+1]=qt,a[L*3+0]=Y.x,a[L*3+1]=Y.y,a[L*3+2]=Y.z),a[m+0]=a[f+0]=a[y+0]=Y.x,a[m+1]=a[f+1]=a[y+1]=Y.y,a[m+2]=a[f+2]=a[y+2]=Y.z,c[v+0]=O,c[v+1]=I,c[_+0]=K,c[_+1]=J,c[p+0]=ze,c[p+1]=qt}return{indices:{size:1,value:new Uint16Array(n)},attributes:{POSITION:{size:3,value:new Float32Array(r)},NORMAL:{size:3,value:new Float32Array(a)},TEXCOORD_0:{size:2,value:new Float32Array(c)}}}}function Ys(s){let{indices:e,attributes:t}=s;if(!e)return s;let i=e.value.length,r={};for(let n in t){let o=t[n],{constant:a,value:c,size:l}=o;if(a||!l)continue;let h=new c.constructor(i*l);for(let d=0;d<i;++d){let u=e.value[d];for(let g=0;g<l;g++)h[d*l+g]=c[u*l+g]}r[n]={size:l,value:h}}return{attributes:Object.assign({},t,r)}}var ht=class extends G{constructor(e={}){let{id:t=C("plane-geometry")}=e,{indices:i,attributes:r}=xr(e);super({...e,id:t,topology:"triangle-list",indices:i,attributes:{...r,...e.attributes}})}};function xr(s){let{type:e="x,y",offset:t=0,flipCull:i=!1,unpack:r=!1}=s,n=e.split(","),o=s[`${n[0]}len`]||1,a=s[`${n[1]}len`]||1,c=s[`n${n[0]}`]||1,l=s[`n${n[1]}`]||1,h=(c+1)*(l+1),d=new Float32Array(h*3),u=new Float32Array(h*3),g=new Float32Array(h*2);i&&(o=-o);let m=0,f=0;for(let p=0;p<=l;p++)for(let x=0;x<=c;x++){let b=x/c,M=p/l;switch(g[m+0]=i?1-b:b,g[m+1]=M,e){case"x,y":d[f+0]=o*b-o*.5,d[f+1]=a*M-a*.5,d[f+2]=t,u[f+0]=0,u[f+1]=0,u[f+2]=i?1:-1;break;case"x,z":d[f+0]=o*b-o*.5,d[f+1]=t,d[f+2]=a*M-a*.5,u[f+0]=0,u[f+1]=i?1:-1,u[f+2]=0;break;case"y,z":d[f+0]=t,d[f+1]=o*b-o*.5,d[f+2]=a*M-a*.5,u[f+0]=i?1:-1,u[f+1]=0,u[f+2]=0;break;default:throw new Error("PlaneGeometry: unknown type")}m+=2,f+=3}let y=c+1,v=new Uint16Array(c*l*6);for(let p=0;p<l;p++)for(let x=0;x<c;x++){let b=(p*c+x)*6;v[b+0]=(p+0)*y+x,v[b+1]=(p+1)*y+x,v[b+2]=(p+0)*y+x+1,v[b+3]=(p+1)*y+x,v[b+4]=(p+1)*y+x+1,v[b+5]=(p+0)*y+x+1}let _={indices:{size:1,value:v},attributes:{POSITION:{size:3,value:d},NORMAL:{size:3,value:u},TEXCOORD_0:{size:2,value:g}}};return r?Ys(_):_}var lt=class extends G{constructor(e={}){let{id:t=C("sphere-geometry")}=e,{indices:i,attributes:r}=yr(e);super({...e,id:t,topology:"triangle-list",indices:i,attributes:{...r,...e.attributes}})}};function yr(s){let{nlat:e=10,nlong:t=10}=s,n=Math.PI-0,o=0,c=2*Math.PI-o,l=(e+1)*(t+1),h=(v,_,p,x,b)=>s.radius||1,d=new Float32Array(l*3),u=new Float32Array(l*3),g=new Float32Array(l*2),m=l>65535?Uint32Array:Uint16Array,f=new m(e*t*6);for(let v=0;v<=e;v++)for(let _=0;_<=t;_++){let p=_/t,x=v/e,b=_+v*(t+1),M=b*2,A=b*3,R=c*p,I=n*x,O=Math.sin(R),w=Math.cos(R),S=Math.sin(I),E=Math.cos(I),T=w*S,D=E,J=O*S,K=h(T,D,J,p,x);d[A+0]=K*T,d[A+1]=K*D,d[A+2]=K*J,u[A+0]=T,u[A+1]=D,u[A+2]=J,g[M+0]=p,g[M+1]=1-x}let y=t+1;for(let v=0;v<t;v++)for(let _=0;_<e;_++){let p=(v*e+_)*6;f[p+0]=_*y+v,f[p+1]=_*y+v+1,f[p+2]=(_+1)*y+v,f[p+3]=(_+1)*y+v,f[p+4]=_*y+v+1,f[p+5]=(_+1)*y+v+1}return{indices:{size:1,value:f},attributes:{POSITION:{size:3,value:d},NORMAL:{size:3,value:u},TEXCOORD_0:{size:2,value:g}}}}function Xs(){let s=1,e=1;return()=>(s=Math.sin(e*17.23),e=Math.cos(s*27.92),br(Math.abs(s*e)*1432.71))}function br(s){return s-Math.floor(s)}var $t="";function Ks(s){$t=s}async function Zs(s,e){let t=new Image;return t.crossOrigin=e?.crossOrigin||"anonymous",t.src=s.startsWith("http")?s:$t+s,await t.decode(),e?await createImageBitmap(t,e):await createImageBitmap(t)}async function Qs(s,e){return await new Promise((t,i)=>{try{let r=new Image;r.onload=()=>t(r),r.onerror=()=>i(new Error(`Could not load image ${s}.`)),r.crossOrigin=e?.crossOrigin||"anonymous",r.src=s.startsWith("http")?s:$t+s}catch(r){i(r)}})}var ei=k(he(),1);var re=k(B(),1),Me=class{id;current;next;constructor(e){this.id=e.id||"swap",this.current=e.current,this.next=e.next}destroy(){this.current?.destroy(),this.next?.destroy()}swap(){let e=this.current;this.current=this.next,this.next=e}},_e=class extends Me{constructor(e,t){t={...t};let{width:i=1,height:r=1}=t,n=t.colorAttachments?.map(c=>typeof c!="string"?c:e.createTexture({id:`${t.id}-texture-0`,format:c,usage:re.Texture.SAMPLE|re.Texture.RENDER|re.Texture.COPY_SRC|re.Texture.COPY_DST,width:i,height:r})),o=e.createFramebuffer({...t,colorAttachments:n});n=t.colorAttachments?.map(c=>typeof c!="string"?c:e.createTexture({id:`${t.id}-texture-1`,format:c,usage:re.Texture.SAMPLE|re.Texture.RENDER|re.Texture.COPY_SRC|re.Texture.COPY_DST,width:i,height:r}));let a=e.createFramebuffer({...t,colorAttachments:n});super({current:o,next:a})}resize(e){if(e.width===this.current.width&&e.height===this.current.height)return!1;let{current:t,next:i}=this;return this.current=t.clone(e),t.destroy(),this.next=i.clone(e),i.destroy(),!0}},dt=class extends Me{constructor(e,t){super({current:e.createBuffer(t),next:e.createBuffer(t)})}resize(e){if(e.byteLength===this.current.byteLength)return!1;let{current:t,next:i}=this;return this.current=t.clone(e),t.destroy(),this.next=i.clone(e),i.destroy(),!0}};function Js(s){let{shaderPass:e,action:t,shadingLanguage:i}=s;switch(t){case"filter":let r=`${e.name}_filterColor_ext`;return i==="wgsl"?vr(r):_r(r);case"sample":let n=`${e.name}_sampleColor`;return i==="wgsl"?Mr(n):wr(n);default:throw new Error(`${e.name} no fragment shader generated for shader pass`)}}function vr(s){return`@group(0) @binding(0) var sourceTexture: texture_2d<f32>;
85
+ @group(0) @binding(2) var sourceTextureSampler: sampler;
95
86
 
96
87
  @fragment
97
88
  fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
98
- let fragUV = inputs.uv;
99
- let fragCoordinate = inputs.coordinate;
100
- let texSize = vec2f(textureDimensions(texture, 0));
89
+ let texCoord = inputs.coordinate;
90
+ let texSize = vec2f(textureDimensions(sourceTexture));
101
91
 
102
- var fragColor = textureSample(texture, textureSampler, fragUV);
103
- fragColor = ${s}(fragColor, texSize, fragCoordinate);
92
+ var fragColor = textureSample(sourceTexture, sourceTextureSampler, texCoord);
93
+ fragColor = ${s}(fragColor, texSize, texCoord);
104
94
  return fragColor;
105
95
  }
106
- `}function fr(s){return`// Binding 0:1 is reserved for shader passes
107
- @group(0) @binding(0) var<uniform> brightnessContrast : brightnessContrastUniforms;
108
- @group(0) @binding(1) var texture: texture_2d<f32>;
109
- @group(0) @binding(2) var sampler: sampler;
110
-
111
- struct FragmentInputs = {
112
- @location(0) fragUV: vec2f,
113
- @location(1) fragPosition: vec4f,
114
- @location(2) fragCoordinate: vec4f
115
- };
96
+ `}function Mr(s){return`@group(0) @binding(0) var sourceTexture: texture_2d<f32>;
97
+ @group(0) @binding(2) var sourceTextureSampler: sampler;
116
98
 
117
99
  @fragment
118
100
  fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
119
- let texSize = vec2f(textureDimensions(texture, 0));
120
- var fragColor = textureSample(texture, sampler, fragUV);
121
- fragColor = ${s}(fragColor, texSize, texCoord);
122
- return fragColor;
101
+ let texCoord = inputs.coordinate;
102
+ let texSize = vec2f(textureDimensions(sourceTexture));
103
+ return ${s}(sourceTexture, sourceTextureSampler, texSize, texCoord);
123
104
  }
124
- `}function ur(s){return`#version 300 es
105
+ `}function _r(s){return`#version 300 es
125
106
 
126
107
  uniform sampler2D sourceTexture;
127
108
 
@@ -139,7 +120,7 @@ void main() {
139
120
  fragColor = texture(sourceTexture, texCoord);
140
121
  fragColor = ${s}(fragColor, texSize, texCoord);
141
122
  }
142
- `}function pr(s){return`#version 300 es
123
+ `}function wr(s){return`#version 300 es
143
124
 
144
125
  uniform sampler2D sourceTexture;
145
126
 
@@ -156,24 +137,7 @@ void main() {
156
137
 
157
138
  fragColor = ${s}(sourceTexture, texSize, texCoord);
158
139
  }
159
- `}var fe=class{device;shaderInputs;passRenderers;swapFramebuffers;clipSpace;textureModel;constructor(t,e){this.device=t,e.shaderPasses.map(n=>(0,Hs.initializeShaderModule)(n));let i=e.shaderPasses.reduce((n,o)=>({...n,[o.name]:o}),{});this.shaderInputs=e.shaderInputs||new K(i);let r=t.getCanvasContext().getDrawingBufferSize();this.swapFramebuffers=new _t(t,{colorAttachments:[t.preferredColorFormat],width:r[0],height:r[1]}),this.textureModel=new gt(t,{backgroundTexture:this.swapFramebuffers.current.colorAttachments[0].texture}),this.clipSpace=new st(t,{source:` @group(0) @binding(0) var sourceTexture: texture_2d<f32>;
160
- @group(0) @binding(1) var sourceTextureSampler: sampler;
161
-
162
- @fragment
163
- fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {
164
- let texCoord: vec2<f32> = inputs.coordinate;
165
- return textureSample(sourceTexture, sourceTextureSampler, texCoord);
166
- }
167
- `,fs:`#version 300 es
168
-
169
- uniform sampler2D sourceTexture;
170
- in vec2 uv;
171
- out vec4 fragColor;
172
-
173
- void main() {
174
- fragColor = texture(sourceTexture, uv);
175
- }
176
- `}),this.passRenderers=e.shaderPasses.map(n=>new ke(t,n))}destroy(){for(let t of this.passRenderers)t.destroy();this.swapFramebuffers.destroy(),this.clipSpace.destroy(),this.textureModel.destroy()}resize(t){t||=this.device.getCanvasContext().getDrawingBufferSize(),this.swapFramebuffers.resize({width:t[0],height:t[1]})}renderToScreen(t){let e=this.renderToTexture(t);if(!e)return!1;let i=this.device.getDefaultCanvasContext().getCurrentFramebuffer({depthStencilAttachment:!1}),r=this.device.beginRenderPass({id:"shader-pass-renderer-to-screen",framebuffer:i,clearDepth:1});return this.clipSpace.setBindings({sourceTexture:e}),this.clipSpace.draw(r),r.end(),!0}renderToTexture(t){let{sourceTexture:e}=t;if(!e.isReady)return null;if(this.passRenderers.length===0)return e.texture;this.textureModel.setProps({backgroundTexture:e});let i=this.device.beginRenderPass({id:"shader-pass-renderer-clear-texture",framebuffer:this.swapFramebuffers.current,clearColor:[1,0,0,1]});this.textureModel.draw(i),i.end();let r=!0;for(let o of this.passRenderers)for(let a of o.subPassRenderers){r||this.swapFramebuffers.swap(),r=!1;let h={sourceTexture:this.swapFramebuffers.current.colorAttachments[0].texture},l=this.device.beginRenderPass({id:"shader-pass-renderer-run-pass",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}},ke=class{shaderPass;subPassRenderers;constructor(t,e,i={}){this.shaderPass=e;let r=e.passes||[];this.subPassRenderers=r.map(n=>new Le(t,e,n))}destroy(){for(let t of this.subPassRenderers)t.destroy()}},Le=class{model;shaderPass;subPass;constructor(t,e,i){this.shaderPass=e,this.subPass=i;let r=i.action||i.filter&&"filter"||i.sampler&&"sample"||"filter",n=Xs({shaderPass:e,action:r,shadingLanguage:t.info.shadingLanguage});this.model=new st(t,{id:`${e.name}-subpass`,source:n,fs:n,modules:[e],parameters:{depthWriteEnabled:!1}})}destroy(){this.model.destroy()}render(t){let{renderPass:e,bindings:i}=t;this.model.shaderInputs.setProps({[this.shaderPass.name]:this.shaderPass.uniforms||{}}),this.model.shaderInputs.setProps({[this.shaderPass.name]:this.subPass.uniforms||{}}),this.model.setBindings(i||{}),this.model.draw(e)}};var j=L(B(),1),Ks=L(ht(),1);var Ne=2,mr=1e4,De=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={...De.defaultProps,...e},e=this.props,this.id=e.id||C("model"),this.device=t,Object.assign(this.userData,e.userData);let i=Object.fromEntries(this.props.modules?.map(c=>[c.name,c])||[]);this.shaderInputs=e.shaderInputs||new K(i),this.setShaderInputs(this.shaderInputs),this.props.shaderLayout||=t.getShaderLayout(this.props.source);let r=gr(t),n=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];this.pipelineFactory=e.pipelineFactory||tt.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||et.getDefaultShaderFactory(this.device);let{source:o,getUniforms:a}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:r,...this.props,modules:n});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,i,r){try{this._logDrawCallStart(),this.pipeline=this._updatePipeline(),this.pipeline.setBindings(this.bindings),t.setPipeline(this.pipeline),t.setBindings([]),t.dispatch(e,i,r)}finally{this._logDrawCallEnd()}}setVertexCount(t){}setInstanceCount(t){}setShaderInputs(t){this.shaderInputs=t,this._uniformStore=new j.UniformStore(this.shaderInputs.modules);for(let e of Object.keys(this.shaderInputs.modules)){let i=this._uniformStore.getManagedUniformBuffer(this.device,e);this.bindings[`${e}Uniforms`]=i}}setShaderModuleProps(t){let e=this._getModuleUniforms(t),i=Object.keys(e).filter(n=>{let o=e[n];return!It(o)&&typeof o!="number"&&typeof o!="boolean"}),r={};for(let n of i)r[n]=e[n],delete e[n]}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&&(j.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=j.log.level>3?0:mr;j.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,j.log.group(Ne,`>>> DRAWING MODEL ${this.id}`,{collapsed:j.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=this.shaderInputs.getDebugTable();j.log.table(Ne,t)(),j.log.groupEnd(Ne)(),this._logOpen=!1}}_drawCount=0;_getBufferOrConstantValues(t,e){let i=(0,j.getTypedArrayConstructor)(e);return(t instanceof j.Buffer?new i(t.debugData):t).toString()}},Ot=De;z(Ot,"defaultProps",{...j.ComputePipeline.defaultProps,id:"unnamed",handle:void 0,userData:{},source:"",modules:[],defines:{},bindings:void 0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,shaderAssembler:Ks.ShaderAssembler.getDefaultShaderAssembler(),debugShaders:void 0});function gr(s){return{type:s.type,shaderLanguage:s.info.shadingLanguage,shaderLanguageVersion:s.info.shadingLanguageVersion,gpu:s.info.gpu,features:s.features}}var xr=[0,1,1,1],Q=-1,yr={isActive:"i32",indexMode:"i32",batchIndex:"i32",isHighlightActive:"i32",highlightedBatchIndex:"i32",highlightedObjectIndex:"i32",highlightColor:"vec4<f32>"},wt=`precision highp float;
140
+ `}var ut=class{device;shaderInputs;passRenderers;swapFramebuffers;textureModel;constructor(e,t){this.device=e,t.shaderPasses.map(n=>(0,ei.initializeShaderModule)(n));let i=t.shaderPasses.reduce((n,o)=>({...n,[o.name]:o}),{});this.shaderInputs=t.shaderInputs||new Z(i);let r=e.getCanvasContext().getDrawingBufferSize();this.swapFramebuffers=new _e(e,{colorAttachments:[e.preferredColorFormat],width:r[0],height:r[1]}),this.textureModel=new xe(e,{backgroundTexture:this.swapFramebuffers.current.colorAttachments[0].texture}),this.passRenderers=t.shaderPasses.map(n=>new Bt(e,n))}destroy(){for(let e of this.passRenderers)e.destroy();this.swapFramebuffers.destroy(),this.textureModel.destroy()}resize(e){e||=this.device.getCanvasContext().getDrawingBufferSize(),this.swapFramebuffers.resize({width:e[0],height:e[1]})}renderToScreen(e){let t=this.renderToTexture(e);if(!t)return!1;let i=this.device.getDefaultCanvasContext().getCurrentFramebuffer({depthStencilFormat:!1}),r=this.device.beginRenderPass({id:"shader-pass-renderer-to-screen",framebuffer:i,clearDepth:!1});return this.textureModel.setProps({backgroundTexture:t}),this.textureModel.draw(r),r.end(),!0}renderToTexture(e){let{sourceTexture:t}=e;if(!t.isReady)return null;if(this.passRenderers.length===0)return t.texture;this.textureModel.setProps({backgroundTexture:t});let i=this.device.beginRenderPass({id:"shader-pass-renderer-clear-texture",framebuffer:this.swapFramebuffers.current,clearColor:[1,0,0,1]});this.textureModel.draw(i),i.end();let r=!0;for(let o of this.passRenderers)for(let a of o.subPassRenderers){r||this.swapFramebuffers.swap(),r=!1;let l={sourceTexture:this.swapFramebuffers.current.colorAttachments[0].texture},h=this.device.beginRenderPass({id:"shader-pass-renderer-run-pass",framebuffer:this.swapFramebuffers.next,clearColor:[0,0,0,1],clearDepth:1});a.render({renderPass:h,bindings:l}),h.end()}return this.swapFramebuffers.swap(),this.swapFramebuffers.current.colorAttachments[0].texture}},Bt=class{shaderPass;subPassRenderers;constructor(e,t,i={}){this.shaderPass=t;let r=t.passes||[];this.subPassRenderers=r.map(n=>new Ut(e,t,n))}destroy(){for(let e of this.subPassRenderers)e.destroy()}},Ut=class{model;shaderPass;subPass;constructor(e,t,i){this.shaderPass=t,this.subPass=i;let r=i.action||i.filter&&"filter"||i.sampler&&"sample"||"filter",n=Js({shaderPass:t,action:r,shadingLanguage:e.info.shadingLanguage});this.model=new ne(e,{id:`${t.name}-subpass`,source:n,fs:n,modules:[t],parameters:{depthWriteEnabled:!1}})}destroy(){this.model.destroy()}render(e){let{renderPass:t,bindings:i}=e;this.model.shaderInputs.setProps({[this.shaderPass.name]:this.shaderPass.uniforms||{}}),this.model.shaderInputs.setProps({[this.shaderPass.name]:this.subPass.uniforms||{}}),this.model.setBindings(i||{}),this.model.draw(t)}};var V=k(B(),1),ti=k(he(),1);var Gt=2,Tr=1e4,jt=class{device;id;pipelineFactory;shaderFactory;userData={};bindings={};pipeline;source;shader;shaderInputs;_uniformStore;_pipelineNeedsUpdate="newly created";_getModuleUniforms;props;_destroyed=!1;constructor(e,t){if(e.type!=="webgpu")throw new Error("Computation is only supported in WebGPU");this.props={...jt.defaultProps,...t},t=this.props,this.id=t.id||C("model"),this.device=e,Object.assign(this.userData,t.userData);let i=Object.fromEntries(this.props.modules?.map(c=>[c.name,c])||[]);this.shaderInputs=t.shaderInputs||new Z(i),this.setShaderInputs(this.shaderInputs),this.props.shaderLayout||=e.getShaderLayout(this.props.source);let r=Ar(e),n=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];this.pipelineFactory=t.pipelineFactory||ee.getDefaultPipelineFactory(this.device),this.shaderFactory=t.shaderFactory||te.getDefaultShaderFactory(this.device);let{source:o,getUniforms:a}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:r,...this.props,modules:n});this.source=o,this._getModuleUniforms=a,this.pipeline=this._updatePipeline(),t.bindings&&this.setBindings(t.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(e,t,i,r){try{this._logDrawCallStart(),this.pipeline=this._updatePipeline(),this.pipeline.setBindings(this.bindings),e.setPipeline(this.pipeline),e.setBindings([]),e.dispatch(t,i,r)}finally{this._logDrawCallEnd()}}setVertexCount(e){}setInstanceCount(e){}setShaderInputs(e){this.shaderInputs=e,this._uniformStore=new V.UniformStore(this.shaderInputs.modules);for(let t of Object.keys(this.shaderInputs.modules)){let i=this._uniformStore.getManagedUniformBuffer(this.device,t);this.bindings[`${t}Uniforms`]=i}}setShaderModuleProps(e){let t=this._getModuleUniforms(e),i=Object.keys(t).filter(n=>{let o=t[n];return!Pe(o)&&typeof o!="number"&&typeof o!="boolean"}),r={};for(let n of i)r[n]=t[n],delete t[n]}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues())}setBindings(e){Object.assign(this.bindings,e)}_setPipelineNeedsUpdate(e){this._pipelineNeedsUpdate=this._pipelineNeedsUpdate||e}_updatePipeline(){if(this._pipelineNeedsUpdate){let e=null;this.pipeline&&(V.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),e=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}),e&&this.shaderFactory.release(e)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let e=V.log.level>3?0:Tr;V.log.level<2||Date.now()-this._lastLogTime<e||(this._lastLogTime=Date.now(),this._logOpen=!0,V.log.group(Gt,`>>> DRAWING MODEL ${this.id}`,{collapsed:V.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let e=this.shaderInputs.getDebugTable();V.log.table(Gt,e)(),V.log.groupEnd(Gt)(),this._logOpen=!1}}_drawCount=0;_getBufferOrConstantValues(e,t){let i=(0,V.getTypedArrayConstructor)(t);return(e instanceof V.Buffer?new i(e.debugData):e).toString()}},Oe=jt;$(Oe,"defaultProps",{...V.ComputePipeline.defaultProps,id:"unnamed",handle:void 0,userData:{},source:"",modules:[],defines:{},bindings:void 0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,shaderAssembler:ti.ShaderAssembler.getDefaultShaderAssembler(),debugShaders:void 0});function Ar(s){return{type:s.type,shaderLanguage:s.info.shadingLanguage,shaderLanguageVersion:s.info.shadingLanguageVersion,gpu:s.info.gpu,features:s.features}}var Sr=[0,1,1,1],Q=-1,Pr={isActive:"i32",indexMode:"i32",batchIndex:"i32",isHighlightActive:"i32",highlightedBatchIndex:"i32",highlightedObjectIndex:"i32",highlightColor:"vec4<f32>"},we=`precision highp float;
177
141
  precision highp int;
178
142
 
179
143
  uniform pickingUniforms {
@@ -186,7 +150,7 @@ uniform pickingUniforms {
186
150
  int highlightedObjectIndex;
187
151
  vec4 highlightColor;
188
152
  } picking;
189
- `,ue=`struct pickingUniforms {
153
+ `,ft=`struct pickingUniforms {
190
154
  isActive: int32;
191
155
  indexMode: int32;
192
156
  batchIndex: int32;
@@ -196,18 +160,12 @@ uniform pickingUniforms {
196
160
  highlightedObjectIndex: int32;
197
161
  highlightColor: vec4<f32>;
198
162
  } picking;
199
- `;function br(s={},t){let e={...t};switch(s.isActive!==void 0&&(e.isActive=Boolean(s.isActive)),s.indexMode){case"instance":e.indexMode=0;break;case"custom":e.indexMode=1;break;case void 0:break}switch(s.highlightedObjectIndex){case void 0:break;case null:e.isHighlightActive=!1,e.highlightedObjectIndex=Q;break;default:e.isHighlightActive=!0,e.highlightedObjectIndex=s.highlightedObjectIndex}return typeof s.highlightedBatchIndex=="number"&&(e.highlightedBatchIndex=s.highlightedBatchIndex),s.highlightColor&&(e.highlightColor=s.highlightColor),e}var pe={props:{},uniforms:{},name:"picking",uniformTypes:yr,defaultUniforms:{isActive:!1,indexMode:0,batchIndex:0,isHighlightActive:!0,highlightedBatchIndex:Q,highlightedObjectIndex:Q,highlightColor:xr},getUniforms:br};var Fe=class{device;props;pickInfo={batchIndex:null,objectIndex:null};framebuffer=null;constructor(t,e){this.device=t,this.props={...Fe.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().getDevicePixelSize()),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})}async updatePickInfo(t){let e=this.getFramebuffer(),[i,r]=this.getPickPosition(t),n=this.device.readPixelsToArrayWebGL(e,{sourceX:i,sourceY:r,sourceWidth:1,sourceHeight:1,sourceAttachment:1});if(!n)return null;let o={objectIndex:n[0]===Q?null:n[0],batchIndex:n[1]===Q?null:n[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),i=e.x+Math.floor(e.width/2),r=e.y+Math.floor(e.height/2);return[i,r]}},kt=Fe;z(kt,"defaultProps",{shaderInputs:void 0,onObjectPicked:()=>{}});var vr=`${ue}
163
+ `;function Cr(s={},e){let t={...e};switch(s.isActive!==void 0&&(t.isActive=Boolean(s.isActive)),s.indexMode){case"instance":t.indexMode=0;break;case"custom":t.indexMode=1;break;case void 0:break}switch(s.highlightedObjectIndex){case void 0:break;case null:t.isHighlightActive=!1,t.highlightedObjectIndex=Q;break;default:t.isHighlightActive=!0,t.highlightedObjectIndex=s.highlightedObjectIndex}return typeof s.highlightedBatchIndex=="number"&&(t.highlightedBatchIndex=s.highlightedBatchIndex),s.highlightColor&&(t.highlightColor=s.highlightColor),t}var pt={props:{},uniforms:{},name:"picking",uniformTypes:Pr,defaultUniforms:{isActive:!1,indexMode:0,batchIndex:0,isHighlightActive:!0,highlightedBatchIndex:Q,highlightedObjectIndex:Q,highlightColor:Sr},getUniforms:Cr};var Vt=class{device;props;pickInfo={batchIndex:null,objectIndex:null};framebuffer=null;constructor(e,t){this.device=e,this.props={...Vt.defaultProps,...t}}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 e=this.getFramebuffer();return e.resize(this.device.getDefaultCanvasContext().getDevicePixelSize()),this.props.shaderInputs?.setProps({picking:{isActive:!0}}),this.device.beginRenderPass({framebuffer:e,clearColors:[new Float32Array([0,0,0,0]),new Int32Array([-1,-1,0,0])],clearDepth:1})}async updatePickInfo(e){let t=this.getFramebuffer(),[i,r]=this.getPickPosition(e),n=this.device.readPixelsToArrayWebGL(t,{sourceX:i,sourceY:r,sourceWidth:1,sourceHeight:1,sourceAttachment:1});if(!n)return null;let o={objectIndex:n[0]===Q?null:n[0],batchIndex:n[1]===Q?null:n[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(e){let t=this.device.getDefaultCanvasContext().cssToDevicePixels(e),i=t.x+Math.floor(t.width/2),r=t.y+Math.floor(t.height/2);return[i,r]}},Le=Vt;$(Le,"defaultProps",{shaderInputs:void 0,onObjectPicked:()=>{}});var Ir=`${ft}
200
164
 
201
165
  const INDEX_PICKING_MODE_INSTANCE = 0;
202
166
  const INDEX_PICKING_MODE_CUSTOM = 1;
203
167
  const INDEX_PICKING_INVALID_INDEX = ${Q}; // 2^32 - 1
204
168
 
205
- struct indexPickingFragmentInputs = {
206
- objectIndex: int32;
207
- };
208
-
209
- let indexPickingFragmentInputs: indexPickingFragmentInputs;
210
-
211
169
  /**
212
170
  * Vertex shaders should call this function to set the object index.
213
171
  * If using instance or vertex mode, argument will be ignored, 0 can be supplied.
@@ -223,7 +181,7 @@ fn picking_setObjectIndex(objectIndex: int32) {
223
181
  }
224
182
  }
225
183
 
226
- `,Mr=`${wt}
184
+ `,Er=`${we}
227
185
 
228
186
  const int INDEX_PICKING_MODE_INSTANCE = 0;
229
187
  const int INDEX_PICKING_MODE_CUSTOM = 1;
@@ -246,7 +204,7 @@ void picking_setObjectIndex(int objectIndex) {
246
204
  break;
247
205
  }
248
206
  }
249
- `,_r=`${wt}
207
+ `,Rr=`${we}
250
208
 
251
209
  const int INDEX_PICKING_INVALID_INDEX = ${Q}; // 2^32 - 1
252
210
 
@@ -314,8 +272,8 @@ vec4 picking_filterColor(vec4 color) {
314
272
  outColor = picking_filterPickingColor(outColor);
315
273
  return outColor;
316
274
  }
317
- `,Zs={...pe,name:"picking",source:vr,vs:Mr,fs:_r};var wr=`${ue}
318
- `,Ar=`${wt}
275
+ `,si={...pt,name:"picking",source:Ir,vs:Er,fs:Rr};var Or=`${ft}
276
+ `,Lr=`${we}
319
277
  out vec4 picking_vRGBcolor_Avalid;
320
278
 
321
279
  // Normalize unsigned byte color to 0-1 range
@@ -390,7 +348,7 @@ void picking_setPickingAttribute(vec3 value) {
390
348
  picking_vRGBcolor_Avalid.rgb = value;
391
349
  }
392
350
  }
393
- `,Sr=`${wt}
351
+ `,kr=`${we}
394
352
 
395
353
  in vec4 picking_vRGBcolor_Avalid;
396
354
 
@@ -439,6 +397,6 @@ vec4 picking_filterColor(vec4 color) {
439
397
  vec4 highlightColor = picking_filterHighlightColor(color);
440
398
  return picking_filterPickingColor(highlightColor);
441
399
  }
442
- `,Qs={...pe,name:"picking",source:wr,vs:Ar,fs:Sr};var me=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().getDevicePixelSize()),this.shaderInputs.setProps({picking:{isActive:!0}}),this.device.beginRenderPass({framebuffer:t,clearColor:[0,0,0,0],clearDepth:1})}updatePickState(t){let e=this.getFramebuffer(),[i,r]=this.getPickPosition(t),o=[...this.device.readPixelsToArrayWebGL(e,{sourceX:i,sourceY:r,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),i=e.x+Math.floor(e.width/2),r=e.y+Math.floor(e.height/2);return[i,r]}};var Tr=q;return li(Lt);})();
400
+ `,ii={...pt,name:"picking",source:Or,vs:Lr,fs:kr};var mt=class{device;framebuffer=null;shaderInputs;constructor(e,t){this.device=e,this.shaderInputs=t}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 e=this.getFramebuffer();return e.resize(this.device.getCanvasContext().getDevicePixelSize()),this.shaderInputs.setProps({picking:{isActive:!0}}),this.device.beginRenderPass({framebuffer:e,clearColor:[0,0,0,0],clearDepth:1})}updatePickState(e){let t=this.getFramebuffer(),[i,r]=this.getPickPosition(e),o=[...this.device.readPixelsToArrayWebGL(t,{sourceX:i,sourceY:r,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(e){let t=this.device.getCanvasContext().cssToDevicePixels(e),i=t.x+Math.floor(t.width/2),r=t.y+Math.floor(t.height/2);return[i,r]}};var Fr=H;return mi(ke);})();
443
401
  return __exports__;
444
402
  });