@luma.gl/engine 9.1.7 → 9.1.10

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.
@@ -1 +1 @@
1
- {"version":3,"file":"async-texture.d.ts","sourceRoot":"","sources":["../../src/async-texture/async-texture.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,OAAO,EACP,WAAW,EACX,MAAM,EACN,aAAa,EACb,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACrB,MAAM,eAAe,CAAC;AAKvB,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,GAAG,qBAAqB,CAAC;AAEnF,KAAK,qBAAqB,GACtB,mBAAmB,GACnB,mBAAmB,GACnB,mBAAmB,GACnB,sBAAsB,GACtB,qBAAqB,GACrB,0BAA0B,CAAC;AAE/B,KAAK,mBAAmB,GAAG;IAAC,SAAS,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,GAAG,IAAI,CAAA;CAAC,CAAC;AAClG,KAAK,mBAAmB,GAAG;IAAC,SAAS,CAAC,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,GAAG,IAAI,CAAA;CAAC,CAAC;AACnG,KAAK,mBAAmB,GAAG;IAAC,SAAS,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,GAAG,IAAI,CAAA;CAAC,CAAC;AAClG,KAAK,sBAAsB,GAAG;IAC5B,SAAS,EAAE,UAAU,CAAC;IACtB,IAAI,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,gBAAgB,GAAG,IAAI,CAAC;CAC3D,CAAC;AACF,KAAK,qBAAqB,GAAG;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,OA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AIpB,OAAO,EAAE,OAAO,CAAC;IAEjB,OAAO,EAAE,OAAO,CAAC;IAEjB,IAAI,EAAE,WAAW,CAAC;IAElB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,OAAO,EAAE,OAAO,CAAS;IACzB,SAAS,EAAE,OAAO,CAAS;IAE3B,SAAS,CAAC,YAAY,EAAE,MAAM,IAAI,CAAY;IAC9C,SAAS,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAY;IAEzD,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAEvB;IAED,QAAQ,IAAI,MAAM;gBAIN,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB;IAqB9C,SAAS,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBxD,OAAO,IAAI,IAAI;IASf;;;;;OAKG;IACH,MAAM,CAAC,IAAI,EAAE;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,GAAG,OAAO;CAgBvD"}
@@ -47,10 +47,14 @@ export class AsyncTexture {
47
47
  this.initAsync(props);
48
48
  }
49
49
  async initAsync(props) {
50
- let resolveReady;
51
- let rejectReady;
52
50
  const asyncData = props.data;
53
- const data = await awaitAllPromises(asyncData).then(resolveReady, rejectReady);
51
+ let data;
52
+ try {
53
+ data = await awaitAllPromises(asyncData);
54
+ }
55
+ catch (error) {
56
+ this.rejectReady(error);
57
+ }
54
58
  // Check that we haven't been destroyed while waiting for texture data to load
55
59
  if (this.destroyed) {
56
60
  return;
@@ -62,6 +66,7 @@ export class AsyncTexture {
62
66
  this.sampler = this.texture.sampler;
63
67
  this.view = this.texture.view;
64
68
  this.isReady = true;
69
+ this.resolveReady();
65
70
  }
66
71
  destroy() {
67
72
  if (this.texture) {
@@ -1 +1 @@
1
- {"version":3,"file":"async-texture.js","sourceRoot":"","sources":["../../src/async-texture/async-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AM,CAAC,CAAC,CAAC;QACxD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjC,MAAM,cAAc,GAAwB,EAAE,CAAC;QAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
package/dist/dist.dev.js CHANGED
@@ -1457,10 +1457,13 @@ var __exports__ = (() => {
1457
1457
  this.initAsync(props);
1458
1458
  }
1459
1459
  async initAsync(props) {
1460
- let resolveReady;
1461
- let rejectReady;
1462
1460
  const asyncData = props.data;
1463
- const data = await awaitAllPromises(asyncData).then(resolveReady, rejectReady);
1461
+ let data;
1462
+ try {
1463
+ data = await awaitAllPromises(asyncData);
1464
+ } catch (error) {
1465
+ this.rejectReady(error);
1466
+ }
1464
1467
  if (this.destroyed) {
1465
1468
  return;
1466
1469
  }
@@ -1469,6 +1472,7 @@ var __exports__ = (() => {
1469
1472
  this.sampler = this.texture.sampler;
1470
1473
  this.view = this.texture.view;
1471
1474
  this.isReady = true;
1475
+ this.resolveReady();
1472
1476
  }
1473
1477
  destroy() {
1474
1478
  if (this.texture) {
@@ -1883,6 +1887,10 @@ var __exports__ = (() => {
1883
1887
  `Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`
1884
1888
  )();
1885
1889
  }
1890
+ this.bufferLayout = (0, import_core7.sortedBufferLayoutByShaderSourceLocations)(
1891
+ this.pipeline.shaderLayout,
1892
+ this.bufferLayout
1893
+ );
1886
1894
  const bufferLayoutHelper = new import_core7._BufferLayoutHelper(this.bufferLayout);
1887
1895
  for (const [bufferName, buffer] of Object.entries(buffers)) {
1888
1896
  const bufferLayout = bufferLayoutHelper.getBufferLayout(bufferName);
@@ -1897,7 +1905,8 @@ var __exports__ = (() => {
1897
1905
  for (const attributeName of attributeNames) {
1898
1906
  const attributeInfo = this._attributeInfos[attributeName];
1899
1907
  if (attributeInfo) {
1900
- this.vertexArray.setBuffer(attributeInfo.location, buffer);
1908
+ const location = this.device.type === "webgpu" ? bufferLayoutHelper.getBufferIndex(attributeInfo.bufferName) : attributeInfo.location;
1909
+ this.vertexArray.setBuffer(location, buffer);
1901
1910
  set = true;
1902
1911
  }
1903
1912
  }
package/dist/dist.min.js CHANGED
@@ -4,7 +4,7 @@
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 Ui=Object.create;var bt=Object.defineProperty;var $i=Object.getOwnPropertyDescriptor;var ji=Object.getOwnPropertyNames;var Gi=Object.getPrototypeOf,Vi=Object.prototype.hasOwnProperty;var qi=(i,t,e)=>t in i?bt(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var Le=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),Wi=(i,t)=>{for(var e in t)bt(i,e,{get:t[e],enumerable:!0})},Et=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ji(t))!Vi.call(i,n)&&n!==e&&bt(i,n,{get:()=>t[n],enumerable:!(s=$i(t,n))||s.enumerable});return i},kt=(i,t,e)=>(Et(i,t,"default"),e&&Et(e,t,"default")),L=(i,t,e)=>(e=i!=null?Ui(Gi(i)):{},Et(t||!i||!i.__esModule?bt(e,"default",{value:i,enumerable:!0}):e,i)),Hi=i=>Et(bt({},"__esModule",{value:!0}),i);var V=(i,t,e)=>(qi(i,typeof t!="symbol"?t+"":t,e),e);var j=Le((rn,Ne)=>{Ne.exports=globalThis.luma});var rt=Le((wn,Be)=>{Be.exports=globalThis.luma});var St={};Wi(St,{AnimationLoop:()=>ht,AnimationLoopTemplate:()=>Ft,AsyncTexture:()=>it,BackgroundTextureModel:()=>at,BufferTransform:()=>At,ClipSpace:()=>J,Computation:()=>Pt,ConeGeometry:()=>ee,CubeGeometry:()=>ie,CylinderGeometry:()=>se,GPUGeometry:()=>lt,Geometry:()=>D,GroupNode:()=>mt,IcoSphereGeometry:()=>ne,KeyFrames:()=>Nt,LegacyPickingManager:()=>de,Model:()=>q,ModelNode:()=>te,PickingManager:()=>It,PipelineFactory:()=>Z,PlaneGeometry:()=>re,ScenegraphNode:()=>et,ShaderFactory:()=>Q,ShaderInputs:()=>Y,ShaderPassRenderer:()=>ce,SphereGeometry:()=>oe,Swap:()=>gt,SwapBuffers:()=>ae,SwapFramebuffers:()=>xt,TextureTransform:()=>qt,Timeline:()=>Lt,TruncatedConeGeometry:()=>st,cancelAnimationFramePolyfill:()=>Dt,colorPicking:()=>Ni,indexPicking:()=>Li,loadImage:()=>Ye,loadImageBitmap:()=>jt,makeAnimationLoop:()=>De,makeRandomGenerator:()=>Ri,requestAnimationFramePolyfill:()=>zt,setPathPrefix:()=>He});kt(St,L(j(),1));var Yi=1,Xi=1,Lt=class{time=0;channels=new Map;animations=new Map;playing=!1;lastEngineTime=-1;constructor(){}addChannel(t){let{delay:e=0,duration:s=Number.POSITIVE_INFINITY,rate:n=1,repeat:r=1}=t,o=Yi++,a={time:0,delay:e,duration:s,rate:n,repeat:r};return this._setChannelTime(a,this.time),this.channels.set(o,a),o}removeChannel(t){this.channels.delete(t);for(let[e,s]of this.animations)s.channel===t&&this.detachAnimation(e)}isFinished(t){let e=this.channels.get(t);return e===void 0?!1:this.time>=e.delay+e.duration*e.repeat}getTime(t){if(t===void 0)return this.time;let e=this.channels.get(t);return e===void 0?-1:e.time}setTime(t){this.time=Math.max(0,t);let e=this.channels.values();for(let n of e)this._setChannelTime(n,this.time);let s=this.animations.values();for(let n of s){let{animation:r,channel:o}=n;r.setTime(this.getTime(o))}}play(){this.playing=!0}pause(){this.playing=!1,this.lastEngineTime=-1}reset(){this.setTime(0)}attachAnimation(t,e){let s=Xi++;return this.animations.set(s,{animation:t,channel:e}),t.setTime(this.getTime(e)),s}detachAnimation(t){this.animations.delete(t)}update(t){this.playing&&(this.lastEngineTime===-1&&(this.lastEngineTime=t),this.setTime(this.time+(t-this.lastEngineTime)),this.lastEngineTime=t)}_setChannelTime(t,e){let s=e-t.delay,n=t.duration*t.repeat;s>=n?t.time=t.duration*t.rate:(t.time=Math.max(0,s)%t.duration,t.time*=t.rate)}};var Nt=class{startIndex=-1;endIndex=-1;factor=0;times=[];values=[];_lastTime=-1;constructor(t){this.setKeyFrames(t),this.setTime(0)}setKeyFrames(t){let e=t.length;this.times.length=e,this.values.length=e;for(let s=0;s<e;++s)this.times[s]=t[s][0],this.values[s]=t[s][1];this._calculateKeys(this._lastTime)}setTime(t){t=Math.max(0,t),t!==this._lastTime&&(this._calculateKeys(t),this._lastTime=t)}getStartTime(){return this.times[this.startIndex]}getEndTime(){return this.times[this.endIndex]}getStartData(){return this.values[this.startIndex]}getEndData(){return this.values[this.endIndex]}_calculateKeys(t){let e=0,s=this.times.length;for(e=0;e<s-2&&!(this.times[e+1]>t);++e);this.startIndex=e,this.endIndex=e+1;let n=this.times[this.startIndex],r=this.times[this.endIndex];this.factor=Math.min(Math.max(0,(t-n)/(r-n)),1)}};var Ft=class{constructor(t){}async onInitialize(t){return null}};var Fe=L(j(),1);function zt(i){return typeof window<"u"&&window.requestAnimationFrame?window.requestAnimationFrame(i):setTimeout(i,1e3/60)}function Dt(i){return typeof window<"u"&&window.cancelAnimationFrame?window.cancelAnimationFrame(i):clearTimeout(i)}function Mt(){let i;if(typeof window<"u"&&window.performance)i=window.performance.now();else if(typeof process<"u"&&process.hrtime){let t=process.hrtime();i=t[0]*1e3+t[1]/1e6}else i=Date.now();return i}var nt=class{constructor(t,e){this.sampleSize=1,this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this.name=t,this.type=e,this.reset()}reset(){return this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this}setSampleSize(t){return this.sampleSize=t,this}incrementCount(){return this.addCount(1),this}decrementCount(){return this.subtractCount(1),this}addCount(t){return this._count+=t,this._samples++,this._checkSampling(),this}subtractCount(t){return this._count-=t,this._samples++,this._checkSampling(),this}addTime(t){return this._time+=t,this.lastTiming=t,this._samples++,this._checkSampling(),this}timeStart(){return this._startTime=Mt(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(Mt()-this._startTime),this._timerPending=!1,this._checkSampling(),this):this}getSampleAverageCount(){return this.sampleSize>0?this.lastSampleCount/this.sampleSize:0}getSampleAverageTime(){return this.sampleSize>0?this.lastSampleTime/this.sampleSize:0}getSampleHz(){return this.lastSampleTime>0?this.sampleSize/(this.lastSampleTime/1e3):0}getAverageCount(){return this.samples>0?this.count/this.samples:0}getAverageTime(){return this.samples>0?this.time/this.samples:0}getHz(){return this.time>0?this.samples/(this.time/1e3):0}_checkSampling(){this._samples===this.sampleSize&&(this.lastSampleTime=this._time,this.lastSampleCount=this._count,this.count+=this._count,this.time+=this._time,this.samples+=this._samples,this._time=0,this._count=0,this._samples=0)}};var ct=class{constructor(t){this.stats={},this.id=t.id,this.stats={},this._initializeStats(t.stats),Object.seal(this)}get(t,e="count"){return this._getOrCreate({name:t,type:e})}get size(){return Object.keys(this.stats).length}reset(){for(let t of Object.values(this.stats))t.reset();return this}forEach(t){for(let e of Object.values(this.stats))t(e)}getTable(){let t={};return this.forEach(e=>{t[e.name]={time:e.time||0,count:e.count||0,average:e.getAverageTime()||0,hz:e.getHz()||0}}),t}_initializeStats(t=[]){t.forEach(e=>this._getOrCreate(e))}_getOrCreate(t){let{name:e,type:s}=t,n=this.stats[e];return n||(t instanceof nt?n=t:n=new nt(e,s),this.stats[e]=n),n}};var Ki=0,Zi={device:null,onAddHTML:()=>"",onInitialize:async()=>null,onRender:()=>{},onFinalize:()=>{},onError:i=>console.error(i),stats:Fe.luma.stats.get(`animation-loop-${Ki++}`),useDevicePixels:!0,autoResizeViewport:!1,autoResizeDrawingBuffer:!1},ht=class{device=null;canvas=null;props;animationProps=null;timeline=null;stats;cpuTime;gpuTime;frameRate;display;needsRedraw="initialized";_initialized=!1;_running=!1;_animationFrameId=null;_nextFramePromise=null;_resolveNextFrame=null;_cpuStartTime=0;_error=null;constructor(t){if(this.props={...Zi,...t},t=this.props,!t.device)throw new Error("No device provided");let{useDevicePixels:e=!0}=this.props;this.stats=t.stats||new ct({id:"animation-loop-stats"}),this.cpuTime=this.stats.get("CPU Time"),this.gpuTime=this.stats.get("GPU Time"),this.frameRate=this.stats.get("Frame Rate"),this.setProps({autoResizeViewport:t.autoResizeViewport,autoResizeDrawingBuffer:t.autoResizeDrawingBuffer,useDevicePixels:e}),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this._onMousemove=this._onMousemove.bind(this),this._onMouseleave=this._onMouseleave.bind(this)}destroy(){this.stop(),this._setDisplay(null)}delete(){this.destroy()}setError(t){if(this.props.onError(t),this._error=Error(),this.device?.canvasContext?.canvas instanceof HTMLCanvasElement){let s=document.createElement("h1");s.innerHTML=t.message,s.style.position="absolute",s.style.top="20%",s.style.left="10px",s.style.color="black",s.style.backgroundColor="red",document.body.appendChild(s)}}setNeedsRedraw(t){return this.needsRedraw=this.needsRedraw||t,this}setProps(t){return"autoResizeViewport"in t&&(this.props.autoResizeViewport=t.autoResizeViewport||!1),"autoResizeDrawingBuffer"in t&&(this.props.autoResizeDrawingBuffer=t.autoResizeDrawingBuffer||!1),"useDevicePixels"in t&&(this.props.useDevicePixels=t.useDevicePixels||!1),this}async start(){if(this._running)return this;this._running=!0;try{let t;return this._initialized||(this._initialized=!0,await this._initDevice(),this._initialize(),await this.props.onInitialize(this._getAnimationProps())),this._running?(t!==!1&&(this._cancelAnimationFrame(),this._requestAnimationFrame()),this):null}catch(t){let e=t instanceof Error?t:new Error("Unknown error");throw this.props.onError(e),e}}stop(){return this._running&&(this.animationProps&&!this._error&&this.props.onFinalize(this.animationProps),this._cancelAnimationFrame(),this._nextFramePromise=null,this._resolveNextFrame=null,this._running=!1),this}redraw(){return this.device?.isLost||this._error?this:(this._beginFrameTimers(),this._setupFrame(),this._updateAnimationProps(),this._renderFrame(this._getAnimationProps()),this._clearNeedsRedraw(),this._resolveNextFrame&&(this._resolveNextFrame(this),this._nextFramePromise=null,this._resolveNextFrame=null),this._endFrameTimers(),this)}attachTimeline(t){return this.timeline=t,this.timeline}detachTimeline(){this.timeline=null}waitForRender(){return this.setNeedsRedraw("waitForRender"),this._nextFramePromise||(this._nextFramePromise=new Promise(t=>{this._resolveNextFrame=t})),this._nextFramePromise}async toDataURL(){if(this.setNeedsRedraw("toDataURL"),await this.waitForRender(),this.canvas instanceof HTMLCanvasElement)return this.canvas.toDataURL();throw new Error("OffscreenCanvas")}_initialize(){this._startEventHandling(),this._initializeAnimationProps(),this._updateAnimationProps(),this._resizeCanvasDrawingBuffer(),this._resizeViewport()}_setDisplay(t){this.display&&(this.display.destroy(),this.display.animationLoop=null),t&&(t.animationLoop=this),this.display=t}_requestAnimationFrame(){this._running&&(this._animationFrameId=zt(this._animationFrame.bind(this)))}_cancelAnimationFrame(){this._animationFrameId!==null&&(Dt(this._animationFrameId),this._animationFrameId=null)}_animationFrame(){this._running&&(this.redraw(),this._requestAnimationFrame())}_renderFrame(t){if(this.display){this.display._renderFrame(t);return}this.props.onRender(this._getAnimationProps()),this.device?.submit()}_clearNeedsRedraw(){this.needsRedraw=!1}_setupFrame(){this._resizeCanvasDrawingBuffer(),this._resizeViewport()}_initializeAnimationProps(){let t=this.device?.canvasContext?.canvas;if(!this.device||!t)throw new Error("loop");this.animationProps={animationLoop:this,device:this.device,canvas:t,timeline:this.timeline,useDevicePixels:this.props.useDevicePixels,needsRedraw:!1,width:1,height:1,aspect:1,time:0,startTime:Date.now(),engineTime:0,tick:0,tock:0,_mousePosition:null}}_getAnimationProps(){if(!this.animationProps)throw new Error("animationProps");return this.animationProps}_updateAnimationProps(){if(!this.animationProps)return;let{width:t,height:e,aspect:s}=this._getSizeAndAspect();(t!==this.animationProps.width||e!==this.animationProps.height)&&this.setNeedsRedraw("drawing buffer resized"),s!==this.animationProps.aspect&&this.setNeedsRedraw("drawing buffer aspect changed"),this.animationProps.width=t,this.animationProps.height=e,this.animationProps.aspect=s,this.animationProps.needsRedraw=this.needsRedraw,this.animationProps.engineTime=Date.now()-this.animationProps.startTime,this.timeline&&this.timeline.update(this.animationProps.engineTime),this.animationProps.tick=Math.floor(this.animationProps.time/1e3*60),this.animationProps.tock++,this.animationProps.time=this.timeline?this.timeline.getTime():this.animationProps.engineTime}async _initDevice(){if(this.device=await this.props.device,!this.device)throw new Error("No device provided");this.canvas=this.device.canvasContext?.canvas||null}_createInfoDiv(){if(this.canvas&&this.props.onAddHTML){let t=document.createElement("div");document.body.appendChild(t),t.style.position="relative";let e=document.createElement("div");e.style.position="absolute",e.style.left="10px",e.style.bottom="10px",e.style.width="300px",e.style.background="white",this.canvas instanceof HTMLCanvasElement&&t.appendChild(this.canvas),t.appendChild(e);let s=this.props.onAddHTML(e);s&&(e.innerHTML=s)}}_getSizeAndAspect(){if(!this.device)return{width:1,height:1,aspect:1};let[t,e]=this.device?.canvasContext?.getPixelSize()||[1,1],s=1,n=this.device?.canvasContext?.canvas;return n&&n.clientHeight?s=n.clientWidth/n.clientHeight:t>0&&e>0&&(s=t/e),{width:t,height:e,aspect:s}}_resizeViewport(){this.props.autoResizeViewport&&this.device.gl&&this.device.gl.viewport(0,0,this.device.gl.drawingBufferWidth,this.device.gl.drawingBufferHeight)}_resizeCanvasDrawingBuffer(){this.props.autoResizeDrawingBuffer&&this.device?.canvasContext?.resize({useDevicePixels:this.props.useDevicePixels})}_beginFrameTimers(){this.frameRate.timeEnd(),this.frameRate.timeStart(),this.cpuTime.timeStart()}_endFrameTimers(){this.cpuTime.timeEnd()}_startEventHandling(){this.canvas&&(this.canvas.addEventListener("mousemove",this._onMousemove.bind(this)),this.canvas.addEventListener("mouseleave",this._onMouseleave.bind(this)))}_onMousemove(t){t instanceof MouseEvent&&(this._getAnimationProps()._mousePosition=[t.offsetX,t.offsetY])}_onMouseleave(t){this._getAnimationProps()._mousePosition=null}};var ze=L(j(),1);function De(i,t){let e=null,s=t?.device||ze.luma.createDevice({id:"animation-loop",adapters:t?.adapters,createCanvasContext:!0}),n=new ht({...t,device:s,async onInitialize(r){return e=new i(r),await e?.onInitialize(r)},onRender:r=>e?.onRender(r),onFinalize:r=>e?.onFinalize(r)});return n.getInfo=()=>this.AnimationLoopTemplateCtor.info,n}var P=L(j(),1),Gt=L(rt(),1);var vt=L(j(),1);var ue={};function O(i="id"){ue[i]=ue[i]||1;let t=ue[i]++;return`${i}-${t}`}var lt=class{id;userData={};topology;bufferLayout=[];vertexCount;indices;attributes;constructor(t){if(this.id=t.id||O("geometry"),this.topology=t.topology,this.indices=t.indices||null,this.attributes=t.attributes,this.vertexCount=t.vertexCount,this.bufferLayout=t.bufferLayout||[],this.indices&&!(this.indices.usage&vt.Buffer.INDEX))throw new Error("Index buffer must have INDEX usage")}destroy(){this.indices?.destroy();for(let t of Object.values(this.attributes))t.destroy()}getVertexCount(){return this.vertexCount}getAttributes(){return this.attributes}getIndexes(){return this.indices||null}_calculateVertexCount(t){return t.byteLength/12}};function Ue(i,t){if(t instanceof lt)return t;let e=Qi(i,t),{attributes:s,bufferLayout:n}=Ji(i,t);return new lt({topology:t.topology||"triangle-list",bufferLayout:n,vertexCount:t.vertexCount,indices:e,attributes:s})}function Qi(i,t){if(!t.indices)return;let e=t.indices.value;return i.createBuffer({usage:vt.Buffer.INDEX,data:e})}function Ji(i,t){let e=[],s={};for(let[r,o]of Object.entries(t.attributes)){let a=r;switch(r){case"POSITION":a="positions";break;case"NORMAL":a="normals";break;case"TEXCOORD_0":a="texCoords";break;case"COLOR_0":a="colors";break}if(o){s[a]=i.createBuffer({data:o.value,id:`${r}-buffer`});let{value:c,size:h,normalized:l}=o;e.push({name:a,format:(0,vt.getVertexFormatFromAttribute)(c,h,l)})}}let n=t._calculateVertexCount(t.attributes,t.indices);return{attributes:s,bufferLayout:e,vertexCount:n}}var ft=L(j(),1);var pe=class{static getDefaultPipelineFactory(t){return t._lumaData.defaultPipelineFactory=t._lumaData.defaultPipelineFactory||new pe(t),t._lumaData.defaultPipelineFactory}device;destroyPolicy;_hashCounter=0;_hashes={};_renderPipelineCache={};_computePipelineCache={};constructor(t){this.device=t,this.destroyPolicy=t.props._factoryDestroyPolicy}createRenderPipeline(t){let e={...ft.RenderPipeline.defaultProps,...t},s=this._hashRenderPipeline(e);if(!this._renderPipelineCache[s]){let n=this.device.createRenderPipeline({...e,id:e.id?`${e.id}-cached`:void 0});n.hash=s,this._renderPipelineCache[s]={pipeline:n,useCount:0}}return this._renderPipelineCache[s].useCount++,this._renderPipelineCache[s].pipeline}createComputePipeline(t){let e={...ft.ComputePipeline.defaultProps,...t},s=this._hashComputePipeline(e);if(!this._computePipelineCache[s]){let n=this.device.createComputePipeline({...e,id:e.id?`${e.id}-cached`:void 0});n.hash=s,this._computePipelineCache[s]={pipeline:n,useCount:0}}return this._computePipelineCache[s].useCount++,this._computePipelineCache[s].pipeline}release(t){let e=t.hash,s=t instanceof ft.ComputePipeline?this._computePipelineCache:this._renderPipelineCache;s[e].useCount--,s[e].useCount===0&&this.destroyPolicy==="unused"&&(s[e].pipeline.destroy(),delete s[e])}_hashComputePipeline(t){return`${this._getHash(t.shader.source)}`}_hashRenderPipeline(t){let e=t.vs?this._getHash(t.vs.source):0,s=t.fs?this._getHash(t.fs.source):0,n="-",r=this._getHash(JSON.stringify(t.bufferLayout));switch(this.device.type){case"webgl":return`${e}/${s}V${n}BL${r}`;default:let o=this._getHash(JSON.stringify(t.parameters));return`${e}/${s}V${n}T${t.topology}P${o}BL${r}`}}_getHash(t){return this._hashes[t]===void 0&&(this._hashes[t]=this._hashCounter++),this._hashes[t]}},Z=pe;V(Z,"defaultProps",{...ft.RenderPipeline.defaultProps});var $e=L(j(),1);var me=class{static getDefaultShaderFactory(t){return t._lumaData.defaultShaderFactory||=new me(t),t._lumaData.defaultShaderFactory}device;destroyPolicy;_cache={};constructor(t){this.device=t,this.destroyPolicy=t.props._factoryDestroyPolicy}createShader(t){let e=this._hashShader(t),s=this._cache[e];if(!s){let n=this.device.createShader({...t,id:t.id?`${t.id}-cached`:void 0});this._cache[e]=s={shader:n,useCount:0}}return s.useCount++,s.shader}release(t){let e=this._hashShader(t),s=this._cache[e];s&&(s.useCount--,s.useCount===0&&this.destroyPolicy==="unused"&&(delete this._cache[e],s.shader.destroy()))}_hashShader(t){return`${t.stage}:${t.source}`}},Q=me;V(Q,"defaultProps",{...$e.Shader.defaultProps});function je(i,t){let e={},s="Values";if(i.attributes.length===0&&!i.varyings?.length)return{"No attributes or varyings":{[s]:"N/A"}};for(let n of i.attributes)if(n){let r=`${n.location} ${n.name}: ${n.type}`;e[`in ${r}`]={[s]:n.stepMode||"vertex"}}for(let n of i.varyings||[]){let r=`${n.location} ${n.name}`;e[`out ${r}`]={[s]:JSON.stringify(n)}}return e}var N=null,ge=null;function Ge(i,{id:t,minimap:e,opaque:s,top:n="0",left:r="0",rgbaScale:o=1}){N||(N=document.createElement("canvas"),N.id=t,N.title=t,N.style.zIndex="100",N.style.position="absolute",N.style.top=n,N.style.left=r,N.style.border="blue 5px solid",N.style.transform="scaleY(-1)",document.body.appendChild(N),ge=N.getContext("2d")),(N.width!==i.width||N.height!==i.height)&&(N.width=i.width/2,N.height=i.height/2,N.style.width="400px",N.style.height="400px");let a=i.device.readPixelsToArrayWebGL(i),c=ge?.createImageData(i.width,i.height);if(c){for(let l=0;l<a.length;l+=4)c.data[0+l+0]=a[l+0]*o,c.data[0+l+1]=a[l+1]*o,c.data[0+l+2]=a[l+2]*o,c.data[0+l+3]=s?255:a[l+3]*o;ge?.putImageData(c,0,0)}}function Bt(i,t,e){if(i===t)return!0;if(!e||!i||!t)return!1;if(Array.isArray(i)){if(!Array.isArray(t)||i.length!==t.length)return!1;for(let s=0;s<i.length;s++)if(!Bt(i[s],t[s],e-1))return!1;return!0}if(Array.isArray(t))return!1;if(typeof i=="object"&&typeof t=="object"){let s=Object.keys(i),n=Object.keys(t);if(s.length!==n.length)return!1;for(let r of s)if(!t.hasOwnProperty(r)||!Bt(i[r],t[r],e-1))return!1;return!0}return!1}var $t=L(j(),1),We=L(rt(),1);function Ve(i){return ArrayBuffer.isView(i)&&!(i instanceof DataView)}function qe(i){return Array.isArray(i)?i.length===0||typeof i[0]=="number":!1}function _t(i){return Ve(i)||qe(i)}function ts(i){return _t(i)||typeof i=="number"||typeof i=="boolean"}function Ut(i){let t={bindings:{},uniforms:{}};return Object.keys(i).forEach(e=>{let s=i[e];ts(s)?t.uniforms[e]=s:t.bindings[e]=s}),t}var Y=class{options={disableWarnings:!1};modules;moduleUniforms;moduleBindings;constructor(t,e){Object.assign(this.options,e);let s=(0,We.getShaderModuleDependencies)(Object.values(t).filter(n=>n.dependencies));for(let n of s)t[n.name]=n;$t.log.log(1,"Creating ShaderInputs with modules",Object.keys(t))(),this.modules=t,this.moduleUniforms={},this.moduleBindings={};for(let[n,r]of Object.entries(t))this._addModule(r),r.name&&n!==r.name&&!this.options.disableWarnings&&$t.log.warn(`Module name: ${n} vs ${r.name}`)()}destroy(){}setProps(t){for(let e of Object.keys(t)){let s=e,n=t[s]||{},r=this.modules[s];if(!r){this.options.disableWarnings||$t.log.warn(`Module ${e} not found`)();continue}let o=this.moduleUniforms[s],a=this.moduleBindings[s],c=r.getUniforms?.(n,o)||n,{uniforms:h,bindings:l}=Ut(c);this.moduleUniforms[s]={...o,...h},this.moduleBindings[s]={...a,...l}}}getModules(){return Object.values(this.modules)}getUniformValues(){return this.moduleUniforms}getBindingValues(){let t={};for(let e of Object.values(this.moduleBindings))Object.assign(t,e);return t}getDebugTable(){let t={};for(let[e,s]of Object.entries(this.moduleUniforms))for(let[n,r]of Object.entries(s))t[`${e}.${n}`]={type:this.modules[e].uniformTypes?.[n],value:String(r)};return t}_addModule(t){let e=t.name;this.moduleUniforms[e]=t.defaultUniforms||{},this.moduleBindings[e]={}}};var xe="";function He(i){xe=i}async function jt(i,t){let e=new Image;return e.crossOrigin=t?.crossOrigin||"anonymous",e.src=i.startsWith("http")?i:xe+i,await e.decode(),t?await createImageBitmap(e,t):await createImageBitmap(e)}async function Ye(i,t){return await new Promise((e,s)=>{try{let n=new Image;n.onload=()=>e(n),n.onerror=()=>s(new Error(`Could not load image ${i}.`)),n.crossOrigin=t?.crossOrigin||"anonymous",n.src=i.startsWith("http")?i:xe+i}catch(n){s(n)}})}var it=class{device;id;texture;sampler;view;ready;isReady=!1;destroyed=!1;resolveReady=()=>{};rejectReady=()=>{};get[Symbol.toStringTag](){return"AsyncTexture"}toString(){return`AsyncTexture:"${this.id}"(${this.isReady?"ready":"loading"})`}constructor(t,e){this.device=t,this.id=e.id||O("async-texture"),typeof e?.data=="string"&&e.dimension==="2d"&&(e={...e,data:jt(e.data)}),this.ready=new Promise((s,n)=>{this.resolveReady=()=>{this.isReady=!0,s()},this.rejectReady=n}),this.initAsync(e)}async initAsync(t){let e,s,n=t.data,r=await Xe(n).then(e,s);if(this.destroyed)return;let o={...t,data:r};this.texture=this.device.createTexture(o),this.sampler=this.texture.sampler,this.view=this.texture.view,this.isReady=!0}destroy(){this.texture&&(this.texture.destroy(),this.texture=null),this.destroyed=!0}resize(t){if(!this.isReady)throw new Error("Cannot resize texture before it is ready");if(t.width===this.texture.width&&t.height===this.texture.height)return!1;if(this.texture){let e=this.texture;this.texture=e.clone(t),e.destroy()}return!0}};async function Xe(i){if(i=await i,Array.isArray(i))return await Promise.all(i.map(Xe));if(i&&typeof i=="object"&&i.constructor===Object){let t=i,e=await Promise.all(Object.values(t)),s=Object.keys(t),n={};for(let r=0;r<s.length;r++)n[s[r]]=e[r];return n}return i}var ot=2,es=1e4,be=class{device;id;source;vs;fs;pipelineFactory;shaderFactory;userData={};parameters;topology;bufferLayout;isInstanced=void 0;instanceCount=0;vertexCount;indexBuffer=null;bufferAttributes={};constantAttributes={};bindings={};uniforms={};vertexArray;transformFeedback=null;pipeline;shaderInputs;_uniformStore;_attributeInfos={};_gpuGeometry=null;_getModuleUniforms;props;_pipelineNeedsUpdate="newly created";_needsRedraw="initializing";_destroyed=!1;_lastDrawTimestamp=-1;get[Symbol.toStringTag](){return"Model"}toString(){return`Model(${this.id})`}constructor(t,e){this.props={...be.defaultProps,...e},e=this.props,this.id=e.id||O("model"),this.device=t,Object.assign(this.userData,e.userData);let s=Object.fromEntries(this.props.modules?.map(c=>[c.name,c])||[]),n=e.shaderInputs||new Y(s,{disableWarnings:this.props.disableWarnings});this.setShaderInputs(n);let r=ss(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:r,...this.props,modules:o});this.source=c,this._getModuleUniforms=h,this.props.shaderLayout||=(0,Gt.getShaderLayoutFromWGSL)(this.source)}else{let{vs:c,fs:h,getUniforms:l}=this.props.shaderAssembler.assembleGLSLShaderPair({platformInfo:r,...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||Z.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||Q.getDefaultShaderFactory(this.device),this.pipeline=this._updatePipeline(),this.vertexArray=t.createVertexArray({renderPipeline:this.pipeline}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry),"isInstanced"in e&&(this.isInstanced=e.isInstanced),e.instanceCount&&this.setInstanceCount(e.instanceCount),e.vertexCount&&this.setVertexCount(e.vertexCount),e.indexBuffer&&this.setIndexBuffer(e.indexBuffer),e.attributes&&this.setAttributes(e.attributes),e.constantAttributes&&this.setConstantAttributes(e.constantAttributes),e.bindings&&this.setBindings(e.bindings),e.uniforms&&this.setUniformsWebGL(e.uniforms),e.moduleSettings&&this.updateModuleSettingsWebGL(e.moduleSettings),e.transformFeedback&&(this.transformFeedback=e.transformFeedback),Object.seal(this)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.pipeline.vs),this.pipeline.fs&&this.shaderFactory.release(this.pipeline.fs),this._uniformStore.destroy(),this._gpuGeometry?.destroy(),this._destroyed=!0)}needsRedraw(){this._getBindingsUpdateTimestamp()>this._lastDrawTimestamp&&this.setNeedsRedraw("contents of bound textures or buffers updated");let t=this._needsRedraw;return this._needsRedraw=!1,t}setNeedsRedraw(t){this._needsRedraw||=t}predraw(){this.updateShaderInputs(),this.pipeline=this._updatePipeline()}draw(t){let e=this._areBindingsLoading();if(e)return P.log.info(ot,`>>> DRAWING ABORTED ${this.id}: ${e} not loaded`)(),!1;try{t.pushDebugGroup(`${this}.predraw(${t})`),this.predraw()}finally{t.popDebugGroup()}let s;try{t.pushDebugGroup(`${this}.draw(${t})`),this._logDrawCallStart(),this.pipeline=this._updatePipeline();let n=this._getBindings();this.pipeline.setBindings(n,{disableWarnings:this.props.disableWarnings}),ye(this.uniforms)||this.pipeline.setUniformsWebGL(this.uniforms);let{indexBuffer:r}=this.vertexArray,o=r?r.byteLength/(r.indexType==="uint32"?4:2):void 0;s=this.pipeline.draw({renderPass:t,vertexArray:this.vertexArray,isInstanced:this.isInstanced,vertexCount:this.vertexCount,instanceCount:this.instanceCount,indexCount:o,transformFeedback:this.transformFeedback||void 0,parameters:this.parameters,topology:this.topology})}finally{t.popDebugGroup(),this._logDrawCallEnd()}return this._logFramebuffer(t),s?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):this._needsRedraw="waiting for resource initialization",s}setGeometry(t){this._gpuGeometry?.destroy();let e=t&&Ue(this.device,t);if(e){this.setTopology(e.topology||"triangle-list");let s=new P._BufferLayoutHelper(this.bufferLayout);this.bufferLayout=s.mergeBufferLayouts(e.bufferLayout,this.bufferLayout),this.vertexArray&&this._setGeometryAttributes(e)}this._gpuGeometry=e}setTopology(t){t!==this.topology&&(this.topology=t,this._setPipelineNeedsUpdate("topology"))}setBufferLayout(t){let e=new P._BufferLayoutHelper(this.bufferLayout);this.bufferLayout=this._gpuGeometry?e.mergeBufferLayouts(t,this._gpuGeometry.bufferLayout):t,this._setPipelineNeedsUpdate("bufferLayout"),this.pipeline=this._updatePipeline(),this.vertexArray=this.device.createVertexArray({renderPipeline:this.pipeline}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry)}setParameters(t){Bt(t,this.parameters,2)||(this.parameters=t,this._setPipelineNeedsUpdate("parameters"))}setInstanceCount(t){this.instanceCount=t,this.isInstanced===void 0&&t>0&&(this.isInstanced=!0),this.setNeedsRedraw("instanceCount")}setVertexCount(t){this.vertexCount=t,this.setNeedsRedraw("vertexCount")}setShaderInputs(t){this.shaderInputs=t,this._uniformStore=new P.UniformStore(this.shaderInputs.modules);for(let[e,s]of Object.entries(this.shaderInputs.modules))if(is(s)){let n=this._uniformStore.getManagedUniformBuffer(this.device,e);this.bindings[`${e}Uniforms`]=n}this.setNeedsRedraw("shaderInputs")}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues()),this.setBindings(this.shaderInputs.getBindingValues()),this.setNeedsRedraw("shaderInputs")}setBindings(t){Object.assign(this.bindings,t),this.setNeedsRedraw("bindings")}setTransformFeedback(t){this.transformFeedback=t,this.setNeedsRedraw("transformFeedback")}setIndexBuffer(t){this.vertexArray.setIndexBuffer(t),this.setNeedsRedraw("indexBuffer")}setAttributes(t,e){let s=e?.disableWarnings??this.props.disableWarnings;t.indices&&P.log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)();let n=new P._BufferLayoutHelper(this.bufferLayout);for(let[r,o]of Object.entries(t)){let a=n.getBufferLayout(r);if(!a){s||P.log.warn(`Model(${this.id}): Missing layout for buffer "${r}".`)();continue}let c=n.getAttributeNamesForBuffer(a),h=!1;for(let l of c){let f=this._attributeInfos[l];f&&(this.vertexArray.setBuffer(f.location,o),h=!0)}!h&&!s&&P.log.warn(`Model(${this.id}): Ignoring buffer "${o.id}" for unknown attribute "${r}"`)()}this.setNeedsRedraw("attributes")}setConstantAttributes(t,e){for(let[s,n]of Object.entries(t)){let r=this._attributeInfos[s];r?this.vertexArray.setConstantWebGL(r.location,n):(e?.disableWarnings??this.props.disableWarnings)||P.log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${s}"`)()}this.setNeedsRedraw("constants")}setUniforms(t){this.setUniformsWebGL(t)}setUniformsWebGL(t){ye(t)||(this.pipeline.setUniformsWebGL(t),Object.assign(this.uniforms,t)),this.setNeedsRedraw("uniforms")}updateModuleSettingsWebGL(t){let{bindings:e,uniforms:s}=Ut(this._getModuleUniforms(t));Object.assign(this.bindings,e),Object.assign(this.uniforms,s),this.setNeedsRedraw("moduleSettings")}_areBindingsLoading(){for(let t of Object.values(this.bindings))if(t instanceof it&&!t.isReady)return t.id;return!1}_getBindings(){let t={};for(let[e,s]of Object.entries(this.bindings))s instanceof it?s.isReady&&(t[e]=s.texture):t[e]=s;return t}_getBindingsUpdateTimestamp(){let t=0;for(let e of Object.values(this.bindings))e instanceof P.TextureView?t=Math.max(t,e.texture.updateTimestamp):e instanceof P.Buffer||e instanceof P.Texture?t=Math.max(t,e.updateTimestamp):e instanceof it?t=e.texture?Math.max(t,e.texture.updateTimestamp):1/0:e instanceof P.Sampler||(t=Math.max(t,e.buffer.updateTimestamp));return t}_setGeometryAttributes(t){let e={...t.attributes};for(let[s]of Object.entries(e))!this.pipeline.shaderLayout.attributes.find(n=>n.name===s)&&s!=="positions"&&delete e[s];this.vertexCount=t.vertexCount,this.setIndexBuffer(t.indices||null),this.setAttributes(t.attributes,{disableWarnings:!0}),this.setAttributes(e,{disableWarnings:this.props.disableWarnings}),this.setNeedsRedraw("geometry attributes")}_setPipelineNeedsUpdate(t){this._pipelineNeedsUpdate||=t,this.setNeedsRedraw(t)}_updatePipeline(){if(this._pipelineNeedsUpdate){let t=null,e=null;this.pipeline&&(P.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),t=this.pipeline.vs,e=this.pipeline.fs),this._pipelineNeedsUpdate=!1;let s=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:"vertex",source:this.source||this.vs,debugShaders:this.props.debugShaders}),n=null;this.source?n=s:this.fs&&(n=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"fragment",source:this.source||this.fs,debugShaders:this.props.debugShaders})),this.pipeline=this.pipelineFactory.createRenderPipeline({...this.props,bufferLayout:this.bufferLayout,topology:this.topology,parameters:this.parameters,bindings:this._getBindings(),vs:s,fs:n}),this._attributeInfos=(0,P.getAttributeInfosFromLayouts)(this.pipeline.shaderLayout,this.bufferLayout),t&&this.shaderFactory.release(t),e&&this.shaderFactory.release(e)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let t=P.log.level>3?0:es;P.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,P.log.group(ot,`>>> DRAWING MODEL ${this.id}`,{collapsed:P.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=je(this.pipeline.shaderLayout,this.id);P.log.table(ot,t)();let e=this.shaderInputs.getDebugTable();for(let[n,r]of Object.entries(this.uniforms))e[n]={value:r};P.log.table(ot,e)();let s=this._getAttributeDebugTable();P.log.table(ot,this._attributeInfos)(),P.log.table(ot,s)(),P.log.groupEnd(ot)(),this._logOpen=!1}}_drawCount=0;_logFramebuffer(t){let e=this.device.props.debugFramebuffers;if(this._drawCount++,!e)return;let s=t.props.framebuffer;s&&Ge(s,{id:s.id,minimap:!0})}_getAttributeDebugTable(){let t={};for(let[e,s]of Object.entries(this._attributeInfos)){let n=this.vertexArray.attributes[s.location];t[s.location]={name:e,type:s.shaderType,values:n?this._getBufferOrConstantValues(n,s.bufferDataType):"null"}}if(this.vertexArray.indexBuffer){let{indexBuffer:e}=this.vertexArray,s=e.indexType==="uint32"?new Uint32Array(e.debugData):new Uint16Array(e.debugData);t.indices={name:"indices",type:e.indexType,values:s.toString()}}return t}_getBufferOrConstantValues(t,e){let s=(0,P.getTypedArrayFromDataType)(e);return(t instanceof P.Buffer?new s(t.debugData):t).toString()}},q=be;V(q,"defaultProps",{...P.RenderPipeline.defaultProps,source:void 0,vs:null,fs:null,id:"unnamed",handle:void 0,userData:{},defines:{},modules:[],moduleSettings:void 0,geometry:null,indexBuffer:null,attributes:{},constantAttributes:{},varyings:[],isInstanced:void 0,instanceCount:0,vertexCount:0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,transformFeedback:void 0,shaderAssembler:Gt.ShaderAssembler.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0});function is(i){return Boolean(i.uniformTypes&&!ye(i.uniformTypes))}function ss(i){return{type:i.type,shaderLanguage:i.info.shadingLanguage,shaderLanguageVersion:i.info.shadingLanguageVersion,gpu:i.info.gpu,features:i.features}}function ye(i){for(let t in i)return!1;return!0}var Ke=L(j(),1),Ze=L(rt(),1);var Vt=class{device;model;transformFeedback;static isSupported(t){return t?.info?.type==="webgl"}constructor(t,e=Vt.defaultProps){if(!Vt.isSupported(t))throw new Error("BufferTransform not yet implemented on WebGPU");this.device=t,this.model=new q(this.device,{id:e.id||"buffer-transform-model",fs:e.fs||(0,Ze.getPassthroughFS)(),topology:e.topology||"point-list",varyings:e.outputs||e.varyings,...e}),this.transformFeedback=this.device.createTransformFeedback({layout:this.model.pipeline.shaderLayout,buffers:e.feedbackBuffers}),this.model.setTransformFeedback(this.transformFeedback),Object.seal(this)}destroy(){this.model&&this.model.destroy()}delete(){this.destroy()}run(t){t?.inputBuffers&&this.model.setAttributes(t.inputBuffers),t?.outputBuffers&&this.transformFeedback.setBuffers(t.outputBuffers);let e=this.device.beginRenderPass(t);this.model.draw(e),e.end()}getBuffer(t){return this.transformFeedback.getBuffer(t)}readAsync(t){let e=this.getBuffer(t);if(!e)throw new Error("BufferTransform#getBuffer");if(e instanceof Ke.Buffer)return e.readAsync();let{buffer:s,byteOffset:n=0,byteLength:r=s.byteLength}=e;return s.readAsync(n,r)}},At=Vt;V(At,"defaultProps",{...q.defaultProps,outputs:void 0,feedbackBuffers:void 0});var Qe=L(rt(),1),ns="transform_output",qt=class{device;model;sampler;currentIndex=0;samplerTextureMap=null;bindings=[];resources={};constructor(t,e){this.device=t,this.sampler=t.createSampler({addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",minFilter:"nearest",magFilter:"nearest",mipmapFilter:"nearest"}),this.model=new q(this.device,{id:e.id||"texture-transform-model",fs:e.fs||(0,Qe.getPassthroughFS)({input:e.targetTextureVarying,inputChannels:e.targetTextureChannels,output:ns}),vertexCount:e.vertexCount,...e}),this._initialize(e),Object.seal(this)}destroy(){this.model.destroy();for(let t of this.bindings)t.framebuffer?.destroy()}delete(){this.destroy()}run(t){let{framebuffer:e}=this.bindings[this.currentIndex],s=this.device.beginRenderPass({framebuffer:e,...t});this.model.draw(s),s.end()}getTargetTexture(){let{targetTexture:t}=this.bindings[this.currentIndex];return t}getFramebuffer(){return this.bindings[this.currentIndex].framebuffer}_initialize(t){this._updateBindings(t)}_updateBindings(t){this.bindings[this.currentIndex]=this._updateBinding(this.bindings[this.currentIndex],t)}_updateBinding(t,{sourceBuffers:e,sourceTextures:s,targetTexture:n}){if(t||(t={sourceBuffers:{},sourceTextures:{},targetTexture:null}),Object.assign(t.sourceTextures,s),Object.assign(t.sourceBuffers,e),n){t.targetTexture=n;let{width:r,height:o}=n;t.framebuffer&&t.framebuffer.destroy(),t.framebuffer=this.device.createFramebuffer({id:"transform-framebuffer",width:r,height:o,colorAttachments:[n]}),t.framebuffer.resize({width:r,height:o})}return t}_setSourceTextureParameters(){let t=this.currentIndex,{sourceTextures:e}=this.bindings[t];for(let s in e)e[s].sampler=this.sampler}};var D=class{id;topology;vertexCount;indices;attributes;userData={};constructor(t){let{attributes:e={},indices:s=null,vertexCount:n=null}=t;this.id=t.id||O("geometry"),this.topology=t.topology,s&&(this.indices=ArrayBuffer.isView(s)?{value:s,size:1}:s),this.attributes={};for(let[r,o]of Object.entries(e)){let a=ArrayBuffer.isView(o)?{value:o}:o;if(!ArrayBuffer.isView(a.value))throw new Error(`${this._print(r)}: must be typed array or object with value as typed array`);if((r==="POSITION"||r==="positions")&&!a.size&&(a.size=3),r==="indices"){if(this.indices)throw new Error("Multiple indices detected");this.indices=a}else this.attributes[r]=a}this.indices&&this.indices.isIndexed!==void 0&&(this.indices=Object.assign({},this.indices),delete this.indices.isIndexed),this.vertexCount=n||this._calculateVertexCount(this.attributes,this.indices)}getVertexCount(){return this.vertexCount}getAttributes(){return this.indices?{indices:this.indices,...this.attributes}:this.attributes}_print(t){return`Geometry ${this.id} attribute ${t}`}_setAttributes(t,e){return this}_calculateVertexCount(t,e){if(e)return e.value.length;let s=1/0;for(let n of Object.values(t)){let{value:r,size:o,constant:a}=n;!a&&r&&o!==void 0&&o>=1&&(s=Math.min(s,r.length/o))}return s}};var rs=`struct VertexInputs {
7
+ "use strict";var __exports__=(()=>{var Ui=Object.create;var bt=Object.defineProperty;var $i=Object.getOwnPropertyDescriptor;var ji=Object.getOwnPropertyNames;var Gi=Object.getPrototypeOf,Vi=Object.prototype.hasOwnProperty;var qi=(i,t,e)=>t in i?bt(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var Le=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),Wi=(i,t)=>{for(var e in t)bt(i,e,{get:t[e],enumerable:!0})},Et=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ji(t))!Vi.call(i,n)&&n!==e&&bt(i,n,{get:()=>t[n],enumerable:!(s=$i(t,n))||s.enumerable});return i},kt=(i,t,e)=>(Et(i,t,"default"),e&&Et(e,t,"default")),L=(i,t,e)=>(e=i!=null?Ui(Gi(i)):{},Et(t||!i||!i.__esModule?bt(e,"default",{value:i,enumerable:!0}):e,i)),Hi=i=>Et(bt({},"__esModule",{value:!0}),i);var V=(i,t,e)=>(qi(i,typeof t!="symbol"?t+"":t,e),e);var j=Le((rn,Ne)=>{Ne.exports=globalThis.luma});var rt=Le((wn,Be)=>{Be.exports=globalThis.luma});var St={};Wi(St,{AnimationLoop:()=>ht,AnimationLoopTemplate:()=>Ft,AsyncTexture:()=>it,BackgroundTextureModel:()=>at,BufferTransform:()=>At,ClipSpace:()=>J,Computation:()=>Pt,ConeGeometry:()=>ee,CubeGeometry:()=>ie,CylinderGeometry:()=>se,GPUGeometry:()=>lt,Geometry:()=>D,GroupNode:()=>mt,IcoSphereGeometry:()=>ne,KeyFrames:()=>Nt,LegacyPickingManager:()=>de,Model:()=>q,ModelNode:()=>te,PickingManager:()=>It,PipelineFactory:()=>Z,PlaneGeometry:()=>re,ScenegraphNode:()=>et,ShaderFactory:()=>Q,ShaderInputs:()=>Y,ShaderPassRenderer:()=>ce,SphereGeometry:()=>oe,Swap:()=>gt,SwapBuffers:()=>ae,SwapFramebuffers:()=>xt,TextureTransform:()=>qt,Timeline:()=>Lt,TruncatedConeGeometry:()=>st,cancelAnimationFramePolyfill:()=>Dt,colorPicking:()=>Ni,indexPicking:()=>Li,loadImage:()=>Ye,loadImageBitmap:()=>jt,makeAnimationLoop:()=>De,makeRandomGenerator:()=>Ri,requestAnimationFramePolyfill:()=>zt,setPathPrefix:()=>He});kt(St,L(j(),1));var Yi=1,Xi=1,Lt=class{time=0;channels=new Map;animations=new Map;playing=!1;lastEngineTime=-1;constructor(){}addChannel(t){let{delay:e=0,duration:s=Number.POSITIVE_INFINITY,rate:n=1,repeat:r=1}=t,o=Yi++,a={time:0,delay:e,duration:s,rate:n,repeat:r};return this._setChannelTime(a,this.time),this.channels.set(o,a),o}removeChannel(t){this.channels.delete(t);for(let[e,s]of this.animations)s.channel===t&&this.detachAnimation(e)}isFinished(t){let e=this.channels.get(t);return e===void 0?!1:this.time>=e.delay+e.duration*e.repeat}getTime(t){if(t===void 0)return this.time;let e=this.channels.get(t);return e===void 0?-1:e.time}setTime(t){this.time=Math.max(0,t);let e=this.channels.values();for(let n of e)this._setChannelTime(n,this.time);let s=this.animations.values();for(let n of s){let{animation:r,channel:o}=n;r.setTime(this.getTime(o))}}play(){this.playing=!0}pause(){this.playing=!1,this.lastEngineTime=-1}reset(){this.setTime(0)}attachAnimation(t,e){let s=Xi++;return this.animations.set(s,{animation:t,channel:e}),t.setTime(this.getTime(e)),s}detachAnimation(t){this.animations.delete(t)}update(t){this.playing&&(this.lastEngineTime===-1&&(this.lastEngineTime=t),this.setTime(this.time+(t-this.lastEngineTime)),this.lastEngineTime=t)}_setChannelTime(t,e){let s=e-t.delay,n=t.duration*t.repeat;s>=n?t.time=t.duration*t.rate:(t.time=Math.max(0,s)%t.duration,t.time*=t.rate)}};var Nt=class{startIndex=-1;endIndex=-1;factor=0;times=[];values=[];_lastTime=-1;constructor(t){this.setKeyFrames(t),this.setTime(0)}setKeyFrames(t){let e=t.length;this.times.length=e,this.values.length=e;for(let s=0;s<e;++s)this.times[s]=t[s][0],this.values[s]=t[s][1];this._calculateKeys(this._lastTime)}setTime(t){t=Math.max(0,t),t!==this._lastTime&&(this._calculateKeys(t),this._lastTime=t)}getStartTime(){return this.times[this.startIndex]}getEndTime(){return this.times[this.endIndex]}getStartData(){return this.values[this.startIndex]}getEndData(){return this.values[this.endIndex]}_calculateKeys(t){let e=0,s=this.times.length;for(e=0;e<s-2&&!(this.times[e+1]>t);++e);this.startIndex=e,this.endIndex=e+1;let n=this.times[this.startIndex],r=this.times[this.endIndex];this.factor=Math.min(Math.max(0,(t-n)/(r-n)),1)}};var Ft=class{constructor(t){}async onInitialize(t){return null}};var Fe=L(j(),1);function zt(i){return typeof window<"u"&&window.requestAnimationFrame?window.requestAnimationFrame(i):setTimeout(i,1e3/60)}function Dt(i){return typeof window<"u"&&window.cancelAnimationFrame?window.cancelAnimationFrame(i):clearTimeout(i)}function Mt(){let i;if(typeof window<"u"&&window.performance)i=window.performance.now();else if(typeof process<"u"&&process.hrtime){let t=process.hrtime();i=t[0]*1e3+t[1]/1e6}else i=Date.now();return i}var nt=class{constructor(t,e){this.sampleSize=1,this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this.name=t,this.type=e,this.reset()}reset(){return this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this}setSampleSize(t){return this.sampleSize=t,this}incrementCount(){return this.addCount(1),this}decrementCount(){return this.subtractCount(1),this}addCount(t){return this._count+=t,this._samples++,this._checkSampling(),this}subtractCount(t){return this._count-=t,this._samples++,this._checkSampling(),this}addTime(t){return this._time+=t,this.lastTiming=t,this._samples++,this._checkSampling(),this}timeStart(){return this._startTime=Mt(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(Mt()-this._startTime),this._timerPending=!1,this._checkSampling(),this):this}getSampleAverageCount(){return this.sampleSize>0?this.lastSampleCount/this.sampleSize:0}getSampleAverageTime(){return this.sampleSize>0?this.lastSampleTime/this.sampleSize:0}getSampleHz(){return this.lastSampleTime>0?this.sampleSize/(this.lastSampleTime/1e3):0}getAverageCount(){return this.samples>0?this.count/this.samples:0}getAverageTime(){return this.samples>0?this.time/this.samples:0}getHz(){return this.time>0?this.samples/(this.time/1e3):0}_checkSampling(){this._samples===this.sampleSize&&(this.lastSampleTime=this._time,this.lastSampleCount=this._count,this.count+=this._count,this.time+=this._time,this.samples+=this._samples,this._time=0,this._count=0,this._samples=0)}};var ct=class{constructor(t){this.stats={},this.id=t.id,this.stats={},this._initializeStats(t.stats),Object.seal(this)}get(t,e="count"){return this._getOrCreate({name:t,type:e})}get size(){return Object.keys(this.stats).length}reset(){for(let t of Object.values(this.stats))t.reset();return this}forEach(t){for(let e of Object.values(this.stats))t(e)}getTable(){let t={};return this.forEach(e=>{t[e.name]={time:e.time||0,count:e.count||0,average:e.getAverageTime()||0,hz:e.getHz()||0}}),t}_initializeStats(t=[]){t.forEach(e=>this._getOrCreate(e))}_getOrCreate(t){let{name:e,type:s}=t,n=this.stats[e];return n||(t instanceof nt?n=t:n=new nt(e,s),this.stats[e]=n),n}};var Ki=0,Zi={device:null,onAddHTML:()=>"",onInitialize:async()=>null,onRender:()=>{},onFinalize:()=>{},onError:i=>console.error(i),stats:Fe.luma.stats.get(`animation-loop-${Ki++}`),useDevicePixels:!0,autoResizeViewport:!1,autoResizeDrawingBuffer:!1},ht=class{device=null;canvas=null;props;animationProps=null;timeline=null;stats;cpuTime;gpuTime;frameRate;display;needsRedraw="initialized";_initialized=!1;_running=!1;_animationFrameId=null;_nextFramePromise=null;_resolveNextFrame=null;_cpuStartTime=0;_error=null;constructor(t){if(this.props={...Zi,...t},t=this.props,!t.device)throw new Error("No device provided");let{useDevicePixels:e=!0}=this.props;this.stats=t.stats||new ct({id:"animation-loop-stats"}),this.cpuTime=this.stats.get("CPU Time"),this.gpuTime=this.stats.get("GPU Time"),this.frameRate=this.stats.get("Frame Rate"),this.setProps({autoResizeViewport:t.autoResizeViewport,autoResizeDrawingBuffer:t.autoResizeDrawingBuffer,useDevicePixels:e}),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this._onMousemove=this._onMousemove.bind(this),this._onMouseleave=this._onMouseleave.bind(this)}destroy(){this.stop(),this._setDisplay(null)}delete(){this.destroy()}setError(t){if(this.props.onError(t),this._error=Error(),this.device?.canvasContext?.canvas instanceof HTMLCanvasElement){let s=document.createElement("h1");s.innerHTML=t.message,s.style.position="absolute",s.style.top="20%",s.style.left="10px",s.style.color="black",s.style.backgroundColor="red",document.body.appendChild(s)}}setNeedsRedraw(t){return this.needsRedraw=this.needsRedraw||t,this}setProps(t){return"autoResizeViewport"in t&&(this.props.autoResizeViewport=t.autoResizeViewport||!1),"autoResizeDrawingBuffer"in t&&(this.props.autoResizeDrawingBuffer=t.autoResizeDrawingBuffer||!1),"useDevicePixels"in t&&(this.props.useDevicePixels=t.useDevicePixels||!1),this}async start(){if(this._running)return this;this._running=!0;try{let t;return this._initialized||(this._initialized=!0,await this._initDevice(),this._initialize(),await this.props.onInitialize(this._getAnimationProps())),this._running?(t!==!1&&(this._cancelAnimationFrame(),this._requestAnimationFrame()),this):null}catch(t){let e=t instanceof Error?t:new Error("Unknown error");throw this.props.onError(e),e}}stop(){return this._running&&(this.animationProps&&!this._error&&this.props.onFinalize(this.animationProps),this._cancelAnimationFrame(),this._nextFramePromise=null,this._resolveNextFrame=null,this._running=!1),this}redraw(){return this.device?.isLost||this._error?this:(this._beginFrameTimers(),this._setupFrame(),this._updateAnimationProps(),this._renderFrame(this._getAnimationProps()),this._clearNeedsRedraw(),this._resolveNextFrame&&(this._resolveNextFrame(this),this._nextFramePromise=null,this._resolveNextFrame=null),this._endFrameTimers(),this)}attachTimeline(t){return this.timeline=t,this.timeline}detachTimeline(){this.timeline=null}waitForRender(){return this.setNeedsRedraw("waitForRender"),this._nextFramePromise||(this._nextFramePromise=new Promise(t=>{this._resolveNextFrame=t})),this._nextFramePromise}async toDataURL(){if(this.setNeedsRedraw("toDataURL"),await this.waitForRender(),this.canvas instanceof HTMLCanvasElement)return this.canvas.toDataURL();throw new Error("OffscreenCanvas")}_initialize(){this._startEventHandling(),this._initializeAnimationProps(),this._updateAnimationProps(),this._resizeCanvasDrawingBuffer(),this._resizeViewport()}_setDisplay(t){this.display&&(this.display.destroy(),this.display.animationLoop=null),t&&(t.animationLoop=this),this.display=t}_requestAnimationFrame(){this._running&&(this._animationFrameId=zt(this._animationFrame.bind(this)))}_cancelAnimationFrame(){this._animationFrameId!==null&&(Dt(this._animationFrameId),this._animationFrameId=null)}_animationFrame(){this._running&&(this.redraw(),this._requestAnimationFrame())}_renderFrame(t){if(this.display){this.display._renderFrame(t);return}this.props.onRender(this._getAnimationProps()),this.device?.submit()}_clearNeedsRedraw(){this.needsRedraw=!1}_setupFrame(){this._resizeCanvasDrawingBuffer(),this._resizeViewport()}_initializeAnimationProps(){let t=this.device?.canvasContext?.canvas;if(!this.device||!t)throw new Error("loop");this.animationProps={animationLoop:this,device:this.device,canvas:t,timeline:this.timeline,useDevicePixels:this.props.useDevicePixels,needsRedraw:!1,width:1,height:1,aspect:1,time:0,startTime:Date.now(),engineTime:0,tick:0,tock:0,_mousePosition:null}}_getAnimationProps(){if(!this.animationProps)throw new Error("animationProps");return this.animationProps}_updateAnimationProps(){if(!this.animationProps)return;let{width:t,height:e,aspect:s}=this._getSizeAndAspect();(t!==this.animationProps.width||e!==this.animationProps.height)&&this.setNeedsRedraw("drawing buffer resized"),s!==this.animationProps.aspect&&this.setNeedsRedraw("drawing buffer aspect changed"),this.animationProps.width=t,this.animationProps.height=e,this.animationProps.aspect=s,this.animationProps.needsRedraw=this.needsRedraw,this.animationProps.engineTime=Date.now()-this.animationProps.startTime,this.timeline&&this.timeline.update(this.animationProps.engineTime),this.animationProps.tick=Math.floor(this.animationProps.time/1e3*60),this.animationProps.tock++,this.animationProps.time=this.timeline?this.timeline.getTime():this.animationProps.engineTime}async _initDevice(){if(this.device=await this.props.device,!this.device)throw new Error("No device provided");this.canvas=this.device.canvasContext?.canvas||null}_createInfoDiv(){if(this.canvas&&this.props.onAddHTML){let t=document.createElement("div");document.body.appendChild(t),t.style.position="relative";let e=document.createElement("div");e.style.position="absolute",e.style.left="10px",e.style.bottom="10px",e.style.width="300px",e.style.background="white",this.canvas instanceof HTMLCanvasElement&&t.appendChild(this.canvas),t.appendChild(e);let s=this.props.onAddHTML(e);s&&(e.innerHTML=s)}}_getSizeAndAspect(){if(!this.device)return{width:1,height:1,aspect:1};let[t,e]=this.device?.canvasContext?.getPixelSize()||[1,1],s=1,n=this.device?.canvasContext?.canvas;return n&&n.clientHeight?s=n.clientWidth/n.clientHeight:t>0&&e>0&&(s=t/e),{width:t,height:e,aspect:s}}_resizeViewport(){this.props.autoResizeViewport&&this.device.gl&&this.device.gl.viewport(0,0,this.device.gl.drawingBufferWidth,this.device.gl.drawingBufferHeight)}_resizeCanvasDrawingBuffer(){this.props.autoResizeDrawingBuffer&&this.device?.canvasContext?.resize({useDevicePixels:this.props.useDevicePixels})}_beginFrameTimers(){this.frameRate.timeEnd(),this.frameRate.timeStart(),this.cpuTime.timeStart()}_endFrameTimers(){this.cpuTime.timeEnd()}_startEventHandling(){this.canvas&&(this.canvas.addEventListener("mousemove",this._onMousemove.bind(this)),this.canvas.addEventListener("mouseleave",this._onMouseleave.bind(this)))}_onMousemove(t){t instanceof MouseEvent&&(this._getAnimationProps()._mousePosition=[t.offsetX,t.offsetY])}_onMouseleave(t){this._getAnimationProps()._mousePosition=null}};var ze=L(j(),1);function De(i,t){let e=null,s=t?.device||ze.luma.createDevice({id:"animation-loop",adapters:t?.adapters,createCanvasContext:!0}),n=new ht({...t,device:s,async onInitialize(r){return e=new i(r),await e?.onInitialize(r)},onRender:r=>e?.onRender(r),onFinalize:r=>e?.onFinalize(r)});return n.getInfo=()=>this.AnimationLoopTemplateCtor.info,n}var w=L(j(),1),Gt=L(rt(),1);var vt=L(j(),1);var ue={};function O(i="id"){ue[i]=ue[i]||1;let t=ue[i]++;return`${i}-${t}`}var lt=class{id;userData={};topology;bufferLayout=[];vertexCount;indices;attributes;constructor(t){if(this.id=t.id||O("geometry"),this.topology=t.topology,this.indices=t.indices||null,this.attributes=t.attributes,this.vertexCount=t.vertexCount,this.bufferLayout=t.bufferLayout||[],this.indices&&!(this.indices.usage&vt.Buffer.INDEX))throw new Error("Index buffer must have INDEX usage")}destroy(){this.indices?.destroy();for(let t of Object.values(this.attributes))t.destroy()}getVertexCount(){return this.vertexCount}getAttributes(){return this.attributes}getIndexes(){return this.indices||null}_calculateVertexCount(t){return t.byteLength/12}};function Ue(i,t){if(t instanceof lt)return t;let e=Qi(i,t),{attributes:s,bufferLayout:n}=Ji(i,t);return new lt({topology:t.topology||"triangle-list",bufferLayout:n,vertexCount:t.vertexCount,indices:e,attributes:s})}function Qi(i,t){if(!t.indices)return;let e=t.indices.value;return i.createBuffer({usage:vt.Buffer.INDEX,data:e})}function Ji(i,t){let e=[],s={};for(let[r,o]of Object.entries(t.attributes)){let a=r;switch(r){case"POSITION":a="positions";break;case"NORMAL":a="normals";break;case"TEXCOORD_0":a="texCoords";break;case"COLOR_0":a="colors";break}if(o){s[a]=i.createBuffer({data:o.value,id:`${r}-buffer`});let{value:c,size:h,normalized:l}=o;e.push({name:a,format:(0,vt.getVertexFormatFromAttribute)(c,h,l)})}}let n=t._calculateVertexCount(t.attributes,t.indices);return{attributes:s,bufferLayout:e,vertexCount:n}}var ft=L(j(),1);var pe=class{static getDefaultPipelineFactory(t){return t._lumaData.defaultPipelineFactory=t._lumaData.defaultPipelineFactory||new pe(t),t._lumaData.defaultPipelineFactory}device;destroyPolicy;_hashCounter=0;_hashes={};_renderPipelineCache={};_computePipelineCache={};constructor(t){this.device=t,this.destroyPolicy=t.props._factoryDestroyPolicy}createRenderPipeline(t){let e={...ft.RenderPipeline.defaultProps,...t},s=this._hashRenderPipeline(e);if(!this._renderPipelineCache[s]){let n=this.device.createRenderPipeline({...e,id:e.id?`${e.id}-cached`:void 0});n.hash=s,this._renderPipelineCache[s]={pipeline:n,useCount:0}}return this._renderPipelineCache[s].useCount++,this._renderPipelineCache[s].pipeline}createComputePipeline(t){let e={...ft.ComputePipeline.defaultProps,...t},s=this._hashComputePipeline(e);if(!this._computePipelineCache[s]){let n=this.device.createComputePipeline({...e,id:e.id?`${e.id}-cached`:void 0});n.hash=s,this._computePipelineCache[s]={pipeline:n,useCount:0}}return this._computePipelineCache[s].useCount++,this._computePipelineCache[s].pipeline}release(t){let e=t.hash,s=t instanceof ft.ComputePipeline?this._computePipelineCache:this._renderPipelineCache;s[e].useCount--,s[e].useCount===0&&this.destroyPolicy==="unused"&&(s[e].pipeline.destroy(),delete s[e])}_hashComputePipeline(t){return`${this._getHash(t.shader.source)}`}_hashRenderPipeline(t){let e=t.vs?this._getHash(t.vs.source):0,s=t.fs?this._getHash(t.fs.source):0,n="-",r=this._getHash(JSON.stringify(t.bufferLayout));switch(this.device.type){case"webgl":return`${e}/${s}V${n}BL${r}`;default:let o=this._getHash(JSON.stringify(t.parameters));return`${e}/${s}V${n}T${t.topology}P${o}BL${r}`}}_getHash(t){return this._hashes[t]===void 0&&(this._hashes[t]=this._hashCounter++),this._hashes[t]}},Z=pe;V(Z,"defaultProps",{...ft.RenderPipeline.defaultProps});var $e=L(j(),1);var me=class{static getDefaultShaderFactory(t){return t._lumaData.defaultShaderFactory||=new me(t),t._lumaData.defaultShaderFactory}device;destroyPolicy;_cache={};constructor(t){this.device=t,this.destroyPolicy=t.props._factoryDestroyPolicy}createShader(t){let e=this._hashShader(t),s=this._cache[e];if(!s){let n=this.device.createShader({...t,id:t.id?`${t.id}-cached`:void 0});this._cache[e]=s={shader:n,useCount:0}}return s.useCount++,s.shader}release(t){let e=this._hashShader(t),s=this._cache[e];s&&(s.useCount--,s.useCount===0&&this.destroyPolicy==="unused"&&(delete this._cache[e],s.shader.destroy()))}_hashShader(t){return`${t.stage}:${t.source}`}},Q=me;V(Q,"defaultProps",{...$e.Shader.defaultProps});function je(i,t){let e={},s="Values";if(i.attributes.length===0&&!i.varyings?.length)return{"No attributes or varyings":{[s]:"N/A"}};for(let n of i.attributes)if(n){let r=`${n.location} ${n.name}: ${n.type}`;e[`in ${r}`]={[s]:n.stepMode||"vertex"}}for(let n of i.varyings||[]){let r=`${n.location} ${n.name}`;e[`out ${r}`]={[s]:JSON.stringify(n)}}return e}var N=null,ge=null;function Ge(i,{id:t,minimap:e,opaque:s,top:n="0",left:r="0",rgbaScale:o=1}){N||(N=document.createElement("canvas"),N.id=t,N.title=t,N.style.zIndex="100",N.style.position="absolute",N.style.top=n,N.style.left=r,N.style.border="blue 5px solid",N.style.transform="scaleY(-1)",document.body.appendChild(N),ge=N.getContext("2d")),(N.width!==i.width||N.height!==i.height)&&(N.width=i.width/2,N.height=i.height/2,N.style.width="400px",N.style.height="400px");let a=i.device.readPixelsToArrayWebGL(i),c=ge?.createImageData(i.width,i.height);if(c){for(let l=0;l<a.length;l+=4)c.data[0+l+0]=a[l+0]*o,c.data[0+l+1]=a[l+1]*o,c.data[0+l+2]=a[l+2]*o,c.data[0+l+3]=s?255:a[l+3]*o;ge?.putImageData(c,0,0)}}function Bt(i,t,e){if(i===t)return!0;if(!e||!i||!t)return!1;if(Array.isArray(i)){if(!Array.isArray(t)||i.length!==t.length)return!1;for(let s=0;s<i.length;s++)if(!Bt(i[s],t[s],e-1))return!1;return!0}if(Array.isArray(t))return!1;if(typeof i=="object"&&typeof t=="object"){let s=Object.keys(i),n=Object.keys(t);if(s.length!==n.length)return!1;for(let r of s)if(!t.hasOwnProperty(r)||!Bt(i[r],t[r],e-1))return!1;return!0}return!1}var $t=L(j(),1),We=L(rt(),1);function Ve(i){return ArrayBuffer.isView(i)&&!(i instanceof DataView)}function qe(i){return Array.isArray(i)?i.length===0||typeof i[0]=="number":!1}function _t(i){return Ve(i)||qe(i)}function ts(i){return _t(i)||typeof i=="number"||typeof i=="boolean"}function Ut(i){let t={bindings:{},uniforms:{}};return Object.keys(i).forEach(e=>{let s=i[e];ts(s)?t.uniforms[e]=s:t.bindings[e]=s}),t}var Y=class{options={disableWarnings:!1};modules;moduleUniforms;moduleBindings;constructor(t,e){Object.assign(this.options,e);let s=(0,We.getShaderModuleDependencies)(Object.values(t).filter(n=>n.dependencies));for(let n of s)t[n.name]=n;$t.log.log(1,"Creating ShaderInputs with modules",Object.keys(t))(),this.modules=t,this.moduleUniforms={},this.moduleBindings={};for(let[n,r]of Object.entries(t))this._addModule(r),r.name&&n!==r.name&&!this.options.disableWarnings&&$t.log.warn(`Module name: ${n} vs ${r.name}`)()}destroy(){}setProps(t){for(let e of Object.keys(t)){let s=e,n=t[s]||{},r=this.modules[s];if(!r){this.options.disableWarnings||$t.log.warn(`Module ${e} not found`)();continue}let o=this.moduleUniforms[s],a=this.moduleBindings[s],c=r.getUniforms?.(n,o)||n,{uniforms:h,bindings:l}=Ut(c);this.moduleUniforms[s]={...o,...h},this.moduleBindings[s]={...a,...l}}}getModules(){return Object.values(this.modules)}getUniformValues(){return this.moduleUniforms}getBindingValues(){let t={};for(let e of Object.values(this.moduleBindings))Object.assign(t,e);return t}getDebugTable(){let t={};for(let[e,s]of Object.entries(this.moduleUniforms))for(let[n,r]of Object.entries(s))t[`${e}.${n}`]={type:this.modules[e].uniformTypes?.[n],value:String(r)};return t}_addModule(t){let e=t.name;this.moduleUniforms[e]=t.defaultUniforms||{},this.moduleBindings[e]={}}};var xe="";function He(i){xe=i}async function jt(i,t){let e=new Image;return e.crossOrigin=t?.crossOrigin||"anonymous",e.src=i.startsWith("http")?i:xe+i,await e.decode(),t?await createImageBitmap(e,t):await createImageBitmap(e)}async function Ye(i,t){return await new Promise((e,s)=>{try{let n=new Image;n.onload=()=>e(n),n.onerror=()=>s(new Error(`Could not load image ${i}.`)),n.crossOrigin=t?.crossOrigin||"anonymous",n.src=i.startsWith("http")?i:xe+i}catch(n){s(n)}})}var it=class{device;id;texture;sampler;view;ready;isReady=!1;destroyed=!1;resolveReady=()=>{};rejectReady=()=>{};get[Symbol.toStringTag](){return"AsyncTexture"}toString(){return`AsyncTexture:"${this.id}"(${this.isReady?"ready":"loading"})`}constructor(t,e){this.device=t,this.id=e.id||O("async-texture"),typeof e?.data=="string"&&e.dimension==="2d"&&(e={...e,data:jt(e.data)}),this.ready=new Promise((s,n)=>{this.resolveReady=()=>{this.isReady=!0,s()},this.rejectReady=n}),this.initAsync(e)}async initAsync(t){let e=t.data,s;try{s=await Xe(e)}catch(r){this.rejectReady(r)}if(this.destroyed)return;let n={...t,data:s};this.texture=this.device.createTexture(n),this.sampler=this.texture.sampler,this.view=this.texture.view,this.isReady=!0,this.resolveReady()}destroy(){this.texture&&(this.texture.destroy(),this.texture=null),this.destroyed=!0}resize(t){if(!this.isReady)throw new Error("Cannot resize texture before it is ready");if(t.width===this.texture.width&&t.height===this.texture.height)return!1;if(this.texture){let e=this.texture;this.texture=e.clone(t),e.destroy()}return!0}};async function Xe(i){if(i=await i,Array.isArray(i))return await Promise.all(i.map(Xe));if(i&&typeof i=="object"&&i.constructor===Object){let t=i,e=await Promise.all(Object.values(t)),s=Object.keys(t),n={};for(let r=0;r<s.length;r++)n[s[r]]=e[r];return n}return i}var ot=2,es=1e4,be=class{device;id;source;vs;fs;pipelineFactory;shaderFactory;userData={};parameters;topology;bufferLayout;isInstanced=void 0;instanceCount=0;vertexCount;indexBuffer=null;bufferAttributes={};constantAttributes={};bindings={};uniforms={};vertexArray;transformFeedback=null;pipeline;shaderInputs;_uniformStore;_attributeInfos={};_gpuGeometry=null;_getModuleUniforms;props;_pipelineNeedsUpdate="newly created";_needsRedraw="initializing";_destroyed=!1;_lastDrawTimestamp=-1;get[Symbol.toStringTag](){return"Model"}toString(){return`Model(${this.id})`}constructor(t,e){this.props={...be.defaultProps,...e},e=this.props,this.id=e.id||O("model"),this.device=t,Object.assign(this.userData,e.userData);let s=Object.fromEntries(this.props.modules?.map(c=>[c.name,c])||[]),n=e.shaderInputs||new Y(s,{disableWarnings:this.props.disableWarnings});this.setShaderInputs(n);let r=ss(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:r,...this.props,modules:o});this.source=c,this._getModuleUniforms=h,this.props.shaderLayout||=(0,Gt.getShaderLayoutFromWGSL)(this.source)}else{let{vs:c,fs:h,getUniforms:l}=this.props.shaderAssembler.assembleGLSLShaderPair({platformInfo:r,...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||Z.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||Q.getDefaultShaderFactory(this.device),this.pipeline=this._updatePipeline(),this.vertexArray=t.createVertexArray({renderPipeline:this.pipeline}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry),"isInstanced"in e&&(this.isInstanced=e.isInstanced),e.instanceCount&&this.setInstanceCount(e.instanceCount),e.vertexCount&&this.setVertexCount(e.vertexCount),e.indexBuffer&&this.setIndexBuffer(e.indexBuffer),e.attributes&&this.setAttributes(e.attributes),e.constantAttributes&&this.setConstantAttributes(e.constantAttributes),e.bindings&&this.setBindings(e.bindings),e.uniforms&&this.setUniformsWebGL(e.uniforms),e.moduleSettings&&this.updateModuleSettingsWebGL(e.moduleSettings),e.transformFeedback&&(this.transformFeedback=e.transformFeedback),Object.seal(this)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.pipeline.vs),this.pipeline.fs&&this.shaderFactory.release(this.pipeline.fs),this._uniformStore.destroy(),this._gpuGeometry?.destroy(),this._destroyed=!0)}needsRedraw(){this._getBindingsUpdateTimestamp()>this._lastDrawTimestamp&&this.setNeedsRedraw("contents of bound textures or buffers updated");let t=this._needsRedraw;return this._needsRedraw=!1,t}setNeedsRedraw(t){this._needsRedraw||=t}predraw(){this.updateShaderInputs(),this.pipeline=this._updatePipeline()}draw(t){let e=this._areBindingsLoading();if(e)return w.log.info(ot,`>>> DRAWING ABORTED ${this.id}: ${e} not loaded`)(),!1;try{t.pushDebugGroup(`${this}.predraw(${t})`),this.predraw()}finally{t.popDebugGroup()}let s;try{t.pushDebugGroup(`${this}.draw(${t})`),this._logDrawCallStart(),this.pipeline=this._updatePipeline();let n=this._getBindings();this.pipeline.setBindings(n,{disableWarnings:this.props.disableWarnings}),ye(this.uniforms)||this.pipeline.setUniformsWebGL(this.uniforms);let{indexBuffer:r}=this.vertexArray,o=r?r.byteLength/(r.indexType==="uint32"?4:2):void 0;s=this.pipeline.draw({renderPass:t,vertexArray:this.vertexArray,isInstanced:this.isInstanced,vertexCount:this.vertexCount,instanceCount:this.instanceCount,indexCount:o,transformFeedback:this.transformFeedback||void 0,parameters:this.parameters,topology:this.topology})}finally{t.popDebugGroup(),this._logDrawCallEnd()}return this._logFramebuffer(t),s?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):this._needsRedraw="waiting for resource initialization",s}setGeometry(t){this._gpuGeometry?.destroy();let e=t&&Ue(this.device,t);if(e){this.setTopology(e.topology||"triangle-list");let s=new w._BufferLayoutHelper(this.bufferLayout);this.bufferLayout=s.mergeBufferLayouts(e.bufferLayout,this.bufferLayout),this.vertexArray&&this._setGeometryAttributes(e)}this._gpuGeometry=e}setTopology(t){t!==this.topology&&(this.topology=t,this._setPipelineNeedsUpdate("topology"))}setBufferLayout(t){let e=new w._BufferLayoutHelper(this.bufferLayout);this.bufferLayout=this._gpuGeometry?e.mergeBufferLayouts(t,this._gpuGeometry.bufferLayout):t,this._setPipelineNeedsUpdate("bufferLayout"),this.pipeline=this._updatePipeline(),this.vertexArray=this.device.createVertexArray({renderPipeline:this.pipeline}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry)}setParameters(t){Bt(t,this.parameters,2)||(this.parameters=t,this._setPipelineNeedsUpdate("parameters"))}setInstanceCount(t){this.instanceCount=t,this.isInstanced===void 0&&t>0&&(this.isInstanced=!0),this.setNeedsRedraw("instanceCount")}setVertexCount(t){this.vertexCount=t,this.setNeedsRedraw("vertexCount")}setShaderInputs(t){this.shaderInputs=t,this._uniformStore=new w.UniformStore(this.shaderInputs.modules);for(let[e,s]of Object.entries(this.shaderInputs.modules))if(is(s)){let n=this._uniformStore.getManagedUniformBuffer(this.device,e);this.bindings[`${e}Uniforms`]=n}this.setNeedsRedraw("shaderInputs")}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues()),this.setBindings(this.shaderInputs.getBindingValues()),this.setNeedsRedraw("shaderInputs")}setBindings(t){Object.assign(this.bindings,t),this.setNeedsRedraw("bindings")}setTransformFeedback(t){this.transformFeedback=t,this.setNeedsRedraw("transformFeedback")}setIndexBuffer(t){this.vertexArray.setIndexBuffer(t),this.setNeedsRedraw("indexBuffer")}setAttributes(t,e){let s=e?.disableWarnings??this.props.disableWarnings;t.indices&&w.log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)(),this.bufferLayout=(0,w.sortedBufferLayoutByShaderSourceLocations)(this.pipeline.shaderLayout,this.bufferLayout);let n=new w._BufferLayoutHelper(this.bufferLayout);for(let[r,o]of Object.entries(t)){let a=n.getBufferLayout(r);if(!a){s||w.log.warn(`Model(${this.id}): Missing layout for buffer "${r}".`)();continue}let c=n.getAttributeNamesForBuffer(a),h=!1;for(let l of c){let f=this._attributeInfos[l];if(f){let d=this.device.type==="webgpu"?n.getBufferIndex(f.bufferName):f.location;this.vertexArray.setBuffer(d,o),h=!0}}!h&&!s&&w.log.warn(`Model(${this.id}): Ignoring buffer "${o.id}" for unknown attribute "${r}"`)()}this.setNeedsRedraw("attributes")}setConstantAttributes(t,e){for(let[s,n]of Object.entries(t)){let r=this._attributeInfos[s];r?this.vertexArray.setConstantWebGL(r.location,n):(e?.disableWarnings??this.props.disableWarnings)||w.log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${s}"`)()}this.setNeedsRedraw("constants")}setUniforms(t){this.setUniformsWebGL(t)}setUniformsWebGL(t){ye(t)||(this.pipeline.setUniformsWebGL(t),Object.assign(this.uniforms,t)),this.setNeedsRedraw("uniforms")}updateModuleSettingsWebGL(t){let{bindings:e,uniforms:s}=Ut(this._getModuleUniforms(t));Object.assign(this.bindings,e),Object.assign(this.uniforms,s),this.setNeedsRedraw("moduleSettings")}_areBindingsLoading(){for(let t of Object.values(this.bindings))if(t instanceof it&&!t.isReady)return t.id;return!1}_getBindings(){let t={};for(let[e,s]of Object.entries(this.bindings))s instanceof it?s.isReady&&(t[e]=s.texture):t[e]=s;return t}_getBindingsUpdateTimestamp(){let t=0;for(let e of Object.values(this.bindings))e instanceof w.TextureView?t=Math.max(t,e.texture.updateTimestamp):e instanceof w.Buffer||e instanceof w.Texture?t=Math.max(t,e.updateTimestamp):e instanceof it?t=e.texture?Math.max(t,e.texture.updateTimestamp):1/0:e instanceof w.Sampler||(t=Math.max(t,e.buffer.updateTimestamp));return t}_setGeometryAttributes(t){let e={...t.attributes};for(let[s]of Object.entries(e))!this.pipeline.shaderLayout.attributes.find(n=>n.name===s)&&s!=="positions"&&delete e[s];this.vertexCount=t.vertexCount,this.setIndexBuffer(t.indices||null),this.setAttributes(t.attributes,{disableWarnings:!0}),this.setAttributes(e,{disableWarnings:this.props.disableWarnings}),this.setNeedsRedraw("geometry attributes")}_setPipelineNeedsUpdate(t){this._pipelineNeedsUpdate||=t,this.setNeedsRedraw(t)}_updatePipeline(){if(this._pipelineNeedsUpdate){let t=null,e=null;this.pipeline&&(w.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),t=this.pipeline.vs,e=this.pipeline.fs),this._pipelineNeedsUpdate=!1;let s=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:"vertex",source:this.source||this.vs,debugShaders:this.props.debugShaders}),n=null;this.source?n=s:this.fs&&(n=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"fragment",source:this.source||this.fs,debugShaders:this.props.debugShaders})),this.pipeline=this.pipelineFactory.createRenderPipeline({...this.props,bufferLayout:this.bufferLayout,topology:this.topology,parameters:this.parameters,bindings:this._getBindings(),vs:s,fs:n}),this._attributeInfos=(0,w.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=w.log.level>3?0:es;w.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,w.log.group(ot,`>>> DRAWING MODEL ${this.id}`,{collapsed:w.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=je(this.pipeline.shaderLayout,this.id);w.log.table(ot,t)();let e=this.shaderInputs.getDebugTable();for(let[n,r]of Object.entries(this.uniforms))e[n]={value:r};w.log.table(ot,e)();let s=this._getAttributeDebugTable();w.log.table(ot,this._attributeInfos)(),w.log.table(ot,s)(),w.log.groupEnd(ot)(),this._logOpen=!1}}_drawCount=0;_logFramebuffer(t){let e=this.device.props.debugFramebuffers;if(this._drawCount++,!e)return;let s=t.props.framebuffer;s&&Ge(s,{id:s.id,minimap:!0})}_getAttributeDebugTable(){let t={};for(let[e,s]of Object.entries(this._attributeInfos)){let n=this.vertexArray.attributes[s.location];t[s.location]={name:e,type:s.shaderType,values:n?this._getBufferOrConstantValues(n,s.bufferDataType):"null"}}if(this.vertexArray.indexBuffer){let{indexBuffer:e}=this.vertexArray,s=e.indexType==="uint32"?new Uint32Array(e.debugData):new Uint16Array(e.debugData);t.indices={name:"indices",type:e.indexType,values:s.toString()}}return t}_getBufferOrConstantValues(t,e){let s=(0,w.getTypedArrayFromDataType)(e);return(t instanceof w.Buffer?new s(t.debugData):t).toString()}},q=be;V(q,"defaultProps",{...w.RenderPipeline.defaultProps,source:void 0,vs:null,fs:null,id:"unnamed",handle:void 0,userData:{},defines:{},modules:[],moduleSettings:void 0,geometry:null,indexBuffer:null,attributes:{},constantAttributes:{},varyings:[],isInstanced:void 0,instanceCount:0,vertexCount:0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,transformFeedback:void 0,shaderAssembler:Gt.ShaderAssembler.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0});function is(i){return Boolean(i.uniformTypes&&!ye(i.uniformTypes))}function ss(i){return{type:i.type,shaderLanguage:i.info.shadingLanguage,shaderLanguageVersion:i.info.shadingLanguageVersion,gpu:i.info.gpu,features:i.features}}function ye(i){for(let t in i)return!1;return!0}var Ke=L(j(),1),Ze=L(rt(),1);var Vt=class{device;model;transformFeedback;static isSupported(t){return t?.info?.type==="webgl"}constructor(t,e=Vt.defaultProps){if(!Vt.isSupported(t))throw new Error("BufferTransform not yet implemented on WebGPU");this.device=t,this.model=new q(this.device,{id:e.id||"buffer-transform-model",fs:e.fs||(0,Ze.getPassthroughFS)(),topology:e.topology||"point-list",varyings:e.outputs||e.varyings,...e}),this.transformFeedback=this.device.createTransformFeedback({layout:this.model.pipeline.shaderLayout,buffers:e.feedbackBuffers}),this.model.setTransformFeedback(this.transformFeedback),Object.seal(this)}destroy(){this.model&&this.model.destroy()}delete(){this.destroy()}run(t){t?.inputBuffers&&this.model.setAttributes(t.inputBuffers),t?.outputBuffers&&this.transformFeedback.setBuffers(t.outputBuffers);let e=this.device.beginRenderPass(t);this.model.draw(e),e.end()}getBuffer(t){return this.transformFeedback.getBuffer(t)}readAsync(t){let e=this.getBuffer(t);if(!e)throw new Error("BufferTransform#getBuffer");if(e instanceof Ke.Buffer)return e.readAsync();let{buffer:s,byteOffset:n=0,byteLength:r=s.byteLength}=e;return s.readAsync(n,r)}},At=Vt;V(At,"defaultProps",{...q.defaultProps,outputs:void 0,feedbackBuffers:void 0});var Qe=L(rt(),1),ns="transform_output",qt=class{device;model;sampler;currentIndex=0;samplerTextureMap=null;bindings=[];resources={};constructor(t,e){this.device=t,this.sampler=t.createSampler({addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",minFilter:"nearest",magFilter:"nearest",mipmapFilter:"nearest"}),this.model=new q(this.device,{id:e.id||"texture-transform-model",fs:e.fs||(0,Qe.getPassthroughFS)({input:e.targetTextureVarying,inputChannels:e.targetTextureChannels,output:ns}),vertexCount:e.vertexCount,...e}),this._initialize(e),Object.seal(this)}destroy(){this.model.destroy();for(let t of this.bindings)t.framebuffer?.destroy()}delete(){this.destroy()}run(t){let{framebuffer:e}=this.bindings[this.currentIndex],s=this.device.beginRenderPass({framebuffer:e,...t});this.model.draw(s),s.end()}getTargetTexture(){let{targetTexture:t}=this.bindings[this.currentIndex];return t}getFramebuffer(){return this.bindings[this.currentIndex].framebuffer}_initialize(t){this._updateBindings(t)}_updateBindings(t){this.bindings[this.currentIndex]=this._updateBinding(this.bindings[this.currentIndex],t)}_updateBinding(t,{sourceBuffers:e,sourceTextures:s,targetTexture:n}){if(t||(t={sourceBuffers:{},sourceTextures:{},targetTexture:null}),Object.assign(t.sourceTextures,s),Object.assign(t.sourceBuffers,e),n){t.targetTexture=n;let{width:r,height:o}=n;t.framebuffer&&t.framebuffer.destroy(),t.framebuffer=this.device.createFramebuffer({id:"transform-framebuffer",width:r,height:o,colorAttachments:[n]}),t.framebuffer.resize({width:r,height:o})}return t}_setSourceTextureParameters(){let t=this.currentIndex,{sourceTextures:e}=this.bindings[t];for(let s in e)e[s].sampler=this.sampler}};var D=class{id;topology;vertexCount;indices;attributes;userData={};constructor(t){let{attributes:e={},indices:s=null,vertexCount:n=null}=t;this.id=t.id||O("geometry"),this.topology=t.topology,s&&(this.indices=ArrayBuffer.isView(s)?{value:s,size:1}:s),this.attributes={};for(let[r,o]of Object.entries(e)){let a=ArrayBuffer.isView(o)?{value:o}:o;if(!ArrayBuffer.isView(a.value))throw new Error(`${this._print(r)}: must be typed array or object with value as typed array`);if((r==="POSITION"||r==="positions")&&!a.size&&(a.size=3),r==="indices"){if(this.indices)throw new Error("Multiple indices detected");this.indices=a}else this.attributes[r]=a}this.indices&&this.indices.isIndexed!==void 0&&(this.indices=Object.assign({},this.indices),delete this.indices.isIndexed),this.vertexCount=n||this._calculateVertexCount(this.attributes,this.indices)}getVertexCount(){return this.vertexCount}getAttributes(){return this.indices?{indices:this.indices,...this.attributes}:this.attributes}_print(t){return`Geometry ${this.id} attribute ${t}`}_setAttributes(t,e){return this}_calculateVertexCount(t,e){if(e)return e.value.length;let s=1/0;for(let n of Object.values(t)){let{value:r,size:o,constant:a}=n;!a&&r&&o!==void 0&&o>=1&&(s=Math.min(s,r.length/o))}return s}};var rs=`struct VertexInputs {
8
8
  @location(0) clipSpacePosition: vec2<f32>,
9
9
  @location(1) texCoord: vec2<f32>,
10
10
  @location(2) coordinate: vec2<f32>
@@ -74,7 +74,7 @@ void main(void) {
74
74
  vec2 position = billboardTexture_getTextureUV();
75
75
  fragColor = texture(backgroundTexture, position);
76
76
  }
77
- `,at=class extends J{constructor(t,e){super(t,{id:e.id||"background-texture-model",source:as,fs:cs,parameters:{depthWriteEnabled:!1,depthCompare:"always",...e.blend?{blend:!0,blendColorOperation:"add",blendAlphaOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one-minus-src-color",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one-minus-src-alpha"}:{}}}),this.setTexture(e.backgroundTexture)}setTexture(t){this.setBindings({backgroundTexture:t})}predraw(){this.shaderInputs.setProps({}),super.predraw()}};var xr=1/Math.PI*180,yr=1/180*Math.PI,hs={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...hs}};var z=globalThis.mathgl.config;function ti(i,{precision:t=z.precision}={}){return i=ls(i),`${parseFloat(i.toPrecision(t))}`}function dt(i){return Array.isArray(i)||ArrayBuffer.isView(i)&&!(i instanceof DataView)}function Me(i,t,e){let s=z.EPSILON;e&&(z.EPSILON=e);try{if(i===t)return!0;if(dt(i)&&dt(t)){if(i.length!==t.length)return!1;for(let n=0;n<i.length;++n)if(!Me(i[n],t[n]))return!1;return!0}return i&&i.equals?i.equals(t):t&&t.equals?t.equals(i):typeof i=="number"&&typeof t=="number"?Math.abs(i-t)<=z.EPSILON*Math.max(1,Math.abs(i),Math.abs(t)):!1}finally{z.EPSILON=s}}function ls(i){return Math.round(i/z.EPSILON)*z.EPSILON}var ut=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,e=0){for(let s=0;s<this.ELEMENTS;++s)this[s]=t[s+e];return this.check()}toArray(t=[],e=0){for(let s=0;s<this.ELEMENTS;++s)t[e+s]=this[s];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:dt(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(z)}formatString(t){let e="";for(let s=0;s<this.ELEMENTS;++s)e+=(s>0?", ":"")+ti(this[s],t);return`${t.printTypes?this.constructor.name:""}[${e}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let e=0;e<this.ELEMENTS;++e)if(!Me(this[e],t[e]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let e=0;e<this.ELEMENTS;++e)if(this[e]!==t[e])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,e,s){if(s===void 0)return this.lerp(this,t,e);for(let n=0;n<this.ELEMENTS;++n){let r=t[n],o=typeof e=="number"?e:e[n];this[n]=r+s*(o-r)}return this.check()}min(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=Math.min(t[e],this[e]);return this.check()}max(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=Math.max(t[e],this[e]);return this.check()}clamp(t,e){for(let s=0;s<this.ELEMENTS;++s)this[s]=Math.min(Math.max(this[s],t[s]),e[s]);return this.check()}add(...t){for(let e of t)for(let s=0;s<this.ELEMENTS;++s)this[s]+=e[s];return this.check()}subtract(...t){for(let e of t)for(let s=0;s<this.ELEMENTS;++s)this[s]-=e[s];return this.check()}scale(t){if(typeof t=="number")for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;else for(let e=0;e<this.ELEMENTS&&e<t.length;++e)this[e]*=t[e];return this.check()}multiplyByScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;return this.check()}check(){if(z.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let e=0;e<this.ELEMENTS;++e)t=t&&Number.isFinite(this[e]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=t;return this.check()}addScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,e){for(let s=0;s<this.ELEMENTS;++s)this[s]=Math.min(Math.max(this[s],t),e);return this.check()}get elements(){return this}};function fs(i,t){if(i.length!==t)return!1;for(let e=0;e<i.length;++e)if(!Number.isFinite(i[e]))return!1;return!0}function B(i){if(!Number.isFinite(i))throw new Error(`Invalid number ${JSON.stringify(i)}`);return i}function Wt(i,t,e=""){if(z.debug&&!fs(i,t))throw new Error(`math.gl: ${e} some fields set to invalid numbers'`);return i}function ve(i,t){if(!i)throw new Error(`math.gl assertion ${t}`)}var Ht=class extends ut{get x(){return this[0]}set x(t){this[0]=B(t)}get y(){return this[1]}set y(t){this[1]=B(t)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let t=0;for(let e=0;e<this.ELEMENTS;++e)t+=this[e]*this[e];return t}magnitudeSquared(){return this.lengthSquared()}distance(t){return Math.sqrt(this.distanceSquared(t))}distanceSquared(t){let e=0;for(let s=0;s<this.ELEMENTS;++s){let n=this[s]-t[s];e+=n*n}return B(e)}dot(t){let e=0;for(let s=0;s<this.ELEMENTS;++s)e+=this[s]*t[s];return B(e)}normalize(){let t=this.magnitude();if(t!==0)for(let e=0;e<this.ELEMENTS;++e)this[e]/=t;return this.check()}multiply(...t){for(let e of t)for(let s=0;s<this.ELEMENTS;++s)this[s]*=e[s];return this.check()}divide(...t){for(let e of t)for(let s=0;s<this.ELEMENTS;++s)this[s]/=e[s];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(t){return this.distance(t)}distanceToSquared(t){return this.distanceSquared(t)}getComponent(t){return ve(t>=0&&t<this.ELEMENTS,"index is out of range"),B(this[t])}setComponent(t,e){return ve(t>=0&&t<this.ELEMENTS,"index is out of range"),this[t]=e,this.check()}addVectors(t,e){return this.copy(t).add(e)}subVectors(t,e){return this.copy(t).subtract(e)}multiplyVectors(t,e){return this.copy(t).multiply(e)}addScaledVector(t,e){return this.add(new this.constructor(t).multiplyScalar(e))}};var tt=typeof Float32Array<"u"?Float32Array:Array;var Cr=Math.PI/180;function ds(){let i=new tt(2);return tt!=Float32Array&&(i[0]=0,i[1]=0),i}function si(i,t,e){let s=t[0],n=t[1];return i[0]=e[0]*s+e[4]*n+e[12],i[1]=e[1]*s+e[5]*n+e[13],i}var Or=function(){let i=ds();return function(t,e,s,n,r,o){let a,c;for(e||(e=2),s||(s=0),n?c=Math.min(n*e+s,t.length):c=t.length,a=s;a<c;a+=e)i[0]=t[a],i[1]=t[a+1],r(i,i,o),t[a]=i[0],t[a+1]=i[1];return t}}();function ni(i,t,e){let s=t[0],n=t[1],r=e[3]*s+e[7]*n||1;return i[0]=(e[0]*s+e[4]*n)/r,i[1]=(e[1]*s+e[5]*n)/r,i}function Yt(i,t,e){let s=t[0],n=t[1],r=t[2],o=e[3]*s+e[7]*n+e[11]*r||1;return i[0]=(e[0]*s+e[4]*n+e[8]*r)/o,i[1]=(e[1]*s+e[5]*n+e[9]*r)/o,i[2]=(e[2]*s+e[6]*n+e[10]*r)/o,i}function ri(i,t,e){let s=t[0],n=t[1];return i[0]=e[0]*s+e[2]*n,i[1]=e[1]*s+e[3]*n,i[2]=t[2],i}function us(){let i=new tt(3);return tt!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0),i}function ps(i,t){return i[0]*t[0]+i[1]*t[1]+i[2]*t[2]}function oi(i,t,e){let s=t[0],n=t[1],r=t[2],o=e[0],a=e[1],c=e[2];return i[0]=n*c-r*a,i[1]=r*o-s*c,i[2]=s*a-n*o,i}function Xt(i,t,e){let s=t[0],n=t[1],r=t[2],o=e[3]*s+e[7]*n+e[11]*r+e[15];return o=o||1,i[0]=(e[0]*s+e[4]*n+e[8]*r+e[12])/o,i[1]=(e[1]*s+e[5]*n+e[9]*r+e[13])/o,i[2]=(e[2]*s+e[6]*n+e[10]*r+e[14])/o,i}function ai(i,t,e){let s=t[0],n=t[1],r=t[2];return i[0]=s*e[0]+n*e[3]+r*e[6],i[1]=s*e[1]+n*e[4]+r*e[7],i[2]=s*e[2]+n*e[5]+r*e[8],i}function ci(i,t,e){let s=e[0],n=e[1],r=e[2],o=e[3],a=t[0],c=t[1],h=t[2],l=n*h-r*c,f=r*a-s*h,d=s*c-n*a,m=n*d-r*f,b=r*l-s*d,u=s*f-n*l,x=o*2;return l*=x,f*=x,d*=x,m*=2,b*=2,u*=2,i[0]=a+l+m,i[1]=c+f+b,i[2]=h+d+u,i}function hi(i,t,e,s){let n=[],r=[];return n[0]=t[0]-e[0],n[1]=t[1]-e[1],n[2]=t[2]-e[2],r[0]=n[0],r[1]=n[1]*Math.cos(s)-n[2]*Math.sin(s),r[2]=n[1]*Math.sin(s)+n[2]*Math.cos(s),i[0]=r[0]+e[0],i[1]=r[1]+e[1],i[2]=r[2]+e[2],i}function li(i,t,e,s){let n=[],r=[];return n[0]=t[0]-e[0],n[1]=t[1]-e[1],n[2]=t[2]-e[2],r[0]=n[2]*Math.sin(s)+n[0]*Math.cos(s),r[1]=n[1],r[2]=n[2]*Math.cos(s)-n[0]*Math.sin(s),i[0]=r[0]+e[0],i[1]=r[1]+e[1],i[2]=r[2]+e[2],i}function fi(i,t,e,s){let n=[],r=[];return n[0]=t[0]-e[0],n[1]=t[1]-e[1],n[2]=t[2]-e[2],r[0]=n[0]*Math.cos(s)-n[1]*Math.sin(s),r[1]=n[0]*Math.sin(s)+n[1]*Math.cos(s),r[2]=n[2],i[0]=r[0]+e[0],i[1]=r[1]+e[1],i[2]=r[2]+e[2],i}function di(i,t){let e=i[0],s=i[1],n=i[2],r=t[0],o=t[1],a=t[2],c=Math.sqrt((e*e+s*s+n*n)*(r*r+o*o+a*a)),h=c&&ps(i,t)/c;return Math.acos(Math.min(Math.max(h,-1),1))}var kr=function(){let i=us();return function(t,e,s,n,r,o){let a,c;for(e||(e=3),s||(s=0),n?c=Math.min(n*e+s,t.length):c=t.length,a=s;a<c;a+=e)i[0]=t[a],i[1]=t[a+1],i[2]=t[a+2],r(i,i,o),t[a]=i[0],t[a+1]=i[1],t[a+2]=i[2];return t}}();var Ae=[0,0,0],Kt,$=class extends Ht{static get ZERO(){return Kt||(Kt=new $(0,0,0),Object.freeze(Kt)),Kt}constructor(t=0,e=0,s=0){super(-0,-0,-0),arguments.length===1&&dt(t)?this.copy(t):(z.debug&&(B(t),B(e),B(s)),this[0]=t,this[1]=e,this[2]=s)}set(t,e,s){return this[0]=t,this[1]=e,this[2]=s,this.check()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this.check()}fromObject(t){return z.debug&&(B(t.x),B(t.y),B(t.z)),this[0]=t.x,this[1]=t.y,this[2]=t.z,this.check()}toObject(t){return t.x=this[0],t.y=this[1],t.z=this[2],t}get ELEMENTS(){return 3}get z(){return this[2]}set z(t){this[2]=B(t)}angle(t){return di(this,t)}cross(t){return oi(this,this,t),this.check()}rotateX({radians:t,origin:e=Ae}){return hi(this,this,e,t),this.check()}rotateY({radians:t,origin:e=Ae}){return li(this,this,e,t),this.check()}rotateZ({radians:t,origin:e=Ae}){return fi(this,this,e,t),this.check()}transform(t){return this.transformAsPoint(t)}transformAsPoint(t){return Xt(this,this,t),this.check()}transformAsVector(t){return Yt(this,this,t),this.check()}transformByMatrix3(t){return ai(this,this,t),this.check()}transformByMatrix2(t){return ri(this,this,t),this.check()}transformByQuaternion(t){return ci(this,this,t),this.check()}};var Zt=class extends ut{toString(){let t="[";if(z.printRowMajor){t+="row-major:";for(let e=0;e<this.RANK;++e)for(let s=0;s<this.RANK;++s)t+=` ${this[s*this.RANK+e]}`}else{t+="column-major:";for(let e=0;e<this.ELEMENTS;++e)t+=` ${this[e]}`}return t+="]",t}getElementIndex(t,e){return e*this.RANK+t}getElement(t,e){return this[e*this.RANK+t]}setElement(t,e,s){return this[e*this.RANK+t]=B(s),this}getColumn(t,e=new Array(this.RANK).fill(-0)){let s=t*this.RANK;for(let n=0;n<this.RANK;++n)e[n]=this[s+n];return e}setColumn(t,e){let s=t*this.RANK;for(let n=0;n<this.RANK;++n)this[s+n]=e[n];return this}};function ms(i){return i[0]=1,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=1,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[10]=1,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i}function ui(i,t){if(i===t){let e=t[1],s=t[2],n=t[3],r=t[6],o=t[7],a=t[11];i[1]=t[4],i[2]=t[8],i[3]=t[12],i[4]=e,i[6]=t[9],i[7]=t[13],i[8]=s,i[9]=r,i[11]=t[14],i[12]=n,i[13]=o,i[14]=a}else i[0]=t[0],i[1]=t[4],i[2]=t[8],i[3]=t[12],i[4]=t[1],i[5]=t[5],i[6]=t[9],i[7]=t[13],i[8]=t[2],i[9]=t[6],i[10]=t[10],i[11]=t[14],i[12]=t[3],i[13]=t[7],i[14]=t[11],i[15]=t[15];return i}function pi(i,t){let e=t[0],s=t[1],n=t[2],r=t[3],o=t[4],a=t[5],c=t[6],h=t[7],l=t[8],f=t[9],d=t[10],m=t[11],b=t[12],u=t[13],x=t[14],M=t[15],_=e*a-s*o,p=e*c-n*o,g=e*h-r*o,y=s*c-n*a,v=s*h-r*a,S=n*h-r*c,R=l*u-f*b,T=l*x-d*b,E=l*M-m*b,A=f*x-d*u,I=f*M-m*u,C=d*M-m*x,w=_*C-p*I+g*A+y*E-v*T+S*R;return w?(w=1/w,i[0]=(a*C-c*I+h*A)*w,i[1]=(n*I-s*C-r*A)*w,i[2]=(u*S-x*v+M*y)*w,i[3]=(d*v-f*S-m*y)*w,i[4]=(c*E-o*C-h*T)*w,i[5]=(e*C-n*E+r*T)*w,i[6]=(x*g-b*S-M*p)*w,i[7]=(l*S-d*g+m*p)*w,i[8]=(o*I-a*E+h*R)*w,i[9]=(s*E-e*I-r*R)*w,i[10]=(b*v-u*g+M*_)*w,i[11]=(f*g-l*v-m*_)*w,i[12]=(a*T-o*A-c*R)*w,i[13]=(e*A-s*T+n*R)*w,i[14]=(u*p-b*y-x*_)*w,i[15]=(l*y-f*p+d*_)*w,i):null}function mi(i){let t=i[0],e=i[1],s=i[2],n=i[3],r=i[4],o=i[5],a=i[6],c=i[7],h=i[8],l=i[9],f=i[10],d=i[11],m=i[12],b=i[13],u=i[14],x=i[15],M=t*o-e*r,_=t*a-s*r,p=e*a-s*o,g=h*b-l*m,y=h*u-f*m,v=l*u-f*b,S=t*v-e*y+s*g,R=r*v-o*y+a*g,T=h*p-l*_+f*M,E=m*p-b*_+u*M;return c*S-n*R+x*T-d*E}function we(i,t,e){let s=t[0],n=t[1],r=t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],f=t[8],d=t[9],m=t[10],b=t[11],u=t[12],x=t[13],M=t[14],_=t[15],p=e[0],g=e[1],y=e[2],v=e[3];return i[0]=p*s+g*a+y*f+v*u,i[1]=p*n+g*c+y*d+v*x,i[2]=p*r+g*h+y*m+v*M,i[3]=p*o+g*l+y*b+v*_,p=e[4],g=e[5],y=e[6],v=e[7],i[4]=p*s+g*a+y*f+v*u,i[5]=p*n+g*c+y*d+v*x,i[6]=p*r+g*h+y*m+v*M,i[7]=p*o+g*l+y*b+v*_,p=e[8],g=e[9],y=e[10],v=e[11],i[8]=p*s+g*a+y*f+v*u,i[9]=p*n+g*c+y*d+v*x,i[10]=p*r+g*h+y*m+v*M,i[11]=p*o+g*l+y*b+v*_,p=e[12],g=e[13],y=e[14],v=e[15],i[12]=p*s+g*a+y*f+v*u,i[13]=p*n+g*c+y*d+v*x,i[14]=p*r+g*h+y*m+v*M,i[15]=p*o+g*l+y*b+v*_,i}function gi(i,t,e){let s=e[0],n=e[1],r=e[2],o,a,c,h,l,f,d,m,b,u,x,M;return t===i?(i[12]=t[0]*s+t[4]*n+t[8]*r+t[12],i[13]=t[1]*s+t[5]*n+t[9]*r+t[13],i[14]=t[2]*s+t[6]*n+t[10]*r+t[14],i[15]=t[3]*s+t[7]*n+t[11]*r+t[15]):(o=t[0],a=t[1],c=t[2],h=t[3],l=t[4],f=t[5],d=t[6],m=t[7],b=t[8],u=t[9],x=t[10],M=t[11],i[0]=o,i[1]=a,i[2]=c,i[3]=h,i[4]=l,i[5]=f,i[6]=d,i[7]=m,i[8]=b,i[9]=u,i[10]=x,i[11]=M,i[12]=o*s+l*n+b*r+t[12],i[13]=a*s+f*n+u*r+t[13],i[14]=c*s+d*n+x*r+t[14],i[15]=h*s+m*n+M*r+t[15]),i}function xi(i,t,e){let s=e[0],n=e[1],r=e[2];return i[0]=t[0]*s,i[1]=t[1]*s,i[2]=t[2]*s,i[3]=t[3]*s,i[4]=t[4]*n,i[5]=t[5]*n,i[6]=t[6]*n,i[7]=t[7]*n,i[8]=t[8]*r,i[9]=t[9]*r,i[10]=t[10]*r,i[11]=t[11]*r,i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15],i}function yi(i,t,e,s){let n=s[0],r=s[1],o=s[2],a=Math.sqrt(n*n+r*r+o*o),c,h,l,f,d,m,b,u,x,M,_,p,g,y,v,S,R,T,E,A,I,C,w,F;return a<1e-6?null:(a=1/a,n*=a,r*=a,o*=a,h=Math.sin(e),c=Math.cos(e),l=1-c,f=t[0],d=t[1],m=t[2],b=t[3],u=t[4],x=t[5],M=t[6],_=t[7],p=t[8],g=t[9],y=t[10],v=t[11],S=n*n*l+c,R=r*n*l+o*h,T=o*n*l-r*h,E=n*r*l-o*h,A=r*r*l+c,I=o*r*l+n*h,C=n*o*l+r*h,w=r*o*l-n*h,F=o*o*l+c,i[0]=f*S+u*R+p*T,i[1]=d*S+x*R+g*T,i[2]=m*S+M*R+y*T,i[3]=b*S+_*R+v*T,i[4]=f*E+u*A+p*I,i[5]=d*E+x*A+g*I,i[6]=m*E+M*A+y*I,i[7]=b*E+_*A+v*I,i[8]=f*C+u*w+p*F,i[9]=d*C+x*w+g*F,i[10]=m*C+M*w+y*F,i[11]=b*C+_*w+v*F,t!==i&&(i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i)}function bi(i,t,e){let s=Math.sin(e),n=Math.cos(e),r=t[4],o=t[5],a=t[6],c=t[7],h=t[8],l=t[9],f=t[10],d=t[11];return t!==i&&(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i[4]=r*n+h*s,i[5]=o*n+l*s,i[6]=a*n+f*s,i[7]=c*n+d*s,i[8]=h*n-r*s,i[9]=l*n-o*s,i[10]=f*n-a*s,i[11]=d*n-c*s,i}function Mi(i,t,e){let s=Math.sin(e),n=Math.cos(e),r=t[0],o=t[1],a=t[2],c=t[3],h=t[8],l=t[9],f=t[10],d=t[11];return t!==i&&(i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i[0]=r*n-h*s,i[1]=o*n-l*s,i[2]=a*n-f*s,i[3]=c*n-d*s,i[8]=r*s+h*n,i[9]=o*s+l*n,i[10]=a*s+f*n,i[11]=c*s+d*n,i}function vi(i,t,e){let s=Math.sin(e),n=Math.cos(e),r=t[0],o=t[1],a=t[2],c=t[3],h=t[4],l=t[5],f=t[6],d=t[7];return t!==i&&(i[8]=t[8],i[9]=t[9],i[10]=t[10],i[11]=t[11],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i[0]=r*n+h*s,i[1]=o*n+l*s,i[2]=a*n+f*s,i[3]=c*n+d*s,i[4]=h*n-r*s,i[5]=l*n-o*s,i[6]=f*n-a*s,i[7]=d*n-c*s,i}function _i(i,t){let e=t[0],s=t[1],n=t[2],r=t[3],o=e+e,a=s+s,c=n+n,h=e*o,l=s*o,f=s*a,d=n*o,m=n*a,b=n*c,u=r*o,x=r*a,M=r*c;return i[0]=1-f-b,i[1]=l+M,i[2]=d-x,i[3]=0,i[4]=l-M,i[5]=1-h-b,i[6]=m+u,i[7]=0,i[8]=d+x,i[9]=m-u,i[10]=1-h-f,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i}function Ai(i,t,e,s,n,r,o){let a=1/(e-t),c=1/(n-s),h=1/(r-o);return i[0]=r*2*a,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=r*2*c,i[6]=0,i[7]=0,i[8]=(e+t)*a,i[9]=(n+s)*c,i[10]=(o+r)*h,i[11]=-1,i[12]=0,i[13]=0,i[14]=o*r*2*h,i[15]=0,i}function gs(i,t,e,s,n){let r=1/Math.tan(t/2);if(i[0]=r/e,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=r,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[11]=-1,i[12]=0,i[13]=0,i[15]=0,n!=null&&n!==1/0){let o=1/(s-n);i[10]=(n+s)*o,i[14]=2*n*s*o}else i[10]=-1,i[14]=-2*s;return i}var wi=gs;function xs(i,t,e,s,n,r,o){let a=1/(t-e),c=1/(s-n),h=1/(r-o);return i[0]=-2*a,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=-2*c,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[10]=2*h,i[11]=0,i[12]=(t+e)*a,i[13]=(n+s)*c,i[14]=(o+r)*h,i[15]=1,i}var Pi=xs;function Ii(i,t,e,s){let n,r,o,a,c,h,l,f,d,m,b=t[0],u=t[1],x=t[2],M=s[0],_=s[1],p=s[2],g=e[0],y=e[1],v=e[2];return Math.abs(b-g)<1e-6&&Math.abs(u-y)<1e-6&&Math.abs(x-v)<1e-6?ms(i):(f=b-g,d=u-y,m=x-v,n=1/Math.sqrt(f*f+d*d+m*m),f*=n,d*=n,m*=n,r=_*m-p*d,o=p*f-M*m,a=M*d-_*f,n=Math.sqrt(r*r+o*o+a*a),n?(n=1/n,r*=n,o*=n,a*=n):(r=0,o=0,a=0),c=d*a-m*o,h=m*r-f*a,l=f*o-d*r,n=Math.sqrt(c*c+h*h+l*l),n?(n=1/n,c*=n,h*=n,l*=n):(c=0,h=0,l=0),i[0]=r,i[1]=c,i[2]=f,i[3]=0,i[4]=o,i[5]=h,i[6]=d,i[7]=0,i[8]=a,i[9]=l,i[10]=m,i[11]=0,i[12]=-(r*b+o*u+a*x),i[13]=-(c*b+h*u+l*x),i[14]=-(f*b+d*u+m*x),i[15]=1,i)}function ys(){let i=new tt(4);return tt!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0,i[3]=0),i}function Si(i,t,e){let s=t[0],n=t[1],r=t[2],o=t[3];return i[0]=e[0]*s+e[4]*n+e[8]*r+e[12]*o,i[1]=e[1]*s+e[5]*n+e[9]*r+e[13]*o,i[2]=e[2]*s+e[6]*n+e[10]*r+e[14]*o,i[3]=e[3]*s+e[7]*n+e[11]*r+e[15]*o,i}var Wr=function(){let i=ys();return function(t,e,s,n,r,o){let a,c;for(e||(e=4),s||(s=0),n?c=Math.min(n*e+s,t.length):c=t.length,a=s;a<c;a+=e)i[0]=t[a],i[1]=t[a+1],i[2]=t[a+2],i[3]=t[a+3],r(i,i,o),t[a]=i[0],t[a+1]=i[1],t[a+2]=i[2],t[a+3]=i[3];return t}}();var Se;(function(i){i[i.COL0ROW0=0]="COL0ROW0",i[i.COL0ROW1=1]="COL0ROW1",i[i.COL0ROW2=2]="COL0ROW2",i[i.COL0ROW3=3]="COL0ROW3",i[i.COL1ROW0=4]="COL1ROW0",i[i.COL1ROW1=5]="COL1ROW1",i[i.COL1ROW2=6]="COL1ROW2",i[i.COL1ROW3=7]="COL1ROW3",i[i.COL2ROW0=8]="COL2ROW0",i[i.COL2ROW1=9]="COL2ROW1",i[i.COL2ROW2=10]="COL2ROW2",i[i.COL2ROW3=11]="COL2ROW3",i[i.COL3ROW0=12]="COL3ROW0",i[i.COL3ROW1=13]="COL3ROW1",i[i.COL3ROW2=14]="COL3ROW2",i[i.COL3ROW3=15]="COL3ROW3"})(Se||(Se={}));var bs=45*Math.PI/180,Ms=1,Pe=.1,Ie=500,vs=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),H=class extends Zt{static get IDENTITY(){return As()}static get ZERO(){return _s()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Se}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,e,s,n,r,o,a,c,h,l,f,d,m,b,u,x){return this[0]=t,this[1]=e,this[2]=s,this[3]=n,this[4]=r,this[5]=o,this[6]=a,this[7]=c,this[8]=h,this[9]=l,this[10]=f,this[11]=d,this[12]=m,this[13]=b,this[14]=u,this[15]=x,this.check()}setRowMajor(t,e,s,n,r,o,a,c,h,l,f,d,m,b,u,x){return this[0]=t,this[1]=r,this[2]=h,this[3]=m,this[4]=e,this[5]=o,this[6]=l,this[7]=b,this[8]=s,this[9]=a,this[10]=f,this[11]=u,this[12]=n,this[13]=c,this[14]=d,this[15]=x,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(vs)}fromObject(t){return this.check()}fromQuaternion(t){return _i(this,t),this.check()}frustum(t){let{left:e,right:s,bottom:n,top:r,near:o=Pe,far:a=Ie}=t;return a===1/0?ws(this,e,s,n,r,o):Ai(this,e,s,n,r,o,a),this.check()}lookAt(t){let{eye:e,center:s=[0,0,0],up:n=[0,1,0]}=t;return Ii(this,e,s,n),this.check()}ortho(t){let{left:e,right:s,bottom:n,top:r,near:o=Pe,far:a=Ie}=t;return Pi(this,e,s,n,r,o,a),this.check()}orthographic(t){let{fovy:e=bs,aspect:s=Ms,focalDistance:n=1,near:r=Pe,far:o=Ie}=t;Ti(e);let a=e/2,c=n*Math.tan(a),h=c*s;return this.ortho({left:-h,right:h,bottom:-c,top:c,near:r,far:o})}perspective(t){let{fovy:e=45*Math.PI/180,aspect:s=1,near:n=.1,far:r=500}=t;return Ti(e),wi(this,e,s,n,r),this.check()}determinant(){return mi(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,e){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],e=e||[-0,-0,-0];let s=this.getScale(e),n=1/s[0],r=1/s[1],o=1/s[2];return t[0]=this[0]*n,t[1]=this[1]*r,t[2]=this[2]*o,t[3]=0,t[4]=this[4]*n,t[5]=this[5]*r,t[6]=this[6]*o,t[7]=0,t[8]=this[8]*n,t[9]=this[9]*r,t[10]=this[10]*o,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,e){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],e=e||[-0,-0,-0];let s=this.getScale(e),n=1/s[0],r=1/s[1],o=1/s[2];return t[0]=this[0]*n,t[1]=this[1]*r,t[2]=this[2]*o,t[3]=this[4]*n,t[4]=this[5]*r,t[5]=this[6]*o,t[6]=this[8]*n,t[7]=this[9]*r,t[8]=this[10]*o,t}transpose(){return ui(this,this),this.check()}invert(){return pi(this,this),this.check()}multiplyLeft(t){return we(this,t,this),this.check()}multiplyRight(t){return we(this,this,t),this.check()}rotateX(t){return bi(this,this,t),this.check()}rotateY(t){return Mi(this,this,t),this.check()}rotateZ(t){return vi(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,e){return yi(this,this,t,e),this.check()}scale(t){return xi(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return gi(this,this,t),this.check()}transform(t,e){return t.length===4?(e=Si(e||[-0,-0,-0,-0],t,this),Wt(e,4),e):this.transformAsPoint(t,e)}transformAsPoint(t,e){let{length:s}=t,n;switch(s){case 2:n=si(e||[-0,-0],t,this);break;case 3:n=Xt(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Wt(n,t.length),n}transformAsVector(t,e){let s;switch(t.length){case 2:s=ni(e||[-0,-0],t,this);break;case 3:s=Yt(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Wt(s,t.length),s}transformPoint(t,e){return this.transformAsPoint(t,e)}transformVector(t,e){return this.transformAsPoint(t,e)}transformDirection(t,e){return this.transformAsVector(t,e)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,e,s){return this.identity().translate([t,e,s])}},Qt,Jt;function _s(){return Qt||(Qt=new H([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Qt)),Qt}function As(){return Jt||(Jt=new H,Object.freeze(Jt)),Jt}function Ti(i){if(i>Math.PI*2)throw Error("expected radians")}function ws(i,t,e,s,n,r){let o=2*r/(e-t),a=2*r/(n-s),c=(e+t)/(e-t),h=(n+s)/(n-s),l=-1,f=-1,d=-2*r;return i[0]=o,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=a,i[6]=0,i[7]=0,i[8]=c,i[9]=h,i[10]=l,i[11]=f,i[12]=0,i[13]=0,i[14]=d,i[15]=0,i}var et=class{id;matrix=new H;display=!0;position=new $;rotation=new $;scale=new $(1,1,1);userData={};props={};constructor(t={}){let{id:e}=t;this.id=e||O(this.constructor.name),this._setScenegraphNodeProps(t)}getBounds(){return null}destroy(){}delete(){this.destroy()}setProps(t){return this._setScenegraphNodeProps(t),this}toString(){return`{type: ScenegraphNode, id: ${this.id})}`}setPosition(t){return this.position=t,this}setRotation(t){return this.rotation=t,this}setScale(t){return this.scale=t,this}setMatrix(t,e=!0){e?this.matrix.copy(t):this.matrix=t}setMatrixComponents(t){let{position:e,rotation:s,scale:n,update:r=!0}=t;return e&&this.setPosition(e),s&&this.setRotation(s),n&&this.setScale(n),r&&this.updateMatrix(),this}updateMatrix(){let t=this.position,e=this.rotation,s=this.scale;return this.matrix.identity(),this.matrix.translate(t),this.matrix.rotateXYZ(e),this.matrix.scale(s),this}update(t={}){let{position:e,rotation:s,scale:n}=t;return e&&this.setPosition(e),s&&this.setRotation(s),n&&this.setScale(n),this.updateMatrix(),this}getCoordinateUniforms(t,e){e=e||this.matrix;let s=new H(t).multiplyRight(e),n=s.invert(),r=n.transpose();return{viewMatrix:t,modelMatrix:e,objectMatrix:e,worldMatrix:s,worldInverseMatrix:n,worldInverseTransposeMatrix:r}}_setScenegraphNodeProps(t){"position"in t&&this.setPosition(t.position),"rotation"in t&&this.setRotation(t.rotation),"scale"in t&&this.setScale(t.scale),"matrix"in t&&this.setMatrix(t.matrix),Object.assign(this.props,t)}};var Ci=L(j(),1);var mt=class extends et{children;constructor(t={}){t=Array.isArray(t)?{children:t}:t;let{children:e=[]}=t;Ci.log.assert(e.every(s=>s instanceof et),"every child must an instance of ScenegraphNode"),super(t),this.children=e}getBounds(){let t=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]];return this.traverse((e,{worldMatrix:s})=>{let n=e.getBounds();if(!n)return;let[r,o]=n,a=new $(r).add(o).divide([2,2,2]);s.transformAsPoint(a,a);let c=new $(o).subtract(r).divide([2,2,2]);s.transformAsVector(c,c);for(let h=0;h<8;h++){let l=new $(h&1?-1:1,h&2?-1:1,h&4?-1:1).multiply(c).add(a);for(let f=0;f<3;f++)t[0][f]=Math.min(t[0][f],l[f]),t[1][f]=Math.max(t[1][f],l[f])}}),Number.isFinite(t[0][0])?t:null}destroy(){this.children.forEach(t=>t.destroy()),this.removeAll(),super.destroy()}add(...t){for(let e of t)Array.isArray(e)?this.add(...e):this.children.push(e);return this}remove(t){let e=this.children,s=e.indexOf(t);return s>-1&&e.splice(s,1),this}removeAll(){return this.children=[],this}traverse(t,{worldMatrix:e=new H}={}){let s=new H(e).multiplyRight(this.matrix);for(let n of this.children)n instanceof mt?n.traverse(t,{worldMatrix:s}):t(n,{worldMatrix:s})}};var te=class extends et{model;bounds=null;managedResources;constructor(t){super(t),this.model=t.model,this.managedResources=t.managedResources||[],this.bounds=t.bounds||null,this.setProps(t)}destroy(){this.model&&(this.model.destroy(),this.model=null),this.managedResources.forEach(t=>t.destroy()),this.managedResources=[]}getBounds(){return this.bounds}draw(t){return this.model.draw(t)}};var Ps={x:[2,0,1],y:[0,1,2],z:[1,2,0]},st=class extends D{constructor(t={}){let{id:e=O("truncated-code-geometry")}=t,{indices:s,attributes:n}=Is(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{POSITION:{size:3,value:n.POSITION},NORMAL:{size:3,value:n.NORMAL},TEXCOORD_0:{size:2,value:n.TEXCOORD_0},...t.attributes}})}};function Is(i={}){let{bottomRadius:t=0,topRadius:e=0,height:s=1,nradial:n=10,nvertical:r=10,verticalAxis:o="y",topCap:a=!1,bottomCap:c=!1}=i,h=(a?2:0)+(c?2:0),l=(n+1)*(r+1+h),f=Math.atan2(t-e,s),d=Math.sin,m=Math.cos,b=Math.PI,u=m(f),x=d(f),M=a?-2:0,_=r+(c?2:0),p=n+1,g=new Uint16Array(n*(r+h)*6),y=Ps[o],v=new Float32Array(l*3),S=new Float32Array(l*3),R=new Float32Array(l*2),T=0,E=0;for(let A=M;A<=_;A++){let I=A/r,C=s*I,w;A<0?(C=0,I=1,w=t):A>r?(C=s,I=1,w=e):w=t+(e-t)*(A/r),(A===-2||A===r+2)&&(w=0,I=0),C-=s/2;for(let F=0;F<p;F++){let K=d(F*b*2/n),W=m(F*b*2/n);v[T+y[0]]=K*w,v[T+y[1]]=C,v[T+y[2]]=W*w,S[T+y[0]]=A<0||A>r?0:K*u,S[T+y[1]]=A<0?-1:A>r?1:x,S[T+y[2]]=A<0||A>r?0:W*u,R[E+0]=F/n,R[E+1]=I,E+=2,T+=3}}for(let A=0;A<r+h;A++)for(let I=0;I<n;I++){let C=(A*n+I)*6;g[C+0]=p*(A+0)+0+I,g[C+1]=p*(A+0)+1+I,g[C+2]=p*(A+1)+1+I,g[C+3]=p*(A+0)+0+I,g[C+4]=p*(A+1)+1+I,g[C+5]=p*(A+1)+0+I}return{indices:g,attributes:{POSITION:v,NORMAL:S,TEXCOORD_0:R}}}var ee=class extends st{constructor(t={}){let{id:e=O("cone-geometry"),radius:s=1,cap:n=!0}=t;super({...t,id:e,topRadius:0,topCap:Boolean(n),bottomCap:Boolean(n),bottomRadius:s})}};var ie=class extends D{constructor(t={}){let{id:e=O("cube-geometry"),indices:s=!0}=t;super(s?{...t,id:e,topology:"triangle-list",indices:{size:1,value:Ss},attributes:{...Ls,...t.attributes}}:{...t,id:e,topology:"triangle-list",indices:void 0,attributes:{...Ns,...t.attributes}})}},Ss=new Uint16Array([0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]),Ts=new Float32Array([-1,-1,1,1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,1,1,1,1,1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1]),Cs=new Float32Array([0,0,1,0,0,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cs},TEXCOORD_0:{size:2,value:Os}},Ns={POSITION:{size:3,value:Rs},TEXCOORD_0:{size:2,value:Es},COLOR_0:{size:3,value:ks}};var se=class extends st{constructor(t={}){let{id:e=O("cylinder-geometry"),radius:s=1}=t;super({...t,id:e,bottomRadius:s,topRadius:s})}};var Fs=[-1,0,0,0,1,0,0,0,-1,0,0,1,0,-1,0,1,0,0],zs=[3,4,5,3,5,1,3,1,0,3,0,4,4,0,2,4,2,5,2,0,1,5,2,1],ne=class extends D{constructor(t={}){let{id:e=O("ico-sphere-geometry")}=t,{indices:s,attributes:n}=Ds(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{...n,...t.attributes}})}};function Ds(i){let{iterations:t=0}=i,e=Math.PI,s=e*2,n=[...Fs],r=[...zs];n.push(),r.push();let o=(()=>{let l={};return(f,d)=>{f*=3,d*=3;let m=f<d?f:d,b=f>d?f:d,u=`${m}|${b}`;if(u in l)return l[u];let x=n[f],M=n[f+1],_=n[f+2],p=n[d],g=n[d+1],y=n[d+2],v=(x+p)/2,S=(M+g)/2,R=(_+y)/2,T=Math.sqrt(v*v+S*S+R*R);return v/=T,S/=T,R/=T,n.push(v,S,R),l[u]=n.length/3-1}})();for(let l=0;l<t;l++){let f=[];for(let d=0;d<r.length;d+=3){let m=o(r[d+0],r[d+1]),b=o(r[d+1],r[d+2]),u=o(r[d+2],r[d+0]);f.push(u,r[d+0],m,m,r[d+1],b,b,r[d+2],u,m,b,u)}r=f}let a=new Array(n.length),c=new Array(n.length/3*2),h=r.length;for(let l=h-3;l>=0;l-=3){let f=r[l+0],d=r[l+1],m=r[l+2],b=f*3,u=d*3,x=m*3,M=f*2,_=d*2,p=m*2,g=n[b+0],y=n[b+1],v=n[b+2],S=Math.acos(v/Math.sqrt(g*g+y*y+v*v)),R=Math.atan2(y,g)+e,T=S/e,E=1-R/s,A=n[u+0],I=n[u+1],C=n[u+2],w=Math.acos(C/Math.sqrt(A*A+I*I+C*C)),F=Math.atan2(I,A)+e,K=w/e,W=1-F/s,Tt=n[x+0],Ct=n[x+1],Ot=n[x+2],Fi=Math.acos(Ot/Math.sqrt(Tt*Tt+Ct*Ct+Ot*Ot)),zi=Math.atan2(Ct,Tt)+e,ke=Fi/e,Rt=1-zi/s,Di=[Tt-A,Ct-I,Ot-C],Bi=[g-A,y-I,v-C],G=new $(Di).cross(Bi).normalize(),k;(E===0||W===0||Rt===0)&&(E===0||E>.5)&&(W===0||W>.5)&&(Rt===0||Rt>.5)&&(n.push(n[b+0],n[b+1],n[b+2]),k=n.length/3-1,r.push(k),c[k*2+0]=1,c[k*2+1]=T,a[k*3+0]=G.x,a[k*3+1]=G.y,a[k*3+2]=G.z,n.push(n[u+0],n[u+1],n[u+2]),k=n.length/3-1,r.push(k),c[k*2+0]=1,c[k*2+1]=K,a[k*3+0]=G.x,a[k*3+1]=G.y,a[k*3+2]=G.z,n.push(n[x+0],n[x+1],n[x+2]),k=n.length/3-1,r.push(k),c[k*2+0]=1,c[k*2+1]=ke,a[k*3+0]=G.x,a[k*3+1]=G.y,a[k*3+2]=G.z),a[b+0]=a[u+0]=a[x+0]=G.x,a[b+1]=a[u+1]=a[x+1]=G.y,a[b+2]=a[u+2]=a[x+2]=G.z,c[M+0]=E,c[M+1]=T,c[_+0]=W,c[_+1]=K,c[p+0]=Rt,c[p+1]=ke}return{indices:{size:1,value:new Uint16Array(r)},attributes:{POSITION:{size:3,value:new Float32Array(n)},NORMAL:{size:3,value:new Float32Array(a)},TEXCOORD_0:{size:2,value:new Float32Array(c)}}}}function Oi(i){let{indices:t,attributes:e}=i;if(!t)return i;let s=t.value.length,n={};for(let r in e){let o=e[r],{constant:a,value:c,size:h}=o;if(a||!h)continue;let l=new c.constructor(s*h);for(let f=0;f<s;++f){let d=t.value[f];for(let m=0;m<h;m++)l[f*h+m]=c[d*h+m]}n[r]={size:h,value:l}}return{attributes:Object.assign({},e,n)}}var re=class extends D{constructor(t={}){let{id:e=O("plane-geometry")}=t,{indices:s,attributes:n}=Bs(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{...n,...t.attributes}})}};function Bs(i){let{type:t="x,y",offset:e=0,flipCull:s=!1,unpack:n=!1}=i,r=t.split(","),o=i[`${r[0]}len`]||1,a=i[`${r[1]}len`]||1,c=i[`n${r[0]}`]||1,h=i[`n${r[1]}`]||1,l=(c+1)*(h+1),f=new Float32Array(l*3),d=new Float32Array(l*3),m=new Float32Array(l*2);s&&(o=-o);let b=0,u=0;for(let p=0;p<=h;p++)for(let g=0;g<=c;g++){let y=g/c,v=p/h;switch(m[b+0]=s?1-y:y,m[b+1]=v,t){case"x,y":f[u+0]=o*y-o*.5,f[u+1]=a*v-a*.5,f[u+2]=e,d[u+0]=0,d[u+1]=0,d[u+2]=s?1:-1;break;case"x,z":f[u+0]=o*y-o*.5,f[u+1]=e,f[u+2]=a*v-a*.5,d[u+0]=0,d[u+1]=s?1:-1,d[u+2]=0;break;case"y,z":f[u+0]=e,f[u+1]=o*y-o*.5,f[u+2]=a*v-a*.5,d[u+0]=s?1:-1,d[u+1]=0,d[u+2]=0;break;default:throw new Error("PlaneGeometry: unknown type")}b+=2,u+=3}let x=c+1,M=new Uint16Array(c*h*6);for(let p=0;p<h;p++)for(let g=0;g<c;g++){let y=(p*c+g)*6;M[y+0]=(p+0)*x+g,M[y+1]=(p+1)*x+g,M[y+2]=(p+0)*x+g+1,M[y+3]=(p+1)*x+g,M[y+4]=(p+1)*x+g+1,M[y+5]=(p+0)*x+g+1}let _={indices:{size:1,value:M},attributes:{POSITION:{size:3,value:f},NORMAL:{size:3,value:d},TEXCOORD_0:{size:2,value:m}}};return n?Oi(_):_}var oe=class extends D{constructor(t={}){let{id:e=O("sphere-geometry")}=t,{indices:s,attributes:n}=Us(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{...n,...t.attributes}})}};function Us(i){let{nlat:t=10,nlong:e=10}=i,r=Math.PI-0,o=0,c=2*Math.PI-o,h=(t+1)*(e+1),l=(M,_,p,g,y)=>i.radius||1,f=new Float32Array(h*3),d=new Float32Array(h*3),m=new Float32Array(h*2),b=h>65535?Uint32Array:Uint16Array,u=new b(t*e*6);for(let M=0;M<=t;M++)for(let _=0;_<=e;_++){let p=_/e,g=M/t,y=_+M*(e+1),v=y*2,S=y*3,R=c*p,T=r*g,E=Math.sin(R),A=Math.cos(R),I=Math.sin(T),C=Math.cos(T),w=A*I,F=C,K=E*I,W=l(w,F,K,p,g);f[S+0]=W*w,f[S+1]=W*F,f[S+2]=W*K,d[S+0]=w,d[S+1]=F,d[S+2]=K,m[v+0]=p,m[v+1]=1-g}let x=e+1;for(let M=0;M<e;M++)for(let _=0;_<t;_++){let p=(M*t+_)*6;u[p+0]=_*x+M,u[p+1]=_*x+M+1,u[p+2]=(_+1)*x+M,u[p+3]=(_+1)*x+M,u[p+4]=_*x+M+1,u[p+5]=(_+1)*x+M+1}return{indices:{size:1,value:u},attributes:{POSITION:{size:3,value:f},NORMAL:{size:3,value:d},TEXCOORD_0:{size:2,value:m}}}}function Ri(){let i=1,t=1;return()=>(i=Math.sin(t*17.23),t=Math.cos(i*27.92),$s(Math.abs(i*t)*1432.71))}function $s(i){return i-Math.floor(i)}var ki=L(rt(),1);var wt=L(j(),1),gt=class{current;next;constructor(t){this.current=t.current,this.next=t.next}destroy(){this.current?.destroy(),this.next?.destroy()}swap(){let t=this.current;this.current=this.next,this.next=t}},xt=class extends gt{constructor(t,e){e={...e};let s=e.colorAttachments?.map(o=>typeof o!="string"?o:t.createTexture({format:o,usage:wt.Texture.COPY_DST|wt.Texture.RENDER_ATTACHMENT})),n=t.createFramebuffer({...e,colorAttachments:s});s=e.colorAttachments?.map(o=>typeof o!="string"?o:t.createTexture({format:o,usage:wt.Texture.COPY_DST|wt.Texture.RENDER_ATTACHMENT}));let r=t.createFramebuffer({...e,colorAttachments:s});super({current:n,next:r})}resize(t){if(t.width===this.current.width&&t.height===this.current.height)return!1;let{current:e,next:s}=this;return this.current=e.clone(t),e.destroy(),this.next=s.clone(t),s.destroy(),!0}},ae=class extends gt{constructor(t,e){super({current:t.createBuffer(e),next:t.createBuffer(e)})}resize(t){if(t.byteLength===this.current.byteLength)return!1;let{current:e,next:s}=this;return this.current=e.clone(t),e.destroy(),this.next=s.clone(t),s.destroy(),!0}};function Ei(i){let{shaderPass:t,action:e,shadingLanguage:s}=i;switch(e){case"filter":let n=`${t.name}_filterColor_ext`;return s==="wgsl"?js(n):Vs(n);case"sample":let r=`${t.name}_sampleColor`;return s==="wgsl"?Gs(r):qs(r);default:throw new Error(`${t.name} no fragment shader generated for shader pass`)}}function js(i){return`// Binding 0:1 is reserved for shader passes
77
+ `,at=class extends J{constructor(t,e){super(t,{id:e.id||"background-texture-model",source:as,fs:cs,parameters:{depthWriteEnabled:!1,depthCompare:"always",...e.blend?{blend:!0,blendColorOperation:"add",blendAlphaOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one-minus-src-color",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one-minus-src-alpha"}:{}}}),this.setTexture(e.backgroundTexture)}setTexture(t){this.setBindings({backgroundTexture:t})}predraw(){this.shaderInputs.setProps({}),super.predraw()}};var xr=1/Math.PI*180,yr=1/180*Math.PI,hs={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...hs}};var z=globalThis.mathgl.config;function ti(i,{precision:t=z.precision}={}){return i=ls(i),`${parseFloat(i.toPrecision(t))}`}function dt(i){return Array.isArray(i)||ArrayBuffer.isView(i)&&!(i instanceof DataView)}function Me(i,t,e){let s=z.EPSILON;e&&(z.EPSILON=e);try{if(i===t)return!0;if(dt(i)&&dt(t)){if(i.length!==t.length)return!1;for(let n=0;n<i.length;++n)if(!Me(i[n],t[n]))return!1;return!0}return i&&i.equals?i.equals(t):t&&t.equals?t.equals(i):typeof i=="number"&&typeof t=="number"?Math.abs(i-t)<=z.EPSILON*Math.max(1,Math.abs(i),Math.abs(t)):!1}finally{z.EPSILON=s}}function ls(i){return Math.round(i/z.EPSILON)*z.EPSILON}var ut=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,e=0){for(let s=0;s<this.ELEMENTS;++s)this[s]=t[s+e];return this.check()}toArray(t=[],e=0){for(let s=0;s<this.ELEMENTS;++s)t[e+s]=this[s];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:dt(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(z)}formatString(t){let e="";for(let s=0;s<this.ELEMENTS;++s)e+=(s>0?", ":"")+ti(this[s],t);return`${t.printTypes?this.constructor.name:""}[${e}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let e=0;e<this.ELEMENTS;++e)if(!Me(this[e],t[e]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let e=0;e<this.ELEMENTS;++e)if(this[e]!==t[e])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,e,s){if(s===void 0)return this.lerp(this,t,e);for(let n=0;n<this.ELEMENTS;++n){let r=t[n],o=typeof e=="number"?e:e[n];this[n]=r+s*(o-r)}return this.check()}min(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=Math.min(t[e],this[e]);return this.check()}max(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=Math.max(t[e],this[e]);return this.check()}clamp(t,e){for(let s=0;s<this.ELEMENTS;++s)this[s]=Math.min(Math.max(this[s],t[s]),e[s]);return this.check()}add(...t){for(let e of t)for(let s=0;s<this.ELEMENTS;++s)this[s]+=e[s];return this.check()}subtract(...t){for(let e of t)for(let s=0;s<this.ELEMENTS;++s)this[s]-=e[s];return this.check()}scale(t){if(typeof t=="number")for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;else for(let e=0;e<this.ELEMENTS&&e<t.length;++e)this[e]*=t[e];return this.check()}multiplyByScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;return this.check()}check(){if(z.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let e=0;e<this.ELEMENTS;++e)t=t&&Number.isFinite(this[e]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=t;return this.check()}addScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,e){for(let s=0;s<this.ELEMENTS;++s)this[s]=Math.min(Math.max(this[s],t),e);return this.check()}get elements(){return this}};function fs(i,t){if(i.length!==t)return!1;for(let e=0;e<i.length;++e)if(!Number.isFinite(i[e]))return!1;return!0}function B(i){if(!Number.isFinite(i))throw new Error(`Invalid number ${JSON.stringify(i)}`);return i}function Wt(i,t,e=""){if(z.debug&&!fs(i,t))throw new Error(`math.gl: ${e} some fields set to invalid numbers'`);return i}function ve(i,t){if(!i)throw new Error(`math.gl assertion ${t}`)}var Ht=class extends ut{get x(){return this[0]}set x(t){this[0]=B(t)}get y(){return this[1]}set y(t){this[1]=B(t)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let t=0;for(let e=0;e<this.ELEMENTS;++e)t+=this[e]*this[e];return t}magnitudeSquared(){return this.lengthSquared()}distance(t){return Math.sqrt(this.distanceSquared(t))}distanceSquared(t){let e=0;for(let s=0;s<this.ELEMENTS;++s){let n=this[s]-t[s];e+=n*n}return B(e)}dot(t){let e=0;for(let s=0;s<this.ELEMENTS;++s)e+=this[s]*t[s];return B(e)}normalize(){let t=this.magnitude();if(t!==0)for(let e=0;e<this.ELEMENTS;++e)this[e]/=t;return this.check()}multiply(...t){for(let e of t)for(let s=0;s<this.ELEMENTS;++s)this[s]*=e[s];return this.check()}divide(...t){for(let e of t)for(let s=0;s<this.ELEMENTS;++s)this[s]/=e[s];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(t){return this.distance(t)}distanceToSquared(t){return this.distanceSquared(t)}getComponent(t){return ve(t>=0&&t<this.ELEMENTS,"index is out of range"),B(this[t])}setComponent(t,e){return ve(t>=0&&t<this.ELEMENTS,"index is out of range"),this[t]=e,this.check()}addVectors(t,e){return this.copy(t).add(e)}subVectors(t,e){return this.copy(t).subtract(e)}multiplyVectors(t,e){return this.copy(t).multiply(e)}addScaledVector(t,e){return this.add(new this.constructor(t).multiplyScalar(e))}};var tt=typeof Float32Array<"u"?Float32Array:Array;var Cr=Math.PI/180;function ds(){let i=new tt(2);return tt!=Float32Array&&(i[0]=0,i[1]=0),i}function si(i,t,e){let s=t[0],n=t[1];return i[0]=e[0]*s+e[4]*n+e[12],i[1]=e[1]*s+e[5]*n+e[13],i}var Or=function(){let i=ds();return function(t,e,s,n,r,o){let a,c;for(e||(e=2),s||(s=0),n?c=Math.min(n*e+s,t.length):c=t.length,a=s;a<c;a+=e)i[0]=t[a],i[1]=t[a+1],r(i,i,o),t[a]=i[0],t[a+1]=i[1];return t}}();function ni(i,t,e){let s=t[0],n=t[1],r=e[3]*s+e[7]*n||1;return i[0]=(e[0]*s+e[4]*n)/r,i[1]=(e[1]*s+e[5]*n)/r,i}function Yt(i,t,e){let s=t[0],n=t[1],r=t[2],o=e[3]*s+e[7]*n+e[11]*r||1;return i[0]=(e[0]*s+e[4]*n+e[8]*r)/o,i[1]=(e[1]*s+e[5]*n+e[9]*r)/o,i[2]=(e[2]*s+e[6]*n+e[10]*r)/o,i}function ri(i,t,e){let s=t[0],n=t[1];return i[0]=e[0]*s+e[2]*n,i[1]=e[1]*s+e[3]*n,i[2]=t[2],i}function us(){let i=new tt(3);return tt!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0),i}function ps(i,t){return i[0]*t[0]+i[1]*t[1]+i[2]*t[2]}function oi(i,t,e){let s=t[0],n=t[1],r=t[2],o=e[0],a=e[1],c=e[2];return i[0]=n*c-r*a,i[1]=r*o-s*c,i[2]=s*a-n*o,i}function Xt(i,t,e){let s=t[0],n=t[1],r=t[2],o=e[3]*s+e[7]*n+e[11]*r+e[15];return o=o||1,i[0]=(e[0]*s+e[4]*n+e[8]*r+e[12])/o,i[1]=(e[1]*s+e[5]*n+e[9]*r+e[13])/o,i[2]=(e[2]*s+e[6]*n+e[10]*r+e[14])/o,i}function ai(i,t,e){let s=t[0],n=t[1],r=t[2];return i[0]=s*e[0]+n*e[3]+r*e[6],i[1]=s*e[1]+n*e[4]+r*e[7],i[2]=s*e[2]+n*e[5]+r*e[8],i}function ci(i,t,e){let s=e[0],n=e[1],r=e[2],o=e[3],a=t[0],c=t[1],h=t[2],l=n*h-r*c,f=r*a-s*h,d=s*c-n*a,m=n*d-r*f,b=r*l-s*d,u=s*f-n*l,x=o*2;return l*=x,f*=x,d*=x,m*=2,b*=2,u*=2,i[0]=a+l+m,i[1]=c+f+b,i[2]=h+d+u,i}function hi(i,t,e,s){let n=[],r=[];return n[0]=t[0]-e[0],n[1]=t[1]-e[1],n[2]=t[2]-e[2],r[0]=n[0],r[1]=n[1]*Math.cos(s)-n[2]*Math.sin(s),r[2]=n[1]*Math.sin(s)+n[2]*Math.cos(s),i[0]=r[0]+e[0],i[1]=r[1]+e[1],i[2]=r[2]+e[2],i}function li(i,t,e,s){let n=[],r=[];return n[0]=t[0]-e[0],n[1]=t[1]-e[1],n[2]=t[2]-e[2],r[0]=n[2]*Math.sin(s)+n[0]*Math.cos(s),r[1]=n[1],r[2]=n[2]*Math.cos(s)-n[0]*Math.sin(s),i[0]=r[0]+e[0],i[1]=r[1]+e[1],i[2]=r[2]+e[2],i}function fi(i,t,e,s){let n=[],r=[];return n[0]=t[0]-e[0],n[1]=t[1]-e[1],n[2]=t[2]-e[2],r[0]=n[0]*Math.cos(s)-n[1]*Math.sin(s),r[1]=n[0]*Math.sin(s)+n[1]*Math.cos(s),r[2]=n[2],i[0]=r[0]+e[0],i[1]=r[1]+e[1],i[2]=r[2]+e[2],i}function di(i,t){let e=i[0],s=i[1],n=i[2],r=t[0],o=t[1],a=t[2],c=Math.sqrt((e*e+s*s+n*n)*(r*r+o*o+a*a)),h=c&&ps(i,t)/c;return Math.acos(Math.min(Math.max(h,-1),1))}var kr=function(){let i=us();return function(t,e,s,n,r,o){let a,c;for(e||(e=3),s||(s=0),n?c=Math.min(n*e+s,t.length):c=t.length,a=s;a<c;a+=e)i[0]=t[a],i[1]=t[a+1],i[2]=t[a+2],r(i,i,o),t[a]=i[0],t[a+1]=i[1],t[a+2]=i[2];return t}}();var Ae=[0,0,0],Kt,$=class extends Ht{static get ZERO(){return Kt||(Kt=new $(0,0,0),Object.freeze(Kt)),Kt}constructor(t=0,e=0,s=0){super(-0,-0,-0),arguments.length===1&&dt(t)?this.copy(t):(z.debug&&(B(t),B(e),B(s)),this[0]=t,this[1]=e,this[2]=s)}set(t,e,s){return this[0]=t,this[1]=e,this[2]=s,this.check()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this.check()}fromObject(t){return z.debug&&(B(t.x),B(t.y),B(t.z)),this[0]=t.x,this[1]=t.y,this[2]=t.z,this.check()}toObject(t){return t.x=this[0],t.y=this[1],t.z=this[2],t}get ELEMENTS(){return 3}get z(){return this[2]}set z(t){this[2]=B(t)}angle(t){return di(this,t)}cross(t){return oi(this,this,t),this.check()}rotateX({radians:t,origin:e=Ae}){return hi(this,this,e,t),this.check()}rotateY({radians:t,origin:e=Ae}){return li(this,this,e,t),this.check()}rotateZ({radians:t,origin:e=Ae}){return fi(this,this,e,t),this.check()}transform(t){return this.transformAsPoint(t)}transformAsPoint(t){return Xt(this,this,t),this.check()}transformAsVector(t){return Yt(this,this,t),this.check()}transformByMatrix3(t){return ai(this,this,t),this.check()}transformByMatrix2(t){return ri(this,this,t),this.check()}transformByQuaternion(t){return ci(this,this,t),this.check()}};var Zt=class extends ut{toString(){let t="[";if(z.printRowMajor){t+="row-major:";for(let e=0;e<this.RANK;++e)for(let s=0;s<this.RANK;++s)t+=` ${this[s*this.RANK+e]}`}else{t+="column-major:";for(let e=0;e<this.ELEMENTS;++e)t+=` ${this[e]}`}return t+="]",t}getElementIndex(t,e){return e*this.RANK+t}getElement(t,e){return this[e*this.RANK+t]}setElement(t,e,s){return this[e*this.RANK+t]=B(s),this}getColumn(t,e=new Array(this.RANK).fill(-0)){let s=t*this.RANK;for(let n=0;n<this.RANK;++n)e[n]=this[s+n];return e}setColumn(t,e){let s=t*this.RANK;for(let n=0;n<this.RANK;++n)this[s+n]=e[n];return this}};function ms(i){return i[0]=1,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=1,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[10]=1,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i}function ui(i,t){if(i===t){let e=t[1],s=t[2],n=t[3],r=t[6],o=t[7],a=t[11];i[1]=t[4],i[2]=t[8],i[3]=t[12],i[4]=e,i[6]=t[9],i[7]=t[13],i[8]=s,i[9]=r,i[11]=t[14],i[12]=n,i[13]=o,i[14]=a}else i[0]=t[0],i[1]=t[4],i[2]=t[8],i[3]=t[12],i[4]=t[1],i[5]=t[5],i[6]=t[9],i[7]=t[13],i[8]=t[2],i[9]=t[6],i[10]=t[10],i[11]=t[14],i[12]=t[3],i[13]=t[7],i[14]=t[11],i[15]=t[15];return i}function pi(i,t){let e=t[0],s=t[1],n=t[2],r=t[3],o=t[4],a=t[5],c=t[6],h=t[7],l=t[8],f=t[9],d=t[10],m=t[11],b=t[12],u=t[13],x=t[14],M=t[15],_=e*a-s*o,p=e*c-n*o,g=e*h-r*o,y=s*c-n*a,v=s*h-r*a,S=n*h-r*c,R=l*u-f*b,T=l*x-d*b,E=l*M-m*b,A=f*x-d*u,I=f*M-m*u,C=d*M-m*x,P=_*C-p*I+g*A+y*E-v*T+S*R;return P?(P=1/P,i[0]=(a*C-c*I+h*A)*P,i[1]=(n*I-s*C-r*A)*P,i[2]=(u*S-x*v+M*y)*P,i[3]=(d*v-f*S-m*y)*P,i[4]=(c*E-o*C-h*T)*P,i[5]=(e*C-n*E+r*T)*P,i[6]=(x*g-b*S-M*p)*P,i[7]=(l*S-d*g+m*p)*P,i[8]=(o*I-a*E+h*R)*P,i[9]=(s*E-e*I-r*R)*P,i[10]=(b*v-u*g+M*_)*P,i[11]=(f*g-l*v-m*_)*P,i[12]=(a*T-o*A-c*R)*P,i[13]=(e*A-s*T+n*R)*P,i[14]=(u*p-b*y-x*_)*P,i[15]=(l*y-f*p+d*_)*P,i):null}function mi(i){let t=i[0],e=i[1],s=i[2],n=i[3],r=i[4],o=i[5],a=i[6],c=i[7],h=i[8],l=i[9],f=i[10],d=i[11],m=i[12],b=i[13],u=i[14],x=i[15],M=t*o-e*r,_=t*a-s*r,p=e*a-s*o,g=h*b-l*m,y=h*u-f*m,v=l*u-f*b,S=t*v-e*y+s*g,R=r*v-o*y+a*g,T=h*p-l*_+f*M,E=m*p-b*_+u*M;return c*S-n*R+x*T-d*E}function we(i,t,e){let s=t[0],n=t[1],r=t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],f=t[8],d=t[9],m=t[10],b=t[11],u=t[12],x=t[13],M=t[14],_=t[15],p=e[0],g=e[1],y=e[2],v=e[3];return i[0]=p*s+g*a+y*f+v*u,i[1]=p*n+g*c+y*d+v*x,i[2]=p*r+g*h+y*m+v*M,i[3]=p*o+g*l+y*b+v*_,p=e[4],g=e[5],y=e[6],v=e[7],i[4]=p*s+g*a+y*f+v*u,i[5]=p*n+g*c+y*d+v*x,i[6]=p*r+g*h+y*m+v*M,i[7]=p*o+g*l+y*b+v*_,p=e[8],g=e[9],y=e[10],v=e[11],i[8]=p*s+g*a+y*f+v*u,i[9]=p*n+g*c+y*d+v*x,i[10]=p*r+g*h+y*m+v*M,i[11]=p*o+g*l+y*b+v*_,p=e[12],g=e[13],y=e[14],v=e[15],i[12]=p*s+g*a+y*f+v*u,i[13]=p*n+g*c+y*d+v*x,i[14]=p*r+g*h+y*m+v*M,i[15]=p*o+g*l+y*b+v*_,i}function gi(i,t,e){let s=e[0],n=e[1],r=e[2],o,a,c,h,l,f,d,m,b,u,x,M;return t===i?(i[12]=t[0]*s+t[4]*n+t[8]*r+t[12],i[13]=t[1]*s+t[5]*n+t[9]*r+t[13],i[14]=t[2]*s+t[6]*n+t[10]*r+t[14],i[15]=t[3]*s+t[7]*n+t[11]*r+t[15]):(o=t[0],a=t[1],c=t[2],h=t[3],l=t[4],f=t[5],d=t[6],m=t[7],b=t[8],u=t[9],x=t[10],M=t[11],i[0]=o,i[1]=a,i[2]=c,i[3]=h,i[4]=l,i[5]=f,i[6]=d,i[7]=m,i[8]=b,i[9]=u,i[10]=x,i[11]=M,i[12]=o*s+l*n+b*r+t[12],i[13]=a*s+f*n+u*r+t[13],i[14]=c*s+d*n+x*r+t[14],i[15]=h*s+m*n+M*r+t[15]),i}function xi(i,t,e){let s=e[0],n=e[1],r=e[2];return i[0]=t[0]*s,i[1]=t[1]*s,i[2]=t[2]*s,i[3]=t[3]*s,i[4]=t[4]*n,i[5]=t[5]*n,i[6]=t[6]*n,i[7]=t[7]*n,i[8]=t[8]*r,i[9]=t[9]*r,i[10]=t[10]*r,i[11]=t[11]*r,i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15],i}function yi(i,t,e,s){let n=s[0],r=s[1],o=s[2],a=Math.sqrt(n*n+r*r+o*o),c,h,l,f,d,m,b,u,x,M,_,p,g,y,v,S,R,T,E,A,I,C,P,F;return a<1e-6?null:(a=1/a,n*=a,r*=a,o*=a,h=Math.sin(e),c=Math.cos(e),l=1-c,f=t[0],d=t[1],m=t[2],b=t[3],u=t[4],x=t[5],M=t[6],_=t[7],p=t[8],g=t[9],y=t[10],v=t[11],S=n*n*l+c,R=r*n*l+o*h,T=o*n*l-r*h,E=n*r*l-o*h,A=r*r*l+c,I=o*r*l+n*h,C=n*o*l+r*h,P=r*o*l-n*h,F=o*o*l+c,i[0]=f*S+u*R+p*T,i[1]=d*S+x*R+g*T,i[2]=m*S+M*R+y*T,i[3]=b*S+_*R+v*T,i[4]=f*E+u*A+p*I,i[5]=d*E+x*A+g*I,i[6]=m*E+M*A+y*I,i[7]=b*E+_*A+v*I,i[8]=f*C+u*P+p*F,i[9]=d*C+x*P+g*F,i[10]=m*C+M*P+y*F,i[11]=b*C+_*P+v*F,t!==i&&(i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i)}function bi(i,t,e){let s=Math.sin(e),n=Math.cos(e),r=t[4],o=t[5],a=t[6],c=t[7],h=t[8],l=t[9],f=t[10],d=t[11];return t!==i&&(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i[4]=r*n+h*s,i[5]=o*n+l*s,i[6]=a*n+f*s,i[7]=c*n+d*s,i[8]=h*n-r*s,i[9]=l*n-o*s,i[10]=f*n-a*s,i[11]=d*n-c*s,i}function Mi(i,t,e){let s=Math.sin(e),n=Math.cos(e),r=t[0],o=t[1],a=t[2],c=t[3],h=t[8],l=t[9],f=t[10],d=t[11];return t!==i&&(i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i[0]=r*n-h*s,i[1]=o*n-l*s,i[2]=a*n-f*s,i[3]=c*n-d*s,i[8]=r*s+h*n,i[9]=o*s+l*n,i[10]=a*s+f*n,i[11]=c*s+d*n,i}function vi(i,t,e){let s=Math.sin(e),n=Math.cos(e),r=t[0],o=t[1],a=t[2],c=t[3],h=t[4],l=t[5],f=t[6],d=t[7];return t!==i&&(i[8]=t[8],i[9]=t[9],i[10]=t[10],i[11]=t[11],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i[0]=r*n+h*s,i[1]=o*n+l*s,i[2]=a*n+f*s,i[3]=c*n+d*s,i[4]=h*n-r*s,i[5]=l*n-o*s,i[6]=f*n-a*s,i[7]=d*n-c*s,i}function _i(i,t){let e=t[0],s=t[1],n=t[2],r=t[3],o=e+e,a=s+s,c=n+n,h=e*o,l=s*o,f=s*a,d=n*o,m=n*a,b=n*c,u=r*o,x=r*a,M=r*c;return i[0]=1-f-b,i[1]=l+M,i[2]=d-x,i[3]=0,i[4]=l-M,i[5]=1-h-b,i[6]=m+u,i[7]=0,i[8]=d+x,i[9]=m-u,i[10]=1-h-f,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i}function Ai(i,t,e,s,n,r,o){let a=1/(e-t),c=1/(n-s),h=1/(r-o);return i[0]=r*2*a,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=r*2*c,i[6]=0,i[7]=0,i[8]=(e+t)*a,i[9]=(n+s)*c,i[10]=(o+r)*h,i[11]=-1,i[12]=0,i[13]=0,i[14]=o*r*2*h,i[15]=0,i}function gs(i,t,e,s,n){let r=1/Math.tan(t/2);if(i[0]=r/e,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=r,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[11]=-1,i[12]=0,i[13]=0,i[15]=0,n!=null&&n!==1/0){let o=1/(s-n);i[10]=(n+s)*o,i[14]=2*n*s*o}else i[10]=-1,i[14]=-2*s;return i}var wi=gs;function xs(i,t,e,s,n,r,o){let a=1/(t-e),c=1/(s-n),h=1/(r-o);return i[0]=-2*a,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=-2*c,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[10]=2*h,i[11]=0,i[12]=(t+e)*a,i[13]=(n+s)*c,i[14]=(o+r)*h,i[15]=1,i}var Pi=xs;function Ii(i,t,e,s){let n,r,o,a,c,h,l,f,d,m,b=t[0],u=t[1],x=t[2],M=s[0],_=s[1],p=s[2],g=e[0],y=e[1],v=e[2];return Math.abs(b-g)<1e-6&&Math.abs(u-y)<1e-6&&Math.abs(x-v)<1e-6?ms(i):(f=b-g,d=u-y,m=x-v,n=1/Math.sqrt(f*f+d*d+m*m),f*=n,d*=n,m*=n,r=_*m-p*d,o=p*f-M*m,a=M*d-_*f,n=Math.sqrt(r*r+o*o+a*a),n?(n=1/n,r*=n,o*=n,a*=n):(r=0,o=0,a=0),c=d*a-m*o,h=m*r-f*a,l=f*o-d*r,n=Math.sqrt(c*c+h*h+l*l),n?(n=1/n,c*=n,h*=n,l*=n):(c=0,h=0,l=0),i[0]=r,i[1]=c,i[2]=f,i[3]=0,i[4]=o,i[5]=h,i[6]=d,i[7]=0,i[8]=a,i[9]=l,i[10]=m,i[11]=0,i[12]=-(r*b+o*u+a*x),i[13]=-(c*b+h*u+l*x),i[14]=-(f*b+d*u+m*x),i[15]=1,i)}function ys(){let i=new tt(4);return tt!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0,i[3]=0),i}function Si(i,t,e){let s=t[0],n=t[1],r=t[2],o=t[3];return i[0]=e[0]*s+e[4]*n+e[8]*r+e[12]*o,i[1]=e[1]*s+e[5]*n+e[9]*r+e[13]*o,i[2]=e[2]*s+e[6]*n+e[10]*r+e[14]*o,i[3]=e[3]*s+e[7]*n+e[11]*r+e[15]*o,i}var Wr=function(){let i=ys();return function(t,e,s,n,r,o){let a,c;for(e||(e=4),s||(s=0),n?c=Math.min(n*e+s,t.length):c=t.length,a=s;a<c;a+=e)i[0]=t[a],i[1]=t[a+1],i[2]=t[a+2],i[3]=t[a+3],r(i,i,o),t[a]=i[0],t[a+1]=i[1],t[a+2]=i[2],t[a+3]=i[3];return t}}();var Se;(function(i){i[i.COL0ROW0=0]="COL0ROW0",i[i.COL0ROW1=1]="COL0ROW1",i[i.COL0ROW2=2]="COL0ROW2",i[i.COL0ROW3=3]="COL0ROW3",i[i.COL1ROW0=4]="COL1ROW0",i[i.COL1ROW1=5]="COL1ROW1",i[i.COL1ROW2=6]="COL1ROW2",i[i.COL1ROW3=7]="COL1ROW3",i[i.COL2ROW0=8]="COL2ROW0",i[i.COL2ROW1=9]="COL2ROW1",i[i.COL2ROW2=10]="COL2ROW2",i[i.COL2ROW3=11]="COL2ROW3",i[i.COL3ROW0=12]="COL3ROW0",i[i.COL3ROW1=13]="COL3ROW1",i[i.COL3ROW2=14]="COL3ROW2",i[i.COL3ROW3=15]="COL3ROW3"})(Se||(Se={}));var bs=45*Math.PI/180,Ms=1,Pe=.1,Ie=500,vs=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),H=class extends Zt{static get IDENTITY(){return As()}static get ZERO(){return _s()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Se}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,e,s,n,r,o,a,c,h,l,f,d,m,b,u,x){return this[0]=t,this[1]=e,this[2]=s,this[3]=n,this[4]=r,this[5]=o,this[6]=a,this[7]=c,this[8]=h,this[9]=l,this[10]=f,this[11]=d,this[12]=m,this[13]=b,this[14]=u,this[15]=x,this.check()}setRowMajor(t,e,s,n,r,o,a,c,h,l,f,d,m,b,u,x){return this[0]=t,this[1]=r,this[2]=h,this[3]=m,this[4]=e,this[5]=o,this[6]=l,this[7]=b,this[8]=s,this[9]=a,this[10]=f,this[11]=u,this[12]=n,this[13]=c,this[14]=d,this[15]=x,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(vs)}fromObject(t){return this.check()}fromQuaternion(t){return _i(this,t),this.check()}frustum(t){let{left:e,right:s,bottom:n,top:r,near:o=Pe,far:a=Ie}=t;return a===1/0?ws(this,e,s,n,r,o):Ai(this,e,s,n,r,o,a),this.check()}lookAt(t){let{eye:e,center:s=[0,0,0],up:n=[0,1,0]}=t;return Ii(this,e,s,n),this.check()}ortho(t){let{left:e,right:s,bottom:n,top:r,near:o=Pe,far:a=Ie}=t;return Pi(this,e,s,n,r,o,a),this.check()}orthographic(t){let{fovy:e=bs,aspect:s=Ms,focalDistance:n=1,near:r=Pe,far:o=Ie}=t;Ti(e);let a=e/2,c=n*Math.tan(a),h=c*s;return this.ortho({left:-h,right:h,bottom:-c,top:c,near:r,far:o})}perspective(t){let{fovy:e=45*Math.PI/180,aspect:s=1,near:n=.1,far:r=500}=t;return Ti(e),wi(this,e,s,n,r),this.check()}determinant(){return mi(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,e){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],e=e||[-0,-0,-0];let s=this.getScale(e),n=1/s[0],r=1/s[1],o=1/s[2];return t[0]=this[0]*n,t[1]=this[1]*r,t[2]=this[2]*o,t[3]=0,t[4]=this[4]*n,t[5]=this[5]*r,t[6]=this[6]*o,t[7]=0,t[8]=this[8]*n,t[9]=this[9]*r,t[10]=this[10]*o,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,e){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],e=e||[-0,-0,-0];let s=this.getScale(e),n=1/s[0],r=1/s[1],o=1/s[2];return t[0]=this[0]*n,t[1]=this[1]*r,t[2]=this[2]*o,t[3]=this[4]*n,t[4]=this[5]*r,t[5]=this[6]*o,t[6]=this[8]*n,t[7]=this[9]*r,t[8]=this[10]*o,t}transpose(){return ui(this,this),this.check()}invert(){return pi(this,this),this.check()}multiplyLeft(t){return we(this,t,this),this.check()}multiplyRight(t){return we(this,this,t),this.check()}rotateX(t){return bi(this,this,t),this.check()}rotateY(t){return Mi(this,this,t),this.check()}rotateZ(t){return vi(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,e){return yi(this,this,t,e),this.check()}scale(t){return xi(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return gi(this,this,t),this.check()}transform(t,e){return t.length===4?(e=Si(e||[-0,-0,-0,-0],t,this),Wt(e,4),e):this.transformAsPoint(t,e)}transformAsPoint(t,e){let{length:s}=t,n;switch(s){case 2:n=si(e||[-0,-0],t,this);break;case 3:n=Xt(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Wt(n,t.length),n}transformAsVector(t,e){let s;switch(t.length){case 2:s=ni(e||[-0,-0],t,this);break;case 3:s=Yt(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Wt(s,t.length),s}transformPoint(t,e){return this.transformAsPoint(t,e)}transformVector(t,e){return this.transformAsPoint(t,e)}transformDirection(t,e){return this.transformAsVector(t,e)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,e,s){return this.identity().translate([t,e,s])}},Qt,Jt;function _s(){return Qt||(Qt=new H([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Qt)),Qt}function As(){return Jt||(Jt=new H,Object.freeze(Jt)),Jt}function Ti(i){if(i>Math.PI*2)throw Error("expected radians")}function ws(i,t,e,s,n,r){let o=2*r/(e-t),a=2*r/(n-s),c=(e+t)/(e-t),h=(n+s)/(n-s),l=-1,f=-1,d=-2*r;return i[0]=o,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=a,i[6]=0,i[7]=0,i[8]=c,i[9]=h,i[10]=l,i[11]=f,i[12]=0,i[13]=0,i[14]=d,i[15]=0,i}var et=class{id;matrix=new H;display=!0;position=new $;rotation=new $;scale=new $(1,1,1);userData={};props={};constructor(t={}){let{id:e}=t;this.id=e||O(this.constructor.name),this._setScenegraphNodeProps(t)}getBounds(){return null}destroy(){}delete(){this.destroy()}setProps(t){return this._setScenegraphNodeProps(t),this}toString(){return`{type: ScenegraphNode, id: ${this.id})}`}setPosition(t){return this.position=t,this}setRotation(t){return this.rotation=t,this}setScale(t){return this.scale=t,this}setMatrix(t,e=!0){e?this.matrix.copy(t):this.matrix=t}setMatrixComponents(t){let{position:e,rotation:s,scale:n,update:r=!0}=t;return e&&this.setPosition(e),s&&this.setRotation(s),n&&this.setScale(n),r&&this.updateMatrix(),this}updateMatrix(){let t=this.position,e=this.rotation,s=this.scale;return this.matrix.identity(),this.matrix.translate(t),this.matrix.rotateXYZ(e),this.matrix.scale(s),this}update(t={}){let{position:e,rotation:s,scale:n}=t;return e&&this.setPosition(e),s&&this.setRotation(s),n&&this.setScale(n),this.updateMatrix(),this}getCoordinateUniforms(t,e){e=e||this.matrix;let s=new H(t).multiplyRight(e),n=s.invert(),r=n.transpose();return{viewMatrix:t,modelMatrix:e,objectMatrix:e,worldMatrix:s,worldInverseMatrix:n,worldInverseTransposeMatrix:r}}_setScenegraphNodeProps(t){"position"in t&&this.setPosition(t.position),"rotation"in t&&this.setRotation(t.rotation),"scale"in t&&this.setScale(t.scale),"matrix"in t&&this.setMatrix(t.matrix),Object.assign(this.props,t)}};var Ci=L(j(),1);var mt=class extends et{children;constructor(t={}){t=Array.isArray(t)?{children:t}:t;let{children:e=[]}=t;Ci.log.assert(e.every(s=>s instanceof et),"every child must an instance of ScenegraphNode"),super(t),this.children=e}getBounds(){let t=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]];return this.traverse((e,{worldMatrix:s})=>{let n=e.getBounds();if(!n)return;let[r,o]=n,a=new $(r).add(o).divide([2,2,2]);s.transformAsPoint(a,a);let c=new $(o).subtract(r).divide([2,2,2]);s.transformAsVector(c,c);for(let h=0;h<8;h++){let l=new $(h&1?-1:1,h&2?-1:1,h&4?-1:1).multiply(c).add(a);for(let f=0;f<3;f++)t[0][f]=Math.min(t[0][f],l[f]),t[1][f]=Math.max(t[1][f],l[f])}}),Number.isFinite(t[0][0])?t:null}destroy(){this.children.forEach(t=>t.destroy()),this.removeAll(),super.destroy()}add(...t){for(let e of t)Array.isArray(e)?this.add(...e):this.children.push(e);return this}remove(t){let e=this.children,s=e.indexOf(t);return s>-1&&e.splice(s,1),this}removeAll(){return this.children=[],this}traverse(t,{worldMatrix:e=new H}={}){let s=new H(e).multiplyRight(this.matrix);for(let n of this.children)n instanceof mt?n.traverse(t,{worldMatrix:s}):t(n,{worldMatrix:s})}};var te=class extends et{model;bounds=null;managedResources;constructor(t){super(t),this.model=t.model,this.managedResources=t.managedResources||[],this.bounds=t.bounds||null,this.setProps(t)}destroy(){this.model&&(this.model.destroy(),this.model=null),this.managedResources.forEach(t=>t.destroy()),this.managedResources=[]}getBounds(){return this.bounds}draw(t){return this.model.draw(t)}};var Ps={x:[2,0,1],y:[0,1,2],z:[1,2,0]},st=class extends D{constructor(t={}){let{id:e=O("truncated-code-geometry")}=t,{indices:s,attributes:n}=Is(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{POSITION:{size:3,value:n.POSITION},NORMAL:{size:3,value:n.NORMAL},TEXCOORD_0:{size:2,value:n.TEXCOORD_0},...t.attributes}})}};function Is(i={}){let{bottomRadius:t=0,topRadius:e=0,height:s=1,nradial:n=10,nvertical:r=10,verticalAxis:o="y",topCap:a=!1,bottomCap:c=!1}=i,h=(a?2:0)+(c?2:0),l=(n+1)*(r+1+h),f=Math.atan2(t-e,s),d=Math.sin,m=Math.cos,b=Math.PI,u=m(f),x=d(f),M=a?-2:0,_=r+(c?2:0),p=n+1,g=new Uint16Array(n*(r+h)*6),y=Ps[o],v=new Float32Array(l*3),S=new Float32Array(l*3),R=new Float32Array(l*2),T=0,E=0;for(let A=M;A<=_;A++){let I=A/r,C=s*I,P;A<0?(C=0,I=1,P=t):A>r?(C=s,I=1,P=e):P=t+(e-t)*(A/r),(A===-2||A===r+2)&&(P=0,I=0),C-=s/2;for(let F=0;F<p;F++){let K=d(F*b*2/n),W=m(F*b*2/n);v[T+y[0]]=K*P,v[T+y[1]]=C,v[T+y[2]]=W*P,S[T+y[0]]=A<0||A>r?0:K*u,S[T+y[1]]=A<0?-1:A>r?1:x,S[T+y[2]]=A<0||A>r?0:W*u,R[E+0]=F/n,R[E+1]=I,E+=2,T+=3}}for(let A=0;A<r+h;A++)for(let I=0;I<n;I++){let C=(A*n+I)*6;g[C+0]=p*(A+0)+0+I,g[C+1]=p*(A+0)+1+I,g[C+2]=p*(A+1)+1+I,g[C+3]=p*(A+0)+0+I,g[C+4]=p*(A+1)+1+I,g[C+5]=p*(A+1)+0+I}return{indices:g,attributes:{POSITION:v,NORMAL:S,TEXCOORD_0:R}}}var ee=class extends st{constructor(t={}){let{id:e=O("cone-geometry"),radius:s=1,cap:n=!0}=t;super({...t,id:e,topRadius:0,topCap:Boolean(n),bottomCap:Boolean(n),bottomRadius:s})}};var ie=class extends D{constructor(t={}){let{id:e=O("cube-geometry"),indices:s=!0}=t;super(s?{...t,id:e,topology:"triangle-list",indices:{size:1,value:Ss},attributes:{...Ls,...t.attributes}}:{...t,id:e,topology:"triangle-list",indices:void 0,attributes:{...Ns,...t.attributes}})}},Ss=new Uint16Array([0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]),Ts=new Float32Array([-1,-1,1,1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,1,1,1,1,1,1,1,-1,-1,-1,-1,1,-1,-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1,0,1,1,1,1,1,1,1,0,0,1,0,0,0,1,0,1,0,1,1,1,0,1,1,0,0,1,0,1,0,1]),Ls={POSITION:{size:3,value:Ts},NORMAL:{size:3,value:Cs},TEXCOORD_0:{size:2,value:Os}},Ns={POSITION:{size:3,value:Rs},TEXCOORD_0:{size:2,value:Es},COLOR_0:{size:3,value:ks}};var se=class extends st{constructor(t={}){let{id:e=O("cylinder-geometry"),radius:s=1}=t;super({...t,id:e,bottomRadius:s,topRadius:s})}};var Fs=[-1,0,0,0,1,0,0,0,-1,0,0,1,0,-1,0,1,0,0],zs=[3,4,5,3,5,1,3,1,0,3,0,4,4,0,2,4,2,5,2,0,1,5,2,1],ne=class extends D{constructor(t={}){let{id:e=O("ico-sphere-geometry")}=t,{indices:s,attributes:n}=Ds(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{...n,...t.attributes}})}};function Ds(i){let{iterations:t=0}=i,e=Math.PI,s=e*2,n=[...Fs],r=[...zs];n.push(),r.push();let o=(()=>{let l={};return(f,d)=>{f*=3,d*=3;let m=f<d?f:d,b=f>d?f:d,u=`${m}|${b}`;if(u in l)return l[u];let x=n[f],M=n[f+1],_=n[f+2],p=n[d],g=n[d+1],y=n[d+2],v=(x+p)/2,S=(M+g)/2,R=(_+y)/2,T=Math.sqrt(v*v+S*S+R*R);return v/=T,S/=T,R/=T,n.push(v,S,R),l[u]=n.length/3-1}})();for(let l=0;l<t;l++){let f=[];for(let d=0;d<r.length;d+=3){let m=o(r[d+0],r[d+1]),b=o(r[d+1],r[d+2]),u=o(r[d+2],r[d+0]);f.push(u,r[d+0],m,m,r[d+1],b,b,r[d+2],u,m,b,u)}r=f}let a=new Array(n.length),c=new Array(n.length/3*2),h=r.length;for(let l=h-3;l>=0;l-=3){let f=r[l+0],d=r[l+1],m=r[l+2],b=f*3,u=d*3,x=m*3,M=f*2,_=d*2,p=m*2,g=n[b+0],y=n[b+1],v=n[b+2],S=Math.acos(v/Math.sqrt(g*g+y*y+v*v)),R=Math.atan2(y,g)+e,T=S/e,E=1-R/s,A=n[u+0],I=n[u+1],C=n[u+2],P=Math.acos(C/Math.sqrt(A*A+I*I+C*C)),F=Math.atan2(I,A)+e,K=P/e,W=1-F/s,Tt=n[x+0],Ct=n[x+1],Ot=n[x+2],Fi=Math.acos(Ot/Math.sqrt(Tt*Tt+Ct*Ct+Ot*Ot)),zi=Math.atan2(Ct,Tt)+e,ke=Fi/e,Rt=1-zi/s,Di=[Tt-A,Ct-I,Ot-C],Bi=[g-A,y-I,v-C],G=new $(Di).cross(Bi).normalize(),k;(E===0||W===0||Rt===0)&&(E===0||E>.5)&&(W===0||W>.5)&&(Rt===0||Rt>.5)&&(n.push(n[b+0],n[b+1],n[b+2]),k=n.length/3-1,r.push(k),c[k*2+0]=1,c[k*2+1]=T,a[k*3+0]=G.x,a[k*3+1]=G.y,a[k*3+2]=G.z,n.push(n[u+0],n[u+1],n[u+2]),k=n.length/3-1,r.push(k),c[k*2+0]=1,c[k*2+1]=K,a[k*3+0]=G.x,a[k*3+1]=G.y,a[k*3+2]=G.z,n.push(n[x+0],n[x+1],n[x+2]),k=n.length/3-1,r.push(k),c[k*2+0]=1,c[k*2+1]=ke,a[k*3+0]=G.x,a[k*3+1]=G.y,a[k*3+2]=G.z),a[b+0]=a[u+0]=a[x+0]=G.x,a[b+1]=a[u+1]=a[x+1]=G.y,a[b+2]=a[u+2]=a[x+2]=G.z,c[M+0]=E,c[M+1]=T,c[_+0]=W,c[_+1]=K,c[p+0]=Rt,c[p+1]=ke}return{indices:{size:1,value:new Uint16Array(r)},attributes:{POSITION:{size:3,value:new Float32Array(n)},NORMAL:{size:3,value:new Float32Array(a)},TEXCOORD_0:{size:2,value:new Float32Array(c)}}}}function Oi(i){let{indices:t,attributes:e}=i;if(!t)return i;let s=t.value.length,n={};for(let r in e){let o=e[r],{constant:a,value:c,size:h}=o;if(a||!h)continue;let l=new c.constructor(s*h);for(let f=0;f<s;++f){let d=t.value[f];for(let m=0;m<h;m++)l[f*h+m]=c[d*h+m]}n[r]={size:h,value:l}}return{attributes:Object.assign({},e,n)}}var re=class extends D{constructor(t={}){let{id:e=O("plane-geometry")}=t,{indices:s,attributes:n}=Bs(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{...n,...t.attributes}})}};function Bs(i){let{type:t="x,y",offset:e=0,flipCull:s=!1,unpack:n=!1}=i,r=t.split(","),o=i[`${r[0]}len`]||1,a=i[`${r[1]}len`]||1,c=i[`n${r[0]}`]||1,h=i[`n${r[1]}`]||1,l=(c+1)*(h+1),f=new Float32Array(l*3),d=new Float32Array(l*3),m=new Float32Array(l*2);s&&(o=-o);let b=0,u=0;for(let p=0;p<=h;p++)for(let g=0;g<=c;g++){let y=g/c,v=p/h;switch(m[b+0]=s?1-y:y,m[b+1]=v,t){case"x,y":f[u+0]=o*y-o*.5,f[u+1]=a*v-a*.5,f[u+2]=e,d[u+0]=0,d[u+1]=0,d[u+2]=s?1:-1;break;case"x,z":f[u+0]=o*y-o*.5,f[u+1]=e,f[u+2]=a*v-a*.5,d[u+0]=0,d[u+1]=s?1:-1,d[u+2]=0;break;case"y,z":f[u+0]=e,f[u+1]=o*y-o*.5,f[u+2]=a*v-a*.5,d[u+0]=s?1:-1,d[u+1]=0,d[u+2]=0;break;default:throw new Error("PlaneGeometry: unknown type")}b+=2,u+=3}let x=c+1,M=new Uint16Array(c*h*6);for(let p=0;p<h;p++)for(let g=0;g<c;g++){let y=(p*c+g)*6;M[y+0]=(p+0)*x+g,M[y+1]=(p+1)*x+g,M[y+2]=(p+0)*x+g+1,M[y+3]=(p+1)*x+g,M[y+4]=(p+1)*x+g+1,M[y+5]=(p+0)*x+g+1}let _={indices:{size:1,value:M},attributes:{POSITION:{size:3,value:f},NORMAL:{size:3,value:d},TEXCOORD_0:{size:2,value:m}}};return n?Oi(_):_}var oe=class extends D{constructor(t={}){let{id:e=O("sphere-geometry")}=t,{indices:s,attributes:n}=Us(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{...n,...t.attributes}})}};function Us(i){let{nlat:t=10,nlong:e=10}=i,r=Math.PI-0,o=0,c=2*Math.PI-o,h=(t+1)*(e+1),l=(M,_,p,g,y)=>i.radius||1,f=new Float32Array(h*3),d=new Float32Array(h*3),m=new Float32Array(h*2),b=h>65535?Uint32Array:Uint16Array,u=new b(t*e*6);for(let M=0;M<=t;M++)for(let _=0;_<=e;_++){let p=_/e,g=M/t,y=_+M*(e+1),v=y*2,S=y*3,R=c*p,T=r*g,E=Math.sin(R),A=Math.cos(R),I=Math.sin(T),C=Math.cos(T),P=A*I,F=C,K=E*I,W=l(P,F,K,p,g);f[S+0]=W*P,f[S+1]=W*F,f[S+2]=W*K,d[S+0]=P,d[S+1]=F,d[S+2]=K,m[v+0]=p,m[v+1]=1-g}let x=e+1;for(let M=0;M<e;M++)for(let _=0;_<t;_++){let p=(M*t+_)*6;u[p+0]=_*x+M,u[p+1]=_*x+M+1,u[p+2]=(_+1)*x+M,u[p+3]=(_+1)*x+M,u[p+4]=_*x+M+1,u[p+5]=(_+1)*x+M+1}return{indices:{size:1,value:u},attributes:{POSITION:{size:3,value:f},NORMAL:{size:3,value:d},TEXCOORD_0:{size:2,value:m}}}}function Ri(){let i=1,t=1;return()=>(i=Math.sin(t*17.23),t=Math.cos(i*27.92),$s(Math.abs(i*t)*1432.71))}function $s(i){return i-Math.floor(i)}var ki=L(rt(),1);var wt=L(j(),1),gt=class{current;next;constructor(t){this.current=t.current,this.next=t.next}destroy(){this.current?.destroy(),this.next?.destroy()}swap(){let t=this.current;this.current=this.next,this.next=t}},xt=class extends gt{constructor(t,e){e={...e};let s=e.colorAttachments?.map(o=>typeof o!="string"?o:t.createTexture({format:o,usage:wt.Texture.COPY_DST|wt.Texture.RENDER_ATTACHMENT})),n=t.createFramebuffer({...e,colorAttachments:s});s=e.colorAttachments?.map(o=>typeof o!="string"?o:t.createTexture({format:o,usage:wt.Texture.COPY_DST|wt.Texture.RENDER_ATTACHMENT}));let r=t.createFramebuffer({...e,colorAttachments:s});super({current:n,next:r})}resize(t){if(t.width===this.current.width&&t.height===this.current.height)return!1;let{current:e,next:s}=this;return this.current=e.clone(t),e.destroy(),this.next=s.clone(t),s.destroy(),!0}},ae=class extends gt{constructor(t,e){super({current:t.createBuffer(e),next:t.createBuffer(e)})}resize(t){if(t.byteLength===this.current.byteLength)return!1;let{current:e,next:s}=this;return this.current=e.clone(t),e.destroy(),this.next=s.clone(t),s.destroy(),!0}};function Ei(i){let{shaderPass:t,action:e,shadingLanguage:s}=i;switch(e){case"filter":let n=`${t.name}_filterColor_ext`;return s==="wgsl"?js(n):Vs(n);case"sample":let r=`${t.name}_sampleColor`;return s==="wgsl"?Gs(r):qs(r);default:throw new Error(`${t.name} no fragment shader generated for shader pass`)}}function js(i){return`// Binding 0:1 is reserved for shader passes
78
78
  @group(0) @binding(0) var<uniform> brightnessContrast : brightnessContrastUniforms;
79
79
  @group(0) @binding(1) var texture: texture_2d<f32>;
80
80
  @group(0) @binding(2) var sampler: sampler;
package/dist/index.cjs CHANGED
@@ -1219,10 +1219,13 @@ var AsyncTexture = class {
1219
1219
  this.initAsync(props);
1220
1220
  }
1221
1221
  async initAsync(props) {
1222
- let resolveReady;
1223
- let rejectReady;
1224
1222
  const asyncData = props.data;
1225
- const data = await awaitAllPromises(asyncData).then(resolveReady, rejectReady);
1223
+ let data;
1224
+ try {
1225
+ data = await awaitAllPromises(asyncData);
1226
+ } catch (error) {
1227
+ this.rejectReady(error);
1228
+ }
1226
1229
  if (this.destroyed) {
1227
1230
  return;
1228
1231
  }
@@ -1231,6 +1234,7 @@ var AsyncTexture = class {
1231
1234
  this.sampler = this.texture.sampler;
1232
1235
  this.view = this.texture.view;
1233
1236
  this.isReady = true;
1237
+ this.resolveReady();
1234
1238
  }
1235
1239
  destroy() {
1236
1240
  if (this.texture) {
@@ -1641,6 +1645,7 @@ var _Model = class {
1641
1645
  if (buffers.indices) {
1642
1646
  import_core7.log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)();
1643
1647
  }
1648
+ this.bufferLayout = (0, import_core7.sortedBufferLayoutByShaderSourceLocations)(this.pipeline.shaderLayout, this.bufferLayout);
1644
1649
  const bufferLayoutHelper = new import_core7._BufferLayoutHelper(this.bufferLayout);
1645
1650
  for (const [bufferName, buffer] of Object.entries(buffers)) {
1646
1651
  const bufferLayout = bufferLayoutHelper.getBufferLayout(bufferName);
@@ -1655,7 +1660,8 @@ var _Model = class {
1655
1660
  for (const attributeName of attributeNames) {
1656
1661
  const attributeInfo = this._attributeInfos[attributeName];
1657
1662
  if (attributeInfo) {
1658
- this.vertexArray.setBuffer(attributeInfo.location, buffer);
1663
+ const location = this.device.type === "webgpu" ? bufferLayoutHelper.getBufferIndex(attributeInfo.bufferName) : attributeInfo.location;
1664
+ this.vertexArray.setBuffer(location, buffer);
1659
1665
  set = true;
1660
1666
  }
1661
1667
  }