@luma.gl/engine 9.3.6 → 9.4.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/animator.d.ts +42 -0
- package/dist/animation/animator.d.ts.map +1 -0
- package/dist/animation/animator.js +53 -0
- package/dist/animation/animator.js.map +1 -0
- package/dist/animation-loop/animation-loop.d.ts +14 -2
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +40 -22
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/animation-loop/animation-props.d.ts +2 -0
- package/dist/animation-loop/animation-props.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.d.ts +1 -0
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +3 -0
- package/dist/animation-loop/make-animation-loop.js.map +1 -1
- package/dist/application-utils/load-file.d.ts +2 -0
- package/dist/application-utils/load-file.d.ts.map +1 -1
- package/dist/application-utils/load-file.js +31 -5
- package/dist/application-utils/load-file.js.map +1 -1
- package/dist/compute/buffer-transform.d.ts +5 -1
- package/dist/compute/buffer-transform.d.ts.map +1 -1
- package/dist/compute/buffer-transform.js +7 -3
- package/dist/compute/buffer-transform.js.map +1 -1
- package/dist/compute/computation.d.ts +20 -8
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +34 -13
- package/dist/compute/computation.js.map +1 -1
- package/dist/compute/swap.d.ts.map +1 -1
- package/dist/compute/swap.js +17 -0
- package/dist/compute/swap.js.map +1 -1
- package/dist/dist.dev.js +4100 -1979
- package/dist/dist.min.js +288 -42
- package/dist/dynamic-buffer/dynamic-buffer.d.ts +171 -0
- package/dist/dynamic-buffer/dynamic-buffer.d.ts.map +1 -0
- package/dist/dynamic-buffer/dynamic-buffer.js +316 -0
- package/dist/dynamic-buffer/dynamic-buffer.js.map +1 -0
- package/dist/dynamic-texture/dynamic-texture.d.ts +14 -1
- package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
- package/dist/dynamic-texture/dynamic-texture.js +31 -2
- package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
- package/dist/dynamic-texture/texture-binding-source.d.ts +55 -0
- package/dist/dynamic-texture/texture-binding-source.d.ts.map +1 -0
- package/dist/dynamic-texture/texture-binding-source.js +55 -0
- package/dist/dynamic-texture/texture-binding-source.js.map +1 -0
- package/dist/dynamic-texture/texture-data.d.ts +5 -3
- package/dist/dynamic-texture/texture-data.d.ts.map +1 -1
- package/dist/dynamic-texture/texture-data.js +5 -0
- package/dist/dynamic-texture/texture-data.js.map +1 -1
- package/dist/dynamic-texture/video-texture.d.ts +101 -0
- package/dist/dynamic-texture/video-texture.d.ts.map +1 -0
- package/dist/dynamic-texture/video-texture.js +272 -0
- package/dist/dynamic-texture/video-texture.js.map +1 -0
- package/dist/geometries/cube-geometry.d.ts +1 -0
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- package/dist/geometries/cube-geometry.js +22 -2
- package/dist/geometries/cube-geometry.js.map +1 -1
- package/dist/geometries/plane-geometry.d.ts +10 -0
- package/dist/geometries/plane-geometry.d.ts.map +1 -1
- package/dist/geometries/plane-geometry.js.map +1 -1
- package/dist/geometry/geometry-utils.d.ts +36 -1
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js +137 -2
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.d.ts +52 -33
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +70 -19
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.d.ts +37 -4
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +44 -36
- package/dist/geometry/gpu-geometry.js.map +1 -1
- package/dist/index.cjs +3990 -1961
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +20 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/dist/material/material-factory.d.ts +2 -1
- package/dist/material/material-factory.d.ts.map +1 -1
- package/dist/material/material-factory.js.map +1 -1
- package/dist/material/material.d.ts +29 -10
- package/dist/material/material.d.ts.map +1 -1
- package/dist/material/material.js +84 -21
- package/dist/material/material.js.map +1 -1
- package/dist/model/model.d.ts +81 -23
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +312 -78
- package/dist/model/model.js.map +1 -1
- package/dist/model/split-uniforms-and-bindings.d.ts +5 -2
- package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
- package/dist/model/split-uniforms-and-bindings.js.map +1 -1
- package/dist/models/billboard-texture-model.d.ts +5 -2
- package/dist/models/billboard-texture-model.d.ts.map +1 -1
- package/dist/models/billboard-texture-model.js +28 -10
- package/dist/models/billboard-texture-model.js.map +1 -1
- package/dist/modules/picking/index-color-picking.d.ts +24 -0
- package/dist/modules/picking/index-color-picking.d.ts.map +1 -0
- package/dist/modules/picking/index-color-picking.js +205 -0
- package/dist/modules/picking/index-color-picking.js.map +1 -0
- package/dist/modules/picking/index-picking.d.ts +3 -3
- package/dist/modules/picking/index-picking.d.ts.map +1 -1
- package/dist/modules/picking/index-picking.js +23 -6
- package/dist/modules/picking/index-picking.js.map +1 -1
- package/dist/modules/picking/picking-manager.d.ts +21 -0
- package/dist/modules/picking/picking-manager.d.ts.map +1 -1
- package/dist/modules/picking/picking-manager.js +100 -0
- package/dist/modules/picking/picking-manager.js.map +1 -1
- package/dist/modules/picking/picking-uniforms.d.ts +4 -4
- package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
- package/dist/modules/picking/picking-uniforms.js +3 -0
- package/dist/modules/picking/picking-uniforms.js.map +1 -1
- package/dist/modules/picking/picking.d.ts +5 -1
- package/dist/modules/picking/picking.d.ts.map +1 -1
- package/dist/modules/picking/picking.js +6 -0
- package/dist/modules/picking/picking.js.map +1 -1
- package/dist/passes/get-fragment-shader.js +4 -4
- package/dist/passes/shader-pass-renderer.d.ts +92 -25
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
- package/dist/passes/shader-pass-renderer.js +466 -72
- package/dist/passes/shader-pass-renderer.js.map +1 -1
- package/dist/passes/texture-transform-module.d.ts +10 -0
- package/dist/passes/texture-transform-module.d.ts.map +1 -0
- package/dist/passes/texture-transform-module.js +50 -0
- package/dist/passes/texture-transform-module.js.map +1 -0
- package/dist/shader-inputs.d.ts +33 -16
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +42 -12
- package/dist/shader-inputs.js.map +1 -1
- package/dist/utils/buffer-layout-helper.d.ts +0 -1
- package/dist/utils/buffer-layout-helper.d.ts.map +1 -1
- package/dist/utils/buffer-layout-helper.js +2 -11
- package/dist/utils/buffer-layout-helper.js.map +1 -1
- package/dist/utils/buffer-layout-order.d.ts.map +1 -1
- package/dist/utils/buffer-layout-order.js +4 -15
- package/dist/utils/buffer-layout-order.js.map +1 -1
- package/dist/utils/shader-module-utils.d.ts +2 -0
- package/dist/utils/shader-module-utils.d.ts.map +1 -1
- package/dist/utils/shader-module-utils.js +64 -3
- package/dist/utils/shader-module-utils.js.map +1 -1
- package/package.json +2 -2
- package/src/animation/animator.ts +79 -0
- package/src/animation-loop/animation-loop.ts +56 -22
- package/src/animation-loop/animation-props.ts +2 -0
- package/src/animation-loop/make-animation-loop.ts +4 -0
- package/src/application-utils/load-file.ts +38 -5
- package/src/compute/buffer-transform.ts +14 -5
- package/src/compute/computation.ts +53 -21
- package/src/compute/swap.ts +19 -0
- package/src/dynamic-buffer/dynamic-buffer.ts +453 -0
- package/src/dynamic-texture/dynamic-texture.ts +36 -3
- package/src/dynamic-texture/texture-binding-source.ts +94 -0
- package/src/dynamic-texture/texture-data.ts +12 -4
- package/src/dynamic-texture/video-texture.ts +334 -0
- package/src/geometries/cube-geometry.ts +24 -2
- package/src/geometries/plane-geometry.ts +10 -0
- package/src/geometry/geometry-utils.ts +209 -4
- package/src/geometry/geometry.ts +113 -36
- package/src/geometry/gpu-geometry.ts +61 -41
- package/src/index.ts +50 -14
- package/src/material/material-factory.ts +5 -1
- package/src/material/material.ts +123 -27
- package/src/model/model.ts +441 -102
- package/src/model/split-uniforms-and-bindings.ts +7 -3
- package/src/models/billboard-texture-model.ts +33 -12
- package/src/modules/picking/index-color-picking.ts +212 -0
- package/src/modules/picking/index-picking.ts +23 -6
- package/src/modules/picking/picking-manager.ts +141 -0
- package/src/modules/picking/picking-uniforms.ts +7 -4
- package/src/modules/picking/picking.ts +8 -0
- package/src/passes/get-fragment-shader.ts +4 -4
- package/src/passes/shader-pass-renderer.ts +691 -89
- package/src/passes/texture-transform-module.ts +52 -0
- package/src/shader-inputs.ts +65 -17
- package/src/utils/buffer-layout-helper.ts +2 -14
- package/src/utils/buffer-layout-order.ts +14 -24
- package/src/utils/shader-module-utils.ts +109 -3
- package/dist/geometry/gpu-table.d.ts +0 -1
- package/dist/geometry/gpu-table.d.ts.map +0 -1
- package/dist/geometry/gpu-table.js +0 -46
- package/dist/geometry/gpu-table.js.map +0 -1
- package/src/dynamic-texture/texture-data.ts.disabled +0 -296
- package/src/geometry/gpu-table.ts +0 -45
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 Wn=Object.create;var Et=Object.defineProperty;var Yn=Object.getOwnPropertyDescriptor;var Kn=Object.getOwnPropertyNames;var Zn=Object.getPrototypeOf,Qn=Object.prototype.hasOwnProperty;var Jn=(i,t,e)=>t in i?Et(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var ui=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),tr=(i,t)=>{for(var e in t)Et(i,e,{get:t[e],enumerable:!0})},Wt=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Kn(t))!Qn.call(i,r)&&r!==e&&Et(i,r,{get:()=>t[r],enumerable:!(n=Yn(t,r))||n.enumerable});return i},Yt=(i,t,e)=>(Wt(i,t,"default"),e&&Wt(e,t,"default")),k=(i,t,e)=>(e=i!=null?Wn(Zn(i)):{},Wt(t||!i||!i.__esModule?Et(e,"default",{value:i,enumerable:!0}):e,i)),er=i=>Wt(Et({},"__esModule",{value:!0}),i);var Y=(i,t,e)=>(Jn(i,typeof t!="symbol"?t+"":t,e),e);var U=ui((io,mi)=>{mi.exports=globalThis.luma});var nt=ui((vo,bi)=>{bi.exports=globalThis.luma});var $t={};tr($t,{AnimationLoop:()=>lt,AnimationLoopTemplate:()=>Qt,AsyncTexture:()=>to,BackgroundTextureModel:()=>Mt,BufferTransform:()=>Bt,ClipSpace:()=>st,Computation:()=>jt,ConeGeometry:()=>ct,CubeGeometry:()=>be,CylinderGeometry:()=>ye,DirectionalLightModel:()=>ge,DynamicTexture:()=>B,GPUGeometry:()=>mt,Geometry:()=>$,GroupNode:()=>ft,IcoSphereGeometry:()=>Me,KeyFrames:()=>Zt,LegacyPickingManager:()=>Se,Material:()=>yt,MaterialFactory:()=>bt,Model:()=>H,ModelNode:()=>xe,PickingManager:()=>Ut,PlaneGeometry:()=>_e,PointLightModel:()=>me,ScenegraphNode:()=>et,ShaderInputs:()=>G,ShaderPassRenderer:()=>ve,SphereGeometry:()=>_t,SpotLightModel:()=>pe,Swap:()=>At,SwapBuffers:()=>Ie,SwapFramebuffers:()=>Tt,TextureTransform:()=>re,Timeline:()=>Kt,TruncatedConeGeometry:()=>at,cancelAnimationFramePolyfill:()=>te,colorPicking:()=>Gt,indexPicking:()=>Pe,legacyColorPicking:()=>$n,loadImage:()=>Rn,loadImageBitmap:()=>On,makeAnimationLoop:()=>xi,makeRandomGenerator:()=>Ln,picking:()=>Un,requestAnimationFramePolyfill:()=>Jt,resolvePickingBackend:()=>jn,resolvePickingMode:()=>Te,setPathPrefix:()=>Cn,supportsIndexPicking:()=>di});Yt($t,k(U(),1));var ir=1,nr=1,Kt=class{time=0;channels=new Map;animations=new Map;playing=!1;lastEngineTime=-1;constructor(){}addChannel(t){let{delay:e=0,duration:n=Number.POSITIVE_INFINITY,rate:r=1,repeat:s=1}=t,o=ir++,a={time:0,delay:e,duration:n,rate:r,repeat:s};return this._setChannelTime(a,this.time),this.channels.set(o,a),o}removeChannel(t){this.channels.delete(t);for(let[e,n]of this.animations)n.channel===t&&this.detachAnimation(e)}isFinished(t){let e=this.channels.get(t);return e===void 0?!1:this.time>=e.delay+e.duration*e.repeat}getTime(t){if(t===void 0)return this.time;let e=this.channels.get(t);return e===void 0?-1:e.time}setTime(t){this.time=Math.max(0,t);let e=this.channels.values();for(let r of e)this._setChannelTime(r,this.time);let n=this.animations.values();for(let r of n){let{animation:s,channel:o}=r;s.setTime(this.getTime(o))}}play(){this.playing=!0}pause(){this.playing=!1,this.lastEngineTime=-1}reset(){this.setTime(0)}attachAnimation(t,e){let n=nr++;return this.animations.set(n,{animation:t,channel:e}),t.setTime(this.getTime(e)),n}detachAnimation(t){this.animations.delete(t)}update(t){this.playing&&(this.lastEngineTime===-1&&(this.lastEngineTime=t),this.setTime(this.time+(t-this.lastEngineTime)),this.lastEngineTime=t)}_setChannelTime(t,e){let n=e-t.delay,r=t.duration*t.repeat;n>=r?t.time=t.duration*t.rate:(t.time=Math.max(0,n)%t.duration,t.time*=t.rate)}};var Zt=class{startIndex=-1;endIndex=-1;factor=0;times=[];values=[];_lastTime=-1;constructor(t){this.setKeyFrames(t),this.setTime(0)}setKeyFrames(t){let e=t.length;this.times.length=e,this.values.length=e;for(let n=0;n<e;++n)this.times[n]=t[n][0],this.values[n]=t[n][1];this._calculateKeys(this._lastTime)}setTime(t){t=Math.max(0,t),t!==this._lastTime&&(this._calculateKeys(t),this._lastTime=t)}getStartTime(){return this.times[this.startIndex]}getEndTime(){return this.times[this.endIndex]}getStartData(){return this.values[this.startIndex]}getEndData(){return this.values[this.endIndex]}_calculateKeys(t){let e=0,n=this.times.length;for(e=0;e<n-2&&!(this.times[e+1]>t);++e);this.startIndex=e,this.endIndex=e+1;let r=this.times[this.startIndex],s=this.times[this.endIndex];this.factor=Math.min(Math.max(0,(t-r)/(s-r)),1)}};var Qt=class{constructor(t){}async onInitialize(t){return null}};var pi=k(U(),1);function Jt(i){let t=typeof window<"u"?window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame:null;return t?t.call(window,i):setTimeout(()=>i(typeof performance<"u"?performance.now():Date.now()),1e3/60)}function te(i){let t=typeof window<"u"?window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame:null;if(t){t.call(window,i);return}clearTimeout(i)}function Lt(){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 ht=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=Lt(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(Lt()-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 ut=class{constructor(t){this.stats={},this.id=t.id,this.stats={},this._initializeStats(t.stats),Object.seal(this)}get(t,e="count"){return this._getOrCreate({name:t,type:e})}get size(){return Object.keys(this.stats).length}reset(){for(let t of Object.values(this.stats))t.reset();return this}forEach(t){for(let e of Object.values(this.stats))t(e)}getTable(){let t={};return this.forEach(e=>{t[e.name]={time:e.time||0,count:e.count||0,average:e.getAverageTime()||0,hz:e.getHz()||0}}),t}_initializeStats(t=[]){t.forEach(e=>this._getOrCreate(e))}_getOrCreate(t){let{name:e,type:n}=t,r=this.stats[e];return r||(t instanceof ht?r=t:r=new ht(e,n),this.stats[e]=r),r}};var rr=0,sr="Animation Loop",Ee=class{device=null;canvas=null;props;animationProps=null;timeline=null;stats;sharedStats;cpuTime;gpuTime;frameRate;display;_needsRedraw="initialized";_initialized=!1;_running=!1;_animationFrameId=null;_nextFramePromise=null;_resolveNextFrame=null;_cpuStartTime=0;_error=null;_lastFrameTime=0;constructor(t){if(this.props={...Ee.defaultAnimationLoopProps,...t},t=this.props,!t.device)throw new Error("No device provided");this.stats=t.stats||new ut({id:`animation-loop-${rr++}`}),this.sharedStats=pi.luma.stats.get(sr),this.frameRate=this.stats.get("Frame Rate"),this.frameRate.setSampleSize(1),this.cpuTime=this.stats.get("CPU Time"),this.gpuTime=this.stats.get("GPU Time"),this.setProps({autoResizeViewport:t.autoResizeViewport}),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this._onMousemove=this._onMousemove.bind(this),this._onMouseleave=this._onMouseleave.bind(this)}destroy(){this.stop(),this._setDisplay(null),this.device?._disableDebugGPUTime()}delete(){this.destroy()}reportError(t){this.props.onError(t),this._error=t}setNeedsRedraw(t){return this._needsRedraw=this._needsRedraw||t,this}needsRedraw(){let t=this._needsRedraw;return this._needsRedraw=!1,t}setProps(t){return"autoResizeViewport"in t&&(this.props.autoResizeViewport=t.autoResizeViewport||!1),this}async start(){if(this._running)return this;this._running=!0;try{let t;if(!this._initialized){if(this._initialized=!0,await this._initDevice(),this._initialize(),!this._running)return null;await this.props.onInitialize(this._getAnimationProps())}return 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._lastFrameTime=0),this}redraw(t){return this.device?.isLost||this._error?this:(this._beginFrameTimers(t),this._setupFrame(),this._updateAnimationProps(),this._renderFrame(this._getAnimationProps()),this._clearNeedsRedraw(),this._resolveNextFrame&&(this._resolveNextFrame(this),this._nextFramePromise=null,this._resolveNextFrame=null),this._endFrameTimers(),this)}attachTimeline(t){return this.timeline=t,this.timeline}detachTimeline(){this.timeline=null}waitForRender(){return this.setNeedsRedraw("waitForRender"),this._nextFramePromise||(this._nextFramePromise=new Promise(t=>{this._resolveNextFrame=t})),this._nextFramePromise}async toDataURL(){if(this.setNeedsRedraw("toDataURL"),await this.waitForRender(),this.canvas instanceof HTMLCanvasElement)return this.canvas.toDataURL();throw new Error("OffscreenCanvas")}_initialize(){this._startEventHandling(),this._initializeAnimationProps(),this._updateAnimationProps(),this._resizeViewport(),this.device?._enableDebugGPUTime()}_setDisplay(t){this.display&&(this.display.destroy(),this.display.animationLoop=null),t&&(t.animationLoop=this),this.display=t}_requestAnimationFrame(){this._running&&(this._animationFrameId=Jt(this._animationFrame.bind(this)))}_cancelAnimationFrame(){this._animationFrameId!==null&&(te(this._animationFrameId),this._animationFrameId=null)}_animationFrame(t){this._running&&(this.redraw(t),this._requestAnimationFrame())}_renderFrame(t){if(this.display){this.display._renderFrame(t);return}this.props.onRender(this._getAnimationProps()),this.device?.submit()}_clearNeedsRedraw(){this._needsRedraw=!1}_setupFrame(){this._resizeViewport()}_initializeAnimationProps(){let t=this.device?.getDefaultCanvasContext();if(!this.device||!t)throw new Error("loop");let e=t?.canvas,n=t.props.useDevicePixels;this.animationProps={animationLoop:this,device:this.device,canvasContext:t,canvas:e,useDevicePixels:n,timeline:this.timeline,needsRedraw:!1,width:1,height:1,aspect:1,time:0,startTime:Date.now(),engineTime:0,tick:0,tock:0,_mousePosition:null}}_getAnimationProps(){if(!this.animationProps)throw new Error("animationProps");return this.animationProps}_updateAnimationProps(){if(!this.animationProps)return;let{width:t,height:e,aspect:n}=this._getSizeAndAspect();(t!==this.animationProps.width||e!==this.animationProps.height)&&this.setNeedsRedraw("drawing buffer resized"),n!==this.animationProps.aspect&&this.setNeedsRedraw("drawing buffer aspect changed"),this.animationProps.width=t,this.animationProps.height=e,this.animationProps.aspect=n,this.animationProps.needsRedraw=this._needsRedraw,this.animationProps.engineTime=Date.now()-this.animationProps.startTime,this.timeline&&this.timeline.update(this.animationProps.engineTime),this.animationProps.tick=Math.floor(this.animationProps.time/1e3*60),this.animationProps.tock++,this.animationProps.time=this.timeline?this.timeline.getTime():this.animationProps.engineTime}async _initDevice(){if(this.device=await this.props.device,!this.device)throw new Error("No device provided");this.canvas=this.device.getDefaultCanvasContext().canvas||null}_createInfoDiv(){if(this.canvas&&this.props.onAddHTML){let t=document.createElement("div");document.body.appendChild(t),t.style.position="relative";let e=document.createElement("div");e.style.position="absolute",e.style.left="10px",e.style.bottom="10px",e.style.width="300px",e.style.background="white",this.canvas instanceof HTMLCanvasElement&&t.appendChild(this.canvas),t.appendChild(e);let n=this.props.onAddHTML(e);n&&(e.innerHTML=n)}}_getSizeAndAspect(){if(!this.device)return{width:1,height:1,aspect:1};let[t,e]=this.device.getDefaultCanvasContext().getDrawingBufferSize(),n=t>0&&e>0?t/e:1;return{width:t,height:e,aspect:n}}_resizeViewport(){this.props.autoResizeViewport&&this.device.gl&&this.device.gl.viewport(0,0,this.device.gl.drawingBufferWidth,this.device.gl.drawingBufferHeight)}_beginFrameTimers(t){let e=t??(typeof performance<"u"?performance.now():Date.now());if(this._lastFrameTime){let n=e-this._lastFrameTime;n>0&&this.frameRate.addTime(n)}this._lastFrameTime=e,this.device?._isDebugGPUTimeEnabled()&&this._consumeEncodedGpuTime(),this.cpuTime.timeStart()}_endFrameTimers(){this.device?._isDebugGPUTimeEnabled()&&this._consumeEncodedGpuTime(),this.cpuTime.timeEnd(),this._updateSharedStats()}_consumeEncodedGpuTime(){if(!this.device)return;let t=this.device.commandEncoder._gpuTimeMs;t!==void 0&&(this.gpuTime.addTime(t),this.device.commandEncoder._gpuTimeMs=void 0)}_updateSharedStats(){if(this.stats!==this.sharedStats){for(let t of Object.keys(this.sharedStats.stats))this.stats.stats[t]||delete this.sharedStats.stats[t];this.stats.forEach(t=>{let e=this.sharedStats.get(t.name,t.type);e.sampleSize=t.sampleSize,e.time=t.time,e.count=t.count,e.samples=t.samples,e.lastTiming=t.lastTiming,e.lastSampleTime=t.lastSampleTime,e.lastSampleCount=t.lastSampleCount,e._count=t._count,e._time=t._time,e._samples=t._samples,e._startTime=t._startTime,e._timerPending=t._timerPending})}}_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}},lt=Ee;Y(lt,"defaultAnimationLoopProps",{device:null,onAddHTML:()=>"",onInitialize:async()=>null,onRender:()=>{},onFinalize:()=>{},onError:t=>console.error(t),stats:void 0,autoResizeViewport:!1});var gi=k(U(),1);function xi(i,t){let e=null,n=t?.device||gi.luma.createDevice({id:"animation-loop",adapters:t?.adapters,createCanvasContext:!0}),r=new lt({...t,device:n,async onInitialize(s){ar(s.animationLoop.device);try{return e=new i(s),await e?.onInitialize(s)}catch(o){return console.error(o),or(s.animationLoop.device,o),null}},onRender:s=>e?.onRender(s),onFinalize:s=>e?.onFinalize(s)});return r.getInfo=()=>this.AnimationLoopTemplateCtor.info,r}function or(i,t){if(!i)return;let e=i.getDefaultCanvasContext().canvas;if(e instanceof HTMLCanvasElement){e.style.overflow="visible";let n=document.getElementById("animation-loop-error");n?.remove(),n=document.createElement("h1"),n.id="animation-loop-error",n.innerHTML=t.message,n.style.position="absolute",n.style.top="10px",n.style.left="10px",n.style.color="black",n.style.backgroundColor="red",e.parentElement?.appendChild(n)}}function ar(i){if(!i)return;let t=document.getElementById("animation-loop-error");t&&t.remove()}var w=k(U(),1),Fi=k(nt(),1);var Ct=k(U(),1);var Le={};function S(i="id"){Le[i]=Le[i]||1;let t=Le[i]++;return`${i}-${t}`}var mt=class{id;userData={};topology;bufferLayout=[];vertexCount;indices;attributes;constructor(t){if(this.id=t.id||S("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&Ct.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 yi(i,t){if(t instanceof mt)return t;let e=cr(i,t),{attributes:n,bufferLayout:r}=hr(i,t);return new mt({topology:t.topology||"triangle-list",bufferLayout:r,vertexCount:t.vertexCount,indices:e,attributes:n})}function cr(i,t){if(!t.indices)return;let e=t.indices.value;return i.createBuffer({usage:Ct.Buffer.INDEX,data:e})}function hr(i,t){let e=[],n={};for(let[s,o]of Object.entries(t.attributes)){let a=s;switch(s){case"POSITION":a="positions";break;case"NORMAL":a="normals";break;case"TEXCOORD_0":a="texCoords";break;case"TEXCOORD_1":a="texCoords1";break;case"COLOR_0":a="colors";break}if(o){n[a]=i.createBuffer({data:o.value,id:`${s}-buffer`});let{value:c,size:h,normalized:l}=o;if(h===void 0)throw new Error(`Attribute ${s} is missing a size`);e.push({name:a,format:Ct.vertexFormatDecoder.getVertexFormatFromAttribute(c,h,l)})}}let r=t._calculateVertexCount(t.attributes,t.indices);return{attributes:n,bufferLayout:e,vertexCount:r}}function Mi(i,t){let e={},n="Values";if(i.attributes.length===0&&!i.varyings?.length)return{"No attributes or varyings":{[n]:"N/A"}};for(let r of i.attributes)if(r){let s=`${r.location} ${r.name}: ${r.type}`;e[`in ${s}`]={[n]:r.stepMode||"vertex"}}for(let r of i.varyings||[]){let s=`${r.location} ${r.name}`;e[`out ${s}`]={[n]:JSON.stringify(r)}}return e}var _i="__debugFramebufferState";function vi(i,t,e){if(i.device.type!=="webgl")return;let n=fr(i.device);if(!n.flushing){if(mr(i)){lr(i,e,n);return}t&&ur(t)&&t.handle!==null&&(n.queuedFramebuffers.includes(t)||n.queuedFramebuffers.push(t))}}function lr(i,t,e){if(e.queuedFramebuffers.length===0)return;let n=i.device,{gl:r}=n,s=r.getParameter(36010),o=r.getParameter(36006),[a,c]=i.device.getDefaultCanvasContext().getDrawingBufferSize(),h=Ii(t.top,8),l=Ii(t.left,8);e.flushing=!0;try{for(let d of e.queuedFramebuffers){let[f,p,g,u,b]=dr({framebuffer:d,targetWidth:a,targetHeight:c,topPx:h,leftPx:l,minimap:t.minimap});r.bindFramebuffer(36008,d.handle),r.bindFramebuffer(36009,null),r.blitFramebuffer(0,0,d.width,d.height,f,p,g,u,16384,9728),h+=b+8}}finally{r.bindFramebuffer(36008,s),r.bindFramebuffer(36009,o),e.flushing=!1}}function dr(i){let{framebuffer:t,targetWidth:e,targetHeight:n,topPx:r,leftPx:s,minimap:o}=i,a=o?Math.max(Math.floor(e/4),1):e,c=o?Math.max(Math.floor(n/4),1):n,h=Math.min(a/t.width,c/t.height),l=Math.max(Math.floor(t.width*h),1),d=Math.max(Math.floor(t.height*h),1),f=s,p=Math.max(n-r-d,0),g=f+l,u=p+d;return[f,p,g,u,d]}function fr(i){return i.userData[_i]||={flushing:!1,queuedFramebuffers:[]},i.userData[_i]}function ur(i){return"colorAttachments"in i}function mr(i){let t=i.props.framebuffer;return!t||t.handle===null}function Ii(i,t){if(!i)return t;let e=Number.parseInt(i,10);return Number.isFinite(e)?e:t}function ee(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 n=0;n<i.length;n++)if(!ee(i[n],t[n],e-1))return!1;return!0}if(Array.isArray(t))return!1;if(typeof i=="object"&&typeof t=="object"){let n=Object.keys(i),r=Object.keys(t);if(n.length!==r.length)return!1;for(let s of n)if(!t.hasOwnProperty(s)||!ee(i[s],t[s],e-1))return!1;return!0}return!1}var wi=k(U(),1),pt=class{bufferLayouts;constructor(t){this.bufferLayouts=t}getBufferLayout(t){return this.bufferLayouts.find(e=>e.name===t)||null}getAttributeNamesForBuffer(t){return t.attributes?t.attributes?.map(e=>e.attribute):[t.name]}mergeBufferLayouts(t,e){let n=[...t];for(let r of e){let s=n.findIndex(o=>o.name===r.name);s<0?n.push(r):n[s]=r}return n}getBufferIndex(t){let e=this.bufferLayouts.findIndex(n=>n.name===t);return e===-1&&wi.log.warn(`BufferLayout: Missing buffer for "${t}".`)(),e}};function Ai(i,t){let e=1/0;for(let n of i){let r=t[n];r!==void 0&&(e=Math.min(e,r))}return e}function Ti(i,t){let e=Object.fromEntries(i.attributes.map(r=>[r.name,r.location])),n=t.slice();return n.sort((r,s)=>{let o=r.attributes?r.attributes.map(l=>l.attribute):[r.name],a=s.attributes?s.attributes.map(l=>l.attribute):[s.name],c=Ai(o,e),h=Ai(a,e);return c-h}),n}function gt(i,t){if(!i||!t.some(n=>n.bindingLayout?.length))return i;let e={...i,bindings:i.bindings.map(n=>({...n}))};"attributes"in(i||{})&&(e.attributes=i?.attributes||[]);for(let n of t)for(let r of n.bindingLayout||[])for(let s of pr(r.name)){let o=e.bindings.find(a=>a.name===s);o?.group===0&&(o.group=r.group)}return e}function xt(i){return Boolean(i.uniformTypes&&!gr(i.uniformTypes))}function pr(i){let t=new Set([i,`${i}Uniforms`]);return i.endsWith("Uniforms")||t.add(`${i}Sampler`),[...t]}function gr(i){for(let t in i)return!1;return!0}var ie=k(U(),1),Ci=k(nt(),1);function Pi(i){return ArrayBuffer.isView(i)&&!(i instanceof DataView)}function Si(i){return Array.isArray(i)?i.length===0||typeof i[0]=="number":!1}function Ot(i){return Pi(i)||Si(i)}function xr(i){return Ot(i)||typeof i=="number"||typeof i=="boolean"}function Ei(i,t={}){let e={bindings:{},uniforms:{}};return Object.keys(i).forEach(n=>{let r=i[n];Object.prototype.hasOwnProperty.call(t,n)||xr(r)?e.uniforms[n]=r:e.bindings[n]=r}),e}var G=class{options={disableWarnings:!1};modules;moduleUniforms;moduleBindings;constructor(t,e){Object.assign(this.options,e);let n=(0,Ci.getShaderModuleDependencies)(Object.values(t).filter(br));for(let r of n)t[r.name]=r;ie.log.log(1,"Creating ShaderInputs with modules",Object.keys(t))(),this.modules=t,this.moduleUniforms={},this.moduleBindings={};for(let[r,s]of Object.entries(t))s&&(this._addModule(s),s.name&&r!==s.name&&!this.options.disableWarnings&&ie.log.warn(`Module name: ${r} vs ${s.name}`)())}destroy(){}setProps(t){for(let e of Object.keys(t)){let n=e,r=t[n]||{},s=this.modules[n];if(!s)this.options.disableWarnings||ie.log.warn(`Module ${e} not found`)();else{let o=this.moduleUniforms[n],a=this.moduleBindings[n],c=s.getUniforms?.(r,o)||r,{uniforms:h,bindings:l}=Ei(c,s.uniformTypes);this.moduleUniforms[n]=Li(o,h,s.uniformTypes),this.moduleBindings[n]={...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,n]of Object.entries(this.moduleUniforms))for(let[r,s]of Object.entries(n))t[`${e}.${r}`]={type:this.modules[e].uniformTypes?.[r],value:String(s)};return t}_addModule(t){let e=t.name;this.moduleUniforms[e]=Li({},t.defaultUniforms||{},t.uniformTypes),this.moduleBindings[e]={}}};function Li(i={},t={},e={}){let n={...i};for(let[r,s]of Object.entries(t))s!==void 0&&(n[r]=Ce(i[r],s,e[r]));return n}function Ce(i,t,e){if(!e||typeof e=="string")return Rt(t);if(Array.isArray(e)){if(Oe(t)||!Array.isArray(t))return Rt(t);let o=Array.isArray(i)&&!Oe(i)?[...i]:[],a=o.slice();for(let c=0;c<t.length;c++){let h=t[c];h!==void 0&&(a[c]=Ce(o[c],h,e[0]))}return a}if(!Re(t))return Rt(t);let n=e,r=Re(i)?i:{},s={...r};for(let[o,a]of Object.entries(t))a!==void 0&&(s[o]=Ce(r[o],a,n[o]));return s}function Rt(i){return ArrayBuffer.isView(i)?Array.prototype.slice.call(i):Array.isArray(i)?Oe(i)?i.slice():i.map(e=>e===void 0?void 0:Rt(e)):Re(i)?Object.fromEntries(Object.entries(i).map(([t,e])=>[t,e===void 0?void 0:Rt(e)])):i}function Oe(i){return ArrayBuffer.isView(i)||Array.isArray(i)&&(i.length===0||typeof i[0]=="number")}function Re(i){return Boolean(i)&&typeof i=="object"&&!Array.isArray(i)&&!ArrayBuffer.isView(i)}function br(i){return Boolean(i?.dependencies)}var R=k(U(),1);var Dt=k(U(),1);var ke={"+X":0,"-X":1,"+Y":2,"-Y":3,"+Z":4,"-Z":5};function kt(i){return i?Array.isArray(i)?i[0]??null:i:null}function Oi(i){let{dimension:t,data:e}=i;if(!e)return null;switch(t){case"1d":{let n=kt(e);if(!n)return null;let{width:r}=Nt(n);return{width:r,height:1}}case"2d":{let n=kt(e);return n?Nt(n):null}case"3d":case"2d-array":{if(!Array.isArray(e)||e.length===0)return null;let n=kt(e[0]);return n?Nt(n):null}case"cube":{let n=Object.keys(e)[0]??null;if(!n)return null;let r=e[n],s=kt(r);return s?Nt(s):null}case"cube-array":{if(!Array.isArray(e)||e.length===0)return null;let n=e[0],r=Object.keys(n)[0]??null;if(!r)return null;let s=kt(n[r]);return s?Nt(s):null}default:return null}}function Nt(i){if((0,Dt.isExternalImage)(i))return(0,Dt.getExternalImageSize)(i);if(typeof i=="object"&&"width"in i&&"height"in i)return{width:i.width,height:i.height};throw new Error("Unsupported mip-level data")}function yr(i){return typeof i=="object"&&i!==null&&"data"in i&&"width"in i&&"height"in i}function Mr(i){return ArrayBuffer.isView(i)}function Ne(i){let{textureFormat:t,format:e}=i;if(t&&e&&t!==e)throw new Error(`Conflicting texture formats "${t}" and "${e}" provided for the same mip level`);return t??e}function Ri(i){let t=ke[i];if(t===void 0)throw new Error(`Invalid cube face: ${i}`);return t}function _r(i,t){return 6*i+Ri(t)}function De(i){throw new Error("setTexture1DData not supported in WebGL.")}function Ir(i){return Array.isArray(i)?i:[i]}function dt(i,t,e,n){let r=Ir(t),s=i,o=[];for(let a=0;a<r.length;a++){let c=r[a];if((0,Dt.isExternalImage)(c))o.push({type:"external-image",image:c,z:s,mipLevel:a});else if(yr(c))o.push({type:"texture-data",data:c,textureFormat:Ne(c),z:s,mipLevel:a});else if(Mr(c)&&e)o.push({type:"texture-data",data:{data:c,width:Math.max(1,e.width>>a),height:Math.max(1,e.height>>a),...n?{format:n}:{}},textureFormat:n,z:s,mipLevel:a});else throw new Error("Unsupported 2D mip-level payload")}return o}function Fe(i){let t=[];for(let e=0;e<i.length;e++)t.push(...dt(e,i[e]));return t}function Be(i){let t=[];for(let e=0;e<i.length;e++)t.push(...dt(e,i[e]));return t}function ze(i){let t=[];for(let[e,n]of Object.entries(i)){let r=Ri(e);t.push(...dt(r,n))}return t}function je(i){let t=[];return i.forEach((e,n)=>{for(let[r,s]of Object.entries(e)){let o=_r(n,r);t.push(...dt(o,s))}}),t}var Ge=class{device;id;props;_texture=null;_sampler=null;_view=null;ready;isReady=!1;destroyed=!1;resolveReady=()=>{};rejectReady=()=>{};get texture(){if(!this._texture)throw new Error("Texture not initialized yet");return this._texture}get sampler(){if(!this._sampler)throw new Error("Sampler not initialized yet");return this._sampler}get view(){if(!this._view)throw new Error("View not initialized yet");return this._view}get[Symbol.toStringTag](){return"DynamicTexture"}toString(){let t=this._texture?.width??this.props.width??"?",e=this._texture?.height??this.props.height??"?";return`DynamicTexture:"${this.id}":${t}x${e}px:(${this.isReady?"ready":"loading..."})`}constructor(t,e){this.device=t;let n=S("dynamic-texture"),r=e;this.props={...Ge.defaultProps,id:n,...e,data:null},this.id=this.props.id,this.ready=new Promise((s,o)=>{this.resolveReady=s,this.rejectReady=o}),this.initAsync(r)}async initAsync(t){try{let e=await this._loadAllData(t);this._checkNotDestroyed();let n=e.data?vr({...e,width:t.width,height:t.height,format:t.format}):[],r="format"in t&&t.format!==void 0,s="usage"in t&&t.usage!==void 0,a=(()=>{if(this.props.width&&this.props.height)return{width:this.props.width,height:this.props.height};let u=Oi(e);return u||{width:this.props.width||1,height:this.props.height||1}})();if(!a||a.width<=0||a.height<=0)throw new Error(`${this} size could not be determined or was zero`);let c=wr(this.device,n,a,{format:r?t.format:void 0}),h=c.format??this.props.format,l={...this.props,...a,format:h,mipLevels:1,data:void 0};this.device.isTextureFormatCompressed(h)&&!s&&(l.usage=R.Texture.SAMPLE|R.Texture.COPY_DST);let d=this.props.mipmaps&&!c.hasExplicitMipChain&&!this.device.isTextureFormatCompressed(h);if(this.device.type==="webgpu"&&d){let u=this.props.dimension==="3d"?R.Texture.SAMPLE|R.Texture.STORAGE|R.Texture.COPY_DST|R.Texture.COPY_SRC:R.Texture.SAMPLE|R.Texture.RENDER|R.Texture.COPY_DST|R.Texture.COPY_SRC;l.usage|=u}let f=this.device.getMipLevelCount(l.width,l.height),p=c.hasExplicitMipChain?c.mipLevels:this.props.mipLevels==="auto"?f:Math.max(1,Math.min(f,this.props.mipLevels??1)),g={...l,mipLevels:p};this._texture=this.device.createTexture(g),this._sampler=this.texture.sampler,this._view=this.texture.view,c.subresources.length&&this._setTextureSubresources(c.subresources),this.props.mipmaps&&!c.hasExplicitMipChain&&!d&&R.log.warn(`${this} skipping auto-generated mipmaps for compressed texture format`)(),d&&this.generateMipmaps(),this.isReady=!0,this.resolveReady(this.texture),R.log.info(0,`${this} created`)()}catch(e){let n=e instanceof Error?e:new Error(String(e));this.rejectReady(n)}}destroy(){this._texture&&(this._texture.destroy(),this._texture=null,this._sampler=null,this._view=null),this.destroyed=!0}generateMipmaps(){this.device.type==="webgl"?this.texture.generateMipmapsWebGL():this.device.type==="webgpu"?this.device.generateMipmapsWebGPU(this.texture):R.log.warn(`${this} mipmaps not supported on ${this.device.type}`)}setSampler(t={}){this._checkReady();let e=t instanceof R.Sampler?t:this.device.createSampler(t);this.texture.setSampler(e),this._sampler=e}async readBuffer(t={}){this.isReady||await this.ready;let e=t.width??this.texture.width,n=t.height??this.texture.height,r=t.depthOrArrayLayers??this.texture.depth,s=this.texture.computeMemoryLayout({width:e,height:n,depthOrArrayLayers:r}),o=this.device.createBuffer({byteLength:s.byteLength,usage:R.Buffer.COPY_DST|R.Buffer.MAP_READ});this.texture.readBuffer({...t,width:e,height:n,depthOrArrayLayers:r},o);let a=this.device.createFence();return await a.signaled,a.destroy(),o}async readAsync(t={}){this.isReady||await this.ready;let e=t.width??this.texture.width,n=t.height??this.texture.height,r=t.depthOrArrayLayers??this.texture.depth,s=this.texture.computeMemoryLayout({width:e,height:n,depthOrArrayLayers:r}),o=await this.readBuffer(t),a=await o.readAsync(0,s.byteLength);return o.destroy(),a.buffer}resize(t){if(this._checkReady(),t.width===this.texture.width&&t.height===this.texture.height)return!1;let e=this.texture;return this._texture=e.clone(t),this._sampler=this.texture.sampler,this._view=this.texture.view,e.destroy(),R.log.info(`${this} resized`),!0}getCubeFaceIndex(t){let e=ke[t];if(e===void 0)throw new Error(`Invalid cube face: ${t}`);return e}getCubeArrayFaceIndex(t,e){return 6*t+this.getCubeFaceIndex(e)}setTexture1DData(t){if(this._checkReady(),this.texture.props.dimension!=="1d")throw new Error(`${this} is not 1d`);let e=De(t);this._setTextureSubresources(e)}setTexture2DData(t,e=0){if(this._checkReady(),this.texture.props.dimension!=="2d")throw new Error(`${this} is not 2d`);let n=dt(e,t);this._setTextureSubresources(n)}setTexture3DData(t){if(this.texture.props.dimension!=="3d")throw new Error(`${this} is not 3d`);let e=Fe(t);this._setTextureSubresources(e)}setTextureArrayData(t){if(this.texture.props.dimension!=="2d-array")throw new Error(`${this} is not 2d-array`);let e=Be(t);this._setTextureSubresources(e)}setTextureCubeData(t){if(this.texture.props.dimension!=="cube")throw new Error(`${this} is not cube`);let e=ze(t);this._setTextureSubresources(e)}setTextureCubeArrayData(t){if(this.texture.props.dimension!=="cube-array")throw new Error(`${this} is not cube-array`);let e=je(t);this._setTextureSubresources(e)}_setTextureSubresources(t){for(let e of t){let{z:n,mipLevel:r}=e;switch(e.type){case"external-image":let{image:s,flipY:o}=e;this.texture.copyExternalImage({image:s,z:n,mipLevel:r,flipY:o});break;case"texture-data":let{data:a,textureFormat:c}=e;if(c&&c!==this.texture.format)throw new Error(`${this} mip level ${r} uses format "${c}" but texture format is "${this.texture.format}"`);this.texture.writeData(a.data,{x:0,y:0,z:n,width:a.width,height:a.height,depthOrArrayLayers:1,mipLevel:r});break;default:throw new Error("Unsupported 2D mip-level payload")}}}async _loadAllData(t){let e=await Ue(t.data);return{dimension:t.dimension??"2d",data:e??null}}_checkNotDestroyed(){this.destroyed&&R.log.warn(`${this} already destroyed`)}_checkReady(){this.isReady||R.log.warn(`${this} Cannot perform this operation before ready`)}},B=Ge;Y(B,"defaultProps",{...R.Texture.defaultProps,dimension:"2d",data:null,mipmaps:!1});function vr(i){if(!i.data)return[];let t=i.width&&i.height?{width:i.width,height:i.height}:void 0,e="format"in i?i.format:void 0;switch(i.dimension){case"1d":return De(i.data);case"2d":return dt(0,i.data,t,e);case"3d":return Fe(i.data);case"2d-array":return Be(i.data);case"cube":return ze(i.data);case"cube-array":return je(i.data);default:throw new Error(`Unhandled dimension ${i.dimension}`)}}function wr(i,t,e,n){if(t.length===0)return{subresources:t,mipLevels:1,format:n.format,hasExplicitMipChain:!1};let r=new Map;for(let l of t){let d=r.get(l.z)??[];d.push(l),r.set(l.z,d)}let s=t.some(l=>l.mipLevel>0),o=n.format,a=Number.POSITIVE_INFINITY,c=[];for(let[l,d]of r){let f=[...d].sort((I,m)=>I.mipLevel-m.mipLevel),p=f[0];if(!p||p.mipLevel!==0)throw new Error(`DynamicTexture: slice ${l} is missing mip level 0`);let g=Ni(i,p);if(g.width!==e.width||g.height!==e.height)throw new Error(`DynamicTexture: slice ${l} base level dimensions ${g.width}x${g.height} do not match expected ${e.width}x${e.height}`);let u=ki(p);if(u){if(o&&o!==u)throw new Error(`DynamicTexture: slice ${l} base level format "${u}" does not match texture format "${o}"`);o=u}let b=o&&i.isTextureFormatCompressed(o)?Ar(i,g.width,g.height,o):i.getMipLevelCount(g.width,g.height),M=0;for(let I=0;I<f.length;I++){let m=f[I];if(!m||m.mipLevel!==I||I>=b)break;let x=Ni(i,m),y=Math.max(1,g.width>>I),_=Math.max(1,g.height>>I);if(x.width!==y||x.height!==_)break;let T=ki(m);if(T&&(o||(o=T),T!==o))break;M++,c.push(m)}a=Math.min(a,M)}let h=Number.isFinite(a)?Math.max(1,a):1;return{subresources:c.filter(l=>l.mipLevel<h),mipLevels:h,format:o,hasExplicitMipChain:s}}function ki(i){if(i.type==="texture-data")return i.textureFormat??Ne(i.data)}function Ni(i,t){switch(t.type){case"external-image":return i.getExternalImageSize(t.image);case"texture-data":return{width:t.data.width,height:t.data.height};default:throw new Error("Unsupported texture subresource")}}function Ar(i,t,e,n){let{blockWidth:r=1,blockHeight:s=1}=i.getTextureFormatInfo(n),o=1;for(let a=1;;a++){let c=Math.max(1,t>>a),h=Math.max(1,e>>a);if(c<r||h<s)break;o++}return o}async function Ue(i){if(i=await i,Array.isArray(i))return await Promise.all(i.map(Ue));if(i&&typeof i=="object"&&i.constructor===Object){let t=i,e=await Promise.all(Object.values(t).map(Ue)),n=Object.keys(t),r={};for(let s=0;s<n.length;s++)r[n[s]]=e[s];return r}return i}var rt=2,Tr=1e4,Di="render pipeline initialization failed",$e=class{device;id;source;vs;fs;pipelineFactory;shaderFactory;userData={};parameters;topology;bufferLayout;isInstanced=void 0;instanceCount=0;vertexCount;indexBuffer=null;bufferAttributes={};constantAttributes={};bindings={};vertexArray;transformFeedback=null;pipeline;shaderInputs;material=null;_uniformStore;_attributeInfos={};_gpuGeometry=null;props;_pipelineNeedsUpdate="newly created";_needsRedraw="initializing";_destroyed=!1;_lastDrawTimestamp=-1;_bindingTable=[];get[Symbol.toStringTag](){return"Model"}toString(){return`Model(${this.id})`}constructor(t,e){this.props={...$e.defaultProps,...e},e=this.props,this.id=e.id||S("model"),this.device=t,Object.assign(this.userData,e.userData),this.material=e.material||null;let n=Object.fromEntries(this.props.modules?.map(c=>[c.name,c])||[]),r=e.shaderInputs||new G(n,{disableWarnings:this.props.disableWarnings});this.setShaderInputs(r);let s=Pr(t),o=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];if(this.props.shaderLayout=gt(this.props.shaderLayout,o)||null,this.device.type==="webgpu"&&this.props.source){let{source:c,getUniforms:h,bindingTable:l}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:s,...this.props,modules:o});this.source=c,this._getModuleUniforms=h,this._bindingTable=l;let d=t.getShaderLayout?.(this.source);this.props.shaderLayout=gt(this.props.shaderLayout||d||null,o)||null}else{let{vs:c,fs:h,getUniforms:l}=this.props.shaderAssembler.assembleGLSLShaderPair({platformInfo:s,...this.props,modules:o});this.vs=c,this.fs=h,this._getModuleUniforms=l,this._bindingTable=[]}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||w.PipelineFactory.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||w.ShaderFactory.getDefaultShaderFactory(this.device),this.pipeline=this._updatePipeline(),this.vertexArray=t.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry),"isInstanced"in e&&(this.isInstanced=e.isInstanced),e.instanceCount&&this.setInstanceCount(e.instanceCount),e.vertexCount&&this.setVertexCount(e.vertexCount),e.indexBuffer&&this.setIndexBuffer(e.indexBuffer),e.attributes&&this.setAttributes(e.attributes),e.constantAttributes&&this.setConstantAttributes(e.constantAttributes),e.bindings&&this.setBindings(e.bindings),e.transformFeedback&&(this.transformFeedback=e.transformFeedback)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.pipeline.vs),this.pipeline.fs&&this.pipeline.fs!==this.pipeline.vs&&this.shaderFactory.release(this.pipeline.fs),this._uniformStore.destroy(),this._gpuGeometry?.destroy(),this._destroyed=!0)}needsRedraw(){this._getBindingsUpdateTimestamp()>this._lastDrawTimestamp&&this.setNeedsRedraw("contents of bound textures or buffers updated");let t=this._needsRedraw;return this._needsRedraw=!1,t}setNeedsRedraw(t){this._needsRedraw||=t}getBindingDebugTable(){return this._bindingTable}predraw(){this.updateShaderInputs(),this.pipeline=this._updatePipeline()}draw(t){let e=this._areBindingsLoading();if(e)return w.log.info(rt,`>>> DRAWING ABORTED ${this.id}: ${e} not loaded`)(),!1;try{t.pushDebugGroup(`${this}.predraw(${t})`),this.predraw()}finally{t.popDebugGroup()}let n,r=this.pipeline.isErrored;try{if(t.pushDebugGroup(`${this}.draw(${t})`),this._logDrawCallStart(),this.pipeline=this._updatePipeline(),r=this.pipeline.isErrored,r)w.log.info(rt,`>>> DRAWING ABORTED ${this.id}: ${Di}`)(),n=!1;else{let s=this._getBindings(),o=this._getBindGroups(),{indexBuffer:a}=this.vertexArray,c=a?a.byteLength/(a.indexType==="uint32"?4:2):void 0;n=this.pipeline.draw({renderPass:t,vertexArray:this.vertexArray,isInstanced:this.isInstanced,vertexCount:this.vertexCount,instanceCount:this.instanceCount,indexCount:c,transformFeedback:this.transformFeedback||void 0,bindings:s,bindGroups:o,_bindGroupCacheKeys:this._getBindGroupCacheKeys(),uniforms:this.props.uniforms,parameters:this.parameters,topology:this.topology})}}finally{t.popDebugGroup(),this._logDrawCallEnd()}return this._logFramebuffer(t),n?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):r?this._needsRedraw=Di:this._needsRedraw="waiting for resource initialization",n}setGeometry(t){this._gpuGeometry?.destroy();let e=t&&yi(this.device,t);if(e){this.setTopology(e.topology||"triangle-list");let n=new pt(this.bufferLayout);this.bufferLayout=n.mergeBufferLayouts(e.bufferLayout,this.bufferLayout),this.vertexArray&&this._setGeometryAttributes(e)}this._gpuGeometry=e}setTopology(t){t!==this.topology&&(this.topology=t,this._setPipelineNeedsUpdate("topology"))}setBufferLayout(t){let e=new pt(this.bufferLayout);this.bufferLayout=this._gpuGeometry?e.mergeBufferLayouts(t,this._gpuGeometry.bufferLayout):t,this._setPipelineNeedsUpdate("bufferLayout"),this.pipeline=this._updatePipeline(),this.vertexArray=this.device.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry)}setParameters(t){ee(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.device,this.shaderInputs.modules);for(let[e,n]of Object.entries(this.shaderInputs.modules))if(xt(n)&&!this.material?.ownsModule(e)){let r=this._uniformStore.getManagedUniformBuffer(e);this.bindings[`${e}Uniforms`]=r}this.setNeedsRedraw("shaderInputs")}setMaterial(t){this.material=t,this.setNeedsRedraw("material")}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues()),this.setBindings(this._getNonMaterialBindings(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 n=e?.disableWarnings??this.props.disableWarnings;t.indices&&w.log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)(),this.bufferLayout=Ti(this.pipeline.shaderLayout,this.bufferLayout);let r=new pt(this.bufferLayout);for(let[s,o]of Object.entries(t)){let a=r.getBufferLayout(s);if(!a){n||w.log.warn(`Model(${this.id}): Missing layout for buffer "${s}".`)();continue}let c=r.getAttributeNamesForBuffer(a),h=!1;for(let l of c){let d=this._attributeInfos[l];if(d){let f=this.device.type==="webgpu"?r.getBufferIndex(d.bufferName):d.location;this.vertexArray.setBuffer(f,o),h=!0}}!h&&!n&&w.log.warn(`Model(${this.id}): Ignoring buffer "${o.id}" for unknown attribute "${s}"`)()}this.setNeedsRedraw("attributes")}setConstantAttributes(t,e){for(let[n,r]of Object.entries(t)){let s=this._attributeInfos[n];s?this.vertexArray.setConstantWebGL(s.location,r):(e?.disableWarnings??this.props.disableWarnings)||w.log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${n}"`)()}this.setNeedsRedraw("constants")}_areBindingsLoading(){for(let t of Object.values(this.bindings))if(t instanceof B&&!t.isReady)return t.id;for(let t of Object.values(this.material?.bindings||{}))if(t instanceof B&&!t.isReady)return t.id;return!1}_getBindings(){let t={};for(let[e,n]of Object.entries(this.bindings))n instanceof B?n.isReady&&(t[e]=n.texture):t[e]=n;return t}_getBindGroups(){let t=this.pipeline?.shaderLayout||this.props.shaderLayout||{bindings:[]},e=t.bindings.length?(0,w.normalizeBindingsByGroup)(t,this._getBindings()):{0:this._getBindings()};if(!this.material)return e;for(let[n,r]of Object.entries(this.material.getBindingsByGroup())){let s=Number(n);e[s]={...e[s]||{},...r}}return e}_getBindGroupCacheKeys(){let t=this.material?.getBindGroupCacheKey(3);return t?{3: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 B?t=e.texture?Math.max(t,e.texture.updateTimestamp):1/0:e instanceof w.Sampler||(t=Math.max(t,e.buffer.updateTimestamp));return Math.max(t,this.material?.getBindingsUpdateTimestamp()||0)}_setGeometryAttributes(t){let e={...t.attributes};for(let[n]of Object.entries(e))!this.pipeline.shaderLayout.attributes.find(r=>r.name===n)&&n!=="positions"&&delete e[n];this.vertexCount=t.vertexCount,this.setIndexBuffer(t.indices||null),this.setAttributes(t.attributes,{disableWarnings:!0}),this.setAttributes(e,{disableWarnings:this.props.disableWarnings}),this.setNeedsRedraw("geometry attributes")}_setPipelineNeedsUpdate(t){this._pipelineNeedsUpdate||=t,this.setNeedsRedraw(t)}_updatePipeline(){if(this._pipelineNeedsUpdate){let t=null,e=null;this.pipeline&&(w.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),t=this.pipeline.vs,e=this.pipeline.fs),this._pipelineNeedsUpdate=!1;let n=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:"vertex",source:this.source||this.vs,debugShaders:this.props.debugShaders}),r=null;this.source?r=n:this.fs&&(r=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"fragment",source:this.source||this.fs,debugShaders:this.props.debugShaders})),this.pipeline=this.pipelineFactory.createRenderPipeline({...this.props,bindings:void 0,bufferLayout:this.bufferLayout,topology:this.topology,parameters:this.parameters,bindGroups:this._getBindGroups(),vs:n,fs:r}),this._attributeInfos=(0,w.getAttributeInfosFromLayouts)(this.pipeline.shaderLayout,this.bufferLayout),t&&this.shaderFactory.release(t),e&&e!==t&&this.shaderFactory.release(e)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let t=w.log.level>3?0:Tr;w.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,w.log.group(rt,`>>> DRAWING MODEL ${this.id}`,{collapsed:w.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=Mi(this.pipeline.shaderLayout,this.id);w.log.table(rt,t)();let e=this.shaderInputs.getDebugTable();w.log.table(rt,e)();let n=this._getAttributeDebugTable();w.log.table(rt,this._attributeInfos)(),w.log.table(rt,n)(),w.log.groupEnd(rt)(),this._logOpen=!1}}_drawCount=0;_logFramebuffer(t){let e=this.device.props.debugFramebuffers;if(this._drawCount++,!e)return;let n=t.props.framebuffer;vi(t,n,{id:n?.id||`${this.id}-framebuffer`,minimap:!0})}_getAttributeDebugTable(){let t={};for(let[e,n]of Object.entries(this._attributeInfos)){let r=this.vertexArray.attributes[n.location];t[n.location]={name:e,type:n.shaderType,values:r?this._getBufferOrConstantValues(r,n.bufferDataType):"null"}}if(this.vertexArray.indexBuffer){let{indexBuffer:e}=this.vertexArray,n=e.indexType==="uint32"?new Uint32Array(e.debugData):new Uint16Array(e.debugData);t.indices={name:"indices",type:e.indexType,values:n.toString()}}return t}_getBufferOrConstantValues(t,e){let n=w.dataTypeDecoder.getTypedArrayConstructor(e);return(t instanceof w.Buffer?new n(t.debugData):t).toString()}_getNonMaterialBindings(t){if(!this.material)return t;let e={};for(let[n,r]of Object.entries(t))this.material.ownsBinding(n)||(e[n]=r);return e}},H=$e;Y(H,"defaultProps",{...w.RenderPipeline.defaultProps,source:void 0,vs:null,fs:null,id:"unnamed",handle:void 0,userData:{},defines:{},modules:[],geometry:null,indexBuffer:null,attributes:{},constantAttributes:{},bindings:{},uniforms:{},varyings:[],isInstanced:void 0,instanceCount:0,vertexCount:0,shaderInputs:void 0,material:void 0,pipelineFactory:void 0,shaderFactory:void 0,transformFeedback:void 0,shaderAssembler:Fi.ShaderAssembler.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0});function Pr(i){return{type:i.type,shaderLanguage:i.info.shadingLanguage,shaderLanguageVersion:i.info.shadingLanguageVersion,gpu:i.info.gpu,features:i.features}}var Q=k(U(),1);var Ft=3,bt=class{device;modules;_materialBindingNames;_materialModuleNames;constructor(t,e={}){this.device=t,this.modules=e.modules||[];let n=new G(Object.fromEntries(this.modules.map(r=>[r.name,r])));this._materialBindingNames=Sr(n),this._materialModuleNames=Er(n)}createMaterial(t={}){return new yt(this.device,{...t,factory:this})}getBindingNames(){return Array.from(this._materialBindingNames)}ownsBinding(t){if(this._materialBindingNames.has(t))return!0;let e=Ve(t);return e?this._materialModuleNames.has(e):!1}ownsModule(t){return this._materialModuleNames.has(t)}getBindingsByGroup(t){return Object.keys(t).length>0?{[Ft]:t}:{}}};function Ve(i){return i.endsWith("Uniforms")?i.slice(0,-8):null}function Sr(i){let t=new Set;for(let e of Object.values(i.modules))for(let n of e.bindingLayout||[])n.group===Ft&&t.add(n.name);return t}function Er(i){let t=new Set;for(let e of Object.values(i.modules))e.name&&e.bindingLayout?.some(n=>n.group===Ft&&n.name===e.name)&&t.add(e.name);return t}var yt=class{id;device;factory;shaderInputs;bindings={};_uniformStore;_bindGroupCacheToken={};constructor(t,e={}){this.id=e.id||S("material"),this.device=t,this.factory=e.factory||new bt(t,{modules:e.modules||e.shaderInputs?.getModules()||[]});let n=Object.fromEntries((e.shaderInputs?.getModules()||this.factory.modules).map(r=>[r.name,r]));this.shaderInputs=e.shaderInputs||new G(n),this._uniformStore=new Q.UniformStore(this.device,this.shaderInputs.modules);for(let[r,s]of Object.entries(this.shaderInputs.modules))if(this.ownsModule(r)&&xt(s)){let o=this._uniformStore.getManagedUniformBuffer(r);this.bindings[`${r}Uniforms`]=o}this.updateShaderInputs(),e.bindings&&this._replaceOwnedBindings(e.bindings)}destroy(){this._uniformStore.destroy()}clone(t={}){let e=this.factory.createMaterial({id:t.id,shaderInputs:t.shaderInputs,bindings:{...this.getResourceBindings(),...t.bindings}});return t.shaderInputs||e.setProps(this.shaderInputs.getUniformValues()),t.moduleProps&&e.setProps(t.moduleProps),e}ownsBinding(t){return this.factory.ownsBinding(t)}ownsModule(t){return this.factory.ownsModule(t)}setProps(t){this.shaderInputs.setProps(t),this.updateShaderInputs()}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues()),this._setOwnedBindings(this.shaderInputs.getBindingValues())&&(this._bindGroupCacheToken={})}getResourceBindings(){let t={};for(let[e,n]of Object.entries(this.bindings))Ve(e)||(t[e]=n);return t}getBindings(){let t={},e=t;for(let[n,r]of Object.entries(this.bindings))r instanceof B?r.isReady&&(e[n]=r.texture):e[n]=r;return t}getBindingsByGroup(){return this.factory.getBindingsByGroup(this.getBindings())}getBindGroupCacheKey(t){return t===Ft?this._bindGroupCacheToken:null}getBindingsUpdateTimestamp(){let t=0;for(let e of Object.values(this.bindings))e instanceof Q.TextureView?t=Math.max(t,e.texture.updateTimestamp):e instanceof Q.Buffer||e instanceof Q.Texture?t=Math.max(t,e.updateTimestamp):e instanceof B?t=e.texture?Math.max(t,e.texture.updateTimestamp):1/0:e instanceof Q.Sampler||(t=Math.max(t,e.buffer.updateTimestamp));return t}_replaceOwnedBindings(t){this._setOwnedBindings(t)&&(this._bindGroupCacheToken={})}_setOwnedBindings(t){let e=!1;for(let[n,r]of Object.entries(t))r!==void 0&&this.ownsBinding(n)&&this.bindings[n]!==r&&(this.bindings[n]=r,e=!0);return e}};var Bi=k(U(),1),zi=k(nt(),1);var ne=class{device;model;transformFeedback;static isSupported(t){return t?.info?.type==="webgl"}constructor(t,e=ne.defaultProps){if(!ne.isSupported(t))throw new Error("BufferTransform not yet implemented on WebGPU");this.device=t,this.model=new H(this.device,{id:e.id||"buffer-transform-model",fs:e.fs||(0,zi.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 Bi.Buffer)return e.readAsync();let{buffer:n,byteOffset:r=0,byteLength:s=n.byteLength}=e;return n.readAsync(r,s)}},Bt=ne;Y(Bt,"defaultProps",{...H.defaultProps,outputs:void 0,feedbackBuffers:void 0});var ji=k(nt(),1);var Lr="transform_output",re=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 H(this.device,{id:e.id||S("texture-transform-model"),fs:e.fs||(0,ji.getPassthroughFS)({input:e.targetTextureVarying,inputChannels:e.targetTextureChannels,output:Lr}),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],n=this.device.beginRenderPass({framebuffer:e,...t});this.model.draw(n),n.end(),this.device.submit()}getTargetTexture(){let{targetTexture:t}=this.bindings[this.currentIndex];return t}getFramebuffer(){return this.bindings[this.currentIndex].framebuffer}_initialize(t){this._updateBindings(t)}_updateBindings(t){this.bindings[this.currentIndex]=this._updateBinding(this.bindings[this.currentIndex],t)}_updateBinding(t,{sourceBuffers:e,sourceTextures:n,targetTexture:r}){if(t||(t={sourceBuffers:{},sourceTextures:{},targetTexture:null}),Object.assign(t.sourceTextures,n),Object.assign(t.sourceBuffers,e),r){t.targetTexture=r;let{width:s,height:o}=r;t.framebuffer&&t.framebuffer.destroy(),t.framebuffer=this.device.createFramebuffer({id:"transform-framebuffer",width:s,height:o,colorAttachments:[r]}),t.framebuffer.resize({width:s,height:o})}return t}_setSourceTextureParameters(){let t=this.currentIndex,{sourceTextures:e}=this.bindings[t];for(let n in e)e[n].sampler=this.sampler}};var $=class{id;topology;vertexCount;indices;attributes;userData={};constructor(t){let{attributes:e={},indices:n=null,vertexCount:r=null}=t;this.id=t.id||S("geometry"),this.topology=t.topology,n&&(this.indices=ArrayBuffer.isView(n)?{value:n,size:1}:n),this.attributes={};for(let[s,o]of Object.entries(e)){let a=ArrayBuffer.isView(o)?{value:o}:o;if(!ArrayBuffer.isView(a.value))throw new Error(`${this._print(s)}: must be typed array or object with value as typed array`);if((s==="POSITION"||s==="positions")&&!a.size&&(a.size=3),s==="indices"){if(this.indices)throw new Error("Multiple indices detected");this.indices=a}else this.attributes[s]=a}this.indices&&this.indices.isIndexed!==void 0&&(this.indices=Object.assign({},this.indices),delete this.indices.isIndexed),this.vertexCount=r||this._calculateVertexCount(this.attributes,this.indices)}getVertexCount(){return this.vertexCount}getAttributes(){return this.indices?{indices:this.indices,...this.attributes}:this.attributes}_print(t){return`Geometry ${this.id} attribute ${t}`}_setAttributes(t,e){return this}_calculateVertexCount(t,e){if(e)return e.value.length;let n=1/0;for(let r of Object.values(t)){let{value:s,size:o,constant:a}=r;!a&&s&&o!==void 0&&o>=1&&(n=Math.min(n,s.length/o))}return n}};var Cr=`struct VertexInputs {
|
|
7
|
+
"use strict";var __exports__=(()=>{var Br=Object.create;var Ge=Object.defineProperty;var Fr=Object.getOwnPropertyDescriptor;var zr=Object.getOwnPropertyNames;var jr=Object.getPrototypeOf,Gr=Object.prototype.hasOwnProperty;var $r=(i,e,t)=>e in i?Ge(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var zi=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),Ur=(i,e)=>{for(var t in e)Ge(i,t,{get:e[t],enumerable:!0})},ct=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of zr(e))!Gr.call(i,r)&&r!==t&&Ge(i,r,{get:()=>e[r],enumerable:!(n=Fr(e,r))||n.enumerable});return i},ht=(i,e,t)=>(ct(i,e,"default"),t&&ct(t,e,"default")),L=(i,e,t)=>(t=i!=null?Br(jr(i)):{},ct(e||!i||!i.__esModule?Ge(t,"default",{value:i,enumerable:!0}):t,i)),Vr=i=>ct(Ge({},"__esModule",{value:!0}),i);var q=(i,e,t)=>($r(i,typeof e!="symbol"?e+"":e,t),t);var k=zi((Sa,ji)=>{ji.exports=globalThis.luma});var ae=zi((qa,Hi)=>{Hi.exports=globalThis.luma});var nt={};Ur(nt,{AnimationClipController:()=>ut,AnimationLoop:()=>pe,AnimationLoopTemplate:()=>mt,Animator:()=>dt,AsyncTexture:()=>Aa,BackgroundTextureModel:()=>Le,BufferTransform:()=>Xe,ClipSpace:()=>he,Computation:()=>Je,ConeGeometry:()=>le,CubeGeometry:()=>Bt,CylinderGeometry:()=>Ft,DirectionalLightModel:()=>Nt,DynamicBuffer:()=>z,DynamicTexture:()=>K,GPUGeometry:()=>ve,Geometry:()=>j,GroupNode:()=>ye,IcoSphereGeometry:()=>zt,KeyFrames:()=>ft,LegacyPickingManager:()=>Wt,Material:()=>Pe,MaterialFactory:()=>Se,Model:()=>Y,ModelNode:()=>Dt,PickingManager:()=>Qe,PlaneGeometry:()=>jt,PointLightModel:()=>Rt,ScenegraphNode:()=>re,ShaderInputs:()=>U,ShaderPassRenderer:()=>Vt,SphereGeometry:()=>Oe,SpotLightModel:()=>kt,Swap:()=>De,SwapBuffers:()=>Ut,SwapFramebuffers:()=>Be,TextureTransform:()=>Mt,Timeline:()=>lt,TruncatedConeGeometry:()=>de,VideoTexture:()=>$t,_resolveLoadFileUrl:()=>Gt,cancelAnimationFramePolyfill:()=>gt,colorPicking:()=>tt,getIndexPickingModule:()=>Pr,indexColorPicking:()=>Yt,indexPicking:()=>it,legacyColorPicking:()=>Or,loadImage:()=>dr,loadImageBitmap:()=>ur,makeAnimationLoop:()=>Xi,makeInterleavedGeometry:()=>xt,makeRandomGenerator:()=>or,picking:()=>Cr,requestAnimationFramePolyfill:()=>pt,resolvePickingBackend:()=>Sr,resolvePickingMode:()=>Ht,setPathPrefix:()=>hr,supportsIndexPicking:()=>et});ht(nt,L(k(),1));var Gi=L(k(),1),ut=class{name;playing=!0;speed=1;startTime=0;constructor(e={}){this.name=e.name||"unnamed",Object.assign(this,e)}setTime(e){if(!this.playing)return;let n=(e/1e3-this.startTime)*this.speed;this.applyTime(n)}},dt=class{clips;animations;constructor(e){this.clips=e,this.animations=e}animate(e){Gi.log.warn(`${this.constructor.name}#animate is deprecated. Use ${this.constructor.name}#setTime instead`)(),this.setTime(e)}setTime(e){this.clips.forEach(t=>t.setTime(e))}getAnimations(){return this.clips}};var Xr=1,Hr=1,lt=class{time=0;channels=new Map;animations=new Map;playing=!1;lastEngineTime=-1;constructor(){}addChannel(e){let{delay:t=0,duration:n=Number.POSITIVE_INFINITY,rate:r=1,repeat:s=1}=e,o=Xr++,a={time:0,delay:t,duration:n,rate:r,repeat:s};return this._setChannelTime(a,this.time),this.channels.set(o,a),o}removeChannel(e){this.channels.delete(e);for(let[t,n]of this.animations)n.channel===e&&this.detachAnimation(t)}isFinished(e){let t=this.channels.get(e);return t===void 0?!1:this.time>=t.delay+t.duration*t.repeat}getTime(e){if(e===void 0)return this.time;let t=this.channels.get(e);return t===void 0?-1:t.time}setTime(e){this.time=Math.max(0,e);let t=this.channels.values();for(let r of t)this._setChannelTime(r,this.time);let n=this.animations.values();for(let r of n){let{animation:s,channel:o}=r;s.setTime(this.getTime(o))}}play(){this.playing=!0}pause(){this.playing=!1,this.lastEngineTime=-1}reset(){this.setTime(0)}attachAnimation(e,t){let n=Hr++;return this.animations.set(n,{animation:e,channel:t}),e.setTime(this.getTime(t)),n}detachAnimation(e){this.animations.delete(e)}update(e){this.playing&&(this.lastEngineTime===-1&&(this.lastEngineTime=e),this.setTime(this.time+(e-this.lastEngineTime)),this.lastEngineTime=e)}_setChannelTime(e,t){let n=t-e.delay,r=e.duration*e.repeat;n>=r?e.time=e.duration*e.rate:(e.time=Math.max(0,n)%e.duration,e.time*=e.rate)}};var ft=class{startIndex=-1;endIndex=-1;factor=0;times=[];values=[];_lastTime=-1;constructor(e){this.setKeyFrames(e),this.setTime(0)}setKeyFrames(e){let t=e.length;this.times.length=t,this.values.length=t;for(let n=0;n<t;++n)this.times[n]=e[n][0],this.values[n]=e[n][1];this._calculateKeys(this._lastTime)}setTime(e){e=Math.max(0,e),e!==this._lastTime&&(this._calculateKeys(e),this._lastTime=e)}getStartTime(){return this.times[this.startIndex]}getEndTime(){return this.times[this.endIndex]}getStartData(){return this.values[this.startIndex]}getEndData(){return this.values[this.endIndex]}_calculateKeys(e){let t=0,n=this.times.length;for(t=0;t<n-2&&!(this.times[t+1]>e);++t);this.startIndex=t,this.endIndex=t+1;let r=this.times[this.startIndex],s=this.times[this.endIndex];this.factor=Math.min(Math.max(0,(e-r)/(s-r)),1)}};var mt=class{constructor(e){}async onInitialize(e){return null}};var Ui=L(k(),1);function pt(i){let e=typeof window<"u"?window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame:null;return e?e.call(window,i):setTimeout(()=>i(typeof performance<"u"?performance.now():Date.now()),1e3/60)}function gt(i){let e=typeof window<"u"?window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame:null;if(e){e.call(window,i);return}clearTimeout(i)}function $e(){let i;if(typeof window<"u"&&window.performance)i=window.performance.now();else if(typeof process<"u"&&process.hrtime){let e=process.hrtime();i=e[0]*1e3+e[1]/1e6}else i=Date.now();return i}var me=class{constructor(e,t){this.sampleSize=1,this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this.name=e,this.type=t,this.reset()}reset(){return this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this}setSampleSize(e){return this.sampleSize=e,this}incrementCount(){return this.addCount(1),this}decrementCount(){return this.subtractCount(1),this}addCount(e){return this._count+=e,this._samples++,this._checkSampling(),this}subtractCount(e){return this._count-=e,this._samples++,this._checkSampling(),this}addTime(e){return this._time+=e,this.lastTiming=e,this._samples++,this._checkSampling(),this}timeStart(){return this._startTime=$e(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime($e()-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 Ie=class{constructor(e){this.stats={},this.id=e.id,this.stats={},this._initializeStats(e.stats),Object.seal(this)}get(e,t="count"){return this._getOrCreate({name:e,type:t})}get size(){return Object.keys(this.stats).length}reset(){for(let e of Object.values(this.stats))e.reset();return this}forEach(e){for(let t of Object.values(this.stats))e(t)}getTable(){let e={};return this.forEach(t=>{e[t.name]={time:t.time||0,count:t.count||0,average:t.getAverageTime()||0,hz:t.getHz()||0}}),e}_initializeStats(e=[]){e.forEach(t=>this._getOrCreate(t))}_getOrCreate(e){let{name:t,type:n}=e,r=this.stats[t];return r||(e instanceof me?r=e:r=new me(t,n),this.stats[t]=r),r}};var Yr=0,Wr="Animation Loop",$i={requestAnimationFrame:i=>pt(i),cancelAnimationFrame:i=>gt(i)},qt=class{device=null;canvas=null;props;animationProps=null;timeline=null;stats;sharedStats;cpuTime;gpuTime;frameRate;display;_needsRedraw="initialized";_initialized=!1;_running=!1;_animationFrameId=null;_nextFramePromise=null;_resolveNextFrame=null;_cpuStartTime=0;_error=null;_lastFrameTime=0;constructor(e){if(this.props={...qt.defaultAnimationLoopProps,...e},e=this.props,!e.device)throw new Error("No device provided");this.stats=e.stats||new Ie({id:`animation-loop-${Yr++}`}),this.sharedStats=Ui.luma.stats.get(Wr),this.frameRate=this.stats.get("Frame Rate"),this.frameRate.setSampleSize(1),this.cpuTime=this.stats.get("CPU Time"),this.gpuTime=this.stats.get("GPU Time"),this.setProps({autoResizeViewport:e.autoResizeViewport,animationFrameProvider:e.animationFrameProvider}),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this._onMousemove=this._onMousemove.bind(this),this._onMouseleave=this._onMouseleave.bind(this)}destroy(){this.stop(),this._setDisplay(null),this.device?._disableDebugGPUTime()}delete(){this.destroy()}reportError(e){this.props.onError(e),this._error=e}setNeedsRedraw(e){return this._needsRedraw=this._needsRedraw||e,this}needsRedraw(){let e=this._needsRedraw;return this._needsRedraw=!1,e}setProps(e){if("autoResizeViewport"in e&&(this.props.autoResizeViewport=e.autoResizeViewport||!1),"animationFrameProvider"in e){let t=e.animationFrameProvider||$i;if(t!==this.props.animationFrameProvider){let n=this._animationFrameId!==null;n&&this._cancelAnimationFrame(),this.props.animationFrameProvider=t,n&&this._requestAnimationFrame()}}return this}async start(){if(this._running)return this;this._running=!0;try{let e;if(!this._initialized){if(this._initialized=!0,await this._initDevice(),this._initialize(),!this._running)return null;await this.props.onInitialize(this._getAnimationProps())}return this._running?(e!==!1&&(this._cancelAnimationFrame(),this._requestAnimationFrame()),this):null}catch(e){let t=e instanceof Error?e:new Error("Unknown error");throw this.props.onError(t),t}}stop(){return this._running&&(this.animationProps&&!this._error&&this.props.onFinalize(this.animationProps),this._cancelAnimationFrame(),this._nextFramePromise=null,this._resolveNextFrame=null,this._running=!1,this._lastFrameTime=0),this}redraw(e,t=null){return this.device?.isLost||this._error?this:(this._beginFrameTimers(e),this._setupFrame(),this.animationProps&&(this.animationProps.animationFrame=t),this._updateAnimationProps(),this._renderFrame(this._getAnimationProps()),this._clearNeedsRedraw(),this._resolveNextFrame&&(this._resolveNextFrame(this),this._nextFramePromise=null,this._resolveNextFrame=null),this._endFrameTimers(),this)}attachTimeline(e){return this.timeline=e,this.timeline}detachTimeline(){this.timeline=null}waitForRender(){return this.setNeedsRedraw("waitForRender"),this._nextFramePromise||(this._nextFramePromise=new Promise(e=>{this._resolveNextFrame=e})),this._nextFramePromise}async toDataURL(){if(this.setNeedsRedraw("toDataURL"),await this.waitForRender(),this.canvas instanceof HTMLCanvasElement)return this.canvas.toDataURL();throw new Error("OffscreenCanvas")}_initialize(){this._startEventHandling(),this._initializeAnimationProps(),this._updateAnimationProps(),this._resizeViewport(),this.device?._enableDebugGPUTime()}_setDisplay(e){this.display&&(this.display.destroy(),this.display.animationLoop=null),e&&(e.animationLoop=this),this.display=e}_requestAnimationFrame(){this._running&&(this._animationFrameId=this.props.animationFrameProvider.requestAnimationFrame(this._animationFrame.bind(this)))}_cancelAnimationFrame(){this._animationFrameId!==null&&(this.props.animationFrameProvider.cancelAnimationFrame(this._animationFrameId),this._animationFrameId=null)}_animationFrame(e,t){this._running&&(this.redraw(e,t??null),this._requestAnimationFrame())}_renderFrame(e){if(this.display){this.display._renderFrame(e);return}this.props.onRender(this._getAnimationProps()),this.device&&this.device.submit()}_clearNeedsRedraw(){this._needsRedraw=!1}_setupFrame(){this._resizeViewport()}_initializeAnimationProps(){let e=this.device?.getDefaultCanvasContext();if(!this.device||!e)throw new Error("loop");let t=e?.canvas,n=e.props.useDevicePixels;this.animationProps={animationLoop:this,device:this.device,canvasContext:e,canvas:t,useDevicePixels:n,timeline:this.timeline,needsRedraw:!1,width:1,height:1,aspect:1,time:0,startTime:Date.now(),engineTime:0,tick:0,tock:0,animationFrame:null,_mousePosition:null}}_getAnimationProps(){if(!this.animationProps)throw new Error("animationProps");return this.animationProps}_updateAnimationProps(){if(!this.animationProps)return;let{width:e,height:t,aspect:n}=this._getSizeAndAspect();(e!==this.animationProps.width||t!==this.animationProps.height)&&this.setNeedsRedraw("drawing buffer resized"),n!==this.animationProps.aspect&&this.setNeedsRedraw("drawing buffer aspect changed"),this.animationProps.width=e,this.animationProps.height=t,this.animationProps.aspect=n,this.animationProps.needsRedraw=this._needsRedraw,this.animationProps.engineTime=Date.now()-this.animationProps.startTime,this.timeline&&this.timeline.update(this.animationProps.engineTime),this.animationProps.tick=Math.floor(this.animationProps.time/1e3*60),this.animationProps.tock++,this.animationProps.time=this.timeline?this.timeline.getTime():this.animationProps.engineTime}async _initDevice(){if(this.device=await this.props.device,!this.device)throw new Error("No device provided");this.canvas=this.device.getDefaultCanvasContext().canvas||null}_createInfoDiv(){if(this.canvas&&this.props.onAddHTML){let e=document.createElement("div");document.body.appendChild(e),e.style.position="relative";let t=document.createElement("div");t.style.position="absolute",t.style.left="10px",t.style.bottom="10px",t.style.width="300px",t.style.background="white",this.canvas instanceof HTMLCanvasElement&&e.appendChild(this.canvas),e.appendChild(t);let n=this.props.onAddHTML(t);n&&(t.innerHTML=n)}}_getSizeAndAspect(){if(!this.device)return{width:1,height:1,aspect:1};let[e,t]=this.device.getDefaultCanvasContext().getDrawingBufferSize(),n=e>0&&t>0?e/t:1;return{width:e,height:t,aspect:n}}_resizeViewport(){this.props.autoResizeViewport&&this.device.gl&&this.device.gl.viewport(0,0,this.device.gl.drawingBufferWidth,this.device.gl.drawingBufferHeight)}_beginFrameTimers(e){let t=e??(typeof performance<"u"?performance.now():Date.now());if(this._lastFrameTime){let n=t-this._lastFrameTime;n>0&&this.frameRate.addTime(n)}this._lastFrameTime=t,this.device?._isDebugGPUTimeEnabled()&&this._consumeEncodedGpuTime(),this.cpuTime.timeStart()}_endFrameTimers(){this.device?._isDebugGPUTimeEnabled()&&this._consumeEncodedGpuTime(),this.cpuTime.timeEnd(),this._updateSharedStats()}_consumeEncodedGpuTime(){if(!this.device)return;let e=this.device.commandEncoder._gpuTimeMs;e!==void 0&&(this.gpuTime.addTime(e),this.device.commandEncoder._gpuTimeMs=void 0)}_updateSharedStats(){if(this.stats!==this.sharedStats){for(let e of Object.keys(this.sharedStats.stats))this.stats.stats[e]||delete this.sharedStats.stats[e];this.stats.forEach(e=>{let t=this.sharedStats.get(e.name,e.type);t.sampleSize=e.sampleSize,t.time=e.time,t.count=e.count,t.samples=e.samples,t.lastTiming=e.lastTiming,t.lastSampleTime=e.lastSampleTime,t.lastSampleCount=e.lastSampleCount,t._count=e._count,t._time=e._time,t._samples=e._samples,t._startTime=e._startTime,t._timerPending=e._timerPending})}}_startEventHandling(){this.canvas&&(this.canvas.addEventListener("mousemove",this._onMousemove.bind(this)),this.canvas.addEventListener("mouseleave",this._onMouseleave.bind(this)))}_onMousemove(e){e instanceof MouseEvent&&(this._getAnimationProps()._mousePosition=[e.offsetX,e.offsetY])}_onMouseleave(e){this._getAnimationProps()._mousePosition=null}},pe=qt;q(pe,"defaultAnimationLoopProps",{device:null,onAddHTML:()=>"",onInitialize:async()=>null,onRender:()=>{},onFinalize:()=>{},onError:e=>{console.error(e)},stats:void 0,autoResizeViewport:!1,animationFrameProvider:$i});var Vi=L(k(),1);function Xi(i,e){let t=null,n=e?.device||Vi.luma.createDevice({id:"animation-loop",adapters:e?.adapters,createCanvasContext:!0}),r=new pe({...e,device:n,async onInitialize(s){Kr(s.animationLoop.device);try{return t=new i(s),await t?.onInitialize(s)}catch(o){return console.error(o),t=null,qr(s.animationLoop.device,o),s.animationLoop.stop(),null}},onRender:s=>t?.onRender(s),onFinalize:s=>t?.onFinalize(s)});return r.getInfo=()=>this.AnimationLoopTemplateCtor.info,r}function qr(i,e){if(!i)return;let t=i.getDefaultCanvasContext().canvas;if(t instanceof HTMLCanvasElement){t.style.overflow="visible";let n=document.getElementById("animation-loop-error");n?.remove(),n=document.createElement("h1"),n.id="animation-loop-error",n.innerHTML=e.message,n.style.position="absolute",n.style.top="10px",n.style.left="10px",n.style.color="black",n.style.backgroundColor="red",t.parentElement?.appendChild(n)}}function Kr(i){if(!i)return;let e=document.getElementById("animation-loop-error");e&&e.remove()}var T=L(k(),1),Ee=L(ae(),1);var Jt=L(k(),1);var Yi=L(k(),1);var Kt={};function S(i="id"){Kt[i]=Kt[i]||1;let e=Kt[i]++;return`${i}-${e}`}var j=class{id;topology;vertexCount;indices;attributes;bufferLayout;userData={};constructor(e){let{attributes:t={},indices:n=null,vertexCount:r=null}=e;this.id=e.id||S("geometry"),this.topology=e.topology,n&&(this.indices=ArrayBuffer.isView(n)?{value:n,size:1}:n),this.attributes={};for(let[s,o]of Object.entries(t)){let a=ArrayBuffer.isView(o)?{value:o}:o;if(!ArrayBuffer.isView(a.value))throw new Error(`${this._print(s)}: must be typed array or object with value as typed array`);if((s==="POSITION"||s==="positions")&&!a.size&&(a.size=3),s==="indices"){if(this.indices)throw new Error("Multiple indices detected");this.indices=a}else{let c=ge(s),h=Object.keys(this.attributes).find(u=>ge(u)===c);h&&delete this.attributes[h],this.attributes[s]=a}}this.indices&&this.indices.isIndexed!==void 0&&(this.indices=Object.assign({},this.indices),delete this.indices.isIndexed),this.vertexCount=r||this._calculateVertexCount(this.attributes,this.indices),this.bufferLayout=e.bufferLayout||Zr(this.attributes)}getVertexCount(){return this.vertexCount}getAttributes(){return this.indices?{indices:this.indices,...this.attributes}:this.attributes}_print(e){return`Geometry ${this.id} attribute ${e}`}_setAttributes(e,t){return this}_calculateVertexCount(e,t){if(t)return t.value.length;let n=1/0;for(let r of Object.values(e)){if(!r)continue;let{value:s,size:o,constant:a}=r;!a&&s&&o!==void 0&&o>=1&&(n=Math.min(n,s.length/o))}return n}};function ge(i){switch(i){case"POSITION":return"positions";case"NORMAL":return"normals";case"TEXCOORD_0":return"texCoords";case"TEXCOORD_1":return"texCoords1";case"COLOR_0":return"colors";default:return i}}function Zr(i){let e=[];for(let[t,n]of Object.entries(i)){if(!n)continue;let{value:r,size:s,normalized:o}=n;if(s===void 0)throw new Error(`Attribute ${t} is missing a size`);e.push({name:ge(t),format:Yi.vertexFormatDecoder.getVertexFormatFromAttribute(r,s,o)})}return e}var Zt=L(k(),1);function qi(i){let{indices:e,attributes:t}=i;if(!e)return i;let n=e.value.length,r={};for(let s in t){let o=t[s];if(!o)continue;let{value:a,size:c}=o;if(o.constant||!c)continue;let u=a.constructor,d=new u(n*c);for(let l=0;l<n;++l){let m=e.value[l];for(let p=0;p<c;p++)d[l*c+p]=a[m*c+p]}r[s]={size:c,value:d}}return{attributes:Object.assign({},t,r)}}function xt(i,e={}){let t=e.bufferName||"geometry";if(Jr(i,t))return i;let n=e.minAttributeAlignment||4,r=Qr(i,e.attributes),s=[],o=0,a=1/0;for(let[u,d]of r){if(!d)continue;if(d.constant)throw new Error(`Attribute ${u} is constant`);let{value:l,size:m,normalized:p}=d;if(!ArrayBuffer.isView(l))throw new Error(`Attribute ${u} is missing typed array data`);if(m===void 0)throw new Error(`Attribute ${u} is missing a size`);let f=Zt.vertexFormatDecoder.getVertexFormatFromAttribute(l,m,p),x=Zt.vertexFormatDecoder.getVertexFormatInfo(f);o=Wi(o,n),s.push({sourceName:u,attributeName:ge(u),value:l,size:m,format:f,byteOffset:o,byteLength:x.byteLength}),o+=x.byteLength;let _=l.length/m;if(!Number.isInteger(_))throw new Error(`Attribute ${u} length is not divisible by size`);a=Math.min(a,_)}if(s.length===0||!Number.isFinite(a))throw new Error(`Geometry ${i.id} has no interleavable attributes`);let c=Wi(o,n),h=new ArrayBuffer(a*c);for(let u of s)es(h,a,c,u);return new j({id:i.id,topology:i.topology||"triangle-list",vertexCount:i.vertexCount,indices:i.indices,attributes:{[t]:{value:new Uint8Array(h),size:c,byteStride:c}},bufferLayout:[{name:t,stepMode:"vertex",byteStride:c,attributes:s.map(u=>({attribute:u.attributeName,format:u.format,byteOffset:u.byteOffset}))}]})}function Jr(i,e){if(i.bufferLayout.length!==1)return!1;let t=i.bufferLayout[0];return t.name===e&&Boolean(t.attributes?.length)&&Boolean(i.attributes[e])}function Qr(i,e){return e?e.map(t=>[t,i.attributes[t]]):Object.entries(i.attributes)}function es(i,e,t,n){let r=n.value.constructor,s=r.BYTES_PER_ELEMENT;if(n.byteOffset%s!==0||t%s!==0)throw new Error(`Attribute ${n.sourceName} is not aligned to its component type`);let o=new r(i),a=n.value,c=n.byteOffset/s,h=t/s;for(let u=0;u<e;u++){let d=u*n.size,l=u*h+c;for(let m=0;m<n.size;m++)o[l+m]=a[d+m]}}function Wi(i,e){return Math.ceil(i/e)*e}var ve=class{id;userData={};topology;bufferLayout=[];vertexCount;indices;attributes;constructor(e){if(this.id=e.id||S("geometry"),this.topology=e.topology,this.indices=e.indices||null,this.attributes=e.attributes,this.vertexCount=e.vertexCount,this.bufferLayout=e.bufferLayout||[],this.indices&&!(this.indices.usage&Jt.Buffer.INDEX))throw new Error("Index buffer must have INDEX usage")}destroy(){this.indices?.destroy();for(let e of Object.values(this.attributes))e.destroy()}getVertexCount(){return this.vertexCount}getAttributes(){return this.attributes}getIndexes(){return this.indices||null}_calculateVertexCount(e){return e.byteLength/12}};function Ki(i,e){if(e instanceof ve)return e;let t=xt(e),n=ts(i,t),{attributes:r,bufferLayout:s}=is(i,t);return new ve({topology:t.topology||"triangle-list",bufferLayout:s,vertexCount:t.vertexCount,indices:n,attributes:r})}function ts(i,e){if(!e.indices)return;let t=e.indices.value;return i.createBuffer({usage:Jt.Buffer.INDEX,data:t})}function is(i,e){let t={};for(let[n,r]of Object.entries(e.attributes)){let s=e.bufferLayout.find(o=>o.name===n)?.name||ge(n);r&&(t[s]=i.createBuffer({data:r.value,id:`${n}-buffer`}))}return{attributes:t,bufferLayout:e.bufferLayout,vertexCount:e.vertexCount}}function Zi(i,e){let t={},n="Values";if(i.attributes.length===0&&!i.varyings?.length)return{"No attributes or varyings":{[n]:"N/A"}};for(let r of i.attributes)if(r){let s=`${r.location} ${r.name}: ${r.type}`;t[`in ${s}`]={[n]:r.stepMode||"vertex"}}for(let r of i.varyings||[]){let s=`${r.location} ${r.name}`;t[`out ${s}`]={[n]:JSON.stringify(r)}}return t}var Ji="__debugFramebufferState";function en(i,e,t){if(i.device.type!=="webgl")return;let n=ss(i.device);if(!n.flushing){if(as(i)){ns(i,t,n);return}e&&os(e)&&e.handle!==null&&(n.queuedFramebuffers.includes(e)||n.queuedFramebuffers.push(e))}}function ns(i,e,t){if(t.queuedFramebuffers.length===0)return;let n=i.device,{gl:r}=n,s=r.getParameter(36010),o=r.getParameter(36006),[a,c]=i.device.getDefaultCanvasContext().getDrawingBufferSize(),h=Qi(e.top,8),u=Qi(e.left,8);t.flushing=!0;try{for(let d of t.queuedFramebuffers){let[l,m,p,f,x]=rs({framebuffer:d,targetWidth:a,targetHeight:c,topPx:h,leftPx:u,minimap:e.minimap});r.bindFramebuffer(36008,d.handle),r.bindFramebuffer(36009,null),r.blitFramebuffer(0,0,d.width,d.height,l,m,p,f,16384,9728),h+=x+8}}finally{r.bindFramebuffer(36008,s),r.bindFramebuffer(36009,o),t.flushing=!1}}function rs(i){let{framebuffer:e,targetWidth:t,targetHeight:n,topPx:r,leftPx:s,minimap:o}=i,a=o?Math.max(Math.floor(t/4),1):t,c=o?Math.max(Math.floor(n/4),1):n,h=Math.min(a/e.width,c/e.height),u=Math.max(Math.floor(e.width*h),1),d=Math.max(Math.floor(e.height*h),1),l=s,m=Math.max(n-r-d,0),p=l+u,f=m+d;return[l,m,p,f,d]}function ss(i){return i.userData[Ji]||={flushing:!1,queuedFramebuffers:[]},i.userData[Ji]}function os(i){return"colorAttachments"in i}function as(i){let e=i.props.framebuffer;return!e||e.handle===null}function Qi(i,e){if(!i)return e;let t=Number.parseInt(i,10);return Number.isFinite(t)?t:e}function Me(i,e,t){if(i===e)return!0;if(!t||!i||!e)return!1;if(Array.isArray(i)){if(!Array.isArray(e)||i.length!==e.length)return!1;for(let n=0;n<i.length;n++)if(!Me(i[n],e[n],t-1))return!1;return!0}if(Array.isArray(e))return!1;if(typeof i=="object"&&typeof e=="object"){let n=Object.keys(i),r=Object.keys(e);if(n.length!==r.length)return!1;for(let s of n)if(!e.hasOwnProperty(s)||!Me(i[s],e[s],t-1))return!1;return!0}return!1}var tn=L(k(),1),Te=class{bufferLayouts;constructor(e){this.bufferLayouts=e}getBufferLayout(e){return this.bufferLayouts.find(t=>t.name===e)||null}getAttributeNamesForBuffer(e){return(0,tn.getBufferLayoutAttributeNames)(e)}mergeBufferLayouts(e,t){let n=[...e];for(let r of t){let s=n.findIndex(o=>o.name===r.name);s<0?n.push(r):n[s]=r}return n}};var ce=L(k(),1);function nn(i,e){let t=(0,ce.getShaderAttributeLocationMap)(i),n=e.slice();return n.sort((r,s)=>{let o=(0,ce.getMinimumAttributeLocation)((0,ce.getBufferLayoutAttributeNames)(r).map(c=>t[c])),a=(0,ce.getMinimumAttributeLocation)((0,ce.getBufferLayoutAttributeNames)(s).map(c=>t[c]));return o-a}),n}function we(i,e){if(!i||!e.some(n=>n.bindingLayout?.length))return i;let t={...i,bindings:i.bindings.map(n=>({...n}))};"attributes"in(i||{})&&(t.attributes=i?.attributes||[]);for(let n of e)for(let r of n.bindingLayout||[])for(let s of cs(r.name)){let o=t.bindings.find(a=>a.name===s);o?.group===0&&(o.group=r.group),o&&r.visibility!==void 0&&(o.visibility=r.visibility)}return t}function rn(i,e,t=[]){return i?e?{...i,attributes:i.attributes.length?ds(i.attributes,e.attributes.filter(n=>t.includes(n.name))):e.attributes,bindings:us(i.bindings,e.bindings)}:i:e}function Ae(i){return Boolean(i.uniformTypes&&!hs(i.uniformTypes))}function bt(i,e){let t=[],n=new Set;for(let r of[...i||[],...e||[]])n.has(r.name)||(n.add(r.name),t.push(r));return t}function cs(i){let e=new Set([i,`${i}Uniforms`]);return i.endsWith("Uniforms")||e.add(`${i}Sampler`),[...e]}function hs(i){for(let e in i)return!1;return!0}function us(i,e){let t=i.map(s=>({...s})),n=new Set(i.map(s=>s.name)),r=new Set(i.map(s=>`${s.group}:${s.location}`));for(let s of e){let o=`${s.group}:${s.location}`;!n.has(s.name)&&!r.has(o)&&t.push({...s})}return t}function ds(i,e){let t=i.map(s=>({...s})),n=new Map(i.map(s=>[s.name,s])),r=new Map(i.map(s=>[s.location,s]));for(let s of e){let o=n.get(s.name);if(o){if(o.type!==s.type||o.location!==s.location)throw new Error(`Shader attribute "${s.name}" conflicts with its inferred type or location`);continue}let a=r.get(s.location);if(a)throw new Error(`Shader attributes "${a.name}" and "${s.name}" both use location ${s.location}`);t.push({...s})}return t}var yt=L(k(),1),Qt=L(ae(),1);function sn(i){return ArrayBuffer.isView(i)&&!(i instanceof DataView)}function on(i){return Array.isArray(i)?i.length===0||typeof i[0]=="number":!1}function Ue(i){return sn(i)||on(i)}function ls(i){return Ue(i)||typeof i=="number"||typeof i=="boolean"}function an(i,e={}){let t={bindings:{},uniforms:{}};return Object.keys(i).forEach(n=>{let r=i[n];Object.prototype.hasOwnProperty.call(e,n)||ls(r)?t.uniforms[n]=r:t.bindings[n]=r}),t}var U=class{options={disableWarnings:!1};modules;moduleUniforms;moduleBindings;directBindings={};constructor(e,t){Object.assign(this.options,t);let n=(0,Qt.getShaderModuleDependencies)(Object.values(e).filter(fs));for(let r of n)e[r.name]=r;yt.log.log(1,"Creating ShaderInputs with modules",Object.keys(e))(),this.modules=e,this.moduleUniforms={},this.moduleBindings={};for(let[r,s]of Object.entries(e))s&&(this._addModule(s),s.name&&r!==s.name&&!this.options.disableWarnings&&yt.log.warn(`Module name: ${r} vs ${s.name}`)())}destroy(){}setProps(e){e.bindings&&Object.assign(this.directBindings,e.bindings);for(let t of Object.keys(e)){if(t==="bindings")continue;let n=t,r=e[n]||{},s=this.modules[n];if(!s)this.options.disableWarnings||yt.log.warn(`Module ${t} not found`)();else{let o=this.moduleUniforms[n],a=this.moduleBindings[n],c=s.getUniforms?.(r,o)||r,{uniforms:h,bindings:u}=an(c,s.uniformTypes);this.moduleUniforms[n]=cn(o,h,s.uniformTypes),this.moduleBindings[n]={...a,...u}}}}getModules(){return Object.values(this.modules)}addModules(e){let t=(0,Qt.getShaderModuleDependencies)(e);for(let n of t){let r=n.name;this.modules[r]||(this.modules[r]=n,this._addModule(n))}}getUniformValues(){return this.moduleUniforms}getBindingValues(){let e={};for(let t of Object.values(this.moduleBindings))Object.assign(e,t);return Object.assign(e,this.directBindings),e}getModuleBindingValues(e){let t=this.moduleBindings[e];return t?{...t}:{}}getDebugTable(){let e={};for(let[t,n]of Object.entries(this.moduleUniforms))for(let[r,s]of Object.entries(n))e[`${t}.${r}`]={type:this.modules[t].uniformTypes?.[r],value:String(s)};return e}_addModule(e){let t=e.name;this.moduleUniforms[t]=cn({},e.defaultUniforms||{},e.uniformTypes),this.moduleBindings[t]={}}};function cn(i={},e={},t={}){let n={...i};for(let[r,s]of Object.entries(e))s!==void 0&&(n[r]=ei(i[r],s,t[r]));return n}function ei(i,e,t){if(!t||typeof t=="string")return Ve(e);if(Array.isArray(t)){if(ti(e)||!Array.isArray(e))return Ve(e);let o=Array.isArray(i)&&!ti(i)?[...i]:[],a=o.slice();for(let c=0;c<e.length;c++){let h=e[c];h!==void 0&&(a[c]=ei(o[c],h,t[0]))}return a}if(!ii(e))return Ve(e);let n=t,r=ii(i)?i:{},s={...r};for(let[o,a]of Object.entries(e))a!==void 0&&(s[o]=ei(r[o],a,n[o]));return s}function Ve(i){return ArrayBuffer.isView(i)?Array.prototype.slice.call(i):Array.isArray(i)?ti(i)?i.slice():i.map(t=>t===void 0?void 0:Ve(t)):ii(i)?Object.fromEntries(Object.entries(i).map(([e,t])=>[e,t===void 0?void 0:Ve(t)])):i}function ti(i){return ArrayBuffer.isView(i)||Array.isArray(i)&&(i.length===0||typeof i[0]=="number")}function ii(i){return Boolean(i)&&typeof i=="object"&&!Array.isArray(i)&&!ArrayBuffer.isView(i)}function fs(i){return Boolean(i?.dependencies)}var ni=L(k(),1);var ms=ni.Buffer.DEBUG_DATA_MAX_LENGTH,z=class{device;id;ready;usage;props;isReady=!0;destroyed=!1;generation=0;updateTimestamp;debugData=new ArrayBuffer(0);_debugDataEnabled;_maxDebugDataByteLength;_ownsBuffer;_buffer;get buffer(){return this._buffer}get byteLength(){return this._buffer.byteLength}get[Symbol.toStringTag](){return"DynamicBuffer"}toString(){return`DynamicBuffer:"${this.id}":${this.byteLength}B`}toJSON(){return this.toString()}constructor(e,t){let{debugData:n=!1,buffer:r,ownsBuffer:s=!0,...o}=t;if(r&&r.device!==e)throw new Error("DynamicBuffer adopted buffers must belong to the supplied device");if(r&&(o.byteLength!==void 0||o.data!==void 0))throw new Error("DynamicBuffer cannot combine an adopted buffer with byteLength or data");let a=t.id||r?.id||S("dynamic-buffer"),c={...o,id:a,usage:o.usage??r?.usage,indexType:o.indexType??r?.indexType};(c.usage||0)&ni.Buffer.INDEX&&!c.indexType&&(o.data instanceof Uint32Array?c.indexType="uint32":o.data instanceof Uint16Array?c.indexType="uint16":o.data instanceof Uint8Array&&(c.indexType="uint8")),delete c.data,delete c.byteOffset,this.device=e,this.id=a,this.props=c,this.usage=c.usage||0,this._debugDataEnabled=Boolean(n),this._maxDebugDataByteLength=typeof n=="object"&&n.maxByteLength!==void 0?n.maxByteLength:ms,this._ownsBuffer=s,this._buffer=r??this.device.createBuffer({...o,id:a}),this.ready=Promise.resolve(this._buffer),this.updateTimestamp=this._buffer.updateTimestamp,this._resetDebugData(this._buffer.byteLength),o.data&&this._writeDebugData(o.data,o.byteOffset||0)}write(e,t=0){this._buffer.write(e,t),this._touch(),this._writeDebugData(e,t)}async mapAndWriteAsync(e,t=0,n=this.byteLength-t){let r=null;await this._buffer.mapAndWriteAsync(async(s,o)=>{await e(s,o),r=new Uint8Array(s.slice(0,n))},t,n),this._touch(),r&&this._writeDebugData(r,t)}async readAsync(e=0,t=this.byteLength-e){let n=await this._buffer.readAsync(e,t);return this._writeDebugData(n,e)&&this._touch(),n}async mapAndReadAsync(e,t=0,n=this.byteLength-t){let r=null,s=await this._buffer.mapAndReadAsync(async(o,a)=>(r=new Uint8Array(o.slice(0)),await e(o,a)),t,n);return r&&this._writeDebugData(r,t)&&this._touch(),s}resize(e){let{byteLength:t,preserveData:n=!1}=e;if(t===this.byteLength)return!1;let r=Math.min(e.copyByteLength??Math.min(this.byteLength,t),this.byteLength,t),s=this._buffer,o=this.debugData.slice(0),{data:a,byteOffset:c,...h}=this.props,u=this.device.createBuffer({...h,byteLength:t});return n&&r>0&&this._copyBufferContents(s,u,r),this._buffer=u,this._resetDebugData(t),n&&o.byteLength>0&&this._writeDebugData(o,0),this._ownsBuffer&&s.destroy(),this._ownsBuffer=!0,this.generation++,this._touch(),!0}ensureSize(e,t){return e<=this.byteLength?!1:this.resize({byteLength:e,preserveData:t?.preserveData})}getBinding(e){return e?.offset===void 0&&e?.size===void 0?this._buffer:{buffer:this._buffer,offset:e?.offset,size:e?.size}}destroy(){this.destroyed||(this._ownsBuffer&&this._buffer.destroy(),this.destroyed=!0,this.debugData=new ArrayBuffer(0))}_copyBufferContents(e,t,n){let r=this.device.type==="webgpu"?Math.ceil(n/4)*4:n,s=this.device.createCommandEncoder();s.copyBufferToBuffer({sourceBuffer:e,destinationBuffer:t,size:r}),this.device.submit(s.finish())}_touch(){this.updateTimestamp=this.device.incrementTimestamp()}_resetDebugData(e){if(!this._debugDataEnabled){this.debugData=new ArrayBuffer(0);return}this.debugData=new ArrayBuffer(Math.min(e,this._maxDebugDataByteLength))}_writeDebugData(e,t){if(!this._debugDataEnabled||this.debugData.byteLength===0||t>=this.debugData.byteLength)return!1;let n=ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e),r=new Uint8Array(this.debugData),s=Math.min(n.byteLength,r.byteLength-t);return r.set(n.subarray(0,s),t),s>0}};function xe(i){return i!==null&&typeof i=="object"&&"buffer"in i}function hn(i){return i instanceof z?i:xe(i)&&i.buffer instanceof z?i.buffer:null}function ps(i){return i instanceof z?i.buffer:i}function _t(i){return{buffer:ps(i.buffer),offset:i.offset,size:i.size}}var un=L(k(),1);function ie(i){return i!==null&&typeof i=="object"&&"resolveTextureBinding"in i&&typeof i.resolveTextureBinding=="function"}function gs(i){return i?.type==="texture"||i?.type==="external-texture"}function It(i,e,t){let n=(0,un.getShaderLayoutBinding)(i,e,{ignoreWarnings:!0});return gs(n)?n:i.bindings.length===0&&t?.fallbackGroup!==void 0?{type:"texture",name:e,group:t.fallbackGroup,location:0}:null}var Q=2,xs=1e4,ri="render pipeline initialization failed",bs=["stencil8","depth16unorm","depth24plus","depth24plus-stencil8","depth32float","depth32float-stencil8"],si=class{device;id;source;vs;fs;pipelineFactory;shaderFactory;userData={};parameters;topology;bufferLayout;isInstanced=void 0;instanceCount=0;vertexCount;indexCount;firstVertex;firstIndex;indexBuffer=null;bufferAttributes={};constantAttributes={};bindings={};vertexArray;transformFeedback=null;pipeline;shaderInputs;material=null;_uniformStore;_attributeInfos={};_gpuGeometry=null;props;_dynamicIndexBufferSource=null;_dynamicAttributeBufferSources={};_colorAttachmentFormats;_depthStencilAttachmentFormat;_pipelineNeedsUpdate="newly created";_needsRedraw="initializing";_drawBlockedReason=!1;_destroyed=!1;_lastDrawTimestamp=-1;_bindingTable=[];get[Symbol.toStringTag](){return"Model"}toString(){return`Model(${this.id})`}constructor(e,t){this.props={...si.defaultProps,...t},t=this.props,this.id=t.id||S("model"),this.device=e,Object.assign(this.userData,t.userData),this.material=t.material||null;let n=Ms(e),r=(0,Ee.resolveShaderPlugins)(this.props.plugins,n.shaderLanguage),s=(0,Ee.mergeShaderPluginModules)(this.props.modules,r.modules),o=Object.fromEntries(s.map(d=>[d.name,d])),a=t.shaderInputs||new U(o,{disableWarnings:this.props.disableWarnings});t.shaderInputs&&r.modules.length>0&&a.addModules(r.modules),this.setShaderInputs(a);let c=bt(this.props.modules,a.getModules()),h={...r.defines,...this.props.defines};if(this.props.shaderLayout=we(this.props.shaderLayout,c)||null,this.device.type==="webgpu"&&this.props.source){let{source:d,getUniforms:l,bindingTable:m}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:n,...this.props,modules:c,defines:h,pluginInjections:r.injections,pluginVertexInputs:r.vertexInputs,pluginVaryings:r.varyings});this.source=d,this._getModuleUniforms=l,this._bindingTable=m;let p=e.getShaderLayout?.(this.source),f=ys(p,r.vertexInputs),x=rn(this.props.shaderLayout,f,Object.keys(r.vertexInputs));this.props.shaderLayout=we(x||null,c)||null}else{let{vs:d,fs:l,getUniforms:m}=this.props.shaderAssembler.assembleGLSLShaderPair({platformInfo:n,...this.props,modules:c,defines:h,pluginInjections:r.injections,pluginVertexInputs:r.vertexInputs,pluginVaryings:r.varyings});this.vs=d,this.fs=l,this._getModuleUniforms=m,this._bindingTable=[]}this.vertexCount=this.props.vertexCount,this.indexCount=this.props.indexCount,this.firstVertex=this.props.firstVertex,this.firstIndex=this.props.firstIndex,this.instanceCount=this.props.instanceCount,this.topology=this.props.topology,this.bufferLayout=this.props.bufferLayout,this.parameters=this.props.parameters,this._colorAttachmentFormats=this.props.colorAttachmentFormats,this._depthStencilAttachmentFormat=this.props.depthStencilAttachmentFormat,t.geometry&&this.setGeometry(t.geometry),this.pipelineFactory=t.pipelineFactory||T.PipelineFactory.getDefaultPipelineFactory(this.device),this.shaderFactory=t.shaderFactory||T.ShaderFactory.getDefaultShaderFactory(this.device),this.pipeline=this._updatePipeline(),this.vertexArray=e.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry),"isInstanced"in t&&(this.isInstanced=t.isInstanced),t.instanceCount&&this.setInstanceCount(t.instanceCount),t.vertexCount&&this.setVertexCount(t.vertexCount),t.indexBuffer&&this.setIndexBuffer(t.indexBuffer),t.attributes&&this.setAttributes(t.attributes),t.constantAttributes&&this.setConstantAttributes(t.constantAttributes),t.bindings&&this.setBindings(t.bindings),t.transformFeedback&&(this.transformFeedback=t.transformFeedback)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.pipeline.vs),this.pipeline.fs&&this.pipeline.fs!==this.pipeline.vs&&this.shaderFactory.release(this.pipeline.fs),this._uniformStore.destroy(),this._gpuGeometry?.destroy(),this._destroyed=!0)}needsRedraw(){this._getBindingsUpdateTimestamp()>this._lastDrawTimestamp&&this.setNeedsRedraw("contents of bound textures or buffers updated");let e=this._needsRedraw;return this._needsRedraw=!1,e}setNeedsRedraw(e){this._needsRedraw||=e}getBindingDebugTable(){return this._bindingTable}predraw(e){this._syncDynamicBuffers(),this.updateShaderInputs(e),this.material?.updateShaderInputs(e),this.pipeline=this._updatePipeline()}draw(e){if(this._drawBlockedReason&&!this._pipelineNeedsUpdate)return T.log.info(Q,`>>> DRAWING ABORTED ${this.id}: ${this._drawBlockedReason}`)(),!1;let t=this._areBindingsLoading();if(t)return T.log.info(Q,`>>> DRAWING ABORTED ${this.id}: ${t} not loaded`)(),!1;this._syncAttachmentFormats(e);try{e.pushDebugGroup(`${this}.predraw(${e})`),this.device.type==="webgpu"?(this.updateShaderInputs(),this.material?.updateShaderInputs(),this._syncDynamicBuffers(),this.pipeline=this._updatePipeline()):this.predraw(this.device.commandEncoder)}finally{e.popDebugGroup()}let n,r=this.pipeline.isErrored;try{if(e.pushDebugGroup(`${this}.draw(${e})`),this._logDrawCallStart(),this.pipeline=this._updatePipeline(),r=this.pipeline.isErrored,r)T.log.info(Q,`>>> DRAWING ABORTED ${this.id}: ${ri}`)(),n=!1;else{let s=this.vertexArray.getDrawValidationError();if(s)T.log.info(Q,`>>> DRAWING ABORTED ${this.id}: ${s}`)(),this._drawBlockedReason=s,n=!1;else{let o=this._getCurrentShaderLayout(),a=this._getBindings(o),c=this._getBindGroups(o,a),{indexBuffer:h}=this.vertexArray,u=h?this.indexCount??h.byteLength/(h.indexType==="uint32"?4:2):void 0;e.setPipeline(this.pipeline),e.setBindings(c,{_bindGroupCacheKeys:this._getBindGroupCacheKeys()}),e.setVertexArray(this.vertexArray),n=this.isInstanced===!0&&this.instanceCount===0?!0:e.draw({isInstanced:this.isInstanced,vertexCount:this.vertexCount,instanceCount:this.isInstanced?this.instanceCount:void 0,indexCount:u,firstVertex:this.firstVertex,firstIndex:this.firstIndex,transformFeedback:this.transformFeedback||void 0,uniforms:this.props.uniforms,parameters:this.parameters,topology:this.topology})}}}finally{e.popDebugGroup(),this._logDrawCallEnd()}return this._logFramebuffer(e),n?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):r?(this._needsRedraw=ri,this._drawBlockedReason=ri):this._drawBlockedReason?this._needsRedraw=this._drawBlockedReason:this._needsRedraw="waiting for resource initialization",n}setGeometry(e){this._gpuGeometry?.destroy();let t=e&&Ki(this.device,e);if(t){this.setTopology(t.topology||"triangle-list");let n=new Te(this.bufferLayout);this.bufferLayout=n.mergeBufferLayouts(t.bufferLayout,this.bufferLayout),this.vertexArray&&this._setGeometryAttributes(t)}this._gpuGeometry=t}setTopology(e){e!==this.topology&&(this.topology=e,this._setPipelineNeedsUpdate("topology"))}setBufferLayout(e){let t=new Te(this.bufferLayout),n=this._gpuGeometry?t.mergeBufferLayouts(e,this._gpuGeometry.bufferLayout):e;Me(n,this.bufferLayout,-1)||(this.bufferLayout=n,this._setPipelineNeedsUpdate("bufferLayout"),this.pipeline=this._updatePipeline(),this.vertexArray=this.device.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry))}setParameters(e){Me(e,this.parameters,2)||(this.parameters=e,this._setPipelineNeedsUpdate("parameters"))}setInstanceCount(e){this.instanceCount=e,this.isInstanced===void 0&&e>0&&(this.isInstanced=!0),this.setNeedsRedraw("instanceCount")}setVertexCount(e){this.vertexCount=e,this.setNeedsRedraw("vertexCount")}setIndexCount(e){this.indexCount=e,this.setNeedsRedraw("indexCount")}setDrawOffsets({firstVertex:e,firstIndex:t}){this.firstVertex=e,this.firstIndex=t,this.setNeedsRedraw("drawOffsets")}setShaderInputs(e){this.shaderInputs=e,this._uniformStore=new T.UniformStore(this.device,this.shaderInputs.modules);for(let[t,n]of Object.entries(this.shaderInputs.modules))if(Ae(n)&&!this.material?.ownsModule(t)){let r=this._uniformStore.getManagedUniformBuffer(t);this.bindings[`${t}Uniforms`]=r}this.setNeedsRedraw("shaderInputs")}setMaterial(e){this.material=e,this.setNeedsRedraw("material")}updateShaderInputs(e){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(),e),this.setBindings(this._getNonMaterialBindings(this.shaderInputs.getBindingValues())),this.setNeedsRedraw("shaderInputs")}setBindings(e){Object.assign(this.bindings,e),this.setNeedsRedraw("bindings")}setTransformFeedback(e){this.transformFeedback=e,this.setNeedsRedraw("transformFeedback")}setIndexBuffer(e){let t=e instanceof z?e.buffer:e;this.indexBuffer=t,this._dynamicIndexBufferSource=e instanceof z?{source:e,generation:e.generation}:null,this.vertexArray.setIndexBuffer(t),this.setNeedsRedraw("indexBuffer")}setAttributes(e,t){this._drawBlockedReason=!1;let n=t?.disableWarnings??this.props.disableWarnings;e.indices&&T.log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)(),this.bufferLayout=nn(this.pipeline.shaderLayout,this.bufferLayout);let r=new Te(this.bufferLayout);for(let[s,o]of Object.entries(e)){let a=o instanceof z?o.buffer:o,c=r.getBufferLayout(s);if(!c){n||T.log.warn(`Model(${this.id}): Missing layout for buffer "${s}".`)();continue}let h=r.getAttributeNamesForBuffer(c),u=!1;for(let d of h){let l=this._attributeInfos[d];if(l){let m=this.device.type==="webgpu"?this.vertexArray.getBufferSlot(l.bufferName):l.location;if(m===null){n||T.log.warn(`Model(${this.id}): Missing vertex array slot for buffer "${l.bufferName}".`)();continue}this.vertexArray.setBuffer(m,a),o instanceof z?this._dynamicAttributeBufferSources[m]={source:o,generation:o.generation}:delete this._dynamicAttributeBufferSources[m],u=!0}}!u&&!n&&T.log.warn(`Model(${this.id}): Ignoring buffer "${a.id}" for unknown attribute "${s}"`)()}this.setNeedsRedraw("attributes")}setConstantAttributes(e,t){for(let[n,r]of Object.entries(e)){let s=this._attributeInfos[n];s?this.vertexArray.setConstantWebGL(s.location,r):(t?.disableWarnings??this.props.disableWarnings)||T.log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${n}"`)()}this.setNeedsRedraw("constants")}_areBindingsLoading(){for(let e of Object.values(this.bindings))if(ie(e)&&!e.isReady)return e.id;for(let e of Object.values(this.material?.bindings||{}))if(ie(e)&&!e.isReady)return e.id;return!1}_getBindings(e=this._getCurrentShaderLayout()){let t={};for(let[n,r]of Object.entries(this.bindings)){let s=_s(n,r,e);s&&(t[n]=s)}return t}_getBindGroups(e=this._getCurrentShaderLayout(),t=this._getBindings(e)){let n=e.bindings.length?(0,T.normalizeBindingsByGroup)(e,t):{0:t};if(!this.material)return n;for(let[r,s]of Object.entries(this.material.getBindingsByGroup(e))){let o=Number(r);n[o]={...n[o]||{},...s}}return n}_getBindGroupCacheKeys(){let e=this.material?.getBindGroupCacheKey(3);return e?{3:e}:{}}_getBindingsUpdateTimestamp(){let e=0;this._dynamicIndexBufferSource&&(e=Math.max(e,this._dynamicIndexBufferSource.source.updateTimestamp));for(let t of Object.values(this._dynamicAttributeBufferSources))e=Math.max(e,t.source.updateTimestamp);for(let t of Object.values(this.bindings))t instanceof T.TextureView?e=Math.max(e,t.texture.updateTimestamp):t instanceof T.Buffer||t instanceof T.Texture||t instanceof T.ExternalTexture||t instanceof z?e=Math.max(e,t.updateTimestamp):ie(t)?e=t.isReady?Math.max(e,t.updateTimestamp):1/0:xe(t)&&(e=Math.max(e,(t.buffer instanceof z,t.buffer.updateTimestamp)));return Math.max(e,this.material?.getBindingsUpdateTimestamp()||0)}_setGeometryAttributes(e){let t={...e.attributes};for(let[n]of Object.entries(t))!this.pipeline.shaderLayout.attributes.find(r=>r.name===n)&&n!=="positions"&&delete t[n];this.vertexCount=e.vertexCount,this.setIndexBuffer(e.indices||null),this.setAttributes(e.attributes,{disableWarnings:!0}),this.setAttributes(t,{disableWarnings:this.props.disableWarnings}),this.setNeedsRedraw("geometry attributes")}_setPipelineNeedsUpdate(e){this._pipelineNeedsUpdate||=e,this._drawBlockedReason=!1,this.setNeedsRedraw(e)}_updatePipeline(){if(this._pipelineNeedsUpdate){let e=null,t=null;this.pipeline&&(T.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),e=this.pipeline.vs,t=this.pipeline.fs),this._pipelineNeedsUpdate=!1;let n=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:"vertex",source:this.source||this.vs,debugShaders:this.props.debugShaders}),r=null;this.source?r=n:this.fs&&(r=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"fragment",source:this.source||this.fs,debugShaders:this.props.debugShaders})),this.pipeline=this.pipelineFactory.createRenderPipeline({...this.props,bindings:void 0,bufferLayout:this.bufferLayout,colorAttachmentFormats:this._colorAttachmentFormats,depthStencilAttachmentFormat:this._depthStencilAttachmentFormat,topology:this.topology,parameters:this.parameters,bindGroups:void 0,vs:n,fs:r}),this._attributeInfos=(0,T.getAttributeInfosFromLayouts)(this.pipeline.shaderLayout,this.bufferLayout),e&&this.shaderFactory.release(e),t&&t!==e&&this.shaderFactory.release(t)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let e=T.log.level>3?0:xs;T.log.level<2||Date.now()-this._lastLogTime<e||(this._lastLogTime=Date.now(),this._logOpen=!0,T.log.group(Q,`>>> DRAWING MODEL ${this.id}`,{collapsed:T.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let e=Zi(this.pipeline.shaderLayout,this.id);T.log.table(Q,e)();let t=this.shaderInputs.getDebugTable();T.log.table(Q,t)();let n=this._getAttributeDebugTable();T.log.table(Q,this._attributeInfos)(),T.log.table(Q,n)(),T.log.groupEnd(Q)(),this._logOpen=!1}}_drawCount=0;_logFramebuffer(e){let t=this.device.props.debugFramebuffers;if(this._drawCount++,!t)return;let n=e.props.framebuffer;en(e,n,{id:n?.id||`${this.id}-framebuffer`,minimap:!0})}_getAttributeDebugTable(){let e={};for(let[t,n]of Object.entries(this._attributeInfos)){let r=this.vertexArray.attributes[n.location];e[n.location]={name:t,type:n.shaderType,values:r?this._getBufferOrConstantValues(r,n.bufferDataType):"null"}}if(this.vertexArray.indexBuffer){let{indexBuffer:t}=this.vertexArray,n=t.indexType==="uint32"?new Uint32Array(t.debugData):new Uint16Array(t.debugData);e.indices={name:"indices",type:t.indexType,values:n.toString()}}return e}_getBufferOrConstantValues(e,t){let n=T.dataTypeDecoder.getTypedArrayConstructor(t);return(e instanceof T.Buffer?new n(e.debugData):e).toString()}_getNonMaterialBindings(e){if(!this.material)return e;let t={};for(let[n,r]of Object.entries(e))this.material.ownsBinding(n)||(t[n]=r);return t}_getCurrentShaderLayout(){return this.pipeline?.shaderLayout||this.props.shaderLayout||{bindings:[]}}_syncDynamicBuffers(){if(this._dynamicIndexBufferSource&&this._dynamicIndexBufferSource.generation!==this._dynamicIndexBufferSource.source.generation){let e=this._dynamicIndexBufferSource.source.buffer;this.indexBuffer=e,this.vertexArray.setIndexBuffer(e),this._dynamicIndexBufferSource.generation=this._dynamicIndexBufferSource.source.generation,this.setNeedsRedraw("dynamic index buffer")}for(let[e,t]of Object.entries(this._dynamicAttributeBufferSources))t.generation!==t.source.generation&&(this.vertexArray.setBuffer(Number(e),t.source.buffer),t.generation=t.source.generation,this.setNeedsRedraw("dynamic attribute buffer"))}_syncAttachmentFormats(e){if(this.device.type!=="webgpu")return;let t=e.framebuffer||e.props.framebuffer,n=e.props,r=n.colorAttachmentFormats??t?.colorAttachments?.map(o=>Is(o?.texture?.format)),s=n.depthStencilAttachmentFormat===!1?void 0:n.depthStencilAttachmentFormat??vs(t?.depthStencilAttachment?.texture?.format);(!Me(this._colorAttachmentFormats,r,1)||this._depthStencilAttachmentFormat!==s)&&(this._colorAttachmentFormats=r,this._depthStencilAttachmentFormat=s,this._setPipelineNeedsUpdate("attachment formats"))}},Y=si;q(Y,"defaultProps",{...T.RenderPipeline.defaultProps,source:void 0,vs:null,fs:null,id:"unnamed",handle:void 0,userData:{},defines:{},modules:[],plugins:[],geometry:null,indexBuffer:null,indexCount:void 0,firstVertex:0,firstIndex:0,attributes:{},constantAttributes:{},bindings:{},uniforms:{},varyings:[],isInstanced:void 0,instanceCount:0,vertexCount:0,shaderInputs:void 0,material:void 0,pipelineFactory:void 0,shaderFactory:void 0,transformFeedback:void 0,shaderAssembler:Ee.ShaderAssembler.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0});function ys(i,e){return!i||Object.keys(e).length===0?i:{...i,attributes:i.attributes.map(t=>{let n=t.name.startsWith("_luma_")?t.name.slice(6):null;return n&&e[n]?{...t,name:n}:t})}}function _s(i,e,t){if(ie(e)){let n=It(t,i,{fallbackGroup:0});return n?e.resolveTextureBinding(n):null}return e instanceof z?e.buffer:xe(e)?_t(e):e}function Is(i){return i&&!dn(i)?i:null}function vs(i){return i&&dn(i)?i:void 0}function dn(i){return bs.includes(i)}function Ms(i){return{type:i.type,shaderLanguage:i.info.shadingLanguage,shaderLanguageVersion:i.info.shadingLanguageVersion,gpu:i.info.gpu,limits:i.limits,features:i.features}}var ee=L(k(),1);var Ce=3,Se=class{device;modules;_materialBindingNames;_materialModuleNames;constructor(e,t={}){this.device=e,this.modules=t.modules||[];let n=new U(Object.fromEntries(this.modules.map(r=>[r.name,r])));this._materialBindingNames=Ts(n),this._materialModuleNames=ws(n)}createMaterial(e={}){return new Pe(this.device,{...e,factory:this})}getBindingNames(){return Array.from(this._materialBindingNames)}ownsBinding(e){if(this._materialBindingNames.has(e))return!0;let t=oi(e);return t?this._materialModuleNames.has(t):!1}ownsModule(e){return this._materialModuleNames.has(e)}getBindingsByGroup(e){return Object.keys(e).length>0?{[Ce]:e}:{}}};function oi(i){return i.endsWith("Uniforms")?i.slice(0,-8):null}function Ts(i){let e=new Set;for(let t of Object.values(i.modules))for(let n of t.bindingLayout||[])n.group===Ce&&e.add(n.name);return e}function ws(i){let e=new Set;for(let t of Object.values(i.modules))t.name&&t.bindingLayout?.some(n=>n.group===Ce&&n.name===t.name)&&e.add(t.name);return e}var Pe=class{id;device;factory;shaderInputs;bindings={};_uniformStore;_bindGroupCacheToken={};_dynamicResourceGenerations={};constructor(e,t={}){this.id=t.id||S("material"),this.device=e,this.factory=t.factory||new Se(e,{modules:t.modules||t.shaderInputs?.getModules()||[]});let n=Object.fromEntries((t.shaderInputs?.getModules()||this.factory.modules).map(r=>[r.name,r]));this.shaderInputs=t.shaderInputs||new U(n),this._uniformStore=new ee.UniformStore(this.device,this.shaderInputs.modules);for(let[r,s]of Object.entries(this.shaderInputs.modules))if(this.ownsModule(r)&&Ae(s)){let o=this._uniformStore.getManagedUniformBuffer(r);this.bindings[`${r}Uniforms`]=o}this.updateShaderInputs(),t.bindings&&this._replaceOwnedBindings(t.bindings)}destroy(){this._uniformStore.destroy()}clone(e={}){let t=this.factory.createMaterial({id:e.id,shaderInputs:e.shaderInputs,bindings:{...this.getResourceBindings(),...e.bindings}});return e.shaderInputs||t.setProps(this.shaderInputs.getUniformValues()),e.moduleProps&&t.setProps(e.moduleProps),t.updateShaderInputs(),t}ownsBinding(e){return this.factory.ownsBinding(e)}ownsModule(e){return this.factory.ownsModule(e)}setProps(e){this.shaderInputs.setProps(e)}updateShaderInputs(e){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(),e),this._setOwnedBindings(this.shaderInputs.getBindingValues())&&(this._bindGroupCacheToken={})}getResourceBindings(){let e={};for(let[t,n]of Object.entries(this.bindings))oi(t)||(e[t]=n);return e}getBindings(e={bindings:[]}){this._syncDynamicResourceGenerations();let t={},n=t;for(let[r,s]of Object.entries(this.bindings))if(ie(s)){let o=It(e,r,{fallbackGroup:Ce}),a=o?s.resolveTextureBinding(o):null;a&&(n[r]=a)}else s instanceof z?n[r]=s.buffer:xe(s)?n[r]=_t(s):n[r]=s;return this._syncDynamicResourceGenerations(),t}getBindingsByGroup(e={bindings:[]}){return this.factory.getBindingsByGroup(this.getBindings(e))}getBindGroupCacheKey(e){return this._syncDynamicResourceGenerations(),e===Ce?this._bindGroupCacheToken:null}getBindingsUpdateTimestamp(){let e=0;for(let t of Object.values(this.bindings))t instanceof ee.TextureView?e=Math.max(e,t.texture.updateTimestamp):t instanceof ee.Buffer||t instanceof ee.Texture||t instanceof ee.ExternalTexture||t instanceof z?e=Math.max(e,t.updateTimestamp):ie(t)?e=t.isReady?Math.max(e,t.updateTimestamp):1/0:xe(t)&&(e=Math.max(e,(t.buffer instanceof z,t.buffer.updateTimestamp)));return e}_replaceOwnedBindings(e){this._setOwnedBindings(e)&&(this._bindGroupCacheToken={})}_setOwnedBindings(e){let t=!1;for(let[n,r]of Object.entries(e))r!==void 0&&this.ownsBinding(n)&&this.bindings[n]!==r&&(this.bindings[n]=r,t=!0);return t}_syncDynamicResourceGenerations(){let e={},t=!1;for(let[n,r]of Object.entries(this.bindings)){let s=As(r);s!==null&&(e[n]=s,this._dynamicResourceGenerations[n]!==s&&(t=!0))}Object.keys(e).length!==Object.keys(this._dynamicResourceGenerations).length&&(t=!0),this._dynamicResourceGenerations=e,t&&(this._bindGroupCacheToken={})}};function As(i){return ie(i)?i.generation:hn(i)?.generation??null}var ln=L(k(),1),fn=L(ae(),1);var Es=35980,Ss=35981,vt=class{device;model;transformFeedback;static isSupported(e){return e?.info?.type==="webgl"}constructor(e,t=vt.defaultProps){if(!vt.isSupported(e))throw new Error("BufferTransform not yet implemented on WebGPU");this.device=e,this.model=new Y(this.device,{id:t.id||"buffer-transform-model",fs:t.fs||(0,fn.getPassthroughFS)(),topology:t.topology||"point-list",varyings:t.outputs||t.varyings,...t,bufferMode:t.bufferMode||(t.feedbackBufferMode==="interleaved"?Es:Ss)}),this.transformFeedback=this.device.createTransformFeedback({layout:this.model.pipeline.shaderLayout,buffers:t.feedbackBuffers}),this.model.setTransformFeedback(this.transformFeedback)}destroy(){this.model&&this.model.destroy()}delete(){this.destroy()}run(e){e?.inputBuffers&&this.model.setAttributes(e.inputBuffers),e?.outputBuffers&&this.transformFeedback.setBuffers(e.outputBuffers);let t=this.device.beginRenderPass({discard:!0,...e});this.model.draw(t),t.end()}getBuffer(e){return this.transformFeedback.getBuffer(e)}readAsync(e){let t=this.getBuffer(e);if(!t)throw new Error("BufferTransform#getBuffer");if(t instanceof ln.Buffer)return t.readAsync();let{buffer:n,byteOffset:r=0,byteLength:s=n.byteLength}=t;return n.readAsync(r,s)}},Xe=vt;q(Xe,"defaultProps",{...Y.defaultProps,feedbackBufferMode:"separate",outputs:void 0,feedbackBuffers:void 0});var mn=L(ae(),1);var Cs="transform_output",Mt=class{device;model;sampler;currentIndex=0;samplerTextureMap=null;bindings=[];resources={};constructor(e,t){this.device=e,this.sampler=e.createSampler({addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",minFilter:"nearest",magFilter:"nearest",mipmapFilter:"nearest"}),this.model=new Y(this.device,{id:t.id||S("texture-transform-model"),fs:t.fs||(0,mn.getPassthroughFS)({input:t.targetTextureVarying,inputChannels:t.targetTextureChannels,output:Cs}),vertexCount:t.vertexCount,...t}),this._initialize(t),Object.seal(this)}destroy(){this.model.destroy();for(let e of this.bindings)e.framebuffer?.destroy()}delete(){this.destroy()}run(e){let{framebuffer:t}=this.bindings[this.currentIndex],n=this.device.beginRenderPass({framebuffer:t,...e});this.model.draw(n),n.end(),this.device.submit()}getTargetTexture(){let{targetTexture:e}=this.bindings[this.currentIndex];return e}getFramebuffer(){return this.bindings[this.currentIndex].framebuffer}_initialize(e){this._updateBindings(e)}_updateBindings(e){this.bindings[this.currentIndex]=this._updateBinding(this.bindings[this.currentIndex],e)}_updateBinding(e,{sourceBuffers:t,sourceTextures:n,targetTexture:r}){if(e||(e={sourceBuffers:{},sourceTextures:{},targetTexture:null}),Object.assign(e.sourceTextures,n),Object.assign(e.sourceBuffers,t),r){e.targetTexture=r;let{width:s,height:o}=r;e.framebuffer&&e.framebuffer.destroy(),e.framebuffer=this.device.createFramebuffer({id:"transform-framebuffer",width:s,height:o,colorAttachments:[r]}),e.framebuffer.resize({width:s,height:o})}return e}_setSourceTextureParameters(){let e=this.currentIndex,{sourceTextures:t}=this.bindings[e];for(let n in t)t[n].sampler=this.sampler}};var Ps=`struct VertexInputs {
|
|
8
8
|
@location(0) clipSpacePositions: vec2<f32>,
|
|
9
9
|
@location(1) texCoords: vec2<f32>,
|
|
10
10
|
@location(2) coordinates: vec2<f32>
|
|
@@ -26,7 +26,7 @@ fn vertexMain(inputs: VertexInputs) -> FragmentInputs {
|
|
|
26
26
|
outputs.uv = inputs.texCoords;
|
|
27
27
|
return outputs;
|
|
28
28
|
}
|
|
29
|
-
`,
|
|
29
|
+
`,Ls=`#version 300 es
|
|
30
30
|
in vec2 clipSpacePositions;
|
|
31
31
|
in vec2 texCoords;
|
|
32
32
|
in vec2 coordinates;
|
|
@@ -41,32 +41,37 @@ void main(void) {
|
|
|
41
41
|
coordinate = coordinates;
|
|
42
42
|
uv = texCoords;
|
|
43
43
|
}
|
|
44
|
-
`,
|
|
45
|
-
${e.source}`}),super(t,{id:e.id||S("clip-space"),...e,vs:Or,vertexCount:4,geometry:new $({topology:"triangle-strip",vertexCount:4,attributes:{clipSpacePositions:{size:2,value:new Float32Array(Ui)},texCoords:{size:2,value:new Float32Array(n)},coordinates:{size:2,value:new Float32Array(n)}}})})}};var Rr={name:"background",uniformTypes:{scale:"vec2<f32>"}},kr=`@group(0) @binding(auto) var backgroundTexture: texture_2d<f32>;
|
|
44
|
+
`,pn=[-1,-1,1,-1,-1,1,1,1],he=class extends Y{constructor(e,t){let n=pn.map(r=>r===-1?0:r);t.source&&(t={...t,source:`${Ps}
|
|
45
|
+
${t.source}`}),super(e,{id:t.id||S("clip-space"),...t,vs:Ls,vertexCount:4,geometry:new j({topology:"triangle-strip",vertexCount:4,attributes:{clipSpacePositions:{size:2,value:new Float32Array(pn)},texCoords:{size:2,value:new Float32Array(n)},coordinates:{size:2,value:new Float32Array(n)}}})})}};var N=L(k(),1);var We=L(k(),1);var ai={"+X":0,"-X":1,"+Y":2,"-Y":3,"+Z":4,"-Z":5};function He(i){return i?Array.isArray(i)?i[0]??null:i:null}function gn(i){let{dimension:e,data:t}=i;if(!t)return null;switch(e){case"1d":{let n=He(t);if(!n)return null;let{width:r}=Ye(n);return{width:r,height:1}}case"2d":{if(ArrayBuffer.isView(t))return null;let n=He(t);return n?Ye(n):null}case"3d":case"2d-array":{if(!Array.isArray(t)||t.length===0)return null;let n=He(t[0]);return n?Ye(n):null}case"cube":{let n=Object.keys(t)[0]??null;if(!n)return null;let r=t[n],s=He(r);return s?Ye(s):null}case"cube-array":{if(!Array.isArray(t)||t.length===0)return null;let n=t[0],r=Object.keys(n)[0]??null;if(!r)return null;let s=He(n[r]);return s?Ye(s):null}default:return null}}function Ye(i){if((0,We.isExternalImage)(i))return(0,We.getExternalImageSize)(i);if(typeof i=="object"&&"width"in i&&"height"in i)return{width:i.width,height:i.height};throw new Error("Unsupported mip-level data")}function Os(i){return typeof i=="object"&&i!==null&&"data"in i&&"width"in i&&"height"in i}function Rs(i){return ArrayBuffer.isView(i)}function ci(i){let{textureFormat:e,format:t}=i;if(e&&t&&e!==t)throw new Error(`Conflicting texture formats "${e}" and "${t}" provided for the same mip level`);return e??t}function xn(i){let e=ai[i];if(e===void 0)throw new Error(`Invalid cube face: ${i}`);return e}function ks(i,e){return 6*i+xn(e)}function hi(i){throw new Error("setTexture1DData not supported in WebGL.")}function Ns(i){return Array.isArray(i)?i:[i]}function be(i,e,t,n){let r=Ns(e),s=i,o=[];for(let a=0;a<r.length;a++){let c=r[a];if((0,We.isExternalImage)(c))o.push({type:"external-image",image:c,z:s,mipLevel:a});else if(Os(c))o.push({type:"texture-data",data:c,textureFormat:ci(c),z:s,mipLevel:a});else if(Rs(c)&&t)o.push({type:"texture-data",data:{data:c,width:Math.max(1,t.width>>a),height:Math.max(1,t.height>>a),...n?{format:n}:{}},textureFormat:n,z:s,mipLevel:a});else throw new Error("Unsupported 2D mip-level payload")}return o}function ui(i){let e=[];for(let t=0;t<i.length;t++)e.push(...be(t,i[t]));return e}function di(i){let e=[];for(let t=0;t<i.length;t++)e.push(...be(t,i[t]));return e}function li(i){let e=[];for(let[t,n]of Object.entries(i)){let r=xn(t);e.push(...be(r,n))}return e}function fi(i){let e=[];return i.forEach((t,n)=>{for(let[r,s]of Object.entries(t)){let o=ks(n,r);e.push(...be(o,s))}}),e}var pi=class{device;id;props;_texture=null;_sampler=null;_view=null;ready;isReady=!1;destroyed=!1;generation=0;updateTimestamp;resolveReady=()=>{};rejectReady=()=>{};get texture(){if(!this._texture)throw new Error("Texture not initialized yet");return this._texture}get sampler(){if(!this._sampler)throw new Error("Sampler not initialized yet");return this._sampler}get view(){if(!this._view)throw new Error("View not initialized yet");return this._view}get[Symbol.toStringTag](){return"DynamicTexture"}toString(){let e=this._texture?.width??this.props.width??"?",t=this._texture?.height??this.props.height??"?";return`DynamicTexture:"${this.id}":${e}x${t}px:(${this.isReady?"ready":"loading..."})`}resolveTextureBinding(e){return this.isReady?this.texture:null}constructor(e,t){this.device=e;let n=S("dynamic-texture"),r=t;this.props={...pi.defaultProps,id:n,...t,data:null},this.id=this.props.id,this.ready=new Promise((s,o)=>{this.resolveReady=s,this.rejectReady=o}),this.updateTimestamp=this.device.incrementTimestamp(),this.initAsync(r)}async initAsync(e){try{let t=await this._loadAllData(e);this._checkNotDestroyed();let n=t.data?Ds({...t,width:e.width,height:e.height,format:e.format}):[],r="format"in e&&e.format!==void 0,s="usage"in e&&e.usage!==void 0,a=(()=>{if(this.props.width&&this.props.height)return{width:this.props.width,height:this.props.height};let f=gn(t);return f||{width:this.props.width||1,height:this.props.height||1}})();if(!a||a.width<=0||a.height<=0)throw new Error(`${this} size could not be determined or was zero`);let c=Bs(this.device,n,a,{format:r?e.format:void 0}),h=c.format??this.props.format,u={...this.props,...a,format:h,mipLevels:1,data:void 0};this.device.isTextureFormatCompressed(h)&&!s&&(u.usage=N.Texture.SAMPLE|N.Texture.COPY_DST);let d=this.props.mipmaps&&!c.hasExplicitMipChain&&!this.device.isTextureFormatCompressed(h);if(this.device.type==="webgpu"&&d){let f=this.props.dimension==="3d"?N.Texture.SAMPLE|N.Texture.STORAGE|N.Texture.COPY_DST|N.Texture.COPY_SRC:N.Texture.SAMPLE|N.Texture.RENDER|N.Texture.COPY_DST|N.Texture.COPY_SRC;u.usage|=f}let l=this.device.getMipLevelCount(u.width,u.height),m=c.hasExplicitMipChain?c.mipLevels:this.props.mipLevels==="auto"?l:Math.max(1,Math.min(l,this.props.mipLevels??1)),p={...u,mipLevels:m};this._texture=this.device.createTexture(p),this._sampler=this.texture.sampler,this._view=this.texture.view,this._touchGeneration(),c.subresources.length&&this._setTextureSubresources(c.subresources),this.props.mipmaps&&!c.hasExplicitMipChain&&!d&&N.log.warn(`${this} skipping auto-generated mipmaps for compressed texture format`)(),d&&this.generateMipmaps(),this.isReady=!0,this.resolveReady(this.texture),N.log.info(1,`${this} created`)()}catch(t){let n=t instanceof Error?t:new Error(String(t));this.rejectReady(n)}}destroy(){this._texture&&(this._texture.destroy(),this._texture=null,this._sampler=null,this._view=null),this.isReady=!1,this.destroyed=!0}generateMipmaps(){this.device.type==="webgl"?(this.texture.generateMipmapsWebGL(),this._touch()):this.device.type==="webgpu"?(this.device.generateMipmapsWebGPU(this.texture),this._touch()):N.log.warn(`${this} mipmaps not supported on ${this.device.type}`)}setSampler(e={}){this._checkReady();let t=e instanceof N.Sampler?e:this.device.createSampler(e);this.texture.setSampler(t),this._sampler=t,this._touchGeneration()}async readBuffer(e={}){this.isReady||await this.ready;let t=e.width??this.texture.width,n=e.height??this.texture.height,r=e.depthOrArrayLayers??this.texture.depth,s=this.texture.computeMemoryLayout({width:t,height:n,depthOrArrayLayers:r}),o=this.device.createBuffer({byteLength:s.byteLength,usage:N.Buffer.COPY_DST|N.Buffer.MAP_READ});this.texture.readBuffer({...e,width:t,height:n,depthOrArrayLayers:r},o);let a=this.device.createFence();return await a.signaled,a.destroy(),o}async readAsync(e={}){this.isReady||await this.ready;let t=e.width??this.texture.width,n=e.height??this.texture.height,r=e.depthOrArrayLayers??this.texture.depth,s=this.texture.computeMemoryLayout({width:t,height:n,depthOrArrayLayers:r}),o=await this.readBuffer(e),a=await o.readAsync(0,s.byteLength);return o.destroy(),a.buffer instanceof ArrayBuffer?a.buffer:a.slice().buffer}resize(e){if(this._checkReady(),e.width===this.texture.width&&e.height===this.texture.height)return!1;let t=this.texture;return this._texture=t.clone(e),this._sampler=this.texture.sampler,this._view=this.texture.view,t.destroy(),this._touchGeneration(),N.log.info(`${this} resized`),!0}getCubeFaceIndex(e){let t=ai[e];if(t===void 0)throw new Error(`Invalid cube face: ${e}`);return t}getCubeArrayFaceIndex(e,t){return 6*e+this.getCubeFaceIndex(t)}setTexture1DData(e){if(this._checkReady(),this.texture.props.dimension!=="1d")throw new Error(`${this} is not 1d`);let t=hi(e);this._setTextureSubresources(t)}setTexture2DData(e,t=0){if(this._checkReady(),this.texture.props.dimension!=="2d")throw new Error(`${this} is not 2d`);let n=be(t,e);this._setTextureSubresources(n)}setTexture3DData(e){if(this.texture.props.dimension!=="3d")throw new Error(`${this} is not 3d`);let t=ui(e);this._setTextureSubresources(t)}setTextureArrayData(e){if(this.texture.props.dimension!=="2d-array")throw new Error(`${this} is not 2d-array`);let t=di(e);this._setTextureSubresources(t)}setTextureCubeData(e){if(this.texture.props.dimension!=="cube")throw new Error(`${this} is not cube`);let t=li(e);this._setTextureSubresources(t)}setTextureCubeArrayData(e){if(this.texture.props.dimension!=="cube-array")throw new Error(`${this} is not cube-array`);let t=fi(e);this._setTextureSubresources(t)}_setTextureSubresources(e){for(let t of e){let{z:n,mipLevel:r}=t;switch(t.type){case"external-image":let{image:s,flipY:o}=t;this.texture.copyExternalImage({image:s,z:n,mipLevel:r,flipY:o});break;case"texture-data":let{data:a,textureFormat:c}=t;if(c&&c!==this.texture.format)throw new Error(`${this} mip level ${r} uses format "${c}" but texture format is "${this.texture.format}"`);this.texture.writeData(a.data,{x:0,y:0,z:n,width:a.width,height:a.height,depthOrArrayLayers:1,mipLevel:r});break;default:throw new Error("Unsupported 2D mip-level payload")}}e.length>0&&this._touch()}async _loadAllData(e){let t=await mi(e.data);return{dimension:e.dimension??"2d",data:t??null}}_checkNotDestroyed(){this.destroyed&&N.log.warn(`${this} already destroyed`)}_checkReady(){this.isReady||N.log.warn(`${this} Cannot perform this operation before ready`)}_touch(){this.updateTimestamp=this.device.incrementTimestamp()}_touchGeneration(){this.generation++,this._touch()}},K=pi;q(K,"defaultProps",{...N.Texture.defaultProps,dimension:"2d",data:null,mipmaps:!1});function Ds(i){if(!i.data)return[];let e=i.width&&i.height?{width:i.width,height:i.height}:void 0,t="format"in i?i.format:void 0;switch(i.dimension){case"1d":return hi(i.data);case"2d":return be(0,i.data,e,t);case"3d":return ui(i.data);case"2d-array":return di(i.data);case"cube":return li(i.data);case"cube-array":return fi(i.data);default:throw new Error(`Unhandled dimension ${i.dimension}`)}}function Bs(i,e,t,n){if(e.length===0)return{subresources:e,mipLevels:1,format:n.format,hasExplicitMipChain:!1};let r=new Map;for(let u of e){let d=r.get(u.z)??[];d.push(u),r.set(u.z,d)}let s=e.some(u=>u.mipLevel>0),o=n.format,a=Number.POSITIVE_INFINITY,c=[];for(let[u,d]of r){let l=[...d].sort((v,g)=>v.mipLevel-g.mipLevel),m=l[0];if(!m||m.mipLevel!==0)throw new Error(`DynamicTexture: slice ${u} is missing mip level 0`);let p=yn(i,m);if(p.width!==t.width||p.height!==t.height)throw new Error(`DynamicTexture: slice ${u} base level dimensions ${p.width}x${p.height} do not match expected ${t.width}x${t.height}`);let f=bn(m);if(f){if(o&&o!==f)throw new Error(`DynamicTexture: slice ${u} base level format "${f}" does not match texture format "${o}"`);o=f}let x=o&&i.isTextureFormatCompressed(o)?Fs(i,p.width,p.height,o):i.getMipLevelCount(p.width,p.height),_=0;for(let v=0;v<l.length;v++){let g=l[v];if(!g||g.mipLevel!==v||v>=x)break;let b=yn(i,g),y=Math.max(1,p.width>>v),I=Math.max(1,p.height>>v);if(b.width!==y||b.height!==I)break;let A=bn(g);if(A&&(o||(o=A),A!==o))break;_++,c.push(g)}a=Math.min(a,_)}let h=Number.isFinite(a)?Math.max(1,a):1;return{subresources:c.filter(u=>u.mipLevel<h),mipLevels:h,format:o,hasExplicitMipChain:s}}function bn(i){if(i.type==="texture-data")return i.textureFormat??ci(i.data)}function yn(i,e){switch(e.type){case"external-image":return i.getExternalImageSize(e.image);case"texture-data":return{width:e.data.width,height:e.data.height};default:throw new Error("Unsupported texture subresource")}}function Fs(i,e,t,n){let{blockWidth:r=1,blockHeight:s=1}=i.getTextureFormatInfo(n),o=1;for(let a=1;;a++){let c=Math.max(1,e>>a),h=Math.max(1,t>>a);if(c<r||h<s)break;o++}return o}async function mi(i){if(i=await i,Array.isArray(i))return await Promise.all(i.map(mi));if(i&&typeof i=="object"&&i.constructor===Object){let e=i,t=await Promise.all(Object.values(e).map(mi)),n=Object.keys(e),r={};for(let s=0;s<n.length;s++)r[n[s]]=t[s];return r}return i}var zs={name:"background",uniformTypes:{scale:"vec2<f32>",flipY:"i32"}},js=`@group(0) @binding(auto) var backgroundTexture: texture_2d<f32>;
|
|
46
46
|
@group(0) @binding(auto) var backgroundTextureSampler: sampler;
|
|
47
47
|
struct backgroundUniforms {
|
|
48
48
|
scale: vec2<f32>,
|
|
49
|
+
flipY: i32,
|
|
49
50
|
};
|
|
50
51
|
@group(0) @binding(auto) var<uniform> background: backgroundUniforms;
|
|
51
52
|
|
|
52
53
|
fn billboardTexture_getTextureUV(uv: vec2<f32>) -> vec2<f32> {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
let scale: vec2<f32> = background.scale;
|
|
55
|
+
var position: vec2<f32> = (uv - vec2<f32>(0.5, 0.5)) / scale + vec2<f32>(0.5, 0.5);
|
|
56
|
+
if (background.flipY != 0) {
|
|
57
|
+
position.y = 1.0 - position.y;
|
|
58
|
+
}
|
|
59
|
+
return position;
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
@fragment
|
|
59
63
|
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
let position: vec2<f32> = billboardTexture_getTextureUV(inputs.uv);
|
|
65
|
+
return textureSample(backgroundTexture, backgroundTextureSampler, position);
|
|
62
66
|
}
|
|
63
|
-
`,
|
|
67
|
+
`,Gs=`#version 300 es
|
|
64
68
|
precision highp float;
|
|
65
69
|
|
|
66
70
|
uniform sampler2D backgroundTexture;
|
|
67
71
|
|
|
68
72
|
layout(std140) uniform backgroundUniforms {
|
|
69
73
|
vec2 scale;
|
|
74
|
+
int flipY;
|
|
70
75
|
} background;
|
|
71
76
|
|
|
72
77
|
in vec2 coordinate;
|
|
@@ -74,6 +79,9 @@ out vec4 fragColor;
|
|
|
74
79
|
|
|
75
80
|
vec2 billboardTexture_getTextureUV(vec2 coord) {
|
|
76
81
|
vec2 position = (coord - 0.5) / background.scale + 0.5;
|
|
82
|
+
if (background.flipY != 0) {
|
|
83
|
+
position.y = 1.0 - position.y;
|
|
84
|
+
}
|
|
77
85
|
return position;
|
|
78
86
|
}
|
|
79
87
|
|
|
@@ -81,7 +89,7 @@ void main(void) {
|
|
|
81
89
|
vec2 position = billboardTexture_getTextureUV(coordinate);
|
|
82
90
|
fragColor = texture(backgroundTexture, position);
|
|
83
91
|
}
|
|
84
|
-
`,Mt=class extends st{backgroundTexture=null;constructor(t,e){if(super(t,{...e,id:e.id||"background-texture-model",source:kr,fs:Nr,modules:[...e.modules||[],Rr],parameters:{depthWriteEnabled:!1,...e.parameters||{},...e.blend?{blend:!0,blendColorOperation:"add",blendAlphaOperation:"add",blendColorSrcFactor:"one-minus-dst-alpha",blendColorDstFactor:"one",blendAlphaSrcFactor:"one-minus-dst-alpha",blendAlphaDstFactor:"one"}:{}}}),!e.backgroundTexture)throw new Error("BackgroundTextureModel requires a backgroundTexture prop");this.setProps(e)}setProps(t){let{backgroundTexture:e}=t;if(e)if(this.setBindings({backgroundTexture:e}),e.isReady){let n=e instanceof B?e.texture:e;this.backgroundTexture=n,this.updateScale(n)}else e.ready.then(n=>{this.backgroundTexture=n,this.updateScale(n)})}predraw(){super.predraw()}updateScale(t){if(!t){this.shaderInputs.setProps({background:{scale:[1,1]}});return}let[e,n]=this.device.getCanvasContext().getDrawingBufferSize(),r=t.width,s=t.height,o=e/n,a=r/s,c=1,h=1;o>a?h=o/a:c=a/o,this.shaderInputs.setProps({background:{scale:[c,h]}})}};var _t=class extends ${constructor(t={}){let{id:e=S("sphere-geometry")}=t,{indices:n,attributes:r}=Dr(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{...r,...t.attributes}})}};function Dr(i){let{nlat:t=10,nlong:e=10}=i,s=Math.PI-0,o=0,c=2*Math.PI-o,h=(t+1)*(e+1),l=(M,I,m,x,y)=>i.radius||1,d=new Float32Array(h*3),f=new Float32Array(h*3),p=new Float32Array(h*2),g=h>65535?Uint32Array:Uint16Array,u=new g(t*e*6);for(let M=0;M<=t;M++)for(let I=0;I<=e;I++){let m=I/e,x=M/t,y=I+M*(e+1),_=y*2,T=y*3,C=c*m,E=s*x,O=Math.sin(C),v=Math.cos(C),P=Math.sin(E),L=Math.cos(E),A=v*P,F=L,J=O*P,K=l(A,F,J,m,x);d[T+0]=K*A,d[T+1]=K*F,d[T+2]=K*J,f[T+0]=A,f[T+1]=F,f[T+2]=J,p[_+0]=m,p[_+1]=1-x}let b=e+1;for(let M=0;M<e;M++)for(let I=0;I<t;I++){let m=(M*t+I)*6;u[m+0]=I*b+M,u[m+1]=I*b+M+1,u[m+2]=(I+1)*b+M,u[m+3]=(I+1)*b+M,u[m+4]=I*b+M+1,u[m+5]=(I+1)*b+M+1}return{indices:{size:1,value:u},attributes:{POSITION:{size:3,value:d},NORMAL:{size:3,value:f},TEXCOORD_0:{size:2,value:p}}}}var La=1/Math.PI*180,Ca=1/180*Math.PI,Fr={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Fr}};var z=globalThis.mathgl.config;function Gi(i,{precision:t=z.precision}={}){return i=Br(i),`${parseFloat(i.toPrecision(t))}`}function It(i){return Array.isArray(i)||ArrayBuffer.isView(i)&&!(i instanceof DataView)}function Xe(i,t,e){let n=z.EPSILON;e&&(z.EPSILON=e);try{if(i===t)return!0;if(It(i)&&It(t)){if(i.length!==t.length)return!1;for(let r=0;r<i.length;++r)if(!Xe(i[r],t[r]))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=n}}function Br(i){return Math.round(i/z.EPSILON)*z.EPSILON}var vt=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,e=0){for(let n=0;n<this.ELEMENTS;++n)this[n]=t[n+e];return this.check()}toArray(t=[],e=0){for(let n=0;n<this.ELEMENTS;++n)t[e+n]=this[n];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:It(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 n=0;n<this.ELEMENTS;++n)e+=(n>0?", ":"")+Gi(this[n],t);return`${t.printTypes?this.constructor.name:""}[${e}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let e=0;e<this.ELEMENTS;++e)if(!Xe(this[e],t[e]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let e=0;e<this.ELEMENTS;++e)if(this[e]!==t[e])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,e,n){if(n===void 0)return this.lerp(this,t,e);for(let r=0;r<this.ELEMENTS;++r){let s=t[r],o=typeof e=="number"?e:e[r];this[r]=s+n*(o-s)}return this.check()}min(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=Math.min(t[e],this[e]);return this.check()}max(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=Math.max(t[e],this[e]);return this.check()}clamp(t,e){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t[n]),e[n]);return this.check()}add(...t){for(let e of t)for(let n=0;n<this.ELEMENTS;++n)this[n]+=e[n];return this.check()}subtract(...t){for(let e of t)for(let n=0;n<this.ELEMENTS;++n)this[n]-=e[n];return this.check()}scale(t){if(typeof t=="number")for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;else for(let e=0;e<this.ELEMENTS&&e<t.length;++e)this[e]*=t[e];return this.check()}multiplyByScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;return this.check()}check(){if(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 n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t),e);return this.check()}get elements(){return this}};function zr(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 V(i){if(!Number.isFinite(i))throw new Error(`Invalid number ${JSON.stringify(i)}`);return i}function se(i,t,e=""){if(z.debug&&!zr(i,t))throw new Error(`math.gl: ${e} some fields set to invalid numbers'`);return i}function qe(i,t){if(!i)throw new Error(`math.gl assertion ${t}`)}var oe=class extends vt{get x(){return this[0]}set x(t){this[0]=V(t)}get y(){return this[1]}set y(t){this[1]=V(t)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let t=0;for(let e=0;e<this.ELEMENTS;++e)t+=this[e]*this[e];return t}magnitudeSquared(){return this.lengthSquared()}distance(t){return Math.sqrt(this.distanceSquared(t))}distanceSquared(t){let e=0;for(let n=0;n<this.ELEMENTS;++n){let r=this[n]-t[n];e+=r*r}return V(e)}dot(t){let e=0;for(let n=0;n<this.ELEMENTS;++n)e+=this[n]*t[n];return V(e)}normalize(){let t=this.magnitude();if(t!==0)for(let e=0;e<this.ELEMENTS;++e)this[e]/=t;return this.check()}multiply(...t){for(let e of t)for(let n=0;n<this.ELEMENTS;++n)this[n]*=e[n];return this.check()}divide(...t){for(let e of t)for(let n=0;n<this.ELEMENTS;++n)this[n]/=e[n];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(t){return this.distance(t)}distanceToSquared(t){return this.distanceSquared(t)}getComponent(t){return qe(t>=0&&t<this.ELEMENTS,"index is out of range"),V(this[t])}setComponent(t,e){return qe(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 Ga=Math.PI/180;function jr(){let i=new tt(2);return tt!=Float32Array&&(i[0]=0,i[1]=0),i}function Xi(i,t,e){let n=t[0],r=t[1];return i[0]=e[0]*n+e[4]*r+e[12],i[1]=e[1]*n+e[5]*r+e[13],i}var $a=function(){let i=jr();return function(t,e,n,r,s,o){let a,c;for(e||(e=2),n||(n=0),r?c=Math.min(r*e+n,t.length):c=t.length,a=n;a<c;a+=e)i[0]=t[a],i[1]=t[a+1],s(i,i,o),t[a]=i[0],t[a+1]=i[1];return t}}();function qi(i,t,e){let n=t[0],r=t[1],s=e[3]*n+e[7]*r||1;return i[0]=(e[0]*n+e[4]*r)/s,i[1]=(e[1]*n+e[5]*r)/s,i}function ae(i,t,e){let n=t[0],r=t[1],s=t[2],o=e[3]*n+e[7]*r+e[11]*s||1;return i[0]=(e[0]*n+e[4]*r+e[8]*s)/o,i[1]=(e[1]*n+e[5]*r+e[9]*s)/o,i[2]=(e[2]*n+e[6]*r+e[10]*s)/o,i}function Hi(i,t,e){let n=t[0],r=t[1];return i[0]=e[0]*n+e[2]*r,i[1]=e[1]*n+e[3]*r,i[2]=t[2],i}function Ur(){let i=new tt(3);return tt!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0),i}function Gr(i,t){return i[0]*t[0]+i[1]*t[1]+i[2]*t[2]}function Wi(i,t,e){let n=t[0],r=t[1],s=t[2],o=e[0],a=e[1],c=e[2];return i[0]=r*c-s*a,i[1]=s*o-n*c,i[2]=n*a-r*o,i}function ce(i,t,e){let n=t[0],r=t[1],s=t[2],o=e[3]*n+e[7]*r+e[11]*s+e[15];return o=o||1,i[0]=(e[0]*n+e[4]*r+e[8]*s+e[12])/o,i[1]=(e[1]*n+e[5]*r+e[9]*s+e[13])/o,i[2]=(e[2]*n+e[6]*r+e[10]*s+e[14])/o,i}function Yi(i,t,e){let n=t[0],r=t[1],s=t[2];return i[0]=n*e[0]+r*e[3]+s*e[6],i[1]=n*e[1]+r*e[4]+s*e[7],i[2]=n*e[2]+r*e[5]+s*e[8],i}function Ki(i,t,e){let n=e[0],r=e[1],s=e[2],o=e[3],a=t[0],c=t[1],h=t[2],l=r*h-s*c,d=s*a-n*h,f=n*c-r*a,p=r*f-s*d,g=s*l-n*f,u=n*d-r*l,b=o*2;return l*=b,d*=b,f*=b,p*=2,g*=2,u*=2,i[0]=a+l+p,i[1]=c+d+g,i[2]=h+f+u,i}function Zi(i,t,e,n){let r=[],s=[];return r[0]=t[0]-e[0],r[1]=t[1]-e[1],r[2]=t[2]-e[2],s[0]=r[0],s[1]=r[1]*Math.cos(n)-r[2]*Math.sin(n),s[2]=r[1]*Math.sin(n)+r[2]*Math.cos(n),i[0]=s[0]+e[0],i[1]=s[1]+e[1],i[2]=s[2]+e[2],i}function Qi(i,t,e,n){let r=[],s=[];return r[0]=t[0]-e[0],r[1]=t[1]-e[1],r[2]=t[2]-e[2],s[0]=r[2]*Math.sin(n)+r[0]*Math.cos(n),s[1]=r[1],s[2]=r[2]*Math.cos(n)-r[0]*Math.sin(n),i[0]=s[0]+e[0],i[1]=s[1]+e[1],i[2]=s[2]+e[2],i}function Ji(i,t,e,n){let r=[],s=[];return r[0]=t[0]-e[0],r[1]=t[1]-e[1],r[2]=t[2]-e[2],s[0]=r[0]*Math.cos(n)-r[1]*Math.sin(n),s[1]=r[0]*Math.sin(n)+r[1]*Math.cos(n),s[2]=r[2],i[0]=s[0]+e[0],i[1]=s[1]+e[1],i[2]=s[2]+e[2],i}function tn(i,t){let e=i[0],n=i[1],r=i[2],s=t[0],o=t[1],a=t[2],c=Math.sqrt((e*e+n*n+r*r)*(s*s+o*o+a*a)),h=c&&Gr(i,t)/c;return Math.acos(Math.min(Math.max(h,-1),1))}var qa=function(){let i=Ur();return function(t,e,n,r,s,o){let a,c;for(e||(e=3),n||(n=0),r?c=Math.min(r*e+n,t.length):c=t.length,a=n;a<c;a+=e)i[0]=t[a],i[1]=t[a+1],i[2]=t[a+2],s(i,i,o),t[a]=i[0],t[a+1]=i[1],t[a+2]=i[2];return t}}();var We=[0,0,0],he,q=class extends oe{static get ZERO(){return he||(he=new q(0,0,0),Object.freeze(he)),he}constructor(t=0,e=0,n=0){super(-0,-0,-0),arguments.length===1&&It(t)?this.copy(t):(z.debug&&(V(t),V(e),V(n)),this[0]=t,this[1]=e,this[2]=n)}set(t,e,n){return this[0]=t,this[1]=e,this[2]=n,this.check()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this.check()}fromObject(t){return z.debug&&(V(t.x),V(t.y),V(t.z)),this[0]=t.x,this[1]=t.y,this[2]=t.z,this.check()}toObject(t){return t.x=this[0],t.y=this[1],t.z=this[2],t}get ELEMENTS(){return 3}get z(){return this[2]}set z(t){this[2]=V(t)}angle(t){return tn(this,t)}cross(t){return Wi(this,this,t),this.check()}rotateX({radians:t,origin:e=We}){return Zi(this,this,e,t),this.check()}rotateY({radians:t,origin:e=We}){return Qi(this,this,e,t),this.check()}rotateZ({radians:t,origin:e=We}){return Ji(this,this,e,t),this.check()}transform(t){return this.transformAsPoint(t)}transformAsPoint(t){return ce(this,this,t),this.check()}transformAsVector(t){return ae(this,this,t),this.check()}transformByMatrix3(t){return Yi(this,this,t),this.check()}transformByMatrix2(t){return Hi(this,this,t),this.check()}transformByQuaternion(t){return Ki(this,this,t),this.check()}};var le=class extends vt{toString(){let t="[";if(z.printRowMajor){t+="row-major:";for(let e=0;e<this.RANK;++e)for(let n=0;n<this.RANK;++n)t+=` ${this[n*this.RANK+e]}`}else{t+="column-major:";for(let e=0;e<this.ELEMENTS;++e)t+=` ${this[e]}`}return t+="]",t}getElementIndex(t,e){return e*this.RANK+t}getElement(t,e){return this[e*this.RANK+t]}setElement(t,e,n){return this[e*this.RANK+t]=V(n),this}getColumn(t,e=new Array(this.RANK).fill(-0)){let n=t*this.RANK;for(let r=0;r<this.RANK;++r)e[r]=this[n+r];return e}setColumn(t,e){let n=t*this.RANK;for(let r=0;r<this.RANK;++r)this[n+r]=e[r];return this}};function $r(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 en(i,t){if(i===t){let e=t[1],n=t[2],r=t[3],s=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]=n,i[9]=s,i[11]=t[14],i[12]=r,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 nn(i,t){let e=t[0],n=t[1],r=t[2],s=t[3],o=t[4],a=t[5],c=t[6],h=t[7],l=t[8],d=t[9],f=t[10],p=t[11],g=t[12],u=t[13],b=t[14],M=t[15],I=e*a-n*o,m=e*c-r*o,x=e*h-s*o,y=n*c-r*a,_=n*h-s*a,T=r*h-s*c,C=l*u-d*g,E=l*b-f*g,O=l*M-p*g,v=d*b-f*u,P=d*M-p*u,L=f*M-p*b,A=I*L-m*P+x*v+y*O-_*E+T*C;return A?(A=1/A,i[0]=(a*L-c*P+h*v)*A,i[1]=(r*P-n*L-s*v)*A,i[2]=(u*T-b*_+M*y)*A,i[3]=(f*_-d*T-p*y)*A,i[4]=(c*O-o*L-h*E)*A,i[5]=(e*L-r*O+s*E)*A,i[6]=(b*x-g*T-M*m)*A,i[7]=(l*T-f*x+p*m)*A,i[8]=(o*P-a*O+h*C)*A,i[9]=(n*O-e*P-s*C)*A,i[10]=(g*_-u*x+M*I)*A,i[11]=(d*x-l*_-p*I)*A,i[12]=(a*E-o*v-c*C)*A,i[13]=(e*v-n*E+r*C)*A,i[14]=(u*m-g*y-b*I)*A,i[15]=(l*y-d*m+f*I)*A,i):null}function rn(i){let t=i[0],e=i[1],n=i[2],r=i[3],s=i[4],o=i[5],a=i[6],c=i[7],h=i[8],l=i[9],d=i[10],f=i[11],p=i[12],g=i[13],u=i[14],b=i[15],M=t*o-e*s,I=t*a-n*s,m=e*a-n*o,x=h*g-l*p,y=h*u-d*p,_=l*u-d*g,T=t*_-e*y+n*x,C=s*_-o*y+a*x,E=h*m-l*I+d*M,O=p*m-g*I+u*M;return c*T-r*C+b*E-f*O}function Ye(i,t,e){let n=t[0],r=t[1],s=t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],d=t[8],f=t[9],p=t[10],g=t[11],u=t[12],b=t[13],M=t[14],I=t[15],m=e[0],x=e[1],y=e[2],_=e[3];return i[0]=m*n+x*a+y*d+_*u,i[1]=m*r+x*c+y*f+_*b,i[2]=m*s+x*h+y*p+_*M,i[3]=m*o+x*l+y*g+_*I,m=e[4],x=e[5],y=e[6],_=e[7],i[4]=m*n+x*a+y*d+_*u,i[5]=m*r+x*c+y*f+_*b,i[6]=m*s+x*h+y*p+_*M,i[7]=m*o+x*l+y*g+_*I,m=e[8],x=e[9],y=e[10],_=e[11],i[8]=m*n+x*a+y*d+_*u,i[9]=m*r+x*c+y*f+_*b,i[10]=m*s+x*h+y*p+_*M,i[11]=m*o+x*l+y*g+_*I,m=e[12],x=e[13],y=e[14],_=e[15],i[12]=m*n+x*a+y*d+_*u,i[13]=m*r+x*c+y*f+_*b,i[14]=m*s+x*h+y*p+_*M,i[15]=m*o+x*l+y*g+_*I,i}function sn(i,t,e){let n=e[0],r=e[1],s=e[2],o,a,c,h,l,d,f,p,g,u,b,M;return t===i?(i[12]=t[0]*n+t[4]*r+t[8]*s+t[12],i[13]=t[1]*n+t[5]*r+t[9]*s+t[13],i[14]=t[2]*n+t[6]*r+t[10]*s+t[14],i[15]=t[3]*n+t[7]*r+t[11]*s+t[15]):(o=t[0],a=t[1],c=t[2],h=t[3],l=t[4],d=t[5],f=t[6],p=t[7],g=t[8],u=t[9],b=t[10],M=t[11],i[0]=o,i[1]=a,i[2]=c,i[3]=h,i[4]=l,i[5]=d,i[6]=f,i[7]=p,i[8]=g,i[9]=u,i[10]=b,i[11]=M,i[12]=o*n+l*r+g*s+t[12],i[13]=a*n+d*r+u*s+t[13],i[14]=c*n+f*r+b*s+t[14],i[15]=h*n+p*r+M*s+t[15]),i}function on(i,t,e){let n=e[0],r=e[1],s=e[2];return i[0]=t[0]*n,i[1]=t[1]*n,i[2]=t[2]*n,i[3]=t[3]*n,i[4]=t[4]*r,i[5]=t[5]*r,i[6]=t[6]*r,i[7]=t[7]*r,i[8]=t[8]*s,i[9]=t[9]*s,i[10]=t[10]*s,i[11]=t[11]*s,i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15],i}function an(i,t,e,n){let r=n[0],s=n[1],o=n[2],a=Math.sqrt(r*r+s*s+o*o),c,h,l,d,f,p,g,u,b,M,I,m,x,y,_,T,C,E,O,v,P,L,A,F;return a<1e-6?null:(a=1/a,r*=a,s*=a,o*=a,h=Math.sin(e),c=Math.cos(e),l=1-c,d=t[0],f=t[1],p=t[2],g=t[3],u=t[4],b=t[5],M=t[6],I=t[7],m=t[8],x=t[9],y=t[10],_=t[11],T=r*r*l+c,C=s*r*l+o*h,E=o*r*l-s*h,O=r*s*l-o*h,v=s*s*l+c,P=o*s*l+r*h,L=r*o*l+s*h,A=s*o*l-r*h,F=o*o*l+c,i[0]=d*T+u*C+m*E,i[1]=f*T+b*C+x*E,i[2]=p*T+M*C+y*E,i[3]=g*T+I*C+_*E,i[4]=d*O+u*v+m*P,i[5]=f*O+b*v+x*P,i[6]=p*O+M*v+y*P,i[7]=g*O+I*v+_*P,i[8]=d*L+u*A+m*F,i[9]=f*L+b*A+x*F,i[10]=p*L+M*A+y*F,i[11]=g*L+I*A+_*F,t!==i&&(i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i)}function cn(i,t,e){let n=Math.sin(e),r=Math.cos(e),s=t[4],o=t[5],a=t[6],c=t[7],h=t[8],l=t[9],d=t[10],f=t[11];return t!==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]=s*r+h*n,i[5]=o*r+l*n,i[6]=a*r+d*n,i[7]=c*r+f*n,i[8]=h*r-s*n,i[9]=l*r-o*n,i[10]=d*r-a*n,i[11]=f*r-c*n,i}function hn(i,t,e){let n=Math.sin(e),r=Math.cos(e),s=t[0],o=t[1],a=t[2],c=t[3],h=t[8],l=t[9],d=t[10],f=t[11];return t!==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]=s*r-h*n,i[1]=o*r-l*n,i[2]=a*r-d*n,i[3]=c*r-f*n,i[8]=s*n+h*r,i[9]=o*n+l*r,i[10]=a*n+d*r,i[11]=c*n+f*r,i}function ln(i,t,e){let n=Math.sin(e),r=Math.cos(e),s=t[0],o=t[1],a=t[2],c=t[3],h=t[4],l=t[5],d=t[6],f=t[7];return t!==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]=s*r+h*n,i[1]=o*r+l*n,i[2]=a*r+d*n,i[3]=c*r+f*n,i[4]=h*r-s*n,i[5]=l*r-o*n,i[6]=d*r-a*n,i[7]=f*r-c*n,i}function dn(i,t){let e=t[0],n=t[1],r=t[2],s=t[3],o=e+e,a=n+n,c=r+r,h=e*o,l=n*o,d=n*a,f=r*o,p=r*a,g=r*c,u=s*o,b=s*a,M=s*c;return i[0]=1-d-g,i[1]=l+M,i[2]=f-b,i[3]=0,i[4]=l-M,i[5]=1-h-g,i[6]=p+u,i[7]=0,i[8]=f+b,i[9]=p-u,i[10]=1-h-d,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i}function fn(i,t,e,n,r,s,o){let a=1/(e-t),c=1/(r-n),h=1/(s-o);return i[0]=s*2*a,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=s*2*c,i[6]=0,i[7]=0,i[8]=(e+t)*a,i[9]=(r+n)*c,i[10]=(o+s)*h,i[11]=-1,i[12]=0,i[13]=0,i[14]=o*s*2*h,i[15]=0,i}function Vr(i,t,e,n,r){let s=1/Math.tan(t/2);if(i[0]=s/e,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=s,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[11]=-1,i[12]=0,i[13]=0,i[15]=0,r!=null&&r!==1/0){let o=1/(n-r);i[10]=(r+n)*o,i[14]=2*r*n*o}else i[10]=-1,i[14]=-2*n;return i}var un=Vr;function Xr(i,t,e,n,r,s,o){let a=1/(t-e),c=1/(n-r),h=1/(s-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]=(r+n)*c,i[14]=(o+s)*h,i[15]=1,i}var mn=Xr;function pn(i,t,e,n){let r,s,o,a,c,h,l,d,f,p,g=t[0],u=t[1],b=t[2],M=n[0],I=n[1],m=n[2],x=e[0],y=e[1],_=e[2];return Math.abs(g-x)<1e-6&&Math.abs(u-y)<1e-6&&Math.abs(b-_)<1e-6?$r(i):(d=g-x,f=u-y,p=b-_,r=1/Math.sqrt(d*d+f*f+p*p),d*=r,f*=r,p*=r,s=I*p-m*f,o=m*d-M*p,a=M*f-I*d,r=Math.sqrt(s*s+o*o+a*a),r?(r=1/r,s*=r,o*=r,a*=r):(s=0,o=0,a=0),c=f*a-p*o,h=p*s-d*a,l=d*o-f*s,r=Math.sqrt(c*c+h*h+l*l),r?(r=1/r,c*=r,h*=r,l*=r):(c=0,h=0,l=0),i[0]=s,i[1]=c,i[2]=d,i[3]=0,i[4]=o,i[5]=h,i[6]=f,i[7]=0,i[8]=a,i[9]=l,i[10]=p,i[11]=0,i[12]=-(s*g+o*u+a*b),i[13]=-(c*g+h*u+l*b),i[14]=-(d*g+f*u+p*b),i[15]=1,i)}function qr(){let i=new tt(4);return tt!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0,i[3]=0),i}function gn(i,t,e){let n=t[0],r=t[1],s=t[2],o=t[3];return i[0]=e[0]*n+e[4]*r+e[8]*s+e[12]*o,i[1]=e[1]*n+e[5]*r+e[9]*s+e[13]*o,i[2]=e[2]*n+e[6]*r+e[10]*s+e[14]*o,i[3]=e[3]*n+e[7]*r+e[11]*s+e[15]*o,i}var sc=function(){let i=qr();return function(t,e,n,r,s,o){let a,c;for(e||(e=4),n||(n=0),r?c=Math.min(r*e+n,t.length):c=t.length,a=n;a<c;a+=e)i[0]=t[a],i[1]=t[a+1],i[2]=t[a+2],i[3]=t[a+3],s(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 Qe;(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"})(Qe||(Qe={}));var Hr=45*Math.PI/180,Wr=1,Ke=.1,Ze=500,Yr=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),X=class extends le{static get IDENTITY(){return Zr()}static get ZERO(){return Kr()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Qe}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,e,n,r,s,o,a,c,h,l,d,f,p,g,u,b){return this[0]=t,this[1]=e,this[2]=n,this[3]=r,this[4]=s,this[5]=o,this[6]=a,this[7]=c,this[8]=h,this[9]=l,this[10]=d,this[11]=f,this[12]=p,this[13]=g,this[14]=u,this[15]=b,this.check()}setRowMajor(t,e,n,r,s,o,a,c,h,l,d,f,p,g,u,b){return this[0]=t,this[1]=s,this[2]=h,this[3]=p,this[4]=e,this[5]=o,this[6]=l,this[7]=g,this[8]=n,this[9]=a,this[10]=d,this[11]=u,this[12]=r,this[13]=c,this[14]=f,this[15]=b,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(Yr)}fromObject(t){return this.check()}fromQuaternion(t){return dn(this,t),this.check()}frustum(t){let{left:e,right:n,bottom:r,top:s,near:o=Ke,far:a=Ze}=t;return a===1/0?Qr(this,e,n,r,s,o):fn(this,e,n,r,s,o,a),this.check()}lookAt(t){let{eye:e,center:n=[0,0,0],up:r=[0,1,0]}=t;return pn(this,e,n,r),this.check()}ortho(t){let{left:e,right:n,bottom:r,top:s,near:o=Ke,far:a=Ze}=t;return mn(this,e,n,r,s,o,a),this.check()}orthographic(t){let{fovy:e=Hr,aspect:n=Wr,focalDistance:r=1,near:s=Ke,far:o=Ze}=t;xn(e);let a=e/2,c=r*Math.tan(a),h=c*n;return this.ortho({left:-h,right:h,bottom:-c,top:c,near:s,far:o})}perspective(t){let{fovy:e=45*Math.PI/180,aspect:n=1,near:r=.1,far:s=500}=t;return xn(e),un(this,e,n,r,s),this.check()}determinant(){return rn(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,e){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],e=e||[-0,-0,-0];let n=this.getScale(e),r=1/n[0],s=1/n[1],o=1/n[2];return t[0]=this[0]*r,t[1]=this[1]*s,t[2]=this[2]*o,t[3]=0,t[4]=this[4]*r,t[5]=this[5]*s,t[6]=this[6]*o,t[7]=0,t[8]=this[8]*r,t[9]=this[9]*s,t[10]=this[10]*o,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,e){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],e=e||[-0,-0,-0];let n=this.getScale(e),r=1/n[0],s=1/n[1],o=1/n[2];return t[0]=this[0]*r,t[1]=this[1]*s,t[2]=this[2]*o,t[3]=this[4]*r,t[4]=this[5]*s,t[5]=this[6]*o,t[6]=this[8]*r,t[7]=this[9]*s,t[8]=this[10]*o,t}transpose(){return en(this,this),this.check()}invert(){return nn(this,this),this.check()}multiplyLeft(t){return Ye(this,t,this),this.check()}multiplyRight(t){return Ye(this,this,t),this.check()}rotateX(t){return cn(this,this,t),this.check()}rotateY(t){return hn(this,this,t),this.check()}rotateZ(t){return ln(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,e){return an(this,this,t,e),this.check()}scale(t){return on(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return sn(this,this,t),this.check()}transform(t,e){return t.length===4?(e=gn(e||[-0,-0,-0,-0],t,this),se(e,4),e):this.transformAsPoint(t,e)}transformAsPoint(t,e){let{length:n}=t,r;switch(n){case 2:r=Xi(e||[-0,-0],t,this);break;case 3:r=ce(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return se(r,t.length),r}transformAsVector(t,e){let n;switch(t.length){case 2:n=qi(e||[-0,-0],t,this);break;case 3:n=ae(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return se(n,t.length),n}transformPoint(t,e){return this.transformAsPoint(t,e)}transformVector(t,e){return this.transformAsPoint(t,e)}transformDirection(t,e){return this.transformAsVector(t,e)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,e,n){return this.identity().translate([t,e,n])}},de,fe;function Kr(){return de||(de=new X([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(de)),de}function Zr(){return fe||(fe=new X,Object.freeze(fe)),fe}function xn(i){if(i>Math.PI*2)throw Error("expected radians")}function Qr(i,t,e,n,r,s){let o=2*s/(e-t),a=2*s/(r-n),c=(e+t)/(e-t),h=(r+n)/(r-n),l=-1,d=-1,f=-2*s;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]=d,i[12]=0,i[13]=0,i[14]=f,i[15]=0,i}var Jr=.02,ts=.12,es=.15,is=.2,ei=[0,1,0],ns=[255,255,255],rs=1,Je=.35,ti=255,ss=1,os=.01,as={depthCompare:"less-equal",depthWriteEnabled:!1,cullMode:"none"},cs=[{name:"instancePosition",format:"float32x3",stepMode:"instance"},{name:"instanceDirection",format:"float32x3",stepMode:"instance"},{name:"instanceScale",format:"float32x3",stepMode:"instance"},{name:"instanceColor",format:"float32x4",stepMode:"instance"}],hs={name:"lightMarker",props:{},uniforms:{},uniformTypes:{viewProjectionMatrix:"mat4x4<f32>"}},ls="inputs.positions * inputs.instanceScale",ds="vec3<f32>(inputs.positions.x * inputs.instanceScale.x, (inputs.positions.y - 0.5) * inputs.instanceScale.y, inputs.positions.z * inputs.instanceScale.z)",fs="positions * instanceScale",us="vec3(positions.x * instanceScale.x, (positions.y - 0.5) * instanceScale.y, positions.z * instanceScale.z)",ot=class extends H{lightModelProps;_instanceData;_managedBuffers;buildInstanceData;sizePropNames;constructor(t,e,n){let r=n.buildInstanceData(e),s=bn(t,e.id||n.idPrefix,r),o=new G({lightMarker:hs});o.setProps({lightMarker:{viewProjectionMatrix:Mn(e)}});let{source:a,vs:c,fs:h}=bs(n.anchorMode),l=e;super(t,{...l,id:e.id||n.idPrefix,source:a,vs:c,fs:h,geometry:n.geometry,shaderInputs:o,bufferLayout:[...cs],attributes:s,instanceCount:r.instanceCount,parameters:_n(e.parameters)}),this.lightModelProps=e,this._instanceData=r,this._managedBuffers=s,this.buildInstanceData=n.buildInstanceData,this.sizePropNames=n.sizePropNames}destroy(){super.destroy(),yn(this._managedBuffers),this._managedBuffers={}}draw(t){return this.instanceCount===0?!0:super.draw(t)}setProps(t){this.lightModelProps={...this.lightModelProps,...t},t.parameters&&this.setParameters(_n(this.lightModelProps.parameters)),("viewMatrix"in t||"projectionMatrix"in t)&&(this.shaderInputs.setProps({lightMarker:{viewProjectionMatrix:Mn(this.lightModelProps)}}),this.setNeedsRedraw("lightMarker camera")),xs(t,this.sizePropNames)&&this.rebuildInstanceData()}rebuildInstanceData(){let t=this.buildInstanceData(this.lightModelProps),e=bn(this.device,this.id,t);this.setAttributes(e),this.setInstanceCount(t.instanceCount),yn(this._managedBuffers),this._managedBuffers=e,this._instanceData=t}};function In(i){let t=An(i.lights),e=ii(i),n=i.pointLightRadius??Jr*e.sceneScale*e.markerScale;return ri(t.length,(r,s)=>({color:ni(r),direction:ei,position:r.position,scale:[n,n,n]}),t)}function vn(i){let t=Tn(i.lights),e=ii(i),n=i.spotLightLength??ts*e.sceneScale*e.markerScale;return ri(t.length,(r,s)=>{let o=zt(r.outerConeAngle??Math.PI/4,0,Math.PI/2-os),a=Math.tan(o)*n;return{color:ni(r),direction:Pn(r.direction),position:r.position,scale:[a,n,a]}},t)}function wn(i){let t=ms(i.lights),e=ii(i),n=i.directionalLightLength??es*e.sceneScale*e.markerScale,r=n*is;return ri(t.length,(s,o)=>{let a=Pn(s.direction),c=[e.sceneCenter[0]-a[0]*e.sceneScale*Je,e.sceneCenter[1]-a[1]*e.sceneScale*Je,e.sceneCenter[2]-a[2]*e.sceneScale*Je];return{color:ni(s),direction:a,position:c,scale:[r,n,r]}},t)}function An(i){return i.filter(t=>t.type==="point")}function Tn(i){return i.filter(t=>t.type==="spot")}function ms(i){return i.filter(t=>t.type==="directional")}function ii(i){let t=ps(i.lights,i.bounds),e=[(t[0][0]+t[1][0])/2,(t[0][1]+t[1][1])/2,(t[0][2]+t[1][2])/2],n=Math.max(Math.hypot(t[1][0]-t[0][0],t[1][1]-t[0][1],t[1][2]-t[0][2]),ss);return{bounds:t,markerScale:Math.max(i.markerScale??rs,0),sceneCenter:e,sceneScale:n}}function ni(i){let t=i.color||ns,e=Math.max(i.intensity??1,0),n=zt(.35+.3*Math.log10(e+1),.35,1);return[zt(t[0]/ti,0,1)*n,zt(t[1]/ti,0,1)*n,zt(t[2]/ti,0,1)*n,1]}function Pn(i){let[t,e,n]=i||ei,r=Math.hypot(t,e,n);return r===0?[...ei]:[t/r,e/r,n/r]}function ri(i,t,e=[]){let n=new Float32Array(i*3),r=new Float32Array(i*3),s=new Float32Array(i*3),o=new Float32Array(i*4);for(let[a,c]of e.entries()){let h=t(c,a);n.set(h.position,a*3),r.set(h.direction,a*3),s.set(h.scale,a*3),o.set(h.color,a*4)}return{instanceCount:i,instancePositions:n,instanceDirections:r,instanceScales:s,instanceColors:o}}function ps(i,t){if(t)return gs(t);let e=[...An(i).map(s=>s.position),...Tn(i).map(s=>s.position)];if(e.length===0)return[[-.5,-.5,-.5],[.5,.5,.5]];let n=[...e[0]],r=[...e[0]];for(let s of e.slice(1))n[0]=Math.min(n[0],s[0]),n[1]=Math.min(n[1],s[1]),n[2]=Math.min(n[2],s[2]),r[0]=Math.max(r[0],s[0]),r[1]=Math.max(r[1],s[1]),r[2]=Math.max(r[2],s[2]);return[n,r]}function gs(i){return[[...i[0]],[...i[1]]]}function bn(i,t,e){return{instancePosition:i.createBuffer({id:`${t}-instance-position`,data:ue(e.instancePositions,3)}),instanceDirection:i.createBuffer({id:`${t}-instance-direction`,data:ue(e.instanceDirections,3)}),instanceScale:i.createBuffer({id:`${t}-instance-scale`,data:ue(e.instanceScales,3)}),instanceColor:i.createBuffer({id:`${t}-instance-color`,data:ue(e.instanceColors,4)})}}function ue(i,t){return i.length>0?i:new Float32Array(t)}function yn(i){for(let t of Object.values(i))t?.destroy()}function Mn(i){return new X(i.projectionMatrix).multiplyRight(i.viewMatrix)}function xs(i,t){return"lights"in i||"bounds"in i||"markerScale"in i?!0:t.some(e=>e in i)}function _n(i){return{...as,...i||{}}}function bs(i){let t=i==="apex"?ds:ls,e=i==="apex"?us:fs;return{source:`struct lightMarkerUniforms {
|
|
92
|
+
`,Le=class extends he{backgroundTexture=null;flipY=!1;constructor(e,t){if(super(e,{...t,id:t.id||"background-texture-model",source:js,fs:Gs,modules:[...t.modules||[],zs],parameters:{depthWriteEnabled:!1,...t.parameters||{},...t.blend?{blend:!0,blendColorOperation:"add",blendAlphaOperation:"add",blendColorSrcFactor:"one-minus-dst-alpha",blendColorDstFactor:"one",blendAlphaSrcFactor:"one-minus-dst-alpha",blendAlphaDstFactor:"one"}:{}}}),!t.backgroundTexture)throw new Error("BackgroundTextureModel requires a backgroundTexture prop");this.setProps(t)}setProps(e){let{backgroundTexture:t}=e;if(e.flipY!==void 0&&(this.flipY=e.flipY,this.backgroundTexture&&this.updateScale(this.backgroundTexture)),t)if(this.setBindings({backgroundTexture:t}),t.isReady){let n=t instanceof K?t.texture:t;this.backgroundTexture=n,this.updateScale(n)}else t.ready.then(n=>{this.backgroundTexture=n,this.updateScale(n)})}predraw(e){super.predraw(e)}updateScale(e){if(!e){this.shaderInputs.setProps({background:{scale:[1,1],flipY:0}});return}let[t,n]=this.device.getCanvasContext().getDrawingBufferSize(),r=e.width,s=e.height,o=t/n,a=r/s,c=1,h=1;o>a?h=o/a:c=a/o,this.shaderInputs.setProps({background:{scale:[c,h],flipY:this.flipY?1:0}})}};var Oe=class extends j{constructor(e={}){let{id:t=S("sphere-geometry")}=e,{indices:n,attributes:r}=$s(e);super({...e,id:t,topology:"triangle-list",indices:n,attributes:{...r,...e.attributes}})}};function $s(i){let{nlat:e=10,nlong:t=10}=i,s=Math.PI-0,o=0,c=2*Math.PI-o,h=(e+1)*(t+1),u=(_,v,g,b,y)=>i.radius||1,d=new Float32Array(h*3),l=new Float32Array(h*3),m=new Float32Array(h*2),p=h>65535?Uint32Array:Uint16Array,f=new p(e*t*6);for(let _=0;_<=e;_++)for(let v=0;v<=t;v++){let g=v/t,b=_/e,y=v+_*(t+1),I=y*2,A=y*3,O=c*g,C=s*b,R=Math.sin(O),M=Math.cos(O),E=Math.sin(C),P=Math.cos(C),w=M*E,G=P,te=R*E,Z=u(w,G,te,g,b);d[A+0]=Z*w,d[A+1]=Z*G,d[A+2]=Z*te,l[A+0]=w,l[A+1]=G,l[A+2]=te,m[I+0]=g,m[I+1]=1-b}let x=t+1;for(let _=0;_<t;_++)for(let v=0;v<e;v++){let g=(_*e+v)*6;f[g+0]=v*x+_,f[g+1]=v*x+_+1,f[g+2]=(v+1)*x+_,f[g+3]=(v+1)*x+_,f[g+4]=v*x+_+1,f[g+5]=(v+1)*x+_+1}return{indices:{size:1,value:f},attributes:{POSITION:{size:3,value:d},NORMAL:{size:3,value:l},TEXCOORD_0:{size:2,value:m}}}}var dh=1/Math.PI*180,lh=1/180*Math.PI,Us={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Us}};var $=globalThis.mathgl.config;function _n(i,{precision:e=$.precision}={}){return i=Vs(i),`${parseFloat(i.toPrecision(e))}`}function Re(i){return Array.isArray(i)||ArrayBuffer.isView(i)&&!(i instanceof DataView)}function gi(i,e,t){let n=$.EPSILON;t&&($.EPSILON=t);try{if(i===e)return!0;if(Re(i)&&Re(e)){if(i.length!==e.length)return!1;for(let r=0;r<i.length;++r)if(!gi(i[r],e[r]))return!1;return!0}return i&&i.equals?i.equals(e):e&&e.equals?e.equals(i):typeof i=="number"&&typeof e=="number"?Math.abs(i-e)<=$.EPSILON*Math.max(1,Math.abs(i),Math.abs(e)):!1}finally{$.EPSILON=n}}function Vs(i){return Math.round(i/$.EPSILON)*$.EPSILON}var ke=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(e,t=0){for(let n=0;n<this.ELEMENTS;++n)this[n]=e[n+t];return this.check()}toArray(e=[],t=0){for(let n=0;n<this.ELEMENTS;++n)e[t+n]=this[n];return e}toObject(e){return e}from(e){return Array.isArray(e)?this.copy(e):this.fromObject(e)}to(e){return e===this?this:Re(e)?this.toArray(e):this.toObject(e)}toTarget(e){return e?this.to(e):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString($)}formatString(e){let t="";for(let n=0;n<this.ELEMENTS;++n)t+=(n>0?", ":"")+_n(this[n],e);return`${e.printTypes?this.constructor.name:""}[${t}]`}equals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(!gi(this[t],e[t]))return!1;return!0}exactEquals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(this[t]!==e[t])return!1;return!0}negate(){for(let e=0;e<this.ELEMENTS;++e)this[e]=-this[e];return this.check()}lerp(e,t,n){if(n===void 0)return this.lerp(this,e,t);for(let r=0;r<this.ELEMENTS;++r){let s=e[r],o=typeof t=="number"?t:t[r];this[r]=s+n*(o-s)}return this.check()}min(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.min(e[t],this[t]);return this.check()}max(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.max(e[t],this[t]);return this.check()}clamp(e,t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],e[n]),t[n]);return this.check()}add(...e){for(let t of e)for(let n=0;n<this.ELEMENTS;++n)this[n]+=t[n];return this.check()}subtract(...e){for(let t of e)for(let n=0;n<this.ELEMENTS;++n)this[n]-=t[n];return this.check()}scale(e){if(typeof e=="number")for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;else for(let t=0;t<this.ELEMENTS&&t<e.length;++t)this[t]*=e[t];return this.check()}multiplyByScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;return this.check()}check(){if($.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let e=this.length===this.ELEMENTS;for(let t=0;t<this.ELEMENTS;++t)e=e&&Number.isFinite(this[t]);return e}sub(e){return this.subtract(e)}setScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=e;return this.check()}addScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]+=e;return this.check()}subScalar(e){return this.addScalar(-e)}multiplyScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;return this.check()}divideScalar(e){return this.multiplyByScalar(1/e)}clampScalar(e,t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],e),t);return this.check()}get elements(){return this}};function Xs(i,e){if(i.length!==e)return!1;for(let t=0;t<i.length;++t)if(!Number.isFinite(i[t]))return!1;return!0}function V(i){if(!Number.isFinite(i))throw new Error(`Invalid number ${JSON.stringify(i)}`);return i}function Tt(i,e,t=""){if($.debug&&!Xs(i,e))throw new Error(`math.gl: ${t} some fields set to invalid numbers'`);return i}function xi(i,e){if(!i)throw new Error(`math.gl assertion ${e}`)}var wt=class extends ke{get x(){return this[0]}set x(e){this[0]=V(e)}get y(){return this[1]}set y(e){this[1]=V(e)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let e=0;for(let t=0;t<this.ELEMENTS;++t)e+=this[t]*this[t];return e}magnitudeSquared(){return this.lengthSquared()}distance(e){return Math.sqrt(this.distanceSquared(e))}distanceSquared(e){let t=0;for(let n=0;n<this.ELEMENTS;++n){let r=this[n]-e[n];t+=r*r}return V(t)}dot(e){let t=0;for(let n=0;n<this.ELEMENTS;++n)t+=this[n]*e[n];return V(t)}normalize(){let e=this.magnitude();if(e!==0)for(let t=0;t<this.ELEMENTS;++t)this[t]/=e;return this.check()}multiply(...e){for(let t of e)for(let n=0;n<this.ELEMENTS;++n)this[n]*=t[n];return this.check()}divide(...e){for(let t of e)for(let n=0;n<this.ELEMENTS;++n)this[n]/=t[n];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(e){return this.distance(e)}distanceToSquared(e){return this.distanceSquared(e)}getComponent(e){return xi(e>=0&&e<this.ELEMENTS,"index is out of range"),V(this[e])}setComponent(e,t){return xi(e>=0&&e<this.ELEMENTS,"index is out of range"),this[e]=t,this.check()}addVectors(e,t){return this.copy(e).add(t)}subVectors(e,t){return this.copy(e).subtract(t)}multiplyVectors(e,t){return this.copy(e).multiply(t)}addScaledVector(e,t){return this.add(new this.constructor(e).multiplyScalar(t))}};var ne=typeof Float32Array<"u"?Float32Array:Array;var Mh=Math.PI/180;function Hs(){let i=new ne(2);return ne!=Float32Array&&(i[0]=0,i[1]=0),i}function Mn(i,e,t){let n=e[0],r=e[1];return i[0]=t[0]*n+t[4]*r+t[12],i[1]=t[1]*n+t[5]*r+t[13],i}var Th=function(){let i=Hs();return function(e,t,n,r,s,o){let a,c;for(t||(t=2),n||(n=0),r?c=Math.min(r*t+n,e.length):c=e.length,a=n;a<c;a+=t)i[0]=e[a],i[1]=e[a+1],s(i,i,o),e[a]=i[0],e[a+1]=i[1];return e}}();function Tn(i,e,t){let n=e[0],r=e[1],s=t[3]*n+t[7]*r||1;return i[0]=(t[0]*n+t[4]*r)/s,i[1]=(t[1]*n+t[5]*r)/s,i}function At(i,e,t){let n=e[0],r=e[1],s=e[2],o=t[3]*n+t[7]*r+t[11]*s||1;return i[0]=(t[0]*n+t[4]*r+t[8]*s)/o,i[1]=(t[1]*n+t[5]*r+t[9]*s)/o,i[2]=(t[2]*n+t[6]*r+t[10]*s)/o,i}function wn(i,e,t){let n=e[0],r=e[1];return i[0]=t[0]*n+t[2]*r,i[1]=t[1]*n+t[3]*r,i[2]=e[2],i}function Ys(){let i=new ne(3);return ne!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0),i}function Ws(i,e){return i[0]*e[0]+i[1]*e[1]+i[2]*e[2]}function An(i,e,t){let n=e[0],r=e[1],s=e[2],o=t[0],a=t[1],c=t[2];return i[0]=r*c-s*a,i[1]=s*o-n*c,i[2]=n*a-r*o,i}function Et(i,e,t){let n=e[0],r=e[1],s=e[2],o=t[3]*n+t[7]*r+t[11]*s+t[15];return o=o||1,i[0]=(t[0]*n+t[4]*r+t[8]*s+t[12])/o,i[1]=(t[1]*n+t[5]*r+t[9]*s+t[13])/o,i[2]=(t[2]*n+t[6]*r+t[10]*s+t[14])/o,i}function En(i,e,t){let n=e[0],r=e[1],s=e[2];return i[0]=n*t[0]+r*t[3]+s*t[6],i[1]=n*t[1]+r*t[4]+s*t[7],i[2]=n*t[2]+r*t[5]+s*t[8],i}function Sn(i,e,t){let n=t[0],r=t[1],s=t[2],o=t[3],a=e[0],c=e[1],h=e[2],u=r*h-s*c,d=s*a-n*h,l=n*c-r*a,m=r*l-s*d,p=s*u-n*l,f=n*d-r*u,x=o*2;return u*=x,d*=x,l*=x,m*=2,p*=2,f*=2,i[0]=a+u+m,i[1]=c+d+p,i[2]=h+l+f,i}function Cn(i,e,t,n){let r=[],s=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],s[0]=r[0],s[1]=r[1]*Math.cos(n)-r[2]*Math.sin(n),s[2]=r[1]*Math.sin(n)+r[2]*Math.cos(n),i[0]=s[0]+t[0],i[1]=s[1]+t[1],i[2]=s[2]+t[2],i}function Pn(i,e,t,n){let r=[],s=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],s[0]=r[2]*Math.sin(n)+r[0]*Math.cos(n),s[1]=r[1],s[2]=r[2]*Math.cos(n)-r[0]*Math.sin(n),i[0]=s[0]+t[0],i[1]=s[1]+t[1],i[2]=s[2]+t[2],i}function Ln(i,e,t,n){let r=[],s=[];return r[0]=e[0]-t[0],r[1]=e[1]-t[1],r[2]=e[2]-t[2],s[0]=r[0]*Math.cos(n)-r[1]*Math.sin(n),s[1]=r[0]*Math.sin(n)+r[1]*Math.cos(n),s[2]=r[2],i[0]=s[0]+t[0],i[1]=s[1]+t[1],i[2]=s[2]+t[2],i}function On(i,e){let t=i[0],n=i[1],r=i[2],s=e[0],o=e[1],a=e[2],c=Math.sqrt((t*t+n*n+r*r)*(s*s+o*o+a*a)),h=c&&Ws(i,e)/c;return Math.acos(Math.min(Math.max(h,-1),1))}var Eh=function(){let i=Ys();return function(e,t,n,r,s,o){let a,c;for(t||(t=3),n||(n=0),r?c=Math.min(r*t+n,e.length):c=e.length,a=n;a<c;a+=t)i[0]=e[a],i[1]=e[a+1],i[2]=e[a+2],s(i,i,o),e[a]=i[0],e[a+1]=i[1],e[a+2]=i[2];return e}}();var yi=[0,0,0],St,H=class extends wt{static get ZERO(){return St||(St=new H(0,0,0),Object.freeze(St)),St}constructor(e=0,t=0,n=0){super(-0,-0,-0),arguments.length===1&&Re(e)?this.copy(e):($.debug&&(V(e),V(t),V(n)),this[0]=e,this[1]=t,this[2]=n)}set(e,t,n){return this[0]=e,this[1]=t,this[2]=n,this.check()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this.check()}fromObject(e){return $.debug&&(V(e.x),V(e.y),V(e.z)),this[0]=e.x,this[1]=e.y,this[2]=e.z,this.check()}toObject(e){return e.x=this[0],e.y=this[1],e.z=this[2],e}get ELEMENTS(){return 3}get z(){return this[2]}set z(e){this[2]=V(e)}angle(e){return On(this,e)}cross(e){return An(this,this,e),this.check()}rotateX({radians:e,origin:t=yi}){return Cn(this,this,t,e),this.check()}rotateY({radians:e,origin:t=yi}){return Pn(this,this,t,e),this.check()}rotateZ({radians:e,origin:t=yi}){return Ln(this,this,t,e),this.check()}transform(e){return this.transformAsPoint(e)}transformAsPoint(e){return Et(this,this,e),this.check()}transformAsVector(e){return At(this,this,e),this.check()}transformByMatrix3(e){return En(this,this,e),this.check()}transformByMatrix2(e){return wn(this,this,e),this.check()}transformByQuaternion(e){return Sn(this,this,e),this.check()}};var Ct=class extends ke{toString(){let e="[";if($.printRowMajor){e+="row-major:";for(let t=0;t<this.RANK;++t)for(let n=0;n<this.RANK;++n)e+=` ${this[n*this.RANK+t]}`}else{e+="column-major:";for(let t=0;t<this.ELEMENTS;++t)e+=` ${this[t]}`}return e+="]",e}getElementIndex(e,t){return t*this.RANK+e}getElement(e,t){return this[t*this.RANK+e]}setElement(e,t,n){return this[t*this.RANK+e]=V(n),this}getColumn(e,t=new Array(this.RANK).fill(-0)){let n=e*this.RANK;for(let r=0;r<this.RANK;++r)t[r]=this[n+r];return t}setColumn(e,t){let n=e*this.RANK;for(let r=0;r<this.RANK;++r)this[n+r]=t[r];return this}};function qs(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 Rn(i,e){if(i===e){let t=e[1],n=e[2],r=e[3],s=e[6],o=e[7],a=e[11];i[1]=e[4],i[2]=e[8],i[3]=e[12],i[4]=t,i[6]=e[9],i[7]=e[13],i[8]=n,i[9]=s,i[11]=e[14],i[12]=r,i[13]=o,i[14]=a}else i[0]=e[0],i[1]=e[4],i[2]=e[8],i[3]=e[12],i[4]=e[1],i[5]=e[5],i[6]=e[9],i[7]=e[13],i[8]=e[2],i[9]=e[6],i[10]=e[10],i[11]=e[14],i[12]=e[3],i[13]=e[7],i[14]=e[11],i[15]=e[15];return i}function kn(i,e){let t=e[0],n=e[1],r=e[2],s=e[3],o=e[4],a=e[5],c=e[6],h=e[7],u=e[8],d=e[9],l=e[10],m=e[11],p=e[12],f=e[13],x=e[14],_=e[15],v=t*a-n*o,g=t*c-r*o,b=t*h-s*o,y=n*c-r*a,I=n*h-s*a,A=r*h-s*c,O=u*f-d*p,C=u*x-l*p,R=u*_-m*p,M=d*x-l*f,E=d*_-m*f,P=l*_-m*x,w=v*P-g*E+b*M+y*R-I*C+A*O;return w?(w=1/w,i[0]=(a*P-c*E+h*M)*w,i[1]=(r*E-n*P-s*M)*w,i[2]=(f*A-x*I+_*y)*w,i[3]=(l*I-d*A-m*y)*w,i[4]=(c*R-o*P-h*C)*w,i[5]=(t*P-r*R+s*C)*w,i[6]=(x*b-p*A-_*g)*w,i[7]=(u*A-l*b+m*g)*w,i[8]=(o*E-a*R+h*O)*w,i[9]=(n*R-t*E-s*O)*w,i[10]=(p*I-f*b+_*v)*w,i[11]=(d*b-u*I-m*v)*w,i[12]=(a*C-o*M-c*O)*w,i[13]=(t*M-n*C+r*O)*w,i[14]=(f*g-p*y-x*v)*w,i[15]=(u*y-d*g+l*v)*w,i):null}function Nn(i){let e=i[0],t=i[1],n=i[2],r=i[3],s=i[4],o=i[5],a=i[6],c=i[7],h=i[8],u=i[9],d=i[10],l=i[11],m=i[12],p=i[13],f=i[14],x=i[15],_=e*o-t*s,v=e*a-n*s,g=t*a-n*o,b=h*p-u*m,y=h*f-d*m,I=u*f-d*p,A=e*I-t*y+n*b,O=s*I-o*y+a*b,C=h*g-u*v+d*_,R=m*g-p*v+f*_;return c*A-r*O+x*C-l*R}function _i(i,e,t){let n=e[0],r=e[1],s=e[2],o=e[3],a=e[4],c=e[5],h=e[6],u=e[7],d=e[8],l=e[9],m=e[10],p=e[11],f=e[12],x=e[13],_=e[14],v=e[15],g=t[0],b=t[1],y=t[2],I=t[3];return i[0]=g*n+b*a+y*d+I*f,i[1]=g*r+b*c+y*l+I*x,i[2]=g*s+b*h+y*m+I*_,i[3]=g*o+b*u+y*p+I*v,g=t[4],b=t[5],y=t[6],I=t[7],i[4]=g*n+b*a+y*d+I*f,i[5]=g*r+b*c+y*l+I*x,i[6]=g*s+b*h+y*m+I*_,i[7]=g*o+b*u+y*p+I*v,g=t[8],b=t[9],y=t[10],I=t[11],i[8]=g*n+b*a+y*d+I*f,i[9]=g*r+b*c+y*l+I*x,i[10]=g*s+b*h+y*m+I*_,i[11]=g*o+b*u+y*p+I*v,g=t[12],b=t[13],y=t[14],I=t[15],i[12]=g*n+b*a+y*d+I*f,i[13]=g*r+b*c+y*l+I*x,i[14]=g*s+b*h+y*m+I*_,i[15]=g*o+b*u+y*p+I*v,i}function Dn(i,e,t){let n=t[0],r=t[1],s=t[2],o,a,c,h,u,d,l,m,p,f,x,_;return e===i?(i[12]=e[0]*n+e[4]*r+e[8]*s+e[12],i[13]=e[1]*n+e[5]*r+e[9]*s+e[13],i[14]=e[2]*n+e[6]*r+e[10]*s+e[14],i[15]=e[3]*n+e[7]*r+e[11]*s+e[15]):(o=e[0],a=e[1],c=e[2],h=e[3],u=e[4],d=e[5],l=e[6],m=e[7],p=e[8],f=e[9],x=e[10],_=e[11],i[0]=o,i[1]=a,i[2]=c,i[3]=h,i[4]=u,i[5]=d,i[6]=l,i[7]=m,i[8]=p,i[9]=f,i[10]=x,i[11]=_,i[12]=o*n+u*r+p*s+e[12],i[13]=a*n+d*r+f*s+e[13],i[14]=c*n+l*r+x*s+e[14],i[15]=h*n+m*r+_*s+e[15]),i}function Bn(i,e,t){let n=t[0],r=t[1],s=t[2];return i[0]=e[0]*n,i[1]=e[1]*n,i[2]=e[2]*n,i[3]=e[3]*n,i[4]=e[4]*r,i[5]=e[5]*r,i[6]=e[6]*r,i[7]=e[7]*r,i[8]=e[8]*s,i[9]=e[9]*s,i[10]=e[10]*s,i[11]=e[11]*s,i[12]=e[12],i[13]=e[13],i[14]=e[14],i[15]=e[15],i}function Fn(i,e,t,n){let r=n[0],s=n[1],o=n[2],a=Math.sqrt(r*r+s*s+o*o),c,h,u,d,l,m,p,f,x,_,v,g,b,y,I,A,O,C,R,M,E,P,w,G;return a<1e-6?null:(a=1/a,r*=a,s*=a,o*=a,h=Math.sin(t),c=Math.cos(t),u=1-c,d=e[0],l=e[1],m=e[2],p=e[3],f=e[4],x=e[5],_=e[6],v=e[7],g=e[8],b=e[9],y=e[10],I=e[11],A=r*r*u+c,O=s*r*u+o*h,C=o*r*u-s*h,R=r*s*u-o*h,M=s*s*u+c,E=o*s*u+r*h,P=r*o*u+s*h,w=s*o*u-r*h,G=o*o*u+c,i[0]=d*A+f*O+g*C,i[1]=l*A+x*O+b*C,i[2]=m*A+_*O+y*C,i[3]=p*A+v*O+I*C,i[4]=d*R+f*M+g*E,i[5]=l*R+x*M+b*E,i[6]=m*R+_*M+y*E,i[7]=p*R+v*M+I*E,i[8]=d*P+f*w+g*G,i[9]=l*P+x*w+b*G,i[10]=m*P+_*w+y*G,i[11]=p*P+v*w+I*G,e!==i&&(i[12]=e[12],i[13]=e[13],i[14]=e[14],i[15]=e[15]),i)}function zn(i,e,t){let n=Math.sin(t),r=Math.cos(t),s=e[4],o=e[5],a=e[6],c=e[7],h=e[8],u=e[9],d=e[10],l=e[11];return e!==i&&(i[0]=e[0],i[1]=e[1],i[2]=e[2],i[3]=e[3],i[12]=e[12],i[13]=e[13],i[14]=e[14],i[15]=e[15]),i[4]=s*r+h*n,i[5]=o*r+u*n,i[6]=a*r+d*n,i[7]=c*r+l*n,i[8]=h*r-s*n,i[9]=u*r-o*n,i[10]=d*r-a*n,i[11]=l*r-c*n,i}function jn(i,e,t){let n=Math.sin(t),r=Math.cos(t),s=e[0],o=e[1],a=e[2],c=e[3],h=e[8],u=e[9],d=e[10],l=e[11];return e!==i&&(i[4]=e[4],i[5]=e[5],i[6]=e[6],i[7]=e[7],i[12]=e[12],i[13]=e[13],i[14]=e[14],i[15]=e[15]),i[0]=s*r-h*n,i[1]=o*r-u*n,i[2]=a*r-d*n,i[3]=c*r-l*n,i[8]=s*n+h*r,i[9]=o*n+u*r,i[10]=a*n+d*r,i[11]=c*n+l*r,i}function Gn(i,e,t){let n=Math.sin(t),r=Math.cos(t),s=e[0],o=e[1],a=e[2],c=e[3],h=e[4],u=e[5],d=e[6],l=e[7];return e!==i&&(i[8]=e[8],i[9]=e[9],i[10]=e[10],i[11]=e[11],i[12]=e[12],i[13]=e[13],i[14]=e[14],i[15]=e[15]),i[0]=s*r+h*n,i[1]=o*r+u*n,i[2]=a*r+d*n,i[3]=c*r+l*n,i[4]=h*r-s*n,i[5]=u*r-o*n,i[6]=d*r-a*n,i[7]=l*r-c*n,i}function $n(i,e){let t=e[0],n=e[1],r=e[2],s=e[3],o=t+t,a=n+n,c=r+r,h=t*o,u=n*o,d=n*a,l=r*o,m=r*a,p=r*c,f=s*o,x=s*a,_=s*c;return i[0]=1-d-p,i[1]=u+_,i[2]=l-x,i[3]=0,i[4]=u-_,i[5]=1-h-p,i[6]=m+f,i[7]=0,i[8]=l+x,i[9]=m-f,i[10]=1-h-d,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i}function Un(i,e,t,n,r,s,o){let a=1/(t-e),c=1/(r-n),h=1/(s-o);return i[0]=s*2*a,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=s*2*c,i[6]=0,i[7]=0,i[8]=(t+e)*a,i[9]=(r+n)*c,i[10]=(o+s)*h,i[11]=-1,i[12]=0,i[13]=0,i[14]=o*s*2*h,i[15]=0,i}function Ks(i,e,t,n,r){let s=1/Math.tan(e/2);if(i[0]=s/t,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=s,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[11]=-1,i[12]=0,i[13]=0,i[15]=0,r!=null&&r!==1/0){let o=1/(n-r);i[10]=(r+n)*o,i[14]=2*r*n*o}else i[10]=-1,i[14]=-2*n;return i}var Vn=Ks;function Zs(i,e,t,n,r,s,o){let a=1/(e-t),c=1/(n-r),h=1/(s-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]=(e+t)*a,i[13]=(r+n)*c,i[14]=(o+s)*h,i[15]=1,i}var Xn=Zs;function Hn(i,e,t,n){let r,s,o,a,c,h,u,d,l,m,p=e[0],f=e[1],x=e[2],_=n[0],v=n[1],g=n[2],b=t[0],y=t[1],I=t[2];return Math.abs(p-b)<1e-6&&Math.abs(f-y)<1e-6&&Math.abs(x-I)<1e-6?qs(i):(d=p-b,l=f-y,m=x-I,r=1/Math.sqrt(d*d+l*l+m*m),d*=r,l*=r,m*=r,s=v*m-g*l,o=g*d-_*m,a=_*l-v*d,r=Math.sqrt(s*s+o*o+a*a),r?(r=1/r,s*=r,o*=r,a*=r):(s=0,o=0,a=0),c=l*a-m*o,h=m*s-d*a,u=d*o-l*s,r=Math.sqrt(c*c+h*h+u*u),r?(r=1/r,c*=r,h*=r,u*=r):(c=0,h=0,u=0),i[0]=s,i[1]=c,i[2]=d,i[3]=0,i[4]=o,i[5]=h,i[6]=l,i[7]=0,i[8]=a,i[9]=u,i[10]=m,i[11]=0,i[12]=-(s*p+o*f+a*x),i[13]=-(c*p+h*f+u*x),i[14]=-(d*p+l*f+m*x),i[15]=1,i)}function Js(){let i=new ne(4);return ne!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0,i[3]=0),i}function Yn(i,e,t){let n=e[0],r=e[1],s=e[2],o=e[3];return i[0]=t[0]*n+t[4]*r+t[8]*s+t[12]*o,i[1]=t[1]*n+t[5]*r+t[9]*s+t[13]*o,i[2]=t[2]*n+t[6]*r+t[10]*s+t[14]*o,i[3]=t[3]*n+t[7]*r+t[11]*s+t[15]*o,i}var jh=function(){let i=Js();return function(e,t,n,r,s,o){let a,c;for(t||(t=4),n||(n=0),r?c=Math.min(r*t+n,e.length):c=e.length,a=n;a<c;a+=t)i[0]=e[a],i[1]=e[a+1],i[2]=e[a+2],i[3]=e[a+3],s(i,i,o),e[a]=i[0],e[a+1]=i[1],e[a+2]=i[2],e[a+3]=i[3];return e}}();var Mi;(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"})(Mi||(Mi={}));var Qs=45*Math.PI/180,eo=1,Ii=.1,vi=500,to=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),X=class extends Ct{static get IDENTITY(){return no()}static get ZERO(){return io()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Mi}constructor(e){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(e)?this.copy(e):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this[9]=e[9],this[10]=e[10],this[11]=e[11],this[12]=e[12],this[13]=e[13],this[14]=e[14],this[15]=e[15],this.check()}set(e,t,n,r,s,o,a,c,h,u,d,l,m,p,f,x){return this[0]=e,this[1]=t,this[2]=n,this[3]=r,this[4]=s,this[5]=o,this[6]=a,this[7]=c,this[8]=h,this[9]=u,this[10]=d,this[11]=l,this[12]=m,this[13]=p,this[14]=f,this[15]=x,this.check()}setRowMajor(e,t,n,r,s,o,a,c,h,u,d,l,m,p,f,x){return this[0]=e,this[1]=s,this[2]=h,this[3]=m,this[4]=t,this[5]=o,this[6]=u,this[7]=p,this[8]=n,this[9]=a,this[10]=d,this[11]=f,this[12]=r,this[13]=c,this[14]=l,this[15]=x,this.check()}toRowMajor(e){return e[0]=this[0],e[1]=this[4],e[2]=this[8],e[3]=this[12],e[4]=this[1],e[5]=this[5],e[6]=this[9],e[7]=this[13],e[8]=this[2],e[9]=this[6],e[10]=this[10],e[11]=this[14],e[12]=this[3],e[13]=this[7],e[14]=this[11],e[15]=this[15],e}identity(){return this.copy(to)}fromObject(e){return this.check()}fromQuaternion(e){return $n(this,e),this.check()}frustum(e){let{left:t,right:n,bottom:r,top:s,near:o=Ii,far:a=vi}=e;return a===1/0?ro(this,t,n,r,s,o):Un(this,t,n,r,s,o,a),this.check()}lookAt(e){let{eye:t,center:n=[0,0,0],up:r=[0,1,0]}=e;return Hn(this,t,n,r),this.check()}ortho(e){let{left:t,right:n,bottom:r,top:s,near:o=Ii,far:a=vi}=e;return Xn(this,t,n,r,s,o,a),this.check()}orthographic(e){let{fovy:t=Qs,aspect:n=eo,focalDistance:r=1,near:s=Ii,far:o=vi}=e;Wn(t);let a=t/2,c=r*Math.tan(a),h=c*n;return this.ortho({left:-h,right:h,bottom:-c,top:c,near:s,far:o})}perspective(e){let{fovy:t=45*Math.PI/180,aspect:n=1,near:r=.1,far:s=500}=e;return Wn(t),Vn(this,t,n,r,s),this.check()}determinant(){return Nn(this)}getScale(e=[-0,-0,-0]){return e[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),e[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),e[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),e}getTranslation(e=[-0,-0,-0]){return e[0]=this[12],e[1]=this[13],e[2]=this[14],e}getRotation(e,t){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],t=t||[-0,-0,-0];let n=this.getScale(t),r=1/n[0],s=1/n[1],o=1/n[2];return e[0]=this[0]*r,e[1]=this[1]*s,e[2]=this[2]*o,e[3]=0,e[4]=this[4]*r,e[5]=this[5]*s,e[6]=this[6]*o,e[7]=0,e[8]=this[8]*r,e[9]=this[9]*s,e[10]=this[10]*o,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}getRotationMatrix3(e,t){e=e||[-0,-0,-0,-0,-0,-0,-0,-0,-0],t=t||[-0,-0,-0];let n=this.getScale(t),r=1/n[0],s=1/n[1],o=1/n[2];return e[0]=this[0]*r,e[1]=this[1]*s,e[2]=this[2]*o,e[3]=this[4]*r,e[4]=this[5]*s,e[5]=this[6]*o,e[6]=this[8]*r,e[7]=this[9]*s,e[8]=this[10]*o,e}transpose(){return Rn(this,this),this.check()}invert(){return kn(this,this),this.check()}multiplyLeft(e){return _i(this,e,this),this.check()}multiplyRight(e){return _i(this,this,e),this.check()}rotateX(e){return zn(this,this,e),this.check()}rotateY(e){return jn(this,this,e),this.check()}rotateZ(e){return Gn(this,this,e),this.check()}rotateXYZ(e){return this.rotateX(e[0]).rotateY(e[1]).rotateZ(e[2])}rotateAxis(e,t){return Fn(this,this,e,t),this.check()}scale(e){return Bn(this,this,Array.isArray(e)?e:[e,e,e]),this.check()}translate(e){return Dn(this,this,e),this.check()}transform(e,t){return e.length===4?(t=Yn(t||[-0,-0,-0,-0],e,this),Tt(t,4),t):this.transformAsPoint(e,t)}transformAsPoint(e,t){let{length:n}=e,r;switch(n){case 2:r=Mn(t||[-0,-0],e,this);break;case 3:r=Et(t||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Tt(r,e.length),r}transformAsVector(e,t){let n;switch(e.length){case 2:n=Tn(t||[-0,-0],e,this);break;case 3:n=At(t||[-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Tt(n,e.length),n}transformPoint(e,t){return this.transformAsPoint(e,t)}transformVector(e,t){return this.transformAsPoint(e,t)}transformDirection(e,t){return this.transformAsVector(e,t)}makeRotationX(e){return this.identity().rotateX(e)}makeTranslation(e,t,n){return this.identity().translate([e,t,n])}},Pt,Lt;function io(){return Pt||(Pt=new X([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Pt)),Pt}function no(){return Lt||(Lt=new X,Object.freeze(Lt)),Lt}function Wn(i){if(i>Math.PI*2)throw Error("expected radians")}function ro(i,e,t,n,r,s){let o=2*s/(t-e),a=2*s/(r-n),c=(t+e)/(t-e),h=(r+n)/(r-n),u=-1,d=-1,l=-2*s;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]=u,i[11]=d,i[12]=0,i[13]=0,i[14]=l,i[15]=0,i}var so=.02,oo=.12,ao=.15,co=.2,Ai=[0,1,0],ho=[255,255,255],uo=1,Ti=.35,wi=255,lo=1,fo=.01,mo={depthCompare:"less-equal",depthWriteEnabled:!1,cullMode:"none"},po=[{name:"instancePosition",format:"float32x3",stepMode:"instance"},{name:"instanceDirection",format:"float32x3",stepMode:"instance"},{name:"instanceScale",format:"float32x3",stepMode:"instance"},{name:"instanceColor",format:"float32x4",stepMode:"instance"}],go={name:"lightMarker",props:{},uniforms:{},uniformTypes:{viewProjectionMatrix:"mat4x4<f32>"}},xo="inputs.positions * inputs.instanceScale",bo="vec3<f32>(inputs.positions.x * inputs.instanceScale.x, (inputs.positions.y - 0.5) * inputs.instanceScale.y, inputs.positions.z * inputs.instanceScale.z)",yo="positions * instanceScale",_o="vec3(positions.x * instanceScale.x, (positions.y - 0.5) * instanceScale.y, positions.z * instanceScale.z)",ue=class extends Y{lightModelProps;_instanceData;_managedBuffers;buildInstanceData;sizePropNames;constructor(e,t,n){let r=n.buildInstanceData(t),s=qn(e,t.id||n.idPrefix,r),o=new U({lightMarker:go});o.setProps({lightMarker:{viewProjectionMatrix:Zn(t)}});let{source:a,vs:c,fs:h}=wo(n.anchorMode),u=t;super(e,{...u,id:t.id||n.idPrefix,source:a,vs:c,fs:h,geometry:n.geometry,shaderInputs:o,bufferLayout:[...po],attributes:s,instanceCount:r.instanceCount,parameters:Jn(t.parameters)}),this.lightModelProps=t,this._instanceData=r,this._managedBuffers=s,this.buildInstanceData=n.buildInstanceData,this.sizePropNames=n.sizePropNames}destroy(){super.destroy(),Kn(this._managedBuffers),this._managedBuffers={}}draw(e){return this.instanceCount===0?!0:super.draw(e)}setProps(e){this.lightModelProps={...this.lightModelProps,...e},e.parameters&&this.setParameters(Jn(this.lightModelProps.parameters)),("viewMatrix"in e||"projectionMatrix"in e)&&(this.shaderInputs.setProps({lightMarker:{viewProjectionMatrix:Zn(this.lightModelProps)}}),this.setNeedsRedraw("lightMarker camera")),To(e,this.sizePropNames)&&this.rebuildInstanceData()}rebuildInstanceData(){let e=this.buildInstanceData(this.lightModelProps),t=qn(this.device,this.id,e);this.setAttributes(t),this.setInstanceCount(e.instanceCount),Kn(this._managedBuffers),this._managedBuffers=t,this._instanceData=e}};function Qn(i){let e=ir(i.lights),t=Ei(i),n=i.pointLightRadius??so*t.sceneScale*t.markerScale;return Ci(e.length,(r,s)=>({color:Si(r),direction:Ai,position:r.position,scale:[n,n,n]}),e)}function er(i){let e=nr(i.lights),t=Ei(i),n=i.spotLightLength??oo*t.sceneScale*t.markerScale;return Ci(e.length,(r,s)=>{let o=qe(r.outerConeAngle??Math.PI/4,0,Math.PI/2-fo),a=Math.tan(o)*n;return{color:Si(r),direction:rr(r.direction),position:r.position,scale:[a,n,a]}},e)}function tr(i){let e=Io(i.lights),t=Ei(i),n=i.directionalLightLength??ao*t.sceneScale*t.markerScale,r=n*co;return Ci(e.length,(s,o)=>{let a=rr(s.direction),c=[t.sceneCenter[0]-a[0]*t.sceneScale*Ti,t.sceneCenter[1]-a[1]*t.sceneScale*Ti,t.sceneCenter[2]-a[2]*t.sceneScale*Ti];return{color:Si(s),direction:a,position:c,scale:[r,n,r]}},e)}function ir(i){return i.filter(e=>e.type==="point")}function nr(i){return i.filter(e=>e.type==="spot")}function Io(i){return i.filter(e=>e.type==="directional")}function Ei(i){let e=vo(i.lights,i.bounds),t=[(e[0][0]+e[1][0])/2,(e[0][1]+e[1][1])/2,(e[0][2]+e[1][2])/2],n=Math.max(Math.hypot(e[1][0]-e[0][0],e[1][1]-e[0][1],e[1][2]-e[0][2]),lo);return{bounds:e,markerScale:Math.max(i.markerScale??uo,0),sceneCenter:t,sceneScale:n}}function Si(i){let e=i.color||ho,t=Math.max(i.intensity??1,0),n=qe(.35+.3*Math.log10(t+1),.35,1);return[qe(e[0]/wi,0,1)*n,qe(e[1]/wi,0,1)*n,qe(e[2]/wi,0,1)*n,1]}function rr(i){let[e,t,n]=i||Ai,r=Math.hypot(e,t,n);return r===0?[...Ai]:[e/r,t/r,n/r]}function Ci(i,e,t=[]){let n=new Float32Array(i*3),r=new Float32Array(i*3),s=new Float32Array(i*3),o=new Float32Array(i*4);for(let[a,c]of t.entries()){let h=e(c,a);n.set(h.position,a*3),r.set(h.direction,a*3),s.set(h.scale,a*3),o.set(h.color,a*4)}return{instanceCount:i,instancePositions:n,instanceDirections:r,instanceScales:s,instanceColors:o}}function vo(i,e){if(e)return Mo(e);let t=[...ir(i).map(s=>s.position),...nr(i).map(s=>s.position)];if(t.length===0)return[[-.5,-.5,-.5],[.5,.5,.5]];let n=[...t[0]],r=[...t[0]];for(let s of t.slice(1))n[0]=Math.min(n[0],s[0]),n[1]=Math.min(n[1],s[1]),n[2]=Math.min(n[2],s[2]),r[0]=Math.max(r[0],s[0]),r[1]=Math.max(r[1],s[1]),r[2]=Math.max(r[2],s[2]);return[n,r]}function Mo(i){return[[...i[0]],[...i[1]]]}function qn(i,e,t){return{instancePosition:i.createBuffer({id:`${e}-instance-position`,data:Ot(t.instancePositions,3)}),instanceDirection:i.createBuffer({id:`${e}-instance-direction`,data:Ot(t.instanceDirections,3)}),instanceScale:i.createBuffer({id:`${e}-instance-scale`,data:Ot(t.instanceScales,3)}),instanceColor:i.createBuffer({id:`${e}-instance-color`,data:Ot(t.instanceColors,4)})}}function Ot(i,e){return i.length>0?i:new Float32Array(e)}function Kn(i){for(let e of Object.values(i))e?.destroy()}function Zn(i){return new X(i.projectionMatrix).multiplyRight(i.viewMatrix)}function To(i,e){return"lights"in i||"bounds"in i||"markerScale"in i?!0:e.some(t=>t in i)}function Jn(i){return{...mo,...i||{}}}function wo(i){let e=i==="apex"?bo:xo,t=i==="apex"?_o:yo;return{source:`struct lightMarkerUniforms {
|
|
85
93
|
viewProjectionMatrix: mat4x4<f32>,
|
|
86
94
|
};
|
|
87
95
|
|
|
@@ -115,7 +123,7 @@ fn lightMarker_rotate(localPosition: vec3<f32>, direction: vec3<f32>) -> vec3<f3
|
|
|
115
123
|
@vertex
|
|
116
124
|
fn vertexMain(inputs: VertexInputs) -> FragmentInputs {
|
|
117
125
|
var outputs : FragmentInputs;
|
|
118
|
-
let localPosition = ${
|
|
126
|
+
let localPosition = ${e};
|
|
119
127
|
let worldPosition = inputs.instancePosition + lightMarker_rotate(localPosition, inputs.instanceDirection);
|
|
120
128
|
outputs.Position = lightMarker.viewProjectionMatrix * vec4<f32>(worldPosition, 1.0);
|
|
121
129
|
outputs.color = inputs.instanceColor;
|
|
@@ -149,7 +157,7 @@ vec3 lightMarker_rotate(vec3 localPosition, vec3 direction) {
|
|
|
149
157
|
}
|
|
150
158
|
|
|
151
159
|
void main(void) {
|
|
152
|
-
vec3 localPosition = ${
|
|
160
|
+
vec3 localPosition = ${t};
|
|
153
161
|
vec3 worldPosition = instancePosition + lightMarker_rotate(localPosition, instanceDirection);
|
|
154
162
|
gl_Position = lightMarker.viewProjectionMatrix * vec4(worldPosition, 1.0);
|
|
155
163
|
vColor = instanceColor;
|
|
@@ -163,28 +171,28 @@ out vec4 fragColor;
|
|
|
163
171
|
void main(void) {
|
|
164
172
|
fragColor = vColor;
|
|
165
173
|
}
|
|
166
|
-
`}}function zt(i,t,e){return Math.min(e,Math.max(t,i))}var ys=new _t({nlat:8,nlong:12,radius:1}),me=class extends ot{constructor(t,e){super(t,e,{anchorMode:"centered",buildInstanceData:In,geometry:ys,idPrefix:"point-light-model",sizePropNames:["pointLightRadius"]})}};var Ms={x:[2,0,1],y:[0,1,2],z:[1,2,0]},at=class extends ${constructor(t={}){let{id:e=S("truncated-code-geometry")}=t,{indices:n,attributes:r}=_s(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{POSITION:{size:3,value:r.POSITION},NORMAL:{size:3,value:r.NORMAL},TEXCOORD_0:{size:2,value:r.TEXCOORD_0},...t.attributes}})}};function _s(i={}){let{bottomRadius:t=0,topRadius:e=0,height:n=1,nradial:r=10,nvertical:s=10,verticalAxis:o="y",topCap:a=!1,bottomCap:c=!1}=i,h=(a?2:0)+(c?2:0),l=(r+1)*(s+1+h),d=Math.atan2(t-e,n),f=Math.sin,p=Math.cos,g=Math.PI,u=p(d),b=f(d),M=a?-2:0,I=s+(c?2:0),m=r+1,x=new Uint16Array(r*(s+h)*6),y=Ms[o],_=new Float32Array(l*3),T=new Float32Array(l*3),C=new Float32Array(l*2),E=0,O=0;for(let v=M;v<=I;v++){let P=v/s,L=n*P,A;v<0?(L=0,P=1,A=t):v>s?(L=n,P=1,A=e):A=t+(e-t)*(v/s),(v===-2||v===s+2)&&(A=0,P=0),L-=n/2;for(let F=0;F<m;F++){let J=f(F*g*2/r),K=p(F*g*2/r);_[E+y[0]]=J*A,_[E+y[1]]=L,_[E+y[2]]=K*A,T[E+y[0]]=v<0||v>s?0:J*u,T[E+y[1]]=v<0?-1:v>s?1:b,T[E+y[2]]=v<0||v>s?0:K*u,C[O+0]=F/r,C[O+1]=P,O+=2,E+=3}}for(let v=0;v<s+h;v++)for(let P=0;P<r;P++){let L=(v*r+P)*6;x[L+0]=m*(v+0)+0+P,x[L+1]=m*(v+0)+1+P,x[L+2]=m*(v+1)+1+P,x[L+3]=m*(v+0)+0+P,x[L+4]=m*(v+1)+1+P,x[L+5]=m*(v+1)+0+P}return{indices:x,attributes:{POSITION:_,NORMAL:T,TEXCOORD_0:C}}}var ct=class extends at{constructor(t={}){let{id:e=S("cone-geometry"),radius:n=1,cap:r=!0}=t;super({...t,id:e,topRadius:0,topCap:Boolean(r),bottomCap:Boolean(r),bottomRadius:n})}};var Is=new ct({cap:!0,nradial:16,nvertical:1,radius:1}),pe=class extends ot{constructor(t,e){super(t,e,{anchorMode:"apex",buildInstanceData:vn,geometry:Is,idPrefix:"spot-light-model",sizePropNames:["spotLightLength"]})}};var vs=new ct({cap:!0,nradial:12,nvertical:1,radius:1}),ge=class extends ot{constructor(t,e){super(t,e,{anchorMode:"apex",buildInstanceData:wn,geometry:vs,idPrefix:"directional-light-model",sizePropNames:["directionalLightLength"]})}};function si(i,t){if(!i)throw new Error(t)}var et=class{id;matrix=new X;display=!0;position=new q;rotation=new q;scale=new q(1,1,1);userData={};props={};constructor(t={}){let{id:e}=t;this.id=e||S(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 si(t.length===3,"setPosition requires vector argument"),this.position=t,this}setRotation(t){return si(t.length===3||t.length===4,"setRotation requires vector argument"),this.rotation=t,this}setScale(t){return si(t.length===3,"setScale requires vector argument"),this.scale=t,this}setMatrix(t,e=!0){e?this.matrix.copy(t):this.matrix=t}setMatrixComponents(t){let{position:e,rotation:n,scale:r,update:s=!0}=t;return e&&this.setPosition(e),n&&this.setRotation(n),r&&this.setScale(r),s&&this.updateMatrix(),this}updateMatrix(){if(this.matrix.identity(),this.matrix.translate(this.position),this.rotation.length===4){let t=new X().fromQuaternion(this.rotation);this.matrix.multiplyRight(t)}else this.matrix.rotateXYZ(this.rotation);return this.matrix.scale(this.scale),this}update({position:t,rotation:e,scale:n}={}){return t&&this.setPosition(t),e&&this.setRotation(e),n&&this.setScale(n),this.updateMatrix(),this}getCoordinateUniforms(t,e){e=e||this.matrix;let n=new X(t).multiplyRight(e),r=n.invert(),s=r.transpose();return{viewMatrix:t,modelMatrix:e,objectMatrix:e,worldMatrix:n,worldInverseMatrix:r,worldInverseTransposeMatrix:s}}_setScenegraphNodeProps(t){t?.position&&this.setPosition(t.position),t?.rotation&&this.setRotation(t.rotation),t?.scale&&this.setScale(t.scale),this.updateMatrix(),t?.matrix&&this.setMatrix(t.matrix),Object.assign(this.props,t)}};var Sn=k(U(),1);var ft=class extends et{children;constructor(t={}){t=Array.isArray(t)?{children:t}:t;let{children:e=[]}=t;Sn.log.assert(e.every(n=>n 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:n})=>{let r=e.getBounds();if(!r)return;let[s,o]=r,a=new q(s).add(o).divide([2,2,2]);n.transformAsPoint(a,a);let c=new q(o).subtract(s).divide([2,2,2]);n.transformAsVector(c,c);for(let h=0;h<8;h++){let l=new q(h&1?-1:1,h&2?-1:1,h&4?-1:1).multiply(c).add(a);for(let d=0;d<3;d++)t[0][d]=Math.min(t[0][d],l[d]),t[1][d]=Math.max(t[1][d],l[d])}}),Number.isFinite(t[0][0])?t:null}destroy(){this.children.forEach(t=>t.destroy()),this.removeAll(),super.destroy()}add(...t){for(let e of t)Array.isArray(e)?this.add(...e):this.children.push(e);return this}remove(t){let e=this.children,n=e.indexOf(t);return n>-1&&e.splice(n,1),this}removeAll(){return this.children=[],this}traverse(t,{worldMatrix:e=new X}={}){let n=new X(e).multiplyRight(this.matrix);for(let r of this.children)r instanceof ft?r.traverse(t,{worldMatrix:n}):t(r,{worldMatrix:n})}preorderTraversal(t,{worldMatrix:e=new X}={}){let n=new X(e).multiplyRight(this.matrix);t(this,{worldMatrix:n});for(let r of this.children)r instanceof ft?r.preorderTraversal(t,{worldMatrix:n}):t(r,{worldMatrix:n})}};var xe=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 be=class extends ${constructor(t={}){let{id:e=S("cube-geometry"),indices:n=!0}=t;super(n?{...t,id:e,topology:"triangle-list",indices:{size:1,value:ws},attributes:{...Cs,...t.attributes}}:{...t,id:e,topology:"triangle-list",indices:void 0,attributes:{...Os,...t.attributes}})}},ws=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]),As=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]),Ts=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0]),Ps=new Float32Array([0,0,1,0,1,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,0,1,1,0,1,0,0,0,0,1,0,1,1,0,1]),Ss=new Float32Array([1,-1,1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,1,1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,1,-1,1,1,1,-1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1]),Es=new Float32Array([1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,1,0,0]),Ls=new Float32Array([1,0,1,1,0,0,1,1,0,0,0,1,1,0,0,1,1,0,1,1,0,0,0,1,1,1,1,1,1,0,1,1,1,0,0,1,1,1,0,1,1,1,1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,0,1,1,0,1,1,1,0,1,0,1,0,0,0,1,0,0,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0,0,1,1,0,0,1,1,1,0,1,1,1,1,1,1,1,0,0,1,0,0,0,1,0,1,0,1,1,1,0,1,1,0,0,1,0,1,0,1]),Cs={POSITION:{size:3,value:As},NORMAL:{size:3,value:Ts},TEXCOORD_0:{size:2,value:Ps}},Os={POSITION:{size:3,value:Ss},TEXCOORD_0:{size:2,value:Es},COLOR_0:{size:3,value:Ls}};var ye=class extends at{constructor(t={}){let{id:e=S("cylinder-geometry"),radius:n=1}=t;super({...t,id:e,bottomRadius:n,topRadius:n})}};var Rs=[-1,0,0,0,1,0,0,0,-1,0,0,1,0,-1,0,1,0,0],ks=[3,4,5,3,5,1,3,1,0,3,0,4,4,0,2,4,2,5,2,0,1,5,2,1],Me=class extends ${constructor(t={}){let{id:e=S("ico-sphere-geometry")}=t,{indices:n,attributes:r}=Ns(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{...r,...t.attributes}})}};function Ns(i){let{iterations:t=0}=i,e=Math.PI,n=e*2,r=[...Rs],s=[...ks];r.push(),s.push();let o=(()=>{let l={};return(d,f)=>{d*=3,f*=3;let p=d<f?d:f,g=d>f?d:f,u=`${p}|${g}`;if(u in l)return l[u];let b=r[d],M=r[d+1],I=r[d+2],m=r[f],x=r[f+1],y=r[f+2],_=(b+m)/2,T=(M+x)/2,C=(I+y)/2,E=Math.sqrt(_*_+T*T+C*C);_/=E,T/=E,C/=E,r.push(_,T,C);let O=r.length/3-1;return l[u]=O,O}})();for(let l=0;l<t;l++){let d=[];for(let f=0;f<s.length;f+=3){let p=o(s[f+0],s[f+1]),g=o(s[f+1],s[f+2]),u=o(s[f+2],s[f+0]);d.push(u,s[f+0],p,p,s[f+1],g,g,s[f+2],u,p,g,u)}s=d}let a=new Array(r.length),c=new Array(r.length/3*2),h=s.length;for(let l=h-3;l>=0;l-=3){let d=s[l+0],f=s[l+1],p=s[l+2],g=d*3,u=f*3,b=p*3,M=d*2,I=f*2,m=p*2,x=r[g+0],y=r[g+1],_=r[g+2],T=Math.acos(_/Math.sqrt(x*x+y*y+_*_)),C=Math.atan2(y,x)+e,E=T/e,O=1-C/n,v=r[u+0],P=r[u+1],L=r[u+2],A=Math.acos(L/Math.sqrt(v*v+P*P+L*L)),F=Math.atan2(P,v)+e,J=A/e,K=1-F/n,Vt=r[b+0],Xt=r[b+1],qt=r[b+2],Vn=Math.acos(qt/Math.sqrt(Vt*Vt+Xt*Xt+qt*qt)),Xn=Math.atan2(Xt,Vt)+e,fi=Vn/e,Ht=1-Xn/n,qn=[Vt-v,Xt-P,qt-L],Hn=[x-v,y-P,_-L],W=new q(qn).cross(Hn).normalize(),N;(O===0||K===0||Ht===0)&&(O===0||O>.5)&&(K===0||K>.5)&&(Ht===0||Ht>.5)&&(r.push(r[g+0],r[g+1],r[g+2]),N=r.length/3-1,s.push(N),c[N*2+0]=1,c[N*2+1]=E,a[N*3+0]=W.x,a[N*3+1]=W.y,a[N*3+2]=W.z,r.push(r[u+0],r[u+1],r[u+2]),N=r.length/3-1,s.push(N),c[N*2+0]=1,c[N*2+1]=J,a[N*3+0]=W.x,a[N*3+1]=W.y,a[N*3+2]=W.z,r.push(r[b+0],r[b+1],r[b+2]),N=r.length/3-1,s.push(N),c[N*2+0]=1,c[N*2+1]=fi,a[N*3+0]=W.x,a[N*3+1]=W.y,a[N*3+2]=W.z),a[g+0]=a[u+0]=a[b+0]=W.x,a[g+1]=a[u+1]=a[b+1]=W.y,a[g+2]=a[u+2]=a[b+2]=W.z,c[M+0]=O,c[M+1]=E,c[I+0]=K,c[I+1]=J,c[m+0]=Ht,c[m+1]=fi}return{indices:{size:1,value:new Uint16Array(s)},attributes:{POSITION:{size:3,value:new Float32Array(r)},NORMAL:{size:3,value:new Float32Array(a)},TEXCOORD_0:{size:2,value:new Float32Array(c)}}}}function En(i){let{indices:t,attributes:e}=i;if(!t)return i;let n=t.value.length,r={};for(let s in e){let o=e[s],{constant:a,value:c,size:h}=o;if(a||!h)continue;let l=new c.constructor(n*h);for(let d=0;d<n;++d){let f=t.value[d];for(let p=0;p<h;p++)l[d*h+p]=c[f*h+p]}r[s]={size:h,value:l}}return{attributes:Object.assign({},e,r)}}var _e=class extends ${constructor(t={}){let{id:e=S("plane-geometry")}=t,{indices:n,attributes:r}=Ds(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{...r,...t.attributes}})}};function Ds(i){let{type:t="x,y",offset:e=0,flipCull:n=!1,unpack:r=!1}=i,s=t.split(","),o=i[`${s[0]}len`]||1,a=i[`${s[1]}len`]||1,c=i[`n${s[0]}`]||1,h=i[`n${s[1]}`]||1,l=(c+1)*(h+1),d=new Float32Array(l*3),f=new Float32Array(l*3),p=new Float32Array(l*2);n&&(o=-o);let g=0,u=0;for(let m=0;m<=h;m++)for(let x=0;x<=c;x++){let y=x/c,_=m/h;switch(p[g+0]=n?1-y:y,p[g+1]=_,t){case"x,y":d[u+0]=o*y-o*.5,d[u+1]=a*_-a*.5,d[u+2]=e,f[u+0]=0,f[u+1]=0,f[u+2]=n?1:-1;break;case"x,z":d[u+0]=o*y-o*.5,d[u+1]=e,d[u+2]=a*_-a*.5,f[u+0]=0,f[u+1]=n?1:-1,f[u+2]=0;break;case"y,z":d[u+0]=e,d[u+1]=o*y-o*.5,d[u+2]=a*_-a*.5,f[u+0]=n?1:-1,f[u+1]=0,f[u+2]=0;break;default:throw new Error("PlaneGeometry: unknown type")}g+=2,u+=3}let b=c+1,M=new Uint16Array(c*h*6);for(let m=0;m<h;m++)for(let x=0;x<c;x++){let y=(m*c+x)*6;M[y+0]=(m+0)*b+x,M[y+1]=(m+1)*b+x,M[y+2]=(m+0)*b+x+1,M[y+3]=(m+1)*b+x,M[y+4]=(m+1)*b+x+1,M[y+5]=(m+0)*b+x+1}let I={indices:{size:1,value:M},attributes:{POSITION:{size:3,value:d},NORMAL:{size:3,value:f},TEXCOORD_0:{size:2,value:p}}};return r?En(I):I}function Ln(){let i=1,t=1;return()=>(i=Math.sin(t*17.23),t=Math.cos(i*27.92),Fs(Math.abs(i*t)*1432.71))}function Fs(i){return i-Math.floor(i)}var oi="";function Cn(i){oi=i}async function On(i,t){let e=new Image;return e.crossOrigin=t?.crossOrigin||"anonymous",e.src=i.startsWith("http")?i:oi+i,await e.decode(),t?await createImageBitmap(e,t):await createImageBitmap(e)}async function Rn(i,t){return await new Promise((e,n)=>{try{let r=new Image;r.onload=()=>e(r),r.onerror=()=>n(new Error(`Could not load image ${i}.`)),r.crossOrigin=t?.crossOrigin||"anonymous",r.src=i.startsWith("http")?i:oi+i}catch(r){n(r)}})}var Nn=k(nt(),1);var it=k(U(),1),At=class{id;current;next;constructor(t){this.id=t.id||"swap",this.current=t.current,this.next=t.next}destroy(){this.current?.destroy(),this.next?.destroy()}swap(){let t=this.current;this.current=this.next,this.next=t}},Tt=class extends At{constructor(t,e){e={...e};let{width:n=1,height:r=1}=e,s=e.colorAttachments?.map(c=>typeof c!="string"?c:t.createTexture({id:`${e.id}-texture-0`,format:c,usage:it.Texture.SAMPLE|it.Texture.RENDER|it.Texture.COPY_SRC|it.Texture.COPY_DST,width:n,height:r})),o=t.createFramebuffer({...e,colorAttachments:s});s=e.colorAttachments?.map(c=>typeof c!="string"?c:t.createTexture({id:`${e.id}-texture-1`,format:c,usage:it.Texture.SAMPLE|it.Texture.RENDER|it.Texture.COPY_SRC|it.Texture.COPY_DST,width:n,height:r}));let a=t.createFramebuffer({...e,colorAttachments:s});super({current:o,next:a})}resize(t){if(t.width===this.current.width&&t.height===this.current.height)return!1;let{current:e,next:n}=this;return this.current=e.clone(t),e.destroy(),this.next=n.clone(t),n.destroy(),!0}},Ie=class extends At{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:n}=this;return this.current=e.clone(t),e.destroy(),this.next=n.clone(t),n.destroy(),!0}};function kn(i){let{shaderPass:t,action:e,shadingLanguage:n}=i;switch(e){case"filter":let r=`${t.name}_filterColor_ext`;return n==="wgsl"?Bs(r):js(r);case"sample":let s=`${t.name}_sampleColor`;return n==="wgsl"?zs(s):Us(s);default:throw new Error(`${t.name} no fragment shader generated for shader pass`)}}function Bs(i){return`@group(0) @binding(auto) var sourceTexture: texture_2d<f32>;
|
|
174
|
+
`}}function qe(i,e,t){return Math.min(t,Math.max(e,i))}var Ao=new Oe({nlat:8,nlong:12,radius:1}),Rt=class extends ue{constructor(e,t){super(e,t,{anchorMode:"centered",buildInstanceData:Qn,geometry:Ao,idPrefix:"point-light-model",sizePropNames:["pointLightRadius"]})}};var Eo={x:[2,0,1],y:[0,1,2],z:[1,2,0]},de=class extends j{constructor(e={}){let{id:t=S("truncated-code-geometry")}=e,{indices:n,attributes:r}=So(e);super({...e,id:t,topology:"triangle-list",indices:n,attributes:{POSITION:{size:3,value:r.POSITION},NORMAL:{size:3,value:r.NORMAL},TEXCOORD_0:{size:2,value:r.TEXCOORD_0},...e.attributes}})}};function So(i={}){let{bottomRadius:e=0,topRadius:t=0,height:n=1,nradial:r=10,nvertical:s=10,verticalAxis:o="y",topCap:a=!1,bottomCap:c=!1}=i,h=(a?2:0)+(c?2:0),u=(r+1)*(s+1+h),d=Math.atan2(e-t,n),l=Math.sin,m=Math.cos,p=Math.PI,f=m(d),x=l(d),_=a?-2:0,v=s+(c?2:0),g=r+1,b=new Uint16Array(r*(s+h)*6),y=Eo[o],I=new Float32Array(u*3),A=new Float32Array(u*3),O=new Float32Array(u*2),C=0,R=0;for(let M=_;M<=v;M++){let E=M/s,P=n*E,w;M<0?(P=0,E=1,w=e):M>s?(P=n,E=1,w=t):w=e+(t-e)*(M/s),(M===-2||M===s+2)&&(w=0,E=0),P-=n/2;for(let G=0;G<g;G++){let te=l(G*p*2/r),Z=m(G*p*2/r);I[C+y[0]]=te*w,I[C+y[1]]=P,I[C+y[2]]=Z*w,A[C+y[0]]=M<0||M>s?0:te*f,A[C+y[1]]=M<0?-1:M>s?1:x,A[C+y[2]]=M<0||M>s?0:Z*f,O[R+0]=G/r,O[R+1]=E,R+=2,C+=3}}for(let M=0;M<s+h;M++)for(let E=0;E<r;E++){let P=(M*r+E)*6;b[P+0]=g*(M+0)+0+E,b[P+1]=g*(M+0)+1+E,b[P+2]=g*(M+1)+1+E,b[P+3]=g*(M+0)+0+E,b[P+4]=g*(M+1)+1+E,b[P+5]=g*(M+1)+0+E}return{indices:b,attributes:{POSITION:I,NORMAL:A,TEXCOORD_0:O}}}var le=class extends de{constructor(e={}){let{id:t=S("cone-geometry"),radius:n=1,cap:r=!0}=e;super({...e,id:t,topRadius:0,topCap:Boolean(r),bottomCap:Boolean(r),bottomRadius:n})}};var Co=new le({cap:!0,nradial:16,nvertical:1,radius:1}),kt=class extends ue{constructor(e,t){super(e,t,{anchorMode:"apex",buildInstanceData:er,geometry:Co,idPrefix:"spot-light-model",sizePropNames:["spotLightLength"]})}};var Po=new le({cap:!0,nradial:12,nvertical:1,radius:1}),Nt=class extends ue{constructor(e,t){super(e,t,{anchorMode:"apex",buildInstanceData:tr,geometry:Po,idPrefix:"directional-light-model",sizePropNames:["directionalLightLength"]})}};function Pi(i,e){if(!i)throw new Error(e)}var re=class{id;matrix=new X;display=!0;position=new H;rotation=new H;scale=new H(1,1,1);userData={};props={};constructor(e={}){let{id:t}=e;this.id=t||S(this.constructor.name),this._setScenegraphNodeProps(e)}getBounds(){return null}destroy(){}delete(){this.destroy()}setProps(e){return this._setScenegraphNodeProps(e),this}toString(){return`{type: ScenegraphNode, id: ${this.id})}`}setPosition(e){return Pi(e.length===3,"setPosition requires vector argument"),this.position=e,this}setRotation(e){return Pi(e.length===3||e.length===4,"setRotation requires vector argument"),this.rotation=e,this}setScale(e){return Pi(e.length===3,"setScale requires vector argument"),this.scale=e,this}setMatrix(e,t=!0){t?this.matrix.copy(e):this.matrix=e}setMatrixComponents(e){let{position:t,rotation:n,scale:r,update:s=!0}=e;return t&&this.setPosition(t),n&&this.setRotation(n),r&&this.setScale(r),s&&this.updateMatrix(),this}updateMatrix(){if(this.matrix.identity(),this.matrix.translate(this.position),this.rotation.length===4){let e=new X().fromQuaternion(this.rotation);this.matrix.multiplyRight(e)}else this.matrix.rotateXYZ(this.rotation);return this.matrix.scale(this.scale),this}update({position:e,rotation:t,scale:n}={}){return e&&this.setPosition(e),t&&this.setRotation(t),n&&this.setScale(n),this.updateMatrix(),this}getCoordinateUniforms(e,t){t=t||this.matrix;let n=new X(e).multiplyRight(t),r=n.invert(),s=r.transpose();return{viewMatrix:e,modelMatrix:t,objectMatrix:t,worldMatrix:n,worldInverseMatrix:r,worldInverseTransposeMatrix:s}}_setScenegraphNodeProps(e){e?.position&&this.setPosition(e.position),e?.rotation&&this.setRotation(e.rotation),e?.scale&&this.setScale(e.scale),this.updateMatrix(),e?.matrix&&this.setMatrix(e.matrix),Object.assign(this.props,e)}};var sr=L(k(),1);var ye=class extends re{children;constructor(e={}){e=Array.isArray(e)?{children:e}:e;let{children:t=[]}=e;sr.log.assert(t.every(n=>n instanceof re),"every child must an instance of ScenegraphNode"),super(e),this.children=t}getBounds(){let e=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]];return this.traverse((t,{worldMatrix:n})=>{let r=t.getBounds();if(!r)return;let[s,o]=r,a=new H(s).add(o).divide([2,2,2]);n.transformAsPoint(a,a);let c=new H(o).subtract(s).divide([2,2,2]);n.transformAsVector(c,c);for(let h=0;h<8;h++){let u=new H(h&1?-1:1,h&2?-1:1,h&4?-1:1).multiply(c).add(a);for(let d=0;d<3;d++)e[0][d]=Math.min(e[0][d],u[d]),e[1][d]=Math.max(e[1][d],u[d])}}),Number.isFinite(e[0][0])?e:null}destroy(){this.children.forEach(e=>e.destroy()),this.removeAll(),super.destroy()}add(...e){for(let t of e)Array.isArray(t)?this.add(...t):this.children.push(t);return this}remove(e){let t=this.children,n=t.indexOf(e);return n>-1&&t.splice(n,1),this}removeAll(){return this.children=[],this}traverse(e,{worldMatrix:t=new X}={}){let n=new X(t).multiplyRight(this.matrix);for(let r of this.children)r instanceof ye?r.traverse(e,{worldMatrix:n}):e(r,{worldMatrix:n})}preorderTraversal(e,{worldMatrix:t=new X}={}){let n=new X(t).multiplyRight(this.matrix);e(this,{worldMatrix:n});for(let r of this.children)r instanceof ye?r.preorderTraversal(e,{worldMatrix:n}):e(r,{worldMatrix:n})}};var Dt=class extends re{model;bounds=null;managedResources;constructor(e){super(e),this.model=e.model,this.managedResources=e.managedResources||[],this.bounds=e.bounds||null,this.setProps(e)}destroy(){this.model&&(this.model.destroy(),this.model=null),this.managedResources.forEach(e=>e.destroy()),this.managedResources=[]}getBounds(){return this.bounds}draw(e){return this.model.draw(e)}};var Bt=class extends j{constructor(e={}){let{id:t=S("cube-geometry"),indices:n=!0}=e;super(n?{...e,id:t,topology:"triangle-list",indices:{size:1,value:Lo},attributes:{...jo,...e.attributes}}:{...e,id:t,topology:"triangle-list",indices:void 0,attributes:{...Go,...e.attributes}})}},Lo=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]),Oo=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]),Ro=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0]),ko=new Float32Array([0,0,1,0,1,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,0,1,1,0,1,0,0,0,0,1,0,1,1,0,1]),No=new Uint32Array([0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5]),Do=new Float32Array([1,-1,1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,1,1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,1,-1,1,1,1,-1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1]),Bo=new Float32Array([1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,1,0,0]),Fo=new Float32Array([1,0,1,1,0,0,1,1,0,0,0,1,1,0,0,1,1,0,1,1,0,0,0,1,1,1,1,1,1,0,1,1,1,0,0,1,1,1,0,1,1,1,1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,0,1,1,0,1,1,1,0,1,0,1,0,0,0,1,0,0,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0,0,1,1,0,0,1,1,1,0,1,1,1,1,1,1,1,0,0,1,0,0,0,1,0,1,0,1,1,1,0,1,1,0,0,1,0,1,0,1]),zo=new Uint32Array([3,3,3,3,3,3,4,4,4,4,4,4,2,2,2,2,2,2,5,5,5,5,5,5,0,0,0,0,0,0,1,1,1,1,1,1]),jo={POSITION:{size:3,value:Oo},NORMAL:{size:3,value:Ro},TEXCOORD_0:{size:2,value:ko},faceIndex:{size:1,value:No}},Go={POSITION:{size:3,value:Do},TEXCOORD_0:{size:2,value:Bo},COLOR_0:{size:3,value:Fo},faceIndex:{size:1,value:zo}};var Ft=class extends de{constructor(e={}){let{id:t=S("cylinder-geometry"),radius:n=1}=e;super({...e,id:t,bottomRadius:n,topRadius:n})}};var $o=[-1,0,0,0,1,0,0,0,-1,0,0,1,0,-1,0,1,0,0],Uo=[3,4,5,3,5,1,3,1,0,3,0,4,4,0,2,4,2,5,2,0,1,5,2,1],zt=class extends j{constructor(e={}){let{id:t=S("ico-sphere-geometry")}=e,{indices:n,attributes:r}=Vo(e);super({...e,id:t,topology:"triangle-list",indices:n,attributes:{...r,...e.attributes}})}};function Vo(i){let{iterations:e=0}=i,t=Math.PI,n=t*2,r=[...$o],s=[...Uo];r.push(),s.push();let o=(()=>{let u={};return(d,l)=>{d*=3,l*=3;let m=d<l?d:l,p=d>l?d:l,f=`${m}|${p}`;if(f in u)return u[f];let x=r[d],_=r[d+1],v=r[d+2],g=r[l],b=r[l+1],y=r[l+2],I=(x+g)/2,A=(_+b)/2,O=(v+y)/2,C=Math.sqrt(I*I+A*A+O*O);I/=C,A/=C,O/=C,r.push(I,A,O);let R=r.length/3-1;return u[f]=R,R}})();for(let u=0;u<e;u++){let d=[];for(let l=0;l<s.length;l+=3){let m=o(s[l+0],s[l+1]),p=o(s[l+1],s[l+2]),f=o(s[l+2],s[l+0]);d.push(f,s[l+0],m,m,s[l+1],p,p,s[l+2],f,m,p,f)}s=d}let a=new Array(r.length),c=new Array(r.length/3*2),h=s.length;for(let u=h-3;u>=0;u-=3){let d=s[u+0],l=s[u+1],m=s[u+2],p=d*3,f=l*3,x=m*3,_=d*2,v=l*2,g=m*2,b=r[p+0],y=r[p+1],I=r[p+2],A=Math.acos(I/Math.sqrt(b*b+y*y+I*I)),O=Math.atan2(y,b)+t,C=A/t,R=1-O/n,M=r[f+0],E=r[f+1],P=r[f+2],w=Math.acos(P/Math.sqrt(M*M+E*E+P*P)),G=Math.atan2(E,M)+t,te=w/t,Z=1-G/n,rt=r[x+0],st=r[x+1],ot=r[x+2],Rr=Math.acos(ot/Math.sqrt(rt*rt+st*st+ot*ot)),kr=Math.atan2(st,rt)+t,Fi=Rr/t,at=1-kr/n,Nr=[rt-M,st-E,ot-P],Dr=[b-M,y-E,I-P],W=new H(Nr).cross(Dr).normalize(),D;(R===0||Z===0||at===0)&&(R===0||R>.5)&&(Z===0||Z>.5)&&(at===0||at>.5)&&(r.push(r[p+0],r[p+1],r[p+2]),D=r.length/3-1,s.push(D),c[D*2+0]=1,c[D*2+1]=C,a[D*3+0]=W.x,a[D*3+1]=W.y,a[D*3+2]=W.z,r.push(r[f+0],r[f+1],r[f+2]),D=r.length/3-1,s.push(D),c[D*2+0]=1,c[D*2+1]=te,a[D*3+0]=W.x,a[D*3+1]=W.y,a[D*3+2]=W.z,r.push(r[x+0],r[x+1],r[x+2]),D=r.length/3-1,s.push(D),c[D*2+0]=1,c[D*2+1]=Fi,a[D*3+0]=W.x,a[D*3+1]=W.y,a[D*3+2]=W.z),a[p+0]=a[f+0]=a[x+0]=W.x,a[p+1]=a[f+1]=a[x+1]=W.y,a[p+2]=a[f+2]=a[x+2]=W.z,c[_+0]=R,c[_+1]=C,c[v+0]=Z,c[v+1]=te,c[g+0]=at,c[g+1]=Fi}return{indices:{size:1,value:new Uint16Array(s)},attributes:{POSITION:{size:3,value:new Float32Array(r)},NORMAL:{size:3,value:new Float32Array(a)},TEXCOORD_0:{size:2,value:new Float32Array(c)}}}}var jt=class extends j{constructor(e={}){let{id:t=S("plane-geometry")}=e,{indices:n,attributes:r}=Xo(e);super({...e,id:t,topology:"triangle-list",indices:n,attributes:{...r,...e.attributes}})}};function Xo(i){let{type:e="x,y",offset:t=0,flipCull:n=!1,unpack:r=!1}=i,s=e.split(","),o=i[`${s[0]}len`]||1,a=i[`${s[1]}len`]||1,c=i[`n${s[0]}`]||1,h=i[`n${s[1]}`]||1,u=(c+1)*(h+1),d=new Float32Array(u*3),l=new Float32Array(u*3),m=new Float32Array(u*2);n&&(o=-o);let p=0,f=0;for(let g=0;g<=h;g++)for(let b=0;b<=c;b++){let y=b/c,I=g/h;switch(m[p+0]=n?1-y:y,m[p+1]=I,e){case"x,y":d[f+0]=o*y-o*.5,d[f+1]=a*I-a*.5,d[f+2]=t,l[f+0]=0,l[f+1]=0,l[f+2]=n?1:-1;break;case"x,z":d[f+0]=o*y-o*.5,d[f+1]=t,d[f+2]=a*I-a*.5,l[f+0]=0,l[f+1]=n?1:-1,l[f+2]=0;break;case"y,z":d[f+0]=t,d[f+1]=o*y-o*.5,d[f+2]=a*I-a*.5,l[f+0]=n?1:-1,l[f+1]=0,l[f+2]=0;break;default:throw new Error("PlaneGeometry: unknown type")}p+=2,f+=3}let x=c+1,_=new Uint16Array(c*h*6);for(let g=0;g<h;g++)for(let b=0;b<c;b++){let y=(g*c+b)*6;_[y+0]=(g+0)*x+b,_[y+1]=(g+1)*x+b,_[y+2]=(g+0)*x+b+1,_[y+3]=(g+1)*x+b,_[y+4]=(g+1)*x+b+1,_[y+5]=(g+0)*x+b+1}let v={indices:{size:1,value:_},attributes:{POSITION:{size:3,value:d},NORMAL:{size:3,value:l},TEXCOORD_0:{size:2,value:m}}};return r?qi(v):v}function or(){let i=1,e=1;return()=>(i=Math.sin(e*17.23),e=Math.cos(i*27.92),Ho(Math.abs(i*e)*1432.71))}function Ho(i){return i-Math.floor(i)}var cr="";function hr(i){cr=i}function Gt(i){return Yo(i)?i:cr+i}async function ur(i,e){let t=new Image,n=Gt(i);t.crossOrigin=e?.crossOrigin||"anonymous",t.src=n;try{await t.decode()}catch(r){throw ar("decode",n,r)}try{return e?await createImageBitmap(t,e):await createImageBitmap(t)}catch(r){throw ar("create",n,r)}}async function dr(i,e){return await new Promise((t,n)=>{try{let r=new Image,s=Gt(i);r.onload=()=>t(r),r.onerror=()=>n(new Error(`Could not load image ${s}.`)),r.crossOrigin=e?.crossOrigin||"anonymous",r.src=s}catch(r){n(r)}})}function ar(i,e,t){let n=t instanceof Error?t.message:String(t),r=i==="decode"?`Could not decode source image "${e}": ${n}`:`Could not create ImageBitmap from decoded image "${e}": ${n}`;return new Error(r,{cause:t})}function Yo(i){return i.startsWith("/")||/^[a-z][a-z\d+\-.]*:/i.test(i)}var _e=L(k(),1);var $t=class{device;id;destroyed=!1;generation=0;_source;_colorSpace;_sampler;_isReady=!1;_updateTimestamp;_sourceVersion=0;_sourceFrameToken=null;_texture=null;_textureFrameToken=void 0;_externalTexture=null;get source(){return this._source}get isReady(){return this._observeSource(),this._isReady}get updateTimestamp(){return this._observeSource(),this._updateTimestamp}get[Symbol.toStringTag](){return"VideoTexture"}toString(){let e=Li(this._source);return`VideoTexture:"${this.id}":${e.width}x${e.height}px:(${this._isReady?"ready":"loading..."})`}constructor(e,t){(0,_e.assert)(Ke(t?.source)||lr(t?.source)),this.device=e,this.id=t.id||S("video-texture"),this._source=t.source,this._colorSpace=t.colorSpace??"srgb",this._sampler=t.sampler??{},this._updateTimestamp=this.device.incrementTimestamp(),this.setSource(t.source)}setSource(e){(0,_e.assert)(Ke(e)||lr(e)),this._destroyExternalTexture(),this._source=e,this._sourceVersion++,this._sourceFrameToken=null,this._textureFrameToken=void 0,this._observeSource(),this._touchGeneration()}resolveTextureBinding(e){return this._observeSource(),!this._isReady||this.destroyed?null:e.type==="external-texture"&&this.device.type==="webgpu"?this._createNativeExternalTexture():this._resolveCopiedTexture()}setSampler(e){this._sampler=e,this._texture?.setSampler(e),this._externalTexture?.setSampler?.(e),this._touchGeneration()}destroy(){this.destroyed||(this._destroyExternalTexture(),this._texture?.destroy(),this._texture=null,this._textureFrameToken=void 0,this._isReady=!1,this.destroyed=!0,this._touchGeneration())}_resolveCopiedTexture(){let e=this._getOrCreateCopiedTexture();return Object.is(this._textureFrameToken,this._sourceFrameToken)||(e.copyExternalImage({image:this._source,colorSpace:this._colorSpace}),this._textureFrameToken=this._sourceFrameToken),e}_getOrCreateCopiedTexture(){let e=this._getResolvedSize(),t=this._texture;if(t&&t.width===e.width&&t.height===e.height)return t;t?.destroy();let n=this.device.createTexture({id:`${this.id}-texture`,width:e.width,height:e.height,format:"rgba8unorm",usage:_e.Texture.SAMPLE|_e.Texture.COPY_DST,mipLevels:1,sampler:this._sampler});return this._texture=n,this._textureFrameToken=void 0,this._touchGeneration(),n}_createNativeExternalTexture(){return this._destroyExternalTexture(),this._externalTexture=this.device.createExternalTexture({id:`${this.id}-external`,source:this._source,colorSpace:this._colorSpace,sampler:this._sampler}),this.generation++,this._externalTexture}_destroyExternalTexture(){this._externalTexture?.destroy(),this._externalTexture=null}_getResolvedSize(){let e=Li(this._source);return(0,_e.assert)(e.width>0&&e.height>0),e}_observeSource(){if(this.destroyed)return;let e=Wo(this._source);if(e!==this._isReady&&(this._isReady=e,this._touch()),!e)return;let t=qo(this._source,this._sourceVersion);Object.is(t,this._sourceFrameToken)||(this._sourceFrameToken=t,this._touch())}_touch(){this._updateTimestamp=this.device.incrementTimestamp()}_touchGeneration(){this.generation++,this._touch()}};function Ke(i){return!i||typeof i!="object"?!1:typeof HTMLVideoElement<"u"&&i instanceof HTMLVideoElement||"videoWidth"in i&&"videoHeight"in i&&"readyState"in i&&"currentTime"in i}function lr(i){return!i||typeof i!="object"?!1:typeof VideoFrame<"u"&&i instanceof VideoFrame||"displayWidth"in i&&"displayHeight"in i&&"timestamp"in i&&!("videoWidth"in i)}function Wo(i){let e=Li(i);return e.width<=0||e.height<=0?!1:Ke(i)?i.readyState>=2:!0}function Li(i){return Ke(i)?{width:i.videoWidth,height:i.videoHeight}:{width:i.displayWidth,height:i.displayHeight}}function qo(i,e){return Ke(i)?`${e}:${i.currentTime}:${i.videoWidth}x${i.videoHeight}`:`${e}:${i.timestamp}:${i.displayWidth}x${i.displayHeight}`}var Ze=L(k(),1),_r=L(ae(),1);var se=L(k(),1),De=class{id;current;next;constructor(e){this.id=e.id||"swap",this.current=e.current,this.next=e.next}destroy(){this.current?.destroy(),this.next?.destroy()}swap(){let e=this.current;this.current=this.next,this.next=e}},Be=class extends De{constructor(e,t){t={...t};let{width:n=1,height:r=1}=t,s=t.colorAttachments?.map(c=>typeof c!="string"?c:e.createTexture({id:`${t.id}-texture-0`,format:c,usage:se.Texture.SAMPLE|se.Texture.RENDER|se.Texture.COPY_SRC|se.Texture.COPY_DST,width:n,height:r})),o=e.createFramebuffer({...t,colorAttachments:s});s=t.colorAttachments?.map(c=>typeof c!="string"?c:e.createTexture({id:`${t.id}-texture-1`,format:c,usage:se.Texture.SAMPLE|se.Texture.RENDER|se.Texture.COPY_SRC|se.Texture.COPY_DST,width:n,height:r}));let a=e.createFramebuffer({...t,colorAttachments:s});super({current:o,next:a});for(let[c,h]of(t.colorAttachments||[]).entries())typeof h=="string"&&(o.attachResource(o.colorAttachments[c].texture),a.attachResource(a.colorAttachments[c].texture))}resize(e){if(e.width===this.current.width&&e.height===this.current.height)return!1;let{current:t,next:n}=this;return this.current=t.clone(e),fr(this.current),t.destroy(),this.next=n.clone(e),fr(this.next),n.destroy(),!0}};function fr(i){for(let e of i.colorAttachments)i.attachResource(e.texture);i.depthStencilAttachment&&i.attachResource(i.depthStencilAttachment.texture)}var Ut=class extends De{constructor(e,t){super({current:e.createBuffer(t),next:e.createBuffer(t)})}resize(e){if(e.byteLength===this.current.byteLength)return!1;let{current:t,next:n}=this;return this.current=t.clone(e),t.destroy(),this.next=n.clone(e),n.destroy(),!0}};function mr(i){let{shaderPass:e,action:t,shadingLanguage:n}=i;switch(t){case"filter":let r=`${e.name}_filterColor_ext`;return n==="wgsl"?Ko(r):Jo(r);case"sample":let s=`${e.name}_sampleColor`;return n==="wgsl"?Zo(s):Qo(s);default:throw new Error(`${e.name} no fragment shader generated for shader pass`)}}function Ko(i){return`@group(0) @binding(auto) var sourceTexture: texture_2d<f32>;
|
|
167
175
|
@group(0) @binding(auto) var sourceTextureSampler: sampler;
|
|
168
176
|
|
|
169
177
|
@fragment
|
|
170
178
|
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
|
|
171
|
-
let texCoord = inputs.coordinate;
|
|
179
|
+
let texCoord = shaderPassRenderer_getTextureUV(inputs.coordinate);
|
|
172
180
|
let texSize = vec2f(textureDimensions(sourceTexture));
|
|
173
181
|
|
|
174
182
|
var fragColor = textureSample(sourceTexture, sourceTextureSampler, texCoord);
|
|
175
183
|
fragColor = ${i}(fragColor, texSize, texCoord);
|
|
176
184
|
return fragColor;
|
|
177
185
|
}
|
|
178
|
-
`}function
|
|
186
|
+
`}function Zo(i){return`@group(0) @binding(auto) var sourceTexture: texture_2d<f32>;
|
|
179
187
|
@group(0) @binding(auto) var sourceTextureSampler: sampler;
|
|
180
188
|
|
|
181
189
|
@fragment
|
|
182
190
|
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
|
|
183
|
-
let texCoord = inputs.coordinate;
|
|
191
|
+
let texCoord = shaderPassRenderer_getTextureUV(inputs.coordinate);
|
|
184
192
|
let texSize = vec2f(textureDimensions(sourceTexture));
|
|
185
193
|
return ${i}(sourceTexture, sourceTextureSampler, texSize, texCoord);
|
|
186
194
|
}
|
|
187
|
-
`}function
|
|
195
|
+
`}function Jo(i){return`#version 300 es
|
|
188
196
|
|
|
189
197
|
uniform sampler2D sourceTexture;
|
|
190
198
|
|
|
@@ -195,14 +203,14 @@ in vec2 uv;
|
|
|
195
203
|
out vec4 fragColor;
|
|
196
204
|
|
|
197
205
|
void main() {
|
|
198
|
-
vec2 texCoord = coordinate;
|
|
206
|
+
vec2 texCoord = shaderPassRenderer_getTextureUV(coordinate);
|
|
199
207
|
ivec2 iTexSize = textureSize(sourceTexture, 0);
|
|
200
208
|
vec2 texSize = vec2(float(iTexSize.x), float(iTexSize.y));
|
|
201
209
|
|
|
202
210
|
fragColor = texture(sourceTexture, texCoord);
|
|
203
211
|
fragColor = ${i}(fragColor, texSize, texCoord);
|
|
204
212
|
}
|
|
205
|
-
`}function
|
|
213
|
+
`}function Qo(i){return`#version 300 es
|
|
206
214
|
|
|
207
215
|
uniform sampler2D sourceTexture;
|
|
208
216
|
|
|
@@ -213,13 +221,50 @@ in vec2 uv;
|
|
|
213
221
|
out vec4 fragColor;
|
|
214
222
|
|
|
215
223
|
void main() {
|
|
216
|
-
vec2 texCoord = coordinate;
|
|
224
|
+
vec2 texCoord = shaderPassRenderer_getTextureUV(coordinate);
|
|
217
225
|
ivec2 iTexSize = textureSize(sourceTexture, 0);
|
|
218
226
|
vec2 texSize = vec2(float(iTexSize.x), float(iTexSize.y));
|
|
219
227
|
|
|
220
228
|
fragColor = ${i}(sourceTexture, texSize, texCoord);
|
|
221
229
|
}
|
|
222
|
-
`}var
|
|
230
|
+
`}var pr={name:"textureTransform",source:`
|
|
231
|
+
struct textureTransformUniforms {
|
|
232
|
+
scale: vec2<f32>,
|
|
233
|
+
flipY: i32,
|
|
234
|
+
};
|
|
235
|
+
@group(0) @binding(auto) var<uniform> textureTransform: textureTransformUniforms;
|
|
236
|
+
|
|
237
|
+
fn shaderPassRenderer_getTextureUV(uv: vec2f) -> vec2f {
|
|
238
|
+
var position = (uv - vec2f(0.5, 0.5)) / textureTransform.scale + vec2f(0.5, 0.5);
|
|
239
|
+
if (textureTransform.flipY != 0) {
|
|
240
|
+
position.y = 1.0 - position.y;
|
|
241
|
+
}
|
|
242
|
+
return position;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
fn shaderPassRenderer_getRenderTargetUV(textureUV: vec2f) -> vec2f {
|
|
246
|
+
let unscaledCoord = (textureUV - vec2f(0.5, 0.5)) * textureTransform.scale + vec2f(0.5, 0.5);
|
|
247
|
+
return select(vec2f(unscaledCoord.x, 1.0 - unscaledCoord.y), unscaledCoord, textureTransform.flipY != 0);
|
|
248
|
+
}
|
|
249
|
+
`,fs:`
|
|
250
|
+
layout(std140) uniform textureTransformUniforms {
|
|
251
|
+
vec2 scale;
|
|
252
|
+
int flipY;
|
|
253
|
+
} textureTransform;
|
|
254
|
+
|
|
255
|
+
vec2 shaderPassRenderer_getTextureUV(vec2 coord) {
|
|
256
|
+
vec2 position = (coord - 0.5) / textureTransform.scale + 0.5;
|
|
257
|
+
if (textureTransform.flipY != 0) {
|
|
258
|
+
position.y = 1.0 - position.y;
|
|
259
|
+
}
|
|
260
|
+
return position;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
|
|
264
|
+
vec2 unscaledCoord = (textureUV - 0.5) * textureTransform.scale + 0.5;
|
|
265
|
+
return textureTransform.flipY != 0 ? unscaledCoord : vec2(unscaledCoord.x, 1.0 - unscaledCoord.y);
|
|
266
|
+
}
|
|
267
|
+
`,uniformTypes:{scale:"vec2<f32>",flipY:"i32"}};var ea=new Set(["original","previous"]),Vt=class{device;shaderInputs;passRenderers;swapFramebuffers;textureModel;constructor(e,t){this.device=e;let n=ta(t.shaderPasses);n.map(a=>(0,_r.initializeShaderModule)(a));let r=n.reduce((a,c)=>({...a,[c.name]:c}),{});this.shaderInputs=t.shaderInputs||new U(r);let s=e.getCanvasContext().getDrawingBufferSize();this.swapFramebuffers=new Be(e,{colorAttachments:[t.colorFormat||e.preferredColorFormat],width:s[0],height:s[1]}),this.textureModel=new Le(e,{backgroundTexture:this.swapFramebuffers.current.colorAttachments[0].texture,flipY:t.flipY??e.type==="webgpu"});let o=t.flipY??e.type==="webgpu";this.passRenderers=t.shaderPasses.map(a=>new Oi(e,a,this.shaderInputs,o))}destroy(){for(let e of this.passRenderers)e.destroy();this.swapFramebuffers.destroy(),this.textureModel.destroy()}resize(e){e||=this.device.getCanvasContext().getDrawingBufferSize(),this.swapFramebuffers.resize({width:e[0],height:e[1]});for(let t of this.passRenderers)t.resize(e)}resetHistory(){for(let e of this.passRenderers)e.resetHistory()}renderToScreen(e){let t=this.renderToTexture(e);if(!t)return!1;let n=this.device.getDefaultCanvasContext().getCurrentFramebuffer({depthStencilFormat:!1});this.textureModel.setProps({backgroundTexture:t}),this.textureModel.predraw(this.device.commandEncoder);let r=this.device.beginRenderPass({id:"shader-pass-renderer-to-screen",framebuffer:n,clearDepth:!1});return this.textureModel.draw(r),r.end(),!0}renderToTexture(e){let{sourceTexture:t}=e;if(t instanceof K&&!t.isReady)return null;let n=t instanceof K?t.texture:t;if(this.passRenderers.length===0)return n;e.resetHistory&&this.resetHistory(),this.textureModel.setProps({backgroundTexture:n}),this.textureModel.predraw(this.device.commandEncoder);let r=ha(this.swapFramebuffers,n),s=this.device.beginRenderPass({id:"shader-pass-renderer-seed-source",framebuffer:r,clearColor:[0,0,0,1],clearDepth:!1});this.textureModel.draw(s),s.end();let o=r,a=Ni(r),c=!1;try{for(let h of this.passRenderers){h.initializeHistoryTargets(n,this.textureModel);for(let u of h.subPassExecutions){let d=u.output||"previous",l=d==="previous"?ca(this.swapFramebuffers,o):h.getOutputFramebuffer(d),m=Ni(l),p=h.resolveBindings({execution:u,originalTexture:n,previousTexture:a,outputTexture:m,externalBindings:e.bindings||{}}),f=ra(this.shaderInputs,u,e.uniforms||{});u.subPassRenderer.prepare({commandEncoder:this.device.commandEncoder,bindings:p,textureScale:ua(p.sourceTexture||a,m),uniforms:f});let x=this.device.beginRenderPass({id:"shader-pass-renderer-run-pass",framebuffer:l,clearColor:[0,0,0,1],clearDepth:1});u.subPassRenderer.draw(x),x.end(),d==="previous"?(a=m,o=l):h.markTargetWritten(d)}}c=!0}finally{for(let h of this.passRenderers)h.finishFrame(c)}return a}},Oi=class{device;shaderInputs;passDefinition;renderTargets;subPassExecutions;constructor(e,t,n,r){if(this.device=e,this.shaderInputs=n,this.passDefinition=t,Ir(t)){ia(t.name,t.renderTargets||{}),this.renderTargets=sa(e,t.renderTargets||{}),this.subPassExecutions=t.steps.flatMap(s=>this.createStepExecutions(t,s,r));return}gr(t,t.name),this.renderTargets={},this.subPassExecutions=this.createPassExecutions(t,{ownerName:t.name,flipY:r})}destroy(){for(let e of this.subPassExecutions)e.subPassRenderer.destroy();oa(this.renderTargets)}resize(e){aa(this.device,this.renderTargets,e)}resetHistory(){for(let e of Object.values(this.renderTargets))e.historyInitialized=!1,e.writtenThisFrame=!1}initializeHistoryTargets(e,t){for(let n of Object.values(this.renderTargets)){if(n.spec.lifetime!=="history"||n.historyInitialized)continue;let r=yr(n),s=n.spec.initialize||{clearColor:[0,0,0,0]};if(s==="original"){t.setProps({backgroundTexture:e}),t.predraw(this.device.commandEncoder);let o=this.device.beginRenderPass({id:`${n.name}-initialize-history`,framebuffer:r,clearColor:[0,0,0,0],clearDepth:!1});t.draw(o),o.end()}else this.device.beginRenderPass({id:`${n.name}-clear-history`,framebuffer:r,clearColor:s.clearColor,clearDepth:!1}).end();n.historyInitialized=!0}}getOutputFramebuffer(e){return this.getRenderTarget(e).framebuffer}markTargetWritten(e){this.getRenderTarget(e).writtenThisFrame=!0}finishFrame(e){for(let t of Object.values(this.renderTargets)){if(e&&t.spec.lifetime==="history"&&t.writtenThisFrame){let n=br(t),r=yr(t);t.historyTexture=t.texture,t.historyFramebuffer=t.framebuffer,t.texture=n,t.framebuffer=r,t.historyInitialized=!0}t.writtenThisFrame=!1}}getRenderTarget(e){let t=this.renderTargets[e];if(!t)throw new Error(`${this.getOwnerName()}: unknown render target "${e}"`);return t}resolveBindings(e){let{execution:t,originalTexture:n,previousTexture:r,outputTexture:s,externalBindings:o}=e,a=t.inputs||{sourceTexture:"previous"},c=this.shaderInputs.getModuleBindingValues(t.shaderPass.name),h=Object.fromEntries(Object.entries(o).filter(([l])=>t.shaderPass.bindingLayout?.some(m=>m.name===l))),u={...c,...h},d=t.output||"previous";for(let[l,m]of Object.entries(a)){if(!m)continue;let p=this.resolveInputTexture(m,n,r),f=m in this.renderTargets?this.renderTargets[m]:null;if(d!=="previous"&&m===d&&f?.spec.lifetime!=="history")throw new Error(`${t.ownerName}: subpass cannot read and write render target "${d}" in the same draw`);if(l==="sourceTexture"&&p===s)throw new Error(`${t.ownerName}: subpass cannot sample from the render target it is writing to`);u[l]=p}return"sourceTexture"in u||(u.sourceTexture=r),u}createStepExecutions(e,t,n){return gr(t.shaderPass,`${e.name}/${t.shaderPass.name}`),this.createPassExecutions(t.shaderPass,{ownerName:`${e.name}/${t.shaderPass.name}`,firstInputs:t.inputs,lastOutput:t.output,uniformOverrides:t.uniforms,flipY:n})}createPassExecutions(e,t){let n=e.passes||[];return n.map((r,s)=>{let o=s===0,a=s===n.length-1,c=o&&t.firstInputs!==void 0?t.firstInputs:r.inputs,h=a&&t.lastOutput!==void 0?t.lastOutput:r.output;return na(t.ownerName,c,h,this.renderTargets),{ownerName:t.ownerName,shaderPass:e,subPassRenderer:new Ri(this.device,e,r,t.flipY),inputs:c,output:h,uniforms:ki(t.uniformOverrides,r.uniforms)}})}resolveInputTexture(e,t,n){switch(e){case"original":return t;case"previous":return n;default:{let r=this.getRenderTarget(e);return r.spec.lifetime==="history"&&!r.writtenThisFrame?br(r):r.texture}}}getOwnerName(){return this.passDefinition.name}},Ri=class{model;shaderPass;subPass;flipY;constructor(e,t,n,r){this.shaderPass=t,this.subPass=n,this.flipY=r;let s=n.action||n.filter&&"filter"||n.sampler&&"sample"||"filter",o=mr({shaderPass:t,action:s,shadingLanguage:e.info.shadingLanguage});this.model=new he(e,{id:`${t.name}-subpass`,source:o,fs:o,modules:[pr,t],parameters:{depthWriteEnabled:!1}})}destroy(){this.model.destroy()}prepare(e){let{commandEncoder:t,bindings:n,textureScale:r,uniforms:s}=e;this.model.shaderInputs.setProps({textureTransform:{scale:r,flipY:this.flipY?1:0}}),this.model.shaderInputs.setProps({[this.shaderPass.name]:this.shaderPass.uniforms||{}}),this.model.shaderInputs.setProps({[this.shaderPass.name]:s||{}}),this.model.setBindings(n||{}),this.model.predraw(t)}draw(e){this.model.draw(e)}};function ta(i){return i.flatMap(e=>Ir(e)?e.steps.map(t=>t.shaderPass):[e])}function Ir(i){return"steps"in i}function gr(i,e){let t=i.renderTargets;if(t&&Object.keys(t).length>0)throw new Error(`${e}: ShaderPass.renderTargets is not supported; use ShaderPassPipeline.renderTargets instead`)}function ia(i,e){for(let t of Object.keys(e))if(ea.has(t))throw new Error(`${i}: render target name "${t}" is reserved`)}function na(i,e,t,n){let r=e||{sourceTexture:"previous"};for(let s of Object.values(r))if(s&&s!=="original"&&s!=="previous"&&!(s in n))throw new Error(`${i}: unknown input source "${s}"`);if(t&&t!=="previous"&&!(t in n))throw new Error(`${i}: unknown output target "${t}"`)}function ki(i,e){if(!(!i&&!e))return{...i||{},...e||{}}}function ra(i,e,t){return ki(ki(i.getUniformValues()[e.shaderPass.name],e.uniforms),t[e.shaderPass.name])}function sa(i,e){let t=i.getCanvasContext().getDrawingBufferSize();return Object.entries(e).reduce((n,[r,s])=>({...n,[r]:vr(i,r,s,t)}),{})}function oa(i){for(let e of Object.values(i))e.framebuffer.destroy(),e.texture.destroy(),e.historyFramebuffer?.destroy(),e.historyTexture?.destroy()}function aa(i,e,t){for(let n of Object.values(e)){let r=Mr(t,n.spec.scale);if(n.texture.width===r[0]&&n.texture.height===r[1])continue;n.framebuffer.destroy(),n.texture.destroy(),n.historyFramebuffer?.destroy(),n.historyTexture?.destroy();let s=vr(i,n.name,n.spec,t);n.texture=s.texture,n.framebuffer=s.framebuffer,n.historyTexture=s.historyTexture,n.historyFramebuffer=s.historyFramebuffer,n.historyInitialized=!1,n.writtenThisFrame=!1}}function vr(i,e,t,n){let r=Mr(n,t.scale),{texture:s,framebuffer:o}=xr(i,e,t,r),a,c;if(t.lifetime==="history"){let h=xr(i,`${e}-history`,t,r);a=h.texture,c=h.framebuffer}return{name:e,spec:t,texture:s,framebuffer:o,historyTexture:a,historyFramebuffer:c,historyInitialized:!1,writtenThisFrame:!1}}function xr(i,e,t,n){let r=i.createTexture({id:`${e}-texture`,width:n[0],height:n[1],format:t.format||i.preferredColorFormat,usage:Ze.Texture.SAMPLE|Ze.Texture.RENDER|Ze.Texture.COPY_SRC|Ze.Texture.COPY_DST}),s=i.createFramebuffer({id:`${e}-framebuffer`,width:n[0],height:n[1],colorAttachments:[r]});return{texture:r,framebuffer:s}}function br(i){if(!i.historyTexture)throw new Error(`${i.name}: transient render target has no history texture`);return i.historyTexture}function yr(i){if(!i.historyFramebuffer)throw new Error(`${i.name}: transient render target has no history framebuffer`);return i.historyFramebuffer}function Mr(i,e=[1,1]){return[Math.max(1,Math.round(i[0]*e[0])),Math.max(1,Math.round(i[1]*e[1]))]}function Ni(i){let e=i.colorAttachments[0]?.texture;if(!e)throw new Error("ShaderPassRenderer: framebuffer is missing a color attachment texture");return e}function ca(i,e){return e===i.current?i.next:i.current}function ha(i,e){return Ni(i.current)===e?i.next:i.current}function ua(i,e){let t=i.width/i.height,n=e.width/e.height;return n>t?[1,n/t]:[t/n,1]}var B=L(k(),1),Fe=L(ae(),1);var Di=2,da=1e4,Bi=class{device;id;pipelineFactory;shaderFactory;userData={};bindings={};pipeline;source;shader;shaderInputs;_uniformStore;_pipelineNeedsUpdate="newly created";_getModuleUniforms;props;_destroyed=!1;constructor(e,t){if(e.type!=="webgpu")throw new Error("Computation is only supported in WebGPU");this.props={...Bi.defaultProps,...t},t=this.props,this.id=t.id||S("model"),this.device=e,Object.assign(this.userData,t.userData);let n=la(e),r=(0,Fe.resolveShaderPlugins)(this.props.plugins,n.shaderLanguage);if(Object.keys(r.vertexInputs).length>0||Object.keys(r.varyings).length>0)throw new Error("Computation does not support ShaderPlugin vertex inputs or varyings");let s=(0,Fe.mergeShaderPluginModules)(this.props.modules,r.modules),o=Object.fromEntries(s.map(l=>[l.name,l]));this.shaderInputs=t.shaderInputs||new U(o),t.shaderInputs&&r.modules.length>0&&this.shaderInputs.addModules(r.modules),this.setShaderInputs(this.shaderInputs);let a=bt(this.props.modules,this.shaderInputs?.getModules()),c={...r.defines,...this.props.defines};this.props.shaderLayout=we(this.props.shaderLayout,a)||null,this.pipelineFactory=t.pipelineFactory||B.PipelineFactory.getDefaultPipelineFactory(this.device),this.shaderFactory=t.shaderFactory||B.ShaderFactory.getDefaultShaderFactory(this.device);let{source:h,getUniforms:u}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:n,...this.props,modules:a,defines:c,pluginInjections:r.injections});this.source=h,this._getModuleUniforms=u;let d=e.getShaderLayout?.(this.source);this.props.shaderLayout=we(this.props.shaderLayout||d||null,a)||null,this.pipeline=this._updatePipeline(),t.bindings&&this.setBindings(t.bindings)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.shader),this._uniformStore.destroy(),this._destroyed=!0)}predraw(e){this.updateShaderInputs(e)}dispatch(e,t,n,r){try{this._logDrawCallStart(),this.pipeline=this._updatePipeline(),this.pipeline.setBindings(this.bindings),e.setPipeline(this.pipeline),e.setBindings({}),e.dispatch(t,n,r)}finally{this._logDrawCallEnd()}}setVertexCount(e){}setInstanceCount(e){}setShaderInputs(e){this.shaderInputs=e,this._uniformStore=new B.UniformStore(this.device,this.shaderInputs.modules);for(let[t,n]of Object.entries(this.shaderInputs.modules))if(Ae(n)){let r=this._uniformStore.getManagedUniformBuffer(t);this.bindings[`${t}Uniforms`]=r}}setShaderModuleProps(e){let t=this._getModuleUniforms(e),n=Object.keys(t).filter(s=>{let o=t[s];return!Ue(o)&&typeof o!="number"&&typeof o!="boolean"}),r={};for(let s of n)r[s]=t[s],delete t[s]}updateShaderInputs(e){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(),e)}setBindings(e){Object.assign(this.bindings,e)}_setPipelineNeedsUpdate(e){this._pipelineNeedsUpdate=this._pipelineNeedsUpdate||e}_updatePipeline(){if(this._pipelineNeedsUpdate){let e=null;this.pipeline&&(B.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),e=this.shader),this._pipelineNeedsUpdate=!1,this.shader=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"compute",source:this.source,debugShaders:this.props.debugShaders}),this.pipeline=this.pipelineFactory.createComputePipeline({...this.props,shader:this.shader}),e&&this.shaderFactory.release(e)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let e=B.log.level>3?0:da;B.log.level<2||Date.now()-this._lastLogTime<e||(this._lastLogTime=Date.now(),this._logOpen=!0,B.log.group(Di,`>>> DRAWING MODEL ${this.id}`,{collapsed:B.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let e=this.shaderInputs.getDebugTable();B.log.table(Di,e)(),B.log.groupEnd(Di)(),this._logOpen=!1}}_drawCount=0;_getBufferOrConstantValues(e,t){let n=B.dataTypeDecoder.getTypedArrayConstructor(t);return(e instanceof B.Buffer?new n(e.debugData):e).toString()}},Je=Bi;q(Je,"defaultProps",{...B.ComputePipeline.defaultProps,id:"unnamed",handle:void 0,userData:{},source:"",modules:[],defines:{},plugins:[],bindings:void 0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,shaderAssembler:Fe.ShaderAssembler.getDefaultShaderAssembler(),debugShaders:void 0});function la(i){return{type:i.type,shaderLanguage:i.info.shadingLanguage,shaderLanguageVersion:i.info.shadingLanguageVersion,gpu:i.info.gpu,limits:i.limits,features:i.features}}var J=L(k(),1);var fa=[0,1,1,1],F=-1,ma={isActive:"i32",indexMode:"i32",batchIndex:"i32",isHighlightActive:"i32",highlightedBatchIndex:"i32",highlightedObjectIndex:"i32",highlightColor:"vec4<f32>"},oe=`precision highp float;
|
|
223
268
|
precision highp int;
|
|
224
269
|
|
|
225
270
|
layout(std140) uniform pickingUniforms {
|
|
@@ -232,7 +277,7 @@ layout(std140) uniform pickingUniforms {
|
|
|
232
277
|
int highlightedObjectIndex;
|
|
233
278
|
vec4 highlightColor;
|
|
234
279
|
} picking;
|
|
235
|
-
`,
|
|
280
|
+
`,ze=`struct pickingUniforms {
|
|
236
281
|
isActive: i32,
|
|
237
282
|
indexMode: i32,
|
|
238
283
|
batchIndex: i32,
|
|
@@ -244,9 +289,9 @@ layout(std140) uniform pickingUniforms {
|
|
|
244
289
|
};
|
|
245
290
|
|
|
246
291
|
@group(0) @binding(auto) var<uniform> picking: pickingUniforms;
|
|
247
|
-
`;function
|
|
292
|
+
`;function pa(i={},e){let t={...e};switch(i.isActive!==void 0&&(t.isActive=Boolean(i.isActive)),i.indexMode){case"instance":t.indexMode=0;break;case"attribute":t.indexMode=1;break;case"vertex":t.indexMode=2;break;case void 0:break}switch(typeof i.batchIndex=="number"&&(t.batchIndex=i.batchIndex),i.highlightedObjectIndex){case void 0:break;case null:t.isHighlightActive=!1,t.highlightedObjectIndex=F;break;default:t.isHighlightActive=!0,t.highlightedObjectIndex=i.highlightedObjectIndex}switch(i.highlightedBatchIndex){case void 0:break;case null:t.isHighlightActive=!1,t.highlightedBatchIndex=F;break;default:t.isHighlightActive=!0,t.highlightedBatchIndex=i.highlightedBatchIndex}return i.highlightColor&&(t.highlightColor=i.highlightColor),t}var fe={props:{},uniforms:{},name:"picking",uniformTypes:ma,defaultUniforms:{isActive:!1,indexMode:0,batchIndex:0,isHighlightActive:!1,highlightedBatchIndex:F,highlightedObjectIndex:F,highlightColor:fa},getUniforms:pa};var Tr=1,ga=new Int32Array([F,F,0,0]);var wr=14,je=8;function Ht(i,e="color",t=i==="webgpu"){if(e==="auto")return t?"index":"color";if(e==="index"&&!t)throw new Error(`Picking mode "${e}" requires WebGPU or a WebGL device that supports renderable rg32sint textures.`);return e}function et(i){return i.type==="webgpu"||i.type==="webgl"&&i.isTextureFormatRenderable("rg32sint")}var Sr=Ht;function Ar(i){return{objectIndex:i[0]===F?null:i[0],batchIndex:i[1]===F?null:i[1]}}function Er(i){let e=i[0]+i[1]*256+i[2]*65536;if(e===0)return{objectIndex:null,batchIndex:null};let t=i[3]>0?i[3]-1:0;return{objectIndex:e-1,batchIndex:t}}var Xt=class{device;props;mode;pickInfo={batchIndex:null,objectIndex:null};framebuffer=null;lastMousePosition=null;tooltipElement=null;constructor(e,t){this.device=e,this.props={...Xt.defaultProps,...t};let n=t.mode??t.backend??Xt.defaultProps.mode;this.props.mode=n,this.props.backend=n,this.mode=Ht(this.device.type,n,et(this.device))}destroy(){this.framebuffer?.destroy(),this.tooltipElement?.remove(),this.tooltipElement=null}getFramebuffer(){return this.framebuffer||(this.framebuffer=this.mode==="index"?this.createIndexFramebuffer():this.createColorFramebuffer()),this.framebuffer}clearPickState(){this.lastMousePosition=null,this.setPickingProps({highlightedBatchIndex:null,highlightedObjectIndex:null}),this.hideTooltip()}shouldPick(e,t={}){if(!e)return this.lastMousePosition&&this.clearPickState(),!1;let[n,r]=e;return!t.force&&this.lastMousePosition&&this.lastMousePosition[0]===n&&this.lastMousePosition[1]===r?!1:(this.lastMousePosition=[n,r],!0)}beginRenderPass(){let e=this.getFramebuffer();return e.resize(this.device.getDefaultCanvasContext().getDevicePixelSize()),this.setPickingProps({isActive:!0}),this.mode==="index"?this.device.beginRenderPass({framebuffer:e,clearColors:[new Float32Array([0,0,0,0]),ga],clearDepth:1}):this.device.beginRenderPass({framebuffer:e,clearColor:[0,0,0,0],clearDepth:1})}async updatePickInfo(e){let t=this.getFramebuffer(),n=this.getPickPosition(e),r=await this.readPickInfo(t,n);return r?(this.hasPickInfoChanged(r)&&(this.pickInfo=r,this.props.onObjectPicked(r)),this.updateTooltip(r,e),this.setPickingProps({isActive:!1,highlightedBatchIndex:r.batchIndex,highlightedObjectIndex:r.objectIndex}),this.pickInfo):null}getPickPosition(e){let t=this.device.type!=="webgpu",n=this.device.getDefaultCanvasContext().cssToDevicePixels(e,t),r=n.x+Math.floor(n.width/2),s=n.y+Math.floor(n.height/2);return[r,s]}createIndexFramebuffer(){let e=this.device.createTexture({format:"rgba8unorm",width:1,height:1,usage:J.Texture.RENDER_ATTACHMENT}),t=this.device.createTexture({format:"rg32sint",width:1,height:1,usage:J.Texture.RENDER_ATTACHMENT|J.Texture.COPY_SRC});return this.device.createFramebuffer({colorAttachments:[e,t],depthStencilAttachment:"depth24plus"})}createColorFramebuffer(){let e=this.device.createTexture({format:"rgba8unorm",width:1,height:1,usage:J.Texture.RENDER_ATTACHMENT|J.Texture.COPY_SRC});return this.device.createFramebuffer({colorAttachments:[e],depthStencilAttachment:"depth24plus"})}setPickingProps(e){this.props.shaderInputs?.setProps({picking:e})}async readPickInfo(e,t){return this.mode==="index"?this.readIndexPickInfo(e,t):this.readColorPickInfo(e,t)}async readIndexPickInfo(e,[t,n]){if(this.device.type==="webgpu"){let s=e.colorAttachments[Tr]?.texture;if(!s)return null;let o=s.computeMemoryLayout({width:1,height:1}),a=this.device.createBuffer({byteLength:o.byteLength,usage:J.Buffer.COPY_DST|J.Buffer.MAP_READ});try{s.readBuffer({x:t,y:n,width:1,height:1},a);let c=await a.readAsync(0,o.byteLength);return Ar(new Int32Array(c.buffer,c.byteOffset,2))}finally{a.destroy()}}let r=this.device.readPixelsToArrayWebGL(e,{sourceX:t,sourceY:n,sourceWidth:1,sourceHeight:1,sourceAttachment:Tr});return r?Ar(new Int32Array(r.buffer,r.byteOffset,2)):null}async readColorPickInfo(e,[t,n]){if(this.device.type==="webgpu"){let s=e.colorAttachments[0]?.texture;if(!s)return null;let o=s.computeMemoryLayout({width:1,height:1}),a=this.device.createBuffer({byteLength:o.byteLength,usage:J.Buffer.COPY_DST|J.Buffer.MAP_READ});try{s.readBuffer({x:t,y:n,width:1,height:1},a);let c=await a.readAsync(0,o.byteLength);return Er(new Uint8Array(c.buffer,c.byteOffset,4))}finally{a.destroy()}}let r=this.device.readPixelsToArrayWebGL(e,{sourceX:t,sourceY:n,sourceWidth:1,sourceHeight:1,sourceAttachment:0});return r?Er(new Uint8Array(r.buffer,r.byteOffset,4)):null}hasPickInfoChanged(e){return e.objectIndex!==this.pickInfo.objectIndex||e.batchIndex!==this.pickInfo.batchIndex}updateTooltip(e,t){let n=this.props.getTooltip(e);if(!n){this.hideTooltip();return}let r=this.getOrCreateTooltipElement();r&&(r.textContent=n,r.style.display="block",this.positionTooltip(r,t))}hideTooltip(){this.tooltipElement&&(this.tooltipElement.style.display="none")}getOrCreateTooltipElement(){if(this.tooltipElement)return this.tooltipElement;if(typeof document>"u"||typeof window>"u"||typeof HTMLCanvasElement>"u"||typeof this.device.getDefaultCanvasContext!="function")return null;let e=this.device.getDefaultCanvasContext().canvas;if(!(e instanceof HTMLCanvasElement)||!e.parentElement)return null;let t=document.createElement("div");t.style.position="absolute",t.style.zIndex="12",t.style.display="none",t.style.maxWidth="220px",t.style.padding="8px 10px",t.style.borderRadius="6px",t.style.background="rgba(15, 23, 42, 0.92)",t.style.color="#f8fafc",t.style.font="600 13px/1.35 system-ui, sans-serif",t.style.pointerEvents="none",t.style.whiteSpace="nowrap",t.style.boxShadow="0 10px 24px rgba(15, 23, 42, 0.22)";let n=e.parentElement;return window.getComputedStyle(n).position==="static"&&(n.style.position="relative"),n.appendChild(t),this.tooltipElement=t,t}positionTooltip(e,t){if(typeof HTMLCanvasElement>"u"||typeof this.device.getDefaultCanvasContext!="function")return;let n=this.device.getDefaultCanvasContext().canvas;if(!(n instanceof HTMLCanvasElement))return;let r=Math.max(je,n.clientWidth-e.offsetWidth-je),s=Math.max(je,n.clientHeight-e.offsetHeight-je),o=Math.min(t[0]+wr,r),a=Math.min(t[1]+wr,s);e.style.left=`${Math.max(je,o)}px`,e.style.top=`${Math.max(je,a)}px`}},Qe=Xt;q(Qe,"defaultProps",{shaderInputs:void 0,onObjectPicked:()=>{},getTooltip:()=>null,mode:"color",backend:"color"});var xa=`${ze}
|
|
248
293
|
|
|
249
|
-
const COLOR_PICKING_INVALID_INDEX = ${
|
|
294
|
+
const COLOR_PICKING_INVALID_INDEX = ${F};
|
|
250
295
|
const COLOR_PICKING_MAX_OBJECT_INDEX = 16777214;
|
|
251
296
|
const COLOR_PICKING_MAX_BATCH_INDEX = 254;
|
|
252
297
|
|
|
@@ -315,12 +360,12 @@ fn picking_filterPickingColor(color: vec4<f32>, objectIndex: i32) -> vec4<f32> {
|
|
|
315
360
|
|
|
316
361
|
return color;
|
|
317
362
|
}
|
|
318
|
-
`,
|
|
363
|
+
`,ba=`${oe}
|
|
319
364
|
|
|
320
365
|
const int INDEX_PICKING_MODE_INSTANCE = 0;
|
|
321
366
|
const int INDEX_PICKING_MODE_CUSTOM = 1;
|
|
322
367
|
|
|
323
|
-
const int COLOR_PICKING_INVALID_INDEX = ${
|
|
368
|
+
const int COLOR_PICKING_INVALID_INDEX = ${F};
|
|
324
369
|
|
|
325
370
|
flat out int picking_objectIndex;
|
|
326
371
|
|
|
@@ -334,9 +379,9 @@ void picking_setObjectIndex(int objectIndex) {
|
|
|
334
379
|
break;
|
|
335
380
|
}
|
|
336
381
|
}
|
|
337
|
-
`,
|
|
382
|
+
`,ya=`${oe}
|
|
338
383
|
|
|
339
|
-
const int COLOR_PICKING_INVALID_INDEX = ${
|
|
384
|
+
const int COLOR_PICKING_INVALID_INDEX = ${F};
|
|
340
385
|
const int COLOR_PICKING_MAX_OBJECT_INDEX = 16777214;
|
|
341
386
|
const int COLOR_PICKING_MAX_BATCH_INDEX = 254;
|
|
342
387
|
|
|
@@ -407,19 +452,216 @@ vec4 picking_filterColor(vec4 color) {
|
|
|
407
452
|
outColor = picking_filterPickingColor(outColor);
|
|
408
453
|
return outColor;
|
|
409
454
|
}
|
|
410
|
-
`,
|
|
455
|
+
`,tt={...fe,name:"picking",source:xa,vs:ba,fs:ya};var _a=`${ze}
|
|
456
|
+
|
|
457
|
+
const COLOR_PICKING_INVALID_INDEX = ${F};
|
|
458
|
+
const COLOR_PICKING_MAX_OBJECT_INDEX = 16777214;
|
|
459
|
+
const COLOR_PICKING_MAX_BATCH_INDEX = 254;
|
|
460
|
+
|
|
461
|
+
fn picking_getInstanceObjectIndex(instanceIndex: u32) -> i32 {
|
|
462
|
+
return i32(instanceIndex);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
fn picking_getVertexObjectIndex(vertexIndex: u32) -> i32 {
|
|
466
|
+
return i32(vertexIndex);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
fn picking_getAttributeObjectIndex(objectIndex: i32) -> i32 {
|
|
470
|
+
return objectIndex;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
fn picking_setObjectIndex(objectIndex: i32) -> i32 {
|
|
474
|
+
return picking_getAttributeObjectIndex(objectIndex);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
fn picking_isObjectHighlighted(objectIndex: i32) -> bool {
|
|
478
|
+
return
|
|
479
|
+
picking.isHighlightActive != 0 &&
|
|
480
|
+
picking.highlightedBatchIndex == picking.batchIndex &&
|
|
481
|
+
picking.highlightedObjectIndex == objectIndex;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
fn picking_filterHighlightColor(color: vec4<f32>, objectIndex: i32) -> vec4<f32> {
|
|
485
|
+
if (picking.isActive != 0 || !picking_isObjectHighlighted(objectIndex)) {
|
|
486
|
+
return color;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
let highLightAlpha = picking.highlightColor.a;
|
|
490
|
+
let blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
|
|
491
|
+
if (blendedAlpha == 0.0) {
|
|
492
|
+
return vec4<f32>(color.rgb, 0.0);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
let highLightRatio = highLightAlpha / blendedAlpha;
|
|
496
|
+
let blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);
|
|
497
|
+
return vec4<f32>(blendedRGB, blendedAlpha);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
fn picking_canEncodePickInfo(objectIndex: i32) -> bool {
|
|
501
|
+
return
|
|
502
|
+
objectIndex != COLOR_PICKING_INVALID_INDEX &&
|
|
503
|
+
objectIndex >= 0 &&
|
|
504
|
+
objectIndex <= COLOR_PICKING_MAX_OBJECT_INDEX &&
|
|
505
|
+
picking.batchIndex >= 0 &&
|
|
506
|
+
picking.batchIndex <= COLOR_PICKING_MAX_BATCH_INDEX;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
fn picking_getPickingColor(objectIndex: i32) -> vec4<f32> {
|
|
510
|
+
if (!picking_canEncodePickInfo(objectIndex)) {
|
|
511
|
+
return vec4<f32>(0.0, 0.0, 0.0, 0.0);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
let encodedObjectIndex = objectIndex + 1;
|
|
515
|
+
let red = encodedObjectIndex % 256;
|
|
516
|
+
let green = (encodedObjectIndex / 256) % 256;
|
|
517
|
+
let blue = (encodedObjectIndex / 65536) % 256;
|
|
518
|
+
let alpha = picking.batchIndex + 1;
|
|
519
|
+
|
|
520
|
+
return vec4<f32>(
|
|
521
|
+
f32(red) / 255.0,
|
|
522
|
+
f32(green) / 255.0,
|
|
523
|
+
f32(blue) / 255.0,
|
|
524
|
+
f32(alpha) / 255.0
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
fn picking_filterPickingColor(color: vec4<f32>, objectIndex: i32) -> vec4<f32> {
|
|
529
|
+
if (picking.isActive != 0) {
|
|
530
|
+
if (!picking_canEncodePickInfo(objectIndex)) {
|
|
531
|
+
discard;
|
|
532
|
+
}
|
|
533
|
+
return picking_getPickingColor(objectIndex);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
return color;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
fn picking_filterColor(color: vec4<f32>, objectIndex: i32) -> vec4<f32> {
|
|
540
|
+
var outColor = color;
|
|
541
|
+
outColor = picking_filterHighlightColor(outColor, objectIndex);
|
|
542
|
+
outColor = picking_filterPickingColor(outColor, objectIndex);
|
|
543
|
+
return outColor;
|
|
544
|
+
}
|
|
545
|
+
`,Ia=`${oe}
|
|
546
|
+
|
|
547
|
+
const int INDEX_PICKING_MODE_INSTANCE = 0;
|
|
548
|
+
const int INDEX_PICKING_MODE_ATTRIBUTE = 1;
|
|
549
|
+
const int INDEX_PICKING_MODE_VERTEX = 2;
|
|
550
|
+
|
|
551
|
+
flat out int picking_objectIndex;
|
|
552
|
+
|
|
553
|
+
void picking_setObjectIndex(int objectIndex) {
|
|
554
|
+
switch (picking.indexMode) {
|
|
555
|
+
case INDEX_PICKING_MODE_INSTANCE:
|
|
556
|
+
picking_objectIndex = gl_InstanceID;
|
|
557
|
+
break;
|
|
558
|
+
case INDEX_PICKING_MODE_ATTRIBUTE:
|
|
559
|
+
picking_objectIndex = objectIndex;
|
|
560
|
+
break;
|
|
561
|
+
case INDEX_PICKING_MODE_VERTEX:
|
|
562
|
+
picking_objectIndex = gl_VertexID;
|
|
563
|
+
break;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
`,va=`${oe}
|
|
567
|
+
|
|
568
|
+
const int COLOR_PICKING_INVALID_INDEX = ${F};
|
|
569
|
+
const int COLOR_PICKING_MAX_OBJECT_INDEX = 16777214;
|
|
570
|
+
const int COLOR_PICKING_MAX_BATCH_INDEX = 254;
|
|
571
|
+
|
|
572
|
+
flat in int picking_objectIndex;
|
|
573
|
+
|
|
574
|
+
bool picking_isFragmentHighlighted() {
|
|
575
|
+
return
|
|
576
|
+
bool(picking.isHighlightActive) &&
|
|
577
|
+
picking.highlightedBatchIndex == picking.batchIndex &&
|
|
578
|
+
picking.highlightedObjectIndex == picking_objectIndex
|
|
579
|
+
;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
vec4 picking_filterHighlightColor(vec4 color) {
|
|
583
|
+
if (bool(picking.isActive)) {
|
|
584
|
+
return color;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
if (!picking_isFragmentHighlighted()) {
|
|
588
|
+
return color;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
float highLightAlpha = picking.highlightColor.a;
|
|
592
|
+
float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
|
|
593
|
+
float highLightRatio = highLightAlpha / blendedAlpha;
|
|
594
|
+
|
|
595
|
+
vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);
|
|
596
|
+
return vec4(blendedRGB, blendedAlpha);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
bool picking_canEncodePickInfo(int objectIndex) {
|
|
600
|
+
return
|
|
601
|
+
objectIndex != COLOR_PICKING_INVALID_INDEX &&
|
|
602
|
+
objectIndex >= 0 &&
|
|
603
|
+
objectIndex <= COLOR_PICKING_MAX_OBJECT_INDEX &&
|
|
604
|
+
picking.batchIndex >= 0 &&
|
|
605
|
+
picking.batchIndex <= COLOR_PICKING_MAX_BATCH_INDEX;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
vec4 picking_getPickingColor() {
|
|
609
|
+
if (!picking_canEncodePickInfo(picking_objectIndex)) {
|
|
610
|
+
return vec4(0.0);
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
int encodedObjectIndex = picking_objectIndex + 1;
|
|
614
|
+
int red = encodedObjectIndex % 256;
|
|
615
|
+
int green = (encodedObjectIndex / 256) % 256;
|
|
616
|
+
int blue = (encodedObjectIndex / 65536) % 256;
|
|
617
|
+
int alpha = picking.batchIndex + 1;
|
|
618
|
+
|
|
619
|
+
return vec4(float(red), float(green), float(blue), float(alpha)) / 255.0;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
vec4 picking_filterPickingColor(vec4 color) {
|
|
623
|
+
if (bool(picking.isActive)) {
|
|
624
|
+
if (!picking_canEncodePickInfo(picking_objectIndex)) {
|
|
625
|
+
discard;
|
|
626
|
+
}
|
|
627
|
+
return picking_getPickingColor();
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
return color;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
vec4 picking_filterColor(vec4 color) {
|
|
634
|
+
vec4 outColor = color;
|
|
635
|
+
outColor = picking_filterHighlightColor(outColor);
|
|
636
|
+
outColor = picking_filterPickingColor(outColor);
|
|
637
|
+
return outColor;
|
|
638
|
+
}
|
|
639
|
+
`,Yt={...fe,name:"picking",source:_a,vs:Ia,fs:va};var Ma=`${ze}
|
|
411
640
|
|
|
412
641
|
const INDEX_PICKING_MODE_INSTANCE = 0;
|
|
413
|
-
const
|
|
414
|
-
const
|
|
642
|
+
const INDEX_PICKING_MODE_ATTRIBUTE = 1;
|
|
643
|
+
const INDEX_PICKING_MODE_VERTEX = 2;
|
|
644
|
+
const INDEX_PICKING_INVALID_INDEX = ${F}; // 2^32 - 1
|
|
415
645
|
|
|
416
646
|
/**
|
|
417
647
|
* WGSL shaders need to carry the returned object index through their own stage outputs.
|
|
418
648
|
*/
|
|
419
|
-
fn
|
|
649
|
+
fn picking_getInstanceObjectIndex(instanceIndex: u32) -> i32 {
|
|
650
|
+
return i32(instanceIndex);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
fn picking_getVertexObjectIndex(vertexIndex: u32) -> i32 {
|
|
654
|
+
return i32(vertexIndex);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
fn picking_getAttributeObjectIndex(objectIndex: i32) -> i32 {
|
|
420
658
|
return objectIndex;
|
|
421
659
|
}
|
|
422
660
|
|
|
661
|
+
fn picking_setObjectIndex(objectIndex: i32) -> i32 {
|
|
662
|
+
return picking_getAttributeObjectIndex(objectIndex);
|
|
663
|
+
}
|
|
664
|
+
|
|
423
665
|
fn picking_isObjectHighlighted(objectIndex: i32) -> bool {
|
|
424
666
|
return
|
|
425
667
|
picking.isHighlightActive != 0 &&
|
|
@@ -454,32 +696,36 @@ fn picking_getPickingColor(objectIndex: i32) -> vec2<i32> {
|
|
|
454
696
|
return vec2<i32>(objectIndex, picking.batchIndex);
|
|
455
697
|
}
|
|
456
698
|
|
|
457
|
-
`,
|
|
699
|
+
`,Ta=`${oe}
|
|
458
700
|
|
|
459
701
|
const int INDEX_PICKING_MODE_INSTANCE = 0;
|
|
460
|
-
const int
|
|
702
|
+
const int INDEX_PICKING_MODE_ATTRIBUTE = 1;
|
|
703
|
+
const int INDEX_PICKING_MODE_VERTEX = 2;
|
|
461
704
|
|
|
462
|
-
const int INDEX_PICKING_INVALID_INDEX = ${
|
|
705
|
+
const int INDEX_PICKING_INVALID_INDEX = ${F}; // 2^32 - 1
|
|
463
706
|
|
|
464
707
|
flat out int picking_objectIndex;
|
|
465
708
|
|
|
466
709
|
/**
|
|
467
710
|
* Vertex shaders should call this function to set the object index.
|
|
468
|
-
* If using instance or vertex mode, argument
|
|
711
|
+
* If using instance or vertex mode, the argument is ignored and 0 can be supplied.
|
|
469
712
|
*/
|
|
470
713
|
void picking_setObjectIndex(int objectIndex) {
|
|
471
714
|
switch (picking.indexMode) {
|
|
472
715
|
case INDEX_PICKING_MODE_INSTANCE:
|
|
473
716
|
picking_objectIndex = gl_InstanceID;
|
|
474
717
|
break;
|
|
475
|
-
case
|
|
718
|
+
case INDEX_PICKING_MODE_ATTRIBUTE:
|
|
476
719
|
picking_objectIndex = objectIndex;
|
|
477
720
|
break;
|
|
721
|
+
case INDEX_PICKING_MODE_VERTEX:
|
|
722
|
+
picking_objectIndex = gl_VertexID;
|
|
723
|
+
break;
|
|
478
724
|
}
|
|
479
725
|
}
|
|
480
|
-
`,
|
|
726
|
+
`,wa=`${oe}
|
|
481
727
|
|
|
482
|
-
const int INDEX_PICKING_INVALID_INDEX = ${
|
|
728
|
+
const int INDEX_PICKING_INVALID_INDEX = ${F}; // 2^32 - 1
|
|
483
729
|
|
|
484
730
|
flat in int picking_objectIndex;
|
|
485
731
|
|
|
@@ -523,7 +769,7 @@ vec4 picking_filterHighlightColor(vec4 color) {
|
|
|
523
769
|
ivec4 picking_getPickingColor() {
|
|
524
770
|
// Assumes that colorAttachment0 is rg32int
|
|
525
771
|
// TODO? - we could render indices into a second color attachment and not mess with fragColor
|
|
526
|
-
return ivec4(picking_objectIndex, picking.batchIndex,
|
|
772
|
+
return ivec4(picking_objectIndex, picking.batchIndex, 0, 0);
|
|
527
773
|
}
|
|
528
774
|
|
|
529
775
|
vec4 picking_filterPickingColor(vec4 color) {
|
|
@@ -545,6 +791,6 @@ vec4 picking_filterColor(vec4 color) {
|
|
|
545
791
|
outColor = picking_filterPickingColor(outColor);
|
|
546
792
|
return outColor;
|
|
547
793
|
}
|
|
548
|
-
`,
|
|
794
|
+
`,it={...fe,name:"picking",source:Ma,vs:Ta,fs:wa};var Cr={...fe,name:"picking",source:it.source,vs:tt.vs,fs:tt.fs};function Pr(i){return et(i)?it:Yt}var Wt=class{device;framebuffer=null;shaderInputs;constructor(e,t){this.device=e,this.shaderInputs=t}destroy(){this.framebuffer?.destroy()}getFramebuffer(){return this.framebuffer||(this.framebuffer=this.device.createFramebuffer({colorAttachments:["rgba8unorm"],depthStencilAttachment:"depth24plus"})),this.framebuffer}clearPickState(){this.shaderInputs.setProps({picking:{highlightedObjectColor:null}})}beginRenderPass(){let e=this.getFramebuffer();return e.resize(this.device.getCanvasContext().getDevicePixelSize()),this.shaderInputs.setProps({picking:{isActive:!0}}),this.device.beginRenderPass({framebuffer:e,clearColor:[0,0,0,0],clearDepth:1})}updatePickState(e){let t=this.getFramebuffer(),[n,r]=this.getPickPosition(e),o=[...this.device.readPixelsToArrayWebGL(t,{sourceX:n,sourceY:r,sourceWidth:1,sourceHeight:1})].map(c=>c/255);o[0]+o[1]+o[2]>0||(o=null),this.shaderInputs.setProps({picking:{isActive:!1,highlightedObjectColor:o}})}getPickPosition(e){let t=this.device.getCanvasContext().cssToDevicePixels(e),n=t.x+Math.floor(t.width/2),r=t.y+Math.floor(t.height/2);return[n,r]}};var Lr=L(ae(),1),Or=Lr.picking;var Aa=K;return Vr(nt);})();
|
|
549
795
|
return __exports__;
|
|
550
796
|
});
|